From patchwork Tue Dec 1 16:16:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 11943227 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.5 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 03D85C64E7B for ; Tue, 1 Dec 2020 16:16:54 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6588922240 for ; Tue, 1 Dec 2020 16:16:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=axtens.net header.i=@axtens.net header.b="o7pY89Eh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6588922240 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 E1A068D0007; Tue, 1 Dec 2020 11:16:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DEF648D0001; Tue, 1 Dec 2020 11:16:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C689F8D0007; Tue, 1 Dec 2020 11:16:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0111.hostedemail.com [216.40.44.111]) by kanga.kvack.org (Postfix) with ESMTP id AD7798D0001 for ; Tue, 1 Dec 2020 11:16:52 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 6ECA51E08 for ; Tue, 1 Dec 2020 16:16:52 +0000 (UTC) X-FDA: 77545217064.02.metal33_4606bcf273ab Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id 4F01210097AA2 for ; Tue, 1 Dec 2020 16:16:52 +0000 (UTC) X-HE-Tag: metal33_4606bcf273ab X-Filterd-Recvd-Size: 5928 Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Tue, 1 Dec 2020 16:16:51 +0000 (UTC) Received: by mail-pl1-f193.google.com with SMTP id k5so1393513plt.6 for ; Tue, 01 Dec 2020 08:16:50 -0800 (PST) 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=TxkOT8OtKTLEt+0Y1UXvfZzv0Ces9ugsvAtyOyjKCDs=; b=o7pY89EhGS4FuHeYUc4jpx36B7f2KYBxNKbOq/4jgMoCFfguMxOvBMBLcu6H5mLAWc x/anTEED9T+2uj+ZTydclqxODCV7E9yeLDG2+pAKs4HNDtsloEY9VrXDuHVr1c+k3B1w O37oyMdq1VuQiHgJUZWxM8S6fHprDAIBMtAbQ= 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=TxkOT8OtKTLEt+0Y1UXvfZzv0Ces9ugsvAtyOyjKCDs=; b=jlVDybKW8SsLDbZ7vilRHMYt8DsimZfalOI4Ah8s1iyIxDyiNUiyo2qNisd4hzVltB 9BpEGTGz58Mo/oz84rGhWuuoBda1R3wHXOqmX6nM8aZQJK6flgXdOytwoP8qllZO0bS8 Da5RzgVt4siobPbNPjPP12/jNu96jwPQcb7iUIgVzxtSwM6lG/dkiS2XEzdfMqgZVye9 Xa1drrxCX0L/KIgN6X0eao6/eyA8415HC/OLqACgg7qvhnEr1FcG8pbs25PFq1UCj5bz sLytAGOdvGvUC5ItwFIWPRaqrfWmVbEd8dTm7WpvYPd08w0Om/uVzAXWkr2cgGJVKuD/ nICQ== X-Gm-Message-State: AOAM530rHKo0isNAJfUcOD3gfMb0X97x8DkVN2a9EI+hdZyV2pJvrSqI 4IHUS9ZcwS2HyqO4cuLQOiS8og== X-Google-Smtp-Source: ABdhPJwhzQX7zADMRMNSTYZAKqZekQIG4Kyq174zWXX5op48Wg8X7+oaufGwfWHly3PUfJa91txMjw== X-Received: by 2002:a17:90a:d3cf:: with SMTP id d15mr3291039pjw.132.1606839409910; Tue, 01 Dec 2020 08:16:49 -0800 (PST) Received: from localhost (2001-44b8-111e-5c00-f932-2db6-916f-25e2.static.ipv6.internode.on.net. [2001:44b8:111e:5c00:f932:2db6:916f:25e2]) by smtp.gmail.com with ESMTPSA id s5sm194359pfh.164.2020.12.01.08.16.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2020 08:16:49 -0800 (PST) From: Daniel Axtens To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, kasan-dev@googlegroups.com, christophe.leroy@c-s.fr, aneesh.kumar@linux.ibm.com, bsingharora@gmail.com Cc: Daniel Axtens Subject: [PATCH v9 3/6] kasan: define and use MAX_PTRS_PER_* for early shadow tables Date: Wed, 2 Dec 2020 03:16:29 +1100 Message-Id: <20201201161632.1234753-4-dja@axtens.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201201161632.1234753-1-dja@axtens.net> References: <20201201161632.1234753-1-dja@axtens.net> MIME-Version: 1.0 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 3df66fdf6662..893d054aad6f 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -24,10 +24,22 @@ struct kunit_kasan_expectation { static inline bool kasan_arch_is_ready(void) { return true; } #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]; -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]; +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 fe6be0be1f76..42bca3d27db8 100644 --- a/mm/kasan/init.c +++ b/mm/kasan/init.c @@ -46,7 +46,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)); @@ -58,7 +58,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)); @@ -69,7 +69,7 @@ static inline bool kasan_pmd_table(pud_t pud) return false; } #endif -pte_t kasan_early_shadow_pte[PTRS_PER_PTE] __page_aligned_bss; +pte_t kasan_early_shadow_pte[MAX_PTRS_PER_PTE] __page_aligned_bss; static inline bool kasan_pte_table(pmd_t pmd) {