Skip to content

Commit ffa571d

Browse files
Davidlohr Buesotorvalds
authored andcommitted
ipc,msg: document barriers
Both expunge_all() and pipeline_send() rely on both a nil msg value and a full barrier to guarantee the correct ordering when waking up a task. While its counterpart at the receiving end is well documented for the lockless recv algorithm, we still need to document these specific smp_mb() calls. [akpm@linux-foundation.org: fix typo, per Mike] [akpm@linux-foundation.org: mroe tpyos] Signed-off-by: Davidlohr Bueso <davidlohr@hp.com> Cc: Aswin Chandramouleeswaran <aswin@hp.com> Cc: Rik van Riel <riel@redhat.com> Cc: Manfred Spraul <manfred@colorfullife.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent daf948c commit ffa571d

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

‎ipc/msg.c‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,14 @@ static void expunge_all(struct msg_queue *msq, int res)
253253
struct msg_receiver *msr, *t;
254254

255255
list_for_each_entry_safe(msr, t, &msq->q_receivers, r_list) {
256-
msr->r_msg = NULL;
256+
msr->r_msg = NULL; /* initialize expunge ordering */
257257
wake_up_process(msr->r_tsk);
258+
/*
259+
* Ensure that the wakeup is visible before setting r_msg as
260+
* the receiving end depends on it: either spinning on a nil,
261+
* or dealing with -EAGAIN cases. See lockless receive part 1
262+
* and 2 in do_msgrcv().
263+
*/
258264
smp_mb();
259265
msr->r_msg = ERR_PTR(res);
260266
}
@@ -638,22 +644,30 @@ static inline int pipelined_send(struct msg_queue *msq, struct msg_msg *msg)
638644

639645
list_del(&msr->r_list);
640646
if (msr->r_maxsize < msg->m_ts) {
647+
/* initialize pipelined send ordering */
641648
msr->r_msg = NULL;
642649
wake_up_process(msr->r_tsk);
643-
smp_mb();
650+
smp_mb(); /* see barrier comment below */
644651
msr->r_msg = ERR_PTR(-E2BIG);
645652
} else {
646653
msr->r_msg = NULL;
647654
msq->q_lrpid = task_pid_vnr(msr->r_tsk);
648655
msq->q_rtime = get_seconds();
649656
wake_up_process(msr->r_tsk);
657+
/*
658+
* Ensure that the wakeup is visible before
659+
* setting r_msg, as the receiving end depends
660+
* on it. See lockless receive part 1 and 2 in
661+
* do_msgrcv().
662+
*/
650663
smp_mb();
651664
msr->r_msg = msg;
652665

653666
return 1;
654667
}
655668
}
656669
}
670+
657671
return 0;
658672
}
659673

@@ -716,6 +730,7 @@ long do_msgsnd(int msqid, long mtype, void __user *mtext,
716730
goto out_unlock0;
717731
}
718732

733+
/* enqueue the sender and prepare to block */
719734
ss_add(msq, &s);
720735

721736
if (!ipc_rcu_getref(msq)) {

0 commit comments

Comments
 (0)