Bug 271995 - graphics/drm-{510,515,61}-kmod: VT switch disables hardware acceleration
Summary: graphics/drm-{510,515,61}-kmod: VT switch disables hardware acceleration
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Only Me
Assignee: freebsd-x11 (Nobody)
URL: https://github.com/freebsd/drm-kmod/i...
Keywords: needs-qa, performance
: 266745 (view as bug list)
Depends on:
Blocks:
 
Reported: 2023-06-14 17:37 UTC by brtastic.dev
Modified: 2025-06-25 10:18 UTC (History)
16 users (show)

See Also:


Attachments
drm: check if fpriv is the current master of the device (822 bytes, patch)
2025-06-19 13:15 UTC, Ali Abdallah
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description brtastic.dev 2023-06-14 17:37:31 UTC
I am testing this by running some 2D/3D graphical apps, and they all seem to behave the same.

Reproducing on Thinkpad T480. Right after booting, I get good performance from those apps and htop readings are not out of the ordinary.

After S3 suspend and resume, things get different. Applications show much lower performance, some becoming unusable, and htop shows up to 800% CPU usage.

I'm running dwm on X11 modesetting with latest drm-kmod installed from ports. Tried resetting Xorg / powerd after resuming, but didn't help.

/var/log/messages and /var/log/Xorg.0.log show no new errors after resuming.
Comment 1 devnull freebsd_committer freebsd_triage 2023-06-14 23:27:58 UTC
> some 2D/3D graphical apps,

Can you name one? And the exact version, please. 

> Thinkpad T480

What's the graphics hardware?

> top shows up to 800% CPU usage.

