Skip to content

Commit d5ace2a

Browse files
kelleymhliuw
authored andcommitted
x86/hyperv: Disable IBT when hypercall page lacks ENDBR instruction
On hardware that supports Indirect Branch Tracking (IBT), Hyper-V VMs with ConfigVersion 9.3 or later support IBT in the guest. However, current versions of Hyper-V have a bug in that there's not an ENDBR64 instruction at the beginning of the hypercall page. Since hypercalls are made with an indirect call to the hypercall page, all hypercall attempts fail with an exception and Linux panics. A Hyper-V fix is in progress to add ENDBR64. But guard against the Linux panic by clearing X86_FEATURE_IBT if the hypercall page doesn't start with ENDBR. The VM will boot and run without IBT. If future Linux 32-bit kernels were to support IBT, additional hypercall page hackery would be needed to make IBT work for such kernels in a Hyper-V VM. Cc: stable@vger.kernel.org Signed-off-by: Michael Kelley <mikelley@microsoft.com> Link: https://lore.kernel.org/r/1690001476-98594-1-git-send-email-mikelley@microsoft.com Signed-off-by: Wei Liu <wei.liu@kernel.org>
1 parent 55e544e commit d5ace2a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

arch/x86/hyperv/hv_init.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <asm/apic.h>
1515
#include <asm/desc.h>
1616
#include <asm/sev.h>
17+
#include <asm/ibt.h>
1718
#include <asm/hypervisor.h>
1819
#include <asm/hyperv-tlfs.h>
1920
#include <asm/mshyperv.h>
@@ -471,6 +472,26 @@ void __init hyperv_init(void)
471472
wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
472473
}
473474

475+
/*
476+
* Some versions of Hyper-V that provide IBT in guest VMs have a bug
477+
* in that there's no ENDBR64 instruction at the entry to the
478+
* hypercall page. Because hypercalls are invoked via an indirect call
479+
* to the hypercall page, all hypercall attempts fail when IBT is
480+
* enabled, and Linux panics. For such buggy versions, disable IBT.
481+
*
482+
* Fixed versions of Hyper-V always provide ENDBR64 on the hypercall
483+
* page, so if future Linux kernel versions enable IBT for 32-bit
484+
* builds, additional hypercall page hackery will be required here
485+
* to provide an ENDBR32.
486+
*/
487+
#ifdef CONFIG_X86_KERNEL_IBT
488+
if (cpu_feature_enabled(X86_FEATURE_IBT) &&
489+
*(u32 *)hv_hypercall_pg != gen_endbr()) {
490+
setup_clear_cpu_cap(X86_FEATURE_IBT);
491+
pr_warn("Hyper-V: Disabling IBT because of Hyper-V bug\n");
492+
}
493+
#endif
494+
474495
/*
475496
* hyperv_init() is called before LAPIC is initialized: see
476497
* apic_intr_mode_init() -> x86_platform.apic_post_init() and

0 commit comments

Comments
 (0)