qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] virtio-net: add USO feature (UDP segmentation offload)
@ 2023-07-19 15:21 Yuri Benditovich
  2023-07-19 15:21 ` [PATCH 1/4] tap: Added USO support to tap device Yuri Benditovich
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Yuri Benditovich @ 2023-07-19 15:21 UTC (permalink / raw)
  To: Dmitry Fleytman, Akihiko Odaki, Jason Wang, Sriram Yagnaraman,
	mst, Stefan Weil, qemu-devel
  Cc: yan, andrew

Starting from 6.2 the kernel supports UDP segmentation offload, the
kernel uses GSO_UDP_L4 to mark packets with USB sermentation request 


Andrew Melnychenko (3):
  tap: Added USO support to tap device.
  virtio-net: Added USO flags to vhost support.
  virtio-net: Added uso check

Yuri Benditovich (1):
  virtio-net: added USO support

 hw/net/e1000e_core.c |  2 +-
 hw/net/igb_core.c    |  2 +-
 hw/net/vhost_net.c   |  3 +++
 hw/net/virtio-net.c  | 35 ++++++++++++++++++++++++++++++++---
 hw/net/vmxnet3.c     |  2 ++
 include/net/net.h    |  7 +++++--
 net/net.c            | 13 +++++++++++--
 net/tap-bsd.c        |  7 ++++++-
 net/tap-linux.c      | 27 ++++++++++++++++++++++++---
 net/tap-linux.h      |  2 ++
 net/tap-solaris.c    |  7 ++++++-
 net/tap-stub.c       |  7 ++++++-
 net/tap-win32.c      |  2 +-
 net/tap.c            | 18 +++++++++++++++---
 net/tap_int.h        |  4 +++-
 net/vhost-vdpa.c     |  3 +++
 16 files changed, 121 insertions(+), 20 deletions(-)

-- 
2.34.3



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

* [PATCH 1/4] tap: Added USO support to tap device.
  2023-07-19 15:21 [PATCH 0/4] virtio-net: add USO feature (UDP segmentation offload) Yuri Benditovich
@ 2023-07-19 15:21 ` Yuri Benditovich
  2023-07-20  0:31   ` Akihiko Odaki
  2023-07-19 15:21 ` [PATCH 2/4] virtio-net: Added USO flags to vhost support Yuri Benditovich
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: Yuri Benditovich @ 2023-07-19 15:21 UTC (permalink / raw)
  To: Dmitry Fleytman, Akihiko Odaki, Jason Wang, Sriram Yagnaraman,
	mst, Stefan Weil, qemu-devel
  Cc: yan, andrew

From: Andrew Melnychenko <andrew@daynix.com>

Passing additional parameters (USOv4 and USOv6 offloads) when
setting TAP offloads

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
---
 hw/net/e1000e_core.c |  2 +-
 hw/net/igb_core.c    |  2 +-
 hw/net/virtio-net.c  |  4 +++-
 hw/net/vmxnet3.c     |  2 ++
 include/net/net.h    |  4 ++--
 net/net.c            |  4 ++--
 net/tap-bsd.c        |  2 +-
 net/tap-linux.c      | 15 ++++++++++++---
 net/tap-linux.h      |  2 ++
 net/tap-solaris.c    |  2 +-
 net/tap-stub.c       |  2 +-
 net/tap-win32.c      |  2 +-
 net/tap.c            |  6 +++---
 net/tap_int.h        |  3 ++-
 14 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c
index f8aeafa16b..d4055956ad 100644
--- a/hw/net/e1000e_core.c
+++ b/hw/net/e1000e_core.c
@@ -2852,7 +2852,7 @@ e1000e_update_rx_offloads(E1000ECore *core)
 
     if (core->has_vnet) {
         qemu_set_offload(qemu_get_queue(core->owner_nic)->peer,
-                         cso_state, 0, 0, 0, 0);
+                         cso_state, 0, 0, 0, 0, 0, 0);
     }
 }
 
diff --git a/hw/net/igb_core.c b/hw/net/igb_core.c
index 8b6b75c522..389eef1549 100644
--- a/hw/net/igb_core.c
+++ b/hw/net/igb_core.c
@@ -2753,7 +2753,7 @@ igb_update_rx_offloads(IGBCore *core)
 
     if (core->has_vnet) {
         qemu_set_offload(qemu_get_queue(core->owner_nic)->peer,
-                         cso_state, 0, 0, 0, 0);
+                         cso_state, 0, 0, 0, 0, 0, 0);
     }
 }
 
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 7102ec4817..d2311e7d6e 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -859,7 +859,9 @@ static void virtio_net_apply_guest_offloads(VirtIONet *n)
             !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_TSO4)),
             !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_TSO6)),
             !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_ECN)),
-            !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_UFO)));
+            !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_UFO)),
+            !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_USO4)),
+            !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_USO6)));
 }
 
 static uint64_t virtio_net_guest_offloads_by_features(uint32_t features)
diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c
index 5dfacb1098..886adae42b 100644
--- a/hw/net/vmxnet3.c
+++ b/hw/net/vmxnet3.c
@@ -1341,6 +1341,8 @@ static void vmxnet3_update_features(VMXNET3State *s)
                          s->lro_supported,
                          s->lro_supported,
                          0,
+                         0,
+                         0,
                          0);
     }
 }
diff --git a/include/net/net.h b/include/net/net.h
index 1448d00afb..b5ccfbbffb 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -58,7 +58,7 @@ typedef bool (HasVnetHdr)(NetClientState *);
 typedef bool (HasVnetHdrLen)(NetClientState *, int);
 typedef bool (GetUsingVnetHdr)(NetClientState *);
 typedef void (UsingVnetHdr)(NetClientState *, bool);
-typedef void (SetOffload)(NetClientState *, int, int, int, int, int);
+typedef void (SetOffload)(NetClientState *, int, int, int, int, int, int, int);
 typedef int (GetVnetHdrLen)(NetClientState *);
 typedef void (SetVnetHdrLen)(NetClientState *, int);
 typedef int (SetVnetLE)(NetClientState *, bool);
@@ -192,7 +192,7 @@ bool qemu_has_vnet_hdr_len(NetClientState *nc, int len);
 bool qemu_get_using_vnet_hdr(NetClientState *nc);
 void qemu_using_vnet_hdr(NetClientState *nc, bool enable);
 void qemu_set_offload(NetClientState *nc, int csum, int tso4, int tso6,
-                      int ecn, int ufo);
+                      int ecn, int ufo, int uso4, int uso6);
 int qemu_get_vnet_hdr_len(NetClientState *nc);
 void qemu_set_vnet_hdr_len(NetClientState *nc, int len);
 int qemu_set_vnet_le(NetClientState *nc, bool is_le);
diff --git a/net/net.c b/net/net.c
index 6492ad530e..543e6dec43 100644
--- a/net/net.c
+++ b/net/net.c
@@ -532,13 +532,13 @@ void qemu_using_vnet_hdr(NetClientState *nc, bool enable)
 }
 
 void qemu_set_offload(NetClientState *nc, int csum, int tso4, int tso6,
-                          int ecn, int ufo)
+                          int ecn, int ufo, int uso4, int uso6)
 {
     if (!nc || !nc->info->set_offload) {
         return;
     }
 
-    nc->info->set_offload(nc, csum, tso4, tso6, ecn, ufo);
+    nc->info->set_offload(nc, csum, tso4, tso6, ecn, ufo, uso4, uso6);
 }
 
 int qemu_get_vnet_hdr_len(NetClientState *nc)
diff --git a/net/tap-bsd.c b/net/tap-bsd.c
index 4c98fdd337..abd16a2ad2 100644
--- a/net/tap-bsd.c
+++ b/net/tap-bsd.c
@@ -232,7 +232,7 @@ int tap_fd_set_vnet_be(int fd, int is_be)
 }
 
 void tap_fd_set_offload(int fd, int csum, int tso4,
-                        int tso6, int ecn, int ufo)
+                        int tso6, int ecn, int ufo, int uso4, int uso6)
 {
 }
 
diff --git a/net/tap-linux.c b/net/tap-linux.c
index f54f308d35..30fcca1bc2 100644
--- a/net/tap-linux.c
+++ b/net/tap-linux.c
@@ -237,7 +237,7 @@ int tap_fd_set_vnet_be(int fd, int is_be)
 }
 
 void tap_fd_set_offload(int fd, int csum, int tso4,
-                        int tso6, int ecn, int ufo)
+                        int tso6, int ecn, int ufo, int uso4, int uso6)
 {
     unsigned int offload = 0;
 
@@ -256,13 +256,22 @@ void tap_fd_set_offload(int fd, int csum, int tso4,
             offload |= TUN_F_TSO_ECN;
         if (ufo)
             offload |= TUN_F_UFO;
+        if (uso4) {
+            offload |= TUN_F_USO4;
+        }
+        if (uso6) {
+            offload |= TUN_F_USO6;
+        }
     }
 
     if (ioctl(fd, TUNSETOFFLOAD, offload) != 0) {
-        offload &= ~TUN_F_UFO;
+        offload &= ~(TUN_F_USO4 | TUN_F_USO6);
         if (ioctl(fd, TUNSETOFFLOAD, offload) != 0) {
-            fprintf(stderr, "TUNSETOFFLOAD ioctl() failed: %s\n",
+            offload &= ~TUN_F_UFO;
+            if (ioctl(fd, TUNSETOFFLOAD, offload) != 0) {
+                fprintf(stderr, "TUNSETOFFLOAD ioctl() failed: %s\n",
                     strerror(errno));
+            }
         }
     }
 }
diff --git a/net/tap-linux.h b/net/tap-linux.h
index bbbb62c2a7..9a58cecb7f 100644
--- a/net/tap-linux.h
+++ b/net/tap-linux.h
@@ -50,5 +50,7 @@
 #define TUN_F_TSO6    0x04    /* I can handle TSO for IPv6 packets */
 #define TUN_F_TSO_ECN 0x08    /* I can handle TSO with ECN bits. */
 #define TUN_F_UFO     0x10    /* I can handle UFO packets */
+#define TUN_F_USO4    0x20    /* I can handle USO for IPv4 packets */
+#define TUN_F_USO6    0x40    /* I can handle USO for IPv6 packets */
 
 #endif /* QEMU_TAP_LINUX_H */
diff --git a/net/tap-solaris.c b/net/tap-solaris.c
index 38e15028bf..a617a10e5c 100644
--- a/net/tap-solaris.c
+++ b/net/tap-solaris.c
@@ -236,7 +236,7 @@ int tap_fd_set_vnet_be(int fd, int is_be)
 }
 
 void tap_fd_set_offload(int fd, int csum, int tso4,
-                        int tso6, int ecn, int ufo)
+                        int tso6, int ecn, int ufo, int uso4, int uso6)
 {
 }
 
