All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] vdpa: regist vhost-vdpa dev class
@ 2021-12-23  7:31 ` Yi Wang
  0 siblings, 0 replies; 9+ messages in thread
From: Yi Wang @ 2021-12-23  7:31 UTC (permalink / raw)
  To: mst
  Cc: wang.yi59, Zhang Min, wang.liang82, kvm, netdev, linux-kernel,
	virtualization, xue.zhihong

From: Zhang Min <zhang.min9@zte.com.cn>

Some applications like kata-containers need to acquire MAJOR/MINOR/DEVNAME
for devInfo [1], so regist vhost-vdpa dev class to expose uevent.

1. https://github.com/kata-containers/kata-containers/blob/main/src/runtime/virtcontainers/device/config/config.go

Signed-off-by: Zhang Min <zhang.min9@zte.com.cn>
Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
---
 drivers/vhost/vdpa.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index fb41db3da611..90fbad93e7a2 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -1012,6 +1012,7 @@ static void vhost_vdpa_release_dev(struct device *device)
 	kfree(v);
 }
 
+static struct class *vhost_vdpa_class;
 static int vhost_vdpa_probe(struct vdpa_device *vdpa)
 {
 	const struct vdpa_config_ops *ops = vdpa->config;
@@ -1040,6 +1041,7 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa)
 	v->dev.release = vhost_vdpa_release_dev;
 	v->dev.parent = &vdpa->dev;
 	v->dev.devt = MKDEV(MAJOR(vhost_vdpa_major), minor);
+	v->dev.class = vhost_vdpa_class;
 	v->vqs = kmalloc_array(v->nvqs, sizeof(struct vhost_virtqueue),
 			       GFP_KERNEL);
 	if (!v->vqs) {
@@ -1097,6 +1099,14 @@ static int __init vhost_vdpa_init(void)
 {
 	int r;
 
+	vhost_vdpa_class = class_create(THIS_MODULE, "vhost-vdpa");
+	if (IS_ERR(vhost_vdpa_class)) {
+		r = PTR_ERR(vhost_vdpa_class);
+		pr_warn("vhost vdpa class create error %d,  maybe mod reinserted\n", r);
+		vhost_vdpa_class = NULL;
+		return r;
+	}
+
 	r = alloc_chrdev_region(&vhost_vdpa_major, 0, VHOST_VDPA_DEV_MAX,
 				"vhost-vdpa");
 	if (r)
@@ -1111,6 +1121,7 @@ static int __init vhost_vdpa_init(void)
 err_vdpa_register_driver:
 	unregister_chrdev_region(vhost_vdpa_major, VHOST_VDPA_DEV_MAX);
 err_alloc_chrdev:
+	class_destroy(vhost_vdpa_class);
 	return r;
 }
 module_init(vhost_vdpa_init);
@@ -1118,6 +1129,7 @@ module_init(vhost_vdpa_init);
 static void __exit vhost_vdpa_exit(void)
 {
 	vdpa_unregister_driver(&vhost_vdpa_driver);
+	class_destroy(vhost_vdpa_class);
 	unregister_chrdev_region(vhost_vdpa_major, VHOST_VDPA_DEV_MAX);
 }
 module_exit(vhost_vdpa_exit);
-- 
2.27.0
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH] vdpa: regist vhost-vdpa dev class
@ 2021-12-23  7:31 ` Yi Wang
  0 siblings, 0 replies; 9+ messages in thread
From: Yi Wang @ 2021-12-23  7:31 UTC (permalink / raw)
  To: mst
  Cc: jasowang, kvm, virtualization, netdev, linux-kernel, xue.zhihong,
	wang.yi59, wang.liang82, Zhang Min

From: Zhang Min <zhang.min9@zte.com.cn>

Some applications like kata-containers need to acquire MAJOR/MINOR/DEVNAME
for devInfo [1], so regist vhost-vdpa dev class to expose uevent.

1. https://github.com/kata-containers/kata-containers/blob/main/src/runtime/virtcontainers/device/config/config.go

Signed-off-by: Zhang Min <zhang.min9@zte.com.cn>
Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
---
 drivers/vhost/vdpa.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index fb41db3da611..90fbad93e7a2 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -1012,6 +1012,7 @@ static void vhost_vdpa_release_dev(struct device *device)
 	kfree(v);
 }
 
