From patchwork Thu Dec 2 11:27:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 12694488 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D3441C433EF for ; Thu, 2 Dec 2021 11:29:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uFadH+5hYKBwuUn5i6GLZHmf+0aIl7OnTiKmL7mRF2U=; b=tN4zQJwFOuGxQK Ogx38fS55MIdolRxCjuj7LQUeG32e3e6yLR7yF4SA/NETNQMSME2vLhahZugh1vz8xNItzB4HboI/ f+6FPZsqbQm9QbUbwhbVsZXKlD6p2SXCiNFQud1DVeaqTIVJ+GWAjRjzf4zyw5j+5OX0GYwSBPEsk qmxk9BVM6LcK9iEtJ4LeKr27xCU5FAwdzWmg6TsTl2E2FSDFA0Xuo0opj0G8GZJvCninKNqShCzxE aCxVfjEGm+YvyL8YyHkTgSNi/VW2mt82Ozjc2tQvGE5WkxD1FT612tcbteuZHdmjvpQ02v8X9hE4i rBbjKivioCtQNtFKWKaw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mskFk-00Bys6-JR; Thu, 02 Dec 2021 11:27:52 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mskFX-00Bynx-KE for linux-arm-kernel@lists.infradead.org; Thu, 02 Dec 2021 11:27:41 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 986851477; Thu, 2 Dec 2021 03:27:38 -0800 (PST) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 5DED23F7D7; Thu, 2 Dec 2021 03:27:37 -0800 (PST) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org Cc: andreyknvl@gmail.com, catalin.marinas@arm.com, dvyukov@google.com, glider@google.com, linux-kernel@vger.kernel.org, mark.rutland@arm.com, ryabinin.a.a@gmail.com, will@kernel.org Subject: [PATCH 1/3] kasan: move kasan_shadow_to_mem() to shared header Date: Thu, 2 Dec 2021 11:27:29 +0000 Message-Id: <20211202112731.3346975-2-mark.rutland@arm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211202112731.3346975-1-mark.rutland@arm.com> References: <20211202112731.3346975-1-mark.rutland@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211202_032739_738478_81D10813 X-CRM114-Status: GOOD ( 10.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Some arch code would like to convert a shadow address to a corresponding memory address, e.g. for better reporting when a fault is taken on a shadow access. We already provide architectures with kasan_mem_to_shadow() and all the underlying constants, so we may as well allow them to use kasan_shadow_to_mem() rather than having to open-code this. Signed-off-by: Mark Rutland Cc: Alexander Potapenko Cc: Andrey Konovalov Cc: Andrey Ryabinin Cc: Dmitry Vyukov --- include/linux/kasan.h | 6 ++++++ mm/kasan/kasan.h | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index d8783b682669..9059533e19c3 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -56,6 +56,12 @@ static inline void *kasan_mem_to_shadow(const void *addr) + KASAN_SHADOW_OFFSET; } +static inline const void *kasan_shadow_to_mem(const void *shadow_addr) +{ + return (void *)(((unsigned long)shadow_addr - KASAN_SHADOW_OFFSET) + << KASAN_SHADOW_SCALE_SHIFT); +} + int kasan_add_zero_shadow(void *start, unsigned long size); void kasan_remove_zero_shadow(void *start, unsigned long size); diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index aebd8df86a1f..9ec09154ceb1 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -213,12 +213,6 @@ struct kasan_free_meta *kasan_get_free_meta(struct kmem_cache *cache, #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) -static inline const void *kasan_shadow_to_mem(const void *shadow_addr) -{ - return (void *)(((unsigned long)shadow_addr - KASAN_SHADOW_OFFSET) - << KASAN_SHADOW_SCALE_SHIFT); -} - static inline bool addr_has_metadata(const void *addr) { return (addr >= kasan_shadow_to_mem((void *)KASAN_SHADOW_START));