From patchwork Thu Oct 17 14:13:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 11196113 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2FDD41575 for ; Thu, 17 Oct 2019 14:13:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 034CC21A49 for ; Thu, 17 Oct 2019 14:13:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="q2AICOUX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439941AbfJQONs (ORCPT ); Thu, 17 Oct 2019 10:13:48 -0400 Received: from mail-ua1-f73.google.com ([209.85.222.73]:47346 "EHLO mail-ua1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439942AbfJQONs (ORCPT ); Thu, 17 Oct 2019 10:13:48 -0400 Received: by mail-ua1-f73.google.com with SMTP id 4so370625uay.14 for ; Thu, 17 Oct 2019 07:13:45 -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=WK0XW0pj3angQDA5Q/f2RR4InnLdQcXEOv/B1XGqGcA=; b=q2AICOUXfZaGMFSuns+PWDFv7IviEfOJbKopMZtW33QU+VemQtbnLj4qpxHAn5TXP2 nzER+TG3nGC/4BnHcTJZtqhT+ftdIDAxWqODmlYmcCyXiCbqVrjWQBjoDghwO4JYBVtZ TyDiMUNobY0cwPOJOBL6+gK8l+10whP9H8NgHsQACC0UZksdSB+unHQrq7KWLfsb6Htl UhaBI8tbBbOVj/p+mV54y6z6FRRqMBaTZKt5+pJJNUFZtpNVLYAamhnmxLhVB0B6Kdzm ehKQd2N9TZJmncuM+e17E05VElF0VQrVLgOt/JhaNy2obM/ZBAaeQNn+R2HBaFJxy2K/ +yGw== 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=WK0XW0pj3angQDA5Q/f2RR4InnLdQcXEOv/B1XGqGcA=; b=huwGxjpnOIUNkHJ6LbYMpTE+m37SpXJnLIm1cRIqbj/Q5odGypRmDjlA64p466iDug 9Rwmp0eHzX1cDPBbfltBD3ARAArbsQMfPyBJIGTurfy2XGyvkGEj4GBkNTsjNBVuWrL6 naNaYd4M7ovilpSl7BlBy7b3DYau4ED49uwbwkNP4mAx4ab1PVd0G26Hl0m1kNa6CKLa IsQ16aezzNIB2d9mk/PCyZ3PAR4VeUJ99X2zC0zgZYcxS3Nk8M37Ik5O7mcKbA6kTQpf PCzrwzTA/XG870gdeh0dwakRmFYxiqCrA4/+YPPf/DbywtgPhhS0aBzzhfgK461GjkeX YJVg== X-Gm-Message-State: APjAAAWgYNx19AVrzuhAPw4sklJejjKIKSytXchMWPdgW6kChCC9DiiM 8ewVl8sY2VRIpZEmhnGdG85XJWp9bw== X-Google-Smtp-Source: APXvYqzc1xz+/8MP7Z8NguqZ/3K5mUNbYma5HtKap1F1LGuqAoshK2iVor1wVZteZ3LMcdUMczzv5cYnww== X-Received: by 2002:a1f:9e8e:: with SMTP id h136mr2074941vke.8.1571321624934; Thu, 17 Oct 2019 07:13:44 -0700 (PDT) Date: Thu, 17 Oct 2019 16:13:03 +0200 In-Reply-To: <20191017141305.146193-1-elver@google.com> Message-Id: <20191017141305.146193-7-elver@google.com> Mime-Version: 1.0 References: <20191017141305.146193-1-elver@google.com> X-Mailer: git-send-email 2.23.0.866.gb869b98d4c-goog Subject: [PATCH v2 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 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Add explicit KCSAN checks for bitops. Signed-off-by: Marco Elver --- v2: * Use kcsan_check{,_atomic}_{read,write} instead of kcsan_check_{access,atomic}. --- 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..864d707cdb87 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_write(addr + BIT_WORD(nr), sizeof(long)); 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_write(addr + BIT_WORD(nr), sizeof(long)); 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_write(addr + BIT_WORD(nr), sizeof(long)); 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_write(addr + BIT_WORD(nr), sizeof(long)); 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_write(addr + BIT_WORD(nr), sizeof(long)); 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_write(addr + BIT_WORD(nr), sizeof(long)); 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_write(addr + BIT_WORD(nr), sizeof(long)); 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_write(addr + BIT_WORD(nr), sizeof(long)); 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_write(addr + BIT_WORD(nr), sizeof(long)); 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_write(addr + BIT_WORD(nr), sizeof(long)); 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_write(addr + BIT_WORD(nr), sizeof(long)); 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_write(addr + BIT_WORD(nr), sizeof(long)); 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_write(addr + BIT_WORD(nr), sizeof(long)); 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_write(addr + BIT_WORD(nr), sizeof(long)); 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_write(addr + BIT_WORD(nr), sizeof(long)); 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_read(addr + BIT_WORD(nr), sizeof(long)); 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_write(addr + BIT_WORD(nr), sizeof(long)); return arch_clear_bit_unlock_is_negative_byte(nr, addr); } /* Let everybody know we have it. */