Skip to content

Commit fb7cba6

Browse files
committed
Merge branch 'rxrpc-timeout-fixes'
David Howells says: ==================== rxrpc: Timeout handling fixes Here are three patches to fix timeouts handling in AF_RXRPC: (1) The hard call timeout should be interpreted in seconds, not milliseconds. (2) Allow a waiting call to be aborted (thereby cancelling the call) in the case a signal interrupts sendmsg() and leaves it hanging until it is granted a channel on a connection. (3) Kernel-generated calls get the timer started on them even if they're still waiting to be attached to a connection. If the timer expires before the wait is complete and a conn is attached, an oops will occur. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 4f163bf + db099c6 commit fb7cba6

File tree

8 files changed

+36
-22
lines changed

8 files changed

+36
-22
lines changed

fs/afs/afs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#define AFSPATHMAX 1024 /* Maximum length of a pathname plus NUL */
2020
#define AFSOPAQUEMAX 1024 /* Maximum length of an opaque field */
2121

22-
#define AFS_VL_MAX_LIFESPAN (120 * HZ)
23-
#define AFS_PROBE_MAX_LIFESPAN (30 * HZ)
22+
#define AFS_VL_MAX_LIFESPAN 120
23+
#define AFS_PROBE_MAX_LIFESPAN 30
2424

2525
typedef u64 afs_volid_t;
2626
typedef u64 afs_vnodeid_t;

fs/afs/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ struct afs_call {
128128
spinlock_t state_lock;
129129
int error; /* error code */
130130
u32 abort_code; /* Remote abort ID or 0 */
131-
unsigned int max_lifespan; /* Maximum lifespan to set if not 0 */
131+
unsigned int max_lifespan; /* Maximum lifespan in secs to set if not 0 */
132132
unsigned request_size; /* size of request data */
133133
unsigned reply_max; /* maximum size of reply */
134134
unsigned count2; /* count used in unmarshalling */

fs/afs/rxrpc.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,9 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp)
335335
/* create a call */
336336
rxcall = rxrpc_kernel_begin_call(call->net->socket, srx, call->key,
337337
(unsigned long)call,
338-
tx_total_len, gfp,
338+
tx_total_len,
339+
call->max_lifespan,
340+
gfp,
339341
(call->async ?
340342
afs_wake_up_async_call :
341343
afs_wake_up_call_waiter),
@@ -350,10 +352,6 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp)
350352
}
351353

352354
call->rxcall = rxcall;
353-
354-
if (call->max_lifespan)
355-
rxrpc_kernel_set_max_life(call->net->socket, rxcall,
356-
call->max_lifespan);
357355
call->issue_time = ktime_get_real();
358356

359357
/* send the request */

include/net/af_rxrpc.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,17 @@ typedef void (*rxrpc_user_attach_call_t)(struct rxrpc_call *, unsigned long);
4040
void rxrpc_kernel_new_call_notification(struct socket *,
4141
rxrpc_notify_new_call_t,
4242
rxrpc_discard_new_call_t);
43-
struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *,
44-
struct sockaddr_rxrpc *,
45-
struct key *,
46-
unsigned long,
47-
s64,
48-
gfp_t,
49-
rxrpc_notify_rx_t,
50-
bool,
51-
enum rxrpc_interruptibility,
52-
unsigned int);
43+
struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,
44+
struct sockaddr_rxrpc *srx,
45+
struct key *key,
46+
unsigned long user_call_ID,
47+
s64 tx_total_len,
48+
u32 hard_timeout,
49+
gfp_t gfp,
50+
rxrpc_notify_rx_t notify_rx,
51+
bool upgrade,
52+
enum rxrpc_interruptibility interruptibility,
53+
unsigned int debug_id);
5354
int rxrpc_kernel_send_data(struct socket *, struct rxrpc_call *,
5455
struct msghdr *, size_t,
5556
rxrpc_notify_end_tx_t);

net/rxrpc/af_rxrpc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ static int rxrpc_listen(struct socket *sock, int backlog)
265265
* @key: The security context to use (defaults to socket setting)
266266
* @user_call_ID: The ID to use
267267
* @tx_total_len: Total length of data to transmit during the call (or -1)
268+
* @hard_timeout: The maximum lifespan of the call in sec
268269
* @gfp: The allocation constraints
269270
* @notify_rx: Where to send notifications instead of socket queue
270271
* @upgrade: Request service upgrade for call
@@ -283,6 +284,7 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,
283284
struct key *key,
284285
unsigned long user_call_ID,
285286
s64 tx_total_len,
287+
u32 hard_timeout,
286288
gfp_t gfp,
287289
rxrpc_notify_rx_t notify_rx,
288290
bool upgrade,
@@ -313,6 +315,7 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,
313315
p.tx_total_len = tx_total_len;
314316
p.interruptibility = interruptibility;
315317
p.kernel = true;
318+
p.timeouts.hard = hard_timeout;
316319

317320
memset(&cp, 0, sizeof(cp));
318321
cp.local = rx->local;

net/rxrpc/ar-internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ struct rxrpc_call {
616616
unsigned long expect_term_by; /* When we expect call termination by */
617617
u32 next_rx_timo; /* Timeout for next Rx packet (jif) */
618618
u32 next_req_timo; /* Timeout for next Rx request packet (jif) */
619+
u32 hard_timo; /* Maximum lifetime or 0 (jif) */
619620
struct timer_list timer; /* Combined event timer */
620621
struct work_struct destroyer; /* In-process-context destroyer */
621622
rxrpc_notify_rx_t notify_rx; /* kernel service Rx notification function */

net/rxrpc/call_object.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ static struct rxrpc_call *rxrpc_alloc_client_call(struct rxrpc_sock *rx,
226226
if (cp->exclusive)
227227
__set_bit(RXRPC_CALL_EXCLUSIVE, &call->flags);
228228

229+
if (p->timeouts.normal)
230+
call->next_rx_timo = min(msecs_to_jiffies(p->timeouts.normal), 1UL);
231+
if (p->timeouts.idle)
232+
call->next_req_timo = min(msecs_to_jiffies(p->timeouts.idle), 1UL);
233+
if (p->timeouts.hard)
234+
call->hard_timo = p->timeouts.hard * HZ;
235+
229236
ret = rxrpc_init_client_call_security(call);
230237
if (ret < 0) {
231238
rxrpc_prefail_call(call, RXRPC_CALL_LOCAL_ERROR, ret);
@@ -257,7 +264,7 @@ void rxrpc_start_call_timer(struct rxrpc_call *call)
257264
call->keepalive_at = j;
258265
call->expect_rx_by = j;
259266
call->expect_req_by = j;
260-
call->expect_term_by = j;
267+
call->expect_term_by = j + call->hard_timo;
261268
call->timer.expires = now;
262269
}
263270

net/rxrpc/sendmsg.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -651,15 +651,19 @@ int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)
651651
if (IS_ERR(call))
652652
return PTR_ERR(call);
653653
/* ... and we have the call lock. */
654+
p.call.nr_timeouts = 0;
654655
ret = 0;
655656
if (rxrpc_call_is_complete(call))
656657
goto out_put_unlock;
657658
} else {
658659
switch (rxrpc_call_state(call)) {
659-
case RXRPC_CALL_UNINITIALISED:
660660
case RXRPC_CALL_CLIENT_AWAIT_CONN:
661-
case RXRPC_CALL_SERVER_PREALLOC:
662661
case RXRPC_CALL_SERVER_SECURING:
662+
if (p.command == RXRPC_CMD_SEND_ABORT)
663+
break;
664+
fallthrough;
665+
case RXRPC_CALL_UNINITIALISED:
666+
case RXRPC_CALL_SERVER_PREALLOC:
663667
rxrpc_put_call(call, rxrpc_call_put_sendmsg);
664668
ret = -EBUSY;
665669
goto error_release_sock;
@@ -699,7 +703,7 @@ int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)
699703
fallthrough;
700704
case 1:
701705
if (p.call.timeouts.hard > 0) {
702-
j = msecs_to_jiffies(p.call.timeouts.hard);
706+
j = p.call.timeouts.hard * HZ;
703707
now = jiffies;
704708
j += now;
705709
WRITE_ONCE(call->expect_term_by, j);

0 commit comments

Comments
 (0)