From: Josef Schlehofer <pepe.schlehofer@gmail.com>
To: netdev@vger.kernel.org
Cc: marcin.s.wojtas@gmail.com, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, maxime.chevallier@bootlin.com, w@1wt.eu,
linux-kernel@vger.kernel.org
Subject: [PATCH net-next v4 5/6] net: mvneta: validate an mqprio setup before applying it
Date: Wed, 18 Nov 2026 10:30:11 +0100 [thread overview]
Message-ID: <20261118093012.90121-6-pepe.schlehofer@gmail.com> (raw)
In-Reply-To: <20261118093012.90121-1-pepe.schlehofer@gmail.com>
A failed mqprio offload setup leaves part of its configuration in the
hardware. When one max_rate is not a multiple of 10 kbit/s, the
command fails, but the RX queue mapping, the rate limit mode and the
rates of TX queues 0-3 are already written:
tc qdisc add dev eth2 root handle 100: mqprio num_tc 2 \
map 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 queues 4@0 4@4 hw 1 \
mode channel shaper bw_rlimit max_rate 10Mbit 10001kbit
mvneta_setup_mqprio() checks the queue ranges and rates while it
programs them, and the qdisc then fails to attach without calling the
driver again.
Check the whole configuration first and write to the hardware only
when it is valid, so a setup that the driver rejects changes nothing.
A class without queues is still accepted. This also covers a rejected
replace under a new handle, which runs while the old offload stays
attached:
tc qdisc add dev eth2 root handle 100: mqprio num_tc 2 \
map 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 queues 4@0 4@4 hw 1 \
mode channel shaper bw_rlimit max_rate 10Mbit 10Mbit
tc qdisc replace dev eth2 root handle 200: mqprio num_tc 2 \
map 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 queues 4@0 4@4 hw 1 \
mode channel shaper bw_rlimit max_rate 10Mbit 10001kbit
The hardware setup of the old qdisc is kept. The rejected qdisc never
enabled its offload, so its mqprio_destroy() still calls
netdev_set_num_tc(dev, 0). Until the old qdisc is deleted, tc shows it
without traffic classes and the stack spreads the flows over all TX
queues.
Found by an AI code review agent while working on this series, and
confirmed on a Turris Omnia (Armada 385). Without this patch, after
the first command failed, TX queues 0-3 stayed limited to 10 Mbit/s
and the VLAN priority map stayed set. With this patch both failed
commands leave every register unchanged, and after the failed replace
the 10 Mbit/s limits of 100: stay in effect. No kernel selftest covers
the mvneta mqprio offload.
Fixes: e9f7099d0730 ("net: mvneta: Allow having more than one queue per TC")
Fixes: 2551dc9e398c ("net: mvneta: Add TC traffic shaping offload")
Link: https://lore.kernel.org/netdev/20261022144814.66366-1-shawnq1@163.com/
Signed-off-by: Josef Schlehofer <pepe.schlehofer@gmail.com>
---
v4: Replaces "unwind a failed mqprio setup". The unwind also cleared
the hardware setup of an attached qdisc when its replacement failed,
as Sashiko pointed out on v3 [1]. Maxime's Reviewed-by is dropped
because the approach changed.
The rate conversion moves to mvneta_txq_refill_val() unchanged. A
follow-up will tighten its range check for very large rates.
[1] https://lore.kernel.org/netdev/179418382346.994134.3211728825005845989@kernel.org/
---
drivers/net/ethernet/marvell/mvneta.c | 90 +++++++++++++--------------
1 file changed, 44 insertions(+), 46 deletions(-)
diff --git a/drivers/net/ethernet/marvell/mvneta.c b/drivers/net/ethernet/marvell/mvneta.c
index 58453c69be36..89ade2ed7ce4 100644
--- a/drivers/net/ethernet/marvell/mvneta.c
+++ b/drivers/net/ethernet/marvell/mvneta.c
@@ -5224,11 +5224,10 @@ static void mvneta_disable_per_queue_rate_limit(struct mvneta_port *pp)
}
}
-static int mvneta_setup_queue_rates(struct mvneta_port *pp, int queue,
- u64 min_rate, u64 max_rate)
+/* Convert a rate limit to the token bucket refill of a TX queue */
+static int mvneta_txq_refill_val(u64 min_rate, u64 max_rate, u32 *val)
{
u32 refill_val, rem;
- u32 val = 0;
/* Convert to from Bps to bps */
max_rate *= 8;
@@ -5243,12 +5242,8 @@ static int mvneta_setup_queue_rates(struct mvneta_port *pp, int queue,
refill_val > MVNETA_TXQ_BUCKET_REFILL_VALUE_MAX)
return -EINVAL;
- val = refill_val;
- val |= (MVNETA_TXQ_BUCKET_REFILL_PERIOD <<
- MVNETA_TXQ_BUCKET_REFILL_PERIOD_SHIFT);
-
- pp->txqs[queue].bucket_refill = val;
- mvreg_write(pp, MVNETA_TXQ_BUCKET_REFILL_REG(queue), val);
+ *val = refill_val | (MVNETA_TXQ_BUCKET_REFILL_PERIOD <<
+ MVNETA_TXQ_BUCKET_REFILL_PERIOD_SHIFT);
return 0;
}
@@ -5276,8 +5271,10 @@ static void mvneta_restore_per_queue_rate_limit(struct mvneta_port *pp)
static int mvneta_setup_mqprio(struct net_device *dev,
struct tc_mqprio_qopt_offload *mqprio)
{
+ bool shaper = mqprio->shaper == TC_MQPRIO_SHAPER_BW_RATE;
struct mvneta_port *pp = netdev_priv(dev);
- int rxq, txq, tc, ret;
+ u32 refill[TC_QOPT_MAX_QUEUE];
+ int queue, last, tc, ret;
u8 num_tc;
num_tc = mqprio->qopt.num_tc;
@@ -5286,58 +5283,59 @@ static int mvneta_setup_mqprio(struct net_device *dev,
if (num_tc && mqprio->qopt.hw != TC_MQPRIO_HW_OFFLOAD_TCS)
return 0;
- if (num_tc > rxq_number)
- return -EINVAL;
-
- mvneta_clear_rx_prio_map(pp);
-
if (!num_tc) {
+ mvneta_clear_rx_prio_map(pp);
mvneta_disable_per_queue_rate_limit(pp);
netdev_reset_tc(dev);
return 0;
}
- netdev_set_num_tc(dev, mqprio->qopt.num_tc);
+ /* Check everything first, a rejected setup must not change anything */
+ if (num_tc > rxq_number || (shaper && num_tc > txq_number))
+ return -EINVAL;
- for (tc = 0; tc < mqprio->qopt.num_tc; tc++) {
- netdev_set_tc_queue(dev, tc, mqprio->qopt.count[tc],
- mqprio->qopt.offset[tc]);
+ for (tc = 0; tc < num_tc; tc++) {
+ if (!mqprio->qopt.count[tc])
+ continue;
- for (rxq = mqprio->qopt.offset[tc];
- rxq < mqprio->qopt.count[tc] + mqprio->qopt.offset[tc];
- rxq++) {
- /* The range sets the TX queues of the class as well */
- if (rxq >= rxq_number || rxq >= txq_number)
- return -EINVAL;
+ last = mqprio->qopt.offset[tc] + mqprio->qopt.count[tc];
+ if (last > rxq_number || last > txq_number)
+ return -EINVAL;
- mvneta_map_vlan_prio_to_rxq(pp, tc, rxq);
- }
+ if (!shaper)
+ continue;
+
+ ret = mvneta_txq_refill_val(mqprio->min_rate[tc],
+ mqprio->max_rate[tc], &refill[tc]);
+ if (ret)
+ return ret;
}
- if (mqprio->shaper != TC_MQPRIO_SHAPER_BW_RATE) {
+ /* This can only fail before it writes to the hardware */
+ if (shaper) {
+ ret = mvneta_enable_per_queue_rate_limit(pp);
+ if (ret)
+ return ret;
+ } else {
mvneta_disable_per_queue_rate_limit(pp);
- return 0;
}
- if (mqprio->qopt.num_tc > txq_number)
- return -EINVAL;
+ mvneta_clear_rx_prio_map(pp);
+ netdev_set_num_tc(dev, num_tc);
- ret = mvneta_enable_per_queue_rate_limit(pp);
- if (ret)
- return ret;
+ for (tc = 0; tc < num_tc; tc++) {
+ netdev_set_tc_queue(dev, tc, mqprio->qopt.count[tc],
+ mqprio->qopt.offset[tc]);
+
+ last = mqprio->qopt.offset[tc] + mqprio->qopt.count[tc];
+ for (queue = mqprio->qopt.offset[tc]; queue < last; queue++) {
+ mvneta_map_vlan_prio_to_rxq(pp, tc, queue);
+ if (!shaper)
+ continue;
- for (tc = 0; tc < mqprio->qopt.num_tc; tc++) {
- for (txq = mqprio->qopt.offset[tc];
- txq < mqprio->qopt.count[tc] + mqprio->qopt.offset[tc];
- txq++) {
- if (txq >= txq_number)
- return -EINVAL;
-
- ret = mvneta_setup_queue_rates(pp, txq,
- mqprio->min_rate[tc],
- mqprio->max_rate[tc]);
- if (ret)
- return ret;
+ pp->txqs[queue].bucket_refill = refill[tc];
+ mvreg_write(pp, MVNETA_TXQ_BUCKET_REFILL_REG(queue),
+ refill[tc]);
}
}
--
2.54.0 (Apple Git-157)
next prev parent reply other threads:[~2026-11-18 9:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 9:30 [PATCH net-next v4 0/6] net: mvneta: fix the TX queue arbitration and the mqprio offload Josef Schlehofer
2026-11-18 9:30 ` [PATCH net-next v4 1/6] net: mvneta: lift the per-queue TX rate limits Josef Schlehofer
2026-11-18 9:30 ` [PATCH net-next v4 2/6] net: mvneta: fix the removal of the mqprio offload Josef Schlehofer
2026-11-18 9:30 ` [PATCH net-next v4 3/6] net: mvneta: check the TX queue range of an " Josef Schlehofer
2026-11-18 9:30 ` [PATCH net-next v4 4/6] net: mvneta: keep the TX rate limits across open and MTU change Josef Schlehofer
2026-11-18 9:30 ` Josef Schlehofer [this message]
2026-11-18 9:30 ` [PATCH net-next v4 6/6] net: mvneta: serve the TX queues in weighted round robin Josef Schlehofer
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=20261118093012.90121-6-pepe.schlehofer@gmail.com \
--to=pepe.schlehofer@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcin.s.wojtas@gmail.com \
--cc=maxime.chevallier@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=w@1wt.eu \
/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