Bug 477242

Summary: Kwin on host duplicates Displays when guest VM is using Intel GVT-g
Product: [Plasma] kwin Reporter: Andreas G <uriesk>
Component: platform-drmAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED FIXED    
Severity: normal Keywords: qt6
Priority: NOR    
Version First Reported In: master   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: Starting a VM utilizing GVTg on a Plasma 6 Host
kwin keeps on adding displays while the VM is running

Description Andreas G 2023-11-19 17:29:51 UTC
SUMMARY

GVTg can be used on some Intel CPUs to provide vGPUs for virtual machines.
Whenever a virtual machine is using a vGPU, the intel driver i915 triggers an "add" uevent for "/dev/dri/card0" (the integrated intel gpu).
Every single time such an uevent happens, kwin on KF6 adds another duplicate display.

On current KF5 (5.27.9), the behaviour is different: It causes kwin to freeze with the warnings:
Nov 19 14:38:35 fedora.gatas kwin_wayland[21784]: kwin_core: Failed to open /dev/dri/card0 device (Device already taken)
Nov 19 14:38:35 fedora.gatas kwin_wayland[21784]: kwin_wayland_drm: failed to open drm device at "/dev/dri/card0"

STEPS TO REPRODUCE
1. buy Intel 5th to 10th gen CPU
2. use Plasma 6 via kdesrc-build
3. setup a virtual machine using GVTg https://wiki.archlinux.org/title/Intel_GVT-g (what form of output you choose doesn't matter)
4. start VM (again doesn't matter how, if it's "virsh start DomainName" and you never look at it, it also happens)

OBSERVED RESULT

Flashing and scale change and new monitors keep getting added in the display settings causing worse and worse performance.

EXPECTED RESULT

Not having a dozen duplicate displays.

SOFTWARE/OS VERSIONS

Operating System: Fedora Linux 39
KDE Plasma Version: 5.81.0
KDE Frameworks Version: 5.245.0
Qt Version: 6.6.0
Kernel Version: 6.5.11-300.fc39.x86_64 (64-bit)
Graphics Platform: Wayland
Processors: 8 × Intel® Core™ i7-7700HQ CPU @ 2.80GHz
Memory: 15.5 GiB of RAM
Graphics Processor: Mesa Intel® HD Graphics 630

ADDITIONAL INFORMATION

This is not an issue when using xorg or when using an older kwin_wayland KF5. But i do not remember the last working version. I just have it in my memory that i used wayland a few months ago in Fedora 38 and the same VM setup did work.
Comment 1 Andreas G 2023-11-19 18:07:16 UTC
Created attachment 163297 [details]
Starting a VM utilizing GVTg on a Plasma 6 Host

Here the uevents are shown and KWin adding a duplicate display on Windows guest VM boot.
Comment 2 Andreas G 2023-11-19 18:18:00 UTC
Created attachment 163298 [details]
kwin keeps on adding displays while the VM is running

This video shows that it doesn't just happen during VM boot, but also when opening a running VM and sometimes just randomly.
Comment 3 Zamundaaa 2023-11-20 13:24:32 UTC
Git commit 5651bae432c6586a1f4c06b92832517cd5448ecb by Xaver Hugl, on behalf of Andreas Gattringer.
Committed on 20/11/2023 at 14:08.
Pushed by zamundaaa into branch 'master'.

backends/drm: Don't add GPU if we are already using it

M  +5    -0    src/backends/drm/drm_backend.cpp

https://invent.kde.org/plasma/kwin/-/commit/5651bae432c6586a1f4c06b92832517cd5448ecb