Skip to content

Commit bb5ed70

Browse files
chazyMarc Zyngier
authored andcommitted
KVM: arm/arm64: Get rid of vgic_elrsr
There is really no need to store the vgic_elrsr on the VGIC data structures as the only need we have for the elrsr is to figure out if an LR is inactive when we save the VGIC state upon returning from the guest. We can might as well store this in a temporary local variable. Reviewed-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
1 parent b7787e6 commit bb5ed70

5 files changed

Lines changed: 10 additions & 28 deletions

File tree

‎include/kvm/arm_vgic.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,6 @@ struct vgic_dist {
263263
struct vgic_v2_cpu_if {
264264
u32 vgic_hcr;
265265
u32 vgic_vmcr;
266-
u64 vgic_elrsr; /* Saved only */
267266
u32 vgic_apr;
268267
u32 vgic_lr[VGIC_V2_MAX_LRS];
269268
};
@@ -272,7 +271,6 @@ struct vgic_v3_cpu_if {
272271
u32 vgic_hcr;
273272
u32 vgic_vmcr;
274273
u32 vgic_sre; /* Restored only, change ignored */
275-
u32 vgic_elrsr; /* Saved only */
276274
u32 vgic_ap0r[4];
277275
u32 vgic_ap1r[4];
278276
u64 vgic_lr[VGIC_V3_MAX_LRS];

‎virt/kvm/arm/hyp/vgic-v2-sr.c‎

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,19 @@
2323
#include <asm/kvm_hyp.h>
2424
#include <asm/kvm_mmu.h>
2525

26-
static void __hyp_text save_elrsr(struct kvm_vcpu *vcpu, void __iomem *base)
27-
{
28-
struct vgic_v2_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v2;
29-
int nr_lr = (kern_hyp_va(&kvm_vgic_global_state))->nr_lr;
30-
u32 elrsr0, elrsr1;
31-
32-
elrsr0 = readl_relaxed(base + GICH_ELRSR0);
33-
if (unlikely(nr_lr > 32))
34-
elrsr1 = readl_relaxed(base + GICH_ELRSR1);
35-
else
36-
elrsr1 = 0;
37-
38-
cpu_if->vgic_elrsr = ((u64)elrsr1 << 32) | elrsr0;
39-
}
40-
4126
static void __hyp_text save_lrs(struct kvm_vcpu *vcpu, void __iomem *base)
4227
{
4328
struct vgic_v2_cpu_if *cpu_if = &vcpu->arch.vgic_cpu.vgic_v2;
44-
int i;
4529
u64 used_lrs = vcpu->arch.vgic_cpu.used_lrs;
30+
u64 elrsr;
31+
int i;
32+
33+
elrsr = readl_relaxed(base + GICH_ELRSR0);
34+
if (unlikely(used_lrs > 32))
35+
elrsr |= ((u64)readl_relaxed(base + GICH_ELRSR1)) << 32;
4636

4737
for (i = 0; i < used_lrs; i++) {
48-
if (cpu_if->vgic_elrsr & (1UL << i))
38+
if (elrsr & (1UL << i))
4939
cpu_if->vgic_lr[i] &= ~GICH_LR_STATE;
5040
else
5141
cpu_if->vgic_lr[i] = readl_relaxed(base + GICH_LR0 + (i * 4));
@@ -68,13 +58,9 @@ void __hyp_text __vgic_v2_save_state(struct kvm_vcpu *vcpu)
6858

6959
if (used_lrs) {
7060
cpu_if->vgic_apr = readl_relaxed(base + GICH_APR);
71-
72-
save_elrsr(vcpu, base);
7361
save_lrs(vcpu, base);
74-
7562
writel_relaxed(0, base + GICH_HCR);
7663
} else {
77-
cpu_if->vgic_elrsr = ~0UL;
7864
cpu_if->vgic_apr = 0;
7965
}
8066
}

‎virt/kvm/arm/hyp/vgic-v3-sr.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,16 @@ void __hyp_text __vgic_v3_save_state(struct kvm_vcpu *vcpu)
222222
if (used_lrs) {
223223
int i;
224224
u32 nr_pre_bits;
225+
u32 elrsr;
225226

226-
cpu_if->vgic_elrsr = read_gicreg(ICH_ELSR_EL2);
227+
elrsr = read_gicreg(ICH_ELSR_EL2);
227228

228229
write_gicreg(0, ICH_HCR_EL2);
229230
val = read_gicreg(ICH_VTR_EL2);
230231
nr_pre_bits = vtr_to_nr_pre_bits(val);
231232

232233
for (i = 0; i < used_lrs; i++) {
233-
if (cpu_if->vgic_elrsr & (1 << i))
234+
if (elrsr & (1 << i))
234235
cpu_if->vgic_lr[i] &= ~ICH_LR_STATE;
235236
else
236237
cpu_if->vgic_lr[i] = __gic_v3_get_lr(i);
@@ -262,7 +263,6 @@ void __hyp_text __vgic_v3_save_state(struct kvm_vcpu *vcpu)
262263
cpu_if->its_vpe.its_vm)
263264
write_gicreg(0, ICH_HCR_EL2);
264265

265-
cpu_if->vgic_elrsr = 0xffff;
266266
cpu_if->vgic_ap0r[0] = 0;
267267
cpu_if->vgic_ap0r[1] = 0;
268268
cpu_if->vgic_ap0r[2] = 0;

‎virt/kvm/arm/vgic/vgic-v2.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ void vgic_v2_enable(struct kvm_vcpu *vcpu)
265265
* anyway.
266266
*/
267267
vcpu->arch.vgic_cpu.vgic_v2.vgic_vmcr = 0;
268-
vcpu->arch.vgic_cpu.vgic_v2.vgic_elrsr = ~0;
269268

270269
/* Get the show on the road... */
271270
vcpu->arch.vgic_cpu.vgic_v2.vgic_hcr = GICH_HCR_EN;

‎virt/kvm/arm/vgic/vgic-v3.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ void vgic_v3_enable(struct kvm_vcpu *vcpu)
267267
* anyway.
268268
*/
269269
vgic_v3->vgic_vmcr = 0;
270-
vgic_v3->vgic_elrsr = ~0;
271270

272271
/*
273272
* If we are emulating a GICv3, we do it in an non-GICv2-compatible

0 commit comments

Comments
 (0)