Skip to contentSkip to conversation

KVM: SVM: fix compilation with modular PSP and non-modular KVM

PATCH In review Paolo Bonzini 3 participants 4 messages Apr 13, 2020 – Apr 16, 2020

Subsystems (3)
lore
Share & tools
lore

Paolo Bonzini

author maintainer
#0 lore raw

PATCH 1/1 KVM: SVM: fix compilation with modular PSP and non-modular KVM

Use svm_sev_enabled() in order to cull all calls to PSP code. Otherwise, compilation fails with undefined symbols if the PSP device driver is compiled as a module and KVM is not.

---
 arch/x86/kvm/svm/sev.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/kvm/svm/sev.c +4 -1
index 0e3fc311d7da..364ffe32139c 100644
@@ -1117,7 +1117,7 @@ int __init sev_hardware_setup(void)
 	/* Maximum number of encrypted guests supported simultaneously */
 	max_sev_asid = cpuid_ecx(0x8000001F);
 
-	if (!max_sev_asid)
+        if (!svm_sev_enabled())
 		return 1;
 
 	/* Minimum ASID value that should be used for SEV guest */
@@ -1156,6 +1156,9 @@ int __init sev_hardware_setup(void)
 
 void sev_hardware_teardown(void)
 {
+        if (!svm_sev_enabled())
+                return;
+
 	bitmap_free(sev_asid_bitmap);
 	bitmap_free(sev_reclaim_asid_bitmap);
 
Signature · 1 line
2.18.2
#1 lore raw
Quoted 24 lines · Paolo Bonzini

Use svm_sev_enabled() in order to cull all calls to PSP code. Otherwise, compilation fails with undefined symbols if the PSP device driver is compiled as a module and KVM is not.

---
 arch/x86/kvm/svm/sev.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/kvm/svm/sev.c +1 -1
index 0e3fc311d7da..364ffe32139c 100644
@@ -1117,7 +1117,7 @@ int __init sev_hardware_setup(void)
 	/* Maximum number of encrypted guests supported simultaneously */
 	max_sev_asid = cpuid_ecx(0x8000001F);
 
-	if (!max_sev_asid)
+        if (!svm_sev_enabled())
 		return 1;
 
 	/* Minimum ASID value that should be used for SEV guest */

arch/x86/kvm/svm/sev.c int __init sev_hardware_setup(void) · line 1161

Quoted 6 lines
arch/x86/kvm/svm/sev.c +3 -0
@@ -1156,6 +1156,9 @@ int __init sev_hardware_setup(void)
 
 void sev_hardware_teardown(void)
 {
+        if (!svm_sev_enabled())
+                return;
+

Tabs instead of spaces. Checkpatch also whinges about going past 75 chars in the changelog.

Quoted 6 lines
arch/x86/kvm/svm/sev.c +0 -0
 	bitmap_free(sev_asid_bitmap);
 	bitmap_free(sev_reclaim_asid_bitmap);
 
Signature · 1 line
2.18.2
#2 lore raw
In reply to Paolo Bonzini
Quoted 3 lines · Paolo Bonzini

Use svm_sev_enabled() in order to cull all calls to PSP code. Otherwise, compilation fails with undefined symbols if the PSP device driver is compiled as a module and KVM is not.

The Kconfig support will set CONFIG_KVM_AMD_SEV to "n" in this situation, so it might be worth seeing if sev.o could be removed from the build at that point. I'll try and look at that when I get a chance, but I'm currently buried with a ton of other work.

Quoted 12 lines
---
  arch/x86/kvm/svm/sev.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/kvm/svm/sev.c +0 -0
index 0e3fc311d7da..364ffe32139c 100644

arch/x86/kvm/svm/sev.c int __init sev_hardware_setup(void) · line 1120

Quoted 5 lines
arch/x86/kvm/svm/sev.c +1 -1
@@ -1117,7 +1117,7 @@ int __init sev_hardware_setup(void)
  	/* Maximum number of encrypted guests supported simultaneously */
  	max_sev_asid = cpuid_ecx(0x8000001F);
 
-	if (!max_sev_asid)
+        if (!svm_sev_enabled())

It looks like these are spaces instead of tabs, could just be my email veiwer, though.

arch/x86/kvm/svm/sev.c int __init sev_hardware_setup(void) · line 1161

Quoted 10 lines
arch/x86/kvm/svm/sev.c +3 -0
  		return 1;
 
  	/* Minimum ASID value that should be used for SEV guest */
@@ -1156,6 +1156,9 @@ int __init sev_hardware_setup(void)
 
  void sev_hardware_teardown(void)
  {
+        if (!svm_sev_enabled())
+                return;
+

Ditto on the spaces/tabs thing, here.

Thanks,
Tom

Quoted 4 lines
arch/x86/kvm/svm/sev.c +0 -0
  	bitmap_free(sev_asid_bitmap);
  	bitmap_free(sev_reclaim_asid_bitmap);
 
author maintainer
#3 lore raw
Quoted 10 lines · Tom Lendacky
Quoted 4 lines · Paolo Bonzini

Use svm_sev_enabled() in order to cull all calls to PSP code.  Otherwise, compilation fails with undefined symbols if the PSP device driver is compiled
as a module and KVM is not.

The Kconfig support will set CONFIG_KVM_AMD_SEV to "n" in this situation, so it might be worth seeing if sev.o could be removed from the build at that point. I'll try and look at that when I get a chance, but I'm currently buried with a ton of other work.

It could be made to work, but you would have to add stubs to sev.h.

Paolo