[PATCH net-next] net: devmem: expose tcp_recvmsg_locked errors

Stanislav Fomichev posted 1 patch 1 day, 3 hours ago
net/ipv4/tcp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH net-next] net: devmem: expose tcp_recvmsg_locked errors
Posted by Stanislav Fomichev 1 day, 3 hours ago
tcp_recvmsg_dmabuf can export the following errors:
- EFAULT when linear copy fails
- ETOOSMALL when cmsg put fails
- ENODEV if one of the frags is readable
- ENOMEM on xarray failures

But they are all ignored and replaced by EFAULT in the caller
(tcp_recvmsg_locked). Expose real error to the userspace to
add more transparency on what specifically fails.

In non-devmem case (skb_copy_datagram_msg) doing `if (!copied)
copied=-EFAULT` is ok because skb_copy_datagram_msg can return only EFAULT.

Cc: Mina Almasry <almasrymina@google.com>
Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
---
 net/ipv4/tcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 588932c3cf1d..c56d53e32c29 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -2820,7 +2820,7 @@ static int tcp_recvmsg_locked(struct sock *sk, struct msghdr *msg, size_t len,
 							 used);
 				if (err <= 0) {
 					if (!copied)
-						copied = -EFAULT;
+						copied = err;
 
 					break;
 				}
-- 
2.51.0
Re: [PATCH net-next] net: devmem: expose tcp_recvmsg_locked errors
Posted by Eric Dumazet 3 hours ago
On Mon, Sep 8, 2025 at 10:50 AM Stanislav Fomichev <sdf@fomichev.me> wrote:
>
> tcp_recvmsg_dmabuf can export the following errors:
> - EFAULT when linear copy fails
> - ETOOSMALL when cmsg put fails
> - ENODEV if one of the frags is readable
> - ENOMEM on xarray failures
>
> But they are all ignored and replaced by EFAULT in the caller
> (tcp_recvmsg_locked). Expose real error to the userspace to
> add more transparency on what specifically fails.
>
> In non-devmem case (skb_copy_datagram_msg) doing `if (!copied)
> copied=-EFAULT` is ok because skb_copy_datagram_msg can return only EFAULT.
>
> Cc: Mina Almasry <almasrymina@google.com>
> Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>

Reviewed-by: Eric Dumazet <edumazet@google.com>
Re: [PATCH net-next] net: devmem: expose tcp_recvmsg_locked errors
Posted by David Ahern 1 day ago
On 9/8/25 11:50 AM, Stanislav Fomichev wrote:
> tcp_recvmsg_dmabuf can export the following errors:
> - EFAULT when linear copy fails
> - ETOOSMALL when cmsg put fails
> - ENODEV if one of the frags is readable
> - ENOMEM on xarray failures
> 
> But they are all ignored and replaced by EFAULT in the caller
> (tcp_recvmsg_locked). Expose real error to the userspace to
> add more transparency on what specifically fails.
> 
> In non-devmem case (skb_copy_datagram_msg) doing `if (!copied)
> copied=-EFAULT` is ok because skb_copy_datagram_msg can return only EFAULT.
> 
> Cc: Mina Almasry <almasrymina@google.com>
> Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
> ---
>  net/ipv4/tcp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 


Reviewed-by: David Ahern <dsahern@kernel.org>
Re: [PATCH net-next] net: devmem: expose tcp_recvmsg_locked errors
Posted by Mina Almasry 3 hours ago
On Mon, Sep 8, 2025 at 1:44 PM David Ahern <dsahern@kernel.org> wrote:
>
> On 9/8/25 11:50 AM, Stanislav Fomichev wrote:
> > tcp_recvmsg_dmabuf can export the following errors:
> > - EFAULT when linear copy fails
> > - ETOOSMALL when cmsg put fails
> > - ENODEV if one of the frags is readable
> > - ENOMEM on xarray failures
> >
> > But they are all ignored and replaced by EFAULT in the caller
> > (tcp_recvmsg_locked). Expose real error to the userspace to
> > add more transparency on what specifically fails.
> >
> > In non-devmem case (skb_copy_datagram_msg) doing `if (!copied)
> > copied=-EFAULT` is ok because skb_copy_datagram_msg can return only EFAULT.
> >
> > Cc: Mina Almasry <almasrymina@google.com>
> > Signed-off-by: Stanislav Fomichev <sdf@fomichev.me>
> > ---
> >  net/ipv4/tcp.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
>
>
> Reviewed-by: David Ahern <dsahern@kernel.org>
>

Reviewed-by: Mina Almasry <almasrymina@google.com>

-- 
Thanks,
Mina