History

drivercore: deferral race condition fix

When the kernel is built with CONFIG_PREEMPT it is possible to reach a state when all modules loaded but some driver still stuck in the deferred list and there is a need for external event to kick the deferred queue to probe these drivers. The issue has been observed on embedded systems with CONFIG_PREEMPT enabled, audio support built as modules and using nfsroot for root filesystem. The following log fragment shows such sequence when all audio modules were loaded but the sound card is not present since the machine driver has failed to probe due to missing dependency during it's probe. The board is am335x-evmsk (McASP<->tlv320aic3106 codec) with davinci-evm machine driver: ... [ 12.615118] davinci-mcasp 4803c000.mcasp: davinci_mcasp_probe: ENTER [ 12.719969] davinci_evm sound.3: davinci_evm_probe: ENTER [ 12.725753] davinci_evm sound.3: davinci_evm_probe: snd_soc_register_card [ 12.753846] davinci-mcasp 4803c000.mcasp: davinci_mcasp_probe: snd_soc_register_component [ 12.922051] davinci-mcasp 4803c000.mcasp: davinci_mcasp_probe: snd_soc_register_component DONE [ 12.950839] davinci_evm sound.3: ASoC: platform (null) not registered [ 12.957898] davinci_evm sound.3: davinci_evm_probe: snd_soc_register_card DONE (-517) [ 13.099026] davinci-mcasp 4803c000.mcasp: Kicking the deferred list [ 13.177838] davinci-mcasp 4803c000.mcasp: really_probe: probe_count = 2 [ 13.194130] davinci_evm sound.3: snd_soc_register_card failed (-517) [ 13.346755] davinci_mcasp_driver_init: LEAVE [ 13.377446] platform sound.3: Driver davinci_evm requests probe deferral [ 13.592527] platform sound.3: really_probe: probe_count = 0 In the log the machine driver enters it's probe at 12.719969 (this point it has been removed from the deferred lists). McASP driver already executing it's probing (since 12.615118). The machine driver tries to construct the sound card (12.950839) but did not found one of the components so it fails. After this McASP driver registers all the ASoC components (the machine driver still in it's probe function after it failed to construct the card) and the deferred work is prepared at 13.099026 (note that this time the machine driver is not in the lists so it is not going to be handled when the work is executing). Lastly the machine driver exit from it's probe and the core places it to the deferred list but there will be no other driver going to load and the deferred queue is not going to be kicked again - till we have external event like connecting USB stick, etc. The proposed solution is to try the deferred queue once more when the last driver is asking for deferring and we had drivers loaded while this last driver was probing. This way we can avoid drivers stuck in the deferred queue.

Grant Likely committed 12 years ago

Commit 58b116b1 parent 9ec36ca1 file · +17 −0Browse files

Unified · Split

drivers/base/dd.c+17−0
@@ -52,6 +52,7 @@ static DEFINE_MUTEX(deferred_probe_mutex); · 51 unmodified lines
5252 static LIST_HEAD(deferred_probe_pending_list);
5353 static LIST_HEAD(deferred_probe_active_list);
5454 static struct workqueue_struct *deferred_wq;
55+static atomic_t deferred_trigger_count = ATOMIC_INIT(0);
5556
5657 /**
5758 * deferred_probe_work_func() - Retry probing devices in the active list.
@@ -135,6 +136,17 @@ static bool driver_deferred_probe_enable = false; · 77 unmodified lines
135136 * This functions moves all devices from the pending list to the active
136137 * list and schedules the deferred probe workqueue to process them. It
137138 * should be called anytime a driver is successfully bound to a device.
139+ *
140+ * Note, there is a race condition in multi-threaded probe. In the case where
141+ * more than one device is probing at the same time, it is possible for one
142+ * probe to complete successfully while another is about to defer. If the second
143+ * depends on the first, then it will get put on the pending list after the
144+ * trigger event has already occured and will be stuck there.
145+ *
146+ * The atomic 'deferred_trigger_count' is used to determine if a successful
147+ * trigger has occurred in the midst of probing a driver. If the trigger count
148+ * changes in the midst of a probe, then deferred processing should be triggered
149+ * again.
138150 */
139151 static void driver_deferred_probe_trigger(void)
140152 {
@@ -147,6 +159,7 @@ static void driver_deferred_probe_trigger(void) · 6 unmodified lines
147159 * into the active list so they can be retried by the workqueue
148160 */
149161 mutex_lock(&deferred_probe_mutex);
162+ atomic_inc(&deferred_trigger_count);
150163 list_splice_tail_init(&deferred_probe_pending_list,
151164 &deferred_probe_active_list);
152165 mutex_unlock(&deferred_probe_mutex);
@@ -265,6 +278,7 @@ static DECLARE_WAIT_QUEUE_HEAD(probe_waitqueue); · 112 unmodified lines
265278 static int really_probe(struct device *dev, struct device_driver *drv)
266279 {
267280 int ret = 0;
281+ int local_trigger_count = atomic_read(&deferred_trigger_count);
268282
269283 atomic_inc(&probe_count);
270284 pr_debug("bus: '%s': %s: probing driver %s with device %s\n",
@@ -310,6 +324,9 @@ probe_failed: · 39 unmodified lines
310324 /* Driver requested deferred probing */
311325 dev_info(dev, "Driver %s requests probe deferral\n", drv->name);
312326 driver_deferred_probe_add(dev);
327+ /* Did a trigger occur while probing? Need to re-trigger if yes */
328+ if (local_trigger_count != atomic_read(&deferred_trigger_count))
329+ driver_deferred_probe_trigger();
313330 } else if (ret != -ENODEV && ret != -ENXIO) {
314331 /* driver matched but the probe failed */
315332 printk(KERN_WARNING

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t