🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: muc.lists.freebsd.bugs
Article #244

[Bug 300062] linuxkpi: pci_release_region() never removes pdev->mmio entries ("driver did not clean up; leaking mmio resources" ...

#244
From: bugzilla-noreply
Date: Sun, 25 Oct 2026 22:44
53 lines
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
Technical Details
Message-ID: <bug-300062-227-ZC01mrADpl@https.bugs.freebsd.org/bugzilla/>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.muc.de!.POSTED.news.muc.de!not-for-mail
References: <bug-300062-227@https.bugs.freebsd.org/bugzilla/>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.muc.de!.POSTED.news.muc.de!not-for-mail
From: bugzilla-noreply@freebsd.org
Newsgroups: muc.lists.freebsd.bugs
Subject: [Bug 300062] linuxkpi: pci_release_region() never removes pdev->mmio
 entries ("driver did not clean up; leaking mmio resources" on detach)
Date: Sun, 25 Oct 2026 22:44:14 +0000
Organization: Newsgate at muc.de e.V.
Sender: owner-freebsd-bugs@FreeBSD.org
Approved: news-admin@muc.de
Distribution: world
Message-ID: <bug-300062-227-ZC01mrADpl@https.bugs.freebsd.org/bugzilla/>
References: <bug-300062-227@https.bugs.freebsd.org/bugzilla/>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2";
	logging-data="75916"; mail-complaints-to="news-admin@muc.de"
X-Original-To: bugs@mlmmj.nyi.freebsd.org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1792968254;
	h=from:from:reply-to:subject:subject:date:date:message-id:message-id:
	 to:to:cc:mime-version:mime-version:content-type:content-type:
	 content-transfer-encoding:content-transfer-encoding:
	 in-reply-to:in-reply-to:references:references;
	bh=j5MJ2Hub5WkeoH6f5jVTlho/nQ37NJv6k42XOM8qDXc=;
	b=WiEmYoaCROXihKYKKHV5Q4Xyu8xgduRgqucg9lhu18iMplLQCYZ6kcVlP2u9d05lNlaGRy
	s0BsmJf2qwnV67JHSr6G77s/hH32hj+9Uqx4kJBPjK8drYaEhEKuFJgApYIoqLTWKi85Fs
	SKejnrakvmd4u+RxXX3zm+nmNV9sX8FI6zeJgP3pz8rMZzPut/3pe46qJve2ppRLzw9KLJ
	FcprkDKueaEhn8Ql2vD4kmNO72sn/5K72DysA4wXOBZukTA0LDyB4qmvN9pW1d0Wveskqf
	IGmwWGuwmQ7k/ZpxlpLDdwVza4+RgvUgH+HdT2y/cZe21GeP69BePtXw2UbIAg==
X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f
In-Reply-To: <bug-300062-227@https.bugs.freebsd.org/bugzilla/>
Auto-Submitted: auto-generated
Precedence: list
X-Newsgate-Id: f02c70b8849f+
X-No-Archive: Yes