netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] vduse: add support for networking devices
@ 2023-07-04 16:40 Maxime Coquelin
  2023-07-04 16:40 ` [PATCH v2 1/3] vduse: validate block features only with block devices Maxime Coquelin
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Maxime Coquelin @ 2023-07-04 16:40 UTC (permalink / raw)
  To: xieyongji, jasowang, mst, david.marchand, lulu
  Cc: linux-kernel, virtualization, netdev, xuanzhuo, eperezma,
	Maxime Coquelin

This small series enables virtio-net device type in VDUSE.
With it, basic operation have been tested, both with
virtio-vdpa and vhost-vdpa using DPDK Vhost library series
adding VDUSE support using split rings layout (merged in
DPDK v23.07-rc1).

Control queue support (and so multiqueue) has also been
tested, but requires a Kernel series from Jason Wang
relaxing control queue polling [1] to function reliably,
so while Jason rework is done, a patch is added to disable
CVQ and features that depend on it (tested also with DPDK
v23.07-rc1).

[1]: https://lore.kernel.org/lkml/CACGkMEtgrxN3PPwsDo4oOsnsSLJfEmBEZ0WvjGRr3whU+QasUg@mail.gmail.com/T/

v1 -> v2 changes:
=================
- Add a patch to disable CVQ (Michael)

RFC -> v1 changes:
==================
- Fail device init if it does not support VERSION_1 (Jason)

Maxime Coquelin (3):
  vduse: validate block features only with block devices
  vduse: enable Virtio-net device type
  vduse: Temporarily disable control queue features

 drivers/vdpa/vdpa_user/vduse_dev.c | 36 ++++++++++++++++++++++++++----
 1 file changed, 32 insertions(+), 4 deletions(-)

-- 
2.41.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/3] vduse: validate block features only with block devices
  2023-07-04 16:40 [PATCH v2 0/3] vduse: add support for networking devices Maxime Coquelin
@ 2023-07-04 16:40 ` Maxime Coquelin
  2023-07-04 16:40 ` [PATCH v2 2/3] vduse: enable Virtio-net device type Maxime Coquelin
  2023-07-04 16:40 ` [PATCH v2 3/3] vduse: Temporarily disable control queue features Maxime Coquelin
  2 siblings, 0 replies; 6+ messages in thread
From: Maxime Coquelin @ 2023-07-04 16:40 UTC (permalink / raw)
  To: xieyongji, jasowang, mst, david.marchand, lulu
  Cc: linux-kernel, virtualization, netdev, xuanzhuo, eperezma,
	Maxime Coquelin

This patch is preliminary work to enable network device
type support to VDUSE.

As VIRTIO_BLK_F_CONFIG_WCE shares the same value as
VIRTIO_NET_F_HOST_TSO4, we need to restrict its check
to Virtio-blk device type.

Acked-by: Jason Wang <jasowang@redhat.com>
Reviewed-by: Xie Yongji <xieyongji@bytedance.com>
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 drivers/vdpa/vdpa_user/vduse_dev.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
index dc38ed21319d..ff9fdd6783fe 100644
--- a/drivers/vdpa/vdpa_user/vduse_dev.c
+++ b/drivers/vdpa/vdpa_user/vduse_dev.c
@@ -1662,13 +1662,14 @@ static bool device_is_allowed(u32 device_id)
 	return false;
 }
 
-static bool features_is_valid(u64 features)
+static bool features_is_valid(struct vduse_dev_config *config)
 {
-	if (!(features & (1ULL << VIRTIO_F_ACCESS_PLATFORM)))
+	if (!(config->features & (1ULL << VIRTIO_F_ACCESS_PLATFORM)))
 		return false;
 
 	/* Now we only support read-only configuration space */
-	if (features & (1ULL << VIRTIO_BLK_F_CONFIG_WCE))
+	if ((config->device_id == VIRTIO_ID_BLOCK) &&
+			(config->features & (1ULL << VIRTIO_BLK_F_CONFIG_WCE)))
 		return false;
 
 	return true;
@@ -1695,7 +1696,7 @@ static bool vduse_validate_config(struct vduse_dev_config *config)
 	if (!device_is_allowed(config->device_id))
 		return false;
 
-	if (!features_is_valid(config->features))
+	if (!features_is_valid(config))
 		return false;
 
 	return true;
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/3] vduse: enable Virtio-net device type
  2023-07-04 16:40 [PATCH v2 0/3] vduse: add support for networking devices Maxime Coquelin
  2023-07-04 16:40 ` [PATCH v2 1/3] vduse: validate block features only with block devices Maxime Coquelin
@ 2023-07-04 16:40 ` Maxime Coquelin
  2023-07-04 16:40 ` [PATCH v2 3/3] vduse: Temporarily disable control queue features Maxime Coquelin
  2 siblings, 0 replies; 6+ messages in thread
From: Maxime Coquelin @ 2023-07-04 16:40 UTC (permalink / raw)
  To: xieyongji, jasowang, mst, david.marchand, lulu
  Cc: linux-kernel, virtualization, netdev, xuanzhuo, eperezma,
	Maxime Coquelin

This patch adds Virtio-net device type to the supported
devices types. Initialization fails if the device does
not support VIRTIO_F_VERSION_1 feature, in order to
guarantee the configuration space is read-only.

Acked-by: Jason Wang <jasowang@redhat.com>
Reviewed-by: Xie Yongji <xieyongji@bytedance.com>
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 drivers/vdpa/vdpa_user/vduse_dev.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
index ff9fdd6783fe..1271c9796517 100644
--- a/drivers/vdpa/vdpa_user/vduse_dev.c
+++ b/drivers/vdpa/vdpa_user/vduse_dev.c
@@ -142,6 +142,7 @@ static struct workqueue_struct *vduse_irq_bound_wq;
 
 static u32 allowed_device_id[] = {
 	VIRTIO_ID_BLOCK,
+	VIRTIO_ID_NET,
 };
 
 static inline struct vduse_dev *vdpa_to_vduse(struct vdpa_device *vdpa)
@@ -1672,6 +1673,10 @@ static bool features_is_valid(struct vduse_dev_config *config)
 			(config->features & (1ULL << VIRTIO_BLK_F_CONFIG_WCE)))
 		return false;
 
+	if ((config->device_id == VIRTIO_ID_NET) &&
+			!(config->features & (1ULL << VIRTIO_F_VERSION_1)))
+		return false;
+
 	return true;
 }
 
@@ -2027,6 +2032,7 @@ static const struct vdpa_mgmtdev_ops vdpa_dev_mgmtdev_ops = {
 
 static struct virtio_device_id id_table[] = {
 	{ VIRTIO_ID_BLOCK, VIRTIO_DEV_ANY_ID },
+	{ VIRTIO_ID_NET, VIRTIO_DEV_ANY_ID },
 	{ 0 },
 };
 
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 3/3] vduse: Temporarily disable control queue features
  2023-07-04 16:40 [PATCH v2 0/3] vduse: add support for networking devices Maxime Coquelin
  2023-07-04 16:40 ` [PATCH v2 1/3] vduse: validate block features only with block devices Maxime Coquelin
  2023-07-04 16:40 ` [PATCH v2 2/3] vduse: enable Virtio-net device type Maxime Coquelin
@ 2023-07-04 16:40 ` Maxime Coquelin
  2023-07-04 16:43   ` Michael S. Tsirkin
  2 siblings, 1 reply; 6+ messages in thread
From: Maxime Coquelin @ 2023-07-04 16:40 UTC (permalink / raw)
  To: xieyongji, jasowang, mst, david.marchand, lulu
  Cc: linux-kernel, virtualization, netdev, xuanzhuo, eperezma,
	Maxime Coquelin

Virtio-net driver control queue implementation is not safe
when used with VDUSE. If the VDUSE application does not
reply to control queue messages, it currently ends up
hanging the kernel thread sending this command.

Some work is on-going to make the control queue
implementation robust with VDUSE. Until it is completed,
let's disable control virtqueue and features that depend on
it.

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 drivers/vdpa/vdpa_user/vduse_dev.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
index 1271c9796517..04367a53802b 100644
--- a/drivers/vdpa/vdpa_user/vduse_dev.c
+++ b/drivers/vdpa/vdpa_user/vduse_dev.c
@@ -1778,6 +1778,25 @@ static struct attribute *vduse_dev_attrs[] = {
 
 ATTRIBUTE_GROUPS(vduse_dev);
 
+static void vduse_dev_features_fixup(struct vduse_dev_config *config)
+{
+	if (config->device_id == VIRTIO_ID_NET) {
+		/*
+		 * Temporarily disable control virtqueue and features that
+		 * depend on it while CVQ is being made more robust for VDUSE.
+		 */
+		config->features &= ~((1ULL << VIRTIO_NET_F_CTRL_VQ) |
+				(1ULL << VIRTIO_NET_F_CTRL_RX) |
+				(1ULL << VIRTIO_NET_F_CTRL_VLAN) |
+				(1ULL << VIRTIO_NET_F_GUEST_ANNOUNCE) |
+				(1ULL << VIRTIO_NET_F_MQ) |
+				(1ULL << VIRTIO_NET_F_CTRL_MAC_ADDR) |
+				(1ULL << VIRTIO_NET_F_RSS) |
+				(1ULL << VIRTIO_NET_F_HASH_REPORT) |
+				(1ULL << VIRTIO_NET_F_NOTF_COAL));
+	}
+}
+
 static int vduse_create_dev(struct vduse_dev_config *config,
 			    void *config_buf, u64 api_version)
 {
@@ -1793,6 +1812,8 @@ static int vduse_create_dev(struct vduse_dev_config *config,
 	if (!dev)
 		goto err;
 
+	vduse_dev_features_fixup(config);
+
 	dev->api_version = api_version;
 	dev->device_features = config->features;
 	dev->device_id = config->device_id;
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 3/3] vduse: Temporarily disable control queue features
  2023-07-04 16:40 ` [PATCH v2 3/3] vduse: Temporarily disable control queue features Maxime Coquelin
