Date: Wed, 19 Nov 2025 11:51:02 -0600 From: Friedrich Doku <friedrichdoku2030@u.northwestern.edu> To: freebsd-hackers@freebsd.org Subject: Kernel panic when using pmap_extract_and_hold() to check physical-to-virtual address mapping Message-ID: <CAD2_vGoBqWmt%2BLgtTDOsJO9T_a2PdqZHjusv6EQeCRUDExxm1Q@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
[-- Attachment #1 --] Hello, We want to see if a specific physical address is mapped into the virtual address space of a user space process. We are trying to do this from the kernel, but we are running into issues with trying to use pmap_extract, specifically we get the following kernel panic: panic: mtx_lock() of spin mutex (invalid) The pmap pointer comes from: 1. pfind(target_pid) - gets the process structure 2. p->p_vmspace - gets the vmspace from the process 3. vmspace_pmap(p->p_vmspace) - extracts the pmap from vmspace Then I'm iterating through vm_map entries with VM_MAP_ENTRY_FOREACH() and calling pmap_extract_and_hold(pmap, va, VM_PROT_READ) for each virtual address. The crash happens when calling pmap_extract_and_hold(). I suspect it's trying to acquire pmap locks that conflict with something. I'm trying to find which virtual address maps to a given physical address in a user space process. I'm doing this from a kernel module via sysctl handler. Best, Friedy [-- Attachment #2 --] <div dir="ltr"><div dir="ltr"><p>Hello,</p> <p>We want to see if a specific physical address is mapped into the virtual address space of a user space process. We are trying to do this from the kernel, but we are running into issues with trying to use pmap_extract, specifically we get the following kernel panic:</p> <pre><code>panic: mtx_lock() of spin mutex (invalid) </code></pre> <p>The pmap pointer comes from:</p> <ol><li>pfind(target_pid) - gets the process structure</li><li>p->p_vmspace - gets the vmspace from the process</li><li>vmspace_pmap(p->p_vmspace) - extracts the pmap from vmspace</li></ol> <p>Then I'm iterating through vm_map entries with VM_MAP_ENTRY_FOREACH() and calling pmap_extract_and_hold(pmap, va, VM_PROT_READ) for each virtual address.</p> <p>The crash happens when calling pmap_extract_and_hold(). I suspect it's trying to acquire pmap locks that conflict with something.</p> <p>I'm trying to find which virtual address maps to a given physical address in a user space process. I'm doing this from a kernel module via sysctl handler.</p> <p>Best, <br>Friedy</p></div><br></div>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAD2_vGoBqWmt%2BLgtTDOsJO9T_a2PdqZHjusv6EQeCRUDExxm1Q>
