From: sashiko-bot@kernel.org
To: "Zhao Gongyi" <zhaogongyi@bytedance.com>
Cc: linux-pci@vger.kernel.org
Subject: Re: [PATCH] PCI/VGA: Serialize per-file resource counters
Date: Sat, 05 Dec 2026 13:32:40 +0000 [thread overview]
Message-ID: <sashiko-outbox-251576@kernel.org> (raw)
In-Reply-To: <20261205131649.84007-1-zhaogongyi@bytedance.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] PCI/VGA: incomplete priv->lock coverage in vga_arb_write()
target and unlock
--
commit 49358fe981ccf86702231b1775d742792b053d29
Author: Zhao Gongyi <zhaogongyi@bytedance.com>
PCI/VGA: Serialize per-file resource counters
This commit protects per-file VGA resource counter updates in
vga_arb_write() with priv->lock and drops vga_user_lock before releasing
resources in vga_arb_release().
> diff --git a/drivers/pci/vgaarb.c b/drivers/pci/vgaarb.c
> index 3e58b2c05c854..5d30a6d0df584 100644
> --- a/drivers/pci/vgaarb.c
> +++ b/drivers/pci/vgaarb.c
[ ... ]
> @@ -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;
[Severity: Medium]
Can a concurrent "target" write still cause uc->io_cnt or uc->mem_cnt to
underflow?
The "target" branch in vga_arb_write() still updates priv->target and
initializes priv->cards[] entries without holding priv->lock:
drivers/pci/vgaarb.c:vga_arb_write() {
...
priv->target = pdev;
for (i = 0; i < MAX_USER_CARDS; i++) {
if (priv->cards[i].pdev == pdev)
break;
if (priv->cards[i].pdev == NULL) {
priv->cards[i].pdev = pdev;
priv->cards[i].io_cnt = 0;
priv->cards[i].mem_cnt = 0;
break;
}
}
...
}
CPU0 CPU1
vga_arb_write("target ...")
priv->target = pdev
priv->cards[i].pdev = pdev
vga_arb_write("lock io")
vga_get_uninterruptible(...)
spin_lock_irqsave(&priv->lock)
priv->cards[i].io_cnt++ (-> 1)
spin_unlock_irqrestore(...)
vga_arb_write("unlock io")
uc = &priv->cards[i]
spin_lock_irqsave(&priv->lock)
uc->io_cnt == 0 (false)
priv->cards[i].io_cnt = 0
uc->io_cnt-- <-- underflow
When the file is closed, vga_arb_release() then loops over the wrapped
unsigned counter calling vga_put() without yielding, reproducing the RCU
stall.
A concurrent "target" can also zero a counter after "lock" increments it
(leaking the VGA lock) or collide with another "target" on the same slot.
In "unlock", scanning priv->cards[] before taking priv->lock also leaves
the uc lookup racing with those slot updates.
Holding priv->lock around the priv->cards[] scan and initialization in
"target" (updating priv->target once the slot is ready) and before scanning
priv->cards[] in "unlock" would close these races.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205131649.84007-1-zhaogongyi@bytedance.com?part=1
prev parent reply other threads:[~2026-12-05 13:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 13:16 [PATCH] PCI/VGA: Serialize per-file resource counters Zhao Gongyi
2026-12-05 13:32 ` sashiko-bot [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-251576@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=zhaogongyi@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.