From patchwork Tue Nov 10 22:20:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11895727 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=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,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 6FDE9C388F7 for ; Tue, 10 Nov 2020 22:35:31 +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 EDDD72068D for ; Tue, 10 Nov 2020 22:35:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="J5dkTuTE"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="X/G1FHBp" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EDDD72068D 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=kz2XUJBMKDKVxGdPOh43oyUogwTrZAA5nEQMP41Gwa0=; b=J5dkTuTEiS/P1+yMKfu+UjKB0 XQ17zcXfbaUZu33v8OuUlhUd+jCITJPKRmeHCYjQbLNlYcUwSP69IKtCovNOdQS4GSD8/Ggk8y+OF 9sVgrXY2b49PIDBMLRWGA+y0d8lHwuBSWzEP0j00IXWCpH/9rETH0dYcm+KYgBe5MbKRMayCpfeN+ s5rXGOz/qH13imN3St+SqTeKNgXst12jhYGcUrH3rjh9Sl1bMgJLuqW+rI6vkoK1cH8IJSo/UY59L hlmVOenAsHmkaB5gNBbkZIf3snPu8G1JoRBLMbpVu148DULfT9ug9xmNbftX+i6avltg4PAWjAbxs PgR64XK5w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kccE2-0006Yb-Dt; Tue, 10 Nov 2020 22:34:54 +0000 Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcc0U-0000Kc-Vj for linux-arm-kernel@lists.infradead.org; Tue, 10 Nov 2020 22:21:04 +0000 Received: by mail-wr1-x449.google.com with SMTP id z13so247636wrm.19 for ; Tue, 10 Nov 2020 14:20:50 -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=/rSFl10DA/GX54GBDw6zGUYBErxFDPI5QaAJ7Zds8ak=; b=X/G1FHBpaTNPbceckVWXnlaQTlozNeiCpeU7tMmREOJimTXkmCTjt6rRjgNPSeQ0pw q73UVtucfzggJP2pLLg0d8XHXT0ngy/FLNTkV+unC3tseUSKbxmMqR1RfIvjsfMbA2Eq fniu1B6bL+1GI15kaPYNzXCk/yeIk98ad1Jm+d8i/5KDIlsK5BgcmP/efX5QPF1s8Si/ 6NXEIxz4MDViC1Q1XgbEBgCSkG1swl6ak5j3v5axkuBmgM9UBfbh1fuNYORk8kWZXP9Q iGwaOfp4qXX5szQspMdAW9gYIF9nebgteHML8xT3tOJCbTT3oOXCOGM54M/KBM4bacSy YBMQ== 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=/rSFl10DA/GX54GBDw6zGUYBErxFDPI5QaAJ7Zds8ak=; b=hdgohbTHIUcN1DK7LOVk9X/FnW9gFSsIcZFsrM6yEy1+1sEJjtKsyUh/bqaNFbcLL0 IN1GX0PJcmN/HZvYzouO/eIDsqiy7f6yTqlaBYZbbY6Zdl0d1153cfeEXoBqiypwGxMV O4SaLkU88nA0N0smtk62w5dKTLXig1VeBszAR1DuVWKpDTtzQftGtx/7AF+kYXg3JVxO RaDT1sx/bHvmJYSNCCLlr/rwB5YdYWmZXMXGC8gimgJRrrDKOD5liklC6BHVn6rM6vaL ezM8N3DnX4LisXcUEzqGj8utr+rBfjg15r4bRHh/pUHmKYKkM/9skF4w4ccSsaJFcqZm 0HLA== X-Gm-Message-State: AOAM533BmW6AHDwMWL/REDgbgLzBgDPUsAVSKFx3ZKMQ4TRl/G64yFYQ zs+L9XG8okf4iidab1g0HqVjMy7aFevApaql X-Google-Smtp-Source: ABdhPJyY/bBCadcyM/PRgjtzpu0TT6SQ1RzDsL0gjh3vrXFFiPqpWwP79w3xbEXBJdKIjt2rfzmw9gOcpXSqt2FT X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a5d:6692:: with SMTP id l18mr14959782wru.44.1605046848070; Tue, 10 Nov 2020 14:20:48 -0800 (PST) Date: Tue, 10 Nov 2020 23:20:12 +0100 In-Reply-To: Message-Id: <73399d4c0644266d61ad81eb391f5ee10c09e098.1605046662.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v2 08/20] kasan: inline random_tag for HW_TAGS From: Andrey Konovalov To: Dmitry Vyukov , Alexander Potapenko , Marco Elver X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201110_172055_173175_AD4DB1B4 X-CRM114-Status: GOOD ( 14.26 ) 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: Branislav Rankov , Catalin Marinas , Kevin Brodsky , Will Deacon , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, Andrey Konovalov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Evgenii Stepanov 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 Link: https://linux-review.googlesource.com/id/Iac5b2faf9a912900e16cca6834d621f5d4abf427 Reviewed-by: Marco Elver --- mm/kasan/hw_tags.c | 5 ----- mm/kasan/kasan.h | 34 +++++++++++++++++----------------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index 49ea5f5c5643..1476ac07666e 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -42,11 +42,6 @@ void kasan_unpoison_memory(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 8a5501ef2339..7498839a15d3 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -188,6 +188,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); @@ -223,23 +229,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) { @@ -279,6 +268,17 @@ 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) +#define random_tag() 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.