From patchwork Fri Oct 1 11:32:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 12530375 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A6BCC433F5 for ; Fri, 1 Oct 2021 11:33:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E51F161AAC for ; Fri, 1 Oct 2021 11:33:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353932AbhJALew (ORCPT ); Fri, 1 Oct 2021 07:34:52 -0400 Received: from mail-bn8nam12on2134.outbound.protection.outlook.com ([40.107.237.134]:33569 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1353920AbhJALeu (ORCPT ); Fri, 1 Oct 2021 07:34:50 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VLMTL7SKzXbGqTGLBRPBBIGq1Uq1VZfJJr/wy4W52+F2tzCeos/8/ZDjvfAG5D+Z1ZsGdUS6UbINW6MXwa8VUaaK6WCiagrIagmLceG7Dzz6TBiX0FRy2gkntIoW9zRPCBvMMeHKVOBI40pOmUtsvHE1tiBlWJC4O2WkkI+vrW1ZKki/3CcH+ulk6FRpLHrwTrcA/0J43NuTdqtoVCUQo36InCEwdR0QScgeaNDl1Mn8H2lRcDed/BlmIgw4kUxcmGzhuSh8UiiHtOaF0NwcmBZ3/pMwMqhA6cuTphdXXtsE+nt9ffVFD/GVlQ481rEdwfZNhcR/Cs5hGyM6HHsyOw== 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=rzkvAljhlxUs5fUjeumyA5sbGFpShpyMtdakJeFZom0=; b=nQJ/X/CIASNnKB1X4pfc1wh3lhUmMrAIykfO/86wnCpIf1oIXAff7kCE18oQCnFN5q3GzXN9FKbDVSGWuKbHKC8KNL5qbagkflw3R/5CYueG8tT43DiVg4a9mHYjR/Ag9KRo72QGsJ9y2zDeuW941w/9ib/IwjO4sK/iDGafLKmbZ0o9iJuKK/HEU7XlsC7+GCMMSxYXMkobGjkpBsgyaOE8Hqx9s9l3uhzXrlD8KP/k478ehh95fwMPu5sWQq3NHIezHvAQOVmPHmiKLejV29Sh2KUv/Ss6PL3GcojjFJPKyhd8HPWJK5+vxLaiyCh15nxNN4rz0TSStexoW3pqxg== 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=rzkvAljhlxUs5fUjeumyA5sbGFpShpyMtdakJeFZom0=; b=kYjx4/SHxVa6HIiQ9tfRo9ONZP3yeHyNRIkKih4Wg1cEtbJGoD42XsxP2ARU6tAZPLcPpT8ufzipcJg/qUky9ZCwqmdWMKBN9uP5456cRTJYSvJpu0MpNyNFCSC9EsDU9EEeNMac7fvY4fZeArlj7BoiFx5szowPFp3QudUBWpw= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=corigine.com; Received: from BY3PR13MB4834.namprd13.prod.outlook.com (2603:10b6:a03:36b::10) by BY3PR13MB4804.namprd13.prod.outlook.com (2603:10b6:a03:355::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.7; Fri, 1 Oct 2021 11:33:05 +0000 Received: from BY3PR13MB4834.namprd13.prod.outlook.com ([fe80::4e4:4194:c369:de5e]) by BY3PR13MB4834.namprd13.prod.outlook.com ([fe80::4e4:4194:c369:de5e%8]) with mapi id 15.20.4587.007; Fri, 1 Oct 2021 11:33:05 +0000 From: Simon Horman To: netdev@vger.kernel.org Cc: Jamal Hadi Salim , Roi Dayan , Vlad Buslov , Cong Wang , Jiri Pirko , Baowen Zheng , Louis Peens , oss-drivers@corigine.com, Baowen Zheng , Simon Horman Subject: [RFC/PATCH net-next v2 1/5] flow_offload: fill flags to action structure Date: Fri, 1 Oct 2021 13:32:33 +0200 Message-Id: <20211001113237.14449-2-simon.horman@corigine.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211001113237.14449-1-simon.horman@corigine.com> References: <20211001113237.14449-1-simon.horman@corigine.com> X-ClientProxiedBy: AM8P191CA0023.EURP191.PROD.OUTLOOK.COM (2603:10a6:20b:21a::28) To BY3PR13MB4834.namprd13.prod.outlook.com (2603:10b6:a03:36b::10) MIME-Version: 1.0 Received: from momiji.horms.nl (2001:982:756:703:d63d:7eff:fe99:ac9d) by AM8P191CA0023.EURP191.PROD.OUTLOOK.COM (2603:10a6:20b:21a::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14 via Frontend Transport; Fri, 1 Oct 2021 11:33:03 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 988a0171-be89-4ac6-662b-08d984cf3c5f X-MS-TrafficTypeDiagnostic: BY3PR13MB4804: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:179; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fOc3azy0KUzv0xaid9kItHCRgm7bpyHzfvHiLh1fjA0l20Frnki5spLSuMdHjzRiAOlb58qot5vYg+G4JCeFOyYXyXb7YH8JIoUOvKyt8wvQ6W3eqi80tTZoXwIyRiCaLnRU0PyAR/VO3qEJ8uBVeozt8efpYRAkL3F0JfCnIYHbsXBUglOotawfcYvoaHSsbDHgzU4rnjSG/37oiHBlNg/VtvuxUrs5yluZOV7DzSXzi0A+r+33WGJuflM9u63VVc20luMXHtW+N3PfI5zcy6dcP/1GOvCFjLXZvwV7QW0SUqAirfvvqaHtuUc3kxtQWwaAPWuKKQ1nWmpJRYRM8UXcwiO9NVe7DQvEnhgPfTwiNHlSFtHTHWOCoaCIZ7p1xSMejKb9K1sIWzjY8TZAsivH7gv/m2UbY/kg6HaZsEISeeZ2YPgTIVTavT1oVE/H6qJhJgnSy/jJq0wHoxtp8sM7FKT0FT+Hs9Nc+n8Np/mFUX9G390FALI1pCtj6ykf/PiT5hCMyS/Rn1HqrgrbqQudygyCpXRKO9ue6Rr0B8TJzSpBZun3qhx5tywnDZCqLS1HFw94gk8ioxEkMu8DLjo3zHslLf7RjhUBqzmLWqNC64Iqe1Sq+JWMB2nnzAK29uFckToJ88sVmCbnwzjpCQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY3PR13MB4834.namprd13.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(346002)(396003)(376002)(366004)(39830400003)(2616005)(66946007)(86362001)(36756003)(8676002)(508600001)(8936002)(6486002)(54906003)(1076003)(316002)(66476007)(2906002)(107886003)(66556008)(186003)(52116002)(6666004)(4326008)(6916009)(44832011)(5660300002)(6506007)(6512007)(38100700002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tY8Ubrw3vWrjeSZ4a/vTHlaV8VwYPw1mT+QChzudw1Yj1LS/AoOX3yn+92tPiY2u5UZCg4QhzdCy5BhbcqYRYyOOkLjIMVzs9K9ER3pneEe9MswvL0MBUt2bQacRCq/2Lless+NKXTLswKponSJpjmkTWJiO/4scEGA0Opd+No9Q2N4CRW0WOUc7T8LgIqU1ySOIZhzLT297D4afcAiHqmMw3GUsyHRusS3hNSFmmLGmSaX6D91kKXSvs2AXc+tXn+5IRUjIm1v5yAFrgH6AWWJFkyXCUVCgg+CN1eX2Rv5LA0bQ/kslxmc/SyFK6iVA4285Iz2ty/cGIZ9zTLK+b/29ujyBYHQScz5Q5EhelqWzSktZmDFtJ8JzLc/cbnbeqjZ1+a6czk5HjHBDgT7IbEMtkFoblinuymrj2iYY9QhgTBkTFnOXey2QG028Gwfbxzi14XtMGLSVpeFVK+z3e3jO08NF4Mn8nelqSn9Lm9XujkYz4cyPKss5gdj1Z7acjoxQswe+SUyTFy4htobYtLDZHQ+dcMXruUvTEZV4Pyckl6r38YXzbT1VASyrIU3/jltCT0Dwl8Q4+hYMAy2EPPHYJpsAcgp5BSlZ6wFTO/VAfayQEJe6xNi2LUEr6NEI0TvIT6ZcZ6x5lZz40WM5+zAfL/Z4QMAME7JnZFtbb+Omvd3u4l6Scho5cvlP/9EpMRBYaqzGqHDJmL7KYrADZTN7dGh7l7WSxd4JZxZ3wLJjjbAdcuayo447VXIEMWT5QIBgUTxJKaISKNvxD+ERDCNLALSjvB0HS1KnN2f8uskH7sgxq0RlLEL12bLF2dDs5cRTT2G6/KjQfMAbH9F5b5M+uShMTH+6KmkdEmcWGSZBtgnvNbAJVqMWNdpUZhvuLaSVk1CSERwpnezYqW7hhGUjLHDTDr18Xuq4MBw4iywi35GdlU5EMPsVtS1vc5V3dx3fK0QqfhJDIAFhvKem7EWJauz7RKs5QLNk8EWWyBhMpDqgDMF1zz5DKyz4ASgVgyoECnC8WPaRKpBWKsmkHu4I/fPV1VdV39P7Wz2JZlsPvbpBQ3SUh06YUyTVR12iGwUSu8ffoP9lKhk9x6eDSKtVbHDnq9qby3W7TK8eiDIFeeW7TG3A3IqSNHPV2qorBcx3+3UuEod4jlDckJVwAGrPA/K8ywrUPnLvr6kaWEOq3FvUJ5AAHTsNCl3+LmmktE9nKdmZIw5N3ih56/jIHpyB0cvJvoNwTZ/blk9+NDqIqVqUF3FrrUJIH7+R1xCFjS4m5l/d4CJ4XnTRIw5S86qbNnoj0Px3d2NR5vT7j8sEMZqt3hH1vCapdasJUz1PUwDImiqT9fXZy/ttVV/0FqDbViw6qDbTTgk+ozV3FZEaqPk7Oq8TdermJ/zMUk2D X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 988a0171-be89-4ac6-662b-08d984cf3c5f X-MS-Exchange-CrossTenant-AuthSource: BY3PR13MB4834.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2021 11:33:05.6692 (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: WcNsbL9UqpQYASzxRbnb6yglCULnouzr6eYRAcjmqVWXSoybdoHI9G7j5uV4hAri/D/H0NmqEd91xL/XG3myPKG5N4l0bnGs5EgmX8p7TDo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY3PR13MB4804 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Baowen Zheng Fill flags to action structure to allow user control if the action should be offloaded to hardware or not. Signed-off-by: Baowen Zheng Signed-off-by: Louis Peens Signed-off-by: Simon Horman --- net/sched/act_bpf.c | 2 +- net/sched/act_connmark.c | 2 +- net/sched/act_ctinfo.c | 2 +- net/sched/act_gate.c | 2 +- net/sched/act_ife.c | 2 +- net/sched/act_ipt.c | 2 +- net/sched/act_mpls.c | 2 +- net/sched/act_nat.c | 2 +- net/sched/act_pedit.c | 2 +- net/sched/act_police.c | 2 +- net/sched/act_sample.c | 2 +- net/sched/act_simple.c | 2 +- net/sched/act_skbedit.c | 2 +- net/sched/act_skbmod.c | 2 +- 14 files changed, 14 insertions(+), 14 deletions(-) diff --git a/net/sched/act_bpf.c b/net/sched/act_bpf.c index 5c36013339e1..2a05bad56ef3 100644 --- a/net/sched/act_bpf.c +++ b/net/sched/act_bpf.c @@ -305,7 +305,7 @@ static int tcf_bpf_init(struct net *net, struct nlattr *nla, ret = tcf_idr_check_alloc(tn, &index, act, bind); if (!ret) { ret = tcf_idr_create(tn, index, est, act, - &act_bpf_ops, bind, true, 0); + &act_bpf_ops, bind, true, flags); if (ret < 0) { tcf_idr_cleanup(tn, index); return ret; diff --git a/net/sched/act_connmark.c b/net/sched/act_connmark.c index 94e78ac7a748..09e2aafc8943 100644 --- a/net/sched/act_connmark.c +++ b/net/sched/act_connmark.c @@ -124,7 +124,7 @@ static int tcf_connmark_init(struct net *net, struct nlattr *nla, ret = tcf_idr_check_alloc(tn, &index, a, bind); if (!ret) { ret = tcf_idr_create(tn, index, est, a, - &act_connmark_ops, bind, false, 0); + &act_connmark_ops, bind, false, flags); if (ret) { tcf_idr_cleanup(tn, index); return ret; diff --git a/net/sched/act_ctinfo.c b/net/sched/act_ctinfo.c index 549374a2d008..0281e45987a4 100644 --- a/net/sched/act_ctinfo.c +++ b/net/sched/act_ctinfo.c @@ -212,7 +212,7 @@ static int tcf_ctinfo_init(struct net *net, struct nlattr *nla, err = tcf_idr_check_alloc(tn, &index, a, bind); if (!err) { ret = tcf_idr_create(tn, index, est, a, - &act_ctinfo_ops, bind, false, 0); + &act_ctinfo_ops, bind, false, flags); if (ret) { tcf_idr_cleanup(tn, index); return ret; diff --git a/net/sched/act_gate.c b/net/sched/act_gate.c index 7df72a4197a3..ac985c53ebaf 100644 --- a/net/sched/act_gate.c +++ b/net/sched/act_gate.c @@ -357,7 +357,7 @@ static int tcf_gate_init(struct net *net, struct nlattr *nla, if (!err) { ret = tcf_idr_create(tn, index, est, a, - &act_gate_ops, bind, false, 0); + &act_gate_ops, bind, false, flags); if (ret) { tcf_idr_cleanup(tn, index); return ret; diff --git a/net/sched/act_ife.c b/net/sched/act_ife.c index 7064a365a1a9..ec987ec75807 100644 --- a/net/sched/act_ife.c +++ b/net/sched/act_ife.c @@ -553,7 +553,7 @@ static int tcf_ife_init(struct net *net, struct nlattr *nla, if (!exists) { ret = tcf_idr_create(tn, index, est, a, &act_ife_ops, - bind, true, 0); + bind, true, flags); if (ret) { tcf_idr_cleanup(tn, index); kfree(p); diff --git a/net/sched/act_ipt.c b/net/sched/act_ipt.c index 265b1443e252..2f3d507c24a1 100644 --- a/net/sched/act_ipt.c +++ b/net/sched/act_ipt.c @@ -145,7 +145,7 @@ static int __tcf_ipt_init(struct net *net, unsigned int id, struct nlattr *nla, if (!exists) { ret = tcf_idr_create(tn, index, est, a, ops, bind, - false, 0); + false, flags); if (ret) { tcf_idr_cleanup(tn, index); return ret; diff --git a/net/sched/act_mpls.c b/net/sched/act_mpls.c index e4529b428cf4..4eb8751e1ad7 100644 --- a/net/sched/act_mpls.c +++ b/net/sched/act_mpls.c @@ -248,7 +248,7 @@ static int tcf_mpls_init(struct net *net, struct nlattr *nla, if (!exists) { ret = tcf_idr_create(tn, index, est, a, - &act_mpls_ops, bind, true, 0); + &act_mpls_ops, bind, true, flags); if (ret) { tcf_idr_cleanup(tn, index); return ret; diff --git a/net/sched/act_nat.c b/net/sched/act_nat.c index 7dd6b586ba7f..2a39b3729e84 100644 --- a/net/sched/act_nat.c +++ b/net/sched/act_nat.c @@ -61,7 +61,7 @@ static int tcf_nat_init(struct net *net, struct nlattr *nla, struct nlattr *est, err = tcf_idr_check_alloc(tn, &index, a, bind); if (!err) { ret = tcf_idr_create(tn, index, est, a, - &act_nat_ops, bind, false, 0); + &act_nat_ops, bind, false, flags); if (ret) { tcf_idr_cleanup(tn, index); return ret; diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c index c6c862c459cc..cd3b8aad3192 100644 --- a/net/sched/act_pedit.c +++ b/net/sched/act_pedit.c @@ -189,7 +189,7 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla, err = tcf_idr_check_alloc(tn, &index, a, bind); if (!err) { ret = tcf_idr_create(tn, index, est, a, - &act_pedit_ops, bind, false, 0); + &act_pedit_ops, bind, false, flags); if (ret) { tcf_idr_cleanup(tn, index); goto out_free; diff --git a/net/sched/act_police.c b/net/sched/act_police.c index 832157a840fc..d95addd8dec5 100644 --- a/net/sched/act_police.c +++ b/net/sched/act_police.c @@ -90,7 +90,7 @@ static int tcf_police_init(struct net *net, struct nlattr *nla, if (!exists) { ret = tcf_idr_create(tn, index, NULL, a, - &act_police_ops, bind, true, 0); + &act_police_ops, bind, true, flags); if (ret) { tcf_idr_cleanup(tn, index); return ret; diff --git a/net/sched/act_sample.c b/net/sched/act_sample.c index 230501eb9e06..ab4ae24ab886 100644 --- a/net/sched/act_sample.c +++ b/net/sched/act_sample.c @@ -70,7 +70,7 @@ static int tcf_sample_init(struct net *net, struct nlattr *nla, if (!exists) { ret = tcf_idr_create(tn, index, est, a, - &act_sample_ops, bind, true, 0); + &act_sample_ops, bind, true, flags); if (ret) { tcf_idr_cleanup(tn, index); return ret; diff --git a/net/sched/act_simple.c b/net/sched/act_simple.c index cbbe1861d3a2..788527154025 100644 --- a/net/sched/act_simple.c +++ b/net/sched/act_simple.c @@ -128,7 +128,7 @@ static int tcf_simp_init(struct net *net, struct nlattr *nla, if (!exists) { ret = tcf_idr_create(tn, index, est, a, - &act_simp_ops, bind, false, 0); + &act_simp_ops, bind, false, flags); if (ret) { tcf_idr_cleanup(tn, index); return ret; diff --git a/net/sched/act_skbedit.c b/net/sched/act_skbedit.c index 605418538347..1bb0266e62c2 100644 --- a/net/sched/act_skbedit.c +++ b/net/sched/act_skbedit.c @@ -176,7 +176,7 @@ static int tcf_skbedit_init(struct net *net, struct nlattr *nla, if (!exists) { ret = tcf_idr_create(tn, index, est, a, - &act_skbedit_ops, bind, true, 0); + &act_skbedit_ops, bind, true, flags); if (ret) { tcf_idr_cleanup(tn, index); return ret; diff --git a/net/sched/act_skbmod.c b/net/sched/act_skbmod.c index ecb9ee666095..ee9cc0abf9e1 100644 --- a/net/sched/act_skbmod.c +++ b/net/sched/act_skbmod.c @@ -168,7 +168,7 @@ static int tcf_skbmod_init(struct net *net, struct nlattr *nla, if (!exists) { ret = tcf_idr_create(tn, index, est, a, - &act_skbmod_ops, bind, true, 0); + &act_skbmod_ops, bind, true, flags); if (ret) { tcf_idr_cleanup(tn, index); return ret; From patchwork Fri Oct 1 11:32:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 12530377 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A389C433EF for ; Fri, 1 Oct 2021 11:33:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E3B2761AAA for ; Fri, 1 Oct 2021 11:33:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353955AbhJALfC (ORCPT ); Fri, 1 Oct 2021 07:35:02 -0400 Received: from mail-bn8nam12on2115.outbound.protection.outlook.com ([40.107.237.115]:36537 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1353956AbhJALe7 (ORCPT ); Fri, 1 Oct 2021 07:34:59 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m58Y7KcX756PMjtn9d09y9dpMVfAnU/OSZ/3vB33q/fon49kahXVdRBhWefEnSPHkFrkUGJf6HHM2MauQQsmbcteqV6vx0flt0wc99OporhA5MG2SJFkcRihiaw4RJf6RiJc1gUlDiWo682DGuxZwDsVpRaSR/b9No3PRIrbin9QkvTkqzWnSX8RQV+gm6xEOakiBCDF2qOKTQtexC81lJ3tmQndVMQlEANNt/qAghwuSE863Zf5H5ZnnErnCg4W2f1Yq9W35hEsPd4kGrCQD/B2ohzjPiNQzwGTNHhmrvnuohkI1VVuSqzXWz8yCfGrda6NY3zk1FOqX70fcej40A== 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=odT68ZVOn25LuOYH6SHXTUkH39ibfmGwnXPDjedQclo=; b=CTjwDnMhZ/YaUMKiWkh06T4wM89trDk/b/S929/5GwtfG7WPX9XRcJgi3UtFbdeA7gQ1bxP4NQdrS2REDJcjnupW0Rn+gwSTAXtkg91kDyPcb6jCgsOZ4ATlsUwaMe9PYpeoRj5XxSYxo9E38CP4EYt/2dLfxpccJWY+fN8/IEcRF4RBkHPDDmgBPFYThmdRjRti3NK/ea7KTUjcfdl1EOYuQ2aiZ7hm72FMh6762iRzjj8erXiIZWK2OddV9NEnRk0Ff1gMFteoIc8jvEc9VhUHQbxt0qtGykAFvZrNSzxbT/xyZyi2hmfB171d9PjJMEhu410mhk0W7cyX/uyP9A== 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=odT68ZVOn25LuOYH6SHXTUkH39ibfmGwnXPDjedQclo=; b=kPzer2B/rrJKf/uYh9q3NBHhueCSkcUZMHaIaTBvrA+ER00odl0frP3MuYJ3SlY1Oritp79ds1iTpnmcCLYZGrcqWWtdi6oQiAIgU5ZC4JDl8Uc7GzqWK1yA2u9RAQGveOlJ3xkPTX0ScgMQCi4Dko3fVHJ2AUedNIb3OfySujU= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=corigine.com; Received: from BY3PR13MB4834.namprd13.prod.outlook.com (2603:10b6:a03:36b::10) by BY3PR13MB4804.namprd13.prod.outlook.com (2603:10b6:a03:355::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.7; Fri, 1 Oct 2021 11:33:08 +0000 Received: from BY3PR13MB4834.namprd13.prod.outlook.com ([fe80::4e4:4194:c369:de5e]) by BY3PR13MB4834.namprd13.prod.outlook.com ([fe80::4e4:4194:c369:de5e%8]) with mapi id 15.20.4587.007; Fri, 1 Oct 2021 11:33:08 +0000 From: Simon Horman To: netdev@vger.kernel.org Cc: Jamal Hadi Salim , Roi Dayan , Vlad Buslov , Cong Wang , Jiri Pirko , Baowen Zheng , Louis Peens , oss-drivers@corigine.com, Baowen Zheng , Simon Horman Subject: [RFC/PATCH net-next v2 2/5] flow_offload: allow user to offload tc action to net device Date: Fri, 1 Oct 2021 13:32:34 +0200 Message-Id: <20211001113237.14449-3-simon.horman@corigine.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211001113237.14449-1-simon.horman@corigine.com> References: <20211001113237.14449-1-simon.horman@corigine.com> X-ClientProxiedBy: AM8P191CA0023.EURP191.PROD.OUTLOOK.COM (2603:10a6:20b:21a::28) To BY3PR13MB4834.namprd13.prod.outlook.com (2603:10b6:a03:36b::10) MIME-Version: 1.0 Received: from momiji.horms.nl (2001:982:756:703:d63d:7eff:fe99:ac9d) by AM8P191CA0023.EURP191.PROD.OUTLOOK.COM (2603:10a6:20b:21a::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14 via Frontend Transport; Fri, 1 Oct 2021 11:33:05 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 472f882e-dd07-45ec-e55f-08d984cf3dda X-MS-TrafficTypeDiagnostic: BY3PR13MB4804: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1775; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fWDbBPDg+gjYQ0NaTYCokb1Qf45O9aA5Zwoe9RiVDrW7BVuPtQwgUKv62GOG+GpiTGKRFCwwEDrZaZKUvi2zxCebHdLYRAhsp+xtmwY6ZElwh/AnTNu/QoxtEZAgk+o2wVhK7x4K2w/OUyHGNtQ/bH2K6Yl6JYqirSehFHFfMNmL43Y+fvjmBdcIroF6QDrj+Zqz5t8h5XoDLLLyKIef1fs3fDp0IhAql/TNbfNO8ShjOPFlH5Pd080A5b6AO1FHiCXpSPv8oTV5me5RkY+k4oGDFcYd7hCNiXMpY7hfOGMF5jZLOxKHahlNcXwuRKRycho2uuWOBZ5oAzK6Nq7fd7vw5btulo7QeIreoAczFIPWhAVcSPsXDHgz9w+iwMo2JD+1gm9M+pefYVx2nt/CmvgleFESJf7DXR5J/9sFJPdmgOw0mfI6ecTWY780ycuSms2JE1wRAclfB7e33M/i214u+dqnhO67nnsvt3V8CV4AnIVUrrNqbAzXey8puacL9871ew1qwdP4X6HG1AnpS2h89YBbqLDJrVikyeJdHfzpmRKSNK/UtvT2kjaKFdLCC1WlOkR5m4NfXr14vHLDQJ9PTeUPW/tzs6553f6L4LmQ45TC5lkGZX+eUnT6bWnisIjUDxK3HdWj2w5cOJWHAw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY3PR13MB4834.namprd13.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(346002)(396003)(376002)(366004)(39830400003)(2616005)(66946007)(86362001)(36756003)(8676002)(508600001)(8936002)(6486002)(30864003)(54906003)(1076003)(316002)(66476007)(2906002)(107886003)(66556008)(186003)(52116002)(6666004)(4326008)(6916009)(44832011)(5660300002)(6506007)(6512007)(38100700002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qXze8abLgslKHDeG9tgDMw1vNx2Md9ptfajpefO15ahD1tihC4NfRFSBvnUxRXYIUuvcUF4sBVzm4KZ9vgy6EERKMuOMuSdG+jjioIJZ+wh6c219UItsV39CWy+VPAyp8KBUNPVCQCJskrnMkXDq2NNPWU95n/cTsl001d4zk6Jo1hESUL0dWzM2as+nOlQ2mCrUJq90OZ2htftvn28ClFLvJ4C7x7y3g1GLmVkW2rdaXoZO5NH/evE5Z+y1zMtHcmSAA10o/oHzXBfN8u4YSg/do7BMYrQ8Eb8PBa4Mau/hrrQl0ygxv22Uo9r6V9xkfgFMEPa5IAWsZM5geQniI4ezrLdCyaIvaQsC9+++fvWFmsCyuNTeLvBUqx9BiwNQfl4hwdzUvUo/99oIbpuN2E0scBCm26zjFgmBcjtWr0o+drrJht1hLVMvimOExz5akv60jKg3MCnM85FNmkiwtn4VssBcY30Q9LnoDTgoLR4dKjw1+gBwSsQmD1ntEXF9NaqKk+TIpkUtXVQzLKHh+UqSAbGh1pVaEicEOm/fhLC7NhfEpz5CcBzmDriipu0PTFRd64UGijth9TDpLmvmbyGKdpU33kCEpMsYm/Pwns+vyIPlTmsQyYithL0b8GhMhpkVEUuUBD7US1ZeSb1p1OtQzAZR8eWYQlvw9UXvG6VB/WoNrbCTOvYE0flO2IgxVk/wcdu5c/kpvKNSOKcAqU6bHrtYcltc4XphUP27SsPOi+FIURJzdEOhaO1Ezc2JSBbmFlK5npbwIVaFnTpvq77TY8xu40iJ9YZ0bSnvn5N8BZVbF1+dl4idQEXCoLsBoTIdovjybGcGX24EsOKmYWdIJo6InXpnClJlIcFDEjH8gC9Juu2ou/SE5YEylpjpLc/nbId9JaOIfEXfUQWUDYZKEdaGZowQ6kOYv0AMz8mXdFx7EpTZAjGUZ/vSho3sSjQybTUmm5slhcd+QFJ/w5PiBg15I9e6h0AKepNFBbtPg0RsShBFygjjJQrmPF2aPeAiaCXxaIhAuVvWseKAkaRJBeKYGm+1i+5+v98hmSxj9stcXodkSQyxksCrG0VV+Fkmgij6LnPQKTSF30E/i0CCvIkibs5/5PsH3khVs7lZYfgFWnqR2PVcmJMsMHdUNRxLGpa7POT4N044lzTplhan1kCdFIZHKWnVMWV4cf3pmxU313pfTnEgbYRZPTKKE+tSQTTR7rgMLMa80lZOeHWQn7dCbceGbxpwqA0btVI3xFDbA9Lrdhp7EhgomaAj+ggfY4fyL4p0wSDUDKwbNzaCMlf12A+jAJeWPALQKHwr1ABcG/8aoycVcbI9P2XJ7eSJz9BYlJQ5zcCQG6RIKOLcd9/b5lTkrsQJsyJuiDN2MNCRxHU4S3ACxel9EfWH X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 472f882e-dd07-45ec-e55f-08d984cf3dda X-MS-Exchange-CrossTenant-AuthSource: BY3PR13MB4834.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2021 11:33:08.2539 (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: XI22XStwU6ErCi3Q6QvSMeANmLOulotcT8nRxjdxIOkb0bTLl+r2J6bpbAFnohY75YfgH3VAgWmss9ZQEPTy/zfTqd/l5sxxhCBLa3dQYZs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY3PR13MB4804 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Baowen Zheng Use flow_indr_dev_register/flow_indr_dev_setup_offload to offload tc action. We add skip_hw and skip_sw for user to control if offload the action to hardware. 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. drivers should update the hw_counter in flow action to indicate it accepts to offload the action. Add a basic process to delete offloaded actions from net device. 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/act_api.h | 3 +- include/net/flow_offload.h | 27 ++ include/net/pkt_cls.h | 40 +++ include/uapi/linux/pkt_cls.h | 12 +- net/core/flow_offload.c | 43 ++- net/sched/act_api.c | 251 +++++++++++++++++- net/sched/cls_api.c | 29 +- 11 files changed, 395 insertions(+), 19 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c index e6a4a768b10b..8c9bab932478 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_tc.c @@ -1962,7 +1962,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 398c6761eeb3..5e69357df295 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/rep/tc.c @@ -497,6 +497,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 64c0ef57ad42..17190fe17a82 100644 --- a/drivers/net/ethernet/netronome/nfp/flower/offload.c +++ b/drivers/net/ethernet/netronome/nfp/flower/offload.c @@ -1867,6 +1867,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 d79163208dfd..a5fa6fa91772 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -916,6 +916,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/act_api.h b/include/net/act_api.h index f19f7f4a463c..656a74002a98 100644 --- a/include/net/act_api.h +++ b/include/net/act_api.h @@ -44,6 +44,7 @@ struct tc_action { u8 hw_stats; u8 used_hw_stats; bool used_hw_stats_valid; + u32 in_hw_count; }; #define tcf_index common.tcfa_index #define tcf_refcnt common.tcfa_refcnt @@ -239,7 +240,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_offload_del(struct tc_action *action); int tcf_action_check_ctrlact(int action, struct tcf_proto *tp, struct tcf_chain **handle, struct netlink_ext_ack *newchain); diff --git a/include/net/flow_offload.h b/include/net/flow_offload.h index 3961461d9c8b..bf76baca579d 100644 --- a/include/net/flow_offload.h +++ b/include/net/flow_offload.h @@ -148,6 +148,10 @@ enum flow_action_id { FLOW_ACTION_MPLS_MANGLE, FLOW_ACTION_GATE, FLOW_ACTION_PPPOE_PUSH, + FLOW_ACTION_PEDIT, /* generic action type of pedit action for action + * offload, it will be different type when adding + * tc actions + */ NUM_FLOW_ACTIONS, }; @@ -552,6 +556,29 @@ struct flow_cls_offload { u32 classid; }; +enum flow_act_command { + FLOW_ACT_REPLACE, + FLOW_ACT_DESTROY, + FLOW_ACT_STATS, +}; + +enum flow_act_hw_oper { + FLOW_ACT_HW_ADD, + FLOW_ACT_HW_UPDATE, + FLOW_ACT_HW_DEL, +}; + +struct flow_offload_action { + struct netlink_ext_ack *extack; /* NULL in FLOW_ACT_STATS process*/ + enum flow_act_command command; + enum flow_action_id id; + u32 index; + 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 83a6d0792180..3bb4e6f45038 100644 --- a/include/net/pkt_cls.h +++ b/include/net/pkt_cls.h @@ -258,6 +258,34 @@ 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 bool tc_act_skip_hw(u32 flags) +{ + return (flags & TCA_ACT_FLAGS_SKIP_HW) ? true : false; +} + +static inline bool tc_act_skip_sw(u32 flags) +{ + return (flags & TCA_ACT_FLAGS_SKIP_SW) ? true : false; +} + +static inline bool tc_act_in_hw(u32 flags) +{ + return (flags & TCA_ACT_FLAGS_IN_HW) ? true : false; +} + +/* SKIP_HW and SKIP_SW are mutually exclusive flags. */ +static inline bool tc_act_flags_valid(u32 flags) +{ + flags &= TCA_ACT_FLAGS_SKIP_HW | TCA_ACT_FLAGS_SKIP_SW; + if (!(flags ^ (TCA_ACT_FLAGS_SKIP_HW | TCA_ACT_FLAGS_SKIP_SW))) + return false; + + return true; +} + static inline void tcf_exts_stats_update(const struct tcf_exts *exts, u64 bytes, u64 packets, u64 drops, u64 lastuse, @@ -532,8 +560,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, @@ -554,6 +593,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_single(struct tc_action *act); #ifdef CONFIG_NET_CLS_ACT int tcf_qevent_init(struct tcf_qevent *qe, struct Qdisc *sch, diff --git a/include/uapi/linux/pkt_cls.h b/include/uapi/linux/pkt_cls.h index 6836ccb9c45d..616e78cde822 100644 --- a/include/uapi/linux/pkt_cls.h +++ b/include/uapi/linux/pkt_cls.h @@ -19,13 +19,19 @@ enum { TCA_ACT_FLAGS, TCA_ACT_HW_STATS, TCA_ACT_USED_HW_STATS, + TCA_ACT_IN_HW_COUNT, __TCA_ACT_MAX }; /* See other TCA_ACT_FLAGS_ * flags in include/net/act_api.h. */ -#define TCA_ACT_FLAGS_NO_PERCPU_STATS 1 /* Don't use percpu allocator for - * actions stats. - */ +#define TCA_ACT_FLAGS_NO_PERCPU_STATS (1 << 0) /* Don't use percpu allocator for + * actions stats. + */ +#define TCA_ACT_FLAGS_SKIP_HW (1 << 1) /* don't offload action to HW */ +#define TCA_ACT_FLAGS_SKIP_SW (1 << 2) /* don't use action in SW */ +#define TCA_ACT_FLAGS_IN_HW (1 << 3) /* action is offloaded to HW */ +#define TCA_ACT_FLAGS_NOT_IN_HW (1 << 4) /* action isn't offloaded to HW */ +#define TCA_ACT_FLAGS_VERBOSE (1 << 5) /* verbose logging */ /* tca HW stats type * When user does not pass the attribute, he does not care. diff --git a/net/core/flow_offload.c b/net/core/flow_offload.c index 6beaea13564a..6676431733ef 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; \ @@ -549,19 +570,25 @@ int flow_indr_dev_setup_offload(struct net_device *dev, struct Qdisc *sch, void (*cleanup)(struct flow_block_cb *block_cb)) { struct flow_indr_dev *this; + u32 count = 0; + int err; mutex_lock(&flow_indr_block_lock); + if (bo) { + if (bo->command == FLOW_BLOCK_BIND) + indir_dev_add(data, dev, sch, type, cleanup, bo); + else if (bo->command == FLOW_BLOCK_UNBIND) + indir_dev_remove(data); + } - if (bo->command == FLOW_BLOCK_BIND) - indir_dev_add(data, dev, sch, type, cleanup, bo); - else if (bo->command == FLOW_BLOCK_UNBIND) - indir_dev_remove(data); - - list_for_each_entry(this, &flow_block_indr_dev_list, list) - this->cb(dev, sch, this->cb_priv, type, bo, data, cleanup); + list_for_each_entry(this, &flow_block_indr_dev_list, list) { + err = this->cb(dev, sch, this->cb_priv, type, bo, data, cleanup); + if (!err) + count++; + } mutex_unlock(&flow_indr_block_lock); - return list_empty(&bo->cb_list) ? -EOPNOTSUPP : 0; + return (bo && list_empty(&bo->cb_list)) ? -EOPNOTSUPP : count; } EXPORT_SYMBOL(flow_indr_dev_setup_offload); diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 7dd3a2dc5fa4..3e18f3456afa 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -21,6 +21,19 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #ifdef CONFIG_INET DEFINE_STATIC_KEY_FALSE(tcf_frag_xmit_count); @@ -145,6 +158,7 @@ static int __tcf_action_put(struct tc_action *p, bool bind) if (refcount_dec_and_mutex_lock(&p->tcfa_refcnt, &idrinfo->lock)) { if (bind) atomic_dec(&p->tcfa_bindcnt); + tcf_action_offload_del(p); idr_remove(&idrinfo->action_idr, p->tcfa_index); mutex_unlock(&idrinfo->lock); @@ -341,6 +355,7 @@ static int tcf_idr_release_unsafe(struct tc_action *p) return -EPERM; if (refcount_dec_and_test(&p->tcfa_refcnt)) { + tcf_action_offload_del(p); idr_remove(&p->idrinfo->action_idr, p->tcfa_index); tcf_action_cleanup(p); return ACT_P_DELETED; @@ -448,6 +463,7 @@ static int tcf_idr_delete_index(struct tcf_idrinfo *idrinfo, u32 index) if (refcount_dec_and_test(&p->tcfa_refcnt)) { struct module *owner = p->ops->owner; + tcf_action_offload_del(p); WARN_ON(p != idr_remove(&idrinfo->action_idr, p->tcfa_index)); mutex_unlock(&idrinfo->lock); @@ -733,6 +749,9 @@ int tcf_action_exec(struct sk_buff *skb, struct tc_action **actions, jmp_prgcnt -= 1; continue; } + + if (tc_act_skip_sw(a->tcfa_flags)) + continue; repeat: ret = a->ops->act(skb, a, res); if (ret == TC_ACT_REPEAT) @@ -838,6 +857,9 @@ tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int bind, int ref) a->tcfa_flags, a->tcfa_flags)) goto nla_put_failure; + if (nla_put_u32(skb, TCA_ACT_IN_HW_COUNT, a->in_hw_count)) + goto nla_put_failure; + nest = nla_nest_start_noflag(skb, TCA_OPTIONS); if (nest == NULL) goto nla_put_failure; @@ -917,7 +939,9 @@ static const struct nla_policy tcf_action_policy[TCA_ACT_MAX + 1] = { [TCA_ACT_COOKIE] = { .type = NLA_BINARY, .len = TC_COOKIE_MAX_SIZE }, [TCA_ACT_OPTIONS] = { .type = NLA_NESTED }, - [TCA_ACT_FLAGS] = NLA_POLICY_BITFIELD32(TCA_ACT_FLAGS_NO_PERCPU_STATS), + [TCA_ACT_FLAGS] = NLA_POLICY_BITFIELD32(TCA_ACT_FLAGS_NO_PERCPU_STATS | + TCA_ACT_FLAGS_SKIP_HW | + TCA_ACT_FLAGS_SKIP_SW), [TCA_ACT_HW_STATS] = NLA_POLICY_BITFIELD32(TCA_ACT_HW_STATS_ANY), }; @@ -1030,8 +1054,13 @@ struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp, } } hw_stats = tcf_action_hw_stats_get(tb[TCA_ACT_HW_STATS]); - if (tb[TCA_ACT_FLAGS]) + if (tb[TCA_ACT_FLAGS]) { userflags = nla_get_bitfield32(tb[TCA_ACT_FLAGS]); + if (!tc_act_flags_valid(userflags.value)) { + err = -EINVAL; + goto err_out; + } + } err = a_o->init(net, tb[TCA_ACT_OPTIONS], est, &a, tp, userflags.value | flags, extack); @@ -1059,6 +1088,219 @@ struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp, return ERR_PTR(err); } +static int flow_action_init(struct flow_offload_action *fl_action, + struct tc_action *act, + enum flow_act_command cmd, + struct netlink_ext_ack *extack) +{ + int err; + + if (!fl_action) + return -EINVAL; + + fl_action->extack = extack; + fl_action->command = cmd; + fl_action->index = act->tcfa_index; + + if (is_tcf_gact_ok(act)) { + fl_action->id = FLOW_ACTION_ACCEPT; + } else if (is_tcf_gact_shot(act)) { + fl_action->id = FLOW_ACTION_DROP; + } else if (is_tcf_gact_trap(act)) { + fl_action->id = FLOW_ACTION_TRAP; + } else if (is_tcf_gact_goto_chain(act)) { + fl_action->id = FLOW_ACTION_GOTO; + } else if (is_tcf_mirred_egress_redirect(act)) { + fl_action->id = FLOW_ACTION_REDIRECT; + } else if (is_tcf_mirred_egress_mirror(act)) { + fl_action->id = FLOW_ACTION_MIRRED; + } else if (is_tcf_mirred_ingress_redirect(act)) { + fl_action->id = FLOW_ACTION_REDIRECT_INGRESS; + } else if (is_tcf_mirred_ingress_mirror(act)) { + fl_action->id = FLOW_ACTION_MIRRED_INGRESS; + } else if (is_tcf_vlan(act)) { + switch (tcf_vlan_action(act)) { + case TCA_VLAN_ACT_PUSH: + fl_action->id = FLOW_ACTION_VLAN_PUSH; + break; + case TCA_VLAN_ACT_POP: + fl_action->id = FLOW_ACTION_VLAN_POP; + break; + case TCA_VLAN_ACT_MODIFY: + fl_action->id = FLOW_ACTION_VLAN_MANGLE; + break; + default: + err = -EOPNOTSUPP; + goto err_out; + } + } else if (is_tcf_tunnel_set(act)) { + fl_action->id = FLOW_ACTION_TUNNEL_ENCAP; + } else if (is_tcf_tunnel_release(act)) { + fl_action->id = FLOW_ACTION_TUNNEL_DECAP; + } else if (is_tcf_pedit(act)) { + fl_action->id = FLOW_ACTION_PEDIT; + } else if (is_tcf_csum(act)) { + fl_action->id = FLOW_ACTION_CSUM; + } else if (is_tcf_skbedit_mark(act)) { + fl_action->id = FLOW_ACTION_MARK; + } else if (is_tcf_sample(act)) { + fl_action->id = FLOW_ACTION_SAMPLE; + } else if (is_tcf_police(act)) { + fl_action->id = FLOW_ACTION_POLICE; + } else if (is_tcf_ct(act)) { + fl_action->id = FLOW_ACTION_CT; + } else if (is_tcf_mpls(act)) { + switch (tcf_mpls_action(act)) { + case TCA_MPLS_ACT_PUSH: + fl_action->id = FLOW_ACTION_MPLS_PUSH; + break; + case TCA_MPLS_ACT_POP: + fl_action->id = FLOW_ACTION_MPLS_POP; + break; + case TCA_MPLS_ACT_MODIFY: + fl_action->id = FLOW_ACTION_MPLS_MANGLE; + break; + default: + err = -EOPNOTSUPP; + goto err_out; + } + } else if (is_tcf_skbedit_ptype(act)) { + fl_action->id = FLOW_ACTION_PTYPE; + } else if (is_tcf_skbedit_priority(act)) { + fl_action->id = FLOW_ACTION_PRIORITY; + } else if (is_tcf_gate(act)) { + fl_action->id = FLOW_ACTION_GATE; + } else { + goto err_out; + } + return 0; + +err_out: + return err; +} + +static void flow_action_update_hw(struct tc_action *act, + u32 hw_count, + enum flow_act_hw_oper cmd) +{ + if (!act) + return; + + switch (cmd) { + case FLOW_ACT_HW_ADD: + act->in_hw_count = hw_count; + break; + case FLOW_ACT_HW_UPDATE: + act->in_hw_count += hw_count; + break; + case FLOW_ACT_HW_DEL: + act->in_hw_count = act->in_hw_count > hw_count ? + act->in_hw_count - hw_count : 0; + break; + default: + return; + } + + if (act->in_hw_count) { + act->tcfa_flags &= ~TCA_ACT_FLAGS_NOT_IN_HW; + act->tcfa_flags |= TCA_ACT_FLAGS_IN_HW; + } else { + act->tcfa_flags &= ~TCA_ACT_FLAGS_IN_HW; + act->tcfa_flags |= TCA_ACT_FLAGS_NOT_IN_HW; + } +} + +static int tcf_action_offload_cmd(struct flow_offload_action *fl_act, + u32 *hw_count, + struct netlink_ext_ack *extack) +{ + int err; + + if (IS_ERR(fl_act)) + return PTR_ERR(fl_act); + + err = flow_indr_dev_setup_offload(NULL, NULL, TC_SETUP_ACT, fl_act, NULL, NULL); + + if (err < 0) + return err; + + if (hw_count) + *hw_count = err; + + return 0; +} + +/* offload the tc command after inserted */ +static int tcf_action_offload_add(struct tc_action *action, + struct netlink_ext_ack *extack) +{ + bool skip_sw = tc_act_skip_sw(action->tcfa_flags); + struct tc_action *actions[TCA_ACT_MAX_PRIO] = { + [0] = action, + }; + struct flow_offload_action *fl_action; + u32 in_hw_count = 0; + int err = 0; + + if (tc_act_skip_hw(action->tcfa_flags)) + return 0; + + fl_action = flow_action_alloc(tcf_act_num_actions_single(action)); + if (!fl_action) + return -EINVAL; + + err = flow_action_init(fl_action, action, FLOW_ACT_REPLACE, extack); + if (err) + goto fl_err; + + err = tc_setup_action(&fl_action->action, actions); + if (err) { + NL_SET_ERR_MSG_MOD(extack, + "Failed to setup tc actions for offload\n"); + goto fl_err; + } + + err = tcf_action_offload_cmd(fl_action, &in_hw_count, extack); + if (!err) + flow_action_update_hw(action, in_hw_count, FLOW_ACT_HW_ADD); + + if (skip_sw && !tc_act_in_hw(action->tcfa_flags)) + err = -EINVAL; + + tc_cleanup_flow_action(&fl_action->action); + +fl_err: + kfree(fl_action); + + return err; +} + +int tcf_action_offload_del(struct tc_action *action) +{ + struct flow_offload_action fl_act; + u32 in_hw_count = 0; + int err = 0; + + if (!action) + return -EINVAL; + + if (!tc_act_in_hw(action->tcfa_flags)) + return 0; + + err = flow_action_init(&fl_act, action, FLOW_ACT_DESTROY, NULL); + if (err) + return err; + + err = tcf_action_offload_cmd(&fl_act, &in_hw_count, NULL); + if (err) + return err; + + if (action->in_hw_count != in_hw_count) + return -EINVAL; + + return 0; +} + /* Returns numbers of initialized actions or negative error. */ int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla, @@ -1101,6 +1343,11 @@ int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla, sz += tcf_action_fill_size(act); /* Start from index 0 */ actions[i - 1] = act; + if (!(flags & TCA_ACT_FLAGS_BIND)) { + err = tcf_action_offload_add(act, extack); + if (tc_act_skip_sw(act->tcfa_flags) && err) + goto err; + } } /* We have to commit them all together, because if any error happened in diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c index 2ef8f5a6205a..351d93988b8b 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,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); + #ifdef CONFIG_NET_CLS_ACT static int tcf_qevent_parse_block_index(struct nlattr *block_index_attr, u32 *p_block_index, From patchwork Fri Oct 1 11:32:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 12530383 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43893C433F5 for ; Fri, 1 Oct 2021 11:33:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B9D761AAA for ; Fri, 1 Oct 2021 11:33:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353964AbhJALfR (ORCPT ); Fri, 1 Oct 2021 07:35:17 -0400 Received: from mail-bn8nam12on2115.outbound.protection.outlook.com ([40.107.237.115]:36537 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1353956AbhJALfD (ORCPT ); Fri, 1 Oct 2021 07:35:03 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BVeXZIlZKlg5dmSfRkprDgVMcZQCXst3J214uhNWVObFAjzH/SbRp1ATX/7HaRRepYuL18t+yCJrDkUt/pZRyyDyGsu8KLJEf+Y4R4omNhwwgcK4I1RI9lJj17zC7ZAUKYKW/Iq8QyuP3KAxYdeM8unddbHCuMKWyfGBSKCcFjakczkC0l+cAOq+u4l4cV9B2RU24Ye3JfRCRliPYvjQIOTg5Mil/PBLfgbwZ9EDTbTklb2oq7MwWmrTFZ2U8ka0IQmP658+ESW0+Hd4tOnzKajfGD3hd9bmU5M0IKNe2X6PnAVhyzYxXMo4eDDEKtLrfF11vilJm6WqKrbwHO/9Lg== 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=+1hwuk0xBOSEMvCcmZHl1HGWgoMXialxwh8/Pc1WQ8I=; b=Gz1KB1FE3R2m1W0bkiLLrjTilM//LrhePIqPxetYqS+La39nSD9i+svVr272oqf2ml4ju+BMCu4DPBGvLcQ/oZORKKJiqhWl4b3RJeoZalRPqGUKjuS02zxiX0lL/uqp+HEJutQnjhnKIItH72TAJUj20JTedOmxT4p9ndTYRLYXSoLUzul8mDUB/8gbIXyqSYCryov81F+pO+W8ciPPSWIdz3k1KDgByX/E4DFb+qu/aYUZ8MhL68CKLajrJjsYhOcRHZPyeQLUkuVRVupTnwVDb7aW/gp1t2oTKoe29OJYUDwDBzcfcyTK04ciebL7qD4ib1h/zQQBmtJD2Gb0uw== 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=+1hwuk0xBOSEMvCcmZHl1HGWgoMXialxwh8/Pc1WQ8I=; b=COgfQOQMbtFZSiploXNQr1j2ZZVEstQuVoSZphLmGEbSunDLjzTak0Xr/7mx54aJ/L51pfa82TkQp3RGWsG5pI8xQf69Rd3WnDT6eJ4Svc7eT9/RX9uY3iF3GL7GTXHFxWYG0X7rAlL+bsVnfddx0xPImlm5oUlAeYobxJlu4EY= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=corigine.com; Received: from BY3PR13MB4834.namprd13.prod.outlook.com (2603:10b6:a03:36b::10) by BY3PR13MB4804.namprd13.prod.outlook.com (2603:10b6:a03:355::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.7; Fri, 1 Oct 2021 11:33:10 +0000 Received: from BY3PR13MB4834.namprd13.prod.outlook.com ([fe80::4e4:4194:c369:de5e]) by BY3PR13MB4834.namprd13.prod.outlook.com ([fe80::4e4:4194:c369:de5e%8]) with mapi id 15.20.4587.007; Fri, 1 Oct 2021 11:33:10 +0000 From: Simon Horman To: netdev@vger.kernel.org Cc: Jamal Hadi Salim , Roi Dayan , Vlad Buslov , Cong Wang , Jiri Pirko , Baowen Zheng , Louis Peens , oss-drivers@corigine.com, Baowen Zheng , Simon Horman Subject: [RFC/PATCH net-next v2 3/5] flow_offload: add process to update action stats from hardware Date: Fri, 1 Oct 2021 13:32:35 +0200 Message-Id: <20211001113237.14449-4-simon.horman@corigine.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211001113237.14449-1-simon.horman@corigine.com> References: <20211001113237.14449-1-simon.horman@corigine.com> X-ClientProxiedBy: AM8P191CA0023.EURP191.PROD.OUTLOOK.COM (2603:10a6:20b:21a::28) To BY3PR13MB4834.namprd13.prod.outlook.com (2603:10b6:a03:36b::10) MIME-Version: 1.0 Received: from momiji.horms.nl (2001:982:756:703:d63d:7eff:fe99:ac9d) by AM8P191CA0023.EURP191.PROD.OUTLOOK.COM (2603:10a6:20b:21a::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14 via Frontend Transport; Fri, 1 Oct 2021 11:33:08 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5fc926f2-722a-4937-6be3-08d984cf3f6c X-MS-TrafficTypeDiagnostic: BY3PR13MB4804: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:363; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zP1fPtWb+Jr+dabtCUMoOqnTePC5ud5oFFRi7vKo8QwIAT2GAvXyCviA82M+QArjLoRYwaw+ng9f4zOMzvQyVvgNtK+3F1SbxKFZzsA5QOEtRmg7btqCFKnnVnznrtz+erKCJdHKD7kIJcLFRLBsrySD6hr6scbfpB9qc2RxCsqbiqrcogLgGEW5ygWPhh2m0RQQPeixJF12c2DRZ2wJqXIrrsjCGSqGfHealjt09zxUXKO4kpyoyFAWjSDarfe1NqpYEDBw9BIfJY+uQKZlKNDyZ9O2zfTvtrHSQviNR1YANpqqfJ3xeZ9+NbnYNkjDXo9eZRll2+8guZYwIf10Avq2d3qJDI82GbF5lNQ7YD5ItPBCh9N0S+0blYUW7PJ5Zr0mp839yg1wNkThn+1P3rP+mTdK6FoIR9VXfmEgXxd7vIbq4qhJydHC1Um+0kzB81iQSXgpM8hSXFo9TivvOK5UoBWgjL+Whp2bFVBcyyR14f9QRdd3bVes2xX0H1E1IXXWsPXez/dtb0s4C7auE5a9zM2cHRfugEa4UcRLOu+eEbUkOnctIkxGur2XMUbzMQHUNBM9xudjPqLOcj8Tf2LqcHmNPjIablV5RY45bCJD2/rFDYzWrD3Q2LaEnbCLogimMDToH4MNvfLjvderNw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY3PR13MB4834.namprd13.prod.outlook.com;PTR:;CAT:NONE;SFS:(136003)(346002)(396003)(376002)(366004)(39830400003)(2616005)(66946007)(86362001)(36756003)(8676002)(508600001)(8936002)(15650500001)(6486002)(54906003)(1076003)(316002)(66476007)(2906002)(107886003)(66556008)(186003)(52116002)(6666004)(4326008)(6916009)(44832011)(5660300002)(6506007)(6512007)(38100700002)(83380400001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hCL5qXpnGZYegrNrs7pUak01EbEXbLUSOxaW6MWiXe4+6MUQbebvbKqdFi5DOtq8SPa0Qn9mfMNokiwIdpBIfVCo8Z2wrGujeQcCQlDR9SIXQ4VnbV+3qYTtWFayceUO8Du6kf1D4xTU5wc1CZNoqLHb1qUmXywzq1tnAz25qU564pYYmjCRShiWqn6UnI+f94cXlfJHye932GT6vyttlUNtjzhWnPgdgoPY1JAXx6WU2GPu7vKgAIXTpZE2EVii3D4jB3O8optS2dbvHbiMIILl/hI7B3FNHQ78HARoAgU9lok9Joav2hyvPrT8KEpBIxdES4oRizVdgnOAkq82vlEok2wouhP9bcKiNJlYHHSmqKGvHySC3zH5vhp9n4QxHiJO5LGoli4qr3Q7pgwgaQK215CJEN63djx1wEM4yiNnXG5D2xOx7eZtxIdU/YHd6+BiI9KNvsXIudFXOeq2n/oyLS0aSZMPnr9rt1QOlEpwOZbSRNn25MDy9rssm1XfWGiZs2/cdA6SiFSNemmO/vrxrLuYQt493BP1enxHoQErLiAozjfhwtTXGbb5sviYR6of2dMnnk1GzM4vX7JBPMbYADs3oMQbQeivogIJMr8B56AEB8Ws3vpOWXO2pP7cNTL7saSYVl1eEUNT3JhvaJqAK7LQqQOdntL1dCALKvJLpM342ZEZWvDovrws6n4I7RVxlu7aL4dpjroge9484LyqFDqtvkKL0bNiK0+F9XHVHF6ClzNYelWJ+Y7uBlcRw6/rsJfWQVID7FFmj6N4uEhzVGLig2TiHG3RTayP6ejvAXm99nzIx0FrlIqnZMwdp0h5iiOyy2kRycI86Y367XmRTTs8uSuebnINjHA1DebWpXooQABwPzm2NFR+yh/8E+TbGCPYMrEWGZfUO0ZxxIzw3ztPBtoNJMf50gdZhUClHDK3+Y8kmkrLQJTV5Hn+20dYJBbEj47UfoZSrdE0pYwif8WFPapPTfycs047dwOW23T/CTomtXvAO88O3xes48xEYn2r0ix7lxtkD3VOyYNTkeMWUQSob712HgU7It2eOP7pZsbbRsjzdbpIjrzCQYqDooS/AXWFeAlnq4DjPOSVjRZzoWDapplVzWnQPEGb+lLpxVuxZlMqRfBqI9wHdTDdaY6ZTJqV7oqamybmmrwzgAdQzOZVRji0hVrvlgDtEP8ivL7Lrp0J+aNdu3qqkT9TwOKCkusdEjla29he/TlP4bwaE5USDDIJWbC7JbXMUbnm1tXJX+AfMrWhLnFXBE9AnGtsGVidb24WdeCfR1pQnQS+j4KTY+j7zvWqoEHqDuK8IVMpIT18QEqIwryMsX+vvfrmTuOhyy9bx+g0pMebUqPwNVeqWetLBjoOgdVEMuCwJzHwSmhd+cUPj/ov X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5fc926f2-722a-4937-6be3-08d984cf3f6c X-MS-Exchange-CrossTenant-AuthSource: BY3PR13MB4834.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2021 11:33:10.8096 (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: 3hzVTwbjAWibbnkvoxFqrohOlV+H2yyNGU3t/INMR+6tf6akpAj03sr6bai1iVjonHzfCKdKLZl56urs9K75iQ69Nw5L8QFYn1cYtqKwETA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY3PR13MB4804 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Baowen Zheng When collecting stats for actions update them using both both hardware and software counters. Stats update process should not in context of preempt_disable. Signed-off-by: Baowen Zheng Signed-off-by: Louis Peens Signed-off-by: Simon Horman --- include/net/act_api.h | 1 + include/net/pkt_cls.h | 18 ++++++++++-------- net/sched/act_api.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/include/net/act_api.h b/include/net/act_api.h index 656a74002a98..1209444ac369 100644 --- a/include/net/act_api.h +++ b/include/net/act_api.h @@ -241,6 +241,7 @@ 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_offload_del(struct tc_action *action); +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, struct netlink_ext_ack *newchain); diff --git a/include/net/pkt_cls.h b/include/net/pkt_cls.h index 3bb4e6f45038..5c394f04feb5 100644 --- a/include/net/pkt_cls.h +++ b/include/net/pkt_cls.h @@ -294,18 +294,20 @@ tcf_exts_stats_update(const struct tcf_exts *exts, #ifdef CONFIG_NET_CLS_ACT int i; - preempt_disable(); - for (i = 0; i < exts->nr_actions; i++) { struct tc_action *a = exts->actions[i]; - tcf_action_stats_update(a, bytes, packets, drops, - lastuse, true); - a->used_hw_stats = used_hw_stats; - a->used_hw_stats_valid = used_hw_stats_valid; - } + /* if stats from hw, just skip */ + if (tcf_action_update_hw_stats(a)) { + preempt_disable(); + tcf_action_stats_update(a, bytes, packets, drops, + lastuse, true); + preempt_enable(); - preempt_enable(); + a->used_hw_stats = used_hw_stats; + a->used_hw_stats_valid = used_hw_stats_valid; + } + } #endif } diff --git a/net/sched/act_api.c b/net/sched/act_api.c index 3e18f3456afa..c98048832c80 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -1275,6 +1275,40 @@ static int tcf_action_offload_add(struct tc_action *action, return err; } +int tcf_action_update_hw_stats(struct tc_action *action) +{ + struct flow_offload_action fl_act = {}; + int err = 0; + + if (!tc_act_in_hw(action->tcfa_flags)) + return -EOPNOTSUPP; + + err = flow_action_init(&fl_act, action, FLOW_ACT_STATS, NULL); + if (err) + goto err_out; + + err = tcf_action_offload_cmd(&fl_act, NULL, NULL); + + if (!err && fl_act.stats.lastused) { + preempt_disable(); + tcf_action_stats_update(action, fl_act.stats.bytes, + fl_act.stats.pkts, + fl_act.stats.drops, + fl_act.stats.lastused, + true); + preempt_enable(); + action->used_hw_stats = fl_act.stats.used_hw_stats; + action->used_hw_stats_valid = true; + err = 0; + } else { + err = -EOPNOTSUPP; + } + +err_out: + return err; +} +EXPORT_SYMBOL(tcf_action_update_hw_stats); + int tcf_action_offload_del(struct tc_action *action) { struct flow_offload_action fl_act; @@ -1399,6 +1433,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. */ From patchwork Fri Oct 1 11:32: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: 12530379 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26213C433F5 for ; Fri, 1 Oct 2021 11:33:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 00CC861AA9 for ; Fri, 1 Oct 2021 11:33:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353951AbhJALfE (ORCPT ); Fri, 1 Oct 2021 07:35:04 -0400 Received: from mail-bn7nam10on2122.outbound.protection.outlook.com ([40.107.92.122]:44000 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1353961AbhJALfB (ORCPT ); Fri, 1 Oct 2021 07:35:01 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DDXuPMLB/QUbzBLDrPvYSKQ6M5uZvmyyd7aQ0BVS+LWK85O3reqnhuNut6/M1CGbKOwWntAY7hPnlcVtg3w5/OREyWiZbVLM2ICbb6UrI74ZAEgn9uQXKxQYFeAuA6OCPQQRwxB7Iwh6u9L8AA1d9wLGLel6B04EkDoi35JKdbJx8qdpGoCt0Otw9Pna4xzWBk3anL3ShAyuH4UMsd7wA9STcMkH2r9dT0Lt5b0tIHKSIdh/jtfJb6ivNJc9ybkM5RIaLCODvf9QxYTBXAeD66ozKeUGt4HU2mP9MjEUmsAmTWeVuCDvl0Is+AgLlshdatVa0bOx7dj6SwUrjwxlwg== 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=2BCxRFOUNyJp1jBnaudP75DOn+U7vMhQxZdHkdAqoHo=; b=mG8OXJg+8sMMtP8w5JY1FcHskN9RkKSQsfQMELAlXhvaAv5jllTgbcDGmmoUpsKxU8KX7ny6BxH5q7lF8OdKMlTrobkJLBJ6f9NednIPXlJuDYOwANdkZR+p+Unyx5PEdslSbbiHSKdgMAxDrI5tw8xhvL535xog2bjMNbw1veVKLM8I2twVtgBb2tLCEyJ9Hn3j7vYZS1nIAoTosJgNu7PzpxCLlpqAMdDBc4f89v5Ku4OyNT1jl2QIEMfx0qPQRpvcY7os0nsCxobDHC3tl3CcxT3Nyx9OPJlUBazTn8Vf6TE2fR31GJ2r4qrby/5OQzyrbiUTwdctO69vkP1u2Q== 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=2BCxRFOUNyJp1jBnaudP75DOn+U7vMhQxZdHkdAqoHo=; b=HfmsAMKACPWwNXFgTN9xoDTvWmG/s3IXEplJrzGpAMvNVQpXa0Zah25q9808pPVGg70/0GC1caWB+46ngu6FCwgI3wW/b/3GQYE8R5wAymuekNpFx/2r5SRqVyTBp7ChwbcGCacCsBc5RQzOIW7qg9MATa7+1Wohjeqtr2NO7as= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=corigine.com; Received: from BY3PR13MB4834.namprd13.prod.outlook.com (2603:10b6:a03:36b::10) by BY5PR13MB3362.namprd13.prod.outlook.com (2603:10b6:a03:196::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.9; Fri, 1 Oct 2021 11:33:13 +0000 Received: from BY3PR13MB4834.namprd13.prod.outlook.com ([fe80::4e4:4194:c369:de5e]) by BY3PR13MB4834.namprd13.prod.outlook.com ([fe80::4e4:4194:c369:de5e%8]) with mapi id 15.20.4587.007; Fri, 1 Oct 2021 11:33:13 +0000 From: Simon Horman To: netdev@vger.kernel.org Cc: Jamal Hadi Salim , Roi Dayan , Vlad Buslov , Cong Wang , Jiri Pirko , Baowen Zheng , Louis Peens , oss-drivers@corigine.com, Baowen Zheng , Simon Horman Subject: [RFC/PATCH net-next v2 4/5] flow_offload: add reoffload process to update hw_count Date: Fri, 1 Oct 2021 13:32:36 +0200 Message-Id: <20211001113237.14449-5-simon.horman@corigine.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211001113237.14449-1-simon.horman@corigine.com> References: <20211001113237.14449-1-simon.horman@corigine.com> X-ClientProxiedBy: AM8P191CA0023.EURP191.PROD.OUTLOOK.COM (2603:10a6:20b:21a::28) To BY3PR13MB4834.namprd13.prod.outlook.com (2603:10b6:a03:36b::10) MIME-Version: 1.0 Received: from momiji.horms.nl (2001:982:756:703:d63d:7eff:fe99:ac9d) by AM8P191CA0023.EURP191.PROD.OUTLOOK.COM (2603:10a6:20b:21a::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14 via Frontend Transport; Fri, 1 Oct 2021 11:33:11 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 20f8b0fd-88c3-4b08-fb51-08d984cf40e8 X-MS-TrafficTypeDiagnostic: BY5PR13MB3362: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eU43flo8249aUuu9Sy37HI/KY72SXwt/kgol9WJQOGQ6/vpETouF9wk9ii9Nj5DmvwqMgaX2dOcstwpo44Bt6zmJMEXRhTAkfpoTgfWzdkinyD737Wjv3NmI6bnCE6sv7KKzwhcvSgbordrn/qEKHTHnuGE0USzwDwShONXljrmnxNr8HlaErxKp5/J6oisVLzNTg2OWkXo3y6rMEmtgumj96FnydCKagxMv8rFvl264CiXhl0DWl1EvP0p6QnUV6oIhzfaMDO40dONTv9Gww8E4GeSZjsofMBSAPRNSL6SYBnAxKF8H1WdfVXsoCs7y3GpupiptuVmJmjDBL+hKJOTT65IBrDo9ncIeumyYaI6FjLS5lQpeUgJTedWwa6YUWGco2x5Sti+aXZiA1ZEDpFQuufzaFKENVYCQ78q1Sqp/9beWINsrHIMUDKbEGyTiqik2ITnl8k46N1ix/CsxNRLKoljuAFOmBkLks7XAwcp6glVSP/MdZPyLLOk7qK5SWkn+ewnI66TIEciTtmpAD0m9H54mVvBkAL5F5RiQtGe3CDfkzX0CdM7MSD7j7B7Vm+BCcIq3lUCSzVlgdRDU7vEFjs3J+yfUuKHl3OFVpyIt9w7Q8sX0LFcc4zI4zEjD56EozWhvZsnhAZ8FqS9GDw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY3PR13MB4834.namprd13.prod.outlook.com;PTR:;CAT:NONE;SFS:(376002)(39830400003)(136003)(346002)(366004)(396003)(6486002)(66556008)(66946007)(186003)(6666004)(5660300002)(6512007)(86362001)(66476007)(2616005)(30864003)(1076003)(6506007)(8936002)(15650500001)(38100700002)(2906002)(6916009)(83380400001)(44832011)(508600001)(52116002)(8676002)(107886003)(316002)(36756003)(4326008)(54906003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VzycvsNje338b1TCSznPr5HbEQ70+tcoCdHqSvFdoSNFHYvcba9TiB3puePQItm2TeBpUfrYRSSXUwbL8Xb4JMffYU5H4XrdplXQJiQblCV5KdYtZBn/BwDj8wGIXNGLvcoeTaqm/2YARiQlL3I7qyfaayqXpFiP+vcYo+xPmu7av+d8vseirOSl9dF4usbCenaXOV9yOpwKff0L30dUzIre/dec0zjrbozRlDZ53auh9SwzkSwxkBbGWFeh6HFoteml7grYEWwfWX1IxgLTEDoZKWibnchOoOFMcT5ZPvWyQYwp37FwxhoFBz+JzhaxgEqEMSIrdj0bU7nYq2aLAkjWJ7nr62E3qhagTHOMQibDOUEOSUE3mDFFiV1GogiRn885ZNB0pfn85sXNFWu5xKKI7GrnqSsI+qIq6BcxByuFRilqBYLQS/IHGmhXsXWpftaFl56M/nw1S25lL4n7WoVqZdoNp1jqGpW/avlJvjdXH6HMh52jDIs/cB1PtdzvE+T6Zv3yavwU+4v/Cup4v/n6zrnA0W1WwDn+DCRMLXlSQuQu9gbzRh7XS7dcvEF1RV882DiVewmPOc/LiyQUWt550rc1PtIkg/26ZqMn0GPnAspIPvD3ZE8NUU8NQcUjnYKH5Xn3xMuUU7V4+bAdZKJvQe1slWYYxvGXAju8o7vAewt6yuNjsfurSpiIjasMeCW8K3V491tYnV8p4+8IifoBbyQLubo7GTnc3IY+/2z2rKhxCwPYBdfajN48DxSxBjFVIucDT2kiOLz181YktKOXL9ZKHTWBErzLjcTLknASLzFi9PbiInTLQFYuHL0aMMpFKfOi9AZwGLEVOq/TJ1wGxgzUvI0CX4h53zH5vVZNcglQuoo6eDvkSy9TY8UE+PA8vU4E+Wxv7zbpugj39I5zfoh4TiBsAVt2m7uAHlBGffgcq5Cx3TiFH49OtI8+Dk4EEjoXzmife84XOzlQoHaq5+MgnlecxsidnSPsza8/3PfUrTh8cQHi6Ny8mheKDS8KCOOQR1F1gxVYn6omiz9WmiX8QNg03ehCHYrHIyRG//w4T+6Gs4dyFhrg34Lr/3NZ0O1AjhW8dH4f0kgotuElwnnvCLDMX+YBh0BsLwQRxcXpprrlpnfgPqnWzOZWMQlB4Kt2+ZQ/MU9wW+mrgTbp6BGBGIvwz9904Cg4MPL4uPLfx/qLhhFGjkbqKX20AcLzRoOoAoG700MofEV1K9nkpJnFxwcSdCfDkew+y/mM4ACfWvMBnJwG36nw2/MqDvZi+1oLDHvi5IFykb5pDAyCs0q+dxV3qPukZxerxJJ6WF97XtALDjue+31Ub0PAcAq7lliBgGYewanBmgumbSXNQQXUdDy2c/sw5Zxpmyn4aTcmdbSYCHKNfPmKim0c X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: 20f8b0fd-88c3-4b08-fb51-08d984cf40e8 X-MS-Exchange-CrossTenant-AuthSource: BY3PR13MB4834.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2021 11:33:13.3216 (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: ZwRQK+jYPUlTDBkKsCUQ92jNtg7S4f9LW45Aw7F5Ao9ZA2Or+Ndkt7t5fxh8iI8uAMcTJMjjlAnTX1k6P3NNx/jfndN3qEk7koSmE9QZ9zA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR13MB3362 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Baowen Zheng Add reoffload process to update hw_count when driver is inserted or removed. When reoffloading actions, we still offload the actions that are added independent of filters. Change the lock usage to fix sleeping in invalid context. Signed-off-by: Baowen Zheng Signed-off-by: Louis Peens Signed-off-by: Simon Horman --- include/net/act_api.h | 14 +++ net/core/flow_offload.c | 5 + net/sched/act_api.c | 215 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 214 insertions(+), 20 deletions(-) diff --git a/include/net/act_api.h b/include/net/act_api.h index 1209444ac369..df64489d1013 100644 --- a/include/net/act_api.h +++ b/include/net/act_api.h @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -44,6 +45,9 @@ struct tc_action { u8 hw_stats; u8 used_hw_stats; bool used_hw_stats_valid; + bool add_separate; /* indicate if the action is created + * independent of any flow + */ u32 in_hw_count; }; #define tcf_index common.tcfa_index @@ -242,6 +246,8 @@ void tcf_action_update_stats(struct tc_action *a, u64 bytes, u64 packets, int tcf_action_copy_stats(struct sk_buff *, struct tc_action *, int); int tcf_action_offload_del(struct tc_action *action); int tcf_action_update_hw_stats(struct tc_action *action); +int tcf_action_reoffload_cb(flow_indr_block_bind_cb_t *cb, + void *cb_priv, bool add); int tcf_action_check_ctrlact(int action, struct tcf_proto *tp, struct tcf_chain **handle, struct netlink_ext_ack *newchain); @@ -253,6 +259,14 @@ DECLARE_STATIC_KEY_FALSE(tcf_frag_xmit_count); #endif int tcf_dev_queue_xmit(struct sk_buff *skb, int (*xmit)(struct sk_buff *skb)); + +#else /* !CONFIG_NET_CLS_ACT */ + +static inline int tcf_action_reoffload_cb(flow_indr_block_bind_cb_t *cb, + void *cb_priv, bool add) { + return 0; +} + #endif /* CONFIG_NET_CLS_ACT */ static inline void tcf_action_stats_update(struct tc_action *a, u64 bytes, diff --git a/net/core/flow_offload.c b/net/core/flow_offload.c index 6676431733ef..d591204af6e0 100644 --- a/net/core/flow_offload.c +++ b/net/core/flow_offload.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0 */ #include #include +#include #include #include #include @@ -418,6 +419,8 @@ int flow_indr_dev_register(flow_indr_block_bind_cb_t *cb, void *cb_priv) existing_qdiscs_register(cb, cb_priv); mutex_unlock(&flow_indr_block_lock); + tcf_action_reoffload_cb(cb, cb_priv, true); + return 0; } EXPORT_SYMBOL(flow_indr_dev_register); @@ -472,6 +475,8 @@ void flow_indr_dev_unregister(flow_indr_block_bind_cb_t *cb, void *cb_priv, flow_block_indr_notify(&cleanup_list); kfree(indr_dev); + + tcf_action_reoffload_cb(cb, cb_priv, false); } EXPORT_SYMBOL(flow_indr_dev_unregister); diff --git a/net/sched/act_api.c b/net/sched/act_api.c index c98048832c80..7bb84d5001b6 100644 --- a/net/sched/act_api.c +++ b/net/sched/act_api.c @@ -512,6 +512,7 @@ int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est, p->tcfa_tm.lastuse = jiffies; p->tcfa_tm.firstuse = 0; p->tcfa_flags = flags & TCA_ACT_FLAGS_USER_MASK; + p->add_separate = !bind; if (est) { err = gen_new_estimator(&p->tcfa_bstats, p->cpu_bstats, &p->tcfa_rate_est, @@ -636,6 +637,59 @@ EXPORT_SYMBOL(tcf_idrinfo_destroy); static LIST_HEAD(act_base); static DEFINE_RWLOCK(act_mod_lock); +/* since act ops id is stored in pernet subsystem list, + * then there is no way to walk through only all the action + * subsystem, so we keep tc action pernet ops id for + * reoffload to walk through. + */ +static LIST_HEAD(act_pernet_id_list); +static DEFINE_MUTEX(act_id_mutex); +struct tc_act_pernet_id { + struct list_head list; + unsigned int id; +}; + +static int tcf_pernet_add_id_list(unsigned int id) +{ + struct tc_act_pernet_id *id_ptr; + int ret = 0; + + mutex_lock(&act_id_mutex); + list_for_each_entry(id_ptr, &act_pernet_id_list, list) { + if (id_ptr->id == id) { + ret = -EEXIST; + goto err_out; + } + } + + id_ptr = kzalloc(sizeof(*id_ptr), GFP_KERNEL); + if (!id_ptr) { + ret = -ENOMEM; + goto err_out; + } + id_ptr->id = id; + + list_add_tail(&id_ptr->list, &act_pernet_id_list); + +err_out: + mutex_unlock(&act_id_mutex); + return ret; +} + +static void tcf_pernet_del_id_list(unsigned int id) +{ + struct tc_act_pernet_id *id_ptr; + + mutex_lock(&act_id_mutex); + list_for_each_entry(id_ptr, &act_pernet_id_list, list) { + if (id_ptr->id == id) { + list_del(&id_ptr->list); + kfree(id_ptr); + break; + } + } + mutex_unlock(&act_id_mutex); +} int tcf_register_action(struct tc_action_ops *act, struct pernet_operations *ops) @@ -654,18 +708,30 @@ int tcf_register_action(struct tc_action_ops *act, if (ret) return ret; + if (ops->id) { + ret = tcf_pernet_add_id_list(*ops->id); + if (ret) + goto id_err; + } + write_lock(&act_mod_lock); list_for_each_entry(a, &act_base, head) { if (act->id == a->id || (strcmp(act->kind, a->kind) == 0)) { - write_unlock(&act_mod_lock); - unregister_pernet_subsys(ops); - return -EEXIST; + ret = -EEXIST; + goto err_out; } } list_add_tail(&act->head, &act_base); write_unlock(&act_mod_lock); return 0; + +err_out: + write_unlock(&act_mod_lock); + tcf_pernet_del_id_list(*ops->id); +id_err: + unregister_pernet_subsys(ops); + return ret; } EXPORT_SYMBOL(tcf_register_action); @@ -684,8 +750,11 @@ int tcf_unregister_action(struct tc_action_ops *act, } } write_unlock(&act_mod_lock); - if (!err) + if (!err) { unregister_pernet_subsys(ops); + if (ops->id) + tcf_pernet_del_id_list(*ops->id); + } return err; } EXPORT_SYMBOL(tcf_unregister_action); @@ -1210,29 +1279,57 @@ static void flow_action_update_hw(struct tc_action *act, } } -static int tcf_action_offload_cmd(struct flow_offload_action *fl_act, - u32 *hw_count, - struct netlink_ext_ack *extack) +static int tcf_action_offload_cmd_ex(struct flow_offload_action *fl_act, + u32 *hw_count) { int err; - if (IS_ERR(fl_act)) - return PTR_ERR(fl_act); + err = flow_indr_dev_setup_offload(NULL, NULL, TC_SETUP_ACT, + fl_act, NULL, NULL); + if (err < 0) + return err; + + if (hw_count) + *hw_count = err; - err = flow_indr_dev_setup_offload(NULL, NULL, TC_SETUP_ACT, fl_act, NULL, NULL); + return 0; +} + +static int tcf_action_offload_cmd_cb_ex(struct flow_offload_action *fl_act, + u32 *hw_count, + flow_indr_block_bind_cb_t *cb, + void *cb_priv) +{ + int err; + err = cb(NULL, NULL, cb_priv, TC_SETUP_ACT, NULL, fl_act, NULL); if (err < 0) return err; if (hw_count) - *hw_count = err; + *hw_count = 1; return 0; } +static int tcf_action_offload_cmd(struct flow_offload_action *fl_act, + u32 *hw_count, + flow_indr_block_bind_cb_t *cb, + void *cb_priv) +{ + if (IS_ERR(fl_act)) + return PTR_ERR(fl_act); + + return cb ? tcf_action_offload_cmd_cb_ex(fl_act, hw_count, + cb, cb_priv) : + tcf_action_offload_cmd_ex(fl_act, hw_count); +} + /* offload the tc command after inserted */ -static int tcf_action_offload_add(struct tc_action *action, - struct netlink_ext_ack *extack) +static int tcf_action_offload_add_ex(struct tc_action *action, + struct netlink_ext_ack *extack, + flow_indr_block_bind_cb_t *cb, + void *cb_priv) { bool skip_sw = tc_act_skip_sw(action->tcfa_flags); struct tc_action *actions[TCA_ACT_MAX_PRIO] = { @@ -1260,9 +1357,10 @@ static int tcf_action_offload_add(struct tc_action *action, goto fl_err; } - err = tcf_action_offload_cmd(fl_action, &in_hw_count, extack); + err = tcf_action_offload_cmd(fl_action, &in_hw_count, cb, cb_priv); if (!err) - flow_action_update_hw(action, in_hw_count, FLOW_ACT_HW_ADD); + flow_action_update_hw(action, in_hw_count, + cb ? FLOW_ACT_HW_UPDATE : FLOW_ACT_HW_ADD); if (skip_sw && !tc_act_in_hw(action->tcfa_flags)) err = -EINVAL; @@ -1275,6 +1373,12 @@ static int tcf_action_offload_add(struct tc_action *action, return err; } +static int tcf_action_offload_add(struct tc_action *action, + struct netlink_ext_ack *extack) +{ + return tcf_action_offload_add_ex(action, extack, NULL, NULL); +} + int tcf_action_update_hw_stats(struct tc_action *action) { struct flow_offload_action fl_act = {}; @@ -1287,7 +1391,7 @@ int tcf_action_update_hw_stats(struct tc_action *action) if (err) goto err_out; - err = tcf_action_offload_cmd(&fl_act, NULL, NULL); + err = tcf_action_offload_cmd(&fl_act, NULL, NULL, NULL); if (!err && fl_act.stats.lastused) { preempt_disable(); @@ -1309,7 +1413,8 @@ int tcf_action_update_hw_stats(struct tc_action *action) } EXPORT_SYMBOL(tcf_action_update_hw_stats); -int tcf_action_offload_del(struct tc_action *action) +int tcf_action_offload_del_ex(struct tc_action *action, + flow_indr_block_bind_cb_t *cb, void *cb_priv) { struct flow_offload_action fl_act; u32 in_hw_count = 0; @@ -1325,13 +1430,83 @@ int tcf_action_offload_del(struct tc_action *action) if (err) return err; - err = tcf_action_offload_cmd(&fl_act, &in_hw_count, NULL); - if (err) + err = tcf_action_offload_cmd(&fl_act, &in_hw_count, cb, cb_priv); + if (err < 0) return err; - if (action->in_hw_count != in_hw_count) + /* do not need to update hw state when deleting action */ + if (cb && in_hw_count) + flow_action_update_hw(action, in_hw_count, FLOW_ACT_HW_DEL); + + if (!cb && action->in_hw_count != in_hw_count) + return -EINVAL; + + return 0; +} + +int tcf_action_offload_del(struct tc_action *action) +{ + return tcf_action_offload_del_ex(action, NULL, NULL); +} + +int tcf_action_reoffload_cb(flow_indr_block_bind_cb_t *cb, + void *cb_priv, bool add) +{ + struct tc_act_pernet_id *id_ptr; + struct tcf_idrinfo *idrinfo; + struct tc_action_net *tn; + struct tc_action *p; + unsigned int act_id; + unsigned long tmp; + unsigned long id; + struct idr *idr; + struct net *net; + int ret; + + if (!cb) return -EINVAL; + down_read(&net_rwsem); + mutex_lock(&act_id_mutex); + + for_each_net(net) { + list_for_each_entry(id_ptr, &act_pernet_id_list, list) { + act_id = id_ptr->id; + tn = net_generic(net, act_id); + if (!tn) + continue; + idrinfo = tn->idrinfo; + if (!idrinfo) + continue; + + mutex_lock(&idrinfo->lock); + idr = &idrinfo->action_idr; + idr_for_each_entry_ul(idr, p, tmp, id) { + if (IS_ERR(p) || !p->add_separate) + continue; + if (add) { + tcf_action_offload_add_ex(p, NULL, cb, + cb_priv); + continue; + } + + /* cb unregister to update hw count */ + ret = tcf_action_offload_del_ex(p, cb, cb_priv); + if (ret < 0) + continue; + if (tc_act_skip_sw(p->tcfa_flags) && + !tc_act_in_hw(p->tcfa_flags)) { + ret = tcf_idr_release_unsafe(p); + if (ret == ACT_P_DELETED) + module_put(p->ops->owner); + } + } + mutex_unlock(&idrinfo->lock); + } + } + mutex_unlock(&act_id_mutex); + up_read(&net_rwsem); + return 0; } From patchwork Fri Oct 1 11:32: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: 12530381 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D673AC433F5 for ; Fri, 1 Oct 2021 11:33:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BC86261AAA for ; Fri, 1 Oct 2021 11:33:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353932AbhJALfP (ORCPT ); Fri, 1 Oct 2021 07:35:15 -0400 Received: from mail-bn7nam10on2122.outbound.protection.outlook.com ([40.107.92.122]:44000 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1353957AbhJALfD (ORCPT ); Fri, 1 Oct 2021 07:35:03 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SzRp77aGbnoFubhc6c8KXWeIFI8nwL+9VIUQ4kuN09O61kFgPQQhLaDf32VqtSqe81wKQO/qQ19kZEiFTeTZ+NhgVzJgMSf90bzfiEzSHL2o0KrLZz6kR1f2hIeFROQlJPurVSulhu7euaf/Ps9ZPioOwUsFOe2ht4xV9U7CoEM/2FqFS9Ug5qzydll61NTHBwsvD4w3VzQlzbf/VRO+ICq7zfasZAkIdxVHI+ZdV3IbGDtDxYEYMXcUD+cEglPaqGm5aH4qIyW0DYTFw8p/33Wu7gDvCluNgACD4vzUir4docSgB0XrU7TXxFH73JLiZboaIlpqDtOSBb7IBxA4EQ== 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=cXSyUiBXXj7j/IKwckBW+AJUq9cE0595u95xgbEf5n0=; b=IYNaN4SYWCsgUZ8GvvT44o1eXITCjJ2CfnHjDTT4Ljsn/roFnFJphNC6nAFlzNjz8jf/uEZIBeqpzPbr029f5bKyvXpHmRAkxJ47T/cksmbB+paUvrqw1HUpuEg0br5GGdSvzvkckBo7Agspa959Ycv9wxJ6u1O9IAakC4iqi6zIbr6DqILg5okQrfDKJHPGzUeHD94mVqTjrmK/ASXGrC2V0UgEsuvM/DE0qYci0ZSJD5OeZAEoFHsoyXX7JbjXTdu9czXuNvXoP7zxqXRDZS6Fc7aNL/gmlgLS9WqCcSTpDsgYcbV7Lq8+TChTGjIOq1RPEq0FlEXwl/T7S1orMg== 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=cXSyUiBXXj7j/IKwckBW+AJUq9cE0595u95xgbEf5n0=; b=LXZqIt8Qb7CCoCPsLnlp8QNygEOomtQDTMkPeErH+ktLyM+W+JlVdxsfD/axotBJSCqmrkbC8IBFC7nCc/BP7Ywz/fmh9xzX5CYKeGILQvVE+dPOHK5Hs4aGqEHM6SAhTvFMJpzFGUl6L5nS65amY8kV3fverCMy7ngUGkbuE6Y= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=corigine.com; Received: from BY3PR13MB4834.namprd13.prod.outlook.com (2603:10b6:a03:36b::10) by BY5PR13MB3362.namprd13.prod.outlook.com (2603:10b6:a03:196::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4587.9; Fri, 1 Oct 2021 11:33:16 +0000 Received: from BY3PR13MB4834.namprd13.prod.outlook.com ([fe80::4e4:4194:c369:de5e]) by BY3PR13MB4834.namprd13.prod.outlook.com ([fe80::4e4:4194:c369:de5e%8]) with mapi id 15.20.4587.007; Fri, 1 Oct 2021 11:33:16 +0000 From: Simon Horman To: netdev@vger.kernel.org Cc: Jamal Hadi Salim , Roi Dayan , Vlad Buslov , Cong Wang , Jiri Pirko , Baowen Zheng , Louis Peens , oss-drivers@corigine.com, Baowen Zheng , Simon Horman Subject: [RFC/PATCH net-next v2 5/5] flow_offload: validate flags of filter and actions Date: Fri, 1 Oct 2021 13:32:37 +0200 Message-Id: <20211001113237.14449-6-simon.horman@corigine.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211001113237.14449-1-simon.horman@corigine.com> References: <20211001113237.14449-1-simon.horman@corigine.com> X-ClientProxiedBy: AM8P191CA0023.EURP191.PROD.OUTLOOK.COM (2603:10a6:20b:21a::28) To BY3PR13MB4834.namprd13.prod.outlook.com (2603:10b6:a03:36b::10) MIME-Version: 1.0 Received: from momiji.horms.nl (2001:982:756:703:d63d:7eff:fe99:ac9d) by AM8P191CA0023.EURP191.PROD.OUTLOOK.COM (2603:10a6:20b:21a::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.14 via Frontend Transport; Fri, 1 Oct 2021 11:33:13 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d2244adb-3418-46cf-3854-08d984cf4297 X-MS-TrafficTypeDiagnostic: BY5PR13MB3362: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:67; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zJ7LMQDvYK699ndXWAw0fwbQmxK3kZZt+I2LmPQGpbS6Ymz3RB+yDFzW26vqK4JVHuIalWo6gq1XrgmG+CtvXlghfhodPihLNB0cK8kDbL9jYnZ551xMC+qxf8jiPeo7VCyE9CFzL1/lZ0bXrW3sRrK4CjBoUobGPInR7zzgW8v8olR/NeZI2X0aZA6UWXkoBLKucLUKnoenEz9Vaq8BwTpja0aVrS7UhWbEPjwQpJucVL98PoGlIeNnIP06VBIO+QXpYNaWBAa6jr0baQoFutekKZlTxp/sZgoQfD2dFku3SLtvTygVTuIMoNeb/6YBCIpjVMPXJCNgTJxqIyQXUfTBiUpWcyjV19VCb23VCwo7WzpfL0ehbGnPF+Lz2c9wxXsuCu5iHkHPsxrbaeJ3cou9mylUAP4I2Aw/yzjIQYka/0iPTmvZw9UWs5fQRKJWVFGOtg1RUnR5N5f08fUY8qHwlOT+UW6gF3KHTrEy2bese0vU+VOdsMq47KZTtFCZSJWiUV7zsYDpBwE5fUfm3qAkGkMGNjOlkONe+JaqJEwVOlFSoSxVRhnZ7K2Pd9PEfWqmUt0mmO+0yYcKLpgqYeNX5V4DW8tssdRFwgNfSwPvSvaV0g+E9NZdNIrzGtpergrGCyMlElDtKXWqANhDGA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY3PR13MB4834.namprd13.prod.outlook.com;PTR:;CAT:NONE;SFS:(376002)(39830400003)(136003)(346002)(366004)(396003)(6486002)(66556008)(66946007)(186003)(6666004)(5660300002)(6512007)(86362001)(66476007)(2616005)(1076003)(6506007)(8936002)(15650500001)(38100700002)(2906002)(6916009)(83380400001)(44832011)(508600001)(52116002)(8676002)(107886003)(316002)(36756003)(4326008)(54906003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FrBLOu/jZQzGipPVPTGr991VdUp8Ge1Y9ICXQX1CiB2p/YBsjIcP/9aGGr/SfbxxIN5OUBP19jU6HIgRoPWcXfqBLEPnukSkinOOHWhrUYdJik/dGLmJH7qrMm2aDFcUQoFBLPLdzV7Hz6HOYZh1l1kXHSYgxPm1ENpCYbIWXYvTdOg5ckiTlCFKbO3dQCmw+08Lgt5wqX4bdkq8LPeXQ8w7KcKzG1yRpojmoqstozsSQIqoGSjflz8K34gY2T04KdETr5oWtD5Y9lhBNWf+lnaVqMb+g5/Fbo2p4CBvGrswjI/nFP8F2/PN87G3bMnlOT25D+Sf3F6R698qie0H4v7p8teh9Lrtmt1Y14Wakt6caq6q7td8N4MOpvxlIEknrh6YEtuLSa/5uHGkMU2MDduNognnteTIZRMLBO92RA5wdgscSKbm3T9MORofN7y2ArJYay2T3ZYj3QNzI3XHgDfn2s1BwvUT61iCwQoKdNvTxFTNutqmhroGw9SUs8gE/tbphOZ2u0pPze5diyGYSBWquT73Xr14eiZUk872C5xSkiG0ErGdi1dLPuEBeIFjwLGtVDaN72k20Au78k9NSyPN+E4kS5UsEV5/LQcmqtrQXD4WzzgDfOkwLAdFEsy6nTwJavkWr9kF7UrrJrzG33HQkQcQyr5jx4MrLLJr+FT0bAbS6pHnFB89YcdOyMOrIQLXazM6tfKylfKKCyrXis4pO0QPdpZ08Jw7h7p5SLxsMf+gQvghgwLwKCKAFDZE8s19L5RFwO9060d4sX0V8kYTOAo9EeLPEEw7kL9OyH1aidU2An9sMXDAKS5h5zwgVGosPZa4EEr/S+TDET1ZdL5g2TAJxn1io627RdH1MLf3JR6y959hU3Ak/zRJhH9E8Or+Adaj7p1kwOu+tJjKyGAv+kVRRA3w1mtxafiTlqQr9djXY6Pj/+2UBryD/skYYMUnAL597bJAUwCb3R7TmwWx/fdQqlzyd/qM3vYAQ5E68xkQiVUJwz+1mOUnBeau0RD72ZRxWAZR2G/FwX1SYGzHIjPCcR2l2N1OTN23wnGRfXnQhQxSE8TtBFSIOoON3Du4O8ejxGmJMJUranL/a1QSxS0niuRWFZAvUKGGZgD8rGdSVgx9G6l30I9RJluGpFMdnY75cK7Tt1IXrv7vF1e9L4piuneJau8u/6Y0tHz5kdFG72wVHGrIqDWFnuk9u4c50ZlakyIFyMpQEQgmXLZeUseg8Vbqc3Ynu5Pvl77U7C01PRWcjUX3fy2oJWF/z0IU4RYo4VKjO0V6wZcy7KO8JSR1Xn1VyC0Uh8H02Am2iEbZoCGFdIUTDo2SxSrH9XKTqkbBGocF4P/goB3h3v304jN6KaE9s8/bjWE6oo8f1h+Fj7tUpjcLBzpHpiv8 X-OriginatorOrg: corigine.com X-MS-Exchange-CrossTenant-Network-Message-Id: d2244adb-3418-46cf-3854-08d984cf4297 X-MS-Exchange-CrossTenant-AuthSource: BY3PR13MB4834.namprd13.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2021 11:33:16.2995 (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: LANwzjAtcwTak4+a05fo1jUsJ6o+CUpvR/Uqcho0bzIsYJUf3ia5vnpVwgBqd0kD1aQ3R4kfWaPQk4WbM9+zQgcgFRwuMY+SDB0lvDO8mRM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR13MB3362 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Baowen Zheng Add process to validate flags of filter and actions when adding a tc filter. We need to prevent adding filter with flags conflicts with its actions. Signed-off-by: Baowen Zheng Signed-off-by: Louis Peens Signed-off-by: Simon Horman --- include/net/pkt_cls.h | 32 ++++++++++++++++++++++++++++++++ net/sched/cls_flower.c | 5 +++++ net/sched/cls_matchall.c | 6 ++++++ net/sched/cls_u32.c | 11 +++++++++++ 4 files changed, 54 insertions(+) diff --git a/include/net/pkt_cls.h b/include/net/pkt_cls.h index 5c394f04feb5..2d51bed434d2 100644 --- a/include/net/pkt_cls.h +++ b/include/net/pkt_cls.h @@ -735,6 +735,38 @@ static inline bool tc_in_hw(u32 flags) return (flags & TCA_CLS_FLAGS_IN_HW) ? true : false; } +/** + * tcf_exts_validate_actions - check if exts actions flags are compatible with + * tc filter flags + * @exts: tc filter extensions handle + * @flags: tc filter flags + * + * Returns true if exts actions flags are compatible with tc filter flags + */ +static inline bool +tcf_exts_validate_actions(const struct tcf_exts *exts, u32 flags) +{ +#ifdef CONFIG_NET_CLS_ACT + bool skip_sw = tc_skip_sw(flags); + bool skip_hw = tc_skip_hw(flags); + int i; + + if (!(skip_sw | skip_hw)) + return true; + + for (i = 0; i < exts->nr_actions; i++) { + struct tc_action *a = exts->actions[i]; + + if ((skip_sw && tc_act_skip_hw(a->tcfa_flags)) || + (skip_hw && tc_act_skip_sw(a->tcfa_flags))) + return false; + } + return true; +#else + return true; +#endif +} + static inline void tc_cls_common_offload_init(struct flow_cls_common_offload *cls_common, const struct tcf_proto *tp, u32 flags, diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c index eb6345a027e1..15e439349124 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -2039,6 +2039,11 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, if (err) goto errout; + if (!tcf_exts_validate_actions(&fnew->exts, fnew->flags)) { + err = -EINVAL; + goto errout; + } + err = fl_check_assign_mask(head, fnew, fold, mask); if (err) goto errout; diff --git a/net/sched/cls_matchall.c b/net/sched/cls_matchall.c index 24f0046ce0b3..89dbbb9f31e8 100644 --- a/net/sched/cls_matchall.c +++ b/net/sched/cls_matchall.c @@ -231,6 +231,11 @@ static int mall_change(struct net *net, struct sk_buff *in_skb, if (err) goto err_set_parms; + if (!tcf_exts_validate_actions(&new->exts, new->flags)) { + err = -EINVAL; + goto err_validate; + } + if (!tc_skip_hw(new->flags)) { err = mall_replace_hw_filter(tp, new, (unsigned long)new, extack); @@ -246,6 +251,7 @@ static int mall_change(struct net *net, struct sk_buff *in_skb, return 0; err_replace_hw_filter: +err_validate: err_set_parms: free_percpu(new->pf); err_alloc_percpu: diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index 4272814487f0..8bc19af18e4a 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -902,6 +902,11 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, return err; } + if (!tcf_exts_validate_actions(&new->exts, flags)) { + u32_destroy_key(new, false); + return -EINVAL; + } + err = u32_replace_hw_knode(tp, new, flags, extack); if (err) { u32_destroy_key(new, false); @@ -1066,6 +1071,11 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, struct tc_u_knode __rcu **ins; struct tc_u_knode *pins; + if (!tcf_exts_validate_actions(&n->exts, n->flags)) { + err = -EINVAL; + goto err_validate; + } + err = u32_replace_hw_knode(tp, n, flags, extack); if (err) goto errhw; @@ -1086,6 +1096,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, return 0; } +err_validate: errhw: #ifdef CONFIG_CLS_U32_MARK free_percpu(n->pcpu_success);