In the Linux kernel, the following vulnerability has been resolved:
powerpc/pci: Fix getphbnumber() locking
The recent change to getphbnumber() causes a DEBUGATOMICSLEEP warning on some systems:
BUG: sleeping function called from invalid context at kernel/locking/mutex.c:580 inatomic(): 1, irqsdisabled(): 0, nonblock: 0, pid: 1, name: swapper preemptcount: 1, expected: 0 RCU nest depth: 0, expected: 0 1 lock held by swapper/1: #0: c157efb0 (hosespinlock){+.+.}-{2:2}, at: pcibiosalloccontroller+0x64/0x220 Preemption disabled at: [<00000000>] 0x0 CPU: 0 PID: 1 Comm: swapper Not tainted 5.19.0-yocto-standard+ #1 Call Trace: [d101dc90] [c073b264] dumpstacklvl+0x50/0x8c (unreliable) [d101dcb0] [c0093b70] _mightresched+0x258/0x2a8 [d101dcd0] [c0d3e634] _mutexlock+0x6c/0x6ec [d101dd50] [c0a84174] ofaliasgetid+0x50/0xf4 [d101dd80] [c002ec78] pcibiosalloccontroller+0x1b8/0x220 [d101ddd0] [c140c9dc] pmacpciinit+0x198/0x784 [d101de50] [c140852c] discoverphbs+0x30/0x4c [d101de60] [c0007fd4] dooneinitcall+0x94/0x344 [d101ded0] [c1403b40] kernelinitfreeable+0x1a8/0x22c [d101df10] [c00086e0] kernelinit+0x34/0x160 [d101df30] [c001b334] retfromkernel_thread+0x5c/0x64
This is because pcibiosalloccontroller() holds hosespinlock but ofaliasgetid() takes of_mutex which can sleep.
The hosespinlock protects the phbbitmap, and also the hoselist, but it doesn't need to be held while getphb_number() calls the OF routines, because those are only looking up information in the device tree.
So fix it by having getphbnumber() take the hosespinlock itself, only where required, and then dropping the lock before returning. pcibiosalloccontroller() then needs to take the lock again before the listadd() but that's safe, the order of the list is not important.