From patchwork Sat Jul 2 03:18:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianbo Liu X-Patchwork-Id: 1651426 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=mbXnMcdQ; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::137; helo=smtp4.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LZckM6lYbz9ryY for ; Sat, 2 Jul 2022 13:19:39 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id DDF1F42540; Sat, 2 Jul 2022 03:19:37 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org DDF1F42540 Authentication-Results: smtp4.osuosl.org; dkim=fail reason="signature verification failed" (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=mbXnMcdQ X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xknYbkrITduE; Sat, 2 Jul 2022 03:19:36 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id 37B5442535; Sat, 2 Jul 2022 03:19:35 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 37B5442535 Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 01BB7C0035; Sat, 2 Jul 2022 03:19:35 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [IPv6:2605:bc80:3010::137]) by lists.linuxfoundation.org (Postfix) with ESMTP id 2B989C0039 for ; Sat, 2 Jul 2022 03:19:34 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id DB96F418CF for ; Sat, 2 Jul 2022 03:19:06 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org DB96F418CF X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id c4P7csnGtUQm for ; Sat, 2 Jul 2022 03:19:05 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 574F7416BC Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2048.outbound.protection.outlook.com [40.107.220.48]) by smtp4.osuosl.org (Postfix) with ESMTPS id 574F7416BC for ; Sat, 2 Jul 2022 03:19:05 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DonpKTzSB2TE5138MY56FmphGQ/PDJW7sP2twS0+w0WdIM9ohhsyiWJWrSX2VnjZCIk5VavjnPTi8MG378MnNCQ8670Rhf1HghiF3/NugqnPn+UW3puzPn9RL5QAVWfA9JU0do5TatbbhM8cCsXPEE/xbHruXN35al31Bu6zsgoMWUsfmv90SyTFwVX0sAA+7Rnm0Z5/c1sP2jOBpaFT8OI18do/hj9U0qJLi2B4PnGzdkoAKuolJ//p/4//TYcTNpe3IephemmrMJPqZznMl+B08os141pm1mzhPcJxSFk02VgHMTDV3pezkHzXovho19u/E7Mk+fuR1ATyElN7+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Qd9WsEGtOFmDEWHWTl2NI2gMvF953sN1goam1O/k/kk=; b=Fde97xMeIqi9ZpBq0H2jUsDFiw4wK2kuFtKKOiA2z8tphphYuhkOVRqnez5EW+buqta6GehWW0uv2dsa1XHF87zUrHTT5Oy2MHtH/eRwOTWjk0f/4mhIozDwQxI3HB22hxHJwzHcFFwPGrcA/1wzt5vg7mcXoGjuU93gKZ76kXuuy6+KdRYPPFbNl1DXe0FsLC4pnpm1ofUqzbdmmZBZI0m3dyhA6MN6+MWkgMME6xutamiRI7A0EG3q5buocRNJ7b3Db+nxGgmAoYFcsinEx87Ub3vq24KIhNS7qtv3s6a1XmEs23zGyDt6uBAHKZrY+csrCFMMK/yei7GXTykDsA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=corigine.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Qd9WsEGtOFmDEWHWTl2NI2gMvF953sN1goam1O/k/kk=; b=mbXnMcdQoxSlzCPnxwu8WZ5RuG97n5xGLgNJ01r1vMRoNYsJ9MFVGAQZ2V7N3aEWdP/v9vor9y2iAmlLZw8fT8I0ScyX+Xpr4HJpj9ZYsMCpU2QdrkkrlmmmW1tVfEMTWf4BRQjWh8hU4p5NtLmB55SAZLkRQGv823NnHvXaaaC/IQvQ4eDKRLr0Lr92+9LoJ/lPF8FTA9HoRYHuJ5Be/S79hY4w4Y9tkgf1riAcpWrTmHE9TS4NL/ppbSnlHkVray18PrXBbt+M8REsb9re4X/2mgm5WHPLxIQyP7XRj9emvH0WZmqxk4FlNfqb0KOAlLLi63V+plZxOvrKPX9XQg== Received: from DM6PR08CA0015.namprd08.prod.outlook.com (2603:10b6:5:80::28) by MW3PR12MB4441.namprd12.prod.outlook.com (2603:10b6:303:59::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.17; Sat, 2 Jul 2022 03:18:56 +0000 Received: from DM6NAM11FT011.eop-nam11.prod.protection.outlook.com (2603:10b6:5:80:cafe::9c) by DM6PR08CA0015.outlook.office365.com (2603:10b6:5:80::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.17 via Frontend Transport; Sat, 2 Jul 2022 03:18:56 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (12.22.5.238) by DM6NAM11FT011.mail.protection.outlook.com (10.13.172.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5395.17 via Frontend Transport; Sat, 2 Jul 2022 03:18:56 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Sat, 2 Jul 2022 03:18:55 +0000 Received: from rnnvmail205.nvidia.com (10.129.68.10) by rnnvmail205.nvidia.com (10.129.68.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Fri, 1 Jul 2022 20:18:55 -0700 Received: from vdi.nvidia.com (10.127.8.14) by mail.nvidia.com (10.129.68.10) with Microsoft SMTP Server id 15.2.986.26 via Frontend Transport; Fri, 1 Jul 2022 20:18:53 -0700 To: , , , , , Date: Sat, 2 Jul 2022 03:18:30 +0000 Message-ID: <20220702031832.13282-8-jianbol@nvidia.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220702031832.13282-1-jianbol@nvidia.com> References: <20220702031832.13282-1-jianbol@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5c9c61fc-0b0f-411d-e786-08da5bd99957 X-MS-TrafficTypeDiagnostic: MW3PR12MB4441:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Sp0TYqrxF/lt8U5yZefDkphBOHsQzjMyfOnhxn63LBS/60+UlIJgZlR6i2CMrUO2aTNbc7+ZWftGciNOONvMFa9ng5uzHCv9liLuyVDRS2op0ajL+7NONWimH4v1wpuEtjXS9LE9YN/XyNjTNfu8iykCQAN2CCNnRcf+8rp76sNQQ4ZvQbh46I0mpRMGZZcs0VHz3+mZZ9vjse4F872BKQLRSbyeJUnjO5pSSD1EAfP30EpqWWWzaYsX8H48prmiKfc3VAT0QX8lnyWKQu5KXxfWsVUY6Aes/TuGlDdkCyi882tH/uZiJKZit9tKKvvnzkzKpovY4Uvwpw953qylgTGTQL+NL+0H3TnY8LS96v+7KbgvLaC+HXiAPHkQbGufkuadkw1ScdMdtL2aHKQnppA3CbpucSlhv9MMnSAyCLzkImB7tX1myrrtjCI/Zy6xomb0itXRoKBsGkoCq5TQd20sDVDtrBNrVMxWnpzf8PyvMxHTFWjBxzYYfZlApRBhO287Jfe5aHE3xNRqqEBNt8Dx8H/2yjslM3q78o8DGQbHCzmU+sAi/t3/h8bggJq3qSvLqRk2KmFFCykp0RLmT0Vh8zsQOJVMUNDrMdw7b6MJiL4o3U4C4gta8EZTnwxI3F7E2zRs0YkfnbEU2l0jgikifoUUB/5ufDcw7c54rGQZUpwNXCRWtJCn8xit6zMJ0viSvNZiqnxBh0bLREU6tlp/jXxhMMYTwO4vh3FF2XZ4mBU8ZEVQ4KpOhib4h7psTG5/kw2H7p2Q5/QFg1xUPntF8tkFGcXo5NiHNgC9/oYJsmnbAvHeCMNN+yvle4GjowSEL0GAdieOcvbbL/nGOazECbKOGz5aq2Z0u4rAcgM= X-Forefront-Antispam-Report: CIP:12.22.5.238; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230016)(4636009)(136003)(39860400002)(396003)(346002)(376002)(46966006)(40470700004)(36840700001)(82740400003)(5660300002)(426003)(356005)(1076003)(47076005)(81166007)(26005)(8936002)(7696005)(478600001)(83380400001)(186003)(107886003)(2616005)(6666004)(336012)(41300700001)(36860700001)(2906002)(40460700003)(316002)(40480700001)(82310400005)(70206006)(70586007)(36756003)(86362001)(4326008)(8676002)(110136005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jul 2022 03:18:56.3958 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5c9c61fc-0b0f-411d-e786-08da5bd99957 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.238]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT011.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW3PR12MB4441 Cc: Jianbo Liu Subject: [ovs-dev] [v6 7/9] netdev-offload-tc: Offloading rules with police actions X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jianbo Liu via dev From: Jianbo Liu Reply-To: Jianbo Liu Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" When offloading rule, tc should be filled with police index, instead of meter id. As meter is mapped to police action, and the mapping is inserted into meter_id_to_police_idx hmap, this hmap is used to find the police index. Besides, the reverse mapping between meter id and police index is also added, so meter id can be retrieved from this hashmap and pass to dpif while dumping rules. Signed-off-by: Jianbo Liu Acked-by: Eelco Chaudron --- lib/netdev-offload-tc.c | 47 ++++++++++++++++++++++++++++++++++++++++- lib/tc.c | 20 +++++++++++++++++- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c index 7de51a6e0..3d53c82dd 100644 --- a/lib/netdev-offload-tc.c +++ b/lib/netdev-offload-tc.c @@ -66,6 +66,7 @@ struct chain_node { struct meter_police_mapping_data { struct hmap_node meter_id_node; + struct hmap_node police_idx_node; uint32_t meter_id; uint32_t police_idx; }; @@ -84,6 +85,11 @@ static struct id_pool *meter_police_ids OVS_GUARDED_BY(meter_police_ids_mutex); static struct ovs_mutex meter_mutex = OVS_MUTEX_INITIALIZER; static struct hmap meter_id_to_police_idx OVS_GUARDED_BY(meter_mutex) = HMAP_INITIALIZER(&meter_id_to_police_idx); +static struct hmap police_idx_to_meter_id OVS_GUARDED_BY(meter_mutex) + = HMAP_INITIALIZER(&police_idx_to_meter_id); + +static int meter_id_lookup(uint32_t meter_id, uint32_t *police_idx); +static int police_idx_lookup(uint32_t police_idx, uint32_t *meter_id); static bool is_internal_port(const char *type) @@ -1041,7 +1047,12 @@ parse_tc_flower_to_match(struct tc_flower *flower, } break; case TC_ACT_POLICE: { - /* Not supported yet */ + uint32_t meter_id; + + if (police_idx_lookup(action->police.index, &meter_id)) { + return ENOENT; + } + nl_msg_put_u32(buf, OVS_ACTION_ATTR_METER, meter_id); } break; } @@ -1964,6 +1975,16 @@ netdev_tc_flow_put(struct netdev *netdev, struct match *match, action->type = TC_ACT_GOTO; action->chain = 0; /* 0 is reserved and not used by recirc. */ flower.action_count++; + } else if (nl_attr_type(nla) == OVS_ACTION_ATTR_METER) { + uint32_t police_index, meter_id; + + meter_id = nl_attr_get_u32(nla); + if (meter_id_lookup(meter_id, &police_index)) { + return EOPNOTSUPP; + } + action->type = TC_ACT_POLICE; + action->police.index = police_index; + flower.action_count++; } else { VLOG_DBG_RL(&rl, "unsupported put action type: %d", nl_attr_type(nla)); @@ -2443,6 +2464,27 @@ meter_id_lookup(uint32_t meter_id, uint32_t *police_idx) return data ? 0 : ENOENT; } +static int +police_idx_lookup(uint32_t police_idx, uint32_t *meter_id) +{ + struct meter_police_mapping_data *data; + size_t hash = hash_int(police_idx, 0); + int err = ENOENT; + + ovs_mutex_lock(&meter_mutex); + HMAP_FOR_EACH_WITH_HASH (data, police_idx_node, hash, + &police_idx_to_meter_id) { + if (data->police_idx == police_idx) { + *meter_id = data->meter_id; + err = 0; + break; + } + } + ovs_mutex_unlock(&meter_mutex); + + return err; +} + static void meter_id_insert(uint32_t meter_id, uint32_t police_idx) { @@ -2454,6 +2496,8 @@ meter_id_insert(uint32_t meter_id, uint32_t police_idx) data->police_idx = police_idx; hmap_insert(&meter_id_to_police_idx, &data->meter_id_node, hash_int(meter_id, 0)); + hmap_insert(&police_idx_to_meter_id, &data->police_idx_node, + hash_int(police_idx, 0)); ovs_mutex_unlock(&meter_mutex); } @@ -2466,6 +2510,7 @@ meter_id_remove(uint32_t meter_id) data = meter_id_find_locked(meter_id); if (data) { hmap_remove(&meter_id_to_police_idx, &data->meter_id_node); + hmap_remove(&police_idx_to_meter_id, &data->police_idx_node); free(data); } ovs_mutex_unlock(&meter_mutex); diff --git a/lib/tc.c b/lib/tc.c index 74e2d6caf..392dee632 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -2444,6 +2444,22 @@ nl_msg_put_act_gact(struct ofpbuf *request, uint32_t chain) nl_msg_end_nested(request, offset); } +static void +nl_msg_put_act_police_index(struct ofpbuf *request, uint32_t police_idx) +{ + struct tc_police police; + size_t offset; + + memset(&police, 0, sizeof police); + police.index = police_idx; + + nl_msg_put_string(request, TCA_ACT_KIND, "police"); + offset = nl_msg_start_nested(request, TCA_ACT_OPTIONS); + nl_msg_put_unspec(request, TCA_POLICE_TBF, &police, sizeof police); + nl_msg_put_u32(request, TCA_POLICE_RESULT, TC_ACT_PIPE); + nl_msg_end_nested(request, offset); +} + static void nl_msg_put_act_ct(struct ofpbuf *request, struct tc_action *action) { @@ -2934,7 +2950,9 @@ nl_msg_put_flower_acts(struct ofpbuf *request, struct tc_flower *flower) } break; case TC_ACT_POLICE: { - /* Not supported yet */ + act_offset = nl_msg_start_nested(request, act_index++); + nl_msg_put_act_police_index(request, action->police.index); + nl_msg_end_nested(request, act_offset); } break; }