linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/12] KVM: arm64: Handle the lack of GICv3 exposed to a guest
@ 2024-08-20 10:03 Marc Zyngier
  2024-08-20 10:03 ` [PATCH 01/12] KVM: arm64: Make ICC_*SGI*_EL1 undef in the absence of a vGICv3 Marc Zyngier
                   ` (11 more replies)
  0 siblings, 12 replies; 26+ messages in thread
From: Marc Zyngier @ 2024-08-20 10:03 UTC (permalink / raw)
  To: kvmarm, linux-arm-kernel, kvm
  Cc: James Morse, Suzuki K Poulose, Oliver Upton, Zenghui Yu,
	Alexander Potapenko

It recently appeared that, when running on a GICv3-equipped platform
(which is what non-ancient arm64 HW has), *not* configuring a GICv3
for the guest could result in less than desirable outcomes.

We have multiple issues to fix:

- for registers that *always* trap (the SGI registers) or that *may*
  trap (the SRE register), we need to check whether a GICv3 has been
  instantiated before acting upon the trap.

- for registers that only conditionally trap, we must actively trap
  them even in the absence of a GICv3 being instantiated, and handle
  those traps accordingly.

- finally, ID registers must reflect the absence of a GICv3, so that
  we are consistent.

This series goes through all these requirements. The main complexity
here is to apply a GICv3 configuration on the host in the absence of a
GICv3 in the guest. This is pretty hackish, but I don't have a much
better solution so far.

As part of making wider use of of the trap bits, we fully define the
trap routing as per the architecture, something that we eventually
need for NV anyway.

Note that patch #1 is a candidate for immediate merge in 6.11 as a
fix, to be backported to all stable versions. We can live without the
rest.

Finally, I have added two additional changes:

- a file-wide cleanup of sys_regs.c, unifying the way we inject an
  UNDEF from the trap handling array

- a selftest that checks for the implemented trapping behaviour (yes,
  I actually wrote a test -- hated every minute of it).

Note that the effects of this series when a GICv2 is configured on a
GICv3 host capable of emulation are imperfect: For some of the
registers, the guest may take a system register trap at EL1 (EC=0x18),
and there is nothing that KVM can do about it (this is a consequence
of ICC_SRE_EL1.SRE being 0, which GICv2 requires). But at least that's
a guest problem, not the host's.

PAtches on top of v6.11-rc4, tested on the usual lot of terrible HW:
Synquacer, TX1 and M1.

Marc Zyngier (12):
  KVM: arm64: Make ICC_*SGI*_EL1 undef in the absence of a vGICv3
  KVM: arm64: Move GICv3 trap configuration to kvm_calculate_traps()
  KVM: arm64: Force SRE traps when SRE access is not enabled
  KVM: arm64: Force GICv3 traps activa when no irqchip is configured on
    VHE
  KVM: arm64: Add helper for last ditch idreg adjustments
  KVM: arm64: Zero ID_AA64PFR0_EL1.GIC when no GICv3 is presented to the
    guest
  KVM: arm64: Add ICH_HCR_EL2 to the vcpu state
  KVM: arm64: Add trap routing information for ICH_HCR_EL2
  KVM: arm64: Honor guest requested traps in GICv3 emulation
  KVM: arm64: Make most GICv3 accesses UNDEF if they trap
  KVM: arm64: Unify UNDEF injection helpers
  KVM: arm64: Add selftest checking how the absence of GICv3 is handled

 arch/arm64/include/asm/kvm_host.h             |   2 +
 arch/arm64/kvm/arm.c                          |  10 +-
 arch/arm64/kvm/emulate-nested.c               |  77 +++++-
 arch/arm64/kvm/hyp/vgic-v3-sr.c               |  97 ++++++-
 arch/arm64/kvm/nested.c                       |  15 +-
 arch/arm64/kvm/sys_regs.c                     | 236 +++++++++++-------
 arch/arm64/kvm/sys_regs.h                     |   9 +
 arch/arm64/kvm/vgic/vgic-v3.c                 |  12 +
 arch/arm64/kvm/vgic/vgic.c                    |  14 +-
 arch/arm64/kvm/vgic/vgic.h                    |   9 +
 tools/testing/selftests/kvm/Makefile          |   1 +
 .../selftests/kvm/aarch64/no-vgic-v3.c        | 170 +++++++++++++
 12 files changed, 526 insertions(+), 126 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/aarch64/no-vgic-v3.c

-- 
2.39.2



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

end of thread, other threads:[~2024-08-22  8:17 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-20 10:03 [PATCH 00/12] KVM: arm64: Handle the lack of GICv3 exposed to a guest Marc Zyngier
2024-08-20 10:03 ` [PATCH 01/12] KVM: arm64: Make ICC_*SGI*_EL1 undef in the absence of a vGICv3 Marc Zyngier
2024-08-20 21:46   ` Oliver Upton
2024-08-21 10:59     ` Marc Zyngier
2024-08-21 16:53       ` Oliver Upton
2024-08-22  8:15   ` (subset) " Oliver Upton
2024-08-20 10:03 ` [PATCH 02/12] KVM: arm64: Move GICv3 trap configuration to kvm_calculate_traps() Marc Zyngier
2024-08-20 10:03 ` [PATCH 03/12] KVM: arm64: Force SRE traps when SRE access is not enabled Marc Zyngier
2024-08-20 23:19   ` Oliver Upton
2024-08-21 11:05     ` Marc Zyngier
2024-08-20 10:03 ` [PATCH 04/12] KVM: arm64: Force GICv3 traps activa when no irqchip is configured on VHE Marc Zyngier
2024-08-20 23:33   ` Oliver Upton
2024-08-21 11:13     ` Marc Zyngier
2024-08-21 16:52       ` Oliver Upton
2024-08-20 10:03 ` [PATCH 05/12] KVM: arm64: Add helper for last ditch idreg adjustments Marc Zyngier
2024-08-20 10:03 ` [PATCH 06/12] KVM: arm64: Zero ID_AA64PFR0_EL1.GIC when no GICv3 is presented to the guest Marc Zyngier
2024-08-20 23:50   ` Oliver Upton
2024-08-21 11:16     ` Marc Zyngier
2024-08-20 10:03 ` [PATCH 07/12] KVM: arm64: Add ICH_HCR_EL2 to the vcpu state Marc Zyngier
2024-08-20 10:03 ` [PATCH 08/12] KVM: arm64: Add trap routing information for ICH_HCR_EL2 Marc Zyngier
2024-08-20 10:03 ` [PATCH 09/12] KVM: arm64: Honor guest requested traps in GICv3 emulation Marc Zyngier
2024-08-20 10:03 ` [PATCH 10/12] KVM: arm64: Make most GICv3 accesses UNDEF if they trap Marc Zyngier
2024-08-20 10:03 ` [PATCH 11/12] KVM: arm64: Unify UNDEF injection helpers Marc Zyngier
2024-08-20 10:03 ` [PATCH 12/12] KVM: arm64: Add selftest checking how the absence of GICv3 is handled Marc Zyngier
2024-08-21  0:10   ` Oliver Upton
2024-08-21 11:17     ` Marc Zyngier

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).