Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp1973992ybb; Fri, 29 Mar 2019 15:32:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqzTUCLse0L+up1QyfyA1/9ohnqOTPxDZK2GK/COuwlS8Y0opqfm5JqFSGK4GcRDY9L7ZHZd X-Received: by 2002:a63:c10d:: with SMTP id w13mr10822999pgf.311.1553898724530; Fri, 29 Mar 2019 15:32:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553898724; cv=none; d=google.com; s=arc-20160816; b=DVyUGEkXSqvL99GajzhCWZfKe8YzAVxmsVbcfTnwG77nxHGLMMqxE3f0d7wdu4NJ0z FEEhfUOQ8NnZ3dm4l75am5X4TAcN4cWL+zca+Nw9s3gLoElYz2d3SW8q4ojyClcqBGxQ XuYdlLTxijRto3vo5UPCnLDm1CbJEgAds/UrtgtvMPX8Y+Ci16k2u4pkYrtd3Bks+1pl NYiFwEoi2U8We7+QjldJ6gZi/43qMeixQXMIa4ElKMzKZ/zqGK0AYEhX9hbWfpqnGX4V d0zruDMbLsKG2Ia3Ym9n8XPMq10+1mpn5mI7EhtLtxs3m6qEgJEMjNJObNSyznFfd6RU QYFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:from:cc:to:subject :content-transfer-encoding:mime-version:references:in-reply-to :user-agent:date; bh=R6N+MFRART8EDZKt5c2lVTrIgeeL9EBFVz0m404thZY=; b=kbUsnewMypsjlVQ10oPKgY9smLSiI6S84B+4a6cOTwPcvgb25zgBGvoUq35n3ViuSV YXAUAFumS+AOf8JylC96UNsBDvwPp2GVfztbsVkP9Qs0m8pDY8jIT75wg7Na3VGa50tZ oxWbnHQ52Y/Q9Eubc6mG+AMYzXC2Q3i1yvzIthGouZh5XVvW4djde5AhdsK3OYWXcm6J 8O9j3XzofYB647iz6ISlG5ScmFiWZipJ4JNpYB9dfy7UHNNQLdbV0i19V9uExHcQJoPD sJb7g+v3sHIfKOn37/30WaKS1WzyU8SIUxoh88O5BpJlvmq3dFUqAgwiWZw1i9pzGUEN giWw== 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 t13si2811414pgp.271.2019.03.29.15.31.48; Fri, 29 Mar 2019 15:32:04 -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 S1730456AbfC2WbP convert rfc822-to-8bit (ORCPT + 99 others); Fri, 29 Mar 2019 18:31:15 -0400 Received: from terminus.zytor.com ([198.137.202.136]:39635 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730335AbfC2WbO (ORCPT ); Fri, 29 Mar 2019 18:31:14 -0400 Received: from [IPv6:2607:fb90:3651:4373:48b0:1794:39b7:b336] ([IPv6:2607:fb90:3651:4373:48b0:1794:39b7:b336]) (authenticated bits=0) by mail.zytor.com (8.15.2/8.15.2) with ESMTPSA id x2TMV0Zx3975236 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Fri, 29 Mar 2019 15:31:01 -0700 Date: Fri, 29 Mar 2019 15:30:57 -0700 User-Agent: K-9 Mail for Android In-Reply-To: <20190329220554.GD4102@linux.ibm.com> References: <20190328162222.GO4102@linux.ibm.com> <8e32ab34-c14c-1ccb-76f9-0dcd729a0ef6@zytor.com> <20190329210918.GZ4102@linux.ibm.com> <8092b8aa-bb1c-0266-b308-5cebfb25e2ef@zytor.com> <20190329220554.GD4102@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Subject: Re: Potentially missing "memory" clobbers in bitops.h for x86 To: paulmck@linux.ibm.com, "Paul E. McKenney" CC: Alexander Potapenko , Peter Zijlstra , Ingo Molnar , LKML , Dmitriy Vyukov , James Y Knight From: hpa@zytor.com Message-ID: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On March 29, 2019 3:05:54 PM PDT, "Paul E. McKenney" wrote: >On Fri, Mar 29, 2019 at 02:51:26PM -0700, H. Peter Anvin wrote: >> On 3/29/19 2:09 PM, Paul E. McKenney wrote: >> >> >> >> Note: the atomic versions of these functions obviously need to >have >> >> "volatile" and the clobber anyway, as they are by definition >barriers >> >> and moving memory operations around them would be a very serious >error. >> > >> > The atomic functions that return void don't need to order anything >except >> > the input and output arguments. The oddness with clear_bit() is >that the >> > memory changed isn't necessarily the quantity referenced by the >argument, >> > if the number of bits specified is large. >> > >> > So (for example) atomic_inc() does not need a "memory" clobber, >right? >> >> I don't believe that is true: the code calling it has a reasonable >> expectation that previous memory operations have finished and later >> memory operations have not started from the point of view of another >> processor. You are more of an expert on memory ordering than I am, >but >> I'm 89% sure that there is plenty of code in the kernel which makes >that >> assumption. > >From Documentation/core-api/atomic_ops.rst: > >------------------------------------------------------------------------ > void atomic_add(int i, atomic_t *v); > void atomic_sub(int i, atomic_t *v); > void atomic_inc(atomic_t *v); > void atomic_dec(atomic_t *v); > >These four routines add and subtract integral values to/from the given >atomic_t value. The first two routines pass explicit integers by >which to make the adjustment, whereas the latter two use an implicit >adjustment value of "1". > >One very important aspect of these two routines is that they DO NOT >require any explicit memory barriers. They need only perform the >atomic_t counter update in an SMP safe manner. >------------------------------------------------------------------------ > >So, no, these functions do not imply any ordering other than to the >variable modified. This one predates my joining the Linux kernel >community. ;-) So any cases where someone is relying on atomic_inc() >to provide ordering are bugs. > >Now for value-returning atomics, for example, atomic_inc_return(), >full ordering is indeed required. > > Thanx, Paul Ok. -- Sent from my Android device with K-9 Mail. Please excuse my brevity.