Skip to contentSkip to conversation

fix poll behaviour for TCP-based tunnel protocols

PATCH Applied Ralf Lici 4 participants 10 messages Oct 21, 2025 – Oct 23, 2025

Subsystems (4)
lore
Share & tools
lore

Ralf Lici

author reviewer
#0 lore raw

v3 cover fix poll behaviour for TCP-based tunnel protocols

Hi all,

This patch series introduces a polling function for datagram-style sockets that operates on custom skb queues, and updates ovpn (the OpenVPN data-channel offload module) and espintcp (the TCP Encapsulation of IKE and IPsec Packets implementation) to use it accordingly.

Protocols like the aforementioned one decapsulate packets received over TCP and deliver userspace-bound data through a separate skb queue, not the standard sk_receive_queue. Previously, both relied on datagram_poll(), which would signal readiness based on non-userspace packets, leading to misleading poll results and unnecessary recv attempts in userspace.

Patch 1 introduces datagram_poll_queue(), a variant of datagram_poll() that accepts an explicit receive queue. This builds on the approach introduced in commit b50b058, which extended other skb-related functions to support custom queues. Patch 2 and 3 update espintcp_poll() and ovpn_tcp_poll() respectively to use this helper, ensuring readiness is only signaled when userspace data is available.

Each patch is self-contained and the ovpn one includes rationale and lifecycle enforcement where appropriate.

Thanks for your time and feedback.

Best Regards,

Ralf Lici
Mandelbit Srl

Changes since v2:
- Documented return value in datagram_poll() kernel-doc
- Replaced WARN_ON with WARN to print a custom message in ovpn_tcp_poll()

Changes since v1:
- Documented return value in datagram_poll_queue() kernel-doc
- Added missing CCs

---

Ralf Lici (3):
net: datagram: introduce datagram_poll_queue for custom receive queues
espintcp: use datagram_poll_queue for socket readiness
ovpn: use datagram_poll_queue for socket readiness in TCP

 drivers/net/ovpn/tcp.c | 26 +++++++++++++++++++++----
 include/linux/skbuff.h |  3 +++
 net/core/datagram.c    | 44 ++++++++++++++++++++++++++++++++----------
 net/xfrm/espintcp.c    |  6 +-----
 4 files changed, 60 insertions(+), 19 deletions(-)
Signature · 1 line
2.51.0
author reviewer
#1 lore raw

PATCH v3 1/3 net: datagram: introduce datagram_poll_queue for custom receive queues

Some protocols using TCP encapsulation (e.g., espintcp, openvpn) deliver userspace-bound packets through a custom skb queue rather than the standard sk_receive_queue.

Introduce datagram_poll_queue that accepts an explicit receive queue, and convert datagram_poll into a wrapper around datagram_poll_queue. This allows protocols with custom skb queues to reuse the core polling logic without relying on sk_receive_queue.

Cc Sabrina Dubroca <[email protected]>
Cc Antonio Quartulli <[email protected]>
---
 include/linux/skbuff.h |  3 +++
 net/core/datagram.c    | 44 ++++++++++++++++++++++++++++++++----------
 2 files changed, 37 insertions(+), 10 deletions(-)
include/linux/skbuff.h +3 -0
index fb3fec9affaa..a7cc3d1f4fd1 100644
@@ -4204,6 +4204,9 @@ struct sk_buff *__skb_recv_datagram(struct sock *sk,
 				    struct sk_buff_head *sk_queue,
 				    unsigned int flags, int *off, int *err);
 struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned int flags, int *err);
