Skip to content

Commit 4b702f8

Browse files
committed
net: explain "protection types" for the instance lock
Try to define some terminology for which fields are protected by which lock and how. Some fields are protected by both rtnl_lock and instance lock which is hard to talk about without having a "key phrase" to refer to a particular protection scheme. "ops protected" fields are defined later in the series, one by one. Add ASSERT_RTNL() to netdev_ops_assert_locked() for drivers not other instance protection of ops. Hopefully it's not too confusion that netdev_lock_ops() does not match the lock which netdev_ops_assert_locked() will assert, exactly. The noun "ops" is in a different place in the name, so I think it's acceptable... Acked-by: Stanislav Fomichev <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent e2f81e8 commit 4b702f8

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

include/linux/netdevice.h

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2496,19 +2496,35 @@ struct net_device {
24962496
* Should always be taken using netdev_lock() / netdev_unlock() helpers.
24972497
* Drivers are free to use it for other protection.
24982498
*
2499-
* Protects:
2499+
* For the drivers that implement shaper or queue API, the scope
2500+
* of this lock is expanded to cover most ndo/queue/ethtool/sysfs
2501+
* operations. Drivers may opt-in to this behavior by setting
2502+
* @request_ops_lock.
2503+
*
2504+
* @lock protection mixes with rtnl_lock in multiple ways, fields are
2505+
* either:
2506+
*
2507+
* - simply protected by the instance @lock;
2508+
*
2509+
* - double protected - writers hold both locks, readers hold either;
2510+
*
2511+
* - ops protected - protected by the lock held around the NDOs
2512+
* and other callbacks, that is the instance lock on devices for
2513+
* which netdev_need_ops_lock() returns true, otherwise by rtnl_lock;
2514+
*
2515+
* - double ops protected - always protected by rtnl_lock but for
2516+
* devices for which netdev_need_ops_lock() returns true - also
2517+
* the instance lock.
2518+
*
2519+
* Simply protects:
25002520
* @gro_flush_timeout, @napi_defer_hard_irqs, @napi_list,
25012521
* @net_shaper_hierarchy, @reg_state, @threaded
25022522
*
2503-
* Partially protects (writers must hold both @lock and rtnl_lock):
2523+
* Double protects:
25042524
* @up
25052525
*
25062526
* Also protects some fields in struct napi_struct.
25072527
*
2508-
* For the drivers that implement shaper or queue API, the scope
2509-
* of this lock is expanded to cover most ndo/queue/ethtool/sysfs
2510-
* operations.
2511-
*
25122528
* Ordering: take after rtnl_lock.
25132529
*/
25142530
struct mutex lock;

include/net/netdev_lock.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <linux/lockdep.h>
77
#include <linux/netdevice.h>
8+
#include <linux/rtnetlink.h>
89

910
static inline bool netdev_trylock(struct net_device *dev)
1011
{
@@ -51,6 +52,8 @@ static inline void netdev_ops_assert_locked(const struct net_device *dev)
5152
{
5253
if (netdev_need_ops_lock(dev))
5354
lockdep_assert_held(&dev->lock);
55+
else
56+
ASSERT_RTNL();
5457
}
5558

5659
static inline int netdev_lock_cmp_fn(const struct lockdep_map *a,

0 commit comments

Comments
 (0)