From patchwork Mon Feb 20 12:23: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: 59411 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1276876wrn; Mon, 20 Feb 2023 04:25:37 -0800 (PST) X-Google-Smtp-Source: AK7set/67sM0TTEilQhZ4UwxGkVXCH6b513XhssZFPywlfM6H5Z4N9vvDbROm2jv9czos16AX7jF X-Received: by 2002:a05:6a20:8ba0:b0:b8:ca86:d1e8 with SMTP id m32-20020a056a208ba000b000b8ca86d1e8mr8620352pzh.14.1676895936677; Mon, 20 Feb 2023 04:25:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1676895936; cv=pass; d=google.com; s=arc-20160816; b=PXvPz9mepoVIA12YapSiZnwmJn1ArlnN0/ITRxNuvjkGUTIvWcIHcegzCuoK+rkQES t/OAuB1GG5SosF1zoM2ULCleO7byaQKw2KyFuG5g+us+QxzBCMv8kuFq+YuuOKxXT5VM Zuc7HgqieyoQdv7HXJ6KpMycmeL9yrpHP97aUF4DK+4UKupdCe4WBay5naJ3zG3obCTr RDcFSRO3XQoUD8hsb3KgxcCVN150jDqdx3mK3+4yZNxWJOu+/cj7mH/VXStXd+3t3ecV 2JPeTJI3SS5t0MqWwUEegPxDvp+x1Vl9HeSQ+s2OK3AMwZ/cKCRDVukFs/3OoNvq7VOg ncPQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=m9EZg6hgUN/dPAkIluWwcqmYHyResOBRpUhAQpACT28=; b=ax46eeJSm+fMtvTFIK7z9NiDQeEh3xPSyQLlOk50e68boWggPDUfssHZ1/zsN+duc3 sVrLw8N9e3CWexMaZgOOkLSjEKsJpIBwJZoX2bEcIaGxGZGyFGYKPLHPzemyovKqtlkK 1V04QClthx8KkErl9wXLqSeVFs6lmp14sPKuc4PHSA0uH1sRitJpP3RTqhGC7HbZAZ2X DOg/bjCTlMtpZCj9YnOt5ojW2MP4/QEc6rhVkrtviGKfF0nsTjr5UkwILAUdW8eDtiFZ 7OxKUdJspPghEpcTQA0nwKO9QQCzKRpmKm7849I4KOEMs97+KrY4VHK4JCD17NyHCbrT BiOA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=Dr+LPQGr; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b6-20020a63d806000000b004fb944d4acdsi14597806pgh.367.2023.02.20.04.25.23; Mon, 20 Feb 2023 04:25:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=Dr+LPQGr; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232045AbjBTMYU (ORCPT + 99 others); Mon, 20 Feb 2023 07:24:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232023AbjBTMYG (ORCPT ); Mon, 20 Feb 2023 07:24:06 -0500 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on2079.outbound.protection.outlook.com [40.107.15.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6B6E1C335; Mon, 20 Feb 2023 04:24:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WRo4v9Hn62gzM3kfZhGY31e2s06HVha1fuqE+U3+g081koy0kwqqW/TXzwDB+h/orNxGwlP+Dkv7FKpbeDM2cAaJIljmuHPo9aRzM9NRKPNrh1W4zSgs1+YB5tqQ/iAFsyiI9dbB5YJR4ZSf/nkLrLzMhUNIfBjve6AGngd38THrNzyZPUr7TiY5TKFOFgK4xpJxtoUqDEgIrTAd42Ml75wpubm7K0kiBTpnklSizJob3T55LypIl69MLrLR9Ms52OX5jogzQ76UhYrWsVBhNKgI6iTWxyqS0orVFn67cWdcPCl/j6PivgAPFvqXxqDVlxzCBPFTgFpsTwdyudlltA== 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=m9EZg6hgUN/dPAkIluWwcqmYHyResOBRpUhAQpACT28=; b=EK57XGBhTe0CBiPhuJOgKFt/H/6KmyrMbT5XMwEYI1v475fE+mH1P1541s4ZOE3BcR9dGBYDWDj3J0ScL54dA2beGrYjABOsAMoKF7ipRUAjckkEh2ppSX/P5Ml1EiEZCBiHcpfC7xhXdZ7lxJfSKRBQsAkiqtlwQJtcmkvKLynkB6Sm+DxgXky/1Flp/eJgqVMJvNkaV1kihgN2dla/Q+z2Mn5im/UZDIEgv27HFApcrrA1o0fyjRi5xcBt1eVoJByjfahK0HI/BaV8iA2mM0U4Z0RbaS12uKniYTfncj59ZpcWHnO6vEFo7EKMX+Zk2Wa6Awu0nfJqFgdWfCKiCw== 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=m9EZg6hgUN/dPAkIluWwcqmYHyResOBRpUhAQpACT28=; b=Dr+LPQGrfPyoTLQ6ANQdZ+/2bpTxuD1JL2g1BbZ84SMHiiu5FtJQ2LZqtLaDVg/rLBJVdKxp7DkDl83I3oQu97Sey59Xto7+Nl79vyipyzy1iFDoiUmWXYwHgPoF7MyRZy4uoXmwEGZSffhK6y1onrXuB7BSFMqVyEAKMPjwwn4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by PA4PR04MB7725.eurprd04.prod.outlook.com (2603:10a6:102:f1::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6111.19; Mon, 20 Feb 2023 12:24:03 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3cfb:3ae7:1686:a68b]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3cfb:3ae7:1686:a68b%7]) with mapi id 15.20.6111.019; Mon, 20 Feb 2023 12:24:03 +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 , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Andrew Lunn , Florian Fainelli , Ferenc Fejes , Xiaoliang Yang , Roger Quadros , Pranavi Somisetty , Harini Katakam , Giuseppe Cavallaro , Alexandre Torgue , Michael Sit Wei Hong , Mohammad Athari Bin Ismail , Jacob Keller , linux-kernel@vger.kernel.org, Ferenc Fejes Subject: [PATCH v3 net-next 03/13] net/sched: mqprio: simplify handling of nlattr portion of TCA_OPTIONS Date: Mon, 20 Feb 2023 14:23:33 +0200 Message-Id: <20230220122343.1156614-4-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230220122343.1156614-1-vladimir.oltean@nxp.com> References: <20230220122343.1156614-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: BE1P281CA0183.DEUP281.PROD.OUTLOOK.COM (2603:10a6:b10:8d::17) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR04MB5136:EE_|PA4PR04MB7725:EE_ X-MS-Office365-Filtering-Correlation-Id: 35d7992e-9601-4482-3e7e-08db133d5a24 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1mJWe/0sA+JGI22kY9o6nfNvQE0z1iT0QCYfztEM31VKnKYf4OOerdTZr0xVRYjWmr2P2JzlV42Dv+S/O9ysoQVOWXNbLAeLLnFELERidgExJggdIbI3vYkmfUYxr29O+nVG9PzSMtRdsxMeIhIeOfN8dOGih8OBAz8jj5maXfKlHTh8BETvu1VrZQz+CzAulPpZU7YOGyZTRqP0Fm27DboUrvRFgY5A6TI/RKZD7d1b+WIYCRSIKRJXqXnS6maxyafqL7ipBa/zyGVBvPuxlvOnc10o/mcxNdhIAiCVzyNhO8Rlk1bwCledfmSwMRSRdZjc65jS20RMknVDuWVUH8fL9vD0C0SCQlzJ/1BKuUBsksUgJdZGfJwrgw5vRdxg+Mr703mIbLaMCv6tsbmalSskIFpCxG5UMg4Dfl8Ru8hUjdk7dcoID0UhP1hjxx71bzRm8TS0Ps9J+CE2wug1kZD2qroCbYEVY5mhOi6nitKhBsou1lsHi7zDyJnoNdsZ5qBSsSpO5oV94lRkCD//KDGc4F0bAo7enwdYXapsmR2oZPqX+wgbM7Oi5sSlMZhJe04uHSlS3o9s9pL34y5om6F05AZ9RYBxJB3+b8mjKp7usXXaGRxgTOTRFKnm3u5QhbkuSfz0uOzhSeqS04Rw4pdYGKoZnd7R39dpLTFcoM2xyFux7zT/kWH4Cy+wzzwgbZ3eDdeZDikipW+d3ecfaA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5136.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(366004)(346002)(39860400002)(136003)(376002)(396003)(451199018)(8676002)(6916009)(4326008)(66556008)(316002)(6486002)(66476007)(54906003)(66946007)(7416002)(52116002)(8936002)(5660300002)(41300700001)(86362001)(36756003)(478600001)(38100700002)(1076003)(38350700002)(6506007)(26005)(186003)(6512007)(6666004)(2616005)(2906002)(44832011)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XLfFqcsfCv3fCQl872yi13Qnn942eAYpBeaxZwA6Oc13se1R3NWJYb/oIFdi0Lyq44L0LW28gIs6/y4rIjNSrDxtxG8wbtyMhKKrOWtTLHUoGqCV9fI1SgSdZPqv2pzaEeg86/vwZKAQagNip9f0B58HNVnMELF4CHYxfhw8uguyFCIsNSbEYvI2MaQuwBrN1YLtam1fBHp6fUZdnC4ypoovY8jxeH47FNpflKWd9Do77r4xKFChbW6wc/ypfr/9CPgI/+qBQaU86uopd8VnoJnnaVUt8VLNius4K4PFKSPW8OkXpsTewYZ+ihYWAzEqO2Kk7eBwVePRdMNYQBmQ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yiXkhjYMrNMEtETqu0i34xWRLD9B3KB48N38hYZG/Z89+GU2xJpC3aALG2is0w5zCeh+N+qGimNVzdgD2NVxnY2Moe8NCqUdHmev+VSMoBDN393wttJuKotz1/eHfegQoftdNQomopA+I6kkL3TRi1WpfdQuXtjE4fj4HScWIbo2ezobmTaR7TrrdGMEXp+X27yoVe5IA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 35d7992e-9601-4482-3e7e-08db133d5a24 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Feb 2023 12:24:03.2283 (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: 9EoS3hWEcesVce+kjXFuas0D3BsxA1QUwNh30g90Jr8ZhGFzoTva/bN4McMoS2+gKHpCPjzvmeZbTv7fimzHYQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB7725 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758352833610490841?= X-GMAIL-MSGID: =?utf-8?q?1758352833610490841?= 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 --- v1->v3: 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;