kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fix: KVM: PPC: Book3S HV: Clean up on uvmem initialization failure
@ 2026-11-17  3:22 Haoxiang Li
  2026-11-17  3:32 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Haoxiang Li @ 2026-11-17  3:22 UTC (permalink / raw)
  To: maddy, npiggin, mpe, chleroy, ritesh.list, sshegde, bharata,
	paulus
  Cc: linuxppc-dev, kvm, linux-kernel, Haoxiang Li

When kvmppc_uvmem_init() fails, kvmppc_book3s_init_hv() returns
directly, bypassing the existing error path. Jump to the existing
error path to clean up before returning the error.

Fixes: ca9f4942670c ("KVM: PPC: Book3S HV: Support for running secure guests")
Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
---
 arch/powerpc/kvm/book3s_hv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
index 22283d46e8fe..620097f292b8 100644
--- a/arch/powerpc/kvm/book3s_hv.c
+++ b/arch/powerpc/kvm/book3s_hv.c
@@ -6743,7 +6743,7 @@ static int kvmppc_book3s_init_hv(void)
 	r = kvmppc_uvmem_init();
 	if (r < 0) {
 		pr_err("KVM-HV: kvmppc_uvmem_init failed %d\n", r);
-		return r;
+		goto err;
 	}
 
 #if defined(CONFIG_KVM_XICS)
-- 
2.25.1


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

* Re: [PATCH] fix: KVM: PPC: Book3S HV: Clean up on uvmem initialization failure
  2026-11-17  3:22 [PATCH] fix: KVM: PPC: Book3S HV: Clean up on uvmem initialization failure Haoxiang Li
@ 2026-11-17  3:32 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-17  3:32 UTC (permalink / raw)
  To: Haoxiang Li; +Cc: kvm

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] KVM: PPC: Book3S HV: inaccurate Fixes tag and subject prefix
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] KVM: PPC: Book3S HV: missing nestedv2 cleanup in
  kvmppc_core_vcpu_create_hv() [1]
--

commit 07a9a6f45bc7e7b1aca445fde7a6c5495883e5b7
Author: Haoxiang Li <haoxiang_li2024@163.com>

> fix: KVM: PPC: Book3S HV: Clean up on uvmem initialization failure
>
> When kvmppc_uvmem_init() fails, kvmppc_book3s_init_hv() returns
> directly, bypassing the existing error path. Jump to the existing
> error path to clean up before returning the error.
>
> Fixes: ca9f4942670c ("KVM: PPC: Book3S HV: Support for running secure guests")
> Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>

[Severity: Low]
In commit ca9f4942670c ("KVM: PPC: Book3S HV: Support for running secure
guests"), kvmppc_book3s_init_hv() had no err: cleanup label and ended
with return r right after calling kvmppc_uvmem_init().  The err: cleanup
label calling kvmhv_nested_exit() and kvmppc_radix_exit() was introduced
later by commit 175be7e5800e ("KVM: PPC: Book3S HV: Free allocated memory
if module init fails"), which converted the other failure paths to goto
err but missed the kvmppc_uvmem_init() check.  Backporting this patch to
a tree without commit 175be7e5800e ("KVM: PPC: Book3S HV: Free allocated
memory if module init fails") will fail to build because the err label
does not exist, so the Fixes tag should point to that commit instead.

Also, the commit subject should drop the leading "fix: " prefix and start
with "KVM: PPC: Book3S HV:".

> diff --git a/arch/powerpc/kvm/book3s_hv.c b/arch/powerpc/kvm/book3s_hv.c
> index 22283d46e8fe6..620097f292b89 100644
> --- a/arch/powerpc/kvm/book3s_hv.c
> +++ b/arch/powerpc/kvm/book3s_hv.c
> @@ -6743,7 +6743,7 @@ static int kvmppc_book3s_init_hv(void)
>  	r = kvmppc_uvmem_init();
>  	if (r < 0) {
>  		pr_err("KVM-HV: kvmppc_uvmem_init failed %d\n", r);
> -		return r;
> +		goto err;
>  	}

[Severity: High]
This problem wasn't introduced by this patch, but in the same file
kvmppc_core_vcpu_create_hv() has a similar error-return leak [1]
when vcore lookup or creation fails:

arch/powerpc/kvm/book3s_hv.c:kvmppc_core_vcpu_create_hv() {
	...
	if (kvmhv_is_nestedv2()) {
		err = kvmhv_nestedv2_vcpu_create(vcpu, &vcpu->arch.nestedv2_io);
		if (err < 0)
			return err;
	}
	...
	if (!vcore)
		return err;
	...
}

When kvmhv_is_nestedv2() is true, kvmhv_nestedv2_vcpu_create() allocates
guest state buffers and message structures in vcpu->arch.nestedv2_io.  If
vcore is NULL (for example, when kvmppc_vcore_create() fails or the vCPU
ID collides), returning err directly without calling
kvmhv_nestedv2_vcpu_free() leaks those allocations because the caller
kvm_arch_vcpu_create() only unwinds via kvmppc_subarch_vcpu_uninit().

[1] https://sashiko.dev/#/bug/linux-46c997c5-a07e-43e8-b2c9-b5fd597c3c0c

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117032247.1053075-1-haoxiang_li2024@163.com?part=1

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

end of thread, other threads:[~2026-11-17  3:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17  3:22 [PATCH] fix: KVM: PPC: Book3S HV: Clean up on uvmem initialization failure Haoxiang Li
2026-11-17  3:32 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).