From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: Yao Yuan <yaoyuan@linux.alibaba.com>
Cc: Marc Zyngier <maz@kernel.org>, 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>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Christoffer Dall <christoffer.dall@arm.com>,
Wei-Lin Chang <weilin.chang@arm.com>,
linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v2 1/2] KVM: arm64: Fix spurious warning for benign stage 2 teardown race
Date: Mon, 24 Aug 2026 14:29:14 +0100 [thread overview]
Message-ID: <aoxETjo-1vbTuLuZ@gremlin> (raw)
In-Reply-To: <dycpfrkpphjy5xnb57t2zvdmlpkx76lbow7w23l3d2fwgbfjjj@lbk4uh7awc2p>
On Sun, Aug 23, 2026 at 01:38:18PM +0800, Yao Yuan wrote:
> On Sat, Aug 22, 2026 at 06:46:53PM +0800, Lorenzo Stoakes (ARM) wrote:
> > A batch of kernel warnings were triggered in the L0 host kernel when using
> > kvmtool to experiment with nested virtualisation.
>
> ...
>
> > Fixes: ec14c272408a ("KVM: arm64: nv: Unmap/flush shadow stage 2 page tables")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
> > ---
> > arch/arm64/kvm/mmu.c | 10 ++++++++--
> > 1 file changed, 8 insertions(+), 2 deletions(-)
> >
> > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
> > index 74e7e7f7564c..31e049ded093 100644
> > --- a/arch/arm64/kvm/mmu.c
> > +++ b/arch/arm64/kvm/mmu.c
> > @@ -59,19 +59,25 @@ static phys_addr_t stage2_range_addr_end(phys_addr_t addr, phys_addr_t end)
> > * long will also starve other vCPUs. We have to also make sure that the page
> > * tables are not freed while we released the lock.
> > */
> > -static int stage2_apply_range(struct kvm_s2_mmu *mmu, phys_addr_t addr,
> > +static int stage2_apply_range(struct kvm_s2_mmu *mmu, phys_addr_t start,
> > phys_addr_t end,
> > int (*fn)(struct kvm_pgtable *, u64, u64),
> > bool resched)
> > {
> > struct kvm *kvm = kvm_s2_mmu_to_kvm(mmu);
> > + phys_addr_t addr = start;
> > int ret;
> > u64 next;
> >
> > do {
> > struct kvm_pgtable *pgt = mmu->pgt;
> > + /*
> > + * We may be raced on PGT teardown when we release the
> > + * kvm->mmu_lock. That's fine as the PGT is legitimately no
> > + * longer present.
> > + */
> > if (!pgt)
> > - return -EINVAL;
> > + return resched && addr > start ? 0 : -EINVAL;
>
> Hi,
>
> I can understand the addr checking makes sure only return 0
> when the mmu_lock is dropped at least once and get pgt =
> NULL, may a variable like drop_lock = true when
> cond_resched_rwlock_write(&kvm->mmu_lock) happens can have
> better readability, but depends on you and others' opinion.
Yeah good point, also the condition is resched && next != end, so this was far
too forgiving already :)
So perhaps:
static int stage2_apply_range(struct kvm_s2_mmu *mmu, phys_addr_t start,
phys_addr_t end,
int (*fn)(struct kvm_pgtable *, u64, u64),
bool resched)
{
...
bool lock_dropped = false;
...
do {
...
if (!pgt)
return lock_dropped ? 0 : -EINVAL;
...
if (resched && next != end) {
cond_resched_rwlock_write(&kvm->mmu_lock);
lock_dropped = true;
}
} while (...);
...
}
That keeps it simple and clear and we don't try to infer anything too
complicated from the state just 'the lock was dropped'.
>
> Reviewed-by: Yuan Yao <yaoyuan@linux.alibaba.com>
Thanks :)
>
> >
> > next = stage2_range_addr_end(addr, end);
> > ret = fn(pgt, addr, next - addr);
> >
> > --
> > 2.55.0
--
Cheers, Lorenzo
next prev parent reply other threads:[~2026-08-24 13:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-22 17:46 [PATCH v2 0/2] KVM: arm64: Fix spurious warn, null ptr deref on S2 teardown race Lorenzo Stoakes (ARM)
2026-08-22 17:46 ` [PATCH v2 1/2] KVM: arm64: Fix spurious warning for benign stage 2 " Lorenzo Stoakes (ARM)
2026-08-23 5:38 ` Yao Yuan
2026-08-24 13:29 ` Lorenzo Stoakes (ARM) [this message]
2026-08-22 17:46 ` [PATCH v2 2/2] KVM: arm64: nv: Fix null ptr deref on nested wp/unmap, " Lorenzo Stoakes (ARM)
2026-08-23 7:53 ` [PATCH v2 0/2] KVM: arm64: Fix spurious warn, null ptr deref on S2 " Marc Zyngier
2026-08-24 13:15 ` Lorenzo Stoakes (ARM)
2026-08-24 15:56 ` Marc Zyngier
2026-08-24 17:34 ` Lorenzo Stoakes (ARM)
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=aoxETjo-1vbTuLuZ@gremlin \
--to=ljs@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=christoffer.dall@arm.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=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=seiden@linux.ibm.com \
--cc=stable@vger.kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=tabba@google.com \
--cc=weilin.chang@arm.com \
--cc=will@kernel.org \
--cc=yaoyuan@linux.alibaba.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox