Skip to contentSkip to conversation

perf/arm_cspmu: nvidia: handle empty resource list in PCIE-TGT init

PATCH In review Saurav Sachidanand 3 participants 5 messages May 11 – Jun 1

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 2/3 perf/arm_cspmu: nvidia: handle empty resource list in PCIE-TGT init

When acpi_dev_get_memory_resources() returns success but the resource list is empty (rentry is NULL), addr_filter_reg remains NULL from devm_kzalloc. Since IS_ERR(NULL) is false, the function proceeds without error and later dereferences the NULL pointer in pcie_tgt_pmu_config_addr_filter().

Set addr_filter_reg to ERR_PTR(-ENODEV) when the resource list is empty so the existing IS_ERR check catches it.

Fixes 3dd73022306b ("perf/arm_cspmu: nvidia: Add Tegra410 PCIE-TGT PMU")
---
 drivers/perf/arm_cspmu/nvidia_cspmu.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/perf/arm_cspmu/nvidia_cspmu.c +5 -3
index bac83e424d6dc..bae722e263e91 100644
@@ -555,14 +555,16 @@ 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)
 		data->addr_filter_reg = devm_ioremap_resource(dev, rentry->res);
-		ret = 0;
-	}
+	else
+		data->addr_filter_reg = ERR_PTR(-ENODEV);
 
 	if (IS_ERR(data->addr_filter_reg)) {
 		dev_err(dev, "failed to get address filter resource\n");
 		ret = PTR_ERR(data->addr_filter_reg);
+	} else {
+		ret = 0;
 	}
 
 	acpi_dev_free_resource_list(&resource_list);
Signature · 1 line
2.47.3
#1 lore raw

PATCH 3/3 perf/arm_cspmu: nvidia: fix BDF calculation examples in PCIE PMU docs

The BDF hex values in the documentation examples are inconsistent with the stated formula (bus << 8) + (device << 3) + (function):

- BDF 27:01.1: documented as 0x2781, correct value is 0x2709

    (0x27 << 8) + (0x01 << 3) + 0x1 = 0x2709
  - BDF 01:01.0: documented as 0x0180, correct value is 0x0108
    (0x01 << 8) + (0x01 << 3) + 0x0 = 0x0108

It appears (device << 7) was used instead of (device << 3) when computing the example values.

Fixes bf585ba14726 ("perf/arm_cspmu: nvidia: Add Tegra410 PCIE PMU")
---
 Documentation/admin-guide/perf/nvidia-tegra410-pmu.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/admin-guide/perf/nvidia-tegra410-pmu.rst +2 -2
index 0656223b61d47..24f0e801d7b80 100644
@@ -170,7 +170,7 @@ The list of event filters:
     devices in root port 0 to 3.
   * src_bdf: the BDF that will be monitored. This is a 16-bit value that
     follows formula: (bus << 8) + (device << 3) + (function). For example, the
-    value of BDF 27:01.1 is 0x2781.
+    value of BDF 27:01.1 is 0x2709.
   * src_bdf_en: enable the BDF filter. If this is set, the BDF filter value in
     "src_bdf" is used to filter the traffic.
 
@@ -215,7 +215,7 @@ Example usage:
 * Count event id 0x4 from BDF 01:01.0 of PCIE RC-4 on socket 0 targeting all
   destinations::
 
-    perf stat -a -e nvidia_pcie_pmu_0_rc_4/event=0x4,src_bdf=0x0180,src_bdf_en=0x1/
+    perf stat -a -e nvidia_pcie_pmu_0_rc_4/event=0x4,src_bdf=0x0108,src_bdf_en=0x1/
 
 .. _NVIDIA_T410_PCIE_PMU_RC_Mapping_Section:
 
Signature · 1 line
2.47.3
Reviewed-by on v1 3/3
#2 lore raw

RE: [PATCH 3/3] perf/arm_cspmu: nvidia: fix BDF calculation examples in PCIE PMU docs

Quoted 26 lines

-----Original Message-----
From: Saurav Sachidanand <[email protected]>
Sent: Monday, May 11, 2026 4:09 PM
To: Will Deacon <[email protected]>
Cc: Mark Rutland <[email protected]>; Besar Wicaksono <[email protected]>; Ilkka Koskinen <[email protected]>; Jon Hunter <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; Saurav Sachidanand <[email protected]>
Subject: [PATCH 3/3] perf/arm_cspmu: nvidia: fix BDF calculation examples in PCIE PMU docs

External email: Use caution opening links or attachments

The BDF hex values in the documentation examples are inconsistent with the stated formula (bus << 8) + (device << 3) + (function):

- BDF 27:01.1: documented as 0x2781, correct value is 0x2709

    (0x27 << 8) + (0x01 << 3) + 0x1 = 0x2709
  - BDF 01:01.0: documented as 0x0180, correct value is 0x0108
    (0x01 << 8) + (0x01 << 3) + 0x0 = 0x0108
