linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/9] KVM: arm64: Hypervisor stack enhancements
@ 2022-02-22 16:51 Kalesh Singh
  2022-02-22 16:51 ` [PATCH v2 1/9] KVM: arm64: Introduce hyp_alloc_private_va_range() Kalesh Singh
                   ` (8 more replies)
  0 siblings, 9 replies; 26+ messages in thread
From: Kalesh Singh @ 2022-02-22 16:51 UTC (permalink / raw)
  Cc: will, maz, qperret, tabba, surenb, kernel-team, Kalesh Singh,
	Catalin Marinas, James Morse, Alexandru Elisei, Suzuki K Poulose,
	Ard Biesheuvel, Mark Rutland, Pasha Tatashin, Joey Gouly,
	Peter Collingbourne, Andrew Scull, linux-arm-kernel,
	linux-kernel, kvmarm

Hi all,

This is v2 of the nVHE hypervisor stack enhancements. v1 can be found at:
https://lore.kernel.org/r/20220210224220.4076151-1-kaleshsingh@google.com/

This version has been updated to work for 'classic' KVM in nVHE mode in
addition to pKVM, per Marc; and rebased on 5.17-rc5.

The cover letter has been copied below for convenience.

Thanks,
Kalesh

-----

This series adds the following stack features to the KVM nVHE hypervisor:

== Hyp Stack Guard Pages ==

Based on the technique used by arm64 VMAP_STACK to detect overflow.
i.e. the stack is aligned to twice its size which ensure that the 
'stack shift' bit of any valid SP is 0. The 'stack shift' bit can be
tested in the exception entry to detect overflow without corrupting GPRs.

== Hyp Stack Unwinder ==

Based on the arm64 kernel stack unwinder
(See: arch/arm64/kernel/stacktrace.c)

The unwinding and dumping of the hyp stack is not enabled by default and
depends on CONFIG_NVHE_EL2_DEBUG to avoid potential information leaks.

When CONFIG_NVHE_EL2_DEBUG is enabled the host stage 2 protection is
disabled, allowing the host to read the hypervisor stack pages and unwind
the stack from EL1. This allows us to print the hypervisor stacktrace
before panicking the host; as shown below:

kvm [408]: nVHE hyp panic at: \
           [<ffffffc01161460c>] __kvm_nvhe_overflow_stack+0x10/0x34!
kvm [408]: nVHE HYP call trace:
kvm [408]: [<ffffffc011614974>] __kvm_nvhe_hyp_panic_bad_stack+0xc/0x10
kvm [408]: [<ffffffc01160fa48>] __kvm_nvhe___kvm_hyp_host_vector+0x248/0x794
kvm [408]: [<ffffffc01161461c>] __kvm_nvhe_overflow_stack+0x20/0x34
. . .
kvm [408]: [<ffffffc01161461c>] __kvm_nvhe_overflow_stack+0x20/0x34
kvm [408]: [<ffffffc01161421c>] __kvm_nvhe___kvm_vcpu_run+0x2c/0x40c
kvm [408]: [<ffffffc011615e14>] __kvm_nvhe_handle___kvm_vcpu_run+0x1c8/0x36c
kvm [408]: [<ffffffc0116157c4>] __kvm_nvhe_handle_trap+0xa4/0x124
kvm [408]: [<ffffffc01160f060>] __kvm_nvhe___host_exit+0x60/0x64
kvm [408]: ---- end of nVHE HYP call trace ----


Kalesh Singh (8):
  KVM: arm64: Introduce hyp_alloc_private_va_range()
  KVM: arm64: Introduce pkvm_alloc_private_va_range()
  KVM: arm64: Add guard pages for KVM nVHE hypervisor stack
  KVM: arm64: Add guard pages for pKVM (protected nVHE) hypervisor stack
  KVM: arm64: Detect and handle hypervisor stack overflows
  KVM: arm64: Add hypervisor overflow stack
  KVM: arm64: Unwind and dump nVHE HYP stacktrace
  KVM: arm64: Symbolize the nVHE HYP backtrace

