Skip to content

Commit 57e3ceb

Browse files
Shenming LuMarc Zyngier
authored andcommitted
KVM: arm64: Delay the polling of the GICR_VPENDBASER.Dirty bit
In order to reduce the impact of the VPT parsing happening on the GIC, we can split the vcpu reseidency in two phases: - programming GICR_VPENDBASER: this still happens in vcpu_load() - checking for the VPT parsing to be complete: this can happen on vcpu entry (in kvm_vgic_flush_hwstate()) This allows the GIC and the CPU to work in parallel, rewmoving some of the entry overhead. Suggested-by: Marc Zyngier <maz@kernel.org> Signed-off-by: Shenming Lu <lushenming@huawei.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20201128141857.983-3-lushenming@huawei.com
1 parent bf118a5 commit 57e3ceb

6 files changed

Lines changed: 47 additions & 4 deletions

File tree

‎arch/arm64/kvm/vgic/vgic-v4.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,18 @@ int vgic_v4_load(struct kvm_vcpu *vcpu)
353353
return err;
354354
}
355355

356+
void vgic_v4_commit(struct kvm_vcpu *vcpu)
357+
{
358+
struct its_vpe *vpe = &vcpu->arch.vgic_cpu.vgic_v3.its_vpe;
359+
360+
/*
361+
* No need to wait for the vPE to be ready across a shallow guest
362+
* exit, as only a vcpu_put will invalidate it.
363+
*/
364+
if (!vpe->ready)
365+
its_commit_vpe(vpe);
366+
}
367+
356368
static struct vgic_its *vgic_get_its(struct kvm *kvm,
357369
struct kvm_kernel_irq_routing_entry *irq_entry)
358370
{

‎arch/arm64/kvm/vgic/vgic.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,9 @@ void kvm_vgic_flush_hwstate(struct kvm_vcpu *vcpu)
915915

916916
if (can_access_vgic_from_kernel())
917917
vgic_restore_state(vcpu);
918+
919+
if (vgic_supports_direct_msis(vcpu->kvm))
920+
vgic_v4_commit(vcpu);
918921
}
919922

920923
void kvm_vgic_load(struct kvm_vcpu *vcpu)

‎drivers/irqchip/irq-gic-v3-its.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3842,8 +3842,6 @@ static void its_vpe_schedule(struct its_vpe *vpe)
38423842
val |= vpe->idai ? GICR_VPENDBASER_IDAI : 0;
38433843
val |= GICR_VPENDBASER_Valid;
38443844
gicr_write_vpendbaser(val, vlpi_base + GICR_VPENDBASER);
3845-
3846-
its_wait_vpt_parse_complete();
38473845
}
38483846

38493847
static void its_vpe_deschedule(struct its_vpe *vpe)
@@ -3891,6 +3889,10 @@ static int its_vpe_set_vcpu_affinity(struct irq_data *d, void *vcpu_info)
38913889
its_vpe_deschedule(vpe);
38923890
return 0;
38933891

3892+
case COMMIT_VPE:
3893+
its_wait_vpt_parse_complete();
3894+
return 0;
3895+
38943896
case INVALL_VPE:
38953897
its_vpe_invall(vpe);
38963898
return 0;
@@ -4052,8 +4054,6 @@ static void its_vpe_4_1_schedule(struct its_vpe *vpe,
40524054
val |= FIELD_PREP(GICR_VPENDBASER_4_1_VPEID, vpe->vpe_id);
40534055

40544056
gicr_write_vpendbaser(val, vlpi_base + GICR_VPENDBASER);
4055-
4056-
its_wait_vpt_parse_complete();
40574057
}
40584058

40594059
static void its_vpe_4_1_deschedule(struct its_vpe *vpe,
@@ -4128,6 +4128,10 @@ static int its_vpe_4_1_set_vcpu_affinity(struct irq_data *d, void *vcpu_info)
41284128
its_vpe_4_1_deschedule(vpe, info);
41294129
return 0;
41304130

4131+
case COMMIT_VPE:
4132+
its_wait_vpt_parse_complete();
4133+
return 0;
4134+
41314135
case INVALL_VPE:
41324136
its_vpe_4_1_invall(vpe);
41334137
return 0;

‎drivers/irqchip/irq-gic-v4.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ int its_make_vpe_non_resident(struct its_vpe *vpe, bool db)
232232
if (!ret)
233233
vpe->resident = false;
234234

235+
vpe->ready = false;
236+
235237
return ret;
236238
}
237239

@@ -258,6 +260,23 @@ int its_make_vpe_resident(struct its_vpe *vpe, bool g0en, bool g1en)
258260
return ret;
259261
}
260262

263+
int its_commit_vpe(struct its_vpe *vpe)
264+
{
265+
struct its_cmd_info info = {
266+
.cmd_type = COMMIT_VPE,
267+
};
268+
int ret;
269+
270+
WARN_ON(preemptible());
271+
272+
ret = its_send_vpe_cmd(vpe, &info);
273+
if (!ret)
274+
vpe->ready = true;
275+
276+
return ret;
277+
}
278+
279+
261280
int its_invall_vpe(struct its_vpe *vpe)
262281
{
263282
struct its_cmd_info info = {

‎include/kvm/arm_vgic.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ int kvm_vgic_v4_unset_forwarding(struct kvm *kvm, int irq,
402402
struct kvm_kernel_irq_routing_entry *irq_entry);
403403

404404
int vgic_v4_load(struct kvm_vcpu *vcpu);
405+
void vgic_v4_commit(struct kvm_vcpu *vcpu);
405406
int vgic_v4_put(struct kvm_vcpu *vcpu, bool need_db);
406407

407408
#endif /* __KVM_ARM_VGIC_H */

‎include/linux/irqchip/arm-gic-v4.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ struct its_vpe {
3939
irq_hw_number_t vpe_db_lpi;
4040
/* VPE resident */
4141
bool resident;
42+
/* VPT parse complete */
43+
bool ready;
4244
union {
4345
/* GICv4.0 implementations */
4446
struct {
@@ -104,6 +106,7 @@ enum its_vcpu_info_cmd_type {
104106
PROP_UPDATE_AND_INV_VLPI,
105107
SCHEDULE_VPE,
106108
DESCHEDULE_VPE,
109+
COMMIT_VPE,
107110
INVALL_VPE,
108111
PROP_UPDATE_VSGI,
109112
};
@@ -129,6 +132,7 @@ int its_alloc_vcpu_irqs(struct its_vm *vm);
129132
void its_free_vcpu_irqs(struct its_vm *vm);
130133
int its_make_vpe_resident(struct its_vpe *vpe, bool g0en, bool g1en);
131134
int its_make_vpe_non_resident(struct its_vpe *vpe, bool db);
135+
int its_commit_vpe(struct its_vpe *vpe);
132136
int its_invall_vpe(struct its_vpe *vpe);
133137
int its_map_vlpi(int irq, struct its_vlpi_map *map);
134138
int its_get_vlpi(int irq, struct its_vlpi_map *map);

0 commit comments

Comments
 (0)