From patchwork Fri Nov 13 22:19:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11905081 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 6216DC4742C for ; Fri, 13 Nov 2020 22:41:37 +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 E200520791 for ; Fri, 13 Nov 2020 22:41:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="2/bUO63a"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="avk+IvhM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E200520791 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=dvZApztdv/thwDdt/7aYXRmbXkHGR2u4w5zibstDwKU=; b=2/bUO63aGmykOvHygN5fUvpcv hd1rpEGq7x/GB1PaaXPe+Rs8F2/f9EG3NXsO8CKKsl8kTBo66ycaxGi9m4yZcibgsobm0FJ5mnyw2 o8eX1NenuX8dIJhhJlhiLaycbaZDo63hDD+wqP4O8XDTOQzMeTYEUUZPsYG3qsZxWA7izFdrbQJF7 d+YpK4KxZh7CiAWgjjELW75bl43z624kFqrEO102MmbnvAzXkHUIbfJ4mbXAOXknd25jXl8lQZ/om 6ao1kOBwsYvDC4kRLJcWJKGF6R9cAPV0IRx25kKMceXeEEKu5hmxgQYfToM9iszyVApmxK9GK2XXF SDgqY5zng==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdhjb-00021K-3s; Fri, 13 Nov 2020 22:39:59 +0000 Received: from mail-qk1-x749.google.com ([2607:f8b0:4864:20::749]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdhQv-0001Z6-3j for linux-arm-kernel@lists.infradead.org; Fri, 13 Nov 2020 22:20:47 +0000 Received: by mail-qk1-x749.google.com with SMTP id 202so7615884qkl.9 for ; Fri, 13 Nov 2020 14:20:36 -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=YBdsxMVQVE97UJPn5Dc1HSKikQDmHg1H37Pt2LLE+Kk=; b=avk+IvhMlEZbmk9DmjnRO5FW8NWySM86BGQFkLT/09JJyb3bg/256owXPaIQNTTw+l 13Og2C+14ZkKV7O8e1B0R7/6G+IdEiu8xNf0Y8uh/3DJRzSSNnEbHhwBkpYwQvS4Dvr3 87rjbB+pQNHS3eleUgWZo+hpMz8uLG8TSmLKVfdfrHwhXOD3+xXbYQHF+7sQdg+ofvKN XP/DdI5ItTdvz5zVDwfjd/70KW2JGXsaqs/30TYn9umM3DXz9coQj5/FW/3sKbfqEdyX naOOcCQpj6mgZY8q56dtr2CJTx5SWs2jxYitvM0NA/jGV7eyTVjJ78xvtPRr5MRutn/E /wWg== 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=YBdsxMVQVE97UJPn5Dc1HSKikQDmHg1H37Pt2LLE+Kk=; b=ZSSUQcE2XtgyT3FRj/0Aeaskfl/CqiQnF/dArMEDcuG6B375NTvXmn2g9uEGkPxbaq 58RJdzT5V/iNNVbkgEQkZuLPNWlZxoj9qAJ9pIQmZjK2FwkA6asFEMWe0QI9Mu5AEh6Z vrmzITbRlfDHMpW1pBKnhElIfyhG2E012EKxbZeW+VW5X89CYqOD4gZRke6232IAMZTa H8UBkDC8IcoD+/RvFhRYuTs/rv6zA455ns+kO10MJOl/FheQtJSC5dDuAZhgUW9aHlCd cjIGE7+XYIfWskMmp8jcI0LAjeHBFjfUgEe9M20XhIquZEkLG3NELs9DwO3rXm9stfK/ P7+g== X-Gm-Message-State: AOAM531/A/y/sJSfr+2FqLxA6Koy07Sk9X/8XE03Itbn7HmUCUe2TIMp 0ytyjQXrPjrbJMmF3XC3HVMY/+O3QrNIxUfJ X-Google-Smtp-Source: ABdhPJwJbNc8LBA5L3yID4KPJo+8gcoSu+K34ENqO85OraM7oBvwXTkr8l2irPNsaon5CTeENcbj5cfem0w7nXTz X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:43ca:: with SMTP id o10mr4757439qvs.33.1605306034217; Fri, 13 Nov 2020 14:20:34 -0800 (PST) Date: Fri, 13 Nov 2020 23:19:58 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog Subject: [PATCH mm v3 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-20201113_172041_290912_7498827D X-CRM114-Status: GOOD ( 14.31 ) 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 Link: https://linux-review.googlesource.com/id/Iac5b2faf9a912900e16cca6834d621f5d4abf427 Reviewed-by: Dmitry Vyukov --- 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.