Received: by 2002:a17:90a:bc8d:0:0:0:0 with SMTP id x13csp2403619pjr; Tue, 19 May 2020 14:28:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0NREbBeJbp0rUBN7vvlooMie5ieA9mACI/C5pqulLf+xTYNZUDsc5KqXG13dkA2vVOetU X-Received: by 2002:a17:907:2095:: with SMTP id pv21mr1043807ejb.247.1589923696244; Tue, 19 May 2020 14:28:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589923696; cv=none; d=google.com; s=arc-20160816; b=VLYoRIQVfKd6iyyOBPgCRsBzDH4rTP5J03y9SWkHrpoeAeby5FvPYfxLHwdBPAo7oM OiywB8qsYAo5oao+qlWgRYix/djXgSQiqipOVzlHPT+abjQ5IsNupWleym+3dC3SS/Ew 6JrDdidRThPqTr+eiHwTc/cnLnTpbyGHM0yfwCWnLFPJQlpspVZAOXczqFigxrw1DSuU 3mnPoDEzGURvk3Gyk1VR9k1lfbE5vpsr8/Da3LavHcYUMmWhEXp6HxTP4uBIVjko4VXG 9pPQyfURkBlnrnpCF1kXhxL0TAHAkTJXjSOfGMZcQN5Oy/UCQcu2mbY5JhSys8lYFD4Q K+CQ== 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=8/DW1pZj1YNbWgzrr4MlM3GiIz1LA4FZ7zkZDxQ3+/E=; b=SutuaS5SAv8pAfDTr3ztr0HOgcnQyXoCQu6RGB0HiYHW13H8f5NhLxmmeYVbhByGos iPbPMhLRHbUHoyvtw55pjCtT47i3K8nvq/BDK0pJknqQshsHAI8ovcoPMJeh0jd61ayw Q7ZQolrok/mxiQc1uE0owxOPO0ZQiMiRP8zzdf6mel+41K2S+aoQjavxunpcnkvXtwh+ JPDyUAvO/O3V5Xz51UyqO4A/4JhvdTe/gT67c4XJuAErJy4NH2XuGbGOV9yU0aX6ARnx hzG7fxBkNZLvkH9Aiph9+BIYOD2eUfZdrCdXnIt9BokKdLy6pvY4PQRnlNhi+78zHMB/ d6mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=SOxhHUdF; 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 y102si344850ede.477.2020.05.19.14.27.53; Tue, 19 May 2020 14:28:16 -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=SOxhHUdF; 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 S1726977AbgESV0D (ORCPT + 99 others); Tue, 19 May 2020 17:26:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725998AbgESV0C (ORCPT ); Tue, 19 May 2020 17:26:02 -0400 Received: from mail-oi1-x242.google.com (mail-oi1-x242.google.com [IPv6:2607:f8b0:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9A9DC08C5C0 for ; Tue, 19 May 2020 14:26:02 -0700 (PDT) Received: by mail-oi1-x242.google.com with SMTP id 19so1085712oiy.8 for ; Tue, 19 May 2020 14:26:02 -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=8/DW1pZj1YNbWgzrr4MlM3GiIz1LA4FZ7zkZDxQ3+/E=; b=SOxhHUdF5aVkURIMUqLZSfCO16IDtsaxcATYSXXOV7Uy3Me1WBKsTQA8ldEVBy1MDf FIbQveeRlcMwBv/lGeNHNhtNv5idIinT8VezWnN9nZfywxCHSN+XrrXWheRyJ+EorNAH xD44DZ0kfGGuYmwEVXfGgtF3cnShbYD4UTL4/46wlHxa5jt8zJZ06D7dc8uR6iO9sMbv QAbUHJGBH0liQNxp8dlnqRTtzswct6efckiIiFL747yiR0ZJ49FHEYZN4CLhvllJziT+ yB8sGqbgpk+CM2CLeXrO0lvSVUsdhADe9r1awZhvzww9Qk6bA4RPIaSFihjrxTX2+tsL Jsbg== 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=8/DW1pZj1YNbWgzrr4MlM3GiIz1LA4FZ7zkZDxQ3+/E=; b=rZrh3h/IELCdVaU3o5qSRtX+kB/I7Q1r1K9tmEyhwC2VW9RpdRiNp7rmRQSh/fvRhN uZoodZBRCVkFf2/dl2/IvvKTeRdplru5LRr8J5zFCF3TJMJcvcMEvSQuDgUASx0bEHuc dyAz9Bac5HFdxHXMt85qfOWa24v/DKospIxEGN14UHDyoNoBhbHKl9lU5KjnGGecaHu4 otnIMeAR0GOlZZdykG8gLF7VYnIwi6jhf2GTFrOQC5gNdpQccYJFzvfhwSO25QMLftVz C5KsdKX3YPIcBgE7IfpNNs6wHno5TXjzb/sflEaYZUWeocXtiicvY3d7bPHUZRgEheiZ YjTQ== X-Gm-Message-State: AOAM530SdbQ51ikJI5YdR98rSG8Q/s/S1rGxIApVdbs5rsH1xyAMda+P gKPHZPr2c/jmHif62ASTktWLTvX4scfo+OJsIdo9/A== X-Received: by 2002:aca:6747:: with SMTP id b7mr771179oiy.121.1589923561779; Tue, 19 May 2020 14:26:01 -0700 (PDT) MIME-Version: 1.0 References: <20200512183839.2373-1-elver@google.com> <20200512190910.GM2957@hirez.programming.kicks-ass.net> In-Reply-To: From: Marco Elver Date: Tue, 19 May 2020 23:25:50 +0200 Message-ID: Subject: Re: [PATCH] READ_ONCE, WRITE_ONCE, kcsan: Perform checks in __*_ONCE variants To: Qian Cai Cc: Peter Zijlstra , Linux Kernel Mailing List , kasan-dev , Will Deacon , 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, 19 May 2020 at 23:10, Qian Cai wrote: > > On Tue, May 12, 2020 at 3:09 PM Peter Zijlstra wrote: > > > > On Tue, May 12, 2020 at 08:38:39PM +0200, Marco Elver wrote: > > > diff --git a/include/linux/compiler.h b/include/linux/compiler.h > > > index 741c93c62ecf..e902ca5de811 100644 > > > --- a/include/linux/compiler.h > > > +++ b/include/linux/compiler.h > > > @@ -224,13 +224,16 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, > > > * atomicity or dependency ordering guarantees. Note that this may result > > > * in tears! > > > */ > > > -#define __READ_ONCE(x) (*(const volatile __unqual_scalar_typeof(x) *)&(x)) > > > +#define __READ_ONCE(x) \ > > > +({ \ > > > + kcsan_check_atomic_read(&(x), sizeof(x)); \ > > > + data_race((*(const volatile __unqual_scalar_typeof(x) *)&(x))); \ > > > +}) > > > > NAK > > > > This will actively insert instrumentation into __READ_ONCE() and I need > > it to not have any. > > Any way to move this forward? Due to linux-next commit 6bcc8f459fe7 > (locking/atomics: Flip fallbacks and instrumentation), it triggers a > lots of KCSAN warnings due to atomic ops are no longer marked. This is no longer the right solution we believe due to the various requirements that Peter also mentioned. See the discussion here: https://lkml.kernel.org/r/CANpmjNOGFqhtDa9wWpXs2kztQsSozbwsuMO5BqqW0c0g0zGfSA@mail.gmail.com The new solution is here: https://lkml.kernel.org/r/20200515150338.190344-1-elver@google.com While it's a little inconvenient that we'll require Clang 11 (currently available by building yourself from LLVM repo), but until we get GCC fixed (my patch there still pending :-/), this is probably the right solution going forward. If possible, please do test! Thanks, -- Marco > For > example, > [ 197.318288][ T1041] write to 0xffff9302764ccc78 of 8 bytes by task > 1048 on cpu 47: > [ 197.353119][ T1041] down_read_trylock+0x9e/0x1e0 > atomic_long_set(&sem->owner, val); > __rwsem_set_reader_owned at kernel/locking/rwsem.c:205 > (inlined by) rwsem_set_reader_owned at kernel/locking/rwsem.c:213 > (inlined by) __down_read_trylock at kernel/locking/rwsem.c:1373 > (inlined by) down_read_trylock at kernel/locking/rwsem.c:1517 > [ 197.374641][ T1041] page_lock_anon_vma_read+0x19d/0x3c0 > [ 197.398894][ T1041] rmap_walk_anon+0x30e/0x620 > > [ 197.924695][ T1041] read to 0xffff9302764ccc78 of 8 bytes by task > 1041 on cpu 43: > [ 197.959501][ T1041] up_read+0xb8/0x41a > arch_atomic64_read at arch/x86/include/asm/atomic64_64.h:22 > (inlined by) atomic64_read at include/asm-generic/atomic-instrumented.h:838 > (inlined by) atomic_long_read at include/asm-generic/atomic-long.h:29 > (inlined by) rwsem_clear_reader_owned at kernel/locking/rwsem.c:242 > (inlined by) __up_read at kernel/locking/rwsem.c:1433 > (inlined by) up_read at kernel/locking/rwsem.c:1574 > [ 197.977728][ T1041] rmap_walk_anon+0x2f2/0x620 > [ 197.999055][ T1041] rmap_walk+0xb5/0xe0