* [PATCH RESEND v4 0/2] PCI: Suppress lockdep warning & make pci_call_probe() more efficient
@ 2026-12-02 19:00 Waiman Long
2026-12-02 19:00 ` [PATCH RESEND v4 1/2] PCI: Suppress false positive lockdep warning in pci_call_probe() Waiman Long
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Waiman Long @ 2026-12-02 19:00 UTC (permalink / raw)
To: Bjorn Helgaas
Cc: linux-pci, linux-kernel, Thomas Gleixner, Frederic Weisbecker,
Danilo Krummrich, Tejun Heo, Jinhui Guo, Waiman Long
Patch 1 suppress the false positive lockdep warning when there is a
nested pci_call_probe() call. Patch 2 makes pci_call_probe() more
efficient when the current has been affined to the right node already.
Waiman Long (2):
PCI: Suppress false positive lockdep warning in pci_call_probe()
PCI: Call local_pci_probe() directly in pci_call_probe() if affined to
the right node
drivers/pci/pci-driver.c | 40 +++++++++++++++++++++++++++++++++-------
1 file changed, 33 insertions(+), 7 deletions(-)
--
2.56.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH RESEND v4 1/2] PCI: Suppress false positive lockdep warning in pci_call_probe()
2026-12-02 19:00 [PATCH RESEND v4 0/2] PCI: Suppress lockdep warning & make pci_call_probe() more efficient Waiman Long
@ 2026-12-02 19:00 ` Waiman Long
2026-12-02 19:00 ` [PATCH RESEND v4 2/2] PCI: Call local_pci_probe() directly in pci_call_probe() if affined to the right node Waiman Long
2026-12-02 19:15 ` [PATCH RESEND v4 0/2] PCI: Suppress lockdep warning & make pci_call_probe() more efficient sashiko-bot
2 siblings, 0 replies; 5+ messages in thread
From: Waiman Long @ 2026-12-02 19:00 UTC (permalink / raw)
To: Bjorn Helgaas
Cc: linux-pci, linux-kernel, Thomas Gleixner, Frederic Weisbecker,
Danilo Krummrich, Tejun Heo, Jinhui Guo, Waiman Long
local_pci_probe() and hence pci_call_probe() can be called recursively,
e.g. when vmd_probe() calls .probe() for devices in the new hierarchy
below VMD or a PF .probe() enables VFs and calls .probe() for them. If
the recursive calls are done indirectly via workqueue kworker, a lockdep
recursive warning like the following can be produced.
============================================
WARNING: possible recursive locking detected
7.1.0-rc6-test+ #1 Not tainted
--------------------------------------------
kworker/52:1/1593 is trying to acquire lock:
ffffc9001498f708 ((work_completion)(&arg.work)){+.+.}-{0:0}, at: start_flush_work+0x3e9/0x9a0
but task is already holding lock:
ffffc9001498fd10 ((work_completion)(&arg.work)){+.+.}-{0:0}, at: process_one_work+0xd4c/0x1390
other info that might help us debug this:
Possible unsafe locking scenario:
CPU0
----
lock((work_completion)(&arg.work));
lock((work_completion)(&arg.work));
*** DEADLOCK ***
This is a false positive warning due to the limitation on the number
of distinct lockdep keys allowed. The same lockdep key is used when the
INIT_WORK_ONSTACK() macro is called in pci_call_probe(). So when a work
function queued by pci_call_probe() calls into pci_call_probe() again
and another work function is queued and flushed, the lockdep warning
will be displayed. This can be suppressed by registering a dynamic key
and used it whenever the current task is a wq kworker.
Dynamic lockdep keys are limited finite resources and they should be
used only when really necessary.
Signed-off-by: Waiman Long <longman@redhat.com>
---
drivers/pci/pci-driver.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 2748ca22e9cf..57c52dd292ea 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -417,8 +417,21 @@ static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev,
error = local_pci_probe(&ddi);
} else {
struct pci_probe_arg arg = { .ddi = &ddi };
+ struct lock_class_key key;
+
+ /*
+ * A nested pci_call_probe() via a work func will produce a
+ * false positive lockdep recursive locking warning. Use
+ * lockdep_register_key() to provision a dynamic key to
+ * suppress this warning when the current task is a wq kworker.
+ */
+ if (current->flags & PF_WQ_WORKER) {
+ lockdep_register_key(&key);
+ INIT_WORK_ONSTACK_KEY(&arg.work, local_pci_probe_callback, &key);
+ } else {
+ INIT_WORK_ONSTACK(&arg.work, local_pci_probe_callback);
+ }
- INIT_WORK_ONSTACK(&arg.work, local_pci_probe_callback);
/*
* The target election and the enqueue of the work must be within
* the same RCU read side section so that when the workqueue pool
@@ -445,6 +458,8 @@ static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev,
}
destroy_work_on_stack(&arg.work);
+ if (current->flags & PF_WQ_WORKER)
+ lockdep_unregister_key(&key);
}
dev->is_probed = 0;
--
2.56.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH RESEND v4 2/2] PCI: Call local_pci_probe() directly in pci_call_probe() if affined to the right node
2026-12-02 19:00 [PATCH RESEND v4 0/2] PCI: Suppress lockdep warning & make pci_call_probe() more efficient Waiman Long
2026-12-02 19:00 ` [PATCH RESEND v4 1/2] PCI: Suppress false positive lockdep warning in pci_call_probe() Waiman Long
@ 2026-12-02 19:00 ` Waiman Long
2026-12-02 19:15 ` sashiko-bot
2026-12-02 19:15 ` [PATCH RESEND v4 0/2] PCI: Suppress lockdep warning & make pci_call_probe() more efficient sashiko-bot
2 siblings, 1 reply; 5+ messages in thread
From: Waiman Long @ 2026-12-02 19:00 UTC (permalink / raw)
To: Bjorn Helgaas
Cc: linux-pci, linux-kernel, Thomas Gleixner, Frederic Weisbecker,
Danilo Krummrich, Tejun Heo, Jinhui Guo, Waiman Long
Currently pci_call_probe() will unconditionally queue a work function
to perform the actual device probing whenever the device is associated
with a valid NUMA node. The use of work function originally comes from
commit 873392ca514f ("PCI: work_on_cpu: use in drivers/pci/pci-driver.c")
to execute the device probing and allocate memory on the right node
where the device bus is attached to.
This is inefficient to schedule another work function in the same or a
neigboring CPU and wait for its completion when the current task is a
work function itself queued by pci_call_probe() or async_schedule_dev()
that has been affined to the right node already. It will also reduce
the amount of parallelism as noted in [1].
Fix that by calling local_pci_probe() directly if the current task has
been affined to the right NUMA node. Now lockdep dynamic key will only
be used if the current task is a wq kworker but is not affined to the
right node.
[1] https://lore.kernel.org/linux-pci/20251227113326.964-1-guojinhui.liam@bytedance.com/
Signed-off-by: Waiman Long <longman@redhat.com>
---
drivers/pci/pci-driver.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 57c52dd292ea..13f4312e74f7 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -398,6 +398,8 @@ static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev,
{
int error, node, cpu;
struct drv_dev_and_id ddi = { drv, dev, id };
+ bool node_invalid, affine_to_node;
+ const struct cpumask *node_cpus;
/*
* Execute driver initialization on node where the device is
@@ -406,14 +408,24 @@ static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev,
*/
node = dev_to_node(&dev->dev);
dev->is_probed = 1;
+ node_invalid = node < 0 || node >= MAX_NUMNODES || !node_online(node);
+
+ if (node_invalid) {
+ node_cpus = cpu_online_mask;
+ affine_to_node = false;
+ } else {
+ node_cpus = cpumask_of_node(node);
+ /* Check if the current task is affined to the right node */
+ affine_to_node = cpumask_subset(current->cpus_ptr, node_cpus);
+ }
cpu_hotplug_disable();
/*
- * Prevent nesting work_on_cpu() for the case where a Virtual Function
- * device is probed from work_on_cpu() of the Physical device.
+ * Prevent nesting queue_work_on() for the case where a Virtual Function
+ * device is probed from queue_work_on() of the Physical function or
+ * when the current task is affined to the right node.
*/
- if (node < 0 || node >= MAX_NUMNODES || !node_online(node) ||
- pci_physfn_is_probed(dev)) {
+ if (node_invalid || affine_to_node || pci_physfn_is_probed(dev)) {
error = local_pci_probe(&ddi);
} else {
struct pci_probe_arg arg = { .ddi = &ddi };
@@ -440,8 +452,7 @@ static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev,
* targets.
*/
rcu_read_lock();
- cpu = cpumask_any_and(cpumask_of_node(node),
- housekeeping_cpumask(HK_TYPE_DOMAIN));
+ cpu = cpumask_any_and(node_cpus, housekeeping_cpumask(HK_TYPE_DOMAIN));
if (cpu < nr_cpu_ids) {
struct workqueue_struct *wq = pci_probe_wq;
--
2.56.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH RESEND v4 2/2] PCI: Call local_pci_probe() directly in pci_call_probe() if affined to the right node
2026-12-02 19:00 ` [PATCH RESEND v4 2/2] PCI: Call local_pci_probe() directly in pci_call_probe() if affined to the right node Waiman Long
@ 2026-12-02 19:15 ` sashiko-bot
0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-12-02 19:15 UTC (permalink / raw)
To: Waiman Long; +Cc: linux-pci
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] PCI: cpumask_subset() in pci_call_probe() misses unbound
async_wq workers
- [Medium] PCI: affine_to_node check in pci_call_probe() bypasses
HK_TYPE_DOMAIN
- [Low] PCI: pci_call_probe() checks node state and affinity before
disabling hotplug
--
commit 9f7bc4a2d73c970ab760b19214b180be397319cb
Author: Waiman Long <longman@redhat.com>
PCI: Call local_pci_probe() directly in pci_call_probe() if affined to the right node
This commit modifies pci_call_probe() to invoke local_pci_probe() directly
instead of queueing work when current->cpus_ptr is a subset of the target
NUMA node's cpumask.
> diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
> index 57c52dd292ea6..13f4312e74f7d 100644
> --- a/drivers/pci/pci-driver.c
> +++ b/drivers/pci/pci-driver.c
> @@ -398,6 +398,8 @@ static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev,
> {
> int error, node, cpu;
> struct drv_dev_and_id ddi = { drv, dev, id };
> + bool node_invalid, affine_to_node;
> + const struct cpumask *node_cpus;
>
> /*
> * Execute driver initialization on node where the device is
> @@ -406,14 +408,24 @@ static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev,
> */
> node = dev_to_node(&dev->dev);
> dev->is_probed = 1;
> + node_invalid = node < 0 || node >= MAX_NUMNODES || !node_online(node);
> +
> + if (node_invalid) {
> + node_cpus = cpu_online_mask;
> + affine_to_node = false;
> + } else {
> + node_cpus = cpumask_of_node(node);
> + /* Check if the current task is affined to the right node */
> + affine_to_node = cpumask_subset(current->cpus_ptr, node_cpus);
> + }
[Severity: Medium]
Does cpumask_subset(current->cpus_ptr, node_cpus) ever match workers from
async_schedule_dev() on multi-node NUMA systems?
async_schedule_dev() queues work onto async_wq, which is allocated with
WQ_UNBOUND and default non-strict affinity (affn_strict == false):
kernel/workqueue.c:pool_allowed_cpus() {
if (!is_percpu_pool(pool) && pool->attrs->affn_strict)
return pool->attrs->__pod_cpumask;
else
return pool->attrs->cpumask;
}
create_worker() binds unbound workers to pool_allowed_cpus(pool), so an
async_wq worker's current->cpus_ptr spans wq_unbound_cpumask across all
NUMA nodes rather than a single node. On multi-node systems,
affine_to_node is always false for async_wq workers, so they still allocate
a dynamic lockdep key and serialize probing via queue_work_on() on
pci_probe_wq.
>
> cpu_hotplug_disable();
[Severity: Low]
Can evaluating node_online(node), cpumask_of_node(node), and
cpumask_subset(current->cpus_ptr, node_cpus) before cpu_hotplug_disable()
race with CPU hotplug?
If the CPUs in current->cpus_ptr are taken offline before
cpu_hotplug_disable() is reached, current's affinity is broken and the task
is migrated to another node, while pci_call_probe() proceeds with the stale
affine_to_node == true result and runs local_pci_probe() on the wrong NUMA
node.
> /*
> - * Prevent nesting work_on_cpu() for the case where a Virtual Function
> - * device is probed from work_on_cpu() of the Physical device.
> + * Prevent nesting queue_work_on() for the case where a Virtual Function
> + * device is probed from queue_work_on() of the Physical function or
> + * when the current task is affined to the right node.
> */
> - if (node < 0 || node >= MAX_NUMNODES || !node_online(node) ||
> - pci_physfn_is_probed(dev)) {
> + if (node_invalid || affine_to_node || pci_physfn_is_probed(dev)) {
> error = local_pci_probe(&ddi);
> } else {
[Severity: Medium]
Can the affine_to_node fast path run local_pci_probe() on domain-isolated
CPUs and bypass housekeeping_update() synchronization?
node_cpus is cpumask_of_node(node), which includes isolated CPUs excluded
from housekeeping_cpumask(HK_TYPE_DOMAIN). When current->cpus_ptr is a
subset of cpumask_of_node(node) (for example, a task with default affinity
on a single-node system or a task affined to a node that contains isolated
CPUs), affine_to_node is true even if current->cpus_ptr includes isolated
CPUs. Calling local_pci_probe() directly here skips the RCU-protected
housekeeping_cpumask(HK_TYPE_DOMAIN) check and pci_probe_wq execution that
608fedd2f303 ("PCI: Prepare to protect against concurrent isolated cpuset
change") and 29b306c44eb5 ("PCI: Flush PCI probe workqueue on cpuset
isolated partition change") rely on when flushing in-flight probes during
cpuset isolation updates.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202190007.1852337-1-longman@redhat.com?part=2
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH RESEND v4 0/2] PCI: Suppress lockdep warning & make pci_call_probe() more efficient
2026-12-02 19:00 [PATCH RESEND v4 0/2] PCI: Suppress lockdep warning & make pci_call_probe() more efficient Waiman Long
2026-12-02 19:00 ` [PATCH RESEND v4 1/2] PCI: Suppress false positive lockdep warning in pci_call_probe() Waiman Long
2026-12-02 19:00 ` [PATCH RESEND v4 2/2] PCI: Call local_pci_probe() directly in pci_call_probe() if affined to the right node Waiman Long
@ 2026-12-02 19:15 ` sashiko-bot
2 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-12-02 19:15 UTC (permalink / raw)
To: Waiman Long; +Cc: linux-pci
Sashiko has finished reviewing this 2-patch series:
- Patch 1: no issues found.
- Patch 2 ("PCI: Call local_pci_probe() directly in pci_call_pro..."): 3
potential issues (2 Medium, 1 Low)
A detailed review has been sent as a separate reply to patch 2.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202190007.1852337-1-longman@redhat.com
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-02 19:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 19:00 [PATCH RESEND v4 0/2] PCI: Suppress lockdep warning & make pci_call_probe() more efficient Waiman Long
2026-12-02 19:00 ` [PATCH RESEND v4 1/2] PCI: Suppress false positive lockdep warning in pci_call_probe() Waiman Long
2026-12-02 19:00 ` [PATCH RESEND v4 2/2] PCI: Call local_pci_probe() directly in pci_call_probe() if affined to the right node Waiman Long
2026-12-02 19:15 ` sashiko-bot
2026-12-02 19:15 ` [PATCH RESEND v4 0/2] PCI: Suppress lockdep warning & make pci_call_probe() more efficient 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.