Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp6950030ybl; Wed, 15 Jan 2020 12:54:54 -0800 (PST) X-Google-Smtp-Source: APXvYqxEX2TJgNY7K8JlexG/LSG94miTShWTSnuhdjMyuZEB7FL9nML4XP1juuNIahraoto1Jyl+ X-Received: by 2002:a9d:6b89:: with SMTP id b9mr3974736otq.298.1579121693856; Wed, 15 Jan 2020 12:54:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579121693; cv=none; d=google.com; s=arc-20160816; b=BBHyZ79+5bmTmZrbVQE04LHOO8DaSyR1QbaBwHvq2d8B9O2LHBwsxZtsBHWDjxAGFv aRysC7MIO57k9DFye4WvSb4SU16myQF7KjPKbEBsi3LyQCiFYYh+vpqbE1oMLug9Rtwb zUvzKJBNOnyg2HHod8WobH5itMWscc1Ot/MYMN8v0PeRR6a3DffestiZvcHW640d1xHz vg7vfqjycX+Qv4jnnKwANW4GiN0B80ESAd4vfSrMibyvZk8EsTM7Wbh+BK/YQThF6H51 fgR4ByphN/gPPseG6j9tUhQeBCak0oBZKhT4uc74fPzqW39RMUpuG5q+sbjayMUXpurd crYQ== 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=/0hOUZCXUZrxkCJ9AqKR7AVN+IgQDsfD1fDkF1X5WSk=; b=N7h3alh9YMWWMS/4R5LcxpRkMp79+YmfyqI3nXvsnOg8Ah1XfwW0PmQwCGJR1QlPdr KAxib8924hN4EC30UAB/bjkGa9YMGwWJBXw7FVr8BRCs3paw10fMUFeB+6+PcxsOIXPy g9C/9OGMw/iQ7BU3Jtck6BfMh8mmIOz611uruy1VH8oq75NpIVVk2iRYXfDLg81fqzsS dIczjVQYppl7F7VCPY/dsI5ANknDCmnhE1TD6y/OvAqeiCa3iBeMM6actKATQUvh8k+a gTos+xQvT8q7J2RCZx+dUYYCsBYetQWACSceEFcWdtmdbLpufVih538B4S9Ha+WfBM46 rs5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=RME5cH1b; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f203si9989948oib.56.2020.01.15.12.54.41; Wed, 15 Jan 2020 12:54:53 -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=pass header.i=@google.com header.s=20161025 header.b=RME5cH1b; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729485AbgAOUuV (ORCPT + 99 others); Wed, 15 Jan 2020 15:50:21 -0500 Received: from mail-ot1-f66.google.com ([209.85.210.66]:37420 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728939AbgAOUuU (ORCPT ); Wed, 15 Jan 2020 15:50:20 -0500 Received: by mail-ot1-f66.google.com with SMTP id k14so17367618otn.4 for ; Wed, 15 Jan 2020 12:50:20 -0800 (PST) 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=/0hOUZCXUZrxkCJ9AqKR7AVN+IgQDsfD1fDkF1X5WSk=; b=RME5cH1b7bsbFi/neSvu8LJzKmtkFaTqf4Tzy85FaxdPmfqxVx2MGdQO/KT+oReYK0 W1wJnWv9txH8tg0T0f7d/HbMkylVjDoxHHcb8RGZSVagfQrSWy4TeiawcuJGTX3LswJr hNCIwU+5VxiZ7vnuwA+kd6NOyAXHqh72zwZZF4jhZf18q6YXGjvuc7BzrDhKKW9re81C 4uI799CZWFqEQ9Wd2GS2RQrc//9QjgVAR4eIDkNm7HBgp9gt0dJHUuI/gjrr3gkgsFun Bg+4FeITtAJOnln+cmzvDEuS8Q2ttNqL/cgTdeTaGNTzjVyiGGBs1GlemC3mMAX8ohIH e5fw== 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=/0hOUZCXUZrxkCJ9AqKR7AVN+IgQDsfD1fDkF1X5WSk=; b=YnKAtohAaGJlak7oL9gYnue48i5A4JtyGrvyxgPr9IWhYx2Xc6qfkE+v8tUODJboMK 8kh2ZmTankkOAfi0I0Z9hlMlf3uu0/84qjEAh7Is0bR1WmVJwLabm6ChKZoNhpIuFauK 8Zv+sy5D1ynZL08/HZjoOZ4rsmA1roQUjkyCAxvS2xJzdmgdpxDurnNmcCoIrg1DUJHH 08K6Gsf4mDv7eDRr0QqnSYZwdYktbV6jd+CBQ54FgtWyIEAcHlsVvyTv/rVkY8Zvpcxf 4yQwCJP72wY4ZbYQGsOKD0bQhw65zTh8ZPiR+OidlDaiQbAG2uYmKFf7oAP64fVDzfGw C+9Q== X-Gm-Message-State: APjAAAWYd9bW5C3HCWbzf9kqmHxUfP2mRoIhiB9fBfla6/5ZuxLiw23N edgTLgEnXXx5Vu/vSqOfeKwjfzVmwkhnt+FZf9yWew== X-Received: by 2002:a9d:7410:: with SMTP id n16mr4203681otk.23.1579121419529; Wed, 15 Jan 2020 12:50:19 -0800 (PST) MIME-Version: 1.0 References: <20200115165749.145649-1-elver@google.com> In-Reply-To: From: Marco Elver Date: Wed, 15 Jan 2020 21:50:08 +0100 Message-ID: Subject: Re: [PATCH -rcu] asm-generic, kcsan: Add KCSAN instrumentation for bitops To: Arnd Bergmann Cc: "Paul E. McKenney" , Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , kasan-dev , "linux-kernel@vger.kernel.org" , Michael Ellerman , christophe leroy , Daniel Axtens , linux-arch 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 Wed, 15 Jan 2020 at 20:55, Arnd Bergmann wrote: > > On Wed, Jan 15, 2020 at 8:51 PM Marco Elver wrote: > > > > On Wed, 15 Jan 2020 at 20:27, Arnd Bergmann wrote: > > > > > > On Wed, Jan 15, 2020 at 5:58 PM Marco Elver wrote: > > > > * set_bit - Atomically set a bit in memory > > > > @@ -26,6 +27,7 @@ > > > > static inline void set_bit(long nr, volatile unsigned long *addr) > > > > { > > > > kasan_check_write(addr + BIT_WORD(nr), sizeof(long)); > > > > + kcsan_check_atomic_write(addr + BIT_WORD(nr), sizeof(long)); > > > > arch_set_bit(nr, addr); > > > > } > > > > > > It looks like you add a kcsan_check_atomic_write or kcsan_check_write directly > > > next to almost any instance of kasan_check_write(). > > > > > > Are there any cases where we actually just need one of the two but not the > > > other? If not, maybe it's better to rename the macro and have it do both things > > > as needed? > > > > Do you mean adding an inline helper at the top of each bitops header > > here, similar to what we did for atomic-instrumented? Happy to do > > that if it improves readability. > > I was thinking of treewide wrappers, given that there are only a couple of files > calling kasan_check_write(): > > $ git grep -wl kasan_check_write > arch/arm64/include/asm/barrier.h > arch/arm64/include/asm/uaccess.h > arch/x86/include/asm/uaccess_64.h > include/asm-generic/atomic-instrumented.h > include/asm-generic/bitops/instrumented-atomic.h > include/asm-generic/bitops/instrumented-lock.h > include/asm-generic/bitops/instrumented-non-atomic.h > include/linux/kasan-checks.h > include/linux/uaccess.h > lib/iov_iter.c > lib/strncpy_from_user.c > lib/usercopy.c > scripts/atomic/gen-atomic-instrumented.sh > > Are there any that really just want kasan_check_write() but not one > of the kcsan checks? If I understood correctly, this suggestion would amount to introducing a new header, e.g. 'ksan-checks.h', that provides unified generic checks. For completeness, we will also need to consider reads. Since KCSAN provides 4 check variants ({read,write} x {plain,atomic}), we will need 4 generic check variants. I certainly do not feel comfortable blindly introducing kcsan_checks in all places where we have kasan_checks, but it may be worthwhile adding this infrastructure and starting with atomic-instrumented and bitops-instrumented wrappers. The other locations you list above would need to be evaluated on a case-by-case basis to check if we want to report data races for those accesses. As a minor data point, {READ,WRITE}_ONCE in compiler.h currently only has kcsan_checks and not kasan_checks. My personal preference would be to keep the various checks explicit, clearly opting into either KCSAN and/or KASAN. Since I do not think it's obvious if we want both for the existing and potentially new locations (in future), the potential for error by blindly using a generic 'ksan_check' appears worse than potentially adding a dozen lines or so. Let me know if you'd like to proceed with 'ksan-checks.h'. Thanks, -- Marco