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)