Re: [PATCH net-next v1 3/9] net: devmem: preserve sockc_err

Stanislav Fomichev
2025-05-19T15:21:38Z

On 05/19, Mina Almasry wrote:
> Preserve the error code returned by sock_cmsg_send and return that on
> err.
>
> Signed-off-by: Mina Almasry <almasrymina@google.com>
> ---
> net/ipv4/tcp.c | 24 ++++++++++--------------
> 1 file changed, 10 insertions(+), 14 deletions(-)
>
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index b7b6ab41b496..45abe5772157 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -1067,7 +1067,7 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
> int flags, err, copied = 0;
> int mss_now = 0, size_goal, copied_syn = 0;
> int process_backlog = 0;
> - bool sockc_valid = true;
> + int sockc_err = 0;
> int zc = 0;
> long timeo;
>
> @@ -1075,13 +1075,10 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
>
> sockc = (struct sockcm_cookie){ .tsflags = READ_ONCE(sk->sk_tsflags) };
> if (msg->msg_controllen) {
> - err = sock_cmsg_send(sk, msg, &sockc);
> - if (unlikely(err))
> - /* Don't return error until MSG_FASTOPEN has been
> - * processed; that may succeed even if the cmsg is
> - * invalid.
> - */
> - sockc_valid = false;
> + sockc_err = sock_cmsg_send(sk, msg, &sockc);
> + /* Don't return error until MSG_FASTOPEN has been processed;
> + * that may succeed even if the cmsg is invalid.
> + */
> }
>
> if ((flags & MSG_ZEROCOPY) && size) {
> @@ -1092,7 +1089,7 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
> } else if (sock_flag(sk, SOCK_ZEROCOPY)) {
> skb = tcp_write_queue_tail(sk);
> uarg = msg_zerocopy_realloc(sk, size, skb_zcopy(skb),
> - sockc_valid && !!sockc.dmabuf_id);
> + !sockc_err && !!sockc.dmabuf_id);

Why have these extra !! here? Other places below simply do '&& sockc.dmabuf_id',
why not the same here?

> if (!uarg) {
> err = -ENOBUFS;
> goto out_err;
> @@ -1102,7 +1099,7 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
> else
> uarg_to_msgzc(uarg)->zerocopy = 0;
>
> - if (sockc_valid && sockc.dmabuf_id) {
> + if (!sockc_err && sockc.dmabuf_id) {
> binding = net_devmem_get_binding(sk, sockc.dmabuf_id);
> if (IS_ERR(binding)) {
> err = PTR_ERR(binding);
> @@ -1116,7 +1113,7 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
> zc = MSG_SPLICE_PAGES;
> }
>
> - if (sockc_valid && sockc.dmabuf_id &&
> + if (!sockc_err && sockc.dmabuf_id &&
> (!(flags & MSG_ZEROCOPY) || !sock_flag(sk, SOCK_ZEROCOPY))) {
> err = -EINVAL;
> goto out_err;
> @@ -1160,9 +1157,8 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
> /* 'common' sending to sendq */
> }
>
> - if (!sockc_valid) {
> - if (!err)
> - err = -EINVAL;
> + if (!!sockc_err) {

Same here, I don't think we need these extra !! ?