Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp25792ybk; Tue, 12 May 2020 14:16:48 -0700 (PDT) X-Google-Smtp-Source: APiQypKQMRCO4t625Tdy831cb72acIr1Wi4HpQQ/xBojSl+i9kG2Z4pSfSMLqpskeQ8Z9A+HYUHP X-Received: by 2002:a17:906:829a:: with SMTP id h26mr19172612ejx.133.1589318207812; Tue, 12 May 2020 14:16:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589318207; cv=none; d=google.com; s=arc-20160816; b=lbs6vMfVxgvzl7brPVbAHKE7NHu4ZbKGx1mPOPRtOR6TX3rW5RRakzbcWKFyrwIVCI fJ3rdrnm/jvdqo3m3Ma9qv1Eg5R8ubTieEp/OpeR01kt0ovSkdpGwhrcZzgcpA018aqs InYFTeCXGaUNEkt9LtMor82NYwvWozptdIxc3iQ2Y+v4X6QsyKU0/98isc2f9fySD49w sfOMAk3elCkYHAnOutL4NIRqdMzWQq5gphWTTsPUAHfkMmQ74Yyhtu1fpVg0OmBe4cxP LByKgjQGJZVtEAFp12TOLRSelCY30hkOhuufuVLisShrlzD0aYCa6IcEXxpoXb0urGPA uQNw== 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=StmRFOiPgdVrfDyK6wA+3wr6neyicK9qwMgNxEGh2PY=; b=WKt+LFWBjKWU4gvTp9NnIWIDJjCt10vwJZafKNsBgherm5r42uP/gIX5sWXHOV72hv LgJ+6TD8sd5Z6vCeBJWsgAAmmycOp+dwf5vsV8UI/4KXDDeV1itVVe26PqOCKhYQzo0F dRyuVTIbq2HBEVPEMYwhtQupJphTC6+kGbu4N1nmUFPMIk1fyTJFbPkCMXDcE0W8AM9Z HiwIp6HJO6WuQtMEoWVdW272M1B0BUdZ6/7i7d8vv98FjPk/y+nAypLjJPBIzMxEMAfM O1y8Jq8H+XZ6dciUxW5PQ39i/tvM8S8qHfTYoMwXwZ4+kIhxKWQiLYF9cmBiJ1snOHuI aoPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=niq+lIwy; 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 rv10si8795968ejb.519.2020.05.12.14.16.24; Tue, 12 May 2020 14:16:47 -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=niq+lIwy; 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 S1731310AbgELVPC (ORCPT + 99 others); Tue, 12 May 2020 17:15:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:58134 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725938AbgELVPB (ORCPT ); Tue, 12 May 2020 17:15:01 -0400 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (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 3EB08205C9; Tue, 12 May 2020 21:15:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589318101; bh=n320LhkZ6wxkYO1Y5MNF012NtzAe10rdOlykBinlwig=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=niq+lIwyCb1vX/1DG0ZgmWcD2CGp8EgHUBOR8+Pp4zQH3MpTXGBwOTgVXExn2cCo+ E/CxIvJg0/v7cfuqfWO5nOrb9z8F95MPXl1ZEoCFYI35qG+ZwVdKmBu1IJLY90xu/7 QVCENAmb4gTvChf8qLfRrfiFuJGBJhqdBLHoKqq8= Date: Tue, 12 May 2020 22:14:56 +0100 From: Will Deacon To: Peter Zijlstra Cc: Marco Elver , LKML , Thomas Gleixner , "Paul E. McKenney" , Ingo Molnar Subject: Re: [PATCH v5 00/18] Rework READ_ONCE() to improve codegen Message-ID: <20200512211450.GA11062@willie-the-truck> References: <20200511204150.27858-1-will@kernel.org> <20200512081826.GE2978@hirez.programming.kicks-ass.net> <20200512190755.GL2957@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200512190755.GL2957@hirez.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 Tue, May 12, 2020 at 09:07:55PM +0200, Peter Zijlstra wrote: > On Tue, May 12, 2020 at 07:53:00PM +0200, Marco Elver wrote: > > I just ran a bunch of KCSAN tests. While this series alone would have > > passed the tests, there appears to be a problem with > > __READ_ONCE/__WRITE_ONCE. I think they should already be using > > 'data_race()', as otherwise we will get lots of false positives in > > future. > > > > I noticed this when testing -tip/locking/kcsan, which breaks > > unfortunately, because I see a bunch of spurious data races with > > arch_atomic_{read,set} because "locking/atomics: Flip fallbacks and > > instrumentation" changed them to use __READ_ONCE()/__WRITE_ONCE(). > > From what I see, the intent was to not double-instrument, > > unfortunately they are still double-instrumented because > > __READ_ONCE/__WRITE_ONCE doesn't hide the access from KCSAN (nor KASAN > > actually). I don't think we can use __no_sanitize_or_inline for the > > arch_ functions, because we really want them to be __always_inline > > (also to avoid calls to these functions in uaccess regions, which > > objtool would notice). > > > > I think the easiest way to resolve this is to wrap the accesses in > > __*_ONCE with data_race(). > > But we can't... because I need arch_atomic_*() and __READ_ONCE() to not > call out to _ANYTHING_. > > Sadly, because the compilers are 'broken' that whole __no_sanitize thing > didn't work, but I'll be moving a whole bunch of code into .c files with > all the sanitizers killed dead. And we'll be validating it'll not be > calling out to anything. Hmm, I may have just run into this problem too. I'm using clang 11.0.1, but even if I do something like: unsigned long __no_sanitize_or_inline foo(unsigned long *p) { return READ_ONCE_NOCHECK(*p); } then I /still/ get calls to __tcsan_func_{entry,exit} emitted by the compiler. Marco -- how do you turn this thing off?! I'm also not particularly fond of treating __{READ,WRITE}ONCE() as "atomic", since they're allowed to tear and I think callers should probably either be using data_race() explicitly or disabling instrumentation (assuming that's possible). Will