Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2020485ybk; Mon, 11 May 2020 09:56:13 -0700 (PDT) X-Google-Smtp-Source: APiQypIkWvwz3RNu6rCllB20hk4zzUyj/XEGgDiOshPIX1IPo5GBae7jnLGvVccA4I+tWDFLDaYD X-Received: by 2002:a17:906:6944:: with SMTP id c4mr14389161ejs.96.1589216173224; Mon, 11 May 2020 09:56:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589216173; cv=none; d=google.com; s=arc-20160816; b=YNx8aVsJJ8aAh2Z+0yo87VE5nuXlTL3sKVc4ESsGo2nVBi85jf8sUIj78bo7pKp0ao boH1Cwf97wp1ScgnUmgAkv/WNAjZnZb89zNZ53WQTGlmPGzxWdljLQdw5AEKbSyuqbkE cTn7KUAKUFA9mMIUY5hMIvJAK853TkE0K56YwUsZLNrlp/nc13CQe8CUu0Ux/l8/m2Ev J4WZ0dTonunYO+0k1JeAAuy8jlUBT4mMISbK3WUzyELADElemfPJ95lmt7oxuPd50lWa AiBLlbHXu9W4Tb4gtRLWw9BckPjcc4mzEw0UEfxPvkv8UQHZlWLI3Jld93p/BxKhAmi4 Ku0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=0A8SpCyuE3K0/rTZWKyLX+tvLSspSQD2FREYnLPFIEQ=; b=P8clwwRmyqDa0jmcX2cqEmBp7fcML2+tHssuaZUrVahLKWSKzu2SYlTfMtkJhRIwcF AziTEyrRy020UTDlmmDPoxSNnaAk3VI1HeViv+vILfxZeIgau8VPdXtKEUrW1hP09FkK nxAs7JOExkF3xYIe9m/N1OseOGrDioeW2bji77hqivdDPZI+f/61jZugA/Pswj4Zf/QR nFc6VoEbOO1A/9jTknCUD9u8f/GPBlI2Vplb5ZKAGa59IWMLT3rzz+NcO1Di+L+TYcKh mV/yNbqcFCwApzdW56jg03sSYgQpxL8FGfPH28HZllG2LkQUqcPB8cFA8FiwsLAOqnDM HS3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TE6o75wL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dk23si6103423edb.282.2020.05.11.09.55.48; Mon, 11 May 2020 09:56:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TE6o75wL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730624AbgEKQwW (ORCPT + 99 others); Mon, 11 May 2020 12:52:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:59908 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729143AbgEKQwW (ORCPT ); Mon, 11 May 2020 12:52:22 -0400 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 66D75206D7; Mon, 11 May 2020 16:52:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589215941; bh=b/yxjgJC2CuxHj+5rql56i3dEt86BgH3xwqCAuAIF9M=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TE6o75wLdo/KppzMxATQ0XogQnqrpmH3VGgJVIfprF/zLj1RhAdH1vRUEjim/Bt5S nsRFEPcxFaft8RBBLV0BJEreD5eUD/NQwLrgbamFBkiNOMJihz1Db4A0D+nnvmRhhl zCxe1EKi9NG3bkd+wN24IlGduwRBUkwqnECqdm64= Date: Mon, 11 May 2020 17:52:17 +0100 From: Will Deacon To: "Paul E. McKenney" Cc: Qian Cai , Elver Marco , LKML , Ingo Molnar , "Peter Zijlstra (Intel)" Subject: Re: [PATCH -next v2] locking/osq_lock: annotate a data race in osq_lock Message-ID: <20200511165216.GA23081@willie-the-truck> References: <20200509161217.GN2869@paulmck-ThinkPad-P72> <45D9EEEB-D887-485D-9045-417A7F2C6A1A@lca.pw> <20200509213654.GO2869@paulmck-ThinkPad-P72> <20200511155812.GB22270@willie-the-truck> <20200511164319.GV2869@paulmck-ThinkPad-P72> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200511164319.GV2869@paulmck-ThinkPad-P72> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 11, 2020 at 09:43:19AM -0700, Paul E. McKenney wrote: > On Mon, May 11, 2020 at 04:58:13PM +0100, Will Deacon wrote: > > On Sat, May 09, 2020 at 02:36:54PM -0700, Paul E. McKenney wrote: > > > diff --git a/kernel/locking/osq_lock.c b/kernel/locking/osq_lock.c > > > index 1f77349..1de006e 100644 > > > --- a/kernel/locking/osq_lock.c > > > +++ b/kernel/locking/osq_lock.c > > > @@ -154,7 +154,11 @@ bool osq_lock(struct optimistic_spin_queue *lock) > > > */ > > > > > > for (;;) { > > > - if (prev->next == node && > > > + /* > > > + * cpu_relax() below implies a compiler barrier which would > > > + * prevent this comparison being optimized away. > > > + */ > > > + if (data_race(prev->next) == node && > > > cmpxchg(&prev->next, node, NULL) == node) > > > break; > > > > I'm fine with the data_race() placement, but I don't find the comment > > very helpful. We assign the result of a READ_ONCE() to 'prev' in the > > loop, so I don't think that the cpu_relax() is really relevant. > > Suppose that the compiler loaded a value that was not equal to "node". > In that case, the cmpxchg() won't happen, so something else must force > the compiler to do the reload in order to avoid an infinite loop, right? > Or am I missing something here? Then we just go round the loop and reload prev: prev = READ_ONCE(node->prev); which should be enough to stop the compiler, no? Will