Skip to content

Commit 4d0efa6

Browse files
vireshkmstsirkin
authored andcommitted
virtio-vdpa: Remove virtqueue list
The virtio vdpa implementation creates a list of virtqueues, while the same is already available in the struct virtio_device. This list is never traversed though, and only the pointer to the struct virtio_vdpa_vq_info is used in the callback, where the virtqueue pointer could be directly used. Remove the unwanted code to simplify the driver. Signed-off-by: Viresh Kumar <[email protected]> Message-Id: <7808f2f7e484987b95f172fffb6c71a5da20ed1e.1748503784.git.viresh.kumar@linaro.org> Signed-off-by: Michael S. Tsirkin <[email protected]> Acked-by: Eugenio Pérez <[email protected]>
1 parent 564a69a commit 4d0efa6

File tree

1 file changed

+3
-41
lines changed

1 file changed

+3
-41
lines changed

drivers/virtio/virtio_vdpa.c

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,6 @@ struct virtio_vdpa_device {
2828
struct virtio_device vdev;
2929
struct vdpa_device *vdpa;
3030
u64 features;
31-
32-
/* The lock to protect virtqueue list */
33-
spinlock_t lock;
34-
/* List of virtio_vdpa_vq_info */
35-
struct list_head virtqueues;
36-
};
37-
38-
struct virtio_vdpa_vq_info {
39-
/* the actual virtqueue */
40-
struct virtqueue *vq;
41-
42-
/* the list node for the virtqueues list */
43-
struct list_head node;
4431
};
4532

4633
static inline struct virtio_vdpa_device *
@@ -135,28 +122,25 @@ static irqreturn_t virtio_vdpa_config_cb(void *private)
135122

136123
static irqreturn_t virtio_vdpa_virtqueue_cb(void *private)
137124
{
138-
struct virtio_vdpa_vq_info *info = private;
125+
struct virtqueue *vq = private;
139126

140-
return vring_interrupt(0, info->vq);
127+
return vring_interrupt(0, vq);
141128
}
142129

143130
static struct virtqueue *
144131
virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
145132
void (*callback)(struct virtqueue *vq),
146133
const char *name, bool ctx)
147134
{
148-
struct virtio_vdpa_device *vd_dev = to_virtio_vdpa_device(vdev);
149135
struct vdpa_device *vdpa = vd_get_vdpa(vdev);
150136
struct device *dma_dev;
151137
const struct vdpa_config_ops *ops = vdpa->config;
152-
struct virtio_vdpa_vq_info *info;
153138
bool (*notify)(struct virtqueue *vq) = virtio_vdpa_notify;
154139
struct vdpa_callback cb;
155140
struct virtqueue *vq;
156141
u64 desc_addr, driver_addr, device_addr;
157142
/* Assume split virtqueue, switch to packed if necessary */
158143
struct vdpa_vq_state state = {0};
159-
unsigned long flags;
160144
u32 align, max_num, min_num = 1;
161145
bool may_reduce_num = true;
162146
int err;
@@ -179,10 +163,6 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
179163
if (ops->get_vq_ready(vdpa, index))
180164
return ERR_PTR(-ENOENT);
181165

182-
/* Allocate and fill out our active queue description */
183-
info = kmalloc(sizeof(*info), GFP_KERNEL);
184-
if (!info)
185-
return ERR_PTR(-ENOMEM);
186166
if (ops->get_vq_size)
187167
max_num = ops->get_vq_size(vdpa, index);
188168
else
@@ -217,7 +197,7 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
217197

218198
/* Setup virtqueue callback */
219199
cb.callback = callback ? virtio_vdpa_virtqueue_cb : NULL;
220-
cb.private = info;
200+
cb.private = vq;
221201
cb.trigger = NULL;
222202
ops->set_vq_cb(vdpa, index, &cb);
223203
ops->set_vq_num(vdpa, index, virtqueue_get_vring_size(vq));
@@ -248,13 +228,6 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
248228

249229
ops->set_vq_ready(vdpa, index, 1);
250230

251-
vq->priv = info;
252-
info->vq = vq;
253-
254-
spin_lock_irqsave(&vd_dev->lock, flags);
255-
list_add(&info->node, &vd_dev->virtqueues);
256-
spin_unlock_irqrestore(&vd_dev->lock, flags);
257-
258231
return vq;
259232

260233
err_vq:
@@ -263,7 +236,6 @@ virtio_vdpa_setup_vq(struct virtio_device *vdev, unsigned int index,
263236
ops->set_vq_ready(vdpa, index, 0);
264237
/* VDPA driver should make sure vq is stopeed here */
265238
WARN_ON(ops->get_vq_ready(vdpa, index));
266-
kfree(info);
267239
return ERR_PTR(err);
268240
}
269241

@@ -272,20 +244,12 @@ static void virtio_vdpa_del_vq(struct virtqueue *vq)
272244
struct virtio_vdpa_device *vd_dev = to_virtio_vdpa_device(vq->vdev);
273245
struct vdpa_device *vdpa = vd_dev->vdpa;
274246
const struct vdpa_config_ops *ops = vdpa->config;
275-
struct virtio_vdpa_vq_info *info = vq->priv;
276247
unsigned int index = vq->index;
277-
unsigned long flags;
278-
279-
spin_lock_irqsave(&vd_dev->lock, flags);
280-
list_del(&info->node);
281-
spin_unlock_irqrestore(&vd_dev->lock, flags);
282248

283249
/* Select and deactivate the queue (best effort) */
284250
ops->set_vq_ready(vdpa, index, 0);
285251

286252
vring_del_virtqueue(vq);
287-
288-
kfree(info);
289253
}
290254

291255
static void virtio_vdpa_del_vqs(struct virtio_device *vdev)
@@ -501,8 +465,6 @@ static int virtio_vdpa_probe(struct vdpa_device *vdpa)
501465
vd_dev->vdev.dev.release = virtio_vdpa_release_dev;
502466
vd_dev->vdev.config = &virtio_vdpa_config_ops;
503467
vd_dev->vdpa = vdpa;
504-
INIT_LIST_HEAD(&vd_dev->virtqueues);
505-
spin_lock_init(&vd_dev->lock);
506468

507469
vd_dev->vdev.id.device = ops->get_device_id(vdpa);
508470
if (vd_dev->vdev.id.device == 0)

0 commit comments

Comments
 (0)