afs: Fix lock recursion
Subsystems (2)
David Howells
maintainerPATCH 1/1 afs: Fix lock recursion
afs_wake_up_async_call() can incur lock recursion. The problem is that it is called from AF_RXRPC whilst holding the ->notify_lock, but it tries to take a ref on the afs_call struct in order to pass it to a work queue - but if the afs_call is already queued, we then have an extraneous ref that must be put... calling afs_put_call() may call back down into AF_RXRPC through rxrpc_kernel_shutdown_call(), however, which might try taking the ->notify_lock again.
This case isn't very common, however, so defer it to a workqueue. The oops looks something like:
BUG: spinlock recursion on CPU#0, krxrpcio/7001/1646 lock: 0xffff888141399b30, .magic: dead4ead, .owner: krxrpcio/7001/1646, .owner_cpu: 0 CPU: 0 UID: 0 PID: 1646 Comm: krxrpcio/7001 Not tainted 6.12.0-rc2-build3+ #4351 Hardware name: ASUS All Series/H97-PLUS, BIOS 2306 10/09/2014 Call Trace: <TASK> dump_stack_lvl+0x47/0x70 do_raw_spin_lock+0x3c/0x90 rxrpc_kernel_shutdown_call+0x83/0xb0 afs_put_call+0xd7/0x180 rxrpc_notify_socket+0xa0/0x190 rxrpc_input_split_jumbo+0x198/0x1d0 rxrpc_input_data+0x14b/0x1e0 ? rxrpc_input_call_packet+0xc2/0x1f0 rxrpc_input_call_event+0xad/0x6b0 rxrpc_input_packet_on_conn+0x1e1/0x210 rxrpc_input_packet+0x3f2/0x4d0 rxrpc_io_thread+0x243/0x410 ? __pfx_rxrpc_io_thread+0x10/0x10 kthread+0xcf/0xe0 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x24/0x40 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK>
--- fs/afs/internal.h | 2 + fs/afs/rxrpc.c | 89 +++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 64 insertions(+), 27 deletions(-)
fs/afs/internal.h +2 -0
@@ -130,6 +130,7 @@ struct afs_call {wait_queue_head_t waitq;/* processes awaiting completion */ struct work_struct async_work;/* async I/O processor */ struct work_struct work;/* actual work processor */ +struct work_struct free_work;/* Deferred free processor */ struct rxrpc_call *rxcall;/* RxRPC call handle */ struct rxrpc_peer *peer;/* Remote endpoint */ struct key *key;/* security for this call */
@@ -1331,6 +1332,7 @@ extern int __net_init afs_open_socket(struct afs_net *); extern void __net_exit afs_close_socket(struct afs_net *);extern void afs_charge_preallocation (struct work_struct *);extern void afs_put_call (struct afs_call *); +void afs_deferred_put_call (struct afs_call *call);void afs_make_call (struct afs_call *call,gfp_t gfp);void afs_wait_for_call_to_complete (struct afs_call *call); extern struct afs_call *afs_alloc_flat_call(struct afs_net *,
fs/afs/rxrpc.c +62 -27
141 lines not on this page · raw message
Quoted 9 lines · David Howells
afs_wake_up_async_call()can incur lock recursion. The problem is that it is called fromAF_RXRPCwhilst holding the ->notify_lock, but it tries to take a ref on theafs_callstruct in order to pass it to a work queue - but if theafs_callis already queued, we then have an extraneous ref that must be put... callingafs_put_call()may call back down intoAF_RXRPCthroughrxrpc_kernel_shutdown_call(), however, which might try taking the ->notify_lock again.[...]
Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs.fixes
[1/1] afs: Fix lock recursion
https://git.kernel.org/vfs/vfs/c/dabae7218d1c
David Howells
maintainerPATCH v2 1/1 afs: Fix lock recursion
In reply to David Howellsafs_wake_up_async_call() can incur lock recursion. The problem is that it is called from AF_RXRPC whilst holding the ->notify_lock, but it tries to take a ref on the afs_call struct in order to pass it to a work queue - but if the afs_call is already queued, we then have an extraneous ref that must be put... calling afs_put_call() may call back down into AF_RXRPC through rxrpc_kernel_shutdown_call(), however, which might try taking the ->notify_lock again.
This case isn't very common, however, so defer it to a workqueue. The oops looks something like:
BUG: spinlock recursion on CPU#0, krxrpcio/7001/1646 lock: 0xffff888141399b30, .magic: dead4ead, .owner: krxrpcio/7001/1646, .owner_cpu: 0 CPU: 0 UID: 0 PID: 1646 Comm: krxrpcio/7001 Not tainted 6.12.0-rc2-build3+ #4351 Hardware name: ASUS All Series/H97-PLUS, BIOS 2306 10/09/2014 Call Trace: <TASK> dump_stack_lvl+0x47/0x70 do_raw_spin_lock+0x3c/0x90 rxrpc_kernel_shutdown_call+0x83/0xb0 afs_put_call+0xd7/0x180 rxrpc_notify_socket+0xa0/0x190 rxrpc_input_split_jumbo+0x198/0x1d0 rxrpc_input_data+0x14b/0x1e0 ? rxrpc_input_call_packet+0xc2/0x1f0 rxrpc_input_call_event+0xad/0x6b0 rxrpc_input_packet_on_conn+0x1e1/0x210 rxrpc_input_packet+0x3f2/0x4d0 rxrpc_io_thread+0x243/0x410 ? __pfx_rxrpc_io_thread+0x10/0x10 kthread+0xcf/0xe0 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x24/0x40 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK>
--- fs/afs/internal.h | 2 + fs/afs/rxrpc.c | 83 ++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 61 insertions(+), 24 deletions(-)
fs/afs/internal.h +2 -0
@@ -130,6 +130,7 @@ struct afs_call {wait_queue_head_t waitq;/* processes awaiting completion */ struct work_struct async_work;/* async I/O processor */ struct work_struct work;/* actual work processor */ +struct work_struct free_work;/* Deferred free processor */ struct rxrpc_call *rxcall;/* RxRPC call handle */ struct rxrpc_peer *peer;/* Remote endpoint */ struct key *key;/* security for this call */
@@ -1331,6 +1332,7 @@ extern int __net_init afs_open_socket(struct afs_net *); extern void __net_exit afs_close_socket(struct afs_net *);extern void afs_charge_preallocation (struct work_struct *);extern void afs_put_call (struct afs_call *); +void afs_deferred_put_call (struct afs_call *call);void afs_make_call (struct afs_call *call,gfp_t gfp);void afs_wait_for_call_to_complete (struct afs_call *call); extern struct afs_call *afs_alloc_flat_call(struct afs_net *,
fs/afs/rxrpc.c +59 -24
123 lines not on this page · raw message
Quoted 10 lines · David Howells
afs_wake_up_async_call()can incur lock recursion. The problem is that it is called fromAF_RXRPCwhilst holding the ->notify_lock, but it tries to take a ref on theafs_callstruct in order to pass it to a work queue - but if theafs_callis already queued, we then have an extraneous ref that must be put... callingafs_put_call()may call back down intoAF_RXRPCthroughrxrpc_kernel_shutdown_call(), however, which might try taking the ->notify_lock again.[...]
Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs.fixes
[1/1] afs: Fix lock recursion
https://git.kernel.org/vfs/vfs/c/610a79ffea02