Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Revert "driver core: enforce device_lock for driver_match_device()"

This reverts commit dc23806a7c47 ("driver core: enforce device_lock for
driver_match_device()") and commit 289b14592cef ("driver core: fix
inverted "locked" suffix of driver_match_device()").

While technically correct, there is a major downside to this approach:

When a device is already present in the system and a driver is
registered on the same bus, we iterate over all devices registered on
this bus to see if one of them matches. If we come across an already
bound one where the corresponding driver crashed while holding the
device lock (e.g. in probe()) we can't make any progress anymore.

However, drivers are typically the least tested code in the kernel and
hence it is a case that is likely to happen regularly. Besides hurting
developer ergonomics, it potentially decreases chances of shutting
things down cleanly and obtaining logs in production environments as
well [1].

This came up in the context of a firewire bug, which only in combination
with the reverted commit, caused the machine to hang [2]. Additionally,
it was observed in [3].

Thus, revert commit dc23806a7c47 ("driver core: enforce device_lock for
driver_match_device()") and add a brief note clarifying that an
implementer of struct bus_type must not expect match() to be called with
the device lock held.

Link: https://lore.kernel.org/driver-core/DGRGTIRHA62X.3RY09D9SOK77P@kernel.org/ [1]
Link: https://lore.kernel.org/all/67f655bb-4d81-4609-b008-68d200255dd2@davidgow.net/ [2]
Link: https://lore.kernel.org/lkml/CALbr=LZ4v7N=tO1vgOsyj9AS+XuNbn6kG-QcF+PacdMjSo0iyw@mail.gmail.com/ [3]
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Closes: https://lore.kernel.org/driver-core/CAHk-=wgJ_L1C=HjcYJotg_zrZEmiLFJaoic+PWthjuQrutrfJw@mail.gmail.com/
Reviewed-by: Gui-Dong Han <hanguidong02@gmail.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://patch.msgid.link/20260302002545.19389-1-dakr@kernel.org
[ Add additional Link: reference. - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

+4 -11
+1 -10
drivers/base/base.h
··· 179 179 void driver_detach(const struct device_driver *drv); 180 180 void driver_deferred_probe_del(struct device *dev); 181 181 void device_set_deferred_probe_reason(const struct device *dev, struct va_format *vaf); 182 - static inline int driver_match_device_locked(const struct device_driver *drv, 183 - struct device *dev) 184 - { 185 - device_lock_assert(dev); 186 - 187 - return drv->bus->match ? drv->bus->match(dev, drv) : 1; 188 - } 189 - 190 182 static inline int driver_match_device(const struct device_driver *drv, 191 183 struct device *dev) 192 184 { 193 - guard(device)(dev); 194 - return driver_match_device_locked(drv, dev); 185 + return drv->bus->match ? drv->bus->match(dev, drv) : 1; 195 186 } 196 187 197 188 static inline void dev_sync_state(struct device *dev)
+1 -1
drivers/base/dd.c
··· 928 928 bool async_allowed; 929 929 int ret; 930 930 931 - ret = driver_match_device_locked(drv, dev); 931 + ret = driver_match_device(drv, dev); 932 932 if (ret == 0) { 933 933 /* no match */ 934 934 return 0;
+2
include/linux/device/bus.h
··· 35 35 * otherwise. It may also return error code if determining that 36 36 * the driver supports the device is not possible. In case of 37 37 * -EPROBE_DEFER it will queue the device for deferred probing. 38 + * Note: This callback may be invoked with or without the device 39 + * lock held. 38 40 * @uevent: Called when a device is added, removed, or a few other things 39 41 * that generate uevents to add the environment variables. 40 42 * @probe: Called when a new device or driver add to this bus, and callback