Skip to contentSkip to conversation

perf/smmuv3: Don't reserve the PMCG register spaces

PATCH Superseded Zhen Lei 3 participants 7 messages Jan 30, 2021 – Feb 1, 2021

Subsystems (3)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Zhen Lei

author
#0 lore raw

v4 cover perf/smmuv3: Don't reserve the PMCG register spaces

v3 --> v4:
1. Delete the unnecessary encapsulation function smmu_pmu_get_and_ioremap_resource().
2. Discard adding MODULE_SOFTDEP.

v2 --> v3:
Patch 3 is updated because https://lkml.org/lkml/2021/1/22/532 has been queued in advance.

v1 --> v2:
According to Robin Murphy's suggestion: https://lkml.org/lkml/2021/1/20/470
Don't reserve the PMCG register spaces, and reserve the entire SMMU register space.

v1:
Since the PMCG may implement its resigters space(4KB Page0 and 4KB Page1) within the SMMUv3 64KB Page0. In this case, when the SMMUv3 driver reserves the 64KB Page0 resource in advance, the PMCG driver try to reserve its Page0 and Page1 resources, a resource conflict occurs.

commit 52f3fab0067d6fa ("iommu/arm-smmu-v3: Don't reserve implementation defined register space") reduce the resource reservation range of the SMMUv3 driver, it only reserves the first 0xe00 bytes in the 64KB Page0, to avoid the above-mentioned resource conflicts.

But the SMMUv3.3 add support for ECMDQ, its registers space is also implemented in the SMMUv3 64KB Page0. This means we need to build two separate mappings. New features may be added in the future, and more independent mappings may be required. The simple problem is complicated because the user expects to map the entire SMMUv3 64KB Page0.

Therefore, the proper solution is: If the PMCG register resources are located in the 64KB Page0 of the SMMU, the PMCG driver does not reserve the conflict resources when the SMMUv3 driver has reserved the conflict resources before. Instead, the PMCG driver only performs devm_ioremap() to ensure that it can work properly.

Zhen Lei (2):
perf/smmuv3: Don't reserve the PMCG register spaces iommu/arm-smmu-v3: Reserving the entire SMMU register space

 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 24 ++++--------------------
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h |  2 --
 drivers/perf/arm_smmuv3_pmu.c               | 25 +++++++++++++++++++------
 3 files changed, 23 insertions(+), 28 deletions(-)
Signature · 7 lines
1.8.3


_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
author
#1 lore raw

PATCH v4 1/2 perf/smmuv3: Don't reserve the PMCG register spaces

According to the SMMUv3 specification:
Each PMCG counter group is represented by one 4KB page (Page 0) with one optional additional 4KB page (Page 1), both of which are at IMPLEMENTATION DEFINED base addresses.

This means that the PMCG register spaces may be within the 64KB pages of the SMMUv3 register space. When both the SMMU and PMCG drivers reserve their own resources, a resource conflict occurs.

To avoid this conflict, don't reserve the PMCG regions.

---
 drivers/perf/arm_smmuv3_pmu.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)
drivers/perf/arm_smmuv3_pmu.c +19 -6
index 74474bb322c3f26..5e894f957c7b935 100644
@@ -793,17 +793,30 @@ static int smmu_pmu_probe(struct platform_device *pdev)
 		.capabilities	= PERF_PMU_CAP_NO_EXCLUDE,
 	};
 
