mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Woodhouse <dwmw2@infradead.org>
To: Sean Christopherson <seanjc@google.com>
Cc: Jeongjun Park <aha310510@gmail.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	 Paul Durrant <pdurrant@amazon.com>,
	Heitor Alves de Siqueira <halves@igalia.com>,
	kvm@vger.kernel.org,  linux-kernel@vger.kernel.org,
	 syzbot+0948c82180d475ad24e2@syzkaller.appspotmail.com,
	 syzbot+fb7c2dd166d3ea63df2a@syzkaller.appspotmail.com
Subject: Re: [PATCH] KVM: pfncache: track HVA invalidations for HVA-based caches
Date: Mon, 03 Aug 2026 17:38:15 +0200	[thread overview]
Message-ID: <992c01aa0167a95181bc59401a3cd991906e9d60.camel@infradead.org> (raw)
In-Reply-To: <ameUih-zuAoR_pnC@google.com>

[-- Attachment #1: Type: text/plain, Size: 3428 bytes --]

(Spent the day prodding at AI on this while I'm in meetings; I've let
it draft the below for me which isn't entirely my voice but I'm mostly
OK with it...)

On Mon, 2026-07-27 at 10:25 -0700, Sean Christopherson wrote:
> Can you provide the reproducer?  That would be super helpful for reviewing and
> iterating on this fix, and probably as a regression test for future changes as
> well.

There's one at https://david.woodhou.se/xen_shinfo_race.c now — no
memslots, just five processes racing
KVM_XEN_HVM_SET_ATTR(SHARED_INFO_HVA) against MAP_FIXED shmem remaps
over the cached HVA. It fires the syzbot splat within five seconds in
a QEMU guest running an unfixed kernel. Tracing confirms the
diagnosis: complete invalidations (start *and* end) land entirely
within the window where hva_to_pfn_retry() has dropped gpc->lock for
the GUP, so by the time it re-checks, mn_active_invalidate_count is
back to zero and mmu_invalidate_seq never moved because nothing
overlapped a memslot. (Note syzbot also found its own reproducer last
week¹.)

The same bug is also reachable through the vcpu_info cache, where the
stale mapping is then dereferenced by kvm_setup_guest_pvclock() on the
next KVM_RUN — which is syzbot+fb7c2dd166d3ea63df2a, the one Heitor
posted a sibling-GPC workaround for². Reproducer for that variant:
https://david.woodhou.se/vcpu_info_race.c

Since you said you'd want to land the sequence fix together with the
range-based optimization: I've taken a shot at that. The branch at

  https://git.infradead.org/?p=users/dwmw2/linux.git;a=shortlog;h=refs/heads/pfncache-fixes

has your gpc_invalidate_seq patch (with the sampling side in
hva_to_pfn_retry() also switched over, and both syzbot tags; Cc:
stable and deliberately minimal for backporting) followed by your Oct
2024 patches³ rebased on top, with the range check's second arm now
checking gpc_invalidate_seq so it catches invalidations which complete
within the refresh window without touching a memslot. I've dropped the
sleep-based wait for now.

David Woodhouse (2):
      KVM: pfncache: use a dedicated invalidation sequence for cache refresh
      KVM: pfncache: Implement range-based invalidation check for hva_to_pfn_retry()

Sean Christopherson (3):
      KVM: pfncache: Snapshot invalidation sequence immediately before hva_to_pfn()
      KVM: pfncache: Wait for in-progress invalidations to complete during refresh
      KVM: pfncache: Add lockless checking of cache invalidation events

 include/linux/kvm_host.h |   4 ++
 virt/kvm/kvm_main.c      |  17 +++++-
 virt/kvm/pfncache.c      | 144 +++++++++++++++++++++++++++++++----------------
 3 files changed, 114 insertions(+), 51 deletions(-)

Both reproducers fire in seconds on the unfixed base and survive
ten-minute soaks under KASAN+lockdep with the first patch alone and
with the full series.

On the RT concern with taking mn_invalidate_lock across the GPC walk:
I don't think the "sleeping while atomic" problem exists once the GPC
locks are no longer irqsave, which v2 of the rwlock_t series⁴ already
does.

¹ https://lore.kernel.org/all/6a6f68af.13bfb6d0.1ecdd5.0271.GAE@google.com/
² https://lore.kernel.org/all/20260723-kvm_guest_pvclock-v1-1-bba3ea77419b@igalia.com/
³ https://lore.kernel.org/all/Zw8DINUkJJKDByXE@google.com/
⁴ https://lore.kernel.org/all/20260529165114.748639-6-seanjc@google.com/

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6179 bytes --]

      reply	other threads:[~2026-08-03 15:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-20 11:13 Jeongjun Park
2026-06-25 21:45 ` Sean Christopherson
2026-07-26 21:31   ` Jeongjun Park
2026-07-27 17:25     ` Sean Christopherson
2026-08-03 15:38       ` David Woodhouse [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=992c01aa0167a95181bc59401a3cd991906e9d60.camel@infradead.org \
    --to=dwmw2@infradead.org \
    --cc=aha310510@gmail.com \
    --cc=halves@igalia.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=pdurrant@amazon.com \
    --cc=seanjc@google.com \
    --cc=syzbot+0948c82180d475ad24e2@syzkaller.appspotmail.com \
    --cc=syzbot+fb7c2dd166d3ea63df2a@syzkaller.appspotmail.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

all inboxes | Powered by JetHome®