Skip to content

Commit 0e77dd4

Browse files
dhowellsgregkh
authored andcommitted
rxrpc, afs: Fix peer hash locking vs RCU callback
[ Upstream commit 79d458c ] 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+ torvalds#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+ torvalds#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: 72904d7 ("rxrpc, afs: Allow afs to pin rxrpc_peer objects") Signed-off-by: David Howells <[email protected]> cc: Marc Dionne <[email protected]> cc: Simon Horman <[email protected]> cc: [email protected] Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent d6714e7 commit 0e77dd4

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

net/rxrpc/peer_event.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ static void rxrpc_peer_keepalive_dispatch(struct rxrpc_net *rxnet,
238238
bool use;
239239
int slot;
240240

241-
spin_lock(&rxnet->peer_hash_lock);
241+
spin_lock_bh(&rxnet->peer_hash_lock);
242242

243243
while (!list_empty(collector)) {
244244
peer = list_entry(collector->next,
@@ -249,7 +249,7 @@ static void rxrpc_peer_keepalive_dispatch(struct rxrpc_net *rxnet,
249249
continue;
250250

251251
use = __rxrpc_use_local(peer->local, rxrpc_local_use_peer_keepalive);
252-
spin_unlock(&rxnet->peer_hash_lock);
252+
spin_unlock_bh(&rxnet->peer_hash_lock);
253253

254254
if (use) {
255255
keepalive_at = peer->last_tx_at + RXRPC_KEEPALIVE_TIME;
@@ -269,17 +269,17 @@ static void rxrpc_peer_keepalive_dispatch(struct rxrpc_net *rxnet,
269269
*/
270270
slot += cursor;
271271
slot &= mask;
272-
spin_lock(&rxnet->peer_hash_lock);
272+
spin_lock_bh(&rxnet->peer_hash_lock);
273273
list_add_tail(&peer->keepalive_link,
274274
&rxnet->peer_keepalive[slot & mask]);
275-
spin_unlock(&rxnet->peer_hash_lock);
275+
spin_unlock_bh(&rxnet->peer_hash_lock);
276276
rxrpc_unuse_local(peer->local, rxrpc_local_unuse_peer_keepalive);
277277
}
278278
rxrpc_put_peer(peer, rxrpc_peer_put_keepalive);
279-
spin_lock(&rxnet->peer_hash_lock);
279+
spin_lock_bh(&rxnet->peer_hash_lock);
280280
}
281281

282-
spin_unlock(&rxnet->peer_hash_lock);
282+
spin_unlock_bh(&rxnet->peer_hash_lock);
283283
}
284284

285285
/*
@@ -309,7 +309,7 @@ void rxrpc_peer_keepalive_worker(struct work_struct *work)
309309
* second; the bucket at cursor + 1 goes at now + 1s and so
310310
* on...
311311
*/
312-
spin_lock(&rxnet->peer_hash_lock);
312+
spin_lock_bh(&rxnet->peer_hash_lock);
313313
list_splice_init(&rxnet->peer_keepalive_new, &collector);
314314

315315
stop = cursor + ARRAY_SIZE(rxnet->peer_keepalive);
@@ -321,7 +321,7 @@ void rxrpc_peer_keepalive_worker(struct work_struct *work)
321321
}
322322

323323
base = now;
324-
spin_unlock(&rxnet->peer_hash_lock);
324+
spin_unlock_bh(&rxnet->peer_hash_lock);
325325

326326
rxnet->peer_keepalive_base = base;
327327
rxnet->peer_keepalive_cursor = cursor;

net/rxrpc/peer_object.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,10 @@ void rxrpc_new_incoming_peer(struct rxrpc_local *local, struct rxrpc_peer *peer)
313313
hash_key = rxrpc_peer_hash_key(local, &peer->srx);
314314
rxrpc_init_peer(local, peer, hash_key);
315315

316-
spin_lock(&rxnet->peer_hash_lock);
316+
spin_lock_bh(&rxnet->peer_hash_lock);
317317
hash_add_rcu(rxnet->peer_hash, &peer->hash_link, hash_key);
318318
list_add_tail(&peer->keepalive_link, &rxnet->peer_keepalive_new);
319-
spin_unlock(&rxnet->peer_hash_lock);
319+
spin_unlock_bh(&rxnet->peer_hash_lock);
320320
}
321321

322322
/*
@@ -348,7 +348,7 @@ struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_local *local,
348348
return NULL;
349349
}
350350

351-
spin_lock(&rxnet->peer_hash_lock);
351+
spin_lock_bh(&rxnet->peer_hash_lock);
352352

353353
/* Need to check that we aren't racing with someone else */
354354
peer = __rxrpc_lookup_peer_rcu(local, srx, hash_key);
@@ -361,7 +361,7 @@ struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_local *local,
361361
&rxnet->peer_keepalive_new);
362362
}
363363

364-
spin_unlock(&rxnet->peer_hash_lock);
364+
spin_unlock_bh(&rxnet->peer_hash_lock);
365365

366366
if (peer)
367367
rxrpc_free_peer(candidate);
@@ -411,10 +411,10 @@ static void __rxrpc_put_peer(struct rxrpc_peer *peer)
411411

412412
ASSERT(hlist_empty(&peer->error_targets));
413413

414-
spin_lock(&rxnet->peer_hash_lock);
414+
spin_lock_bh(&rxnet->peer_hash_lock);
415415
hash_del_rcu(&peer->hash_link);
416416
list_del_init(&peer->keepalive_link);
417-
spin_unlock(&rxnet->peer_hash_lock);
417+
spin_unlock_bh(&rxnet->peer_hash_lock);
418418

419419
rxrpc_free_peer(peer);
420420
}

0 commit comments

Comments
 (0)