]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
vdpa_sim: make devices agnostic for work management
authorStefano Garzarella <sgarzare@redhat.com>
Tue, 4 Apr 2023 13:17:21 +0000 (15:17 +0200)
committerMichael S. Tsirkin <mst@redhat.com>
Fri, 21 Apr 2023 07:02:33 +0000 (03:02 -0400)
Let's move work management inside the vdpa_sim core.
This way we can easily change how we manage the works, without
having to change the devices each time.

Acked-by: Eugenio Pérez Martin <eperezma@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Message-Id: <20230404131721.45886-1-sgarzare@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
drivers/vdpa/vdpa_sim/vdpa_sim.c
drivers/vdpa/vdpa_sim/vdpa_sim.h
drivers/vdpa/vdpa_sim/vdpa_sim_blk.c
drivers/vdpa/vdpa_sim/vdpa_sim_net.c

index eea23c630f7c08d3abc33ef463529bde775e64b8..2df5227e0b628e94639e66bc2e09b539ab5b3e06 100644 (file)
@@ -127,6 +127,13 @@ static void vdpasim_do_reset(struct vdpasim *vdpasim)
 static const struct vdpa_config_ops vdpasim_config_ops;
 static const struct vdpa_config_ops vdpasim_batch_config_ops;
 
+static void vdpasim_work_fn(struct work_struct *work)
+{
+       struct vdpasim *vdpasim = container_of(work, struct vdpasim, work);
+
+       vdpasim->dev_attr.work_fn(vdpasim);
+}
+
 struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr,
                               const struct vdpa_dev_set_config *config)
 {
@@ -163,7 +170,7 @@ struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr,
 
        vdpasim = vdpa_to_sim(vdpa);
        vdpasim->dev_attr = *dev_attr;
-       INIT_WORK(&vdpasim->work, dev_attr->work_fn);
+       INIT_WORK(&vdpasim->work, vdpasim_work_fn);
        spin_lock_init(&vdpasim->lock);
        spin_lock_init(&vdpasim->iommu_lock);
 
@@ -214,6 +221,12 @@ err_alloc:
 }
 EXPORT_SYMBOL_GPL(vdpasim_create);
 
+void vdpasim_schedule_work(struct vdpasim *vdpasim)
+{
+       schedule_work(&vdpasim->work);
+}
+EXPORT_SYMBOL_GPL(vdpasim_schedule_work);
+
 static int vdpasim_set_vq_address(struct vdpa_device *vdpa, u16 idx,
                                  u64 desc_area, u64 driver_area,
                                  u64 device_area)
@@ -248,7 +261,7 @@ static void vdpasim_kick_vq(struct vdpa_device *vdpa, u16 idx)
        }
 
        if (vq->ready)
-               schedule_work(&vdpasim->work);
+               vdpasim_schedule_work(vdpasim);
 }
 
 static void vdpasim_set_vq_cb(struct vdpa_device *vdpa, u16 idx,
index 144858636c10aa426db65721b110b6ac51ce811a..acee20faaf6aaa5463189bc7b3fa69cf278ac678 100644 (file)
@@ -45,7 +45,7 @@ struct vdpasim_dev_attr {
        u32 ngroups;
        u32 nas;
 
-       work_func_t work_fn;
+       void (*work_fn)(struct vdpasim *vdpasim);
        void (*get_config)(struct vdpasim *vdpasim, void *config);
        void (*set_config)(struct vdpasim *vdpasim, const void *config);
        int (*get_stats)(struct vdpasim *vdpasim, u16 idx,
@@ -78,6 +78,7 @@ struct vdpasim {
 
 struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *attr,
                               const struct vdpa_dev_set_config *config);
+void vdpasim_schedule_work(struct vdpasim *vdpasim);
 
 /* TODO: cross-endian support */
 static inline bool vdpasim_is_little_endian(struct vdpasim *vdpasim)
index 5117959bed8a2c847df8cec3a847e9f08855170f..eb4897c8541e9ad6d120769850be3b4897bdef5a 100644 (file)
@@ -11,7 +11,6 @@
 #include <linux/module.h>
 #include <linux/device.h>
 #include <linux/kernel.h>
-#include <linux/sched.h>
 #include <linux/blkdev.h>
 #include <linux/vringh.h>
 #include <linux/vdpa.h>
@@ -286,9 +285,8 @@ err:
        return handled;
 }
 
-static void vdpasim_blk_work(struct work_struct *work)
+static void vdpasim_blk_work(struct vdpasim *vdpasim)
 {
-       struct vdpasim *vdpasim = container_of(work, struct vdpasim, work);
        bool reschedule = false;
        int i;
 
@@ -326,7 +324,7 @@ out:
        spin_unlock(&vdpasim->lock);
 
        if (reschedule)
-               schedule_work(&vdpasim->work);
+               vdpasim_schedule_work(vdpasim);
 }
 
 static void vdpasim_blk_get_config(struct vdpasim *vdpasim, void *config)
index dfe2ce34180356e408cb129a9ce0be77461bd64d..30ac41c5827ec2d4533f0ab780c06471d32dbc17 100644 (file)
@@ -11,7 +11,6 @@
 #include <linux/module.h>
 #include <linux/device.h>
 #include <linux/kernel.h>
-#include <linux/sched.h>
 #include <linux/etherdevice.h>
 #include <linux/vringh.h>
 #include <linux/vdpa.h>
@@ -192,9 +191,8 @@ static void vdpasim_handle_cvq(struct vdpasim *vdpasim)
        u64_stats_update_end(&net->cq_stats.syncp);
 }
 
-static void vdpasim_net_work(struct work_struct *work)
+static void vdpasim_net_work(struct vdpasim *vdpasim)
 {
-       struct vdpasim *vdpasim = container_of(work, struct vdpasim, work);
        struct vdpasim_virtqueue *txq = &vdpasim->vqs[1];
        struct vdpasim_virtqueue *rxq = &vdpasim->vqs[0];
        struct vdpasim_net *net = sim_to_net(vdpasim);
@@ -260,7 +258,7 @@ static void vdpasim_net_work(struct work_struct *work)
                vdpasim_net_complete(rxq, write);
 
                if (tx_pkts > 4) {
-                       schedule_work(&vdpasim->work);
+                       vdpasim_schedule_work(vdpasim);
                        goto out;
                }
        }