Date: Wed, 3 Jul 2024 16:14:57 GMT From: Ryan Libby <rlibby@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 2730f4291411 - main - amd64 pcpu: fix clobbers, suppress warnings, and clean up Message-ID: <202407031614.463GEvIc041569@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by rlibby: URL: https://cgit.FreeBSD.org/src/commit/?id=2730f4291411be0adc1c6ec421f72e146556579c commit 2730f4291411be0adc1c6ec421f72e146556579c Author: Ryan Libby <rlibby@FreeBSD.org> AuthorDate: 2024-07-03 15:36:31 +0000 Commit: Ryan Libby <rlibby@FreeBSD.org> CommitDate: 2024-07-03 15:36:31 +0000 amd64 pcpu: fix clobbers, suppress warnings, and clean up These changes mostly apply to the !__SEG_GS section, which is no longer the normal compilation path. They're made to be consistent with changes to i386. - Add missing cc clobber to __PCPU_ADD (which is currently unused). - Allow the compiler the opportunity to marginally improve code generation from __PCPU_PTR by letting it figure out how to do the add (also removing the addition fixes a missing cc clobber). - Quiet gcc -Warray-bounds by using constant operands instead of bogus memory references. - Remove the struct __s __s temporaries, just cast through the type. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D45827 --- sys/amd64/include/pcpu.h | 51 +++++++++++++++++++------------------------- sys/amd64/include/pcpu_aux.h | 4 ++-- 2 files changed, 24 insertions(+), 31 deletions(-) diff --git a/sys/amd64/include/pcpu.h b/sys/amd64/include/pcpu.h index fb49eb31ef8a..213790d245dc 100644 --- a/sys/amd64/include/pcpu.h +++ b/sys/amd64/include/pcpu.h @@ -182,16 +182,8 @@ _Static_assert(sizeof(struct monitorbuf) == 128, "2x cache line"); /* * Evaluates to the address of the per-cpu variable name. */ -#define __PCPU_PTR(name) __extension__ ({ \ - __pcpu_type(name) *__p; \ - \ - __asm __volatile("movq %%gs:%1,%0; addq %2,%0" \ - : "=r" (__p) \ - : "m" (*(struct pcpu *)(__pcpu_offset(pc_prvspace))), \ - "i" (__pcpu_offset(name))); \ - \ - __p; \ -}) +#define __PCPU_PTR(name) \ + (&get_pcpu()->name) /* * Evaluates to the value of the per-cpu variable name. @@ -200,14 +192,13 @@ _Static_assert(sizeof(struct monitorbuf) == 128, "2x cache line"); __pcpu_type(name) __res; \ struct __s { \ u_char __b[MIN(sizeof(__pcpu_type(name)), 8)]; \ - } __s; \ + }; \ \ if (sizeof(__res) == 1 || sizeof(__res) == 2 || \ sizeof(__res) == 4 || sizeof(__res) == 8) { \ - __asm __volatile("mov %%gs:%1,%0" \ - : "=r" (__s) \ - : "m" (*(struct __s *)(__pcpu_offset(name)))); \ - *(struct __s *)(void *)&__res = __s; \ + __asm __volatile("mov %%gs:%c1,%0" \ + : "=r" (*(struct __s *)(void *)&__res) \ + : "i" (__pcpu_offset(name))); \ } else { \ __res = *__PCPU_PTR(name); \ } \ @@ -222,15 +213,16 @@ _Static_assert(sizeof(struct monitorbuf) == 128, "2x cache line"); __pcpu_type(name) __val; \ struct __s { \ u_char __b[MIN(sizeof(__pcpu_type(name)), 8)]; \ - } __s; \ + }; \ \ __val = (val); \ if (sizeof(__val) == 1 || sizeof(__val) == 2 || \ sizeof(__val) == 4 || sizeof(__val) == 8) { \ - __s = *(struct __s *)(void *)&__val; \ - __asm __volatile("add %1,%%gs:%0" \ - : "=m" (*(struct __s *)(__pcpu_offset(name))) \ - : "r" (__s)); \ + __asm __volatile("add %1,%%gs:%c0" \ + : \ + : "i" (__pcpu_offset(name)), \ + "r" (*(struct __s *)(void *)&__val) \ + : "cc", "memory"); \ } else \ *__PCPU_PTR(name) += __val; \ } while (0) @@ -238,30 +230,31 @@ _Static_assert(sizeof(struct monitorbuf) == 128, "2x cache line"); /* * Sets the value of the per-cpu variable name to value val. */ -#define __PCPU_SET(name, val) { \ +#define __PCPU_SET(name, val) do { \ __pcpu_type(name) __val; \ struct __s { \ u_char __b[MIN(sizeof(__pcpu_type(name)), 8)]; \ - } __s; \ + }; \ \ __val = (val); \ if (sizeof(__val) == 1 || sizeof(__val) == 2 || \ sizeof(__val) == 4 || sizeof(__val) == 8) { \ - __s = *(struct __s *)(void *)&__val; \ - __asm __volatile("mov %1,%%gs:%0" \ - : "=m" (*(struct __s *)(__pcpu_offset(name))) \ - : "r" (__s)); \ + __asm __volatile("mov %1,%%gs:%c0" \ + : \ + : "i" (__pcpu_offset(name)), \ + "r" (*(struct __s *)(void *)&__val) \ + : "memory"); \ } else { \ *__PCPU_PTR(name) = __val; \ } \ -} +} while (0) #define get_pcpu() __extension__ ({ \ struct pcpu *__pc; \ \ - __asm __volatile("movq %%gs:%1,%0" \ + __asm __volatile("movq %%gs:%c1,%0" \ : "=r" (__pc) \ - : "m" (*(struct pcpu *)(__pcpu_offset(pc_prvspace)))); \ + : "i" (__pcpu_offset(pc_prvspace))); \ __pc; \ }) #endif /* !__SEG_GS */ diff --git a/sys/amd64/include/pcpu_aux.h b/sys/amd64/include/pcpu_aux.h index 9d776274a57d..6e27162e1fb4 100644 --- a/sys/amd64/include/pcpu_aux.h +++ b/sys/amd64/include/pcpu_aux.h @@ -54,8 +54,8 @@ __curthread(void) { struct thread *td; - __asm("movq %%gs:%P1,%0" : "=r" (td) : "n" (offsetof(struct pcpu, - pc_curthread))); + __asm("movq %%gs:%c1,%0" : "=r" (td) + : "i" (offsetof(struct pcpu, pc_curthread))); return (td); } #define curthread (__curthread())
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202407031614.463GEvIc041569>