From patchwork Wed Nov 10 16:28:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 1553495 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" (1024-bit key; unprotected) header.d=corigine.onmicrosoft.com header.i=@corigine.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-corigine-onmicrosoft-com header.b=HN60yOL4; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hq9Kq2frLz9sCD for ; Thu, 11 Nov 2021 03:29:35 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 9693340441; Wed, 10 Nov 2021 16:29:32 +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 kteWyQG8unna; Wed, 10 Nov 2021 16:29:30 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTPS id 32EC440426; Wed, 10 Nov 2021 16:29:29 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0BB2EC001E; Wed, 10 Nov 2021 16:29:29 +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 4CF44C0019 for ; Wed, 10 Nov 2021 16:29:28 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 3486B403E8 for ; Wed, 10 Nov 2021 16:29:28 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp4.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=corigine.onmicrosoft.com 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 m0bwKE94p57q for ; Wed, 10 Nov 2021 16:29:26 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20711.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe59::711]) by smtp4.osuosl.org (Postfix) with ESMTPS id 67B0C403CE for ; Wed, 10 Nov 2021 16:29:26 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hTTKnLMFUBSe8k094n3aSf+gTU5MEaGIeRD7jl7g0sQwhBXtPROht97gsEdvqyT6CisOqM6niU4GFbHE2f3mgjUTJSv60B1cl0RoqdQhNHAOr1+JiCWSQM8A4Ibf5TV32hoYJH2DdCZhUdOlp38vvg204YPOIKfrVweQaE/aK2J5vVR4kIkPzHA2XPAb9jzLb5N7JI7rxKT6T2mY0D7HrExRKJofaP/TZyko0QsvNiGzQa2MmkHFpKZJzMzQwr3W0gCfZ3UVENJyjDSZdUeTVME9VzKXDRVBIERRf6B1SF0noAMujCQB+bfZrPP/rvCi7n70uR7tsIIHF2fJbWrgdA== 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=W5vhlaKJrVLdmpveNVKyXgYIhtH4AmJMI6gHMDNJ5HA=; b=ZqHo7Llkp3siBtGNLrXwHI4lcoqzt57NpaNTbLF512oI0dt2ZO4fX+qAq3gPEjAfnj1CODy+5x5LySIup2bzW6biBdu1phhmhqtK0XZ9IbAsU/oRvNLFXFDns07lyyZgaiu5Nl5fdUPwOtEvq7g6Ots0KcLTgp4GHn4da5N5+D2yUHPDrQnxI0xmwng+j5EPRp2a+BX7mRxkAC5h6POpGDLeiB/LCcOTS50u6V27Mq1mniCvOMhQjPEEXjR40ep/p6JogYr91e6/m9avZWelMh6uZsF73vRq93+W+eWwfXDgeXO2p61DrQUF6vbqOz/bEs++O3z6t4NxJ8flI0V+EQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=W5vhlaKJrVLdmpveNVKyXgYIhtH4AmJMI6gHMDNJ5HA=; b=HN60yOL4rcvaZWSu3fDQMJaMCytmbZccBhESW7tgOmea5yuPLApFQhJxjlIyAGBh0vyZfGm+csW7cy9oWtehk1WdGstgdwvtAnCga9Ia9qLXpWJ2zCotmXm5qA9+JZZKP3s/Y3X84NE0zoKsUOjYvBCZXjKerikTwzlxi0XF6+M= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) by PH0PR13MB5639.namprd13.prod.outlook.com (2603:10b6:510:12a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.14; Wed, 10 Nov 2021 16:29:21 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::e1d9:64d0:cb4f:3e90]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::e1d9:64d0:cb4f:3e90%9]) with mapi id 15.20.4690.005; Wed, 10 Nov 2021 16:29:21 +0000 From: Simon Horman To: dev@openvswitch.org Date: Wed, 10 Nov 2021 17:28:52 +0100 Message-Id: <20211110162858.20101-2-simon.horman@corigine.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211110162858.20101-1-simon.horman@corigine.com> References: <20211110162858.20101-1-simon.horman@corigine.com> X-ClientProxiedBy: AM0PR02CA0224.eurprd02.prod.outlook.com (2603:10a6:20b:28f::31) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 Received: from madeliefje.horms.nl (80.113.23.202) by AM0PR02CA0224.eurprd02.prod.outlook.com (2603:10a6:20b:28f::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.15 via Frontend Transport; Wed, 10 Nov 2021 16:29:19 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7f3e702b-66db-45f7-3e3d-08d9a4673fb5 X-MS-TrafficTypeDiagnostic: PH0PR13MB5639: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: E0YrHnjVskOs6kETFjNdU4OUfWutYLbmmiaICuB8iXkhyx8ndU9IiWZhBolXEBjgaFSrgYo+fPpoi2HAfHi7d/l24k3b3di9HLD3JTmFYd9D+xa+svjhFYzpUfZo+4Qns5LhllLFoAWj6pSUhayXG/Wrc8OKS3UIkM5WM7MeSklG5x0Cmy/7twBHSmEj/nv9UzPLFMTZNwtqCUSiQxT/N19lSg887BZXQjyjz8FZEYX60iEQJ0Danct9nDaJyuWc4BFe3h+lGx27DQxrghpL0hbjnFbyIRAEYgoeirxWBnCjdPe+xg3KNqw3uzOc7eBSaepEI3H3b3KcWtsS0+f5/bp3MONtMv+P5fryl6xxvXRk0KYMM7u1Hx6e2Raoy+BTwdm/FVWfEGvLBmnIj5sh+Ik7CBSNmaSo4HDWnxminBHUAqPksdXtGXLlc8v/+W1swqBj9GtAMhc7g1bQkSnYft/ew0ckqUhTfp8fOSnJTi8o3I83VHXWqk9mD1NMcC2lVs4U3xbM3WWOchxxmJ5VI1XwbRfGGJquv6CnTc/Du6MJ9w2l7abDVBKK6Pllmz9fivLzZc6ikmo6029xO5K9610AyaVlWncUAqYZg2KKLFjkz17BuMmOW7Cw67A8Bv9AVfX0qbUsl4OBasJoMNRMOwlZeJh+xk3zWOXHWjfMJz5U9LPWYLzG5HCLeLWSReXB1XxRGebabzynHGCODRDNkQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH0PR13MB4842.namprd13.prod.outlook.com; PTR:; CAT:NONE; SFS:(346002)(376002)(396003)(39830400003)(366004)(136003)(1076003)(36756003)(86362001)(8676002)(66946007)(54906003)(107886003)(6512007)(44832011)(6666004)(316002)(30864003)(83380400001)(6916009)(956004)(66476007)(508600001)(4326008)(5660300002)(8936002)(2906002)(6506007)(52116002)(186003)(6486002)(26005)(38100700002)(38350700002)(66556008)(2616005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZWrwDxkpsizzrzrfiplS+yL+tCu+3ACnoSUovYLsly2lT4K9yn0I5jiLjCReztIn1mfXJb4c2gTkctsYXHwk3Rw9zsCuN+1x//VFvLp/QbwfOxs4rGydomK1RpOPOWT+Dq9xxDa647G2f4GudsjkqcP360AZ7inemWcG5mw5bjjDeD9B1VpFGUYqjJ2MV3EGoWQh+/y45TT/ucO4zlnjeo/6MYpJJ0eW9z9xmRuXH1DSEL8IXJeE3uYlexiRAF1AfFMHBKCiHekSlgSyynbM6u6WbWbWqcTRXiDEWDkYaCiEamx+PWq6H/YHEZLFwC69ZeHLaIVC3fVgN/dhc70rJPX5uRqz8qevnolyOaFg0kpvAe/QBIulEXGCHEVnztq2V6swAcv/16NB63uvnHMSHQALX0xoqRsSSQmXXyyLC4SmKYkahUu5oJ7jr5hBzyhJgeFG5K8AVX3LytYiXvlgZuXZ1U1o8Iyh/QrsVH1gLOMh//bNv2GXhWP9xXaidA5kWZYYVNBBGFUuXcEJwpsj+givdEiA9G2QawA9n6gl2wC475JL7sG1TchflI1TRPpQPZ56rXVrzj8rW10mfXGqdeo5b5AHh2Wj9tpBTCudH6RrYTQ4BWLX0dtr4KLrE+aJReqLgXiDsyGeIS/F75qGk6U/CQV24kZfdssJIhN3dkD5hoQkZUBSZjALozS/8vBdvkLSaZgP1XUw2JOFTg7patslqJ3NROaNSPdDBshb8Ele+j2XPzEIWcYTw1H5W17Y6oHRNs7EFy/PEWu4Pt5cpbd3sNSE5YkRZMfXi4G84lf18hzs1jAj5l/UMsrul01qytwqv0bE/c8OkW4DjpL+yafyx7FnOmeJjqcuurl63NtMqTmGJmp7Z2wjJ8XQFT3/m+PtPDLH+UC2fDMgALm/ifR9sQKEW+7RLdEx8BCQqFlpIM6/YH9TYrDvU10f12P5yVlv/eiGMw17haLc3tUCNZPa+otLlU/3RNrLay+X7WpmieFuUsWbhrxFLL1ICDXRqWuFDIE3hQMjX9QE9Y0SAwHD+n6PCK8qY9hXClmx/VZqbgY93o/IfOj+cb7MqhZLZxRuI1FAKT7xiwZPrvbJ7DDHFNJFYiKt008lTEK4JfLKQoylse1GAwRe/Yj6Pk1ZtIAdgQU4RhNsfX8sRsWdb1QKWRTCnaTXwHLiRfuncXjEum4xONL+hM5jq653PdUVY89T8cRBGDCjP4pEw2I+FwaiizL+GDFbb+WZCFLJ4v3iJWW6NQMpDeBB9txoGMIgSgqtPkf9aUSeQ5W2VFDcX+fodYyHlw4FUjGnulggDp0DEgUZhay7wmgMZlobSmKl9vvaWOYDRjsztRi9fBkzrcL8ku9bAOaa/ZHEOxBy+/H7w0TmJqzEKKIUsr6h4HAE//YXrF5lTiH/KM44lXi3TbFNdv0dNzMVcPnR0X+2rZZWO1yluhqBDOjobHcaal8HZkVp+9aieAImjY6ekEJyGVLvTZI5PFfouwVPC0PSOlK/LAOiJR+4bUOlDWumuPJ4gDxE5+Y1bxyVHMvupMDmjltS0qHL8S7xImQ1Eq2QbaT7P7uIUkPXhXWuY0P3qFPzyhsOL69n5aOA6jLQaRlMuZ/xxaBqWHomgCImINZjKEEtM3lrYRchh6LRVxYmW3FzVbzJa3nyh2200y1nN/gnHw== X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7f3e702b-66db-45f7-3e3d-08d9a4673fb5 X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Nov 2021 16:29:20.9355 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 9kqcsO2joZhXKsXzJBuO2cifkrbpO0GCUXoJ7l4wa5QRnfmHPZmQpB/3AWmK6GzHiYR9OAT7u5zjylfNd2J/HnxeEMFEZYPJKZUO93MJii0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR13MB5639 Cc: Baowen Zheng , Tianyu Yuan , oss-drivers@corigine.com Subject: [ovs-dev] [PATCH/RFC 1/7] dpif-netlink: add support for offload of meters 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: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Baowen Zheng Allow hardware offload of meters via OVS-TC by reflecting meter configuration into the TC datapath as TC police actions whose lifecycle is independent of flows. A follow-up patch will make use of such TC policer action instances by referring to them by index in TC flower classifiers (flows added to the TC datapath) that use OF meter actions. Signed-off-by: Baowen Zheng Signed-off-by: Tianyu Yuan Signed-off-by: Simon Horman --- lib/dpif-netdev.c | 2 +- lib/dpif-netlink.c | 114 +++++++++++++++++++++++++++++++++++-- lib/dpif-provider.h | 2 +- lib/dpif.c | 4 +- lib/dpif.h | 2 +- lib/netdev-linux.c | 8 +-- lib/tc.c | 13 +++++ lib/tc.h | 7 +++ ofproto/ofproto-dpif.c | 4 +- ofproto/ofproto-provider.h | 2 +- ofproto/ofproto.c | 3 +- 11 files changed, 143 insertions(+), 18 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 98453a206..bf4de3cf4 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -6490,7 +6490,7 @@ dp_netdev_run_meter(struct dp_netdev *dp, struct dp_packet_batch *packets_, /* Meter set/get/del processing is still single-threaded. */ static int dpif_netdev_meter_set(struct dpif *dpif, ofproto_meter_id meter_id, - struct ofputil_meter_config *config) + bool add OVS_UNUSED, struct ofputil_meter_config *config) { struct dp_netdev *dp = get_dp_netdev(dpif); uint32_t mid = meter_id.uint32; diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index 18cdfe6e5..3c42db0fa 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -60,6 +61,7 @@ #include "packets.h" #include "random.h" #include "sset.h" +#include "tc.h" #include "timeval.h" #include "unaligned.h" #include "util.h" @@ -273,6 +275,16 @@ static int dpif_netlink_vport_from_ofpbuf(struct dpif_netlink_vport *, static int dpif_netlink_port_query__(const struct dpif_netlink *dpif, odp_port_t port_no, const char *port_name, struct dpif_port *dpif_port); +unsigned int tc_bytes_to_ticks(unsigned int rate, unsigned int size); +void tc_put_rtab(struct ofpbuf *msg, uint16_t type, + const struct tc_ratespec *rate); +void tc_fill_rate(struct tc_ratespec *rate, uint64_t bps, int mtu); +static void dpif_netlink_police_start_nested(struct ofpbuf *request, int *prio, + size_t *total_offset, + size_t *basic_offset); +static void dpif_netlink_police_end_nested(struct ofpbuf *request, + size_t *total_offset, + size_t *basic_offset); static int create_nl_sock(struct dpif_netlink *dpif OVS_UNUSED, struct nl_sock **sockp) @@ -3959,6 +3971,23 @@ dpif_netlink_ct_timeout_policy_dump_done(struct dpif *dpif OVS_UNUSED, * zero. Check for that condition and disable meters on those kernels. */ static bool probe_broken_meters(struct dpif *); +static void +dpif_netlink_police_start_nested(struct ofpbuf *request, int *prio, + size_t *total_offset, size_t *basic_offset) +{ + *total_offset = nl_msg_start_nested(request, TCA_ACT_TAB); + *basic_offset = nl_msg_start_nested(request, ++*prio); + nl_msg_put_string(request, TCA_KIND, "police"); +} + +static void +dpif_netlink_police_end_nested(struct ofpbuf *request, size_t *total_offset, + size_t *basic_offset) +{ + nl_msg_end_nested(request, *basic_offset); + nl_msg_end_nested(request, *total_offset); +} + static void dpif_netlink_meter_init(struct dpif_netlink *dpif, struct ofpbuf *buf, void *stub, size_t size, uint32_t command) @@ -4067,9 +4096,80 @@ dpif_netlink_meter_get_features(const struct dpif *dpif_, ofpbuf_delete(msg); } +/* add/remove police action for the meter configuration */ +static int +dpif_netlink_meter_add_police(ofproto_meter_id meter_id, + struct ofputil_meter_config *config, + bool add) +{ + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20); + struct ofputil_meter_band * band = &config->bands[0]; + unsigned int pkt_burst_ticks = 0, pps_rate = 0; + struct tc_police tc_police; + struct ofpbuf request; + struct tcamsg *tcmsg; + size_t total_offset; + size_t basic_offset; + size_t act_offset; + int mtu = 65535; + int prio = 0; + int error; + + tcmsg = tc_act_make_request(RTM_NEWACTION, + (add ? NLM_F_EXCL : NLM_F_REPLACE) + | NLM_F_CREATE, &request); + if (!tcmsg) { + return ENODEV; + } + + if (config->n_bands > 1) { + VLOG_ERR_RL(&rl, "TC offloading does not support more than one band"); + return EINVAL; + } + memset(&tc_police, 0, sizeof tc_police); + dpif_netlink_police_start_nested(&request, &prio, &total_offset, + &act_offset); + tc_police.action = TC_POLICE_SHOT; + tc_police.mtu = mtu; + tc_police.index = METER_ID_TO_POLICY_INDEX(meter_id.uint32); + + if (config->flags & OFPMF13_KBPS) { + tc_fill_rate(&tc_police.rate, band->rate * 1000 / 8, mtu); + /* Set burst value to 1/5 of rate when the burst is not specified, + * and ratio from bit to byte is 1/8, therefore here is an ratio of + * 1/40 to calculate the burst */ + tc_police.burst = tc_bytes_to_ticks( + tc_police.rate.rate, band->burst_size ?\ + band->burst_size * 1000 / 8 : tc_police.rate.rate / 40); + } else { + pps_rate = band->rate; + pkt_burst_ticks = tc_bytes_to_ticks(pps_rate, band->burst_size? + band->burst_size : pps_rate / 5); + } + basic_offset = nl_msg_start_nested(&request, TCA_OPTIONS); + nl_msg_put_unspec(&request, TCA_POLICE_TBF, &tc_police, sizeof tc_police); + if (config->flags & OFPMF13_KBPS) { + tc_put_rtab(&request, TCA_POLICE_RATE, &tc_police.rate); + } else if (config->flags & OFPMF13_PKTPS) { + nl_msg_put_u64(&request, TCA_POLICE_PKTRATE64, (uint64_t) pps_rate); + nl_msg_put_u64(&request, TCA_POLICE_PKTBURST64, + (uint64_t) pkt_burst_ticks); + } + nl_msg_end_nested(&request, basic_offset); + dpif_netlink_police_end_nested(&request, &total_offset, &act_offset); + error = tc_transact(&request, NULL); + if (error) { + VLOG_ERR_RL(&rl, "failed to send netlink msg for meterid %u error " + "%d\n", config->meter_id, error); + return error; + } + + return 0; +} + static int dpif_netlink_meter_set__(struct dpif *dpif_, ofproto_meter_id meter_id, - struct ofputil_meter_config *config) + bool add, struct ofputil_meter_config *config) { struct dpif_netlink *dpif = dpif_netlink_cast(dpif_); struct ofpbuf buf, *msg; @@ -4093,6 +4193,10 @@ dpif_netlink_meter_set__(struct dpif *dpif_, ofproto_meter_id meter_id, } } + if (netdev_is_flow_api_enabled()) { + dpif_netlink_meter_add_police(meter_id, config, add); + } + dpif_netlink_meter_init(dpif, &buf, stub, sizeof stub, OVS_METER_CMD_SET); nl_msg_put_u32(&buf, OVS_METER_ATTR_ID, meter_id.uint32); @@ -4146,13 +4250,13 @@ dpif_netlink_meter_set__(struct dpif *dpif_, ofproto_meter_id meter_id, static int dpif_netlink_meter_set(struct dpif *dpif_, ofproto_meter_id meter_id, - struct ofputil_meter_config *config) + bool add, struct ofputil_meter_config *config) { if (probe_broken_meters(dpif_)) { return ENOMEM; } - return dpif_netlink_meter_set__(dpif_, meter_id, config); + return dpif_netlink_meter_set__(dpif_, meter_id, add, config); } /* Retrieve statistics and/or delete meter 'meter_id'. Statistics are @@ -4270,8 +4374,8 @@ probe_broken_meters__(struct dpif *dpif) /* Try adding two meters and make sure that they both come back with * the proper meter id. Use the "__" version so that we don't cause * a recurve deadlock. */ - dpif_netlink_meter_set__(dpif, id1, &config1); - dpif_netlink_meter_set__(dpif, id2, &config2); + dpif_netlink_meter_set__(dpif, id1, true, &config1); + dpif_netlink_meter_set__(dpif, id2, true, &config2); if (dpif_netlink_meter_get(dpif, id1, NULL, 0) || dpif_netlink_meter_get(dpif, id2, NULL, 0)) { diff --git a/lib/dpif-provider.h b/lib/dpif-provider.h index 27e3a7658..0d092de9b 100644 --- a/lib/dpif-provider.h +++ b/lib/dpif-provider.h @@ -608,7 +608,7 @@ struct dpif_class { * * The meter id specified through 'config->meter_id' is ignored. */ int (*meter_set)(struct dpif *, ofproto_meter_id meter_id, - struct ofputil_meter_config *); + bool add, struct ofputil_meter_config *); /* Queries 'dpif' for meter stats with the given 'meter_id'. Stores * maximum of 'n_bands' meter statistics, returning the number of band diff --git a/lib/dpif.c b/lib/dpif.c index 38bcb47cb..069f17863 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -1928,7 +1928,7 @@ dpif_meter_get_features(const struct dpif *dpif, * The meter id specified through 'config->meter_id' is ignored. */ int dpif_meter_set(struct dpif *dpif, ofproto_meter_id meter_id, - struct ofputil_meter_config *config) + bool add, struct ofputil_meter_config *config) { COVERAGE_INC(dpif_meter_set); @@ -1950,7 +1950,7 @@ dpif_meter_set(struct dpif *dpif, ofproto_meter_id meter_id, } } - int error = dpif->dpif_class->meter_set(dpif, meter_id, config); + int error = dpif->dpif_class->meter_set(dpif, meter_id, add, config); if (!error) { VLOG_DBG_RL(&dpmsg_rl, "%s: DPIF meter %"PRIu32" set", dpif_name(dpif), meter_id.uint32); diff --git a/lib/dpif.h b/lib/dpif.h index 8febfb9f6..4398a4077 100644 --- a/lib/dpif.h +++ b/lib/dpif.h @@ -891,7 +891,7 @@ void dpif_print_packet(struct dpif *, struct dpif_upcall *); void dpif_meter_get_features(const struct dpif *, struct ofputil_meter_features *); int dpif_meter_set(struct dpif *, ofproto_meter_id meter_id, - struct ofputil_meter_config *); + bool add, struct ofputil_meter_config *); int dpif_meter_get(const struct dpif *, ofproto_meter_id meter_id, struct ofputil_meter_stats *, uint16_t n_bands); int dpif_meter_del(struct dpif *, ofproto_meter_id meter_id, diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 97bd21be4..5ace3ca02 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -477,7 +477,7 @@ static const struct tc_ops *const tcs[] = { }; static unsigned int tc_ticks_to_bytes(unsigned int rate, unsigned int ticks); -static unsigned int tc_bytes_to_ticks(unsigned int rate, unsigned int size); +unsigned int tc_bytes_to_ticks(unsigned int rate, unsigned int size); static unsigned int tc_buffer_per_jiffy(unsigned int rate); static uint32_t tc_time_to_ticks(uint32_t time); @@ -506,7 +506,7 @@ static int tc_query_qdisc(const struct netdev *netdev); void tc_put_rtab(struct ofpbuf *msg, uint16_t type, const struct tc_ratespec *rate); static int tc_calc_cell_log(unsigned int mtu); -static void tc_fill_rate(struct tc_ratespec *rate, uint64_t bps, int mtu); +void tc_fill_rate(struct tc_ratespec *rate, uint64_t bps, int mtu); static int tc_calc_buffer(unsigned int Bps, int mtu, uint64_t burst_bytes); @@ -5746,7 +5746,7 @@ tc_ticks_to_bytes(unsigned int rate, unsigned int ticks) /* Returns the number of ticks that it would take to transmit 'size' bytes at a * rate of 'rate' bytes per second. */ -static unsigned int +unsigned int tc_bytes_to_ticks(unsigned int rate, unsigned int size) { read_psched(); @@ -6106,7 +6106,7 @@ tc_calc_cell_log(unsigned int mtu) /* Initializes 'rate' properly for a rate of 'Bps' bytes per second with an MTU * of 'mtu'. */ -static void +void tc_fill_rate(struct tc_ratespec *rate, uint64_t Bps, int mtu) { memset(rate, 0, sizeof *rate); diff --git a/lib/tc.c b/lib/tc.c index 38a1dfc0e..3d54cd28e 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -199,6 +199,19 @@ tc_make_request(int ifindex, int type, unsigned int flags, return tcmsg; } +struct tcamsg * +tc_act_make_request(int type, unsigned int flags, struct ofpbuf *request) +{ + struct tcamsg *tcamsg; + + ofpbuf_init(request, 16384); + 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) diff --git a/lib/tc.h b/lib/tc.h index a147ca461..2408a0e92 100644 --- a/lib/tc.h +++ b/lib/tc.h @@ -52,6 +52,11 @@ enum tc_flower_reserved_prio { }; #define TC_RESERVED_PRIORITY_MAX (__TC_RESERVED_PRIORITY_MAX -1) +/* Mapping meter_id.uint32 into a 32-bit integer, first 8 fixed bits(ff) is + * the prefix of meter related policy, following 16 bits are mapped by + * meter_id, last 8 bits are reserved for bands in further. */ +#define METER_ID_TO_POLICY_INDEX(meter_id) 0xff << 24 | (meter_id + 1) << 8 + enum tc_qdisc_hook { TC_INGRESS, TC_EGRESS, @@ -78,6 +83,8 @@ tc_get_minor(unsigned int handle) return TC_H_MIN(handle); } +struct tcamsg *tc_act_make_request(int type, unsigned int flags, + struct ofpbuf *request); struct tcmsg *tc_make_request(int ifindex, int type, unsigned int flags, struct ofpbuf *); int tc_transact(struct ofpbuf *request, struct ofpbuf **replyp); diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index cba49a99e..5b89f5909 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -6688,7 +6688,7 @@ meter_get_features(const struct ofproto *ofproto_, static enum ofperr meter_set(struct ofproto *ofproto_, ofproto_meter_id *meter_id, - struct ofputil_meter_config *config) + bool add, struct ofputil_meter_config *config) { struct ofproto_dpif *ofproto = ofproto_dpif_cast(ofproto_); @@ -6703,7 +6703,7 @@ meter_set(struct ofproto *ofproto_, ofproto_meter_id *meter_id, } } - switch (dpif_meter_set(ofproto->backer->dpif, *meter_id, config)) { + switch (dpif_meter_set(ofproto->backer->dpif, *meter_id, add, config)) { case 0: return 0; case EFBIG: /* meter_id out of range */ diff --git a/ofproto/ofproto-provider.h b/ofproto/ofproto-provider.h index 57c7d17cb..5338971b2 100644 --- a/ofproto/ofproto-provider.h +++ b/ofproto/ofproto-provider.h @@ -1836,7 +1836,7 @@ struct ofproto_class { * leaving '*id' unchanged. On failure, the existing meter configuration * is left intact. */ enum ofperr (*meter_set)(struct ofproto *ofproto, ofproto_meter_id *id, - struct ofputil_meter_config *config); + bool add, struct ofputil_meter_config *config); /* Gets the meter and meter band packet and byte counts for maximum of * 'n_bands' bands for the meter with provider ID 'id' within 'ofproto'. diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index bd6103b1c..614bcec7c 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -6790,7 +6790,7 @@ handle_add_meter(struct ofproto *ofproto, struct ofputil_meter_mod *mm) } error = ofproto->ofproto_class->meter_set(ofproto, &provider_meter_id, - &mm->meter); + true, &mm->meter); if (!error) { ovs_assert(provider_meter_id.uint32 != UINT32_MAX); meter = meter_create(&mm->meter, provider_meter_id); @@ -6813,6 +6813,7 @@ handle_modify_meter(struct ofproto *ofproto, struct ofputil_meter_mod *mm) provider_meter_id = meter->provider_meter_id.uint32; error = ofproto->ofproto_class->meter_set(ofproto, &meter->provider_meter_id, + false, &mm->meter); ovs_assert(meter->provider_meter_id.uint32 == provider_meter_id); if (!error) { From patchwork Wed Nov 10 16:28:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 1553496 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" (1024-bit key; unprotected) header.d=corigine.onmicrosoft.com header.i=@corigine.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-corigine-onmicrosoft-com header.b=MV+YkYB0; 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 (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hq9Kq6pFTz9sRK for ; Thu, 11 Nov 2021 03:29:35 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 7B05E40416; Wed, 10 Nov 2021 16:29:33 +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 ARr0D1zVVg5N; Wed, 10 Nov 2021 16:29:32 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp4.osuosl.org (Postfix) with ESMTPS id 4C9BC403F2; Wed, 10 Nov 2021 16:29:31 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 1E0ACC0038; Wed, 10 Nov 2021 16:29:31 +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 420AAC0037 for ; Wed, 10 Nov 2021 16:29:29 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 5BB90403CE for ; Wed, 10 Nov 2021 16:29:28 +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 NtUsDAwIWNMa for ; Wed, 10 Nov 2021 16:29:27 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20711.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe59::711]) by smtp4.osuosl.org (Postfix) with ESMTPS id B54EE403D0 for ; Wed, 10 Nov 2021 16:29:26 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=isYRIA5vNu84DytSt9986txP09Jt6GM032mpHLoGer9nreK9AgT5t8CZbVP22m0FTmgUPfMGS2mG5Btsc/BI6AAVxqv/3PyenBH4bFwwj1LzMGzYhXgJBNnkqcaGRX8zTOAEu+f7YRg5ghRomKExsaA8eSG8s3nWYaAboqDGQRE8YTaEePktX+wdC0RjUCISCYgveDdZTSEj417CJD9OUwHcvNu7yww5q5AJJb+j/sREAh+lJHvT4SHtii3b+B1pE5oVAjnCyYwcDlbXCFyk5EP6ocT6nPlcPA30cQFQpA6pgypRNJGA1VH75nUmLFoInzg/PZaF5etYPbzdlGfnOw== 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=m8Nxr1xuooWHlF1VOJk0Ii2o7Hpzw8UFJwL6OMmk6ng=; b=JcZYsDtjb0XL2xmggWvpxmnIDt4xWtQymgElgzmhX45CerJ1IwaIekf5OpiF76E8hoWZEHNrBcmdtZOpK+RmYDY5SxSlGfxIwIOlyoe/V+v+p+xnkfIklrkyd4K3cYouIpktuKDe9fCL8Miw6dDrrHtrPo7raw1o0BEZ0nn6L2ho8glSnQi0sSpWKM6Mc/Zqn8LpghAxNZBLZnVM+alnKJyoshAV7LVa42gjAADDsYSDygpcnMlAl79q+XVxwRraPgSEwTxmyxYsiUAsG4BrEkk91NZ65R8K7fqfBgxbTmIaNKvQIUmvX+CtHz7up7n7Cz+AnLvzg5a/6Mdq7+cjxg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=m8Nxr1xuooWHlF1VOJk0Ii2o7Hpzw8UFJwL6OMmk6ng=; b=MV+YkYB0XnbXKN9889N9nznGeYCobtoxNVweIR/V/Xe5DEQ+8DBKBXHZNv1SA2MritdEQYUL4Enry1ybqpF5/Ty7IHILcN3eHz6MfwdAeudU+liOBMDzp5WpiBQ65Q+jn/sIwOFkim110Eu4SpyVFFSudekkIsD3VpwU6Hue+v8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) by PH0PR13MB5639.namprd13.prod.outlook.com (2603:10b6:510:12a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.14; Wed, 10 Nov 2021 16:29:23 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::e1d9:64d0:cb4f:3e90]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::e1d9:64d0:cb4f:3e90%9]) with mapi id 15.20.4690.005; Wed, 10 Nov 2021 16:29:23 +0000 From: Simon Horman To: dev@openvswitch.org Date: Wed, 10 Nov 2021 17:28:53 +0100 Message-Id: <20211110162858.20101-3-simon.horman@corigine.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211110162858.20101-1-simon.horman@corigine.com> References: <20211110162858.20101-1-simon.horman@corigine.com> X-ClientProxiedBy: AM0PR02CA0224.eurprd02.prod.outlook.com (2603:10a6:20b:28f::31) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 Received: from madeliefje.horms.nl (80.113.23.202) by AM0PR02CA0224.eurprd02.prod.outlook.com (2603:10a6:20b:28f::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.15 via Frontend Transport; Wed, 10 Nov 2021 16:29:21 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e7603d93-09a0-4e8d-bb1c-08d9a46740e8 X-MS-TrafficTypeDiagnostic: PH0PR13MB5639: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:209; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3xRFrzxKCF4PpX8wUlptpDqg+TdUIunoVGqnrmZlLQkumUoPw/baj2LWPH5dn/WWuc7L90Iu4T3T8pbFDnykWLxqjPkz6gXhyQqUKqHQq6ZtHGFpj/PdaKpJyLQtXyNn4hRwkLtvxqxVhvmm+niV1Q50KVFR3uMrL/ycoPYwZhpWRo+CxAIe3jZMa1w/+dz/SIUyefLqMpSYG1+OT0ul851rroJiBHpEOhgSXXUiwGgYqDGVSqFJvjSwIozzezpPCJ80JN8dh++iTXaMBS82dJZycYonIaH9KEGQQdqfN++ayaiKIXEwqG1tciQpGIkL5yWYhUO3UdXpOztaO8fwMBoP3xZHRGZyjpuQ8lodOkUtG9sxNT0KumJRr01F8npG0AGL4Ii3bxcgWl8q0drIGnsEprjA+pDypZSm3MufpIcdrict/envnLdZR/7JTEVAKywBxQGj8ozgX+PvpuFP7vH7ZU39upkYqyHFBqN59IuNDGxBdNhLA/xY72oHd336hHJwfC/vOT7dBHzb6RVqQN6nmnOt+gSznn6UhckwINQDGPIBFSAzC7tIPMc9v9hXQfwGkfW5zyK4WA0INGMphy0/QRMxNAM8deAGL8m8pHojo7v5d4egiR04UfKQpepwCJcpkhbZzcCn04eUWBOeWvzSntWfHcjq5OPh/YYf7H7IlfqujnwFulQkorlYC4NQJ34rCtk4t2BW/BVP1oJd0A== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH0PR13MB4842.namprd13.prod.outlook.com; PTR:; CAT:NONE; SFS:(346002)(376002)(396003)(366004)(39840400004)(136003)(1076003)(36756003)(86362001)(8676002)(66946007)(54906003)(107886003)(6512007)(44832011)(6666004)(316002)(83380400001)(6916009)(956004)(66476007)(508600001)(4326008)(5660300002)(8936002)(2906002)(6506007)(52116002)(186003)(6486002)(26005)(38100700002)(38350700002)(66556008)(2616005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lH3PVK/1d4CldaMqgTuRMRy/9ZJPTLssE5dUt3egawxPDeHKuNbNkmcYrE/no/K2lIIbhjXcy/mGTunDJKJUnRl+Nf3hzRlcOe5b2YXcgFPu+f5O6Jeznb1QdupzoNfgX+mbIM5O3U2EW4824Jyret1KY0gIDno3wjZJihmJh0QdzVqTLBV45U9YmgYvuHuSLI7Fty8U0xPjfJZBU1WFskL5AyyUYZwj5bzfB/gl4nkY3Sdlgw3lfLnVqAD+KMKulzJ4vqgsux9hmFlZaHaBoNJ+sMeirLJBzknaQJX2/q1ITLlnwpZHgJ9LqJeh5e4nq8kxgVSEli5qO9x2o+3E19Isq0famMpXfir35CkodI8IDFs3GRyo59tmyOsrTw+WrFs0pAcuhP8i3+OuuhS8AMFAkFbR90zW9eGB04fPBfe+GjQcOBC50mOZ5LC5Hr5oDKrjV9z/w0/10luYlzRN0fl+zxvHUueuxvoEpNjixEzBKco7CalrV0CaW+OT3nHmEziKDqnLzRytlpY+bd494MVmUVMI26n/TCAKLFGeglFMbnvu2udObjmb0ZnQdur8sZReKUNo6zhNKoQ9SDd1+/jrHwxu6Itu8YqSYHs8PXD3LwD7089gu+cPgcf69fEcZSdH52haW5jQM3GEO5oGNvd9xOn+4jL2/FGKhyHiS61/XH+oclLYIRUuFkyV0oYGeHUSRoJRZTG8j0g19GawyWlcilQVJ9wXqYcdVWJ3zjznavcOJnfgeLLengL70YBM83IdwgNrbyPjnjwU4MFmrJp4IuaRo2BV9WxXqyGhg/ee1pTo0MXN4B9J8T1H8/GNsXlDPsiW3UT0935LJgncn2q8lcp5P7NALFdkV2L8HKal9IXhddzSqUa+zrPMY+CKGoRQm+T9e6nGHNTTNve/kb0/YBFdgkcdKvr/tyKTBrHma9z/uNCtdCseto3hCqw49BnENoyXfCjEwDFqLnNtiiAgATfqCk07bGeb+GGnE9DKralmWwuqswRNHmAsEG/VbQZB777lMSY0qqNulBtp6cbpCqau8Y8bOdKch7W9pJbCMq7vQHLKbwsRLTVnjCxW/F978wRZCwsGET5KzH01J3EdhgNBK1LK66YCCPLOVMss4lT2lf6ikVsYkNHJj1wA1dczLfL+Gm1c4y6bukW8EIg4pPekUqyHuZYz+PUyo9o3/8BOUhgez5NVW3/F00Pj+rku7Vfp0PdKzF88rgt7FC7mfpvYcrxPBOh3Nxf5a7OE0F9PSRPThQpbrodV31g9fymPpk/8Xul7z5BuPQt/Mh+8ejP8YOSFXHw8EWw17+RufBeoEcXUFRhQ2/mu6S3vgCJU9L1DuWtUhl1G8Ti99pDLRZrlZFLWppyD2yuJzd4CwWy0QU+xYJAlbF0ZG4BoZV6nsQwe26VaHUHy4Ia6CHC8AV1ObQT+FvHrHnKQ2jsgDvALWxI1OwkpuwSWs4fA/2kaPRswJUQN+yzbTIPikL7Tnmctz64x/L9nHRHiUV9D7H5jR6E+Z78Ng9GbNgJY34+5oEd0MFMGOnuReElOTl0OtRyMMirppu4bkZzHUV4F4DHX8wP9+QcxRACrETd5SvWUE0tkAbEX+Vs1PkAYEyzC7CoOQH8puDBPMYcYhz2hOZab4jBBzr4WOfKOT8sB13TlRY4KFpiPPahExOsiBw== X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: e7603d93-09a0-4e8d-bb1c-08d9a46740e8 X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Nov 2021 16:29:22.9516 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: a4ozAgRuIL+QbtCh2FkQy6ZurVIApWLcHUyJBVFZ6bwzAu5fXFnmF/5Mopi3r1s6daZlAJC+jpOnjUB9UmWdssm4h1nHHsn70+c7wKBEueo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR13MB5639 Cc: Baowen Zheng , Tianyu Yuan , oss-drivers@corigine.com Subject: [ovs-dev] [PATCH/RFC 2/7] netdev-offload-tc: support offload of meter 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: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Tianyu Yuan Support offload of OF meter action using TC police actions. The TC police action instances are created when meters are configured and referred to here, in TC flower classifiers (flows) that use meter actions, by index. Signed-off-by: Tianyu Yuan Signed-off-by: Simon Horman --- lib/netdev-offload-tc.c | 4 ++++ lib/tc.c | 30 ++++++++++++++++++++++++++++++ lib/tc.h | 8 ++++++++ 3 files changed, 42 insertions(+) diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c index 9845e8d3f..0387b9b2e 100644 --- a/lib/netdev-offload-tc.c +++ b/lib/netdev-offload-tc.c @@ -1917,6 +1917,10 @@ 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) { + action->type = TC_ACT_METER; + action->meter.meter_id = nl_attr_get_u32(nla); + 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 3d54cd28e..9fb7eba07 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -2403,6 +2403,30 @@ nl_msg_put_act_flags(struct ofpbuf *request) { nl_msg_put_unspec(request, TCA_ACT_FLAGS, &act_flags, sizeof act_flags); } +void +nl_msg_fill_police(struct ofpbuf *request, struct tc_police police, + size_t *offset) +{ + 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); +} + +static void +nl_msg_put_act_meter(struct ofpbuf *request, uint32_t meter_id) +{ + struct tc_police tc_police; + int mtu = 65535; + size_t offset; + + tc_police.action = TC_POLICE_SHOT; + tc_police.mtu = mtu; + tc_police.index = METER_ID_TO_POLICY_INDEX(meter_id); + nl_msg_fill_police(request, tc_police, &offset); + nl_msg_end_nested(request, offset); +} + + /* Given flower, a key_to_pedit map entry, calculates the rest, * where: * @@ -2719,6 +2743,12 @@ nl_msg_put_flower_acts(struct ofpbuf *request, struct tc_flower *flower) nl_msg_end_nested(request, act_offset); } break; + case TC_ACT_METER: { + act_offset = nl_msg_start_nested(request,act_index++); + nl_msg_put_act_meter(request, action->meter.meter_id); + nl_msg_end_nested(request, act_offset); + } + break; } } } diff --git a/lib/tc.h b/lib/tc.h index 2408a0e92..6ba7f946c 100644 --- a/lib/tc.h +++ b/lib/tc.h @@ -90,6 +90,9 @@ struct tcmsg *tc_make_request(int ifindex, int type, 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); +void +nl_msg_fill_police(struct ofpbuf *request, struct tc_police police, + size_t *offset); struct tc_cookie { const void *data; @@ -181,6 +184,7 @@ enum tc_action_type { TC_ACT_MPLS_SET, TC_ACT_GOTO, TC_ACT_CT, + TC_ACT_METER, }; enum nat_type { @@ -263,6 +267,10 @@ struct tc_action { bool force; bool commit; } ct; + + struct { + uint32_t meter_id; + } meter; }; enum tc_action_type type; From patchwork Wed Nov 10 16:28:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 1553498 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" (1024-bit key; unprotected) header.d=corigine.onmicrosoft.com header.i=@corigine.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-corigine-onmicrosoft-com header.b=hV3Sn6qE; 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 (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hq9Ky4d4xz9sCD for ; Thu, 11 Nov 2021 03:29:42 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 365F34045F; Wed, 10 Nov 2021 16:29:37 +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 JcTvB5XReGca; Wed, 10 Nov 2021 16:29:36 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id 472A440423; Wed, 10 Nov 2021 16:29:34 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id ED900C001E; Wed, 10 Nov 2021 16:29:33 +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 076F2C003F for ; Wed, 10 Nov 2021 16:29:30 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 9A9B2403D1 for ; Wed, 10 Nov 2021 16:29:28 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp4.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=corigine.onmicrosoft.com 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 xSLRJ-07tsOR for ; Wed, 10 Nov 2021 16:29:28 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20711.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe59::711]) by smtp4.osuosl.org (Postfix) with ESMTPS id D62E7403DB for ; Wed, 10 Nov 2021 16:29:27 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ahoJaG+PbrdJlA6iUW7fCWFvxvBegAjH3URSzKxM4w7JDfUoNMtKsoDufsQwDJMCbMLu2KZbjkkzswXnf9ewEDfHuWYzUOlz8dgY+LYapzM7r5TsMR2ScoiPYE0Fx/D+u/kdvoBfK8D2LrjUqmwGro/o79IcDAr6xbb6aGKzKDiQhBTzKiuf+/Wwe6RkmyK9A9npXj49xafOtVS99a9H182WpoPyhGamloV6bYRv8inpCLXyAbtlF4T1Skj/z9weEb246CWlYRVfQRlWDi8cbUwhXRA0884wwjDpGv+ASuks81AV2ZIvxwWXTWF/FSc81q2z2FkQxeS32M+E7Ite+g== 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=P4m/eN1l7yYXziUqe4PdKMfuGtx5MIPFhr9YMyRk28k=; b=Exu3jALKbypuKjAZy7cIqWP86FAgtgU/JbuMriSDJ0C7gfjV163/1MVROXmwcY+ELlOqqvfxHMEIHDGVCNfz0/rMyja1MnGE+z4d4Y18mhFtyAmlfdpj0rktT1rVfHQBBhtYs+fBN7oCNRPtdTIpClWiRIWXC+sULA5628wswd7YAJ7VNIQrWi8DiDlCnmILdGGqIgXeDWOKNEsRrOlsGaeaqHESocT7eTYsZIkRFMqHlfv251ZqOAZY1NsJlULwep8xxaoLECLbEWw/1yi6j0KCAdfvk7f6ktOC0jQYKuHLD8vIINiPaKAmjWjyikJBwX/yKrQYrUqXs4qlk0H3+w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=P4m/eN1l7yYXziUqe4PdKMfuGtx5MIPFhr9YMyRk28k=; b=hV3Sn6qExVR5hD64FiwrrKggO6C1/EDJ3SboOPf/WMQANvJ9MGTWEfzIlQiLehRV5vW2EbZTjxI/zJ0qEvbvxKuMOcjBKQTEIes0sUabDfIe5f/3aYcLqoXRX3lxwN1+WXn9CwrQtnshl/blLyReBoGwoBLvPa53A2wzBsyp+Is= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) by PH0PR13MB5639.namprd13.prod.outlook.com (2603:10b6:510:12a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.14; Wed, 10 Nov 2021 16:29:25 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::e1d9:64d0:cb4f:3e90]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::e1d9:64d0:cb4f:3e90%9]) with mapi id 15.20.4690.005; Wed, 10 Nov 2021 16:29:25 +0000 From: Simon Horman To: dev@openvswitch.org Date: Wed, 10 Nov 2021 17:28:54 +0100 Message-Id: <20211110162858.20101-4-simon.horman@corigine.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211110162858.20101-1-simon.horman@corigine.com> References: <20211110162858.20101-1-simon.horman@corigine.com> X-ClientProxiedBy: AM0PR02CA0224.eurprd02.prod.outlook.com (2603:10a6:20b:28f::31) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 Received: from madeliefje.horms.nl (80.113.23.202) by AM0PR02CA0224.eurprd02.prod.outlook.com (2603:10a6:20b:28f::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.15 via Frontend Transport; Wed, 10 Nov 2021 16:29:23 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b7048c34-c298-4f1f-5be4-08d9a4674223 X-MS-TrafficTypeDiagnostic: PH0PR13MB5639: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CwRADy/kZ0E297UHx25K/wXw295WI3eBSaHItZ7K/zWvsTEeHOu6pTzbskigvsmi9pR3PzlsTKgyN4IwCbPU2/k8Iur/FI+ir2liOyLs47y0op8Wi23pcWsCbqBazbCLuy7juiXoczntLA68P/C+J/q+Fd1tJKudDKsIwwn8o34+bWURSUKB6qmarc6JGIlkyYudjYP9E1jqcb6OCsBwMo5N3T6FDzLudK261nocayJVcosMrAui/rvzV46XHUQ+fgpsymHcEjG9xkKBEW47pRET/rlwyMyx/taQ/XuYH+hXfgCWc7u7EUsYkujG0u3XULVVEhpt+btZlb4AgCqYyvAtHuj4b7gnvu02HZwgIttnkl0xdSdY9xNLeEqQ2QwLoq+mrQJ/jn1KzhpMA6rBZH6wq3GoqFV01egve1KC+lrdJzfWtLyFW0A641ILqgQL111Y66uMcETPDrlPCmpwockapZny06zSX/U87OLkBdMdKxwPyj21qtoaWVYxaLCKGOMXlXdnfnpBDHFjNRFTaiDuvm5vcTk9e6UwjVD25G/De8AfEbAQjCFzvAblMQ233c0eGgyMHE2YYPQRSIMtJcZrL7TbcNzAhp0oTUE6N2KWBMm8l+KigraqtXDjRpTas2xtZ1lKME+C/oYpL9Ub6o45f8aAfEl74FCj2N8TtK9w60hzbvk6xLJdyRQxzcW4za6rH/UD5eq39jONj/FwEg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH0PR13MB4842.namprd13.prod.outlook.com; PTR:; CAT:NONE; SFS:(346002)(376002)(396003)(39830400003)(366004)(136003)(1076003)(36756003)(86362001)(8676002)(66946007)(54906003)(107886003)(6512007)(44832011)(6666004)(316002)(6916009)(956004)(66476007)(508600001)(4326008)(5660300002)(8936002)(2906002)(6506007)(52116002)(186003)(6486002)(26005)(38100700002)(38350700002)(66556008)(2616005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9z2GoG8vMATkEcg6qL1XDL74+lYpIW2Cdcpw3Dk9izjwiS9sTMprbCfBaMIocqSsdh0xYJyyovFecLtTiBioM/GKsSMoggxtSb/BFlfTsaVnghJLbZCzm1uK/Ch0MQh4vDLMWSFKWYYiYX03+gAsXdcTgrccljY9p66CnidMr5S2KCAOYduq6xtWBOnAHr70UBjwCvzdydScVYSjBaz2ZApKWD19or9/yj68LcShH/qX6RxezdGjAfmiJAHTliX8bgePLkD/ZaNoD8H+bIN2DBgSZpd7YobNWhfDCoceUd6Gj1BfJl81eWjhT99I47n2ctVM4L6O654IupOTFJB0owYt7XgRrd8rkhUCIVdXwPLJ2/0AmlPiTBZRtOnkMl6si6j1vvRLHfYSY4BBCV+xt/MrZLku5ZuhB2C8x02l8tehtfuOMmWkJ1j2dFIFuhEOZgmLRsX/Y+q+W7NfFbe6bTw0UjMckXQLRn1ENV26skZYTBcrCw1f8yGpWWvZ9JEqjw6PcIah09CZazBgrS8K5DVGwEmFCHwWsDlM0WjcyPb0OTe/Ctdyawc7Q6Mb5ru8yPi1I7Iy3U3haPgCQWPgfM4NB7F7WuNL3vs0sQw1dSg9NR69wYPADooE6hBFYisVlYVHWRqJ8C9GrOVHa2Dnzxxrf6cyl/hEVuP1ntkTk/23sXVrI4B5lsBX04VamiOaHoMAHBz+vMqIOJlkP2d/B6MAXJXXFfit10RuXPqHjnYbDOt7cx5OoshfKXeL4QbPPzdS+PopKF8fFyY+MxykbbDxz0StWM993rtQbCYzgI4fm+CZr2v++5YruXjgUP6rH7yLeOcz95Twg27l8m21lR0YZIibVVtoe4ADDK2zocvRCbgknH/BXcwjYBs+oECUH1bSnGUhCy2Ps+xHTUR3CLVdmt9qBBhfRY9bMRsxre6uE0BGSgE541Sh1xHOUpZDr3aFI4cf1dldTSCWjbxnXkGEno0JgweltMYlfR79GsRrqfJmc1Cxb/SB2v7NcRJEWKK59OlkLTgTZEu60t5vK4vVIJRm16rahwEvq0X9OmJhLG1tAezOjMLq/tog7E9sCkXoDZbG0WTHX3nF5e/UO5Uo/6EQFRryYwX2vqKxqQOdrtJmpnVBdmIIivJ9Qi3W2vSkeqM9HXph3k0YWTswkIWDWWX/4EzfM8eaD+v6PoW2oznP+wuTu7WLjZCGRG4akdEzJsqcF1xVgTUWST/ruMnVukCQ7F8WBgoGRSYYBA0ZSnwkGoHMZ4VkSpqcA8mA3yRZyH9gotqmSOUjMJKgExUrPveeEAWvrpyP1kmt8uT+2/HhenI5tQHl2luQeVZpksjaJ5WJaLhxLBLaIOkNro9Vv/hcuLekE/LTY0688wKcMgTVtK+KpFx1ok+L27tVrfNW0AbDZV37q9FsRNtm9E4zj1oGZLtP2eQUHVLSvoYYHqg9Vwc+wxs0U3N5WDsNoNsegxVjsNMfqSEMHqBlBkO5TSuEZVOTEo7AVbCdfVz5kLWLe10Ahl1nUjwjkQrkCiNrJBNJ6qZ8Unh+K/9zCAFu1NWbJ/ih6CTwD7P+Z7skAb3W+WJ1ls5q6sqE6eH208C5dmzKJb6m82boTdJKUWE3FKp/qehjOrDGr/Li65TT9R88MlI96OhcZlDgDXt8BZKRstdXJQeMpuw43Ktvmg== X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: b7048c34-c298-4f1f-5be4-08d9a4674223 X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Nov 2021 16:29:24.9936 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 3YIcR4n51EfEFQZq3jrGVQCPM2dWmopUayqz3zLoItE7+W+mSrTDuWQQtHJ7bUkjQ7IY5iJc9ix/FcWU2Sga5sCq5c64C7BQ5+ugj6d8GdY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR13MB5639 Cc: Baowen Zheng , Tianyu Yuan , oss-drivers@corigine.com Subject: [ovs-dev] [PATCH/RFC 3/7] netdev-offload-tc: get police action for meter configuration 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: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Tianyu Yuan Retrieve configuration of meter actions in TC flower classifiers (flows in the TC datapath). These actions are TC police action instances referred to by index. Signed-off-by: Tianyu Yuan Signed-off-by: Simon Horman --- lib/netdev-offload-tc.c | 5 +++++ lib/tc.c | 28 ++++++++++++++++++++++++++++ lib/tc.h | 2 ++ 3 files changed, 35 insertions(+) diff --git a/lib/netdev-offload-tc.c b/lib/netdev-offload-tc.c index 0387b9b2e..3222f9e54 100644 --- a/lib/netdev-offload-tc.c +++ b/lib/netdev-offload-tc.c @@ -1015,6 +1015,11 @@ parse_tc_flower_to_match(struct tc_flower *flower, nl_msg_put_u32(buf, OVS_ACTION_ATTR_RECIRC, action->chain); } break; + case TC_ACT_METER: { + nl_msg_put_u32(buf, OVS_ACTION_ATTR_METER, + action->meter.meter_id); + } + break; } } } diff --git a/lib/tc.c b/lib/tc.c index 9fb7eba07..3993498b0 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -1704,6 +1704,32 @@ nl_parse_act_csum(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, }, +}; + +static int nl_parse_act_meter(struct nlattr *options, struct tc_flower *flower) +{ + struct nlattr *attrs[__TCA_POLICE_MAX]; + const struct tc_police *tc_police; + const struct nlattr *meter_parms; + struct tc_action *action; + + action = &flower->actions[flower->action_count++]; + if (!nl_parse_nested(options, police_policy, attrs, + ARRAY_SIZE(police_policy))){ + VLOG_ERR_RL(&error_rl, "failed to parse meter action options"); + return EPROTO; + } + meter_parms = attrs[TCA_POLICE_TBF]; + tc_police = nl_attr_get_unspec(meter_parms, sizeof *tc_police); + action->meter.meter_id = POLICY_INDEX_TO_METER_ID(tc_police->index); + action->type = TC_ACT_METER; + return 0; +} + static const struct nl_policy act_policy[] = { [TCA_ACT_KIND] = { .type = NL_A_STRING, .optional = false, }, [TCA_ACT_COOKIE] = { .type = NL_A_UNSPEC, .optional = true, }, @@ -1762,6 +1788,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_meter(act_options, flower); } else { VLOG_ERR_RL(&error_rl, "unknown tc action kind: %s", act_kind); err = EINVAL; diff --git a/lib/tc.h b/lib/tc.h index 6ba7f946c..0f7de8677 100644 --- a/lib/tc.h +++ b/lib/tc.h @@ -56,6 +56,8 @@ enum tc_flower_reserved_prio { * the prefix of meter related policy, following 16 bits are mapped by * meter_id, last 8 bits are reserved for bands in further. */ #define METER_ID_TO_POLICY_INDEX(meter_id) 0xff << 24 | (meter_id + 1) << 8 +/* Mapping policy_index to meter_id */ +#define POLICY_INDEX_TO_METER_ID(index) (((index >> 8) & 0xffff) - 1) enum tc_qdisc_hook { TC_INGRESS, From patchwork Wed Nov 10 16:28:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 1553497 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" (1024-bit key; unprotected) header.d=corigine.onmicrosoft.com header.i=@corigine.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-corigine-onmicrosoft-com header.b=UkExf/dr; 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 (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hq9Kw4G7Fz9sCD for ; Thu, 11 Nov 2021 03:29:40 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id D1AE381959; Wed, 10 Nov 2021 16:29:38 +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 jwK8Bp0xBuDT; Wed, 10 Nov 2021 16:29:37 +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 B994581003; Wed, 10 Nov 2021 16:29:35 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id C8157C0037; Wed, 10 Nov 2021 16:29:34 +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 41BF3C0039 for ; Wed, 10 Nov 2021 16:29:31 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id BCF09403DB for ; Wed, 10 Nov 2021 16:29:28 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp4.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=corigine.onmicrosoft.com 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 U21idz-hs3v5 for ; Wed, 10 Nov 2021 16:29:28 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20711.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe59::711]) by smtp4.osuosl.org (Postfix) with ESMTPS id 1AD8C403E1 for ; Wed, 10 Nov 2021 16:29:28 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IRVL2c3bAgxql2vTSypGJpFQxXev/7ZzThdfxJYjWngapnrq91CoWV3sXV2AF+QdoKKKznK3zcByKEcBh6N6pwO8Avvdd59LFx2mJ2EWLxwNJ9NkHB1DQCVq/C42sbAQxlvn5pCF1Ee5UzSw72gzJ3pCbgerf9+LRrAfIChjAG8BqE8BUuA0778kLkL/OtO0Jmx6jrRebka4bkwwYo2i/AV0AelXFmnJsF0OHzLO1tXSBrX68hGxGA68maUqtxtYDUllTB68f1VRzcvlVlY+GPXRzmaYzQZbjD/w4R3PBDamfucLTit0KQuf47e7KNeXCY+b1xnlLOQ/imXR1USxBg== 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=yRUh5bYcsEOBi5sbGzj3blNoXT+WrAfnzmdm/d43bJ0=; b=AkcMnt1IpqeYxS4VtatA8zTgNnpdYhBaTwNprlHQspoi008PQcSww61qi7xuYUSl+WTpuna5LYI35hy0A5kkW7GO9EJwjqn+p1u51z5mXMuEUbWiXxjlcKm3D/S6R0PId/mlJ1x+/eadqi8rBYBkM+QMjJjoqkTqLF3qV9sjSpcg5QqiLH3g9X4uqyA19vc8PjOr5j4jXiRDVbdZOkEx5GP+8YhFOa/n97ilrBGtQOLxTveslW6JAr/b9m4qW5trevCfNn+M2Ft0TCnJV4KgBrfh3XXnELhhBKH9e02B0wqR5xQvrVxOFGKDadL6qE39j8iaTm7ek7iPscG7lmHXfw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yRUh5bYcsEOBi5sbGzj3blNoXT+WrAfnzmdm/d43bJ0=; b=UkExf/drc5ag66FK5WM71xnNgS0Q3iv/85cSLGThRa/zLVAkAOcQriisSFTPXt1Nep/9agOV640ItfbdOeHKsBxHdUF0TuWoX+ksbWxd+jLY4nf3/SBZMDp4zJtlVVXIttQ9QDM3gu8dAhR9rfvDF6h2TJ3NGfjsvh5ZJGTjSXQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) by PH0PR13MB5639.namprd13.prod.outlook.com (2603:10b6:510:12a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.14; Wed, 10 Nov 2021 16:29:27 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::e1d9:64d0:cb4f:3e90]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::e1d9:64d0:cb4f:3e90%9]) with mapi id 15.20.4690.005; Wed, 10 Nov 2021 16:29:27 +0000 From: Simon Horman To: dev@openvswitch.org Date: Wed, 10 Nov 2021 17:28:55 +0100 Message-Id: <20211110162858.20101-5-simon.horman@corigine.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211110162858.20101-1-simon.horman@corigine.com> References: <20211110162858.20101-1-simon.horman@corigine.com> X-ClientProxiedBy: AM0PR02CA0224.eurprd02.prod.outlook.com (2603:10a6:20b:28f::31) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 Received: from madeliefje.horms.nl (80.113.23.202) by AM0PR02CA0224.eurprd02.prod.outlook.com (2603:10a6:20b:28f::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.15 via Frontend Transport; Wed, 10 Nov 2021 16:29:25 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2bbaae28-425b-4c99-bc22-08d9a4674365 X-MS-TrafficTypeDiagnostic: PH0PR13MB5639: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3968; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: x2quET2IFFNRKJiG4nXhLn8kY2nsW8Husq16tVE3ER1PvuKNTJn5sRfIF0VxoNWdmtk2QgHKIxBY/q163BBMAMOYM4hPiqD32O72yT+bO72XJbUpsexsVJbtZmnICAsh4It/SppzmDdDyFRl3cSCCMWWqOgg1n+lIMQbtRqDlNHQvv/eHBGySl8Jrt+VoiAdvaRySJaN+UmYM6T9VVB3lVwc6ghOhxaD4AvVhmPG7fX59MqOJ557xFXheMOrfBAbmhqDoCdReakaoWRr6j6a61AE4HhY4dCFYyNRV86FDQ0/DgpaBtSDjwTfdswGPNeX3HmSev2f7NNfral9eSYrFrEONX1BsDhcZ+PKjq317YUruDmF7LFAIu51UdQ7iM/Wb+VPribZmyg/jrmcKsOkv/mdDWtZ/qxgmnwCZA5DRBgMF+/NY5gYbkw55jL718tLSA+NL86Nyg5RYKFFvsVBMoJw67Cser7j4Nj7iiXOXl/+yoHnMeOdn0XIe8V/l2IovFoMKG+iStt9LaR2vuyXuNkpy+7f82yA9q8ksLNYCjAHVMYDlNH8xmMD5CV0FtwNH7Un/Z26/WY/bGsOHCLX2TqhK+ZvRojDyld5WdI9xZzOIlkaiFb45062C3DB2KdJ3u0DfqbGZLBT3pAztLlejFQQLyEmGDzxTB6SrbXwGMTp/aO+4uO8Fg9KNamlEKGYDua+syInZBlyjIy+1z0ZfA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH0PR13MB4842.namprd13.prod.outlook.com; PTR:; CAT:NONE; SFS:(346002)(376002)(396003)(39830400003)(366004)(136003)(1076003)(36756003)(86362001)(8676002)(66946007)(54906003)(107886003)(6512007)(44832011)(6666004)(316002)(83380400001)(6916009)(956004)(66476007)(508600001)(4326008)(5660300002)(8936002)(2906002)(6506007)(52116002)(186003)(6486002)(26005)(38100700002)(38350700002)(66556008)(2616005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lwL51dgA6+GE8yu13JOLi6Fhn8G6/bDFsoPfif3t2KcUq4tHU3juf+HW/f6Wk+vnL7dfmOiHFvNJpJ5suo6NlPShLFY09KZJ/Y7HpzPkCQcmKqbrFgjqJpAucpKoKAGg9XVxh4XLz55Sb7aRDHAYNda3bsGLm8Rm22S2gyfcKYK/n2TcHZYqTjARML3J0YfFiRjPteeZgUjs1v8JJeZAJBNBDBcl12bpeLc2vG5cQquqBux6ol0X6ZYCTduWim68bDqwgFJZVgkabTHLZeInOHxT7IrxlcXnG9W7icZVGD8OJDzBUHxaWPPkyzxXCNhdcuSyyviAPaTUW62EhO5tXpTnFZ3BSajdV+IBBzFrgumPnPD6LQoewKDQvDsyg1bh57hsAFeNdd54PMIQsoF+6JsgOMqIoBDYIrhq+gizScpjRyGU9vFr+YedkXO4l8GS2DTpelzJEzPBwMOrq4WEc6AFeO+KWTXHJFUNfTuFcmqRtv3dFUfp9DMCh+5jYdfs2cuLOjGdHuLc8fUTyuruwnPXr7uSOauMxI0lfmuaZLsMLBXe6Q4GoHDzWAQX6Inlqm+rfF+6nZlUCsMrRekGHIo/Oxc0iFxaNnPR9L/xlYa6QBqefzloMnUmhISXES9ytK/YltGKXleaTp3LWzhpsezIeXyQ95yESnCLmai4OJkQCziCK0yJczR396HGV7mK3+onvWBi6Ae8g6MvxQxwOGBCQiBB/YkfKKEogvDOMdiIxYNBXzxzY2Z3+YCGAQk3XmnRvTDfvNK8UvttmOH9rJDzPaB9hB16lVVw842v5k6mDVRsZgxo+rjc/emGGmYY4bNgg5HHtIU13vLimRPYxhxyfdW3eWALc1HoiYm68cZkDoYmOxgjnW7ZSQ9QqD0Zkt2ome3f6tBV83rV9kZ+7QOnEsg2NgNVXeeBwMRxWEp80yozOB/LvrpbMOwl8Tj9gUmEMiExBY76j0MWB57RMR91t8+rs7UzswGXAorRWqb1I5plwG5WqJEx5uQktks5/W5J+53JMfrpxi6nMzRKenTr6UkMSp2Uh6oCAgURUf79/aH1b7tdpMofw4yyEYuPjAlInmM502MmlCGH5tmRRnOCjWnfHeJJs1KJDxmdgxi1UBnT/pY4FdlODXjjRttyfuIJHmMvhuAnYNKV9unjEGwUS1Vf9pqOOsqoAcrVCcq9FXSJrcs70W7ccn1GDGPQkXxv4SOFVcx8Rd5q2PacEZw2l/tfWS6EDYIvp8xNDTFGkbkrPwBEijQnCLLpeGE0JKgV5CBiZtIFFnmHe8TdJE22Gg6oxvjFkl+Fjwx5d0P+Mna6LHbvTfhTEKuAOIeICT2+NuyZHtWsOAuCKYRtfEFdLeY69RiQaamjtM9oncMlgyggr/hqq6Kc3fezEuIU6yoPcFpeGWcxCjo1Eek1623su8iCeIVTAByqmJKkvc52Xsv/TS4BHWZTRlzfcMFRVBCc6CIZ8I3b/fqmSU62U/tC2AWYoIB5HEIKLCHYLdlSldb6tD5mO7sY7rV8rldVLZ9kagaSS+TUaPsLohQ0GFLS22TPHbFJJFdPUR/xMLhBbMBmucI9nO1ma5pRIh9aVnHUgk+rGXopMVTb/X5S517TwwQ1hdxc7dDbBLK+NgCX1cahnX9uOWVKOIdo5UedmumoOwBOaVp+A0Vw+JBAJA== X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2bbaae28-425b-4c99-bc22-08d9a4674365 X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Nov 2021 16:29:27.1362 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 4X7DSvIfmO3iDBjoAkONbAKyrVuoESJTXX7hmBt23vRt+a5RFw/HzSsgxfM248E6yFe86gpbilwbAs21OszXNcOdrhaFKGpfrbBpdm/pSJw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR13MB5639 Cc: Baowen Zheng , Tianyu Yuan , oss-drivers@corigine.com Subject: [ovs-dev] [PATCH/RFC 4/7] dpif-netlink: delete TC police action instance when deleting meter instance 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: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Baowen Zheng Delete the corresponding TC police action when deleting a meter. This is part of adding support for hardware offload of meters via OVS-TC. The delete may failed if there is filter rule is refered to this action. Signed-off-by: Baowen Zheng Signed-off-by: Tianyu Yuan Signed-off-by: Simon Horman --- lib/dpif-netlink.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index 3c42db0fa..81eb19c51 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -4167,6 +4167,41 @@ dpif_netlink_meter_add_police(ofproto_meter_id meter_id, return 0; } +static int +dpif_netlink_meter_del_police(ofproto_meter_id meter_id, + struct ofputil_meter_stats *stats OVS_UNUSED, + uint16_t max_bands OVS_UNUSED) +{ + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20); + struct ofpbuf request; + struct tcamsg *tcmsg; + size_t total_offset; + size_t act_offset; + int index = 0; + int prio = 0; + int error; + + tcmsg = tc_act_make_request(RTM_DELACTION, 0, &request); + if (!tcmsg) { + return ENODEV; + } + + dpif_netlink_police_start_nested(&request, &prio, &total_offset, + &act_offset); + index = METER_ID_TO_POLICY_INDEX(meter_id.uint32); + nl_msg_put_u32(&request, TCA_ACT_INDEX, index); + dpif_netlink_police_end_nested(&request, &total_offset, &act_offset); + + error = tc_transact(&request, NULL); + if (error) { + VLOG_ERR_RL(&rl, "failed to send del netlink msg for provider " + "id %u error %d\n", meter_id.uint32, error); + return error; + } + + return 0; +} + static int dpif_netlink_meter_set__(struct dpif *dpif_, ofproto_meter_id meter_id, bool add, struct ofputil_meter_config *config) @@ -4355,6 +4390,11 @@ static int dpif_netlink_meter_del(struct dpif *dpif, ofproto_meter_id meter_id, struct ofputil_meter_stats *stats, uint16_t max_bands) { + + if (netdev_is_flow_api_enabled()) { + dpif_netlink_meter_del_police(meter_id, stats, max_bands); + } + return dpif_netlink_meter_get_stats(dpif, meter_id, stats, max_bands, OVS_METER_CMD_DEL); } From patchwork Wed Nov 10 16:28:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 1553499 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" (1024-bit key; unprotected) header.d=corigine.onmicrosoft.com header.i=@corigine.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-corigine-onmicrosoft-com header.b=jMesmBTs; 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 (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hq9L22W47z9sRN for ; Thu, 11 Nov 2021 03:29:46 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 9044D60B1D; Wed, 10 Nov 2021 16:29:42 +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 kRqCFy2ITcg8; Wed, 10 Nov 2021 16:29:39 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id 97B2860AED; Wed, 10 Nov 2021 16:29:37 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id BD369C0046; Wed, 10 Nov 2021 16:29:35 +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 054B0C003C for ; Wed, 10 Nov 2021 16:29:35 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id B196240444 for ; Wed, 10 Nov 2021 16:29:33 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp2.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=corigine.onmicrosoft.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 A2rykp5sKcTp for ; Wed, 10 Nov 2021 16:29:31 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20706.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe59::706]) by smtp2.osuosl.org (Postfix) with ESMTPS id A0F0740432 for ; Wed, 10 Nov 2021 16:29:30 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AFRt5S+rZxC9ub0J5c45T44Ah+AkLoa6MDEjwkIM0G4IaZP5GrBpe3H+uH6OvuBy51ovJIkF7ogDcOhJjfTirunH/apuRv6im1H809T/uTvOpd39niPhcs+VDCiwn0FgDgzkCVTyFMHM30pv3bGbYpUf7z96Bjh30awI+kxOxGw2dIuc4HB5dftA7iX9fuvfY7pUh4xD95DstbK/NSSOwAcmt1OKOnj/Epl+rQOTZsLzc3CVYpj31LHOM9YYZ0atOssUN45wLzSy6ITj5aYn3mDq8SkMuStBja8/k/kVwOEsmyUSqZ3Gn6aRYXsZ0jdDzD9et3gksT4JLH8trd5HuA== 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=Vl6z4Uq/QEWSDHyFto2Rwexln+fpJmBO79SRLeQIjfM=; b=TMY6bFyR0xF/u0liUR/MeSbs8TuJOVFxluBkMlSyVDOUFmwh8HLAtEJEmd/fSthYNIDhf2h7EPufpdA34oqBnQ4/0yBmgUnnUdq4Mr/750dIPU9U6Bvt1oNFy+d2UPj0fMwzZFq4JxOqOeWuh9WiEIepg9vUxT1TxielIfJ6IPSLZLMNYN4tytZpYibXyQ6jNLHBjNtJE/PTfslDohrtZOMjTIDD6VZAhWa9QRC5kHcshmR4Sz3tE71pWFLgsG1BJPL6V2KGBwWcZTZHwKWmbhRigowjeVM1boqfKVOMMhYqbHpxhStY8k71QoDwApPPbarbZ4N2BYY5Ca8WLCSkaA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Vl6z4Uq/QEWSDHyFto2Rwexln+fpJmBO79SRLeQIjfM=; b=jMesmBTs41s0ch0qYETaT52CdbllA+Td7Uc/7MkEjftJctU+buOB2TfDBuzldgW36WV6lgR6lXclcKGFrlyR+FbQ20Tak/7v4hiX/fk5OeRNjjhnUALIKTbeLGFnsD2jLQToF75LL/V/9VXy+LYG/sZF9i2Gv3mMQh5DRN861L0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) by PH0PR13MB5639.namprd13.prod.outlook.com (2603:10b6:510:12a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.14; Wed, 10 Nov 2021 16:29:29 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::e1d9:64d0:cb4f:3e90]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::e1d9:64d0:cb4f:3e90%9]) with mapi id 15.20.4690.005; Wed, 10 Nov 2021 16:29:29 +0000 From: Simon Horman To: dev@openvswitch.org Date: Wed, 10 Nov 2021 17:28:56 +0100 Message-Id: <20211110162858.20101-6-simon.horman@corigine.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211110162858.20101-1-simon.horman@corigine.com> References: <20211110162858.20101-1-simon.horman@corigine.com> X-ClientProxiedBy: AM0PR02CA0224.eurprd02.prod.outlook.com (2603:10a6:20b:28f::31) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 Received: from madeliefje.horms.nl (80.113.23.202) by AM0PR02CA0224.eurprd02.prod.outlook.com (2603:10a6:20b:28f::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.15 via Frontend Transport; Wed, 10 Nov 2021 16:29:27 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7217f055-691f-4033-82de-08d9a4674488 X-MS-TrafficTypeDiagnostic: PH0PR13MB5639: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:17; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BDDc1Sjklu5vcrW5UjeY6dZd4u1erq7BW3xajKAhMw9Ud3fjm90KBsy0GN4NG/lxXfhbv6IF4BHSTr43kxJkuaf6DE4XdfFfACJxwxlR/voMkeUoXiJ/qxlFm/cHmKgtexEjt3ZcOZ1FwgFoMQj6llxVq7AVYLq9lM+DNlQ+QtuACSLH+uwiQbjTTOPqfD8KkgVMbyb8mjz37CwV7PgIHtKZL5h0S8U36CVvD29C9YXiDDGoJxuWVUEmdG2Kbg9D3l4a5h74ZCCZreOfgCYoDjZIs4YYTI+JNK9aoOQpQKBHQmUjAtC2PmBgQdphqZglBPeq/n2nPwN1HRNcWpgcFIa65zH4EiAiC4q68YiLFZpTsO0kG3Pa0PQvpkQPNC1KsJQ/boSnH2iYjGxKn4+vOnhXeWBt9SfOEhmN31O6gC7/KAnf4hh73UlxzbmywuTusj6Z/kfqmNXQYVicnVPi+5vOYQcSbawB0KKkJaWjB2NRWtlX/L+FGuTa7szw8E4f3ENouozBZRVuVcgVCjIrilerVjwnhxD87aFQRkYIN+H25JLyLFpPaw5lGAc/Yuu9sg08xXdlh+86xjciErHktDWNMY7+egkqY8X17aCR3vO1ttK1YWMormvyAPLE2M482ecGJKlDiGU3+S+IaAnOc9YzzUuWhhThOXNywLqhVwHrI9jGxONS+j1KrnnFG0rfxvPj1MqglMq3RG+5aCI/Cw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH0PR13MB4842.namprd13.prod.outlook.com; PTR:; CAT:NONE; SFS:(346002)(376002)(396003)(39830400003)(366004)(136003)(1076003)(36756003)(86362001)(8676002)(66946007)(54906003)(107886003)(6512007)(44832011)(6666004)(316002)(83380400001)(6916009)(956004)(66476007)(508600001)(4326008)(5660300002)(8936002)(2906002)(6506007)(52116002)(186003)(6486002)(26005)(38100700002)(38350700002)(66556008)(2616005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?SVE1VHAhMWPG5zjVoeM/5VX2Qt4e?= =?utf-8?q?wS2ZidSsnW7M0ttiLrx53qzYhVgvMccAdgo72DOAay8ZvHzX9ewzUoIlIWXdXtUKq?= =?utf-8?q?FfGFwXaIwSS3ZKym1R0UKUm9c2gcIhV03WpjeLwfqaSfzTbuJW3/y23O4wV03YNdR?= =?utf-8?q?wuG9Ixz2rgIfJEOEv1ecS3dauq89EbRdQ6obB7aKfvv6T+iLLqRaWZfn9PJ+vuXAF?= =?utf-8?q?p2IxZAvg7vTIWDhXSMk/yx7dZv2cNo9Uh6sgal81OKatRAw5VnBTAEa5xjIltDIzD?= =?utf-8?q?Q1bA3Aafe1b5juyYcEaPzUDLNPZorFrIUk4ZIgmTmOf13OtKbNko9gOqvdyWbz6Vr?= =?utf-8?q?TjWBhcxgyZAR+fHrYMz0hVer4VW42cJ+58+tmLScN7OpF0lMznaQCSBHLNaNtO+Pt?= =?utf-8?q?6mjY61skyrKQY/er21iwPu1x17HvJ3oyfYdPFhf2pQ1drELANh0e1Vhviqk6cS1v9?= =?utf-8?q?5mYLWRa1mduPeO2G/KzgkH+WbNcvuRj0oN6WmcWZCd/J/RbuVVDl5FSX2KvG422al?= =?utf-8?q?T1lb7QD96TuJwReBW7UR26E3/IPVUdffxaWnH6z2JIHKjCt8SQxIh2nktf1tVcS9+?= =?utf-8?q?FsOlbeJUYCCg2FkryGGeES7vXwTxgFlBz4ETDoeJX+qj4V+O75be5cGA30msp0hny?= =?utf-8?q?uu53VZrHr1leq+MFmyaMiT4BX0uHAv6d334Ojk4PluGKqMgyOVO6I4HaN178LrN8W?= =?utf-8?q?JMFYQyjsxr5oT0cly/bFRIzbOLH8yEKAPUoPR3MEGTO5ebLEDMdWpGDXPH9C3Iv2t?= =?utf-8?q?5gvVhVIUmIYPx3f0f/VKDvef8dSf3+RETzmlxVYSmJSfldDYoHShsxfW0mZJB/tzc?= =?utf-8?q?Fl31itfxIQ9nsXFDjfX4rBerVkgOVOalsuC1zaEGjNDXi0EA+B4IO/nSyccvxc4Jt?= =?utf-8?q?Zu4eIs29QLWUYj/pKQV3n1wquREnOB5PokdvN+5OzW/VwQQNHWE3Uec5CkaJy7y0I?= =?utf-8?q?9fH8YIfU+A3ZQaDtacnPRtUiF7Izn5a1SlcsY4JkVMhO5GVtjlI/T3YXeEDgB8g/6?= =?utf-8?q?UjY3tqXCwH0hAqiAFdNl0vNCJ1IjYFclmOphOSZpvPO3gTS+ObrVx3APTadWXzrqU?= =?utf-8?q?PdhWjeBT4CSBaIs0e9ZI6AOGA2d3GqnFfQ8oVqEJIKVeDalPUGtOUwWtVXXOTtoWw?= =?utf-8?q?TZV29dkYnB2w3tkH+fVS7qA+/iNP1wiDQAwdla6MqynNSDRbDRzLsW7hZd3elfOmf?= =?utf-8?q?hj+WGd9TcIk3Pie0S60xTi8Yi2HWNA0BX26+Vf43cOkhk/H43fDq1q2IevpM3Trhp?= =?utf-8?q?lPHpWQpxZyVBfaGKrTtvZE6ilaIgO7fC8ma3ZSSwjh9cacN9HVdRETMDM+GShUvoO?= =?utf-8?q?JlZ3VcylPCXPP/1qEdNWfyCr39KEixb8T+HuNeoeB0ZUg1Fm0/l3ON5N85vPKkc4f?= =?utf-8?q?ZT++Z0epXtzy1VkKPCFkKAsAagcK5a8nPZiEBg9NAQffr5RnfKgmWoIJzTnRgZWTG?= =?utf-8?q?2av5saZtnL45052XYMBaGw2Dz3I3n9+8ENJvs4XbmticLl7zDlmEycKlP712eIgcG?= =?utf-8?q?zPZLt7Gfs+ZL8pDdzOKh5eIHpoTh99QjRu+OkFf9CITUEZG4BD8sEiWwFbffuUSKX?= =?utf-8?q?fDBAW7dkzM9dBd7XB17uyxC4FJO4sm9WA=3D=3D?= X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7217f055-691f-4033-82de-08d9a4674488 X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Nov 2021 16:29:28.9343 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: NtJ971h8UeBDn850CREvwFPLk6JT7BQdyPWdCkZRASWMNxqPaOSrcZkFzHiCFLamRvj6gciIgQQEmxqokvX8iypjBvV+FsXUuoTCNYWaxBw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR13MB5639 Cc: Baowen Zheng , Tianyu Yuan , oss-drivers@corigine.com Subject: [ovs-dev] [PATCH/RFC 5/7] dpif: replace n_handlers with n_handlers_ 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: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Tianyu Yuan A following commit will include "ofproto-dpif.h" in "dpif-netlink.c", in order to use "struct dpif_backer". However this method will result in the declaration of ‘n_handlers’ shadowing a global declaration. Address this by replacing n_handlers with n_handlers_ in relavant function definitions. Signed-off-by: Tianyu Yuan Signed-off-by: Simon Horman --- lib/dpif-netlink.c | 40 ++++++++++++++++++++-------------------- lib/dpif.c | 8 ++++---- lib/dpif.h | 4 ++-- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index 81eb19c51..d270dbbd2 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -2509,17 +2509,17 @@ dpif_netlink_refresh_handlers_cpu_dispatch(struct dpif_netlink *dpif) { int handler_id; int error = 0; - uint32_t n_handlers; + uint32_t n_handlers_; uint32_t *upcall_pids; - n_handlers = count_cpu_cores(); - if (dpif->n_handlers != n_handlers) { + n_handlers_ = count_cpu_cores(); + if (dpif->n_handlers != n_handlers_) { VLOG_DBG("Dispatch mode(per-cpu): initializing %d handlers", - n_handlers); + n_handlers_); destroy_all_handlers(dpif); - upcall_pids = xzalloc(n_handlers * sizeof *upcall_pids); - dpif->handlers = xzalloc(n_handlers * sizeof *dpif->handlers); - for (handler_id = 0; handler_id < n_handlers; handler_id++) { + upcall_pids = xzalloc(n_handlers_ * sizeof *upcall_pids); + dpif->handlers = xzalloc(n_handlers_ * sizeof *dpif->handlers); + for (handler_id = 0; handler_id < n_handlers_; handler_id++) { struct dpif_handler *handler = &dpif->handlers[handler_id]; error = create_nl_sock(dpif, &handler->sock); if (error) { @@ -2533,9 +2533,9 @@ dpif_netlink_refresh_handlers_cpu_dispatch(struct dpif_netlink *dpif) handler_id, upcall_pids[handler_id]); } - dpif->n_handlers = n_handlers; + dpif->n_handlers = n_handlers_; error = dpif_netlink_set_handler_pids(&dpif->dpif, upcall_pids, - n_handlers); + n_handlers_); free(upcall_pids); } return error; @@ -2547,7 +2547,7 @@ dpif_netlink_refresh_handlers_cpu_dispatch(struct dpif_netlink *dpif) * backing kernel vports. */ static int dpif_netlink_refresh_handlers_vport_dispatch(struct dpif_netlink *dpif, - uint32_t n_handlers) + uint32_t n_handlers_) OVS_REQ_WRLOCK(dpif->upcall_lock) { unsigned long int *keep_channels; @@ -2559,13 +2559,13 @@ dpif_netlink_refresh_handlers_vport_dispatch(struct dpif_netlink *dpif, int retval = 0; size_t i; - ovs_assert(!WINDOWS || n_handlers <= 1); + ovs_assert(!WINDOWS || n_handlers_ <= 1); ovs_assert(!WINDOWS || dpif->n_handlers <= 1); - if (dpif->n_handlers != n_handlers) { + if (dpif->n_handlers != n_handlers_) { destroy_all_channels(dpif); - dpif->handlers = xzalloc(n_handlers * sizeof *dpif->handlers); - for (i = 0; i < n_handlers; i++) { + dpif->handlers = xzalloc(n_handlers_ * sizeof *dpif->handlers); + for (i = 0; i < n_handlers_; i++) { int error; struct dpif_handler *handler = &dpif->handlers[i]; @@ -2583,10 +2583,10 @@ dpif_netlink_refresh_handlers_vport_dispatch(struct dpif_netlink *dpif, return error; } } - dpif->n_handlers = n_handlers; + dpif->n_handlers = n_handlers_; } - for (i = 0; i < n_handlers; i++) { + for (i = 0; i < n_handlers_; i++) { struct dpif_handler *handler = &dpif->handlers[i]; handler->event_offset = handler->n_events = 0; @@ -2719,7 +2719,7 @@ dpif_netlink_recv_set(struct dpif *dpif_, bool enable) } static int -dpif_netlink_handlers_set(struct dpif *dpif_, uint32_t n_handlers) +dpif_netlink_handlers_set(struct dpif *dpif_, uint32_t n_handlers_) { struct dpif_netlink *dpif = dpif_netlink_cast(dpif_); int error = 0; @@ -2738,7 +2738,7 @@ dpif_netlink_handlers_set(struct dpif *dpif_, uint32_t n_handlers) error = dpif_netlink_refresh_handlers_cpu_dispatch(dpif); } else { error = dpif_netlink_refresh_handlers_vport_dispatch(dpif, - n_handlers); + n_handlers_); } } fat_rwlock_unlock(&dpif->upcall_lock); @@ -2747,12 +2747,12 @@ dpif_netlink_handlers_set(struct dpif *dpif_, uint32_t n_handlers) } static bool -dpif_netlink_number_handlers_required(struct dpif *dpif_, uint32_t *n_handlers) +dpif_netlink_number_handlers_required(struct dpif *dpif_, uint32_t *n_handlers_) { struct dpif_netlink *dpif = dpif_netlink_cast(dpif_); if (dpif_netlink_upcall_per_cpu(dpif)) { - *n_handlers = count_cpu_cores(); + *n_handlers_ = count_cpu_cores(); return true; } diff --git a/lib/dpif.c b/lib/dpif.c index 069f17863..3d4eae1a6 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -1478,12 +1478,12 @@ dpif_recv_set(struct dpif *dpif, bool enable) * * Returns 0 if successful, otherwise a positive errno value. */ int -dpif_handlers_set(struct dpif *dpif, uint32_t n_handlers) +dpif_handlers_set(struct dpif *dpif, uint32_t n_handlers_) { int error = 0; if (dpif->dpif_class->handlers_set) { - error = dpif->dpif_class->handlers_set(dpif, n_handlers); + error = dpif->dpif_class->handlers_set(dpif, n_handlers_); log_operation(dpif, "handlers_set", error); } return error; @@ -1497,10 +1497,10 @@ dpif_handlers_set(struct dpif *dpif, uint32_t n_handlers) * If not, returns 'false' */ bool -dpif_number_handlers_required(struct dpif *dpif, uint32_t *n_handlers) +dpif_number_handlers_required(struct dpif *dpif, uint32_t *n_handlers_) { if (dpif->dpif_class->number_handlers_required) { - return dpif->dpif_class->number_handlers_required(dpif, n_handlers); + return dpif->dpif_class->number_handlers_required(dpif, n_handlers_); } return false; } diff --git a/lib/dpif.h b/lib/dpif.h index 4398a4077..14f1d4d3f 100644 --- a/lib/dpif.h +++ b/lib/dpif.h @@ -874,8 +874,8 @@ typedef int upcall_callback(const struct dp_packet *packet, void dpif_register_upcall_cb(struct dpif *, upcall_callback *, void *aux); int dpif_recv_set(struct dpif *, bool enable); -int dpif_handlers_set(struct dpif *, uint32_t n_handlers); -bool dpif_number_handlers_required(struct dpif *, uint32_t *n_handlers); +int dpif_handlers_set(struct dpif *, uint32_t n_handlers_); +bool dpif_number_handlers_required(struct dpif *, uint32_t *n_handlers_); int dpif_set_config(struct dpif *, const struct smap *cfg); int dpif_port_set_config(struct dpif *, odp_port_t, const struct smap *cfg); int dpif_recv(struct dpif *, uint32_t handler_id, struct dpif_upcall *, From patchwork Wed Nov 10 16:28:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 1553500 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" (1024-bit key; unprotected) header.d=corigine.onmicrosoft.com header.i=@corigine.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-corigine-onmicrosoft-com header.b=cs0ThyPU; 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 (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hq9L22yp0z9sf8 for ; Thu, 11 Nov 2021 03:29:46 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id AB4DA40485; Wed, 10 Nov 2021 16:29:43 +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 Qn89UVDyRKZg; Wed, 10 Nov 2021 16:29:41 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp2.osuosl.org (Postfix) with ESMTPS id 6674C4044F; Wed, 10 Nov 2021 16:29:39 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 8FB1BC0037; Wed, 10 Nov 2021 16:29:38 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0533BC0019 for ; Wed, 10 Nov 2021 16:29:38 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 65A0680CF9 for ; Wed, 10 Nov 2021 16:29:36 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (1024-bit key) header.d=corigine.onmicrosoft.com 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 HZoVRSpBP3Ce for ; Wed, 10 Nov 2021 16:29:35 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20726.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe59::726]) by smtp1.osuosl.org (Postfix) with ESMTPS id E2C6E81024 for ; Wed, 10 Nov 2021 16:29:34 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Do2x7+EGIwR2iSwqKLLVN+Ee8xOgBA7vZZYrZBj/cVIFyb2USC0ENXPhR3J8zg/LDuS4KWKx2mZC9bHA9EW1dcLr3bLqV0qnMF6v4xNF5oExGIPkJtMRCJCQrFnJqZmqZT+liKcdpSE31ZcqLBIwkh9qtrejY/wGe8U3AkWGC2EhHDKV7HE5hrPiZqJr0c2M9gqARycQiOExiPPvZbvjVzH9vx2iPYvWESfI4BNMQrg785elHW9t66C0iHLOVS2L5owCqYnmluW3MLve1/gdDmuAJ7wIm4zV8oCuZAag9h+8S/02q5AWK5yScwlPQG4Nu4DuuWss2VyfW+NyoqfeRQ== 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=WJSURw5DmZW8xia6t4S6ttmCWpxHr8qenWH6bh8isSI=; b=VgXVtS+1tCIo3trgHcYODBUZz6hBMDYZeffABC0Tm2H7uBd3LGiqmt7KZvPOcZHK06hzY0IcMu/xGqP5r4j9vgf85Cj99iojolQg3za5ibR7dknQq+krf705qEAubG1OU/XnKHZd+V80Yvt2s06VnGpCPtxde5XX4P8bjWMg4Tl1sIg7+Vk/j9NNkY00sROJ/8csicrgR85sg6X8IJ+LAKf8Ggds7ezryuSobBCKAJNttystQB7K50Z6/As/SkDT/BbiBfVCAZCkiRbmNpD/+mOGOAWw08gG4bemrzWsfv9ST9No3kC0XVDVG9BsF5bYktDppORxHLRc0wkM02jeUA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WJSURw5DmZW8xia6t4S6ttmCWpxHr8qenWH6bh8isSI=; b=cs0ThyPUjEDgzTRz5jZF+Rd3Vk678yq67A1StunZcreG8zu/MnHAnySzFqJmK1Kl+cFa7Cj8yNaWT0By7icRUyR4hmf9/8TxdBUHjFCBkBs+Yx9HTKuDx296mnjjzMrysm8ZXDBGb6NExHz1u7Kr+HNT8yN0xmt3t6PQxrKPZVQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=corigine.com; Received: from PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) by PH0PR13MB5639.namprd13.prod.outlook.com (2603:10b6:510:12a::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.14; Wed, 10 Nov 2021 16:29:31 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::e1d9:64d0:cb4f:3e90]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::e1d9:64d0:cb4f:3e90%9]) with mapi id 15.20.4690.005; Wed, 10 Nov 2021 16:29:31 +0000 From: Simon Horman To: dev@openvswitch.org Date: Wed, 10 Nov 2021 17:28:57 +0100 Message-Id: <20211110162858.20101-7-simon.horman@corigine.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211110162858.20101-1-simon.horman@corigine.com> References: <20211110162858.20101-1-simon.horman@corigine.com> X-ClientProxiedBy: AM0PR02CA0224.eurprd02.prod.outlook.com (2603:10a6:20b:28f::31) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 Received: from madeliefje.horms.nl (80.113.23.202) by AM0PR02CA0224.eurprd02.prod.outlook.com (2603:10a6:20b:28f::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.15 via Frontend Transport; Wed, 10 Nov 2021 16:29:29 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0c5a3fd2-f39d-4892-cf7d-08d9a46745c4 X-MS-TrafficTypeDiagnostic: PH0PR13MB5639: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:279; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bBJgaVAtOT0SDBhLaagUs8hG8Ck47B8/J0TCJqHFUsbT9kdYbfbzg2MhpKBDlaalkvSwVcqYPDvtjAH8hXtjRXxI/IEqsfWrb1mE0iU7DOGPYrRAk/8ce+Rr0OPf5UpbrVFmAVYSJ0vu5Hcogd3nrHLlHOF2WBF6Brt9FFemEmEZ9zZdphIDGRpy+WRACbSLVo4j3+05xjtip3O+evIYrepMWLdIQimLpYlKsWQEO0zC2AJ8YfyrBvAtJIecY4EE+LctczcOCIZyU/0Ak0AYELlXfM/ATNTqq/qVziq5xQj1mtCcxnDznpv3FKTaK/6g1IjNywtupYMc4b+AxzpDuezgcGcst6RhJ7WBXNZeOX4Zl9jwc61a+ehz+pyJfJ6Gl+MYwJtZK4yXlYDZEH2UNlHvOVvYtS0+K7omCJJRwh1n/Wj+HEtlIsgf5MQJfcXZTHGcHlWs61VYUpWzi9ZpWd/6jGH23askI+jnFbK2V0fwfp1fJ/+0g75y4SI7uDBxgLdiKBQ4OmU7Q2P3nrWhYq9z/UUpYI0GRwoN7B/FrxR8mwf2FxdAkGlolFc2t4SSQeX4LvtrURa1aYtC/4NM99b78G+ROQiLWf1zYpybVDUWAfHpWVOKAL9XwUNaAE1kCsh6Pj4XLVVC0w4rwtXoHLedxPiRsgNCxAYA8x1/eGaQoLCcw0IjiFYPeCC1CzKeVgSyxn38OdrzeVlgNKg9wEGLVoik7gE0fu0MdHl5fS0= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH0PR13MB4842.namprd13.prod.outlook.com; PTR:; CAT:NONE; SFS:(346002)(376002)(396003)(39830400003)(366004)(136003)(1076003)(36756003)(86362001)(8676002)(66946007)(54906003)(107886003)(6512007)(44832011)(6666004)(316002)(30864003)(83380400001)(6916009)(956004)(66476007)(508600001)(4326008)(5660300002)(8936002)(2906002)(6506007)(52116002)(186003)(6486002)(26005)(38100700002)(38350700002)(66556008)(2616005)(309714004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: s3TrEvRulBOXlojtU48oHGaOU35M1bAc4RuZOc3y1bJXB93LGrldtavqxavTBDEWoof37W+Ls4v3QFsko++hNEizfuClRWFNzV8kF5Ijao2eUhUQhtG5nWmpa9lZISYsd+GldCTi5NVT8c+eWqhuzPpmIUN6FNXPFZst/jCIH52Z8D+U3cH6t9Ukt7Gbm+NWzUjmA4zqFj0FMe9X+62j13zMCcQUJqOo3wGATRa+Rmm5+NXXXbD5ebcCy5crVpPg7+3hLXISkuDubpSFm/0mlb658oO1Gbl/CRluA3jA9Cp6ZxXRSvQ+NzzugLxhOPEiVY69RjhWFSS9x4LWX/S0WILCVGi7YQuftLP170pnBwl2W08x2TaOAx6Zwlid3Qk3lVOVuZzLzqxslzKMcbWUAbaXoJe/xVJZ+fVlWIXbYI9qPKKiHn6/5PrRTGRHEkPeNiLM3JeF54489NtIHLRIyLDOKYhRLpJCY+MNUU7flsgl62yAsNc9hFHxLk+u4syhGys/XW6pGb+f/2b2XeC6z/iVdpfYyqP9NTxdSOidOM/alTB7Satz/ef69juCPWWZ1MixnV+fG2mY5AWE/5lMKEjiSEEqUSYk0JuT/RapR+eVHbFZk3sw0HI33u4sQiaCpDERdlvusguPfv0LafaK0ffTnNKMTTQYmHWfnAJsHmtVd6BwyT6VnjhGVBCwd8iCPZYZ9V96YkqRm+aj93l6BpiHE3bUNN49N6xhOGdq7pE/6ddLFrT73tV6xSpn0giMgZBxqM1BM6WJGBVxRyaZXA8HcIZStzcRO6g2T/P6F/owbXGq+wtsO6mlQyUHmW9hD6/RIOz2Me+QJoXPCUPg5PDsqUZgtfD2ccWkQ4JAdaHazUsrBIldM/RNBUtwdcjLi1KvD4ef4hpqi+eF5qlHUEwdEoFNHjSlzHZg3Vq97CDFMIvgX2e+Umi1VuW4kdxY4hKQenUfADlngCFEt6hDlsZTQKAhj9f4TJBqHXa0EPS70BXCBOf65HwJm0tksrxWSmh9LEOQ1o8QHZpFSCX30Km+LcmymHojYt3nnORDqGafvTz7icKqVav3HbukJUOIUP1UeEFJ6q2l/io7ZoR9MTFDFZrjS33SwNlLP8YpDBuBcp0nfC6B+/UnrZAdhy06a6ca+IBI23aCobge92kPaiMvvwcH1za4GdfWxpkLyt1Op97r1dMsIJGDC45d2fIQ2G124RMoUVgdtVjPIco42KCyn9Qnigv6HaTTUP3DA3wgEL65ftBcuuAfz+HzxudJbVJI3I/B6X4/L9Jo2zn8327Cw+s7rUn7tOLws0KAdtRLvbziPGS2QygIXxTMvywxcu/3uPIisLFAzJwM69clu0a8TZ1kaos666nuTPnbv+PXomJX99Q0AgfY1+4sn6hbwh8goiIiwhEqgcW9Pf6wZBotoqCiOQC2BwbY3180anH0kNhqp86tvTihMTGDbFqMOh32pKKUfJArGwjPOzn6JARy+zw0SgzyMmctAQVcFiAPXEblL8uPp3E1XaBPGIhUaY4TWCi8dWd8zWyntehTCOy5m20Pn8I2mXT3Fk6Ueu4QvsUA4c67qAHptSEigbDaC2d/BGjpKI6RIVgdGhM3f63XeH/MGGHZYMnmr3EuZwUYgjKKnRtYxmrE+ShswmnjhDqWvz9djXp1f6lSHNxQVg== X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0c5a3fd2-f39d-4892-cf7d-08d9a46745c4 X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Nov 2021 16:29:31.2004 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: lKbejjhHjrz5frQC2hzdq8N0pe8ZGf8gdVMwBqv7rPkeSSeElbJEHc3M2NsBqK9r8WcGphK9KA+6iQkHOEARPaEse+r30bu3w4O4vB8Qo9k= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR13MB5639 Cc: Baowen Zheng , Tianyu Yuan , oss-drivers@corigine.com Subject: [ovs-dev] [PATCH/RFC 6/7] ofproto-dpif: add offloaded meter revalidatation 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: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Baowen Zheng When meter deleted the deletion of the corresponding TC police action, used to facilitate offload via OVS-TC, may fail. This is occurs when the TC police action instance still in use by a TC flower classifiers (flows added to the TC datapath). In this commit, i add a revalidate process to clean the police action that offloaded relatewith a meter. Signed-off-by: Baowen Zheng Signed-off-by: Tianyu Yuan Signed-off-by: Simon Horman --- lib/dpif-netdev.c | 1 + lib/dpif-netlink.c | 172 ++++++++++++++++++++++++++++++++++ lib/dpif-provider.h | 4 + lib/dpif.c | 6 ++ lib/id-pool.c | 6 ++ lib/id-pool.h | 1 + lib/tc.c | 6 -- lib/tc.h | 7 ++ ofproto/ofproto-dpif-upcall.c | 1 + ofproto/ofproto-dpif.h | 2 + 10 files changed, 200 insertions(+), 6 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index bf4de3cf4..0c0a0249e 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -8809,6 +8809,7 @@ const struct dpif_class dpif_netdev_class = { dpif_netdev_meter_set, dpif_netdev_meter_get, dpif_netdev_meter_del, + NULL, /* meter_revalidate */ dpif_netdev_bond_add, dpif_netdev_bond_del, dpif_netdev_bond_stats_get, diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index d270dbbd2..aff78abcc 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -49,6 +49,7 @@ #include "netlink.h" #include "netnsid.h" #include "odp-util.h" +#include "ofproto/ofproto-dpif.h" #include "openvswitch/dynamic-string.h" #include "openvswitch/flow.h" #include "openvswitch/hmap.h" @@ -4035,6 +4036,12 @@ dpif_netlink_meter_transact(struct ofpbuf *request, struct ofpbuf **replyp, return 0; } +static const struct nl_policy police_policy[] = { + [TCA_POLICE_TBF] = { .type = NL_A_UNSPEC, + .min_len = sizeof(struct tc_police), + .optional = false, }, +}; + static void dpif_netlink_meter_get_features(const struct dpif *dpif_, struct ofputil_meter_features *features) @@ -4294,6 +4301,170 @@ dpif_netlink_meter_set(struct dpif *dpif_, ofproto_meter_id meter_id, return dpif_netlink_meter_set__(dpif_, meter_id, add, config); } +static const struct nl_policy tca_root_policy[] = { + [TCA_ACT_TAB] = { .type = NL_A_NESTED, .optional = false }, + [TCA_ROOT_COUNT] = { .type = NL_A_U32, .optional = false }, +}; + +static const struct nl_policy act_policy[] = { + [TCA_ACT_KIND] = { .type = NL_A_STRING, .optional = false, }, + [TCA_ACT_COOKIE] = { .type = NL_A_UNSPEC, .optional = true, }, + [TCA_ACT_OPTIONS] = { .type = NL_A_NESTED, .optional = true, }, + [TCA_ACT_STATS] = { .type = NL_A_NESTED, .optional = false, }, +}; + +static bool dpif_netlink_meter_should_revalidate(struct dpif_backer *backer, + uint32_t meter_id) +{ + return !id_pool_id_exist(backer->meter_ids, meter_id); +} + +static void +dpif_tc_meter_revalidate(struct dpif *dpif_ OVS_UNUSED, + struct dpif_backer *backer, struct ofpbuf *reply) +{ + static struct nl_policy actions_orders_policy[ACT_MAX_NUM + 1] = {}; + struct nlattr *actions_orders[ARRAY_SIZE(actions_orders_policy)]; + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20); + struct nlattr *action_root_attrs[ARRAY_SIZE(tca_root_policy)]; + struct nlattr *action_police_tab[ARRAY_SIZE(police_policy)]; + struct nlattr *action_police_attrs[ARRAY_SIZE(act_policy)]; + const int max_size = ARRAY_SIZE(actions_orders_policy); + const struct tc_police *tc_police = NULL; + struct ofputil_meter_stats stats; + ofproto_meter_id meter_id; + size_t revalidate_num; + size_t act_count; + uint32_t index; + int i; + + if (!reply) { + VLOG_ERR_RL(&rl, "get null reply message when meter revalidate \n"); + return; + } + + if (!nl_policy_parse(reply, NLMSG_HDRLEN + sizeof(struct tcamsg), + tca_root_policy, action_root_attrs, + ARRAY_SIZE(action_root_attrs))) { + VLOG_ERR_RL(&rl, "failed to parse reply message when meter " + "revalidate \n"); + return; + } + + act_count = nl_attr_get_u32(action_root_attrs[TCA_ROOT_COUNT]); + if (!act_count) { + VLOG_ERR_RL(&rl, "there is no police action returned in message when " + "meter revalidate \n"); + return; + } + + for (i = 0; i < max_size; i++) { + actions_orders_policy[i].type = NL_A_NESTED; + actions_orders_policy[i].optional = true; + } + + revalidate_num = act_count > ACT_MAX_NUM ? + (ACT_MAX_NUM + 1) : (act_count + 1); + + if (!nl_parse_nested(action_root_attrs[TCA_ACT_TAB], actions_orders_policy, + actions_orders, revalidate_num) ) { + VLOG_ERR_RL(&rl, "failed to parse TCA_ACT_TAB when meter revalidate " + "for act_count %lu", act_count); + return; + } + + for (i = 0; i < revalidate_num; i++) { + if (!actions_orders[i]) { + continue; + } + + if (!nl_parse_nested(actions_orders[i], act_policy, + action_police_attrs, ARRAY_SIZE(act_policy))) { + VLOG_ERR_RL(&rl, "failed to parse police action when meter " + "revalidate\n"); + return; + } + if (strcmp(nl_attr_get_string(action_police_attrs[TCA_KIND]), + "police")) { + VLOG_EMER("get none police action when meter revalidate\n"); + continue; + } + if (!nl_parse_nested(action_police_attrs[TCA_ACT_OPTIONS], + police_policy, action_police_tab, + ARRAY_SIZE(action_police_tab))) { + VLOG_ERR_RL(&rl, "failed to parse the single police action when " + "meter revalidate\n"); + return; + } + tc_police = nl_attr_get_unspec(action_police_tab[TCA_POLICE_TBF], + sizeof *tc_police); + if (!tc_police) { + VLOG_ERR_RL(&rl, "can not get police struct in police order %u " + "when meter revalidate\n", i); + continue; + } + index = tc_police->index; + if (UNLIKELY_METER_ACTION(index)) { + continue; + } + + index = POLICY_INDEX_TO_METER_ID(index); + if (dpif_netlink_meter_should_revalidate(backer, index)) { + meter_id.uint32 = index; + VLOG_ERR_RL(&rl, "revalidate the meter id %u for police index " + "%08x\n", index, tc_police->index); + dpif_netlink_meter_del_police(meter_id, &stats, 1); + } + } +} + +static void +dpif_netlink_meter_revalidate__(struct dpif *dpif_ OVS_UNUSED, + struct dpif_backer *backer) +{ + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20); + struct nla_bitfield32 dump_flags = { TCA_DUMP_FLAGS_TERSE, + TCA_DUMP_FLAGS_TERSE }; + struct ofpbuf request; + struct ofpbuf *reply; + struct tcamsg *tcmsg; + size_t total_offset; + size_t act_offset; + int prio = 0; + int error; + + if (!netdev_is_flow_api_enabled()) { + return; + } + tcmsg = tc_act_make_request(RTM_GETACTION, NLM_F_DUMP, &request); + if (!tcmsg) { + return; + } + dpif_netlink_police_start_nested(&request, &prio, &total_offset, + &act_offset); + nl_msg_put_string(&request, TCA_KIND, "police"); + dpif_netlink_police_end_nested(&request, &total_offset, &act_offset); + nl_msg_put_unspec(&request, TCA_ROOT_FLAGS, &dump_flags, + sizeof dump_flags); + error = tc_transact(&request, &reply); + if (error) { + VLOG_ERR_RL(&rl, "failed to send dump netlink msg for revalidate " + "error %d\n", error); + return; + } + dpif_tc_meter_revalidate(dpif_, backer, reply); + ofpbuf_delete(reply); +} + +static void +dpif_netlink_meter_revalidate(struct dpif *dpif_, struct dpif_backer *backer) +{ + if (probe_broken_meters(dpif_)) { + return; + } + dpif_netlink_meter_revalidate__(dpif_, backer); +} + /* Retrieve statistics and/or delete meter 'meter_id'. Statistics are * stored in 'stats', if it is not null. If 'command' is * OVS_METER_CMD_DEL, the meter is deleted and statistics are optionally @@ -4617,6 +4788,7 @@ const struct dpif_class dpif_netlink_class = { dpif_netlink_meter_set, dpif_netlink_meter_get, dpif_netlink_meter_del, + dpif_netlink_meter_revalidate, NULL, /* bond_add */ NULL, /* bond_del */ NULL, /* bond_stats_get */ diff --git a/lib/dpif-provider.h b/lib/dpif-provider.h index 0d092de9b..f3893b2d1 100644 --- a/lib/dpif-provider.h +++ b/lib/dpif-provider.h @@ -25,6 +25,7 @@ #include "openflow/openflow.h" #include "dpif.h" #include "util.h" +#include "ofproto/ofproto-dpif.h" #ifdef __cplusplus extern "C" { @@ -624,6 +625,9 @@ struct dpif_class { int (*meter_del)(struct dpif *, ofproto_meter_id meter_id, struct ofputil_meter_stats *, uint16_t n_bands); + /* revalidate meter entries in offload cases */ + void (*meter_revalidate)(struct dpif *, struct dpif_backer *); + /* Adds a bond with 'bond_id' and the member-map to 'dpif'. */ int (*bond_add)(struct dpif *dpif, uint32_t bond_id, odp_port_t *member_map); diff --git a/lib/dpif.c b/lib/dpif.c index 3d4eae1a6..984b20fef 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -2090,3 +2090,9 @@ dpif_cache_set_size(struct dpif *dpif, uint32_t level, uint32_t size) ? dpif->dpif_class->cache_set_size(dpif, level, size) : EOPNOTSUPP; } + +void +dpif_meter_revalidate(struct dpif *dpif, struct dpif_backer *backer) +{ + dpif->dpif_class->meter_revalidate(dpif, backer); +} diff --git a/lib/id-pool.c b/lib/id-pool.c index 69910ad08..50999a096 100644 --- a/lib/id-pool.c +++ b/lib/id-pool.c @@ -155,3 +155,9 @@ id_pool_free_id(struct id_pool *pool, uint32_t id) } } } + +bool +id_pool_id_exist(struct id_pool *pool, uint32_t id) +{ + return !!id_pool_find(pool, id); +} diff --git a/lib/id-pool.h b/lib/id-pool.h index 8721f8793..08fba6d43 100644 --- a/lib/id-pool.h +++ b/lib/id-pool.h @@ -29,6 +29,7 @@ void id_pool_destroy(struct id_pool *); bool id_pool_alloc_id(struct id_pool *, uint32_t *id); void id_pool_free_id(struct id_pool *, uint32_t id); void id_pool_add(struct id_pool *, uint32_t id); +bool id_pool_id_exist(struct id_pool *pool, uint32_t id); /* * ID pool. diff --git a/lib/tc.c b/lib/tc.c index 3993498b0..5d89560f8 100644 --- a/lib/tc.c +++ b/lib/tc.c @@ -51,10 +51,6 @@ #define TCM_IFINDEX_MAGIC_BLOCK (0xFFFFFFFFU) #endif -#ifndef TCA_DUMP_FLAGS_TERSE -#define TCA_DUMP_FLAGS_TERSE (1 << 0) -#endif - #if TCA_MAX < 15 #define TCA_CHAIN 11 #define TCA_INGRESS_BLOCK 13 @@ -1821,8 +1817,6 @@ nl_parse_single_action(struct nlattr *action, struct tc_flower *flower, return 0; } -#define TCA_ACT_MIN_PRIO 1 - static int nl_parse_flower_actions(struct nlattr **attrs, struct tc_flower *flower, bool terse) diff --git a/lib/tc.h b/lib/tc.h index 0f7de8677..5b1c934d8 100644 --- a/lib/tc.h +++ b/lib/tc.h @@ -58,6 +58,8 @@ enum tc_flower_reserved_prio { #define METER_ID_TO_POLICY_INDEX(meter_id) 0xff << 24 | (meter_id + 1) << 8 /* Mapping policy_index to meter_id */ #define POLICY_INDEX_TO_METER_ID(index) (((index >> 8) & 0xffff) - 1) +/* Ckeck if given policy action is meter action*/ +#define UNLIKELY_METER_ACTION(index) !(index & (0xff << 24)) || !((index >> 8) & 0xffff) enum tc_qdisc_hook { TC_INGRESS, @@ -284,7 +286,12 @@ enum tc_offloaded_state { TC_OFFLOADED_STATE_NOT_IN_HW, }; +#ifndef TCA_DUMP_FLAGS_TERSE +#define TCA_DUMP_FLAGS_TERSE (1 << 0) +#endif +#define ACT_MAX_NUM 1024 #define TCA_ACT_MAX_NUM 16 +#define TCA_ACT_MIN_PRIO 1 struct tcf_id { enum tc_qdisc_hook hook; diff --git a/ofproto/ofproto-dpif-upcall.c b/ofproto/ofproto-dpif-upcall.c index 1c9c720f0..091b0a626 100644 --- a/ofproto/ofproto-dpif-upcall.c +++ b/ofproto/ofproto-dpif-upcall.c @@ -2794,6 +2794,7 @@ revalidate(struct revalidator *revalidator) ovsrcu_quiesce(); } dpif_flow_dump_thread_destroy(dump_thread); + dpif_meter_revalidate(udpif->dpif, udpif->backer); ofpbuf_uninit(&odp_actions); } diff --git a/ofproto/ofproto-dpif.h b/ofproto/ofproto-dpif.h index 191cfcb0d..cf7ebc29d 100644 --- a/ofproto/ofproto-dpif.h +++ b/ofproto/ofproto-dpif.h @@ -401,4 +401,6 @@ bool ofproto_dpif_ct_zone_timeout_policy_get_name( bool ovs_explicit_drop_action_supported(struct ofproto_dpif *); +void dpif_meter_revalidate(struct dpif *dpif, struct dpif_backer *backer); + #endif /* ofproto-dpif.h */ From patchwork Wed Nov 10 16:28:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 1553501 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" (1024-bit key; unprotected) header.d=corigine.onmicrosoft.com header.i=@corigine.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-corigine-onmicrosoft-com header.b=uQM18BgJ; 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 (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hq9L63m2tz9sRK for ; Thu, 11 Nov 2021 03:29:50 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 7ACEB60B34; Wed, 10 Nov 2021 16:29:48 +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 sWvB39awoZcC; Wed, 10 Nov 2021 16:29:46 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTPS id 0C07760B01; Wed, 10 Nov 2021 16:29:44 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id C5B64C0019; Wed, 10 Nov 2021 16:29:44 +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 2E92CC000E for ; Wed, 10 Nov 2021 16:29:44 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id DF17C60AF2 for ; Wed, 10 Nov 2021 16:29:38 +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 8thQw0Q4XDv4 for ; Wed, 10 Nov 2021 16:29:36 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on20702.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe59::702]) by smtp3.osuosl.org (Postfix) with ESMTPS id DCBB560ADE for ; Wed, 10 Nov 2021 16:29:35 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j/WGi8vAUL85tVBz+/BargqrBAuCxGPzFuuZ15CKZFPODEKkTgk0TFXMl22XCAQPTBWRMz2TWi+siG6kqye13UFX+AS7P6mnJIhrEwh3+csP2G3Qx2OrRXKiIwWJcGJFTfwVldt+QaD+djqHD3nGcoK+KoET1d8ZIAd67KcBfOPKYsUTJQJDv/bS6v7k7nGjN5wujvJQ9VZ1ew3i+kc80XIDqG5O6F26f3MaWCFN6ayTIzy6OmiNG8Nhh9Nd2JD4loTtdKoCYFqwI2ktqhlivzakmLcBtGjTZe110wABLmDgTmpz397hR8kacDvsitqBf+29WALQuk59Hw70/Ico6Q== 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=1nUwEjL9Edvm4ws/wVS64BBdoZPHmbcuqbnHfwMXymg=; b=Y3gAmApOFBdS4lNf/Ilmv8FJDuf0EPRozcFuu20wBXZoBc3tRSKZTZ68SV5Dsl3JEWvYDmkAK1cUpO2aKrBINmjPfFFDXKg+z0qj+yeX9M7GMmp48IBPE8187ZjBTjhNE5cMhIand1V5O4XXtY4jtt0sd085qGV4TrrC94S+7782yn9ePGGtK88tA1pH1vL7+/S27Z88xVtdqwT+LOd1V5eVl6pKXgHPmfn/PA0lrwRj9TQMnYEgvmJcOkcGT7Z+j/yA/YiwVWxjXHFt2Zns8AOMyMNIRTJjStl/wSK/MI2zN2rlZu/QXpTXoNIhzwabfI5TvGLwMfNIg3NQgqc/1g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=corigine.com; dmarc=pass action=none header.from=corigine.com; dkim=pass header.d=corigine.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=corigine.onmicrosoft.com; s=selector2-corigine-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1nUwEjL9Edvm4ws/wVS64BBdoZPHmbcuqbnHfwMXymg=; b=uQM18BgJpPck39kqkFyD6VKMXoA9IljCFUfXKjFUWCL6No+FAzUpKo5qapnL+CiNh3uWm2lKvmlp7qLfo/zMonUTbVrooEVwt7z4IYzcgHl6yD6zoWGTAV43sn0mP+oU8bvVz+KR29iVPCPAPfGc08qxlir4T851WPqUCcJxwX0= Authentication-Results: openvswitch.org; dkim=none (message not signed) header.d=none;openvswitch.org; dmarc=none action=none header.from=corigine.com; Received: from PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) by PH0PR13MB5003.namprd13.prod.outlook.com (2603:10b6:510:78::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.6; Wed, 10 Nov 2021 16:29:33 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::e1d9:64d0:cb4f:3e90]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::e1d9:64d0:cb4f:3e90%9]) with mapi id 15.20.4690.005; Wed, 10 Nov 2021 16:29:33 +0000 From: Simon Horman To: dev@openvswitch.org Date: Wed, 10 Nov 2021 17:28:58 +0100 Message-Id: <20211110162858.20101-8-simon.horman@corigine.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211110162858.20101-1-simon.horman@corigine.com> References: <20211110162858.20101-1-simon.horman@corigine.com> X-ClientProxiedBy: AM0PR02CA0224.eurprd02.prod.outlook.com (2603:10a6:20b:28f::31) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 Received: from madeliefje.horms.nl (80.113.23.202) by AM0PR02CA0224.eurprd02.prod.outlook.com (2603:10a6:20b:28f::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.15 via Frontend Transport; Wed, 10 Nov 2021 16:29:31 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 24407225-2ac2-4181-c044-08d9a467473b X-MS-TrafficTypeDiagnostic: PH0PR13MB5003: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: m8UUnVX0G/udvHRolkb3/Ghdnn1gRbmqxJmfZBp5rEzaOkmjKFUOBJw3ZkgDo0rvPa4Lc9R8s9XAz/K8XWdxDDmcAcPFSjpg+9FhYgHYiL4xOjajlEiQxmd2Som8HL9RL4yIM2o2AhnWwGolLkDB6/oHUGG1KqjMaepIix3gAS9Q4e0a+zvCQn+94acbkTnCPlw0Q+ROFqETXBY10dU8rmAnqYpY4EhoMbfUvqjOCNCzuyG0V5vPTlAL+9v9lAPS1mpkSrIZ55YamBVw/+TzImcDaT/VRCE64LRcIBM7PwuV8E8q2L9YU83iU6cfxjmXTMqEM8yCPvN9Vo+AzfR6MQDp9D4AnvQJ/kyoqBz6gwg2MFc87jSuin+8h3K0sLnNhQzkxnz18f6QiAyVHUmZHEgZKFOYELvhcl7p3Wc/FHWyLDLz9NIFpTPhkrBSgfQmiaOwNdk4QXrpfumkzbD2q8Nsw9T+josHl17HiTlsUGbeiwSTZ5KLpWUGN9IJrJ5x2JwM7ymo7Y8XUzD2hyQW/RfaXb5+Zyhk/S5aK1aGzKkTPA2CXk2xEXSzgIhmkVK3wR5WlJFtijWRvlRQlZmHiYQdz/k9L2tDR/KreCHPgF2R2sXr8+ZVnyXSFyO3cHN9/k8pzmhcHHk0s8W98bSsGTHYXbi3Rf1zoX0nHhtF0XMG5gjQUE8NLdt7s6rgq/mSEizd6MO0CF2DrfC+/Zhd3A== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH0PR13MB4842.namprd13.prod.outlook.com; PTR:; CAT:NONE; SFS:(376002)(39830400003)(366004)(396003)(136003)(346002)(38100700002)(5660300002)(4326008)(316002)(83380400001)(8676002)(186003)(6916009)(8936002)(508600001)(26005)(1076003)(44832011)(38350700002)(86362001)(2906002)(52116002)(2616005)(54906003)(6512007)(956004)(66946007)(36756003)(107886003)(6506007)(6486002)(6666004)(66556008)(66476007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8sp3aRp3ckmXBNPQ9TBb+R5xjlcFvYsYox0k5ePOSp/O2D4G18dWHi9GGnxQBmeJuBgW+bPLv5+hwrLEBWcRfbiVchy/FnkFXABkTenZbFXIwMaEzFVEHPEVt5qKxdrcl8qTwcIjkSq+c1d/qrDQO6J3gutz1XSr6D9V+Nex5FujNdRRe+aWOGXfCKw7OjthPU/EtDE75Dr7ikVyxznxaEFTu7xGZ8BlxzWEFB+YSqPJqfERPuwP2N/UnoLKIj4Ip069qtE5zAJPFPdqiLQ3aUDNG9tN/3UxKqVUWulc6NVqvoman2atkPWBO088WLxaRh6XHQzdrP820tj7trdtHpaIT4lz8Oh+o9EH44cZL/CJRla8gwX4Zl7mX4py/XbGbtm5k3QY4LTasJGXp1FF2Zh+vlDm3MrFeztrPaiyue3NeaAehIRuc4xt0tVxVcWRLbBYxljE2nGV36h1hJKy+PCgDi5mvhMsWli9OeaYcfGfXeKy0+VbqlYwi+13bgfclm9PhPHYy2Llgee5zmciBdHyYe1r5WNXra0nPdJrCSt8/BZmr39vkNK5JO3jC5QIeyRpmKg8rDd8rpJ9Tq/UUAhw24V8BpaavxGyiCK53AJind+OCo71RjgHakaykrXSmIIOKxPXDR+4idI8WqiHojYd7JJQRPVOR0JOiF4HPlXPXRo4vqeD9V2jEuo7QjBvchkg5RsOOfJp9lBZXbpLXCGWDdowPeysQ2mw3aKhOHRYX1YLysiFPtbE7disrK+bpuJaU80lTNWCBnhCAkpZIPnTGv0hgU3S/TCHJlB6MbIXqrXxPkc2o1MSY0h5UbuqFc8jhu3sGlI1qlru/e3m9Z3HmqVdzE5Quic88/IGIdGrO6gByvSSwXXWKe8la9NDn+M+T5wJtPdbtbkiYG1FLDpVhtY6gj63msRVac5DhwAvMok9D063CgiVW3XfuT/qvgQCgao23wCM/UV5IFLHQLnYBdfj5otRjC8WmgRlEwuwMOvctCP7md0L3I1K46ydodk1O9QsG7BOAQEdSkUhjSyg6aCXiOXPULZNRizzfQa4JpskxHeeDjS0/q9q17asPboJA0wWpGA5e3o8Ui6jgIDdaQAtVmz9f6dhFPhAuu8qRmRXA9UYMV9guKr+us7tYHVVc1cH7chzAVI44UVsRszYIK/CChS7T+w0vK7Ft9UEAN4rEnuHHGX6JzuPigQnuihqiufHcxgrbWEtpJLe2F3Ag2Z4AUWELJSRbRHrv3j/XHLv195PxddnebB+bfmNBoir+3gb1uScWpyDNqN7TYsrJuF3YbRY4Yy7jiWuhLNfxjv7ITYa1cctJQokOqG5SUtwvEtjyWCLH6ibH2naE8EBllfsN4xWrYIlc5EBbMEj0y+05n3kiAqLKFFobhMcGNCINBg5FYJaI83nfmOKNmoSOBccwef2A4JRxIr3J04aZAqKxO2RuuUnWeuRtq5p3OFlC/RIrYEz3iNikDyw+TgLGBWuAc0Nm2KgvhmrNvHt1xGcMNP7J3SkyIQWHuKAyvuxL9IaIzhf4teGTXFaKpKUPlBggmUoS3811SESEnu/2ESq7chtnHr+/JA/k6yIfzSSsakHxzd406of8ikN3Vp+bFIs+jCjK0gPdw0/4XjYstyeiO4zKJwU4HVn2gh1DzELgrgQ9E/NA929TrfAsg== X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 24407225-2ac2-4181-c044-08d9a467473b X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Nov 2021 16:29:33.4873 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: fe128f2c-073b-4c20-818e-7246a585940c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: HJlvBy7v/5FQNZFNLJMCjE543KcJxzuIMwwbfhufsRKga42XQQ/Ul65v2iPNYLCrgO7jWyLw9zZJhx5sL5H6Iksa5O46lHg5m0F0h/C61Cg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR13MB5003 Cc: Baowen Zheng , Tianyu Yuan , oss-drivers@corigine.com Subject: [ovs-dev] [PATCH/RFC 7/7] dpif-netlink: add offloaded meter stats dump in dpif_netlink_meter_get_stats 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: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Tianyu Yuan Since previous ovs meter only supported dumping meter stats in non-offload datapath, the dpif_netlink_meter_transact_offloaded is introduced in dpif_netlink_meter_get_stats, in order to ckech meter stats in offloaded datapath through sending and receiving corresponding netlink message. Using "ovs-ofctl meter-stats br0 [meter] -O openflow13" can check the stats on OVS-Bridge br0. Shown stats(packet_in_count and byte_in_count) are counted by summing states of offloaded and non-offloaded datapath. Signed-off-by: Tianyu Yuan Signed-off-by: Simon Horman --- lib/dpif-netlink.c | 136 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 133 insertions(+), 3 deletions(-) diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index aff78abcc..0765ceda3 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "bitmap.h" #include "dpif-netlink-rtnl.h" @@ -4036,12 +4037,125 @@ dpif_netlink_meter_transact(struct ofpbuf *request, struct ofpbuf **replyp, return 0; } + +static const struct nl_policy tca_root_policy_[] = { + [TCA_ACT_TAB] = { .type = NL_A_NESTED, .optional = false }, + [TCA_ROOT_COUNT] = { .type = NL_A_U32, .optional = true }, +}; + +static const struct nl_policy act_policy_[] = { + [TCA_ACT_KIND] = { .type = NL_A_STRING, .optional = false, }, + [TCA_ACT_COOKIE] = { .type = NL_A_UNSPEC, .optional = true, }, + [TCA_ACT_OPTIONS] = { .type = NL_A_NESTED, .optional = true, }, + [TCA_ACT_STATS] = { .type = NL_A_NESTED, .optional = true, }, +}; + +static const struct nl_policy stats_policy[] = { + [TCA_STATS_BASIC] = { .type = NL_A_UNSPEC, + .min_len = sizeof(struct gnet_stats_basic), + .optional = false, }, +}; + static const struct nl_policy police_policy[] = { [TCA_POLICE_TBF] = { .type = NL_A_UNSPEC, .min_len = sizeof(struct tc_police), .optional = false, }, }; +static int +dpif_netlink_meter_transact_offloaded(ofproto_meter_id meter_id, + struct ofpbuf request, + struct ofpbuf **reply) +{ + uint32_t index = METER_ID_TO_POLICY_INDEX(meter_id.uint32); + size_t total_offset, basic_offset; + struct tcamsg *tcamsg; + int prio = 0; + + tcamsg = tc_act_make_request(RTM_GETACTION, NLM_F_REQUEST, &request); + if (!tcamsg) { + return ENODEV; + } + dpif_netlink_police_start_nested(&request, &prio, &total_offset, + &basic_offset); + nl_msg_put_u32(&request, TCA_ACT_INDEX, index); + dpif_netlink_police_end_nested(&request, &total_offset, &basic_offset); + + return tc_transact(&request, reply); +} + +static int +dpif_netlink_meter_get_stats_offloaded(ofproto_meter_id meter_id, + struct ovs_flow_stats *stats) +{ + static struct nl_policy actions_orders_policy[ACT_MAX_NUM + 1] = {}; + struct nlattr *action_root_attrs_temp[ARRAY_SIZE(tca_root_policy_)]; + struct nlattr *actions_orders[ARRAY_SIZE(actions_orders_policy)]; + static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20); + struct nlattr *action_police_attrs[ARRAY_SIZE(act_policy_)]; + const int max_size = ARRAY_SIZE(actions_orders_policy); + struct nlattr *stats_attrs[ARRAY_SIZE(stats_policy)]; + const struct gnet_stats_basic *bs; + struct nlattr *act_stats; + struct ofpbuf request; + struct ofpbuf *reply; + int i, err; + + err = dpif_netlink_meter_transact_offloaded(meter_id, request, &reply); + if (err) { + VLOG_ERR_RL(&rl, "failed to send get-action netlink msg : %d", err); + goto err_out; + } + + /*parse reply from ofpbuf to *nlattr[] */ + if (!nl_policy_parse(reply, NLMSG_HDRLEN + sizeof(struct tcamsg), + tca_root_policy_, action_root_attrs_temp, + ARRAY_SIZE(action_root_attrs_temp))) { + VLOG_ERR_RL(&rl, "failed to parse reply message"); + err = EINVAL; + goto err_out; + } + + for (i = 0; i < max_size; i++) { + actions_orders_policy[i].type = NL_A_NESTED; + actions_orders_policy[i].optional = true; + } + + if (!nl_parse_nested(action_root_attrs_temp[TCA_ACT_TAB], + actions_orders_policy, + actions_orders, ACT_MAX_NUM + 1)) { + VLOG_ERR_RL(&rl, "failed to parse TCA_ACT_TAB"); + err = EPROTO; + goto err_out; + } + + if (!nl_parse_nested(actions_orders[1], act_policy_, action_police_attrs, + ARRAY_SIZE(act_policy_)) ) { + VLOG_ERR_RL(&rl, "failed to parse action when getting meter stats"); + err = EPROTO; + goto err_out; + } + + act_stats = action_police_attrs[TCA_ACT_STATS]; + + if (!nl_parse_nested(act_stats, stats_policy, stats_attrs, + ARRAY_SIZE(stats_policy))) { + VLOG_ERR_RL(&rl, "failed to parse action stats policy"); + err = EPROTO; + goto err_out; + } + + bs = nl_attr_get_unspec(stats_attrs[TCA_STATS_BASIC], sizeof *bs); + if (bs->packets) { + put_32aligned_u64(&stats->n_packets, bs->packets); + put_32aligned_u64(&stats->n_bytes, bs->bytes); + } + +err_out: + ofpbuf_delete(reply); + return err; +} + static void dpif_netlink_meter_get_features(const struct dpif *dpif_, struct ofputil_meter_features *features) @@ -4478,8 +4592,13 @@ dpif_netlink_meter_get_stats(const struct dpif *dpif_, enum ovs_meter_cmd command) { struct dpif_netlink *dpif = dpif_netlink_cast(dpif_); + struct ovs_flow_stats stats_t; + struct ovs_flow_stats *stats_offload = &stats_t; struct ofpbuf buf, *msg; uint64_t stub[1024 / 8]; + int error; + + memset(&stats_t, 0, sizeof(struct ovs_flow_stats)); static const struct nl_policy ovs_meter_stats_policy[] = { [OVS_METER_ATTR_ID] = { .type = NL_A_U32, .optional = true}, @@ -4493,9 +4612,9 @@ dpif_netlink_meter_get_stats(const struct dpif *dpif_, nl_msg_put_u32(&buf, OVS_METER_ATTR_ID, meter_id.uint32); - int error = dpif_netlink_meter_transact(&buf, &msg, - ovs_meter_stats_policy, a, - ARRAY_SIZE(ovs_meter_stats_policy)); + error = dpif_netlink_meter_transact(&buf, &msg, + ovs_meter_stats_policy, a, + ARRAY_SIZE(ovs_meter_stats_policy)); if (error) { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); VLOG_INFO_RL(&rl, "dpif_netlink_meter_transact %s failed", @@ -4503,6 +4622,10 @@ dpif_netlink_meter_get_stats(const struct dpif *dpif_, return error; } + if (netdev_is_flow_api_enabled()) { + dpif_netlink_meter_get_stats_offloaded(meter_id, stats_offload); + } + if (stats && a[OVS_METER_ATTR_ID] && a[OVS_METER_ATTR_STATS] @@ -4516,6 +4639,13 @@ dpif_netlink_meter_get_stats(const struct dpif *dpif_, stats->packet_in_count = get_32aligned_u64(&stat->n_packets); stats->byte_in_count = get_32aligned_u64(&stat->n_bytes); + if (netdev_is_flow_api_enabled()) { + stats->packet_in_count += + get_32aligned_u64(&stats_offload->n_packets); + stats->byte_in_count += + get_32aligned_u64(&stats_offload->n_bytes); + } + if (a[OVS_METER_ATTR_BANDS]) { size_t n_bands = 0; NL_NESTED_FOR_EACH (nla, left, a[OVS_METER_ATTR_BANDS]) {