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=1796238032; b=u3diCqAwRhMgdrH0cT9EwoJ0lScwno4vOZoZK1rrXsAHpeKVdkPNN890OjS4v8vMMy8p RRb762lO6dJVI7KZdev83pIEsFATr5l3c7SB8fl3cAUMkY8jcBWn9TZM4rpcFQDesUI3g Ug1UP6HywOGoG01Qg7Z8jJSNxS4/6b8taoycAMjhmMl3jzUNGpFu07Uehkrj7Z/S9dI3V jqvbsw3A0frLi54GjQ6DbGjiSDr4WZojff18RjdX6S46aObnezWTKLI2mm9LXuAAidHnY xpRIxM6zWJSwDvxLpJcLJvey4VHJixAMc2lwpXpvEas64DadeQsHieX/MPKx0lMgYDA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796238032; 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=4OhzRJOm6qtDJz8NnRPECN10N/TFAImFbJOfGlOi1FteImPY/XbQAux6R3QuYftbCFN+ /9wgHRK4qxqBrFjuZO485QBpmGDqgStqYwglqVeux+GW84cRFHf3VseDmRt4jiTMfhzIP fjBDFfTlKANbWRnYrCcR3CJJ3NcxkGzaRuFlAiL//EBXOLfPqf9odLDFDWRWcl+1buuKm bDPr4XLskyGn7INlzuMgFyem/6U5kyGVDTfLi0nKTMEMc+o7ZcUjAL4mxssXruJESKEzH qm5MLSLVhsvZsXUYmTBdsoYApvW8F1pUvdyGYvzCNdrne9fDFFXx+z5Yl2bWzZBYLhQ== 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=U0QE3CnD; 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 4B758606A686 for ; Wed, 2 Dec 2026 19:00:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4B758606A686 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=U0QE3CnD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796238032; 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=U0QE3CnDwoaF0qswM6HJ2YxLsTAfZxKbWauu4qvIeFZqYj0NBMbjeB+6MsM19qXTDpGM5G 8+ZjY/KQWC10DiIW8BKRf7CWB9skVFEKrEUny53X3Nmp7PP5Owc0Ev1Iyzd2hbgyXypt67 xv0x1moXMFL036SsJnIbHfaNTOgiUpY= 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-kernel@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