From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796477561; b=Ca8itkFlxuTQxNk67eGIpleIMoGGYq04hb/9y5XhwbRfojMPo8YsOkDQ/bWoo2/N4TES wavFRIKhNLfZ81NPosf+SrelG3qlIySuAvIG0KwITbqizF33Zi9ufmS/nDRyLVQhP4nkZ VvdcDiw9znhMbvE9tJOWNcicNuXLbF8B6FwocHXGIL5rDDigbc8ZNpPNKa826jD3VPRqw xN187x0pZQySDJ3M1xtpHE56Jj4WKACu6i3BzC9T/y07RGHn/46ACn0B0xcfptLCGJv/D u63fPqRkouFyEQqvQPLiT57hFJmzNfVPkzZrMGe6sTUjqUlNF13FCkSqvmbantg0MyQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796477561; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=Q39JIyqwAQUOPENiqeSmQ3xQV83bGAke30SNmhQHwzg=; b=rSUpUCAU/m3MMGQcPDBFPBclmdLnntNOnzDn/OxJCZ+FzjuWjJf4Imjn6y+B89/GkETC GJToLKhPafLn9bxMNo1Os7yO/Fj2lrLH8Ld3Ox9+qB6+oi3wKdkOkUL1358hNJ5AAYrxp PMu/+EuUp/0WkmSkStdiKs33Vnd7tZrLqcuW+KlF+52d7VBmTGmTVQ4cl5GdZ9qxSo8y5 fxmbVgO01Njcquj45DhHgcQA/zGl/3WNpfTRmwkBm5MG/n1dHOaYNgYHmIqUBS5JUqO1p 2nIQIJ4YUDl2ZIk+FyKy0+397KlwRuj52f1sOl4J56PWg70jbSr/GMgi0P8B6NdSsgw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Ml7RESCR; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58B74606A68D for ; Sat, 5 Dec 2026 13:32:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Ml7RESCR Received: by smtp.kernel.org (Postfix) with ESMTPSA id F2AB41F00A15; Sat, 5 Dec 2026 13:32:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796477561; bh=Q39JIyqwAQUOPENiqeSmQ3xQV83bGAke30SNmhQHwzg=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Ml7RESCRStNhCFdAUykIUQ8Q4/1VMsDvaEo/3WO4npy43ltwepwGhSJFpUgOUNFWY 2rjnf3v0P1VKOgrGJ+db96hpJ5hFKpIxTZm0fJxM3/BaHBcZwzK4hmrlujPJq9Q8zA XvOjxlEtIac9OCo12mdsQyqQLD4RR6ItPekEG0TJEk/pbEdJxESyfoUpNgzuEGUrrC A4HamwrDMaTY6t010JCkF+CLbjWc53OYml3N0da4p+Qul7/4TrlQMoYrRAIfFQLJ7k LTBZbNPctpxKBrgzKsVxKSrS4/rBRRODe7pmv9mGj3YwUOFM9K6fxxQeaZDP+tImJz rOv7hJezSHAwA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] PCI/VGA: Serialize per-file resource counters Reply-To: sashiko-reviews@lists.linux.dev To: "Zhao Gongyi" Cc: linux-pci@vger.kernel.org In-Reply-To: <20261205131649.84007-1-zhaogongyi@bytedance.com> References: <20261205131649.84007-1-zhaogongyi@bytedance.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 13:32:40 +0000 X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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, c= onst char __user *buf, > goto done; > } > =20 > + spin_lock_irqsave(&priv->lock, flags); > if (io_state & VGA_RSRC_LEGACY_IO && uc->io_cnt =3D=3D 0) { > + spin_unlock_irqrestore(&priv->lock, flags); > ret_val =3D -EINVAL; > goto done; > } > =20 > if (io_state & VGA_RSRC_LEGACY_MEM && uc->mem_cnt =3D=3D 0) { > + spin_unlock_irqrestore(&priv->lock, flags); > ret_val =3D -EINVAL; > goto done; > } > =20 > - 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); > =20 > ret_val =3D 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 =3D pdev; for (i =3D 0; i < MAX_USER_CARDS; i++) { if (priv->cards[i].pdev =3D=3D pdev) break; if (priv->cards[i].pdev =3D=3D NULL) { priv->cards[i].pdev =3D pdev; priv->cards[i].io_cnt =3D 0; priv->cards[i].mem_cnt =3D 0; break; } } ... } CPU0 CPU1 vga_arb_write("target ...") priv->target =3D pdev priv->cards[i].pdev =3D 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 =3D &priv->cards[i] spin_lock_irqsave(&priv->lock) uc->io_cnt =3D=3D 0 (false) priv->cards[i].io_cnt =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205131649.8400= 7-1-zhaogongyi@bytedance.com?part=3D1