All of lore.kernel.org
 help / color / mirror / Atom feed
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Eric Dumazet <edumazet@kernel.org>,
	 "David S . Miller" <davem@davemloft.net>,
	 Jakub Kicinski <kuba@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>,
	 Willem de Bruijn <willemb@google.com>
Cc: Kuniyuki Iwashima <kuniyu@google.com>,
	 Simon Horman <horms@kernel.org>,
	 netdev@vger.kernel.org,  Eric Dumazet <edumazet@kernel.org>
Subject: Re: [PATCH net-next 2/4] tap: add a mutex to protect queue management
Date: Thu, 19 Nov 2026 18:49:46 -0500	[thread overview]
Message-ID: <willemdebruijn.kernel.320d89ebe1495@gmail.com> (raw)
In-Reply-To: <20261119072258.3157902-3-edumazet@kernel.org>

Eric Dumazet wrote:
> The list of queues attached to a tap device (tap->taps[],
> tap->queue_list, tap->numvtaps, tap->numqueues) and the back pointer
> from each queue (q->tap, q->enabled, q->queue_index) are all private
> to tap, but are protected by RTNL.
> 
> Add tap->lock, a per-device mutex nesting inside RTNL, and hold it in
> every function reading or changing this state: tap_open(),
> tap_put_queue(), the TUNSETQUEUE ioctl, tap_del_queues() and
> tap_queue_resize(). A mutex is needed because tap_open() and
> tap_queue_resize() allocate ptr_ring storage with GFP_KERNEL.
> 
> Add tap->ring_size, the ptr_ring size shared by all the queues of a
> device. It is updated under the mutex when tap_queue_resize() succeeds
> and is used by tap_open() instead of dev->tx_queue_len. Once RTNL is
> gone, tap_open() can thus not size a new ring from a tx_queue_len
> which is being changed, or rolled back by netif_change_tx_queue_len()
> after a failure.
> 
> tap_handle_frame() reads tap->numvtaps locklessly, add the missing
> WRITE_ONCE() annotations while touching these lines.
> 
> The mutex is initialized in the macvtap and ipvtap ->setup() handlers
> and destroyed from dev->priv_destructor, once all references to the
> device are gone. macvtap has to chain to the macvlan destructor,
> export macvlan_dev_free() for this purpose.
> 
> Set tap->dev before the netdevice is registered instead of after,
> since the char device can be opened as soon as the NETDEV_REGISTER
> notifier has run. Like the mutex itself this has no effect yet: RTNL
> is still held by all callers, and is removed from the paths that do
> not need it in the following patch.
> 
> Signed-off-by: Eric Dumazet <edumazet@kernel.org>

Reviewed-by: Willem de Bruijn <willemb@google.com>

> diff --git a/include/linux/if_tap.h b/include/linux/if_tap.h
> index e9c4c9272585cdb14cf0ea7ea7d96acc3e8964b7..f2507fd41b9c9bf37687d17d06a2a9821b934b50 100644
> --- a/include/linux/if_tap.h
> +++ b/include/linux/if_tap.h
> @@ -35,12 +35,22 @@ struct tap_queue;
>  struct tap_dev {
>  	struct net_device	*dev;
>  	u16			flags;
> +	/* Protects taps[], queue_list, numvtaps, numqueues, ring_size, dead,
> +	 * and the tap, enabled and queue_index fields of the attached queues.
> +	 * Nests inside RTNL.
> +	 */
> +	struct mutex		lock;

It's very helpful that the exact fields guarded by the lock are explicitly
listed.

(not a blocker) could this use even more mechanically verifiable
instrumentation, such as __guarded_by field annotations and __must_hold
for helper functions that access these fields?

It is not possible for every such example, as e.g., lockless READ_ONCE
numvtaps.

  reply	other threads:[~2026-11-19 23:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  7:22 [PATCH net-next 0/4] tap: do not hold RTNL in open(), release() and queue ioctls Eric Dumazet
2026-11-19  7:22 ` [PATCH net-next 1/4] tap: detach queues from the NETDEV_UNREGISTER notifier Eric Dumazet
2026-11-19 23:46   ` Willem de Bruijn
2026-11-19  7:22 ` [PATCH net-next 2/4] tap: add a mutex to protect queue management Eric Dumazet
2026-11-19 23:49   ` Willem de Bruijn [this message]
2026-11-19  7:22 ` [PATCH net-next 3/4] tap: do not hold RTNL in open(), release() and queue ioctls Eric Dumazet
2026-11-19  7:22 ` [PATCH net-next 4/4] tap: remove tap_get_tap_dev() and tap_put_tap_dev() Eric Dumazet
2026-11-20  0:03   ` Willem de Bruijn

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=willemdebruijn.kernel.320d89ebe1495@gmail.com \
    --to=willemdebruijn.kernel@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.