Thread View: muc.lists.freebsd.bugs
5 messages
5 total messages
Started by bugzilla-noreply
Sun, 25 Oct 2026 22:25
[Bug 300062] linuxkpi: pci_release_region() never removes pdev->mmio entries ("driver did not clean up; leaking mmio resources" ...
Author: bugzilla-noreply
Date: Sun, 25 Oct 2026 22:25
Date: Sun, 25 Oct 2026 22:25
108 lines
6353 bytes
6353 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300062
Bug ID: 300062
Summary: linuxkpi: pci_release_region() never removes
pdev->mmio entries ("driver did not clean up; leaking
mmio resources" on detach)
Product: Base System
Version: CURRENT
Hardware: amd64
OS: Any
Status: New
Severity: Affects Some People
Priority: ---
Component: kern
Assignee: bugs@FreeBSD.org
Reporter: michal+freebsd@kilijanek.pl
CC: bz@FreeBSD.org
------------------------------------------------------------------------
Description
------------------------------------------------------------------------
Every detach of iwlwifi (AX210, 8086:2725) prints:
iwlwifi0: lkpi_pci_dev_release_common: driver did not clean up; leaking mmio
resources
iwlwifi0: detached
The message appeared 4 times out of 4 when running `devctl detach iwlwifi0`
(re-attach works). iwlwifi uses the managed API
(sys/contrib/dev/iwlwifi/pcie/drv.c):
pcim_enable_device(pdev);
pcim_request_all_regions(pdev, DRV_NAME);
hw_base = pcim_iomap(pdev, 0, 0);
so it is not expected to release the regions itself.
------------------------------------------------------------------------
Suspected cause (code reading, main 175595ba6)
------------------------------------------------------------------------
sys/compat/linuxkpi/common/src/linux_pci.c:
lkpi_pci_request_region() (line 1168) records each requested BAR in
pdev->mmio (TAILQ_INSERT_TAIL at line 1216) with mmio->res = the
struct resource *. On release, lkpi_pci_devres_release() calls
pci_release_region() for each BAR, but linuxkpi_pci_release_region()
(line 1262) matches the list entry like this (line 1285):
TAILQ_FOREACH_SAFE(mmio, &pdev->mmio, next, p) {
if (rle->res != (void *)rman_get_bushandle(mmio->res))
continue;
TAILQ_REMOVE(&pdev->mmio, mmio, next);
free(mmio, M_DEVBUF);
}
rle->res is a struct resource * while rman_get_bushandle() returns the
bus-space handle (the mapping address), so the condition is (practically)
always true and the entry is never removed. The resource itself is then
released with bus_release_resource(), leaving a stale pci_mmio_region
that still points at it, and lkpi_pci_dev_release_common() (line 391)
warns about the non-empty list on detach.
Besides the memory leak and the warning, a stale entry referencing a
released resource could be dereferenced by a later
linuxkpi_pci_iounmap() walk on the same pdev (it calls
rman_get_bushandle(mmio->res) on every entry). I have not observed a
crash from that.
------------------------------------------------------------------------
Proposed fix (untested)
------------------------------------------------------------------------
--- a/sys/compat/linuxkpi/common/src/linux_pci.c
+++ b/sys/compat/linuxkpi/common/src/linux_pci.c
@@ linuxkpi_pci_release_region(struct pci_dev *pdev, int bar)
TAILQ_FOREACH_SAFE(mmio, &pdev->mmio, next, p) {
- if (rle->res != (void *)rman_get_bushandle(mmio->res))
+ if (rle->res != mmio->res)
continue;
TAILQ_REMOVE(&pdev->mmio, mmio, next);
free(mmio, M_DEVBUF);
}
To verify: devctl detach/attach of an iwlwifi (or any pcim_request_*
user) should no longer print "leaking mmio resources".
------------------------------------------------------------------------
Environment
------------------------------------------------------------------------
Machine: Lenovo ThinkPad T14 Gen 2a (20XLS34M00)
Wi-Fi: Intel AX210, pci 8086:2725 sub 8086:0024, iwlwifi, fw 89
Kernel: 16.0-CURRENT built from main (GENERIC + platform devices, plus
an unrelated LinuxKPI NAPI change, freebsd-src PR #2497); detach
was not exercised on the packaged GENERIC kernel
Repro: service netif stop wlan0; devctl detach iwlwifi0
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 300062] linuxkpi: pci_release_region() never removes pdev->mmio entries ("driver did not clean up; leaking mmio resources" ...
Author: bugzilla-noreply
Date: Sun, 25 Oct 2026 22:44
Date: Sun, 25 Oct 2026 22:44
16 lines
2673 bytes
2673 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300062 --- Comment #1 from Michal Kilijanek <michal+freebsd@kilijanek.pl> --- Created attachment 276479 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=276479&action=edit linuxkpi: match the resource in pci_release_region() (tested) -- You are receiving this mail because: You are the assignee for the bug. -- Posted automagically by a mail2news gateway at muc.de e.V. Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 300062] linuxkpi: pci_release_region() never removes pdev->mmio entries ("driver did not clean up; leaking mmio resources" ...
Author: bugzilla-noreply
Date: Sun, 25 Oct 2026 22:44
Date: Sun, 25 Oct 2026 22:44
53 lines
4522 bytes
4522 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300062
--- Comment #2 from Michal Kilijanek <michal+freebsd@kilijanek.pl> ---
Follow-up: runtime analysis and test of the proposed fix.
DTrace on iwlwifi detach (devctl detach), before the fix:
lkpi_pcim_iomap_table_release()
pci_iounmap(res=0xfffff800fd700000)
lkpi_pci_devres_release()
pci_release_region(bar=0)
compare loop: rman_get_bushandle(mmio->res) -> 0xfffff800fd700000
bus_release_resource_old(res=0xfffff80001a53580)
release_common: pdev->mmio first entry res=0xfffff80001a53580 rid=0x10
-> "driver did not clean up; leaking mmio resources"
Correction to my description: the BAR resource itself IS released, exactly
once, by pci_release_region(). What leaks is only the pci_mmio_region list
entry, which is left pointing at the already released resource.
At attach, pcim_request_all_regions() allocates BAR 0 (0xfffff80001a53580)
and the following pcim_iomap(pdev, 0) returns the same entry (the
"duplicate mapping" path in _lkpi_pci_iomap()). So there is one entry
shared by the region request and the iomap.
A related latent issue: pci_iounmap() is called with the mapped address
(0xfffff800fd700000), but with want_iomap_res set (iwlwifi calls
linuxkpi_pcim_want_to_use_bus_functions()) it compares that address against
mmio->res (a struct resource *), so it never matches and is a no-op. Today
that is what keeps the shared resource from being released twice. If only
iounmap were "fixed" to match, pci_iounmap() and pci_release_region() would
both release BAR 0.
With the attached one-line fix (compare rle->res with mmio->res), on main
175595ba6 with GENERIC + the LinuxKPI NAPI change from freebsd-src PR #2497,
INVARIANTS and WITNESS enabled:
pci_release_region(bar=0)
bus_release_resource_old(res=0xfffff80001a4b580) <- once
release_common: pdev->mmio empty
- 3x `devctl detach iwlwifi0` / `devctl attach pci0:3:0:0`, each followed by
re-association with traffic verified over wlan0: 0 "leaking mmio
resources" messages (previously one per detach), no panic, no KASSERT.
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 300062] linuxkpi: pci_release_region() never removes pdev->mmio entries ("driver did not clean up; leaking mmio resources" ...
Author: bugzilla-noreply
Date: Sun, 25 Oct 2026 22:52
Date: Sun, 25 Oct 2026 22:52
41 lines
4056 bytes
4056 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300062
--- Comment #3 from Michal Kilijanek <michal+freebsd@kilijanek.pl> ---
Kernel used for testing, to rule out local modifications:
Packaged kernel (pkgbase FreeBSD-kernel-generic 16.snap20261024185836,
GENERIC main-n290312-91bff7d7ed46): the AX210 firmware assert on ADDBA
(bug 300064) and the AUTH->AUTH ENOTRECOVERABLE wedge (bug 300063) were
first seen on this unmodified kernel.
Custom kernel "T14AMD", used for the reproductions and tests:
- upstream main 175595ba6 (2026-10-25), with two local LinuxKPI commits:
linuxkpi: do not sleep forever on a stale NAPI IS_SCHEDULED
(linux_netdev.c only; freebsd-src PR #2497)
linuxkpi: match the resource in pci_release_region()
(linux_pci.c only; the fix proposed in bug 300062)
Nothing else in sys/ differs from upstream.
- kernel config = "include GENERIC" plus platform devices only, with no
nodevice/nooptions:
device acpi_ibm acpi_wmi amdsmn amdtemp intpm smbus smb ig4 iicbus iic
gpio amdgpio iichid hconf hms hmt rtsx tpm cuse
options NETGRAPH NETGRAPH_SOCKET
NETGRAPH_BLUETOOTH{,_HCI,_L2CAP,_SOCKET,_UBT}
makeoptions MODULES_EXTRA+="mt76/core mt76/mt7921" (not loaded; the
Wi-Fi card is the Intel AX210)
None of these touch net80211, LinuxKPI or iwlwifi.
- iwlwifi and the firmware are the stock if_iwlwifi.ko from this build and
wifi-firmware-iwlwifi-kmod-ax210-20260410.
The mmio leak (bug 300062) was only observed on T14AMD, because the card
was never detached on the packaged kernel. At that point the kernel
contained only the NAPI commit, which does not touch linux_pci.c.
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
[Bug 300062] linuxkpi: pci_release_region() never removes pdev->mmio entries ("driver did not clean up; leaking mmio resources" ...
Author: bugzilla-noreply
Date: Mon, 26 Oct 2026 00:14
Date: Mon, 26 Oct 2026 00:14
16 lines
2679 bytes
2679 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300062
Mark Linimon <linimon@FreeBSD.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|bugs@FreeBSD.org |emulation@FreeBSD.org
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads