diff mbox series

[3/3] KVM: arm64: vgic-its: Clear ite when discard frees an ite

Message ID 20240620130650.1279-4-jiangkunkun@huawei.com (mailing list archive)
State New, archived
Headers show
Series KVM: arm64: vgic-its: Some fixes about vgic-its | expand

Commit Message

Kunkun Jiang June 20, 2024, 1:06 p.m. UTC
When discard frees an ite, we do not invalidate the
corresponding ite. In the scenario of continuous save and
restore, there may be a situation where an ite is not saved
but is restored. This is unreasonable and may cause restore
to fail. This patch clears the corresponding ite when discard
frees a ite.

Link: https://lore.kernel.org/kvmarm/8f9d74fc-f9d9-43ac-a387-91ff804cfaf1@redhat.com/
Signed-off-by: Kunkun Jiang <jiangkunkun@huawei.com>
---
 arch/arm64/kvm/vgic/vgic-its.c | 7 +++++++
 1 file changed, 7 insertions(+)
diff mbox series

Patch

diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c
index 8e11859ff803..a10516ff760a 100644
--- a/arch/arm64/kvm/vgic/vgic-its.c
+++ b/arch/arm64/kvm/vgic/vgic-its.c
@@ -782,6 +782,10 @@  static int vgic_its_cmd_handle_discard(struct kvm *kvm, struct vgic_its *its,
 
 	ite = find_ite(its, device_id, event_id);
 	if (ite && its_is_collection_mapped(ite->collection)) {
+		struct its_device *device = find_its_device(its, device_id);
+		int ite_esz = vgic_its_get_abi(its)->ite_esz;
+		gpa_t gpa = device->itt_addr + ite->event_id * ite_esz;
+		u64 val = 0;
 		/*
 		 * Though the spec talks about removing the pending state, we
 		 * don't bother here since we clear the ITTE anyway and the
@@ -790,6 +794,9 @@  static int vgic_its_cmd_handle_discard(struct kvm *kvm, struct vgic_its *its,
 		vgic_its_invalidate_cache(its);
 
 		its_free_ite(kvm, ite);
+
+		BUG_ON(ite_esz > sizeof(val));
+		vgic_write_guest_lock(kvm, gpa, &val, ite_esz);
 		return 0;
 	}