Skip to contentSkip to conversation

kvm/svm: PKU not currently supported

PATCH Superseded John Allen 2 participants 3 messages Dec 19, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

John Allen

author
#0 lore raw

PATCH 1/1 kvm/svm: PKU not currently supported

Current SVM implementation does not have support for handling PKU. Guests running on a host with future AMD cpus that support the feature will read garbage from the PKRU register and will hit segmentation faults on boot as memory is getting marked as protected that should not be. Ensure that cpuid from SVM does not advertise the feature.

---
 arch/x86/kvm/svm.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/kvm/svm.c +2 -0
index 122d4ce3b1ab..f911aa1b41c8 100644
@@ -5933,6 +5933,8 @@ static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry)
 		if (avic)
 			entry->ecx &= ~bit(X86_FEATURE_X2APIC);
 		break;
+	case 0x7:
+		entry->ecx &= ~bit(X86_FEATURE_PKU);
 	case 0x80000001:
 		if (nested)
 			entry->ecx |= (1 << 2); /* Set SVM bit */
Signature · 1 line
2.24.0
#1 lore raw
Quoted 16 lines · John Allen

Current SVM implementation does not have support for handling PKU. Guests running on a host with future AMD cpus that support the feature will read garbage from the PKRU register and will hit segmentation faults on boot as memory is getting marked as protected that should not be. Ensure that cpuid from SVM does not advertise the feature.

---
 arch/x86/kvm/svm.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/kvm/svm.c +0 -0
index 122d4ce3b1ab..f911aa1b41c8 100644

arch/x86/kvm/svm.c static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry) · line 5937

Quoted 5 lines
arch/x86/kvm/svm.c +2 -0
@@ -5933,6 +5933,8 @@ static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry)
 		if (avic)
 			entry->ecx &= ~bit(X86_FEATURE_X2APIC);
 		break;
+	case 0x7:
+		entry->ecx &= ~bit(X86_FEATURE_PKU);

Would it make more sense to introduce kvm_x86_ops->pku_supported() (and return false for SVM and boot_cpu_has(X86_FEATURE_PKU) for vmx) so we don't set the bit in the first place?

Quoted 3 lines
arch/x86/kvm/svm.c +0 -0
 	case 0x80000001:
 		if (nested)
 			entry->ecx |= (1 << 2); /* Set SVM bit */
Signature · 1 line
Vitaly
author
#2 lore raw
Quoted 13 lines · Vitaly Kuznetsov
Quoted 11 lines · John Allen

Current SVM implementation does not have support for handling PKU. Guests running on a host with future AMD cpus that support the feature will read garbage from the PKRU register and will hit segmentation faults on boot as memory is getting marked as protected that should not be. Ensure that cpuid from SVM does not advertise the feature.

---
 arch/x86/kvm/svm.c | 2 ++
 1 file changed, 2 insertions(+)
Quoted 14 lines

arch/x86/kvm/svm.c static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry) · line 5937

Quoted 10 lines
arch/x86/kvm/svm.c +2 -0
index 122d4ce3b1ab..f911aa1b41c8 100644
@@ -5933,6 +5933,8 @@ static void svm_set_supported_cpuid(u32 func, struct kvm_cpuid_entry2 *entry)
 		if (avic)
 			entry->ecx &= ~bit(X86_FEATURE_X2APIC);
 		break;
+	case 0x7:
+		entry->ecx &= ~bit(X86_FEATURE_PKU);

Would it make more sense to introduce kvm_x86_ops->pku_supported() (and return false for SVM and boot_cpu_has(X86_FEATURE_PKU) for vmx) so we don't set the bit in the first place?

Yes, I think you're right. I had initially planned to do it that way so I already have a patch ready. I'll send it up pronto.

Quoted 8 lines
Quoted 4 lines
arch/x86/kvm/svm.c +0 -0
 	case 0x80000001:
 		if (nested)
 			entry->ecx |= (1 << 2); /* Set SVM bit */
Signature · 1 line
Vitaly