.. | .. |
---|
86 | 86 | ring->coalesced_mmio[insert].phys_addr = addr; |
---|
87 | 87 | ring->coalesced_mmio[insert].len = len; |
---|
88 | 88 | memcpy(ring->coalesced_mmio[insert].data, val, len); |
---|
| 89 | + ring->coalesced_mmio[insert].pio = dev->zone.pio; |
---|
89 | 90 | smp_wmb(); |
---|
90 | 91 | ring->last = (insert + 1) % KVM_COALESCED_MMIO_MAX; |
---|
91 | 92 | spin_unlock(&dev->kvm->ring_lock); |
---|
.. | .. |
---|
109 | 110 | int kvm_coalesced_mmio_init(struct kvm *kvm) |
---|
110 | 111 | { |
---|
111 | 112 | struct page *page; |
---|
112 | | - int ret; |
---|
113 | 113 | |
---|
114 | | - ret = -ENOMEM; |
---|
115 | 114 | page = alloc_page(GFP_KERNEL | __GFP_ZERO); |
---|
116 | 115 | if (!page) |
---|
117 | | - goto out_err; |
---|
| 116 | + return -ENOMEM; |
---|
118 | 117 | |
---|
119 | | - ret = 0; |
---|
120 | 118 | kvm->coalesced_mmio_ring = page_address(page); |
---|
121 | 119 | |
---|
122 | 120 | /* |
---|
123 | 121 | * We're using this spinlock to sync access to the coalesced ring. |
---|
124 | | - * The list doesn't need it's own lock since device registration and |
---|
| 122 | + * The list doesn't need its own lock since device registration and |
---|
125 | 123 | * unregistration should only happen when kvm->slots_lock is held. |
---|
126 | 124 | */ |
---|
127 | 125 | spin_lock_init(&kvm->ring_lock); |
---|
128 | 126 | INIT_LIST_HEAD(&kvm->coalesced_zones); |
---|
129 | 127 | |
---|
130 | | -out_err: |
---|
131 | | - return ret; |
---|
| 128 | + return 0; |
---|
132 | 129 | } |
---|
133 | 130 | |
---|
134 | 131 | void kvm_coalesced_mmio_free(struct kvm *kvm) |
---|
.. | .. |
---|
143 | 140 | int ret; |
---|
144 | 141 | struct kvm_coalesced_mmio_dev *dev; |
---|
145 | 142 | |
---|
146 | | - dev = kzalloc(sizeof(struct kvm_coalesced_mmio_dev), GFP_KERNEL); |
---|
| 143 | + if (zone->pio != 1 && zone->pio != 0) |
---|
| 144 | + return -EINVAL; |
---|
| 145 | + |
---|
| 146 | + dev = kzalloc(sizeof(struct kvm_coalesced_mmio_dev), |
---|
| 147 | + GFP_KERNEL_ACCOUNT); |
---|
147 | 148 | if (!dev) |
---|
148 | 149 | return -ENOMEM; |
---|
149 | 150 | |
---|
.. | .. |
---|
152 | 153 | dev->zone = *zone; |
---|
153 | 154 | |
---|
154 | 155 | mutex_lock(&kvm->slots_lock); |
---|
155 | | - ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS, zone->addr, |
---|
156 | | - zone->size, &dev->dev); |
---|
| 156 | + ret = kvm_io_bus_register_dev(kvm, |
---|
| 157 | + zone->pio ? KVM_PIO_BUS : KVM_MMIO_BUS, |
---|
| 158 | + zone->addr, zone->size, &dev->dev); |
---|
157 | 159 | if (ret < 0) |
---|
158 | 160 | goto out_free_dev; |
---|
159 | 161 | list_add_tail(&dev->list, &kvm->coalesced_zones); |
---|
.. | .. |
---|
172 | 174 | struct kvm_coalesced_mmio_zone *zone) |
---|
173 | 175 | { |
---|
174 | 176 | struct kvm_coalesced_mmio_dev *dev, *tmp; |
---|
| 177 | + int r; |
---|
| 178 | + |
---|
| 179 | + if (zone->pio != 1 && zone->pio != 0) |
---|
| 180 | + return -EINVAL; |
---|
175 | 181 | |
---|
176 | 182 | mutex_lock(&kvm->slots_lock); |
---|
177 | 183 | |
---|
178 | | - list_for_each_entry_safe(dev, tmp, &kvm->coalesced_zones, list) |
---|
179 | | - if (coalesced_mmio_in_range(dev, zone->addr, zone->size)) { |
---|
180 | | - kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS, &dev->dev); |
---|
| 184 | + list_for_each_entry_safe(dev, tmp, &kvm->coalesced_zones, list) { |
---|
| 185 | + if (zone->pio == dev->zone.pio && |
---|
| 186 | + coalesced_mmio_in_range(dev, zone->addr, zone->size)) { |
---|
| 187 | + r = kvm_io_bus_unregister_dev(kvm, |
---|
| 188 | + zone->pio ? KVM_PIO_BUS : KVM_MMIO_BUS, &dev->dev); |
---|
| 189 | + |
---|
181 | 190 | kvm_iodevice_destructor(&dev->dev); |
---|
| 191 | + |
---|
| 192 | + /* |
---|
| 193 | + * On failure, unregister destroys all devices on the |
---|
| 194 | + * bus _except_ the target device, i.e. coalesced_zones |
---|
| 195 | + * has been modified. Bail after destroying the target |
---|
| 196 | + * device, there's no need to restart the walk as there |
---|
| 197 | + * aren't any zones left. |
---|
| 198 | + */ |
---|
| 199 | + if (r) |
---|
| 200 | + break; |
---|
182 | 201 | } |
---|
| 202 | + } |
---|
183 | 203 | |
---|
184 | 204 | mutex_unlock(&kvm->slots_lock); |
---|
185 | 205 | |
---|
| 206 | + /* |
---|
| 207 | + * Ignore the result of kvm_io_bus_unregister_dev(), from userspace's |
---|
| 208 | + * perspective, the coalesced MMIO is most definitely unregistered. |
---|
| 209 | + */ |
---|
186 | 210 | return 0; |
---|
187 | 211 | } |
---|