* [PATCH] genirq/test: Release fake irq descriptors after KUnit tests
@ 2026-11-30 10:44 Xiaolei Wang
2026-11-30 19:11 ` Brian Norris
0 siblings, 1 reply; 2+ messages in thread
From: Xiaolei Wang @ 2026-11-30 10:44 UTC (permalink / raw)
To: tglx, radu, briannorris, linux, davidgow, wangxiaolei01
Cc: linux-kernel, geert, kunit-dev
Each of the four irq_test_cases cases allocates a virtual interrupt via
irq_domain_alloc_descs() in irq_test_setup_fake_irq(), but only calls
free_irq() at the end. free_irq() releases the irqaction, not the
descriptor, so every run of the suite leaves 4 fake irq descriptors behind.
Each leaked descriptor keeps its debugfs node alive at
/sys/kernel/debug/irq/irqs/<N> ("chip: fake"), and the nodes accumulate
across repeated runs.
kmemleak does not report this because irq descriptors have a kobject/rcu
lifetime, but the descriptors are never returned to the irq_desc radix
tree and the debugfs entries are never removed.
Register a cleanup callback with kunit_add_action_or_reset() immediately
after the descriptor is allocated. On test exit, including an early abort
on a failed assertion, it frees any still-registered action and then
calls irq_free_descs() to release the descriptor. The _or_reset() variant
also cleans up when registering the action itself fails.
Fixes: 66067c3c8a1e ("genirq: Add kunit tests for depth counts")
Signed-off-by: Xiaolei Wang <wangxiaolei01@kaihong.com>
---
kernel/irq/irq_test.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/kernel/irq/irq_test.c b/kernel/irq/irq_test.c
index e2d31914b3c4..283fe32bf39a 100644
--- a/kernel/irq/irq_test.c
+++ b/kernel/irq/irq_test.c
@@ -41,14 +41,29 @@ static struct irq_chip fake_irq_chip = {
.flags = IRQCHIP_SKIP_SET_WAKE,
};
+static void irq_test_free_fake_irq(void *data)
+{
+ unsigned int virq = (unsigned long)data;
+ struct irq_desc *desc = irq_to_desc(virq);
+
+ if (desc->action)
+ free_irq(virq, NULL);
+
+ irq_free_descs(virq, 1);
+}
+
static int irq_test_setup_fake_irq(struct kunit *test, struct irq_affinity_desc *affd)
{
struct irq_desc *desc;
- int virq;
+ int virq, ret;
virq = irq_domain_alloc_descs(-1, 1, 0, NUMA_NO_NODE, affd);
KUNIT_ASSERT_GE(test, virq, 0);
+ ret = kunit_add_action_or_reset(test, irq_test_free_fake_irq,
+ (void *)(unsigned long)virq);
+ KUNIT_ASSERT_EQ(test, ret, 0);
+
irq_set_chip_and_handler(virq, &fake_irq_chip, handle_simple_irq);
desc = irq_to_desc(virq);
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] genirq/test: Release fake irq descriptors after KUnit tests
2026-11-30 10:44 [PATCH] genirq/test: Release fake irq descriptors after KUnit tests Xiaolei Wang
@ 2026-11-30 19:11 ` Brian Norris
0 siblings, 0 replies; 2+ messages in thread
From: Brian Norris @ 2026-11-30 19:11 UTC (permalink / raw)
To: Xiaolei Wang; +Cc: tglx, radu, linux, davidgow, linux-kernel, geert, kunit-dev
On Mon, Nov 30, 2026 at 10:44:26AM +0000, Xiaolei Wang wrote:
> Each of the four irq_test_cases cases allocates a virtual interrupt via
> irq_domain_alloc_descs() in irq_test_setup_fake_irq(), but only calls
> free_irq() at the end. free_irq() releases the irqaction, not the
> descriptor, so every run of the suite leaves 4 fake irq descriptors behind.
> Each leaked descriptor keeps its debugfs node alive at
> /sys/kernel/debug/irq/irqs/<N> ("chip: fake"), and the nodes accumulate
> across repeated runs.
>
> kmemleak does not report this because irq descriptors have a kobject/rcu
> lifetime, but the descriptors are never returned to the irq_desc radix
> tree and the debugfs entries are never removed.
>
> Register a cleanup callback with kunit_add_action_or_reset() immediately
> after the descriptor is allocated. On test exit, including an early abort
> on a failed assertion, it frees any still-registered action and then
> calls irq_free_descs() to release the descriptor. The _or_reset() variant
> also cleans up when registering the action itself fails.
>
> Fixes: 66067c3c8a1e ("genirq: Add kunit tests for depth counts")
> Signed-off-by: Xiaolei Wang <wangxiaolei01@kaihong.com>
Thanks for the fix. Looks fine to me:
Reviewed-by: Brian Norris <briannorris@chromium.org>
> ---
> kernel/irq/irq_test.c | 17 ++++++++++++++++-
> 1 file changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/irq/irq_test.c b/kernel/irq/irq_test.c
> index e2d31914b3c4..283fe32bf39a 100644
> --- a/kernel/irq/irq_test.c
> +++ b/kernel/irq/irq_test.c
> @@ -41,14 +41,29 @@ static struct irq_chip fake_irq_chip = {
> .flags = IRQCHIP_SKIP_SET_WAKE,
> };
>
> +static void irq_test_free_fake_irq(void *data)
> +{
> + unsigned int virq = (unsigned long)data;
> + struct irq_desc *desc = irq_to_desc(virq);
> +
> + if (desc->action)
> + free_irq(virq, NULL);
I wondered whether we should remove free_irq() from the tail of each
test, but I suppose it's not really logically the right responsibility
-- irq_test_setup_fake_irq() isn't really about assigning IRQ actions,
so its cleanup here is just done for safety, not because it's really the
best place to do it.
Regards,
Brian
> +
> + irq_free_descs(virq, 1);
> +}
> +
> static int irq_test_setup_fake_irq(struct kunit *test, struct irq_affinity_desc *affd)
> {
> struct irq_desc *desc;
> - int virq;
> + int virq, ret;
>
> virq = irq_domain_alloc_descs(-1, 1, 0, NUMA_NO_NODE, affd);
> KUNIT_ASSERT_GE(test, virq, 0);
>
> + ret = kunit_add_action_or_reset(test, irq_test_free_fake_irq,
> + (void *)(unsigned long)virq);
> + KUNIT_ASSERT_EQ(test, ret, 0);
> +
> irq_set_chip_and_handler(virq, &fake_irq_chip, handle_simple_irq);
>
> desc = irq_to_desc(virq);
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-30 19:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30 10:44 [PATCH] genirq/test: Release fake irq descriptors after KUnit tests Xiaolei Wang
2026-11-30 19:11 ` Brian Norris
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®