diff options
author | Christoffer Dall <christoffer.dall@linaro.org> | 2017-11-10 03:16:23 -0500 |
---|---|---|
committer | Christoffer Dall <christoffer.dall@linaro.org> | 2017-11-10 03:55:59 -0500 |
commit | 3d1ad640f8c94a9ae9c7c8bbb311614bc0332a7e (patch) | |
tree | 7ca1847dee2a945c4ad3a7e8935cdf8fd60b344b | |
parent | ed8703a506a8241f921feb63a656d0ff5a090895 (diff) |
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 <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
-rw-r--r-- | virt/kvm/arm/vgic/vgic-init.c | 8 | ||||
-rw-r--r-- | virt/kvm/arm/vgic/vgic-its.c | 2 | ||||
-rw-r--r-- | virt/kvm/arm/vgic/vgic-v4.c | 3 |
3 files changed, 7 insertions, 6 deletions
diff --git a/virt/kvm/arm/vgic/vgic-init.c b/virt/kvm/arm/vgic/vgic-init.c index 40be908da238..62310122ee78 100644 --- a/virt/kvm/arm/vgic/vgic-init.c +++ b/virt/kvm/arm/vgic/vgic-init.c | |||
@@ -285,11 +285,9 @@ int vgic_init(struct kvm *kvm) | |||
285 | if (ret) | 285 | if (ret) |
286 | goto out; | 286 | goto out; |
287 | 287 | ||
288 | if (vgic_supports_direct_msis(kvm)) { | 288 | ret = vgic_v4_init(kvm); |
289 | ret = vgic_v4_init(kvm); | 289 | if (ret) |
290 | if (ret) | 290 | goto out; |
291 | goto out; | ||
292 | } | ||
293 | 291 | ||
294 | kvm_for_each_vcpu(i, vcpu, kvm) | 292 | kvm_for_each_vcpu(i, vcpu, kvm) |
295 | kvm_vgic_vcpu_enable(vcpu); | 293 | kvm_vgic_vcpu_enable(vcpu); |
diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index b8c1b724ba3e..c93ecd4a903b 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c | |||
@@ -1673,7 +1673,7 @@ static int vgic_its_create(struct kvm_device *dev, u32 type) | |||
1673 | 1673 | ||
1674 | if (vgic_initialized(dev->kvm)) { | 1674 | if (vgic_initialized(dev->kvm)) { |
1675 | int ret = vgic_v4_init(dev->kvm); | 1675 | int ret = vgic_v4_init(dev->kvm); |
1676 | if (ret) { | 1676 | if (ret < 0) { |
1677 | kfree(its); | 1677 | kfree(its); |
1678 | return ret; | 1678 | return ret; |
1679 | } | 1679 | } |
diff --git a/virt/kvm/arm/vgic/vgic-v4.c b/virt/kvm/arm/vgic/vgic-v4.c index 915d09dc2638..53c324aa44ef 100644 --- a/virt/kvm/arm/vgic/vgic-v4.c +++ b/virt/kvm/arm/vgic/vgic-v4.c | |||
@@ -118,6 +118,9 @@ int vgic_v4_init(struct kvm *kvm) | |||
118 | struct kvm_vcpu *vcpu; | 118 | struct kvm_vcpu *vcpu; |
119 | int i, nr_vcpus, ret; | 119 | int i, nr_vcpus, ret; |
120 | 120 | ||
121 | if (!vgic_supports_direct_msis(kvm)) | ||
122 | return 0; /* Nothing to see here... move along. */ | ||
123 | |||
121 | if (dist->its_vm.vpes) | 124 | if (dist->its_vm.vpes) |
122 | return 0; | 125 | return 0; |
123 | 126 | ||