Re: [PATCH v4 1/6] powerpc: prefer memblock APIs returning virtual address
Hi, On Tue, Jan 08, 2019 at 11:02:24AM +0100, Christophe Leroy wrote: > > Le 31/12/2018 à 10:29, Mike Rapoport a écrit : > >There are a several places that allocate memory using memblock APIs that > >return a physical address, convert the returned address to the virtual > >address and frequently also memset(0) the allocated range. > > > >Update these places to use memblock allocators already returning a virtual > >address. Use memblock functions that clear the allocated memory instead of > >calling memset(0) where appropriate. > > > >The calls to memblock_alloc_base() that were not followed by memset(0) are > >replaced with memblock_alloc_try_nid_raw(). Since the latter does not > >panic() when the allocation fails, the appropriate panic() calls are added > >to the call sites. > > > >Signed-off-by: Mike Rapoport > >--- > > arch/powerpc/kernel/paca.c | 16 ++-- > > arch/powerpc/kernel/setup_64.c | 24 ++-- > > arch/powerpc/mm/hash_utils_64.c| 6 +++--- > > arch/powerpc/mm/pgtable-book3e.c | 8 ++-- > > arch/powerpc/mm/pgtable-book3s64.c | 5 + > > arch/powerpc/mm/pgtable-radix.c| 25 +++-- > > arch/powerpc/platforms/pasemi/iommu.c | 5 +++-- > > arch/powerpc/platforms/pseries/setup.c | 18 ++ > > arch/powerpc/sysdev/dart_iommu.c | 7 +-- > > 9 files changed, 51 insertions(+), 63 deletions(-) > > > >diff --git a/arch/powerpc/kernel/paca.c b/arch/powerpc/kernel/paca.c > >index 913bfca..276d36d4 100644 > >--- a/arch/powerpc/kernel/paca.c > >+++ b/arch/powerpc/kernel/paca.c > >@@ -27,7 +27,7 @@ > > static void *__init alloc_paca_data(unsigned long size, unsigned long > > align, > > unsigned long limit, int cpu) > > { > >-unsigned long pa; > >+void *ptr; > > int nid; > > /* > >@@ -42,17 +42,15 @@ static void *__init alloc_paca_data(unsigned long size, > >unsigned long align, > > nid = early_cpu_to_node(cpu); > > } > >-pa = memblock_alloc_base_nid(size, align, limit, nid, MEMBLOCK_NONE); > >-if (!pa) { > >-pa = memblock_alloc_base(size, align, limit); > >-if (!pa) > >-panic("cannot allocate paca data"); > >-} > >+ptr = memblock_alloc_try_nid(size, align, MEMBLOCK_LOW_LIMIT, > >+ limit, nid); > >+if (!ptr) > >+panic("cannot allocate paca data"); > > AFAIKS, memblock_alloc_try_nid() panics if memblock_alloc_internal() returns > NULL, so the above panic is useless, isn't it ? My plan is to make all memblock_alloc() APIs to return NULL rather then panic and then get rid of _nopanic variants. It's currently WIP and hopefully I'll have the patches ready next week. > > if (cpu == boot_cpuid) > > memblock_set_bottom_up(false); > >-return __va(pa); > >+return ptr; > > } > > #ifdef CONFIG_PPC_PSERIES > >@@ -118,7 +116,6 @@ static struct slb_shadow * __init new_slb_shadow(int > >cpu, unsigned long limit) > > } > > s = alloc_paca_data(sizeof(*s), L1_CACHE_BYTES, limit, cpu); > >-memset(s, 0, sizeof(*s)); > > s->persistent = cpu_to_be32(SLB_NUM_BOLTED); > > s->buffer_length = cpu_to_be32(sizeof(*s)); > >@@ -222,7 +219,6 @@ void __init allocate_paca(int cpu) > > paca = alloc_paca_data(sizeof(struct paca_struct), L1_CACHE_BYTES, > > limit, cpu); > > paca_ptrs[cpu] = paca; > >-memset(paca, 0, sizeof(struct paca_struct)); > > initialise_paca(paca, cpu); > > #ifdef CONFIG_PPC_PSERIES > >diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c > >index 236c115..3dcd779 100644 > >--- a/arch/powerpc/kernel/setup_64.c > >+++ b/arch/powerpc/kernel/setup_64.c > >@@ -634,19 +634,17 @@ __init u64 ppc64_bolted_size(void) > > static void *__init alloc_stack(unsigned long limit, int cpu) > > { > >-unsigned long pa; > >+void *ptr; > > BUILD_BUG_ON(STACK_INT_FRAME_SIZE % 16); > >-pa = memblock_alloc_base_nid(THREAD_SIZE, THREAD_SIZE, limit, > >-early_cpu_to_node(cpu), MEMBLOCK_NONE); > >-if (!pa) { > >-pa = memblock_alloc_base(THREAD_SIZE, THREAD_SIZE, limit); > >-if (!pa) > >-panic("cannot allocate stacks"); > >-} > >+ptr = memblock_alloc_try_nid(THREAD_SIZE, THREAD_SIZE, > >+ MEMBLOCK_LOW_LIMIT, limit, > >+ early_cpu_to_node(cpu)); > >+if (!ptr) > >+panic("cannot allocate stacks"); > > Same ? > > Christophe > > >-return __va(pa); > >+return ptr; > > } > > void __init irqstack_early_init(void) > >@@ -739,20 +737,17 @@ void __init emergency_stack_init(void) > > struct thread_info *ti; > > ti = alloc_stack(limit, i); > >-memset(ti, 0, THREAD_SIZE); > >
Re: [PATCH v4 1/6] powerpc: prefer memblock APIs returning virtual address
Le 31/12/2018 à 10:29, Mike Rapoport a écrit : There are a several places that allocate memory using memblock APIs that return a physical address, convert the returned address to the virtual address and frequently also memset(0) the allocated range. Update these places to use memblock allocators already returning a virtual address. Use memblock functions that clear the allocated memory instead of calling memset(0) where appropriate. The calls to memblock_alloc_base() that were not followed by memset(0) are replaced with memblock_alloc_try_nid_raw(). Since the latter does not panic() when the allocation fails, the appropriate panic() calls are added to the call sites. Signed-off-by: Mike Rapoport --- arch/powerpc/kernel/paca.c | 16 ++-- arch/powerpc/kernel/setup_64.c | 24 ++-- arch/powerpc/mm/hash_utils_64.c| 6 +++--- arch/powerpc/mm/pgtable-book3e.c | 8 ++-- arch/powerpc/mm/pgtable-book3s64.c | 5 + arch/powerpc/mm/pgtable-radix.c| 25 +++-- arch/powerpc/platforms/pasemi/iommu.c | 5 +++-- arch/powerpc/platforms/pseries/setup.c | 18 ++ arch/powerpc/sysdev/dart_iommu.c | 7 +-- 9 files changed, 51 insertions(+), 63 deletions(-) diff --git a/arch/powerpc/kernel/paca.c b/arch/powerpc/kernel/paca.c index 913bfca..276d36d4 100644 --- a/arch/powerpc/kernel/paca.c +++ b/arch/powerpc/kernel/paca.c @@ -27,7 +27,7 @@ static void *__init alloc_paca_data(unsigned long size, unsigned long align, unsigned long limit, int cpu) { - unsigned long pa; + void *ptr; int nid; /* @@ -42,17 +42,15 @@ static void *__init alloc_paca_data(unsigned long size, unsigned long align, nid = early_cpu_to_node(cpu); } - pa = memblock_alloc_base_nid(size, align, limit, nid, MEMBLOCK_NONE); - if (!pa) { - pa = memblock_alloc_base(size, align, limit); - if (!pa) - panic("cannot allocate paca data"); - } + ptr = memblock_alloc_try_nid(size, align, MEMBLOCK_LOW_LIMIT, +limit, nid); + if (!ptr) + panic("cannot allocate paca data"); AFAIKS, memblock_alloc_try_nid() panics if memblock_alloc_internal() returns NULL, so the above panic is useless, isn't it ? if (cpu == boot_cpuid) memblock_set_bottom_up(false); - return __va(pa); + return ptr; } #ifdef CONFIG_PPC_PSERIES @@ -118,7 +116,6 @@ static struct slb_shadow * __init new_slb_shadow(int cpu, unsigned long limit) } s = alloc_paca_data(sizeof(*s), L1_CACHE_BYTES, limit, cpu); - memset(s, 0, sizeof(*s)); s->persistent = cpu_to_be32(SLB_NUM_BOLTED); s->buffer_length = cpu_to_be32(sizeof(*s)); @@ -222,7 +219,6 @@ void __init allocate_paca(int cpu) paca = alloc_paca_data(sizeof(struct paca_struct), L1_CACHE_BYTES, limit, cpu); paca_ptrs[cpu] = paca; - memset(paca, 0, sizeof(struct paca_struct)); initialise_paca(paca, cpu); #ifdef CONFIG_PPC_PSERIES diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c index 236c115..3dcd779 100644 --- a/arch/powerpc/kernel/setup_64.c +++ b/arch/powerpc/kernel/setup_64.c @@ -634,19 +634,17 @@ __init u64 ppc64_bolted_size(void) static void *__init alloc_stack(unsigned long limit, int cpu) { - unsigned long pa; + void *ptr; BUILD_BUG_ON(STACK_INT_FRAME_SIZE % 16); - pa = memblock_alloc_base_nid(THREAD_SIZE, THREAD_SIZE, limit, - early_cpu_to_node(cpu), MEMBLOCK_NONE); - if (!pa) { - pa = memblock_alloc_base(THREAD_SIZE, THREAD_SIZE, limit); - if (!pa) - panic("cannot allocate stacks"); - } + ptr = memblock_alloc_try_nid(THREAD_SIZE, THREAD_SIZE, +MEMBLOCK_LOW_LIMIT, limit, +early_cpu_to_node(cpu)); + if (!ptr) + panic("cannot allocate stacks"); Same ? Christophe - return __va(pa); + return ptr; } void __init irqstack_early_init(void) @@ -739,20 +737,17 @@ void __init emergency_stack_init(void) struct thread_info *ti; ti = alloc_stack(limit, i); - memset(ti, 0, THREAD_SIZE); emerg_stack_init_thread_info(ti, i); paca_ptrs[i]->emergency_sp = (void *)ti + THREAD_SIZE; #ifdef CONFIG_PPC_BOOK3S_64 /* emergency stack for NMI exception handling. */ ti = alloc_stack(limit, i); - memset(ti, 0, THREAD_SIZE); emerg_stack_init_thread_info(ti, i); paca_ptrs[i]->nmi_emergency_sp = (void *)ti + THREAD_SIZE; /* emergency stack for machine
[PATCH v4 1/6] powerpc: prefer memblock APIs returning virtual address
There are a several places that allocate memory using memblock APIs that return a physical address, convert the returned address to the virtual address and frequently also memset(0) the allocated range. Update these places to use memblock allocators already returning a virtual address. Use memblock functions that clear the allocated memory instead of calling memset(0) where appropriate. The calls to memblock_alloc_base() that were not followed by memset(0) are replaced with memblock_alloc_try_nid_raw(). Since the latter does not panic() when the allocation fails, the appropriate panic() calls are added to the call sites. Signed-off-by: Mike Rapoport --- arch/powerpc/kernel/paca.c | 16 ++-- arch/powerpc/kernel/setup_64.c | 24 ++-- arch/powerpc/mm/hash_utils_64.c| 6 +++--- arch/powerpc/mm/pgtable-book3e.c | 8 ++-- arch/powerpc/mm/pgtable-book3s64.c | 5 + arch/powerpc/mm/pgtable-radix.c| 25 +++-- arch/powerpc/platforms/pasemi/iommu.c | 5 +++-- arch/powerpc/platforms/pseries/setup.c | 18 ++ arch/powerpc/sysdev/dart_iommu.c | 7 +-- 9 files changed, 51 insertions(+), 63 deletions(-) diff --git a/arch/powerpc/kernel/paca.c b/arch/powerpc/kernel/paca.c index 913bfca..276d36d4 100644 --- a/arch/powerpc/kernel/paca.c +++ b/arch/powerpc/kernel/paca.c @@ -27,7 +27,7 @@ static void *__init alloc_paca_data(unsigned long size, unsigned long align, unsigned long limit, int cpu) { - unsigned long pa; + void *ptr; int nid; /* @@ -42,17 +42,15 @@ static void *__init alloc_paca_data(unsigned long size, unsigned long align, nid = early_cpu_to_node(cpu); } - pa = memblock_alloc_base_nid(size, align, limit, nid, MEMBLOCK_NONE); - if (!pa) { - pa = memblock_alloc_base(size, align, limit); - if (!pa) - panic("cannot allocate paca data"); - } + ptr = memblock_alloc_try_nid(size, align, MEMBLOCK_LOW_LIMIT, +limit, nid); + if (!ptr) + panic("cannot allocate paca data"); if (cpu == boot_cpuid) memblock_set_bottom_up(false); - return __va(pa); + return ptr; } #ifdef CONFIG_PPC_PSERIES @@ -118,7 +116,6 @@ static struct slb_shadow * __init new_slb_shadow(int cpu, unsigned long limit) } s = alloc_paca_data(sizeof(*s), L1_CACHE_BYTES, limit, cpu); - memset(s, 0, sizeof(*s)); s->persistent = cpu_to_be32(SLB_NUM_BOLTED); s->buffer_length = cpu_to_be32(sizeof(*s)); @@ -222,7 +219,6 @@ void __init allocate_paca(int cpu) paca = alloc_paca_data(sizeof(struct paca_struct), L1_CACHE_BYTES, limit, cpu); paca_ptrs[cpu] = paca; - memset(paca, 0, sizeof(struct paca_struct)); initialise_paca(paca, cpu); #ifdef CONFIG_PPC_PSERIES diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c index 236c115..3dcd779 100644 --- a/arch/powerpc/kernel/setup_64.c +++ b/arch/powerpc/kernel/setup_64.c @@ -634,19 +634,17 @@ __init u64 ppc64_bolted_size(void) static void *__init alloc_stack(unsigned long limit, int cpu) { - unsigned long pa; + void *ptr; BUILD_BUG_ON(STACK_INT_FRAME_SIZE % 16); - pa = memblock_alloc_base_nid(THREAD_SIZE, THREAD_SIZE, limit, - early_cpu_to_node(cpu), MEMBLOCK_NONE); - if (!pa) { - pa = memblock_alloc_base(THREAD_SIZE, THREAD_SIZE, limit); - if (!pa) - panic("cannot allocate stacks"); - } + ptr = memblock_alloc_try_nid(THREAD_SIZE, THREAD_SIZE, +MEMBLOCK_LOW_LIMIT, limit, +early_cpu_to_node(cpu)); + if (!ptr) + panic("cannot allocate stacks"); - return __va(pa); + return ptr; } void __init irqstack_early_init(void) @@ -739,20 +737,17 @@ void __init emergency_stack_init(void) struct thread_info *ti; ti = alloc_stack(limit, i); - memset(ti, 0, THREAD_SIZE); emerg_stack_init_thread_info(ti, i); paca_ptrs[i]->emergency_sp = (void *)ti + THREAD_SIZE; #ifdef CONFIG_PPC_BOOK3S_64 /* emergency stack for NMI exception handling. */ ti = alloc_stack(limit, i); - memset(ti, 0, THREAD_SIZE); emerg_stack_init_thread_info(ti, i); paca_ptrs[i]->nmi_emergency_sp = (void *)ti + THREAD_SIZE; /* emergency stack for machine check exception handling. */ ti = alloc_stack(limit, i); - memset(ti, 0, THREAD_SIZE); emerg_stack_init_thread_info(ti, i);