+static struct class *vhost_vdpa_class;
 static int vhost_vdpa_probe(struct vdpa_device *vdpa)
 {
 	const struct vdpa_config_ops *ops = vdpa->config;
@@ -1040,6 +1041,7 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa)
 	v->dev.release = vhost_vdpa_release_dev;
 	v->dev.parent = &vdpa->dev;
 	v->dev.devt = MKDEV(MAJOR(vhost_vdpa_major), minor);
+	v->dev.class = vhost_vdpa_class;
 	v->vqs = kmalloc_array(v->nvqs, sizeof(struct vhost_virtqueue),
 			       GFP_KERNEL);
 	if (!v->vqs) {
@@ -1097,6 +1099,14 @@ static int __init vhost_vdpa_init(void)
 {
 	int r;
 
+	vhost_vdpa_class = class_create(THIS_MODULE, "vhost-vdpa");
+	if (IS_ERR(vhost_vdpa_class)) {
+		r = PTR_ERR(vhost_vdpa_class);
+		pr_warn("vhost vdpa class create error %d,  maybe mod reinserted\n", r);
+		vhost_vdpa_class = NULL;
+		return r;
+	}
+
 	r = alloc_chrdev_region(&vhost_vdpa_major, 0, VHOST_VDPA_DEV_MAX,
 				"vhost-vdpa");
 	if (r)
@@ -1111,6 +1121,7 @@ static int __init vhost_vdpa_init(void)
 err_vdpa_register_driver:
 	unregister_chrdev_region(vhost_vdpa_major, VHOST_VDPA_DEV_MAX);
 err_alloc_chrdev:
+	class_destroy(vhost_vdpa_class);
 	return r;
 }
 module_init(vhost_vdpa_init);
@@ -1118,6 +1129,7 @@ module_init(vhost_vdpa_init);
 static void __exit vhost_vdpa_exit(void)
 {
 	vdpa_unregister_driver(&vhost_vdpa_driver);
+	class_destroy(vhost_vdpa_class);
 	unregister_chrdev_region(vhost_vdpa_major, VHOST_VDPA_DEV_MAX);
 }
 module_exit(vhost_vdpa_exit);
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] vdpa: regist vhost-vdpa dev class
  2021-12-23  7:31 ` Yi Wang
@ 2021-12-23 10:59   ` Stefano Garzarella
  -1 siblings, 0 replies; 9+ messages in thread
From: Stefano Garzarella @ 2021-12-23 10:59 UTC (permalink / raw)
  To: Yi Wang
  Cc: mst, Zhang Min, wang.liang82, kvm, netdev, linux-kernel,
	virtualization, xue.zhihong

On Thu, Dec 23, 2021 at 03:31:45PM +0800, Yi Wang wrote:
>From: Zhang Min <zhang.min9@zte.com.cn>
>
>Some applications like kata-containers need to acquire MAJOR/MINOR/DEVNAME
>for devInfo [1], so regist vhost-vdpa dev class to expose uevent.
>
>1. https://github.com/kata-containers/kata-containers/blob/main/src/runtime/virtcontainers/device/config/config.go
>
>Signed-off-by: Zhang Min <zhang.min9@zte.com.cn>
>Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
>---
> drivers/vhost/vdpa.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
>diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
>index fb41db3da611..90fbad93e7a2 100644
>--- a/drivers/vhost/vdpa.c
>+++ b/drivers/vhost/vdpa.c
>@@ -1012,6 +1012,7 @@ static void vhost_vdpa_release_dev(struct device *device)
> 	kfree(v);
> }
>
>+static struct class *vhost_vdpa_class;
   ^
Maybe is better to move this declaration on top, near `static dev_t 
vhost_vdpa_major;`

