From patchwork Mon Nov 2 16:04:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11874397 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 3DD5CC388F2 for ; Mon, 2 Nov 2020 16:12:41 +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 9972E206E3 for ; Mon, 2 Nov 2020 16:12:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="MfqC+qYS"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="T32phW7q" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9972E206E3 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=vcpagapbsoTQt06ywyafMRkkuocH3R5e2oJTmyug0fI=; b=MfqC+qYSHzr/djCnBR7BI2hXV Hq8kpdr2Z6v4i3n1Hl3EOA1accXjgKUTWdZQ7xKcaX9WBKj+GcmZ8ZRlhvDCdot0oj0ZP4sjkIh1t /OjjWz57iNAbhW3WzRKIrufTIkXpstvVrtIMF5T13WU6O3Vq6dpyV57qD6TQtYrC9qW4VBNt7EEwc CmFJ0XfFwbDfzoLqiks6DvdzvivQ0aOCVB9+IEq5I2n0asJolkmBWSWiw8XPaEz1+HtRuoHUZWkCa AfA/tSDnGH+VFmZEr2Lt2z0o/GRcKnLgsNBoTA7pCyaXc1WPBxvNfgkPcBZaMAMHpesrEy6eFL4jX sjntO5hjw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kZcPQ-0001NY-Qu; Mon, 02 Nov 2020 16:10:17 +0000 Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kZcKl-0006mT-0o for linux-arm-kernel@lists.infradead.org; Mon, 02 Nov 2020 16:05:38 +0000 Received: by mail-wm1-x349.google.com with SMTP id 3so1040904wms.9 for ; Mon, 02 Nov 2020 08:05:25 -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=d4Yc7AItymQNyKGF4tg/i8f/qZM6X5xLr7PA4bM2pG0=; b=T32phW7qTdq9kcSd5GtgEhtNi/LmGt8NgjkKImgHLRYKvZr1tqLQXwsKMPf0jCu8Ag dWW5TAZ6hw+UWMg/v271CSQcU1pOccja0Ph2S5m+Iz85trmJ+G2wdbOR1AVfgrfOuGc2 fWuk8f1Nl3tEXY38xe2uh//fsCnFP/J7dUjvkOvRpzy6nBJl7a//pKnS7x3RawD7yKrB GI6Jt74mRqMe598MA98i1+mHERWwGmHvxSMWG3/z94X/kF0YhN7JDjrH8791K0lCQyxi fpHJx0cyvyKW/jd+2mLuDBK1lLPiP/485JyEcbmVq9gfrFIm8X2s5g0zx9FOSz49Yk7N rwfQ== 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=d4Yc7AItymQNyKGF4tg/i8f/qZM6X5xLr7PA4bM2pG0=; b=uQB+izOzpC9lvyanKyurIdQM5WwKUeXFdDkBO19hKk2YuDX60dsTCn3+87j61rr2LS 4+i2SeQMKA6jhM4FdZNLueCheLutBZmDG5nDeIN+O7NCdLbNyVSwx0PvDVeDSDmp8fzu vaUpI6AAztWlhKRD2VVXTtMDPhEKbvNlmHwpL1rkrhtViOqENwmzy5AxhXQri3nA6Tvb U82Jy0SWc0xlhXBDm5VPsfArebkQ8PZOQy/rspkkgR3nmUBmZSa258u0cmx69sGIu8LQ SpoNszzfGLIuH+35YeAhmx6dRuFzmJ6XoOaQzfhjhzuiZynIwd9whGBhdD1KCkn0KfYe jZrw== X-Gm-Message-State: AOAM530dKTDKqEQFVMIM/VvqXgfZuBRy26A/7EUBjrpifE9DDNlDAV8I COh1vMqRiG0/89BHryYJROIjDmgjHVI6DGdF X-Google-Smtp-Source: ABdhPJzF83tj7y9dhim3vCvql2zL9bIoIDWntnLoO7Tf6GtiQCiGTSmsgBQh8jTP4UlZRmOKJxUIWliBUq+bAbwh X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:adf:e685:: with SMTP id r5mr22556902wrm.340.1604333124197; Mon, 02 Nov 2020 08:05:24 -0800 (PST) Date: Mon, 2 Nov 2020 17:04:04 +0100 In-Reply-To: Message-Id: <02c3a4f12747cfdd57e75c3dec2c62482e521d38.1604333009.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v7 24/41] kasan, arm64: only init shadow for software modes From: Andrey Konovalov To: Catalin Marinas , Will Deacon X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201102_110527_216404_7E43CFB6 X-CRM114-Status: GOOD ( 17.01 ) 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 , Elena Petrova , Andrey Konovalov , Kevin Brodsky , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , 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 --- 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;