Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp410666ybl; Wed, 29 Jan 2020 02:51:36 -0800 (PST) X-Google-Smtp-Source: APXvYqxXpdc2Y3qd3MBpZZn5y/9tWTqSMnYxBKxoiwbb36zJ3YHqOZbVCMqXd2pKhx5xUscvIuaR X-Received: by 2002:a9d:21f4:: with SMTP id s107mr20985307otb.102.1580295095665; Wed, 29 Jan 2020 02:51:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580295095; cv=none; d=google.com; s=arc-20160816; b=e1oFgp2/mvuFG+aACF9Edn+XN55eGY3M8Axlv1xx6BmgYfm4+m3/IXz8UY197IFo+U A6HVzbSc6NhLLAFUYP333KBYQkB8r9dszPqSmruc9VCHNhPF49h9hbDEE0VW5zB3UDXm X7qV/QY1jSj6igx6Xa0EuOfQCgWfVjIK7H5/kelHfV4G2kuZgeftWRUExYyIXya/jj2/ l10gMybTQUX2wJYZnTQ9vwLnIA4g/cU3BRtCqQSfi8kyuKL5vhtED1ZNEF6Xbg4TSUto X2Vf/LPVlbDvU1ToSsnOArNNqI0tHFzJ353/vz3p3O0h0Ph9XLIaFL9N5ZFaj+JPU9BP gCig== 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=ekaLsCwMQDEgP33Uu27b/1osxPW25kXxN7+YpOV4y48=; b=bLcxPRwer08Al0VzKIN19+aOv35BoWaY49JwlcZuhLrEzji0HUoXchfEL82n7Ik2Nl 0WBUUDOPJ6gYKaQjOhVUEH8k038nTwbNJAK0Fv4mp1RFuuV2XalNARCq1JJwy3GuQtRO aML5nrXg6nialzmkavYAAUZIFfTWOkNSGjZslVULGazAH2m++yzxb2CbDAz2lYN0Gpcb vz0U7Irpy+G8cHcD0x5kwi/Gt8AhJehHphRAaNAF3G57WCfA0gMx3IuaFJnxzyPIh5fA SxKc1wytG8z1n21G0ST0UHquSjOZMG8Bsyzr8HnCe3i3BZfUPTH88t3kC1cdueZwci8T EJkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=bsgyrNxk; 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 d17si787236oij.136.2020.01.29.02.51.24; Wed, 29 Jan 2020 02:51:35 -0800 (PST) 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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=bsgyrNxk; 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 S1726271AbgA2Kta (ORCPT + 99 others); Wed, 29 Jan 2020 05:49:30 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:60734 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726091AbgA2Kt3 (ORCPT ); Wed, 29 Jan 2020 05:49:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ekaLsCwMQDEgP33Uu27b/1osxPW25kXxN7+YpOV4y48=; b=bsgyrNxkkQgAoQHj/4H9VWg0N BYsLqJysTjNSgmBABm8S5YQWI1DcUZk6nleemESGdQWJv3wIzq3sGGupizG+s/cDiTtI/UvIctZiG 5k6FiuO4Mup1k9l46KybgPMSMk5EwE/5FwToNuFO5vIAhvKlfjwU7rL1awecWueGMETKAFlNbfSCI A8eAUwTGuUolJB7vMZPCOAr6pXlnj0XVsA4fCZSLO1WL8ZoJWx3DlfuWa10UuvPGTwZtMSXMVGA1d UyjylwaWinAr3GjMyBmqlkRgbwz4DakMbxKbC3JioBuZyr2/OkwP38aDlFAZ33INLQT0aRSOnBnRV BNhN/+TgA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1iwkuN-0001y9-RH; Wed, 29 Jan 2020 10:49:20 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 85D05300606; Wed, 29 Jan 2020 11:47:34 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 3B7A82B49B91B; Wed, 29 Jan 2020 11:49:17 +0100 (CET) Date: Wed, 29 Jan 2020 11:49:17 +0100 From: Peter Zijlstra To: Will Deacon Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, kernel-team@android.com, Michael Ellerman , Linus Torvalds , Segher Boessenkool , Christian Borntraeger , Luc Van Oostenryck , Arnd Bergmann , Peter Oberparleiter , Masahiro Yamada , Nick Desaulniers , ying.huang@intel.com, kirill.shutemov@linux.intel.com Subject: Re: [PATCH v2 05/10] READ_ONCE: Enforce atomicity for {READ,WRITE}_ONCE() memory accesses Message-ID: <20200129104917.GN14946@hirez.programming.kicks-ass.net> References: <20200123153341.19947-1-will@kernel.org> <20200123153341.19947-6-will@kernel.org> <20200125082746.GT11457@worktop.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200125082746.GT11457@worktop.programming.kicks-ass.net> 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 Sat, Jan 25, 2020 at 09:27:46AM +0100, Peter Zijlstra wrote: > On Thu, Jan 23, 2020 at 03:33:36PM +0000, Will Deacon wrote: > > {READ,WRITE}_ONCE() cannot guarantee atomicity for arbitrary data sizes. > > This can be surprising to callers that might incorrectly be expecting > > atomicity for accesses to aggregate structures, although there are other > > callers where tearing is actually permissable (e.g. if they are using > > something akin to sequence locking to protect the access). > > > > Linus sayeth: > > > > | We could also look at being stricter for the normal READ/WRITE_ONCE(), > > | and require that they are > > | > > | (a) regular integer types > > | > > | (b) fit in an atomic word > > | > > | We actually did (b) for a while, until we noticed that we do it on > > | loff_t's etc and relaxed the rules. But maybe we could have a > > | "non-atomic" version of READ/WRITE_ONCE() that is used for the > > | questionable cases? > > > > The slight snag is that we also have to support 64-bit accesses on 32-bit > > architectures, as these appear to be widespread and tend to work out ok > > if either the architecture supports atomic 64-bit accesses (x86, armv7) > > or if the variable being accesses represents a virtual address and > > therefore only requires 32-bit atomicity in practice. > > > > Take a step in that direction by introducing a variant of > > 'compiletime_assert_atomic_type()' and use it to check the pointer > > argument to {READ,WRITE}_ONCE(). Expose __{READ,WRITE_ONCE}() variants > > which are allowed to tear and convert the two broken callers over to the > > new macros. > > The build robot is telling me we also need this for m68k; they have: > > arch/m68k/include/asm/page.h:typedef struct { unsigned long pmd[16]; } pmd_t; Fixed that with these patches: https://lkml.kernel.org/r/20200129103941.304769381@infradead.org