linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] task_work: return -EBUSY when adding same work
@ 2021-07-09 12:27 yaozhenguo
  2021-07-09 14:18 ` Jens Axboe
  0 siblings, 1 reply; 7+ messages in thread
From: yaozhenguo @ 2021-07-09 12:27 UTC (permalink / raw)
  To: axboe, oleg; +Cc: linux-kernel, yaozhenguo, yaozhenguo

when same work is added to task->task_works list one by one,
the list becomes endless loop. So return -EBUSY when this
situation happen.

Signed-off-by: yaozhenguo <yaozhenguo1@gmail.com>
---
 kernel/task_work.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/task_work.c b/kernel/task_work.c
index 1698fbe..5061ebf 100644
--- a/kernel/task_work.c
+++ b/kernel/task_work.c
@@ -27,7 +27,7 @@
  * list is LIFO.
  *
  * RETURNS:
- * 0 if succeeds or -ESRCH.
+ * 0 if succeeds or -ESRCH, -EBUSY.
  */
 int task_work_add(struct task_struct *task, struct callback_head *work,
 		  enum task_work_notify_mode notify)
@@ -41,6 +41,8 @@ int task_work_add(struct task_struct *task, struct callback_head *work,
 		head = READ_ONCE(task->task_works);
 		if (unlikely(head == &work_exited))
 			return -ESRCH;
+		if (unlikely(head == work))
+			return -EBUSY;
 		work->next = head;
 	} while (cmpxchg(&task->task_works, head, work) != head);
 
-- 
1.8.3.1


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

end of thread, other threads:[~2021-07-13 20:22 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-09 12:27 [PATCH] task_work: return -EBUSY when adding same work yaozhenguo
2021-07-09 14:18 ` Jens Axboe
     [not found]   ` <CA+WzARnFgohHZ=BhL4OaCagB_c1uB6a=Bv7vM_zRUJeANHksEg@mail.gmail.com>
2021-07-12  2:44     ` Jens Axboe
2021-07-12  3:45       ` zhenguo yao
2021-07-12  9:08       ` zhenguo yao
2021-07-13 10:41   ` David Laight
2021-07-13 20:22     ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).