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
This commit is contained in:
Mateusz Guzik 2018-10-20 17:00:18 +00:00
parent b287b40c49
commit c88205e76e

View File

@ -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())