From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: Pedro Falcato <pfalcato@suse.de>
Cc: David Hildenbrand <david@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
"James E.J. Bottomley" <James.Bottomley@hansenpartnership.com>,
Helge Deller <deller@gmx.de>,
Madhavan Srinivasan <maddy@linux.ibm.com>,
Michael Ellerman <mpe@ellerman.id.au>,
"Liam R. Howlett" <liam@infradead.org>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
"Matthew Wilcox (Oracle)" <willy@infradead.org>,
Jan Kara <jack@suse.cz>, Zi Yan <ziy@nvidia.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Nico Pache <npache@redhat.com>,
Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
Barry Song <baohua@kernel.org>,
Lance Yang <lance.yang@linux.dev>,
Usama Arif <usama.arif@linux.dev>,
Kevin Brodsky <kevin.brodsky@arm.com>,
Muhammad Usama Anjum <usama.anjum@arm.com>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-parisc@vger.kernel.org,
linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org,
linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH v2 1/6] mm/arm64: constify pte_get*() and contpte get logic
Date: Tue, 4 Aug 2026 11:55:09 +0100 [thread overview]
Message-ID: <anG2V7KpvIHjNyVq@lucifer> (raw)
In-Reply-To: <20260803164400.531199-2-pfalcato@suse.de>
On Mon, Aug 03, 2026 at 05:43:55PM +0100, Pedro Falcato wrote:
> None of the contpte code needs write access to the PTEs.
This seems like a very broad statement? Is that actually true? I see a bunch of
ptep's that aren't const-ified, so you should explain why those couldn't be
converted.
Also you add a new contpte_align_down() macro, you should mention that it the
commit message, explain why it was needed.
In general more needed here :) it'd be ok if it was a truly trivial change that
was all obvious but you're changing some pte_t *'s and not others so it's
clearly not.
>
> Signed-off-by: Pedro Falcato <pfalcato@suse.de>
> ---
> arch/arm64/include/asm/pgtable.h | 10 +++++-----
> arch/arm64/mm/contpte.c | 11 ++++++++---
> 2 files changed, 13 insertions(+), 8 deletions(-)
>
> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
> index a2681d755358..043bc0649cee 100644
> --- a/arch/arm64/include/asm/pgtable.h
> +++ b/arch/arm64/include/asm/pgtable.h
> @@ -378,7 +378,7 @@ static inline void __set_pte(pte_t *ptep, pte_t pte)
> __set_pte_complete(pte);
> }
>
> -static inline pte_t __ptep_get(pte_t *ptep)
> +static inline pte_t __ptep_get(const pte_t *ptep)
> {
> return READ_ONCE(*ptep);
> }
> @@ -1652,8 +1652,8 @@ extern void __contpte_try_fold(struct mm_struct *mm, unsigned long addr,
> pte_t *ptep, pte_t pte);
> extern void __contpte_try_unfold(struct mm_struct *mm, unsigned long addr,
> pte_t *ptep, pte_t pte);
> -extern pte_t contpte_ptep_get(pte_t *ptep, pte_t orig_pte);
> -extern pte_t contpte_ptep_get_lockless(pte_t *orig_ptep);
> +extern pte_t contpte_ptep_get(const pte_t *ptep, pte_t orig_pte);
> +extern pte_t contpte_ptep_get_lockless(const pte_t *orig_ptep);
This is (very) nitty but - not sure on the policy on extern's (Will/Catalin?) -
but in mm we drop them when we touch the code since you don't need them these
days :)
> extern void contpte_set_ptes(struct mm_struct *mm, unsigned long addr,
> pte_t *ptep, pte_t pte, unsigned int nr);
> extern void contpte_clear_full_ptes(struct mm_struct *mm, unsigned long addr,
> @@ -1732,7 +1732,7 @@ static inline unsigned int pte_batch_hint(pte_t *ptep, pte_t pte)
> */
>
> #define ptep_get ptep_get
> -static inline pte_t ptep_get(pte_t *ptep)
> +static inline pte_t ptep_get(const pte_t *ptep)
> {
> pte_t pte = __ptep_get(ptep);
>
> @@ -1743,7 +1743,7 @@ static inline pte_t ptep_get(pte_t *ptep)
> }
>
> #define ptep_get_lockless ptep_get_lockless
> -static inline pte_t ptep_get_lockless(pte_t *ptep)
> +static inline pte_t ptep_get_lockless(const pte_t *ptep)
> {
> pte_t pte = __ptep_get(ptep);
>
> diff --git a/arch/arm64/mm/contpte.c b/arch/arm64/mm/contpte.c
> index 2de12656b4d8..3a5d6937fb51 100644
> --- a/arch/arm64/mm/contpte.c
> +++ b/arch/arm64/mm/contpte.c
> @@ -26,6 +26,11 @@ static inline pte_t *contpte_align_down(pte_t *ptep)
> return PTR_ALIGN_DOWN(ptep, sizeof(*ptep) * CONT_PTES);
> }
>
> +#define contpte_align_down(ptep) \
> + _Generic((ptep), \
> + const pte_t *: (const pte_t *) contpte_align_down((pte_t *) (ptep)), \
> + pte_t *: contpte_align_down((pte_t *) ptep))
I really hate these _Generic() helper things. So ugly. And it's a pretty horrid
cast now :(
Was it not possible to const-ify further to just be able to constify
contpte_align_down itself?
It also seems to contradict the claim that contpte doesn't need write-access to
pte's since you're going to lengths to allow non-const pte_t * here.
You should cover off why this was necessary in the commit message as above.
Anyway PTR_ALIGN_DOWN() is already const-safe so couldn't you anyway just
collapse this to:
#define contpte_align_down(ptep) \
PTR_ALIGN_DOWN(ptep, sizeof(*(ptep)) * CONT_PTES)
Then describe in the commit message why you need to handle both cases?
> +
> static inline pte_t *contpte_align_addr_ptep(unsigned long *start,
> unsigned long *end, pte_t *ptep,
> unsigned int nr)
> @@ -310,7 +315,7 @@ void __contpte_try_unfold(struct mm_struct *mm, unsigned long addr,
> }
> EXPORT_SYMBOL_GPL(__contpte_try_unfold);
>
> -pte_t contpte_ptep_get(pte_t *ptep, pte_t orig_pte)
> +pte_t contpte_ptep_get(const pte_t *ptep, pte_t orig_pte)
> {
> /*
> * Gather access/dirty bits, which may be populated in any of the ptes
> @@ -367,7 +372,7 @@ static inline bool contpte_is_consistent(pte_t pte, unsigned long pfn,
> pgprot_val(prot) == pgprot_val(orig_prot);
> }
>
> -pte_t contpte_ptep_get_lockless(pte_t *orig_ptep)
> +pte_t contpte_ptep_get_lockless(const pte_t *orig_ptep)
> {
> /*
> * The ptep_get_lockless() API requires us to read and return *orig_ptep
> @@ -386,10 +391,10 @@ pte_t contpte_ptep_get_lockless(pte_t *orig_ptep)
> * because it is not part of a contpte range.
> */
>
> + const pte_t *ptep;
Nit but this is breaking the reverse xmas tree isn't it?
> pgprot_t orig_prot;
> unsigned long pfn;
> pte_t orig_pte;
> - pte_t *ptep;
> pte_t pte;
> int i;
>
> --
> 2.55.0
>
--
Cheers, Lorenzo
next prev parent reply other threads:[~2026-08-04 10:55 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-03 16:43 [PATCH v2 0/6] mm: add basic PTE const type-safety Pedro Falcato
2026-08-03 16:43 ` [PATCH v2 1/6] mm/arm64: constify pte_get*() and contpte get logic Pedro Falcato
2026-08-04 10:55 ` Lorenzo Stoakes (ARM) [this message]
2026-08-04 12:31 ` Pedro Falcato
2026-08-04 12:36 ` Lorenzo Stoakes (ARM)
2026-08-03 16:43 ` [PATCH v2 2/6] parisc: Drop own implementations for ptep_get() and ptep_test_and_clear_young() Pedro Falcato
2026-08-04 11:11 ` Lorenzo Stoakes (ARM)
2026-08-04 12:34 ` Pedro Falcato
2026-08-04 12:42 ` Lorenzo Stoakes (ARM)
2026-08-04 13:00 ` Helge Deller
2026-08-04 13:03 ` Lorenzo Stoakes (ARM)
2026-08-03 16:43 ` [PATCH v2 3/6] mm/powerpc/8xx: constify ptep_get() argument Pedro Falcato
2026-08-04 11:13 ` Lorenzo Stoakes (ARM)
2026-08-04 12:38 ` Pedro Falcato
2026-08-04 12:43 ` Lorenzo Stoakes (ARM)
2026-08-04 12:50 ` Christophe Leroy (CS GROUP)
2026-08-04 12:59 ` Lorenzo Stoakes (ARM)
2026-08-04 13:08 ` LEROY Christophe
2026-08-04 13:09 ` Christophe Leroy (CS GROUP)
2026-08-03 16:43 ` [PATCH v2 4/6] mm/s390: " Pedro Falcato
2026-08-04 11:14 ` Lorenzo Stoakes (ARM)
2026-08-03 16:43 ` [PATCH v2 5/6] mm: constify generic pte_get*() Pedro Falcato
2026-08-04 11:15 ` Lorenzo Stoakes (ARM)
2026-08-03 16:44 ` [PATCH v2 6/6] mm: constify the pte_offset_map_ro_nolock() return value Pedro Falcato
2026-08-04 11:22 ` Lorenzo Stoakes (ARM)
2026-08-03 18:38 ` [PATCH v2 0/6] mm: add basic PTE const type-safety Muhammad Usama Anjum
2026-08-04 6:55 ` Christophe Leroy (CS GROUP)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=anG2V7KpvIHjNyVq@lucifer \
--to=ljs@kernel.org \
--cc=James.Bottomley@hansenpartnership.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=catalin.marinas@arm.com \
--cc=david@kernel.org \
--cc=deller@gmx.de \
--cc=dev.jain@arm.com \
--cc=jack@suse.cz \
--cc=kevin.brodsky@arm.com \
--cc=lance.yang@linux.dev \
--cc=liam@infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-parisc@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=mhocko@suse.com \
--cc=mpe@ellerman.id.au \
--cc=npache@redhat.com \
--cc=pfalcato@suse.de \
--cc=rppt@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=surenb@google.com \
--cc=usama.anjum@arm.com \
--cc=usama.arif@linux.dev \
--cc=vbabka@kernel.org \
--cc=will@kernel.org \
--cc=willy@infradead.org \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox