Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17730ybl; Thu, 12 Dec 2019 13:14:33 -0800 (PST) X-Google-Smtp-Source: APXvYqxdD25WZnRmp9czyy7MiHGJI45FhOyMEAVNVXyA5ZL5HxWd106fDRqqnKFaAw0Bdxs3YK9Q X-Received: by 2002:a05:6830:18e6:: with SMTP id d6mr10636464otf.170.1576185273120; Thu, 12 Dec 2019 13:14:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576185273; cv=none; d=google.com; s=arc-20160816; b=HEjugNndZYK/+qOXfcM0WOOLTm1LuBnd8OKuwQVl0J9eFw23B0LID29NqjVeMOtYLN bEPTbgyQII5dAmi+DRdgIEzRrBPUyadZKhwHqK8eBA5w+VvsrPb1KRd0Sorw/FcwRR5I e3TGtOaNYrrKCl+CaR6kso8Ntg5+MMTsscy8Qdh6i4PHPjCYiAF/DlgcbV/JARGqTuRj 7QS+P/qGJ3MkCre6c/IWt2jntmbR3ubTFkmUOwVvDf44vusJnKuwXoZniKUGsl+Rs6pI hWxvN5+iB2W1iZ9ONNz30dgw2lyPYHDbaIKUfJwl8XWFlNA7oOp/CO0DwZ5QGEzL+Ves bvkw== 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=cBgSBX+BgteTiVIKyAFTeKLIx8W4ON2ZbWr1HbcmNZw=; b=ukqFzhkGmpygEknoVYEuUk4gzG1UWQwCRNy3UHbumgYuX6mHoErcIHXzviUqHtBnIV 6tLUVabtPRa8zd3kvl0FYBAzrX+Bti6P+hU5eEEmKquek2ugbgvbYWAkHrKjQ6csgPKq P7fvc3sMReHSQnSh90SlQtFF7GLu+oTl3cmoZp5RfAa+a+IqgpQ7d6NgbYawtjeCIYPM fdUfornMQ1yifyIW30shwoUIM8LpwKJveYEkmGA0P6ecrLR4WvVhy6OY6ZFd632bxAJ4 Lb5dMd0wfPpGSpZ8loZVH4+wyjGKF/13ybS7wN51SDdCUu4XWS4NaGXcSKomDB6kfizU ZL6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=kwaUKevD; 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 q124si3644741oig.228.2019.12.12.13.14.12; Thu, 12 Dec 2019 13:14:33 -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=kwaUKevD; 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 S1731028AbfLLVMN (ORCPT + 99 others); Thu, 12 Dec 2019 16:12:13 -0500 Received: from mail-ot1-f68.google.com ([209.85.210.68]:42561 "EHLO mail-ot1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730806AbfLLVMM (ORCPT ); Thu, 12 Dec 2019 16:12:12 -0500 Received: by mail-ot1-f68.google.com with SMTP id 66so3468996otd.9 for ; Thu, 12 Dec 2019 13:12:11 -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=cBgSBX+BgteTiVIKyAFTeKLIx8W4ON2ZbWr1HbcmNZw=; b=kwaUKevD6sBtvubSGOcjMFUrNyqLf9s43G9986p77vdUXpcyCu6+A6nWiLJC0ZzSlh WSvkEh+AhTEfds40OsZCnYRQNmk2O8JIBdlgl1KIaHbRAE/t5K0TCGKoDZXyn0O71cWX k3fatX5eXPUQb4l23Wryg3gVPCtyQOM4sTPcivy+sn/qkpapIjgMkqEfYbBLKEQp6VIb J6xwScQ0D3js4Hf7oXSpKx1o9zqj+C84TE512uCQLoyxOxDtVrmb0pijxBfnOjsr+nHb YP0rH432N5T2YRCM8hKarI3ymPB3th0RS7OMs6xfTeWXpjGYC1SBe3KjR5LINHA2jFPb zwFw== 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=cBgSBX+BgteTiVIKyAFTeKLIx8W4ON2ZbWr1HbcmNZw=; b=m/5SeNsxDHLFNcf7m6QDqmYNbQbysL96aaCZpx5da/+9EBxqQSAZrD8ijAfaElj054 VmSQVb3lBRNKT4o2Gg7Q+6FwwGLr/58cc31RzgH3KFNKGZYIbPiYhA9caAXTnRLih25l D3LUkkkvDJdFusnSTUpMJNudhWkOW0UoOUBlPJypYLVP7aU8zvDBqHZvw15p2EvvSJXg /Xvea9dkWYMcVh+RsjuNuCX4nKJ8MdxZZ0+ToJNOIn5MBt4o/dNMnHQU0luJAK5FzDgL Vq45yeWrIQ0bZxPGi3TZDdbcBLrOfiW+P77C1m2psGVo8D5QmPZYOMdELoMNn9zE9oEN 9Znw== X-Gm-Message-State: APjAAAWs4KUI+S/JxwI8iDWpDG/dZQIrBvX8TpPebOX2JRYR1hB1IvZU oTveooxsa9re6hwtLfg4v1NpRHbjJuDSiOnzil3pjg== X-Received: by 2002:a05:6830:1d6a:: with SMTP id l10mr10813196oti.233.1576185131062; Thu, 12 Dec 2019 13:12:11 -0800 (PST) MIME-Version: 1.0 References: <20191126140406.164870-1-elver@google.com> <20191126140406.164870-3-elver@google.com> <00ee3b40-0e37-c9ac-3209-d07b233a0c1d@infradead.org> <20191203160128.GC2889@paulmck-ThinkPad-P72> In-Reply-To: <20191203160128.GC2889@paulmck-ThinkPad-P72> From: Marco Elver Date: Thu, 12 Dec 2019 22:11:59 +0100 Message-ID: Subject: Re: [PATCH v3 3/3] kcsan: Prefer __always_inline for fast-path To: "Paul E. McKenney" Cc: Randy Dunlap , Mark Rutland , LKML , Will Deacon , Peter Zijlstra , Boqun Feng , Arnd Bergmann , Dmitry Vyukov , linux-arch , kasan-dev 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, 3 Dec 2019 at 17:01, Paul E. McKenney wrote: > > On Mon, Dec 02, 2019 at 09:30:22PM -0800, Randy Dunlap wrote: > > On 11/26/19 6:04 AM, Marco Elver wrote: > > > 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 > > > > Acked-by: Randy Dunlap # build-tested > > Thank you, Randy! Hoped this would have applied by now, but since KCSAN isn't in mainline yet, should I send a version of this patch rebased on -rcu/kcsan? It will just conflict with the style cleanup that is in -tip/locking/kcsan when another eventual merge happens. Alternatively, we can delay it for now and just have to remember to apply eventually (and have to live with things being messy for a bit longer :-)). The version as-is here applies on -tip/locking/kcsan and -next (which merged -tip/locking/kcsan). Thanks, -- Marco > Thanx, Paul > > > Thanks. > > > > > --- > > > 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; > > > > > > > > > -- > > ~Randy > >