All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kirti Wankhede <kwankhede@nvidia.com>
To: Christoph Hellwig <hch@lst.de>,
	Tony Krowiak <akrowiak@linux.ibm.com>,
	Halil Pasic <pasic@linux.ibm.com>,
	Jason Herne <jjherne@linux.ibm.com>,
	Eric Farman <farman@linux.ibm.com>,
	Matthew Rosato <mjrosato@linux.ibm.com>,
	Zhenyu Wang <zhenyuw@linux.intel.com>,
	Zhi Wang <zhi.a.wang@intel.com>,
	Alex Williamson <alex.williamson@redhat.com>
Cc: kvm@vger.kernel.org, linux-s390@vger.kernel.org,
	intel-gvt-dev@lists.freedesktop.org, Neo Jia <cjia@nvidia.com>,
	Tarun Gupta <targupta@nvidia.com>,
	Dheeraj Nigam <dnigam@nvidia.com>
Subject: Re: [PATCH 10/13] vfio/mdev: consolidate all the name sysfs into the core code
Date: Thu, 16 Jun 2022 02:01:23 +0530	[thread overview]
Message-ID: <adab68ab-1f61-f975-8dee-f9f95012ecb5@nvidia.com> (raw)
In-Reply-To: <20220614045428.278494-11-hch@lst.de>



On 6/14/2022 10:24 AM, Christoph Hellwig wrote:
> Every driver just emits a static string, simply add a field to the
> mdev_type for the driver to fill out or fall back to the sysfs name and
> provide a standard sysfs show function.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Kirti Wankhede <kwankhede@nvidia.com>

> ---
>   .../driver-api/vfio-mediated-device.rst       |  2 +-
>   drivers/gpu/drm/i915/gvt/kvmgt.c              |  8 -------
>   drivers/s390/cio/vfio_ccw_ops.c               |  9 +-------
>   drivers/s390/crypto/vfio_ap_ops.c             |  9 --------
>   drivers/vfio/mdev/mdev_sysfs.c                | 11 ++++++++++
>   include/linux/mdev.h                          |  1 +
>   samples/vfio-mdev/mbochs.c                    | 20 ++++--------------
>   samples/vfio-mdev/mdpy.c                      | 21 +++++--------------
>   samples/vfio-mdev/mtty.c                      | 18 ++++------------
>   9 files changed, 27 insertions(+), 72 deletions(-)
> 
> diff --git a/Documentation/driver-api/vfio-mediated-device.rst b/Documentation/driver-api/vfio-mediated-device.rst
> index e9913bfb4393b..87d207744db79 100644
> --- a/Documentation/driver-api/vfio-mediated-device.rst
> +++ b/Documentation/driver-api/vfio-mediated-device.rst
> @@ -219,7 +219,7 @@ Directories and files under the sysfs for Each Physical Device
>   
>   * name
>   
> -  This attribute should show human readable name. This is optional attribute.
> +  This attribute shows a human readable name.
>   
>   * description
>   
> diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c
> index 44a418d897377..191e64ef70acf 100644
> --- a/drivers/gpu/drm/i915/gvt/kvmgt.c
> +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c
> @@ -138,20 +138,12 @@ static ssize_t description_show(struct mdev_type *mtype,
>   		       type->weight);
>   }
>   
> -static ssize_t name_show(struct mdev_type *mtype,
> -			 struct mdev_type_attribute *attr, char *buf)
> -{
> -	return sprintf(buf, "%s\n", mtype->sysfs_name);
> -}
> -
>   static MDEV_TYPE_ATTR_RO(available_instances);
>   static MDEV_TYPE_ATTR_RO(description);
> -static MDEV_TYPE_ATTR_RO(name);
>   
>   static const struct attribute *gvt_type_attrs[] = {
>   	&mdev_type_attr_available_instances.attr,
>   	&mdev_type_attr_description.attr,
> -	&mdev_type_attr_name.attr,
>   	NULL,
>   };
>   
> diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c
> index 730d87a96a305..35389f4b67dc5 100644
> --- a/drivers/s390/cio/vfio_ccw_ops.c
> +++ b/drivers/s390/cio/vfio_ccw_ops.c
> @@ -70,13 +70,6 @@ static int vfio_ccw_mdev_notifier(struct notifier_block *nb,
>   	return NOTIFY_DONE;
>   }
>   
> -static ssize_t name_show(struct mdev_type *mtype,
> -			 struct mdev_type_attribute *attr, char *buf)
> -{
> -	return sprintf(buf, "I/O subchannel (Non-QDIO)\n");
> -}
> -static MDEV_TYPE_ATTR_RO(name);
> -
>   static ssize_t available_instances_show(struct mdev_type *mtype,
>   					struct mdev_type_attribute *attr,
>   					char *buf)
> @@ -88,7 +81,6 @@ static ssize_t available_instances_show(struct mdev_type *mtype,
>   static MDEV_TYPE_ATTR_RO(available_instances);
>   
>   static const struct attribute *mdev_types_attrs[] = {
> -	&mdev_type_attr_name.attr,
>   	&mdev_type_attr_available_instances.attr,
>   	NULL,
>   };
> @@ -642,6 +634,7 @@ struct mdev_driver vfio_ccw_mdev_driver = {
>   int vfio_ccw_mdev_reg(struct subchannel *sch)
>   {
>   	strcat(sch->mdev_type.sysfs_name, "io");
> +	strcat(sch->mdev_type.pretty_name, "I/O subchannel (Non-QDIO)");
>   	sch->mdev_types[0] = &sch->mdev_type;
>   	return mdev_register_parent(&sch->parent, &sch->dev,
>   				    &vfio_ccw_mdev_driver, sch->mdev_types,
> diff --git a/drivers/s390/crypto/vfio_ap_ops.c b/drivers/s390/crypto/vfio_ap_ops.c
> index da21fd60877fb..d6b2e819a615e 100644
> --- a/drivers/s390/crypto/vfio_ap_ops.c
> +++ b/drivers/s390/crypto/vfio_ap_ops.c
> @@ -511,14 +511,6 @@ static void vfio_ap_mdev_remove(struct mdev_device *mdev)
>   	atomic_inc(&matrix_dev->available_instances);
>   }
>   
> -static ssize_t name_show(struct mdev_type *mtype,
> -			 struct mdev_type_attribute *attr, char *buf)
> -{
> -	return sprintf(buf, "%s\n", VFIO_AP_MDEV_NAME_HWVIRT);
> -}
> -
> -static MDEV_TYPE_ATTR_RO(name);
> -
>   static ssize_t available_instances_show(struct mdev_type *mtype,
>   					struct mdev_type_attribute *attr,
>   					char *buf)
> @@ -530,7 +522,6 @@ static ssize_t available_instances_show(struct mdev_type *mtype,
>   static MDEV_TYPE_ATTR_RO(available_instances);
>   
>   static const struct attribute *vfio_ap_mdev_type_attrs[] = {
> -	&mdev_type_attr_name.attr,
>   	&mdev_type_attr_available_instances.attr,
>   	NULL,
>   };
> diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c
> index 20763f1aa9f5a..8384e2992c706 100644
> --- a/drivers/vfio/mdev/mdev_sysfs.c
> +++ b/drivers/vfio/mdev/mdev_sysfs.c
> @@ -81,9 +81,20 @@ static ssize_t device_api_show(struct mdev_type *mtype,
>   }
>   static MDEV_TYPE_ATTR_RO(device_api);
>   
> +static ssize_t name_show(struct mdev_type *mtype,
> +			 struct mdev_type_attribute *attr, char *buf)
> +{
> +	if (!mtype->pretty_name[0])
> +		return sprintf(buf, "%s\n", mtype->sysfs_name);
> +	return sprintf(buf, "%s\n", mtype->pretty_name);
> +}
> +
> +static MDEV_TYPE_ATTR_RO(name);
> +
>   static struct attribute *mdev_types_core_attrs[] = {
>   	&mdev_type_attr_create.attr,
>   	&mdev_type_attr_device_api.attr,
> +	&mdev_type_attr_name.attr,
>   	NULL,
>   };
>   
> diff --git a/include/linux/mdev.h b/include/linux/mdev.h
> index 81e11e18b3e41..64ca2ba806ed3 100644
> --- a/include/linux/mdev.h
> +++ b/include/linux/mdev.h
> @@ -26,6 +26,7 @@ struct mdev_device {
>   struct mdev_type {
>   	/* set by the driver before calling mdev_register parent: */
>   	char sysfs_name[32];
> +	char pretty_name[32]; /* optional */
>   
>   	/* set by the core, can be used drivers */
>   	struct mdev_parent *parent;
> diff --git a/samples/vfio-mdev/mbochs.c b/samples/vfio-mdev/mbochs.c
> index 199846f01de92..c8271168a96ad 100644
> --- a/samples/vfio-mdev/mbochs.c
> +++ b/samples/vfio-mdev/mbochs.c
> @@ -101,26 +101,25 @@ MODULE_PARM_DESC(mem, "megabytes available to " MBOCHS_NAME " devices");
>   
>   static struct mbochs_type {
>   	struct mdev_type type;
> -	const char *name;
>   	u32 mbytes;
>   	u32 max_x;
>   	u32 max_y;
>   } mbochs_types[] = {
>   	{
>   		.type.sysfs_name	= MBOCHS_TYPE_1,
> -		.name	= MBOCHS_CLASS_NAME "-" MBOCHS_TYPE_1,
> +		.type.pretty_name	= MBOCHS_CLASS_NAME "-" MBOCHS_TYPE_1,
>   		.mbytes = 4,
>   		.max_x  = 800,
>   		.max_y  = 600,
>   	}, {
>   		.type.sysfs_name	= MBOCHS_TYPE_2,
> -		.name	= MBOCHS_CLASS_NAME "-" MBOCHS_TYPE_2,
> +		.type.pretty_name	= MBOCHS_CLASS_NAME "-" MBOCHS_TYPE_2,
>   		.mbytes = 16,
>   		.max_x  = 1920,
>   		.max_y  = 1440,
>   	}, {
>   		.type.sysfs_name	= MBOCHS_TYPE_3,
> -		.name	= MBOCHS_CLASS_NAME "-" MBOCHS_TYPE_3,
> +		.type.pretty_name	= MBOCHS_CLASS_NAME "-" MBOCHS_TYPE_3,
>   		.mbytes = 64,
>   		.max_x  = 0,
>   		.max_y  = 0,
> @@ -547,7 +546,7 @@ static int mbochs_probe(struct mdev_device *mdev)
>   		goto err_mem;
>   
>   	dev_info(dev, "%s: %s, %d MB, %ld pages\n", __func__,
> -		 type->name, type->mbytes, mdev_state->pagecount);
> +		 type->type.pretty_name, type->mbytes, mdev_state->pagecount);
>   
>   	mutex_init(&mdev_state->ops_lock);
>   	mdev_state->mdev = mdev;
> @@ -1334,16 +1333,6 @@ static const struct attribute_group *mdev_dev_groups[] = {
>   	NULL,
>   };
>   
> -static ssize_t name_show(struct mdev_type *mtype,
> -			 struct mdev_type_attribute *attr, char *buf)
> -{
> -	struct mbochs_type *type =
> -		container_of(mtype, struct mbochs_type, type);
> -
> -	return sprintf(buf, "%s\n", type->name);
> -}
> -static MDEV_TYPE_ATTR_RO(name);
> -
>   static ssize_t description_show(struct mdev_type *mtype,
>   				struct mdev_type_attribute *attr, char *buf)
>   {
> @@ -1368,7 +1357,6 @@ static ssize_t available_instances_show(struct mdev_type *mtype,
>   static MDEV_TYPE_ATTR_RO(available_instances);
>   
>   static const struct attribute *mdev_types_attrs[] = {
> -	&mdev_type_attr_name.attr,
>   	&mdev_type_attr_description.attr,
>   	&mdev_type_attr_available_instances.attr,
>   	NULL,
> diff --git a/samples/vfio-mdev/mdpy.c b/samples/vfio-mdev/mdpy.c
> index 401a9a622673c..1b2117772192f 100644
> --- a/samples/vfio-mdev/mdpy.c
> +++ b/samples/vfio-mdev/mdpy.c
> @@ -53,7 +53,6 @@ MODULE_PARM_DESC(count, "number of " MDPY_NAME " devices");
>   
>   static struct mdpy_type {
>   	struct mdev_type type;
> -	const char *name;
>   	u32 format;
>   	u32 bytepp;
>   	u32 width;
> @@ -61,21 +60,21 @@ static struct mdpy_type {
>   } mdpy_types[] = {
>   	{
>   		.type.sysfs_name 	= MDPY_TYPE_1,
> -		.name	= MDPY_CLASS_NAME "-" MDPY_TYPE_1,
> +		.type.pretty_name	= MDPY_CLASS_NAME "-" MDPY_TYPE_1,
>   		.format = DRM_FORMAT_XRGB8888,
>   		.bytepp = 4,
>   		.width	= 640,
>   		.height = 480,
>   	}, {
>   		.type.sysfs_name 	= MDPY_TYPE_2,
> -		.name	= MDPY_CLASS_NAME "-" MDPY_TYPE_2,
> +		.type.pretty_name	= MDPY_CLASS_NAME "-" MDPY_TYPE_2,
>   		.format = DRM_FORMAT_XRGB8888,
>   		.bytepp = 4,
>   		.width	= 1024,
>   		.height = 768,
>   	}, {
>   		.type.sysfs_name 	= MDPY_TYPE_3,
> -		.name	= MDPY_CLASS_NAME "-" MDPY_TYPE_3,
> +		.type.pretty_name	= MDPY_CLASS_NAME "-" MDPY_TYPE_3,
>   		.format = DRM_FORMAT_XRGB8888,
>   		.bytepp = 4,
>   		.width	= 1920,
> @@ -256,8 +255,8 @@ static int mdpy_probe(struct mdev_device *mdev)
>   		ret = -ENOMEM;
>   		goto err_vconfig;
>   	}
> -	dev_info(dev, "%s: %s (%dx%d)\n", __func__, type->name, type->width,
> -		 type->height);
> +	dev_info(dev, "%s: %s (%dx%d)\n", __func__, type->type.pretty_name,
> +		 type->width, type->height);
>   
>   	mutex_init(&mdev_state->ops_lock);
>   	mdev_state->mdev = mdev;
> @@ -651,15 +650,6 @@ static const struct attribute_group *mdev_dev_groups[] = {
>   	NULL,
>   };
>   
> -static ssize_t name_show(struct mdev_type *mtype,
> -			 struct mdev_type_attribute *attr, char *buf)
> -{
> -	struct mdpy_type *type = container_of(mtype, struct mdpy_type, type);
> -
> -	return sprintf(buf, "%s\n", type->name);
> -}
> -static MDEV_TYPE_ATTR_RO(name);
> -
>   static ssize_t description_show(struct mdev_type *mtype,
>   				struct mdev_type_attribute *attr, char *buf)
>   {
> @@ -679,7 +669,6 @@ static ssize_t available_instances_show(struct mdev_type *mtype,
>   static MDEV_TYPE_ATTR_RO(available_instances);
>   
>   static const struct attribute *mdev_types_attrs[] = {
> -	&mdev_type_attr_name.attr,
>   	&mdev_type_attr_description.attr,
>   	&mdev_type_attr_available_instances.attr,
>   	NULL,
> diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c
> index 2a470424628af..b95a4491265c5 100644
> --- a/samples/vfio-mdev/mtty.c
> +++ b/samples/vfio-mdev/mtty.c
> @@ -146,10 +146,11 @@ struct mdev_state {
>   static struct mtty_type {
>   	struct mdev_type type;
>   	int nr_ports;
> -	const char *name;
>   } mtty_types[2] = {
> -	{ .nr_ports = 1, .type.sysfs_name = "1", .name = "Single port serial" },
> -	{ .nr_ports = 2, .type.sysfs_name = "2", .name = "Dual port serial" },
> +	{ .nr_ports = 1, .type.sysfs_name = "1",
> +	  .type.pretty_name = "Single port serial" },
> +	{ .nr_ports = 2, .type.sysfs_name = "2",
> +	  .type.pretty_name = "Dual port serial" },
>   };
>   
>   static struct mdev_type *mtty_mdev_types[] = {
> @@ -1246,16 +1247,6 @@ static const struct attribute_group *mdev_dev_groups[] = {
>   	NULL,
>   };
>   
> -static ssize_t name_show(struct mdev_type *mtype,
> -			 struct mdev_type_attribute *attr, char *buf)
> -{
> -	struct mtty_type *type = container_of(mtype, struct mtty_type, type);
> -
> -	return sysfs_emit(buf, "%s\n", type->name);
> -}
> -
> -static MDEV_TYPE_ATTR_RO(name);
> -
>   static ssize_t available_instances_show(struct mdev_type *mtype,
>   					struct mdev_type_attribute *attr,
>   					char *buf)
> @@ -1269,7 +1260,6 @@ static ssize_t available_instances_show(struct mdev_type *mtype,
>   static MDEV_TYPE_ATTR_RO(available_instances);
>   
>   static const struct attribute *mdev_types_attrs[] = {
> -	&mdev_type_attr_name.attr,
>   	&mdev_type_attr_available_instances.attr,
>   	NULL,
>   };

  parent reply	other threads:[~2022-06-15 20:31 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-14  4:54 simplify the mdev interface v2 Christoph Hellwig
2022-06-14  4:54 ` [PATCH 01/13] vfio/mdev: make mdev.h standalone includable Christoph Hellwig
2022-06-14  9:50   ` Tian, Kevin
2022-06-15 19:12   ` Kirti Wankhede
2022-06-23 19:39   ` [PATCH 1/13] " Jason Gunthorpe
2022-06-14  4:54 ` [PATCH 02/13] vfio/mdev: embedd struct mdev_parent in the parent data structure Christoph Hellwig
2022-06-14  9:54   ` Tian, Kevin
2022-06-15 19:29   ` Kirti Wankhede
2022-06-23 20:18     ` Jason Gunthorpe
2022-06-24 12:29       ` Kirti Wankhede
2022-06-24 12:33         ` Jason Gunthorpe
2022-06-24 12:53           ` Kirti Wankhede
2022-06-24 13:05             ` Jason Gunthorpe
2022-06-24 13:14               ` Kirti Wankhede
2022-06-23 20:59   ` [PATCH 2/13] " Jason Gunthorpe
2022-06-14  4:54 ` [PATCH 03/13] vfio/mdev: simplify mdev_type handling Christoph Hellwig
2022-06-14  6:14   ` Yi Liu
2022-06-14 10:06   ` Tian, Kevin
2022-06-15  6:28     ` Christoph Hellwig
2022-06-15  6:11       ` Zhenyu Wang
2022-06-15 19:55   ` Kirti Wankhede
2022-06-19  7:42     ` Christoph Hellwig
2022-06-23 21:27   ` [PATCH 3/13] " Jason Gunthorpe
2022-06-24 12:32     ` Kirti Wankhede
2022-06-14  4:54 ` [PATCH 04/13] vfio/mdev: remove mdev_{create,remove}_sysfs_files Christoph Hellwig
2022-06-15 20:03   ` Kirti Wankhede
2022-06-19  7:37     ` Christoph Hellwig
2022-06-14  4:54 ` [PATCH 05/13] vfio/mdev: remove mdev_from_dev Christoph Hellwig
2022-06-15 20:06   ` Kirti Wankhede
2022-06-14  4:54 ` [PATCH 06/13] vfio/mdev: unexport mdev_bus_type Christoph Hellwig
2022-06-15 20:08   ` Kirti Wankhede
2022-06-14  4:54 ` [PATCH 07/13] vfio/mdev: remove mdev_parent_dev Christoph Hellwig
2022-06-15 20:11   ` Kirti Wankhede
2022-06-14  4:54 ` [PATCH 08/13] vfio/mdev: remove mtype_get_parent_dev Christoph Hellwig
2022-06-15 20:13   ` Kirti Wankhede
2022-06-14  4:54 ` [PATCH 09/13] vfio/mdev: consolidate all the device_api sysfs into the core code Christoph Hellwig
2022-06-14 10:10   ` Tian, Kevin
2022-06-15 20:24   ` Kirti Wankhede
2022-06-23 21:30   ` [PATCH 9/13] " Jason Gunthorpe
2022-06-14  4:54 ` [PATCH 10/13] vfio/mdev: consolidate all the name " Christoph Hellwig
2022-06-14 10:11   ` Tian, Kevin
2022-06-15 20:31   ` Kirti Wankhede [this message]
2022-06-23 21:32   ` Jason Gunthorpe
2022-06-14  4:54 ` [PATCH 11/13] vfio/mdev: consolidate all the available_instance " Christoph Hellwig
2022-06-14 10:14   ` Tian, Kevin
2022-06-14 10:29     ` Tian, Kevin
2022-06-15 20:37   ` Kirti Wankhede
2022-06-23 21:36   ` Jason Gunthorpe
2022-06-14  4:54 ` [PATCH 12/13] vfio/mdev: consolidate all the description " Christoph Hellwig
2022-06-15 20:52   ` Kirti Wankhede
2022-06-23 21:37   ` Jason Gunthorpe
2022-06-14  4:54 ` [PATCH 13/13] vfio/mdev: add mdev available instance checking to the core Christoph Hellwig
2022-06-14 10:32   ` Tian, Kevin
2022-06-15  6:29     ` Christoph Hellwig
2022-06-14  5:03 ` simplify the mdev interface v2 Yi Liu
2022-06-14  5:17   ` Christoph Hellwig
2022-06-14  5:30     ` Yi Liu
2022-06-14  5:44       ` Christoph Hellwig
2022-06-14  5:47         ` Yi Liu
2022-06-28  5:14 simplify the mdev interface v3 Christoph Hellwig
2022-06-28  5:14 ` [PATCH 10/13] vfio/mdev: consolidate all the name sysfs into the core code Christoph Hellwig

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=adab68ab-1f61-f975-8dee-f9f95012ecb5@nvidia.com \
    --to=kwankhede@nvidia.com \
    --cc=akrowiak@linux.ibm.com \
    --cc=alex.williamson@redhat.com \
    --cc=cjia@nvidia.com \
    --cc=dnigam@nvidia.com \
    --cc=farman@linux.ibm.com \
    --cc=hch@lst.de \
    --cc=intel-gvt-dev@lists.freedesktop.org \
    --cc=jjherne@linux.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mjrosato@linux.ibm.com \
    --cc=pasic@linux.ibm.com \
    --cc=targupta@nvidia.com \
    --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 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.