Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1462357pxf; Fri, 19 Mar 2021 07:43:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwJfPN8rNgqEo/Md2pOjrlpX7esJF6Q48B62DeZUM+Sr4ShGw6ZFw93Tka1H6UFUgBHi9BX X-Received: by 2002:a17:907:3e8a:: with SMTP id hs10mr4765827ejc.267.1616164984903; Fri, 19 Mar 2021 07:43:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616164984; cv=none; d=google.com; s=arc-20160816; b=G0f2zm1aXobMdLwdryZrtb5WrQq9boDLvJpjyF7x9cKPaCp0LUdXeAcO+lwOhrwFzh AbwKhhivXzyyELgC/8x7/YoEptlQ9GcrbtPZAHuiFLSGzEQGPpdML13FNvcBkuTEe5Ed WcutQzbmAzuBwmAaKNRIDfKFw3G681o9zXMQn69cFmscx2X2mGH+o7Ojc7InyKdHOdUR lSFYuxAomgsbncCU0Nv/j+BpPg/oPQADQ6au0wnTjZFTPEamSDprFwyPyflaBuNrR1bK hdkuqj7iv1HIRBScK4gx3tFMw6dvZMRdzftemMGILyFdXwQZrM60UZy3gv3he5TdhyI3 UQWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qKLiRC30kOdPHC3UyyAEWstGuLi3bp5QolFCwAhhC7s=; b=uWYZQqyb2qqkbKTGFGeKZRMQ9huUydfOMmlqOJxKB1hZnBx5O921caWLhGWQV6nOXL AFUV7coypEom1axpZeGGfMz9ic5gyQFfCcnYRlCMOqER8wtvPgKfmdlQRuszGRbekGrb B4RxWDFDJ/qF4G0tyO3Ip6zAMTTPr17BpEk/VXzk2fYFOC7IQrYc4U08TGGvXZMW8OmT 7Y+YhcuOFHaC2mJLRb1JPXom4QRsXNqh2WTVcWPwbVeyDbt71HOLeKURmIkCF8HwYqlz HVTxv6grztFCfjh/+I4GH6EnUQMmdCmxo8MAD5MVjWuX83a/Y9kzCyGJ6iq6C1DXQALC vkmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@axtens.net header.s=google header.b=RB9K609x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mb15si4390066ejb.147.2021.03.19.07.42.42; Fri, 19 Mar 2021 07:43:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@axtens.net header.s=google header.b=RB9K609x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230295AbhCSOlY (ORCPT + 99 others); Fri, 19 Mar 2021 10:41:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230260AbhCSOlR (ORCPT ); Fri, 19 Mar 2021 10:41:17 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 246D2C06174A for ; Fri, 19 Mar 2021 07:41:17 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id bt4so4753976pjb.5 for ; Fri, 19 Mar 2021 07:41:17 -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=qKLiRC30kOdPHC3UyyAEWstGuLi3bp5QolFCwAhhC7s=; b=RB9K609xBBKHLmVu6q0zBTHCurmpEPtTCvtNqpEq5RNh8dgYMtilKPNGL41//RV7E8 Ua5icRvqI9/RhIxy6y9EtY9nDrLEDq6rlnBiR74X/IkmxlgfJFDHmwfydWhuEZOm65rj a9ceUlQqbrxKJjxyKrQQKLa18u7T8FtnPoA0s= 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=qKLiRC30kOdPHC3UyyAEWstGuLi3bp5QolFCwAhhC7s=; b=Dk91IfpTtmIliyebuLgcami0BfxqidA8nprhEXBxei2iIplUhM35qAoMhnxDQT4VEH FXwf+ion4ORfqUUSC11GRMWeWx54EjhvSEx0/Nay2PXajXaIumatIw7tT7hLH5qZTmoD YkpAIigqncDli93qs26g0ZoxSzZi3JLjdMEjIZZKSvTyVspT/Vxhlpl7/tjL/qH42rvO wkFzDZlwWzGMcLEH5UzjhWOiPsRYQipAi0gfvmeojoamXHnxehBWlT14rnC+eE7th0nT dwi46Z6ktrKiAEpwU6oGvwmqtQ+gQ+/1JY8FzaDE16IRofbdJQ2gxsc7p9/aga72zaSr 4Uyw== X-Gm-Message-State: AOAM531Ey7ie14k0yP4U5iBhSTtWatgU2Uwk5jRAtibexGF8i8leJtAa sYkBcm8N/3PkoldcW08Jnw7ZphJacqEqIg== X-Received: by 2002:a17:90a:7786:: with SMTP id v6mr10062692pjk.16.1616164876553; Fri, 19 Mar 2021 07:41:16 -0700 (PDT) Received: from localhost (2001-44b8-111e-5c00-674e-5c6f-efc9-136d.static.ipv6.internode.on.net. [2001:44b8:111e:5c00:674e:5c6f:efc9:136d]) by smtp.gmail.com with ESMTPSA id w8sm5204443pgk.46.2021.03.19.07.41.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Mar 2021 07:41:16 -0700 (PDT) From: Daniel Axtens To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, christophe.leroy@csgroup.eu, aneesh.kumar@linux.ibm.com, bsingharora@gmail.com Cc: Daniel Axtens Subject: [PATCH v11 3/6] kasan: define and use MAX_PTRS_PER_* for early shadow tables Date: Sat, 20 Mar 2021 01:40:55 +1100 Message-Id: <20210319144058.772525-4-dja@axtens.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210319144058.772525-1-dja@axtens.net> References: <20210319144058.772525-1-dja@axtens.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 6bd8343f0033..68cd6e55c872 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -44,10 +44,22 @@ static inline bool kasan_arch_is_ready(void) { return true; } #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 c4605ac9837b..b4d822dff1fb 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) -- 2.27.0