Skip to contentSkip to conversation

octeontx2: mqprio bandwidth offload for NIX TX schedulers

PATCH In review Ratheesh Kannoth 4 participants 10 messages Nov 9 – Nov 14

Subsystems (4)
lore
Share & tools
lore

Ratheesh Kannoth

author maintainer
#0 lore raw

v21 cover octeontx2: mqprio bandwidth offload for NIX TX schedulers

This series adds hardware offload for channel-mode mqprio with TC_MQPRIO_SHAPER_BW_RATE on Marvell octeontx2/cn10k PF and VF RVU netdevices. Each non-QoS transmit queue is shaped by programming MDQ CIR/PIR on the NIX TX scheduler. When bandwidth offload is active, the driver allocates one SMQ per queue, parents every MDQ under TL4[0], and maps each traffic class min/max rate to the queue(s) in that class.

The NIX TX scheduler hierarchy cannot be reprogrammed live today, so mqprio add, replace, delete, and failed-replace rollback rebuild it by bouncing the netdev through ndo_stop()/ndo_open(). That intentionally drops in-flight traffic on each change. otx2_mqprio_restart_netdev() clears __LINK_STATE_START before ndo_stop() and does not call dev_deactivate()/dev_activate(); carrier and TX queues are restored after ndo_open() via the normal link-event path when the link is up. Cache the active rates and restore MDQ shapers from otx2_mqprio_up() during ndo_open(); fail closed if restoration fails, leaving ndo_open() unsuccessful and the interface administratively down.

Track mqprio configuration in mq_offload_snap snapshots (TC layout and rates). On tc qdisc replace, stage the new configuration while keeping the previous snapshot for rollback: failed setup restores the old snapshot via netdev restart when the interface is running, successful graft is recorded through TC_ROOT_GRAFT, and teardown of the replaced qdisc instance commits the staged snapshot without tearing down the live offload.

Patch 1 converts PF/VF and representor flag access to atomic bitops. Patch 2 depends on it for safe OTX2_FLAG_INTF_DOWN and OTX2_FLAG_PORT_UP updates on asynchronous mbox paths and during the mqprio netdev bounce.

The driver rejects offload unless the interface is running and the device advertises CIR+PIR support. PF and VF RVU netdevices share the same TC offload path via ndo_setup_tc / otx2_open(); SDP representors are not supported. Per-TC rates are rejected when a traffic class spans more than one queue. Concurrent PFC, XDP, SDP rep, or HTB use is blocked, and ethtool channel count changes are blocked while mqprio bandwidth offload is active.

Ratheesh Kannoth (2):
octeontx2: use atomic bitops for PF/VF and rep flags
octeontx2: add mqprio bandwidth offload for NIX TX schedulers

 .../ethernet/marvell/octeontx2/nic/cn10k_ipsec.c   |   8 +-
 .../ethernet/marvell/octeontx2/nic/otx2_common.c   | 154 +++-
 .../ethernet/marvell/octeontx2/nic/otx2_common.h   | 107 ++-
 .../ethernet/marvell/octeontx2/nic/otx2_dcbnl.c    |   6 +
 .../ethernet/marvell/octeontx2/nic/otx2_devlink.c  |   2 +-
 .../ethernet/marvell/octeontx2/nic/otx2_ethtool.c  |  29 +-
 .../ethernet/marvell/octeontx2/nic/otx2_flows.c    |  34 +-
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   |  95 ++-
 .../net/ethernet/marvell/octeontx2/nic/otx2_tc.c   | 838 ++++++++++++++++++++-
 .../net/ethernet/marvell/octeontx2/nic/otx2_txrx.c |  16 +-
 .../net/ethernet/marvell/octeontx2/nic/otx2_vf.c   |  10 +-
 .../net/ethernet/marvell/octeontx2/nic/otx2_xsk.c  |   4 +-
 drivers/net/ethernet/marvell/octeontx2/nic/qos.c   |  11 +
 .../net/ethernet/marvell/octeontx2/nic/qos_sq.c    |   4 +-
 drivers/net/ethernet/marvell/octeontx2/nic/rep.c   |  32 +-
 drivers/net/ethernet/marvell/octeontx2/nic/rep.h   |   3 +-
 16 files changed, 1203 insertions(+), 150 deletions(-)

---
v20 -> v21: Resend

	https://lore.kernel.org/netdev/[email protected]/

v19 -> v20: Addressed sashiko and Paolo comments on v19.
- Fix the deferred netdev_tc_work use-after-free on removal: set defer_tc_work under rtnl_lock() in otx2_shutdown_tc_mqprio() (the work is only queued from ndo_setup_tc() with RTNL held) and run cancel_work_sync() after rtnl_unlock(); drop the lockless early check in the work handler.
- Always release mqprio software state in otx2_mqprio_down() when clearing the hardware shapers fails (the core cannot veto qdisc teardown); the following netdev restart reallocates the TX scheduler and drops any stale shaper. The error is still reported to the user.
- Drop the ethtool -L check that rejected TX queue reduction while old_mq_snap/cur_mq_snap exist; it blocked channel changes forever after an mqprio qdisc was deleted. Channel changes remain blocked while mqprio offload is active.
- Warn when tearing down an offloaded mqprio clears the TC layout installed by a replacing software taprio root qdisc.
- Say "bringing interface down" in the error printed when ndo_open() fails during an mqprio restart, and correct the netif_close()/dev_close() comment; drop the "in-flight traffic will be dropped" wording from the restart debug message.

	https://lore.kernel.org/netdev/[email protected]/

v18 -> v19: Addressed sashiko and review nits on v18.
- Gate mqprio netdev_tc_work with defer_tc_work: set the flag before cancel_work_sync() in otx2_shutdown_tc_mqprio() and skip scheduling or running the deferred TC restore work once teardown starts (Sashiko #1).
= Address Jakub comment.
- Clarify the otx2_mqprio_restart_netdev() comment on failed ndo_open():
__LINK_STATE_START stays clear until open succeeds, so netif_running() is false on that path

	https://lore.kernel.org/netdev/[email protected]/

v17 -> v18: Addressed sashiko comments on v17.
- Commit staged mqprio replace snapshots when TC_ROOT_GRAFT is skipped because hw-tc-offload is off in netdev->features (!tc_can_offload()), instead of rolling back a replace that actually succeeded.
- Keep NETIF_F_HW_TC in netdev->hw_features only (PF and VF); gate mqprio setup/teardown on otx2_tc_can_offload() so hw-tc-offload stays opt-in via ethtool -K and flower/matchall are not pushed to ndo_setup_tc by default.
- Split TC shutdown around netdev unregister: cancel mqprio deferred work and free mqprio snapshots before unregister_netdev(), but destroy the TC flower flow list only after unregister so clsact teardown can still run otx2_tc_del_flow() and free MCAM/mcast/policer state.
- Reject ethtool -L TX queue reduction while mqprio offload snapshots remain, so a later replace rollback cannot restore stale per-queue rates past the current queue count.
- Clarify mqprio shaper and netdev-restart comments: ndo_open() may restore cached MDQ shapers via otx2_mqprio_up() before setup clears them, and a failed mqprio restart relies on OTX2_FLAG_INTF_DOWN so otx2_stop() returns early through netif_close(), not on skipping ndo_stop().

	https://lore.kernel.org/netdev/[email protected]/

v16 -> v17: Addressed sashiko comments on v16.
- Replace the per-bit otx2_sync_flags_from_rep() loop with a masked READ_ONCE/WRITE_ONCE publish of OTX2_REP_SYNC_FLAGS_MASK so lockless NAPI readers never observe torn PF/representor flag combinations.
- Evaluate mqprio.rate_limit and old_mq_snap inside rtnl_lock in otx2_mqprio_netdev_tc_work() so a concurrent qdisc delete cannot leave stale netdev TC mappings after offload teardown.
- Advertise NETIF_F_HW_TC in netdev->features (PF and VF) when TC flower offload is supported, so tc_can_offload() succeeds without ethtool -K hw-tc-offload on; move otx2_init_tc() before register_netdev() and fix probe/remove teardown ordering.
- Reject mqprio add when a software mqprio root is already installed (otx2_mqprio_keep_netdev_tc()) and defer netdev TC restore from a new fail_validate path on failed replace validation before any hardware change.
- Fix otx2_mqprio_max_rate_bytes_ps() to cap against the NIX TLX maximum rate instead of the burst-bucket size; use the 65536 byte HTB default burst when programming MDQ shapers; guard otx2_get_smq_idx() when txschq_cnt[NIX_TXSCH_LVL_SMQ] is zero after otx2_txschq_stop().
- Rename patch 2 to octeontx2: (driver-wide PF/VF offload, not PF-only).

	https://lore.kernel.org/netdev/[email protected]/

v15 -> v16: Addressed sashiko comments on v15 and aligned documentation with code.
- Sync representor flags through OTX2_FLAG_MAX in otx2_sync_flags_from_rep() instead of hard-coding OTX2_REP_VF_INITIALIZED as the loop bound.
- Drop the rvu_nix.c is_valid_txschq() ratelimited error print from the mqprio patch; remove the misplaced atomic-bitops and AF-debug paragraphs from the mqprio commit message (they belong to patch 1 or are out of scope).
- Extend mq_offload_snap to record prio_tc_map[] and mqprio rate flags; restore the full netdev TC layout (num_tc, queue ranges, and priority map) via otx2_mqprio_apply_snap_netdev() on rollback paths.
- Defer netdev TC restore on failed replace (otx2_mqprio_netdev_tc_work) so rollback survives mqprio_destroy() clearing dev->num_tc after setup errors once the core unwinds the failed qdisc instance.
- Stop calling dev_deactivate()/dev_activate() from otx2_mqprio_restart_netdev(); bounce the interface with ndo_stop()/ndo_open() only and restore carrier through the normal link-event path after ndo_open(), avoiding qdisc reentrancy during tc replace graft.
- Preserve netdev TC mappings when tearing down an offloaded instance that is replaced by a software mqprio graft (otx2_mqprio_keep_netdev_tc()) instead of always calling netdev_set_num_tc(0) and breaking the live replacement.
- Return an error from otx2_mqprio_down() when clearing hardware shapers fails and keep offload software state, instead of v15's behaviour of clearing rate_limit while stale MDQ limits may remain programmed.
- Rebuild the TX scheduler via netdev restart in otx2_mqprio_restore_old() on a running interface after failed-replace rollback so partially applied MDQ shapers are not left running with mismatched software state.
- Clear txschq_cnt[] in otx2_txschq_stop() after freeing scheduler nodes so post-stop shaper mailbox operations do not consult stale counts.
- Document fail-closed ndo_open() when otx2_mqprio_up() cannot restore shapers, and that PF/VF RVU netdevices share the ndo_setup_tc / otx2_open() offload path (SDP representors remain unsupported); downgrade the mqprio restart notice to netdev_dbg().

	https://lore.kernel.org/netdev/[email protected]/

v14 -> v15: Addressed sashiko comments.
- Split atomic PF/VF and representor flag access into a preparatory patch so mqprio netdev-restart and mbox paths can update OTX2_FLAG_INTF_DOWN and OTX2_FLAG_PORT_UP without data races on the shared flags word.
- Clear mqprio software state when hardware shaper teardown fails, warn, and still bounce the netdev on delete so offload does not remain stuck active after a mailbox error.

	https://lore.kernel.org/netdev/[email protected]/

v13 -> v14: Addressed sashiko comments.
- Use atomic set_bit()/clear_bit() for OTX2_FLAG_INTF_DOWN and OTX2_FLAG_PORT_UP updates on netdev-restart and mbox paths.
- Block concurrent mqprio bandwidth offload and HTB shaping.
- Fail ndo_open() if otx2_mqprio_up() cannot restore MDQ shapers.
- Rebuild the TX scheduler via netdev restart in otx2_mqprio_restore_old() when rolling back a failed replace on a running interface.
- Return an error from otx2_mqprio_down() if clearing hardware shapers fails instead of clearing software state anyway.

	https://lore.kernel.org/netdev/[email protected]/

v12 -> v13: Addressed sashiko comments.

	https://sashiko.dev/#/patchset/20260903023324.3078284-1-rkannoth%40marvell.com

v11 -> v12: Addressed sashiko comments.

	https://sashiko.dev/#/patchset/20260902015500.2985371-1-rkannoth%40marvell.com
v10 -> v11: Addressed sashiko comments.
	https://sashiko.dev/#/patchset/20260831131014.2639581-1-rkannoth%40marvell.com

v9 -> v10: Addressed sashiko/jacub comments.

	https://sashiko.dev/#/message/20260817032747.1765883-1-rkannoth%40marvell.com

v8 -> v9: Addressed Sashiko comments
https://lore.kernel.org/netdev/aoJ6FhtWue0FHDQV@rkannoth-OptiPlex-7090/
v7 -> v8: Addressed Sashiko comments

	https://sashiko.dev/#/patchset/20260811085050.3212280-1-rkannoth%40marvell.com
v6 -> v7: Addressed Sashiko comments
	https://sashiko.dev/#/message/20260810034738.1786029-1-rkannoth%40marvell.com
v5 -> v6: Addressed Sashiko comments
	https://lore.kernel.org/netdev/[email protected]/
v4 -> v5: Addressed sashiko comments
	https://sashiko.dev/#/patchset/20260803042724.3380209-1-rkannoth%40marvell.com
v3 -> v4: Addressed sashiko comments
	https://lore.kernel.org/netdev/[email protected]/
v2 -> v3: Addressed sashiko comments
	https://lore.kernel.org/netdev/amnYX866mYx02cBe@rkannoth-OptiPlex-7090/T/#m67310cbec48b21c7720858ab3a1ea083a0f8dc10
v1 -> v2: Addressed sashiko comments
	https://lore.kernel.org/netdev/[email protected]/

--
2.43.0

author maintainer
#1 lore raw

PATCH v21 1/2 octeontx2: use atomic bitops for PF/VF and rep flags

Switch PF/VF and representor flags from non-atomic u64 masks to unsigned long bitmaps with set_bit/clear_bit/test_bit. Add helpers and otx2_sync_flags_from_rep() to publish representor-owned flags onto the PF mailbox context with a masked WRITE_ONCE, giving lockless NAPI readers a consistent word without clearing PF-owned bits.

Relocate representor VF initialization to OTX2_FLAG_REP_VF_INITIALIZED (bit 21).

---
 .../marvell/octeontx2/nic/cn10k_ipsec.c       |  8 +-
 .../marvell/octeontx2/nic/otx2_common.c       |  8 +-
 .../marvell/octeontx2/nic/otx2_common.h       | 84 ++++++++++++++-----
 .../marvell/octeontx2/nic/otx2_devlink.c      |  2 +-
 .../marvell/octeontx2/nic/otx2_ethtool.c      | 21 ++---
 .../marvell/octeontx2/nic/otx2_flows.c        | 34 ++++----
 .../ethernet/marvell/octeontx2/nic/otx2_pf.c  | 78 ++++++++---------
 .../ethernet/marvell/octeontx2/nic/otx2_tc.c  | 30 +++----
 .../marvell/octeontx2/nic/otx2_txrx.c         | 16 ++--
 .../ethernet/marvell/octeontx2/nic/otx2_vf.c  | 10 +--
 .../ethernet/marvell/octeontx2/nic/otx2_xsk.c |  4 +-
 .../ethernet/marvell/octeontx2/nic/qos_sq.c   |  4 +-
 .../net/ethernet/marvell/octeontx2/nic/rep.c  | 32 +++----
 .../net/ethernet/marvell/octeontx2/nic/rep.h  |  3 +-
 14 files changed, 185 insertions(+), 149 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/cn10k_ipsec.c +4 -4
index 443435608781..6ba1b91fdebc 100644
@@ -334,7 +334,7 @@ static int cn10k_outb_cpt_init(struct net_device *netdev)
 						CN10K_CPT_LF_NQX(0));
 
 	/* Set ipsec offload enabled for this device */
-	pf->flags |= OTX2_FLAG_IPSEC_OFFLOAD_ENABLED;
+	otx2_set_flag(pf, OTX2_FLAG_IPSEC_OFFLOAD_ENABLED);
 
 	cn10k_cpt_device_set_available(pf);
 	return 0;
@@ -356,7 +356,7 @@ static int cn10k_outb_cpt_clean(struct otx2_nic *pf)
 	}
 
 	/* Set ipsec offload disabled for this device */
-	pf->flags &= ~OTX2_FLAG_IPSEC_OFFLOAD_ENABLED;
+	otx2_clear_flag(pf, OTX2_FLAG_IPSEC_OFFLOAD_ENABLED);
 
 	/* Disable CPTLF Instruction Queue (IQ) */
 	cn10k_outb_cptlf_iq_disable(pf);
@@ -820,7 +820,7 @@ void cn10k_ipsec_clean(struct otx2_nic *pf)
 	if (!is_dev_support_ipsec_offload(pf->pdev))
 		return;
 
-	if (!(pf->flags & OTX2_FLAG_IPSEC_OFFLOAD_ENABLED))
+	if (!otx2_test_flag(pf, OTX2_FLAG_IPSEC_OFFLOAD_ENABLED))
 		return;
 
 	if (pf->ipsec.sa_workq) {
@@ -945,7 +945,7 @@ bool cn10k_ipsec_transmit(struct otx2_nic *pf, struct netdev_queue *txq,
 	u16 dlen;
 
 	/* Check for IPSEC offload enabled */
-	if (!(pf->flags & OTX2_FLAG_IPSEC_OFFLOAD_ENABLED))
+	if (!otx2_test_flag(pf, OTX2_FLAG_IPSEC_OFFLOAD_ENABLED))
 		goto drop;
 
 	sp = skb_sec_path(skb);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +4 -4
index c85436457286..f4047b0d5d96 100644
@@ -220,10 +220,10 @@ int otx2_set_mac_address(struct net_device *netdev, void *p)
 		eth_hw_addr_set(netdev, addr->sa_data);
 		/* update dmac field in vlan offload rule */
 		if (netif_running(netdev) &&
-		    pfvf->flags & OTX2_FLAG_RX_VLAN_SUPPORT)
+		    otx2_test_flag(pfvf, OTX2_FLAG_RX_VLAN_SUPPORT))
 			otx2_install_rxvlan_offload_flow(pfvf);
 		/* update dmac address in ntuple and DMAC filter list */
-		if (pfvf->flags & OTX2_FLAG_DMACFLTR_SUPPORT)
+		if (otx2_test_flag(pfvf, OTX2_FLAG_DMACFLTR_SUPPORT))
 			otx2_dmacflt_update_pfmac_flow(pfvf);
 	} else {
 		return -EPERM;
@@ -275,8 +275,8 @@ int otx2_config_pause_frm(struct otx2_nic *pfvf)
 		goto unlock;
 	}
 
-	req->rx_pause = !!(pfvf->flags & OTX2_FLAG_RX_PAUSE_ENABLED);
-	req->tx_pause = !!(pfvf->flags & OTX2_FLAG_TX_PAUSE_ENABLED);
+	req->rx_pause = otx2_test_flag(pfvf, OTX2_FLAG_RX_PAUSE_ENABLED);
+	req->tx_pause = otx2_test_flag(pfvf, OTX2_FLAG_TX_PAUSE_ENABLED);
 	req->set = 1;
 
 	err = otx2_sync_mbox_msg(&pfvf->mbox);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +62 -22

