[v2] vhost: fix missing virtqueue status check in async path

Message ID 20200721033557.3372262-1-patrick.fu@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series [v2] vhost: fix missing virtqueue status check in async path |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-broadcom-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-intel-Performance success Performance Testing PASS
ci/travis-robot success Travis build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-testing success Testing PASS

Commit Message

Patrick Fu July 21, 2020, 3:35 a.m. UTC
  From: Patrick Fu <patrick.fu@intel.com>

Vring should not be touched if vq is disabled. This patch adds the vq
status check in async enqueue polling to avoid accessing to a disabled
queue.

Fixes: cd6760da1076 ("vhost: introduce async enqueue for split ring")

Signed-off-by: Patrick Fu <patrick.fu@intel.com>
---
v2:
 revise commit title

 lib/librte_vhost/virtio_net.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
  

Comments

Maxime Coquelin July 21, 2020, 8:36 a.m. UTC | #1
On 7/21/20 5:35 AM, patrick.fu@intel.com wrote:
> From: Patrick Fu <patrick.fu@intel.com>
> 
> Vring should not be touched if vq is disabled. This patch adds the vq
> status check in async enqueue polling to avoid accessing to a disabled
> queue.
> 
> Fixes: cd6760da1076 ("vhost: introduce async enqueue for split ring")
> 
> Signed-off-by: Patrick Fu <patrick.fu@intel.com>
> ---
> v2:
>  revise commit title
> 
>  lib/librte_vhost/virtio_net.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
> index 1d0be3dd4..b197d76d3 100644
> --- a/lib/librte_vhost/virtio_net.c
> +++ b/lib/librte_vhost/virtio_net.c
> @@ -1686,9 +1686,11 @@ uint16_t rte_vhost_poll_enqueue_completed(int vid, uint16_t queue_id,
>  
>  	if (n_pkts_put) {
>  		vq->async_pkts_inflight_n -= n_pkts_put;
> -		__atomic_add_fetch(&vq->used->idx, n_descs, __ATOMIC_RELEASE);
> -
> -		vhost_vring_call_split(dev, vq);
> +		if (likely(vq->enabled && vq->access_ok)) {
> +			__atomic_add_fetch(&vq->used->idx,
> +					n_descs, __ATOMIC_RELEASE);
> +			vhost_vring_call_split(dev, vq);
> +		}
>  	}
>  
>  	if (start_idx + n_pkts_put <= vq_size) {
> 

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
  
Ferruh Yigit July 21, 2020, 2:53 p.m. UTC | #2
On 7/21/2020 9:36 AM, Maxime Coquelin wrote:
> 
> 
> On 7/21/20 5:35 AM, patrick.fu@intel.com wrote:
>> From: Patrick Fu <patrick.fu@intel.com>
>>
>> Vring should not be touched if vq is disabled. This patch adds the vq
>> status check in async enqueue polling to avoid accessing to a disabled
>> queue.
>>
>> Fixes: cd6760da1076 ("vhost: introduce async enqueue for split ring")
>>
>> Signed-off-by: Patrick Fu <patrick.fu@intel.com>
> 
> Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> 

Applied to dpdk-next-net/master, thanks.
  

Patch

diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
index 1d0be3dd4..b197d76d3 100644
--- a/lib/librte_vhost/virtio_net.c
+++ b/lib/librte_vhost/virtio_net.c
@@ -1686,9 +1686,11 @@  uint16_t rte_vhost_poll_enqueue_completed(int vid, uint16_t queue_id,
 
 	if (n_pkts_put) {
 		vq->async_pkts_inflight_n -= n_pkts_put;
-		__atomic_add_fetch(&vq->used->idx, n_descs, __ATOMIC_RELEASE);
-
-		vhost_vring_call_split(dev, vq);
+		if (likely(vq->enabled && vq->access_ok)) {
+			__atomic_add_fetch(&vq->used->idx,
+					n_descs, __ATOMIC_RELEASE);
+			vhost_vring_call_split(dev, vq);
+		}
 	}
 
 	if (start_idx + n_pkts_put <= vq_size) {