Skip to contentSkip to conversation

iommu/arm-smmu: Fix for ThunderX erratum #27704

PATCH In review Tomasz Nowicki 3 participants 6 messages Jan 11, 2017 – Jan 13, 2017 1 message not in the archive IOMMU

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu/arm-smmu: Fix for ThunderX erratum #27704

The goal of erratum #27704 workaround was to make sure that ASIDs and VMIDs are unique across all SMMU instances on affected Cavium systems.

Currently, the workaround code partitions ASIDs and VMIDs by increasing global cavium_smmu_context_count which in turn becomes the base ASID and VMID value for the given SMMU instance upon the context bank initialization.

For systems with multiple SMMU instances this approach implies the risk of crossing 8-bit ASID, like for CN88xx capable of 4 SMMUv2, 128 context bank each:
SMMU_0 (0-127 ASID RANGE)
SMMU_1 (127-255 ASID RANGE)
SMMU_2 (256-383 ASID RANGE) <--- crossing 8-bit ASID
SMMU_3 (384-511 ASID RANGE) <--- crossing 8-bit ASID

Since we use 8-bit ASID now we effectively misconfigure ASID[15:8] bits for SMMU_CBn_TTBRm register. Also, we still use non-zero ASID[15:8] bits upon context invalidation. This patch adds 16-bit ASID support for stage-1 AArch64 contexts for Cavium SMMUv2 model so that we use ASIDs consistently.

---
 drivers/iommu/arm-smmu.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/iommu/arm-smmu.c +4 -0
index a60cded..ae8f059 100644
@@ -260,6 +260,7 @@ enum arm_smmu_s2cr_privcfg {
 
 #define TTBCR2_SEP_SHIFT		15
 #define TTBCR2_SEP_UPSTREAM		(0x7 << TTBCR2_SEP_SHIFT)
+#define TTBCR2_AS			(1 << 4)
 
 #define TTBRn_ASID_SHIFT		48
 
@@ -778,6 +779,9 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain,
 			reg = pgtbl_cfg->arm_lpae_s1_cfg.tcr;
 			reg2 = pgtbl_cfg->arm_lpae_s1_cfg.tcr >> 32;
 			reg2 |= TTBCR2_SEP_UPSTREAM;
+			if (smmu->model == CAVIUM_SMMUV2 &&
+			    cfg->fmt == ARM_SMMU_CTX_FMT_AARCH64)
+				reg2 |= TTBCR2_AS;
 		}
 		if (smmu->version > ARM_SMMU_V1)
 			writel_relaxed(reg2, cb_base + ARM_SMMU_CB_TTBCR2);
Signature · 1 line
2.7.4
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Tomasz Nowicki

The goal of erratum #27704 workaround was to make sure that ASIDs and VMIDs are unique across all SMMU instances on affected Cavium systems.

Currently, the workaround code partitions ASIDs and VMIDs by increasing global cavium_smmu_context_count which in turn becomes the base ASID and VMID value for the given SMMU instance upon the context bank initialization.

Quoted 6 lines

For systems with multiple SMMU instances this approach implies the risk of crossing 8-bit ASID, like for CN88xx capable of 4 SMMUv2, 128 context bank each:
SMMU_0 (0-127 ASID RANGE)
SMMU_1 (127-255 ASID RANGE)
SMMU_2 (256-383 ASID RANGE) <--- crossing 8-bit ASID
SMMU_3 (384-511 ASID RANGE) <--- crossing 8-bit ASID

I could swear that@some point in the original discussion it was said that the TLBs were only shared between pairs of SMMUs, so in fact 0/1 and 2/3 are independent of each other - out of interest, have you managed to hit an actual problem in practice or is this patch just by inspection?

Of course, depending on the SMMUs to probe in the right order isn't particularly robust, so it's still probably a worthwhile change.

Quoted 23 lines

Since we use 8-bit ASID now we effectively misconfigure ASID[15:8] bits for SMMU_CBn_TTBRm register. Also, we still use non-zero ASID[15:8] bits upon context invalidation. This patch adds 16-bit ASID support for stage-1 AArch64 contexts for Cavium SMMUv2 model so that we use ASIDs consistently.

---
 drivers/iommu/arm-smmu.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/iommu/arm-smmu.c +1 -0
index a60cded..ae8f059 100644
@@ -260,6 +260,7 @@ enum arm_smmu_s2cr_privcfg {
 
 #define TTBCR2_SEP_SHIFT		15
 #define TTBCR2_SEP_UPSTREAM		(0x7 << TTBCR2_SEP_SHIFT)
+#define TTBCR2_AS			(1 << 4)
 
 #define TTBRn_ASID_SHIFT		48
 

drivers/iommu/arm-smmu.c static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain, · line 782

Quoted 4 lines
drivers/iommu/arm-smmu.c +1 -0
@@ -778,6 +779,9 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain,
 			reg = pgtbl_cfg->arm_lpae_s1_cfg.tcr;
 			reg2 = pgtbl_cfg->arm_lpae_s1_cfg.tcr >> 32;
 			reg2 |= TTBCR2_SEP_UPSTREAM;
+			if (smmu->model == CAVIUM_SMMUV2 &&

I'd be inclined to say "smmu->version == ARM_SMMU_V2" there, rather than make it Cavium-specific - we enable 16-bit VMID unconditionally where supported, so I don't see any reason not to handle 16-bit ASIDs in the same manner.

drivers/iommu/arm-smmu.c static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain, · line 787

Quoted 6 lines
drivers/iommu/arm-smmu.c +2 -0
+			    cfg->fmt == ARM_SMMU_CTX_FMT_AARCH64)
+				reg2 |= TTBCR2_AS;
 		}
 		if (smmu->version > ARM_SMMU_V1)
 			writel_relaxed(reg2, cb_base + ARM_SMMU_CB_TTBCR2);

Either way:

#6 lore raw
In reply to a message not in the archive

________________________________
From: Tomasz Nowicki <tn-nYOzD4b6Jr9Wk0Htik3J/[email protected]>
Sent: Wednesday, January 11, 2017 3:51 AM
To: [email protected]; [email protected]; [email protected]; [email protected]
Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org; iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org; [email protected]; Goutham, Sunil; Akula, Geethasowjanya; Chalamarla, Tirumalesh; Kapoor, Prasun; Tomasz Nowicki
Subject: [PATCH 1/1] iommu/arm-smmu: Fix for ThunderX erratum #27704

The goal of erratum #27704 workaround was to make sure that ASIDs and VMIDs are unique across all SMMU instances on affected Cavium systems.

Currently, the workaround code partitions ASIDs and VMIDs by increasing global cavium_smmu_context_count which in turn becomes the base ASID and VMID value for the given SMMU instance upon the context bank initialization.

For systems with multiple SMMU instances this approach implies the risk of crossing 8-bit ASID, like for CN88xx capable of 4 SMMUv2, 128 context bank each:
SMMU_0 (0-127 ASID RANGE)
SMMU_1 (127-255 ASID RANGE)
SMMU_2 (256-383 ASID RANGE) <--- crossing 8-bit ASID
SMMU_3 (384-511 ASID RANGE) <--- crossing 8-bit ASID

Since we use 8-bit ASID now we effectively misconfigure ASID[15:8] bits for SMMU_CBn_TTBRm register. Also, we still use non-zero ASID[15:8] bits upon context invalidation. This patch adds 16-bit ASID support for stage-1 AArch64 contexts for Cavium SMMUv2 model so that we use ASIDs consistently.

---
 drivers/iommu/arm-smmu.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/iommu/arm-smmu.c +4 -0
index a60cded..ae8f059 100644
@@ -260,6 +260,7 @@ enum arm_smmu_s2cr_privcfg {
 
 #define TTBCR2_SEP_SHIFT                15
 #define TTBCR2_SEP_UPSTREAM             (0x7 << TTBCR2_SEP_SHIFT)
+#define TTBCR2_AS                      (1 << 4)
 
 #define TTBRn_ASID_SHIFT                48
 
@@ -778,6 +779,9 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain,
                         reg = pgtbl_cfg->arm_lpae_s1_cfg.tcr;
                         reg2 = pgtbl_cfg->arm_lpae_s1_cfg.tcr >> 32;
                         reg2 |= TTBCR2_SEP_UPSTREAM;
+                       if (smmu->model == CAVIUM_SMMUV2 &&
+                           cfg->fmt == ARM_SMMU_CTX_FMT_AARCH64)
+                               reg2 |= TTBCR2_AS;
 
 

it shouldn't be cavium specific just set this bet when we enable 16bit ASID.

                 }
                 if (smmu->version > ARM_SMMU_V1)
                         writel_relaxed(reg2, cb_base + ARM_SMMU_CB_TTBCR2);

you can add my review by.
--
2.7.4

#2 lore raw
In reply to Robin Murphy
Quoted 15 lines · Robin Murphy
Quoted 7 lines · Tomasz Nowicki

The goal of erratum #27704 workaround was to make sure that ASIDs and VMIDs are unique across all SMMU instances on affected Cavium systems.

Currently, the workaround code partitions ASIDs and VMIDs by increasing global cavium_smmu_context_count which in turn becomes the base ASID and VMID value for the given SMMU instance upon the context bank initialization.

Quoted 6 lines

For systems with multiple SMMU instances this approach implies the risk of crossing 8-bit ASID, like for CN88xx capable of 4 SMMUv2, 128 context bank each:
SMMU_0 (0-127 ASID RANGE)
SMMU_1 (127-255 ASID RANGE)
SMMU_2 (256-383 ASID RANGE) <--- crossing 8-bit ASID
SMMU_3 (384-511 ASID RANGE) <--- crossing 8-bit ASID

Quoted 3 lines

I could swear that at some point in the original discussion it was said that the TLBs were only shared between pairs of SMMUs, so in fact 0/1 and 2/3 are independent of each other

Indeed TLBs are only shared between pairs of SMMUs but the workaround makes sure ASIDs are unique across all SMMU instances so we do not have to bother about SMMUs probe order.

- out of interest, have you

Quoted 2 lines

managed to hit an actual problem in practice or is this patch just by inspection?

Except SMMU0/1 devices all other devices under other SMMUs will fail on guest power off/on. Since we try to invalidate tlb with 16bit ASID but we actually have 8 bit zero padded 16 bit entry.

Quoted 26 lines

Of course, depending on the SMMUs to probe in the right order isn't particularly robust, so it's still probably a worthwhile change.

Quoted 22 lines

Since we use 8-bit ASID now we effectively misconfigure ASID[15:8] bits for SMMU_CBn_TTBRm register. Also, we still use non-zero ASID[15:8] bits upon context invalidation. This patch adds 16-bit ASID support for stage-1 AArch64 contexts for Cavium SMMUv2 model so that we use ASIDs consistently.

---
 drivers/iommu/arm-smmu.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/iommu/arm-smmu.c +1 -0
index a60cded..ae8f059 100644
@@ -260,6 +260,7 @@ enum arm_smmu_s2cr_privcfg {
 
 #define TTBCR2_SEP_SHIFT		15
 #define TTBCR2_SEP_UPSTREAM		(0x7 << TTBCR2_SEP_SHIFT)
+#define TTBCR2_AS			(1 << 4)
 
 #define TTBRn_ASID_SHIFT		48
 
Quoted 10 lines

drivers/iommu/arm-smmu.c static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain, · line 782

Quoted 5 lines
drivers/iommu/arm-smmu.c +1 -0
@@ -778,6 +779,9 @@ static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain,
 			reg = pgtbl_cfg->arm_lpae_s1_cfg.tcr;
 			reg2 = pgtbl_cfg->arm_lpae_s1_cfg.tcr >> 32;
 			reg2 |= TTBCR2_SEP_UPSTREAM;
+			if (smmu->model == CAVIUM_SMMUV2 &&

I'd be inclined to say "smmu->version == ARM_SMMU_V2" there, rather than make it Cavium-specific - we enable 16-bit VMID unconditionally where supported, so I don't see any reason not to handle 16-bit ASIDs in the same manner.

I agree, I will enable 16-bit ASID for ARM_SMMU_V2.

Quoted 11 lines

drivers/iommu/arm-smmu.c static void arm_smmu_init_context_bank(struct arm_smmu_domain *smmu_domain, · line 787

Quoted 7 lines
drivers/iommu/arm-smmu.c +2 -0
+			    cfg->fmt == ARM_SMMU_CTX_FMT_AARCH64)
+				reg2 |= TTBCR2_AS;
 		}
 		if (smmu->version > ARM_SMMU_V1)
 			writel_relaxed(reg2, cb_base + ARM_SMMU_CB_TTBCR2);

Either way:

Thanks Robin!

Tomasz

#3 lore raw
Quoted 76 lines · Tomasz Nowicki
Quoted 18 lines · Robin Murphy
Quoted 9 lines · Tomasz Nowicki

The goal of erratum #27704 workaround was to make sure that ASIDs and VMIDs
are unique across all SMMU instances on affected Cavium systems.

Currently, the workaround code partitions ASIDs and VMIDs by increasing global cavium_smmu_context_count which in turn becomes the base ASID and VMID
value for the given SMMU instance upon the context bank initialization.

Quoted 7 lines

For systems with multiple SMMU instances this approach implies the risk of crossing 8-bit ASID, like for CN88xx capable of 4 SMMUv2, 128 context bank each:
SMMU_0 (0-127 ASID RANGE)
SMMU_1 (127-255 ASID RANGE)
SMMU_2 (256-383 ASID RANGE) <--- crossing 8-bit ASID
SMMU_3 (384-511 ASID RANGE) <--- crossing 8-bit ASID

Quoted 3 lines

I could swear that at some point in the original discussion it was said that the TLBs were only shared between pairs of SMMUs, so in fact 0/1 and 2/3 are independent of each other

Indeed TLBs are only shared between pairs of SMMUs but the workaround makes sure ASIDs are unique across all SMMU instances so we do not have to bother about SMMUs probe order.

- out of interest, have you

Quoted 2 lines

managed to hit an actual problem in practice or is this patch just by inspection?

Except SMMU0/1 devices all other devices under other SMMUs will fail on guest power off/on. Since we try to invalidate tlb with 16bit ASID but we actually have 8 bit zero padded 16 bit entry.

Quoted 29 lines

Of course, depending on the SMMUs to probe in the right order isn't particularly robust, so it's still probably a worthwhile change.

Quoted 25 lines

Since we use 8-bit ASID now we effectively misconfigure ASID[15:8] bits for
SMMU_CBn_TTBRm register. Also, we still use non-zero ASID[15:8] bits upon context invalidation. This patch adds 16-bit ASID support for stage-1
AArch64 contexts for Cavium SMMUv2 model so that we use ASIDs consistently.

---
 drivers/iommu/arm-smmu.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/iommu/arm-smmu.c +1 -0
index a60cded..ae8f059 100644
@@ -260,6 +260,7 @@ enum arm_smmu_s2cr_privcfg {
 
 #define TTBCR2_SEP_SHIFT        15
 #define TTBCR2_SEP_UPSTREAM        (0x7 << TTBCR2_SEP_SHIFT)
+#define TTBCR2_AS            (1 << 4)
 
 #define TTBRn_ASID_SHIFT        48
 
Quoted 11 lines

drivers/iommu/arm-smmu.c static void arm_smmu_init_context_bank(struct · line 783

Quoted 6 lines
drivers/iommu/arm-smmu.c +1 -0
@@ -778,6 +779,9 @@ static void arm_smmu_init_context_bank(struct
 arm_smmu_domain *smmu_domain,
             reg = pgtbl_cfg->arm_lpae_s1_cfg.tcr;
             reg2 = pgtbl_cfg->arm_lpae_s1_cfg.tcr >> 32;
             reg2 |= TTBCR2_SEP_UPSTREAM;
+            if (smmu->model == CAVIUM_SMMUV2 &&

I'd be inclined to say "smmu->version == ARM_SMMU_V2" there, rather than make it Cavium-specific - we enable 16-bit VMID unconditionally where supported, so I don't see any reason not to handle 16-bit ASIDs in the same manner.

Quoted 2 lines

I agree, I will enable 16-bit ASID for ARM_SMMU_V2.

Actually, the ARM_SMMU_CTX_FMT_AARCH64 context check is all we need here:

+ if (cfg->fmt == ARM_SMMU_CTX_FMT_AARCH64)
+ reg2 |= TTBCR2_AS;

Thanks,
Tomasz

reviewer
#4 lore raw
Quoted 82 lines · Tomasz Nowicki
Quoted 76 lines · Tomasz Nowicki
Quoted 18 lines · Robin Murphy
Quoted 9 lines · Tomasz Nowicki

The goal of erratum #27704 workaround was to make sure that ASIDs and VMIDs
are unique across all SMMU instances on affected Cavium systems.

Currently, the workaround code partitions ASIDs and VMIDs by increasing global cavium_smmu_context_count which in turn becomes the base ASID and VMID
value for the given SMMU instance upon the context bank initialization.

Quoted 7 lines

For systems with multiple SMMU instances this approach implies the risk of crossing 8-bit ASID, like for CN88xx capable of 4 SMMUv2, 128 context bank each:
SMMU_0 (0-127 ASID RANGE)
SMMU_1 (127-255 ASID RANGE)
SMMU_2 (256-383 ASID RANGE) <--- crossing 8-bit ASID
SMMU_3 (384-511 ASID RANGE) <--- crossing 8-bit ASID

Quoted 3 lines

I could swear that at some point in the original discussion it was said that the TLBs were only shared between pairs of SMMUs, so in fact 0/1 and 2/3 are independent of each other

Indeed TLBs are only shared between pairs of SMMUs but the workaround makes sure ASIDs are unique across all SMMU instances so we do not have to bother about SMMUs probe order.

- out of interest, have you

Quoted 2 lines

managed to hit an actual problem in practice or is this patch just by inspection?

Except SMMU0/1 devices all other devices under other SMMUs will fail on guest power off/on. Since we try to invalidate tlb with 16bit ASID but we actually have 8 bit zero padded 16 bit entry.

Quoted 29 lines

Of course, depending on the SMMUs to probe in the right order isn't particularly robust, so it's still probably a worthwhile change.

Quoted 25 lines

Since we use 8-bit ASID now we effectively misconfigure ASID[15:8] bits for
SMMU_CBn_TTBRm register. Also, we still use non-zero ASID[15:8] bits upon context invalidation. This patch adds 16-bit ASID support for stage-1
AArch64 contexts for Cavium SMMUv2 model so that we use ASIDs consistently.

---
 drivers/iommu/arm-smmu.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/iommu/arm-smmu.c +1 -0
index a60cded..ae8f059 100644
@@ -260,6 +260,7 @@ enum arm_smmu_s2cr_privcfg {
 
 #define TTBCR2_SEP_SHIFT        15
 #define TTBCR2_SEP_UPSTREAM        (0x7 << TTBCR2_SEP_SHIFT)
+#define TTBCR2_AS            (1 << 4)
 
 #define TTBRn_ASID_SHIFT        48
 
Quoted 11 lines

drivers/iommu/arm-smmu.c static void arm_smmu_init_context_bank(struct · line 783

Quoted 6 lines
drivers/iommu/arm-smmu.c +1 -0
@@ -778,6 +779,9 @@ static void arm_smmu_init_context_bank(struct
 arm_smmu_domain *smmu_domain,
             reg = pgtbl_cfg->arm_lpae_s1_cfg.tcr;
             reg2 = pgtbl_cfg->arm_lpae_s1_cfg.tcr >> 32;
             reg2 |= TTBCR2_SEP_UPSTREAM;
+            if (smmu->model == CAVIUM_SMMUV2 &&

I'd be inclined to say "smmu->version == ARM_SMMU_V2" there, rather than make it Cavium-specific - we enable 16-bit VMID unconditionally where supported, so I don't see any reason not to handle 16-bit ASIDs in the same manner.

Quoted 2 lines

I agree, I will enable 16-bit ASID for ARM_SMMU_V2.

Actually, the ARM_SMMU_CTX_FMT_AARCH64 context check is all we need here:

Review

Quoted 2 lines
(quoted diff) +2 -0
+            if (cfg->fmt == ARM_SMMU_CTX_FMT_AARCH64)
+                reg2 |= TTBCR2_AS;

Ah, clever! The horrible SMMUv1 64KB supplement supports AArch64 contexts without being SMMUv2, but of course doesn't have stage 1 :)

Robin.

Quoted 3 lines

Thanks,
Tomasz