Re: drm-66-kmod build fail during main-n290014-7a48c3fd3e6e -> main-n290042-9f0432041b8f

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Mon, 12 Oct 2026 22:42:27 UTC
On Tue, 13 Oct 2026, Tomoaki AOKI wrote:

> On Mon, 12 Oct 2026 18:13:40 +0000 (UTC)
> "Bjoern A. Zeeb" <bz@FreeBSD.org> wrote:
>
>> On Tue, 13 Oct 2026, Tomoaki AOKI wrote:
>>
>>> On Mon, 12 Oct 2026 17:21:39 +0200
>>> A FreeBSD User <freebsd@walstatt-de.de> wrote:
>>>
>>>> Am Tage des Herren Sun, 11 Oct 2026 22:07:36 +0100
>>>> Nuno Teixeira <eduardo@freebsd.org> schrieb:
>>>>
>>>>> Hello,
>>>>>
>>>>> 37:
>>>>>> /usr/src/sys/compat/linuxkpi/common/include/linux/kernel.h:33:10: fatal
>>>>>> error: 'opt_linuxkpi.h' file not found
>>>>>>    33 | #include "opt_linuxkpi.h"
>>>>>>       |          ^~~~~~~~~~~~~~~~
>>>>>
>>>>>
>>>>> I've reported today at
>>>>> https://lists.freebsd.org/archives/dev-commits-src-all/2026-October/082012.html
>>>>>
>>>>> Cheers,
>>>>>
>>>>
>>>> Ups. I did also for port graphics/drm-612-kmod a few minutes ago. The header file in question
>>>> is simply not in the most recent source tree ... very strange ;-)
>>>
>>> Good point.
>>>
>>> It SHOULDN'T be under /usr/src/, but under /usr/obj/, as it's generated
>>> on "kernel build time".
>>>
>>> This means, it shouldn't exist unless you built kernel
>>> yourself locally.
>>>
>>> Thus, I believe it SHOULDN'T be required for out-of-tree
>>> kmods (in ports or in the wild).
>>>
>>> If it's REALLY mandatory for out-of-tree kmod builds
>>> and fix in out-of-tree kmod side, error message to request
>>> local kernel builds first should be needed.
>>>
>>> If not, guards for #include NOT to be included except for
>>> kernel builds in src side would be the best fix.
>>>
>>> IIRC, it's the way usually done for this kind of situations,
>>> but I'm not enough sure if opt_linuxkpi.h is really mandatory
>>> or not for out-of-tree kmod builds.
>>>
>>> Note that, as far as I could confirm, there are 3 headers
>>> attempting to include opt_linuxkpi.h in offending commits
>>> (at least). And LINUXKPI_DEBUG could be appropreate to be
>>> used for safeguard?
>>>
>>> /usr/src/sys/compat/linuxkpi/common/include/linux/spinlock.h
>>> /usr/src/sys/compat/linuxkpi/common/include/linux/kconfig.h
>>> /usr/src/sys/compat/linuxkpi/common/include/linux/kernel.h
>>
>> The sole problem here is that drm-kmod is handrolling stuff
>> instead of using the kmod,mk provided defines.
>
> I think pulling in something from /usr/obj/ for ports kmods
> itself is a bad idea, as it's NOT guaranteed to be existing
> on invoking `make` in ports directory when stable/16 and
> releng/16.0 are branched in the future for anyone NOT building
> base locally.

This is all normal "magic" for SRCS.

The file will get created (empty) in the obj dir if there is no KERNBUILDDIR set.

Given the obj dir for the ports build is set to be in the port's WRKSRC dir:

MAKE_ENV+=      MAKEOBJDIRPREFIX=${WRKSRC}/obj

From somehwere in there (I trimmed paths) you can see all these opt_*.h
got created and it has nothing to do with /usr/obj.

% pwd
/ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/obj/
% find . -name "opt*" -ls
79776217        0 -rw-r--r--    1 root wheel   0 Oct 12 10:48 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/dmabuf/opt_linuxkpi.h
79776218        0 -rw-r--r--    1 root wheel   0 Oct 12 10:48 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/dmabuf/opt_stack.h
79776219        0 -rw-r--r--    1 root wheel   0 Oct 12 10:48 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/dmabuf/opt_usb.h
79776220        8 -rw-r--r--    1 root wheel 115 Oct 12 10:48 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/dmabuf/opt_global.h
79776259        0 -rw-r--r--    1 root wheel   0 Oct 12 10:48 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/ttm/opt_linuxkpi.h
79776260        0 -rw-r--r--    1 root wheel   0 Oct 12 10:48 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/ttm/opt_stack.h
79776261        0 -rw-r--r--    1 root wheel   0 Oct 12 10:48 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/ttm/opt_usb.h
79776262        0 -rw-r--r--    1 root wheel   0 Oct 12 10:48 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/ttm/opt_drm.h
79776263        0 -rw-r--r--    1 root wheel   0 Oct 12 10:48 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/ttm/opt_vm.h
79776264        0 -rw-r--r--    1 root wheel   0 Oct 12 10:48 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/ttm/opt_syscons.h
79776265        8 -rw-r--r--    1 root wheel 115 Oct 12 10:48 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/ttm/opt_global.h
79776312        0 -rw-r--r--    1 root wheel   0 Oct 12 10:48 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/drm/opt_linuxkpi.h
79776313        0 -rw-r--r--    1 root wheel   0 Oct 12 10:48 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/drm/opt_stack.h
79776314        0 -rw-r--r--    1 root wheel   0 Oct 12 10:48 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/drm/opt_usb.h
79776315        0 -rw-r--r--    1 root wheel   0 Oct 12 10:48 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/drm/opt_teken.h
79776316        0 -rw-r--r--    1 root wheel   0 Oct 12 10:48 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/drm/opt_splash.h
79776317        0 -rw-r--r--    1 root wheel   0 Oct 12 10:48 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/drm/opt_syscons.h
79776318        0 -rw-r--r--    1 root wheel   0 Oct 12 10:48 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/drm/opt_drm.h
79776319        0 -rw-r--r--    1 root wheel   0 Oct 12 10:48 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/drm/opt_vm.h
79776320        8 -rw-r--r--    1 root wheel 115 Oct 12 10:48 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/drm/opt_global.h
79776514        0 -rw-r--r--    1 root wheel   0 Oct 12 10:49 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/amd/amdgpu/opt_linuxkpi.h
79776515        0 -rw-r--r--    1 root wheel   0 Oct 12 10:49 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/amd/amdgpu/opt_stack.h
79776516        0 -rw-r--r--    1 root wheel   0 Oct 12 10:49 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/amd/amdgpu/opt_usb.h
79776517        0 -rw-r--r--    1 root wheel   0 Oct 12 10:49 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/amd/amdgpu/opt_drm.h
79776518        0 -rw-r--r--    1 root wheel   0 Oct 12 10:49 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/amd/amdgpu/opt_vm.h
79776519        0 -rw-r--r--    1 root wheel   0 Oct 12 10:49 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/amd/amdgpu/opt_syscons.h
79776520        0 -rw-r--r--    1 root wheel   0 Oct 12 10:49 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/amd/amdgpu/opt_acpi.h
79776521        8 -rw-r--r--    1 root wheel 115 Oct 12 10:49 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/amd/amdgpu/opt_global.h
79778169        0 -rw-r--r--    1 root wheel   0 Oct 12 11:00 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/radeon/opt_acpi.h
79778173        0 -rw-r--r--    1 root wheel   0 Oct 12 11:00 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/radeon/opt_linuxkpi.h
79778174        0 -rw-r--r--    1 root wheel   0 Oct 12 11:00 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/radeon/opt_stack.h
79778175        0 -rw-r--r--    1 root wheel   0 Oct 12 11:00 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/radeon/opt_usb.h
79778176        0 -rw-r--r--    1 root wheel   0 Oct 12 11:00 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/radeon/opt_drm.h
79778177        0 -rw-r--r--    1 root wheel   0 Oct 12 11:00 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/radeon/opt_vm.h
79778178        0 -rw-r--r--    1 root wheel   0 Oct 12 11:00 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/radeon/opt_syscons.h
79778179        8 -rw-r--r--    1 root wheel 115 Oct 12 11:00 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/radeon/opt_global.h
79778402        0 -rw-r--r--    1 root wheel   0 Oct 12 11:02 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/i915/opt_linuxkpi.h
79778403        0 -rw-r--r--    1 root wheel   0 Oct 12 11:02 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/i915/opt_stack.h
79778404        0 -rw-r--r--    1 root wheel   0 Oct 12 11:02 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/i915/opt_usb.h
79778405        0 -rw-r--r--    1 root wheel   0 Oct 12 11:02 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/i915/opt_acpi.h
79778406        0 -rw-r--r--    1 root wheel   0 Oct 12 11:02 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/i915/opt_drm.h
79778407        0 -rw-r--r--    1 root wheel   0 Oct 12 11:02 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/i915/opt_syscons.h
79778408        8 -rw-r--r--    1 root wheel 115 Oct 12 11:02 ./ports/graphics/drm-612-kmod/work/drm-kmod-drm_v6.12.110_1/i915/opt_global.h


Whether or not this gives different options than a kernel build is a different
story but the same goes for stand-alone builds of modules within src/sys/modules;
just check sys/modules/pfsync/Makefile for an example.

But you will also find that the generated opt_global.h files do have values set
which come out of sys/conf/config.mk defaults.


>> Apply the changes from the pull request and what's in drm-kmod
>> master already and it'll build along with a kernel, as a standalone
>> git checkout or from ports.  If there's a 4th method, please let me
>> know.
>
> Putting attached file (made the change to fit for files/ without
> touching ports Makefile) into files/ directory of each
> graphics/drm-*-kmod may be easier to test.
>
> Confirmed causing no harm on build for graphics/drm-612-kmod
> and graphics/nvidia-drm-612-kmod-devel on stable/15 (there's no
> opt_linuxkpi.h under /usr/obj/). But unfortunately I don't
> have time to switch to main for now.

If you followed the github PR you will know you need another
change from drm-kmod master to also be dropped into files/
for the drm-kmod ports (and the nvidia ones).  I'd rather hope
someone can roll a new drm-kmod tag for the few branches.


> Maybe graphics/nvidia-drm-kmod/Makefile.common would need
> to have additional hack to pick the patch, as files/ in
> each graphics/nvidia-drm-*-kmod* are to be applied to
> NVIDIA parts only (DRM parts are extracted along"side").
>
>
>> As a plus (once cleanup gets done beyond initial repair), in the
>> future this kind of breakage shouldn't happen anymore and there's
>> going to be a single place to track SRCS+= and CFLAGS+= dependencies
>> needed to use LinuxKPI.
>>
>> So yes, please see https://github.com/freebsd/drm-kmod/pull/524

-- 
For there shall arise false Christs, and false prophets, and shall shew
great signs and wonders; insomuch that, if it were possible, they shall
deceive the very elect. Behold, I have told you before. [Mat. 24:24-25]