From: Palmer Dabbelt <palmer@dabbelt.com>
To: alex@ghiti.fr
Cc: Paul Walmsley <paul.walmsley@sifive.com>,
aou@eecs.berkeley.edu, wangkefeng.wang@huawei.com,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
alex@ghiti.fr
Subject: Re: [PATCH 3/3] riscv: Make sure the kernel mapping does not overlap with IS_ERR_VALUE
Date: Fri, 23 Jul 2021 17:58:08 -0700 (PDT) [thread overview]
Message-ID: <mhng-bc552805-71aa-4a1e-afa7-dfd08cfba35b@palmerdabbelt-glaptop> (raw)
In-Reply-To: <20210629091349.3802690-3-alex@ghiti.fr>
On Tue, 29 Jun 2021 02:13:48 PDT (-0700), alex@ghiti.fr wrote:
> The check that is done in setup_bootmem currently only works for 32-bit
> kernel since the kernel mapping has been moved outside of the linear
> mapping for 64-bit kernel. So make sure that for 64-bit kernel, the kernel
> mapping does not overlap with the last 4K of the addressable memory.
>
> Signed-off-by: Alexandre Ghiti <alex@ghiti.fr>
> ---
> arch/riscv/mm/init.c | 18 ++++++++++++++++--
> 1 file changed, 16 insertions(+), 2 deletions(-)
>
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index a1a0c4afa80f..a90c41bc9485 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -156,7 +156,7 @@ static void __init setup_bootmem(void)
> {
> phys_addr_t vmlinux_end = __pa_symbol(&_end);
> phys_addr_t vmlinux_start = __pa_symbol(&_start);
> - phys_addr_t max_mapped_addr = __pa(~(ulong)0);
> + phys_addr_t __maybe_unused max_mapped_addr;
> phys_addr_t dram_end;
>
> #ifdef CONFIG_XIP_KERNEL
> @@ -179,14 +179,20 @@ static void __init setup_bootmem(void)
> memblock_reserve(vmlinux_start, vmlinux_end - vmlinux_start);
>
> dram_end = memblock_end_of_DRAM();
> +#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
> * macro. Make sure that last 4k bytes are not usable by memblock
> - * if end of dram is equal to maximum addressable memory.
> + * if end of dram is equal to maximum addressable memory. For 64-bit
> + * kernel, this problem can't happen here as the end of the virtual
> + * address space is occupied by the kernel mapping then this check must
> + * be done in create_kernel_page_table.
> */
> + max_mapped_addr = __pa(~(ulong)0);
> if (max_mapped_addr == (dram_end - 1))
> memblock_set_current_limit(max_mapped_addr - 4096);
> +#endif
>
> min_low_pfn = PFN_UP(memblock_start_of_DRAM());
> max_low_pfn = max_pfn = PFN_DOWN(dram_end);
> @@ -556,6 +562,7 @@ static void __init create_kernel_page_table(pgd_t *pgdir, uintptr_t map_size,
> uintptr_t va, end_va;
>
> end_va = kernel_virt_addr + load_sz;
> +
> for (va = kernel_virt_addr; va < end_va; va += map_size)
> create_pgd_mapping(pgdir, va,
> load_pa + (va - kernel_virt_addr),
> @@ -602,6 +609,13 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
> /* Sanity check alignment and size */
> BUG_ON((PAGE_OFFSET % PGDIR_SIZE) != 0);
> BUG_ON((load_pa % map_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_virt_addr + load_sz) > ADDRESS_SPACE_END - SZ_4K);
> +#endif
>
> pt_ops.alloc_pte = alloc_pte_early;
> pt_ops.get_pte_virt = get_pte_virt_early;
Thanks. These are on fixes, with some fixes tags added. This one had
some merge conflicts that I had to fix up, LMK if something went wrong.
next prev parent reply other threads:[~2021-07-24 0:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-29 9:13 [PATCH 1/3] riscv: Fix memory_limit for 64-bit kernel Alexandre Ghiti
2021-06-29 9:13 ` [PATCH 2/3] riscv: Make sure the linear mapping does not use the kernel mapping Alexandre Ghiti
2021-06-29 9:13 ` [PATCH 3/3] riscv: Make sure the kernel mapping does not overlap with IS_ERR_VALUE Alexandre Ghiti
2021-07-24 0:58 ` Palmer Dabbelt [this message]
2021-07-26 5:47 ` Alex Ghiti
2021-07-01 10:44 ` [PATCH 1/3] riscv: Fix memory_limit for 64-bit kernel Kefeng Wang
2021-07-01 19:01 ` Alex Ghiti
2021-07-01 19:04 ` Alex 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=mhng-bc552805-71aa-4a1e-afa7-dfd08cfba35b@palmerdabbelt-glaptop \
--to=palmer@dabbelt.com \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=paul.walmsley@sifive.com \
--cc=wangkefeng.wang@huawei.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).