]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
nvdimm: virtio_pmem: serialize flush requests
authorLi Chen <me@linux.beauty>
Tue, 3 Feb 2026 02:13:51 +0000 (10:13 +0800)
committerIra Weiny <ira.weiny@intel.com>
Wed, 4 Feb 2026 19:16:40 +0000 (13:16 -0600)
Under heavy concurrent flush traffic, virtio-pmem can overflow its request
virtqueue (req_vq): virtqueue_add_sgs() starts returning -ENOSPC and the
driver logs "no free slots in the virtqueue". Shortly after that the
device enters VIRTIO_CONFIG_S_NEEDS_RESET and flush requests fail with
"virtio pmem device needs a reset".

Serialize virtio_pmem_flush() with a per-device mutex so only one flush
request is in-flight at a time. This prevents req_vq descriptor overflow
under high concurrency.

Reproducer (guest with virtio-pmem):
  - mkfs.ext4 -F /dev/pmem0
  - mount -t ext4 -o dax,noatime /dev/pmem0 /mnt/bench
  - fio: ioengine=io_uring rw=randwrite bs=4k iodepth=64 numjobs=64
        direct=1 fsync=1 runtime=30s time_based=1
  - dmesg: "no free slots in the virtqueue"
           "virtio pmem device needs a reset"

Fixes: 6e84200c0a29 ("virtio-pmem: Add virtio pmem driver")
Signed-off-by: Li Chen <me@linux.beauty>
Acked-by: Pankaj Gupta <pankaj.gupta.linux@gmail.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Link: https://patch.msgid.link/20260203021353.121091-1-me@linux.beauty
Signed-off-by: Ira Weiny <ira.weiny@intel.com>
drivers/nvdimm/nd_virtio.c
drivers/nvdimm/virtio_pmem.c
drivers/nvdimm/virtio_pmem.h

index c3f07be4aa22adbedfcc5ee30bee9762c5d55e64..af82385be7c6aaf157b441e9c909f94a76d4a1f1 100644 (file)
@@ -44,6 +44,8 @@ static int virtio_pmem_flush(struct nd_region *nd_region)
        unsigned long flags;
        int err, err1;
 
+       guard(mutex)(&vpmem->flush_lock);
+
        /*
         * Don't bother to submit the request to the device if the device is
         * not activated.
@@ -53,7 +55,6 @@ static int virtio_pmem_flush(struct nd_region *nd_region)
                return -EIO;
        }
 
-       might_sleep();
        req_data = kmalloc(sizeof(*req_data), GFP_KERNEL);
        if (!req_data)
                return -ENOMEM;
index 2396d19ce5496974f8b93b54cc8c95e48dda103d..77b1966619059c50aa3cfd9c9e2ebd76f9c3ac7e 100644 (file)
@@ -64,6 +64,7 @@ static int virtio_pmem_probe(struct virtio_device *vdev)
                goto out_err;
        }
 
+       mutex_init(&vpmem->flush_lock);
        vpmem->vdev = vdev;
        vdev->priv = vpmem;
        err = init_vq(vpmem);
index 0dddefe594c46ad7e0c0557f73ffcdc20bbe9c1c..f72cf17f9518fb0b3dff4c138dc9cde108c2b8bc 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/module.h>
 #include <uapi/linux/virtio_pmem.h>
 #include <linux/libnvdimm.h>
+#include <linux/mutex.h>
 #include <linux/spinlock.h>
 
 struct virtio_pmem_request {
@@ -35,6 +36,9 @@ struct virtio_pmem {
        /* Virtio pmem request queue */
        struct virtqueue *req_vq;
 
+       /* Serialize flush requests to the device. */
+       struct mutex flush_lock;
+
        /* nvdimm bus registers virtio pmem device */
        struct nvdimm_bus *nvdimm_bus;
        struct nvdimm_bus_descriptor nd_desc;