From patchwork Thu Nov 5 00:02:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883243 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 CCC19C00A89 for ; Thu, 5 Nov 2020 05:03:29 +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 3D8212083B for ; Thu, 5 Nov 2020 05:03:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="V9lTLeDj"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="p67rrdlX"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="cMYeDNAI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3D8212083B 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=KwmBp53CdNzCQIt8XhHMA1N7EuuXLuiEYT7j3E25NEQ=; b=V9lTLeDjdy41KRt8k/iKyibbC MAq/PYcI8ape1W3pxogJYXG1pmP2rRCPMK4umlTFUDnsd8b2/2LtvLf+247EybQuZ6O5UlDF14u0u h5gvCGZVrtuK9cZSAQFHDRTu7lfU+yhox1yUvQEo5APegVWUdjG8q0H33u9TWeEdMdYfY15rBWeHJ IqtmSZ1rKTgLCTegkNiByqGftBdKcSF/gPLlSvb+E9bUlqW4QQOfMll7BXgkvLNYvjzliYx/qmbZA P8KxbEDPrYFttQ+IVisEa0mqKPSuO6B6XRBO96tib2VU3N4/vKlXNqfMPlhxsksbTcA3bbWOstijm 6V8WtQuFA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaXOv-00033B-1X; Thu, 05 Nov 2020 05:01:33 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW3r-000145-TG for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:35:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=mRk4x8ffqejU12g7nFdHunjF+UNrFXF8Jgp9G1eFhMI=; b=p67rrdlXvmTq2/KdqA5fnzXskn 2vZLbV4o8E5vW/wp14TYd7/F7g2PYcaPseDwt4r7I2wXN8if76mym1xtxWvbMTALIAMYzloMu5chK 5dd5dLCS7Z1vQrpOXtLWCLpI30ofvnPABBKMEbaNBH4otd2ph18Esbd5kCbeZiHhzP7H7OzYKWfVC cXsZEDnHrtmSpYGs9DmKxrLFwGSE0WT/8BACSrmJYTSuE6aT5oZLpegmYtjtIdb7TalZDenaVoMi6 MDcJZsqrLozb2nbN8w4ju3HJ9gP1uEF7S4G/50PjP4T0B2tDo7sC+eCXW+0rcChkz4epQBWujbAVq /wv/EE8g==; Received: from mail-wr1-x449.google.com ([2a00:1450:4864:20::449]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaSkv-0000q3-Lb for linux-arm-kernel@lists.infradead.org; Thu, 05 Nov 2020 00:04:00 +0000 Received: by mail-wr1-x449.google.com with SMTP id w1so99597wrr.5 for ; Wed, 04 Nov 2020 16:03:57 -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=mRk4x8ffqejU12g7nFdHunjF+UNrFXF8Jgp9G1eFhMI=; b=cMYeDNAIEtLr1J3RVSdvrmgQMONBQrVYYerYkXCetvmGBA2xUeYAgNtkEzxajLT3CI Bh1DopQkey4TaU1/5/i1N7npPVtiA/6+48OP7fv9WSaHFiK0vGvalq1IIyODIovLziQ6 zMS4w9QJ63hGFrVjV3+FF8tTat/0fKVwSKWNijqQLrijIlcvDOkez4BWmkgXGFA9J0aB 6Z7OHg1UfOyKJi6jTLQEvCR+dVhIDQbvKXe/QHUgcqVkfITeCc8cvOBbeOhVboFi7Xqz K+At9OBj/xD9fE95zOkrKIEfvez3xnemsuQTm53Fi0esSdQzKOjhX1YcdHiNvLB6WEkw qHUg== 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=mRk4x8ffqejU12g7nFdHunjF+UNrFXF8Jgp9G1eFhMI=; b=kbmVOAoHVWMZFo5r6bF+DrJ9jjiV4rhR3wz69PPNf9dlEpnuFw0DE9yZ7AK12N8Jut 2QrjiDIuSgamPI6aV3WIvXNuBYJvQIURunYU292U0tjok+SCPG0vGl99YObW6PwAXQLP M2drgM8pZCPSH3Xi/+03nq6/hv9+icLQxcKtMXyXLp7PjragYffZNX9vdmSnuXyu4gwC hpCZUpLRqAyMN5rDvJPCrSpm58FXKaaWeZl1Rm9JOsg9l/G6hFPoSMFj1hUGaNvy4L+m h/QVbTvl1HLPksA/ydJ+8fCuPdxgnNbGjoXiF6AJgMFzfawYYhhPwPvh4Z4CcdqXYTNm 2keg== X-Gm-Message-State: AOAM530arKtcyZzEZZkd3rOcDxrmrk4aSUiYqJPXK5F2xhs57UunrVGQ q1LigMMtGIwbu77cTfByaXe7LEi+pSsOhRU+ X-Google-Smtp-Source: ABdhPJxaB9bS1n4FopLulDs5jJOJUms2oIgnCPMGCHt0rWTOkeMjdf4qr41+n+qwT4dQ3uLhsi4LP6SGG6zkwG0L X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:6000:36f:: with SMTP id f15mr532689wrf.78.1604534574449; Wed, 04 Nov 2020 16:02:54 -0800 (PST) Date: Thu, 5 Nov 2020 01:02:18 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH 08/20] kasan: inline random_tag for HW_TAGS From: Andrey Konovalov To: Catalin Marinas , Will Deacon , Vincenzo Frascino , Dmitry Vyukov , Alexander Potapenko , Marco Elver X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201105_000357_869192_68611188 X-CRM114-Status: GOOD ( 12.44 ) 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 , Andrey Konovalov , Kevin Brodsky , linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, Andrey Ryabinin , Andrew Morton , 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 --- 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 fe8e6c8e6319..d5824530fd15 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -38,11 +38,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 e9c7d061fbe5..d7a03eab5814 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) { @@ -275,6 +264,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.