[PATCH] KVM: VMX: Don't register posted interrupt wakeup handler if alloc_kvm_area() fails

From: Hou Wenlong

Date: Tue Jan 13 2026 - 07:02:36 EST


Unregistering the posted interrupt wakeup handler only happens during
hardware unsetup. Therefore, if alloc_kvm_area() fails and continue to
register the posted interrupt wakeup handler, this will leave the global
posted interrupt wakeup handler pointer in an incorrect state. Although
it should not be an issue, it's still better to change it.

Signed-off-by: Hou Wenlong <houwenlong.hwl@xxxxxxxxxxxx>
---
arch/x86/kvm/vmx/vmx.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 9b92f672ccfe..676f32aa72bb 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -8829,8 +8829,11 @@ __init int vmx_hardware_setup(void)
}

r = alloc_kvm_area();
- if (r && nested)
- nested_vmx_hardware_unsetup();
+ if (r) {
+ if (nested)
+ nested_vmx_hardware_unsetup();
+ return r;
+ }

kvm_set_posted_intr_wakeup_handler(pi_wakeup_handler);


base-commit: f62b64b970570c92fe22503b0cdc65be7ce7fc7c
--
2.31.1