virtio: wrap config->reset calls
authorMichael S. Tsirkin <mst@redhat.com>
Wed, 13 Oct 2021 10:55:44 +0000 (06:55 -0400)
committerMichael S. Tsirkin <mst@redhat.com>
Fri, 14 Jan 2022 23:50:52 +0000 (18:50 -0500)
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 <mst@redhat.com>
Link: https://lore.kernel.org/r/20211013105226.20225-1-mst@redhat.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
26 files changed:
arch/um/drivers/virt-pci.c
drivers/block/virtio_blk.c
drivers/bluetooth/virtio_bt.c
drivers/char/hw_random/virtio-rng.c
drivers/char/virtio_console.c
drivers/crypto/virtio/virtio_crypto_core.c
drivers/firmware/arm_scmi/virtio.c
drivers/gpio/gpio-virtio.c
drivers/gpu/drm/virtio/virtgpu_kms.c
drivers/i2c/busses/i2c-virtio.c
drivers/iommu/virtio-iommu.c
drivers/net/caif/caif_virtio.c
drivers/net/virtio_net.c
drivers/net/wireless/mac80211_hwsim.c
drivers/nvdimm/virtio_pmem.c
drivers/rpmsg/virtio_rpmsg_bus.c
drivers/scsi/virtio_scsi.c
drivers/virtio/virtio.c
drivers/virtio/virtio_balloon.c
drivers/virtio/virtio_input.c
drivers/virtio/virtio_mem.c
fs/fuse/virtio_fs.c
include/linux/virtio.h
net/9p/trans_virtio.c
net/vmw_vsock/virtio_transport.c
sound/virtio/virtio_card.c

index c0806663302349eb4398de2a879650d65fd03667..22c4d87c9c150e019a11482adc17a99e42dc7db6 100644 (file)
@@ -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);
index 6ae38776e30e5049b31f45dc8b8158cf98643a4d..644c6cddad6dfd1fedaee907c77db206f90ef473 100644 (file)
@@ -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;
@@ -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);
index 57908ce4fae856fd2023d0a5e443cd18a9766900..24a9258962fa55a9b70249719fe8adc0ed0b9175 100644 (file)
@@ -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;
index 0a7dde135db19a84df0c809370bce039ada2be59..b2bf78b256302dabfe6dde0a9f76ed06050aff6d 100644 (file)
@@ -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);
index 660c5c388c291759838e686c387f370005690719..2359889a35a0a6711964d35df3bce342e6bc2f54 100644 (file)
@@ -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);
@@ -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);
index e2375d992308701f32574b2d5abf13ce496cbfe8..8e977b7627cb74879f1c3630b20abd96af0d3451 100644 (file)
@@ -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);
@@ -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);
@@ -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);
@@ -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;
 }
index 87039c5c03fdb96c3de61dc6e58d519f918914e7..eefcc4146749ce0a7c50ad37ef01c0c41cc4fb59 100644 (file)
@@ -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);
index 9f4941bc57604bdacfd4e2605ec760965e2589e0..fcc5e8c08973b3e797051b43b1af9bc36ef4d092 100644 (file)
@@ -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);
 }
 
index 21f4109016949cf33072ad504d1b625511c4354d..3313b92db53190cb640ea5660b3b6975ddf77ce7 100644 (file)
@@ -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);
 }
 
index 41eb0dcc3204fe86ddcc7570730ab5bf509850e3..4b9536f508006dce032e752f0dccaae9b8919182 100644 (file)
@@ -165,7 +165,7 @@ err_free:
 
 static void virtio_i2c_del_vqs(struct virtio_device *vdev)
 {
-       vdev->config->reset(vdev);
+       virtio_reset_device(vdev);
        vdev->config->del_vqs(vdev);
 }
 
index 80930ce04a168156eb15c7137d713cddc587ca04..1d4e1e7cf1753d075e83105c5882bb843894af0d 100644 (file)
@@ -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");
index 91230894692d27bfc833c6136f47cb65716fe0f1..444ef6a342f6979b1cae7f4afa2cb6ec60f4d10b 100644 (file)
@@ -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);
index b107835242ade6c2f7411b2a019e44a9b0c85748..eeed458c794e3bcb7ffd2900b6278a5966133d40 100644 (file)
@@ -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:
@@ -3326,7 +3326,7 @@ free:
 
 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);
index 23219f3747f816db5cd4b359939aa62b1f2365ec..02d374360bcc563620e1a682efbe686e7e7cd8a0 100644 (file)
@@ -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];
index 726c7354d465984adb4bc35259af54a5ec8d6534..995b6cdc67ede881a3e94eb81472ba52e0945f36 100644 (file)
@@ -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 = {
index 9c112aa6504032ee48037743a97c37733a9eb36c..4bda40568dc9cec7c0e760dca1abde5f98df7d91 100644 (file)
@@ -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)
index 28e1d98ae1021440c86ae73a6a4d8cf793d7934f..c616c7171cc4eddfefae6807e288c4ff98868cb6 100644 (file)
@@ -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);
 }
 
index 236081afe9a2a38566a4e8e25d9ff0331d032ec5..00ac9db792a4d3a7798ab3fdf4eb06747064d143 100644 (file)
@@ -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;
index c22ff0117b46b8b128bb7915744acd914d40d7c7..f4c34a2a6b8eddc6d80af064fc8ede0991f6afe3 100644 (file)
@@ -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);
 }
index ce51ae1659432874245f45dad6e2d8662d556617..3aa46703872dcc54cf541f714af9cb4f10f074ff 100644 (file)
@@ -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);
index 96e5a878276976e816f85cddcf5d6f7dba43b8e6..033fb93ed52847a5d31c81bacae2e28e9b169f37 100644 (file)
@@ -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);
index 4cfa4bc1f5794415d69c8c2ea69e3fcda3d6dfc3..ca2cac196d73b89af3de2f0966c3618a5cdff349 100644 (file)
@@ -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);
 
@@ -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;
index 41edbc01ffa4039524d5519caaa2f18e5884ca65..72292a62cd9050e0f95f997400277cb7833c4ef1 100644 (file)
@@ -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);
 
index bd5a89c4960dd76099977f2b3eda91a984268838..8ff6d7160677d3f7aee5f67fa9f93470d3cee136 100644 (file)
@@ -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);
index 4f7c99dfd16cfeeaca42355366540ea99c9e83ea..fb3302fff62795b1c3723ed0b7982772d7f38d55 100644 (file)
@@ -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;
@@ -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])))
index 150ab3e37013e9ab240b064b8739a63b395ad5f8..e2847c040f750f98a77cb0bfe4ec2a548f5eb691 100644 (file)
@@ -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];
@@ -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);