Skip to content

Commit 317e493

Browse files
haokexinkuba-moo
authored andcommitted
net: macb: Move devm_{free,request}_irq() out of spin lock area
The devm_free_irq() and devm_request_irq() functions should not be executed in an atomic context. During device suspend, all userspace processes and most kernel threads are frozen. Additionally, we flush all tx/rx status, disable all macb interrupts, and halt rx operations. Therefore, it is safe to split the region protected by bp->lock into two independent sections, allowing devm_free_irq() and devm_request_irq() to run in a non-atomic context. This modification resolves the following lockdep warning: BUG: sleeping function called from invalid context at kernel/locking/mutex.c:591 in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 501, name: rtcwake preempt_count: 1, expected: 0 RCU nest depth: 1, expected: 0 7 locks held by rtcwake/501: #0: ffff0008038c3408 (sb_writers#5){.+.+}-{0:0}, at: vfs_write+0xf8/0x368 #1: ffff0008049a5e88 (&of->mutex#2){+.+.}-{4:4}, at: kernfs_fop_write_iter+0xbc/0x1c8 #2: ffff00080098d588 (kn->active#70){.+.+}-{0:0}, at: kernfs_fop_write_iter+0xcc/0x1c8 #3: ffff800081c84888 (system_transition_mutex){+.+.}-{4:4}, at: pm_suspend+0x1ec/0x290 #4: ffff0008009ba0f8 (&dev->mutex){....}-{4:4}, at: device_suspend+0x118/0x4f0 #5: ffff800081d00458 (rcu_read_lock){....}-{1:3}, at: rcu_lock_acquire+0x4/0x48 #6: ffff0008031fb9e0 (&bp->lock){-.-.}-{3:3}, at: macb_suspend+0x144/0x558 irq event stamp: 8682 hardirqs last enabled at (8681): [<ffff8000813c7d7c>] _raw_spin_unlock_irqrestore+0x44/0x88 hardirqs last disabled at (8682): [<ffff8000813c7b58>] _raw_spin_lock_irqsave+0x38/0x98 softirqs last enabled at (7322): [<ffff8000800f1b4c>] handle_softirqs+0x52c/0x588 softirqs last disabled at (7317): [<ffff800080010310>] __do_softirq+0x20/0x2c CPU: 1 UID: 0 PID: 501 Comm: rtcwake Not tainted 7.0.0-rc3-next-20260310-yocto-standard+ #125 PREEMPT Hardware name: ZynqMP ZCU102 Rev1.1 (DT) Call trace: show_stack+0x24/0x38 (C) __dump_stack+0x28/0x38 dump_stack_lvl+0x64/0x88 dump_stack+0x18/0x24 __might_resched+0x200/0x218 __might_sleep+0x38/0x98 __mutex_lock_common+0x7c/0x1378 mutex_lock_nested+0x38/0x50 free_irq+0x68/0x2b0 devm_irq_release+0x24/0x38 devres_release+0x40/0x80 devm_free_irq+0x48/0x88 macb_suspend+0x298/0x558 device_suspend+0x218/0x4f0 dpm_suspend+0x244/0x3a0 dpm_suspend_start+0x50/0x78 suspend_devices_and_enter+0xec/0x560 pm_suspend+0x194/0x290 state_store+0x110/0x158 kobj_attr_store+0x1c/0x30 sysfs_kf_write+0xa8/0xd0 kernfs_fop_write_iter+0x11c/0x1c8 vfs_write+0x248/0x368 ksys_write+0x7c/0xf8 __arm64_sys_write+0x28/0x40 invoke_syscall+0x4c/0xe8 el0_svc_common+0x98/0xf0 do_el0_svc+0x28/0x40 el0_svc+0x54/0x1e0 el0t_64_sync_handler+0x84/0x130 el0t_64_sync+0x198/0x1a0 Fixes: 558e35c ("net: macb: WoL support for GEM type of Ethernet controller") Cc: [email protected] Reviewed-by: Théo Lebrun <[email protected]> Signed-off-by: Kevin Hao <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 7c770da commit 317e493

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

drivers/net/ethernet/cadence/macb_main.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5835,6 +5835,7 @@ static int __maybe_unused macb_suspend(struct device *dev)
58355835
/* write IP address into register */
58365836
tmp |= MACB_BFEXT(IP, be32_to_cpu(ifa->ifa_local));
58375837
}
5838+
spin_unlock_irqrestore(&bp->lock, flags);
58385839

58395840
/* Change interrupt handler and
58405841
* Enable WoL IRQ on queue 0
@@ -5847,25 +5848,26 @@ static int __maybe_unused macb_suspend(struct device *dev)
58475848
dev_err(dev,
58485849
"Unable to request IRQ %d (error %d)\n",
58495850
bp->queues[0].irq, err);
5850-
spin_unlock_irqrestore(&bp->lock, flags);
58515851
return err;
58525852
}
5853+
spin_lock_irqsave(&bp->lock, flags);
58535854
queue_writel(bp->queues, IER, GEM_BIT(WOL));
58545855
gem_writel(bp, WOL, tmp);
5856+
spin_unlock_irqrestore(&bp->lock, flags);
58555857
} else {
58565858
err = devm_request_irq(dev, bp->queues[0].irq, macb_wol_interrupt,
58575859
IRQF_SHARED, netdev->name, bp->queues);
58585860
if (err) {
58595861
dev_err(dev,
58605862
"Unable to request IRQ %d (error %d)\n",
58615863
bp->queues[0].irq, err);
5862-
spin_unlock_irqrestore(&bp->lock, flags);
58635864
return err;
58645865
}
5866+
spin_lock_irqsave(&bp->lock, flags);
58655867
queue_writel(bp->queues, IER, MACB_BIT(WOL));
58665868
macb_writel(bp, WOL, tmp);
5869+
spin_unlock_irqrestore(&bp->lock, flags);
58675870
}
5868-
spin_unlock_irqrestore(&bp->lock, flags);
58695871

58705872
enable_irq_wake(bp->queues[0].irq);
58715873
}
@@ -5932,6 +5934,8 @@ static int __maybe_unused macb_resume(struct device *dev)
59325934
queue_readl(bp->queues, ISR);
59335935
if (bp->caps & MACB_CAPS_ISR_CLEAR_ON_WRITE)
59345936
queue_writel(bp->queues, ISR, -1);
5937+
spin_unlock_irqrestore(&bp->lock, flags);
5938+
59355939
/* Replace interrupt handler on queue 0 */
59365940
devm_free_irq(dev, bp->queues[0].irq, bp->queues);
59375941
err = devm_request_irq(dev, bp->queues[0].irq, macb_interrupt,
@@ -5940,10 +5944,8 @@ static int __maybe_unused macb_resume(struct device *dev)
59405944
dev_err(dev,
59415945
"Unable to request IRQ %d (error %d)\n",
59425946
bp->queues[0].irq, err);
5943-
spin_unlock_irqrestore(&bp->lock, flags);
59445947
return err;
59455948
}
5946-
spin_unlock_irqrestore(&bp->lock, flags);
59475949

59485950
disable_irq_wake(bp->queues[0].irq);
59495951

0 commit comments

Comments
 (0)