-	smmu_pmu->reg_base = devm_platform_get_and_ioremap_resource(pdev, 0, &res_0);
-	if (IS_ERR(smmu_pmu->reg_base))
-		return PTR_ERR(smmu_pmu->reg_base);
+	/*
+	 * The register spaces of the PMCG may be in the register space of
+	 * other devices. For example, SMMU. Therefore, the PMCG resources are
+	 * not reserved to avoid resource conflicts with other drivers.
+	 */
+	res_0 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res_0)
+		return ERR_PTR(-EINVAL);
+	smmu_pmu->reg_base = devm_ioremap(dev, res_0->start, resource_size(res_0));
+	if (!smmu_pmu->reg_base)
+		return ERR_PTR(-ENOMEM);
 
 	cfgr = readl_relaxed(smmu_pmu->reg_base + SMMU_PMCG_CFGR);
 
 	/* Determine if page 1 is present */
 	if (cfgr & SMMU_PMCG_CFGR_RELOC_CTRS) {
-		smmu_pmu->reloc_base = devm_platform_ioremap_resource(pdev, 1);
-		if (IS_ERR(smmu_pmu->reloc_base))
-			return PTR_ERR(smmu_pmu->reloc_base);
+		struct resource *res_1;
+
+		res_1 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+		if (!res_1)
+			return ERR_PTR(-EINVAL);
+		smmu_pmu->reloc_base = devm_ioremap(dev, res_1->start, resource_size(res_1));
+		if (!smmu_pmu->reloc_base)
+			return ERR_PTR(-ENOMEM);
 	} else {
 		smmu_pmu->reloc_base = smmu_pmu->reg_base;
 	}
Signature · 7 lines
1.8.3


_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
#2 lore raw

Hi, Robin:
Can you review this patch again?

Quoted 49 lines · Zhen Lei

According to the SMMUv3 specification:
Each PMCG counter group is represented by one 4KB page (Page 0) with one optional additional 4KB page (Page 1), both of which are at IMPLEMENTATION DEFINED base addresses.

This means that the PMCG register spaces may be within the 64KB pages of the SMMUv3 register space. When both the SMMU and PMCG drivers reserve their own resources, a resource conflict occurs.

To avoid this conflict, don't reserve the PMCG regions.

---
 drivers/perf/arm_smmuv3_pmu.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)
drivers/perf/arm_smmuv3_pmu.c +12 -6
index 74474bb322c3f26..5e894f957c7b935 100644
@@ -793,17 +793,30 @@ static int smmu_pmu_probe(struct platform_device *pdev)
 		.capabilities	= PERF_PMU_CAP_NO_EXCLUDE,
 	};
 
-	smmu_pmu->reg_base = devm_platform_get_and_ioremap_resource(pdev, 0, &res_0);
-	if (IS_ERR(smmu_pmu->reg_base))
-		return PTR_ERR(smmu_pmu->reg_base);
+	/*
+	 * The register spaces of the PMCG may be in the register space of
+	 * other devices. For example, SMMU. Therefore, the PMCG resources are
+	 * not reserved to avoid resource conflicts with other drivers.
+	 */
+	res_0 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res_0)
+		return ERR_PTR(-EINVAL);
+	smmu_pmu->reg_base = devm_ioremap(dev, res_0->start, resource_size(res_0));
+	if (!smmu_pmu->reg_base)
+		return ERR_PTR(-ENOMEM);
 
 	cfgr = readl_relaxed(smmu_pmu->reg_base + SMMU_PMCG_CFGR);
 
 	/* Determine if page 1 is present */
 	if (cfgr & SMMU_PMCG_CFGR_RELOC_CTRS) {
-		smmu_pmu->reloc_base = devm_platform_ioremap_resource(pdev, 1);
-		if (IS_ERR(smmu_pmu->reloc_base))
-			return PTR_ERR(smmu_pmu->reloc_base);
+		struct resource *res_1;

drivers/perf/arm_smmuv3_pmu.c static int smmu_pmu_probe(struct platform_device *pdev) · line 822

Quoted 10 lines
drivers/perf/arm_smmuv3_pmu.c +7 -0
+
+		res_1 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+		if (!res_1)
+			return ERR_PTR(-EINVAL);
+		smmu_pmu->reloc_base = devm_ioremap(dev, res_1->start, resource_size(res_1));
+		if (!smmu_pmu->reloc_base)
+			return ERR_PTR(-ENOMEM);
 	} else {
 		smmu_pmu->reloc_base = smmu_pmu->reg_base;
 	}

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

