From: Praneeth Balasubramanian <praneethb2002@gmail.com>
To: Juergen Gross <jgross@suse.com>,
Stefano Stabellini <sstabellini@kernel.org>
Cc: "Oleksandr Tyshchenko" <oleksandr_tyshchenko@epam.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org,
"Praneeth Balasubramanian" <praneethb2002@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH] xen-pciback: Hold the device lock when initializing seized devices late
Date: Fri, 4 Dec 2026 10:51:43 -0800 [thread overview]
Message-ID: <20261204185143.1688493-1-praneethb2002@gmail.com> (raw)
pcistub_init_device() resets the device through
pcistub_reset_device_state(), which calls __pci_reset_function_locked().
That function requires the device lock, and since commit f06e0ad226fd
("PCI: Use device_lock_assert() to verify device lock is held") it
asserts it.
When the driver is probed for a device after initialization, as for a
device bound through sysfs, pcistub_seize() runs pcistub_init_device()
from ->probe(), so the driver core holds the lock. Devices that are
seized while the driver registers, such as those listed in
xen-pciback.hide=, are initialized later by pcistub_init_devices_late(),
which does not take the lock. A dom0 kernel with lockdep warns once for
each such device at boot, and the reset is not serialized against other
users of the device lock.
Take the device lock around pcistub_init_device() in
pcistub_init_devices_late(), so it runs in the same context as on the
probe path.
The missing lock was found by a static check that turns the locking rule
in a function's comment into a Clang context-analysis requirement on its
callers. Compile tested only.
Fixes: cd9db80e5257 ("xen/pciback: Support pci_reset_function, aka FLR or D3 support.")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---
Notes:
This was found by a compiler-based check, part of research at UCSB SecLab.
The locking rule stated in the kernel-doc comment of the called function
was turned into a Clang context-analysis requirement (__must_hold) on that
function, and Clang 23 with CONFIG_WARN_CONTEXT_ANALYSIS then checked every
caller. An LLM was used only to turn the comment into a machine-readable
rule; the report itself comes from the compiler. The patch and changelog
were drafted with Claude Opus 5.5. I reviewed the patch and take
responsibility for it.
Testing: builds without new warnings with W=1 (x86_64, clang 23,
allmodconfig). Not runtime-tested, and I have not observed the race
myself.
drivers/xen/xen-pciback/pci_stub.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/pci_stub.c
index d1a335233aab..9eba7a982300 100644
--- a/drivers/xen/xen-pciback/pci_stub.c
+++ b/drivers/xen/xen-pciback/pci_stub.c
@@ -508,7 +508,9 @@ static int __init pcistub_init_devices_late(void)
spin_unlock_irqrestore(&pcistub_devices_lock, flags);
+ device_lock(&psdev->dev->dev);
err = pcistub_init_device(psdev);
+ device_unlock(&psdev->dev->dev);
if (err) {
dev_err(&psdev->dev->dev,
"error %d initializing device\n", err);
--
2.25.1
reply other threads:[~2026-12-04 18:51 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261204185143.1688493-1-praneethb2002@gmail.com \
--to=praneethb2002@gmail.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jgross@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=oleksandr_tyshchenko@epam.com \
--cc=sstabellini@kernel.org \
--cc=stable@vger.kernel.org \
--cc=xen-devel@lists.xenproject.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox