]> git.baikalelectronics.ru Git - kernel.git/commitdiff
rxrpc: Fix call interruptibility handling
authorDavid Howells <dhowells@redhat.com>
Fri, 13 Mar 2020 09:22:09 +0000 (09:22 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 17 Apr 2020 08:49:57 +0000 (10:49 +0200)
[ Upstream commit 68c3c9ad70ee96bc13ec2ee00246f76add29060a ]

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: 8d0c6fe295af ("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>
fs/afs/rxrpc.c
include/net/af_rxrpc.h
net/rxrpc/af_rxrpc.c
net/rxrpc/ar-internal.h
net/rxrpc/call_object.c
net/rxrpc/conn_client.c
net/rxrpc/sendmsg.c

index ef1d09f8920bd9aefd5517c2fadbd7f5aaa80026..52aa90fb4fbd9d18032e741a644e8e64489a4bea 100644 (file)
@@ -414,7 +414,8 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp)
                                          afs_wake_up_async_call :
                                          afs_wake_up_call_waiter),
                                         call->upgrade,
-                                        call->intr,
+                                        (call->intr ? RXRPC_PREINTERRUPTIBLE :
+                                         RXRPC_UNINTERRUPTIBLE),
                                         call->debug_id);
        if (IS_ERR(rxcall)) {
                ret = PTR_ERR(rxcall);
index 299240df79e4a324b221f114e498e695bd289c38..04e97bab6f28b9eff4d1efba213c667b9ad596af 100644 (file)
@@ -16,6 +16,12 @@ struct sock;
 struct socket;
 struct rxrpc_call;
 
+enum rxrpc_interruptibility {
+       RXRPC_INTERRUPTIBLE,    /* Call is interruptible */
+       RXRPC_PREINTERRUPTIBLE, /* Call can be cancelled whilst waiting for a slot */
+       RXRPC_UNINTERRUPTIBLE,  /* Call should not be interruptible at all */
+};
+
 /*
  * Debug ID counter for tracing.
  */
@@ -41,7 +47,7 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *,
                                           gfp_t,
                                           rxrpc_notify_rx_t,
                                           bool,
-                                          bool,
+                                          enum rxrpc_interruptibility,
                                           unsigned int);
 int rxrpc_kernel_send_data(struct socket *, struct rxrpc_call *,
                           struct msghdr *, size_t,
index a293238fe1e7e1acb1d0c11ab20c32f971f44fb4..2921fc27671347073934666ef6025a09e29f4311 100644 (file)
@@ -285,7 +285,7 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,
                                           gfp_t gfp,
                                           rxrpc_notify_rx_t notify_rx,
                                           bool upgrade,
-                                          bool intr,
+                                          enum rxrpc_interruptibility interruptibility,
                                           unsigned int debug_id)
 {
        struct rxrpc_conn_parameters cp;
@@ -310,7 +310,7 @@ struct rxrpc_call *rxrpc_kernel_begin_call(struct socket *sock,
        memset(&p, 0, sizeof(p));
        p.user_call_ID = user_call_ID;
        p.tx_total_len = tx_total_len;
-       p.intr = intr;
+       p.interruptibility = interruptibility;
 
        memset(&cp, 0, sizeof(cp));
        cp.local                = rx->local;
index 394d18857979acf669691221d90260d1a635f7f1..3eb1ab40ca5cb5933c68f0e87b9551d13f6eda5a 100644 (file)
@@ -489,7 +489,6 @@ enum rxrpc_call_flag {
        RXRPC_CALL_BEGAN_RX_TIMER,      /* We began the expect_rx_by timer */
        RXRPC_CALL_RX_HEARD,            /* The peer responded at least once to this call */
        RXRPC_CALL_RX_UNDERRUN,         /* Got data underrun */
-       RXRPC_CALL_IS_INTR,             /* The call is interruptible */
        RXRPC_CALL_DISCONNECTED,        /* The call has been disconnected */
 };
 
@@ -598,6 +597,7 @@ struct rxrpc_call {
        atomic_t                usage;
        u16                     service_id;     /* service ID */
        u8                      security_ix;    /* Security type */
+       enum rxrpc_interruptibility interruptibility; /* At what point call may be interrupted */
        u32                     call_id;        /* call ID on connection  */
        u32                     cid;            /* connection ID plus channel index */
        int                     debug_id;       /* debug ID for printks */
@@ -720,7 +720,7 @@ struct rxrpc_call_params {
                u32             normal;         /* Max time since last call packet (msec) */
        } timeouts;
        u8                      nr_timeouts;    /* Number of timeouts specified */
-       bool                    intr;           /* The call is interruptible */
+       enum rxrpc_interruptibility interruptibility; /* How is interruptible is the call? */
 };
 
 struct rxrpc_send_params {
index c9f34b0a11df488731d66182e0aa0bf5223e7780..f07970207b5447079c71d9cbd88501f07cafa53f 100644 (file)
@@ -237,8 +237,7 @@ struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *rx,
                return call;
        }
 
-       if (p->intr)
-               __set_bit(RXRPC_CALL_IS_INTR, &call->flags);
+       call->interruptibility = p->interruptibility;
        call->tx_total_len = p->tx_total_len;
        trace_rxrpc_call(call->debug_id, rxrpc_call_new_client,
                         atomic_read(&call->usage),
index ea7d4c21f88933d1fd23a6571b2931f82c151265..f2a1a5dbb5a7bb21d47f33f3e2cf8fd1acd88192 100644 (file)
@@ -655,13 +655,20 @@ static int rxrpc_wait_for_channel(struct rxrpc_call *call, gfp_t gfp)
 
                add_wait_queue_exclusive(&call->waitq, &myself);
                for (;;) {
-                       if (test_bit(RXRPC_CALL_IS_INTR, &call->flags))
+                       switch (call->interruptibility) {
+                       case RXRPC_INTERRUPTIBLE:
+                       case RXRPC_PREINTERRUPTIBLE:
                                set_current_state(TASK_INTERRUPTIBLE);
-                       else
+                               break;
+                       case RXRPC_UNINTERRUPTIBLE:
+                       default:
                                set_current_state(TASK_UNINTERRUPTIBLE);
+                               break;
+                       }
                        if (call->call_id)
                                break;
-                       if (test_bit(RXRPC_CALL_IS_INTR, &call->flags) &&
+                       if ((call->interruptibility == RXRPC_INTERRUPTIBLE ||
+                            call->interruptibility == RXRPC_PREINTERRUPTIBLE) &&
                            signal_pending(current)) {
                                ret = -ERESTARTSYS;
                                break;
index 1cbd43eeda9377c1e6501ae1f7586d516746617e..0fcf157aa09f8350b156234693b700ac3a89dbcf 100644 (file)
@@ -62,7 +62,7 @@ static int rxrpc_wait_for_tx_window_intr(struct rxrpc_sock *rx,
  * Wait for space to appear in the Tx queue uninterruptibly, but with
  * a timeout of 2*RTT if no progress was made and a signal occurred.
  */
-static int rxrpc_wait_for_tx_window_nonintr(struct rxrpc_sock *rx,
+static int rxrpc_wait_for_tx_window_waitall(struct rxrpc_sock *rx,
                                            struct rxrpc_call *call)
 {
        rxrpc_seq_t tx_start, tx_win;
@@ -87,8 +87,7 @@ static int rxrpc_wait_for_tx_window_nonintr(struct rxrpc_sock *rx,
                if (call->state >= RXRPC_CALL_COMPLETE)
                        return call->error;
 
-               if (test_bit(RXRPC_CALL_IS_INTR, &call->flags) &&
-                   timeout == 0 &&
+               if (timeout == 0 &&
                    tx_win == tx_start && signal_pending(current))
                        return -EINTR;
 
@@ -102,6 +101,26 @@ static int rxrpc_wait_for_tx_window_nonintr(struct rxrpc_sock *rx,
        }
 }
 
+/*
+ * Wait for space to appear in the Tx queue uninterruptibly.
+ */
+static int rxrpc_wait_for_tx_window_nonintr(struct rxrpc_sock *rx,
+                                           struct rxrpc_call *call,
+                                           long *timeo)
+{
+       for (;;) {
+               set_current_state(TASK_UNINTERRUPTIBLE);
+               if (rxrpc_check_tx_space(call, NULL))
+                       return 0;
+
+               if (call->state >= RXRPC_CALL_COMPLETE)
+                       return call->error;
+
+               trace_rxrpc_transmit(call, rxrpc_transmit_wait);
+               *timeo = schedule_timeout(*timeo);
+       }
+}
+
 /*
  * wait for space to appear in the transmit/ACK window
  * - caller holds the socket locked
@@ -119,10 +138,19 @@ static int rxrpc_wait_for_tx_window(struct rxrpc_sock *rx,
 
        add_wait_queue(&call->waitq, &myself);
 
-       if (waitall)
-               ret = rxrpc_wait_for_tx_window_nonintr(rx, call);
-       else
-               ret = rxrpc_wait_for_tx_window_intr(rx, call, timeo);
+       switch (call->interruptibility) {
+       case RXRPC_INTERRUPTIBLE:
+               if (waitall)
+                       ret = rxrpc_wait_for_tx_window_waitall(rx, call);
+               else
+                       ret = rxrpc_wait_for_tx_window_intr(rx, call, timeo);
+               break;
+       case RXRPC_PREINTERRUPTIBLE:
+       case RXRPC_UNINTERRUPTIBLE:
+       default:
+               ret = rxrpc_wait_for_tx_window_nonintr(rx, call, timeo);
+               break;
+       }
 
        remove_wait_queue(&call->waitq, &myself);
        set_current_state(TASK_RUNNING);
@@ -628,7 +656,7 @@ int rxrpc_do_sendmsg(struct rxrpc_sock *rx, struct msghdr *msg, size_t len)
                .call.tx_total_len      = -1,
                .call.user_call_ID      = 0,
                .call.nr_timeouts       = 0,
-               .call.intr              = true,
+               .call.interruptibility  = RXRPC_INTERRUPTIBLE,
                .abort_code             = 0,
                .command                = RXRPC_CMD_SEND_DATA,
                .exclusive              = false,