Message ID | 20221006021223.3091711-1-panqinglin2020@iscas.ac.cn (mailing list archive) |
---|---|
State | Superseded, archived |
Headers | show |
Series | [v1,1/1] riscv: mm: call best_map_size many times during linear-mapping | expand |
On Thu, Oct 06, 2022 at 10:12:23AM +0800, panqinglin2020@iscas.ac.cn wrote: > From: Qinglin Pan <panqinglin2020@iscas.ac.cn> > > Modify the best_map_size function to give map_size many times instead > of only once, so a memory region can be mapped by both PMD_SIZE and > PAGE_SIZE. > > Signed-off-by: Qinglin Pan <panqinglin2020@iscas.ac.cn> > --- > arch/riscv/mm/init.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c > index b56a0a75533f..1b76d3fe4e26 100644 > --- a/arch/riscv/mm/init.c > +++ b/arch/riscv/mm/init.c > @@ -673,10 +673,11 @@ void __init create_pgd_mapping(pgd_t *pgdp, > static uintptr_t __init best_map_size(phys_addr_t base, phys_addr_t size) > { > /* Upgrade to PMD_SIZE mappings whenever possible */ > - if ((base & (PMD_SIZE - 1)) || (size & (PMD_SIZE - 1))) > - return PAGE_SIZE; > + base &= PMD_SIZE - 1; > + if (!base && size >= PMD_SIZE) > + return PMD_SIZE; > > - return PMD_SIZE; > + return PAGE_SIZE; > } > > #ifdef CONFIG_XIP_KERNEL > @@ -1111,9 +1112,9 @@ static void __init setup_vm_final(void) > if (end >= __pa(PAGE_OFFSET) + memory_limit) > end = __pa(PAGE_OFFSET) + memory_limit; > > - map_size = best_map_size(start, end - start); > for (pa = start; pa < end; pa += map_size) { > va = (uintptr_t)__va(pa); > + map_size = best_map_size(pa, end - pa); > > create_pgd_mapping(swapper_pg_dir, va, pa, map_size, > pgprot_from_va(va)); > -- > 2.35.1 > Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Hi Palmer, ping? Thanks Qinglin On 10/6/22 8:28 PM, Andrew Jones wrote: > On Thu, Oct 06, 2022 at 10:12:23AM +0800, panqinglin2020@iscas.ac.cn wrote: >> From: Qinglin Pan <panqinglin2020@iscas.ac.cn> >> >> Modify the best_map_size function to give map_size many times instead >> of only once, so a memory region can be mapped by both PMD_SIZE and >> PAGE_SIZE. >> >> Signed-off-by: Qinglin Pan <panqinglin2020@iscas.ac.cn> >> --- >> arch/riscv/mm/init.c | 9 +++++---- >> 1 file changed, 5 insertions(+), 4 deletions(-) >> >> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c >> index b56a0a75533f..1b76d3fe4e26 100644 >> --- a/arch/riscv/mm/init.c >> +++ b/arch/riscv/mm/init.c >> @@ -673,10 +673,11 @@ void __init create_pgd_mapping(pgd_t *pgdp, >> static uintptr_t __init best_map_size(phys_addr_t base, phys_addr_t size) >> { >> /* Upgrade to PMD_SIZE mappings whenever possible */ >> - if ((base & (PMD_SIZE - 1)) || (size & (PMD_SIZE - 1))) >> - return PAGE_SIZE; >> + base &= PMD_SIZE - 1; >> + if (!base && size >= PMD_SIZE) >> + return PMD_SIZE; >> >> - return PMD_SIZE; >> + return PAGE_SIZE; >> } >> >> #ifdef CONFIG_XIP_KERNEL >> @@ -1111,9 +1112,9 @@ static void __init setup_vm_final(void) >> if (end >= __pa(PAGE_OFFSET) + memory_limit) >> end = __pa(PAGE_OFFSET) + memory_limit; >> >> - map_size = best_map_size(start, end - start); >> for (pa = start; pa < end; pa += map_size) { >> va = (uintptr_t)__va(pa); >> + map_size = best_map_size(pa, end - pa); >> >> create_pgd_mapping(swapper_pg_dir, va, pa, map_size, >> pgprot_from_va(va)); >> -- >> 2.35.1 >> > > Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Hi Qinglin, On 06/10/2022 04:12, panqinglin2020@iscas.ac.cn wrote: > From: Qinglin Pan <panqinglin2020@iscas.ac.cn> > > Modify the best_map_size function to give map_size many times instead > of only once, so a memory region can be mapped by both PMD_SIZE and > PAGE_SIZE. > > Signed-off-by: Qinglin Pan <panqinglin2020@iscas.ac.cn> > --- > arch/riscv/mm/init.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c > index b56a0a75533f..1b76d3fe4e26 100644 > --- a/arch/riscv/mm/init.c > +++ b/arch/riscv/mm/init.c > @@ -673,10 +673,11 @@ void __init create_pgd_mapping(pgd_t *pgdp, > static uintptr_t __init best_map_size(phys_addr_t base, phys_addr_t size) > { > /* Upgrade to PMD_SIZE mappings whenever possible */ > - if ((base & (PMD_SIZE - 1)) || (size & (PMD_SIZE - 1))) > - return PAGE_SIZE; > + base &= PMD_SIZE - 1; > + if (!base && size >= PMD_SIZE) > + return PMD_SIZE; > > - return PMD_SIZE; > + return PAGE_SIZE; > } > > #ifdef CONFIG_XIP_KERNEL > @@ -1111,9 +1112,9 @@ static void __init setup_vm_final(void) > if (end >= __pa(PAGE_OFFSET) + memory_limit) > end = __pa(PAGE_OFFSET) + memory_limit; > > - map_size = best_map_size(start, end - start); > for (pa = start; pa < end; pa += map_size) { > va = (uintptr_t)__va(pa); > + map_size = best_map_size(pa, end - pa); > > create_pgd_mapping(swapper_pg_dir, va, pa, map_size, > pgprot_from_va(va)); It works fine for me, so you can add: Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com> Tested-by: Alexandre Ghiti <alexghiti@rivosinc.com> FYI, I'm working right now on using hugepages of 1GB for the linear mapping. Thanks, Alex
Hi Alex, On 11/15/22 11:38 PM, Alexandre Ghiti wrote: > Hi Qinglin, > > On 06/10/2022 04:12, panqinglin2020@iscas.ac.cn wrote: >> From: Qinglin Pan <panqinglin2020@iscas.ac.cn> >> >> Modify the best_map_size function to give map_size many times instead >> of only once, so a memory region can be mapped by both PMD_SIZE and >> PAGE_SIZE. >> >> Signed-off-by: Qinglin Pan <panqinglin2020@iscas.ac.cn> >> --- >> arch/riscv/mm/init.c | 9 +++++---- >> 1 file changed, 5 insertions(+), 4 deletions(-) >> >> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c >> index b56a0a75533f..1b76d3fe4e26 100644 >> --- a/arch/riscv/mm/init.c >> +++ b/arch/riscv/mm/init.c >> @@ -673,10 +673,11 @@ void __init create_pgd_mapping(pgd_t *pgdp, >> static uintptr_t __init best_map_size(phys_addr_t base, phys_addr_t >> size) >> { >> /* Upgrade to PMD_SIZE mappings whenever possible */ >> - if ((base & (PMD_SIZE - 1)) || (size & (PMD_SIZE - 1))) >> - return PAGE_SIZE; >> + base &= PMD_SIZE - 1; >> + if (!base && size >= PMD_SIZE) >> + return PMD_SIZE; >> - return PMD_SIZE; >> + return PAGE_SIZE; >> } >> #ifdef CONFIG_XIP_KERNEL >> @@ -1111,9 +1112,9 @@ static void __init setup_vm_final(void) >> if (end >= __pa(PAGE_OFFSET) + memory_limit) >> end = __pa(PAGE_OFFSET) + memory_limit; >> - map_size = best_map_size(start, end - start); >> for (pa = start; pa < end; pa += map_size) { >> va = (uintptr_t)__va(pa); >> + map_size = best_map_size(pa, end - pa); >> create_pgd_mapping(swapper_pg_dir, va, pa, map_size, >> pgprot_from_va(va)); > > > It works fine for me, so you can add: > > Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com> > Tested-by: Alexandre Ghiti <alexghiti@rivosinc.com> > > FYI, I'm working right now on using hugepages of 1GB for the linear > mapping. > > Thanks, > > Alex Got it. Thanks a lot for your revew and test. Thanks, Qinglin
Hi Palmer, Is there anything I need to change about this patch? :) Thanks, Qinglin On 10/6/22 8:28 PM, Andrew Jones wrote: > On Thu, Oct 06, 2022 at 10:12:23AM +0800, panqinglin2020@iscas.ac.cn wrote: >> From: Qinglin Pan <panqinglin2020@iscas.ac.cn> >> >> Modify the best_map_size function to give map_size many times instead >> of only once, so a memory region can be mapped by both PMD_SIZE and >> PAGE_SIZE. >> >> Signed-off-by: Qinglin Pan <panqinglin2020@iscas.ac.cn> >> --- >> arch/riscv/mm/init.c | 9 +++++---- >> 1 file changed, 5 insertions(+), 4 deletions(-) >> >> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c >> index b56a0a75533f..1b76d3fe4e26 100644 >> --- a/arch/riscv/mm/init.c >> +++ b/arch/riscv/mm/init.c >> @@ -673,10 +673,11 @@ void __init create_pgd_mapping(pgd_t *pgdp, >> static uintptr_t __init best_map_size(phys_addr_t base, phys_addr_t size) >> { >> /* Upgrade to PMD_SIZE mappings whenever possible */ >> - if ((base & (PMD_SIZE - 1)) || (size & (PMD_SIZE - 1))) >> - return PAGE_SIZE; >> + base &= PMD_SIZE - 1; >> + if (!base && size >= PMD_SIZE) >> + return PMD_SIZE; >> >> - return PMD_SIZE; >> + return PAGE_SIZE; >> } >> >> #ifdef CONFIG_XIP_KERNEL >> @@ -1111,9 +1112,9 @@ static void __init setup_vm_final(void) >> if (end >= __pa(PAGE_OFFSET) + memory_limit) >> end = __pa(PAGE_OFFSET) + memory_limit; >> >> - map_size = best_map_size(start, end - start); >> for (pa = start; pa < end; pa += map_size) { >> va = (uintptr_t)__va(pa); >> + map_size = best_map_size(pa, end - pa); >> >> create_pgd_mapping(swapper_pg_dir, va, pa, map_size, >> pgprot_from_va(va)); >> -- >> 2.35.1 >> > > Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index b56a0a75533f..1b76d3fe4e26 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -673,10 +673,11 @@ void __init create_pgd_mapping(pgd_t *pgdp, static uintptr_t __init best_map_size(phys_addr_t base, phys_addr_t size) { /* Upgrade to PMD_SIZE mappings whenever possible */ - if ((base & (PMD_SIZE - 1)) || (size & (PMD_SIZE - 1))) - return PAGE_SIZE; + base &= PMD_SIZE - 1; + if (!base && size >= PMD_SIZE) + return PMD_SIZE; - return PMD_SIZE; + return PAGE_SIZE; } #ifdef CONFIG_XIP_KERNEL @@ -1111,9 +1112,9 @@ static void __init setup_vm_final(void) if (end >= __pa(PAGE_OFFSET) + memory_limit) end = __pa(PAGE_OFFSET) + memory_limit; - map_size = best_map_size(start, end - start); for (pa = start; pa < end; pa += map_size) { va = (uintptr_t)__va(pa); + map_size = best_map_size(pa, end - pa); create_pgd_mapping(swapper_pg_dir, va, pa, map_size, pgprot_from_va(va));