[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251026175445.1519537-2-viswanathiyyappan@gmail.com>
Date: Sun, 26 Oct 2025 23:24:44 +0530
From: I Viswanath <viswanathiyyappan@...il.com>
To: davem@...emloft.net,
edumazet@...gle.com,
kuba@...nel.org,
pabeni@...hat.com,
horms@...nel.org,
sdf@...ichev.me,
kuniyu@...gle.com,
ahmed.zaki@...el.com,
aleksander.lobakin@...el.com,
jacob.e.keller@...el.com
Cc: netdev@...r.kernel.org,
linux-kernel@...r.kernel.org,
skhan@...uxfoundation.org,
linux-kernel-mentees@...ts.linux.dev,
david.hunter.linux@...il.com,
khalid@...nel.org,
I Viswanath <viswanathiyyappan@...il.com>
Subject: [RFC PATCH net-next v2 1/2] net: Add ndo_write_rx_config and helper structs and functions:
Add ndo_write_rx_config callback and helper structs/functions:
rx_config_work - To schedule the callback and handle synchronization
read_snapshot/update_snapshot - Helper functions to read/update the
rx_config snapshot
set_and_schedule_rx_config - Helper function to call ndo_set_rx_mode
and schedule ndo_write_rx_config
execute_write_rx_config - Helper function that will be scheduled
by rx_work->config_write
Signed-off-by: I Viswanath <viswanathiyyappan@...il.com>
---
include/linux/netdevice.h | 38 ++++++++++++++++++++++++++-
net/core/dev.c | 54 +++++++++++++++++++++++++++++++++++----
2 files changed, 86 insertions(+), 6 deletions(-)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index d1a687444b27..80d6966d6981 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1100,7 +1100,12 @@ struct netdev_net_notifier {
* void (*ndo_set_rx_mode)(struct net_device *dev);
* This function is called device changes address list filtering.
* If driver handles unicast address filtering, it should set
- * IFF_UNICAST_FLT in its priv_flags.
+ * IFF_UNICAST_FLT in its priv_flags. This sets up the snapshot of
+ * rx_config that will be written to the device.
+ *
+ * void (*ndo_write_rx_config)(struct net_device *dev);
+ * This function is scheduled immediately after ndo_set_rx_mode to
+ * write rx_config to the device.
*
* int (*ndo_set_mac_address)(struct net_device *dev, void *addr);
* This function is called when the Media Access Control address
@@ -1421,6 +1426,7 @@ struct net_device_ops {
void (*ndo_change_rx_flags)(struct net_device *dev,
int flags);
void (*ndo_set_rx_mode)(struct net_device *dev);
+ void (*ndo_write_rx_config)(struct net_device *dev);
int (*ndo_set_mac_address)(struct net_device *dev,
void *addr);
int (*ndo_validate_addr)(struct net_device *dev);
@@ -1767,6 +1773,12 @@ enum netdev_reg_state {
NETREG_DUMMY, /* dummy device for NAPI poll */
};
+struct rx_config_work {
+ struct work_struct config_write;
+ struct net_device *dev;
+ spinlock_t config_lock;
+};
+
/**
* struct net_device - The DEVICE structure.
*
@@ -2082,6 +2094,8 @@ enum netdev_reg_state {
* dev_list, one per address-family.
* @hwprov: Tracks which PTP performs hardware packet time stamping.
*
+ * @rx_work: helper struct to schedule rx config write to the hardware.
+ *
* FIXME: cleanup struct net_device such that network protocol info
* moves out.
*/
@@ -2559,6 +2573,8 @@ struct net_device {
struct hwtstamp_provider __rcu *hwprov;
+ struct rx_config_work *rx_work;
+
u8 priv[] ____cacheline_aligned
__counted_by(priv_len);
} ____cacheline_aligned;
@@ -2734,6 +2750,26 @@ void dev_net_set(struct net_device *dev, struct net *net)
write_pnet(&dev->nd_net, net);
}
+#define update_snapshot(config_ptr, type) \
+ do { \
+ typeof((config_ptr)) rx_config = ((type *)(dev->priv))->rx_config; \
+ unsigned long flags; \
+ spin_lock_irqsave(&((dev)->rx_work->config_lock), flags); \
+ *rx_config = *(config_ptr); \
+ spin_unlock_irqrestore(&((dev)->rx_work->config_lock), flags); \
+ } while (0)
+
+#define read_snapshot(config_ptr, type) \
+ do { \
+ typeof((config_ptr)) rx_config = ((type *)(dev->priv))->rx_config; \
+ unsigned long flags; \
+ spin_lock_irqsave(&((dev)->rx_work->config_lock), flags); \
+ *(config_ptr) = *rx_config; \
+ spin_unlock_irqrestore(&((dev)->rx_work->config_lock), flags); \
+ } while (0)
+
+void set_and_schedule_rx_config(struct net_device *dev, bool flush);
+
/**
* netdev_priv - access network device private data
* @dev: network device
diff --git a/net/core/dev.c b/net/core/dev.c
index 2acfa44927da..2d3c6031e282 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -9524,6 +9524,38 @@ int netif_set_allmulti(struct net_device *dev, int inc, bool notify)
return 0;
}
+static void execute_write_rx_config(struct work_struct *param)
+{
+ struct rx_config_work *rx_work = container_of(param,
+ struct rx_config_work,
+ config_write);
+ struct net_device *dev = rx_work->dev;
+
+ // This path should not be hit outside the work item
+ WARN_ON(!dev->netdev_ops->ndo_write_rx_config);
+ dev->netdev_ops->ndo_write_rx_config(dev);
+}
+
+/*
+ * Sets up the rx_config snapshot and schedules write_rx_config. If
+ * it's necessary to wait for completion of write_rx_config, set
+ * flush to true.
+ */
+void set_and_schedule_rx_config(struct net_device *dev, bool flush)
+{
+ const struct net_device_ops *ops = dev->netdev_ops;
+
+ if (ops->ndo_set_rx_mode)
+ ops->ndo_set_rx_mode(dev);
+
+ if (ops->ndo_write_rx_config) {
+ schedule_work(&dev->rx_work->config_write);
+ if (flush)
+ flush_work(&dev->rx_work->config_write);
+ }
+}
+EXPORT_SYMBOL(set_and_schedule_rx_config);
+
/*
* Upload unicast and multicast address lists to device and
* configure RX filtering. When the device doesn't support unicast
@@ -9532,8 +9564,6 @@ int netif_set_allmulti(struct net_device *dev, int inc, bool notify)
*/
void __dev_set_rx_mode(struct net_device *dev)
{
- const struct net_device_ops *ops = dev->netdev_ops;
-
/* dev_open will call this function so the list will stay sane. */
if (!(dev->flags&IFF_UP))
return;
@@ -9554,8 +9584,7 @@ void __dev_set_rx_mode(struct net_device *dev)
}
}
- if (ops->ndo_set_rx_mode)
- ops->ndo_set_rx_mode(dev);
+ set_and_schedule_rx_config(dev, false);
}
void dev_set_rx_mode(struct net_device *dev)
@@ -11914,9 +11943,17 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
refcount_set(&dev->dev_refcnt, 1);
#endif
- if (dev_addr_init(dev))
+ dev->rx_work = kmalloc(sizeof(*dev->rx_work), GFP_KERNEL);
+ if (!dev->rx_work)
goto free_pcpu;
+ dev->rx_work->dev = dev;
+ spin_lock_init(&dev->rx_work->config_lock);
+ INIT_WORK(&dev->rx_work->config_write, execute_write_rx_config);
+
+ if (dev_addr_init(dev))
+ goto free_rx_work;
+
dev_mc_init(dev);
dev_uc_init(dev);
@@ -11998,6 +12035,10 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
free_netdev(dev);
return NULL;
+free_rx_work:
+ cancel_work_sync(&dev->rx_work->config_write);
+ kfree(dev->rx_work);
+
free_pcpu:
#ifdef CONFIG_PCPU_DEV_REFCNT
free_percpu(dev->pcpu_refcnt);
@@ -12083,6 +12124,9 @@ void free_netdev(struct net_device *dev)
return;
}
+ cancel_work_sync(&dev->rx_work->config_write);
+ kfree(dev->rx_work);
+
BUG_ON(dev->reg_state != NETREG_UNREGISTERED);
WRITE_ONCE(dev->reg_state, NETREG_RELEASED);
--
2.47.3
Powered by blists - more mailing lists