From patchwork Tue Oct 8 13:52:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eelco Chaudron X-Patchwork-Id: 1994275 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=M39fKFLc; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XNHYP0ysTz1xtV for ; Wed, 9 Oct 2024 00:53:45 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 7615B8111C; Tue, 8 Oct 2024 13:53:43 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id YqR8_7gKRnt2; Tue, 8 Oct 2024 13:53:42 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=2605:bc80:3010:104::8cd3:938; helo=lists.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 40DA681100 Authentication-Results: smtp1.osuosl.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=M39fKFLc Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id 40DA681100; Tue, 8 Oct 2024 13:53:42 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id BBCF5C08AA; Tue, 8 Oct 2024 13:53:41 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 177B6C08A8 for ; Tue, 8 Oct 2024 13:53:41 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id E3A4540552 for ; Tue, 8 Oct 2024 13:53:40 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 5Zq-lH_nVN6K for ; Tue, 8 Oct 2024 13:53:39 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=170.10.133.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=echaudro@redhat.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp4.osuosl.org 0D0374053D Authentication-Results: smtp4.osuosl.org; dmarc=pass (p=none dis=none) header.from=redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 0D0374053D Authentication-Results: smtp4.osuosl.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=M39fKFLc Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by smtp4.osuosl.org (Postfix) with ESMTPS id 0D0374053D for ; Tue, 8 Oct 2024 13:53:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728395618; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oeDjoHCPcrMADeYSMGPI18nl9jgMGhPZYPBf1a/bvjg=; b=M39fKFLcOdRqCVqgn1wHA2w5iCVkK6FnhnLr2yHPpSxLGhSRHyFONoO/pFDjrumyGBXLFJ tPcP9W+mI1ZKP6Ap/SrV+PaUUI/emIsP2vHoAMLd0+VHwUD34eMiVLCkWk9HiXDgDPeihy 8+LA3aDvex70IKn5oIiO7KaLaBnH4PY= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-26-ogQp0b9APyqqyK61oSOHBg-1; Tue, 08 Oct 2024 09:53:36 -0400 X-MC-Unique: ogQp0b9APyqqyK61oSOHBg-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id ECFD81956058 for ; Tue, 8 Oct 2024 13:53:35 +0000 (UTC) Received: from localhost.localdomain (unknown [10.39.194.95]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 450A01956089 for ; Tue, 8 Oct 2024 13:53:35 +0000 (UTC) From: Eelco Chaudron To: dev@openvswitch.org Date: Tue, 8 Oct 2024 15:52:45 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [ovs-dev] [PATCH 2/4] netdev-offload-tc: Match against tunnel flags if supported. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" This patch adds support for TC to match on tunnel flags, if supported by the kernel. If the kernel does not support this, it will fall back to the previous behavior, ignoring the DF and CSUM flags. Signed-off-by: Eelco Chaudron Acked-by: Roi Dayan --- lib/netdev-offload-tc.c | 74 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 68 insertions(+), 6 deletions(-) diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c index fcd206f2c..53c4245b9 100644 --- a/lib/netdev-offload-tc.c +++ b/lib/netdev-offload-tc.c @@ -737,6 +737,36 @@ flower_tun_opt_to_match(struct match *match, struct tc_flower *flower) } } +static void +flower_tun_enc_flags_to_match(struct match *match, struct tc_flower *flower) +{ + uint32_t tc_flags = flower->key.tunnel.tc_enc_flags; + uint32_t tc_mask = flower->mask.tunnel.tc_enc_flags; + uint16_t *m_flags = &match->flow.tunnel.flags; + uint16_t *m_mask = &match->wc.masks.tunnel.flags; + + if (tc_mask & TCA_FLOWER_KEY_FLAGS_TUNNEL_OAM) { + if (tc_flags & TCA_FLOWER_KEY_FLAGS_TUNNEL_OAM) { + *m_flags |= FLOW_TNL_F_OAM; + } + *m_mask |= FLOW_TNL_F_OAM; + } + + if (tc_mask & TCA_FLOWER_KEY_FLAGS_TUNNEL_DONT_FRAGMENT) { + if (tc_flags & TCA_FLOWER_KEY_FLAGS_TUNNEL_DONT_FRAGMENT) { + *m_flags |= FLOW_TNL_F_DONT_FRAGMENT; + } + *m_mask |= FLOW_TNL_F_DONT_FRAGMENT; + } + + if (tc_mask & TCA_FLOWER_KEY_FLAGS_TUNNEL_CSUM) { + if (tc_flags & TCA_FLOWER_KEY_FLAGS_TUNNEL_CSUM) { + *m_flags |= FLOW_TNL_F_CSUM; + } + *m_mask |= FLOW_TNL_F_CSUM; + } +} + static void parse_tc_flower_to_stats(struct tc_flower *flower, struct dpif_flow_stats *stats) @@ -1272,6 +1302,9 @@ parse_tc_flower_to_match(const struct netdev *netdev, flower->key.tunnel.gbp.flags, flower->mask.tunnel.gbp.flags); } + if (flower->mask.tunnel.tc_enc_flags) { + flower_tun_enc_flags_to_match(match, flower); + } if (!strcmp(netdev_get_type(netdev), "geneve")) { flower_tun_opt_to_match(match, flower); @@ -2293,12 +2326,41 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, memset(&tnl_mask->gbp_flags, 0, sizeof tnl_mask->gbp_flags); tnl_mask->flags &= ~FLOW_TNL_F_KEY; - /* XXX: This is wrong! We're ignoring DF and CSUM flags configuration - * requested by the user. However, TC for now has no way to pass - * these flags in a flower key and their masks are set by default, - * meaning tunnel offloading will not work at all if not cleared. - * Keeping incorrect behavior for now. */ - tnl_mask->flags &= ~(FLOW_TNL_F_DONT_FRAGMENT | FLOW_TNL_F_CSUM); + if (enc_flags_support) { + if (tnl_mask->flags & FLOW_TNL_F_OAM) { + if (tnl->flags & FLOW_TNL_F_OAM) { + flower.key.tunnel.tc_enc_flags |= + TCA_FLOWER_KEY_FLAGS_TUNNEL_OAM; + } + flower.mask.tunnel.tc_enc_flags |= + TCA_FLOWER_KEY_FLAGS_TUNNEL_OAM; + tnl_mask->flags &= ~FLOW_TNL_F_OAM; + } + if (tnl_mask->flags & FLOW_TNL_F_DONT_FRAGMENT) { + if (tnl->flags & FLOW_TNL_F_DONT_FRAGMENT) { + flower.key.tunnel.tc_enc_flags |= + TCA_FLOWER_KEY_FLAGS_TUNNEL_DONT_FRAGMENT; + } + flower.mask.tunnel.tc_enc_flags |= + TCA_FLOWER_KEY_FLAGS_TUNNEL_DONT_FRAGMENT; + tnl_mask->flags &= ~FLOW_TNL_F_DONT_FRAGMENT; + } + if (tnl_mask->flags & FLOW_TNL_F_CSUM) { + if (tnl->flags & FLOW_TNL_F_CSUM) { + flower.key.tunnel.tc_enc_flags |= + TCA_FLOWER_KEY_FLAGS_TUNNEL_CSUM; + } + flower.mask.tunnel.tc_enc_flags |= + TCA_FLOWER_KEY_FLAGS_TUNNEL_CSUM; + tnl_mask->flags &= ~FLOW_TNL_F_CSUM; + } + } else { + /* For kernels not supporting the encapsulation flags we're + * ignoring DF and CSUM flags configuration requested by the user. + * This to keep the old, incorrect behaviour, and allow tunnels to + * be offloaded by TC with these kernels. */ + tnl_mask->flags &= ~(FLOW_TNL_F_DONT_FRAGMENT | FLOW_TNL_F_CSUM); + } if (!strcmp(netdev_get_type(netdev), "geneve")) { err = flower_match_to_tun_opt(&flower, tnl, tnl_mask);