Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2777955ybp; Thu, 10 Oct 2019 12:27:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqzQ7yK6RMqu5EcfXSTf2OnVHoiTt3o1+bMvyByQtwvB16y9Um+maBsqeHBHK7M3bSuHFvX+ X-Received: by 2002:a50:d4d7:: with SMTP id e23mr9821460edj.135.1570735640195; Thu, 10 Oct 2019 12:27:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570735640; cv=none; d=google.com; s=arc-20160816; b=B+rpBIXc4UPJ/F3nMSlQSZBqgnM72aCIzEz44WA5zOQzqSl/2LswVsdmTfcXMMn10/ 6M5zYaiZMtxDzxoPC1YwWfJzgGrEIIE/8NU8W5yPzNioRPuBuAPt+NVLzRalO5Ecri9i uiGFyLdLt69ySnzFUXCn/UMl8It7REGEepVEO2tvV37iVyQnkFcNpLkQV/ZRDBxE1H7q BcA4P6lYayr8wWRw+g2rOE3bxx3XCPXK2tLWEd1PYQqO4YvhydzI93FD4uyG1oJsueD4 /+wcb3g2E9rKOA7ODQJazCL1r+T7IIPVX5OIQQrX76VsujMWh9apNOiTBdeYzkLOyN1C MbGA== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=qbWaY9hiXshvIySwOzF2wqcuQDRIKdHxORxtRs7/yNQ=; b=MljYdIQ+w19JitAVmRd0fbnxg5A07azup/nGZXJkUaFzT8B8AxSWFLPkOClG92g4IU J9mNK4gYWfE+6gdfFSn1UkBx2TGcamVEywGwUaFtz6hYD6z7u5+PUPTEpp2Nf/V6ypgu TL3VQ6EDhLB2HydPwFkepKqdNM0S++ZatVh6KENPmsHW6zFMkjURU237jTCsudBnnBco 2GZwZIn3QGXU+mOvkB576V0fk0+JkWXsgFdOg7eKE+ohXgC6DtB7uXbqZqZaIQjS86SD ZHUaZVaWW+g/t51qicJwMGuNItnGrmN04ADuVNun3WsBh4B62Kz2snsCURGcdLAhmFdc a5zg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e48si4585417eda.130.2019.10.10.12.26.56; Thu, 10 Oct 2019 12:27:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727121AbfJJT0Z convert rfc822-to-8bit (ORCPT + 99 others); Thu, 10 Oct 2019 15:26:25 -0400 Received: from mx2.suse.de ([195.135.220.15]:35454 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726489AbfJJT0Y (ORCPT ); Thu, 10 Oct 2019 15:26:24 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 1C38CAB9B; Thu, 10 Oct 2019 19:26:22 +0000 (UTC) Date: Thu, 10 Oct 2019 12:25:08 -0700 From: Davidlohr Bueso To: Peter Zijlstra Cc: Manfred Spraul , Waiman Long , Linux Kernel Mailing List , 1vier1@web.de, "Paul E. McKenney" Subject: Re: wake_q memory ordering Message-ID: <20191010192508.3yvpc5r6oqjq5tbr@linux-p48b> References: <990690aa-8281-41da-4a46-99bb8f9fec31@colorfullife.com> <20191010114244.GS2311@hirez.programming.kicks-ass.net> <7af22b09-2ab9-78c9-3027-8281f020e2e8@colorfullife.com> <20191010123219.GO2328@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8BIT In-Reply-To: <20191010123219.GO2328@hirez.programming.kicks-ass.net> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 10 Oct 2019, Peter Zijlstra wrote: >On Thu, Oct 10, 2019 at 02:13:47PM +0200, Manfred Spraul wrote: >> Hi Peter, >> >> On 10/10/19 1:42 PM, Peter Zijlstra wrote: >> > On Thu, Oct 10, 2019 at 12:41:11PM +0200, Manfred Spraul wrote: >> > > Hi, >> > > >> > > Waiman Long noticed that the memory barriers in sem_lock() are not really >> > > documented, and while adding documentation, I ended up with one case where >> > > I'm not certain about the wake_q code: >> > > >> > > Questions: >> > > - Does smp_mb__before_atomic() + a (failed) cmpxchg_relaxed provide an >> > > ? ordering guarantee? >> > Yep. Either the atomic instruction implies ordering (eg. x86 LOCK >> > prefix) or it doesn't (most RISC LL/SC), if it does, >> > smp_mb__{before,after}_atomic() are a NO-OP and the ordering is >> > unconditinoal, if it does not, then smp_mb__{before,after}_atomic() are >> > unconditional barriers. >> >> And _relaxed() differs from "normal" cmpxchg only for LL/SC architectures, >> correct? > >Indeed. > >> Therefore smp_mb__{before,after}_atomic() may be combined with >> cmpxchg_relaxed, to form a full memory barrier, on all archs. > >Just so. We might want something like this? ----8<--------------------------------------------------------- From: Davidlohr Bueso Subject: [PATCH] Documentation/memory-barriers.txt: Mention smp_mb__{before,after}_atomic() and CAS Explicitly mention possible usages to guarantee serialization even upon failed cmpxchg (or similar) calls along with smp_mb__{before,after}_atomic(). Signed-off-by: Davidlohr Bueso --- Documentation/memory-barriers.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Documentation/memory-barriers.txt b/Documentation/memory-barriers.txt index 1adbb8a371c7..5d2873d4b442 100644 --- a/Documentation/memory-barriers.txt +++ b/Documentation/memory-barriers.txt @@ -1890,6 +1890,18 @@ There are some more advanced barrier functions: This makes sure that the death mark on the object is perceived to be set *before* the reference counter is decremented. + Similarly, these barriers can be used to guarantee serialization for atomic + RMW calls on architectures which may not imply memory barriers upon failure. + + obj->next = NULL; + smp_mb__before_atomic() + if (cmpxchg(&obj->ptr, NULL, val)) + return; + + This makes sure that the store to the next pointer always has smp_store_mb() + semantics. As such, smp_mb__{before,after}_atomic() calls allow optimizing + the barrier usage by finer grained serialization. + See Documentation/atomic_{t,bitops}.txt for more information. -- 2.16.4