Skip to contentSkip to conversation

iommu/arm-smmu: Allow size of stage 1 output to max possible value for sateg 2 bypass

PATCH New c.tirumalesh at gmail.com 2 participants 5 messages Aug 27, 2014 – Sep 1, 2014 IOMMU

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu/arm-smmu: Allow size of stage 1 output to max possible value for sateg 2 bypass

From: Tirumalesh Chalamarla <[email protected]>

This patch modifes output_mask calculation logic for stage 1 and allow max possible value supported by SMMU implementaions for translations, where stage 2 is bypassed.

Erlier it is not possible to access full supported PA address with stage 1, even if it is supported by SMMU and stage 2 is bypass.

---
 drivers/iommu/arm-smmu.c | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)
drivers/iommu/arm-smmu.c +23 -8
index a6b00bd..56cf42d 100644
@@ -707,6 +707,17 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain)
 	struct arm_smmu_cfg *cfg = &smmu_domain->cfg;
 	struct arm_smmu_device *smmu = smmu_domain->smmu;
 	void __iomem *cb_base, *gr0_base, *gr1_base;
+	unsigned long s1_out_size;
+
+	if (cfg->cbar == CBAR_TYPE_S1_TRANS_S2_BYPASS) {
+		s1_out_size = smmu->s1_output_size;
+	} else {
+#ifdef CONFIG_64BIT
+		s1_out_size = min((unsigned long)VA_BITS, smmu->s1_output_size);
+#else
+		s1_out_size = min(32UL, smmu->s1_output_size);
+#endif
+	}
 
 	gr0_base = ARM_SMMU_GR0(smmu);
 	gr1_base = ARM_SMMU_GR1(smmu);
@@ -762,7 +773,7 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain)
 			break;
 		}
 
