[RFC PATCH 11/14] vfio: opt vfio-dev and VFIO group devices into sysfs_lazy
Pavol Sakac <[email protected]>
| Newsgroups | org.infradead.lists.kexec,dev.linux.lists.driver-core,org.kernel.vger.linux-kernel,org.kvack.linux-mm |
|---|---|
| Message-ID | <[email protected]> |
Call device_set_sysfs_lazy() on vfio_device->device (vfio-dev/) and on the VFIO group's struct device (vfio/<group>/) before device_add(). With opt-in, vfio-dev directories materialise their attribute_groups (vfio_dev_groups + drvdata->ops->dev_groups) on first access via the sysfs lookup path instead of eagerly at device_add(). The VFIO group device's flat attrs follow the same deferral. Removes the eager creation cost on platforms with thousands of VFs assigned to VFIO containers. No userspace ABI change. Cc: Alex Williamson <[email protected]> Cc: Jason Gunthorpe <[email protected]> Cc: [email protected] Cc: [email protected] Cc: Greg Kroah-Hartman <[email protected]> Cc: Danilo Krummrich <[email protected]> Cc: [email protected] Cc: [email protected] Assisted-by: Claude:claude-opus-4.7 Signed-off-by: Pavol Sakac <[email protected]> --- drivers/vfio/group.c | 5 +++++ drivers/vfio/vfio_main.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/drivers/vfio/group.c b/drivers/vfio/group.c index b2299e5bc6df3..aa7e0033b96e8 100644 --- a/drivers/vfio/group.c +++ b/drivers/vfio/group.c @@ -533,6 +533,11 @@ static struct vfio_group *vfio_group_alloc(struct iommu_group *iommu_group, group->dev.devt = MKDEV(MAJOR(vfio.group_devt), minor); group->dev.class = &vfio_class; group->dev.release = vfio_group_release; + /* Defer per-device attrs to first kernfs access; userspace reads via ioctl. */ + if (device_set_sysfs_lazy(&group->dev)) { + put_device(&group->dev); + return ERR_PTR(-ENOMEM); + } cdev_init(&group->cdev, &vfio_group_fops); group->cdev.owner = THIS_MODULE; diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c index 6222376ab6ab5..ab90279c44bd0 100644 --- a/drivers/vfio/vfio_main.c +++ b/drivers/vfio/vfio_main.c @@ -306,6 +306,11 @@ static int vfio_init_device(struct vfio_device *device, struct device *dev, goto out_uninit; } + /* Allocated before device_initialize() so out_uninit unwind frees it. */ + ret = device_set_sysfs_lazy(&device->device); + if (ret) + goto out_uninit; + device_initialize(&device->device); device->device.release = vfio_device_release; device->device.class = &vfio_device_class; -- 2.47.3 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christof Hellmis, Andreas Stieger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597