Skip to contentSkip to conversation

riscv: mm: Enable PMD split page table lock for RV64

PATCH Superseded Kefeng Wang 2 participants 4 messages Jul 30, 2021 – Aug 27, 2021 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 riscv: mm: Enable PMD split page table lock for RV64

After commit 1355c31eeb7e ("asm-generic: pgalloc: provide generic pmd_alloc_one() and pmd_free_one()"), it is easy to enable ARCH_ENABLE_SPLIT_PMD_PTLOCK for RV64.

---
 arch/riscv/Kconfig   | 1 +
 arch/riscv/mm/init.c | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)
arch/riscv/Kconfig +1 -0
index 8fcceb8eda07..c3e456fc7108 100644
@@ -12,6 +12,7 @@ config 32BIT
 
 config RISCV
 	def_bool y
+	select ARCH_ENABLE_SPLIT_PMD_PTLOCK if PGTABLE_LEVELS > 2
 	select ARCH_CLOCKSOURCE_INIT
 	select ARCH_SUPPORTS_ATOMIC_RMW
 	select ARCH_SUPPORTS_DEBUG_PAGEALLOC if MMU
arch/riscv/mm/init.c +2 -1
index e547e53cddd2..ce12905a0224 100644
@@ -361,7 +361,8 @@ static phys_addr_t __init alloc_pmd_late(uintptr_t va)
 	unsigned long vaddr;
 
 	vaddr = __get_free_page(GFP_KERNEL);
-	BUG_ON(!vaddr);
+	BUG_ON(!vaddr || !pgtable_pmd_page_ctor(virt_to_page(vaddr)));
+
 	return __pa(vaddr);
 }
 
Signature · 7 lines
2.26.2


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
reviewer Reviewed-by on v1 1/1
#1 lore raw

Hi Kefeng,

Quoted 28 lines · Kefeng Wang

After commit 1355c31eeb7e ("asm-generic: pgalloc: provide generic pmd_alloc_one() and pmd_free_one()"), it is easy to enable ARCH_ENABLE_SPLIT_PMD_PTLOCK for RV64.

---
  arch/riscv/Kconfig   | 1 +
  arch/riscv/mm/init.c | 3 ++-
  2 files changed, 3 insertions(+), 1 deletion(-)
arch/riscv/Kconfig +1 -0
index 8fcceb8eda07..c3e456fc7108 100644
@@ -12,6 +12,7 @@ config 32BIT
 
  config RISCV
  	def_bool y
+	select ARCH_ENABLE_SPLIT_PMD_PTLOCK if PGTABLE_LEVELS > 2
  	select ARCH_CLOCKSOURCE_INIT
  	select ARCH_SUPPORTS_ATOMIC_RMW
  	select ARCH_SUPPORTS_DEBUG_PAGEALLOC if MMU
arch/riscv/mm/init.c +0 -0
index e547e53cddd2..ce12905a0224 100644

arch/riscv/mm/init.c static phys_addr_t __init alloc_pmd_late(uintptr_t va) · line 368

Quoted 9 lines
arch/riscv/mm/init.c +2 -1
@@ -361,7 +361,8 @@ static phys_addr_t __init alloc_pmd_late(uintptr_t va)
  	unsigned long vaddr;
 
  	vaddr = __get_free_page(GFP_KERNEL);
-	BUG_ON(!vaddr);
+	BUG_ON(!vaddr || !pgtable_pmd_page_ctor(virt_to_page(vaddr)));
+
  	return __pa(vaddr);
  }
 

I took the time to check how the page table lock works, and indeed, the commit you mention makes it easy to enable this feature since the initialization of the lock for the general case is done there and your patch seems correct as this is the only place we allocate a PMD page, and the PTE page allocation already calls pgtable_pte_page_ctor.

Maybe your commit message would need some of the explanation I gave above, or something similar, but this is up to you.

You can add:

Thanks,

Alex

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#2 lore raw
Quoted 41 lines · Alex Ghiti

Hi Kefeng,

Quoted 26 lines · Kefeng Wang

After commit 1355c31eeb7e ("asm-generic: pgalloc: provide generic pmd_alloc_one() and pmd_free_one()"), it is easy to enable ARCH_ENABLE_SPLIT_PMD_PTLOCK for RV64.

---
  arch/riscv/Kconfig   | 1 +
  arch/riscv/mm/init.c | 3 ++-

  2 files changed, 3 insertions(+), 1 deletion(-)
arch/riscv/Kconfig +0 -0
index 8fcceb8eda07..c3e456fc7108 100644
@@ -12,6 +12,7 @@ config 32BIT

    config RISCV
      def_bool y
+    select ARCH_ENABLE_SPLIT_PMD_PTLOCK if PGTABLE_LEVELS > 2 select ARCH_CLOCKSOURCE_INIT
      select ARCH_SUPPORTS_ATOMIC_RMW
      select ARCH_SUPPORTS_DEBUG_PAGEALLOC if MMU

arch/riscv/mm/init.c +0 -0
index e547e53cddd2..ce12905a0224 100644

arch/riscv/mm/init.c static phys_addr_t __init · line 368

Quoted 9 lines
arch/riscv/mm/init.c +2 -1
@@ -361,7 +361,8 @@ static phys_addr_t __init 
 alloc_pmd_late(uintptr_t va)
       unsigned long vaddr;
         vaddr = __get_free_page(GFP_KERNEL);
-    BUG_ON(!vaddr);
+    BUG_ON(!vaddr || !pgtable_pmd_page_ctor(virt_to_page(vaddr)));
+
       return __pa(vaddr);
   }
 

I took the time to check how the page table lock works, and indeed, the commit you mention makes it easy to enable this feature since the initialization of the lock for the general case is done there and your patch seems correct as this is the only place we allocate a PMD page, and the PTE page allocation already calls pgtable_pte_page_ctor.

Quoted 1 line

Maybe your commit message would need some of the explanation I gave above, or something similar, but this is up to you.

There is a  Documentation/vm/split_page_table_lock.rst doc about this feature, we could learn more from changelog with the feature introduced.

Quoted 4 lines

You can add:

Thanks, Alex ;)

Quoted 6 lines

Thanks,

Alex
.

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#3 lore raw
In reply to Kefeng Wang

Hi Palmer, ping ...

Quoted 27 lines · Kefeng Wang

After commit 1355c31eeb7e ("asm-generic: pgalloc: provide generic pmd_alloc_one() and pmd_free_one()"), it is easy to enable ARCH_ENABLE_SPLIT_PMD_PTLOCK for RV64.

---
  arch/riscv/Kconfig   | 1 +
  arch/riscv/mm/init.c | 3 ++-
  2 files changed, 3 insertions(+), 1 deletion(-)
arch/riscv/Kconfig +1 -0
index 8fcceb8eda07..c3e456fc7108 100644
@@ -12,6 +12,7 @@ config 32BIT
 
  config RISCV
  	def_bool y
+	select ARCH_ENABLE_SPLIT_PMD_PTLOCK if PGTABLE_LEVELS > 2
  	select ARCH_CLOCKSOURCE_INIT
  	select ARCH_SUPPORTS_ATOMIC_RMW
  	select ARCH_SUPPORTS_DEBUG_PAGEALLOC if MMU
arch/riscv/mm/init.c +0 -0
index e547e53cddd2..ce12905a0224 100644

arch/riscv/mm/init.c static phys_addr_t __init alloc_pmd_late(uintptr_t va) · line 368

Quoted 9 lines
arch/riscv/mm/init.c +2 -1
@@ -361,7 +361,8 @@ static phys_addr_t __init alloc_pmd_late(uintptr_t va)
  	unsigned long vaddr;
 
  	vaddr = __get_free_page(GFP_KERNEL);
-	BUG_ON(!vaddr);
+	BUG_ON(!vaddr || !pgtable_pmd_page_ctor(virt_to_page(vaddr)));
+
  	return __pa(vaddr);
  }
 

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv