From: Stanislav Fomichev <sdf@fomichev.me>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, Saeed Mahameed <saeed@kernel.org>
Subject: [PATCH net-next v8 11/12] docs: net: document new locking reality
Date: Wed, 26 Feb 2025 13:11:07 -0800 [thread overview]
Message-ID: <20250226211108.387727-12-sdf@fomichev.me> (raw)
In-Reply-To: <20250226211108.387727-1-sdf@fomichev.me>
Also clarify ndo_get_stats (that read and write paths can run
concurrently) and mention only RCU.
Cc: Saeed Mahameed <saeed@kernel.org>
Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
---
Documentation/networking/netdevices.rst | 65 ++++++++++++++++++++-----
include/linux/netdevice.h | 4 ++
2 files changed, 56 insertions(+), 13 deletions(-)
diff --git a/Documentation/networking/netdevices.rst b/Documentation/networking/netdevices.rst
index 1d37038e9fbe..d235a7364893 100644
--- a/Documentation/networking/netdevices.rst
+++ b/Documentation/networking/netdevices.rst
@@ -210,49 +210,55 @@ packets is preferred.
struct net_device synchronization rules
=======================================
ndo_open:
- Synchronization: rtnl_lock() semaphore.
+ Synchronization: rtnl_lock() semaphore. In addition, netdev instance
+ lock if the driver implements queue management or shaper API.
Context: process
ndo_stop:
- Synchronization: rtnl_lock() semaphore.
+ Synchronization: rtnl_lock() semaphore. In addition, netdev instance
+ lock if the driver implements queue management or shaper API.
Context: process
Note: netif_running() is guaranteed false
ndo_do_ioctl:
Synchronization: rtnl_lock() semaphore.
- Context: process
- This is only called by network subsystems internally,
- not by user space calling ioctl as it was in before
- linux-5.14.
+ This is only called by network subsystems internally,
+ not by user space calling ioctl as it was in before
+ linux-5.14.
ndo_siocbond:
- Synchronization: rtnl_lock() semaphore.
+ Synchronization: rtnl_lock() semaphore. In addition, netdev instance
+ lock if the driver implements queue management or shaper API.
Context: process
- Used by the bonding driver for the SIOCBOND family of
- ioctl commands.
+ Used by the bonding driver for the SIOCBOND family of
+ ioctl commands.
ndo_siocwandev:
- Synchronization: rtnl_lock() semaphore.
+ Synchronization: rtnl_lock() semaphore. In addition, netdev instance
+ lock if the driver implements queue management or shaper API.
Context: process
Used by the drivers/net/wan framework to handle
the SIOCWANDEV ioctl with the if_settings structure.
ndo_siocdevprivate:
- Synchronization: rtnl_lock() semaphore.
+ Synchronization: rtnl_lock() semaphore. In addition, netdev instance
+ lock if the driver implements queue management or shaper API.
Context: process
This is used to implement SIOCDEVPRIVATE ioctl helpers.
These should not be added to new drivers, so don't use.
ndo_eth_ioctl:
- Synchronization: rtnl_lock() semaphore.
+ Synchronization: rtnl_lock() semaphore. In addition, netdev instance
+ lock if the driver implements queue management or shaper API.
Context: process
ndo_get_stats:
- Synchronization: rtnl_lock() semaphore, or RCU.
+ Synchronization: RCU (can be called concurrently with the stats
+ update path).
Context: atomic (can't sleep under RCU)
ndo_start_xmit:
@@ -284,6 +290,10 @@ struct net_device synchronization rules
Synchronization: netif_addr_lock spinlock.
Context: BHs disabled
+Most ndo callbacks not specified in the list above are running
+under ``rtnl_lock``. In addition, netdev instance lock is taken as well if
+the driver implements queue management or shaper API.
+
struct napi_struct synchronization rules
========================================
napi->poll:
@@ -298,6 +308,35 @@ struct napi_struct synchronization rules
softirq
will be called with interrupts disabled by netconsole.
+struct netdev_queue_mgmt_ops synchronization rules
+==================================================
+
+All queue management ndo callbacks are holding netdev instance lock.
+
+RTNL and netdev instance lock
+=============================
+
+Historically, all networking control operations were protected by a single
+global lock known as ``rtnl_lock``. There is an ongoing effort to replace this
+global lock with separate locks for each network namespace. Additionally,
+properties of individual netdev are increasingly protected by per-netdev locks.
+
+For device drivers that implement shaping or queue management APIs, all control
+operations will be performed under the netdev instance lock. Currently, this
+instance lock is acquired within the context of ``rtnl_lock``. The drivers
+can also explicitly request instance lock to be acquired via
+``request_ops_lock``. In the future, there will be an option for individual
+drivers to opt out of using ``rtnl_lock`` and instead perform their control
+operations directly under the netdev instance lock.
+
+Devices drivers are encouraged to rely on the instance lock where possible.
+
+For the (mostly software) drivers that need to interact with the core stack,
+there are two sets of interfaces: ``dev_xxx`` and ``netif_xxx`` (e.g.,
+``dev_set_mtu`` and ``netif_set_mtu``). The ``dev_xxx`` functions handle
+acquiring the instance lock themselves, while the ``netif_xxx`` functions
+assume that the driver has already acquired the instance lock.
+
NETDEV_INTERNAL symbol namespace
================================
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 29f61bd0ddf1..59bbe189d542 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2476,6 +2476,10 @@ struct net_device {
*
* Also protects some fields in struct napi_struct.
*
+ * For the drivers that implement shaper or queue API, the scope
+ * of this lock is expanded to cover most ndo/queue/ethtool/sysfs
+ * operations.
+ *
* Ordering: take after rtnl_lock.
*/
struct mutex lock;
--
2.48.1
next prev parent reply other threads:[~2025-02-26 21:11 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-26 21:10 [PATCH net-next v8 00/12] net: Hold netdev instance lock during ndo operations Stanislav Fomichev
2025-02-26 21:10 ` [PATCH net-next v8 01/12] net: hold netdev instance lock during ndo_open/ndo_stop Stanislav Fomichev
2025-02-26 21:10 ` [PATCH net-next v8 02/12] net: hold netdev instance lock during ndo_setup_tc Stanislav Fomichev
2025-02-26 21:10 ` [PATCH net-next v8 03/12] net: hold netdev instance lock during queue operations Stanislav Fomichev
2025-02-26 21:11 ` [PATCH net-next v8 04/12] net: hold netdev instance lock during rtnetlink operations Stanislav Fomichev
2025-02-26 21:11 ` [PATCH net-next v8 05/12] net: hold netdev instance lock during ioctl operations Stanislav Fomichev
2025-02-26 21:11 ` [PATCH net-next v8 06/12] net: hold netdev instance lock during sysfs operations Stanislav Fomichev
2025-02-26 21:11 ` [PATCH net-next v8 07/12] net: hold netdev instance lock during ndo_bpf Stanislav Fomichev
2025-02-26 21:11 ` [PATCH net-next v8 08/12] net: ethtool: try to protect all callback with netdev instance lock Stanislav Fomichev
2025-02-27 8:48 ` Maxime Chevallier
2025-02-27 22:40 ` Stanislav Fomichev
2025-02-26 21:11 ` [PATCH net-next v8 09/12] net: replace dev_addr_sem " Stanislav Fomichev
2025-02-26 21:11 ` [PATCH net-next v8 10/12] net: add option to request " Stanislav Fomichev
2025-02-26 21:11 ` Stanislav Fomichev [this message]
2025-02-26 21:11 ` [PATCH net-next v8 12/12] eth: bnxt: remove most dependencies on RTNL Stanislav Fomichev
2025-02-28 1:27 ` [PATCH net-next v8 00/12] net: Hold netdev instance lock during ndo operations Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250226211108.387727-12-sdf@fomichev.me \
--to=sdf@fomichev.me \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=saeed@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox