From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by smtp.lore.kernel.org (Postfix) with ESMTP id E19DCCD342F for ; Wed, 6 May 2026 02:06:09 +0000 (UTC) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 56C5440A71; Wed, 6 May 2026 04:05:47 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 4507340679; Wed, 6 May 2026 04:05:45 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1202) id 72D9320B716B; Tue, 5 May 2026 19:05:42 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 72D9320B716B From: Long Li To: dev@dpdk.org, Wei Hu , Stephen Hemminger Cc: Long Li , stable@dpdk.org Subject: [PATCH v2 5/7] net/netvsc: retry when no matching MAC found in net directory Date: Tue, 5 May 2026 19:05:26 -0700 Message-ID: <20260506020529.281654-5-longli@microsoft.com> X-Mailer: git-send-email 2.43.7 In-Reply-To: <20260506020529.281654-1-longli@microsoft.com> References: <20260506020529.281654-1-longli@microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On multi-NIC Azure VMs, a single MANA PCI device (7870:00:00.0) hosts multiple VF interfaces. After PCI rescan, these interfaces register at different times — the management NIC's VF appears first, followed by the test NIC's VF. Previously, when netvsc_hotplug_retry scanned the net/ directory and found interfaces with non-matching MACs, it would exit the readdir loop and free the hotadd context, permanently giving up. The matching VF interface had not appeared yet. Now, when the readdir loop ends without finding a matching MAC (dir is NULL after loop), schedule another retry instead of giving up. This uses a separate mac_retry counter (limit 120, ~2 minutes) so the main retry loop remains unlimited. Fixes: a2a23a794b3a ("net/netvsc: support VF device hot add/remove") Cc: stable@dpdk.org Signed-off-by: Long Li --- v2: - Fixed commit message: "limit 30, ~30 seconds" corrected to "limit 120, ~2 minutes" to match NETVSC_MAX_MAC_RETRY=120 - Changed mac_retry log level from NOTICE to DEBUG - Changed implicit pointer checks to explicit NULL comparisons (if (di) -> if (di != NULL), if (!dir) -> if (dir == NULL)) drivers/net/netvsc/hn_ethdev.c | 36 +++++++++++++++++++++++++++++++++- drivers/net/netvsc/hn_var.h | 1 + 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/drivers/net/netvsc/hn_ethdev.c b/drivers/net/netvsc/hn_ethdev.c index d1c12ca9d5..08465489f2 100644 --- a/drivers/net/netvsc/hn_ethdev.c +++ b/drivers/net/netvsc/hn_ethdev.c @@ -92,6 +92,12 @@ struct netvsc_mp_param { /* Retry interval for hot-add VF device (microseconds) */ #define NETVSC_HOTADD_RETRY_INTERVAL 1000000 +/* Max retries when net/ directory exists but no matching MAC found. + * On multi-NIC PCI devices, a second VF may register later. + * 120 retries = ~2 minutes. + */ +#define NETVSC_MAX_MAC_RETRY 120 + struct hn_xstats_name_off { char name[RTE_ETH_XSTATS_NAME_SIZE]; unsigned int offset; @@ -767,8 +773,36 @@ static void netvsc_hotplug_retry(void *args) RTE_ETHER_ADDR_BYTES(dev->data->mac_addrs)); } + /* If we opened the net directory but didn't find a matching MAC, + * the VF interface may not have appeared yet (e.g. on a multi-NIC + * PCI device, the second VF registers later). Retry. + */ + if (di != NULL) { + closedir(di); + di = NULL; + if (dir == NULL) { + /* readdir returned NULL — loop ended without match */ + hot_ctx->mac_retry++; + if (hot_ctx->mac_retry < NETVSC_MAX_MAC_RETRY) { + PMD_DRV_LOG(DEBUG, + "%s: no matching MAC found in %s, " + "retrying in 1 second (mac_retry %d/%d)", + __func__, buf, + hot_ctx->mac_retry, + NETVSC_MAX_MAC_RETRY); + rte_eal_alarm_set(NETVSC_HOTADD_RETRY_INTERVAL, + netvsc_hotplug_retry, + hot_ctx); + return; + } + PMD_DRV_LOG(NOTICE, + "%s: no matching MAC found after %d retries, giving up", + __func__, hot_ctx->mac_retry); + } + } + free_hotadd_ctx: - if (di) + if (di != NULL) closedir(di); PMD_DRV_LOG(NOTICE, "%s: retry loop exiting for device %s (retry %d)", diff --git a/drivers/net/netvsc/hn_var.h b/drivers/net/netvsc/hn_var.h index ef55dee28e..574b909c82 100644 --- a/drivers/net/netvsc/hn_var.h +++ b/drivers/net/netvsc/hn_var.h @@ -127,6 +127,7 @@ struct hv_hotadd_context { struct hn_data *hv; struct rte_devargs da; int eal_hot_plug_retry; + int mac_retry; }; struct hn_data { -- 2.43.0