From: Vladimir Oltean <vladimir.oltean@nxp.com>
To: Claudiu Manoil <claudiu.manoil@nxp.com>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Vinicius Costa Gomes <vinicius.gomes@intel.com>,
Kurt Kanzenbach <kurt@linutronix.de>,
Jacob Keller <jacob.e.keller@intel.com>,
Jamal Hadi Salim <jhs@mojatatu.com>,
Cong Wang <xiyou.wangcong@gmail.com>,
Jiri Pirko <jiri@resnulli.us>
Subject: Re: [PATCH v4 net-next 08/15] net/sched: mqprio: allow offloading drivers to request queue count validation
Date: Mon, 30 Jan 2023 21:06:28 +0200 [thread overview]
Message-ID: <20230130190628.5jaa2st434f2vfhj@skbuf> (raw)
In-Reply-To: <AM9PR04MB83977621774954ABED31037896D39@AM9PR04MB8397.eurprd04.prod.outlook.com>
Hi Claudiu,
On Mon, Jan 30, 2023 at 08:37:02PM +0200, Claudiu Manoil wrote:
> > -----Original Message-----
> > From: Vladimir Oltean <vladimir.oltean@nxp.com>
> > Sent: Monday, January 30, 2023 7:32 PM
> [...]
> > Subject: [PATCH v4 net-next 08/15] net/sched: mqprio: allow offloading drivers
> > to request queue count validation
> >
>
> [...]
>
> > +static int mqprio_validate_queue_counts(struct net_device *dev,
> > + const struct tc_mqprio_qopt *qopt)
> > +{
> > + int i, j;
> > +
> > + for (i = 0; i < qopt->num_tc; i++) {
> > + unsigned int last = qopt->offset[i] + qopt->count[i];
> > +
> > + /* Verify the queue count is in tx range being equal to the
> > + * real_num_tx_queues indicates the last queue is in use.
> > + */
> > + if (qopt->offset[i] >= dev->real_num_tx_queues ||
> > + !qopt->count[i] ||
> > + last > dev->real_num_tx_queues)
> > + return -EINVAL;
> > +
> > + /* Verify that the offset and counts do not overlap */
> > + for (j = i + 1; j < qopt->num_tc; j++) {
> > + if (last > qopt->offset[j])
> > + return -EINVAL;
> > + }
> > + }
> > +
> > + return 0;
> > +}
> > +
>
> Not related to this series, but the above O(n^2) code snippet....
> If last[i] := offset[i] + count[i] and last[i] <= offset[i+1],
> then offset[i] + count[i] <= offset[i+1] for every i := 0, num_tc - 1.
>
> In other words, it's enough to check that last[i] <= offset[i+1] to make
> sure there's no interval overlap, and it's O(n).
Hmm, actually you bring a good point, which I didn't notice.
It looks to me like someone had an idea but never went through implementing it.
The complexity is O(n^2) because it's actually only the overlaps that
the code is supposed to check for. It's not necessary for TXQs to be in
ascending order ("last[i] <= offset[i+1]" isn't a given).
I'm pretty sure that TXQs can also be mapped in reverse compared to the TC,
like this:
tc qdisc add dev eno0 root handle 1: mqprio num_tc 8 map 0 1 2 3 4 5 6 7 queues 1@7 1@6 1@5 1@4 1@3 1@2 1@1 1@0 hw 1
Which *should* be allowed (at least in hardware, it is), and which would
indeed justify the higher complexity validation function.
But with "hw 0", the existing code indeed doesn't allow that.
We would need this change first, targeting "net":
diff --git a/net/sched/sch_mqprio.c b/net/sched/sch_mqprio.c
index 4c68abaa289b..4f6fb05a4adc 100644
--- a/net/sched/sch_mqprio.c
+++ b/net/sched/sch_mqprio.c
@@ -101,7 +101,8 @@ static int mqprio_parse_opt(struct net_device *dev, struct tc_mqprio_qopt *qopt)
/* Verify that the offset and counts do not overlap */
for (j = i + 1; j < qopt->num_tc; j++) {
- if (last > qopt->offset[j])
+ if (last > qopt->offset[j] &&
+ last <= qopt->offset[j] + qopt->count[j])
return -EINVAL;
}
}
then see you in a week from now, with net-next merged with that patch.
Oh well.. :)
next prev parent reply other threads:[~2023-01-30 19:06 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-30 17:31 [PATCH v4 net-next 00/15] ENETC mqprio/taprio cleanup Vladimir Oltean
2023-01-30 17:31 ` [PATCH v4 net-next 01/15] net: enetc: simplify enetc_num_stack_tx_queues() Vladimir Oltean
2023-02-01 13:44 ` Simon Horman
2023-01-30 17:31 ` [PATCH v4 net-next 02/15] net: enetc: allow the enetc_reconfigure() callback to fail Vladimir Oltean
2023-02-01 13:45 ` Simon Horman
2023-01-30 17:31 ` [PATCH v4 net-next 03/15] net: enetc: recalculate num_real_tx_queues when XDP program attaches Vladimir Oltean
2023-02-01 13:45 ` Simon Horman
2023-01-30 17:31 ` [PATCH v4 net-next 04/15] net: enetc: ensure we always have a minimum number of TXQs for stack Vladimir Oltean
2023-02-01 13:43 ` Simon Horman
2023-02-01 18:46 ` Vladimir Oltean
2023-02-02 9:29 ` Simon Horman
2023-01-30 17:31 ` [PATCH v4 net-next 05/15] net/sched: mqprio: refactor nlattr parsing to a separate function Vladimir Oltean
2023-02-01 14:03 ` Simon Horman
2023-01-30 17:31 ` [PATCH v4 net-next 06/15] net/sched: mqprio: refactor offloading and unoffloading to dedicated functions Vladimir Oltean
2023-02-01 14:07 ` Simon Horman
2023-02-01 14:09 ` Simon Horman
2023-01-30 17:31 ` [PATCH v4 net-next 07/15] net/sched: move struct tc_mqprio_qopt_offload from pkt_cls.h to pkt_sched.h Vladimir Oltean
2023-02-01 14:07 ` Simon Horman
2023-02-01 14:11 ` Simon Horman
2023-01-30 17:31 ` [PATCH v4 net-next 08/15] net/sched: mqprio: allow offloading drivers to request queue count validation Vladimir Oltean
2023-01-30 18:37 ` Claudiu Manoil
2023-01-30 19:06 ` Vladimir Oltean [this message]
2023-02-01 14:08 ` Simon Horman
2023-01-30 17:31 ` [PATCH v4 net-next 09/15] net/sched: mqprio: add extack messages for " Vladimir Oltean
2023-02-01 14:12 ` Simon Horman
2023-01-30 17:31 ` [PATCH v4 net-next 10/15] net: enetc: request mqprio to validate the queue counts Vladimir Oltean
2023-02-01 14:12 ` Simon Horman
2023-01-30 17:31 ` [PATCH v4 net-next 11/15] net: enetc: act upon the requested mqprio queue configuration Vladimir Oltean
2023-02-01 15:15 ` Simon Horman
2023-01-30 17:31 ` [PATCH v4 net-next 12/15] net/sched: taprio: pass mqprio queue configuration to ndo_setup_tc() Vladimir Oltean
2023-02-01 15:16 ` Simon Horman
2023-01-30 17:31 ` [PATCH v4 net-next 13/15] net: enetc: act upon mqprio queue config in taprio offload Vladimir Oltean
2023-02-01 15:16 ` Simon Horman
2023-01-30 17:31 ` [PATCH v4 net-next 14/15] net/sched: taprio: mask off bits in gate mask that exceed number of TCs Vladimir Oltean
2023-02-01 15:17 ` Simon Horman
2023-01-30 17:31 ` [PATCH v4 net-next 15/15] net/sched: taprio: only calculate gate mask per TXQ for igc, stmmac and tsnep Vladimir Oltean
2023-02-01 15:17 ` Simon Horman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230130190628.5jaa2st434f2vfhj@skbuf \
--to=vladimir.oltean@nxp.com \
--cc=claudiu.manoil@nxp.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jacob.e.keller@intel.com \
--cc=jhs@mojatatu.com \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=kurt@linutronix.de \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=vinicius.gomes@intel.com \
--cc=xiyou.wangcong@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox