From: Xu Lu <luxu.kernel@bytedance.com>
To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu
Cc: lihangjing@bytedance.com, xieyongji@bytedance.com,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
Xu Lu <luxu.kernel@bytedance.com>
Subject: [PATCH] riscv: mm: Fix alignment of phys_ram_base
Date: Mon, 2 Dec 2024 18:16:01 +0800 [thread overview]
Message-ID: <20241202101601.48284-1-luxu.kernel@bytedance.com> (raw)
This commit fixes the alignment of phys_ram_base in RISC-V.
In sparse vmemmap model, the virtual address of vmemmap is calculated as:
'(struct page *)VMEMMAP_START - (phys_ram_base >> PAGE_SHIFT)'.
And the struct page's va can be calculated with an offset:
'vmemmap + (pfn)'.
However, when initializing struct pages, kernel actually starts from the
first page from the same section that phys_ram_base belongs to. If the
first page's physical address is not 'phys_ram_base >> PAGE_SHIFT', then
we get an va below VMEMMAP_START when calculating va for it's struct page.
For example, if phys_ram_base starts from 0x82000000 with pfn 0x82000, the
first page in the same section is actually pfn 0x80000. During
init_unavailage_range, we will initialize struct page for pfn 0x80000
with virtual address '(struct page *)VMEMMAP_START - 0x2000', which is
below VMEMMAP_START as well as PCI_IO_END.
This commit fixes this bug by aligning phys_ram_base with SECTION_SIZE.
Signed-off-by: Xu Lu <luxu.kernel@bytedance.com>
---
arch/riscv/mm/init.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
index 0e8c20adcd98..9866de267b74 100644
--- a/arch/riscv/mm/init.c
+++ b/arch/riscv/mm/init.c
@@ -59,6 +59,8 @@ EXPORT_SYMBOL(pgtable_l4_enabled);
EXPORT_SYMBOL(pgtable_l5_enabled);
#endif
+#define RISCV_MEMSTART_ALIGN (1UL << SECTION_SIZE_BITS)
+
phys_addr_t phys_ram_base __ro_after_init;
EXPORT_SYMBOL(phys_ram_base);
@@ -241,7 +243,8 @@ static void __init setup_bootmem(void)
* at worst, we map the linear mapping with PMD mappings.
*/
if (!IS_ENABLED(CONFIG_XIP_KERNEL))
- phys_ram_base = memblock_start_of_DRAM() & PMD_MASK;
+ phys_ram_base = round_down(memblock_start_of_DRAM(),
+ RISCV_MEMSTART_ALIGN);
/*
* In 64-bit, any use of __va/__pa before this point is wrong as we
--
2.20.1
next reply other threads:[~2024-12-02 10:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-02 10:16 Xu Lu [this message]
2024-12-02 16:15 ` [PATCH] riscv: mm: Fix alignment of phys_ram_base kernel test robot
2024-12-03 11:49 ` Björn Töpel
2024-12-03 13:37 ` [External] " Xu Lu
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=20241202101601.48284-1-luxu.kernel@bytedance.com \
--to=luxu.kernel@bytedance.com \
--cc=aou@eecs.berkeley.edu \
--cc=lihangjing@bytedance.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=xieyongji@bytedance.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