From patchwork Mon Nov 23 20:14:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926671 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0EBD8C63697 for ; Mon, 23 Nov 2020 20:35:08 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9C79120721 for ; Mon, 23 Nov 2020 20:35:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="DAku0S+P"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="nMsy4P1z" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9C79120721 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=oexkPbuFzxroGwCarqT+EaMvrjTTA9p5EJSWFjGoGLk=; b=DAku0S+P2ltZ1N4a6kqF3DdNg k7yqqNhAAJwASz+iSA8fNf2XYdh7K5/LXfkgUzznQ1f7EBjtG0Lh0pQ02t9dhfaJVLvU3sbxmA/t2 3oq2uTvYdiqUDJVLj0JtVnioM4FLOk/19iSGfUlTrrb2RpDAyEr0rUZ2nmi59XefHdx7QfeL0qxhH d/o/sWikmkd61upX3CFr3wOsJ/WJ1WCC7cnMXPCW4FlH83Ba5VOlcTmgAehcuzMLjV1VPdVTjWveO 4yNpiGgIWxJjlIDSwYhPbm4Zof9N91NIls3OZM9AVmVM+4ha9IftyXWmxkE2YOpGkL3BLuAxVoU8H L9JQZFuGA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIXf-0002Ic-Mo; Mon, 23 Nov 2020 20:34:31 +0000 Received: from mail-qv1-f73.google.com ([209.85.219.73]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIF7-0002EP-Mg for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:15:36 +0000 Received: by mail-qv1-f73.google.com with SMTP id v8so13698258qvq.12 for ; Mon, 23 Nov 2020 12:15:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=+ebVro8WhZiLU99JJsnZ41QIjsbf3l1QeUgTEZT5fwM=; b=nMsy4P1zBhnUlJ7LXW5vgMe9VAoz/CbtlFUKrJKF1+LyFx3nO8IGDWAzkq6sCI3cyX 37cZ0AyhoIpiVPMTMdyIP8+n8+BQA57PTXiQxaqv1coMlGKSDmL5G0Bzu1IswwgHYRIF WL3uJIRxFuTlY8/s2i4hCvE/6Vy8uBi6lCrsVkIn8eAz6q3j1YzY9iX/JW8uCtCQyoOv 2fgfUu3tA1ooA7GWCT/E5nVFskmr0ABKzjIcPB/jQauVJM9VZ8rbHjYRd8eAchmaVMRZ kRtz9MnoLJ+37V9QrBxh8/aA/B7kZ8Cwx1WSfgMSxOgxMX4E7RLZx4vULPLNgYjMi0p6 nheA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=+ebVro8WhZiLU99JJsnZ41QIjsbf3l1QeUgTEZT5fwM=; b=YNSNFs0vJIoC1xAhfL6bst+dSh5hLfS6LJZxcrXE21/5WssT/IR8rGpmnRHrCfKKod e+SEl4hOC4zgVWokCAyeDJJHcnubraCFTGZX/xh1V/NYeMigxWp+V3KH2bdTnvcP0kf2 NnUFo23fxWg5LADGRqFXRaX97h+DbgGMAeFDho8vEngA3ypiq4fRtzlhDgqdz5kNjIqv m+/Gi3ouMrR9wuk9rKf1ZGxikQjRDavOMYYZBg650Mj2HmOemR8PijpvBSp60kExGzeq RhK+tg5aw7zgSVObS+YLj5dx8ORoYoCsbja/P5l1T3MXA8EK0qm1GDXS4CZc0v7Bg0n/ QJLg== X-Gm-Message-State: AOAM530oBdULHCU6ijQdNtDVVlMMfysJ9VDVP4+NekfPbQYZqYlPyN2P MpS89IAbaKnN9evQ4pZM1Afrip+Yw243wrep X-Google-Smtp-Source: ABdhPJz/EIT+p1GLjg2l1/jdNIDDxtLmLPSNqnUlEbXUIzj7/CSWJSG0+2TpsAC2+guYEI2P9bEmzgTPMtEAhQTQ X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:6214:aab:: with SMTP id ew11mr1176833qvb.4.1606162512301; Mon, 23 Nov 2020 12:15:12 -0800 (PST) Date: Mon, 23 Nov 2020 21:14:38 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v4 08/19] kasan: inline random_tag for HW_TAGS From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_151522_310746_313B832A X-CRM114-Status: GOOD ( 14.58 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Using random_tag() currently results in a function call. Move its definition to mm/kasan/kasan.h and turn it into a static inline function for hardware tag-based mode to avoid uneeded function calls. Signed-off-by: Andrey Konovalov Reviewed-by: Marco Elver Reviewed-by: Dmitry Vyukov Link: https://linux-review.googlesource.com/id/Iac5b2faf9a912900e16cca6834d621f5d4abf427 --- mm/kasan/hw_tags.c | 5 ----- mm/kasan/kasan.h | 31 ++++++++++++++----------------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index a34476764f1d..3cdd87d189f6 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -51,11 +51,6 @@ void unpoison_range(const void *address, size_t size) round_up(size, KASAN_GRANULE_SIZE), get_tag(address)); } -u8 random_tag(void) -{ - return hw_get_random_tag(); -} - bool check_invalid_free(void *addr) { u8 ptr_tag = get_tag(addr); diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 5e8cd2080369..7876a2547b7d 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -190,6 +190,12 @@ static inline bool addr_has_metadata(const void *addr) #endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ +#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) +void print_tags(u8 addr_tag, const void *addr); +#else +static inline void print_tags(u8 addr_tag, const void *addr) { } +#endif + bool check_invalid_free(void *addr); void *find_first_bad_addr(void *addr, size_t size); @@ -225,23 +231,6 @@ static inline void quarantine_reduce(void) { } static inline void quarantine_remove_cache(struct kmem_cache *cache) { } #endif -#if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) - -void print_tags(u8 addr_tag, const void *addr); - -u8 random_tag(void); - -#else - -static inline void print_tags(u8 addr_tag, const void *addr) { } - -static inline u8 random_tag(void) -{ - return 0; -} - -#endif - #ifndef arch_kasan_set_tag static inline const void *arch_kasan_set_tag(const void *addr, u8 tag) { @@ -281,6 +270,14 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag) #endif /* CONFIG_KASAN_HW_TAGS */ +#ifdef CONFIG_KASAN_SW_TAGS +u8 random_tag(void); +#elif defined(CONFIG_KASAN_HW_TAGS) +static inline u8 random_tag(void) { return hw_get_random_tag(); } +#else +static inline u8 random_tag(void) { return 0; } +#endif + /* * Exported functions for interfaces called from assembly or from generated * code. Declarations here to avoid warning about missing declarations.