> static int vhost_vdpa_probe(struct vdpa_device *vdpa)
> {
> 	const struct vdpa_config_ops *ops = vdpa->config;
>@@ -1040,6 +1041,7 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa)
> 	v->dev.release = vhost_vdpa_release_dev;
> 	v->dev.parent = &vdpa->dev;
> 	v->dev.devt = MKDEV(MAJOR(vhost_vdpa_major), minor);
>+	v->dev.class = vhost_vdpa_class;
> 	v->vqs = kmalloc_array(v->nvqs, sizeof(struct vhost_virtqueue),
> 			       GFP_KERNEL);
> 	if (!v->vqs) {
>@@ -1097,6 +1099,14 @@ static int __init vhost_vdpa_init(void)
> {
> 	int r;
>
>+	vhost_vdpa_class = class_create(THIS_MODULE, "vhost-vdpa");
>+	if (IS_ERR(vhost_vdpa_class)) {
>+		r = PTR_ERR(vhost_vdpa_class);
>+		pr_warn("vhost vdpa class create error %d,  maybe mod reinserted\n", r);
                                                           ^
double space.

I'm not a native speaker, but I would rephrase the second part to "maybe 
the module is already loaded"

>+		vhost_vdpa_class = NULL;
>+		return r;
>+	}
>+
> 	r = alloc_chrdev_region(&vhost_vdpa_major, 0, VHOST_VDPA_DEV_MAX,
> 				"vhost-vdpa");
> 	if (r)
>@@ -1111,6 +1121,7 @@ static int __init vhost_vdpa_init(void)
> err_vdpa_register_driver:
> 	unregister_chrdev_region(vhost_vdpa_major, VHOST_VDPA_DEV_MAX);
> err_alloc_chrdev:
>+	class_destroy(vhost_vdpa_class);

Should we set `vhost_vdpa_class` to NULL here?

If yes, maybe better to add a new label, and a goto in the 
`class_create` error handling.

> 	return r;
> }
> module_init(vhost_vdpa_init);
>@@ -1118,6 +1129,7 @@ module_init(vhost_vdpa_init);
> static void __exit vhost_vdpa_exit(void)
> {
> 	vdpa_unregister_driver(&vhost_vdpa_driver);
>+	class_destroy(vhost_vdpa_class);

I would move it after unregister_chrdev_region() to have the reverse 
order of initialization (as we already rightly do in the error path of 
vhost_vdpa_init()).

Thanks,
Stefano

> 	unregister_chrdev_region(vhost_vdpa_major, VHOST_VDPA_DEV_MAX);
> }
> module_exit(vhost_vdpa_exit);
>-- 
>2.27.0
>_______________________________________________
>Virtualization mailing list
>Virtualization@lists.linux-foundation.org
>https://lists.linuxfoundation.org/mailman/listinfo/virtualization
>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] vdpa: regist vhost-vdpa dev class
@ 2021-12-23 10:59   ` Stefano Garzarella
  0 siblings, 0 replies; 9+ messages in thread
From: Stefano Garzarella @ 2021-12-23 10:59 UTC (permalink / raw)
  To: Yi Wang
  Cc: Zhang Min, wang.liang82, kvm, mst, netdev, linux-kernel,
	virtualization, xue.zhihong

On Thu, Dec 23, 2021 at 03:31:45PM +0800, Yi Wang wrote:
>From: Zhang Min <zhang.min9@zte.com.cn>
>
>Some applications like kata-containers need to acquire MAJOR/MINOR/DEVNAME
>for devInfo [1], so regist vhost-vdpa dev class to expose uevent.
>
>1. https://github.com/kata-containers/kata-containers/blob/main/src/runtime/virtcontainers/device/config/config.go
>
>Signed-off-by: Zhang Min <zhang.min9@zte.com.cn>
>Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
>---
> drivers/vhost/vdpa.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
>diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
>index fb41db3da611..90fbad93e7a2 100644
>--- a/drivers/vhost/vdpa.c
>+++ b/drivers/vhost/vdpa.c
>@@ -1012,6 +1012,7 @@ static void vhost_vdpa_release_dev(struct device *device)
> 	kfree(v);
> }
>
>+static struct class *vhost_vdpa_class;
   ^
Maybe is better to move this declaration on top, near `static dev_t 
vhost_vdpa_major;`

> static int vhost_vdpa_probe(struct vdpa_device *vdpa)
> {
> 	const struct vdpa_config_ops *ops = vdpa->config;
>@@ -1040,6 +1041,7 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa)
> 	v->dev.release = vhost_vdpa_release_dev;
> 	v->dev.parent = &vdpa->dev;
> 	v->dev.devt = MKDEV(MAJOR(vhost_vdpa_major), minor);
>+	v->dev.class = vhost_vdpa_class;
> 	v->vqs = kmalloc_array(v->nvqs, sizeof(struct vhost_virtqueue),
> 			       GFP_KERNEL);
> 	if (!v->vqs) {
>@@ -1097,6 +1099,14 @@ static int __init vhost_vdpa_init(void)
> {
> 	int r;
>
>+	vhost_vdpa_class = class_create(THIS_MODULE, "vhost-vdpa");
>+	if (IS_ERR(vhost_vdpa_class)) {
>+		r = PTR_ERR(vhost_vdpa_class);
>+		pr_warn("vhost vdpa class create error %d,  maybe mod reinserted\n", r);
                                                           ^
double space.

I'm not a native speaker, but I would rephrase the second part to "maybe 
the module is already loaded"

>+		vhost_vdpa_class = NULL;
>+		return r;
>+	}
>+
> 	r = alloc_chrdev_region(&vhost_vdpa_major, 0, VHOST_VDPA_DEV_MAX,
> 				"vhost-vdpa");
> 	if (r)
>@@ -1111,6 +1121,7 @@ static int __init vhost_vdpa_init(void)
> err_vdpa_register_driver:
> 	unregister_chrdev_region(vhost_vdpa_major, VHOST_VDPA_DEV_MAX);
> err_alloc_chrdev:
>+	class_destroy(vhost_vdpa_class);

Should we set `vhost_vdpa_class` to NULL here?

If yes, maybe better to add a new label, and a goto in the 
`class_create` error handling.

> 	return r;
> }
> module_init(vhost_vdpa_init);
>@@ -1118,6 +1129,7 @@ module_init(vhost_vdpa_init);
> static void __exit vhost_vdpa_exit(void)
> {
> 	vdpa_unregister_driver(&vhost_vdpa_driver);
>+	class_destroy(vhost_vdpa_class);

I would move it after unregister_chrdev_region() to have the reverse 
order of initialization (as we already rightly do in the error path of 
vhost_vdpa_init()).

Thanks,
Stefano

> 	unregister_chrdev_region(vhost_vdpa_major, VHOST_VDPA_DEV_MAX);
> }
> module_exit(vhost_vdpa_exit);
>-- 
>2.27.0
>_______________________________________________
>Virtualization mailing list
>Virtualization@lists.linux-foundation.org
>https://lists.linuxfoundation.org/mailman/listinfo/virtualization
>

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] vdpa: regist vhost-vdpa dev class
  2021-12-23  7:31 ` Yi Wang
