Skip to content

Commit 4997bd0

Browse files
dhowellsgregkh
authored andcommitted
afs: Fix handling of an abort from a service handler
commit dde9f09 upstream. When an AFS service handler function aborts a call, AF_RXRPC marks the call as complete - which means that it's not going to get any more packets from the receiver. This is a problem because reception of the final ACK is what triggers afs_deliver_to_call() to drop the final ref on the afs_call object. Instead, aborted AFS service calls may then just sit around waiting for ever or until they're displaced by a new call on the same connection channel or a connection-level abort. Fix this by calling afs_set_call_complete() to finalise the afs_call struct representing the call. However, we then need to drop the ref that stops the call from being deallocated. We can do this in afs_set_call_complete(), as the work queue is holding a separate ref of its own, but then we shouldn't do it in afs_process_async_call() and afs_delete_async_call(). call->drop_ref is set to indicate that a ref needs dropping for a call and this is dealt with when we transition a call to AFS_CALL_COMPLETE. But then we also need to get rid of the ref that pins an asynchronous client call. We can do this by the same mechanism, setting call->drop_ref for an async client call too. We can also get rid of call->incoming since nothing ever sets it and only one thing ever checks it (futilely). A trace of the rxrpc_call and afs_call struct ref counting looks like: <idle>-0 [001] ..s5 164.764892: rxrpc_call: c=00000002 SEE u=3 sp=rxrpc_new_incoming_call+0x473/0xb34 a=00000000442095b5 <idle>-0 [001] .Ns5 164.766001: rxrpc_call: c=00000002 QUE u=4 sp=rxrpc_propose_ACK+0xbe/0x551 a=00000000442095b5 <idle>-0 [001] .Ns4 164.766005: rxrpc_call: c=00000002 PUT u=3 sp=rxrpc_new_incoming_call+0xa3f/0xb34 a=00000000442095b5 <idle>-0 [001] .Ns7 164.766433: afs_call: c=00000002 WAKE u=2 o=11 sp=rxrpc_notify_socket+0x196/0x33c kworker/1:2-1810 [001] ...1 164.768409: rxrpc_call: c=00000002 SEE u=3 sp=rxrpc_process_call+0x25/0x7ae a=00000000442095b5 kworker/1:2-1810 [001] ...1 164.769439: rxrpc_tx_packet: c=00000002 e9f1a7a8:95786a88:00000008:09c5 00000001 00000000 02 22 ACK CallAck kworker/1:2-1810 [001] ...1 164.769459: rxrpc_call: c=00000002 PUT u=2 sp=rxrpc_process_call+0x74f/0x7ae a=00000000442095b5 kworker/1:2-1810 [001] ...1 164.770794: afs_call: c=00000002 QUEUE u=3 o=12 sp=afs_deliver_to_call+0x449/0x72c kworker/1:2-1810 [001] ...1 164.770829: afs_call: c=00000002 PUT u=2 o=12 sp=afs_process_async_call+0xdb/0x11e kworker/1:2-1810 [001] ...2 164.771084: rxrpc_abort: c=00000002 95786a88:00000008 s=0 a=1 e=1 K-1 kworker/1:2-1810 [001] ...1 164.771461: rxrpc_tx_packet: c=00000002 e9f1a7a8:95786a88:00000008:09c5 00000002 00000000 04 00 ABORT CallAbort kworker/1:2-1810 [001] ...1 164.771466: afs_call: c=00000002 PUT u=1 o=12 sp=SRXAFSCB_ProbeUuid+0xc1/0x106 The abort generated in SRXAFSCB_ProbeUuid(), labelled "K-1", indicates that the local filesystem/cache manager didn't recognise the UUID as its own. Fixes: 2067b2b ("afs: Fix the CB.ProbeUuid service handler to reply correctly") Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4fe4ac2 commit 4997bd0

3 files changed

Lines changed: 26 additions & 33 deletions

File tree

‎fs/afs/cmservice.c‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,17 @@ static void afs_cm_destructor(struct afs_call *call)
243243
call->buffer = NULL;
244244
}
245245

246+
/*
247+
* Abort a service call from within an action function.
248+
*/
249+
static void afs_abort_service_call(struct afs_call *call, u32 abort_code, int error,
250+
const char *why)
251+
{
252+
rxrpc_kernel_abort_call(call->net->socket, call->rxcall,
253+
abort_code, error, why);
254+
afs_set_call_complete(call, error, 0);
255+
}
256+
246257
/*
247258
* The server supplied a list of callbacks that it wanted to break.
248259
*/
@@ -510,8 +521,7 @@ static void SRXAFSCB_ProbeUuid(struct work_struct *work)
510521
if (memcmp(r, &call->net->uuid, sizeof(call->net->uuid)) == 0)
511522
afs_send_empty_reply(call);
512523
else
513-
rxrpc_kernel_abort_call(call->net->socket, call->rxcall,
514-
1, 1, "K-1");
524+
afs_abort_service_call(call, 1, 1, "K-1");
515525

516526
afs_put_call(call);
517527
_leave("");

‎fs/afs/internal.h‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ struct afs_call {
154154
};
155155
unsigned char unmarshall; /* unmarshalling phase */
156156
unsigned char addr_ix; /* Address in ->alist */
157-
bool incoming; /* T if incoming call */
157+
bool drop_ref; /* T if need to drop ref for incoming call */
158158
bool send_pages; /* T if data from mapping should be sent */
159159
bool need_attention; /* T if RxRPC poked us */
160160
bool async; /* T if asynchronous */
@@ -1209,8 +1209,16 @@ static inline void afs_set_call_complete(struct afs_call *call,
12091209
ok = true;
12101210
}
12111211
spin_unlock_bh(&call->state_lock);
1212-
if (ok)
1212+
if (ok) {
12131213
trace_afs_call_done(call);
1214+
1215+
/* Asynchronous calls have two refs to release - one from the alloc and
1216+
* one queued with the work item - and we can't just deallocate the
1217+
* call because the work item may be queued again.
1218+
*/
1219+
if (call->drop_ref)
1220+
afs_put_call(call);
1221+
}
12141222
}
12151223

12161224
/*

‎fs/afs/rxrpc.c‎

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ struct workqueue_struct *afs_async_calls;
1818

1919
static void afs_wake_up_call_waiter(struct sock *, struct rxrpc_call *, unsigned long);
2020
static void afs_wake_up_async_call(struct sock *, struct rxrpc_call *, unsigned long);
21-
static void afs_delete_async_call(struct work_struct *);
2221
static void afs_process_async_call(struct work_struct *);
2322
static void afs_rx_new_call(struct sock *, struct rxrpc_call *, unsigned long);
2423
static void afs_rx_discard_new_call(struct rxrpc_call *, unsigned long);
@@ -402,8 +401,10 @@ void afs_make_call(struct afs_addr_cursor *ac, struct afs_call *call, gfp_t gfp)
402401
/* If the call is going to be asynchronous, we need an extra ref for
403402
* the call to hold itself so the caller need not hang on to its ref.
404403
*/
405-
if (call->async)
404+
if (call->async) {
406405
afs_get_call(call, afs_call_trace_get);
406+
call->drop_ref = true;
407+
}
407408

408409
/* create a call */
409410
rxcall = rxrpc_kernel_begin_call(call->net->socket, srx, call->key,
@@ -584,8 +585,6 @@ static void afs_deliver_to_call(struct afs_call *call)
584585
done:
585586
if (call->type->done)
586587
call->type->done(call);
587-
if (state == AFS_CALL_COMPLETE && call->incoming)
588-
afs_put_call(call);
589588
out:
590589
_leave("");
591590
return;
@@ -744,21 +743,6 @@ static void afs_wake_up_async_call(struct sock *sk, struct rxrpc_call *rxcall,
744743
}
745744
}
746745

747-
/*
748-
* Delete an asynchronous call. The work item carries a ref to the call struct
749-
* that we need to release.
750-
*/
751-
static void afs_delete_async_call(struct work_struct *work)
752-
{
753-
struct afs_call *call = container_of(work, struct afs_call, async_work);
754-
755-
_enter("");
756-
757-
afs_put_call(call);
758-
759-
_leave("");
760-
}
761-
762746
/*
763747
* Perform I/O processing on an asynchronous call. The work item carries a ref
764748
* to the call struct that we either need to release or to pass on.
@@ -774,16 +758,6 @@ static void afs_process_async_call(struct work_struct *work)
774758
afs_deliver_to_call(call);
775759
}
776760

777-
if (call->state == AFS_CALL_COMPLETE) {
778-
/* We have two refs to release - one from the alloc and one
779-
* queued with the work item - and we can't just deallocate the
780-
* call because the work item may be queued again.
781-
*/
782-
call->async_work.func = afs_delete_async_call;
783-
if (!queue_work(afs_async_calls, &call->async_work))
784-
afs_put_call(call);
785-
}
786-
787761
afs_put_call(call);
788762
_leave("");
789763
}
@@ -810,6 +784,7 @@ void afs_charge_preallocation(struct work_struct *work)
810784
if (!call)
811785
break;
812786

787+
call->drop_ref = true;
813788
call->async = true;
814789
call->state = AFS_CALL_SV_AWAIT_OP_ID;
815790
init_waitqueue_head(&call->waitq);

0 commit comments

Comments
 (0)