Commit fb7cba61 authored by David S. Miller's avatar David S. Miller

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: default avatarDavid S. Miller <davem@davemloft.net>
parents 4f163bf8 db099c62
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
#define AFSPATHMAX 1024 /* Maximum length of a pathname plus NUL */ #define AFSPATHMAX 1024 /* Maximum length of a pathname plus NUL */
#define AFSOPAQUEMAX 1024 /* Maximum length of an opaque field */ #define AFSOPAQUEMAX 1024 /* Maximum length of an opaque field */
#define AFS_VL_MAX_LIFESPAN (120 * HZ) #define AFS_VL_MAX_LIFESPAN 120
#define AFS_PROBE_MAX_LIFESPAN (30 * HZ) #define AFS_PROBE_MAX_LIFESPAN 30
typedef u64 afs_volid_t; typedef u64 afs_volid_t;
typedef u64 afs_vnodeid_t; typedef u64 afs_vnodeid_t;
......
...@@ -128,7 +128,7 @@ struct afs_call { ...@@ -128,7 +128,7 @@ struct afs_call {
spinlock_t state_lock; spinlock_t state_lock;
int error; /* error code */ int error; /* error code */
u32 abort_code; /* Remote abort ID or 0 */ u32 abort_code; /* Remote abort ID or 0 */
unsigned int max_lifespan; /* Maximum lifespan to set if not 0 */ unsigned int max_lifespan; /* Maximum lifespan in secs to set if not 0 */
unsigned request_size; /* size of request data */ unsigned request_size; /* size of request data */
unsigned reply_max; /* maximum size of reply */ unsigned reply_max; /* maximum size of reply */
unsigned count2; /* count used in unmarshalling */ unsigned count2; /* count used in unmarshalling */
......
...@@ -335,7 +335,9 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp) ...@@ -335,7 +335,9 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp)
/* create a call */ /* create a call */
rxcall = rxrpc_kernel_begin_call(call->net->socket, srx, call->key, rxcall = rxrpc_kernel_begin_call(call->net->socket, srx, call->key,
(unsigned long)call, (unsigned long)call,
tx_total_len, gfp, tx_total_len,
call->max_lifespan,
gfp,
(call->async ? (call->async ?
afs_wake_up_async_call : afs_wake_up_async_call :
afs_wake_up_call_waiter), 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) ...@@ -350,10 +352,6 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp)
} }
call->rxcall = rxcall; call->rxcall = rxcall;
if (call->max_lifespan)
rxrpc_kernel_set_max_life(call->net->socket, rxcall,
call->max_lifespan);
call->issue_time = ktime_get_real(); call->issue_time = ktime_get_real();
/* send the request */ /* send the request */
......
...@@ -40,16 +40,17 @@ typedef void (*rxrpc_user_attach_call_t)(struct rxrpc_call *, unsigned long); ...@@ -40,16 +40,17 @@ typedef void (*rxrpc_user_attach_call_t)(struct rxrpc_call *, unsigned long);
void rxrpc_kernel_new_call_notification(struct socket *, void rxrpc_kernel_new_call_notification(struct socket *,
rxrpc_notify_new_call_t, rxrpc_notify_new_call_t,
rxrpc_discard_new_call_t); rxrpc_discard_new_call_t);
struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *, struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,
struct sockaddr_rxrpc *, struct sockaddr_rxrpc *srx,
struct key *, struct key *key,
unsigned long, unsigned long user_call_ID,
s64, s64 tx_total_len,
gfp_t, u32 hard_timeout,
rxrpc_notify_rx_t, gfp_t gfp,
bool, rxrpc_notify_rx_t notify_rx,
enum rxrpc_interruptibility, bool upgrade,
unsigned int); enum rxrpc_interruptibility interruptibility,
unsigned int debug_id);
int rxrpc_kernel_send_data(struct socket *, struct rxrpc_call *, int rxrpc_kernel_send_data(struct socket *, struct rxrpc_call *,
struct msghdr *, size_t, struct msghdr *, size_t,
rxrpc_notify_end_tx_t); rxrpc_notify_end_tx_t);
......
...@@ -265,6 +265,7 @@ static int rxrpc_listen(struct socket *sock, int backlog) ...@@ -265,6 +265,7 @@ static int rxrpc_listen(struct socket *sock, int backlog)
* @key: The security context to use (defaults to socket setting) * @key: The security context to use (defaults to socket setting)
* @user_call_ID: The ID to use * @user_call_ID: The ID to use
* @tx_total_len: Total length of data to transmit during the call (or -1) * @tx_total_len: Total length of data to transmit during the call (or -1)
* @hard_timeout: The maximum lifespan of the call in sec
* @gfp: The allocation constraints * @gfp: The allocation constraints
* @notify_rx: Where to send notifications instead of socket queue * @notify_rx: Where to send notifications instead of socket queue
* @upgrade: Request service upgrade for call * @upgrade: Request service upgrade for call
...@@ -283,6 +284,7 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock, ...@@ -283,6 +284,7 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,
struct key *key, struct key *key,
unsigned long user_call_ID, unsigned long user_call_ID,
s64 tx_total_len, s64 tx_total_len,
u32 hard_timeout,
gfp_t gfp, gfp_t gfp,
rxrpc_notify_rx_t notify_rx, rxrpc_notify_rx_t notify_rx,
bool upgrade, bool upgrade,
...@@ -313,6 +315,7 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock, ...@@ -313,6 +315,7 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,
p.tx_total_len = tx_total_len; p.tx_total_len = tx_total_len;
p.interruptibility = interruptibility; p.interruptibility = interruptibility;
p.kernel = true; p.kernel = true;
p.timeouts.hard = hard_timeout;
memset(&cp, 0, sizeof(cp)); memset(&cp, 0, sizeof(cp));
cp.local = rx->local; cp.local = rx->local;
......
...@@ -616,6 +616,7 @@ struct rxrpc_call { ...@@ -616,6 +616,7 @@ struct rxrpc_call {
unsigned long expect_term_by; /* When we expect call termination by */ unsigned long expect_term_by; /* When we expect call termination by */
u32 next_rx_timo; /* Timeout for next Rx packet (jif) */ u32 next_rx_timo; /* Timeout for next Rx packet (jif) */
u32 next_req_timo; /* Timeout for next Rx request packet (jif) */ u32 next_req_timo; /* Timeout for next Rx request packet (jif) */
u32 hard_timo; /* Maximum lifetime or 0 (jif) */
struct timer_list timer; /* Combined event timer */ struct timer_list timer; /* Combined event timer */
struct work_struct destroyer; /* In-process-context destroyer */ struct work_struct destroyer; /* In-process-context destroyer */
rxrpc_notify_rx_t notify_rx; /* kernel service Rx notification function */ rxrpc_notify_rx_t notify_rx; /* kernel service Rx notification function */
......
...@@ -226,6 +226,13 @@ static struct rxrpc_call *rxrpc_alloc_client_call(struct rxrpc_sock *rx, ...@@ -226,6 +226,13 @@ static struct rxrpc_call *rxrpc_alloc_client_call(struct rxrpc_sock *rx,
if (cp->exclusive) if (cp->exclusive)
__set_bit(RXRPC_CALL_EXCLUSIVE, &call->flags); __set_bit(RXRPC_CALL_EXCLUSIVE, &call->flags);
if (p->timeouts.normal)
call->next_rx_timo = min(msecs_to_jiffies(p->timeouts.normal), 1UL);
if (p->timeouts.idle)
call->next_req_timo = min(msecs_to_jiffies(p->timeouts.idle), 1UL);
if (p->timeouts.hard)
call->hard_timo = p->timeouts.hard * HZ;
ret = rxrpc_init_client_call_security(call); ret = rxrpc_init_client_call_security(call);
if (ret < 0) { if (ret < 0) {
rxrpc_prefail_call(call, RXRPC_CALL_LOCAL_ERROR, ret); rxrpc_prefail_call(call, RXRPC_CALL_LOCAL_ERROR, ret);
...@@ -257,7 +264,7 @@ void rxrpc_start_call_timer(struct rxrpc_call *call) ...@@ -257,7 +264,7 @@ void rxrpc_start_call_timer(struct rxrpc_call *call)
call->keepalive_at = j; call->keepalive_at = j;
call->expect_rx_by = j; call->expect_rx_by = j;
call->expect_req_by = j; call->expect_req_by = j;
call->expect_term_by = j; call->expect_term_by = j + call->hard_timo;
call->timer.expires = now; call->timer.expires = now;
} }
......
...@@ -651,15 +651,19 @@ int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len) ...@@ -651,15 +651,19 @@ int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)
if (IS_ERR(call)) if (IS_ERR(call))
return PTR_ERR(call); return PTR_ERR(call);
/* ... and we have the call lock. */ /* ... and we have the call lock. */
p.call.nr_timeouts = 0;
ret = 0; ret = 0;
if (rxrpc_call_is_complete(call)) if (rxrpc_call_is_complete(call))
goto out_put_unlock; goto out_put_unlock;
} else { } else {
switch (rxrpc_call_state(call)) { switch (rxrpc_call_state(call)) {
case RXRPC_CALL_UNINITIALISED:
case RXRPC_CALL_CLIENT_AWAIT_CONN: case RXRPC_CALL_CLIENT_AWAIT_CONN:
case RXRPC_CALL_SERVER_PREALLOC:
case RXRPC_CALL_SERVER_SECURING: case RXRPC_CALL_SERVER_SECURING:
if (p.command == RXRPC_CMD_SEND_ABORT)
break;
fallthrough;
case RXRPC_CALL_UNINITIALISED:
case RXRPC_CALL_SERVER_PREALLOC:
rxrpc_put_call(call, rxrpc_call_put_sendmsg); rxrpc_put_call(call, rxrpc_call_put_sendmsg);
ret = -EBUSY; ret = -EBUSY;
goto error_release_sock; goto error_release_sock;
...@@ -699,7 +703,7 @@ int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len) ...@@ -699,7 +703,7 @@ int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)
fallthrough; fallthrough;
case 1: case 1:
if (p.call.timeouts.hard > 0) { if (p.call.timeouts.hard > 0) {
j = msecs_to_jiffies(p.call.timeouts.hard); j = p.call.timeouts.hard * HZ;
now = jiffies; now = jiffies;
j += now; j += now;
WRITE_ONCE(call->expect_term_by, j); WRITE_ONCE(call->expect_term_by, j);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment