🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #19466

Re: [PATCH net-next 2/4] tap: add a mutex to protect queue management

#19466
From: Willem de Bruijn
Date: Thu, 19 Nov 2026 23:49
61 lines
13726 bytes
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.
Technical Details
Message-ID: <willemdebruijn.kernel.320d89ebe1495@gmail.com>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367425-linux-kernel-netdev=dewy.ru
References: <20261119072258.3157902-1-edumazet@kernel.org> <20261119072258.3157902-3-edumazet@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-367425-linux-kernel-netdev=dewy.ru
From: willemdebruijn.kernel@gmail.com (Willem de Bruijn)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next 2/4] tap: add a mutex to protect queue management
Date: Thu, 19 Nov 2026 18:49:46 -0500
Organization: Usenet Network
Message-ID: <willemdebruijn.kernel.320d89ebe1495@gmail.com>
References: <20261119072258.3157902-1-edumazet@kernel.org>
 <20261119072258.3157902-3-edumazet@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain;
 charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="3013401"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:socOZvbk34xCYxLrooeD6rFqWpQ= sha256:DZkDsg5GN8nx2FQNDYyRGYh4M0sHnqpLxdu0nq7PSrI=
	sha1:J87SJmw9T68TAsvHK1q755pm0og= sha256:TdKMtqQleQ8F4m98ab9yrh1J0U+m8xpI1WGDRZP0WA8=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 3B5711157FF; Fri, 20 Nov 2026 02:50:04 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id CR_hXvH2rA-H;
	Fri, 20 Nov 2026 02:50:01 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-367425-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id DAABF115806; Fri, 20 Nov 2026 02:49:52 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 6E1B0107C48; Thu, 19 Nov 2026 23:49:50 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795132190;
	b=lUqYKnrdprZNmMpDMa9syo93zDyZc/MbC+iPn4gRyVIkCAyozfUoL6eO9U2vaa47jx33
	 ZQmmFFxr6y//j/8TBRmPPfc24IdLqV2prhW33ejsfq3UTWeTKjtqwxMmvz1teoDLons/w
	 fLxKDTEg3p/OmOgRVKeRSEUjwNa85QrDO7oKnd8cupgsf7zrNT9qcESFZrN8oZ3S5Ew4C
	 n4Wsv0n/OV/kWbJQkp2xyXbDQ7f8TWyDAlzIQX+TH3x4ISI3anI7rScYHBS48kNP7aGAl
	 y8GRUIzwUFwb0DNSAgpF8VxSwwjv/oMqAIlEqqACQpqdnP0G6x8MVl5H5ksfCsMy1FA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795132190;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
	 X-Gm-Gg:X-Received:Received:Date:From:To:Cc:Message-ID:In-Reply-To:
	 References:Subject:X-Mailing-List:List-Id:List-Post:List-Help:
	 List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Type:Content-Transfer-Encoding;
	bh=8pxF1XjPmydG2nmBhgUZ39yA7PK/1cXjwAWpQkhvRAQ=;
	b=DFyKUBbHNL3L8r5FcteFqY/4+H+HZ4cKjeUiMiwLyWVO+sQSHZ3NadTIVgyfpki86gem
	 rCnxKiDJwDeRm6hZrpjSIiDXCx9Kc9ZHOS3ItDCwFChjPB+ysfG/b23Sc9teLmeGRvgHT
	 /CTnW7pBsDdGGmMeZYb2vbq75ZNdnE7f4WjvFs8KKAjkiFrig27xTJZjL14+Zjf0uCnmv
	 fiBgO/YHjhvZmS4RJW8stT54+pKpECc4dTXXWmX7iUHWBW55yZeDpFoAsQAo6b2SlWx9l
	 Jvdz5mc2eAdfkeHw00Fr7WQg9Cou9u1bwur/KZTrD2q9kYRJAnKrkg8iMcQkvuJK0dg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=WjRmHavG;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 34092606A32A;
	Thu, 19 Nov 2026 23:49:50 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=WjRmHavG
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.217.46
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795132189;
	b=e5kbte2okTmsnpZq9Jbdf1lPMGqAdPy7l0IMi+8QwusP8JXC77WXUGQaieYZHSA7FO2u
	 lAY8+/TiPJJDBZ/AxCZ88rI30s5VoIvtmJMLWEi/awFdCJEMxq+FOt4580AQNMpLbaMRo
	 Pa+VmOec162yrqoir2QPXUdUEeQG4LyFIPxjkvDq9ft9quSXBtZTUUP6VwkypivIWrDur
	 8hkqGaxZaEC5iGZHk1D+NxhOuIn1Wxb/NYkLHVSUIm9hFSocIe+86u3dFItUDTm/+MYyh
	 sK+gWR8XNO1oLytFY24zUKbJja7dmqjG4BGRZJXNdAF4eC7t0KS03GVvd9s0O5WvjEw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795132189;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
	 Date:From:To:Cc:Message-ID:In-Reply-To:References:Subject:
	 MIME-Version:Content-Type:Content-Transfer-Encoding;
	bh=8pxF1XjPmydG2nmBhgUZ39yA7PK/1cXjwAWpQkhvRAQ=;
	b=dWyNNCtnfVzQBq30XnyJR0WnDPPlPZvwAW6eKCmHz/sGPeHJ1Y9B1RlGlHEqPA38xaos
	 2CqCw8PrulMyMceI81qrtJ2VtuyND4LiCsJAxZryYG5b/OhuaaeXqClMzR5DkVq+PM3nE
	 RLXGFcWJogqe/H90ccV46sgfLzyWeiGqepXwbenw0pSM5t37iqWv6yxBIxS8/SuCXk2DY
	 LMnLMgLMY8dMEkC94z8eHXnfvYu79HIBc8ixTnNnZ9YljQ2JI2VQ956soVadD3Yc8U3J9
	 2baVlIBaBxfadD8qrGxSyAICh4uolxuPuggWTvipCBfGVPasw9O+HIbtR/q2Fb5DgFg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=WjRmHavG;
	arc=none smtp.remote-ip=209.85.217.46
