From: Sean Christopherson <seanjc@google.com>
To: Robert Hoo <robert.hoo.linux@gmail.com>
Cc: Robert Hoo <robert.hu@intel.com>,
pbonzini@redhat.com, kvm@vger.kernel.org
Subject: Re: [PATCH 2/3] KVM: VMX: Remove a unnecessary cpu_has_vmx_desc() check in vmx_set_cr4()
Date: Wed, 15 Mar 2023 09:35:58 -0700 [thread overview]
Message-ID: <ZBHz7kL7wSRZzvKk@google.com> (raw)
In-Reply-To: <CA+wubQAXBFthBhsNqWDtY=Qf4-FtfJ3dojJctXXg=iokXJRbmg@mail.gmail.com>
On Sat, Mar 11, 2023, Robert Hoo wrote:
> Sean Christopherson <seanjc@google.com> 于2023年3月11日周六 00:12写道:
> >
> > On Fri, Mar 10, 2023, Robert Hoo wrote:
> > > Remove the unnecessary cpu_has_vmx_desc() check for emulating UMIP.
> >
> > It's not unnecessary. See commit 64f7a11586ab ("KVM: vmx: update sec exec controls
> > for UMIP iff emulating UMIP"). Dropping the check will cause KVM to execute
> >
> > secondary_exec_controls_clearbit(vmx, SECONDARY_EXEC_DESC);
> >
> > on CPUs that don't have SECONDARY_VM_EXEC_CONTROL.
>
> Sorry I don't follow you.
> My point is that, given it has passed kvm_is_valid_cr4() (in kvm_set_cr4()),
> we can assert boot_cpu_has(X86_FEATURE_UMIP) and vmx_umip_emulated() must be
> at least one true.
This assertion is wrong for the case where guest.CR4.UMIP=0. The below code is
not guarded with a check on guest.CR4.UMIP. If the vmx_umip_emulated() check goes
away and guest.CR4.UMIP=0, KVM will attempt to write secondary controls.
Technically, now that controls_shadow exists, KVM won't actually do a VMWRITE,
but I most definitely don't want to rely on controls_shadow for functional
correctness. And controls_shadow aside, the "vmx_umip_emulated()" effectively
serves as documentation for why KVM is mucking with UMIP when it's obviously not
supported in hardware.
if (!boot_cpu_has(X86_FEATURE_UMIP) && vmx_umip_emulated()) {
if (cr4 & X86_CR4_UMIP) {
secondary_exec_controls_setbit(vmx, SECONDARY_EXEC_DESC);
hw_cr4 &= ~X86_CR4_UMIP;
} else if (!is_guest_mode(vcpu) ||
!nested_cpu_has2(get_vmcs12(vcpu), SECONDARY_EXEC_DESC)) {
secondary_exec_controls_clearbit(vmx, SECONDARY_EXEC_DESC);
}
}
next prev parent reply other threads:[~2023-03-15 16:36 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-10 12:57 [PATCH 0/3] Some code refactor surround CR4.UMIP virtualization Robert Hoo
2023-03-10 12:57 ` [PATCH 1/3] KVM: VMX: Rename vmx_umip_emulated() to cpu_has_vmx_desc() Robert Hoo
2023-03-10 15:59 ` Sean Christopherson
2023-03-11 1:59 ` Robert Hoo
2023-03-15 17:50 ` Sean Christopherson
2023-03-31 9:48 ` Robert Hoo
2023-04-10 18:12 ` Sean Christopherson
2023-03-10 12:57 ` [PATCH 2/3] KVM: VMX: Remove a unnecessary cpu_has_vmx_desc() check in vmx_set_cr4() Robert Hoo
2023-03-10 16:12 ` Sean Christopherson
2023-03-11 2:36 ` Robert Hoo
2023-03-15 16:35 ` Sean Christopherson [this message]
2023-03-31 9:48 ` Robert Hoo
2023-04-10 18:35 ` Sean Christopherson
2023-04-11 5:04 ` Hoo Robert
2023-03-10 12:57 ` [PATCH 3/3] KVM: VMX: Use the canonical interface to read CR4.UMIP bit Robert Hoo
2023-03-10 16:27 ` Sean Christopherson
[not found] ` <CA+wubQBsiaH_==UJ-JUi7hwS8W1i5MLZ-dPuw2smVH8Z0sqXsw@mail.gmail.com>
2023-03-28 4:38 ` Sean Christopherson
2023-03-31 9:48 ` Robert Hoo
2023-04-10 18:35 ` 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=ZBHz7kL7wSRZzvKk@google.com \
--to=seanjc@google.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=robert.hoo.linux@gmail.com \
--cc=robert.hu@intel.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.