Commit 5386cef200ae0ac79cdcd160772989e8f5c47a4f

Authored by Michael S. Tsirkin
1 parent f30eaf4a09

virtio_pci: delete vqs indirectly

VQ deletion is mostly version-specific, add another level of indirection
to split the version-independent code out.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

Showing 1 changed file with 20 additions and 7 deletions Side-by-side Diff

drivers/virtio/virtio_pci.c
... ... @@ -81,6 +81,8 @@
81 81  
82 82 /* Whether we have vector per vq */
83 83 bool per_vq_vectors;
  84 +
  85 + void (*del_vq)(struct virtio_pci_vq_info *info);
84 86 };
85 87  
86 88 /* Constants for MSI-X */
87 89  
88 90  
89 91  
... ... @@ -468,16 +470,12 @@
468 470 return ERR_PTR(err);
469 471 }
470 472  
471   -static void vp_del_vq(struct virtqueue *vq)
  473 +static void del_vq(struct virtio_pci_vq_info *info)
472 474 {
  475 + struct virtqueue *vq = info->vq;
473 476 struct virtio_pci_device *vp_dev = to_vp_device(vq->vdev);
474   - struct virtio_pci_vq_info *info = vp_dev->vqs[vq->index];
475   - unsigned long flags, size;
  477 + unsigned long size;
476 478  
477   - spin_lock_irqsave(&vp_dev->lock, flags);
478   - list_del(&info->node);
479   - spin_unlock_irqrestore(&vp_dev->lock, flags);
480   -
481 479 iowrite16(vq->index, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_SEL);
482 480  
483 481 if (vp_dev->msix_enabled) {
... ... @@ -494,6 +492,19 @@
494 492  
495 493 size = PAGE_ALIGN(vring_size(info->num, VIRTIO_PCI_VRING_ALIGN));
496 494 free_pages_exact(info->queue, size);
  495 +}
  496 +
  497 +static void vp_del_vq(struct virtqueue *vq)
  498 +{
  499 + struct virtio_pci_device *vp_dev = to_vp_device(vq->vdev);
  500 + struct virtio_pci_vq_info *info = vp_dev->vqs[vq->index];
  501 + unsigned long flags;
  502 +
  503 + spin_lock_irqsave(&vp_dev->lock, flags);
  504 + list_del(&info->node);
  505 + spin_unlock_irqrestore(&vp_dev->lock, flags);
  506 +
  507 + vp_dev->del_vq(info);
497 508 kfree(info);
498 509 }
499 510  
... ... @@ -736,6 +747,8 @@
736 747 * the subsystem ids */
737 748 vp_dev->vdev.id.vendor = pci_dev->subsystem_vendor;
738 749 vp_dev->vdev.id.device = pci_dev->subsystem_device;
  750 +
  751 + vp_dev->del_vq = del_vq;
739 752  
740 753 /* finally register the virtio device */
741 754 err = register_virtio_device(&vp_dev->vdev);