diff mbox series

[ovs-dev] netdev-linux: Enable TSO in the TAP device.

Message ID 20200229232935.71355-1-fbl@sysclose.org
State Accepted
Commit 6211ad57089e16fe0c84cf5ba0f6a03b4df3ceb8
Headers show
Series [ovs-dev] netdev-linux: Enable TSO in the TAP device. | expand

Commit Message

Flavio Leitner Feb. 29, 2020, 11:29 p.m. UTC
Use ioctl TUNSETOFFLOAD if kernel supports to enable TSO
offloading in the tap device.

Fixes: 29cf9c1b3b9c ("userspace: Add TCP Segmentation Offload support")
Reported-by: "Yi Yang (杨�D)-云服务集团" <yangyi01@inspur.com>
Tested-by: William Tu <u9012063@gmail.com>
Signed-off-by: Flavio Leitner <fbl@sysclose.org>
---
 lib/netdev-linux.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

It would be great to have this patch applied to branch-2.13 as well.

Comments

William Tu March 2, 2020, 5:59 p.m. UTC | #1
On Sat, Feb 29, 2020 at 08:29:35PM -0300, Flavio Leitner wrote:
> Use ioctl TUNSETOFFLOAD if kernel supports to enable TSO
> offloading in the tap device.
> 
> Fixes: 29cf9c1b3b9c ("userspace: Add TCP Segmentation Offload support")
> Reported-by: "Yi Yang (杨�D)-云服务集团" <yangyi01@inspur.com>
> Tested-by: William Tu <u9012063@gmail.com>
> Signed-off-by: Flavio Leitner <fbl@sysclose.org>
> ---

Thanks, I applied to master.

Currently there is no consistent way to test TSO.
So I tested your patch using
$ make check-system-tso

in this patch under review:
https://patchwork.ozlabs.org/patch/1241630/
https://patchwork.ozlabs.org/patch/1241631/

Regards,
William
diff mbox series

Patch

diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c
index 432645601..c6e46f188 100644
--- a/lib/netdev-linux.c
+++ b/lib/netdev-linux.c
@@ -1012,6 +1012,23 @@  netdev_linux_construct_tap(struct netdev *netdev_)
         goto error_close;
     }
 
+    if (userspace_tso_enabled()) {
+        /* Old kernels don't support TUNSETOFFLOAD. If TUNSETOFFLOAD is
+         * available, it will return EINVAL when a flag is unknown.
+         * Therefore, try enabling offload with no flags to check
+         * if TUNSETOFFLOAD support is available or not. */
+        if (ioctl(netdev->tap_fd, TUNSETOFFLOAD, 0) == 0 || errno != EINVAL) {
+            unsigned long oflags = TUN_F_CSUM | TUN_F_TSO4 | TUN_F_TSO6;
+
+            if (ioctl(netdev->tap_fd, TUNSETOFFLOAD, oflags) == -1) {
+                VLOG_WARN("%s: enabling tap offloading failed: %s", name,
+                          ovs_strerror(errno));
+                error = errno;
+                goto error_close;
+            }
+        }
+    }
+
     netdev->present = true;
     return 0;