@ 2021-12-23 13:58   ` Michael S. Tsirkin
  -1 siblings, 0 replies; 9+ messages in thread
From: Michael S. Tsirkin @ 2021-12-23 13:58 UTC (permalink / raw)
  To: Yi Wang
  Cc: jasowang, kvm, virtualization, netdev, linux-kernel, xue.zhihong,
	wang.liang82, Zhang Min

typo in subject

On Thu, Dec 23, 2021 at 03:31:45PM +0800, Yi Wang wrote:
> From: Zhang Min <zhang.min9@zte.com.cn>
> 
> Some applications like kata-containers need to acquire MAJOR/MINOR/DEVNAME
> for devInfo [1], so regist vhost-vdpa dev class to expose uevent.
> 
> 1. https://github.com/kata-containers/kata-containers/blob/main/src/runtime/virtcontainers/device/config/config.go
> 
> Signed-off-by: Zhang Min <zhang.min9@zte.com.cn>
> Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
> ---
>  drivers/vhost/vdpa.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> index fb41db3da611..90fbad93e7a2 100644
> --- a/drivers/vhost/vdpa.c
> +++ b/drivers/vhost/vdpa.c
> @@ -1012,6 +1012,7 @@ static void vhost_vdpa_release_dev(struct device *device)
>  	kfree(v);
>  }
>  
> +static struct class *vhost_vdpa_class;
>  static int vhost_vdpa_probe(struct vdpa_device *vdpa)
>  {
>  	const struct vdpa_config_ops *ops = vdpa->config;
> @@ -1040,6 +1041,7 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa)
>  	v->dev.release = vhost_vdpa_release_dev;
>  	v->dev.parent = &vdpa->dev;
>  	v->dev.devt = MKDEV(MAJOR(vhost_vdpa_major), minor);
> +	v->dev.class = vhost_vdpa_class;
>  	v->vqs = kmalloc_array(v->nvqs, sizeof(struct vhost_virtqueue),
>  			       GFP_KERNEL);
>  	if (!v->vqs) {
> @@ -1097,6 +1099,14 @@ static int __init vhost_vdpa_init(void)
>  {
>  	int r;
>  
> +	vhost_vdpa_class = class_create(THIS_MODULE, "vhost-vdpa");
> +	if (IS_ERR(vhost_vdpa_class)) {
> +		r = PTR_ERR(vhost_vdpa_class);
> +		pr_warn("vhost vdpa class create error %d,  maybe mod reinserted\n", r);

what's mod reinserted? why warn not error?

> +		vhost_vdpa_class = NULL;
> +		return r;
> +	}
> +
>  	r = alloc_chrdev_region(&vhost_vdpa_major, 0, VHOST_VDPA_DEV_MAX,
>  				"vhost-vdpa");
>  	if (r)
> @@ -1111,6 +1121,7 @@ static int __init vhost_vdpa_init(void)
>  err_vdpa_register_driver:
>  	unregister_chrdev_region(vhost_vdpa_major, VHOST_VDPA_DEV_MAX);
>  err_alloc_chrdev:
> +	class_destroy(vhost_vdpa_class);
>  	return r;
>  }
>  module_init(vhost_vdpa_init);
> @@ -1118,6 +1129,7 @@ module_init(vhost_vdpa_init);
>  static void __exit vhost_vdpa_exit(void)
>  {
>  	vdpa_unregister_driver(&vhost_vdpa_driver);
> +	class_destroy(vhost_vdpa_class);
>  	unregister_chrdev_region(vhost_vdpa_major, VHOST_VDPA_DEV_MAX);
>  }
>  module_exit(vhost_vdpa_exit);
> -- 
> 2.27.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] vdpa: regist vhost-vdpa dev class
@ 2021-12-23 13:58   ` Michael S. Tsirkin
  0 siblings, 0 replies; 9+ messages in thread
From: Michael S. Tsirkin @ 2021-12-23 13:58 UTC (permalink / raw)
  To: Yi Wang
  Cc: Zhang Min, wang.liang82, kvm, netdev, linux-kernel,
	virtualization, xue.zhihong

typo in subject

On Thu, Dec 23, 2021 at 03:31:45PM +0800, Yi Wang wrote:
> From: Zhang Min <zhang.min9@zte.com.cn>
> 
> Some applications like kata-containers need to acquire MAJOR/MINOR/DEVNAME
> for devInfo [1], so regist vhost-vdpa dev class to expose uevent.
> 
> 1. https://github.com/kata-containers/kata-containers/blob/main/src/runtime/virtcontainers/device/config/config.go
> 
> Signed-off-by: Zhang Min <zhang.min9@zte.com.cn>
> Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
> ---
>  drivers/vhost/vdpa.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> index fb41db3da611..90fbad93e7a2 100644
> --- a/drivers/vhost/vdpa.c
> +++ b/drivers/vhost/vdpa.c
> @@ -1012,6 +1012,7 @@ static void vhost_vdpa_release_dev(struct device *device)
>  	kfree(v);
>  }
>  
> +static struct class *vhost_vdpa_class;
>  static int vhost_vdpa_probe(struct vdpa_device *vdpa)
>  {
>  	const struct vdpa_config_ops *ops = vdpa->config;
> @@ -1040,6 +1041,7 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa)
>  	v->dev.release = vhost_vdpa_release_dev;
>  	v->dev.parent = &vdpa->dev;
>  	v->dev.devt = MKDEV(MAJOR(vhost_vdpa_major), minor);
> +	v->dev.class = vhost_vdpa_class;
>  	v->vqs = kmalloc_array(v->nvqs, sizeof(struct vhost_virtqueue),
>  			       GFP_KERNEL);
>  	if (!v->vqs) {
> @@ -1097,6 +1099,14 @@ static int __init vhost_vdpa_init(void)
>  {
>  	int r;
>  
> +	vhost_vdpa_class = class_create(THIS_MODULE, "vhost-vdpa");
> +	if (IS_ERR(vhost_vdpa_class)) {
> +		r = PTR_ERR(vhost_vdpa_class);
> +		pr_warn("vhost vdpa class create error %d,  maybe mod reinserted\n", r);

what's mod reinserted? why warn not error?

> +		vhost_vdpa_class = NULL;
> +		return r;
> +	}
> +
>  	r = alloc_chrdev_region(&vhost_vdpa_major, 0, VHOST_VDPA_DEV_MAX,
>  				"vhost-vdpa");
>  	if (r)
> @@ -1111,6 +1121,7 @@ static int __init vhost_vdpa_init(void)
>  err_vdpa_register_driver:
>  	unregister_chrdev_region(vhost_vdpa_major, VHOST_VDPA_DEV_MAX);
>  err_alloc_chrdev:
> +	class_destroy(vhost_vdpa_class);
>  	return r;
>  }
>  module_init(vhost_vdpa_init);
> @@ -1118,6 +1129,7 @@ module_init(vhost_vdpa_init);
>  static void __exit vhost_vdpa_exit(void)
>  {
>  	vdpa_unregister_driver(&vhost_vdpa_driver);
> +	class_destroy(vhost_vdpa_class);
>  	unregister_chrdev_region(vhost_vdpa_major, VHOST_VDPA_DEV_MAX);
>  }
>  module_exit(vhost_vdpa_exit);
> -- 
> 2.27.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [PATCH] vdpa: regist vhost-vdpa dev class
  2021-12-23  7:31 ` Yi Wang
                   ` (2 preceding siblings ...)
  (?)
@ 2021-12-23 15:53 ` Longpeng (Mike, Cloud Infrastructure Service Product Dept.)
  -1 siblings, 0 replies; 9+ messages in thread
From: Longpeng (Mike, Cloud Infrastructure Service Product Dept.) @ 2021-12-23 15:53 UTC (permalink / raw)
  To: Yi Wang
  Cc: jasowang, kvm, virtualization, netdev, linux-kernel, xue.zhihong,
	wang.liang82, Zhang Min, mst



> -----Original Message-----
> From: Yi Wang [mailto:wang.yi59@zte.com.cn]
> Sent: Thursday, December 23, 2021 3:32 PM
> To: mst@redhat.com
> Cc: jasowang@redhat.com; kvm@vger.kernel.org;
> virtualization@lists.linux-foundation.org; netdev@vger.kernel.org;
> linux-kernel@vger.kernel.org; xue.zhihong@zte.com.cn; wang.yi59@zte.com.cn;
> wang.liang82@zte.com.cn; Zhang Min <zhang.min9@zte.com.cn>
> Subject: [PATCH] vdpa: regist vhost-vdpa dev class
> 
> From: Zhang Min <zhang.min9@zte.com.cn>
> 
> Some applications like kata-containers need to acquire MAJOR/MINOR/DEVNAME
> for devInfo [1], so regist vhost-vdpa dev class to expose uevent.
> 
> 1.
> https://github.com/kata-containers/kata-containers/blob/main/src/runtime/vi
> rtcontainers/device/config/config.go
> 
> Signed-off-by: Zhang Min <zhang.min9@zte.com.cn>
> Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
> ---
>  drivers/vhost/vdpa.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> index fb41db3da611..90fbad93e7a2 100644
> --- a/drivers/vhost/vdpa.c
> +++ b/drivers/vhost/vdpa.c
> @@ -1012,6 +1012,7 @@ static void vhost_vdpa_release_dev(struct device *device)
>  	kfree(v);
>  }
> 
> +static struct class *vhost_vdpa_class;
>  static int vhost_vdpa_probe(struct vdpa_device *vdpa)
>  {
>  	const struct vdpa_config_ops *ops = vdpa->config;
> @@ -1040,6 +1041,7 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa)
>  	v->dev.release = vhost_vdpa_release_dev;
>  	v->dev.parent = &vdpa->dev;
>  	v->dev.devt = MKDEV(MAJOR(vhost_vdpa_major), minor);
> +	v->dev.class = vhost_vdpa_class;
>  	v->vqs = kmalloc_array(v->nvqs, sizeof(struct vhost_virtqueue),
>  			       GFP_KERNEL);
>  	if (!v->vqs) {
> @@ -1097,6 +1099,14 @@ static int __init vhost_vdpa_init(void)
>  {
>  	int r;
> 
> +	vhost_vdpa_class = class_create(THIS_MODULE, "vhost-vdpa");
> +	if (IS_ERR(vhost_vdpa_class)) {
> +		r = PTR_ERR(vhost_vdpa_class);
> +		pr_warn("vhost vdpa class create error %d,  maybe mod reinserted\n", r);
> +		vhost_vdpa_class = NULL;

Unnecessary to reset?

> +		return r;
> +	}
> +
>  	r = alloc_chrdev_region(&vhost_vdpa_major, 0, VHOST_VDPA_DEV_MAX,
>  				"vhost-vdpa");
>  	if (r)
> @@ -1111,6 +1121,7 @@ static int __init vhost_vdpa_init(void)
>  err_vdpa_register_driver:
>  	unregister_chrdev_region(vhost_vdpa_major, VHOST_VDPA_DEV_MAX);
>  err_alloc_chrdev:
> +	class_destroy(vhost_vdpa_class);
>  	return r;
>  }
>  module_init(vhost_vdpa_init);
> @@ -1118,6 +1129,7 @@ module_init(vhost_vdpa_init);
>  static void __exit vhost_vdpa_exit(void)
>  {
>  	vdpa_unregister_driver(&vhost_vdpa_driver);
> +	class_destroy(vhost_vdpa_class);
>  	unregister_chrdev_region(vhost_vdpa_major, VHOST_VDPA_DEV_MAX);
>  }
>  module_exit(vhost_vdpa_exit);
> --
> 2.27.0

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re:[PATCH] vdpa: regist vhost-vdpa dev class
  2021-12-23 10:59   ` Stefano Garzarella
@ 2021-12-24  7:02     ` wang.yi59
  -1 siblings, 0 replies; 9+ messages in thread
From: wang.yi59 @ 2021-12-24  7:02 UTC (permalink / raw)
  To: sgarzare
  Cc: mst, zhang.min9, wang.liang82, kvm, netdev, linux-kernel,
	virtualization, xue.zhihong

Hi Stefano,

Thanks for your quick reply and review, :)

> On Thu, Dec 23, 2021 at 03:31:45PM +0800, Yi Wang wrote:
> >From: Zhang Min <zhang.min9@zte.com.cn>
> >
> >Some applications like kata-containers need to acquire MAJOR/MINOR/DEVNAME
> >for devInfo [1], so regist vhost-vdpa dev class to expose uevent.
> >
> >1. https://github.com/kata-containers/kata-containers/blob/main/src/runtime/virtcontainers/device/config/config.go
> >
> >Signed-off-by: Zhang Min <zhang.min9@zte.com.cn>
> >Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
> >---
> > drivers/vhost/vdpa.c | 12 ++++++++++++
> > 1 file changed, 12 insertions(+)
> >
> >diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> >index fb41db3da611..90fbad93e7a2 100644
> >--- a/drivers/vhost/vdpa.c
> >+++ b/drivers/vhost/vdpa.c

..

> >+    vhost_vdpa_class = class_create(THIS_MODULE, "vhost-vdpa");
> >+    if (IS_ERR(vhost_vdpa_class)) {
> >+        r = PTR_ERR(vhost_vdpa_class);
> >+        pr_warn("vhost vdpa class create error %d,  maybe mod reinserted\n", r);
>                                                            ^
> double space.
> 
> I'm not a native speaker, but I would rephrase the second part to "maybe 
> the module is already loaded"
> 
> >+        vhost_vdpa_class = NULL;
> >+        return r;
> >+    }
> >+
> >     r = alloc_chrdev_region(&vhost_vdpa_major, 0, VHOST_VDPA_DEV_MAX,
> >                 "vhost-vdpa");
> >     if (r)
> >@@ -1111,6 +1121,7 @@ static int __init vhost_vdpa_init(void)
> > err_vdpa_register_driver:
> >     unregister_chrdev_region(vhost_vdpa_major, VHOST_VDPA_DEV_MAX);
> > err_alloc_chrdev:
> >+    class_destroy(vhost_vdpa_class);
> 
> Should we set `vhost_vdpa_class` to NULL here?
> 
> If yes, maybe better to add a new label, and a goto in the 
> `class_create` error handling.

Yes, reset to NULL is unnecessary, and pr_warn will not be reached when module
is already loaded, so it's no need too.
There will be a v2 patch which simply return PTR_ERR(vhost_vdpa_class);
Other suggestions are also accepted. 

> >     return r;
> > }

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re:[PATCH] vdpa: regist vhost-vdpa dev class
@ 2021-12-24  7:02     ` wang.yi59
  0 siblings, 0 replies; 9+ messages in thread
From: wang.yi59 @ 2021-12-24  7:02 UTC (permalink / raw)
  To: sgarzare
  Cc: zhang.min9, wang.liang82, kvm, mst, netdev, linux-kernel,
	virtualization, xue.zhihong

Hi Stefano,

Thanks for your quick reply and review, :)

