Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1049473rwl; Fri, 7 Apr 2023 09:09:45 -0700 (PDT) X-Google-Smtp-Source: AKy350aJqFN2w5okj7je6Z7p9JWptL4y4k7ESniJQUfT2Xo/r/LFyBHSqsO8GKzAoYIXX81qUASv X-Received: by 2002:aa7:dd06:0:b0:502:8f49:2552 with SMTP id i6-20020aa7dd06000000b005028f492552mr3240704edv.27.1680883785541; Fri, 07 Apr 2023 09:09:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680883785; cv=none; d=google.com; s=arc-20160816; b=GsVhC3NqdJvQVavLDRcbtFJBA84/2P9HZFehIIU24AajEgdpO1BmgiuFA44Krp+Nwa XrQyg7/beQDWaKpjKoEl/h8alH+F41CVowgtuabrPBCZq+tIafL8hfWbRGsP7zUbQJY7 uYsaQXrmxab1ubSn1hCxTrR8uRjNPYndJ2wOFNfO2dF1+xn1x7TJ3aGnmMSUdPwSsUlF h3l8i252++XVXV/ORVaJpT742hQrmIbuukYPkToHMJWSZ4twSfsZseTHGAGtp6l0oCDI GjyCcctMZQcfMFV1qvJOPxqt2MBuqO1cINjk2UX8XXkgudSX9MEK+mHro0hZxUU+GvGC ZFUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=4Ikt4cUnbAD+aNtn12UlFaiBStoPGqSHVX26BE/7WeM=; b=Fb0p+51UZ2JVT1XiV5dn7XvRVUib+Lyhq/ZfqaWXyfrhuxIcjUDsAyI0llRTZzEjsh CYFaB4Pd0hZ63buRFhlXe10Ik4XdhPG1Dwu0cf2GVoVnGV6zh0PWtGvah/Sl4hlj8un/ Eivm5yvpru4v4xgFDmZdduHbw/yDJiYtT/jB4vtgFe70RH0aMmjTQnJXQupJXg57xx+T c4hG5G5lQIf8cOoeTTjMapn5nZSH4mHLg88W6hVOMbZYO57MRLNtLZhUf20E+nG+jQeG jaMeI4L2BTyppM3eT3FQdYxglovpN0T7WV0+d4FNFf9KI43QdIPqt+/ZTtaMmeBSBvpN bHbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mojatatu-com.20210112.gappssmtp.com header.s=20210112 header.b="qW65ZX/f"; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k5-20020a05640212c500b00501cf1795cdsi3293506edx.112.2023.04.07.09.09.18; Fri, 07 Apr 2023 09:09:45 -0700 (PDT) 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=@mojatatu-com.20210112.gappssmtp.com header.s=20210112 header.b="qW65ZX/f"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240753AbjDGQGH (ORCPT + 99 others); Fri, 7 Apr 2023 12:06:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240763AbjDGQF7 (ORCPT ); Fri, 7 Apr 2023 12:05:59 -0400 Received: from mail-yw1-x112e.google.com (mail-yw1-x112e.google.com [IPv6:2607:f8b0:4864:20::112e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17FBDBDCB for ; Fri, 7 Apr 2023 09:05:48 -0700 (PDT) Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-545cb3c9898so728095307b3.7 for ; Fri, 07 Apr 2023 09:05:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mojatatu-com.20210112.gappssmtp.com; s=20210112; t=1680883547; x=1683475547; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=4Ikt4cUnbAD+aNtn12UlFaiBStoPGqSHVX26BE/7WeM=; b=qW65ZX/foFdpDfE3Ib3eFqGMbd36ADAGUHlyKPdtan0k1ZOf6XvSqQddwkzHUBMBak 3/9mo9/7/4mVZoZKZOair9LztKforOnN51P1FqfCb4ocR9yDRl/DmT1mKg/eR1Ztf6zK W5SmbB4vywpEhq3qXzWBJlEwbYud17wSwGbkM9B+6KoimE4yzYNkLaqFXbs+jcJiFSes UujHFLDkg1ulIrSdrkPuRFFGnpmYoxrA+/d+m5EzfzUk4rgG0JtNpp0eazFmR6yxCSr6 SS/a4+sbUO5YTyGl6/l+4Mfm9aPpZCYzKqzHMXbqgJR1AbkXDU7G6qLfoShp7tukBhV0 fFoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680883547; x=1683475547; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4Ikt4cUnbAD+aNtn12UlFaiBStoPGqSHVX26BE/7WeM=; b=COeJlZD20mohcjJ9Nkqi5q5axGihEmhvRYKE23JHRJbCHgfbog6Ks+VtQt7CsH5YCW 45kbSR1d3Sth15pTHqfUprZXoAz5xW+2RTGYrajPlTS6YqIRFTrw9Xz2TdetIyXe8Oy5 Cc3xq2k3PvTv3oRNV+PYOnqyhiYSCBwqq69ZpqUc2O43STPE4A37fA20GeHvc3TD9MiF UGyy1/s16Lza5OHttUxuQzBfEsol0AbrcjgNrFsTMq1fmIwNY1b+710cm/qPiRsO+hfl rhspf5mzRJLOumub4zL+jWYOqRbzci4vLutLlr2FM9Pt5Cbg7nlsnq5kXhVQG2C+k5ky W0Nw== X-Gm-Message-State: AAQBX9eHh49xZoUCfofuwajj9bsOcNtVm16srC9Uqpx3P7bOUgFlKLvo /oncCHhJy033KhaHMZPJmSZ//KLI9kgPTsF0vqRllA== X-Received: by 2002:a81:e20a:0:b0:54d:4a49:ba22 with SMTP id p10-20020a81e20a000000b0054d4a49ba22mr1019445ywl.7.1680883547060; Fri, 07 Apr 2023 09:05:47 -0700 (PDT) MIME-Version: 1.0 References: <20230403103440.2895683-1-vladimir.oltean@nxp.com> <20230403103440.2895683-3-vladimir.oltean@nxp.com> In-Reply-To: <20230403103440.2895683-3-vladimir.oltean@nxp.com> From: Jamal Hadi Salim Date: Fri, 7 Apr 2023 12:05:35 -0400 Message-ID: Subject: Re: [PATCH v4 net-next 2/9] net/sched: mqprio: simplify handling of nlattr portion of TCA_OPTIONS To: Vladimir Oltean Cc: netdev@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=0.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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 On Mon, Apr 3, 2023 at 6:35=E2=80=AFAM Vladimir Oltean wrote: > > 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 cheers, jamal > --- > 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_MQ= PRIO_MAX + 1] =3D { > [TCA_MQPRIO_MAX_RATE64] =3D { .type =3D NLA_NESTED }, > }; > > -static int parse_attr(struct nlattr *tb[], int maxtype, struct nlattr *n= la, > - const struct nla_policy *policy, int len) > -{ > - int nested_len =3D nla_len(nla) - NLA_ALIGN(len); > - > - if (nested_len >=3D 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 =3D nla_data(opt) + NLA_ALIGN(sizeof(*q= opt)); > + int nlattr_opt_len =3D nla_len(opt) - NLA_ALIGN(sizeof(*qopt)); > struct mqprio_sched *priv =3D qdisc_priv(sch); > - struct nlattr *tb[TCA_MQPRIO_MAX + 1]; > + struct nlattr *tb[TCA_MQPRIO_MAX + 1] =3D {}; > struct nlattr *attr; > int i, rem, err; > > - err =3D parse_attr(tb, TCA_MQPRIO_MAX, opt, mqprio_policy, > - sizeof(*qopt)); > - if (err < 0) > - return err; > + if (nlattr_opt_len >=3D nla_attr_size(0)) { > + err =3D nla_parse_deprecated(tb, TCA_MQPRIO_MAX, nlattr_o= pt, > + nlattr_opt_len, mqprio_policy, > + NULL); > + if (err < 0) > + return err; > + } > > if (!qopt->hw) > return -EINVAL; > -- > 2.34.1 >