From patchwork Tue Nov 10 22:10:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11895613 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 3F0F5C4742C for ; Tue, 10 Nov 2020 22:16:26 +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 87062204FD for ; Tue, 10 Nov 2020 22:16:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="1+wv1rGL"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="Seki+Rjk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 87062204FD 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=V2SxqQXCt2qu0Tj7FwiKn1Z5gUpIkTKbeD5Jygw1vrA=; b=1+wv1rGLAo73KpXD4CKxF4kT+ xtrydmAMyygWfMYV53pME8q9uhlNxbOAkLM5gRdJLBV7AMxkArlbLCGamWhku0/KMXT81twAPhmz8 cbyxUtgCZQGXtacQU3HvT91oPSIU42HurV2rIO0g/rqYp42Dd0pZVFw5ti3HoSeiJMaim779DYLdt jmESYTTk3UmiiamG/wXQDYEetuLcB9pZ81dLY0r5mKA3qGkdLpHjRW91wEZM+Jwd0WJ0B4RE6elcM /B1f6Mr7SQuVWmEJFZnuAFQ2LM74JwJjD/fWj1ccYNMMNdssDS3TS4R6+5Rlj3FXffyU4Bjd6FjLY 9M0f6pT0A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcbvg-0006Kg-8x; Tue, 10 Nov 2020 22:15:56 +0000 Received: from mail-qt1-x84a.google.com ([2607:f8b0:4864:20::84a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcbrd-0004eh-UT for linux-arm-kernel@lists.infradead.org; Tue, 10 Nov 2020 22:12:02 +0000 Received: by mail-qt1-x84a.google.com with SMTP id l67so8476303qte.6 for ; Tue, 10 Nov 2020 14:11:43 -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=g1D3QU7M8sz0sof3NdcHUc7FXuL+sBstwF4DigTeK5Y=; b=Seki+Rjk+6gglclmnRomIxzf7l8MDwdZnmHP40lRdAobeeBoRoYPoGvyQOSyWSjDdM hcdF+y8YrrNhDMLgVNBBNMAVXY5tKt8Z555dTSWt+CpOP6nKK+C081pYfxEDaBe/dTOS GLk8ss4cPTmIfstbDaFk/1o0WPFX5J6TVhAW3SewT5B+hp4IKbNav27L5kT6bXgPRxSt deCnQMSGZrgXYzrgb87nIT+7g4pP3so7a3ifNS90Mz6n1Ez43/1pxJq831oK9DouPXlz 5Vn6OB0RCx+kwlD93G80yveo3aXuZJ2+4noPAmEdAu/GZvadGiDJvc9WJHinakDOXf80 mqrQ== 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=g1D3QU7M8sz0sof3NdcHUc7FXuL+sBstwF4DigTeK5Y=; b=nOwL1blhmTDf50Qz8S3IlZ20rAlS3FaLOyXI89peCBVMet7Vn9wqkHhB/sCbFE+SzY R5oWjFbcPD5l1hWx3+A7nvphfemuK7P6ztWqexMcFPxxip2ShRm+vDiOSdKK1ffQqnfU Csy+fsTi3p2iJtGhFOfN1i/L1nBqeu/UDBNnfxeWpA2d0LMtUFTwWRhy2Ia1A8Sxs/fB gqam8vnYAnngm/iXusNY7MTIhTeyMqhk8TRgNcrKTNw+9uIx09ofbDe4ULEp8GqLI1E2 2QptdakTfmH5V/NSrb4e3KxAvLtllhXdU6B1x4uP+VZ9sw9KCNAYnbZugZuA+L7i6GUy 1EWg== X-Gm-Message-State: AOAM5313G26xcCEf1WUKo7mpuZC/Vqtl0HEmDugJb/k5edupsa2+qOX1 NRxF8wJkzxqD1rfdhs9JxFD7XP7DikiJPohk X-Google-Smtp-Source: ABdhPJzGvaD4Cz55sGiAr39q833nDETwoET26pPoOiQ4AAn2dd6MPHhhSIvSmZbkqYNj//IKqzhWtrPWZcw505/K X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a0c:aa8f:: with SMTP id f15mr20400649qvb.46.1605046302266; Tue, 10 Nov 2020 14:11:42 -0800 (PST) Date: Tue, 10 Nov 2020 23:10:12 +0100 In-Reply-To: Message-Id: <3aae3b3f931618b4418af7992bff1e258e4eb1ad.1605046192.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v9 15/44] 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-20201110_171146_077191_AA381D68 X-CRM114-Status: GOOD ( 16.75 ) 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 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;