Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: o.rempel@pengutronix.de
Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, linusw@kernel.org,
	luizluca@gmail.com, alvin.sipraga@analog.com, andrew@lunn.ch,
	olteanv@gmail.com, netdev@vger.kernel.org, kernel@pengutronix.de
Subject: Re: [PATCH net-next 2/2] net: dsa: realtek: rtl8365mb: offload ETS strict priority scheduling
Date: Wed, 25 Nov 2026 10:23:31 +0000	[thread overview]
Message-ID: <179560221157.3135.10940899213423821559@kernel.org> (raw)
In-Reply-To: <20261124-rtl8365mb-ets-strict-v1-2-6ab01ad545c8@pengutronix.de>

Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 3

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] rtl83xx_port_setup_tc() / rtl83xx_setup_tc_ets_replace()
  (drivers/net/dsa/realtek/rtl83xx-qos.c) never reads p->priomap and…
- [Low] In rtl83xx_port_setup_tc() (drivers/net/dsa/realtek/rtl83xx-
  qos.c), the TC_ETS_STATS reply decides whether a qdisc is offloaded…
- [Low] The driver writes to the kernel log with no rate limit when a
  user's tc configuration is refused: - rtl83xx_setup_tc_ets_replace()…
- [Low] rtl83xx_setup_tc_ets_restore_wfq()
  (drivers/net/dsa/realtek/rtl83xx-qos.c) sets priv->ets_handle[port] =…

--

net: dsa: realtek: rtl8365mb: offload ETS strict priority scheduling

This commit adds ETS qdisc offload to rtl8365mb user ports. A root ets
qdisc with one strict band per queue moves the port from the default
equal-weight WFQ to strict priority, and deleting the qdisc restores WFQ.
Weighted bands are refused, and any priomap is accepted but not applied.

> diff --git a/drivers/net/dsa/realtek/rtl83xx-qos.c b/drivers/net/dsa/realtek/rtl83xx-qos.c
> index f294222987eff..388013291d502 100644
> --- a/drivers/net/dsa/realtek/rtl83xx-qos.c
> +++ b/drivers/net/dsa/realtek/rtl83xx-qos.c

[ ... ]

> @@ -208,3 +209,115 @@ int rtl83xx_port_set_apptrust(struct dsa_switch *ds, int port, const u8 *sel,
>  					   ARRAY_SIZE(trust));
>  }
>  EXPORT_SYMBOL_NS_GPL(rtl83xx_port_set_apptrust, "REALTEK_DSA");
> +
> +static int
> +rtl83xx_setup_tc_ets_replace(struct dsa_switch *ds, int port,
> +			     struct tc_ets_qopt_offload_replace_params *p)
> +{
> +	struct realtek_priv *priv = ds->priv;
> +	unsigned int nq = ds->num_tx_queues;
> +	int i;
> +
> +	/* The qdisc must have one band per queue. */
> +	if (p->bands != nq) {
> +		dev_err(priv->dev, "port %d: ETS must configure all %u bands\n",
> +			port, nq);
> +		return -EOPNOTSUPP;
> +	}

[Severity: Low]
Should these prints be ratelimited?

This dev_err() fires on every refused root ets REPLACE. So does the
"ETS weighted bands are not supported" one below. While hw-tc-offload is
on, sch_ets sends REPLACE from every ets_init() and ets_change(). A loop
like this can therefore fill dmesg without bound:

    tc qdisc change dev swpN root ets bands 4 ...

Every refused REPLACE also goes through
rtl83xx_setup_tc_ets_restore_wfq(). That function adds another dev_err()
if the register write fails.

DSA user netdevs are not netns-local. Anyone with CAP_NET_ADMIN in a
netns that owns the port can trigger this. ksz_tc_ets_validate() uses
the same unratelimited pattern, so this is minor.

Since tc_ets_qopt_offload has no extack, would dev_err_ratelimited() or a
once-only print be a better fit here?

> +
> +	/* Only strict bands can be offloaded. */
> +	for (i = 0; i < p->bands; i++) {
> +		if (p->quanta[i]) {
> +			dev_err(priv->dev, "port %d: ETS weighted bands are not supported\n",
> +				port);
> +			return -EOPNOTSUPP;
> +		}
> +	}
> +
> +	/* The switch does not use the priomap. */
> +	return priv->ops->qos_set_port_sched(priv, port, nq, true);
> +}

[Severity: Medium]
Can this report offload for configurations the hardware does not
implement?

Only p->bands and p->quanta[] are checked here. p->priomap is never read,
and the band order is never compared with the order the hardware uses.
Later, TC_ETS_STATS in rtl83xx_port_setup_tc() returns 0 for the stored
handle, so qdisc_offload_dump_helper() sets TCQ_F_OFFLOADED.

In sch_ets, band 0 is the highest priority strict band. The default
priomap sends every priority to the last band:

net/sched/sch_ets.c:ets_qdisc_change() {
    ...
	memset(priomap, nbands - 1, sizeof(priomap));
    ...
}

The hardware maps internal priority to tc, and tc to qid through
rtl8365mb_qos_tc_to_qid(). In strict mode it serves the higher qid first.
The only priomap it actually implements is prio i -> band nq - 1 - tc(i).

For example, with this command the software qdisc gives no
prioritisation, because every priority goes to band 7:

    tc qdisc add dev swpN root ets bands 8 strict 8

The hardware still applies strict priority by internal priority. With
"priomap 0 1 2 3 4 5 6 7", the software order is the reverse of the
hardware order. In both cases tc shows the qdisc as offloaded.

Other TC_SETUP_QDISC_ETS implementers handle the priomap:

- ksz_tc_ets_add() programs priomap[] into KSZ9477_PORT_MRI_TC_MAP. It
  also returns -EOPNOTSUPP for TC_ETS_STATS.
- lan966x_ets_add() and the sparx5 offload reject any priomap except
  priomap[i] == 7 - i.
- airoha checks the priomap against its fixed layout.
- mlxsw programs the priomap.

Is the comment "The switch does not use the priomap." accurate? The
backend has a programmable internal-priority to qid table.
rtl8365mb_qos_qmap_init() fills it through rtl8365mb_qos_set_qmap_qid().
That is the same kind of map ksz drives from the priomap.

Would it be better to program that table from priomap[]? The other option
is to reject priomaps and band orders that do not match the fixed
hardware mapping.

The commit message also says:

    The patch uses ets, not prio. The hardware picks strict priority or
    WFQ per queue, and ets sets the type per band.

Every band with a quantum is refused, so the only accepted configuration
is all-strict, which is what prio expresses. Does this justification only
hold for future work?

> +
> +/* Forget the offloaded ETS qdisc of @port and put the port back on WFQ */
> +static int rtl83xx_setup_tc_ets_restore_wfq(struct dsa_switch *ds, int port)
> +{
> +	struct realtek_priv *priv = ds->priv;
> +	int ret;
> +
> +	priv->ets_handle[port] = 0;
> +
> +	ret = priv->ops->qos_set_port_sched(priv, port, ds->num_tx_queues,
> +					    false);
> +	if (ret)
> +		dev_err(priv->dev, "port %d: failed to restore WFQ: %pe\n",
> +			port, ERR_PTR(ret));
> +
> +	return ret;
> +}

[Severity: Low]
What state is the port left in if qos_set_port_sched() fails here?

ets_handle[port] is cleared before the call, and it stays cleared even if
the call fails. rtl8365mb_qos_write_port_sched() programs one queue at a
time and returns at the first error:

drivers/net/dsa/realtek/rtl8365mb_qos.c:rtl8365mb_qos_write_port_sched() {
    ...
	for (tc = 0; tc < num_queues; tc++) {
		...
		if (!strict) {
			ret = regmap_write(priv->map, wreg, weight);
			if (ret)
				return ret;
		}

		ret = rtl8365mb_qos_regmap_update_field(priv, reg, mask, qtype);
		if (ret)
			return ret;
	}
    ...
}

If an SMI/MDIO access fails partway through, some queues end up WFQ and
the rest stay strict. Consider this sequence:

1. qdisc A is offloaded, and the port is strict.
2. A tc qdisc change on A fails validation. restore_wfq() runs, and a
   register access fails midway. ets_handle[port] is now 0.
