[PATCH v3 01/11] mm: Relocate the page table ceiling and floor definitions

Liam R. Howlett posted 11 patches 2 weeks, 2 days ago
[PATCH v3 01/11] mm: Relocate the page table ceiling and floor definitions
Posted by Liam R. Howlett 2 weeks, 2 days ago
pgtables.h defines a fallback for ceiling and floor of the page tables
within the CONFIG_MMU section.  Moving the definitions to outside the
CONFIG_MMU Allows for using them in generic code.

Suggested-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Suggested-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
---
 include/linux/pgtable.h | 39 ++++++++++++++++++++-------------------
 mm/vma_internal.h       |  1 +
 2 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index eb8aacba3698d..557ac918bdca6 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -22,25 +22,6 @@
 #error CONFIG_PGTABLE_LEVELS is not consistent with __PAGETABLE_{P4D,PUD,PMD}_FOLDED
 #endif
 
-/*
- * On almost all architectures and configurations, 0 can be used as the
- * upper ceiling to free_pgtables(): on many architectures it has the same
- * effect as using TASK_SIZE.  However, there is one configuration which
- * must impose a more careful limit, to avoid freeing kernel pgtables.
- */
-#ifndef USER_PGTABLES_CEILING
-#define USER_PGTABLES_CEILING	0UL
-#endif
-
-/*
- * This defines the first usable user address. Platforms
- * can override its value with custom FIRST_USER_ADDRESS
- * defined in their respective <asm/pgtable.h>.
- */
-#ifndef FIRST_USER_ADDRESS
-#define FIRST_USER_ADDRESS	0UL
-#endif
-
 /*
  * This defines the generic helper for accessing PMD page
  * table page. Although platforms can still override this
@@ -1660,6 +1641,26 @@ void arch_sync_kernel_mappings(unsigned long start, unsigned long end);
 
 #endif /* CONFIG_MMU */
 
+/*
+ * On almost all architectures and configurations, 0 can be used as the
+ * upper ceiling to free_pgtables(): on many architectures it has the same
+ * effect as using TASK_SIZE.  However, there is one configuration which
+ * must impose a more careful limit, to avoid freeing kernel pgtables.
+ */
+#ifndef USER_PGTABLES_CEILING
+#define USER_PGTABLES_CEILING	0UL
+#endif
+
+/*
+ * This defines the first usable user address. Platforms
+ * can override its value with custom FIRST_USER_ADDRESS
+ * defined in their respective <asm/pgtable.h>.
+ */
+#ifndef FIRST_USER_ADDRESS
+#define FIRST_USER_ADDRESS	0UL
+#endif
+
+
 /*
  * No-op macros that just return the current protection value. Defined here
  * because these macros can be used even if CONFIG_MMU is not defined.
diff --git a/mm/vma_internal.h b/mm/vma_internal.h
index 2f05735ff190c..2da6d224c1a85 100644
--- a/mm/vma_internal.h
+++ b/mm/vma_internal.h
@@ -46,6 +46,7 @@
 #include <linux/swap.h>
 #include <linux/uprobes.h>
 #include <linux/userfaultfd_k.h>
+#include <linux/pgtable.h>
 
 #include <asm/current.h>
 #include <asm/tlb.h>
-- 
2.47.3
Re: [PATCH v3 01/11] mm: Relocate the page table ceiling and floor definitions
Posted by SeongJae Park 2 weeks, 2 days ago
On Wed, 21 Jan 2026 11:49:36 -0500 "Liam R. Howlett" <Liam.Howlett@oracle.com> wrote:

> pgtables.h defines a fallback for ceiling and floor of the page tables
> within the CONFIG_MMU section.  Moving the definitions to outside the
> CONFIG_MMU Allows for using them in generic code.
> 
> Suggested-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> Suggested-by: SeongJae Park <sj@kernel.org>
> Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
> ---
>  include/linux/pgtable.h | 39 ++++++++++++++++++++-------------------
>  mm/vma_internal.h       |  1 +
>  2 files changed, 21 insertions(+), 19 deletions(-)
> 
> diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
> index eb8aacba3698d..557ac918bdca6 100644
> --- a/include/linux/pgtable.h
> +++ b/include/linux/pgtable.h
> @@ -22,25 +22,6 @@
>  #error CONFIG_PGTABLE_LEVELS is not consistent with __PAGETABLE_{P4D,PUD,PMD}_FOLDED
>  #endif
>  
> -/*
> - * On almost all architectures and configurations, 0 can be used as the
> - * upper ceiling to free_pgtables(): on many architectures it has the same
> - * effect as using TASK_SIZE.  However, there is one configuration which
> - * must impose a more careful limit, to avoid freeing kernel pgtables.
> - */
> -#ifndef USER_PGTABLES_CEILING
> -#define USER_PGTABLES_CEILING	0UL
> -#endif
> -
> -/*
> - * This defines the first usable user address. Platforms
> - * can override its value with custom FIRST_USER_ADDRESS
> - * defined in their respective <asm/pgtable.h>.
> - */
> -#ifndef FIRST_USER_ADDRESS
> -#define FIRST_USER_ADDRESS	0UL
> -#endif
> -
>  /*
>   * This defines the generic helper for accessing PMD page
>   * table page. Although platforms can still override this
> @@ -1660,6 +1641,26 @@ void arch_sync_kernel_mappings(unsigned long start, unsigned long end);
>  
>  #endif /* CONFIG_MMU */
>  
> +/*
> + * On almost all architectures and configurations, 0 can be used as the
> + * upper ceiling to free_pgtables(): on many architectures it has the same
> + * effect as using TASK_SIZE.  However, there is one configuration which
> + * must impose a more careful limit, to avoid freeing kernel pgtables.
> + */
> +#ifndef USER_PGTABLES_CEILING
> +#define USER_PGTABLES_CEILING	0UL
> +#endif
> +
> +/*
> + * This defines the first usable user address. Platforms
> + * can override its value with custom FIRST_USER_ADDRESS
> + * defined in their respective <asm/pgtable.h>.
> + */
> +#ifndef FIRST_USER_ADDRESS
> +#define FIRST_USER_ADDRESS	0UL
> +#endif

Looks good to me :)

> +
> +

Nit.  I think just one new line here should be ok?

>  /*
>   * No-op macros that just return the current protection value. Defined here
>   * because these macros can be used even if CONFIG_MMU is not defined.
> diff --git a/mm/vma_internal.h b/mm/vma_internal.h
> index 2f05735ff190c..2da6d224c1a85 100644
> --- a/mm/vma_internal.h
> +++ b/mm/vma_internal.h
> @@ -46,6 +46,7 @@
>  #include <linux/swap.h>
>  #include <linux/uprobes.h>
>  #include <linux/userfaultfd_k.h>
> +#include <linux/pgtable.h>

I think this might be better to be done together with the following change that
starts using the ceiling and floor from generic code, or mention this change in
the description together?

Above comments are for only trivial things that I don't really mind.  Please
feel free to proceed as you want.


Thanks,
SJ

[...]
Re: [PATCH v3 01/11] mm: Relocate the page table ceiling and floor definitions
Posted by Liam R. Howlett 2 weeks, 2 days ago
* SeongJae Park <sj@kernel.org> [260121 12:26]:
> On Wed, 21 Jan 2026 11:49:36 -0500 "Liam R. Howlett" <Liam.Howlett@oracle.com> wrote:
> 
> > pgtables.h defines a fallback for ceiling and floor of the page tables
> > within the CONFIG_MMU section.  Moving the definitions to outside the
> > CONFIG_MMU Allows for using them in generic code.
> > 
> > Suggested-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> > Suggested-by: SeongJae Park <sj@kernel.org>
> > Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
> > ---
> >  include/linux/pgtable.h | 39 ++++++++++++++++++++-------------------
> >  mm/vma_internal.h       |  1 +
> >  2 files changed, 21 insertions(+), 19 deletions(-)
> > 
> > diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
> > index eb8aacba3698d..557ac918bdca6 100644
> > --- a/include/linux/pgtable.h
> > +++ b/include/linux/pgtable.h
> > @@ -22,25 +22,6 @@
> >  #error CONFIG_PGTABLE_LEVELS is not consistent with __PAGETABLE_{P4D,PUD,PMD}_FOLDED
> >  #endif
> >  
> > -/*
> > - * On almost all architectures and configurations, 0 can be used as the
> > - * upper ceiling to free_pgtables(): on many architectures it has the same
> > - * effect as using TASK_SIZE.  However, there is one configuration which
> > - * must impose a more careful limit, to avoid freeing kernel pgtables.
> > - */
> > -#ifndef USER_PGTABLES_CEILING
> > -#define USER_PGTABLES_CEILING	0UL
> > -#endif
> > -
> > -/*
> > - * This defines the first usable user address. Platforms
> > - * can override its value with custom FIRST_USER_ADDRESS
> > - * defined in their respective <asm/pgtable.h>.
> > - */
> > -#ifndef FIRST_USER_ADDRESS
> > -#define FIRST_USER_ADDRESS	0UL
> > -#endif
> > -
> >  /*
> >   * This defines the generic helper for accessing PMD page
> >   * table page. Although platforms can still override this
> > @@ -1660,6 +1641,26 @@ void arch_sync_kernel_mappings(unsigned long start, unsigned long end);
> >  
> >  #endif /* CONFIG_MMU */
> >  
> > +/*
> > + * On almost all architectures and configurations, 0 can be used as the
> > + * upper ceiling to free_pgtables(): on many architectures it has the same
> > + * effect as using TASK_SIZE.  However, there is one configuration which
> > + * must impose a more careful limit, to avoid freeing kernel pgtables.
> > + */
> > +#ifndef USER_PGTABLES_CEILING
> > +#define USER_PGTABLES_CEILING	0UL
> > +#endif
> > +
> > +/*
> > + * This defines the first usable user address. Platforms
> > + * can override its value with custom FIRST_USER_ADDRESS
> > + * defined in their respective <asm/pgtable.h>.
> > + */
> > +#ifndef FIRST_USER_ADDRESS
> > +#define FIRST_USER_ADDRESS	0UL
> > +#endif
> 
> Looks good to me :)

I had it at the start of the file but realised your change was more in
line with what the file already did.

> 
> > +
> > +
> 
> Nit.  I think just one new line here should be ok?

Agreed, Thanks.

Andrew, can you remove this extra line?

> 
> >  /*
> >   * No-op macros that just return the current protection value. Defined here
> >   * because these macros can be used even if CONFIG_MMU is not defined.
> > diff --git a/mm/vma_internal.h b/mm/vma_internal.h
> > index 2f05735ff190c..2da6d224c1a85 100644
> > --- a/mm/vma_internal.h
> > +++ b/mm/vma_internal.h
> > @@ -46,6 +46,7 @@
> >  #include <linux/swap.h>
> >  #include <linux/uprobes.h>
> >  #include <linux/userfaultfd_k.h>
> > +#include <linux/pgtable.h>
> 
> I think this might be better to be done together with the following change that
> starts using the ceiling and floor from generic code, or mention this change in
> the description together?
> 
> Above comments are for only trivial things that I don't really mind.  Please
> feel free to proceed as you want.

I was also debating this, but the impact should be virtually unnoticed -
it's included in most cases anyways, so arm32 and m68k would have the
extra define.  Tracing the reason will have the cover letter in the
change log as well.

If anyone feels strongly, I can respin this in a few days again.

Thanks again,
Liam