]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
rxrpc: Fix handling of call quietly cancelled out on server
authorDavid Howells <dhowells@redhat.com>
Sun, 3 Jun 2018 01:17:39 +0000 (02:17 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 4 Jun 2018 20:06:26 +0000 (16:06 -0400)
Sometimes an in-progress call will stop responding on the fileserver when
the fileserver quietly cancels the call with an internally marked abort
(RX_CALL_DEAD), without sending an ABORT to the client.

This causes the client's call to eventually expire from lack of incoming
packets directed its way, which currently leads to it being cancelled
locally with ETIME.  Note that it's not currently clear as to why this
happens as it's really hard to reproduce.

The rotation policy implement by kAFS, however, doesn't differentiate
between ETIME meaning we didn't get any response from the server and ETIME
meaning the call got cancelled mid-flow.  The latter leads to an oops when
fetching data as the rotation partially resets the afs_read descriptor,
which can result in a cleared page pointer being dereferenced because that
page has already been filled.

Handle this by the following means:

 (1) Set a flag on a call when we receive a packet for it.

 (2) Store the highest packet serial number so far received for a call
     (bearing in mind this may wrap).

 (3) If, when the "not received anything recently" timeout expires on a
     call, we've received at least one packet for a call and the connection
     as a whole has received packets more recently than that call, then
     cancel the call locally with ECONNRESET rather than ETIME.

     This indicates that the call was definitely in progress on the server.

 (4) In kAFS, if the rotation algorithm sees ECONNRESET rather than ETIME,
     don't try the next server, but rather abort the call.

     This avoids the oops as we don't try to reuse the afs_read struct.
     Rather, as-yet ungotten pages will be reread at a later data.

Also:

 (5) Add an rxrpc tracepoint to log detection of the call being reset.

Without this, I occasionally see an oops like the following:

    general protection fault: 0000 [#1] SMP PTI
    ...
    RIP: 0010:_copy_to_iter+0x204/0x310
    RSP: 0018:ffff8800cae0f828 EFLAGS: 00010206
    RAX: 0000000000000560 RBX: 0000000000000560 RCX: 0000000000000560
    RDX: ffff8800cae0f968 RSI: ffff8800d58b3312 RDI: 0005080000000000
    RBP: ffff8800cae0f968 R08: 0000000000000560 R09: ffff8800ca00f400
    R10: ffff8800c36f28d4 R11: 00000000000008c4 R12: ffff8800cae0f958
    R13: 0000000000000560 R14: ffff8800d58b3312 R15: 0000000000000560
    FS:  00007fdaef108080(0000) GS:ffff8800ca680000(0000) knlGS:0000000000000000
    CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 00007fb28a8fa000 CR3: 00000000d2a76002 CR4: 00000000001606e0
    Call Trace:
     skb_copy_datagram_iter+0x14e/0x289
     rxrpc_recvmsg_data.isra.0+0x6f3/0xf68
     ? trace_buffer_unlock_commit_regs+0x4f/0x89
     rxrpc_kernel_recv_data+0x149/0x421
     afs_extract_data+0x1e0/0x798
     ? afs_wait_for_call_to_complete+0xc9/0x52e
     afs_deliver_fs_fetch_data+0x33a/0x5ab
     afs_deliver_to_call+0x1ee/0x5e0
     ? afs_wait_for_call_to_complete+0xc9/0x52e
     afs_wait_for_call_to_complete+0x12b/0x52e
     ? wake_up_q+0x54/0x54
     afs_make_call+0x287/0x462
     ? afs_fs_fetch_data+0x3e6/0x3ed
     ? rcu_read_lock_sched_held+0x5d/0x63
     afs_fs_fetch_data+0x3e6/0x3ed
     afs_fetch_data+0xbb/0x14a
     afs_readpages+0x317/0x40d
     __do_page_cache_readahead+0x203/0x2ba
     ? ondemand_readahead+0x3a7/0x3c1
     ondemand_readahead+0x3a7/0x3c1
     generic_file_buffered_read+0x18b/0x62f
     __vfs_read+0xdb/0xfe
     vfs_read+0xb2/0x137
     ksys_read+0x50/0x8c
     do_syscall_64+0x7d/0x1a0
     entry_SYSCALL_64_after_hwframe+0x49/0xbe

Note the weird value in RDI which is a result of trying to kmap() a NULL
page pointer.

Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
fs/afs/rotate.c
include/trace/events/rxrpc.h
net/rxrpc/ar-internal.h
net/rxrpc/call_event.c
net/rxrpc/input.c

index e065bc0768e6a5068ef762e3d3967fc54d50e2b2..1faef56b12bd3f9591b2acc29ce89c6689e224e6 100644 (file)
@@ -310,6 +310,10 @@ bool afs_select_fileserver(struct afs_fs_cursor *fc)
        case -ETIME:
                _debug("no conn");
                goto iterate_address;
+
+       case -ECONNRESET:
+               _debug("call reset");
+               goto failed;
        }
 
 restart_from_beginning:
index 077e664ac9a20986eebf07fc829339738882f8a9..4fff00e9da8ac43b581fa95a318a59db43832611 100644 (file)
@@ -1459,6 +1459,38 @@ TRACE_EVENT(rxrpc_tx_fail,
                      __print_symbolic(__entry->what, rxrpc_tx_fail_traces))
            );
 
