Skip to contentSkip to conversation

mm: Enable CONFIG_PT_RECLAIM on all architectures

RFC PATCH In review Dev Jain 3 participants 9 messages Nov 3, 2025 – Nov 4, 2025

Subsystems (3)
lore
Share & tools
lore

Dev Jain

author
#0 lore raw

RFC PATCH 1/1 mm: Enable CONFIG_PT_RECLAIM on all architectures

The implementation of CONFIG_PT_RECLAIM is completely contained in generic mm code. It depends on the RCU callback which will reclaim the pagetables - there is nothing arch-specific about that. So, enable this config for all architectures.

---
 arch/x86/Kconfig | 1 -
 mm/Kconfig       | 5 +----
 mm/pt_reclaim.c  | 2 +-
 3 files changed, 2 insertions(+), 6 deletions(-)
arch/x86/Kconfig +0 -1
index fa3b616af03a..5681308a5650 100644
@@ -327,7 +327,6 @@ config X86
 	select FUNCTION_ALIGNMENT_4B
 	imply IMA_SECURE_AND_OR_TRUSTED_BOOT    if EFI
 	select HAVE_DYNAMIC_FTRACE_NO_PATCHABLE
-	select ARCH_SUPPORTS_PT_RECLAIM		if X86_64
 	select ARCH_SUPPORTS_SCHED_SMT		if SMP
 	select SCHED_SMT			if SMP
 	select ARCH_SUPPORTS_SCHED_CLUSTER	if SMP
mm/Kconfig +1 -4
index 0e26f4fc8717..903c37d02555 100644
@@ -1355,13 +1355,10 @@ config ARCH_HAS_USER_SHADOW_STACK
 	  The architecture has hardware support for userspace shadow call
           stacks (eg, x86 CET, arm64 GCS or RISC-V Zicfiss).
 
-config ARCH_SUPPORTS_PT_RECLAIM
-	def_bool n
-
 config PT_RECLAIM
 	bool "reclaim empty user page table pages"
 	default y
-	depends on ARCH_SUPPORTS_PT_RECLAIM && MMU && SMP
+	depends on MMU && SMP
 	select MMU_GATHER_RCU_TABLE_FREE
 	help
 	  Try to reclaim empty user page table pages in paths other than munmap
mm/pt_reclaim.c +1 -1
index 7e9455a18aae..049e17f08c6a 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <linux/hugetlb.h>
-#include <asm-generic/tlb.h>
+#include <asm/tlb.h>
 #include <asm/pgalloc.h>
 
 #include "internal.h"
Signature · 1 line
2.30.2
#1 lore raw

Hi Dev,

Quoted 4 lines · Dev Jain

The implementation of CONFIG_PT_RECLAIM is completely contained in generic mm code. It depends on the RCU callback which will reclaim the pagetables - there is nothing arch-specific about that. So, enable this config for all architectures.

Thanks for doing this!

But unfortunately, not all architectures call tlb_remove_ptdesc() in __pte_free_tlb(). Some architectures directly call pte_free() to free PTE pages (without RCU).

We need to modify these architectures first, otherwise it will lead to UAF. This approach is feasible because Hugh provides similar support in pte_free_defer().

Enabling PT_RECLAIM on all architecture has always been on my TODO list, but it's been blocked by other things. :(

Thanks,
Qi

Quoted 51 lines
---
  arch/x86/Kconfig | 1 -
  mm/Kconfig       | 5 +----
  mm/pt_reclaim.c  | 2 +-
  3 files changed, 2 insertions(+), 6 deletions(-)
arch/x86/Kconfig +0 -1
index fa3b616af03a..5681308a5650 100644
@@ -327,7 +327,6 @@ config X86
  	select FUNCTION_ALIGNMENT_4B
  	imply IMA_SECURE_AND_OR_TRUSTED_BOOT    if EFI
  	select HAVE_DYNAMIC_FTRACE_NO_PATCHABLE
-	select ARCH_SUPPORTS_PT_RECLAIM		if X86_64
  	select ARCH_SUPPORTS_SCHED_SMT		if SMP
  	select SCHED_SMT			if SMP
  	select ARCH_SUPPORTS_SCHED_CLUSTER	if SMP
mm/Kconfig +1 -4
index 0e26f4fc8717..903c37d02555 100644
@@ -1355,13 +1355,10 @@ config ARCH_HAS_USER_SHADOW_STACK
  	  The architecture has hardware support for userspace shadow call
            stacks (eg, x86 CET, arm64 GCS or RISC-V Zicfiss).
 
-config ARCH_SUPPORTS_PT_RECLAIM
-	def_bool n
-
  config PT_RECLAIM
  	bool "reclaim empty user page table pages"
  	default y
-	depends on ARCH_SUPPORTS_PT_RECLAIM && MMU && SMP
+	depends on MMU && SMP
  	select MMU_GATHER_RCU_TABLE_FREE
  	help
  	  Try to reclaim empty user page table pages in paths other than munmap
mm/pt_reclaim.c +1 -1
index 7e9455a18aae..049e17f08c6a 100644
@@ -1,6 +1,6 @@
  // SPDX-License-Identifier: GPL-2.0
  #include <linux/hugetlb.h>
-#include <asm-generic/tlb.h>
+#include <asm/tlb.h>
  #include <asm/pgalloc.h>
 
  #include "internal.h"
author
#2 lore raw
Quoted 8 lines · Qi Zheng

Hi Dev,

Quoted 4 lines · Dev Jain

The implementation of CONFIG_PT_RECLAIM is completely contained in generic mm code. It depends on the RCU callback which will reclaim the pagetables - there is nothing arch-specific about that. So, enable this config for all architectures.

Quoted 5 lines

Thanks for doing this!

But unfortunately, not all architectures call tlb_remove_ptdesc() in __pte_free_tlb(). Some architectures directly call pte_free() to free PTE pages (without RCU).

Thanks! This was not obvious to figure out.

Is there an arch bottleneck because of which they do this? I mean to say,

is something stopping us from simply redirecting __pte_free_tlb to tlb_remove_ptdesc

or pte_free_defer?

I am looking to enable this config at least on arm64 by default, I believe it will be legal

to do this at least here.

Quoted 61 lines

We need to modify these architectures first, otherwise it will lead to UAF. This approach is feasible because Hugh provides similar support in pte_free_defer().

Enabling PT_RECLAIM on all architecture has always been on my TODO list, but it's been blocked by other things. :(

Thanks,
Qi

Quoted 49 lines

---
  arch/x86/Kconfig | 1 -
  mm/Kconfig       | 5 +----
  mm/pt_reclaim.c  | 2 +-

  3 files changed, 2 insertions(+), 6 deletions(-)
arch/x86/Kconfig +0 -0
index fa3b616af03a..5681308a5650 100644
@@ -327,7 +327,6 @@ config X86

      select FUNCTION_ALIGNMENT_4B
      imply IMA_SECURE_AND_OR_TRUSTED_BOOT    if EFI select HAVE_DYNAMIC_FTRACE_NO_PATCHABLE -    select ARCH_SUPPORTS_PT_RECLAIM        if X86_64 select ARCH_SUPPORTS_SCHED_SMT        if SMP select SCHED_SMT            if SMP select ARCH_SUPPORTS_SCHED_CLUSTER    if SMP

mm/Kconfig +0 -0
index 0e26f4fc8717..903c37d02555 100644
@@ -1355,13 +1355,10 @@ config ARCH_HAS_USER_SHADOW_STACK

        The architecture has hardware support for userspace shadow call stacks (eg, x86 CET, arm64 GCS or RISC-V Zicfiss). -config ARCH_SUPPORTS_PT_RECLAIM
-    def_bool n
-
  config PT_RECLAIM
      bool "reclaim empty user page table pages"
      default y
-    depends on ARCH_SUPPORTS_PT_RECLAIM && MMU && SMP
+    depends on MMU && SMP
      select MMU_GATHER_RCU_TABLE_FREE
      help
        Try to reclaim empty user page table pages in paths other than munmap

mm/pt_reclaim.c +1 -1
index 7e9455a18aae..049e17f08c6a 100644
@@ -1,6 +1,6 @@
   // SPDX-License-Identifier: GPL-2.0
   #include <linux/hugetlb.h>
-#include <asm-generic/tlb.h>
+#include <asm/tlb.h>
   #include <asm/pgalloc.h>
     #include "internal.h"
#3 lore raw

Hi Dev,

Quoted 16 lines · Dev Jain
Quoted 8 lines · Qi Zheng

Hi Dev,

Quoted 4 lines · Dev Jain

The implementation of CONFIG_PT_RECLAIM is completely contained in generic mm code. It depends on the RCU callback which will reclaim the pagetables - there is nothing arch-specific about that. So, enable this config for all architectures.

Quoted 5 lines

Thanks for doing this!

But unfortunately, not all architectures call tlb_remove_ptdesc() in __pte_free_tlb(). Some architectures directly call pte_free() to free PTE pages (without RCU).

Quoted 5 lines

Thanks! This was not obvious to figure out.

Is there an arch bottleneck because of which they do this? I mean to say,

is something stopping us from simply redirecting __pte_free_tlb to tlb_remove_ptdesc

Some architectures have special handling in __pte_free_tlb(), and cannot simple redirect __pte_free_tlb() to tlb_remove_ptdesc(), such as m68k, powerpc, etc.

For those architectures that call pte_free() in __pte_free_tlb(), it should be easy to modify them.

If you're not in a rush, I can take the time to finish the above tasks.

Quoted 7 lines

or pte_free_defer?

I am looking to enable this config at least on arm64 by default, I believe it will be legal

to do this at least here.

IIRC, arm64 can directly enable CONFIG_PT_RECLAIM, as it is supported at the architecture level.

Thanks,
Qi

Quoted 63 lines
Quoted 63 lines

We need to modify these architectures first, otherwise it will lead to UAF. This approach is feasible because Hugh provides similar support in pte_free_defer().

Enabling PT_RECLAIM on all architecture has always been on my TODO list, but it's been blocked by other things. :(

Thanks,
Qi

Quoted 49 lines

---
  arch/x86/Kconfig | 1 -
  mm/Kconfig       | 5 +----
  mm/pt_reclaim.c  | 2 +-

  3 files changed, 2 insertions(+), 6 deletions(-)
arch/x86/Kconfig +0 -0
index fa3b616af03a..5681308a5650 100644
@@ -327,7 +327,6 @@ config X86

      select FUNCTION_ALIGNMENT_4B
      imply IMA_SECURE_AND_OR_TRUSTED_BOOT    if EFI select HAVE_DYNAMIC_FTRACE_NO_PATCHABLE -    select ARCH_SUPPORTS_PT_RECLAIM        if X86_64 select ARCH_SUPPORTS_SCHED_SMT        if SMP select SCHED_SMT            if SMP select ARCH_SUPPORTS_SCHED_CLUSTER    if SMP

mm/Kconfig +0 -0
index 0e26f4fc8717..903c37d02555 100644
@@ -1355,13 +1355,10 @@ config ARCH_HAS_USER_SHADOW_STACK

        The architecture has hardware support for userspace shadow call stacks (eg, x86 CET, arm64 GCS or RISC-V Zicfiss). -config ARCH_SUPPORTS_PT_RECLAIM
-    def_bool n
-
  config PT_RECLAIM
      bool "reclaim empty user page table pages"
      default y
-    depends on ARCH_SUPPORTS_PT_RECLAIM && MMU && SMP
+    depends on MMU && SMP
      select MMU_GATHER_RCU_TABLE_FREE
      help
        Try to reclaim empty user page table pages in paths other than munmap

mm/pt_reclaim.c +1 -1
index 7e9455a18aae..049e17f08c6a 100644
@@ -1,6 +1,6 @@
   // SPDX-License-Identifier: GPL-2.0
   #include <linux/hugetlb.h>
-#include <asm-generic/tlb.h>
+#include <asm/tlb.h>
   #include <asm/pgalloc.h>
     #include "internal.h"
author
#4 lore raw
Quoted 25 lines · Qi Zheng

Hi Dev,

Quoted 16 lines · Dev Jain
Quoted 8 lines · Qi Zheng

Hi Dev,

Quoted 4 lines · Dev Jain

The implementation of CONFIG_PT_RECLAIM is completely contained in generic mm code. It depends on the RCU callback which will reclaim the pagetables - there is nothing arch-specific about that. So, enable this config for all architectures.

Quoted 5 lines

Thanks for doing this!

But unfortunately, not all architectures call tlb_remove_ptdesc() in __pte_free_tlb(). Some architectures directly call pte_free() to free PTE pages (without RCU).

Quoted 5 lines

Thanks! This was not obvious to figure out.

Is there an arch bottleneck because of which they do this? I mean to say,

is something stopping us from simply redirecting __pte_free_tlb to tlb_remove_ptdesc

Quoted 8 lines

Some architectures have special handling in __pte_free_tlb(), and cannot simple redirect __pte_free_tlb() to tlb_remove_ptdesc(), such as m68k, powerpc, etc.

For those architectures that call pte_free() in __pte_free_tlb(), it should be easy to modify them.

If you're not in a rush, I can take the time to finish the above tasks.

Right then, I'll leave that up to you!

Quoted 79 lines
Quoted 8 lines

or pte_free_defer?

I am looking to enable this config at least on arm64 by default, I believe it will be legal

to do this at least here.

IIRC, arm64 can directly enable CONFIG_PT_RECLAIM, as it is supported at the architecture level.

Thanks,
Qi

Quoted 63 lines
Quoted 63 lines

We need to modify these architectures first, otherwise it will lead to UAF. This approach is feasible because Hugh provides similar support in pte_free_defer().

Enabling PT_RECLAIM on all architecture has always been on my TODO list, but it's been blocked by other things. :(

Thanks,
Qi

Quoted 49 lines

---
  arch/x86/Kconfig | 1 -
  mm/Kconfig       | 5 +----
  mm/pt_reclaim.c  | 2 +-

  3 files changed, 2 insertions(+), 6 deletions(-)
arch/x86/Kconfig +0 -0
index fa3b616af03a..5681308a5650 100644
@@ -327,7 +327,6 @@ config X86

      select FUNCTION_ALIGNMENT_4B
      imply IMA_SECURE_AND_OR_TRUSTED_BOOT    if EFI select HAVE_DYNAMIC_FTRACE_NO_PATCHABLE -    select ARCH_SUPPORTS_PT_RECLAIM        if X86_64 select ARCH_SUPPORTS_SCHED_SMT        if SMP select SCHED_SMT            if SMP select ARCH_SUPPORTS_SCHED_CLUSTER    if SMP

mm/Kconfig +0 -0
index 0e26f4fc8717..903c37d02555 100644
@@ -1355,13 +1355,10 @@ config ARCH_HAS_USER_SHADOW_STACK

        The architecture has hardware support for userspace shadow call stacks (eg, x86 CET, arm64 GCS or RISC-V Zicfiss). -config ARCH_SUPPORTS_PT_RECLAIM
-    def_bool n
-
  config PT_RECLAIM
      bool "reclaim empty user page table pages"
      default y
-    depends on ARCH_SUPPORTS_PT_RECLAIM && MMU && SMP
+    depends on MMU && SMP
      select MMU_GATHER_RCU_TABLE_FREE
      help
        Try to reclaim empty user page table pages in paths other than munmap

mm/pt_reclaim.c +1 -1
index 7e9455a18aae..049e17f08c6a 100644
@@ -1,6 +1,6 @@
   // SPDX-License-Identifier: GPL-2.0
   #include <linux/hugetlb.h>
-#include <asm-generic/tlb.h>
+#include <asm/tlb.h>
   #include <asm/pgalloc.h>
     #include "internal.h"
#5 lore raw
Quoted 31 lines · Dev Jain
Quoted 29 lines · Qi Zheng

Hi Dev,

Quoted 16 lines · Dev Jain
Quoted 8 lines · Qi Zheng

Hi Dev,

Quoted 4 lines · Dev Jain

The implementation of CONFIG_PT_RECLAIM is completely contained in generic mm code. It depends on the RCU callback which will reclaim the pagetables - there is nothing arch-specific about that. So, enable this config for all architectures.

Quoted 5 lines

Thanks for doing this!

But unfortunately, not all architectures call tlb_remove_ptdesc() in __pte_free_tlb(). Some architectures directly call pte_free() to free PTE pages (without RCU).

Quoted 5 lines

Thanks! This was not obvious to figure out.

Is there an arch bottleneck because of which they do this? I mean to say,

is something stopping us from simply redirecting __pte_free_tlb to tlb_remove_ptdesc

Some architectures have special handling in __pte_free_tlb(), and cannot simple redirect __pte_free_tlb() to tlb_remove_ptdesc(), such as m68k, powerpc, etc.

Quoted 6 lines
Quoted 4 lines

For those architectures that call pte_free() in __pte_free_tlb(), it should be easy to modify them.

If you're not in a rush, I can take the time to finish the above tasks.

Right then, I'll leave that up to you!

OK, I will do it ASAP.

Quoted 81 lines
Quoted 81 lines
Quoted 10 lines

or pte_free_defer?

I am looking to enable this config at least on arm64 by default, I believe it will be legal

to do this at least here.

IIRC, arm64 can directly enable CONFIG_PT_RECLAIM, as it is supported at the architecture level.

Thanks,
Qi

Quoted 63 lines
Quoted 63 lines

We need to modify these architectures first, otherwise it will lead to UAF. This approach is feasible because Hugh provides similar support in pte_free_defer().

Enabling PT_RECLAIM on all architecture has always been on my TODO list, but it's been blocked by other things. :(

Thanks,
Qi

Quoted 49 lines

---
  arch/x86/Kconfig | 1 -
  mm/Kconfig       | 5 +----
  mm/pt_reclaim.c  | 2 +-

  3 files changed, 2 insertions(+), 6 deletions(-)
arch/x86/Kconfig +0 -0
index fa3b616af03a..5681308a5650 100644
@@ -327,7 +327,6 @@ config X86

      select FUNCTION_ALIGNMENT_4B
      imply IMA_SECURE_AND_OR_TRUSTED_BOOT    if EFI select HAVE_DYNAMIC_FTRACE_NO_PATCHABLE -    select ARCH_SUPPORTS_PT_RECLAIM        if X86_64 select ARCH_SUPPORTS_SCHED_SMT        if SMP select SCHED_SMT            if SMP select ARCH_SUPPORTS_SCHED_CLUSTER    if SMP

mm/Kconfig +0 -0
index 0e26f4fc8717..903c37d02555 100644
@@ -1355,13 +1355,10 @@ config ARCH_HAS_USER_SHADOW_STACK

        The architecture has hardware support for userspace shadow call stacks (eg, x86 CET, arm64 GCS or RISC-V Zicfiss). -config ARCH_SUPPORTS_PT_RECLAIM
-    def_bool n
-
  config PT_RECLAIM
      bool "reclaim empty user page table pages"
      default y
-    depends on ARCH_SUPPORTS_PT_RECLAIM && MMU && SMP
+    depends on MMU && SMP
      select MMU_GATHER_RCU_TABLE_FREE
      help
        Try to reclaim empty user page table pages in paths other than munmap

mm/pt_reclaim.c +1 -1
index 7e9455a18aae..049e17f08c6a 100644
@@ -1,6 +1,6 @@
   // SPDX-License-Identifier: GPL-2.0
   #include <linux/hugetlb.h>
-#include <asm-generic/tlb.h>
+#include <asm/tlb.h>
   #include <asm/pgalloc.h>
     #include "internal.h"
#6 lore raw

From: Lance Yang <[email protected]>

Quoted 38 lines · Qi Zheng
Quoted 35 lines · Dev Jain
Quoted 33 lines · Qi Zheng

Hi Dev,

Quoted 18 lines · Dev Jain
Quoted 10 lines · Qi Zheng

Hi Dev,

Quoted 6 lines · Dev Jain

The implementation of CONFIG_PT_RECLAIM is completely contained in generic
mm code. It depends on the RCU callback which will reclaim the pagetables -
there is nothing arch-specific about that. So, enable this config for all architectures.

Quoted 5 lines

Thanks for doing this!

But unfortunately, not all architectures call tlb_remove_ptdesc() in __pte_free_tlb(). Some architectures directly call pte_free() to free PTE pages (without RCU).

Quoted 7 lines

Thanks! This was not obvious to figure out.

Is there an arch bottleneck because of which they do this? I mean to say,

is something stopping us from simply redirecting __pte_free_tlb to tlb_remove_ptdesc

Some architectures have special handling in __pte_free_tlb(), and cannot simple redirect __pte_free_tlb() to tlb_remove_ptdesc(), such as m68k, powerpc, etc.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

For those architectures that call pte_free() in __pte_free_tlb(), it should be easy to modify them.

If you're not in a rush, I can take the time to finish the above tasks.

Right then, I'll leave that up to you!

OK, I will do it ASAP.

Cool! Looking forward to seeing that land ;p

Cheers,
Lance

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

or pte_free_defer?

I am looking to enable this config at least on arm64 by default, I believe it will be legal

Great proposal, Dev! That looks like a very useful feature. Let's make it happen on arm64 ;)

Quoted 77 lines
Quoted 75 lines
Quoted 75 lines
Quoted 2 lines

to do this at least here.

IIRC, arm64 can directly enable CONFIG_PT_RECLAIM, as it is supported at the architecture level.

Thanks,
Qi

Quoted 65 lines
Quoted 65 lines

We need to modify these architectures first, otherwise it will lead to UAF. This approach is feasible because Hugh provides similar support in pte_free_defer().

Enabling PT_RECLAIM on all architecture has always been on my TODO list, but it's been blocked by other things. :(

Thanks,
Qi

Quoted 51 lines

---
  arch/x86/Kconfig | 1 -
  mm/Kconfig       | 5 +----
  mm/pt_reclaim.c  | 2 +-

  3 files changed, 2 insertions(+), 6 deletions(-)
arch/x86/Kconfig +0 -0
index fa3b616af03a..5681308a5650 100644
@@ -327,7 +327,6 @@ config X86

      select FUNCTION_ALIGNMENT_4B
      imply IMA_SECURE_AND_OR_TRUSTED_BOOT    if EFI select HAVE_DYNAMIC_FTRACE_NO_PATCHABLE -    select ARCH_SUPPORTS_PT_RECLAIM        if X86_64 select ARCH_SUPPORTS_SCHED_SMT        if SMP select SCHED_SMT            if SMP select ARCH_SUPPORTS_SCHED_CLUSTER    if SMP

mm/Kconfig +0 -0
index 0e26f4fc8717..903c37d02555 100644
@@ -1355,13 +1355,10 @@ config ARCH_HAS_USER_SHADOW_STACK

        The architecture has hardware support for userspace shadow call
            stacks (eg, x86 CET, arm64 GCS or RISC-V Zicfiss). -config ARCH_SUPPORTS_PT_RECLAIM
-    def_bool n
-
  config PT_RECLAIM
      bool "reclaim empty user page table pages" default y
-    depends on ARCH_SUPPORTS_PT_RECLAIM && MMU && SMP +    depends on MMU && SMP
      select MMU_GATHER_RCU_TABLE_FREE
      help
        Try to reclaim empty user page table pages in paths other than munmap

mm/pt_reclaim.c +1 -1
index 7e9455a18aae..049e17f08c6a 100644
@@ -1,6 +1,6 @@
   // SPDX-License-Identifier: GPL-2.0
   #include <linux/hugetlb.h>
-#include <asm-generic/tlb.h>
+#include <asm/tlb.h>
   #include <asm/pgalloc.h>
     #include "internal.h"
author
#7 lore raw
Quoted 48 lines · Lance Yang

From: Lance Yang <[email protected]>

Quoted 32 lines · Qi Zheng
Quoted 30 lines · Dev Jain
Quoted 29 lines · Qi Zheng

Hi Dev,

Quoted 15 lines · Dev Jain
Quoted 9 lines · Qi Zheng

Hi Dev,

Quoted 6 lines · Dev Jain

The implementation of CONFIG_PT_RECLAIM is completely contained in generic
mm code. It depends on the RCU callback which will reclaim the pagetables -
there is nothing arch-specific about that. So, enable this config for all architectures.

Quoted 5 lines

Thanks for doing this!

But unfortunately, not all architectures call tlb_remove_ptdesc() in __pte_free_tlb(). Some architectures directly call pte_free() to free PTE pages (without RCU).

Quoted 7 lines

Thanks! This was not obvious to figure out.

Is there an arch bottleneck because of which they do this? I mean to say,

is something stopping us from simply redirecting __pte_free_tlb to tlb_remove_ptdesc

Some architectures have special handling in __pte_free_tlb(), and cannot simple redirect __pte_free_tlb() to tlb_remove_ptdesc(), such as m68k, powerpc, etc.

Quoted 6 lines
Quoted 5 lines
Quoted 4 lines

For those architectures that call pte_free() in __pte_free_tlb(), it should be easy to modify them.

If you're not in a rush, I can take the time to finish the above tasks.

Right then, I'll leave that up to you!

OK, I will do it ASAP.

Cool! Looking forward to seeing that land ;p

Cheers,
Lance

Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

or pte_free_defer?

I am looking to enable this config at least on arm64 by default, I believe it will be legal

Great proposal, Dev! That looks like a very useful feature. Let's make it happen on arm64 ;)

Yup, but not sure whether an arm64 enabling patch, only for that to go away when Qi implements the feature generically, is worth the trouble!

Quoted 70 lines
Quoted 70 lines
Quoted 69 lines
Quoted 69 lines
Quoted 2 lines

to do this at least here.

IIRC, arm64 can directly enable CONFIG_PT_RECLAIM, as it is supported at the architecture level.

Thanks,
Qi

Quoted 61 lines
Quoted 61 lines

We need to modify these architectures first, otherwise it will lead to UAF. This approach is feasible because Hugh provides similar support in pte_free_defer().

Enabling PT_RECLAIM on all architecture has always been on my TODO list, but it's been blocked by other things. :(

Thanks,
Qi

Quoted 50 lines
---
   arch/x86/Kconfig | 1 -
   mm/Kconfig       | 5 +----
   mm/pt_reclaim.c  | 2 +-
   3 files changed, 2 insertions(+), 6 deletions(-)
arch/x86/Kconfig +0 -1
index fa3b616af03a..5681308a5650 100644
@@ -327,7 +327,6 @@ config X86
       select FUNCTION_ALIGNMENT_4B
       imply IMA_SECURE_AND_OR_TRUSTED_BOOT    if EFI
       select HAVE_DYNAMIC_FTRACE_NO_PATCHABLE
-    select ARCH_SUPPORTS_PT_RECLAIM        if X86_64
       select ARCH_SUPPORTS_SCHED_SMT        if SMP
       select SCHED_SMT            if SMP
       select ARCH_SUPPORTS_SCHED_CLUSTER    if SMP
mm/Kconfig +0 -0
index 0e26f4fc8717..903c37d02555 100644
@@ -1355,13 +1355,10 @@ config ARCH_HAS_USER_SHADOW_STACK
         The architecture has hardware support for userspace shadow

call
            stacks (eg, x86 CET, arm64 GCS or RISC-V Zicfiss). -config ARCH_SUPPORTS_PT_RECLAIM
-    def_bool n
-
  config PT_RECLAIM
      bool "reclaim empty user page table pages" default y
-    depends on ARCH_SUPPORTS_PT_RECLAIM && MMU && SMP +    depends on MMU && SMP
      select MMU_GATHER_RCU_TABLE_FREE
      help
        Try to reclaim empty user page table pages in paths other
than munmap

mm/pt_reclaim.c +1 -1
index 7e9455a18aae..049e17f08c6a 100644
@@ -1,6 +1,6 @@
   // SPDX-License-Identifier: GPL-2.0
   #include <linux/hugetlb.h>
-#include <asm-generic/tlb.h>
+#include <asm/tlb.h>
   #include <asm/pgalloc.h>
     #include "internal.h"
#8 lore raw
In reply to Qi Zheng

From: Lance Yang <[email protected]>

Quoted 38 lines · Qi Zheng
Quoted 35 lines · Dev Jain
Quoted 33 lines · Qi Zheng

Hi Dev,

Quoted 18 lines · Dev Jain
Quoted 10 lines · Qi Zheng

Hi Dev,

Quoted 6 lines · Dev Jain

The implementation of CONFIG_PT_RECLAIM is completely contained in generic
mm code. It depends on the RCU callback which will reclaim the pagetables -
there is nothing arch-specific about that. So, enable this config for all architectures.

Quoted 5 lines

Thanks for doing this!

But unfortunately, not all architectures call tlb_remove_ptdesc() in __pte_free_tlb(). Some architectures directly call pte_free() to free PTE pages (without RCU).

Quoted 7 lines

Thanks! This was not obvious to figure out.

Is there an arch bottleneck because of which they do this? I mean to say,

is something stopping us from simply redirecting __pte_free_tlb to tlb_remove_ptdesc

Some architectures have special handling in __pte_free_tlb(), and cannot simple redirect __pte_free_tlb() to tlb_remove_ptdesc(), such as m68k, powerpc, etc.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

For those architectures that call pte_free() in __pte_free_tlb(), it should be easy to modify them.

If you're not in a rush, I can take the time to finish the above tasks.

Right then, I'll leave that up to you!

OK, I will do it ASAP.

Cool! Looking forward to seeing that land ;p

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

or pte_free_defer?

I am looking to enable this config at least on arm64 by default, I believe it will be legal

Great proposal, Dev! That looks like a very useful feature. Let's make it happen on arm64 ;)

Quoted 77 lines
Quoted 75 lines
Quoted 75 lines
Quoted 2 lines

to do this at least here.

IIRC, arm64 can directly enable CONFIG_PT_RECLAIM, as it is supported at the architecture level.

Thanks,
Qi

Quoted 65 lines
Quoted 65 lines

We need to modify these architectures first, otherwise it will lead to UAF. This approach is feasible because Hugh provides similar support in pte_free_defer().

Enabling PT_RECLAIM on all architecture has always been on my TODO list, but it's been blocked by other things. :(

Thanks,
Qi

Quoted 51 lines

---
  arch/x86/Kconfig | 1 -
  mm/Kconfig       | 5 +----
  mm/pt_reclaim.c  | 2 +-

  3 files changed, 2 insertions(+), 6 deletions(-)
arch/x86/Kconfig +0 -0
index fa3b616af03a..5681308a5650 100644
@@ -327,7 +327,6 @@ config X86

      select FUNCTION_ALIGNMENT_4B
      imply IMA_SECURE_AND_OR_TRUSTED_BOOT    if EFI select HAVE_DYNAMIC_FTRACE_NO_PATCHABLE -    select ARCH_SUPPORTS_PT_RECLAIM        if X86_64 select ARCH_SUPPORTS_SCHED_SMT        if SMP select SCHED_SMT            if SMP select ARCH_SUPPORTS_SCHED_CLUSTER    if SMP

mm/Kconfig +0 -0
index 0e26f4fc8717..903c37d02555 100644
@@ -1355,13 +1355,10 @@ config ARCH_HAS_USER_SHADOW_STACK

        The architecture has hardware support for userspace shadow call
            stacks (eg, x86 CET, arm64 GCS or RISC-V Zicfiss). -config ARCH_SUPPORTS_PT_RECLAIM
-    def_bool n
-
  config PT_RECLAIM
      bool "reclaim empty user page table pages" default y
-    depends on ARCH_SUPPORTS_PT_RECLAIM && MMU && SMP +    depends on MMU && SMP
      select MMU_GATHER_RCU_TABLE_FREE
      help
        Try to reclaim empty user page table pages in paths other than munmap

mm/pt_reclaim.c +1 -1
index 7e9455a18aae..049e17f08c6a 100644
@@ -1,6 +1,6 @@
   // SPDX-License-Identifier: GPL-2.0
   #include <linux/hugetlb.h>
-#include <asm-generic/tlb.h>
+#include <asm/tlb.h>
   #include <asm/pgalloc.h>
     #include "internal.h"