From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796238031; b=yUpt1sYD/p7nr/d4VcempcG7xj9SRWxSD7QfnmOvtlSMaXhzNzpBVwayg+wmyMTdiJCc 0KrpOC2Ok3+n0LbuKYY/k9IsVwNeVyFgh4vaE7eIlk2s/G4afHjY5lVP6NoyuP/OSoKK/ HCF5Sa3Js0o7iycj5J0rKOZkLLOmcG453nzlWgjO77uxt/7NXJmlGPoc4r2o/iLE4Ls3v ME0nO9KebuoZkk0Zoar43wKmsHivG8hPDhERfKB+0eXdbq3KA3JxT3s5QNUv2x7UrHbNr VcWtgKybPBrCimpcRW6zgX4GoHgYFyyMjml6IIqreRMoJjEQp/uy9ejYbzczPZWAgZw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796238031; 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=OHAt7TuuTklri+IMHsVyWdcso8toHileBdNzm6qY0Dg=; b=WMmbeblIFlpxbeOv51zrNSYtZlw7MOVjVd80vO2GYwxhcc/nQRP8wKSfN4Y4eg1Puv8F 5T55hZSrsUXeVCkm6AshtQe7cAe/37W7ZlMarx0XWD52r3GUjfJ6xihbp+P2IwGPPaoUY qagnZGYT4jfJXCGh/XAzguuE/zoS2msOars8cP60HUpIf6kl4EVxK7GJgYWYrtVPLOrW1 KI913BA7V6Q1zo874xtPdQXSCGI0CSv2YJgQzqLsGRMqxxPrzvDYx1E+WM+TAO0CyXIj3 ikLZ+aJ6APMQuFdJ2RVfpVqe157fUGxZY69P372NZOKfiNh4oNRrXR/xpRH25LXnyQg== 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=DYafc1aI; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 9B5E0606A32C for ; Wed, 2 Dec 2026 19:00:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9B5E0606A32C 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=DYafc1aI DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796238030; 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=OHAt7TuuTklri+IMHsVyWdcso8toHileBdNzm6qY0Dg=; b=DYafc1aIIsiNveKhny0FsydBY1wO+Ag+NFcZtTNPUC8ImMkon1o8FjbzXKZN7xm8+2iTaZ VNqQwgUTub9cvvkfhJhv/RJ7sHLiKF4yOyC9kRrMl0n7YDRReVPWNhIWWyPbnKEFhsx277 dDjRJ7BX6uL4T2QbyFr1fDPvnXPsnJ8= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-111-ByPmiu33OeyhHFKMePq2aQ-1; Wed, 2 Dec 2026 19:00:25 +0000 X-MC-Unique: ByPmiu33OeyhHFKMePq2aQ-1 X-Mimecast-MFC-AGG-ID: ByPmiu33OeyhHFKMePq2aQ_1796238024 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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3F98018736B8; Wed, 2 Dec 2026 19:00:24 +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 94A1D7DE; Wed, 2 Dec 2026 19:00:22 +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 1/2] PCI: Suppress false positive lockdep warning in pci_call_probe() Date: Wed, 2 Dec 2026 14:00:06 -0500 Message-ID: <20261202190007.1852337-2-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 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 --- 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