Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp7249309ybp; Wed, 16 Oct 2019 06:07:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqytphY2vNcXqZdIJVKqfOJtrXLzl/cxyXP6hy4lYjE470yDN89VdmluloZlorcGPoX4uQiY X-Received: by 2002:a05:6000:49:: with SMTP id k9mr40277wrx.289.1571231238018; Wed, 16 Oct 2019 06:07:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571231238; cv=none; d=google.com; s=arc-20160816; b=j5AtFY3GYgf3NgsyclZ+/9V0Wl/b4buperVbN6XYh6uxItJerjVIspjF8A6FMYvIM6 kJdtJ04O/QNsViDGJ3pETWnhd0qG0dyiJoUOxq9SyWKSEXeEOLH+7MqFrMFRizKegqIK G7JA21h/92+5lyAjRg9Ex5O78cOV+veAL/Tvx9vhJZZ6nIonUO/We/SD4vIi1/7EKt/3 zQmR3jxCXpbyjRaMzsOOotnTnUEAIdBkiEVxnoERBdQkT8mCYKod6tT78JdzxJM14dVx dxHT03TJO1uxn+U0mCo7T5O4Xr6x9vvff7ioE9CcI4i/egAyf6dmlOfiF9MFO8rIyj5f hzGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=3fadaJNY8io0I9mSUJYjT11edd0e7dEg1D1vHmOcbCo=; b=iijjsuIkW+FSLR4zdJ8bwzACLDs3ouyLhH62lrfNmBuWZJgwUnBztz9IivyFdL+GYR MnEde1MhuDONb4CsChjT8PnHgNIxj+V04YMsbH1EmqosyLBdZOExSBBj3jEIMhPCunWw Hz2mZeZkRtjXDL/h/3t0dL42CbmUmfTL2xljm6z9rjcMLKpM05R9geqHg88y7u24wq9f G8Z3c2IWpvnsmNPcrJXYr/wmdtLDCejZhx7Tg3az5SuYJmdLAlLf4C7oHcOfUAICY3dt Ks5conAr7IRFQxEPyO5IVtKwtytXHbfNcReNDlL7rBiBbOOWomrHRgO/25dYuvOrDmH7 Xz9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ksjY6JoO; 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 z6si17258169edm.316.2019.10.16.06.06.42; Wed, 16 Oct 2019 06:07:17 -0700 (PDT) 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=ksjY6JoO; 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 S2404094AbfJPIle (ORCPT + 99 others); Wed, 16 Oct 2019 04:41:34 -0400 Received: from mail-wm1-f73.google.com ([209.85.128.73]:32913 "EHLO mail-wm1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391787AbfJPIlc (ORCPT ); Wed, 16 Oct 2019 04:41:32 -0400 Received: by mail-wm1-f73.google.com with SMTP id r187so2043599wme.0 for ; Wed, 16 Oct 2019 01:41:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=3fadaJNY8io0I9mSUJYjT11edd0e7dEg1D1vHmOcbCo=; b=ksjY6JoOjWytq2TYC/oK0zOAvtvo/2GZK/Z9GhwZkoNMbj2PHesiqjczqeQSE93/xV d1/f7nTpc6/nK3QCd2xeAv1p0Fx1ajnVjstMeHMLFBuC6uQbJAwemlBBjU3oU1TFLBuE SBmFMKIpFZJOw2ZF62H3KudIp5W2+fPpliass6KydtEhjgmTAEehW63jvcvWbCw1q76T TLTLYky1Cf0TvkOzNgvfbV21+/XriWkdMzCzYEEYXsmJ1EI0wrZyJ3D2vG6ya7+Plx7Q VM87OGh1AysuXviPUsLPUpvjrhr6o3F5Xn2gIuqaagrendd9yK8vP8tzRMQbht2sdQ0A 7hJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=3fadaJNY8io0I9mSUJYjT11edd0e7dEg1D1vHmOcbCo=; b=S1jHmJ9TGI/l0+6B1PQ83CL7rN0bpviRpXzJqthHfWaUYxGA1d9L2mJD4O2+f4TrW/ gclBsA7UoIEEfaG0GApOBvOLh0gbJA/otcYL1GSOW6SBpaaKxmxh1wfZ+ROlsk0hUwN+ KeH29Fa8q8UjdgEeGenkk8abBPqXOWu8RK1NcRkLskcqvTxr4iQIE/Zf+2VXn+snM84m GB7ymm74bRWDLg6x2oPdkwl8K7ojbSnwzTmNjkIU58bYotzXNzCwx7fnoxFyvCgo77iW pxcWppMvBctveRX0j/nTLr7QetbJMLJT1h+XK4K2qqK/oQ8OWYXu6gHeMn2es5eFOZSP RGAA== X-Gm-Message-State: APjAAAU5wix+t5KGydT0hLmb0viFXOvjYKn4UvZRcyaByoAqGcUvLhIX /pD0xs555z4Ye4EAWzeZLVkLk4ephQ== X-Received: by 2002:adf:e688:: with SMTP id r8mr1726076wrm.342.1571215287907; Wed, 16 Oct 2019 01:41:27 -0700 (PDT) Date: Wed, 16 Oct 2019 10:39:57 +0200 In-Reply-To: <20191016083959.186860-1-elver@google.com> Message-Id: <20191016083959.186860-7-elver@google.com> Mime-Version: 1.0 References: <20191016083959.186860-1-elver@google.com> X-Mailer: git-send-email 2.23.0.700.g56cf767bdb-goog Subject: [PATCH 6/8] asm-generic, kcsan: Add KCSAN instrumentation for bitops From: Marco Elver To: elver@google.com Cc: akiyks@gmail.com, stern@rowland.harvard.edu, glider@google.com, parri.andrea@gmail.com, andreyknvl@google.com, luto@kernel.org, ard.biesheuvel@linaro.org, arnd@arndb.de, boqun.feng@gmail.com, bp@alien8.de, dja@axtens.net, dlustig@nvidia.com, dave.hansen@linux.intel.com, dhowells@redhat.com, dvyukov@google.com, hpa@zytor.com, mingo@redhat.com, j.alglave@ucl.ac.uk, joel@joelfernandes.org, corbet@lwn.net, jpoimboe@redhat.com, luc.maranget@inria.fr, mark.rutland@arm.com, npiggin@gmail.com, paulmck@linux.ibm.com, peterz@infradead.org, tglx@linutronix.de, will@kernel.org, kasan-dev@googlegroups.com, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-efi@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org 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 Add explicit KCSAN checks for bitops. Signed-off-by: Marco Elver --- include/asm-generic/bitops-instrumented.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/include/asm-generic/bitops-instrumented.h b/include/asm-generic/bitops-instrumented.h index ddd1c6d9d8db..5767debd4b52 100644 --- a/include/asm-generic/bitops-instrumented.h +++ b/include/asm-generic/bitops-instrumented.h @@ -12,6 +12,7 @@ #define _ASM_GENERIC_BITOPS_INSTRUMENTED_H #include +#include /** * 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(addr + BIT_WORD(nr), sizeof(long), true); arch_set_bit(nr, addr); } @@ -41,6 +43,7 @@ static inline void set_bit(long nr, volatile unsigned long *addr) static inline void __set_bit(long nr, volatile unsigned long *addr) { kasan_check_write(addr + BIT_WORD(nr), sizeof(long)); + kcsan_check_access(addr + BIT_WORD(nr), sizeof(long), true); arch___set_bit(nr, addr); } @@ -54,6 +57,7 @@ static inline void __set_bit(long nr, volatile unsigned long *addr) static inline void clear_bit(long nr, volatile unsigned long *addr) { kasan_check_write(addr + BIT_WORD(nr), sizeof(long)); + kcsan_check_atomic(addr + BIT_WORD(nr), sizeof(long), true); arch_clear_bit(nr, addr); } @@ -69,6 +73,7 @@ static inline void clear_bit(long nr, volatile unsigned long *addr) static inline void __clear_bit(long nr, volatile unsigned long *addr) { kasan_check_write(addr + BIT_WORD(nr), sizeof(long)); + kcsan_check_access(addr + BIT_WORD(nr), sizeof(long), true); arch___clear_bit(nr, addr); } @@ -82,6 +87,7 @@ static inline void __clear_bit(long nr, volatile unsigned long *addr) static inline void clear_bit_unlock(long nr, volatile unsigned long *addr) { kasan_check_write(addr + BIT_WORD(nr), sizeof(long)); + kcsan_check_atomic(addr + BIT_WORD(nr), sizeof(long), true); arch_clear_bit_unlock(nr, addr); } @@ -97,6 +103,7 @@ static inline void clear_bit_unlock(long nr, volatile unsigned long *addr) static inline void __clear_bit_unlock(long nr, volatile unsigned long *addr) { kasan_check_write(addr + BIT_WORD(nr), sizeof(long)); + kcsan_check_access(addr + BIT_WORD(nr), sizeof(long), true); arch___clear_bit_unlock(nr, addr); } @@ -113,6 +120,7 @@ static inline void __clear_bit_unlock(long nr, volatile unsigned long *addr) static inline void change_bit(long nr, volatile unsigned long *addr) { kasan_check_write(addr + BIT_WORD(nr), sizeof(long)); + kcsan_check_atomic(addr + BIT_WORD(nr), sizeof(long), true); arch_change_bit(nr, addr); } @@ -128,6 +136,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr) static inline void __change_bit(long nr, volatile unsigned long *addr) { kasan_check_write(addr + BIT_WORD(nr), sizeof(long)); + kcsan_check_access(addr + BIT_WORD(nr), sizeof(long), true); arch___change_bit(nr, addr); } @@ -141,6 +150,7 @@ static inline void __change_bit(long nr, volatile unsigned long *addr) static inline bool test_and_set_bit(long nr, volatile unsigned long *addr) { kasan_check_write(addr + BIT_WORD(nr), sizeof(long)); + kcsan_check_atomic(addr + BIT_WORD(nr), sizeof(long), true); return arch_test_and_set_bit(nr, addr); } @@ -155,6 +165,7 @@ static inline bool test_and_set_bit(long nr, volatile unsigned long *addr) static inline bool __test_and_set_bit(long nr, volatile unsigned long *addr) { kasan_check_write(addr + BIT_WORD(nr), sizeof(long)); + kcsan_check_access(addr + BIT_WORD(nr), sizeof(long), true); return arch___test_and_set_bit(nr, addr); } @@ -170,6 +181,7 @@ static inline bool __test_and_set_bit(long nr, volatile unsigned long *addr) static inline bool test_and_set_bit_lock(long nr, volatile unsigned long *addr) { kasan_check_write(addr + BIT_WORD(nr), sizeof(long)); + kcsan_check_atomic(addr + BIT_WORD(nr), sizeof(long), true); return arch_test_and_set_bit_lock(nr, addr); } @@ -183,6 +195,7 @@ static inline bool test_and_set_bit_lock(long nr, volatile unsigned long *addr) static inline bool test_and_clear_bit(long nr, volatile unsigned long *addr) { kasan_check_write(addr + BIT_WORD(nr), sizeof(long)); + kcsan_check_atomic(addr + BIT_WORD(nr), sizeof(long), true); return arch_test_and_clear_bit(nr, addr); } @@ -197,6 +210,7 @@ static inline bool test_and_clear_bit(long nr, volatile unsigned long *addr) static inline bool __test_and_clear_bit(long nr, volatile unsigned long *addr) { kasan_check_write(addr + BIT_WORD(nr), sizeof(long)); + kcsan_check_access(addr + BIT_WORD(nr), sizeof(long), true); return arch___test_and_clear_bit(nr, addr); } @@ -210,6 +224,7 @@ static inline bool __test_and_clear_bit(long nr, volatile unsigned long *addr) static inline bool test_and_change_bit(long nr, volatile unsigned long *addr) { kasan_check_write(addr + BIT_WORD(nr), sizeof(long)); + kcsan_check_atomic(addr + BIT_WORD(nr), sizeof(long), true); return arch_test_and_change_bit(nr, addr); } @@ -224,6 +239,7 @@ static inline bool test_and_change_bit(long nr, volatile unsigned long *addr) static inline bool __test_and_change_bit(long nr, volatile unsigned long *addr) { kasan_check_write(addr + BIT_WORD(nr), sizeof(long)); + kcsan_check_access(addr + BIT_WORD(nr), sizeof(long), true); return arch___test_and_change_bit(nr, addr); } @@ -235,6 +251,7 @@ static inline bool __test_and_change_bit(long nr, volatile unsigned long *addr) static inline bool test_bit(long nr, const volatile unsigned long *addr) { kasan_check_read(addr + BIT_WORD(nr), sizeof(long)); + kcsan_check_atomic(addr + BIT_WORD(nr), sizeof(long), false); return arch_test_bit(nr, addr); } @@ -254,6 +271,7 @@ static inline bool clear_bit_unlock_is_negative_byte(long nr, volatile unsigned long *addr) { kasan_check_write(addr + BIT_WORD(nr), sizeof(long)); + kcsan_check_atomic(addr + BIT_WORD(nr), sizeof(long), true); return arch_clear_bit_unlock_is_negative_byte(nr, addr); } /* Let everybody know we have it. */ -- 2.23.0.700.g56cf767bdb-goog