[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <SN6PR2101MB16933FAC4E09E15D824EB2FDD73FA@SN6PR2101MB1693.namprd21.prod.outlook.com>
Date: Fri, 21 Jul 2023 00:41:35 +0000
From: "Michael Kelley (LINUX)" <mikelley@...rosoft.com>
To: Peter Zijlstra <peterz@...radead.org>
CC: KY Srinivasan <kys@...rosoft.com>,
Haiyang Zhang <haiyangz@...rosoft.com>,
"wei.liu@...nel.org" <wei.liu@...nel.org>,
Dexuan Cui <decui@...rosoft.com>,
"tglx@...utronix.de" <tglx@...utronix.de>,
"mingo@...hat.com" <mingo@...hat.com>,
"bp@...en8.de" <bp@...en8.de>,
"dave.hansen@...ux.intel.com" <dave.hansen@...ux.intel.com>,
"hpa@...or.com" <hpa@...or.com>, "x86@...nel.org" <x86@...nel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-hyperv@...r.kernel.org" <linux-hyperv@...r.kernel.org>,
"stable@...r.kernel.org" <stable@...r.kernel.org>
Subject: RE: [PATCH 1/1] x86/hyperv: Disable IBT when hypercall page lacks
ENDBR instruction
From: Peter Zijlstra <peterz@...radead.org> Sent: Thursday, July 20, 2023 2:16 PM
>
> On Thu, Jul 20, 2023 at 01:33:57PM -0700, Michael Kelley wrote:
> > 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.
>
> Whoops :/
>
> > 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.
>
> There are currently no plans to add IBT support to 32bit.
That's what I thought.
>
> > Cc: stable@...r.kernel.org
> > Signed-off-by: Michael Kelley <mikelley@...rosoft.com>
> > ---
> > arch/x86/hyperv/hv_init.c | 21 +++++++++++++++++++++
> > 1 file changed, 21 insertions(+)
> >
> > diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
> > index 6c04b52..5cbee24 100644
> > --- a/arch/x86/hyperv/hv_init.c
> > +++ b/arch/x86/hyperv/hv_init.c
> > @@ -14,6 +14,7 @@
> > #include <asm/apic.h>
> > #include <asm/desc.h>
> > #include <asm/sev.h>
> > +#include <asm/ibt.h>
> > #include <asm/hypervisor.h>
> > #include <asm/hyperv-tlfs.h>
> > #include <asm/mshyperv.h>
> > @@ -472,6 +473,26 @@ void __init hyperv_init(void)
> > }
> >
> > /*
> > + * Some versions of Hyper-V that provide IBT in guest VMs have a bug
> > + * in that there's no ENDBR64 instruction at the entry to the
> > + * hypercall page. Because hypercalls are invoked via an indirect call
> > + * to the hypercall page, all hypercall attempts fail when IBT is
> > + * enabled, and Linux panics. For such buggy versions, disable IBT.
> > + *
> > + * Fixed versions of Hyper-V always provide ENDBR64 on the hypercall
> > + * page, so if future Linux kernel versions enable IBT for 32-bit
> > + * builds, additional hypercall page hackery will be required here
> > + * to provide an ENDBR32.
> > + */
> > +#ifdef CONFIG_X86_KERNEL_IBT
> > + if (cpu_feature_enabled(X86_FEATURE_IBT) &&
> > + *(u32 *)hv_hypercall_pg != gen_endbr()) {
> > + setup_clear_cpu_cap(X86_FEATURE_IBT);
> > + pr_info("Hyper-V: Disabling IBT because of Hyper-V bug\n");
> > + }
> > +#endif
>
> pr_warn() perhaps?
I wanted pr_info() so there's an immediate way to check for this
case in the dmesg output if a user complains about IBT not being
enabled when he expects it. In some sense, the message is temporary
because once the Hyper-V patch is available and users install it,
the message will go away. The pipeline for the Hyper-V patch is a
bit long, so availability is at least several months away. This Linux
workaround will be available much faster. Once it is picked up on
stable branches, we will avoid the situations like we saw where
someone upgraded Fedora 38 from a 6.2 to a 6.3 kernel, and the 6.3
kernel wouldn't boot because it has kernel IBT enabled.
>
> Other than that, this seems fairly straight forward. One thing I
> wondered about; wouldn't it be possible to re-write the indirect
> hypercall thingies to a direct call? I mean, once we have the hypercall
> page mapped, the address is known right?
Yes, the address is known. It does not change across things like
hibernation. But the indirect call instruction is part of an inline assembly
sequence, so the call instructions that need re-writing are scattered
throughout the code. There's also the SEV-SNP case from the
latest version of Tianyu Lan's patch set [1] where vmmcall may be used
instead, based on your recent enhancement for nested ALTERNATIVE.
Re-writing seems like that's more complexity than warranted for a
mostly interim situation until the Hyper-V patch is available and
users install it.
Michael
[1] https://lore.kernel.org/lkml/20230718032304.136888-6-ltykernel@gmail.com/
Powered by blists - more mailing lists