+TRACE_EVENT(rxrpc_call_reset,
+           TP_PROTO(struct rxrpc_call *call),
+
+           TP_ARGS(call),
+
+           TP_STRUCT__entry(
+                   __field(unsigned int,               debug_id        )
+                   __field(u32,                        cid             )
+                   __field(u32,                        call_id         )
+                   __field(rxrpc_serial_t,             call_serial     )
+                   __field(rxrpc_serial_t,             conn_serial     )
+                   __field(rxrpc_seq_t,                tx_seq          )
+                   __field(rxrpc_seq_t,                rx_seq          )
+                            ),
+
+           TP_fast_assign(
+                   __entry->debug_id = call->debug_id;
+                   __entry->cid = call->cid;
+                   __entry->call_id = call->call_id;
+                   __entry->call_serial = call->rx_serial;
+                   __entry->conn_serial = call->conn->hi_serial;
+                   __entry->tx_seq = call->tx_hard_ack;
+                   __entry->rx_seq = call->ackr_seen;
+                          ),
+
+           TP_printk("c=%08x %08x:%08x r=%08x/%08x tx=%08x rx=%08x",
+                     __entry->debug_id,
+                     __entry->cid, __entry->call_id,
+                     __entry->call_serial, __entry->conn_serial,
+                     __entry->tx_seq, __entry->rx_seq)
+           );
+
 #endif /* _TRACE_RXRPC_H */
 
 /* This part must be outside protection */
index 19975d2ca9a20367d900f14ab8b776953e3d5ba1..b2393113a2518329cf11ae0195c305712f117503 100644 (file)
@@ -477,6 +477,7 @@ enum rxrpc_call_flag {
        RXRPC_CALL_PINGING,             /* Ping in process */
        RXRPC_CALL_RETRANS_TIMEOUT,     /* Retransmission due to timeout occurred */
        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 */
 };
 
 /*
@@ -624,6 +625,7 @@ struct rxrpc_call {
                                                 */
        rxrpc_seq_t             rx_top;         /* Highest Rx slot allocated. */
        rxrpc_seq_t             rx_expect_next; /* Expected next packet sequence number */
+       rxrpc_serial_t          rx_serial;      /* Highest serial received for this call */
        u8                      rx_winsize;     /* Size of Rx window */
        u8                      tx_winsize;     /* Maximum size of Tx window */
        bool                    tx_phase;       /* T if transmission phase, F if receive phase */
index 6e0d788b4dc43e0674ccaeb7b1282382cae01d0a..20210418904bf61975e5f00ef196c5dce4770cca 100644 (file)
@@ -392,7 +392,13 @@ recheck_state:
 
        /* Process events */
        if (test_and_clear_bit(RXRPC_CALL_EV_EXPIRED, &call->events)) {
-               rxrpc_abort_call("EXP", call, 0, RX_USER_ABORT, -ETIME);
+               if (test_bit(RXRPC_CALL_RX_HEARD, &call->flags) &&
+                   (int)call->conn->hi_serial - (int)call->rx_serial > 0) {
+                       trace_rxrpc_call_reset(call);
+                       rxrpc_abort_call("EXP", call, 0, RX_USER_ABORT, -ECONNRESET);
+               } else {
+                       rxrpc_abort_call("EXP", call, 0, RX_USER_ABORT, -ETIME);
+               }
                set_bit(RXRPC_CALL_EV_ABORT, &call->events);
                goto recheck_state;
        }
index b5fd6381313d06b1b02ad6e6f6ca5c0dcc74b10d..608d078a4981fd78d42b1e3c87b983a7ec0be0db 100644 (file)
@@ -1278,8 +1278,14 @@ void rxrpc_data_ready(struct sock *udp_sk)
                        call = NULL;
                }
 
-               if (call && sp->hdr.serviceId != call->service_id)
-                       call->service_id = sp->hdr.serviceId;
+               if (call) {
+                       if (sp->hdr.serviceId != call->service_id)
+                               call->service_id = sp->hdr.serviceId;
+                       if ((int)sp->hdr.serial - (int)call->rx_serial > 0)
+                               call->rx_serial = sp->hdr.serial;
+                       if (!test_bit(RXRPC_CALL_RX_HEARD, &call->flags))
+                               set_bit(RXRPC_CALL_RX_HEARD, &call->flags);
+               }
        } else {
                skew = 0;
                call = NULL;