Skip to content

tap: do not hold RTNL in open(), release() and queue ioctls

Eric Dumazet netdev 1 version Applied

Status from this message: This series was applied to netdev/net-next.git (main)

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest4 patches 3 repliesApplied 4/4

Patches in v1 All 4 applied

#Subject and filesSizeRepliesApplied
1/4tap: detach queues from the NETDEV_UNREGISTER notifierdrivers/net/ipvlan/ipvtap.c drivers/net/macvtap.c drivers/net/tap.c +1 more+16 -71 replyApplied
2/4tap: add a mutex to protect queue managementdrivers/net/ipvlan/ipvtap.c drivers/net/macvlan.c drivers/net/macvtap.c +3 more+87 -331 replyApplied
3/4tap: do not hold RTNL in open(), release() and queue ioctlsdrivers/net/tap.c net/core/dev.c+60 -310 repliesApplied
4/4tap: remove tap_get_tap_dev() and tap_put_tap_dev()drivers/net/tap.c+2 -211 replyApplied

Reviews trailers per patch

3 of 4 patches have a Reviewed-by or Acked-by.

PatchWillem de Bruijn
1/4R-b
2/4R-b
3/4
4/4R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH net-next 0/4] tap: do not hold RTNL in open(), release() and queue ioctls

Opening or closing a macvtap/ipvtap char device acquires RTNL, as do the TUNSETQUEUE and TUNGETIFF ioctls, although they only manipulate the list of queues attached to the device, which is private to tap. Hosts starting and stopping many virtual machines thus add contention on RTNL for no good reason.

This series protects the queue list with a per-device mutex, and stops taking RTNL in these four paths.

Patch 1 makes sure tap_del_queues() is called for every unregistered device, and that no queue can be attached afterwards. Both properties are currently provided by RTNL being held in tap_open().

Patch 2 adds tap->lock and takes it wherever the queue list is used, still under RTNL.

Patch 3 removes RTNL from open(), release(), TUNSETQUEUE and TUNGETIFF.

Patch 4 removes a device reference that is not needed by the ioctls still running under RTNL.

TUNSETOFFLOAD, SIOCGIFHWADDR and SIOCSIFHWADDR still take RTNL, since they call into the core stack. The datapath is unchanged.

Testing: selftests net/tap and net/ipvtap_test.sh pass. A test program (not part of this series) checking the queue limit, attach/detach, txqueuelen change, rename, netns move and device or lower device removal with open queues gives the same results before and after the series. The same program was used to run open/ioctl/read/write/close loops against concurrent link add/del/rename/netns moves for macvtap and ipvtap, on a kernel with lockdep, PROVE_RCU and KASAN enabled, without any splat. No test was done with vhost-net or real VM.

Eric Dumazet (4):
tap: detach queues from the NETDEV_UNREGISTER notifier
tap: add a mutex to protect queue management
tap: do not hold RTNL in open(), release() and queue ioctls
tap: remove tap_get_tap_dev() and tap_put_tap_dev()

 drivers/net/ipvlan/ipvtap.c |  23 ++++--
 drivers/net/macvlan.c       |   3 +-
 drivers/net/macvtap.c       |  24 ++++--
 drivers/net/tap.c           | 184 ++++++++++++++++++++++++++------------------
 include/linux/if_macvlan.h  |   2 +
 include/linux/if_tap.h      |  12 +++
 net/core/dev.c              |   1 +
 7 files changed, 161 insertions(+), 88 deletions(-)

base-commit: 66726ba54a01a2951688a56f5eb4d13d063acbea

Signature · 1 line
2.53.0