All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Steffen Eiden" <seiden@linux.ibm.com>
Cc: "Alexander Gordeev" <agordeev@linux.ibm.com>,
	kvm@vger.kernel.org,
	"Christian Borntraeger" <borntraeger@linux.ibm.vom>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	"Heiko Carstens" <hca@linux.ibm.com>,
	linux-s390@vger.kernel.org
Subject: Re: [PATCH] vfio: Use file-based reference counting for KVM
Date: Wed, 12 Aug 2026 19:23:19 +0000	[thread overview]
Message-ID: <20260812192319.BF41B1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260812-vfio-v1-1-5cfe0b1fa4e7@linux.ibm.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] Missing SRCU read lock when iterating over KVM memslots in `kvm_enable_external_write_tracking`.
--

--- Patch [1]: [PATCH] vfio: Use file-based reference counting for KVM ---
commit 6e2d7f7af50df153e78728c6ab103209dafd02a4
Author: Steffen Eiden <seiden@linux.ibm.com>
Subject: vfio: Use file-based reference counting for KVM

This commit replaces manual module reference counting with file-based
reference counting for KVM integration in VFIO. It passes struct file
pointers instead of struct kvm pointers throughout the interface to
leverage the kernel's existing file reference counting mechanism.

Link: https://lore.kernel.org/all/anyhChQlOs37se4B@google.com/
Link: https://lore.kernel.org/all/20260812153631.3376090-2-seiden@linux.ibm.com

> diff --git a/arch/x86/kvm/mmu/page_track.c b/arch/x86/kvm/mmu/page_track.c
> index 7e8195a311bb0..98f133e4f0b32 100644
> --- a/arch/x86/kvm/mmu/page_track.c
> +++ b/arch/x86/kvm/mmu/page_track.c
> @@ -237,10 +237,11 @@ static int kvm_enable_external_write_tracking(struct kvm *kvm)

[Severity: High]
This is a pre-existing issue, but does kvm_enable_external_write_tracking()
need to hold srcu_read_lock(&kvm->srcu) when iterating over the memslots
array?

Looking at the function, it retrieves and iterates over the memslots array
while only holding the slots_arch_lock mutex:

mutex_lock(&kvm->slots_arch_lock);
...
for (i = 0; i < kvm_arch_nr_memslot_as_ids(kvm); i++) {
    slots = __kvm_memslots(kvm, i);
    kvm_for_each_memslot(slot, bkt, slots) {
        r = kvm_page_track_write_tracking_alloc(slot);
        if (r)
            goto out_unlock;
    }
}

Without holding srcu_read_lock(&kvm->srcu) or the writer-side slots_lock,
could a concurrent memslot update swap and free the memslots array while
the loop is traversing it, causing a use-after-free?

>   * register the notifier so that event interception for the tracked guest
>   * pages can be received.
>   */
> -int kvm_page_track_register_notifier(struct kvm *kvm,
> +int kvm_page_track_register_notifier(struct file *file,
>  				     struct kvm_page_track_notifier_node *n)

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260812-vfio-v1-1-5cfe0b1fa4e7@linux.ibm.com?part=1

  reply	other threads:[~2026-08-12 19:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-12 18:55 [PATCH] vfio: Use file-based reference counting for KVM Steffen Eiden
2026-08-12 19:23 ` sashiko-bot [this message]
2026-08-12 19:39   ` Sean Christopherson

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=20260812192319.BF41B1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.vom \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=seiden@linux.ibm.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.