Skip to content

riscv: Add remaining module relocations and tests

Charlie Jenkins linux-mm linux-riscv lkml 9 versions – Applied

Status from this message: This series was applied to riscv/linux.git (for-next)

Get series with b4
b4 am [email protected] change-id 20230908-module_relocations-f63ced651bd7

Versions newest first

  1. v9 Latest3 patches 0 repliesApplied 3/3
  2. v83 patches 2 repliesSuperseded
  3. v73 patches 5 repliesSuperseded
Earlier versions · 6
VersionPostedPatchesRepliesStatus
v63 patches0 repliesSuperseded
v53 patches0 repliesSuperseded
v42 patches13 repliesSuperseded
v32 patches4 repliesSuperseded
v22 patches0 repliesSuperseded
v12 patches0 repliesSuperseded

Changes in v9 from the cover letter

- Use uintptr_t where applicable (Emil)
- Split up insn_rmw changes into correct patch (Emil)
- Make reloc_handlers const and simplify struct (Emil)
- Link to v8: https://lore.kernel.org/r/[email protected]

Patches in v9 All 3 applied

#Subject and filesSizeRepliesApplied
1/3riscv: Avoid unaligned access when relocating modulesarch/riscv/kernel/module.c+81 -760 repliesApplied
2/3riscv: Add remaining module relocationsarch/riscv/include/uapi/asm/elf.h arch/riscv/kernel/module.c+423 -300 repliesApplied
3/3riscv: Add tests for riscv module loadingarch/riscv/Kconfig.debug arch/riscv/kernel/Makefile arch/riscv/kernel/tests/Kconfig.debug +13 more+366 -00 repliesApplied

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v9 yet.

Read the v9 thread

Cover letter [PATCH v9 0/3] riscv: Add remaining module relocations and tests

A handful of module relocations were missing, this patch includes the remaining ones. I also wrote some test cases to ensure that module loading works properly. Some relocations cannot be supported in the kernel, these include the ones that rely on thread local storage and dynamic linking.

This patch also overhauls the implementation of ADD/SUB/SET/ULEB128 relocations to handle overflow. "Overflow" is different for ULEB128 since it is a variable-length encoding that the compiler can be expected to generate enough space for. Instead of overflowing, ULEB128 will expand into the next 8-bit segment of the location.

A psABI proposal [1] was merged that mandates that SET_ULEB128 and SUB_ULEB128 are paired, however the discussion following the merging of the pull request revealed that while the pull request was valid, it would be better for linkers to properly handle this overflow. This patch proactively implements this methodology for future compatibility.

This can be tested by enabling KUNIT, RUNTIME_KERNEL_TESTING_MENU, and RISCV_MODULE_LINKING_KUNIT.

[1] https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/403

---
Changes in v9:
- Use uintptr_t where applicable (Emil)
- Split up insn_rmw changes into correct patch (Emil)
- Make reloc_handlers const and simplify struct (Emil)
- Link to v8: https://lore.kernel.org/r/[email protected]

Changes in v8:
- Fix up riscv_insn_rmw to work with big-endian systems (Andreas/Emil)
- Improve readability of bitops throughout module.c (Emil)
- Consolidate all relocation handler functions into a single struct so
array doesn't need to be duplicated 3 times
- Use .space assember op instead of .rept
- Fix up name of uleb128 testcase
- Define prototypes of some new functions to conform to -Wmissing-prototypes
- Remove unused variable "first"
- Link to v7: https://lore.kernel.org/r/[email protected]

Changes in v7:
- Overhaul ADD/SUB/SET/ULEB128 relocations
- Fix ULEB128 so it produces correct values when more than 1 byte is
needed
- Link to v6: https://lore.kernel.org/r/[email protected]

Changes in v6:
- Use (void *) instead of (u32 *) for handler type
- Constrain ULEB128 to be consecutive relocations
- Link to v5: https://lore.kernel.org/r/[email protected]

Changes in v5:
- Brought in patch by Emil and fixed it up to force little endian
- Fixed up issues with apply_r_riscv_32_pcrel_rela and
apply_r_riscv_plt32_rela (Samuel)
- Added u8 cast in apply_r_riscv_sub6_rela (Andreas)
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Complete removal of R_RISCV_RVC_LUI
- Fix bug in R_RISCV_SUB6 linking
- Only build ULEB128 tests if supported by toolchain
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Add prototypes to test_module_linking_main as recommended by intel
zero day bot
- Improve efficiency of ULEB128 pair matching
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Added ULEB128 relocations
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Charlie Jenkins (2):
riscv: Add remaining module relocations
riscv: Add tests for riscv module loading

Emil Renner Berthing (1):
riscv: Avoid unaligned access when relocating modules

 arch/riscv/Kconfig.debug                           |   1 +
 arch/riscv/include/uapi/asm/elf.h                  |   5 +-
 arch/riscv/kernel/Makefile                         |   1 +
 arch/riscv/kernel/module.c                         | 603 +++++++++++++++++----
 arch/riscv/kernel/tests/Kconfig.debug              |  35 ++
 arch/riscv/kernel/tests/Makefile                   |   1 +
 arch/riscv/kernel/tests/module_test/Makefile       |  15 +
 .../tests/module_test/test_module_linking_main.c   |  88 +++
 arch/riscv/kernel/tests/module_test/test_set16.S   |  23 +
 arch/riscv/kernel/tests/module_test/test_set32.S   |  20 +
 arch/riscv/kernel/tests/module_test/test_set6.S    |  23 +
 arch/riscv/kernel/tests/module_test/test_set8.S    |  23 +
 arch/riscv/kernel/tests/module_test/test_sub16.S   |  20 +
 arch/riscv/kernel/tests/module_test/test_sub32.S   |  20 +
 arch/riscv/kernel/tests/module_test/test_sub6.S    |  20 +
 arch/riscv/kernel/tests/module_test/test_sub64.S   |  25 +
 arch/riscv/kernel/tests/module_test/test_sub8.S    |  20 +
 arch/riscv/kernel/tests/module_test/test_uleb128.S |  31 ++
 18 files changed, 869 insertions(+), 105 deletions(-)

---
base-commit: 3bcce01fcbcd868b8cf3a5632fde283e122d7213
change-id: 20230908-module_relocations-f63ced651bd7

Signature · 1 line
- Charlie