public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: liguang <lig.fnst@cn.fujitsu.com>
Cc: viro@zeniv.linux.org.uk, edumazet@google.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] task_work: make FIFO task_work list
Date: Thu, 14 Mar 2013 15:40:19 +0100	[thread overview]
Message-ID: <20130314144019.GA16136@redhat.com> (raw)
In-Reply-To: <1363247865-3531-1-git-send-email-lig.fnst@cn.fujitsu.com>

On 03/14, liguang wrote:
>
> Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>

Changelog please...

> ---
>  kernel/task_work.c |   15 +++------------
>  1 files changed, 3 insertions(+), 12 deletions(-)
> 
> diff --git a/kernel/task_work.c b/kernel/task_work.c
> index 65bd3c9..0bf4258 100644
> --- a/kernel/task_work.c
> +++ b/kernel/task_work.c
> @@ -13,11 +13,12 @@ task_work_add(struct task_struct *task, struct callback_head *work, bool notify)
>  		head = ACCESS_ONCE(task->task_works);
>  		if (unlikely(head == &work_exited))
>  			return -ESRCH;
> -		work->next = head;
> -	} while (cmpxchg(&task->task_works, head, work) != head);
> +		head = head->next;
> +	} while (cmpxchg(&head, NULL, work) == head);

I simply can't understand how this can work... The patch assumes
that head->next == NULL after head = head->next, why? And then
compares the result with head and succeeds if not equal.

Could you please explain how it was supposed to work? If nothing
else, Suppose we have task->task_works -> W1 -> W2 -> W3. How this
code can add W4 after W3?

And cmpxchg(&head) should be cmpxchg(&head->next)....



Anyway, whatever I missed this is racy.

	head = head->next;

nothing protects "head" after this. Say, it can be task_work_cancel'ed
and freed. So,

	 cmpxchg(&head, ...)

can modify the freed and reused memory.

Oleg.


  parent reply	other threads:[~2013-03-14 14:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-14  7:57 [PATCH 1/2] task_work: make FIFO task_work list liguang
2013-03-14  7:57 ` [PATCH 2/2] task_work: check callback if it's NULL liguang
2013-03-14 14:43   ` Oleg Nesterov
2013-03-15  0:20     ` li guang
2013-03-15  1:01       ` Li Zefan
2013-03-15  1:26         ` li guang
2013-03-15  1:43           ` Li Zefan
2013-03-15  2:29             ` li guang
2013-03-14 14:40 ` Oleg Nesterov [this message]
2013-03-15  0:16   ` [PATCH 1/2] task_work: make FIFO task_work list li guang
2013-03-15 14:34     ` Oleg Nesterov

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=20130314144019.GA16136@redhat.com \
    --to=oleg@redhat.com \
    --cc=edumazet@google.com \
    --cc=lig.fnst@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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