From nobody Mon Feb 9 11:47:18 2026 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BF88314A73 for ; Fri, 2 Jan 2026 18:06:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767377171; cv=none; b=jCiZFWlyPH1ffQLxV9JxW3PxukycCqGlGHe8lrLoe/wtWmZ0KnvwfJTajkfAqo/Um6LIpVQaTlcuCpwUAEzKiiif4pHznQVOIGEqnbXJhcXcXVZrLgiLyLkSlTf3lnSTcIdZr5GQ1EAGArdMRH53+9NkDtnM0gNmUpU8VLKBn2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767377171; c=relaxed/simple; bh=oetQtpSM3DjCX3/aeFuWgTQCahQBkDyO/iqkcjjmuuw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K5iaJKPAz6ZCrDFgUoce7X+XZp/ZFdGz70kwkGqoh/MeuB7MHlLfkHAcBn7e4xvaYKkYc6Egy5gWxPOJATIziN7WlCefF7mjhGD2QtwRLGb02UedQsdt7eQ+C6uam4TGdQ3mzPSrJ/Ulsx9Pw94LPTUbiKL7X+id8SeupE+UmY4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ISi8jBR3; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ISi8jBR3" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2a1388cdac3so113357385ad.0 for ; Fri, 02 Jan 2026 10:06:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767377160; x=1767981960; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dfcgCbP6RhhVMiMr9Azv6F2aQ7T6/MJccCOzX/54vEE=; b=ISi8jBR3puCj3RPUhCjqDezSdK1NmfG1a2nm6j6QUUa/TudJetCSJdhFJLOAIknsrt XZpWKgNCJfuRAM8PYDwMhyuXG3huXnx3H5n+VZiggPV6zv/dheod3HId05xLEKCDD5kL oYb9IXAMoDTc6+9cQyQQyMYpzUBI4yeGHNBR1hKp4bLyOVeMXuR33sJfUY3vqCTI8Rbt jMt3VUV/EbhhusPKArVA69h5WEAWFWlvyc4EkEgMx/pbdHcxn+u4rVzMpSkejSUcf9dl 3XlPOSdPJ2ppqMeN6nxImGFn0QI7vvuyTP0+cI+b4W5xiChvkNdgap0KYQI2uQI2hDzx UYJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767377160; x=1767981960; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=dfcgCbP6RhhVMiMr9Azv6F2aQ7T6/MJccCOzX/54vEE=; b=no03xdinuXu6zIXgCqOHSOeRpw8B98baFXndNtl4z6JuNLAJotI1AomCmzqTgT2nLW sfbGNT3TlUWliE3cAWJ///3/tr3FM/TcfHtUPAd5cR5IqbZ5cbo30dA1QJRaGpLi9C33 yplDpN3o3baAYuB5L7B6mhInymxpgRYp96pfl75lh5ZGYZTeJl5b6sunK1tP56QljiGL hL5me/L+ey94Ql/mmDQJA35YhGZMMaqBWOsW4vUN8ua3mKbDt3sdqTJNOh74RC1z8Dzg bqGFpabsqo/VUb+lmCz+Bi0LfBmn5snGm2NDQ86H2qhh72uU/z7t57Gm/dBt5ggOiXGd zGHA== X-Forwarded-Encrypted: i=1; AJvYcCWggg774n6Mn46qPCGAy7LPapXyZ70+vkvl1DXRT5IO56Yes3fXQai2nlp5VT48STfvUI/o3vi6XaUuXYg=@vger.kernel.org X-Gm-Message-State: AOJu0Yz9ymhN18UEVgCdtXxYfFUn6hTTKxPWZ0zUyEEjcMTz9RkK165f clEMGdfo0IOjC23hl1pyNzo8wXIT1dmzUoJOjKpZXNl/ZCBwYpix9V/v X-Gm-Gg: AY/fxX6gcZ/ARC85WNm4KtjdjLxRVQkWArohcxvz9tWtrVAqyZ6a1mdMe1Ld64kYgxU HVyLpR+GFIfzEm7o2Sxd5SBBe1XWyddq1iXTG+KGNgTZDt/1Y53Ed4z2bYosO1UjNr+Vew+dtQy OfOzBfLSkF9YMPtNyXIJSQUAafDvLyJgiOHICOSmlBsQKhwuKA/ME9RtnJU9F8D7+HQgn9UG60t bkKeZTqvQIYylsBABSH9rHI2bjDz0D/1jacM9JbjuCzUrlb6BgblKDJBXLm84msbeMMQyeyLeD8 M1V4onHM1XnkE0Bs9XHbPXKgZRVZOt3a2JihT7fC3jQmvNQveQ/P5+6ut7qxEUG/UlFyIsvti4J xz6Lwjy2usKeaXJ+Y2XCiI/z4iYDsj6dxCEMWk7wl0KKsJWlt0y6lwKqkhityoVGNWwFn2dNBGT AyjDxxbn5t1uX4fPLy4dN9+T4AjZF4m1k8cN6pu/PJx2c7OYypBzoeYWGjbqdaIgn4pWA= X-Google-Smtp-Source: AGHT+IGlPf0sJytEVblRsx7DE7M/l8a4Fbt7aqtuWECHLRxylpFO/PMXbrQ9354tq/9aQ/e2ZEXM+g== X-Received: by 2002:a17:902:e74b:b0:299:e215:f61e with SMTP id d9443c01a7336-2a2f2a34fadmr407610955ad.36.1767377159960; Fri, 02 Jan 2026 10:05:59 -0800 (PST) Received: from localhost.localdomain ([223.181.108.198]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a2f3d77566sm386297585ad.97.2026.01.02.10.05.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jan 2026 10:05:59 -0800 (PST) From: I Viswanath To: edumazet@google.com, andrew+netdev@lunn.ch, horms@kernel.org, kuba@kernel.org, pabeni@redhat.com, mst@redhat.com, eperezma@redhat.com, jasowang@redhat.com, xuanzhuo@linux.alibaba.com Cc: netdev@vger.kernel.org, virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, I Viswanath Subject: [PATCH net-next v7 2/2] virtio-net: Implement ndo_write_rx_mode callback Date: Fri, 2 Jan 2026 23:35:30 +0530 Message-ID: <20260102180530.1559514-3-viswanathiyyappan@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260102180530.1559514-1-viswanathiyyappan@gmail.com> References: <20260102180530.1559514-1-viswanathiyyappan@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement ndo_write_rx_mode callback for virtio-net Signed-off-by: I Viswanath --- drivers/net/virtio_net.c | 55 +++++++++++++++------------------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 1bb3aeca66c6..83d543bf6ae2 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -460,9 +460,6 @@ struct virtnet_info { /* Work struct for config space updates */ struct work_struct config_work; =20 - /* Work struct for setting rx mode */ - struct work_struct rx_mode_work; - /* OK to queue work setting RX mode? */ bool rx_mode_work_enabled; =20 @@ -3866,33 +3863,31 @@ static int virtnet_close(struct net_device *dev) return 0; } =20 -static void virtnet_rx_mode_work(struct work_struct *work) +static void virtnet_write_rx_mode(struct net_device *dev) { - struct virtnet_info *vi =3D - container_of(work, struct virtnet_info, rx_mode_work); + struct virtnet_info *vi =3D netdev_priv(dev); u8 *promisc_allmulti __free(kfree) =3D NULL; - struct net_device *dev =3D 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 idx; int i; =20 /* We can't dynamically set ndo_set_rx_mode, so return gracefully */ if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_CTRL_RX)) return; =20 - promisc_allmulti =3D kzalloc(sizeof(*promisc_allmulti), GFP_KERNEL); + promisc_allmulti =3D kzalloc(sizeof(*promisc_allmulti), GFP_ATOMIC); if (!promisc_allmulti) { dev_warn(&dev->dev, "Failed to set RX mode, no memory.\n"); return; } =20 - rtnl_lock(); - - *promisc_allmulti =3D !!(dev->flags & IFF_PROMISC); + *promisc_allmulti =3D netif_rx_mode_get_cfg(dev, + NETIF_RX_MODE_CFG_PROMISC); sg_init_one(sg, promisc_allmulti, sizeof(*promisc_allmulti)); =20 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX, @@ -3900,7 +3895,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"); =20 - *promisc_allmulti =3D !!(dev->flags & IFF_ALLMULTI); + *promisc_allmulti =3D netif_rx_mode_get_cfg(dev, + NETIF_RX_MODE_CFG_ALLMULTI); sg_init_one(sg, promisc_allmulti, sizeof(*promisc_allmulti)); =20 if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_RX, @@ -3908,27 +3904,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"); =20 - netif_addr_lock_bh(dev); - - uc_count =3D netdev_uc_count(dev); - mc_count =3D netdev_mc_count(dev); + uc_count =3D netif_rx_mode_get_uc_count(dev); + mc_count =3D netif_rx_mode_get_mc_count(dev); /* MAC filter - use one buffer for both lists */ buf =3D kzalloc(((uc_count + mc_count) * ETH_ALEN) + (2 * sizeof(mac_data->entries)), GFP_ATOMIC); mac_data =3D buf; - if (!buf) { - netif_addr_unlock_bh(dev); - rtnl_unlock(); + if (!buf) return; - } =20 sg_init_table(sg, 2); =20 /* Store the unicast list and count in the front of the buffer */ mac_data->entries =3D cpu_to_virtio32(vi->vdev, uc_count); i =3D 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(dev, ha_addr, idx) + memcpy(&mac_data->macs[i++][0], ha_addr, ETH_ALEN); =20 sg_set_buf(&sg[0], mac_data, sizeof(mac_data->entries) + (uc_count * ETH_ALEN)); @@ -3938,10 +3929,8 @@ static void virtnet_rx_mode_work(struct work_struct = *work) =20 mac_data->entries =3D cpu_to_virtio32(vi->vdev, mc_count); i =3D 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(dev, ha_addr, idx) + memcpy(&mac_data->macs[i++][0], ha_addr, ETH_ALEN); =20 sg_set_buf(&sg[1], mac_data, sizeof(mac_data->entries) + (mc_count * ETH_ALEN)); @@ -3950,17 +3939,15 @@ 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"); =20 - rtnl_unlock(); - kfree(buf); } =20 static void virtnet_set_rx_mode(struct net_device *dev) { struct virtnet_info *vi =3D netdev_priv(dev); + char cfg_disabled =3D !vi->rx_mode_work_enabled; =20 - if (vi->rx_mode_work_enabled) - schedule_work(&vi->rx_mode_work); + netif_rx_mode_set_flag(dev, NETIF_RX_MODE_SET_SKIP, cfg_disabled); } =20 static int virtnet_vlan_rx_add_vid(struct net_device *dev, @@ -5776,7 +5763,7 @@ 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); + netif_flush_rx_mode_work(vi->dev); =20 if (netif_running(vi->dev)) { rtnl_lock(); @@ -6279,6 +6266,7 @@ static const struct net_device_ops virtnet_netdev =3D= { .ndo_validate_addr =3D eth_validate_addr, .ndo_set_mac_address =3D virtnet_set_mac_address, .ndo_set_rx_mode =3D virtnet_set_rx_mode, + .ndo_write_rx_mode =3D virtnet_write_rx_mode, .ndo_get_stats64 =3D virtnet_stats, .ndo_vlan_rx_add_vid =3D virtnet_vlan_rx_add_vid, .ndo_vlan_rx_kill_vid =3D virtnet_vlan_rx_kill_vid, @@ -6900,7 +6888,6 @@ static int virtnet_probe(struct virtio_device *vdev) vdev->priv =3D vi; =20 INIT_WORK(&vi->config_work, virtnet_config_changed_work); - INIT_WORK(&vi->rx_mode_work, virtnet_rx_mode_work); spin_lock_init(&vi->refill_lock); =20 if (virtio_has_feature(vdev, VIRTIO_NET_F_MRG_RXBUF)) { @@ -7205,7 +7192,7 @@ 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); + netif_flush_rx_mode_work(vi->dev); =20 virtnet_free_irq_moder(vi); =20 --=20 2.47.3