reviewer Reviewed-by on v4 1/2
#3 lore raw
In reply to Zhen Lei
Quoted 10 lines · Zhen Lei

According to the SMMUv3 specification:
Each PMCG counter group is represented by one 4KB page (Page 0) with one optional additional 4KB page (Page 1), both of which are at IMPLEMENTATION DEFINED base addresses.

This means that the PMCG register spaces may be within the 64KB pages of the SMMUv3 register space. When both the SMMU and PMCG drivers reserve their own resources, a resource conflict occurs.

To avoid this conflict, don't reserve the PMCG regions.

I said my review on v3 stood either way, but for the avoidance of doubt,

I hadn't considered that a comment is a very good idea, in case the cleanup-script crew find this in future and try to "simplify" it :)

Thanks,
Robin.

Quoted 38 lines
---
  drivers/perf/arm_smmuv3_pmu.c | 25 +++++++++++++++++++------
  1 file changed, 19 insertions(+), 6 deletions(-)
drivers/perf/arm_smmuv3_pmu.c +12 -6
index 74474bb322c3f26..5e894f957c7b935 100644
@@ -793,17 +793,30 @@ static int smmu_pmu_probe(struct platform_device *pdev)
  		.capabilities	= PERF_PMU_CAP_NO_EXCLUDE,
  	};
 
-	smmu_pmu->reg_base = devm_platform_get_and_ioremap_resource(pdev, 0, &res_0);
-	if (IS_ERR(smmu_pmu->reg_base))
-		return PTR_ERR(smmu_pmu->reg_base);
+	/*
+	 * The register spaces of the PMCG may be in the register space of
+	 * other devices. For example, SMMU. Therefore, the PMCG resources are
+	 * not reserved to avoid resource conflicts with other drivers.
+	 */
+	res_0 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res_0)
+		return ERR_PTR(-EINVAL);
+	smmu_pmu->reg_base = devm_ioremap(dev, res_0->start, resource_size(res_0));
+	if (!smmu_pmu->reg_base)
+		return ERR_PTR(-ENOMEM);
 
  	cfgr = readl_relaxed(smmu_pmu->reg_base + SMMU_PMCG_CFGR);
 
  	/* Determine if page 1 is present */
  	if (cfgr & SMMU_PMCG_CFGR_RELOC_CTRS) {
-		smmu_pmu->reloc_base = devm_platform_ioremap_resource(pdev, 1);
-		if (IS_ERR(smmu_pmu->reloc_base))
-			return PTR_ERR(smmu_pmu->reloc_base);
+		struct resource *res_1;

drivers/perf/arm_smmuv3_pmu.c static int smmu_pmu_probe(struct platform_device *pdev) · line 822

Quoted 10 lines
drivers/perf/arm_smmuv3_pmu.c +7 -0
+
+		res_1 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+		if (!res_1)
+			return ERR_PTR(-EINVAL);
+		smmu_pmu->reloc_base = devm_ioremap(dev, res_1->start, resource_size(res_1));
+		if (!smmu_pmu->reloc_base)
+			return ERR_PTR(-ENOMEM);
  	} else {
  		smmu_pmu->reloc_base = smmu_pmu->reg_base;
  	}

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

maintainer
#4 lore raw
In reply to Zhen Lei
Quoted 26 lines · Zhen Lei

According to the SMMUv3 specification:
Each PMCG counter group is represented by one 4KB page (Page 0) with one optional additional 4KB page (Page 1), both of which are at IMPLEMENTATION DEFINED base addresses.

This means that the PMCG register spaces may be within the 64KB pages of the SMMUv3 register space. When both the SMMU and PMCG drivers reserve their own resources, a resource conflict occurs.

To avoid this conflict, don't reserve the PMCG regions.