@ 2023-07-04 16:43   ` Michael S. Tsirkin
  2023-07-04 19:22     ` Maxime Coquelin
  0 siblings, 1 reply; 6+ messages in thread
From: Michael S. Tsirkin @ 2023-07-04 16:43 UTC (permalink / raw)
  To: Maxime Coquelin
  Cc: xieyongji, jasowang, david.marchand, lulu, linux-kernel,
	virtualization, netdev, xuanzhuo, eperezma

On Tue, Jul 04, 2023 at 06:40:45PM +0200, Maxime Coquelin wrote:
> Virtio-net driver control queue implementation is not safe
> when used with VDUSE. If the VDUSE application does not
> reply to control queue messages, it currently ends up
> hanging the kernel thread sending this command.
> 
> Some work is on-going to make the control queue
> implementation robust with VDUSE. Until it is completed,
> let's disable control virtqueue and features that depend on
> it.
> 
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> ---
>  drivers/vdpa/vdpa_user/vduse_dev.c | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
> 
> diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
> index 1271c9796517..04367a53802b 100644
> --- a/drivers/vdpa/vdpa_user/vduse_dev.c
> +++ b/drivers/vdpa/vdpa_user/vduse_dev.c
> @@ -1778,6 +1778,25 @@ static struct attribute *vduse_dev_attrs[] = {
>  
>  ATTRIBUTE_GROUPS(vduse_dev);
>  
> +static void vduse_dev_features_fixup(struct vduse_dev_config *config)
> +{
> +	if (config->device_id == VIRTIO_ID_NET) {
> +		/*
> +		 * Temporarily disable control virtqueue and features that
> +		 * depend on it while CVQ is being made more robust for VDUSE.
> +		 */
> +		config->features &= ~((1ULL << VIRTIO_NET_F_CTRL_VQ) |
> +				(1ULL << VIRTIO_NET_F_CTRL_RX) |
> +				(1ULL << VIRTIO_NET_F_CTRL_VLAN) |
> +				(1ULL << VIRTIO_NET_F_GUEST_ANNOUNCE) |
> +				(1ULL << VIRTIO_NET_F_MQ) |
> +				(1ULL << VIRTIO_NET_F_CTRL_MAC_ADDR) |
> +				(1ULL << VIRTIO_NET_F_RSS) |
> +				(1ULL << VIRTIO_NET_F_HASH_REPORT) |
> +				(1ULL << VIRTIO_NET_F_NOTF_COAL));
> +	}
> +}
> +


This will never be exhaustive, we are adding new features.
Please add an allowlist with just legal ones instead.


>  static int vduse_create_dev(struct vduse_dev_config *config,
>  			    void *config_buf, u64 api_version)
>  {
> @@ -1793,6 +1812,8 @@ static int vduse_create_dev(struct vduse_dev_config *config,
>  	if (!dev)
>  		goto err;
>  
> +	vduse_dev_features_fixup(config);
> +
>  	dev->api_version = api_version;
>  	dev->device_features = config->features;
>  	dev->device_id = config->device_id;
> -- 
> 2.41.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 3/3] vduse: Temporarily disable control queue features
  2023-07-04 16:43   ` Michael S. Tsirkin
@ 2023-07-04 19:22     ` Maxime Coquelin
  0 siblings, 0 replies; 6+ messages in thread
From: Maxime Coquelin @ 2023-07-04 19:22 UTC (permalink / raw)
  To: Michael S. Tsirkin
  Cc: xieyongji, jasowang, david.marchand, lulu, linux-kernel,
	virtualization, netdev, xuanzhuo, eperezma



On 7/4/23 18:43, Michael S. Tsirkin wrote:
> On Tue, Jul 04, 2023 at 06:40:45PM +0200, Maxime Coquelin wrote:
>> Virtio-net driver control queue implementation is not safe
>> when used with VDUSE. If the VDUSE application does not
>> reply to control queue messages, it currently ends up
>> hanging the kernel thread sending this command.
>>
>> Some work is on-going to make the control queue
>> implementation robust with VDUSE. Until it is completed,
>> let's disable control virtqueue and features that depend on
>> it.
>>
>> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
>> ---
>>   drivers/vdpa/vdpa_user/vduse_dev.c | 21 +++++++++++++++++++++
>>   1 file changed, 21 insertions(+)
>>
>> diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
>> index 1271c9796517..04367a53802b 100644
>> --- a/drivers/vdpa/vdpa_user/vduse_dev.c
>> +++ b/drivers/vdpa/vdpa_user/vduse_dev.c
>> @@ -1778,6 +1778,25 @@ static struct attribute *vduse_dev_attrs[] = {
>>   
>>   ATTRIBUTE_GROUPS(vduse_dev);
>>   
>> +static void vduse_dev_features_fixup(struct vduse_dev_config *config)
>> +{
>> +	if (config->device_id == VIRTIO_ID_NET) {
>> +		/*
>> +		 * Temporarily disable control virtqueue and features that
>> +		 * depend on it while CVQ is being made more robust for VDUSE.
>> +		 */
>> +		config->features &= ~((1ULL << VIRTIO_NET_F_CTRL_VQ) |
>> +				(1ULL << VIRTIO_NET_F_CTRL_RX) |
>> +				(1ULL << VIRTIO_NET_F_CTRL_VLAN) |
>> +				(1ULL << VIRTIO_NET_F_GUEST_ANNOUNCE) |
>> +				(1ULL << VIRTIO_NET_F_MQ) |
>> +				(1ULL << VIRTIO_NET_F_CTRL_MAC_ADDR) |
>> +				(1ULL << VIRTIO_NET_F_RSS) |
>> +				(1ULL << VIRTIO_NET_F_HASH_REPORT) |
>> +				(1ULL << VIRTIO_NET_F_NOTF_COAL));
>> +	}
>> +}
>> +
> 
> 
> This will never be exhaustive, we are adding new features.
> Please add an allowlist with just legal ones instead.

Ok, got it!
I'll post a new revision.

Thanks,
Maxime

> 
> 
>>   static int vduse_create_dev(struct vduse_dev_config *config,
>>   			    void *config_buf, u64 api_version)
>>   {
>> @@ -1793,6 +1812,8 @@ static int vduse_create_dev(struct vduse_dev_config *config,
>>   	if (!dev)
>>   		goto err;
>>   
>> +	vduse_dev_features_fixup(config);
>> +
>>   	dev->api_version = api_version;
>>   	dev->device_features = config->features;
>>   	dev->device_id = config->device_id;
>> -- 
>> 2.41.0
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-07-04 19:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-04 16:40 [PATCH v2 0/3] vduse: add support for networking devices Maxime Coquelin
2023-07-04 16:40 ` [PATCH v2 1/3] vduse: validate block features only with block devices Maxime Coquelin
2023-07-04 16:40 ` [PATCH v2 2/3] vduse: enable Virtio-net device type Maxime Coquelin
2023-07-04 16:40 ` [PATCH v2 3/3] vduse: Temporarily disable control queue features Maxime Coquelin
2023-07-04 16:43   ` Michael S. Tsirkin
2023-07-04 19:22     ` Maxime Coquelin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).