Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rxrpc: Move call state changes from recvmsg to I/O thread

Move the call state changes that are made in rxrpc_recvmsg() to the I/O
thread. This means that, thenceforth, only the I/O thread does this and
the call state lock can be removed.

This requires the Rx phase to be ended when the last packet is received,
not when it is processed.

Since this now changes the rxrpc call state to SUCCEEDED before we've
consumed all the data from it, rxrpc_kernel_check_life() mustn't say the
call is dead until the recvmsg queue is empty (unless the call has failed).

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: linux-afs@lists.infradead.org

+109 -111
+1
fs/afs/rxrpc.c
··· 909 909 ret = rxrpc_kernel_recv_data(net->socket, call->rxcall, iter, 910 910 &call->iov_len, want_more, &remote_abort, 911 911 &call->service_id); 912 + trace_afs_receive_data(call, call->iter, want_more, ret); 912 913 if (ret == 0 || ret == -EAGAIN) 913 914 return ret; 914 915
+7 -3
net/rxrpc/af_rxrpc.c
··· 373 373 * @sock: The socket the call is on 374 374 * @call: The call to check 375 375 * 376 - * Allow a kernel service to find out whether a call is still alive - 377 - * ie. whether it has completed. 376 + * Allow a kernel service to find out whether a call is still alive - whether 377 + * it has completed successfully and all received data has been consumed. 378 378 */ 379 379 bool rxrpc_kernel_check_life(const struct socket *sock, 380 380 const struct rxrpc_call *call) 381 381 { 382 - return !rxrpc_call_is_complete(call); 382 + if (!rxrpc_call_is_complete(call)) 383 + return true; 384 + if (call->completion != RXRPC_CALL_SUCCEEDED) 385 + return false; 386 + return !skb_queue_empty(&call->recvmsg_queue); 383 387 } 384 388 EXPORT_SYMBOL(rxrpc_kernel_check_life); 385 389
+2 -1
net/rxrpc/ar-internal.h
··· 545 545 RXRPC_CALL_KERNEL, /* The call was made by the kernel */ 546 546 RXRPC_CALL_UPGRADE, /* Service upgrade was requested for the call */ 547 547 RXRPC_CALL_EXCLUSIVE, /* The call uses a once-only connection */ 548 - RXRPC_CALL_RX_IS_IDLE, /* Reception is idle - send an ACK */ 548 + RXRPC_CALL_RX_IS_IDLE, /* recvmsg() is idle - send an ACK */ 549 + RXRPC_CALL_RECVMSG_READ_ALL, /* recvmsg() read all of the received data */ 549 550 }; 550 551 551 552 /*
+37 -1
net/rxrpc/input.c
··· 319 319 return true; 320 320 } 321 321 322 + /* 323 + * End the packet reception phase. 324 + */ 325 + static void rxrpc_end_rx_phase(struct rxrpc_call *call, rxrpc_serial_t serial) 326 + { 327 + rxrpc_seq_t whigh = READ_ONCE(call->rx_highest_seq); 328 + 329 + _enter("%d,%s", call->debug_id, rxrpc_call_states[call->state]); 330 + 331 + trace_rxrpc_receive(call, rxrpc_receive_end, 0, whigh); 332 + 333 + if (rxrpc_call_state(call) == RXRPC_CALL_CLIENT_RECV_REPLY) 334 + rxrpc_propose_delay_ACK(call, serial, rxrpc_propose_ack_terminal_ack); 335 + 336 + write_lock(&call->state_lock); 337 + 338 + switch (call->state) { 339 + case RXRPC_CALL_CLIENT_RECV_REPLY: 340 + __rxrpc_call_completed(call); 341 + write_unlock(&call->state_lock); 342 + break; 343 + 344 + case RXRPC_CALL_SERVER_RECV_REQUEST: 345 + call->state = RXRPC_CALL_SERVER_ACK_REQUEST; 346 + call->expect_req_by = jiffies + MAX_JIFFY_OFFSET; 347 + write_unlock(&call->state_lock); 348 + rxrpc_propose_delay_ACK(call, serial, 349 + rxrpc_propose_ack_processing_op); 350 + break; 351 + default: 352 + write_unlock(&call->state_lock); 353 + break; 354 + } 355 + } 356 + 322 357 static void rxrpc_input_update_ack_window(struct rxrpc_call *call, 323 358 rxrpc_seq_t window, rxrpc_seq_t wtop) 324 359 { ··· 372 337 373 338 __skb_queue_tail(&call->recvmsg_queue, skb); 374 339 rxrpc_input_update_ack_window(call, window, wtop); 375 - 376 340 trace_rxrpc_receive(call, last ? why + 1 : why, sp->hdr.serial, sp->hdr.seq); 341 + if (last) 342 + rxrpc_end_rx_phase(call, sp->hdr.serial); 377 343 } 378 344 379 345 /*
+62 -106
net/rxrpc/recvmsg.c
··· 101 101 } 102 102 103 103 /* 104 - * End the packet reception phase. 105 - */ 106 - static void rxrpc_end_rx_phase(struct rxrpc_call *call, rxrpc_serial_t serial) 107 - { 108 - rxrpc_seq_t whigh = READ_ONCE(call->rx_highest_seq); 109 - 110 - _enter("%d,%s", call->debug_id, rxrpc_call_states[call->state]); 111 - 112 - trace_rxrpc_receive(call, rxrpc_receive_end, 0, whigh); 113 - 114 - if (rxrpc_call_state(call) == RXRPC_CALL_CLIENT_RECV_REPLY) 115 - rxrpc_propose_delay_ACK(call, serial, rxrpc_propose_ack_terminal_ack); 116 - 117 - write_lock(&call->state_lock); 118 - 119 - switch (call->state) { 120 - case RXRPC_CALL_CLIENT_RECV_REPLY: 121 - __rxrpc_call_completed(call); 122 - write_unlock(&call->state_lock); 123 - rxrpc_poke_call(call, rxrpc_call_poke_complete); 124 - break; 125 - 126 - case RXRPC_CALL_SERVER_RECV_REQUEST: 127 - call->state = RXRPC_CALL_SERVER_ACK_REQUEST; 128 - call->expect_req_by = jiffies + MAX_JIFFY_OFFSET; 129 - write_unlock(&call->state_lock); 130 - rxrpc_propose_delay_ACK(call, serial, 131 - rxrpc_propose_ack_processing_op); 132 - break; 133 - default: 134 - write_unlock(&call->state_lock); 135 - break; 136 - } 137 - } 138 - 139 - /* 140 104 * Discard a packet we've used up and advance the Rx window by one. 141 105 */ 142 106 static void rxrpc_rotate_rx_window(struct rxrpc_call *call) ··· 130 166 131 167 trace_rxrpc_receive(call, last ? rxrpc_receive_rotate_last : rxrpc_receive_rotate, 132 168 serial, call->rx_consumed); 133 - if (last) { 134 - rxrpc_end_rx_phase(call, serial); 135 - return; 136 - } 169 + 170 + if (last) 171 + set_bit(RXRPC_CALL_RECVMSG_READ_ALL, &call->flags); 137 172 138 173 /* Check to see if there's an ACK that needs sending. */ 139 174 acked = atomic_add_return(call->rx_consumed - old_consumed, ··· 157 194 /* 158 195 * Deliver messages to a call. This keeps processing packets until the buffer 159 196 * is filled and we find either more DATA (returns 0) or the end of the DATA 160 - * (returns 1). If more packets are required, it returns -EAGAIN. 197 + * (returns 1). If more packets are required, it returns -EAGAIN and if the 198 + * call has failed it returns -EIO. 161 199 */ 162 200 static int rxrpc_recvmsg_data(struct socket *sock, struct rxrpc_call *call, 163 201 struct msghdr *msg, struct iov_iter *iter, ··· 174 210 rx_pkt_offset = call->rx_pkt_offset; 175 211 rx_pkt_len = call->rx_pkt_len; 176 212 177 - if (rxrpc_call_state(call) >= RXRPC_CALL_SERVER_ACK_REQUEST) { 213 + if (rxrpc_call_has_failed(call)) { 214 + seq = lower_32_bits(atomic64_read(&call->ackr_window)) - 1; 215 + ret = -EIO; 216 + goto done; 217 + } 218 + 219 + if (test_bit(RXRPC_CALL_RECVMSG_READ_ALL, &call->flags)) { 178 220 seq = lower_32_bits(atomic64_read(&call->ackr_window)) - 1; 179 221 ret = 1; 180 222 goto done; ··· 204 234 205 235 if (rx_pkt_offset == 0) { 206 236 ret2 = rxrpc_verify_data(call, skb); 207 - rx_pkt_offset = sp->offset; 208 - rx_pkt_len = sp->len; 209 237 trace_rxrpc_recvdata(call, rxrpc_recvmsg_next, seq, 210 - rx_pkt_offset, rx_pkt_len, ret2); 238 + sp->offset, sp->len, ret2); 211 239 if (ret2 < 0) { 240 + kdebug("verify = %d", ret2); 212 241 ret = ret2; 213 242 goto out; 214 243 } 244 + rx_pkt_offset = sp->offset; 245 + rx_pkt_len = sp->len; 215 246 } else { 216 247 trace_rxrpc_recvdata(call, rxrpc_recvmsg_cont, seq, 217 248 rx_pkt_offset, rx_pkt_len, 0); ··· 387 416 msg->msg_namelen = len; 388 417 } 389 418 390 - switch (rxrpc_call_state(call)) { 391 - case RXRPC_CALL_CLIENT_RECV_REPLY: 392 - case RXRPC_CALL_SERVER_RECV_REQUEST: 393 - case RXRPC_CALL_SERVER_ACK_REQUEST: 394 - ret = rxrpc_recvmsg_data(sock, call, msg, &msg->msg_iter, len, 395 - flags, &copied); 396 - if (ret == -EAGAIN) 397 - ret = 0; 398 - 399 - if (!skb_queue_empty(&call->recvmsg_queue)) 400 - rxrpc_notify_socket(call); 401 - break; 402 - default: 419 + ret = rxrpc_recvmsg_data(sock, call, msg, &msg->msg_iter, len, 420 + flags, &copied); 421 + if (ret == -EAGAIN) 403 422 ret = 0; 404 - break; 405 - } 406 - 423 + if (ret == -EIO) 424 + goto call_failed; 407 425 if (ret < 0) 408 426 goto error_unlock_call; 409 427 410 - if (rxrpc_call_is_complete(call)) { 411 - ret = rxrpc_recvmsg_term(call, msg); 412 - if (ret < 0) 413 - goto error_unlock_call; 414 - if (!(flags & MSG_PEEK)) 415 - rxrpc_release_call(rx, call); 416 - msg->msg_flags |= MSG_EOR; 417 - ret = 1; 418 - } 428 + if (rxrpc_call_is_complete(call) && 429 + skb_queue_empty(&call->recvmsg_queue)) 430 + goto call_complete; 431 + if (rxrpc_call_has_failed(call)) 432 + goto call_failed; 419 433 434 + rxrpc_notify_socket(call); 435 + goto not_yet_complete; 436 + 437 + call_failed: 438 + rxrpc_purge_queue(&call->recvmsg_queue); 439 + call_complete: 440 + ret = rxrpc_recvmsg_term(call, msg); 441 + if (ret < 0) 442 + goto error_unlock_call; 443 + if (!(flags & MSG_PEEK)) 444 + rxrpc_release_call(rx, call); 445 + msg->msg_flags |= MSG_EOR; 446 + ret = 1; 447 + 448 + not_yet_complete: 420 449 if (ret == 0) 421 450 msg->msg_flags |= MSG_MORE; 422 451 else ··· 479 508 size_t offset = 0; 480 509 int ret; 481 510 482 - _enter("{%d,%s},%zu,%d", 483 - call->debug_id, rxrpc_call_states[call->state], 484 - *_len, want_more); 485 - 486 - ASSERTCMP(call->state, !=, RXRPC_CALL_SERVER_SECURING); 511 + _enter("{%d},%zu,%d", call->debug_id, *_len, want_more); 487 512 488 513 mutex_lock(&call->user_mutex); 489 514 490 - switch (rxrpc_call_state(call)) { 491 - case RXRPC_CALL_CLIENT_RECV_REPLY: 492 - case RXRPC_CALL_SERVER_RECV_REQUEST: 493 - case RXRPC_CALL_SERVER_ACK_REQUEST: 494 - ret = rxrpc_recvmsg_data(sock, call, NULL, iter, 495 - *_len, 0, &offset); 496 - *_len -= offset; 497 - if (ret < 0) 498 - goto out; 499 - 500 - /* We can only reach here with a partially full buffer if we 501 - * have reached the end of the data. We must otherwise have a 502 - * full buffer or have been given -EAGAIN. 503 - */ 504 - if (ret == 1) { 505 - if (iov_iter_count(iter) > 0) 506 - goto short_data; 507 - if (!want_more) 508 - goto read_phase_complete; 509 - ret = 0; 510 - goto out; 511 - } 512 - 513 - if (!want_more) 514 - goto excess_data; 515 + ret = rxrpc_recvmsg_data(sock, call, NULL, iter, *_len, 0, &offset); 516 + *_len -= offset; 517 + if (ret == -EIO) 518 + goto call_failed; 519 + if (ret < 0) 515 520 goto out; 516 521 517 - case RXRPC_CALL_COMPLETE: 518 - goto call_complete; 519 - 520 - default: 521 - ret = -EINPROGRESS; 522 + /* We can only reach here with a partially full buffer if we have 523 + * reached the end of the data. We must otherwise have a full buffer 524 + * or have been given -EAGAIN. 525 + */ 526 + if (ret == 1) { 527 + if (iov_iter_count(iter) > 0) 528 + goto short_data; 529 + if (!want_more) 530 + goto read_phase_complete; 531 + ret = 0; 522 532 goto out; 523 533 } 534 + 535 + if (!want_more) 536 + goto excess_data; 537 + goto out; 524 538 525 539 read_phase_complete: 526 540 ret = 1; ··· 528 572 0, -EMSGSIZE); 529 573 ret = -EMSGSIZE; 530 574 goto out; 531 - call_complete: 575 + call_failed: 532 576 *_abort = call->abort_code; 533 577 ret = call->error; 534 578 if (call->completion == RXRPC_CALL_SUCCEEDED) {