Skip to contentSkip to conversation

perf/smmuv3: fix crash when platdata not specified

PATCH In review Ajay Kumar 5 participants 12 messages Jul 13, 2020 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): CGME20200712165509epcas5p29e66777a4e0115420b9104ba5aa83f57@epcas5p2.samsung.com

Ajay Kumar

author
#1 lore raw

cover Add DT support for arm_smmuv3_pmu driver

Currently, only those platforms using ACPI can enable arm_smmuv3_pmu driver. This patchset adds support for enabling arm_smmuv3_pmu driver on platforms which do not enable ACPI and instead rely on DT.

Ajay Kumar (4):
perf/smmuv3: Remove dependency on CONFIG_ACPI
Documentation: perf: Add documentation for arm-smmu-v3-pmcg perf/smmuv3: add device tree support
perf/smmuv3: fix crash when platdata not specified

 .../bindings/perf/arm-smmu-v3-pmcg.txt        | 21 +++++++++++++++++++
 drivers/perf/Kconfig                          |  2 +-
 drivers/perf/arm_smmuv3_pmu.c                 | 11 ++++++++--
 3 files changed, 31 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/perf/arm-smmu-v3-pmcg.txt
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author
#2 lore raw

PATCH 1/4 perf/smmuv3: Remove dependency on CONFIG_ACPI

This patch removes CONFIG_ACPI dependency for arm_smmuv3_pmu driver so that we can build it on platforms which don't enable ACPI.

---
 drivers/perf/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/perf/Kconfig +1 -1
index a9261cf48293..8c99445a3de0 100644
@@ -55,7 +55,7 @@ config ARM_PMU_ACPI
 
 config ARM_SMMU_V3_PMU
 	 tristate "ARM SMMUv3 Performance Monitors Extension"
-	 depends on ARM64 && ACPI && ARM_SMMU_V3
+	 depends on ARM64 && ARM_SMMU_V3
 	   help
 	   Provides support for the ARM SMMUv3 Performance Monitor Counter
 	   Groups (PMCG), which provide monitoring of transactions passing
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author
#3 lore raw

PATCH 2/4 Documentation: perf: Add documentation for arm-smmu-v3-pmcg

In reply to Ajay Kumar

This patch adds devicetree binding for perf/arm_smmuv3_pmu driver.

---
 .../bindings/perf/arm-smmu-v3-pmcg.txt        | 21 +++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/perf/arm-smmu-v3-pmcg.txt
Documentation/devicetree/bindings/perf/arm-smmu-v3-pmcg.txt new file +21 -0
new file mode 100644
index 000000000000..a20fe68ce149
@@ -0,0 +1,21 @@
+* ARM SMMU V3 PMCG
+
+Required properties:
+
+- compatible: should be "arm-smmu-v3-pmu"
+
+- reg: (standard registers property) physical address and size
+	of the performance counters registers block.
+	If Page 1 is present, specify the same.
+
+- interrupts: (standard interrupt property) single interrupt
+	generated by the SMMU PMU control block
+
+Example:
+
+	pmcg@20002000 {
+		compatible = "arm-smmu-v3-pmu";
+		reg = <0x0 0x20002000 0x0 0x1000>,
+			<0x0 0x20022000 0x0 0xE00>; /* Page 1 */
+		interrupts = <0 181 4>;
+	};
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#4 lore raw

Re: [PATCH 2/4] Documentation: perf: Add documentation for arm-smmu-v3-pmcg

Quoted 3 lines · On Sun, 12 Jul 2020 22:03:39 +0530 Ajay Kumar <[email protected]> wrote:

This patch adds devicetree binding for perf/arm_smmuv3_pmu driver.

New bindings want to be in yaml format.

Quoted 22 lines
---
 .../bindings/perf/arm-smmu-v3-pmcg.txt        | 21 +++++++++++++++++++
 1 file changed, 21 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/perf/arm-smmu-v3-pmcg.txt
Documentation/devicetree/bindings/perf/arm-smmu-v3-pmcg.txt new file +11 -0
new file mode 100644
index 000000000000..a20fe68ce149
@@ -0,0 +1,21 @@
+* ARM SMMU V3 PMCG
+
+Required properties:
+
+- compatible: should be "arm-smmu-v3-pmu"
+
+- reg: (standard registers property) physical address and size
+	of the performance counters registers block.
+	If Page 1 is present, specify the same.
+
+- interrupts: (standard interrupt property) single interrupt

Documentation/devicetree/bindings/perf/arm-smmu-v3-pmcg.txt line 21

