KVM: arm64: vgic-its: Update GITS_CTLR.Enabled under its_lock
Subsystems (3)
Fuad Tabba
reviewerPATCH v2 1/1 KVM: arm64: vgic-its: Update GITS_CTLR.Enabled under its_lock
A GITS_CTLR write that disables the ITS clears its->enabled and invalidates the translation cache under cmd_lock, while an MSI injection tests the enable bit and populates the cache under its_lock. An injection that passed the test before the disable can cache its translation after the invalidation, and the cached path then injects the LPI from the disabled ITS on every later MSI for that event.
Take its_lock around the store and the invalidation, so that it serializes the store against the test. Nest it under cmd_lock, as the command handlers do.
---
Notes:
Changes since v1 [1]:
- Reworded the commit message.
- Rebased on 7.4-rc1.
Picking up the fix Marc was worried had stalled [2].
The GICR_CTLR.EnableLPIs path has the same window and is left as is. vgic_its_invalidate_all_caches() can't take kvm->lock there (it runs with vcpu->mutex held) or config_lock (the userspace GICR_CTLR route already holds it). Instead, the vgic_target_oracle() check in my LPIs-disabled series [3] keeps an LPI off a redistributor with EnableLPIs clear. The two don't depend on each other.
vgic_its_free_collection_list() still leaves the cache alone. A guest reaches it only through a GITS_BASER write, which already drops the cache (8cd92f77ae4f). An ITS reset frees the devices first, which drops it too. That leaves a failed collection-table restore. A VMM gets there with translations cached only by enabling the ITS before the restore, against the documented order. Those translations then keep injecting their LPIs into the old target vCPUs.
Based on Linux 7.4-rc1 (6628e7d4c6b25; also applies to kvmarm/fixes 79f3724ca8913).
[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
arch/arm64/kvm/vgic/vgic-its.c | 3 +++ 1 file changed, 3 insertions(+)
arch/arm64/kvm/vgic/vgic-its.c +3 -0
@@ -1800,9 +1800,12 @@ static void vgic_mmio_write_its_ctlr(struct kvm *kvm, struct vgic_its *its, !(its->cbaser & GITS_CBASER_VALID))) goto out; +/* vgic_its_resolve_lpi() tests the enable bit and caches under its_lock. */ +mutex_lock (&its->its_lock); its->enabled = !!(val &GITS_CTLR_ENABLE );if (!its->enabled)vgic_its_invalidate_cache (its); +mutex_unlock (&its->its_lock);/* * Try to process any pending commands. This function bails out early
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
Signature · 1 line
2.47.3
Quoted 8 lines · Fuad Tabba
A
GITS_CTLRwrite that disables the ITS clearsits->enabledand invalidates the translation cache undercmd_lock, while an MSI injection tests the enable bit and populates the cache underits_lock. An injection that passed the test before the disable can cache its translation after the invalidation, and the cached path then injects the LPI from the disabled ITS on every later MSI for that event.[...]
Applied to fixes, thanks!
[1/1] KVM: arm64: vgic-its: Update GITS_CTLR.Enabled under its_lock
commit: 61d4f8c3d02cf936cfb91f7b72516b17febf74d3
Cheers,
M.
Signature · 1 line
Without deviation from the norm, progress is not possible.