memblock: cleanup memblock_free interface
Subsystems (39)
Mike Rapoport
maintainercover memblock: cleanup memblock_free interface
From: Mike Rapoport <[email protected]>
Hi,
Following the discussion on [1] this is the fix for memblock freeing APIs mismatch.
The first patch is a cleanup of numa_distance allocation in arch_numa I've spotted during the conversion.
The second patch is a fix for Xen memory freeing on some of the error paths.
The core change is in the third patch that makes memblock_free() a counterpart of memblock_alloc() and adds memblock_phys_alloc() to be a counterpart of memblock_phys_alloc().
Since scripts/get_maintainer.pl returned more than 100 addresses I've trimmed the distribution list only to the relevant lists.
[1] https://lore.kernel.org/all/CAHk-=wj9k4LZTz+svCxLYs5Y1=+yKrbAUArH1+ghyG3OLd8VVg@mail.gmail.com
Mike Rapoport (3):
arch_numa: simplify numa_distance allocation
xen/x86: free_p2m_page: use memblock_free_ptr() to free a virtual pointer
memblock: cleanup memblock_free interface
arch/alpha/kernel/core_irongate.c | 2 +- arch/arc/mm/init.c | 2 +- arch/arm/mach-hisi/platmcpm.c | 2 +- arch/arm/mm/init.c | 2 +- arch/arm64/mm/mmu.c | 4 ++-- arch/mips/mm/init.c | 2 +- arch/mips/sgi-ip30/ip30-setup.c | 6 +++--- arch/powerpc/kernel/dt_cpu_ftrs.c | 2 +- arch/powerpc/kernel/paca.c | 4 ++-- arch/powerpc/kernel/setup-common.c | 2 +- arch/powerpc/kernel/setup_64.c | 2 +- arch/powerpc/platforms/powernv/pci-ioda.c | 2 +- arch/powerpc/platforms/pseries/svm.c | 4 +--- arch/riscv/kernel/setup.c | 4 ++-- arch/s390/kernel/setup.c | 8 ++++---- arch/s390/kernel/smp.c | 4 ++-- arch/s390/kernel/uv.c | 2 +- arch/s390/mm/kasan_init.c | 2 +- arch/sh/boards/mach-ap325rxa/setup.c | 2 +- arch/sh/boards/mach-ecovec24/setup.c | 4 ++-- arch/sh/boards/mach-kfr2r09/setup.c | 2 +- arch/sh/boards/mach-migor/setup.c | 2 +- arch/sh/boards/mach-se/7724/setup.c | 4 ++-- arch/sparc/kernel/smp_64.c | 2 +- arch/um/kernel/mem.c | 2 +- arch/x86/kernel/setup.c | 4 ++-- arch/x86/kernel/setup_percpu.c | 2 +- arch/x86/mm/init.c | 2 +- arch/x86/mm/kasan_init_64.c | 4 ++-- arch/x86/mm/numa.c | 2 +- arch/x86/mm/numa_emulation.c | 2 +- arch/x86/xen/mmu_pv.c | 6 +++--- arch/x86/xen/p2m.c | 2 +- arch/x86/xen/setup.c | 6 +++--- drivers/base/arch_numa.c | 10 ++++------ drivers/firmware/efi/memmap.c | 2 +- drivers/macintosh/smu.c | 2 +- drivers/of/kexec.c | 2 +- drivers/of/of_reserved_mem.c | 4 ++-- drivers/s390/char/sclp_early.c | 2 +- drivers/usb/early/xhci-dbc.c | 10 +++++----- drivers/xen/swiotlb-xen.c | 2 +- include/linux/memblock.h | 16 ++-------------- init/initramfs.c | 2 +- init/main.c | 2 +- kernel/dma/swiotlb.c | 2 +- kernel/printk/printk.c | 4 ++-- lib/bootconfig.c | 2 +- lib/cpumask.c | 2 +- mm/cma.c | 2 +- mm/memblock.c | 20 ++++++++++---------- mm/memory_hotplug.c | 2 +- mm/percpu.c | 8 ++++---- mm/sparse.c | 2 +- tools/bootconfig/include/linux/memblock.h | 2 +- 55 files changed, 94 insertions(+), 110 deletions(-)
base-commit: e4e737bb5c170df6135a127739a9e6148ee3da82
Signature · 1 line
2.28.0
Mike Rapoport
maintainerPATCH 1/3 arch_numa: simplify numa_distance allocation
From: Mike Rapoport <[email protected]>
Memory allocation of numa_distance uses memblock_phys_alloc_range() without actual range limits, converts the returned physical address to virtual and then only uses the virtual address for further initialization.
Simplify this by replacing memblock_phys_alloc_range() with memblock_alloc().
--- drivers/base/arch_numa.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/base/arch_numa.c +2 -4
@@ -275,15 +275,13 @@ void __init numa_free_distance(void)static int __init numa_alloc_distance (void ) {size_t size; -u64 phys;int i, j; size = nr_node_ids * nr_node_ids *sizeof (numa_distance[0 ]); - phys =memblock_phys_alloc_range (size,PAGE_SIZE ,0 ,PFN_PHYS (max_pfn)); -if (WARN_ON (!phys)) + numa_distance =memblock_alloc (size,PAGE_SIZE ); +if (WARN_ON (!numa_distance))return -ENOMEM ; - numa_distance =__va (phys); numa_distance_cnt = nr_node_ids;/* fill with the default distances */
Signature · 1 line
2.28.0
Mike Rapoport
maintainerPATCH 2/3 xen/x86: free_p2m_page: use memblock_free_ptr() to free a virtual pointer
In reply to Mike RapoportFrom: Mike Rapoport <[email protected]>
free_p2m_page() wrongly passes a virtual pointer to memblock_free() that treats it as a physical address.
Call memblock_free_ptr() instead that gets a virtual address to free the memory.
--- arch/x86/xen/p2m.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/xen/p2m.c +1 -1
@@ -197,7 +197,7 @@ static void * __ref alloc_p2m_page(void)static void __ref free_p2m_page (void *p) {if (unlikely (!slab_is_available ())) { -memblock_free ((unsigned long )p,PAGE_SIZE ); +memblock_free_ptr (p,PAGE_SIZE );return ; }
Signature · 1 line
2.28.0
Mike Rapoport
maintainerPATCH 3/3 memblock: cleanup memblock_free interface
In reply to Mike RapoportFrom: Mike Rapoport <[email protected]>
For ages memblock_free() interface dealt with physical addresses even despite the existence of memblock_alloc_xx() functions that return a virtual pointer.
Introduce memblock_phys_free() for freeing physical ranges and repurpose memblock_free() to free virtual pointers to make the following pairing abundantly clear:
int memblock_phys_free(phys_addr_t base, phys_addr_t size); phys_addr_t memblock_phys_alloc(phys_addr_t base, phys_addr_t size); void *memblock_alloc(phys_addr_t size, phys_addr_t align); void memblock_free(void *ptr, size_t size);
Replace intermediate memblock_free_ptr() with memblock_free() and drop unnecessary aliases memblock_free_early() and memblock_free_early_nid().
--- arch/alpha/kernel/core_irongate.c | 2 +- arch/arc/mm/init.c | 2 +- arch/arm/mach-hisi/platmcpm.c | 2 +- arch/arm/mm/init.c | 2 +- arch/arm64/mm/mmu.c | 4 ++-- arch/mips/mm/init.c | 2 +- arch/mips/sgi-ip30/ip30-setup.c | 6 +++--- arch/powerpc/kernel/dt_cpu_ftrs.c | 2 +- arch/powerpc/kernel/paca.c | 4 ++-- arch/powerpc/kernel/setup-common.c | 2 +- arch/powerpc/kernel/setup_64.c | 2 +- arch/powerpc/platforms/powernv/pci-ioda.c | 2 +- arch/powerpc/platforms/pseries/svm.c | 4 +--- arch/riscv/kernel/setup.c | 4 ++-- arch/s390/kernel/setup.c | 8 ++++---- arch/s390/kernel/smp.c | 4 ++-- arch/s390/kernel/uv.c | 2 +- arch/s390/mm/kasan_init.c | 2 +- arch/sh/boards/mach-ap325rxa/setup.c | 2 +- arch/sh/boards/mach-ecovec24/setup.c | 4 ++-- arch/sh/boards/mach-kfr2r09/setup.c | 2 +- arch/sh/boards/mach-migor/setup.c | 2 +- arch/sh/boards/mach-se/7724/setup.c | 4 ++-- arch/sparc/kernel/smp_64.c | 2 +- arch/um/kernel/mem.c | 2 +- arch/x86/kernel/setup.c | 4 ++-- arch/x86/kernel/setup_percpu.c | 2 +- arch/x86/mm/init.c | 2 +- arch/x86/mm/kasan_init_64.c | 4 ++-- arch/x86/mm/numa.c | 2 +- arch/x86/mm/numa_emulation.c | 2 +- arch/x86/xen/mmu_pv.c | 6 +++--- arch/x86/xen/p2m.c | 2 +- arch/x86/xen/setup.c | 6 +++--- drivers/base/arch_numa.c | 4 ++-- drivers/firmware/efi/memmap.c | 2 +- drivers/macintosh/smu.c | 2 +- drivers/of/kexec.c | 2 +- drivers/of/of_reserved_mem.c | 4 ++-- drivers/s390/char/sclp_early.c | 2 +- drivers/usb/early/xhci-dbc.c | 10 +++++----- drivers/xen/swiotlb-xen.c | 2 +- include/linux/memblock.h | 16 ++-------------- init/initramfs.c | 2 +- init/main.c | 2 +- kernel/dma/swiotlb.c | 2 +- kernel/printk/printk.c | 4 ++-- lib/bootconfig.c | 2 +- lib/cpumask.c | 2 +- mm/cma.c | 2 +- mm/memblock.c | 20 ++++++++++---------- mm/memory_hotplug.c | 2 +- mm/percpu.c | 8 ++++---- mm/sparse.c | 2 +- tools/bootconfig/include/linux/memblock.h | 2 +- 55 files changed, 92 insertions(+), 106 deletions(-)
arch/alpha/kernel/core_irongate.c +1 -1
@@ -233,7 +233,7 @@ albacore_init_arch(void)unsigned long size; size = initrd_end - initrd_start; -memblock_free (__pa (initrd_start),PAGE_ALIGN (size)); +memblock_free ((void *)initrd_start,PAGE_ALIGN (size));if (!move_initrd (pci_mem)) printk("irongate_init_arch: initrd too big " "(%ldK)\ndisabling initrd\n",
arch/arc/mm/init.c +1 -1
@@ -173,7 +173,7 @@ static void __init highmem_init(void)#ifdef CONFIG_HIGHMEM unsigned long tmp; -memblock_free (high_mem_start, high_mem_sz); +memblock_phys_free (high_mem_start, high_mem_sz);for (tmp = min_high_pfn; tmp < max_high_pfn; tmp++)free_highmem_page (pfn_to_page (tmp));#endif
arch/arm/mach-hisi/platmcpm.c +1 -1
@@ -339,7 +339,7 @@ static int __init hip04_smp_init(void) err_sysctrl:iounmap (relocation); err_reloc: -memblock_free (hip04_boot_method[0 ], hip04_boot_method[1 ]); +memblock_phys_free (hip04_boot_method[0 ], hip04_boot_method[1 ]); err:return ret; }
arch/arm/mm/init.c +1 -1
@@ -158,7 +158,7 @@ phys_addr_t __init arm_memblock_steal(phys_addr_t size, phys_addr_t align)panic ("Failed to steal %pa bytes at %pS\n" , &size, (void *)_RET_IP_); -memblock_free (phys, size); +memblock_phys_free (phys, size);memblock_remove (phys, size);return phys;
arch/arm64/mm/mmu.c +2 -2
@@ -738,8 +738,8 @@ void __init paging_init(void)cpu_replace_ttbr1 (lm_alias (swapper_pg_dir)); init_mm.pgd = swapper_pg_dir; -memblock_free (__pa_symbol (init_pg_dir), -__pa_symbol (init_pg_end) -__pa_symbol (init_pg_dir)); +memblock_phys_free (__pa_symbol (init_pg_dir), +__pa_symbol (init_pg_end) -__pa_symbol (init_pg_dir));memblock_allow_resize (); }
arch/mips/mm/init.c +1 -1
@@ -529,7 +529,7 @@ static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size,static void __init pcpu_fc_free (void *ptr,size_t size) { -memblock_free_early (__pa (ptr), size); +memblock_free (ptr, size); }void __init setup_per_cpu_areas (void )
arch/mips/sgi-ip30/ip30-setup.c +3 -3
@@ -69,10 +69,10 @@ static void __init ip30_mem_init(void) total_mem += size;if (addr >=IP30_REAL_MEMORY_START ) -memblock_free (addr, size); +memblock_phys_free (addr, size);else if ((addr + size) >IP30_REAL_MEMORY_START ) -memblock_free (IP30_REAL_MEMORY_START , - size -IP30_MAX_PROM_MEMORY ); +memblock_phys_free (IP30_REAL_MEMORY_START , + size -IP30_MAX_PROM_MEMORY ); }pr_info ("Detected %luMB of physical memory.\n" ,MEM_SHIFT (total_mem)); }
arch/powerpc/kernel/dt_cpu_ftrs.c +1 -1
@@ -1095,7 +1095,7 @@ static int __init dt_cpu_ftrs_scan_callback(unsigned long node, const charcpufeatures_setup_finished (); -memblock_free (__pa (dt_cpu_features), +memblock_free (dt_cpu_features,sizeof (struct dt_cpu_feature )*nr_dt_cpu_features);return 0 ;
arch/powerpc/kernel/paca.c +2 -2
@@ -322,7 +322,7 @@ void __init free_unused_pacas(void) new_ptrs_size =sizeof (struct paca_struct *) * nr_cpu_ids;if (new_ptrs_size < paca_ptrs_size) -memblock_free (__pa (paca_ptrs) + new_ptrs_size, +memblock_free (paca_ptrs + new_ptrs_size, paca_ptrs_size - new_ptrs_size); paca_nr_cpu_ids = nr_cpu_ids;
@@ -331,7 +331,7 @@ void __init free_unused_pacas(void)#ifdef CONFIG_PPC_BOOK3S_64 if (early_radix_enabled ()) {/* Ugly fixup, see new_slb_shadow() */ -memblock_free (__pa (paca_ptrs[boot_cpuid]->slb_shadow_ptr), +memblock_free (paca_ptrs[boot_cpuid]->slb_shadow_ptr,sizeof (struct slb_shadow )); paca_ptrs[boot_cpuid]->slb_shadow_ptr =NULL ; }
arch/powerpc/kernel/setup-common.c +1 -1
@@ -825,7 +825,7 @@ static void __init smp_setup_pacas(void) set_hard_smp_processor_id(cpu, cpu_to_phys_id[cpu]); } -memblock_free (__pa (cpu_to_phys_id), nr_cpu_ids *sizeof (u32)); +memblock_free (cpu_to_phys_id, nr_cpu_ids *sizeof (u32)); cpu_to_phys_id =NULL ; }#endif
arch/powerpc/kernel/setup_64.c +1 -1
@@ -812,7 +812,7 @@ static void * __init pcpu_alloc_bootmem(unsigned int cpu, size_t size,static void __init pcpu_free_bootmem (void *ptr,size_t size) { -memblock_free (__pa (ptr), size); +memblock_free (ptr, size); }static int pcpu_cpu_distance (unsigned int from,unsigned int to)
arch/powerpc/platforms/powernv/pci-ioda.c +1 -1
@@ -2981,7 +2981,7 @@ static void __init pnv_pci_init_ioda_phb(struct device_node *np,if (!phb->hose) {pr_err (" Can't allocate PCI controller for %pOF\n" , np); -memblock_free (__pa (phb),sizeof (struct pnv_phb )); +memblock_free (phb,sizeof (struct pnv_phb ));return ; }
arch/powerpc/platforms/pseries/svm.c +1 -3
@@ -55,9 +55,7 @@ void __init svm_swiotlb_init(void)if (vstart && !swiotlb_init_with_tbl (vstart, io_tlb_nslabs, false))return ; - -memblock_free_early (__pa (vstart), -PAGE_ALIGN (io_tlb_nslabs <<IO_TLB_SHIFT )); +memblock_free (vstart,PAGE_ALIGN (io_tlb_nslabs <<IO_TLB_SHIFT ));panic ("SVM: Cannot allocate SWIOTLB buffer" ); }
arch/riscv/kernel/setup.c +2 -2
@@ -230,13 +230,13 @@ static void __init init_resources(void)/* Clean-up any unused pre-allocated resources */ if (res_idx >=0 ) -memblock_free (__pa (mem_res), (res_idx +1 ) *sizeof (*mem_res)); +memblock_free (mem_res, (res_idx +1 ) *sizeof (*mem_res));return ; error:/* Better an empty resource tree than an inconsistent one */ release_child_resources (&iomem_resource); -memblock_free (__pa (mem_res), mem_res_sz); +memblock_free (mem_res, mem_res_sz); }
arch/s390/kernel/setup.c +4 -4
@@ -693,7 +693,7 @@ static void __init reserve_crashkernel(void) }if (register_memory_notifier (&kdump_mem_nb)) { -memblock_free (crash_base, crash_size); +memblock_phys_free (crash_base, crash_size);return ; }
@@ -748,7 +748,7 @@ static void __init free_mem_detect_info(void)get_mem_detect_reserved (&start, &size);if (size) -memblock_free (start, size); +memblock_phys_free (start, size); }static const char *__init get_mem_info_source (void )
@@ -793,7 +793,7 @@ static void __init check_initrd(void)if (initrd_data.start && initrd_data.size && !memblock_is_region_memory (initrd_data.start, initrd_data.size)) {pr_err ("The initial RAM disk does not fit into the memory\n" ); -memblock_free (initrd_data.start, initrd_data.size); +memblock_phys_free (initrd_data.start, initrd_data.size); initrd_start = initrd_end =0 ; }#endif
@@ -890,7 +890,7 @@ static void __init setup_randomness(void)if (stsi (vmms,3 ,2 ,2 ) ==0 && vmms->count)add_device_randomness (&vmms->vm,sizeof (vmms->vm[0 ]) * vmms->count); -memblock_free ((unsigned long ) vmms,PAGE_SIZE ); +memblock_phys_free ((unsigned long ) vmms,PAGE_SIZE ); }/*
arch/s390/kernel/smp.c +2 -2
@@ -723,7 +723,7 @@ void __init smp_save_dump_cpus(void)/* Get the CPU registers */ smp_save_cpu_regs (sa, addr, is_boot_cpu, page); } -memblock_free (page,PAGE_SIZE ); +memblock_phys_free (page,PAGE_SIZE ); diag_amode31_ops.diag308_reset ();pcpu_set_smt (0 ); }
@@ -880,7 +880,7 @@ void __init smp_detect_cpus(void)/* Add CPUs present at boot */ __smp_rescan_cpus (info, true); -memblock_free_early ((unsigned long )info,sizeof (*info)); +memblock_free (info,sizeof (*info)); }/*
arch/s390/kernel/uv.c +1 -1
@@ -64,7 +64,7 @@ void __init setup_uv(void) }if (uv_init (uv_stor_base, uv_info.uv_base_stor_len)) { -memblock_free (uv_stor_base, uv_info.uv_base_stor_len); +memblock_phys_free (uv_stor_base, uv_info.uv_base_stor_len); goto fail; }
arch/s390/mm/kasan_init.c +1 -1
@@ -399,5 +399,5 @@ void __init kasan_copy_shadow_mapping(void)void __init kasan_free_early_identity (void ) { -memblock_free (pgalloc_pos, pgalloc_freeable - pgalloc_pos); +memblock_phys_free (pgalloc_pos, pgalloc_freeable - pgalloc_pos); }
arch/sh/boards/mach-ap325rxa/setup.c +1 -1
@@ -560,7 +560,7 @@ static void __init ap325rxa_mv_mem_reserve(void)if (!phys)panic ("Failed to allocate CEU memory\n" ); -memblock_free (phys, size); +memblock_phys_free (phys, size);memblock_remove (phys, size); ceu_dma_membase = phys;
arch/sh/boards/mach-ecovec24/setup.c +2 -2
@@ -1502,7 +1502,7 @@ static void __init ecovec_mv_mem_reserve(void)if (!phys)panic ("Failed to allocate CEU0 memory\n" ); -memblock_free (phys, size); +memblock_phys_free (phys, size);memblock_remove (phys, size); ceu0_dma_membase = phys;
@@ -1510,7 +1510,7 @@ static void __init ecovec_mv_mem_reserve(void)if (!phys)panic ("Failed to allocate CEU1 memory\n" ); -memblock_free (phys, size); +memblock_phys_free (phys, size);memblock_remove (phys, size); ceu1_dma_membase = phys; }
arch/sh/boards/mach-kfr2r09/setup.c +1 -1
@@ -633,7 +633,7 @@ static void __init kfr2r09_mv_mem_reserve(void)if (!phys)panic ("Failed to allocate CEU memory\n" ); -memblock_free (phys, size); +memblock_phys_free (phys, size);memblock_remove (phys, size); ceu_dma_membase = phys;
arch/sh/boards/mach-migor/setup.c +1 -1
@@ -633,7 +633,7 @@ static void __init migor_mv_mem_reserve(void)if (!phys)panic ("Failed to allocate CEU memory\n" ); -memblock_free (phys, size); +memblock_phys_free (phys, size);memblock_remove (phys, size); ceu_dma_membase = phys;
arch/sh/boards/mach-se/7724/setup.c +2 -2
@@ -966,7 +966,7 @@ static void __init ms7724se_mv_mem_reserve(void)if (!phys)panic ("Failed to allocate CEU0 memory\n" ); -memblock_free (phys, size); +memblock_phys_free (phys, size);memblock_remove (phys, size); ceu0_dma_membase = phys;
@@ -974,7 +974,7 @@ static void __init ms7724se_mv_mem_reserve(void)if (!phys)panic ("Failed to allocate CEU1 memory\n" ); -memblock_free (phys, size); +memblock_phys_free (phys, size);memblock_remove (phys, size); ceu1_dma_membase = phys; }
arch/sparc/kernel/smp_64.c +1 -1
@@ -1567,7 +1567,7 @@ static void * __init pcpu_alloc_bootmem(unsigned int cpu, size_t size,static void __init pcpu_free_bootmem (void *ptr,size_t size) { -memblock_free (__pa (ptr), size); +memblock_free (ptr, size); }static int __init pcpu_cpu_distance (unsigned int from,unsigned int to)
arch/um/kernel/mem.c +1 -1
@@ -47,7 +47,7 @@ void __init mem_init(void)*/ brk_end = (unsigned long )UML_ROUND_UP (sbrk (0 ));map_memory (brk_end,__pa (brk_end), uml_reserved - brk_end,1 ,1 ,0 ); -memblock_free (__pa (brk_end), uml_reserved - brk_end); +memblock_free ((void *)brk_end, uml_reserved - brk_end); uml_reserved = brk_end;/* this will put all low memory onto the freelists */
arch/x86/kernel/setup.c +2 -2
@@ -322,7 +322,7 @@ static void __init reserve_initrd(void)relocate_initrd (); - memblock_free(ramdisk_image, ramdisk_end - ramdisk_image); + memblock_phys_free(ramdisk_image, ramdisk_end - ramdisk_image); }#else
@@ -521,7 +521,7 @@ static void __init reserve_crashkernel(void) }if (crash_base >= (1ULL <<32 ) &&reserve_crashkernel_low ()) { -memblock_free (crash_base, crash_size); +memblock_phys_free (crash_base, crash_size);return ; }
arch/x86/kernel/setup_percpu.c +1 -1
@@ -135,7 +135,7 @@ static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size, size_t align)static void __init pcpu_fc_free (void *ptr,size_t size) { -memblock_free_ptr (ptr, size); +memblock_free (ptr, size); }static int __init pcpu_cpu_distance (unsigned int from,unsigned int to)
arch/x86/mm/init.c +1 -1
@@ -618,7 +618,7 @@ static void __init memory_map_top_down(unsigned long map_start,*/ addr =memblock_phys_alloc_range (PMD_SIZE ,PMD_SIZE , map_start, map_end); -memblock_free (addr,PMD_SIZE ); +memblock_phys_free (addr,PMD_SIZE ); real_end = addr +PMD_SIZE ;/* step_size need to be small so pgt_buf from BRK could cover it */
arch/x86/mm/kasan_init_64.c +2 -2
@@ -49,7 +49,7 @@ static void __init kasan_populate_pmd(pmd_t *pmd, unsigned long addr, p =early_alloc (PMD_SIZE , nid, false);if (p &&pmd_set_huge (pmd,__pa (p),PAGE_KERNEL ))return ; -memblock_free_ptr (p,PMD_SIZE ); +memblock_free (p,PMD_SIZE ); } p =early_alloc (PAGE_SIZE , nid, true);
@@ -85,7 +85,7 @@ static void __init kasan_populate_pud(pud_t *pud, unsigned long addr, p =early_alloc (PUD_SIZE , nid, false);if (p &&pud_set_huge (pud,__pa (p),PAGE_KERNEL ))return ; -memblock_free_ptr (p,PUD_SIZE ); +memblock_free (p,PUD_SIZE ); } p =early_alloc (PAGE_SIZE , nid, true);
arch/x86/mm/numa.c +1 -1
@@ -355,7 +355,7 @@ void __init numa_reset_distance(void)/* numa_distance could be 1LU marking allocation failure, test cnt */ if (numa_distance_cnt) -memblock_free_ptr (numa_distance, size); +memblock_free (numa_distance, size); numa_distance_cnt =0 ; numa_distance =NULL ;/* enable table creation */ }
arch/x86/mm/numa_emulation.c +1 -1
@@ -517,7 +517,7 @@ void __init numa_emulation(struct numa_meminfo *numa_meminfo, int numa_dist_cnt) }/* free the copied physical distance table */ -memblock_free_ptr (phys_dist, phys_size); +memblock_free (phys_dist, phys_size);return ; no_emu:
arch/x86/xen/mmu_pv.c +3 -3
@@ -1025,7 +1025,7 @@ static void __init xen_free_ro_pages(unsigned long paddr, unsigned long size)for (; vaddr < vaddr_end; vaddr +=PAGE_SIZE )make_lowmem_page_readwrite (vaddr); -memblock_free (paddr, size); +memblock_phys_free (paddr, size); }static void __init xen_cleanmfnmap_free_pgtbl (void *pgtbl,bool unpin)
@@ -1151,7 +1151,7 @@ static void __init xen_pagetable_p2m_free(void)xen_cleanhighmap (addr, addr + size); size =PAGE_ALIGN (xen_start_info->nr_pages *sizeof (unsigned long )); -memblock_free (__pa (addr), size); +memblock_free ((void *)addr, size); }else {xen_cleanmfnmap (addr); }
@@ -1955,7 +1955,7 @@ void __init xen_relocate_p2m(void) pfn_end = p2m_pfn_end; } -memblock_free (PFN_PHYS (pfn),PAGE_SIZE * (pfn_end - pfn)); +memblock_phys_free (PFN_PHYS (pfn),PAGE_SIZE * (pfn_end - pfn));while (pfn < pfn_end) {if (pfn == p2m_pfn) { pfn = p2m_pfn_end;
arch/x86/xen/p2m.c +1 -1
@@ -197,7 +197,7 @@ static void * __ref alloc_p2m_page(void)static void __ref free_p2m_page (void *p) {if (unlikely (!slab_is_available ())) { -memblock_free_ptr (p,PAGE_SIZE ); +memblock_free (p,PAGE_SIZE );return ; }
arch/x86/xen/setup.c +3 -3
@@ -153,7 +153,7 @@ static void __init xen_del_extra_mem(unsigned long start_pfn,break ; } } -memblock_free (PFN_PHYS (start_pfn),PFN_PHYS (n_pfns)); +memblock_phys_free (PFN_PHYS (start_pfn),PFN_PHYS (n_pfns)); }/*
@@ -719,7 +719,7 @@ static void __init xen_reserve_xen_mfnlist(void)return ;xen_relocate_p2m (); -memblock_free (start, size); +memblock_phys_free (start, size); }/**
@@ -885,7 +885,7 @@ char * __init xen_memory_setup(void)xen_phys_memcpy (new_area, start, size);pr_info ("initrd moved from [mem %#010llx-%#010llx] to [mem %#010llx-%#010llx]\n" , start, start + size, new_area, new_area + size); -memblock_free (start, size); +memblock_phys_free (start, size); boot_params.hdr.ramdisk_image = new_area; boot_params.ext_ramdisk_image = new_area >>32 ; }
drivers/base/arch_numa.c +2 -2
@@ -165,7 +165,7 @@ static void * __init pcpu_fc_alloc(unsigned int cpu, size_t size,static void __init pcpu_fc_free (void *ptr,size_t size) { -memblock_free_early (__pa (ptr), size); +memblock_free (ptr, size); }void __init setup_per_cpu_areas (void )
@@ -264,7 +264,7 @@ void __init numa_free_distance(void) size = numa_distance_cnt * numa_distance_cnt *sizeof (numa_distance[0 ]); -memblock_free_ptr (numa_distance, size); +memblock_free (numa_distance, size); numa_distance_cnt =0 ; numa_distance =NULL ; }
drivers/firmware/efi/memmap.c +1 -1
@@ -35,7 +35,7 @@ void __init __efi_memmap_free(u64 phys, unsigned long size, unsigned long flags)if (slab_is_available ())memblock_free_late (phys, size);else -memblock_free (phys, size); +memblock_phys_free (phys, size); }else if (flags &EFI_MEMMAP_SLAB ) {struct page *p =pfn_to_page (PHYS_PFN (phys));unsigned int order =get_order (size);
drivers/macintosh/smu.c +1 -1
@@ -570,7 +570,7 @@ int __init smu_init (void) fail_db_node:of_node_put (smu->db_node); fail_bootmem: -memblock_free_ptr (smu,sizeof (struct smu_device )); +memblock_free (smu,sizeof (struct smu_device )); smu =NULL ; fail_np:of_node_put (np);
drivers/of/kexec.c +1 -1
@@ -170,7 +170,7 @@ int ima_free_kexec_buffer(void)if (ret)return ret; -return memblock_free (addr, size); +return memblock_phys_free (addr, size); }
drivers/of/of_reserved_mem.c +2 -2
@@ -45,7 +45,7 @@ static int __init early_init_dt_alloc_reserved_memory_arch(phys_addr_t size,if (nomap) { err =memblock_mark_nomap (base, size);if (err) -memblock_free (base, size); +memblock_phys_free (base, size); }return err;
@@ -282,7 +282,7 @@ void __init fdt_init_reserved_mem(void)if (nomap)memblock_clear_nomap (rmem->base, rmem->size);else -memblock_free (rmem->base, rmem->size); +memblock_phys_free (rmem->base, rmem->size); } } }
drivers/s390/char/sclp_early.c +1 -1
@@ -139,7 +139,7 @@ int __init sclp_early_get_core_info(struct sclp_core_info *info) }sclp_fill_core_info (info, sccb); out: -memblock_free_early ((unsigned long )sccb, length); +memblock_free (sccb, length);return rc; }
drivers/usb/early/xhci-dbc.c +5 -5
@@ -185,7 +185,7 @@ static void __init xdbc_free_ring(struct xdbc_ring *ring)if (!seg)return ; -memblock_free (seg->dma,PAGE_SIZE ); +memblock_phys_free (seg->dma,PAGE_SIZE ); ring->segment =NULL ; }
@@ -665,10 +665,10 @@ int __init early_xdbc_setup_hardware(void)xdbc_free_ring (&xdbc.in_ring);if (xdbc.table_dma) -memblock_free (xdbc.table_dma,PAGE_SIZE ); +memblock_phys_free (xdbc.table_dma,PAGE_SIZE );if (xdbc.out_dma) -memblock_free (xdbc.out_dma,PAGE_SIZE ); +memblock_phys_free (xdbc.out_dma,PAGE_SIZE ); xdbc.table_base =NULL ; xdbc.out_buf =NULL ;
@@ -987,8 +987,8 @@ static int __init xdbc_init(void)xdbc_free_ring (&xdbc.evt_ring);xdbc_free_ring (&xdbc.out_ring);xdbc_free_ring (&xdbc.in_ring); -memblock_free (xdbc.table_dma,PAGE_SIZE ); -memblock_free (xdbc.out_dma,PAGE_SIZE ); +memblock_phys_free (xdbc.table_dma,PAGE_SIZE ); +memblock_phys_free (xdbc.out_dma,PAGE_SIZE );writel (0 , &xdbc.xdbc_reg->control);early_iounmap (xdbc.xhci_base, xdbc.xhci_length);
drivers/xen/swiotlb-xen.c +1 -1
@@ -240,7 +240,7 @@ void __init xen_swiotlb_init_early(void)*/ rc =xen_swiotlb_fixup (start, nslabs);if (rc) { -memblock_free (__pa (start),PAGE_ALIGN (bytes)); +memblock_free (start,PAGE_ALIGN (bytes));if (nslabs >1024 && repeat--) {/* Min is 2MB */ nslabs =max (1024UL ,ALIGN (nslabs >>1 ,IO_TLB_SEGSIZE ));
include/linux/memblock.h +2 -14
@@ -103,7 +103,7 @@ void memblock_allow_resize(void);int memblock_add_node (phys_addr_t base,phys_addr_t size,int nid);int memblock_add (phys_addr_t base,phys_addr_t size);int memblock_remove (phys_addr_t base,phys_addr_t size); -int memblock_free (phys_addr_t base,phys_addr_t size); +int memblock_phys_free (phys_addr_t base,phys_addr_t size);int memblock_reserve (phys_addr_t base,phys_addr_t size);#ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP int memblock_physmem_add (phys_addr_t base,phys_addr_t size);
@@ -117,8 +117,8 @@ int memblock_mark_mirror(phys_addr_t base, phys_addr_t size);int memblock_mark_nomap (phys_addr_t base,phys_addr_t size);int memblock_clear_nomap (phys_addr_t base,phys_addr_t size); +void memblock_free (void *ptr,size_t size);void memblock_free_all (void ); -void memblock_free_ptr (void *ptr,size_t size);void reset_node_managed_pages (pg_data_t *pgdat);void reset_all_zones_managed_pages (void );
@@ -441,18 +441,6 @@ static inline void *memblock_alloc_node(phys_addr_t size, MEMBLOCK_ALLOC_ACCESSIBLE, nid); } -static inline void memblock_free_early (phys_addr_t base, -phys_addr_t size) -{ -memblock_free (base, size); -} - -static inline void memblock_free_early_nid (phys_addr_t base, -phys_addr_t size,int nid) -{ -memblock_free (base, size); -} -static inline void memblock_free_late (phys_addr_t base,phys_addr_t size) {__memblock_free_late (base, size);
init/initramfs.c +1 -1
@@ -607,7 +607,7 @@ void __weak __init free_initrd_mem(unsigned long start, unsigned long end)unsigned long aligned_start =ALIGN_DOWN (start,PAGE_SIZE );unsigned long aligned_end =ALIGN (end,PAGE_SIZE ); -memblock_free (__pa (aligned_start), aligned_end - aligned_start); +memblock_free ((void *)aligned_start, aligned_end - aligned_start);#endif free_reserved_area((void *)start, (void *)end, POISON_FREE_INITMEM,
init/main.c +1 -1
@@ -924,7 +924,7 @@ static void __init print_unknown_bootoptions(void) end +=sprintf (end," %s" , *p);pr_notice ("Unknown command line parameters:%s\n" , unknown_options); -memblock_free_ptr (unknown_options, len); +memblock_free (unknown_options, len); } asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
kernel/dma/swiotlb.c +1 -1
@@ -247,7 +247,7 @@ swiotlb_init(int verbose)return ; fail_free_mem: -memblock_free_early (__pa (tlb), bytes); +memblock_free (tlb, bytes); fail:pr_warn ("Cannot allocate buffer" ); }
kernel/printk/printk.c +2 -2
@@ -1166,9 +1166,9 @@ void __init setup_log_buf(int early)return ; err_free_descs: -memblock_free_ptr (new_descs, new_descs_size); +memblock_free (new_descs, new_descs_size); err_free_log_buf: -memblock_free_ptr (new_log_buf, new_log_buf_len); +memblock_free (new_log_buf, new_log_buf_len); }static bool __read_mostly ignore_loglevel;
lib/bootconfig.c +1 -1
@@ -792,7 +792,7 @@ void __init xbc_destroy_all(void) xbc_data =NULL ; xbc_data_size =0 ; xbc_node_num =0 ; -memblock_free_ptr (xbc_nodes,sizeof (struct xbc_node ) *XBC_NODE_MAX ); +memblock_free (xbc_nodes,sizeof (struct xbc_node ) *XBC_NODE_MAX ); xbc_nodes =NULL ; brace_index =0 ; }
lib/cpumask.c +1 -1
@@ -188,7 +188,7 @@ EXPORT_SYMBOL(free_cpumask_var);*/ void __init free_bootmem_cpumask_var (cpumask_var_t mask) { -memblock_free_early (__pa (mask),cpumask_size ()); +memblock_free (mask,cpumask_size ()); }#endif
mm/cma.c +1 -1
@@ -378,7 +378,7 @@ int __init cma_declare_contiguous_nid(phys_addr_t base,return 0 ; free_mem: -memblock_free (base, size); +memblock_phys_free (base, size); err:pr_err ("Failed to reserve %ld MiB\n" , (unsigned long )size /SZ_1M );return ret;
mm/memblock.c +10 -10
@@ -472,7 +472,7 @@ static int __init_memblock memblock_double_array(struct memblock_type *type,kfree (old_array); else if (old_array != memblock_memory_init_regions && old_array != memblock_reserved_init_regions) - memblock_free_ptr(old_array, old_alloc_size); + memblock_free(old_array, old_alloc_size);/* * Reserve the new array if that comes from the memblock. Otherwise, we
@@ -796,28 +796,28 @@ int __init_memblock memblock_remove(phys_addr_t base, phys_addr_t size) }/** -* memblock_free_ptr - free boot memory allocation -* @ptr: starting address of the boot memory allocation +* memblock_free - free boot memory allocation +* @ptr: starting *virtual* address of the boot memory allocation * @size: size of the boot memory block in bytes * * Free boot memory block previously allocated by memblock_alloc_xx() API. * The freeing memory will not be released to the buddy allocator. */ -void __init_memblock memblock_free_ptr(void *ptr, size_t size) +void __init_memblock memblock_free(void *ptr, size_t size) {if (ptr) -memblock_free (__pa (ptr), size); +memblock_phys_free (__pa (ptr), size); }/** -* memblock_free - free boot memory block -* @base: phys starting address of the boot memory block +* memblock_free_phys - free boot memory block +* @base: starting *physical* address of the boot memory block * @size: size of the boot memory block in bytes * -* Free boot memory block previously allocated by memblock_alloc_xx() API. +* Free boot memory block previously allocated by memblock_phys_alloc_xx() API. * The freeing memory will not be released to the buddy allocator. */ -int __init_memblock memblock_free(phys_addr_t base, phys_addr_t size) +int __init_memblock memblock_phys_free(phys_addr_t base, phys_addr_t size) {phys_addr_t end = base + size -1 ;
@@ -1934,7 +1934,7 @@ static void __init free_memmap(unsigned long start_pfn, unsigned long end_pfn)* memmap array. */ if (pg < pgend) -memblock_free (pg, pgend - pg); +memblock_phys_free (pg, pgend - pg); }/*
mm/memory_hotplug.c +1 -1
@@ -2204,7 +2204,7 @@ static int __ref try_remove_memory(u64 start, u64 size)arch_remove_memory (start, size, altmap);if (IS_ENABLED (CONFIG_ARCH_KEEP_MEMBLOCK )) { -memblock_free (start, size); +memblock_phys_free (start, size);memblock_remove (start, size); }
mm/percpu.c +4 -4
@@ -2472,7 +2472,7 @@ struct pcpu_alloc_info * __init pcpu_alloc_alloc_info(int nr_groups,*/ void __init pcpu_free_alloc_info (struct pcpu_alloc_info *ai) { -memblock_free_early (__pa (ai), ai->__ai_size); +memblock_free (ai, ai->__ai_size); }/**
@@ -3134,7 +3134,7 @@ int __init pcpu_embed_first_chunk(size_t reserved_size, size_t dyn_size, out_free:pcpu_free_alloc_info (ai);if (areas) -memblock_free_early (__pa (areas), areas_size); +memblock_free (areas, areas_size); return rc; }#endif /* BUILD_EMBED_FIRST_CHUNK */
@@ -3256,7 +3256,7 @@ int __init pcpu_page_first_chunk(size_t reserved_size,free_fn (page_address (pages[j]),PAGE_SIZE ); rc = -ENOMEM ; out_free_ar: -memblock_free_early (__pa (pages), pages_size); +memblock_free (pages, pages_size);pcpu_free_alloc_info (ai);return rc; }
@@ -3286,7 +3286,7 @@ static void * __init pcpu_dfl_fc_alloc(unsigned int cpu, size_t size,static void __init pcpu_dfl_fc_free (void *ptr,size_t size) { -memblock_free_early (__pa (ptr), size); +memblock_free (ptr, size); }void __init setup_per_cpu_areas (void )
mm/sparse.c +1 -1
@@ -451,7 +451,7 @@ static void *sparsemap_buf_end __meminitdata;static inline void __meminit sparse_buffer_free (unsigned long size) {WARN_ON (!sparsemap_buf || size ==0 ); -memblock_free_early (__pa (sparsemap_buf), size); +memblock_free (sparsemap_buf, size); }static void __init sparse_buffer_init (unsigned long size,int nid)
tools/bootconfig/include/linux/memblock.h +1 -1
@@ -6,6 +6,6 @@#define SMP_CACHE_BYTES 0#define memblock_alloc (size, align) malloc(size) -#define memblock_free_ptr (paddr, size) free(paddr) +#define memblock_free (paddr, size) free(paddr)#endif
Signature · 1 line
2.28.0
Re: [PATCH 2/3] xen/x86: free_p2m_page: use memblock_free_ptr() to free a virtual pointer
In reply to Mike RapoportQuoted 9 lines · Mike Rapoport
From: Mike Rapoport <[email protected]>
free_p2m_page()wrongly passes a virtual pointer tomemblock_free()that treats it as a physical address.Call
memblock_free_ptr()instead that gets a virtual address to free the memory.Signed-off-by Mike Rapoport <[email protected]>
Juergen
Juergen Gross
maintainerQuoted 16 lines · Mike Rapoport
From: Mike Rapoport <[email protected]>
For ages
memblock_free()interface dealt with physical addresses even despite the existence ofmemblock_alloc_xx()functions that return a virtual pointer.Introduce
memblock_phys_free()for freeing physical ranges and repurposememblock_free()to free virtual pointers to make the following pairing abundantly clear:int memblock_phys_free(phys_addr_t base, phys_addr_t size); phys_addr_t memblock_phys_alloc(phys_addr_t base, phys_addr_t size); void *memblock_alloc(phys_addr_t size, phys_addr_t align); void memblock_free(void *ptr, size_t size);
Quoted 5 lines
Replace intermediate
memblock_free_ptr()withmemblock_free()and drop unnecessary aliasesmemblock_free_early()andmemblock_free_early_nid().Suggested-by Linus Torvalds <[email protected]>Signed-off-by Mike Rapoport <[email protected]>
arch/x86/xen/ parts: Reviewed-by: Juergen Gross <[email protected]>
Juergen
Le 23/09/2021 à 09:43, Mike Rapoport a écrit :
Quoted 37 lines
From: Mike Rapoport <[email protected]>
For ages
memblock_free()interface dealt with physical addresses even despite the existence ofmemblock_alloc_xx()functions that return a virtual pointer.Introduce
memblock_phys_free()for freeing physical ranges and repurposememblock_free()to free virtual pointers to make the following pairing abundantly clear:int memblock_phys_free(phys_addr_t base, phys_addr_t size); phys_addr_t memblock_phys_alloc(phys_addr_t base, phys_addr_t size); void *memblock_alloc(phys_addr_t size, phys_addr_t align); void memblock_free(void *ptr, size_t size);Replace intermediate
memblock_free_ptr()withmemblock_free()and drop unnecessary aliasesmemblock_free_early()andmemblock_free_early_nid().Suggested-by Linus Torvalds <[email protected]>Signed-off-by Mike Rapoport <[email protected]>---
arch/s390/kernel/smp.c +1
-1@@ -723,7 +723,7 @@ void __init smp_save_dump_cpus(void)/* Get the CPU registers */ smp_save_cpu_regs (sa, addr, is_boot_cpu, page); } -memblock_free (page,PAGE_SIZE ); +memblock_phys_free (page,PAGE_SIZE ); diag_amode31_ops.diag308_reset ();pcpu_set_smt (0 ); }
arch/s390/kernel/smp.c void __init smp_detect_cpus(void) · line 886
Quoted 8 lines
arch/s390/kernel/smp.c +1
-1@@ -880,7 +880,7 @@ void __init smp_detect_cpus(void)/* Add CPUs present at boot */ __smp_rescan_cpus (info, true); -memblock_free_early ((unsigned long )info,sizeof (*info)); +memblock_free (info,sizeof (*info)); }/*
I'm a bit lost. IIUC memblock_free_early() and memblock_free() where identical.
In the first hunk memblock_free() gets replaced by memblock_phys_free() In the second hunk memblock_free_early() gets replaced by memblock_free()
I think it would be easier to follow if you could split it in several patches:
- First patch: Create memblock_phys_free() and change all relevant memblock_free() to memblock_phys_free() - Or change memblock_free() to memblock_phys_free() and make memblock_free() an alias of it.
- Second patch: Make memblock_free_ptr() become memblock_free() and change all remaining callers to the new semantics (IIUC memblock_free(__pa(ptr)) becomes memblock_free(ptr) and make memblock_free_ptr() an alias of memblock_free()
- Fourth patch: Replace and drop memblock_free_ptr()
- Fifth patch: Drop memblock_free_early() and memblock_free_early_nid() (All users should have been upgraded to memblock_free_phys() in patch 1 or memblock_free() in patch 2)
Christophe
Quoted 41 lines · Christophe Leroy
Le 23/09/2021 à 09:43, Mike Rapoport a écrit :
Quoted 38 lines
From: Mike Rapoport <[email protected]>
For ages
memblock_free()interface dealt with physical addresses even despite the existence ofmemblock_alloc_xx()functions that return a virtual pointer.Introduce
memblock_phys_free()for freeing physical ranges and repurposememblock_free()to free virtual pointers to make the following pairing abundantly clear:int memblock_phys_free(phys_addr_t base, phys_addr_t size); phys_addr_t memblock_phys_alloc(phys_addr_t base, phys_addr_t size); void *memblock_alloc(phys_addr_t size, phys_addr_t align); void memblock_free(void *ptr, size_t size);Replace intermediate
memblock_free_ptr()withmemblock_free()and drop unnecessary aliasesmemblock_free_early()andmemblock_free_early_nid().Suggested-by Linus Torvalds <torvalds-de/[email protected]>Signed-off-by Mike Rapoport <[email protected]>---
arch/s390/kernel/smp.c +1
-1@@ -723,7 +723,7 @@ void __init smp_save_dump_cpus(void)/* Get the CPU registers */ smp_save_cpu_regs (sa, addr, is_boot_cpu, page); } -memblock_free (page,PAGE_SIZE ); +memblock_phys_free (page,PAGE_SIZE ); diag_amode31_ops.diag308_reset ();pcpu_set_smt (0 ); }@@ -880,7 +880,7 @@ void __init smp_detect_cpus(void)/* Add CPUs present at boot */
Quoted 8 lines
arch/s390/kernel/smp.c void __init smp_detect_cpus(void) · line 886
Quoted 5 lines
arch/s390/kernel/smp.c +1
-1__smp_rescan_cpus (info, true); -memblock_free_early ((unsigned long )info,sizeof (*info)); +memblock_free (info,sizeof (*info)); }/* I'm a bit lost. IIUC
memblock_free_early()andmemblock_free()where identical.
Yes, they were, but all calls to memblock_free_early() were using __pa(vaddr) because they had a virtual address at hand.
Quoted 2 lines
In the first hunk
memblock_free()gets replaced bymemblock_phys_free()In the second hunkmemblock_free_early()gets replaced bymemblock_free()
In the first hunk the memory is allocated with memblock_phys_alloc() and we have a physical range to free. In the second hunk the memory is allocated with memblock_alloc() and we are freeing a virtual pointer.
Quoted 2 lines
I think it would be easier to follow if you could split it in several patches:
It was an explicit request from Linus to make it a single commit:
but the actual commit can and should be just a single commit that just fixes 'memblock_free()' to have sane interfaces.
I don't feel strongly about splitting it (except my laziness really objects), but I don't think doing the conversion in several steps worth the churn.
Quoted 13 lines
- First patch: Create
memblock_phys_free()and change all relevantmemblock_free()tomemblock_phys_free()- Or changememblock_free()tomemblock_phys_free()and makememblock_free()an alias of it.
- Second patch: Makememblock_free_ptr()becomememblock_free()and change all remaining callers to the new semantics (IIUC memblock_free(__pa(ptr)) becomesmemblock_free(ptr)and makememblock_free_ptr()an alias ofmemblock_free()
- Fourth patch: Replace and dropmemblock_free_ptr()
- Fifth patch: Dropmemblock_free_early()andmemblock_free_early_nid()(All users should have been upgraded tomemblock_free_phys()in patch 1 ormemblock_free()in patch 2)Christophe
Signature · 2 lines
Sincerely yours, Mike.
Quoted 16 lines · Mike Rapoport
From: Mike Rapoport <[email protected]>
For ages
memblock_free()interface dealt with physical addresses even despite the existence ofmemblock_alloc_xx()functions that return a virtual pointer.Introduce
memblock_phys_free()for freeing physical ranges and repurposememblock_free()to free virtual pointers to make the following pairing abundantly clear:int memblock_phys_free(phys_addr_t base, phys_addr_t size); phys_addr_t memblock_phys_alloc(phys_addr_t base, phys_addr_t size); void *memblock_alloc(phys_addr_t size, phys_addr_t align); void memblock_free(void *ptr, size_t size);
Quoted 5 lines
Replace intermediate
memblock_free_ptr()withmemblock_free()and drop unnecessary aliasesmemblock_free_early()andmemblock_free_early_nid().Suggested-by Linus Torvalds <[email protected]>Signed-off-by Mike Rapoport <[email protected]>
arch/arc part: Reviewed-by: Shahab Vahedi <[email protected]>
Thanks,
Shahab
Le 23/09/2021 à 14:01, Mike Rapoport a écrit :
Quoted 51 lines · Christophe Leroy
Quoted 41 lines
Le 23/09/2021 à 09:43, Mike Rapoport a écrit :
Quoted 38 lines
From: Mike Rapoport <[email protected]>
For ages
memblock_free()interface dealt with physical addresses even despite the existence ofmemblock_alloc_xx()functions that return a virtual pointer.Introduce
memblock_phys_free()for freeing physical ranges and repurposememblock_free()to free virtual pointers to make the following pairing abundantly clear:int memblock_phys_free(phys_addr_t base, phys_addr_t size); phys_addr_t memblock_phys_alloc(phys_addr_t base, phys_addr_t size); void *memblock_alloc(phys_addr_t size, phys_addr_t align); void memblock_free(void *ptr, size_t size);Replace intermediate
memblock_free_ptr()withmemblock_free()and drop unnecessary aliasesmemblock_free_early()andmemblock_free_early_nid().Suggested-by Linus Torvalds <[email protected]>Signed-off-by Mike Rapoport <[email protected]>---
arch/s390/kernel/smp.c +1
-1@@ -723,7 +723,7 @@ void __init smp_save_dump_cpus(void)/* Get the CPU registers */ smp_save_cpu_regs (sa, addr, is_boot_cpu, page); } -memblock_free (page,PAGE_SIZE ); +memblock_phys_free (page,PAGE_SIZE ); diag_amode31_ops.diag308_reset ();pcpu_set_smt (0 ); }@@ -880,7 +880,7 @@ void __init smp_detect_cpus(void)/* Add CPUs present at boot */ Quoted 8 lines
arch/s390/kernel/smp.c void __init smp_detect_cpus(void) · line 886
Quoted 5 lines
arch/s390/kernel/smp.c +1
-1__smp_rescan_cpus (info, true); -memblock_free_early ((unsigned long )info,sizeof (*info)); +memblock_free (info,sizeof (*info)); }/* I'm a bit lost. IIUC
memblock_free_early()andmemblock_free()where identical.
Quoted 2 lines
Yes, they were, but all calls to
memblock_free_early()were using__pa(vaddr)because they had a virtual address at hand.
I'm still not following. In the above memblock_free_early() was taking (unsigned long)info . Was it a bug ? It looks odd to hide bug fixes in such a big patch, should that bug fix go in patch 2 ?
Quoted 11 lines
Quoted 3 lines
In the first hunk
memblock_free()gets replaced bymemblock_phys_free()In the second hunkmemblock_free_early()gets replaced bymemblock_free()In the first hunk the memory is allocated with
memblock_phys_alloc()and we have a physical range to free. In the second hunk the memory is allocated withmemblock_alloc()and we are freeing a virtual pointer.Quoted 2 lines
I think it would be easier to follow if you could split it in several patches:
Quoted 8 lines
It was an explicit request from Linus to make it a single commit:
but the actual commit can and should be just a single commit that just fixes '
memblock_free()' to have sane interfaces.I don't feel strongly about splitting it (except my laziness really objects), but I don't think doing the conversion in several steps worth the churn.
The commit is quite big (55 files changed, approx 100 lines modified).
If done in the right order the change should be minimal.
It is rather not-easy to follow and review when a function that was existing (namely memblock_free() ) disappears and re-appears in the same commit but to do something different.
You do:
- memblock_free() ==> memblock_phys_free()
- memblock_free_ptr() ==> memblock_free()
At least you could split in two patches, the advantage would be that between first and second patch memblock() doesn't exist anymore so you can check you really don't have anymore user.
Quoted 15 lines
Quoted 14 lines
- First patch: Create
memblock_phys_free()and change all relevantmemblock_free()tomemblock_phys_free()- Or changememblock_free()tomemblock_phys_free()and makememblock_free()an alias of it.
- Second patch: Makememblock_free_ptr()becomememblock_free()and change all remaining callers to the new semantics (IIUC memblock_free(__pa(ptr)) becomesmemblock_free(ptr)and makememblock_free_ptr()an alias ofmemblock_free()
- Fourth patch: Replace and dropmemblock_free_ptr()
- Fifth patch: Dropmemblock_free_early()andmemblock_free_early_nid()(All users should have been upgraded tomemblock_free_phys()in patch 1 ormemblock_free()in patch 2)Christophe
Quoted 3 lines · Mike Rapoport
The core change is in the third patch that makes
memblock_free()a counterpart ofmemblock_alloc()and addsmemblock_phys_alloc()to be a
^^^^^^^^^^^^^^^^^^^
Quoted 1 line
counterpart of
memblock_phys_alloc().
That should be 'memblock_phys_free()'
HOWEVER.
The real reason I'm replying is that this patch is horribly buggy, and will cause subtle problems that are nasty to debug.
You need to be a LOT more careful.
From a trivial check - exactly because I looked at doing it with a script, and decided it's not so easy - I found cases like this:
- memblock_free(__pa(paca_ptrs) + new_ptrs_size,
+ memblock_free(paca_ptrs + new_ptrs_size,
which is COMPLETELY wrong.
Why? Because now that addition is done as _pointer_ addition, not as an integer addition, and the end result is something completely different.
pcac_ptrs is of type 'struct paca_struct **', so when you add new_ptrs_size to it, it will add it in terms of that many pointers, not that many bytes.
You need to use some smarter scripting, or some way to validate it.
And no, making the scripting just replace '__pa(x)' with '(void *)(x)'
- which _would_ be mindless and get the same result - is not acceptable either, because it avoids one of the big improvements from using the right interface, namely having compiler type checking (and saner code that people understand).
So NAK. No broken automated scripting patches.
Linus
Hi Linus,
Quoted 11 lines · Linus Torvalds
Quoted 1 line · Mike Rapoport
You need to be a LOT more careful.
From a trivial check - exactly because I looked at doing it with a script, and decided it's not so easy - I found cases like this:
(quoted diff) +1
-1- memblock_free(__pa(paca_ptrs) + new_ptrs_size, + memblock_free(paca_ptrs + new_ptrs_size,which is COMPLETELY wrong.
I did use a coccinelle script that's slightly more robust that a sed you've sent, but then I did a manual review, hence the two small patches with fixes. Indeed I missed this one, so to be on the safe side I'll rename only the obvious cases where coccinelle can be used reliably and leave all the rest as it's now. If somebody cares enough they can update it later.
Quoted 1 line
And no, making the scripting just replace '
__pa(x)' with '(void *)(x)'
These were actually manual and they are required for variables that used as virtual addresses but have unsigned long type, like e.g. initrd_start. So it's either __pa(x) or (void *).
Signature · 2 lines
Sincerely yours, Mike.
Quoted 53 lines · Christophe Leroy
Le 23/09/2021 à 14:01, Mike Rapoport a écrit :
Quoted 51 lines · Christophe Leroy
Quoted 49 lines
Le 23/09/2021 à 09:43, Mike Rapoport a écrit :
Quoted 37 lines
From: Mike Rapoport <[email protected]>
For ages
memblock_free()interface dealt with physical addresses even despite the existence ofmemblock_alloc_xx()functions that return a virtual pointer.Introduce
memblock_phys_free()for freeing physical ranges and repurposememblock_free()to free virtual pointers to make the following pairing abundantly clear:int memblock_phys_free(phys_addr_t base, phys_addr_t size); phys_addr_t memblock_phys_alloc(phys_addr_t base, phys_addr_t size); void *memblock_alloc(phys_addr_t size, phys_addr_t align); void memblock_free(void *ptr, size_t size);Replace intermediate
memblock_free_ptr()withmemblock_free()and drop unnecessary aliasesmemblock_free_early()andmemblock_free_early_nid().Suggested-by Linus Torvalds <torvalds-de/[email protected]>Signed-off-by Mike Rapoport <[email protected]>---
arch/s390/kernel/smp.c +1
-1@@ -723,7 +723,7 @@ void __init smp_save_dump_cpus(void)/* Get the CPU registers */ smp_save_cpu_regs (sa, addr, is_boot_cpu, page); } -memblock_free (page,PAGE_SIZE ); +memblock_phys_free (page,PAGE_SIZE ); diag_amode31_ops.diag308_reset ();pcpu_set_smt (0 ); }arch/s390/kernel/smp.c void __init smp_detect_cpus(void) · line 884
Quoted 6 lines
arch/s390/kernel/smp.c +1
-1@@ -880,7 +880,7 @@ void __init smp_detect_cpus(void)/* Add CPUs present at boot */ __smp_rescan_cpus (info, true); -memblock_free_early ((unsigned long )info,sizeof (*info)); +memblock_free (info,sizeof (*info)); }/* I'm a bit lost. IIUC
memblock_free_early()andmemblock_free()where identical.
Quoted 5 lines
Quoted 2 lines
Yes, they were, but all calls to
memblock_free_early()were using__pa(vaddr)because they had a virtual address at hand.I'm still not following. In the above
memblock_free_early()was taking (unsigned long)info . Was it a bug ?
Not really because s390 has pa == va:
https://elixir.bootlin.com/linux/latest/source/arch/s390/include/asm/page.h#L169
Signature · 2 lines
Sincerely yours, Mike.