linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/11] KVM: arm64: Accelerate lookup of vcpus by MPIDR values (and other fixes)
@ 2023-09-20 18:17 Marc Zyngier
  2023-09-20 18:17 ` [PATCH v2 01/11] KVM: arm64: vgic: Make kvm_vgic_inject_irq() take a vcpu pointer Marc Zyngier
                   ` (12 more replies)
  0 siblings, 13 replies; 24+ messages in thread
From: Marc Zyngier @ 2023-09-20 18:17 UTC (permalink / raw)
  To: kvmarm, linux-arm-kernel, kvm
  Cc: James Morse, Suzuki K Poulose, Oliver Upton, Zenghui Yu,
	Joey Gouly, Shameerali Kolothum Thodi, Xu Zhao, Eric Auger

This is a follow-up on [1], which contains the original patches, only
augmented with a bunch of fixes after Zenghui pointed out that I was
inadvertently fixing bugs (yay!), but that there were plenty more.

The core of the issue is that we tend to confuse vcpu_id with
vcpu_idx. The first is a userspace-provided value, from which we
derive the default MPIDR_EL1 value, while the second is something that
used to represent the position in the vcpu array, and is now more of
an internal identifier.

To convince oneself that things are terminally broken, it is easy
enough to run a kvmtool guest with the following patchlet:

diff --git a/kvm-cpu.c b/kvm-cpu.c
index 1c566b3..520d759 100644
--- a/kvm-cpu.c
+++ b/kvm-cpu.c
@@ -287,7 +287,7 @@ int kvm_cpu__init(struct kvm *kvm)
                return -ENOMEM;
        }
 
-       for (i = 0; i < kvm->nrcpus; i++) {
+       for (i = kvm->nrcpus - 1; i >= 0; i--) {
                kvm->cpus[i] = kvm_cpu__arch_init(kvm, i);
                if (!kvm->cpus[i]) {
                        pr_err("unable to initialize KVM VCPU");

and witness that the resulting VM doesn't boot. The only combination
we support is to have vcpu_id == vcpu_idx. B0rken.

So this series, on top of trying to optimise SGI injection, also aims
at disambiguating this mess, and documenting some of the implicit
requirements for userspace.

With that, a VM created with vcpu upside down boots correctly.

* From v1 [1]:
  - Added a bunch of patches fixing the vcpu_id[x] ambiguity
  - Added a documentation update spelling out some extra ordering requirements
  - Collected RBs/TBs, with thanks

[1] https://lore.kernel.org/r/20230907100931.1186690-1-maz@kernel.org

Marc Zyngier (11):
  KVM: arm64: vgic: Make kvm_vgic_inject_irq() take a vcpu pointer
  KVM: arm64: vgic-its: Treat the collection target address as a vcpu_id
  KVM: arm64: vgic-v3: Refactor GICv3 SGI generation
  KVM: arm64: vgic-v2: Use cpuid from userspace as vcpu_id
  KVM: arm64: vgic: Use vcpu_idx for the debug information
  KVM: arm64: Use vcpu_idx for invalidation tracking
  KVM: arm64: Simplify kvm_vcpu_get_mpidr_aff()
  KVM: arm64: Build MPIDR to vcpu index cache at runtime
  KVM: arm64: Fast-track kvm_mpidr_to_vcpu() when mpidr_data is
    available
  KVM: arm64: vgic-v3: Optimize affinity-based SGI injection
  KVM: arm64: Clarify the ordering requirements for vcpu/RD creation

 .../virt/kvm/devices/arm-vgic-v3.rst          |   7 +
 arch/arm64/include/asm/kvm_emulate.h          |   2 +-
 arch/arm64/include/asm/kvm_host.h             |  28 ++++
 arch/arm64/kvm/arch_timer.c                   |   2 +-
 arch/arm64/kvm/arm.c                          |  90 +++++++++--
 arch/arm64/kvm/pmu-emul.c                     |   2 +-
 arch/arm64/kvm/vgic/vgic-debug.c              |   6 +-
 arch/arm64/kvm/vgic/vgic-irqfd.c              |   2 +-
 arch/arm64/kvm/vgic/vgic-its.c                |  21 ++-
 arch/arm64/kvm/vgic/vgic-kvm-device.c         |   2 +-
 arch/arm64/kvm/vgic/vgic-mmio-v3.c            | 142 +++++++-----------
 arch/arm64/kvm/vgic/vgic.c                    |  12 +-
 include/kvm/arm_vgic.h                        |   4 +-
 13 files changed, 195 insertions(+), 125 deletions(-)

-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2023-09-21 13:13 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-20 18:17 [PATCH v2 00/11] KVM: arm64: Accelerate lookup of vcpus by MPIDR values (and other fixes) Marc Zyngier
2023-09-20 18:17 ` [PATCH v2 01/11] KVM: arm64: vgic: Make kvm_vgic_inject_irq() take a vcpu pointer Marc Zyngier
2023-09-21  9:11   ` Zenghui Yu
2023-09-21 11:20     ` Marc Zyngier
2023-09-20 18:17 ` [PATCH v2 02/11] KVM: arm64: vgic-its: Treat the collection target address as a vcpu_id Marc Zyngier
2023-09-21  9:14   ` Zenghui Yu
2023-09-21 11:46     ` Marc Zyngier
2023-09-21 13:12       ` Zenghui Yu
2023-09-20 18:17 ` [PATCH v2 03/11] KVM: arm64: vgic-v3: Refactor GICv3 SGI generation Marc Zyngier
2023-09-21  9:42   ` Joey Gouly
2023-09-21 11:13     ` Marc Zyngier
2023-09-20 18:17 ` [PATCH v2 04/11] KVM: arm64: vgic-v2: Use cpuid from userspace as vcpu_id Marc Zyngier
2023-09-20 18:17 ` [PATCH v2 05/11] KVM: arm64: vgic: Use vcpu_idx for the debug information Marc Zyngier
2023-09-20 18:17 ` [PATCH v2 06/11] KVM: arm64: Use vcpu_idx for invalidation tracking Marc Zyngier
2023-09-21  9:16   ` Zenghui Yu
2023-09-21 12:58     ` Marc Zyngier
2023-09-20 18:17 ` [PATCH v2 07/11] KVM: arm64: Simplify kvm_vcpu_get_mpidr_aff() Marc Zyngier
2023-09-20 18:17 ` [PATCH v2 08/11] KVM: arm64: Build MPIDR to vcpu index cache at runtime Marc Zyngier
2023-09-20 18:17 ` [PATCH v2 09/11] KVM: arm64: Fast-track kvm_mpidr_to_vcpu() when mpidr_data is available Marc Zyngier
2023-09-20 18:17 ` [PATCH v2 10/11] KVM: arm64: vgic-v3: Optimize affinity-based SGI injection Marc Zyngier
2023-09-21  9:32   ` Zenghui Yu
2023-09-20 18:17 ` [PATCH v2 11/11] KVM: arm64: Clarify the ordering requirements for vcpu/RD creation Marc Zyngier
2023-09-21  2:11 ` [PATCH v2 00/11] KVM: arm64: Accelerate lookup of vcpus by MPIDR values (and other fixes) Oliver Upton
2023-09-21  9:39 ` Zenghui Yu

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