Skip to content

Commit 0921ddd

Browse files
mikechristiemstsirkin
authored andcommitted
vhost: take worker or vq instead of dev for queueing
This patch has the core work queueing function take a worker for when we support multiple workers. It also adds a helper that takes a vq during queueing so modules can control which vq/worker to queue work on. This temp leaves vhost_work_queue. It will be removed when the drivers are converted in the next patches. Signed-off-by: Mike Christie <michael.christie@oracle.com> Message-Id: <20230626232307.97930-6-michael.christie@oracle.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 9784df1 commit 0921ddd

2 files changed

Lines changed: 29 additions & 16 deletions

File tree

drivers/vhost/vhost.c

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -231,21 +231,10 @@ void vhost_poll_stop(struct vhost_poll *poll)
231231
}
232232
EXPORT_SYMBOL_GPL(vhost_poll_stop);
233233

234-
void vhost_dev_flush(struct vhost_dev *dev)
234+
static bool vhost_worker_queue(struct vhost_worker *worker,
235+
struct vhost_work *work)
235236
{
236-
struct vhost_flush_struct flush;
237-
238-
init_completion(&flush.wait_event);
239-
vhost_work_init(&flush.work, vhost_flush_work);
240-
241-
if (vhost_work_queue(dev, &flush.work))
242-
wait_for_completion(&flush.wait_event);
243-
}
244-
EXPORT_SYMBOL_GPL(vhost_dev_flush);
245-
246-
bool vhost_work_queue(struct vhost_dev *dev, struct vhost_work *work)
247-
{
248-
if (!dev->worker)
237+
if (!worker)
249238
return false;
250239
/*
251240
* vsock can queue while we do a VHOST_SET_OWNER, so we have a smp_wmb
@@ -257,14 +246,37 @@ bool vhost_work_queue(struct vhost_dev *dev, struct vhost_work *work)
257246
* sure it was not in the list.
258247
* test_and_set_bit() implies a memory barrier.
259248
*/
260-
llist_add(&work->node, &dev->worker->work_list);
261-
vhost_task_wake(dev->worker->vtsk);
249+
llist_add(&work->node, &worker->work_list);
250+
vhost_task_wake(worker->vtsk);
262251
}
263252

264253
return true;
265254
}
255+
256+
bool vhost_work_queue(struct vhost_dev *dev, struct vhost_work *work)
257+
{
258+
return vhost_worker_queue(dev->worker, work);
259+
}
266260
EXPORT_SYMBOL_GPL(vhost_work_queue);
267261

262+
bool vhost_vq_work_queue(struct vhost_virtqueue *vq, struct vhost_work *work)
263+
{
264+
return vhost_worker_queue(vq->worker, work);
265+
}
266+
EXPORT_SYMBOL_GPL(vhost_vq_work_queue);
267+
268+
void vhost_dev_flush(struct vhost_dev *dev)
269+
{
270+
struct vhost_flush_struct flush;
271+
272+
init_completion(&flush.wait_event);
273+
vhost_work_init(&flush.work, vhost_flush_work);
274+
275+
if (vhost_work_queue(dev, &flush.work))
276+
wait_for_completion(&flush.wait_event);
277+
}
278+
EXPORT_SYMBOL_GPL(vhost_dev_flush);
279+
268280
/* A lockless hint for busy polling code to exit the loop */
269281
bool vhost_vq_has_work(struct vhost_virtqueue *vq)
270282
{

drivers/vhost/vhost.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ int vhost_get_vq_desc(struct vhost_virtqueue *,
198198
struct vhost_log *log, unsigned int *log_num);
199199
void vhost_discard_vq_desc(struct vhost_virtqueue *, int n);
200200

201+
bool vhost_vq_work_queue(struct vhost_virtqueue *vq, struct vhost_work *work);
201202
bool vhost_vq_has_work(struct vhost_virtqueue *vq);
202203
bool vhost_vq_is_setup(struct vhost_virtqueue *vq);
203204
int vhost_vq_init_access(struct vhost_virtqueue *);

0 commit comments

Comments
 (0)