diff --git a/net/tap-stub.c b/net/tap-stub.c
index a0fa25804b..ac8dfc03b4 100644
--- a/net/tap-stub.c
+++ b/net/tap-stub.c
@@ -67,7 +67,7 @@ int tap_fd_set_vnet_be(int fd, int is_be)
 }
 
 void tap_fd_set_offload(int fd, int csum, int tso4,
-                        int tso6, int ecn, int ufo)
+                        int tso6, int ecn, int ufo, int uso4, int uso6)
 {
 }
 
diff --git a/net/tap-win32.c b/net/tap-win32.c
index f327d62ab0..7b8b4be02c 100644
--- a/net/tap-win32.c
+++ b/net/tap-win32.c
@@ -741,7 +741,7 @@ static void tap_using_vnet_hdr(NetClientState *nc, bool using_vnet_hdr)
 }
 
 static void tap_set_offload(NetClientState *nc, int csum, int tso4,
-                     int tso6, int ecn, int ufo)
+                     int tso6, int ecn, int ufo, int uso4, int uso6)
 {
 }
 
diff --git a/net/tap.c b/net/tap.c
index 1bf085d422..14ea4ef26f 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -307,14 +307,14 @@ static int tap_set_vnet_be(NetClientState *nc, bool is_be)
 }
 
 static void tap_set_offload(NetClientState *nc, int csum, int tso4,
-                     int tso6, int ecn, int ufo)
+                     int tso6, int ecn, int ufo, int uso4, int uso6)
 {
     TAPState *s = DO_UPCAST(TAPState, nc, nc);
     if (s->fd < 0) {
         return;
     }
 
-    tap_fd_set_offload(s->fd, csum, tso4, tso6, ecn, ufo);
+    tap_fd_set_offload(s->fd, csum, tso4, tso6, ecn, ufo, uso4, uso6);
 }
 
 static void tap_exit_notify(Notifier *notifier, void *data)
@@ -414,7 +414,7 @@ static TAPState *net_tap_fd_init(NetClientState *peer,
     s->using_vnet_hdr = false;
     s->has_ufo = tap_probe_has_ufo(s->fd);
     s->enabled = true;
-    tap_set_offload(&s->nc, 0, 0, 0, 0, 0);
+    tap_set_offload(&s->nc, 0, 0, 0, 0, 0, 0, 0);
     /*
      * Make sure host header length is set correctly in tap:
      * it might have been modified by another instance of qemu.
diff --git a/net/tap_int.h b/net/tap_int.h
index 547f8a5a28..d8861d81ba 100644
--- a/net/tap_int.h
+++ b/net/tap_int.h
@@ -37,7 +37,8 @@ void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp);
 int tap_probe_vnet_hdr(int fd, Error **errp);
 int tap_probe_vnet_hdr_len(int fd, int len);
 int tap_probe_has_ufo(int fd);
-void tap_fd_set_offload(int fd, int csum, int tso4, int tso6, int ecn, int ufo);
+void tap_fd_set_offload(int fd, int csum, int tso4, int tso6, int ecn, int ufo,
+                        int uso4, int uso6);
 void tap_fd_set_vnet_hdr_len(int fd, int len);
 int tap_fd_set_vnet_le(int fd, int vnet_is_le);
 int tap_fd_set_vnet_be(int fd, int vnet_is_be);
-- 
2.34.3



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

* [PATCH 2/4] virtio-net: Added USO flags to vhost support.
  2023-07-19 15:21 [PATCH 0/4] virtio-net: add USO feature (UDP segmentation offload) Yuri Benditovich
  2023-07-19 15:21 ` [PATCH 1/4] tap: Added USO support to tap device Yuri Benditovich
@ 2023-07-19 15:21 ` Yuri Benditovich
  2023-07-19 15:21 ` [PATCH 3/4] virtio-net: added USO support Yuri Benditovich
  2023-07-19 15:21 ` [PATCH 4/4] virtio-net: Added uso check Yuri Benditovich
  3 siblings, 0 replies; 11+ messages in thread
From: Yuri Benditovich @ 2023-07-19 15:21 UTC (permalink / raw)
  To: Dmitry Fleytman, Akihiko Odaki, Jason Wang, Sriram Yagnaraman,
	mst, Stefan Weil, qemu-devel
  Cc: yan, andrew

From: Andrew Melnychenko <andrew@daynix.com>

New features are subject to check with vhost-user and vdpa.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
---
 hw/net/vhost_net.c | 3 +++
 net/vhost-vdpa.c   | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index 6b958d6363..57427a3997 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -78,6 +78,9 @@ static const int user_feature_bits[] = {
     VIRTIO_F_RING_RESET,
     VIRTIO_NET_F_RSS,
     VIRTIO_NET_F_HASH_REPORT,
+    VIRTIO_NET_F_GUEST_USO4,
+    VIRTIO_NET_F_GUEST_USO6,
+    VIRTIO_NET_F_HOST_USO,
 
     /* This bit implies RARP isn't sent by QEMU out of band */
     VIRTIO_NET_F_GUEST_ANNOUNCE,
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index 9795306742..1dca37aae2 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -75,11 +75,14 @@ const int vdpa_feature_bits[] = {
     VIRTIO_NET_F_GUEST_TSO4,
     VIRTIO_NET_F_GUEST_TSO6,
     VIRTIO_NET_F_GUEST_UFO,
+    VIRTIO_NET_F_GUEST_USO4,
+    VIRTIO_NET_F_GUEST_USO6,
     VIRTIO_NET_F_HASH_REPORT,
     VIRTIO_NET_F_HOST_ECN,
     VIRTIO_NET_F_HOST_TSO4,
     VIRTIO_NET_F_HOST_TSO6,
     VIRTIO_NET_F_HOST_UFO,
+    VIRTIO_NET_F_HOST_USO,
     VIRTIO_NET_F_MQ,
     VIRTIO_NET_F_MRG_RXBUF,
     VIRTIO_NET_F_MTU,
-- 
2.34.3



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

* [PATCH 3/4] virtio-net: added USO support
  2023-07-19 15:21 [PATCH 0/4] virtio-net: add USO feature (UDP segmentation offload) Yuri Benditovich
  2023-07-19 15:21 ` [PATCH 1/4] tap: Added USO support to tap device Yuri Benditovich
  2023-07-19 15:21 ` [PATCH 2/4] virtio-net: Added USO flags to vhost support Yuri Benditovich
@ 2023-07-19 15:21 ` Yuri Benditovich
  2023-07-20  0:37   ` Akihiko Odaki
  2023-07-19 15:21 ` [PATCH 4/4] virtio-net: Added uso check Yuri Benditovich
  3 siblings, 1 reply; 11+ messages in thread
From: Yuri Benditovich @ 2023-07-19 15:21 UTC (permalink / raw)
  To: Dmitry Fleytman, Akihiko Odaki, Jason Wang, Sriram Yagnaraman,
	mst, Stefan Weil, qemu-devel
  Cc: yan, andrew

virtio-net can suggest USO features TX, RX v4 and RX v6,
depending on kernel TUN ability to support them. These
features require explicit enable in command-line.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
---
 hw/net/virtio-net.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index d2311e7d6e..e76cad923b 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -796,6 +796,10 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features,
         virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_TSO6);
         virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_ECN);
 
+        virtio_clear_feature(&features, VIRTIO_NET_F_HOST_USO);
+        virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_USO4);
+        virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_USO6);
+
         virtio_clear_feature(&features, VIRTIO_NET_F_HASH_REPORT);
     }
 
@@ -864,14 +868,16 @@ static void virtio_net_apply_guest_offloads(VirtIONet *n)
             !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_USO6)));
 }
 
-static uint64_t virtio_net_guest_offloads_by_features(uint32_t features)
+static uint64_t virtio_net_guest_offloads_by_features(uint64_t features)
 {
     static const uint64_t guest_offloads_mask =
         (1ULL << VIRTIO_NET_F_GUEST_CSUM) |
         (1ULL << VIRTIO_NET_F_GUEST_TSO4) |
         (1ULL << VIRTIO_NET_F_GUEST_TSO6) |
         (1ULL << VIRTIO_NET_F_GUEST_ECN)  |
-        (1ULL << VIRTIO_NET_F_GUEST_UFO);
+        (1ULL << VIRTIO_NET_F_GUEST_UFO)  |
+        (1ULL << VIRTIO_NET_F_GUEST_USO4) |
+        (1ULL << VIRTIO_NET_F_GUEST_USO6);
 
     return guest_offloads_mask & features;
 }
@@ -3924,6 +3930,12 @@ static Property virtio_net_properties[] = {
     DEFINE_PROP_INT32("speed", VirtIONet, net_conf.speed, SPEED_UNKNOWN),
     DEFINE_PROP_STRING("duplex", VirtIONet, net_conf.duplex_str),
     DEFINE_PROP_BOOL("failover", VirtIONet, failover, false),
+    DEFINE_PROP_BIT64("guest_uso4", VirtIONet, host_features,
+                      VIRTIO_NET_F_GUEST_USO4, false),
+    DEFINE_PROP_BIT64("guest_uso6", VirtIONet, host_features,
+                      VIRTIO_NET_F_GUEST_USO6, false),
+    DEFINE_PROP_BIT64("host_uso", VirtIONet, host_features,
+                      VIRTIO_NET_F_HOST_USO, false),
     DEFINE_PROP_END_OF_LIST(),
 };
 
-- 
2.34.3



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

* [PATCH 4/4] virtio-net: Added uso check
  2023-07-19 15:21 [PATCH 0/4] virtio-net: add USO feature (UDP segmentation offload) Yuri Benditovich
                   ` (2 preceding siblings ...)
  2023-07-19 15:21 ` [PATCH 3/4] virtio-net: added USO support Yuri Benditovich
@ 2023-07-19 15:21 ` Yuri Benditovich
  2023-07-20  0:41   ` Akihiko Odaki
  3 siblings, 1 reply; 11+ messages in thread
From: Yuri Benditovich @ 2023-07-19 15:21 UTC (permalink / raw)
  To: Dmitry Fleytman, Akihiko Odaki, Jason Wang, Sriram Yagnaraman,
	mst, Stefan Weil, qemu-devel
  Cc: yan, andrew

From: Andrew Melnychenko <andrew@daynix.com>

Added tap uso check with stubs for non-Linux systems.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
---
 hw/net/virtio-net.c | 15 +++++++++++++++
 include/net/net.h   |  3 +++
 net/net.c           |  9 +++++++++
 net/tap-bsd.c       |  5 +++++
 net/tap-linux.c     | 12 ++++++++++++
 net/tap-solaris.c   |  5 +++++
 net/tap-stub.c      |  5 +++++
 net/tap.c           | 12 ++++++++++++
 net/tap_int.h       |  1 +
 9 files changed, 67 insertions(+)

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index e76cad923b..d950d3a77f 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -659,6 +659,15 @@ static int peer_has_ufo(VirtIONet *n)
     return n->has_ufo;
 }
 
+static int peer_has_uso(VirtIONet *n)
+{
+    if (!peer_has_vnet_hdr(n)) {
+        return 0;
+    }
+
+    return qemu_has_uso(qemu_get_queue(n->nic)->peer);
+}
+
 static void virtio_net_set_mrg_rx_bufs(VirtIONet *n, int mergeable_rx_bufs,
                                        int version_1, int hash_report)
 {
@@ -808,6 +817,12 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features,
         virtio_clear_feature(&features, VIRTIO_NET_F_HOST_UFO);
     }
 
+    if (!peer_has_uso(n)) {
+        virtio_clear_feature(&features, VIRTIO_NET_F_HOST_USO);
+        virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_USO4);
+        virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_USO6);
+    }
+
     if (!get_vhost_net(nc->peer)) {
         return features;
     }
diff --git a/include/net/net.h b/include/net/net.h
index b5ccfbbffb..330d285930 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -54,6 +54,7 @@ typedef void (LinkStatusChanged)(NetClientState *);
 typedef void (NetClientDestructor)(NetClientState *);
 typedef RxFilterInfo *(QueryRxFilter)(NetClientState *);
 typedef bool (HasUfo)(NetClientState *);
+typedef bool (HasUso)(NetClientState *);
 typedef bool (HasVnetHdr)(NetClientState *);
 typedef bool (HasVnetHdrLen)(NetClientState *, int);
 typedef bool (GetUsingVnetHdr)(NetClientState *);
@@ -84,6 +85,7 @@ typedef struct NetClientInfo {
     QueryRxFilter *query_rx_filter;
     NetPoll *poll;
     HasUfo *has_ufo;
+    HasUso *has_uso;
     HasVnetHdr *has_vnet_hdr;
     HasVnetHdrLen *has_vnet_hdr_len;
     GetUsingVnetHdr *get_using_vnet_hdr;
@@ -187,6 +189,7 @@ void qemu_set_info_str(NetClientState *nc,
                        const char *fmt, ...) G_GNUC_PRINTF(2, 3);
 void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6]);
 bool qemu_has_ufo(NetClientState *nc);
+bool qemu_has_uso(NetClientState *nc);
 bool qemu_has_vnet_hdr(NetClientState *nc);
 bool qemu_has_vnet_hdr_len(NetClientState *nc, int len);
 bool qemu_get_using_vnet_hdr(NetClientState *nc);
diff --git a/net/net.c b/net/net.c
index 543e6dec43..b110e61f66 100644
--- a/net/net.c
+++ b/net/net.c
@@ -495,6 +495,15 @@ bool qemu_has_ufo(NetClientState *nc)
     return nc->info->has_ufo(nc);
 }
 
+bool qemu_has_uso(NetClientState *nc)
+{
+    if (!nc || !nc->info->has_uso) {
+        return false;
+    }
+
+    return nc->info->has_uso(nc);
+}
+
 bool qemu_has_vnet_hdr(NetClientState *nc)
 {
     if (!nc || !nc->info->has_vnet_hdr) {
diff --git a/net/tap-bsd.c b/net/tap-bsd.c
index abd16a2ad2..274ea7bd2c 100644
--- a/net/tap-bsd.c
+++ b/net/tap-bsd.c
@@ -212,6 +212,11 @@ int tap_probe_has_ufo(int fd)
     return 0;
 }
 
+int tap_probe_has_uso(int fd)
+{
+    return 0;
+}
+
 int tap_probe_vnet_hdr_len(int fd, int len)
 {
     return 0;
diff --git a/net/tap-linux.c b/net/tap-linux.c
index 30fcca1bc2..c7e514ecb0 100644
--- a/net/tap-linux.c
+++ b/net/tap-linux.c
@@ -173,6 +173,18 @@ int tap_probe_has_ufo(int fd)
     return 1;
 }
 
+int tap_probe_has_uso(int fd)
+{
+    unsigned offload;
+
+    offload = TUN_F_CSUM | TUN_F_USO4 | TUN_F_USO6;
+
+    if (ioctl(fd, TUNSETOFFLOAD, offload) < 0) {
+        return 0;
+    }
+    return 1;
+}
+
 /* Verify that we can assign given length */
 int tap_probe_vnet_hdr_len(int fd, int len)
 {
diff --git a/net/tap-solaris.c b/net/tap-solaris.c
index a617a10e5c..08b13af512 100644
--- a/net/tap-solaris.c
+++ b/net/tap-solaris.c
@@ -216,6 +216,11 @@ int tap_probe_has_ufo(int fd)
     return 0;
 }
 
+int tap_probe_has_uso(int fd)
+{
+    return 0;
+}
+
 int tap_probe_vnet_hdr_len(int fd, int len)
 {
     return 0;
diff --git a/net/tap-stub.c b/net/tap-stub.c
index ac8dfc03b4..4b24f61e3a 100644
--- a/net/tap-stub.c
+++ b/net/tap-stub.c
@@ -47,6 +47,11 @@ int tap_probe_has_ufo(int fd)
     return 0;
 }
 
+int tap_probe_has_uso(int fd)
+{
+    return 0;
+}
+
 int tap_probe_vnet_hdr_len(int fd, int len)
 {
     return 0;
diff --git a/net/tap.c b/net/tap.c
index 14ea4ef26f..bcea8d03f9 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -57,6 +57,7 @@ typedef struct TAPState {
     bool write_poll;
     bool using_vnet_hdr;
     bool has_ufo;
+    bool has_uso;
     bool enabled;
     VHostNetState *vhost_net;
     unsigned host_vnet_hdr_len;
@@ -237,6 +238,15 @@ static bool tap_has_ufo(NetClientState *nc)
     return s->has_ufo;
 }
 
+static bool tap_has_uso(NetClientState *nc)
+{
+    TAPState *s = DO_UPCAST(TAPState, nc, nc);
+
+    assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
+
+    return s->has_uso;
+}
+
 static bool tap_has_vnet_hdr(NetClientState *nc)
 {
     TAPState *s = DO_UPCAST(TAPState, nc, nc);
@@ -384,6 +394,7 @@ static NetClientInfo net_tap_info = {
     .poll = tap_poll,
     .cleanup = tap_cleanup,
     .has_ufo = tap_has_ufo,
+    .has_uso = tap_has_uso,
     .has_vnet_hdr = tap_has_vnet_hdr,
     .has_vnet_hdr_len = tap_has_vnet_hdr_len,
     .get_using_vnet_hdr = tap_get_using_vnet_hdr,
@@ -413,6 +424,7 @@ static TAPState *net_tap_fd_init(NetClientState *peer,
     s->host_vnet_hdr_len = vnet_hdr ? sizeof(struct virtio_net_hdr) : 0;
     s->using_vnet_hdr = false;
     s->has_ufo = tap_probe_has_ufo(s->fd);
+    s->has_uso = tap_probe_has_uso(s->fd);
     s->enabled = true;
     tap_set_offload(&s->nc, 0, 0, 0, 0, 0, 0, 0);
     /*
diff --git a/net/tap_int.h b/net/tap_int.h
index d8861d81ba..9a2175655b 100644
--- a/net/tap_int.h
+++ b/net/tap_int.h
@@ -37,6 +37,7 @@ void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp);
 int tap_probe_vnet_hdr(int fd, Error **errp);
 int tap_probe_vnet_hdr_len(int fd, int len);
 int tap_probe_has_ufo(int fd);
+int tap_probe_has_uso(int fd);
 void tap_fd_set_offload(int fd, int csum, int tso4, int tso6, int ecn, int ufo,
                         int uso4, int uso6);
 void tap_fd_set_vnet_hdr_len(int fd, int len);
-- 
2.34.3



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

* Re: [PATCH 1/4] tap: Added USO support to tap device.
  2023-07-19 15:21 ` [PATCH 1/4] tap: Added USO support to tap device Yuri Benditovich
@ 2023-07-20  0:31   ` Akihiko Odaki
  2023-07-20 15:53     ` Yuri Benditovich
  0 siblings, 1 reply; 11+ messages in thread
From: Akihiko Odaki @ 2023-07-20  0:31 UTC (permalink / raw)
  To: Yuri Benditovich, Dmitry Fleytman, Jason Wang, Sriram Yagnaraman,
	mst, Stefan Weil, qemu-devel
  Cc: yan, andrew

Nitpicking: the subject of this patch is somewhat unconventional. What 
about: "tap: Add USO support to tap device"?

On 2023/07/20 0:21, Yuri Benditovich wrote:
> From: Andrew Melnychenko <andrew@daynix.com>
> 
> Passing additional parameters (USOv4 and USOv6 offloads) when
> setting TAP offloads
> 
> Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
> Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
> ---
>   hw/net/e1000e_core.c |  2 +-
>   hw/net/igb_core.c    |  2 +-
>   hw/net/virtio-net.c  |  4 +++-
>   hw/net/vmxnet3.c     |  2 ++
>   include/net/net.h    |  4 ++--
>   net/net.c            |  4 ++--
>   net/tap-bsd.c        |  2 +-
>   net/tap-linux.c      | 15 ++++++++++++---
>   net/tap-linux.h      |  2 ++
>   net/tap-solaris.c    |  2 +-
>   net/tap-stub.c       |  2 +-
>   net/tap-win32.c      |  2 +-
>   net/tap.c            |  6 +++---
>   net/tap_int.h        |  3 ++-
>   14 files changed, 34 insertions(+), 18 deletions(-)
> 
> diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c
> index f8aeafa16b..d4055956ad 100644
> --- a/hw/net/e1000e_core.c
> +++ b/hw/net/e1000e_core.c
> @@ -2852,7 +2852,7 @@ e1000e_update_rx_offloads(E1000ECore *core)
>   
>       if (core->has_vnet) {
>           qemu_set_offload(qemu_get_queue(core->owner_nic)->peer,
> -                         cso_state, 0, 0, 0, 0);
> +                         cso_state, 0, 0, 0, 0, 0, 0);
>       }
>   }
>   
> diff --git a/hw/net/igb_core.c b/hw/net/igb_core.c
> index 8b6b75c522..389eef1549 100644
> --- a/hw/net/igb_core.c
> +++ b/hw/net/igb_core.c
> @@ -2753,7 +2753,7 @@ igb_update_rx_offloads(IGBCore *core)
>   
>       if (core->has_vnet) {
>           qemu_set_offload(qemu_get_queue(core->owner_nic)->peer,
> -                         cso_state, 0, 0, 0, 0);
> +                         cso_state, 0, 0, 0, 0, 0, 0);
>       }
>   }
>   
> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> index 7102ec4817..d2311e7d6e 100644
> --- a/hw/net/virtio-net.c
> +++ b/hw/net/virtio-net.c
> @@ -859,7 +859,9 @@ static void virtio_net_apply_guest_offloads(VirtIONet *n)
>               !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_TSO4)),
>               !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_TSO6)),
>               !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_ECN)),
> -            !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_UFO)));
> +            !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_UFO)),
> +            !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_USO4)),
> +            !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_USO6)));
>   }
>   
>   static uint64_t virtio_net_guest_offloads_by_features(uint32_t features)
> diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c
> index 5dfacb1098..886adae42b 100644
> --- a/hw/net/vmxnet3.c
> +++ b/hw/net/vmxnet3.c
> @@ -1341,6 +1341,8 @@ static void vmxnet3_update_features(VMXNET3State *s)
>                            s->lro_supported,
>                            s->lro_supported,
>                            0,
> +                         0,
> +                         0,
>                            0);
>       }
>   }
> diff --git a/include/net/net.h b/include/net/net.h
> index 1448d00afb..b5ccfbbffb 100644
> --- a/include/net/net.h
> +++ b/include/net/net.h
> @@ -58,7 +58,7 @@ typedef bool (HasVnetHdr)(NetClientState *);
>   typedef bool (HasVnetHdrLen)(NetClientState *, int);
>   typedef bool (GetUsingVnetHdr)(NetClientState *);
>   typedef void (UsingVnetHdr)(NetClientState *, bool);
> -typedef void (SetOffload)(NetClientState *, int, int, int, int, int);
> +typedef void (SetOffload)(NetClientState *, int, int, int, int, int, int, int);
>   typedef int (GetVnetHdrLen)(NetClientState *);
>   typedef void (SetVnetHdrLen)(NetClientState *, int);
>   typedef int (SetVnetLE)(NetClientState *, bool);
> @@ -192,7 +192,7 @@ bool qemu_has_vnet_hdr_len(NetClientState *nc, int len);
>   bool qemu_get_using_vnet_hdr(NetClientState *nc);
>   void qemu_using_vnet_hdr(NetClientState *nc, bool enable);
>   void qemu_set_offload(NetClientState *nc, int csum, int tso4, int tso6,
> -                      int ecn, int ufo);
> +                      int ecn, int ufo, int uso4, int uso6);
>   int qemu_get_vnet_hdr_len(NetClientState *nc);
>   void qemu_set_vnet_hdr_len(NetClientState *nc, int len);
>   int qemu_set_vnet_le(NetClientState *nc, bool is_le);
> diff --git a/net/net.c b/net/net.c
> index 6492ad530e..543e6dec43 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -532,13 +532,13 @@ void qemu_using_vnet_hdr(NetClientState *nc, bool enable)
>   }
>   
>   void qemu_set_offload(NetClientState *nc, int csum, int tso4, int tso6,
> -                          int ecn, int ufo)
> +                          int ecn, int ufo, int uso4, int uso6)
>   {
>       if (!nc || !nc->info->set_offload) {
>           return;
>       }
>   
> -    nc->info->set_offload(nc, csum, tso4, tso6, ecn, ufo);
> +    nc->info->set_offload(nc, csum, tso4, tso6, ecn, ufo, uso4, uso6);
>   }
>   
>   int qemu_get_vnet_hdr_len(NetClientState *nc)
> diff --git a/net/tap-bsd.c b/net/tap-bsd.c
> index 4c98fdd337..abd16a2ad2 100644
> --- a/net/tap-bsd.c
> +++ b/net/tap-bsd.c
> @@ -232,7 +232,7 @@ int tap_fd_set_vnet_be(int fd, int is_be)
>   }
>   
>   void tap_fd_set_offload(int fd, int csum, int tso4,
> -                        int tso6, int ecn, int ufo)
> +                        int tso6, int ecn, int ufo, int uso4, int uso6)
>   {
>   }
>   
> diff --git a/net/tap-linux.c b/net/tap-linux.c
> index f54f308d35..30fcca1bc2 100644
> --- a/net/tap-linux.c
> +++ b/net/tap-linux.c
> @@ -237,7 +237,7 @@ int tap_fd_set_vnet_be(int fd, int is_be)
>   }
>   
>   void tap_fd_set_offload(int fd, int csum, int tso4,
> -                        int tso6, int ecn, int ufo)
> +                        int tso6, int ecn, int ufo, int uso4, int uso6)
>   {
>       unsigned int offload = 0;
>   
> @@ -256,13 +256,22 @@ void tap_fd_set_offload(int fd, int csum, int tso4,
>               offload |= TUN_F_TSO_ECN;
>           if (ufo)
>               offload |= TUN_F_UFO;
> +        if (uso4) {
> +            offload |= TUN_F_USO4;
> +        }
> +        if (uso6) {
> +            offload |= TUN_F_USO6;
> +        }
>       }
>   
>       if (ioctl(fd, TUNSETOFFLOAD, offload) != 0) {
> -        offload &= ~TUN_F_UFO;
> +        offload &= ~(TUN_F_USO4 | TUN_F_USO6);

Shouldn't we just report an error when USO is requested on a system that 
does not support it?

>           if (ioctl(fd, TUNSETOFFLOAD, offload) != 0) {
> -            fprintf(stderr, "TUNSETOFFLOAD ioctl() failed: %s\n",
> +            offload &= ~TUN_F_UFO;
> +            if (ioctl(fd, TUNSETOFFLOAD, offload) != 0) {
> +                fprintf(stderr, "TUNSETOFFLOAD ioctl() failed: %s\n",
>                       strerror(errno));
> +            }
>           }
>       }
>   }
> diff --git a/net/tap-linux.h b/net/tap-linux.h
> index bbbb62c2a7..9a58cecb7f 100644
> --- a/net/tap-linux.h
> +++ b/net/tap-linux.h
> @@ -50,5 +50,7 @@
>   #define TUN_F_TSO6    0x04    /* I can handle TSO for IPv6 packets */
>   #define TUN_F_TSO_ECN 0x08    /* I can handle TSO with ECN bits. */
>   #define TUN_F_UFO     0x10    /* I can handle UFO packets */
> +#define TUN_F_USO4    0x20    /* I can handle USO for IPv4 packets */
> +#define TUN_F_USO6    0x40    /* I can handle USO for IPv6 packets */
>   
>   #endif /* QEMU_TAP_LINUX_H */
> diff --git a/net/tap-solaris.c b/net/tap-solaris.c
> index 38e15028bf..a617a10e5c 100644
> --- a/net/tap-solaris.c
> +++ b/net/tap-solaris.c
> @@ -236,7 +236,7 @@ int tap_fd_set_vnet_be(int fd, int is_be)
>   }
>   
>   void tap_fd_set_offload(int fd, int csum, int tso4,
> -                        int tso6, int ecn, int ufo)
> +                        int tso6, int ecn, int ufo, int uso4, int uso6)
>   {
>   }
>   
> diff --git a/net/tap-stub.c b/net/tap-stub.c
> index a0fa25804b..ac8dfc03b4 100644
> --- a/net/tap-stub.c
> +++ b/net/tap-stub.c
> @@ -67,7 +67,7 @@ int tap_fd_set_vnet_be(int fd, int is_be)
>   }
>   
>   void tap_fd_set_offload(int fd, int csum, int tso4,
> -                        int tso6, int ecn, int ufo)
> +                        int tso6, int ecn, int ufo, int uso4, int uso6)
>   {
>   }
>   
> diff --git a/net/tap-win32.c b/net/tap-win32.c
> index f327d62ab0..7b8b4be02c 100644
> --- a/net/tap-win32.c
> +++ b/net/tap-win32.c
> @@ -741,7 +741,7 @@ static void tap_using_vnet_hdr(NetClientState *nc, bool using_vnet_hdr)
>   }
>   
>   static void tap_set_offload(NetClientState *nc, int csum, int tso4,
> -                     int tso6, int ecn, int ufo)
> +                     int tso6, int ecn, int ufo, int uso4, int uso6)
>   {
>   }
>   
> diff --git a/net/tap.c b/net/tap.c
> index 1bf085d422..14ea4ef26f 100644
> --- a/net/tap.c
> +++ b/net/tap.c
> @@ -307,14 +307,14 @@ static int tap_set_vnet_be(NetClientState *nc, bool is_be)
>   }
>   
>   static void tap_set_offload(NetClientState *nc, int csum, int tso4,
> -                     int tso6, int ecn, int ufo)
> +                     int tso6, int ecn, int ufo, int uso4, int uso6)
>   {
>       TAPState *s = DO_UPCAST(TAPState, nc, nc);
>       if (s->fd < 0) {
>           return;
>       }
>   
> -    tap_fd_set_offload(s->fd, csum, tso4, tso6, ecn, ufo);
> +    tap_fd_set_offload(s->fd, csum, tso4, tso6, ecn, ufo, uso4, uso6);
>   }
>   
>   static void tap_exit_notify(Notifier *notifier, void *data)
> @@ -414,7 +414,7 @@ static TAPState *net_tap_fd_init(NetClientState *peer,
>       s->using_vnet_hdr = false;
>       s->has_ufo = tap_probe_has_ufo(s->fd);
>       s->enabled = true;
> -    tap_set_offload(&s->nc, 0, 0, 0, 0, 0);
> +    tap_set_offload(&s->nc, 0, 0, 0, 0, 0, 0, 0);
>       /*
>        * Make sure host header length is set correctly in tap:
>        * it might have been modified by another instance of qemu.
> diff --git a/net/tap_int.h b/net/tap_int.h
> index 547f8a5a28..d8861d81ba 100644
> --- a/net/tap_int.h
> +++ b/net/tap_int.h
> @@ -37,7 +37,8 @@ void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp);
>   int tap_probe_vnet_hdr(int fd, Error **errp);
>   int tap_probe_vnet_hdr_len(int fd, int len);
>   int tap_probe_has_ufo(int fd);
> -void tap_fd_set_offload(int fd, int csum, int tso4, int tso6, int ecn, int ufo);
> +void tap_fd_set_offload(int fd, int csum, int tso4, int tso6, int ecn, int ufo,
> +                        int uso4, int uso6);
>   void tap_fd_set_vnet_hdr_len(int fd, int len);
>   int tap_fd_set_vnet_le(int fd, int vnet_is_le);
>   int tap_fd_set_vnet_be(int fd, int vnet_is_be);


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

* Re: [PATCH 3/4] virtio-net: added USO support
  2023-07-19 15:21 ` [PATCH 3/4] virtio-net: added USO support Yuri Benditovich
@ 2023-07-20  0:37   ` Akihiko Odaki
  2023-07-20 16:05     ` Yuri Benditovich
  0 siblings, 1 reply; 11+ messages in thread
From: Akihiko Odaki @ 2023-07-20  0:37 UTC (permalink / raw)
  To: Yuri Benditovich, Dmitry Fleytman, Jason Wang, Sriram Yagnaraman,
	mst, Stefan Weil, qemu-devel
  Cc: yan, andrew

On 2023/07/20 0:21, Yuri Benditovich wrote:
> virtio-net can suggest USO features TX, RX v4 and RX v6,
> depending on kernel TUN ability to support them. These
> features require explicit enable in command-line.

Shouldn't we enable these by default as the other offload features are?

> 
> Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
> ---
>   hw/net/virtio-net.c | 16 ++++++++++++++--
>   1 file changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> index d2311e7d6e..e76cad923b 100644
> --- a/hw/net/virtio-net.c
> +++ b/hw/net/virtio-net.c
> @@ -796,6 +796,10 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features,
>           virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_TSO6);
>           virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_ECN);
>   
> +        virtio_clear_feature(&features, VIRTIO_NET_F_HOST_USO);
> +        virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_USO4);
> +        virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_USO6);
> +
>           virtio_clear_feature(&features, VIRTIO_NET_F_HASH_REPORT);
>       }
>   
> @@ -864,14 +868,16 @@ static void virtio_net_apply_guest_offloads(VirtIONet *n)
>               !!(n->curr_guest_offloads & (1ULL << VIRTIO_NET_F_GUEST_USO6)));
>   }
>   
> -static uint64_t virtio_net_guest_offloads_by_features(uint32_t features)
> +static uint64_t virtio_net_guest_offloads_by_features(uint64_t features)
>   {
>       static const uint64_t guest_offloads_mask =
>           (1ULL << VIRTIO_NET_F_GUEST_CSUM) |
>           (1ULL << VIRTIO_NET_F_GUEST_TSO4) |
>           (1ULL << VIRTIO_NET_F_GUEST_TSO6) |
>           (1ULL << VIRTIO_NET_F_GUEST_ECN)  |
> -        (1ULL << VIRTIO_NET_F_GUEST_UFO);
> +        (1ULL << VIRTIO_NET_F_GUEST_UFO)  |
> +        (1ULL << VIRTIO_NET_F_GUEST_USO4) |
> +        (1ULL << VIRTIO_NET_F_GUEST_USO6);
>   
>       return guest_offloads_mask & features;
>   }
> @@ -3924,6 +3930,12 @@ static Property virtio_net_properties[] = {
>       DEFINE_PROP_INT32("speed", VirtIONet, net_conf.speed, SPEED_UNKNOWN),
>       DEFINE_PROP_STRING("duplex", VirtIONet, net_conf.duplex_str),
>       DEFINE_PROP_BOOL("failover", VirtIONet, failover, false),
> +    DEFINE_PROP_BIT64("guest_uso4", VirtIONet, host_features,
> +                      VIRTIO_NET_F_GUEST_USO4, false),
> +    DEFINE_PROP_BIT64("guest_uso6", VirtIONet, host_features,
> +                      VIRTIO_NET_F_GUEST_USO6, false),
> +    DEFINE_PROP_BIT64("host_uso", VirtIONet, host_features,
> +                      VIRTIO_NET_F_HOST_USO, false),
>       DEFINE_PROP_END_OF_LIST(),
>   };
>   


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

* Re: [PATCH 4/4] virtio-net: Added uso check
  2023-07-19 15:21 ` [PATCH 4/4] virtio-net: Added uso check Yuri Benditovich
@ 2023-07-20  0:41   ` Akihiko Odaki
  0 siblings, 0 replies; 11+ messages in thread
From: Akihiko Odaki @ 2023-07-20  0:41 UTC (permalink / raw)
  To: Yuri Benditovich, Dmitry Fleytman, Jason Wang, Sriram Yagnaraman,
	mst, Stefan Weil, qemu-devel
  Cc: yan, andrew

Placing this patch after "[PATCH 3/4] virtio-net: added USO support" may 
interfer with "git bisect" on a host that does not support USO as 
virtio-net can advertise USO support where it's not supported.

I suggest to combine this patch with the earlier patch aforementioned. 
It will make the entire patch big so I think it's also better to extract 
the change for tap into another patch.

On 2023/07/20 0:21, Yuri Benditovich wrote:
> From: Andrew Melnychenko <andrew@daynix.com>
> 
> Added tap uso check with stubs for non-Linux systems.
> 
> Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
> Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
> ---
>   hw/net/virtio-net.c | 15 +++++++++++++++
>   include/net/net.h   |  3 +++
>   net/net.c           |  9 +++++++++
>   net/tap-bsd.c       |  5 +++++
>   net/tap-linux.c     | 12 ++++++++++++
>   net/tap-solaris.c   |  5 +++++
>   net/tap-stub.c      |  5 +++++
>   net/tap.c           | 12 ++++++++++++
>   net/tap_int.h       |  1 +
>   9 files changed, 67 insertions(+)
> 
> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> index e76cad923b..d950d3a77f 100644
> --- a/hw/net/virtio-net.c
> +++ b/hw/net/virtio-net.c
> @@ -659,6 +659,15 @@ static int peer_has_ufo(VirtIONet *n)
>       return n->has_ufo;
>   }
>   
> +static int peer_has_uso(VirtIONet *n)
> +{
> +    if (!peer_has_vnet_hdr(n)) {
> +        return 0;
> +    }
> +
> +    return qemu_has_uso(qemu_get_queue(n->nic)->peer);
> +}
> +
>   static void virtio_net_set_mrg_rx_bufs(VirtIONet *n, int mergeable_rx_bufs,
>                                          int version_1, int hash_report)
>   {
> @@ -808,6 +817,12 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features,
>           virtio_clear_feature(&features, VIRTIO_NET_F_HOST_UFO);
>       }
>   
> +    if (!peer_has_uso(n)) {
> +        virtio_clear_feature(&features, VIRTIO_NET_F_HOST_USO);
> +        virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_USO4);
> +        virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_USO6);
> +    }
> +
>       if (!get_vhost_net(nc->peer)) {
>           return features;
>       }
> diff --git a/include/net/net.h b/include/net/net.h
> index b5ccfbbffb..330d285930 100644
> --- a/include/net/net.h
> +++ b/include/net/net.h
> @@ -54,6 +54,7 @@ typedef void (LinkStatusChanged)(NetClientState *);
>   typedef void (NetClientDestructor)(NetClientState *);
>   typedef RxFilterInfo *(QueryRxFilter)(NetClientState *);
>   typedef bool (HasUfo)(NetClientState *);
> +typedef bool (HasUso)(NetClientState *);
>   typedef bool (HasVnetHdr)(NetClientState *);
>   typedef bool (HasVnetHdrLen)(NetClientState *, int);
>   typedef bool (GetUsingVnetHdr)(NetClientState *);
> @@ -84,6 +85,7 @@ typedef struct NetClientInfo {
>       QueryRxFilter *query_rx_filter;
>       NetPoll *poll;
>       HasUfo *has_ufo;
> +    HasUso *has_uso;
>       HasVnetHdr *has_vnet_hdr;
>       HasVnetHdrLen *has_vnet_hdr_len;
>       GetUsingVnetHdr *get_using_vnet_hdr;
> @@ -187,6 +189,7 @@ void qemu_set_info_str(NetClientState *nc,
>                          const char *fmt, ...) G_GNUC_PRINTF(2, 3);
>   void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6]);
>   bool qemu_has_ufo(NetClientState *nc);
> +bool qemu_has_uso(NetClientState *nc);
>   bool qemu_has_vnet_hdr(NetClientState *nc);
>   bool qemu_has_vnet_hdr_len(NetClientState *nc, int len);
>   bool qemu_get_using_vnet_hdr(NetClientState *nc);
> diff --git a/net/net.c b/net/net.c
> index 543e6dec43..b110e61f66 100644
> --- a/net/net.c
> +++ b/net/net.c
> @@ -495,6 +495,15 @@ bool qemu_has_ufo(NetClientState *nc)
>       return nc->info->has_ufo(nc);
>   }
>   
> +bool qemu_has_uso(NetClientState *nc)
> +{
> +    if (!nc || !nc->info->has_uso) {
> +        return false;
> +    }
> +
> +    return nc->info->has_uso(nc);
> +}
> +
>   bool qemu_has_vnet_hdr(NetClientState *nc)
>   {
>       if (!nc || !nc->info->has_vnet_hdr) {
> diff --git a/net/tap-bsd.c b/net/tap-bsd.c
> index abd16a2ad2..274ea7bd2c 100644
> --- a/net/tap-bsd.c
> +++ b/net/tap-bsd.c
> @@ -212,6 +212,11 @@ int tap_probe_has_ufo(int fd)
>       return 0;
>   }
>   
> +int tap_probe_has_uso(int fd)
> +{
> +    return 0;
> +}
> +
>   int tap_probe_vnet_hdr_len(int fd, int len)
>   {
>       return 0;
> diff --git a/net/tap-linux.c b/net/tap-linux.c
> index 30fcca1bc2..c7e514ecb0 100644
> --- a/net/tap-linux.c
> +++ b/net/tap-linux.c
> @@ -173,6 +173,18 @@ int tap_probe_has_ufo(int fd)
>       return 1;
>   }
>   
> +int tap_probe_has_uso(int fd)
> +{
> +    unsigned offload;
> +
> +    offload = TUN_F_CSUM | TUN_F_USO4 | TUN_F_USO6;
> +
> +    if (ioctl(fd, TUNSETOFFLOAD, offload) < 0) {
> +        return 0;
> +    }
> +    return 1;
> +}
> +
>   /* Verify that we can assign given length */
>   int tap_probe_vnet_hdr_len(int fd, int len)
>   {
> diff --git a/net/tap-solaris.c b/net/tap-solaris.c
> index a617a10e5c..08b13af512 100644
> --- a/net/tap-solaris.c
> +++ b/net/tap-solaris.c
> @@ -216,6 +216,11 @@ int tap_probe_has_ufo(int fd)
>       return 0;
>   }
>   
> +int tap_probe_has_uso(int fd)
> +{
> +    return 0;
> +}
> +
>   int tap_probe_vnet_hdr_len(int fd, int len)
>   {
>       return 0;
> diff --git a/net/tap-stub.c b/net/tap-stub.c
> index ac8dfc03b4..4b24f61e3a 100644
> --- a/net/tap-stub.c
> +++ b/net/tap-stub.c
> @@ -47,6 +47,11 @@ int tap_probe_has_ufo(int fd)
>       return 0;
>   }
>   
> +int tap_probe_has_uso(int fd)
> +{
> +    return 0;
> +}
> +
>   int tap_probe_vnet_hdr_len(int fd, int len)
>   {
>       return 0;
> diff --git a/net/tap.c b/net/tap.c
> index 14ea4ef26f..bcea8d03f9 100644
> --- a/net/tap.c
> +++ b/net/tap.c
> @@ -57,6 +57,7 @@ typedef struct TAPState {
>       bool write_poll;
>       bool using_vnet_hdr;
>       bool has_ufo;
> +    bool has_uso;
>       bool enabled;
>       VHostNetState *vhost_net;
>       unsigned host_vnet_hdr_len;
> @@ -237,6 +238,15 @@ static bool tap_has_ufo(NetClientState *nc)
>       return s->has_ufo;
>   }
>   
> +static bool tap_has_uso(NetClientState *nc)
> +{
> +    TAPState *s = DO_UPCAST(TAPState, nc, nc);
> +
> +    assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
> +
> +    return s->has_uso;
> +}
> +
>   static bool tap_has_vnet_hdr(NetClientState *nc)
>   {
>       TAPState *s = DO_UPCAST(TAPState, nc, nc);
> @@ -384,6 +394,7 @@ static NetClientInfo net_tap_info = {
>       .poll = tap_poll,
>       .cleanup = tap_cleanup,
>       .has_ufo = tap_has_ufo,
> +    .has_uso = tap_has_uso,
>       .has_vnet_hdr = tap_has_vnet_hdr,
>       .has_vnet_hdr_len = tap_has_vnet_hdr_len,
>       .get_using_vnet_hdr = tap_get_using_vnet_hdr,
> @@ -413,6 +424,7 @@ static TAPState *net_tap_fd_init(NetClientState *peer,
>       s->host_vnet_hdr_len = vnet_hdr ? sizeof(struct virtio_net_hdr) : 0;
>       s->using_vnet_hdr = false;
>       s->has_ufo = tap_probe_has_ufo(s->fd);
> +    s->has_uso = tap_probe_has_uso(s->fd);
>       s->enabled = true;
>       tap_set_offload(&s->nc, 0, 0, 0, 0, 0, 0, 0);
>       /*
> diff --git a/net/tap_int.h b/net/tap_int.h
> index d8861d81ba..9a2175655b 100644
> --- a/net/tap_int.h
> +++ b/net/tap_int.h
> @@ -37,6 +37,7 @@ void tap_set_sndbuf(int fd, const NetdevTapOptions *tap, Error **errp);
>   int tap_probe_vnet_hdr(int fd, Error **errp);
>   int tap_probe_vnet_hdr_len(int fd, int len);
>   int tap_probe_has_ufo(int fd);
> +int tap_probe_has_uso(int fd);
>   void tap_fd_set_offload(int fd, int csum, int tso4, int tso6, int ecn, int ufo,
>                           int uso4, int uso6);
>   void tap_fd_set_vnet_hdr_len(int fd, int len);


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

* Re: [PATCH 1/4] tap: Added USO support to tap device.
  2023-07-20  0:31   ` Akihiko Odaki
@ 2023-07-20 15:53     ` Yuri Benditovich
  0 siblings, 0 replies; 11+ messages in thread
From: Yuri Benditovich @ 2023-07-20 15:53 UTC (permalink / raw)
  To: Akihiko Odaki
  Cc: Dmitry Fleytman, Jason Wang, Sriram Yagnaraman, mst, Stefan Weil,
	qemu-devel, yan, andrew

[-- Attachment #1: Type: text/plain, Size: 11676 bytes --]

On Thu, Jul 20, 2023 at 3:31 AM Akihiko Odaki <akihiko.odaki@daynix.com>
wrote:

> Nitpicking: the subject of this patch is somewhat unconventional. What
> about: "tap: Add USO support to tap device"?
>
> Will take it in account in v2


> On 2023/07/20 0:21, Yuri Benditovich wrote:
> > From: Andrew Melnychenko <andrew@daynix.com>
> >
> > Passing additional parameters (USOv4 and USOv6 offloads) when
> > setting TAP offloads
> >
> > Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
> > Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
> > ---
> >   hw/net/e1000e_core.c |  2 +-
> >   hw/net/igb_core.c    |  2 +-
> >   hw/net/virtio-net.c  |  4 +++-
> >   hw/net/vmxnet3.c     |  2 ++
> >   include/net/net.h    |  4 ++--
> >   net/net.c            |  4 ++--
> >   net/tap-bsd.c        |  2 +-
> >   net/tap-linux.c      | 15 ++++++++++++---
> >   net/tap-linux.h      |  2 ++
> >   net/tap-solaris.c    |  2 +-
> >   net/tap-stub.c       |  2 +-
> >   net/tap-win32.c      |  2 +-
> >   net/tap.c            |  6 +++---
> >   net/tap_int.h        |  3 ++-
> >   14 files changed, 34 insertions(+), 18 deletions(-)
> >
> > diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c
> > index f8aeafa16b..d4055956ad 100644
> > --- a/hw/net/e1000e_core.c
> > +++ b/hw/net/e1000e_core.c
> > @@ -2852,7 +2852,7 @@ e1000e_update_rx_offloads(E1000ECore *core)
> >
> >       if (core->has_vnet) {
> >           qemu_set_offload(qemu_get_queue(core->owner_nic)->peer,
> > -                         cso_state, 0, 0, 0, 0);
> > +                         cso_state, 0, 0, 0, 0, 0, 0);
> >       }
> >   }
> >
> > diff --git a/hw/net/igb_core.c b/hw/net/igb_core.c
> > index 8b6b75c522..389eef1549 100644
> > --- a/hw/net/igb_core.c
> > +++ b/hw/net/igb_core.c
> > @@ -2753,7 +2753,7 @@ igb_update_rx_offloads(IGBCore *core)
> >
> >       if (core->has_vnet) {
> >           qemu_set_offload(qemu_get_queue(core->owner_nic)->peer,
> > -                         cso_state, 0, 0, 0, 0);
> > +                         cso_state, 0, 0, 0, 0, 0, 0);
> >       }
> >   }
> >
> > diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> > index 7102ec4817..d2311e7d6e 100644
> > --- a/hw/net/virtio-net.c
> > +++ b/hw/net/virtio-net.c
> > @@ -859,7 +859,9 @@ static void
> virtio_net_apply_guest_offloads(VirtIONet *n)
> >               !!(n->curr_guest_offloads & (1ULL <<
> VIRTIO_NET_F_GUEST_TSO4)),
> >               !!(n->curr_guest_offloads & (1ULL <<
> VIRTIO_NET_F_GUEST_TSO6)),
> >               !!(n->curr_guest_offloads & (1ULL <<
> VIRTIO_NET_F_GUEST_ECN)),
> > -            !!(n->curr_guest_offloads & (1ULL <<
> VIRTIO_NET_F_GUEST_UFO)));
> > +            !!(n->curr_guest_offloads & (1ULL <<
> VIRTIO_NET_F_GUEST_UFO)),
> > +            !!(n->curr_guest_offloads & (1ULL <<
> VIRTIO_NET_F_GUEST_USO4)),
> > +            !!(n->curr_guest_offloads & (1ULL <<
> VIRTIO_NET_F_GUEST_USO6)));
> >   }
> >
> >   static uint64_t virtio_net_guest_offloads_by_features(uint32_t
> features)
> > diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c
> > index 5dfacb1098..886adae42b 100644
> > --- a/hw/net/vmxnet3.c
> > +++ b/hw/net/vmxnet3.c
> > @@ -1341,6 +1341,8 @@ static void vmxnet3_update_features(VMXNET3State
> *s)
> >                            s->lro_supported,
> >                            s->lro_supported,
> >                            0,
> > +                         0,
> > +                         0,
> >                            0);
> >       }
> >   }
> > diff --git a/include/net/net.h b/include/net/net.h
> > index 1448d00afb..b5ccfbbffb 100644
> > --- a/include/net/net.h
> > +++ b/include/net/net.h
> > @@ -58,7 +58,7 @@ typedef bool (HasVnetHdr)(NetClientState *);
> >   typedef bool (HasVnetHdrLen)(NetClientState *, int);
> >   typedef bool (GetUsingVnetHdr)(NetClientState *);
> >   typedef void (UsingVnetHdr)(NetClientState *, bool);
> > -typedef void (SetOffload)(NetClientState *, int, int, int, int, int);
> > +typedef void (SetOffload)(NetClientState *, int, int, int, int, int,
> int, int);
> >   typedef int (GetVnetHdrLen)(NetClientState *);
> >   typedef void (SetVnetHdrLen)(NetClientState *, int);
> >   typedef int (SetVnetLE)(NetClientState *, bool);
> > @@ -192,7 +192,7 @@ bool qemu_has_vnet_hdr_len(NetClientState *nc, int
> len);
> >   bool qemu_get_using_vnet_hdr(NetClientState *nc);
> >   void qemu_using_vnet_hdr(NetClientState *nc, bool enable);
> >   void qemu_set_offload(NetClientState *nc, int csum, int tso4, int tso6,
> > -                      int ecn, int ufo);
> > +                      int ecn, int ufo, int uso4, int uso6);
> >   int qemu_get_vnet_hdr_len(NetClientState *nc);
> >   void qemu_set_vnet_hdr_len(NetClientState *nc, int len);
> >   int qemu_set_vnet_le(NetClientState *nc, bool is_le);
> > diff --git a/net/net.c b/net/net.c
> > index 6492ad530e..543e6dec43 100644
> > --- a/net/net.c
> > +++ b/net/net.c
> > @@ -532,13 +532,13 @@ void qemu_using_vnet_hdr(NetClientState *nc, bool
> enable)
> >   }
> >
> >   void qemu_set_offload(NetClientState *nc, int csum, int tso4, int tso6,
> > -                          int ecn, int ufo)
> > +                          int ecn, int ufo, int uso4, int uso6)
> >   {
> >       if (!nc || !nc->info->set_offload) {
> >           return;
> >       }
> >
> > -    nc->info->set_offload(nc, csum, tso4, tso6, ecn, ufo);
> > +    nc->info->set_offload(nc, csum, tso4, tso6, ecn, ufo, uso4, uso6);
> >   }
> >
> >   int qemu_get_vnet_hdr_len(NetClientState *nc)
> > diff --git a/net/tap-bsd.c b/net/tap-bsd.c
> > index 4c98fdd337..abd16a2ad2 100644
> > --- a/net/tap-bsd.c
> > +++ b/net/tap-bsd.c
> > @@ -232,7 +232,7 @@ int tap_fd_set_vnet_be(int fd, int is_be)
> >   }
> >
> >   void tap_fd_set_offload(int fd, int csum, int tso4,
> > -                        int tso6, int ecn, int ufo)
> > +                        int tso6, int ecn, int ufo, int uso4, int uso6)
> >   {
> >   }
> >
> > diff --git a/net/tap-linux.c b/net/tap-linux.c
> > index f54f308d35..30fcca1bc2 100644
> > --- a/net/tap-linux.c
> > +++ b/net/tap-linux.c
> > @@ -237,7 +237,7 @@ int tap_fd_set_vnet_be(int fd, int is_be)
> >   }
> >
> >   void tap_fd_set_offload(int fd, int csum, int tso4,
> > -                        int tso6, int ecn, int ufo)
> > +                        int tso6, int ecn, int ufo, int uso4, int uso6)
> >   {
> >       unsigned int offload = 0;
> >
> > @@ -256,13 +256,22 @@ void tap_fd_set_offload(int fd, int csum, int tso4,
> >               offload |= TUN_F_TSO_ECN;
> >           if (ufo)
> >               offload |= TUN_F_UFO;
> > +        if (uso4) {
> > +            offload |= TUN_F_USO4;
> > +        }
> > +        if (uso6) {
> > +            offload |= TUN_F_USO6;
> > +        }
> >       }
> >
> >       if (ioctl(fd, TUNSETOFFLOAD, offload) != 0) {
> > -        offload &= ~TUN_F_UFO;
> > +        offload &= ~(TUN_F_USO4 | TUN_F_USO6);
>
> Shouldn't we just report an error when USO is requested on a system that
> does not support it?
>

Existing approach to non-critical features is silently drop them when not
supported by the kernel


>
> >           if (ioctl(fd, TUNSETOFFLOAD, offload) != 0) {
> > -            fprintf(stderr, "TUNSETOFFLOAD ioctl() failed: %s\n",
> > +            offload &= ~TUN_F_UFO;
> > +            if (ioctl(fd, TUNSETOFFLOAD, offload) != 0) {
> > +                fprintf(stderr, "TUNSETOFFLOAD ioctl() failed: %s\n",
> >                       strerror(errno));
> > +            }
> >           }
> >       }
> >   }
> > diff --git a/net/tap-linux.h b/net/tap-linux.h
> > index bbbb62c2a7..9a58cecb7f 100644
> > --- a/net/tap-linux.h
> > +++ b/net/tap-linux.h
> > @@ -50,5 +50,7 @@
> >   #define TUN_F_TSO6    0x04    /* I can handle TSO for IPv6 packets */
> >   #define TUN_F_TSO_ECN 0x08    /* I can handle TSO with ECN bits. */
> >   #define TUN_F_UFO     0x10    /* I can handle UFO packets */
> > +#define TUN_F_USO4    0x20    /* I can handle USO for IPv4 packets */
> > +#define TUN_F_USO6    0x40    /* I can handle USO for IPv6 packets */
> >
> >   #endif /* QEMU_TAP_LINUX_H */
> > diff --git a/net/tap-solaris.c b/net/tap-solaris.c
> > index 38e15028bf..a617a10e5c 100644
> > --- a/net/tap-solaris.c
> > +++ b/net/tap-solaris.c
> > @@ -236,7 +236,7 @@ int tap_fd_set_vnet_be(int fd, int is_be)
> >   }
> >
> >   void tap_fd_set_offload(int fd, int csum, int tso4,
> > -                        int tso6, int ecn, int ufo)
> > +                        int tso6, int ecn, int ufo, int uso4, int uso6)
> >   {
> >   }
> >
> > diff --git a/net/tap-stub.c b/net/tap-stub.c
> > index a0fa25804b..ac8dfc03b4 100644
> > --- a/net/tap-stub.c
> > +++ b/net/tap-stub.c
> > @@ -67,7 +67,7 @@ int tap_fd_set_vnet_be(int fd, int is_be)
> >   }
> >
> >   void tap_fd_set_offload(int fd, int csum, int tso4,
> > -                        int tso6, int ecn, int ufo)
> > +                        int tso6, int ecn, int ufo, int uso4, int uso6)
> >   {
> >   }
> >
> > diff --git a/net/tap-win32.c b/net/tap-win32.c
> > index f327d62ab0..7b8b4be02c 100644
> > --- a/net/tap-win32.c
> > +++ b/net/tap-win32.c
> > @@ -741,7 +741,7 @@ static void tap_using_vnet_hdr(NetClientState *nc,
> bool using_vnet_hdr)
> >   }
> >
> >   static void tap_set_offload(NetClientState *nc, int csum, int tso4,
> > -                     int tso6, int ecn, int ufo)
> > +                     int tso6, int ecn, int ufo, int uso4, int uso6)
> >   {
> >   }
> >
> > diff --git a/net/tap.c b/net/tap.c
> > index 1bf085d422..14ea4ef26f 100644
> > --- a/net/tap.c
> > +++ b/net/tap.c
> > @@ -307,14 +307,14 @@ static int tap_set_vnet_be(NetClientState *nc,
> bool is_be)
> >   }
> >
> >   static void tap_set_offload(NetClientState *nc, int csum, int tso4,
> > -                     int tso6, int ecn, int ufo)
> > +                     int tso6, int ecn, int ufo, int uso4, int uso6)
> >   {
> >       TAPState *s = DO_UPCAST(TAPState, nc, nc);
> >       if (s->fd < 0) {
> >           return;
> >       }
> >
> > -    tap_fd_set_offload(s->fd, csum, tso4, tso6, ecn, ufo);
> > +    tap_fd_set_offload(s->fd, csum, tso4, tso6, ecn, ufo, uso4, uso6);
> >   }
> >
> >   static void tap_exit_notify(Notifier *notifier, void *data)
> > @@ -414,7 +414,7 @@ static TAPState *net_tap_fd_init(NetClientState
> *peer,
> >       s->using_vnet_hdr = false;
> >       s->has_ufo = tap_probe_has_ufo(s->fd);
> >       s->enabled = true;
> > -    tap_set_offload(&s->nc, 0, 0, 0, 0, 0);
> > +    tap_set_offload(&s->nc, 0, 0, 0, 0, 0, 0, 0);
> >       /*
> >        * Make sure host header length is set correctly in tap:
> >        * it might have been modified by another instance of qemu.
> > diff --git a/net/tap_int.h b/net/tap_int.h
> > index 547f8a5a28..d8861d81ba 100644
> > --- a/net/tap_int.h
> > +++ b/net/tap_int.h
> > @@ -37,7 +37,8 @@ void tap_set_sndbuf(int fd, const NetdevTapOptions
> *tap, Error **errp);
> >   int tap_probe_vnet_hdr(int fd, Error **errp);
> >   int tap_probe_vnet_hdr_len(int fd, int len);
> >   int tap_probe_has_ufo(int fd);
> > -void tap_fd_set_offload(int fd, int csum, int tso4, int tso6, int ecn,
> int ufo);
> > +void tap_fd_set_offload(int fd, int csum, int tso4, int tso6, int ecn,
> int ufo,
> > +                        int uso4, int uso6);
> >   void tap_fd_set_vnet_hdr_len(int fd, int len);
> >   int tap_fd_set_vnet_le(int fd, int vnet_is_le);
> >   int tap_fd_set_vnet_be(int fd, int vnet_is_be);
>

[-- Attachment #2: Type: text/html, Size: 14948 bytes --]

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

* Re: [PATCH 3/4] virtio-net: added USO support
  2023-07-20  0:37   ` Akihiko Odaki
@ 2023-07-20 16:05     ` Yuri Benditovich
  2023-07-20 17:17       ` Michael S. Tsirkin
  0 siblings, 1 reply; 11+ messages in thread
From: Yuri Benditovich @ 2023-07-20 16:05 UTC (permalink / raw)
  To: Akihiko Odaki
  Cc: Dmitry Fleytman, Jason Wang, Sriram Yagnaraman, mst, Stefan Weil,
	qemu-devel, yan, andrew

[-- Attachment #1: Type: text/plain, Size: 3165 bytes --]

On Thu, Jul 20, 2023 at 3:37 AM Akihiko Odaki <akihiko.odaki@daynix.com>
wrote:

> On 2023/07/20 0:21, Yuri Benditovich wrote:
> > virtio-net can suggest USO features TX, RX v4 and RX v6,
> > depending on kernel TUN ability to support them. These
> > features require explicit enable in command-line.
>
> Shouldn't we enable these by default as the other offload features are?
>

My suggestion is to add these features as disabled by default and
reevaluate the
possibility to enable later.
If we enable them by default we'll also need to disable them by default in
previous
generations of machine types.


> >
> > Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
> > ---
> >   hw/net/virtio-net.c | 16 ++++++++++++++--
> >   1 file changed, 14 insertions(+), 2 deletions(-)
> >
> > diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> > index d2311e7d6e..e76cad923b 100644
> > --- a/hw/net/virtio-net.c
> > +++ b/hw/net/virtio-net.c
> > @@ -796,6 +796,10 @@ static uint64_t
> virtio_net_get_features(VirtIODevice *vdev, uint64_t features,
> >           virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_TSO6);
> >           virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_ECN);
> >
> > +        virtio_clear_feature(&features, VIRTIO_NET_F_HOST_USO);
> > +        virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_USO4);
> > +        virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_USO6);
> > +
> >           virtio_clear_feature(&features, VIRTIO_NET_F_HASH_REPORT);
> >       }
> >
> > @@ -864,14 +868,16 @@ static void
> virtio_net_apply_guest_offloads(VirtIONet *n)
> >               !!(n->curr_guest_offloads & (1ULL <<
> VIRTIO_NET_F_GUEST_USO6)));
> >   }
> >
> > -static uint64_t virtio_net_guest_offloads_by_features(uint32_t features)
> > +static uint64_t virtio_net_guest_offloads_by_features(uint64_t features)
> >   {
> >       static const uint64_t guest_offloads_mask =
> >           (1ULL << VIRTIO_NET_F_GUEST_CSUM) |
> >           (1ULL << VIRTIO_NET_F_GUEST_TSO4) |
> >           (1ULL << VIRTIO_NET_F_GUEST_TSO6) |
> >           (1ULL << VIRTIO_NET_F_GUEST_ECN)  |
> > -        (1ULL << VIRTIO_NET_F_GUEST_UFO);
> > +        (1ULL << VIRTIO_NET_F_GUEST_UFO)  |
> > +        (1ULL << VIRTIO_NET_F_GUEST_USO4) |
> > +        (1ULL << VIRTIO_NET_F_GUEST_USO6);
> >
> >       return guest_offloads_mask & features;
> >   }
> > @@ -3924,6 +3930,12 @@ static Property virtio_net_properties[] = {
> >       DEFINE_PROP_INT32("speed", VirtIONet, net_conf.speed,
> SPEED_UNKNOWN),
> >       DEFINE_PROP_STRING("duplex", VirtIONet, net_conf.duplex_str),
> >       DEFINE_PROP_BOOL("failover", VirtIONet, failover, false),
> > +    DEFINE_PROP_BIT64("guest_uso4", VirtIONet, host_features,
> > +                      VIRTIO_NET_F_GUEST_USO4, false),
> > +    DEFINE_PROP_BIT64("guest_uso6", VirtIONet, host_features,
> > +                      VIRTIO_NET_F_GUEST_USO6, false),
> > +    DEFINE_PROP_BIT64("host_uso", VirtIONet, host_features,
> > +                      VIRTIO_NET_F_HOST_USO, false),
> >       DEFINE_PROP_END_OF_LIST(),
> >   };
> >
>

[-- Attachment #2: Type: text/html, Size: 4363 bytes --]

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

* Re: [PATCH 3/4] virtio-net: added USO support
  2023-07-20 16:05     ` Yuri Benditovich
@ 2023-07-20 17:17       ` Michael S. Tsirkin
  0 siblings, 0 replies; 11+ messages in thread
From: Michael S. Tsirkin @ 2023-07-20 17:17 UTC (permalink / raw)
  To: Yuri Benditovich
  Cc: Akihiko Odaki, Dmitry Fleytman, Jason Wang, Sriram Yagnaraman,
	Stefan Weil, qemu-devel, yan, andrew

On Thu, Jul 20, 2023 at 07:05:40PM +0300, Yuri Benditovich wrote:
> 
> 
> On Thu, Jul 20, 2023 at 3:37 AM Akihiko Odaki <akihiko.odaki@daynix.com> wrote:
> 
>     On 2023/07/20 0:21, Yuri Benditovich wrote:
>     > virtio-net can suggest USO features TX, RX v4 and RX v6,
>     > depending on kernel TUN ability to support them. These
>     > features require explicit enable in command-line.
> 
>     Shouldn't we enable these by default as the other offload features are?
> 
> 
> My suggestion is to add these features as disabled by default and reevaluate
> the
> possibility to enable later.
> If we enable them by default we'll also need to disable them by default in
> previous
> generations of machine types.

Yea, let's do that, that's how we always did it traditionally.

> 
> 
>     >
>     > Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
>     > ---
>     >   hw/net/virtio-net.c | 16 ++++++++++++++--
>     >   1 file changed, 14 insertions(+), 2 deletions(-)
>     >
>     > diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
>     > index d2311e7d6e..e76cad923b 100644
>     > --- a/hw/net/virtio-net.c
>     > +++ b/hw/net/virtio-net.c
>     > @@ -796,6 +796,10 @@ static uint64_t virtio_net_get_features(VirtIODevice
>     *vdev, uint64_t features,
>     >           virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_TSO6);
>     >           virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_ECN);
>     >   
>     > +        virtio_clear_feature(&features, VIRTIO_NET_F_HOST_USO);
>     > +        virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_USO4);
>     > +        virtio_clear_feature(&features, VIRTIO_NET_F_GUEST_USO6);
>     > +
>     >           virtio_clear_feature(&features, VIRTIO_NET_F_HASH_REPORT);
>     >       }
>     >   
>     > @@ -864,14 +868,16 @@ static void virtio_net_apply_guest_offloads
>     (VirtIONet *n)
>     >               !!(n->curr_guest_offloads & (1ULL <<
>     VIRTIO_NET_F_GUEST_USO6)));
>     >   }
>     >   
>     > -static uint64_t virtio_net_guest_offloads_by_features(uint32_t features)
>     > +static uint64_t virtio_net_guest_offloads_by_features(uint64_t features)
>     >   {
>     >       static const uint64_t guest_offloads_mask =
>     >           (1ULL << VIRTIO_NET_F_GUEST_CSUM) |
>     >           (1ULL << VIRTIO_NET_F_GUEST_TSO4) |
>     >           (1ULL << VIRTIO_NET_F_GUEST_TSO6) |
>     >           (1ULL << VIRTIO_NET_F_GUEST_ECN)  |
>     > -        (1ULL << VIRTIO_NET_F_GUEST_UFO);
>     > +        (1ULL << VIRTIO_NET_F_GUEST_UFO)  |
>     > +        (1ULL << VIRTIO_NET_F_GUEST_USO4) |
>     > +        (1ULL << VIRTIO_NET_F_GUEST_USO6);
>     >   
>     >       return guest_offloads_mask & features;
>     >   }
>     > @@ -3924,6 +3930,12 @@ static Property virtio_net_properties[] = {
>     >       DEFINE_PROP_INT32("speed", VirtIONet, net_conf.speed,
>     SPEED_UNKNOWN),
>     >       DEFINE_PROP_STRING("duplex", VirtIONet, net_conf.duplex_str),
>     >       DEFINE_PROP_BOOL("failover", VirtIONet, failover, false),
>     > +    DEFINE_PROP_BIT64("guest_uso4", VirtIONet, host_features,
>     > +                      VIRTIO_NET_F_GUEST_USO4, false),
>     > +    DEFINE_PROP_BIT64("guest_uso6", VirtIONet, host_features,
>     > +                      VIRTIO_NET_F_GUEST_USO6, false),
>     > +    DEFINE_PROP_BIT64("host_uso", VirtIONet, host_features,
>     > +                      VIRTIO_NET_F_HOST_USO, false),
>     >       DEFINE_PROP_END_OF_LIST(),
>     >   };
>     >   
> 



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

end of thread, other threads:[~2023-07-20 17:18 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-19 15:21 [PATCH 0/4] virtio-net: add USO feature (UDP segmentation offload) Yuri Benditovich
2023-07-19 15:21 ` [PATCH 1/4] tap: Added USO support to tap device Yuri Benditovich
2023-07-20  0:31   ` Akihiko Odaki
2023-07-20 15:53     ` Yuri Benditovich
2023-07-19 15:21 ` [PATCH 2/4] virtio-net: Added USO flags to vhost support Yuri Benditovich
2023-07-19 15:21 ` [PATCH 3/4] virtio-net: added USO support Yuri Benditovich
2023-07-20  0:37   ` Akihiko Odaki
2023-07-20 16:05     ` Yuri Benditovich
2023-07-20 17:17       ` Michael S. Tsirkin
2023-07-19 15:21 ` [PATCH 4/4] virtio-net: Added uso check Yuri Benditovich
2023-07-20  0:41   ` Akihiko Odaki

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).