> On Thu, Dec 23, 2021 at 03:31:45PM +0800, Yi Wang wrote:
> >From: Zhang Min <zhang.min9@zte.com.cn>
> >
> >Some applications like kata-containers need to acquire MAJOR/MINOR/DEVNAME
> >for devInfo [1], so regist vhost-vdpa dev class to expose uevent.
> >
> >1. https://github.com/kata-containers/kata-containers/blob/main/src/runtime/virtcontainers/device/config/config.go
> >
> >Signed-off-by: Zhang Min <zhang.min9@zte.com.cn>
> >Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
> >---
> > drivers/vhost/vdpa.c | 12 ++++++++++++
> > 1 file changed, 12 insertions(+)
> >
> >diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
> >index fb41db3da611..90fbad93e7a2 100644
> >--- a/drivers/vhost/vdpa.c
> >+++ b/drivers/vhost/vdpa.c

..

> >+    vhost_vdpa_class = class_create(THIS_MODULE, "vhost-vdpa");
> >+    if (IS_ERR(vhost_vdpa_class)) {
> >+        r = PTR_ERR(vhost_vdpa_class);
> >+        pr_warn("vhost vdpa class create error %d,  maybe mod reinserted\n", r);
>                                                            ^
> double space.
> 
> I'm not a native speaker, but I would rephrase the second part to "maybe 
> the module is already loaded"
> 
> >+        vhost_vdpa_class = NULL;
> >+        return r;
> >+    }
> >+
> >     r = alloc_chrdev_region(&vhost_vdpa_major, 0, VHOST_VDPA_DEV_MAX,
> >                 "vhost-vdpa");
> >     if (r)
> >@@ -1111,6 +1121,7 @@ static int __init vhost_vdpa_init(void)
> > err_vdpa_register_driver:
> >     unregister_chrdev_region(vhost_vdpa_major, VHOST_VDPA_DEV_MAX);
> > err_alloc_chrdev:
> >+    class_destroy(vhost_vdpa_class);
> 
> Should we set `vhost_vdpa_class` to NULL here?
> 
> If yes, maybe better to add a new label, and a goto in the 
> `class_create` error handling.

Yes, reset to NULL is unnecessary, and pr_warn will not be reached when module
is already loaded, so it's no need too.
There will be a v2 patch which simply return PTR_ERR(vhost_vdpa_class);
Other suggestions are also accepted. 

> >     return r;
> > }
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-12-24  7:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-23  7:31 [PATCH] vdpa: regist vhost-vdpa dev class Yi Wang
2021-12-23  7:31 ` Yi Wang
2021-12-23 10:59 ` Stefano Garzarella
2021-12-23 10:59   ` Stefano Garzarella
2021-12-24  7:02   ` wang.yi59
2021-12-24  7:02     ` wang.yi59
2021-12-23 13:58 ` [PATCH] " Michael S. Tsirkin
2021-12-23 13:58   ` Michael S. Tsirkin
2021-12-23 15:53 ` Longpeng (Mike, Cloud Infrastructure Service Product Dept.)

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.