Bug 279864 - graphics/drm-61-kmod: doesn't compile on powerpc64
Summary: graphics/drm-61-kmod: doesn't compile on powerpc64
Status: Open
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: powerpc Any
: --- Affects Some People
Assignee: freebsd-x11 (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-06-19 18:58 UTC by Benjamin Stürz
Modified: 2026-04-01 04:35 UTC (History)
7 users (show)

See Also:
bugzilla: maintainer-feedback? (x11)


Attachments
cd /usr/ports/graphics/drm-61-kmod && make (77.63 KB, text/plain)
2024-06-19 18:58 UTC, Benjamin Stürz
no flags Details
Allow build on powerpc64 (450 bytes, patch)
2024-10-28 14:04 UTC, Curtis Hamilton
no flags Details | Diff
Fix for drm-61-kmod to build (1.50 KB, patch)
2025-02-25 21:58 UTC, Justin Hibbits
no flags Details | Diff
Fix for drm-61-kmod to build and load (1.87 KB, patch)
2025-03-16 23:33 UTC, Justin Hibbits
no flags Details | Diff
poudriere log (95.75 KB, text/plain)
2026-03-19 14:06 UTC, yzrh
no flags Details
core.txt (5.92 KB, text/plain)
2026-03-21 17:36 UTC, yzrh
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Stürz 2024-06-19 18:58:23 UTC
Created attachment 251578 [details]
cd /usr/ports/graphics/drm-61-kmod && make

uname -aKU: FreeBSD powerkek 14.1-RELEASE FreeBSD 14.1-RELEASE releng/14.1-n267679-10e31f0946d8 GENERIC powerpc 1401000 1401000

TLDR:
/usr/ports/graphics/drm-61-kmod/work/drm-kmod-drm_v6.1.69_2/drivers/gpu/drm/drm_cache.c:358:10: error: call to undeclared function 'in_interrupt'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
  358 |         WARN_ON(in_interrupt());
      |                 ^
1 error generated.
*** [drm_cache.o] Error code 1
Comment 1 Curtis Hamilton 2024-10-28 14:04:03 UTC
Created attachment 254592 [details]
Allow build on powerpc64
Comment 2 Curtis Hamilton 2024-10-28 14:05:14 UTC
I also tried to build this and discovered that powerpc64 support is broken here and in drm-515-kmod.  The attached patch allows you to get past this error but you'll encounter other errors.  After, further investigation and troubleshooting t I found missing kernel files in "sys/compat/linuxkpi/common/include/asm". The missing files are cputable.h and switch_to.h (there may be more).

This leads me to believe that kernel support for powerpc64, beyond drm-510, is broken.  As even after a successfully build, it will does not work.  I get a drm version error on boot.
Comment 3 Justin Hibbits freebsd_committer freebsd_triage 2025-02-25 21:58:18 UTC
Created attachment 257959 [details]
Fix for drm-61-kmod to build

This patch should get it building (sort of transcribed it from a poudriere build session, but should be close enough) for powerpc64.  However, I never tested the resulting package.
Comment 4 Justin Hibbits freebsd_committer freebsd_triage 2025-03-16 23:33:57 UTC
Created attachment 258740 [details]
Fix for drm-61-kmod to build and load

With this new patch drm-61-kmod builds and loads.  I haven't tested if it actually works, as I loaded it in a VM.  But it does load, no symbol errors or anything.  However, the patch to drm_os_freebsd.c obviously can't be pushed, since it would likely break x86 (and arm64, possibly).
Comment 5 Piotr Kubaj freebsd_committer freebsd_triage 2025-03-17 09:11:33 UTC
Can't the patch to drm_os_freebsd.c be also put behind #if defined(CONFIG_X86)?
Comment 6 Piotr Kubaj freebsd_committer freebsd_triage 2025-03-17 09:11:56 UTC
Or maybe #if !defined(CONFIG_PPC64)
Comment 7 Justin Hibbits freebsd_committer freebsd_triage 2025-03-17 13:52:54 UTC
(In reply to Piotr Kubaj from comment #6)
Probably one of those.  This was a starting point just to get it building, so others can test functionality.
Comment 8 yzrh 2026-03-19 14:06:55 UTC
Created attachment 268925 [details]
poudriere log

I am getting a different error with and without the patch:

/wrkdirs/usr/ports/graphics/drm-61-kmod/work/drm-kmod-drm_v6.1.128_7/drivers/gpu/drm/drm_cache.c:358:10: error: call to undeclared function 'in_interrupt'; ISO C99 and later do not support implicit function declarations [-Werror,-Wimplicit-function-declaration]
  358 |         WARN_ON(in_interrupt());
      |                 ^
Comment 9 yzrh 2026-03-19 14:14:45 UTC
It is a Talos II system with an AMD GPU.  From pciconf -lv:

vgapci0@pci0:3:0:0:     class=0x030000 rev=0xc1 hdr=0x00 vendor=0x1002 device=0x66af subvendor=0x1002 subdevice=0x081e
    vendor     = 'Advanced Micro Devices, Inc. [AMD/ATI]'
    device     = 'Vega 20 [Radeon VII]'
    class      = display
    subclass   = VGA

Anything I can do to help with drm-kmod?
Comment 10 Robert Clausecker freebsd_committer freebsd_triage 2026-03-19 19:47:28 UTC
(In reply to yzrh from comment #9)

I have looked into the code base.  Unfortunately the drivers have bitrotted for ppc64le.  Some nontrivial work will be needed to make them work.
Comment 11 Bjoern A. Zeeb freebsd_committer freebsd_triage 2026-03-19 22:30:45 UTC
I believe the problem is in LinuxKPI and missing "hidden #includes" to get preempt.h into the files on non-X86 which includes asm/smp.h already to get there.

Looking at the patch from #c4 it seems this is not the only problem though with the patch from https://reviews.freebsd.org/D55974 I at least can cross-compile drm-kmod 6.1-lts on main for powerpc[64le].

Can you give that patch a try and let us know if further errors happen?
Comment 12 yzrh 2026-03-20 17:42:30 UTC
It builds fine with both patches, but the module does not load correctly:

The first time kldload crashed the system and subsequent kldload displays

kldload: can't load /boot/modules/amdgpu.ko: No such file or directory

in console and 

KLD amdgpu.ko: depends on drmn - not available or version mismatch

in /var/log/messages
Comment 13 Bjoern A. Zeeb freebsd_committer freebsd_triage 2026-03-20 23:02:40 UTC
(In reply to yzrh from comment #12)

> It builds fine with both patches, 

But in comment #c8 you said you get an error with and without a patch.
I'll get the LinuxKPI changes into the tree at least.

 
> KLD amdgpu.ko: depends on drmn - not available or version mismatch

might be interesting to know more.  Are the modules part of the package?  if you check the installed files, do they have the correct date?   Do you have another copy lying around?   What does dmesg -a | tail -50 say right after you try to kldload amdgpu?  Is there a more detailed error?
Comment 14 yzrh 2026-03-21 13:01:58 UTC
(In reply to Bjoern A. Zeeb from comment #13)

I meant both patches (D55974 and #c4).

> might be interesting to know more.  Are the modules part of the package?  if you check the installed files, do they have the correct date?   Do you have another copy lying around?   What does dmesg -a | tail -50 say right after you try to kldload amdgpu?  Is there a more detailed error?

I pkg remove and pkg install drm-kmod again (pulls in drm-61-kmod; built by poudriere) to be sure.

When kldload amdgpu, the system reboots immediately just like before.  Maybe the crash corrupted the files, which affected subsequent kldload.  Now it reboots every time I kldload amdgpu (I executed sync after pkg install this time).

I do see entries in dmesg:

savecore 84011 - - reboot after panic: mmu_radix_mapdev_attr: Couldn't alloc kernel virtual memory
Mar 21 12:58:18 localhost savecore[84011]: reboot after panic: mmu_radix_mapdev_attr: Couldn't alloc kernel virtual memory
savecore 84011 - - writing core to /var/crash/vmcore.4
Writing crash summary to /var/crash/core.txt.4.

The system is on stable/15-1b7687f053af-dirty.
Comment 15 Robert Clausecker freebsd_committer freebsd_triage 2026-03-21 13:03:33 UTC
(In reply to yzrh from comment #12)

Which version of FreeBSD do you run?  The drm-kmod version must match your kernel. drm-61-kmod is for FreeBSD 14 only.
Comment 16 Bjoern A. Zeeb freebsd_committer freebsd_triage 2026-03-21 13:07:38 UTC
(In reply to yzrh from comment #14)

That's a powerpc issue now.  Can you possibly share the /var/crash/core.txt.4 file for the people to look at this?

If not the full file (showing processes etc. as well), then at the top there are backtraces up to a first line with ------------------------------------------------------------------------ which may be good to have, and then the section starting with a long line titles "dmesg" as well.

Thanks a lot for doing all the testing and helping to debug this!
Comment 17 yzrh 2026-03-21 13:21:48 UTC
(In reply to Robert Clausecker from comment #15)

The system is on stable/15-1b7687f053af-dirty (patch from D55974).

Looking at https://cgit.freebsd.org/ports/tree/graphics/drm-kmod/Makefile

graphics/drm-66-kmod seems to support amd64 only.

For powerpc64[le], only options are graphics/drm-510-kmod (not available for stable/15) and graphics/drm-61-kmod.
Comment 18 yzrh 2026-03-21 13:29:56 UTC
(In reply to Bjoern A. Zeeb from comment #16)

The file reads:

Unable to find a kernel debugger.
Please install the devel/gdb port or gdb package.

Let me crash again with gdb (building now).
Comment 19 Robert Clausecker freebsd_committer freebsd_triage 2026-03-21 14:25:52 UTC
(In reply to yzrh from comment #17)

> graphics/drm-66-kmod seems to support amd64 only.

Yes, this is because the DRM code has rotten on powerpc64le and doesn't build.  I have tried to make some inroads with fixing it, but didn't have the time to get far.
Comment 20 yzrh 2026-03-21 17:36:36 UTC
Created attachment 268982 [details]
core.txt
Comment 21 yzrh 2026-03-21 17:44:45 UTC
I am not sure what went wrong, but I am getting

Failed to open vmcore: invalid corefile

I am uploading the corefile as well, just in case it is useful.

Too big for bugzilla: https://etc.noema.org/drop/k1rp.xz
Comment 22 commit-hook freebsd_committer freebsd_triage 2026-03-21 21:17:57 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=1d18872c2519d7ca726ddc49735180ab1d8916e0

commit 1d18872c2519d7ca726ddc49735180ab1d8916e0
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2026-03-19 20:29:29 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2026-03-21 21:16:43 +0000

    LinuxKPI: add supporting #includes

    Compiling drm-kmod on !X86 does not include asm/smp.h which includes
    preempt.h on FreeBSD.  In order to compile drm-kmod on other
    architectures add the secondary #includes for preempt.h to
    spinlock.h and hardirq.h (which now also gets included from highmem.h)
    to connect the #include chain.

    Sponsored by:   The FreeBSD Foundation
    MFC after:      3 days
    PR:             279864
    Reviewed by:    jhibbits, emaste
    Differential Revision: https://reviews.freebsd.org/D55974

 sys/compat/linuxkpi/common/include/linux/hardirq.h  | 1 +
 sys/compat/linuxkpi/common/include/linux/highmem.h  | 1 +
 sys/compat/linuxkpi/common/include/linux/spinlock.h | 1 +
 3 files changed, 3 insertions(+)
Comment 23 commit-hook freebsd_committer freebsd_triage 2026-03-31 20:29:08 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=29dce45d8c50ea5858dc91a4294e83b8d72a2f80

commit 29dce45d8c50ea5858dc91a4294e83b8d72a2f80
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2026-03-19 20:29:29 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2026-03-31 16:22:51 +0000

    LinuxKPI: add supporting #includes

    Compiling drm-kmod on !X86 does not include asm/smp.h which includes
    preempt.h on FreeBSD.  In order to compile drm-kmod on other
    architectures add the secondary #includes for preempt.h to
    spinlock.h and hardirq.h (which now also gets included from highmem.h)
    to connect the #include chain.

    Sponsored by:   The FreeBSD Foundation
    PR:             279864
    Reviewed by:    jhibbits, emaste
    Differential Revision: https://reviews.freebsd.org/D55974

    (cherry picked from commit 1d18872c2519d7ca726ddc49735180ab1d8916e0)

 sys/compat/linuxkpi/common/include/linux/hardirq.h  | 1 +
 sys/compat/linuxkpi/common/include/linux/highmem.h  | 1 +
 sys/compat/linuxkpi/common/include/linux/spinlock.h | 1 +
 3 files changed, 3 insertions(+)
Comment 24 commit-hook freebsd_committer freebsd_triage 2026-04-01 04:35:09 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=7d069d7846519eb015133758647ee343e7d7f20a

commit 7d069d7846519eb015133758647ee343e7d7f20a
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2026-03-19 20:29:29 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2026-04-01 04:33:47 +0000

    LinuxKPI: add supporting #includes

    Compiling drm-kmod on !X86 does not include asm/smp.h which includes
    preempt.h on FreeBSD.  In order to compile drm-kmod on other
    architectures add the secondary #includes for preempt.h to
    spinlock.h and hardirq.h (which now also gets included from highmem.h)
    to connect the #include chain.

    Sponsored by:   The FreeBSD Foundation
    PR:             279864
    Reviewed by:    jhibbits, emaste
    Differential Revision: https://reviews.freebsd.org/D55974

    (cherry picked from commit 1d18872c2519d7ca726ddc49735180ab1d8916e0)
    (cherry picked from commit 29dce45d8c50ea5858dc91a4294e83b8d72a2f80)

 sys/compat/linuxkpi/common/include/linux/hardirq.h  | 1 +
 sys/compat/linuxkpi/common/include/linux/highmem.h  | 1 +
 sys/compat/linuxkpi/common/include/linux/spinlock.h | 1 +
 3 files changed, 3 insertions(+)