---
 drivers/perf/arm_smmuv3_pmu.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)
drivers/perf/arm_smmuv3_pmu.c +0 -1
index 74474bb322c3f26..5e894f957c7b935 100644
@@ -793,17 +793,30 @@ static int smmu_pmu_probe(struct platform_device *pdev)
 		.capabilities	= PERF_PMU_CAP_NO_EXCLUDE,
 	};
 
-	smmu_pmu->reg_base = devm_platform_get_and_ioremap_resource(pdev, 0, &res_0);

drivers/perf/arm_smmuv3_pmu.c static int smmu_pmu_probe(struct platform_device *pdev) · line 803

Quoted 10 lines
drivers/perf/arm_smmuv3_pmu.c +8 -2
-	if (IS_ERR(smmu_pmu->reg_base))
-		return PTR_ERR(smmu_pmu->reg_base);
+	/*
+	 * The register spaces of the PMCG may be in the register space of
+	 * other devices. For example, SMMU. Therefore, the PMCG resources are
+	 * not reserved to avoid resource conflicts with other drivers.
+	 */
+	res_0 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res_0)
+		return ERR_PTR(-EINVAL);

I tried to apply this, but you've got your return type in a muddle:

@@ @@
+drivers/perf/arm_smmuv3_pmu.c: In function ‘smmu_pmu_probe’:
+drivers/perf/arm_smmuv3_pmu.c:803:10: warning: returning ‘void *’ from a function with return type ‘int’ makes integer from pointer without a cast [-Wint-conversion]
+ 803 | return ERR_PTR(-EINVAL);
+ | ^~~~~~~~~~~~~~~~
+drivers/perf/arm_smmuv3_pmu.c:803:31: warning: incorrect type in return expression (different base types) [sparse]
+drivers/perf/arm_smmuv3_pmu.c:803:31: expected int [sparse]
+drivers/perf/arm_smmuv3_pmu.c:803:31: got void * [sparse]
+drivers/perf/arm_smmuv3_pmu.c:806:10: warning: returning ‘void *’ from a function with return type ‘int’ makes integer from pointer without a cast [-Wint-conversion]
+ 806 | return ERR_PTR(-ENOMEM);
+ | ^~~~~~~~~~~~~~~~
+drivers/perf/arm_smmuv3_pmu.c:806:31: warning: incorrect type in return expression (different base types) [sparse]
+drivers/perf/arm_smmuv3_pmu.c:806:31: expected int [sparse]
+drivers/perf/arm_smmuv3_pmu.c:806:31: got void * [sparse]
+drivers/perf/arm_smmuv3_pmu.c:816:11: warning: returning ‘void *’ from a function with return type ‘int’ makes integer from pointer without a cast [-Wint-conversion]
+ 816 | return ERR_PTR(-EINVAL);
+ | ^~~~~~~~~~~~~~~~
+drivers/perf/arm_smmuv3_pmu.c:816:39: warning: incorrect type in return expression (different base types) [sparse]
+drivers/perf/arm_smmuv3_pmu.c:816:39: expected int [sparse]
+drivers/perf/arm_smmuv3_pmu.c:816:39: got void * [sparse]
+drivers/perf/arm_smmuv3_pmu.c:819:11: warning: returning ‘void *’ from a function with return type ‘int’ makes integer from pointer without a cast [-Wint-conversion]
+ 819 | return ERR_PTR(-ENOMEM);
+ | ^~~~~~~~~~~~~~~~
+drivers/perf/arm_smmuv3_pmu.c:819:39: warning: incorrect type in return expression (different base types) [sparse]
+drivers/perf/arm_smmuv3_pmu.c:819:39: expected int [sparse]
+drivers/perf/arm_smmuv3_pmu.c:819:39: got void * [sparse]

Will
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

#5 lore raw
Quoted 26 lines · Will Deacon
Quoted 25 lines · Zhen Lei

According to the SMMUv3 specification:
Each PMCG counter group is represented by one 4KB page (Page 0) with one optional additional 4KB page (Page 1), both of which are at IMPLEMENTATION DEFINED base addresses.

This means that the PMCG register spaces may be within the 64KB pages of the SMMUv3 register space. When both the SMMU and PMCG drivers reserve their own resources, a resource conflict occurs.

To avoid this conflict, don't reserve the PMCG regions.

---
 drivers/perf/arm_smmuv3_pmu.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)
drivers/perf/arm_smmuv3_pmu.c +0 -0
index 74474bb322c3f26..5e894f957c7b935 100644
@@ -793,17 +793,30 @@ static int smmu_pmu_probe(struct platform_device *pdev)
 		.capabilities	= PERF_PMU_CAP_NO_EXCLUDE,
 	};
 
Quoted 13 lines

drivers/perf/arm_smmuv3_pmu.c static int smmu_pmu_probe(struct platform_device *pdev) · line 803

Quoted 11 lines
drivers/perf/arm_smmuv3_pmu.c +8 -3
-	smmu_pmu->reg_base = devm_platform_get_and_ioremap_resource(pdev, 0, &res_0);
-	if (IS_ERR(smmu_pmu->reg_base))
-		return PTR_ERR(smmu_pmu->reg_base);
+	/*
+	 * The register spaces of the PMCG may be in the register space of
+	 * other devices. For example, SMMU. Therefore, the PMCG resources are
+	 * not reserved to avoid resource conflicts with other drivers.
+	 */
+	res_0 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res_0)
+		return ERR_PTR(-EINVAL);

I tried to apply this, but you've got your return type in a muddle:

I'm dizzy. I don't know how this bug patch came out. I just pinched my leg, like I'm still in the real world.

The "ERR_PTR()" of the four ERR_PTR(xxx) should be removed. Can you help me? Or I send a new one.

Quoted 28 lines

@@ @@

(quoted diff) +25 -0
+drivers/perf/arm_smmuv3_pmu.c: In function ‘smmu_pmu_probe’:
+drivers/perf/arm_smmuv3_pmu.c:803:10: warning: returning ‘void *’ from a function with return type ‘int’ makes integer from pointer without a cast [-Wint-conversion]
+  803 |   return ERR_PTR(-EINVAL);
+      |          ^~~~~~~~~~~~~~~~
+drivers/perf/arm_smmuv3_pmu.c:803:31: warning: incorrect type in return expression (different base types) [sparse]
+drivers/perf/arm_smmuv3_pmu.c:803:31:    expected int [sparse]
+drivers/perf/arm_smmuv3_pmu.c:803:31:    got void * [sparse]
+drivers/perf/arm_smmuv3_pmu.c:806:10: warning: returning ‘void *’ from a function with return type ‘int’ makes integer from pointer without a cast [-Wint-conversion]
+  806 |   return ERR_PTR(-ENOMEM);
+      |          ^~~~~~~~~~~~~~~~
+drivers/perf/arm_smmuv3_pmu.c:806:31: warning: incorrect type in return expression (different base types) [sparse]
+drivers/perf/arm_smmuv3_pmu.c:806:31:    expected int [sparse]
+drivers/perf/arm_smmuv3_pmu.c:806:31:    got void * [sparse]
+drivers/perf/arm_smmuv3_pmu.c:816:11: warning: returning ‘void *’ from a function with return type ‘int’ makes integer from pointer without a cast [-Wint-conversion]
+  816 |    return ERR_PTR(-EINVAL);
+      |           ^~~~~~~~~~~~~~~~
+drivers/perf/arm_smmuv3_pmu.c:816:39: warning: incorrect type in return expression (different base types) [sparse]
+drivers/perf/arm_smmuv3_pmu.c:816:39:    expected int [sparse]
+drivers/perf/arm_smmuv3_pmu.c:816:39:    got void * [sparse]
+drivers/perf/arm_smmuv3_pmu.c:819:11: warning: returning ‘void *’ from a function with return type ‘int’ makes integer from pointer without a cast [-Wint-conversion]
+  819 |    return ERR_PTR(-ENOMEM);
+      |           ^~~~~~~~~~~~~~~~
+drivers/perf/arm_smmuv3_pmu.c:819:39: warning: incorrect type in return expression (different base types) [sparse]
+drivers/perf/arm_smmuv3_pmu.c:819:39:    expected int [sparse]
+drivers/perf/arm_smmuv3_pmu.c:819:39:    got void * [sparse]
Quoted 4 lines

