Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Nov 2025 16:17:27 +0200
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Friedrich Doku <friedrichdoku2030@u.northwestern.edu>
Cc:        Mark Johnston <markj@freebsd.org>, freebsd-hackers@freebsd.org
Subject:   Re: Kernel panic when using pmap_extract_and_hold() to check physical-to-virtual address mapping
Message-ID:  <aR8i98jTHsmlRFWB@kib.kiev.ua>
In-Reply-To: <CAD2_vGrnU47tsfaCVBJfSf1eMZH=xAxLdn4GVRhD3T71N7m-ww@mail.gmail.com>
References:  <CAD2_vGoBqWmt%2BLgtTDOsJO9T_a2PdqZHjusv6EQeCRUDExxm1Q@mail.gmail.com> <aR4JUjIZxR1dPh-m@nuc> <CAD2_vGrEWrM=hRJQUG8xeYhfBtLvvgKLtUrJ3moBag6hPi=xgw@mail.gmail.com> <CAD2_vGrnU47tsfaCVBJfSf1eMZH=xAxLdn4GVRhD3T71N7m-ww@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

On Thu, Nov 20, 2025 at 08:01:01AM -0600, Friedrich Doku wrote:
> Hello,
> 
> I wanted to follow up on the pmap issue I reported earlier where userspace
> process pmaps appeared to have corrupted/invalid fields (pm_l0,
> pm_l0_paddr=0x0, garbage values in pm_stage and pm_levels).
> 
> The issue was caused by building my kernel module outside the kernel source
> tree using a custom Makefile. This resulted in structure layout mismatches
> with my module seeing a different version or layout of struct pmap than
> what the kernel actually had, causing what appeared to be corrupted
> pointers but was actually just misaligned field access.
> 
> After moving my module to sys/modules/ and building it, the pmap structure
> is now correctly aligned and all fields have valid values and pmap_extract()
> works correctly. I understand that there is no good method for building
> modules outside the kernel on FreeBSD.

You should use config(8) to generate all opt_*.h files somewhere, then
use make with SYSDIR env var set to the location of your kernel
sources, and KERNBUILDDIR pointing to the directory where the kernel
was configured, i.e. where the opt_*.h files are kept.  E.g.
$ SYSDIR=<sources>/sys KERNBUILDDIR=somehwere/CONFIGNAME make



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?aR8i98jTHsmlRFWB>