vhost: add non-blocking API for posting interrupt

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: c573699830 ("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>
This commit is contained in:
Changpeng Liu 2022-10-17 15:48:17 +08:00 committed by Chenbo Xia
parent 974f216bf9
commit 830f7e7907
5 changed files with 58 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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.
*

View File

@ -97,6 +97,7 @@ EXPERIMENTAL {
# added in 22.11
rte_vhost_async_dma_unconfigure;
rte_vhost_vring_call_nonblock;
};
INTERNAL {

View File

@ -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)
{