Will

.

_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu

author
#6 lore raw

PATCH v4 2/2 iommu/arm-smmu-v3: Reserving the entire SMMU register space

In reply to Zhen Lei

commit 52f3fab0067d ("iommu/arm-smmu-v3: Don't reserve implementation defined register space") only reserves the basic SMMU register space. So the ECMDQ register space is not covered, it should be mapped again. Due to the size of this ECMDQ resource is not fixed, depending on SMMU_IDR6.CMDQ_CONTROL_PAGE_LOG2NUMQ. Processing its resource reservation to avoid resource conflict with PMCG is a bit more complicated.

Therefore, the resources of the PMCG are not reserved, and the entire SMMU resources are reserved.

---
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 24 ++++--------------------
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h |  2 --
 2 files changed, 4 insertions(+), 22 deletions(-)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +4 -20
index f04c55a7503c790..fde24403b06a9e3 100644
@@ -3476,14 +3476,6 @@ static int arm_smmu_set_bus_ops(struct iommu_ops *ops)
 	return err;
 }
 
-static void __iomem *arm_smmu_ioremap(struct device *dev, resource_size_t start,
-				      resource_size_t size)
-{
-	struct resource res = DEFINE_RES_MEM(start, size);
-
-	return devm_ioremap_resource(dev, &res);
-}
-
 static int arm_smmu_device_probe(struct platform_device *pdev)
 {
 	int irq, ret;
@@ -3519,22 +3511,14 @@ static int arm_smmu_device_probe(struct platform_device *pdev)
 	}
 	ioaddr = res->start;
 
-	/*
-	 * Don't map the IMPLEMENTATION DEFINED regions, since they may contain
-	 * the PMCG registers which are reserved by the PMU driver.
-	 */
-	smmu->base = arm_smmu_ioremap(dev, ioaddr, ARM_SMMU_REG_SZ);
+	smmu->base = devm_ioremap_resource(dev, res);
 	if (IS_ERR(smmu->base))
 		return PTR_ERR(smmu->base);
 
-	if (arm_smmu_resource_size(smmu) > SZ_64K) {
-		smmu->page1 = arm_smmu_ioremap(dev, ioaddr + SZ_64K,
-					       ARM_SMMU_REG_SZ);
-		if (IS_ERR(smmu->page1))
-			return PTR_ERR(smmu->page1);
-	} else {
+	if (arm_smmu_resource_size(smmu) > SZ_64K)
+		smmu->page1 = smmu->base + SZ_64K;
+	else
 		smmu->page1 = smmu->base;
-	}
 
 	/* Interrupt lines */
 
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +0 -2
index da525f46dab4fc1..63f2b476987d6ae 100644
@@ -152,8 +152,6 @@
 #define ARM_SMMU_PRIQ_IRQ_CFG1		0xd8
 #define ARM_SMMU_PRIQ_IRQ_CFG2		0xdc
 
-#define ARM_SMMU_REG_SZ			0xe00
-
 /* Common MSI config fields */
 #define MSI_CFG0_ADDR_MASK		GENMASK_ULL(51, 2)
 #define MSI_CFG2_SH			GENMASK(5, 4)
Signature · 7 lines
1.8.3


_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu