Skip to content

KVM: arm64: Handle the lack of GICv3 exposed to a guest

Marc Zyngier kvm kvmarm linux-arm-kernel 2 versions – Applied

Status from this message: Applied to next, thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest11 patches 4 repliesApplied
  2. v112 patches 13 repliesApplied

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/11KVM: arm64: Move GICv3 trap configuration to kvm_calculate_traps()arch/arm64/kvm/sys_regs.c arch/arm64/kvm/vgic/vgic-v3.c arch/arm64/kvm/vgic/vgic.h+12 -00 replies
2/11KVM: arm64: Force SRE traps when SRE access is not enabledarch/arm64/kvm/hyp/vgic-v3-sr.c arch/arm64/kvm/vgic/vgic-v3.c+20 -70 replies
3/11KVM: arm64: Force GICv3 trap activation when no irqchip is configured on VHEarch/arm64/kvm/vgic/vgic.c+10 -40 replies
4/11KVM: arm64: Add helper for last ditch idreg adjustmentsarch/arm64/kvm/arm.c arch/arm64/kvm/nested.c arch/arm64/kvm/sys_regs.c +1 more+37 -170 replies
5/11KVM: arm64: Zero ID_AA64PFR0_EL1.GIC when no GICv3 is presented to the guestarch/arm64/kvm/sys_regs.c arch/arm64/kvm/vgic/vgic.h+8 -42 replies
6/11KVM: arm64: Add ICH_HCR_EL2 to the vcpu statearch/arm64/include/asm/kvm_host.h arch/arm64/kvm/sys_regs.c+4 -00 replies
7/11KVM: arm64: Add trap routing information for ICH_HCR_EL2arch/arm64/kvm/emulate-nested.c+66 -50 replies
8/11KVM: arm64: Honor guest requested traps in GICv3 emulationarch/arm64/kvm/hyp/vgic-v3-sr.c+72 -00 replies
9/11KVM: arm64: Make most GICv3 accesses UNDEF if they traparch/arm64/kvm/hyp/vgic-v3-sr.c arch/arm64/kvm/sys_regs.c arch/arm64/kvm/sys_regs.h+66 -180 replies
10/11KVM: arm64: Unify UNDEF injection helpersarch/arm64/kvm/sys_regs.c+51 -810 replies
11/11KVM: arm64: Add selftest checking how the absence of GICv3 is handledtools/testing/selftests/kvm/Makefile tools/testing/selftests/kvm/aarch64/no-vgic-v3.c+176 -00 replies

Reviews trailers per patch

None of the 11 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchOliver Upton
SeriesR-b
1/11
2/11
3/11
4/11
5/11
6/11
7/11
8/11
9/11
10/11
11/11

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 00/11] KVM: arm64: Handle the lack of GICv3 exposed to a guest

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.

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-rc5, tested on the usual lot of terrible HW:
Synquacer, TX1 and M1.

* From v1 [1]:

- Drop the first patch of the series, as Oliver picked it up and

    ferried it into 6.11-rc5.

- Fixed a number of comments involving GICv2

- Rewrote kvm_has_gicv3() to look at the ID registers instead of the internal condition soup.

- Hacked more of the selftest so that we check that even when ICC_SRE_EL1 doesn't trap, it is still RAO/WI.

[1] https://lore.kernel.org/r/[email protected]

Marc Zyngier (11):
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 trap activation 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                          |  14 +-
 arch/arm64/kvm/emulate-nested.c               |  71 +++++-
 arch/arm64/kvm/hyp/vgic-v3-sr.c               |  97 ++++++-
 arch/arm64/kvm/nested.c                       |  15 +-
 arch/arm64/kvm/sys_regs.c                     | 240 ++++++++++--------
 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                    |   6 +-
 tools/testing/selftests/kvm/Makefile          |   1 +
 .../selftests/kvm/aarch64/no-vgic-v3.c        | 175 +++++++++++++
 12 files changed, 521 insertions(+), 135 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/aarch64/no-vgic-v3.c
Signature · 1 line
2.39.2