All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jisheng Zhang <jszhang@kernel.org>
To: Alexandre ghiti <alex@ghiti.fr>
Cc: Paul Walmsley <paul.walmsley@sifive.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/5] riscv: mm: init: try best to IS_ENABLED(CONFIG_64BIT) instead of #ifdef
Date: Tue, 7 Dec 2021 00:10:30 +0800	[thread overview]
Message-ID: <20211206161748.0C772C341C1@smtp.kernel.org> (raw)
In-Reply-To: <3344a7ae-aaa6-2f35-09fc-60039bb8184d@ghiti.fr>

On Fri, 3 Dec 2021 09:33:12 +0100
Alexandre ghiti <alex@ghiti.fr> wrote:

> On 12/3/21 06:03, Jisheng Zhang wrote:
> > Try our best to replace the conditional compilation using
> > "#ifdef CONFIG_64BIT" by a check for "IS_ENABLED(CONFIG_64BIT)", to
> > simplify the code and to increase compile coverage.
> >
> > Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
> > ---
> >   arch/riscv/mm/init.c | 38 +++++++++++++++++---------------------
> >   1 file changed, 17 insertions(+), 21 deletions(-)
> >
> > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> > index 745f26a3b02e..bd445ac778a8 100644
> > --- a/arch/riscv/mm/init.c
> > +++ b/arch/riscv/mm/init.c
> > @@ -102,10 +102,9 @@ static void __init print_vm_layout(void)
> >   		  (unsigned long)VMALLOC_END);
> >   	print_mlm("lowmem", (unsigned long)PAGE_OFFSET,
> >   		  (unsigned long)high_memory);
> > -#ifdef CONFIG_64BIT
> > -	print_mlm("kernel", (unsigned long)KERNEL_LINK_ADDR,
> > -		  (unsigned long)ADDRESS_SPACE_END);
> > -#endif
> > +	if (IS_ENABLED(CONFIG_64BIT))
> > +		print_mlm("kernel", (unsigned long)KERNEL_LINK_ADDR,
> > +			  (unsigned long)ADDRESS_SPACE_END);
> >   }
> >   #else
> >   static void print_vm_layout(void) { }
> > @@ -172,17 +171,16 @@ static void __init setup_bootmem(void)
> >   
> >   	memblock_enforce_memory_limit(memory_limit);
> >   
> > -	/*
> > -	 * Reserve from the start of the kernel to the end of the kernel
> > -	 */
> > -#if defined(CONFIG_64BIT) && defined(CONFIG_STRICT_KERNEL_RWX)
> >   	/*
> >   	 * Make sure we align the reservation on PMD_SIZE since we will
> >   	 * map the kernel in the linear mapping as read-only: we do not want
> >   	 * any allocation to happen between _end and the next pmd aligned page.
> >   	 */
> > -	vmlinux_end = (vmlinux_end + PMD_SIZE - 1) & PMD_MASK;
> > -#endif
> > +	if (IS_ENABLED(CONFIG_64BIT) && IS_ENABLED(CONFIG_STRICT_KERNEL_RWX))
> > +		vmlinux_end = (vmlinux_end + PMD_SIZE - 1) & PMD_MASK;
> > +	/*
> > +	 * Reserve from the start of the kernel to the end of the kernel
> > +	 */
> >   	memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start);
> >   
> >   
> > @@ -190,7 +188,6 @@ static void __init setup_bootmem(void)
> >   #ifndef CONFIG_XIP_KERNEL
> >   	phys_ram_base = memblock_start_of_DRAM();
> >   #endif
> > -#ifndef CONFIG_64BIT
> >   	/*
> >   	 * memblock allocator is not aware of the fact that last 4K bytes of
> >   	 * the addressable memory can not be mapped because of IS_ERR_VALUE
> > @@ -200,10 +197,11 @@ static void __init setup_bootmem(void)
> >   	 * address space is occupied by the kernel mapping then this check must
> >   	 * be done as soon as the kernel mapping base address is determined.
> >   	 */
> > -	max_mapped_addr = __pa(~(ulong)0);
> > -	if (max_mapped_addr == (phys_ram_end - 1))
> > -		memblock_set_current_limit(max_mapped_addr - 4096);
> > -#endif
> > +	if (!IS_ENABLED(CONFIG_64BIT)) {
> > +		max_mapped_addr = __pa(~(ulong)0);
> > +		if (max_mapped_addr == (phys_ram_end - 1))
> > +			memblock_set_current_limit(max_mapped_addr - 4096);
> > +	}
> >   
> >   	min_low_pfn = PFN_UP(phys_ram_base);
> >   	max_low_pfn = max_pfn = PFN_DOWN(phys_ram_end);
> > @@ -616,13 +614,12 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
> >   	BUG_ON((PAGE_OFFSET % PGDIR_SIZE) != 0);
> >   	BUG_ON((kernel_map.phys_addr % PMD_SIZE) != 0);
> >   
> > -#ifdef CONFIG_64BIT
> >   	/*
> >   	 * The last 4K bytes of the addressable memory can not be mapped because
> >   	 * of IS_ERR_VALUE macro.
> >   	 */
> > -	BUG_ON((kernel_map.virt_addr + kernel_map.size) > ADDRESS_SPACE_END - SZ_4K);
> > -#endif
> > +	if (IS_ENABLED(CONFIG_64BIT))
> > +		BUG_ON((kernel_map.virt_addr + kernel_map.size) > ADDRESS_SPACE_END - SZ_4K);  
> 
> 
> For this one, I think we can just get rid of the condition since this is 
> true for every kernel actually.

Thanks for pointing out this out. Addressed in v2

> 
> 
> >   
> >   	pt_ops.alloc_pte = alloc_pte_early;
> >   	pt_ops.get_pte_virt = get_pte_virt_early;
> > @@ -735,10 +732,9 @@ static void __init setup_vm_final(void)
> >   		}
> >   	}
> >   
> > -#ifdef CONFIG_64BIT
> >   	/* Map the kernel */
> > -	create_kernel_page_table(swapper_pg_dir, false);
> > -#endif
> > +	if (IS_ENABLED(CONFIG_64BIT))
> > +		create_kernel_page_table(swapper_pg_dir, false);  
> 
> 
> Wouldn't it be better to introduce a create_kernel_page_table function 
> that does nothing for !CONFIG_64BIT?
> 

If so, we will have something as:
#ifdef CONFIG_64BIT
create_kernel_page_table()
{
...
}
#else
create_kernel_page_table() { }
#endif

Since we already have different create_kernel_page_table() version for
XIP and !XIP, the code would be more complex.

Thanks for your code review

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

WARNING: multiple messages have this Message-ID (diff)
From: Jisheng Zhang <jszhang@kernel.org>
To: Alexandre ghiti <alex@ghiti.fr>
Cc: Paul Walmsley <paul.walmsley@sifive.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/5] riscv: mm: init: try best to IS_ENABLED(CONFIG_64BIT) instead of #ifdef
Date: Tue, 7 Dec 2021 00:10:30 +0800	[thread overview]
Message-ID: <20211206161748.0C772C341C1@smtp.kernel.org> (raw)
In-Reply-To: <3344a7ae-aaa6-2f35-09fc-60039bb8184d@ghiti.fr>

On Fri, 3 Dec 2021 09:33:12 +0100
Alexandre ghiti <alex@ghiti.fr> wrote:

