Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 343D236A37E; Sat, 12 Sep 2026 09:24:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789205084; cv=none; b=R1sfh7prIvXMFIKjyuSVVVJeIcBqhnNHYhHU257CLrgSk7Y0FnnJBE0GxiQDloTQ/GdASXGKciEwgw0+TyadFMwbrxs87LKlt+YA7o1SGZtxD4TaT9AWdzOns4MeLAa6EINraV7YZ/cVduKoJgxFMfG7aNOtWi9DOMSORbWubz4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789205084; c=relaxed/simple; bh=CmImO1Rj7Z2zti+d3DKwRVexq31HXvgDwmR0GcCLjKc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cz+K4l1q8YL2Bffjc5fvejCc5XhzDpnHBlvavfNEQQ0LCYQ9soThlZ43WXcAwHXiIzLaku2GRopF+DkF6nnh1NXoYi1wcvg6A4OKBfwyVm+G7eAqNtd7/M8ZguC4NANF51h6jYO8R5Ih1hrOBLJXz/w4zVg87xulLHRnGdhcjL8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=wbROe4yV; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="wbROe4yV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37A2F1F000FF; Sat, 12 Sep 2026 09:24:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789205083; bh=NyNR400NFhqIOiv5sROAwv2I8gexOyWtcUWBiX4nq/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=wbROe4yVqa9uxRLz8vlA730ZG7JEsuKlbZ5TNrh0Q0ce+lTTuFuRcpi1ZMy2cPq3A dB3YLiKvp+QyrVKPp69VVrjxb/dcCXVpHamRB/GyuLSrxY7fI9gDFjjRCvnGAfCmcl CDM492/Obkbl6GJr/DfivxxbzGF1QIr0rE70GP4c= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Wei Fang , Jakub Kicinski , Sasha Levin Subject: [PATCH 7.2 1738/1815] net: enetc: convert ndo_set_rx_mode() to ndo_set_rx_mode_async() Date: Sat, 12 Sep 2026 08:58:08 +0200 Message-ID: <20260912065729.782502640@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260912065648.999753832@linuxfoundation.org> References: <20260912065648.999753832@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.2-stable review patch. If anyone has any objections, please let me know. ------------------ From: Wei Fang [ Upstream commit debf0c7a34fab2c4c47fc257a97a145543b6d3aa ] The current ndo_set_rx_mode() is called under netif_addr_lock spinlock with BHs disabled, which prevents drivers from sleeping. To work around this limitation, the enetc driver uses a dedicated workqueue to defer MAC address list updates to a sleepable context. Since commit 3554b4345d85 ("net: introduce ndo_set_rx_mode_async and netdev_rx_mode_work") introduced the ndo_set_rx_mode_async() callback, drivers can now handle address list updates directly in a sleepable context. Therefore, convert the enetc driver to use ndo_set_rx_mode_async() and remove the dedicated workqueue and the deferred work item accordingly. Signed-off-by: Wei Fang Link: https://patch.msgid.link/20260720014317.1059359-4-wei.fang@oss.nxp.com Signed-off-by: Jakub Kicinski Stable-dep-of: fa1a8457b858 ("net: enetc: restore RX ring congestion mode for ENETC v4") Signed-off-by: Sasha Levin --- drivers/net/ethernet/freescale/enetc/enetc.h | 2 - .../net/ethernet/freescale/enetc/enetc4_pf.c | 178 ++++++------------ 2 files changed, 58 insertions(+), 122 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.h b/drivers/net/ethernet/freescale/enetc/enetc.h index 41357c5611084..2145563ab2ac1 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.h +++ b/drivers/net/ethernet/freescale/enetc/enetc.h @@ -331,8 +331,6 @@ struct enetc_si { const struct enetc_drvdata *drvdata; const struct enetc_si_ops *ops; - struct workqueue_struct *workqueue; - struct work_struct rx_mode_task; struct dentry *debugfs_root; struct enetc_msg_swbd msg; /* Only valid for VSI */ }; diff --git a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c index 48a74db90ed5c..a02b01753ff27 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc4_pf.c +++ b/drivers/net/ethernet/freescale/enetc/enetc4_pf.c @@ -101,24 +101,23 @@ static void enetc4_pf_clear_maft_entries(struct enetc_pf *pf) } static int enetc4_pf_add_maft_entries(struct enetc_pf *pf, - struct enetc_mac_addr *mac, - int mac_cnt) + struct netdev_hw_addr_list *uc) { struct maft_entry_data maft = {}; + struct netdev_hw_addr *ha; u16 si_bit = BIT(0); - int i, err; + int err; maft.cfge.si_bitmap = cpu_to_le16(si_bit); - for (i = 0; i < mac_cnt; i++) { - ether_addr_copy(maft.keye.mac_addr, mac[i].addr); - err = ntmp_maft_add_entry(&pf->si->ntmp_user, i, &maft); - if (unlikely(err)) { - pf->num_mfe = i; + netdev_hw_addr_list_for_each(ha, uc) { + ether_addr_copy(maft.keye.mac_addr, ha->addr); + err = ntmp_maft_add_entry(&pf->si->ntmp_user, pf->num_mfe, + &maft); + if (unlikely(err)) goto clear_maft_entries; - } - } - pf->num_mfe = mac_cnt; + pf->num_mfe++; + } return 0; @@ -128,23 +127,29 @@ static int enetc4_pf_add_maft_entries(struct enetc_pf *pf, return err; } -static int enetc4_pf_set_uc_exact_filter(struct enetc_pf *pf) +static void enetc4_pf_set_uc_hash_filter(struct enetc_pf *pf, + struct netdev_hw_addr_list *uc) { - int max_num_mfe = pf->caps.mac_filter_num; - struct enetc_mac_filter mac_filter = {}; - struct net_device *ndev = pf->si->ndev; - struct enetc_mac_addr *mac_tbl; - struct enetc_si *si = pf->si; + struct enetc_mac_filter *mac_filter = &pf->mac_filter[UC]; struct netdev_hw_addr *ha; - int i = 0, err; - int mac_cnt; u64 hash; - netif_addr_lock_bh(ndev); + enetc_reset_mac_addr_filter(mac_filter); + netdev_hw_addr_list_for_each(ha, uc) + enetc_add_mac_addr_ht_filter(mac_filter, ha->addr); + + bitmap_to_arr64(&hash, mac_filter->mac_hash_table, + ENETC_MADDR_HASH_TBL_SZ); + enetc_set_si_uc_hash_filter(pf->si, 0, hash); +} + +static int enetc4_pf_set_uc_exact_filter(struct enetc_pf *pf, + struct netdev_hw_addr_list *uc) +{ + int mac_cnt = netdev_hw_addr_list_count(uc); + struct enetc_si *si = pf->si; - mac_cnt = netdev_uc_count(ndev); if (!mac_cnt) { - netif_addr_unlock_bh(ndev); /* clear both MAC hash and exact filters */ enetc_set_si_uc_hash_filter(si, 0, 0); enetc4_pf_clear_maft_entries(pf); @@ -152,79 +157,42 @@ static int enetc4_pf_set_uc_exact_filter(struct enetc_pf *pf) return 0; } - if (mac_cnt > max_num_mfe) { - err = -ENOSPC; - goto unlock_netif_addr; - } - - mac_tbl = kzalloc_objs(*mac_tbl, mac_cnt, GFP_ATOMIC); - if (!mac_tbl) { - err = -ENOMEM; - goto unlock_netif_addr; - } - - netdev_for_each_uc_addr(ha, ndev) { - enetc_add_mac_addr_ht_filter(&mac_filter, ha->addr); - ether_addr_copy(mac_tbl[i++].addr, ha->addr); - } - - netif_addr_unlock_bh(ndev); + if (mac_cnt > pf->caps.mac_filter_num) + return -ENOSPC; /* Set temporary unicast hash filters in case of Rx loss when * updating MAC address filter table */ - bitmap_to_arr64(&hash, mac_filter.mac_hash_table, - ENETC_MADDR_HASH_TBL_SZ); - enetc_set_si_uc_hash_filter(si, 0, hash); + enetc4_pf_set_uc_hash_filter(pf, uc); enetc4_pf_clear_maft_entries(pf); - if (!enetc4_pf_add_maft_entries(pf, mac_tbl, i)) + if (!enetc4_pf_add_maft_entries(pf, uc)) { + enetc_reset_mac_addr_filter(&pf->mac_filter[UC]); enetc_set_si_uc_hash_filter(si, 0, 0); - - kfree(mac_tbl); + } return 0; - -unlock_netif_addr: - netif_addr_unlock_bh(ndev); - - return err; } -static void enetc4_pf_set_mac_hash_filter(struct enetc_pf *pf, int type) +static void enetc4_pf_set_mc_hash_filter(struct enetc_pf *pf, + struct netdev_hw_addr_list *mc) { - struct net_device *ndev = pf->si->ndev; - struct enetc_mac_filter *mac_filter; - struct enetc_si *si = pf->si; + struct enetc_mac_filter *mac_filter = &pf->mac_filter[MC]; struct netdev_hw_addr *ha; u64 hash; - netif_addr_lock_bh(ndev); - if (type & ENETC_MAC_FILTER_TYPE_UC) { - mac_filter = &pf->mac_filter[UC]; - enetc_reset_mac_addr_filter(mac_filter); - netdev_for_each_uc_addr(ha, ndev) - enetc_add_mac_addr_ht_filter(mac_filter, ha->addr); - - bitmap_to_arr64(&hash, mac_filter->mac_hash_table, - ENETC_MADDR_HASH_TBL_SZ); - enetc_set_si_uc_hash_filter(si, 0, hash); - } + enetc_reset_mac_addr_filter(mac_filter); + netdev_hw_addr_list_for_each(ha, mc) + enetc_add_mac_addr_ht_filter(mac_filter, ha->addr); - if (type & ENETC_MAC_FILTER_TYPE_MC) { - mac_filter = &pf->mac_filter[MC]; - enetc_reset_mac_addr_filter(mac_filter); - netdev_for_each_mc_addr(ha, ndev) - enetc_add_mac_addr_ht_filter(mac_filter, ha->addr); - - bitmap_to_arr64(&hash, mac_filter->mac_hash_table, - ENETC_MADDR_HASH_TBL_SZ); - enetc_set_si_mc_hash_filter(si, 0, hash); - } - netif_addr_unlock_bh(ndev); + bitmap_to_arr64(&hash, mac_filter->mac_hash_table, + ENETC_MADDR_HASH_TBL_SZ); + enetc_set_si_mc_hash_filter(pf->si, 0, hash); } -static void enetc4_pf_set_mac_filter(struct enetc_pf *pf, int type) +static void enetc4_pf_set_mac_filter(struct enetc_pf *pf, int type, + struct netdev_hw_addr_list *uc, + struct netdev_hw_addr_list *mc) { /* Currently, the MAC address filter table (MAFT) only has 4 entries, * and multiple multicast addresses for filtering will be configured @@ -232,15 +200,16 @@ static void enetc4_pf_set_mac_filter(struct enetc_pf *pf, int type) * unicast filtering. If the number of unicast addresses exceeds the * table capacity, the MAC hash filter will be used. */ - if (type & ENETC_MAC_FILTER_TYPE_UC && enetc4_pf_set_uc_exact_filter(pf)) { + if (type & ENETC_MAC_FILTER_TYPE_UC && + enetc4_pf_set_uc_exact_filter(pf, uc)) { /* Fall back to the MAC hash filter */ - enetc4_pf_set_mac_hash_filter(pf, ENETC_MAC_FILTER_TYPE_UC); + enetc4_pf_set_uc_hash_filter(pf, uc); /* Clear the old MAC exact filter */ enetc4_pf_clear_maft_entries(pf); } if (type & ENETC_MAC_FILTER_TYPE_MC) - enetc4_pf_set_mac_hash_filter(pf, ENETC_MAC_FILTER_TYPE_MC); + enetc4_pf_set_mc_hash_filter(pf, mc); } static const struct enetc_pf_ops enetc4_pf_ops = { @@ -467,17 +436,17 @@ static void enetc4_pf_free(struct enetc_pf *pf) enetc4_free_ntmp_user(pf->si); } -static void enetc4_psi_do_set_rx_mode(struct work_struct *work) +static int enetc4_pf_set_rx_mode(struct net_device *ndev, + struct netdev_hw_addr_list *uc, + struct netdev_hw_addr_list *mc) { - struct enetc_si *si = container_of(work, struct enetc_si, rx_mode_task); - struct enetc_pf *pf = enetc_si_priv(si); - struct net_device *ndev = si->ndev; + struct enetc_ndev_priv *priv = netdev_priv(ndev); + struct enetc_pf *pf = enetc_si_priv(priv->si); + struct enetc_si *si = priv->si; bool uc_promisc = false; bool mc_promisc = false; int type = 0; - rtnl_lock(); - if (ndev->flags & IFF_PROMISC) { uc_promisc = true; mc_promisc = true; @@ -500,17 +469,9 @@ static void enetc4_psi_do_set_rx_mode(struct work_struct *work) enetc_set_si_mc_hash_filter(si, 0, 0); /* Set new MAC filter */ - enetc4_pf_set_mac_filter(pf, type); - - rtnl_unlock(); -} + enetc4_pf_set_mac_filter(pf, type, uc, mc); -static void enetc4_pf_set_rx_mode(struct net_device *ndev) -{ - struct enetc_ndev_priv *priv = netdev_priv(ndev); - struct enetc_si *si = priv->si; - - queue_work(si->workqueue, &si->rx_mode_task); + return 0; } static int enetc4_pf_set_features(struct net_device *ndev, @@ -540,7 +501,7 @@ static const struct net_device_ops enetc4_ndev_ops = { .ndo_start_xmit = enetc_xmit, .ndo_get_stats = enetc_get_stats, .ndo_set_mac_address = enetc_pf_set_mac_addr, - .ndo_set_rx_mode = enetc4_pf_set_rx_mode, + .ndo_set_rx_mode_async = enetc4_pf_set_rx_mode, .ndo_set_features = enetc4_pf_set_features, .ndo_vlan_rx_add_vid = enetc_vlan_rx_add_vid, .ndo_vlan_rx_kill_vid = enetc_vlan_rx_del_vid, @@ -983,19 +944,6 @@ static void enetc4_link_deinit(struct enetc_ndev_priv *priv) enetc_mdiobus_destroy(pf); } -static int enetc4_psi_wq_task_init(struct enetc_si *si) -{ - char wq_name[24]; - - INIT_WORK(&si->rx_mode_task, enetc4_psi_do_set_rx_mode); - snprintf(wq_name, sizeof(wq_name), "enetc-%s", pci_name(si->pdev)); - si->workqueue = create_singlethread_workqueue(wq_name); - if (!si->workqueue) - return -ENOMEM; - - return 0; -} - static int enetc4_pf_netdev_create(struct enetc_si *si) { struct device *dev = &si->pdev->dev; @@ -1036,12 +984,6 @@ static int enetc4_pf_netdev_create(struct enetc_si *si) if (err) goto err_link_init; - err = enetc4_psi_wq_task_init(si); - if (err) { - dev_err(dev, "Failed to init workqueue\n"); - goto err_wq_init; - } - err = register_netdev(ndev); if (err) { dev_err(dev, "Failed to register netdev\n"); @@ -1051,8 +993,6 @@ static int enetc4_pf_netdev_create(struct enetc_si *si) return 0; err_reg_netdev: - destroy_workqueue(si->workqueue); -err_wq_init: enetc4_link_deinit(priv); err_link_init: enetc_free_msix(priv); @@ -1070,8 +1010,6 @@ static void enetc4_pf_netdev_destroy(struct enetc_si *si) struct net_device *ndev = si->ndev; unregister_netdev(ndev); - cancel_work(&si->rx_mode_task); - destroy_workqueue(si->workqueue); enetc4_link_deinit(priv); enetc_free_msix(priv); free_netdev(ndev); -- 2.53.0