Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3724982ybz; Mon, 20 Apr 2020 08:19:32 -0700 (PDT) X-Google-Smtp-Source: APiQypLL3hyrHXDu3E+CLFPZcwp6cFzUNl3SM3H/soNEkocyso5EAKK0wJQYnptqvZ1UbVqLmitf X-Received: by 2002:aa7:dd84:: with SMTP id g4mr15064765edv.273.1587395972471; Mon, 20 Apr 2020 08:19:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587395972; cv=none; d=google.com; s=arc-20160816; b=ojbmY4qY7vcg+3BrlWRssc6fz8IWMyAO/H63F1uRJ+eedD9Gv/RWhyEhtIqUoGQsLJ auGbR6Rr7W7vaX48Tsq2Qi+xScG8d04wdshKWSOqVb0nf30hSHMHmlsdde2oIEKJsxIx g6oStJM8qDjtalHpg03PRZ9PAriQr/FNrZbSzkocouTxIFfCsAd8B51O7w7ahc1lkhZq UX5Y8o2Zg70H48SX2+AGdfnOUmHsulg3XJxh0wuoP/jhtLbEmRnDr7dMWyAR7krJW/FV teuRiUYpBwidltQP50AK8DUHf730+EYz/8eMokiTAawzwQ9pow6YUoFkilwjqBBCjk3G i8Cg== 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:reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=V/+eSS2XeOmYW80NfRyRiKVbKaIJNnY2+7Vo/OP6fLE=; b=JwEIBr8q+B8s/85YJbkRCJ5b0WoteICeQkkVYFi8rLWAmg/0LRH2ok6ybKn2Pc1INq J/EMIiI/upY+17GfqEU7V+5cMygF4zUHHIhF5eHRps+dYQ60uvk1YCo+7Xdmwr11FSZ2 Hu8UaHvUv5vCKP7AMOBBP2AgQJQlTYWcW+eC6fBmLM3Nd9gcLbtoElu5flJtI7Ddku+T ISRNjpCnFlw8zQ2yDADQBRYcwS2rHG4LNn6CdawH4G1IdkV/9tqN3KnmnSSf+wZ3Csof TXRY9yCBINt0cgex5Ax3HDU7AgfN8tNbpjTi+BLV9olLybYl52m1/NYY/h9rx0X8nrms lVeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Y79zU3kE; 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 n34si818013edc.207.2020.04.20.08.19.09; Mon, 20 Apr 2020 08:19:32 -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=Y79zU3kE; 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 S1728176AbgDTPFq (ORCPT + 99 others); Mon, 20 Apr 2020 11:05:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:53748 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726105AbgDTPFq (ORCPT ); Mon, 20 Apr 2020 11:05:46 -0400 Received: from paulmck-ThinkPad-P72.home (50-39-105-78.bvtn.or.frontiernet.net [50.39.105.78]) (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 8576C206F6; Mon, 20 Apr 2020 15:05:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587395145; bh=7BiXorufPKAH/HQwDAPyJlEGnPQWrcZBKYuT26mkfa4=; h=Date:From:To:Cc:Subject:Reply-To:References:In-Reply-To:From; b=Y79zU3kE6J9vfYKflUYmHAt3XecS+mZTfm+H8HkXK3PHnSJ9yjRFZJWExU+/7OR0p abbEFTGtu1H67B9XabUMY2hvw8VC8LP2BS2IZ7K7Nzcam92+0Bn3VNL5fhWlPqa2Gd UzCvXt4ka5tJegHGIalhYUTCi4s2BX2ebkgTiZuM= Received: by paulmck-ThinkPad-P72.home (Postfix, from userid 1000) id 5972F35233EC; Mon, 20 Apr 2020 08:05:45 -0700 (PDT) Date: Mon, 20 Apr 2020 08:05:45 -0700 From: "Paul E. McKenney" To: David Laight Cc: 'Petko Manolov' , LKML Subject: Re: [RFC] WRITE_ONCE_INC() and friends Message-ID: <20200420150545.GB17661@paulmck-ThinkPad-P72> Reply-To: paulmck@kernel.org References: <20200419094439.GA32841@carbon> <491f0b0bc9e4419d93a78974fd7f44c7@AcuMS.aculab.com> <20200419182957.GA36919@carbon> <8e5a0283ed76465aac19a2b97a27ff15@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8e5a0283ed76465aac19a2b97a27ff15@AcuMS.aculab.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Apr 19, 2020 at 09:37:10PM +0000, David Laight wrote: > From: Petko Manolov > > Sent: 19 April 2020 19:30 > > > > On 20-04-19 18:02:50, David Laight wrote: > > > From: Petko Manolov > > > > Sent: 19 April 2020 10:45 > > > > Recently I started reading up on KCSAN and at some point I ran into stuff like: > > > > > > > > WRITE_ONCE(ssp->srcu_lock_nesting[idx], ssp->srcu_lock_nesting[idx] + 1); > > > > WRITE_ONCE(p->mm->numa_scan_seq, READ_ONCE(p->mm->numa_scan_seq) + 1); > > > > > > If all the accesses use READ/WRITE_ONCE() why not just mark the structure > > > field 'volatile'? > > > > This is a bit heavy. I guess you've read this one: > > > > https://lwn.net/Articles/233479/ > > I remember reading something similar before. > I also remember a very old gcc (2.95?) that did a readback > after every volatile write on sparc (to flush the store buffer). > That broke everything. > > I suspect there is a lot more code that is attempting to be lockless > these days. > Ring buffers (one writer and one reader) are a typical example where > you don't need locks but do need to use a consistent value. > > Now you may also need ordering between accesses - which I think needs > more than volatile. In Petko's patch, all needed ordering is supplied by the fact that it is the same variable being read and written. But yes, in many other cases, more ordering is required. > > And no, i am not sure all accesses are through READ/WRITE_ONCE(). If, for > > example, all others are from withing spin_lock/unlock pairs then we _may_ not > > need READ/WRITE_ONCE(). > > The cost of volatile accesses is probably minimal unless the > code is written assuming the compiler will only access things once. And there are variables marked as volatile, for example, jiffies. But one downside of declaring variables volatile is that it can prevent KCSAN from spotting violations of the concurrency design for those variables. > > I merely proposed the _INC() variant for better readability. > > More like shorter code lines :-) That too! ;-) Thanx, Paul