102 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_devlink.c +1 -1
index 4a5ce0e67dda..863a5ced9a26 100644
@@ -104,7 +104,7 @@ static int otx2_dl_ucast_flt_cnt_validate(struct devlink *devlink, u32 id,
 	struct otx2_nic *pfvf = otx2_dl->pfvf;
 
 	/* Check for UNICAST filter support*/
-	if (!(pfvf->flags & OTX2_FLAG_UCAST_FLTR_SUPPORT)) {
+	if (!otx2_test_flag(pfvf, OTX2_FLAG_UCAST_FLTR_SUPPORT)) {
 		NL_SET_ERR_MSG_MOD(extack,
 				   "Unicast filter not enabled");
 		return -EINVAL;
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +9 -12
index a05dee0085a3..4fe473d9ea0d 100644
@@ -354,14 +354,14 @@ static int otx2_set_pauseparam(struct net_device *netdev,
 		return -EOPNOTSUPP;
 
 	if (pause->rx_pause)
-		pfvf->flags |= OTX2_FLAG_RX_PAUSE_ENABLED;
+		otx2_set_flag(pfvf, OTX2_FLAG_RX_PAUSE_ENABLED);
 	else
-		pfvf->flags &= ~OTX2_FLAG_RX_PAUSE_ENABLED;
+		otx2_clear_flag(pfvf, OTX2_FLAG_RX_PAUSE_ENABLED);
 
 	if (pause->tx_pause)
-		pfvf->flags |= OTX2_FLAG_TX_PAUSE_ENABLED;
+		otx2_set_flag(pfvf, OTX2_FLAG_TX_PAUSE_ENABLED);
 	else
-		pfvf->flags &= ~OTX2_FLAG_TX_PAUSE_ENABLED;
+		otx2_clear_flag(pfvf, OTX2_FLAG_TX_PAUSE_ENABLED);
 
 	return otx2_config_pause_frm(pfvf);
 }
@@ -470,8 +470,7 @@ static int otx2_get_coalesce(struct net_device *netdev,
 	cmd->rx_max_coalesced_frames = hw->cq_ecount_wait;
 	cmd->tx_coalesce_usecs = hw->cq_time_wait;
 	cmd->tx_max_coalesced_frames = hw->cq_ecount_wait;
-	if ((pfvf->flags & OTX2_FLAG_ADPTV_INT_COAL_ENABLED) ==
-			OTX2_FLAG_ADPTV_INT_COAL_ENABLED) {
+	if (otx2_test_flag(pfvf, OTX2_FLAG_ADPTV_INT_COAL_ENABLED)) {
 		cmd->use_adaptive_rx_coalesce = 1;
 		cmd->use_adaptive_tx_coalesce = 1;
 	} else {
@@ -502,15 +501,14 @@ static int otx2_set_coalesce(struct net_device *netdev,
 	}
 
 	/* Check and update coalesce status */
-	if ((pfvf->flags & OTX2_FLAG_ADPTV_INT_COAL_ENABLED) ==
-			OTX2_FLAG_ADPTV_INT_COAL_ENABLED) {
+	if (otx2_test_flag(pfvf, OTX2_FLAG_ADPTV_INT_COAL_ENABLED)) {
 		priv_coalesce_status = 1;
 		if (!ec->use_adaptive_rx_coalesce)
-			pfvf->flags &= ~OTX2_FLAG_ADPTV_INT_COAL_ENABLED;
+			otx2_clear_flag(pfvf, OTX2_FLAG_ADPTV_INT_COAL_ENABLED);
 	} else {
 		priv_coalesce_status = 0;
 		if (ec->use_adaptive_rx_coalesce)
-			pfvf->flags |= OTX2_FLAG_ADPTV_INT_COAL_ENABLED;
+			otx2_set_flag(pfvf, OTX2_FLAG_ADPTV_INT_COAL_ENABLED);
 	}
 
 	/* 'cq_time_wait' is 8bit and is in multiple of 100ns,
@@ -556,8 +554,7 @@ static int otx2_set_coalesce(struct net_device *netdev,
 	 * 'on' to 'off'.
 	 */
 	if (priv_coalesce_status &&
-	    ((pfvf->flags & OTX2_FLAG_ADPTV_INT_COAL_ENABLED) !=
-	     OTX2_FLAG_ADPTV_INT_COAL_ENABLED)) {
+	    (!otx2_test_flag(pfvf, OTX2_FLAG_ADPTV_INT_COAL_ENABLED))) {
 		hw->cq_time_wait = CQ_TIMER_THRESH_DEFAULT;
 		hw->cq_ecount_wait = CQ_CQE_THRESH_DEFAULT;
 	}
drivers/net/ethernet/marvell/octeontx2/nic/otx2_flows.c +17 -17
index 6d095023d17b..0d8576ef822f 100644
@@ -270,9 +270,9 @@ int otx2_alloc_mcam_entries(struct otx2_nic *pfvf, u16 count)
 	flow_cfg->max_flows = allocated;
 
 	if (allocated) {
-		pfvf->flags |= OTX2_FLAG_MCAM_ENTRIES_ALLOC;
-		pfvf->flags |= OTX2_FLAG_NTUPLE_SUPPORT;
-		pfvf->flags |= OTX2_FLAG_TC_FLOWER_SUPPORT;
+		otx2_set_flag(pfvf, OTX2_FLAG_MCAM_ENTRIES_ALLOC);
+		otx2_set_flag(pfvf, OTX2_FLAG_NTUPLE_SUPPORT);
+		otx2_set_flag(pfvf, OTX2_FLAG_TC_FLOWER_SUPPORT);
 	}
 
 	if (allocated != count)
@@ -375,7 +375,7 @@ int otx2_mcam_entry_init(struct otx2_nic *pfvf)
 	flow_cfg->unicast_offset = vf_vlan_max_flows;
 	flow_cfg->rx_vlan_offset = flow_cfg->unicast_offset +
 					flow_cfg->ucast_flt_cnt;
-	pfvf->flags |= OTX2_FLAG_UCAST_FLTR_SUPPORT;
+	otx2_set_flag(pfvf, OTX2_FLAG_UCAST_FLTR_SUPPORT);
 
 	/* Check if NPC_DMAC field is supported
 	 * by the mkex profile before setting VLAN support flag.
@@ -400,11 +400,11 @@ int otx2_mcam_entry_init(struct otx2_nic *pfvf)
 	}
 
 	if (frsp->enable) {
-		pfvf->flags |= OTX2_FLAG_RX_VLAN_SUPPORT;
-		pfvf->flags |= OTX2_FLAG_VF_VLAN_SUPPORT;
+		otx2_set_flag(pfvf, OTX2_FLAG_RX_VLAN_SUPPORT);
+		otx2_set_flag(pfvf, OTX2_FLAG_VF_VLAN_SUPPORT);
 	}
 
-	pfvf->flags |= OTX2_FLAG_MCAM_ENTRIES_ALLOC;
+	otx2_set_flag(pfvf, OTX2_FLAG_MCAM_ENTRIES_ALLOC);
 	mutex_unlock(&pfvf->mbox.lock);
 
 	/* Allocate entries for Ntuple filters */
@@ -414,7 +414,7 @@ int otx2_mcam_entry_init(struct otx2_nic *pfvf)
 		return 0;
 	}
 
-	pfvf->flags |= OTX2_FLAG_TC_FLOWER_SUPPORT;
+	otx2_set_flag(pfvf, OTX2_FLAG_TC_FLOWER_SUPPORT);
 
 	refcount_set(&flow_cfg->mark_flows, 1);
 	return 0;
@@ -477,7 +477,7 @@ int otx2_mcam_flow_init(struct otx2_nic *pf)
 		return err;
 
 	/* Check if MCAM entries are allocate or not */
-	if (!(pf->flags & OTX2_FLAG_UCAST_FLTR_SUPPORT))
+	if (!otx2_test_flag(pf, OTX2_FLAG_UCAST_FLTR_SUPPORT))
 		return 0;
 
 	pf->mac_table = devm_kzalloc(pf->dev, sizeof(struct otx2_mac_table)
@@ -499,7 +499,7 @@ int otx2_mcam_flow_init(struct otx2_nic *pf)
 	if (!pf->flow_cfg->bmap_to_dmacindex)
 		return -ENOMEM;
 
-	pf->flags |= OTX2_FLAG_DMACFLTR_SUPPORT;
+	otx2_set_flag(pf, OTX2_FLAG_DMACFLTR_SUPPORT);
 
 	return 0;
 }
@@ -519,7 +519,7 @@ static int otx2_do_add_macfilter(struct otx2_nic *pf, const u8 *mac)
 	struct npc_install_flow_req *req;
 	int err, i;
 
-	if (!(pf->flags & OTX2_FLAG_UCAST_FLTR_SUPPORT))
+	if (!otx2_test_flag(pf, OTX2_FLAG_UCAST_FLTR_SUPPORT))
 		return -ENOMEM;
 
 	/* dont have free mcam entries or uc list is greater than alloted */
@@ -1164,7 +1164,7 @@ static int otx2_is_flow_rule_dmacfilter(struct otx2_nic *pfvf,
 	u64 ring_cookie = fsp->ring_cookie;
 	u32 flow_type;
 
-	if (!(pfvf->flags & OTX2_FLAG_DMACFLTR_SUPPORT))
+	if (!otx2_test_flag(pfvf, OTX2_FLAG_DMACFLTR_SUPPORT))
 		return false;
 
 	flow_type = fsp->flow_type & ~(FLOW_EXT | FLOW_MAC_EXT | FLOW_RSS);
@@ -1361,7 +1361,7 @@ int otx2_add_flow(struct otx2_nic *pfvf, struct ethtool_rxnfc *nfc)
 	}
 
 	ring = ethtool_get_flow_spec_ring(fsp->ring_cookie);
-	if (!(pfvf->flags & OTX2_FLAG_NTUPLE_SUPPORT))
+	if (!otx2_test_flag(pfvf, OTX2_FLAG_NTUPLE_SUPPORT))
 		return -ENOMEM;
 
 	/* Number of queues on a VF can be greater or less than
@@ -1593,7 +1593,7 @@ int otx2_destroy_ntuple_flows(struct otx2_nic *pfvf)
 	struct otx2_flow *iter, *tmp;
 	int err;
 
-	if (!(pfvf->flags & OTX2_FLAG_NTUPLE_SUPPORT))
+	if (!otx2_test_flag(pfvf, OTX2_FLAG_NTUPLE_SUPPORT))
 		return 0;
 
 	if (!flow_cfg->max_flows)
@@ -1626,7 +1626,7 @@ int otx2_destroy_mcam_flows(struct otx2_nic *pfvf)
 	struct otx2_flow *iter, *tmp;
 	int err;
 
-	if (!(pfvf->flags & OTX2_FLAG_MCAM_ENTRIES_ALLOC))
+	if (!otx2_test_flag(pfvf, OTX2_FLAG_MCAM_ENTRIES_ALLOC))
 		return 0;
 
 	/* remove all flows */
@@ -1655,7 +1655,7 @@ int otx2_destroy_mcam_flows(struct otx2_nic *pfvf)
 		return err;
 	}
 
-	pfvf->flags &= ~OTX2_FLAG_MCAM_ENTRIES_ALLOC;
+	otx2_clear_flag(pfvf, OTX2_FLAG_MCAM_ENTRIES_ALLOC);
 	flow_cfg->max_flows = 0;
 	mutex_unlock(&pfvf->mbox.lock);
 
@@ -1718,7 +1718,7 @@ int otx2_enable_rxvlan(struct otx2_nic *pf, bool enable)
 	int err;
 
 	/* Dont have enough mcam entries */
-	if (!(pf->flags & OTX2_FLAG_RX_VLAN_SUPPORT))
+	if (!otx2_test_flag(pf, OTX2_FLAG_RX_VLAN_SUPPORT))
 		return -ENOMEM;
 
 	if (enable) {
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +39 -39

228 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +15 -15
index dee38d5c7f65..8877af348a09 100644
@@ -159,7 +159,7 @@ static int otx2_tc_validate_flow(struct otx2_nic *nic,
 				 struct flow_action *actions,
 				 struct netlink_ext_ack *extack)
 {
-	if (nic->flags & OTX2_FLAG_INTF_DOWN) {
+	if (otx2_test_flag(nic, OTX2_FLAG_INTF_DOWN)) {
 		NL_SET_ERR_MSG_MOD(extack, "Interface not initialized");
 		return -EINVAL;
 	}
@@ -223,7 +223,7 @@ static int otx2_tc_egress_matchall_install(struct otx2_nic *nic,
 	if (err)
 		return err;
 
-	if (nic->flags & OTX2_FLAG_TC_MATCHALL_EGRESS_ENABLED) {
+	if (otx2_test_flag(nic, OTX2_FLAG_TC_MATCHALL_EGRESS_ENABLED)) {
 		NL_SET_ERR_MSG_MOD(extack,
 				   "Only one Egress MATCHALL ratelimiter can be offloaded");
 		return -ENOMEM;
@@ -244,7 +244,7 @@ static int otx2_tc_egress_matchall_install(struct otx2_nic *nic,
 						    otx2_convert_rate(entry->police.rate_bytes_ps));
 		if (err)
 			return err;
-		nic->flags |= OTX2_FLAG_TC_MATCHALL_EGRESS_ENABLED;
+		otx2_set_flag(nic, OTX2_FLAG_TC_MATCHALL_EGRESS_ENABLED);
 		break;
 	default:
 		NL_SET_ERR_MSG_MOD(extack,
@@ -261,13 +261,13 @@ static int otx2_tc_egress_matchall_delete(struct otx2_nic *nic,
 	struct netlink_ext_ack *extack = cls->common.extack;
 	int err;
 
-	if (nic->flags & OTX2_FLAG_INTF_DOWN) {
+	if (otx2_test_flag(nic, OTX2_FLAG_INTF_DOWN)) {
 		NL_SET_ERR_MSG_MOD(extack, "Interface not initialized");
 		return -EINVAL;
 	}
 
 	err = otx2_set_matchall_egress_rate(nic, 0, 0);
-	nic->flags &= ~OTX2_FLAG_TC_MATCHALL_EGRESS_ENABLED;
+	otx2_clear_flag(nic, OTX2_FLAG_TC_MATCHALL_EGRESS_ENABLED);
 	return err;
 }
 
@@ -505,7 +505,7 @@ static int otx2_tc_parse_actions(struct otx2_nic *nic,
 			mark = act->mark;
 			req->match_id = mark & OTX2_RX_MATCH_ID_MASK;
 			req->op = NIX_RX_ACTION_DEFAULT;
-			nic->flags |= OTX2_FLAG_TC_MARK_ENABLED;
+			otx2_set_flag(nic, OTX2_FLAG_TC_MARK_ENABLED);
 			refcount_inc(&nic->flow_cfg->mark_flows);
 			break;
 
@@ -942,7 +942,7 @@ static void otx2_destroy_tc_flow_list(struct otx2_nic *pfvf)
 	struct otx2_flow_config *flow_cfg = pfvf->flow_cfg;
 	struct otx2_tc_flow *iter, *tmp;
 
-	if (!(pfvf->flags & OTX2_FLAG_MCAM_ENTRIES_ALLOC))
+	if (!otx2_test_flag(pfvf, OTX2_FLAG_MCAM_ENTRIES_ALLOC))
 		return;
 
 	list_for_each_entry_safe(iter, tmp, &flow_cfg->flow_list_tc, list) {
@@ -1195,12 +1195,12 @@ static int otx2_tc_del_flow(struct otx2_nic *nic,
 	/* Disable TC MARK flag if they are no rules with skbedit mark action */
 	if (flow_node->req.match_id)
 		if (!refcount_dec_and_test(&flow_cfg->mark_flows))
-			nic->flags &= ~OTX2_FLAG_TC_MARK_ENABLED;
+			otx2_clear_flag(nic, OTX2_FLAG_TC_MARK_ENABLED);
 
 	if (flow_node->is_act_police) {
 		__clear_bit(flow_node->rq, &nic->rq_bmap);
 
-		if (nic->flags & OTX2_FLAG_INTF_DOWN)
+		if (otx2_test_flag(nic, OTX2_FLAG_INTF_DOWN))
 			goto free_mcam_flow;
 
 		mutex_lock(&nic->mbox.lock);
@@ -1246,10 +1246,10 @@ static int otx2_tc_add_flow(struct otx2_nic *nic,
 	struct npc_install_flow_req *req, dummy;
 	int rc, err, entry;
 
-	if (!(nic->flags & OTX2_FLAG_TC_FLOWER_SUPPORT))
+	if (!otx2_test_flag(nic, OTX2_FLAG_TC_FLOWER_SUPPORT))
 		return -ENOMEM;
 
-	if (nic->flags & OTX2_FLAG_INTF_DOWN) {
+	if (otx2_test_flag(nic, OTX2_FLAG_INTF_DOWN)) {
 		NL_SET_ERR_MSG_MOD(extack, "Interface not initialized");
 		return -EINVAL;
 	}
@@ -1444,7 +1444,7 @@ static int otx2_tc_ingress_matchall_install(struct otx2_nic *nic,
 	if (err)
 		return err;
 
-	if (nic->flags & OTX2_FLAG_TC_MATCHALL_INGRESS_ENABLED) {
+	if (otx2_test_flag(nic, OTX2_FLAG_TC_MATCHALL_INGRESS_ENABLED)) {
 		NL_SET_ERR_MSG_MOD(extack,
 				   "Only one ingress MATCHALL ratelimitter can be offloaded");
 		return -ENOMEM;
@@ -1469,7 +1469,7 @@ static int otx2_tc_ingress_matchall_install(struct otx2_nic *nic,
 		err = cn10k_set_matchall_ipolicer_rate(nic, entry->police.burst, rate);
 		if (err)
 			return err;
-		nic->flags |= OTX2_FLAG_TC_MATCHALL_INGRESS_ENABLED;
+		otx2_set_flag(nic, OTX2_FLAG_TC_MATCHALL_INGRESS_ENABLED);
 		break;
 	default:
 		NL_SET_ERR_MSG_MOD(extack,
@@ -1486,13 +1486,13 @@ static int otx2_tc_ingress_matchall_delete(struct otx2_nic *nic,
 	struct netlink_ext_ack *extack = cls->common.extack;
 	int err;
 
-	if (nic->flags & OTX2_FLAG_INTF_DOWN) {
+	if (otx2_test_flag(nic, OTX2_FLAG_INTF_DOWN)) {
 		NL_SET_ERR_MSG_MOD(extack, "Interface not initialized");
 		return -EINVAL;
 	}
 
 	err = cn10k_free_matchall_ipolicer(nic);
-	nic->flags &= ~OTX2_FLAG_TC_MATCHALL_INGRESS_ENABLED;
+	otx2_clear_flag(nic, OTX2_FLAG_TC_MATCHALL_INGRESS_ENABLED);
 	return err;
 }
 
drivers/net/ethernet/marvell/octeontx2/nic/otx2_txrx.c +8 -8
index b038bb145194..755dc4725713 100644
@@ -171,7 +171,7 @@ static void otx2_set_rxtstamp(struct otx2_nic *pfvf,
 	u64 timestamp, tsns;
 	int err;
 
-	if (!(pfvf->flags & OTX2_FLAG_RX_TSTAMP_ENABLED))
+	if (!otx2_test_flag(pfvf, OTX2_FLAG_RX_TSTAMP_ENABLED))
 		return;
 
 	timestamp = pfvf->ptp->convert_rx_ptp_tstmp(*(u64 *)data);
@@ -374,13 +374,13 @@ static void otx2_rcv_pkt_handler(struct otx2_nic *pfvf,
 	}
 	otx2_set_rxhash(pfvf, cqe, skb);
 
-	if (!(pfvf->flags & OTX2_FLAG_REP_MODE_ENABLED)) {
+	if (!otx2_test_flag(pfvf, OTX2_FLAG_REP_MODE_ENABLED)) {
 		skb_record_rx_queue(skb, cq->cq_idx);
 		if (pfvf->netdev->features & NETIF_F_RXCSUM)
 			skb->ip_summed = CHECKSUM_UNNECESSARY;
 	}
 
-	if (pfvf->flags & OTX2_FLAG_TC_MARK_ENABLED)
+	if (otx2_test_flag(pfvf, OTX2_FLAG_TC_MARK_ENABLED))
 		skb->mark = parse->match_id;
 
 	skb_mark_for_recycle(skb);
@@ -513,7 +513,7 @@ static int otx2_tx_napi_handler(struct otx2_nic *pfvf,
 		     ((u64)cq->cq_idx << 32) | processed_cqe);
 
 #if IS_ENABLED(CONFIG_RVU_ESWITCH)
-	if (pfvf->flags & OTX2_FLAG_REP_MODE_ENABLED)
+	if (otx2_test_flag(pfvf, OTX2_FLAG_REP_MODE_ENABLED))
 		ndev = pfvf->reps[qidx]->netdev;
 	else
 #endif
@@ -526,7 +526,7 @@ static int otx2_tx_napi_handler(struct otx2_nic *pfvf,
 
 		if (qidx >= pfvf->hw.tx_queues)
 			qidx -= pfvf->hw.xdp_queues;
-		if (pfvf->flags & OTX2_FLAG_REP_MODE_ENABLED)
+		if (otx2_test_flag(pfvf, OTX2_FLAG_REP_MODE_ENABLED))
 			qidx = 0;
 		txq = netdev_get_tx_queue(ndev, qidx);
 		netdev_tx_completed_queue(txq, tx_pkts, tx_bytes);
@@ -599,11 +599,11 @@ int otx2_napi_handler(struct napi_struct *napi, int budget)
 
 	if (workdone < budget && napi_complete_done(napi, workdone)) {
 		/* If interface is going down, don't re-enable IRQ */
-		if (pfvf->flags & OTX2_FLAG_INTF_DOWN)
+		if (otx2_test_flag(pfvf, OTX2_FLAG_INTF_DOWN))
 			return workdone;
 
 		/* Adjust irq coalese using net_dim */
-		if (pfvf->flags & OTX2_FLAG_ADPTV_INT_COAL_ENABLED)
+		if (otx2_test_flag(pfvf, OTX2_FLAG_ADPTV_INT_COAL_ENABLED))
 			otx2_adjust_adaptive_coalese(pfvf, cq_poll);
 
 		if (likely(cq))
@@ -1137,7 +1137,7 @@ static void otx2_set_txtstamp(struct otx2_nic *pfvf, struct sk_buff *skb,
 
 	if (unlikely(!skb_shinfo(skb)->gso_size &&
 		     (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP))) {
-		if (unlikely(pfvf->flags & OTX2_FLAG_PTP_ONESTEP_SYNC &&
+		if (unlikely(otx2_test_flag(pfvf, OTX2_FLAG_PTP_ONESTEP_SYNC) &&
 			     otx2_ptp_is_sync(skb, &ptp_offset, &udp_csum_crt))) {
 			origin_tstamp = (struct ptpv2_tstamp *)
 					((u8 *)skb->data + ptp_offset +
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c +5 -5
index f7765e19d78a..5f7915231ca3 100644
@@ -610,7 +610,7 @@ static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	vf->dev = dev;
 	vf->iommu_domain = iommu_get_domain_for_dev(dev);
 
-	vf->flags |= OTX2_FLAG_INTF_DOWN;
+	otx2_set_flag(vf, OTX2_FLAG_INTF_DOWN);
 	hw = &vf->hw;
 	hw->pdev = vf->pdev;
 	hw->rx_queues = qcount;
@@ -824,10 +824,10 @@ static void otx2vf_remove(struct pci_dev *pdev)
 	vf = netdev_priv(netdev);
 
 	/* Disable 802.3x pause frames */
-	if (vf->flags & OTX2_FLAG_RX_PAUSE_ENABLED ||
-	    (vf->flags & OTX2_FLAG_TX_PAUSE_ENABLED)) {
-		vf->flags &= ~OTX2_FLAG_RX_PAUSE_ENABLED;
-		vf->flags &= ~OTX2_FLAG_TX_PAUSE_ENABLED;
+	if (otx2_test_flag(vf, OTX2_FLAG_RX_PAUSE_ENABLED) ||
+	    otx2_test_flag(vf, OTX2_FLAG_TX_PAUSE_ENABLED)) {
+		otx2_clear_flag(vf, OTX2_FLAG_RX_PAUSE_ENABLED);
+		otx2_clear_flag(vf, OTX2_FLAG_TX_PAUSE_ENABLED);
 		otx2_config_pause_frm(vf);
 	}
 
drivers/net/ethernet/marvell/octeontx2/nic/otx2_xsk.c +2 -2
index 0e8a6a6486c4..7808588a0234 100644
@@ -96,7 +96,7 @@ static void otx2_clean_up_rq(struct otx2_nic *pfvf, int qidx)
 	u64 iova;
 
 	/* If the DOWN flag is set SQs are already freed */
-	if (pfvf->flags & OTX2_FLAG_INTF_DOWN)
+	if (otx2_test_flag(pfvf, OTX2_FLAG_INTF_DOWN))
 		return;
 
 	cq = &qset->cq[qidx];
@@ -172,7 +172,7 @@ int otx2_xsk_wakeup(struct net_device *dev, u32 queue_id, u32 flags)
 	struct otx2_cq_poll *cq_poll = NULL;
 	struct otx2_qset *qset = &pf->qset;
 
-	if (pf->flags & OTX2_FLAG_INTF_DOWN)
+	if (otx2_test_flag(pf, OTX2_FLAG_INTF_DOWN))
 		return -ENETDOWN;
 
 	if (queue_id >= pf->hw.rx_queues || queue_id >= pf->hw.tx_queues)
drivers/net/ethernet/marvell/octeontx2/nic/qos_sq.c +2 -2
index 2872adabc830..5f09e2960144 100644
@@ -238,7 +238,7 @@ int otx2_qos_enable_sq(struct otx2_nic *pfvf, int qidx)
 	struct otx2_hw *hw = &pfvf->hw;
 	int pool_id, sq_idx, err;
 
-	if (pfvf->flags & OTX2_FLAG_INTF_DOWN)
+	if (otx2_test_flag(pfvf, OTX2_FLAG_INTF_DOWN))
 		return -EPERM;
 
 	sq_idx = hw->non_qos_queues + qidx;
@@ -288,7 +288,7 @@ void otx2_qos_disable_sq(struct otx2_nic *pfvf, int qidx)
 	sq_idx = hw->non_qos_queues + qidx;
 
 	/* If the DOWN flag is set SQs are already freed */
-	if (pfvf->flags & OTX2_FLAG_INTF_DOWN)
+	if (otx2_test_flag(pfvf, OTX2_FLAG_INTF_DOWN))
 		return;
 
 	sq = &pfvf->qset.sq[sq_idx];
drivers/net/ethernet/marvell/octeontx2/nic/rep.c +16 -16
index 0f5d5642d3f7..7df82c22cc12 100644
@@ -93,9 +93,9 @@ static int rvu_rep_mcam_flow_init(struct rep_dev *rep)
 	rep->flow_cfg->max_flows = allocated;
 
 	if (allocated) {
-		rep->flags |= OTX2_FLAG_MCAM_ENTRIES_ALLOC;
-		rep->flags |= OTX2_FLAG_NTUPLE_SUPPORT;
-		rep->flags |= OTX2_FLAG_TC_FLOWER_SUPPORT;
+		set_bit(OTX2_FLAG_MCAM_ENTRIES_ALLOC, &rep->flags);
+		set_bit(OTX2_FLAG_NTUPLE_SUPPORT, &rep->flags);
+		set_bit(OTX2_FLAG_TC_FLOWER_SUPPORT, &rep->flags);
 	}
 
 	INIT_LIST_HEAD(&rep->flow_cfg->flow_list);
@@ -109,14 +109,14 @@ static int rvu_rep_setup_tc_cb(enum tc_setup_type type,
 	struct rep_dev *rep = cb_priv;
 	struct otx2_nic *priv = rep->mdev;
 
-	if (!(rep->flags & RVU_REP_VF_INITIALIZED))
+	if (!test_bit(OTX2_FLAG_REP_VF_INITIALIZED, &rep->flags))
 		return -EINVAL;
 
-	if (!(rep->flags & OTX2_FLAG_TC_FLOWER_SUPPORT))
+	if (!test_bit(OTX2_FLAG_TC_FLOWER_SUPPORT, &rep->flags))
 		rvu_rep_mcam_flow_init(rep);
 
 	priv->netdev = rep->netdev;
-	priv->flags = rep->flags;
+	otx2_sync_flags_from_rep(priv, &rep->flags);
 	priv->pcifunc = rep->pcifunc;
 	priv->flow_cfg = rep->flow_cfg;
 
@@ -303,9 +303,9 @@ static void rvu_rep_state_evt_handler(struct otx2_nic *priv,
 	rep_id = rvu_rep_get_repid(priv, info->pcifunc);
 	rep = priv->reps[rep_id];
 	if (info->evt_data.vf_state)
-		rep->flags |= RVU_REP_VF_INITIALIZED;
+		set_bit(OTX2_FLAG_REP_VF_INITIALIZED, &rep->flags);
 	else
-		rep->flags &= ~RVU_REP_VF_INITIALIZED;
+		clear_bit(OTX2_FLAG_REP_VF_INITIALIZED, &rep->flags);
 }
 
 int rvu_event_up_notify(struct otx2_nic *pf, struct rep_event *info)
@@ -382,7 +382,7 @@ static void rvu_rep_get_stats64(struct net_device *dev,
 {
 	struct rep_dev *rep = netdev_priv(dev);
 
-	if (!(rep->flags & RVU_REP_VF_INITIALIZED))
+	if (!test_bit(OTX2_FLAG_REP_VF_INITIALIZED, &rep->flags))
 		return;
 
 	stats->rx_packets = rep->stats.rx_frames;
@@ -453,7 +453,7 @@ static int rvu_rep_open(struct net_device *dev)
 	struct otx2_nic *priv = rep->mdev;
 	struct rep_event evt = {0};
 
-	if (!(rep->flags & RVU_REP_VF_INITIALIZED))
+	if (!test_bit(OTX2_FLAG_REP_VF_INITIALIZED, &rep->flags))
 		return 0;
 
 	netif_carrier_on(dev);
@@ -472,7 +472,7 @@ static int rvu_rep_stop(struct net_device *dev)
 	struct otx2_nic *priv = rep->mdev;
 	struct rep_event evt = {0};
 
-	if (!(rep->flags & RVU_REP_VF_INITIALIZED))
+	if (!test_bit(OTX2_FLAG_REP_VF_INITIALIZED, &rep->flags))
 		return 0;
 
 	netif_carrier_off(dev);
@@ -547,7 +547,7 @@ static int rvu_rep_napi_init(struct otx2_nic *priv,
 		otx2_write64(priv, NIX_LF_CINTX_INT(qidx), BIT_ULL(0));
 		otx2_write64(priv, NIX_LF_CINTX_ENA_W1S(qidx), BIT_ULL(0));
 	}
-	priv->flags &= ~OTX2_FLAG_INTF_DOWN;
+	otx2_clear_flag(priv, OTX2_FLAG_INTF_DOWN);
 	return 0;
 
 err_free_cints:
@@ -632,7 +632,7 @@ void rvu_rep_destroy(struct otx2_nic *priv)
 	int rep_id;
 
 	rvu_eswitch_config(priv, false);
-	priv->flags |= OTX2_FLAG_INTF_DOWN;
+	otx2_set_flag(priv, OTX2_FLAG_INTF_DOWN);
 	rvu_rep_free_cq_rsrc(priv);
 	for (rep_id = 0; rep_id < priv->rep_cnt; rep_id++) {
 		rep = priv->reps[rep_id];
@@ -801,8 +801,8 @@ static int rvu_rep_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	pci_set_drvdata(pdev, priv);
 	priv->pdev = pdev;
 	priv->dev = dev;
-	priv->flags |= OTX2_FLAG_INTF_DOWN;
-	priv->flags |= OTX2_FLAG_REP_MODE_ENABLED;
+	otx2_set_flag(priv, OTX2_FLAG_INTF_DOWN);
+	otx2_set_flag(priv, OTX2_FLAG_REP_MODE_ENABLED);
 
 	hw = &priv->hw;
 	hw->pdev = pdev;
@@ -845,7 +845,7 @@ static void rvu_rep_remove(struct pci_dev *pdev)
 	struct otx2_nic *priv = pci_get_drvdata(pdev);
 
 	otx2_unregister_dl(priv);
-	if (!(priv->flags & OTX2_FLAG_INTF_DOWN))
+	if (!otx2_test_flag(priv, OTX2_FLAG_INTF_DOWN))
 		rvu_rep_destroy(priv);
 	otx2_detach_resources(&priv->mbox);
 	if (priv->hw.lmt_info)
drivers/net/ethernet/marvell/octeontx2/nic/rep.h +1 -2
index 5bc9e2c7d800..45707c434d89 100644
@@ -37,8 +37,7 @@ struct rep_dev {
 	struct delayed_work stats_wrk;
 	struct devlink_port dl_port;
 	struct otx2_flow_config	*flow_cfg;
-#define RVU_REP_VF_INITIALIZED		BIT_ULL(0)
-	u64 flags;
+	unsigned long		flags;
 	u16 rep_id;
 	u16 pcifunc;
 	u8 mac[ETH_ALEN];

--
2.43.0

#2 lore raw

Re: [PATCH v21 net-next 1/2] octeontx2: use atomic bitops for PF/VF and rep flags

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] net: octeontx2: non-atomic RMW in otx2_sync_flags_from_rep() clobbers flags --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] net: octeontx2: non-atomic RMW in otx2_sync_flags_from_rep() clobbers flags
--

commit d48d79ca17214bd041428c7ee5971241f58dd157
Author: Ratheesh Kannoth <[email protected]>

octeontx2: use atomic bitops for PF/VF and rep flags

This commit converts the PF/VF and representor flags from u64 bitmasks to unsigned long bitmaps manipulated with atomic bitops, and adds otx2_sync_flags_from_rep() to copy representor flags onto the PF context.

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +0 -0
index 8417af94a02a0..f3158e293d864 100644

[ ... ]

Quoted 19 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +15 -0
@@ -593,6 +607,32 @@ struct otx2_nic {
 	unsigned long		*af_xdp_zc_qidx;
 };
 
+static inline void otx2_set_flag(struct otx2_nic *nic, unsigned int flag)
+{
+	set_bit(flag, &nic->flags);
+}
+
+static inline void otx2_clear_flag(struct otx2_nic *nic, unsigned int flag)
+{
+	clear_bit(flag, &nic->flags);
+}
+
+static inline bool otx2_test_flag(struct otx2_nic *nic, unsigned int flag)
+{
+	return test_bit(flag, &nic->flags);
+}
+

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h struct otx2_nic { · line 634

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +10 -0
+static inline void otx2_sync_flags_from_rep(struct otx2_nic *dst,
+					    unsigned long *src_flags)
+{
+	unsigned long src = READ_ONCE(*src_flags);
+	unsigned long new_flags;
+
+	new_flags = (READ_ONCE(dst->flags) & ~OTX2_REP_SYNC_FLAGS_MASK) |
+		    (src & OTX2_REP_SYNC_FLAGS_MASK);
+	WRITE_ONCE(dst->flags, new_flags);
+}

[Severity: High]
Can the non-atomic read-modify-write in otx2_sync_flags_from_rep() clobber concurrent atomic updates to dst->flags?

All representor netdevs share a single struct otx2_nic *priv (rep->mdev). rvu_rep_setup_tc_cb() calls otx2_sync_flags_from_rep(priv, &rep->flags) without holding the devlink lock, while otx2_devlink_eswitch_mode_set() -> rvu_rep_destroy() runs under the devlink lock without rtnl_lock and sets OTX2_FLAG_INTF_DOWN before unregistering the representor netdevs:

CPU0 CPU1
rvu_rep_setup_tc_cb() otx2_devlink_eswitch_mode_set()
otx2_sync_flags_from_rep() rvu_rep_destroy()

    READ_ONCE(dst->flags)
    /* OTX2_FLAG_INTF_DOWN is 0 */
                                        otx2_set_flag(priv,
                                          OTX2_FLAG_INTF_DOWN)
    WRITE_ONCE(dst->flags, new_flags)
    /* clears OTX2_FLAG_INTF_DOWN */
                                        ...
                                    rvu_rep_remove()
                                      if (!otx2_test_flag(priv,
                                            OTX2_FLAG_INTF_DOWN))
                                        rvu_rep_destroy(priv)
                                          /* double teardown / free */

Because OTX2_FLAG_INTF_DOWN is overwritten back to 0, otx2_napi_handler() can re-enable CQ interrupts during teardown, and rvu_rep_remove() will call rvu_rep_destroy() a second time, causing a NULL pointer dereference on qset->napi and a double free of priv->reps and the representor netdevs.

Similarly, because cls_fl_ops sets TCF_PROTO_OPS_DOIT_UNLOCKED, concurrent TC flower operations on sibling representors can lose updates to OTX2_FLAG_TC_MARK_ENABLED on priv->flags.

Using a try_cmpxchg() loop (or atomic_long_andnot() / atomic_long_or()) to update the masked bits in dst->flags would preserve concurrent bit updates.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

Re: [PATCH v21 net-next 1/2] octeontx2: use atomic bitops for PF/VF and rep flags

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

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

Critical: 0 (1) · High: 1 (4) · Medium: 2 (1) · Low: 1

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).

- [High] otx2_sync_flags_from_rep() (drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h) is the only…
- [Medium] The commit message hides that this patch fixes a real bug, and it has no Fixes: tag.
- [Medium] Before this patch, priv->flags = rep->flags always cleared OTX2_FLAG_INTF_DOWN on the eswitch PF context before calling into the…
- [Low] The commit message says the flags now use atomic bitops and that otx2_sync_flags_from_rep() publishes representor flags "without…

Pre-existing issues:
- [Critical] rvu_rep_state_evt_handler() (drivers/net/ethernet/marvell/octeontx2/nic/rep.c) does `rep_id =…
- [High] rep->stats_wrk is set up with INIT_DELAYED_WORK in rvu_rep_create().
- [High] In rvu_rep_destroy() (drivers/net/ethernet/marvell/octeontx2/nic/rep.c),…
- [High] rvu_rep_mcam_flow_init() (drivers/net/ethernet/marvell/octeontx2/nic/rep.c) builds and sends…
- [High] Any PF or VF, including a VF owned by a guest since the PF forwards all VF mbox messages to AF, can send REP_EVENT_NOTIFY with…
- [Medium] rvu_rep_setup_tc_cb() calls rvu_rep_mcam_flow_init(rep) on every tc callback while OTX2_FLAG_TC_FLOWER_SUPPORT is clear in…

--

octeontx2: use atomic bitops for PF/VF and rep flags

This converts the otx2_nic and rep_dev flags from u64 masks to unsigned long bitmaps, updated through set_bit()/clear_bit()/test_bit() helpers. In rvu_rep_setup_tc_cb(), the full-word assignment is replaced by otx2_sync_flags_from_rep(), which copies a mask of representor-owned bits onto the eswitch PF context. The representor VF-initialized flag moves from BIT_ULL(0) in rep.h to OTX2_FLAG_REP_VF_INITIALIZED (bit 21).

Quoted 5 lines

Switch PF/VF and representor flags from non-atomic u64 masks to unsigned long bitmaps with set_bit/clear_bit/test_bit. Add helpers and otx2_sync_flags_from_rep() to publish representor-owned flags onto the PF mailbox context with a masked WRITE_ONCE, giving lockless NAPI readers a consistent word without clearing PF-owned bits.

[Severity: Low]
Is "without clearing PF-owned bits" accurate? otx2_sync_flags_from_rep() does a plain READ_ONCE()/mask/WRITE_ONCE() read-modify-write of dst->flags. Every other writer of that word now uses set_bit() or clear_bit().

If an atomic update to a PF-owned bit lands between the read and the write, it gets overwritten. So the guarantee only holds when nothing else is writing at the same time. There are more details on this below, at otx2_sync_flags_from_rep().

Could the commit message also say which concurrent update problem the atomic conversion is meant to fix?

Quoted 2 lines

Relocate representor VF initialization to OTX2_FLAG_REP_VF_INITIALIZED (bit 21).

[Severity: Medium]
Is this only a relocation? Before this patch, rvu_rep_setup_tc_cb() did:

    priv->flags = rep->flags;

That overwrote the whole flags word of the eswitch PF otx2_nic, including OTX2_FLAG_REP_MODE_ENABLED, which rvu_rep_probe() sets.

The removed RVU_REP_VF_INITIALIZED was also BIT_ULL(0), the same bit as OTX2_FLAG_RX_TSTAMP_ENABLED. The callback only gets past its first check when that bit is set, so the bit was copied onto priv every time.

Once REP_MODE_ENABLED was cleared, otx2_tx_napi_handler() stopped taking these branches:

    if (otx2_test_flag(pfvf, OTX2_FLAG_REP_MODE_ENABLED))
        ndev = pfvf->reps[qidx]->netdev;
    ...
    if (otx2_test_flag(pfvf, OTX2_FLAG_REP_MODE_ENABLED))
        qidx = 0;
    txq = netdev_get_tx_queue(ndev, qidx);

Instead it fell back to pfvf->netdev, which rvu_rep_setup_tc_cb() had pointed at rep->netdev. That netdev comes from alloc_etherdev() and has a single TX queue, and qidx was no longer clamped. Doesn't that index past dev->_tx[] and then write DQL state beyond it?

If so, this patch includes a fix. Would a Fixes: tag and a description of the old behaviour help with stable backports?

The mask also changes one more behaviour: OTX2_FLAG_TC_MARK_ENABLED now stays set in priv instead of being cleared on every representor tc callback. Is that intended, and is it worth mentioning in the commit message?

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +0 -0
index 8417af94a02a0..f3158e293d864 100644

[ ... ]

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +0 -0
@@ -593,6 +607,32 @@ struct otx2_nic {
 	unsigned long		*af_xdp_zc_qidx;
 };
 

[ ... ]

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h struct otx2_nic { · line 634

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +10 -0
+static inline void otx2_sync_flags_from_rep(struct otx2_nic *dst,
+					    unsigned long *src_flags)
+{
+	unsigned long src = READ_ONCE(*src_flags);
+	unsigned long new_flags;
+
+	new_flags = (READ_ONCE(dst->flags) & ~OTX2_REP_SYNC_FLAGS_MASK) |
+		    (src & OTX2_REP_SYNC_FLAGS_MASK);
+	WRITE_ONCE(dst->flags, new_flags);
+}

[Severity: High]
Can this lose concurrent updates to PF-owned bits in priv->flags?

The only caller is rvu_rep_setup_tc_cb(), which runs from the tc block callback under rtnl. Other writers of the same word don't hold rtnl. One example is the devlink eswitch path:

otx2_devlink_eswitch_mode_set()

    case DEVLINK_ESWITCH_MODE_LEGACY:
        rvu_rep_destroy(pfvf);
            otx2_set_flag(priv, OTX2_FLAG_INTF_DOWN);

This runs under the devlink lock only; unregister_netdev() takes rtnl later. rvu_rep_napi_init() clears INTF_DOWN on the same devlink path, and the mbox up-handler work sets and clears OTX2_FLAG_PORT_UP.

If one of those set_bit()/clear_bit() calls lands between the READ_ONCE() and the WRITE_ONCE() here, the stale word gets written back.

If the INTF_DOWN set is lost, the eswitch PF still looks up after teardown. otx2_napi_handler() can then re-arm the CINT, and rvu_rep_remove() runs destroy a second time:

    if (!otx2_test_flag(priv, OTX2_FLAG_INTF_DOWN))
        rvu_rep_destroy(priv);

That second destroy calls unregister_netdev()/free_netdev() on netdevs that are already freed, and calls kfree(priv->reps) a second time.

If the INTF_DOWN clear in rvu_rep_napi_init() is lost instead, the CQ interrupts are never re-enabled, because otx2_napi_handler() returns early:

    if (otx2_test_flag(pfvf, OTX2_FLAG_INTF_DOWN))
        return workdone;

Would updating only the masked bits with assign_bit(), or using a cmpxchg loop, avoid this?

[ ... ]

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +0 -0
index 7dc0ce669d0b7..777e7156badb7 100644

[ ... ]

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +0 -0
@@ -907,11 +907,11 @@ static int otx2_mbox_up_handler_rep_event_up_notify(struct otx2_nic *pf,
 
 	if (info->event == RVU_EVENT_PORT_STATE) {
 		if (info->evt_data.port_state) {

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c static int otx2_mbox_up_handler_rep_event_up_notify(struct otx2_nic *pf, · line 917

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +2 -2
-			pf->flags |= OTX2_FLAG_PORT_UP;
+			otx2_set_flag(pf, OTX2_FLAG_PORT_UP);
 			netif_carrier_on(netdev);
 			netif_tx_start_all_queues(netdev);
 		} else {
-			pf->flags &= ~OTX2_FLAG_PORT_UP;
+			otx2_clear_flag(pf, OTX2_FLAG_PORT_UP);
 			netif_tx_stop_all_queues(netdev);
 			netif_carrier_off(netdev);
 		}

[Severity: High]
This isn't a bug introduced by this patch, but can any PF or VF forge this event for a PF it doesn't own?

On the AF side, rvu_mbox_handler_rep_event_notify() only range-checks the target:

    if (!is_pf_func_valid(rvu, req->pcifunc))
        return -EINVAL;

It doesn't check that the sender is rvu->rep_pcifunc. rvu_rep_up_notify() then forwards the event and evt_data to rvu_get_pf(event->pcifunc). The PF forwards VF mailbox messages to AF through otx2_forward_vf_mbox_msgs(), so a VF owned by a guest can send this as well.

On the victim PF, port_state=0 stops TX and drops carrier. port_state=1 sets OTX2_FLAG_PORT_UP, and from then on otx2_handle_link_event() ignores real CGX link events until the next otx2_open():

    if (otx2_test_flag(pf, OTX2_FLAG_PORT_UP))
        return;

Should AF reject REP_EVENT_NOTIFY from anything other than the representor PF?

[ ... ]

Quoted 5 lines
drivers/net/ethernet/marvell/octeontx2/nic/rep.c +0 -0
index 0f5d5642d3f7a..7df82c22cc12b 100644

drivers/net/ethernet/marvell/octeontx2/nic/rep.c static int rvu_rep_mcam_flow_init(struct rep_dev *rep) · line 99

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/rep.c +3 -3
@@ -93,9 +93,9 @@ static int rvu_rep_mcam_flow_init(struct rep_dev *rep)
 	rep->flow_cfg->max_flows = allocated;
 
 	if (allocated) {
-		rep->flags |= OTX2_FLAG_MCAM_ENTRIES_ALLOC;
-		rep->flags |= OTX2_FLAG_NTUPLE_SUPPORT;
-		rep->flags |= OTX2_FLAG_TC_FLOWER_SUPPORT;
+		set_bit(OTX2_FLAG_MCAM_ENTRIES_ALLOC, &rep->flags);
+		set_bit(OTX2_FLAG_NTUPLE_SUPPORT, &rep->flags);
+		set_bit(OTX2_FLAG_TC_FLOWER_SUPPORT, &rep->flags);
 	}

[Severity: High]
This is a pre-existing issue, but where does rvu_rep_mcam_flow_init() take priv->mbox.lock? The loop allocates and sends NPC_MCAM_ALLOC_ENTRY messages on priv->mbox without the lock, and the exit path then does:

exit:

    ...
    mutex_unlock(&priv->mbox.lock);

Neither this function nor rvu_rep_setup_tc_cb() calls mutex_lock().

Suppose another context holds the mutex at that point, such as the rvu_rep_get_stats() worker. Doesn't this release that holder's lock and let mailbox messages from both contexts interleave? If nobody holds it, this is an unbalanced unlock, which lockdep would report.

drivers/net/ethernet/marvell/octeontx2/nic/rep.c static int rvu_rep_setup_tc_cb(enum tc_setup_type type, · line 116

Quoted 11 lines
drivers/net/ethernet/marvell/octeontx2/nic/rep.c +2 -2
@@ -109,14 +109,14 @@ static int rvu_rep_setup_tc_cb(enum tc_setup_type type,
 	struct rep_dev *rep = cb_priv;
 	struct otx2_nic *priv = rep->mdev;
 
-	if (!(rep->flags & RVU_REP_VF_INITIALIZED))
+	if (!test_bit(OTX2_FLAG_REP_VF_INITIALIZED, &rep->flags))
 		return -EINVAL;
 
-	if (!(rep->flags & OTX2_FLAG_TC_FLOWER_SUPPORT))
+	if (!test_bit(OTX2_FLAG_TC_FLOWER_SUPPORT, &rep->flags))
 		rvu_rep_mcam_flow_init(rep);

[Severity: Medium]
This isn't a bug introduced by this patch, but does this leak rep->flow_cfg and rep->flow_cfg->flow_ent?

rvu_rep_mcam_flow_init() always assigns new kzalloc()/kcalloc() results to rep->flow_cfg and rep->flow_cfg->flow_ent. It only sets OTX2_FLAG_TC_FLOWER_SUPPORT when allocated > 0.

So if AF returns no entries, a mailbox call fails, or the flow_ent allocation fails, the next tc callback calls it again and the previous allocations are lost. The return value is also ignored here.

Separately, rvu_rep_destroy() only does kfree(rep->flow_cfg), so flow_ent is never freed on teardown.

drivers/net/ethernet/marvell/octeontx2/nic/rep.c static int rvu_rep_setup_tc_cb(enum tc_setup_type type, · line 119

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/rep.c +1 -1
 	priv->netdev = rep->netdev;
-	priv->flags = rep->flags;
+	otx2_sync_flags_from_rep(priv, &rep->flags);

[Severity: Medium]
Does this change how otx2_tc_del_flow() handles representor rules during teardown?

The old full-word assignment always cleared OTX2_FLAG_INTF_DOWN on priv, because rep->flags never carried that bit. With the mask, priv keeps its real INTF_DOWN value.

rvu_rep_destroy() sets INTF_DOWN before unregister_netdev(rep->netdev). Unregistering sends FLOW_CLS_DESTROY through this callback, and for police rules otx2_tc_del_flow() then skips the policer and mcast group cleanup:

    if (otx2_test_flag(nic, OTX2_FLAG_INTF_DOWN))
        goto free_mcam_flow;

otx2_free_hw_resources() skips cn10k_free_all_ipolicers() for otx2_rep_dev() devices, and AF's nix_lf_free handler doesn't free bandwidth profiles. Can each switch from switchdev to legacy mode leak ingress policer leaf profiles?

There is a similar change in rvu_rep_create(). Between register_netdev() and rvu_rep_napi_init(), otx2_tc_add_flow() now rejects representor offload with "Interface not initialized". Is that intended?

[ ... ]

drivers/net/ethernet/marvell/octeontx2/nic/rep.c static void rvu_rep_state_evt_handler(struct otx2_nic *priv, · line 309

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/rep.c +2 -2
@@ -303,9 +303,9 @@ static void rvu_rep_state_evt_handler(struct otx2_nic *priv,
 	rep_id = rvu_rep_get_repid(priv, info->pcifunc);
 	rep = priv->reps[rep_id];
 	if (info->evt_data.vf_state)
-		rep->flags |= RVU_REP_VF_INITIALIZED;
+		set_bit(OTX2_FLAG_REP_VF_INITIALIZED, &rep->flags);
 	else
-		rep->flags &= ~RVU_REP_VF_INITIALIZED;
+		clear_bit(OTX2_FLAG_REP_VF_INITIALIZED, &rep->flags);
 }

[Severity: Critical]
This is a pre-existing issue, but what happens here when rvu_rep_get_repid() doesn't find info->pcifunc? It returns -EINVAL:

    for (rep_id = 0; rep_id < priv->rep_cnt; rep_id++)
        if (priv->rep_pf_map[rep_id] == pcifunc)
            return rep_id;
    return -EINVAL;

In that case priv->reps[-22] is read from memory before the array, and set_bit() or clear_bit() writes through that pointer. priv->reps can also be NULL before switchdev mode is enabled. It can also be freed memory, because rvu_rep_destroy() calls kfree() on it without setting it to NULL.

Can a VF reach this? AF's rvu_mbox_handler_rep_event_notify() only checks is_pf_func_valid(). rvu_rep_up_notify() forwards the sender's event bits and only sets the header pcifunc:

    msg->hdr.pcifunc = event->pcifunc;
    msg->event = event->event;

So the body pcifunc arrives as 0. A REP_EVENT_NOTIFY with event=RVU_EVENT_PFVF_STATE aimed at the representor PF would reach this handler through otx2_mbox_up_handler_rep_event_up_notify()->rvu_event_up_notify(), and the lookup would miss.

Should rep_id be checked here, and should AF validate the sender?

[ ... ]

drivers/net/ethernet/marvell/octeontx2/nic/rep.c static void rvu_rep_get_stats64(struct net_device *dev, · line 388

Quoted 9 lines
drivers/net/ethernet/marvell/octeontx2/nic/rep.c +1 -1
@@ -382,7 +382,7 @@ static void rvu_rep_get_stats64(struct net_device *dev,
 {
 	struct rep_dev *rep = netdev_priv(dev);
 
-	if (!(rep->flags & RVU_REP_VF_INITIALIZED))
+	if (!test_bit(OTX2_FLAG_REP_VF_INITIALIZED, &rep->flags))
 		return;
 
 	stats->rx_packets = rep->stats.rx_frames;

[Severity: High]
This isn't a bug introduced by this patch, but is rep->stats_wrk ever cancelled? rvu_rep_get_stats64() ends with:

    schedule_delayed_work(&rep->stats_wrk, msecs_to_jiffies(100));

The only cancel_delayed_work_sync() in rep.c is for priv->refill_wrk.

rvu_rep_destroy() and the rvu_rep_create() error unwind both call free_netdev(rep->netdev). That frees the rep_dev (netdev_priv) while the delayed work embedded in it may still be pending. unregister_netdev() itself sends link notifications that call ndo_get_stats64, so the work is likely armed during teardown.

Wouldn't rvu_rep_get_stats() then run about 100ms later on freed memory?

    rep = container_of(del_work, struct rep_dev, stats_wrk);
    priv = rep->mdev;

[ ... ]

drivers/net/ethernet/marvell/octeontx2/nic/rep.c void rvu_rep_destroy(struct otx2_nic *priv) · line 638

Quoted 9 lines
drivers/net/ethernet/marvell/octeontx2/nic/rep.c +1 -1
@@ -632,7 +632,7 @@ void rvu_rep_destroy(struct otx2_nic *priv)
 	int rep_id;
 
 	rvu_eswitch_config(priv, false);
-	priv->flags |= OTX2_FLAG_INTF_DOWN;
+	otx2_set_flag(priv, OTX2_FLAG_INTF_DOWN);
 	rvu_rep_free_cq_rsrc(priv);
 	for (rep_id = 0; rep_id < priv->rep_cnt; rep_id++) {
 		rep = priv->reps[rep_id];

[Severity: High]
This is a pre-existing issue, but the rest of this loop does:

        unregister_netdev(rep->netdev);
        rvu_rep_devlink_port_unregister(rep);
        free_netdev(rep->netdev);
        kfree(rep->flow_cfg);

rep comes from netdev_priv() of a netdev that rvu_rep_create() allocated with alloc_etherdev(sizeof(*rep)). Isn't rep->flow_cfg read after free_netdev() has already freed that memory?

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261109033154.2161803-1-rkannoth%40marvell.com
author maintainer
#4 lore raw

Re: [PATCH v21 net-next 1/2] octeontx2: use atomic bitops for PF/VF and rep flags

Quoted 4 lines · On 2026-11-12 at 03:02:28, [email protected]…

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

Critical: 0 (1) · High: 1 (4) · Medium: 2 (1) · Low: 1

v21 is RESEND of v20

v20 sashiko comments reply : https://lore.kernel.org/netdev/atV60YxlUUmKoOD7@rkannoth-OptiPlex-7090/

Quoted 405 lines

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).

- [High] otx2_sync_flags_from_rep() (drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h) is the only…
- [Medium] The commit message hides that this patch fixes a real bug, and it has no Fixes: tag.
- [Medium] Before this patch, priv->flags = rep->flags always cleared OTX2_FLAG_INTF_DOWN on the eswitch PF context before calling into the…
- [Low] The commit message says the flags now use atomic bitops and that otx2_sync_flags_from_rep() publishes representor flags "without…

Pre-existing issues:
- [Critical] rvu_rep_state_evt_handler() (drivers/net/ethernet/marvell/octeontx2/nic/rep.c) does `rep_id =…
- [High] rep->stats_wrk is set up with INIT_DELAYED_WORK in rvu_rep_create().
- [High] In rvu_rep_destroy() (drivers/net/ethernet/marvell/octeontx2/nic/rep.c),…
- [High] rvu_rep_mcam_flow_init() (drivers/net/ethernet/marvell/octeontx2/nic/rep.c) builds and sends…
- [High] Any PF or VF, including a VF owned by a guest since the PF forwards all VF mbox messages to AF, can send REP_EVENT_NOTIFY with…
- [Medium] rvu_rep_setup_tc_cb() calls rvu_rep_mcam_flow_init(rep) on every tc callback while OTX2_FLAG_TC_FLOWER_SUPPORT is clear in…

--

octeontx2: use atomic bitops for PF/VF and rep flags

This converts the otx2_nic and rep_dev flags from u64 masks to unsigned long bitmaps, updated through set_bit()/clear_bit()/test_bit() helpers. In rvu_rep_setup_tc_cb(), the full-word assignment is replaced by otx2_sync_flags_from_rep(), which copies a mask of representor-owned bits onto the eswitch PF context. The representor VF-initialized flag moves from BIT_ULL(0) in rep.h to OTX2_FLAG_REP_VF_INITIALIZED (bit 21).

Quoted 5 lines

Switch PF/VF and representor flags from non-atomic u64 masks to unsigned long bitmaps with set_bit/clear_bit/test_bit. Add helpers and otx2_sync_flags_from_rep() to publish representor-owned flags onto the PF mailbox context with a masked WRITE_ONCE, giving lockless NAPI readers a consistent word without clearing PF-owned bits.

[Severity: Low]
Is "without clearing PF-owned bits" accurate? otx2_sync_flags_from_rep() does a plain READ_ONCE()/mask/WRITE_ONCE() read-modify-write of dst->flags. Every other writer of that word now uses set_bit() or clear_bit().

If an atomic update to a PF-owned bit lands between the read and the write, it gets overwritten. So the guarantee only holds when nothing else is writing at the same time. There are more details on this below, at otx2_sync_flags_from_rep().

Could the commit message also say which concurrent update problem the atomic conversion is meant to fix?

Quoted 2 lines

Relocate representor VF initialization to OTX2_FLAG_REP_VF_INITIALIZED (bit 21).

[Severity: Medium]
Is this only a relocation? Before this patch, rvu_rep_setup_tc_cb() did:

    priv->flags = rep->flags;

That overwrote the whole flags word of the eswitch PF otx2_nic, including OTX2_FLAG_REP_MODE_ENABLED, which rvu_rep_probe() sets.

The removed RVU_REP_VF_INITIALIZED was also BIT_ULL(0), the same bit as OTX2_FLAG_RX_TSTAMP_ENABLED. The callback only gets past its first check when that bit is set, so the bit was copied onto priv every time.

Once REP_MODE_ENABLED was cleared, otx2_tx_napi_handler() stopped taking these branches:

    if (otx2_test_flag(pfvf, OTX2_FLAG_REP_MODE_ENABLED))
        ndev = pfvf->reps[qidx]->netdev;
    ...
    if (otx2_test_flag(pfvf, OTX2_FLAG_REP_MODE_ENABLED))
        qidx = 0;
    txq = netdev_get_tx_queue(ndev, qidx);

Instead it fell back to pfvf->netdev, which rvu_rep_setup_tc_cb() had pointed at rep->netdev. That netdev comes from alloc_etherdev() and has a single TX queue, and qidx was no longer clamped. Doesn't that index past dev->_tx[] and then write DQL state beyond it?

If so, this patch includes a fix. Would a Fixes: tag and a description of the old behaviour help with stable backports?

The mask also changes one more behaviour: OTX2_FLAG_TC_MARK_ENABLED now stays set in priv instead of being cleared on every representor tc callback. Is that intended, and is it worth mentioning in the commit message?

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +0 -0
index 8417af94a02a0..f3158e293d864 100644

[ ... ]

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +0 -0
@@ -593,6 +607,32 @@ struct otx2_nic {
 	unsigned long		*af_xdp_zc_qidx;
 };
 

[ ... ]

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h struct otx2_nic { · line 634

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +10 -0
+static inline void otx2_sync_flags_from_rep(struct otx2_nic *dst,
+					    unsigned long *src_flags)
+{
+	unsigned long src = READ_ONCE(*src_flags);
+	unsigned long new_flags;
+
+	new_flags = (READ_ONCE(dst->flags) & ~OTX2_REP_SYNC_FLAGS_MASK) |
+		    (src & OTX2_REP_SYNC_FLAGS_MASK);
+	WRITE_ONCE(dst->flags, new_flags);
+}

[Severity: High]
Can this lose concurrent updates to PF-owned bits in priv->flags?

The only caller is rvu_rep_setup_tc_cb(), which runs from the tc block callback under rtnl. Other writers of the same word don't hold rtnl. One example is the devlink eswitch path:

otx2_devlink_eswitch_mode_set()

    case DEVLINK_ESWITCH_MODE_LEGACY:
        rvu_rep_destroy(pfvf);
            otx2_set_flag(priv, OTX2_FLAG_INTF_DOWN);

This runs under the devlink lock only; unregister_netdev() takes rtnl later. rvu_rep_napi_init() clears INTF_DOWN on the same devlink path, and the mbox up-handler work sets and clears OTX2_FLAG_PORT_UP.

If one of those set_bit()/clear_bit() calls lands between the READ_ONCE() and the WRITE_ONCE() here, the stale word gets written back.

If the INTF_DOWN set is lost, the eswitch PF still looks up after teardown. otx2_napi_handler() can then re-arm the CINT, and rvu_rep_remove() runs destroy a second time:

    if (!otx2_test_flag(priv, OTX2_FLAG_INTF_DOWN))
        rvu_rep_destroy(priv);

That second destroy calls unregister_netdev()/free_netdev() on netdevs that are already freed, and calls kfree(priv->reps) a second time.

If the INTF_DOWN clear in rvu_rep_napi_init() is lost instead, the CQ interrupts are never re-enabled, because otx2_napi_handler() returns early:

    if (otx2_test_flag(pfvf, OTX2_FLAG_INTF_DOWN))
        return workdone;

Would updating only the masked bits with assign_bit(), or using a cmpxchg loop, avoid this?

[ ... ]

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +0 -0
index 7dc0ce669d0b7..777e7156badb7 100644

[ ... ]

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +0 -0
@@ -907,11 +907,11 @@ static int otx2_mbox_up_handler_rep_event_up_notify(struct otx2_nic *pf,
 
 	if (info->event == RVU_EVENT_PORT_STATE) {
 		if (info->evt_data.port_state) {

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c static int otx2_mbox_up_handler_rep_event_up_notify(struct otx2_nic *pf, · line 917

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +2 -2
-			pf->flags |= OTX2_FLAG_PORT_UP;
+			otx2_set_flag(pf, OTX2_FLAG_PORT_UP);
 			netif_carrier_on(netdev);
 			netif_tx_start_all_queues(netdev);
 		} else {
-			pf->flags &= ~OTX2_FLAG_PORT_UP;
+			otx2_clear_flag(pf, OTX2_FLAG_PORT_UP);
 			netif_tx_stop_all_queues(netdev);
 			netif_carrier_off(netdev);
 		}

[Severity: High]
This isn't a bug introduced by this patch, but can any PF or VF forge this event for a PF it doesn't own?

On the AF side, rvu_mbox_handler_rep_event_notify() only range-checks the target:

    if (!is_pf_func_valid(rvu, req->pcifunc))
        return -EINVAL;

It doesn't check that the sender is rvu->rep_pcifunc. rvu_rep_up_notify() then forwards the event and evt_data to rvu_get_pf(event->pcifunc). The PF forwards VF mailbox messages to AF through otx2_forward_vf_mbox_msgs(), so a VF owned by a guest can send this as well.

On the victim PF, port_state=0 stops TX and drops carrier. port_state=1 sets OTX2_FLAG_PORT_UP, and from then on otx2_handle_link_event() ignores real CGX link events until the next otx2_open():

    if (otx2_test_flag(pf, OTX2_FLAG_PORT_UP))
        return;

Should AF reject REP_EVENT_NOTIFY from anything other than the representor PF?

[ ... ]

Quoted 5 lines
drivers/net/ethernet/marvell/octeontx2/nic/rep.c +0 -0
index 0f5d5642d3f7a..7df82c22cc12b 100644

drivers/net/ethernet/marvell/octeontx2/nic/rep.c static int rvu_rep_mcam_flow_init(struct rep_dev *rep) · line 99

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/rep.c +3 -3
@@ -93,9 +93,9 @@ static int rvu_rep_mcam_flow_init(struct rep_dev *rep)
 	rep->flow_cfg->max_flows = allocated;
 
 	if (allocated) {
-		rep->flags |= OTX2_FLAG_MCAM_ENTRIES_ALLOC;
-		rep->flags |= OTX2_FLAG_NTUPLE_SUPPORT;
-		rep->flags |= OTX2_FLAG_TC_FLOWER_SUPPORT;
+		set_bit(OTX2_FLAG_MCAM_ENTRIES_ALLOC, &rep->flags);
+		set_bit(OTX2_FLAG_NTUPLE_SUPPORT, &rep->flags);
+		set_bit(OTX2_FLAG_TC_FLOWER_SUPPORT, &rep->flags);
 	}

[Severity: High]
This is a pre-existing issue, but where does rvu_rep_mcam_flow_init() take priv->mbox.lock? The loop allocates and sends NPC_MCAM_ALLOC_ENTRY messages on priv->mbox without the lock, and the exit path then does:

exit:

    ...
    mutex_unlock(&priv->mbox.lock);

Neither this function nor rvu_rep_setup_tc_cb() calls mutex_lock().

Suppose another context holds the mutex at that point, such as the rvu_rep_get_stats() worker. Doesn't this release that holder's lock and let mailbox messages from both contexts interleave? If nobody holds it, this is an unbalanced unlock, which lockdep would report.

drivers/net/ethernet/marvell/octeontx2/nic/rep.c static int rvu_rep_setup_tc_cb(enum tc_setup_type type, · line 116

Quoted 11 lines
drivers/net/ethernet/marvell/octeontx2/nic/rep.c +2 -2
@@ -109,14 +109,14 @@ static int rvu_rep_setup_tc_cb(enum tc_setup_type type,
 	struct rep_dev *rep = cb_priv;
 	struct otx2_nic *priv = rep->mdev;
 
-	if (!(rep->flags & RVU_REP_VF_INITIALIZED))
+	if (!test_bit(OTX2_FLAG_REP_VF_INITIALIZED, &rep->flags))
 		return -EINVAL;
 
-	if (!(rep->flags & OTX2_FLAG_TC_FLOWER_SUPPORT))
+	if (!test_bit(OTX2_FLAG_TC_FLOWER_SUPPORT, &rep->flags))
 		rvu_rep_mcam_flow_init(rep);

[Severity: Medium]
This isn't a bug introduced by this patch, but does this leak rep->flow_cfg and rep->flow_cfg->flow_ent?

rvu_rep_mcam_flow_init() always assigns new kzalloc()/kcalloc() results to rep->flow_cfg and rep->flow_cfg->flow_ent. It only sets OTX2_FLAG_TC_FLOWER_SUPPORT when allocated > 0.

So if AF returns no entries, a mailbox call fails, or the flow_ent allocation fails, the next tc callback calls it again and the previous allocations are lost. The return value is also ignored here.

Separately, rvu_rep_destroy() only does kfree(rep->flow_cfg), so flow_ent is never freed on teardown.

drivers/net/ethernet/marvell/octeontx2/nic/rep.c static int rvu_rep_setup_tc_cb(enum tc_setup_type type, · line 119

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/rep.c +1 -1
 	priv->netdev = rep->netdev;
-	priv->flags = rep->flags;
+	otx2_sync_flags_from_rep(priv, &rep->flags);

[Severity: Medium]
Does this change how otx2_tc_del_flow() handles representor rules during teardown?

The old full-word assignment always cleared OTX2_FLAG_INTF_DOWN on priv, because rep->flags never carried that bit. With the mask, priv keeps its real INTF_DOWN value.

rvu_rep_destroy() sets INTF_DOWN before unregister_netdev(rep->netdev). Unregistering sends FLOW_CLS_DESTROY through this callback, and for police rules otx2_tc_del_flow() then skips the policer and mcast group cleanup:

    if (otx2_test_flag(nic, OTX2_FLAG_INTF_DOWN))
        goto free_mcam_flow;

otx2_free_hw_resources() skips cn10k_free_all_ipolicers() for otx2_rep_dev() devices, and AF's nix_lf_free handler doesn't free bandwidth profiles. Can each switch from switchdev to legacy mode leak ingress policer leaf profiles?

There is a similar change in rvu_rep_create(). Between register_netdev() and rvu_rep_napi_init(), otx2_tc_add_flow() now rejects representor offload with "Interface not initialized". Is that intended?

[ ... ]

drivers/net/ethernet/marvell/octeontx2/nic/rep.c static void rvu_rep_state_evt_handler(struct otx2_nic *priv, · line 309

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/rep.c +2 -2
@@ -303,9 +303,9 @@ static void rvu_rep_state_evt_handler(struct otx2_nic *priv,
 	rep_id = rvu_rep_get_repid(priv, info->pcifunc);
 	rep = priv->reps[rep_id];
 	if (info->evt_data.vf_state)
-		rep->flags |= RVU_REP_VF_INITIALIZED;
+		set_bit(OTX2_FLAG_REP_VF_INITIALIZED, &rep->flags);
 	else
-		rep->flags &= ~RVU_REP_VF_INITIALIZED;
+		clear_bit(OTX2_FLAG_REP_VF_INITIALIZED, &rep->flags);
 }

[Severity: Critical]
This is a pre-existing issue, but what happens here when rvu_rep_get_repid() doesn't find info->pcifunc? It returns -EINVAL:

    for (rep_id = 0; rep_id < priv->rep_cnt; rep_id++)
        if (priv->rep_pf_map[rep_id] == pcifunc)
            return rep_id;
    return -EINVAL;

In that case priv->reps[-22] is read from memory before the array, and set_bit() or clear_bit() writes through that pointer. priv->reps can also be NULL before switchdev mode is enabled. It can also be freed memory, because rvu_rep_destroy() calls kfree() on it without setting it to NULL.

Can a VF reach this? AF's rvu_mbox_handler_rep_event_notify() only checks is_pf_func_valid(). rvu_rep_up_notify() forwards the sender's event bits and only sets the header pcifunc:

    msg->hdr.pcifunc = event->pcifunc;
    msg->event = event->event;

So the body pcifunc arrives as 0. A REP_EVENT_NOTIFY with event=RVU_EVENT_PFVF_STATE aimed at the representor PF would reach this handler through otx2_mbox_up_handler_rep_event_up_notify()->rvu_event_up_notify(), and the lookup would miss.

Should rep_id be checked here, and should AF validate the sender?

[ ... ]

drivers/net/ethernet/marvell/octeontx2/nic/rep.c static void rvu_rep_get_stats64(struct net_device *dev, · line 388

Quoted 9 lines
drivers/net/ethernet/marvell/octeontx2/nic/rep.c +1 -1
@@ -382,7 +382,7 @@ static void rvu_rep_get_stats64(struct net_device *dev,
 {
 	struct rep_dev *rep = netdev_priv(dev);
 
-	if (!(rep->flags & RVU_REP_VF_INITIALIZED))
+	if (!test_bit(OTX2_FLAG_REP_VF_INITIALIZED, &rep->flags))
 		return;
 
 	stats->rx_packets = rep->stats.rx_frames;

[Severity: High]
This isn't a bug introduced by this patch, but is rep->stats_wrk ever cancelled? rvu_rep_get_stats64() ends with:

    schedule_delayed_work(&rep->stats_wrk, msecs_to_jiffies(100));

The only cancel_delayed_work_sync() in rep.c is for priv->refill_wrk.

rvu_rep_destroy() and the rvu_rep_create() error unwind both call free_netdev(rep->netdev). That frees the rep_dev (netdev_priv) while the delayed work embedded in it may still be pending. unregister_netdev() itself sends link notifications that call ndo_get_stats64, so the work is likely armed during teardown.

Wouldn't rvu_rep_get_stats() then run about 100ms later on freed memory?

    rep = container_of(del_work, struct rep_dev, stats_wrk);
    priv = rep->mdev;

[ ... ]

drivers/net/ethernet/marvell/octeontx2/nic/rep.c void rvu_rep_destroy(struct otx2_nic *priv) · line 638

Quoted 9 lines
drivers/net/ethernet/marvell/octeontx2/nic/rep.c +1 -1
@@ -632,7 +632,7 @@ void rvu_rep_destroy(struct otx2_nic *priv)
 	int rep_id;
 
 	rvu_eswitch_config(priv, false);
-	priv->flags |= OTX2_FLAG_INTF_DOWN;
+	otx2_set_flag(priv, OTX2_FLAG_INTF_DOWN);
 	rvu_rep_free_cq_rsrc(priv);
 	for (rep_id = 0; rep_id < priv->rep_cnt; rep_id++) {
 		rep = priv->reps[rep_id];

[Severity: High]
This is a pre-existing issue, but the rest of this loop does:

        unregister_netdev(rep->netdev);
        rvu_rep_devlink_port_unregister(rep);
        free_netdev(rep->netdev);
        kfree(rep->flow_cfg);

rep comes from netdev_priv() of a netdev that rvu_rep_create() allocated with alloc_etherdev(sizeof(*rep)). Isn't rep->flow_cfg read after free_netdev() has already freed that memory?

[ ... ]

--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261109033154.2161803-1-rkannoth%40marvell.com

author maintainer
#5 lore raw

PATCH v21 2/2 octeontx2: add mqprio bandwidth offload for NIX TX schedulers

In reply to Ratheesh Kannoth

Add TC_SETUP_QDISC_MQPRIO offload with TC_MQPRIO_SHAPER_BW_RATE on PF and VF netdevs. Program per-queue MDQ CIR/PIR via the NIX TX scheduler mailbox; when active, allocate one SMQ per non-QoS queue under TL4[0].

The TX scheduler cannot be reprogrammed live, so add/replace/delete and failed setup bounce the netdev through ndo_stop()/ndo_open(). Cache rates in software and restore them from otx2_mqprio_up() on open, failing closed on error.

Stage tc replace in mq_offload_snap snapshots committed on TC_ROOT_GRAFT or replaced-qdisc teardown.

Require a running interface with CIR+PIR support. Reject offload with PFC, XDP, HTB, SDP representors, per-TC rates on multi-queue classes, and ethtool channel changes while active.

---
 .../marvell/octeontx2/nic/otx2_common.c       | 143 ++-
 .../marvell/octeontx2/nic/otx2_common.h       |  34 +
 .../marvell/octeontx2/nic/otx2_dcbnl.c        |   6 +
 .../marvell/octeontx2/nic/otx2_ethtool.c      |   8 +
 .../ethernet/marvell/octeontx2/nic/otx2_pf.c  |  34 +-
 .../ethernet/marvell/octeontx2/nic/otx2_tc.c  | 936 ++++++++++++++++++
 .../ethernet/marvell/octeontx2/nic/otx2_vf.c  |  28 +-
 .../net/ethernet/marvell/octeontx2/nic/qos.c  |  11 +
 8 files changed, 1179 insertions(+), 21 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +142 -1
index f4047b0d5d96..b4a738cf9a8b 100644
@@ -615,6 +615,139 @@ void otx2_get_mac_from_af(struct net_device *netdev)
 }
 EXPORT_SYMBOL(otx2_get_mac_from_af);
 
+static int
+otx2_nix_tmq_reg_write(struct otx2_nic *pfvf, int cnt,
+		       u64 reg_addr[MAX_REGS_PER_MBOX_MSG],
+		       u64 reg_val[MAX_REGS_PER_MBOX_MSG])
+{
+	struct mbox *mbox = &pfvf->mbox;
+	struct nix_txschq_config *req;
+	int i, err;
+
+	mutex_lock(&mbox->lock);
+	req = otx2_mbox_alloc_msg_nix_txschq_cfg(mbox);
+	if (!req) {
+		mutex_unlock(&mbox->lock);
+		return -ENOMEM;
+	}
+
+	req->lvl = NIX_TXSCH_LVL_MDQ;
+	req->num_regs = cnt;
+
+	for (i = 0; i < cnt; i++) {
+		req->reg[i] = reg_addr[i];
+		req->regval[i] = reg_val[i];
+	}
+
+	err = otx2_sync_mbox_msg(mbox);
+	mutex_unlock(&mbox->lock);
+
+	return err;
+}
+
+int otx2_nix_tm_clear_queue_shaper(struct otx2_nic *pfvf)
+{
+	u64 reg_addr[MAX_REGS_PER_MBOX_MSG];
+	u64 reg_val[MAX_REGS_PER_MBOX_MSG];
+	int err, smq, i, cnt = 0;
+
+	for (i = 0; i < pfvf->hw.txschq_cnt[NIX_TXSCH_LVL_SMQ]; i++) {
+		smq = pfvf->hw.txschq_list[NIX_TXSCH_LVL_SMQ][i];
+
+		reg_addr[cnt] = NIX_AF_MDQX_PIR(smq);
+		reg_val[cnt] = 0;
+		cnt++;
+
+		reg_addr[cnt] = NIX_AF_MDQX_CIR(smq);
+		reg_val[cnt] = 0;
+		cnt++;
+
+		if (cnt < MAX_REGS_PER_MBOX_MSG - 1)
+			continue;
+
+		err = otx2_nix_tmq_reg_write(pfvf, cnt,
+					     reg_addr, reg_val);
+		if (err)
+			goto fail;
+		cnt = 0;
+	}
+
+	if (cnt) {
+		err = otx2_nix_tmq_reg_write(pfvf, cnt,
+					     reg_addr, reg_val);
+		if (err)
+			goto fail;
+	}
+
+	return 0;
+fail:
+	return err;
+}
+
+int otx2_nix_tm_set_queue_shaper(struct otx2_nic *pfvf,
+				 int txq, u64 minrate, u64 maxrate)
+{
+	struct mbox *mbox = &pfvf->mbox;
+	struct nix_txschq_config *req;
+	int err, smq, n = 0;
+	u64 reg_addr[2];
+	u64 reg_val[2];
+	u64 rate;
+
+	if (!maxrate && !minrate) {
+		smq = otx2_get_smq_idx(pfvf, txq);
+		reg_addr[0] = NIX_AF_MDQX_PIR(smq);
+		reg_val[0] = 0;
+		reg_addr[1] = NIX_AF_MDQX_CIR(smq);
+		reg_val[1] = 0;
+		return otx2_nix_tmq_reg_write(pfvf, 2, reg_addr, reg_val);
+	}
+
+	smq = otx2_get_smq_idx(pfvf, txq);
+
+	mutex_lock(&mbox->lock);
+	req = otx2_mbox_alloc_msg_nix_txschq_cfg(mbox);
+	if (!req) {
+		mutex_unlock(&mbox->lock);
+		return -ENOMEM;
+	}
+
+	req->lvl = NIX_TXSCH_LVL_MDQ;
+
+	/* MQPRIO exposes only min/max rate, not burst.  Use the same 65536
+	 * byte default as the HTB shaper path.
+	 *
+	 * mqprio setup restarts the netdev (otx2_mqprio_restart_netdev);
+	 * ndo_open() may restore cached MDQ shapers via otx2_mqprio_up(), and
+	 * setup clears every MDQ shaper before applying the new mapping.
+	 * Program both PIR and CIR on every update so omitted rates are
+	 * applied explicitly rather than relying on stale hardware state.
+	 */
+	req->reg[n] = NIX_AF_MDQX_PIR(smq);
+	if (maxrate) {
+		rate = otx2_convert_rate(maxrate);
+		req->regval[n] = otx2_get_txschq_rate_regval(pfvf, rate, 65536);
+	} else {
+		req->regval[n] = 0;
+	}
+	n++;
+
+	/* CIR+PIR support is required and checked at mqprio setup. */
+	req->reg[n] = NIX_AF_MDQX_CIR(smq);
+	if (minrate) {
+		rate = otx2_convert_rate(minrate);
+		req->regval[n] = otx2_get_txschq_rate_regval(pfvf, rate, 65536);
+	} else {
+		req->regval[n] = 0;
+	}
+	n++;
+	req->num_regs = n;
+
+	err = otx2_sync_mbox_msg(mbox);
+	mutex_unlock(&mbox->lock);
+	return err;
+}
+
 int otx2_txschq_config(struct otx2_nic *pfvf, int lvl, int prio, bool txschq_for_pfc)
 {
 	u16 (*schq_list)[MAX_TXSCHQ_PER_FUNC];
@@ -651,7 +784,11 @@ int otx2_txschq_config(struct otx2_nic *pfvf, int lvl, int prio, bool txschq_for
 						(u64)hw->smq_link_type);
 		req->num_regs++;
 		/* MDQ config */
-		parent = schq_list[NIX_TXSCH_LVL_TL4][prio];
+		if (pfvf->mqprio.rate_limit)
+			parent = schq_list[NIX_TXSCH_LVL_TL4][0];
+		else
+			parent = schq_list[NIX_TXSCH_LVL_TL4][prio];
+
 		req->reg[1] = NIX_AF_MDQX_PARENT(schq);
 		req->regval[1] = parent << 16;
 		req->num_regs++;
@@ -777,6 +914,9 @@ int otx2_txsch_alloc(struct otx2_nic *pfvf)
 		req->schq[NIX_TXSCH_LVL_TL4] = chan_cnt;
 	}
 
+	if (pfvf->mqprio.rate_limit)
+		req->schq[NIX_TXSCH_LVL_SMQ] = pfvf->hw.non_qos_queues;
+
 	rc = otx2_sync_mbox_msg(&pfvf->mbox);
 	if (rc)
 		return rc;
@@ -841,6 +981,7 @@ void otx2_txschq_stop(struct otx2_nic *pfvf)
 
 	/* Clear the txschq list */
 	for (lvl = 0; lvl < NIX_TXSCH_LVL_CNT; lvl++) {
+		pfvf->hw.txschq_cnt[lvl] = 0;
 		for (schq = 0; schq < MAX_TXSCHQ_PER_FUNC; schq++)
 			pfvf->hw.txschq_list[lvl][schq] = 0;
 	}
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +34 -0
index f3158e293d86..dc635b246d64 100644
@@ -17,6 +17,7 @@
 #include <linux/soc/marvell/silicons.h>
 #include <linux/soc/marvell/octeontx2/asm.h>
 #include <net/macsec.h>
+#include <uapi/linux/pkt_sched.h>
 #include <net/pkt_cls.h>
 #include <net/devlink.h>
 #include <linux/time64.h>
@@ -517,6 +518,27 @@ enum otx2_flag_bits {
 	 BIT(OTX2_FLAG_TC_FLOWER_SUPPORT) |			\
 	 BIT(OTX2_FLAG_REP_VF_INITIALIZED))
 
+struct mq_offload_snap {
+	u64 min_rate[TC_QOPT_MAX_QUEUE];
+	u64 max_rate[TC_QOPT_MAX_QUEUE];
+	u32 flags;
+	__u8 num_tc;
+	__u16 count[TC_QOPT_MAX_QUEUE];
+	__u16 offset[TC_QOPT_MAX_QUEUE];
+	__u8 prio_tc_map[TC_QOPT_BITMASK + 1];
+};
+
+struct otx2_mqprio {
+	u32	flags;
+	u64	*min_rate;
+	u64	*max_rate;
+	bool	rate_limit;
+	bool	replace_setup_done;
+	bool	replace_graft_done;
+	bool	defer_tc_work;
+	struct work_struct netdev_tc_work;
+};
+
 struct otx2_nic {
 	void __iomem		*reg_base;
 	struct net_device	*netdev;
@@ -528,6 +550,10 @@ struct otx2_nic {
 	unsigned long		flags;
 	u64			*cq_op_addr;
 
+	struct otx2_mqprio	mqprio;
+	struct mq_offload_snap	*cur_mq_snap;
+	struct mq_offload_snap	*old_mq_snap;
+
 	struct bpf_prog		*xdp_prog;
 	struct otx2_qset	qset;
 	struct otx2_hw		hw;
@@ -1036,6 +1062,8 @@ static inline u16 otx2_get_smq_idx(struct otx2_nic *pfvf, u16 qidx)
 	if (qidx >= pfvf->hw.non_qos_queues) {
 		smq = pfvf->qos.qid_to_sqmap[qidx - pfvf->hw.non_qos_queues];
 	} else {
+		if (!pfvf->hw.txschq_cnt[NIX_TXSCH_LVL_SMQ])
+			return 0;
 		idx = qidx % pfvf->hw.txschq_cnt[NIX_TXSCH_LVL_SMQ];
 		smq = pfvf->hw.txschq_list[NIX_TXSCH_LVL_SMQ][idx];
 	}
@@ -1223,6 +1251,7 @@ int otx2_mcam_entry_init(struct otx2_nic *pfvf);
 
 /* tc support */
 int otx2_init_tc(struct otx2_nic *nic);
+void otx2_shutdown_tc_mqprio(struct otx2_nic *nic);
 void otx2_shutdown_tc(struct otx2_nic *nic);
 int otx2_setup_tc(struct net_device *netdev, enum tc_setup_type type,
 		  void *type_data);
@@ -1295,6 +1324,11 @@ dma_addr_t otx2_dma_map_skb_frag(struct otx2_nic *pfvf,
 void otx2_dma_unmap_skb_frags(struct otx2_nic *pfvf, struct sg_list *sg,
 			      struct sk_buff *skb);
 int otx2_read_free_sqe(struct otx2_nic *pfvf, u16 qidx);
+int otx2_nix_tm_set_queue_shaper(struct otx2_nic *pfvf, int txq,
+				 u64 minrate, u64 maxrate);
+int otx2_nix_tm_clear_queue_shaper(struct otx2_nic *pfvf);
+int otx2_mqprio_down(struct otx2_nic *pfvf);
+int otx2_mqprio_up(struct otx2_nic *pfvf);
 void otx2_queue_vf_work(struct mbox *mw, struct workqueue_struct *mbox_wq,
 			int first, int mdevs, u64 intr);
 int otx2_del_mcam_flow_entry(struct otx2_nic *nic, u16 entry,
drivers/net/ethernet/marvell/octeontx2/nic/otx2_dcbnl.c +6 -0
index e3d54009180d..851bf3fd5bab 100644
@@ -408,6 +408,12 @@ static int otx2_dcbnl_ieee_setpfc(struct net_device *dev, struct ieee_pfc *pfc)
 	u8 old_pfc_en;
 	int err;
 
+	if (pfvf->mqprio.rate_limit && pfc->pfc_en) {
+		netdev_err(dev,
+			   "PFC: cannot enable while mqprio bandwidth offload is active\n");
+		return -EOPNOTSUPP;
+	}
+
 	old_pfc_en = pfvf->pfc_en;
 	pfvf->pfc_en = pfc->pfc_en;
 
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +8 -0
index 4fe473d9ea0d..5428b3d1b332 100644
@@ -287,6 +287,14 @@ static int otx2_set_channels(struct net_device *dev,
 		return -EINVAL;
 	}
 
+	if (pfvf->mqprio.rate_limit &&
+	    (channel->tx_count != pfvf->hw.tx_queues ||
+	     channel->rx_count != pfvf->hw.rx_queues)) {
+		netdev_info(dev,
+			    "Not permitted to change channel count while MQ prio is active\n");
+		return -EINVAL;
+	}
+
 	if (if_up)
 		dev->netdev_ops->ndo_stop(dev);
 
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +27 -7
index 777e7156badb..f51161e8b594 100644
@@ -2008,6 +2008,15 @@ int otx2_open(struct net_device *netdev)
 	if (err)
 		goto err_free_mem;
 
+	/* Fail closed: abort open if cached mqprio shapers cannot be restored. */
+	err = otx2_mqprio_up(pf);
+	if (err) {
+		netdev_err(pf->netdev,
+			   "mqprio: failed to restore shapers during open: %d\n",
+			   err);
+		goto err_free_hw;
+	}
+
 	/* Register NAPI handler */
 	for (qidx = 0; qidx < pf->hw.cint_cnt; qidx++) {
 		cq_poll = &qset->napi[qidx];
@@ -2206,6 +2215,7 @@ int otx2_open(struct net_device *netdev)
 	free_irq(vec, pf);
 err_disable_napi:
 	otx2_disable_napi(pf);
+err_free_hw:
 	otx2_free_hw_resources(pf);
 err_free_mem:
 	otx2_free_queue_mem(qset);
@@ -2281,6 +2291,7 @@ int otx2_stop(struct net_device *netdev)
 	for (qidx = 0; qidx < netdev->num_tx_queues; qidx++)
 		netdev_tx_reset_queue(netdev_get_tx_queue(netdev, qidx));
 
+	synchronize_net();
 	otx2_free_queue_mem(qset);
 	/* Do not clear RQ/SQ ringsize settings */
 	memset_startat(qset, 0, sqe_cnt);
@@ -2924,6 +2935,12 @@ static int otx2_xdp_setup(struct otx2_nic *pf, struct bpf_prog *prog)
 	bool if_up = netif_running(pf->netdev);
 	struct bpf_prog *old_prog;
 
+	if (prog && pf->mqprio.rate_limit) {
+		netdev_err(dev,
+			   "XDP: cannot attach while mqprio bandwidth offload is active\n");
+		return -EOPNOTSUPP;
+	}
+
 	if (prog && dev->mtu > MAX_XDP_MTU) {
 		netdev_warn(dev, "Jumbo frames not yet supported with XDP\n");
 		return -EOPNOTSUPP;
@@ -3368,10 +3385,14 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	if (err)
 		goto err_mcs_free;
 
+	err = otx2_init_tc(pf);
+	if (err)
+		goto err_ipsec_clean;
+
 	err = register_netdev(netdev);
 	if (err) {
 		dev_err(dev, "Failed to register netdevice\n");
-		goto err_ipsec_clean;
+		goto err_shutdown_tc;
 	}
 
 	err = otx2_wq_init(pf);
@@ -3380,10 +3401,6 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
 	otx2_set_ethtool_ops(netdev);
 
-	err = otx2_init_tc(pf);
-	if (err)
-		goto err_mcam_flow_del;
-
 	err = otx2_register_dl(pf);
 	if (err)
 		goto err_mcam_flow_del;
@@ -3420,11 +3437,13 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	otx2_sriov_vfcfg_cleanup(pf);
 err_pf_sriov_init:
 	otx2_unregister_dl(pf);
-	otx2_shutdown_tc(pf);
 err_mcam_flow_del:
 	otx2_mcam_flow_del(pf);
 err_unreg_netdev:
+	otx2_shutdown_tc_mqprio(pf);
 	unregister_netdev(netdev);
+err_shutdown_tc:
+	otx2_shutdown_tc(pf);
 err_ipsec_clean:
 	cn10k_ipsec_clean(pf);
 err_mcs_free:
@@ -3622,7 +3641,9 @@ static void otx2_remove(struct pci_dev *pdev)
 	otx2_cgx_config_linkevents(pf, false);
 
 	otx2_unregister_dl(pf);
+	otx2_shutdown_tc_mqprio(pf);
 	unregister_netdev(netdev);
+	otx2_shutdown_tc(pf);
 	cn10k_ipsec_clean(pf);
 	cn10k_mcs_free(pf);
 	otx2_sriov_disable(pf->pdev);
@@ -3632,7 +3653,6 @@ static void otx2_remove(struct pci_dev *pdev)
 
 	otx2_ptp_destroy(pf);
 	otx2_mcam_flow_del(pf);
-	otx2_shutdown_tc(pf);
 	otx2_shutdown_qos(pf);
 	otx2_ndc_sync(pf);
 	otx2_detach_resources(&pf->mbox);
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +936 -0

984 lines not on this page · raw message

drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c +15 -13
index 5f7915231ca3..6ca08b12520a 100644
@@ -740,25 +740,25 @@ static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	if (err)
 		goto err_ipsec_clean;
 
+	err = otx2vf_mcam_flow_init(vf);
+	if (err)
+		goto err_wq_destroy;
+
+	err = otx2_init_tc(vf);
+	if (err)
+		goto err_wq_destroy;
+
 	err = register_netdev(netdev);
 	if (err) {
 		dev_err(dev, "Failed to register netdevice\n");
-		goto err_wq_destroy;
+		goto err_shutdown_tc;
 	}
 
 	otx2vf_set_ethtool_ops(netdev);
 
-	err = otx2vf_mcam_flow_init(vf);
-	if (err)
-		goto err_unreg_netdev;
-
-	err = otx2_init_tc(vf);
-	if (err)
-		goto err_unreg_netdev;
-
 	err = otx2_register_dl(vf);
 	if (err)
-		goto err_shutdown_tc;
+		goto err_unreg_netdev;
 
 	vf->af_xdp_zc_qidx = bitmap_zalloc(qcount, GFP_KERNEL);
 	if (!vf->af_xdp_zc_qidx) {
@@ -784,10 +784,11 @@ static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 #endif
 err_unreg_devlink:
 	otx2_unregister_dl(vf);
-err_shutdown_tc:
-	otx2_shutdown_tc(vf);
 err_unreg_netdev:
+	otx2_shutdown_tc_mqprio(vf);
 	unregister_netdev(netdev);
+err_shutdown_tc:
+	otx2_shutdown_tc(vf);
 err_wq_destroy:
 	cancel_work_sync(&vf->reset_task);
 	cancel_work_sync(&vf->rx_mode_work);
@@ -840,7 +841,9 @@ static void otx2vf_remove(struct pci_dev *pdev)
 #endif
 
 	otx2_unregister_dl(vf);
+	otx2_shutdown_tc_mqprio(vf);
 	unregister_netdev(netdev);
+	otx2_shutdown_tc(vf);
 	if (vf->otx2_wq) {
 		cancel_work_sync(&vf->reset_task);
 		cancel_work_sync(&vf->rx_mode_work);
@@ -849,7 +852,6 @@ static void otx2vf_remove(struct pci_dev *pdev)
 	cn10k_ipsec_clean(vf);
 	otx2_ptp_destroy(vf);
 	otx2_mcam_flow_del(vf);
-	otx2_shutdown_tc(vf);
 	otx2_shutdown_qos(vf);
 	otx2_detach_resources(&vf->mbox);
 	otx2vf_disable_mbox_intr(vf);
drivers/net/ethernet/marvell/octeontx2/nic/qos.c +11 -0
index 2ede0b84e5f5..732fff75ab0b 100644
@@ -118,6 +118,9 @@ static void otx2_config_sched_shaping(struct otx2_nic *pfvf,
 	/* configure PIR */
 	maxrate = (node->rate > node->ceil) ? node->rate : node->ceil;
 
+	/* 65536 is the kernel-side default burst when HTB does not supply an
+	 * explicit value, not the NIX hardware maximum (CN10K_MAX_BURST_SIZE).
+	 */
 	cfg->regval[*num_regs] =
 		otx2_get_txschq_rate_regval(pfvf, maxrate, 65536);
 	(*num_regs)++;
@@ -1090,6 +1093,14 @@ static int otx2_qos_root_add(struct otx2_nic *pfvf, u16 htb_maj_id, u16 htb_defc
 		   "TC_HTB_CREATE: handle=0x%x defcls=0x%x\n",
 		   htb_maj_id, htb_defcls);
 
+	if (pfvf->mqprio.rate_limit) {
+		netdev_err(pfvf->netdev,
+			   "HTB: cannot enable while mqprio bandwidth offload is active\n");
+		NL_SET_ERR_MSG_MOD(extack,
+				   "HTB: cannot enable while mqprio bandwidth offload is active");
+		return -EOPNOTSUPP;
+	}
+
 	root = otx2_qos_alloc_root(pfvf);
 	if (IS_ERR(root)) {
 		err = PTR_ERR(root);
Signature · 1 line
2.43.0
#6 lore raw

Re: [PATCH v21 net-next 2/2] octeontx2: add mqprio bandwidth offload for NIX TX schedulers

Thank you for your contribution! Sashiko AI review found 7 potential issues to consider: - [Medium] octeontx2: otx2_teardown_tc_mqprio() commits aborted replace without graft - [Medium] octeontx2…

Thank you for your contribution! Sashiko AI review found 7 potential issues to consider:
- [Medium] octeontx2: otx2_teardown_tc_mqprio() commits aborted replace without graft
- [Medium] octeontx2: skipped netdev restart on shaper clear error in otx2_teardown_tc_mqprio()
- [Medium] octeontx2-pf: premature otx2_mcam_flow_del() in otx2_probe() error path
- [Medium] octeontx2: otx2_mqprio_clear_sw() wipes netdev TC layout on taprio replace
- [Medium] octeontx2: incomplete rollback and state loss in otx2_mqprio_restore_old()
- [Medium] octeontx2: broken mqprio replace rollback in otx2_mqprio_restart_netdev()
- [Medium] octeontx2: lost netdev TC state on rejected replace in otx2_setup_tc_mqprio()
--

commit 9864a43cee348b7e8d668cd98a7aae2752988212
Author: Ratheesh Kannoth <[email protected]>

octeontx2: add mqprio bandwidth offload for NIX TX schedulers

This commit adds TC_SETUP_QDISC_MQPRIO bandwidth offload support for PF and VF netdevs by reprogramming NIX TX scheduler MDQ CIR/PIR registers and bouncing the netdev to allocate one SMQ per non-QoS queue.

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +0 -0
index 777e7156badb7..f51161e8b5949 100644

[ ... ]

Quoted 5 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +0 -1
@@ -3420,11 +3437,13 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	otx2_sriov_vfcfg_cleanup(pf);
 err_pf_sriov_init:
 	otx2_unregister_dl(pf);
-	otx2_shutdown_tc(pf);

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 3449

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +3 -0
 err_mcam_flow_del:
 	otx2_mcam_flow_del(pf);
 err_unreg_netdev:
+	otx2_shutdown_tc_mqprio(pf);
 	unregister_netdev(netdev);
+err_shutdown_tc:
+	otx2_shutdown_tc(pf);
 err_ipsec_clean:
 	cn10k_ipsec_clean(pf);
 err_mcs_free:

[Severity: Medium]
Does moving otx2_shutdown_tc(pf) below err_mcam_flow_del cause otx2_destroy_tc_flow_list() to skip freeing flow_cfg->flow_list_tc entries when probe fails after register_netdev()?

otx2_mcam_flow_del() calls otx2_destroy_mcam_flows(), which frees the MCAM entries while the netdev is still registered and clears OTX2_FLAG_MCAM_ENTRIES_ALLOC. When otx2_shutdown_tc() then calls otx2_destroy_tc_flow_list(), it sees OTX2_FLAG_MCAM_ENTRIES_ALLOC clear and returns early without freeing any otx2_tc_flow nodes added while the netdev was registered:

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c:otx2_destroy_tc_flow_list() {
    ...
	if (!otx2_test_flag(pfvf, OTX2_FLAG_MCAM_ENTRIES_ALLOC))
		return;

	list_for_each_entry_safe(iter, tmp, &flow_cfg->flow_list_tc, list) {
		list_del(&iter->list);
		kfree(iter);
		flow_cfg->nr_flows--;
	}
}

err_del_mcam_entries below err_mcs_free already calls otx2_mcam_flow_del(pf), so err_mcam_flow_del can be dropped.

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +0 -0
index 8877af348a090..b34a86259e786 100644

[ ... ]

Quoted 64 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +64 -0
+static int otx2_mqprio_restore_old(struct otx2_nic *pfvf)
+{
+	struct mq_offload_snap *snap = pfvf->old_mq_snap;
+	struct net_device *netdev = pfvf->netdev;
+	u16 num_txq = pfvf->hw.non_qos_queues;
+	int tc, txq, err;
+
+	if (!snap)
+		return 0;
+
+	err = otx2_mqprio_alloc_cache(pfvf, false);
+	if (err) {
+		netdev_err(netdev,
+			   "mqprio: rollback failed to allocate rate cache: %d\n",
+			   err);
+		return err;
+	}
+
+	memset(pfvf->mqprio.min_rate, 0, num_txq * sizeof(*pfvf->mqprio.min_rate));
+	memset(pfvf->mqprio.max_rate, 0, num_txq * sizeof(*pfvf->mqprio.max_rate));
+	pfvf->mqprio.flags = snap->flags;
+
+	for (tc = 0; tc < snap->num_tc; tc++) {
+		u64 min_rate = snap->min_rate[tc];
+		u64 max_rate = snap->max_rate[tc];
+
+		for (txq = snap->offset[tc];
+		     txq < snap->offset[tc] + snap->count[tc]; txq++) {
+			pfvf->mqprio.min_rate[txq] = min_rate;
+			pfvf->mqprio.max_rate[txq] = max_rate;
+		}
+	}
+
+	otx2_mqprio_apply_snap_netdev(netdev, snap);
+
+	if (otx2_mqprio_mdq_allocated(pfvf)) {
+		err = otx2_nix_tm_clear_queue_shaper(pfvf);
+		if (err) {
+			netdev_err(netdev,
+				   "mqprio: rollback shaper clear failed: %d; hardware limits may not match qdisc\n",
+				   err);
+			return err;
+		}
+	}
+
+	/* Rebuild the TX scheduler via netdev restart when running; otx2_mqprio_up()
+	 * alone is insufficient after a failed replace that already bounced the
+	 * interface. If open failed, TX schedulers were freed; defer shaper restore
+	 * to the next successful ndo_open() via otx2_mqprio_up().
+	 */
+	pfvf->mqprio.rate_limit = true;
+
+	if (netif_running(netdev)) {
+		err = otx2_mqprio_restart_netdev(netdev, true);
+		if (err) {
+			netdev_err(netdev,
+				   "mqprio: rollback netdev restart failed: %d; qdisc rates may not be enforced\n",
+				   err);
+			return err;
+		}
+	} else if (pfvf->hw.txschq_cnt[NIX_TXSCH_LVL_SMQ]) {
+		err = otx2_mqprio_up(pfvf);
+		if (err) {
+			netdev_err(netdev,

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_setup_tc_block(struct net_device *netdev, · line 1845

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +10 -0
+				   "mqprio: rollback shaper restore failed: %d; qdisc rates may not be enforced\n",
+				   err);
+			return err;
+		}
+	}
+
+	otx2_mqprio_snap_free(pfvf, &pfvf->cur_mq_snap);
+
+	return 0;
+}

[Severity: Medium]
Can an error in otx2_mqprio_restore_old() discard the restored rate cache and leave the surviving mqprio qdisc out of sync with hardware?

If otx2_mqprio_restart_netdev(netdev, true) fails in ops->ndo_open(), it calls otx2_mqprio_clear_sw(pfvf), which sets pfvf->mqprio.rate_limit to false and frees pfvf->mqprio.min_rate and max_rate. Contrary to the comment above, the next ndo_open() will then see rate_limit == false, allocate only a single SMQ in otx2_txsch_alloc(), and return early in otx2_mqprio_up(), leaving traffic unshaped while the old offloaded mqprio qdisc remains attached.

Passing replacing = false to otx2_mqprio_alloc_cache() also forces new allocations instead of reusing the existing arrays, and any early return from otx2_mqprio_restore_old() skips freeing pfvf->cur_mq_snap and causes the cleanup path in otx2_setup_tc_mqprio() to skip otx2_mqprio_defer_netdev_tc_restore(pfvf), so mqprio_destroy() on the rejected new qdisc resets netdev->num_tc to 0.

Quoted 24 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +24 -0
+
+static void otx2_mqprio_snap_destroy(struct otx2_nic *pfvf)
+{
+	otx2_mqprio_snap_free(pfvf, &pfvf->cur_mq_snap);
+	otx2_mqprio_snap_free(pfvf, &pfvf->old_mq_snap);
+}
+
+/* Offloaded mqprio replaced by software mqprio installs netdev TC layout in
+ * mqprio_init() before the old offload instance is destroyed during graft.
+ */
+static bool otx2_mqprio_keep_netdev_tc(struct otx2_nic *pfvf)
+{
+	struct Qdisc *qdisc = rtnl_dereference(pfvf->netdev->qdisc);
+
+	return qdisc && qdisc->ops && !strcmp(qdisc->ops->id, "mqprio");
+}
+
+static void otx2_mqprio_clear_sw(struct otx2_nic *pfvf)
+{
+	struct net_device *netdev = pfvf->netdev;
+
+	pfvf->mqprio.rate_limit = false;
+	otx2_mqprio_clear_replace_state(pfvf);
+	if (!otx2_mqprio_keep_netdev_tc(pfvf)) {

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_setup_tc_block(struct net_device *netdev, · line 1879

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +10 -0
+		struct Qdisc *root = rtnl_dereference(netdev->qdisc);
+
+		if (root && root->ops && !strcmp(root->ops->id, "taprio"))
+			netdev_warn(netdev,
+				    "mqprio: offload teardown cleared the TC layout of the new %s\n",
+				    root->ops->id);
+		netdev_set_num_tc(netdev, 0);
+	}
+	otx2_mqprio_free_cache(pfvf);
+}

[Severity: Medium]
When tc qdisc replace replaces an offloaded mqprio qdisc with a software taprio qdisc, does calling netdev_set_num_tc(netdev, 0) here break the new taprio qdisc?

During replacement, taprio_init() -> taprio_change() configures netdev->num_tc, netdev->tc_to_txq, and netdev->prio_tc_map before qdisc_graft() publishes the new taprio qdisc and destroys the old mqprio qdisc. Resetting num_tc to 0 in otx2_mqprio_clear_sw() causes taprio_dequeue_tc_priority() (which loops from netdev_get_num_tc(dev) - 1 down to 0) to do zero iterations and stop dequeuing TX packets. Preserving the netdev TC layout in otx2_mqprio_keep_netdev_tc() when the new root qdisc is taprio would avoid wiping out taprio's configuration.

[ ... ]

Quoted 51 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +51 -0
+static int otx2_mqprio_restart_netdev(struct net_device *netdev, bool rate_limit)
+{
+	struct otx2_nic *pfvf = netdev_priv(netdev);
+	const struct net_device_ops *ops = netdev->netdev_ops;
+	bool running = netif_running(netdev);
+	int err;
+
+	/* TODO: Explore live TX scheduler reprogramming to avoid a full
+	 * ndo_stop()/ndo_open() bounce on every mqprio change.
+	 */
+	netdev_dbg(netdev,
+		   "mqprio: restarting interface to reprogram TX scheduler\n");
+
+	if (running) {
+		clear_bit(__LINK_STATE_START, &netdev->state);
+		smp_mb__after_atomic(); /* Commit netif_running(). */
+	}
+
+	err = ops->ndo_stop(netdev);
+	if (err) {
+		if (running)
+			set_bit(__LINK_STATE_START, &netdev->state);
+		return err;
+	}
+
+	/* Set before ndo_open() so otx2_txsch_alloc() widens SMQ allocation.
+	 * On teardown, drop mqprio software state so ndo_open() does not
+	 * re-apply bandwidth limits via otx2_mqprio_up() after the kernel
+	 * removed the qdisc.
+	 */
+	if (rate_limit)
+		pfvf->mqprio.rate_limit = true;
+	else
+		otx2_mqprio_clear_sw(pfvf);
+
+	err = ops->ndo_open(netdev);
+	if (!err && running) {
+		set_bit(__LINK_STATE_START, &netdev->state);
+	} else if (err) {
+		netdev_err(netdev,
+			   "Failed to restart device after mqprio change: %d; bringing interface down\n",
+			   err);
+		/* ndo_open() already tore down TX scheduler resources on failure;
+		 * netif_running() is false here (__LINK_STATE_START stays clear
+		 * until open succeeds). Drop mqprio software state only instead
+		 * of sending shaper clears to freed queues.
+		 */
+		otx2_mqprio_clear_sw(pfvf);
+		/* ndo_open() rolls back on failure; mark the interface down so
+		 * otx2_stop() returns early when netif_close() runs.  Caller
+		 * holds RTNL; netif_close() is used since it needs no extra

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_setup_tc_block(struct net_device *netdev, · line 2043

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +10 -0
+		 * locking (dev_close() would also take the netdev ops lock).
+		 */
+		otx2_set_flag(pfvf, OTX2_FLAG_INTF_DOWN);
+		/* visible to otx2_stop() on other cpus */
+		smp_wmb();
+		netif_close(netdev);
+	}
+
+	return err;
+}

[Severity: Medium]
What happens during a tc qdisc replace if ops->ndo_open() fails in the first otx2_mqprio_restart_netdev() call in otx2_setup_tc_mqprio()?

When ops->ndo_open() fails, otx2_free_hw_resources() -> otx2_txschq_stop() zeroes pfvf->hw.txschq_cnt[NIX_TXSCH_LVL_SMQ], and this error path leaves __LINK_STATE_START clear and calls netif_close(netdev) from inside ndo_setup_tc() (which runs dev_deactivate_many() and emits NETDEV_GOING_DOWN/NETDEV_DOWN notifiers mid-qdisc operation). When otx2_setup_tc_mqprio() then jumps to cleanup and calls otx2_mqprio_restore_old(), both netif_running(netdev) and pfvf->hw.txschq_cnt[NIX_TXSCH_LVL_SMQ] are 0, so otx2_mqprio_restore_old() returns 0 without restoring hardware limits, and cleanup logs and sets extack to "mqprio: replace failed; hardware limits restored, netdev TC layout restore deferred" even though the interface was closed.

[ ... ]

Quoted 30 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +30 -0
+static bool otx2_tc_can_offload(struct net_device *netdev)
+{
+	return !!(netdev->hw_features & NETIF_F_HW_TC);
+}
+
+static int otx2_teardown_tc_mqprio(struct otx2_nic *pfvf,
+				   struct tc_mqprio_qopt_offload *mqprio)
+{
+	struct netlink_ext_ack *extack = mqprio->extack;
+	struct tc_mqprio_qopt *qopt = &mqprio->qopt;
+	bool had_mqprio = pfvf->mqprio.rate_limit;
+	struct net_device *netdev = pfvf->netdev;
+	bool if_up = netif_running(netdev);
+	int err;
+
+	if (!otx2_tc_can_offload(netdev))
+		return -EOPNOTSUPP;
+
+	qopt->hw = 0;
+
+	/* tc qdisc replace runs setup on the new mqprio before destroying the
+	 * old one. replace_setup_done and TC_ROOT_GRAFT distinguish stale
+	 * old-instance teardown from graft failure after setup.
+	 * qdisc_offload_graft_helper() skips TC_ROOT_GRAFT unless hw-tc-offload
+	 * is enabled in netdev->features; commit without graft in that case.
+	 */
+	if (pfvf->mqprio.replace_setup_done && pfvf->cur_mq_snap) {
+		err = 0;
+		if (pfvf->mqprio.replace_graft_done || !tc_can_offload(netdev)) {
+			otx2_mqprio_snap_commit(pfvf);

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_setup_tc_block(struct net_device *netdev, · line 2172

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +10 -0
+		} else {
+			err = otx2_mqprio_restore_old(pfvf);
+			if (err && extack)
+				NL_SET_ERR_MSG_FMT_MOD(extack,
+						       "mqprio: rollback failed (%d)",
+						       err);
+		}
+		otx2_mqprio_clear_replace_state(pfvf);
+		return err;
+	}

[Severity: Medium]
Does checking !tc_can_offload(netdev) here commit a rejected replacement instead of rolling back when qdisc_create() fails after mqprio_init()?

In both otx2_probe() and otx2vf_probe(), NETIF_F_HW_TC is added to netdev->hw_features after netdev->features |= netdev->hw_features, so !tc_can_offload(netdev) is true by default while otx2_tc_can_offload() still permits mqprio offload. If a replacement mqprio qdisc succeeds in mqprio_init() -> otx2_setup_tc_mqprio() (setting replace_setup_done and cur_mq_snap) but qdisc_create() then fails before qdisc_graft() (for example when TCA_RATE is passed on a TCQ_F_MQROOT qdisc), err_out4 in qdisc_create() calls mqprio_destroy() -> otx2_teardown_tc_mqprio() on the rejected new qdisc. Because !tc_can_offload(netdev) is true, this branch calls otx2_mqprio_snap_commit() instead of otx2_mqprio_restore_old(), leaving the old mqprio qdisc attached while hardware shapers, software rate caches, and old_mq_snap retain the rejected replacement configuration.

Checking tc_can_offload(netdev) in otx2_tc_can_offload() so offload requires NETIF_F_HW_TC in netdev->features would ensure TC_ROOT_GRAFT is always sent on a successful graft.

Quoted 9 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +9 -0
+
+	/* Skip the netdev restart when mqprio offload was not active. */
+	if (!had_mqprio)
+		return 0;
+
+	if (if_up) {
+		err = otx2_mqprio_down(pfvf);
+		if (err) {
+			if (extack)

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_setup_tc_block(struct net_device *netdev, · line 2191

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +10 -0
+				NL_SET_ERR_MSG_FMT_MOD(extack,
+						       "mqprio: teardown incomplete (%d)",
+						       err);
+			netdev_err(netdev,
+				   "mqprio: offload teardown incomplete (%d); driver state may not match removed qdisc\n",
+				   err);
+			return err;
+		}
+
+		err = otx2_mqprio_restart_netdev(netdev, false);

[Severity: Medium]
Does returning early when otx2_mqprio_down() fails skip the netdev restart that otx2_mqprio_down() relies on?

otx2_mqprio_down() unconditionally calls otx2_mqprio_clear_sw(pfvf) (setting pfvf->mqprio.rate_limit to false, resetting num_tc, and freeing the rate caches) and notes in its comment that the following netdev restart reallocates the TX scheduler and drops any shaper left programmed. Returning early here on a shaper-clear error skips otx2_mqprio_restart_netdev(netdev, false), and because mqprio_disable_offload() ignores the return value, the qdisc is destroyed while the interface stays up with the multi-SMQ hierarchy and stale MDQ rate limits active in hardware, and with rate_limit == false no longer blocking PFC or HTB setup.

[ ... ]

Quoted 20 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +20 -0
+static int otx2_setup_tc_mqprio(struct net_device *netdev,
+				struct tc_mqprio_qopt_offload *mqprio)
+{
+	struct netlink_ext_ack *extack = mqprio->extack;
+	struct otx2_nic *pfvf = netdev_priv(netdev);
+	struct tc_mqprio_qopt *qopt = &mqprio->qopt;
+	bool replacing = pfvf->mqprio.rate_limit;
+	bool if_up = netif_running(netdev);
+	int tc, txq, err, i;
+
+	if (!otx2_tc_can_offload(netdev))
+		return -EOPNOTSUPP;
+
+	if (!qopt->hw)
+		return otx2_teardown_tc_mqprio(pfvf, mqprio);
+
+	if (!if_up) {
+		netdev_err(netdev, "mqprio: setup requires interface UP\n");
+		NL_SET_ERR_MSG_MOD(extack, "mqprio: setup requires interface UP");
+		err = -EOPNOTSUPP;

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_setup_tc_block(struct net_device *netdev, · line 2241

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +10 -0
+		goto fail_validate;
+	}
+
+	if (!replacing && otx2_mqprio_keep_netdev_tc(pfvf)) {
+		netdev_err(netdev,
+			   "mqprio: delete existing mqprio before re-enabling hw/sw offload\n");
+		NL_SET_ERR_MSG_MOD(extack,
+				   "mqprio: delete existing mqprio before re-enabling hw/sw offload");
+		return -EOPNOTSUPP;
+	}

[Severity: Medium]
When rejecting a replace of an existing software mqprio qdisc (hw 0) with a hardware-offloaded mqprio qdisc (hw 1), does the error unwind in qdisc_create() wipe out the software mqprio qdisc's netdev TC layout?

When otx2_setup_tc_mqprio() returns -EOPNOTSUPP here (or at the !if_up check above), qdisc_create() jumps to err_out4 and calls mqprio_destroy() on the failed new qdisc. Because priv->hw_offload is 0 on the failed qdisc, mqprio_destroy() calls netdev_set_num_tc(dev, 0), clearing the num_tc and queue mappings of the still-attached software mqprio qdisc without old_mq_snap or netdev_tc_work restoring them.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#7 lore raw

Re: [PATCH v21 net-next 2/2] octeontx2: add mqprio bandwidth offload for NIX TX schedulers

In reply to Ratheesh Kannoth
Thank you for your contribution! Sashiko AI review found 11 potential issue(s) to consider.

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

Critical: 0 · High: 0 · Medium: 6 · Low: 5

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] Replacing an offloaded mqprio with a software taprio stops TX on the interface.
- [Medium] With mqprio rate limiting active, otx2_txsch_alloc() requests hw.non_qos_queues SMQs but still only one TL4.
- [Medium] Setup and teardown use different notions of 'offload enabled'.
- [Medium] When otx2_mqprio_down() fails, otx2_teardown_tc_mqprio() returns immediately and skips otx2_mqprio_restart_netdev(netdev,…
- [Medium] The new otx2_mqprio_up() failure branch in otx2_open() jumps to the new err_free_hw label.
- [Medium] octeontx2-pf: premature otx2_mcam_flow_del() in otx2_probe() error path
- [Low] The commit message leaves out several changes that reach code paths unrelated to mqprio.
- [Low] otx2_mqprio_restart_netdev(), called from ndo_setup_tc, clears and sets __LINK_STATE_START on netdev->state directly.
- [Low] The new comment in otx2_config_sched_shaping() calls 65536 'the kernel-side default burst when HTB does not supply an explicit value'.
- [Low] The comment on otx2_mqprio_keep_netdev_tc() says it detects a new software mqprio that installed its TC layout before the old offloaded…
- [Low] In otx2_setup_tc_mqprio(), the cleanup path for a failed replace is entered mid-loop when otx2_nix_tm_set_queue_shaper() fails.

--

octeontx2: add mqprio bandwidth offload for NIX TX schedulers

This commit adds TC_SETUP_QDISC_MQPRIO offload with the bw_rlimit shaper for octeontx2 PF and VF netdevs. It programs per-queue MDQ CIR/PIR through the NIX TX scheduler mailbox.

The TX scheduler cannot be reprogrammed live, so every mqprio add, replace and delete bounces the netdev through ndo_stop()/ndo_open(). Cached rates are restored from otx2_mqprio_up(), and replace operations are staged in snapshots.

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +0 -0
index f4047b0d5d963..b4a738cf9a8b7 100644

[ ... ]

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c int otx2_txschq_config(struct otx2_nic *pfvf, int lvl, int prio, bool txschq_for · line 794

Quoted 13 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +5 -1
@@ -651,7 +784,11 @@ int otx2_txschq_config(struct otx2_nic *pfvf, int lvl, int prio, bool txschq_for
 						(u64)hw->smq_link_type);
 		req->num_regs++;
 		/* MDQ config */
-		parent = schq_list[NIX_TXSCH_LVL_TL4][prio];
+		if (pfvf->mqprio.rate_limit)
+			parent = schq_list[NIX_TXSCH_LVL_TL4][0];
+		else
+			parent = schq_list[NIX_TXSCH_LVL_TL4][prio];
+
 		req->reg[1] = NIX_AF_MDQX_PARENT(schq);
 		req->regval[1] = parent << 16;
 		req->num_regs++;

[Severity: Medium]
With rate_limit set, otx2_txsch_alloc() asks for hw.non_qos_queues SMQs but still only one TL4. Every MDQ then becomes a child of TL4[0] with MDQ_SCHEDULE = dwrr_val (priority 0).

Is NIX_AF_TL4X_TOPOLOGY for TL4[0] programmed anywhere on this path?

As far as I can tell, TL4X_TOPOLOGY is only written from nic/qos.c. The AF reset clears only PARENT and SCHEDULE:

drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c:nix_reset_tx_schedule() {
	case NIX_TXSCH_LVL_TL4:
		tlx_parent   = NIX_AF_TL4X_PARENT(schq);
		tlx_schedule = NIX_AF_TL4X_SCHEDULE(schq);
}

The HTB teardown in otx2_qos_free_hw_schq() does reset the topology, but only best-effort. If the mailbox fails it warns and frees the schq anyway.

TL4[0] may have been last used by another function, or by an HTB teardown whose reset failed. Can it then keep a non-zero RR_PRIO/PRIO_ANCHOR? If so, the priority-0 MDQ children would not form a single DWRR group, and per-queue shaping could behave unexpectedly.

The patch acknowledges this later with:

	netdev_warn_once(netdev,
			 "mqprio: bandwidth offload uses TL4[0] without explicit topology programming; verify scheduling if limits look wrong\n");

Would it make sense to program TL4[0] TOPOLOGY with an RR_PRIO that matches the MDQ priority when several MDQs are attached?

[ ... ]

Quoted 6 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +0 -0
index 777e7156badb7..f51161e8b5949 100644
@@ -2008,6 +2008,15 @@ int otx2_open(struct net_device *netdev)
 	if (err)

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c int otx2_open(struct net_device *netdev) · line 2018

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +8 -0
 		goto err_free_mem;
 
+	/* Fail closed: abort open if cached mqprio shapers cannot be restored. */
+	err = otx2_mqprio_up(pf);
+	if (err) {
+		netdev_err(pf->netdev,
+			   "mqprio: failed to restore shapers during open: %d\n",
+			   err);
+		goto err_free_hw;
+	}

[Severity: Medium]
Does this new error path leak pf->refill_wrk?

otx2_init_hw_resources()->otx2_config_nix_queues() has just allocated it:

	pfvf->refill_wrk = devm_kcalloc(pfvf->dev, pfvf->qset.cq_cnt,
					sizeof(struct refill_work), GFP_KERNEL);

err_free_hw only runs otx2_free_hw_resources() and otx2_free_queue_mem(). Neither of them frees refill_wrk. The only devm_kfree() of it is in otx2_stop().

When the open fails from otx2_mqprio_restart_netdev(), OTX2_FLAG_INTF_DOWN is set before netif_close(). otx2_stop() then returns early, so the allocation is never released.

With rate_limit active, a persistent shaper mailbox failure would leak cq_cnt * sizeof(struct refill_work) on every admin up attempt until the driver is unbound.

The older error labels after otx2_init_hw_resources() have the same gap. This patch adds a new way to reach it from userspace.

[ ... ]

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c int otx2_stop(struct net_device *netdev) · line 2295

Quoted 6 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +1 -0
@@ -2281,6 +2291,7 @@ int otx2_stop(struct net_device *netdev)
 	for (qidx = 0; qidx < netdev->num_tx_queues; qidx++)
 		netdev_tx_reset_queue(netdev_get_tx_queue(netdev, qidx));
 
+	synchronize_net();
 	otx2_free_queue_mem(qset);

[Severity: Low]
This isn't a bug, but several changes here affect paths outside mqprio, and the commit message does not mention them.

synchronize_net() now runs on every ndo_stop. That covers admin down, otx2_change_mtu(), ethtool channel and ring changes, XDP attach/detach, and the reset task. Under RTNL it becomes synchronize_rcu_expedited().

What race does it close? If it fixes an existing problem with otx2_free_queue_mem(), could it go in a separate patch with a Fixes: tag?

otx2_txschq_stop() now zeroes hw.txschq_cnt[] for every caller. After a stop, otx2_get_smq_idx() returns 0 instead of the last SMQ. Existing users such as otx2_pfc_update_sq_smq_mapping() and otx2_qos_disable_sq() will see this.

The PF and VF probe/remove ordering also changes:

- otx2_init_tc() and otx2vf_mcam_flow_init() now run before register_netdev()
- otx2_shutdown_tc() moves to right after unregister_netdev()
- the error labels are rewired

There are also comment-only edits in qos.c and otx2_get_egress_burst_cfg().

Could the commit message describe these changes, or could they be split out?

[ ... ]

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +0 -0
index 8877af348a090..b34a86259e786 100644

[ ... ]

Quoted 7 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +7 -0
+static int otx2_mqprio_restore_old(struct otx2_nic *pfvf)
+{
+	struct mq_offload_snap *snap = pfvf->old_mq_snap;
+	struct net_device *netdev = pfvf->netdev;
+	u16 num_txq = pfvf->hw.non_qos_queues;
+	int tc, txq, err;
+

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_setup_tc_block(struct net_device *netdev, · line 1788

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +10 -0
+	if (!snap)
+		return 0;
+
+	err = otx2_mqprio_alloc_cache(pfvf, false);
+	if (err) {
+		netdev_err(netdev,
+			   "mqprio: rollback failed to allocate rate cache: %d\n",
+			   err);
+		return err;
+	}

[Severity: Low]
The replace path in otx2_setup_tc_mqprio() can reach cleanup because otx2_nix_tm_set_queue_shaper() failed partway through the loop. At that point pfvf->mqprio.min_rate[]/max_rate[] and pfvf->mqprio.flags already hold part of the new config, and rate_limit is true.

If otx2_mqprio_alloc_cache() fails here, we return before refilling the cache from old_mq_snap. Does that leave the partially-new rates cached with rate_limit still set, while the old qdisc stays root?

The same applies if otx2_nix_tm_clear_queue_shaper() fails further down. The cache is restored, but the hardware keeps the partially-new shapers.

On the restore_err branch in otx2_setup_tc_mqprio(), no deferred TC restore is scheduled. num_tc therefore stays 0 after mqprio_destroy() of the failed qdisc. From then on, otx2_mqprio_up() would re-apply the mixed rate set on every ndo_open().

[ ... ]

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_setup_tc_block(struct net_device *netdev, · line 1861

Quoted 9 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +9 -0
+/* Offloaded mqprio replaced by software mqprio installs netdev TC layout in
+ * mqprio_init() before the old offload instance is destroyed during graft.
+ */
+static bool otx2_mqprio_keep_netdev_tc(struct otx2_nic *pfvf)
+{
+	struct Qdisc *qdisc = rtnl_dereference(pfvf->netdev->qdisc);
+
+	return qdisc && qdisc->ops && !strcmp(qdisc->ops->id, "mqprio");
+}

[Severity: Low]
Can this match the offloaded mqprio that is being destroyed, and not only a new software mqprio?

dev_shutdown() puts the root qdisc while dev->qdisc still points at it:

net/sched/sch_generic.c:dev_shutdown() {
	qdisc_put(rtnl_dereference(dev->qdisc));
	rcu_assign_pointer(dev->qdisc, &noop_qdisc);
}

When offload is active, mqprio_destroy() leaves num_tc to the driver:

net/sched/sch_mqprio.c:mqprio_destroy() {
	if (priv->hw_offload && dev->netdev_ops->ndo_setup_tc)
		mqprio_disable_offload(sch);
	else
		netdev_set_num_tc(dev, 0);
}

This happens on unregister, and in __dev_change_net_namespace(), which calls netif_close() and then dev_shutdown(). In both cases otx2_mqprio_clear_sw() would see "mqprio" and skip netdev_set_num_tc(netdev, 0).

After a netns move, the stale TC layout would stay while only the default mq is attached. skb_tx_hash() would keep limiting queue selection to the old TC offset/count until a new mqprio is installed.

Quoted 5 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +5 -0
+static void otx2_mqprio_clear_sw(struct otx2_nic *pfvf)
+{
+	struct net_device *netdev = pfvf->netdev;
+
+	pfvf->mqprio.rate_limit = false;

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_setup_tc_block(struct net_device *netdev, · line 1877

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +10 -0
+	otx2_mqprio_clear_replace_state(pfvf);
+	if (!otx2_mqprio_keep_netdev_tc(pfvf)) {
+		struct Qdisc *root = rtnl_dereference(netdev->qdisc);
+
+		if (root && root->ops && !strcmp(root->ops->id, "taprio"))
+			netdev_warn(netdev,
+				    "mqprio: offload teardown cleared the TC layout of the new %s\n",
+				    root->ops->id);
+		netdev_set_num_tc(netdev, 0);
+	}

[Severity: Medium]
Does replacing an offloaded mqprio with a software taprio stop TX on the interface?

Consider "tc qdisc replace dev X root taprio ..." without full offload:

1. taprio_change() installs its layout with netdev_set_num_tc() and

     netdev_set_tc_queue().
  2. qdisc_graft() publishes taprio as dev->qdisc and destroys the old
     mqprio.
  3. Because hw_offload is set, mqprio_destroy() calls ndo_setup_tc()
     with hw=0.

4. otx2_teardown_tc_mqprio() reaches otx2_mqprio_clear_sw(), either directly or through otx2_mqprio_down()/otx2_mqprio_restart_netdev().

Here the root is detected as "taprio" and the warning is printed, but netdev_set_num_tc(netdev, 0) still runs.

otx2 returns -EOPNOTSUPP for TAPRIO caps, so taprio uses taprio_dequeue_tc_priority():

net/sched/sch_taprio.c:taprio_dequeue_tc_priority() {
	int num_tc = netdev_get_num_tc(dev);
	...
	for (tc = num_tc - 1; tc >= 0; tc--) {
}

With num_tc == 0 this loop never runs, so dequeue always returns NULL.

Should the TC layout also be kept for taprio, or for any new root that owns it?

[ ... ]

Quoted 2 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +2 -0
+static int otx2_mqprio_restart_netdev(struct net_device *netdev, bool rate_limit)
+{

[ ... ]

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +4 -0
+	if (running) {
+		clear_bit(__LINK_STATE_START, &netdev->state);
+		smp_mb__after_atomic(); /* Commit netif_running(). */
+	}

[ ... ]

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_setup_tc_block(struct net_device *netdev, · line 2040

Quoted 5 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +5 -0
+		otx2_set_flag(pfvf, OTX2_FLAG_INTF_DOWN);
+		/* visible to otx2_stop() on other cpus */
+		smp_wmb();
+		netif_close(netdev);
+	}

[Severity: Low]
Is it ok for a driver to clear and set __LINK_STATE_START directly from ndo_setup_tc()? I couldn't find another driver under drivers/net that does this. The bit is owned by the core open/close helpers.

When ndo_open() fails, netif_close() is also called from inside the qdisc operation. A failed "tc qdisc add/replace/del ... mqprio" can then take the interface administratively down. That includes a delete, which the core cannot veto. IFF_UP is cleared and NETDEV_GOING_DOWN/NETDEV_DOWN are sent.

The commit message only says the netdev is bounced through ndo_stop()/ndo_open(). Could it mention that a tc command can close the interface?

[ ... ]

Quoted 8 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +8 -0
+static bool otx2_tc_can_offload(struct net_device *netdev)
+{
+	return !!(netdev->hw_features & NETIF_F_HW_TC);
+}
+
+static int otx2_teardown_tc_mqprio(struct otx2_nic *pfvf,
+				   struct tc_mqprio_qopt_offload *mqprio)
+{

[ ... ]

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_setup_tc_block(struct net_device *netdev, · line 2163

Quoted 5 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +5 -0
+	if (pfvf->mqprio.replace_setup_done && pfvf->cur_mq_snap) {
+		err = 0;
+		if (pfvf->mqprio.replace_graft_done || !tc_can_offload(netdev)) {
+			otx2_mqprio_snap_commit(pfvf);
+		} else {

[Severity: Medium]
otx2_tc_can_offload() checks netdev->hw_features. This check uses the core tc_can_offload(), which checks netdev->features. Can the two disagree in the default configuration?

Both otx2_probe() and otx2vf_probe() add NETIF_F_HW_TC to hw_features after "netdev->features |= netdev->hw_features". So hw-tc-offload is off by default, and qdisc_offload_graft_helper() never sends TC_ROOT_GRAFT:

net/sched/sch_api.c:qdisc_offload_graft_helper() {
	if (!tc_can_offload(dev) || !dev->netdev_ops->ndo_setup_tc)
		return;
}

As a result, this branch always commits.

Suppose a replacement mqprio passes otx2_setup_tc_mqprio() and then fails later in qdisc_create(). For example, an estimator on a TCQ_F_MQROOT qdisc goes to err_out4 and ->destroy().

Wouldn't the rejected config be committed as old_mq_snap? The hardware shapers and netdev TC layout would keep enforcing it while the old qdisc stays root.

Separately, on the PF NETIF_F_HW_TC is only in hw_features when OTX2_FLAG_TC_FLOWER_SUPPORT is set. Is it intended that MDQ shaping is refused on PFs without flower/MCAM support? The commit message says the feature applies to PF and VF netdevs, without that qualification.

[ ... ]

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +4 -0
+	if (if_up) {
+		err = otx2_mqprio_down(pfvf);
+		if (err) {
+			if (extack)

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_setup_tc_block(struct net_device *netdev, · line 2191

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +10 -0
+				NL_SET_ERR_MSG_FMT_MOD(extack,
+						       "mqprio: teardown incomplete (%d)",
+						       err);
+			netdev_err(netdev,
+				   "mqprio: offload teardown incomplete (%d); driver state may not match removed qdisc\n",
+				   err);
+			return err;
+		}
+
+		err = otx2_mqprio_restart_netdev(netdev, false);

[Severity: Medium]
If otx2_nix_tm_clear_queue_shaper() fails inside otx2_mqprio_down(), the software state has already been released through otx2_mqprio_clear_sw(). otx2_mqprio_down() explains this as:

	/* The core cannot veto qdisc teardown, so always release software
	 * state.  The netdev restart that follows reallocates the TX
	 * scheduler, which drops any shaper left programmed.
	 */

On this error path, though, we return before otx2_mqprio_restart_netdev(), so no restart follows. Doesn't that leave the MDQ CIR/PIR limits and the widened SMQ allocation in place, with rate_limit false and num_tc 0?

mqprio_disable_offload() is void, so "tc qdisc del" looks successful to the user. The stale limits would remain until an unrelated ndo_stop()/ndo_open().

Should the restart still happen when the clear fails?

[ ... ]

drivers/net/ethernet/marvell/octeontx2/nic/qos.c static void otx2_config_sched_shaping(struct otx2_nic *pfvf, · line 125

Quoted 13 lines
drivers/net/ethernet/marvell/octeontx2/nic/qos.c +3 -0
index 2ede0b84e5f52..732fff75ab0be 100644
@@ -118,6 +118,9 @@ static void otx2_config_sched_shaping(struct otx2_nic *pfvf,
 	/* configure PIR */
 	maxrate = (node->rate > node->ceil) ? node->rate : node->ceil;
 
+	/* 65536 is the kernel-side default burst when HTB does not supply an
+	 * explicit value, not the NIX hardware maximum (CN10K_MAX_BURST_SIZE).
+	 */
 	cfg->regval[*num_regs] =
 		otx2_get_txschq_rate_regval(pfvf, maxrate, 65536);

[Severity: Low]
This isn't a bug, but is this comment accurate? struct tc_htb_qopt_offload has no burst member, so HTB offload can never supply an explicit burst, and 65536 is always used.

The comment in otx2_nix_tm_set_queue_shaper() ("Use the same 65536 byte default as the HTB shaper path") repeats the same idea.

[ ... ]

Quoted 5 lines
drivers/net/ethernet/marvell/octeontx2/nic/qos.c +0 -1
@@ -3420,11 +3437,13 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	otx2_sriov_vfcfg_cleanup(pf);
 err_pf_sriov_init:
 	otx2_unregister_dl(pf);
-	otx2_shutdown_tc(pf);

drivers/net/ethernet/marvell/octeontx2/nic/qos.c static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 3449

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/qos.c +3 -0
 err_mcam_flow_del:
 	otx2_mcam_flow_del(pf);
 err_unreg_netdev:
+	otx2_shutdown_tc_mqprio(pf);
 	unregister_netdev(netdev);
+err_shutdown_tc:
+	otx2_shutdown_tc(pf);
 err_ipsec_clean:
 	cn10k_ipsec_clean(pf);
 err_mcs_free:

[Severity: Medium]
Does the new label ordering stop otx2_shutdown_tc() from doing anything on the late probe error paths?

Before this patch, err_pf_sriov_init ran otx2_shutdown_tc() and only then fell through to otx2_mcam_flow_del(). With this patch, a failure in otx2_register_dl(), otx2_sriov_vfcfg_init(), the af_xdp_zc_qidx bitmap_zalloc() or otx2_dcbnl_set_ops() unwinds like this:

  err_mcam_flow_del:  otx2_mcam_flow_del()
  err_unreg_netdev:   otx2_shutdown_tc_mqprio(), unregister_netdev()
  err_shutdown_tc:    otx2_shutdown_tc()

otx2_mcam_flow_del() goes through otx2_destroy_mcam_flows(), which clears OTX2_FLAG_MCAM_ENTRIES_ALLOC.

otx2_shutdown_tc() then calls otx2_destroy_tc_flow_list(). That function returns early when OTX2_FLAG_MCAM_ENTRIES_ALLOC is clear, so it no longer walks flow_cfg->flow_list_tc.

Any otx2_tc_flow nodes added while the netdev was registered are therefore never freed. The window is small, and installing flower rules needs CAP_NET_ADMIN.

The ordering is also now the reverse of otx2_remove() after this patch. There, otx2_shutdown_tc() runs right after unregister_netdev(), and otx2_mcam_flow_del() runs later.

The unwind already reaches err_del_mcam_entries by fallthrough from err_shutdown_tc/err_ipsec_clean/err_mcs_free. err_del_mcam_entries calls otx2_mcam_flow_del() again, so the call at err_mcam_flow_del looks redundant.

Could that first call be dropped, with the labels folded, so the probe error path mirrors otx2_remove()? Or is there a reason the MCAM flows have to be deleted before unregister_netdev() here?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261109033154.2161803-1-rkannoth%40marvell.com
author maintainer
#8 lore raw

Re: [PATCH v21 net-next 2/2] octeontx2: add mqprio bandwidth offload for NIX TX schedulers

Quoted 4 lines · On 2026-11-12 at 03:02:30, [email protected]…

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

Critical: 0 · High: 0 · Medium: 6 · Low: 5

v21 is a RESEND of v20.

Sashiko comments reply for v20: https://lore.kernel.org/netdev/atV491xfWzf9YqV_@rkannoth-OptiPlex-7090/

Quoted 509 lines

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] Replacing an offloaded mqprio with a software taprio stops TX on the interface.
- [Medium] With mqprio rate limiting active, otx2_txsch_alloc() requests hw.non_qos_queues SMQs but still only one TL4.
- [Medium] Setup and teardown use different notions of 'offload enabled'.
- [Medium] When otx2_mqprio_down() fails, otx2_teardown_tc_mqprio() returns immediately and skips otx2_mqprio_restart_netdev(netdev,…
- [Medium] The new otx2_mqprio_up() failure branch in otx2_open() jumps to the new err_free_hw label.
- [Medium] octeontx2-pf: premature otx2_mcam_flow_del() in otx2_probe() error path
- [Low] The commit message leaves out several changes that reach code paths unrelated to mqprio.
- [Low] otx2_mqprio_restart_netdev(), called from ndo_setup_tc, clears and sets __LINK_STATE_START on netdev->state directly.
- [Low] The new comment in otx2_config_sched_shaping() calls 65536 'the kernel-side default burst when HTB does not supply an explicit value'.
- [Low] The comment on otx2_mqprio_keep_netdev_tc() says it detects a new software mqprio that installed its TC layout before the old offloaded…
- [Low] In otx2_setup_tc_mqprio(), the cleanup path for a failed replace is entered mid-loop when otx2_nix_tm_set_queue_shaper() fails.

--

octeontx2: add mqprio bandwidth offload for NIX TX schedulers

This commit adds TC_SETUP_QDISC_MQPRIO offload with the bw_rlimit shaper for octeontx2 PF and VF netdevs. It programs per-queue MDQ CIR/PIR through the NIX TX scheduler mailbox.

The TX scheduler cannot be reprogrammed live, so every mqprio add, replace and delete bounces the netdev through ndo_stop()/ndo_open(). Cached rates are restored from otx2_mqprio_up(), and replace operations are staged in snapshots.

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +0 -0
index f4047b0d5d963..b4a738cf9a8b7 100644

[ ... ]

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c int otx2_txschq_config(struct otx2_nic *pfvf, int lvl, int prio, bool txschq_for · line 794

Quoted 13 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +5 -1
@@ -651,7 +784,11 @@ int otx2_txschq_config(struct otx2_nic *pfvf, int lvl, int prio, bool txschq_for
 						(u64)hw->smq_link_type);
 		req->num_regs++;
 		/* MDQ config */
-		parent = schq_list[NIX_TXSCH_LVL_TL4][prio];
+		if (pfvf->mqprio.rate_limit)
+			parent = schq_list[NIX_TXSCH_LVL_TL4][0];
+		else
+			parent = schq_list[NIX_TXSCH_LVL_TL4][prio];
+
 		req->reg[1] = NIX_AF_MDQX_PARENT(schq);
 		req->regval[1] = parent << 16;
 		req->num_regs++;

[Severity: Medium]
With rate_limit set, otx2_txsch_alloc() asks for hw.non_qos_queues SMQs but still only one TL4. Every MDQ then becomes a child of TL4[0] with MDQ_SCHEDULE = dwrr_val (priority 0).

Is NIX_AF_TL4X_TOPOLOGY for TL4[0] programmed anywhere on this path?

As far as I can tell, TL4X_TOPOLOGY is only written from nic/qos.c. The AF reset clears only PARENT and SCHEDULE:

drivers/net/ethernet/marvell/octeontx2/af/rvu_nix.c:nix_reset_tx_schedule() {
	case NIX_TXSCH_LVL_TL4:
		tlx_parent   = NIX_AF_TL4X_PARENT(schq);
		tlx_schedule = NIX_AF_TL4X_SCHEDULE(schq);
}

The HTB teardown in otx2_qos_free_hw_schq() does reset the topology, but only best-effort. If the mailbox fails it warns and frees the schq anyway.

TL4[0] may have been last used by another function, or by an HTB teardown whose reset failed. Can it then keep a non-zero RR_PRIO/PRIO_ANCHOR? If so, the priority-0 MDQ children would not form a single DWRR group, and per-queue shaping could behave unexpectedly.

The patch acknowledges this later with:

	netdev_warn_once(netdev,
			 "mqprio: bandwidth offload uses TL4[0] without explicit topology programming; verify scheduling if limits look wrong\n");

Would it make sense to program TL4[0] TOPOLOGY with an RR_PRIO that matches the MDQ priority when several MDQs are attached?

[ ... ]

Quoted 6 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +0 -0
index 777e7156badb7..f51161e8b5949 100644
@@ -2008,6 +2008,15 @@ int otx2_open(struct net_device *netdev)
 	if (err)

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c int otx2_open(struct net_device *netdev) · line 2018

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +8 -0
 		goto err_free_mem;
 
+	/* Fail closed: abort open if cached mqprio shapers cannot be restored. */
+	err = otx2_mqprio_up(pf);
+	if (err) {
+		netdev_err(pf->netdev,
+			   "mqprio: failed to restore shapers during open: %d\n",
+			   err);
+		goto err_free_hw;
+	}

[Severity: Medium]
Does this new error path leak pf->refill_wrk?

otx2_init_hw_resources()->otx2_config_nix_queues() has just allocated it:

	pfvf->refill_wrk = devm_kcalloc(pfvf->dev, pfvf->qset.cq_cnt,
					sizeof(struct refill_work), GFP_KERNEL);

err_free_hw only runs otx2_free_hw_resources() and otx2_free_queue_mem(). Neither of them frees refill_wrk. The only devm_kfree() of it is in otx2_stop().

When the open fails from otx2_mqprio_restart_netdev(), OTX2_FLAG_INTF_DOWN is set before netif_close(). otx2_stop() then returns early, so the allocation is never released.

With rate_limit active, a persistent shaper mailbox failure would leak cq_cnt * sizeof(struct refill_work) on every admin up attempt until the driver is unbound.

The older error labels after otx2_init_hw_resources() have the same gap. This patch adds a new way to reach it from userspace.

[ ... ]

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c int otx2_stop(struct net_device *netdev) · line 2295

Quoted 6 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +1 -0
@@ -2281,6 +2291,7 @@ int otx2_stop(struct net_device *netdev)
 	for (qidx = 0; qidx < netdev->num_tx_queues; qidx++)
 		netdev_tx_reset_queue(netdev_get_tx_queue(netdev, qidx));
 
+	synchronize_net();
 	otx2_free_queue_mem(qset);

[Severity: Low]
This isn't a bug, but several changes here affect paths outside mqprio, and the commit message does not mention them.

synchronize_net() now runs on every ndo_stop. That covers admin down, otx2_change_mtu(), ethtool channel and ring changes, XDP attach/detach, and the reset task. Under RTNL it becomes synchronize_rcu_expedited().

What race does it close? If it fixes an existing problem with otx2_free_queue_mem(), could it go in a separate patch with a Fixes: tag?

otx2_txschq_stop() now zeroes hw.txschq_cnt[] for every caller. After a stop, otx2_get_smq_idx() returns 0 instead of the last SMQ. Existing users such as otx2_pfc_update_sq_smq_mapping() and otx2_qos_disable_sq() will see this.

The PF and VF probe/remove ordering also changes:

- otx2_init_tc() and otx2vf_mcam_flow_init() now run before register_netdev()
- otx2_shutdown_tc() moves to right after unregister_netdev()
- the error labels are rewired

There are also comment-only edits in qos.c and otx2_get_egress_burst_cfg().

Could the commit message describe these changes, or could they be split out?

[ ... ]

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +0 -0
index 8877af348a090..b34a86259e786 100644

[ ... ]

Quoted 7 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +7 -0
+static int otx2_mqprio_restore_old(struct otx2_nic *pfvf)
+{
+	struct mq_offload_snap *snap = pfvf->old_mq_snap;
+	struct net_device *netdev = pfvf->netdev;
+	u16 num_txq = pfvf->hw.non_qos_queues;
+	int tc, txq, err;
+

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_setup_tc_block(struct net_device *netdev, · line 1788

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +10 -0
+	if (!snap)
+		return 0;
+
+	err = otx2_mqprio_alloc_cache(pfvf, false);
+	if (err) {
+		netdev_err(netdev,
+			   "mqprio: rollback failed to allocate rate cache: %d\n",
+			   err);
+		return err;
+	}

[Severity: Low]
The replace path in otx2_setup_tc_mqprio() can reach cleanup because otx2_nix_tm_set_queue_shaper() failed partway through the loop. At that point pfvf->mqprio.min_rate[]/max_rate[] and pfvf->mqprio.flags already hold part of the new config, and rate_limit is true.

If otx2_mqprio_alloc_cache() fails here, we return before refilling the cache from old_mq_snap. Does that leave the partially-new rates cached with rate_limit still set, while the old qdisc stays root?

The same applies if otx2_nix_tm_clear_queue_shaper() fails further down. The cache is restored, but the hardware keeps the partially-new shapers.

On the restore_err branch in otx2_setup_tc_mqprio(), no deferred TC restore is scheduled. num_tc therefore stays 0 after mqprio_destroy() of the failed qdisc. From then on, otx2_mqprio_up() would re-apply the mixed rate set on every ndo_open().

[ ... ]

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_setup_tc_block(struct net_device *netdev, · line 1861

Quoted 9 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +9 -0
+/* Offloaded mqprio replaced by software mqprio installs netdev TC layout in
+ * mqprio_init() before the old offload instance is destroyed during graft.
+ */
+static bool otx2_mqprio_keep_netdev_tc(struct otx2_nic *pfvf)
+{
+	struct Qdisc *qdisc = rtnl_dereference(pfvf->netdev->qdisc);
+
+	return qdisc && qdisc->ops && !strcmp(qdisc->ops->id, "mqprio");
+}

[Severity: Low]
Can this match the offloaded mqprio that is being destroyed, and not only a new software mqprio?

dev_shutdown() puts the root qdisc while dev->qdisc still points at it:

net/sched/sch_generic.c:dev_shutdown() {
	qdisc_put(rtnl_dereference(dev->qdisc));
	rcu_assign_pointer(dev->qdisc, &noop_qdisc);
}

When offload is active, mqprio_destroy() leaves num_tc to the driver:

net/sched/sch_mqprio.c:mqprio_destroy() {
	if (priv->hw_offload && dev->netdev_ops->ndo_setup_tc)
		mqprio_disable_offload(sch);
	else
		netdev_set_num_tc(dev, 0);
}

This happens on unregister, and in __dev_change_net_namespace(), which calls netif_close() and then dev_shutdown(). In both cases otx2_mqprio_clear_sw() would see "mqprio" and skip netdev_set_num_tc(netdev, 0).

After a netns move, the stale TC layout would stay while only the default mq is attached. skb_tx_hash() would keep limiting queue selection to the old TC offset/count until a new mqprio is installed.

Quoted 5 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +5 -0
+static void otx2_mqprio_clear_sw(struct otx2_nic *pfvf)
+{
+	struct net_device *netdev = pfvf->netdev;
+
+	pfvf->mqprio.rate_limit = false;

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_setup_tc_block(struct net_device *netdev, · line 1877

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +10 -0
+	otx2_mqprio_clear_replace_state(pfvf);
+	if (!otx2_mqprio_keep_netdev_tc(pfvf)) {
+		struct Qdisc *root = rtnl_dereference(netdev->qdisc);
+
+		if (root && root->ops && !strcmp(root->ops->id, "taprio"))
+			netdev_warn(netdev,
+				    "mqprio: offload teardown cleared the TC layout of the new %s\n",
+				    root->ops->id);
+		netdev_set_num_tc(netdev, 0);
+	}

[Severity: Medium]
Does replacing an offloaded mqprio with a software taprio stop TX on the interface?

Consider "tc qdisc replace dev X root taprio ..." without full offload:

1. taprio_change() installs its layout with netdev_set_num_tc() and

     netdev_set_tc_queue().
  2. qdisc_graft() publishes taprio as dev->qdisc and destroys the old
     mqprio.
  3. Because hw_offload is set, mqprio_destroy() calls ndo_setup_tc()
     with hw=0.

4. otx2_teardown_tc_mqprio() reaches otx2_mqprio_clear_sw(), either directly or through otx2_mqprio_down()/otx2_mqprio_restart_netdev().

Here the root is detected as "taprio" and the warning is printed, but netdev_set_num_tc(netdev, 0) still runs.

otx2 returns -EOPNOTSUPP for TAPRIO caps, so taprio uses taprio_dequeue_tc_priority():

net/sched/sch_taprio.c:taprio_dequeue_tc_priority() {
	int num_tc = netdev_get_num_tc(dev);
	...
	for (tc = num_tc - 1; tc >= 0; tc--) {
}

With num_tc == 0 this loop never runs, so dequeue always returns NULL.

Should the TC layout also be kept for taprio, or for any new root that owns it?

[ ... ]

Quoted 2 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +2 -0
+static int otx2_mqprio_restart_netdev(struct net_device *netdev, bool rate_limit)
+{

[ ... ]

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +4 -0
+	if (running) {
+		clear_bit(__LINK_STATE_START, &netdev->state);
+		smp_mb__after_atomic(); /* Commit netif_running(). */
+	}

[ ... ]

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_setup_tc_block(struct net_device *netdev, · line 2040

Quoted 5 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +5 -0
+		otx2_set_flag(pfvf, OTX2_FLAG_INTF_DOWN);
+		/* visible to otx2_stop() on other cpus */
+		smp_wmb();
+		netif_close(netdev);
+	}

[Severity: Low]
Is it ok for a driver to clear and set __LINK_STATE_START directly from ndo_setup_tc()? I couldn't find another driver under drivers/net that does this. The bit is owned by the core open/close helpers.

When ndo_open() fails, netif_close() is also called from inside the qdisc operation. A failed "tc qdisc add/replace/del ... mqprio" can then take the interface administratively down. That includes a delete, which the core cannot veto. IFF_UP is cleared and NETDEV_GOING_DOWN/NETDEV_DOWN are sent.

The commit message only says the netdev is bounced through ndo_stop()/ndo_open(). Could it mention that a tc command can close the interface?

[ ... ]

Quoted 8 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +8 -0
+static bool otx2_tc_can_offload(struct net_device *netdev)
+{
+	return !!(netdev->hw_features & NETIF_F_HW_TC);
+}
+
+static int otx2_teardown_tc_mqprio(struct otx2_nic *pfvf,
+				   struct tc_mqprio_qopt_offload *mqprio)
+{

[ ... ]

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_setup_tc_block(struct net_device *netdev, · line 2163

Quoted 5 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +5 -0
+	if (pfvf->mqprio.replace_setup_done && pfvf->cur_mq_snap) {
+		err = 0;
+		if (pfvf->mqprio.replace_graft_done || !tc_can_offload(netdev)) {
+			otx2_mqprio_snap_commit(pfvf);
+		} else {

[Severity: Medium]
otx2_tc_can_offload() checks netdev->hw_features. This check uses the core tc_can_offload(), which checks netdev->features. Can the two disagree in the default configuration?

Both otx2_probe() and otx2vf_probe() add NETIF_F_HW_TC to hw_features after "netdev->features |= netdev->hw_features". So hw-tc-offload is off by default, and qdisc_offload_graft_helper() never sends TC_ROOT_GRAFT:

net/sched/sch_api.c:qdisc_offload_graft_helper() {
	if (!tc_can_offload(dev) || !dev->netdev_ops->ndo_setup_tc)
		return;
}

As a result, this branch always commits.

Suppose a replacement mqprio passes otx2_setup_tc_mqprio() and then fails later in qdisc_create(). For example, an estimator on a TCQ_F_MQROOT qdisc goes to err_out4 and ->destroy().

Wouldn't the rejected config be committed as old_mq_snap? The hardware shapers and netdev TC layout would keep enforcing it while the old qdisc stays root.

Separately, on the PF NETIF_F_HW_TC is only in hw_features when OTX2_FLAG_TC_FLOWER_SUPPORT is set. Is it intended that MDQ shaping is refused on PFs without flower/MCAM support? The commit message says the feature applies to PF and VF netdevs, without that qualification.

[ ... ]

Quoted 4 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +4 -0
+	if (if_up) {
+		err = otx2_mqprio_down(pfvf);
+		if (err) {
+			if (extack)

drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c static int otx2_setup_tc_block(struct net_device *netdev, · line 2191

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_tc.c +10 -0
+				NL_SET_ERR_MSG_FMT_MOD(extack,
+						       "mqprio: teardown incomplete (%d)",
+						       err);
+			netdev_err(netdev,
+				   "mqprio: offload teardown incomplete (%d); driver state may not match removed qdisc\n",
+				   err);
+			return err;
+		}
+
+		err = otx2_mqprio_restart_netdev(netdev, false);

[Severity: Medium]
If otx2_nix_tm_clear_queue_shaper() fails inside otx2_mqprio_down(), the software state has already been released through otx2_mqprio_clear_sw(). otx2_mqprio_down() explains this as:

	/* The core cannot veto qdisc teardown, so always release software
	 * state.  The netdev restart that follows reallocates the TX
	 * scheduler, which drops any shaper left programmed.
	 */

On this error path, though, we return before otx2_mqprio_restart_netdev(), so no restart follows. Doesn't that leave the MDQ CIR/PIR limits and the widened SMQ allocation in place, with rate_limit false and num_tc 0?

mqprio_disable_offload() is void, so "tc qdisc del" looks successful to the user. The stale limits would remain until an unrelated ndo_stop()/ndo_open().

Should the restart still happen when the clear fails?

[ ... ]

drivers/net/ethernet/marvell/octeontx2/nic/qos.c static void otx2_config_sched_shaping(struct otx2_nic *pfvf, · line 125

Quoted 13 lines
drivers/net/ethernet/marvell/octeontx2/nic/qos.c +3 -0
index 2ede0b84e5f52..732fff75ab0be 100644
@@ -118,6 +118,9 @@ static void otx2_config_sched_shaping(struct otx2_nic *pfvf,
 	/* configure PIR */
 	maxrate = (node->rate > node->ceil) ? node->rate : node->ceil;
 
+	/* 65536 is the kernel-side default burst when HTB does not supply an
+	 * explicit value, not the NIX hardware maximum (CN10K_MAX_BURST_SIZE).
+	 */
 	cfg->regval[*num_regs] =
 		otx2_get_txschq_rate_regval(pfvf, maxrate, 65536);

[Severity: Low]
This isn't a bug, but is this comment accurate? struct tc_htb_qopt_offload has no burst member, so HTB offload can never supply an explicit burst, and 65536 is always used.

The comment in otx2_nix_tm_set_queue_shaper() ("Use the same 65536 byte default as the HTB shaper path") repeats the same idea.

[ ... ]

Quoted 5 lines
drivers/net/ethernet/marvell/octeontx2/nic/qos.c +0 -1
@@ -3420,11 +3437,13 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	otx2_sriov_vfcfg_cleanup(pf);
 err_pf_sriov_init:
 	otx2_unregister_dl(pf);
-	otx2_shutdown_tc(pf);

drivers/net/ethernet/marvell/octeontx2/nic/qos.c static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id) · line 3449

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/qos.c +3 -0
 err_mcam_flow_del:
 	otx2_mcam_flow_del(pf);
 err_unreg_netdev:
+	otx2_shutdown_tc_mqprio(pf);
 	unregister_netdev(netdev);
+err_shutdown_tc:
+	otx2_shutdown_tc(pf);
 err_ipsec_clean:
 	cn10k_ipsec_clean(pf);
 err_mcs_free:

[Severity: Medium]
Does the new label ordering stop otx2_shutdown_tc() from doing anything on the late probe error paths?

Before this patch, err_pf_sriov_init ran otx2_shutdown_tc() and only then fell through to otx2_mcam_flow_del(). With this patch, a failure in otx2_register_dl(), otx2_sriov_vfcfg_init(), the af_xdp_zc_qidx bitmap_zalloc() or otx2_dcbnl_set_ops() unwinds like this:

  err_mcam_flow_del:  otx2_mcam_flow_del()
  err_unreg_netdev:   otx2_shutdown_tc_mqprio(), unregister_netdev()
  err_shutdown_tc:    otx2_shutdown_tc()

otx2_mcam_flow_del() goes through otx2_destroy_mcam_flows(), which clears OTX2_FLAG_MCAM_ENTRIES_ALLOC.

otx2_shutdown_tc() then calls otx2_destroy_tc_flow_list(). That function returns early when OTX2_FLAG_MCAM_ENTRIES_ALLOC is clear, so it no longer walks flow_cfg->flow_list_tc.

Any otx2_tc_flow nodes added while the netdev was registered are therefore never freed. The window is small, and installing flower rules needs CAP_NET_ADMIN.

The ordering is also now the reverse of otx2_remove() after this patch. There, otx2_shutdown_tc() runs right after unregister_netdev(), and otx2_mcam_flow_del() runs later.

The unwind already reaches err_del_mcam_entries by fallthrough from err_shutdown_tc/err_ipsec_clean/err_mcs_free. err_del_mcam_entries calls otx2_mcam_flow_del() again, so the call at err_mcam_flow_del looks redundant.

Could that first call be dropped, with the labels folded, so the probe error path mirrors otx2_remove()? Or is there a reason the MCAM flows have to be deleted before unregister_netdev() here?

--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261109033154.2161803-1-rkannoth%40marvell.com

maintainer
#9 lore raw

Re: [PATCH v21 net-next 2/2] octeontx2: add mqprio bandwidth offload for NIX TX schedulers

In reply to Ratheesh Kannoth
Quoted 94 lines · On Mon, 9 Nov 2026 09:01:53 +0530 Ratheesh Kannoth wrote:

Add TC_SETUP_QDISC_MQPRIO offload with TC_MQPRIO_SHAPER_BW_RATE on PF and VF netdevs. Program per-queue MDQ CIR/PIR via the NIX TX scheduler mailbox; when active, allocate one SMQ per non-QoS queue under TL4[0].

The TX scheduler cannot be reprogrammed live, so add/replace/delete and failed setup bounce the netdev through ndo_stop()/ndo_open(). Cache rates in software and restore them from otx2_mqprio_up() on open, failing closed on error.

Stage tc replace in mq_offload_snap snapshots committed on TC_ROOT_GRAFT or replaced-qdisc teardown.

Require a running interface with CIR+PIR support. Reject offload with PFC, XDP, HTB, SDP representors, per-TC rates on multi-queue classes, and ethtool channel changes while active.

---
 .../marvell/octeontx2/nic/otx2_common.c       | 143 ++-
 .../marvell/octeontx2/nic/otx2_common.h       |  34 +
 .../marvell/octeontx2/nic/otx2_dcbnl.c        |   6 +
 .../marvell/octeontx2/nic/otx2_ethtool.c      |   8 +
 .../ethernet/marvell/octeontx2/nic/otx2_pf.c  |  34 +-
 .../ethernet/marvell/octeontx2/nic/otx2_tc.c  | 936 ++++++++++++++++++
 .../ethernet/marvell/octeontx2/nic/otx2_vf.c  |  28 +-
 .../net/ethernet/marvell/octeontx2/nic/qos.c  |  11 +
 8 files changed, 1179 insertions(+), 21 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +57 -0
index f4047b0d5d96..b4a738cf9a8b 100644
@@ -615,6 +615,139 @@ void otx2_get_mac_from_af(struct net_device *netdev)
 }
 EXPORT_SYMBOL(otx2_get_mac_from_af);
 
+static int
+otx2_nix_tmq_reg_write(struct otx2_nic *pfvf, int cnt,
+		       u64 reg_addr[MAX_REGS_PER_MBOX_MSG],
+		       u64 reg_val[MAX_REGS_PER_MBOX_MSG])
+{
+	struct mbox *mbox = &pfvf->mbox;
+	struct nix_txschq_config *req;
+	int i, err;
+
+	mutex_lock(&mbox->lock);
+	req = otx2_mbox_alloc_msg_nix_txschq_cfg(mbox);
+	if (!req) {
+		mutex_unlock(&mbox->lock);
+		return -ENOMEM;
+	}
+
+	req->lvl = NIX_TXSCH_LVL_MDQ;
+	req->num_regs = cnt;
+
+	for (i = 0; i < cnt; i++) {
+		req->reg[i] = reg_addr[i];
+		req->regval[i] = reg_val[i];
+	}
+
+	err = otx2_sync_mbox_msg(mbox);
+	mutex_unlock(&mbox->lock);
+
+	return err;
+}
+
+int otx2_nix_tm_clear_queue_shaper(struct otx2_nic *pfvf)
+{
+	u64 reg_addr[MAX_REGS_PER_MBOX_MSG];
+	u64 reg_val[MAX_REGS_PER_MBOX_MSG];
+	int err, smq, i, cnt = 0;
+
+	for (i = 0; i < pfvf->hw.txschq_cnt[NIX_TXSCH_LVL_SMQ]; i++) {
+		smq = pfvf->hw.txschq_list[NIX_TXSCH_LVL_SMQ][i];
+
+		reg_addr[cnt] = NIX_AF_MDQX_PIR(smq);
+		reg_val[cnt] = 0;
+		cnt++;
+
+		reg_addr[cnt] = NIX_AF_MDQX_CIR(smq);
+		reg_val[cnt] = 0;
+		cnt++;
+
+		if (cnt < MAX_REGS_PER_MBOX_MSG - 1)
+			continue;
+
+		err = otx2_nix_tmq_reg_write(pfvf, cnt,
+					     reg_addr, reg_val);
+		if (err)
+			goto fail;
+		cnt = 0;
+	}
+

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c void otx2_get_mac_from_af(struct net_device *netdev) · line 684

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +10 -0
+	if (cnt) {
+		err = otx2_nix_tmq_reg_write(pfvf, cnt,
+					     reg_addr, reg_val);
+		if (err)
+			goto fail;
+	}
+
+	return 0;
+fail:
+	return err;

just return err; why the label ?

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c void otx2_get_mac_from_af(struct net_device *netdev) · line 692

Quoted 8 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +8 -0
+struct mq_offload_snap {
+	u64 min_rate[TC_QOPT_MAX_QUEUE];
+	u64 max_rate[TC_QOPT_MAX_QUEUE];
+	u32 flags;
+	__u8 num_tc;
+	__u16 count[TC_QOPT_MAX_QUEUE];
+	__u16 offset[TC_QOPT_MAX_QUEUE];
+	__u8 prio_tc_map[TC_QOPT_BITMASK + 1];

Why is this using __u types?

drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c static int otx2_set_channels(struct net_device *dev, · line 294

Quoted 13 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +5 -0
index 4fe473d9ea0d..5428b3d1b332 100644
@@ -287,6 +287,14 @@ static int otx2_set_channels(struct net_device *dev,
 		return -EINVAL;
 	}
 
+	if (pfvf->mqprio.rate_limit &&
+	    (channel->tx_count != pfvf->hw.tx_queues ||
+	     channel->rx_count != pfvf->hw.rx_queues)) {
+		netdev_info(dev,
+			    "Not permitted to change channel count while MQ prio is active\n");

Why? This seems quite limiting.
User has to remove the root qdisc to change the queue count?

drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c static int otx2_set_channels(struct net_device *dev,

Quoted 9 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +6 -0
+		return -EINVAL;
+	}
+
 	if (if_up)
 		dev->netdev_ops->ndo_stop(dev);
 
+	if (prog && pf->mqprio.rate_limit) {
+		netdev_err(dev,
+			   "XDP: cannot attach while mqprio bandwidth offload is active\n");

Again - why?

drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c

Quoted 11 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +7 -0
+		return -EOPNOTSUPP;
+	}
+
 	if (prog && dev->mtu > MAX_XDP_MTU) {
 		netdev_warn(dev, "Jumbo frames not yet supported with XDP\n");
 		return -EOPNOTSUPP;
 
+static void otx2_mqprio_free_cache(struct otx2_nic *pfvf)
+{
+	devm_kfree(pfvf->dev, pfvf->mqprio.min_rate);
+	devm_kfree(pfvf->dev, pfvf->mqprio.max_rate);

devm_kfree() is a red flag, either this is something tied to the lifetime of the driver, or you need to clean this up. Saying that something "doesn't leak because it was devm_kmalloc()ed" is invalid. Drivers don't get re-probed in real life, memory parked in devm_ is as bad as leaked.

Quoted 5 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +5 -0
+static int otx2_mqprio_restart_netdev(struct net_device *netdev, bool rate_limit)
+{
+	struct otx2_nic *pfvf = netdev_priv(netdev);
+	const struct net_device_ops *ops = netdev->netdev_ops;
+	bool running = netif_running(netdev);

drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +10 -0
+	int err;
+
+	/* TODO: Explore live TX scheduler reprogramming to avoid a full
+	 * ndo_stop()/ndo_open() bounce on every mqprio change.
+	 */
+	netdev_dbg(netdev,
+		   "mqprio: restarting interface to reprogram TX scheduler\n");
+
+	if (running) {
+		clear_bit(__LINK_STATE_START, &netdev->state);

Messing with internal netdev state like this from the driver is obviously unacceptable.

drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c

Quoted 10 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c +9 -0
+		smp_mb__after_atomic(); /* Commit netif_running(). */
+	}
 
+	/* TODO: per-TC TL4 shapers or equal per-queue MDQ split for multi-queue TC rates. */
+	netdev_err(netdev,
+		   "mqprio: %s rate for tc %d not supported with %u queues\n",
+		   name, tc, qcount);
+	NL_SET_ERR_MSG_FMT_MOD(extack,
+			       "mqprio: tc %d rate needs 1 queue (has %u)",
+			       tc, qcount);

Doubling out output to extack and dmesg is not okay, user space should look at the extack. And a decade after it was added it mostly does.

You are at v21 this is nowhere near the acceptable quality. You should probably give up.