From: Sean Christopherson <seanjc@google.com>
To: mlevitsk@redhat.com
Cc: kvm@vger.kernel.org, Ingo Molnar <mingo@redhat.com>,
x86@kernel.org, Paolo Bonzini <pbonzini@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
Borislav Petkov <bp@alien8.de>,
linux-kernel@vger.kernel.org, "H. Peter Anvin" <hpa@zytor.com>
Subject: Re: [PATCH v3 3/4] KVM: nVMX: relax canonical checks on some x86 registers in vmx host state
Date: Fri, 16 Aug 2024 15:03:31 -0700 [thread overview]
Message-ID: <Zr_Ms-7IpzINzmc7@google.com> (raw)
In-Reply-To: <4d292a92016c65ae7521edec2cc0e9842c033e26.camel@redhat.com>
On Fri, Aug 16, 2024, mlevitsk@redhat.com wrote:
> > Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
> > ---
> > arch/x86/kvm/vmx/nested.c | 30 +++++++++++++++++++++++-------
> > 1 file changed, 23 insertions(+), 7 deletions(-)
> >
> > diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> > index 2392a7ef254d..3f18edff80ac 100644
> > --- a/arch/x86/kvm/vmx/nested.c
> > +++ b/arch/x86/kvm/vmx/nested.c
> > @@ -2969,6 +2969,22 @@ static int nested_vmx_check_address_space_size(struct kvm_vcpu *vcpu,
> > return 0;
> > }
> >
> > +static bool is_l1_noncanonical_address_static(u64 la, struct kvm_vcpu *vcpu)
> > +{
> > + u8 max_guest_address_bits = guest_can_use(vcpu, X86_FEATURE_LA57) ? 57 : 48;
I don't see any reason to use LA57 support from guest CPUID for the VMCS checks.
The virtualization hole exists can't be safely plugged for all cases, so why
bother trying to plug it only for some cases?
It'd be very odd that an L1 could set a "bad" value via WRMSR, but then couldn't
load that same value on VM-Exit, e.g. if L1 gets the VMCS value by doing RDMSR.
> > + /*
> > + * Most x86 arch registers which contain linear addresses like
> > + * segment bases, addresses that are used in instructions (e.g SYSENTER),
> > + * have static canonicality checks,
> > + * size of whose depends only on CPU's support for 5-level
> > + * paging, rather than state of CR4.LA57.
> > + *
> > + * In other words the check only depends on the CPU model,
> > + * rather than on runtime state.
> > + */
> > + return !__is_canonical_address(la, max_guest_address_bits);
> > +}
> > +
> > static int nested_vmx_check_host_state(struct kvm_vcpu *vcpu,
> > struct vmcs12 *vmcs12)
> > {
> > @@ -2979,8 +2995,8 @@ static int nested_vmx_check_host_state(struct kvm_vcpu *vcpu,
> > CC(!kvm_vcpu_is_legal_cr3(vcpu, vmcs12->host_cr3)))
> > return -EINVAL;
> >
> > - if (CC(is_noncanonical_address(vmcs12->host_ia32_sysenter_esp, vcpu)) ||
> > - CC(is_noncanonical_address(vmcs12->host_ia32_sysenter_eip, vcpu)))
> > + if (CC(is_l1_noncanonical_address_static(vmcs12->host_ia32_sysenter_esp, vcpu)) ||
> > + CC(is_l1_noncanonical_address_static(vmcs12->host_ia32_sysenter_eip, vcpu)))
> > return -EINVAL;
> >
> > if ((vmcs12->vm_exit_controls & VM_EXIT_LOAD_IA32_PAT) &&
> > @@ -3014,11 +3030,11 @@ static int nested_vmx_check_host_state(struct kvm_vcpu *vcpu,
> > CC(vmcs12->host_ss_selector == 0 && !ia32e))
> > return -EINVAL;
> >
> > - if (CC(is_noncanonical_address(vmcs12->host_fs_base, vcpu)) ||
> > - CC(is_noncanonical_address(vmcs12->host_gs_base, vcpu)) ||
> > - CC(is_noncanonical_address(vmcs12->host_gdtr_base, vcpu)) ||
> > - CC(is_noncanonical_address(vmcs12->host_idtr_base, vcpu)) ||
> > - CC(is_noncanonical_address(vmcs12->host_tr_base, vcpu)) ||
> > + if (CC(is_l1_noncanonical_address_static(vmcs12->host_fs_base, vcpu)) ||
> > + CC(is_l1_noncanonical_address_static(vmcs12->host_gs_base, vcpu)) ||
> > + CC(is_l1_noncanonical_address_static(vmcs12->host_gdtr_base, vcpu)) ||
> > + CC(is_l1_noncanonical_address_static(vmcs12->host_idtr_base, vcpu)) ||
> > + CC(is_l1_noncanonical_address_static(vmcs12->host_tr_base, vcpu)) ||
If loads via LTR, LLDT, and LGDT are indeed exempt, then we need to update
emul_is_noncanonical_address() too.
The best idea I have is to have a separate flow for system registers (not a great
name, but I can't think of anything better), and the
E.g. s/is_host_noncanonical_msr_value/is_non_canonical_system_reg, and then
wire that up to the emulator.
> > CC(is_noncanonical_address(vmcs12->host_rip, vcpu)))
> > return -EINVAL;
> >
>
next prev parent reply other threads:[~2024-08-16 22:03 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-15 12:33 [PATCH v3 0/4] Relax canonical checks on some arch msrs Maxim Levitsky
2024-08-15 12:33 ` [PATCH v3 1/4] KVM: x86: relax canonical check for some x86 architectural msrs Maxim Levitsky
2024-08-16 21:49 ` Sean Christopherson
2024-08-16 22:02 ` Sean Christopherson
2024-08-20 12:13 ` mlevitsk
2024-08-21 12:04 ` mlevitsk
2024-08-21 16:04 ` Sean Christopherson
2024-08-23 11:14 ` mlevitsk
2024-08-23 13:59 ` Sean Christopherson
2025-09-12 20:28 ` Jim Mattson
2025-09-16 20:47 ` Sean Christopherson
2024-08-15 12:33 ` [PATCH v3 2/4] KVM: x86: add X86_FEATURE_LA57 to governed_features Maxim Levitsky
2024-08-15 12:33 ` [PATCH v3 3/4] KVM: nVMX: relax canonical checks on some x86 registers in vmx host state Maxim Levitsky
2024-08-16 10:40 ` mlevitsk
2024-08-16 22:03 ` Sean Christopherson [this message]
2024-08-20 12:19 ` mlevitsk
2024-08-15 12:33 ` [PATCH v3 4/4] KVM: SVM: fix emulation of msr reads/writes of MSR_FS_BASE and MSR_GS_BASE Maxim Levitsky
2024-08-16 22:04 ` Sean Christopherson
2024-08-24 0:07 ` Sean Christopherson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zr_Ms-7IpzINzmc7@google.com \
--to=seanjc@google.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mlevitsk@redhat.com \
--cc=pbonzini@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox