diff mbox series

[1/4] powerpc/64s: Add DEBUG_PAGEALLOC for radix

Message ID 20220919014437.608167-1-nicholas@linux.ibm.com (mailing list archive)
State Superseded
Headers show
Series [1/4] powerpc/64s: Add DEBUG_PAGEALLOC for radix | expand

Commit Message

Nicholas Miehlbradt Sept. 19, 2022, 1:44 a.m. UTC
There is support for DEBUG_PAGEALLOC on hash but not on radix.
Add support on radix.

Signed-off-by: Nicholas Miehlbradt <nicholas@linux.ibm.com>
---
 arch/powerpc/mm/book3s64/radix_pgtable.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

Comments

Christophe Leroy Sept. 19, 2022, 6:17 a.m. UTC | #1
Le 19/09/2022 à 03:44, Nicholas Miehlbradt a écrit :
> [Vous ne recevez pas souvent de courriers de nicholas@linux.ibm.com. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ]
> 
> There is support for DEBUG_PAGEALLOC on hash but not on radix.
> Add support on radix.
> 
> Signed-off-by: Nicholas Miehlbradt <nicholas@linux.ibm.com>
> ---
>   arch/powerpc/mm/book3s64/radix_pgtable.c | 16 +++++++++++++++-
>   1 file changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c b/arch/powerpc/mm/book3s64/radix_pgtable.c
> index db2f3d193448..483c99bfbde5 100644
> --- a/arch/powerpc/mm/book3s64/radix_pgtable.c
> +++ b/arch/powerpc/mm/book3s64/radix_pgtable.c
> @@ -30,6 +30,7 @@
>   #include <asm/trace.h>
>   #include <asm/uaccess.h>
>   #include <asm/ultravisor.h>
> +#include <asm/set_memory.h>
> 
>   #include <trace/events/thp.h>
> 
> @@ -503,6 +504,9 @@ static unsigned long __init radix_memory_block_size(void)
>   {
>          unsigned long mem_block_size = MIN_MEMORY_BLOCK_SIZE;
> 
> +       if (debug_pagealloc_enabled())
> +               return PAGE_SIZE;
> +
>          /*
>           * OPAL firmware feature is set by now. Hence we are ok
>           * to test OPAL feature.
> @@ -519,6 +523,9 @@ static unsigned long __init radix_memory_block_size(void)
> 
>   static unsigned long __init radix_memory_block_size(void)
>   {
> +       if (debug_pagealloc_enabled())
> +               return PAGE_SIZE;
> +
>          return 1UL * 1024 * 1024 * 1024;

While at it, maybe you can replace the above by SZ_1G

>   }
> 
> @@ -899,7 +906,14 @@ void __meminit radix__vmemmap_remove_mapping(unsigned long start, unsigned long
>   #ifdef CONFIG_DEBUG_PAGEALLOC
>   void radix__kernel_map_pages(struct page *page, int numpages, int enable)
>   {
> -       pr_warn_once("DEBUG_PAGEALLOC not supported in radix mode\n");
> +       unsigned long addr;
> +
> +       addr = (unsigned long)page_address(page);
> +
> +       if (enable)
> +               set_memory_p(addr, numpages);
> +       else
> +               set_memory_np(addr, numpages);
>   }
>   #endif
> 
> --
> 2.34.1
>
Michael Ellerman Sept. 19, 2022, 7 a.m. UTC | #2
Nicholas Miehlbradt <nicholas@linux.ibm.com> writes:
> There is support for DEBUG_PAGEALLOC on hash but not on radix.
> Add support on radix.
>
> Signed-off-by: Nicholas Miehlbradt <nicholas@linux.ibm.com>
> ---
>  arch/powerpc/mm/book3s64/radix_pgtable.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c b/arch/powerpc/mm/book3s64/radix_pgtable.c
> index db2f3d193448..483c99bfbde5 100644
> --- a/arch/powerpc/mm/book3s64/radix_pgtable.c
> +++ b/arch/powerpc/mm/book3s64/radix_pgtable.c
> @@ -30,6 +30,7 @@
>  #include <asm/trace.h>
>  #include <asm/uaccess.h>
>  #include <asm/ultravisor.h>
> +#include <asm/set_memory.h>
>  
>  #include <trace/events/thp.h>
>  
> @@ -503,6 +504,9 @@ static unsigned long __init radix_memory_block_size(void)
>  {
>  	unsigned long mem_block_size = MIN_MEMORY_BLOCK_SIZE;
>  
> +	if (debug_pagealloc_enabled())
> +		return PAGE_SIZE;
> +
>  	/*
>  	 * OPAL firmware feature is set by now. Hence we are ok
>  	 * to test OPAL feature.
> @@ -519,6 +523,9 @@ static unsigned long __init radix_memory_block_size(void)
>  
>  static unsigned long __init radix_memory_block_size(void)
>  {
> +	if (debug_pagealloc_enabled())
> +		return PAGE_SIZE;
> +
>  	return 1UL * 1024 * 1024 * 1024;
>  }
  
This value ends up in radix_mem_block_size, which is returned by 
pnv_memory_block_size(), which is wired up as ppc_md.memory_block_size,
and that's called by memory_block_size_bytes().

And I thought that value had to be >= MIN_MEMORY_BLOCK_SIZE.

#define MIN_MEMORY_BLOCK_SIZE     (1UL << SECTION_SIZE_BITS)
#define SECTION_SIZE_BITS       24


I would expect us to hit the panic in memory_dev_init().

So that's odd.

I suspect you need to leave radix_memory_block_size() alone, or at least
make sure you return MIN_MEMORY_BLOCK_SIZE when debug page alloc is
enabled.

We probably need a separate variable that holds the max page size used
for the linear mapping, and that would then be 1G in the normal case or
PAGE_SIZE in the debug page alloc case.

cheers
Christophe Leroy Sept. 19, 2022, 7:05 a.m. UTC | #3
Le 19/09/2022 à 09:00, Michael Ellerman a écrit :
> Nicholas Miehlbradt <nicholas@linux.ibm.com> writes:
>> There is support for DEBUG_PAGEALLOC on hash but not on radix.
>> Add support on radix.
>>
>> Signed-off-by: Nicholas Miehlbradt <nicholas@linux.ibm.com>
>> ---
>>   arch/powerpc/mm/book3s64/radix_pgtable.c | 16 +++++++++++++++-
>>   1 file changed, 15 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c b/arch/powerpc/mm/book3s64/radix_pgtable.c
>> index db2f3d193448..483c99bfbde5 100644
>> --- a/arch/powerpc/mm/book3s64/radix_pgtable.c
>> +++ b/arch/powerpc/mm/book3s64/radix_pgtable.c
>> @@ -30,6 +30,7 @@
>>   #include <asm/trace.h>
>>   #include <asm/uaccess.h>
>>   #include <asm/ultravisor.h>
>> +#include <asm/set_memory.h>
>>   
>>   #include <trace/events/thp.h>
>>   
>> @@ -503,6 +504,9 @@ static unsigned long __init radix_memory_block_size(void)
>>   {
>>   	unsigned long mem_block_size = MIN_MEMORY_BLOCK_SIZE;
>>   
>> +	if (debug_pagealloc_enabled())
>> +		return PAGE_SIZE;
>> +
>>   	/*
>>   	 * OPAL firmware feature is set by now. Hence we are ok
>>   	 * to test OPAL feature.
>> @@ -519,6 +523,9 @@ static unsigned long __init radix_memory_block_size(void)
>>   
>>   static unsigned long __init radix_memory_block_size(void)
>>   {
>> +	if (debug_pagealloc_enabled())
>> +		return PAGE_SIZE;
>> +
>>   	return 1UL * 1024 * 1024 * 1024;
>>   }
>    
> This value ends up in radix_mem_block_size, which is returned by
> pnv_memory_block_size(), which is wired up as ppc_md.memory_block_size,
> and that's called by memory_block_size_bytes().
> 
> And I thought that value had to be >= MIN_MEMORY_BLOCK_SIZE.
> 
> #define MIN_MEMORY_BLOCK_SIZE     (1UL << SECTION_SIZE_BITS)
> #define SECTION_SIZE_BITS       24
> 
> 
> I would expect us to hit the panic in memory_dev_init().
> 
> So that's odd.
> 
> I suspect you need to leave radix_memory_block_size() alone, or at least
> make sure you return MIN_MEMORY_BLOCK_SIZE when debug page alloc is
> enabled.
> 
> We probably need a separate variable that holds the max page size used
> for the linear mapping, and that would then be 1G in the normal case or
> PAGE_SIZE in the debug page alloc case.
> 

I don't know the details of PPC64, but as you mention linear mapping, be 
aware that you don't need to map everything with pages. Only data. You 
can keep text mapped by blocks, it's what is done on 8xx and book3s/32.

Christophe
diff mbox series

Patch

diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c b/arch/powerpc/mm/book3s64/radix_pgtable.c
index db2f3d193448..483c99bfbde5 100644
--- a/arch/powerpc/mm/book3s64/radix_pgtable.c
+++ b/arch/powerpc/mm/book3s64/radix_pgtable.c
@@ -30,6 +30,7 @@ 
 #include <asm/trace.h>
 #include <asm/uaccess.h>
 #include <asm/ultravisor.h>
+#include <asm/set_memory.h>
 
 #include <trace/events/thp.h>
 
@@ -503,6 +504,9 @@  static unsigned long __init radix_memory_block_size(void)
 {
 	unsigned long mem_block_size = MIN_MEMORY_BLOCK_SIZE;
 
+	if (debug_pagealloc_enabled())
+		return PAGE_SIZE;
+
 	/*
 	 * OPAL firmware feature is set by now. Hence we are ok
 	 * to test OPAL feature.
@@ -519,6 +523,9 @@  static unsigned long __init radix_memory_block_size(void)
 
 static unsigned long __init radix_memory_block_size(void)
 {
+	if (debug_pagealloc_enabled())
+		return PAGE_SIZE;
+
 	return 1UL * 1024 * 1024 * 1024;
 }
 
@@ -899,7 +906,14 @@  void __meminit radix__vmemmap_remove_mapping(unsigned long start, unsigned long
 #ifdef CONFIG_DEBUG_PAGEALLOC
 void radix__kernel_map_pages(struct page *page, int numpages, int enable)
 {
-	pr_warn_once("DEBUG_PAGEALLOC not supported in radix mode\n");
+	unsigned long addr;
+
+	addr = (unsigned long)page_address(page);
+
+	if (enable)
+		set_memory_p(addr, numpages);
+	else
+		set_memory_np(addr, numpages);
 }
 #endif