From patchwork Wed Nov 4 23:18:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883141 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 91620C00A89 for ; Thu, 5 Nov 2020 04:29:24 +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 0358320825 for ; Thu, 5 Nov 2020 04:29:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="hrnSTJaM"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="np3qLHK7"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="im6MoqCK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0358320825 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=vcpagapbsoTQt06ywyafMRkkuocH3R5e2oJTmyug0fI=; b=hrnSTJaMtxLnhdoucqYfDliCs 91AisBkS/cS6lBjrywpxQaTZ3PFKHf+Ck0u+3MLI9srDtpPlj8WDi45/EWcaUBApNBJ0DnUqxPAnb aciWdoxgzS5j7RhKBVvWIWLW7XKaa52H374OPaz2dZQjBZDKqdQb6ZTGJ+X4exIE2Sidx9AIIMIyE MJ+ytNjZ2wwuMoTzKVBVpiG4kJoVikrvGP1MX8NRT/d+wnrqXrw1rPoL+QZVQg6IVUVX2GoB/JHPf Dr08RKGqERED8ma1YXvDEWmZ6YxjMk/erM9c3IqffP6+7DllBJqqemlffzVEzGDTOE++m/rkTsJwL I+0WL+SrQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaWs0-0000Bt-2N; Thu, 05 Nov 2020 04:27:32 +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 1kaW5G-00016k-PJ for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:10 +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=d4Yc7AItymQNyKGF4tg/i8f/qZM6X5xLr7PA4bM2pG0=; b=np3qLHK76nMvb/H0Zl/uZcLEn5 /5sdCNqws33HiL1w6EF43kMTOeMtii0vIXITk7/jP4S1VBEhbshUOWMySEk+9cBfQQfZBP45vGdFS YRTiTOVR4/doYAjNMAliUJygNxsiMcwg+JsMdePGVdPX/sIqmr0l4qESF+CTwVDQniaWGS23NjFgw K0gR3TP99EMD749R86aXUsBnxXjq/GS4S6cdLwLSv5hwtsS2ZlDphqQi9rGjR2wCQVbUay6h0qY3g OYdeW27LKnBAXHU48j8ekKnyrTkODUixgSdZf1M4Ryk1bhl3GRSC2rm5RRl2YYUHIfio9JFWv4Gin EZBNof1A==; Received: from mail-qk1-x74a.google.com ([2607:f8b0:4864:20::74a]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS58-00040N-2w for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:20:49 +0000 Received: by mail-qk1-x74a.google.com with SMTP id t70so14384979qka.11 for ; Wed, 04 Nov 2020 15:20:45 -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=d4Yc7AItymQNyKGF4tg/i8f/qZM6X5xLr7PA4bM2pG0=; b=im6MoqCKBPimqz1qFHzYTKjtM/SP4xbNj9lqr3+UxqrIDbQMPQjwIdXzthS7jpjGO4 3EcJa8vpYK443mb9T3VXyXZ7BOIItSr4fq2re7sZ3t2jvFZWIc0hQAS+2H3OEqC2u7LZ dKT04KNcmFA0bmrZH178cjfaVWiCJ4PZ5Xs5gs/rC6ULLyS5ZLqfftn6OGZJhi5ELmIn j5tNBMwU7QhW6NXZFeB1ffQ3sT6D0/mVpwGLHCk/iMFPaArf+42hWgYqdAwUmUlMd0T/ cC1waSCYw5qKAzMaV8/V5pfZ8vjWLa1kipuN91CKuTYipRSPTnZwhF9GmhgD2Rsrta6H qfOw== 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=d4Yc7AItymQNyKGF4tg/i8f/qZM6X5xLr7PA4bM2pG0=; b=WrnC7T7D0owjagIkzlKfhM+kJLQRfzTXKHBfkzXSTIMKxp7ZuWlzXUuVr7BIsHqew8 vUZ6gTWb5/2l4wDJqaCYAnphlyji//8hEZ1ax4JJDv8UiQYluguX/aFTshByQqh5lty+ IJx/ZJ6V8ggA3cJ8CVH10exH4N7SnD1XRW1Yf1asP881oRKpIdx6Fiq6bQcfIDWdOd+5 lFC2k0ygd5LYR1wYLgnGgyu9ml5bERLBnwPdUwJwbGipqZYLK/Fx8qrVJr6C8if18S9b +Ukab982i2JCBl4xiJCuywGPwWJaoW/WJY0XdrP/QxKA/6KHNCqUDv6mT6w52OGL1+Dq ecqw== X-Gm-Message-State: AOAM532bWAbuUTrTn5G56TEak9qk984JaTYTTzsgo2N6M3DVzYX0Q/4I pb7gDU6LAivlzzQkQ1MHHhFzYdShpS7BQQFW X-Google-Smtp-Source: ABdhPJwX0nXmCdm5STp8GDmlwJmCmGhLQmNoNB8M224tUiklstu8Z5zoEBhqUpAe9orxivGxyeg98JncJ3U1EYl2 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:464f:: with SMTP id y15mr268562qvv.52.1604531982632; Wed, 04 Nov 2020 15:19:42 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:30 +0100 In-Reply-To: Message-Id: <82bba01b005a8a658596a77b2413adc16c8dfac5.1604531793.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 15/43] kasan, arm64: only init shadow for software modes From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201104_232046_262488_7A55F8F3 X-CRM114-Status: GOOD ( 14.69 ) 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 , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This is a preparatory commit for the upcoming addition of a new hardware tag-based (MTE-based) KASAN mode. Hardware tag-based KASAN won't be using shadow memory. Only initialize it when one of the software KASAN modes are enabled. No functional changes for software modes. Signed-off-by: Andrey Konovalov Signed-off-by: Vincenzo Frascino Reviewed-by: Catalin Marinas --- Change-Id: I055e0651369b14d3e54cdaa8c48e6329b2e8952d --- arch/arm64/include/asm/kasan.h | 8 ++++++-- arch/arm64/mm/kasan_init.c | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/kasan.h b/arch/arm64/include/asm/kasan.h index b0dc4abc3589..f7ea70d02cab 100644 --- a/arch/arm64/include/asm/kasan.h +++ b/arch/arm64/include/asm/kasan.h @@ -13,6 +13,12 @@ #define arch_kasan_get_tag(addr) __tag_get(addr) #ifdef CONFIG_KASAN +void kasan_init(void); +#else +static inline void kasan_init(void) { } +#endif + +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) /* * KASAN_SHADOW_START: beginning of the kernel virtual addresses. @@ -33,12 +39,10 @@ #define _KASAN_SHADOW_START(va) (KASAN_SHADOW_END - (1UL << ((va) - KASAN_SHADOW_SCALE_SHIFT))) #define KASAN_SHADOW_START _KASAN_SHADOW_START(vabits_actual) -void kasan_init(void); void kasan_copy_shadow(pgd_t *pgdir); asmlinkage void kasan_early_init(void); #else -static inline void kasan_init(void) { } static inline void kasan_copy_shadow(pgd_t *pgdir) { } #endif diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c index b24e43d20667..ffeb80d5aa8d 100644 --- a/arch/arm64/mm/kasan_init.c +++ b/arch/arm64/mm/kasan_init.c @@ -21,6 +21,8 @@ #include #include +#if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) + static pgd_t tmp_pg_dir[PTRS_PER_PGD] __initdata __aligned(PGD_SIZE); /* @@ -208,7 +210,7 @@ static void __init clear_pgds(unsigned long start, set_pgd(pgd_offset_k(start), __pgd(0)); } -void __init kasan_init(void) +static void __init kasan_init_shadow(void) { u64 kimg_shadow_start, kimg_shadow_end; u64 mod_shadow_start, mod_shadow_end; @@ -269,6 +271,17 @@ void __init kasan_init(void) memset(kasan_early_shadow_page, KASAN_SHADOW_INIT, PAGE_SIZE); cpu_replace_ttbr1(lm_alias(swapper_pg_dir)); +} + +#else /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS) */ + +static inline void __init kasan_init_shadow(void) { } + +#endif /* CONFIG_KASAN_GENERIC || CONFIG_KASAN_SW_TAGS */ + +void __init kasan_init(void) +{ + kasan_init_shadow(); /* At this point kasan is fully initialized. Enable error messages */ init_task.kasan_depth = 0;