[Deepin-Kernel-SIG] [linux 6.6-y] [Upstream] [Alibaba] Backport bugfixes for Root Port PMU for Yitian710#839
Conversation
[ Upstream commit b94b054 ] When the PCIe devices are discovered late, the driver can't find the PCIe devices and returns in the init without registering with the bus notifier. Due to that the devices which are discovered late the driver can't register for this. Register for bus notifier & driver even if the device is not found as part of init. Fixes: af9597a ("drivers/perf: add DesignWare PCIe PMU driver") Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com> Reviewed-by: Yicong Yang <yangyicong@hisilicon.com> Link: https://lore.kernel.org/r/20240816-dwc_pmu_fix-v2-3-198b8ab1077c@quicinc.com Signed-off-by: Will Deacon <will@kernel.org> [ Backport from v6.11 ] Suggested-by: Wentao Guan <guanwentao@uniontech.com> Signed-off-by: WangYuli <wangyuli@uniontech.com>
[ Upstream commit e669388 ] When there are multiple of instances of PCIe controllers, registration to perf driver fails with this error. sysfs: cannot create duplicate filename '/devices/platform/dwc_pcie_pmu.0' CPU: 0 PID: 166 Comm: modprobe Not tainted 6.10.0-rc2-next-20240607-dirty Hardware name: Qualcomm SA8775P Ride (DT) Call trace: dump_backtrace.part.8+0x98/0xf0 show_stack+0x14/0x1c dump_stack_lvl+0x74/0x88 dump_stack+0x14/0x1c sysfs_warn_dup+0x60/0x78 sysfs_create_dir_ns+0xe8/0x100 kobject_add_internal+0x94/0x224 kobject_add+0xa8/0x118 device_add+0x298/0x7b4 platform_device_add+0x1a0/0x228 platform_device_register_full+0x11c/0x148 dwc_pcie_register_dev+0x74/0xf0 [dwc_pcie_pmu] dwc_pcie_pmu_init+0x7c/0x1000 [dwc_pcie_pmu] do_one_initcall+0x58/0x1c0 do_init_module+0x58/0x208 load_module+0x1804/0x188c __do_sys_init_module+0x18c/0x1f0 __arm64_sys_init_module+0x14/0x1c invoke_syscall+0x40/0xf8 el0_svc_common.constprop.1+0x70/0xf4 do_el0_svc+0x18/0x20 el0_svc+0x28/0xb0 el0t_64_sync_handler+0x9c/0xc0 el0t_64_sync+0x160/0x164 kobject: kobject_add_internal failed for dwc_pcie_pmu.0 with -EEXIST, don't try to register things with the same name in the same directory. This is because of having same bdf value for devices under two different controllers. Update the logic to use sbdf which is a unique number in case of multi instance also. Fixes: af9597a ("drivers/perf: add DesignWare PCIe PMU driver") Signed-off-by: Krishna chaitanya chundru <quic_krichai@quicinc.com> Reviewed-by: Yicong Yang <yangyicong@hisilicon.com> Link: https://lore.kernel.org/r/20240816-dwc_pmu_fix-v2-1-198b8ab1077c@quicinc.com Signed-off-by: Will Deacon <will@kernel.org> [ Backport from v6.11 ] Suggested-by: Wentao Guan <guanwentao@uniontech.com> Signed-off-by: WangYuli <wangyuli@uniontech.com>
Reviewer's GuideThis backport adjusts the PCI identifier logic to use a 32-bit SBDF (including domain) instead of the legacy 16-bit BDF throughout the driver, and cleans up a dead initialization code path. Sequence Diagram: PCI Device Registration with SBDFsequenceDiagram
participant init as dwc_pcie_pmu_init
participant reg_dev as dwc_pcie_register_dev
participant pdev_obj as "pci_dev (data)"
participant plat_reg as platform_device_register_data
init->>reg_dev: Call dwc_pcie_register_dev(pdev)
activate reg_dev
reg_dev->>pdev_obj: Read bus->number, devfn
reg_dev->>pdev_obj: Read pci_domain_nr(pdev->bus)
reg_dev-->>reg_dev: Calculate sbdf = (domain << 16) | PCI_DEVID(bus_num, devfn)
reg_dev->>plat_reg: platform_device_register_data(NULL, "dwc_pcie_pmu", sbdf, pdev, sizeof(*pdev))
activate plat_reg
plat_reg-->>reg_dev: Return plat_dev or ERR_PTR
deactivate plat_reg
reg_dev-->>init: Return status
deactivate reg_dev
Sequence Diagram: PMU Probe using SBDFsequenceDiagram
participant plat_core as Platform Core
participant pmu_probe as dwc_pcie_pmu_probe
participant plat_dev_obj as "platform_device (data)"
participant kasprintf as devm_kasprintf
participant perf_reg as perf_pmu_register
plat_core->>pmu_probe: Call dwc_pcie_pmu_probe(plat_dev)
activate pmu_probe
pmu_probe->>plat_dev_obj: Get pci_dev from plat_dev->dev.platform_data
pmu_probe->>plat_dev_obj: Get sbdf from plat_dev->id
pmu_probe-->>pmu_probe: Use sbdf for operations
pmu_probe->>kasprintf: devm_kasprintf(&plat_dev->dev, GFP_KERNEL, "dwc_rootport_%x", sbdf)
activate kasprintf
kasprintf-->>pmu_probe: Return name
deactivate kasprintf
pmu_probe->>perf_reg: perf_pmu_register(&pcie_pmu->pmu, name, -1)
activate perf_reg
alt Registration Succeeded
perf_reg-->>pmu_probe: Return 0
else Registration Failed
perf_reg-->>pmu_probe: Return error_code (ret)
pmu_probe-->>pmu_probe: Log error: pci_err(pdev, "Error %d registering PMU @%x", ret, sbdf)
end
deactivate perf_reg
pmu_probe-->>plat_core: Return status
deactivate pmu_probe
Class Diagram: Changes in dwc_pcie_pmu.c FunctionsclassDiagram
class `dwc_pcie_register_dev()` {
<<C Function in dwc_pcie_pmu.c>>
+ Calculates `sbdf` (32-bit Segment/Bus/Device/Function ID)
+ sbdf = (pci_domain_nr(pdev->bus) << 16) | PCI_DEVID(pdev->bus->number, pdev->devfn)
+ Calls `platform_device_register_data()` with `sbdf`
- Replaces logic using 16-bit `bdf`
}
class `dwc_pcie_pmu_probe()` {
<<C Function in dwc_pcie_pmu.c>>
+ Retrieves `sbdf` from `plat_dev->id`
+ Uses `sbdf` for device naming: `devm_kasprintf(..., "dwc_rootport_%x", sbdf)`
+ Uses `sbdf` in error logging: `pci_err(..., sbdf)`
- Replaces logic using 16-bit `bdf`
}
class `dwc_pcie_pmu_init()` {
<<C Function in dwc_pcie_pmu.c>>
- Removed `bool found` variable and related logic (dead code cleanup)
+ Iterates `for_each_pci_dev(pdev)`
+ Calls `dwc_pcie_register_dev(pdev)` in loop
}
`dwc_pcie_pmu_init()` --> `dwc_pcie_register_dev()` : calls
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
deepin pr auto review代码审查意见:
综上所述,代码的改进主要集中在变量命名、代码重复、错误处理、代码可读性、性能优化、错误信息和安全性方面。通过这些改进,可以提高代码的质量和可维护性。 |
There was a problem hiding this comment.
Pull Request Overview
This PR backports bugfixes for the Root Port PMU to include PCI domain information in the BDF and streamlines device initialization.
- Incorporate PCI domain into the BDF value passed to the platform device.
- Rename internal BDF variable to
sbdfand update related registration/print calls. - Remove the
foundflag and its-ENODEVcheck indwc_pcie_pmu_init.
Comments suppressed due to low confidence (3)
drivers/perf/dwc_pcie_pmu.c:559
- [nitpick] The name
sbdfis terse and may be unclear. Consider renaming to something more descriptive likesegment_bdfordomain_bdfto clarify that it includes the PCI domain.
u32 sbdf;
drivers/perf/dwc_pcie_pmu.c:561
- This new logic computing a segment-aware BDF should be covered by unit or integration tests (e.g., verifying correct encoding of domain, bus, device, and function) to prevent regressions.
sbdf = (pci_domain_nr(pdev->bus) << 16) | PCI_DEVID(pdev->bus->number, pdev->devfn);
drivers/perf/dwc_pcie_pmu.c:731
- Removing the
!foundcheck and its-ENODEVreturn means the CPHP state will be set up even if no matching PCI root port is found. Consider retaining a guard or adding a fallback to avoid registering hotplug callbacks with no target devices.
bool found = false;
|
|
||
| bdf = PCI_DEVID(pdev->bus->number, pdev->devfn); | ||
| plat_dev = platform_device_register_data(NULL, "dwc_pcie_pmu", bdf, | ||
| sbdf = (pci_domain_nr(pdev->bus) << 16) | PCI_DEVID(pdev->bus->number, pdev->devfn); |
There was a problem hiding this comment.
The shift by 16 is a magic number here. Introduce a named constant or helper macro (e.g., PCI_DOMAIN_SHIFT) to document its purpose and avoid repeated literals.
| sbdf = (pci_domain_nr(pdev->bus) << 16) | PCI_DEVID(pdev->bus->number, pdev->devfn); | |
| sbdf = (pci_domain_nr(pdev->bus) << PCI_DOMAIN_SHIFT) | PCI_DEVID(pdev->bus->number, pdev->devfn); |
There was a problem hiding this comment.
Hey @Avenger-285714 - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Fixes: #831
Suggested-by: Wentao Guan guanwentao@uniontech.com
Summary by Sourcery
Backport fixes for the root port PMU driver to correctly identify devices by full SBDF and simplify initialization logic.
Bug Fixes:
Enhancements: