[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251020134857.5820-2-viswanathiyyappan@gmail.com>
Date: Mon, 20 Oct 2025 19:18:56 +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,
andrew+netdev@...n.ch
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 net-next PATCH 1/2] net: Add ndo_write_rx_config and helper structs and functions.
Add ndo_write_rx_config callback and following 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>
---
I expect that shallow copy should be good enough as rx_config should consist exclusively
of integer types (primitives and arrays)
Would flushing the work queue be necessary for functions like *_init_hw()?
include/linux/netdevice.h | 38 ++++++++++++++++++++++++++++++-
net/core/dev.c | 48 +++++++++++++++++++++++++++++++++++----
2 files changed, 81 insertions(+), 5 deletions(-)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index d1a687444b27..37a48e41a004 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..24eeaec5881b 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -9524,6 +9524,37 @@ 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);
+ }
+}
+
/*
* Upload unicast and multicast address lists to device and
* configure RX filtering. When the device doesn't support unicast
@@ -9532,8 +9563,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 +9583,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)
@@ -11946,6 +11974,15 @@ struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,
INIT_LIST_HEAD(&dev->ptype_all);
INIT_LIST_HEAD(&dev->ptype_specific);
INIT_LIST_HEAD(&dev->net_notifier_list);
+
+ dev->rx_work = kmalloc(sizeof(*dev->rx_work), GFP_KERNEL);
+ if (!dev->rx_work)
+ goto free_all;
+
+ dev->rx_work->dev = dev;
+ spin_lock_init(&dev->rx_work->config_lock);
+ INIT_WORK(&dev->rx_work->config_write, execute_write_rx_config);
+
#ifdef CONFIG_NET_SCHED
hash_init(dev->qdisc_hash);
#endif
@@ -12083,6 +12120,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