From patchwork Thu Feb 16 23:21:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 58278 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp583092wrn; Thu, 16 Feb 2023 15:23:29 -0800 (PST) X-Google-Smtp-Source: AK7set+OLsnJO9J/cHtbpiBAzc6xfJkMdBjikWrcip/JJ0BL/ttecPG7yKf1oJPE8Ezwx3OM3gj3 X-Received: by 2002:a62:1a09:0:b0:592:528e:72a1 with SMTP id a9-20020a621a09000000b00592528e72a1mr5758555pfa.27.1676589808759; Thu, 16 Feb 2023 15:23:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1676589808; cv=pass; d=google.com; s=arc-20160816; b=b2fX3Y+e6ori2+iZyy7LcJgWouiqmYP3NGOPQR6J9uwSiP/N8MjVmzCZkPwJCzfOLE 3OfTGgsqtykxRIeUol1bW97VFwxlyxXNE6yH6fUZTuQrvNp1P+40q3/+NjKsxQZ64o/5 78C7A44R2CoQrXbTXwrkfw3w4cPx40nw2zRwNN3x2VBEHtVYO/L1OZAxGiluc3yBW1TE snRNL4ifTtSBwRXa7cLC2/t8XPUxhsHdSd8ItetCYwx3+N7ChLoXia8Z6deu5jdDiZmt llC8kj8ZW7zqUSSz+aa+eGJ82uQDdUP1y7C+E5cC29bxbusjw0wJIukk9faj33BA3wAF rF2Q== 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=jiUVozUMEjWcF8Zejiu7eEwqiflH6NVFM+g++3wtl7E=; b=MjwiOhRSnJP9bc+/XjUhe4mPhPeC7L/yrxpdwAjoiyBJin1o2XaH8saCjhwfZYfm49 30U1cmpSYWkrrEXdprYvvDOh57PkNJcFdwHLud2bH53Nto1BM4i+1amm+OnGKlcoD0CC MNjJqhcnNHsRZSgzqoIXAD3gGyEdW7t9TbGpStCDzplx6ikOGabCH5vN9xJ7KdvTbrPP ZpH1vO6LruL0ZJS/JsQzrSuZv3I0m3hsp6iZm4JPvPST7O72GQgTSsiGXJLmUAvX2JqF Cv1vOMoZuSGG8Y8k0q7mDFQ9+38ushoWJocC8tw/mIH6v6+F3VHtJuDV5PKHZqx4IiBz r0xQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=kU7vBFi6; 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 t23-20020a62d157000000b005659a66d652si2742636pfl.229.2023.02.16.15.23.15; Thu, 16 Feb 2023 15:23:28 -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=kU7vBFi6; 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 S229955AbjBPXWe (ORCPT + 99 others); Thu, 16 Feb 2023 18:22:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229866AbjBPXWN (ORCPT ); Thu, 16 Feb 2023 18:22:13 -0500 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2075.outbound.protection.outlook.com [40.107.104.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C20554D0F; Thu, 16 Feb 2023 15:21:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bOt3WS2d8USB6w407j269zL2shDXXyIb4UefolaeTbQWr8193Aqb7qLagr/IopnwgKlS7E8aI/1Ned3ZkWlxSm2qlF7Szi5iMxwddBIoHx4ysFv/rmo+Bz8ycMqCpbMpeM5FSLlPVXmZkwrtD6Nw1S++TpCYDLYC7Gx/j5wdjJEPeVRMoAvhBdu6AkMq+8N7OkBQLGENRBs/REAzpEeCv/40P5QEBoJXUW/8QxvAgdwieKf/0UMK9njxtjwEcObN7VambPlhuid7Om7rDlvUaynlWauNPwG+SAm7BRyGZk/2xQN8Coma8Xxu/f5rHxzkyNuIMVi6looYlAAMlhFnzg== 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=jiUVozUMEjWcF8Zejiu7eEwqiflH6NVFM+g++3wtl7E=; b=ICDzIK6qhe/RDbTzy4CCFf2yA7+seB+YojHyiJKfWCdfWb5xjp1dbfoibd1Rkylx1D3TqZdSAbgr8WQhSBX2k6aQ0sECvKqndnvXaAtIU1PcRa34CTZDJYvGb4BH84/JdxsiAz+HNAlKgpG9zbEDXv6bIb4FuCOzgvzKrNxl42YqAxgNunv/e1YOCad/SYN17grc7B/+hIrrf2N63TW5PwoMzzyNtxGLXEsCQAxkQnEEVtCJ+7/Td1fs4WL+3rPQ0JtnzcWcvb3+8BNu7zfw7t6RX6FEChUwG1utw4uRJ/c2i3Wa++fHZP0fqW9bga886UmKhbuHlzpcICassSB4wA== 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=jiUVozUMEjWcF8Zejiu7eEwqiflH6NVFM+g++3wtl7E=; b=kU7vBFi6ulNsgUacvjjhdkfm0VJAhRxDAmfX5M1/JaS8cV24//BhgUgwRDDgdKKM+a+8dk3ZYldjcTGL5Ynbs5qdvIJZYdKe/m9/swos52IgyfnJ/hgYGPlXzKag9ZY5WM5QSaa5MKh3zN0xvk6Tqg2v/x67FHnec6dZ/O5CZw8= 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 PR3PR04MB7436.eurprd04.prod.outlook.com (2603:10a6:102:87::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6086.26; Thu, 16 Feb 2023 23:21:47 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3cfb:3ae7:1686:a68b]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3cfb:3ae7:1686:a68b%4]) with mapi id 15.20.6086.026; Thu, 16 Feb 2023 23:21:47 +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 , linux-kernel@vger.kernel.org Subject: [PATCH net-next 06/12] net/sched: mqprio: simplify handling of nlattr portion of TCA_OPTIONS Date: Fri, 17 Feb 2023 01:21:20 +0200 Message-Id: <20230216232126.3402975-7-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216232126.3402975-1-vladimir.oltean@nxp.com> References: <20230216232126.3402975-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VI1PR0501CA0018.eurprd05.prod.outlook.com (2603:10a6:800:92::28) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR04MB5136:EE_|PR3PR04MB7436:EE_ X-MS-Office365-Filtering-Correlation-Id: 961174d8-43f7-4f6a-fe89-08db1074931d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PENbNupF6m/UEy0zscRy7oMLO3CSk0wA4lRyYmAHmZey3moEsP5JM96cfeq0EvD9zf/+kAC3pWGDBToqyKwaQov14NI2HEV2cvEzdyXXmh2iN4aAbzKVqlYgXJJwUGq9yymh+P1wVTmOAzhtQvvL0YEFrcpjek9PPAc0wJD7t8bKAVRGAxHV7rn6+pRLcRO3CP9WSLMi1PVM3P03jflQ26CMOQ+j51v/etPVbxdUcQajzAVe3YphoMgserIVrZOCN8RBBcjaYd0X7PIkj3swJJxB/NfYL+GckLCmnk87OhIg5aZl2DOI+7NjdJPf+VAS5HJdmnCiAqAiAltxpxcU6w40fRwlcPkwhdbot1JoOshYl4ywxIrtdI4cK2Y32jVyey8XG/A7YcvBY7Hlf0iJHuEvrCYoqe7eMbhVmCGCipy6xZe2BGmZDP336ce8uMMtpdjNLJy81zMcnYSYEDvvBPINROLm1R9yLMtuvuc0nhduYkPOpFO/VLZiNvHy1E+vGS+o9sQw2i2t6EPnDchb8XBnUf6yTR2I2mb3TfdXBX0MJytlIb+TV8JsWjzRYdDPZSH/9VazsJVts+od0f8QjjiIqupF0p7MNRmst/Yt90vH7ZXSU9HnLjdPNW3w+WZkDbh2tbeyEi3Pdz8Whwsm3LysP32IXlqnwlwHDPdffdLdCmVBatz9fjn2IWBE4F5/zFUAXmY7vCDKV8ntclLmjw== 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)(376002)(366004)(396003)(136003)(39860400002)(346002)(451199018)(38100700002)(2906002)(38350700002)(44832011)(7416002)(83380400001)(66476007)(2616005)(86362001)(478600001)(6916009)(66556008)(36756003)(5660300002)(41300700001)(6506007)(52116002)(6666004)(4326008)(66946007)(6486002)(54906003)(186003)(316002)(8936002)(26005)(6512007)(1076003)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fpWsW2kmHU+lkCtD0abn4gfZDhbn9STsvgs+5odDufpevO6zSh0mGHGYN+lR8KQQorAISL4zfzfKPpKTxIBusXKCsYh7XAvfD6Tg/hqYRXt5gEzVBkrzXOhCxOvVpWFHnLDs1esg2F5/TfndK8CgMuF+A4v19O0dxRAay81M/cohelaR8DV/8L4OkgsNG6EqqM8cu6Uzc1CspukCX/cN5XIyUrPfQrR4y7IJ1OdBiuEpyRI3b6YCOfJWyiQwIr4J9biftoU4kdLoctdiujkPAMLH7xiFAqXRkW6Bokq+Wjbmfy1zlYsTAAvbYnCG7xfKCZC1VFXaRdaK87esuHKj8LkknNiIhv7QFGOigXAhYeAuPi49I6xwsuSWHmvwTQsWZcv17aFkMFQSQOBE6XVo+AArZr/ha2vQaifcnLRdbN7Fpp6M7d9bku6WEhmrdD6mMOEpIsYFITl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T3AIzGTdDVoZVGds8RxGxvaLWrbCYK7jH1OJPmwp89ExcBJDJ6jIGRp+QPApr2xMVkWDttm+rwp6iMU4AaADDK+g44N9vYtM3+g== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 961174d8-43f7-4f6a-fe89-08db1074931d X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Feb 2023 23:21:47.5086 (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: M3uFzIkXpKujzhMGVTRxvc3RN43cWIhJiw+4dOmmW6QpT6epJ7YxyWxqh2I5ysDXzMK0i+9Qc6WVbWtcQLyLkA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR3PR04MB7436 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_NONE,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?1758031835275731428?= X-GMAIL-MSGID: =?utf-8?q?1758031835275731428?= 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 --- 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 f0232783ced7..cbb9cd2c3eff 100644 --- a/net/sched/sch_mqprio.c +++ b/net/sched/sch_mqprio.c @@ -147,32 +147,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;