diff mbox series

vhost: fix invalid use of stored last used index

Message ID 83fa6253725a7bc69bccb7897f380422354a2898.1621008025.git.bnemeth@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Maxime Coquelin
Headers show
Series vhost: fix invalid use of stored last used index | expand

Checks

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

Commit Message

Balazs Nemeth May 14, 2021, 4:02 p.m. UTC
The optimization introduced by commit d18db8049c7c ("vhost: read last
used index once") didn't account for the fact that
vhost_flush_enqueue_shadow_packed increments the last_used_idx. For this
reason, store last_used_idx after the potential call to
vhost_flush_enqueue_shadow_packed.

Fixes: d18db8049c7c ("vhost: read last used index once")
Signed-off-by: Balazs Nemeth <bnemeth@redhat.com>
---
 lib/vhost/virtio_net.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

David Marchand May 15, 2021, 6:10 a.m. UTC | #1
On Fri, May 14, 2021 at 6:02 PM Balazs Nemeth <bnemeth@redhat.com> wrote:
>
> The optimization introduced by commit d18db8049c7c ("vhost: read last
> used index once") didn't account for the fact that
> vhost_flush_enqueue_shadow_packed increments the last_used_idx. For this
> reason, store last_used_idx after the potential call to
> vhost_flush_enqueue_shadow_packed.
>

Bugzilla ID: 699
> Fixes: d18db8049c7c ("vhost: read last used index once")

> Signed-off-by: Balazs Nemeth <bnemeth@redhat.com>
Reviewed-by: David Marchand <david.marchand@redhat.com>
Maxime Coquelin May 17, 2021, 7:37 a.m. UTC | #2
Hi Ling,


On 5/14/21 6:02 PM, Balazs Nemeth wrote:
> The optimization introduced by commit d18db8049c7c ("vhost: read last
> used index once") didn't account for the fact that
> vhost_flush_enqueue_shadow_packed increments the last_used_idx. For this
> reason, store last_used_idx after the potential call to
> vhost_flush_enqueue_shadow_packed.
> 
> Fixes: d18db8049c7c ("vhost: read last used index once")
> Signed-off-by: Balazs Nemeth <bnemeth@redhat.com>
> ---
>  lib/vhost/virtio_net.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
> index abfd67d38c..8da8a86a10 100644
> --- a/lib/vhost/virtio_net.c
> +++ b/lib/vhost/virtio_net.c
> @@ -218,14 +218,17 @@ vhost_flush_enqueue_batch_packed(struct virtio_net *dev,
>  {
>  	uint16_t i;
>  	uint16_t flags;
> -	uint16_t last_used_idx = vq->last_used_idx;
> -	struct vring_packed_desc *desc_base = &vq->desc_packed[last_used_idx];
> +	uint16_t last_used_idx;
> +	struct vring_packed_desc *desc_base;
>  
>  	if (vq->shadow_used_idx) {
>  		do_data_copy_enqueue(dev, vq);
>  		vhost_flush_enqueue_shadow_packed(dev, vq);
>  	}
>  
> +	last_used_idx = vq->last_used_idx;
> +	desc_base = &vq->desc_packed[last_used_idx];
> +
>  	flags = PACKED_DESC_ENQUEUE_USED_FLAG(vq->used_wrap_counter);
>  
>  	vhost_for_each_try_unroll(i, 0, PACKED_BATCH_SIZE) {
> 

Could you please confirm the patch fixes the issue you reported?

Thanks,
Maxime
Ling, WeiX May 17, 2021, 10:07 a.m. UTC | #3
> -----Original Message-----
> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> Sent: Monday, May 17, 2021 03:38 PM
> To: Balazs Nemeth <bnemeth@redhat.com>; dev@dpdk.org; Ling, WeiX
> <weix.ling@intel.com>
> Subject: Re: [dpdk-dev] [PATCH] vhost: fix invalid use of stored last used
> index
> 
> Hi Ling,
> 
> 
> On 5/14/21 6:02 PM, Balazs Nemeth wrote:
> > The optimization introduced by commit d18db8049c7c ("vhost: read last
> > used index once") didn't account for the fact that
> > vhost_flush_enqueue_shadow_packed increments the last_used_idx. For
> > this reason, store last_used_idx after the potential call to
> > vhost_flush_enqueue_shadow_packed.
> >
> > Fixes: d18db8049c7c ("vhost: read last used index once")
> > Signed-off-by: Balazs Nemeth <bnemeth@redhat.com>
> > ---
> >  lib/vhost/virtio_net.c | 7 +++++--
> >  1 file changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index
> > abfd67d38c..8da8a86a10 100644
> > --- a/lib/vhost/virtio_net.c
> > +++ b/lib/vhost/virtio_net.c
> > @@ -218,14 +218,17 @@ vhost_flush_enqueue_batch_packed(struct
> > virtio_net *dev,  {
> >  	uint16_t i;
> >  	uint16_t flags;
> > -	uint16_t last_used_idx = vq->last_used_idx;
> > -	struct vring_packed_desc *desc_base = &vq-
> >desc_packed[last_used_idx];
> > +	uint16_t last_used_idx;
> > +	struct vring_packed_desc *desc_base;
> >
> >  	if (vq->shadow_used_idx) {
> >  		do_data_copy_enqueue(dev, vq);
> >  		vhost_flush_enqueue_shadow_packed(dev, vq);
> >  	}
> >
> > +	last_used_idx = vq->last_used_idx;
> > +	desc_base = &vq->desc_packed[last_used_idx];
> > +
> >  	flags = PACKED_DESC_ENQUEUE_USED_FLAG(vq-
> >used_wrap_counter);
> >
> >  	vhost_for_each_try_unroll(i, 0, PACKED_BATCH_SIZE) {
> >
> 
> Could you please confirm the patch fixes the issue you reported?
> 
> Thanks,
> Maxime

Hi Maxime,

Apply your patch https://patches.dpdk.org/project/dpdk/patch/83fa6253725a7bc69bccb7897f380422354a2898.1621008025.git.bnemeth@redhat.com/ based on DPDK-21.05-rc3(7989b7e7da9b), tested PASSED.

Regards,
Ling Wei
Maxime Coquelin May 17, 2021, 10:46 a.m. UTC | #4
On 5/17/21 12:07 PM, Ling, WeiX wrote:
>> -----Original Message-----
>> From: Maxime Coquelin <maxime.coquelin@redhat.com>
>> Sent: Monday, May 17, 2021 03:38 PM
>> To: Balazs Nemeth <bnemeth@redhat.com>; dev@dpdk.org; Ling, WeiX
>> <weix.ling@intel.com>
>> Subject: Re: [dpdk-dev] [PATCH] vhost: fix invalid use of stored last used
>> index
>>
>> Hi Ling,
>>
>>
>> On 5/14/21 6:02 PM, Balazs Nemeth wrote:
>>> The optimization introduced by commit d18db8049c7c ("vhost: read last
>>> used index once") didn't account for the fact that
>>> vhost_flush_enqueue_shadow_packed increments the last_used_idx. For
>>> this reason, store last_used_idx after the potential call to
>>> vhost_flush_enqueue_shadow_packed.
>>>
>>> Fixes: d18db8049c7c ("vhost: read last used index once")
>>> Signed-off-by: Balazs Nemeth <bnemeth@redhat.com>
>>> ---
>>>  lib/vhost/virtio_net.c | 7 +++++--
>>>  1 file changed, 5 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index
>>> abfd67d38c..8da8a86a10 100644
>>> --- a/lib/vhost/virtio_net.c
>>> +++ b/lib/vhost/virtio_net.c
>>> @@ -218,14 +218,17 @@ vhost_flush_enqueue_batch_packed(struct
>>> virtio_net *dev,  {
>>>  	uint16_t i;
>>>  	uint16_t flags;
>>> -	uint16_t last_used_idx = vq->last_used_idx;
>>> -	struct vring_packed_desc *desc_base = &vq-
>>> desc_packed[last_used_idx];
>>> +	uint16_t last_used_idx;
>>> +	struct vring_packed_desc *desc_base;
>>>
>>>  	if (vq->shadow_used_idx) {
>>>  		do_data_copy_enqueue(dev, vq);
>>>  		vhost_flush_enqueue_shadow_packed(dev, vq);
>>>  	}
>>>
>>> +	last_used_idx = vq->last_used_idx;
>>> +	desc_base = &vq->desc_packed[last_used_idx];
>>> +
>>>  	flags = PACKED_DESC_ENQUEUE_USED_FLAG(vq-
>>> used_wrap_counter);
>>>
>>>  	vhost_for_each_try_unroll(i, 0, PACKED_BATCH_SIZE) {
>>>
>>
>> Could you please confirm the patch fixes the issue you reported?
>>
>> Thanks,
>> Maxime
> 
> Hi Maxime,
> 
> Apply your patch https://patches.dpdk.org/project/dpdk/patch/83fa6253725a7bc69bccb7897f380422354a2898.1621008025.git.bnemeth@redhat.com/ based on DPDK-21.05-rc3(7989b7e7da9b), tested PASSED.

Thanks for testing with the patch.

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Tested-by: Wei Ling <weix.ling@intel.com>

Thanks,
Maxime


Thanks,
Maxime


> Regards,
> Ling Wei
>
Xia, Chenbo May 18, 2021, 8:03 a.m. UTC | #5
> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Balazs Nemeth
> Sent: Saturday, May 15, 2021 12:02 AM
> To: bnemeth@redhat.com; dev@dpdk.org; Ling, WeiX <weix.ling@intel.com>
> Subject: [dpdk-dev] [PATCH] vhost: fix invalid use of stored last used index
> 
> The optimization introduced by commit d18db8049c7c ("vhost: read last
> used index once") didn't account for the fact that
> vhost_flush_enqueue_shadow_packed increments the last_used_idx. For this
> reason, store last_used_idx after the potential call to
> vhost_flush_enqueue_shadow_packed.
> 
> Fixes: d18db8049c7c ("vhost: read last used index once")
> Signed-off-by: Balazs Nemeth <bnemeth@redhat.com>
> ---
> 2.30.2

Applied to next-virtio/main, thanks
diff mbox series

Patch

diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
index abfd67d38c..8da8a86a10 100644
--- a/lib/vhost/virtio_net.c
+++ b/lib/vhost/virtio_net.c
@@ -218,14 +218,17 @@  vhost_flush_enqueue_batch_packed(struct virtio_net *dev,
 {
 	uint16_t i;
 	uint16_t flags;
-	uint16_t last_used_idx = vq->last_used_idx;
-	struct vring_packed_desc *desc_base = &vq->desc_packed[last_used_idx];
+	uint16_t last_used_idx;
+	struct vring_packed_desc *desc_base;
 
 	if (vq->shadow_used_idx) {
 		do_data_copy_enqueue(dev, vq);
 		vhost_flush_enqueue_shadow_packed(dev, vq);
 	}
 
+	last_used_idx = vq->last_used_idx;
+	desc_base = &vq->desc_packed[last_used_idx];
+
 	flags = PACKED_DESC_ENQUEUE_USED_FLAG(vq->used_wrap_counter);
 
 	vhost_for_each_try_unroll(i, 0, PACKED_BATCH_SIZE) {