From patchwork Wed Jun 16 08:02:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 12324467 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.6 required=3.0 tests=BAYES_00,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 15D6FC48BE8 for ; Wed, 16 Jun 2021 08:02:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C0B666054E for ; Wed, 16 Jun 2021 08:02:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C0B666054E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=axtens.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 636526B0072; Wed, 16 Jun 2021 04:02:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 60D2F6B0073; Wed, 16 Jun 2021 04:02:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 385B26B0074; Wed, 16 Jun 2021 04:02:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0208.hostedemail.com [216.40.44.208]) by kanga.kvack.org (Postfix) with ESMTP id 8359C6B0072 for ; Wed, 16 Jun 2021 04:02:55 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 17F6B6D93 for ; Wed, 16 Jun 2021 08:02:55 +0000 (UTC) X-FDA: 78258845910.01.FEECA49 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf24.hostedemail.com (Postfix) with ESMTP id ADBAFA000261 for ; Wed, 16 Jun 2021 08:02:44 +0000 (UTC) Received: by mail-pl1-f175.google.com with SMTP id v12so706364plo.10 for ; Wed, 16 Jun 2021 01:02:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FhcxQma+NItwG5Mp37m/KF4tp14MA8dMkKZlGGIww7w=; b=hJE2AePhitLJVg38bm97ceVZi5FIj9UG7cAFa6I89qpLoHOqs1eZo/sgHrTjHCz5vc Z0OB2QrJBz1ePSDeeTBoNAwwTmCWMao+fbzv6i6nf+j/nn2Z/6pH2J/atzq4c7e26OtD 9Ge5u0WlHxE6DHdxeFWDpzw27Ij3DBzy52+fg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FhcxQma+NItwG5Mp37m/KF4tp14MA8dMkKZlGGIww7w=; b=REy9YEAmQ9+wz7LGo0jjHx3b9HvCQVt05vuarTYI5E3LqcLumtA991j/d+jNRApvAT EyKks0GrbQ5boE+8WGLvB0FbYX2IcQlp4Np6xstlMOWx4PXvwba6OlwpNSNuyqZx9isd HYcvUpHuuQyimJg4zt8e+sbNesmgOF58L/xk4nObktHd4XLMsQ8J+nEs8epAZ5n7zRVA F+fBkDiSO5bjKKfJdQpyNg8VBD3eKdNqr/h05j9YIM4EiT/y85xzc66L5sSRcypqwbtI s90CQkXShZN38YrK6S4ief1WrVZqCI/wkYWiiUVzi7iIpGhiNyFhcKiRkZn2z1ygBQbe uDNA== X-Gm-Message-State: AOAM531JHMpV4qmNTAHjN403KvxjnT9NwGneDVI6DaBlr0d6LZxekr+e yNFy93aDSgpMfCGumbRiTkOmkg== X-Google-Smtp-Source: ABdhPJylA3muk5yAlLrF6ZcVpEMYtRnxGVKqGdGUGSYY+nWAMfaRgU5cUbiR3WYP/UOF26ki7J90ZQ== X-Received: by 2002:a17:90a:708a:: with SMTP id g10mr9621854pjk.108.1623830573897; Wed, 16 Jun 2021 01:02:53 -0700 (PDT) Received: from localhost ([203.206.29.204]) by smtp.gmail.com with ESMTPSA id v15sm1595449pgf.26.2021.06.16.01.02.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Jun 2021 01:02:53 -0700 (PDT) From: Daniel Axtens To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com, elver@google.com, akpm@linux-foundation.org, andreyknvl@gmail.com Cc: linuxppc-dev@lists.ozlabs.org, christophe.leroy@csgroup.eu, aneesh.kumar@linux.ibm.com, bsingharora@gmail.com, Daniel Axtens Subject: [PATCH v13 1/3] kasan: allow an architecture to disable inline instrumentation Date: Wed, 16 Jun 2021 18:02:42 +1000 Message-Id: <20210616080244.51236-2-dja@axtens.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210616080244.51236-1-dja@axtens.net> References: <20210616080244.51236-1-dja@axtens.net> MIME-Version: 1.0 Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=axtens.net header.s=google header.b=hJE2AePh; spf=pass (imf24.hostedemail.com: domain of dja@axtens.net designates 209.85.214.175 as permitted sender) smtp.mailfrom=dja@axtens.net; dmarc=none X-Stat-Signature: 965ebzs5x8fy195yda4xtyfda6s1tdr9 X-Rspamd-Queue-Id: ADBAFA000261 X-Rspamd-Server: rspam06 X-HE-Tag: 1623830564-173551 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: For annoying architectural reasons, it's very difficult to support inline instrumentation on powerpc64.* Add a Kconfig flag to allow an arch to disable inline. (It's a bit annoying to be 'backwards', but I'm not aware of any way to have an arch force a symbol to be 'n', rather than 'y'.) We also disable stack instrumentation in this case as it does things that are functionally equivalent to inline instrumentation, namely adding code that touches the shadow directly without going through a C helper. * on ppc64 atm, the shadow lives in virtual memory and isn't accessible in real mode. However, before we turn on virtual memory, we parse the device tree to determine which platform and MMU we're running under. That calls generic DT code, which is instrumented. Inline instrumentation in DT would unconditionally attempt to touch the shadow region, which we won't have set up yet, and would crash. We can make outline mode wait for the arch to be ready, but we can't change what the compiler inserts for inline mode. Signed-off-by: Daniel Axtens Reviewed-by: Marco Elver --- lib/Kconfig.kasan | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan index cffc2ebbf185..cb5e02d09e11 100644 --- a/lib/Kconfig.kasan +++ b/lib/Kconfig.kasan @@ -12,6 +12,15 @@ config HAVE_ARCH_KASAN_HW_TAGS config HAVE_ARCH_KASAN_VMALLOC bool +config ARCH_DISABLE_KASAN_INLINE + bool + help + Sometimes an architecture might not be able to support inline + instrumentation but might be able to support outline instrumentation. + This option allows an architecture to prevent inline and stack + instrumentation from being enabled. + + config CC_HAS_KASAN_GENERIC def_bool $(cc-option, -fsanitize=kernel-address) @@ -130,6 +139,7 @@ config KASAN_OUTLINE config KASAN_INLINE bool "Inline instrumentation" + depends on !ARCH_DISABLE_KASAN_INLINE help Compiler directly inserts code checking shadow memory before memory accesses. This is faster than outline (in some workloads @@ -141,6 +151,7 @@ endchoice config KASAN_STACK bool "Enable stack instrumentation (unsafe)" if CC_IS_CLANG && !COMPILE_TEST depends on KASAN_GENERIC || KASAN_SW_TAGS + depends on !ARCH_DISABLE_KASAN_INLINE default y if CC_IS_GCC help The LLVM stack address sanitizer has a know problem that @@ -154,6 +165,9 @@ config KASAN_STACK but clang users can still enable it for builds without CONFIG_COMPILE_TEST. On gcc it is assumed to always be safe to use and enabled by default. + If the architecture disables inline instrumentation, this is + also disabled as it adds inline-style instrumentation that + is run unconditionally. config KASAN_SW_TAGS_IDENTIFY bool "Enable memory corruption identification" From patchwork Wed Jun 16 08:02:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 12324469 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.6 required=3.0 tests=BAYES_00,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 0BC10C49361 for ; Wed, 16 Jun 2021 08:03:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B6A3361159 for ; Wed, 16 Jun 2021 08:03:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B6A3361159 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=axtens.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3CB2E6B0073; Wed, 16 Jun 2021 04:03:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 301866B0074; Wed, 16 Jun 2021 04:03:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 108ED6B0075; Wed, 16 Jun 2021 04:03:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0006.hostedemail.com [216.40.44.6]) by kanga.kvack.org (Postfix) with ESMTP id D3F7C6B0073 for ; Wed, 16 Jun 2021 04:02:59 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 738506D93 for ; Wed, 16 Jun 2021 08:02:59 +0000 (UTC) X-FDA: 78258846078.20.181F647 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf15.hostedemail.com (Postfix) with ESMTP id 9310AA000241 for ; Wed, 16 Jun 2021 08:02:54 +0000 (UTC) Received: by mail-pj1-f44.google.com with SMTP id x21-20020a17090aa395b029016e25313bfcso1287362pjp.2 for ; Wed, 16 Jun 2021 01:02:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rH421sL9ZKJVhIfbMwMWVv41eEYVWpLNRPNIYH4GF8E=; b=rWR8kokaYW/1Ws03OSl7FQcv6NX3J8PeEPGquUZjPZp0EiXN1xoAn93b34g1mUVDiV bZsjpSplWHUoBNaL9eEUpaD7KbqnSMVjlFktezoH5yM/kKsrV7iOi23E5xFRZB+3gE1Y GLPYTe2unRYzcu4E1eViAN4Tm54h1Tt9hUB9g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rH421sL9ZKJVhIfbMwMWVv41eEYVWpLNRPNIYH4GF8E=; b=JDm6hK/HO8LdVSZV2PkTmbamq1Z4A4TGqVR8eGsYkhKqduVmPWFL9vZ0AoCSZVkHjT y+kSaVGpIluq9SF4JIPRNvXNGOr9B7ptb6PE7H3HX2NJO2+/NCAzSSc6O/sLHUp1Xww8 GtowRAUtWwTOBU/7xSQoePBzS/9weCSe7bx5Yydoab5R+HMfafV269aOg7pe+vthuNu5 wkPPVLXhleSSw9YfRHeETfFsxo7BnyElGFwsN/56pYjU9478nXQ3okOufaUKyyKBMXz0 IzS45mqXdapQcEjuFY4P3YbzumdABYnv6UuRNjWXo3hTf/My/9wNWglPF24ummA8Ibcd RqIQ== X-Gm-Message-State: AOAM533sWxDNP/2+/nTS8w4anBm0WtgxU7T3aZUiU+e8WR6narrmeibK KYme0955btMBiL8e2ATs6eT5Kw== X-Google-Smtp-Source: ABdhPJwHBPwbeGLF51zGBnN9cTF9GK5Qyaefc/d+iF3iBApps1JGiW3hB5aVTX0B+7hJFgq58tPxIw== X-Received: by 2002:a17:90a:29e2:: with SMTP id h89mr3700284pjd.93.1623830578010; Wed, 16 Jun 2021 01:02:58 -0700 (PDT) Received: from localhost ([203.206.29.204]) by smtp.gmail.com with ESMTPSA id z3sm1398579pgl.77.2021.06.16.01.02.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Jun 2021 01:02:57 -0700 (PDT) From: Daniel Axtens To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com, elver@google.com, akpm@linux-foundation.org, andreyknvl@gmail.com Cc: linuxppc-dev@lists.ozlabs.org, christophe.leroy@csgroup.eu, aneesh.kumar@linux.ibm.com, bsingharora@gmail.com, Daniel Axtens , "Aneesh Kumar K . V" Subject: [PATCH v13 2/3] kasan: allow architectures to provide an outline readiness check Date: Wed, 16 Jun 2021 18:02:43 +1000 Message-Id: <20210616080244.51236-3-dja@axtens.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210616080244.51236-1-dja@axtens.net> References: <20210616080244.51236-1-dja@axtens.net> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 9310AA000241 X-Stat-Signature: 8ibzb3s9ispsoggtruyu6yqwskibxi51 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=axtens.net header.s=google header.b=rWR8koka; dmarc=none; spf=pass (imf15.hostedemail.com: domain of dja@axtens.net designates 209.85.216.44 as permitted sender) smtp.mailfrom=dja@axtens.net X-HE-Tag: 1623830574-736976 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: Allow architectures to define a kasan_arch_is_ready() hook that bails out of any function that's about to touch the shadow unless the arch says that it is ready for the memory to be accessed. This is fairly uninvasive and should have a negligible performance penalty. This will only work in outline mode, so an arch must specify ARCH_DISABLE_KASAN_INLINE if it requires this. Cc: Balbir Singh Cc: Aneesh Kumar K.V Suggested-by: Christophe Leroy Signed-off-by: Daniel Axtens Reviewed-by: Marco Elver --- I discuss the justfication for this later in the series. Also, both previous RFCs for ppc64 - by 2 different people - have needed this trick! See: - https://lore.kernel.org/patchwork/patch/592820/ # ppc64 hash series - https://patchwork.ozlabs.org/patch/795211/ # ppc radix series --- mm/kasan/common.c | 4 ++++ mm/kasan/generic.c | 3 +++ mm/kasan/kasan.h | 4 ++++ mm/kasan/shadow.c | 8 ++++++++ 4 files changed, 19 insertions(+) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 10177cc26d06..0ad615f3801d 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -331,6 +331,10 @@ static inline bool ____kasan_slab_free(struct kmem_cache *cache, void *object, u8 tag; void *tagged_object; + /* Bail if the arch isn't ready */ + if (!kasan_arch_is_ready()) + return false; + tag = get_tag(object); tagged_object = object; object = kasan_reset_tag(object); diff --git a/mm/kasan/generic.c b/mm/kasan/generic.c index 53cbf28859b5..c3f5ba7a294a 100644 --- a/mm/kasan/generic.c +++ b/mm/kasan/generic.c @@ -163,6 +163,9 @@ static __always_inline bool check_region_inline(unsigned long addr, size_t size, bool write, unsigned long ret_ip) { + if (!kasan_arch_is_ready()) + return true; + if (unlikely(size == 0)) return true; diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index 8f450bc28045..19323a3d5975 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -449,6 +449,10 @@ static inline void kasan_poison_last_granule(const void *address, size_t size) { #endif /* CONFIG_KASAN_GENERIC */ +#ifndef kasan_arch_is_ready +static inline bool kasan_arch_is_ready(void) { return true; } +#endif + /* * Exported functions for interfaces called from assembly or from generated * code. Declarations here to avoid warning about missing declarations. diff --git a/mm/kasan/shadow.c b/mm/kasan/shadow.c index 082ee5b6d9a1..3c7f7efe6f68 100644 --- a/mm/kasan/shadow.c +++ b/mm/kasan/shadow.c @@ -73,6 +73,10 @@ void kasan_poison(const void *addr, size_t size, u8 value, bool init) { void *shadow_start, *shadow_end; + /* Don't touch the shadow memory if arch isn't ready */ + if (!kasan_arch_is_ready()) + return; + /* * Perform shadow offset calculation based on untagged address, as * some of the callers (e.g. kasan_poison_object_data) pass tagged @@ -99,6 +103,10 @@ EXPORT_SYMBOL(kasan_poison); #ifdef CONFIG_KASAN_GENERIC void kasan_poison_last_granule(const void *addr, size_t size) { + /* Don't touch the shadow memory if arch isn't ready */ + if (!kasan_arch_is_ready()) + return; + if (size & KASAN_GRANULE_MASK) { u8 *shadow = (u8 *)kasan_mem_to_shadow(addr + size); *shadow = size & KASAN_GRANULE_MASK; From patchwork Wed Jun 16 08:02:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 12324471 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.6 required=3.0 tests=BAYES_00,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 D6DA5C48BE5 for ; Wed, 16 Jun 2021 08:03:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7BDDA6054E for ; Wed, 16 Jun 2021 08:03:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7BDDA6054E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=axtens.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 165036B0074; Wed, 16 Jun 2021 04:03:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 12C106B0075; Wed, 16 Jun 2021 04:03:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DFDDC6B0078; Wed, 16 Jun 2021 04:03:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0150.hostedemail.com [216.40.44.150]) by kanga.kvack.org (Postfix) with ESMTP id A4CEC6B0074 for ; Wed, 16 Jun 2021 04:03:03 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 46B7A8249980 for ; Wed, 16 Jun 2021 08:03:03 +0000 (UTC) X-FDA: 78258846246.22.C4EC3BE Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by imf12.hostedemail.com (Postfix) with ESMTP id 5D976546 for ; Wed, 16 Jun 2021 08:02:49 +0000 (UTC) Received: by mail-pf1-f180.google.com with SMTP id g6so1569599pfq.1 for ; Wed, 16 Jun 2021 01:03:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j1YLXpeuYLLATMRsuPzyJcK3SDVQ5TMCmimmfEEEFlM=; b=rVBqDrHDojw1oOxvtGWdyVPwGWo2mMUr5IgajW4/qA4lE1M4G4tEBk3XJzv0y7ko3e Fz6GvlzHMtBiLEQVONvxx5QdpBJP3sdvzKkZ6WuE/e56rSuPyGDhIk/gXRXRLPqVm02U VDeEj9eDuhM941UL2SJm4SP6rH2lgPfnF9k0w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=j1YLXpeuYLLATMRsuPzyJcK3SDVQ5TMCmimmfEEEFlM=; b=DybSY6L5oVZ/LVeDIUqf5Ee7oWtWrpjsgo50D7J/pSaGZ8gTtz1dqgmgVuunBYCMuq lECnceCqXsqOCmQ38YtCPHbatEAuHGfk5N/Pw+FRGpDHrMSlXJRDItj83lz1XQRZTP1M mAcozD4LYk8Wg+rtLGX8fdJa8o9CVBfb6NWv9/pllEW11/K21fxFz+F9XAsAqyqvKFEZ CVG4tN1fMINqma2Z5vzCKuXONqN3fY8JvvsYIyL/+dA3NMwllLaQRVT3+y4gu5VtBocg +SmJkqprQuLLiUHaKF1/anuQkp57J1ibCTJ++z1DV2YkpGek79DJ1pzMEB3JRvoWprMT xc8g== X-Gm-Message-State: AOAM5321fJMAAGzKBae0KedRBLVlA5IA0SJ8OLVPOJvhL0wj4nehV/2X uZ4u/WURAzPiPhoBop7V6vXmww== X-Google-Smtp-Source: ABdhPJxoCRhpWmzvnliIbHWAX/WGlzPbnJ/iqyfsGmCCe8L+UNRUKHGC27ecG9iS94G7m1ZOmRlU9A== X-Received: by 2002:a62:e307:0:b029:2f8:d49:7b65 with SMTP id g7-20020a62e3070000b02902f80d497b65mr8326880pfh.48.1623830582233; Wed, 16 Jun 2021 01:03:02 -0700 (PDT) Received: from localhost ([203.206.29.204]) by smtp.gmail.com with ESMTPSA id g17sm1466688pgh.61.2021.06.16.01.03.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Jun 2021 01:03:01 -0700 (PDT) From: Daniel Axtens To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com, elver@google.com, akpm@linux-foundation.org, andreyknvl@gmail.com Cc: linuxppc-dev@lists.ozlabs.org, christophe.leroy@csgroup.eu, aneesh.kumar@linux.ibm.com, bsingharora@gmail.com, Daniel Axtens Subject: [PATCH v13 3/3] kasan: define and use MAX_PTRS_PER_* for early shadow tables Date: Wed, 16 Jun 2021 18:02:44 +1000 Message-Id: <20210616080244.51236-4-dja@axtens.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210616080244.51236-1-dja@axtens.net> References: <20210616080244.51236-1-dja@axtens.net> MIME-Version: 1.0 Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=axtens.net header.s=google header.b=rVBqDrHD; dmarc=none; spf=pass (imf12.hostedemail.com: domain of dja@axtens.net designates 209.85.210.180 as permitted sender) smtp.mailfrom=dja@axtens.net X-Rspamd-Server: rspam02 X-Stat-Signature: 57j9o419r53bejckxfxo7psp7ukapttm X-Rspamd-Queue-Id: 5D976546 X-HE-Tag: 1623830569-623368 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: powerpc has a variable number of PTRS_PER_*, set at runtime based on the MMU that the kernel is booted under. This means the PTRS_PER_* are no longer constants, and therefore breaks the build. Define default MAX_PTRS_PER_*s in the same style as MAX_PTRS_PER_P4D. As KASAN is the only user at the moment, just define them in the kasan header, and have them default to PTRS_PER_* unless overridden in arch code. Suggested-by: Christophe Leroy Suggested-by: Balbir Singh Reviewed-by: Christophe Leroy Reviewed-by: Balbir Singh Signed-off-by: Daniel Axtens --- include/linux/kasan.h | 18 +++++++++++++++--- mm/kasan/init.c | 6 +++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index 768d7d342757..fd65f477ac92 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -40,10 +40,22 @@ struct kunit_kasan_expectation { #define PTE_HWTABLE_PTRS 0 #endif +#ifndef MAX_PTRS_PER_PTE +#define MAX_PTRS_PER_PTE PTRS_PER_PTE +#endif + +#ifndef MAX_PTRS_PER_PMD +#define MAX_PTRS_PER_PMD PTRS_PER_PMD +#endif + +#ifndef MAX_PTRS_PER_PUD +#define MAX_PTRS_PER_PUD PTRS_PER_PUD +#endif + extern unsigned char kasan_early_shadow_page[PAGE_SIZE]; -extern pte_t kasan_early_shadow_pte[PTRS_PER_PTE + PTE_HWTABLE_PTRS]; -extern pmd_t kasan_early_shadow_pmd[PTRS_PER_PMD]; -extern pud_t kasan_early_shadow_pud[PTRS_PER_PUD]; +extern pte_t kasan_early_shadow_pte[MAX_PTRS_PER_PTE + PTE_HWTABLE_PTRS]; +extern pmd_t kasan_early_shadow_pmd[MAX_PTRS_PER_PMD]; +extern pud_t kasan_early_shadow_pud[MAX_PTRS_PER_PUD]; extern p4d_t kasan_early_shadow_p4d[MAX_PTRS_PER_P4D]; int kasan_populate_early_shadow(const void *shadow_start, diff --git a/mm/kasan/init.c b/mm/kasan/init.c index 348f31d15a97..cc64ed6858c6 100644 --- a/mm/kasan/init.c +++ b/mm/kasan/init.c @@ -41,7 +41,7 @@ static inline bool kasan_p4d_table(pgd_t pgd) } #endif #if CONFIG_PGTABLE_LEVELS > 3 -pud_t kasan_early_shadow_pud[PTRS_PER_PUD] __page_aligned_bss; +pud_t kasan_early_shadow_pud[MAX_PTRS_PER_PUD] __page_aligned_bss; static inline bool kasan_pud_table(p4d_t p4d) { return p4d_page(p4d) == virt_to_page(lm_alias(kasan_early_shadow_pud)); @@ -53,7 +53,7 @@ static inline bool kasan_pud_table(p4d_t p4d) } #endif #if CONFIG_PGTABLE_LEVELS > 2 -pmd_t kasan_early_shadow_pmd[PTRS_PER_PMD] __page_aligned_bss; +pmd_t kasan_early_shadow_pmd[MAX_PTRS_PER_PMD] __page_aligned_bss; static inline bool kasan_pmd_table(pud_t pud) { return pud_page(pud) == virt_to_page(lm_alias(kasan_early_shadow_pmd)); @@ -64,7 +64,7 @@ static inline bool kasan_pmd_table(pud_t pud) return false; } #endif -pte_t kasan_early_shadow_pte[PTRS_PER_PTE + PTE_HWTABLE_PTRS] +pte_t kasan_early_shadow_pte[MAX_PTRS_PER_PTE + PTE_HWTABLE_PTRS] __page_aligned_bss; static inline bool kasan_pte_table(pmd_t pmd)