From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796238035; b=zbBMfSJ7ku36OQHRD53ewORXhlhcOrgt3JTq7zmp7GkB38BvfFwsaZNT/gJnOLW3aolR CEhXIJDpT8UjuQqs/YUkNgdHmWuL1k4QTgM/G3Q22BlnAmx/UVtg2/SRKKkuH1SpBNlec QuaZgJei6wfPXBNwF7Pht/kDd0fDmWcNkij7J/k10KVXfE5mrUfy+Vzhw4BouMhCyDEJM NBBhxfHXil29N6OEVh/lwl4+g4+SSaBHYiVeLRiXVf67hg4whGeeRy+sP+F4YhZfI6UK/ SRHoQa+x/r0k78AEZLjyWc8n6GzXsMEsp3PavCuC+/fDgkgE427nLY6+GAUOkR0ST+w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796238035; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:From:To:Cc:Subject:Date: Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Scanned-By; bh=Aol6nKG18dkROJk38V1LgElR8miB4KyM9FUarU9XaIM=; b=XepVs3+Cv+aVsWH6eqHHylMQ/QCNuLrlUdsl9uhU6Kv0yrZoDt+41zH1Ds39ajqBBRRF STk8jUNBzGQ0liQqRs/AZdZc5g/VEK6SxT/WBS/CxBRaioPLlXxyLKF2NXTwuMb7iLUjJ jERnOYSh6BnO9mI7LKV4418aBgfW5rcraZZfrLKAzj0h3bAJWP7lg3daCWdQbGclk0+Gh 0Eo6X0Kywb2oD02jC2ZRkI76UHDEi+hHqiuhWcR6tJVsFCcWuzpBwzKgDYB9Z+chH3fvz S/aNc66BMrPquOVk6MNnKqUGZVJ/YgAIhca3mwm6MYPcMVMB40AlJphJ+wfO0swisiA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=I3hPgZNg; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 635EB606A692 for ; Wed, 2 Dec 2026 19:00:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 635EB606A692 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=I3hPgZNg DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796238034; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Aol6nKG18dkROJk38V1LgElR8miB4KyM9FUarU9XaIM=; b=I3hPgZNgWHZM+VczEzTSfez0pRoFO5sngurz1GuEYdTxSs5bF9EqumfLi/NbIo8NzgTp9c L1CiS0HmFKtQIQ/p0puxPg25oJhputlru1T43ymWQ5I/DCw3Zun7EvIqkZTyOBo9jliFlc vLEUkA9T/yhjoWTECMwZxqhvJtpU1uk= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-526-0V4vPfv1N7uOUTTK4-fouQ-1; Wed, 2 Dec 2026 19:00:27 +0000 X-MC-Unique: 0V4vPfv1N7uOUTTK4-fouQ-1 X-Mimecast-MFC-AGG-ID: 0V4vPfv1N7uOUTTK4-fouQ_1796238026 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D6335195C585; Wed, 2 Dec 2026 19:00:25 +0000 (UTC) Received: from llong-thinkpadp16vgen1.rmtusnh.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 762627DD; Wed, 2 Dec 2026 19:00:24 +0000 (UTC) From: Waiman Long To: Bjorn Helgaas Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Frederic Weisbecker , Danilo Krummrich , Tejun Heo , Jinhui Guo , Waiman Long 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 Message-ID: <20261202190007.1852337-3-longman@redhat.com> In-Reply-To: <20261202190007.1852337-1-longman@redhat.com> References: <20261202190007.1852337-1-longman@redhat.com> X-Mailing-List: linux-pci@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 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 --- 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