Skip to content

Commit 987a878

Browse files
shavitmichaelwilldeacon
authored andcommitted
iommu/arm-smmu-v3: Move ctx_desc out of s1_cfg
arm_smmu_s1_cfg (and by extension arm_smmu_domain) owns both a CD table and the CD inserted into that table's non-pasid CD entry. This limits arm_smmu_domain's ability to represent non-pasid domains, where multiple domains need to be inserted into a common CD table. Rather than describing an STE entry (which may have multiple domains installed into it with PASID), a domain should describe a single CD entry instead. This is precisely the role of arm_smmu_ctx_desc. A subsequent commit will also move the CD table outside of arm_smmu_domain. Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Nicolin Chen <nicolinc@nvidia.com> Signed-off-by: Michael Shavit <mshavit@google.com> Tested-by: Nicolin Chen <nicolinc@nvidia.com> Link: https://lore.kernel.org/r/20230915211705.v8.1.I67ab103c18d882aedc8a08985af1fba70bca084e@changeid Signed-off-by: Will Deacon <will@kernel.org>
1 parent 70c6136 commit 987a878

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
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
@@ -62,7 +62,7 @@ arm_smmu_share_asid(struct mm_struct *mm, u16 asid)
6262
return cd;
6363
}
6464

65-
smmu_domain = container_of(cd, struct arm_smmu_domain, s1_cfg.cd);
65+
smmu_domain = container_of(cd, struct arm_smmu_domain, cd);
6666
smmu = smmu_domain->smmu;
6767

6868
ret = xa_alloc(&arm_smmu_asid_xa, &new_asid, cd,

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,7 +1869,7 @@ static void arm_smmu_tlb_inv_context(void *cookie)
18691869
* careful, 007.
18701870
*/
18711871
if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) {
1872-
arm_smmu_tlb_inv_asid(smmu, smmu_domain->s1_cfg.cd.asid);
1872+
arm_smmu_tlb_inv_asid(smmu, smmu_domain->cd.asid);
18731873
} else {
18741874
cmd.opcode = CMDQ_OP_TLBI_S12_VMALL;
18751875
cmd.tlbi.vmid = smmu_domain->s2_cfg.vmid;
@@ -1962,7 +1962,7 @@ static void arm_smmu_tlb_inv_range_domain(unsigned long iova, size_t size,
19621962
if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) {
19631963
cmd.opcode = smmu_domain->smmu->features & ARM_SMMU_FEAT_E2H ?
19641964
CMDQ_OP_TLBI_EL2_VA : CMDQ_OP_TLBI_NH_VA;
1965-
cmd.tlbi.asid = smmu_domain->s1_cfg.cd.asid;
1965+
cmd.tlbi.asid = smmu_domain->cd.asid;
19661966
} else {
19671967
cmd.opcode = CMDQ_OP_TLBI_S2_IPA;
19681968
cmd.tlbi.vmid = smmu_domain->s2_cfg.vmid;
@@ -2075,7 +2075,7 @@ static void arm_smmu_domain_free(struct iommu_domain *domain)
20752075
mutex_lock(&arm_smmu_asid_lock);
20762076
if (cfg->cdcfg.cdtab)
20772077
arm_smmu_free_cd_tables(smmu_domain);
2078-
arm_smmu_free_asid(&cfg->cd);
2078+
arm_smmu_free_asid(&smmu_domain->cd);
20792079
mutex_unlock(&arm_smmu_asid_lock);
20802080
} else {
20812081
struct arm_smmu_s2_cfg *cfg = &smmu_domain->s2_cfg;
@@ -2094,13 +2094,14 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain,
20942094
u32 asid;
20952095
struct arm_smmu_device *smmu = smmu_domain->smmu;
20962096
struct arm_smmu_s1_cfg *cfg = &smmu_domain->s1_cfg;
2097+
struct arm_smmu_ctx_desc *cd = &smmu_domain->cd;
20972098
typeof(&pgtbl_cfg->arm_lpae_s1_cfg.tcr) tcr = &pgtbl_cfg->arm_lpae_s1_cfg.tcr;
20982099

2099-
refcount_set(&cfg->cd.refs, 1);
2100+
refcount_set(&cd->refs, 1);
21002101

21012102
/* Prevent SVA from modifying the ASID until it is written to the CD */
21022103
mutex_lock(&arm_smmu_asid_lock);
2103-
ret = xa_alloc(&arm_smmu_asid_xa, &asid, &cfg->cd,
2104+
ret = xa_alloc(&arm_smmu_asid_xa, &asid, cd,
21042105
XA_LIMIT(1, (1 << smmu->asid_bits) - 1), GFP_KERNEL);
21052106
if (ret)
21062107
goto out_unlock;
@@ -2113,23 +2114,23 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain,
21132114
if (ret)
21142115
goto out_free_asid;
21152116

2116-
cfg->cd.asid = (u16)asid;
2117-
cfg->cd.ttbr = pgtbl_cfg->arm_lpae_s1_cfg.ttbr;
2118-
cfg->cd.tcr = FIELD_PREP(CTXDESC_CD_0_TCR_T0SZ, tcr->tsz) |
2117+
cd->asid = (u16)asid;
2118+
cd->ttbr = pgtbl_cfg->arm_lpae_s1_cfg.ttbr;
2119+
cd->tcr = FIELD_PREP(CTXDESC_CD_0_TCR_T0SZ, tcr->tsz) |
21192120
FIELD_PREP(CTXDESC_CD_0_TCR_TG0, tcr->tg) |
21202121
FIELD_PREP(CTXDESC_CD_0_TCR_IRGN0, tcr->irgn) |
21212122
FIELD_PREP(CTXDESC_CD_0_TCR_ORGN0, tcr->orgn) |
21222123
FIELD_PREP(CTXDESC_CD_0_TCR_SH0, tcr->sh) |
21232124
FIELD_PREP(CTXDESC_CD_0_TCR_IPS, tcr->ips) |
21242125
CTXDESC_CD_0_TCR_EPD1 | CTXDESC_CD_0_AA64;
2125-
cfg->cd.mair = pgtbl_cfg->arm_lpae_s1_cfg.mair;
2126+
cd->mair = pgtbl_cfg->arm_lpae_s1_cfg.mair;
21262127

21272128
/*
21282129
* Note that this will end up calling arm_smmu_sync_cd() before
21292130
* the master has been added to the devices list for this domain.
21302131
* This isn't an issue because the STE hasn't been installed yet.
21312132
*/
2132-
ret = arm_smmu_write_ctx_desc(smmu_domain, IOMMU_NO_PASID, &cfg->cd);
2133+
ret = arm_smmu_write_ctx_desc(smmu_domain, IOMMU_NO_PASID, cd);
21332134
if (ret)
21342135
goto out_free_cd_tables;
21352136

@@ -2139,7 +2140,7 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain,
21392140
out_free_cd_tables:
21402141
arm_smmu_free_cd_tables(smmu_domain);
21412142
out_free_asid:
2142-
arm_smmu_free_asid(&cfg->cd);
2143+
arm_smmu_free_asid(cd);
21432144
out_unlock:
21442145
mutex_unlock(&arm_smmu_asid_lock);
21452146
return ret;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,6 @@ struct arm_smmu_ctx_desc_cfg {
599599

600600
struct arm_smmu_s1_cfg {
601601
struct arm_smmu_ctx_desc_cfg cdcfg;
602-
struct arm_smmu_ctx_desc cd;
603602
u8 s1fmt;
604603
u8 s1cdmax;
605604
};
@@ -724,7 +723,10 @@ struct arm_smmu_domain {
724723

725724
enum arm_smmu_domain_stage stage;
726725
union {
727-
struct arm_smmu_s1_cfg s1_cfg;
726+
struct {
727+
struct arm_smmu_ctx_desc cd;
728+
struct arm_smmu_s1_cfg s1_cfg;
729+
};
728730
struct arm_smmu_s2_cfg s2_cfg;
729731
};
730732

0 commit comments

Comments
 (0)