mbox series

[v4,00/15] Split off nVHE hyp code

Message ID 20200625131420.71444-1-dbrazdil@google.com (mailing list archive)
Headers show
Series Split off nVHE hyp code | expand

Message

David Brazdil June 25, 2020, 1:14 p.m. UTC
Refactor files in arch/arm64/kvm/hyp to compile all code which runs in EL2
under nVHE into separate object files from the rest of KVM. This is done in
preparation for being able to unmap hyp code from EL1 and kernel code/data
from EL2 but has other benefits too, notably:
 * safe use of KASAN/UBSAN/GCOV instrumentation on VHE code,
 * no need for __hyp_text annotations.

nVHE-specific code is moved to hyp/nvhe and compiled with custom build rules
similar to those used by EFI stub. Shared source files are compiled under both
VHE and nVHE build rules. Where a source file contained both VHE and nVHE code,
it is split into a shared header file and two C source files. This is done one
file per commit to make review easier.

All nVHE symbols are prefixed with "__kvm_nvhe_" to avoid collisions with VHE
variants (also inspired by EFI stub). Since this prefixes unresolved symbols
too, image-vars.h contains a list of kernel symbol aliases where nVHE code
still refers to kernel proper. The list grows fairly large as the patch series
progresses and code is moved around, but at the end contains 20 symbols. These
remaining dependencies on kernel proper will be further reduced in the future.

No functional changes are intended but code was simplified whenever the
refactoring made it possible.

Tested by running kvm-unit-tests on QEMU 5.0 with VHE/nVHE and GIC v2/v3.

Dual compilation of code shared by VHE/nVHE increase the size of the kernel.
Bloat-o-meter vmlinux diff shows an increase of 21 KB on the ELF symbol level.
Size of Image.gz is up by 10 KB; size of Image is unchanged, presumably due
to ELF section alignment.

This is based off v5.8-rc2. Available in branch 'topic/el2-obj-v4' of git repo:
  https://android-kvm.googlesource.com/linux

Changes v3 -> v4:
 * rebase onto v5.8-rc2 (trivial)
 * add SYM_DATA_START/END around __smccc_workaround_1_smc
 * move VHE-specific source files into hyp/vhe
 * move headers shared by VHE/nVHE into hyp/include
 * define __KVM_VHE_HYPERVISOR__ for VHE-specific code
 * has_vhe() compile-time determinable when used in hyp/
 * KVM_NVHE_ALIAS macro in image-vars.h, comments throughout series
 * #define hyp symbols in kernel to magically select between VHE/nVHE variant
 * duplicate hyp/tlb.c instead of splitting it
 * pass idmap_t0sz to hyp-init as parameter to avoid symbol alias

Changes v2 -> v3:
 * rebase onto v5.8-rc1
 * remove patch changing hypcall interface to function IDs
 * move hyp-init.S to nVHE
 * fix symbol aliasing under CONFIG_ARM64_PSEUDO_NMI and CONFIG_ARM64_SVE
 * remove VHE's unused __kvm_enable_ssbs()
 * make nVHE use VHE's hyp_panic_string for consistent use of absolute relocs
   when returning pointers back to kernel
 * replace __noscs annotation (added to __hyp_text macro) with build rule

Changes v1 -> v2:
 * change nVHE symbol prefix from __hyp_text_ to __kvm_nvhe_
 * rename __HYPERVISOR__ macro to __KVM_NVHE_HYPERVISOR__
 * use hcall jump table instead of array of function pointers
 * drop patch to unify HVC callers
 * move __smccc_workaround_1_smc to own file
 * header guards for hyp/*.h
 * improve helpers for handling VHE/nVHE hyp syms in kernel proper
 * improve commit messages, cover letter

-David

Andrew Scull (2):
  arm64: kvm: Handle calls to prefixed hyp functions
  arm64: kvm: Move hyp-init.S to nVHE

David Brazdil (13):
  arm64: kvm: Fix symbol dependency in __hyp_call_panic_nvhe
  arm64: kvm: Move __smccc_workaround_1_smc to .rodata
  arm64: kvm: Add build rules for separate VHE/nVHE object files
  arm64: kvm: Use build-time defines in has_vhe()
  arm64: kvm: Build hyp-entry.S separately for VHE/nVHE
  arm64: kvm: Duplicate hyp/tlb.c for VHE/nVHE
  arm64: kvm: Split hyp/switch.c to VHE/nVHE
  arm64: kvm: Split hyp/debug-sr.c to VHE/nVHE
  arm64: kvm: Split hyp/sysreg-sr.c to VHE/nVHE
  arm64: kvm: Duplicate hyp/timer-sr.c for VHE/nVHE
  arm64: kvm: Compile remaining hyp/ files for both VHE/nVHE
  arm64: kvm: Remove __hyp_text macro, use build rules  instead
  arm64: kvm: Lift instrumentation restrictions on VHE

 arch/arm64/include/asm/kvm_asm.h              |  48 +-
 arch/arm64/include/asm/kvm_emulate.h          |   2 +-
 arch/arm64/include/asm/kvm_host.h             |  23 +-
 arch/arm64/include/asm/kvm_hyp.h              |  15 +-
 arch/arm64/include/asm/mmu.h                  |   7 -
 arch/arm64/include/asm/virt.h                 |  13 +-
 arch/arm64/kernel/image-vars.h                |  51 +
 arch/arm64/kvm/Makefile                       |   2 +-
 arch/arm64/kvm/arm.c                          |  18 +-
 arch/arm64/kvm/hyp/Makefile                   |  24 +-
 arch/arm64/kvm/hyp/aarch32.c                  |   6 +-
 arch/arm64/kvm/hyp/entry.S                    |   1 -
 arch/arm64/kvm/hyp/fpsimd.S                   |   1 -
 arch/arm64/kvm/hyp/hyp-entry.S                |  21 +-
 .../{debug-sr.c => include/hyp/debug-sr.h}    |  78 +-
 arch/arm64/kvm/hyp/include/hyp/switch.h       | 509 ++++++++++
 .../{sysreg-sr.c => include/hyp/sysreg-sr.h}  | 162 +--
 arch/arm64/kvm/hyp/nvhe/Makefile              |  42 +
 arch/arm64/kvm/hyp/nvhe/debug-sr.c            |  77 ++
 arch/arm64/kvm/{ => hyp/nvhe}/hyp-init.S      |  24 +-
 arch/arm64/kvm/hyp/nvhe/switch.c              | 272 +++++
 arch/arm64/kvm/hyp/nvhe/sysreg-sr.c           |  46 +
 arch/arm64/kvm/hyp/{ => nvhe}/timer-sr.c      |   6 +-
 arch/arm64/kvm/hyp/{ => nvhe}/tlb.c           | 100 +-
 arch/arm64/kvm/hyp/smccc_wa.S                 |  32 +
 arch/arm64/kvm/hyp/switch.c                   | 936 ------------------
 arch/arm64/kvm/hyp/vgic-v2-cpuif-proxy.c      |   4 +-
 arch/arm64/kvm/hyp/vgic-v3-sr.c               | 130 ++-
 arch/arm64/kvm/hyp/vhe/Makefile               |  11 +
 arch/arm64/kvm/hyp/vhe/debug-sr.c             |  26 +
 arch/arm64/kvm/hyp/vhe/switch.c               | 219 ++++
 arch/arm64/kvm/hyp/vhe/sysreg-sr.c            | 114 +++
 arch/arm64/kvm/hyp/vhe/timer-sr.c             |  12 +
 arch/arm64/kvm/hyp/vhe/tlb.c                  | 162 +++
 scripts/kallsyms.c                            |   1 +
 35 files changed, 1786 insertions(+), 1409 deletions(-)
 rename arch/arm64/kvm/hyp/{debug-sr.c => include/hyp/debug-sr.h} (71%)
 create mode 100644 arch/arm64/kvm/hyp/include/hyp/switch.h
 rename arch/arm64/kvm/hyp/{sysreg-sr.c => include/hyp/sysreg-sr.h} (56%)
 create mode 100644 arch/arm64/kvm/hyp/nvhe/Makefile
 create mode 100644 arch/arm64/kvm/hyp/nvhe/debug-sr.c
 rename arch/arm64/kvm/{ => hyp/nvhe}/hyp-init.S (91%)
 create mode 100644 arch/arm64/kvm/hyp/nvhe/switch.c
 create mode 100644 arch/arm64/kvm/hyp/nvhe/sysreg-sr.c
 rename arch/arm64/kvm/hyp/{ => nvhe}/timer-sr.c (84%)
 rename arch/arm64/kvm/hyp/{ => nvhe}/tlb.c (55%)
 create mode 100644 arch/arm64/kvm/hyp/smccc_wa.S
 delete mode 100644 arch/arm64/kvm/hyp/switch.c
 create mode 100644 arch/arm64/kvm/hyp/vhe/Makefile
 create mode 100644 arch/arm64/kvm/hyp/vhe/debug-sr.c
 create mode 100644 arch/arm64/kvm/hyp/vhe/switch.c
 create mode 100644 arch/arm64/kvm/hyp/vhe/sysreg-sr.c
 create mode 100644 arch/arm64/kvm/hyp/vhe/timer-sr.c
 create mode 100644 arch/arm64/kvm/hyp/vhe/tlb.c

Comments

Marc Zyngier July 5, 2020, 5:51 p.m. UTC | #1
On Thu, 25 Jun 2020 14:14:05 +0100, David Brazdil wrote:
> Refactor files in arch/arm64/kvm/hyp to compile all code which runs in EL2
> under nVHE into separate object files from the rest of KVM. This is done in
> preparation for being able to unmap hyp code from EL1 and kernel code/data
> from EL2 but has other benefits too, notably:
>  * safe use of KASAN/UBSAN/GCOV instrumentation on VHE code,
>  * no need for __hyp_text annotations.
> 
> [...]

Applied to kvm-arm64/next-5.9, thanks!

[01/15] KVM: arm64: Fix symbol dependency in __hyp_call_panic_nvhe
        commit: b38b298aa4397e2dc74a89b4dd3eac9e59b64c96
[02/15] KVM: arm64: Move __smccc_workaround_1_smc to .rodata
        commit: 7b2399ea5640b2e5f576af08b91091a26f240ea4
[03/15] KVM: arm64: Add build rules for separate VHE/nVHE object files
        commit: 7621712918ad4f5e6356193d9058debf657a6254
[04/15] KVM: arm64: Use build-time defines in has_vhe()
        commit: 53b671128bd7f9ea41ae1a06106d88eb4cf66623
[05/15] KVM: arm64: Handle calls to prefixed hyp functions
        commit: f50b6f6ae131b6ee7d5dd738961eda0c00b7f027
[06/15] KVM: arm64: Build hyp-entry.S separately for VHE/nVHE
        commit: b877e9849d41e7d2100d2933e0a3971d0ddec011
[07/15] KVM: arm64: Move hyp-init.S to nVHE
        commit: 208243c752a7eeef4236f7b7d67e806ee356e3f8
[08/15] KVM: arm64: Duplicate hyp/tlb.c for VHE/nVHE
        commit: e03fa29164ec1db1a81dc0168d0017a9e0366c7c
[09/15] KVM: arm64: Split hyp/switch.c to VHE/nVHE
        commit: 09cf57eba304246141367b95c89801fd2047ac96
[10/15] KVM: arm64: Split hyp/debug-sr.c to VHE/nVHE
        commit: d400c5b2025c9aeca76213d6bd4138ec39da5cef
[11/15] KVM: arm64: Split hyp/sysreg-sr.c to VHE/nVHE
        commit: 13aeb9b400c5d7c5e979fdbbf994c787487f7889
[12/15] KVM: arm64: Duplicate hyp/timer-sr.c for VHE/nVHE
        commit: 9aebdea494b5d2d5fe0ba54d71e9d6c5acfe76b4
[13/15] KVM: arm64: Compile remaining hyp/ files for both VHE/nVHE
        commit: c04dd455eb311d2d289c9d81d080eaf11a06cebf
[14/15] KVM: arm64: Remove __hyp_text macro, use build rules instead
        commit: c50cb04303cb88c517715b078e3e010c024af1a5
[15/15] KVM: arm64: Lift instrumentation restrictions on VHE
        commit: f9a026e3d38ba81cd274725f1caaf64322a86aa5

Cheers,

	M.