From patchwork Fri Nov 13 22:15:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11904999 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 6F816C4742C for ; Fri, 13 Nov 2020 22:22: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 98319207DE for ; Fri, 13 Nov 2020 22:22: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="TNT0kRqy"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="jtDCsSAS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 98319207DE 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=Z/CRw1dJHhLIQ19zIEkp3S+fEUaqKSQ/qyQLJdxyZYM=; b=TNT0kRqyCgmq6499Xau/Ynnh1 V2EQ0Tjciq3aGgy1rAckc8iR526K20jBkYH0W1U3sKxdL8cyUopHBgF2fmPShiekwrAf9vML6rwRU X2Om7jSJVMX+6ZAMZfGBjuxOu+A6PVnLy3hAgT+wKToE5JUU9S1QLVbKIetdbOl6WA0nPUAA1gLbD SoQ/ZuJeMg/+o6fnkffLdnyuv3J/T2F6abIG54iRwsybjTAZVLMG0ntHF8BBhPsy+mp/F54wZ+nl0 DaHGTLhIrR9v/5wRBbNc1SafoG5kdqKLaMWG/pyfv1AUyG6UzK11Pwb6eeHIv3jNdvVo8lpH9dYck DQtMNdkEg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdhRj-0001xo-Ot; Fri, 13 Nov 2020 22:21:31 +0000 Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdhND-0008U3-2D for linux-arm-kernel@lists.infradead.org; Fri, 13 Nov 2020 22:17:04 +0000 Received: by mail-wr1-x44a.google.com with SMTP id f4so4676085wru.21 for ; Fri, 13 Nov 2020 14:16:49 -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=AsJkOJ42mgBB/RpOeNzMBcOw45undU7MsCeikCxw0wY=; b=jtDCsSASkhJrdVvv08oa/t2CYlSg7YgeVr2lKaZdyGX32BYggniNGXDaV36eYvWTpp epHb7jqQJ6jMbsO/xQCDJcMlM9+JJek4IwjWJaFPnGzcYQSnj4kWsrkqFODPftORl+vG 82OlwJrZKti8gt0DfpMCawZLfDa2gdMyzxHtrH2wPwhklupqzkKP8Yctdz7b4XoOToAC SkxwqI7PpE/Q9xlA8PvORQ+pvkc8Hss3fbUQKo3CykYnfTF97iU7Z29Kd5FVF39tbYaq xk61Gs3UAXQIEB06nxxULs2aQ4wr/PDstaScPpqyUCMSJ2a5b+oHdjNzp00Hiqx2kRM1 yHhA== 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=AsJkOJ42mgBB/RpOeNzMBcOw45undU7MsCeikCxw0wY=; b=hIuMlwKbe4CjuDGbQ0+fYUgY9y7s3DHQy0ii/KmsNbbFQl9R67rgh3JMrzspLgO3fJ f/iZ9egDZF3kmqmbJCkCch/yOtJU+HI7P+gZPUe/PsUWuIPsZ7kAV3TkgpkIsJiq1GA0 Y3DKpG478hS/mEpgO1DGzZ+Og5Wde0+ohn1XdRaAPaPY7jw9Vm/bAXTKDXev3zMmVnKS 7Br/1oWbqZb3WYpHdTWtkRdLDw4LxGC8+e//u90A3VBRSnWYJno9UHLZbm3Ajb357D/K uYkPUiDG+UWk63baQ0+Wkeep8WBXAsoGcGqHr7sIC+U6jTV6OHPjwzhRJOUSORtUpfvl 6cYQ== X-Gm-Message-State: AOAM530kQbSvX45JAO+Mhrj98+gmZbs4bDCwlajkp5c+HvFp8oAdSFaD y/OXNYsd039StSoY6YoRLtHdzJzbfyE/JQ5W X-Google-Smtp-Source: ABdhPJxo4MrSFgo4LBQaZOUmymVqMcG1hcFjM18H+V5FrKccNzzw2EezYLoej6MFVLEy0MG6pWsulzFmxKQnz6Du X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:adf:f9c5:: with SMTP id w5mr5786688wrr.69.1605305808039; Fri, 13 Nov 2020 14:16:48 -0800 (PST) Date: Fri, 13 Nov 2020 23:15:42 +0100 In-Reply-To: Message-Id: <3d5b13c846573540ba224405f3f9c6ca6ef98e89.1605305705.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog Subject: [PATCH mm v10 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-20201113_171651_259615_73F3EAF8 X-CRM114-Status: GOOD ( 16.94 ) 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;