Skip to content

Commit

Permalink
vhost: add non-blocking API for posting interrupt
Browse files Browse the repository at this point in the history
[ upstream commit 830f7e7 ]

Vhost-user library locks all VQ's access lock when processing
vring based messages, such as SET_VRING_KICK and SET_VRING_CALL,
and the data processing thread may already be started, e.g: SPDK
vhost-blk and vhost-scsi will start the data processing thread
when one vring is ready, then deadlock may happen when SPDK is
posting interrupts to VM.  Here, we add a new API which allows
caller to try again later for this case.

Bugzilla ID: 1015
Fixes: c573699 ("vhost: fix missing virtqueue lock protection")

Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
  • Loading branch information
changpe1 authored and kevintraynor committed Nov 7, 2022
1 parent a38a7de commit a5ff9eb
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/guides/prog_guide/vhost_lib.rst
Expand Up @@ -303,6 +303,12 @@ The following is an overview of some key Vhost API functions:
Clear inflight packets which are submitted to DMA engine in vhost async data
path. Completed packets are returned to applications through ``pkts``.

* ``rte_vhost_vring_call_nonblock(int vid, uint16_t vring_idx)``

Notify the guest that used descriptors have been added to the vring. This function
will return -EAGAIN when vq's access lock is held by other thread, user should try
again later.

Vhost-user Implementations
--------------------------

Expand Down
15 changes: 15 additions & 0 deletions lib/vhost/rte_vhost.h
Expand Up @@ -918,6 +918,21 @@ rte_vhost_clr_inflight_desc_packed(int vid, uint16_t vring_idx,
*/
int rte_vhost_vring_call(int vid, uint16_t vring_idx);

/**
* Notify the guest that used descriptors have been added to the vring. This
* function acts as a memory barrier. This function will return -EAGAIN when
* vq's access lock is held by other thread, user should try again later.
*
* @param vid
* vhost device ID
* @param vring_idx
* vring index
* @return
* 0 on success, -1 on failure, -EAGAIN for another retry
*/
__rte_experimental
int rte_vhost_vring_call_nonblock(int vid, uint16_t vring_idx);

/**
* Get vhost RX queue avail count.
*
Expand Down
1 change: 1 addition & 0 deletions lib/vhost/version.map
Expand Up @@ -84,6 +84,7 @@ EXPERIMENTAL {

# added in 21.11
rte_vhost_get_monitor_addr;
rte_vhost_vring_call_nonblock;
};

INTERNAL {
Expand Down
30 changes: 30 additions & 0 deletions lib/vhost/vhost.c
Expand Up @@ -1311,6 +1311,36 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx)
return 0;
}

int
rte_vhost_vring_call_nonblock(int vid, uint16_t vring_idx)
{
struct virtio_net *dev;
struct vhost_virtqueue *vq;

dev = get_device(vid);
if (!dev)
return -1;

if (vring_idx >= VHOST_MAX_VRING)
return -1;

vq = dev->virtqueue[vring_idx];
if (!vq)
return -1;

if (!rte_spinlock_trylock(&vq->access_lock))
return -EAGAIN;

if (vq_is_packed(dev))
vhost_vring_call_packed(dev, vq);
else
vhost_vring_call_split(dev, vq);

rte_spinlock_unlock(&vq->access_lock);

return 0;
}

uint16_t
rte_vhost_avail_entries(int vid, uint16_t queue_id)
{
Expand Down

0 comments on commit a5ff9eb

Please sign in to comment.