Skip to content

Commit 310ae9e

Browse files
committed
net: designate queue -> napi linking as "ops protected"
netdev netlink is the only reader of netdev_{,rx_}queue->napi, and it already holds netdev->lock. Switch protection of the writes to netdev->lock to "ops protected". The expectation will be now that accessing queue->napi will require netdev->lock for "ops locked" drivers, and rtnl_lock for all other drivers. Current "ops locked" drivers don't require any changes. gve and netdevsim use _locked() helpers right next to netif_queue_set_napi() so they must be holding the instance lock. iavf doesn't call it. bnxt is a bit messy but all paths seem locked. Acked-by: Stanislav Fomichev <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 0a65dcf commit 310ae9e

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

include/linux/netdevice.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ struct netdev_queue {
710710
* slow- / control-path part
711711
*/
712712
/* NAPI instance for the queue
713-
* Readers and writers must hold RTNL
713+
* "ops protected", see comment about net_device::lock
714714
*/
715715
struct napi_struct *napi;
716716

@@ -2526,7 +2526,8 @@ struct net_device {
25262526
* Double ops protects:
25272527
* @real_num_rx_queues, @real_num_tx_queues
25282528
*
2529-
* Also protects some fields in struct napi_struct.
2529+
* Also protects some fields in:
2530+
* struct napi_struct, struct netdev_queue, struct netdev_rx_queue
25302531
*
25312532
* Ordering: take after rtnl_lock.
25322533
*/

include/net/netdev_lock.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ static inline void netdev_ops_assert_locked(const struct net_device *dev)
5656
ASSERT_RTNL();
5757
}
5858

59+
static inline void
60+
netdev_ops_assert_locked_or_invisible(const struct net_device *dev)
61+
{
62+
if (dev->reg_state == NETREG_REGISTERED ||
63+
dev->reg_state == NETREG_UNREGISTERING)
64+
netdev_ops_assert_locked(dev);
65+
}
66+
5967
static inline int netdev_lock_cmp_fn(const struct lockdep_map *a,
6068
const struct lockdep_map *b)
6169
{

include/net/netdev_rx_queue.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct netdev_rx_queue {
2424
struct xsk_buff_pool *pool;
2525
#endif
2626
/* NAPI instance for the queue
27-
* Readers and writers must hold RTNL
27+
* "ops protected", see comment about net_device::lock
2828
*/
2929
struct napi_struct *napi;
3030
struct pp_memory_provider_params mp_params;

net/core/dev.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6901,8 +6901,7 @@ void netif_queue_set_napi(struct net_device *dev, unsigned int queue_index,
69016901

69026902
if (WARN_ON_ONCE(napi && !napi->dev))
69036903
return;
6904-
if (dev->reg_state >= NETREG_REGISTERED)
6905-
ASSERT_RTNL();
6904+
netdev_ops_assert_locked_or_invisible(dev);
69066905

69076906
switch (type) {
69086907
case NETDEV_QUEUE_TYPE_RX:

0 commit comments

Comments
 (0)