mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: yaozhenguo <yaozhenguo1@gmail.com>
To: axboe@kernel.dk, oleg@redhat.comm
Cc: linux-kernel@vger.kernel.org, yaozhenguo@jd.com,
	yaozhenguo <yaozhenguo1@gmail.com>
Subject: [PATCH] task_work: return -EBUSY when adding same work
Date: Fri,  9 Jul 2021 20:27:12 +0800	[thread overview]
Message-ID: <20210709122712.42844-1-yaozhenguo1@gmail.com> (raw)

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


             reply	other threads:[~2021-07-09 12:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-09 12:27 yaozhenguo [this message]
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

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=20210709122712.42844-1-yaozhenguo1@gmail.com \
    --to=yaozhenguo1@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.comm \
    --cc=yaozhenguo@jd.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 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®