https://bugs.kde.org/show_bug.cgi?id=528571

            Bug ID: 528571
           Summary: PowerDevil DDC/CI watcher blocks system suspend:
                    watch_displays stuck in D state reading a DRM
                    connector's EDID
    Classification: Plasma
           Product: plasmashell
      Version First 6.8.2
       Reported In:
          Platform: Arch Linux
                OS: Linux
            Status: REPORTED
          Severity: major
          Priority: NOR
         Component: Power management & brightness
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
  Target Milestone: 1.0

Created attachment 198256
  --> https://bugs.kde.org/attachment.cgi?id=198256&action=edit
kernel log of both failed attempts, with full call traces,
/sys/power/suspend_stats transcribed at each step and PowerDevil/ddcutil DDC
activity and counts, before and after the workaround

DESCRIPTION

I finally jumped to Linux recently and kept having trouble with suspend on my
laptop. The visible symptom was that after waking up, the monitor plugged
straight into the HDMI port on the NVIDIA GPU stayed black while the one on
USB-C was fine, so I assumed it was a display problem. It turned out suspend
itself was never completing. After digging through logs and testing for a while
I worked out what was happening. This is my first post here, so sorry if I get
something wrong.
I tried to be as torough as I could.

The short version: PowerDevil's DDC/CI display watcher sometimes blocks
suspend. Its watch_displays thread ends up in uninterruptible D state while it
reads a DRM connector's EDID through sysfs. The kernel freezer cannot freeze a
task in that state, so after 20 seconds suspend gives up with "Device or
resource busy".

The confusing part is what it looks like. The monitors go dark and the session
locks, so you think the laptop slept. It did not, it stayed awake and kept
draining the battery. That took some methodical testing to figure out - the
monitor on USB-C keeps the laptop charged enough that I did not notice, and oh
boy this laptop takes a long time to drain.

STEPS TO REPRODUCE

1. PowerDevil is running with DDC/CI enabled on external monitors, at least one
of them on an NVIDIA dGPU (mine: HDMI monitor on the RTX 4070, second monitor
on the Intel iGPU via USB-C).
2. Suspend the system (systemctl suspend).
3. On my machine suspend aborted this way on both captured attempts (10 of 10),
and it has happened again and again but I couldn't get it to happen on demand,
so the logs below are the main evidence I have.

OBSERVED RESULT

kernel: PM: suspend entry (deep)
kernel: Freezing user space processes failed after 20.003 seconds (2 tasks
refusing to freeze, wq_busy=0):
kernel: task:watch_displays  state:D stack:0  pid:54648 tgid:2881 ppid:1559
kernel: Call Trace:
kernel:  __schedule+0x712/0x22a0
kernel:  schedule+0x56/0x140
kernel:  schedule_preempt_disabled+0x16/0x30
kernel:  __mutex_lock+0x299/0x580
kernel:  drm_edid_connector_property_show+0x2f/0xa0
kernel:  kernfs_file_read_iter+0xb3/0x180
kernel:  __x64_sys_read+0x22e/0x450
kernel: PM: suspend exit
kernel: PM: suspend entry (s2idle)
kernel: Freezing user space processes failed after 20.008 seconds (1 tasks
refusing to freeze)
systemd-sleep: Failed to put system to sleep. System resumed again: Device or
resource busy
systemd[1]: systemd-suspend.service: Main process exited, code=exited,
status=1/FAILURE

tgid 2881 is /usr/lib/org_kde_powerdevil.

/sys/power/suspend_stats/ afterwards:
  success=0  fail=2  failed_freeze=2
  last_failed_step=freeze  last_failed_errno=-16

EXPECTED RESULT

A DDC/CI display watcher should never be able to block system suspend.

SOFTWARE/OS VERSIONS

Operating System: CachyOS (Arch-based)
KDE Plasma Version: 6.8.2
KDE Frameworks Version: 6.31.0
Qt Version: 6.12.0
Kernel: 7.3.3-1-cachyos, Wayland session, powerdevil 6.8.2-1.1, ddcutil 3.0.2-1
Graphics: NVIDIA open kernel modules 620.70.06 (RTX 4070 Max-Q) + Intel i915
Displays: 2x identical monitors Samsung C34H89x 3440x1440 but one HDMI on the
dGPU, one USB-C on the iGPU) + internal 3200x2000, both external at 100 Hz (yes
I tested different frequencies on them, no difference on th bug, also tested
known good cables that had no problem long usages on other monitors at much
higher troughput)

ADDITIONAL INFORMATION

One thing that helped me figure it out: the same freeze report also named a
process that has nothing to do with ddcutil. I had run "wc -c <
/sys/class/drm/card0-HDMI-A-3/edid" by hand to test something, and it got stuck
at the same frame:

kernel: task:wc  state:D ...
kernel:  __mutex_lock+0x299/0x580
kernel:  drm_edid_connector_property_show+0x2f/0xa0
kernel:  kernfs_file_read_iter+0xb3/0x180

So while whatever holds mode_config.mutex is stuck, any EDID sysfs reader goes
uninterruptible, powerDevil just happens to be the one running at the time.
Related reports I found while searching:

- https://github.com/rockowitz/ddcutil/issues/659 has the same stack, but that
system had an EVDI/DisplayLink dock. Mine has no evdi, udl or displaylink
module, no package and no USB device with DisplayLink vendor id 17e9, so EVDI
is not the only trigger.
- https://bugs.kde.org/show_bug.cgi?id=500951 looks similar but it's not bug
500951, a deadlock inside ddca_redetect_displays fixed in ddcutil 2.2.1. The
blocking point here is somewhere else.



TWO POSSIBLE POWERDEVIL-SIDE IMPROVEMENTS:

1. In bug 500951 the ddcutil maintainer says clients no longer need to call
ddca_redetect_displays() since libddcutil 2.2.0, because the watcher reports
changes by callback itself. The faulting backtrace in that report has
PowerDevil going through DDCutilPrivateSingleton::redetect() ->
ddca_redetect_displays(), which is the path reading connector EDIDs. So maybe
dropping that call removes this whole failure mode?
2. On PrepareForSleep(true), stop and join the display watcher thread instead
of pausing it for 500 ms, so no DDC/EDID read can still be in flight when the
kernel freezer runs (but I'm haven't read how it's done way it its now or the
changelogs, maybe it's a tradeoff somewhere there)


SOLUTION THAT WORKED ON MY LAPTOP
In case it helps anyone else: POWERDEVIL_NO_DDCUTIL=1 in the PowerDevil service
environment. This is documented in PowerDevil's own README for DDC/CI trouble.
I checked before and after: suspend went from 0 of 10 attempts succeeding to 10
of 10, and PowerDevil's DDC/CI log lines went from 973 to 0 bus operations.

Attached logs:
- Suspend-freeze-failed-attempts.log - kernel log of both failed attempts, with
full call traces
- Suspend-stats.txt - /sys/power/suspend_stats transcribed at each step
- Powerdevil-ddc-activity.log - PowerDevil/ddcutil DDC activity and counts,
before and after the workaround

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to