Locking
We saw in the section "Organization of net_device Structures" that
the dev_base list and the two hash tables dev_name_head and dev_name_index are protected by the dev_base_list lock. That lock, however, is used only to serialize accesses to
the list and tables, not to serialize changes to the contents of net_device data structures. net_device
content changes are taken care of by the Routing Netlink semaphore (rtnl_sem), which is acquired and released with rtnl_lock and rtnl_unlock,
respectively.[*] This semaphore is used to serialize changes to net_device instances from:
- Runtime events
For example, when the link state changes (e.g., a network cable is plugged or unplugged), the kernel needs to change the device state by modifying
dev->flags.- Configuration changes
When the user applies a configuration change with commands such as ifconfig and route from the net-tools package, or ip from the IPROUTE2 package, the kernel is notified via
ioctlcommands and the Netlink socket, respectively. The routines invoked via these interfaces must use locks.
The net_device data structure includes a few fields
used for locking, among them:
-
ingress_lock -
queue_lock Used by Traffic Control when dealing with ingress and egress traffic scheduling, respectively.
-
xmit_lock -
xmit_lock_owner Used to synchronize accesses to the device driver
hard_start_xmitfunction.
For more details on these locks, please refer to Chapter 11.
[*] Other routines can also be used to acquire and release the semaphore. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access