From nobody Tue Sep 29 06:11:06 2026 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66F073C061C for ; Tue, 11 Aug 2026 16:07:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786464425; cv=none; b=hNii6Nax9/tlRg3dNmTE/Y5Xlv+fUwgKky3QePDpdfoo25dYEh2TPznezLUAlLqR5YBv2BIzLc8rpK9YjfcbMi1vEb7uGkf4TGcvvqHH5zJwjwfxV77ia3CSRjT7rj2QCFeS9Or4qO1kxmx53citvKpJmIwyYHkYnVaz/8U+EBg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786464425; c=relaxed/simple; bh=s7zP/G+oeEaVi0BMhvkcbTExiUknMwFMVDCdVWZnBbw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ne2tW5vBM5UsC/yaKbKnRacYNxjYVbjSZ5e6s1IaisNzq9yv4EAM2QDGM3AQr/xmh5pxxX2Tm8HZf00raP4xFBu7A95UuPNca3fthrNKVOC4AuoTbpOnxPtpImpV8p7c2WtAAXyI/lU8MyHY2ioI1OLXBvX+JoSxRWLdMPgis7s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=d3M67rtg; arc=none smtp.client-ip=209.85.216.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="d3M67rtg" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-3900e39d935so67240a91.0 for ; Tue, 11 Aug 2026 09:07:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1786464421; x=1787069221; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=7G7x9YFsXn4FS+MsawAPuBrlOk9V6aLvapXNJP5fUgU=; b=d3M67rtgs4AFv10xtjomxDkvwoWQDAvQ0qFtUxsD+I2P7yiWi2IdCYtqMUp0wVhOLz KM9oKDfA6IxjelvwQfBFD01nGpiNxVQE9imH0+pu/u2IB0VjSgPlrbiYI+xXOnMRj0fz Y1F6n1ZmwJ1lq2SQpz09C22x5FN7fOH4iX4VsvvUV+ce1DaWN5WddUbwTkMzb5Y3rx7T 18V5K0Z+TG/FBkkFYzkgMuBzhHL0X7g8gH9bcn0EiUKdpPDDOAV26PeB2t6Aqu5uI5Qu TDonXmx/wss5KfXrr+7BjY3vsoOow+HmmX7OLI8+ujWYof5odloeqcG3KSO9RPJD41f4 mSdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786464421; x=1787069221; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=7G7x9YFsXn4FS+MsawAPuBrlOk9V6aLvapXNJP5fUgU=; b=lxEcwLlOTUJi8tqlj9hRmqSlE3hptYroLyAgjeXKjkpf1YuoeTjiY6vKZqJFHj5e3J lwC4OLwznncjxh3UWKI5iaNIRdmyBbjmSZS+q0Yj9DTNFCCMiPUSXAdC+s/nQwU/YRv5 BXpUuF4ewFyhjxI4pd1cflhoiySVl6wkurXUXzZO6PXV+ty6dXUy2rbweogaU/ploQzc 2n24CmBxssnxojGwrxtzU+V4ZqPmKj5OayOJ+aFvj93wuMvHRiAyezJ/gwtnteLUKaPj BzcZdqZTabtg1e6tBu+HHAu9hR72+6ItwW7loP5Cfpvdd6D+H0idzpbbS5jbJq94eyo5 UP/w== X-Forwarded-Encrypted: i=1; AHgh+RpfMbHNhGUNy5uf78WFerVxpfIUJvQhGtEKILnJvY1KcFlaQ/WiX1k9JMPIzaZuRZZXoZn5SmpBblT5Aak=@vger.kernel.org X-Gm-Message-State: AOJu0Yzb5q+oCl0ilCt2nb9hCmGu3dEjZGk2D2orNUDPFTXdUnGxmOVh G1N3VNsE5yXi9KeQEz9KT7zhvGLqiMjwrnkppm9jI5Db6P7UmyKw5+mbcUp9WmJlE/Q= X-Gm-Gg: AR+sD12SCVJQy8959rsbaKakW24QWmMCXmkJp5pKQjz28u8tHkef8I0DIoxhEtBTeKk br7W0/8ElIyJ9tZ0zo+sad4TKIKhSZ2vefTe8ENm2i/I1ZvZxnIxFiAhNVBUzNlvWBdhVERW0lv ePgoLCGUMY3DVz1wppdUt9zL2qdbeyS+eRuzl2EF88BR3XJafTijC2RSNPcUj2QSbI1qEdkV59O 8LuPbzwcSTKztYuYZtmB7pCkgyXsJY7Eu3JjL6oAIGdwr5Ni0uTlSOM7p2oOQoyKkXci6oU/qpL ua3+fUR7UMACNFvAZrx0lnPuoRG/g345YOmS+v5guIN1A02Kx66uGJidEwt23eIhmvAhwlB6b0C HPGO/NbjVhaq+t0xWGSCOY3elhzaHPv4Ty/fz3VPsPxcYpf/fSIgP230xcNBm4ILqYFfqACO0WC S8QLwglCyqg8upA4hFrF/oe7BFjT9o99rMNBVN8q8U1xKzdbOKxOdwa6i0QFIWlECWKXqIZvmpO 3Qc1DO+QnXR+7ELQqs= X-Received: by 2002:a17:90b:2dca:b0:381:a766:efc9 with SMTP id 98e67ed59e1d1-392ec34642fmr5541878a91.7.1786464421415; Tue, 11 Aug 2026 09:07:01 -0700 (PDT) Received: from FJ7FR2JRQ3 ([178.93.176.7]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-31cf7094c8dsm822008eec.31.2026.08.11.09.06.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 11 Aug 2026 09:07:00 -0700 (PDT) From: Zhanpeng Zhang To: Shuai Xue , Jing Zhang Cc: Will Deacon , Mark Rutland , Yicong Yang , Baolin Wang , Jonathan Cameron , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Zhanpeng Zhang Subject: [PATCH v2 1/2] perf/dwc_pcie: Avoid nested bus notifier locking Date: Wed, 12 Aug 2026 00:06:49 +0800 Message-ID: <20260811160649.28255-1-zhangzhanpeng.jasper@bytedance.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260811131714.12779-1-zhangzhanpeng.jasper@bytedance.com> References: <20260811131714.12779-1-zhangzhanpeng.jasper@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" dwc_pcie_pmu_notifier() registers a synthetic platform device directly from the BUS_NOTIFY_ADD_DEVICE callback. Bus notifier callbacks run with the bus_notifier rwsem held, so platform_device_register_data() enters the platform bus notifier chain before the PCI bus notifier returns. When PCI host bridges are registered during late init, lockdep reports this as possible recursive locking. Move platform device reconciliation to a work item that runs after the PCI notifier returns. Serialize it with PCI rescan and removal, and parent each synthetic device to its Root Port so their lifetimes remain coupled. During removal, unregister the perf PMU and its CPU hotplug instance before PCI resources disappear, then defer only platform device destruction. Disable manual bind controls to preserve that ordering. Fixes: af9597adc2f1 ("drivers/perf: add DesignWare PCIe PMU driver") Signed-off-by: Zhanpeng Zhang --- Tested on a RISC-V system with CONFIG_KASAN, CONFIG_PROVE_LOCKING, CONFIG_DEBUG_LOCK_ALLOC and CONFIG_LOCKDEP enabled. Late-init PCI discovery no longer triggers the nested bus notifier warning. drivers/perf/dwc_pcie_pmu.c | 149 +++++++++++++++++++++++++++--------- 1 file changed, 113 insertions(+), 36 deletions(-) diff --git a/drivers/perf/dwc_pcie_pmu.c b/drivers/perf/dwc_pcie_pmu.c index 5385401fa9cf..7b2e28aade73 100644 --- a/drivers/perf/dwc_pcie_pmu.c +++ b/drivers/perf/dwc_pcie_pmu.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -20,6 +21,7 @@ #include #include #include +#include =20 #define DWC_PCIE_EVENT_CNT_CTL 0x8 =20 @@ -103,12 +105,15 @@ struct dwc_pcie_pmu { static int dwc_pcie_pmu_hp_state; static struct list_head dwc_pcie_dev_info_head =3D LIST_HEAD_INIT(dwc_pcie_dev_info_head); +static DEFINE_MUTEX(dwc_pcie_dev_info_lock); +static struct work_struct dwc_pcie_pmu_work; static bool notify; =20 struct dwc_pcie_dev_info { struct platform_device *plat_dev; struct pci_dev *pdev; struct list_head dev_node; + bool removed; }; =20 static ssize_t cpumask_show(struct device *dev, @@ -593,6 +598,8 @@ static struct dwc_pcie_dev_info *dwc_pcie_find_dev_info= (struct pci_dev *pdev) { struct dwc_pcie_dev_info *dev_info; =20 + lockdep_assert_held(&dwc_pcie_dev_info_lock); + list_for_each_entry(dev_info, &dwc_pcie_dev_info_head, dev_node) if (dev_info->pdev =3D=3D pdev) return dev_info; @@ -634,7 +641,6 @@ static u16 dwc_pcie_des_cap(struct pci_dev *pdev) static void dwc_pcie_unregister_dev(struct dwc_pcie_dev_info *dev_info) { platform_device_unregister(dev_info->plat_dev); - list_del(&dev_info->dev_node); kfree(dev_info); } =20 @@ -644,25 +650,92 @@ static int dwc_pcie_register_dev(struct pci_dev *pdev) struct dwc_pcie_dev_info *dev_info; u32 sbdf; =20 - sbdf =3D (pci_domain_nr(pdev->bus) << 16) | PCI_DEVID(pdev->bus->number, = pdev->devfn); - plat_dev =3D platform_device_register_simple("dwc_pcie_pmu", sbdf, NULL, = 0); - if (IS_ERR(plat_dev)) - return PTR_ERR(plat_dev); - dev_info =3D kzalloc_obj(*dev_info); - if (!dev_info) { - platform_device_unregister(plat_dev); + if (!dev_info) return -ENOMEM; - } =20 - /* Cache platform device to handle pci device hotplug */ + sbdf =3D (pci_domain_nr(pdev->bus) << 16) | + PCI_DEVID(pdev->bus->number, pdev->devfn); + plat_dev =3D platform_device_register_data(&pdev->dev, "dwc_pcie_pmu", + sbdf, NULL, 0); + if (IS_ERR(plat_dev)) { + kfree(dev_info); + return PTR_ERR(plat_dev); + } dev_info->plat_dev =3D plat_dev; dev_info->pdev =3D pdev; - list_add(&dev_info->dev_node, &dwc_pcie_dev_info_head); + + mutex_lock(&dwc_pcie_dev_info_lock); + list_add_tail(&dev_info->dev_node, &dwc_pcie_dev_info_head); + mutex_unlock(&dwc_pcie_dev_info_lock); =20 return 0; } =20 +static void dwc_pcie_quiesce_dev(struct dwc_pcie_dev_info *dev_info) +{ + struct dwc_pcie_pmu *pcie_pmu; + + pcie_pmu =3D platform_get_drvdata(dev_info->plat_dev); + if (!pcie_pmu) + return; + + /* Stop config-space accesses before PCI host resources are released. */ + platform_set_drvdata(dev_info->plat_dev, NULL); + devm_release_action(&dev_info->plat_dev->dev, dwc_pcie_unregister_pmu, + pcie_pmu); + devm_release_action(&dev_info->plat_dev->dev, + dwc_pcie_pmu_remove_cpuhp_instance, + &pcie_pmu->cpuhp_node); +} + +static int dwc_pcie_reconcile_devices(void) +{ + LIST_HEAD(removed_devices); + struct dwc_pcie_dev_info *dev_info, *tmp; + struct pci_dev *pdev =3D NULL; + int error =3D 0; + int ret; + + pci_lock_rescan_remove(); + mutex_lock(&dwc_pcie_dev_info_lock); + list_for_each_entry_safe(dev_info, tmp, &dwc_pcie_dev_info_head, dev_node) + if (dev_info->removed) + list_move_tail(&dev_info->dev_node, &removed_devices); + mutex_unlock(&dwc_pcie_dev_info_lock); + + list_for_each_entry_safe(dev_info, tmp, &removed_devices, dev_node) { + list_del(&dev_info->dev_node); + dwc_pcie_unregister_dev(dev_info); + } + + for_each_pci_dev(pdev) { + if (!dwc_pcie_des_cap(pdev)) + continue; + + mutex_lock(&dwc_pcie_dev_info_lock); + dev_info =3D dwc_pcie_find_dev_info(pdev); + mutex_unlock(&dwc_pcie_dev_info_lock); + if (dev_info) + continue; + + ret =3D dwc_pcie_register_dev(pdev); + if (ret) { + pci_warn(pdev, "failed to register DWC PCIe PMU: %d\n", ret); + if (!error) + error =3D ret; + } + } + pci_unlock_rescan_remove(); + + return error; +} + +static void dwc_pcie_update_devices(struct work_struct *work) +{ + dwc_pcie_reconcile_devices(); +} + static int dwc_pcie_pmu_notifier(struct notifier_block *nb, unsigned long action, void *data) { @@ -674,14 +747,19 @@ static int dwc_pcie_pmu_notifier(struct notifier_bloc= k *nb, case BUS_NOTIFY_ADD_DEVICE: if (!dwc_pcie_des_cap(pdev)) return NOTIFY_DONE; - if (dwc_pcie_register_dev(pdev)) - return NOTIFY_BAD; + schedule_work(&dwc_pcie_pmu_work); break; case BUS_NOTIFY_DEL_DEVICE: + mutex_lock(&dwc_pcie_dev_info_lock); dev_info =3D dwc_pcie_find_dev_info(pdev); + if (dev_info) { + dwc_pcie_quiesce_dev(dev_info); + dev_info->removed =3D true; + } + mutex_unlock(&dwc_pcie_dev_info_lock); if (!dev_info) return NOTIFY_DONE; - dwc_pcie_unregister_dev(dev_info); + schedule_work(&dwc_pcie_pmu_work); break; } =20 @@ -702,18 +780,14 @@ static int dwc_pcie_pmu_probe(struct platform_device = *plat_dev) int ret; =20 sbdf =3D plat_dev->id; - pdev =3D pci_get_domain_bus_and_slot(sbdf >> 16, PCI_BUS_NUM(sbdf & 0xfff= f), - sbdf & 0xff); - if (!pdev) { - pr_err("No pdev found for the sbdf 0x%x\n", sbdf); + if (!plat_dev->dev.parent || plat_dev->dev.parent->bus !=3D &pci_bus_type) return -ENODEV; - } =20 + pdev =3D to_pci_dev(plat_dev->dev.parent); vsec =3D dwc_pcie_des_cap(pdev); if (!vsec) return -ENODEV; =20 - pci_dev_put(pdev); name =3D devm_kasprintf(&plat_dev->dev, GFP_KERNEL, "dwc_rootport_%x", sb= df); if (!name) return -ENOMEM; @@ -766,6 +840,8 @@ static int dwc_pcie_pmu_probe(struct platform_device *p= lat_dev) if (ret) return ret; =20 + platform_set_drvdata(plat_dev, pcie_pmu); + return 0; } =20 @@ -815,7 +891,11 @@ static int dwc_pcie_pmu_offline_cpu(unsigned int cpu, = struct hlist_node *cpuhp_n =20 static struct platform_driver dwc_pcie_pmu_driver =3D { .probe =3D dwc_pcie_pmu_probe, - .driver =3D {.name =3D "dwc_pcie_pmu",}, + .driver =3D { + .name =3D "dwc_pcie_pmu", + .probe_type =3D PROBE_FORCE_SYNCHRONOUS, + .suppress_bind_attrs =3D true, + }, }; =20 static void dwc_pcie_cleanup_devices(void) @@ -823,32 +903,21 @@ static void dwc_pcie_cleanup_devices(void) struct dwc_pcie_dev_info *dev_info, *tmp; =20 list_for_each_entry_safe(dev_info, tmp, &dwc_pcie_dev_info_head, dev_node= ) { + list_del(&dev_info->dev_node); dwc_pcie_unregister_dev(dev_info); } } =20 static int __init dwc_pcie_pmu_init(void) { - struct pci_dev *pdev =3D NULL; int ret; =20 - for_each_pci_dev(pdev) { - if (!dwc_pcie_des_cap(pdev)) - continue; - - ret =3D dwc_pcie_register_dev(pdev); - if (ret) { - pci_dev_put(pdev); - goto err_cleanup; - } - } - ret =3D cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, "perf/dwc_pcie_pmu:online", dwc_pcie_pmu_online_cpu, dwc_pcie_pmu_offline_cpu); if (ret < 0) - goto err_cleanup; + return ret; =20 dwc_pcie_pmu_hp_state =3D ret; =20 @@ -856,19 +925,26 @@ static int __init dwc_pcie_pmu_init(void) if (ret) goto err_remove_cpuhp; =20 + INIT_WORK(&dwc_pcie_pmu_work, dwc_pcie_update_devices); ret =3D bus_register_notifier(&pci_bus_type, &dwc_pcie_pmu_nb); if (ret) goto err_unregister_driver; notify =3D true; + ret =3D dwc_pcie_reconcile_devices(); + if (ret) + goto err_unregister_notifier; =20 return 0; =20 +err_unregister_notifier: + bus_unregister_notifier(&pci_bus_type, &dwc_pcie_pmu_nb); + notify =3D false; + cancel_work_sync(&dwc_pcie_pmu_work); + dwc_pcie_cleanup_devices(); err_unregister_driver: platform_driver_unregister(&dwc_pcie_pmu_driver); err_remove_cpuhp: cpuhp_remove_multi_state(dwc_pcie_pmu_hp_state); -err_cleanup: - dwc_pcie_cleanup_devices(); return ret; } =20 @@ -876,6 +952,7 @@ static void __exit dwc_pcie_pmu_exit(void) { if (notify) bus_unregister_notifier(&pci_bus_type, &dwc_pcie_pmu_nb); + cancel_work_sync(&dwc_pcie_pmu_work); dwc_pcie_cleanup_devices(); platform_driver_unregister(&dwc_pcie_pmu_driver); cpuhp_remove_multi_state(dwc_pcie_pmu_hp_state); --=20 2.50.1 (Apple Git-155) From nobody Tue Sep 29 06:11:06 2026 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E94B45198A for ; Tue, 11 Aug 2026 16:07:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786464455; cv=none; b=JW0JWS+wwN2UHdgfkTbDQRw23WA5eluHeDqfgW+9GpWlPex6tGsFS+njbVppovo5QMJTLEEjNh3xQxzx4340vRu8AYPi3PD1wNYF20cKqDqKxyvujrT6txtcupOWv/S2GGis1OJk9hsEr5mpIFv1FASZAxyNCO1vPaG8vi32lTY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786464455; c=relaxed/simple; bh=b4iGCjAETc70J2mY90wjgIvRfv40Kh3jeZC9IcZWgrQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qKVmuw51S1JOqxxCCAhIFOg7FK4aqe6+7fbi7qYTQ85EBQ0xXw4XfMPlLyAZaH8nzgm/PaPSlNH/w1esFHYlr4SRkEUkUuojji6k8MbusLNj6/0qzkwGAbXoxh2PDd0YT+ZR78RqGicXWJelFN7wwEVu6MKxM/KvjOiP8lnIOtM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=hDG6nBoS; arc=none smtp.client-ip=209.85.215.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="hDG6nBoS" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-cbedf433a99so352850a12.2 for ; Tue, 11 Aug 2026 09:07:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1786464453; x=1787069253; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=eCz0YHuViuBY7u6bH/PtQQQ8c7S/xgDkr5juavEWHHA=; b=hDG6nBoS/RaRB1vO1cgCc17CBWzxC6NsupXtVyU7ozjYPA8WOvHA2mTHuCt7AjIyhN MzN4lGO4emwjGB2zLNiYWC2HgvpAPV0YTwllGpbRpljkUbLM1wUHdlN6WPaZkdyyioA3 pvOoDkHrt8J9lp8hnG/PwY9+Ss88nKC2W16/twT+mTeUGRqyDSs0Q4DWb0D1MkWOrYkM YaDEuGCCgApqGK75nrPs5ulkXTZJvJfc9OBfkCyEmeGa2FztUyECxTl3scsNoFYXPohK rvSlt9X1iLONYq4uTtURY1qfPc4bUK9b7t5HBYx1WtyoOviC2+ErVqD6+iBv+E9xQgQ1 lG5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786464453; x=1787069253; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=eCz0YHuViuBY7u6bH/PtQQQ8c7S/xgDkr5juavEWHHA=; b=mSx+PSn4kiaFvjJiM1RuzX7OBHS/1Iogas5QSpLFqJtlofy7KD6JKyamx3uc5AszQX CM9jC27dj3v+XkJwn3mNozI8YDWjNLXL0Ks9ForYl0gNLjDnV8okdTtmjwMwqww92wIF ZdIOSkehG7BzCmAcLvcDFysoylRd1quPcb6r6XIsdMFHaCcDualXk/GGOvqE7m+dO/+M t7WgznyVM/ItGsysHGxUfLoSNTuRV5LyaNLqe10g4nU8IiNlFmPKqorcZaPf4Y3oPv8b LbZIwKs3rpboF9hvReSviSJBDOpj5xJFBkAWIY+z3iWesAFZOBQqx7zV5vP39yM/r4LU K9XA== X-Forwarded-Encrypted: i=1; AHgh+RqmLjOdfeuZpbOmFSaXh15FMPWb+qemiL9pBed0R12B1J6oi6i9L2F9kREPQfHBMhKZlbQBf/a2b126ARU=@vger.kernel.org X-Gm-Message-State: AOJu0YwnZh99dvFQhg83wXYROw99wtZmlIZ6IKVXdOgq0kMiGO8ir9WD zaUJfiMBrCeLRdSVz6HQBb6pRX3lQEaYihr+vjGgxEOWD9ugsd3dSycBgKF6OkoTbJo= X-Gm-Gg: AR+sD12AgMvy9BLRWFGFgT9eY468hiSySELsmhqqiJI+ZsANSbYz1v/G/oAuMaStO/j 4VUuYCBQf+hZ79bgInOnlfL+GumypKDN24sN5Fe4Zia1C/GaWBfosnbnYGhvRfF6BE/UiMyrzIc lIQmcnXdLuei73QN8mWWB6ia2yz+QuOp8wYavKLQzr4vxM7GiDhx5RkebXB1AXSIHpeYuw+ZXt7 eosKX1uWtoscQOdYaPVK3EsnqtxX+pp4SSCSJywqMIugahDWaQHI+U7xy8ZWh6xM9GBoEz3IXnx Aa3VUYxlSstOIFGUlGvGhzpBXJ5X8zCeaIroOy0lPtiazk5pPkphphxOp6AGRGyophB8hxjEP1j pKknIzWS6Gv+PwhEgjXhr9AXuzwJCUrbCFIPmkMac7VQRJWfWgIt0ddedNaT67kbur2HtsXlAft NFtpqz0B9oBlKG5g+mmGfoDvqg2ApxvRCTHbfVlsL62YUpw3Bhrjq1V69bumtliW9qrbWi8I7Iu FTIM8UHnydrErF524c= X-Received: by 2002:a05:6a21:6497:b0:3b7:aefe:4367 with SMTP id adf61e73a8af0-3cc2bb05975mr6307163637.33.1786464452412; Tue, 11 Aug 2026 09:07:32 -0700 (PDT) Received: from FJ7FR2JRQ3 ([178.93.176.7]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-31cf3d0517csm893108eec.9.2026.08.11.09.07.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 11 Aug 2026 09:07:31 -0700 (PDT) From: Zhanpeng Zhang To: Shuai Xue , Jing Zhang Cc: Will Deacon , Mark Rutland , Yicong Yang , Baolin Wang , Jonathan Cameron , linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Zhanpeng Zhang Subject: [PATCH v2 2/2] perf/dwc_pcie: Skip sibling walks for new group leaders Date: Wed, 12 Aug 2026 00:07:20 +0800 Message-ID: <20260811160720.28580-1-zhangzhanpeng.jasper@bytedance.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260811131714.12779-1-zhangzhanpeng.jasper@bytedance.com> References: <20260811131714.12779-1-zhangzhanpeng.jasper@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" for_each_sibling_event() requires the event context lock to be held. perf_try_init_event() only takes that lock when initializing a group member. The DWC PCIe PMU walks the sibling list twice for every event, including a new group leader whose event_init() method runs without the lock. Although the leader cannot have siblings yet, the lock assertion is evaluated before the empty list is walked and produces two lockdep warnings. Skip both sibling walks while initializing a group leader. Group member validation is unchanged and continues to run with the event context mutex held. Fixes: af9597adc2f1 ("drivers/perf: add DesignWare PCIe PMU driver") Signed-off-by: Zhanpeng Zhang Reviewed-by: Yicong Yang --- A system-wide DWC PCIe PMU perf stat completed successfully with the same debug configuration, without lockdep reports or kernel taint. drivers/perf/dwc_pcie_pmu.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/perf/dwc_pcie_pmu.c b/drivers/perf/dwc_pcie_pmu.c index 7b2e28aade73..a6667ac19a99 100644 --- a/drivers/perf/dwc_pcie_pmu.c +++ b/drivers/perf/dwc_pcie_pmu.c @@ -417,6 +417,10 @@ static int dwc_pcie_pmu_validate_group(struct perf_eve= nt *event) if (dwc_pcie_pmu_validate_add_lane_event(leader, val_lane_events)) return -ENOSPC; =20 + /* A new group leader cannot have any siblings yet. */ + if (event =3D=3D leader) + return 0; + for_each_sibling_event(sibling, leader) { type =3D DWC_PCIE_EVENT_TYPE(sibling); if (type =3D=3D DWC_PCIE_TIME_BASE_EVENT) { @@ -452,9 +456,11 @@ static int dwc_pcie_pmu_event_init(struct perf_event *= event) if (event->cpu < 0 || event->attach_state & PERF_ATTACH_TASK) return -EINVAL; =20 - for_each_sibling_event(sibling, event->group_leader) { - if (sibling->pmu !=3D event->pmu && !is_software_event(sibling)) - return -EINVAL; + if (event !=3D event->group_leader) { + for_each_sibling_event(sibling, event->group_leader) { + if (sibling->pmu !=3D event->pmu && !is_software_event(sibling)) + return -EINVAL; + } } =20 if (type < 0 || type >=3D DWC_PCIE_EVENT_TYPE_MAX) --=20 2.50.1 (Apple Git-155)