Quentin Perret (1):
  arm64: asm: Introduce test_sp_overflow macro

 arch/arm64/include/asm/assembler.h   |  11 +
 arch/arm64/include/asm/kvm_asm.h     |  18 ++
 arch/arm64/include/asm/kvm_mmu.h     |   4 +
 arch/arm64/kernel/entry.S            |   7 +-
 arch/arm64/kvm/Kconfig               |   5 +-
 arch/arm64/kvm/Makefile              |   1 +
 arch/arm64/kvm/arm.c                 |  34 +++-
 arch/arm64/kvm/handle_exit.c         |  16 +-
 arch/arm64/kvm/hyp/include/nvhe/mm.h |   3 +-
 arch/arm64/kvm/hyp/nvhe/host.S       |  21 ++
 arch/arm64/kvm/hyp/nvhe/hyp-main.c   |   5 +-
 arch/arm64/kvm/hyp/nvhe/mm.c         |  49 +++--
 arch/arm64/kvm/hyp/nvhe/setup.c      |  25 ++-
 arch/arm64/kvm/hyp/nvhe/switch.c     |  29 +++
 arch/arm64/kvm/mmu.c                 |  61 ++++--
 arch/arm64/kvm/stacktrace.c          | 290 +++++++++++++++++++++++++++
 arch/arm64/kvm/stacktrace.h          |  17 ++
 scripts/kallsyms.c                   |   2 +-
 18 files changed, 533 insertions(+), 65 deletions(-)
 create mode 100644 arch/arm64/kvm/stacktrace.c
 create mode 100644 arch/arm64/kvm/stacktrace.h


base-commit: cfb92440ee71adcc2105b0890bb01ac3cddb8507
-- 
2.35.1.473.g83b2b277ed-goog


^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2022-02-25 15:38 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-22 16:51 [PATCH v2 0/9] KVM: arm64: Hypervisor stack enhancements Kalesh Singh
2022-02-22 16:51 ` [PATCH v2 1/9] KVM: arm64: Introduce hyp_alloc_private_va_range() Kalesh Singh
2022-02-22 18:53   ` Mark Rutland
2022-02-22 16:51 ` [PATCH v2 2/9] KVM: arm64: Introduce pkvm_alloc_private_va_range() Kalesh Singh
2022-02-22 16:51 ` [PATCH v2 3/9] KVM: arm64: Add guard pages for KVM nVHE hypervisor stack Kalesh Singh
2022-02-22 16:51 ` [PATCH v2 4/9] KVM: arm64: Add guard pages for pKVM (protected nVHE) " Kalesh Singh
2022-02-22 18:55   ` Mark Rutland
2022-02-22 20:30     ` Kalesh Singh
2022-02-22 16:51 ` [PATCH v2 5/9] arm64: asm: Introduce test_sp_overflow macro Kalesh Singh
2022-02-22 18:32   ` Mark Rutland
2022-02-22 20:20     ` Kalesh Singh
2022-02-22 16:51 ` [PATCH v2 6/9] KVM: arm64: Detect and handle hypervisor stack overflows Kalesh Singh
2022-02-23  2:04   ` kernel test robot
2022-02-23  9:05   ` kernel test robot
2022-02-23  9:16     ` Marc Zyngier
2022-02-23 12:34       ` [kbuild-all] " Philip Li
2022-02-23 12:54         ` Marc Zyngier
2022-02-23 12:56           ` Ard Biesheuvel
2022-02-24 10:39             ` Marc Zyngier
2022-02-25  2:12               ` Chen, Rong A
2022-02-25  3:11                 ` Kalesh Singh
2022-02-25 15:31                 ` Marc Zyngier
2022-02-25 15:38                 ` Ard Biesheuvel
2022-02-22 16:51 ` [PATCH v2 7/9] KVM: arm64: Add hypervisor overflow stack Kalesh Singh
2022-02-22 16:51 ` [PATCH v2 8/9] KVM: arm64: Unwind and dump nVHE HYP stacktrace Kalesh Singh
2022-02-22 16:51 ` [PATCH v2 9/9] KVM: arm64: Symbolize the nVHE HYP backtrace Kalesh Singh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).