Linux-RISC-V Archive mirror
 help / color / mirror / Atom feed
From: Alexandre Ghiti <alex@ghiti.fr>
To: Nam Cao <namcao@linutronix.de>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	Alexandre Ghiti <alexghiti@rivosinc.com>,
	linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] riscv: change XIP's kernel_map.size to be size of the entire kernel
Date: Wed, 8 May 2024 21:43:11 +0200	[thread overview]
Message-ID: <f582aedc-603c-4c2f-9013-ae8e6cde767f@ghiti.fr> (raw)
In-Reply-To: <20240508191917.2892064-1-namcao@linutronix.de>

Hi Nam,

On 08/05/2024 21:19, Nam Cao wrote:
> With XIP kernel, kernel_map.size is set to be only the size of data part of
> the kernel. This is inconsistent with "normal" kernel, who sets it to be
> the size of the entire kernel.
>
> More importantly, XIP kernel fails to boot if CONFIG_DEBUG_VIRTUAL is
> enabled, because there are checks on virtual addresses with the assumption
> that kernel_map.size is the size of the entire kernel (these checks are in
> arch/riscv/mm/physaddr.c).
>
> Change XIP's kernel_map.size to be the size of the entire kernel.
>
> Signed-off-by: Nam Cao <namcao@linutronix.de>
> Cc: <stable@vger.kernel.org> # v6.1+
> ---
> I wouldn't consider this inconsistency to be a bug. It only became a
> a problem after kernel_map.size is used to check virtual addresses in
> 5f763b3b5960 ("riscv: Fix DEBUG_VIRTUAL false warnings"). So I will only
> backport this to stable versions that contain this commit: v6.1+
>
>   arch/riscv/mm/init.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index c081e7d349b1..0c0562839899 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -903,7 +903,7 @@ static void __init create_kernel_page_table(pgd_t *pgdir,
>   				   PMD_SIZE, PAGE_KERNEL_EXEC);
>   
>   	/* Map the data in RAM */
> -	end_va = kernel_map.virt_addr + XIP_OFFSET + kernel_map.size;
> +	end_va = kernel_map.virt_addr + kernel_map.size;
>   	for (va = kernel_map.virt_addr + XIP_OFFSET; va < end_va; va += PMD_SIZE)
>   		create_pgd_mapping(pgdir, va,
>   				   kernel_map.phys_addr + (va - (kernel_map.virt_addr + XIP_OFFSET)),
> @@ -1072,7 +1072,7 @@ asmlinkage void __init setup_vm(uintptr_t dtb_pa)
>   
>   	phys_ram_base = CONFIG_PHYS_RAM_BASE;
>   	kernel_map.phys_addr = (uintptr_t)CONFIG_PHYS_RAM_BASE;
> -	kernel_map.size = (uintptr_t)(&_end) - (uintptr_t)(&_sdata);
> +	kernel_map.size = (uintptr_t)(&_end) - (uintptr_t)(&_start);
>   
>   	kernel_map.va_kernel_xip_pa_offset = kernel_map.virt_addr - kernel_map.xiprom;
>   #else


You can add:

Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>

Thanks,

Alex


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

      reply	other threads:[~2024-05-09  2:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-08 19:19 [PATCH] riscv: change XIP's kernel_map.size to be size of the entire kernel Nam Cao
2024-05-08 19:43 ` Alexandre Ghiti [this message]

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=f582aedc-603c-4c2f-9013-ae8e6cde767f@ghiti.fr \
    --to=alex@ghiti.fr \
    --cc=alexghiti@rivosinc.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=namcao@linutronix.de \
    --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 read-only IMAP folder(s) and NNTP newsgroup(s).