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: 11895535 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 E05A915E6 for ; Tue, 10 Nov 2020 22:11:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 971B020637 for ; Tue, 10 Nov 2020 22:11:46 +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="Seki+Rjk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 971B020637 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 2BF5C6B0099; Tue, 10 Nov 2020 17:11:44 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 297B46B009A; Tue, 10 Nov 2020 17:11:44 -0500 (EST) 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 1AB926B009B; Tue, 10 Nov 2020 17:11:44 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0053.hostedemail.com [216.40.44.53]) by kanga.kvack.org (Postfix) with ESMTP id DB7F86B0099 for ; Tue, 10 Nov 2020 17:11:43 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 8CEB3180AD806 for ; Tue, 10 Nov 2020 22:11:43 +0000 (UTC) X-FDA: 77469906486.29.quill39_5312e5c272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id 702FA18086CD8 for ; Tue, 10 Nov 2020 22:11:43 +0000 (UTC) X-Spam-Summary: 1,0,0,c38f3eea318fcc42,d41d8cd98f00b204,3hhcrxwokco0pcsgtnzckavddvat.rdbaxcjm-bbzkprz.dgv@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: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.160.202:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04y818rzfn873usw18r6j8cf5znpuocdnuwtxgfg4j6dz6dfd7xcbmeggee5kah.ttub5fd9dg98tx51sjah5j1sd3wyptre8645emgzp9mcxcxaneii6juytrsh9r8.h-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,DNSBL:n eutral,C X-HE-Tag: quill39_5312e5c272f8 X-Filterd-Recvd-Size: 6227 Received: from mail-qt1-f202.google.com (mail-qt1-f202.google.com [209.85.160.202]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 22:11:42 +0000 (UTC) Received: by mail-qt1-f202.google.com with SMTP id 7so8461092qtw.23 for ; Tue, 10 Nov 2020 14:11:42 -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=PWqn6hh9X5kYMfq0T6B/yXdAWzhK8MgUwdODN9zmxRHwMUgnVrk4XuJrgZqNt8MQPv MEHydf2DzEPQmzklh+JgTSQg5mVbNmRW+nWauu/iNPgPRG8MFwrxo3u80mWGGhq+SI9q OZJ1nGppm3w2dSKaqeQu7ALAfquLzIWlPQrjkVUEibsWAHnB0DeHDICOAtiO+8UAVXKx kDwgyLn3C6/Cf94fmg4bLsvvcJVRUuSk7k/9mAaIFN5hmRqdnjMYtR7Zf90k86aPnM2b 1CAdjgZWzwpnypQ3Xiw9LFx26Ojyr13PzNThmZ5P57QiaRAzdinh1T+cWogc5T+zbCf9 E8eQ== X-Gm-Message-State: AOAM5333LhZqAtELqkfFJPMMRqt53Y3oMFDdgeVa8lmQozxsKkAVr/Sg RrDuOVxZRHFvGY2Dj4IGFSYJ+IZtkQhz4yyj 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 Cc: Will Deacon , Vincenzo Frascino , Dmitry Vyukov , Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , Andrew Morton , 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;