[v2,18/21] net/virtio-user: add new callback to enable control queue

Message ID 20230207151747.245808-19-maxime.coquelin@redhat.com (mailing list archive)
State Superseded, archived
Delegated to: Maxime Coquelin
Headers
Series Add control queue & MQ support to Virtio-user vDPA |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Maxime Coquelin Feb. 7, 2023, 3:17 p.m. UTC
  This patch introduces a new callback that is to be called
when the backend supports control virtqueue.

Implementation for Vhost-vDPA backend is added in this patch.

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
---
 drivers/net/virtio/virtio_user/vhost.h           |  1 +
 drivers/net/virtio/virtio_user/vhost_vdpa.c      | 15 +++++++++++++++
 drivers/net/virtio/virtio_user/virtio_user_dev.c |  3 +++
 3 files changed, 19 insertions(+)
  

Comments

Eugenio Perez Martin Feb. 7, 2023, 6:10 p.m. UTC | #1
On Tue, Feb 7, 2023 at 4:18 PM Maxime Coquelin
<maxime.coquelin@redhat.com> wrote:
>
> This patch introduces a new callback that is to be called
> when the backend supports control virtqueue.
>
> Implementation for Vhost-vDPA backend is added in this patch.
>
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>

Small nitpick but as previous one it is ok to leave as it is now.

Acked-by: Eugenio Pérez <eperezma@redhat.com>

> ---
>  drivers/net/virtio/virtio_user/vhost.h           |  1 +
>  drivers/net/virtio/virtio_user/vhost_vdpa.c      | 15 +++++++++++++++
>  drivers/net/virtio/virtio_user/virtio_user_dev.c |  3 +++
>  3 files changed, 19 insertions(+)
>
> diff --git a/drivers/net/virtio/virtio_user/vhost.h b/drivers/net/virtio/virtio_user/vhost.h
> index dfbf6be033..f817cab77a 100644
> --- a/drivers/net/virtio/virtio_user/vhost.h
> +++ b/drivers/net/virtio/virtio_user/vhost.h
> @@ -82,6 +82,7 @@ struct virtio_user_backend_ops {
>         int (*get_config)(struct virtio_user_dev *dev, uint8_t *data, uint32_t off, uint32_t len);
>         int (*set_config)(struct virtio_user_dev *dev, const uint8_t *data, uint32_t off,
>                         uint32_t len);
> +       int (*cvq_enable)(struct virtio_user_dev *dev, int enable);
>         int (*enable_qp)(struct virtio_user_dev *dev, uint16_t pair_idx, int enable);
>         int (*dma_map)(struct virtio_user_dev *dev, void *addr, uint64_t iova, size_t len);
>         int (*dma_unmap)(struct virtio_user_dev *dev, void *addr, uint64_t iova, size_t len);
> diff --git a/drivers/net/virtio/virtio_user/vhost_vdpa.c b/drivers/net/virtio/virtio_user/vhost_vdpa.c
> index a0897f8dd1..3fd13d9fac 100644
> --- a/drivers/net/virtio/virtio_user/vhost_vdpa.c
> +++ b/drivers/net/virtio/virtio_user/vhost_vdpa.c
> @@ -564,6 +564,20 @@ vhost_vdpa_destroy(struct virtio_user_dev *dev)
>         return 0;
>  }
>
> +static int
> +vhost_vdpa_cvq_enable(struct virtio_user_dev *dev, int enable)
> +{
> +       struct vhost_vring_state state = {
> +               .index = dev->max_queue_pairs * 2,
> +               .num   = enable,
> +       };
> +
> +       if (vhost_vdpa_set_vring_enable(dev, &state))
> +               return -1;
> +
> +       return 0;

Any reason for not to "return vhost_vdpa_set_vring_enable(dev, &state));"?

Thanks!

> +}
> +
>  static int
>  vhost_vdpa_enable_queue_pair(struct virtio_user_dev *dev,
>                                uint16_t pair_idx,
> @@ -629,6 +643,7 @@ struct virtio_user_backend_ops virtio_ops_vdpa = {
>         .set_status = vhost_vdpa_set_status,
>         .get_config = vhost_vdpa_get_config,
>         .set_config = vhost_vdpa_set_config,
> +       .cvq_enable = vhost_vdpa_cvq_enable,
>         .enable_qp = vhost_vdpa_enable_queue_pair,
>         .dma_map = vhost_vdpa_dma_map_batch,
>         .dma_unmap = vhost_vdpa_dma_unmap_batch,
> diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> index 1a5386a3f6..b0d603ee12 100644
> --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
> +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
> @@ -767,6 +767,9 @@ virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs)
>         for (i = q_pairs; i < dev->max_queue_pairs; ++i)
>                 ret |= dev->ops->enable_qp(dev, i, 0);
>
> +       if (dev->scvq)
> +               ret |= dev->ops->cvq_enable(dev, 1);
> +
>         dev->queue_pairs = q_pairs;
>
>         return ret;
> --
> 2.39.1
>
  
Maxime Coquelin Feb. 9, 2023, 8:50 a.m. UTC | #2
On 2/7/23 19:10, Eugenio Perez Martin wrote:
> On Tue, Feb 7, 2023 at 4:18 PM Maxime Coquelin
> <maxime.coquelin@redhat.com> wrote:
>>
>> This patch introduces a new callback that is to be called
>> when the backend supports control virtqueue.
>>
>> Implementation for Vhost-vDPA backend is added in this patch.
>>
>> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
>> Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
> 
> Small nitpick but as previous one it is ok to leave as it is now.
> 
> Acked-by: Eugenio Pérez <eperezma@redhat.com>
> 
>> ---
>>   drivers/net/virtio/virtio_user/vhost.h           |  1 +
>>   drivers/net/virtio/virtio_user/vhost_vdpa.c      | 15 +++++++++++++++
>>   drivers/net/virtio/virtio_user/virtio_user_dev.c |  3 +++
>>   3 files changed, 19 insertions(+)
>>
>> diff --git a/drivers/net/virtio/virtio_user/vhost.h b/drivers/net/virtio/virtio_user/vhost.h
>> index dfbf6be033..f817cab77a 100644
>> --- a/drivers/net/virtio/virtio_user/vhost.h
>> +++ b/drivers/net/virtio/virtio_user/vhost.h
>> @@ -82,6 +82,7 @@ struct virtio_user_backend_ops {
>>          int (*get_config)(struct virtio_user_dev *dev, uint8_t *data, uint32_t off, uint32_t len);
>>          int (*set_config)(struct virtio_user_dev *dev, const uint8_t *data, uint32_t off,
>>                          uint32_t len);
>> +       int (*cvq_enable)(struct virtio_user_dev *dev, int enable);
>>          int (*enable_qp)(struct virtio_user_dev *dev, uint16_t pair_idx, int enable);
>>          int (*dma_map)(struct virtio_user_dev *dev, void *addr, uint64_t iova, size_t len);
>>          int (*dma_unmap)(struct virtio_user_dev *dev, void *addr, uint64_t iova, size_t len);
>> diff --git a/drivers/net/virtio/virtio_user/vhost_vdpa.c b/drivers/net/virtio/virtio_user/vhost_vdpa.c
>> index a0897f8dd1..3fd13d9fac 100644
>> --- a/drivers/net/virtio/virtio_user/vhost_vdpa.c
>> +++ b/drivers/net/virtio/virtio_user/vhost_vdpa.c
>> @@ -564,6 +564,20 @@ vhost_vdpa_destroy(struct virtio_user_dev *dev)
>>          return 0;
>>   }
>>
>> +static int
>> +vhost_vdpa_cvq_enable(struct virtio_user_dev *dev, int enable)
>> +{
>> +       struct vhost_vring_state state = {
>> +               .index = dev->max_queue_pairs * 2,
>> +               .num   = enable,
>> +       };
>> +
>> +       if (vhost_vdpa_set_vring_enable(dev, &state))
>> +               return -1;
>> +
>> +       return 0;
> 
> Any reason for not to "return vhost_vdpa_set_vring_enable(dev, &state));"?

No reason, I guess I didn't refactor when modifying the code.
Will simplify it in next revision.

Thanks,
Maxime

> Thanks!
> 
>> +}
>> +
>>   static int
>>   vhost_vdpa_enable_queue_pair(struct virtio_user_dev *dev,
>>                                 uint16_t pair_idx,
>> @@ -629,6 +643,7 @@ struct virtio_user_backend_ops virtio_ops_vdpa = {
>>          .set_status = vhost_vdpa_set_status,
>>          .get_config = vhost_vdpa_get_config,
>>          .set_config = vhost_vdpa_set_config,
>> +       .cvq_enable = vhost_vdpa_cvq_enable,
>>          .enable_qp = vhost_vdpa_enable_queue_pair,
>>          .dma_map = vhost_vdpa_dma_map_batch,
>>          .dma_unmap = vhost_vdpa_dma_unmap_batch,
>> diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
>> index 1a5386a3f6..b0d603ee12 100644
>> --- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
>> +++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
>> @@ -767,6 +767,9 @@ virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs)
>>          for (i = q_pairs; i < dev->max_queue_pairs; ++i)
>>                  ret |= dev->ops->enable_qp(dev, i, 0);
>>
>> +       if (dev->scvq)
>> +               ret |= dev->ops->cvq_enable(dev, 1);
>> +
>>          dev->queue_pairs = q_pairs;
>>
>>          return ret;
>> --
>> 2.39.1
>>
>
  

Patch

diff --git a/drivers/net/virtio/virtio_user/vhost.h b/drivers/net/virtio/virtio_user/vhost.h
index dfbf6be033..f817cab77a 100644
--- a/drivers/net/virtio/virtio_user/vhost.h
+++ b/drivers/net/virtio/virtio_user/vhost.h
@@ -82,6 +82,7 @@  struct virtio_user_backend_ops {
 	int (*get_config)(struct virtio_user_dev *dev, uint8_t *data, uint32_t off, uint32_t len);
 	int (*set_config)(struct virtio_user_dev *dev, const uint8_t *data, uint32_t off,
 			uint32_t len);
+	int (*cvq_enable)(struct virtio_user_dev *dev, int enable);
 	int (*enable_qp)(struct virtio_user_dev *dev, uint16_t pair_idx, int enable);
 	int (*dma_map)(struct virtio_user_dev *dev, void *addr, uint64_t iova, size_t len);
 	int (*dma_unmap)(struct virtio_user_dev *dev, void *addr, uint64_t iova, size_t len);
diff --git a/drivers/net/virtio/virtio_user/vhost_vdpa.c b/drivers/net/virtio/virtio_user/vhost_vdpa.c
index a0897f8dd1..3fd13d9fac 100644
--- a/drivers/net/virtio/virtio_user/vhost_vdpa.c
+++ b/drivers/net/virtio/virtio_user/vhost_vdpa.c
@@ -564,6 +564,20 @@  vhost_vdpa_destroy(struct virtio_user_dev *dev)
 	return 0;
 }
 
+static int
+vhost_vdpa_cvq_enable(struct virtio_user_dev *dev, int enable)
+{
+	struct vhost_vring_state state = {
+		.index = dev->max_queue_pairs * 2,
+		.num   = enable,
+	};
+
+	if (vhost_vdpa_set_vring_enable(dev, &state))
+		return -1;
+
+	return 0;
+}
+
 static int
 vhost_vdpa_enable_queue_pair(struct virtio_user_dev *dev,
 			       uint16_t pair_idx,
@@ -629,6 +643,7 @@  struct virtio_user_backend_ops virtio_ops_vdpa = {
 	.set_status = vhost_vdpa_set_status,
 	.get_config = vhost_vdpa_get_config,
 	.set_config = vhost_vdpa_set_config,
+	.cvq_enable = vhost_vdpa_cvq_enable,
 	.enable_qp = vhost_vdpa_enable_queue_pair,
 	.dma_map = vhost_vdpa_dma_map_batch,
 	.dma_unmap = vhost_vdpa_dma_unmap_batch,
diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index 1a5386a3f6..b0d603ee12 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -767,6 +767,9 @@  virtio_user_handle_mq(struct virtio_user_dev *dev, uint16_t q_pairs)
 	for (i = q_pairs; i < dev->max_queue_pairs; ++i)
 		ret |= dev->ops->enable_qp(dev, i, 0);
 
+	if (dev->scvq)
+		ret |= dev->ops->cvq_enable(dev, 1);
+
 	dev->queue_pairs = q_pairs;
 
 	return ret;