X-Received: from mail-vs1-f46.google.com (mail-vs1-f46.google.com [209.85.217.46])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id ECD57606A320
	for <netdev@vger.kernel.org>; Thu, 19 Nov 2026 23:49:48 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org ECD57606A320
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-vs1-f46.google.com with SMTP id ada2fe7eead31-77bf892b496so126584137.0
        for <netdev@vger.kernel.org>; Thu, 19 Nov 2026 15:49:48 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1795132188; x=1795736988; darn=vger.kernel.org;
        h=content-transfer-encoding:content-type:mime-version:subject
         :references:in-reply-to:message-id:cc:to:from:date:from:to:cc
         :subject:date:message-id:reply-to:content-type;
        bh=8pxF1XjPmydG2nmBhgUZ39yA7PK/1cXjwAWpQkhvRAQ=;
        b=WjRmHavGc1axqWZ/NY0RuQD48lhYaCkSwdQqA2C5NLcw4M4NlhxBwnCfqcRS6+ddzM
         0fLFbVfOrjyIIyBbdPLCVG1fL9wToVC9/zJZf+DEKVBbwbsFBL+OUPnrfFSV0tfGX0NL
         EpHq6kKsFPohP6yjEYQh2q28tyqBBesVy72WbOHBy3t+CehEKmBq+tiZXHU5Ga1pOcnH
         suRePIAOIrvoWPiAx/3cLtPHECgr7AioI0DsXLD9IfFFi+4i9QV6d3girZeBhyNIPFFk
         8hoaCl8d0H7iatKCkw1b/mMuIj6WEVAy8qPRb4Pa9k/d2nDUi6HeMsCDGTGHxEkE4MyJ
         BETw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1795132188; x=1795736988;
        h=content-transfer-encoding:content-type:mime-version:subject
         :references:in-reply-to:message-id:cc:to:from:date:x-gm-gg
         :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
         :content-type;
        bh=8pxF1XjPmydG2nmBhgUZ39yA7PK/1cXjwAWpQkhvRAQ=;
        b=iqQ/t8egIBk3NqwG3mr5QgkN1j0ZMA/SD6+PzuWWgoXcSgal+lFdBvW0UdKqd3R9dK
         JMi4e9G5XAPhI+Oa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wb0gZLtG5o3bk+Us059sIYkep+cnJDMVX/Ikrlhfdro/4NJnymyHKa2
	K/vwtdhEXFaS3ZeBES8nGL3kpRQilFXrYH39+sLA4x2xLCGFH/jK5/FVr6QZhh8+Xg+bHbdVOoG
	76dI8E4NGhDkTK3rOU0+fhgoQL/t9RPEojRUXaNt8UPdsRHbxj+DmjX2lIv2l33A=
X-Received: by 2002:a05:6102:41a3:b0:7d2:754c:23e7 with SMTP id ada2fe7eead31-7d7396d1b09mr430676137.35.1795132187626;
        Thu, 19 Nov 2026 15:49:47 -0800 (PST)
X-Received: from gmail.com (15.60.86.34.bc.googleusercontent.com. [34.86.60.15])
        by smtp.gmail.com with ESMTPSA id a1e0cc1a2514c-99e6e0686b1sm1376086241.10.2026.11.19.15.49.47
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Thu, 19 Nov 2026 15:49:47 -0800 (PST)
X-Cc: Kuniyuki Iwashima <kuniyu@google.com>, 
 Simon Horman <horms@kernel.org>, 
 netdev@vger.kernel.org, 
 Eric Dumazet <edumazet@kernel.org>
X-In-Reply-To: <20261119072258.3157902-3-edumazet@kernel.org>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list