From patchwork Fri Sep 19 09:16:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yael Chemla X-Patchwork-Id: 2139392 X-Patchwork-Delegate: aconole@redhat.com 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" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=fYzUC53Z; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=patchwork.ozlabs.org) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (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 4cSn28326Zz1yFx for ; Fri, 19 Sep 2025 19:16:46 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 8973460FD6; Fri, 19 Sep 2025 09:16:44 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 31kGkYHrw4gN; Fri, 19 Sep 2025 09:16:43 +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 smtp3.osuosl.org 1C39E60F4A Authentication-Results: smtp3.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=fYzUC53Z Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTPS id 1C39E60F4A; Fri, 19 Sep 2025 09:16:43 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id E0240C04FB; Fri, 19 Sep 2025 09:16:42 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 79F14C04FA for ; Fri, 19 Sep 2025 09:16:41 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 663E960A4B for ; Fri, 19 Sep 2025 09:16:41 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id U7rhhTTi4__f for ; Fri, 19 Sep 2025 09:16:40 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=2a01:111:f403:c007::2; helo=mw6pr02cu001.outbound.protection.outlook.com; envelope-from=ychemla@nvidia.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp3.osuosl.org 5A699608E3 Authentication-Results: smtp3.osuosl.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 5A699608E3 Received: from MW6PR02CU001.outbound.protection.outlook.com (mail-westus2azlp170120002.outbound.protection.outlook.com [IPv6:2a01:111:f403:c007::2]) by smtp3.osuosl.org (Postfix) with ESMTPS id 5A699608E3 for ; Fri, 19 Sep 2025 09:16:40 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ZTniDX0B5/fw2bqYai/iIK3uQwe/fMNtfh51jwwbuvYtJth66JaMQTJqTrGVGnJcNAuyMJTcZFveSgmR7c1tEq8EW1qnHyOu2hZSGKUtj16GSxf3he0c1kCsruxENAkFGnrlzuklgqdotH/CMD0zct+pLDEdwV/P1jekOdnpeCJtzlhHtDntq8QqAf0jWqx+ajnJQfPPqA/I0KT5Vnvlv+8xsK20tHqpwizMUauVXvB6wbZOzHOkqaGxjtQPlugI2dY4oqC4qKZDbAa/eR7OuUKiQ3W3ffFg0L3l2qV+OgxtweEuINiu7Pb5L6FCqAQ0oZU4C/bumDAIwuhV8u7dSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mQY7xPGLD8EhpHU262TPb+pjUe+W2kLlsnWz69Yuni0=; b=lV2K569HYM71inIQhHznVWBJbECFf2QeE9bukggW2VuPFlEgjDBh0fcFETZTQCnvBBBDAyUX/HSiUvl1GDfKb0ohUVtJ8uxcevsp0gTyz0DSNg2NQgIhwJoueB0YuSmTEyhsqhiHAUi8gaYQVSTnG/1gQTYkx9mhWOgmBNx6kA0MoChxqyt396lhIkmTiP6wJzfX/nznck/tfssh3rt3nthikPhMZBXhY7+iwkyrQB229mkmnNvFo/NS9GT+LqaMDLYln9uiRONCS6rJqGmaJ2kAmD867bWwACNi/Pgy2A6kkOock88TogyM1FkEWmZvZQRieHlGueM6j2wl5hswhw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.118.233) smtp.rcpttodomain=ovn.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mQY7xPGLD8EhpHU262TPb+pjUe+W2kLlsnWz69Yuni0=; b=fYzUC53Z6D8WPgiTVALwpiOYksc1oZr7Ewz2uaEBCBVAH6jGnFIZxRDfoGN6GOc2wC8/0gid/woXRhgWqG8bwfhbBcU3DDp8WX3ID/CU13UEwPr1SzFxhOw23EMFeeA2eWorZ3N0zQo+1/eGsQbtSCpjuEi3ufp8UBkbH8x0GSm/AVWnfwWeXZhugbEjSACI0kerLUQ3zRzJ6NWcQHLtnhagjbTuUzp+O1voGf0PRX3Wo2lEmt6qiRwMkSwGjW3hccuq+YRZqW1h1OiOUfbWYWgqgmahWL+Tio3SZp14HN3WjJa7owRNqv7iHigkVJvU6fZL3569PrMuI5hWYKXH/Q== Received: from BYAPR04CA0036.namprd04.prod.outlook.com (2603:10b6:a03:40::49) by PH8PR12MB7109.namprd12.prod.outlook.com (2603:10b6:510:22f::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9115.23; Fri, 19 Sep 2025 09:16:32 +0000 Received: from SJ5PEPF000001EA.namprd05.prod.outlook.com (2603:10b6:a03:40:cafe::aa) by BYAPR04CA0036.outlook.office365.com (2603:10b6:a03:40::49) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9137.15 via Frontend Transport; Fri, 19 Sep 2025 09:16:32 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.118.233) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.118.233 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.118.233; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.118.233) by SJ5PEPF000001EA.mail.protection.outlook.com (10.167.242.198) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9137.12 via Frontend Transport; Fri, 19 Sep 2025 09:16:32 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by mail.nvidia.com (10.127.129.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.14; Fri, 19 Sep 2025 02:16:22 -0700 Received: from drhqmail201.nvidia.com (10.126.190.180) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.20; Fri, 19 Sep 2025 02:16:21 -0700 Received: from vdi.nvidia.com (10.127.8.10) by mail.nvidia.com (10.126.190.180) with Microsoft SMTP Server id 15.2.2562.20 via Frontend Transport; Fri, 19 Sep 2025 02:16:19 -0700 To: Ilya Maximets , Simon Horman , "Eelco Chaudron" , Roi Dayan , "ovs-dev @ openvswitch . org" CC: Jianbo Liu , Gal Pressman , "Yael Chemla" Date: Fri, 19 Sep 2025 12:16:45 +0300 Message-ID: <20250919091645.1791490-1-ychemla@nvidia.com> X-Mailer: git-send-email 2.45.0 MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ5PEPF000001EA:EE_|PH8PR12MB7109:EE_ X-MS-Office365-Filtering-Correlation-Id: 05b34076-b351-4b94-da2b-08ddf75d394a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|82310400026|36860700013|376014; X-Microsoft-Antispam-Message-Info: =?utf-8?q?JVcrgLoRpOBXmfyiKbYCNxr7ZL7CKdr?= =?utf-8?q?3JNcnMa4YZtVffwz1hOtNFWg/JNkZFr/oP2Qnf0Qq+pR7hPTimSw/C/YelNKhWZXV?= =?utf-8?q?nbDrOwZwhy+ABi5UrSBQe/2JAZkg0UKfFuNlY7vQrvMJvFfnPjRDZtJIy3QI81Ldx?= =?utf-8?q?iUB3mPwnCPWQoio+V5NxD3zeZlcNz/2+PbKfGukE0lXYpebOzvUrJqpieEsil3iTa?= =?utf-8?q?+t2FGXaSpQRHz/tbzpadrEiG60PZmEL8brb3SZYZzxLlBfBAjXBY4gQj+FmvO21JR?= =?utf-8?q?EyvDzw5kAH+bJLrQDFXlct/qbwfEGnQL0Wx/wADSJpA6LRYZetSPpOmWgvmXtfjww?= =?utf-8?q?j9oKUfiq7UMdZXPeYUHdAopHXiOq2ReNy2NQeKKMRbiNLYQoxb0bgSPEDyTo7XSgW?= =?utf-8?q?bh+YIqGmjSzWchD1eQDtk3HvcHum1lEHimAreRKfbCnDYlsgqaXQgxiWLc2aHAxgm?= =?utf-8?q?/3eA/DLpl5TlA8qib+/Zcp3I/eUDU9TJc/lNSAWCIeSTy/4HHZD+KYx9/P7rRAgFa?= =?utf-8?q?A10hs2K2Ouoh/6320Cmq5SsN+izovINinptouL0qHEuL6golGHWTAX/9WzDklMMcf?= =?utf-8?q?oBUqwfF1AUUlvhovUAekCfG7CeDGyiMKeJKs3EjEc1PKuIpHz9nV6MjqwBXqSQZcV?= =?utf-8?q?mwBymeHBFvGEKNfmjAkRDmTHhkXUhF9vB8yUCkDcur9xvyFWjXObHUcH3yuZrlRfj?= =?utf-8?q?6rHL0VEVXYjzs2sIj6Eg6U3tUvBuLU0RW2N8aspsAqLuX7IATVw4+vgBwUGJplKDV?= =?utf-8?q?uuzXSEwv0TvAtKKABO4ssVdrQ2nEKukcCcvUW9DXC9l9CGRpHAY6L1l4/RBM1kb2v?= =?utf-8?q?PkLGA6JrdFqMFv3Z9MNQsJ/h8hZLoxEyNBUetXkbVFUqs/+tiq41gXa6MSVtpFGyP?= =?utf-8?q?GTajRVVWxqVwdBHpPqUj1f5+ufQ5fA+rsIP0EN1w0+q7H/ZmueFUvwKTHla/+jHfo?= =?utf-8?q?M30QsHUvQOa9qEXRUnVj9kP6OTq7bnPWUW9C87UjXQ+ugyKAUYbPqQwjQat3LOkQq?= =?utf-8?q?XHOPAnelcWztmQG5Xk/NEjhccQENHr1gxptyi1td+DFE1A9zPgvqNic3WrCumNn/d?= =?utf-8?q?oj/lV+jT1bZTqLWzNk8UGN/fJyfFmrotCiHDmV6NOE4pkI/+OGuXx//BaDHMFoaDy?= =?utf-8?q?1js//2BLKJyIu3qQ6Ov7n2TW4gt/pP5Mu60AV7NGbVFH3GqETFgr1yh1rYch0ViU1?= =?utf-8?q?5YJMFk8/m/n7OiEcibIbkvkjHU+Hrfp+W6qgAf/dWyhqtPF+wOmDAflYWVacoksf8?= =?utf-8?q?GjYkmil//QPFu0sSxik3RJpxHHXmwXKTFWgzu9s5dZJKofW7qDFFXJePtzboyXM+1?= =?utf-8?q?TO9Or3j2bMNHfS3/ra3lzF6tSDAdnpg1Ix3RKI7BIRZ5efMXu0WgBz5XhL7Hp5NW+?= =?utf-8?q?V7NxGFBRT3eiOqjplcxaDTq9/WoDm3WpNmFYs1s5X6o9zlzyChq97/f2pU9HPGkVH?= =?utf-8?q?hojn1AR03I?= X-Forefront-Antispam-Report: CIP:216.228.118.233; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc7edge2.nvidia.com; CAT:NONE; SFS:(13230040)(1800799024)(82310400026)(36860700013)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2025 09:16:32.1448 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 05b34076-b351-4b94-da2b-08ddf75d394a X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.118.233]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SJ5PEPF000001EA.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7109 Subject: [ovs-dev] [PATCH] netdev-offload-tc: Respect hw-offload when probing encap flags. 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: , X-Patchwork-Original-From: Yael Chemla via dev From: Yael Chemla Reply-To: Yael Chemla Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Currently, the kernel capability probe for TCA_FLOWER_KEY_ENC_FLAGS does not take into account whether hardware offload is enabled. This can lead to incorrect detection of encapsulation flag support and failed offload attempts on devices lacking proper hardware support. This patch uses a two-step probe to validate hardware support for ENC_FLAGS: (1) A global skip_hw probe checks whether the kernel recognizes TCA_FLOWER_KEY_ENC_FLAGS. (2) Per device, if it’s a tunnel and hw offload is enabled, we install a temporary flower rule and read it back with tc_get_flower to confirm offloaded_state == IN_HW. This checks whether ENC_FLAGS can actually be offloaded to hardware. Results are cached per device in the new netdev_tc_data structure, and we skip probing for system/non-tunnel devices. This avoids false positives where the global skip_hw probe succeeds but the device supports the key only in software, and prevents unnecessary probes and offload attempts on unsupported devices. Fixes: 3f7af5233a29 ("netdev-offload-tc: Check if TCA_FLOWER_KEY_ENC_FLAGS is supported.") Signed-off-by: Yael Chemla --- lib/netdev-offload-tc.c | 123 +++++++++++++++++++++++++++++++++++++--- lib/tc.c | 2 +- lib/tc.h | 2 + 3 files changed, 118 insertions(+), 9 deletions(-) diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c index 804885285..6103b47eb 100644 --- a/lib/netdev-offload-tc.c +++ b/lib/netdev-offload-tc.c @@ -79,6 +79,12 @@ struct policer_node { uint32_t police_idx; }; +/* Per-netdev TC offload data */ +struct netdev_tc_data { + bool enc_flags_support; /* Per-netdev enc flags support */ + struct ovsthread_once once; /* avoid concurrency per-netdev TC data */ +}; + /* ccmap and protective mutex for counting recirculation id (chain) usage. */ static struct ovs_mutex used_chains_mutex = OVS_MUTEX_INITIALIZER; static struct ccmap used_chains OVS_GUARDED; @@ -88,6 +94,7 @@ static struct ovs_mutex meter_police_ids_mutex = OVS_MUTEX_INITIALIZER; static struct id_pool *meter_police_ids OVS_GUARDED_BY(meter_police_ids_mutex); /* Protects below meter hashmaps. */ static struct ovs_mutex meter_mutex = OVS_MUTEX_INITIALIZER; +static struct ovs_mutex tc_data_alloc_mutex = OVS_MUTEX_INITIALIZER; static struct hmap meter_id_to_police_idx OVS_GUARDED_BY(meter_mutex) = HMAP_INITIALIZER(&meter_id_to_police_idx); static struct hmap police_idx_to_meter_id OVS_GUARDED_BY(meter_mutex) @@ -109,6 +116,9 @@ static void parse_tc_flower_to_stats(struct tc_flower *flower, static int get_ufid_adjust_stats(const ovs_u128 *ufid, struct dpif_flow_stats *stats); +static void netdev_tc_cleanup_data(struct netdev *netdev); +static bool netdev_tc_get_enc_flags_support(struct netdev *netdev); +static struct netdev_tc_data * get_netdev_tc_data(struct netdev *netdev); static bool is_internal_port(const char *type) @@ -581,6 +591,8 @@ netdev_tc_flow_flush(struct netdev *netdev) } ovs_mutex_unlock(&ufid_lock); + netdev_tc_cleanup_data(netdev); + return 0; } @@ -2398,7 +2410,7 @@ 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; - if (enc_flags_support) { + if (netdev_tc_get_enc_flags_support(netdev)) { if (tnl_mask->flags & FLOW_TNL_F_OAM) { if (tnl->flags & FLOW_TNL_F_OAM) { flower.key.tunnel.tc_enc_flags |= @@ -3026,22 +3038,73 @@ out: tc_add_del_qdisc(ifindex, false, block_id, TC_INGRESS); } +/* Helper functions for per-netdev TC data */ +static struct netdev_tc_data * get_netdev_tc_data(struct netdev *netdev) +{ + struct netdev_tc_data *tc_data; + + /* avoid races on allocation/ovsrcu_set */ + ovs_mutex_lock(&tc_data_alloc_mutex); + tc_data = (struct netdev_tc_data *) ovsrcu_get_protected(void *, + &netdev->hw_info.offload_data); + if (!tc_data) { + tc_data = xzalloc(sizeof *tc_data); + tc_data->enc_flags_support = false; + tc_data->once.done = false; + ovs_mutex_init(&tc_data->once.mutex); + ovsrcu_set(&netdev->hw_info.offload_data, tc_data); + } + ovs_mutex_unlock(&tc_data_alloc_mutex); + return tc_data; +} + +/* Returns the enc flags support for the given netdev, return global flag if + * not probed yet (non tunnel devices) */ +static bool netdev_tc_get_enc_flags_support(struct netdev *netdev) +{ + struct netdev_tc_data *tc_data = (struct netdev_tc_data *) + ovsrcu_get(void *, &netdev->hw_info.offload_data); + return tc_data ? tc_data->enc_flags_support : enc_flags_support; +} + +/* Cleanup the per-netdev TC data */ +static void netdev_tc_cleanup_data(struct netdev *netdev) +{ + struct netdev_tc_data *tc_data; + + tc_data = (struct netdev_tc_data *) + ovsrcu_get(void *, &netdev->hw_info.offload_data); + + if (tc_data) { + ovsrcu_set(&netdev->hw_info.offload_data, NULL); + ovsrcu_postpone(free, tc_data); + } +} + static void -probe_enc_flags_support(int ifindex) +probe_enc_flags_support(struct netdev *netdev, struct netdev_tc_data *tc_data, + enum tc_offload_policy policy) { + const char *netdev_type = netdev_get_type(netdev); + const char *netdev_name = netdev_get_name(netdev); struct tc_flower flower; struct tcf_id id; int block_id = 0; int prio = TC_RESERVED_PRIORITY_FEATURE_PROBE; + int ifindex; int error; + + /* assume ifindex is already checked in calling function */ + ifindex = netdev_get_ifindex(netdev); error = tc_add_del_qdisc(ifindex, true, block_id, TC_INGRESS); if (error) { return; } memset(&flower, 0, sizeof flower); - flower.tc_policy = TC_POLICY_SKIP_HW; + + flower.tc_policy = policy; flower.key.eth_type = htons(ETH_P_IP); flower.mask.eth_type = OVS_BE16_MAX; flower.tunnel = true; @@ -3049,22 +3112,54 @@ probe_enc_flags_support(int ifindex) flower.mask.tunnel.ipv4.ipv4_src = OVS_BE32_MAX; flower.mask.tunnel.ipv4.ipv4_dst = OVS_BE32_MAX; flower.mask.tunnel.tp_dst = OVS_BE16_MAX; - flower.mask.tunnel.tc_enc_flags = TCA_FLOWER_KEY_FLAGS_TUNNEL_CRIT_OPT; + + /* respect the policy */ + if (policy == TC_POLICY_NONE) { + flower.mask.tunnel.tc_enc_flags = TCA_FLOWER_KEY_FLAGS_TUNNEL_DONT_FRAGMENT | + TCA_FLOWER_KEY_FLAGS_TUNNEL_CSUM; + flower.key.tunnel.tc_enc_flags = TCA_FLOWER_KEY_FLAGS_TUNNEL_DONT_FRAGMENT | + TCA_FLOWER_KEY_FLAGS_TUNNEL_CSUM; + } else { + flower.mask.tunnel.tc_enc_flags = TCA_FLOWER_KEY_FLAGS_TUNNEL_CRIT_OPT; + flower.key.tunnel.tc_enc_flags = TCA_FLOWER_KEY_FLAGS_TUNNEL_CRIT_OPT; + } + flower.key.tunnel.ipv4.ipv4_src = htonl(0x01010101); flower.key.tunnel.ipv4.ipv4_dst = htonl(0x01010102); flower.key.tunnel.tp_dst = htons(46354); - flower.key.tunnel.tc_enc_flags = TCA_FLOWER_KEY_FLAGS_TUNNEL_CRIT_OPT; id = tc_make_tcf_id(ifindex, block_id, prio, TC_INGRESS); + flower.probing = true; error = tc_replace_flower(&id, &flower); if (error) { + VLOG_INFO("probe tc: enc flags are not supported for %s device %s.", + netdev_type, netdev_name); goto out; } + /* Query the newly-added rule, check its offload state before deletion + * when policy is TC_POLICY_NONE it's the case of tunnel device */ + if (policy == TC_POLICY_NONE) { + struct tc_flower flower_state; + + memset(&flower_state, 0, sizeof flower_state); + if (!tc_get_flower(&id, &flower_state)) { + tc_data->enc_flags_support = + (flower_state.offloaded_state == TC_OFFLOADED_STATE_IN_HW); + } + } else { + tc_data->enc_flags_support = true; + } + tc_del_flower_filter(&id); - enc_flags_support = true; - VLOG_INFO("probe tc: enc flags are supported."); + if (tc_data->enc_flags_support) { + VLOG_INFO("probe tc: enc flags with tc_policy(%d) are offloaded for %s device %s.", + policy, netdev_type, netdev_name); + } else { + VLOG_INFO("probe tc: enc flags with tc_policy(%d) are not offloaded for %s device %s.", + policy, netdev_type, netdev_name); + } out: tc_add_del_qdisc(ifindex, false, block_id, TC_INGRESS); } @@ -3152,7 +3247,9 @@ netdev_tc_init_flow_api(struct netdev *netdev) { static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; enum tc_qdisc_hook hook = get_tc_qdisc_hook(netdev); + struct netdev_tc_data dummy_tcdata = {0}; static bool get_chain_supported = true; + struct netdev_tc_data *tc_data; uint32_t block_id = 0; struct tcf_id id; int ifindex; @@ -3199,7 +3296,8 @@ netdev_tc_init_flow_api(struct netdev *netdev) probe_multi_mask_per_prio(ifindex); probe_ct_state_support(ifindex); probe_vxlan_gbp_support(ifindex); - probe_enc_flags_support(ifindex); + probe_enc_flags_support(netdev, &dummy_tcdata, TC_POLICY_SKIP_HW); + enc_flags_support = dummy_tcdata.enc_flags_support; ovs_mutex_lock(&meter_police_ids_mutex); meter_police_ids = id_pool_create(METER_POLICE_IDS_BASE, @@ -3211,6 +3309,15 @@ netdev_tc_init_flow_api(struct netdev *netdev) ovsthread_once_done(&once); } + /* probe if tunnel device and hw offload is enabled */ + if (netdev_get_tunnel_config(netdev) && netdev_is_flow_api_enabled()) { + tc_data = get_netdev_tc_data(netdev); + if (ovsthread_once_start(&tc_data->once)) { + probe_enc_flags_support(netdev, tc_data, TC_POLICY_NONE); + ovsthread_once_done(&tc_data->once); + } + } + error = tc_add_del_qdisc(ifindex, true, block_id, hook); if (error && error != EEXIST) { diff --git a/lib/tc.c b/lib/tc.c index a5f9bc1c1..6367333a2 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -3834,7 +3834,7 @@ nl_msg_put_flower_options(struct ofpbuf *request, struct tc_flower *flower) } } - if (policy == TC_POLICY_NONE) { + if (!flower->probing && policy == TC_POLICY_NONE) { policy = tc_policy; } diff --git a/lib/tc.h b/lib/tc.h index 883e21f4c..e30f2f582 100644 --- a/lib/tc.h +++ b/lib/tc.h @@ -403,6 +403,8 @@ struct tc_flower { enum tc_offloaded_state offloaded_state; /* Used to force skip_hw when probing tc features. */ enum tc_offload_policy tc_policy; + /* Used to indicate that the flower is being probed. */ + bool probing; }; int tc_replace_flower(struct tcf_id *id, struct tc_flower *flower);