From: Waiman Long <longman@redhat.com>
To: Bjorn Helgaas <bhelgaas@google.com>
Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>,
Frederic Weisbecker <frederic@kernel.org>,
Danilo Krummrich <dakr@kernel.org>, Tejun Heo <tj@kernel.org>,
Jinhui Guo <guojinhui.liam@bytedance.com>,
Waiman Long <longman@redhat.com>
Subject: [PATCH RESEND v4 2/2] PCI: Call local_pci_probe() directly in pci_call_probe() if affined to the right node
Date: Wed, 2 Dec 2026 14:00:07 -0500 [thread overview]
Message-ID: <20261202190007.1852337-3-longman@redhat.com> (raw)
In-Reply-To: <20261202190007.1852337-1-longman@redhat.com>
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
next prev parent reply other threads:[~2026-12-02 19:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-12-02 19:15 ` [PATCH RESEND v4 2/2] PCI: Call local_pci_probe() directly in pci_call_probe() if affined to the right node sashiko-bot
2026-12-02 19:15 ` [PATCH RESEND v4 0/2] PCI: Suppress lockdep warning & make pci_call_probe() more efficient sashiko-bot
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=20261202190007.1852337-3-longman@redhat.com \
--to=longman@redhat.com \
--cc=bhelgaas@google.com \
--cc=dakr@kernel.org \
--cc=frederic@kernel.org \
--cc=guojinhui.liam@bytedance.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=tj@kernel.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 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.