Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/3] perf/arm_cspmu: nvidia: handle empty resource list in PCIE-TGT init
@ 2026-05-11 21:09 Saurav Sachidanand
  2026-05-11 21:09 ` [PATCH 3/3] perf/arm_cspmu: nvidia: fix BDF calculation examples in PCIE PMU docs Saurav Sachidanand
  2026-05-11 22:09 ` [PATCH 2/3] perf/arm_cspmu: nvidia: handle empty resource list in PCIE-TGT init Besar Wicaksono
  0 siblings, 2 replies; 4+ messages in thread
From: Saurav Sachidanand @ 2026-05-11 21:09 UTC (permalink / raw)
  To: Will Deacon
  Cc: Mark Rutland, Besar Wicaksono, Ilkka Koskinen, Jonathan Hunter,
	linux-arm-kernel, linux-perf-users, linux-kernel, aghayev, juew,
	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().

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")
Signed-off-by: Saurav Sachidanand <sauravsc@amazon.com>
---
 drivers/perf/arm_cspmu/nvidia_cspmu.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

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



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

* [PATCH 3/3] perf/arm_cspmu: nvidia: fix BDF calculation examples in PCIE PMU docs
  2026-05-11 21:09 [PATCH 2/3] perf/arm_cspmu: nvidia: handle empty resource list in PCIE-TGT init Saurav Sachidanand
@ 2026-05-11 21:09 ` Saurav Sachidanand
  2026-05-11 21:48   ` Besar Wicaksono
  2026-05-11 22:09 ` [PATCH 2/3] perf/arm_cspmu: nvidia: handle empty resource list in PCIE-TGT init Besar Wicaksono
  1 sibling, 1 reply; 4+ messages in thread
From: Saurav Sachidanand @ 2026-05-11 21:09 UTC (permalink / raw)
  To: Will Deacon
  Cc: Mark Rutland, Besar Wicaksono, Ilkka Koskinen, Jonathan Hunter,
	linux-arm-kernel, linux-perf-users, linux-kernel, aghayev, juew,
	Saurav Sachidanand

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")
Signed-off-by: Saurav Sachidanand <sauravsc@amazon.com>
---
 Documentation/admin-guide/perf/nvidia-tegra410-pmu.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/admin-guide/perf/nvidia-tegra410-pmu.rst b/Documentation/admin-guide/perf/nvidia-tegra410-pmu.rst
index 0656223b61d47..24f0e801d7b80 100644
--- a/Documentation/admin-guide/perf/nvidia-tegra410-pmu.rst
+++ b/Documentation/admin-guide/perf/nvidia-tegra410-pmu.rst
@@ -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



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

* RE: [PATCH 3/3] perf/arm_cspmu: nvidia: fix BDF calculation examples in PCIE PMU docs
  2026-05-11 21:09 ` [PATCH 3/3] perf/arm_cspmu: nvidia: fix BDF calculation examples in PCIE PMU docs Saurav Sachidanand
