Skip to content

Commit

Permalink
virtio: wrap config->reset calls
Browse files Browse the repository at this point in the history
This will enable cleanups down the road.
The idea is to disable cbs, then add "flush_queued_cbs" callback
as a parameter, this way drivers can flush any work
queued after callbacks have been disabled.

Signed-off-by: Michael S. Tsirkin <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Michael S. Tsirkin <[email protected]>
  • Loading branch information
mstsirkin committed Jan 14, 2022
1 parent c9e6606 commit d9679d0
Show file tree
Hide file tree
Showing 26 changed files with 40 additions and 33 deletions.
2 changes: 1 addition & 1 deletion arch/um/drivers/virt-pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ static void um_pci_virtio_remove(struct virtio_device *vdev)
int i;

/* Stop all virtqueues */
vdev->config->reset(vdev);
virtio_reset_device(vdev);
vdev->config->del_vqs(vdev);

device_set_wakeup_enable(&vdev->dev, false);
Expand Down
4 changes: 2 additions & 2 deletions drivers/block/virtio_blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ static void virtblk_remove(struct virtio_device *vdev)
mutex_lock(&vblk->vdev_mutex);

/* Stop all the virtqueues. */
vdev->config->reset(vdev);
virtio_reset_device(vdev);

/* Virtqueues are stopped, nothing can use vblk->vdev anymore. */
vblk->vdev = NULL;
Expand All @@ -996,7 +996,7 @@ static int virtblk_freeze(struct virtio_device *vdev)
struct virtio_blk *vblk = vdev->priv;

/* Ensure we don't receive any more interrupts */
vdev->config->reset(vdev);
virtio_reset_device(vdev);

/* Make sure no work handler is accessing the device. */
flush_work(&vblk->config_work);
Expand Down
2 changes: 1 addition & 1 deletion drivers/bluetooth/virtio_bt.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ static void virtbt_remove(struct virtio_device *vdev)
struct hci_dev *hdev = vbt->hdev;

hci_unregister_dev(hdev);
vdev->config->reset(vdev);
virtio_reset_device(vdev);

hci_free_dev(hdev);
vbt->hdev = NULL;
Expand Down
2 changes: 1 addition & 1 deletion drivers/char/hw_random/virtio-rng.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static void remove_common(struct virtio_device *vdev)
vi->data_avail = 0;
vi->data_idx = 0;
complete(&vi->have_data);
vdev->config->reset(vdev);
virtio_reset_device(vdev);
if (vi->hwrng_register_done)
hwrng_unregister(&vi->hwrng);
vdev->config->del_vqs(vdev);
Expand Down
4 changes: 2 additions & 2 deletions drivers/char/virtio_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -1958,7 +1958,7 @@ static void virtcons_remove(struct virtio_device *vdev)
spin_unlock_irq(&pdrvdata_lock);

/* Disable interrupts for vqs */
vdev->config->reset(vdev);
virtio_reset_device(vdev);
/* Finish up work that's lined up */
if (use_multiport(portdev))
cancel_work_sync(&portdev->control_work);
Expand Down Expand Up @@ -2148,7 +2148,7 @@ static int virtcons_freeze(struct virtio_device *vdev)

portdev = vdev->priv;

vdev->config->reset(vdev);
virtio_reset_device(vdev);

if (use_multiport(portdev))
virtqueue_disable_cb(portdev->c_ivq);
Expand Down
8 changes: 4 additions & 4 deletions drivers/crypto/virtio/virtio_crypto_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ static int virtcrypto_probe(struct virtio_device *vdev)
free_engines:
virtcrypto_clear_crypto_engines(vcrypto);
free_vqs:
vcrypto->vdev->config->reset(vdev);
virtio_reset_device(vdev);
virtcrypto_del_vqs(vcrypto);
free_dev:
virtcrypto_devmgr_rm_dev(vcrypto);
Expand Down Expand Up @@ -436,7 +436,7 @@ static void virtcrypto_remove(struct virtio_device *vdev)

if (virtcrypto_dev_started(vcrypto))
virtcrypto_dev_stop(vcrypto);
vdev->config->reset(vdev);
virtio_reset_device(vdev);
virtcrypto_free_unused_reqs(vcrypto);
virtcrypto_clear_crypto_engines(vcrypto);
virtcrypto_del_vqs(vcrypto);
Expand All @@ -456,7 +456,7 @@ static int virtcrypto_freeze(struct virtio_device *vdev)
{
struct virtio_crypto *vcrypto = vdev->priv;

vdev->config->reset(vdev);
virtio_reset_device(vdev);
virtcrypto_free_unused_reqs(vcrypto);
if (virtcrypto_dev_started(vcrypto))
virtcrypto_dev_stop(vcrypto);
Expand Down Expand Up @@ -492,7 +492,7 @@ static int virtcrypto_restore(struct virtio_device *vdev)
free_engines:
virtcrypto_clear_crypto_engines(vcrypto);
free_vqs:
vcrypto->vdev->config->reset(vdev);
virtio_reset_device(vdev);
virtcrypto_del_vqs(vcrypto);
return err;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/firmware/arm_scmi/virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ static void scmi_vio_remove(struct virtio_device *vdev)
* outstanding message on any vqueue to be ignored by complete_cb: now
* we can just stop processing buffers and destroy the vqueues.
*/
vdev->config->reset(vdev);
virtio_reset_device(vdev);
vdev->config->del_vqs(vdev);
/* Ensure scmi_vdev is visible as NULL */
smp_store_mb(scmi_vdev, NULL);
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpio/gpio-virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ static void virtio_gpio_request_vq(struct virtqueue *vq)

static void virtio_gpio_free_vqs(struct virtio_device *vdev)
{
vdev->config->reset(vdev);
virtio_reset_device(vdev);
vdev->config->del_vqs(vdev);
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/virtio/virtgpu_kms.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ void virtio_gpu_deinit(struct drm_device *dev)
flush_work(&vgdev->ctrlq.dequeue_work);
flush_work(&vgdev->cursorq.dequeue_work);
flush_work(&vgdev->config_changed_work);
vgdev->vdev->config->reset(vgdev->vdev);
virtio_reset_device(vgdev->vdev);
vgdev->vdev->config->del_vqs(vgdev->vdev);
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/i2c/busses/i2c-virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static int virtio_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,

static void virtio_i2c_del_vqs(struct virtio_device *vdev)
{
vdev->config->reset(vdev);
virtio_reset_device(vdev);
vdev->config->del_vqs(vdev);
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/iommu/virtio-iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ static void viommu_remove(struct virtio_device *vdev)
iommu_device_unregister(&viommu->iommu);

/* Stop all virtqueues */
vdev->config->reset(vdev);
virtio_reset_device(vdev);
vdev->config->del_vqs(vdev);

dev_info(&vdev->dev, "device removed\n");
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/caif/caif_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ static void cfv_remove(struct virtio_device *vdev)
debugfs_remove_recursive(cfv->debugfs);

vringh_kiov_cleanup(&cfv->ctx.riov);
vdev->config->reset(vdev);
virtio_reset_device(vdev);
vdev->vringh_config->del_vrhs(cfv->vdev);
cfv->vr_rx = NULL;
vdev->config->del_vqs(cfv->vdev);
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/virtio_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -3310,7 +3310,7 @@ static int virtnet_probe(struct virtio_device *vdev)
return 0;

free_unregister_netdev:
vi->vdev->config->reset(vdev);
virtio_reset_device(vdev);

unregister_netdev(dev);
free_failover:
Expand All @@ -3326,7 +3326,7 @@ static int virtnet_probe(struct virtio_device *vdev)

static void remove_vq_common(struct virtnet_info *vi)
{
vi->vdev->config->reset(vi->vdev);
virtio_reset_device(vi->vdev);

/* Free unused buffers in both send and recv, if any. */
free_unused_bufs(vi);
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/mac80211_hwsim.c
Original file line number Diff line number Diff line change
Expand Up @@ -4498,7 +4498,7 @@ static void remove_vqs(struct virtio_device *vdev)
{
int i;

vdev->config->reset(vdev);
virtio_reset_device(vdev);

for (i = 0; i < ARRAY_SIZE(hwsim_vqs); i++) {
struct virtqueue *vq = hwsim_vqs[i];
Expand Down
2 changes: 1 addition & 1 deletion drivers/nvdimm/virtio_pmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static void virtio_pmem_remove(struct virtio_device *vdev)

nvdimm_bus_unregister(nvdimm_bus);
vdev->config->del_vqs(vdev);
vdev->config->reset(vdev);
virtio_reset_device(vdev);
}

static struct virtio_driver virtio_pmem_driver = {
Expand Down
2 changes: 1 addition & 1 deletion drivers/rpmsg/virtio_rpmsg_bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ static void rpmsg_remove(struct virtio_device *vdev)
size_t total_buf_space = vrp->num_bufs * vrp->buf_size;
int ret;

vdev->config->reset(vdev);
virtio_reset_device(vdev);

ret = device_for_each_child(&vdev->dev, NULL, rpmsg_remove_device);
if (ret)
Expand Down
2 changes: 1 addition & 1 deletion drivers/scsi/virtio_scsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ static void virtscsi_init_vq(struct virtio_scsi_vq *virtscsi_vq,
static void virtscsi_remove_vqs(struct virtio_device *vdev)
{
/* Stop all the virtqueues. */
vdev->config->reset(vdev);
virtio_reset_device(vdev);
vdev->config->del_vqs(vdev);
}

Expand Down
6 changes: 6 additions & 0 deletions drivers/virtio/virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ int virtio_finalize_features(struct virtio_device *dev)
}
EXPORT_SYMBOL_GPL(virtio_finalize_features);

void virtio_reset_device(struct virtio_device *dev)
{
dev->config->reset(dev);
}
EXPORT_SYMBOL_GPL(virtio_reset_device);

static int virtio_dev_probe(struct device *_d)
{
int err, i;
Expand Down
2 changes: 1 addition & 1 deletion drivers/virtio/virtio_balloon.c
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,7 @@ static void remove_common(struct virtio_balloon *vb)
return_free_pages_to_mm(vb, ULONG_MAX);

/* Now we reset the device so we can clean up the queues. */
vb->vdev->config->reset(vb->vdev);
virtio_reset_device(vb->vdev);

vb->vdev->config->del_vqs(vb->vdev);
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/virtio/virtio_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ static void virtinput_remove(struct virtio_device *vdev)
spin_unlock_irqrestore(&vi->lock, flags);

input_unregister_device(vi->idev);
vdev->config->reset(vdev);
virtio_reset_device(vdev);
while ((buf = virtqueue_detach_unused_buf(vi->sts)) != NULL)
kfree(buf);
vdev->config->del_vqs(vdev);
Expand Down
2 changes: 1 addition & 1 deletion drivers/virtio/virtio_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -2850,7 +2850,7 @@ static void virtio_mem_remove(struct virtio_device *vdev)
virtio_mem_deinit_hotplug(vm);

/* reset the device and cleanup the queues */
vdev->config->reset(vdev);
virtio_reset_device(vdev);
vdev->config->del_vqs(vdev);

kfree(vm);
Expand Down
4 changes: 2 additions & 2 deletions fs/fuse/virtio_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ static int virtio_fs_probe(struct virtio_device *vdev)
return 0;

out_vqs:
vdev->config->reset(vdev);
virtio_reset_device(vdev);
virtio_fs_cleanup_vqs(vdev, fs);
kfree(fs->vqs);

Expand Down Expand Up @@ -927,7 +927,7 @@ static void virtio_fs_remove(struct virtio_device *vdev)
list_del_init(&fs->list);
virtio_fs_stop_all_queues(fs);
virtio_fs_drain_all_queues_locked(fs);
vdev->config->reset(vdev);
virtio_reset_device(vdev);
virtio_fs_cleanup_vqs(vdev, fs);

vdev->priv = NULL;
Expand Down
1 change: 1 addition & 0 deletions include/linux/virtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ int virtio_finalize_features(struct virtio_device *dev);
int virtio_device_freeze(struct virtio_device *dev);
int virtio_device_restore(struct virtio_device *dev);
#endif
void virtio_reset_device(struct virtio_device *dev);

size_t virtio_max_dma_size(struct virtio_device *vdev);

Expand Down
2 changes: 1 addition & 1 deletion net/9p/trans_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ static void p9_virtio_remove(struct virtio_device *vdev)

mutex_unlock(&virtio_9p_lock);

vdev->config->reset(vdev);
virtio_reset_device(vdev);
vdev->config->del_vqs(vdev);

sysfs_remove_file(&(vdev->dev.kobj), &dev_attr_mount_tag.attr);
Expand Down
4 changes: 2 additions & 2 deletions net/vmw_vsock/virtio_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ static void virtio_vsock_remove(struct virtio_device *vdev)
vsock_for_each_connected_socket(virtio_vsock_reset_sock);

/* Stop all work handlers to make sure no one is accessing the device,
* so we can safely call vdev->config->reset().
* so we can safely call virtio_reset_device().
*/
mutex_lock(&vsock->rx_lock);
vsock->rx_run = false;
Expand All @@ -682,7 +682,7 @@ static void virtio_vsock_remove(struct virtio_device *vdev)
/* Flush all device writes and interrupts, device will not use any
* more buffers.
*/
vdev->config->reset(vdev);
virtio_reset_device(vdev);

mutex_lock(&vsock->rx_lock);
while ((pkt = virtqueue_detach_unused_buf(vsock->vqs[VSOCK_VQ_RX])))
Expand Down
4 changes: 2 additions & 2 deletions sound/virtio/virtio_card.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ static void virtsnd_remove(struct virtio_device *vdev)
snd_card_free(snd->card);

vdev->config->del_vqs(vdev);
vdev->config->reset(vdev);
virtio_reset_device(vdev);

for (i = 0; snd->substreams && i < snd->nsubstreams; ++i) {
struct virtio_pcm_substream *vss = &snd->substreams[i];
Expand Down Expand Up @@ -379,7 +379,7 @@ static int virtsnd_freeze(struct virtio_device *vdev)
virtsnd_ctl_msg_cancel_all(snd);

vdev->config->del_vqs(vdev);
vdev->config->reset(vdev);
virtio_reset_device(vdev);

for (i = 0; i < snd->nsubstreams; ++i)
cancel_work_sync(&snd->substreams[i].elapsed_period);
Expand Down

0 comments on commit d9679d0

Please sign in to comment.