-		switch (smmu->s1_output_size) {
+		switch (s1_out_size) {
 		case 32:
 			reg |= (TTBCR2_ADDR_32 << TTBCR2_PASIZE_SHIFT);
 			break;
@@ -808,7 +819,7 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain)
 			reg = TTBCR_TG0_64K;
 
 		if (!stage1) {
-			reg |= (64 - smmu->s1_output_size) << TTBCR_T0SZ_SHIFT;
+			reg |= (64 - s1_out_size) << TTBCR_T0SZ_SHIFT;
 
 			switch (smmu->s2_output_size) {
 			case 32:
@@ -1411,9 +1422,17 @@ static int arm_smmu_handle_mapping(struct arm_smmu_domain *smmu_domain,
 	if (cfg->cbar == CBAR_TYPE_S2_TRANS) {
 		stage = 2;
 		output_mask = (1ULL << smmu->s2_output_size) - 1;
-	} else {
+	} else if (cfg->cbar == CBAR_TYPE_S1_TRANS_S2_BYPASS) {
 		stage = 1;
 		output_mask = (1ULL << smmu->s1_output_size) - 1;
+	} else {
+		stage = 1;
+#ifdef CONFIG_64BIT
+		output_mask = (1ULL << min((unsigned long)VA_BITS,
+					smmu->s1_output_size)) - 1;
+#else
+		output_mask = (1ULL << min(32UL, smmu->s1_output_size)) - 1;
+#endif
 	}
 
 	if (!pgd)
@@ -1777,11 +1796,7 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu)
 	 * Stage-1 output limited by stage-2 input size due to pgd
 	 * allocation (PTRS_PER_PGD).
 	 */
-#ifdef CONFIG_64BIT
-	smmu->s1_output_size = min((unsigned long)VA_BITS, size);
-#else
-	smmu->s1_output_size = min(32UL, size);
-#endif
+	smmu->s1_output_size = size;
 
 	/* The stage-2 output mask is also applied for bypass */
 	size = arm_smmu_id_size_to_bits((id >> ID2_OAS_SHIFT) & ID2_OAS_MASK);
Signature · 1 line
1.9.3
#1 lore raw

PATCH 1/1 iommu/arm-smmu: Allow size of stage 1 output to max possible value for sateg 2 bypass

Hi Tirumalesh,

Quoted 8 lines · c.tirumalesh at gmail.com

From: Tirumalesh Chalamarla <[email protected]>

This patch modifes output_mask calculation logic for stage 1 and allow max possible value supported by SMMU implementaions for translations, where stage 2 is bypassed.

Erlier it is not possible to access full supported PA address with stage 1, even if it is supported by SMMU and stage 2 is bypass.

I'm trying to understand what you're getting at here. Essentially, you want to use the full stage-1 output range for a stage-1 only MMU, right?

The code is currently structured to truncate that to the stage-2 input size for nested translation. However, I think that's better solved by faking the ID registers in the virtual SMMU instead of posing these restrictions on the host as well.

Assuming I understand the problem correctly, why not simply remove the truncation from the existing code (untested patch below)? Does that not work for you?

Will

--->8

drivers/iommu/arm-smmu.c +1 -15
index 2b1271658bfa..a02d05793a73 100644
@@ -1917,21 +1917,7 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu)
        /* ID2 */
        id = readl_relaxed(gr0_base + ARM_SMMU_GR0_ID2);
        size = arm_smmu_id_size_to_bits((id >> ID2_IAS_SHIFT) & ID2_IAS_MASK);
-
-       /*
-        * Stage-1 output limited by stage-2 input size due to pgd
-        * allocation (PTRS_PER_PGD).
-        */
-       if (smmu->features & ARM_SMMU_FEAT_TRANS_NESTED) {
-#ifdef CONFIG_64BIT
-               smmu->s1_output_size = min_t(unsigned long, VA_BITS, size);
-#else
-               smmu->s1_output_size = min(32UL, size);
-#endif
-       } else {
-               smmu->s1_output_size = min_t(unsigned long, PHYS_MASK_SHIFT,
-                                            size);
-       }
+       smmu->s1_output_size = min_t(unsigned long, PHYS_MASK_SHIFT, size);
 
        /* The stage-2 output mask is also applied for bypass */
        size = arm_smmu_id_size_to_bits((id >> ID2_OAS_SHIFT) & ID2_OAS_MASK);
#2 lore raw

PATCH 1/1 iommu/arm-smmu: Allow size of stage 1 output to max possible value for sateg 2 bypass

Hi Will,

Quoted 9 lines · Will Deacon

Hi Tirumalesh,

Quoted 6 lines · c.tirumalesh at gmail.com

From: Tirumalesh Chalamarla <[email protected]>

This patch modifes output_mask calculation logic for stage 1 and allow max possible value supported by SMMU implementaions for translations, where stage 2 is bypassed.

Quoted 6 lines
Quoted 2 lines

Erlier it is not possible to access full supported PA address with stage 1, even if it is supported by SMMU and stage 2 is bypass.

I'm trying to understand what you're getting at here. Essentially, you want to use the full stage-1 output range for a stage-1 only MMU, right?

YES, restrict stage 1 out put to VA_BITS only if stage 2 is needed (i.e for NESTED_TRANSLATIONS).

Quoted 5 lines

The code is currently structured to truncate that to the stage-2 input size for nested translation. However, I think that's better solved by faking the ID registers in the virtual SMMU instead of posing these restrictions on the host as well.

This sounds good, the only problem is, it is too much bound to virtual SMMU. There is no harm in changing/checking the
stage 1 output mask, if stage 2 present, in host also.

Quoted 4 lines

Assuming I understand the problem correctly, why not simply remove the truncation from the existing code (untested patch below)? Does that not work for you?

This will not restrict stage 1 out put to VA_BITS, even for two level translations. this results in non debuggable problems
if we configure incorrectly. there is no harm in checking the condition for nested translations, as i did in my patch.

Regards,
Tirumalesh.

Quoted 31 lines

Will

--->8

drivers/iommu/arm-smmu.c +1 -15
index 2b1271658bfa..a02d05793a73 100644
@@ -1917,21 +1917,7 @@ static int arm_smmu_device_cfg_probe(struct arm_smmu_device *smmu)
        /* ID2 */
        id = readl_relaxed(gr0_base + ARM_SMMU_GR0_ID2);
        size = arm_smmu_id_size_to_bits((id >> ID2_IAS_SHIFT) & ID2_IAS_MASK);
-
-       /*
-        * Stage-1 output limited by stage-2 input size due to pgd
-        * allocation (PTRS_PER_PGD).
-        */
-       if (smmu->features & ARM_SMMU_FEAT_TRANS_NESTED) {
-#ifdef CONFIG_64BIT
-               smmu->s1_output_size = min_t(unsigned long, VA_BITS, size);
-#else
-               smmu->s1_output_size = min(32UL, size);
-#endif
-       } else {
-               smmu->s1_output_size = min_t(unsigned long, PHYS_MASK_SHIFT,
-                                            size);
-       }
+       smmu->s1_output_size = min_t(unsigned long, PHYS_MASK_SHIFT, size);
 
        /* The stage-2 output mask is also applied for bypass */
        size = arm_smmu_id_size_to_bits((id >> ID2_OAS_SHIFT) & ID2_OAS_MASK);
#3 lore raw

PATCH 1/1 iommu/arm-smmu: Allow size of stage 1 output to max possible value for sateg 2 bypass

Quoted 10 lines · tirumalesh chalamarla
Quoted 4 lines · Will Deacon

Assuming I understand the problem correctly, why not simply remove the truncation from the existing code (untested patch below)? Does that not work for you?

This will not restrict stage 1 out put to VA_BITS, even for two level translations. this results in non debuggable problems
if we configure incorrectly. there is no harm in checking the condition for nested translations, as i did in my patch.

Right, but restricting stage-1 output to VA_BITS doesn't make sense; remember it's not the same kernel writing the stage-1 and stage-2 tables.

Will

#4 lore raw

PATCH 1/1 iommu/arm-smmu: Allow size of stage 1 output to max possible value for sateg 2 bypass

Quoted 7 lines · Will Deacon
Quoted 6 lines · tirumalesh chalamarla
Quoted 4 lines · Will Deacon

Assuming I understand the problem correctly, why not simply remove the truncation from the existing code (untested patch below)? Does that not work for you?

Quoted 8 lines
Quoted 4 lines

This will not restrict stage 1 out put to VA_BITS, even for two level translations. this results in non debuggable problems
if we configure incorrectly. there is no harm in checking the condition for nested translations, as i did in my patch.

Right, but restricting stage-1 output to VA_BITS doesn't make sense; remember it's not the same kernel writing the stage-1 and stage-2 tables.

Yes, if we restrict driver by limiting either one and removing NESTED altogether, i don't have a problem with this approach.

Regards,
Tirumalesh.

Quoted 1 line

Will