linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4] RISC-V: Remove any memblock representing unusable memory area
@ 2020-10-07 21:51 Atish Patra
  2020-11-05 18:03 ` Palmer Dabbelt
  0 siblings, 1 reply; 2+ messages in thread
From: Atish Patra @ 2020-10-07 21:51 UTC (permalink / raw)
  To: linux-kernel
  Cc: Atish Patra, Mike Rapoport, Albert Ou, Andrew Morton, Anup Patel,
	linux-riscv, Mike Rapoport, Palmer Dabbelt, Paul Walmsley

RISC-V limits the physical memory size by -PAGE_OFFSET. Any memory beyond
that size from DRAM start is unusable. Just remove any memblock pointing
to those memory region without worrying about computing the maximum size.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
Reviewed-by: Mike Rapoport <rppt@linux.ibm.com>
---
Changes from v3->v4:
1. Rebased on top of for-next.
---
 arch/riscv/mm/init.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 4eda1a7e8521..da43c17544c5 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -156,9 +156,8 @@ static void __init setup_initrd(void)
 
 void __init setup_bootmem(void)
 {
-	phys_addr_t mem_size = 0;
-	phys_addr_t total_mem = 0;
-	phys_addr_t mem_start, start, end = 0;
+	phys_addr_t mem_start = 0;
+	phys_addr_t start, end = 0;
 	phys_addr_t vmlinux_end = __pa_symbol(&_end);
 	phys_addr_t vmlinux_start = __pa_symbol(&_start);
 	u64 i;
@@ -166,21 +165,18 @@ void __init setup_bootmem(void)
 	/* Find the memory region containing the kernel */
 	for_each_mem_range(i, &start, &end) {
 		phys_addr_t size = end - start;
-		if (!total_mem)
+		if (!mem_start)
 			mem_start = start;
 		if (start <= vmlinux_start && vmlinux_end <= end)
 			BUG_ON(size == 0);
-		total_mem = total_mem + size;
 	}
 
 	/*
-	 * Remove memblock from the end of usable area to the
-	 * end of region
+	 * The maximal physical memory size is -PAGE_OFFSET.
+	 * Make sure that any memory beyond mem_start + (-PAGE_OFFSET) is removed
+	 * as it is unusable by kernel.
 	 */
-	mem_size = min(total_mem, (phys_addr_t)-PAGE_OFFSET);
-	if (mem_start + mem_size < end)
-		memblock_remove(mem_start + mem_size,
-				end - mem_start - mem_size);
+	memblock_enforce_memory_limit(mem_start - PAGE_OFFSET);
 
 	/* Reserve from the start of the kernel to the end of the kernel */
 	memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v4] RISC-V: Remove any memblock representing unusable memory area
  2020-10-07 21:51 [PATCH v4] RISC-V: Remove any memblock representing unusable memory area Atish Patra
@ 2020-11-05 18:03 ` Palmer Dabbelt
  0 siblings, 0 replies; 2+ messages in thread
From: Palmer Dabbelt @ 2020-11-05 18:03 UTC (permalink / raw)
  To: Atish Patra
  Cc: linux-kernel, Atish Patra, rppt, aou, akpm, Anup Patel,
	linux-riscv, rppt, Paul Walmsley

On Wed, 07 Oct 2020 14:51:59 PDT (-0700), Atish Patra wrote:
> RISC-V limits the physical memory size by -PAGE_OFFSET. Any memory beyond
> that size from DRAM start is unusable. Just remove any memblock pointing
> to those memory region without worrying about computing the maximum size.
>
> Signed-off-by: Atish Patra <atish.patra@wdc.com>
> Reviewed-by: Mike Rapoport <rppt@linux.ibm.com>
> ---
> Changes from v3->v4:
> 1. Rebased on top of for-next.
> ---
>  arch/riscv/mm/init.c | 18 +++++++-----------
>  1 file changed, 7 insertions(+), 11 deletions(-)
>
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index 4eda1a7e8521..da43c17544c5 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -156,9 +156,8 @@ static void __init setup_initrd(void)
>
>  void __init setup_bootmem(void)
>  {
> -	phys_addr_t mem_size = 0;
> -	phys_addr_t total_mem = 0;
> -	phys_addr_t mem_start, start, end = 0;
> +	phys_addr_t mem_start = 0;
> +	phys_addr_t start, end = 0;
>  	phys_addr_t vmlinux_end = __pa_symbol(&_end);
>  	phys_addr_t vmlinux_start = __pa_symbol(&_start);
>  	u64 i;
> @@ -166,21 +165,18 @@ void __init setup_bootmem(void)
>  	/* Find the memory region containing the kernel */
>  	for_each_mem_range(i, &start, &end) {
>  		phys_addr_t size = end - start;
> -		if (!total_mem)
> +		if (!mem_start)
>  			mem_start = start;
>  		if (start <= vmlinux_start && vmlinux_end <= end)
>  			BUG_ON(size == 0);
> -		total_mem = total_mem + size;
>  	}
>
>  	/*
> -	 * Remove memblock from the end of usable area to the
> -	 * end of region
> +	 * The maximal physical memory size is -PAGE_OFFSET.
> +	 * Make sure that any memory beyond mem_start + (-PAGE_OFFSET) is removed
> +	 * as it is unusable by kernel.
>  	 */
> -	mem_size = min(total_mem, (phys_addr_t)-PAGE_OFFSET);
> -	if (mem_start + mem_size < end)
> -		memblock_remove(mem_start + mem_size,
> -				end - mem_start - mem_size);
> +	memblock_enforce_memory_limit(mem_start - PAGE_OFFSET);
>
>  	/* Reserve from the start of the kernel to the end of the kernel */
>  	memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start);

This is on fixes.  Thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-11-05 18:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-07 21:51 [PATCH v4] RISC-V: Remove any memblock representing unusable memory area Atish Patra
2020-11-05 18:03 ` Palmer Dabbelt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).