From nobody Thu Nov 20 14:17:27 2025 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4dC0mj5mWdz6HS9w for ; Thu, 20 Nov 2025 14:17:41 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4dC0mj0sr5z3D52; Thu, 20 Nov 2025 14:17:41 +0000 (UTC) (envelope-from kostikbel@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: from tom.home (kib@localhost [127.0.0.1] (may be forged)) by kib.kiev.ua (8.18.1/8.18.1) with ESMTP id 5AKEHRYK065098; Thu, 20 Nov 2025 16:17:30 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 5AKEHRYK065098 Received: (from kostik@localhost) by tom.home (8.18.1/8.18.1/Submit) id 5AKEHRDh065097; Thu, 20 Nov 2025 16:17:27 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 20 Nov 2025 16:17:27 +0200 From: Konstantin Belousov To: Friedrich Doku Cc: Mark Johnston , freebsd-hackers@freebsd.org Subject: Re: Kernel panic when using pmap_extract_and_hold() to check physical-to-virtual address mapping Message-ID: References: List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Queue-Id: 4dC0mj0sr5z3D52 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=/sys KERNBUILDDIR=somehwere/CONFIGNAME make