Linux s390 Architecture development
 help / color / mirror / Atom feed
From: Christian Borntraeger <borntraeger@linux.ibm.com>
To: sashiko-reviews@lists.linux.dev, Steffen Eiden <seiden@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>,
	linux-s390@vger.kernel.org, kvm@vger.kernel.org,
	Heiko Carstens <hca@linux.ibm.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>
Subject: Re: [PATCH v3 4/5] KVM/vfio: Use file-based reference counting for KVM
Date: Fri, 25 Sep 2026 14:22:50 +0200	[thread overview]
Message-ID: <b49ec974-6937-4057-869b-a6e2d5958c6d@linux.ibm.com> (raw)
In-Reply-To: <20260924091457.74D2E1F000FF@smtp.kernel.org>

Am 24.09.26 um 11:14 schrieb sashiko-bot@kernel.org:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] kvm/vfio: memory leak due to circular file reference

So with the help of AI drawing things I think this is a false positive, see below.


References between KVM and VFIO after
"KVM/vfio: Use file-based reference counting for KVM" v3

   ====>  ||  \/  /\   holds a reference (get_file(), kvm_get_kvm(), fd)
   ---->  :   v        plain pointer, holds no reference

                process fd table (exit_files() drops every fd)
         ||               ||                 ||               ||
         \/               \/                 \/               \/
  +--------------+  +--------------+  +---------------+  +-----------+
  | kvm-vfio     |  | VFIO group   |  | VFIO device   |  | VM file   |
  | device file  |  | or cdev file |  | file (opened) |  | "kvm-vm"  |
  +--------------+  +--------------+  +---------------+  +-----------+
    ||   ||            /\     ||              ||            /\   ||
    ||   || kvf->file  ||     || group->kvm   || device->kvm||   || private_data
    ||   ++============++     || df->kvm      ++============++   || users_count
    ||                        || (NEW)                      ||   ||
    || dev->kvm               ++============================++   ||
    || users_count                                               \/
    ||                                                   +-------------+
    ++==================================================>| struct kvm  |
                                                         +-------------+
                                                           :         :
                                              kvm->devices :         : kvm->file
                                                (no ref)   :         : (no ref)
                                              to kvm-vfio  v         v to the
                                                device                 VM file


Every ====> arrow points to the right or down.  Nothing leaves the
VM file or struct kvm with a ====> back to a VFIO file or to the
kvm-vfio device file; the two arrows that do point back are plain
pointers.  The kvm-vfio device file is held only by the fd table,
so it is always released first, and its .release takes the
kvf->file and group->kvm/df->kvm arrows away:






[...]

> > -void vfio_group_set_kvm(struct vfio_group *group, struct kvm *kvm)
> > +void vfio_group_set_kvm(struct vfio_group *group, struct file *kvm)
> >  {
> > +   struct file *old;
> > +
> > +   if (kvm)
> > +           get_file(kvm);
> > +
> >     spin_lock(&group->kvm_ref_lock);
> > +   old = group->kvm;
> >     group->kvm = kvm;
> >     spin_unlock(&group->kvm_ref_lock);
>
> [Severity: High]
> Does this create a circular file reference? VFIO takes a reference on the KVM VM
> file here in vfio_group_set_kvm(), while KVM also takes a reference on the
> VFIO file.

And this (also for the other aspects) might be the relevant part.
The VM file does not hold the reference on the VFIO file.  The
reference is held by the kvm-vfio device (kvf->file in struct kvm_vfio),
and that device is owned by its own fd, not by the VM file or by
struct kvm.

  reply	other threads:[~2026-09-25 12:22 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-24  8:58 [PATCH v3 0/5] KVM/vfio: Use file-based reference counting for KVM Steffen Eiden
2026-09-24  8:58 ` [PATCH v3 1/5] KVM: Introduce file_to_kvm_<arch>() infrastructure Steffen Eiden
2026-09-24  9:06   ` sashiko-bot
2026-09-24  8:58 ` [PATCH v3 2/5] KVM: Add file back-pointer to struct kvm Steffen Eiden
2026-09-24  9:07   ` sashiko-bot
2026-09-30  5:56   ` Aneesh Kumar K.V
2026-09-30  7:19     ` Aneesh Kumar K.V
2026-10-01 11:51       ` Steffen Eiden
2026-09-24  8:58 ` [PATCH v3 3/5] KVM: x86: Use file_to_kvm_x86() in SEV Steffen Eiden
2026-09-24  9:04   ` sashiko-bot
2026-09-25  8:35   ` Christian Borntraeger
2026-09-25  9:32     ` Steffen Eiden
2026-09-24  8:58 ` [PATCH v3 4/5] KVM/vfio: Use file-based reference counting for KVM Steffen Eiden
2026-09-24  9:14   ` sashiko-bot
2026-09-25 12:22     ` Christian Borntraeger [this message]
2026-09-24 12:47   ` Jason J. Herne
2026-09-24  8:58 ` [PATCH v3 5/5] KVM: Restrict kvm_get_kvm/kvm_put_kvm export to internal KVM modules Steffen Eiden
2026-09-24  9:02   ` sashiko-bot

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=b49ec974-6937-4057-869b-a6e2d5958c6d@linux.ibm.com \
    --to=borntraeger@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox