net: mana: reconfigure by replacing the queue set
Subsystems (5)
v2 cover net: mana: reconfigure by replacing the queue set
MANA reconfigures a port by destroying its queues and building them again. mana_detach() tears the whole queue set down, mana_attach() allocates a new one, and every path that changes a queue property does this: the ethtool channel, ring and private-flag setters, the MTU change and XDP attach.
If the second half fails there is nothing left to fall back to. The old queues are already gone, so the port stays down and the failure cannot be undone from userspace:
# ethtool -G ens1 rx 8192 tx 16384 # under memory pressure netlink error: Cannot allocate memory mana 7870:00:00.0 ens1: Failed to create 16 TX queues, -12 mana 7870:00:00.0 ens1: mana_attach failed: -12 # ip link show ens1 ... state DOWN
On VM SKUs with no netvsc fallback interface this takes the VM off the network entirely, and it is reachable from an ordinary ethtool ring resize that happens to run when memory is tight.
v1 [1] tried to recover after the fact: schedule a reset and retry mana_attach() with smaller values, falling back to the previous setting or to the defaults. Review pointed out that silently replacing a user's setting with a different one is the wrong behaviour, and that pre-allocating the resources and replacing the queue set looked feasible and should be investigated instead. This series does that, so there is no failure to recover from and no user setting to override.
The model is to build the new queue set alongside the running one, publish it, then retire the old one.
carrier off -> netif_tx_disable -> swap the queue pointers -> update the netdev queue counts -> reprogram RSS/steering -> reattach XDP -> netif_tx_start_all_queues -> restore carrier
Everything that can fail happens before anything is swapped. If allocation fails the running queues have not been touched at all: the ethtool call returns the error, the interface keeps forwarding traffic and the configuration is unchanged. If the swap itself fails, the previous set is put back and the port keeps running on it.
Patch layout:
1 the queue-set allocate/publish/free helpers.
2-6 convert the five callers: ethtool channels, rings and private
flags, the MTU change and XDP attach.
7 the remaining detach/attach users are the TX-timeout reset handler
and suspend; make mana_detach() always finish its teardown so the reset handler cannot leave a port permanently dead.
8-11 keep behaviour the swap model would otherwise change: per-queue
counters move into the port context so a rebuild no longer zeroes the interface statistics, the EQ pool is shared across a swap instead of being duplicated, EQs left idle by a reduction are released, and a user-configured RSS indirection table survives a rebuild.
12-13 stop rebuilding queues that do not change. A reduction keeps the
surviving queues and an increase keeps the existing ones, so
32 -> 8 channels destroys 24 queue pairs instead of building 8 and
destroying 32, and 4 -> 8 builds 4 instead of 8.Known trade-off, since it is deliberate: RX counters are now indexed by queue number in the port context, so during the window between steering moving to the new queues and the old ones being destroyed, both generations can update one slot. MANA is 64-bit only, so u64_stats_sync carries no seqcount and nothing can be corrupted; at worst a few increments are lost. Serialising them would put a lock in the per-packet receive path, and giving each set its own slots would make ndo_get_stats64() report a dip during a swap, which is the regression this is meant to remove.
[1] https://lore.kernel.org/netdev/[email protected]/
Dipayaan Roy (1):
net: mana: do not bail out of mana_detach on dealloc failure
Long Li (12):
net: mana: add queue-set allocation and teardown helpers
net: mana: swap queue sets in mana_set_channels
net: mana: swap queue sets in mana_set_ringparam
net: mana: swap queue sets in mana_set_priv_flags
net: mana: swap queue sets in mana_change_mtu
net: mana: swap queue sets in mana_xdp_set
net: mana: keep per-queue statistics in the port context
net: mana: share the EQ pool across a queue-set swap
net: mana: release EQs left idle by a channel-count reduction
net: mana: keep a user-configured RSS table across a queue rebuild
net: mana: keep the surviving queues when the channel count is reduced
net: mana: keep the existing queues when the channel count is raised
.../net/ethernet/microsoft/mana/mana_bpf.c | 117 +- drivers/net/ethernet/microsoft/mana/mana_en.c | 1698 ++++++++++++++++- .../ethernet/microsoft/mana/mana_ethtool.c | 333 +++- include/net/mana/gdma.h | 11 +- include/net/mana/mana.h | 130 +- 5 files changed, 2066 insertions(+), 223 deletions(-)
base-commit: d67e5dbda22604d0fcde32fce58c65f88676e676
Signature · 1 line
2.43.0
PATCH v2 1/13 net: mana: add queue-set allocation and teardown helpers
The ethtool reconfiguration paths (channel count, ring size, private flags) and mana_change_mtu()/mana_xdp_set() all rebuild the queues by calling mana_detach() followed by mana_attach(). That tears the vport down and rebuilds it, so the RDMA driver can claim the vport while it is released, and if mana_attach() fails the port is left down with no way back except manual intervention.
Introduce the data model for replacing that with pre-allocate and swap. struct mana_qset holds the queue-related fields of mana_port_context that can be rebuilt independently of the vport: the EQ/TXQ/RXQ arrays, the indirection and rxobj tables, and the configuration those queues were built for.
mana_alloc_qset() builds a complete queue set and mana_free_qset() destroys one. Both run against a scratch mana_port_context obtained from mana_qset_scratch_alloc() - a heap copy that shares the port's vport identity but owns no queues - so the live port context is never made to point at queues that are still being built or freed.
Running the allocators against a scratch context rather than temporarily clearing the live one is essential, not cosmetic. mana_start_xmit() dereferences apc->tx_qp[] guarded only by apc->port_is_up, and mana_alloc_qset() takes 50-300ms including firmware calls. An earlier revision of this work cleared apc->tx_qp so the existing allocators could build into the live context, and reliably panicked under traffic:
RIP: 0010:mana_start_xmit+0x138/0x1040 ; apc->tx_qp[txq_idx] RAX: 0000000000000000 CR2: 0000000000000000 Kernel panic - not syncing: Fatal exception in interrupt
The scratch context also gets rxbufs_pre = NULL so it never consumes the live set's preallocated RX buffers, and mana_port_debugfs = ERR_PTR(-ENODEV). debugfs_start_creating() returns early on an IS_ERR() parent and debugfs_remove() ignores IS_ERR_OR_NULL, which makes every create and remove a no-op for swapped-in sets. Without this the two live sets collide on the same names under vport%d.
mana_dealloc_queues()'s inline TX drain moves into mana_drain_txqs() so the new teardown path gets it too: a retiring queue set can still hold packets the device has not completed, and freeing the SQs and the SKB queues underneath them would leak those SKBs and their DMA mappings.
While moving it, the reset that the drain falls back to when the hardware stops responding becomes pci_try_reset_function() instead of an open-coded pcie_flr(). pcie_flr() resets the function without saving and restoring config space, so BARs, MSI-X state and bus master enable are wiped while the PCI core still believes its cached values are live. pci_try_reset_function() brackets the reset with pci_dev_save_and_disable() and pci_dev_restore(). The trylock variant is required rather than pci_reset_function(): this runs under RTNL, while driver removal takes the device lock first and RTNL second, so blocking on the device lock here could deadlock.
Other than that reset change, no functional change: nothing calls the new helpers yet.
--- .../net/ethernet/microsoft/mana/mana_bpf.c | 31 ++ drivers/net/ethernet/microsoft/mana/mana_en.c | 520 ++++++++++++++++-- include/net/mana/mana.h | 64 +++ 3 files changed, 577 insertions(+), 38 deletions(-)
drivers/net/ethernet/microsoft/mana/mana_bpf.c +31 -0
@@ -265,3 +265,34 @@ int mana_bpf(struct net_device *ndev, struct netdev_bpf *bpf)return ret; } + +/* Read the XDP program a queue set is running, without changing anything. */ +struct bpf_prog *mana_chn_xdp_peek (struct mana_port_context *apc) +{ +ASSERT_RTNL (); + +if (!apc->rxqs || !apc->rxqs[0 ]) +return NULL ; + +return rtnl_dereference (apc->rxqs[0 ]->bpf_prog); +} + +/* Drop the per-queue references a retiring set holds on @prog. +* +* Kept separate from mana_chn_setxdp() so the pointers can stay in place +* until the queues stop polling: clearing them up front would let packets +* already sitting in a retiring RQ take the pass path and reach the stack +* without the program ever seeing them. +*/ +void mana_chn_xdp_release (struct bpf_prog *prog,unsigned int num_queues) +{ +unsigned int i; + +ASSERT_RTNL (); + +if (!prog) +return ; + +for (i =0 ; i < num_queues; i++) +bpf_prog_put (prog); +}
drivers/net/ethernet/microsoft/mana/mana_en.c +482 -38
574 lines not on this page · raw message
include/net/mana/mana.h +64 -0
94 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 2/13 net: mana: swap queue sets in mana_set_channels
In reply to Long LiAdd mana_publish_qset(), which installs a queue set built by mana_alloc_qset() onto the live port context and hands the previous set back to the caller, and use it to convert mana_set_channels() away from detach/attach.
The publish ordering is:
carrier off -> netif_tx_disable -> swap pointers -> update netdev queue counts -> reprogram RSS/steering -> netif_tx_start_all_queues -> carrier restore
netif_tx_disable() is load-bearing. mana_start_xmit() dereferences apc->tx_qp[] guarded only by apc->port_is_up, so swapping the array with TX live would let an in-flight xmit use a pointer that the caller is about to free, and would let ndo_select_queue() hand out an index derived from a stale real_num_tx_queues.
The old set's NAPI keeps running between the swap and mana_free_qset(). That is safe: the old CQs and RQs are still fully constructed, and mana_destroy_txq()/mana_destroy_rxq() perform napi_synchronize() and napi_disable_locked() before freeing anything.
If mana_publish_qset() fails partway it reinstalls the old set and points steering back at it, so the caller only has to free the new set.
For mana_set_channels() this removes the failure mode entirely. The new queues are built before anything is torn down, so an allocation failure returns the error with the running configuration untouched, and the value the user asked for is never silently replaced by a fallback. The vport is never released, so vport_use_count stays above zero and RDMA cannot claim it mid-reconfiguration.
--- .../net/ethernet/microsoft/mana/mana_bpf.c | 7 + drivers/net/ethernet/microsoft/mana/mana_en.c | 402 +++++++++++++++++- .../ethernet/microsoft/mana/mana_ethtool.c | 103 ++++- include/net/mana/mana.h | 13 + 4 files changed, 502 insertions(+), 23 deletions(-)
drivers/net/ethernet/microsoft/mana/mana_bpf.c +7 -0
@@ -59,6 +59,13 @@ int mana_xdp_xmit(struct net_device *ndev, int n, struct xdp_frame **frames,if (unlikely (!apc->port_is_up))return 0 ; +/* Pair with the smp_wmb() in mana_publish_qset(), as mana_start_xmit() +* does. This path is gated only by the flag above, so without the +* barrier it could pick q_idx from a stale real_num_tx_queues and +* index a freshly installed, smaller apc->tx_qp[]. +*/ +smp_rmb (); + q_idx =smp_processor_id () % ndev->real_num_tx_queues;for (i =0 ; i < n; i++) {
drivers/net/ethernet/microsoft/mana/mana_en.c +400 -2
446 lines not on this page · raw message
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +82 -21
132 lines not on this page · raw message
include/net/mana/mana.h +13 -0
@@ -634,6 +634,16 @@ struct mana_port_context {*/ bool channel_changing; +/* mana_publish_qset() could neither publish the new queue set nor put +* the previous one back. It has already disabled vport RX, so nothing +* is being delivered; what is left is closing the port, and that can +* only happen after the caller has torn down the set it was trying to +* publish: those queues own CQs attached to the shared EQ pool, and +* closing destroys that pool. Checked through +* mana_publish_close_if_needed(). +*/ +bool publish_dead_end; +/* Net shaper handle*/ struct net_shaper_handle handle;
@@ -730,6 +740,9 @@ void mana_qset_scratch_free(struct mana_port_context *scratch);int mana_alloc_qset (struct mana_port_context *scratch,unsigned int num_queues,unsigned int rx_queue_size,unsigned int tx_queue_size,u32 priv_flags,struct mana_qset *out); +int mana_publish_qset (struct mana_port_context *apc,struct mana_qset *newq, +struct mana_qset *out_old); +void mana_publish_close_if_needed (struct mana_port_context *apc);void mana_free_qset (struct mana_port_context *scratch,struct mana_qset *qset);void mana_dim_change (struct mana_cq *cq,bool enable);
Signature · 1 line
2.43.0
PATCH v2 3/13 net: mana: swap queue sets in mana_set_ringparam
In reply to Long LiConvert the ring size path to the pre-allocate and swap helpers, for the same reasons as mana_set_channels(): the new queues are built before anything is torn down, so an allocation failure returns the error with the running configuration untouched, and the vport is never released so RDMA cannot claim it mid-reconfiguration.
This also drops the fallback behaviour on failure. Previously, when mana_attach() failed, the code retried with ring sizes chosen to maximise the chance of recovery - the previous values, or the defaults, or the minimums - and scheduled queue_reset_work(). A user who asked for a specific ring size could therefore end up with a different one, with no indication beyond dmesg. There is nothing to recover from now, so the error is simply returned and the requested value is never silently replaced.
Add an early return when the requested sizes round to the values already in use.
--- .../ethernet/microsoft/mana/mana_ethtool.c | 81 +++++++++++++------ 1 file changed, 58 insertions(+), 23 deletions(-)
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +58 -23
@@ -775,19 +775,25 @@ static void mana_get_ringparam(struct net_device *ndev, ring->tx_max_pending =MAX_TX_BUFFERS_PER_QUEUE ; } +/* mana_set_ringparam - resize the RX/TX rings +* +* Uses the pre-allocate + swap path: the new queue set is built with the +* requested ring sizes while the current one keeps serving traffic. If the +* allocation fails the running configuration is untouched and the error is +* returned - the requested sizes are never silently replaced by fallback +* values. +*/ static int mana_set_ringparam (struct net_device *ndev,struct ethtool_ringparam *ring,struct kernel_ethtool_ringparam *kernel_ring,struct netlink_ext_ack *extack) {struct mana_port_context *apc =netdev_priv (ndev); +struct mana_port_context *scratch; +struct mana_qset newq, oldq;u32 new_tx, new_rx; -u32 old_tx, old_rx;int err; - old_tx = apc->tx_queue_size; - old_rx = apc->rx_queue_size; -if (ring->tx_pending <MIN_TX_BUFFERS_PER_QUEUE ) {NL_SET_ERR_MSG_FMT (extack,"tx:%d less than the min:%d" , ring->tx_pending,MIN_TX_BUFFERS_PER_QUEUE );
@@ -805,32 +811,61 @@ static int mana_set_ringparam(struct net_device *ndev,netdev_info (ndev,"Using nearest power of 2 values for Txq:%d Rxq:%d\n" , new_tx, new_rx); -/* pre-allocating new buffers to prevent failures in mana_attach() later */ - apc->rx_queue_size = new_rx; - err =mana_pre_alloc_rxbufs (apc, ndev->mtu, apc->num_queues); - apc->rx_queue_size = old_rx; -if (err) { -netdev_err (ndev,"Insufficient memory for new allocations\n" ); -return err; +if (new_rx == apc->rx_queue_size && new_tx == apc->tx_queue_size) +return 0 ; + +/* Port is down: no queues to rebuild, just record the new sizes. */ +if (!apc->port_is_up) { + apc->rx_queue_size = new_rx; + apc->tx_queue_size = new_tx; +return 0 ; } - err =mana_detach (ndev, false); -if (err) { -netdev_err (ndev,"mana_detach failed: %d\n" , err); - goto out; +/* Block RDMA from acquiring the vport for the duration. The vport +* itself is never released, so vport_use_count stays > 0. +*/ +mutex_lock (&apc->vport_mutex); +if (apc->channel_changing) { +mutex_unlock (&apc->vport_mutex); +return -EBUSY ; + } + apc->channel_changing = true; +mutex_unlock (&apc->vport_mutex); + + scratch =mana_qset_scratch_alloc (apc); +if (!scratch) { + err = -ENOMEM ; + goto clear_flag; } - apc->tx_queue_size = new_tx; - apc->rx_queue_size = new_rx; + err =mana_alloc_qset (scratch, apc->num_queues, new_rx, new_tx, + apc->priv_flags, &newq); +if (err) { +NL_SET_ERR_MSG_FMT (extack,"failed to change ring params: %d" , + err); + goto free_scratch;/* current qset untouched */ + } - err =mana_attach (ndev); + err =mana_publish_qset (apc, &newq, &oldq);if (err) { -netdev_err (ndev,"mana_attach failed: %d\n" , err); - apc->tx_queue_size = old_tx; - apc->rx_queue_size = old_rx; +NL_SET_ERR_MSG_FMT (extack,"failed to change ring params: %d" , + err); +mana_free_qset (scratch, &newq); + goto free_scratch; } -out: -mana_pre_dealloc_rxbufs (apc); + +mana_free_qset (scratch, &oldq); + +free_scratch: +/* After the caller-side cleanup above, so the EQ pool outlives the +* CQs that reference it. +*/ +mana_publish_close_if_needed (apc); +mana_qset_scratch_free (scratch); +clear_flag: +mutex_lock (&apc->vport_mutex); + apc->channel_changing = false; +mutex_unlock (&apc->vport_mutex);return err; }
Signature · 1 line
2.43.0
PATCH v2 4/13 net: mana: swap queue sets in mana_set_priv_flags
In reply to Long LiMANA_PRIV_FLAG_USE_FULL_PAGE_RXBUF changes the RX buffer layout, so toggling it rebuilds the queues. Convert that path to the pre-allocate and swap helpers, for the same reasons as the channel count and ring size paths: an allocation failure now returns the error with both the queues and the flag word untouched, and the vport is never released so RDMA cannot claim it mid-reconfiguration.
The flag word is no longer written before the rebuild and rolled back on failure. It is passed to mana_alloc_qset() as part of the queue-set configuration and installed by mana_publish_qset() only once the new set is serving traffic, so there is no window where apc->priv_flags describes queues that do not exist.
Scheduling queue_reset_work() on failure is dropped along with it. After this patch the TX timeout handler is the only remaining user of queue_reset_work().
The existing shortcuts are unchanged in behaviour - a down port, or a configuration where single-buffer-per-page is already forced by a jumbo MTU or an attached XDP program, still just records the new value - but they now share one condition instead of being spread across the function.
--- .../ethernet/microsoft/mana/mana_ethtool.c | 85 ++++++++++--------- 1 file changed, 47 insertions(+), 38 deletions(-)
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +47 -38
@@ -891,11 +891,18 @@ static u32 mana_get_priv_flags(struct net_device *ndev)return apc->priv_flags; } +/* mana_set_priv_flags - apply a change to the driver private flags +* +* MANA_PRIV_FLAG_USE_FULL_PAGE_RXBUF changes the RX buffer layout, so the +* queues must be rebuilt. Uses the pre-allocate + swap path, so a failed +* allocation leaves both the queues and the flag word untouched. +*/ static int mana_set_priv_flags (struct net_device *ndev,u32 priv_flags) {struct mana_port_context *apc =netdev_priv (ndev);u32 changed = apc->priv_flags ^ priv_flags; -u32 old_priv_flags = apc->priv_flags; +struct mana_port_context *scratch; +struct mana_qset newq, oldq;int err =0 ;if (!changed)
@@ -905,54 +912,56 @@ static int mana_set_priv_flags(struct net_device *ndev, u32 priv_flags)if (priv_flags & ~GENMASK (MANA_PRIV_FLAG_MAX -1 ,0 ))return -EINVAL ; - apc->priv_flags = priv_flags; - -if (changed &BIT (MANA_PRIV_FLAG_USE_FULL_PAGE_RXBUF )) { -if (!apc->port_is_up) -return 0 ; - -/* If XDP is attached or MTU is jumbo, single-buffer-per-page -* is already forced regardless of this flag. Skip the -* expensive detach/attach cycle since nothing changes. -*/ -if (ndev->mtu +MANA_RXBUF_PAD >PAGE_SIZE /2 || -mana_xdp_get (apc)) -return 0 ; +/* Only the RX buffer layout flag requires a queue rebuild. Anything +* else, a down port, or a configuration where single-buffer-per-page +* is already forced, just records the new value. +*/ +if (!(changed &BIT (MANA_PRIV_FLAG_USE_FULL_PAGE_RXBUF )) || + !apc->port_is_up || + ndev->mtu +MANA_RXBUF_PAD >PAGE_SIZE /2 || +mana_xdp_get (apc)) { + apc->priv_flags = priv_flags; +return 0 ; + } -/* Block RDMA from grabbing the vport during detach/attach */ -mutex_lock (&apc->vport_mutex); - apc->channel_changing = true; +/* Block RDMA from acquiring the vport for the duration. */ +mutex_lock (&apc->vport_mutex); +if (apc->channel_changing) {mutex_unlock (&apc->vport_mutex); +return -EBUSY ; + } + apc->channel_changing = true; +mutex_unlock (&apc->vport_mutex); - err =mana_pre_alloc_rxbufs (apc, ndev->mtu, apc->num_queues); -if (err) { -netdev_err (ndev, -"Insufficient memory for new allocations\n" ); - apc->priv_flags = old_priv_flags; - goto clear_flag; - } + scratch =mana_qset_scratch_alloc (apc); +if (!scratch) { + err = -ENOMEM ; + goto clear_flag; + } - err =mana_detach (ndev, false); -if (err) { -netdev_err (ndev,"mana_detach failed: %d\n" , err); - apc->priv_flags = old_priv_flags; - goto out; - } + err =mana_alloc_qset (scratch, apc->num_queues, apc->rx_queue_size, + apc->tx_queue_size, priv_flags, &newq); +if (err) + goto free_scratch;/* current qset and priv_flags untouched */ - err =mana_attach (ndev); -if (err) { -netdev_err (ndev,"mana_attach failed: %d\n" , err); - apc->priv_flags = old_priv_flags; - } + err =mana_publish_qset (apc, &newq, &oldq); +if (err) { +mana_free_qset (scratch, &newq); + goto free_scratch; } -out: -mana_pre_dealloc_rxbufs (apc); +mana_free_qset (scratch, &oldq); + +free_scratch: +/* After the caller-side cleanup above, so the EQ pool outlives the +* CQs that reference it. +*/ +mana_publish_close_if_needed (apc); +mana_qset_scratch_free (scratch); clear_flag:mutex_lock (&apc->vport_mutex); apc->channel_changing = false;mutex_unlock (&apc->vport_mutex); -return err; }
Signature · 1 line
2.43.0
PATCH v2 5/13 net: mana: swap queue sets in mana_change_mtu
In reply to Long LiThe RX buffer layout depends on the MTU - see mana_get_rxbuf_cfg() - so changing it rebuilds the queues. Convert mana_change_mtu() to the pre-allocate and swap helpers.
The MTU becomes part of the queue-set configuration:
- struct mana_qset gains mtu, so it is swapped atomically with the queues it describes and restored by the rollback path.
- mana_port_context gains configured_mtu, the MTU the current RX queues were built for. mana_create_rxq() now sizes buffers from it rather than ndev->mtu, so a new set can be built for a different MTU while ndev->mtu still advertises the old one.
- mana_publish_qset() commits ndev->mtu once the new set is serving traffic. It is a no-op for callers that do not change the MTU.
Previously ndev->mtu was written before mana_attach() and rolled back on failure, so a failed change was briefly visible to the stack.
mana_pre_alloc_rxbufs() is no longer needed here; de-risking allocation after teardown is pointless when there is no teardown.
--- drivers/net/ethernet/microsoft/mana/mana_en.c | 75 ++++++++++++++----- .../ethernet/microsoft/mana/mana_ethtool.c | 8 +- include/net/mana/mana.h | 14 +++- 3 files changed, 74 insertions(+), 23 deletions(-)
drivers/net/ethernet/microsoft/mana/mana_en.c +56 -19
@@ -889,35 +889,54 @@ int mana_pre_alloc_rxbufs(struct mana_port_context *mpc, int new_mtu, int num_qureturn -ENOMEM ; } +/* mana_change_mtu - resize RX buffers for a new MTU +* +* Uses the pre-allocate + swap path: the new queue set is built for +* @new_mtu while the current one keeps serving traffic at the old MTU. +* ndev->mtu is only updated once the new set is live (see +* mana_publish_qset), so a failed allocation leaves both the queues and +* the advertised MTU untouched. +*/ static int mana_change_mtu (struct net_device *ndev,int new_mtu) {struct mana_port_context *mpc =netdev_priv (ndev); -unsigned int old_mtu = ndev->mtu; +struct mana_port_context *scratch; +struct mana_qset newq, oldq;int err; -/* Pre-allocate buffers to prevent failure in mana_attach later */ - err =mana_pre_alloc_rxbufs (mpc, new_mtu, mpc->num_queues); -if (err) { -netdev_err (ndev,"Insufficient memory for new MTU\n" ); -return err; +/* Port is down: no queues to rebuild, just record the new MTU. +* mana_open() will size the RX buffers accordingly. +*/ +if (!mpc->port_is_up) { + mpc->configured_mtu = new_mtu; +WRITE_ONCE (ndev->mtu, new_mtu); +return 0 ; } - err =mana_detach (ndev, false); -if (err) { -netdev_err (ndev,"mana_detach failed: %d\n" , err); - goto out; - } + scratch =mana_qset_scratch_alloc (mpc); +if (!scratch) +return -ENOMEM ; -WRITE_ONCE (ndev->mtu, new_mtu); + err =mana_alloc_qset (scratch, mpc->num_queues, mpc->rx_queue_size, + mpc->tx_queue_size, mpc->priv_flags, new_mtu, + &newq); +if (err) + goto free_scratch;/* current qset and ndev->mtu untouched */ - err =mana_attach (ndev); + err =mana_publish_qset (mpc, &newq, &oldq);if (err) { -netdev_err (ndev,"mana_attach failed: %d\n" , err); -WRITE_ONCE (ndev->mtu, old_mtu); +mana_free_qset (scratch, &newq); + goto free_scratch; } -out: -mana_pre_dealloc_rxbufs (mpc); +mana_free_qset (scratch, &oldq); + +free_scratch: +/* After the caller-side cleanup above, so the EQ pool outlives the +* CQs that reference it. +*/ +mana_publish_close_if_needed (mpc); +mana_qset_scratch_free (scratch);return err; }
@@ -3097,7 +3116,8 @@ static struct mana_rxq *mana_create_rxq(struct mana_port_context *apc, rxq->rxq_idx = rxq_idx; rxq->rxobj =INVALID_MANA_HANDLE ; -mana_get_rxbuf_cfg (apc, ndev->mtu, &rxq->datasize, &rxq->alloc_size, +mana_get_rxbuf_cfg (apc, apc->configured_mtu, &rxq->datasize, + &rxq->alloc_size, &rxq->headroom, &rxq->frag_count);/* Create page pool for RX queue */ err =mana_create_page_pool (rxq, gc);
@@ -3965,6 +3985,7 @@ static void mana_qset_snapshot(const struct mana_port_context *ctx, out->rx_queue_size = ctx->rx_queue_size; out->tx_queue_size = ctx->tx_queue_size; out->priv_flags = ctx->priv_flags; + out->mtu = ctx->configured_mtu; out->mana_eqs_debugfs = ctx->mana_eqs_debugfs; }
@@ -3986,6 +4007,7 @@ static void mana_qset_install(struct mana_port_context *ctx, ctx->rx_queue_size = qset->rx_queue_size; ctx->tx_queue_size = qset->tx_queue_size; ctx->priv_flags = qset->priv_flags; + ctx->configured_mtu = qset->mtu; ctx->mana_eqs_debugfs = qset->mana_eqs_debugfs; }
@@ -4049,6 +4071,7 @@ void mana_qset_scratch_free(struct mana_port_context *scratch)* @rx_queue_size: new RX ring size * @tx_queue_size: new TX ring size * @priv_flags: new priv-flag word (affects full-page RX) +* @mtu: MTU the new set is sized for * @out: output qset, populated on success * * The live port context is not referenced at all, so the currently
@@ -4057,7 +4080,7 @@ void mana_qset_scratch_free(struct mana_port_context *scratch)*/ int mana_alloc_qset (struct mana_port_context *scratch,unsigned int num_queues,unsigned int rx_queue_size,unsigned int tx_queue_size, -u32 priv_flags,struct mana_qset *out) +u32 priv_flags,int mtu,struct mana_qset *out) {struct net_device *ndev = scratch->ndev;int err;
@@ -4069,6 +4092,12 @@ int mana_alloc_qset(struct mana_port_context *scratch, unsigned int num_queues, scratch->tx_queue_size = tx_queue_size; scratch->priv_flags = priv_flags; +/* mana_get_rxbuf_cfg() reads this when sizing RX buffers, so the +* new set is built for the requested MTU without disturbing the +* running set. +*/ + scratch->configured_mtu = mtu; + err =mana_init_port_context (scratch);if (err) goto out_err;
@@ -4361,6 +4390,11 @@ int mana_publish_qset(struct mana_port_context *apc, struct mana_qset *newq,if (err) goto rollback; +/* The new set is serving traffic: advertise its MTU. A no-op for +* callers that are not changing the MTU. +*/ +WRITE_ONCE (ndev->mtu, apc->configured_mtu); +/* Pair with the queue-state stores above: a datapath reader that sees * the gate open must also see the queue set it is about to index. */
@@ -4413,6 +4447,8 @@ int mana_publish_qset(struct mana_port_context *apc, struct mana_qset *newq,return err; } +WRITE_ONCE (ndev->mtu, apc->configured_mtu); +/* Same pairing as the success path: the restored queue set has to be * visible before the gate reopens on it. */
@@ -4658,6 +4694,7 @@ static int mana_probe_port(struct mana_context *ac, int port_idx, apc->port_handle =INVALID_MANA_HANDLE ; apc->pf_filter_handle =INVALID_MANA_HANDLE ; apc->port_idx = port_idx; + apc->configured_mtu = ndev->mtu; apc->link_cfg_error =1 ; apc->cqe_coalescing_enable =0 ; apc->cqe8_coalescing_enable =0 ;
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +5 -3
@@ -737,7 +737,8 @@ static int mana_set_channels(struct net_device *ndev, } err =mana_alloc_qset (scratch, new_count, apc->rx_queue_size, - apc->tx_queue_size, apc->priv_flags, &newq); + apc->tx_queue_size, apc->priv_flags, + apc->configured_mtu, &newq);if (err) goto free_scratch;/* current qset untouched, nothing to undo */
@@ -839,7 +840,7 @@ static int mana_set_ringparam(struct net_device *ndev, } err =mana_alloc_qset (scratch, apc->num_queues, new_rx, new_tx, - apc->priv_flags, &newq); + apc->priv_flags, apc->configured_mtu, &newq);if (err) {NL_SET_ERR_MSG_FMT (extack,"failed to change ring params: %d" , err);
@@ -940,7 +941,8 @@ static int mana_set_priv_flags(struct net_device *ndev, u32 priv_flags) } err =mana_alloc_qset (scratch, apc->num_queues, apc->rx_queue_size, - apc->tx_queue_size, priv_flags, &newq); + apc->tx_queue_size, priv_flags, + apc->configured_mtu, &newq);if (err) goto free_scratch;/* current qset and priv_flags untouched */
include/net/mana/mana.h +13 -1
@@ -621,6 +621,12 @@ struct mana_port_context {unsigned int rx_queue_size;unsigned int tx_queue_size; +/* MTU the current RX queues were built for. Normally equal to +* ndev->mtu, but during a queue-set swap the new set is built for +* the new MTU while ndev->mtu still advertises the old one. +*/ +int configured_mtu; +mana_handle_t port_handle;mana_handle_t pf_filter_handle;
@@ -714,6 +720,12 @@ struct mana_qset {unsigned int tx_queue_size;u32 priv_flags; +/* MTU the RX buffers of this set were sized for. It feeds +* mana_get_rxbuf_cfg(), so it is part of the queue-set +* configuration and must be swapped atomically with the queues. +*/ +int mtu; +/* Per-queue-set debugfs root ("EQs"). Owned by the qset: it is * recreated by mana_create_eq() for each new set and torn down * with that set, so it must travel with the qset rather than
@@ -739,7 +751,7 @@ struct mana_port_context *mana_qset_scratch_alloc(struct mana_port_context *apc)void mana_qset_scratch_free (struct mana_port_context *scratch);int mana_alloc_qset (struct mana_port_context *scratch,unsigned int num_queues,unsigned int rx_queue_size,unsigned int tx_queue_size, -u32 priv_flags,struct mana_qset *out); +u32 priv_flags,int mtu,struct mana_qset *out);int mana_publish_qset (struct mana_port_context *apc,struct mana_qset *newq,struct mana_qset *out_old);void mana_publish_close_if_needed (struct mana_port_context *apc);
Signature · 1 line
2.43.0
PATCH v2 6/13 net: mana: swap queue sets in mana_xdp_set
In reply to Long LiAttaching or detaching an XDP program changes the RX buffer layout - full pages with headroom rather than page fragments, see mana_get_rxbuf_cfg() - so it rebuilds the queues. Convert mana_xdp_set() to the pre-allocate and swap helpers, completing the removal of detach/attach from the reconfiguration paths.
struct mana_qset gains bpf_prog, so the program the queues were built for is swapped atomically with them and restored by the rollback path.
Refcounting is handled by the swap helpers. mana_publish_qset() already re-attaches apc->bpf_prog to the new RX queues, which are created with bpf_prog == NULL; installing qset->bpf_prog first means that same call now attaches the new program. mana_free_qset() drops the old set's per-queue references. The caller's reference is still consumed by the port context and the old one released once, as before.
mana_pre_alloc_rxbufs() is no longer needed here. The TX timeout reset handler is now its only caller.
--- .../net/ethernet/microsoft/mana/mana_bpf.c | 75 +++++++++++-------- drivers/net/ethernet/microsoft/mana/mana_en.c | 15 ++-- .../ethernet/microsoft/mana/mana_ethtool.c | 7 +- include/net/mana/mana.h | 16 ++-- 4 files changed, 65 insertions(+), 48 deletions(-)
drivers/net/ethernet/microsoft/mana/mana_bpf.c +42 -33
@@ -175,10 +175,24 @@ void mana_chn_setxdp(struct mana_port_context *apc, struct bpf_prog *prog)bpf_prog_put (old_prog); } +/* mana_xdp_set - attach or detach an XDP program +* +* Attaching or detaching XDP changes the RX buffer layout (full pages with +* headroom vs. page fragments), so the RX queues must be rebuilt. Uses the +* pre-allocate + swap path: the new set is built for @prog while the +* current one keeps serving traffic. On allocation failure nothing changes +* and the error is returned to the caller. +* +* mana_publish_qset() installs qset->bpf_prog onto apc and re-attaches it +* to the new RX queues, and mana_free_qset() drops the old set's per-queue +* references, so refcounting is handled by the swap helpers. +*/ static int mana_xdp_set (struct net_device *ndev,struct bpf_prog *prog,struct netlink_ext_ack *extack) {struct mana_port_context *apc =netdev_priv (ndev); +struct mana_port_context *scratch; +struct mana_qset newq, oldq;struct bpf_prog *old_prog;struct gdma_context *gc;int err;
@@ -198,46 +212,46 @@ static int mana_xdp_set(struct net_device *ndev, struct bpf_prog *prog,return -EOPNOTSUPP ; } -/* One refcnt of the prog is hold by the caller already, so -* don't increase refcnt for this one. -*/ - apc->bpf_prog = prog; -if (apc->port_is_up) { -/* Re-create rxq's after xdp prog was loaded or unloaded. -* Ex: re create rxq's to switch from full pages to smaller -* size page fragments when xdp prog is unloaded and -* vice-versa. -*/ - -/* Pre-allocate buffers to prevent failure in mana_attach */ - err =mana_pre_alloc_rxbufs (apc, ndev->mtu, apc->num_queues); -if (err) { + scratch =mana_qset_scratch_alloc (apc); +if (!scratch) {NL_SET_ERR_MSG_MOD (extack, -"XDP: Insufficient memory for tx/rx re-config" ); -return err; +"XDP: Insufficient memory for re-config" ); +return -ENOMEM ; } - err =mana_detach (ndev, false); + err =mana_alloc_qset (scratch, apc->num_queues, + apc->rx_queue_size, apc->tx_queue_size, + apc->priv_flags, apc->configured_mtu, + prog, &newq);if (err) { -netdev_err (ndev, -"mana_detach failed at xdp set: %d\n" , err);NL_SET_ERR_MSG_MOD (extack, -"XDP: Re-config failed at detach" ); - goto err_dealloc_rxbuffs; +"XDP: Re-config failed at alloc" ); +mana_qset_scratch_free (scratch); +return err; } - err =mana_attach (ndev); + err =mana_publish_qset (apc, &newq, &oldq);if (err) { -netdev_err (ndev, -"mana_attach failed at xdp set: %d\n" , err);NL_SET_ERR_MSG_MOD (extack, -"XDP: Re-config failed at attach" ); - goto err_dealloc_rxbuffs; +"XDP: Re-config failed at publish" ); +mana_free_qset (scratch, &newq); +/* After the cleanup above: closing destroys the EQ pool +* those queues' CQs were attached to. +*/ +mana_publish_close_if_needed (apc); +mana_qset_scratch_free (scratch); +return err; } -mana_chn_setxdp (apc, prog); -mana_pre_dealloc_rxbufs (apc); +mana_free_qset (scratch, &oldq); +mana_qset_scratch_free (scratch); + }else { +/* No queues to rebuild; mana_open() will size the RX buffers +* for this program. One refcnt is held by the caller already, +* so don't take another. +*/ + apc->bpf_prog = prog; }if (old_prog)
@@ -250,11 +264,6 @@ static int mana_xdp_set(struct net_device *ndev, struct bpf_prog *prog, ndev->max_mtu = gc->adapter_mtu -ETH_HLEN ;return 0 ; - -err_dealloc_rxbuffs: - apc->bpf_prog = old_prog; -mana_pre_dealloc_rxbufs (apc); -return err; }int mana_bpf (struct net_device *ndev,struct netdev_bpf *bpf)
drivers/net/ethernet/microsoft/mana/mana_en.c +10 -5
@@ -919,7 +919,7 @@ static int mana_change_mtu(struct net_device *ndev, int new_mtu) err =mana_alloc_qset (scratch, mpc->num_queues, mpc->rx_queue_size, mpc->tx_queue_size, mpc->priv_flags, new_mtu, - &newq); + mpc->bpf_prog, &newq);if (err) goto free_scratch;/* current qset and ndev->mtu untouched */
@@ -3986,6 +3986,7 @@ static void mana_qset_snapshot(const struct mana_port_context *ctx, out->tx_queue_size = ctx->tx_queue_size; out->priv_flags = ctx->priv_flags; out->mtu = ctx->configured_mtu; + out->bpf_prog = ctx->bpf_prog; out->mana_eqs_debugfs = ctx->mana_eqs_debugfs; }
@@ -4008,6 +4009,7 @@ static void mana_qset_install(struct mana_port_context *ctx, ctx->tx_queue_size = qset->tx_queue_size; ctx->priv_flags = qset->priv_flags; ctx->configured_mtu = qset->mtu; + ctx->bpf_prog = qset->bpf_prog; ctx->mana_eqs_debugfs = qset->mana_eqs_debugfs; }
@@ -4072,6 +4074,7 @@ void mana_qset_scratch_free(struct mana_port_context *scratch)* @tx_queue_size: new TX ring size * @priv_flags: new priv-flag word (affects full-page RX) * @mtu: MTU the new set is sized for +* @bpf_prog: XDP program the new set is sized for, may be NULL * @out: output qset, populated on success * * The live port context is not referenced at all, so the currently
@@ -4080,7 +4083,8 @@ void mana_qset_scratch_free(struct mana_port_context *scratch)*/ int mana_alloc_qset (struct mana_port_context *scratch,unsigned int num_queues,unsigned int rx_queue_size,unsigned int tx_queue_size, -u32 priv_flags,int mtu,struct mana_qset *out) +u32 priv_flags,int mtu,struct bpf_prog *bpf_prog, +struct mana_qset *out) {struct net_device *ndev = scratch->ndev;int err;
@@ -4092,11 +4096,12 @@ int mana_alloc_qset(struct mana_port_context *scratch, unsigned int num_queues, scratch->tx_queue_size = tx_queue_size; scratch->priv_flags = priv_flags; -/* mana_get_rxbuf_cfg() reads this when sizing RX buffers, so the -* new set is built for the requested MTU without disturbing the -* running set. +/* mana_get_rxbuf_cfg() reads both of these when sizing RX buffers, +* so the new set is built for the requested MTU / XDP program +* without disturbing the running set. */ scratch->configured_mtu = mtu; + scratch->bpf_prog = bpf_prog; err =mana_init_port_context (scratch);if (err)
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +4 -3
@@ -738,7 +738,7 @@ static int mana_set_channels(struct net_device *ndev, err =mana_alloc_qset (scratch, new_count, apc->rx_queue_size, apc->tx_queue_size, apc->priv_flags, - apc->configured_mtu, &newq); + apc->configured_mtu, apc->bpf_prog, &newq);if (err) goto free_scratch;/* current qset untouched, nothing to undo */
@@ -840,7 +840,8 @@ static int mana_set_ringparam(struct net_device *ndev, } err =mana_alloc_qset (scratch, apc->num_queues, new_rx, new_tx, - apc->priv_flags, apc->configured_mtu, &newq); + apc->priv_flags, apc->configured_mtu, + apc->bpf_prog, &newq);if (err) {NL_SET_ERR_MSG_FMT (extack,"failed to change ring params: %d" , err);
@@ -942,7 +943,7 @@ static int mana_set_priv_flags(struct net_device *ndev, u32 priv_flags) err =mana_alloc_qset (scratch, apc->num_queues, apc->rx_queue_size, apc->tx_queue_size, priv_flags, - apc->configured_mtu, &newq); + apc->configured_mtu, apc->bpf_prog, &newq);if (err) goto free_scratch;/* current qset and priv_flags untouched */
include/net/mana/mana.h +9 -7
@@ -590,7 +590,7 @@ struct mana_port_context {/* Indirection Table for RX & TX. The values are queue indexes */ u32 *indir_table; -u32 indir_table_sz; +u32 indir_table_sz;/* Indirection table containing RxObject Handles */ mana_handle_t *rxobj_table;
@@ -720,11 +720,12 @@ struct mana_qset {unsigned int tx_queue_size;u32 priv_flags; -/* MTU the RX buffers of this set were sized for. It feeds -* mana_get_rxbuf_cfg(), so it is part of the queue-set +/* MTU and XDP program the RX buffers of this set were sized for. +* Both feed mana_get_rxbuf_cfg(), so they are part of the queue-set * configuration and must be swapped atomically with the queues. */ int mtu; +struct bpf_prog *bpf_prog;/* Per-queue-set debugfs root ("EQs"). Owned by the qset: it is * recreated by mana_create_eq() for each new set and torn down
@@ -743,15 +744,16 @@ int mana_alloc_queues(struct net_device *ndev);int mana_attach (struct net_device *ndev);int mana_detach (struct net_device *ndev,bool from_close); -/* Pre-allocate + swap reconfiguration path. Allocation and teardown run -* against a scratch context so the live port context is never made to -* point at queues that are still being built or freed. +/* Pre-allocate + swap reconfiguration path (prototype). Allocation and +* teardown run against a scratch context so the live port context is only +* mutated inside mana_publish_qset(), with TX disabled. */ struct mana_port_context *mana_qset_scratch_alloc (struct mana_port_context *apc);void mana_qset_scratch_free (struct mana_port_context *scratch);int mana_alloc_qset (struct mana_port_context *scratch,unsigned int num_queues,unsigned int rx_queue_size,unsigned int tx_queue_size, -u32 priv_flags,int mtu,struct mana_qset *out); +u32 priv_flags,int mtu,struct bpf_prog *bpf_prog, +struct mana_qset *out);int mana_publish_qset (struct mana_port_context *apc,struct mana_qset *newq,struct mana_qset *out_old);void mana_publish_close_if_needed (struct mana_port_context *apc);
Signature · 1 line
2.43.0
PATCH v2 7/13 net: mana: do not bail out of mana_detach on dealloc failure
In reply to Long LiFrom: Dipayaan Roy <[email protected]>
mana_detach() sets port_is_up = false before calling mana_dealloc_queues(). If that call were to fail and return early, netif_device_detach() and mana_cleanup_port_context() are skipped, leaving the port in an inconsistent state where port_is_up is false but netif_device_present() still returns true.
With the ethtool, MTU and XDP paths converted to pre-allocate and swap, the callers that reach this code with from_close == false are the TX timeout reset handler and the suspend path. For the reset handler the inconsistent state is fatal: its mana_detach() would overwrite port_st_save with false, so the following mana_attach() skips queue allocation and leaves the port permanently dead. For suspend it leaves the port context allocated across the transition.
Remove the early return so that mana_detach() always completes its full teardown. mana_dealloc_queues() already performs best-effort cleanup regardless of internal errors, and in practice cannot fail here since port_is_up is already false, so continuing to netif_device_detach() and mana_cleanup_port_context() is safe and keeps the state consistent.
--- drivers/net/ethernet/microsoft/mana/mana_en.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/ethernet/microsoft/mana/mana_en.c +1 -3
@@ -4659,10 +4659,8 @@ int mana_detach(struct net_device *ndev, bool from_close)if (apc->port_st_save) { err =mana_dealloc_queues (ndev); -if (err) { +if (err)netdev_err (ndev,"%s failed to deallocate queues: %d\n" , __func__, err); -return err; - } }if (!from_close) {
Signature · 1 line
2.43.0
PATCH v2 8/13 net: mana: keep per-queue statistics in the port context
In reply to Long Listruct mana_rxq and struct mana_txq embed their statistics by value, and mana_get_stats64()/mana_get_ethtool_stats() read them through apc->rxqs[q] and apc->tx_qp[q]. The queues are destroyed and recreated by every reconfiguration - ethtool channel count, ring size and private flags, MTU changes and XDP attach - so the interface counters are reset each time and rx_bytes/tx_bytes can be observed going backwards:
rx_bytes before: 4475831638
rx_bytes after: 526629152
Move the statistics into arrays owned by the port context, sized to max_queues, allocated in mana_probe_port() and freed in mana_remove(). The queues keep pointers into those arrays, so a queue set can be freed without losing the counters it accumulated.
mana_get_stats64() now walks max_queues rather than num_queues, so counters accumulated on queues that a later reconfiguration removed are still reported and the totals stay monotonic. The ethtool per-queue statistics keep iterating num_queues, since mana_get_sset_count() sizes the string table the same way.
Note this is not specific to the queue-set swap: the detach/attach path reset the counters in exactly the same way. It matters more now only because reconfiguration is hitless and therefore likely to be done on a live link.
--- .../net/ethernet/microsoft/mana/mana_bpf.c | 4 +- drivers/net/ethernet/microsoft/mana/mana_en.c | 112 +++++++++++++++--- .../ethernet/microsoft/mana/mana_ethtool.c | 4 +- include/net/mana/mana.h | 27 ++++- 4 files changed, 122 insertions(+), 25 deletions(-)
drivers/net/ethernet/microsoft/mana/mana_bpf.c +2 -2
@@ -75,7 +75,7 @@ int mana_xdp_xmit(struct net_device *ndev, int n, struct xdp_frame **frames, count++; } - tx_stats = &apc->tx_qp[q_idx]->txq.stats; + tx_stats = apc->tx_qp[q_idx]->txq.stats;u64_stats_update_begin (&tx_stats->syncp); tx_stats->xdp_xmit += count;
@@ -102,7 +102,7 @@ u32 mana_run_xdp(struct net_device *ndev, struct mana_rxq *rxq, act =bpf_prog_run_xdp (prog, xdp); - rx_stats = &rxq->stats; + rx_stats = rxq->stats;switch (act) {case XDP_PASS :
drivers/net/ethernet/microsoft/mana/mana_en.c +95 -17
217 lines not on this page · raw message
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +2 -2
@@ -271,7 +271,7 @@ static void mana_get_ethtool_stats(struct net_device *ndev, data[i++] = *(u64 *)(phy_stats + mana_phy_stats[q].offset);for (q =0 ; q < num_queues; q++) { - rx_stats = &apc->rxqs[q]->stats; + rx_stats = &apc->rxq_stats[q]; do { start = u64_stats_fetch_begin(&rx_stats->syncp);
@@ -296,7 +296,7 @@ static void mana_get_ethtool_stats(struct net_device *ndev, }for (q =0 ; q < num_queues; q++) { - tx_stats = &apc->tx_qp[q]->txq.stats; + tx_stats = &apc->txq_stats[q]; do { start = u64_stats_fetch_begin(&tx_stats->syncp);
include/net/mana/mana.h +23 -4
@@ -102,7 +102,11 @@ struct mana_stats_rx {u64 pkt_len0_err;u64 coalesced_cqe[MANA_CQE_COAL_PKTS_8 -1 ];struct u64_stats_sync syncp; -}; +/* Kept in a per-port array indexed by queue, so give each entry its +* own cache line. Without it two queues polled on different CPUs +* would share one, and every packet would bounce it between them. +*/ +}____cacheline_aligned_in_smp ;struct mana_stats_tx {u64 packets;
@@ -117,7 +121,8 @@ struct mana_stats_tx {u64 csum_partial;u64 mana_map_err;struct u64_stats_sync syncp; -}; +/* Per-queue array entry, same cache line reasoning as the RX side. */ +}____cacheline_aligned_in_smp ;struct mana_txq {struct gdma_queue *gdma_sq;
@@ -153,7 +158,10 @@ struct mana_txq {*/ bool retiring; -struct mana_stats_tx stats; +/* Points into apc->txq_stats[]. Owned by the port context, not by +* this queue, so counters survive queue-set replacement. +*/ +struct mana_stats_tx *stats; };/* skb data and frags dma mappings */
@@ -415,7 +423,10 @@ struct mana_rxq {u32 buf_index; -struct mana_stats_rx stats; +/* Points into apc->rxq_stats[]. Owned by the port context, not by +* this queue, so counters survive queue-set replacement. +*/ +struct mana_stats_rx *stats;struct bpf_prog __rcu *bpf_prog;struct xdp_rxq_info xdp_rxq;
@@ -618,6 +629,14 @@ struct mana_port_context {unsigned int max_queues;unsigned int num_queues; +/* Per-queue statistics, max_queues entries each. Allocated once at +* probe and freed at remove, never on queue teardown, so counters +* are not reset by an ethtool/MTU/XDP reconfiguration. The queues +* point into these arrays. +*/ +struct mana_stats_rx *rxq_stats; +struct mana_stats_tx *txq_stats; +unsigned int rx_queue_size;unsigned int tx_queue_size;
Signature · 1 line
2.43.0
PATCH v2 9/13 net: mana: share the EQ pool across a queue-set swap
In reply to Long LiRaising the channel count fails with -ENOSPC once the queue-set swap is in use:
# ethtool -L ens1 combined 32 netlink error: No space left on device mana 7870:00:00.0: No free MSI vectors available mana 7870:00:00.0 ens1: mana_alloc_qset(num_queues=32) failed: -28
mana_alloc_qset() called mana_create_eq() to build a complete second set of EQs while the running set still held its own. EQs are bound to MSI-X vectors taken from gc->msi_bitmap, so peak demand was old_num_queues + new_num_queues and had to fit in gc->num_msix_usable. On a VM with 32 usable vectors and a driver that comes up at 16 queues, 16 -> 17 already needs 33 and fails, so the advertised maximum channel count is unreachable and a ring resize is impossible at 32 channels.
Fix it by making the EQ pool belong to the port rather than to a queue set. Both sets share it across a swap, so peak usage is max(old, new) instead of the sum:
- struct mana_qset no longer carries eqs or the EQ debugfs dir.
- mana_port_context gains num_eqs, a high-water mark of how many EQs have been created. mana_create_eq() now sizes the array to max_queues, so growing it later never reallocates - the CQs of a live queue set hold pointers taken from those slots.
- mana_grow_eqs() creates only the EQs a larger set needs. It is
grow-only: EQs above the current queue count are kept for a later increase. The ceiling is apc->max_queues, the same value ethtool reports as maximum combined, so those vectors are by definition obtainable.
- mana_alloc_qset() takes the live port context as well as the scratch one, since the pool it grows belongs to the former.
- Neither mana_alloc_qset()'s error path nor mana_free_qset() tears the pool down any more; it is released by mana_destroy_eq() on detach as before.
mana_destroy_eq() now iterates num_eqs rather than num_queues. Those were always equal before this patch, but with a grow-only pool they are not, and iterating num_queues would leak the EQs above it.
--- .../net/ethernet/microsoft/mana/mana_bpf.c | 2 +- drivers/net/ethernet/microsoft/mana/mana_en.c | 126 +++++++++++++++--- .../ethernet/microsoft/mana/mana_ethtool.c | 6 +- include/net/mana/mana.h | 22 +-- 4 files changed, 119 insertions(+), 37 deletions(-)
drivers/net/ethernet/microsoft/mana/mana_bpf.c +1 -1
@@ -220,7 +220,7 @@ static int mana_xdp_set(struct net_device *ndev, struct bpf_prog *prog,return -ENOMEM ; } - err =mana_alloc_qset (scratch, apc->num_queues, + err =mana_alloc_qset (apc, scratch, apc->num_queues, apc->rx_queue_size, apc->tx_queue_size, apc->priv_flags, apc->configured_mtu, prog, &newq);
drivers/net/ethernet/microsoft/mana/mana_en.c +104 -22
247 lines not on this page · raw message
drivers/net/ethernet/microsoft/mana/mana_ethtool.c +3 -3
@@ -736,7 +736,7 @@ static int mana_set_channels(struct net_device *ndev, goto clear_flag; } - err =mana_alloc_qset (scratch, new_count, apc->rx_queue_size, + err =mana_alloc_qset (apc, scratch, new_count, apc->rx_queue_size, apc->tx_queue_size, apc->priv_flags, apc->configured_mtu, apc->bpf_prog, &newq);if (err)
@@ -839,7 +839,7 @@ static int mana_set_ringparam(struct net_device *ndev, goto clear_flag; } - err =mana_alloc_qset (scratch, apc->num_queues, new_rx, new_tx, + err =mana_alloc_qset (apc, scratch, apc->num_queues, new_rx, new_tx, apc->priv_flags, apc->configured_mtu, apc->bpf_prog, &newq);if (err) {
@@ -941,7 +941,7 @@ static int mana_set_priv_flags(struct net_device *ndev, u32 priv_flags) goto clear_flag; } - err =mana_alloc_qset (scratch, apc->num_queues, apc->rx_queue_size, + err =mana_alloc_qset (apc, scratch, apc->num_queues, apc->rx_queue_size, apc->tx_queue_size, priv_flags, apc->configured_mtu, apc->bpf_prog, &newq);if (err)
include/net/mana/mana.h +11 -11
@@ -588,7 +588,13 @@ struct mana_port_context {u8 mac_addr[ETH_ALEN ]; +/* EQ pool. Owned by the port, not by a queue set: EQs are bound to +* MSI-X vectors, so a queue-set swap must not double-book them. +* The array is sized to max_queues and num_eqs is a high-water mark +* of how many have actually been created. +*/ struct mana_eq *eqs; +unsigned int num_eqs;struct dentry *mana_eqs_debugfs;enum TRI_STATE rss_state;
@@ -725,7 +731,6 @@ struct mana_port_context {* can never race in during reconfiguration. */ struct mana_qset { -struct mana_eq *eqs;struct mana_tx_qp **tx_qp;struct mana_rxq **rxqs;
@@ -745,13 +750,6 @@ struct mana_qset {*/ int mtu;struct bpf_prog *bpf_prog; - -/* Per-queue-set debugfs root ("EQs"). Owned by the qset: it is -* recreated by mana_create_eq() for each new set and torn down -* with that set, so it must travel with the qset rather than -* staying on apc. -*/ -struct dentry *mana_eqs_debugfs; };netdev_tx_t mana_start_xmit (struct sk_buff *skb,struct net_device *ndev);
@@ -763,13 +761,15 @@ int mana_alloc_queues(struct net_device *ndev);int mana_attach (struct net_device *ndev);int mana_detach (struct net_device *ndev,bool from_close); -/* Pre-allocate + swap reconfiguration path (prototype). Allocation and +/* Pre-allocate + swap reconfiguration path. Allocation and * teardown run against a scratch context so the live port context is only -* mutated inside mana_publish_qset(), with TX disabled. +* mutated inside mana_publish_qset(), with TX disabled. The EQs live in a +* port-owned pool that both queue sets share across a swap. */ struct mana_port_context *mana_qset_scratch_alloc (struct mana_port_context *apc);void mana_qset_scratch_free (struct mana_port_context *scratch); -int mana_alloc_qset (struct mana_port_context *scratch,unsigned int num_queues, +int mana_alloc_qset (struct mana_port_context *apc, +struct mana_port_context *scratch,unsigned int num_queues,unsigned int rx_queue_size,unsigned int tx_queue_size,u32 priv_flags,int mtu,struct bpf_prog *bpf_prog,struct mana_qset *out);
Signature · 1 line
2.43.0
Jakub Kicinski
maintainerQuoted 4 lines · On Mon, 10 Aug 2026 23:34:57 -0700 Long Li wrote:
MANA reconfigures a port by destroying its queues and building them again.
mana_detach()tears the whole queue set down,mana_attach()allocates a new one, and every path that changes a queue property does this: the ethtool channel, ring and private-flag setters, the MTU change and XDP attach.
This posting is broken. Please *wait 2 days*, practice sending patches to yourself (--suppress-cc=all) and the repost.