Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796151829; b=b8AR5B3GyGReMLK+usmm+7IL6j1NTxPx0veV6S+NXPcxbRlsmBaYd3cMzphuOR93QklG hKG7s4oZ51NBJu9ViBF6yYxasIp1rQ407ev/MLj+RlVqicMub7A0AUHoIMt9CpQEvYY8z pb45m6CsSEFVuo1Ixikwj1wfagZuCLTIOr9G6yQO5N++7b/yt9CXto2Bi8F08nwimcZq/ CL63/YYcNLyjVTycqZwLIekDw1g3sg7HEOb2ydMR+oUsony6n8rPydjUGLhLft4v5GkM6 PReACGbN0c1Zfc9obAzZoMF2nPaijgWjvwlFtXaxSW+m0Ypuq1ZsPkRyUW1HgcHjM6w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796151829; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:Received: Received:Received:Received:Received:From:To:Cc:Subject:Date: Message-Id:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-TM-AS-GCONF:X-Proofpoint-Reinject: X-Proofpoint-Spam-Info:X-Authority-Analysis: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-GUID: X-Proofpoint-ORIG-GUID:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=ibLPX9k/dmavdyLqSjrHqtbRO5uuXz91gUOkfcCs0BE=; b=q/EtHcC5kgNIRx5JtotC+GWEugLih24ttkhFE4DdpQfSXllr1WRSYrVgKNHyxeyWuonn pvLHDyFmiWDq39xE+j6DG+Sa6jKl/MYzbVyfCs3RBrroDJaKaV/D2zlFMrlvB2jIrof0O EENTb7rKxgpBns7Ht9Jp8S061X4BsqyOPecwWPlop3Yhamj9geFHoQErMmLI7d4L1e65W J1pDzLRujQsZC+m0SsPVtvlT5MYrcyE8rCZoANl1bk1xn85gzt6OKK9c3OB6ALMc+L7rd bd9ZoeR0bzoN6VG9oiqobXa0r6IvKutBIHZWoEGjt6r6vyOAMHQ3yrgvrglWqqbcJpg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=bGxR91vE; arc=none smtp.remote-ip=148.163.158.5 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D18BB606A322 for ; Tue, 1 Dec 2026 19:03:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D18BB606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=bGxR91vE Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B1F5tU62082369; Tue, 1 Dec 2026 19:02:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=ibLPX9k/dmavdyLqS jrHqtbRO5uuXz91gUOkfcCs0BE=; b=bGxR91vEhXg7Dm9kCg/1gL2cqkks89wIG sKMlNKf9hhky4shftLaJX8sgybIS1f/ctpC1CfTK/VMUOSmAfjtNYn0Eeay1Yc6N THgwbUylS9QgKni9GEyK8P5PKdFucvZAna//5jKauQfJRRTABdyFxF0Rpx255RF5 zZWHQgOVR1zt0JstpGQ7DLCm/BR7lUn7vUBLVuJw/A5s35XdGzMCsFQ67z/X2Pbn CK8omuxQgGSB8RT4OpYeR/ofC27jCkYurDdppcUeR98aLRDCLI3AsDCQk7SxcYxM 7EVQJWvtupcYhN4pogBl5vodP/GdlmO6VcQHyj+3nUsZG4EHszDnA== Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4j7mcke1pe-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 01 Dec 2026 19:02:56 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6B1IrZlG1772769; Tue, 1 Dec 2026 19:02:55 GMT Received: from smtprelay03.dal12v.mail.ibm.com ([172.16.1.5]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4j9v5w1vwb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 01 Dec 2026 19:02:55 +0000 (GMT) Received: from smtpav01.wdc07v.mail.ibm.com (smtpav01.wdc07v.mail.ibm.com [10.39.53.228]) by smtprelay03.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6B1J2s6Z7078532 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 1 Dec 2026 19:02:54 GMT Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1A89F58067; Tue, 1 Dec 2026 19:02:54 +0000 (GMT) Received: from smtpav01.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CFA875804B; Tue, 1 Dec 2026 19:02:50 +0000 (GMT) Received: from localhost.localdomain (unknown [9.67.162.22]) by smtpav01.wdc07v.mail.ibm.com (Postfix) with ESMTP; Tue, 1 Dec 2026 19:02:50 +0000 (GMT) From: Mingming Cao To: netdev@vger.kernel.org Cc: Mingming Cao , 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 Message-Id: <20261201190216.62407-6-mmc@linux.ibm.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20261201190216.62407-1-mmc@linux.ibm.com> References: <20261201190216.62407-1-mmc@linux.ibm.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAxMDA3NCBTYWx0ZWRfXzv31nrsjTN7i et/2tWkixysbqJ8YK+UVbr+y4ugBQ3WaWgwTdmo1HqrC7rVJl8vciqY1lk240UwuhK/qMM2A3oj u5fF3jyhTmCFgWw+/LEz7wKHBLJnx/Y= X-Authority-Analysis: v=2.4 cv=MtfHeGae c=1 sm=1 tr=0 ts=6b0f19e1 cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=Y2IxJ9c9Rs8Kov3niI8_:22 a=VnNF1IyMAAAA:8 a=coVNIdNy6CbFps0foocA:9 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAxMDA3NCBTYWx0ZWRfXzb4oOb5BBjXW RCs5I7uFtEA0KAqYGDrjuq06+AVp5iHJCkL8Tl6mYPNRshpxIPI/CLgwzjhn+qfnq+KR1g68NN6 FPvJL0xfZm8Qy5YmAyYq319N9H9PtCJKkTB2eZNk3HpLmSBo7bgR68ohsEPkQf8qmUESgDWDmC9 CYG8/lOGZ3Mmzs07jdXQa9pB44qFS6wKRf9pyS9TTMYmKBnzIIBM3ZLKnq4pl5JCBdsEDfSejVr zfMKU8GPR1EpxKNEnaPVWH5yJVEU47xDugWMcid1jBctSYRDrajCYPqqSTw2ZNku9LoXWPDkab8 GaM1ibq+aedwCSpm1EvvUStIhimHn0QTtrqjRvaMxuoVIeNvJtVT2X6a5ZzrsjAgVfslwRPLp/P Fr+OOSswNxbOsra0G6srZg5cUOKCNFvdXuwM1IU1n7aqVLfpdsWYJbwQUrQY1jQ4vJz3Ok6kRT3 rKwnKfmCRrSjzUgEPVw== X-Proofpoint-GUID: 1qrQtj3MHCebUDJ4UgjAVnYaoSfiWx50 X-Proofpoint-ORIG-GUID: Z_y53JubkUoYxPXKqTlIXnHXX4IwPTB8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-01_03,2026-12-01_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 bulkscore=0 malwarescore=0 spamscore=0 phishscore=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 suspectscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612010074 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 --- 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 #include +#include #include #include #include @@ -21,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -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)