]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.4.177/kvm-arm-arm64-fix-mmio-emulation-data-handling.patch
Linux 4.4.177
[thirdparty/kernel/stable-queue.git] / releases / 4.4.177 / kvm-arm-arm64-fix-mmio-emulation-data-handling.patch
1 From 83091db981e105d97562d3ed3ffe676e21927e3a Mon Sep 17 00:00:00 2001
2 From: Christoffer Dall <christoffer.dall@linaro.org>
3 Date: Tue, 29 Mar 2016 14:29:28 +0200
4 Subject: KVM: arm/arm64: Fix MMIO emulation data handling
5
6 From: Christoffer Dall <christoffer.dall@linaro.org>
7
8 commit 83091db981e105d97562d3ed3ffe676e21927e3a upstream.
9
10 When the kernel was handling a guest MMIO read access internally, we
11 need to copy the emulation result into the run->mmio structure in order
12 for the kvm_handle_mmio_return() function to pick it up and inject the
13 result back into the guest.
14
15 Currently the only user of kvm_io_bus for ARM is the VGIC, which did
16 this copying itself, so this was not causing issues so far.
17
18 But with the upcoming new vgic implementation we need this done
19 properly.
20
21 Update the kvm_handle_mmio_return description and cleanup the code to
22 only perform a single copying when needed.
23
24 Code and commit message inspired by Andre Przywara.
25
26 Reported-by: Andre Przywara <andre.przywara@arm.com>
27 Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org>
28 Signed-off-by: Andre Przywara <andre.przywara@arm.com>
29 Reviewed-by: Marc Zyngier <marc.zyngier@arm.com>
30 Reviewed-by: Andre Przywara <andre.przywara@arm.com>
31 Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
32 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
33
34 ---
35 arch/arm/kvm/mmio.c | 11 ++++++-----
36 virt/kvm/arm/vgic.c | 7 -------
37 2 files changed, 6 insertions(+), 12 deletions(-)
38
39 --- a/arch/arm/kvm/mmio.c
40 +++ b/arch/arm/kvm/mmio.c
41 @@ -87,11 +87,10 @@ static unsigned long mmio_read_buf(char
42
43 /**
44 * kvm_handle_mmio_return -- Handle MMIO loads after user space emulation
45 + * or in-kernel IO emulation
46 + *
47 * @vcpu: The VCPU pointer
48 * @run: The VCPU run struct containing the mmio data
49 - *
50 - * This should only be called after returning from userspace for MMIO load
51 - * emulation.
52 */
53 int kvm_handle_mmio_return(struct kvm_vcpu *vcpu, struct kvm_run *run)
54 {
55 @@ -207,15 +206,17 @@ int io_mem_abort(struct kvm_vcpu *vcpu,
56 run->mmio.is_write = is_write;
57 run->mmio.phys_addr = fault_ipa;
58 run->mmio.len = len;
59 - if (is_write)
60 - memcpy(run->mmio.data, data_buf, len);
61
62 if (!ret) {
63 /* We handled the access successfully in the kernel. */
64 + if (!is_write)
65 + memcpy(run->mmio.data, data_buf, len);
66 kvm_handle_mmio_return(vcpu, run);
67 return 1;
68 }
69
70 + if (is_write)
71 + memcpy(run->mmio.data, data_buf, len);
72 run->exit_reason = KVM_EXIT_MMIO;
73 return 0;
74 }
75 --- a/virt/kvm/arm/vgic.c
76 +++ b/virt/kvm/arm/vgic.c
77 @@ -821,7 +821,6 @@ static int vgic_handle_mmio_access(struc
78 struct vgic_dist *dist = &vcpu->kvm->arch.vgic;
79 struct vgic_io_device *iodev = container_of(this,
80 struct vgic_io_device, dev);
81 - struct kvm_run *run = vcpu->run;
82 const struct vgic_io_range *range;
83 struct kvm_exit_mmio mmio;
84 bool updated_state;
85 @@ -850,12 +849,6 @@ static int vgic_handle_mmio_access(struc
86 updated_state = false;
87 }
88 spin_unlock(&dist->lock);
89 - run->mmio.is_write = is_write;
90 - run->mmio.len = len;
91 - run->mmio.phys_addr = addr;
92 - memcpy(run->mmio.data, val, len);
93 -
94 - kvm_handle_mmio_return(vcpu, run);
95
96 if (updated_state)
97 vgic_kick_vcpus(vcpu->kvm);