Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752173AbbD2Toe (ORCPT ); Wed, 29 Apr 2015 15:44:34 -0400 Received: from mail-wg0-f54.google.com ([74.125.82.54]:33694 "EHLO mail-wg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751033AbbD2Toc (ORCPT ); Wed, 29 Apr 2015 15:44:32 -0400 Message-ID: <5541349C.5060000@colorfullife.com> Date: Wed, 29 Apr 2015 21:44:28 +0200 From: Manfred Spraul User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Davidlohr Bueso , Peter Zijlstra CC: Thomas Gleixner , Sebastian Andrzej Siewior , LKML , Ingo Molnar , Darren Hart , Steven Rostedt , fredrik.markstrom@windriver.com, "Paul E. McKenney" Subject: Re: [PATCH v2] ipc/mqueue: remove STATE_PENDING References: <1428419030-20030-1-git-send-email-bigeasy@linutronix.de> <1428419030-20030-4-git-send-email-bigeasy@linutronix.de> <55241851.7060704@colorfullife.com> <20150410143726.GD3057@linutronix.de> <1430191493.2050.3.camel@stgolabs.net> <20150428123738.GY23123@twins.programming.kicks-ass.net> <1430239010.2004.6.camel@stgolabs.net> <20150428164329.GK5029@twins.programming.kicks-ass.net> <1430240361.2004.13.camel@stgolabs.net> In-Reply-To: <1430240361.2004.13.camel@stgolabs.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1903 Lines: 52 Hi Davidlohr, On 04/28/2015 06:59 PM, Davidlohr Bueso wrote: > On Tue, 2015-04-28 at 18:43 +0200, Peter Zijlstra wrote: >> Well, if you can 'guarantee' the cmpxchg will not fail, you can then >> rely on the fact that cmpxchg implies a full barrier, which would >> obviate the need for the wmb. > Yes, assuming it implies barriers on both sides. And we could obviously > remove the need for pairing. With wake_q being local to wq_sleep() I > cannot see duplicate tasks trying to add themselves in the list. Failed > cmpxchg should only occur when users start misusing the wake_q. > > Manfred, do you have any objections to this? Perhaps I've missed the > real purpose of the barriers. I don't remember the details either, so let's check what should happen: CPU1: sender copies message to kernel memory aaaa CPU1: sender does receiver->msg = message; ** barrier 1 CPU1: sender does receiver->state = STATE_READY; CPU2: receiver notices receiver->state = STATE_READY; ** barrier 2 CPU2: receiver reads receiver->msg bbbb CPU2: receiver reads *receiver->msg Failures would be: - write to receiver->state is visible before the write to receiver->msg or to *receiver->msg ** barrier 1 needs to be an smp_wmb() - cpu 2 reads receiver->msg before receiver->state ** barrier 2 needs to be an smp_rmb(). As far as I can see, no barrier is needed in pos aaaa or bbbb. With regards to failed cmpxchg(): I don't see that mqueue could cause it by itself. Who is allowed to use wake_q? If it is permitted to use wake_q for e.g. timeout/signal delivery wakeup, then that user might have a pending wakeup stored in the task struct. -- Manfred -- 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/