public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Junaid Shahid <junaids@google.com>,
	Sean Christopherson <seanjc@google.com>,
	Sasha Levin <sashal@kernel.org>,
	pbonzini@redhat.com, tglx@linutronix.de, mingo@redhat.com,
	bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org,
	kvm@vger.kernel.org
Subject: [PATCH AUTOSEL 5.19 03/10] kvm: x86: Do proper cleanup if kvm_x86_ops->vm_init() fails
Date: Fri, 14 Oct 2022 09:52:14 -0400	[thread overview]
Message-ID: <20221014135222.2109334-3-sashal@kernel.org> (raw)
In-Reply-To: <20221014135222.2109334-1-sashal@kernel.org>

From: Junaid Shahid <junaids@google.com>

[ Upstream commit b24ede22538b4d984cbe20532bbcb303692e7f52 ]

If vm_init() fails [which can happen, for instance, if a memory
allocation fails during avic_vm_init()], we need to cleanup some
state in order to avoid resource leaks.

Signed-off-by: Junaid Shahid <junaids@google.com>
Link: https://lore.kernel.org/r/20220729224329.323378-1-junaids@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 arch/x86/kvm/x86.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 8c2815151864..8d2211b22ff3 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -11842,6 +11842,10 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
 	if (ret)
 		goto out_page_track;
 
+	ret = static_call(kvm_x86_vm_init)(kvm);
+	if (ret)
+		goto out_uninit_mmu;
+
 	INIT_HLIST_HEAD(&kvm->arch.mask_notifier_list);
 	INIT_LIST_HEAD(&kvm->arch.assigned_dev_head);
 	atomic_set(&kvm->arch.noncoherent_dma_count, 0);
@@ -11877,8 +11881,10 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
 	kvm_hv_init_vm(kvm);
 	kvm_xen_init_vm(kvm);
 
-	return static_call(kvm_x86_vm_init)(kvm);
+	return 0;
 
+out_uninit_mmu:
+	kvm_mmu_uninit_vm(kvm);
 out_page_track:
 	kvm_page_track_cleanup(kvm);
 out:
-- 
2.35.1


  parent reply	other threads:[~2022-10-14 13:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-14 13:52 [PATCH AUTOSEL 5.19 01/10] signal: break out of wait loops on kthread_stop() Sasha Levin
2022-10-14 13:52 ` [PATCH AUTOSEL 5.19 02/10] powerpc/selftests: Use timersub() for gettimeofday() Sasha Levin
2022-10-14 13:52 ` Sasha Levin [this message]
2022-11-02 18:01   ` [PATCH AUTOSEL 5.19 03/10] kvm: x86: Do proper cleanup if kvm_x86_ops->vm_init() fails Paolo Bonzini
2022-10-14 13:52 ` [PATCH AUTOSEL 5.19 04/10] powerpc/math-emu: Remove -w build flag and fix warnings Sasha Levin
2022-10-14 13:52 ` [PATCH AUTOSEL 5.19 05/10] powerpc/85xx: Fix fall-through warning for Clang Sasha Levin
2022-10-14 13:52 ` [PATCH AUTOSEL 5.19 06/10] powerpc: Remove direct call to personality syscall handler Sasha Levin
2022-10-14 13:52 ` [PATCH AUTOSEL 5.19 07/10] powerpc/perf: Fix branch_filter support for multiple filters Sasha Levin
2022-10-14 13:52 ` [PATCH AUTOSEL 5.19 08/10] powerpc/rtas: block error injection when locked down Sasha Levin
2022-10-14 13:52 ` [PATCH AUTOSEL 5.19 09/10] powerpc/mm: Fix UBSAN warning reported on hugetlb Sasha Levin
2022-10-14 13:52 ` [PATCH AUTOSEL 5.19 10/10] powerpc/64: Fix msr_check_and_set/clear MSR[EE] race Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221014135222.2109334-3-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=junaids@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox