mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] virtio_pci_modern: don't sleep in atomic context in admin cmd submission
@ 2026-11-11  7:51 Hyunjung Ko
  0 siblings, 0 replies; only message in thread
From: Hyunjung Ko @ 2026-11-11  7:51 UTC (permalink / raw)
  To: Michael S . Tsirkin, Jason Wang
  Cc: Eugenio Pérez, Xuan Zhuo, Jiri Pirko, virtualization,
	linux-kernel, Hyunjung Ko, stable

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.

Fixes: 4c3b54af907e ("virtio_pci_modern: use completion instead of busy loop to wait on admin cmd result")
Cc: stable@vger.kernel.org
Signed-off-by: Hyunjung Ko <hj351016@gmail.com>
---
 drivers/virtio/virtio_pci_modern.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/virtio/virtio_pci_modern.c b/drivers/virtio/virtio_pci_modern.c
index 922e2df027de..ef96140118ec 100644
--- a/drivers/virtio/virtio_pci_modern.c
+++ b/drivers/virtio/virtio_pci_modern.c
@@ -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);
-- 
2.43.0

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-11  7:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-11  7:51 [PATCH] virtio_pci_modern: don't sleep in atomic context in admin cmd submission Hyunjung Ko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®