* [PATCH v3 1/3] vduse: validate block features only with block devices
2023-07-05 10:04 [PATCH v3 0/3] vduse: add support for networking devices Maxime Coquelin
@ 2023-07-05 10:04 ` Maxime Coquelin
2023-07-05 10:04 ` [PATCH v3 2/3] vduse: enable Virtio-net device type Maxime Coquelin
` (2 subsequent siblings)
3 siblings, 0 replies; 11+ messages in thread
From: Maxime Coquelin @ 2023-07-05 10:04 UTC (permalink / raw)
To: xieyongji, jasowang, mst, david.marchand, lulu
Cc: xuanzhuo, netdev, linux-kernel, virtualization, 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
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH v3 2/3] vduse: enable Virtio-net device type
2023-07-05 10:04 [PATCH v3 0/3] vduse: add support for networking devices Maxime Coquelin
2023-07-05 10:04 ` [PATCH v3 1/3] vduse: validate block features only with block devices Maxime Coquelin
@ 2023-07-05 10:04 ` Maxime Coquelin
2023-07-05 10:04 ` [PATCH v3 3/3] vduse: Temporarily disable control queue features Maxime Coquelin
2023-08-10 19:04 ` [PATCH v3 0/3] vduse: add support for networking devices Michael S. Tsirkin
3 siblings, 0 replies; 11+ messages in thread
From: Maxime Coquelin @ 2023-07-05 10:04 UTC (permalink / raw)
To: xieyongji, jasowang, mst, david.marchand, lulu
Cc: xuanzhuo, netdev, linux-kernel, virtualization, 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
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH v3 3/3] vduse: Temporarily disable control queue features
2023-07-05 10:04 [PATCH v3 0/3] vduse: add support for networking devices Maxime Coquelin
2023-07-05 10:04 ` [PATCH v3 1/3] vduse: validate block features only with block devices Maxime Coquelin
2023-07-05 10:04 ` [PATCH v3 2/3] vduse: enable Virtio-net device type Maxime Coquelin
@ 2023-07-05 10:04 ` Maxime Coquelin
2023-07-06 1:58 ` Jason Wang
2023-08-10 19:04 ` [PATCH v3 0/3] vduse: add support for networking devices Michael S. Tsirkin
3 siblings, 1 reply; 11+ messages in thread
From: Maxime Coquelin @ 2023-07-05 10:04 UTC (permalink / raw)
To: xieyongji, jasowang, mst, david.marchand, lulu
Cc: xuanzhuo, netdev, linux-kernel, virtualization, 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 filter out control virtqueue and features that depend
on it by keeping only features known to be supported.
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
drivers/vdpa/vdpa_user/vduse_dev.c | 36 ++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
index 1271c9796517..7345071db0a8 100644
--- a/drivers/vdpa/vdpa_user/vduse_dev.c
+++ b/drivers/vdpa/vdpa_user/vduse_dev.c
@@ -46,6 +46,30 @@
#define IRQ_UNBOUND -1
+#define VDUSE_NET_VALID_FEATURES_MASK \
+ (BIT_ULL(VIRTIO_NET_F_CSUM) | \
+ BIT_ULL(VIRTIO_NET_F_GUEST_CSUM) | \
+ BIT_ULL(VIRTIO_NET_F_MTU) | \
+ BIT_ULL(VIRTIO_NET_F_MAC) | \
+ BIT_ULL(VIRTIO_NET_F_GUEST_TSO4) | \
+ BIT_ULL(VIRTIO_NET_F_GUEST_TSO6) | \
+ BIT_ULL(VIRTIO_NET_F_GUEST_ECN) | \
+ BIT_ULL(VIRTIO_NET_F_GUEST_UFO) | \
+ BIT_ULL(VIRTIO_NET_F_HOST_TSO4) | \
+ BIT_ULL(VIRTIO_NET_F_HOST_TSO6) | \
+ BIT_ULL(VIRTIO_NET_F_HOST_ECN) | \
+ BIT_ULL(VIRTIO_NET_F_HOST_UFO) | \
+ BIT_ULL(VIRTIO_NET_F_MRG_RXBUF) | \
+ BIT_ULL(VIRTIO_NET_F_STATUS) | \
+ BIT_ULL(VIRTIO_NET_F_HOST_USO) | \
+ BIT_ULL(VIRTIO_F_ANY_LAYOUT) | \
+ BIT_ULL(VIRTIO_RING_F_INDIRECT_DESC) | \
+ BIT_ULL(VIRTIO_F_EVENT_IDX) | \
+ BIT_ULL(VIRTIO_F_VERSION_1) | \
+ BIT_ULL(VIRTIO_F_IOMMU_PLATFORM) | \
+ BIT_ULL(VIRTIO_F_RING_PACKED) | \
+ BIT_ULL(VIRTIO_F_IN_ORDER))
+
struct vduse_virtqueue {
u16 index;
u16 num_max;
@@ -1778,6 +1802,16 @@ static struct attribute *vduse_dev_attrs[] = {
ATTRIBUTE_GROUPS(vduse_dev);
+static void vduse_dev_features_filter(struct vduse_dev_config *config)
+{
+ /*
+ * Temporarily filter out virtio-net's control virtqueue and features
+ * that depend on it while CVQ is being made more robust for VDUSE.
+ */
+ if (config->device_id == VIRTIO_ID_NET)
+ config->features &= VDUSE_NET_VALID_FEATURES_MASK;
+}
+
static int vduse_create_dev(struct vduse_dev_config *config,
void *config_buf, u64 api_version)
{
@@ -1793,6 +1827,8 @@ static int vduse_create_dev(struct vduse_dev_config *config,
if (!dev)
goto err;
+ vduse_dev_features_filter(config);
+
dev->api_version = api_version;
dev->device_features = config->features;
dev->device_id = config->device_id;
--
2.41.0
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH v3 3/3] vduse: Temporarily disable control queue features
2023-07-05 10:04 ` [PATCH v3 3/3] vduse: Temporarily disable control queue features Maxime Coquelin
@ 2023-07-06 1:58 ` Jason Wang
0 siblings, 0 replies; 11+ messages in thread
From: Jason Wang @ 2023-07-06 1:58 UTC (permalink / raw)
To: Maxime Coquelin
Cc: xuanzhuo, lulu, mst, netdev, linux-kernel, virtualization,
xieyongji, eperezma, david.marchand
On Wed, Jul 5, 2023 at 6:04 PM Maxime Coquelin
<maxime.coquelin@redhat.com> 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 filter out control virtqueue and features that depend
> on it by keeping only features known to be supported.
>
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
Acked-by: Jason Wang <jasowang@redhat.com>
Thanks
> ---
> drivers/vdpa/vdpa_user/vduse_dev.c | 36 ++++++++++++++++++++++++++++++
> 1 file changed, 36 insertions(+)
>
> diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c
> index 1271c9796517..7345071db0a8 100644
> --- a/drivers/vdpa/vdpa_user/vduse_dev.c
> +++ b/drivers/vdpa/vdpa_user/vduse_dev.c
> @@ -46,6 +46,30 @@
>
> #define IRQ_UNBOUND -1
>
> +#define VDUSE_NET_VALID_FEATURES_MASK \
> + (BIT_ULL(VIRTIO_NET_F_CSUM) | \
> + BIT_ULL(VIRTIO_NET_F_GUEST_CSUM) | \
> + BIT_ULL(VIRTIO_NET_F_MTU) | \
> + BIT_ULL(VIRTIO_NET_F_MAC) | \
> + BIT_ULL(VIRTIO_NET_F_GUEST_TSO4) | \
> + BIT_ULL(VIRTIO_NET_F_GUEST_TSO6) | \
> + BIT_ULL(VIRTIO_NET_F_GUEST_ECN) | \
> + BIT_ULL(VIRTIO_NET_F_GUEST_UFO) | \
> + BIT_ULL(VIRTIO_NET_F_HOST_TSO4) | \
> + BIT_ULL(VIRTIO_NET_F_HOST_TSO6) | \
> + BIT_ULL(VIRTIO_NET_F_HOST_ECN) | \
> + BIT_ULL(VIRTIO_NET_F_HOST_UFO) | \
> + BIT_ULL(VIRTIO_NET_F_MRG_RXBUF) | \
> + BIT_ULL(VIRTIO_NET_F_STATUS) | \
> + BIT_ULL(VIRTIO_NET_F_HOST_USO) | \
> + BIT_ULL(VIRTIO_F_ANY_LAYOUT) | \
> + BIT_ULL(VIRTIO_RING_F_INDIRECT_DESC) | \
> + BIT_ULL(VIRTIO_F_EVENT_IDX) | \
> + BIT_ULL(VIRTIO_F_VERSION_1) | \
> + BIT_ULL(VIRTIO_F_IOMMU_PLATFORM) | \
> + BIT_ULL(VIRTIO_F_RING_PACKED) | \
> + BIT_ULL(VIRTIO_F_IN_ORDER))
> +
> struct vduse_virtqueue {
> u16 index;
> u16 num_max;
> @@ -1778,6 +1802,16 @@ static struct attribute *vduse_dev_attrs[] = {
>
> ATTRIBUTE_GROUPS(vduse_dev);
>
> +static void vduse_dev_features_filter(struct vduse_dev_config *config)
> +{
> + /*
> + * Temporarily filter out virtio-net's control virtqueue and features
> + * that depend on it while CVQ is being made more robust for VDUSE.
> + */
> + if (config->device_id == VIRTIO_ID_NET)
> + config->features &= VDUSE_NET_VALID_FEATURES_MASK;
> +}
> +
> static int vduse_create_dev(struct vduse_dev_config *config,
> void *config_buf, u64 api_version)
> {
> @@ -1793,6 +1827,8 @@ static int vduse_create_dev(struct vduse_dev_config *config,
> if (!dev)
> goto err;
>
> + vduse_dev_features_filter(config);
> +
> dev->api_version = api_version;
> dev->device_features = config->features;
> dev->device_id = config->device_id;
> --
> 2.41.0
>
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v3 0/3] vduse: add support for networking devices
2023-07-05 10:04 [PATCH v3 0/3] vduse: add support for networking devices Maxime Coquelin
` (2 preceding siblings ...)
2023-07-05 10:04 ` [PATCH v3 3/3] vduse: Temporarily disable control queue features Maxime Coquelin
@ 2023-08-10 19:04 ` Michael S. Tsirkin
[not found] ` <20230810142949.074c9430@kernel.org>
3 siblings, 1 reply; 11+ messages in thread
From: Michael S. Tsirkin @ 2023-08-10 19:04 UTC (permalink / raw)
To: Maxime Coquelin
Cc: xuanzhuo, lulu, eperezma, netdev, linux-kernel, virtualization,
xieyongji, david.marchand
On Wed, Jul 05, 2023 at 12:04:27PM +0200, Maxime Coquelin wrote:
> 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).
So I can put this in next, the issue I think is
that of security: currently selinux can if necessary block
access to creating virtio block devices.
But if we have more than one type we need a way for selinux to
block specific types. Can be a patch on top but pls work to
address.
Another question is that with this userspace can inject
packets directly into net stack. Should we check CAP_NET_ADMIN
or such?
> [1]: https://lore.kernel.org/lkml/CACGkMEtgrxN3PPwsDo4oOsnsSLJfEmBEZ0WvjGRr3whU+QasUg@mail.gmail.com/T/
>
> v2 -> v3 changes:
> =================
> - Use allow list instead of deny list (Michael)
>
> 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 | 51 +++++++++++++++++++++++++++---
> 1 file changed, 47 insertions(+), 4 deletions(-)
>
> --
> 2.41.0
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
^ permalink raw reply [flat|nested] 11+ messages in thread