powerpc/mm: Cleanup memory block size probing
Subsystems (2)
PATCH v3 1/2 powerpc/mm: Cleanup memory block size probing
Parse the device tree in early init to find the memory block size to be used by the kernel. Consolidate the memory block size device tree parsing to one helper and use that on both powernv and pseries. We still want to use machine-specific callback because on all machine types other than powernv and pseries we continue to return MIN_MEMORY_BLOCK_SIZE.
pseries_memory_block_size used to look for the second memory block (memory@x) to determine the memory_block_size value. This patch changed that to look at all memory blocks and make sure we can map them all correctly using the computed memory block size value.
Add workaround to force 256MB memory block size if device driver managed memory such as GPU memory is present. This helps to add GPU memory that is not aligned to 1G.
---
Changes from v2:
* Add workaround for forcing 256MB memory blocksize with GPU
arch/powerpc/include/asm/book3s/64/mmu.h | 5 +- arch/powerpc/mm/book3s64/radix_pgtable.c | 65 +--------- arch/powerpc/mm/init_64.c | 115 ++++++++++++++++++ arch/powerpc/platforms/powernv/setup.c | 10 +- .../platforms/pseries/hotplug-memory.c | 60 +-------- arch/powerpc/platforms/pseries/pseries.h | 2 - arch/powerpc/platforms/pseries/setup.c | 7 ++ 7 files changed, 129 insertions(+), 135 deletions(-)
arch/powerpc/include/asm/book3s/64/mmu.h +1 -4
@@ -71,10 +71,7 @@ extern unsigned int mmu_pid_bits;/* Base PID to allocate from */ extern unsigned int mmu_base_pid; -/* -* memory block size used with radix translation. -*/ -extern unsigned long __ro_after_init radix_mem_block_size; +extern unsigned long __ro_after_init memory_block_size;#define PRTB_SIZE_SHIFT (mmu_pid_bits + 4)#define PRTB_ENTRIES (1ul << mmu_pid_bits)
arch/powerpc/mm/book3s64/radix_pgtable.c +1 -64
89 lines not on this page · raw message
arch/powerpc/mm/init_64.c +115 -0
133 lines not on this page · raw message
arch/powerpc/platforms/powernv/setup.c +1 -9
@@ -482,15 +482,7 @@ static void pnv_kexec_cpu_down(int crash_shutdown, int secondary)#ifdef CONFIG_MEMORY_HOTPLUG static unsigned long pnv_memory_block_size (void ) { -/* -* We map the kernel linear region with 1GB large pages on radix. For -* memory hot unplug to work our memory block size must be at least -* this size. -*/ -if (radix_enabled ()) -return radix_mem_block_size; -else -return 256UL *1024 *1024 ; +return memory_block_size; }#endif
arch/powerpc/platforms/pseries/hotplug-memory.c +4 -56
93 lines not on this page · raw message
arch/powerpc/platforms/pseries/pseries.h +0 -2
@@ -90,8 +90,6 @@ extern struct pci_controller_ops pseries_pci_controller_ops;int pseries_msi_allocate_domains (struct pci_controller *phb);void pseries_msi_free_domains (struct pci_controller *phb); -unsigned long pseries_memory_block_size (void ); -extern int CMO_PrPSP;extern int CMO_SecPSP;extern unsigned long CMO_PageSize;
arch/powerpc/platforms/pseries/setup.c +7 -0
@@ -1116,6 +1116,13 @@ static int pSeries_pci_probe_mode(struct pci_bus *bus)return PCI_PROBE_NORMAL ; } +#ifdef CONFIG_MEMORY_HOTPLUG +static unsigned long pseries_memory_block_size (void ) +{ +return memory_block_size; +} +#endif +struct pci_controller_ops pseries_pci_controller_ops = { .probe_mode = pSeries_pci_probe_mode, #ifdef CONFIG_SPAPR_TCE_IOMMU
Signature · 1 line
2.41.0
PATCH v3 2/2 powerpc/mm: Add memory_block_size as a kernel parameter
Certain devices can possess non-standard memory capacities, not constrained to multiples of 1GB. Provide a kernel parameter so that we can map the device memory completely on memory hotplug.
Restrict memory_block_size value to a power of 2 value similar to LMB size. The memory block size should also be more than the section size.
--- .../admin-guide/kernel-parameters.txt | 3 +++ arch/powerpc/kernel/setup_64.c | 23 +++++++++++++++++++ arch/powerpc/mm/init_64.c | 17 ++++++++++---- 3 files changed, 38 insertions(+), 5 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +3 -0
@@ -3201,6 +3201,9 @@ Note that even when enabled, there are a few cases where the feature is not effective. + memory_block_size=size [PPC] + Use this parameter to configure the memory block size value. + memtest= [KNL,X86,ARM,M68K,PPC,RISCV] Enable memtest Format: <integer> default : 0 <disable>
arch/powerpc/kernel/setup_64.c +23 -0
@@ -892,6 +892,29 @@ unsigned long memory_block_size_bytes(void) return MIN_MEMORY_BLOCK_SIZE; } + +/* +* Restrict to a power of 2 value for memblock which is larger than +* section size +*/ +static int __init parse_mem_block_size (char *ptr) +{ +unsigned int order; +unsigned long size =memparse (ptr,NULL ); + + order =fls64 (size); +if (!order) +return 0 ; + + order--; +if (order <SECTION_SIZE_BITS ) +return 0 ; + + memory_block_size =1UL << order; + +return 0 ; +} +early_param ("memory_block_size" , parse_mem_block_size);#endif #if defined(CONFIG_PPC_INDIRECT_PIO ) || defined(CONFIG_PPC_INDIRECT_MMIO )
arch/powerpc/mm/init_64.c +12 -5
@@ -569,13 +569,20 @@ static int __init probe_memory_block_size(unsigned long node, const char *uname,return 0 ; } -/* -* start with 1G memory block size. Early init will -* fix this with correct value. -*/ -unsigned long memory_block_size__ro_after_init =1UL <<30 ; +unsigned long memory_block_size__ro_after_init ;static void __init early_init_memory_block_size (void ) { +/* +* if it is set via early param just return. +*/ +if (memory_block_size) +return ; + +/* +* start with 1G memory block size. update_memory_block_size() +* will derive the right value based on device tree details. +*/ + memory_block_size =SZ_1G ;/* * We need to do memory_block_size probe early so that * radix__early_init_mmu() can use this as limit for
Signature · 1 line
2.41.0
Quoted 2 lines · Aneesh Kumar K.V
arch/powerpc/mm/init_64.c +0
-0
[snip]
arch/powerpc/mm/init_64.c
Quoted 13 lines
arch/powerpc/mm/init_64.c +13
-0+/* +* "ibm,coherent-device-memory with linux,usable-memory = 0 +* Force 256MiB block size. Work around for GPUs on P9 PowerNV +* linux,usable-memory == 0 implies driver managed memory and +* we can't use large memory block size due to hotplug/unplug +* limitations. +*/ + compatible =of_get_flat_dt_prop (node,"compatible" ,NULL ); +if (compatible && !strcmp (compatible,"ibm,coherent-device-memory" )) { +int len =0 ; +const __be32 *usm; + + usm =of_get_flat_dt_prop (node,"linux,drconf-usable-memory" , &len);
I think this should be "linux,usable-memory".
arch/powerpc/mm/init_64.c
Quoted 4 lines
arch/powerpc/mm/init_64.c +4
-0+if (usm && !len) { + *block_size =SZ_256M ; +return 1 ; + }
This isn't quite right. The criteria is not that the property itself has no registers, it's that the base/size combo has size zero.
If you fold in the patch appended to the end of this mail, things worked for me.
Quoted 15 lines
arch/powerpc/mm/init_64.c +15
-0+ } + + reg =of_get_flat_dt_prop (node,"reg" , &l); + endp = reg + (l /sizeof (__be32)); + +while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) { +u64 base, size; + + base =dt_mem_next_cell (dt_root_addr_cells, ®); + size =dt_mem_next_cell (dt_root_size_cells, ®); + +if (size ==0 ) +continue ; + +update_memory_block_size (block_size, size);
arch/powerpc/mm/init_64.c
Quoted 10 lines
arch/powerpc/mm/init_64.c +10
-0+ } +/* continue looking for other memory device types */ +return 0 ; +} + +/* +* start with 1G memory block size. Early init will +* fix this with correct value. +*/ +unsigned long memory_block_size__ro_after_init =1UL <<30 ;
Could use SZ_1G here.
With the following fixup, I got 256MiB blocks on a system with "ibm,coherent-device-memory" nodes.
arch/powerpc/mm/init_64.c +21 -22
@@ -487,7 +487,6 @@ static int __init probe_memory_block_size(unsigned long node, const char *uname, depth, void *data) {const char *type; -const char *compatible;unsigned long *block_size = (unsigned long *)data;const __be32 *reg, *endp;int l;
@@ -532,38 +531,38 @@ static int __init probe_memory_block_size(unsigned long node, const char *uname,if (type ==NULL ||strcmp (type,"memory" ) !=0 )return 0 ; -/* -* "ibm,coherent-device-memory with linux,usable-memory = 0 -* Force 256MiB block size. Work around for GPUs on P9 PowerNV -* linux,usable-memory == 0 implies driver managed memory and -* we can't use large memory block size due to hotplug/unplug -* limitations. -*/ - compatible =of_get_flat_dt_prop (node,"compatible" ,NULL ); -if (compatible && !strcmp (compatible,"ibm,coherent-device-memory" )) { -int len =0 ; -const __be32 *usm; - - usm =of_get_flat_dt_prop (node,"linux,drconf-usable-memory" , &len); -if (usm && !len) { - *block_size =SZ_256M ; -return 1 ; - } - } + reg =of_get_flat_dt_prop (node,"linux,usable-memory" , &l); +if (!reg) + reg =of_get_flat_dt_prop (node,"reg" , &l); +if (!reg) +return 0 ; - reg =of_get_flat_dt_prop (node,"reg" , &l); endp = reg + (l /sizeof (__be32));while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) { +const char *compatible;u64 base, size; base =dt_mem_next_cell (dt_root_addr_cells, ®); size =dt_mem_next_cell (dt_root_size_cells, ®); -if (size ==0 ) +if (size) { +update_memory_block_size (block_size, size);continue ; + } -update_memory_block_size (block_size, size); +/* +* ibm,coherent-device-memory with linux,usable-memory = 0 +* Force 256MiB block size. Work around for GPUs on P9 PowerNV +* linux,usable-memory == 0 implies driver managed memory and +* we can't use large memory block size due to hotplug/unplug +* limitations. +*/ + compatible =of_get_flat_dt_prop (node,"compatible" ,NULL ); +if (compatible && !strcmp (compatible,"ibm,coherent-device-memory" )) { + *block_size =SZ_256M ; +return 1 ; + } }/* continue looking for other memory device types */ return 0 ;
Signature · 1 line
Reza Arbab
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Aneesh,
kernel test robot noticed the following build errors:
[auto build test ERROR on powerpc/next]
[also build test ERROR on powerpc/fixes linus/master v6.5-rc3 next-20230728] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Aneesh-Kumar-K-V/powerpc-mm-Add-memory_block_size-as-a-kernel-parameter/20230728-184256 base: https://git.kernel.org/pub/scm/linux/kernel/git/powerpc/linux.git next patch link: https://lore.kernel.org/r/20230728103556.745681-1-aneesh.kumar%40linux.ibm.com patch subject: [PATCH v3 1/2] powerpc/mm: Cleanup memory block size probing config: powerpc-powernv_defconfig (https://download.01.org/0day-ci/archive/20230729/[email protected]/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a) reproduce: (https://download.01.org/0day-ci/archive/20230729/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> arch/powerpc/mm/init_64.c:558:7: error: variable 'base' set but not used [-Werror,-Wunused-but-set-variable]
558 | u64 base, size;
| ^1 error generated.
vim +/base +558 arch/powerpc/mm/init_64.c
485
486 static int __init probe_memory_block_size(unsigned long node, const char *uname, int
487 depth, void *data)
488 {
489 const char *type;
490 const char *compatible;
491 unsigned long *block_size = (unsigned long *)data;
492 const __be32 *reg, *endp;
493 int l;
494
495 if (depth != 1)
496 return 0;
497 /*
498 * If we have dynamic-reconfiguration-memory node, use the
499 * lmb value.
500 */
501 if (strcmp(uname, "ibm,dynamic-reconfiguration-memory") == 0) {
502
503 const __be32 *prop;
504
505 prop = of_get_flat_dt_prop(node, "ibm,lmb-size", &l);
506
507 if (!prop || l < dt_root_size_cells * sizeof(__be32))
508 /*
509 * Nothing in the device tree
510 */
511 *block_size = MIN_MEMORY_BLOCK_SIZE;
512 else
513 *block_size = of_read_number(prop, dt_root_size_cells);
514 /*
515 * We have found the final value. Don't probe further.
516 */
517 return 1;
518 }
519 /*
520 * Find all the device tree nodes of memory type and make sure
521 * the area can be mapped using the memory block size value
522 * we end up using. We start with 1G value and keep reducing
523 * it such that we can map the entire area using memory_block_size.
524 * This will be used on powernv and older pseries that don't
525 * have ibm,lmb-size node.
526 * For ex: with P5 we can end up with
527 * memory@0 -> 128MB
528 * memory@128M -> 64M
529 * This will end up using 64MB memory block size value.
530 */
531 type = of_get_flat_dt_prop(node, "device_type", NULL);
532 if (type == NULL || strcmp(type, "memory") != 0)
533 return 0;
534
535 /*
536 * "ibm,coherent-device-memory with linux,usable-memory = 0
537 * Force 256MiB block size. Work around for GPUs on P9 PowerNV
538 * linux,usable-memory == 0 implies driver managed memory and
539 * we can't use large memory block size due to hotplug/unplug
540 * limitations.
541 */
542 compatible = of_get_flat_dt_prop(node, "compatible", NULL);
543 if (compatible && !strcmp(compatible, "ibm,coherent-device-memory")) {
544 int len = 0;
545 const __be32 *usm;
546
547 usm = of_get_flat_dt_prop(node, "linux,drconf-usable-memory", &len);
548 if (usm && !len) {
549 *block_size = SZ_256M;
550 return 1;
551 }
552 }
553
554 reg = of_get_flat_dt_prop(node, "reg", &l);
555 endp = reg + (l / sizeof(__be32));
556
557 while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) {
> 558 u64 base, size;
559
560 base = dt_mem_next_cell(dt_root_addr_cells, ®);
561 size = dt_mem_next_cell(dt_root_size_cells, ®);
562
563 if (size == 0)
564 continue;
565
566 update_memory_block_size(block_size, size);
567 }
568 /* continue looking for other memory device types */
569 return 0;
570 }
571
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Quoted 124 lines · Reza Arbab
Quoted 2 lines · Aneesh Kumar K.V
arch/powerpc/mm/init_64.c +0
-0[snip]
Quoted 5 lines
+ /*
+ * "ibm,coherent-device-memory with linux,usable-memory = 0 + * Force 256MiB block size. Work around for GPUs on P9 PowerNV + * linux,usable-memory == 0 implies driver managed memory and + * we can't use large memory block size due to hotplug/unplugQuoted 8 lines
+ * limitations.
+ */
+ compatible =of_get_flat_dt_prop(node, "compatible", NULL); + if (compatible && !strcmp(compatible, "ibm,coherent-device-memory")) { + int len = 0;
+ const__be32*usm;
+
+ usm =of_get_flat_dt_prop(node, "linux,drconf-usable-memory", &len);I think this should be "linux,usable-memory".
Quoted 4 lines
+ if (usm && !len) {
+*block_size=SZ_256M;
+ return 1;
+ }This isn't quite right. The criteria is not that the property itself has no registers, it's that the base/size combo has size zero.
If you fold in the patch appended to the end of this mail, things worked for me.
Quoted 15 lines
+ }
arch/powerpc/mm/init_64.c +14
-0+ + reg = of_get_flat_dt_prop(node, "reg", &l); + endp = reg + (l / sizeof(__be32)); + + while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) { + u64 base, size; + + base = dt_mem_next_cell(dt_root_addr_cells, ®); + size = dt_mem_next_cell(dt_root_size_cells, ®); + + if (size == 0) + continue; + + update_memory_block_size(block_size, size);arch/powerpc/mm/init_64.c
Quoted 10 lines
arch/powerpc/mm/init_64.c +10
-0+ } + /* continue looking for other memory device types */ + return 0; +} + +/* +* start with 1G memory block size. Early init will +* fix this with correct value. +*/ +unsigned long memory_block_size__ro_after_init =1UL <<30 ;Could use
SZ_1Ghere.With the following fixup, I got 256MiB blocks on a system with "ibm,coherent-device-memory" nodes.
arch/powerpc/mm/init_64.c +0
-1@@ -487,7 +487,6 @@ static int __init probe_memory_block_size(unsigned long node, const char *uname, depth, void *data) { const char *type; - const char *compatible; unsigned long *block_size = (unsigned long *)data; const __be32 *reg, *endp; int l;@@ -532,38 +531,38 @@ static int __init probe_memory_block_size(unsigned long node, const char *uname, if (type == NULL || strcmp(type, "memory") != 0) return 0;
- /*
- * "ibm,coherent-device-memory with linux,usable-memory = 0 - * Force 256MiB block size. Work around for GPUs on P9 PowerNV - * linux,usable-memory == 0 implies driver managed memory and - * we can't use large memory block size due to hotplug/unplug - * limitations.
- */
- compatible =of_get_flat_dt_prop(node, "compatible", NULL); - if (compatible && !strcmp(compatible, "ibm,coherent-device-memory")) { - int len = 0;
- const__be32*usm;
-
- usm =of_get_flat_dt_prop(node, "linux,drconf-usable-memory", &len); - if (usm && !len) {
-*block_size=SZ_256M;
- return 1;
- }
- }
+ reg =of_get_flat_dt_prop(node, "linux,usable-memory", &l); + if (!reg)
+ reg =of_get_flat_dt_prop(node, "reg", &l);
+ if (!reg)
+ return 0;
- reg =of_get_flat_dt_prop(node, "reg", &l);
endp = reg + (l /sizeof(__be32));
while ((endp - reg) >= (dt_root_addr_cells+dt_root_size_cells)) { + const char *compatible;
u64 base, size;
base =dt_mem_next_cell(dt_root_addr_cells, ®);
size =dt_mem_next_cell(dt_root_size_cells, ®);
- if (size == 0)
+ if (size) {
+update_memory_block_size(block_size, size); continue;
+ }
-update_memory_block_size(block_size, size);
+ /*
+ * ibm,coherent-device-memory with linux,usable-memory = 0 + * Force 256MiB block size. Work around for GPUs on P9 PowerNV + * linux,usable-memory == 0 implies driver managed memory and + * we can't use large memory block size due to hotplug/unplug + * limitations.
+ */
Quoted 8 lines
+ compatible =
of_get_flat_dt_prop(node, "compatible", NULL); + if (compatible && !strcmp(compatible, "ibm,coherent-device-memory")) { +*block_size=SZ_256M;
+ return 1;
+ }
}
/* continue looking for other memory device types */
return 0;
Thanks for correcting the right device tree node and testing the changes. Can I add
-aneesh
Quoted 3 lines · Aneesh Kumar K V
Thanks for correcting the right device tree node and testing the changes. Can I add
Co-authored-by Reza Arbab <[email protected]>
Sure, that's fine.
Signature · 1 line
Reza Arbab