+__poll_t datagram_poll_queue(struct file *file, struct socket *sock,
+			     struct poll_table_struct *wait,
+			     struct sk_buff_head *rcv_queue);
 __poll_t datagram_poll(struct file *file, struct socket *sock,
 			   struct poll_table_struct *wait);
 int skb_copy_datagram_iter(const struct sk_buff *from, int offset,
net/core/datagram.c +34 -10

66 lines not on this page · raw message

Signature · 1 line
2.51.0
reviewer Reviewed-by on v3 1/3
#2 lore raw

Re: [PATCH net v3 1/3] net: datagram: introduce datagram_poll_queue for custom receive queues

Quoted 9 lines · Ralf Lici

Some protocols using TCP encapsulation (e.g., espintcp, openvpn) deliver userspace-bound packets through a custom skb queue rather than the standard sk_receive_queue.

Introduce datagram_poll_queue that accepts an explicit receive queue, and convert datagram_poll into a wrapper around datagram_poll_queue. This allows protocols with custom skb queues to reuse the core polling logic without relying on sk_receive_queue.

Quoted 7 lines
Cc Sabrina Dubroca <[email protected]>
Cc Antonio Quartulli <[email protected]>
---
 include/linux/skbuff.h |  3 +++
 net/core/datagram.c    | 44 ++++++++++++++++++++++++++++++++----------
 2 files changed, 37 insertions(+), 10 deletions(-)
Signature · 1 line
Sabrina
maintainer Reviewed-by on v3 1/3
#3 lore raw

Re: [PATCH net v3 1/3] net: datagram: introduce datagram_poll_queue for custom receive queues

In reply to Ralf Lici
Quoted 4 lines · Ralf Lici

Some protocols using TCP encapsulation (e.g., espintcp, openvpn) deliver userspace-bound packets through a custom skb queue rather than the standard sk_receive_queue.

Quoted 8 lines

Introduce datagram_poll_queue that accepts an explicit receive queue, and convert datagram_poll into a wrapper around datagram_poll_queue. This allows protocols with custom skb queues to reuse the core polling logic without relying on sk_receive_queue.

Cc Sabrina Dubroca <[email protected]>
Cc Antonio Quartulli <[email protected]>
Signature · 2 lines
Antonio Quartulli
OpenVPN Inc.
author reviewer
#4 lore raw

PATCH v3 2/3 espintcp: use datagram_poll_queue for socket readiness

In reply to Ralf Lici

espintcp uses a custom queue (ike_queue) to deliver packets to userspace. The polling logic relies on datagram_poll, which checks sk_receive_queue, which can lead to false readiness signals when that queue contains non-userspace packets.

Switch espintcp_poll to use datagram_poll_queue with ike_queue, ensuring poll only signals readiness when userspace data is actually available.

Fixes e27cca96cd68 ("xfrm: add espintcp (RFC 8229)")
---
 net/xfrm/espintcp.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
net/xfrm/espintcp.c +1 -5
index fc7a603b04f1..bf744ac9d5a7 100644
@@ -555,14 +555,10 @@ static void espintcp_close(struct sock *sk, long timeout)
 static __poll_t espintcp_poll(struct file *file, struct socket *sock,
 			      poll_table *wait)
 {
-	__poll_t mask = datagram_poll(file, sock, wait);
 	struct sock *sk = sock->sk;
 	struct espintcp_ctx *ctx = espintcp_getctx(sk);
 
-	if (!skb_queue_empty(&ctx->ike_queue))
-		mask |= EPOLLIN | EPOLLRDNORM;
-
-	return mask;
+	return datagram_poll_queue(file, sock, wait, &ctx->ike_queue);
 }
 
 static void build_protos(struct proto *espintcp_prot,
Signature · 1 line
2.51.0
reviewer Reviewed-by on v3 2/3
#5 lore raw

Re: [PATCH net v3 2/3] espintcp: use datagram_poll_queue for socket readiness

Quoted 5 lines · Ralf Lici

espintcp uses a custom queue (ike_queue) to deliver packets to userspace. The polling logic relies on datagram_poll, which checks sk_receive_queue, which can lead to false readiness signals when that queue contains non-userspace packets.

Quoted 8 lines

Switch espintcp_poll to use datagram_poll_queue with ike_queue, ensuring poll only signals readiness when userspace data is actually available.

Fixes e27cca96cd68 ("xfrm: add espintcp (RFC 8229)")
---
 net/xfrm/espintcp.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
Signature · 1 line
Sabrina
author reviewer
#6 lore raw

PATCH v3 3/3 ovpn: use datagram_poll_queue for socket readiness in TCP

In reply to Ralf Lici

openvpn TCP encapsulation uses a custom queue to deliver packets to userspace. Currently it relies on datagram_poll, which checks sk_receive_queue, leading to false readiness signals when that queue contains non-userspace packets.

Switch ovpn_tcp_poll to use datagram_poll_queue with the peer's user_queue, ensuring poll only signals readiness when userspace data is actually available. Also refactor ovpn_tcp_poll in order to enforce the assumption we can make on the lifetime of ovpn_sock and peer.

Fixes 11851cbd60ea ("ovpn: implement TCP transport")
---
 drivers/net/ovpn/tcp.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)
drivers/net/ovpn/tcp.c +22 -4
index 289f62c5d2c7..0d7f30360d87 100644
@@ -560,16 +560,34 @@ static void ovpn_tcp_close(struct sock *sk, long timeout)
 static __poll_t ovpn_tcp_poll(struct file *file, struct socket *sock,
 			      poll_table *wait)
 {
-	__poll_t mask = datagram_poll(file, sock, wait);
+	struct sk_buff_head *queue = &sock->sk->sk_receive_queue;
 	struct ovpn_socket *ovpn_sock;
+	struct ovpn_peer *peer = NULL;
+	__poll_t mask;
 
 	rcu_read_lock();
 	ovpn_sock = rcu_dereference_sk_user_data(sock->sk);
-	if (ovpn_sock && ovpn_sock->peer &&
-	    !skb_queue_empty(&ovpn_sock->peer->tcp.user_queue))
-		mask |= EPOLLIN | EPOLLRDNORM;
+	/* if we landed in this callback, we expect to have a
+	 * meaningful state. The ovpn_socket lifecycle would
+	 * prevent it otherwise.
+	 */
+	if (WARN(!ovpn_sock || !ovpn_sock->peer,
+		 "ovpn: null state in ovpn_tcp_poll!")) {
+		rcu_read_unlock();
+		return 0;
+	}
+
+	if (ovpn_peer_hold(ovpn_sock->peer)) {
+		peer = ovpn_sock->peer;
+		queue = &peer->tcp.user_queue;
+	}
 	rcu_read_unlock();
 
+	mask = datagram_poll_queue(file, sock, wait, queue);
+
+	if (peer)
+		ovpn_peer_put(peer);
+
 	return mask;
 }
 
Signature · 1 line
2.51.0
reviewer Reviewed-by on v3 3/3
#7 lore raw

Re: [PATCH net v3 3/3] ovpn: use datagram_poll_queue for socket readiness in TCP

Quoted 10 lines · Ralf Lici

openvpn TCP encapsulation uses a custom queue to deliver packets to userspace. Currently it relies on datagram_poll, which checks sk_receive_queue, leading to false readiness signals when that queue contains non-userspace packets.

Switch ovpn_tcp_poll to use datagram_poll_queue with the peer's user_queue, ensuring poll only signals readiness when userspace data is actually available. Also refactor ovpn_tcp_poll in order to enforce the assumption we can make on the lifetime of ovpn_sock and peer.

Quoted 6 lines
Fixes 11851cbd60ea ("ovpn: implement TCP transport")
---
 drivers/net/ovpn/tcp.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)

Thanks Ralf.

Signature · 1 line
Sabrina
#8 lore raw

Re: [PATCH net v3 3/3] ovpn: use datagram_poll_queue for socket readiness in TCP

In reply to Ralf Lici
Quoted 5 lines · Ralf Lici

openvpn TCP encapsulation uses a custom queue to deliver packets to userspace. Currently it relies on datagram_poll, which checks sk_receive_queue, leading to false readiness signals when that queue contains non-userspace packets.

Quoted 8 lines

Switch ovpn_tcp_poll to use datagram_poll_queue with the peer's user_queue, ensuring poll only signals readiness when userspace data is actually available. Also refactor ovpn_tcp_poll in order to enforce the assumption we can make on the lifetime of ovpn_sock and peer.

Fixes 11851cbd60ea ("ovpn: implement TCP transport")

Jakub,

fell free to merge this commit directly to net, as it's not useful to have it go through my tree without the other patches.

Regards,

Signature · 2 lines
Antonio Quartulli
OpenVPN Inc.
#9 lore raw
In reply to Ralf Lici
This series was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This series was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 8 lines · On Tue, 21 Oct 2025 12:09:39 +0200 you wrote:

Hi all,

This patch series introduces a polling function for datagram-style sockets that operates on custom skb queues, and updates ovpn (the OpenVPN data-channel offload module) and espintcp (the TCP Encapsulation of IKE and IPsec Packets implementation) to use it accordingly.

[...]

Here is the summary with links:
- [net,v3,1/3] net: datagram: introduce datagram_poll_queue for custom receive queues

    https://git.kernel.org/netdev/net/c/f6ceec6434b5
  - [net,v3,2/3] espintcp: use datagram_poll_queue for socket readiness
    https://git.kernel.org/netdev/net/c/0fc3e32c2c06
  - [net,v3,3/3] ovpn: use datagram_poll_queue for socket readiness in TCP
    https://git.kernel.org/netdev/net/c/efd729408bc7

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html