public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: alex.williamson@redhat.com
Cc: jike.song@intel.com, kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Zhenyu Wang <zhenyuw@linux.intel.com>,
	kwankhede@nvidia.com, Zhi Wang <zhi.a.wang@intel.com>
Subject: [PATCH v2 3/4] vfio-mdev: Make mdev_parent private
Date: Thu, 22 Dec 2016 13:22:09 -0700	[thread overview]
Message-ID: <20161222202209.15541.53734.stgit@gimli.home> (raw)
In-Reply-To: <20161222201809.15541.22506.stgit@gimli.home>

Rather than hoping for good behavior by marking some elements
internal, enforce it by making the entire structure private and
creating an accessor function for the one useful external field.

Cc: Kirti Wankhede <kwankhede@nvidia.com>
Cc: Zhenyu Wang <zhenyuw@linux.intel.com>
Cc: Zhi Wang <zhi.a.wang@intel.com>
Cc: Jike Song <jike.song@intel.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
 Documentation/vfio-mediated-device.txt |    3 +++
 drivers/gpu/drm/i915/gvt/kvmgt.c       |    2 +-
 drivers/vfio/mdev/mdev_core.c          |    6 ++++++
 drivers/vfio/mdev/mdev_private.h       |   10 ++++++++++
 include/linux/mdev.h                   |   15 ++-------------
 samples/vfio-mdev/mtty.c               |    2 +-
 6 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/Documentation/vfio-mediated-device.txt b/Documentation/vfio-mediated-device.txt
index cfee106..d226c7a 100644
--- a/Documentation/vfio-mediated-device.txt
+++ b/Documentation/vfio-mediated-device.txt
@@ -223,6 +223,9 @@ Directories and files under the sysfs for Each Physical Device
 
 	sprintf(buf, "%s-%s", dev_driver_string(parent->dev), group->name);
 
+  (or using mdev_parent_dev(mdev) to arrive at the parent device outside
+   of the core mdev code)
+
 * device_api
 
   This attribute should show which device API is being created, for example,
diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c
index 081ada2..3850032 100644
--- a/drivers/gpu/drm/i915/gvt/kvmgt.c
+++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
@@ -396,7 +396,7 @@ static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev)
 	struct device *pdev;
 	void *gvt;
 
-	pdev = mdev->parent->dev;
+	pdev = mdev_parent_dev(mdev);
 	gvt = kdev_to_i915(pdev)->gvt;
 
 	type = intel_gvt_find_vgpu_type(gvt, kobject_name(kobj));
diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c
index bf3b3b0..30d0530 100644
--- a/drivers/vfio/mdev/mdev_core.c
+++ b/drivers/vfio/mdev/mdev_core.c
@@ -30,6 +30,12 @@
 static LIST_HEAD(mdev_list);
 static DEFINE_MUTEX(mdev_list_lock);
 
+struct device *mdev_parent_dev(struct mdev_device *mdev)
+{
+	return mdev->parent->dev;
+}
+EXPORT_SYMBOL(mdev_parent_dev);
+
 static int _find_mdev_device(struct device *dev, void *data)
 {
 	struct mdev_device *mdev;
diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h
index 0b72c2d9..b05dd22 100644
--- a/drivers/vfio/mdev/mdev_private.h
+++ b/drivers/vfio/mdev/mdev_private.h
@@ -16,6 +16,16 @@
 int  mdev_bus_register(void);
 void mdev_bus_unregister(void);
 
+struct mdev_parent {
+	struct device *dev;
+	const struct mdev_parent_ops *ops;
+	struct kref ref;
+	struct mutex lock;
+	struct list_head next;
+	struct kset *mdev_types_kset;
+	struct list_head type_list;
+};
+
 struct mdev_type {
 	struct kobject kobj;
 	struct kobject *devices_kobj;
diff --git a/include/linux/mdev.h b/include/linux/mdev.h
index 853bb78..f586222 100644
--- a/include/linux/mdev.h
+++ b/include/linux/mdev.h
@@ -13,19 +13,6 @@
 #ifndef MDEV_H
 #define MDEV_H
 
-/* Parent device */
-struct mdev_parent {
-	struct device			*dev;
-	const struct mdev_parent_ops	*ops;
-
-	/* internal */
-	struct kref		ref;
-	struct mutex		lock;
-	struct list_head	next;
-	struct kset		*mdev_types_kset;
-	struct list_head	type_list;
-};
-
 /* Mediated device */
 struct mdev_device {
 	struct device		dev;
@@ -165,4 +152,6 @@ extern int  mdev_register_device(struct device *dev,
 extern int  mdev_register_driver(struct mdev_driver *drv, struct module *owner);
 extern void mdev_unregister_driver(struct mdev_driver *drv);
 
+extern struct device *mdev_parent_dev(struct mdev_device *mdev);
+
 #endif /* MDEV_H */
diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c
index 1a74f0e..5e13efc 100644
--- a/samples/vfio-mdev/mtty.c
+++ b/samples/vfio-mdev/mtty.c
@@ -734,7 +734,7 @@ int mtty_create(struct kobject *kobj, struct mdev_device *mdev)
 
 	for (i = 0; i < 2; i++) {
 		snprintf(name, MTTY_STRING_LEN, "%s-%d",
-			dev_driver_string(mdev->parent->dev), i + 1);
+			dev_driver_string(mdev_parent_dev(mdev)), i + 1);
 		if (!strcmp(kobj->name, name)) {
 			nr_ports = i + 1;
 			break;

  parent reply	other threads:[~2016-12-22 20:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-22 20:21 [PATCH v2 0/4] vfio-mdev: Fix remove race, clean namespace and better define ABI Alex Williamson
2016-12-22 20:21 ` [PATCH v2 1/4] vfio-mdev: Fix remove race Alex Williamson
2016-12-25 17:09   ` Kirti Wankhede
2016-12-25 19:40     ` Alex Williamson
2016-12-26  3:28       ` Kirti Wankhede
2016-12-22 20:22 ` [PATCH v2 2/4] vfio-mdev: de-polute the namespace, rename parent_device & parent_ops Alex Williamson
2016-12-22 20:22 ` Alex Williamson [this message]
2016-12-22 20:22 ` [PATCH v2 4/4] vfio-mdev: Make mdev_device private and abstract interfaces Alex Williamson
2016-12-26  3:31 ` [PATCH v2 0/4] vfio-mdev: Fix remove race, clean namespace and better define ABI Kirti Wankhede

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=20161222202209.15541.53734.stgit@gimli.home \
    --to=alex.williamson@redhat.com \
    --cc=jike.song@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=kwankhede@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zhenyuw@linux.intel.com \
    --cc=zhi.a.wang@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox