From patchwork Mon Nov 23 20:07:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926727 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=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,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 8DD0FC2D0E4 for ; Mon, 23 Nov 2020 20:44:12 +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 10F5620721 for ; Mon, 23 Nov 2020 20:44:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="xxly5R6H"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="jiY4O8Ae"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="slyXwv8q" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 10F5620721 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=KClqNAPYNJuJYvtzYUI+ccsMh3lei7X7JSQwRWqj7EI=; b=xxly5R6H2z5Ntp20RV8/EaplQ LubvAGB989bnW1no/mjgfXt87CNPuWwyIjQ/ZKsXqzHEPoevTSPw/1hjB0zZo/KNZX9EKtX5svuIt CZZbQXvCWOri9P6k5E27ElPTo/uCAlqsbg3nxayLFIusMNn0HhLEaAmG+Mty6T7Ta2O4WxS2KSzfE FuvArsjpkTti7J0lYNXCS630zbho05jFBpRmSrFPOTbV2EhDWql2ZXI/m/hOK3FKgnrxcikQAbN3W SXYxMfW7r5EdG7wRx/6c3LEVpq298ddN9ZysIH+f+FMMEOmFjVGXFL9BGTObLv9mC+9mQ2WnAMurj GaQsc48Cw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIfI-0005sF-0K; Mon, 23 Nov 2020 20:42:24 +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 1khIPH-0006KM-1M for linux-arm-kernel@merlin.infradead.org; Mon, 23 Nov 2020 20:25:51 +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=cvraDLvCJyIxw98+lt/3PDpM3Nirwfhsw5x/8diNIQE=; b=jiY4O8Ae05DHaSGCe25ws1hQIr YGkWn02/tqehAfXO/kloR1J3mRn8PRDiQax87r8ILJ+2NFwOysKx9S5Jm8wlTtOWDkOto9kmPu8F3 ZTaanpQJm9t3fHJdTzlJYbekmX2ZskZKh1e+E8AN7EUPrGyIZAzrRV+28ZaExsqGiMP8b7rTxWSRO c8jdAiR3NC20Ob3FiCXn+XvOtDn7rY1E1iiXfWwvgnxxrvjgKOjpi/N9yNZ/EW2DAx8Jk97z0y9km ev72QI6SSss5O85dF7Ro6chdqz9Whf5hmXctV1+jg1GaWxhG0f9qplNKcym7otXjlN1TQwEDnHz57 pqlC1AwA==; Received: from mail-qv1-xf49.google.com ([2607:f8b0:4864:20::f49]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1khI8s-0005FH-Lr for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:08:59 +0000 Received: by mail-qv1-xf49.google.com with SMTP id d41so13663283qvc.23 for ; Mon, 23 Nov 2020 12:08:53 -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=cvraDLvCJyIxw98+lt/3PDpM3Nirwfhsw5x/8diNIQE=; b=slyXwv8qG8zCsaA4IB1r95uezXa3k9HnCVXr070V4sFzCEE1mjh/Fw+pHJN4rlUyrc D6NOSxSCaPVKJN7mo61CZQTsjDkbf/8tKZVvkHy8LNC66jzzABGmLmVcxDfwKMeEaH6v DmOZKiibrCS6oW22020O9/15pI0X+vDa4FzXnqq4ZnQjmDVnODlzYShDRG3/MMC3ywB5 Ujif5i6rqkX/OXd5BHDyhD1lZjDwuq3ohYIt3hz64zqk30rEnLnEaA8kDLOhJNHd7GWB wzF8CDFp6oAD3EhPZew1TobghKrw51OOtlOHIsQeCf/3w/SxEUkAP/U9cw6hhca41XmE v7kA== 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=cvraDLvCJyIxw98+lt/3PDpM3Nirwfhsw5x/8diNIQE=; b=t7cGf3SacY1HjmcreJGH3CnTGwXytFfdzoFIJar3kmpsq2/HFNuCV9kdVPsQVir7d/ eSA9jwSpRT/3Ir/JW7JLVPQW7fpn+1wZbS4aQsBW/C5gZNxUMmsAk97LyJKyKK2fHN4J a9snqwFwqJieiy1VrKxl8wkoq3ZCSokZpYGQ8h+XJl1AevpHpiSpqM6nOIIi4Eljd31c j8ROKHIXEwdaH6bF8NzVcx/H92FXMxf6mrnnL4Rzn+Xw5I3sntKwt/u0pJ4sAjA1AJXi WsOpv7T7B3KyugujYWdBPdyEnjcrg/ZOI4/bmHiH+YiYVOVJLMLyRa98Fz9mwWf0dzdP 53xw== X-Gm-Message-State: AOAM532KV3GSoirMOvqrfyjW4LHZVY3jv1Qys8rF9tXOMEmoes07l0DH N9lMGpZSYt8Nhd+bTfkY6Hf4DBAMxUU46eH1 X-Google-Smtp-Source: ABdhPJwPuuM8WrXDAAsPpYWCwtLA0QS3qrDwTNVKFknfRJG4EzSnfbKJpt82bY1nIj58y8ZcrppL+ieB35tTltaG X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:6214:363:: with SMTP id t3mr1130705qvu.9.1606162131658; Mon, 23 Nov 2020 12:08:51 -0800 (PST) Date: Mon, 23 Nov 2020 21:07:38 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v11 14/42] kasan, arm64: only init shadow for software modes From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_200855_277431_D7D02CB5 X-CRM114-Status: GOOD ( 14.67 ) 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 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 Reviewed-by: Alexander Potapenko --- 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;