Skip to content

arm64: Relocate absolute hyp VAs

David Brazdil kvmarm linux-arm-kernel lkml 2 versions – Applied

Status from this message: Applied to kvm-arm64/hyp-reloc, thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest8 patches 10 repliesApplied
  2. v19 patches 0 repliesSuperseded

Changes in v2 from the cover letter

* fix for older linkers: declare hyp section symbols in hyp-reloc.S
* fix for older host glibc: define R_AARCH64_ constants if missing
* add generated files to .gitignore

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/8KVM: arm64: Rename .idmap.text in hyp linker scriptarch/arm64/kvm/hyp/nvhe/hyp-init.S arch/arm64/kvm/hyp/nvhe/hyp.lds.S+2 -10 replies
2/8KVM: arm64: Set up .hyp.rodata ELF sectionarch/arm64/include/asm/sections.h arch/arm64/kernel/vmlinux.lds.S arch/arm64/kvm/arm.c +1 more+11 -90 replies
3/8KVM: arm64: Add symbol at the beginning of each hyp sectionarch/arm64/include/asm/hyp_image.h arch/arm64/kvm/hyp/nvhe/hyp.lds.S+29 -41 reply
4/8KVM: arm64: Generate hyp relocation dataarch/arm64/kernel/vmlinux.lds.S arch/arm64/kvm/hyp/nvhe/.gitignore arch/arm64/kvm/hyp/nvhe/Makefile +1 more+451 -37 replies
5/8KVM: arm64: Apply hyp relocations at runtimearch/arm64/include/asm/kvm_mmu.h arch/arm64/include/asm/sections.h arch/arm64/kernel/smp.c +1 more+33 -10 replies
6/8KVM: arm64: Fix constant-pool users in hyparch/arm64/include/asm/kvm_mmu.h arch/arm64/kvm/hyp/nvhe/host.S arch/arm64/kvm/hyp/nvhe/hyp-init.S+31 -420 replies
7/8KVM: arm64: Remove patching of fn pointers in hyparch/arm64/include/asm/kvm_mmu.h arch/arm64/kernel/image-vars.h arch/arm64/kvm/hyp/nvhe/hyp-main.c +1 more+4 -320 replies
8/8KVM: arm64: Remove hyp_symbol_addrarch/arm64/include/asm/kvm_asm.h arch/arm64/kvm/hyp/include/hyp/switch.h arch/arm64/kvm/hyp/nvhe/hyp-smp.c +2 more+17 -431 reply

Reviews trailers per patch

3 of 8 patches have a Reviewed-by or Acked-by.

PatchArd BiesheuvelGuenter RoeckDavid Brazdil
1/8
2/8
3/8
4/8T-b A-b
5/8
6/8
7/8A-b
8/8A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v2 thread

Cover letter [PATCH v2 0/8] arm64: Relocate absolute hyp VAs

nVHE hyp code is linked into the same kernel binary but executes under different memory mappings. If the compiler of hyp code chooses absolute addressing for accessing a symbol, the kernel linker will relocate that address to a kernel image virtual address, causing a runtime exception.

So far the strategy has been to force PC-relative addressing by wrapping all symbol references with the hyp_symbol_addr macro. This is error prone and developer unfriendly.

The series adds a new build-time step for nVHE hyp object file where positions targeted by R_AARCH64_ABS64 relocations are enumerated and the information stored in a separate ELF section in the kernel image. At runtime, the kernel first relocates all absolute addresses to their actual virtual offset (eg. for KASLR), and then addresses listed in this section are converted to hyp VAs.

The RFC of this series did not have a build-time step and instead relied on filtering dynamic relocations at runtime. That approach does not work if the kernel is built with !CONFIG_RELOCATABLE, hence an always-present set of relocation positions was added.

The series is based on 5.11-rc2 + kvmarm/next and structured as follows:
* patches 1-2 make sure that all sections referred to by hyp code are handled by the hyp linker script and prefixed with .hyp so they can be identified by the build-time tool
* patches 3-5 contain the actual changes to identify and relocate VAs
* patches 6-7 fix existing code that assumes kernel VAs
* patch 8 removes the (now redundant) hyp_symbol_addr

The series is also available at:
https://android-kvm.googlesource.com/linux topic/hyp-reloc_v2

Changes since v1:
* fix for older linkers: declare hyp section symbols in hyp-reloc.S
* fix for older host glibc: define R_AARCH64_ constants if missing
* add generated files to .gitignore

-David

David Brazdil (8):
KVM: arm64: Rename .idmap.text in hyp linker script
KVM: arm64: Set up .hyp.rodata ELF section
KVM: arm64: Add symbol at the beginning of each hyp section
KVM: arm64: Generate hyp relocation data
KVM: arm64: Apply hyp relocations at runtime
KVM: arm64: Fix constant-pool users in hyp
KVM: arm64: Remove patching of fn pointers in hyp
KVM: arm64: Remove hyp_symbol_addr

 arch/arm64/include/asm/hyp_image.h       |  29 +-
 arch/arm64/include/asm/kvm_asm.h         |  26 --
 arch/arm64/include/asm/kvm_mmu.h         |  61 +---
 arch/arm64/include/asm/sections.h        |   3 +-
 arch/arm64/kernel/image-vars.h           |   1 -
 arch/arm64/kernel/smp.c                  |   4 +-
 arch/arm64/kernel/vmlinux.lds.S          |  18 +-
 arch/arm64/kvm/arm.c                     |   7 +-
 arch/arm64/kvm/hyp/include/hyp/switch.h  |   4 +-
 arch/arm64/kvm/hyp/nvhe/.gitignore       |   2 +
 arch/arm64/kvm/hyp/nvhe/Makefile         |  28 +-
 arch/arm64/kvm/hyp/nvhe/gen-hyprel.c     | 413 +++++++++++++++++++++++
 arch/arm64/kvm/hyp/nvhe/host.S           |  29 +-
 arch/arm64/kvm/hyp/nvhe/hyp-init.S       |   4 +-
 arch/arm64/kvm/hyp/nvhe/hyp-main.c       |  11 +-
 arch/arm64/kvm/hyp/nvhe/hyp-smp.c        |   4 +-
 arch/arm64/kvm/hyp/nvhe/hyp.lds.S        |   9 +-
 arch/arm64/kvm/hyp/nvhe/psci-relay.c     |  24 +-
 arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c |   2 +-
 arch/arm64/kvm/va_layout.c               |  34 +-
 20 files changed, 578 insertions(+), 135 deletions(-)
 create mode 100644 arch/arm64/kvm/hyp/nvhe/gen-hyprel.c

--
2.29.2.729.g45daf8777d-goog
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm