From: Chao Gao <chao.gao@intel.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Maxim Levitsky <mlevitsk@redhat.com>, <kvm@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, Borislav Petkov <bp@alien8.de>,
"H. Peter Anvin" <hpa@zytor.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Ingo Molnar <mingo@redhat.com>, <x86@kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Dave Hansen <dave.hansen@linux.intel.com>
Subject: Re: [PATCH v2 1/2] KVM: x86: relax canonical check for some x86 architectural msrs
Date: Mon, 5 Aug 2024 14:12:08 +0800 [thread overview]
Message-ID: <ZrBtOAzZurwvWKZM@chao-email> (raw)
In-Reply-To: <Zq0A9R5R_MAFrqTP@google.com>
>Checking kvm_cpu_cap_has() is wrong. What the _host_ supports is irrelevant,
>what matters is what the guest CPU supports, i.e. this should check guest CPUID.
>Ah, but for safety, KVM also needs to check kvm_cpu_cap_has() to prevent faulting
>on a bad load into hardware. Which means adding a "governed" feature until my
>CPUID rework lands.
>
>And I'm pretty sure this fix is incomplete, as nVMX's consistency checks on MSRs
>that are loaded via dedicated VMCS fields likely need the same treatment, e.g.
>presumably these checks should follow the MSR handling.
>
> if (CC(is_noncanonical_address(vmcs12->host_ia32_sysenter_esp, vcpu)) ||
> CC(is_noncanonical_address(vmcs12->host_ia32_sysenter_eip, vcpu)))
> return -EINVAL;
>
>
> (CC(is_noncanonical_address(vmcs12->guest_bndcfgs & PAGE_MASK, vcpu)) ||
>
>So I think we probably need a dedicated helper for MSRs.
+1
>
>Hmm, and I suspect these are wrong too, but in a different way. Toggling host
Actually they are wrong in the _same_ way because ...
>LA57 on VM-Exit is legal[*], so logically, KVM should use CR4.LA57 from
>vmcs12->host_cr4, not the vCPU's current CR4 value. Which makes me _really_
>curious if Intel CPUs actually get that right.
... according to Section 3.1 in 5-level paging whitepaper[1], on VM entry, the
canonicality checking about the host/guest state (except guest RIP) is also
based on whether the CPU supports 5-level paging, i.e., host or guest CR4.LA57
isn't checked.
[1]: https://cdrdv2.intel.com/v1/dl/getContent/671442?fileName=5-level-paging-white-paper.pdf
>
> 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)) ||
> CC(is_noncanonical_address(vmcs12->host_rip, vcpu)))
not sure how host_rip should be handled because it isn't documented in that
spec.
> return -EINVAL;
>
>[*] https://lore.kernel.org/all/20210622211124.3698119-1-seanjc@google.com
next prev parent reply other threads:[~2024-08-05 6:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-02 15:16 [PATCH v2 0/2] Relax canonical checks on some arch msrs Maxim Levitsky
2024-08-02 15:16 ` [PATCH v2 1/2] KVM: x86: relax canonical check for some x86 architectural msrs Maxim Levitsky
2024-08-02 15:53 ` Sean Christopherson
2024-08-05 6:12 ` Chao Gao [this message]
2024-08-05 11:01 ` mlevitsk
2024-08-05 16:39 ` Sean Christopherson
2024-08-05 18:07 ` mlevitsk
2024-08-05 20:54 ` Sean Christopherson
2024-08-02 15:16 ` [PATCH v2 2/2] KVM: SVM: fix emulation of msr reads/writes of MSR_FS_BASE and MSR_GS_BASE Maxim Levitsky
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=ZrBtOAzZurwvWKZM@chao-email \
--to=chao.gao@intel.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=seanjc@google.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
all inboxes | Powered by JetHome®