@ 2026-05-11 21:48   ` Besar Wicaksono
  0 siblings, 0 replies; 4+ messages in thread
From: Besar Wicaksono @ 2026-05-11 21:48 UTC (permalink / raw)
  To: Saurav Sachidanand, Will Deacon
  Cc: Mark Rutland, Ilkka Koskinen, Jon Hunter,
	linux-arm-kernel@lists.infradead.org,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	aghayev@amazon.com, juew@amazon.com



> -----Original Message-----
> From: Saurav Sachidanand <sauravsc@amazon.com>
> Sent: Monday, May 11, 2026 4:09 PM
> To: Will Deacon <will@kernel.org>
> Cc: Mark Rutland <mark.rutland@arm.com>; Besar Wicaksono
> <bwicaksono@nvidia.com>; Ilkka Koskinen
> <ilkka@os.amperecomputing.com>; Jon Hunter <jonathanh@nvidia.com>;
> linux-arm-kernel@lists.infradead.org; linux-perf-users@vger.kernel.org; linux-
> kernel@vger.kernel.org; aghayev@amazon.com; juew@amazon.com; Saurav
> Sachidanand <sauravsc@amazon.com>
> 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
> 
> 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")
> Signed-off-by: Saurav Sachidanand <sauravsc@amazon.com>

Thanks for the fix.
Reviewed-by: Besar Wicaksono <bwicaksono@nvidia.com>

> ---
>  Documentation/admin-guide/perf/nvidia-tegra410-pmu.rst | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/admin-guide/perf/nvidia-tegra410-pmu.rst
> b/Documentation/admin-guide/perf/nvidia-tegra410-pmu.rst
> index 0656223b61d47..24f0e801d7b80 100644
> --- a/Documentation/admin-guide/perf/nvidia-tegra410-pmu.rst
> +++ b/Documentation/admin-guide/perf/nvidia-tegra410-pmu.rst
> @@ -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



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

* RE: [PATCH 2/3] perf/arm_cspmu: nvidia: handle empty resource list in PCIE-TGT init
  2026-05-11 21:09 [PATCH 2/3] perf/arm_cspmu: nvidia: handle empty resource list in PCIE-TGT init Saurav Sachidanand
  2026-05-11 21:09 ` [PATCH 3/3] perf/arm_cspmu: nvidia: fix BDF calculation examples in PCIE PMU docs Saurav Sachidanand
@ 2026-05-11 22:09 ` Besar Wicaksono
  1 sibling, 0 replies; 4+ messages in thread
From: Besar Wicaksono @ 2026-05-11 22:09 UTC (permalink / raw)
  To: Saurav Sachidanand, Will Deacon
  Cc: Mark Rutland, Ilkka Koskinen, Jon Hunter,
	linux-arm-kernel@lists.infradead.org,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
	aghayev@amazon.com, juew@amazon.com



> -----Original Message-----
> From: Saurav Sachidanand <sauravsc@amazon.com>
> Sent: Monday, May 11, 2026 4:09 PM
> To: Will Deacon <will@kernel.org>
> Cc: Mark Rutland <mark.rutland@arm.com>; Besar Wicaksono
> <bwicaksono@nvidia.com>; Ilkka Koskinen
> <ilkka@os.amperecomputing.com>; Jon Hunter <jonathanh@nvidia.com>;
> linux-arm-kernel@lists.infradead.org; linux-perf-users@vger.kernel.org; linux-
> kernel@vger.kernel.org; aghayev@amazon.com; juew@amazon.com; Saurav
> Sachidanand <sauravsc@amazon.com>
> 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")
> Signed-off-by: Saurav Sachidanand <sauravsc@amazon.com>
> ---
>  drivers/perf/arm_cspmu/nvidia_cspmu.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/perf/arm_cspmu/nvidia_cspmu.c
> b/drivers/perf/arm_cspmu/nvidia_cspmu.c
> index bac83e424d6dc..bae722e263e91 100644
> --- a/drivers/perf/arm_cspmu/nvidia_cspmu.c
> +++ b/drivers/perf/arm_cspmu/nvidia_cspmu.c
> @@ -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 {

Thanks for fixing.
Reviewed-by: Besar Wicaksono <bwicaksono@nvidia.com>


> +               ret = 0;
>         }
> 
>         acpi_dev_free_resource_list(&resource_list);
> --
> 2.47.3



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

end of thread, other threads:[~2026-05-11 22:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-11 21:09 [PATCH 2/3] perf/arm_cspmu: nvidia: handle empty resource list in PCIE-TGT init Saurav Sachidanand
2026-05-11 21:09 ` [PATCH 3/3] perf/arm_cspmu: nvidia: fix BDF calculation examples in PCIE PMU docs Saurav Sachidanand
2026-05-11 21:48   ` Besar Wicaksono
2026-05-11 22:09 ` [PATCH 2/3] perf/arm_cspmu: nvidia: handle empty resource list in PCIE-TGT init Besar Wicaksono

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