mbox series

[v5,0/6] KVM: arm64: Emulate the OS Lock

Message ID 20220203174159.2887882-1-oupton@google.com (mailing list archive)
Headers show
Series KVM: arm64: Emulate the OS Lock | expand

Message

Oliver Upton Feb. 3, 2022, 5:41 p.m. UTC
KVM does not implement the debug architecture to the letter of the
specification. One such issue is the fact that KVM treats the OS Lock as
RAZ/WI, rather than emulating its behavior on hardware. This series adds
emulation support for the OS Lock to KVM. Emulation is warranted as the
OS Lock affects debug exceptions taken from all ELs, and is not limited
to only the context of the guest.

The 1st patch is a correctness fix for the OSLSR register, ensuring
the trap handler actually is written to suggest WO behavior. Note that
the changed code should never be reached on a correct implementation, as
hardware should generate the undef, not KVM.

The 2nd patch adds the necessary context to track guest values of the
OS Lock bit and exposes the value to userspace for the sake of
migration.

The 3rd patch makes the OSLK bit writable in OSLAR_EL1 (from the guest)
and OSLSR_EL1 (from userspace), but does nothing with its value.

The 4th patch actually implements the OS Lock behavior, disabling all
debug exceptions (except breakpoint instructions) from the perspective
of the guest. This is done by disabling MDE and SS in MDSCR_EL1.

The 5th patch asserts that OSLSR_EL1 is exposed by KVM to userspace
through the KVM_GET_REG_LIST ioctl. Lastly, the 6th patch asserts that
no debug exceptions are routed to the guest when the OSLK bit is set.

With this series a new register is exposed to userspace: OSLSR_EL1.
Since the register was not exposed to userspace before, changes to
register mutability do not have ABI breakage implications.

This series applies cleanly to 5.17-rc2. Tested on an Ampere Altra
machine with the included selftests patches.

Oliver Upton (6):
  KVM: arm64: Correctly treat writes to OSLSR_EL1 as undefined
  KVM: arm64: Stash OSLSR_EL1 in the cpu context
  KVM: arm64: Allow guest to set the OSLK bit
  KVM: arm64: Emulate the OS Lock
  selftests: KVM: Add OSLSR_EL1 to the list of blessed regs
  selftests: KVM: Test OS lock behavior

 arch/arm64/include/asm/kvm_host.h             |  5 ++
 arch/arm64/include/asm/sysreg.h               |  8 ++
 arch/arm64/kvm/debug.c                        | 26 ++++++-
 arch/arm64/kvm/sys_regs.c                     | 74 ++++++++++++++-----
 .../selftests/kvm/aarch64/debug-exceptions.c  | 58 ++++++++++++++-
 .../selftests/kvm/aarch64/get-reg-list.c      |  1 +
 6 files changed, 149 insertions(+), 23 deletions(-)

Comments

Marc Zyngier Feb. 8, 2022, 5:37 p.m. UTC | #1
On Thu, 3 Feb 2022 17:41:53 +0000, Oliver Upton wrote:
> KVM does not implement the debug architecture to the letter of the
> specification. One such issue is the fact that KVM treats the OS Lock as
> RAZ/WI, rather than emulating its behavior on hardware. This series adds
> emulation support for the OS Lock to KVM. Emulation is warranted as the
> OS Lock affects debug exceptions taken from all ELs, and is not limited
> to only the context of the guest.
> 
> [...]

Applied to next, thanks!

[1/6] KVM: arm64: Correctly treat writes to OSLSR_EL1 as undefined
      commit: e2ffceaae50883c5064641167078e5720fd8b74a
[2/6] KVM: arm64: Stash OSLSR_EL1 in the cpu context
      commit: d42e26716d038d9689a23c193b934cdf0e2a2117
[3/6] KVM: arm64: Allow guest to set the OSLK bit
      commit: f24adc65c5568a8d94e2693f5441de80f1ffe0d3
[4/6] KVM: arm64: Emulate the OS Lock
      commit: 7dabf02f43a1670d13282463fc0106f01dfd6f9c
[5/6] selftests: KVM: Add OSLSR_EL1 to the list of blessed regs
      commit: d134998838ac217a8427c1ddc83cf48888bb3fa3
[6/6] selftests: KVM: Test OS lock behavior
      commit: 05c9324de1695b5e61dceca6d2ef0ab8c0f2f26b

Cheers,

	M.