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

From: Karl Mehltretter

Date: Sun Aug 09 2026 - 14:12:12 EST


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.

I reproduced this with failslab. If init_nested_s2_mmu() fails while
allocating pgt, before mmu->arch is assigned, the for loop still
increments i. Thus while (--i >= 0) passes the failed entry to
kvm_free_stage2_pgd(). The resulting log is:

Unable to handle kernel paging request at virtual address fffffffffffff650
Internal error: Oops: 0000000096000046 [#1] SMP
Call trace:
_raw_write_lock
kvm_free_stage2_pgd
kvm_vcpu_init_nested

Thanks,
Karl