From 9775a6ebd2c2fc1f673553b6516a2027fa197870 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Mon, 29 Oct 2018 23:52:31 +0000 Subject: [PATCH] amd64: Use ifuncs to select suitable implementation of set_pcb_flags(). There is no reason to check for PCB_FULL_IRET if FSGSBASE instructions are not supported. Sponsored by: The FreeBSD Foundation MFC after: 1 week --- sys/amd64/amd64/machdep.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index 2432adcb492..a743d8c63e1 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -2616,15 +2616,14 @@ set_pcb_flags_raw(struct pcb *pcb, const u_int flags) * the PCB_FULL_IRET flag is set. We disable interrupts to sync with * context switches. */ -void -set_pcb_flags(struct pcb *pcb, const u_int flags) +static void +set_pcb_flags_fsgsbase(struct pcb *pcb, const u_int flags) { register_t r; if (curpcb == pcb && (flags & PCB_FULL_IRET) != 0 && - (pcb->pcb_flags & PCB_FULL_IRET) == 0 && - (cpu_stdext_feature & CPUID_STDEXT_FSGSBASE) != 0) { + (pcb->pcb_flags & PCB_FULL_IRET) == 0) { r = intr_disable(); if ((pcb->pcb_flags & PCB_FULL_IRET) == 0) { if (rfs() == _ufssel) @@ -2639,6 +2638,13 @@ set_pcb_flags(struct pcb *pcb, const u_int flags) } } +DEFINE_IFUNC(, void, set_pcb_flags, (struct pcb *, const u_int), static) +{ + + return ((cpu_stdext_feature & CPUID_STDEXT_FSGSBASE) != 0 ? + set_pcb_flags_fsgsbase : set_pcb_flags_raw); +} + void clear_pcb_flags(struct pcb *pcb, const u_int flags) { -- 2.45.2