From patchwork Mon Apr 3 10:34:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13197995 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84DE9C77B60 for ; Mon, 3 Apr 2023 10:35:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232206AbjDCKfK (ORCPT ); Mon, 3 Apr 2023 06:35:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231448AbjDCKfD (ORCPT ); Mon, 3 Apr 2023 06:35:03 -0400 Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2064.outbound.protection.outlook.com [40.107.105.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1963F2D51; Mon, 3 Apr 2023 03:35:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d1dCZOu9J1FOVcwu4gcigmtVNTc3+mefEZayuSTsUCJFZuGOBhWGNyQpNOV967CeSjw7HNJkOdIdxTa1AYll1yY5Ft9NC5ZqZBZZOpAX6baau3g9xMClbn3auSfmNZwrcf+SMkRAxH0mCZfmmin1wASMRZ0dTdY+ivdCpKk+zLwyl6C8LZIjW62DGVvmx468jki7M04eF6DozxRiooQDzE4BmlWrZvTv+/TwRPRClpvahRDWTZPURZyf9Uos0Ovhwd5ig5LQJlxEENIzApbx7ysMYnz7ePWahAC5iVLfR3u0s1kaasMyVleeMKfJ2VufncYw2j1+OwFsuL8C/4Q0cQ== 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=dHR+Em53mXNFOhp8OKYBi4y9+SSYpR64IKXLzh5xz/s=; b=nfS/+31GrpZlL09WXFrQ4pRuCgQ9Z+D+WjorO9yqCM/RRdGi70Qskea0obKDq/t2Nq8fg3ZGEMmBmtIkEku6Ifl1sFAq6ZIwV2fjTdtPBYAuMU4ZALFEiZ5qwfPSjH5i4QHx3E7xtKYSiYSOsgbAbQhVoQElt/V6fOlrLkqKZ83SIzlgWQGW4NbnV+PZEflMQBWy+M0kn0ztQ6/h1kIhZfQ6sxXuYczs3592N+qMetuXTLbJ7oY9JRNB5RGTUpP5OmGyXAjVMrTqJCXU3+f0jXbgRElJt3y3jvRiibn0nBkWjavQQFbLjN7HJDMLlAL/Qpof/m64AHIw/VfXvOOWJg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dHR+Em53mXNFOhp8OKYBi4y9+SSYpR64IKXLzh5xz/s=; b=Mcs70Uyp+HY8Fg0SZxLNAGBvoCbmQgDhOI1NdhPHmT3tY4UJv1RDbExD2oNpUK3GtCpnR3CR/oOkRXWcO6gQ3xHNmAsKDSJ1BFhVHP0P6LtVztYU6vVlmdvIG/+DotGyr6rFoScShf/6E6WTvP1QLgKB06GiZXxG5zMpJ/7mJbc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) by AS4PR04MB9292.eurprd04.prod.outlook.com (2603:10a6:20b:4e7::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.29; Mon, 3 Apr 2023 10:35:00 +0000 Received: from AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::dfa2:5d65:fad:a2a5]) by AM0PR04MB6452.eurprd04.prod.outlook.com ([fe80::dfa2:5d65:fad:a2a5%3]) with mapi id 15.20.6254.026; Mon, 3 Apr 2023 10:35:00 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jamal Hadi Salim , Cong Wang , Jiri Pirko , Vinicius Costa Gomes , Kurt Kanzenbach , Gerhard Engleder , Amritha Nambiar , Ferenc Fejes , Xiaoliang Yang , Roger Quadros , Pranavi Somisetty , Harini Katakam , Giuseppe Cavallaro , Alexandre Torgue , Michael Sit Wei Hong , Mohammad Athari Bin Ismail , Oleksij Rempel , Jacob Keller , linux-kernel@vger.kernel.org, Ferenc Fejes , Simon Horman Subject: [PATCH v4 net-next 2/9] net/sched: mqprio: simplify handling of nlattr portion of TCA_OPTIONS Date: Mon, 3 Apr 2023 13:34:33 +0300 Message-Id: <20230403103440.2895683-3-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230403103440.2895683-1-vladimir.oltean@nxp.com> References: <20230403103440.2895683-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: FR0P281CA0221.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:ac::17) To AM0PR04MB6452.eurprd04.prod.outlook.com (2603:10a6:208:16d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM0PR04MB6452:EE_|AS4PR04MB9292:EE_ X-MS-Office365-Filtering-Correlation-Id: 62ac9251-de2d-402e-d08a-08db342f1378 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: m6QxJh1n3B3CpQGNEyUCFtvSsRBs5ID1IsOg1n8t354F375VAgUvN4/KlpS1NofcgHGLMprQfOp4Gqa4M24Db+bCrOs5YNi8ms5lIsGzd2Yjy6jrC5CE3xdCVqT2j227D0OHCFe/6vJKAyFM1ELvMrsn2tIe0Y/N8ngO/uO3VjCZKAl4IDP42g6t+TONq94mwvh52JDGoDIFdW11vDJY2VJZYbkRatD842yT5M7RNelu29EBtt9Oexz7TYRoNZ7Je2C8RP3tYEq+1cNMHkUkiijJxa1P3gxj6rczJs871BstLWFLOwXh58oqNulEPZbrWE3qzAK56mQ4J4rx71sncLJjQhR5yDE6mm44rbghCrjIWZxZw8EXP9T20ggHky3nI+R/5DwMkHPsdehenxRdO021egvoZGlbMVEN1iOOX92dMFqfyJi1ipcwZdhyCLMtQQWq1ESyg723pj6ShyyIauYpCbJ2BEaVeNyoftSyeOz6isrXeBPgw0Ww92nMj5s2qPjP0vaiJbkLMUJreWa7kKJgGDmpVZ4jsYPuXuYKZd/umDfc2iU/9d5lNiCOlFa0lIcXto69Ce+qfmTzP7VGFSCcMcKdBSYfFAWLwOlq/wWN/9WchD5KkfncnnlHLLcB X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AM0PR04MB6452.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(136003)(39860400002)(376002)(346002)(366004)(396003)(451199021)(26005)(1076003)(6506007)(186003)(38350700002)(38100700002)(6512007)(86362001)(316002)(54906003)(41300700001)(7416002)(5660300002)(44832011)(66556008)(66476007)(4326008)(66946007)(8676002)(6916009)(478600001)(52116002)(8936002)(6666004)(6486002)(36756003)(2616005)(2906002)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: X/a8CJ2aIY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9g8lXSLEoVjMikqvMvngZK5ilRuZ5vK0+2Kje5Av+MJUT9qvnvZwsfWsdL7TCBMkOaEzQkzDkUll7kyV3OWwFQyUsdzCNwJd+WVJNltGc36Wd9Ioy6OHqw7jpGOrH5SuZygmmpxflMCDn5MIZVcdep5NRjcfnQRhRIglaYK0csrq8EjCHtb/pvNGQuAiBxPauF7DTqxY5u5EgDnftTDVpO0N2DzURXq37hvDtFnJdJT58+FB77M+eVzNbjwgVAD8cuMEJdbQnZggLo6m9f9oMCqTe9gNQTAF/MPpKfNbMlcqvZ2jruaBotKkFWirUHtFbfmr6qNp3m/1lCy0XuiPclqhk5c8z6/qF7SFtIJKaF1JoLg6c5XtBf+cL9DYQPLE2vdOp7KGPq+kKyn7Tmjz0Svo5eldwvimFfHYFQ8GpQbdGWvZhQDDu0ie+01xmbZpOvaymMVqDvqRnZ4ocX0LWSuTgEFC10TTBWbqJifjSgRh8ATwS0f//MYIZDLSZm7vqelY7kix96+KI+N85zXw2+aGfJ6VR/iBjGr0A== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 62ac9251-de2d-402e-d08a-08db342f1378 X-MS-Exchange-CrossTenant-AuthSource: AM0PR04MB6452.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Apr 2023 10:35:00.0723 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: BKO+++QoEc2rnRXLpWL+F645q/2o5ESE5cjMe0cKqt8lEOR+jJN5a91f6IYci78GBfT7pigpc3FcdSwct0dD0A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS4PR04MB9292 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org In commit 4e8b86c06269 ("mqprio: Introduce new hardware offload mode and shaper in mqprio"), the TCA_OPTIONS format of mqprio was extended to contain a fixed portion (of size NLA_ALIGN(sizeof struct tc_mqprio_qopt)) and a variable portion of other nlattrs (in the TCA_MQPRIO_* type space) following immediately afterwards. In commit feb2cf3dcfb9 ("net/sched: mqprio: refactor nlattr parsing to a separate function"), we've moved the nlattr handling to a smaller function, but yet, a small parse_attr() still remains, and the larger mqprio_parse_nlattr() still does not have access to the beginning, and the length, of the TCA_OPTIONS region containing these other nlattrs. In a future change, the mqprio qdisc will need to iterate through this nlattr region to discover other attributes, so eliminate parse_attr() and add 2 variables in mqprio_parse_nlattr() which hold the beginning and the length of the nlattr range. We avoid the need to memset when nlattr_opt_len has insufficient length by pre-initializing the table "tb". Signed-off-by: Vladimir Oltean Reviewed-by: Ferenc Fejes Reviewed-by: Simon Horman Acked-by: Jamal Hadi Salim --- v1->v4: none net/sched/sch_mqprio.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/net/sched/sch_mqprio.c b/net/sched/sch_mqprio.c index 48ed87b91086..94093971da5e 100644 --- a/net/sched/sch_mqprio.c +++ b/net/sched/sch_mqprio.c @@ -146,32 +146,26 @@ static const struct nla_policy mqprio_policy[TCA_MQPRIO_MAX + 1] = { [TCA_MQPRIO_MAX_RATE64] = { .type = NLA_NESTED }, }; -static int parse_attr(struct nlattr *tb[], int maxtype, struct nlattr *nla, - const struct nla_policy *policy, int len) -{ - int nested_len = nla_len(nla) - NLA_ALIGN(len); - - if (nested_len >= nla_attr_size(0)) - return nla_parse_deprecated(tb, maxtype, - nla_data(nla) + NLA_ALIGN(len), - nested_len, policy, NULL); - - memset(tb, 0, sizeof(struct nlattr *) * (maxtype + 1)); - return 0; -} - +/* Parse the other netlink attributes that represent the payload of + * TCA_OPTIONS, which are appended right after struct tc_mqprio_qopt. + */ static int mqprio_parse_nlattr(struct Qdisc *sch, struct tc_mqprio_qopt *qopt, struct nlattr *opt) { + struct nlattr *nlattr_opt = nla_data(opt) + NLA_ALIGN(sizeof(*qopt)); + int nlattr_opt_len = nla_len(opt) - NLA_ALIGN(sizeof(*qopt)); struct mqprio_sched *priv = qdisc_priv(sch); - struct nlattr *tb[TCA_MQPRIO_MAX + 1]; + struct nlattr *tb[TCA_MQPRIO_MAX + 1] = {}; struct nlattr *attr; int i, rem, err; - err = parse_attr(tb, TCA_MQPRIO_MAX, opt, mqprio_policy, - sizeof(*qopt)); - if (err < 0) - return err; + if (nlattr_opt_len >= nla_attr_size(0)) { + err = nla_parse_deprecated(tb, TCA_MQPRIO_MAX, nlattr_opt, + nlattr_opt_len, mqprio_policy, + NULL); + if (err < 0) + return err; + } if (!qopt->hw) return -EINVAL;