Skip to content

Commit a23eaf9

Browse files
Gavin ShanMarc Zyngier
authored andcommitted
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 <[email protected]> Signed-off-by: Gavin Shan <[email protected]> Reviewed-by: Oliver Upton <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent ef36916 commit a23eaf9

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

arch/arm64/kvm/vgic/vgic-its.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2187,7 +2187,7 @@ static int vgic_its_save_ite(struct vgic_its *its, struct its_device *dev,
21872187
((u64)ite->irq->intid << KVM_ITS_ITE_PINTID_SHIFT) |
21882188
ite->collection->collection_id;
21892189
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);
21912191
}
21922192

21932193
/**
@@ -2339,7 +2339,7 @@ static int vgic_its_save_dte(struct vgic_its *its, struct its_device *dev,
23392339
(itt_addr_field << KVM_ITS_DTE_ITTADDR_SHIFT) |
23402340
(dev->num_eventid_bits - 1));
23412341
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);
23432343
}
23442344

23452345
/**
@@ -2526,7 +2526,7 @@ static int vgic_its_save_cte(struct vgic_its *its,
25262526
((u64)collection->target_addr << KVM_ITS_CTE_RDBASE_SHIFT) |
25272527
collection->collection_id);
25282528
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);
25302530
}
25312531

25322532
/*
@@ -2607,7 +2607,7 @@ static int vgic_its_save_collection_table(struct vgic_its *its)
26072607
*/
26082608
val = 0;
26092609
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);
26112611
return ret;
26122612
}
26132613

@@ -2743,7 +2743,6 @@ static int vgic_its_has_attr(struct kvm_device *dev,
27432743
static int vgic_its_ctrl(struct kvm *kvm, struct vgic_its *its, u64 attr)
27442744
{
27452745
const struct vgic_its_abi *abi = vgic_its_get_abi(its);
2746-
struct vgic_dist *dist = &kvm->arch.vgic;
27472746
int ret = 0;
27482747

27492748
if (attr == KVM_DEV_ARM_VGIC_CTRL_INIT) /* Nothing to do */
@@ -2763,9 +2762,7 @@ static int vgic_its_ctrl(struct kvm *kvm, struct vgic_its *its, u64 attr)
27632762
vgic_its_reset(kvm, its);
27642763
break;
27652764
case KVM_DEV_ARM_ITS_SAVE_TABLES:
2766-
dist->save_its_tables_in_progress = true;
27672765
ret = abi->save_tables(its);
2768-
dist->save_its_tables_in_progress = false;
27692766
break;
27702767
case KVM_DEV_ARM_ITS_RESTORE_TABLES:
27712768
ret = abi->restore_tables(its);
@@ -2792,7 +2789,7 @@ bool kvm_arch_allow_write_without_running_vcpu(struct kvm *kvm)
27922789
{
27932790
struct vgic_dist *dist = &kvm->arch.vgic;
27942791

2795-
return dist->save_its_tables_in_progress;
2792+
return dist->table_write_in_progress;
27962793
}
27972794

27982795
static int vgic_its_set_attr(struct kvm_device *dev,

arch/arm64/kvm/vgic/vgic.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define __KVM_ARM_VGIC_NEW_H__
77

88
#include <linux/irqchip/arm-gic-common.h>
9+
#include <asm/kvm_mmu.h>
910

1011
#define PRODUCT_ID_KVM 0x4b /* ASCII code K */
1112
#define IMPLEMENTER_ARM 0x43b
@@ -131,6 +132,19 @@ static inline bool vgic_irq_is_multi_sgi(struct vgic_irq *irq)
131132
return vgic_irq_get_lr_count(irq) > 1;
132133
}
133134

135+
static inline int vgic_write_guest_lock(struct kvm *kvm, gpa_t gpa,
136+
const void *data, unsigned long len)
137+
{
138+
struct vgic_dist *dist = &kvm->arch.vgic;
139+
int ret;
140+
141+
dist->table_write_in_progress = true;
142+
ret = kvm_write_guest_lock(kvm, gpa, data, len);
143+
dist->table_write_in_progress = false;
144+
145+
return ret;
146+
}
147+
134148
/*
135149
* This struct provides an intermediate representation of the fields contained
136150
* in the GICH_VMCR and ICH_VMCR registers, such that code exporting the GIC

include/kvm/arm_vgic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ struct vgic_dist {
263263
struct vgic_io_device dist_iodev;
264264

265265
bool has_its;
266-
bool save_its_tables_in_progress;
266+
bool table_write_in_progress;
267267

268268
/*
269269
* Contains the attributes and gpa of the LPI configuration table.

0 commit comments

Comments
 (0)