From: David Howells <dhowells@redhat.com>
To: netdev@vger.kernel.org
Cc: David Howells <dhowells@redhat.com>,
Marc Dionne <marc.dionne@auristor.com>,
Jakub Kicinski <kuba@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
linux-afs@lists.infradead.org, linux-kernel@vger.kernel.org,
Jeffrey Altman <jaltman@auristor.com>,
stable@vger.kernel.org
Subject: [PATCH net v10 06/14] rxrpc: Fix error handling in rxrpc_send_data()
Date: Mon, 14 Sep 2026 16:13:30 +0100 [thread overview]
Message-ID: <20260914151340.3227501-7-dhowells@redhat.com> (raw)
In-Reply-To: <20260914151340.3227501-1-dhowells@redhat.com>
Fix the error handling in rxrpc_send_data() so that it doesn't return an
error if it has successfully queued the last packet of a call, but the call
has seen to have completed after it did that. Rather, leave it to
recvmsg() to report the completion (which it will do anyway).
The problem with trying to report the error twice is that the caller may
try to clean up the dead call twice.
Further, if we haven't queued the final packet yet, return -ESHUTDOWN if
the call is now marked complete (e.g. it got aborted by the peer) as
there's no point sendmsg() continuing to try to add data to a call if it is
defunct. The application should abort the call and then call recvmsg() to
pick up the reason.
Fixes: 4ba68c519255 ("rxrpc: Return an error to sendmsg if call failed")
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Jeffrey Altman <jaltman@auristor.com>
cc: Eric Dumazet <edumazet@google.com>
cc: "David S. Miller" <davem@davemloft.net>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Simon Horman <horms@kernel.org>
cc: linux-afs@lists.infradead.org
cc: stable@vger.kernel.org
---
fs/afs/rxrpc.c | 11 +++---
net/rxrpc/rxperf.c | 38 +++++++++++++-------
net/rxrpc/sendmsg.c | 86 +++++++++++++++++++++++++++++++++------------
3 files changed, 95 insertions(+), 40 deletions(-)
diff --git a/fs/afs/rxrpc.c b/fs/afs/rxrpc.c
index 2b241716dae7..4694a6fca9b4 100644
--- a/fs/afs/rxrpc.c
+++ b/fs/afs/rxrpc.c
@@ -448,13 +448,14 @@ void afs_make_call(struct afs_call *call, gfp_t gfp)
return;
}
- if (ret == -ECONNABORTED) {
+ if (ret == -ESHUTDOWN) {
len = 0;
iov_iter_kvec(&msg.msg_iter, ITER_DEST, NULL, 0, 0);
- rxrpc_kernel_recv_data(call->net->socket, rxcall,
- &msg.msg_iter, &len, false,
- &call->abort_code, &call->service_id);
- call->responded = true;
+ ret = rxrpc_kernel_recv_data(call->net->socket, rxcall,
+ &msg.msg_iter, &len, false,
+ &call->abort_code, &call->service_id);
+ if (ret == -ECONNABORTED)
+ call->responded = true;
}
call->error = ret;
trace_afs_call_done(call);
diff --git a/net/rxrpc/rxperf.c b/net/rxrpc/rxperf.c
index 7e9a53615309..83016830e696 100644
--- a/net/rxrpc/rxperf.c
+++ b/net/rxrpc/rxperf.c
@@ -74,7 +74,7 @@ static struct workqueue_struct *rxperf_workqueue;
static void rxperf_deliver_to_call(struct work_struct *work);
static int rxperf_deliver_param_block(struct rxperf_call *call);
static int rxperf_deliver_request(struct rxperf_call *call);
-static int rxperf_process_call(struct rxperf_call *call);
+static void rxperf_process_call(struct rxperf_call *call);
static void rxperf_charge_preallocation(struct work_struct *work);
static DECLARE_WORK(rxperf_charge_preallocation_work,
@@ -293,18 +293,28 @@ static void rxperf_deliver_to_call(struct work_struct *work)
state == RXPERF_CALL_SV_AWAIT_ACK
) {
if (state == RXPERF_CALL_SV_AWAIT_ACK) {
- if (!rxrpc_kernel_check_life(rxperf_socket, call->rxcall))
+ size_t len = 0;
+ iov_iter_kvec(&call->iter, ITER_DEST, NULL, 0, 0);
+ ret = rxrpc_kernel_recv_data(rxperf_socket,
+ call->rxcall, &call->iter,
+ &len, false, &remote_abort,
+ &call->service_id);
+
+ if (ret == -EINPROGRESS || ret == -EAGAIN)
+ return;
+ if (ret < 0 || ret == 1) {
+ if (ret == 1)
+ ret = 0;
goto call_complete;
+ }
return;
}
ret = call->deliver(call);
- if (ret == 0)
- ret = rxperf_process_call(call);
-
switch (ret) {
case 0:
- continue;
+ rxperf_process_call(call);
+ return;
case -EINPROGRESS:
case -EAGAIN:
return;
@@ -508,7 +518,7 @@ static int rxperf_deliver_request(struct rxperf_call *call)
/*
* Process a call for which we've received the request.
*/
-static int rxperf_process_call(struct rxperf_call *call)
+static void rxperf_process_call(struct rxperf_call *call)
{
struct msghdr msg = {};
struct bio_vec bv;
@@ -527,7 +537,7 @@ static int rxperf_process_call(struct rxperf_call *call)
n = rxrpc_kernel_send_data(rxperf_socket, call->rxcall, &msg,
rxperf_notify_end_reply_tx);
if (n < 0)
- return n;
+ goto send_error;
reply_len -= len;
}
@@ -539,10 +549,13 @@ static int rxperf_process_call(struct rxperf_call *call)
n = rxrpc_kernel_send_data(rxperf_socket, call->rxcall, &msg,
rxperf_notify_end_reply_tx);
if (n < 0)
- rxrpc_kernel_abort_call(rxperf_socket, call->rxcall,
- RXGEN_SS_MARSHAL, n,
- rxperf_abort_send_error);
- return n;
+ goto send_error;
+ return;
+
+send_error:
+ rxrpc_kernel_abort_call(rxperf_socket, call->rxcall,
+ RXGEN_SS_MARSHAL, n,
+ rxperf_abort_send_error);
}
/*
@@ -695,4 +708,3 @@ static void __exit rxperf_exit(void)
rcu_barrier();
}
module_exit(rxperf_exit);
-
diff --git a/net/rxrpc/sendmsg.c b/net/rxrpc/sendmsg.c
index b370e440e2fd..1012d2d337a5 100644
--- a/net/rxrpc/sendmsg.c
+++ b/net/rxrpc/sendmsg.c
@@ -329,13 +329,6 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
bool more = msg->msg_flags & MSG_MORE;
int ret, copied = 0;
- if (test_bit(RXRPC_CALL_TX_NO_MORE, &call->flags)) {
- trace_rxrpc_abort(call->debug_id, rxrpc_sendmsg_late_send,
- call->cid, call->call_id, call->rx_consumed,
- 0, -EPROTO);
- return -EPROTO;
- }
-
timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);
ret = rxrpc_wait_to_be_connected(call, &timeo);
@@ -352,13 +345,20 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
sk_clear_bit(SOCKWQ_ASYNC_NOSPACE, sk);
reload:
+ if (unlikely(test_bit(RXRPC_CALL_TX_NO_MORE, &call->flags))) {
+ trace_rxrpc_abort(call->debug_id, rxrpc_sendmsg_late_send,
+ call->cid, call->call_id, call->rx_consumed,
+ 0, -EPROTO);
+ ret = -EPROTO;
+ goto out_unlock;
+ }
+
ret = -EPIPE;
if (sk->sk_shutdown & SEND_SHUTDOWN)
- goto maybe_error;
+ goto out_unlock;
state = rxrpc_call_state(call);
- ret = -ESHUTDOWN;
if (state >= RXRPC_CALL_COMPLETE)
- goto maybe_error;
+ goto call_terminated;
ret = -EPROTO;
if (state != RXRPC_CALL_CLIENT_PRE_SEND &&
state != RXRPC_CALL_CLIENT_SEND_REQUEST &&
@@ -368,7 +368,7 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
trace_rxrpc_abort(call->debug_id, rxrpc_sendmsg_late_send,
call->cid, call->call_id, call->rx_consumed,
0, -EPROTO);
- goto maybe_error;
+ goto out_unlock;
}
ret = -EMSGSIZE;
@@ -448,31 +448,73 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
goto out_unlock;
rxrpc_queue_packet(rx, call, txb, notify_end_tx);
call->tx_pending = NULL;
+
+ /* At this point, if that was the last packet, it may
+ * have been transmitted and the reply (client call) or
+ * final ACK (service call) may have been received,
+ * completing the call.
+ */
}
} while (len > 0 && msg_data_left(msg) > 0);
-success:
+ /* Don't check for call completeness here, but leave that to recvmsg or
+ * a further call to sendmsg().
+ */
ret = copied;
- if (rxrpc_call_is_complete(call) &&
- call->error < 0)
- ret = call->error;
out_unlock:
mutex_unlock(&call->user_mutex);
+out:
+
+ /* The return value is a bit complicated as we want to avoid returning
+ * an error if we have queued the final packet. In descending order of
+ * preference:
+ *
+ * (1) If we queue the last packet: the amount copied (which may be
+ * zero). recvmsg() should be used to collect the result.
+ *
+ * (2) If another sendmsg() has already queued the last packet: -EPROTO.
+ *
+ * (3) If the send side of the socket is shut down, -EPIPE.
+ *
+ * (4) If the call is in the wrong state to transmit: -EPROTO.
+ *
+ * (5) If the call has terminated early, likely due to an external
+ * event such as being remotely aborted: -ESHUTDOWN.
+ *
+ * (6) If some data has been copied by this call: the amount copied
+ * (which will be greater than zero).
+ *
+ * (7) Any other error.
+ *
+ * For (2)-(5), there's no point in continuing with the sendmsg(). The
+ * app should abort the call (just in case the error came from
+ * somewhere else) and then use recvmsg() to collect the final result
+ * of the call.
+ */
_leave(" = %d", ret);
return ret;
call_terminated:
- ret = call->error;
+ ret = -ESHUTDOWN;
goto out_unlock;
maybe_error:
- if (copied)
- goto success;
+ if (copied) {
+ if (test_bit(RXRPC_CALL_TX_NO_MORE, &call->flags)) {
+ /* If we've get here, we must have slept waiting for space and .
+ */
+ ret = copied;
+ goto out_unlock;
+ }
+ if (rxrpc_call_is_complete(call))
+ goto call_terminated;
+ ret = copied;
+ }
goto out_unlock;
efault:
ret = -EFAULT;
- goto out_unlock;
+ goto maybe_error;
wait_for_space:
ret = -EAGAIN;
@@ -495,7 +537,9 @@ static int rxrpc_send_data(struct rxrpc_sock *rx,
goto reload;
out_nolock:
_leave(" = %d [intr]", ret);
- return copied ?: ret;
+ if (copied)
+ ret = copied;
+ goto out;
}
/*
@@ -817,8 +861,6 @@ int rxrpc_kernel_send_data(struct socket *sock, struct rxrpc_call *call,
ret = rxrpc_send_data(rxrpc_sk(sock->sk), call, msg,
msg_data_left(msg), notify_end_tx);
- if (ret == -ESHUTDOWN)
- ret = call->error;
if (ret < 0)
break;
if (msg_data_left(msg) == 0) {
next prev parent reply other threads:[~2026-09-14 15:14 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 15:13 [PATCH net v10 00/14] rxrpc: Miscellaneous fixes David Howells
2026-09-14 15:13 ` [PATCH net v10 01/14] rxrpc: Fix lack of short-send handling in rxrpc_kernel_send_data() David Howells
2026-09-14 21:11 ` David Laight
2026-09-14 15:13 ` [PATCH net v10 02/14] afs: Fix afs to abort the rxrpc call on send error David Howells
2026-09-14 15:13 ` [PATCH net v10 03/14] rxrpc: Fix aborting in rxperf test server David Howells
2026-09-14 15:13 ` [PATCH net v10 04/14] rxrpc: Fix sendmsg length David Howells
2026-09-14 15:13 ` [PATCH net v10 05/14] rxrpc: Fix update of call->tx_pending without holding lock David Howells
2026-09-14 15:13 ` David Howells [this message]
2026-09-14 15:13 ` [PATCH net v10 07/14] rxrpc: Fix packet encryption error handling David Howells
2026-09-14 15:13 ` [PATCH net v10 08/14] rxrpc: Fix double IRQ enablement David Howells
2026-09-14 15:13 ` [PATCH net v10 09/14] rxrpc: Fix generation of notifications after call completion David Howells
2026-09-14 15:13 ` [PATCH net v10 10/14] rxrpc: Fix RxGK key parser to check enctype is supported David Howells
2026-09-14 15:13 ` [PATCH net v10 11/14] afs: Fix creation of RxGK CM channel token to have right size David Howells
2026-09-14 15:13 ` [PATCH net v10 12/14] afs: Fix lack of setting call->server when doing FS.InlineBulkStatus David Howells
2026-09-14 15:13 ` [PATCH net v10 13/14] afs: Fix uncleared op->call pointer David Howells
2026-09-14 15:13 ` [PATCH net v10 14/14] rxrpc: fix use-after-free in rxrpc_poke_conn() David Howells
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260914151340.3227501-7-dhowells@redhat.com \
--to=dhowells@redhat.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jaltman@auristor.com \
--cc=kuba@kernel.org \
--cc=linux-afs@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marc.dionne@auristor.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®