From c88205e76ef6021b9521d1d1dee813394826a8de Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Sat, 20 Oct 2018 17:00:18 +0000 Subject: [PATCH] amd64: relax constraints in curthread and curpcb This makes the compiler less likely to reload the content from %gs. The 'P' modifier drops all synteax prefixes and 'n' constraint treats input as a known at compilation time immediate integer. Example reloading victim was spinlock_enter. Stolen from: OpenBSD Reported by: jtl Reviewed by: kib Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D17615 --- sys/amd64/include/pcpu.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sys/amd64/include/pcpu.h b/sys/amd64/include/pcpu.h index f1493176708a..95a647747a79 100644 --- a/sys/amd64/include/pcpu.h +++ b/sys/amd64/include/pcpu.h @@ -227,8 +227,7 @@ __curthread(void) { struct thread *td; - __asm("movq %%gs:%1,%0" : "=r" (td) - : "m" (*(char *)OFFSETOF_CURTHREAD)); + __asm("movq %%gs:%P1,%0" : "=r" (td) : "n" (OFFSETOF_CURTHREAD)); return (td); } #ifdef __clang__ @@ -242,7 +241,7 @@ __curpcb(void) { struct pcb *pcb; - __asm("movq %%gs:%1,%0" : "=r" (pcb) : "m" (*(char *)OFFSETOF_CURPCB)); + __asm("movq %%gs:%P1,%0" : "=r" (pcb) : "n" (OFFSETOF_CURPCB)); return (pcb); } #define curpcb (__curpcb())