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, willemb@google.com
Subject: [PATCH net-next v9 05/13] ibmveth: Register subordinate RX queues
Date: Tue, 1 Dec 2026 11:02:08 -0800 [thread overview]
Message-ID: <20261201190216.62407-6-mmc@linux.ibm.com> (raw)
In-Reply-To: <20261201190216.62407-1-mmc@linux.ibm.com>
This is preparation for multi-queue (MQ) RX; nothing sets multi_queue
yet, so single-queue behavior does not change.
PHYP delivers frames only to registered RX queues. Queue 0 is
registered with H_REGISTER_LOGICAL_LAN; each further (subordinate)
queue is registered with H_REG_LOGICAL_LAN_QUEUE, which returns its
handle and the hardware number of its interrupt.
In MQ mode, open() registers queues 1..N-1 after queue 0 and maps
each queue's interrupt. If that fails, open() disposes of the
mappings and frees every queue with one H_FREE_LOGICAL_LAN. There is
no fallback to one queue, since PowerVM blocks Live Partition
Migration to a host without MQ support.
PHYP fails H_FREE_LOGICAL_LAN only with H_PARAMETER, when no LAN is
registered, and the RX memory is then freed. Any other failure may
leave the LAN registered. MQ mode then leaks the RX memory, still
mapped, so whatever PHYP still writes lands in memory nothing else
uses. Single-queue mode frees it, as close() always has: CMO
(Cooperative Memory Overcommitment) partitions are single-queue and
must not keep memory mapped at remove.
Signed-off-by: Mingming Cao <mmc@linux.ibm.com>
---
drivers/net/ethernet/ibm/ibmveth.c | 163 +++++++++++++++++++++++++++--
drivers/net/ethernet/ibm/ibmveth.h | 32 ++++++
2 files changed, 188 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/ibm/ibmveth.c b/drivers/net/ethernet/ibm/ibmveth.c
index 236992ded33a..5783c0ce34a3 100644
--- a/drivers/net/ethernet/ibm/ibmveth.c
+++ b/drivers/net/ethernet/ibm/ibmveth.c
@@ -13,6 +13,7 @@
#include <linux/module.h>
#include <linux/types.h>
+#include <linux/delay.h>
#include <linux/errno.h>
#include <linux/dma-mapping.h>
#include <linux/kernel.h>
@@ -21,6 +22,7 @@
#include <linux/skbuff.h>
#include <linux/init.h>
#include <linux/interrupt.h>
+#include <linux/irqdomain.h>
#include <linux/mm.h>
#include <linux/pm.h>
#include <linux/ethtool.h>
@@ -449,6 +451,28 @@ ibmveth_enable_irq(struct ibmveth_adapter *adapter, int queue_index)
return ibmveth_toggle_irq(adapter, queue_index, true);
}
+/**
+ * ibmveth_dispose_subordinate_irq_mappings - Drop subordinate virq mappings
+ * @adapter: ibmveth adapter structure
+ *
+ * Subordinate queues get mappings from irq_create_mapping() during PHYP
+ * registration; queue 0 uses netdev->irq and is left alone. Call after
+ * free_irq(), or after a registration failure that may have mapped only
+ * some of the queues.
+ */
+static void
+ibmveth_dispose_subordinate_irq_mappings(struct ibmveth_adapter *adapter)
+{
+ int i;
+
+ for (i = 1; i < adapter->num_rx_queues; i++) {
+ if (adapter->queue_irq[i]) {
+ irq_dispose_mapping(adapter->queue_irq[i]);
+ adapter->queue_irq[i] = 0;
+ }
+ }
+}
+
/**
* ibmveth_setup_rx_interrupts - Register IRQs and enable NAPI
* @adapter: ibmveth adapter structure
@@ -493,7 +517,7 @@ err_free_irqs:
*
* Mask, napi_disable, wait for the poll tail, remask, then free_irq.
* napi_disable() does not wait past napi_complete_done(), which can
- * unmask.
+ * unmask. Then dispose of the subordinate queues' IRQ mappings.
*/
static void
ibmveth_cleanup_rx_interrupts(struct ibmveth_adapter *adapter)
@@ -517,6 +541,8 @@ ibmveth_cleanup_rx_interrupts(struct ibmveth_adapter *adapter)
for (i = 0; i < adapter->num_rx_queues; i++)
free_irq(adapter->queue_irq[i], &adapter->napi[i]);
+
+ ibmveth_dispose_subordinate_irq_mappings(adapter);
}
/**
@@ -783,6 +809,10 @@ static void ibmveth_update_rx_no_buffer(struct ibmveth_adapter *adapter)
{
__be64 *p;
+ /* NULL after ibmveth_leak_rx_memory(). */
+ if (!adapter->buffer_list_addr[0])
+ return;
+
p = adapter->buffer_list_addr[0] + 4096 - 8;
adapter->rx_no_buffer = be64_to_cpup(p);
}
@@ -1228,12 +1258,49 @@ retry:
return rc;
}
+/**
+ * ibmveth_leak_rx_memory - Keep the RX memory PHYP may still own
+ * @adapter: ibmveth adapter structure
+ *
+ * Forgets each queue's ring, buffer list and pool buffers and the filter
+ * list without unmapping or freeing them, so the free paths skip them
+ * and their TCEs are not reused by later mappings.
+ */
+static void ibmveth_leak_rx_memory(struct ibmveth_adapter *adapter)
+{
+ struct ibmveth_buff_pool *pool;
+ int i, j;
+
+ netdev_err(adapter->netdev, "leaking RX memory of %d queues\n",
+ adapter->num_rx_queues);
+
+ for (i = 0; i < adapter->num_rx_queues; i++) {
+ adapter->rx_queue[i].queue_addr = NULL;
+ adapter->buffer_list_addr[i] = NULL;
+ adapter->buffer_list_dma[i] = 0;
+ for (j = 0; j < IBMVETH_NUM_BUFF_POOLS; j++) {
+ pool = &adapter->rx_buff_pool[i][j];
+ pool->free_map = NULL;
+ pool->dma_addr = NULL;
+ pool->skbuff = NULL;
+ }
+ }
+ adapter->filter_list_addr = NULL;
+ adapter->filter_list_dma = 0;
+}
+
/**
* ibmveth_free_all_queues - Free all RX queues at once
* @adapter: ibmveth adapter structure
*
- * Issues one H_FREE_LOGICAL_LAN. A failure is logged; the caller still
- * frees the RX memory, as close() always has.
+ * Issues one H_FREE_LOGICAL_LAN, which frees the logical LAN and every
+ * RX queue registered under it. Past busy, PHYP fails it only with
+ * H_PARAMETER, when no LAN is registered, and the caller then frees the
+ * RX memory. On any other failure in multi-queue mode the RX memory is
+ * leaked instead. Single-queue mode frees it, as close() always has:
+ * CMO partitions are single-queue and must not keep it mapped at
+ * remove, and the unmap clears the adapter's TCEs before the pages are
+ * freed.
*/
static void ibmveth_free_all_queues(struct ibmveth_adapter *adapter)
{
@@ -1243,6 +1310,68 @@ static void ibmveth_free_all_queues(struct ibmveth_adapter *adapter)
if (lpar_rc != H_SUCCESS)
netdev_err(adapter->netdev,
"h_free_logical_lan failed: %ld\n", lpar_rc);
+
+ if (lpar_rc != H_SUCCESS && lpar_rc != H_PARAMETER &&
+ adapter->multi_queue)
+ ibmveth_leak_rx_memory(adapter);
+}
+
+/**
+ * ibmveth_register_rx_queue - Register one subordinate RX queue
+ * @adapter: ibmveth adapter structure
+ * @queue_idx: RX queue index (1..N-1)
+ *
+ * Registers the queue with H_REG_LOGICAL_LAN_QUEUE and maps its interrupt.
+ * Only called in multi-queue mode, which probe enables only on firmware
+ * with MQ support; PowerVM blocks Live Partition Migration to a host
+ * without it. On failure the caller frees every queue with
+ * H_FREE_LOGICAL_LAN.
+ *
+ * Return: 0 on success, -ENOMEM if the interrupt cannot be mapped,
+ * -EIO if H_REG_LOGICAL_LAN_QUEUE fails
+ */
+static int ibmveth_register_rx_queue(struct ibmveth_adapter *adapter,
+ int queue_idx)
+{
+ struct ibmveth_rx_q *rxq = &adapter->rx_queue[queue_idx];
+ unsigned long bl = adapter->buffer_list_dma[queue_idx];
+ unsigned long ua = adapter->vdev->unit_address;
+ union ibmveth_buf_desc rxq_desc;
+ unsigned long handle, hwirq;
+ unsigned int virq;
+ long lpar_rc;
+
+ rxq_desc.fields.flags_len = IBMVETH_BUF_VALID | rxq->queue_len;
+ rxq_desc.fields.address = rxq->queue_dma;
+
+ do {
+ lpar_rc = h_register_logical_lan_queue(ua, bl, rxq_desc.desc,
+ &handle, &hwirq);
+ if (H_IS_LONG_BUSY(lpar_rc)) {
+ msleep(get_longbusy_msecs(lpar_rc));
+ lpar_rc = H_BUSY;
+ } else if (lpar_rc == H_BUSY) {
+ cond_resched();
+ }
+ } while (lpar_rc == H_BUSY);
+ if (lpar_rc != H_SUCCESS) {
+ netdev_err(adapter->netdev,
+ "h_register_logical_lan_queue failed for queue %d: %ld\n",
+ queue_idx, lpar_rc);
+ return -EIO;
+ }
+
+ virq = irq_create_mapping(NULL, hwirq);
+ if (!virq) {
+ netdev_err(adapter->netdev,
+ "failed to map IRQ for queue %d (hwirq=%lu)\n",
+ queue_idx, hwirq);
+ return -ENOMEM;
+ }
+
+ adapter->queue_handle[queue_idx] = handle;
+ adapter->queue_irq[queue_idx] = virq;
+ return 0;
}
/**
@@ -1250,9 +1379,11 @@ static void ibmveth_free_all_queues(struct ibmveth_adapter *adapter)
* @adapter: ibmveth adapter structure
* @mac_address: MAC address for device registration
*
- * Registers queue 0 with H_REGISTER_LOGICAL_LAN.
+ * Registers queue 0 via ibmveth_register_logical_lan(), then subordinate
+ * queues 1..N-1 when multi-queue mode is enabled.
*
- * Return: 0 on success, -ENONET if queue 0 registration fails
+ * Return: 0 on success, -ENONET if queue 0 registration fails,
+ * or the error from ibmveth_register_rx_queue()
*/
static int
ibmveth_register_rx_queues(struct ibmveth_adapter *adapter, u64 mac_address)
@@ -1260,6 +1391,8 @@ ibmveth_register_rx_queues(struct ibmveth_adapter *adapter, u64 mac_address)
struct net_device *netdev = adapter->netdev;
union ibmveth_buf_desc rxq_desc;
long lpar_rc;
+ unsigned int num;
+ int i, rc;
rxq_desc.fields.flags_len = IBMVETH_BUF_VALID |
adapter->rx_queue[0].queue_len;
@@ -1280,7 +1413,22 @@ ibmveth_register_rx_queues(struct ibmveth_adapter *adapter, u64 mac_address)
return -ENONET;
}
+ num = adapter->num_rx_queues;
+ if (num == 1 || !adapter->multi_queue)
+ return 0;
+
+ for (i = 1; i < num; i++) {
+ rc = ibmveth_register_rx_queue(adapter, i);
+ if (rc)
+ goto err_unregister;
+ }
+
return 0;
+
+err_unregister:
+ ibmveth_dispose_subordinate_irq_mappings(adapter);
+ ibmveth_free_all_queues(adapter);
+ return rc;
}
static int ibmveth_open(struct net_device *netdev)
@@ -1332,7 +1480,7 @@ static int ibmveth_open(struct net_device *netdev)
*/
rc = ibmveth_setup_rx_interrupts(adapter);
if (rc)
- goto out_free_all_queues;
+ goto out_unregister_queues;
netdev_dbg(netdev, "initial replenish cycle\n");
ibmveth_schedule_rx_queue(adapter, 0);
@@ -1349,7 +1497,8 @@ static int ibmveth_open(struct net_device *netdev)
return 0;
-out_free_all_queues:
+out_unregister_queues:
+ ibmveth_dispose_subordinate_irq_mappings(adapter);
ibmveth_free_all_queues(adapter);
out_free_buffer_pools:
ibmveth_free_buffer_pools(adapter);
diff --git a/drivers/net/ethernet/ibm/ibmveth.h b/drivers/net/ethernet/ibm/ibmveth.h
index 7ac3372afc0f..34f57ad07a2f 100644
--- a/drivers/net/ethernet/ibm/ibmveth.h
+++ b/drivers/net/ethernet/ibm/ibmveth.h
@@ -68,6 +68,38 @@ static inline long h_add_logical_lan_buffers(unsigned long unit_address,
desc5, desc6, desc7, desc8);
}
+/**
+ * h_register_logical_lan_queue - Register a subordinate receive queue
+ * @unit_address: Device unit address
+ * @buffer_list: DMA address of 4KB page for tracking registered buffers
+ * @rec_queue: Buffer descriptor of receive queue
+ * @queue_handle: Output queue handle on success
+ * @irq: Output hypervisor IRQ number on success
+ *
+ * Return: hypervisor return code; H_BUSY and H_LONG_BUSY_* mean retry
+ */
+static inline long
+h_register_logical_lan_queue(unsigned long unit_address,
+ unsigned long buffer_list,
+ unsigned long rec_queue,
+ unsigned long *queue_handle,
+ unsigned long *irq)
+{
+ unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
+ long rc;
+
+ rc = plpar_hcall(H_REG_LOGICAL_LAN_QUEUE,
+ retbuf, unit_address,
+ buffer_list, rec_queue);
+
+ if (rc == H_SUCCESS) {
+ *queue_handle = retbuf[0];
+ *irq = retbuf[1];
+ }
+
+ return rc;
+}
+
/**
* h_register_logical_lan_with_handle - Register primary queue and get handle
* @unit_address: Device unit address
--
2.50.1 (Apple Git-155)
next prev parent reply other threads:[~2026-12-01 19:03 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 19:02 [PATCH net-next v9 00/13] ibmveth: Add multi-queue RX support Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 01/13] ibmveth: Keep a buffer pool enabled after its allocation fails Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 02/13] ibmveth: Keep TX statistics per queue Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 03/13] powerpc/pseries: Add hcall numbers for multi-queue virtual ethernet Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 04/13] ibmveth: Add RX queue handles Mingming Cao
2026-12-01 19:02 ` Mingming Cao [this message]
2026-12-01 19:02 ` [PATCH net-next v9 06/13] ibmveth: Add subordinate RX queue interrupt control Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 07/13] ibmveth: Add the MQ RX buffer submit hypercall Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 08/13] ibmveth: Start every RX queue on open and resume Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 09/13] ibmveth: Keep RX statistics per queue Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 10/13] ibmveth: Keep rx_no_buffer across ifdown/up Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 11/13] ibmveth: Report per-queue statistics through netdev_stat_ops Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 12/13] ibmveth: Enable multi-queue RX Mingming Cao
2026-12-01 19:02 ` [PATCH net-next v9 13/13] ibmveth: Allow changing the RX queue count 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=20261201190216.62407-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 \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox