From patchwork Tue Sep 15 21:15:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777737 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C824259D for ; Tue, 15 Sep 2020 21:16:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 88B3720770 for ; Tue, 15 Sep 2020 21:16: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="KwKBifrT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 88B3720770 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 5E2B990007F; Tue, 15 Sep 2020 17:16:54 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 56D06900012; Tue, 15 Sep 2020 17:16:54 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4596590007F; Tue, 15 Sep 2020 17:16:54 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0021.hostedemail.com [216.40.44.21]) by kanga.kvack.org (Postfix) with ESMTP id 2ECD5900012 for ; Tue, 15 Sep 2020 17:16:54 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id EA2EB2C07 for ; Tue, 15 Sep 2020 21:16:53 +0000 (UTC) X-FDA: 77266555506.08.vase62_5206bf027114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id C14D21819E793 for ; Tue, 15 Sep 2020 21:16:53 +0000 (UTC) X-Spam-Summary: 1,0,0,c8f15b42c20b1d6c,d41d8cd98f00b204,3rc9hxwokcckfsiwjdpsaqlttlqj.htrqnszc-rrpafhp.twl@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1042:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1542:1593:1594:1711:1730:1747:1777:1792:1981:2194:2199:2282:2393:2559:2562:3138:3139:3140:3141:3142:3152:3353:3865:3866:3871:3872:4117:4250:4321:4605:5007:6261:6653:6742:7875:9969:10004:10400:10450:10455:11026:11232:11473:11657:11658:11914:12043:12048:12296:12297:12438:12555:12895:14096:14097:14181:14394:14659:14721:19904:19999:21080:21365:21433:21444:21451:21627:21772:30054,0,RBL:209.85.128.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04y865pjqhaqbfxsq5cxfm9q5tinkocdnuwtxgfg4j6dz6dfd7xcbmeggee4w3k.3bo7puu9dg98tx51sjah5j1sd3qe7xcujgm5emgzp9mcxcxaneii6jwwpmxftgo.c-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DN SBL:neut X-HE-Tag: vase62_5206bf027114 X-Filterd-Recvd-Size: 6201 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:16:53 +0000 (UTC) Received: by mail-wm1-f74.google.com with SMTP id y18so225114wma.4 for ; Tue, 15 Sep 2020 14:16:52 -0700 (PDT) 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=IohLAiQritHYDUsEyFojJvH0Itf5Q6tgZwjJNHAxVZI=; b=KwKBifrTZVrDXaHnoOdwHc/M5dni2e323Mp+mNPmCsK0W8O7Y8VXJVi3AE5Jo+ENnk EkGS8GuntJzkIIof+6wo2+RelNqEkT8AzAWR+IYpLFmN9+9mhgXciRNcQQBmCWFxXwOW mm18KrwH9w5clj7/igQ6hoHVFcw9+8yJ1xmQfA93dgtSY5QSor7XXk5jyo+crlVKAWnp btvVEGqWSJknyo34NzbkH+W5g8uCKLArOGU++xd3ifOZaGtxnNyjf/e3LxwCnrnbNtRQ 4iW7Q/YXlGnFBNG8pOB2sAvLVRvRfNRGuUGU+X9u/OAZqVMesvc6GxLKobPKyE9Sgi9E xvGA== 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=IohLAiQritHYDUsEyFojJvH0Itf5Q6tgZwjJNHAxVZI=; b=PgBbMkQWjtb76LeiUJhfx7bOlTPJUkn55BQGIlz25kz0BxWNlgX9smaMDrpJmo8R3m LLgWTSFrS5g6xSlfkGJ9et9bhYEe1cFtu8H3suFpM2s0uqeYzmoZhXcpptPqv1Nt6bC8 Mx6RUQPJ1Q5L/4UWQVhe9ekhiufpvc9aqVZnoW3Him+saJ/5VP90r4Tlud7kjhr0fYfW HvCWs4t3QY4nxaMITJ37yMEe2VXnO7gJtZ/05jyD/7y1oLVZejSHw5AAnJgQ6dxrzKkj mkYy2ii45R+vBTxJ8hydG7ATPkGcHOdtEUWcBfY1VmGBnECTARKCf/R5LnDfJIIklmuN Z1yg== X-Gm-Message-State: AOAM533NktMPDmDJYhormQakmXKcSRr4M6sa3bijkNXZf5erRtfEjeb9 HHZLVYQx9EzmsYq0o8z+bxR6+68XCBI8FsiQ X-Google-Smtp-Source: ABdhPJw1CmWQAP9tJjtlXp/HfdjCVKqfCNtO3HPAI+fWlLqJnWhmg0N55nUWjB6VKGB/XuTbHQN3196z0TpRBXCx X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:adf:cf01:: with SMTP id o1mr23727593wrj.421.1600204612062; Tue, 15 Sep 2020 14:16:52 -0700 (PDT) Date: Tue, 15 Sep 2020 23:15:54 +0200 In-Reply-To: Message-Id: <2d009928ca496df0d7c061749c6a74d9ad36588c.1600204505.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 12/37] kasan, arm64: only init shadow for software modes From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: C14D21819E793 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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 --- 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 7291b26ce788..4d35eaf3ec97 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;