From patchwork Thu Jul 22 09:19:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 485116 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A497AC63793 for ; Thu, 22 Jul 2021 09:19:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8FB136120C for ; Thu, 22 Jul 2021 09:19:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231438AbhGVIjV (ORCPT ); Thu, 22 Jul 2021 04:39:21 -0400 Received: from mail-mw2nam10on2116.outbound.protection.outlook.com ([40.107.94.116]:34920 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231392AbhGVIjT (ORCPT ); Thu, 22 Jul 2021 04:39:19 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OsKt46CukyQMuWQ/KeNvaKzFtK4G+CbIfmvXE5rJgF4laqZ/ongdWZbZGrA+36idqBezxSXb0WDrECySa0t7mghT+O4LG1WlFafzyyyvXQ6ko5j+udw1QwNGm1pCqHFB4yEeyh+6Tqkd/iWq0CIqHRGXCenEgBWOjAA84LyoSGq+Eldes3ijhsjvCZ1aWuTtnXY45uHiPs98ojyAKKkD+ZLPBzgl1S+AxDDNgsTKlxSZDBNHGQRQcuI7esofXr8t0/q4WH78/YyTvjpbpcE6ctIylFtO6RWNHDgwOoa+l5rCnsWgS6LHSEw3TOffAEutmDifAjKMs+pV3ghm0pRIEg== 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-SenderADCheck; bh=Q80oKmxNL17D9s9qTL19JU1W6Si2xtc7eYc+23ApZG0=; b=RblhrsBXmb20Fv82qDB56qugNl48N/sfWre4g9CK3D54XeiXL2CDMKruagKOitn6Vf3aF+FwlaLBDkVVLnVK0Jap9t4jRYr2XCo3HtFSnghJfrZGyaFBnDseExI3uy9209dRYApBOk4VbkwWOX82iUw/AT5igWjMSeP6BNZ0HzD/HKE6mXbMiXwFjjrVMpy/TVPq41McDrgCJ45eqHp3+lYBmHKsh/FMPB3dB5u9oy6I6rE/A717FHLnurgBd4WY6ylmihKuaY8julVhcKbYGS1m7uak3t+5nkhy0JgqYNRV9H9xhM9zfLryzu8y+3TT2ALWVcGeCqhQN9gqUK/kLg== 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=Q80oKmxNL17D9s9qTL19JU1W6Si2xtc7eYc+23ApZG0=; b=AZAMkWDusFh8d2TrtrGP+SGxmUUngwSuhbYaflKIEkouLaXdrMKaZQg9WX7HOV1lcsYSLBiiof5oObgFDfXZJPuU6LROHzCLrGkkcU7PtdaKc/UP3E9/6dlfit4zhDXkRXJb7Na/BreSUYw+/7c/2gxlwcgIghEXnVy2jjb3h5M= Authentication-Results: davemloft.net; dkim=none (message not signed) header.d=none; davemloft.net; dmarc=none action=none header.from=corigine.com; Received: from PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) by PH0PR13MB4841.namprd13.prod.outlook.com (2603:10b6:510:a0::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.11; Thu, 22 Jul 2021 09:19:53 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::cd1:e3ba:77fd:f4f3]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::cd1:e3ba:77fd:f4f3%7]) with mapi id 15.20.4352.024; Thu, 22 Jul 2021 09:19:53 +0000 From: Simon Horman To: David Miller , Jakub Kicinski Cc: Jamal Hadi Salim , Cong Wang , Jiri Pirko , netdev@vger.kernel.org, oss-drivers@corigine.com, Baowen Zheng , Louis Peens , Simon Horman Subject: [PATCH net-next 1/3] flow_offload: allow user to offload tc action to net device Date: Thu, 22 Jul 2021 11:19:36 +0200 Message-Id: <20210722091938.12956-2-simon.horman@corigine.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210722091938.12956-1-simon.horman@corigine.com> References: <20210722091938.12956-1-simon.horman@corigine.com> X-ClientProxiedBy: AM4PR05CA0025.eurprd05.prod.outlook.com (2603:10a6:205::38) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from madeliefje.horms.nl (2001:982:7ed1:403:201:8eff:fe22:8fea) by AM4PR05CA0025.eurprd05.prod.outlook.com (2603:10a6:205::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.25 via Frontend Transport; Thu, 22 Jul 2021 09:19:51 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 18e54e94-f406-40ac-bdf3-08d94cf1dd56 X-MS-TrafficTypeDiagnostic: PH0PR13MB4841: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7Pt0y0QTC6VjuaoGDQFmEILEV3gawzRp5c5jBglaYfpV1vMH7UHKybVspX5AvmiNV62L9tmndq6vuwBbtryv8IEDv3MBSRbNXBA0TjVNATuxinjDG4Q4gEgBjpJe51se5QK3g2/P0rYAXb74czm/jTIj6dNXnTJGD/OFapA1v8RGXaAurb4j24mSpZsqdsTZeEruyXd4eiZWL+UpoeAQ6MwyT9LiHuez+DDXF0Y1b/ePPU9sBwI72AYsfm8LNe9FURIP0PKpoBDQYJgyvMQsRj0pxeyjjdudB9+tjxc6JHCc8egOs2V4BsGbEmSpwQJ3lcqSqvNjgbESdIB+VeAC9omkdLh7l/9c8VUnR1O+cozpyI2cK6HVbRljomX2MFqc6Uld6ZSRAMw3vT0huz66GTNpRFiExOgqGcsMd0esP7M6jhF/SA9N3KL9eRrmp29h+gG/zer+Pg/6RDcXuHdRTdgK2MVtzq6wSLRUucixgLYceUNUIsFmQkmI44oVqX2S/0d/bEdH8oTXdpwmm41jXOdA8RGEC61s/hqIC9L2/WngX7XPSySzkGEqG7CblZd+uBj3VKZBGtX1DNyc+OOh1Kr37feyDBLTUw/cL68QX3xQx/kVzUstwVhR+5wi5ePqeU2cGEojD1GwcrL7zl3U3A== 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)(366004)(396003)(39830400003)(136003)(376002)(6486002)(86362001)(8676002)(6666004)(2616005)(30864003)(6512007)(2906002)(54906003)(83380400001)(36756003)(66476007)(66556008)(8936002)(1076003)(107886003)(66946007)(110136005)(4326008)(186003)(44832011)(38100700002)(508600001)(316002)(52116002)(5660300002)(6506007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2395ysvrTkGhUaul62Zn2W+VYnDrztqu+Phz+tH+/noyLkmwzIlOkSAAoF3ICFOSxuppQQMtni+cnIbqE4gnI+qOGca9XLMIzE8vFmDZaVV4s8KOWsG2NBzEZ3lmstFx7ys+HGBqK0EV7PT6malCSVy5Bki6N2duP65LG9Z4TojlAPAhqswdu2/FeJU8bMqhkP1j6mG+E+Cgku5n82sYlh8dZtEe1OfrGEjvY07SUoFFG7QnTu0aXPTAAWs7rZa914BPxxDKMqerJtO3reYCYAr570Vp6m6R5TNa8QceXEA4zKZk1uUd/xy+n2FZqzdkdzn+kMcOTfiW+/Nm35soLHz5xKHUtiVYJZrZG8NZ/2Hd/Gks6kCgPrVVOK8XQ/G6A8GIU96rCb+67uNtYoEtI2A/AEiAkEIaBJcnCFe2cUHajrqkFMkQIsZpcfuWh40GKQ4AFVyvs2c0UPt/b54Gatk0hhqjduF5dTb26H0Z4ZYpOgZQmTdlM8ZOc3Fnyc7G8kFhhVFmbnbvAYcyj4pWgMXWsuBNXTmPu6m3PBqGMPN8TDDg3eYC/MFIJNIKo7WEbmMG1fLRKr0N/9SNL2bToBeBqcGvVRmV6hsDDAGTWn+5NmVR7by1R4hxBDgTYwoFohgRl7BYG3W8wKdHRForPNO+akesJwmPSwV2tM4gGR6shGTm0Qvjm3qdwgFjF0D2R/9tRYUjvGxCQUdRaAoOteHMq4p8qaMPLoZ0MUUlAVG3JaRqbfX9DBe9l+2M5R9HOErtOyDTM93PS2xmji/ucp1iiuYiPGJMKYSihRhr16e89vi0SAIL2fPabdE17j+9Ov9vPSrQsv6s0/VrE1F+fWiylTxxjq8ejpYgTPo+sYZL33TjzBbxWptg3IIAqWdNawFyWdXzoZWIvUAAi1OX50V07hmPI63MSRDJyqKPpUBe5aae47wPR98GsUavWmKnqt5/ru6QaoM/E6c47GmMcybHBdm0WtSYHjzDLcftCUhAiTAPZCD5+xKv8yfkNcSpxEYkaHViJLrlRWZ4fghC3RnJylPh3TZTtRT0rYZPyJcDSkhDOvU0NqcRxnOcN58tisnOE2CKckDDEl+qILJhGttEpLv675Jy9lZt1cmj63CQt1/Qdrk+C5Kub0FC1HggLQc2NLrlQGzJn5Q/RAzwKvjIhYg/7XX/oHcI2uL8FN+pnJttwHqWD4GQzKQ5cSYq3PI9FH4+Y0r5QtVZZMmEJNQgrRVDuniGl1St6Fwch7bZ0gJVYQN802+kvLXivY7slu1y8MWeto16WdicNCSBqkOCfEHr9cRgANBa9j2j4/dzBd0CgzdIcGd7HmLOwGWvATjd8o2srmfpztUsJB0SFlvqxyYH0VNbs44gH9XDlAQ59kDBe1jv2sHOgJllsl0b X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 18e54e94-f406-40ac-bdf3-08d94cf1dd56 X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2021 09:19:53.5358 (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: r04Y2TmFu3ju4S04aUbml25/4sEci9rDTPVCmXzhGJLjsdoQgRdONABAHGk3DXXW3QsNz18DBTWnSFnva7LRs96CyMdhPOgGhKtLo6IM5Es= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR13MB4841 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Baowen Zheng Use flow_indr_dev_register/flow_indr_dev_setup_offload to offload tc action. We offload the tc action mainly for ovs meter configuration. Make some basic changes for different vendors to return EOPNOTSUPP. We need to call tc_cleanup_flow_action to clean up tc action entry since in tc_setup_action, some actions may hold dev refcnt, especially the mirror action. As per review from the RFC, the kernel test robot will fail to run, so we add CONFIG_NET_CLS_ACT control for the action offload. Signed-off-by: Baowen Zheng Signed-off-by: Louis Peens Signed-off-by: Simon Horman --- drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c | 2 +- .../ethernet/mellanox/mlx5/core/en/rep/tc.c | 3 ++ .../ethernet/netronome/nfp/flower/offload.c | 3 ++ include/linux/netdevice.h | 1 + include/net/flow_offload.h | 15 ++++++++ include/net/pkt_cls.h | 15 ++++++++ net/core/flow_offload.c | 26 +++++++++++++- net/sched/act_api.c | 33 +++++++++++++++++ net/sched/cls_api.c | 36 ++++++++++++++++--- 9 files changed, 128 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c index 5e4429b14b8c..edbbf7b4df77 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c @@ -1951,7 +1951,7 @@ static int bnxt_tc_setup_indr_cb(struct net_device *netdev, struct Qdisc *sch, v void *data, void (*cleanup)(struct flow_block_cb *block_cb)) { - if (!bnxt_is_netdev_indr_offload(netdev)) + if (!netdev || !bnxt_is_netdev_indr_offload(netdev)) return -EOPNOTSUPP; switch (type) { diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c index 059799e4f483..111daacc4cc3 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c @@ -486,6 +486,9 @@ int mlx5e_rep_indr_setup_cb(struct net_device *netdev, struct Qdisc *sch, void * void *data, void (*cleanup)(struct flow_block_cb *block_cb)) { + if (!netdev) + return -EOPNOTSUPP; + switch (type) { case TC_SETUP_BLOCK: return mlx5e_rep_indr_setup_block(netdev, sch, cb_priv, type_data, diff --git a/drivers/net/ethernet/netronome/nfp/flower/offload.c b/drivers/net/ethernet/netronome/nfp/flower/offload.c index 2406d33356ad..88bbc86347b4 100644 --- a/drivers/net/ethernet/netronome/nfp/flower/offload.c +++ b/drivers/net/ethernet/netronome/nfp/flower/offload.c @@ -1869,6 +1869,9 @@ nfp_flower_indr_setup_tc_cb(struct net_device *netdev, struct Qdisc *sch, void * void *data, void (*cleanup)(struct flow_block_cb *block_cb)) { + if (!netdev) + return -EOPNOTSUPP; + if (!nfp_fl_is_netdev_to_offload(netdev)) return -EOPNOTSUPP; diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 42f6f866d5f3..b138219baf6f 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -923,6 +923,7 @@ enum tc_setup_type { TC_SETUP_QDISC_TBF, TC_SETUP_QDISC_FIFO, TC_SETUP_QDISC_HTB, + TC_SETUP_ACT, }; /* These structures hold the attributes of bpf state that are being passed diff --git a/include/net/flow_offload.h b/include/net/flow_offload.h index 69c9eabf8325..26644596fd54 100644 --- a/include/net/flow_offload.h +++ b/include/net/flow_offload.h @@ -553,6 +553,21 @@ struct flow_cls_offload { u32 classid; }; +enum flow_act_command { + FLOW_ACT_REPLACE, + FLOW_ACT_DESTROY, + FLOW_ACT_STATS, +}; + +struct flow_offload_action { + struct netlink_ext_ack *extack; + enum flow_act_command command; + struct flow_stats stats; + struct flow_action action; +}; + +struct flow_offload_action *flow_action_alloc(unsigned int num_actions); + static inline struct flow_rule * flow_cls_offload_flow_rule(struct flow_cls_offload *flow_cmd) { diff --git a/include/net/pkt_cls.h b/include/net/pkt_cls.h index ec7823921bd2..cd4cf6b10f5d 100644 --- a/include/net/pkt_cls.h +++ b/include/net/pkt_cls.h @@ -266,6 +266,9 @@ static inline void tcf_exts_put_net(struct tcf_exts *exts) for (; 0; (void)(i), (void)(a), (void)(exts)) #endif +#define tcf_act_for_each_action(i, a, actions) \ + for (i = 0; i < TCA_ACT_MAX_PRIO && ((a) = actions[i]); i++) + static inline void tcf_exts_stats_update(const struct tcf_exts *exts, u64 bytes, u64 packets, u64 drops, u64 lastuse, @@ -536,8 +539,19 @@ tcf_match_indev(struct sk_buff *skb, int ifindex) return ifindex == skb->skb_iif; } +#ifdef CONFIG_NET_CLS_ACT int tc_setup_flow_action(struct flow_action *flow_action, const struct tcf_exts *exts); +#else +static inline int tc_setup_flow_action(struct flow_action *flow_action, + const struct tcf_exts *exts) +{ + return 0; +} +#endif + +int tc_setup_action(struct flow_action *flow_action, + struct tc_action *actions[]); void tc_cleanup_flow_action(struct flow_action *flow_action); int tc_setup_cb_call(struct tcf_block *block, enum tc_setup_type type, @@ -558,6 +572,7 @@ int tc_setup_cb_reoffload(struct tcf_block *block, struct tcf_proto *tp, enum tc_setup_type type, void *type_data, void *cb_priv, u32 *flags, unsigned int *in_hw_count); unsigned int tcf_exts_num_actions(struct tcf_exts *exts); +unsigned int tcf_act_num_actions(struct tc_action *actions[]); #ifdef CONFIG_NET_CLS_ACT int tcf_qevent_init(struct tcf_qevent *qe, struct Qdisc *sch, diff --git a/net/core/flow_offload.c b/net/core/flow_offload.c index 715b67f6c62f..0fa2f75cc9b3 100644 --- a/net/core/flow_offload.c +++ b/net/core/flow_offload.c @@ -27,6 +27,27 @@ struct flow_rule *flow_rule_alloc(unsigned int num_actions) } EXPORT_SYMBOL(flow_rule_alloc); +struct flow_offload_action *flow_action_alloc(unsigned int num_actions) +{ + struct flow_offload_action *fl_action; + int i; + + fl_action = kzalloc(struct_size(fl_action, action.entries, num_actions), + GFP_KERNEL); + if (!fl_action) + return NULL; + + fl_action->action.num_entries = num_actions; + /* Pre-fill each action hw_stats with DONT_CARE. + * Caller can override this if it wants stats for a given action. + */ + for (i = 0; i < num_actions; i++) + fl_action->action.entries[i].hw_stats = FLOW_ACTION_HW_STATS_DONT_CARE; + + return fl_action; +} +EXPORT_SYMBOL(flow_action_alloc); + #define FLOW_DISSECTOR_MATCH(__rule, __type, __out) \ const struct flow_match *__m = &(__rule)->match; \ struct flow_dissector *__d = (__m)->dissector; \ @@ -476,6 +497,9 @@ int flow_indr_dev_setup_offload(struct net_device *dev, struct Qdisc *sch, mutex_unlock(&flow_indr_block_lock); - return list_empty(&bo->cb_list) ? -EOPNOTSUPP : 0; + if (bo) + return list_empty(&bo->cb_list) ? -EOPNOTSUPP : 0; + else + return 0; } EXPORT_SYMBOL(flow_indr_dev_setup_offload); diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 998a2374f7ae..185f17ea60d5 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -1060,6 +1060,36 @@ struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp, return ERR_PTR(err); } +/* offload the tc command after inserted */ +int tcf_action_offload_cmd(struct tc_action *actions[], + struct netlink_ext_ack *extack) +{ + struct flow_offload_action *fl_act; + int err = 0; + + fl_act = flow_action_alloc(tcf_act_num_actions(actions)); + if (!fl_act) + return -ENOMEM; + + fl_act->extack = extack; + err = tc_setup_action(&fl_act->action, actions); + if (err) { + NL_SET_ERR_MSG_MOD(extack, + "Failed to setup tc actions for offload\n"); + goto err_out; + } + fl_act->command = FLOW_ACT_REPLACE; + + flow_indr_dev_setup_offload(NULL, NULL, TC_SETUP_ACT, fl_act, NULL, NULL); + + tc_cleanup_flow_action(&fl_act->action); + +err_out: + kfree(fl_act); + return err; +} +EXPORT_SYMBOL(tcf_action_offload_cmd); + /* Returns numbers of initialized actions or negative error. */ int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla, @@ -1514,6 +1544,9 @@ static int tcf_action_add(struct net *net, struct nlattr *nla, return ret; ret = tcf_add_notify(net, n, actions, portid, attr_size, extack); + /* offload actions to hardware if possible */ + tcf_action_offload_cmd(actions, extack); + /* only put existing actions */ for (i = 0; i < TCA_ACT_MAX_PRIO; i++) if (init_res[i] == ACT_P_CREATED) diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c index c8cb59a11098..9b9770dab5e8 100644 --- a/net/sched/cls_api.c +++ b/net/sched/cls_api.c @@ -3544,8 +3544,8 @@ static enum flow_action_hw_stats tc_act_hw_stats(u8 hw_stats) return hw_stats; } -int tc_setup_flow_action(struct flow_action *flow_action, - const struct tcf_exts *exts) +int tc_setup_action(struct flow_action *flow_action, + struct tc_action *actions[]) { struct tc_action *act; int i, j, k, err = 0; @@ -3554,11 +3554,11 @@ int tc_setup_flow_action(struct flow_action *flow_action, BUILD_BUG_ON(TCA_ACT_HW_STATS_IMMEDIATE != FLOW_ACTION_HW_STATS_IMMEDIATE); BUILD_BUG_ON(TCA_ACT_HW_STATS_DELAYED != FLOW_ACTION_HW_STATS_DELAYED); - if (!exts) + if (!actions) return 0; j = 0; - tcf_exts_for_each_action(i, act, exts) { + tcf_act_for_each_action(i, act, actions) { struct flow_action_entry *entry; entry = &flow_action->entries[j]; @@ -3725,7 +3725,19 @@ int tc_setup_flow_action(struct flow_action *flow_action, spin_unlock_bh(&act->tcfa_lock); goto err_out; } +EXPORT_SYMBOL(tc_setup_action); + +#ifdef CONFIG_NET_CLS_ACT +int tc_setup_flow_action(struct flow_action *flow_action, + const struct tcf_exts *exts) +{ + if (!exts) + return 0; + + return tc_setup_action(flow_action, exts->actions); +} EXPORT_SYMBOL(tc_setup_flow_action); +#endif unsigned int tcf_exts_num_actions(struct tcf_exts *exts) { @@ -3743,6 +3755,22 @@ unsigned int tcf_exts_num_actions(struct tcf_exts *exts) } EXPORT_SYMBOL(tcf_exts_num_actions); +unsigned int tcf_act_num_actions(struct tc_action *actions[]) +{ + unsigned int num_acts = 0; + struct tc_action *act; + int i; + + tcf_act_for_each_action(i, act, actions) { + if (is_tcf_pedit(act)) + num_acts += tcf_pedit_nkeys(act); + else + num_acts++; + } + return num_acts; +} +EXPORT_SYMBOL(tcf_act_num_actions); + #ifdef CONFIG_NET_CLS_ACT static int tcf_qevent_parse_block_index(struct nlattr *block_index_attr, u32 *p_block_index, From patchwork Thu Jul 22 09:19:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 484329 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09CA4C63797 for ; Thu, 22 Jul 2021 09:20:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EAC0E6109F for ; Thu, 22 Jul 2021 09:19:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231446AbhGVIjW (ORCPT ); Thu, 22 Jul 2021 04:39:22 -0400 Received: from mail-mw2nam10on2126.outbound.protection.outlook.com ([40.107.94.126]:12705 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231421AbhGVIjV (ORCPT ); Thu, 22 Jul 2021 04:39:21 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fVrO/Q5YXFkNDoq37jglLGKkijI1uHY52svR6FkT0VVqU51CC0lEKZQQG2fDrDvxWPOBO6mgE8YG8W3QZGMobsTVMKXprf8kC60WmfS3uTXBTzcHjbNYF5GJvj4Xad8pYUZ4iv32fX1kd4aqOb1ZcFFVYsIT1bKHiWvYq4mogBFu4Rf37hKktSuHNDINVK4JcEqjxQInbD3hy7X9Vmdmrt669o+OV1ySMd+uc2V4H985dzLgcIPe62qJeLOqoD2nJwqlXqk9dE+JjNjyeTw5EpOhNazw4F0BR5NEHV/ubsL+9xdtmUrUd+h+6bYU2Rlz8f2vaDTMV8LFDGY1tMAmXQ== 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-SenderADCheck; bh=JBClcTPo2YiHUEHQ+/1LalfBn411jXgnDu/PohhgmjM=; b=EvUlTcsD7fOnjqXdKZy4vnJBa+xB2yrZdNl1EOzAjHJJVpnBdURmZO2P7ypSf++y+CwK6NTu1cD3GBAwjItBDryrToa493I2hMDyfT1NrrnYg7b0Vvc8dgOeaAMmFWWTKpO3WaY/0lI2KD1vBa9Bwlbai5iqdgSHg21+MNa/YJkbxU3K4/sAXY9JzkTs+QDn6/3h9EM8+upYOly3WvIYBuEPlyzYc2s2kZg2Qvl1FaJjvUsu9VzBKH98qIz069EfsrQLEvjEmUsgcKyUZr6DHiVv17qh0klyd4eUAJPVUGjIxPBiG5g4M2J0TNk06JPN/5UI9XHUk7n2fIbXgVGHEw== 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=JBClcTPo2YiHUEHQ+/1LalfBn411jXgnDu/PohhgmjM=; b=IHKJ9X1JwypsNdlxlYPwsv5WHnZRaHx6qToRW2Jypgwdhl/w0W9ghFU3oidxSOt2EJRbnac7ySLBHFwW98Ns60Ehk6L2dDn76SmxG4OCNym+Vo9r602iebD9n9MkH/tpDtMf0prc8w7O/oZBt9hgRQe6q+LEYpQLz5h6WYIg4HQ= Authentication-Results: davemloft.net; dkim=none (message not signed) header.d=none; davemloft.net; dmarc=none action=none header.from=corigine.com; Received: from PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) by PH0PR13MB4841.namprd13.prod.outlook.com (2603:10b6:510:a0::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.11; Thu, 22 Jul 2021 09:19:55 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::cd1:e3ba:77fd:f4f3]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::cd1:e3ba:77fd:f4f3%7]) with mapi id 15.20.4352.024; Thu, 22 Jul 2021 09:19:55 +0000 From: Simon Horman To: David Miller , Jakub Kicinski Cc: Jamal Hadi Salim , Cong Wang , Jiri Pirko , netdev@vger.kernel.org, oss-drivers@corigine.com, Baowen Zheng , Louis Peens , Simon Horman Subject: [PATCH net-next 2/3] flow_offload: add process to delete offloaded actions from net device Date: Thu, 22 Jul 2021 11:19:37 +0200 Message-Id: <20210722091938.12956-3-simon.horman@corigine.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210722091938.12956-1-simon.horman@corigine.com> References: <20210722091938.12956-1-simon.horman@corigine.com> X-ClientProxiedBy: AM4PR05CA0025.eurprd05.prod.outlook.com (2603:10a6:205::38) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from madeliefje.horms.nl (2001:982:7ed1:403:201:8eff:fe22:8fea) by AM4PR05CA0025.eurprd05.prod.outlook.com (2603:10a6:205::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.25 via Frontend Transport; Thu, 22 Jul 2021 09:19:53 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: bf5644d2-8be2-403a-faca-08d94cf1de9d X-MS-TrafficTypeDiagnostic: PH0PR13MB4841: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rFM/aw8od7ciTWqSdYjf2OT3E75+XJXo9DxsT5EYuenHXm7CtDjnlQi20WVob3G4l/elT7NliV32euqRbmg0PNn1d18zu7jyGKK/F6/56dx9OIz7ZZb54mBo1QzFtTx62f8WlRpP0wpN6iuwmkmhTnTXFMq2Eqihm42jKDxPaAso02swnAvOVnKn8hXmjCgiFuXataa1U6J3D9jvfEPpiYgCqjbyd9AjoNIqaamkYu5Hal56jGGIxy+igZLSnOgvsNQWGbmPQnx4fv6nTYd7emDQO1t+dtPb6hw+5WjhH8NKzuvveYGBRt+aTOwO9/pMF0u7BcTiGH4Bkrm+PfUA1saDjSmPYfGBsOi4rDAvW5sCBt7MZgx7OG93+MQvQ0Thao60JGhUZC70BSoAIbIly1hUDounUI+jA98J8bSIFsK0gjTRL2atXFmVvegJFEBKYtPz/HrhTjgdWxXqlX/36clVx3BLK0q+0DpiJABoZ0jFMlB96OEto9/k0x+RqN9kJ7ZT2FOv0Abii9Qm6NeOjtXOCNvAG60jjmjwu4KiSgvVx3zAKcgWVZhswhJUaPC+DJ6z9yZmX0rfF74iYaifj71HfwCPrU1ipQUUb4216oMv2DIIrHeEiR3Rgqj9/e9+aWyMMxbiRuVD+dEZduMh2w== 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)(366004)(396003)(39830400003)(136003)(376002)(6486002)(86362001)(8676002)(6666004)(2616005)(6512007)(2906002)(54906003)(83380400001)(36756003)(66476007)(66556008)(8936002)(1076003)(107886003)(66946007)(110136005)(4326008)(186003)(44832011)(38100700002)(508600001)(316002)(52116002)(5660300002)(6506007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: GxbPXmIEycdvkcwANvtDffY1T67pPVYk9ClNuJvYix6KJCojb1QO6U1XI2Ikw+L/y10SIza5OGvI71sD5Bwe4AeApqK/kGvbtXgf2gBKnkystwhmDR/aFOfzqCy0rTEXqZidcTjELVN8Et1rlOzzz/do877VVnTJzr0J8iQfz6rVoYb2SKefzOX/6YYu4G6HhAxcuGoWh6wYyibwmk/lwF6LTh8VHbvbbLgy4Un2sG5ovmk+4Zc31QrOU2tI1y4Sa7rfEj2frspyOTdMRYYqxBWa94HMByxw7LxbA80RCNPHvw8YL3AIy73irBCQwcNauGrF/+eBgb9VqMoOwMZl7j+XqXtfT3Gc10JDcZajwUkmI4h1sQXXbwjcPGji0VlbOqq1eLUXfJ+gJfUc4tyhBSpZX+1fq/akq5hQ8tdXcpJvy8RK3GUldbgTQOAA59hwi+nG5J+gxxLGi/PrkqGzYR+ppkiUnQfHaZG+lgKzHI8MV0kKfslQ7PcRFqHmnDqsjCkkiEUGD/tj5TVOPfsYeS1iph92EL02lIaPaD7xeE6TX2MKMIwzb3LDgOmBvoZgpTGsi7xj6IMM55q9noxgotwztAHhbDaurSmS64nK+7mFWAxRWtC/AApM1QHkdo+712bBjGDvCva3zmksTZqwAkheUNlthuZX23vh60CROCb2tRU6BzNHVGWkNhJKA8owcy/MNSoFVfJrpwDsPpSXd/RNmklme3Bj9TI6pd3n08a5xkpA47k9TpT7ojBy61qlGiXHFaNMGIQvisH7P8XQXAAuC1oReWQ5D14jE4Uln/roLXlSDK7GGs3PAjk8qF+g5Px/dkPgUCWBkSkeooiIbMsQSDe8NrQ1Ip0ISfBZUIm/bSTpO9RpmgkQ3VjrZvM+RbWFbjoTQZWS3svJPrcbBWj/rB+OWngGZ8z4xSwO+VJ+SOy+XZFLcS6DFE8fYIwMS+fgC2UQtSID0XSoh2sFK5fMHRBJ35FuzxwQH5nIDNaFIoVD9e5unr+ZKso4SyMvss/CXu12qcSS06TX1rzRf4SeT32c2Uz8haVUEwOGov1HfY+8M4t0QoECEEe4klCp7yyZDJjlzatTvXkZdzaFkgUC7N6RFjgP3w6CqGUeoZKJ7XPsET+mAXzmszDMF4vlYG6/9q+XyuP/DN0VbWrPLsuJLfo3ONN1DQ5lAUQq9ZFhULKkvkdJCTZm3HfnGwvundyZEykjzmcOqtj+fFqAYUQyDF8rScWdCG8v537nYusKHjIr3LlY69pwgph9JmPZgntzsJKrexlqcpW9Cb/FyZZhvd7bnb4SU41zM/x1ke8HC2yV/7s8Xba+xesLKvvjqKPTAxgOsw0g1c8yGcSfwXONLGgpqTem3MVx4bAcehuzVgfG0/lwTMJ5qNjETp01 X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: bf5644d2-8be2-403a-faca-08d94cf1de9d X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2021 09:19:55.6734 (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: MjnZ6HIIWmSuBtmSjL6uiqT9Y5n1eWrqpLxY3CO8tOYExjrbzkiuMT8hiQOHpRqjoucC1P1Q0uNMDU2Db0bhGJF6i16S5PfmVO4SIVNDZno= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR13MB4841 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Baowen Zheng Add a basic process to delete offloaded actions from net device. Should not remove the offloaded action entries if the action fails to delete in tcf_del_notify. Signed-off-by: Baowen Zheng Signed-off-by: Louis Peens Signed-off-by: Simon Horman --- include/net/pkt_cls.h | 1 + net/sched/act_api.c | 112 +++++++++++++++++++++++++++++++++++------- net/sched/cls_api.c | 14 ++++-- 3 files changed, 106 insertions(+), 21 deletions(-) diff --git a/include/net/pkt_cls.h b/include/net/pkt_cls.h index cd4cf6b10f5d..03dae225d64f 100644 --- a/include/net/pkt_cls.h +++ b/include/net/pkt_cls.h @@ -573,6 +573,7 @@ int tc_setup_cb_reoffload(struct tcf_block *block, struct tcf_proto *tp, void *cb_priv, u32 *flags, unsigned int *in_hw_count); unsigned int tcf_exts_num_actions(struct tcf_exts *exts); unsigned int tcf_act_num_actions(struct tc_action *actions[]); +unsigned int tcf_act_num_actions_single(struct tc_action *act); #ifdef CONFIG_NET_CLS_ACT int tcf_qevent_init(struct tcf_qevent *qe, struct Qdisc *sch, diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 185f17ea60d5..23a4538916af 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -1060,36 +1060,109 @@ struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp, return ERR_PTR(err); } -/* offload the tc command after inserted */ -int tcf_action_offload_cmd(struct tc_action *actions[], - struct netlink_ext_ack *extack) +int tcf_action_offload_cmd_pre(struct tc_action *actions[], + enum flow_act_command cmd, + struct netlink_ext_ack *extack, + struct flow_offload_action **fl_act) { - struct flow_offload_action *fl_act; + struct flow_offload_action *fl_act_p; int err = 0; - fl_act = flow_action_alloc(tcf_act_num_actions(actions)); - if (!fl_act) + fl_act_p = flow_action_alloc(tcf_act_num_actions(actions)); + if (!fl_act_p) return -ENOMEM; - fl_act->extack = extack; - err = tc_setup_action(&fl_act->action, actions); + fl_act_p->extack = extack; + fl_act_p->command = cmd; + err = tc_setup_action(&fl_act_p->action, actions); if (err) { NL_SET_ERR_MSG_MOD(extack, "Failed to setup tc actions for offload\n"); goto err_out; } - fl_act->command = FLOW_ACT_REPLACE; + *fl_act = fl_act_p; + return 0; +err_out: + kfree(fl_act_p); + return err; +} +EXPORT_SYMBOL(tcf_action_offload_cmd_pre); + +int tcf_action_offload_cmd_post(struct flow_offload_action *fl_act, + struct netlink_ext_ack *extack) +{ + if (IS_ERR(fl_act)) + return PTR_ERR(fl_act); flow_indr_dev_setup_offload(NULL, NULL, TC_SETUP_ACT, fl_act, NULL, NULL); tc_cleanup_flow_action(&fl_act->action); - -err_out: kfree(fl_act); - return err; + return 0; +} + +/* offload the tc command after inserted */ +int tcf_action_offload_cmd(struct tc_action *actions[], + struct netlink_ext_ack *extack) +{ + struct flow_offload_action *fl_act; + int err = 0; + + err = tcf_action_offload_cmd_pre(actions, + FLOW_ACT_REPLACE, + extack, + &fl_act); + if (err) + return err; + + return tcf_action_offload_cmd_post(fl_act, extack); } EXPORT_SYMBOL(tcf_action_offload_cmd); +/* offload the tc command after deleted */ +int tcf_action_offload_del_post(struct flow_offload_action *fl_act, + struct tc_action *actions[], + struct netlink_ext_ack *extack, + int fallback_num) +{ + int fallback_entries = 0; + struct tc_action *act; + int total_entries = 0; + int i; + + if (!fl_act) + return -EINVAL; + + if (fallback_num) { + /* for each the actions to fallback the action entries remain in the actions */ + for (i = 0; i < TCA_ACT_MAX_PRIO; i++) { + act = actions[i]; + if (!act) + continue; + + fallback_entries += tcf_act_num_actions_single(act); + } + fallback_entries += fallback_num; + } + total_entries = fl_act->action.num_entries; + if (total_entries > fallback_entries) { + /* just offload the actions that is not fallback and start with the actions */ + fl_act->action.num_entries -= fallback_entries; + flow_indr_dev_setup_offload(NULL, NULL, TC_SETUP_ACT, fl_act, NULL, NULL); + + /* recovery num_entries for cleanup */ + fl_act->action.num_entries = total_entries; + } else { + NL_SET_ERR_MSG(extack, "no entries to offload when deleting the tc actions"); + } + + tc_cleanup_flow_action(&fl_act->action); + + kfree(fl_act); + return 0; +} +EXPORT_SYMBOL(tcf_action_offload_del_post); + /* Returns numbers of initialized actions or negative error. */ int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla, @@ -1393,7 +1466,7 @@ static int tca_action_flush(struct net *net, struct nlattr *nla, return err; } -static int tcf_action_delete(struct net *net, struct tc_action *actions[]) +static int tcf_action_delete(struct net *net, struct tc_action *actions[], int *fallbacknum) { int i; @@ -1407,6 +1480,7 @@ static int tcf_action_delete(struct net *net, struct tc_action *actions[]) u32 act_index = a->tcfa_index; actions[i] = NULL; + *fallbacknum = tcf_act_num_actions_single(a); if (tcf_action_put(a)) { /* last reference, action was deleted concurrently */ module_put(ops->owner); @@ -1419,12 +1493,13 @@ static int tcf_action_delete(struct net *net, struct tc_action *actions[]) return ret; } } + *fallbacknum = 0; return 0; } static int tcf_del_notify(struct net *net, struct nlmsghdr *n, struct tc_action *actions[], - u32 portid, size_t attr_size, struct netlink_ext_ack *extack) + u32 portid, size_t attr_size, struct netlink_ext_ack *extack, int *fallbacknum) { int ret; struct sk_buff *skb; @@ -1442,7 +1517,7 @@ tcf_del_notify(struct net *net, struct nlmsghdr *n, struct tc_action *actions[], } /* now do the delete */ - ret = tcf_action_delete(net, actions); + ret = tcf_action_delete(net, actions, fallbacknum); if (ret < 0) { NL_SET_ERR_MSG(extack, "Failed to delete TC action"); kfree_skb(skb); @@ -1458,11 +1533,12 @@ static int tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n, u32 portid, int event, struct netlink_ext_ack *extack) { - int i, ret; struct nlattr *tb[TCA_ACT_MAX_PRIO + 1]; struct tc_action *act; size_t attr_size = 0; struct tc_action *actions[TCA_ACT_MAX_PRIO] = {}; + struct flow_offload_action *fl_act; + int i, ret, fallback_num; ret = nla_parse_nested_deprecated(tb, TCA_ACT_MAX_PRIO, nla, NULL, extack); @@ -1492,7 +1568,9 @@ tca_action_gd(struct net *net, struct nlattr *nla, struct nlmsghdr *n, if (event == RTM_GETACTION) ret = tcf_get_notify(net, portid, n, actions, event, extack); else { /* delete */ - ret = tcf_del_notify(net, n, actions, portid, attr_size, extack); + tcf_action_offload_cmd_pre(actions, FLOW_ACT_DESTROY, extack, &fl_act); + ret = tcf_del_notify(net, n, actions, portid, attr_size, extack, &fallback_num); + tcf_action_offload_del_post(fl_act, actions, extack, fallback_num); if (ret) goto err; return 0; diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c index 9b9770dab5e8..23ce021f07f8 100644 --- a/net/sched/cls_api.c +++ b/net/sched/cls_api.c @@ -3755,6 +3755,15 @@ unsigned int tcf_exts_num_actions(struct tcf_exts *exts) } EXPORT_SYMBOL(tcf_exts_num_actions); +unsigned int tcf_act_num_actions_single(struct tc_action *act) +{ + if (is_tcf_pedit(act)) + return tcf_pedit_nkeys(act); + else + return 1; +} +EXPORT_SYMBOL(tcf_act_num_actions_single); + unsigned int tcf_act_num_actions(struct tc_action *actions[]) { unsigned int num_acts = 0; @@ -3762,10 +3771,7 @@ unsigned int tcf_act_num_actions(struct tc_action *actions[]) int i; tcf_act_for_each_action(i, act, actions) { - if (is_tcf_pedit(act)) - num_acts += tcf_pedit_nkeys(act); - else - num_acts++; + num_acts += tcf_act_num_actions_single(act); } return num_acts; } From patchwork Thu Jul 22 09:19:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 485115 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E281C6377D for ; Thu, 22 Jul 2021 09:20:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 60EDD61019 for ; Thu, 22 Jul 2021 09:20:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231421AbhGVIja (ORCPT ); Thu, 22 Jul 2021 04:39:30 -0400 Received: from mail-mw2nam10on2134.outbound.protection.outlook.com ([40.107.94.134]:9156 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231392AbhGVIjX (ORCPT ); Thu, 22 Jul 2021 04:39:23 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A8fX0mXKmYtk8C3F1RwrgSeYlh9jstwN3UCPVw/VSEoKnvHeqmSwOgxhHLFSTjRzFUNRjTKR210b4Uj9OQYZ2tb5j4VMTiH2RTjcmIO0k7LTLNSUnJwP2GRSANx0DkmA8fY2QpbhGFwzKONQewmCk+aERG80iCdOE2AyrgeLVPM7hK+7xfsYwGKC4V2xJaoNrFnDEPlpOfMczEQRzjJTTRUGcmrwfP/t+LEzm9QXj8FOJdBXLr3/lD4dJqEnAUQcRQtS9FQkWdIuz6+GanFQh39MvAefQRtiLu3fwUkl7Mv2Ibux94G4MplY9k8MGXf0zOJ3wRqXN6coJ1B8+1AgYQ== 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-SenderADCheck; bh=N/jM9NQIrl/kX0wAj/XjT+uNKnF0Co6YFWIbN/klhDE=; b=Veqzsm2td8vH+sy+B4uVuSCXw5dcYIKPiADyl4U6i84o/R26rrQ/u9yG//w9XzT+Vth/DEFH2wmQJ4rPtIvsq09Ray2qH+qud90Lwgh44Hww/lQCKBxmWPS3kjI25jucQYQSkkbeOxK10eLoQh3gygIqnzgIC3Y88jrVh//qWmPgUB3CNi20TB54SQh56ndGMqNlQCxwhFO9/FAPCLkI6gOnt9mLAvmcudcmLHvVbEUEf9OZw/iIHfNdzTwIiBo5pMNyrbeRiiPaBsMakkyWJxBI8H+4waAPmF1OmAU0s7ecJulPyGTTMch/HEuvBtbuOxYpdNM8PhYTDXBawE8T5Q== 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=N/jM9NQIrl/kX0wAj/XjT+uNKnF0Co6YFWIbN/klhDE=; b=jAwP/IrECNRPrmhkSud2qrlAOdIfS51cusfroyCVQJU0OuCQWB93XusJenf9a7qxIBbgN4gM/gZi7zHQfLwwN1i6g36wUBwcqmfnl4X3JXVbxcxBTLuEgzX3jkBOxq60v7FZ+iwel4i0Mh1KyPbKcaLY9Ke1pwGSa2E3WawFAyo= Authentication-Results: davemloft.net; dkim=none (message not signed) header.d=none; davemloft.net; dmarc=none action=none header.from=corigine.com; Received: from PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) by PH0PR13MB4841.namprd13.prod.outlook.com (2603:10b6:510:a0::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.11; Thu, 22 Jul 2021 09:19:58 +0000 Received: from PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::cd1:e3ba:77fd:f4f3]) by PH0PR13MB4842.namprd13.prod.outlook.com ([fe80::cd1:e3ba:77fd:f4f3%7]) with mapi id 15.20.4352.024; Thu, 22 Jul 2021 09:19:58 +0000 From: Simon Horman To: David Miller , Jakub Kicinski Cc: Jamal Hadi Salim , Cong Wang , Jiri Pirko , netdev@vger.kernel.org, oss-drivers@corigine.com, Baowen Zheng , Louis Peens , Simon Horman Subject: [PATCH net-next 3/3] flow_offload: add process to update action stats from hardware Date: Thu, 22 Jul 2021 11:19:38 +0200 Message-Id: <20210722091938.12956-4-simon.horman@corigine.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210722091938.12956-1-simon.horman@corigine.com> References: <20210722091938.12956-1-simon.horman@corigine.com> X-ClientProxiedBy: AM4PR05CA0025.eurprd05.prod.outlook.com (2603:10a6:205::38) To PH0PR13MB4842.namprd13.prod.outlook.com (2603:10b6:510:78::6) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from madeliefje.horms.nl (2001:982:7ed1:403:201:8eff:fe22:8fea) by AM4PR05CA0025.eurprd05.prod.outlook.com (2603:10a6:205::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4352.25 via Frontend Transport; Thu, 22 Jul 2021 09:19:56 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 534a7ce2-6fdc-4acb-8c49-08d94cf1dfef X-MS-TrafficTypeDiagnostic: PH0PR13MB4841: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:148; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cQHsgRPShjP66pyUSWmedFDtgxVa9Ry9SVtlbNaiUU8sMlACTvcaxa03QpibqCogdDijCSuA3z8LKxJZrlkD90/Wxi5E0RAxRDUtRKzL64CvNxVtbmD4jUCca81bQZ8qt6FqXU9oChhFocVMoAXgvBlyqwTBjpPmAH4tob/KbYIiODomV5WPUbabLRy3SrWv0Yit3YDQBSqbwjYDRcOsyA/g5iIT1lywcKNr79vUpZpkyNBqXf2aRRjVMwlJvWAtTuz2dwUtKyqEj6g2H7d50lDHU/VynZx+hD0GeVy8nHOdmReQM0kcFCLlkIrq43RwQ4YIDUVVXgv5LZTTRVh0EPtSMKpXFS5FrkFYw6O5XcOGGrQkoiA7urkIGH81D8P8sz1PLfsKpiajo4Se7oQxk/MRdRHGRt/ptB/QMzvftvyeBOPOy4Bg9SlJKgqvTdmY6u8kafHbLCvB9ZoH6Ffl8xLtR/KTRqzz4qYzN+VE+SUOupzqgwabIeS1ZV0S/R3RJZQiw3EAsX0KzktzG9fByz1O0SGqb3GBZhsy7vc1oOueiuOwnynNGYgnsOp21iHKNmiEGqxc8VKomAMfcswLrILQNKH0HszHosPo8WXqD888Yv8HxZW9SQHJj5qzdO6o6EEaB5PR2v75uUPUS/OKug== 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)(366004)(396003)(39830400003)(136003)(376002)(6486002)(86362001)(8676002)(6666004)(2616005)(6512007)(2906002)(54906003)(83380400001)(36756003)(66476007)(66556008)(8936002)(1076003)(15650500001)(107886003)(66946007)(110136005)(4326008)(186003)(44832011)(38100700002)(508600001)(316002)(52116002)(5660300002)(6506007); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WxFn0a5RT/g/xWaSkFLH4JV8CMKpauMKbpQtW6XdjIuEtOs7+4qmUfeUkpjJxsimJJLEP9/V7r11qk6tVzfW4Dh/rjHsCQW/OqbZNfye4eSui8mDMwoplWIot2ksSkRSAzJdJhZF/NcDtBmKYoMDTs0C5B0/qtS7C0bWuvOBwONZA3qAlcBwuhYtdF6bW/73bOQ4r8pnX7gLsnPImiLYBGmRa47GDRG9zvm7EqSY08ogPp3rC9jhkt/6wu4pamAR3a+h1pcmxou+edT3tfsHWdrxaMGPVlIgigc0w0Nht3/4pLOKGHML3afNT5Ac9k26AZdxw+/vmuNhIgHEaoiZMDrjchlt8vcPQOMPEJM2bkVgr/WFs0Dew4eTdybDeJB/XYMm1rYscjJbbj6UjAaYFIPkDuh/30Z3tRIbtawcL/e78R9VkS+LkpKGi6iLVYn3Q61T29TGmD+U4DB8H8gdGt7z2d5Sl7nvILhhZu6yCJzkVqK74HTCTpRTvv7apEKx0c10VomoX+iN5aMaUIVK5MldsdhvOs5lu4mSKsPXklD7VHWveIizZ5mzwFiV+HQ1ybFjaxlMUTZvDZ9r16Tte2Z/ZdxBCNQ5dy1Us4l6ZgIEn/jCk1g0+TlwICDLW2G8Starj9EftDgN7wQrIF8Fqiqa+MdG9Jnof51Q7MAHYpKpVB0idkZiXVcL4796a1jCN28JO1ufiqY1KqV6oVTGkgxhg7F4Zmdiu4QuEhe4EDXtP/YAz63loqZrXyWWyOi0W3QPHuMUixwKtRq6EUo9mo2uKVhJxmjwRxIYwfjDgdV7rB1/ZGulozD4CNP0NuIzBou9mCI4icbeKOop6HWKoX6osx1wpXrrta0LJOOcYZ1+VWyavTQE7Gv+f1qnLMJC53n1fn80YDbnZo/vajz+ruZBBSdDjWkqSjjhsrMPJtMfc7csYezSPbFWA0ZJxC0M00zhCVMrp4H29a0X1K/m5BY8+l2AaJNNtg+9Ddj3y5lDL7+8zSZNygmRoPv0oEkO556EVa8bdGmeZEY6Zu5Xe4Qi0QuZQnZ+YiqxIwu4e7zO17NY5CrxrUHEk7vTyLfZYHqBun5Czv2GSaXYs9eMCAkyXZtfh82ZJ+wxcDXYYEQEPqXyUoZH407ybwibsFO8QrK62iLrHC8AffjTfGrSXe6FZ1A5rPfTj2OUHOMseZtKyc0IDne+9Ex00X1P13ud1EOQp7WjXZEHUU07Ozg229wq9x+eBifqeVYgQYOfNE17HOVH75TLxrSe5JMpMDyHyauN0aIEFR2pDo/6/8CBQSOj0yZa7nGKhtHUUoofv4geKKwp3M9epsiYWaTqLsMav/tELpYfHkZWkqzF04w4NHmCrUEgZ8/+USgiqw2P9xZ87Am+UN3aqC0hGkbJYmXC X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 534a7ce2-6fdc-4acb-8c49-08d94cf1dfef X-MS-Exchange-CrossTenant-AuthSource: PH0PR13MB4842.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2021 09:19:57.8727 (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: ODfOAY1cBgb0HKDooF3ljtdsepAs6Ku+wXeBb7c64wHSxOON6Mvffx3RodLklgu5uLHuywFE4R6rGKzH3ltiMHD23hXyUc/DYQGcj12W9CI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR13MB4841 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Baowen Zheng When collecting stats for actions update them using both both hardware and software counters. Signed-off-by: Baowen Zheng Signed-off-by: Louis Peens Signed-off-by: Simon Horman --- include/net/act_api.h | 1 + include/net/flow_offload.h | 2 +- include/net/pkt_cls.h | 4 ++++ net/sched/act_api.c | 49 ++++++++++++++++++++++++++++++++++---- 4 files changed, 51 insertions(+), 5 deletions(-) diff --git a/include/net/act_api.h b/include/net/act_api.h index 086b291e9530..fe8331b5efce 100644 --- a/include/net/act_api.h +++ b/include/net/act_api.h @@ -233,6 +233,7 @@ static inline void tcf_action_inc_overlimit_qstats(struct tc_action *a) void tcf_action_update_stats(struct tc_action *a, u64 bytes, u64 packets, u64 drops, bool hw); int tcf_action_copy_stats(struct sk_buff *, struct tc_action *, int); +int tcf_action_update_hw_stats(struct tc_action *action); int tcf_action_check_ctrlact(int action, struct tcf_proto *tp, struct tcf_chain **handle, diff --git a/include/net/flow_offload.h b/include/net/flow_offload.h index 26644596fd54..467688fff7ce 100644 --- a/include/net/flow_offload.h +++ b/include/net/flow_offload.h @@ -560,7 +560,7 @@ enum flow_act_command { }; struct flow_offload_action { - struct netlink_ext_ack *extack; + struct netlink_ext_ack *extack; /* NULL in FLOW_ACT_STATS process*/ enum flow_act_command command; struct flow_stats stats; struct flow_action action; diff --git a/include/net/pkt_cls.h b/include/net/pkt_cls.h index 03dae225d64f..569c9294b15b 100644 --- a/include/net/pkt_cls.h +++ b/include/net/pkt_cls.h @@ -282,6 +282,10 @@ tcf_exts_stats_update(const struct tcf_exts *exts, for (i = 0; i < exts->nr_actions; i++) { struct tc_action *a = exts->actions[i]; + /* if stats from hw, just skip */ + if (!tcf_action_update_hw_stats(a)) + continue; + tcf_action_stats_update(a, bytes, packets, drops, lastuse, true); a->used_hw_stats = used_hw_stats; diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 23a4538916af..7d5535bc2c13 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -1089,15 +1089,18 @@ int tcf_action_offload_cmd_pre(struct tc_action *actions[], EXPORT_SYMBOL(tcf_action_offload_cmd_pre); int tcf_action_offload_cmd_post(struct flow_offload_action *fl_act, - struct netlink_ext_ack *extack) + struct netlink_ext_ack *extack, + bool keep_fl_act) { if (IS_ERR(fl_act)) return PTR_ERR(fl_act); flow_indr_dev_setup_offload(NULL, NULL, TC_SETUP_ACT, fl_act, NULL, NULL); - tc_cleanup_flow_action(&fl_act->action); - kfree(fl_act); + if (!keep_fl_act) { + tc_cleanup_flow_action(&fl_act->action); + kfree(fl_act); + } return 0; } @@ -1115,10 +1118,45 @@ int tcf_action_offload_cmd(struct tc_action *actions[], if (err) return err; - return tcf_action_offload_cmd_post(fl_act, extack); + return tcf_action_offload_cmd_post(fl_act, extack, false); } EXPORT_SYMBOL(tcf_action_offload_cmd); +int tcf_action_update_hw_stats(struct tc_action *action) +{ + struct tc_action *actions[TCA_ACT_MAX_PRIO] = { + [0] = action, + }; + struct flow_offload_action *fl_act; + int err = 0; + + err = tcf_action_offload_cmd_pre(actions, + FLOW_ACT_STATS, + NULL, + &fl_act); + if (err) + goto err_out; + + err = tcf_action_offload_cmd_post(fl_act, NULL, true); + + if (fl_act->stats.lastused) { + tcf_action_stats_update(action, fl_act->stats.bytes, + fl_act->stats.pkts, + fl_act->stats.drops, + fl_act->stats.lastused, + true); + err = 0; + } else { + err = -EOPNOTSUPP; + } + tc_cleanup_flow_action(&fl_act->action); + kfree(fl_act); + +err_out: + return err; +} +EXPORT_SYMBOL(tcf_action_update_hw_stats); + /* offload the tc command after deleted */ int tcf_action_offload_del_post(struct flow_offload_action *fl_act, struct tc_action *actions[], @@ -1255,6 +1293,9 @@ int tcf_action_copy_stats(struct sk_buff *skb, struct tc_action *p, if (p == NULL) goto errout; + /* update hw stats for this action */ + tcf_action_update_hw_stats(p); + /* compat_mode being true specifies a call that is supposed * to add additional backward compatibility statistic TLVs. */