FAILED: patch "[PATCH] genirq: Defer kfree(irqaction) until irq_thread_dtor()" failed to apply to 6.1-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 6.1-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.1.y
git checkout FETCH_HEAD
git cherry-pick -x d04adff6860587e843948b0c31174f8ae11b8dfe
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026110452-liability-uncooked-f75f@gregkh' --subject-prefix 'PATCH 6.1.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From d04adff6860587e843948b0c31174f8ae11b8dfe Mon Sep 17 00:00:00 2001
From: Richard Patel <[email protected]>
Date: Fri, 9 Oct 2026 14:58:41 +0000
Subject: [PATCH] genirq: Defer kfree(irqaction) until irq_thread_dtor()
finishes
When an interrupt thread exits abnormally via do_exit() (e.g. the interrupt handler oopses) without returning from irq_thread(), a concurrent call to free_irq() could free the irqaction before the irq_thread_dtor() exit task work runs.
irq thread (oopsed) free_irq()
------------------- ----------
do_exit()
exit_mm()
complete_vfork_done() -------> kthread_stop() returns
exit_files() ... kfree(action)
exit_task_work()
irq_thread_dtor()
action->... <- use-after-freeTrack the pending exit work with the IRQTF_EXIT_WORK thread flag, and have __free_irq() wait for the bit to clear before kfree().
irq_thread_dtor() only runs on irq_thread abnormal exit. If that dtor also faults, free_irq() will hang indefinitely, but double IRQ thread faults require a reboot anyways.
[ tglx: Add missing include ]
kernel/irq/internals.h +2 -0
@@ -36,6 +36,7 @@ extern struct irqaction chained_action;* IRQTF_AFFINITY - irq thread is requested to adjust affinity * IRQTF_FORCED_THREAD - irq action is force threaded * IRQTF_READY - signals that irq thread is ready +* IRQTF_EXIT_WORK - irq thread exit task_work is pending */ enum {IRQTF_RUNTHREAD ,
@@ -43,6 +44,7 @@ enum {IRQTF_AFFINITY ,IRQTF_FORCED_THREAD ,IRQTF_READY , + IRQTF_EXIT_WORK, };/*
kernel/irq/manage.c +20 -6
@@ -21,6 +21,7 @@#include <linux/sched/isolation.h> #include <uapi/linux/sched/types.h> #include <linux/task_work.h> +#include <linux/wait_bit.h> #include "internals.h"
@@ -1176,17 +1177,14 @@ void wake_threads_waitq(struct irq_desc *desc)wake_up (&desc->wait_for_threads); } -static void irq_thread_dtor (struct callback_head *unused) +static void __irq_thread_dtor (struct irqaction *action) {struct task_struct *tsk = current;struct irq_desc *desc; -struct irqaction *action;if (WARN_ON_ONCE (!(current->flags &PF_EXITING )))return ; - action =kthread_data (tsk); -pr_err ("exiting task \"%s\" (%d) is an active IRQ thread (irq %d)\n" , tsk->comm, tsk->pid, action->irq);
@@ -1203,6 +1201,14 @@ static void irq_thread_dtor(struct callback_head *unused)irq_finalize_oneshot (desc, action); } +static void irq_thread_dtor (struct callback_head *unused) +{ +struct irqaction *action =kthread_data (current); + +__irq_thread_dtor (action); +clear_and_wake_up_bit (IRQTF_EXIT_WORK , &action->thread_flags); +} +static void irq_wake_secondary (struct irq_desc *desc,struct irqaction *action) {struct irqaction *secondary = action->secondary;
@@ -1263,6 +1269,7 @@ static int irq_thread(void *data)else handler_fn = irq_thread_fn; +set_bit (IRQTF_EXIT_WORK , &action->thread_flags);init_task_work (&on_exit_work, irq_thread_dtor);task_work_add (current, &on_exit_work,TWA_NONE );
@@ -1283,6 +1290,7 @@ static int irq_thread(void *data)* oneshot mask bit can be set. */ task_work_cancel_func (current, irq_thread_dtor); +clear_and_wake_up_bit (IRQTF_EXIT_WORK , &action->thread_flags);return 0 ; }
@@ -1853,6 +1861,12 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)return ret; } +static void irq_stop_thread (struct irqaction *action) +{ +kthread_stop_put (action->thread); +wait_on_bit (&action->thread_flags,IRQTF_EXIT_WORK ,TASK_UNINTERRUPTIBLE ); +} +/* * Internal function to unregister an irqaction - used to free * regular and special interrupts that are part of the architecture.
@@ -1958,9 +1972,9 @@ static struct irqaction *__free_irq(struct irq_desc *desc, void *dev_id)* the same bit to a newly requested action. */ if (action->thread) { -kthread_stop_put (action->thread); +irq_stop_thread (action);if (action->secondary && action->secondary->thread) -kthread_stop_put (action->secondary->thread); +irq_stop_thread (action->secondary); }/* Last action releases resources */
Sasha Levin
maintainerPATCH 1/1 genirq: Defer kfree(irqaction) until irq_thread_dtor() finishes
From: Richard Patel <[email protected]>
[ Upstream commit d04adff6860587e843948b0c31174f8ae11b8dfe ]
When an interrupt thread exits abnormally via do_exit() (e.g. the interrupt handler oopses) without returning from irq_thread(), a concurrent call to free_irq() could free the irqaction before the irq_thread_dtor() exit task work runs.
irq thread (oopsed) free_irq()
------------------- ----------
do_exit()
exit_mm()
complete_vfork_done() -------> kthread_stop() returns
exit_files() ... kfree(action)
exit_task_work()
irq_thread_dtor()
action->... <- use-after-freeTrack the pending exit work with the IRQTF_EXIT_WORK thread flag, and have __free_irq() wait for the bit to clear before kfree().
irq_thread_dtor() only runs on irq_thread abnormal exit. If that dtor also faults, free_irq() will hang indefinitely, but double IRQ thread faults require a reboot anyways.
[ tglx: Add missing include ]
--- kernel/irq/internals.h | 2 ++ kernel/irq/manage.c | 32 ++++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 10 deletions(-)
kernel/irq/internals.h +2 -0
@@ -30,6 +30,7 @@ extern struct irqaction chained_action;* IRQTF_AFFINITY - irq thread is requested to adjust affinity * IRQTF_FORCED_THREAD - irq action is force threaded * IRQTF_READY - signals that irq thread is ready +* IRQTF_EXIT_WORK - irq thread exit task_work is pending */ enum {IRQTF_RUNTHREAD ,
@@ -37,6 +38,7 @@ enum {IRQTF_AFFINITY ,IRQTF_FORCED_THREAD ,IRQTF_READY , + IRQTF_EXIT_WORK, };/*
kernel/irq/manage.c +22 -10
@@ -21,6 +21,7 @@#include <linux/sched/isolation.h> #include <uapi/linux/sched/types.h> #include <linux/task_work.h> +#include <linux/wait_bit.h> #include "internals.h"
@@ -1216,17 +1217,14 @@ static void wake_threads_waitq(struct irq_desc *desc)wake_up (&desc->wait_for_threads); } -static void irq_thread_dtor (struct callback_head *unused) +static void __irq_thread_dtor (struct irqaction *action) {struct task_struct *tsk = current;struct irq_desc *desc; -struct irqaction *action;if (WARN_ON_ONCE (!(current->flags &PF_EXITING )))return ; - action =kthread_data (tsk); -pr_err ("exiting task \"%s\" (%d) is an active IRQ thread (irq %d)\n" , tsk->comm, tsk->pid, action->irq);
@@ -1243,6 +1241,14 @@ static void irq_thread_dtor(struct callback_head *unused)irq_finalize_oneshot (desc, action); } +static void irq_thread_dtor (struct callback_head *unused) +{ +struct irqaction *action =kthread_data (current); + +__irq_thread_dtor (action); +clear_and_wake_up_bit (IRQTF_EXIT_WORK , &action->thread_flags); +} +static void irq_wake_secondary (struct irq_desc *desc,struct irqaction *action) {struct irqaction *secondary = action->secondary;
@@ -1301,6 +1307,7 @@ static int irq_thread(void *data)else handler_fn = irq_thread_fn; +set_bit (IRQTF_EXIT_WORK , &action->thread_flags);init_task_work (&on_exit_work, irq_thread_dtor);task_work_add (current, &on_exit_work,TWA_NONE );
@@ -1325,6 +1332,7 @@ static int irq_thread(void *data)* oneshot mask bit can be set. */ task_work_cancel_func (current, irq_thread_dtor); +clear_and_wake_up_bit (IRQTF_EXIT_WORK , &action->thread_flags);return 0 ; }
@@ -1859,6 +1867,13 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)return ret; } +static void irq_stop_thread (struct irqaction *action) +{ +kthread_stop (action->thread); +put_task_struct (action->thread); +wait_on_bit (&action->thread_flags,IRQTF_EXIT_WORK ,TASK_UNINTERRUPTIBLE ); +} +/* * Internal function to unregister an irqaction - used to free * regular and special interrupts that are part of the architecture.
@@ -1963,12 +1978,9 @@ static struct irqaction *__free_irq(struct irq_desc *desc, void *dev_id)* the same bit to a newly requested action. */ if (action->thread) { -kthread_stop (action->thread); -put_task_struct (action->thread); -if (action->secondary && action->secondary->thread) { -kthread_stop (action->secondary->thread); -put_task_struct (action->secondary->thread); - } +irq_stop_thread (action); +if (action->secondary && action->secondary->thread) +irq_stop_thread (action->secondary); }/* Last action releases resources */
Signature · 1 line
2.53.0