Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: arm64: Add helper vgic_write_guest_lock()

Currently, the unknown no-running-vcpu sites are reported when a
dirty page is tracked by mark_page_dirty_in_slot(). Until now, the
only known no-running-vcpu site is saving vgic/its tables through
KVM_DEV_ARM_{VGIC_GRP_CTRL, ITS_SAVE_TABLES} command on KVM device
"kvm-arm-vgic-its". Unfortunately, there are more unknown sites to
be handled and no-running-vcpu context will be allowed in these
sites: (1) KVM_DEV_ARM_{VGIC_GRP_CTRL, ITS_RESTORE_TABLES} command
on KVM device "kvm-arm-vgic-its" to restore vgic/its tables. The
vgic3 LPI pending status could be restored. (2) Save vgic3 pending
table through KVM_DEV_ARM_{VGIC_GRP_CTRL, VGIC_SAVE_PENDING_TABLES}
command on KVM device "kvm-arm-vgic-v3".

In order to handle those unknown cases, we need a unified helper
vgic_write_guest_lock(). struct vgic_dist::save_its_tables_in_progress
is also renamed to struct vgic_dist::save_tables_in_progress.

No functional change intended.

Suggested-by: Oliver Upton <oliver.upton@linux.dev>
Signed-off-by: Gavin Shan <gshan@redhat.com>
Reviewed-by: Oliver Upton <oliver.upton@linux.dev>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20230126235451.469087-3-gshan@redhat.com

authored by

Gavin Shan and committed by
Marc Zyngier
a23eaf93 ef369168

+20 -9
+5 -8
arch/arm64/kvm/vgic/vgic-its.c
··· 2187 2187 ((u64)ite->irq->intid << KVM_ITS_ITE_PINTID_SHIFT) | 2188 2188 ite->collection->collection_id; 2189 2189 val = cpu_to_le64(val); 2190 - return kvm_write_guest_lock(kvm, gpa, &val, ite_esz); 2190 + return vgic_write_guest_lock(kvm, gpa, &val, ite_esz); 2191 2191 } 2192 2192 2193 2193 /** ··· 2339 2339 (itt_addr_field << KVM_ITS_DTE_ITTADDR_SHIFT) | 2340 2340 (dev->num_eventid_bits - 1)); 2341 2341 val = cpu_to_le64(val); 2342 - return kvm_write_guest_lock(kvm, ptr, &val, dte_esz); 2342 + return vgic_write_guest_lock(kvm, ptr, &val, dte_esz); 2343 2343 } 2344 2344 2345 2345 /** ··· 2526 2526 ((u64)collection->target_addr << KVM_ITS_CTE_RDBASE_SHIFT) | 2527 2527 collection->collection_id); 2528 2528 val = cpu_to_le64(val); 2529 - return kvm_write_guest_lock(its->dev->kvm, gpa, &val, esz); 2529 + return vgic_write_guest_lock(its->dev->kvm, gpa, &val, esz); 2530 2530 } 2531 2531 2532 2532 /* ··· 2607 2607 */ 2608 2608 val = 0; 2609 2609 BUG_ON(cte_esz > sizeof(val)); 2610 - ret = kvm_write_guest_lock(its->dev->kvm, gpa, &val, cte_esz); 2610 + ret = vgic_write_guest_lock(its->dev->kvm, gpa, &val, cte_esz); 2611 2611 return ret; 2612 2612 } 2613 2613 ··· 2743 2743 static int vgic_its_ctrl(struct kvm *kvm, struct vgic_its *its, u64 attr) 2744 2744 { 2745 2745 const struct vgic_its_abi *abi = vgic_its_get_abi(its); 2746 - struct vgic_dist *dist = &kvm->arch.vgic; 2747 2746 int ret = 0; 2748 2747 2749 2748 if (attr == KVM_DEV_ARM_VGIC_CTRL_INIT) /* Nothing to do */ ··· 2762 2763 vgic_its_reset(kvm, its); 2763 2764 break; 2764 2765 case KVM_DEV_ARM_ITS_SAVE_TABLES: 2765 - dist->save_its_tables_in_progress = true; 2766 2766 ret = abi->save_tables(its); 2767 - dist->save_its_tables_in_progress = false; 2768 2767 break; 2769 2768 case KVM_DEV_ARM_ITS_RESTORE_TABLES: 2770 2769 ret = abi->restore_tables(its); ··· 2789 2792 { 2790 2793 struct vgic_dist *dist = &kvm->arch.vgic; 2791 2794 2792 - return dist->save_its_tables_in_progress; 2795 + return dist->table_write_in_progress; 2793 2796 } 2794 2797 2795 2798 static int vgic_its_set_attr(struct kvm_device *dev,
+14
arch/arm64/kvm/vgic/vgic.h
··· 6 6 #define __KVM_ARM_VGIC_NEW_H__ 7 7 8 8 #include <linux/irqchip/arm-gic-common.h> 9 + #include <asm/kvm_mmu.h> 9 10 10 11 #define PRODUCT_ID_KVM 0x4b /* ASCII code K */ 11 12 #define IMPLEMENTER_ARM 0x43b ··· 130 129 static inline bool vgic_irq_is_multi_sgi(struct vgic_irq *irq) 131 130 { 132 131 return vgic_irq_get_lr_count(irq) > 1; 132 + } 133 + 134 + static inline int vgic_write_guest_lock(struct kvm *kvm, gpa_t gpa, 135 + const void *data, unsigned long len) 136 + { 137 + struct vgic_dist *dist = &kvm->arch.vgic; 138 + int ret; 139 + 140 + dist->table_write_in_progress = true; 141 + ret = kvm_write_guest_lock(kvm, gpa, data, len); 142 + dist->table_write_in_progress = false; 143 + 144 + return ret; 133 145 } 134 146 135 147 /*
+1 -1
include/kvm/arm_vgic.h
··· 263 263 struct vgic_io_device dist_iodev; 264 264 265 265 bool has_its; 266 - bool save_its_tables_in_progress; 266 + bool table_write_in_progress; 267 267 268 268 /* 269 269 * Contains the attributes and gpa of the LPI configuration table.