x86/spec-ctrl: Build with BRANCH_HARDEN lfences by default
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 4 Oct 2021 20:39:03 +0000 (21:39 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 8 Oct 2021 17:52:22 +0000 (18:52 +0100)
commitb11380f6cd58ce40422473262b2b4c2b210447a1
tree504cbe4092907880c65bb00575b75814a5ea8073
parent1d345539c0e3654025fc00187bf633fda6ea9a43
x86/spec-ctrl: Build with BRANCH_HARDEN lfences by default

Branch Harden is enabled by default at compile and boot time.  Invert the
logic to compile with lfence by default and nop out in the non-default case.

This has several advantages.  It removes 3829 patch points (in the random
build of Xen I have to hand) by default on boot, 70% (!) of the
.altinstr_replacement section.  For builds of Xen with a non-nops capable tool
chain, the code after `spec-ctrl=no-branch-harden` is better because Xen can
write long nops.

Most importantly however, it means the disassembly actually matches what runs
in the common case, with the ability to distinguish the lfences from other
uses of nops.

Finally, make opt_branch_harden local to spec_ctrl.c and __initdata.  It has
never been used externally, even at it's introduction in c/s 3860d5534df4
"spec: add l1tf-barrier".

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/spec_ctrl.c
xen/include/asm-x86/cpufeatures.h
xen/include/asm-x86/nospec.h
xen/include/asm-x86/spec_ctrl.h