Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] perf/arm_cspmu: nvidia: Fix TGT address-filter handling
@ 2026-11-27  7:10 Jiangtian Feng
  2026-11-27  7:10 ` [PATCH 1/2] perf/arm_cspmu: nvidia: Reject missing TGT address-filter resource Jiangtian Feng
  2026-11-27  7:10 ` [PATCH 2/2] perf/arm_cspmu: nvidia: Fix TGT address-filter slot lifecycle Jiangtian Feng
  0 siblings, 2 replies; 3+ messages in thread
From: Jiangtian Feng @ 2026-11-27  7:10 UTC (permalink / raw)
  To: Will Deacon, Mark Rutland, Besar Wicaksono
  Cc: Robin Murphy, linux-arm-kernel, linux-perf-users, linux-kernel,
	jiangtianfeng

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(-)

-- 
2.47.3



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] perf/arm_cspmu: nvidia: Reject missing TGT address-filter resource
  2026-11-27  7:10 [PATCH 0/2] perf/arm_cspmu: nvidia: Fix TGT address-filter handling Jiangtian Feng
@ 2026-11-27  7:10 ` Jiangtian Feng
  2026-11-27  7:10 ` [PATCH 2/2] perf/arm_cspmu: nvidia: Fix TGT address-filter slot lifecycle Jiangtian Feng
  1 sibling, 0 replies; 3+ messages in thread
From: Jiangtian Feng @ 2026-11-27  7:10 UTC (permalink / raw)
  To: Will Deacon, Mark Rutland, Besar Wicaksono
  Cc: Robin Murphy, linux-arm-kernel, linux-perf-users, linux-kernel,
	jiangtianfeng

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.

Fixes: 3dd73022306b ("perf/arm_cspmu: nvidia: Add Tegra410 PCIE-TGT PMU")
Signed-off-by: Jiangtian Feng <jiangtianfeng@linux.alibaba.com>
---
 drivers/perf/arm_cspmu/nvidia_cspmu.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/perf/arm_cspmu/nvidia_cspmu.c b/drivers/perf/arm_cspmu/nvidia_cspmu.c
index af256f662731..a0257dc3249d 100644
--- a/drivers/perf/arm_cspmu/nvidia_cspmu.c
+++ b/drivers/perf/arm_cspmu/nvidia_cspmu.c
@@ -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;
 	}
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] perf/arm_cspmu: nvidia: Fix TGT address-filter slot lifecycle
  2026-11-27  7:10 [PATCH 0/2] perf/arm_cspmu: nvidia: Fix TGT address-filter handling Jiangtian Feng
  2026-11-27  7:10 ` [PATCH 1/2] perf/arm_cspmu: nvidia: Reject missing TGT address-filter resource Jiangtian Feng
@ 2026-11-27  7:10 ` Jiangtian Feng
  1 sibling, 0 replies; 3+ messages in thread
From: Jiangtian Feng @ 2026-11-27  7:10 UTC (permalink / raw)
  To: Will Deacon, Mark Rutland, Besar Wicaksono
  Cc: Robin Murphy, linux-arm-kernel, linux-perf-users, linux-kernel,
	jiangtianfeng

The 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.

Fixes: 3dd73022306b ("perf/arm_cspmu: nvidia: Add Tegra410 PCIE-TGT PMU")
Signed-off-by: Jiangtian Feng <jiangtianfeng@linux.alibaba.com>
---
 drivers/perf/arm_cspmu/nvidia_cspmu.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/perf/arm_cspmu/nvidia_cspmu.c b/drivers/perf/arm_cspmu/nvidia_cspmu.c
index a0257dc3249d..1e9e52cbec09 100644
--- a/drivers/perf/arm_cspmu/nvidia_cspmu.c
+++ b/drivers/perf/arm_cspmu/nvidia_cspmu.c
@@ -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;
-- 
2.47.3



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-27  7:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27  7:10 [PATCH 0/2] perf/arm_cspmu: nvidia: Fix TGT address-filter handling Jiangtian Feng
2026-11-27  7:10 ` [PATCH 1/2] perf/arm_cspmu: nvidia: Reject missing TGT address-filter resource Jiangtian Feng
2026-11-27  7:10 ` [PATCH 2/2] perf/arm_cspmu: nvidia: Fix TGT address-filter slot lifecycle Jiangtian Feng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox