All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Alex Williamson <alex.williamson@redhat.com>,
	Cornelia Huck <cohuck@redhat.com>,
	kvm@vger.kernel.org, Kirti Wankhede <kwankhede@nvidia.com>
Cc: "Raj, Ashok" <ashok.raj@intel.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Daniel Vetter <daniel@ffwll.ch>, Christoph Hellwig <hch@lst.de>,
	Leon Romanovsky <leonro@nvidia.com>,
	Max Gurtovoy <mgurtovoy@nvidia.com>,
	Tarun Gupta <targupta@nvidia.com>
Subject: [PATCH 09/12] vfio/mdev: Remove mdev_parent_ops dev_attr_groups
Date: Fri, 23 Apr 2021 20:03:06 -0300	[thread overview]
Message-ID: <9-v1-d88406ed308e+418-vfio3_jgg@nvidia.com> (raw)
In-Reply-To: <0-v1-d88406ed308e+418-vfio3_jgg@nvidia.com>

This is only used by one sample to print a fixed string that is pointless.

In general, having a device driver attach sysfs attributes to the parent
is horrific. This should never happen, and always leads to some kind of
liftime bug as it become very difficult for the sysfs attribute to go back
to any data owned by the device driver.

Remove the general mechanism to create this abuse.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/vfio/mdev/mdev_sysfs.c | 12 ++----------
 include/linux/mdev.h           |  2 --
 samples/vfio-mdev/mtty.c       | 30 +-----------------------------
 3 files changed, 3 insertions(+), 41 deletions(-)

diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c
index f5cf1931c54e48..66eef08833a4ef 100644
--- a/drivers/vfio/mdev/mdev_sysfs.c
+++ b/drivers/vfio/mdev/mdev_sysfs.c
@@ -197,7 +197,6 @@ void parent_remove_sysfs_files(struct mdev_parent *parent)
 		remove_mdev_supported_type(type);
 	}
 
-	sysfs_remove_groups(&parent->dev->kobj, parent->ops->dev_attr_groups);
 	kset_unregister(parent->mdev_types_kset);
 }
 
@@ -213,17 +212,10 @@ int parent_create_sysfs_files(struct mdev_parent *parent)
 
 	INIT_LIST_HEAD(&parent->type_list);
 
-	ret = sysfs_create_groups(&parent->dev->kobj,
-				  parent->ops->dev_attr_groups);
-	if (ret)
-		goto create_err;
-
 	ret = add_mdev_supported_type_groups(parent);
 	if (ret)
-		sysfs_remove_groups(&parent->dev->kobj,
-				    parent->ops->dev_attr_groups);
-	else
-		return ret;
+		goto create_err;
+	return 0;
 
 create_err:
 	kset_unregister(parent->mdev_types_kset);
diff --git a/include/linux/mdev.h b/include/linux/mdev.h
index ea48c401e4fa63..fd9fe1dcf0e230 100644
--- a/include/linux/mdev.h
+++ b/include/linux/mdev.h
@@ -57,7 +57,6 @@ struct device *mtype_get_parent_dev(struct mdev_type *mtype);
  *
  * @owner:		The module owner.
  * @device_driver:	Which device driver to probe() on newly created devices
- * @dev_attr_groups:	Attributes of the parent device.
  * @mdev_attr_groups:	Attributes of the mediated device.
  * @supported_type_groups: Attributes to define supported types. It is mandatory
  *			to provide supported types.
@@ -67,7 +66,6 @@ struct device *mtype_get_parent_dev(struct mdev_type *mtype);
 struct mdev_parent_ops {
 	struct module   *owner;
 	struct mdev_driver *device_driver;
-	const struct attribute_group **dev_attr_groups;
 	const struct attribute_group **mdev_attr_groups;
 	struct attribute_group **supported_type_groups;
 };
diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c
index d2a168420b775d..31eec76bc553ce 100644
--- a/samples/vfio-mdev/mtty.c
+++ b/samples/vfio-mdev/mtty.c
@@ -1207,38 +1207,11 @@ static void mtty_close(struct vfio_device *mdev)
 	pr_info("%s\n", __func__);
 }
 
-static ssize_t
-sample_mtty_dev_show(struct device *dev, struct device_attribute *attr,
-		     char *buf)
-{
-	return sprintf(buf, "This is phy device\n");
-}
-
-static DEVICE_ATTR_RO(sample_mtty_dev);
-
-static struct attribute *mtty_dev_attrs[] = {
-	&dev_attr_sample_mtty_dev.attr,
-	NULL,
-};
-
-static const struct attribute_group mtty_dev_group = {
-	.name  = "mtty_dev",
-	.attrs = mtty_dev_attrs,
-};
-
-static const struct attribute_group *mtty_dev_groups[] = {
-	&mtty_dev_group,
-	NULL,
-};
-
 static ssize_t
 sample_mdev_dev_show(struct device *dev, struct device_attribute *attr,
 		     char *buf)
 {
-	if (mdev_from_dev(dev))
-		return sprintf(buf, "This is MDEV %s\n", dev_name(dev));
-
-	return sprintf(buf, "\n");
+	return sprintf(buf, "This is MDEV %s\n", dev_name(dev));
 }
 
 static DEVICE_ATTR_RO(sample_mdev_dev);
