public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] arch/powerpc/kvm: kvmppc_core_vcpu_create_hv: check for kzalloc failure
@ 2023-03-23  7:47 Kautuk Consul
  2023-03-28  4:36 ` Kautuk Consul
  2023-03-28  9:44 ` Michael Ellerman
  0 siblings, 2 replies; 9+ messages in thread
From: Kautuk Consul @ 2023-03-23  7:47 UTC (permalink / raw)
  To: Michael Ellerman, Nicholas Piggin, Christophe Leroy,
	Fabiano Rosas
  Cc: linuxppc-dev, linux-kernel, Kautuk Consul

kvmppc_vcore_create() might not be able to allocate memory through
kzalloc. In that case the kvm->arch.online_vcores shouldn't be
incremented.
Add a check for kzalloc failure and return with -ENOMEM from
kvmppc_core_vcpu_create_hv().

Signed-off-by: Kautuk Consul <kconsul@linux.vnet.ibm.com>
---
 arch/powerpc/kvm/book3s_hv.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 6ba68dd6190b..e29ee755c920 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -2968,13 +2968,17 @@ static int kvmppc_core_vcpu_create_hv(struct kvm_vcpu *vcpu)
 			pr_devel("KVM: collision on id %u", id);
 			vcore = NULL;
 		} else if (!vcore) {
+			vcore = kvmppc_vcore_create(kvm,
+					id & ~(kvm->arch.smt_mode - 1));
+			if (unlikely(!vcore)) {
+				mutex_unlock(&kvm->lock);
+				return -ENOMEM;
+			}
+
 			/*
 			 * Take mmu_setup_lock for mutual exclusion
 			 * with kvmppc_update_lpcr().
 			 */
-			err = -ENOMEM;
-			vcore = kvmppc_vcore_create(kvm,
-					id & ~(kvm->arch.smt_mode - 1));
 			mutex_lock(&kvm->arch.mmu_setup_lock);
 			kvm->arch.vcores[core] = vcore;
 			kvm->arch.online_vcores++;
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-03-30  4:21 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-23  7:47 [PATCH] arch/powerpc/kvm: kvmppc_core_vcpu_create_hv: check for kzalloc failure Kautuk Consul
2023-03-28  4:36 ` Kautuk Consul
2023-03-28  9:44 ` Michael Ellerman
2023-03-28 10:14   ` Kautuk Consul
2023-03-28 10:53     ` Kautuk Consul
2023-03-28 12:02       ` Michael Ellerman
2023-03-28 12:34         ` Kautuk Consul
2023-03-29 23:59           ` Michael Ellerman
2023-03-30  4:20             ` Kautuk Consul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox