Skip to contentSkip to conversation

kvm/vmx: Make setup/unsetup under the same conditions

PATCH Superseded Peng Hao 2 participants 2 messages Feb 18, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Peng Hao

author
#0 lore raw

PATCH 1/1 kvm/vmx: Make setup/unsetup under the same conditions

Make sure nested_vmx_hardware_setup/unsetup are called in pairs under the same conditions.

---
 arch/x86/kvm/vmx/vmx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/vmx/vmx.c +1 -1
index 0ffcfe54eea5..5392def71093 100644
@@ -7852,7 +7852,7 @@ static __init int hardware_setup(void)
 	vmx_set_cpu_caps();
 
 	r = alloc_kvm_area();
-	if (r)
+	if (r && nested)
 		nested_vmx_hardware_unsetup();
 
 	kvm_set_posted_intr_wakeup_handler(pi_wakeup_handler);
Signature · 1 line
2.27.0
maintainer Reviewed-by on v1 1/1
#1 lore raw

"KVM: VMX" for the scope, or maybe even "KVM: nVMX:" despite this not touching vmx/nested.c. Either way (but not "kvm/vmx:").

Quoted 2 lines · Peng Hao

Make sure nested_vmx_hardware_setup/unsetup are called in pairs under the same conditions.

Probably worth adding a sentence to clarify that the existing code isn't buggy only because free_page() plays nice with getting passed '0' and vmx_bitmap is initialized to zero. Something like:

Make sure nested_vmx_hardware_setup/unsetup() are called in pairs under the same conditions. Calling nested_vmx_hardware_unsetup() when nested is false "works" right now because it only calls free_page() on zero- initialized pointers, but it's possible that more code will be added to nested_vmx_hardware_unsetup() in the future.

Quoted 22 lines
---
 arch/x86/kvm/vmx/vmx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/vmx/vmx.c +1 -1
index 0ffcfe54eea5..5392def71093 100644
@@ -7852,7 +7852,7 @@ static __init int hardware_setup(void)
 	vmx_set_cpu_caps();
 
 	r = alloc_kvm_area();
-	if (r)
+	if (r && nested)
 		nested_vmx_hardware_unsetup();
 
 	kvm_set_posted_intr_wakeup_handler(pi_wakeup_handler);
Signature · 1 line
2.27.0