@@ -1340,7 +1313,6 @@ static struct mdev_driver mtty_driver = {
 static const struct mdev_parent_ops mdev_fops = {
 	.owner                  = THIS_MODULE,
 	.device_driver		= &mtty_driver,
-	.dev_attr_groups        = mtty_dev_groups,
 	.supported_type_groups  = mdev_type_groups,
 };
 
-- 
2.31.1


  parent reply	other threads:[~2021-04-23 23:08 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-23 23:02 [PATCH 00/12] Remove vfio_mdev.c, mdev_parent_ops and more Jason Gunthorpe
2021-04-23 23:02 ` [Intel-gfx] " Jason Gunthorpe
2021-04-23 23:02 ` Jason Gunthorpe
2021-04-23 23:02 ` [PATCH 01/12] vfio/mdev: Remove CONFIG_VFIO_MDEV_DEVICE Jason Gunthorpe
2021-04-23 23:02   ` [Intel-gfx] " Jason Gunthorpe
2021-04-23 23:02   ` Jason Gunthorpe
2021-04-24  0:08   ` Randy Dunlap
2021-04-24  0:08     ` [Intel-gfx] " Randy Dunlap
2021-04-24  0:08     ` Randy Dunlap
2021-04-26 18:26     ` Jason Gunthorpe
2021-04-26 18:26       ` [Intel-gfx] " Jason Gunthorpe
2021-04-26 18:26       ` Jason Gunthorpe
2021-04-26 19:11       ` Randy Dunlap
2021-04-26 19:11         ` [Intel-gfx] " Randy Dunlap
2021-04-26 19:11         ` Randy Dunlap
2021-04-23 23:02 ` [PATCH 02/12] vfio/mdev: Allow the mdev_parent_ops to specify the device driver to bind Jason Gunthorpe
2021-04-26 14:02   ` Christoph Hellwig
2021-04-26 14:11     ` Jason Gunthorpe
2021-04-23 23:03 ` [PATCH 03/12] vfio/mtty: Convert to use vfio_register_group_dev() Jason Gunthorpe
2021-04-26 14:06   ` Christoph Hellwig
2021-04-23 23:03 ` [PATCH 04/12] vfio/mdpy: " Jason Gunthorpe
2021-04-26 14:06   ` Christoph Hellwig
2021-04-23 23:03 ` [PATCH 05/12] vfio/mbochs: " Jason Gunthorpe
2021-04-26 14:06   ` Christoph Hellwig
2021-04-23 23:03 ` [PATCH 06/12] vfio/ap_ops: " Jason Gunthorpe
2021-04-26 14:07   ` Christoph Hellwig
2021-04-26 17:48   ` Cornelia Huck
2021-04-26 18:10     ` Jason Gunthorpe
2021-04-26 23:41     ` Halil Pasic
2021-05-03 20:14     ` Tony Krowiak
2021-05-03 20:33       ` Jason Gunthorpe
2021-05-04 13:58         ` Tony Krowiak
2021-05-04 16:04           ` Jason Gunthorpe
2021-05-05 13:07             ` Tony Krowiak
2021-05-04 15:30       ` Cornelia Huck
2021-05-05 12:30         ` Tony Krowiak
2021-05-05 17:47           ` Jason Gunthorpe
2021-05-05 16:28       ` Tony Krowiak
2021-04-23 23:03 ` [PATCH 07/12] vfio/ccw: " Jason Gunthorpe
2021-04-23 23:03 ` [PATCH 08/12] vfio/gvt: " Jason Gunthorpe
2021-04-23 23:03   ` [Intel-gfx] " Jason Gunthorpe
2021-04-23 23:03   ` Jason Gunthorpe
2021-04-26 14:13   ` Christoph Hellwig
2021-04-26 14:13     ` [Intel-gfx] " Christoph Hellwig
2021-04-26 15:44     ` Jason Gunthorpe
2021-04-26 15:44       ` [Intel-gfx] " Jason Gunthorpe
2021-04-26 15:44       ` Jason Gunthorpe
2021-04-23 23:03 ` Jason Gunthorpe [this message]
2021-04-26 14:14   ` [PATCH 09/12] vfio/mdev: Remove mdev_parent_ops dev_attr_groups Christoph Hellwig
2021-04-23 23:03 ` [PATCH 10/12] vfio/mdev: Remove mdev_parent_ops Jason Gunthorpe
2021-04-23 23:03   ` [Intel-gfx] " Jason Gunthorpe
2021-04-23 23:03   ` Jason Gunthorpe
2021-04-26 14:19   ` Christoph Hellwig
2021-04-26 14:19     ` [Intel-gfx] " Christoph Hellwig
2021-04-26 18:33     ` Jason Gunthorpe
2021-04-26 18:33       ` [Intel-gfx] " Jason Gunthorpe
2021-04-26 18:33       ` Jason Gunthorpe
2021-04-23 23:03 ` [PATCH 11/12] vfio/mdev: Use the driver core to create the 'remove' file Jason Gunthorpe
2021-04-26 14:20   ` Christoph Hellwig
2021-04-26 19:07     ` Jason Gunthorpe
2021-04-23 23:03 ` [PATCH 12/12] vfio/mdev: Remove mdev drvdata Jason Gunthorpe
2021-04-26 14:20   ` Christoph Hellwig
2021-04-26 16:43 ` [PATCH 00/12] Remove vfio_mdev.c, mdev_parent_ops and more Christian Borntraeger
2021-04-26 16:43   ` [Intel-gfx] " Christian Borntraeger
2021-04-26 16:43   ` Christian Borntraeger
2021-04-26 17:42   ` Jason Gunthorpe
2021-04-26 17:42     ` [Intel-gfx] " Jason Gunthorpe
2021-04-26 17:42     ` Jason Gunthorpe
2021-04-27  7:33     ` Christian Borntraeger
2021-04-27  7:33       ` [Intel-gfx] " Christian Borntraeger
2021-04-27  7:33       ` Christian Borntraeger
2021-04-27 23:21       ` Jason Gunthorpe
2021-04-27 23:21         ` [Intel-gfx] " Jason Gunthorpe
2021-04-27 23:21         ` Jason Gunthorpe

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=9-v1-d88406ed308e+418-vfio3_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=daniel@ffwll.ch \
    --cc=hch@lst.de \
    --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.