Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp49285ybk; Tue, 12 May 2020 15:03:28 -0700 (PDT) X-Google-Smtp-Source: APiQypK11Eb4GVuLj2jxXz/WGsWHVvIZ7YRZq763lBATeC8kieeCidyBRM52Xh1pKmTBy5cMp1v/ X-Received: by 2002:aa7:d342:: with SMTP id m2mr19354267edr.130.1589321008753; Tue, 12 May 2020 15:03:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589321008; cv=none; d=google.com; s=arc-20160816; b=e2ZFT42T1+Y9Iej/RM/ExcZMH7+WWo46TiUsDi75LtVOXYzCKujIdG/53FG1jAYU0/ /hY9m7MZw0W3UC8rL+be7Ac1gZDy+JwNnXrLi7BK4x1yC+/xDaOzVGJcoQRpQ34qDrqY YZgCXGHZN3lODFFiTmvv39y54WanY2iVA1d24U9sJsWZ6r/+JHI4S+IzZr5FIiq+/pgO NtiiVNEnoWkLFHhiLIVomlhqkX1ugd/CERIYQbmu4nPUT++AFtwYp98kELyCbrY2Br/L Ix5gKJrh4IjYtGwRVIql0hspCWOhAPZMdgjCM+F8Q99/YSGeY37hdQxt4Dtx7PZUcqKQ 4/FA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=r919tpUIjzuRxoZ5Yps7DZLSIsY9ElfTOSP9gLEZ7kQ=; b=BXtggMJwZ2blGqoqzaDsqtXUUT8GeXyIsdsNF9opGweuTW+q8nW426igGl7XqrM+CV OL9LhqWr6IanTGD8+RPyFty1bHjG0V9FZXtpXF2Qfq4M2nksYYtM+fveDqaZAMjROKLf VrrxYP0Ga5r4PgqcMEPqpoNvDzD7siqjSyYvbobtIoSOZGcDjnF8tDchbsWjG+vgZsY2 KCwc3vAUBBytTS/HO3yLZYJWwcoQnqO0D7gaW62wYSwDOs4hKcl3dJ+m3xej8o7orl/c iG/8XmUUl6Lal+P0PLFHdQVoxHDCitTHlm8BxEL6VpFCgEZHgaXOKipNviSiIq1szQkS vOQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="LCFA2dV/"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b24si8663109edr.338.2020.05.12.15.02.57; Tue, 12 May 2020 15:03:28 -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=@google.com header.s=20161025 header.b="LCFA2dV/"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731546AbgELWBJ (ORCPT + 99 others); Tue, 12 May 2020 18:01:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728313AbgELWBI (ORCPT ); Tue, 12 May 2020 18:01:08 -0400 Received: from mail-oi1-x241.google.com (mail-oi1-x241.google.com [IPv6:2607:f8b0:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA22FC061A0C for ; Tue, 12 May 2020 15:01:08 -0700 (PDT) Received: by mail-oi1-x241.google.com with SMTP id k133so19459155oih.12 for ; Tue, 12 May 2020 15:01:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=r919tpUIjzuRxoZ5Yps7DZLSIsY9ElfTOSP9gLEZ7kQ=; b=LCFA2dV/bKYR0BKsqQ8kFfzVjfHymn4z2cMpX14C3LKyYdrNCqR9q7ID8oIadZyjED d9/c6yOHMCwnMfLcE0DEZ/1kly4vLn0Le5UU9VdkQm+wdTylJrQTLczJrIxXvS0VQDVJ lCgOKXTJBS/4tf2KVmJ4g6CoiiW0xbo64nuWLUBtMeNeQq/mYNq9+DBuihXzB6UopYV8 5WH8B9ZWa44MX9L1CF0YR2CutPo/4Oc1xQ9Df2r29y22uLa23ZooQFfcLy0xbhs1C3t4 n8xqR6hYSLaPKUDskvQ5n7ivrRlNUHgtKy4Rd0GkvT0YwdhaE+Ar9fUxzuN5D8S82RSb 1hZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=r919tpUIjzuRxoZ5Yps7DZLSIsY9ElfTOSP9gLEZ7kQ=; b=G1/m1CnrAWp3PA5wPtbkHEIgOOTNm5syo14uS6q3DrkC0fzldAy6Ldd4+YokcVEU34 BGt36qr6YlTPITxWzxtZYurE00R68rmlT116rObLHrcu/+6oBcMgF5lsF50zhUZLho7r w1WS4JGfw0oPPdHedSFbJCUDkEciDDAMmrE1amHpdzwU/lmsamLTY5BZMMXlS1/2Aiu2 cRA4lirovVvOFhsje2VqDLZngOcohnKPsu6DpN3S4kB2miKH/+tR1vlvsfyCqPWKuxnj gT6SiQ/D4Eo5wEL410Iq3UWDyI746rCnjGiLWjNnStMds+F+CSK0mA1D+EoeurRBTlDl tc3w== X-Gm-Message-State: AGi0PuYsN9iHlupxiQv5CIMZ6inYJ5JZCGwai8g7862eflvluDbgWGVV wIQ7/kQx4YPyeiEh9NYC4MaUEucBDQ0gwybiYax+uA== X-Received: by 2002:aca:3254:: with SMTP id y81mr4949358oiy.172.1589320867527; Tue, 12 May 2020 15:01:07 -0700 (PDT) MIME-Version: 1.0 References: <20200511204150.27858-1-will@kernel.org> <20200512081826.GE2978@hirez.programming.kicks-ass.net> <20200512190755.GL2957@hirez.programming.kicks-ass.net> <20200512211450.GA11062@willie-the-truck> In-Reply-To: <20200512211450.GA11062@willie-the-truck> From: Marco Elver Date: Wed, 13 May 2020 00:00:55 +0200 Message-ID: Subject: Re: [PATCH v5 00/18] Rework READ_ONCE() to improve codegen To: Will Deacon Cc: Peter Zijlstra , LKML , Thomas Gleixner , "Paul E. McKenney" , Ingo Molnar Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 12 May 2020 at 23:15, Will Deacon wrote: > > 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?! For Clang we have an option ("-mllvm -tsan-instrument-func-entry-exit=0"), for GCC, I don't think we have the option. I had hoped we could keep these compiler changes optional for now, to not require a very recent compiler. I'll send a patch to enable the option, but keep it optional for now. Or do you think we require the compiler to support this? Because then we'll only support Clang. > 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). That point is fair enough. But how do we fix arch_atomic_{read,set} then? Thanks, -- Marco