Quoted 10 lines
Documentation/devicetree/bindings/perf/arm-smmu-v3-pmcg.txt new file +10 -0
+	generated by the SMMU PMU control block
+
+Example:
+
+	pmcg@20002000 {
+		compatible = "arm-smmu-v3-pmu";
+		reg = <0x0 0x20002000 0x0 0x1000>,
+			<0x0 0x20022000 0x0 0xE00>; /* Page 1 */
+		interrupts = <0 181 4>;
+	};

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author
#5 lore raw

PATCH 3/4 perf/smmuv3: add device tree support

In reply to Ajay Kumar

Add a OF match table with compatible string to add device tree support onto arm_smmuv3_pmu driver.

---
 drivers/perf/arm_smmuv3_pmu.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/perf/arm_smmuv3_pmu.c +6 -0
index 48e28ef93a70..25feab718c20 100644
@@ -856,9 +856,15 @@ static void smmu_pmu_shutdown(struct platform_device *pdev)
 	smmu_pmu_disable(&smmu_pmu->pmu);
 }
 
+static const struct of_device_id arm_smmu_pmu_match[] = {
+	{ .compatible = "arm-smmu-v3-pmu", },
+	{},
+};
+
 static struct platform_driver smmu_pmu_driver = {
 	.driver = {
 		.name = "arm-smmu-v3-pmcg",
+		.of_match_table = arm_smmu_pmu_match,
 	},
 	.probe = smmu_pmu_probe,
 	.remove = smmu_pmu_remove,
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author
#6 lore raw

PATCH 4/4 perf/smmuv3: fix crash when platdata not specified

In reply to Ajay Kumar

The arm_smmuv3_pmu driver assumes platform data is always available and exposes a possible NULL pointer deferencing at the below line.

model = *(u32 *)dev_get_platdata(smmu_pmu->dev);

This patch fixes the bug by adding a check prior to the deferencing of the platform data pointer.

---
 drivers/perf/arm_smmuv3_pmu.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/perf/arm_smmuv3_pmu.c +3 -2
index 25feab718c20..f7a27ae2f8d8 100644
@@ -710,9 +710,10 @@ static void smmu_pmu_reset(struct smmu_pmu *smmu_pmu)
 
 static void smmu_pmu_get_acpi_options(struct smmu_pmu *smmu_pmu)
 {
-	u32 model;
+	u32 model = 0;
 
-	model = *(u32 *)dev_get_platdata(smmu_pmu->dev);
+	if (dev_get_platdata(smmu_pmu->dev))
+		model = *(u32 *)dev_get_platdata(smmu_pmu->dev);
 
 	switch (model) {
 	case IORT_SMMU_V3_PMCG_HISI_HIP08:
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#7 lore raw
Quoted 19 lines · On Sun, 12 Jul 2020 22:03:41 +0530 Ajay Kumar <[email protected]> wrote:

The arm_smmuv3_pmu driver assumes platform data is always available and exposes a possible NULL pointer deferencing at the below line.

model = *(u32 *)dev_get_platdata(smmu_pmu->dev);

This patch fixes the bug by adding a check prior to the deferencing of the platform data pointer.

---
 drivers/perf/arm_smmuv3_pmu.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/perf/arm_smmuv3_pmu.c +0 -0
index 25feab718c20..f7a27ae2f8d8 100644

drivers/perf/arm_smmuv3_pmu.c static void smmu_pmu_reset(struct smmu_pmu *smmu_pmu) · line 713

Quoted 5 lines
drivers/perf/arm_smmuv3_pmu.c +1 -1
@@ -710,9 +710,10 @@ static void smmu_pmu_reset(struct smmu_pmu *smmu_pmu)
 
 static void smmu_pmu_get_acpi_options(struct smmu_pmu *smmu_pmu)
 {
-	u32 model;
+	u32 model = 0;

Use the generic model define. Sure it's 0, but good to make it clear what the meaning of this default is.

It also seems likely you hit this because of you were using dt. If so, it seems 'odd' to be running a function explicitly mentioning acpi in it's name.

Also, should do this before introducing support that might lead to this path so as not to cause bisection problems.

Jonathan

drivers/perf/arm_smmuv3_pmu.c static void smmu_pmu_reset(struct smmu_pmu *smmu_pmu) · line 719

Quoted 7 lines
drivers/perf/arm_smmuv3_pmu.c +2 -1
-	model = *(u32 *)dev_get_platdata(smmu_pmu->dev);
+	if (dev_get_platdata(smmu_pmu->dev))
+		model = *(u32 *)dev_get_platdata(smmu_pmu->dev);
 
 	switch (model) {
 	case IORT_SMMU_V3_PMCG_HISI_HIP08:

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#8 lore raw
In reply to Ajay Kumar
Quoted 19 lines · Ajay Kumar

The arm_smmuv3_pmu driver assumes platform data is always available and exposes a possible NULL pointer deferencing at the below line.

model = *(u32 *)dev_get_platdata(smmu_pmu->dev);

This patch fixes the bug by adding a check prior to the deferencing of the platform data pointer.

---
  drivers/perf/arm_smmuv3_pmu.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
drivers/perf/arm_smmuv3_pmu.c +0 -0
index 25feab718c20..f7a27ae2f8d8 100644

drivers/perf/arm_smmuv3_pmu.c static void smmu_pmu_reset(struct smmu_pmu *smmu_pmu) · line 716

Quoted 9 lines
drivers/perf/arm_smmuv3_pmu.c +3 -2
@@ -710,9 +710,10 @@ static void smmu_pmu_reset(struct smmu_pmu *smmu_pmu)
 
  static void smmu_pmu_get_acpi_options(struct smmu_pmu *smmu_pmu)
  {
-	u32 model;
+	u32 model = 0;
 
-	model = *(u32 *)dev_get_platdata(smmu_pmu->dev);
+	if (dev_get_platdata(smmu_pmu->dev))
+		model = *(u32 *)dev_get_platdata(smmu_pmu->dev);

As I commented on the other series, ideally this could be something like:

	if (dev->of_node)
		model = of_device_get_match_data(dev->of_node);
	else
		model = *(u32 *)dev_get_platdata(dev); /* from IORT */

(and lose the "acpi_" from the function name, obviously)

Robin.

drivers/perf/arm_smmuv3_pmu.c static void smmu_pmu_reset(struct smmu_pmu *smmu_pmu)

Quoted 4 lines
drivers/perf/arm_smmuv3_pmu.c +0 -0
  	switch (model) {
  	case IORT_SMMU_V3_PMCG_HISI_HIP08:
 

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#9 lore raw

Re: [PATCH 0/4] Add DT support for arm_smmuv3_pmu driver

In reply to Ajay Kumar
Quoted 4 lines · Ajay Kumar

Currently, only those platforms using ACPI can enable arm_smmuv3_pmu driver. This patchset adds support for enabling arm_smmuv3_pmu driver on platforms which do not enable ACPI and instead rely on DT.

This must be a popular topic all of a sudden, since it's barely a week since the last one!

https://lore.kernel.org/linux-arm-kernel/[email protected]/

I'm not sure whether Jay has seen my review since Alibaba's mail server apparently decided to reject the direct reply as spam, but some of what I said there applies here too. Could we please try to coordinate where we go from here so we're not all wasting time developing and reviewing multiple versions of the exact same thing?

Robin.

Quoted 7 lines

Ajay Kumar (4):
perf/smmuv3: Remove dependency on CONFIG_ACPI
Documentation: perf: Add documentation for arm-smmu-v3-pmcg perf/smmuv3: add device tree support
perf/smmuv3: fix crash when platdata not specified

Quoted 6 lines
  .../bindings/perf/arm-smmu-v3-pmcg.txt        | 21 +++++++++++++++++++
  drivers/perf/Kconfig                          |  2 +-
  drivers/perf/arm_smmuv3_pmu.c                 | 11 ++++++++--
  3 files changed, 31 insertions(+), 3 deletions(-)

create mode 100644 Documentation/devicetree/bindings/perf/arm-smmu-v3-pmcg.txt

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#10 lore raw

Re: [PATCH 0/4] Add DT support for arm_smmuv3_pmu driver

Quoted 10 lines · Robin Murphy
Quoted 4 lines · Ajay Kumar

Currently, only those platforms using ACPI can enable arm_smmuv3_pmu driver. This patchset adds support for enabling arm_smmuv3_pmu driver on platforms which do not enable ACPI and instead rely on DT.

This must be a popular topic all of a sudden, since it's barely a week since the last one!

https://lore.kernel.org/linux-arm-kernel/[email protected]/

JFYI, I don't have that mail (so can't reply directly), but hisi platforms which have SMMUv3 PMCG don't support DT intentionally, and there is a desire to avoid headache of HW-specific DT support there in future.

thanks

Quoted 22 lines

I'm not sure whether Jay has seen my review since Alibaba's mail server apparently decided to reject the direct reply as spam, but some of what I said there applies here too. Could we please try to coordinate where we go from here so we're not all wasting time developing and reviewing multiple versions of the exact same thing?

Robin.

Quoted 7 lines

Ajay Kumar (4):
   perf/smmuv3: Remove dependency on CONFIG_ACPI
   Documentation: perf: Add documentation for arm-smmu-v3-pmcg perf/smmuv3: add device tree support
   perf/smmuv3: fix crash when platdata not specified

Quoted 6 lines

  .../bindings/perf/arm-smmu-v3-pmcg.txt        | 21 +++++++++++++++++++ drivers/perf/Kconfig                          |  2 +- drivers/perf/arm_smmuv3_pmu.c                 | 11 ++++++++--

  3 files changed, 31 insertions(+), 3 deletions(-)

  create mode 100644 Documentation/devicetree/bindings/perf/arm-smmu-v3-pmcg.txt

Quoted 5 lines

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#11 lore raw

Re: [PATCH 0/4] Add DT support for arm_smmuv3_pmu driver

Hi Robin and Garry,

Quoted 10 lines · John Garry
Quoted 9 lines · Robin Murphy
Quoted 4 lines · Ajay Kumar

Currently, only those platforms using ACPI can enable arm_smmuv3_pmu driver. This patchset adds support for enabling arm_smmuv3_pmu driver on platforms which do not enable ACPI and instead rely on DT.

This must be a popular topic all of a sudden, since it's barely a week since the last one!

Quoted 8 lines
Quoted 3 lines

https://lore.kernel.org/linux-arm-kernel/[email protected]/

JFYI, I don't have that mail (so can't reply directly), but hisi platforms which have SMMUv3 PMCG don't support DT intentionally, and there is a desire to avoid headache of HW-specific DT support there in future.

The patchset allows support for both DT and ACPI to co-exist.

Quoted 6 lines
Quoted 6 lines

I'm not sure whether Jay has seen my review since Alibaba's mail server apparently decided to reject the direct reply as spam, but some of what I said there applies here too. Could we please try to coordinate where we go from here so we're not all wasting time developing and reviewing multiple versions of the exact same thing?

Agreed. I checked Jay's patchset:
https://lore.kernel.org/linux-arm-kernel/[email protected]/

Pretty much tries to achieve the same thing. Its Jay's call now.

Quoted 28 lines
Quoted 21 lines

Robin.

Quoted 7 lines

Ajay Kumar (4):
perf/smmuv3: Remove dependency on CONFIG_ACPI
Documentation: perf: Add documentation for arm-smmu-v3-pmcg perf/smmuv3: add device tree support
perf/smmuv3: fix crash when platdata not specified

Quoted 7 lines
  .../bindings/perf/arm-smmu-v3-pmcg.txt        | 21 +++++++++++++++++++
  drivers/perf/Kconfig                          |  2 +-
  drivers/perf/arm_smmuv3_pmu.c                 | 11 ++++++++--
  3 files changed, 31 insertions(+), 3 deletions(-)

create mode 100644
Documentation/devicetree/bindings/perf/arm-smmu-v3-pmcg.txt

Quoted 5 lines

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
.

Quoted 5 lines

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#12 lore raw

Re: [PATCH 0/4] Add DT support for arm_smmuv3_pmu driver

In reply to John Garry
Quoted 7 lines · John Garry
Quoted 6 lines · Robin Murphy
Quoted 4 lines · Ajay Kumar

Currently, only those platforms using ACPI can enable arm_smmuv3_pmu driver. This patchset adds support for enabling arm_smmuv3_pmu driver on platforms which do not enable ACPI and instead rely on DT.

Quoted 6 lines
Quoted 4 lines

This must be a popular topic all of a sudden, since it's barely a week since the last one!

https://lore.kernel.org/linux-arm-kernel/[email protected]/

JFYI, I don't have that mail (so can't reply directly), but hisi platforms which have SMMUv3 PMCG don't support DT intentionally, and there is a desire to avoid headache of HW-specific DT support there in future.

Thanks John, I was wondering about that, since I do have a vague memory of a promise that you guys would never ask for DT support yourselves :)

Perhaps someone at Huawei can follow up directly with Alibaba about their use-case and whether there's a better way to support it upstream (if at all).

Bonus tip: If you download a "raw" link from lore and save it with a .eml extension, Thunderbird can then be convinced to open it in a manner which can be replied to.

Robin.

Quoted 31 lines

thanks

Quoted 27 lines

I'm not sure whether Jay has seen my review since Alibaba's mail server apparently decided to reject the direct reply as spam, but some of what I said there applies here too. Could we please try to coordinate where we go from here so we're not all wasting time developing and reviewing multiple versions of the exact same thing?

Robin.

Quoted 7 lines

Ajay Kumar (4):
   perf/smmuv3: Remove dependency on CONFIG_ACPI
   Documentation: perf: Add documentation for arm-smmu-v3-pmcg perf/smmuv3: add device tree support
   perf/smmuv3: fix crash when platdata not specified

Quoted 6 lines

  .../bindings/perf/arm-smmu-v3-pmcg.txt        | 21 +++++++++++++++++++ drivers/perf/Kconfig                          |  2 +- drivers/perf/arm_smmuv3_pmu.c                 | 11 ++++++++--

  3 files changed, 31 insertions(+), 3 deletions(-)

  create mode 100644 Documentation/devicetree/bindings/perf/arm-smmu-v3-pmcg.txt

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel