[v2,1/5] vhost: fix missing virtqueue lock protection

Message ID 20220324124638.32672-2-maxime.coquelin@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Maxime Coquelin
Headers
Series vhost: introduce per-virtqueue stats API |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Maxime Coquelin March 24, 2022, 12:46 p.m. UTC
  This patch ensures virtqueue metadata are not being
modified while rte_vhost_vring_call() is executed.

Fixes: 6c299bb7322f ("vhost: introduce vring call API")
Cc: stable@dpdk.org

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 lib/vhost/vhost.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

David Marchand March 28, 2022, 8:07 a.m. UTC | #1
On Thu, Mar 24, 2022 at 1:46 PM Maxime Coquelin
<maxime.coquelin@redhat.com> wrote:
>
> This patch ensures virtqueue metadata are not being
> modified while rte_vhost_vring_call() is executed.
>
> Fixes: 6c299bb7322f ("vhost: introduce vring call API")
> Cc: stable@dpdk.org
>
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> ---
>  lib/vhost/vhost.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
> index bc88148347..2f96a28dac 100644
> --- a/lib/vhost/vhost.c
> +++ b/lib/vhost/vhost.c
> @@ -1291,11 +1291,15 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx)
>         if (!vq)
>                 return -1;
>
> +       rte_spinlock_lock(&vq->access_lock);
> +
>         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;
>  }
>

Reviewed-by: David Marchand <david.marchand@redhat.com>

You can probably merge quickly this fix regardless of the rest of the
stats series.
It would help me with a series of mine that annotates vhost locks.
  
Maxime Coquelin March 28, 2022, 2:59 p.m. UTC | #2
On 3/28/22 10:07, David Marchand wrote:
> On Thu, Mar 24, 2022 at 1:46 PM Maxime Coquelin
> <maxime.coquelin@redhat.com> wrote:
>>
>> This patch ensures virtqueue metadata are not being
>> modified while rte_vhost_vring_call() is executed.
>>
>> Fixes: 6c299bb7322f ("vhost: introduce vring call API")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
>> ---
>>   lib/vhost/vhost.c | 4 ++++
>>   1 file changed, 4 insertions(+)
>>
>> diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
>> index bc88148347..2f96a28dac 100644
>> --- a/lib/vhost/vhost.c
>> +++ b/lib/vhost/vhost.c
>> @@ -1291,11 +1291,15 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx)
>>          if (!vq)
>>                  return -1;
>>
>> +       rte_spinlock_lock(&vq->access_lock);
>> +
>>          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;
>>   }
>>
> 
> Reviewed-by: David Marchand <david.marchand@redhat.com>
> 
> You can probably merge quickly this fix regardless of the rest of the
> stats series.
> It would help me with a series of mine that annotates vhost locks.
> 
> 

Thanks for the review.

Applied this single patch to next-virtio tree.

Maxime
  

Patch

diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
index bc88148347..2f96a28dac 100644
--- a/lib/vhost/vhost.c
+++ b/lib/vhost/vhost.c
@@ -1291,11 +1291,15 @@  rte_vhost_vring_call(int vid, uint16_t vring_idx)
 	if (!vq)
 		return -1;
 
+	rte_spinlock_lock(&vq->access_lock);
+
 	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;
 }