perf/arm_cspmu: nvidia: Fix TGT address-filter handling
cover perf/arm_cspmu: nvidia: Fix TGT address-filter handling
The Tegra410 PCIE-TGT implementation has two independent issues in its address-filter handling.
First, an empty ACPI memory-resource list is accepted during probe, leaving addr_filter_reg as NULL and allowing a later filter event to perform an invalid MMIO access.
Second, the slot lookup can allocate a free slot before finding an identical active filter, reset can match zeroed metadata from a free slot, and cycle events can reset a slot they never allocated. These can cause wrong-slot release, refcount underflow, and loss of filtering for an active event.
This series rejects the missing resource at probe and fixes the slot lifecycle without changing the shared PMU callback ABI or rejecting valid zero base/mask filter data.
AI assistance disclosure:
Qoder AI coding assistant was used with the current upstream source and the identified defect sequences as inputs. It contributed to the problem analysis, code changes, state model, and changelog drafts. The human submitter is responsible for reviewing the complete series and adding their own Signed-off-by tags.
Validation:
- source-derived model reproduces wrong-slot release, zero base/mask underflow, and cycle/reset underflow before the fix;
- the proposed lifecycle model passes those cases and 100 x 500 random operations;
- independent static review covers duplicate filters, arbitrary stop order, zero base/mask, cycle, full slots, and reset-without-allocation;
- checkpatch.pl reports no issues other than the expected missing human Signed-off-by tags in this unsigned draft;
- complete ARM64 Image builds successfully;
- nvidia_cspmu.o and arm_cspmu.o build with W=1 without new warnings.
NOT_RUN:
- runtime fault injection or probe validation with abnormal ACPI tables;
- real address filtering, duplicate event start/stop, cycle/reset, slot exhaustion, module reload, or multi-RC testing;
- PCIe/CXL traffic, target hardware, existing Ampere/NVIDIA runtime regression, or long-duration testing.
Jiangtian Feng (2):
perf/arm_cspmu: nvidia: Reject missing TGT address-filter resource perf/arm_cspmu: nvidia: Fix TGT address-filter slot lifecycle
drivers/perf/arm_cspmu/nvidia_cspmu.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-)
Signature · 1 line
2.47.3
PATCH 1/2 perf/arm_cspmu: nvidia: Reject missing TGT address-filter resource
acpi_dev_get_memory_resources() can return 0 with an empty resource list. In that case pcie_tgt_init_data() leaves addr_filter_reg as NULL but returns success. A later address-filter event then writes to registers computed from that NULL base.
Reject an empty resource list with -ENODEV and keep the existing ioremap error propagation. This turns missing firmware resources into a probe failure instead of a runtime invalid MMIO access.
Qoder, an AI coding assistant, helped analyze the issue, develop the fix and source-derived state model, and draft this description.
--- drivers/perf/arm_cspmu/nvidia_cspmu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/perf/arm_cspmu/nvidia_cspmu.c +4 -1
@@ -555,7 +555,10 @@ static int pcie_tgt_init_data(struct arm_cspmu *cspmu) rentry =list_first_entry_or_null ( &resource_list, struct resource_entry, node); -if (rentry) { +if (!rentry) { +dev_err (dev,"no address filter resource\n" ); + ret = -ENODEV ; + }else { data->addr_filter_reg =devm_ioremap_resource (dev, rentry->res); ret =0 ; }
Signature · 1 line
2.47.3
PATCH 2/2 perf/arm_cspmu: nvidia: Fix TGT address-filter slot lifecycle
In reply to Jiangtian FengThe current lookup returns a free slot before checking later slots for an identical active filter. After another filter is stopped, a new event can therefore occupy a different slot from an existing identical filter. Reset then searches only by base/mask and can release the wrong slot.
Reset also matches zeroed metadata from free slots and decrements their refcount without checking occupancy. A zero base/mask filter can thus underflow a free slot's refcount when another filter is stopped first. Cycle events never allocate an address-filter slot, but their stop path can still call reset and release another event's filter.
First match an active filter so identical filters share one slot. Only allocation searches for a free slot afterward. Reset must match an active slot, and cycle events return without resetting an address filter. This keeps zero base/mask as valid filter data and does not change the shared PMU callback ABI.
Qoder, an AI coding assistant, helped analyze the issue, develop the fix and source-derived state model, and draft this description.
--- drivers/perf/arm_cspmu/nvidia_cspmu.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/perf/arm_cspmu/nvidia_cspmu.c +14 -4
@@ -589,7 +589,7 @@ static struct pcie_tgt_data *pcie_tgt_get_data(struct arm_cspmu *cspmu)return ctx->data; } -/* Find the first available address filter slot. */ +/* Find an active matching filter or a free slot for allocation. */ static int pcie_tgt_find_addr_idx (struct arm_cspmu *cspmu,u64 base,u64 mask,bool is_reset) {
@@ -597,11 +597,17 @@ static int pcie_tgt_find_addr_idx(struct arm_cspmu *cspmu, u64 base, u64 mask,struct pcie_tgt_data *data =pcie_tgt_get_data (cspmu);for (i =0 ; i <NV_PCIE_TGT_ADDR_COUNT ; i++) { -if (!is_reset && data->addr_filter[i].refcount ==0 ) +if (data->addr_filter[i].refcount >0 && + data->addr_filter[i].base == base && + data->addr_filter[i].mask == mask)return i; + } + +if (is_reset) +return -ENODEV ; -if (data->addr_filter[i].base == base && - data->addr_filter[i].mask == mask) +for (i =0 ; i <NV_PCIE_TGT_ADDR_COUNT ; i++) { +if (data->addr_filter[i].refcount ==0 )return i; }
@@ -748,6 +754,10 @@ static void pcie_tgt_pmu_reset_ev_filter(struct arm_cspmu *cspmu,u64 base, mask;int idx; +/* Cycle events never allocate an address-filter slot. */ +if (event->hw.extra_reg.idx == cspmu->cycle_counter_logical_idx) +return ; + addr_filter_en =pcie_tgt_pmu_addr_en (event);if (!addr_filter_en)return ;
Signature · 1 line
2.47.3
[email protected]
AI reviewSashiko has reviewed this 2-patch series and found no issues.
Sashiko has reviewed this 2-patch series and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]