From patchwork Sat Jul 2 03:18:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianbo Liu X-Patchwork-Id: 1651419 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=S+yaN3ne; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4LZcjX6Z8vz9sGG for ; Sat, 2 Jul 2022 13:18:56 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id E879D415D7; Sat, 2 Jul 2022 03:18:51 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org E879D415D7 Authentication-Results: smtp2.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=S+yaN3ne X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id h9VWfYabBbre; Sat, 2 Jul 2022 03:18:50 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id BB7AC4026F; Sat, 2 Jul 2022 03:18:49 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org BB7AC4026F Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id A28FFC007B; Sat, 2 Jul 2022 03:18:47 +0000 (UTC) X-Original-To: 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 B68FEC002D for ; Sat, 2 Jul 2022 03:18:45 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 82BBB60B5B for ; Sat, 2 Jul 2022 03:18:45 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 82BBB60B5B Authentication-Results: smtp3.osuosl.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=S+yaN3ne X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id spyGGpaw9k3F for ; Sat, 2 Jul 2022 03:18:44 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 88ED660A97 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2046.outbound.protection.outlook.com [40.107.220.46]) by smtp3.osuosl.org (Postfix) with ESMTPS id 88ED660A97 for ; Sat, 2 Jul 2022 03:18:44 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bAEem/iWzZOkd02nCS1DJ81B1sJ76tVu+560ybAGgFj2brouIXCfH0yIYnAb01pTEPku2kcsSIVB7tZgwFi4Lmx8p4YstoRSPHYyZMoqWZNVn+GTKA2CV5DQp1ky33YlJejasZhJKoVXY46cPGCx+s0+mZuJcM0KXYZkqZVbGDvoJGcDIpsP7NW0QifjFKWlnK3c+Qrs4oGyn/V4SLBklmDz55W2FaynItJ4u/EPEpXSsYf5iBAD5sJM0JPpt4xnRwTMvIsmLvytCR+KvhTexoP790JAlRrMAMmfnp1bZn59s462LX8VKra0gTHqn/k25ggC0t5LtgjCewa9RFHupA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=qXNfaqE5sehmbXZegggHCcWnql/tbR4ZbGgBNmVGarE=; b=lAN6tZ1nJXOh3peHfbdwByjVHOYt3dFS8ik9PkwHbo5/oDSnSaXXZxebMnSzURLPS5NMNfQgygUUUkht91pBv1gpApLX0l/1WSEYfZ/4Ryc0KQLoQqPTcfGtdvJes/aeXvIrI3XpIAWh9qLYw1eZpkzH8wV40rOFXv54WKAkymlMId0F9QQ2Q8cybAiTwaQgsVtUVordKg17F3AHyQWXNd31GQGSDuN2OgJsLS6NSB3QEfoRfedJFtkuvc7GXWwo4h0O3nSN5zpPmozYduGvH7MeJVaFydbL2BlWTsqa0N0hENCSYuKDqGaes+h45cqYNuxJB9WMslqqJF7VDPpMuw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) smtp.rcpttodomain=corigine.com 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 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=qXNfaqE5sehmbXZegggHCcWnql/tbR4ZbGgBNmVGarE=; b=S+yaN3nei3YLWzKCjNfi1gerOQkgWIkGq7BEL3QujXV6be9pj6djyfT9H42JJGPzwCCF9XdTIk38gW0PEuvQHfO+P767+0EB50CQKwLQmwzhAhJrjMoVctI06CMXlTIAB5Azv6voLrDR18NgNMGyg0aKOLHRthWabSgzkDGQM5Tf0lYv4m7kVgBkuEWXITnw5DHlKga89M1sH2TyyB6QAoeNX5FyD2xWcQfDPFcNlar8QESgbS/upyQl0N7nB1bPrserjbFijyRyjAjTOP5IPr9rYwvM+/+e4YsILDGucUI6Ju08mDbNHJIEfoEmk3LT7xZN0mfoZLNS+B3FKYV3NA== Received: from DM6PR02CA0118.namprd02.prod.outlook.com (2603:10b6:5:1b4::20) by BN7PR12MB2657.namprd12.prod.outlook.com (2603:10b6:408:32::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.15; Sat, 2 Jul 2022 03:18:41 +0000 Received: from DM6NAM11FT035.eop-nam11.prod.protection.outlook.com (2603:10b6:5:1b4:cafe::6) by DM6PR02CA0118.outlook.office365.com (2603:10b6:5:1b4::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.18 via Frontend Transport; Sat, 2 Jul 2022 03:18:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) 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 12.22.5.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.236) by DM6NAM11FT035.mail.protection.outlook.com (10.13.172.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5395.14 via Frontend Transport; Sat, 2 Jul 2022 03:18:41 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Sat, 2 Jul 2022 03:18:40 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Fri, 1 Jul 2022 20:18:39 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Fri, 1 Jul 2022 20:18:37 -0700 To: , , , , , Date: Sat, 2 Jul 2022 03:18:24 +0000 Message-ID: <20220702031832.13282-2-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220702031832.13282-1-jianbol@nvidia.com> References: <20220702031832.13282-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2e307366-3e7c-4d08-4f35-08da5bd9904c X-MS-TrafficTypeDiagnostic: BN7PR12MB2657:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VGgEo6DGPSbIPcUa/Ikeew53LWk5AZRmxzxYQiTeQ9vwiesYJBIbw+65iSet7PfmNHUV52D4oourzdF/eGMAppj9MWJ663oaW8chCVVDqnZR/hWmeHFWpbwPyW7wEeLDY+uvg4GPCVQK6pdgzFFtvpNGLFVDd45lxyYrIv4QFX/4b7+O4f7iyh33vHWlvrIcy4fXdsjX0CB22emXYxTxXyHmAVNC21B8koPCyWb9fvOo1ebLeEx+UVwKnLE/jUrHQnNZ5tx3k3wGoD67dLmiBjbUV6UHy7e3032M56RcJy92uZaGk9uO0MATd4QoZPChlZJucgJZlk2saoC1JX+oyFNswzpyNHYKaBAbUWYHt/4akzVbM7z9roJqe/lDTYRl7XGn2SxqdfKGLR9eSkpxS05BqabjyvZo11s1qZfaVAtYvi/0wjeNNhtnM3R8CdvyHGXQ0D6UTbVBGyoPHankHIHB6dPYiD44bnCouUOnLX3mjT/SYXMQMD/LEeh3N5TI/LSh/8/5HqopnzWwkAPlfBMe7jbc1a/4zYE5LTbIjibZEe30qCual7iZPQXKSdhcpi2e8BOUPCWNvvxcpHZlwE6ExLnkAJFV6VopGygIIKByC2Uk+HF4YRh0twvpkZg2EvNVpiTzW+9VfScN+q4unz+rCOc9/ZHYPymCROHo1VVtvZ7fT8NjrTYx3/sWEjXPAK946J14Ykk+hqfOMnR3G2cGJdzPeWjRXNmVM0ZiOZlWlnEVk9DTYc1FOXWK+qlVJUgAni3hg4UrNig7Jf68e0sn9AJK/NkCX8PeZ/DXszf0UpQJM6PgUO1R7aqzYLn/+PiI5l9h365rjONTtZJYHT4r4sAeGKmuWGV17DI1tlY= X-Forefront-Antispam-Report: CIP:12.22.5.236; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230016)(4636009)(39860400002)(346002)(376002)(136003)(396003)(40470700004)(36840700001)(46966006)(70586007)(36860700001)(70206006)(8936002)(36756003)(478600001)(40480700001)(4326008)(82310400005)(8676002)(110136005)(83380400001)(316002)(5660300002)(81166007)(186003)(2616005)(26005)(107886003)(336012)(426003)(7696005)(1076003)(47076005)(6666004)(2906002)(356005)(82740400003)(40460700003)(41300700001)(86362001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jul 2022 03:18:41.2203 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2e307366-3e7c-4d08-4f35-08da5bd9904c X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.236]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT035.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR12MB2657 Cc: Jianbo Liu Subject: [ovs-dev] [v6 1/9] netdev-offload: Add meter offload API X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jianbo Liu via dev From: Jianbo Liu Reply-To: Jianbo Liu Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Add API to offload meter to HW, and the corresponding functions to call the meter callbacks from all the registered flow API providers. The interfaces are like those related to meter in dpif_class, in order to pass necessary info to HW. Signed-off-by: Jianbo Liu Acked-by: Eelco Chaudron --- lib/netdev-offload-provider.h | 27 ++++++++++++++++ lib/netdev-offload.c | 59 +++++++++++++++++++++++++++++++++++ lib/netdev-offload.h | 5 +++ 3 files changed, 91 insertions(+) diff --git a/lib/netdev-offload-provider.h b/lib/netdev-offload-provider.h index 8ff2de983..9108856d1 100644 --- a/lib/netdev-offload-provider.h +++ b/lib/netdev-offload-provider.h @@ -94,6 +94,33 @@ struct netdev_flow_api { * takes ownership of a packet if errno != EOPNOTSUPP. */ int (*hw_miss_packet_recover)(struct netdev *, struct dp_packet *); + /* Offloads or modifies the offloaded meter in HW with the given 'meter_id' + * and the configuration in 'config'. On failure, a non-zero error code is + * returned. + * + * The meter id specified through 'config->meter_id' is ignored. */ + int (*meter_set)(ofproto_meter_id meter_id, + struct ofputil_meter_config *config); + + /* Queries HW for meter stats with the given 'meter_id'. Store the stats + * of dropped packets to band 0. On failure, a non-zero error code is + * returned. + * + * Note that the 'stats' structure is already initialized, and only the + * available statistics should be incremented, not replaced. Those fields + * are packet_in_count, byte_in_count and band[]->byte_count and + * band[]->packet_count. */ + int (*meter_get)(ofproto_meter_id meter_id, + struct ofputil_meter_stats *stats); + + /* Removes meter 'meter_id' from HW. Store the stats of dropped packets to + * band 0. On failure, a non-zero error code is returned. + * + * 'stats' may be passed in as NULL if no stats are needed, See the above + * function for additional details on the 'stats' usage. */ + int (*meter_del)(ofproto_meter_id meter_id, + struct ofputil_meter_stats *stats); + /* Initializies the netdev flow api. * Return 0 if successful, otherwise returns a positive errno value. */ int (*init_flow_api)(struct netdev *); diff --git a/lib/netdev-offload.c b/lib/netdev-offload.c index fb108c0d5..9fde5f7a9 100644 --- a/lib/netdev-offload.c +++ b/lib/netdev-offload.c @@ -58,6 +58,7 @@ VLOG_DEFINE_THIS_MODULE(netdev_offload); +static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); static bool netdev_flow_api_enabled = false; #define DEFAULT_OFFLOAD_THREAD_NB 1 @@ -195,6 +196,64 @@ netdev_assign_flow_api(struct netdev *netdev) return -1; } +void +meter_offload_set(ofproto_meter_id meter_id, + struct ofputil_meter_config *config) +{ + struct netdev_registered_flow_api *rfa; + + CMAP_FOR_EACH (rfa, cmap_node, &netdev_flow_apis) { + if (rfa->flow_api->meter_set) { + int ret = rfa->flow_api->meter_set(meter_id, config); + if (ret) { + VLOG_DBG_RL(&rl, "Failed setting meter %u for flow api %s, " + "error %d", meter_id.uint32, rfa->flow_api->type, + ret); + } + } + } + /* Offload APIs could fail, for example, because the offload is not + * supported. This is fine, as the offload API should take care of this. */ +} + +int +meter_offload_get(ofproto_meter_id meter_id, struct ofputil_meter_stats *stats) +{ + struct netdev_registered_flow_api *rfa; + + CMAP_FOR_EACH (rfa, cmap_node, &netdev_flow_apis) { + if (rfa->flow_api->meter_get) { + int ret = rfa->flow_api->meter_get(meter_id, stats); + if (ret) { + VLOG_DBG_RL(&rl, "Failed getting meter %u for flow api %s, " + "error %d", meter_id.uint32, rfa->flow_api->type, + ret); + } + } + } + + return 0; +} + +int +meter_offload_del(ofproto_meter_id meter_id, struct ofputil_meter_stats *stats) +{ + struct netdev_registered_flow_api *rfa; + + CMAP_FOR_EACH (rfa, cmap_node, &netdev_flow_apis) { + if (rfa->flow_api->meter_del) { + int ret = rfa->flow_api->meter_del(meter_id, stats); + if (ret) { + VLOG_DBG_RL(&rl, "Failed deleting meter %u for flow api %s, " + "error %d", meter_id.uint32, rfa->flow_api->type, + ret); + } + } + } + + return 0; +} + int netdev_flow_flush(struct netdev *netdev) { diff --git a/lib/netdev-offload.h b/lib/netdev-offload.h index 8237a85dd..249a3102a 100644 --- a/lib/netdev-offload.h +++ b/lib/netdev-offload.h @@ -22,6 +22,7 @@ #include "openvswitch/types.h" #include "ovs-rcu.h" #include "ovs-thread.h" +#include "openvswitch/ofp-meter.h" #include "packets.h" #include "flow.h" @@ -158,6 +159,10 @@ int netdev_ports_flow_get(const char *dpif_type, struct match *match, int netdev_ports_get_n_flows(const char *dpif_type, odp_port_t port_no, uint64_t *n_flows); +void meter_offload_set(ofproto_meter_id, struct ofputil_meter_config *); +int meter_offload_get(ofproto_meter_id, struct ofputil_meter_stats *); +int meter_offload_del(ofproto_meter_id, struct ofputil_meter_stats *); + #ifdef __cplusplus } #endif From patchwork Sat Jul 2 03:18:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianbo Liu X-Patchwork-Id: 1651418 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=kcjzZgVD; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::136; helo=smtp3.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4LZcjX0DKhz9ryY for ; Sat, 2 Jul 2022 13:18:55 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id BB47260E74; Sat, 2 Jul 2022 03:18:53 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org BB47260E74 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=kcjzZgVD X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0_AlTdWN3mPY; Sat, 2 Jul 2022 03:18:52 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id 6C72560B5B; Sat, 2 Jul 2022 03:18:51 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 6C72560B5B Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 35247C0035; Sat, 2 Jul 2022 03:18:51 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists.linuxfoundation.org (Postfix) with ESMTP id 92F7FC0035 for ; Sat, 2 Jul 2022 03:18:49 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 5E0D760DFD for ; Sat, 2 Jul 2022 03:18:49 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 5E0D760DFD X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id x5w92RL8t6XO for ; Sat, 2 Jul 2022 03:18:48 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 6B81860B5B Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2047.outbound.protection.outlook.com [40.107.100.47]) by smtp3.osuosl.org (Postfix) with ESMTPS id 6B81860B5B for ; Sat, 2 Jul 2022 03:18:48 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gb75zM2fomcXUarW+0oM+rNcg3IYtYaE4wBWAXJKCzyZtTaJt+fdXXNEtovxj/UM8GkkBFWFd4OaqVM/voDkJ5jGF2KSb84ss/thWrkKr+Gggy/kbzsuawy8VM/X0Gk/Nkb2gzJnZpcwRCBjc1WdQEu6IAInB6koB+Vl6CO+/xo8z2g0BBCdSP3/0QYYd586Uc7+5PZCtpfJP1e0QRz2/vnmiEGHfkhSfZyMujUJp3CQ04kKTOJcClg3r0yF60Quhhca5zLWnQOjK6ocCPQ/EnxIpdAkWdzF9VDkHLSshyw8MyeyTBkNue3w+TFyTN+I18H70A3sDTzvin4o0V27iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=7OOPJROqpQqzpVdDjNu09Bwoi81G+I5/o3c1IxwyEiU=; b=Skk+mW0q0TFoCehAqzRJaJq70YdiyoceF7vlx5Gd1IEC8pYfy3kP6o4HMSB+ohEr2Coi10UyTMiLH1nfXvlnqqWp998rN6SqYnccDko3oO2TAKkgxBXrz33c0fh1iG0c+lrpM5f2jxHG9o/lHr8rsMLgnYS8dNBfZeZyPABJy0c1Tx6Om75rZRseA21Xyz2xCrAoHPwN+xCYZQYbGax+s3Msk40IxOrKeKkeCAwwlw76u2+CEQiqM/jPhS9Wv2cYFMiSok1d94LZV3ubGMB7gO5J7eitkqiQhuDFbq5c0eMxDTDzY/ZcTMsuXmiuHgJWecBdReCy/B9bL4Yb37YHJA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=corigine.com 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 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=7OOPJROqpQqzpVdDjNu09Bwoi81G+I5/o3c1IxwyEiU=; b=kcjzZgVDh1fjx6Q/3Ig+Sw/gpdiLEz07m3XvuzhEgV5Il77QDtlhSdzGDvNyhR9INvzkVy0jJpi3diuhyaOSu3LNoT4p07KRxy6trkvPIBzfroHoNc0iLneKT3Pu1sOrktOy7m9S3DZ+LsCtdLFKmWVmqncO41O4nkUbgJjwu4uJhFywnY7Z0AQefh6nQ8ZlL5FCQkD4+RGNN69UaLuRy6N9mRGy1Z01CDwPFUstAAQim+hkuWb1YGBp07dYazLRD5vFlC+wDrdY+lEZgbJwc4PLzpdVd8DeTI8YruOsDTEv0/ujirO5tsBklh4OSDmvSlWYKVECWfVzkoLamGkIrg== Received: from DM6PR08CA0023.namprd08.prod.outlook.com (2603:10b6:5:80::36) by MWHPR12MB1855.namprd12.prod.outlook.com (2603:10b6:300:10e::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.17; Sat, 2 Jul 2022 03:18:44 +0000 Received: from DM6NAM11FT011.eop-nam11.prod.protection.outlook.com (2603:10b6:5:80:cafe::cb) by DM6PR08CA0023.outlook.office365.com (2603:10b6:5:80::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.18 via Frontend Transport; Sat, 2 Jul 2022 03:18:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) 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 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.238) by DM6NAM11FT011.mail.protection.outlook.com (10.13.172.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5395.17 via Frontend Transport; Sat, 2 Jul 2022 03:18:43 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Sat, 2 Jul 2022 03:18:43 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Fri, 1 Jul 2022 20:18:42 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Fri, 1 Jul 2022 20:18:40 -0700 To: , , , , , Date: Sat, 2 Jul 2022 03:18:25 +0000 Message-ID: <20220702031832.13282-3-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220702031832.13282-1-jianbol@nvidia.com> References: <20220702031832.13282-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f03d40a5-ad84-4d13-ffd0-08da5bd991c7 X-MS-TrafficTypeDiagnostic: MWHPR12MB1855:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XrvkxbNSvezwXmG4jttBpp8gg1Z2u4iK1fBsGAPVdg/ELCQZZeXhPOfaYwxEaV1JgWRW7esPJLdUzbcFNxGHgAM68h/lqAT12zC3tpbLIuTIbn01VP45s1GBb76Jjt/mGh8dnHtNREN0n+zVKIP3ZCjAXDN4MYCz+h1723HwnNVXhUdIlLctLAjCBWqrUU6bRRgC5lHofdFOwHSS0zxw8lEI6YR6GdN7nIzl9tdul50iUuZSgCfLEEvJ8xyVl2zDqfYWrbJGRcJN6RNy50w/QhvoQMgEyw4lYDFBhJABN2D5dqClKcupNuVc0ZHV7g29Lnz0QCcxKQbJnNJPAd+lv+jpfTSOXV7Kku6g1esngSWOrNCa9fw7dCDtRA3QXWcxyNJw7f0AazcxUbQtnYCeNsEHBm++g1LnRRaTiwhHBQSigpeHxp8aa6dQCrINOoqx9e/AdApFR/rS3t2EFay9Gsmd9reWcojxdGLyR2YZawFZmzxdcBRqeREufWBBm1RymmUSloWWNBIImQp7V19bvifXeQVeMsbIozZgGpDbswxsEfmBFYEJ7P8b2bAdbCrnluVqrXq684VqbRC35PNJQCBks6K4M8pZte7BS3AOGEI3fLlY+76nPfvSECAVfYUSu4r+lSTqO7zyFay6zMKVrFiCD0nQzEk0PHapOhfu2Vb3pspCF2P0aBI5P1EZ1VrRZWTIdM80I/1MFOKInYRwQDtL3mX0DbeBJbIb16p+Gnn6kNgu7cH/wwA1AVZxFQXYTE+qT/QuILg+leyEPo9rDmlyly1rcjqKvk+l0w0xQbiUnKPmIS5eMSPMM/jhkWISgoazIjPC2fPvfm/d/pCQ+8mcf4nR9V9iz2ELSpa7MiQ= X-Forefront-Antispam-Report: CIP:12.22.5.238; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230016)(4636009)(396003)(39860400002)(376002)(346002)(136003)(40470700004)(46966006)(36840700001)(1076003)(2906002)(86362001)(478600001)(316002)(7696005)(26005)(36860700001)(110136005)(8936002)(36756003)(2616005)(107886003)(4326008)(5660300002)(70586007)(70206006)(8676002)(336012)(426003)(356005)(81166007)(83380400001)(47076005)(82310400005)(186003)(41300700001)(6666004)(82740400003)(40460700003)(40480700001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jul 2022 03:18:43.7087 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f03d40a5-ad84-4d13-ffd0-08da5bd991c7 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.238]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT011.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1855 Cc: Jianbo Liu Subject: [ovs-dev] [v6 2/9] tc: Add support parsing tc police action X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jianbo Liu via dev From: Jianbo Liu Reply-To: Jianbo Liu Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Add function to parse police action from netlink message. Signed-off-by: Jianbo Liu Acked-by: Eelco Chaudron Acked-by: Eelco Chaudron --- lib/netdev-offload-tc.c | 4 +++ lib/tc.c | 54 +++++++++++++++++++++++++++++++++++++++++ lib/tc.h | 5 ++++ 3 files changed, 63 insertions(+) diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c index 262faf3c6..4d42d27b4 100644 --- a/lib/netdev-offload-tc.c +++ b/lib/netdev-offload-tc.c @@ -1017,6 +1017,10 @@ parse_tc_flower_to_match(struct tc_flower *flower, nl_msg_put_u32(buf, OVS_ACTION_ATTR_RECIRC, action->chain); } break; + case TC_ACT_POLICE: { + /* Not supported yet */ + } + break; } } } diff --git a/lib/tc.c b/lib/tc.c index bbb8c86f7..bfd6512a1 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -1340,6 +1340,54 @@ nl_parse_act_gact(struct nlattr *options, struct tc_flower *flower) return 0; } +static const struct nl_policy police_policy[] = { + [TCA_POLICE_TBF] = { .type = NL_A_UNSPEC, + .min_len = sizeof(struct tc_police), + .optional = false, }, + [TCA_POLICE_RATE] = { .type = NL_A_UNSPEC, + .min_len = 1024, + .optional = true, }, + [TCA_POLICE_PEAKRATE] = { .type = NL_A_UNSPEC, + .min_len = 1024, + .optional = true, }, + [TCA_POLICE_AVRATE] = { .type = NL_A_U32, + .optional = true, }, + [TCA_POLICE_RESULT] = { .type = NL_A_U32, + .optional = true, }, + [TCA_POLICE_TM] = { .type = NL_A_UNSPEC, + .min_len = sizeof(struct tcf_t), + .optional = true, }, +}; + +static int +nl_parse_act_police(const struct nlattr *options, struct tc_flower *flower) +{ + struct nlattr *police_attrs[ARRAY_SIZE(police_policy)] = {}; + const struct tc_police *police; + struct tc_action *action; + struct nlattr *police_tm; + const struct tcf_t *tm; + + if (!nl_parse_nested(options, police_policy, police_attrs, + ARRAY_SIZE(police_policy))) { + VLOG_ERR_RL(&error_rl, "Failed to parse police action options"); + return EPROTO; + } + + police = nl_attr_get_unspec(police_attrs[TCA_POLICE_TBF], sizeof *police); + action = &flower->actions[flower->action_count++]; + action->type = TC_ACT_POLICE; + action->police.index = police->index; + + police_tm = police_attrs[TCA_POLICE_TM]; + if (police_tm) { + tm = nl_attr_get_unspec(police_tm, sizeof *tm); + nl_parse_tcf(tm, flower); + } + + return 0; +} + static const struct nl_policy mirred_policy[] = { [TCA_MIRRED_PARMS] = { .type = NL_A_UNSPEC, .min_len = sizeof(struct tc_mirred), @@ -1760,6 +1808,8 @@ nl_parse_single_action(struct nlattr *action, struct tc_flower *flower, /* Added for TC rule only (not in OvS rule) so ignore. */ } else if (!strcmp(act_kind, "ct")) { nl_parse_act_ct(act_options, flower); + } else if (!strcmp(act_kind, "police")) { + nl_parse_act_police(act_options, flower); } else { VLOG_ERR_RL(&error_rl, "unknown tc action kind: %s", act_kind); err = EINVAL; @@ -2776,6 +2826,10 @@ nl_msg_put_flower_acts(struct ofpbuf *request, struct tc_flower *flower) nl_msg_end_nested(request, act_offset); } break; + case TC_ACT_POLICE: { + /* Not supported yet */ + } + break; } } } diff --git a/lib/tc.h b/lib/tc.h index d6cdddd16..751bec891 100644 --- a/lib/tc.h +++ b/lib/tc.h @@ -174,6 +174,7 @@ enum tc_action_type { TC_ACT_MPLS_SET, TC_ACT_GOTO, TC_ACT_CT, + TC_ACT_POLICE, }; enum nat_type { @@ -261,6 +262,10 @@ struct tc_action { struct tc_flower_key key; struct tc_flower_key mask; } rewrite; + + struct { + uint32_t index; + } police; }; enum tc_action_type type; From patchwork Sat Jul 2 03:18:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianbo Liu X-Patchwork-Id: 1651420 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=gI1GQfkp; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4LZcjd0T9Sz9ryY for ; Sat, 2 Jul 2022 13:19:00 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id DF0864161B; Sat, 2 Jul 2022 03:18:57 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org DF0864161B Authentication-Results: smtp2.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=gI1GQfkp X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Fvqi2_Y5EGGJ; Sat, 2 Jul 2022 03:18:55 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id A193D415EF; Sat, 2 Jul 2022 03:18:53 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org A193D415EF Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5B63BC0086; Sat, 2 Jul 2022 03:18:52 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id C41E9C002D for ; Sat, 2 Jul 2022 03:18:50 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 90B3E403C8 for ; Sat, 2 Jul 2022 03:18:50 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 90B3E403C8 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lcp5DlI0KFsj for ; Sat, 2 Jul 2022 03:18:49 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 913854018B Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2066.outbound.protection.outlook.com [40.107.244.66]) by smtp2.osuosl.org (Postfix) with ESMTPS id 913854018B for ; Sat, 2 Jul 2022 03:18:49 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gY66oGAEqz+73h6y7FzXkXLSKbqFFsrSr52lj38C4kWQMRMCz5VdCFd6fOXaqcuWjmxgNF8ZPbFTaiWu3R1b+m5xJgQnKq4S1qkA6mOoBH0cjg1SaqIald/8csof0xMRm4O75M9RhUdaURLim8zrwn45hsKNZbus9KS5+EWL1LrYsRdzMyl3FO9TBKD2HYu7qtMXDsV91MClgrU1Kr1oOhWLu6d42ZMB1RHgvmR2aixRJVXf64uaBkX+421HI+eIZ2JS9nsQ2vHDEc/srgCA9LaTlFv40u4CVKxtBTG/y5J7dD4QQXtlcMKpz1xs48J0LOo2tflQVQKfOeQviT6u6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=Hu+NkxxK6zD/18BhwUcTfaN8olaFMz/2vVNFCA/zX9Q=; b=DZjZi8twEmazFsL6lHJ+2l0tlFOxiFJPXrnF8Lz1rJFr/pyPEouh419PXPQTTlPUi5GMgTah3eIvzOSCM9xSGKuI8utoSBrxXnKWcOJxrBAHVhY6qkM9GPGo197/TUgNX7qkx7fy/rEUUrlg24q7CMTcSjk6CiEUKBHq4yZN/iyyDnrW16jfNIB1ca2ijX4J/eMjDiOU03bqxQNVTERMMVNyfjQKlR9Db/DGY0In+WdIuHQ5WYWWA9HVUSl7rFed/gtugmkBDJuItcbSDrp1hQzK2GLfJkGYs7pduvtc9RXgEbrs/A/lIZqMQWfUyjZzu4U7RbbgnfAMYKN3r3Z+YA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.235) smtp.rcpttodomain=corigine.com 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 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=Hu+NkxxK6zD/18BhwUcTfaN8olaFMz/2vVNFCA/zX9Q=; b=gI1GQfkp66jzKI9dcFASSwn21fBWTAw2B0i875pWKBvY+p0YJ8QtJ82BkrWA6lieqKOWpXWDwt3JOqHGGP7yUZkaWkAN3eFaJ2henk+s8KWcYvr3rWDTreCt2zsT7hO19818KeZs95PYikznZTeAioMv/vsTtLyG9mRDwHb8o9fBpuLYSXNopO4sTjWnLIaFzD9DYgOm8YcbungcZK/WudG1wGAnDySFJnnoatD9RzhfBk6vQC/UH6K/3fXQMs7NWg/6XfqUAXQWntAXavhZmzocM4riPX7TjVl1kHolQnGYcF+97hewT7uTZhzEKGeBKfQjd81nPoReTbim5lZWbw== Received: from MW4PR03CA0166.namprd03.prod.outlook.com (2603:10b6:303:8d::21) by BL1PR12MB5362.namprd12.prod.outlook.com (2603:10b6:208:31d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.15; Sat, 2 Jul 2022 03:18:47 +0000 Received: from CO1NAM11FT016.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8d:cafe::6b) by MW4PR03CA0166.outlook.office365.com (2603:10b6:303:8d::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.14 via Frontend Transport; Sat, 2 Jul 2022 03:18:46 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235) 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 12.22.5.235 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.235; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.235) by CO1NAM11FT016.mail.protection.outlook.com (10.13.175.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5395.14 via Frontend Transport; Sat, 2 Jul 2022 03:18:46 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Sat, 2 Jul 2022 03:18:45 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Fri, 1 Jul 2022 20:18:44 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Fri, 1 Jul 2022 20:18:42 -0700 To: , , , , , Date: Sat, 2 Jul 2022 03:18:26 +0000 Message-ID: <20220702031832.13282-4-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220702031832.13282-1-jianbol@nvidia.com> References: <20220702031832.13282-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 73aff9b0-80ae-4d70-9f45-08da5bd99344 X-MS-TrafficTypeDiagnostic: BL1PR12MB5362:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kQbxTojR5x5bP03w+g7nGvcEyCyH+DDMxOcgWxkORf6vjYXbi6ZLa0vbUKa72XydDh/UWWg//tGo3XIr5OpyIuoo/270mgZMMPIwGa/dUxUYTESoVdt6+gp8FwVMnV6gTGXMxyfdkNdydbtmWPJ/u4UkMAVUqfNnHyryDGeZFu6OJg/SBDulPgOuAwzkseY/dsEdT5FShAq1C1HNeh9+3jchXyzk+qLZrpbpp9K9OisPhAuE6GIYpujb8Wa7cshqdb2lqsCWCU8Qs21iaK2d42WZwKRTVXdJsQtgnEHmwgF6c1V5UAotLV6w/vAU6fKdPJ0B4ZbSKJiJ4LUSq2xAYGYkWiiF5Dp6rsqYCZ6ZdnNU39LgJKOpnxB9eg5n+1jJ7phYnu0whCQVZDKb4iWN0U5YDTeRJwm2wncwnCttiuWp+fVhToYGOqPRjAgGxAGeqjs3kGeysBVojbbcxn5ChuIVmdQjBif/+nKNQixTLshZoU9cYPjxe97oFQCuuAC4tNj0X3XrQaBwx4iqDvJSyJ94xxuPjHmdKGA96Pkebp59i7J8/1lPqgWLORtVCITnV0MAcXzKify0uSNTWxkXxI8idWQ6AFmCbXOTNBfofdBlE9XMWXHQJesV8ZX4dk3Z7SAyGwIYLe0O5tcpm0Q7Hvk6jeBLaQVWsNSJY4aMbpO0Tn7YPjDGPuDRMIleXkK0P6Pbk/Ag+R4eywGZCOfrgUuiCcBUMavL9N4r+itnOk7/LZBUVWD/qjsa3IwqgoHrCH9Ppr5Sa5XSuOZ8gA0eilz5KiA7u5FaLbEzv5q2HEQY5Nlvt9mZkiTkzo2Mo5hwVusbfql4wHYn3sNw4IahzDgh3mMLk5QY+PIx2IiQsFQ= X-Forefront-Antispam-Report: CIP:12.22.5.235; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230016)(4636009)(376002)(396003)(346002)(39860400002)(136003)(46966006)(40470700004)(36840700001)(2906002)(41300700001)(36860700001)(15650500001)(4326008)(110136005)(8676002)(40480700001)(70586007)(86362001)(40460700003)(36756003)(316002)(70206006)(82310400005)(478600001)(356005)(1076003)(47076005)(81166007)(5660300002)(82740400003)(426003)(186003)(2616005)(107886003)(6666004)(8936002)(7696005)(26005)(83380400001)(336012)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jul 2022 03:18:46.2031 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 73aff9b0-80ae-4d70-9f45-08da5bd99344 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.235]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT016.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5362 Cc: Jianbo Liu Subject: [ovs-dev] [v6 3/9] netdev-linux: Refactor put police action netlink message X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jianbo Liu via dev From: Jianbo Liu Reply-To: Jianbo Liu Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" To reuse the code for manipulating police action, move the common initialization code to a function, and change PPS parameters as meter pktps is in unit of packet per second. null_police is redundant because either BPS or PPS, not both, can be configured in one message. So the police passed in to nl_msg_put_act_police can be reused as its rate is zero for PPS, and it also provides the index for police action to be created. Signed-off-by: Jianbo Liu Acked-by: Eelco Chaudron --- lib/netdev-linux.c | 89 ++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 42 deletions(-) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 2766b3f2b..039a99f49 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -2629,37 +2629,30 @@ nl_msg_act_police_end_nest(struct ofpbuf *request, size_t offset, } static void -nl_msg_put_act_police(struct ofpbuf *request, struct tc_police police, - uint32_t kpkts_rate, uint32_t kpkts_burst) +nl_msg_put_act_police(struct ofpbuf *request, struct tc_police *police, + uint64_t pkts_rate, uint64_t pkts_burst) { size_t offset, act_offset; uint32_t prio = 0; - /* used for PPS, set rate as 0 to act as a single action */ - struct tc_police null_police; - - memset(&null_police, 0, sizeof null_police); - - if (police.rate.rate) { - nl_msg_act_police_start_nest(request, ++prio, &offset, &act_offset); - tc_put_rtab(request, TCA_POLICE_RATE, &police.rate); - nl_msg_put_unspec(request, TCA_POLICE_TBF, &police, sizeof police); - nl_msg_act_police_end_nest(request, offset, act_offset); - } - if (kpkts_rate) { - unsigned int pkt_burst_ticks, pps_rate, size; - nl_msg_act_police_start_nest(request, ++prio, &offset, &act_offset); - pps_rate = kpkts_rate * 1000; - size = MIN(UINT32_MAX / 1000, kpkts_burst) * 1000; + + if (!police->rate.rate && !pkts_rate) { + return; + } + + nl_msg_act_police_start_nest(request, ++prio, &offset, &act_offset); + if (police->rate.rate) { + tc_put_rtab(request, TCA_POLICE_RATE, &police->rate); + } + if (pkts_rate) { + uint64_t pkt_burst_ticks; /* Here tc_bytes_to_ticks is used to convert packets rather than bytes to ticks. */ - pkt_burst_ticks = tc_bytes_to_ticks(pps_rate, size); - nl_msg_put_u64(request, TCA_POLICE_PKTRATE64, (uint64_t) pps_rate); - nl_msg_put_u64(request, TCA_POLICE_PKTBURST64, - (uint64_t) pkt_burst_ticks); - nl_msg_put_unspec(request, TCA_POLICE_TBF, &null_police, - sizeof null_police); - nl_msg_act_police_end_nest(request, offset, act_offset); + pkt_burst_ticks = tc_bytes_to_ticks(pkts_rate, pkts_burst); + nl_msg_put_u64(request, TCA_POLICE_PKTRATE64, pkts_rate); + nl_msg_put_u64(request, TCA_POLICE_PKTBURST64, pkt_burst_ticks); } + nl_msg_put_unspec(request, TCA_POLICE_TBF, police, sizeof *police); + nl_msg_act_police_end_nest(request, offset, act_offset); } static int @@ -2692,7 +2685,8 @@ tc_add_matchall_policer(struct netdev *netdev, uint32_t kbits_rate, nl_msg_put_string(&request, TCA_KIND, "matchall"); basic_offset = nl_msg_start_nested(&request, TCA_OPTIONS); action_offset = nl_msg_start_nested(&request, TCA_MATCHALL_ACT); - nl_msg_put_act_police(&request, pol_act, kpkts_rate, kpkts_burst); + nl_msg_put_act_police(&request, &pol_act, kpkts_rate * 1000, + kpkts_burst * 1000); nl_msg_end_nested(&request, action_offset); nl_msg_end_nested(&request, basic_offset); @@ -5599,6 +5593,29 @@ netdev_linux_tc_make_request(const struct netdev *netdev, int type, return tc_make_request(ifindex, type, flags, request); } +static void +tc_policer_init(struct tc_police *tc_police, uint64_t kbits_rate, + uint64_t kbits_burst) +{ + int mtu = 65535; + + memset(tc_police, 0, sizeof *tc_police); + + tc_police->action = TC_POLICE_SHOT; + tc_police->mtu = mtu; + tc_fill_rate(&tc_police->rate, kbits_rate * 1000 / 8, mtu); + + /* The following appears wrong in one way: In networking a kilobit is + * usually 1000 bits but this uses 1024 bits. + * + * However if you "fix" those problems then "tc filter show ..." shows + * "125000b", meaning 125,000 bits, when OVS configures it for 1000 kbit == + * 1,000,000 bits, whereas this actually ends up doing the right thing from + * tc's point of view. Whatever. */ + tc_police->burst = tc_bytes_to_ticks( + tc_police->rate.rate, kbits_burst * 1024 / 8); +} + /* Adds a policer to 'netdev' with a rate of 'kbits_rate' and a burst size * of 'kbits_burst', with a rate of 'kpkts_rate' and a burst size of * 'kpkts_burst'. @@ -5623,22 +5640,7 @@ tc_add_policer(struct netdev *netdev, uint32_t kbits_rate, struct ofpbuf request; struct tcmsg *tcmsg; int error; - int mtu = 65535; - memset(&tc_police, 0, sizeof tc_police); - tc_police.action = TC_POLICE_SHOT; - tc_police.mtu = mtu; - tc_fill_rate(&tc_police.rate, ((uint64_t) kbits_rate * 1000)/8, mtu); - - /* The following appears wrong in one way: In networking a kilobit is - * usually 1000 bits but this uses 1024 bits. - * - * However if you "fix" those problems then "tc filter show ..." shows - * "125000b", meaning 125,000 bits, when OVS configures it for 1000 kbit == - * 1,000,000 bits, whereas this actually ends up doing the right thing from - * tc's point of view. Whatever. */ - tc_police.burst = tc_bytes_to_ticks( - tc_police.rate.rate, MIN(UINT32_MAX / 1024, kbits_burst) * 1024 / 8); tcmsg = netdev_linux_tc_make_request(netdev, RTM_NEWTFILTER, NLM_F_EXCL | NLM_F_CREATE, &request); if (!tcmsg) { @@ -5648,9 +5650,12 @@ tc_add_policer(struct netdev *netdev, uint32_t kbits_rate, tcmsg->tcm_info = tc_make_handle(49, (OVS_FORCE uint16_t) htons(ETH_P_ALL)); nl_msg_put_string(&request, TCA_KIND, "basic"); + basic_offset = nl_msg_start_nested(&request, TCA_OPTIONS); police_offset = nl_msg_start_nested(&request, TCA_BASIC_ACT); - nl_msg_put_act_police(&request, tc_police, kpkts_rate, kpkts_burst); + tc_policer_init(&tc_police, kbits_rate, kbits_burst); + nl_msg_put_act_police(&request, &tc_police, kpkts_rate * 1000ULL, + kpkts_burst * 1000ULL); nl_msg_end_nested(&request, police_offset); nl_msg_end_nested(&request, basic_offset); From patchwork Sat Jul 2 03:18:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianbo Liu X-Patchwork-Id: 1651421 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=UrFTvJLQ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4LZcjg5qpfz9ryY for ; Sat, 2 Jul 2022 13:19:03 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id B34E0415E7; Sat, 2 Jul 2022 03:19:01 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org B34E0415E7 Authentication-Results: smtp2.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=UrFTvJLQ X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id umydnPzxKhLH; Sat, 2 Jul 2022 03:18:58 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id 34C2D40BB7; Sat, 2 Jul 2022 03:18:56 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 34C2D40BB7 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id EDD3BC0037; Sat, 2 Jul 2022 03:18:55 +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 1D432C0037 for ; Sat, 2 Jul 2022 03:18:55 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id CA5974188A for ; Sat, 2 Jul 2022 03:18:54 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org CA5974188A Authentication-Results: smtp4.osuosl.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=UrFTvJLQ X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yNa8n1ZLvp4T for ; Sat, 2 Jul 2022 03:18:51 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 5B08B4161E Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2069.outbound.protection.outlook.com [40.107.93.69]) by smtp4.osuosl.org (Postfix) with ESMTPS id 5B08B4161E for ; Sat, 2 Jul 2022 03:18:51 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jESzxmMCls6TnO9EKp4AQtP7m8mPbIqSHiMfjyzybN4Drxrwb0HAHSqgmgrOCDAWYwDkUeEgip7ijoFUN6GRm0xbhxFRljezsN9AaYMeMoXjKDqfkA1wVVtz8bmQKJNTRrWfRShUHuzyqrc0WWGcUy+wr5va+SAjcQT5crYjArMjFkTJ6C09g3asxwtbEOOhGAcmQxzP3abvdqpyi5Q/LUod+lSj7J21eyahXs8Z+O1pn7sF28PJwgWMdPMnc1VCAxWXV8Xjd3a9nYOUNFKnMsV0UlGlMEEmKuW5LfgUujBuZXx4HeApjCRxTwmK6ev88Jg+BQQl1t7LALZzlnkrsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=vfFot9jJ1C6JMLxYyp5VOswAyTKV/1OfmKYxHPQ+Z0k=; b=Xzll+rBO/Bbn33+Kcf60gvdsGZ5JJ34R2xt5R1NpGyHd24YPo1Rzcly42aB1toWXPzFzlIEmXxwzjDrejEtbl8G+RbBHcd2eminNjlP5GyNCallM58dyLewQ6bpQZPcsGfomePp/fzfmjvSFogQKIzatevqdZCkYk6bf6nWN572HLgRkTufu5Sx1TH4hWRAhOr9oZnjnpJXtiF9ohgyx693q/QRwuBGGW0d5SzhY+lr5Sf+2W4FbmoaOv8omkFYbnlwcOHMixTB1vtDWH++2xpg+tL+gMpU3e756KBHdnB48w6Wu1wWC6AcGse5k0fHIUlvo5O7aqUacA+vle70iNw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=corigine.com 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 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=vfFot9jJ1C6JMLxYyp5VOswAyTKV/1OfmKYxHPQ+Z0k=; b=UrFTvJLQeaEBxw0ZjrnagqrCLL/8TrleNwHzDw7VJZ6mox4o44f4F4ySHi7OWwP4zKBR+l0k67rl7VAT8nM2rLORN9bFyE3YnRsFf84GPf+DZI00nf6Z5TyAlV4Q0VLJTLLngVnGTDNa+jCWNqLiDbbXVkghfxstKZrUufdJf+DBFCHl1f+UBajXT6VcmhCRO/UrMnz6fPAfhC542GL59cEI4wiuKLUuuMPkBdiKRR4FnMzq5cH2vADpmO2S0DP4M9ynXXwVBh4F5UrzSxCY6wxEiOtWNA8FEngWaw1nA7nvsdul0xp4BtWI5ImcJQez8JY5A8FhWvQPngnLfaa04g== Received: from DM6PR08CA0058.namprd08.prod.outlook.com (2603:10b6:5:1e0::32) by DM6PR12MB4516.namprd12.prod.outlook.com (2603:10b6:5:2ac::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.15; Sat, 2 Jul 2022 03:18:49 +0000 Received: from DM6NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:5:1e0:cafe::bb) by DM6PR08CA0058.outlook.office365.com (2603:10b6:5:1e0::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.14 via Frontend Transport; Sat, 2 Jul 2022 03:18:49 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) 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 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.238) by DM6NAM11FT066.mail.protection.outlook.com (10.13.173.179) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5395.14 via Frontend Transport; Sat, 2 Jul 2022 03:18:48 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Sat, 2 Jul 2022 03:18:48 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Fri, 1 Jul 2022 20:18:47 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Fri, 1 Jul 2022 20:18:45 -0700 To: , , , , , Date: Sat, 2 Jul 2022 03:18:27 +0000 Message-ID: <20220702031832.13282-5-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220702031832.13282-1-jianbol@nvidia.com> References: <20220702031832.13282-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a8e5a677-6696-4db0-5d56-08da5bd994cf X-MS-TrafficTypeDiagnostic: DM6PR12MB4516:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mXkdPf/c/w+ft64IPXow8sWKmpgJGaMU+kUUdVwC3yW1xWpgdeTXRIxawMhIBYSxzf23eZ87BH/6DX5jw7CHhl0a9F83UHlpOg0WkPfWziqU+S6rdV9dcM9MRGt1koKkejupDEmvh5mtES7vatXeLwVHGeeLw5q1nHwJigC7JTVl8yv5L9ipNBZHMJgoB8XzL6RLdQzBTQZnJJ4fj2Ia+j234X3UKBAoZ6dDTF7IWbDH1d8u0+qW7KJeR3ourrrNrn3UIp9I8J6UFcC2JFdS7fukhmJ07LX5LT2jxSM+jPZgUTJMPqJnlG7Cvr7m6PVOEoL0HGHMF0xjOxuGJIXs5i/yY/0mSU/ssy4vrcuXe1qv/lE9eWWryMlpFpg545dRgkICo9sJktxQLRc7kPDhMwOnDdYXfdwowgxNid/W4Dcgjrt5K6SoQ0KdRY81CMJShq+4RhFi43WVRuY9b1bYp0MD75riTE3eLsJr2pM+T4ll+diLyB7P1IYn52kkE+R8lwCU58AOI21Xy42svrt4AUNRuCae7Y4xsD7Ccwv4chlmdN+tdsKTjWjSimwHp5SvazomNWJHGNybZlFUQsKirlribOu3dWP98VPoJexPRMLMesT4wn6LZekGuc/+e0yZjU0EKOU6rgAsenD8LN2c3d8WJDm6Hy9QyKx/5KMf01OhsYwE2Sy2MLp4B+ixT+bhmNDbelnkFgyuZBikHbTSFGnKgBjbYY11POGic2i96a4kqsLwmQM3PEAuTLSwaL/toUJsNh590sNGUZJU0TXyVQUPvnK4jI0iONPZFRSUJblJLIyLOH0cxLyzADVeUVSF3/uz+/rlzJmafbnh9UArP+K+sduDkTdjP4Fo+4lJyLE= X-Forefront-Antispam-Report: CIP:12.22.5.238; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230016)(4636009)(376002)(346002)(136003)(39860400002)(396003)(46966006)(40470700004)(36840700001)(40460700003)(86362001)(36860700001)(81166007)(356005)(82740400003)(82310400005)(8936002)(478600001)(6666004)(41300700001)(2906002)(5660300002)(30864003)(316002)(110136005)(4326008)(8676002)(70206006)(70586007)(426003)(186003)(47076005)(336012)(40480700001)(83380400001)(1076003)(26005)(7696005)(2616005)(107886003)(36756003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jul 2022 03:18:48.7276 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a8e5a677-6696-4db0-5d56-08da5bd994cf X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.238]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4516 Cc: Jianbo Liu Subject: [ovs-dev] [v6 4/9] netdev-linux: Add functions to manipulate tc police action X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jianbo Liu via dev From: Jianbo Liu Reply-To: Jianbo Liu Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Add helpers to add, delete and get stats of police action with the specified index. Signed-off-by: Jianbo Liu --- lib/netdev-linux.c | 144 +++++++++++++++++++++++++++++++++++++++++++++ lib/netdev-linux.h | 6 ++ lib/tc.c | 118 +++++++++++++++++++++++++------------ lib/tc.h | 7 +++ 4 files changed, 239 insertions(+), 36 deletions(-) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 039a99f49..24f0bceb8 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -5667,6 +5667,150 @@ tc_add_policer(struct netdev *netdev, uint32_t kbits_rate, return 0; } +int +tc_add_policer_action(uint32_t index, uint32_t kbits_rate, + uint32_t kbits_burst, uint32_t pkts_rate, + uint32_t pkts_burst, bool update) +{ + struct tc_police tc_police; + struct ofpbuf request; + struct tcamsg *tcamsg; + size_t offset; + int flags; + int error; + + tc_policer_init(&tc_police, kbits_rate, kbits_burst); + tc_police.index = index; + + flags = (update ? NLM_F_REPLACE : NLM_F_EXCL) | NLM_F_CREATE; + tcamsg = tc_make_action_request(RTM_NEWACTION, flags, &request); + if (!tcamsg) { + return ENODEV; + } + + offset = nl_msg_start_nested(&request, TCA_ACT_TAB); + nl_msg_put_act_police(&request, &tc_police, pkts_rate, pkts_burst); + nl_msg_end_nested(&request, offset); + + error = tc_transact(&request, NULL); + if (error) { + VLOG_ERR_RL(&rl, "Failed to %s police action, err=%d", + update ? "update" : "add", error); + } + + return error; +} + +static int +tc_update_policer_action_stats(struct ofpbuf *msg, + struct ofputil_meter_stats *stats) +{ + struct ovs_flow_stats stats_dropped = {0}; + struct ovs_flow_stats stats_hw = {0}; + struct ovs_flow_stats stats_sw = {0}; + const struct nlattr *act = NULL; + struct nlattr *prio; + struct tcamsg *tca; + int error; + + if (!stats) { + return 0; + } + + if (NLMSG_HDRLEN + sizeof *tca > msg->size) { + VLOG_ERR_RL(&rl, "Failed to get action stats, size error"); + return EPROTO; + } + + tca = ofpbuf_at_assert(msg, NLMSG_HDRLEN, sizeof *tca); + act = nl_attr_find(msg, NLMSG_HDRLEN + sizeof *tca, TCA_ACT_TAB); + if (!act) { + VLOG_ERR_RL(&rl, "Failed to get action stats, can't find attr"); + return EPROTO; + } + + prio = (struct nlattr *) act + 1; + error = tc_parse_action_stats(prio, &stats_sw, &stats_hw, &stats_dropped); + if (!error) { + stats->packet_in_count += + get_32aligned_u64(&stats_sw.n_packets); + stats->byte_in_count += get_32aligned_u64(&stats_sw.n_bytes); + stats->packet_in_count += + get_32aligned_u64(&stats_hw.n_packets); + stats->byte_in_count += get_32aligned_u64(&stats_hw.n_bytes); + if (stats->n_bands >= 1) { + stats->bands[0].packet_count += + get_32aligned_u64(&stats_dropped.n_packets); + } + } + + return error; +} + +int +tc_get_policer_action(uint32_t index, struct ofputil_meter_stats *stats) +{ + struct ofpbuf *replyp = NULL; + struct ofpbuf request; + struct tcamsg *tcamsg; + size_t root_offset; + size_t prio_offset; + int error; + + tcamsg = tc_make_action_request(RTM_GETACTION, 0, &request); + if (!tcamsg) { + return ENODEV; + } + + root_offset = nl_msg_start_nested(&request, TCA_ACT_TAB); + prio_offset = nl_msg_start_nested(&request, 1); + nl_msg_put_string(&request, TCA_ACT_KIND, "police"); + nl_msg_put_u32(&request, TCA_ACT_INDEX, index); + nl_msg_end_nested(&request, prio_offset); + nl_msg_end_nested(&request, root_offset); + + error = tc_transact(&request, &replyp); + if (error) { + VLOG_ERR_RL(&rl, "Failed to dump police action (index: %u), err=%d", + index, error); + return error; + } + + return tc_update_policer_action_stats(replyp, stats); +} + +int +tc_del_policer_action(uint32_t index, struct ofputil_meter_stats *stats) +{ + struct ofpbuf *replyp = NULL; + struct ofpbuf request; + struct tcamsg *tcamsg; + size_t root_offset; + size_t prio_offset; + int error; + + tcamsg = tc_make_action_request(RTM_DELACTION, NLM_F_ACK, &request); + if (!tcamsg) { + return ENODEV; + } + + root_offset = nl_msg_start_nested(&request, TCA_ACT_TAB); + prio_offset = nl_msg_start_nested(&request, 1); + nl_msg_put_string(&request, TCA_ACT_KIND, "police"); + nl_msg_put_u32(&request, TCA_ACT_INDEX, index); + nl_msg_end_nested(&request, prio_offset); + nl_msg_end_nested(&request, root_offset); + + error = tc_transact(&request, &replyp); + if (error) { + VLOG_ERR_RL(&rl, "Failed to delete police action (index: %u), err=%d", + index, error); + return error; + } + + return tc_update_policer_action_stats(replyp, stats); +} + static void read_psched(void) { diff --git a/lib/netdev-linux.h b/lib/netdev-linux.h index e1e30f806..9a416ce50 100644 --- a/lib/netdev-linux.h +++ b/lib/netdev-linux.h @@ -19,6 +19,7 @@ #include #include +#include "openvswitch/ofp-meter.h" /* These functions are Linux specific, so they should be used directly only by * Linux-specific code. */ @@ -28,5 +29,10 @@ struct netdev; int netdev_linux_ethtool_set_flag(struct netdev *netdev, uint32_t flag, const char *flag_name, bool enable); int linux_get_ifindex(const char *netdev_name); +int tc_add_policer_action(uint32_t index, uint32_t kbits_rate, + uint32_t kbits_burst, uint32_t pkts_rate, + uint32_t pkts_burst, bool update); +int tc_del_policer_action(uint32_t index, struct ofputil_meter_stats *stats); +int tc_get_policer_action(uint32_t index, struct ofputil_meter_stats *stats); #endif /* netdev-linux.h */ diff --git a/lib/tc.c b/lib/tc.c index bfd6512a1..bd107a588 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -199,6 +199,20 @@ tc_make_request(int ifindex, int type, unsigned int flags, return tcmsg; } +struct tcamsg * +tc_make_action_request(int type, unsigned int flags, + struct ofpbuf *request) +{ + struct tcamsg *tcamsg; + + ofpbuf_init(request, 512); + nl_msg_put_nlmsghdr(request, sizeof *tcamsg, type, NLM_F_REQUEST | flags); + tcamsg = ofpbuf_put_zeros(request, sizeof *tcamsg); + tcamsg->tca_family = AF_UNSPEC; + + return tcamsg; +} + static void request_from_tcf_id(struct tcf_id *id, uint16_t eth_type, int type, unsigned int flags, struct ofpbuf *request) @@ -1760,21 +1774,69 @@ static const struct nl_policy stats_policy[] = { [TCA_STATS_BASIC_HW] = { .type = NL_A_UNSPEC, .min_len = sizeof(struct gnet_stats_basic), .optional = true, }, + [TCA_STATS_QUEUE] = { .type = NL_A_UNSPEC, + .min_len = sizeof(struct gnet_stats_queue), + .optional = true, }, }; +static int +nl_parse_action_stats(struct nlattr *act_stats, + struct ovs_flow_stats *stats_sw, + struct ovs_flow_stats *stats_hw, + struct ovs_flow_stats *stats_dropped) +{ + struct nlattr *stats_attrs[ARRAY_SIZE(stats_policy)]; + struct gnet_stats_basic bs_all, bs_sw, bs_hw; + const struct gnet_stats_queue *qs; + + if (!nl_parse_nested(act_stats, stats_policy, stats_attrs, + ARRAY_SIZE(stats_policy))) { + VLOG_ERR_RL(&error_rl, "Failed to parse action stats policy"); + return EPROTO; + } + + memcpy(&bs_all, + nl_attr_get_unspec(stats_attrs[TCA_STATS_BASIC], sizeof bs_all), + sizeof bs_all); + if (stats_attrs[TCA_STATS_BASIC_HW]) { + memcpy(&bs_hw, nl_attr_get_unspec(stats_attrs[TCA_STATS_BASIC_HW], + sizeof bs_hw), + sizeof bs_hw); + + bs_sw.packets = bs_all.packets - bs_hw.packets; + bs_sw.bytes = bs_all.bytes - bs_hw.bytes; + } else { + bs_sw.packets = bs_all.packets; + bs_sw.bytes = bs_all.bytes; + } + + if (bs_sw.packets > get_32aligned_u64(&stats_sw->n_packets)) { + put_32aligned_u64(&stats_sw->n_packets, bs_sw.packets); + put_32aligned_u64(&stats_sw->n_bytes, bs_sw.bytes); + } + + if (stats_attrs[TCA_STATS_BASIC_HW] + && bs_hw.packets > get_32aligned_u64(&stats_hw->n_packets)) { + put_32aligned_u64(&stats_hw->n_packets, bs_hw.packets); + put_32aligned_u64(&stats_hw->n_bytes, bs_hw.bytes); + } + + if (stats_dropped && stats_attrs[TCA_STATS_QUEUE]) { + qs = nl_attr_get_unspec(stats_attrs[TCA_STATS_QUEUE], sizeof *qs); + put_32aligned_u64(&stats_dropped->n_packets, qs->drops); + } + + return 0; +} + static int nl_parse_single_action(struct nlattr *action, struct tc_flower *flower, bool terse) { struct nlattr *act_options; - struct nlattr *act_stats; struct nlattr *act_cookie; const char *act_kind; struct nlattr *action_attrs[ARRAY_SIZE(act_policy)]; - struct nlattr *stats_attrs[ARRAY_SIZE(stats_policy)]; - struct ovs_flow_stats *stats_sw = &flower->stats_sw; - struct ovs_flow_stats *stats_hw = &flower->stats_hw; - struct gnet_stats_basic bs_all, bs_hw, bs_sw; int err = 0; if (!nl_parse_nested(action, act_policy, action_attrs, @@ -1824,41 +1886,25 @@ nl_parse_single_action(struct nlattr *action, struct tc_flower *flower, flower->act_cookie.len = nl_attr_get_size(act_cookie); } - act_stats = action_attrs[TCA_ACT_STATS]; - - if (!nl_parse_nested(act_stats, stats_policy, stats_attrs, - ARRAY_SIZE(stats_policy))) { - VLOG_ERR_RL(&error_rl, "failed to parse action stats policy"); - return EPROTO; - } - - memcpy(&bs_all, - nl_attr_get_unspec(stats_attrs[TCA_STATS_BASIC], sizeof bs_all), - sizeof bs_all); - if (stats_attrs[TCA_STATS_BASIC_HW]) { - memcpy(&bs_hw, nl_attr_get_unspec(stats_attrs[TCA_STATS_BASIC_HW], - sizeof bs_hw), - sizeof bs_hw); - - bs_sw.packets = bs_all.packets - bs_hw.packets; - bs_sw.bytes = bs_all.bytes - bs_hw.bytes; - } else { - bs_sw.packets = bs_all.packets; - bs_sw.bytes = bs_all.bytes; - } + return nl_parse_action_stats(action_attrs[TCA_ACT_STATS], + &flower->stats_sw, &flower->stats_hw, NULL); +} - if (bs_sw.packets > get_32aligned_u64(&stats_sw->n_packets)) { - put_32aligned_u64(&stats_sw->n_packets, bs_sw.packets); - put_32aligned_u64(&stats_sw->n_bytes, bs_sw.bytes); - } +int +tc_parse_action_stats(struct nlattr *action, struct ovs_flow_stats *stats_sw, + struct ovs_flow_stats *stats_hw, + struct ovs_flow_stats *stats_dropped) +{ + struct nlattr *action_attrs[ARRAY_SIZE(act_policy)]; - if (stats_attrs[TCA_STATS_BASIC_HW] - && bs_hw.packets > get_32aligned_u64(&stats_hw->n_packets)) { - put_32aligned_u64(&stats_hw->n_packets, bs_hw.packets); - put_32aligned_u64(&stats_hw->n_bytes, bs_hw.bytes); + if (!nl_parse_nested(action, act_policy, action_attrs, + ARRAY_SIZE(act_policy))) { + VLOG_ERR_RL(&error_rl, "Failed to parse single action options"); + return EPROTO; } - return 0; + return nl_parse_action_stats(action_attrs[TCA_ACT_STATS], stats_sw, + stats_hw, stats_dropped); } #define TCA_ACT_MIN_PRIO 1 diff --git a/lib/tc.h b/lib/tc.h index 751bec891..30cd2f7ff 100644 --- a/lib/tc.h +++ b/lib/tc.h @@ -23,6 +23,7 @@ #include #include +#include "netlink.h" #include "netlink-socket.h" #include "odp-netlink.h" #include "openvswitch/ofpbuf.h" @@ -80,6 +81,8 @@ tc_get_minor(unsigned int handle) struct tcmsg *tc_make_request(int ifindex, int type, unsigned int flags, struct ofpbuf *); +struct tcamsg *tc_make_action_request(int type, unsigned int flags, + struct ofpbuf *request); int tc_transact(struct ofpbuf *request, struct ofpbuf **replyp); int tc_add_del_qdisc(int ifindex, bool add, uint32_t block_id, enum tc_qdisc_hook hook); @@ -375,5 +378,9 @@ int parse_netlink_to_tc_flower(struct ofpbuf *reply, bool terse); int parse_netlink_to_tc_chain(struct ofpbuf *reply, uint32_t *chain); void tc_set_policy(const char *policy); +int tc_parse_action_stats(struct nlattr *action, + struct ovs_flow_stats *stats_sw, + struct ovs_flow_stats *stats_hw, + struct ovs_flow_stats *stats_dropped); #endif /* tc.h */ From patchwork Sat Jul 2 03:18:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianbo Liu X-Patchwork-Id: 1651422 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=UjBeZIaj; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4LZcjr53Gmz9ryY for ; Sat, 2 Jul 2022 13:19:12 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 74A00418BE; Sat, 2 Jul 2022 03:19:10 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 74A00418BE Authentication-Results: smtp4.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=UjBeZIaj X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qTit_uSpcTvE; Sat, 2 Jul 2022 03:19:08 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id 5ECB9418D7; Sat, 2 Jul 2022 03:19:06 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 5ECB9418D7 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0E813C0037; Sat, 2 Jul 2022 03:19:06 +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 1172FC0035 for ; Sat, 2 Jul 2022 03:19:05 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 592BF416BC for ; Sat, 2 Jul 2022 03:18:58 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 592BF416BC X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TQBs3y5L43Oa for ; Sat, 2 Jul 2022 03:18:56 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 37C04418F3 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2048.outbound.protection.outlook.com [40.107.223.48]) by smtp4.osuosl.org (Postfix) with ESMTPS id 37C04418F3 for ; Sat, 2 Jul 2022 03:18:55 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gH5Hvpy2GqEB1aDfPXqpzbZGDhyF2iQY45s7ezP/DeA6DHn/wIIPieMHSGB4ffOW1x1PhjzeNO9UD4xNYgz8WArDX5KaRWTDOk1xnSrDMJYWQdp+RnMk+F95t01VzwURX1bJ6ECYpaiLZ6EZXgwzGbbSJg/SVN6ECVxM06nuk1fELnqo6S8pvV0L/xHi91WmU2evGuWbdj3o/emGire8iWVuWzhwBh6xh7t+uK10xpkr8gZgtsYxrGQhziuncLfGT8RsFZIFks+3T2MhmmLCQL3jFmCl/qsm2lbP6udENZakjQqY4hKWTJ2rcJd/cP9iKNkmHAnEZ5nj3H0gXnYvPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=4kXUdtQdWUbNZ0l0KTfImz/OTzext54TSuwbiyGsmMM=; b=h/4T4PpIJxAydh7yOQOSglz4jw75g+GWxjCfrMsPwpolOcCbAcxp4XH017GD52Yn62X7f51SAnxGi/5wka5zpCejKPK7pXxFk/5IDuZS4nJGxw+/4VoM3emdq3rvI3Us1ZwOXhUFMwmp4wQ9EPL4E39xbgteTfTh7go+GLs+0OFhRRfHjjg+M1hKTYJ8kGc1b8rKOiA+IxcSg0/9gAn93tu8TAUe85vAw+jkHZASSTB7wA3KDOmvkqxXkRuesh6RJnRgV7bef39lgX0HoeffG6ZFy4c4e5og66Z6DfB4sTS62JG1MbbLsdzKmQcvjMhlnRQgv08FwFqCZW+PWUvZcw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.234) smtp.rcpttodomain=corigine.com 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 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=4kXUdtQdWUbNZ0l0KTfImz/OTzext54TSuwbiyGsmMM=; b=UjBeZIajLXeanoZ+d5PwOroeW6oi7svsTMFsB5UhRwrJ1+92Z4U1tA5g8dIo0ZX11Cn7REblh8F/ICG0WPhQOWO5ZbZlLYzmjx4yVtAw6+m2N/Yi+eOWow2CoJYzewfHOUviq0p+93uCcAbCumv+oGHuLZUAGufOLoehLwzWVZWL8Y/0tDqq5T13ydEC8VJmUBEPsp3con/37674NNUAUcuBe/ZYPRMxstLwpshVndNDBWCCt+wDAbE6VUYU9xDehdyUeK4h4qzyi9dd7lX7kRrgEugjLRIBvERtZaLzTZlvNNVnQqjjD52gjI9gk0ktm91QIMWiM/6mVDqgobDXgw== Received: from BN6PR11CA0006.namprd11.prod.outlook.com (2603:10b6:405:2::16) by DM6PR12MB4012.namprd12.prod.outlook.com (2603:10b6:5:1cc::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.15; Sat, 2 Jul 2022 03:18:51 +0000 Received: from BN8NAM11FT059.eop-nam11.prod.protection.outlook.com (2603:10b6:405:2:cafe::26) by BN6PR11CA0006.outlook.office365.com (2603:10b6:405:2::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.14 via Frontend Transport; Sat, 2 Jul 2022 03:18:51 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.234) 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 12.22.5.234 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.234; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.234) by BN8NAM11FT059.mail.protection.outlook.com (10.13.177.120) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5395.14 via Frontend Transport; Sat, 2 Jul 2022 03:18:51 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Sat, 2 Jul 2022 03:18:50 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Fri, 1 Jul 2022 20:18:50 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Fri, 1 Jul 2022 20:18:48 -0700 To: , , , , , Date: Sat, 2 Jul 2022 03:18:28 +0000 Message-ID: <20220702031832.13282-6-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220702031832.13282-1-jianbol@nvidia.com> References: <20220702031832.13282-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 11824298-2cf5-48ca-f21a-08da5bd99648 X-MS-TrafficTypeDiagnostic: DM6PR12MB4012:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JoBsyvOovXAG4srY8dXageuQFsXNpwLJxetZHz/vnfnsOV1cCP4E97JbOZxXwHKFvyN4U+PLT4wEHFdvWgknDAJGi1bKQuXxuXN7pXkzuJhpFSraEndGCXdTdYw/T2eJZ/N6yLC27RLjjCKeEN3C1X0Aiv1+sE+nh/oN5nf7ywPu6UgRBrUUth5yQf3h2QXggQytllALV8s8sp9Npy2TeckMpIyLjL377HHpxTvWteT3kAFGTH5dteP7naVvI8x4GNeUidj71WXjMHr9Qk74QLBs++S308zxj1dhTaJpi6YsIfI161ybIJTafyJL4bAH0hBLE2Glqn6ZP/Bncpw+zK/Wh+Y0ixB/cIpV7F+0uZxEkjKLNCAdbXrD3V0OG899M09LS0gM4SheHji+pd0AxtNscXR5diT+uYacRYixnjW7Lky2jEkHoVop2Gx0kJc4v3Nd8ONgM0m62e81I1XvkqVnJ/iBn9skpZCV5s9A70bJ8/mW+cMWybpE2+ZYsVBPj9zbxyDDwwnCUMh3NCxvGHV4fD/o7qJ9Qy+SjN88voBYKvO/r6APF5+JFSUFPklU860NM2zgEQ5/Han37jeCZcuW7fRkyXUKFDKjEK2km0+p46egGNX8K7ebQlefSMd0Q6WL7tWMsBK+f75d7Pr+D5ZAagXZXSCRaggjN/kqSBkkmjvu1z75lFvmNRm8w6xgBCIypg4a68QaRM/DlFipy0vQHX07IPCyzE2ht/D25FQKW170KXIx9UeUH9qURU6w2d2WkPBwbwT+yLEEl8d61ZTQBCG3cNfAAf3g/MGrKv69AhFiKC+01busbEO7AZphTqQpvR07kd+0CjrKS3AkR27QaahhCIbEbI5ycBTPDp4= X-Forefront-Antispam-Report: CIP:12.22.5.234; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230016)(4636009)(376002)(396003)(39860400002)(136003)(346002)(36840700001)(40470700004)(46966006)(356005)(70206006)(4326008)(478600001)(8676002)(5660300002)(70586007)(2906002)(81166007)(110136005)(26005)(40460700003)(8936002)(86362001)(41300700001)(6666004)(7696005)(82310400005)(316002)(336012)(40480700001)(36860700001)(1076003)(36756003)(47076005)(107886003)(186003)(426003)(2616005)(82740400003)(83380400001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jul 2022 03:18:51.1865 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 11824298-2cf5-48ca-f21a-08da5bd99648 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.234]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT059.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4012 Cc: Jianbo Liu Subject: [ovs-dev] [v6 5/9] netdev-offload-tc: Implement meter offload API for tc X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jianbo Liu via dev From: Jianbo Liu Reply-To: Jianbo Liu Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" For dpif-netlink, meters are mapped by tc to police actions with one-to-one relationship. Implement meter offload API to set/get/del the police action, and a hmap is used to save the mappings. An id-pool is used to manage all the available police indexes, which are 0x10000000-0x1fffffff, reserved only for OVS. Signed-off-by: Jianbo Liu Acked-by: Eelco Chaudron --- lib/netdev-offload-tc.c | 202 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 202 insertions(+) diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c index 4d42d27b4..2d3206fb6 100644 --- a/lib/netdev-offload-tc.c +++ b/lib/netdev-offload-tc.c @@ -21,6 +21,7 @@ #include "dpif.h" #include "hash.h" +#include "id-pool.h" #include "openvswitch/hmap.h" #include "openvswitch/match.h" #include "openvswitch/ofpbuf.h" @@ -44,6 +45,7 @@ VLOG_DEFINE_THIS_MODULE(netdev_offload_tc); static struct vlog_rate_limit error_rl = VLOG_RATE_LIMIT_INIT(60, 5); +static struct vlog_rate_limit warn_rl = VLOG_RATE_LIMIT_INIT(10, 2); static struct hmap ufid_to_tc = HMAP_INITIALIZER(&ufid_to_tc); static struct hmap tc_to_ufid = HMAP_INITIALIZER(&tc_to_ufid); @@ -62,6 +64,22 @@ struct chain_node { uint32_t chain; }; +struct meter_police_mapping_data { + struct hmap_node meter_id_node; + uint32_t meter_id; + uint32_t police_idx; +}; + +#define METER_POLICE_IDS_BASE 0x10000000 +#define METER_POLICE_IDS_MAX 0x1FFFFFFF +/* Protects below meter police ids pool. */ +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 hmap meter_id_to_police_idx OVS_GUARDED_BY(meter_mutex) + = HMAP_INITIALIZER(&meter_id_to_police_idx); + static bool is_internal_port(const char *type) { @@ -2286,6 +2304,12 @@ netdev_tc_init_flow_api(struct netdev *netdev) probe_multi_mask_per_prio(ifindex); probe_ct_state_support(ifindex); + + ovs_mutex_lock(&meter_police_ids_mutex); + meter_police_ids = id_pool_create(METER_POLICE_IDS_BASE, + METER_POLICE_IDS_MAX - METER_POLICE_IDS_BASE + 1); + ovs_mutex_unlock(&meter_police_ids_mutex); + ovsthread_once_done(&once); } @@ -2302,6 +2326,181 @@ netdev_tc_init_flow_api(struct netdev *netdev) return 0; } +static struct meter_police_mapping_data * +meter_id_find_locked(uint32_t meter_id) + OVS_REQUIRES(meter_mutex) +{ + struct meter_police_mapping_data *data; + size_t hash = hash_int(meter_id, 0); + + HMAP_FOR_EACH_WITH_HASH (data, meter_id_node, hash, + &meter_id_to_police_idx) { + if (data->meter_id == meter_id) { + return data; + } + } + + return NULL; +} + +static int +meter_id_lookup(uint32_t meter_id, uint32_t *police_idx) +{ + struct meter_police_mapping_data *data; + + ovs_mutex_lock(&meter_mutex); + data = meter_id_find_locked(meter_id); + if (data) { + *police_idx = data->police_idx; + } + ovs_mutex_unlock(&meter_mutex); + + return data ? 0 : ENOENT; +} + +static void +meter_id_insert(uint32_t meter_id, uint32_t police_idx) +{ + struct meter_police_mapping_data *data; + + ovs_mutex_lock(&meter_mutex); + data = xzalloc(sizeof *data); + data->meter_id = meter_id; + data->police_idx = police_idx; + hmap_insert(&meter_id_to_police_idx, &data->meter_id_node, + hash_int(meter_id, 0)); + ovs_mutex_unlock(&meter_mutex); +} + +static void +meter_id_remove(uint32_t meter_id) +{ + struct meter_police_mapping_data *data; + + ovs_mutex_lock(&meter_mutex); + data = meter_id_find_locked(meter_id); + if (data) { + hmap_remove(&meter_id_to_police_idx, &data->meter_id_node); + free(data); + } + ovs_mutex_unlock(&meter_mutex); +} + +static bool +meter_alloc_police_index(uint32_t *police_index) +{ + bool ret; + + ovs_mutex_lock(&meter_police_ids_mutex); + ret = id_pool_alloc_id(meter_police_ids, police_index); + ovs_mutex_unlock(&meter_police_ids_mutex); + + return ret; +} + +static void +meter_free_police_index(uint32_t police_index) +{ + ovs_mutex_lock(&meter_police_ids_mutex); + id_pool_free_id(meter_police_ids, police_index); + ovs_mutex_unlock(&meter_police_ids_mutex); +} + +static int +meter_tc_set_policer(ofproto_meter_id meter_id, + struct ofputil_meter_config *config) +{ + uint32_t police_index; + uint32_t rate, burst; + bool add_policer; + int err; + + if (!config->bands || config->n_bands < 1 || + config->bands[0].type != OFPMBT13_DROP) { + return 0; + } + + rate = config->bands[0].rate; + if (config->flags & OFPMF13_BURST) { + burst = config->bands[0].burst_size; + } else { + burst = config->bands[0].rate; + } + + add_policer = (meter_id_lookup(meter_id.uint32, &police_index) == ENOENT); + if (add_policer) { + if (!meter_alloc_police_index(&police_index)) { + VLOG_WARN_RL(&warn_rl, "No free police index for meter id %u", + meter_id.uint32); + return ENOENT; + } + } + + err = tc_add_policer_action(police_index, + (config->flags & OFPMF13_KBPS) ? rate : 0, + (config->flags & OFPMF13_KBPS) ? burst : 0, + (config->flags & OFPMF13_PKTPS) ? rate : 0, + (config->flags & OFPMF13_PKTPS) ? burst : 0, + !add_policer); + if (err) { + VLOG_WARN_RL(&warn_rl, + "Failed to %s police %u for meter id %u: %s", + add_policer ? "add" : "modify", + police_index, meter_id.uint32, ovs_strerror(err)); + } + + if (add_policer) { + if (!err) { + meter_id_insert(meter_id.uint32, police_index); + } else { + meter_free_police_index(police_index); + } + } + + return err; +} + +static int +meter_tc_get_policer(ofproto_meter_id meter_id, + struct ofputil_meter_stats *stats) +{ + uint32_t police_index; + int err = ENOENT; + + if (!meter_id_lookup(meter_id.uint32, &police_index)) { + err = tc_get_policer_action(police_index, stats); + if (err) { + VLOG_WARN_RL(&warn_rl, + "Failed to get police %u stats for meter %u: %s", + police_index, meter_id.uint32, ovs_strerror(err)); + } + } + + return err; +} + +static int +meter_tc_del_policer(ofproto_meter_id meter_id, + struct ofputil_meter_stats *stats) +{ + uint32_t police_index; + int err = ENOENT; + + if (!meter_id_lookup(meter_id.uint32, &police_index)) { + err = tc_del_policer_action(police_index, stats); + if (err && err != ENOENT) { + VLOG_ERR_RL(&error_rl, + "Failed to del police %u for meter %u: %s", + police_index, meter_id.uint32, ovs_strerror(err)); + } else { + meter_free_police_index(police_index); + } + meter_id_remove(meter_id.uint32); + } + + return err; +} + const struct netdev_flow_api netdev_offload_tc = { .type = "linux_tc", .flow_flush = netdev_tc_flow_flush, @@ -2312,5 +2511,8 @@ const struct netdev_flow_api netdev_offload_tc = { .flow_get = netdev_tc_flow_get, .flow_del = netdev_tc_flow_del, .flow_get_n_flows = netdev_tc_get_n_flows, + .meter_set = meter_tc_set_policer, + .meter_get = meter_tc_get_policer, + .meter_del = meter_tc_del_policer, .init_flow_api = netdev_tc_init_flow_api, }; From patchwork Sat Jul 2 03:18:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianbo Liu X-Patchwork-Id: 1651424 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=tMNv/fYf; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4LZcjx6JRQz9ryY for ; Sat, 2 Jul 2022 13:19:17 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 7AF42418F4; Sat, 2 Jul 2022 03:19:15 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 7AF42418F4 Authentication-Results: smtp4.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=tMNv/fYf X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id oXC3neGVMTLU; Sat, 2 Jul 2022 03:19:13 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id A6228424D4; Sat, 2 Jul 2022 03:19:10 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org A6228424D4 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0C7A8C007B; Sat, 2 Jul 2022 03:19:07 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 297FAC0039 for ; Sat, 2 Jul 2022 03:19:05 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id CE3A084814 for ; Sat, 2 Jul 2022 03:18:59 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org CE3A084814 Authentication-Results: smtp1.osuosl.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=tMNv/fYf X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZY3GQU0lymo4 for ; Sat, 2 Jul 2022 03:18:58 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 88840847FD Received: from NAM04-DM6-obe.outbound.protection.outlook.com (mail-dm6nam04on2057.outbound.protection.outlook.com [40.107.102.57]) by smtp1.osuosl.org (Postfix) with ESMTPS id 88840847FD for ; Sat, 2 Jul 2022 03:18:58 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ke0RVZ0s7PhFyxVmxqqSarsfu1beazUfE8EuyEu43Pyma9+ygdDLjE5CxUe00ZF5zHvS5VWF1SeS2QN5f0xgqI8/8eYfrBdnV3bQk/dlxOS80ABoljk5P7Ne5iHtsdK/vsk1EzUdSOIRzyeApWKa66AHyLCEWBPiS82InNrm8cqENkaaNlSydw5MzXAu9OjNe98l92kI8vzolL7XCnATTPYTKi/o2TBSM38TyrwnjL+1dvXhqFiKPmdvkI+zXQk7TU9xOzZZAKKl8zP5bKPrEqYAgHuaLVOJQ0d4UE9U1WELfXlfGmTvvsTT33kwwcMWJOPi1Scl/+pDhauMN5o8Iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=M+P+po9LpdwG+n8FU0N1RXoYGRO6sz8sxZs0JesqQac=; b=MOHCzqlm4mnPFhhnMFW07gi9eXNDApk4XRE7d0Il5yo+VcCSzYwyFeZiOOcd271Z8UMjA6bzyX+i/peIrLPz0kGo6JKQn0+TdL8I5T6RgQ57amI3nMlg5OaET/augy/wk+YPyaqq5r9iJ4mKiuX32BBpK5mXZ/pKtraFaai4TbdYN5+Aoq2h4dyWbSJrHiuF/6t8LEbuY7QdDH92Nl69WkNI3UrwhcdPHoSzyGXkHxmLCUFdPCyMv8Hp82ANZmxsISIgmlcb7nE897wmGKkeXmg2UcJRZPzzSaa0zsIuHVB2buNem/E/UzOHo/ni8OhfRkdAPSlQwqt4nRh+M2znqw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.235) smtp.rcpttodomain=corigine.com 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 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=M+P+po9LpdwG+n8FU0N1RXoYGRO6sz8sxZs0JesqQac=; b=tMNv/fYf/hBb9M5IjEno4LjK+yW1bfoiOj+8B8kUCIOd5Gw4f4rz1xAb3KhgmoV3DHqCfJMBr9tmNDSzENbhvpNiskv4LqQkX7pbnj1dO5b/3W5uHZYe3m7ZlTIrks5swNMXW6vZdE9jYG2zwYTmSv0hn4esNJdd5OscWzsbBZwKumVYhQV3OIlNDpYsmSbwuiDQ7EdxfGTC+yA0ZlqT14R9PEltFvHR+8iuVu1O5KtGyBBilLZSbH+vNzF0nkuLXFu8SBvqFxl5N4wnRZ+zS2IiJMAmvGy5RIxRoIj+2uyzGINO7VeEtv+CGLFHz0s1OOMgDg4YfUhT/NPvgGIFJA== Received: from MWHPR20CA0046.namprd20.prod.outlook.com (2603:10b6:300:ed::32) by SJ1PR12MB6291.namprd12.prod.outlook.com (2603:10b6:a03:456::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.15; Sat, 2 Jul 2022 03:18:54 +0000 Received: from CO1NAM11FT051.eop-nam11.prod.protection.outlook.com (2603:10b6:300:ed:cafe::f6) by MWHPR20CA0046.outlook.office365.com (2603:10b6:300:ed::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.18 via Frontend Transport; Sat, 2 Jul 2022 03:18:54 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235) 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 12.22.5.235 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.235; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.235) by CO1NAM11FT051.mail.protection.outlook.com (10.13.174.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5395.17 via Frontend Transport; Sat, 2 Jul 2022 03:18:53 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Sat, 2 Jul 2022 03:18:53 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Fri, 1 Jul 2022 20:18:52 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Fri, 1 Jul 2022 20:18:50 -0700 To: , , , , , Date: Sat, 2 Jul 2022 03:18:29 +0000 Message-ID: <20220702031832.13282-7-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220702031832.13282-1-jianbol@nvidia.com> References: <20220702031832.13282-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 73897413-073f-48cf-acc0-08da5bd997b7 X-MS-TrafficTypeDiagnostic: SJ1PR12MB6291:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: T/QwWKa9HxF/tYwAdAB+ZW/XUllOex4bm1QSHFX4qD167YRJgV5Wtj7l5bJ5MWUdgdPydE3OBesU/Wa8uaflwvqkDvQ9SLDKyKRUJ/AJNVb0ypwAJ8bVjdRMEtzs3NAWI0LPvMBmMUt84pOLkOetx8v3eiNRNIXmiBbG1StWqzqibrt0++6d8qxVXI+jpC+WSADTyig1crb4pcNRA8jtnvcWvI+jYcm3MtF82g/d44Oy/yOr3Qqr3pDkfT9ZiFLtA3pau5Wtfv6fvSeDiEQ+20vLZF28WO1zNm5Y7X7KMGCBD8xes6J7bLud4ll6SiB2DjFWUx3DDMeez1uTSDsNVP6fC3TyMHniSUPXcCaOBaFrGQJyBYCBzfG5FjaYCnA6BJLAKsJql1RtJWs4u5xx/3CtsRPG2EIo9J/T3taJwbTGFg5A06OEF1DYF/BWBLwSLzyPM0kTDY46S299pAO3jkJ/YFUTikydgh2IUzPBJVM8Sz+QTIrs5mJQD5KIwv57re46opN2V9SnzT6wAwus1wFvyL8zWUrSY0GoajfVfF1fWFJ2p/zMPKnaUiGOjLo3bNv3kx9AipQ7xOx4n1gJXGd63qsA5F5wt8ekkqd+uSl8OPKYnYXPKiKqFwjLv74NfarwFDTSF5c81273x/7zjZjf+211zEZUvFqi/p+HtROaoYsSx/Jlh6vzidW3qVeZxK26W12DvDr46g9sqKygKBMsXB7De6UCpvxX0joUEkIzgPbVTjLocUOKrWIyKNYcjANGGHcoc9xI5xEfRyptAL1ZAwEWlnWIb7wFJjN8vMZKo4gLGEnOJGndmvV9YX6pQ+STcQFOK9YHKYdDj268gFMKYRtm4TaG2sbIxhiMhzM= X-Forefront-Antispam-Report: CIP:12.22.5.235; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230016)(4636009)(39860400002)(376002)(396003)(136003)(346002)(46966006)(36840700001)(40470700004)(6666004)(186003)(426003)(47076005)(86362001)(82310400005)(336012)(81166007)(83380400001)(40480700001)(36860700001)(356005)(40460700003)(41300700001)(82740400003)(2906002)(7696005)(1076003)(478600001)(107886003)(2616005)(8676002)(4326008)(70586007)(70206006)(110136005)(8936002)(36756003)(316002)(5660300002)(26005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jul 2022 03:18:53.6680 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 73897413-073f-48cf-acc0-08da5bd997b7 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.235]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT051.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6291 Cc: Jianbo Liu Subject: [ovs-dev] [v6 6/9] netdev-offload-tc: Cleanup police actions with reserved indexes on startup X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jianbo Liu via dev From: Jianbo Liu Reply-To: Jianbo Liu Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" As the police actions with indexes of 0x10000000-0x1fffffff are reserved for meter offload, to provide a clean environment for OVS, these reserved police actions should be deleted on startup. So dump all the police actions, delete those actions with indexes in this range. Signed-off-by: Jianbo Liu Acked-by: Eelco Chaudron --- lib/netdev-offload-tc.c | 85 +++++++++++++++++++++++++++++++++++++++++ lib/tc.c | 61 +++++++++++++++++++++++++++++ lib/tc.h | 2 + 3 files changed, 148 insertions(+) diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c index 2d3206fb6..7de51a6e0 100644 --- a/lib/netdev-offload-tc.c +++ b/lib/netdev-offload-tc.c @@ -70,6 +70,11 @@ struct meter_police_mapping_data { uint32_t police_idx; }; +struct policer_node { + struct hmap_node node; + uint32_t police_idx; +}; + #define METER_POLICE_IDS_BASE 0x10000000 #define METER_POLICE_IDS_MAX 0x1FFFFFFF /* Protects below meter police ids pool. */ @@ -2255,6 +2260,84 @@ probe_tc_block_support(int ifindex) } } +static int +tc_get_policer_action_ids(struct hmap *map) +{ + uint32_t police_idx[TCA_ACT_MAX_PRIO]; + struct policer_node *policer_node; + struct netdev_flow_dump *dump; + struct ofpbuf rbuffer, reply; + size_t hash; + int i, err; + + dump = xzalloc(sizeof *dump); + dump->nl_dump = xzalloc(sizeof *dump->nl_dump); + + ofpbuf_init(&rbuffer, NL_DUMP_BUFSIZE); + tc_dump_tc_action_start("police", dump->nl_dump); + + while (nl_dump_next(dump->nl_dump, &reply, &rbuffer)) { + memset(police_idx, 0, sizeof police_idx); + if (parse_netlink_to_tc_policer(&reply, police_idx)) { + continue; + } + + for (i = 0; i < TCA_ACT_MAX_PRIO; i++) { + if (!police_idx[i]) { + break; + } + policer_node = xzalloc(sizeof *policer_node); + policer_node->police_idx = police_idx[i]; + hash = hash_int(police_idx[i], 0); + hmap_insert(map, &policer_node->node, hash); + } + } + + err = nl_dump_done(dump->nl_dump); + ofpbuf_uninit(&rbuffer); + free(dump->nl_dump); + free(dump); + + return err; +} + +static void +tc_cleanup_policer_actions(struct id_pool *police_ids, + uint32_t id_min, uint32_t id_max) +{ + struct policer_node *policer_node; + unsigned int unusable_ids = 0; + uint32_t police_idx; + struct hmap map; + int err; + + hmap_init(&map); + tc_get_policer_action_ids(&map); + + HMAP_FOR_EACH_POP (policer_node, node, &map) { + police_idx = policer_node->police_idx; + if (police_idx >= id_min && police_idx <= id_max) { + err = tc_del_policer_action(police_idx, NULL); + if (err && err != ENOENT) { + /* Don't use this police any more. */ + id_pool_add(police_ids, police_idx); + + unusable_ids++; + VLOG_DBG("Policer index %u could not be freed for OVS, " + "error %d", police_idx, err); + } + } + free(policer_node); + } + + if (unusable_ids) { + VLOG_WARN("Full policer index pool allocation failed, " + "%u indexes are unavailable", unusable_ids); + } + + hmap_destroy(&map); +} + static int netdev_tc_init_flow_api(struct netdev *netdev) { @@ -2308,6 +2391,8 @@ netdev_tc_init_flow_api(struct netdev *netdev) ovs_mutex_lock(&meter_police_ids_mutex); meter_police_ids = id_pool_create(METER_POLICE_IDS_BASE, METER_POLICE_IDS_MAX - METER_POLICE_IDS_BASE + 1); + tc_cleanup_policer_actions(meter_police_ids, METER_POLICE_IDS_BASE, + METER_POLICE_IDS_MAX); ovs_mutex_unlock(&meter_police_ids_mutex); ovsthread_once_done(&once); diff --git a/lib/tc.c b/lib/tc.c index bd107a588..74e2d6caf 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -2090,6 +2090,67 @@ tc_dump_tc_chain_start(struct tcf_id *id, struct nl_dump *dump) return 0; } +int +tc_dump_tc_action_start(char *name, struct nl_dump *dump) +{ + size_t offset, root_offset; + struct ofpbuf request; + + tc_make_action_request(RTM_GETACTION, NLM_F_DUMP, &request); + root_offset = nl_msg_start_nested(&request, TCA_ACT_TAB); + offset = nl_msg_start_nested(&request, 1); + nl_msg_put_string(&request, TCA_ACT_KIND, name); + nl_msg_end_nested(&request, offset); + nl_msg_end_nested(&request, root_offset); + + nl_dump_start(dump, NETLINK_ROUTE, &request); + ofpbuf_uninit(&request); + + return 0; +} + +int +parse_netlink_to_tc_policer(struct ofpbuf *reply, uint32_t police_idx[]) +{ + static struct nl_policy actions_orders_policy[TCA_ACT_MAX_PRIO] = {}; + struct nlattr *actions_orders[ARRAY_SIZE(actions_orders_policy)]; + const int max_size = ARRAY_SIZE(actions_orders_policy); + const struct nlattr *actions; + struct tc_flower flower; + struct tcamsg *tca; + int i, cnt = 0; + int err; + + for (i = 0; i < max_size; i++) { + actions_orders_policy[i].type = NL_A_NESTED; + actions_orders_policy[i].optional = true; + } + + tca = ofpbuf_at_assert(reply, NLMSG_HDRLEN, sizeof *tca); + actions = nl_attr_find(reply, NLMSG_HDRLEN + sizeof *tca, TCA_ACT_TAB); + if (!actions || !nl_parse_nested(actions, actions_orders_policy, + actions_orders, max_size)) { + VLOG_ERR_RL(&error_rl, + "Failed to parse actions in netlink to policer"); + return EPROTO; + } + + for (i = 0; i < TCA_ACT_MAX_PRIO; i++) { + if (actions_orders[i]) { + memset(&flower, 0, sizeof(struct tc_flower)); + err = nl_parse_single_action(actions_orders[i], &flower, false); + if (err || flower.actions[0].type != TC_ACT_POLICE) { + continue; + } + if (flower.actions[0].police.index) { + police_idx[cnt++] = flower.actions[0].police.index; + } + } + } + + return 0; +} + int tc_del_filter(struct tcf_id *id) { diff --git a/lib/tc.h b/lib/tc.h index 30cd2f7ff..4690dce4f 100644 --- a/lib/tc.h +++ b/lib/tc.h @@ -382,5 +382,7 @@ int tc_parse_action_stats(struct nlattr *action, struct ovs_flow_stats *stats_sw, struct ovs_flow_stats *stats_hw, struct ovs_flow_stats *stats_dropped); +int tc_dump_tc_action_start(char *name, struct nl_dump *dump); +int parse_netlink_to_tc_policer(struct ofpbuf *reply, uint32_t police_idx[]); #endif /* tc.h */ From patchwork Sat Jul 2 03:18:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianbo Liu X-Patchwork-Id: 1651426 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=mbXnMcdQ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4LZckM6lYbz9ryY for ; Sat, 2 Jul 2022 13:19:39 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id DDF1F42540; Sat, 2 Jul 2022 03:19:37 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org DDF1F42540 Authentication-Results: smtp4.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=mbXnMcdQ X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xknYbkrITduE; Sat, 2 Jul 2022 03:19:36 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id 37B5442535; Sat, 2 Jul 2022 03:19:35 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 37B5442535 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 01BB7C0035; Sat, 2 Jul 2022 03:19:35 +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 2B989C0039 for ; Sat, 2 Jul 2022 03:19:34 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id DB96F418CF for ; Sat, 2 Jul 2022 03:19:06 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org DB96F418CF X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id c4P7csnGtUQm for ; Sat, 2 Jul 2022 03:19:05 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 574F7416BC Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2048.outbound.protection.outlook.com [40.107.220.48]) by smtp4.osuosl.org (Postfix) with ESMTPS id 574F7416BC for ; Sat, 2 Jul 2022 03:19:05 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DonpKTzSB2TE5138MY56FmphGQ/PDJW7sP2twS0+w0WdIM9ohhsyiWJWrSX2VnjZCIk5VavjnPTi8MG378MnNCQ8670Rhf1HghiF3/NugqnPn+UW3puzPn9RL5QAVWfA9JU0do5TatbbhM8cCsXPEE/xbHruXN35al31Bu6zsgoMWUsfmv90SyTFwVX0sAA+7Rnm0Z5/c1sP2jOBpaFT8OI18do/hj9U0qJLi2B4PnGzdkoAKuolJ//p/4//TYcTNpe3IephemmrMJPqZznMl+B08os141pm1mzhPcJxSFk02VgHMTDV3pezkHzXovho19u/E7Mk+fuR1ATyElN7+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=Qd9WsEGtOFmDEWHWTl2NI2gMvF953sN1goam1O/k/kk=; b=Fde97xMeIqi9ZpBq0H2jUsDFiw4wK2kuFtKKOiA2z8tphphYuhkOVRqnez5EW+buqta6GehWW0uv2dsa1XHF87zUrHTT5Oy2MHtH/eRwOTWjk0f/4mhIozDwQxI3HB22hxHJwzHcFFwPGrcA/1wzt5vg7mcXoGjuU93gKZ76kXuuy6+KdRYPPFbNl1DXe0FsLC4pnpm1ofUqzbdmmZBZI0m3dyhA6MN6+MWkgMME6xutamiRI7A0EG3q5buocRNJ7b3Db+nxGgmAoYFcsinEx87Ub3vq24KIhNS7qtv3s6a1XmEs23zGyDt6uBAHKZrY+csrCFMMK/yei7GXTykDsA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=corigine.com 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 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=Qd9WsEGtOFmDEWHWTl2NI2gMvF953sN1goam1O/k/kk=; b=mbXnMcdQoxSlzCPnxwu8WZ5RuG97n5xGLgNJ01r1vMRoNYsJ9MFVGAQZ2V7N3aEWdP/v9vor9y2iAmlLZw8fT8I0ScyX+Xpr4HJpj9ZYsMCpU2QdrkkrlmmmW1tVfEMTWf4BRQjWh8hU4p5NtLmB55SAZLkRQGv823NnHvXaaaC/IQvQ4eDKRLr0Lr92+9LoJ/lPF8FTA9HoRYHuJ5Be/S79hY4w4Y9tkgf1riAcpWrTmHE9TS4NL/ppbSnlHkVray18PrXBbt+M8REsb9re4X/2mgm5WHPLxIQyP7XRj9emvH0WZmqxk4FlNfqb0KOAlLLi63V+plZxOvrKPX9XQg== Received: from DM6PR08CA0015.namprd08.prod.outlook.com (2603:10b6:5:80::28) by MW3PR12MB4441.namprd12.prod.outlook.com (2603:10b6:303:59::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.17; Sat, 2 Jul 2022 03:18:56 +0000 Received: from DM6NAM11FT011.eop-nam11.prod.protection.outlook.com (2603:10b6:5:80:cafe::9c) by DM6PR08CA0015.outlook.office365.com (2603:10b6:5:80::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.17 via Frontend Transport; Sat, 2 Jul 2022 03:18:56 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) 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 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.238) by DM6NAM11FT011.mail.protection.outlook.com (10.13.172.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5395.17 via Frontend Transport; Sat, 2 Jul 2022 03:18:56 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Sat, 2 Jul 2022 03:18:55 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Fri, 1 Jul 2022 20:18:55 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Fri, 1 Jul 2022 20:18:53 -0700 To: , , , , , Date: Sat, 2 Jul 2022 03:18:30 +0000 Message-ID: <20220702031832.13282-8-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220702031832.13282-1-jianbol@nvidia.com> References: <20220702031832.13282-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5c9c61fc-0b0f-411d-e786-08da5bd99957 X-MS-TrafficTypeDiagnostic: MW3PR12MB4441:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Sp0TYqrxF/lt8U5yZefDkphBOHsQzjMyfOnhxn63LBS/60+UlIJgZlR6i2CMrUO2aTNbc7+ZWftGciNOONvMFa9ng5uzHCv9liLuyVDRS2op0ajL+7NONWimH4v1wpuEtjXS9LE9YN/XyNjTNfu8iykCQAN2CCNnRcf+8rp76sNQQ4ZvQbh46I0mpRMGZZcs0VHz3+mZZ9vjse4F872BKQLRSbyeJUnjO5pSSD1EAfP30EpqWWWzaYsX8H48prmiKfc3VAT0QX8lnyWKQu5KXxfWsVUY6Aes/TuGlDdkCyi882tH/uZiJKZit9tKKvvnzkzKpovY4Uvwpw953qylgTGTQL+NL+0H3TnY8LS96v+7KbgvLaC+HXiAPHkQbGufkuadkw1ScdMdtL2aHKQnppA3CbpucSlhv9MMnSAyCLzkImB7tX1myrrtjCI/Zy6xomb0itXRoKBsGkoCq5TQd20sDVDtrBNrVMxWnpzf8PyvMxHTFWjBxzYYfZlApRBhO287Jfe5aHE3xNRqqEBNt8Dx8H/2yjslM3q78o8DGQbHCzmU+sAi/t3/h8bggJq3qSvLqRk2KmFFCykp0RLmT0Vh8zsQOJVMUNDrMdw7b6MJiL4o3U4C4gta8EZTnwxI3F7E2zRs0YkfnbEU2l0jgikifoUUB/5ufDcw7c54rGQZUpwNXCRWtJCn8xit6zMJ0viSvNZiqnxBh0bLREU6tlp/jXxhMMYTwO4vh3FF2XZ4mBU8ZEVQ4KpOhib4h7psTG5/kw2H7p2Q5/QFg1xUPntF8tkFGcXo5NiHNgC9/oYJsmnbAvHeCMNN+yvle4GjowSEL0GAdieOcvbbL/nGOazECbKOGz5aq2Z0u4rAcgM= X-Forefront-Antispam-Report: CIP:12.22.5.238; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230016)(4636009)(136003)(39860400002)(396003)(346002)(376002)(46966006)(40470700004)(36840700001)(82740400003)(5660300002)(426003)(356005)(1076003)(47076005)(81166007)(26005)(8936002)(7696005)(478600001)(83380400001)(186003)(107886003)(2616005)(6666004)(336012)(41300700001)(36860700001)(2906002)(40460700003)(316002)(40480700001)(82310400005)(70206006)(70586007)(36756003)(86362001)(4326008)(8676002)(110136005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jul 2022 03:18:56.3958 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5c9c61fc-0b0f-411d-e786-08da5bd99957 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.238]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT011.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4441 Cc: Jianbo Liu Subject: [ovs-dev] [v6 7/9] netdev-offload-tc: Offloading rules with police actions X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jianbo Liu via dev From: Jianbo Liu Reply-To: Jianbo Liu Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" When offloading rule, tc should be filled with police index, instead of meter id. As meter is mapped to police action, and the mapping is inserted into meter_id_to_police_idx hmap, this hmap is used to find the police index. Besides, the reverse mapping between meter id and police index is also added, so meter id can be retrieved from this hashmap and pass to dpif while dumping rules. Signed-off-by: Jianbo Liu Acked-by: Eelco Chaudron --- lib/netdev-offload-tc.c | 47 ++++++++++++++++++++++++++++++++++++++++- lib/tc.c | 20 +++++++++++++++++- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c index 7de51a6e0..3d53c82dd 100644 --- a/lib/netdev-offload-tc.c +++ b/lib/netdev-offload-tc.c @@ -66,6 +66,7 @@ struct chain_node { struct meter_police_mapping_data { struct hmap_node meter_id_node; + struct hmap_node police_idx_node; uint32_t meter_id; uint32_t police_idx; }; @@ -84,6 +85,11 @@ static struct id_pool *meter_police_ids OVS_GUARDED_BY(meter_police_ids_mutex); static struct ovs_mutex meter_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) + = HMAP_INITIALIZER(&police_idx_to_meter_id); + +static int meter_id_lookup(uint32_t meter_id, uint32_t *police_idx); +static int police_idx_lookup(uint32_t police_idx, uint32_t *meter_id); static bool is_internal_port(const char *type) @@ -1041,7 +1047,12 @@ parse_tc_flower_to_match(struct tc_flower *flower, } break; case TC_ACT_POLICE: { - /* Not supported yet */ + uint32_t meter_id; + + if (police_idx_lookup(action->police.index, &meter_id)) { + return ENOENT; + } + nl_msg_put_u32(buf, OVS_ACTION_ATTR_METER, meter_id); } break; } @@ -1964,6 +1975,16 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, action->type = TC_ACT_GOTO; action->chain = 0; /* 0 is reserved and not used by recirc. */ flower.action_count++; + } else if (nl_attr_type(nla) == OVS_ACTION_ATTR_METER) { + uint32_t police_index, meter_id; + + meter_id = nl_attr_get_u32(nla); + if (meter_id_lookup(meter_id, &police_index)) { + return EOPNOTSUPP; + } + action->type = TC_ACT_POLICE; + action->police.index = police_index; + flower.action_count++; } else { VLOG_DBG_RL(&rl, "unsupported put action type: %d", nl_attr_type(nla)); @@ -2443,6 +2464,27 @@ meter_id_lookup(uint32_t meter_id, uint32_t *police_idx) return data ? 0 : ENOENT; } +static int +police_idx_lookup(uint32_t police_idx, uint32_t *meter_id) +{ + struct meter_police_mapping_data *data; + size_t hash = hash_int(police_idx, 0); + int err = ENOENT; + + ovs_mutex_lock(&meter_mutex); + HMAP_FOR_EACH_WITH_HASH (data, police_idx_node, hash, + &police_idx_to_meter_id) { + if (data->police_idx == police_idx) { + *meter_id = data->meter_id; + err = 0; + break; + } + } + ovs_mutex_unlock(&meter_mutex); + + return err; +} + static void meter_id_insert(uint32_t meter_id, uint32_t police_idx) { @@ -2454,6 +2496,8 @@ meter_id_insert(uint32_t meter_id, uint32_t police_idx) data->police_idx = police_idx; hmap_insert(&meter_id_to_police_idx, &data->meter_id_node, hash_int(meter_id, 0)); + hmap_insert(&police_idx_to_meter_id, &data->police_idx_node, + hash_int(police_idx, 0)); ovs_mutex_unlock(&meter_mutex); } @@ -2466,6 +2510,7 @@ meter_id_remove(uint32_t meter_id) data = meter_id_find_locked(meter_id); if (data) { hmap_remove(&meter_id_to_police_idx, &data->meter_id_node); + hmap_remove(&police_idx_to_meter_id, &data->police_idx_node); free(data); } ovs_mutex_unlock(&meter_mutex); diff --git a/lib/tc.c b/lib/tc.c index 74e2d6caf..392dee632 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -2444,6 +2444,22 @@ nl_msg_put_act_gact(struct ofpbuf *request, uint32_t chain) nl_msg_end_nested(request, offset); } +static void +nl_msg_put_act_police_index(struct ofpbuf *request, uint32_t police_idx) +{ + struct tc_police police; + size_t offset; + + memset(&police, 0, sizeof police); + police.index = police_idx; + + nl_msg_put_string(request, TCA_ACT_KIND, "police"); + offset = nl_msg_start_nested(request, TCA_ACT_OPTIONS); + nl_msg_put_unspec(request, TCA_POLICE_TBF, &police, sizeof police); + nl_msg_put_u32(request, TCA_POLICE_RESULT, TC_ACT_PIPE); + nl_msg_end_nested(request, offset); +} + static void nl_msg_put_act_ct(struct ofpbuf *request, struct tc_action *action) { @@ -2934,7 +2950,9 @@ nl_msg_put_flower_acts(struct ofpbuf *request, struct tc_flower *flower) } break; case TC_ACT_POLICE: { - /* Not supported yet */ + act_offset = nl_msg_start_nested(request, act_index++); + nl_msg_put_act_police_index(request, action->police.index); + nl_msg_end_nested(request, act_offset); } break; } From patchwork Sat Jul 2 03:18:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianbo Liu X-Patchwork-Id: 1651425 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=mz9wY0Fu; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LZckG1kzbz9ryY for ; Sat, 2 Jul 2022 13:19:33 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id A2D5A8482F; Sat, 2 Jul 2022 03:19:31 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org A2D5A8482F Authentication-Results: smtp1.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=mz9wY0Fu X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id byfZwBIE9Cq8; Sat, 2 Jul 2022 03:19:30 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id 64D5884846; Sat, 2 Jul 2022 03:19:29 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org 64D5884846 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 36DFBC002D; Sat, 2 Jul 2022 03:19:29 +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 233CFC002D for ; Sat, 2 Jul 2022 03:19:28 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 758AC416EA for ; Sat, 2 Jul 2022 03:19:05 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 758AC416EA Authentication-Results: smtp4.osuosl.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=mz9wY0Fu X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id f_3JxWUY81MH for ; Sat, 2 Jul 2022 03:19:04 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org EEC204245B Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) by smtp4.osuosl.org (Postfix) with ESMTPS id EEC204245B for ; Sat, 2 Jul 2022 03:19:03 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Xtvd9um/ebuxCHp8VZnJXswb2Pl3LV/Fzct/1heCZsSEDsnMBMy1/ayD/eE5+HQerRBSkfVdZHraKeFQh8i8iQ0B422SBPVrUG1+hRoPSURmEATLo9yxiFYvV3P2p2j/Vzqf0h7kmf4O7zr0do3aXgMWflWGkAa30zIhEJuZk+371wQPhTY1NWzLk71k/clOG+btuzHv+cAXPTQzAOEESQMQiKQ+v3icKP3Rt07p/t6Wo7/Eq1XlBdJpEumwNI+hMpqmrrCWsvRIwNIVia+ssvhNZbh7ezgMavUOuhg24lVJEww2BTz+GJOc1IU1X0FMDnGMPHgLECd7JKHLxoK90g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=D4gPFHewWD6hzTrxJwjwMISTbcD6fAbeOvpOpSIFKfs=; b=MnPH4mF53kWi2ROMA3Kz08Gh/m3cWlZLB4u3/LNuBFL/aCUd91+PHv3fNC0VNbovAEa9hyL1w0hbAfM4AbDuyv24yunxgx65KRbUqpCYNS7rC41qMHBqapS268P1L3rAY7m/qnbZpjFTLYi7GnQ1sXquzHfsIskCRiA73Ph/zkcBsUNgCHnshc+lpfBC9RUUmAbZKdrt+ANcCxeE6jS7rca7qiOFRFfV8yrEFuQ4tl62tV6whoFLlD9wy4p2j3pTBeugwEvStZM2Ml08yq7AP6Rd/HTVEu2Xqi0+sdeKqjzkdYyqXhIWlR1joVSwS6xSF1yGdoDi2gXcA37LhIqnsQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.236) smtp.rcpttodomain=corigine.com 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 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=D4gPFHewWD6hzTrxJwjwMISTbcD6fAbeOvpOpSIFKfs=; b=mz9wY0FuSrFEKHeKzanzUpFW6zIFj5AhJsLYbb8JQhOKzh+uHFS8f71PnclON5Byoa9VhT6hz9rcRW9IeOAXgLTETMTkg4o1CUmcfXCC3oH8UZFeKjE7atcXyr2wGCfuz1Ti5XhWjAJb/sEOLjboWbG+68UKtKO7Z7fUB76bJLmRwDdEZT0hEwH9KYFyM79Gp6o3Obb6AIBjHOJgPk7fBpZqp1iCkZuzLWziJvveAV/9YNWWE1Idwi4TB8rmRMzU8kUSDJh5ghjH17KZ6n1hM08DDp4wsnbFJom/yzb5YxXJIc8FPqTQ3fosWCkD56/K3BhQAtrmDOREXos8hKAQLw== Received: from DM6PR05CA0056.namprd05.prod.outlook.com (2603:10b6:5:335::25) by BY5PR12MB4068.namprd12.prod.outlook.com (2603:10b6:a03:203::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.15; Sat, 2 Jul 2022 03:18:59 +0000 Received: from DM6NAM11FT010.eop-nam11.prod.protection.outlook.com (2603:10b6:5:335:cafe::1b) by DM6PR05CA0056.outlook.office365.com (2603:10b6:5:335::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.14 via Frontend Transport; Sat, 2 Jul 2022 03:18:59 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.236) 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 12.22.5.236 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.236; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.236) by DM6NAM11FT010.mail.protection.outlook.com (10.13.172.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5395.14 via Frontend Transport; Sat, 2 Jul 2022 03:18:59 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Sat, 2 Jul 2022 03:18:58 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Fri, 1 Jul 2022 20:18:57 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Fri, 1 Jul 2022 20:18:55 -0700 To: , , , , , Date: Sat, 2 Jul 2022 03:18:31 +0000 Message-ID: <20220702031832.13282-9-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220702031832.13282-1-jianbol@nvidia.com> References: <20220702031832.13282-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b9ac8459-4c18-4740-6f02-08da5bd99aeb X-MS-TrafficTypeDiagnostic: BY5PR12MB4068:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +x4QIPgzckp1LjkDu4ZaEQRtwhqx/3issoi2cj9ocDy7t4v44Vh/zj3Nuxv7KcTjKNM3xQCea7UDM9A24TNvtHqcwufgSW8RR0zQPP0zO5/D0n13UDpi0M4j90nL1UNPGpDJ2XOKbaSim1+jBpioyZvwfbPpvyro8e46G6/q6CFOYEJgefx74eTIO3U0QDUxoDLByGOSC65Y5bcTE2g73cBoL5O3gT5A/rbDJyLYaioPOMz79BkKrzXlSoS0S7Q61PsI8cZW5wGC8fb/fDlCW96N6b0AsiOgMZD+az+nro1Ce9bxduIPnKQmvsi7VKSM6G9FIx716pOYyaPnkBdUjjSISXyFRnojTzMXQHw7wnakLcfeJBbXhchuUx4ELZq0z9/ah3TUSdPf0nJLLpivP8zQ6NDDsZD/758dkIzYVGDSRtYuLVxzRwCiDQK0S/iFpbbbT+IzkZ8Pu+Bc/5M5PyAkdhUt2VuEUTWL4jr4w/T1zmBNVtD8nnHJkJCZtDXunv4z5KpBRPvynH1ptOwdGrX5l1iK5l4ZJmzIl26CWzNb4GbURkfruLmWQjagdbIFyb1dlvJicMfV8FFAQqHkPVP6z7v1GBYEA2T/nAqwmgkEurXoMdfwLj1IClBDxHcdtDVfFlkZjMhYB02GrODIKu6jGHSHkc38Nh72IyGEA0YCCyftZoBnbR7IfhHErRR7lXHkSqV9U/KocxwujkSUryeqneZaYoU/m9oFIlf9aE2CNPXvbu8lnByqJXVdtIxg3gX3SnelMqlRkpUydmJAnGpklsHR5iqJ1WyDE3ZlufaaXYOWvbCNAwLVKbCmb86cncaiCoAO/aiL4k6Egng3aTKJLSB6WBPVEfa12Q+H3hk= X-Forefront-Antispam-Report: CIP:12.22.5.236; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230016)(4636009)(376002)(136003)(39860400002)(396003)(346002)(40470700004)(36840700001)(46966006)(2616005)(47076005)(186003)(336012)(1076003)(426003)(7696005)(26005)(5660300002)(107886003)(86362001)(40480700001)(6666004)(41300700001)(82740400003)(356005)(40460700003)(81166007)(82310400005)(4326008)(8676002)(36860700001)(70206006)(36756003)(316002)(83380400001)(8936002)(2906002)(110136005)(70586007)(478600001)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jul 2022 03:18:59.0404 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b9ac8459-4c18-4740-6f02-08da5bd99aeb X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.236]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT010.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4068 Cc: Jianbo Liu Subject: [ovs-dev] [v6 8/9] dpif-netlink: Offloading meter to tc police action X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jianbo Liu via dev From: Jianbo Liu Reply-To: Jianbo Liu Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" OVS meters are created in advance and openflow rules refer to them by their unique ID. New tc_police API is used to offload them. By calling the API, police actions are created and meters are mapped to them. These actions then can be used in tc filter rules by the index. Signed-off-by: Jianbo Liu --- NEWS | 2 + lib/dpif-netlink.c | 31 ++++++++-- tests/system-offloads-traffic.at | 98 ++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 994fdf6a9..6e07ef08c 100644 --- a/NEWS +++ b/NEWS @@ -43,6 +43,8 @@ Post-v2.17.0 * 'dpif-netdev/subtable-lookup-prio-get' appctl command renamed to 'dpif-netdev/subtable-lookup-info-get' to better reflect its purpose. The old variant is kept for backward compatibility. + - Linux datapath: + * Add offloading meter tc police. v2.17.0 - 17 Feb 2022 diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index 06e1e8ca0..a498d5667 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -4163,11 +4163,18 @@ static int dpif_netlink_meter_set(struct dpif *dpif_, ofproto_meter_id meter_id, struct ofputil_meter_config *config) { + int err; + if (probe_broken_meters(dpif_)) { return ENOMEM; } - return dpif_netlink_meter_set__(dpif_, meter_id, config); + err = dpif_netlink_meter_set__(dpif_, meter_id, config); + if (!err && netdev_is_flow_api_enabled()) { + meter_offload_set(meter_id, config); + } + + return err; } /* Retrieve statistics and/or delete meter 'meter_id'. Statistics are @@ -4258,16 +4265,30 @@ static int dpif_netlink_meter_get(const struct dpif *dpif, ofproto_meter_id meter_id, struct ofputil_meter_stats *stats, uint16_t max_bands) { - return dpif_netlink_meter_get_stats(dpif, meter_id, stats, max_bands, - OVS_METER_CMD_GET); + int err; + + err = dpif_netlink_meter_get_stats(dpif, meter_id, stats, max_bands, + OVS_METER_CMD_GET); + if (!err && netdev_is_flow_api_enabled()) { + meter_offload_get(meter_id, stats); + } + + return err; } static int dpif_netlink_meter_del(struct dpif *dpif, ofproto_meter_id meter_id, struct ofputil_meter_stats *stats, uint16_t max_bands) { - return dpif_netlink_meter_get_stats(dpif, meter_id, stats, max_bands, - OVS_METER_CMD_DEL); + int err; + + err = dpif_netlink_meter_get_stats(dpif, meter_id, stats, + max_bands, OVS_METER_CMD_DEL); + if (!err && netdev_is_flow_api_enabled()) { + meter_offload_del(meter_id, stats); + } + + return err; } static bool diff --git a/tests/system-offloads-traffic.at b/tests/system-offloads-traffic.at index 80bc1dd5c..47dfdb8e9 100644 --- a/tests/system-offloads-traffic.at +++ b/tests/system-offloads-traffic.at @@ -168,3 +168,101 @@ matchall ]) OVS_TRAFFIC_VSWITCHD_STOP AT_CLEANUP + +AT_SETUP([offloads - check interface meter offloading ]) +AT_KEYWORDS([offload-meter]) +AT_SKIP_IF([test $SUPPORT_TC_INGRESS_PPS = "no"]) +OVS_TRAFFIC_VSWITCHD_START() + +AT_CHECK([ovs-vsctl set Open_vSwitch . other_config:hw-offload=true]) +AT_CHECK([ovs-ofctl -O OpenFlow13 add-meter br0 'meter=1 pktps bands=type=drop rate=1']) + +ADD_NAMESPACES(at_ns0, at_ns1) +ADD_VETH(p0, at_ns0, br0, "10.1.1.1/24", "f0:00:00:01:01:01") +ADD_VETH(p1, at_ns1, br0, "10.1.1.2/24", "f0:00:00:01:01:02") + +NS_CHECK_EXEC([at_ns0], [ip neigh add 10.1.1.2 lladdr f0:00:00:01:01:02 dev p0]) +NS_CHECK_EXEC([at_ns1], [ip neigh add 10.1.1.1 lladdr f0:00:00:01:01:01 dev p1]) + +AT_CHECK([ovs-ofctl -O OpenFlow13 add-flow br0 "actions=normal"]) +NS_CHECK_EXEC([at_ns0], [ping -q -c 10 -i 0.1 -w 2 10.1.1.2 | FORMAT_PING], [0], [dnl +10 packets transmitted, 10 received, 0% packet loss, time 0ms +]) + +NETNS_DAEMONIZE([at_ns1], [nc -u -l 5678 > /dev/null ], [nc0.pid]) + +AT_CHECK([ovs-ofctl -O OpenFlow13 del-flows br0]) +AT_CHECK([ovs-ofctl -O OpenFlow13 add-flow br0 "priority=10,in_port=ovs-p0,udp actions=meter:1,normal"]) +AT_CHECK([ovs-ofctl -O OpenFlow13 add-flow br0 "priority=1 actions=normal"]) + +NS_CHECK_EXEC([at_ns0], [echo "mark" | nc -u 10.1.1.2 5678 -p 6789]) +AT_CHECK([ovs-appctl dpctl/dump-flows | grep "meter" | DUMP_CLEAN_SORTED], [0], [dnl +in_port(2),eth(macs),eth_type(0x0800),ipv4(proto=17,frag=no), packets:0, bytes:0, used:0.001s, actions:outputmeter(0),3 +]) + +sleep 1 + +for i in `seq 10`; do +NS_CHECK_EXEC([at_ns0], [echo "mark" | nc -u 10.1.1.2 5678 -p 6789]) +done + +AT_CHECK([ovs-appctl dpctl/dump-flows | grep "meter" | DUMP_CLEAN_SORTED], [0], [dnl +in_port(2),eth(macs),eth_type(0x0800),ipv4(proto=17,frag=no), packets:10, bytes:330, used:0.001s, actions:outputmeter(0),3 +]) + +AT_CHECK([ovs-ofctl -O OpenFlow13 meter-stats br0 | sed -e 's/duration:[[0-9]].[[0-9]]*s/duration:0.001s/'], [0], [dnl +OFPST_METER reply (OF1.3) (xid=0x2): +meter:1 flow_count:1 packet_in_count:11 byte_in_count:377 duration:0.001s bands: +0: packet_count:9 byte_count:0 +]) + +OVS_TRAFFIC_VSWITCHD_STOP +AT_CLEANUP + +AT_SETUP([unoffload meter - Check DP meter ]) +AT_KEYWORDS([dp-meter]) +OVS_TRAFFIC_VSWITCHD_START() + +AT_CHECK([ovs-ofctl -O OpenFlow13 add-meter br0 'meter=1 pktps bands=type=drop rate=1']) + +ADD_NAMESPACES(at_ns0, at_ns1) +ADD_VETH(p0, at_ns0, br0, "10.1.1.1/24", "f0:00:00:01:01:01") +ADD_VETH(p1, at_ns1, br0, "10.1.1.2/24", "f0:00:00:01:01:02") + +NS_CHECK_EXEC([at_ns0], [ip neigh add 10.1.1.2 lladdr f0:00:00:01:01:02 dev p0]) +NS_CHECK_EXEC([at_ns1], [ip neigh add 10.1.1.1 lladdr f0:00:00:01:01:01 dev p1]) + +AT_CHECK([ovs-ofctl -O OpenFlow13 add-flow br0 "actions=normal"]) +NS_CHECK_EXEC([at_ns0], [ping -q -c 10 -i 0.1 -w 2 10.1.1.2 | FORMAT_PING], [0], [dnl +10 packets transmitted, 10 received, 0% packet loss, time 0ms +]) + +NETNS_DAEMONIZE([at_ns1], [nc -u -l 5678 > /dev/null ], [nc0.pid]) + +AT_CHECK([ovs-ofctl -O OpenFlow13 del-flows br0]) +AT_CHECK([ovs-ofctl -O OpenFlow13 add-flow br0 "priority=10,in_port=ovs-p0,udp actions=meter:1,normal"]) +AT_CHECK([ovs-ofctl -O OpenFlow13 add-flow br0 "priority=1 actions=normal"]) + +NS_CHECK_EXEC([at_ns0], [echo "mark" | nc -u 10.1.1.2 5678 -p 6789]) +AT_CHECK([ovs-appctl dpctl/dump-flows | grep "meter" | DUMP_CLEAN_SORTED], [0], [dnl +in_port(2),eth(macs),eth_type(0x0800),ipv4(proto=17,frag=no), packets:0, bytes:0, used:never, actions:outputmeter(0),3 +]) + +sleep 1 + +for i in `seq 10`; do +NS_CHECK_EXEC([at_ns0], [echo "mark" | nc -u 10.1.1.2 5678 -p 6789]) +done + +AT_CHECK([ovs-appctl dpctl/dump-flows | grep "meter" | DUMP_CLEAN_SORTED], [0], [dnl +in_port(2),eth(macs),eth_type(0x0800),ipv4(proto=17,frag=no), packets:10, bytes:470, used:0.001s, actions:outputmeter(0),3 +]) + +AT_CHECK([ovs-ofctl -O OpenFlow13 meter-stats br0 | sed -e 's/duration:[[0-9]].[[0-9]]*s/duration:0.001s/'], [0], [dnl +OFPST_METER reply (OF1.3) (xid=0x2): +meter:1 flow_count:1 packet_in_count:11 byte_in_count:517 duration:0.001s bands: +0: packet_count:9 byte_count:423 +]) + +OVS_TRAFFIC_VSWITCHD_STOP +AT_CLEANUP From patchwork Sat Jul 2 03:18:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianbo Liu X-Patchwork-Id: 1651427 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=t7cLDBii; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LZckR1r8Lz9ryY for ; Sat, 2 Jul 2022 13:19:43 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 30B3F60F60; Sat, 2 Jul 2022 03:19:41 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 30B3F60F60 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=t7cLDBii X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FjAGz9PwTfv0; Sat, 2 Jul 2022 03:19:40 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id 75B7B614D0; Sat, 2 Jul 2022 03:19:38 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 75B7B614D0 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 65756C0083; Sat, 2 Jul 2022 03:19:37 +0000 (UTC) X-Original-To: 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 20420C007B for ; Sat, 2 Jul 2022 03:19:35 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 74C6D61471 for ; Sat, 2 Jul 2022 03:19:06 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 74C6D61471 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 16ttfIemPuLO for ; Sat, 2 Jul 2022 03:19:05 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org A1B2F60FEF Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2071.outbound.protection.outlook.com [40.107.223.71]) by smtp3.osuosl.org (Postfix) with ESMTPS id A1B2F60FEF for ; Sat, 2 Jul 2022 03:19:04 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ioCnU71UGVajrTIsjs0KxqCKeqHxdywkhVUhqkgHaheL3f1oocJmalIOuknPwYG48v42zhQ5XnT+crLhRxV7wuiCeW1Wn8sEbjxgLsqiCWkhW4OQ3znvt8ob15+S2IZDBPNZMTi4bgUxah4LF6aoUyoHZuCv3ajR22jFXXVMCAzMsXX78zqpEHa+FBhUrfAqtdJw9lByic0NWK4olYr4MJuKISjS91w4Zil6Hi0bRdWbXQNSrKmy7W1V8wKYp1pYDbiTIKFnvYh+TeM+KSTcx3XvWnm/xXDWX3N2IQ/z9MELVbk0gvafOmE0ku5HfzGL/BNo1SGDqcxniesXvCNkCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=+Uh4MPqEz1RQrKoTYdG+8pwNXZaukZ3FBe3mkfRJLng=; b=nG2kgxbgKrK2KXEGJ3x4+DSV7MolO9GGH6tlIdeWqrym1XhX0Dc6nJw3RjlMoBVs7Kj+7AoicFy5SarJNHyC5T9Bls2Scr9n4g3drb+reWgbg1Qcz41UROTvf6rO2yJh0Ik2OFzMYB9F82OskWoPz199rx35J4loW9dlplaIcAcFCc9FPa444D8skj7azFiqrQYCidTJBo+Nr4Tl6z88bPBykubZqffjtGXcgcsrFSGdhuq55mmmqUWY0BZ7b8Tur0aXhM/76+zYNCNTNfOcePUSOiIpozUPCTeFex+GUgv96S8Nu+X3cp0KW2j0AHznPLoKduPb5ikTP4l30d/tMQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.235) smtp.rcpttodomain=corigine.com 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 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=+Uh4MPqEz1RQrKoTYdG+8pwNXZaukZ3FBe3mkfRJLng=; b=t7cLDBiim/vloUFuoHe4NTIln9gaSoUEsa8K4RXrW0DBM8R+OROp5AAkqANh5iRhHfKqm81bmL/obnO2SfmYKU8xJgBgI86NuvfztSfWjBePEKZvkHNeIy603exPMpo46hrS/tCJiIMVYagZBOoc6LxwLNbMi7pnYzZArY80tClX2CxpCInvoaTgVITgQwGWxZ8liTfeLp31D9kH8FOdv7kszr968xbq+kiT/suwtT/SEyFAYE51Kxjryov09z0M4+iSiAQHZZlVaVnogY2WqKhc4Pd0bShFvrxWjYf0+SbIfggyQVvClc20fDPglpyK0FqW3Mc82B6g7PPhlJlm8Q== Received: from MW4PR04CA0090.namprd04.prod.outlook.com (2603:10b6:303:6b::35) by MWHPR12MB1151.namprd12.prod.outlook.com (2603:10b6:300:e::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.14; Sat, 2 Jul 2022 03:19:02 +0000 Received: from CO1NAM11FT039.eop-nam11.prod.protection.outlook.com (2603:10b6:303:6b:cafe::d0) by MW4PR04CA0090.outlook.office365.com (2603:10b6:303:6b::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.15 via Frontend Transport; Sat, 2 Jul 2022 03:19:01 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235) 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 12.22.5.235 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.235; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.235) by CO1NAM11FT039.mail.protection.outlook.com (10.13.174.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5395.14 via Frontend Transport; Sat, 2 Jul 2022 03:19:01 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Sat, 2 Jul 2022 03:19:01 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Fri, 1 Jul 2022 20:19:00 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Fri, 1 Jul 2022 20:18:58 -0700 To: , , , , , Date: Sat, 2 Jul 2022 03:18:32 +0000 Message-ID: <20220702031832.13282-10-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220702031832.13282-1-jianbol@nvidia.com> References: <20220702031832.13282-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5c3aa801-c145-492e-4f90-08da5bd99c6d X-MS-TrafficTypeDiagnostic: MWHPR12MB1151:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3P9hdCno7lcCOlA5mkW8HebTnOmxoWM0ESnYND5I2fddHAEjXAYHxm/gAg6sDIPhhL2xlFjd6oX8RL0GFUC+/6zOZZ9FstyPS73yorqksaEACsIi8L9RN5v4s8xQfOExtNEccY5Ljq8ldXWGVuVbGeShyAMRcclqBrVi0zUZz9MJBOPqbpz17tOnc+qmc9nBt3tPu6rjQ+rjalAbxxBWk7p18pQJqoz/G3Fe38doYrS3nHtneneLuiTrqzTxh1L6d5wTAzvRSXuWbI3RFCDoCBuWFE2tLpyCYpfxUT5JKBNHr0FRQGMlXyHOp+iMhJnJYLZw/KqITXKyQ7WLSpyfnbJl1IC4pKXmhq+VwsRPtpxxYnneGP43p5w1SnAWsSwTqnL99+AgyMzCOYtGRMs1kdcR25ELd0cNvQZuJfSpnuAMpE+hXvyBtjl/wDbrLZhs8FSy4SLZxeWXunv3sxpGyStJ4NtAPwxNUycrEzUuJYaFrsL/bFffHjNDDnS7iT/uehg9CUQcHbRBe3UvjzpF/4ycFKryxP+wWMoWT+ttxebX4Z53Awk5n4hqmx9WE/n8oD8dlI4Q+v0UnyroGhTDSDjxbVUByvxTT8KW7UDKPTS+BNAP9ffcJXmLC2C5b3+OpkDPHoo24b2QO/2C5VuNQ6HWDFZlubzhlaEF2oC1ABNn7bkP0KkX10hhc0IrU5ieBoy+dpdwjc99Ss8hhZefL21/JOYt0lyHEfKmpOOUCPIIQAt7sVAySelVNDsB15YjSXL+nm4mTKMt1rHi69249FfeswYNdOiUnJNN5XgyTe1qacROc8lS5kM/JfNwuHp8mcA1NEZ+bDPMFX4t4X1HLWQca3VFJ6Ghpl306nOxF5Tvbol52hNNRzYXMct6QXwvojyweJQxY0s7HgvUOt2JGHjutxkKD5XIsljUx0hllw68VqwdTe/1vX9jwdapvUoU X-Forefront-Antispam-Report: CIP:12.22.5.235; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230016)(4636009)(136003)(346002)(39860400002)(376002)(396003)(46966006)(40470700004)(36840700001)(7696005)(82740400003)(81166007)(82310400005)(356005)(2906002)(6666004)(186003)(41300700001)(83380400001)(40480700001)(2616005)(47076005)(26005)(426003)(70586007)(107886003)(8676002)(36756003)(86362001)(966005)(5660300002)(70206006)(4326008)(478600001)(8936002)(336012)(40460700003)(1076003)(110136005)(36860700001)(316002)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jul 2022 03:19:01.5224 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5c3aa801-c145-492e-4f90-08da5bd99c6d X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.235]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT039.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1151 Cc: Jianbo Liu Subject: [ovs-dev] [v6 9/9] doc: Add meter offload topic document X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jianbo Liu via dev From: Jianbo Liu Reply-To: Jianbo Liu Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Fow now, add introduction and the limitation of meter offload. Signed-off-by: Jianbo Liu --- Documentation/automake.mk | 1 + Documentation/howto/index.rst | 1 + Documentation/howto/tc-offload.rst | 75 ++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 Documentation/howto/tc-offload.rst diff --git a/Documentation/automake.mk b/Documentation/automake.mk index 6c2c57739..185349c14 100644 --- a/Documentation/automake.mk +++ b/Documentation/automake.mk @@ -79,6 +79,7 @@ DOC_SOURCE = \ Documentation/howto/vlan.png \ Documentation/howto/vlan.rst \ Documentation/howto/vtep.rst \ + Documentation/howto/tc-offload.rst \ Documentation/ref/index.rst \ Documentation/faq/index.rst \ Documentation/faq/configuration.rst \ diff --git a/Documentation/howto/index.rst b/Documentation/howto/index.rst index 60fb8a717..1812f6a11 100644 --- a/Documentation/howto/index.rst +++ b/Documentation/howto/index.rst @@ -49,4 +49,5 @@ OVS vtep sflow dpdk + tc-offload diff --git a/Documentation/howto/tc-offload.rst b/Documentation/howto/tc-offload.rst new file mode 100644 index 000000000..09a136264 --- /dev/null +++ b/Documentation/howto/tc-offload.rst @@ -0,0 +1,75 @@ +.. + Licensed under the Apache License, Version 2.0 (the "License"); you may + not use this file except in compliance with the License. You may obtain + a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + License for the specific language governing permissions and limitations + under the License. + + Convention for heading levels in Open vSwitch documentation: + + ======= Heading 0 (reserved for the title in a document) + ------- Heading 1 + ~~~~~~~ Heading 2 + +++++++ Heading 3 + ''''''' Heading 4 + + Avoid deeper levels because they do not render well. + +===================================== +Hardware offload with Linux TC flower +===================================== + +This document describes how to offload with TC flower. It is disabled by +default and can be enabled by:: + + $ ovs-vsctl set Open_vSwitch . other_config:hw-offload=true + +Offload meter to TC +------------------- + +After hardware offload is enabled, meter offload is enabled as well. + +Configuration +~~~~~~~~~~~~~ + +There is no parameter change in ovs-ofctl command, to configue a meter and use +it for a flow in the offload way. Usually the commands are like:: + + $ ovs-ofctl -O OpenFlow13 add-meter br0 "meter=1 pktps bands=type=drop rate=1" + $ ovs-ofctl -O OpenFlow13 add-flow br0 "priority=10,in_port=ovs-p0,udp actions=meter:1,normal" + +.. note:: + Each meter is mapped to one TC police action. To avovid the conflicton, the + police action index of 0x10000000-0x1fffffff are resevered for the mapping. + You can check the police actions by the command "tc action ls action police" + in Linux system. + +Dump meter statistics +--------------------- + +You can use ovs-ofctl to display the statisticsof meter:: + + $ ovs-ofctl -O OpenFlow13 meter-stats br0 + OFPST_METER reply (OF1.3) (xid=0x2): + meter:1 flow_count:1 packet_in_count:11 byte_in_count:377 duration:3.199s bands: + 0: packet_count:9 byte_count:0 + +The stats of the dropped packets is stored to band 0. + +.. note:: + Meter in OVS DP is not synced with the mapped poloce action, and the first + packet for DP learning does not pass TC police action, as the rule is not + offloaded yet. So, you may notice that packet_count of band 0 (for dropped + packets) is counted after the rule is offoalded, while packet_in_count is + summed with the numbers of packets of both DP and TC police action. + +.. note:: + Linux TC does not support the dropped bytes count, so the byte_count of band + 0 is always 0 if meter is offloaded. +