The patch below does not apply to the 4.19-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <stable@xxxxxxxxxxxxxxx>. Possible dependencies: 917401f26a6a ("KVM: x86: nSVM: leave nested mode on vCPU free") 2fcf4876ada8 ("KVM: nSVM: implement on demand allocation of the nested state") 72f211ecaa80 ("KVM: x86: allow kvm_x86_ops.set_efer to return an error value") fd6fa73d1337 ("KVM: x86: SVM: Prevent MSR passthrough when MSR access is denied") 476c9bd8e997 ("KVM: x86: Prepare MSR bitmaps for userspace tracked MSRs") d85a8034c016 ("KVM: VMX: Rename "find_msr_entry" to "vmx_find_uret_msr"") eb3db1b13788 ("KVM: VMX: Rename the "shared_msr_entry" struct to "vmx_uret_msr"") ce833b2324ba ("KVM: VMX: Prepend "MAX_" to MSR array size defines") 7e34fbd05c63 ("KVM: x86: Rename "shared_msrs" to "user_return_msrs"") 8d22b90e942c ("KVM: SVM: refactor exit labels in svm_create_vcpu") 0681de1b8369 ("KVM: SVM: use __GFP_ZERO instead of clear_page") f4c847a95654 ("KVM: SVM: refactor msr permission bitmap allocation") 0dd16b5b0c9b ("KVM: nSVM: rename nested vmcb to vmcb12") 1feaba144cd3 ("KVM: SVM: rename a variable in the svm_create_vcpu") bf3c0e5e7102 ("Merge branch 'x86-seves-for-paolo' of https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip into HEAD") thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From 917401f26a6af5756d89b550a8e1bd50cf42b07e Mon Sep 17 00:00:00 2001 From: Maxim Levitsky <mlevitsk@xxxxxxxxxx> Date: Thu, 3 Nov 2022 16:13:43 +0200 Subject: [PATCH] KVM: x86: nSVM: leave nested mode on vCPU free If the VM was terminated while nested, we free the nested state while the vCPU still is in nested mode. Soon a warning will be added for this condition. Cc: stable@xxxxxxxxxxxxxxx Signed-off-by: Maxim Levitsky <mlevitsk@xxxxxxxxxx> Message-Id: <20221103141351.50662-2-mlevitsk@xxxxxxxxxx> Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 9f88c8e6766e..098f04bec8ef 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1438,6 +1438,7 @@ static void svm_vcpu_free(struct kvm_vcpu *vcpu) */ svm_clear_current_vmcb(svm->vmcb); + svm_leave_nested(vcpu); svm_free_nested(svm); sev_free_vcpu(vcpu);