From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Wander Lairson Costa <wander@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Thomas Gleixner <tglx@linutronix.de>,
"Eric W. Biederman" <ebiederm@xmission.com>,
Andy Lutomirski <luto@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Fenghua Yu <fenghua.yu@intel.com>,
Andrei Vagin <avagin@gmail.com>,
open list <linux-kernel@vger.kernel.org>,
Hu Chunyu <chuhu@redhat.com>, Oleg Nesterov <oleg@redhat.com>,
Valentin Schneider <vschneid@redhat.com>,
Paul McKenney <paulmck@kernel.org>
Subject: Re: [PATCH v4] kernel/fork: beware of __put_task_struct calling context
Date: Mon, 6 Feb 2023 15:56:55 +0100 [thread overview]
Message-ID: <Y+EVNz4ORkFSvTfP@linutronix.de> (raw)
In-Reply-To: <20230206130449.41360-1-wander@redhat.com>
On 2023-02-06 10:04:47 [-0300], Wander Lairson Costa wrote:
> Under PREEMPT_RT, __put_task_struct() indirectly acquires sleeping
> locks. Therefore, it can't be called from an non-preemptible context.
>
> One practical example is splat inside inactive_task_timer(), which is
> called in a interrupt context:
Do you have more?
The inactive_task_timer() is marked as HRTIMER_MODE_REL_HARD which means
in runs in hardirq-context. The author of commit
850377a875a48 ("sched/deadline: Ensure inactive_timer runs in hardirq context")
should have been aware of that.
We have on workaround of that put_task() in sched-switch. I wasn't aware
of this shortcoming. So either we have more problems or potential
problems or this is the only finding so far.
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 9f7fe3541897..532dd2ceb6a3 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -857,6 +857,29 @@ void __put_task_struct(struct task_struct *tsk)
…
> +void __put_task_struct(struct task_struct *tsk)
> +{
> + if (IS_ENABLED(CONFIG_PREEMPT_RT) && (!preemptible() || !in_task()))
Is it safe to use the rcu member in any case? If so why not use it
unconditionally?
> + /*
> + * under PREEMPT_RT, we can't call put_task_struct
> + * in atomic context because it will indirectly
> + * acquire sleeping locks.
> + *
> + * call_rcu() will schedule delayed_put_task_struct_rcu()
> + * to be called in process context.
> + */
> + call_rcu(&tsk->rcu, delayed_put_task_struct_rcu);
> + else
> + ___put_task_struct(tsk);
> +}
> EXPORT_SYMBOL_GPL(__put_task_struct);
>
> void __init __weak arch_task_cache_init(void) { }
Sebastian
next prev parent reply other threads:[~2023-02-06 14:57 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-06 13:04 [PATCH v4] kernel/fork: beware of __put_task_struct calling context Wander Lairson Costa
2023-02-06 14:56 ` Sebastian Andrzej Siewior [this message]
2023-02-06 15:27 ` Oleg Nesterov
2023-02-06 16:04 ` Sebastian Andrzej Siewior
2023-02-06 16:27 ` Oleg Nesterov
2023-02-10 16:48 ` Sebastian Andrzej Siewior
2023-02-06 18:36 ` Wander Lairson Costa
2023-02-06 18:34 ` Wander Lairson Costa
2023-02-06 18:32 ` Wander Lairson Costa
2023-02-07 1:09 ` Andrew Morton
2023-02-07 15:26 ` Wander Lairson Costa
2023-02-10 17:08 ` Sebastian Andrzej Siewior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y+EVNz4ORkFSvTfP@linutronix.de \
--to=bigeasy@linutronix.de \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=avagin@gmail.com \
--cc=chuhu@redhat.com \
--cc=ebiederm@xmission.com \
--cc=fenghua.yu@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=oleg@redhat.com \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=vschneid@redhat.com \
--cc=wander@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.