net/virtio-user: check negotiated features before set
PATCH v3 1/1 net/virtio-user: check negotiated features before set
This patch checks negotiated features to see if necessary to offload before set the tap device offload capabilities. It also checks if kernel support the TUNSETOFFLOAD operation.
---
v3:
* make other offloading features depend on CSUM
* check IFF_VNET_HDR support when handling VHOST_GET_FEATURES
---
v2:
* don't return failure when failed to set offload to tap
* check if offloads available when handling VHOST_GET_FEATURES
--- drivers/net/virtio/virtio_user/vhost_kernel.c | 18 +++++--- drivers/net/virtio/virtio_user/vhost_kernel_tap.c | 56 +++++++++++++++++------ drivers/net/virtio/virtio_user/vhost_kernel_tap.h | 2 +- 3 files changed, 54 insertions(+), 22 deletions(-)
drivers/net/virtio/virtio_user/vhost_kernel.c +11 -7
@@ -189,8 +189,8 @@ struct vhost_memory_kernel { (1ULL << VIRTIO_NET_F_HOST_TSO6) | \ (1ULL << VIRTIO_NET_F_CSUM)) -static int -tap_supporte_mq (void ) +static unsigned int +tap_support_features (void ) {int tapfd;unsigned int tap_features;
@@ -209,7 +209,7 @@ struct vhost_memory_kernel { }close (tapfd); -return tap_features &IFF_MULTI_QUEUE ; +return tap_features; } static int
@@ -223,6 +223,7 @@ struct vhost_memory_kernel {struct vhost_memory_kernel *vm =NULL ;int vhostfd;unsigned int queue_sel; +unsigned int features;PMD_DRV_LOG (INFO ,"%s" , vhost_msg_strings[req]);
@@ -276,17 +277,20 @@ struct vhost_memory_kernel { }if (!ret && req_kernel ==VHOST_GET_FEATURES ) { + features =tap_support_features ();/* with tap as the backend, all these features are supported * but not claimed by vhost-net, so we add them back when * reporting to upper layer. */ - *((uint64_t *)arg) |=VHOST_KERNEL_GUEST_OFFLOADS_MASK ; - *((uint64_t *)arg) |=VHOST_KERNEL_HOST_OFFLOADS_MASK ; +if (features &IFF_VNET_HDR ) { + *((uint64_t *)arg) |=VHOST_KERNEL_GUEST_OFFLOADS_MASK ; + *((uint64_t *)arg) |=VHOST_KERNEL_HOST_OFFLOADS_MASK ; + }/* vhost_kernel will not declare this feature, but it does * support multi-queue. */ -if (tap_supporte_mq ()) +if (features &IFF_MULTI_QUEUE ) *(uint64_t *)arg |= (1ull <<VIRTIO_NET_F_MQ ); }
@@ -381,7 +385,7 @@ struct vhost_memory_kernel { hdr_size =sizeof (struct virtio_net_hdr ); tapfd =vhost_kernel_open_tap (&dev->ifname, hdr_size, req_mq, - (char *)dev->mac_addr); + (char *)dev->mac_addr, dev->features);if (tapfd <0 ) {PMD_DRV_LOG (ERR ,"fail to open tap for vhost kernel" );return -1 ;
drivers/net/virtio/virtio_user/vhost_kernel_tap.c +42 -14
76 lines not on this page · raw message
drivers/net/virtio/virtio_user/vhost_kernel_tap.h +1 -1
@@ -65,4 +65,4 @@#define PATH_NET_TUN "/dev/net/tun"int vhost_kernel_open_tap (char **p_ifname,int hdr_size,int req_mq, -const char *mac); +const char *mac,uint64_t features);
Signature · 1 line
1.8.3.1
Quoted 3 lines · eric zhang
This patch checks negotiated features to see if necessary to offload before set the tap device offload capabilities. It also checks if kernel support the TUNSETOFFLOAD operation.
Thanks!
Quoted 18 lines
Signed-off-by eric zhang <[email protected]>---
v3:
* make other offloading features depend on CSUM
* checkIFF_VNET_HDRsupport when handlingVHOST_GET_FEATURES---
v2:
* don't return failure when failed to set offload to tap
* check if offloads available when handlingVHOST_GET_FEATURES--- drivers/net/virtio/virtio_user/vhost_kernel.c | 18 +++++--- drivers/net/virtio/virtio_user/vhost_kernel_tap.c | 56 +++++++++++++++++------ drivers/net/virtio/virtio_user/vhost_kernel_tap.h | 2 +- 3 files changed, 54 insertions(+), 22 deletions(-)
Maxime Coquelin
AppliedQuoted 15 lines · eric zhang
This patch checks negotiated features to see if necessary to offload before set the tap device offload capabilities. It also checks if kernel support the TUNSETOFFLOAD operation.
Signed-off-by eric zhang <[email protected]>---
v3:
* make other offloading features depend on CSUM
* checkIFF_VNET_HDRsupport when handlingVHOST_GET_FEATURES---
v2:
* don't return failure when failed to set offload to tap
* check if offloads available when handlingVHOST_GET_FEATURES
Quoted 6 lines
--- drivers/net/virtio/virtio_user/vhost_kernel.c | 18 +++++--- drivers/net/virtio/virtio_user/vhost_kernel_tap.c | 56 +++++++++++++++++------ drivers/net/virtio/virtio_user/vhost_kernel_tap.h | 2 +- 3 files changed, 54 insertions(+), 22 deletions(-)
Applied to dpdk-next-virtio/master, adding Fixes: line as suggested by Tiwei.
Thanks,
Maxime