[PATCH 0/9] KVM: arm64: Relocate absolute hyp VAs
From: David Brazdil
Date: Wed Dec 09 2020 - 08:18:39 EST
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 the current kvmarm/next (commit 3a514592b6) and
structured as follows:
* patch 1 is Jamie's fix of .hyp.data..percpu alignment; already in
master, not yet in kvmarm/next; included to avoid merge conflicts
* patches 2-3 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 4-6 contain the actual changes to identify and relocate VAs
* patches 7-8 fix existing code that assumes kernel VAs
* patch 9 removes the (now redundant) hyp_symbol_addr
The series is also available at:
https://android-kvm.googlesource.com/linux topic/hyp-reloc_v1
-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
Jamie Iles (1):
KVM: arm64: Correctly align nVHE percpu data
arch/arm64/configs/defconfig | 1 +
arch/arm64/include/asm/hyp_image.h | 29 +-
arch/arm64/include/asm/kvm_asm.h | 20 --
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/Makefile | 28 +-
arch/arm64/kvm/hyp/nvhe/gen-hyprel.c | 326 +++++++++++++++++++++++
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 | 14 +-
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, 495 insertions(+), 129 deletions(-)
create mode 100644 arch/arm64/kvm/hyp/nvhe/gen-hyprel.c
--
2.29.2.576.ga3fc446d84-goog