From: Jens Axboe <[email protected]>
To: [email protected]
Cc: [email protected], Jens Axboe <[email protected]>,
Oleg Nesterov <[email protected]>,
Peter Zijlstra <[email protected]>
Subject: [PATCH 3/4] task_work: make exit_work externally visible
Date: Tue, 7 Apr 2020 10:02:57 -0600 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
If task_work has already been run on task exit, we don't always know
if it's safe to run again. Most call paths don't really care as they
can never hit this condition, but io_uring would like to call task
work from the fops->release() handler, which can get invoked off
do_exit() where we could have already run exit_task_work().
Cc: Oleg Nesterov <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
---
include/linux/task_work.h | 2 ++
kernel/task_work.c | 8 ++++----
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/include/linux/task_work.h b/include/linux/task_work.h
index 088538590e65..893c916d8677 100644
--- a/include/linux/task_work.h
+++ b/include/linux/task_work.h
@@ -7,6 +7,8 @@
typedef void (*task_work_func_t)(struct callback_head *);
+extern struct callback_head task_work_exited;
+
static inline void
init_task_work(struct callback_head *twork, task_work_func_t func)
{
diff --git a/kernel/task_work.c b/kernel/task_work.c
index 9620333423a3..d6a8b4ab4858 100644
--- a/kernel/task_work.c
+++ b/kernel/task_work.c
@@ -3,7 +3,7 @@
#include <linux/task_work.h>
#include <linux/tracehook.h>
-static struct callback_head work_exited; /* all we need is ->next == NULL */
+struct callback_head task_work_exited = { };
/**
* task_work_add - ask the @task to execute @work->func()
@@ -31,7 +31,7 @@ task_work_add(struct task_struct *task, struct callback_head *work, bool notify)
do {
head = READ_ONCE(task->task_works);
- if (unlikely(head == &work_exited))
+ if (unlikely(head == &task_work_exited))
return -ESRCH;
work->next = head;
} while (cmpxchg(&task->task_works, head, work) != head);
@@ -95,14 +95,14 @@ void __task_work_run(void)
for (;;) {
/*
* work->func() can do task_work_add(), do not set
- * work_exited unless the list is empty.
+ * task_work_exited unless the list is empty.
*/
do {
head = NULL;
work = READ_ONCE(task->task_works);
if (!work) {
if (task->flags & PF_EXITING)
- head = &work_exited;
+ head = &task_work_exited;
else
break;
}
--
2.26.0
next prev parent reply other threads:[~2020-04-07 16:03 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-07 16:02 [PATCHSET v2] io_uring and task_work interactions Jens Axboe
2020-04-07 16:02 ` [PATCH 1/4] task_work: add task_work_pending() helper Jens Axboe
2020-04-07 17:52 ` Jann Horn
2020-04-07 16:02 ` [PATCH 2/4] task_work: kill current->task_works checking in callers Jens Axboe
2020-04-07 16:02 ` Jens Axboe [this message]
2020-04-07 16:02 ` [PATCH 4/4] io_uring: flush task work before waiting for ring exit Jens Axboe
2020-04-07 16:24 ` Oleg Nesterov
2020-04-07 16:38 ` Oleg Nesterov
2020-04-07 20:30 ` Jens Axboe
2020-04-07 20:39 ` Jens Axboe
2020-04-08 18:40 ` Oleg Nesterov
2020-04-08 18:48 ` Jens Axboe
2020-04-08 19:06 ` Jens Axboe
2020-04-08 20:17 ` Oleg Nesterov
2020-04-08 20:25 ` Jens Axboe
2020-04-08 21:19 ` Jens Axboe
2020-04-09 18:50 ` Oleg Nesterov
2020-04-10 0:29 ` Jens Axboe
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 \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox