From: Alex Williamson <alex@shazbot.org>
To: Yash Suthar <yashsuthar983@gmail.com>
Cc: pbonzini@redhat.com, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org, skhan@linuxfoundation.org,
me@brighamcampbell.com, alex@shazbot.org
Subject: Re: [PATCH] kvm: vfio: Convert kvm_vfio_file_add() to use CLASS(fd) and guard(mutex)
Date: Fri, 12 Jun 2026 10:17:19 -0600 [thread overview]
Message-ID: <20260612101719.02746ec5@shazbot.org> (raw)
In-Reply-To: <20260612101530.7b8b8edf@shazbot.org>
On Fri, 12 Jun 2026 10:15:30 -0600
Alex Williamson <alex@shazbot.org> wrote:
> On Sat, 23 May 2026 10:32:42 +0530
> Yash Suthar <yashsuthar983@gmail.com> wrote:
>
> > Convert manual fget/fput call to CLASS(fd, f) and
> > mutex_lock/unlock to guard(mutex).
> >
> > This remove the goto based paths both out_unlock and
> > out_fput.
> >
> > Signed-off-by: Yash Suthar <yashsuthar983@gmail.com>
> > ---
> > virt/kvm/vfio.c | 37 ++++++++++++++-----------------------
> > 1 file changed, 14 insertions(+), 23 deletions(-)
>
> Sean already took Carlos' series[1] that mostly
Sent too soon, [1] mostly handles this, only maybe the CLASS change
remains, if that's still worthwhile on its own. Thanks,
Alex
[1]https://lore.kernel.org/all/20260313122040.1413091-3-clopez@suse.de/
> > diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c
> > index 9f9acb66cc1e..bb3694d9c0c4 100644
> > --- a/virt/kvm/vfio.c
> > +++ b/virt/kvm/vfio.c
> > @@ -144,45 +144,36 @@ static int kvm_vfio_file_add(struct kvm_device *dev, unsigned int fd)
> > {
> > struct kvm_vfio *kv = dev->private;
> > struct kvm_vfio_file *kvf;
> > - struct file *filp;
> > - int ret = 0;
> > + struct file *file;
> > + CLASS(fd, f)(fd);
> >
> > - filp = fget(fd);
> > - if (!filp)
> > + if (fd_empty(f))
> > return -EBADF;
> >
> > + file = fd_file(f);
> > +
> > /* Ensure the FD is a vfio FD. */
> > - if (!kvm_vfio_file_is_valid(filp)) {
> > - ret = -EINVAL;
> > - goto out_fput;
> > - }
> > + if (!kvm_vfio_file_is_valid(file))
> > + return -EINVAL;
> >
> > - mutex_lock(&kv->lock);
> > + guard(mutex)(&kv->lock);
> >
> > list_for_each_entry(kvf, &kv->file_list, node) {
> > - if (kvf->file == filp) {
> > - ret = -EEXIST;
> > - goto out_unlock;
> > - }
> > + if (kvf->file == file)
> > + return -EEXIST;
> > }
> >
> > kvf = kzalloc_obj(*kvf, GFP_KERNEL_ACCOUNT);
> > - if (!kvf) {
> > - ret = -ENOMEM;
> > - goto out_unlock;
> > - }
> > + if (!kvf)
> > + return -ENOMEM;
> >
> > - kvf->file = get_file(filp);
> > + kvf->file = get_file(file);
> > list_add_tail(&kvf->node, &kv->file_list);
> >
> > kvm_vfio_file_set_kvm(kvf->file, dev->kvm);
> > kvm_vfio_update_coherency(dev);
> >
> > -out_unlock:
> > - mutex_unlock(&kv->lock);
> > -out_fput:
> > - fput(filp);
> > - return ret;
> > + return 0;
> > }
> >
> > static int kvm_vfio_file_del(struct kvm_device *dev, unsigned int fd)
>
next prev parent reply other threads:[~2026-06-12 16:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-23 5:02 Yash Suthar
2026-06-12 16:15 ` Alex Williamson
2026-06-12 16:17 ` Alex Williamson [this message]
2026-06-15 17:29 ` [PATCH v2] KVM: vfio: Convert fget() to CLASS(fd) in kvm_vfio_file_add() Yash Suthar
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=20260612101719.02746ec5@shazbot.org \
--to=alex@shazbot.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=me@brighamcampbell.com \
--cc=pbonzini@redhat.com \
--cc=skhan@linuxfoundation.org \
--cc=yashsuthar983@gmail.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®