]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.19/kvm-arm-arm64-vgic-always-initialize-the-group-of-pr.patch
Linux 4.14.108
[thirdparty/kernel/stable-queue.git] / queue-4.19 / kvm-arm-arm64-vgic-always-initialize-the-group-of-pr.patch
1 From ae4cdd17fd1e802bc55137d1e5f44086eeb914a9 Mon Sep 17 00:00:00 2001
2 From: Christoffer Dall <christoffer.dall@arm.com>
3 Date: Thu, 10 Jan 2019 15:33:52 +0100
4 Subject: KVM: arm/arm64: vgic: Always initialize the group of private IRQs
5
6 [ Upstream commit ab2d5eb03dbb7b37a1c6356686fb48626ab0c93e ]
7
8 We currently initialize the group of private IRQs during
9 kvm_vgic_vcpu_init, and the value of the group depends on the GIC model
10 we are emulating. However, CPUs created before creating (and
11 initializing) the VGIC might end up with the wrong group if the VGIC
12 is created as GICv3 later.
13
14 Since we have no enforced ordering of creating the VGIC and creating
15 VCPUs, we can end up with part the VCPUs being properly intialized and
16 the remaining incorrectly initialized. That also means that we have no
17 single place to do the per-cpu data structure initialization which
18 depends on knowing the emulated GIC model (which is only the group
19 field).
20
21 This patch removes the incorrect comment from kvm_vgic_vcpu_init and
22 initializes the group of all previously created VCPUs's private
23 interrupts in vgic_init in addition to the existing initialization in
24 kvm_vgic_vcpu_init.
25
26 Signed-off-by: Christoffer Dall <christoffer.dall@arm.com>
27 Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
28 Signed-off-by: Sasha Levin <sashal@kernel.org>
29 ---
30 virt/kvm/arm/vgic/vgic-init.c | 22 ++++++++++++++--------
31 1 file changed, 14 insertions(+), 8 deletions(-)
32
33 diff --git a/virt/kvm/arm/vgic/vgic-init.c b/virt/kvm/arm/vgic/vgic-init.c
34 index 33e7ee814f7b..8196e4f8731f 100644
35 --- a/virt/kvm/arm/vgic/vgic-init.c
36 +++ b/virt/kvm/arm/vgic/vgic-init.c
37 @@ -231,13 +231,6 @@ int kvm_vgic_vcpu_init(struct kvm_vcpu *vcpu)
38 irq->config = VGIC_CONFIG_LEVEL;
39 }
40
41 - /*
42 - * GICv3 can only be created via the KVM_DEVICE_CREATE API and
43 - * so we always know the emulation type at this point as it's
44 - * either explicitly configured as GICv3, or explicitly
45 - * configured as GICv2, or not configured yet which also
46 - * implies GICv2.
47 - */
48 if (dist->vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3)
49 irq->group = 1;
50 else
51 @@ -281,7 +274,7 @@ int vgic_init(struct kvm *kvm)
52 {
53 struct vgic_dist *dist = &kvm->arch.vgic;
54 struct kvm_vcpu *vcpu;
55 - int ret = 0, i;
56 + int ret = 0, i, idx;
57
58 if (vgic_initialized(kvm))
59 return 0;
60 @@ -298,6 +291,19 @@ int vgic_init(struct kvm *kvm)
61 if (ret)
62 goto out;
63
64 + /* Initialize groups on CPUs created before the VGIC type was known */
65 + kvm_for_each_vcpu(idx, vcpu, kvm) {
66 + struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic_cpu;
67 +
68 + for (i = 0; i < VGIC_NR_PRIVATE_IRQS; i++) {
69 + struct vgic_irq *irq = &vgic_cpu->private_irqs[i];
70 + if (dist->vgic_model == KVM_DEV_TYPE_ARM_VGIC_V3)
71 + irq->group = 1;
72 + else
73 + irq->group = 0;
74 + }
75 + }
76 +
77 if (vgic_has_its(kvm)) {
78 ret = vgic_v4_init(kvm);
79 if (ret)
80 --
81 2.19.1
82