From: Jason Gunthorpe <jgg@nvidia.com>
To: "Tian, Kevin" <kevin.tian@intel.com>
Cc: Alex Williamson <alex.williamson@redhat.com>,
Cornelia Huck <cohuck@redhat.com>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
Christoph Hellwig <hch@lst.de>, "Liu, Yi L" <yi.l.liu@intel.com>
Subject: Re: [PATCH 5/5] vfio: Use cdev_device_add() instead of device_create()
Date: Tue, 12 Oct 2021 09:05:05 -0300 [thread overview]
Message-ID: <20211012120505.GT2744544@nvidia.com> (raw)
In-Reply-To: <BN9PR11MB5433538884DA4EB3B5BF89628CB69@BN9PR11MB5433.namprd11.prod.outlook.com>
On Tue, Oct 12, 2021 at 08:33:49AM +0000, Tian, Kevin wrote:
> > From: Jason Gunthorpe <jgg@nvidia.com>
> > Sent: Saturday, October 2, 2021 7:22 AM
> >
> [...]
>
> > +static void vfio_group_release(struct device *dev)
> > {
> > - struct vfio_group *group, *existing_group;
> > - struct device *dev;
> > - int ret, minor;
> > + struct vfio_group *group = container_of(dev, struct vfio_group, dev);
> > + struct vfio_unbound_dev *unbound, *tmp;
> > +
> > + list_for_each_entry_safe(unbound, tmp,
> > + &group->unbound_list, unbound_next) {
> > + list_del(&unbound->unbound_next);
> > + kfree(unbound);
> > + }
>
> move to vfio_group_put()? this is not paired with vfio_group_alloc()...
Lists are tricky for pairing analysis, the vfio_group_alloc() creates
an empty list and release restores the list to empty.
> > static int vfio_group_fops_open(struct inode *inode, struct file *filep)
> > {
> > - struct vfio_group *group;
> > + struct vfio_group *group =
> > + container_of(inode->i_cdev, struct vfio_group, cdev);
> > int opened;
>
> A curiosity question. According to cdev_device_del() any cdev already
> open will remain with their fops callable.
Correct
> What prevents vfio_group from being released after cdev_device_del()
> has been called? Is it because cdev open will hold a reference to
> device thus put_device() will not hit zero in vfio_group_put()?
Yes, that is right. The extra reference is hidden deep inside the FS
code and is actually a reference on the cdev struct, which in turn
holds a kobject parent reference on the struct device. It is
complicated under the covers, but from an API perspective if a struct
file exists then so does the vfio_group.
Jason
next prev parent reply other threads:[~2021-10-12 12:05 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-01 23:22 [PATCH 0/5] Update vfio_group to use the modern cdev lifecycle Jason Gunthorpe
2021-10-01 23:22 ` [PATCH 1/5] vfio: Delete vfio_get/put_group from vfio_iommu_group_notifier() Jason Gunthorpe
2021-10-04 22:25 ` Alex Williamson
2021-10-04 22:34 ` Jason Gunthorpe
2021-10-05 4:01 ` Alex Williamson
2021-10-05 16:17 ` Jason Gunthorpe
2021-10-12 6:32 ` Tian, Kevin
2021-10-12 8:51 ` Liu, Yi L
2021-10-01 23:22 ` [PATCH 2/5] vfio: Do not open code the group list search in vfio_create_group() Jason Gunthorpe
2021-10-02 3:19 ` kernel test robot
2021-10-12 6:37 ` Tian, Kevin
2021-10-12 8:52 ` Liu, Yi L
2021-10-01 23:22 ` [PATCH 3/5] vfio: Don't leak a group reference if the group already exists Jason Gunthorpe
2021-10-04 22:25 ` Alex Williamson
2021-10-04 22:36 ` Jason Gunthorpe
2021-10-05 4:01 ` Alex Williamson
2021-10-05 14:45 ` Jason Gunthorpe
2021-10-01 23:22 ` [PATCH 4/5] vfio: Use a refcount_t instead of a kref in the vfio_group Jason Gunthorpe
2021-10-04 22:25 ` Alex Williamson
2021-10-04 22:39 ` Jason Gunthorpe
2021-10-12 7:08 ` Tian, Kevin
2021-10-12 9:04 ` Liu, Yi L
2021-10-01 23:22 ` [PATCH 5/5] vfio: Use cdev_device_add() instead of device_create() Jason Gunthorpe
2021-10-12 8:33 ` Tian, Kevin
2021-10-12 12:05 ` Jason Gunthorpe [this message]
2021-10-13 1:07 ` Tian, Kevin
2021-10-12 8:57 ` Liu, Yi L
2021-10-13 12:49 ` Jason Gunthorpe
2021-10-13 14:15 ` Liu, Yi L
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=20211012120505.GT2744544@nvidia.com \
--to=jgg@nvidia.com \
--cc=alex.williamson@redhat.com \
--cc=cohuck@redhat.com \
--cc=hch@lst.de \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=yi.l.liu@intel.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.