[v5 1/5] vhost: skip crypto op fetch before vring init

Maxime Coquelin maxime.coquelin at redhat.com
Tue Feb 25 17:17:53 CET 2025



On 2/24/25 11:35 AM, Gowrishankar Muthukrishnan wrote:
> Until virtio avail ring is initialized (by VHOST_USER_SET_VRING_ADDR),
> worker thread should not try to fetch crypto op, which would lead to
> memory fault.
> 
> Fixes: 939066d96563 ("vhost/crypto: add public function implementation")
> Cc: stable at dpdk.org
> 
> Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn at marvell.com>
> Acked-by: Akhil Goyal <gakhil at marvell.com>
> ---
>   lib/vhost/vhost_crypto.c | 10 ++++++++++
>   1 file changed, 10 insertions(+)
> 
> diff --git a/lib/vhost/vhost_crypto.c b/lib/vhost/vhost_crypto.c
> index 3dc41a3bd5..55ea24710e 100644
> --- a/lib/vhost/vhost_crypto.c
> +++ b/lib/vhost/vhost_crypto.c
> @@ -1580,6 +1580,16 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid,
>   
>   	vq = dev->virtqueue[qid];
>   
> +	if (unlikely(vq == NULL)) {
> +		VC_LOG_ERR("Invalid virtqueue %u", qid);
> +		return 0;
> +	}
> +
> +	if (unlikely(vq->avail == NULL)) {
> +		VC_LOG_DBG("Virtqueue ring not yet initialized %u", qid);
> +		return 0;
> +	}
> +

I think the proper fix to:
1. acquire the access_lock as reader
2. check whether vq is enabled
3. acquire the iotlb lock as a reader
4. check vq's access_ok

You can have a look at rte_vhost_dequeue_burst for example.

>   	avail_idx = *((volatile uint16_t *)&vq->avail->idx);
>   	start_idx = vq->last_used_idx;
>   	count = avail_idx - start_idx;



More information about the stable mailing list