@@ -210,49 +210,55 @@ packets is preferred.
210
210
struct net_device synchronization rules
211
211
=======================================
212
212
ndo_open:
213
- Synchronization: rtnl_lock() semaphore.
213
+ Synchronization: rtnl_lock() semaphore. In addition, netdev instance
214
+ lock if the driver implements queue management or shaper API.
214
215
Context: process
215
216
216
217
ndo_stop:
217
- Synchronization: rtnl_lock() semaphore.
218
+ Synchronization: rtnl_lock() semaphore. In addition, netdev instance
219
+ lock if the driver implements queue management or shaper API.
218
220
Context: process
219
221
Note: netif_running() is guaranteed false
220
222
221
223
ndo_do_ioctl:
222
224
Synchronization: rtnl_lock() semaphore.
223
- Context: process
224
225
225
- This is only called by network subsystems internally,
226
- not by user space calling ioctl as it was in before
227
- linux-5.14.
226
+ This is only called by network subsystems internally,
227
+ not by user space calling ioctl as it was in before
228
+ linux-5.14.
228
229
229
230
ndo_siocbond:
230
- Synchronization: rtnl_lock() semaphore.
231
+ Synchronization: rtnl_lock() semaphore. In addition, netdev instance
232
+ lock if the driver implements queue management or shaper API.
231
233
Context: process
232
234
233
- Used by the bonding driver for the SIOCBOND family of
234
- ioctl commands.
235
+ Used by the bonding driver for the SIOCBOND family of
236
+ ioctl commands.
235
237
236
238
ndo_siocwandev:
237
- Synchronization: rtnl_lock() semaphore.
239
+ Synchronization: rtnl_lock() semaphore. In addition, netdev instance
240
+ lock if the driver implements queue management or shaper API.
238
241
Context: process
239
242
240
243
Used by the drivers/net/wan framework to handle
241
244
the SIOCWANDEV ioctl with the if_settings structure.
242
245
243
246
ndo_siocdevprivate:
244
- Synchronization: rtnl_lock() semaphore.
247
+ Synchronization: rtnl_lock() semaphore. In addition, netdev instance
248
+ lock if the driver implements queue management or shaper API.
245
249
Context: process
246
250
247
251
This is used to implement SIOCDEVPRIVATE ioctl helpers.
248
252
These should not be added to new drivers, so don't use.
249
253
250
254
ndo_eth_ioctl:
251
- Synchronization: rtnl_lock() semaphore.
255
+ Synchronization: rtnl_lock() semaphore. In addition, netdev instance
256
+ lock if the driver implements queue management or shaper API.
252
257
Context: process
253
258
254
259
ndo_get_stats:
255
- Synchronization: rtnl_lock() semaphore, or RCU.
260
+ Synchronization: RCU (can be called concurrently with the stats
261
+ update path).
256
262
Context: atomic (can't sleep under RCU)
257
263
258
264
ndo_start_xmit:
@@ -284,6 +290,10 @@ ndo_set_rx_mode:
284
290
Synchronization: netif_addr_lock spinlock.
285
291
Context: BHs disabled
286
292
293
+ Most ndo callbacks not specified in the list above are running
294
+ under ``rtnl_lock ``. In addition, netdev instance lock is taken as well if
295
+ the driver implements queue management or shaper API.
296
+
287
297
struct napi_struct synchronization rules
288
298
========================================
289
299
napi->poll:
@@ -298,6 +308,35 @@ napi->poll:
298
308
softirq
299
309
will be called with interrupts disabled by netconsole.
300
310
311
+ struct netdev_queue_mgmt_ops synchronization rules
312
+ ==================================================
313
+
314
+ All queue management ndo callbacks are holding netdev instance lock.
315
+
316
+ RTNL and netdev instance lock
317
+ =============================
318
+
319
+ Historically, all networking control operations were protected by a single
320
+ global lock known as ``rtnl_lock ``. There is an ongoing effort to replace this
321
+ global lock with separate locks for each network namespace. Additionally,
322
+ properties of individual netdev are increasingly protected by per-netdev locks.
323
+
324
+ For device drivers that implement shaping or queue management APIs, all control
325
+ operations will be performed under the netdev instance lock. Currently, this
326
+ instance lock is acquired within the context of ``rtnl_lock ``. The drivers
327
+ can also explicitly request instance lock to be acquired via
328
+ ``request_ops_lock ``. In the future, there will be an option for individual
329
+ drivers to opt out of using ``rtnl_lock `` and instead perform their control
330
+ operations directly under the netdev instance lock.
331
+
332
+ Devices drivers are encouraged to rely on the instance lock where possible.
333
+
334
+ For the (mostly software) drivers that need to interact with the core stack,
335
+ there are two sets of interfaces: ``dev_xxx `` and ``netif_xxx `` (e.g.,
336
+ ``dev_set_mtu `` and ``netif_set_mtu ``). The ``dev_xxx `` functions handle
337
+ acquiring the instance lock themselves, while the ``netif_xxx `` functions
338
+ assume that the driver has already acquired the instance lock.
339
+
301
340
NETDEV_INTERNAL symbol namespace
302
341
================================
303
342
0 commit comments