Skip to content

irqchip/gic-v4, KVM: arm64: Fix the vgic init error paths

Fuad Tabba kvmarm linux-arm-kernel lkml 3 versions – Applied

Status from this message: Applied to fixes, thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest4 patches 5 repliesApplied
  2. v24 patches 4 repliesSuperseded
  3. v13 patches 4 repliesSuperseded

Patches in v3 Applied

#Subject and filesSizeRepliesApplied
1/4irqchip/gic-v4: Clear the domain and fwnode pointers after freeing themdrivers/irqchip/irq-gic-v4.c+16 -40 replies
2/4irqchip/gic-v4: Unwind what its_alloc_vcpu_irqs() allocated on failuredrivers/irqchip/irq-gic-v4.c+12 -20 replies
3/4KVM: arm64: vgic: Tear down what vgic_init() created when it failsarch/arm64/kvm/vgic/vgic-init.c+14 -70 replies
4/4KVM: arm64: vgic-v4: Restore nr_vpes before freeing the vPE resourcesarch/arm64/kvm/vgic/vgic-v4.c+3 -00 replies

Reviews trailers per patch

2 of 4 patches have a Reviewed-by or Acked-by.

PatchYuan Yao
1/4R-b
2/4R-b
3/4
4/4

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

Read the v3 thread

Cover letter [PATCH v3 0/4] irqchip/gic-v4, KVM: arm64: Fix the vgic init error paths

Hi folks,

Changes since v2 [1]:
- Patch 3: a vgic_v4_init() failure now frees only the SPI array, since that function unwinds its own state; the teardown label is for the routing failure. (Yuan Yao)
- Rebased on kvmarm/next, where the routing failure already tears down the GICv5 state. Patch 3 moves that into the shared label, so the SPI array is freed on that path too.
- Collected Reviewed-by from Yuan Yao on patches 1 and 2. (thanks!)

Four fixes on the paths that run when vgic init fails partway. Each one needs an allocation failure to reach.

Sashiko reported the vgic_init() case [2] while reviewing the SPI-array leak fix, and the two irq-gic-v4.c fixes came out of chasing the first [3]. Then, just when I thought I'd squashed every bug Sashiko could find, it turned up one more in its v1 review: the pre-existing nr_vpes one, fixed in patch 4 as Marc suggested [4].

Patch 1 clears the irq domain and fwnode pointers at the four GICv4 sites that free them and leave them set. Patch 2 makes its_alloc_vcpu_irqs() release what it allocated when the SGI loop fails, which is both the SGI domains and the vPE irqs, wider than the SGI-domain leak I described before posting v1 [3]. Patch 3 releases the SPI array and the vPEs on vgic_init()'s later failure paths, so KVM_DEV_ARM_VGIC_CTRL_INIT is all or nothing and a retry starts from scratch. Patch 4 is Marc's suggested fix [4] for the nr_vpes overload.

These patches run across two subsystems, but ordering matters, which is why this is one series. Patch 2 reuses its_free_sgi_irqs() from an error path, which only works once patch 1 has cleared the pointers. Patch 3 runs vgic_v4_teardown() on a path it never ran on before, which adds a route into what patch 1 fixes. Patch 4 is only correct on top of patch 3, which is what stops online_vcpus outgrowing the vPE array.

Based on kvmarm/next (23ddf997ab16b).

Cheers,
/fuad

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/CA+EHjTyDix+y6NTLTsXP5j9Sn2VLOZcsw94LntQxg_etRBJZuA@mail.gmail.com/
[4] https://lore.kernel.org/all/[email protected]/

Fuad Tabba (4):
irqchip/gic-v4: Clear the domain and fwnode pointers after freeing
them
irqchip/gic-v4: Unwind what its_alloc_vcpu_irqs() allocated on failure
KVM: arm64: vgic: Tear down what vgic_init() created when it fails
KVM: arm64: vgic-v4: Restore nr_vpes before freeing the vPE resources

 arch/arm64/kvm/vgic/vgic-init.c | 21 +++++++++++++-------
 arch/arm64/kvm/vgic/vgic-v4.c   |  3 +++
 drivers/irqchip/irq-gic-v4.c    | 34 +++++++++++++++++++++++++++------
 3 files changed, 45 insertions(+), 13 deletions(-)

base-commit: 23ddf997ab16b5f4aa9f948f5a68f5b35e4e398f

Signature · 1 line
2.39.5