🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: muc.lists.freebsd.emulation
Article #39

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

#39
From: bugzilla-noreply
Date: Mon, 26 Oct 2026 07:36
52 lines
4722 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=300062

--- Comment #4 from Michal Kilijanek <michal+freebsd@kilijanek.pl> ---
Two related latent problems in the same code (linux_pci.c, main 175595ba6).
Neither is triggered by an in-tree driver today, as far as I can tell.

(a) linuxkpi_pcim_iomap() (line 985) stores the result of
    linuxkpi_pci_iomap() (line 1000) via lkpi_set_pcim_iomap_devres(), and
    that helper always treats its argument as a struct resource *:

        dr->mmio_table[bar] = (void *)rman_get_bushandle(res);    /* line 980
*/
        dr->res_table[bar] = res;

    linuxkpi_pci_iomap_range() returns a struct resource * only when
    pdev->want_iomap_res is set (line 961); otherwise it returns
    rman_get_bushandle(res) + off.  For a pcim_iomap() user without
    want_iomap_res, rman_get_bushandle() would therefore read device MMIO
    as if it were a struct resource.  The only in-tree pcim_iomap() user,
    iwlwifi, calls linuxkpi_pcim_want_to_use_bus_functions(), and
    linuxkpi_pcim_iomap_regions() (used by mt76) calls _lkpi_pci_iomap()
    directly, which always returns the resource.  So this path is
    currently unused, but it is easy to hit with a new driver.

(b) lkpi_pcim_iomap_table_release() calls
    pci_iounmap(pdev, dr->mmio_table[bar]) (line 1097), i.e. with the
    bus-space handle.  With want_iomap_res set, linuxkpi_pci_iounmap()
    compares the argument against mmio->res, a struct resource *
    (lines 1020-1021), so it never matches and does nothing.  That is
    what the DTrace run above showed for iwlwifi:
    pci_iounmap(0xfffff800fd700000) with no release.

    Today (b) happens to be harmless and even protective.  For iwlwifi
    the region request and the iomap share one pdev->mmio entry (the
    "duplicate mapping" path in _lkpi_pci_iomap()), and with the fix
    attached here that entry is released exactly once by
    pci_release_region().  If (b) were fixed on its own, for example by
    passing res_table[bar] to pci_iounmap() or by also matching on the
    bus handle, BAR 0 would be released twice: once in pci_iounmap() and
    again in pci_release_region().  So fixing (b) needs ownership or
    reference counting for entries shared between pci(m)_request_region(s)
    and pci(m)_iomap().

-- 
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-4077-skUUx8WPIZ@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-4077@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.emulation
Subject: [Bug 300062] linuxkpi: pci_release_region() never removes pdev->mmio
 entries ("driver did not clean up; leaking mmio resources" on detach)
Date: Mon, 26 Oct 2026 07:36:10 +0000
Organization: Newsgate at muc.de e.V.
Sender: owner-freebsd-emulation@FreeBSD.org
Approved: news-admin@muc.de
Distribution: world
Message-ID: <bug-300062-4077-skUUx8WPIZ@https.bugs.freebsd.org/bugzilla/>
References: <bug-300062-4077@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="75301"; mail-complaints-to="news-admin@muc.de"
X-Original-To: emulation@mlmmj.nyi.freebsd.org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim;
	t=1793000170;
	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=50pc/f2g2KPubrHF/TDTBtRmTg5y8YyLZv/Wjd7Gi2w=;
	b=VkW23PJQDAYfUsxdlPGShL4tzeoyQXV0cs7PncTAQpSTky34eylQiwmGr0LGmEsyamc8Jm
	e3jM4hBYhhnxUT+BbbgiLmQYKdm1GmySsxKO+/k6TDWrA8D7MfpEb62vy/gE41ifmgOsCc
	rxYvZALyt4rTtF5RRNHN/kCsUaplHuJCMDf9SjOsBY0wLIya8gXlvA4ZS+QpxqduJGtdn1
	lO3fTGH5MKVRlJK8/EcYB7SwigHSfhQP0Q+Hr/ZTjsZfJ2GSa7BEI7MxKNTqFxv7gvbxCq
	usRYXfUwldwDB8+J034P5OhycyQog+kCFDsLpLhQDyGeq3KmCcOJXnczqtL1Kg==
X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f
In-Reply-To: <bug-300062-4077@https.bugs.freebsd.org/bugzilla/>
Auto-Submitted: auto-generated
Precedence: list
X-Newsgate-Id: f02c70b8849f+
X-No-Archive: Yes