linux/net/rxrpc
David Howells 3cec055c56 rxrpc: Don't hold a ref for connection workqueue
Currently, rxrpc gives the connection's work item a ref on the connection
when it queues it - and this is called from the timer expiration function.
The problem comes when queue_work() fails (ie. the work item is already
queued): the timer routine must put the ref - but this may cause the
cleanup code to run.

This has the unfortunate effect that the cleanup code may then be run in
softirq context - which means that any spinlocks it might need to touch
have to be guarded to disable softirqs (ie. they need a "_bh" suffix).

 (1) Don't give a ref to the work item.

 (2) Simplify handling of service connections by adding a separate active
     count so that the refcount isn't also used for this.

 (3) Connection destruction for both client and service connections can
     then be cleaned up by putting rxrpc_put_connection() out of line and
     making a tidy progression through the destruction code (offloaded to a
     workqueue if put from softirq or processor function context).  The RCU
     part of the cleanup then only deals with the freeing at the end.

 (4) Make rxrpc_queue_conn() return immediately if it sees the active count
     is -1 rather then queuing the connection.

 (5) Make sure that the cleanup routine waits for the work item to
     complete.

 (6) Stash the rxrpc_net pointer in the conn struct so that the rcu free
     routine can use it, even if the local endpoint has been freed.

Unfortunately, neither the timer nor the work item can simply get around
the problem by just using refcount_inc_not_zero() as the waits would still
have to be done, and there would still be the possibility of having to put
the ref in the expiration function.

Note the connection work item is mostly going to go away with the main
event work being transferred to the I/O thread, so the wait in (6) will
become obsolete.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: linux-afs@lists.infradead.org
2022-12-01 13:36:40 +00:00
..
af_rxrpc.c rxrpc: trace: Don't use __builtin_return_address for rxrpc_peer tracing 2022-12-01 13:36:38 +00:00
ar-internal.h rxrpc: Don't hold a ref for connection workqueue 2022-12-01 13:36:40 +00:00
call_accept.c rxrpc: Don't hold a ref for connection workqueue 2022-12-01 13:36:40 +00:00
call_event.c rxrpc: Don't hold a ref for call timer or workqueue 2022-12-01 13:36:39 +00:00
call_object.c rxrpc: Don't hold a ref for call timer or workqueue 2022-12-01 13:36:39 +00:00
conn_client.c rxrpc: Don't hold a ref for connection workqueue 2022-12-01 13:36:40 +00:00
conn_event.c rxrpc: Don't hold a ref for connection workqueue 2022-12-01 13:36:40 +00:00
conn_object.c rxrpc: Don't hold a ref for connection workqueue 2022-12-01 13:36:40 +00:00
conn_service.c rxrpc: Don't hold a ref for connection workqueue 2022-12-01 13:36:40 +00:00
input.c rxrpc: trace: Don't use __builtin_return_address for sk_buff tracing 2022-12-01 13:36:39 +00:00
insecure.c rxrpc: Don't use a ring buffer for call Tx queue 2022-11-08 16:42:28 +00:00
Kconfig rxrpc: Implement an in-kernel rxperf server for testing purposes 2022-12-01 13:36:37 +00:00
key.c rxrpc: Drop rxrpc_conn_parameters from rxrpc_connection and rxrpc_bundle 2022-12-01 13:36:38 +00:00
local_event.c rxrpc: trace: Don't use __builtin_return_address for sk_buff tracing 2022-12-01 13:36:39 +00:00
local_object.c rxrpc: trace: Don't use __builtin_return_address for rxrpc_local tracing 2022-12-01 13:36:38 +00:00
Makefile rxrpc: Implement an in-kernel rxperf server for testing purposes 2022-12-01 13:36:37 +00:00
misc.c rxrpc: Get rid of the Rx ring 2022-11-08 16:42:28 +00:00
net_ns.c rxrpc: Don't hold a ref for connection workqueue 2022-12-01 13:36:40 +00:00
output.c rxrpc: trace: Don't use __builtin_return_address for sk_buff tracing 2022-12-01 13:36:39 +00:00
peer_event.c rxrpc: trace: Don't use __builtin_return_address for sk_buff tracing 2022-12-01 13:36:39 +00:00
peer_object.c rxrpc: trace: Don't use __builtin_return_address for rxrpc_peer tracing 2022-12-01 13:36:38 +00:00
proc.c rxrpc: Don't hold a ref for connection workqueue 2022-12-01 13:36:40 +00:00
protocol.h rxrpc: Clone received jumbo subpackets and queue separately 2022-11-08 16:42:28 +00:00
recvmsg.c rxrpc: trace: Don't use __builtin_return_address for sk_buff tracing 2022-12-01 13:36:39 +00:00
rtt.c rxrpc: Fix _usecs_to_jiffies() by using usecs_to_jiffies() 2021-09-24 14:18:34 +01:00
rxkad.c rxrpc: Drop rxrpc_conn_parameters from rxrpc_connection and rxrpc_bundle 2022-12-01 13:36:38 +00:00
rxperf.c rxrpc: Implement an in-kernel rxperf server for testing purposes 2022-12-01 13:36:37 +00:00
security.c rxrpc: Drop rxrpc_conn_parameters from rxrpc_connection and rxrpc_bundle 2022-12-01 13:36:38 +00:00
sendmsg.c rxrpc: trace: Don't use __builtin_return_address for rxrpc_call tracing 2022-12-01 13:36:39 +00:00
server_key.c rxrpc: Implement an in-kernel rxperf server for testing purposes 2022-12-01 13:36:37 +00:00
skbuff.c rxrpc: trace: Don't use __builtin_return_address for sk_buff tracing 2022-12-01 13:36:39 +00:00
sysctl.c rxrpc: Get rid of the Rx ring 2022-11-08 16:42:28 +00:00
txbuf.c rxrpc: Don't hold a ref for call timer or workqueue 2022-12-01 13:36:39 +00:00
utils.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 36 2019-05-24 17:27:11 +02:00