mbox series

[0/7] remove size limit on XIP kernel

Message ID cover.1715286093.git.namcao@linutronix.de (mailing list archive)
Headers show
Series remove size limit on XIP kernel | expand

Message

Nam Cao May 10, 2024, 6:28 a.m. UTC
Hi,

For XIP kernel, the writable data section is always at offset specified in
XIP_OFFSET, which is hard-coded to 32MB.

Unfortunately, this means the read-only section (placed before the
writable section) is restricted in size. This causes build failure if the
kernel gets too large.

This series remove the use of XIP_OFFSET one by one, then remove this
macro entirely at the end, with the goal of lifting this size restriction.

Also some cleanup and documentation along the way.

This series depends on
    https://lore.kernel.org/linux-riscv/20240508191917.2892064-1-namcao@linutronix.de/
to apply cleanly, and also depends on
    https://lore.kernel.org/linux-riscv/20240508173116.2866192-1-namcao@linutronix.de/
which fixes a boot issue.

Best regards,
Nam

Nam Cao (7):
  riscv: cleanup XIP_FIXUP macro
  riscv: replace va_kernel_pa_offset with va_kernel_data_pa_offset on
    XIP
  riscv: drop the use of XIP_OFFSET in XIP_FIXUP_OFFSET
  riscv: drop the use of XIP_OFFSET in XIP_FIXUP_FLASH_OFFSET
  riscv: drop the use of XIP_OFFSET in kernel_mapping_va_to_pa()
  riscv: drop the use of XIP_OFFSET in create_kernel_page_table()
  riscv: remove limit on the size of read-only section for XIP kernel

 arch/riscv/include/asm/page.h       | 25 ++++++++++++++++++------
 arch/riscv/include/asm/pgtable.h    | 18 +++++++----------
 arch/riscv/include/asm/xip_fixup.h  | 30 +++++++++++++++++++++++------
 arch/riscv/kernel/vmlinux-xip.lds.S |  4 ++--
 arch/riscv/mm/init.c                | 11 +++++++----
 5 files changed, 59 insertions(+), 29 deletions(-)

Comments

Alexandre Ghiti May 12, 2024, 3:47 p.m. UTC | #1
Hi Nam,

On 10/05/2024 08:28, Nam Cao wrote:
> Hi,
>
> For XIP kernel, the writable data section is always at offset specified in
> XIP_OFFSET, which is hard-coded to 32MB.
>
> Unfortunately, this means the read-only section (placed before the
> writable section) is restricted in size. This causes build failure if the
> kernel gets too large.
>
> This series remove the use of XIP_OFFSET one by one, then remove this
> macro entirely at the end, with the goal of lifting this size restriction.
>
> Also some cleanup and documentation along the way.
>
> This series depends on
>      https://lore.kernel.org/linux-riscv/20240508191917.2892064-1-namcao@linutronix.de/
> to apply cleanly, and also depends on
>      https://lore.kernel.org/linux-riscv/20240508173116.2866192-1-namcao@linutronix.de/
> which fixes a boot issue.
>
> Best regards,
> Nam
>
> Nam Cao (7):
>    riscv: cleanup XIP_FIXUP macro
>    riscv: replace va_kernel_pa_offset with va_kernel_data_pa_offset on
>      XIP
>    riscv: drop the use of XIP_OFFSET in XIP_FIXUP_OFFSET
>    riscv: drop the use of XIP_OFFSET in XIP_FIXUP_FLASH_OFFSET
>    riscv: drop the use of XIP_OFFSET in kernel_mapping_va_to_pa()
>    riscv: drop the use of XIP_OFFSET in create_kernel_page_table()
>    riscv: remove limit on the size of read-only section for XIP kernel
>
>   arch/riscv/include/asm/page.h       | 25 ++++++++++++++++++------
>   arch/riscv/include/asm/pgtable.h    | 18 +++++++----------
>   arch/riscv/include/asm/xip_fixup.h  | 30 +++++++++++++++++++++++------
>   arch/riscv/kernel/vmlinux-xip.lds.S |  4 ++--
>   arch/riscv/mm/init.c                | 11 +++++++----
>   5 files changed, 59 insertions(+), 29 deletions(-)
>

XIP kernels are intended for use with flash devices so the XIP_OFFSET 
restriction actually represents the size of the flash device: IIRC this 
32MB was chosen because it would fit "most devices". I think it would be 
good to come up with a mechanism that allows to restrict the size at 
build time: a config? XIP kernels are custom kernels so the user could 
enter its flash size so that if kernel ends up being too large, it 
fails. And by default, we could a very large size to avoid kernel test 
robot build failures.

Thanks,

Alex
Nam Cao May 13, 2024, 8:19 a.m. UTC | #2
On Sun, May 12, 2024 at 05:47:24PM +0200, Alexandre Ghiti wrote:
> XIP kernels are intended for use with flash devices so the XIP_OFFSET
> restriction actually represents the size of the flash device: IIRC this 32MB
> was chosen because it would fit "most devices". I think it would be good to
> come up with a mechanism that allows to restrict the size at build time: a
> config? XIP kernels are custom kernels so the user could enter its flash
> size so that if kernel ends up being too large, it fails. And by default, we
> could a very large size to avoid kernel test robot build failures.

I'm not sure if it is beneficial to do that. Users' flash tool would
complain about the kernel not fitting in flash anyway. I think this would
only make it (a bit more) complicated to build the kernel.

Furthermore XIP_OFFSET at the moment is not the flash size, it is size of
.text (and some other read-only sections). Kernel's data sections are in
flash too, which is copied to RAM during boot.

With the current linker setting, the first 32MB of virtual memory is
occupied by .text. Then at 32MB offset, .data section starts. So if
XIP_OFFSET limit is exceeded, the kernel's size is already way more than
32MB.

Instead, this series moves .data and .text right next to each other (well,
almost, because we need PMD_SIZE alignment). So that if .text size exceed
32MB, the offset that .data resides would increase as well.

If we really want to set flash size during build time (which, again, I
doubt the benefit of), this series would still be relevant: it is not just
removing the size limit, it is also removing the fixed position of the
.data section in virtual address space (in other words, removing the
useless "hole" between .text section and .data section).

Best regards,
Nam