Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp4366183ybc; Tue, 26 Nov 2019 07:51:49 -0800 (PST) X-Google-Smtp-Source: APXvYqz76JJOrlMQZ1+f/mx3ikBWGl3xTqcgvjtEpSdYq5UJT/9fOEhca21NTCqfxGKLqHB5ZXtx X-Received: by 2002:a17:906:a28d:: with SMTP id i13mr27389662ejz.154.1574783509287; Tue, 26 Nov 2019 07:51:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574783509; cv=none; d=google.com; s=arc-20160816; b=Btke2kPqp6sfM/48c7UDDaTk5tKC36mDR8hiiwUiA+GSB3sn3xDnYqXr1WhkMIWEuw Q0LvhYwWtcGVwqHwO91xrQYoBBVpgu97nZCvRFx2tlHHjCpqnBh5gmUy5I+bnHddvKxl 4lBRvFFdOGzE3ciRv68E0fO8S3Y+rFaUUHPJ0rGAdsFLjBPOu0bGj9Z9zzvpbbaf6wHd N/zV7qjJ2Z2gkROYl7yMT9+vdX9ojZmrq2+/4+bcu9TI6/KIsg9pjHV1bPF66wBNOb/p 04P1ftC4i+lgKpvSlUyEHC9CGoA9PizcZ40j1xdN34Bebrq7H1slovJh8bEDmnx+PiSQ 4/4w== 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=UhG4TbrFQmzzMiP4BKNG5iQmKmV3aCdN4xUR1YDfRPM=; b=0+X/zJt/KoDMI9gX4h7pdofVqjDYniDdtBvZ6GsaZar7IMpZ5ALz0ubq+u0+XoYxrU K/jyJ0QRJ6oDTJN1VZ16Qcdyh8Qe27GYWZVG3yN9nTj0yupcN6L0guV2fCcsQd1nW+Z3 NQlYEZGwtJgksik2mji49TJCIqcDOCET7lHZTy5oP8Hqo8Z2LLPA2DFSUV3nhxkMdcU4 pbc6dRzHIDvPn53XVDgf8tKJ+vNtve3iUZwME46658G4aZXopVKJJrLm3gT4KXcWgruS gG519zzfUEAxN4FtmxQ/UCBWADrq8gR69c59jTrJoO97bGAsQJcviqeMk0/W0S8YjVWC s+4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=EymjOpB0; 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 j2si7357801ejx.28.2019.11.26.07.51.24; Tue, 26 Nov 2019 07:51:49 -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=EymjOpB0; 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 S1728212AbfKZOFD (ORCPT + 99 others); Tue, 26 Nov 2019 09:05:03 -0500 Received: from mail-wr1-f74.google.com ([209.85.221.74]:55796 "EHLO mail-wr1-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728194AbfKZOFC (ORCPT ); Tue, 26 Nov 2019 09:05:02 -0500 Received: by mail-wr1-f74.google.com with SMTP id k15so10519495wrp.22 for ; Tue, 26 Nov 2019 06:04:59 -0800 (PST) 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=UhG4TbrFQmzzMiP4BKNG5iQmKmV3aCdN4xUR1YDfRPM=; b=EymjOpB0+8SfpmZCmMcNlsOPRU3RMG0wks+OGGU5RoKu5iNnds8kJyGLwdmaUmWXuE dnqplvFAsz1dWhct6ntlAzyoICh86s7vqDfU6+IiJYYhw0Ph7X2fvARCSRMsQKHfLcNY twyP1G55MZ7sV/FGuuzZKyNFCtBZ/DG2K9EYcJHInSWHOW/ZNLNYA4kU6LSSjWhUk2gG NExttxy8LAyaJZ5/yDTur8/fhlLE+CiaawhkaNeLA1hrypDOSghW49sZ+Y4WyKUgRSzD X9V8XACo+gcKTYWQ7YjmfJF3aMm7g21gt2l8Aug8yD4aTHxnklsLncYC51IY8LEDjVG/ D70w== 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=UhG4TbrFQmzzMiP4BKNG5iQmKmV3aCdN4xUR1YDfRPM=; b=DDL+IBaAuygXWZWBxxb+8uIrQtPmjUBVsYGnAbVqfps3/NJ2Zx/exicx69aDAZyP1H M2xwka702x6FDaM9qe32vy/BqRr2nLjNQaqlczDx9ExH5Fo5TUAPdBLoYVjXidMx6ijd Sd3aB+Iq0mH3WPBsqzZQvqzMWg8lshE/0sic//9PIgA/IwD5p8+42MHWhgPkps9I/bNw V3EanorMLyP0Of6pXodZPXWjxBhBto7PMDi3QO6hENglvUB+X+V2c6W3besATtnaCNVD bi2ll3aTnIGmJ9tGhdyTVBF5bB3fKxax8tW5M8HIlX6+mm+Wwqrrula5fZtJJ2+T0wO4 7DLw== X-Gm-Message-State: APjAAAU0XUu+MS2NYdJQanH0nk+Irm9BhOvQG75E8g7BpkmiaR1tI2D/ V+vmZPngyt4Db0wg32kT4xcwZr51Qw== X-Received: by 2002:a5d:694d:: with SMTP id r13mr27765421wrw.395.1574777098959; Tue, 26 Nov 2019 06:04:58 -0800 (PST) Date: Tue, 26 Nov 2019 15:04:06 +0100 In-Reply-To: <20191126140406.164870-1-elver@google.com> Message-Id: <20191126140406.164870-3-elver@google.com> Mime-Version: 1.0 References: <20191126140406.164870-1-elver@google.com> X-Mailer: git-send-email 2.24.0.432.g9d3f5f5b63-goog Subject: [PATCH v3 3/3] kcsan: Prefer __always_inline for fast-path From: Marco Elver To: elver@google.com Cc: mark.rutland@arm.com, paulmck@kernel.org, linux-kernel@vger.kernel.org, will@kernel.org, peterz@infradead.org, boqun.feng@gmail.com, arnd@arndb.de, dvyukov@google.com, linux-arch@vger.kernel.org, kasan-dev@googlegroups.com, Randy Dunlap 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 Prefer __always_inline for fast-path functions that are called outside of user_access_save, to avoid generating UACCESS warnings when optimizing for size (CC_OPTIMIZE_FOR_SIZE). It will also avoid future surprises with compiler versions that change the inlining heuristic even when optimizing for performance. Report: http://lkml.kernel.org/r/58708908-84a0-0a81-a836-ad97e33dbb62@infradead.org Reported-by: Randy Dunlap Signed-off-by: Marco Elver --- Rebased on: locking/kcsan branch of tip tree. --- kernel/kcsan/atomic.h | 2 +- kernel/kcsan/core.c | 16 +++++++--------- kernel/kcsan/encoding.h | 14 +++++++------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/kernel/kcsan/atomic.h b/kernel/kcsan/atomic.h index 576e03ddd6a3..a9c193053491 100644 --- a/kernel/kcsan/atomic.h +++ b/kernel/kcsan/atomic.h @@ -18,7 +18,7 @@ * than cast to volatile. Eventually, we hope to be able to remove this * function. */ -static inline bool kcsan_is_atomic(const volatile void *ptr) +static __always_inline bool kcsan_is_atomic(const volatile void *ptr) { /* only jiffies for now */ return ptr == &jiffies; diff --git a/kernel/kcsan/core.c b/kernel/kcsan/core.c index 3314fc29e236..c616fec639cd 100644 --- a/kernel/kcsan/core.c +++ b/kernel/kcsan/core.c @@ -78,10 +78,8 @@ static atomic_long_t watchpoints[CONFIG_KCSAN_NUM_WATCHPOINTS + NUM_SLOTS-1]; */ static DEFINE_PER_CPU(long, kcsan_skip); -static inline atomic_long_t *find_watchpoint(unsigned long addr, - size_t size, - bool expect_write, - long *encoded_watchpoint) +static __always_inline atomic_long_t * +find_watchpoint(unsigned long addr, size_t size, bool expect_write, long *encoded_watchpoint) { const int slot = watchpoint_slot(addr); const unsigned long addr_masked = addr & WATCHPOINT_ADDR_MASK; @@ -146,7 +144,7 @@ insert_watchpoint(unsigned long addr, size_t size, bool is_write) * 2. the thread that set up the watchpoint already removed it; * 3. the watchpoint was removed and then re-used. */ -static inline bool +static __always_inline bool try_consume_watchpoint(atomic_long_t *watchpoint, long encoded_watchpoint) { return atomic_long_try_cmpxchg_relaxed(watchpoint, &encoded_watchpoint, CONSUMED_WATCHPOINT); @@ -160,7 +158,7 @@ static inline bool remove_watchpoint(atomic_long_t *watchpoint) return atomic_long_xchg_relaxed(watchpoint, INVALID_WATCHPOINT) != CONSUMED_WATCHPOINT; } -static inline struct kcsan_ctx *get_ctx(void) +static __always_inline struct kcsan_ctx *get_ctx(void) { /* * In interrupts, use raw_cpu_ptr to avoid unnecessary checks, that would @@ -169,7 +167,7 @@ static inline struct kcsan_ctx *get_ctx(void) return in_task() ? ¤t->kcsan_ctx : raw_cpu_ptr(&kcsan_cpu_ctx); } -static inline bool is_atomic(const volatile void *ptr) +static __always_inline bool is_atomic(const volatile void *ptr) { struct kcsan_ctx *ctx = get_ctx(); @@ -193,7 +191,7 @@ static inline bool is_atomic(const volatile void *ptr) return kcsan_is_atomic(ptr); } -static inline bool should_watch(const volatile void *ptr, int type) +static __always_inline bool should_watch(const volatile void *ptr, int type) { /* * Never set up watchpoints when memory operations are atomic. @@ -226,7 +224,7 @@ static inline void reset_kcsan_skip(void) this_cpu_write(kcsan_skip, skip_count); } -static inline bool kcsan_is_enabled(void) +static __always_inline bool kcsan_is_enabled(void) { return READ_ONCE(kcsan_enabled) && get_ctx()->disable_count == 0; } diff --git a/kernel/kcsan/encoding.h b/kernel/kcsan/encoding.h index b63890e86449..f03562aaf2eb 100644 --- a/kernel/kcsan/encoding.h +++ b/kernel/kcsan/encoding.h @@ -59,10 +59,10 @@ encode_watchpoint(unsigned long addr, size_t size, bool is_write) (addr & WATCHPOINT_ADDR_MASK)); } -static inline bool decode_watchpoint(long watchpoint, - unsigned long *addr_masked, - size_t *size, - bool *is_write) +static __always_inline bool decode_watchpoint(long watchpoint, + unsigned long *addr_masked, + size_t *size, + bool *is_write) { if (watchpoint == INVALID_WATCHPOINT || watchpoint == CONSUMED_WATCHPOINT) @@ -78,13 +78,13 @@ static inline bool decode_watchpoint(long watchpoint, /* * Return watchpoint slot for an address. */ -static inline int watchpoint_slot(unsigned long addr) +static __always_inline int watchpoint_slot(unsigned long addr) { return (addr / PAGE_SIZE) % CONFIG_KCSAN_NUM_WATCHPOINTS; } -static inline bool matching_access(unsigned long addr1, size_t size1, - unsigned long addr2, size_t size2) +static __always_inline bool matching_access(unsigned long addr1, size_t size1, + unsigned long addr2, size_t size2) { unsigned long end_range1 = addr1 + size1 - 1; unsigned long end_range2 = addr2 + size2 - 1; -- 2.24.0.432.g9d3f5f5b63-goog