public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] riscv: change XIP's kernel_map.size to be size of the entire kernel
@ 2024-05-08 19:19 Nam Cao
  2024-05-08 19:43 ` Alexandre Ghiti
  2024-08-15 17:50 ` patchwork-bot+linux-riscv
  0 siblings, 2 replies; 3+ messages in thread
From: Nam Cao @ 2024-05-08 19:19 UTC (permalink / raw)
  To: Paul Walmsley, Palmer Dabbelt, Albert Ou, Alexandre Ghiti,
	linux-riscv, linux-kernel

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
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] riscv: change XIP's kernel_map.size to be size of the entire kernel
  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
  2024-08-15 17:50 ` patchwork-bot+linux-riscv
  1 sibling, 0 replies; 3+ messages in thread
From: Alexandre Ghiti @ 2024-05-08 19:43 UTC (permalink / raw)
  To: Nam Cao, Paul Walmsley, Palmer Dabbelt, Albert Ou,
	Alexandre Ghiti, linux-riscv, linux-kernel

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] riscv: change XIP's kernel_map.size to be size of the entire kernel
  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
@ 2024-08-15 17:50 ` patchwork-bot+linux-riscv
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+linux-riscv @ 2024-08-15 17:50 UTC (permalink / raw)
  To: Nam Cao; +Cc: linux-riscv, paul.walmsley, palmer, aou, alexghiti, linux-kernel

Hello:

This patch was applied to riscv/linux.git (fixes)
by Palmer Dabbelt <palmer@rivosinc.com>:

On Wed,  8 May 2024 21:19:17 +0200 you 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).
> 
> [...]

Here is the summary with links:
  - riscv: change XIP's kernel_map.size to be size of the entire kernel
    https://git.kernel.org/riscv/c/57d76bc51fd8

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-15 17:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2024-08-15 17:50 ` patchwork-bot+linux-riscv

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox