Skip to content

Commit 3d1ad64

Browse files
committed
KVM: arm/arm64: Fix GICv4 ITS initialization issues
We should only try to initialize GICv4 data structures on a GICv4 capable system. Move the vgic_supports_direct_msis() check inito vgic_v4_init() so that any KVM VGIC initialization path does not fail on non-GICv4 systems. Also be slightly more strict in the checking of the return value in vgic_its_create, and only error out on negative return values from the vgic_v4_init() function. This is important because the kvm device code only treats negative values as errors and only cleans up in this case. Errornously treating a positive return value as an error from the vgic_v4_init() function can lead to NULL pointer dereferences, as has recently been observed. Acked-by: Marc Zyngier <[email protected]> Signed-off-by: Christoffer Dall <[email protected]>
1 parent ed8703a commit 3d1ad64

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

virt/kvm/arm/vgic/vgic-init.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,9 @@ int vgic_init(struct kvm *kvm)
285285
if (ret)
286286
goto out;
287287

288-
if (vgic_supports_direct_msis(kvm)) {
289-
ret = vgic_v4_init(kvm);
290-
if (ret)
291-
goto out;
292-
}
288+
ret = vgic_v4_init(kvm);
289+
if (ret)
290+
goto out;
293291

294292
kvm_for_each_vcpu(i, vcpu, kvm)
295293
kvm_vgic_vcpu_enable(vcpu);

virt/kvm/arm/vgic/vgic-its.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,7 @@ static int vgic_its_create(struct kvm_device *dev, u32 type)
16731673

16741674
if (vgic_initialized(dev->kvm)) {
16751675
int ret = vgic_v4_init(dev->kvm);
1676-
if (ret) {
1676+
if (ret < 0) {
16771677
kfree(its);
16781678
return ret;
16791679
}

virt/kvm/arm/vgic/vgic-v4.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ int vgic_v4_init(struct kvm *kvm)
118118
struct kvm_vcpu *vcpu;
119119
int i, nr_vcpus, ret;
120120

121+
if (!vgic_supports_direct_msis(kvm))
122+
return 0; /* Nothing to see here... move along. */
123+
121124
if (dist->its_vm.vpes)
122125
return 0;
123126

0 commit comments

Comments
 (0)