Linux PCI subsystem development
 help / color / mirror / Atom feed
* [PATCH] PCI/IDE: Destroy host bridge IDAs on release
@ 2026-11-19  6:54 Xiaolei Wang
  2026-11-19  6:59 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Xiaolei Wang @ 2026-11-19  6:54 UTC (permalink / raw)
  To: bhelgaas, jic23, aik, djbw, wangxiaolei01, linus.walleij,
	bartosz.golaszewski
  Cc: linux-pci, linux-kernel

pci_ide_init_host_bridge() initializes two IDAs embedded in the host
bridge and reserves stream ID 255 in ide_stream_ids_ida, which allocates
an 128-byte IDA chunk.  pci_release_host_bridge_dev(), however, only frees
the resource lists and kfree()s the bridge, leaving both IDAs undestroyed.
The chunk becomes unreferenced once the bridge is gone.

This is observed at boot with CONFIG_DEBUG_KMEMLEAK:

  unreferenced object 0xffff000100d4df00 (size 128):
  comm "kworker/u16:3", pid 52, jiffies 4294892598
  backtrace (crc 6f8346e1):
    kmemleak_alloc+0x34/0x40
    __kmalloc_cache_noprof+0x3c0/0x56c
    ida_alloc_range+0x42c/0x554
    pci_ide_init_host_bridge+0x130/0x170
    pci_alloc_host_bridge+0x16c/0x1e0
    devm_pci_alloc_host_bridge+0x1c/0xb4

The 128 bytes is IDA_CHUNK_SIZE, and the trailing 0x80 in the object hex
dump is bit 63 of bitmap[3], i.e. the reserved stream ID 255.

The leak only exists in builds with CONFIG_PCI_IDE (selected by
CONFIG_PCI_TSM), so it is invisible on kernels without TEE-IO support.
Every host bridge that is freed leaks one chunk: a probe that fails or
defers, and a driver unbind, all go through the same release callback.

Add pci_ide_destroy_host_bridge() to destroy both IDAs and call it from
pci_release_host_bridge_dev() just before kfree(), symmetric with
pci_ide_destroy() which handles struct pci_dev.

Fixes: 079115370d00 ("PCI/IDE: Initialize an ID for all IDE streams")
Signed-off-by: Xiaolei Wang <wangxiaolei01@kaihong.com>
---
 drivers/pci/ide.c   | 6 ++++++
 drivers/pci/pci.h   | 2 ++
 drivers/pci/probe.c | 1 +
 3 files changed, 9 insertions(+)

diff --git a/drivers/pci/ide.c b/drivers/pci/ide.c
index beb67b8fb5c5..c0b64778d1ca 100644
--- a/drivers/pci/ide.c
+++ b/drivers/pci/ide.c
@@ -736,6 +736,12 @@ void pci_ide_init_host_bridge(struct pci_host_bridge *hb)
 	reserve_stream_id(hb, PCI_IDE_RESERVED_STREAM_ID);
 }
 
+void pci_ide_destroy_host_bridge(struct pci_host_bridge *hb)
+{
+	ida_destroy(&hb->ide_stream_ida);
+	ida_destroy(&hb->ide_stream_ids_ida);
+}
+
 static ssize_t available_secure_streams_show(struct device *dev,
 					     struct device_attribute *attr,
 					     char *buf)
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 77efa4c5c960..36af4585a5f7 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -755,11 +755,13 @@ static inline void pci_doe_sysfs_teardown(struct pci_dev *pdev) { }
 #ifdef CONFIG_PCI_IDE
 void pci_ide_init(struct pci_dev *dev);
 void pci_ide_init_host_bridge(struct pci_host_bridge *hb);
+void pci_ide_destroy_host_bridge(struct pci_host_bridge *hb);
 void pci_ide_destroy(struct pci_dev *dev);
 extern const struct attribute_group pci_ide_attr_group;
 #else
 static inline void pci_ide_init(struct pci_dev *dev) { }
 static inline void pci_ide_init_host_bridge(struct pci_host_bridge *hb) { }
+static inline void pci_ide_destroy_host_bridge(struct pci_host_bridge *hb) { }
 static inline void pci_ide_destroy(struct pci_dev *dev) { }
 #endif
 
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 9a178e0e5f7f..e22ceb5f42e7 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -641,6 +641,7 @@ static void pci_release_host_bridge_dev(struct device *dev)
 	if (bridge->domain_nr != PCI_DOMAIN_NR_NOT_SET)
 		pci_bus_release_emul_domain_nr(bridge->domain_nr);
 
+	pci_ide_destroy_host_bridge(bridge);
 	kfree(bridge);
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] PCI/IDE: Destroy host bridge IDAs on release
  2026-11-19  6:54 [PATCH] PCI/IDE: Destroy host bridge IDAs on release Xiaolei Wang
@ 2026-11-19  6:59 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-19  6:59 UTC (permalink / raw)
  To: Xiaolei Wang; +Cc: linux-pci

> pci_ide_init_host_bridge() initializes two IDAs embedded in the host
> bridge and reserves stream ID 255 in ide_stream_ids_ida, which allocates
> an 128-byte IDA chunk.  pci_release_host_bridge_dev(), however, only frees
> the resource lists and kfree()s the bridge, leaving both IDAs undestroyed.
> The chunk becomes unreferenced once the bridge is gone.
> 
> This is observed at boot with CONFIG_DEBUG_KMEMLEAK:
> 
>   unreferenced object 0xffff000100d4df00 (size 128):
>   comm "kworker/u16:3", pid 52, jiffies 4294892598
>   backtrace (crc 6f8346e1):
>     kmemleak_alloc+0x34/0x40
>     __kmalloc_cache_noprof+0x3c0/0x56c
>     ida_alloc_range+0x42c/0x554
>     pci_ide_init_host_bridge+0x130/0x170
> [ ... ]
> pci_release_host_bridge_dev() just before kfree(), symmetric with
> pci_ide_destroy() which handles struct pci_dev.
> 
> Fixes: 079115370d00 ("PCI/IDE: Initialize an ID for all IDE streams")
> Signed-off-by: Xiaolei Wang <wangxiaolei01@kaihong.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119065429.1824738-1-wangxiaolei01@kaihong.com?part=1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-19  6:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19  6:54 [PATCH] PCI/IDE: Destroy host bridge IDAs on release Xiaolei Wang
2026-11-19  6:59 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox