Re: [PATCH 1/2] KVM: arm64: nv: Allocate the shadow S2 MMUs individually

Marc Zyngier <[email protected]>
Newsgroups gmane.linux.kernel.stable,gmane.linux.ports.arm.kernel,gmane.linux.kernel
Message-ID <[email protected]>
On Sun, 09 Aug 2026 19:11:54 +0100,
Karl Mehltretter <[email protected]> wrote:
> 
> On Sun, Aug 09, 2026 at 12:39:10PM +0100, Marc Zyngier wrote:
> > My current patch is as follows, and so far, I haven't seen much that I
> > like better.
> > 
> 
> Hi Marc,
> 
> Thanks for your revised patch.
> I think one correctness issue is in there. 
> 
> > +		for (i = 0; !ret && i < S2_MMU_PER_VCPU; i++)
> > +			ret = init_nested_s2_mmu(kvm, &tmp[i]);
> 
> > +		if (ret) {
> > +			while (--i >= 0)
> > +				kvm_free_stage2_pgd(&tmp[i]);
> 
> The increment expression of the for loop still runs after an error.

Yup. Should be fixed with

diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c
index 5b69a0f382320..50d6dcc75582c 100644
--- a/arch/arm64/kvm/nested.c
+++ b/arch/arm64/kvm/nested.c
@@ -96,8 +96,11 @@ int kvm_vcpu_init_nested(struct kvm_vcpu *vcpu)
 		if (!tmp)
 			ret = -ENOMEM;
 
-		for (i = 0; !ret && i < S2_MMU_PER_VCPU; i++)
+		for (i = 0; !ret && i < S2_MMU_PER_VCPU; i++) {
 			ret = init_nested_s2_mmu(kvm, &tmp[i]);
+			if (ret)
+				break;
+		}
 
 		if (ret) {
 			while (--i >= 0)

	M.

-- 
Without deviation from the norm, progress is not possible.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.