From patchwork Thu Jun 24 03:40:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 12340753 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 C9AEFC48BC2 for ; Thu, 24 Jun 2021 03:41:11 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6EB06613C0 for ; Thu, 24 Jun 2021 03:41:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6EB06613C0 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 79D746B008C; Wed, 23 Jun 2021 23:41:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 780926B0092; Wed, 23 Jun 2021 23:41:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 616626B0093; Wed, 23 Jun 2021 23:41:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0227.hostedemail.com [216.40.44.227]) by kanga.kvack.org (Postfix) with ESMTP id 333566B008C for ; Wed, 23 Jun 2021 23:41:10 -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 5881218068BCA for ; Thu, 24 Jun 2021 03:41:10 +0000 (UTC) X-FDA: 78287216700.01.2316AFF Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) by imf05.hostedemail.com (Postfix) with ESMTP id 150A0E000113 for ; Thu, 24 Jun 2021 03:41:09 +0000 (UTC) Received: by mail-pg1-f181.google.com with SMTP id h4so3584063pgp.5 for ; Wed, 23 Jun 2021 20:41:09 -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=rvCzMPY1iDnXrmjh/pjQWKgOuSudghioSXufJUjyJjc=; b=J2OkXKObl6CYfnxQlkmmMaeOYyf2X6Xqhir66nx7wrcwvPBnkeeC3KAPr2dkh9bBvk dcgGqLWR2GuWsJDWbQCbhGoXzXg7rC/UvvUfZbJ3GYgvMU54Aly5ZTKyA54Wb49muTXL 7cqPneehzSNCUAVQlZrhlJusCiC4Edx4OYisY= 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=rvCzMPY1iDnXrmjh/pjQWKgOuSudghioSXufJUjyJjc=; b=Fd90zfYZpLFUB/DH6BIL7WnAjiQolUXnsGul8QPQEjaQyYqttpUhIHPXPR3Tl51GL/ ILexpKWmTGZNx4AkrQYUsuerVPndQeGeHew1w2dvLHpD4EmcplMxW3a8vDH17wRWNO1E iurESlgd4pSlLAdGo4L0uovybUybEshIzJ7Gr7HuZ2f4N0IORuafljP06MbTZbGeIJVd L0X7/gM6rKeMcCWaEMVZnlHNa57QZJ312WqTm5V9ZxAvMrTSfx1hhhh6A3+4q6KYKTRT M6KMKB7pkOw4mpJ2yJsfKk+ZiZyIpH05HlJ8SUn4Mvc6kGHKWF5muqPzldsWgNybwOs6 ClGw== X-Gm-Message-State: AOAM530oy3q6LDF+4LoYxpnlpfQDD+GG3gSOQvVUQNlx2AVYtO+GEpaU nWxWyWGly8lLfAGuJEtoHtj+Vg== X-Google-Smtp-Source: ABdhPJxG3zy2eS/jaYiZ/EUqvgZ/Z2jIEolGittrt/Ulk+fSsAbrQb8DXATsxr4lxtZy+aRd09K8cw== X-Received: by 2002:a62:844d:0:b029:308:230c:fe3a with SMTP id k74-20020a62844d0000b0290308230cfe3amr906161pfd.34.1624506069293; Wed, 23 Jun 2021 20:41:09 -0700 (PDT) Received: from localhost ([203.206.29.204]) by smtp.gmail.com with ESMTPSA id j19sm556042pgm.44.2021.06.23.20.41.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 20:41:08 -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 v16 3/4] mm: define default MAX_PTRS_PER_* in include/pgtable.h Date: Thu, 24 Jun 2021 13:40:49 +1000 Message-Id: <20210624034050.511391-4-dja@axtens.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210624034050.511391-1-dja@axtens.net> References: <20210624034050.511391-1-dja@axtens.net> MIME-Version: 1.0 Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=axtens.net header.s=google header.b=J2OkXKOb; dmarc=none; spf=pass (imf05.hostedemail.com: domain of dja@axtens.net designates 209.85.215.181 as permitted sender) smtp.mailfrom=dja@axtens.net X-Rspamd-Server: rspam02 X-Stat-Signature: w7jm59na3m9eihqjqig9jgssgqjky1p4 X-Rspamd-Queue-Id: 150A0E000113 X-HE-Tag: 1624506069-657958 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: Commit c65e774fb3f6 ("x86/mm: Make PGDIR_SHIFT and PTRS_PER_P4D variable") made PTRS_PER_P4D variable on x86 and introduced MAX_PTRS_PER_P4D as a constant for cases which need a compile-time constant (e.g. fixed-size arrays). powerpc likewise has boot-time selectable MMU features which can cause other mm "constants" to vary. For KASAN, we have some static PTE/PMD/PUD/P4D arrays so we need compile-time maximums for all these constants. Extend the MAX_PTRS_PER_ idiom, and place default definitions in include/pgtable.h. These define MAX_PTRS_PER_x to be PTRS_PER_x unless an architecture has defined MAX_PTRS_PER_x in its arch headers. Clean up pgtable-nop4d.h and s390's MAX_PTRS_PER_P4D definitions while we're at it: both can just pick up the default now. Acked-by: Andrey Konovalov Reviewed-by: Christophe Leroy Reviewed-by: Marco Elver Signed-off-by: Daniel Axtens --- s390 was compile tested only. --- arch/s390/include/asm/pgtable.h | 2 -- include/asm-generic/pgtable-nop4d.h | 1 - include/linux/pgtable.h | 22 ++++++++++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h index 79742f497cb5..dcac7b2df72c 100644 --- a/arch/s390/include/asm/pgtable.h +++ b/arch/s390/include/asm/pgtable.h @@ -343,8 +343,6 @@ static inline int is_module_addr(void *addr) #define PTRS_PER_P4D _CRST_ENTRIES #define PTRS_PER_PGD _CRST_ENTRIES -#define MAX_PTRS_PER_P4D PTRS_PER_P4D - /* * Segment table and region3 table entry encoding * (R = read-only, I = invalid, y = young bit): diff --git a/include/asm-generic/pgtable-nop4d.h b/include/asm-generic/pgtable-nop4d.h index 2f1d0aad645c..03b7dae47dd4 100644 --- a/include/asm-generic/pgtable-nop4d.h +++ b/include/asm-generic/pgtable-nop4d.h @@ -9,7 +9,6 @@ typedef struct { pgd_t pgd; } p4d_t; #define P4D_SHIFT PGDIR_SHIFT -#define MAX_PTRS_PER_P4D 1 #define PTRS_PER_P4D 1 #define P4D_SIZE (1UL << P4D_SHIFT) #define P4D_MASK (~(P4D_SIZE-1)) diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index fb20c57de2ce..d147480cdefc 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -1634,4 +1634,26 @@ typedef unsigned int pgtbl_mod_mask; #define pte_leaf_size(x) PAGE_SIZE #endif +/* + * Some architectures have MMUs that are configurable or selectable at boot + * time. These lead to variable PTRS_PER_x. For statically allocated arrays it + * helps to have a static maximum value. + */ + +#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 + +#ifndef MAX_PTRS_PER_P4D +#define MAX_PTRS_PER_P4D PTRS_PER_P4D +#endif + #endif /* _LINUX_PGTABLE_H */