mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Wei-Lin Chang <weilin.chang@arm.com>
Cc: Wang Han <wanghan@linux.alibaba.com>,
	linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
	linux-kernel@vger.kernel.org, oupton@kernel.org,
	tabba@google.com, joey.gouly@arm.com, seiden@linux.ibm.com,
	suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org,
	ljs@kernel.org, itaru.kitayama@fujitsu.com
Subject: Re: [PATCH v5 0/6] KVM: arm64: nv: Implement nested stage-2 reverse map (new data structure)
Date: Sat, 05 Sep 2026 14:48:41 +0100	[thread overview]
Message-ID: <87pkyr4xmu.wl-maz@kernel.org> (raw)
In-Reply-To: <eylfcgxs2xzu57czyuhkpmum45lpxyccyu2yh3mipr67aq3xo6@xinygxzavoja>

On Fri, 04 Sep 2026 23:42:15 +0100,
Wei-Lin Chang <weilin.chang@arm.com> wrote:
> 
> On Fri, Sep 04, 2026 at 08:49:14AM +0100, Marc Zyngier wrote:
> 
> [...]
> 
> > > > >
> > > > > The L1 was started with 8 vCPUs and 32 GiB of RAM using:
> > > > > 
> > > > >   qemu-system-aarch64 -smp 8 -m 32G \
> > > > >     -machine virt,accel=kvm,gic-version=3,virtualization=on \
> > > > >     -cpu host -nographic -enable-kvm \
> > > > >     -drive if=pflash,format=raw,readonly=on,file=pflash0_bak.img \
> > > > >     -drive if=pflash,format=raw,file=pflash1_bak.img \
> > > > >     -drive file=./ubuntu-vm.qcow2,format=qcow2,if=virtio,cache=none,aio=native \
> > > > >     -nic user,model=virtio-net-pci,hostfwd=tcp::11234-:22 \
> > > > >     -serial mon:stdio
> > > > > 
> > > > 
> > > > Puzzling. If you are only running an L1 in VHE mode, there is no
> > > > shadow S2, and therefore nothing to unmap. For shadow S2s to be built
> > > > and affect the MMU notifiers, you need to run an L2.
> > > 
> > > I was thinking the same at first, but realized even with L1 in VHE mode
> > > there is a small period of time where L1 runs in its EL1 during boot, so
> > > one nested MMU will become valid for each vCPU. That causes
> > > kvm_nested_s2_unmap() to iterate through the entire IPA space 8 times
> > > (-smp 8).
> > 
> > It should be one nested MMU for the whole VM, not one per vcpu.
> > That's assuming they share the same VMID+VTCR.
> > 
> > > What I am curious about is whether one single notifier unmap is enough
> > > to hang L1, or were there multiple notifier unmaps.
> > > 
> > > QEMU with -machine virt uses 40 IPA bits only, unmapping that takes:
> > > 1024  (4KB pages,  unmapping 1GB per iteration)
> > > 32768 (16KB pages, unmapping 32MB per iteration)
> > > 2048  (64KB pages, unmapping 512MB per iteration)
> > > iterations for each page size. There aren't many mappings in each
> > > iteration too. Does this really take that long on real hardware (even if
> > > this must be done 8 times)?
> > 
> > This should be close to being at zero cost, so something else is
> > amiss.
> > 
> 
> Guess what? I am completely wrong once again.
> 
> The complete range of the nested mmus isn't about the value
> supplied by KVM_VM_TYPE_ARM_IPA_SIZE. Instead it is the PARange exposed
> to the guest. That's because the guest hypervisor is allowed to expose
> whatever memory map it likes to its nested guests, as long as it is
> within the guest's PARange. This is explained clearly in
> init_nested_s2_mmu().
> 
> Now the PARange exposed to guests should be much larger than 40bits. On
> the neoverse-n2 it should be 48bits (256TB), therefore the iterations
> required for each unmapping would be 256x:
> 
> 262144  (4KB pages,  unmapping 1GB per iteration)
> 8388608 (16KB pages, unmapping 32MB per iteration)
> 524288  (64KB pages, unmapping 512MB per iteration)
> 
> I think these numbers match the hang time Shuai have shown.
>
> Just to demonstrate the difference I have tried manually limiting
> kvm_ipa_limit to 40, and tested with software emulation. Before the
> manual change a kvm_nested_s2_unmap() finished after 42 seconds, after
> limiting kvm_ipa_limit kvm_nested_s2_unmap() can finish in less than a
> second.
>
> With this, I think there aren't other underlying issues, it just is that
> slow unfortunately..

I don't buy this. There should be very little mapped in the shadow S2,
a few dozen pages at most. As you noticed, there is very little the
kernel executes at EL1 before upgrading to EL2. Invalidating this
should be cheap.  Furthermore, once invalidated after the last vcpu
has booted, the cost should be exactly zero.

It seems that these two assumptions are not holding up, and I wonder
why.

	M.

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

  reply	other threads:[~2026-09-05 13:46 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-10 20:50 Wei-Lin Chang
2026-08-10 20:50 ` [PATCH v5 1/6] KVM: arm64: Use a variable for the canonical IPA in kvm_s2_fault_map() Wei-Lin Chang
2026-08-10 20:50 ` [PATCH v5 2/6] KVM: arm64: nv: Introduce guest stage-2 tracking structures Wei-Lin Chang
2026-08-14  1:04   ` Itaru Kitayama
2026-08-14 10:42     ` Wei-Lin Chang
2026-08-16 22:01       ` Itaru Kitayama
2026-08-10 20:50 ` [PATCH v5 3/6] KVM: arm64: nv: Track guest stage-2 mapping creation Wei-Lin Chang
2026-08-10 20:50 ` [PATCH v5 4/6] KVM: arm64: nv: Track guest stage-2 mapping removal Wei-Lin Chang
2026-08-10 20:50 ` [PATCH v5 5/6] KVM: arm64: nv: Avoid full shadow stage-2 unmap Wei-Lin Chang
2026-08-10 20:50 ` [PATCH v5 6/6] KVM: arm64: Refactor kvm_unmap_gfn_range() with common variables Wei-Lin Chang
2026-08-12  2:12 ` [PATCH v5 0/6] KVM: arm64: nv: Implement nested stage-2 reverse map (new data structure) Itaru Kitayama
2026-09-02 16:35 ` Wang Han
2026-09-03  7:43   ` Marc Zyngier
2026-09-03 13:28     ` Wei-Lin Chang
2026-09-04  7:01       ` Shuai Xue
2026-09-04  7:54         ` Marc Zyngier
2026-09-05 15:35           ` Shuai Xue
2026-09-04  7:49       ` Marc Zyngier
2026-09-04 11:37         ` Wei-Lin Chang
2026-09-04 22:42         ` Wei-Lin Chang
2026-09-05 13:48           ` Marc Zyngier [this message]
2026-09-05 15:49           ` Shuai Xue

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=87pkyr4xmu.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=itaru.kitayama@fujitsu.com \
    --cc=joey.gouly@arm.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ljs@kernel.org \
    --cc=oupton@kernel.org \
    --cc=seiden@linux.ibm.com \
    --cc=suzuki.poulose@arm.com \
    --cc=tabba@google.com \
    --cc=wanghan@linux.alibaba.com \
    --cc=weilin.chang@arm.com \
    --cc=will@kernel.org \
    /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

all inboxes | Powered by JetHome®