Bug 454639

Summary: amdgpu driver: Flickering in Wayland session after suspend without lock screen enabled
Product: [Plasma] kwin Reporter: Jan Rathmann <jan.rathmann>
Component: wayland-genericAssignee: KWin default assignee <kwin-bugs-null>
Severity: normal CC: jsteinaker, nate, postix
Priority: NOR Flags: jan.rathmann: Wayland+
Version: 5.24.5   
Target Milestone: ---   
Platform: Kubuntu   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: Video showing the flickering
Output of lshw
radeon driver: Corrupted screen after suspend
Output of lshw in english

Description Jan Rathmann 2022-05-31 07:36:27 UTC
Created attachment 149345 [details]
Video showing the flickering

This is a follow-up report to https://bugs.kde.org/show_bug.cgi?id=447705

Steps how I experience the bug:
* Use Plasma Wayland session, screenlocking disabled, GPU driver set to amdgpu (see below)
* Do Suspend-to-RAM.
* Resume.

Sometimes heavy flickering of the whole screen, it goes away if I click on UI elements (see attached video).

Happens always?:
No. At the first resumes after boot chances are good that everythings's fine. But when flickering has happend one time, it seems it will also flicker on all subsequent resumes (until rebooting).

(I rarely see a similar flickering in Firefox at Firefox startup or when a new browser tab loads [usually only a small square part of the window is affected, it goes away almost immediately  <1 second. Not sure if it is related.].)

Additional notes:

Kubuntu 22.04 + Backports-PPA
Plasma 5.24.5
Frameworks: 5.94.0
Qt: 5.15.3
Kernel: 5.15.0-33-generic

== My system ==
Board: Gigabyte P35-DS3
CPU: Intel Core2Quad Q9550
Graphics card: Asus Radeon R7 240

Note that my graphics card can work with two different drivers: 
The default driver is radeon but amdgpu also works by manually enabling it by adding the following boot optionts to the linux command line in Grub:

radeon.si_support=0 radeon.cik_support=0 amdgpu.si_support=1 amdgpu.cik_support=1

For at least a year(?) I solely used amdgpu on my system (the initial reason was something like amdgpu worked slightly better than radeon at one minor aspect, but I don't remember exactly anymore). Using amdgpu was so ubiquitous for me that I didn't even remember it when writing the original bug report.

For debugging purpose I tested how suspend/resume behaves with radeon driver in use (both on Wayland and X11), and it is different:

Resume from suspend under Wayland:
* amdgpu: flickers sometimes, as described above.
* radeon: no flickering, but even worse: graphics output completely distorted and corrupted (see attached video). Sometimes temporarily switching between different TTYs (Ctrl+Alt+F1-7) restores the desktop, when it does not it effectively crashes the whole session.
Resume from suspend under X11:
* Everything fine, no flicker (amdgpu), no corruption (radeon)

I also tested (under Wayland) what happens if the lock screen is enabled after suspend:
* amdgpu: Everythings fine now, couldn't reproduce the flickering anymore
* radeon: corrupted screen, as described above

Sorry it took so long to report this follow-up report, it took some time to investigate and test all those different subtly different surrounding conditions.

Kind regards, Jan
Comment 1 Jan Rathmann 2022-05-31 07:37:19 UTC
Created attachment 149346 [details]
Output of lshw
Comment 2 Jan Rathmann 2022-05-31 07:38:26 UTC
Created attachment 149347 [details]
radeon driver: Corrupted screen after suspend
Comment 3 Jan Rathmann 2022-05-31 07:44:36 UTC
Created attachment 149348 [details]
Output of lshw in english

Sorry, the output of lshw I first posted was in german, attaching an english version.
Comment 4 Javier Steinaker 2022-06-02 20:06:06 UTC
(In reply to Jan Rathmann from comment #2)
> Created attachment 149347 [details]
> radeon driver: Corrupted screen after suspend

Jan, the exact same thing is happening to me ever since I've switched to Plasma (using Wayland). I'm using an old HP Sleekbook 14 (old AMD card, radeon graphics driver) and I get the same results as you. Things I've tried:

- Disabling screen lock on suspend: same results, so likely kscreenlocker is not the culprit.
- Using a different DE/Compositor: resuming behaves correctly (tested on Sway and gtkgreet using Cage), so it seems to be a Plasma thing.

Running updated Arch Linux here. Might be a little difficult for me to try patches, unstable versions and the like since this is an old computer, but I can provide logs and run some tests if the devs need them.
Comment 5 Jan Rathmann 2022-06-04 09:22:59 UTC
Javier, is your card also supported by the amdgpu driver? (You can check by running 'lspci -k' and see if there is a line that says something like "Kernel modules: radeon, amdgpu") If yes, it could be helpful if you try it out and see if you can confirm the behaviour that I'm getting when using amdgpu (flickering when lock screen is disabled).

Have you tested if everything works fine when you use Plasma X11 session instead? This would also be interesting to know.
Comment 6 Javier Steinaker 2022-06-04 21:02:23 UTC
No, unfortunately my card is not supported, there's no way I'd be using the radeon driver if AMDGPU was available. About the Plasma X11 thing, I gave it a try the other day, the session never started, and I kind of gave up for now. Might give it a try again in a few days.
Comment 7 Javier Steinaker 2022-06-05 22:44:55 UTC
Ok so I did the test using a Fedora KDE Live CD and suspending and resuming a Wayland session brings the same results to the table. On the X11 session suspending and resuming works fine for me.
Comment 8 Jan Rathmann 2022-10-15 09:05:00 UTC
Update: I recently got a new PC and I don't see the bug there anymore, without changing anything on the installed OS.

For graphics now I use the integrated GPU of the Ryzen 7 5700G that also uses the amdgpu driver, same as before. So this bug may be a special problem related to my old graphics card, an Asus Radeon R7 240.

For other people still affected, I can present you a really ugly workaround that nevertheless worked for me:

* Create  a systemd service roughly like this (Don't know if all of those environment variables are actually necessary. Don't forget to insert your actual user name/computer name etc.):
Description=Workaround to fix flickering after suspend under Wayland
After=suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target

declare -x DISPLAY=":1"
WantedBy=suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target

* Then create a script kwin-suspend-fix-flicker.sh :
qdbus org.kde.KWin /component/kwin org.kde.kglobalaccel.Component.invokeShortcut "MinimizeAll"
sleep 0.5
qdbus org.kde.KWin /component/kwin org.kde.kglobalaccel.Component.invokeShortcut "MinimizeAll"
This will run the Kwin effect "Minimize all" to stop the flickering, and the run the same effect a second time to restore the original positions of all windows.
Comment 9 Nate Graham 2022-10-15 14:00:33 UTC
It makes a lot of sense this this would be a GPU driver issue, yeah. You can file those at https://gitlab.freedesktop.org/drm/amd/-/issues.