Skip to contentSkip to conversation

sctp: support MSG_ERRQUEUE flag in recvmsg()

PATCH Applied Eric Dumazet 3 participants 5 messages Dec 12, 2023 – Dec 14, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sctp: support MSG_ERRQUEUE flag in recvmsg()

For some reason sctp_poll() generates EPOLLERR if sk->sk_error_queue is not empty but recvmsg() can not drain the error queue yet.

This is needed to better support timestamping.

I had to export inet_recv_error(), since sctp
can be compiled as a module.

Cc Xin Long <[email protected]>
Cc Marcelo Ricardo Leitner <[email protected]>
Cc Willem de Bruijn <[email protected]>
---
 net/ipv4/af_inet.c | 1 +
 net/sctp/socket.c  | 3 +++
 2 files changed, 4 insertions(+)
net/ipv4/af_inet.c +1 -0
index fbeacf04dbf3744e5888360e0b74bf6f70ff214f..835f4f9d98d25559fb8965a7531c6863448a55c2 100644
@@ -1633,6 +1633,7 @@ int inet_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
 #endif
 	return -EINVAL;
 }
+EXPORT_SYMBOL(inet_recv_error);
 
 int inet_gro_complete(struct sk_buff *skb, int nhoff)
 {
net/sctp/socket.c +3 -0
index 7f89e43154c091f6f7a3c995c1ba8abb62a8e767..5fb02bbb4b349ef9ab9c2790cccb30fb4c4e897c 100644
@@ -2099,6 +2099,9 @@ static int sctp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
 	pr_debug("%s: sk:%p, msghdr:%p, len:%zd, flags:0x%x, addr_len:%p)\n",
 		 __func__, sk, msg, len, flags, addr_len);
 
+	if (unlikely(flags & MSG_ERRQUEUE))
+		return inet_recv_error(sk, msg, len, addr_len);
+
 	lock_sock(sk);
 
 	if (sctp_style(sk, TCP) && !sctp_sstate(sk, ESTABLISHED) &&
Signature · 1 line
2.43.0.472.g3155946c3a-goog
maintainer
#1 lore raw
Quoted 3 lines · Eric Dumazet

For some reason sctp_poll() generates EPOLLERR if sk->sk_error_queue is not empty but recvmsg() can not drain the error queue yet.

I'm checking the code but can't see how SCTP may enqueue skbs into sk->sk_error_queue. Have you ever seen it happen in any of your cases?

Quoted 2 lines

This is needed to better support timestamping.

I think SCTP doesn't support timestamping, there's no functions like tcp_tx_timestamp()/tcp_gso_tstamp() to enable it.

Or do you mean SO_TXTIME socket option, and then tc-etf may enqueue a skb into sk->sk_error_queue if it's enabled?

Quoted 42 lines

I had to export inet_recv_error(), since sctp
can be compiled as a module.

Cc Xin Long <[email protected]>
Cc Marcelo Ricardo Leitner <[email protected]>
Cc Willem de Bruijn <[email protected]>
---
 net/ipv4/af_inet.c | 1 +
 net/sctp/socket.c  | 3 +++
 2 files changed, 4 insertions(+)
net/ipv4/af_inet.c +1 -0
index fbeacf04dbf3744e5888360e0b74bf6f70ff214f..835f4f9d98d25559fb8965a7531c6863448a55c2 100644
@@ -1633,6 +1633,7 @@ int inet_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
 #endif
        return -EINVAL;
 }
+EXPORT_SYMBOL(inet_recv_error);
 
 int inet_gro_complete(struct sk_buff *skb, int nhoff)
 {
net/sctp/socket.c +3 -1
index 7f89e43154c091f6f7a3c995c1ba8abb62a8e767..5fb02bbb4b349ef9ab9c2790cccb30fb4c4e897c 100644
@@ -2099,6 +2099,9 @@ static int sctp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
        pr_debug("%s: sk:%p, msghdr:%p, len:%zd, flags:0x%x, addr_len:%p)\n",
                 __func__, sk, msg, len, flags, addr_len);
 
+       if (unlikely(flags & MSG_ERRQUEUE))
+               return inet_recv_error(sk, msg, len, addr_len);
+
        lock_sock(sk);
 
        if (sctp_style(sk, TCP) && !sctp_sstate(sk, ESTABLISHED) &&
--

2.43.0.472.g3155946c3a-goog

#2 lore raw
Quoted 9 lines · Xin Long
Quoted 3 lines · Eric Dumazet

For some reason sctp_poll() generates EPOLLERR if sk->sk_error_queue is not empty but recvmsg() can not drain the error queue yet.

I'm checking the code but can't see how SCTP may enqueue skbs into sk->sk_error_queue. Have you ever seen it happen in any of your cases?

Quoted 1 line
Quoted 7 lines
Quoted 1 line

This is needed to better support timestamping.

I think SCTP doesn't support timestamping, there's no functions like tcp_tx_timestamp()/tcp_gso_tstamp() to enable it.

Or do you mean SO_TXTIME socket option, and then tc-etf may enqueue a skb into sk->sk_error_queue if it's enabled?

I think this is the goal yes.

Also this prevents developers from using MSG_ERRQUEUE and having the kernel read the receive queue.

mptcp had a similar issue in the past, Paolo fixed it.

Quoted 42 lines
Quoted 42 lines

I had to export inet_recv_error(), since sctp
can be compiled as a module.

Cc Xin Long <[email protected]>
Cc Marcelo Ricardo Leitner <[email protected]>
Cc Willem de Bruijn <[email protected]>
---
 net/ipv4/af_inet.c | 1 +
 net/sctp/socket.c  | 3 +++
 2 files changed, 4 insertions(+)
net/ipv4/af_inet.c +1 -0
index fbeacf04dbf3744e5888360e0b74bf6f70ff214f..835f4f9d98d25559fb8965a7531c6863448a55c2 100644
@@ -1633,6 +1633,7 @@ int inet_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
 #endif
        return -EINVAL;
 }
+EXPORT_SYMBOL(inet_recv_error);
 
 int inet_gro_complete(struct sk_buff *skb, int nhoff)
 {
net/sctp/socket.c +3 -1
index 7f89e43154c091f6f7a3c995c1ba8abb62a8e767..5fb02bbb4b349ef9ab9c2790cccb30fb4c4e897c 100644
@@ -2099,6 +2099,9 @@ static int sctp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
        pr_debug("%s: sk:%p, msghdr:%p, len:%zd, flags:0x%x, addr_len:%p)\n",
                 __func__, sk, msg, len, flags, addr_len);
 
+       if (unlikely(flags & MSG_ERRQUEUE))
+               return inet_recv_error(sk, msg, len, addr_len);
+
        lock_sock(sk);
 
        if (sctp_style(sk, TCP) && !sctp_sstate(sk, ESTABLISHED) &&
--

2.43.0.472.g3155946c3a-goog

maintainer Acked-by
#3 lore raw
Quoted 64 lines · Eric Dumazet
Quoted 9 lines · Xin Long
Quoted 3 lines · Eric Dumazet

For some reason sctp_poll() generates EPOLLERR if sk->sk_error_queue is not empty but recvmsg() can not drain the error queue yet.

I'm checking the code but can't see how SCTP may enqueue skbs into sk->sk_error_queue. Have you ever seen it happen in any of your cases?

Quoted 1 line
Quoted 7 lines
Quoted 1 line

This is needed to better support timestamping.

I think SCTP doesn't support timestamping, there's no functions like tcp_tx_timestamp()/tcp_gso_tstamp() to enable it.

Or do you mean SO_TXTIME socket option, and then tc-etf may enqueue a skb into sk->sk_error_queue if it's enabled?

I think this is the goal yes.

Also this prevents developers from using MSG_ERRQUEUE and having the kernel read the receive queue.

mptcp had a similar issue in the past, Paolo fixed it.

Quoted 38 lines
Quoted 38 lines

I had to export inet_recv_error(), since sctp
can be compiled as a module.

Cc Xin Long <[email protected]>
Cc Marcelo Ricardo Leitner <[email protected]>
Cc Willem de Bruijn <[email protected]>
---
 net/ipv4/af_inet.c | 1 +
 net/sctp/socket.c  | 3 +++
 2 files changed, 4 insertions(+)
net/ipv4/af_inet.c +1 -0
index fbeacf04dbf3744e5888360e0b74bf6f70ff214f..835f4f9d98d25559fb8965a7531c6863448a55c2 100644
@@ -1633,6 +1633,7 @@ int inet_recv_error(struct sock *sk, struct msghdr *msg, int len, int *addr_len)
 #endif
        return -EINVAL;
 }
+EXPORT_SYMBOL(inet_recv_error);
 
 int inet_gro_complete(struct sk_buff *skb, int nhoff)
 {
net/sctp/socket.c +3 -0
index 7f89e43154c091f6f7a3c995c1ba8abb62a8e767..5fb02bbb4b349ef9ab9c2790cccb30fb4c4e897c 100644
@@ -2099,6 +2099,9 @@ static int sctp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
        pr_debug("%s: sk:%p, msghdr:%p, len:%zd, flags:0x%x, addr_len:%p)\n",
                 __func__, sk, msg, len, flags, addr_len);
 
+       if (unlikely(flags & MSG_ERRQUEUE))
+               return inet_recv_error(sk, msg, len, addr_len);
+
        lock_sock(sk);
 
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
net/sctp/socket.c +0 -1
        if (sctp_style(sk, TCP) && !sctp_sstate(sk, ESTABLISHED) &&
--

2.43.0.472.g3155946c3a-goog

#4 lore raw
In reply to Eric Dumazet
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Tue, 12 Dec 2023 14:55:50 +0000 you wrote:

For some reason sctp_poll() generates EPOLLERR if sk->sk_error_queue is not empty but recvmsg() can not drain the error queue yet.

This is needed to better support timestamping.

I had to export inet_recv_error(), since sctp
can be compiled as a module.

[...]

Here is the summary with links:
- [net-next] sctp: support MSG_ERRQUEUE flag in recvmsg()

    https://git.kernel.org/netdev/net-next/c/4746b36b1abe

You are awesome, thank you!

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