From: sashiko-bot@kernel.org
To: "Fil Dunsky" <filipp.dunsky@gmail.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH RFC net-next 5/7] net: dsa: qca8k: select the four-byte format before port activation
Date: Thu, 26 Nov 2026 20:54:30 +0000 [thread overview]
Message-ID: <sashiko-outbox-236174@kernel.org> (raw)
In-Reply-To: <20261125-almondplus-offload-rfc-v1-5-703175c6340c@gmail.com>
Thank you for your contribution! Sashiko AI review found 7 potential
issues to consider:
- [High] net: dsa: qca8k: pre-open MTU change desynchronizes conduits
and wedges switch
- [High] net: dsa: qca8k: lock inversion between persistent_lock and
live_lock on open
- [High] net: dsa: qca8k: missing change_tag_protocol op rejects qca4 DT
probe
- [Medium] net: dsa: qca8k: qca8k_persistent_first_user_locked() replays
CPU MACs when ready
- [Medium] net: dsa: qca8k: qca8k_port_enable() ignores
qca8k_persistent_port_status() error
- [Low] net: dsa: qca8k: unused transaction helpers in persistent_qca4.h
duplicated
- [Low] net: dsa: qca8k: false fault on remove in
qca8k_persistent_remove()
--
commit b0b6c968f61aca7939b30eea79316b5b27dbbff1
Author: Fil Dunsky <filipp.dunsky@gmail.com>
net: dsa: qca8k: select the four-byte format before port activation
This commit adds opt-in support for selecting and verifying the four-byte
QCA4 header format on dual-conduit CS7542 QCA8337 switches before user
port activation, and restores the two-byte header format on teardown.
> diff --git a/drivers/net/dsa/qca/persistent_qca4.h b/drivers/net/dsa/qca/persistent_qca4.h
> new file mode 100644
> index 0000000000000..6e4dc21622748
> --- /dev/null
> +++ b/drivers/net/dsa/qca/persistent_qca4.h
> @@ -0,0 +1,178 @@
[ ... ]
> +struct qca4_persistent_ops {
> + void *context;
> + int (*quiesce)(void *context);
> + int (*stop_all_macs)(void *context);
> + int (*read_global)(void *context, qca4_word *value);
> + int (*read_cpu_header)(void *context, unsigned int cpu_port,
> + qca4_word *value);
> + int (*set_global)(void *context, qca4_word value, bool restore,
> + bool *verified);
> + int (*software_ready)(void *context);
> + int (*replay_cpu_enables)(void *context);
> +};
[ ... ]
> +static inline int qca4_persistent_restore(struct qca4_persistent_state *state,
> + struct qca4_persistent_ops *ops)
[ ... ]
> +static inline int qca4_persistent_begin(struct qca4_persistent_state *state,
> + struct qca4_persistent_ops *ops,
> + bool opt_in)
[ ... ]
> +static inline int qca4_persistent_ready(struct qca4_persistent_state *state,
> + struct qca4_persistent_ops *ops)
[Severity: Low]
This isn't a bug, but struct qca4_persistent_ops, qca4_persistent_restore(),
qca4_persistent_begin(), and qca4_persistent_ready() are never called.
Instead, qca8k-persistent-boot.inc and qca8k-persistent-lifecycle.inc
open-code the same state transitions directly on priv->persistent_boot.
> diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c
> index 382753bcc466a..3e120ddaa684c 100644
> --- a/drivers/net/dsa/qca/qca8k-8xxx.c
> +++ b/drivers/net/dsa/qca/qca8k-8xxx.c
[ ... ]
> @@ -2032,6 +2094,9 @@ static const struct phylink_mac_ops qca8k_phylink_mac_ops = {
>
> static const struct dsa_switch_ops qca8k_switch_ops = {
> .get_tag_protocol = qca8k_get_tag_protocol,
> +#if IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE)
> + .teardown = qca8k_persistent_dsa_teardown,
> +#endif
> .setup = qca8k_setup,
[Severity: High]
Does probing with dsa-tag-protocol = "qca4" in the device tree always fail
with -EINVAL because qca8k_switch_ops has no .change_tag_protocol callback?
qca8k_persistent_boot_admit() requires dsa-tag-protocol = "qca4" on every
CPU port node to enable four-byte mode. When dsa_register_switch() ->
dsa_port_parse_of() -> dsa_port_parse_cpu() sees that property on a CPU
port, it checks ds->ops->change_tag_protocol before comparing the protocol
against ds->ops->get_tag_protocol(), and aborts probe with -EINVAL when the
callback is NULL.
> diff --git a/drivers/net/dsa/qca/qca8k-common.c b/drivers/net/dsa/qca/qca8k-common.c
> index ab978cc8367f7..2f690593e913e 100644
> --- a/drivers/net/dsa/qca/qca8k-common.c
> +++ b/drivers/net/dsa/qca/qca8k-common.c
> @@ -741,6 +751,31 @@ int qca8k_port_enable(struct dsa_switch *ds, int port,
> struct phy_device *phy)
> {
> struct qca8k_priv *priv = ds->priv;
> +#if IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE)
> + int ret;
> +
> + if (READ_ONCE(priv->persistent_boot.requested) &&
> + dsa_is_cpu_port(ds, port)) {
> + mutex_lock(&priv->persistent_lock);
> + if (!priv->persistent_boot.ready) {
> + priv->persistent_cpu_requested |= BIT(port);
> + priv->port_enabled_map |= BIT(port);
> + mutex_unlock(&priv->persistent_lock);
> + return 0;
> + }
> + mutex_unlock(&priv->persistent_lock);
> + }
> + if (dsa_is_user_port(ds, port)) {
> + ret = qca8k_persistent_first_user(priv);
> + if (ret)
> + return ret;
> + }
> +
> +#endif
> +
> + if (IS_ENABLED(CONFIG_NET_DSA_QCA8K_4B_MODE) &&
> + READ_ONCE(priv->private_open_blocked))
> + return -EIO;
>
> qca8k_port_set_status(priv, port, 1);
> priv->port_enabled_map |= BIT(port);
[Severity: Medium]
Can qca8k_port_enable() return 0 and mark the port enabled when
qca8k_persistent_port_status() fails inside qca8k_port_set_status()?
If the MDIO update or readback verification in qca8k_persistent_port_status()
fails, it sets priv->private_open_blocked = true, latches the error, and
stops both CPU MACs. Because qca8k_port_set_status() returns void and
qca8k_port_enable() only checks priv->private_open_blocked beforehand,
qca8k_port_enable() still sets priv->port_enabled_map |= BIT(port) and
returns success to DSA with the switch halted.
> diff --git a/drivers/net/dsa/qca/qca8k-persistent-boot.inc b/drivers/net/dsa/qca/qca8k-persistent-boot.inc
> new file mode 100644
> index 0000000000000..88638bb533570
> --- /dev/null
> +++ b/drivers/net/dsa/qca/qca8k-persistent-boot.inc
> @@ -0,0 +1,632 @@
[ ... ]
> +static int qca8k_persistent_change_mtu_locked(struct qca8k_priv *priv, int port,
> + int mtu)
> +{
> + struct qca4_persistent_mtu_ops ops = qca8k_persistent_mtu_ops(priv);
> + struct dsa_port *user;
> + unsigned int largest = ETH_DATA_LEN;
> + bool blocked;
> + int ret = 0;
> +
> + ASSERT_RTNL();
> + if (!dsa_is_user_port(priv->ds, port) &&
> + !dsa_is_cpu_port(priv->ds, port))
> + return -EOPNOTSUPP;
> + if (mtu <= 0 || mtu > QCA8K_MAX_MTU)
> + return -EINVAL;
> + lockdep_assert_held(&priv->persistent_lock);
> + if (priv->persistent_closing || priv->persistent_boot.first_error ||
> + priv->persistent_mtu.pending || priv->persistent_mtu.unknown) {
> + ret = -EUCLEAN;
> + goto unlock;
> + }
> + /*
> + * Early DSA allocation has not yet published both conduits. First-open
> + * readiness performs the initial checked transaction before MAC replay.
> + */
> + if (!priv->persistent_boot.ready)
> + goto unlock;
[Severity: High]
Can changing a user port MTU after switch registration but before the first
user port is opened desynchronize the two conduits and permanently wedge the
switch on open?
When userspace changes a user port MTU while all user ports are still down,
dsa_user_change_mtu() updates the assigned conduit (conduit 0) to
largest_mtu + 4 before calling qca8k_port_change_mtu(). Because
priv->persistent_boot.ready is still false,
qca8k_persistent_change_mtu_locked() returns 0 here without clamping
conduit 0 to ETH_DATA_LEN + 4 or updating conduit 6.
If the user port MTUs are lowered below 1500 before the first open (leaving
conduit 0 below 1504), qca8k_persistent_first_user_locked() calls
qca8k_persistent_software_ready() before qca4_pmtu_change().
qca8k_persistent_software_ready() checks cpu->conduit->mtu >= 1504, fails
with -EMSGSIZE, and jumps to failed:, latching
priv->persistent_boot.first_error and blocking all future port opens. If a
user port MTU is raised above 1500 before first open, conduit 0 is raised
while conduit 6 stays at 1504, so the initial qca4_pmtu_change() snapshots a
mismatched pair into state->saved[].
[ ... ]
> +static int qca8k_persistent_first_user_locked(struct qca8k_priv *priv)
> +{
> + unsigned int port;
> + u32 value;
> + int ret;
> +
> + if (!priv->persistent_boot.requested)
> + return 0;
> + ASSERT_RTNL();
> + if (priv->persistent_closing || !priv->persistent_boot.hardware4 ||
> + priv->persistent_boot.unknown || priv->persistent_boot.first_error)
> + return -EIO;
[Severity: Medium]
Should qca8k_persistent_first_user_locked() return 0 immediately when
priv->persistent_boot.ready is already true?
qca8k_port_enable() calls qca8k_persistent_first_user() on every user port
open. Without an early return once ready is true, bringing up a second user
port re-runs qca8k_persistent_replay_cpus() and rewrites
QCA8K_REG_PORT_STATUS(0) and QCA8K_REG_PORT_STATUS(6) over MDIO while traffic
is active and after priv->persistent_fe_held has already been released.
> + ret = qca8k_persistent_software_ready(priv, !priv->persistent_mtu.committed_valid);
> + /*
> + * A netdev can be published before the complete DSA tree. This is a
> + * pre-I/O readiness refusal, not an I/O fault or a permanent latch.
> + */
> + if (ret == -EAGAIN)
> + return ret;
> + if (ret)
> + goto failed;
> + if (priv->persistent_status_valid != (BIT(0) | BIT(6)))
> + return -EAGAIN;
> + ret = qca8k_read_mii(priv, QCA8K_REG_GLOBAL_HDR_CTRL, &value);
> + if (!ret && (value & QCA4_PERSISTENT_MASK) != QCA4_PERSISTENT_VALUE)
> + ret = -EUCLEAN;
> + for (port = 0; !ret && port <= 6; port += 6) {
> + ret = qca8k_read_mii(priv, QCA8K_REG_PORT_HDR_CTRL(port),
> + &value);
> + if (!ret && value != QCA4_PERSISTENT_CPU_HEADER)
> + ret = -EUCLEAN;
> + }
> + if (!ret && !priv->persistent_mtu.committed_valid) {
> + struct qca4_persistent_mtu_ops ops =
> + qca8k_persistent_mtu_ops(priv);
> + struct dsa_port *user;
> + unsigned int largest = ETH_DATA_LEN;
> +
> + dsa_switch_for_each_user_port(user, priv->ds)
> + if (user->user)
> + largest = max_t(unsigned int, largest,
> + user->user->mtu);
> + ret = qca4_pmtu_change(&priv->persistent_mtu, &ops, largest + 4,
> + largest + ETH_HLEN + ETH_FCS_LEN);
> + }
> + if (!ret)
> + ret = qca8k_persistent_software_ready(priv, false);
> + if (!ret)
> + ret = qca8k_persistent_replay_cpus(priv);
> + if (ret)
> + goto failed;
> + if (priv->persistent_fe_held) {
> + ret = cs7542_ft_live_format_release();
> + if (ret)
> + goto failed;
> + priv->persistent_fe_held = false;
> + }
[Severity: High]
Does calling cs7542_ft_live_format_release() under priv->persistent_lock
invert the lock ordering against live_lock?
CPU0 CPU1
---- ----
lock(&priv->persistent_lock)
lock(&live_lock)
lock(&live_lock)
lock(&priv->persistent_lock)
*** DEADLOCK ***
CPU0: qca8k_port_enable() -> qca8k_persistent_first_user() ->
qca8k_persistent_first_user_locked() -> cs7542_ft_live_format_release()
CPU1: live_rule() -> provider_ops->rule() -> ... -> qca8k_persistent_status()
Unlike qca8k_persistent_detach_complete(), which drops priv->persistent_lock
around cs7542_ft_live_format_release(), qca8k_persistent_first_user_locked()
calls it while holding priv->persistent_lock.
> diff --git a/drivers/net/dsa/qca/qca8k-persistent-lifecycle.inc b/drivers/net/dsa/qca/qca8k-persistent-lifecycle.inc
> new file mode 100644
> index 0000000000000..bd7892b80aba0
> --- /dev/null
> +++ b/drivers/net/dsa/qca/qca8k-persistent-lifecycle.inc
> @@ -0,0 +1,394 @@
[ ... ]
> +static void qca8k_persistent_remove(struct qca8k_priv *priv)
> +{
> + int completed;
> +
> + rtnl_lock();
> + qca8k_persistent_unwind(priv, 0);
> + rtnl_unlock();
> + dsa_unregister_switch(priv->ds);
> + rtnl_lock();
> + completed = qca8k_persistent_detach_complete(priv);
> + if (completed)
> + qca8k_persistent_note_fault(priv, completed);
> + rtnl_unlock();
> +}
[Severity: Low]
Can qca8k_persistent_remove() log and latch a false -EBUSY fault if the
switch is removed before qca8k_persistent_boot_start() sets
priv->persistent_setup_started?
Unlike qca8k_persistent_unwind() and qca8k_persistent_register_complete(),
qca8k_persistent_remove() does not check priv->persistent_setup_started
before calling qca8k_persistent_detach_complete(). If qca8k_setup() never
ran or failed in qca8k_persistent_profile(), qca8k_persistent_unwind()
returns early, leaving qca8k_persistent_can_release() false, so
qca8k_persistent_detach_complete() returns -EBUSY and triggers
qca8k_persistent_note_fault().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125-almondplus-offload-rfc-v1-0-703175c6340c@gmail.com?part=5
next prev parent reply other threads:[~2026-11-26 20:54 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 20:50 [PATCH RFC net-next 0/7] net: cortina: CS7542 wired IPv4 hardware flowtable offload Fil Dunsky via B4 Relay
2026-11-25 20:50 ` [PATCH RFC net-next 1/7] dt-bindings: net: dsa: allow the QCA four-byte tag protocol Fil Dunsky via B4 Relay
2026-11-25 20:50 ` [PATCH RFC net-next 2/7] net: dsa: add a QCA four-byte CPU tagger Fil Dunsky via B4 Relay
2026-11-25 21:15 ` Andrew Lunn
2026-11-26 20:54 ` sashiko-bot
2026-11-25 20:50 ` [PATCH RFC net-next 3/7] netfilter: flowtable: expose route MTU and established TCP context Fil Dunsky via B4 Relay
2026-11-25 20:50 ` [PATCH RFC net-next 4/7] net: cortina: add a serialized CS7542 forwarding engine owner Fil Dunsky via B4 Relay
2026-11-26 20:54 ` sashiko-bot
2026-11-25 20:50 ` [PATCH RFC net-next 5/7] net: dsa: qca8k: select the four-byte format before port activation Fil Dunsky via B4 Relay
2026-11-25 21:13 ` Andrew Lunn
2026-11-26 20:54 ` sashiko-bot [this message]
2026-11-25 20:50 ` [PATCH RFC net-next 6/7] net: cortina: connect wired IPv4 NAT to nftables hardware flowtables Fil Dunsky via B4 Relay
2026-11-26 20:54 ` sashiko-bot
2026-11-25 20:50 ` [PATCH RFC net-next 7/7] docs: networking: describe the CS7542 flowtable RFC limits Fil Dunsky via B4 Relay
2026-11-26 20:54 ` sashiko-bot
2026-11-25 21:10 ` [PATCH RFC net-next 0/7] net: cortina: CS7542 wired IPv4 hardware flowtable offload Andrew Lunn
2026-11-25 21:55 ` Fil Dunsky
2026-11-25 22:10 ` Andrew Lunn
2026-11-25 22:56 ` Fil Dunsky
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=sashiko-outbox-236174@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=filipp.dunsky@gmail.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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