Skip to contentSkip to conversation

KVM: x86: Mark CR4.UMIP as reserved based on associated CPUID bit

PATCH Applied Sean Christopherson 3 participants 3 messages Jan 28, 2020 – Feb 5, 2020

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

PATCH 1/1 KVM: x86: Mark CR4.UMIP as reserved based on associated CPUID bit

Re-add code to mark CR4.UMIP as reserved if UMIP is not supported by the host. The UMIP handling was unintentionally dropped during a recent refactoring.

Not flagging CR4.UMIP allows the guest to set its CR4.UMIP regardless of host support or userspace desires. On CPUs with UMIP support, including emulated UMIP, this allows the guest to enable UMIP against the wishes of the userspace VMM. On CPUs without any form of UMIP, this results in a failed VM-Enter due to invalid guest state.

Fixes 345599f9a2928 ("KVM: x86: Add macro to ensure reserved cr4 bits checks stay in sync")
---
 arch/x86/kvm/x86.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/kvm/x86.c +2 -0
index 7e3f1d937224..e70d1215638a 100644
@@ -898,6 +898,8 @@ EXPORT_SYMBOL_GPL(kvm_set_xcr);
 		__reserved_bits |= X86_CR4_PKE;		\
 	if (!__cpu_has(__c, X86_FEATURE_LA57))		\
 		__reserved_bits |= X86_CR4_LA57;	\
+	if (!__cpu_has(__c, X86_FEATURE_UMIP))		\
+		__reserved_bits |= X86_CR4_UMIP;	\
 	__reserved_bits;				\
 })
 
Signature · 1 line
2.24.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Sean Christopherson

Re-add code to mark CR4.UMIP as reserved if UMIP is not supported by the host. The UMIP handling was unintentionally dropped during a recent refactoring.

Not flagging CR4.UMIP allows the guest to set its CR4.UMIP regardless of host support or userspace desires. On CPUs with UMIP support, including emulated UMIP, this allows the guest to enable UMIP against the wishes of the userspace VMM. On CPUs without any form of UMIP, this results in a failed VM-Enter due to invalid guest state.

Fixes 345599f9a2928 ("KVM: x86: Add macro to ensure reserved cr4 bits checks stay in sync")

This one in only in kvm/next so just in case another force-push is around the corner I'd suggest we squash this change in :-)

Quoted 10 lines
---
 arch/x86/kvm/x86.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/kvm/x86.c +0 -0
index 7e3f1d937224..e70d1215638a 100644

arch/x86/kvm/x86.c EXPORT_SYMBOL_GPL(kvm_set_xcr); · line 904

Quoted 7 lines
arch/x86/kvm/x86.c +2 -0
@@ -898,6 +898,8 @@ EXPORT_SYMBOL_GPL(kvm_set_xcr);
 		__reserved_bits |= X86_CR4_PKE;		\
 	if (!__cpu_has(__c, X86_FEATURE_LA57))		\
 		__reserved_bits |= X86_CR4_LA57;	\
+	if (!__cpu_has(__c, X86_FEATURE_UMIP))		\
+		__reserved_bits |= X86_CR4_UMIP;	\
 	__reserved_bits;				\
 })
Signature · 1 line
Vitaly
maintainer Applied
#2 lore raw
In reply to Sean Christopherson
Quoted 22 lines · Sean Christopherson

Re-add code to mark CR4.UMIP as reserved if UMIP is not supported by the host. The UMIP handling was unintentionally dropped during a recent refactoring.

Not flagging CR4.UMIP allows the guest to set its CR4.UMIP regardless of host support or userspace desires. On CPUs with UMIP support, including emulated UMIP, this allows the guest to enable UMIP against the wishes of the userspace VMM. On CPUs without any form of UMIP, this results in a failed VM-Enter due to invalid guest state.

Fixes 345599f9a2928 ("KVM: x86: Add macro to ensure reserved cr4 bits checks stay in sync")
---
 arch/x86/kvm/x86.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/kvm/x86.c +0 -0
index 7e3f1d937224..e70d1215638a 100644

arch/x86/kvm/x86.c EXPORT_SYMBOL_GPL(kvm_set_xcr); · line 905

Quoted 8 lines
arch/x86/kvm/x86.c +2 -0
@@ -898,6 +898,8 @@ EXPORT_SYMBOL_GPL(kvm_set_xcr);
 		__reserved_bits |= X86_CR4_PKE;		\
 	if (!__cpu_has(__c, X86_FEATURE_LA57))		\
 		__reserved_bits |= X86_CR4_LA57;	\
+	if (!__cpu_has(__c, X86_FEATURE_UMIP))		\
+		__reserved_bits |= X86_CR4_UMIP;	\
 	__reserved_bits;				\
 })
 

Queued, thanks.

Paolo