From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755850AbbIAKCD (ORCPT ); Tue, 1 Sep 2015 06:02:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38595 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755500AbbIAKCB (ORCPT ); Tue, 1 Sep 2015 06:02:01 -0400 Date: Tue, 1 Sep 2015 11:59:23 +0200 From: Oleg Nesterov To: Boqun Feng Cc: "Paul E. McKenney" , Michal Hocko , Peter Zijlstra , LKML , David Howells , Linus Torvalds , Jonathan Corbet Subject: Re: wake_up_process implied memory barrier clarification Message-ID: <20150901095923.GB31368@redhat.com> References: <20150827131444.GE27052@dhcp22.suse.cz> <20150827182654.GA12191@redhat.com> <20150828145121.GG5301@dhcp22.suse.cz> <20150828160637.GA4393@redhat.com> <20150829092514.GA3240@fixme-laptop.cn.ibm.com> <20150829142707.GA19263@redhat.com> <20150831003719.GC924@fixme-laptop.cn.ibm.com> <20150831183335.GA26333@redhat.com> <20150831203739.GX4029@linux.vnet.ibm.com> <20150901034014.GD1071@fixme-laptop.cn.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150901034014.GD1071@fixme-laptop.cn.ibm.com> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/01, Boqun Feng wrote: > > But I'm still a little confused at Oleg's words: > > "What is really important is that we have a barrier before we _read_ the > task state." > > I read is as "What is really important is that we have a barrier before > we _read_ the task state and _after_ we write the CONDITION", if I don't > misunderstand Oleg, this means a STORE-barrier-LOAD sequence, Yes, exactly. Let's look at this trivial code again, CONDITION = 1; wake_up_process(); note that try_to_wake_up() does if (!(p->state & state)) goto out; If this LOAD could be reordered with STORE(CONDITION) above we can obviously race with set_current_state(...); if (!CONDITION) schedule(); See the comment at the start of try_to_wake_up(). And again, again, please note that initially the only documented behaviour of smp_mb__before_spinlock() was the STORE - LOAD serialization. This is what try_to_wake_up() needs, it doesn't actually need the write barrier after STORE(CONDITION). And just in case, wake_up() differs in a sense that it doesn't even need that STORE-LOAD barrier in try_to_wake_up(), we can rely on wait_queue_head_t->lock. Assuming that wake_up() pairs with the "normal" wait_event()-like code. > which IIUC > can't pair with anything. It pairs with the barrier implied by set_current_state(). Oleg.