For which process(es)?
Comment 2 Oleksandr Kryvulia 2023-06-15 05:48:30 UTC
It is not caused by suspend-resume but a switching vt terminal. Try to set kern.vt.suspendswitch=0, see for details https://github.com/freebsd/drm-kmod/issues/175
Comment 3 Alexey Dokuchaev freebsd_committer freebsd_triage 2023-06-15 07:48:23 UTC
(In reply to Graham Perrin from comment #1)
> Can you name one? And the exact version, please.
For example, the latest version of Stellarium, 23.1 stops working -- it hangs on start while eating all available CPU cycles after VT switch (which is likely the trigger, not going in and out of S3) as I've reported earlier: https://github.com/Stellarium/stellarium/issues/3145.  Previous versions are immune to this bug.

> What's the graphics hardware?
Looking at the issue linked in comment #2 it can happen on both AMD and Intel, e.g. UHD Graphics 620 (Kaby Lake GT2) in my case.
Comment 4 brtastic.dev 2023-06-25 05:10:08 UTC
I've got UHD Graphics 620. But anyway, what Oleksandr Kryvulia said is true, there is no longer an issue after configuring kern.vt.suspendswitch=0.

Thank you!
Comment 5 Olivier Certner freebsd_committer freebsd_triage 2024-09-02 20:54:22 UTC
Changed the title to reflect what this bug is really about after comment #4.

Details to be found in the linked GitHub drm-kmod issue (https://github.com/freebsd/drm-kmod/issues/175).
Comment 6 Alexey Dokuchaev freebsd_committer freebsd_triage 2024-10-07 15:15:05 UTC
*** Bug 266745 has been marked as a duplicate of this bug. ***
Comment 7 Vurefozu 2025-01-07 12:35:51 UTC
FreeBSD 13.2
FreeBSD 14.1
FreeBSD 14.2

CPU: Intel i7-4770k
GPU: Intel HD Graphics 4600
Kernel module: i915kms

After switching from a graphical console to another console via CTRL+ALT+F1 and back CTRL+ALT+F9, hardware graphics acceleration disappears.

My post: https://forums.freebsd.org/threads/switching-between-tty-consoles-breaks-intel-hardware-acceleration-i915kms.96348/
Comment 8 JBrown 2025-01-08 17:02:46 UTC
I would also add version 13.1 to the list of versions.
Comment 9 Vurefozu 2025-01-16 09:01:07 UTC
FreeBSD 14.1
FreeBSD 14.2
CPU: Intel i7-4770k
GPU: Intel HD Graphics 4600
Kernel module: i915kms

I solved this problem with the loss of intel hardware acceleration via xorg.conf. I added "DRI" "3":
/usr/local/etc/X11/xorg.conf.d/xorg.conf
Section "Device"
        Identifier "Card0"
        Driver "intel"
        Option "DRI" "3"
        BusID "PCI:0:2:0"
EndSection

Anyone who has this problem, please check this configuration and report the results here or on the forum
https://forums.freebsd.org/threads/switching-between-tty-consoles-breaks-intel-hardware-acceleration-i915kms.96348/


# pkg info | grep -i drm
drm-61-kmod-6.1.92 DRM drivers modules
libdrm-2.4.123,1 Direct Rendering Manager library and headers

# pkg info | grep -iE 'intel|libva|vaapi'
libva-2.22.0 VAAPI wrapper and dummy driver
libva-intel-driver-2.4.1_3 VAAPI legacy driver for Intel GMA 4500 (Gen4) to UHD 630 (Gen9.5)
libva-intel-hybrid-driver-1.0.2_3 Hybrid VP8 encoder and VP9 decoder for Intel GPUs
libva-utils-2.22.0 Collection of tests and utilities for VAAPI
xf86-video-intel-2.99.917.923_1,1 X.Org legacy driver for Intel integrated graphics chipsets
Comment 10 Ali Abdallah 2025-06-19 13:15:29 UTC
Created attachment 261402 [details]
drm: check if fpriv is the current master of the device

Short story, the attached patch should fix the problem. 

Long story, the issue is reproducible with the modesetting drivers in Xorg, not with the outdated xf86-video-intel or xf86-video-amdgpu. So proposing to add a section to Xorg to use "Intel" driver instead of the modesetting driver has nothing to do with the bug itself. 

When switching to VT, modesetting_drv calls drmDropMaster and drmGetMaster when switching back to X. 

Without the additional check proposed in the patch, the magic map of the real master of the device (which is Xorg) is cleaned up, programs using DRI were getting a different magic_map for a different master, and thus the magic_map of authenticated clients of the real master Xorg remains free, and so all clients get authentication error, loosing hardware acceleration. You can trace the idr_alloc/idr_find in drm_getmagic/drm_authmagic to see the problem yourself. 

I've tested with drm-61-kmod on amd based system Thinkpad T495 and intel one X270 (without the amdgpu or intel xorg drivers obviously, using only modesetting_drv) On FreeBSD 14.3-RELEASE

PS: Linux upstream commit:

0aae5920a84469: drm: Clear up master tracking booleans
Comment 11 Oleksandr Kryvulia 2025-06-19 14:05:19 UTC
(In reply to Ali Abdallah from comment #10)
Your patch fixes an issue for me on current and graphics/drm-66-kmod.
Thank you!
Comment 12 Olivier Certner freebsd_committer freebsd_triage 2025-06-19 15:01:19 UTC
Great Ali! Thanks.
Comment 13 rkoberman 2025-06-19 23:37:52 UTC
Applied the one-liner to 66 on my Alden Lake laptop and it made no difference. Still comes back from VT with zink instead of iris with a message:
failed to authenticate magic 1
failed to load driver: iris

I was just sure that this would fix it. :-(

Running current updated to the latest yesterday afternoon (8d51f2aba9ad).
Comment 14 Ali Abdallah 2025-06-20 06:15:35 UTC
(In reply to rkoberman from comment #13)

Are you sure you installed and loaded drm.ko after applying the patch?
Comment 15 Emmanuel Vadot freebsd_committer freebsd_triage 2025-06-20 06:19:32 UTC
It works fine for me on my amd machine, no way to test on intel right now but I can't see why it wouldn't work.
Comment 16 commit-hook freebsd_committer freebsd_triage 2025-06-20 06:26:23 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=8ebe065203495c6c246d0ce3c29619a11c9cf910

commit 8ebe065203495c6c246d0ce3c29619a11c9cf910
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2025-06-20 06:25:10 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2025-06-20 06:25:10 +0000

    graphics/drm-66-kmod: Update to drm_v6.6.25_5

    This update fixes GPU acceleration when switching to VT and back to Xorg.

    PR:             271995
    Sponsored by:   Beckhoff Automation GmbH & Co. KG

 graphics/drm-66-kmod/Makefile         | 2 +-
 graphics/drm-66-kmod/Makefile.version | 2 +-
 graphics/drm-66-kmod/distinfo         | 6 +++---
 graphics/nvidia-drm-66-kmod/Makefile  | 2 +-
 graphics/nvidia-drm-66-kmod/distinfo  | 6 +++---
 5 files changed, 9 insertions(+), 9 deletions(-)
Comment 17 commit-hook freebsd_committer freebsd_triage 2025-06-20 06:26:26 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=2648f5b3b996ac77536a60f2a6012db1eb5a4349

commit 2648f5b3b996ac77536a60f2a6012db1eb5a4349
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2025-06-20 06:22:13 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2025-06-20 06:22:13 +0000

    graphics/drm-515-kmod: Update to drm_v5.15.160_5

    This update fixes GPU acceleration when switching to VT and back to Xorg.

    PR:             271995
    Sponsored by:   Beckhoff Automation GmbH & Co. KG

 graphics/drm-515-kmod/Makefile         | 2 +-
 graphics/drm-515-kmod/Makefile.version | 2 +-
 graphics/drm-515-kmod/distinfo         | 6 +++---
 graphics/nvidia-drm-515-kmod/Makefile  | 2 +-
 graphics/nvidia-drm-515-kmod/distinfo  | 6 +++---
 5 files changed, 9 insertions(+), 9 deletions(-)
Comment 18 commit-hook freebsd_committer freebsd_triage 2025-06-20 06:26:28 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=275846acd725a3e0240e07ae88773158c4d5f29c

commit 275846acd725a3e0240e07ae88773158c4d5f29c
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2025-06-20 06:23:54 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2025-06-20 06:23:54 +0000

    graphics/drm-61-kmod: Update to drm_v6.1.128_4

    This update fixes GPU acceleration when switching to VT and back to Xorg.

    PR:             271995
    Sponsored by:   Beckhoff Automation GmbH & Co. KG

 graphics/drm-61-kmod/Makefile         | 2 +-
 graphics/drm-61-kmod/Makefile.version | 2 +-
 graphics/drm-61-kmod/distinfo         | 6 +++---
 graphics/nvidia-drm-61-kmod/Makefile  | 2 +-
 graphics/nvidia-drm-61-kmod/distinfo  | 6 +++---
 5 files changed, 9 insertions(+), 9 deletions(-)
Comment 19 Alexey Dokuchaev freebsd_committer freebsd_triage 2025-06-20 06:39:14 UTC
(In reply to Ali Abdallah from comment #10)
> Linux upstream commit: 0aae5920a84469: drm: Clear up master tracking booleans
Kudos for digging this Ali, it is huge!  Posting the clickable link to aforementioned commit for some extra convenience: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=0aae5920a84469
Comment 20 rkoberman 2025-06-20 23:43:30 UTC
(In reply to Emmanuel Vadot from comment #15)
Yes, it appears that I did, as you suggest, fail to install the patched code. I patched, built and staged, but did not install the fixed module.

I'm very sorry for the error. I was just anxious to get this resolved that I built the port and rebooted.
Comment 21 Vurefozu 2025-06-21 06:23:56 UTC
Ali, THX!!!
Comment 22 Jan Beich freebsd_committer freebsd_triage 2025-06-21 06:33:12 UTC
- drm-510-kmod is still affected[1] (unlike drm-54-kmod) and required for FreeBSD 13.* until EOL on 2026-04-30
- Do you plan to MFH to /quarterly? May help reduce support load with new users who are unaware of this bug.

[1] According to "git blame" on 5.10-lts branch the true culprit is https://github.com/freebsd/drm-kmod/commit/1f3625023b0f
    On newer branches it was squashed into the upstream commit.
Comment 23 commit-hook freebsd_committer freebsd_triage 2025-06-21 11:33:57 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=408bc22ceb8f1971abdb5271decf4275a7af9d8f

commit 408bc22ceb8f1971abdb5271decf4275a7af9d8f
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2025-06-21 11:32:07 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2025-06-21 11:32:07 +0000

    graphics/drm-510-kmod: Update to drm_v5.10.163_8

    This update fixes GPU acceleration when switching to VT and back to Xorg.

    PR:             271995
    Sponsored by:   Beckhoff Automation GmbH & Co. KG

 graphics/drm-510-kmod/Makefile         | 3 +--
 graphics/drm-510-kmod/Makefile.version | 2 +-
 graphics/drm-510-kmod/distinfo         | 6 +++---
 graphics/nvidia-drm-510-kmod/Makefile  | 1 +
 graphics/nvidia-drm-510-kmod/distinfo  | 6 +++---
 5 files changed, 9 insertions(+), 9 deletions(-)
Comment 24 p5B2EA84B3 2025-06-21 17:40:44 UTC
As this PR is about graphics/drm-{510,515,61}-kmod,
and the commit affects drm-510-kmod only,

Commits for 515 and 61 kmods are missing.
Comment 25 Vurefozu 2025-06-21 17:53:24 UTC
> Commits for 515 and 61 kmods are missing.

FreeBSD 14.2
drm-61-kmod-6.1.128.1402000_5
Build from ports, problem solved.
Comment 26 Olivier Certner freebsd_committer freebsd_triage 2025-06-25 10:09:03 UTC
Just wanted to report that, for me, the problem in fact had been already fixed somehow by switching to a recent stable/14 and drm-61-kmod-6.1.128.*_5 (corresponding to tag drm_v6.1.128_3) on one of my Intel laptops that had been showing the issue, so without the patch above.  So there is something else at play here.  Hopefully the patch above is enough to fix all cases.
Comment 27 Emmanuel Vadot freebsd_committer freebsd_triage 2025-06-25 10:12:50 UTC
(In reply to Olivier Certner from comment #26)

drm-61-kmod-6.1.128.*_5 is tracking drm_v6.1.128_4 and so have the patch for this issue.
Comment 28 Olivier Certner freebsd_committer freebsd_triage 2025-06-25 10:16:40 UTC
> (snip) by switching to a recent stable/14 and drm-61-kmod-6.1.128.*_5 (snip)

Correction: drm-61-kmod-6.1.128.*_4
Comment 29 Olivier Certner freebsd_committer freebsd_triage 2025-06-25 10:18:10 UTC
(In reply to Emmanuel Vadot from comment #27)

> drm-61-kmod-6.1.128.*_5 is tracking drm_v6.1.128_4

Yes, but I made a mistake in the package version.  The corresponding DRM tag is drm_v6.1.128_3, so without the fix.