From: Mingming Cao <mmc@linux.ibm.com>
To: netdev@vger.kernel.org
Cc: Mingming Cao <mmc@linux.ibm.com>,
maddy@linux.ibm.com, mpe@ellerman.id.au, npiggin@gmail.com,
chleroy@kernel.org, ritesh.list@gmail.com, sshegde@linux.ibm.com,
nnac123@linux.ibm.com, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
pabeni@redhat.com, linuxppc-dev@lists.ozlabs.org,
horms@kernel.org, davemarq@linux.ibm.com, haren@linux.ibm.com,
ricklind@linux.ibm.com, bjking1@linux.ibm.com,
shaik.abdulla1@ibm.com
Subject: [PATCH net-next 5/8] ibmveth: Refactor TX resource allocation in open/close paths
Date: Wed, 18 Nov 2026 16:07:08 -0800 [thread overview]
Message-ID: <20261119000711.18093-6-mmc@linux.ibm.com> (raw)
In-Reply-To: <20261119000711.18093-1-mmc@linux.ibm.com>
Move TX LTB allocation and free out of open() and close() into
ibmveth_alloc_tx_resources() and ibmveth_free_tx_resources(), like
the RX helpers.
open() now allocates the TX LTBs last, after RX is running. It stops
TX with netif_tx_disable() first: on a first open the queues are not
DRV_XOFF, so generic XDP_TX could transmit before the LTBs exist. It
starts TX under netif_tx_lock_bh() once they do. A TX allocation
failure unwinds RX the way close() does.
Signed-off-by: Mingming Cao <mmc@linux.ibm.com>
---
drivers/net/ethernet/ibm/ibmveth.c | 82 +++++++++++++++++++++++-------
1 file changed, 65 insertions(+), 17 deletions(-)
diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c
index ab5df1794004..8f32f75f2d7f 100644
--- a/drivers/net/ethernet/ibm/ibmveth.c
+++ b/drivers/net/ethernet/ibm/ibmveth.c
@@ -1046,6 +1046,48 @@ static int ibmveth_allocate_tx_ltb(struct ibmveth_adapter *adapter, int idx)
return 0;
}
+/**
+ * ibmveth_alloc_tx_resources - Allocate TX LTBs for real_num_tx_queues
+ * @adapter: ibmveth adapter structure
+ *
+ * Allocate a TX long-term buffer for each live TX queue. On a
+ * partial failure this helper already frees what it allocated.
+ *
+ * Return: 0 on success, -ENOMEM on failure
+ */
+static int ibmveth_alloc_tx_resources(struct ibmveth_adapter *adapter)
+{
+ struct net_device *netdev = adapter->netdev;
+ int i;
+
+ for (i = 0; i < netdev->real_num_tx_queues; i++) {
+ if (ibmveth_allocate_tx_ltb(adapter, i))
+ goto err_free_ltbs;
+ }
+
+ return 0;
+
+err_free_ltbs:
+ while (--i >= 0)
+ ibmveth_free_tx_ltb(adapter, i);
+ return -ENOMEM;
+}
+
+/**
+ * ibmveth_free_tx_resources - Free TX LTBs for real_num_tx_queues
+ * @adapter: ibmveth adapter structure
+ *
+ * Free the TX long-term buffers for each live TX queue.
+ */
+static void ibmveth_free_tx_resources(struct ibmveth_adapter *adapter)
+{
+ struct net_device *netdev = adapter->netdev;
+ int i;
+
+ for (i = 0; i < netdev->real_num_tx_queues; i++)
+ ibmveth_free_tx_ltb(adapter, i);
+}
+
static int ibmveth_register_logical_lan(struct ibmveth_adapter *adapter,
union ibmveth_buf_desc rxq_desc, u64 mac_address)
{
@@ -1085,6 +1127,11 @@ static int ibmveth_open(struct net_device *netdev)
netdev_dbg(netdev, "open starting\n");
+ /* Stop TX first. First-open queues are not DRV_XOFF, so generic
+ * XDP_TX could run once NAPI is up and before the LTBs exist.
+ */
+ netif_tx_disable(netdev);
+
for (i = 0; i < IBMVETH_NUM_BUFF_POOLS; i++)
rxq_entries += adapter->rx_buff_pool[0][i].size;
@@ -1096,12 +1143,6 @@ static int ibmveth_open(struct net_device *netdev)
if (rc)
goto out_free_filter_list;
- rc = -ENOMEM;
- for (i = 0; i < netdev->real_num_tx_queues; i++) {
- if (ibmveth_allocate_tx_ltb(adapter, i))
- goto out_free_tx_ltb;
- }
-
mac_address = ether_addr_to_u64(netdev->dev_addr);
rxq_desc.fields.flags_len = IBMVETH_BUF_VALID |
@@ -1123,12 +1164,12 @@ static int ibmveth_open(struct net_device *netdev)
rxq_desc.desc,
mac_address);
rc = -ENONET;
- goto out_free_tx_ltb;
+ goto out_free_queue_mem;
}
rc = ibmveth_alloc_buffer_pools(adapter);
if (rc)
- goto out_free_buffer_pools;
+ goto out_unregister_lan;
/* Enables NAPI, so everything ibmveth_poll() touches must exist:
* netpoll during the direct close()/open() pairs, or a direct
@@ -1136,26 +1177,35 @@ static int ibmveth_open(struct net_device *netdev)
*/
rc = ibmveth_setup_rx_interrupts(adapter);
if (rc)
- goto out_free_buffer_pools;
+ goto out_unregister_lan;
netdev_dbg(netdev, "initial replenish cycle\n");
ibmveth_schedule_rx_queue(adapter, 0);
+ rc = ibmveth_alloc_tx_resources(adapter);
+ if (rc)
+ goto out_cleanup_rx_interrupts;
+
+ /* Start under the xmit lock so a sender that tests DRV_XOFF
+ * there sees the LTBs this open just published.
+ */
+ netif_tx_lock_bh(netdev);
netif_tx_start_all_queues(netdev);
+ netif_tx_unlock_bh(netdev);
adapter->opened = true;
netdev_dbg(netdev, "open complete\n");
return 0;
-out_free_buffer_pools:
+out_cleanup_rx_interrupts:
+ ibmveth_cleanup_rx_interrupts(adapter);
+out_unregister_lan:
do {
lpar_rc = h_free_logical_lan(adapter->vdev->unit_address);
} while (H_IS_LONG_BUSY(lpar_rc) || (lpar_rc == H_BUSY));
ibmveth_free_buffer_pools(adapter);
-out_free_tx_ltb:
- for (i = netdev->real_num_tx_queues - 1; i >= 0; i--)
- ibmveth_free_tx_ltb(adapter, i);
+out_free_queue_mem:
ibmveth_cleanup_rx_resources(adapter);
out_free_filter_list:
ibmveth_free_filter_list(adapter);
@@ -1167,7 +1217,6 @@ static int ibmveth_close(struct net_device *netdev)
{
struct ibmveth_adapter *adapter = netdev_priv(netdev);
long lpar_rc;
- int i;
/* change_mtu, pool sysfs, set_csum and set_tso call close() and
* open() directly. If that open() fails, IFF_UP stays set and
@@ -1192,13 +1241,12 @@ static int ibmveth_close(struct net_device *netdev)
lpar_rc);
}
ibmveth_update_rx_no_buffer(adapter);
+ /* netif_tx_disable() above keeps xmit off the TX LTBs. */
+ ibmveth_free_tx_resources(adapter);
ibmveth_free_buffer_pools(adapter);
ibmveth_cleanup_rx_resources(adapter);
ibmveth_free_filter_list(adapter);
- for (i = 0; i < netdev->real_num_tx_queues; i++)
- ibmveth_free_tx_ltb(adapter, i);
-
netdev_dbg(netdev, "close complete\n");
return 0;
--
2.50.1 (Apple Git-155)
next prev parent reply other threads:[~2026-11-19 0:07 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 0:07 [PATCH net-next 0/8] ibmveth: prepare the RX path for multi-queue Mingming Cao
2026-11-19 0:07 ` [PATCH net-next 1/8] ibmveth: Prepare MQ RX adapter data structures Mingming Cao
2026-11-19 0:07 ` [PATCH net-next 2/8] ibmveth: Refactor RX resource allocation for MQ RX bring-up Mingming Cao
2026-11-19 0:07 ` [PATCH net-next 3/8] ibmveth: Refactor buffer pool management for per-queue MQ RX Mingming Cao
2026-11-19 0:07 ` [PATCH net-next 4/8] ibmveth: Refactor RX interrupt control for MQ RX queues Mingming Cao
2026-11-19 0:07 ` Mingming Cao [this message]
2026-11-19 0:07 ` [PATCH net-next 6/8] ibmveth: Add RX queue register helpers for MQ Mingming Cao
2026-11-19 0:07 ` [PATCH net-next 7/8] ibmveth: Pass the RX queue index through replenish and poll Mingming Cao
2026-11-19 0:07 ` [PATCH net-next 8/8] ibmveth: Split RX poll into per-slot helpers for MQ Mingming Cao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261119000711.18093-6-mmc@linux.ibm.com \
--to=mmc@linux.ibm.com \
--cc=andrew+netdev@lunn.ch \
--cc=bjking1@linux.ibm.com \
--cc=chleroy@kernel.org \
--cc=davem@davemloft.net \
--cc=davemarq@linux.ibm.com \
--cc=edumazet@kernel.org \
--cc=haren@linux.ibm.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=mpe@ellerman.id.au \
--cc=netdev@vger.kernel.org \
--cc=nnac123@linux.ibm.com \
--cc=npiggin@gmail.com \
--cc=pabeni@redhat.com \
--cc=ricklind@linux.ibm.com \
--cc=ritesh.list@gmail.com \
--cc=shaik.abdulla1@ibm.com \
--cc=sshegde@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.