linux-yocto/net/rxrpc
David Howells 79d458c130 rxrpc, afs: Fix peer hash locking vs RCU callback
In its address list, afs now retains pointers to and refs on one or more
rxrpc_peer objects.  The address list is freed under RCU and at this time,
it puts the refs on those peers.

Now, when an rxrpc_peer object runs out of refs, it gets removed from the
peer hash table and, for that, rxrpc has to take a spinlock.  However, it
is now being called from afs's RCU cleanup, which takes place in BH
context - but it is just taking an ordinary spinlock.

The put may also be called from non-BH context, and so there exists the
possibility of deadlock if the BH-based RCU cleanup happens whilst the hash
spinlock is held.  This led to the attached lockdep complaint.

Fix this by changing spinlocks of rxnet->peer_hash_lock back to
BH-disabling locks.

    ================================
    WARNING: inconsistent lock state
    6.13.0-rc5-build2+ #1223 Tainted: G            E
    --------------------------------
    inconsistent {SOFTIRQ-ON-W} -> {IN-SOFTIRQ-W} usage.
    swapper/1/0 [HC0[0]:SC1[1]:HE1:SE0] takes:
    ffff88810babe228 (&rxnet->peer_hash_lock){+.?.}-{3:3}, at: rxrpc_put_peer+0xcb/0x180
    {SOFTIRQ-ON-W} state was registered at:
      mark_usage+0x164/0x180
      __lock_acquire+0x544/0x990
      lock_acquire.part.0+0x103/0x280
      _raw_spin_lock+0x2f/0x40
      rxrpc_peer_keepalive_worker+0x144/0x440
      process_one_work+0x486/0x7c0
      process_scheduled_works+0x73/0x90
      worker_thread+0x1c8/0x2a0
      kthread+0x19b/0x1b0
      ret_from_fork+0x24/0x40
      ret_from_fork_asm+0x1a/0x30
    irq event stamp: 972402
    hardirqs last  enabled at (972402): [<ffffffff8244360e>] _raw_spin_unlock_irqrestore+0x2e/0x50
    hardirqs last disabled at (972401): [<ffffffff82443328>] _raw_spin_lock_irqsave+0x18/0x60
    softirqs last  enabled at (972300): [<ffffffff810ffbbe>] handle_softirqs+0x3ee/0x430
    softirqs last disabled at (972313): [<ffffffff810ffc54>] __irq_exit_rcu+0x44/0x110

    other info that might help us debug this:
     Possible unsafe locking scenario:
           CPU0
           ----
      lock(&rxnet->peer_hash_lock);
      <Interrupt>
        lock(&rxnet->peer_hash_lock);

     *** DEADLOCK ***
    1 lock held by swapper/1/0:
     #0: ffffffff83576be0 (rcu_callback){....}-{0:0}, at: rcu_lock_acquire+0x7/0x30

    stack backtrace:
    CPU: 1 UID: 0 PID: 0 Comm: swapper/1 Tainted: G            E      6.13.0-rc5-build2+ #1223
    Tainted: [E]=UNSIGNED_MODULE
    Hardware name: ASUS All Series/H97-PLUS, BIOS 2306 10/09/2014
    Call Trace:
     <IRQ>
     dump_stack_lvl+0x57/0x80
     print_usage_bug.part.0+0x227/0x240
     valid_state+0x53/0x70
     mark_lock_irq+0xa5/0x2f0
     mark_lock+0xf7/0x170
     mark_usage+0xe1/0x180
     __lock_acquire+0x544/0x990
     lock_acquire.part.0+0x103/0x280
     _raw_spin_lock+0x2f/0x40
     rxrpc_put_peer+0xcb/0x180
     afs_free_addrlist+0x46/0x90 [kafs]
     rcu_do_batch+0x2d2/0x640
     rcu_core+0x2f7/0x350
     handle_softirqs+0x1ee/0x430
     __irq_exit_rcu+0x44/0x110
     irq_exit_rcu+0xa/0x30
     sysvec_apic_timer_interrupt+0x7f/0xa0
     </IRQ>

Fixes: 72904d7b9b ("rxrpc, afs: Allow afs to pin rxrpc_peer objects")
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: Simon Horman <horms@kernel.org>
cc: linux-afs@lists.infradead.org
Link: https://patch.msgid.link/2095618.1737622752@warthog.procyon.org.uk
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2025-01-27 14:46:18 -08:00
..
af_rxrpc.c rxrpc: Use irq-disabling spinlocks between app and I/O thread 2024-12-09 13:48:31 -08:00
ar-internal.h rxrpc: Fix ability to add more data to a call once MSG_MORE deasserted 2024-12-16 18:06:59 -08:00
call_accept.c rxrpc: Use irq-disabling spinlocks between app and I/O thread 2024-12-09 13:48:31 -08:00
call_event.c rxrpc: Implement RACK/TLP to deal with transmission stalls [RFC8985] 2024-12-09 13:48:33 -08:00
call_object.c rxrpc: Implement RACK/TLP to deal with transmission stalls [RFC8985] 2024-12-09 13:48:33 -08:00
call_state.c rxrpc: Move client call connection to the I/O thread 2023-01-06 09:43:33 +00:00
conn_client.c rxrpc: Use irq-disabling spinlocks between app and I/O thread 2024-12-09 13:48:31 -08:00
conn_event.c rxrpc: Add a reason indicator to the tx_ack tracepoint 2024-12-09 13:48:32 -08:00
conn_object.c rxrpc: Use irq-disabling spinlocks between app and I/O thread 2024-12-09 13:48:31 -08:00
conn_service.c rxrpc_find_service_conn_rcu: fix the usage of read_seqbegin_or_lock() 2023-12-24 15:22:49 +00:00
input_rack.c rxrpc: Implement RACK/TLP to deal with transmission stalls [RFC8985] 2024-12-09 13:48:33 -08:00
input.c rxrpc: Implement RACK/TLP to deal with transmission stalls [RFC8985] 2024-12-09 13:48:33 -08:00
insecure.c rxrpc: Prepare to be able to send jumbo DATA packets 2024-12-09 13:48:26 -08:00
io_thread.c rxrpc: Disable IRQ, not BH, to take the lock for ->attend_link 2024-12-16 18:06:23 -08:00
Kconfig rxrpc: Allow a delay to be injected into packet reception 2023-01-31 16:38:09 +00:00
key.c rxrpc: Fix error when reading rxrpc tokens 2023-04-23 13:38:28 +01:00
local_event.c rxrpc: Truncate UTS_RELEASE for rxrpc version 2023-05-30 10:01:06 +02:00
local_object.c rxrpc: Don't use received skbuff timestamps 2024-12-09 13:48:29 -08:00
Makefile rxrpc: Implement RACK/TLP to deal with transmission stalls [RFC8985] 2024-12-09 13:48:33 -08:00
misc.c rxrpc: Implement path-MTU probing using padded PING ACKs (RFC8899) 2024-12-09 13:48:25 -08:00
net_ns.c rxrpc: Create a procfile to display outstanding client conn bundles 2023-12-24 15:22:56 +00:00
output.c rxrpc: Implement RACK/TLP to deal with transmission stalls [RFC8985] 2024-12-09 13:48:33 -08:00
peer_event.c rxrpc, afs: Fix peer hash locking vs RCU callback 2025-01-27 14:46:18 -08:00
peer_object.c rxrpc, afs: Fix peer hash locking vs RCU callback 2025-01-27 14:46:18 -08:00
proc.c rxrpc: Manage RTT per-call rather than per-peer 2024-12-09 13:48:32 -08:00
protocol.h rxrpc: Implement path-MTU probing using padded PING ACKs (RFC8899) 2024-12-09 13:48:25 -08:00
recvmsg.c rxrpc: Use irq-disabling spinlocks between app and I/O thread 2024-12-09 13:48:31 -08:00
rtt.c rxrpc: Manage RTT per-call rather than per-peer 2024-12-09 13:48:32 -08:00
rxkad.c rxrpc: Prepare to be able to send jumbo DATA packets 2024-12-09 13:48:26 -08:00
rxperf.c rxrpc: Use umin() and umax() rather than min_t()/max_t() where possible 2024-12-09 13:48:23 -08:00
security.c rxrpc: Use irq-disabling spinlocks between app and I/O thread 2024-12-09 13:48:31 -08:00
sendmsg.c rxrpc: Fix ability to add more data to a call once MSG_MORE deasserted 2024-12-16 18:06:59 -08:00
server_key.c
skbuff.c rxrpc: Use consume_skb() rather than kfree_skb_reason() 2023-02-07 23:11:20 +00:00
sysctl.c rxrpc: Implement path-MTU probing using padded PING ACKs (RFC8899) 2024-12-09 13:48:25 -08:00
txbuf.c rxrpc: Don't allocate a txbuf for an ACK transmission 2024-12-09 13:48:31 -08:00
utils.c