All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Alex Williamson <alex.williamson@redhat.com>,
	kvm@vger.kernel.org, Kirti Wankhede <kwankhede@nvidia.com>
Cc: "Raj, Ashok" <ashok.raj@intel.com>,
	Cornelia Huck <cohuck@redhat.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Christoph Hellwig <hch@lst.de>, Kevin Tian <kevin.tian@intel.com>,
	Leon Romanovsky <leonro@nvidia.com>,
	Max Gurtovoy <mgurtovoy@nvidia.com>,
	Tarun Gupta <targupta@nvidia.com>
Subject: [PATCH v2 05/18] vfio/mdev: Use struct mdev_type in struct mdev_device
Date: Tue,  6 Apr 2021 16:40:28 -0300	[thread overview]
Message-ID: <5-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com> (raw)
In-Reply-To: <0-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com>

The kobj pointer in mdev_device is actually pointing at a struct
mdev_type. Use the proper type so things are understandable.

There are a number of places that are confused and passing both the mdev
and the mtype as function arguments, fix these to derive the mtype
directly from the mdev to remove the redundancy.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/vfio/mdev/mdev_core.c    | 16 ++++++----------
 drivers/vfio/mdev/mdev_private.h |  7 +++----
 drivers/vfio/mdev/mdev_sysfs.c   | 11 ++++++-----
 include/linux/mdev.h             |  4 +++-
 4 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c
index 057922a1707e04..5ca0efa5266bad 100644
--- a/drivers/vfio/mdev/mdev_core.c
+++ b/drivers/vfio/mdev/mdev_core.c
@@ -73,11 +73,9 @@ static void mdev_put_parent(struct mdev_parent *parent)
 static void mdev_device_remove_common(struct mdev_device *mdev)
 {
 	struct mdev_parent *parent;
-	struct mdev_type *type;
 	int ret;
 
-	type = to_mdev_type(mdev->type_kobj);
-	mdev_remove_sysfs_files(mdev, type);
+	mdev_remove_sysfs_files(mdev);
 	device_del(&mdev->dev);
 	parent = mdev->parent;
 	lockdep_assert_held(&parent->unreg_sem);
@@ -241,13 +239,11 @@ static void mdev_device_release(struct device *dev)
 	mdev_device_free(mdev);
 }
 
