Skip to content

ARM: p2v: reduce min alignment to 2 MiB

Ard Biesheuvel linux-arm-kernel linux-efi 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest10 patches 22 repliesIn review
  2. v16 patches 7 repliesSuperseded

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/10ARM: p2v: fix handling of LPAE translation in BE modearch/arm/kernel/head.S+1 -53 replies
2/10ARM: assembler: introduce adr_l, ldr_l and str_l macrosarch/arm/include/asm/assembler.h+84 -01 reply
3/10ARM: p2v: move patching code to separate assembler source filearch/arm/kernel/Makefile arch/arm/kernel/head.S arch/arm/kernel/phys2virt.S+152 -1381 reply
4/10ARM: p2v: factor out shared loop processingarch/arm/kernel/phys2virt.S+11 -132 replies
5/10ARM: p2v: factor out BE8 handlingarch/arm/kernel/phys2virt.S+16 -142 replies
6/10ARM: p2v: drop redundant 'type' argument from __pv_stubarch/arm/include/asm/memory.h+4 -41 reply
7/10ARM: p2v: use relative references in patch site arraysarch/arm/include/asm/memory.h arch/arm/kernel/phys2virt.S+10 -142 replies
8/10ARM: p2v: simplify __fixup_pv_table()arch/arm/kernel/phys2virt.S+14 -201 reply
9/10ARM: p2v: switch to MOVW for Thumb2 and ARM/LPAEarch/arm/include/asm/memory.h arch/arm/kernel/phys2virt.S+148 -433 replies
10/10ARM: p2v: reduce p2v alignment requirement to 2 MiBarch/arm/Kconfig arch/arm/include/asm/memory.h arch/arm/kernel/phys2virt.S+35 -204 replies

Reviews trailers per patch

All 10 patches have a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchNicolas PitreLinus Walleij
SeriesA-b
1/10R-b
2/10R-b R-b
3/10R-b
4/10R-b
5/10R-b
6/10R-b
7/10R-b
8/10R-b
9/10R-b
10/10A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 00/10] ARM: p2v: reduce min alignment to 2 MiB

This series is inspired by Zhei Len's series [0], which updates the ARM p2v patching code to optionally support p2v relative alignments of as little as 64 KiB.

Reducing this alignment is necessary for some specific Huawei boards, but given that reducing this minimum alignment will make the boot sequence more robust for all platforms, especially EFI boot, which no longer relies on the 128 MB masking of the decompressor load address, but uses firmware memory allocation routines to find a suitable spot for the decompressed kernel.

This series is not based on Zhei Len's code, but addresses the same problem, and takes some feedback given in the review into account:
- use of a MOVW instruction to avoid two adds/adcs sequences when dealing with the carry on LPAE
- add support for Thumb2 kernels as well
- make the change unconditional - it will bit rot otherwise, and has value for other platforms as well.

Patch #1 fixes a BE8 bug in the existing code.

Patch #2 incorporates a patch from a different series [1] that introduces the adr_l and str_l macros, for use in subsequent patches.

Patch #3 moves the p2v patching code into a separate assembler source file, as suggested by Nico.

Patches #4 to #8 perform some preparatory clean up to make the real changes easier to review, and more maintainable going forward.

Patch #9 switches the ARM/LPAE and Thumb2 p2v patchable sequences to MOVW, so that we can extend the size of the immediate field in a later patch.

Patch #10 increases the size of the low order immediate to 11 bits, so that we can deal with any physical to virtual displacement that is a multiple of 2 MiB.

Tested in QEMU using various permutations of the the following configuration options:
- ARM mode vs Thumb2 mode
- LE vs BE8
- LPAE vs non-LPAE
- 3/1 split, 2/2 split, 3/1 opt split

with the following diff applied to decompress the kernel at an address which is not 16 MiB aligned:

arch/arm/boot/compressed/head.S +1 -0
@@ -275,6 +275,7 @@ not_angel:
                and     r4, r4, #0xf8000000
                /* Determine final kernel image address. */
                add     r4, r4, #TEXT_OFFSET
+               add     r4, r4, #SZ_2M
 #else
                ldr     r4, =zreladdr
 #endif

Changes since RFC/RFT:
- new patches #1 - #3 and #8
- drop bogus patching of ADD/SUB instructions, which is unnecessary, and only happens to work when the p2v displacement is exactly 2 GiB like on QEMU when running a 3/1 split
- use a copious amount of comments to make the code more understandable and maintainable

Cc Zhen Lei <[email protected]>
Cc Russell King <[email protected]>
Cc Linus Walleij <[email protected]>
Cc Nicolas Pitre <[email protected]>

[0] https://lore.kernel.org/linux-arm-kernel/[email protected]/
[1] https://lore.kernel.org/linux-arm-kernel/[email protected]/

Ard Biesheuvel (10):
ARM: p2v: fix handling of LPAE translation in BE mode
ARM: assembler: introduce adr_l, ldr_l and str_l macros
ARM: p2v: move patching code to separate assembler source file
ARM: p2v: factor out shared loop processing
ARM: p2v: factor out BE8 handling
ARM: p2v: drop redundant 'type' argument from __pv_stub
ARM: p2v: use relative references in patch site arrays
ARM: p2v: simplify __fixup_pv_table()
ARM: p2v: switch to MOVW for Thumb2 and ARM/LPAE
ARM: p2v: reduce p2v alignment requirement to 2 MiB

 arch/arm/Kconfig                 |   2 +-
 arch/arm/include/asm/assembler.h |  84 +++++++
 arch/arm/include/asm/memory.h    |  57 +++--
 arch/arm/kernel/Makefile         |   1 +
 arch/arm/kernel/head.S           | 142 ------------
 arch/arm/kernel/phys2virt.S      | 238 ++++++++++++++++++++
 6 files changed, 364 insertions(+), 160 deletions(-)
 create mode 100644 arch/arm/kernel/phys2virt.S
Signature · 1 line
2.17.1