PCI/TPH: Expose CPU-to-Steering Tag mappings via debugfs
Subsystems (2)
cover PCI/TPH: Expose CPU-to-Steering Tag mappings via debugfs
Add reusable per-device PCI debugfs directories and use them to expose the firmware-provided CPU-to-Steering Tag mapping for each Root Port. Factor the ACPI _DSM query path for reuse and document the new read-only interface.
Wei Huang (3):
PCI/TPH: Factor out the ST _DSM evaluation
PCI: Add per-device debugfs directories
Expose the CPU/Steering Tag mapping via debugfs
Documentation/PCI/tph.rst | 32 ++++++ drivers/pci/Makefile | 1 + drivers/pci/debugfs.c | 60 ++++++++++++ drivers/pci/pci.h | 12 +++ drivers/pci/remove.c | 1 + drivers/pci/tph.c | 201 ++++++++++++++++++++++++++++++++++---- include/linux/pci.h | 3 + 7 files changed, 290 insertions(+), 20 deletions(-) create mode 100644 drivers/pci/debugfs.c
Signature · 1 line
2.55.0
RFC PATCH 1/3 PCI/TPH: Factor out the ST _DSM evaluation
The ACPI _DSM that returns the CPU to Steering Tag (ST) mapping is evaluated in one place today, with the lookup of the ACPI device providing it open coded in pcie_tph_get_cpu_st().
Factor the handle lookup and the per-CPU query into tph_dsm_handle() and tph_get_cpu_st_info() so other callers can reuse them, name the _DSM revision instead of repeating the bare number, and constify the ST info passed to tph_extract_tag().
No functional change introduced.
--- drivers/pci/tph.c | 65 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 20 deletions(-)
drivers/pci/tph.c +45 -20
@@ -18,6 +18,9 @@static bool pci_tph_disabled;#ifdef CONFIG_ACPI +#define TPH_ST_DSM_REV 7 +#define TPH_ST_DSM_FUNC_INDEX 0xF +/* * The st_info struct defines the Steering Tag (ST) info returned by the * firmware PCI ACPI _DSM method (rev=0x7, func=0xF, "_DSM to Query Cache
@@ -54,7 +57,7 @@ union st_info { };static u16 tph_extract_tag (enum tph_mem_type mem_type,u8 req_type, -union st_info *info) +const union st_info *info) {switch (req_type) {case PCI_TPH_REQ_TPH_ONLY :/* 8-bit tag */
@@ -88,13 +91,12 @@ static u16 tph_extract_tag(enum tph_mem_type mem_type, u8 req_type,return 0 ; } -#define TPH_ST_DSM_FUNC_INDEX 0xFstatic acpi_status tph_invoke_dsm (acpi_handle handle,u32 cpu_uid,union st_info *st_out) {union acpi_object arg3[3 ], in_obj, *out_obj; -if (!acpi_check_dsm (handle, &pci_acpi_dsm_guid,7 , +if (!acpi_check_dsm (handle, &pci_acpi_dsm_guid,TPH_ST_DSM_REV ,BIT (TPH_ST_DSM_FUNC_INDEX )))return AE_ERROR ;
@@ -114,7 +116,7 @@ static acpi_status tph_invoke_dsm(acpi_handle handle, u32 cpu_uid, in_obj.package.count =ARRAY_SIZE (arg3); in_obj.package.elements = arg3; - out_obj =acpi_evaluate_dsm (handle, &pci_acpi_dsm_guid,7 , + out_obj =acpi_evaluate_dsm (handle, &pci_acpi_dsm_guid,TPH_ST_DSM_REV ,TPH_ST_DSM_FUNC_INDEX , &in_obj);if (!out_obj)return AE_ERROR ;
@@ -130,6 +132,43 @@ static acpi_status tph_invoke_dsm(acpi_handle handle, u32 cpu_uid, return AE_OK; } + +/* +* The ST _DSM is provided by the ACPI device of the Root Port's host bridge, +* so all Root Ports below the same host bridge share one ST mapping. +*/ +static acpi_handle tph_dsm_handle (struct pci_dev *pdev) +{ +struct pci_dev *rp; + + rp =pcie_find_root_port (pdev); +if (!rp || !rp->bus || !rp->bus->bridge) +return NULL ; + +return ACPI_HANDLE (rp->bus->bridge); +} + +/* Query the firmware for the ST info of @cpu - Return 0 if OK, else -errno */ +static int tph_get_cpu_st_info (struct pci_dev *pdev,unsigned int cpu, +union st_info *info) +{ +acpi_handle handle; +u32 cpu_uid; +int ret; + + handle =tph_dsm_handle (pdev); +if (!handle) +return -ENODEV ; + + ret =acpi_get_cpu_uid (cpu, &cpu_uid); +if (ret) +return ret; + +if (tph_invoke_dsm (handle, cpu_uid, info) !=AE_OK ) +return -EINVAL ; + +return 0 ; +}#endif /* Update the TPH Requester Enable field of TPH Control Register */
@@ -247,27 +286,13 @@ int pcie_tph_get_cpu_st(struct pci_dev *pdev, enum tph_mem_type mem_type, unsigned int cpu, u16 *tag) { #ifdef CONFIG_ACPI - struct pci_dev *rp; -acpi_handle rp_acpi_handle; union st_info info; -u32 cpu_uid;int ret; - ret =acpi_get_cpu_uid (cpu, &cpu_uid); -if (ret !=0 ) + ret =tph_get_cpu_st_info (pdev, cpu, &info); +if (ret)return ret; - rp =pcie_find_root_port (pdev); -if (!rp || !rp->bus || !rp->bus->bridge) -return -ENODEV ; - - rp_acpi_handle =ACPI_HANDLE (rp->bus->bridge); - -if (tph_invoke_dsm (rp_acpi_handle, cpu_uid, &info) !=AE_OK ) { - *tag =0 ; -return -EINVAL ; - } - *tag =tph_extract_tag (mem_type, pdev->tph_req_type, &info); pci_dbg(pdev, "get steering tag: mem_type=%s, cpu=%d, tag=%#04x\n",
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH RFC 1/3] PCI/TPH: Factor out the ST _DSM evaluation
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 4 lines
The ACPI
_DSMthat returns the CPU to Steering Tag (ST) mapping is evaluated in one place today, with the lookup of the ACPI device providing it open coded inpcie_tph_get_cpu_st().
Quoted 8 lines
Factor the handle lookup and the per-CPU query into
tph_dsm_handle()andtph_get_cpu_st_info()so other callers can reuse them, name the_DSMrevision instead of repeating the bare number, and constify the ST info passed totph_extract_tag().No functional change introduced.
Signed-off-by Wei Huang <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH RFC 1/3] PCI/TPH: Factor out the ST _DSM evaluation
In reply to Wei HuangQuoted 12 lines · Wei Huang
The ACPI
_DSMthat returns the CPU to Steering Tag (ST) mapping is evaluated in one place today, with the lookup of the ACPI device providing it open coded inpcie_tph_get_cpu_st().Factor the handle lookup and the per-CPU query into
tph_dsm_handle()andtph_get_cpu_st_info()so other callers can reuse them, name the_DSMrevision instead of repeating the bare number, and constify the ST info passed totph_extract_tag().No functional change introduced.
Signed-off-by Wei Huang <[email protected]>
RFC PATCH 2/3 PCI: Add per-device debugfs directories
In reply to Wei HuangPCI features that export debug information have no common place to put it. The only existing user, PTM, creates a "pcie_ptm_<device>" directory in the debugfs root, which does not scale as more features follow and leaves each user to invent its own lifetime rules and leaf names.
Add /sys/kernel/debug/pci/<device>/ directories owned by the PCI core. pci_dev_debugfs_dir() returns the directory of a device, creating it and the PCI root directory on first use, so devices without debug content do not get an empty directory. pci_destroy_dev() removes the directory recursively, so a feature that pins data in a debugfs file needs no removal hook of its own: debugfs_remove_recursive() returns only once no operation on those files is still running.
No functional change for existing users; the next patch is the first consumer.
--- drivers/pci/Makefile | 1 + drivers/pci/debugfs.c | 60 +++++++++++++++++++++++++++++++++++++++++++ drivers/pci/pci.h | 12 +++++++++ drivers/pci/remove.c | 1 + include/linux/pci.h | 3 +++ 5 files changed, 77 insertions(+) create mode 100644 drivers/pci/debugfs.c
drivers/pci/Makefile +1 -0
@@ -15,6 +15,7 @@ ifdef CONFIG_PCI obj-$(CONFIG_PROC_FS) += proc.o obj-$(CONFIG_SYSFS) += pci-sysfs.o slot.o obj-$(CONFIG_ACPI) += pci-acpi.o +obj-$(CONFIG_DEBUG_FS) += debugfs.o obj-$(CONFIG_GENERIC_PCI_IOMAP) += iomap.o endif
drivers/pci/debugfs.c new file +60 -0
60 lines not on this page · raw message
drivers/pci/pci.h +12 -0
@@ -1059,6 +1059,18 @@ static inline int pci_resource_num_to_vf_bar(int resno) }#endif /* CONFIG_PCI_IOV */ +#ifdef CONFIG_DEBUG_FS +struct dentry *pci_dev_debugfs_dir (struct pci_dev *dev); +void pci_dev_debugfs_remove (struct pci_dev *dev); +#else +static inline struct dentry *pci_dev_debugfs_dir (struct pci_dev *dev) +{ +return ERR_PTR (-ENODEV ); +} + +static inline void pci_dev_debugfs_remove (struct pci_dev *dev) { } +#endif +#ifdef CONFIG_PCIE_TPH void pci_restore_tph_state (struct pci_dev *dev);void pci_save_tph_state (struct pci_dev *dev);
drivers/pci/remove.c +1 -0
@@ -37,6 +37,7 @@ static void pci_destroy_dev(struct pci_dev *dev)platform_pci_remove_wake (dev);pci_doe_sysfs_teardown (dev);pci_npem_remove (dev); +pci_dev_debugfs_remove (dev);/* * While device is in D0 drop the device from TSM link operations
include/linux/pci.h +3 -0
@@ -580,6 +580,9 @@ struct pci_dev {#endif #ifdef CONFIG_PCI_TSM struct pci_tsm *tsm;/* TSM operation state */ +#endif +#ifdef CONFIG_DEBUG_FS +struct dentry *debugfs;/* debugfs directory, if any */ #endif u16 acs_cap;/* ACS Capability offset */ u16 acs_capabilities;/* ACS Capabilities */
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH RFC 2/3] PCI: Add per-device debugfs directories
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] PCI: system-wide stall during hotplug due to global pci_debugfs_lock held over debugfs removal…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] PCI: system-wide stall during hotplug due to global pci_debugfs_lock held over debugfs removal
- [Medium] PCI: speculative resource leak due to unpoisoned debugfs pointer on teardown --
commit 64859f6a500632327edcd41b730592212c9d3478
Author: Wei Huang <[email protected]>
PCI: Add per-device debugfs directories
This commit adds per-device debugfs directories owned by the PCI core, using pci_dev_debugfs_dir() to create them on demand and pci_destroy_dev() to recursively remove them.
Quoted 5 lines
drivers/pci/debugfs.c new file +0
-0
[ ... ]
drivers/pci/debugfs.c line 58
Quoted 5 lines
drivers/pci/debugfs.c new file +5
-0+void pci_dev_debugfs_remove (struct pci_dev *dev) +{ +guard (mutex)(&pci_debugfs_lock); + +debugfs_remove_recursive (dev->debugfs);
[Severity: High]
Does holding the global pci_debugfs_lock during debugfs_remove_recursive() risk a system-wide stall?
If a userspace process is actively reading a debugfs file, the removal will block for SRCU synchronization. Because the global lock is held via guard(mutex) for the entire function scope, any concurrent pci_dev_debugfs_dir() or pci_dev_debugfs_remove() calls on unrelated PCI devices will then block indefinitely during hotplug and removal operations.
Could the dentry be extracted under the lock and removed outside of it?
drivers/pci/debugfs.c line 59
Quoted 1 line
drivers/pci/debugfs.c new file +1
-0+ dev->debugfs =NULL ;
[Severity: Medium]
Can a concurrent runtime sysfs operation mistakenly recreate this debugfs directory after removal?
This sets the pointer to NULL while the device is still exposed to the system. As seen in pci_destroy_dev(), pci_dev_debugfs_remove() is called prior to device_del(). If a concurrent operation calls pci_dev_debugfs_dir() and sees NULL, it might recreate the directory and permanently leak it after the device is finally deleted.
Should the pointer be explicitly poisoned with ERR_PTR(-ENODEV) instead of set to NULL to prevent recreation?
Quoted 6 lines
drivers/pci/debugfs.c new file +1
-0+}drivers/pci/remove.c +0
-0
[ ... ]
Quoted 13 lines
drivers/pci/remove.c +1
-0@@ -37,6 +37,7 @@ static void pci_destroy_dev(struct pci_dev *dev)platform_pci_remove_wake (dev);pci_doe_sysfs_teardown (dev);pci_npem_remove (dev); +pci_dev_debugfs_remove (dev);/* * While device is in D0 drop the device from TSM link operations drivers/pci/remove.c +0
-0* including unbind and disconnect (IDE + SPDM teardown). */ pci_tsm_destroy (dev);device_del (&dev->dev);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH RFC 2/3] PCI: Add per-device debugfs directories
In reply to Wei HuangQuoted 17 lines · Wei Huang
PCI features that export debug information have no common place to put it. The only existing user, PTM, creates a "pcie_ptm_<device>" directory in the debugfs root, which does not scale as more features follow and leaves each user to invent its own lifetime rules and leaf names.
Add /sys/kernel/debug/pci/<device>/ directories owned by the PCI core.
pci_dev_debugfs_dir()returns the directory of a device, creating it and the PCI root directory on first use, so devices without debug content do not get an empty directory.pci_destroy_dev()removes the directory recursively, so a feature that pins data in a debugfs file needs no removal hook of its own:debugfs_remove_recursive()returns only once no operation on those files is still running.No functional change for existing users; the next patch is the first consumer.
Signed-off-by Wei Huang <[email protected]>
RFC PATCH 3/3 Expose the CPU/Steering Tag mapping via debugfs
In reply to Wei HuangSteering Tags (ST) are opaque, platform specific values obtained from the ACPI ST _DSM, and are only visible to the driver that asks for them. That makes it hard to validate whether firmware reports a sane mapping at all.
Expose the mapping read-only in the debugfs directory of each Root Port that has ST _DSM support:
# cat /sys/kernel/debug/pci/0000:00:01.1/tph_cpu_st cpu vm_st vm_xst vm_ph_ignore pm_st pm_xst pm_ph_ignore 0 0x03 0x0103 0 - - 0 1 0x03 0x0103 0 - - 0
Each line holds the raw ST info the _DSM returns for one online CPU; invalid tags and failed queries are reported as "-".
The interface is per Root Port because the _DSM is evaluated on the ACPI device of the host bridge above it. A system with multiple host bridges may return different tags for the same CPU, and the value that matters to a driver is the one for the Root Port its device sits below. Root Ports below the same host bridge report identical contents.
The file is created during enumeration and removed with the device's debugfs directory in pci_destroy_dev(), which returns only once no read is running, so the pci_dev the file refers to stays valid.
--- Documentation/PCI/tph.rst | 32 +++++++++ drivers/pci/tph.c | 136 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 168 insertions(+)
Documentation/PCI/tph.rst +32 -0
@@ -125,6 +125,38 @@ been changed. Here is a sample code for IRQ affinity notifier: return; } +Inspect the firmware ST mapping +------------------------------- + +When firmware provides the ST _DSM, the CPU to ST mapping it returns is +exposed read-only under debugfs, in the directory of each Root Port:: + + /sys/kernel/debug/pci/<domain:bus:device.function>/tph_cpu_st + +Each file holds one line per online CPU:: + + # cat /sys/kernel/debug/pci/0000:00:01.1/tph_cpu_st + cpu vm_st vm_xst vm_ph_ignore pm_st pm_xst pm_ph_ignore + 0 0x03 0x0103 0 - - 0 + 1 0x03 0x0103 0 - - 0 + +``vm_*`` and ``pm_*`` refer to volatile and persistent memory, ``*_st`` and +``*_xst`` are the 8-bit and 16-bit (extended) Steering Tags, and +``*_ph_ignore`` reports whether the Processing Hint is ignored by the +platform. Steering Tags that firmware marks as invalid, and CPUs whose +query fails, are shown as ``-``. + +The _DSM is evaluated on the ACPI device of the host bridge above the Root +Port, so all Root Ports below the same host bridge report the same mapping. +The file is per Root Port because that is the granularity drivers see: the +mapping that applies to a device is the one in the directory of the Root +Port the device sits below. + +Tags are queried on read rather than cached, so the output always matches +what pcie_tph_get_cpu_st() would return at that moment. The list of CPUs +is a snapshot; CPUs that come or go while the file is being read may be +missing from the output. + Disable TPH system-wide -----------------------
drivers/pci/tph.c +136 -0
159 lines not on this page · raw message
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH RFC 3/3] Expose the CPU/Steering Tag mapping via debugfs
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 21 lines
Steering Tags (ST) are opaque, platform specific values obtained from the ACPI ST
_DSM, and are only visible to the driver that asks for them. That makes it hard to validate whether firmware reports a sane mapping at all.Expose the mapping read-only in the debugfs directory of each Root Port that has ST
_DSMsupport:# cat /sys/kernel/debug/pci/0000:00:01.1/tph_cpu_st cpu vm_st vm_xst vm_ph_ignore pm_st pm_xst pm_ph_ignore 0 0x03 0x0103 0 - - 0 1 0x03 0x0103 0 - - 0Each line holds the raw ST info the
_DSMreturns for one online CPU; invalid tags and failed queries are reported as "-".The interface is per Root Port because the
_DSMis evaluated on the ACPI device of the host bridge above it. A system with multiple host bridges may return different tags for the same CPU, and the value that matters to a driver is the one for the Root Port its device sits below. Root Ports below the same host bridge report identical contents.
Quoted 5 lines
The file is created during enumeration and removed with the device's debugfs directory in
pci_destroy_dev(), which returns only once no read is running, so thepci_devthe file refers to stays valid.Signed-off-by Wei Huang <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH RFC 3/3] Expose the CPU/Steering Tag mapping via debugfs
In reply to Wei HuangHi Wei,
1. Should we consider cpu hotplug ? How about add cpus_read_lock() in start() and release it in stop()
2. Does this support RCiEP device?
Other LGTM
Thanks,
Chengwen
Quoted 26 lines · Wei Huang
Steering Tags (ST) are opaque, platform specific values obtained from the ACPI ST
_DSM, and are only visible to the driver that asks for them. That makes it hard to validate whether firmware reports a sane mapping at all.Expose the mapping read-only in the debugfs directory of each Root Port that has ST
_DSMsupport:# cat /sys/kernel/debug/pci/0000:00:01.1/tph_cpu_st cpu vm_st vm_xst vm_ph_ignore pm_st pm_xst pm_ph_ignore 0 0x03 0x0103 0 - - 0 1 0x03 0x0103 0 - - 0Each line holds the raw ST info the
_DSMreturns for one online CPU; invalid tags and failed queries are reported as "-".The interface is per Root Port because the
_DSMis evaluated on the ACPI device of the host bridge above it. A system with multiple host bridges may return different tags for the same CPU, and the value that matters to a driver is the one for the Root Port its device sits below. Root Ports below the same host bridge report identical contents.The file is created during enumeration and removed with the device's debugfs directory in
pci_destroy_dev(), which returns only once no read is running, so thepci_devthe file refers to stays valid.Signed-off-by Wei Huang <[email protected]>
Hi Bjorn,
Gentle ping on this patch series. Do you have any feedback, or would you be comfortable to add this support into PCI TPH?
Thanks,
-Wei
Quoted 23 lines · Wei Huang
Add reusable per-device PCI debugfs directories and use them to expose the firmware-provided CPU-to-Steering Tag mapping for each Root Port. Factor the ACPI
_DSMquery path for reuse and document the new read-only interface.Wei Huang (3):
PCI/TPH: Factor out the ST_DSMevaluation
PCI: Add per-device debugfs directories
Expose the CPU/Steering Tag mapping via debugfsDocumentation/PCI/tph.rst | 32 ++++++ drivers/pci/Makefile | 1 + drivers/pci/debugfs.c | 60 ++++++++++++ drivers/pci/pci.h | 12 +++ drivers/pci/remove.c | 1 + drivers/pci/tph.c | 201 ++++++++++++++++++++++++++++++++++---- include/linux/pci.h | 3 + 7 files changed, 290 insertions(+), 20 deletions(-) create mode 100644 drivers/pci/debugfs.cSignature · 1 line
2.55.0