3. tc qdisc del sends TC_ETS_DESTROY with handle A.
   rtl83xx_port_setup_tc() then returns early:

	if (ets->handle != priv->ets_handle[port])
		return 0;

The port keeps a mixed strict/WFQ scheduler with no ETS qdisc present.
It only gets back to WFQ after another strict offload and its DESTROY, or
after a re-probe through rtl8365mb_qos_sched_init().

Would it make sense to keep the record until the restore succeeds, so
that the later DESTROY retries it?

> +
> +int rtl83xx_port_setup_tc(struct dsa_switch *ds, int port,
> +			  enum tc_setup_type type, void *type_data)
> +{

[ ... ]

> +	switch (ets->command) {
> +	case TC_ETS_REPLACE:

[ ... ]

> +		priv->ets_handle[port] = ets->handle;
> +
> +		return 0;
> +
> +	case TC_ETS_DESTROY:

[ ... ]

> +		 * With hw-tc-offload off, sch_ets sends no DESTROY, so the
> +		 * port stays strict.
> +		 */
> +		if (ets->handle != priv->ets_handle[port])
> +			return 0;
> +
> +		return rtl83xx_setup_tc_ets_restore_wfq(ds, port);
> +
> +	case TC_ETS_STATS:
> +		/* Report the qdisc as offloaded. tc_ets_qopt_offload carries
> +		 * no extack, so this mark is the only sign in tc that the
> +		 * offload was accepted. The stats stay the software ones. They
> +		 * count only what the host sends on this port, not traffic
> +		 * the switch forwards.
> +		 */
> +		return ets->handle == priv->ets_handle[port] ? 0 : -EOPNOTSUPP;

[Severity: Low]
Can a stale ets_handle[port] mark a qdisc as offloaded that the driver
never validated?

ets_handle[port] is only cleared by a matching DESTROY or by a failed
REPLACE. ets_offload_change() and ets_offload_destroy() both return early
when !tc_can_offload(dev). DSA user ports also have no ndo_set_features
hook to resync this state when NETIF_F_HW_TC is turned back on. Consider
this sequence:

1. With offload on:
       tc qdisc add dev swpN root handle 1: ets bands 8 strict 8
   ets_handle[port] becomes 1:0, and the port is strict.
2. ethtool -K swpN hw-tc-offload off
3. tc qdisc del dev swpN root
   No DESTROY is sent, so ets_handle[port] stays 1:0.
4. tc qdisc add dev swpN root handle 1: ets bands 8 quanta 1500 ...
   No REPLACE is sent, so the driver never sees this configuration.
5. ethtool -K swpN hw-tc-offload on, then tc qdisc show:
   ets_offload_dump()->qdisc_offload_dump_helper() sends TC_ETS_STATS
   with handle 1:0. It returns 0, so TCQ_F_OFFLOADED is set.

tc then marks a weighted qdisc as offloaded, although REPLACE would have
refused it with -EOPNOTSUPP. The hardware still runs the old strict
setup. The same happens after a tc qdisc change on 1: while offload is
off.

The commit message and the DESTROY comment do note that the port may not
follow tc while hw-tc-offload is off. This false offloaded mark, though,
contradicts the STATS comment that it is "the only sign in tc that the
offload was accepted". Is that intended?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124-rtl8365mb-ets-strict-v1-0-6ab01ad545c8%40pengutronix.de

      reply	other threads:[~2026-11-25 10:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 10:20 [PATCH net-next 0/2] net: dsa: realtek: rtl8365mb: offload ETS strict priority Oleksij Rempel
2026-11-24 10:20 ` [PATCH net-next 1/2] net: dsa: realtek: rtl8365mb: default the egress scheduler to WFQ Oleksij Rempel
2026-11-24 10:20 ` [PATCH net-next 2/2] net: dsa: realtek: rtl8365mb: offload ETS strict priority scheduling Oleksij Rempel
2026-11-25 10:23   ` netdev-bot+sashiko [this message]

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=179560221157.3135.10940899213423821559@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=alvin.sipraga@analog.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kernel@pengutronix.de \
    --cc=kuba@kernel.org \
    --cc=linusw@kernel.org \
    --cc=luizluca@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=o.rempel@pengutronix.de \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.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