Skip to contentSkip to conversation

KVM: x86: Supplement __cr4_reserved_bits() with X86_FEATURE_PCID check

PATCH Applied Vitaly Kuznetsov 2 participants 2 messages Feb 1, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: x86: Supplement __cr4_reserved_bits() with X86_FEATURE_PCID check

Commit 7a873e455567 ("KVM: selftests: Verify supported CR4 bits can be set before KVM_SET_CPUID2") reveals that KVM allows to set X86_CR4_PCIDE even when PCID support is missing:

==== Test Assertion Failure ====
x86_64/set_sregs_test.c:41: rc
pid=6956 tid=6956 - Invalid argument

     1	0x000000000040177d: test_cr4_feature_bit at set_sregs_test.c:41
     2	0x00000000004014fc: main at set_sregs_test.c:119
     3	0x00007f2d9346d041: ?? ??:0
     4	0x000000000040164d: _start at ??:?

KVM allowed unsupported CR4 bit (0x20000)

Add X86_FEATURE_PCID feature check to __cr4_reserved_bits() to make kvm_is_valid_cr4() fail.

---
 arch/x86/kvm/x86.h | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/kvm/x86.h +2 -0
index c5ee0f5ce0f1..0f727b50bd3d 100644
@@ -425,6 +425,8 @@ bool kvm_msr_allowed(struct kvm_vcpu *vcpu, u32 index, u32 type);
 		__reserved_bits |= X86_CR4_UMIP;        \
 	if (!__cpu_has(__c, X86_FEATURE_VMX))           \
 		__reserved_bits |= X86_CR4_VMXE;        \
+	if (!__cpu_has(__c, X86_FEATURE_PCID))          \
+		__reserved_bits |= X86_CR4_PCIDE;       \
 	__reserved_bits;                                \
 })
 
Signature · 1 line
2.29.2
maintainer Applied
#1 lore raw
Quoted 27 lines · Vitaly Kuznetsov

Commit 7a873e455567 ("KVM: selftests: Verify supported CR4 bits can be set before KVM_SET_CPUID2") reveals that KVM allows to set X86_CR4_PCIDE even when PCID support is missing:

==== Test Assertion Failure ====
x86_64/set_sregs_test.c:41: rc
pid=6956 tid=6956 - Invalid argument

      1	0x000000000040177d: test_cr4_feature_bit at set_sregs_test.c:41
      2	0x00000000004014fc: main at set_sregs_test.c:119
      3	0x00007f2d9346d041: ?? ??:0
      4	0x000000000040164d: _start at ??:?

KVM allowed unsupported CR4 bit (0x20000)

Add X86_FEATURE_PCID feature check to __cr4_reserved_bits() to make kvm_is_valid_cr4() fail.

---
  arch/x86/kvm/x86.h | 2 ++
  1 file changed, 2 insertions(+)
arch/x86/kvm/x86.h +0 -0
index c5ee0f5ce0f1..0f727b50bd3d 100644

arch/x86/kvm/x86.h bool kvm_msr_allowed(struct kvm_vcpu *vcpu, u32 index, u32 type); · line 432

Quoted 8 lines
arch/x86/kvm/x86.h +2 -0
@@ -425,6 +425,8 @@ bool kvm_msr_allowed(struct kvm_vcpu *vcpu, u32 index, u32 type);
  		__reserved_bits |= X86_CR4_UMIP;        \
  	if (!__cpu_has(__c, X86_FEATURE_VMX))           \
  		__reserved_bits |= X86_CR4_VMXE;        \
+	if (!__cpu_has(__c, X86_FEATURE_PCID))          \
+		__reserved_bits |= X86_CR4_PCIDE;       \
  	__reserved_bits;                                \
  })
 

Queued, thanks.

Paolo