-int mdev_device_create(struct kobject *kobj,
-		       struct device *dev, const guid_t *uuid)
+int mdev_device_create(struct mdev_type *type, const guid_t *uuid)
 {
 	int ret;
 	struct mdev_device *mdev, *tmp;
 	struct mdev_parent *parent;
-	struct mdev_type *type = to_mdev_type(kobj);
 
 	parent = mdev_get_parent(type->parent);
 	if (!parent)
@@ -285,14 +281,14 @@ int mdev_device_create(struct kobject *kobj,
 	}
 
 	device_initialize(&mdev->dev);
-	mdev->dev.parent  = dev;
+	mdev->dev.parent = parent->dev;
 	mdev->dev.bus     = &mdev_bus_type;
 	mdev->dev.release = mdev_device_release;
 	dev_set_name(&mdev->dev, "%pUl", uuid);
 	mdev->dev.groups = parent->ops->mdev_attr_groups;
-	mdev->type_kobj = kobj;
+	mdev->type = type;
 
-	ret = parent->ops->create(kobj, mdev);
+	ret = parent->ops->create(&type->kobj, mdev);
 	if (ret)
 		goto ops_create_fail;
 
@@ -300,7 +296,7 @@ int mdev_device_create(struct kobject *kobj,
 	if (ret)
 		goto add_fail;
 
-	ret = mdev_create_sysfs_files(mdev, type);
+	ret = mdev_create_sysfs_files(mdev);
 	if (ret)
 		goto sysfs_fail;
 
diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h
index bb60ec4a8d9d21..debf27f95b4f10 100644
--- a/drivers/vfio/mdev/mdev_private.h
+++ b/drivers/vfio/mdev/mdev_private.h
@@ -40,11 +40,10 @@ struct mdev_type {
 int  parent_create_sysfs_files(struct mdev_parent *parent);
 void parent_remove_sysfs_files(struct mdev_parent *parent);
 
-int  mdev_create_sysfs_files(struct mdev_device *mdev, struct mdev_type *type);
-void mdev_remove_sysfs_files(struct mdev_device *mdev, struct mdev_type *type);
+int  mdev_create_sysfs_files(struct mdev_device *mdev);
+void mdev_remove_sysfs_files(struct mdev_device *mdev);
 
-int  mdev_device_create(struct kobject *kobj,
-			struct device *dev, const guid_t *uuid);
+int mdev_device_create(struct mdev_type *kobj, const guid_t *uuid);
 int  mdev_device_remove(struct mdev_device *dev);
 
 #endif /* MDEV_PRIVATE_H */
diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c
index 18114f3e090a2a..bcfe48d56e8a9e 100644
--- a/drivers/vfio/mdev/mdev_sysfs.c
+++ b/drivers/vfio/mdev/mdev_sysfs.c
@@ -67,7 +67,7 @@ static ssize_t create_store(struct kobject *kobj, struct device *dev,
 	if (ret)
 		return ret;
 
-	ret = mdev_device_create(kobj, dev, &uuid);
+	ret = mdev_device_create(to_mdev_type(kobj), &uuid);
 	if (ret)
 		return ret;
 
@@ -249,8 +249,9 @@ static const struct attribute *mdev_device_attrs[] = {
 	NULL,
 };
 
-int mdev_create_sysfs_files(struct mdev_device *mdev, struct mdev_type *type)
+int mdev_create_sysfs_files(struct mdev_device *mdev)
 {
+	struct mdev_type *type = mdev->type;
 	struct kobject *kobj = &mdev->dev.kobj;
 	int ret;
 
@@ -271,15 +272,15 @@ int mdev_create_sysfs_files(struct mdev_device *mdev, struct mdev_type *type)
 create_files_failed:
 	sysfs_remove_link(kobj, "mdev_type");
 type_link_failed:
-	sysfs_remove_link(type->devices_kobj, dev_name(&mdev->dev));
+	sysfs_remove_link(mdev->type->devices_kobj, dev_name(&mdev->dev));
 	return ret;
 }
 
-void mdev_remove_sysfs_files(struct mdev_device *mdev, struct mdev_type *type)
+void mdev_remove_sysfs_files(struct mdev_device *mdev)
 {
 	struct kobject *kobj = &mdev->dev.kobj;
 
 	sysfs_remove_files(kobj, mdev_device_attrs);
 	sysfs_remove_link(kobj, "mdev_type");
-	sysfs_remove_link(type->devices_kobj, dev_name(&mdev->dev));
+	sysfs_remove_link(mdev->type->devices_kobj, dev_name(&mdev->dev));
 }
diff --git a/include/linux/mdev.h b/include/linux/mdev.h
index cb771c712da0f4..349e8ac1fe3382 100644
--- a/include/linux/mdev.h
+++ b/include/linux/mdev.h
@@ -10,13 +10,15 @@
 #ifndef MDEV_H
 #define MDEV_H
 
+struct mdev_type;
+
 struct mdev_device {
 	struct device dev;
 	struct mdev_parent *parent;
 	guid_t uuid;
 	void *driver_data;
 	struct list_head next;
-	struct kobject *type_kobj;
+	struct mdev_type *type;
 	struct device *iommu_device;
 	bool active;
 };
-- 
2.31.1


  parent reply	other threads:[~2021-04-06 20:07 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-06 19:40 [PATCH v2 00/18] Make vfio_mdev type safe Jason Gunthorpe
2021-04-06 19:40 ` [Intel-gfx] " Jason Gunthorpe
2021-04-06 19:40 ` Jason Gunthorpe
2021-04-06 19:40 ` [PATCH v2 01/18] vfio/mdev: Fix missing static's on MDEV_TYPE_ATTR's Jason Gunthorpe
2021-04-07  5:09   ` Christoph Hellwig
2021-04-06 19:40 ` [PATCH v2 02/18] vfio/mdev: Do not allow a mdev_type to have a NULL parent pointer Jason Gunthorpe
2021-04-06 19:40 ` [PATCH v2 03/18] vfio/mdev: Add missing typesafety around mdev_device Jason Gunthorpe
2021-04-07  5:16   ` Christoph Hellwig
2021-04-06 19:40 ` [PATCH v2 04/18] vfio/mdev: Simplify driver registration Jason Gunthorpe
2021-04-06 19:40 ` Jason Gunthorpe [this message]
2021-04-06 19:40 ` [PATCH v2 06/18] vfio/mdev: Expose mdev_get/put_parent to mdev_private.h Jason Gunthorpe
2021-04-06 19:40 ` [PATCH v2 07/18] vfio/mdev: Add missing reference counting to mdev_type Jason Gunthorpe
2021-04-06 19:40 ` [PATCH v2 08/18] vfio/mdev: Reorganize mdev_device_create() Jason Gunthorpe
2021-04-06 19:40 ` [PATCH v2 09/18] vfio/mdev: Add missing error handling to dev_set_name() Jason Gunthorpe
2021-04-06 19:40 ` [PATCH v2 10/18] vfio/mdev: Remove duplicate storage of parent in mdev_device Jason Gunthorpe
2021-04-06 19:40 ` [PATCH v2 11/18] vfio/mdev: Add mdev/mtype_get_type_group_id() Jason Gunthorpe
2021-04-06 19:40 ` [PATCH v2 12/18] vfio/mtty: Use mdev_get_type_group_id() Jason Gunthorpe
2021-04-06 19:40 ` [PATCH v2 13/18] vfio/mdpy: " Jason Gunthorpe
2021-04-06 19:40 ` [PATCH v2 14/18] vfio/mbochs: " Jason Gunthorpe
2021-04-06 19:40 ` [PATCH v2 15/18] vfio/gvt: Make DRM_I915_GVT depend on VFIO_MDEV Jason Gunthorpe
2021-04-06 19:40   ` [Intel-gfx] " Jason Gunthorpe
2021-04-12  7:27   ` Zhenyu Wang
2021-04-12  7:27     ` Zhenyu Wang
2021-04-06 19:40 ` [PATCH v2 16/18] vfio/gvt: Use mdev_get_type_group_id() Jason Gunthorpe
2021-04-06 19:40   ` [Intel-gfx] " Jason Gunthorpe
2021-04-12  7:30   ` Zhenyu Wang
2021-04-12  7:30     ` [Intel-gfx] " Zhenyu Wang
2021-04-06 19:40 ` [PATCH v2 17/18] vfio/mdev: Remove kobj from mdev_parent_ops->create() Jason Gunthorpe
2021-04-06 19:40   ` [Intel-gfx] " Jason Gunthorpe
2021-04-06 19:40   ` Jason Gunthorpe
2021-04-06 19:40 ` [PATCH v2 18/18] vfio/mdev: Correct the function signatures for the mdev_type_attributes Jason Gunthorpe
2021-04-06 19:40   ` [Intel-gfx] " Jason Gunthorpe
2021-04-06 19:40   ` Jason Gunthorpe
2021-04-14 18:17 ` [PATCH v2 00/18] Make vfio_mdev type safe Alex Williamson
2021-04-14 18:17   ` [Intel-gfx] " Alex Williamson
2021-04-14 18:17   ` Alex Williamson

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=5-v2-d36939638fc6+d54-vfio2_jgg@nvidia.com \
    --to=jgg@nvidia.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=kevin.tian@intel.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.