Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp6727867ybp; Tue, 15 Oct 2019 20:45:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqz5S6A1KavgEQiWjpijBhmeuiXUwHGiWSohsvF+EJLTD07OXAhlnASU/UdXJaxPcU2KaIP0 X-Received: by 2002:aa7:db55:: with SMTP id n21mr37044821edt.1.1571197522210; Tue, 15 Oct 2019 20:45:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571197522; cv=none; d=google.com; s=arc-20160816; b=pGA/u/t/AeWZSUwGSIQvxq2FyoK6prNLm23wxnQjyBlCPefF2Qmaf3KYeGMhOPVA/M hD9neinWsTwYrsdr5JKi7B1jw1kBep962egUX2Rraaa/qbDJuDY3HD9bhISf4t9I4OPa vK+Ojx71V2moCmFynL6AFU+iu5KOFiSfYY9bP2dTBlynw4UUEfRRosdiB871ZhgZlXVf H3JO7jr2yC/Iq4LzTXr6GSZHez+DInwOoxdhY/GwcfUXCuZ0VgCpZlwxT1Drq6c/U2Oy OXc92OlvgLyVOnYb+Xhj8NeGQaqTgyowEo7QmiEdR9VSpqP3HYj6AlSeEFepEu+Ysu5y kCaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject; bh=0QG8lKEoixiDyZzx8sNy+wFll12qynnJ9YeUQBDe8AM=; b=AusfIP3cbzMhIqDRZ/KFmQWl6hIptUFM6JkHD5R+moYP6Qe8J1u2VsD/6rfBB6PVXo /XG/f+5xZFJMUqPIumM2Dg0zt6DMxHaN5+Bb8RirnIVNQgeHbR+SGYiixGEGq7CKXuji jZupgpPSV7r7jXKtHPFp34NFlbtlTstskNuE7vzzQ7mMM/j9cC5ZHDsrQo7i2i+6bLQK pe4mQOU3YEW7jGQpt7p3OMqQAbdPWV0dl10igDWhE+dDbOlelnrUe84pdeW6wAxT2+am AYU8ibzc0xCC0YNmZly6/Ia2W9ZxNJrKP9KiJTjxATf4fYcXi7Di2QU3SFXb8HHDjWL7 qA7A== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i19si14862105ejf.247.2019.10.15.20.44.58; Tue, 15 Oct 2019 20:45:22 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387895AbfJOUbH (ORCPT + 99 others); Tue, 15 Oct 2019 16:31:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52300 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726590AbfJOUbH (ORCPT ); Tue, 15 Oct 2019 16:31:07 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8990C302C08E; Tue, 15 Oct 2019 20:31:06 +0000 (UTC) Received: from llong.remote.csb (ovpn-123-27.rdu2.redhat.com [10.10.123.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7985860127; Tue, 15 Oct 2019 20:31:05 +0000 (UTC) Subject: Re: [PATCH 6/6] Documentation/memory-barriers.txt: Clarify cmpxchg() To: Manfred Spraul , Peter Zijlstra Cc: LKML , Davidlohr Bueso , 1vier1@web.de, Andrew Morton , Jonathan Corbet References: <20191012054958.3624-1-manfred@colorfullife.com> <20191012054958.3624-7-manfred@colorfullife.com> <20191014130321.GG2328@hirez.programming.kicks-ass.net> From: Waiman Long Organization: Red Hat Message-ID: Date: Tue, 15 Oct 2019 16:31:04 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Tue, 15 Oct 2019 20:31:06 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/14/19 1:49 PM, Manfred Spraul wrote: > Hello Peter, > > On 10/14/19 3:03 PM, Peter Zijlstra wrote: >> On Sat, Oct 12, 2019 at 07:49:58AM +0200, Manfred Spraul wrote: >>> The documentation in memory-barriers.txt claims that >>> smp_mb__{before,after}_atomic() are for atomic ops that do not return a >>> value. >>> >>> This is misleading and doesn't match the example in atomic_t.txt, >>> and e.g. smp_mb__before_atomic() may and is used together with >>> cmpxchg_relaxed() in the wake_q code. >>> >>> The purpose of e.g. smp_mb__before_atomic() is to "upgrade" a following >>> RMW atomic operation to a full memory barrier. >>> The return code of the atomic operation has no impact, so all of the >>> following examples are valid: >> The value return of atomic ops is relevant in so far that >> (traditionally) all value returning atomic ops already implied full >> barriers. That of course changed when we added >> _release/_acquire/_relaxed variants. > I've updated the Change description accordingly >>> 1) >>>     smp_mb__before_atomic(); >>>     atomic_add(); >>> >>> 2) >>>     smp_mb__before_atomic(); >>>     atomic_xchg_relaxed(); >>> >>> 3) >>>     smp_mb__before_atomic(); >>>     atomic_fetch_add_relaxed(); >>> >>> Invalid would be: >>>     smp_mb__before_atomic(); >>>     atomic_set(); >>> >>> Signed-off-by: Manfred Spraul >>> Cc: Waiman Long >>> Cc: Davidlohr Bueso >>> Cc: Peter Zijlstra >>> --- >>>   Documentation/memory-barriers.txt | 11 ++++++----- >>>   1 file changed, 6 insertions(+), 5 deletions(-) >>> >>> diff --git a/Documentation/memory-barriers.txt >>> b/Documentation/memory-barriers.txt >>> index 1adbb8a371c7..52076b057400 100644 >>> --- a/Documentation/memory-barriers.txt >>> +++ b/Documentation/memory-barriers.txt >>> @@ -1873,12 +1873,13 @@ There are some more advanced barrier functions: >>>    (*) smp_mb__before_atomic(); >>>    (*) smp_mb__after_atomic(); >>>   -     These are for use with atomic (such as add, subtract, >>> increment and >>> -     decrement) functions that don't return a value, especially >>> when used for >>> -     reference counting.  These functions do not imply memory >>> barriers. >>> +     These are for use with atomic RMW functions (such as add, >>> subtract, >>> +     increment, decrement, failed conditional operations, ...) that do >>> +     not imply memory barriers, but where the code needs a memory >>> barrier, >>> +     for example when used for reference counting. >>>   -     These are also used for atomic bitop functions that do not >>> return a >>> -     value (such as set_bit and clear_bit). >>> +     These are also used for atomic RMW bitop functions that do >>> imply a full >> s/do/do not/ ? > Sorry, yes, of course I was wondering the same thing. With the revised patch, Acked-by: Waiman Long >>> +     memory barrier (such as set_bit and clear_bit). > >