Re: [PATCH 12/13] vfio/nvidia-vgpu: add the NVIDIA vGPU VFIO variant driver
From: Gary Guo
Date: Thu Sep 17 2026 - 03:07:21 EST
On Thu Sep 17, 2026 at 2:49 AM BST, Dave Airlie wrote:
> On Thu, 17 Sept 2026 at 02:28, Jason Gunthorpe <jgg@xxxxxxxxxx> wrote:
>>
>> Stated another way - the very point of vfio-pci is to remove
>> duplicated code from the drivers.
>>
>> So if we wanted to push hard on removing drvdata, and don't want to
>> touch the struct device I would probably say to #define up a way for
>> the driver to build its unique trampolines. It wastes a bunch of .text
>> but at least it doesn't duplicate code.
>
> +static pci_ers_result_t hisi_acc_vfio_pci_aer_err_detected(
> + struct pci_dev *pdev, pci_channel_state_t state)
> +{
> + struct hisi_acc_vf_core_device *hisi_acc_vdev = hisi_acc_drvdata(pdev);
> +
> + return vfio_pci_core_aer_err_detected(&hisi_acc_vdev->core_device,
> state);
> +}
> +
> +static int hisi_acc_vfio_pci_runtime_suspend(struct device *dev)
> +{
> + struct hisi_acc_vf_core_device *hisi_acc_vdev = dev_get_drvdata(dev);
> +
> + return vfio_pci_core_runtime_suspend(&hisi_acc_vdev->core_device);
> +}
> +
> +static int hisi_acc_vfio_pci_runtime_resume(struct device *dev)
> +{
> + struct hisi_acc_vf_core_device *hisi_acc_vdev = dev_get_drvdata(dev);
> +
> + return vfio_pci_core_runtime_resume(&hisi_acc_vdev->core_device);
> +}
> +
> +static const struct dev_pm_ops hisi_acc_vfio_pci_pm_ops = {
> + SET_RUNTIME_PM_OPS(hisi_acc_vfio_pci_runtime_suspend,
> + hisi_acc_vfio_pci_runtime_resume, NULL)
> +};
>
> is how much code it adds to current drivers, this doesn't seem
> excessive for 10 drivers,
> like you could obfuscate it a bit with some macros, but I really don't
> see a lot of value in hiding
> what is effectively just standard driver boilerplate.
If it's just these callbacks, you could even have vfio-pci directly proxying these
callbacks by having a `struct device` -> `struct vfio_pci_core_device` hashmap.
(Not that I'm saying it's a good idea).
Best,
Gary