From patchwork Tue Jun 15 01:47:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 12320385 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,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 40091C2B9F4 for ; Tue, 15 Jun 2021 01:47:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BDCA16140B for ; Tue, 15 Jun 2021 01:47:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BDCA16140B 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 5F9696B0071; Mon, 14 Jun 2021 21:47:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A77F6B0072; Mon, 14 Jun 2021 21:47:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3D3B26B0073; Mon, 14 Jun 2021 21:47:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0212.hostedemail.com [216.40.44.212]) by kanga.kvack.org (Postfix) with ESMTP id 0BEB06B0071 for ; Mon, 14 Jun 2021 21:47:25 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 9B9A8180AD804 for ; Tue, 15 Jun 2021 01:47:25 +0000 (UTC) X-FDA: 78254269842.01.8F848DA Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) by imf10.hostedemail.com (Postfix) with ESMTP id 0A52B40002C1 for ; Tue, 15 Jun 2021 01:47:15 +0000 (UTC) Received: by mail-pg1-f175.google.com with SMTP id t17so10146360pga.5 for ; Mon, 14 Jun 2021 18:47:24 -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=a1pNfOTnuu9q0yP3UcKWGmSF0bOy6BujGvnQzOBamsE=; b=YYXooO3Cnx/8RRR45+QVR/V3WcE3xeUcgsrSiFZ8Bce/7llMZ/Adqd2T0IUdvAugcd RY+YQ19gupEvIYKx525suaotmjelBf+zbDnEqFa02qOVcK3JeIm1KTWd08naiN3zgzao rCgISrOnSh+C1pCvsjM5c7/EWMqh4CojaCtPs= 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=a1pNfOTnuu9q0yP3UcKWGmSF0bOy6BujGvnQzOBamsE=; b=p3uREqyffC3A1QvAQkGS9Ysu5kDCDynmSrZzo2B/6fyG7RruDKYZ0/aR6ssWWb6D7F U3olLqBsIUks5bFB4acJj7OTp4RyIlmyG0HBMV/5k01/PeNRoXN/MkQLYCfPzYLswZV8 9lIu9qv9z5hGhqG35yoFQDlWVGuHOL7rvqc5gWYsHMzN0ZxUx48NsZ7SVUh4C/OrrUKa DgNlq8CWCTWddvleLvu1oE3C3fvNhz71PPYbCw0PceVVqR7UEbuZ0178nobWqxvSPLjO 94G6DH5+3GgZuhzUxapKMng/9zuUU3iHF1gTyl3u8oAEr8aU9HRlLxIPv02MU6J7tUnb dcuA== X-Gm-Message-State: AOAM532GHoVN4/vWumEpbmi5ND7GKN+8Lakoj22U8DTEzobYxLDW0yLb xrI4k5Zc49vgFwnemivhESb/8Q== X-Google-Smtp-Source: ABdhPJzk937KNv1xqdfNNH68yFFGRboFxRzpAnQokFApWsBfy+ttacdd4uZ+sRluc5jsOiD/+Z34tw== X-Received: by 2002:a05:6a00:82:b029:2e9:c6db:e16d with SMTP id c2-20020a056a000082b02902e9c6dbe16dmr1937093pfj.78.1623721643469; Mon, 14 Jun 2021 18:47:23 -0700 (PDT) Received: from localhost ([203.206.29.204]) by smtp.gmail.com with ESMTPSA id n6sm5768289pgt.7.2021.06.14.18.47.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 18:47:23 -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: elver@google.com, Daniel Axtens Subject: [PATCH v12 3/6] kasan: define and use MAX_PTRS_PER_* for early shadow tables Date: Tue, 15 Jun 2021 11:47:02 +1000 Message-Id: <20210615014705.2234866-4-dja@axtens.net> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210615014705.2234866-1-dja@axtens.net> References: <20210615014705.2234866-1-dja@axtens.net> MIME-Version: 1.0 Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=axtens.net header.s=google header.b=YYXooO3C; dmarc=none; spf=pass (imf10.hostedemail.com: domain of dja@axtens.net designates 209.85.215.175 as permitted sender) smtp.mailfrom=dja@axtens.net X-Stat-Signature: q54rb7rwcreshnwsfuia11neij5aqs76 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0A52B40002C1 X-HE-Tag: 1623721635-434240 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)