Skip to content

Commit

Permalink
vhost: add non-blocking API for posting interrupt
Browse files Browse the repository at this point in the history
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")
Cc: stable@dpdk.org

Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
  • Loading branch information
Changpeng Liu authored and chenbo-xia committed Oct 26, 2022
1 parent 974f216 commit 830f7e7
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/guides/prog_guide/vhost_lib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,12 @@ The following is an overview of some key Vhost API functions:
Clear in-flight packets which are submitted to async channel 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.

* ``rte_vhost_vring_stats_get_names(int vid, uint16_t queue_id, struct rte_vhost_stat_name *names, unsigned int size)``

This function returns the names of the queue statistics. It requires
Expand Down
6 changes: 6 additions & 0 deletions doc/guides/rel_notes/release_22_11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ New Features
Added support to unconfigure DMA vChannel that is no longer used
by the vhost library.

* **Added non-blocking notify API to vhost library.**

Added ``rte_vhost_vring_call_nonblock`` API to notify the guest that
used descriptors have been added to the vring in non-blocking way.
User should check the return value of this API and try again if needed.

* **Added support for MACsec in rte_security.**

Added MACsec transform for rte_security session and added new API
Expand Down
15 changes: 15 additions & 0 deletions lib/vhost/rte_vhost.h
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,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
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ EXPERIMENTAL {

# added in 22.11
rte_vhost_async_dma_unconfigure;
rte_vhost_vring_call_nonblock;
};

INTERNAL {
Expand Down
30 changes: 30 additions & 0 deletions lib/vhost/vhost.c
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,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 830f7e7

Please sign in to comment.