linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Atish Patra <atish.patra@wdc.com>
To: linux-kernel@vger.kernel.org
Cc: Atish Patra <atish.patra@wdc.com>,
	Ard Biesheuvel <ardb@kernel.org>,
	linux-efi@vger.kernel.org, linux-riscv@lists.infradead.org,
	Masahiro Yamada <masahiroy@kernel.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>
Subject: [RFC PATCH v2 06/11] riscv: Parse all memory blocks to remove unusable memory
Date: Mon,  6 Jul 2020 10:26:04 -0700	[thread overview]
Message-ID: <20200706172609.25965-7-atish.patra@wdc.com> (raw)
In-Reply-To: <20200706172609.25965-1-atish.patra@wdc.com>

Currently, maximum physical memory allowed is equal to -PAGE_OFFSET.
That's why we remove any memory blocks spanning beyond that size. However,
it is done only for memblock containing linux kernel which will not work
if there are multiple memblocks.

Process all memory blocks to figure out how much memory needs to be removed
and remove at the end instead of updating the memblock list in place.

Signed-off-by: Atish Patra <atish.patra@wdc.com>
---
 arch/riscv/mm/init.c | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 4021706aef81..c5268fe6e6de 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -123,26 +123,29 @@ void __init setup_bootmem(void)
 {
 	struct memblock_region *reg;
 	phys_addr_t mem_size = 0;
+	phys_addr_t total_mem = 0;
+	phys_addr_t mem_start, end = 0;
 	phys_addr_t vmlinux_end = __pa_symbol(&_end);
 	phys_addr_t vmlinux_start = __pa_symbol(&_start);
 
 	/* Find the memory region containing the kernel */
 	for_each_memblock(memory, reg) {
-		phys_addr_t end = reg->base + reg->size;
-
-		if (reg->base <= vmlinux_start && vmlinux_end <= end) {
-			mem_size = min(reg->size, (phys_addr_t)-PAGE_OFFSET);
-
-			/*
-			 * Remove memblock from the end of usable area to the
-			 * end of region
-			 */
-			if (reg->base + mem_size < end)
-				memblock_remove(reg->base + mem_size,
-						end - reg->base - mem_size);
-		}
+		end = reg->base + reg->size;
+		if (!total_mem)
+			mem_start = reg->base;
+		if (reg->base <= vmlinux_start && vmlinux_end <= end)
+			BUG_ON(reg->size == 0);
+		total_mem = total_mem + reg->size;
 	}
-	BUG_ON(mem_size == 0);
+
+	/*
+	 * Remove memblock from the end of usable area to the
+	 * end of region
+	 */
+	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);
 
 	/* Reserve from the start of the kernel to the end of the kernel */
 	memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start);
-- 
2.24.0


  parent reply	other threads:[~2020-07-06 17:27 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-06 17:25 [RFC PATCH v2 00/11] Add UEFI support for RISC-V Atish Patra
2020-07-06 17:25 ` [RFC PATCH v2 01/11] efi/libstub: Move the function prototypes to header file Atish Patra
2020-07-22 22:48   ` [tip: efi/urgent] " tip-bot2 for Atish Patra
2020-07-06 17:26 ` [RFC PATCH v2 02/11] RISC-V: Move DT mapping outof fixmap Atish Patra
2020-07-06 17:26 ` [RFC PATCH v2 03/11] RISC-V: Setup exception vector early Atish Patra
2020-07-06 17:26 ` [RFC PATCH v2 04/11] RISC-V: Add early ioremap support Atish Patra
2020-07-06 17:26 ` [RFC PATCH v2 05/11] RISC-V: Set maximum number of mapped pages correctly Atish Patra
2020-07-06 17:26 ` Atish Patra [this message]
2020-07-06 17:26 ` [RFC PATCH v2 07/11] include: pe.h: Add RISC-V related PE definition Atish Patra
2020-07-06 17:26 ` [RFC PATCH v2 08/11] RISC-V: Add PE/COFF header for EFI stub Atish Patra
2020-07-06 17:26 ` [RFC PATCH v2 09/11] RISC-V: Add EFI stub support Atish Patra
2020-07-06 17:26 ` [RFC PATCH v2 10/11] efi: Rename arm-init to efi-init common for all arch Atish Patra
2020-07-06 17:26 ` [RFC PATCH v2 11/11] RISC-V: Add EFI runtime services Atish Patra
2020-07-07  6:41 ` [RFC PATCH v2 00/11] Add UEFI support for RISC-V Ard Biesheuvel
2020-07-07  7:49   ` Atish Patra

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=20200706172609.25965-7-atish.patra@wdc.com \
    --to=atish.patra@wdc.com \
    --cc=ardb@kernel.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=masahiroy@kernel.org \
    --cc=palmer@dabbelt.com \
    --cc=xypron.glpk@gmx.de \
    /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 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).