Skip to content

Commit 81bacb4

Browse files
dhowellsgregkh
authored andcommitted
rxrpc: Fix call interruptibility handling
[ Upstream commit e138aa7 ] Fix the interruptibility of kernel-initiated client calls so that they're either only interruptible when they're waiting for a call slot to come available or they're not interruptible at all. Either way, they're not interruptible during transmission. This should help prevent StoreData calls from being interrupted when writeback is in progress. It doesn't, however, handle interruption during the receive phase. Userspace-initiated calls are still interruptable. After the signal has been handled, sendmsg() will return the amount of data copied out of the buffer and userspace can perform another sendmsg() call to continue transmission. Fixes: bc5e3a5 ("rxrpc: Use MSG_WAITALL to tell sendmsg() to temporarily ignore signals") Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent f58ed36 commit 81bacb4

7 files changed

Lines changed: 60 additions & 19 deletions

File tree

‎fs/afs/rxrpc.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,8 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp)
414414
afs_wake_up_async_call :
415415
afs_wake_up_call_waiter),
416416
call->upgrade,
417-
call->intr,
417+
(call->intr ? RXRPC_PREINTERRUPTIBLE :
418+
RXRPC_UNINTERRUPTIBLE),
418419
call->debug_id);
419420
if (IS_ERR(rxcall)) {
420421
ret = PTR_ERR(rxcall);

‎include/net/af_rxrpc.h‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ struct sock;
1616
struct socket;
1717
struct rxrpc_call;
1818

19+
enum rxrpc_interruptibility {
20+
RXRPC_INTERRUPTIBLE, /* Call is interruptible */
21+
RXRPC_PREINTERRUPTIBLE, /* Call can be cancelled whilst waiting for a slot */
22+
RXRPC_UNINTERRUPTIBLE, /* Call should not be interruptible at all */
23+
};
24+
1925
/*
2026
* Debug ID counter for tracing.
2127
*/
@@ -41,7 +47,7 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *,
4147
gfp_t,
4248
rxrpc_notify_rx_t,
4349
bool,
44-
bool,
50+
enum rxrpc_interruptibility,
4551
unsigned int);
4652
int rxrpc_kernel_send_data(struct socket *, struct rxrpc_call *,
4753
struct msghdr *, size_t,

‎net/rxrpc/af_rxrpc.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,
285285
gfp_t gfp,
286286
rxrpc_notify_rx_t notify_rx,
287287
bool upgrade,
288-
bool intr,
288+
enum rxrpc_interruptibility interruptibility,
289289
unsigned int debug_id)
290290
{
291291
struct rxrpc_conn_parameters cp;
@@ -310,7 +310,7 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,
310310
memset(&p, 0, sizeof(p));
311311
p.user_call_ID = user_call_ID;
312312
p.tx_total_len = tx_total_len;
313-
p.intr = intr;
313+
p.interruptibility = interruptibility;
314314

315315
memset(&cp, 0, sizeof(cp));
316316
cp.local = rx->local;

‎net/rxrpc/ar-internal.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,6 @@ enum rxrpc_call_flag {
489489
RXRPC_CALL_BEGAN_RX_TIMER, /* We began the expect_rx_by timer */
490490
RXRPC_CALL_RX_HEARD, /* The peer responded at least once to this call */
491491
RXRPC_CALL_RX_UNDERRUN, /* Got data underrun */
492-
RXRPC_CALL_IS_INTR, /* The call is interruptible */
493492
RXRPC_CALL_DISCONNECTED, /* The call has been disconnected */
494493
};
495494

@@ -598,6 +597,7 @@ struct rxrpc_call {
598597
atomic_t usage;
599598
u16 service_id; /* service ID */
600599
u8 security_ix; /* Security type */
600+
enum rxrpc_interruptibility interruptibility; /* At what point call may be interrupted */
601601
u32 call_id; /* call ID on connection */
602602
u32 cid; /* connection ID plus channel index */
603603
int debug_id; /* debug ID for printks */
@@ -720,7 +720,7 @@ struct rxrpc_call_params {
720720
u32 normal; /* Max time since last call packet (msec) */
721721
} timeouts;
722722
u8 nr_timeouts; /* Number of timeouts specified */
723-
bool intr; /* The call is interruptible */
723+
enum rxrpc_interruptibility interruptibility; /* How is interruptible is the call? */
724724
};
725725

726726
struct rxrpc_send_params {

‎net/rxrpc/call_object.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,7 @@ struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *rx,
237237
return call;
238238
}
239239

240-
if (p->intr)
241-
__set_bit(RXRPC_CALL_IS_INTR, &call->flags);
240+
call->interruptibility = p->interruptibility;
242241
call->tx_total_len = p->tx_total_len;
243242
trace_rxrpc_call(call->debug_id, rxrpc_call_new_client,
244243
atomic_read(&call->usage),

‎net/rxrpc/conn_client.c‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,13 +655,20 @@ static int rxrpc_wait_for_channel(struct rxrpc_call *call, gfp_t gfp)
655655

656656
add_wait_queue_exclusive(&call->waitq, &myself);
657657
for (;;) {
658-
if (test_bit(RXRPC_CALL_IS_INTR, &call->flags))
658+
switch (call->interruptibility) {
659+
case RXRPC_INTERRUPTIBLE:
660+
case RXRPC_PREINTERRUPTIBLE:
659661
set_current_state(TASK_INTERRUPTIBLE);
660-
else
662+
break;
663+
case RXRPC_UNINTERRUPTIBLE:
664+
default:
661665
set_current_state(TASK_UNINTERRUPTIBLE);
666+
break;
667+
}
662668
if (call->call_id)
663669
break;
664-
if (test_bit(RXRPC_CALL_IS_INTR, &call->flags) &&
670+
if ((call->interruptibility == RXRPC_INTERRUPTIBLE ||
671+
call->interruptibility == RXRPC_PREINTERRUPTIBLE) &&
665672
signal_pending(current)) {
666673
ret = -ERESTARTSYS;
667674
break;

‎net/rxrpc/sendmsg.c‎

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static int rxrpc_wait_for_tx_window_intr(struct rxrpc_sock *rx,
6262
* Wait for space to appear in the Tx queue uninterruptibly, but with
6363
* a timeout of 2*RTT if no progress was made and a signal occurred.
6464
*/
65-
static int rxrpc_wait_for_tx_window_nonintr(struct rxrpc_sock *rx,
65+
static int rxrpc_wait_for_tx_window_waitall(struct rxrpc_sock *rx,
6666
struct rxrpc_call *call)
6767
{
6868
rxrpc_seq_t tx_start, tx_win;
@@ -87,8 +87,7 @@ static int rxrpc_wait_for_tx_window_nonintr(struct rxrpc_sock *rx,
8787
if (call->state >= RXRPC_CALL_COMPLETE)
8888
return call->error;
8989

90-
if (test_bit(RXRPC_CALL_IS_INTR, &call->flags) &&
91-
timeout == 0 &&
90+
if (timeout == 0 &&
9291
tx_win == tx_start && signal_pending(current))
9392
return -EINTR;
9493

@@ -102,6 +101,26 @@ static int rxrpc_wait_for_tx_window_nonintr(struct rxrpc_sock *rx,
102101
}
103102
}
104103

104+
/*
105+
* Wait for space to appear in the Tx queue uninterruptibly.
106+
*/
107+
static int rxrpc_wait_for_tx_window_nonintr(struct rxrpc_sock *rx,
108+
struct rxrpc_call *call,
109+
long *timeo)
110+
{
111+
for (;;) {
112+
set_current_state(TASK_UNINTERRUPTIBLE);
113+
if (rxrpc_check_tx_space(call, NULL))
114+
return 0;
115+
116+
if (call->state >= RXRPC_CALL_COMPLETE)
117+
return call->error;
118+
119+
trace_rxrpc_transmit(call, rxrpc_transmit_wait);
120+
*timeo = schedule_timeout(*timeo);
121+
}
122+
}
123+
105124
/*
106125
* wait for space to appear in the transmit/ACK window
107126
* - caller holds the socket locked
@@ -119,10 +138,19 @@ static int rxrpc_wait_for_tx_window(struct rxrpc_sock *rx,
119138

120139
add_wait_queue(&call->waitq, &myself);
121140

122-
if (waitall)
123-
ret = rxrpc_wait_for_tx_window_nonintr(rx, call);
124-
else
125-
ret = rxrpc_wait_for_tx_window_intr(rx, call, timeo);
141+
switch (call->interruptibility) {
142+
case RXRPC_INTERRUPTIBLE:
143+
if (waitall)
144+
ret = rxrpc_wait_for_tx_window_waitall(rx, call);
145+
else
146+
ret = rxrpc_wait_for_tx_window_intr(rx, call, timeo);
147+
break;
148+
case RXRPC_PREINTERRUPTIBLE:
149+
case RXRPC_UNINTERRUPTIBLE:
150+
default:
151+
ret = rxrpc_wait_for_tx_window_nonintr(rx, call, timeo);
152+
break;
153+
}
126154

127155
remove_wait_queue(&call->waitq, &myself);
128156
set_current_state(TASK_RUNNING);
@@ -628,7 +656,7 @@ int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)
628656
.call.tx_total_len = -1,
629657
.call.user_call_ID = 0,
630658
.call.nr_timeouts = 0,
631-
.call.intr = true,
659+
.call.interruptibility = RXRPC_INTERRUPTIBLE,
632660
.abort_code = 0,
633661
.command = RXRPC_CMD_SEND_DATA,
634662
.exclusive = false,

0 commit comments

Comments
 (0)