Re: [PATCH 2/3] driver core: Index class glue directories by parent kobject
From: Andy Shevchenko
Date: Fri Sep 11 2026 - 14:13:21 EST
On Fri, Sep 11, 2026 at 07:16:04PM +0200, Pavol Sakac wrote:
> get_device_parent() finds a parent's glue directory by walking the
> class's glue_dirs kset list under gdp_mutex, so one per parent, as
> vfio-dev needs per SR-IOV VF, is quadratic.
>
> Index them by parent kobject in an rbtree embedded in the class's
> subsys_private, which dies with the kset list it indexes, so no
> per-entry class check is needed: two classes below one parent are told
> apart by tree selection. The key is a kobject because a parentless
> class device hangs off the shared "virtual" kobject, referenced by the
> glue dir while indexed. The rb_node lives in struct class_dir, adding
> no allocation and no failure mode.
>
> gdp_mutex serializes the index, as it has glue dir lookup/create/remove
> since commit 77d3d7c1d561f
> ("driver-core: fix race condition in get_device_parent()") and
> commit e4a60d1390609
> ("sysfs: driver core: Fix glue dir race condition by gdp_mutex").
> A kernfs name lookup in the parent's directory needs no new state, but
> takes the kernfs root rwsem under gdp_mutex, behind the writes
> concurrent sysfs directory creation generates.
>
> A KUnit suite covers the index: reuse of one parent's glue directory,
> two classes below one parent, the parentless "virtual" cases, reap and
> recreate, name collision, many parents, device_move(), and class
> teardown.
...
> +++ b/drivers/base/test/.kunitconfig
> @@ -1,2 +1,3 @@
> CONFIG_KUNIT=y
> CONFIG_DM_KUNIT_TEST=y
> +CONFIG_GLUE_DIR_KUNIT_TEST=y
Is this test case is so important that it must *always* run?
--
With Best Regards,
Andy Shevchenko