All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Karl Mehltretter <kmehltretter@gmail.com>
Cc: Oliver Upton <oupton@kernel.org>, Fuad Tabba <tabba@google.com>,
	Joey Gouly <joey.gouly@arm.com>,
	Steffen Eiden <seiden@linux.ibm.com>,
	Suzuki K Poulose <suzuki.poulose@arm.com>,
	Zenghui Yu <yuzenghui@huawei.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Shuah Khan <shuah@kernel.org>,
	linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	linux-kselftest@vger.kernel.org
Subject: Re: [PATCH 2/2] KVM: arm64: selftests: Add a nested S2 MMU realloc test
Date: Tue, 04 Aug 2026 15:44:36 +0100	[thread overview]
Message-ID: <86ldamaqsr.wl-maz@kernel.org> (raw)
In-Reply-To: <20260803224405.41468-2-kmehltretter@gmail.com>

On Mon, 03 Aug 2026 23:44:05 +0100,
Karl Mehltretter <kmehltretter@gmail.com> wrote:
> 
> Add a regression test for a stale vcpu->arch.hw_mmu reference when
> initialising a vCPU grows the nested S2 MMU table.
> 
> The test drives vCPU0 into L2 through a minimal L1 stage-2 identity map,
> pins it to a second pCPU where it spins in L2, and then initialises
> vCPU1.  That initialisation grows the nested MMU table while vCPU0 still
> holds one of its entries; keeping vCPU0 on a pCPU of its own means the
> reference stays live without relying on hw_mmu being retained across a
> schedule-out.  vCPU0 is then released and has to run to completion.
> 
> Creating vCPU1 up front is what allows the in-kernel VGIC to be used:
> kvm_arch_vcpu_precreate() refuses KVM_CREATE_VCPU once the VGIC has been
> initialised, which the test does before its first KVM_RUN.  Creation on
> its own increments online_vcpus, so deferring vCPU1's KVM_ARM_VCPU_INIT
> until vCPU0 is in L2 still grows the table.
> 
> With KASAN enabled, an unfixed kernel reports a slab-use-after-free in
> kvm_handle_guest_abort(); with the fix it completes cleanly.

The problem is that we can't mandate selftests to rely on KASAN on the
host. Selftests are there to verify that we match the architecture
requirements.

If anything, this is a nice hack to demonstrate the problem (and yes,
it fires here).

> 
> Assisted-by: Claude:claude-fable-5
> Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
> ---
> 
> The test requires nested virtualization and two pCPUs.  Under QEMU TCG
> it takes ~233s, exceeding the 120s timeout in
> tools/testing/selftests/kvm/settings; psci_test takes ~167s in the same
> boot, so emulating the second vCPU is the dominant cost.

# time /host/home/maz/nested_mmu_realloc_test 
Random seed: 0x6b8b4567
Running control thread on pCPU 0, vCPU thread on pCPU 1
vCPU0 is running in L2; initializing vCPU1 to grow the table
vCPU1 initialized; releasing vCPU0
vCPU0 resumed after nested MMU resize

real	0m0.161s
user	0m0.007s
sys	0m0.109s

This is with KVM running as an L1 already...

	M.

-- 
Without deviation from the norm, progress is not possible.

  reply	other threads:[~2026-08-04 14:44 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-03 22:44 [PATCH 1/2] KVM: arm64: nv: Allocate the shadow S2 MMUs individually Karl Mehltretter
2026-08-03 22:44 ` [PATCH 2/2] KVM: arm64: selftests: Add a nested S2 MMU realloc test Karl Mehltretter
2026-08-04 14:44   ` Marc Zyngier [this message]
2026-08-04 10:24 ` [PATCH 1/2] KVM: arm64: nv: Allocate the shadow S2 MMUs individually Wei-Lin Chang
2026-08-04 14:31 ` Marc Zyngier
2026-08-04 14:56   ` Marc Zyngier
2026-08-04 21:54     ` Karl Mehltretter
2026-08-05  7:32       ` Marc Zyngier
2026-08-05 21:39         ` Karl Mehltretter
2026-08-07 17:08   ` Karl Mehltretter
2026-08-09 11:39     ` Marc Zyngier

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=86ldamaqsr.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=joey.gouly@arm.com \
    --cc=kmehltretter@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=oupton@kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seiden@linux.ibm.com \
    --cc=shuah@kernel.org \
    --cc=suzuki.poulose@arm.com \
    --cc=tabba@google.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.