All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe via iommu <iommu@lists.linux-foundation.org>
To: "Liu, Yi L" <yi.l.liu@intel.com>
Cc: "kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"jasowang@redhat.com" <jasowang@redhat.com>,
	"kwankhede@nvidia.com" <kwankhede@nvidia.com>,
	"hch@lst.de" <hch@lst.de>,
	"jean-philippe@linaro.org" <jean-philippe@linaro.org>,
	"Jiang, Dave" <dave.jiang@intel.com>,
	"Raj, Ashok" <ashok.raj@intel.com>,
	"corbet@lwn.net" <corbet@lwn.net>,
	"Tian, Kevin" <kevin.tian@intel.com>,
	"parav@mellanox.com" <parav@mellanox.com>,
	"alex.williamson@redhat.com" <alex.williamson@redhat.com>,
	"lkml@metux.net" <lkml@metux.net>,
	"david@gibson.dropbear.id.au" <david@gibson.dropbear.id.au>,
	"dwmw2@infradead.org" <dwmw2@infradead.org>,
	"Tian, Jun J" <jun.j.tian@intel.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"lushenming@huawei.com" <lushenming@huawei.com>,
	"iommu@lists.linux-foundation.org"
	<iommu@lists.linux-foundation.org>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"robin.murphy@arm.com" <robin.murphy@arm.com>
Subject: Re: [RFC 02/20] vfio: Add device class for /dev/vfio/devices
Date: Mon, 1 Nov 2021 09:50:13 -0300	[thread overview]
Message-ID: <20211101125013.GL2744544@nvidia.com> (raw)
In-Reply-To: <PH0PR11MB56586D2EC89F282C915AF18DC3879@PH0PR11MB5658.namprd11.prod.outlook.com>

On Fri, Oct 29, 2021 at 09:47:27AM +0000, Liu, Yi L wrote:
> Hi Jason,
> 
> > From: Jason Gunthorpe <jgg@nvidia.com>
> > Sent: Monday, October 25, 2021 8:53 PM
> > 
> > On Mon, Oct 25, 2021 at 06:28:09AM +0000, Liu, Yi L wrote:
> > >    thanks for the guiding. will also refer to your vfio_group_cdev series.
> > >
> > >    Need to double confirm here. Not quite following on the kfree. Is
> > >    this kfree to free the vfio_device structure? But now the
> > >    vfio_device pointer is provided by callers (e.g. vfio-pci). Do
> > >    you want to let vfio core allocate the vfio_device struct and
> > >    return the pointer to callers?
> > 
> > There are several common patterns for this problem, two that would be
> > suitable:
> > 
> > - Require each driver to provide a release op inside vfio_device_ops
> >   that does the kfree. Have the core provide a struct device release
> >   op that calls this one. Keep the kalloc/kfree in the drivers
> 
> this way sees to suit the existing vfio registration manner listed
> below. right? 

Not really, most drivers are just doing kfree. The need for release
comes if the drivers are doing more stuff.

> But device drivers needs to do the kfree in the
> newly added release op instead of doing it on their own (e.g.
> doing kfree in remove).

Yes

> > struct ib_device *_ib_alloc_device(size_t size);
> > #define ib_alloc_device(drv_struct, member)                                    \
> >         container_of(_ib_alloc_device(sizeof(struct drv_struct) +              \
> >                                       BUILD_BUG_ON_ZERO(offsetof(              \
> >                                               struct drv_struct, member))),    \
> >                      struct drv_struct, member)
> > 
> 
> thanks for the example. If this way, still requires driver to provide
> a release op inside vfio_device_ops. right?

No, it would optional. It would contain the stuff the driver is doing
before kfree()

For instance mdev looks like the only driver that cares:

	vfio_uninit_group_dev(&mdev_state->vdev);
	kfree(mdev_state->pages);
	kfree(mdev_state->vconfig);
	kfree(mdev_state);

pages/vconfig would logically be in a release function

On the other hand ccw needs to rcu free the vfio_device, so that would
have to be global overhead with this api design.

Jason
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

WARNING: multiple messages have this Message-ID (diff)
From: Jason Gunthorpe <jgg@nvidia.com>
To: "Liu, Yi L" <yi.l.liu@intel.com>
Cc: "alex.williamson@redhat.com" <alex.williamson@redhat.com>,
	"hch@lst.de" <hch@lst.de>,
	"jasowang@redhat.com" <jasowang@redhat.com>,
	"joro@8bytes.org" <joro@8bytes.org>,
	"jean-philippe@linaro.org" <jean-philippe@linaro.org>,
	"Tian, Kevin" <kevin.tian@intel.com>,
	"parav@mellanox.com" <parav@mellanox.com>,
	"lkml@metux.net" <lkml@metux.net>,
	"pbonzini@redhat.com" <pbonzini@redhat.com>,
	"lushenming@huawei.com" <lushenming@huawei.com>,
	"eric.auger@redhat.com" <eric.auger@redhat.com>,
	"corbet@lwn.net" <corbet@lwn.net>,
	"Raj, Ashok" <ashok.raj@intel.com>,
	"yi.l.liu@linux.intel.com" <yi.l.liu@linux.intel.com>,
	"Tian, Jun J" <jun.j.tian@intel.com>,
	"Wu, Hao" <hao.wu@intel.com>,
	"Jiang, Dave" <dave.jiang@intel.com>,
	"jacob.jun.pan@linux.intel.com" <jacob.jun.pan@linux.intel.com>,
	"kwankhede@nvidia.com" <kwankhede@nvidia.com>,
	"robin.murphy@arm.com" <robin.murphy@arm.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"iommu@lists.linux-foundation.org"
	<iommu@lists.linux-foundation.org>,
	"dwmw2@infradead.org" <dwmw2@infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"baolu.lu@linux.intel.com" <baolu.lu@linux.intel.com>,
	"david@gibson.dropbear.id.au" <david@gibson.dropbear.id.au>,
	"nicolinc@nvidia.com" <nicolinc@nvidia.com>
Subject: Re: [RFC 02/20] vfio: Add device class for /dev/vfio/devices
Date: Mon, 1 Nov 2021 09:50:13 -0300	[thread overview]
Message-ID: <20211101125013.GL2744544@nvidia.com> (raw)
In-Reply-To: <PH0PR11MB56586D2EC89F282C915AF18DC3879@PH0PR11MB5658.namprd11.prod.outlook.com>

On Fri, Oct 29, 2021 at 09:47:27AM +0000, Liu, Yi L wrote:
> Hi Jason,
> 
> > From: Jason Gunthorpe <jgg@nvidia.com>
> > Sent: Monday, October 25, 2021 8:53 PM
> > 
> > On Mon, Oct 25, 2021 at 06:28:09AM +0000, Liu, Yi L wrote:
> > >    thanks for the guiding. will also refer to your vfio_group_cdev series.
> > >
> > >    Need to double confirm here. Not quite following on the kfree. Is
> > >    this kfree to free the vfio_device structure? But now the
> > >    vfio_device pointer is provided by callers (e.g. vfio-pci). Do
> > >    you want to let vfio core allocate the vfio_device struct and
> > >    return the pointer to callers?
> > 
> > There are several common patterns for this problem, two that would be
> > suitable:
> > 
> > - Require each driver to provide a release op inside vfio_device_ops
> >   that does the kfree. Have the core provide a struct device release
> >   op that calls this one. Keep the kalloc/kfree in the drivers
> 
> this way sees to suit the existing vfio registration manner listed
> below. right? 

Not really, most drivers are just doing kfree. The need for release
comes if the drivers are doing more stuff.

> But device drivers needs to do the kfree in the
> newly added release op instead of doing it on their own (e.g.
> doing kfree in remove).

Yes

> > struct ib_device *_ib_alloc_device(size_t size);
> > #define ib_alloc_device(drv_struct, member)                                    \
> >         container_of(_ib_alloc_device(sizeof(struct drv_struct) +              \
> >                                       BUILD_BUG_ON_ZERO(offsetof(              \
> >                                               struct drv_struct, member))),    \
> >                      struct drv_struct, member)
> > 
> 
> thanks for the example. If this way, still requires driver to provide
> a release op inside vfio_device_ops. right?

No, it would optional. It would contain the stuff the driver is doing
before kfree()

For instance mdev looks like the only driver that cares:

	vfio_uninit_group_dev(&mdev_state->vdev);
	kfree(mdev_state->pages);
	kfree(mdev_state->vconfig);
	kfree(mdev_state);

pages/vconfig would logically be in a release function

On the other hand ccw needs to rcu free the vfio_device, so that would
have to be global overhead with this api design.

Jason

  reply	other threads:[~2021-11-01 12:50 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-25  6:28 [RFC 02/20] vfio: Add device class for /dev/vfio/devices Liu, Yi L
2021-10-25 12:53 ` Jason Gunthorpe via iommu
2021-10-25 12:53   ` Jason Gunthorpe
2021-10-29  9:47   ` Liu, Yi L
2021-10-29  9:47     ` Liu, Yi L
2021-11-01 12:50     ` Jason Gunthorpe via iommu [this message]
2021-11-01 12:50       ` Jason Gunthorpe
2021-11-02  9:53       ` Liu, Yi L
2021-11-02  9:53         ` Liu, Yi L
2021-11-03 13:25         ` Jason Gunthorpe via iommu
2021-11-03 13:25           ` Jason Gunthorpe
2021-11-11 12:32           ` Liu, Yi L
2021-11-11 12:32             ` Liu, Yi L
  -- strict thread matches above, loose matches on Subject: below --
2021-09-19  6:38 [RFC 00/20] Introduce /dev/iommu for userspace I/O address space management Liu Yi L
2021-09-19  6:38 ` [RFC 02/20] vfio: Add device class for /dev/vfio/devices Liu Yi L
2021-09-19  6:38   ` Liu Yi L
2021-09-21 15:57   ` Jason Gunthorpe via iommu
2021-09-21 15:57     ` Jason Gunthorpe
2021-09-21 23:56     ` Tian, Kevin
2021-09-21 23:56       ` Tian, Kevin
2021-09-22  0:55       ` Jason Gunthorpe via iommu
2021-09-22  0:55         ` Jason Gunthorpe
2021-09-22  1:07         ` Tian, Kevin
2021-09-22  1:07           ` Tian, Kevin
2021-09-22 12:31           ` Jason Gunthorpe via iommu
2021-09-22 12:31             ` Jason Gunthorpe
2021-09-22  3:22         ` Tian, Kevin
2021-09-22  3:22           ` Tian, Kevin
2021-09-22 12:50           ` Jason Gunthorpe via iommu
2021-09-22 12:50             ` Jason Gunthorpe
2021-09-22 14:09             ` Tian, Kevin
2021-09-22 14:09               ` Tian, Kevin
2021-09-21 19:56   ` Alex Williamson
2021-09-21 19:56     ` Alex Williamson
2021-09-22  0:56     ` Tian, Kevin
2021-09-22  0:56       ` Tian, Kevin
2021-09-29  2:08   ` David Gibson
2021-09-29  2:08     ` David Gibson
2021-09-29 19:05     ` Alex Williamson
2021-09-29 19:05       ` Alex Williamson
2021-09-30  2:43       ` David Gibson
2021-09-30  2:43         ` David Gibson
2021-10-20 12:39     ` Liu, Yi L
2021-10-20 12:39       ` 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=20211101125013.GL2744544@nvidia.com \
    --to=iommu@lists.linux-foundation.org \
    --cc=alex.williamson@redhat.com \
    --cc=ashok.raj@intel.com \
    --cc=corbet@lwn.net \
    --cc=dave.jiang@intel.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=dwmw2@infradead.org \
    --cc=hch@lst.de \
    --cc=jasowang@redhat.com \
    --cc=jean-philippe@linaro.org \
    --cc=jgg@nvidia.com \
    --cc=jun.j.tian@intel.com \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=kwankhede@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkml@metux.net \
    --cc=lushenming@huawei.com \
    --cc=parav@mellanox.com \
    --cc=pbonzini@redhat.com \
    --cc=robin.murphy@arm.com \
    --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.