[v1] vhost: add vq status check in async enqueue poll

Message ID 20200716153010.2894802-1-patrick.fu@intel.com (mailing list archive)
State Changes Requested, archived
Delegated to: Maxime Coquelin
Headers
Series [v1] vhost: add vq status check in async enqueue poll |

Checks

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

Commit Message

Patrick Fu July 16, 2020, 3:30 p.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>
---
 lib/librte_vhost/virtio_net.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
  

Comments

Chenbo Xia July 17, 2020, 8:09 a.m. UTC | #1
> -----Original Message-----
> From: Fu, Patrick <patrick.fu@intel.com>
> Sent: Thursday, July 16, 2020 11:30 PM
> To: dev@dpdk.org; maxime.coquelin@redhat.com; Xia, Chenbo
> <chenbo.xia@intel.com>
> Cc: Fu, Patrick <patrick.fu@intel.com>
> Subject: [PATCH v1] vhost: add vq status check in async enqueue poll
> 
> 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>
> ---
>  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) {
> --
> 2.18.4

Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
  
Ferruh Yigit July 17, 2020, 1:09 p.m. UTC | #2
On 7/17/2020 9:09 AM, Xia, Chenbo wrote:
> 
>> -----Original Message-----
>> From: Fu, Patrick <patrick.fu@intel.com>
>> Sent: Thursday, July 16, 2020 11:30 PM
>> To: dev@dpdk.org; maxime.coquelin@redhat.com; Xia, Chenbo
>> <chenbo.xia@intel.com>
>> Cc: Fu, Patrick <patrick.fu@intel.com>
>> Subject: [PATCH v1] vhost: add vq status check in async enqueue poll
>>
>> From: Patrick Fu <patrick.fu@intel.com>
> 
> Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
> 

Applied to dpdk-next-net/master, thanks.
  
Maxime Coquelin July 20, 2020, 3:57 p.m. UTC | #3
What about this commit title?
vhost: fix missing virtqueue status check in async path

On 7/16/20 5:30 PM, 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>
> ---
>  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) {
>
  
Ferruh Yigit July 20, 2020, 4:49 p.m. UTC | #4
On 7/20/2020 4:57 PM, Maxime Coquelin wrote:
> What about this commit title?
> vhost: fix missing virtqueue status check in async path

Existing commit dropped from next-net and patchwork status updated.

> 
> On 7/16/20 5:30 PM, 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>

<...>
  
Patrick Fu July 21, 2020, 3:38 a.m. UTC | #5
V2 patch sent with revised title

> -----Original Message-----
> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> Sent: Monday, July 20, 2020 11:58 PM
> To: Fu, Patrick <patrick.fu@intel.com>; dev@dpdk.org; Xia, Chenbo
> <chenbo.xia@intel.com>
> Subject: Re: [PATCH v1] vhost: add vq status check in async enqueue poll
> 
> What about this commit title?
> vhost: fix missing virtqueue status check in async path
> 
> On 7/16/20 5:30 PM, 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>
> > ---
> >  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) {
> >
  

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