Skip to contentSkip to conversation

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

PATCH Applied Robert Hoo 2 participants 3 messages Mar 8, 2023 – Mar 24, 2023

Subsystems (3)
lore
Share & tools
lore

Robert Hoo

author
#0 lore raw

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

From: Robert Hoo <[email protected]>

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.

---
===Test==
kvm-unit-test pcid cases (pcid-asymmetric, pcid-disabled, pcid-enabled) passed.

---
 arch/x86/kvm/x86.c | 3 ---
 1 file changed, 3 deletions(-)
arch/x86/kvm/x86.c +0 -3
index f706621c35b8..96b3c510fdde 100644
@@ -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;

base-commit: 45dd9bc75d9adc9483f0c7d662ba6e73ed698a0b

Signature · 1 line
2.31.1
#1 lore raw
Quoted 9 lines · Robert Hoo

From: Robert Hoo <[email protected]>

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.

---

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).

maintainer Applied
#2 lore raw
In reply to Robert Hoo
Quoted 5 lines · Robert Hoo

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