All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] sctp: support MSG_ERRQUEUE flag in recvmsg()
@ 2023-12-12 14:55 Eric Dumazet
  2023-12-13 15:19 ` Xin Long
  2023-12-14  2:40 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 5+ messages in thread
From: Eric Dumazet @ 2023-12-12 14:55 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, Paolo Abeni
  Cc: netdev, eric.dumazet, Eric Dumazet, Xin Long,
	Marcelo Ricardo Leitner, Willem de Bruijn

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.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Xin Long <lucien.xin@gmail.com>
Cc: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Cc: Willem de Bruijn <willemb@google.com>
---
 net/ipv4/af_inet.c | 1 +
 net/sctp/socket.c  | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index fbeacf04dbf3744e5888360e0b74bf6f70ff214f..835f4f9d98d25559fb8965a7531c6863448a55c2 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -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)
 {
diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 7f89e43154c091f6f7a3c995c1ba8abb62a8e767..5fb02bbb4b349ef9ab9c2790cccb30fb4c4e897c 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next] sctp: support MSG_ERRQUEUE flag in recvmsg()
  2023-12-12 14:55 [PATCH net-next] sctp: support MSG_ERRQUEUE flag in recvmsg() Eric Dumazet
@ 2023-12-13 15:19 ` Xin Long
  2023-12-13 15:49   ` Eric Dumazet
  2023-12-14  2:40 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 5+ messages in thread
From: Xin Long @ 2023-12-13 15:19 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, netdev,
	eric.dumazet, Marcelo Ricardo Leitner, Willem de Bruijn

On Tue, Dec 12, 2023 at 9:55 AM Eric Dumazet <edumazet@google.com> 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.
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?

>
> 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 had to export inet_recv_error(), since sctp
> can be compiled as a module.
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Xin Long <lucien.xin@gmail.com>
> Cc: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
> Cc: Willem de Bruijn <willemb@google.com>
> ---
>  net/ipv4/af_inet.c | 1 +
>  net/sctp/socket.c  | 3 +++
>  2 files changed, 4 insertions(+)
>
> diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
> index fbeacf04dbf3744e5888360e0b74bf6f70ff214f..835f4f9d98d25559fb8965a7531c6863448a55c2 100644
> --- a/net/ipv4/af_inet.c
> +++ b/net/ipv4/af_inet.c
> @@ -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)
>  {
> diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> index 7f89e43154c091f6f7a3c995c1ba8abb62a8e767..5fb02bbb4b349ef9ab9c2790cccb30fb4c4e897c 100644
> --- a/net/sctp/socket.c
> +++ b/net/sctp/socket.c
> @@ -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
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next] sctp: support MSG_ERRQUEUE flag in recvmsg()
  2023-12-13 15:19 ` Xin Long
@ 2023-12-13 15:49   ` Eric Dumazet
  2023-12-13 19:46     ` Xin Long
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Dumazet @ 2023-12-13 15:49 UTC (permalink / raw)
  To: Xin Long
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, netdev,
	eric.dumazet, Marcelo Ricardo Leitner, Willem de Bruijn

On Wed, Dec 13, 2023 at 4:19 PM Xin Long <lucien.xin@gmail.com> wrote:
>
> On Tue, Dec 12, 2023 at 9:55 AM Eric Dumazet <edumazet@google.com> 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.
> 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?
>
> >
> > 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.

> >
> > I had to export inet_recv_error(), since sctp
> > can be compiled as a module.
> >
> > Signed-off-by: Eric Dumazet <edumazet@google.com>
> > Cc: Xin Long <lucien.xin@gmail.com>
> > Cc: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
> > Cc: Willem de Bruijn <willemb@google.com>
> > ---
> >  net/ipv4/af_inet.c | 1 +
> >  net/sctp/socket.c  | 3 +++
> >  2 files changed, 4 insertions(+)
> >
> > diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
> > index fbeacf04dbf3744e5888360e0b74bf6f70ff214f..835f4f9d98d25559fb8965a7531c6863448a55c2 100644
> > --- a/net/ipv4/af_inet.c
> > +++ b/net/ipv4/af_inet.c
> > @@ -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)
> >  {
> > diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> > index 7f89e43154c091f6f7a3c995c1ba8abb62a8e767..5fb02bbb4b349ef9ab9c2790cccb30fb4c4e897c 100644
> > --- a/net/sctp/socket.c
> > +++ b/net/sctp/socket.c
> > @@ -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
> >

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next] sctp: support MSG_ERRQUEUE flag in recvmsg()
  2023-12-13 15:49   ` Eric Dumazet
@ 2023-12-13 19:46     ` Xin Long
  0 siblings, 0 replies; 5+ messages in thread
From: Xin Long @ 2023-12-13 19:46 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: David S . Miller, Jakub Kicinski, Paolo Abeni, netdev,
	eric.dumazet, Marcelo Ricardo Leitner, Willem de Bruijn

On Wed, Dec 13, 2023 at 10:50 AM Eric Dumazet <edumazet@google.com> wrote:
>
> On Wed, Dec 13, 2023 at 4:19 PM Xin Long <lucien.xin@gmail.com> wrote:
> >
> > On Tue, Dec 12, 2023 at 9:55 AM Eric Dumazet <edumazet@google.com> 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.
> > 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?
> >
> > >
> > > 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.
>
> > >
> > > I had to export inet_recv_error(), since sctp
> > > can be compiled as a module.
> > >
> > > Signed-off-by: Eric Dumazet <edumazet@google.com>
> > > Cc: Xin Long <lucien.xin@gmail.com>
> > > Cc: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
> > > Cc: Willem de Bruijn <willemb@google.com>
> > > ---
> > >  net/ipv4/af_inet.c | 1 +
> > >  net/sctp/socket.c  | 3 +++
> > >  2 files changed, 4 insertions(+)
> > >
> > > diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
> > > index fbeacf04dbf3744e5888360e0b74bf6f70ff214f..835f4f9d98d25559fb8965a7531c6863448a55c2 100644
> > > --- a/net/ipv4/af_inet.c
> > > +++ b/net/ipv4/af_inet.c
> > > @@ -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)
> > >  {
> > > diff --git a/net/sctp/socket.c b/net/sctp/socket.c
> > > index 7f89e43154c091f6f7a3c995c1ba8abb62a8e767..5fb02bbb4b349ef9ab9c2790cccb30fb4c4e897c 100644
> > > --- a/net/sctp/socket.c
> > > +++ b/net/sctp/socket.c
> > > @@ -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
> > >
Acked-by: Xin Long <lucien.xin@gmail.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net-next] sctp: support MSG_ERRQUEUE flag in recvmsg()
  2023-12-12 14:55 [PATCH net-next] sctp: support MSG_ERRQUEUE flag in recvmsg() Eric Dumazet
  2023-12-13 15:19 ` Xin Long
@ 2023-12-14  2:40 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-12-14  2:40 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: davem, kuba, pabeni, netdev, eric.dumazet, lucien.xin,
	marcelo.leitner, willemb

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-12-14  2:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-12 14:55 [PATCH net-next] sctp: support MSG_ERRQUEUE flag in recvmsg() Eric Dumazet
2023-12-13 15:19 ` Xin Long
2023-12-13 15:49   ` Eric Dumazet
2023-12-13 19:46     ` Xin Long
2023-12-14  2:40 ` patchwork-bot+netdevbpf

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.