From: Woody Zhang <woodylab@foxmail.com>
To: 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
Cc: Woody Zhang <woodylab@foxmail.com>
Subject: [PATCH] riscv: reserve DTB before possible memblock allocation
Date: Wed, 7 Jun 2023 21:35:19 +0800 [thread overview]
Message-ID: <tencent_B15C0F1F3105597D0DCE7DADC96C5EB5CF0A@qq.com> (raw)
It's possible that early_init_fdt_scan_reserved_mem() allocates memory
from memblock for dynamic reserved memory in `/reserved-memory` node.
Any fixed reservation must be done before that to avoid potential
conflicts.
Reserve the DTB in memblock just after early scanning it.
Signed-off-by: Woody Zhang <woodylab@foxmail.com>
---
arch/riscv/kernel/setup.c | 10 ++++++++++
arch/riscv/mm/init.c | 9 ---------
2 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index 36b026057503..c147fa8da929 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -16,6 +16,7 @@
#include <linux/console.h>
#include <linux/screen_info.h>
#include <linux/of_fdt.h>
+#include <linux/libfdt.h>
#include <linux/sched/task.h>
#include <linux/smp.h>
#include <linux/efi.h>
@@ -256,6 +257,15 @@ static void __init parse_dtb(void)
pr_err("No DTB passed to the kernel\n");
}
+ /*
+ * If DTB is built in, no need to reserve its memblock.
+ * Otherwise, do reserve it but avoid using
+ * early_init_fdt_reserve_self() since __pa() does
+ * not work for DTB pointers that are fixmap addresses
+ */
+ if (!IS_ENABLED(CONFIG_BUILTIN_DTB))
+ memblock_reserve(dtb_early_pa, fdt_totalsize(dtb_early_va));
+
#ifdef CONFIG_CMDLINE_FORCE
strscpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
pr_info("Forcing kernel command line to: %s\n", boot_command_line);
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index c6bb966e4123..f8c9a79acd94 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -254,15 +254,6 @@ static void __init setup_bootmem(void)
*/
early_init_fdt_scan_reserved_mem();
- /*
- * If DTB is built in, no need to reserve its memblock.
- * Otherwise, do reserve it but avoid using
- * early_init_fdt_reserve_self() since __pa() does
- * not work for DTB pointers that are fixmap addresses
- */
- if (!IS_ENABLED(CONFIG_BUILTIN_DTB))
- memblock_reserve(dtb_early_pa, fdt_totalsize(dtb_early_va));
-
dma_contiguous_reserve(dma32_phys_limit);
if (IS_ENABLED(CONFIG_64BIT))
hugetlb_cma_reserve(PUD_SHIFT - PAGE_SHIFT);
--
2.39.2
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next reply other threads:[~2023-06-07 13:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-07 13:35 Woody Zhang [this message]
2023-06-07 18:17 ` [PATCH] riscv: reserve DTB before possible memblock allocation Conor Dooley
2023-06-07 22:17 ` Woody Zhang
2023-06-07 22:23 ` Conor Dooley
2023-11-27 14:29 ` Conor Dooley
2023-06-08 7:49 ` Alexandre Ghiti
2023-06-10 15:41 ` Conor Dooley
2023-06-10 23:27 ` Woody Zhang
2023-06-12 6:57 ` 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=tencent_B15C0F1F3105597D0DCE7DADC96C5EB5CF0A@qq.com \
--to=woodylab@foxmail.com \
--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 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).