From nobody Mon Feb 9 17:35:37 2026 Received: from unimail.uni-dortmund.de (mx1.hrz.uni-dortmund.de [129.217.128.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B44EA33AD89; Wed, 7 Jan 2026 21:06:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=129.217.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767819978; cv=none; b=pXoXvv00gn63sNnXIIRq/xYfdoFP45VU+0+Bb7VxEj0QWktctpgTeS3m9dFpmVMTilFRi/jfHTz+RbBkOb4ZmAdbr1Ifj5E3mCluzvkLkXKMgzeFzhLV2wAXdtodl9m8kidipbzgcjoAJGoBWcvlrwMOKWtdIfiR5+ArlhHO+ps= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767819978; c=relaxed/simple; bh=5XhV857b4Zt0CASKZBxygyRwR2i/i6QOZmWNbvIntIQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RAX+2aFhkWg0/4RK0yWAwJdqAM4FZA1Ms1aXJ017a0G/JwsVzuJL/kcy0jGXQL1dSFqruZYQi+1AfRDLQUgqiyKHYf8zcbvh2RCczVK7dKOEwgNqKNg8SEaM1WBrYiROOku89Suvy7TyLEdHd/Q9HqhOxSnJ8cTzg/6YbVqEuCQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=tu-dortmund.de; spf=pass smtp.mailfrom=tu-dortmund.de; dkim=pass (1024-bit key) header.d=tu-dortmund.de header.i=@tu-dortmund.de header.b=Zlxs0MP0; arc=none smtp.client-ip=129.217.128.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=tu-dortmund.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tu-dortmund.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=tu-dortmund.de header.i=@tu-dortmund.de header.b="Zlxs0MP0" Received: from simon-Latitude-5450.fritz.box (p5dc880d2.dip0.t-ipconnect.de [93.200.128.210]) (authenticated bits=0) by unimail.uni-dortmund.de (8.18.1.16/8.18.1.16) with ESMTPSA id 607L5t9N026667 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 7 Jan 2026 22:06:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tu-dortmund.de; s=unimail; t=1767819961; bh=5XhV857b4Zt0CASKZBxygyRwR2i/i6QOZmWNbvIntIQ=; h=From:To:Subject:Date:In-Reply-To:References; b=Zlxs0MP0MeZWEY5o8s83hir/dpKxKP6jSSDNvqfqUeCHyp9VE0USm3WYlne0P52OI 1Fl8Qk9hMaGSPB6PSpGTj3Tjv2gUNPzAdOdkQC9zuqAmPJtAvEnZTdlNJmR4kOiuc1 A2c8FMVix1qgvV8eCQfehr2KKWUgJf+gWcJQN6TQ= From: Simon Schippers To: willemdebruijn.kernel@gmail.com, jasowang@redhat.com, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mst@redhat.com, eperezma@redhat.com, leiyang@redhat.com, stephen@networkplumber.org, jon@nutanix.com, tim.gebauer@tu-dortmund.de, simon.schippers@tu-dortmund.de, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux.dev Subject: [PATCH net-next v7 4/9] tun/tap: add batched ptr_ring consume functions with netdev queue wakeup Date: Wed, 7 Jan 2026 22:04:43 +0100 Message-ID: <20260107210448.37851-5-simon.schippers@tu-dortmund.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260107210448.37851-1-simon.schippers@tu-dortmund.de> References: <20260107210448.37851-1-simon.schippers@tu-dortmund.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add {tun,tap}_ring_consume_batched() that wrap __ptr_ring_consume_batched() and wake the corresponding netdev subqueue when consuming the entries frees space in the ptr_ring. These wrappers are supposed to be used by vhost-net in an upcoming commit. Co-developed-by: Tim Gebauer Signed-off-by: Tim Gebauer Signed-off-by: Simon Schippers --- drivers/net/tap.c | 23 +++++++++++++++++++++++ drivers/net/tun.c | 23 +++++++++++++++++++++++ include/linux/if_tap.h | 6 ++++++ include/linux/if_tun.h | 7 +++++++ 4 files changed, 59 insertions(+) diff --git a/drivers/net/tap.c b/drivers/net/tap.c index 2442cf7ac385..7e3b4eed797c 100644 --- a/drivers/net/tap.c +++ b/drivers/net/tap.c @@ -774,6 +774,29 @@ static void *tap_ring_consume(struct tap_queue *q) return ptr; } =20 +int tap_ring_consume_batched(struct file *file, void **array, int n) +{ + struct tap_queue *q =3D file->private_data; + struct ptr_ring *ring =3D &q->ring; + struct net_device *dev; + int i; + + spin_lock(&ring->consumer_lock); + + i =3D __ptr_ring_consume_batched(ring, array, n); + if (__ptr_ring_consume_created_space(ring, i)) { + rcu_read_lock(); + dev =3D rcu_dereference(q->tap)->dev; + netif_wake_subqueue(dev, q->queue_index); + rcu_read_unlock(); + } + + spin_unlock(&ring->consumer_lock); + + return i; +} +EXPORT_SYMBOL_GPL(tap_ring_consume_batched); + static ssize_t tap_do_read(struct tap_queue *q, struct iov_iter *to, int noblock, struct sk_buff *skb) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 7148f9a844a4..db3b72025cfb 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -3736,6 +3736,29 @@ struct socket *tun_get_socket(struct file *file) } EXPORT_SYMBOL_GPL(tun_get_socket); =20 +int tun_ring_consume_batched(struct file *file, void **array, int n) +{ + struct tun_file *tfile =3D file->private_data; + struct ptr_ring *ring =3D &tfile->tx_ring; + struct net_device *dev; + int i; + + spin_lock(&ring->consumer_lock); + + i =3D __ptr_ring_consume_batched(ring, array, n); + if (__ptr_ring_consume_created_space(ring, i)) { + rcu_read_lock(); + dev =3D rcu_dereference(tfile->tun)->dev; + netif_wake_subqueue(dev, tfile->queue_index); + rcu_read_unlock(); + } + + spin_unlock(&ring->consumer_lock); + + return i; +} +EXPORT_SYMBOL_GPL(tun_ring_consume_batched); + struct ptr_ring *tun_get_tx_ring(struct file *file) { struct tun_file *tfile; diff --git a/include/linux/if_tap.h b/include/linux/if_tap.h index 553552fa635c..cf8b90320b8d 100644 --- a/include/linux/if_tap.h +++ b/include/linux/if_tap.h @@ -11,6 +11,7 @@ struct socket; #if IS_ENABLED(CONFIG_TAP) struct socket *tap_get_socket(struct file *); struct ptr_ring *tap_get_ptr_ring(struct file *file); +int tap_ring_consume_batched(struct file *file, void **array, int n); #else #include #include @@ -22,6 +23,11 @@ static inline struct ptr_ring *tap_get_ptr_ring(struct f= ile *f) { return ERR_PTR(-EINVAL); } +static inline int tap_ring_consume_batched(struct file *f, + void **array, int n) +{ + return 0; +} #endif /* CONFIG_TAP */ =20 /* diff --git a/include/linux/if_tun.h b/include/linux/if_tun.h index 80166eb62f41..444dda75a372 100644 --- a/include/linux/if_tun.h +++ b/include/linux/if_tun.h @@ -22,6 +22,7 @@ struct tun_msg_ctl { #if defined(CONFIG_TUN) || defined(CONFIG_TUN_MODULE) struct socket *tun_get_socket(struct file *); struct ptr_ring *tun_get_tx_ring(struct file *file); +int tun_ring_consume_batched(struct file *file, void **array, int n); =20 static inline bool tun_is_xdp_frame(void *ptr) { @@ -55,6 +56,12 @@ static inline struct ptr_ring *tun_get_tx_ring(struct fi= le *f) return ERR_PTR(-EINVAL); } =20 +static inline int tun_ring_consume_batched(struct file *file, + void **array, int n) +{ + return 0; +} + static inline bool tun_is_xdp_frame(void *ptr) { return false; --=20 2.43.0