[PATCH RFC v2 07/15] vfio/nvgrace-egm: Register auxiliary driver ops

ankita@nvidia.com posted 15 patches 1 month, 1 week ago
[PATCH RFC v2 07/15] vfio/nvgrace-egm: Register auxiliary driver ops
Posted by ankita@nvidia.com 1 month, 1 week ago
From: Ankit Agrawal <ankita@nvidia.com>

Setup dummy auxiliary device ops to be able to get probed by
the nvgrace-egm auxiliary driver.

Both nvgrace-gpu and the out-of-tree nvidia-vgpu-vfio will make
use of the EGM for device assignment and the SRIOV vGPU virtualization
solutions respectively. Hence allow auxiliary device probing for both.

Signed-off-by: Ankit Agrawal <ankita@nvidia.com>
---
 drivers/vfio/pci/nvgrace-gpu/egm.c | 38 +++++++++++++++++++++++++++---
 1 file changed, 35 insertions(+), 3 deletions(-)

diff --git a/drivers/vfio/pci/nvgrace-gpu/egm.c b/drivers/vfio/pci/nvgrace-gpu/egm.c
index 6bab4d94cb99..6fd6302a004a 100644
--- a/drivers/vfio/pci/nvgrace-gpu/egm.c
+++ b/drivers/vfio/pci/nvgrace-gpu/egm.c
@@ -11,6 +11,29 @@
 static dev_t dev;
 static struct class *class;
 
+static int egm_driver_probe(struct auxiliary_device *aux_dev,
+			    const struct auxiliary_device_id *id)
+{
+	return 0;
+}
+
+static void egm_driver_remove(struct auxiliary_device *aux_dev)
+{
+}
+
+static const struct auxiliary_device_id egm_id_table[] = {
+	{ .name = "nvgrace_gpu_vfio_pci.egm" },
+	{ },
+};
+MODULE_DEVICE_TABLE(auxiliary, egm_id_table);
+
+static struct auxiliary_driver egm_driver = {
+	.name = KBUILD_MODNAME,
+	.id_table = egm_id_table,
+	.probe = egm_driver_probe,
+	.remove = egm_driver_remove,
+};
+
 static char *egm_devnode(const struct device *device, umode_t *mode)
 {
 	if (mode)
@@ -35,17 +58,26 @@ static int __init nvgrace_egm_init(void)
 
 	class = class_create(NVGRACE_EGM_DEV_NAME);
 	if (IS_ERR(class)) {
-		unregister_chrdev_region(dev, MAX_EGM_NODES);
-		return PTR_ERR(class);
+		ret = PTR_ERR(class);
+		goto unregister_chrdev;
 	}
 
 	class->devnode = egm_devnode;
 
-	return 0;
+	ret = auxiliary_driver_register(&egm_driver);
+	if (!ret)
+		goto fn_exit;
+
+	class_destroy(class);
+unregister_chrdev:
+	unregister_chrdev_region(dev, MAX_EGM_NODES);
+fn_exit:
+	return ret;
 }
 
 static void __exit nvgrace_egm_cleanup(void)
 {
+	auxiliary_driver_unregister(&egm_driver);
 	class_destroy(class);
 	unregister_chrdev_region(dev, MAX_EGM_NODES);
 }
-- 
2.34.1
Re: [PATCH RFC v2 07/15] vfio/nvgrace-egm: Register auxiliary driver ops
Posted by Alex Williamson 1 month ago
On Mon, 23 Feb 2026 15:55:06 +0000
<ankita@nvidia.com> wrote:

> From: Ankit Agrawal <ankita@nvidia.com>
> 
> Setup dummy auxiliary device ops to be able to get probed by
> the nvgrace-egm auxiliary driver.
> 
> Both nvgrace-gpu and the out-of-tree nvidia-vgpu-vfio will make
> use of the EGM for device assignment and the SRIOV vGPU virtualization
> solutions respectively. Hence allow auxiliary device probing for both.

But only one is added?

Can you point to any other in-tree drivers that include out-of-tree
device entries in their ID table?

Isn't this ID table what should make the module soft-dep unnecessary?

> 
> Signed-off-by: Ankit Agrawal <ankita@nvidia.com>
> ---
>  drivers/vfio/pci/nvgrace-gpu/egm.c | 38 +++++++++++++++++++++++++++---
>  1 file changed, 35 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/vfio/pci/nvgrace-gpu/egm.c b/drivers/vfio/pci/nvgrace-gpu/egm.c
> index 6bab4d94cb99..6fd6302a004a 100644
> --- a/drivers/vfio/pci/nvgrace-gpu/egm.c
> +++ b/drivers/vfio/pci/nvgrace-gpu/egm.c
> @@ -11,6 +11,29 @@
>  static dev_t dev;
>  static struct class *class;
>  
> +static int egm_driver_probe(struct auxiliary_device *aux_dev,
> +			    const struct auxiliary_device_id *id)
> +{
> +	return 0;
> +}
> +
> +static void egm_driver_remove(struct auxiliary_device *aux_dev)
> +{
> +}
> +
> +static const struct auxiliary_device_id egm_id_table[] = {
> +	{ .name = "nvgrace_gpu_vfio_pci.egm" },
> +	{ },
> +};
> +MODULE_DEVICE_TABLE(auxiliary, egm_id_table);
> +
> +static struct auxiliary_driver egm_driver = {
> +	.name = KBUILD_MODNAME,
> +	.id_table = egm_id_table,
> +	.probe = egm_driver_probe,
> +	.remove = egm_driver_remove,
> +};
> +
>  static char *egm_devnode(const struct device *device, umode_t *mode)
>  {
>  	if (mode)
> @@ -35,17 +58,26 @@ static int __init nvgrace_egm_init(void)
>  
>  	class = class_create(NVGRACE_EGM_DEV_NAME);
>  	if (IS_ERR(class)) {
> -		unregister_chrdev_region(dev, MAX_EGM_NODES);
> -		return PTR_ERR(class);
> +		ret = PTR_ERR(class);
> +		goto unregister_chrdev;
>  	}
>  
>  	class->devnode = egm_devnode;
>  
> -	return 0;
> +	ret = auxiliary_driver_register(&egm_driver);
> +	if (!ret)
> +		goto fn_exit;

This is not a good success oriented flow.  The error condition should
goto the unwind, the success condition can just fall through to return.
Thanks,

Alex

> +
> +	class_destroy(class);
> +unregister_chrdev:
> +	unregister_chrdev_region(dev, MAX_EGM_NODES);
> +fn_exit:
> +	return ret;
>  }
>  
>  static void __exit nvgrace_egm_cleanup(void)
>  {
> +	auxiliary_driver_unregister(&egm_driver);
>  	class_destroy(class);
>  	unregister_chrdev_region(dev, MAX_EGM_NODES);
>  }