Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752891AbbDGS2O (ORCPT ); Tue, 7 Apr 2015 14:28:14 -0400 Received: from www.linutronix.de ([62.245.132.108]:39552 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750881AbbDGS2K (ORCPT ); Tue, 7 Apr 2015 14:28:10 -0400 Date: Tue, 7 Apr 2015 20:28:30 +0200 (CEST) From: Thomas Gleixner To: Manfred Spraul cc: Sebastian Andrzej Siewior , linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Darren Hart , Steven Rostedt , fredrik.markstrom@windriver.com, Davidlohr Bueso Subject: Re: [PATCH 3/3] ipc/mqueue: remove STATE_PENDING In-Reply-To: <55241851.7060704@colorfullife.com> Message-ID: References: <1428419030-20030-1-git-send-email-bigeasy@linutronix.de> <1428419030-20030-4-git-send-email-bigeasy@linutronix.de> <55241851.7060704@colorfullife.com> User-Agent: Alpine 2.11 (DEB 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1651 Lines: 56 On Tue, 7 Apr 2015, Manfred Spraul wrote: > On 04/07/2015 05:03 PM, Sebastian Andrzej Siewior wrote: > > + * spinlock. The same algorithm is used for sysv semaphores, see ipc/sem.c > > + * for more details. > No. With your change, ipc/sem.c and ipc/msg.c use different algorithms. > Please update the comment and describe the new approach: > > Current approach: > - set pointer to message > - STATE_PENDING > - wake_up_process() > - STATE_READY > (now the receiver can continue) > > New approach: > - set pointer to message > - get_task_struct > - STATE_READY > (now the receiver can continue, e.g. woken up due to an unrelated > SIGKILL) > - wake_up_process() > - put_task_struct() > > > > + if (r_sender) { > > + wake_up_process(r_sender); > > + put_task_struct(r_sender); > > + } > > ret = 0; > Could you double-check that it is safe to call wake_up_process on a killed > and reaped thread, only with a get_task_struct reference? Yes. It is safe to call wake_up_process() on a dead thread if you hold a ref. wake_up_process() return try_to_wake_up(p, TASK_NORMAL, 0); try_to_wake_up() raw_spin_lock_irqsave(&p->pi_lock, flags); if (!(p->state & state)) goto out; TASK_NORMAL == (TASK_INTERRUPTIBLE | TASK_UNINTERRUPTIBLE) That makes try_to_wake_up() a NOOP on a task with state TASK_DEAD. We have quite some code in the kernel which relies on this. Thanks, tglx -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/