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: 11926385 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.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 C4354C2D0E4 for ; Mon, 23 Nov 2020 20:08:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 479D120717 for ; Mon, 23 Nov 2020 20:08:56 +0000 (UTC) Authentication-Results: mail.kernel.org; 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 479D120717 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B490C6B0099; Mon, 23 Nov 2020 15:08:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AA90C6B009B; Mon, 23 Nov 2020 15:08:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9467F6B009C; Mon, 23 Nov 2020 15:08:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0068.hostedemail.com [216.40.44.68]) by kanga.kvack.org (Postfix) with ESMTP id 5F4C56B0099 for ; Mon, 23 Nov 2020 15:08:53 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id EE9EE181AEF1A for ; Mon, 23 Nov 2020 20:08:52 +0000 (UTC) X-FDA: 77516771304.30.men43_55009cf27368 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id CD81B180B3C83 for ; Mon, 23 Nov 2020 20:08:52 +0000 (UTC) X-HE-Tag: men43_55009cf27368 X-Filterd-Recvd-Size: 6285 Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Mon, 23 Nov 2020 20:08:52 +0000 (UTC) Received: by mail-qt1-f202.google.com with SMTP id t22so9781712qtq.2 for ; Mon, 23 Nov 2020 12:08:52 -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=W8M0b9XXk+PB/lty8DSg8yPBoZc/8xEiF5Aw0zzJCZerrVrN6Gzdg7aHWv876kM6BE 5WqE6eUPykr+45DS3MnT30SSx4EbcA//SnFaBmEXUqws0Shd33EYxrSyKqzYJGHwV0AM XKrSjoEV8BnSwp/wwi6gEPUF+ePSynQiH+5oCTJbCVtGHrONGz+q4kZEafUXPWIHqu2/ z3+/R2KyLHID9FosKUvYAA1J/isvyZdkS5l2U84fZS9COW3YLTTWTQrnAzX+Izr1LG7L cAGgmB80Swl1+7LTnR2H8YR2mGTDX66+40ddZSRHE8GYRrw5vhYV+FrQjqa53HFKGlrq 2Q/w== X-Gm-Message-State: AOAM5333prFhGg/i6XDuX0hyBm68yV8w39lXZc63t8jzvboXtaHvqvis XuYKrlGs41OQUNk++EUx+o8aAIya/hdScs0D 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 Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Dmitry Vyukov , Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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;