From mboxrd@z Thu Jan 1 00:00:00 1970 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=-12.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 DF2F0C48BDF for ; Sun, 20 Jun 2021 11:17:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7A3E1610EA for ; Sun, 20 Jun 2021 11:17:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7A3E1610EA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E8B546B006E; Sun, 20 Jun 2021 07:17:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E13F16B0072; Sun, 20 Jun 2021 07:17:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C676F6B0073; Sun, 20 Jun 2021 07:17:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0159.hostedemail.com [216.40.44.159]) by kanga.kvack.org (Postfix) with ESMTP id 8F3206B006E for ; Sun, 20 Jun 2021 07:17:25 -0400 (EDT) Received: from smtpin40.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 32008180AD81F for ; Sun, 20 Jun 2021 11:17:25 +0000 (UTC) X-FDA: 78273851250.40.CFEB38A Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) by imf11.hostedemail.com (Postfix) with ESMTP id EEFC3200112F for ; Sun, 20 Jun 2021 11:17:24 +0000 (UTC) Received: by mail-ed1-f51.google.com with SMTP id d7so15015550edx.0 for ; Sun, 20 Jun 2021 04:17:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Ox6b74Fvc6eYbkVfNLZ3KvjE6zQLqybhjoI+fLMMAAM=; b=WXYG6Cdf6By2iyUeWDdpOD47jL5uFwBbosTEKrmlnmXvDpzsAuoyBww2pRA2Nf2Ygd DD4A5L3vWj87qldAax3ct/cAmp7164hOVOcjWuNyybt/M5PYq+bH7Uw8xsxzqm4JclDK LIto+UwOj0HHXP1hgJKyxLfliaNccUpEscCUVWs3myw6twqAl1PUNRlS4mwtL8VPvH2i /jG/shwVDIPB0cqHPRLgk+7J9ddYULS67W9JTNIBBiYBCKekjzWaq4G6xn3gTi7x3oZi 4TI3M6kZhzIxXd31Git2Xl8h73DWG2h8bolP5AxjIovmioxJN4HIDmt/HBr1mTifgnT4 w+GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Ox6b74Fvc6eYbkVfNLZ3KvjE6zQLqybhjoI+fLMMAAM=; b=JrVzTjYOaz/bNSvmiVA9+GDVJ/a1IqV3k6Eg3W1AmEFS6dwRDsJY9z8lYf4ZQCLGvY BvHev5p7I+bhBW2WgNwHU4CoUfIJGv5+pa7UBYd7mfQ8LU4dHwyAol9slfhebYttYKvm hrJmj75/1IzaERSXcxfRXqQ8/ObiVnI/m2Z/kRDpIBOI+POZVwiZXyJWdJQLGMxi5VQ+ 3ipA66KQaw2xwQaDTssQu89kEuQ5Bc2CsfDvZUA/q/AhTvkjVZUEIWTaY5TGxQ3mvWiG /ODPmrZderfOB+2973CsX4TPhSE+w3eLchycEsRXYLf453aMbj2HjrYsDihnGMCTMg/U QNug== X-Gm-Message-State: AOAM533blJdeUNKpdLlEIzzN6Tn4ikB8jYTTpzKgZGcp8pvWq/K1imlf pTjN9Rh9px4B8q5BieY7Zl4lVXB20zgpygH2+J8= X-Google-Smtp-Source: ABdhPJww9MCpsYchtIGF8m60gxIne2Q2KYFvGjYAO6vwCGhLCbJsxWFd2YH44uCprI1gDhfoSaxdRwpOLzbrVk0RxPA= X-Received: by 2002:a50:fd83:: with SMTP id o3mr12106286edt.95.1624187843896; Sun, 20 Jun 2021 04:17:23 -0700 (PDT) MIME-Version: 1.0 References: <20210617093032.103097-1-dja@axtens.net> <20210617093032.103097-4-dja@axtens.net> In-Reply-To: <20210617093032.103097-4-dja@axtens.net> From: Andrey Konovalov Date: Sun, 20 Jun 2021 14:17:04 +0300 Message-ID: Subject: Re: [PATCH v15 3/4] mm: define default MAX_PTRS_PER_* in include/pgtable.h To: Daniel Axtens Cc: LKML , Linux Memory Management List , kasan-dev , Marco Elver , Andrew Morton , linuxppc-dev@lists.ozlabs.org, christophe.leroy@csgroup.eu, aneesh.kumar@linux.ibm.com, bsingharora@gmail.com Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=WXYG6Cdf; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf11.hostedemail.com: domain of andreyknvl@gmail.com designates 209.85.208.51 as permitted sender) smtp.mailfrom=andreyknvl@gmail.com X-Rspamd-Server: rspam02 X-Stat-Signature: b5g7k316cfk4ce3f44mgucssptjjzt3r X-Rspamd-Queue-Id: EEFC3200112F X-HE-Tag: 1624187844-875387 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: On Thu, Jun 17, 2021 at 12:30 PM Daniel Axtens wrote: > > 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. > > 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 7c66ae5d7e32..cf05954ce013 100644 > --- a/arch/s390/include/asm/pgtable.h > +++ b/arch/s390/include/asm/pgtable.h > @@ -342,8 +342,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 ce2cbb3c380f..2f6b1befb129 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 9e6f71265f72..69700e3e615f 100644 > --- a/include/linux/pgtable.h > +++ b/include/linux/pgtable.h > @@ -1625,4 +1625,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 */ > -- > 2.30.2 > Acked-by: Andrey Konovalov