Before commit 9499d3bc41a2 ("drm: Send per-connector hotplug events"),
output_poll_execute() used to always send connector hotplug events when
mode_config.delayed_event == true (which was good), without taking
mode_config.mutex (which was bad).
Since that commit, it always takes mode_config.mutex before checking
mode_config.delayed_event (which is good, because delayed event needs to be
read-and-updated) but at the cost of having to reschedule when the lock
cannot be taken.
So now a delayed event could be missed for up to DRM_OUTPUT_POLL_PERIOD,
i.e. 10 seconds. This happens frequently (10~20% of the cases in my tests)
when writing the 'status' sysfs attribute, as in:
echo on >/sys/class/drm/card*/status
#or
echo off >/sys/class/drm/card*/status
This is because:
CPU0 CPU1
status_store() in drm_sysfs.c:
* takes mode_config.mutex
* calls connector->funcs->fill_modes()
. -> drm_helper_probe_single_connector_modes()
. -> dev->mode_config.delayed_event = true
. -> mod_delayed_work() // with zero delay
. `-> wakes -----> output_poll_execute()
. -> tries taking mode_config.mutex
* releases mode_config.mutex
The CPU1 code sometimes runs before mode_config.mutex is released, and in
that case output_poll_execute() reschedules 10 seconds later. When this
happens, a display or panel will react exactly 10 seconds later.
Avoid the 10 seconds delay by rescheduling almost immediately when a
delayed event is known to be present, so it will be picked up very soon.
Fixes: 9499d3bc41a2 ("drm: Send per-connector hotplug events")
Signed-off-by: Luca Ceresoli <[email protected]>
---
drivers/gpu/drm/drm_probe_helper.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/drm_probe_helper.c
b/drivers/gpu/drm/drm_probe_helper.c
index 856b40fdaac4..fb93ae6f70e9 100644
--- a/drivers/gpu/drm/drm_probe_helper.c
+++ b/drivers/gpu/drm/drm_probe_helper.c
@@ -797,7 +797,13 @@ static void output_poll_execute(struct work_struct *work)
}
if (!mutex_trylock(&dev->mode_config.mutex)) {
- schedule_delayed_work(delayed_work, DRM_OUTPUT_POLL_PERIOD);
+ /*
+ * Cannot get the lock: reschedule after the default
+ * interval, or "very soon" if a delayed event is pending
+ */
+ schedule_delayed_work(delayed_work,
+ dev->mode_config.delayed_event ?
+ msecs_to_jiffies(10) :
DRM_OUTPUT_POLL_PERIOD);
return;
}
---
base-commit: ae720e1e682846a3c23ba572d96a38f46709bef0
change-id: 20261204-drm-output-poll-10s-fix-e480efb33307
Best regards,
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com