Skip to content

Commit af8f0b8

Browse files
jgunthorpewilldeacon
authored andcommitted
iommu/arm-smmu-v3: Consolidate clearing a CD table entry
A cleared entry is all 0's. Make arm_smmu_clear_cd() do this sequence. If we are clearing an entry and for some reason it is not already allocated in the CD table then something has gone wrong. Remove case (5) from arm_smmu_write_ctx_desc(). Tested-by: Nicolin Chen <[email protected]> Tested-by: Shameer Kolothum <[email protected]> Reviewed-by: Michael Shavit <[email protected]> Reviewed-by: Nicolin Chen <[email protected]> Reviewed-by: Moritz Fischer <[email protected]> Reviewed-by: Mostafa Saleh <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent e9d1e4f commit af8f0b8

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ void arm_smmu_sva_remove_dev_pasid(struct iommu_domain *domain,
569569

570570
mutex_lock(&sva_lock);
571571

572-
arm_smmu_write_ctx_desc(master, id, NULL);
572+
arm_smmu_clear_cd(master, id);
573573

574574
list_for_each_entry(t, &master->bonds, list) {
575575
if (t->mm == mm) {

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,19 @@ void arm_smmu_make_s1_cd(struct arm_smmu_cd *target,
13101310
target->data[3] = cpu_to_le64(cd->mair);
13111311
}
13121312

1313+
void arm_smmu_clear_cd(struct arm_smmu_master *master, ioasid_t ssid)
1314+
{
1315+
struct arm_smmu_cd target = {};
1316+
struct arm_smmu_cd *cdptr;
1317+
1318+
if (!master->cd_table.cdtab)
1319+
return;
1320+
cdptr = arm_smmu_get_cd_ptr(master, ssid);
1321+
if (WARN_ON(!cdptr))
1322+
return;
1323+
arm_smmu_write_cd_entry(master, ssid, cdptr, &target);
1324+
}
1325+
13131326
int arm_smmu_write_ctx_desc(struct arm_smmu_master *master, int ssid,
13141327
struct arm_smmu_ctx_desc *cd)
13151328
{
@@ -1320,7 +1333,6 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_master *master, int ssid,
13201333
* (2) Install a secondary CD, for SID+SSID traffic.
13211334
* (4) Quiesce the context without clearing the valid bit. Disable
13221335
* translation, and ignore any translation fault.
1323-
* (5) Remove a secondary CD.
13241336
*/
13251337
u64 val;
13261338
struct arm_smmu_cd target;
@@ -1339,10 +1351,7 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_master *master, int ssid,
13391351
target = *cd_table_entry;
13401352
val = le64_to_cpu(cdptr->data[0]);
13411353

1342-
if (!cd) { /* (5) */
1343-
memset(cdptr, 0, sizeof(*cdptr));
1344-
val = 0;
1345-
} else if (cd == &quiet_cd) { /* (4) */
1354+
if (cd == &quiet_cd) { /* (4) */
13461355
val &= ~(CTXDESC_CD_0_TCR_T0SZ | CTXDESC_CD_0_TCR_TG0 |
13471356
CTXDESC_CD_0_TCR_IRGN0 | CTXDESC_CD_0_TCR_ORGN0 |
13481357
CTXDESC_CD_0_TCR_SH0);
@@ -2674,9 +2683,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
26742683
case ARM_SMMU_DOMAIN_S2:
26752684
arm_smmu_make_s2_domain_ste(&target, master, smmu_domain);
26762685
arm_smmu_install_ste_for_dev(master, &target);
2677-
if (master->cd_table.cdtab)
2678-
arm_smmu_write_ctx_desc(master, IOMMU_NO_PASID,
2679-
NULL);
2686+
arm_smmu_clear_cd(master, IOMMU_NO_PASID);
26802687
break;
26812688
}
26822689

@@ -2724,8 +2731,7 @@ static int arm_smmu_attach_dev_ste(struct device *dev,
27242731
* arm_smmu_domain->devices to avoid races updating the same context
27252732
* descriptor from arm_smmu_share_asid().
27262733
*/
2727-
if (master->cd_table.cdtab)
2728-
arm_smmu_write_ctx_desc(master, IOMMU_NO_PASID, NULL);
2734+
arm_smmu_clear_cd(master, IOMMU_NO_PASID);
27292735
return 0;
27302736
}
27312737

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,7 @@ extern struct xarray arm_smmu_asid_xa;
751751
extern struct mutex arm_smmu_asid_lock;
752752
extern struct arm_smmu_ctx_desc quiet_cd;
753753

754+
void arm_smmu_clear_cd(struct arm_smmu_master *master, ioasid_t ssid);
754755
struct arm_smmu_cd *arm_smmu_get_cd_ptr(struct arm_smmu_master *master,
755756
u32 ssid);
756757
void arm_smmu_make_s1_cd(struct arm_smmu_cd *target,

0 commit comments

Comments
 (0)