diff options
-rw-r--r-- | drivers/virtio/virtio_balloon.c | 19 | ||||
-rw-r--r-- | drivers/virtio/virtio_pci_common.c | 9 |
2 files changed, 18 insertions, 10 deletions
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 4e1191508228..34adf9b9c053 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c | |||
@@ -242,11 +242,11 @@ static inline void update_stat(struct virtio_balloon *vb, int idx, | |||
242 | 242 | ||
243 | #define pages_to_bytes(x) ((u64)(x) << PAGE_SHIFT) | 243 | #define pages_to_bytes(x) ((u64)(x) << PAGE_SHIFT) |
244 | 244 | ||
245 | static void update_balloon_stats(struct virtio_balloon *vb) | 245 | static unsigned int update_balloon_stats(struct virtio_balloon *vb) |
246 | { | 246 | { |
247 | unsigned long events[NR_VM_EVENT_ITEMS]; | 247 | unsigned long events[NR_VM_EVENT_ITEMS]; |
248 | struct sysinfo i; | 248 | struct sysinfo i; |
249 | int idx = 0; | 249 | unsigned int idx = 0; |
250 | long available; | 250 | long available; |
251 | 251 | ||
252 | all_vm_events(events); | 252 | all_vm_events(events); |
@@ -254,18 +254,22 @@ static void update_balloon_stats(struct virtio_balloon *vb) | |||
254 | 254 | ||
255 | available = si_mem_available(); | 255 | available = si_mem_available(); |
256 | 256 | ||
257 | #ifdef CONFIG_VM_EVENT_COUNTERS | ||
257 | update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_IN, | 258 | update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_IN, |
258 | pages_to_bytes(events[PSWPIN])); | 259 | pages_to_bytes(events[PSWPIN])); |
259 | update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_OUT, | 260 | update_stat(vb, idx++, VIRTIO_BALLOON_S_SWAP_OUT, |
260 | pages_to_bytes(events[PSWPOUT])); | 261 | pages_to_bytes(events[PSWPOUT])); |
261 | update_stat(vb, idx++, VIRTIO_BALLOON_S_MAJFLT, events[PGMAJFAULT]); | 262 | update_stat(vb, idx++, VIRTIO_BALLOON_S_MAJFLT, events[PGMAJFAULT]); |
262 | update_stat(vb, idx++, VIRTIO_BALLOON_S_MINFLT, events[PGFAULT]); | 263 | update_stat(vb, idx++, VIRTIO_BALLOON_S_MINFLT, events[PGFAULT]); |
264 | #endif | ||
263 | update_stat(vb, idx++, VIRTIO_BALLOON_S_MEMFREE, | 265 | update_stat(vb, idx++, VIRTIO_BALLOON_S_MEMFREE, |
264 | pages_to_bytes(i.freeram)); | 266 | pages_to_bytes(i.freeram)); |
265 | update_stat(vb, idx++, VIRTIO_BALLOON_S_MEMTOT, | 267 | update_stat(vb, idx++, VIRTIO_BALLOON_S_MEMTOT, |
266 | pages_to_bytes(i.totalram)); | 268 | pages_to_bytes(i.totalram)); |
267 | update_stat(vb, idx++, VIRTIO_BALLOON_S_AVAIL, | 269 | update_stat(vb, idx++, VIRTIO_BALLOON_S_AVAIL, |
268 | pages_to_bytes(available)); | 270 | pages_to_bytes(available)); |
271 | |||
272 | return idx; | ||
269 | } | 273 | } |
270 | 274 | ||
271 | /* | 275 | /* |
@@ -291,14 +295,14 @@ static void stats_handle_request(struct virtio_balloon *vb) | |||
291 | { | 295 | { |
292 | struct virtqueue *vq; | 296 | struct virtqueue *vq; |
293 | struct scatterlist sg; | 297 | struct scatterlist sg; |
294 | unsigned int len; | 298 | unsigned int len, num_stats; |
295 | 299 | ||
296 | update_balloon_stats(vb); | 300 | num_stats = update_balloon_stats(vb); |
297 | 301 | ||
298 | vq = vb->stats_vq; | 302 | vq = vb->stats_vq; |
299 | if (!virtqueue_get_buf(vq, &len)) | 303 | if (!virtqueue_get_buf(vq, &len)) |
300 | return; | 304 | return; |
301 | sg_init_one(&sg, vb->stats, sizeof(vb->stats)); | 305 | sg_init_one(&sg, vb->stats, sizeof(vb->stats[0]) * num_stats); |
302 | virtqueue_add_outbuf(vq, &sg, 1, vb, GFP_KERNEL); | 306 | virtqueue_add_outbuf(vq, &sg, 1, vb, GFP_KERNEL); |
303 | virtqueue_kick(vq); | 307 | virtqueue_kick(vq); |
304 | } | 308 | } |
@@ -423,13 +427,16 @@ static int init_vqs(struct virtio_balloon *vb) | |||
423 | vb->deflate_vq = vqs[1]; | 427 | vb->deflate_vq = vqs[1]; |
424 | if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ)) { | 428 | if (virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_STATS_VQ)) { |
425 | struct scatterlist sg; | 429 | struct scatterlist sg; |
430 | unsigned int num_stats; | ||
426 | vb->stats_vq = vqs[2]; | 431 | vb->stats_vq = vqs[2]; |
427 | 432 | ||
428 | /* | 433 | /* |
429 | * Prime this virtqueue with one buffer so the hypervisor can | 434 | * Prime this virtqueue with one buffer so the hypervisor can |
430 | * use it to signal us later (it can't be broken yet!). | 435 | * use it to signal us later (it can't be broken yet!). |
431 | */ | 436 | */ |
432 | sg_init_one(&sg, vb->stats, sizeof vb->stats); | 437 | num_stats = update_balloon_stats(vb); |
438 | |||
439 | sg_init_one(&sg, vb->stats, sizeof(vb->stats[0]) * num_stats); | ||
433 | if (virtqueue_add_outbuf(vb->stats_vq, &sg, 1, vb, GFP_KERNEL) | 440 | if (virtqueue_add_outbuf(vb->stats_vq, &sg, 1, vb, GFP_KERNEL) |
434 | < 0) | 441 | < 0) |
435 | BUG(); | 442 | BUG(); |
diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c index df548a6fb844..590534910dc6 100644 --- a/drivers/virtio/virtio_pci_common.c +++ b/drivers/virtio/virtio_pci_common.c | |||
@@ -147,7 +147,7 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs, | |||
147 | { | 147 | { |
148 | struct virtio_pci_device *vp_dev = to_vp_device(vdev); | 148 | struct virtio_pci_device *vp_dev = to_vp_device(vdev); |
149 | const char *name = dev_name(&vp_dev->vdev.dev); | 149 | const char *name = dev_name(&vp_dev->vdev.dev); |
150 | int i, err = -ENOMEM, allocated_vectors, nvectors; | 150 | int i, j, err = -ENOMEM, allocated_vectors, nvectors; |
151 | unsigned flags = PCI_IRQ_MSIX; | 151 | unsigned flags = PCI_IRQ_MSIX; |
152 | bool shared = false; | 152 | bool shared = false; |
153 | u16 msix_vec; | 153 | u16 msix_vec; |
@@ -212,7 +212,7 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs, | |||
212 | if (!vp_dev->msix_vector_map) | 212 | if (!vp_dev->msix_vector_map) |
213 | goto out_disable_config_irq; | 213 | goto out_disable_config_irq; |
214 | 214 | ||
215 | allocated_vectors = 1; /* vector 0 is the config interrupt */ | 215 | allocated_vectors = j = 1; /* vector 0 is the config interrupt */ |
216 | for (i = 0; i < nvqs; ++i) { | 216 | for (i = 0; i < nvqs; ++i) { |
217 | if (!names[i]) { | 217 | if (!names[i]) { |
218 | vqs[i] = NULL; | 218 | vqs[i] = NULL; |
@@ -236,18 +236,19 @@ static int vp_find_vqs_msix(struct virtio_device *vdev, unsigned nvqs, | |||
236 | continue; | 236 | continue; |
237 | } | 237 | } |
238 | 238 | ||
239 | snprintf(vp_dev->msix_names[i + 1], | 239 | snprintf(vp_dev->msix_names[j], |
240 | sizeof(*vp_dev->msix_names), "%s-%s", | 240 | sizeof(*vp_dev->msix_names), "%s-%s", |
241 | dev_name(&vp_dev->vdev.dev), names[i]); | 241 | dev_name(&vp_dev->vdev.dev), names[i]); |
242 | err = request_irq(pci_irq_vector(vp_dev->pci_dev, msix_vec), | 242 | err = request_irq(pci_irq_vector(vp_dev->pci_dev, msix_vec), |
243 | vring_interrupt, IRQF_SHARED, | 243 | vring_interrupt, IRQF_SHARED, |
244 | vp_dev->msix_names[i + 1], vqs[i]); | 244 | vp_dev->msix_names[j], vqs[i]); |
245 | if (err) { | 245 | if (err) { |
246 | /* don't free this irq on error */ | 246 | /* don't free this irq on error */ |
247 | vp_dev->msix_vector_map[i] = VIRTIO_MSI_NO_VECTOR; | 247 | vp_dev->msix_vector_map[i] = VIRTIO_MSI_NO_VECTOR; |
248 | goto out_remove_vqs; | 248 | goto out_remove_vqs; |
249 | } | 249 | } |
250 | vp_dev->msix_vector_map[i] = msix_vec; | 250 | vp_dev->msix_vector_map[i] = msix_vec; |
251 | j++; | ||
251 | 252 | ||
252 | /* | 253 | /* |
253 | * Use a different vector for each queue if they are available, | 254 | * Use a different vector for each queue if they are available, |