Quoted 5 lines

It appears (device << 7) was used instead of (device << 3) when computing the example values.

Fixes bf585ba14726 ("perf/arm_cspmu: nvidia: Add Tegra410 PCIE PMU")

Thanks for the fix.

Quoted 31 lines
---
 Documentation/admin-guide/perf/nvidia-tegra410-pmu.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/admin-guide/perf/nvidia-tegra410-pmu.rst +1 -2
index 0656223b61d47..24f0e801d7b80 100644
@@ -170,7 +170,7 @@ The list of event filters:
     devices in root port 0 to 3.
   * src_bdf: the BDF that will be monitored. This is a 16-bit value that
     follows formula: (bus << 8) + (device << 3) + (function). For example, the
-    value of BDF 27:01.1 is 0x2781.
+    value of BDF 27:01.1 is 0x2709.
   * src_bdf_en: enable the BDF filter. If this is set, the BDF filter value in
     "src_bdf" is used to filter the traffic.
 
@@ -215,7 +215,7 @@ Example usage:
 * Count event id 0x4 from BDF 01:01.0 of PCIE RC-4 on socket 0 targeting all
   destinations::
 
-    perf stat -a -e

nvidia_pcie_pmu_0_rc_4/event=0x4,src_bdf=0x0180,src_bdf_en=0x1/
+ perf stat -a -e
nvidia_pcie_pmu_0_rc_4/event=0x4,src_bdf=0x0108,src_bdf_en=0x1/

.. _NVIDIA_T410_PCIE_PMU_RC_Mapping_Section:

--
2.47.3

Reviewed-by on v1 2/3
#3 lore raw
In reply to Saurav Sachidanand
Quoted 46 lines

-----Original Message-----
From: Saurav Sachidanand <[email protected]>
Sent: Monday, May 11, 2026 4:09 PM
To: Will Deacon <[email protected]>
Cc: Mark Rutland <[email protected]>; Besar Wicaksono <[email protected]>; Ilkka Koskinen <[email protected]>; Jon Hunter <[email protected]>; [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; Saurav Sachidanand <[email protected]>
Subject: [PATCH 2/3] perf/arm_cspmu: nvidia: handle empty resource list in PCIE-TGT init

External email: Use caution opening links or attachments

When acpi_dev_get_memory_resources() returns success but the resource list is empty (rentry is NULL), addr_filter_reg remains NULL from devm_kzalloc. Since IS_ERR(NULL) is false, the function proceeds without error and later dereferences the NULL pointer in pcie_tgt_pmu_config_addr_filter().

Set addr_filter_reg to ERR_PTR(-ENODEV) when the resource list is empty so the existing IS_ERR check catches it.

Fixes 3dd73022306b ("perf/arm_cspmu: nvidia: Add Tegra410 PCIE-TGT

PMU")

---
 drivers/perf/arm_cspmu/nvidia_cspmu.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/perf/arm_cspmu/nvidia_cspmu.c +1 -1
index bac83e424d6dc..bae722e263e91 100644
@@ -555,14 +555,16 @@ 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)

drivers/perf/arm_cspmu/nvidia_cspmu.c static int pcie_tgt_init_data(struct arm_cspmu · line 567

Quoted 10 lines
drivers/perf/arm_cspmu/nvidia_cspmu.c +3 -2
                data->addr_filter_reg = devm_ioremap_resource(dev, rentry->res);
-               ret = 0;
-       }
+       else
+               data->addr_filter_reg = ERR_PTR(-ENODEV);
 
        if (IS_ERR(data->addr_filter_reg)) {
                dev_err(dev, "failed to get address filter resource\n");
                ret = PTR_ERR(data->addr_filter_reg);
+       } else {

Thanks for fixing.

Quoted 6 lines
drivers/perf/arm_cspmu/nvidia_cspmu.c +1 -0
+               ret = 0;
        }
 
        acpi_dev_free_resource_list(&resource_list);

--
2.47.3

maintainer
#4 lore raw
In reply to Saurav Sachidanand
Quoted 6 lines · Saurav Sachidanand

When acpi_dev_get_memory_resources() returns success but the resource list is empty (rentry is NULL), addr_filter_reg remains NULL from devm_kzalloc. Since IS_ERR(NULL) is false, the function proceeds without error and later dereferences the NULL pointer in pcie_tgt_pmu_config_addr_filter().

Quoted 8 lines

Set addr_filter_reg to ERR_PTR(-ENODEV) when the resource list is empty so the existing IS_ERR check catches it.

Fixes 3dd73022306b ("perf/arm_cspmu: nvidia: Add Tegra410 PCIE-TGT PMU")
---
 drivers/perf/arm_cspmu/nvidia_cspmu.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

What happened to patch 1/3? I don't have it in my inbox and it seems to be missing from the archive as well:

https://lore.kernel.org/all/[email protected]/

Please can you post a v2, with all three patches and the R-b tags from Besar?

Thanks,

Will