All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Tian, Kevin" <kevin.tian@intel.com>
To: Jason Gunthorpe <jgg@nvidia.com>,
	Alex Williamson <alex.williamson@redhat.com>,
	Cornelia Huck <cohuck@redhat.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	Kirti Wankhede <kwankhede@nvidia.com>
Cc: "Raj, Ashok" <ashok.raj@intel.com>,
	"Williams, Dan J" <dan.j.williams@intel.com>,
	Christoph Hellwig <hch@lst.de>,
	Leon Romanovsky <leonro@nvidia.com>,
	Max Gurtovoy <mgurtovoy@nvidia.com>,
	Tarun Gupta <targupta@nvidia.com>
Subject: RE: [PATCH 10/18] vfio/mdev: Remove duplicate storage of parent in mdev_device
Date: Fri, 26 Mar 2021 03:53:10 +0000	[thread overview]
Message-ID: <MWHPR11MB18864F0836984277A52BB4CB8C619@MWHPR11MB1886.namprd11.prod.outlook.com> (raw)
In-Reply-To: <10-v1-7dedf20b2b75+4f785-vfio2_jgg@nvidia.com>

> From: Jason Gunthorpe <jgg@nvidia.com>
> Sent: Wednesday, March 24, 2021 1:55 AM
> 
> mdev_device->type->parent is the same thing.
> 
> The struct mdev_device was relying on the kref on the mdev_parent to also
> indirectly hold a kref on the mdev_type pointer. Now that the type holds a
> kref on the parent we can directly kref the mdev_type and remove this
> implicit relationship.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
>  drivers/vfio/mdev/mdev_core.c | 13 +++++--------
>  drivers/vfio/mdev/vfio_mdev.c | 14 +++++++-------
>  include/linux/mdev.h          |  1 -
>  3 files changed, 12 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/vfio/mdev/mdev_core.c
> b/drivers/vfio/mdev/mdev_core.c
> index 4b5e372ed58f26..493df3da451339 100644
> --- a/drivers/vfio/mdev/mdev_core.c
> +++ b/drivers/vfio/mdev/mdev_core.c
> @@ -29,7 +29,7 @@ static DEFINE_MUTEX(mdev_list_lock);
> 
>  struct device *mdev_parent_dev(struct mdev_device *mdev)
>  {
> -	return mdev->parent->dev;
> +	return mdev->type->parent->dev;
>  }
>  EXPORT_SYMBOL(mdev_parent_dev);
> 
> @@ -58,12 +58,11 @@ void mdev_release_parent(struct kref *kref)
>  /* Caller must hold parent unreg_sem read or write lock */
>  static void mdev_device_remove_common(struct mdev_device *mdev)
>  {
> -	struct mdev_parent *parent;
> +	struct mdev_parent *parent = mdev->type->parent;

What about having a wrapper here, like mdev_parent_dev? For
readability it's not necessary to show that the parent is indirectly
retrieved through mdev_type.

>  	int ret;
> 
>  	mdev_remove_sysfs_files(mdev);
>  	device_del(&mdev->dev);
> -	parent = mdev->parent;
>  	lockdep_assert_held(&parent->unreg_sem);
>  	ret = parent->ops->remove(mdev);
>  	if (ret)
> @@ -212,7 +211,7 @@ static void mdev_device_release(struct device *dev)
>  	struct mdev_device *mdev = to_mdev_device(dev);
> 
>  	/* Pairs with the get in mdev_device_create() */
> -	mdev_put_parent(mdev->parent);
> +	kobject_put(&mdev->type->kobj);

Maybe keep mdev_get/put_parent and change them to accept "struct
mdev_device *" parameter like other places.

> 
>  	mutex_lock(&mdev_list_lock);
>  	list_del(&mdev->next);
> @@ -250,9 +249,8 @@ int mdev_device_create(struct mdev_type *type,
> const guid_t *uuid)
>  	mdev->dev.release = mdev_device_release;
>  	mdev->dev.groups = parent->ops->mdev_attr_groups;
>  	mdev->type = type;
> -	mdev->parent = parent;
>  	/* Pairs with the put in mdev_device_release() */
> -	mdev_get_parent(parent);
> +	kobject_get(&type->kobj);
> 
>  	guid_copy(&mdev->uuid, uuid);
>  	list_add(&mdev->next, &mdev_list);
> @@ -300,7 +298,7 @@ int mdev_device_create(struct mdev_type *type,
> const guid_t *uuid)
>  int mdev_device_remove(struct mdev_device *mdev)
>  {
>  	struct mdev_device *tmp;
> -	struct mdev_parent *parent;
> +	struct mdev_parent *parent = mdev->type->parent;
> 
>  	mutex_lock(&mdev_list_lock);
>  	list_for_each_entry(tmp, &mdev_list, next) {
> @@ -321,7 +319,6 @@ int mdev_device_remove(struct mdev_device *mdev)
>  	mdev->active = false;
>  	mutex_unlock(&mdev_list_lock);
> 
> -	parent = mdev->parent;
>  	/* Check if parent unregistration has started */
>  	if (!down_read_trylock(&parent->unreg_sem))
>  		return -ENODEV;
> diff --git a/drivers/vfio/mdev/vfio_mdev.c b/drivers/vfio/mdev/vfio_mdev.c
> index cc9507ed85a181..922729071c5a8e 100644
> --- a/drivers/vfio/mdev/vfio_mdev.c
> +++ b/drivers/vfio/mdev/vfio_mdev.c
> @@ -24,7 +24,7 @@
>  static int vfio_mdev_open(struct vfio_device *core_vdev)
>  {
>  	struct mdev_device *mdev = to_mdev_device(core_vdev->dev);
> -	struct mdev_parent *parent = mdev->parent;
> +	struct mdev_parent *parent = mdev->type->parent;
> 
>  	int ret;
> 
> @@ -44,7 +44,7 @@ static int vfio_mdev_open(struct vfio_device
> *core_vdev)
>  static void vfio_mdev_release(struct vfio_device *core_vdev)
>  {
>  	struct mdev_device *mdev = to_mdev_device(core_vdev->dev);
> -	struct mdev_parent *parent = mdev->parent;
> +	struct mdev_parent *parent = mdev->type->parent;
> 
>  	if (likely(parent->ops->release))
>  		parent->ops->release(mdev);
> @@ -56,7 +56,7 @@ static long vfio_mdev_unlocked_ioctl(struct vfio_device
> *core_vdev,
>  				     unsigned int cmd, unsigned long arg)
>  {
>  	struct mdev_device *mdev = to_mdev_device(core_vdev->dev);
> -	struct mdev_parent *parent = mdev->parent;
> +	struct mdev_parent *parent = mdev->type->parent;
> 
>  	if (unlikely(!parent->ops->ioctl))
>  		return -EINVAL;
> @@ -68,7 +68,7 @@ static ssize_t vfio_mdev_read(struct vfio_device
> *core_vdev, char __user *buf,
>  			      size_t count, loff_t *ppos)
>  {
>  	struct mdev_device *mdev = to_mdev_device(core_vdev->dev);
> -	struct mdev_parent *parent = mdev->parent;
> +	struct mdev_parent *parent = mdev->type->parent;
> 
>  	if (unlikely(!parent->ops->read))
>  		return -EINVAL;
> @@ -81,7 +81,7 @@ static ssize_t vfio_mdev_write(struct vfio_device
> *core_vdev,
>  			       loff_t *ppos)
>  {
>  	struct mdev_device *mdev = to_mdev_device(core_vdev->dev);
> -	struct mdev_parent *parent = mdev->parent;
> +	struct mdev_parent *parent = mdev->type->parent;
> 
>  	if (unlikely(!parent->ops->write))
>  		return -EINVAL;
> @@ -93,7 +93,7 @@ static int vfio_mdev_mmap(struct vfio_device
> *core_vdev,
>  			  struct vm_area_struct *vma)
>  {
>  	struct mdev_device *mdev = to_mdev_device(core_vdev->dev);
> -	struct mdev_parent *parent = mdev->parent;
> +	struct mdev_parent *parent = mdev->type->parent;
> 
>  	if (unlikely(!parent->ops->mmap))
>  		return -EINVAL;
> @@ -104,7 +104,7 @@ static int vfio_mdev_mmap(struct vfio_device
> *core_vdev,
>  static void vfio_mdev_request(struct vfio_device *core_vdev, unsigned int
> count)
>  {
>  	struct mdev_device *mdev = to_mdev_device(core_vdev->dev);
> -	struct mdev_parent *parent = mdev->parent;
> +	struct mdev_parent *parent = mdev->type->parent;
> 
>  	if (parent->ops->request)
>  		parent->ops->request(mdev, count);
> diff --git a/include/linux/mdev.h b/include/linux/mdev.h
> index 349e8ac1fe3382..fb582adda28a9b 100644
> --- a/include/linux/mdev.h
> +++ b/include/linux/mdev.h
> @@ -14,7 +14,6 @@ struct mdev_type;
> 
>  struct mdev_device {
>  	struct device dev;
> -	struct mdev_parent *parent;
>  	guid_t uuid;
>  	void *driver_data;
>  	struct list_head next;
> --
> 2.31.0


  parent reply	other threads:[~2021-03-26  3:54 UTC|newest]

Thread overview: 101+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-23 17:55 [PATCH 00/18] Make vfio_mdev type safe Jason Gunthorpe
2021-03-23 17:55 ` [Intel-gfx] " Jason Gunthorpe
2021-03-23 17:55 ` Jason Gunthorpe
2021-03-23 17:55 ` [PATCH 01/18] vfio/mdev: Fix missing static's on MDEV_TYPE_ATTR's Jason Gunthorpe
2021-03-23 17:55 ` [PATCH 02/18] vfio/mdev: Add missing typesafety around mdev_device Jason Gunthorpe
2021-03-26  2:04   ` Tian, Kevin
2021-03-30 15:24   ` Cornelia Huck
2021-03-23 17:55 ` [PATCH 03/18] vfio/mdev: Simplify driver registration Jason Gunthorpe
2021-03-23 19:14   ` Christoph Hellwig
2021-03-26 12:10     ` Jason Gunthorpe
2021-03-26 12:55       ` Christoph Hellwig
2021-03-26  2:17   ` Tian, Kevin
2021-03-30 15:28   ` Cornelia Huck
2021-03-23 17:55 ` [PATCH 04/18] vfio/mdev: Use struct mdev_type in struct mdev_device Jason Gunthorpe
2021-03-23 19:15   ` Christoph Hellwig
2021-03-26  2:29   ` Tian, Kevin
2021-04-06 18:41     ` Jason Gunthorpe
2021-03-30 15:31   ` Cornelia Huck
2021-03-23 17:55 ` [PATCH 05/18] vfio/mdev: Do not allow a mdev_type to have a NULL parent pointer Jason Gunthorpe
2021-03-23 19:15   ` Christoph Hellwig
2021-04-06 16:08     ` Jason Gunthorpe
2021-03-26  2:38   ` Tian, Kevin
2021-03-29  8:42   ` Max Gurtovoy
2021-03-30 15:34   ` Cornelia Huck
2021-03-23 17:55 ` [PATCH 06/18] vfio/mdev: Expose mdev_get/put_parent to mdev_private.h Jason Gunthorpe
2021-03-23 19:16   ` Christoph Hellwig
2021-03-26  2:47   ` Tian, Kevin
2021-03-30 15:37   ` Cornelia Huck
2021-03-23 17:55 ` [PATCH 07/18] vfio/mdev: Add missing reference counting to mdev_type Jason Gunthorpe
2021-03-23 19:17   ` Christoph Hellwig
2021-03-26  2:52   ` Tian, Kevin
2021-03-30 15:38   ` Cornelia Huck
2021-03-23 17:55 ` [PATCH 08/18] vfio/mdev: Reorganize mdev_device_create() Jason Gunthorpe
2021-03-23 19:20   ` Christoph Hellwig
2021-03-26  3:33     ` Tian, Kevin
2021-03-26  3:36       ` Tian, Kevin
2021-04-06 16:40     ` Jason Gunthorpe
2021-03-26  3:31   ` Tian, Kevin
2021-03-30 15:50   ` Cornelia Huck
2021-03-23 17:55 ` [PATCH 09/18] vfio/mdev: Add missing error handling to dev_set_name() Jason Gunthorpe
2021-03-23 19:21   ` Christoph Hellwig
2021-03-26  3:35   ` Tian, Kevin
2021-03-29  8:50   ` Max Gurtovoy
2021-03-30 15:53   ` Cornelia Huck
2021-03-23 17:55 ` [PATCH 10/18] vfio/mdev: Remove duplicate storage of parent in mdev_device Jason Gunthorpe
2021-03-23 19:22   ` Christoph Hellwig
2021-03-26  3:53   ` Tian, Kevin [this message]
2021-03-26 11:53     ` Jason Gunthorpe
2021-03-30 16:14       ` Cornelia Huck
2021-03-30 16:50         ` Jason Gunthorpe
2021-03-30 16:15   ` Cornelia Huck
2021-03-23 17:55 ` [PATCH 11/18] vfio/mdev: Add mdev/mtype_get_type_group_id() Jason Gunthorpe
2021-03-23 19:23   ` Christoph Hellwig
2021-04-06 18:53     ` Jason Gunthorpe
2021-03-26  5:52   ` Tian, Kevin
2021-03-30 16:26   ` Cornelia Huck
2021-03-23 17:55 ` [PATCH 12/18] vfio/mtty: Use mdev_get_type_group_id() Jason Gunthorpe
2021-03-23 19:24   ` Christoph Hellwig
2021-03-23 17:55 ` [PATCH 13/18] vfio/mdpy: " Jason Gunthorpe
2021-03-23 19:25   ` Christoph Hellwig
2021-03-23 17:55 ` [PATCH 14/18] vfio/mbochs: " Jason Gunthorpe
2021-03-23 19:25   ` Christoph Hellwig
2021-03-23 17:55 ` [PATCH 15/18] vfio/gvt: Make DRM_I915_GVT depend on VFIO_MDEV Jason Gunthorpe
2021-03-23 17:55   ` [Intel-gfx] " Jason Gunthorpe
2021-03-23 19:26   ` Christoph Hellwig
2021-03-23 19:39     ` Jason Gunthorpe
2021-03-23 19:39       ` [Intel-gfx] " Jason Gunthorpe
2021-03-30  4:39       ` Zhenyu Wang
2021-03-30  4:39         ` Zhenyu Wang
2021-03-26  6:03   ` Tian, Kevin
2021-03-26  6:03     ` Tian, Kevin
2021-03-23 17:55 ` [PATCH 16/18] vfio/gvt: Use mdev_get_type_group_id() Jason Gunthorpe
2021-03-23 17:55   ` [Intel-gfx] " Jason Gunthorpe
2021-03-23 19:28   ` Christoph Hellwig
2021-03-26  6:09   ` Tian, Kevin
2021-03-26  6:09     ` [Intel-gfx] " Tian, Kevin
2021-03-23 17:55 ` [PATCH 17/18] vfio/mdev: Remove kobj from mdev_parent_ops->create() Jason Gunthorpe
2021-03-23 17:55   ` [Intel-gfx] " Jason Gunthorpe
2021-03-23 17:55   ` Jason Gunthorpe
2021-03-23 19:29   ` Christoph Hellwig
2021-03-23 19:29     ` [Intel-gfx] " Christoph Hellwig
2021-03-26  6:11   ` Tian, Kevin
2021-03-26  6:11     ` [Intel-gfx] " Tian, Kevin
2021-03-26  6:11     ` Tian, Kevin
2021-03-30 16:29   ` Cornelia Huck
2021-03-30 16:29     ` [Intel-gfx] " Cornelia Huck
2021-03-30 16:29     ` Cornelia Huck
2021-03-23 17:55 ` [PATCH 18/18] vfio/mdev: Correct the function signatures for the mdev_type_attributes Jason Gunthorpe
2021-03-23 17:55   ` [Intel-gfx] " Jason Gunthorpe
2021-03-23 17:55   ` Jason Gunthorpe
2021-03-23 19:31   ` Christoph Hellwig
2021-03-23 19:31     ` [Intel-gfx] " Christoph Hellwig
2021-04-06 18:34     ` Jason Gunthorpe
2021-04-06 18:34       ` [Intel-gfx] " Jason Gunthorpe
2021-04-06 18:34       ` Jason Gunthorpe
2021-03-26  7:03   ` Tian, Kevin
2021-03-26  7:03     ` [Intel-gfx] " Tian, Kevin
2021-03-26  7:03     ` Tian, Kevin
2021-03-30 16:35   ` Cornelia Huck
2021-03-30 16:35     ` [Intel-gfx] " Cornelia Huck
2021-03-30 16:35     ` Cornelia Huck

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=MWHPR11MB18864F0836984277A52BB4CB8C619@MWHPR11MB1886.namprd11.prod.outlook.com \
    --to=kevin.tian@intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=ashok.raj@intel.com \
    --cc=cohuck@redhat.com \
    --cc=dan.j.williams@intel.com \
    --cc=hch@lst.de \
    --cc=jgg@nvidia.com \
    --cc=kvm@vger.kernel.org \
    --cc=kwankhede@nvidia.com \
    --cc=leonro@nvidia.com \
    --cc=mgurtovoy@nvidia.com \
    --cc=targupta@nvidia.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.