diff mbox series

KVM: x86: Remove a redundant guest cpuid check in kvm_set_cr4()

Message ID 20230308072936.1293101-1-robert.hu@intel.com (mailing list archive)
State New, archived
Headers show
Series KVM: x86: Remove a redundant guest cpuid check in kvm_set_cr4() | expand

Commit Message

Robert Hoo March 8, 2023, 7:29 a.m. UTC
From: Robert Hoo <robert.hu@linux.intel.com>

If !guest_cpuid_has(vcpu, X86_FEATURE_PCID), CR4.PCIDE would have been in
vcpu->arch.cr4_guest_rsvd_bits and failed earlier kvm_is_valid_cr4() check.
Remove this meaningless check.

Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Signed-off-by: Robert Hoo <robert.hu@linux.intel.com>
---
===Test==
kvm-unit-test pcid cases (pcid-asymmetric, pcid-disabled, pcid-enabled)
passed.
---
 arch/x86/kvm/x86.c | 3 ---
 1 file changed, 3 deletions(-)


base-commit: 45dd9bc75d9adc9483f0c7d662ba6e73ed698a0b

Comments

Sean Christopherson March 8, 2023, 8:02 p.m. UTC | #1
On Wed, Mar 08, 2023, Robert Hoo wrote:
> From: Robert Hoo <robert.hu@linux.intel.com>
> 
> If !guest_cpuid_has(vcpu, X86_FEATURE_PCID), CR4.PCIDE would have been in
> vcpu->arch.cr4_guest_rsvd_bits and failed earlier kvm_is_valid_cr4() check.
> Remove this meaningless check.
> 
> Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
> Signed-off-by: Robert Hoo <robert.hu@linux.intel.com>
> ---

Nice!  I think I'll add

Fixes: 4683d758f48e ("KVM: x86: Supplement __cr4_reserved_bits() with X86_FEATURE_PCID check")

when applying (won't happen until next week).
Sean Christopherson March 24, 2023, 11:38 p.m. UTC | #2
On Wed, 08 Mar 2023 15:29:36 +0800, Robert Hoo wrote:
> If !guest_cpuid_has(vcpu, X86_FEATURE_PCID), CR4.PCIDE would have been in
> vcpu->arch.cr4_guest_rsvd_bits and failed earlier kvm_is_valid_cr4() check.
> Remove this meaningless check.
> 
> 

Applied to kvm-x86 misc, thanks!

[1/1] KVM: x86: Remove a redundant guest cpuid check in kvm_set_cr4()
      https://github.com/kvm-x86/linux/commit/99b30869804e

--
https://github.com/kvm-x86/linux/tree/next
https://github.com/kvm-x86/linux/tree/fixes
diff mbox series

Patch

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index f706621c35b8..96b3c510fdde 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1174,9 +1174,6 @@  int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
 		return 1;
 
 	if ((cr4 & X86_CR4_PCIDE) && !(old_cr4 & X86_CR4_PCIDE)) {
-		if (!guest_cpuid_has(vcpu, X86_FEATURE_PCID))
-			return 1;
-
 		/* PCID can not be enabled when cr3[11:0]!=000H or EFER.LMA=0 */
 		if ((kvm_read_cr3(vcpu) & X86_CR3_PCID_MASK) || !is_long_mode(vcpu))
 			return 1;