> On 12/3/21 06:03, Jisheng Zhang wrote:
> > Try our best to replace the conditional compilation using
> > "#ifdef CONFIG_64BIT" by a check for "IS_ENABLED(CONFIG_64BIT)", to
> > simplify the code and to increase compile coverage.
> >
> > Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
> > ---
> >   arch/riscv/mm/init.c | 38 +++++++++++++++++---------------------
> >   1 file changed, 17 insertions(+), 21 deletions(-)
> >
> > diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> > index 745f26a3b02e..bd445ac778a8 100644
> > --- a/arch/riscv/mm/init.c
> > +++ b/arch/riscv/mm/init.c
> > @@ -102,10 +102,9 @@ static void __init print_vm_layout(void)
> >   		  (unsigned long)VMALLOC_END);
> >   	print_mlm("lowmem", (unsigned long)PAGE_OFFSET,
> >   		  (unsigned long)high_memory);
> > -#ifdef CONFIG_64BIT
> > -	print_mlm("kernel", (unsigned long)KERNEL_LINK_ADDR,
> > -		  (unsigned long)ADDRESS_SPACE_END);
> > -#endif
> > +	if (IS_ENABLED(CONFIG_64BIT))
> > +		print_mlm("kernel", (unsigned long)KERNEL_LINK_ADDR,
> > +			  (unsigned long)ADDRESS_SPACE_END);
> >   }
> >   #else
> >   static void print_vm_layout(void) { }
> > @@ -172,17 +171,16 @@ static void __init setup_bootmem(void)
> >   
> >   	memblock_enforce_memory_limit(memory_limit);
> >   
> > -	/*
> > -	 * Reserve from the start of the kernel to the end of the kernel
> > -	 */
> > -#if defined(CONFIG_64BIT) && defined(CONFIG_STRICT_KERNEL_RWX)
> >   	/*
> >   	 * Make sure we align the reservation on PMD_SIZE since we will
> >   	 * map the kernel in the linear mapping as read-only: we do not want
> >   	 * any allocation to happen between _end and the next pmd aligned page.
> >   	 */
> > -	vmlinux_end = (vmlinux_end + PMD_SIZE - 1) & PMD_MASK;
> > -#endif
> > +	if (IS_ENABLED(CONFIG_64BIT) && IS_ENABLED(CONFIG_STRICT_KERNEL_RWX))
> > +		vmlinux_end = (vmlinux_end + PMD_SIZE - 1) & PMD_MASK;
> > +	/*
> > +	 * Reserve from the start of the kernel to the end of the kernel
> > +	 */
> >   	memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start);
> >   
> >   
> > @@ -190,7 +188,6 @@ static void __init setup_bootmem(void)
> >   #ifndef CONFIG_XIP_KERNEL
> >   	phys_ram_base = memblock_start_of_DRAM();
> >   #endif
> > -#ifndef CONFIG_64BIT
> >   	/*
> >   	 * memblock allocator is not aware of the fact that last 4K bytes of
> >   	 * the addressable memory can not be mapped because of IS_ERR_VALUE
> > @@ -200,10 +197,11 @@ static void __init setup_bootmem(void)
> >   	 * address space is occupied by the kernel mapping then this check must
> >   	 * be done as soon as the kernel mapping base address is determined.
> >   	 */
> > -	max_mapped_addr = __pa(~(ulong)0);
> > -	if (max_mapped_addr == (phys_ram_end - 1))
> > -		memblock_set_current_limit(max_mapped_addr - 4096);
> > -#endif
> > +	if (!IS_ENABLED(CONFIG_64BIT)) {
> > +		max_mapped_addr = __pa(~(ulong)0);
> > +		if (max_mapped_addr == (phys_ram_end - 1))
> > +			memblock_set_current_limit(max_mapped_addr - 4096);
> > +	}
> >   
> >   	min_low_pfn = PFN_UP(phys_ram_base);
> >   	max_low_pfn = max_pfn = PFN_DOWN(phys_ram_end);
> > @@ -616,13 +614,12 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
> >   	BUG_ON((PAGE_OFFSET % PGDIR_SIZE) != 0);
> >   	BUG_ON((kernel_map.phys_addr % PMD_SIZE) != 0);
> >   
> > -#ifdef CONFIG_64BIT
> >   	/*
> >   	 * The last 4K bytes of the addressable memory can not be mapped because
> >   	 * of IS_ERR_VALUE macro.
> >   	 */
> > -	BUG_ON((kernel_map.virt_addr + kernel_map.size) > ADDRESS_SPACE_END - SZ_4K);
> > -#endif
> > +	if (IS_ENABLED(CONFIG_64BIT))
> > +		BUG_ON((kernel_map.virt_addr + kernel_map.size) > ADDRESS_SPACE_END - SZ_4K);  
> 
> 
> For this one, I think we can just get rid of the condition since this is 
> true for every kernel actually.

Thanks for pointing out this out. Addressed in v2

> 
> 
> >   
> >   	pt_ops.alloc_pte = alloc_pte_early;
> >   	pt_ops.get_pte_virt = get_pte_virt_early;
> > @@ -735,10 +732,9 @@ static void __init setup_vm_final(void)
> >   		}
> >   	}
> >   
> > -#ifdef CONFIG_64BIT
> >   	/* Map the kernel */
> > -	create_kernel_page_table(swapper_pg_dir, false);
> > -#endif
> > +	if (IS_ENABLED(CONFIG_64BIT))
> > +		create_kernel_page_table(swapper_pg_dir, false);  
> 
> 
> Wouldn't it be better to introduce a create_kernel_page_table function 
> that does nothing for !CONFIG_64BIT?
> 

If so, we will have something as:
#ifdef CONFIG_64BIT
create_kernel_page_table()
{
...
}
#else
create_kernel_page_table() { }
#endif

Since we already have different create_kernel_page_table() version for
XIP and !XIP, the code would be more complex.

Thanks for your code review

  reply	other threads:[~2021-12-06 16:18 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-03  5:03 [PATCH 0/5] riscv: mm: init clean up #ifdefs Jisheng Zhang
2021-12-03  5:03 ` Jisheng Zhang
2021-12-03  5:03 ` [PATCH 1/5] riscv: mm: init: remove unnecessary "#ifdef CONFIG_CRASH_DUMP" Jisheng Zhang
2021-12-03  5:03   ` Jisheng Zhang
2021-12-03  8:15   ` Alexandre ghiti
2021-12-03  8:15     ` Alexandre ghiti
2021-12-03  5:03 ` [PATCH 2/5] riscv: mm: init: try best to IS_ENABLED(CONFIG_64BIT) instead of #ifdef Jisheng Zhang
2021-12-03  5:03   ` Jisheng Zhang
2021-12-03  8:33   ` Alexandre ghiti
2021-12-03  8:33     ` Alexandre ghiti
2021-12-06 16:10     ` Jisheng Zhang [this message]
2021-12-06 16:10       ` Jisheng Zhang
2021-12-03  8:35   ` Alexandre ghiti
2021-12-03  8:35     ` Alexandre ghiti
2021-12-03  5:03 ` [PATCH 3/5] riscv: mm: init: remove _pt_ops and use pt_ops directly Jisheng Zhang
2021-12-03  5:03   ` Jisheng Zhang
2021-12-03  8:57   ` Alexandre ghiti
2021-12-03  8:57     ` Alexandre ghiti
2021-12-03 14:18     ` Jisheng Zhang
2021-12-03 14:18       ` Jisheng Zhang
2021-12-03  5:03 ` [PATCH 4/5] riscv: mm: init: try IS_ENABLED(CONFIG_XIP_KERNEL) instead of #ifdef Jisheng Zhang
2021-12-03  5:03   ` Jisheng Zhang
2021-12-03  8:39   ` Alexandre ghiti
2021-12-03  8:39     ` Alexandre ghiti
2021-12-03  5:03 ` [PATCH 5/5] riscv: mm: init: try best to remove #ifdef CONFIG_XIP_KERNEL usage Jisheng Zhang
2021-12-03  5:03   ` Jisheng Zhang
2021-12-03  8:41   ` Alexandre ghiti
2021-12-03  8:41     ` Alexandre ghiti

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211206161748.0C772C341C1@smtp.kernel.org \
    --to=jszhang@kernel.org \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.