From patchwork Thu Sep 24 22:50:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11798325 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 45F471731 for ; Thu, 24 Sep 2020 22:51:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0DE3A23899 for ; Thu, 24 Sep 2020 22:51:29 +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="Pjdl2utZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0DE3A23899 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 55F5B8E0011; Thu, 24 Sep 2020 18:51:27 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4C0518E0001; Thu, 24 Sep 2020 18:51:27 -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 363778E0011; Thu, 24 Sep 2020 18:51:27 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0191.hostedemail.com [216.40.44.191]) by kanga.kvack.org (Postfix) with ESMTP id 1E1888E0001 for ; Thu, 24 Sep 2020 18:51:27 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id D8D1F4410 for ; Thu, 24 Sep 2020 22:51:26 +0000 (UTC) X-FDA: 77299452972.04.pear48_210ee2527162 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin04.hostedemail.com (Postfix) with ESMTP id B7927800E2D9 for ; Thu, 24 Sep 2020 22:51:26 +0000 (UTC) X-Spam-Summary: 1,0,0,050f64a6e354a449,d41d8cd98f00b204,37cjtxwokcocjwmanhtweupxxpun.lxvurwdg-vvtejlt.xap@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.218.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04y8jngzx8kjffqitoem6s1343a8xocdnuwtxgfg4j6dz6dfd7xcbmeggee5kah.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,DN SBL:neut X-HE-Tag: pear48_210ee2527162 X-Filterd-Recvd-Size: 6259 Received: from mail-ej1-f74.google.com (mail-ej1-f74.google.com [209.85.218.74]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Thu, 24 Sep 2020 22:51:26 +0000 (UTC) Received: by mail-ej1-f74.google.com with SMTP id f17so282322ejq.5 for ; Thu, 24 Sep 2020 15:51:26 -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=WSKmYtIIRd6kxfe5CKlrOgcFvBqAzMyIV7HUyA4uuco=; b=Pjdl2utZ2uKdW6u0Dzi1KrmC+/5RfwoxKbGoz9gCPBjl+b5noBBNfsbspaCt5V0pQY xsbDOs5zHwl3qy3dB4cBcj4iTZppXDHPYO+dSq44lp2650QMtk0TbW4VfjrRyfqOaH2i gcQ25GEI3riSbti1sWMobhhJSM2iMyZry0aTfIHb550f2k09euoTM01n2rxDr90f0bHM lQA8kcYLlqDakrIjEHBh6RQe7W8PZhEPjtNW47F9RyI+n73aoqjYVA/q2zXHs/ggsFbj ABSDtSKicMtEEX8f3AK2aMtBhhpAzK0xakBgOPowZ7Pmk6aQK4eSUM79QUdTvNhO5wMh 8vUA== 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=WSKmYtIIRd6kxfe5CKlrOgcFvBqAzMyIV7HUyA4uuco=; b=GMQfPDB3R+STcqt2qdcMB47EqwHYRObBdbgLQnId8u7boUEpI1nsjTbt/aanAlhFnw awEfdtkAShNXXZ/QnzpUvQPAtI03+RJe7FirthjwM4CE8hGnNo5QGCfOiIitQZG4H+PC DG8yQJyynuHl7byiRGrEv2io24wqXO4kBUsEqwKA2VGhEaMkCahDQg0z5g+aql975m/4 xxpgePuAxEuA8h2vRUGxsjelEiaktr+mX6h0iI/Z9ySmoN7SAv9Iugc59TRyuudUS86Q BamffWv10KiGR1W7RH/WTbeXhjRJmy7wbIboYKEsrHakeYwOTpVM6Iu302hUqLtY7CEu VGRg== X-Gm-Message-State: AOAM532UUSq0rHFG6pLjslhAlNvvHUzO/4kFgTnnHZIG2oNttn7h2Cos 1YNVSDnvty0rG8JKn04NW3ld6kyGCQiuL6go X-Google-Smtp-Source: ABdhPJwUSOgoRD2AOF+tbmV9ovrlIIGaxyO+tontblprCpuBMAygrqcaZHb8CXYXsyJFbiVnU6kaRN3PZng7WHm6 X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a17:906:5008:: with SMTP id s8mr918984ejj.408.1600987884775; Thu, 24 Sep 2020 15:51:24 -0700 (PDT) Date: Fri, 25 Sep 2020 00:50:21 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.681.g6f77f65b4e-goog Subject: [PATCH v3 14/39] 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-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;