Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Hyunwoo Kim <imv4bel@gmail.com>
Cc: Oliver Upton <oupton@kernel.org>,
	joey.gouly@arm.com, seiden@linux.ibm.com, suzuki.poulose@arm.com,
	yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org,
	christoffer.dall@arm.com, linux-arm-kernel@lists.infradead.org,
	kvmarm@lists.linux.dev
Subject: Re: [PATCH] KVM: arm64: Reallocate the nested_mmus array under the mmu_lock
Date: Fri, 05 Jun 2026 08:51:54 +0100	[thread overview]
Message-ID: <87cxy5a0h1.wl-maz@kernel.org> (raw)
In-Reply-To: <aiJgGBv3OCPNJJPc@v4bel>

On Fri, 05 Jun 2026 06:35:20 +0100,
Hyunwoo Kim <imv4bel@gmail.com> wrote:
> 
> On Thu, Jun 04, 2026 at 03:27:16PM -0700, Oliver Upton wrote:
> > Hi,
> > 
> > The shortlog is very confusing, since "allocate behind $LOCK" is usually
> > something alarming. Maybe instead:
> > 
> >   KVM: arm64: Reassign nested_mmus array behind mmu_lock
> 
> heh, that's confusing indeed. I'll change it that way.
> 
> > 
> > On Fri, Jun 05, 2026 at 03:30:00AM +0900, Hyunwoo Kim wrote:
> > > Code that walks kvm->arch.nested_mmus[] holds kvm->mmu_lock. By contrast,
> > > kvm_vcpu_init_nested() reallocates the array and frees the old buffer while
> > > holding only kvm->arch.config_lock, so a walker can reference the freed
> > > array.
> > 
> > It wouldn't hurt to share slightly more information here. Are you
> > dealing with a concurrent MMU notifier?
> 
> Yes. The MMU notifier path also walks nested_mmus[] under mmu_lock.
> kvm_vcpu_init_nested() holds only config_lock, so if a notifier fires
> during vCPU init, it races with the array realloc and free.
> 
> Here's the reworked changelog. Should I send v2?
> 
>   kvm->arch.nested_mmus[] is walked under kvm->mmu_lock, including from the
>   MMU notifier path (kvm_unmap_gfn_range() -> kvm_nested_s2_unmap()), which
>   can run at any time. kvm_vcpu_init_nested() reallocates the array and frees
>   the old buffer while holding only kvm->arch.config_lock, so such a walker
>   can reference the freed array.
> 
>   Allocate the new array outside of mmu_lock, as the allocation can sleep.
>   Under the lock, copy the existing entries, fix up the back pointers and
>   reassign the array. Free the old buffer after dropping the lock, as
>   kvfree() can sleep as well.

That's significantly better. Please send a v2 with this.

Thanks,

	M.

-- 
Jazz isn't dead. It just smells funny.


      reply	other threads:[~2026-06-05  7:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-04 18:30 [PATCH] KVM: arm64: Reallocate the nested_mmus array under the mmu_lock Hyunwoo Kim
2026-06-04 22:27 ` Oliver Upton
2026-06-04 22:58   ` Sean Christopherson
2026-06-05  5:35   ` Hyunwoo Kim
2026-06-05  7:51     ` Marc Zyngier [this message]

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=87cxy5a0h1.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=christoffer.dall@arm.com \
    --cc=imv4bel@gmail.com \
    --cc=joey.gouly@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=oupton@kernel.org \
    --cc=seiden@linux.ibm.com \
    --cc=suzuki.poulose@arm.com \
    --cc=will@kernel.org \
    --cc=yuzenghui@huawei.com \
    /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