virtio_pci_modern: don't sleep in atomic context in admin cmd submission
Subsystems (2)
PATCH 1/1 virtio_pci_modern: don't sleep in atomic context in admin cmd submission
virtqueue_exec_admin_cmd() calls virtqueue_add_sgs() with GFP_KERNEL while holding admin_vq->lock, which is taken with spin_lock_irqsave(). The admin virtqueue is created with ctx=false, so when the device has negotiated VIRTIO_RING_F_INDIRECT_DESC it uses indirect descriptors and virtqueue_add() allocates the indirect descriptor table with the passed gfp. Admin commands always have more than one sg (header plus status), so the indirect path is taken and a GFP_KERNEL allocation may sleep while interrupts are disabled under the spinlock, triggering a "BUG: sleeping function called from invalid context" splat with CONFIG_DEBUG_ATOMIC_SLEEP.
Use GFP_ATOMIC for the descriptor allocation that runs under the lock; the table is small and the -ENOMEM path is already handled.
--- drivers/virtio/virtio_pci_modern.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/virtio/virtio_pci_modern.c +1 -1
@@ -101,7 +101,7 @@ again:return -EIO ;spin_lock_irqsave (&admin_vq->lock, flags); - ret =virtqueue_add_sgs (vq, sgs, out_num, in_num, cmd,GFP_KERNEL ); + ret =virtqueue_add_sgs (vq, sgs, out_num, in_num, cmd,GFP_ATOMIC );if (ret <0 ) {if (ret == -ENOSPC ) {spin_unlock_irqrestore (&admin_vq->lock, flags);
Signature · 1 line
2.43.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 10 lines
virtqueue_exec_admin_cmd()callsvirtqueue_add_sgs()withGFP_KERNELwhile holdingadmin_vq->lock, which is taken withspin_lock_irqsave(). The admin virtqueue is created with ctx=false, so when the device has negotiatedVIRTIO_RING_F_INDIRECT_DESCit uses indirect descriptors andvirtqueue_add()allocates the indirect descriptor table with the passed gfp. Admin commands always have more than one sg (header plus status), so the indirect path is taken and aGFP_KERNELallocation may sleep while interrupts are disabled under the spinlock, triggering a "BUG: sleeping function called from invalid context" splat withCONFIG_DEBUG_ATOMIC_SLEEP.
Quoted 6 lines
Use
GFP_ATOMICfor the descriptor allocation that runs under the lock; the table is small and the-ENOMEMpath is already handled.Fixes 4c3b54af907e ("virtio_pci_modern: use completion instead of busy loop to wait on admin cmd result")Signed-off-by Hyunjung Ko <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1