[RFC PATCH 8/8] vfio: Opt the group and vfio-dev class devices into staged sysfs

From: Pavol Sakac

Date: Fri Sep 11 2026 - 13:49:11 EST


The vfio group chardev and the vfio-dev class device are created once per
VF during a registration storm and satisfy the staged-sysfs opt-in
conditions trivially: class devices never match drivers, no
class_interface consumers exist for either class, and the KOBJ_ADD uevent
fires after publication, so no consumer can observe a partially built
directory. Without this, the concurrent registrations that creating the
group chardev outside vfio.group_lock unleashes convoy on the eager
kernfs_rwsem path instead.

Both devices live in class glue directories, which staged registration
covers.

Assisted-by: LLM
Signed-off-by: Pavol Sakac <sakacpav@xxxxxxxxx>
---
drivers/vfio/group.c | 7 +++++++
drivers/vfio/vfio_main.c | 3 +++
2 files changed, 10 insertions(+)

diff --git a/drivers/vfio/group.c b/drivers/vfio/group.c
index 692381151303..ee41e1253f3d 100644
--- a/drivers/vfio/group.c
+++ b/drivers/vfio/group.c
@@ -659,6 +659,13 @@ vfio_group_find_or_create(struct device *dev, struct iommu_group *iommu_group,
list_add(&new->vfio_next, &vfio.group_list);
mutex_unlock(&vfio.group_lock);

+ /*
+ * Class devices never match drivers and vfio has no class_interface
+ * consumers, so nothing can observe the group chardev's directory
+ * before device_add() publishes it in one step.
+ */
+ dev_set_sysfs_staged(&new->dev);
+
/*
* Hold back device_add()'s KOBJ_ADD until publication; on failure,
* suppression also keeps the device_add() unwind from emitting an
diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
index 423ead48aafe..7abdfbd54b9d 100644
--- a/drivers/vfio/vfio_main.c
+++ b/drivers/vfio/vfio_main.c
@@ -383,6 +383,9 @@ static int __vfio_register_dev(struct vfio_device *device,
goto err_out;
}

+ /* Staged opt-in: same conditions as vfio_group_find_or_create(). */
+ dev_set_sysfs_staged(&device->device);
+
ret = vfio_device_add(device);
if (ret)
goto err_out;
--
2.47.3