From: "George Spelvin" <linux@horizon.com>
To: dave@stgolabs.net, linux@horizon.com
Cc: bigeasy@linutronix.de, clm@fb.com, linux-kernel@vger.kernel.org,
manfred@colorfullife.com, mingo@redhat.com, peterz@infradead.org,
rostedt@goodmis.org, tglx@linutronix.de,
torvalds@linux-foundation.org
Subject: Re: [PATCH 3/3] ipc/mqueue: lockless pipelined wakeups
Date: 4 May 2015 20:37:13 -0400 [thread overview]
Message-ID: <20150505003713.20276.qmail@ns.horizon.com> (raw)
In-Reply-To: <1430526956.1940.8.camel@stgolabs.net>
> You are not wrong, but I'd rather leave the comment as is, as it will
> vary from user to user. The comments in the sched wake_q bits are
> already pretty clear, and if users cannot see the need for holding
> reference and the task disappearing on their own they have no business
> using wake_q. Furthermore, I think my comment serves better in mqueues
> as the need for it isn't immediately obvious.
Okay, but the comment is still rather awkward and hard-to-follow English.
How about:
/*
* Rely on the implicit cmpxchg barrier from wake_q_add to
* ensure that updating receiver->state is the last write
* operation. Once set, the receiver can continue, and if we
* hadn't placed it on the wake_q (which takes a reference to
* the task), any later use might cause a use-after-free
* condition.
*/
Part of the confusion is that there are two different ordering conditions
that wake_q_add is involved in, and the comment above (even my version)
isn't good about explaining the distinction:
1) It, itself, must come before the receiver->state update, because
after that, the receiver may run (and possibly exit).
2) It serves as a write barrier for all the other state writes above.
If I wanted to be clearer, I'd have to do more extensive edits:
/*
* wake_q_add must come before updating receiver->state, since
* that write lets the receiver continue (and possibly exit).
* The reference count from the wake_q prevents use-after-free.
*
* The cmpxchg inside wake_q_add also serves as a write barrier
* for all the other state updates that must be visible before
* receiver->state.
*/
None of this affects the code, which is
Acked-by: George Spelvin <linux@horizon.com>
next prev parent reply other threads:[~2015-05-05 0:37 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-01 15:27 [PATCH v2 0/3] kernel: lockless wake-queues Davidlohr Bueso
2015-05-01 15:27 ` [PATCH 1/3] sched: " Davidlohr Bueso
2015-05-08 13:23 ` [tip:sched/core] sched: Implement " tip-bot for Peter Zijlstra
2015-05-01 15:27 ` [PATCH 2/3] futex: lockless wakeups Davidlohr Bueso
2015-05-08 13:23 ` [tip:sched/core] futex: Implement " tip-bot for Davidlohr Bueso
2015-05-01 15:27 ` [PATCH 3/3] ipc/mqueue: lockless pipelined wakeups Davidlohr Bueso
2015-05-01 21:52 ` George Spelvin
2015-05-02 0:35 ` Davidlohr Bueso
2015-05-05 0:37 ` George Spelvin [this message]
2015-05-04 14:02 ` [PATCH v2 " Davidlohr Bueso
2015-05-08 13:24 ` [tip:sched/core] ipc/mqueue: Implement " tip-bot for Davidlohr Bueso
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=20150505003713.20276.qmail@ns.horizon.com \
--to=linux@horizon.com \
--cc=bigeasy@linutronix.de \
--cc=clm@fb.com \
--cc=dave@stgolabs.net \
--cc=linux-kernel@vger.kernel.org \
--cc=manfred@colorfullife.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
/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®