All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PCI/VGA: Serialize per-file resource counters
@ 2026-12-05 13:16 Zhao Gongyi
  2026-12-05 13:32 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Zhao Gongyi @ 2026-12-05 13:16 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: linux-pci, linux-kernel, stable, Zhao Gongyi

Concurrent unlocks on the same file can both pass the zero check and
underflow a resource counter. On close, vga_arb_release() can then spend
a long time releasing resources with interrupts disabled.

Syzkaller reported an RCU stall during the release loop:

  __sanitizer_cov_trace_pc+0xc/0x70
  vga_arb_release+0x1a2/0x330

Serialize updates to the counters, including the unlock checks and
decrements, with the per-file lock. Drop vga_user_lock after unlinking
the file. The final release has exclusive access to its counters.

Fixes: deb2d2ecd43d ("PCI/GPU: implement VGA arbitration on Linux")
Cc: stable@vger.kernel.org
Signed-off-by: Zhao Gongyi <zhaogongyi@bytedance.com>

diff --git a/drivers/pci/vgaarb.c b/drivers/pci/vgaarb.c
index 3e58b2c05c8546cacc00ba8b881f625c195e0c83..5d30a6d0df584b61431e8d604ac18b4d4e1c94d2 100644
--- a/drivers/pci/vgaarb.c
+++ b/drivers/pci/vgaarb.c
@@ -1140,6 +1140,7 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf,
 	struct vga_arb_private *priv = file->private_data;
 	struct vga_arb_user_card *uc = NULL;
 	struct pci_dev *pdev;
+	unsigned long flags;
 
 	unsigned int io_state;
 
@@ -1185,6 +1186,7 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf,
 		}
 
 		/* Update the client's locks lists */
+		spin_lock_irqsave(&priv->lock, flags);
 		for (i = 0; i < MAX_USER_CARDS; i++) {
 			if (priv->cards[i].pdev == pdev) {
 				if (io_state & VGA_RSRC_LEGACY_IO)
@@ -1194,6 +1196,7 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf,
 				break;
 			}
 		}
+		spin_unlock_irqrestore(&priv->lock, flags);
 
 		ret_val = count;
 		goto done;
@@ -1234,22 +1237,26 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf,
 			goto done;
 		}
 
+		spin_lock_irqsave(&priv->lock, flags);
 		if (io_state & VGA_RSRC_LEGACY_IO && uc->io_cnt == 0) {
+			spin_unlock_irqrestore(&priv->lock, flags);
 			ret_val = -EINVAL;
 			goto done;
 		}
 
 		if (io_state & VGA_RSRC_LEGACY_MEM && uc->mem_cnt == 0) {
+			spin_unlock_irqrestore(&priv->lock, flags);
 			ret_val = -EINVAL;
 			goto done;
 		}
 
-		vga_put(pdev, io_state);
-
 		if (io_state & VGA_RSRC_LEGACY_IO)
 			uc->io_cnt--;
 		if (io_state & VGA_RSRC_LEGACY_MEM)
 			uc->mem_cnt--;
+		spin_unlock_irqrestore(&priv->lock, flags);
+
+		vga_put(pdev, io_state);
 
 		ret_val = count;
 		goto done;
@@ -1278,6 +1285,7 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf,
 
 		if (vga_tryget(pdev, io_state)) {
 			/* Update the client's locks lists... */
+			spin_lock_irqsave(&priv->lock, flags);
 			for (i = 0; i < MAX_USER_CARDS; i++) {
 				if (priv->cards[i].pdev == pdev) {
 					if (io_state & VGA_RSRC_LEGACY_IO)
@@ -1287,6 +1295,7 @@ static ssize_t vga_arb_write(struct file *file, const char __user *buf,
 					break;
 				}
 			}
+			spin_unlock_irqrestore(&priv->lock, flags);
 			ret_val = count;
 			goto done;
 		} else {
@@ -1432,6 +1441,8 @@ static int vga_arb_release(struct inode *inode, struct file *file)
 
 	spin_lock_irqsave(&vga_user_lock, flags);
 	list_del(&priv->list);
+	spin_unlock_irqrestore(&vga_user_lock, flags);
+
 	for (i = 0; i < MAX_USER_CARDS; i++) {
 		uc = &priv->cards[i];
 		if (uc->pdev == NULL)
@@ -1443,7 +1454,6 @@ static int vga_arb_release(struct inode *inode, struct file *file)
 		while (uc->mem_cnt--)
 			vga_put(uc->pdev, VGA_RSRC_LEGACY_MEM);
 	}
-	spin_unlock_irqrestore(&vga_user_lock, flags);
 
 	kfree(priv);
 

base-commit: 85a0cf7926b9e6883cbc515b8b5f77090d3b1889
-- 
2.39.5 (Apple Git-154)

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-05 13:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 13:16 [PATCH] PCI/VGA: Serialize per-file resource counters Zhao Gongyi
2026-12-05 13:32 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.