From: I Viswanath <viswanathiyyappan@gmail.com>
To: stfomichev@gmail.com, horms@kernel.org, edumazet@google.com,
pabeni@redhat.com, andrew+netdev@lunn.ch, kuba@kernel.org,
davem@davemloft.net, eperezma@redhat.com,
xuanzhuo@linux.alibaba.com, jasowang@redhat.com, mst@redhat.com,
przemyslaw.kitszel@intel.com, anthony.l.nguyen@intel.com,
jacob.e.keller@intel.com, ronak.doshi@broadcom.com,
pcnet32@frontier.com
Cc: bcm-kernel-feedback-list@broadcom.com, netdev@vger.kernel.org,
virtualization@lists.linux.dev, intel-wired-lan@lists.osuosl.org,
linux-kernel@vger.kernel.org,
I Viswanath <viswanathiyyappan@gmail.com>
Subject: [PATCH net-next v9 3/7] virtio-net: Implement ndo_set_rx_mode_async callback
Date: Sat, 14 Mar 2026 23:58:05 +0530 [thread overview]
Message-ID: <20260314182809.362808-4-viswanathiyyappan@gmail.com> (raw)
In-Reply-To: <20260314182809.362808-1-viswanathiyyappan@gmail.com>
Implement the ndo_set_rx_mode_async callback and update
the driver to use the snapshot/commit model for RX mode update.
Signed-off-by: I Viswanath <viswanathiyyappan@gmail.com>
---
There are no calls to netif_set_rx_mode in virtio-net
drivers/net/virtio_net.c | 85 ++++++++++++----------------------------
1 file changed, 25 insertions(+), 60 deletions(-)
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 811b90da15a9..70255d09401c 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -448,12 +448,6 @@ struct virtnet_info {
/* Work struct for config space updates */
struct work_struct config_work;
- /* Work struct for setting rx mode */
- struct work_struct rx_mode_work;
-
- /* OK to queue work setting RX mode? */
- bool rx_mode_work_enabled;
-
/* Does the affinity hint is set for virtqueues? */
bool affinity_hint_set;
@@ -717,20 +711,6 @@ static void virtnet_rq_free_buf(struct virtnet_info *vi,
put_page(virt_to_head_page(buf));
}
-static void enable_rx_mode_work(struct virtnet_info *vi)
-{
- rtnl_lock();
- vi->rx_mode_work_enabled = true;
- rtnl_unlock();
-}
-
-static void disable_rx_mode_work(struct virtnet_info *vi)
-{
- rtnl_lock();
- vi->rx_mode_work_enabled = false;
- rtnl_unlock();
-}
-
static void virtqueue_napi_schedule(struct napi_struct *napi,
struct virtqueue *vq)
{
@@ -3802,33 +3782,30 @@ static int virtnet_close(struct net_device *dev)
return 0;
}
-static void virtnet_rx_mode_work(struct work_struct *work)
+static void virtnet_set_rx_mode_async(struct net_device *dev)
{
- struct virtnet_info *vi =
- container_of(work, struct virtnet_info, rx_mode_work);
+ struct virtnet_info *vi = netdev_priv(dev);
u8 *promisc_allmulti __free(kfree) = NULL;
- struct net_device *dev = vi->dev;
struct scatterlist sg[2];
struct virtio_net_ctrl_mac *mac_data;
- struct netdev_hw_addr *ha;
+ char *ha_addr;
int uc_count;
int mc_count;
void *buf;
- int i;
+ int i, ni;
- /* We can't dynamically set ndo_set_rx_mode, so return gracefully */
+ /* We can't dynamically set rx_mode, so return gracefully */
if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_RX))
return;
- promisc_allmulti = kzalloc_obj(*promisc_allmulti);
+ promisc_allmulti = kzalloc_obj(*promisc_allmulti, GFP_ATOMIC);
if (!promisc_allmulti) {
dev_warn(&dev->dev, "Failed to set RX mode, no memory.\n");
return;
}
- rtnl_lock();
-
- *promisc_allmulti = !!(dev->flags & IFF_PROMISC);
+ *promisc_allmulti = netif_get_rx_mode_cfg(dev,
+ NETIF_RX_MODE_CFG_PROMISC);
sg_init_one(sg, promisc_allmulti, sizeof(*promisc_allmulti));
if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX,
@@ -3836,7 +3813,8 @@ static void virtnet_rx_mode_work(struct work_struct *work)
dev_warn(&dev->dev, "Failed to %sable promisc mode.\n",
*promisc_allmulti ? "en" : "dis");
- *promisc_allmulti = !!(dev->flags & IFF_ALLMULTI);
+ *promisc_allmulti = netif_get_rx_mode_cfg(dev,
+ NETIF_RX_MODE_CFG_ALLMULTI);
sg_init_one(sg, promisc_allmulti, sizeof(*promisc_allmulti));
if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX,
@@ -3844,27 +3822,22 @@ static void virtnet_rx_mode_work(struct work_struct *work)
dev_warn(&dev->dev, "Failed to %sable allmulti mode.\n",
*promisc_allmulti ? "en" : "dis");
- netif_addr_lock_bh(dev);
-
- uc_count = netdev_uc_count(dev);
- mc_count = netdev_mc_count(dev);
+ uc_count = netif_rx_mode_uc_count(dev);
+ mc_count = netif_rx_mode_mc_count(dev);
/* MAC filter - use one buffer for both lists */
buf = kzalloc(((uc_count + mc_count) * ETH_ALEN) +
(2 * sizeof(mac_data->entries)), GFP_ATOMIC);
mac_data = buf;
- if (!buf) {
- netif_addr_unlock_bh(dev);
- rtnl_unlock();
+ if (!buf)
return;
- }
sg_init_table(sg, 2);
/* Store the unicast list and count in the front of the buffer */
mac_data->entries = cpu_to_virtio32(vi->vdev, uc_count);
i = 0;
- netdev_for_each_uc_addr(ha, dev)
- memcpy(&mac_data->macs[i++][0], ha->addr, ETH_ALEN);
+ netif_rx_mode_for_each_uc_addr(ha_addr, dev, ni)
+ memcpy(&mac_data->macs[i++][0], ha_addr, ETH_ALEN);
sg_set_buf(&sg[0], mac_data,
sizeof(mac_data->entries) + (uc_count * ETH_ALEN));
@@ -3874,10 +3847,8 @@ static void virtnet_rx_mode_work(struct work_struct *work)
mac_data->entries = cpu_to_virtio32(vi->vdev, mc_count);
i = 0;
- netdev_for_each_mc_addr(ha, dev)
- memcpy(&mac_data->macs[i++][0], ha->addr, ETH_ALEN);
-
- netif_addr_unlock_bh(dev);
+ netif_rx_mode_for_each_mc_addr(ha_addr, dev, ni)
+ memcpy(&mac_data->macs[i++][0], ha_addr, ETH_ALEN);
sg_set_buf(&sg[1], mac_data,
sizeof(mac_data->entries) + (mc_count * ETH_ALEN));
@@ -3886,17 +3857,16 @@ static void virtnet_rx_mode_work(struct work_struct *work)
VIRTIO_NET_CTRL_MAC_TABLE_SET, sg))
dev_warn(&dev->dev, "Failed to set MAC filter table.\n");
- rtnl_unlock();
-
kfree(buf);
}
static void virtnet_set_rx_mode(struct net_device *dev)
{
- struct virtnet_info *vi = netdev_priv(dev);
+ bool allmulti = !!(dev->flags & IFF_ALLMULTI);
+ bool promisc = !!(dev->flags & IFF_PROMISC);
- if (vi->rx_mode_work_enabled)
- schedule_work(&vi->rx_mode_work);
+ netif_set_rx_mode_cfg(dev, NETIF_RX_MODE_CFG_ALLMULTI, allmulti);
+ netif_set_rx_mode_cfg(dev, NETIF_RX_MODE_CFG_PROMISC, promisc);
}
static int virtnet_vlan_rx_add_vid(struct net_device *dev,
@@ -5711,8 +5681,6 @@ static void virtnet_freeze_down(struct virtio_device *vdev)
/* Make sure no work handler is accessing the device */
flush_work(&vi->config_work);
- disable_rx_mode_work(vi);
- flush_work(&vi->rx_mode_work);
if (netif_running(vi->dev)) {
rtnl_lock();
@@ -5738,8 +5706,6 @@ static int virtnet_restore_up(struct virtio_device *vdev)
virtio_device_ready(vdev);
- enable_rx_mode_work(vi);
-
if (netif_running(vi->dev)) {
rtnl_lock();
err = virtnet_open(vi->dev);
@@ -6214,6 +6180,7 @@ static const struct net_device_ops virtnet_netdev = {
.ndo_validate_addr = eth_validate_addr,
.ndo_set_mac_address = virtnet_set_mac_address,
.ndo_set_rx_mode = virtnet_set_rx_mode,
+ .ndo_set_rx_mode_async = virtnet_set_rx_mode_async,
.ndo_get_stats64 = virtnet_stats,
.ndo_vlan_rx_add_vid = virtnet_vlan_rx_add_vid,
.ndo_vlan_rx_kill_vid = virtnet_vlan_rx_kill_vid,
@@ -6834,7 +6801,6 @@ static int virtnet_probe(struct virtio_device *vdev)
vdev->priv = vi;
INIT_WORK(&vi->config_work, virtnet_config_changed_work);
- INIT_WORK(&vi->rx_mode_work, virtnet_rx_mode_work);
if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF)) {
vi->mergeable_rx_bufs = true;
@@ -6986,8 +6952,6 @@ static int virtnet_probe(struct virtio_device *vdev)
if (vi->has_rss || vi->has_rss_hash_report)
virtnet_init_default_rss(vi);
- enable_rx_mode_work(vi);
-
/* serialize netdev register + virtio_device_ready() with ndo_open() */
rtnl_lock();
@@ -7136,8 +7100,6 @@ static void virtnet_remove(struct virtio_device *vdev)
/* Make sure no work handler is accessing the device. */
flush_work(&vi->config_work);
- disable_rx_mode_work(vi);
- flush_work(&vi->rx_mode_work);
virtnet_free_irq_moder(vi);
@@ -7158,6 +7120,7 @@ static __maybe_unused int virtnet_freeze(struct virtio_device *vdev)
virtnet_freeze_down(vdev);
remove_vq_common(vi);
+ netif_disable_async_ops(vi->dev);
return 0;
}
@@ -7166,6 +7129,7 @@ static __maybe_unused int virtnet_restore(struct virtio_device *vdev)
struct virtnet_info *vi = vdev->priv;
int err;
+ netif_enable_async_ops(vi->dev);
err = virtnet_restore_up(vdev);
if (err)
return err;
@@ -7175,6 +7139,7 @@ static __maybe_unused int virtnet_restore(struct virtio_device *vdev)
if (err) {
virtnet_freeze_down(vdev);
remove_vq_common(vi);
+ netif_disable_async_ops(vi->dev);
return err;
}
--
2.47.3
next prev parent reply other threads:[~2026-03-14 18:29 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-14 18:28 [PATCH net-next v9 0/7] Introduce async callback ndo_set_rx_mode_async I Viswanath
2026-03-14 18:28 ` [PATCH net-next v9 1/7] net: core: Add state tracking for async netdev ops I Viswanath
2026-03-16 7:25 ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-03-14 18:28 ` [PATCH net-next v9 2/7] net: core: Introduce callback ndo_set_rx_mode_async I Viswanath
2026-03-16 7:29 ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-03-14 18:28 ` I Viswanath [this message]
2026-03-16 7:30 ` [Intel-wired-lan] [PATCH net-next v9 3/7] virtio-net: Implement ndo_set_rx_mode_async callback Loktionov, Aleksandr
2026-03-14 18:28 ` [PATCH net-next v9 4/7] e1000: " I Viswanath
2026-03-16 7:30 ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-03-14 18:28 ` [PATCH net-next v9 5/7] 8139cp: " I Viswanath
2026-03-16 7:34 ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-03-14 18:28 ` [PATCH net-next v9 6/7] vmxnet3: " I Viswanath
2026-03-16 7:35 ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-03-14 18:28 ` [PATCH net-next v9 7/7] pcnet32: " I Viswanath
2026-03-16 7:35 ` [Intel-wired-lan] " Loktionov, Aleksandr
2026-03-14 20:06 ` [PATCH net-next v9 0/7] Introduce async callback ndo_set_rx_mode_async Jakub Kicinski
2026-03-14 19:59 ` I Viswanath
2026-03-17 16:15 ` Jakub Kicinski
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=20260314182809.362808-4-viswanathiyyappan@gmail.com \
--to=viswanathiyyappan@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=anthony.l.nguyen@intel.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=eperezma@redhat.com \
--cc=horms@kernel.org \
--cc=intel-wired-lan@lists.osuosl.org \
--cc=jacob.e.keller@intel.com \
--cc=jasowang@redhat.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pcnet32@frontier.com \
--cc=przemyslaw.kitszel@intel.com \
--cc=ronak.doshi@broadcom.com \
--cc=stfomichev@gmail.com \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.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