From: David Laight <David.Laight@ACULAB.COM>
To: 'Jens Axboe' <axboe@kernel.dk>,
yaozhenguo <yaozhenguo1@gmail.com>,
"oleg@redhat.comm" <oleg@redhat.comm>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"yaozhenguo@jd.com" <yaozhenguo@jd.com>
Subject: RE: [PATCH] task_work: return -EBUSY when adding same work
Date: Tue, 13 Jul 2021 10:41:26 +0000 [thread overview]
Message-ID: <3079d213543c4d398d96031e6da26c82@AcuMS.aculab.com> (raw)
In-Reply-To: <872612b5-b9c6-43aa-a167-1c204d0f1c5a@kernel.dk>
From: Jens Axboe
> Sent: 09 July 2021 15:18
...
> > */
> > 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);
>
> I don't think there's anything conceptually wrong with this patch, but
> it makes me think that you hit this condition. It's really a bug in the
> caller, of course, is a WARN_ON_ONCE() warranted here? And who was the
> caller?
How can the caller know that the task is on the queue?
There will be a race condition just before the work function
is called and/or just after it returns that the caller
can't detect.
The check needs to be done atomically with the code that
removes the work item from the list.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2021-07-13 10:41 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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=3079d213543c4d398d96031e6da26c82@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=axboe@kernel.dk \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@redhat.comm \
--cc=yaozhenguo1@gmail.com \
--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;
as well as URLs for NNTP newsgroup(s).