From patchwork Tue May 3 03:08: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: 1625294 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=e+5+tkCt; 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 4KslKh3Bwqz9sFx for ; Tue, 3 May 2022 13:08:56 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 4644760FBB; Tue, 3 May 2022 03:08:53 +0000 (UTC) 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 n9ITh32pTAWW; Tue, 3 May 2022 03:08:52 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp3.osuosl.org (Postfix) with ESMTPS id 1832760F18; Tue, 3 May 2022 03:08:51 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 24223C007F; Tue, 3 May 2022 03:08:50 +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 BF5F9C002D for ; Tue, 3 May 2022 03:08:47 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 9F68040123 for ; Tue, 3 May 2022 03:08:47 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp2.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=nvidia.com 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 ss8D6H0b4LCP for ; Tue, 3 May 2022 03:08:46 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on20606.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e88::606]) by smtp2.osuosl.org (Postfix) with ESMTPS id D652E400D9 for ; Tue, 3 May 2022 03:08:46 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z3UNbiinMPykTrvwhpFEQjUeuJCsbRKUtsbdfCGJrTq0IU4+bWgWT3A5Qjaa0Tr+4TSa88cueu2c6wyiF32WvrNfWoulbj8U86HYZUYMahXikwTR3WC02oq2Su94cDM/Avvhq6/zIg3+VKsEG4wgdN6umvKAf2DSfQpuSAizI+DrCnMcnFhj62DWhcbVPIxVnx1BW8tU+YaVCzFcdhtnaE84A+pAvdJ9zORfpnO/1kDMBKWXQxAM+y0q50L22vqdZu5I9joEimc90+5QvbAtotJLdseNsCQYwUdRFmjo2q6aDN8zWe5PWwsh3tf39T6uNjqc1MjcXChToBIoine03w== 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=sUp5MTfCC7PatUdDgyawDWuSyprBzW+jmns3tFmEYEo=; b=AoTQ3AjR5AOoRzplAwesMlxKFyhZjiUoo2+18nFkYlbENn/S7rl0JfrYWYbKZ6N3z0l1xvZQTcAmhmIGz1k3ZUztMNZLo+4GEvj+1XniQ6KLP9Nc1vZuuSFnlv1PnnrFlZwitXvgBzMGRjfxlLbUWJlnp2hqn/9HMa6TYLhWH/QJnsC2eGcfCb/n8DxXVSeLzKC9ytumqnVMTRe84vjWGe8wPTiDIYhmYkHss2L8nOcEDFpF+KH36u3dLg5QVbSurMVTFr5PCDHPXRo5zRCF+TKb71k8s6NFkO5WeEvVIFlvBWtJcJT52KCa9tS6li8eQWojJIwIhquz8egmTKOoLw== 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=sUp5MTfCC7PatUdDgyawDWuSyprBzW+jmns3tFmEYEo=; b=e+5+tkCtYK3E7a9atJhB5XorFTcVCFRSdZY0ad64o0OfhderPLB2gisJg6gVGoi7pV7WVMhLux/zDQq18YtwMdsCNiFiq2JBITlyfzc6OMswFNZl6k22HdvVA3dCsC4SJenE4sBkmvdsvFwDCAjtEtBgE2yJEC5lhnRN3rAgZ5ril6RL8HZYg729t+pGasmjo+bC/rDyp8ddFWV3RmnTR/F6OcZzAiaxo4Va2x1PG+5mKjeUbDwd7fYkSypunXKdcBlBE4toK7fVya7y6zoIiUDmA0y6gtu4syYUCe3Jv7WwrhH3FyQsTAPJYVy/FWrp+mtbT25ny5mQv37gxKsnfw== Received: from MW4PR04CA0350.namprd04.prod.outlook.com (2603:10b6:303:8a::25) by IA1PR12MB6330.namprd12.prod.outlook.com (2603:10b6:208:3e4::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.19; Tue, 3 May 2022 03:08:44 +0000 Received: from CO1NAM11FT006.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8a:cafe::90) by MW4PR04CA0350.outlook.office365.com (2603:10b6:303:8a::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.12 via Frontend Transport; Tue, 3 May 2022 03:08:44 +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; Received: from mail.nvidia.com (12.22.5.236) by CO1NAM11FT006.mail.protection.outlook.com (10.13.174.246) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5206.12 via Frontend Transport; Tue, 3 May 2022 03:08:44 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Tue, 3 May 2022 03:08:43 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Mon, 2 May 2022 20:08:43 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Mon, 2 May 2022 20:08:41 -0700 To: , , , , Date: Tue, 3 May 2022 03:08:29 +0000 Message-ID: <20220503030836.28783-2-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220503030836.28783-1-jianbol@nvidia.com> References: <20220503030836.28783-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a6950668-0213-4c59-67ea-08da2cb23b9c X-MS-TrafficTypeDiagnostic: IA1PR12MB6330:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Km0O4fA8T557Ssg5/ECcvMedlIrNPW/FENKjqXxzkP2YI8AvrTiRQksCZ7gXd2sxnRnfqc4yi38yprP4GAT84vQoghfyxrQYX2Sdrvq9m/zWfi4t/ZFZSibbc7K1lzVng6ZuNCXMYe/8AR2rfyoLT1Z0fxCQyPrEpv/cJA6WUxjKVBkxVnzrTdq4wgw6LSI5bKRv5Zqiqq4HfpGLj7Kd0y2H9HF+hMuw5VFKz8W7oQAiEwUEDhfpxbcKvxegsvqgKbwvwceroHi94UFuuW4Q+wVbJbGrNuV+tj6iALi3pjMVDoVg/779yDr+J9cZjkDehc0biZarOnfkdVF8Y/R1xNilyuwRwmQ77RVraCUCZy/qyRrDJBF+yg5KA2wRuXhKea3l8pL8GacgUrNbcDym1c+HofuBprSeJWK3D6/3v7tfaNoSDYG4zXwub/5oFLa+6BLOBfZI54IoBSswz+R9w9nOznzO3fhiJ/ZY6ZgAI77amebyBlcBHQDWWPyCpUaVgz9ztGm7qyWnknmlIRPtR9P1SZ9j1dif9xcQPX/v/RsJIrxIrqu5q7B5+RiEZl1FYK/UUszwOqXAZorTPX9iZvE9vCCpqYXUGw/DQwPaUbp04crtSBoFScT5m/3WP0ZwVjTaXXqIAuoEa/gUFI/DP2nwZaSXZlU8MX86+E5vWw/ghtG5Q+MFT3Ace6a8jdUSc4E70ckHBbi3GrFFhc8j+w== 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:(13230001)(4636009)(36840700001)(46966006)(40470700004)(1076003)(2616005)(508600001)(40460700003)(186003)(70206006)(70586007)(107886003)(36860700001)(8676002)(4326008)(356005)(26005)(7696005)(6666004)(47076005)(426003)(81166007)(336012)(316002)(110136005)(83380400001)(2906002)(86362001)(8936002)(82310400005)(5660300002)(36756003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 03:08:44.1315 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a6950668-0213-4c59-67ea-08da2cb23b9c 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: CO1NAM11FT006.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6330 Cc: Jianbo Liu Subject: [ovs-dev] [v4 1/8] 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 --- lib/netdev-offload-provider.h | 15 ++++++++++++ lib/netdev-offload.c | 45 +++++++++++++++++++++++++++++++++++ lib/netdev-offload.h | 8 +++++++ 3 files changed, 68 insertions(+) diff --git a/lib/netdev-offload-provider.h b/lib/netdev-offload-provider.h index 8ff2de983..2441534c3 100644 --- a/lib/netdev-offload-provider.h +++ b/lib/netdev-offload-provider.h @@ -94,6 +94,21 @@ struct netdev_flow_api { * takes ownership of a packet if errno != EOPNOTSUPP. */ int (*hw_miss_packet_recover)(struct netdev *, struct dp_packet *); + /* Offloads the meter or modifies it if exists in HW + * with the given 'meter_id' and the configuration in 'config'. */ + int (*meter_set)(ofproto_meter_id meter_id, + struct ofputil_meter_config *config); + + /* Queries HW for meter stats with the given 'meter_id'. */ + int (*meter_get)(ofproto_meter_id meter_id, + struct ofputil_meter_stats *stats, + uint16_t max_bands); + + /* Removes meter 'meter_id' from HW. */ + int (*meter_del)(ofproto_meter_id meter_id, + struct ofputil_meter_stats *stats, + uint16_t max_bands); + /* 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..41f6e1723 100644 --- a/lib/netdev-offload.c +++ b/lib/netdev-offload.c @@ -195,6 +195,51 @@ netdev_assign_flow_api(struct netdev *netdev) return -1; } +int +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) { + rfa->flow_api->meter_set(meter_id, config); + } + } + + return 0; +} + +int +meter_offload_get(ofproto_meter_id meter_id, + struct ofputil_meter_stats *stats, uint16_t max_bands) +{ + struct netdev_registered_flow_api *rfa; + + CMAP_FOR_EACH (rfa, cmap_node, &netdev_flow_apis) { + if (rfa->flow_api->meter_get) { + rfa->flow_api->meter_get(meter_id, stats, max_bands); + } + } + + return 0; +} + +int +meter_offload_del(ofproto_meter_id meter_id, + struct ofputil_meter_stats *stats, uint16_t max_bands) +{ + struct netdev_registered_flow_api *rfa; + + CMAP_FOR_EACH (rfa, cmap_node, &netdev_flow_apis) { + if (rfa->flow_api->meter_del) { + rfa->flow_api->meter_del(meter_id, stats, max_bands); + } + } + + return 0; +} + int netdev_flow_flush(struct netdev *netdev) { diff --git a/lib/netdev-offload.h b/lib/netdev-offload.h index 8237a85dd..a6d4ba3cb 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,13 @@ 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); +int meter_offload_set(ofproto_meter_id, + struct ofputil_meter_config *); +int meter_offload_get(ofproto_meter_id, + struct ofputil_meter_stats *, uint16_t); +int meter_offload_del(ofproto_meter_id, + struct ofputil_meter_stats *, uint16_t); + #ifdef __cplusplus } #endif From patchwork Tue May 3 03:08: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: 1625296 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=Gv1HkgYT; 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 4KslKk62wZz9sFr for ; Tue, 3 May 2022 13:08:58 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id E056040ABD; Tue, 3 May 2022 03:08:56 +0000 (UTC) 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 hCLwfBDIGnb1; Tue, 3 May 2022 03:08:56 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id EC07D40AC7; Tue, 3 May 2022 03:08:54 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id BE9A9C0032; Tue, 3 May 2022 03:08:54 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3D8E0C002D for ; Tue, 3 May 2022 03:08:53 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 2278040AC1 for ; Tue, 3 May 2022 03:08:53 +0000 (UTC) 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 C89Dpq-2Sik0 for ; Tue, 3 May 2022 03:08:52 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam07on2060d.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eb2::60d]) by smtp2.osuosl.org (Postfix) with ESMTPS id 0099F403A4 for ; Tue, 3 May 2022 03:08:51 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GO6AiWGEfPdGbyK3t17e6ANoQ1PCRpNYL4pTvZxm+8zzPALxBMS8ABLnvoCc1AQwl3wFZ9BMGoLKWRqP4UrPE5wa7J5di+ZdYf1tFXzMpyiVv4+TmJeYaLI+4xlYOEbQiCw62TEpmZuDkyQImamvuD5tngmoXQIvmfVb5+k6GdGwvPldVOLe2Ng8b56DDfu4u3zXG+gnVeUZyWVbf/dsFP51Gw66et0g+OgkxyYQUXf7WvGyuIJNtzw50+UmMWHESTZxhrJ0SqsSY0xk+Nv25eyDSp7N6z8DtWqjVUXoFOoKRoYHxA8IPBY1xYlCrFgg4y0Y2HZXwwh+ZGN8zf9TjQ== 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=QpjP5H4k5i+c3DQYoaBVeZDI8VJjQUyMwA45O1Oibl8=; b=PL1kQmPcEN25gGN6l+WAzTEPgUIuoaxV3yd//l5DwZvlcwBeDBh4eU1e4TsMgQLXGgF2qoFdaBgJA0HMoqLkmATe9fIYIyfCajzM8m+5lPOi7R5i3QLWbtZiUaF8yrhEeS3xixz+tbq6fW0ljbjTwxaI/l4HgkCkyPHfMossNzDDOHoV8S+dATv1ThE02hXABF+oGXaVRnvWn3e2XzNwDtUY16APKKkJS/Uv5AC5UXG11AQ09XhSCkbLvZDja8un0ua6sus2B+BoLcQ6b/DDdYOb1U2aU1Yriji1vW5EJjw2q5IrgJbY1DY6BmRSBa93qL1rl5HiqlRdm4AzUKhBEg== 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=QpjP5H4k5i+c3DQYoaBVeZDI8VJjQUyMwA45O1Oibl8=; b=Gv1HkgYT7TaUQ+tAECldNlZnJvMaME+nzIiWB72mWk1xmUPWbTIGxV+YTfyBdKXZRzR+6QoU63oUnz4SpWY5W5NaRNLBLNn0xVPJl6vTVkirYECpKIjbTVdWouPnclREI1tOPDjFwVfqbZ9LGitBffqsyHMWIAoMh82HKoI0iajq9QYE2lN6wKbcPfbaGSIIBZqoN2XljrCUS4uSkmGXGim45AsUvoW8ix/3x2J31H9nT62LCXtVdy9PzklU6iCtDP3BSL8dfqw1DvGthRdJGTlxfe2S3v+L+UIBrA2U6w+whOnL1R3KEloi4pVrMnDyLDuknJnDfxuRQQOUnTpebg== Received: from DS7P222CA0020.NAMP222.PROD.OUTLOOK.COM (2603:10b6:8:2e::16) by DM4PR12MB5247.namprd12.prod.outlook.com (2603:10b6:5:39b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13; Tue, 3 May 2022 03:08:49 +0000 Received: from DM6NAM11FT016.eop-nam11.prod.protection.outlook.com (2603:10b6:8:2e:cafe::91) by DS7P222CA0020.outlook.office365.com (2603:10b6:8:2e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24 via Frontend Transport; Tue, 3 May 2022 03:08:48 +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; Received: from mail.nvidia.com (12.22.5.235) by DM6NAM11FT016.mail.protection.outlook.com (10.13.173.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5206.12 via Frontend Transport; Tue, 3 May 2022 03:08:48 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Tue, 3 May 2022 03:08:47 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Mon, 2 May 2022 20:08:45 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Mon, 2 May 2022 20:08:43 -0700 To: , , , , Date: Tue, 3 May 2022 03:08:30 +0000 Message-ID: <20220503030836.28783-3-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220503030836.28783-1-jianbol@nvidia.com> References: <20220503030836.28783-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 84462341-3d86-4a5a-965b-08da2cb23e69 X-MS-TrafficTypeDiagnostic: DM4PR12MB5247:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: T0BxUOajqQcTyz81YSR26UUzpK3dzvAaG64aq96qZ4ZhWZ8NBkWKN4T1w3mAHnf/4pUJAxJsttrXdng4G/kmuNmpmHvlPbjLkY88yDCEud4Ee4e7RW9nPE0oZeDL3d79COi0ANl8T+AFLT6LWl4hxvstNOXDyVDSAq0k7W/I/GpsJxvvuURHAfAF2c/h6Wa1f4ySZ5RGxqo+aJd4P5STZy6XfY0HPTEuy6X9Zs5rAvWXlAN5e2H00cn0jQXpfV/kUAX/uHYlGPc0ekKT46A2DIx4fcosiqtD8BAY/OjxRM+cUv4KH70ahjv17J9N2uZAoGnZCyQXfeAYOPIKCmr1OZTw2HLuHqLjd/27rpxS4CXp2i7p3J7cL/3Vg20nJ/reHmq1m1a9CHswl7cv7qz7QqC/OUj6/mIvfjoALzogQrKz3EakLZjnw1VivL4Y4fX/+V/uSIIJ49W5D/RWyjCFhSvJTGxWZ2mDZ4SaSlga2cWrFZ5jAZs030+T/sRlHj8JbPA6AJvdLYQRYrQr6ODJY7Crr+BUmf7EeF/7sKOXmWJDeByKlY9lsYlx2IsV488J9rWBeMw6UDwhBP+VbkjQfS3w4gkZ/XeqG0n6/4O9kQybkjO7EZAey2vnhUW5YX+1zzUBpvZ2Rn4C3o3H74Mgx0J+OcpBm+Gvl/WZgx3cm8gm4yokCjdzQ/+U9LevMH+BnYKhuxsQW1b+H9j7nlMRkw== 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:(13230001)(4636009)(36840700001)(46966006)(40470700004)(47076005)(186003)(316002)(1076003)(6666004)(508600001)(107886003)(36860700001)(426003)(36756003)(8936002)(86362001)(336012)(110136005)(82310400005)(7696005)(356005)(81166007)(40460700003)(83380400001)(5660300002)(26005)(70586007)(8676002)(2906002)(4326008)(70206006)(2616005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 03:08:48.8004 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 84462341-3d86-4a5a-965b-08da2cb23e69 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: DM6NAM11FT016.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5247 Cc: Jianbo Liu Subject: [ovs-dev] [v4 2/8] 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, and meter id can be retrieved from action cockie as it will be saved there in later patch. Signed-off-by: Jianbo Liu --- lib/netdev-offload-tc.c | 4 +++ lib/tc.c | 59 +++++++++++++++++++++++++++++++++++++++++ lib/tc.h | 6 +++++ 3 files changed, 69 insertions(+) diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c index a41b62758..83d57c63b 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 df73a43d4..af7a7bc6d 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -1339,6 +1339,59 @@ 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 *act_cookie) +{ + struct nlattr *police_attrs[ARRAY_SIZE(police_policy)] = {}; + struct tc_action *action; + const struct tc_police *police; + 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(police_attrs[TCA_POLICE_TBF]); + action = &flower->actions[flower->action_count++]; + action->type = TC_ACT_POLICE; + action->police.index = police->index; + + if (act_cookie) { + action->police.meter_id = nl_attr_get_u32(act_cookie); + } + + 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), @@ -1761,6 +1814,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, act_cookie); } else { VLOG_ERR_RL(&error_rl, "unknown tc action kind: %s", act_kind); err = EINVAL; @@ -2773,6 +2828,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..201345672 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,11 @@ struct tc_action { struct tc_flower_key key; struct tc_flower_key mask; } rewrite; + + struct { + uint32_t index; + uint32_t meter_id; + } police; }; enum tc_action_type type; From patchwork Tue May 3 03:08: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: 1625297 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=CxjikeJi; 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 4KslKq5Zdpz9sFr for ; Tue, 3 May 2022 13:09:03 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 0075A41740; Tue, 3 May 2022 03:09:01 +0000 (UTC) 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 v1X28QCJPk7e; Tue, 3 May 2022 03:08:59 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id E17234171E; Tue, 3 May 2022 03:08:57 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id E8A77C0088; Tue, 3 May 2022 03:08:56 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 209A8C0032 for ; Tue, 3 May 2022 03:08:54 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id E338341579 for ; Tue, 3 May 2022 03:08:53 +0000 (UTC) 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 edVKXVMS0CLT for ; Tue, 3 May 2022 03:08:52 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam07on20607.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eb2::607]) by smtp4.osuosl.org (Postfix) with ESMTPS id F0E3D416E0 for ; Tue, 3 May 2022 03:08:51 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HuLZ10dTwPCqdkWZKNjBiQ/63MhRzRvjKykWMETigID33ed1e9A/xQn2Y0G/g98AoXRRgF1UbhzcATjXuGR39L3ZcpSvzLaGHR226s1TZqLdgZykH4cdj5Vm9VG1GbrFdVeoo97t048TiRTVj21AqM7KeR49bH5e0hEXKSmxi6fOwH7z6uSbtLCUbN/ANAQmcOiVvxBdspXHzNB1WVA683LylxYG9K+gJPLO775LApkh8Fc3rSXJ13UEqqJTnMwjfPBTTnTyzXFVHVT2q444HWR/9Ye4RNc4pqVtm3QgN+pnHNcYjBNgSUnZ+AcplIr80FyO9HLtl+Fq8VxqFW1Gpg== 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=GrNlfCHw3DPWF3GzYBIfIjGS0nT5MEcasjdaSTLNhwA=; b=bix8aI7M/ioWVWCI7JZQGn3QSVs3lgE32Xe5FvFsnDssOp0BBYSXreFJs8/41zrv5FM5dBzSZkWejW/zESHoDirPahZWL4tA8etAeX1ZuQPtTpps/3t6rRoSnICwbyFy1JfR8jl/AzYzkHjX9I+kJ0Sdm3p1mW+tz6TWk48LsVf5XfEXxOHxjfbm81QTJtNNKI6QC2zwizYMeymePxbiJybNlx5XOK5/5vdXjcvuNdRZS2vJyeUlZsKNVsDHXnBMPRdj739K17YpP7hWW359NdmRwbOaavLmpXLxZrL4tC+MrvS3uXP58bXc0R+EGvoTWbIBySOdJHQtyM+cNbK+OA== 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=GrNlfCHw3DPWF3GzYBIfIjGS0nT5MEcasjdaSTLNhwA=; b=CxjikeJiAmrxz8GMe51wrxgXk/AVpvbz+byvNF7D1cLWMyqiqSPxtPk6EgzABo4kAxHyyES3mdBolGaE10mteTiKP/EU05vcjZgJsiaBHp51rAuSiRrO/T1COWJnLzhfcCxtWsAoaAk5dh00Np9oqYIeMAXxDrpgiCzd6Rxj6X2nVSU2J6yeqIHKQ5fLYgkGFmz25TxsrCFlOoJy5CjMXK0iLELsSiqB7oJrVaR7wp23eBolHpqyxBJyaYQI78RXJgdHa+8ajzjzkG0k0Ol4iVk3tEcgB80jPLHJqV9Wx8hEo4/Q4dGA3BpVfUWIAs2QEsQqAysiz3Yggk0aBar7gw== Received: from MW4PR04CA0346.namprd04.prod.outlook.com (2603:10b6:303:8a::21) by CY4PR12MB1672.namprd12.prod.outlook.com (2603:10b6:910:11::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13; Tue, 3 May 2022 03:08:48 +0000 Received: from CO1NAM11FT043.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8a:cafe::f8) by MW4PR04CA0346.outlook.office365.com (2603:10b6:303:8a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.12 via Frontend Transport; Tue, 3 May 2022 03:08:48 +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; Received: from mail.nvidia.com (12.22.5.236) by CO1NAM11FT043.mail.protection.outlook.com (10.13.174.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5206.12 via Frontend Transport; Tue, 3 May 2022 03:08:48 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Tue, 3 May 2022 03:08:47 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Mon, 2 May 2022 20:08:47 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Mon, 2 May 2022 20:08:45 -0700 To: , , , , Date: Tue, 3 May 2022 03:08:31 +0000 Message-ID: <20220503030836.28783-4-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220503030836.28783-1-jianbol@nvidia.com> References: <20220503030836.28783-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7a9ad930-d37f-49fc-b32b-08da2cb23e16 X-MS-TrafficTypeDiagnostic: CY4PR12MB1672:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: O9WPhe3P8hbpPHTUCClgWACAqjrJm7LEpub8csDxED6U12JxcnhlAwo6jVcE2QRihPveHeJRQ8KyMVK/U3Y5q0ChqpruSfwaOBSmtY5lDike7YAoupF+vnLrlxmM93y4XXUme41v+iUWpdaFd0Z0CPIINdZfhg3+GEiYP0Ud/vXU1BVjNlFboRaah/YItAEI2nvd5CFx9tf2dEgkCEQt9ILU8BD2bO1J3zU+jFxsX7r9wONOWl+k0CF34i5HDojok7I/2UqDpG5Ip05/A59qdOR6P+GdfULMKIRcDF/qG1xWmDf6awKu08IonbG3kIoup63cEjwyUuBT4icM2OmPPNP7cqMZiChOf4mZxemQ1ZIfDXf8v/IBQLtTDNYvxT23PN28j0sriyx/Kfl/jEzBMCBRIFsFYsEk4m9u7uiOHihO1VE2hQP7zn664Nhv67sASBTNll+N4aRWXbpteVHkAk2S+NhjHYZFZ+BP6wI0T737owmq2itunak4UYHq0SUw99WK9UB6RVBBGxlSM9LmPJ7+KHoVhoejUnB5LuV0JZBbMm6tcBF7UZfJfVxwe2REhhnRq0z0tptjIyjoHO8u+h0E6TMFRw3Yp5StpXa5dyCIr9Wb0k/KmDN3n/723KBwyldaVlE3qQPKm7+ijpK8a7D4G7e6ofvQQHDkYhO7jy276HiGiYQ3UiFU3jZyyncYZgXjwVDprfn68VpFO689yA== 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:(13230001)(4636009)(40470700004)(46966006)(36840700001)(2906002)(82310400005)(81166007)(40460700003)(36860700001)(356005)(186003)(7696005)(316002)(6666004)(110136005)(26005)(508600001)(336012)(426003)(5660300002)(8676002)(15650500001)(4326008)(36756003)(83380400001)(2616005)(1076003)(8936002)(86362001)(47076005)(70206006)(70586007)(107886003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 03:08:48.2728 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7a9ad930-d37f-49fc-b32b-08da2cb23e16 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: CO1NAM11FT043.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1672 Cc: Jianbo Liu Subject: [ovs-dev] [v4 3/8] 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 --- lib/netdev-linux.c | 82 ++++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 9d125029d..eb05153c0 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -2629,37 +2629,27 @@ 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, + uint32_t pkts_rate, uint32_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; + + 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) { + unsigned int 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); + pkt_burst_ticks = tc_bytes_to_ticks(pkts_rate, pkts_burst); + nl_msg_put_u64(request, TCA_POLICE_PKTRATE64, (uint64_t) pkts_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); } + 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 +2682,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 +5590,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, uint32_t kbits_rate, + uint32_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, ((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); +} + /* 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 +5637,8 @@ 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); + tc_policer_init(&tc_police, kbits_rate, kbits_burst); tcmsg = netdev_linux_tc_make_request(netdev, RTM_NEWTFILTER, NLM_F_EXCL | NLM_F_CREATE, &request); if (!tcmsg) { @@ -5648,9 +5648,11 @@ 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); + nl_msg_put_act_police(&request, &tc_police, kpkts_rate * 1000, + kpkts_burst * 1000); nl_msg_end_nested(&request, police_offset); nl_msg_end_nested(&request, basic_offset); From patchwork Tue May 3 03:08: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: 1625298 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=PgcBswaJ; 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 4KslKt5lnjz9sFr for ; Tue, 3 May 2022 13:09:06 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 81636415C4; Tue, 3 May 2022 03:09:03 +0000 (UTC) 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 nHJ225leqX1o; Tue, 3 May 2022 03:09:01 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp4.osuosl.org (Postfix) with ESMTPS id 402B641731; Tue, 3 May 2022 03:08:59 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id E4E4FC0080; Tue, 3 May 2022 03:08:57 +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 0EA4DC0089 for ; Tue, 3 May 2022 03:08:56 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 07E3E416E3 for ; Tue, 3 May 2022 03:08:55 +0000 (UTC) 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 1oUBNp1aOucQ for ; Tue, 3 May 2022 03:08:53 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on20603.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e89::603]) by smtp4.osuosl.org (Postfix) with ESMTPS id 9523F4154F for ; Tue, 3 May 2022 03:08:53 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ROmB0L3olLC1KCQw/DWMzYRF31TNg+DhY26ChuAe179bFAGLILI0SGCiU+9R4T12+uAvxx/gQn+UNuigu4W2u0422pgGqAA99/Ktksp5w1gMwS4vp63K37XBVRdCiuKStLYVqAAuvk3KTh10c+zGzcP/lM39J3FT07dH4sdseJQsuo8D/l11Y3/MVfHuryiPFPWX3s4QkgVZSS73rMCKWzMrqt3bciIsb+PPptUE12q6TklzUCOwd6PPb7XjcoR43x9YKUZUHq7iwK0LWBr2PPt5ALF9NNtUZTpAO8/m/c3rH72fubYaZcZvTPT80I2r8Ow+agEN4ubHsNkp6ajkYg== 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=Bs+D1eSr6NKkWFVkLXDgLjh0uOmSejOINqlBi53imPU=; b=Yhz6c3VUsOYU/nyxlvjfDNOuEIxceUyLQmEaiI/maQbjVbW9Oi932hSNl3OUf4i6NU2Cvu+Wv1eFqJIM7LR1EJqc+zyBa6HRWaTR7pKWvP/k15CR4hHik2PqjkNBpwec8dOsSvWGLXyNWtr2dlalnL/NvpsJ9HlZrzEBy17Ql7Dy3r/Tu15gKcFy856793ln+YHpZoY7ZW2dTn3xdGyNTmLLUpP57HrSt5tyA4F3sMovXMiM3frSeAZuaL1S6Bjqll9jrTWmwUZVRWHHZdLncoE6JQGXg+jJCRf36DQ1Lzo93kN+CSGvWu3IOrkpgUr1vqyNlGa5pGTfD8eD2NJvNw== 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=Bs+D1eSr6NKkWFVkLXDgLjh0uOmSejOINqlBi53imPU=; b=PgcBswaJIN1JA6YCrWyNSObB8oBqh5uTaUyQ1muUTu9UEC4IRJatEjSX8EtNWGW43dwWj5UhRyqMXFsE0+29cm9UnFjPDUwwSM/45L8Kz5O+5PBXU32BFn23rDtb+Ot/IkzSFYb2zQfLwRg1I7MRB4aC1wNeIA8DM6zGflSW1AHC3ajs7APrwJPnA7d+LQIAyDE7xG2O3Sl2oY1rrv61uLFv5Ks9NW4lCFQDayLJQocvm9l7qlNDYyOIESi7kxmOESZ5V80AKP8ax0i3c/kW9tIr4COmSJ2j9AmMuwhOYwL8EkVSZQsobpHUk5syzVBDSbcI6loHrWCg01jfbZzmtw== Received: from DM6PR06CA0068.namprd06.prod.outlook.com (2603:10b6:5:54::45) by MN2PR12MB3373.namprd12.prod.outlook.com (2603:10b6:208:c8::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13; Tue, 3 May 2022 03:08:50 +0000 Received: from DM6NAM11FT031.eop-nam11.prod.protection.outlook.com (2603:10b6:5:54:cafe::1e) by DM6PR06CA0068.outlook.office365.com (2603:10b6:5:54::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.15 via Frontend Transport; Tue, 3 May 2022 03:08:50 +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; Received: from mail.nvidia.com (12.22.5.235) by DM6NAM11FT031.mail.protection.outlook.com (10.13.172.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5206.12 via Frontend Transport; Tue, 3 May 2022 03:08:50 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Tue, 3 May 2022 03:08:49 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Mon, 2 May 2022 20:08:49 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Mon, 2 May 2022 20:08:47 -0700 To: , , , , Date: Tue, 3 May 2022 03:08:32 +0000 Message-ID: <20220503030836.28783-5-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220503030836.28783-1-jianbol@nvidia.com> References: <20220503030836.28783-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e14b067d-1331-4db8-99ce-08da2cb23f5a X-MS-TrafficTypeDiagnostic: MN2PR12MB3373:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MIT79t9U0OmUP739mWETZxhFxhFj8de1TuZbxJxLhlLXC7V8bP5ZsUbgdH9c06+42Fx8i23aizmtNNXhx76NGcvdg7JqeKjnzNLltcuykj+U55Hm/M22EU664LIBkfwGDLXI5GJsU6KQDRM0n3++WFVRbRwvI+PUzKEc+rOvCra39sx64dQThGbUDqQwhSUQ+C67/H3DyQPzlxxomh9iPROSJLq6nxsrCLkp1u9e1PsU9LBIs7gkyYBXaaBHjbWu2+0lPbPcM0pl99mLu21bpMBGTMpeCH0pA7j1mh5DKVDI7BYKtrhDtJM66DCPwJaWFx1ugpPKmVrSwNiLinM84TSEsVQyBFsxSzTU6AMQoHml1v6VDEjQZt3mIieushBCoHziz8FDOxz1vk7yY4UIU+TXE0t7h3mPgGA3OBt02N+AaPp4ArQK1+dXwDrr6EhEcHs+yj1Sx8sN8NLJsJdZzulqYa7/qhYLrX297XZZGFa2F0lf1rOtJjAoi574p2EtYTnwg2jxVnd+uAJBal3Rsg6HwKGWrt6VEecuBeAGD65WYKBVdnOtvtYoCumQ2iik6T9K0fdK4MgfCeVx59pDs3K1CLsRO6DyjHJeVlZDq7Et5STvTH2iKdEFigujGT88jm/FxgBkOc2D4jqwmcgy1WLDxQYTlh02Bi+yDhaE6RQ8MdWo8NebvBDP+y3W5x0P498cCGGhs5pdcgJuTTW7Zw== 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:(13230001)(4636009)(40470700004)(36840700001)(46966006)(7696005)(26005)(5660300002)(110136005)(40460700003)(6666004)(83380400001)(36756003)(2906002)(508600001)(70586007)(8936002)(82310400005)(70206006)(81166007)(47076005)(2616005)(316002)(426003)(336012)(107886003)(186003)(1076003)(36860700001)(4326008)(86362001)(8676002)(356005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 03:08:50.3799 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e14b067d-1331-4db8-99ce-08da2cb23f5a 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: DM6NAM11FT031.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3373 Cc: Jianbo Liu Subject: [ovs-dev] [v4 4/8] 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 | 133 +++++++++++++++++++++++++++++++++++++++++++++ lib/netdev-linux.h | 6 ++ lib/tc.c | 21 +++++++ lib/tc.h | 6 ++ 4 files changed, 166 insertions(+) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index eb05153c0..ef6c7312f 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -5664,6 +5664,139 @@ 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; + + 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); + + return tc_transact(&request, NULL); +} + +static int +tc_update_policer_action_stats(struct ofpbuf *msg, + struct ofputil_meter_stats *stats) +{ + const struct nlattr *act = NULL; + struct tc_flower flower; + struct nlattr *prio; + struct tcamsg *tca; + int error; + + if (NLMSG_HDRLEN + sizeof *tca > msg->size) { + 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) { + return EPROTO; + } + + prio = (struct nlattr *) act + 1; + memset(&flower, 0, sizeof(struct tc_flower)); + error = tc_parse_single_action(prio, &flower, false); + if (!error) { + stats->packet_in_count += + get_32aligned_u64(&flower.stats_sw.n_packets); + stats->byte_in_count += get_32aligned_u64(&flower.stats_sw.n_bytes); + stats->packet_in_count += + get_32aligned_u64(&flower.stats_hw.n_packets); + stats->byte_in_count += get_32aligned_u64(&flower.stats_hw.n_bytes); + } + + 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 prio = 0; + 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, ++prio); + 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; + } + + error = tc_update_policer_action_stats(replyp, stats); + if (error) { + VLOG_ERR_RL(&rl, "failed to update police stats (index: %u), err=%d", + index, error); + } + + return error; +} + +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 prio = 0; + 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, ++prio); + 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 && stats) { + error = tc_update_policer_action_stats(replyp, stats); + } + + return error; +} + 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 af7a7bc6d..ee16364ea 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) @@ -1863,6 +1877,13 @@ nl_parse_single_action(struct nlattr *action, struct tc_flower *flower, return 0; } +int +tc_parse_single_action(struct nlattr *action, struct tc_flower *flower, + bool terse) +{ + return nl_parse_single_action(action, flower, terse); +} + #define TCA_ACT_MIN_PRIO 1 static int diff --git a/lib/tc.h b/lib/tc.h index 201345672..96b9e6ccc 100644 --- a/lib/tc.h +++ b/lib/tc.h @@ -80,6 +80,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); @@ -365,6 +367,8 @@ struct tc_flower { enum tc_offload_policy tc_policy; }; +struct nlattr; + int tc_replace_flower(struct tcf_id *id, struct tc_flower *flower); int tc_del_filter(struct tcf_id *id); int tc_get_flower(struct tcf_id *id, struct tc_flower *flower); @@ -376,5 +380,7 @@ 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_single_action(struct nlattr *action, struct tc_flower *flower, + bool terse); #endif /* tc.h */ From patchwork Tue May 3 03:08:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianbo Liu X-Patchwork-Id: 1625301 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=oZBmGi74; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.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 4KslLD6BpQz9sFr for ; Tue, 3 May 2022 13:09:24 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id DFD5083EDE; Tue, 3 May 2022 03:09:22 +0000 (UTC) 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 MIKgclxCSY-U; Tue, 3 May 2022 03:09:20 +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 E566683ECB; Tue, 3 May 2022 03:09:18 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id B8672C0032; Tue, 3 May 2022 03:09:18 +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 3B4ACC002D for ; Tue, 3 May 2022 03:09:17 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id E28176100A for ; Tue, 3 May 2022 03:09:03 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp3.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=nvidia.com 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 GFI_u2jkp1y6 for ; Tue, 3 May 2022 03:09:02 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on20604.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e8a::604]) by smtp3.osuosl.org (Postfix) with ESMTPS id 1514361006 for ; Tue, 3 May 2022 03:09:00 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UgWmZcbHddEDYC9ApKneTyxry7W4K0PEx9RE3MU7g2It8jATntdsA21cIJawPnEIH78iwMixrCpEpof0qIHMP4TmIbclw6klLCgWAIvtKDhIhCQympAPrDdwrqb/zjLVYKqQqFxx4b+Qd7Ueo6T6xUHknpDCIAnxgcrKJWWnXVeO9+gcODZn/Wgu0WYchx/7jMxPUcgueKUu7iYBM91AonS2KIgOQShw2yNxS3IDxn1BlbvE7GjU1+LF1Ml5g3HN58+ZjTQUezZ6NsjWHEn2W8UZXSyVycNGNeO/9H4Wj7PjupnHIX+9TGOiItb29X5Qfc8RiOjIeXXXxD2XkJv1jg== 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=tiYCWImL7sQSvpIkUIDUoKJg5BoLgqbIztdn6LkRQ8o=; b=aIhu8P2k4COTmQhQrginkZATO4SOG0Eu81hgXN/5TxgA4U1AW4Jstm5rRigkA1BkO2GbS8B9z8c4o1yrtJge09RCIB3C9feJGm7vP1TZpVol4zRUHmrGUaxUZ7HyJuyGtIgARZr0PVbEPtCHPnKtHd6gKc9a9Gp/sfR+4rOdXxF4Q4ck2FXkuNtLOqAnaGAXSwE1iM2ffTHZOrmvDQlWNpliTGtEVEyAi82jQo3TwCPNmDnv0+JGHKCjBCMh2zgCPy8Lw6fQ0jOM04yLk5j5KC4tFMFOToro1q+y6Eph7+LIwpW0TOqIs1hg0DAesqVOdtR1i/LwvM1+RYpW5T7oVA== 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=tiYCWImL7sQSvpIkUIDUoKJg5BoLgqbIztdn6LkRQ8o=; b=oZBmGi74wFcYy7bDPefYR57CfBAwMus161UykchnDq4mLS5iCQ364OI4vhXWPMfnwkSbSYkrXg5Ro9Pk6l5qkFjDck9jIgrJz2e6dFyxIaiZ1G/C4k35ZUJzSGQYli7L5umat3r+e5WnsC2gD/CXglPEW61San6XCB7H3ybFUjR4kr3+WH+ubDBAoo4JxwSBxS0273Gh13OsuJBo1XDCc66qFvMzx3EIf9qgPxvWkqiJrEHWMhmH1ZwB+Lz7AwB3iFCU/zuuTlOu/0JQWbIAlyRKvLElVlq/TDJy44X4z51/2H11wFcJsXBfgNrHYS1LkIEXa7HHRGctp2QIZtGQ+g== Received: from DS7PR03CA0124.namprd03.prod.outlook.com (2603:10b6:5:3b4::9) by MWHPR12MB1615.namprd12.prod.outlook.com (2603:10b6:301:10::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.15; Tue, 3 May 2022 03:08:57 +0000 Received: from DM6NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3b4:cafe::41) by DS7PR03CA0124.outlook.office365.com (2603:10b6:5:3b4::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.14 via Frontend Transport; Tue, 3 May 2022 03:08:57 +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; Received: from mail.nvidia.com (12.22.5.234) by DM6NAM11FT009.mail.protection.outlook.com (10.13.173.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5206.12 via Frontend Transport; Tue, 3 May 2022 03:08:57 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Tue, 3 May 2022 03:08:51 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Mon, 2 May 2022 20:08:51 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Mon, 2 May 2022 20:08:49 -0700 To: , , , , Date: Tue, 3 May 2022 03:08:33 +0000 Message-ID: <20220503030836.28783-6-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220503030836.28783-1-jianbol@nvidia.com> References: <20220503030836.28783-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 94cacd85-e149-4639-0ce9-08da2cb243a8 X-MS-TrafficTypeDiagnostic: MWHPR12MB1615:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NpOvPjc9izG4c7EYl2ALEtiKwuZMNV7NrsvTLug/xn81uTttfFJHVqRxBtfnmXdjWORxbOEcuyrBywSm7ZBhLgK1Q8dQTLulbrv/QB4Qh9A9JL/IHq3e+ZUQmNJpBcmW28ZHTgei1SRJjOGvWbUuSRAAzEekcUAip8TZwShUa0k3hwCDqfUPeNVsf4/Lzi5sA6SO2NO7xDGhY72tavCkV8RITPCAjRQP5uR/xCQAEaNphu6NHGOM/Aw+dLPjC86U56xBd8fNOAirwARirxvJMAjBN8/4QyX++1puYwF2bs/pM55THeBUExFD0QyWBZnlhXfGM0SBH7GH1CvLmLMRL4uTh67Yq2CfAgC0mZTlRfwDFVih171KhKXvQqp8xSlBf2c+/x2+zmG1zY+9opTRT7I+5c+QfPDvz6N0Se4PrqwD+4ZqMwYN+BcVVo5+rQgeSs2BVil6NR5fOSe+Ao0Zee8o2luDM67vHzLCsRY1KDWGBWJzmFTbqRCOTe9LmTuU8zOsuOsthvUaXnpWot5e/3Pef9qA1JCQMcnKQxUDFscff68zQmx44eG9WJP4WkEIH8rLEJvHovtrqfEWIuUxDglOCMfNgOl7/HbA9XvrqOQhjg3DnLhElcI7HGUuMC6G1j/8Z5rq4G0mqrTi61SNv3lhnnZDurHpSF2yZ1q05kQnZDSBUKKFw0qTX4HKZ9PE9KLjXy6wOdq4fUjVjWCiMA== 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:(13230001)(4636009)(36840700001)(40470700004)(46966006)(107886003)(2616005)(1076003)(186003)(26005)(2906002)(426003)(47076005)(336012)(81166007)(82310400005)(356005)(86362001)(40460700003)(508600001)(36860700001)(83380400001)(36756003)(7696005)(5660300002)(8936002)(316002)(4326008)(8676002)(110136005)(70586007)(6666004)(70206006)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 03:08:57.5984 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 94cacd85-e149-4639-0ce9-08da2cb243a8 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: DM6NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1615 Cc: Jianbo Liu Subject: [ovs-dev] [v4 5/8] 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 --- lib/netdev-offload-tc.c | 209 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 209 insertions(+) diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c index 83d57c63b..b3c60c125 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" @@ -62,6 +63,20 @@ struct chain_node { uint32_t chain; }; +struct meter_id_to_police_idx_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 ids pool and hashmaps. */ +static struct ovs_mutex meter_mutex = OVS_MUTEX_INITIALIZER; +static struct id_pool *meter_police_ids; +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 +2301,10 @@ netdev_tc_init_flow_api(struct netdev *netdev) probe_multi_mask_per_prio(ifindex); probe_ct_state_support(ifindex); + + meter_police_ids = id_pool_create(METER_POLICE_IDS_BASE, + METER_POLICE_IDS_MAX - METER_POLICE_IDS_BASE + 1); + ovsthread_once_done(&once); } @@ -2302,6 +2321,193 @@ netdev_tc_init_flow_api(struct netdev *netdev) return 0; } +static struct meter_id_to_police_idx_data * +meter_id_find_locked(uint32_t meter_id) + OVS_REQUIRES(meter_mutex) +{ + struct meter_id_to_police_idx_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_id_to_police_idx_data *data; + int ret = 0; + + ovs_mutex_lock(&meter_mutex); + data = meter_id_find_locked(meter_id); + if (data) { + *police_idx = data->police_idx; + } else { + ret = ENOENT; + } + ovs_mutex_unlock(&meter_mutex); + + return ret; +} + +static void +meter_id_insert(uint32_t meter_id, uint32_t police_idx) +{ + struct meter_id_to_police_idx_data *data; + + ovs_mutex_lock(&meter_mutex); + data = meter_id_find_locked(meter_id); + if (!data) { + 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)); + } else { + VLOG_WARN_RL(&error_rl, + "try to insert meter %u (%u) with different police (%u)", + meter_id, data->police_idx, police_idx); + } + ovs_mutex_unlock(&meter_mutex); +} + +static void +meter_id_remove(uint32_t meter_id) +{ + struct meter_id_to_police_idx_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_mutex); + ret = id_pool_alloc_id(meter_police_ids, police_index); + ovs_mutex_unlock(&meter_mutex); + + return ret; +} + +static void +meter_free_police_index(uint32_t police_index) +{ + ovs_mutex_lock(&meter_mutex); + id_pool_free_id(meter_police_ids, police_index); + ovs_mutex_unlock(&meter_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; + + ovs_assert(config->bands != NULL); + + 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(&error_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(&error_rl, + "failed to %s police %u for meter id %u: %s", + add_policer ? "add" : "modify", + police_index, meter_id.uint32, ovs_strerror(err)); + goto err_add_policer; + } + + if (add_policer) { + meter_id_insert(meter_id.uint32, police_index); + } + + return 0; + +err_add_policer: + if (add_policer) { + meter_free_police_index(police_index); + } + return err; +} + +static int +meter_tc_get_policer(ofproto_meter_id meter_id, + struct ofputil_meter_stats *stats, + uint16_t max_bands OVS_UNUSED) +{ + uint32_t police_index; + int err = 0; + + if (!meter_id_lookup(meter_id.uint32, &police_index)) { + err = tc_get_policer_action(police_index, stats); + if (err) { + VLOG_WARN_RL(&error_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, + uint16_t max_bands OVS_UNUSED) +{ + uint32_t police_index; + int err = 0; + + if (!meter_id_lookup(meter_id.uint32, &police_index)) { + err = tc_del_policer_action(police_index, stats); + if (err) { + VLOG_WARN_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 +2518,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 Tue May 3 03:08:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianbo Liu X-Patchwork-Id: 1625300 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=nqIhPEwM; 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 4KslL90Vxfz9sFr for ; Tue, 3 May 2022 13:09:21 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 80B5A60FFB; Tue, 3 May 2022 03:09:18 +0000 (UTC) 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 VrXbYILmLFi7; Tue, 3 May 2022 03:09:16 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id 46A0F61021; Tue, 3 May 2022 03:09:13 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id AA7A3C007F; Tue, 3 May 2022 03:09:12 +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 336F7C0080 for ; Tue, 3 May 2022 03:09:11 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 530FB60FDF for ; Tue, 3 May 2022 03:09:01 +0000 (UTC) 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 JatBbYFumQaX for ; Tue, 3 May 2022 03:08:59 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on20609.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e8a::609]) by smtp3.osuosl.org (Postfix) with ESMTPS id B2A1560FF7 for ; Tue, 3 May 2022 03:08:59 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kTeCw4y9ESOXKmgBZwx0k3LeH218fb+opEpBISReugInjc6kbUzPBysonOsqb5ulvbn8oPggQBMOMQZYyI4gXO2nZPHCBpbzrHa92FIyHeXQdmNksNMIoTDfBd6/mip/tZYuMnuigNOkWjM2A7vdu6D5ZExafQDzuKKnRIBNwMN7Uy8vomeRvykxEqYR3WLHeHAIflyyydvnx1uGdUf0yJG70rEWquHhtehbX43J0cubIMXxRv4H7ECO57Rag99jUIKB5sRDrcJf2k70bL35wa6MDBb+jrconKlPJFp0B6Dan/vepYDA5OXipnUBHttnAZXE7RvY8XJUKO15cryyPw== 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=8DT5fd0XAS24fvBqbhKebsLZZrLXWPPhRCz089yJ2Gs=; b=I1v3Mnfe+CFiOUehFHjKdU2dXsuD6bEE0dlQYKFT+nsoqt4b2NFehrGnZIG6f/e+c3kX1syOs6mG5XE+kq0mCDBsaLuh2WRAoXIwMsyY8PT9BAGwHo7VeKPlL3zOtlnS5+FYa5dzu9f5dL6EpoIMU1As7AiGg5v2IPdZiHRu2kjX8eQUNWpSnHOrIph8odBlrlvUeqrvdVKUIZyd+fTzZLYLjWMsyks66iaaNVO3jytehKUBHJx6gS+9kzwxCCneItkoF4r/ZQGzs1V4/w+qEW5JOCiDfCMtaQ/DJuLu0aY4x/KCHwrBs538OU9JcJxIt578EPSuBPq0rhs30qbl7g== 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=8DT5fd0XAS24fvBqbhKebsLZZrLXWPPhRCz089yJ2Gs=; b=nqIhPEwMh0VOSMmfIqSZ5jGDGG6wWhJdE5j81E7di+q6lSmA5qp5s+cM8gOIVVnnGmOeFgFJx85BUjRSRxdrTgEIfkHEqoRhpsKCQiWt0C1xITyo8D7rAXhciydt1HJ9dcmNuR2Juo9ektImJDJqhGBp3Hv9fTvDNslf+yo3bc/CC7XPhUgZ5NEZiQhPARnXBHq/aizCWFaS0Eak05qkN1xOMelbWdvDbhQnZf+ZyxcknPdqlTlx8WmDAj4hIxlNfz4DPfdBcT/aecw39Vurd4sO3ePD4ZQ9ZO+Scs0XmSqdiNa1qTe1hhNjL05fHOsdurvIoMW5q5XpgwiFa3xd6Q== Received: from MW4PR03CA0034.namprd03.prod.outlook.com (2603:10b6:303:8e::9) by MW2PR12MB2585.namprd12.prod.outlook.com (2603:10b6:907:3::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.20; Tue, 3 May 2022 03:08:55 +0000 Received: from CO1NAM11FT007.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8e:cafe::49) by MW4PR03CA0034.outlook.office365.com (2603:10b6:303:8e::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24 via Frontend Transport; Tue, 3 May 2022 03:08:55 +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; Received: from mail.nvidia.com (12.22.5.236) by CO1NAM11FT007.mail.protection.outlook.com (10.13.174.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5206.12 via Frontend Transport; Tue, 3 May 2022 03:08:55 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by DRHQMAIL109.nvidia.com (10.27.9.19) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Tue, 3 May 2022 03:08:53 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Mon, 2 May 2022 20:08:53 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Mon, 2 May 2022 20:08:51 -0700 To: , , , , Date: Tue, 3 May 2022 03:08:34 +0000 Message-ID: <20220503030836.28783-7-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220503030836.28783-1-jianbol@nvidia.com> References: <20220503030836.28783-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: eaa98160-ffd8-409f-b85d-08da2cb24232 X-MS-TrafficTypeDiagnostic: MW2PR12MB2585:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ESl7f1ry/s86uWF8NTEijpj0pYxvY89/jvb5HNVGqaZwvtTUCwiLayh9QdJySh7CRbChVB3W1isybr+qRlv6xLgF00l3NVJEFtDQwVNuhXEjU5UKOBvpjDhrqz7iDvUQc9aJGDke2+m1bCrR/OvdKmFj/SWYViciSl+aY3FRGEtgBc8Xxt0kfVei/8VaiawyQVYc22dgDqJmMZrFYGw7Gse9jr2nL1jax0uh3TBAlcuVKwmX0T4/li9JY4iWZGM+i7af9apl3SERxgA9YgtDyzO2gjUAVo+KV7/T5DRH6PnfhN9GfKd9ikCQ7KIfUIaUyb/DOESjpS77luJVBIjintLfpN4jVXUfgTIp9XVbtqBXcRR49s2EMoTcJsQJ7nWJjTnCrcnJ4YD2U9TocHmU/lwuhaiiqqbTJx7wqtpfdhesdv4tcYlny/nY5aGQKrAcVO0qTFxh5x/0Av1LmsUaOy4NKhZFotjOpZbmcfirR7NB1EpOHaKfrPWC2cKafMv9QJnkzRBG9ghywQWEajoook+pCoVHgl3/bU8aRPu199uB6lsYBhYTDoEHRZ0vWqV4yrfEEuqaTsUvlYY+OVRtYOZfYR0X4CXp8wMaYsW27sWgm5ZQEEdKiZst1JV9/eZF0KQyQ4jP8V/ckzNgtygcQPJSAxRrIq1KVxpX7E2QZrs7eALzTu+F0/nPHEqQAPpsWOppgyjDvnHjf0bmyy/QxA== 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:(13230001)(4636009)(40470700004)(46966006)(36840700001)(82310400005)(2906002)(8676002)(70586007)(36756003)(70206006)(86362001)(26005)(4326008)(356005)(81166007)(47076005)(6666004)(316002)(40460700003)(5660300002)(8936002)(110136005)(2616005)(508600001)(36860700001)(83380400001)(336012)(426003)(1076003)(186003)(107886003)(7696005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 03:08:55.1673 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: eaa98160-ffd8-409f-b85d-08da2cb24232 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: CO1NAM11FT007.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR12MB2585 Cc: Jianbo Liu Subject: [ovs-dev] [v4 6/8] 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 --- lib/netdev-offload-tc.c | 75 +++++++++++++++++++++++++++++++++++++++++ lib/tc.c | 61 +++++++++++++++++++++++++++++++++ lib/tc.h | 2 ++ 3 files changed, 138 insertions(+) diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c index b3c60c125..bded4bc8c 100644 --- a/lib/netdev-offload-tc.c +++ b/lib/netdev-offload-tc.c @@ -69,6 +69,11 @@ struct meter_id_to_police_idx_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 ids pool and hashmaps. */ @@ -2252,6 +2257,74 @@ 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)) { + 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); + } + memset(police_idx, 0, TCA_ACT_MAX_PRIO * sizeof(uint32_t)); + } + + err = nl_dump_done(dump->nl_dump); + ofpbuf_uninit(&rbuffer); + free(dump->nl_dump); + free(dump); + + return err; +} + +static void +tc_cleanup_policer_action(struct id_pool *police_ids, + uint32_t id_min, uint32_t id_max) +{ + struct policer_node *policer_node; + 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) { + /* don't use this police any more */ + id_pool_add(police_ids, police_idx); + } + } + free(policer_node); + } + + hmap_destroy(&map); +} + static int netdev_tc_init_flow_api(struct netdev *netdev) { @@ -2304,6 +2377,8 @@ netdev_tc_init_flow_api(struct netdev *netdev) meter_police_ids = id_pool_create(METER_POLICE_IDS_BASE, METER_POLICE_IDS_MAX - METER_POLICE_IDS_BASE + 1); + tc_cleanup_policer_action(meter_police_ids, METER_POLICE_IDS_BASE, + METER_POLICE_IDS_MAX); ovsthread_once_done(&once); } diff --git a/lib/tc.c b/lib/tc.c index ee16364ea..16d4ae3da 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -2067,6 +2067,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; + uint32_t prio = 0; + + 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, ++prio); + 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 police actions"); + return EPROTO; + } + + for (i = 0; i < TCA_ACT_MAX_PRIO; i++) { + if (actions_orders[i]) { + memset(&flower, 0, sizeof(struct tc_flower)); + err = tc_parse_single_action(actions_orders[i], &flower, false); + if (err) { + 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 96b9e6ccc..f6d1ed91c 100644 --- a/lib/tc.h +++ b/lib/tc.h @@ -382,5 +382,7 @@ int parse_netlink_to_tc_chain(struct ofpbuf *reply, uint32_t *chain); void tc_set_policy(const char *policy); int tc_parse_single_action(struct nlattr *action, struct tc_flower *flower, bool terse); +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 Tue May 3 03:08:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianbo Liu X-Patchwork-Id: 1625299 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=gJURHy4M; 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 4KslL22ZTbz9sFr for ; Tue, 3 May 2022 13:09:14 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 4DCF2831CA; Tue, 3 May 2022 03:09:12 +0000 (UTC) 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 FK4O9_EeD9Cj; Tue, 3 May 2022 03:09:11 +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 2176D8340C; Tue, 3 May 2022 03:09:10 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id DFF7DC0032; Tue, 3 May 2022 03:09:09 +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 2149AC0032 for ; Tue, 3 May 2022 03:09:09 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id D5E3240B0E for ; Tue, 3 May 2022 03:09:02 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp2.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=nvidia.com 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 IrO9oqLZH8Va for ; Tue, 3 May 2022 03:09:01 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2062a.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eaa::62a]) by smtp2.osuosl.org (Postfix) with ESMTPS id 57C2440AFA for ; Tue, 3 May 2022 03:09:01 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SufSRJPgBIdA85cAf0AitROTH8WFfAzKKkUTo7QYiRJUN/Zr+m3kRYnF7GUX+wl4NbtxA8lUkyR5h/9c+dP+WBi1inCoPDpcnrTvSyivZIZAMdgTiRjfd4grKuTJI/7L1rsMpNO81xQLSQpTpf2d9fX0o4+f9BRlYDwx0M91V2kJrxqC4RpIwFseCY/ibnY91Lb4OByponU1rdZioJR6LDvJXV2a6T7InlbOF/gFCtfI37B7Ut4fiXAQ3gVb2ShjCLvQ0Z/PH21RG6oDIycMnLaImetHTkIPfbk+VpbPHfUZ16zU0AS4QBs6PTNQMMAnCPWSHf5Q30eIs5kr6y+xmQ== 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=U4yMAWgnZF1+S4+4sOnPr4gXF2L9xuXgbda4YNNj+4g=; b=ZBfq5afqrXTlwNtnZ94nWgWO1UYsMDMDF8DacSw0kRlQNqkapeRx4yoe8VLukdGRCZcTwVw2rR+IpctVJQPgYRDxyH6ktE/Vq4xGY78+q9YlTTpxKeRVjBR4KgEll19ywIKdRicmw/5Ds8CtkVdW0GuCF8PG5HcsIN289wM1UaLBT8di1v0szgrhBrwdX5zz+QshTqMu7KUKJTByRWAZbnQaIx2ARIHA406KWktPGRhBKvxbkvlOb+ZgzZVBQbDrbE/EdIJMPJVcPe/TZOEioSW6Dclq3S2I+TQr9tjWvf9JSfoRFu5MHUI8X6KiaABaTCTUDkPCezbVS0+aJykXJw== 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=U4yMAWgnZF1+S4+4sOnPr4gXF2L9xuXgbda4YNNj+4g=; b=gJURHy4MPaywxbYL7gds6PzO2cPWs0J7HuTgK+TjkX4BG/WsPAtGud2EJ/CocKvCjZObNJCWauzYW8HnYxblE4YCwu5qKKWIJmGNuRgEj57I+kJWzlaOusboAlAdG8OGlqVuuaM2NxRjCoxj+SpAJ5U1/CLHf8ha6N0tE1cehgs429qMzvbgreKWnHEQbdL2L9u0L2jpdoBME+7f5aThYt6mXUnx0I1fPjZDYeIpbec/1P+auDLsUYfuDTcvRBSGbaKz9OXiRkeOTOAq0k6gFBwiZVgn3xF0gKyqApxwsKhljSq1Ehf54/IYYHRThZTt66PXTSC75sa9dnVBnFhW+g== Received: from DM6PR06CA0007.namprd06.prod.outlook.com (2603:10b6:5:120::20) by MN2PR12MB4029.namprd12.prod.outlook.com (2603:10b6:208:167::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.15; Tue, 3 May 2022 03:08:56 +0000 Received: from DM6NAM11FT044.eop-nam11.prod.protection.outlook.com (2603:10b6:5:120:cafe::d6) by DM6PR06CA0007.outlook.office365.com (2603:10b6:5:120::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.13 via Frontend Transport; Tue, 3 May 2022 03:08:56 +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; Received: from mail.nvidia.com (12.22.5.235) by DM6NAM11FT044.mail.protection.outlook.com (10.13.173.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5206.12 via Frontend Transport; Tue, 3 May 2022 03:08:56 +0000 Received: from drhqmail201.nvidia.com (10.126.190.180) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Tue, 3 May 2022 03:08:55 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail201.nvidia.com (10.126.190.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Mon, 2 May 2022 20:08:55 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Mon, 2 May 2022 20:08:53 -0700 To: , , , , Date: Tue, 3 May 2022 03:08:35 +0000 Message-ID: <20220503030836.28783-8-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220503030836.28783-1-jianbol@nvidia.com> References: <20220503030836.28783-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 192e4dd7-93a2-43ef-3b38-08da2cb242fc X-MS-TrafficTypeDiagnostic: MN2PR12MB4029:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yuoAjFDik1381607ZpbHgdfpKcSFQ8sHh/MiJS7Q6uOaPy1QFwCljIBFEnmevkJ5IRSm73wHdLoLZIx0Ebwbh4jAzd5WeraZ7+tWeXtNBJ5gCap7G1+4IyFxnFUCOSOnmIvAI/J163Y1/SJ1Xpkd5XydZ8wGv0Jd3hhFAMu2owxXPEvA+mSzE9MGcxImsfLnWugkTeEWHcDrY/hdPIim+3OCfDsRiSZfV3snaFF0tuIMnG/yiO8+eDS0RCWm+8pIkIq5YEkc/sPStkZhguTocUvuGNXWMGP3HkTimkBFwZy2DTIVINfv+zgAS4yqydUMUGtnpJmWjAzR0F1esc7ewY7eDJCy1bt6NSGbw95ZWbC/7pSghawClVj+q4RRUQIh4eU+LuzLb2Rbv46jvh6YaUNk4eoUuxwhodeDvhPTXKhav6ji6LmC5ZZy8y7BKEiH5eQLLShHIh3/M/+WGsEuoXX6vCCMP9g5LFd+AD5yIzHEEAbaIlkCgrCxiN2j9b94meUeqyrcsPdyxELalCcWvIhH5LWcLJLNuxMj+mx8Z8l/XOcI40tw+ohfwUUvqzlF2vXRGXd8ZdIzRzkQNzxmc2d9uD2L7CXpTQx401vK59+2D5TvvJk9qm2nlHtf8l1+jsfa5oryiYNbUMnwYBx4Q4O0Z9dXvb4jO+jzbQ7OcYVKipBsvojrOtO8B3FCeYmUZO4u5O09aZVBHtVJ2pjyIQ== 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:(13230001)(4636009)(36840700001)(40470700004)(46966006)(107886003)(2616005)(1076003)(186003)(26005)(2906002)(426003)(47076005)(336012)(81166007)(82310400005)(356005)(86362001)(40460700003)(508600001)(36860700001)(83380400001)(36756003)(7696005)(5660300002)(8936002)(316002)(4326008)(8676002)(110136005)(70586007)(6666004)(70206006)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 03:08:56.4880 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 192e4dd7-93a2-43ef-3b38-08da2cb242fc 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: DM6NAM11FT044.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4029 Cc: Jianbo Liu Subject: [ovs-dev] [v4 7/8] 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, an action cookie is added to save meter id on rule creation, so meter id can be retrieved from the cookie, and pass to dpif while dumping rules. Signed-off-by: Jianbo Liu --- lib/netdev-offload-tc.c | 16 +++++++++++++++- lib/tc.c | 25 ++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c index bded4bc8c..fa3e8113b 100644 --- a/lib/netdev-offload-tc.c +++ b/lib/netdev-offload-tc.c @@ -169,6 +169,8 @@ static struct netlink_field set_flower_map[][4] = { }, }; +static int meter_id_lookup(uint32_t meter_id, uint32_t *police_idx); + static struct ovs_mutex ufid_lock = OVS_MUTEX_INITIALIZER; /** @@ -1038,7 +1040,8 @@ parse_tc_flower_to_match(struct tc_flower *flower, } break; case TC_ACT_POLICE: { - /* Not supported yet */ + nl_msg_put_u32(buf, OVS_ACTION_ATTR_METER, + action->police.meter_id); } break; } @@ -1961,6 +1964,17 @@ 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; + + action->type = TC_ACT_POLICE; + action->police.meter_id = nl_attr_get_u32(nla); + if (meter_id_lookup(action->police.meter_id, &police_index)) { + return EOPNOTSUPP; + } + + action->police.index = police_index; + flower.action_count++; } else { VLOG_DBG_RL(&rl, "unsupported put action type: %d", nl_attr_type(nla)); diff --git a/lib/tc.c b/lib/tc.c index 16d4ae3da..ecdcb676d 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -2421,6 +2421,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) { @@ -2911,7 +2927,14 @@ nl_msg_put_flower_acts(struct ofpbuf *request, struct tc_flower *flower) } break; case TC_ACT_POLICE: { - /* Not supported yet */ + struct tc_cookie act_cookie; + + act_offset = nl_msg_start_nested(request, act_index++); + nl_msg_put_act_police_index(request, action->police.index); + act_cookie.data = &action->police.meter_id; + act_cookie.len = sizeof(action->police.meter_id); + nl_msg_put_act_cookie(request, &act_cookie); + nl_msg_end_nested(request, act_offset); } break; } From patchwork Tue May 3 03:08:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianbo Liu X-Patchwork-Id: 1625302 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=CitVkaty; 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 4KslLM2tjZz9sFr for ; Tue, 3 May 2022 13:09:31 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 284D683ED3; Tue, 3 May 2022 03:09:29 +0000 (UTC) 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 2GMpAdvWS3U1; Tue, 3 May 2022 03:09:26 +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 B188C83EEA; Tue, 3 May 2022 03:09:22 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id DF23AC0088; Tue, 3 May 2022 03:09:20 +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 407C7C0084 for ; Tue, 3 May 2022 03:09:19 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 6680160FF6 for ; Tue, 3 May 2022 03:09:04 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp3.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=nvidia.com 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 seOxHXcJy5ok for ; Tue, 3 May 2022 03:09:02 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2062d.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe59::62d]) by smtp3.osuosl.org (Postfix) with ESMTPS id 55B8A60FF1 for ; Tue, 3 May 2022 03:09:01 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N3lp4xJFKt8U31IrxvpdyADrTYk8zGznlegrIlUyGGE8uZ+JdDq33HXeYwSQUSt/WxZxVOSVgdR9OAb7ru3V+eryJWYqdAIJaIYejSVm7P/e8CPvoozT/0U/k9iXuoNqPxjP0Dhh/Zi+1u3Sd4p4sVMkd8KMPhJ5tTVOd/tbJTUlM/xfBROwZn52M+Y3vbwWLHNDTwmeW4x31BpkBD3PalqNC/+OBywZYFnCbbs2X9fYbM4krv7gEajnlp6CW4p3cPdV1rEwFHCbmD2p5MB886XJCACP/zMe5cx32TXDMTuLgyt/HzevVxW8sL5okvRrSEY+SbsBJXQscY8QkxUSqQ== 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=qjMAYwtFTRZhCm3dVkYvykXC+c6h5lbZgL6n0CXwNuo=; b=HQGBkZ1pIAvZjkyHauprn7/z1W6D1K0e9PHA39HD6AKTmDuFfGKv8yhS1UDLHO+U7k94Nib6j48v/a29Roh4YJV7AEfyhi3PTjW9G0CXAUyGhQkF1Gc89uR1S1/72Xd/B4+7cDy6grsgPbdbvCmoKf3VwD0o5i1mOLCNtUcwBSo3l7c0irpsnCd8K28vO1BJbiNvetXc6scpazATt2K/R7YM9inHD/A3ZCvK/VRy4pCVFz2wUkbpUHo3TeWK9wzsYvq6ZGAdVgvrLn0GnrUfMAuEvHnit8AQjQWqI81FTrp/RkHL+NC9FGurLfo5pJzKHNaEMeOOdxLnz5pRR64SpQ== 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=qjMAYwtFTRZhCm3dVkYvykXC+c6h5lbZgL6n0CXwNuo=; b=CitVkaty6F5lypSCNkL7VE4gHefk3omhIzeoFsLAruoKtAtAy7S+B5uurUyAy0EjhkeZAROEEX6aIQwGM3HcQyIlON16emgEnjLpUSA93G/w9GEJsYAYwEYUlS5ZV+Yx2xS00v1kmUsL6yd6mT7Aptws82Qy8kagNHp5r9t/TEgQsRnGxYHAARsUR/n1QwJertwgGD0hw4cATZnM8LgaKZYBNdUkZtxsL2yBrihnH2HPOKRiJH7xlAIDgHWrJpgyMx179l48Yw/gutJ9cZ4wEp6amVb6x4kSLIhgkUPvt7rhXsVYz+oZyy7K1+q9mM7hzZDnBEHIbXfBqilUg3XKOQ== Received: from DS7PR03CA0059.namprd03.prod.outlook.com (2603:10b6:5:3b5::34) by DM5PR1201MB0154.namprd12.prod.outlook.com (2603:10b6:4:58::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.15; Tue, 3 May 2022 03:08:58 +0000 Received: from DM6NAM11FT058.eop-nam11.prod.protection.outlook.com (2603:10b6:5:3b5:cafe::2) by DS7PR03CA0059.outlook.office365.com (2603:10b6:5:3b5::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.24 via Frontend Transport; Tue, 3 May 2022 03:08:58 +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; Received: from mail.nvidia.com (12.22.5.234) by DM6NAM11FT058.mail.protection.outlook.com (10.13.172.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5206.12 via Frontend Transport; Tue, 3 May 2022 03:08:58 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by DRHQMAIL101.nvidia.com (10.27.9.10) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Tue, 3 May 2022 03:08:58 +0000 Received: from drhqmail203.nvidia.com (10.126.190.182) by drhqmail203.nvidia.com (10.126.190.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.22; Mon, 2 May 2022 20:08:57 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.126.190.182) with Microsoft SMTP Server id 15.2.986.22 via Frontend Transport; Mon, 2 May 2022 20:08:55 -0700 To: , , , , Date: Tue, 3 May 2022 03:08:36 +0000 Message-ID: <20220503030836.28783-9-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220503030836.28783-1-jianbol@nvidia.com> References: <20220503030836.28783-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d2690c49-b8cc-4b96-23a2-08da2cb24441 X-MS-TrafficTypeDiagnostic: DM5PR1201MB0154:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5YIt6GqSdSQb/98j7E1XjL0iyvs9cahcs86c2GSrlajpIfAwSVTgf7cy6JhqGPXuIrlrT4flBx7RR6gS1/0Sq6NIBjN3KoCwp29YwIZ87i9r+D9ZP4MOfw2+kqWb/GGB80QUVCbBVJJlx5T3Ec5mlXToAxwg/6c18MbnL5VVKhX25Pc1Heq/yLDs1ipRREasG9oR0zo3TU/ndTI4NxKqAL7RjhT9jNLijLCrBqT+vwyuEs8mH3vNtOawizm4N4Tu97ZqFBPjmotY+mate61BYSzpboMEpDkcxy6vPaME2utwcKw4nSKu20DgnM9iJf1AgFJ+ezohLCmAHOT7ulnohxmlhREciaHHNGKpRMj+z6kLogLA+iyE/m1suBq2dPuOM/ZWBPu22OT5YZ9kIeuUSPreq1ClFTkzYQCLBMIS2D4oeO/ZsAIYQN/LMFwFK9aZnXnD/A19h+SU1Z2/BKFNQETT7GDzl7jcGoRPWb2lbP0Go7lab1Wiafc92i9M5WUhenJX8fXEj1wAYn4dqJ9CzgykxOxnJue67FGvSxG5Up6+VcdBFy9tNrKjiBKdeHQ3eCohlj+VaYAXkHZGfAqd9I6DHCVYnNIrMIgrzL73Fokt92u5FrOUROpqh2turcTgBSD40oMDmGlPLbgh3+MRhkydGH85NAEW+jjXbJdn8xcAhb3At6G/aldXEIz7ILIy6qEbk30QWTW/M9IigBKv3w== 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:(13230001)(4636009)(40470700004)(46966006)(36840700001)(47076005)(2616005)(1076003)(40460700003)(426003)(186003)(83380400001)(2906002)(336012)(36756003)(26005)(8936002)(107886003)(356005)(7696005)(6666004)(81166007)(5660300002)(110136005)(36860700001)(508600001)(4326008)(70586007)(86362001)(8676002)(316002)(82310400005)(70206006)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 May 2022 03:08:58.6017 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d2690c49-b8cc-4b96-23a2-08da2cb24441 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: DM6NAM11FT058.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0154 Cc: Jianbo Liu Subject: [ovs-dev] [v4 8/8] 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 | 12 ++++++++++++ 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 1e107340f..bed398c2c 100644 --- a/NEWS +++ b/NEWS @@ -26,6 +26,8 @@ Post-v2.17.0 - Windows: * Conntrack support for TCPv6, UDPv6, ICMPv6, FTPv6. * IPv6 Geneve tunnel support. + - 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 71e35ccdd..2fa639529 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, max_bands); + } + + 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, max_bands); + } + + return err; } static bool diff --git a/tests/system-offloads-traffic.at b/tests/system-offloads-traffic.at index 80bc1dd5c..b6f1e8411 100644 --- a/tests/system-offloads-traffic.at +++ b/tests/system-offloads-traffic.at @@ -168,3 +168,15 @@ matchall ]) OVS_TRAFFIC_VSWITCHD_STOP AT_CLEANUP + +AT_SETUP([offloads - check if meter is offloaded ]) +AT_KEYWORDS([meter]) +AT_SKIP_IF([test $HAVE_TC = "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']) +AT_CHECK([test `tc action list action police | grep 'police 0x10000000' | wc -l` -eq 1 ]) + +OVS_TRAFFIC_VSWITCHD_STOP +AT_CLEANUP