* [PATCH v1 1/7] iommu/arm-smmu-v3: Move ctx_desc out of s1_cfg
2023-07-27 18:26 [PATCH v1 0/7] Refactor the SMMU's CD table ownership Michael Shavit
@ 2023-07-27 18:26 ` Michael Shavit
2023-07-27 18:45 ` Jason Gunthorpe
2023-07-27 18:26 ` [PATCH v1 2/7] iommu/arm-smmu-v3: Replace s1_cfg with ctx_desc_cfg Michael Shavit
` (6 subsequent siblings)
7 siblings, 1 reply; 26+ messages in thread
From: Michael Shavit @ 2023-07-27 18:26 UTC (permalink / raw)
To: Will Deacon, Robin Murphy, Joerg Roedel
Cc: Michael Shavit, jean-philippe, nicolinc, jgg, baolu.lu,
linux-arm-kernel, iommu, linux-kernel
s1_cfg describes the CD table that is inserted into an SMMU's STEs. It's
weird for s1_cfg to also own ctx_desc which describes a CD that is
inserted into that table. It is more appropriate for arm_smmu_domain to
own ctx_desc.
Signed-off-by: Michael Shavit <mshavit@google.com>
---
.../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 2 +-
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 23 +++++++--------
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 28 ++++++++++---------
3 files changed, 28 insertions(+), 25 deletions(-)
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c
index a5a63b1c947eb..968559d625c40 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c
@@ -62,7 +62,7 @@ arm_smmu_share_asid(struct mm_struct *mm, u16 asid)
return cd;
}
- smmu_domain = container_of(cd, struct arm_smmu_domain, s1_cfg.cd);
+ smmu_domain = container_of(cd, struct arm_smmu_domain, cd);
smmu = smmu_domain->smmu;
ret = xa_alloc(&arm_smmu_asid_xa, &new_asid, cd,
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
index 9b0dc35056019..bb277ff86f65f 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -1869,7 +1869,7 @@ static void arm_smmu_tlb_inv_context(void *cookie)
* careful, 007.
*/
if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) {
- arm_smmu_tlb_inv_asid(smmu, smmu_domain->s1_cfg.cd.asid);
+ arm_smmu_tlb_inv_asid(smmu, smmu_domain->cd.asid);
} else {
cmd.opcode = CMDQ_OP_TLBI_S12_VMALL;
cmd.tlbi.vmid = smmu_domain->s2_cfg.vmid;
@@ -1957,7 +1957,7 @@ static void arm_smmu_tlb_inv_range_domain(unsigned long iova, size_t size,
if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) {
cmd.opcode = smmu_domain->smmu->features & ARM_SMMU_FEAT_E2H ?
CMDQ_OP_TLBI_EL2_VA : CMDQ_OP_TLBI_NH_VA;
- cmd.tlbi.asid = smmu_domain->s1_cfg.cd.asid;
+ cmd.tlbi.asid = smmu_domain->cd.asid;
} else {
cmd.opcode = CMDQ_OP_TLBI_S2_IPA;
cmd.tlbi.vmid = smmu_domain->s2_cfg.vmid;
@@ -2088,7 +2088,7 @@ static void arm_smmu_domain_free(struct iommu_domain *domain)
mutex_lock(&arm_smmu_asid_lock);
if (cfg->cdcfg.cdtab)
arm_smmu_free_cd_tables(smmu_domain);
- arm_smmu_free_asid(&cfg->cd);
+ arm_smmu_free_asid(&smmu_domain->cd);
mutex_unlock(&arm_smmu_asid_lock);
} else {
struct arm_smmu_s2_cfg *cfg = &smmu_domain->s2_cfg;
@@ -2107,13 +2107,14 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain,
u32 asid;
struct arm_smmu_device *smmu = smmu_domain->smmu;
struct arm_smmu_s1_cfg *cfg = &smmu_domain->s1_cfg;
+ struct arm_smmu_ctx_desc *cd = &smmu_domain->cd;
typeof(&pgtbl_cfg->arm_lpae_s1_cfg.tcr) tcr = &pgtbl_cfg->arm_lpae_s1_cfg.tcr;
- refcount_set(&cfg->cd.refs, 1);
+ refcount_set(&cd->refs, 1);
/* Prevent SVA from modifying the ASID until it is written to the CD */
mutex_lock(&arm_smmu_asid_lock);
- ret = xa_alloc(&arm_smmu_asid_xa, &asid, &cfg->cd,
+ ret = xa_alloc(&arm_smmu_asid_xa, &asid, cd,
XA_LIMIT(1, (1 << smmu->asid_bits) - 1), GFP_KERNEL);
if (ret)
goto out_unlock;
@@ -2126,23 +2127,23 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain,
if (ret)
goto out_free_asid;
- cfg->cd.asid = (u16)asid;
- cfg->cd.ttbr = pgtbl_cfg->arm_lpae_s1_cfg.ttbr;
- cfg->cd.tcr = FIELD_PREP(CTXDESC_CD_0_TCR_T0SZ, tcr->tsz) |
+ cd->asid = (u16)asid;
+ cd->ttbr = pgtbl_cfg->arm_lpae_s1_cfg.ttbr;
+ cd->tcr = FIELD_PREP(CTXDESC_CD_0_TCR_T0SZ, tcr->tsz) |
FIELD_PREP(CTXDESC_CD_0_TCR_TG0, tcr->tg) |
FIELD_PREP(CTXDESC_CD_0_TCR_IRGN0, tcr->irgn) |
FIELD_PREP(CTXDESC_CD_0_TCR_ORGN0, tcr->orgn) |
FIELD_PREP(CTXDESC_CD_0_TCR_SH0, tcr->sh) |
FIELD_PREP(CTXDESC_CD_0_TCR_IPS, tcr->ips) |
CTXDESC_CD_0_TCR_EPD1 | CTXDESC_CD_0_AA64;
- cfg->cd.mair = pgtbl_cfg->arm_lpae_s1_cfg.mair;
+ cd->mair = pgtbl_cfg->arm_lpae_s1_cfg.mair;
/*
* Note that this will end up calling arm_smmu_sync_cd() before
* the master has been added to the devices list for this domain.
* This isn't an issue because the STE hasn't been installed yet.
*/
- ret = arm_smmu_write_ctx_desc(smmu_domain, 0, &cfg->cd);
+ ret = arm_smmu_write_ctx_desc(smmu_domain, 0, cd);
if (ret)
goto out_free_cd_tables;
@@ -2152,7 +2153,7 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain,
out_free_cd_tables:
arm_smmu_free_cd_tables(smmu_domain);
out_free_asid:
- arm_smmu_free_asid(&cfg->cd);
+ arm_smmu_free_asid(cd);
out_unlock:
mutex_unlock(&arm_smmu_asid_lock);
return ret;
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
index dcab85698a4e2..5347be54584bc 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
@@ -599,7 +599,6 @@ struct arm_smmu_ctx_desc_cfg {
struct arm_smmu_s1_cfg {
struct arm_smmu_ctx_desc_cfg cdcfg;
- struct arm_smmu_ctx_desc cd;
u8 s1fmt;
u8 s1cdmax;
};
@@ -715,25 +714,28 @@ enum arm_smmu_domain_stage {
};
struct arm_smmu_domain {
- struct arm_smmu_device *smmu;
- struct mutex init_mutex; /* Protects smmu pointer */
+ struct arm_smmu_device *smmu;
+ struct mutex init_mutex; /* Protects smmu pointer */
- struct io_pgtable_ops *pgtbl_ops;
- bool stall_enabled;
- atomic_t nr_ats_masters;
+ struct io_pgtable_ops *pgtbl_ops;
+ bool stall_enabled;
+ atomic_t nr_ats_masters;
- enum arm_smmu_domain_stage stage;
+ enum arm_smmu_domain_stage stage;
union {
- struct arm_smmu_s1_cfg s1_cfg;
- struct arm_smmu_s2_cfg s2_cfg;
+ struct {
+ struct arm_smmu_ctx_desc cd;
+ struct arm_smmu_s1_cfg s1_cfg;
+ };
+ struct arm_smmu_s2_cfg s2_cfg;
};
- struct iommu_domain domain;
+ struct iommu_domain domain;
- struct list_head devices;
- spinlock_t devices_lock;
+ struct list_head devices;
+ spinlock_t devices_lock;
- struct list_head mmu_notifiers;
+ struct list_head mmu_notifiers;
};
static inline struct arm_smmu_domain *to_smmu_domain(struct iommu_domain *dom)
--
2.41.0.585.gd2178a4bd4-goog
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 26+ messages in thread* Re: [PATCH v1 1/7] iommu/arm-smmu-v3: Move ctx_desc out of s1_cfg
2023-07-27 18:26 ` [PATCH v1 1/7] iommu/arm-smmu-v3: Move ctx_desc out of s1_cfg Michael Shavit
@ 2023-07-27 18:45 ` Jason Gunthorpe
0 siblings, 0 replies; 26+ messages in thread
From: Jason Gunthorpe @ 2023-07-27 18:45 UTC (permalink / raw)
To: Michael Shavit
Cc: Will Deacon, Robin Murphy, Joerg Roedel, jean-philippe, nicolinc,
baolu.lu, linux-arm-kernel, iommu, linux-kernel
On Fri, Jul 28, 2023 at 02:26:17AM +0800, Michael Shavit wrote:
> @@ -715,25 +714,28 @@ enum arm_smmu_domain_stage {
> };
>
> struct arm_smmu_domain {
> - struct arm_smmu_device *smmu;
> - struct mutex init_mutex; /* Protects smmu pointer */
> + struct arm_smmu_device *smmu;
> + struct mutex init_mutex; /* Protects smmu pointer */
>
> - struct io_pgtable_ops *pgtbl_ops;
> - bool stall_enabled;
> - atomic_t nr_ats_masters;
> + struct io_pgtable_ops *pgtbl_ops;
> + bool stall_enabled;
> + atomic_t nr_ats_masters;
>
> - enum arm_smmu_domain_stage stage;
> + enum arm_smmu_domain_stage stage;
> union {
> - struct arm_smmu_s1_cfg s1_cfg;
> - struct arm_smmu_s2_cfg s2_cfg;
> + struct {
> + struct arm_smmu_ctx_desc cd;
> + struct arm_smmu_s1_cfg s1_cfg;
> + };
> + struct arm_smmu_s2_cfg s2_cfg;
> };
>
> - struct iommu_domain domain;
> + struct iommu_domain domain;
>
> - struct list_head devices;
> - spinlock_t devices_lock;
> + struct list_head devices;
> + spinlock_t devices_lock;
>
> - struct list_head mmu_notifiers;
> + struct list_head mmu_notifiers;
> };
Don't re-indent a whole struct just to get column alignment. Do
a few lines around where you are touching.
This is also why I quite dislike column alignment, aside from being
unreadable, it harms readability of diffs and increases maintenance
costs.
Jason
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v1 2/7] iommu/arm-smmu-v3: Replace s1_cfg with ctx_desc_cfg
2023-07-27 18:26 [PATCH v1 0/7] Refactor the SMMU's CD table ownership Michael Shavit
2023-07-27 18:26 ` [PATCH v1 1/7] iommu/arm-smmu-v3: Move ctx_desc out of s1_cfg Michael Shavit
@ 2023-07-27 18:26 ` Michael Shavit
2023-07-27 20:57 ` Nicolin Chen
2023-07-27 18:26 ` [PATCH v1 3/7] iommu/arm-smmu-v3: Encapsulate ctx_desc_cfg init in alloc_cd_tables Michael Shavit
` (5 subsequent siblings)
7 siblings, 1 reply; 26+ messages in thread
From: Michael Shavit @ 2023-07-27 18:26 UTC (permalink / raw)
To: Will Deacon, Robin Murphy, Joerg Roedel
Cc: Michael Shavit, jean-philippe, nicolinc, jgg, baolu.lu,
linux-arm-kernel, iommu, linux-kernel
Remove or move s1_cfg fields that are redundant with those found in
arm_smmu_ctx_desc_cfg. The arm_smmu_ctx_desc_cfg member is named
cd_table to make it more obvious that it represents a cd table.
Signed-off-by: Michael Shavit <mshavit@google.com>
---
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 45 +++++++++++----------
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 10 ++---
2 files changed, 26 insertions(+), 29 deletions(-)
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
index bb277ff86f65f..8cf4987dd9ec7 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -1033,9 +1033,9 @@ static __le64 *arm_smmu_get_cd_ptr(struct arm_smmu_domain *smmu_domain,
unsigned int idx;
struct arm_smmu_l1_ctx_desc *l1_desc;
struct arm_smmu_device *smmu = smmu_domain->smmu;
- struct arm_smmu_ctx_desc_cfg *cdcfg = &smmu_domain->s1_cfg.cdcfg;
+ struct arm_smmu_ctx_desc_cfg *cdcfg = &smmu_domain->cd_table;
- if (smmu_domain->s1_cfg.s1fmt == STRTAB_STE_0_S1FMT_LINEAR)
+ if (!cdcfg->l1_desc)
return cdcfg->cdtab + ssid * CTXDESC_CD_DWORDS;
idx = ssid >> CTXDESC_SPLIT;
@@ -1071,7 +1071,7 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_domain *smmu_domain, int ssid,
bool cd_live;
__le64 *cdptr;
- if (WARN_ON(ssid >= (1 << smmu_domain->s1_cfg.s1cdmax)))
+ if (WARN_ON(ssid >= (1 << smmu_domain->cd_table.max_cds_bits)))
return -E2BIG;
cdptr = arm_smmu_get_cd_ptr(smmu_domain, ssid);
@@ -1138,19 +1138,16 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_domain *smmu_domain)
size_t l1size;
size_t max_contexts;
struct arm_smmu_device *smmu = smmu_domain->smmu;
- struct arm_smmu_s1_cfg *cfg = &smmu_domain->s1_cfg;
- struct arm_smmu_ctx_desc_cfg *cdcfg = &cfg->cdcfg;
+ struct arm_smmu_ctx_desc_cfg *cdcfg = &smmu_domain->cd_table;
- max_contexts = 1 << cfg->s1cdmax;
+ max_contexts = 1 << cdcfg->max_cds_bits;
if (!(smmu->features & ARM_SMMU_FEAT_2_LVL_CDTAB) ||
max_contexts <= CTXDESC_L2_ENTRIES) {
- cfg->s1fmt = STRTAB_STE_0_S1FMT_LINEAR;
cdcfg->num_l1_ents = max_contexts;
l1size = max_contexts * (CTXDESC_CD_DWORDS << 3);
} else {
- cfg->s1fmt = STRTAB_STE_0_S1FMT_64K_L2;
cdcfg->num_l1_ents = DIV_ROUND_UP(max_contexts,
CTXDESC_L2_ENTRIES);
@@ -1186,7 +1183,7 @@ static void arm_smmu_free_cd_tables(struct arm_smmu_domain *smmu_domain)
int i;
size_t size, l1size;
struct arm_smmu_device *smmu = smmu_domain->smmu;
- struct arm_smmu_ctx_desc_cfg *cdcfg = &smmu_domain->s1_cfg.cdcfg;
+ struct arm_smmu_ctx_desc_cfg *cdcfg = &smmu_domain->cd_table;
if (cdcfg->l1_desc) {
size = CTXDESC_L2_ENTRIES * (CTXDESC_CD_DWORDS << 3);
@@ -1276,7 +1273,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid,
u64 val = le64_to_cpu(dst[0]);
bool ste_live = false;
struct arm_smmu_device *smmu = NULL;
- struct arm_smmu_s1_cfg *s1_cfg = NULL;
+ struct arm_smmu_ctx_desc_cfg *cd_table = NULL;
struct arm_smmu_s2_cfg *s2_cfg = NULL;
struct arm_smmu_domain *smmu_domain = NULL;
struct arm_smmu_cmdq_ent prefetch_cmd = {
@@ -1294,7 +1291,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid,
if (smmu_domain) {
switch (smmu_domain->stage) {
case ARM_SMMU_DOMAIN_S1:
- s1_cfg = &smmu_domain->s1_cfg;
+ cd_table = &smmu_domain->cd_table;
break;
case ARM_SMMU_DOMAIN_S2:
case ARM_SMMU_DOMAIN_NESTED:
@@ -1325,7 +1322,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid,
val = STRTAB_STE_0_V;
/* Bypass/fault */
- if (!smmu_domain || !(s1_cfg || s2_cfg)) {
+ if (!smmu_domain || !(cd_table || s2_cfg)) {
if (!smmu_domain && disable_bypass)
val |= FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_ABORT);
else
@@ -1344,7 +1341,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid,
return;
}
- if (s1_cfg) {
+ if (cd_table) {
u64 strw = smmu->features & ARM_SMMU_FEAT_E2H ?
STRTAB_STE_1_STRW_EL2 : STRTAB_STE_1_STRW_NSEL1;
@@ -1360,10 +1357,14 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid,
!master->stall_enabled)
dst[1] |= cpu_to_le64(STRTAB_STE_1_S1STALLD);
- val |= (s1_cfg->cdcfg.cdtab_dma & STRTAB_STE_0_S1CTXPTR_MASK) |
- FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S1_TRANS) |
- FIELD_PREP(STRTAB_STE_0_S1CDMAX, s1_cfg->s1cdmax) |
- FIELD_PREP(STRTAB_STE_0_S1FMT, s1_cfg->s1fmt);
+ val |= (cd_table->cdtab_dma & STRTAB_STE_0_S1CTXPTR_MASK) |
+ FIELD_PREP(STRTAB_STE_0_CFG, STRTAB_STE_0_CFG_S1_TRANS) |
+ FIELD_PREP(STRTAB_STE_0_S1CDMAX,
+ cd_table->max_cds_bits) |
+ FIELD_PREP(STRTAB_STE_0_S1FMT,
+ cd_table->l1_desc ?
+ STRTAB_STE_0_S1FMT_64K_L2 :
+ STRTAB_STE_0_S1FMT_LINEAR);
}
if (s2_cfg) {
@@ -2082,11 +2083,11 @@ static void arm_smmu_domain_free(struct iommu_domain *domain)
/* Free the CD and ASID, if we allocated them */
if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) {
- struct arm_smmu_s1_cfg *cfg = &smmu_domain->s1_cfg;
+ struct arm_smmu_ctx_desc_cfg *cdcfg = &smmu_domain->cd_table;
/* Prevent SVA from touching the CD while we're freeing it */
mutex_lock(&arm_smmu_asid_lock);
- if (cfg->cdcfg.cdtab)
+ if (cdcfg->cdtab)
arm_smmu_free_cd_tables(smmu_domain);
arm_smmu_free_asid(&smmu_domain->cd);
mutex_unlock(&arm_smmu_asid_lock);
@@ -2106,7 +2107,7 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain,
int ret;
u32 asid;
struct arm_smmu_device *smmu = smmu_domain->smmu;
- struct arm_smmu_s1_cfg *cfg = &smmu_domain->s1_cfg;
+ struct arm_smmu_ctx_desc_cfg *cdcfg = &smmu_domain->cd_table;
struct arm_smmu_ctx_desc *cd = &smmu_domain->cd;
typeof(&pgtbl_cfg->arm_lpae_s1_cfg.tcr) tcr = &pgtbl_cfg->arm_lpae_s1_cfg.tcr;
@@ -2119,7 +2120,7 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain,
if (ret)
goto out_unlock;
- cfg->s1cdmax = master->ssid_bits;
+ cdcfg->max_cds_bits = master->ssid_bits;
smmu_domain->stall_enabled = master->stall_enabled;
@@ -2457,7 +2458,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
ret = -EINVAL;
goto out_unlock;
} else if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1 &&
- master->ssid_bits != smmu_domain->s1_cfg.s1cdmax) {
+ master->ssid_bits != smmu_domain->cd_table.max_cds_bits) {
ret = -EINVAL;
goto out_unlock;
} else if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1 &&
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
index 5347be54584bc..006a724ee9230 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
@@ -595,12 +595,8 @@ struct arm_smmu_ctx_desc_cfg {
dma_addr_t cdtab_dma;
struct arm_smmu_l1_ctx_desc *l1_desc;
unsigned int num_l1_ents;
-};
-
-struct arm_smmu_s1_cfg {
- struct arm_smmu_ctx_desc_cfg cdcfg;
- u8 s1fmt;
- u8 s1cdmax;
+ /* log2 of the maximum number of CDs supported by this table */
+ u8 max_cds_bits;
};
struct arm_smmu_s2_cfg {
@@ -725,7 +721,7 @@ struct arm_smmu_domain {
union {
struct {
struct arm_smmu_ctx_desc cd;
- struct arm_smmu_s1_cfg s1_cfg;
+ struct arm_smmu_ctx_desc_cfg cd_table;
};
struct arm_smmu_s2_cfg s2_cfg;
};
--
2.41.0.585.gd2178a4bd4-goog
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 26+ messages in thread* Re: [PATCH v1 2/7] iommu/arm-smmu-v3: Replace s1_cfg with ctx_desc_cfg
2023-07-27 18:26 ` [PATCH v1 2/7] iommu/arm-smmu-v3: Replace s1_cfg with ctx_desc_cfg Michael Shavit
@ 2023-07-27 20:57 ` Nicolin Chen
2023-07-28 7:47 ` Michael Shavit
0 siblings, 1 reply; 26+ messages in thread
From: Nicolin Chen @ 2023-07-27 20:57 UTC (permalink / raw)
To: Michael Shavit
Cc: Will Deacon, Robin Murphy, Joerg Roedel, jean-philippe, jgg,
baolu.lu, linux-arm-kernel, iommu, linux-kernel
On Fri, Jul 28, 2023 at 02:26:18AM +0800, Michael Shavit wrote:
> Remove or move s1_cfg fields that are redundant with those found in
> arm_smmu_ctx_desc_cfg. The arm_smmu_ctx_desc_cfg member is named
> cd_table to make it more obvious that it represents a cd table.
Though the "cd_table" is clear, it doesn't feel very obvious to me
that "struct arm_smmu_ctx_desc_cfg" means CD table, so a mismatch
with "cd_table". How about renaming to "struct arm_smmu_cdtab_cfg",
similar to "struct arm_smmu_strtab_cfg"?
> Signed-off-by: Michael Shavit <mshavit@google.com>
> ---
> drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 45 +++++++++++----------
> drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 10 ++---
> 2 files changed, 26 insertions(+), 29 deletions(-)
>
> diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> index bb277ff86f65f..8cf4987dd9ec7 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> @@ -1033,9 +1033,9 @@ static __le64 *arm_smmu_get_cd_ptr(struct arm_smmu_domain *smmu_domain,
> unsigned int idx;
> struct arm_smmu_l1_ctx_desc *l1_desc;
> struct arm_smmu_device *smmu = smmu_domain->smmu;
> - struct arm_smmu_ctx_desc_cfg *cdcfg = &smmu_domain->s1_cfg.cdcfg;
> + struct arm_smmu_ctx_desc_cfg *cdcfg = &smmu_domain->cd_table;
[<<<]
> @@ -1276,7 +1273,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid,
> u64 val = le64_to_cpu(dst[0]);
> bool ste_live = false;
> struct arm_smmu_device *smmu = NULL;
> - struct arm_smmu_s1_cfg *s1_cfg = NULL;
> + struct arm_smmu_ctx_desc_cfg *cd_table = NULL;
[>>>]
It'd be nicer to align all the variables to "cd_table" like the
2nd piece here. And if we rename the struct name too:
struct arm_smmu_cdtab_cfg *cd_table = xxxx;
> -struct arm_smmu_s1_cfg {
> - struct arm_smmu_ctx_desc_cfg cdcfg;
> - u8 s1fmt;
> - u8 s1cdmax;
> + /* log2 of the maximum number of CDs supported by this table */
> + u8 max_cds_bits;
Though "s1fmt" is redundant, "max_cds_bits" doesn't seem to be.
It'd be nicer to separate them in the commit message to why we
remove s1fmt and why we rename s1cdmax.
Thanks
Nicolin
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 26+ messages in thread* Re: [PATCH v1 2/7] iommu/arm-smmu-v3: Replace s1_cfg with ctx_desc_cfg
2023-07-27 20:57 ` Nicolin Chen
@ 2023-07-28 7:47 ` Michael Shavit
2023-07-28 12:22 ` Jason Gunthorpe
0 siblings, 1 reply; 26+ messages in thread
From: Michael Shavit @ 2023-07-28 7:47 UTC (permalink / raw)
To: Nicolin Chen
Cc: Will Deacon, Robin Murphy, Joerg Roedel, jean-philippe, jgg,
baolu.lu, linux-arm-kernel, iommu, linux-kernel
On Fri, Jul 28, 2023 at 4:57 AM Nicolin Chen <nicolinc@nvidia.com> wrote:
> It'd be nicer to align all the variables to "cd_table" like the
> 2nd piece here. And if we rename the struct name too:
>
> struct arm_smmu_cdtab_cfg *cd_table = xxxx;
I agree that renaming these would be nice. There's 36 usages of cdcfg
in arm-smmu-v3.c, and 6 usages of arm_smmu_ctx_desc_cfg.
I can rename the struct since we'll be touching many of those in this
patch anyways, but I'm a bit concerned of the churn from updating all
the cdcfg usages.
> Though "s1fmt" is redundant, "max_cds_bits" doesn't seem to be.
>
> It'd be nicer to separate them in the commit message to why we
> remove s1fmt and why we rename s1cdmax.
Will fix!
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v1 2/7] iommu/arm-smmu-v3: Replace s1_cfg with ctx_desc_cfg
2023-07-28 7:47 ` Michael Shavit
@ 2023-07-28 12:22 ` Jason Gunthorpe
2023-07-28 18:41 ` Nicolin Chen
0 siblings, 1 reply; 26+ messages in thread
From: Jason Gunthorpe @ 2023-07-28 12:22 UTC (permalink / raw)
To: Michael Shavit
Cc: Nicolin Chen, Will Deacon, Robin Murphy, Joerg Roedel,
jean-philippe, baolu.lu, linux-arm-kernel, iommu, linux-kernel
On Fri, Jul 28, 2023 at 03:47:45PM +0800, Michael Shavit wrote:
> On Fri, Jul 28, 2023 at 4:57 AM Nicolin Chen <nicolinc@nvidia.com> wrote:
>
> > It'd be nicer to align all the variables to "cd_table" like the
> > 2nd piece here. And if we rename the struct name too:
> >
> > struct arm_smmu_cdtab_cfg *cd_table = xxxx;
>
> I agree that renaming these would be nice. There's 36 usages of cdcfg
> in arm-smmu-v3.c, and 6 usages of arm_smmu_ctx_desc_cfg.
> I can rename the struct since we'll be touching many of those in this
> patch anyways, but I'm a bit concerned of the churn from updating all
> the cdcfg usages.
Will was not keen on churn for clarity so it seem better to be
thoughtful about what is touched to get this merged.
Jason
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v1 2/7] iommu/arm-smmu-v3: Replace s1_cfg with ctx_desc_cfg
2023-07-28 12:22 ` Jason Gunthorpe
@ 2023-07-28 18:41 ` Nicolin Chen
2023-07-28 18:54 ` Jason Gunthorpe
0 siblings, 1 reply; 26+ messages in thread
From: Nicolin Chen @ 2023-07-28 18:41 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: Michael Shavit, Will Deacon, Robin Murphy, Joerg Roedel,
jean-philippe, baolu.lu, linux-arm-kernel, iommu, linux-kernel
On Fri, Jul 28, 2023 at 09:22:52AM -0300, Jason Gunthorpe wrote:
> On Fri, Jul 28, 2023 at 03:47:45PM +0800, Michael Shavit wrote:
> > On Fri, Jul 28, 2023 at 4:57 AM Nicolin Chen <nicolinc@nvidia.com> wrote:
> >
> > > It'd be nicer to align all the variables to "cd_table" like the
> > > 2nd piece here. And if we rename the struct name too:
> > >
> > > struct arm_smmu_cdtab_cfg *cd_table = xxxx;
> >
> > I agree that renaming these would be nice. There's 36 usages of cdcfg
> > in arm-smmu-v3.c, and 6 usages of arm_smmu_ctx_desc_cfg.
> > I can rename the struct since we'll be touching many of those in this
> > patch anyways, but I'm a bit concerned of the churn from updating all
> > the cdcfg usages.
>
> Will was not keen on churn for clarity so it seem better to be
> thoughtful about what is touched to get this merged.
Still, it would be odd to have "cdcfg" and "cd_table" at the same
time. If we have to be conservative, perhaps we should just align
with the old naming: "struct arm_smmu_ctx_desc_cfg *cdcfg;"...
Nicolin
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v1 2/7] iommu/arm-smmu-v3: Replace s1_cfg with ctx_desc_cfg
2023-07-28 18:41 ` Nicolin Chen
@ 2023-07-28 18:54 ` Jason Gunthorpe
2023-07-30 11:24 ` Michael Shavit
0 siblings, 1 reply; 26+ messages in thread
From: Jason Gunthorpe @ 2023-07-28 18:54 UTC (permalink / raw)
To: Nicolin Chen
Cc: Michael Shavit, Will Deacon, Robin Murphy, Joerg Roedel,
jean-philippe, baolu.lu, linux-arm-kernel, iommu, linux-kernel
On Fri, Jul 28, 2023 at 11:41:26AM -0700, Nicolin Chen wrote:
> On Fri, Jul 28, 2023 at 09:22:52AM -0300, Jason Gunthorpe wrote:
> > On Fri, Jul 28, 2023 at 03:47:45PM +0800, Michael Shavit wrote:
> > > On Fri, Jul 28, 2023 at 4:57 AM Nicolin Chen <nicolinc@nvidia.com> wrote:
> > >
> > > > It'd be nicer to align all the variables to "cd_table" like the
> > > > 2nd piece here. And if we rename the struct name too:
> > > >
> > > > struct arm_smmu_cdtab_cfg *cd_table = xxxx;
> > >
> > > I agree that renaming these would be nice. There's 36 usages of cdcfg
> > > in arm-smmu-v3.c, and 6 usages of arm_smmu_ctx_desc_cfg.
> > > I can rename the struct since we'll be touching many of those in this
> > > patch anyways, but I'm a bit concerned of the churn from updating all
> > > the cdcfg usages.
> >
> > Will was not keen on churn for clarity so it seem better to be
> > thoughtful about what is touched to get this merged.
>
> Still, it would be odd to have "cdcfg" and "cd_table" at the same
> time. If we have to be conservative, perhaps we should just align
> with the old naming: "struct arm_smmu_ctx_desc_cfg *cdcfg;"...
Yeah, I think changing to cd_table in the places touched makes alot of
sense
Jason
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v1 2/7] iommu/arm-smmu-v3: Replace s1_cfg with ctx_desc_cfg
2023-07-28 18:54 ` Jason Gunthorpe
@ 2023-07-30 11:24 ` Michael Shavit
2023-07-30 23:05 ` Jason Gunthorpe
0 siblings, 1 reply; 26+ messages in thread
From: Michael Shavit @ 2023-07-30 11:24 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: Nicolin Chen, Will Deacon, Robin Murphy, Joerg Roedel,
jean-philippe, baolu.lu, linux-arm-kernel, iommu, linux-kernel
On Sat, Jul 29, 2023 at 2:54 AM Jason Gunthorpe <jgg@nvidia.com> wrote:
> > Still, it would be odd to have "cdcfg" and "cd_table" at the same
> > time. If we have to be conservative, perhaps we should just align
> > with the old naming: "struct arm_smmu_ctx_desc_cfg *cdcfg;"...
>
> Yeah, I think changing to cd_table in the places touched makes alot of
> sense
A bit confused by the "Yeah" reply given the quote... Are we ok
keeping the v1 version of this patch w.r.t. to cd_table/cdcfg and
struct naming?
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v1 2/7] iommu/arm-smmu-v3: Replace s1_cfg with ctx_desc_cfg
2023-07-30 11:24 ` Michael Shavit
@ 2023-07-30 23:05 ` Jason Gunthorpe
0 siblings, 0 replies; 26+ messages in thread
From: Jason Gunthorpe @ 2023-07-30 23:05 UTC (permalink / raw)
To: Michael Shavit
Cc: Nicolin Chen, Will Deacon, Robin Murphy, Joerg Roedel,
jean-philippe, baolu.lu, linux-arm-kernel, iommu, linux-kernel
On Sun, Jul 30, 2023 at 07:24:28PM +0800, Michael Shavit wrote:
> On Sat, Jul 29, 2023 at 2:54 AM Jason Gunthorpe <jgg@nvidia.com> wrote:
> > > Still, it would be odd to have "cdcfg" and "cd_table" at the same
> > > time. If we have to be conservative, perhaps we should just align
> > > with the old naming: "struct arm_smmu_ctx_desc_cfg *cdcfg;"...
> >
> > Yeah, I think changing to cd_table in the places touched makes alot of
> > sense
>
> A bit confused by the "Yeah" reply given the quote... Are we ok
> keeping the v1 version of this patch w.r.t. to cd_table/cdcfg and
> struct naming?
I think you should optimistically use the name "cd_table" in any place
you touch. Leave cdcfg as is if you don't touch it. Consider a final
patch at the end to fix the cdcfgs, and see if Willy agrees.
Jason
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v1 3/7] iommu/arm-smmu-v3: Encapsulate ctx_desc_cfg init in alloc_cd_tables
2023-07-27 18:26 [PATCH v1 0/7] Refactor the SMMU's CD table ownership Michael Shavit
2023-07-27 18:26 ` [PATCH v1 1/7] iommu/arm-smmu-v3: Move ctx_desc out of s1_cfg Michael Shavit
2023-07-27 18:26 ` [PATCH v1 2/7] iommu/arm-smmu-v3: Replace s1_cfg with ctx_desc_cfg Michael Shavit
@ 2023-07-27 18:26 ` Michael Shavit
2023-07-27 18:26 ` [PATCH v1 4/7] iommu/arm-smmu-v3: move stall_enabled to the cd table Michael Shavit
` (4 subsequent siblings)
7 siblings, 0 replies; 26+ messages in thread
From: Michael Shavit @ 2023-07-27 18:26 UTC (permalink / raw)
To: Will Deacon, Robin Murphy, Joerg Roedel
Cc: Michael Shavit, jean-philippe, nicolinc, jgg, baolu.lu,
linux-arm-kernel, iommu, linux-kernel
This is slighlty cleaner: arm_smmu_ctx_desc_cfg is initialized in a
single function instead of having pieces set ahead-of time by its caller.
Signed-off-by: Michael Shavit <mshavit@google.com>
---
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
index 8cf4987dd9ec7..8a286e3838d70 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -1132,7 +1132,8 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_domain *smmu_domain, int ssid,
return 0;
}
-static int arm_smmu_alloc_cd_tables(struct arm_smmu_domain *smmu_domain)
+static int arm_smmu_alloc_cd_tables(struct arm_smmu_domain *smmu_domain,
+ struct arm_smmu_master *master)
{
int ret;
size_t l1size;
@@ -1140,6 +1141,7 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_domain *smmu_domain)
struct arm_smmu_device *smmu = smmu_domain->smmu;
struct arm_smmu_ctx_desc_cfg *cdcfg = &smmu_domain->cd_table;
+ cdcfg->max_cds_bits = master->ssid_bits;
max_contexts = 1 << cdcfg->max_cds_bits;
if (!(smmu->features & ARM_SMMU_FEAT_2_LVL_CDTAB) ||
@@ -2107,7 +2109,6 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain,
int ret;
u32 asid;
struct arm_smmu_device *smmu = smmu_domain->smmu;
- struct arm_smmu_ctx_desc_cfg *cdcfg = &smmu_domain->cd_table;
struct arm_smmu_ctx_desc *cd = &smmu_domain->cd;
typeof(&pgtbl_cfg->arm_lpae_s1_cfg.tcr) tcr = &pgtbl_cfg->arm_lpae_s1_cfg.tcr;
@@ -2120,11 +2121,9 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain,
if (ret)
goto out_unlock;
- cdcfg->max_cds_bits = master->ssid_bits;
-
smmu_domain->stall_enabled = master->stall_enabled;
- ret = arm_smmu_alloc_cd_tables(smmu_domain);
+ ret = arm_smmu_alloc_cd_tables(smmu_domain, master);
if (ret)
goto out_free_asid;
--
2.41.0.585.gd2178a4bd4-goog
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 26+ messages in thread* [PATCH v1 4/7] iommu/arm-smmu-v3: move stall_enabled to the cd table
2023-07-27 18:26 [PATCH v1 0/7] Refactor the SMMU's CD table ownership Michael Shavit
` (2 preceding siblings ...)
2023-07-27 18:26 ` [PATCH v1 3/7] iommu/arm-smmu-v3: Encapsulate ctx_desc_cfg init in alloc_cd_tables Michael Shavit
@ 2023-07-27 18:26 ` Michael Shavit
2023-07-27 18:26 ` [PATCH v1 5/7] iommu/arm-smmu-v3: Skip cd sync if CD table isn't active Michael Shavit
` (3 subsequent siblings)
7 siblings, 0 replies; 26+ messages in thread
From: Michael Shavit @ 2023-07-27 18:26 UTC (permalink / raw)
To: Will Deacon, Robin Murphy, Joerg Roedel
Cc: Michael Shavit, jean-philippe, nicolinc, jgg, baolu.lu,
linux-arm-kernel, iommu, linux-kernel
This controls whether CD entries will have the stall bit set when
writing entries into the table.
Signed-off-by: Michael Shavit <mshavit@google.com>
---
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 8 ++++----
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 3 ++-
2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
index 8a286e3838d70..654acf6002bf3 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -1114,7 +1114,7 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_domain *smmu_domain, int ssid,
FIELD_PREP(CTXDESC_CD_0_ASID, cd->asid) |
CTXDESC_CD_0_V;
- if (smmu_domain->stall_enabled)
+ if (smmu_domain->cd_table.stall_enabled)
val |= CTXDESC_CD_0_S;
}
@@ -1141,6 +1141,7 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_domain *smmu_domain,
struct arm_smmu_device *smmu = smmu_domain->smmu;
struct arm_smmu_ctx_desc_cfg *cdcfg = &smmu_domain->cd_table;
+ cdcfg->stall_enabled = master->stall_enabled;
cdcfg->max_cds_bits = master->ssid_bits;
max_contexts = 1 << cdcfg->max_cds_bits;
@@ -2121,8 +2122,6 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain,
if (ret)
goto out_unlock;
- smmu_domain->stall_enabled = master->stall_enabled;
-
ret = arm_smmu_alloc_cd_tables(smmu_domain, master);
if (ret)
goto out_free_asid;
@@ -2461,7 +2460,8 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
ret = -EINVAL;
goto out_unlock;
} else if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1 &&
- smmu_domain->stall_enabled != master->stall_enabled) {
+ smmu_domain->cd_table.stall_enabled !=
+ master->stall_enabled) {
ret = -EINVAL;
goto out_unlock;
}
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
index 006a724ee9230..0e55ca0d40e6b 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
@@ -597,6 +597,8 @@ struct arm_smmu_ctx_desc_cfg {
unsigned int num_l1_ents;
/* log2 of the maximum number of CDs supported by this table */
u8 max_cds_bits;
+ /* Whether CD entries in this table have the stall bit set. */
+ bool stall_enabled;
};
struct arm_smmu_s2_cfg {
@@ -714,7 +716,6 @@ struct arm_smmu_domain {
struct mutex init_mutex; /* Protects smmu pointer */
struct io_pgtable_ops *pgtbl_ops;
- bool stall_enabled;
atomic_t nr_ats_masters;
enum arm_smmu_domain_stage stage;
--
2.41.0.585.gd2178a4bd4-goog
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 26+ messages in thread* [PATCH v1 5/7] iommu/arm-smmu-v3: Skip cd sync if CD table isn't active
2023-07-27 18:26 [PATCH v1 0/7] Refactor the SMMU's CD table ownership Michael Shavit
` (3 preceding siblings ...)
2023-07-27 18:26 ` [PATCH v1 4/7] iommu/arm-smmu-v3: move stall_enabled to the cd table Michael Shavit
@ 2023-07-27 18:26 ` Michael Shavit
2023-07-27 18:33 ` Jason Gunthorpe
2023-07-27 18:26 ` [PATCH v1 6/7] iommu/arm-smmu-v3: Refactor write_ctx_desc Michael Shavit
` (2 subsequent siblings)
7 siblings, 1 reply; 26+ messages in thread
From: Michael Shavit @ 2023-07-27 18:26 UTC (permalink / raw)
To: Will Deacon, Robin Murphy, Joerg Roedel
Cc: Michael Shavit, jean-philippe, nicolinc, jgg, baolu.lu,
linux-arm-kernel, iommu, linux-kernel
This commit explicitly keeps track of whether a CD table is installed in
an STE so that arm_smmu_sync_cd can skip the sync when unnecessary. This
was previously achieved through the domain->devices list, but we are
moving to a model where arm_smmu_sync_cd directly operates on a master
and the master's CD table instead of a domain.
Signed-off-by: Michael Shavit <mshavit@google.com>
---
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 4 ++++
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 ++
2 files changed, 6 insertions(+)
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
index 654acf6002bf3..af7949b62327b 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -987,6 +987,9 @@ static void arm_smmu_sync_cd(struct arm_smmu_domain *smmu_domain,
},
};
+ if (!smmu_domain->cd_table.installed)
+ return;
+
cmds.num = 0;
spin_lock_irqsave(&smmu_domain->devices_lock, flags);
@@ -1368,6 +1371,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid,
cd_table->l1_desc ?
STRTAB_STE_0_S1FMT_64K_L2 :
STRTAB_STE_0_S1FMT_LINEAR);
+ cd_table->installed = true;
}
if (s2_cfg) {
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
index 0e55ca0d40e6b..f301efe90b599 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
@@ -599,6 +599,8 @@ struct arm_smmu_ctx_desc_cfg {
u8 max_cds_bits;
/* Whether CD entries in this table have the stall bit set. */
bool stall_enabled;
+ /* Whether this CD table is installed in any STE */
+ bool installed;
};
struct arm_smmu_s2_cfg {
--
2.41.0.585.gd2178a4bd4-goog
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 26+ messages in thread* Re: [PATCH v1 5/7] iommu/arm-smmu-v3: Skip cd sync if CD table isn't active
2023-07-27 18:26 ` [PATCH v1 5/7] iommu/arm-smmu-v3: Skip cd sync if CD table isn't active Michael Shavit
@ 2023-07-27 18:33 ` Jason Gunthorpe
0 siblings, 0 replies; 26+ messages in thread
From: Jason Gunthorpe @ 2023-07-27 18:33 UTC (permalink / raw)
To: Michael Shavit
Cc: Will Deacon, Robin Murphy, Joerg Roedel, jean-philippe, nicolinc,
baolu.lu, linux-arm-kernel, iommu, linux-kernel
On Fri, Jul 28, 2023 at 02:26:21AM +0800, Michael Shavit wrote:
> This commit explicitly keeps track of whether a CD table is installed in
> an STE so that arm_smmu_sync_cd can skip the sync when unnecessary. This
> was previously achieved through the domain->devices list, but we are
> moving to a model where arm_smmu_sync_cd directly operates on a master
> and the master's CD table instead of a domain.
>
> Signed-off-by: Michael Shavit <mshavit@google.com>
> ---
> drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 4 ++++
> drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 ++
> 2 files changed, 6 insertions(+)
>
> diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> index 654acf6002bf3..af7949b62327b 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> @@ -987,6 +987,9 @@ static void arm_smmu_sync_cd(struct arm_smmu_domain *smmu_domain,
> },
> };
>
> + if (!smmu_domain->cd_table.installed)
> + return;
> +
> cmds.num = 0;
>
> spin_lock_irqsave(&smmu_domain->devices_lock, flags);
> @@ -1368,6 +1371,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid,
> cd_table->l1_desc ?
> STRTAB_STE_0_S1FMT_64K_L2 :
> STRTAB_STE_0_S1FMT_LINEAR);
> + cd_table->installed = true;
> }
>
> if (s2_cfg) {
> diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
> index 0e55ca0d40e6b..f301efe90b599 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
> @@ -599,6 +599,8 @@ struct arm_smmu_ctx_desc_cfg {
> u8 max_cds_bits;
> /* Whether CD entries in this table have the stall bit set. */
> bool stall_enabled;
> + /* Whether this CD table is installed in any STE */
> + bool installed;
Do
u8 xx:1;
u8 yy:1;
For these things, Linus has complained about lists of bools in structs
before.
Jason
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v1 6/7] iommu/arm-smmu-v3: Refactor write_ctx_desc
2023-07-27 18:26 [PATCH v1 0/7] Refactor the SMMU's CD table ownership Michael Shavit
` (4 preceding siblings ...)
2023-07-27 18:26 ` [PATCH v1 5/7] iommu/arm-smmu-v3: Skip cd sync if CD table isn't active Michael Shavit
@ 2023-07-27 18:26 ` Michael Shavit
2023-07-27 21:37 ` Nicolin Chen
2023-07-27 18:26 ` [PATCH v1 7/7] iommu/arm-smmu-v3: Move CD table to arm_smmu_master Michael Shavit
2023-07-27 20:19 ` [PATCH v1 0/7] Refactor the SMMU's CD table ownership Nicolin Chen
7 siblings, 1 reply; 26+ messages in thread
From: Michael Shavit @ 2023-07-27 18:26 UTC (permalink / raw)
To: Will Deacon, Robin Murphy, Joerg Roedel
Cc: Michael Shavit, jean-philippe, nicolinc, jgg, baolu.lu,
linux-arm-kernel, iommu, linux-kernel
Update arm_smmu_write_ctx_desc and downstream functions to operate on
a master instead of an smmu domain. We expect arm_smmu_write_ctx_desc()
to only be called to write a CD entry into a CD table owned by the
master. Under the hood, arm_smmu_write_ctx_desc still fetches the CD
table from the domain that is attached to the master, but a subsequent
commit will move that table's ownership to the master.
Note that this change isn't a nop refactor since SVA will call
arm_smmu_write_ctx_desc in a loop for every master the domain is
attached to despite the fact that they all share the same CD table. This
loop may look weird but becomes necessary when the CD table becomes
per-master in a subsequent commit.
Signed-off-by: Michael Shavit <mshavit@google.com>
---
v4->v5: arm_smmu_write_ctx_desc now get's the CD table to write to from
the master parameter instead of a distinct parameter. This works well
because the CD table being written to should always be owned by the
master by the end of this series. This version no longer allows master
to be NULL.
---
.../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 33 ++++++++--
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 61 ++++++++-----------
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 +-
3 files changed, 54 insertions(+), 42 deletions(-)
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c
index 968559d625c40..57073d278cd7e 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c
@@ -45,10 +45,12 @@ static struct arm_smmu_ctx_desc *
arm_smmu_share_asid(struct mm_struct *mm, u16 asid)
{
int ret;
+ unsigned long flags;
u32 new_asid;
struct arm_smmu_ctx_desc *cd;
struct arm_smmu_device *smmu;
struct arm_smmu_domain *smmu_domain;
+ struct arm_smmu_master *master;
cd = xa_load(&arm_smmu_asid_xa, asid);
if (!cd)
@@ -80,7 +82,11 @@ arm_smmu_share_asid(struct mm_struct *mm, u16 asid)
* be some overlap between use of both ASIDs, until we invalidate the
* TLB.
*/
- arm_smmu_write_ctx_desc(smmu_domain, 0, cd);
+ spin_lock_irqsave(&smmu_domain->devices_lock, flags);
+ list_for_each_entry(master, &smmu_domain->devices, domain_head) {
+ arm_smmu_write_ctx_desc(master, 0, cd);
+ }
+ spin_unlock_irqrestore(&smmu_domain->devices_lock, flags);
/* Invalidate TLB entries previously associated with that context */
arm_smmu_tlb_inv_asid(smmu, asid);
@@ -211,6 +217,8 @@ static void arm_smmu_mm_release(struct mmu_notifier *mn, struct mm_struct *mm)
{
struct arm_smmu_mmu_notifier *smmu_mn = mn_to_smmu(mn);
struct arm_smmu_domain *smmu_domain = smmu_mn->domain;
+ struct arm_smmu_master *master;
+ unsigned long flags;
mutex_lock(&sva_lock);
if (smmu_mn->cleared) {
@@ -222,7 +230,11 @@ static void arm_smmu_mm_release(struct mmu_notifier *mn, struct mm_struct *mm)
* DMA may still be running. Keep the cd valid to avoid C_BAD_CD events,
* but disable translation.
*/
- arm_smmu_write_ctx_desc(smmu_domain, mm->pasid, &quiet_cd);
+ spin_lock_irqsave(&smmu_domain->devices_lock, flags);
+ list_for_each_entry(master, &smmu_domain->devices, domain_head) {
+ arm_smmu_write_ctx_desc(master, mm->pasid, &quiet_cd);
+ }
+ spin_unlock_irqrestore(&smmu_domain->devices_lock, flags);
arm_smmu_tlb_inv_asid(smmu_domain->smmu, smmu_mn->cd->asid);
arm_smmu_atc_inv_domain(smmu_domain, mm->pasid, 0, 0);
@@ -248,8 +260,10 @@ arm_smmu_mmu_notifier_get(struct arm_smmu_domain *smmu_domain,
struct mm_struct *mm)
{
int ret;
+ unsigned long flags;
struct arm_smmu_ctx_desc *cd;
struct arm_smmu_mmu_notifier *smmu_mn;
+ struct arm_smmu_master *master;
list_for_each_entry(smmu_mn, &smmu_domain->mmu_notifiers, list) {
if (smmu_mn->mn.mm == mm) {
@@ -279,7 +293,11 @@ arm_smmu_mmu_notifier_get(struct arm_smmu_domain *smmu_domain,
goto err_free_cd;
}
- ret = arm_smmu_write_ctx_desc(smmu_domain, mm->pasid, cd);
+ spin_lock_irqsave(&smmu_domain->devices_lock, flags);
+ list_for_each_entry(master, &smmu_domain->devices, domain_head) {
+ ret = arm_smmu_write_ctx_desc(master, mm->pasid, cd);
+ }
+ spin_unlock_irqrestore(&smmu_domain->devices_lock, flags);
if (ret)
goto err_put_notifier;
@@ -296,15 +314,22 @@ arm_smmu_mmu_notifier_get(struct arm_smmu_domain *smmu_domain,
static void arm_smmu_mmu_notifier_put(struct arm_smmu_mmu_notifier *smmu_mn)
{
+ unsigned long flags;
struct mm_struct *mm = smmu_mn->mn.mm;
struct arm_smmu_ctx_desc *cd = smmu_mn->cd;
+ struct arm_smmu_master *master;
struct arm_smmu_domain *smmu_domain = smmu_mn->domain;
if (!refcount_dec_and_test(&smmu_mn->refs))
return;
list_del(&smmu_mn->list);
- arm_smmu_write_ctx_desc(smmu_domain, mm->pasid, NULL);
+
+ spin_lock_irqsave(&smmu_domain->devices_lock, flags);
+ list_for_each_entry(master, &smmu_domain->devices, domain_head) {
+ arm_smmu_write_ctx_desc(master, mm->pasid, NULL);
+ }
+ spin_unlock_irqrestore(&smmu_domain->devices_lock, flags);
/*
* If we went through clear(), we've already invalidated, and no
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
index af7949b62327b..b211424a85fb2 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -971,14 +971,12 @@ void arm_smmu_tlb_inv_asid(struct arm_smmu_device *smmu, u16 asid)
arm_smmu_cmdq_issue_cmd_with_sync(smmu, &cmd);
}
-static void arm_smmu_sync_cd(struct arm_smmu_domain *smmu_domain,
+static void arm_smmu_sync_cd(struct arm_smmu_master *master,
int ssid, bool leaf)
{
size_t i;
- unsigned long flags;
- struct arm_smmu_master *master;
struct arm_smmu_cmdq_batch cmds;
- struct arm_smmu_device *smmu = smmu_domain->smmu;
+ struct arm_smmu_device *smmu;
struct arm_smmu_cmdq_ent cmd = {
.opcode = CMDQ_OP_CFGI_CD,
.cfgi = {
@@ -987,19 +985,15 @@ static void arm_smmu_sync_cd(struct arm_smmu_domain *smmu_domain,
},
};
- if (!smmu_domain->cd_table.installed)
+ if (!master->domain->cd_table.installed)
return;
+ smmu = master->smmu;
cmds.num = 0;
-
- spin_lock_irqsave(&smmu_domain->devices_lock, flags);
- list_for_each_entry(master, &smmu_domain->devices, domain_head) {
- for (i = 0; i < master->num_streams; i++) {
- cmd.cfgi.sid = master->streams[i].id;
- arm_smmu_cmdq_batch_add(smmu, &cmds, &cmd);
- }
+ for (i = 0; i < master->num_streams; i++) {
+ cmd.cfgi.sid = master->streams[i].id;
+ arm_smmu_cmdq_batch_add(smmu, &cmds, &cmd);
}
- spin_unlock_irqrestore(&smmu_domain->devices_lock, flags);
arm_smmu_cmdq_batch_submit(smmu, &cmds);
}
@@ -1029,14 +1023,12 @@ static void arm_smmu_write_cd_l1_desc(__le64 *dst,
WRITE_ONCE(*dst, cpu_to_le64(val));
}
-static __le64 *arm_smmu_get_cd_ptr(struct arm_smmu_domain *smmu_domain,
- u32 ssid)
+static __le64 *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, u32 ssid)
{
__le64 *l1ptr;
unsigned int idx;
struct arm_smmu_l1_ctx_desc *l1_desc;
- struct arm_smmu_device *smmu = smmu_domain->smmu;
- struct arm_smmu_ctx_desc_cfg *cdcfg = &smmu_domain->cd_table;
+ struct arm_smmu_ctx_desc_cfg *cdcfg = &master->domain->cd_table;
if (!cdcfg->l1_desc)
return cdcfg->cdtab + ssid * CTXDESC_CD_DWORDS;
@@ -1044,19 +1036,19 @@ static __le64 *arm_smmu_get_cd_ptr(struct arm_smmu_domain *smmu_domain,
idx = ssid >> CTXDESC_SPLIT;
l1_desc = &cdcfg->l1_desc[idx];
if (!l1_desc->l2ptr) {
- if (arm_smmu_alloc_cd_leaf_table(smmu, l1_desc))
+ if (arm_smmu_alloc_cd_leaf_table(master->smmu, l1_desc))
return NULL;
l1ptr = cdcfg->cdtab + idx * CTXDESC_L1_DESC_DWORDS;
arm_smmu_write_cd_l1_desc(l1ptr, l1_desc);
/* An invalid L1CD can be cached */
- arm_smmu_sync_cd(smmu_domain, ssid, false);
+ arm_smmu_sync_cd(master, ssid, false);
}
idx = ssid & (CTXDESC_L2_ENTRIES - 1);
return l1_desc->l2ptr + idx * CTXDESC_CD_DWORDS;
}
-int arm_smmu_write_ctx_desc(struct arm_smmu_domain *smmu_domain, int ssid,
+int arm_smmu_write_ctx_desc(struct arm_smmu_master *master, int ssid,
struct arm_smmu_ctx_desc *cd)
{
/*
@@ -1073,11 +1065,12 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_domain *smmu_domain, int ssid,
u64 val;
bool cd_live;
__le64 *cdptr;
+ struct arm_smmu_ctx_desc_cfg *cd_table = &master->domain->cd_table;
- if (WARN_ON(ssid >= (1 << smmu_domain->cd_table.max_cds_bits)))
+ if (WARN_ON(ssid >= (1 << cd_table->max_cds_bits)))
return -E2BIG;
- cdptr = arm_smmu_get_cd_ptr(smmu_domain, ssid);
+ cdptr = arm_smmu_get_cd_ptr(master, ssid);
if (!cdptr)
return -ENOMEM;
@@ -1101,11 +1094,11 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_domain *smmu_domain, int ssid,
cdptr[3] = cpu_to_le64(cd->mair);
/*
- * STE is live, and the SMMU might read dwords of this CD in any
- * order. Ensure that it observes valid values before reading
- * V=1.
+ * STE may be live, and the SMMU might read dwords of this CD
+ * in any order. Ensure that it observes valid values before
+ * reading V=1.
*/
- arm_smmu_sync_cd(smmu_domain, ssid, true);
+ arm_smmu_sync_cd(master, ssid, true);
val = cd->tcr |
#ifdef __BIG_ENDIAN
@@ -1117,7 +1110,7 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_domain *smmu_domain, int ssid,
FIELD_PREP(CTXDESC_CD_0_ASID, cd->asid) |
CTXDESC_CD_0_V;
- if (smmu_domain->cd_table.stall_enabled)
+ if (cd_table->stall_enabled)
val |= CTXDESC_CD_0_S;
}
@@ -1131,7 +1124,7 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_domain *smmu_domain, int ssid,
* without first making the structure invalid.
*/
WRITE_ONCE(cdptr[0], cpu_to_le64(val));
- arm_smmu_sync_cd(smmu_domain, ssid, true);
+ arm_smmu_sync_cd(master, ssid, true);
return 0;
}
@@ -1141,7 +1134,7 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_domain *smmu_domain,
int ret;
size_t l1size;
size_t max_contexts;
- struct arm_smmu_device *smmu = smmu_domain->smmu;
+ struct arm_smmu_device *smmu = master->smmu;
struct arm_smmu_ctx_desc_cfg *cdcfg = &smmu_domain->cd_table;
cdcfg->stall_enabled = master->stall_enabled;
@@ -2141,12 +2134,7 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain,
CTXDESC_CD_0_TCR_EPD1 | CTXDESC_CD_0_AA64;
cd->mair = pgtbl_cfg->arm_lpae_s1_cfg.mair;
- /*
- * Note that this will end up calling arm_smmu_sync_cd() before
- * the master has been added to the devices list for this domain.
- * This isn't an issue because the STE hasn't been installed yet.
- */
- ret = arm_smmu_write_ctx_desc(smmu_domain, 0, cd);
+ ret = arm_smmu_write_ctx_desc(master, 0, cd);
if (ret)
goto out_free_cd_tables;
@@ -2464,8 +2452,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
ret = -EINVAL;
goto out_unlock;
} else if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1 &&
- smmu_domain->cd_table.stall_enabled !=
- master->stall_enabled) {
+ smmu_domain->cd_table.stall_enabled != master->stall_enabled) {
ret = -EINVAL;
goto out_unlock;
}
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
index f301efe90b599..a8cc2de0cc254 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
@@ -746,7 +746,7 @@ extern struct xarray arm_smmu_asid_xa;
extern struct mutex arm_smmu_asid_lock;
extern struct arm_smmu_ctx_desc quiet_cd;
-int arm_smmu_write_ctx_desc(struct arm_smmu_domain *smmu_domain, int ssid,
+int arm_smmu_write_ctx_desc(struct arm_smmu_master *smmu_master, int ssid,
struct arm_smmu_ctx_desc *cd);
void arm_smmu_tlb_inv_asid(struct arm_smmu_device *smmu, u16 asid);
void arm_smmu_tlb_inv_range_asid(unsigned long iova, size_t size, int asid,
--
2.41.0.585.gd2178a4bd4-goog
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 26+ messages in thread* Re: [PATCH v1 6/7] iommu/arm-smmu-v3: Refactor write_ctx_desc
2023-07-27 18:26 ` [PATCH v1 6/7] iommu/arm-smmu-v3: Refactor write_ctx_desc Michael Shavit
@ 2023-07-27 21:37 ` Nicolin Chen
2023-07-28 7:34 ` Michael Shavit
0 siblings, 1 reply; 26+ messages in thread
From: Nicolin Chen @ 2023-07-27 21:37 UTC (permalink / raw)
To: Michael Shavit
Cc: Will Deacon, Robin Murphy, Joerg Roedel, jean-philippe, jgg,
baolu.lu, linux-arm-kernel, iommu, linux-kernel
On Fri, Jul 28, 2023 at 02:26:22AM +0800, Michael Shavit wrote:
> diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c
> index 968559d625c40..57073d278cd7e 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c
> @@ -45,10 +45,12 @@ static struct arm_smmu_ctx_desc *
> arm_smmu_share_asid(struct mm_struct *mm, u16 asid)
> {
> int ret;
> + unsigned long flags;
> u32 new_asid;
> struct arm_smmu_ctx_desc *cd;
> struct arm_smmu_device *smmu;
> struct arm_smmu_domain *smmu_domain;
> + struct arm_smmu_master *master;
It seems that the coding style at these struct lines is listing
from shorter to longer, like a Christmas tree? If so, we should
place "master" before "smmu_domain".
> @@ -80,7 +82,11 @@ arm_smmu_share_asid(struct mm_struct *mm, u16 asid)
> * be some overlap between use of both ASIDs, until we invalidate the
> * TLB.
> */
> - arm_smmu_write_ctx_desc(smmu_domain, 0, cd);
> + spin_lock_irqsave(&smmu_domain->devices_lock, flags);
> + list_for_each_entry(master, &smmu_domain->devices, domain_head) {
> + arm_smmu_write_ctx_desc(master, 0, cd);
> + }
+ list_for_each_entry(master, &smmu_domain->devices, domain_head)
+ arm_smmu_write_ctx_desc(master, 0, cd);
> @@ -248,8 +260,10 @@ arm_smmu_mmu_notifier_get(struct arm_smmu_domain *smmu_domain,
> struct mm_struct *mm)
> {
> int ret;
> + unsigned long flags;
> struct arm_smmu_ctx_desc *cd;
> struct arm_smmu_mmu_notifier *smmu_mn;
> + struct arm_smmu_master *master;
For the coding style topic, similarly, "master" before "smmu_mn".
> diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> index af7949b62327b..b211424a85fb2 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> @@ -971,14 +971,12 @@ void arm_smmu_tlb_inv_asid(struct arm_smmu_device *smmu, u16 asid)
> arm_smmu_cmdq_issue_cmd_with_sync(smmu, &cmd);
> }
>
> -static void arm_smmu_sync_cd(struct arm_smmu_domain *smmu_domain,
> +static void arm_smmu_sync_cd(struct arm_smmu_master *master,
> int ssid, bool leaf)
> {
> size_t i;
> - unsigned long flags;
> - struct arm_smmu_master *master;
> struct arm_smmu_cmdq_batch cmds;
> - struct arm_smmu_device *smmu = smmu_domain->smmu;
> + struct arm_smmu_device *smmu;
struct arm_smmu_device *smmu = master->smmu;
Then ...
> @@ -987,19 +985,15 @@ static void arm_smmu_sync_cd(struct arm_smmu_domain *smmu_domain,
> },
> };
>
> - if (!smmu_domain->cd_table.installed)
> + if (!master->domain->cd_table.installed)
> return;
>
> + smmu = master->smmu;
... no need of this line.
> @@ -1029,14 +1023,12 @@ static void arm_smmu_write_cd_l1_desc(__le64 *dst,
> WRITE_ONCE(*dst, cpu_to_le64(val));
> }
>
> -static __le64 *arm_smmu_get_cd_ptr(struct arm_smmu_domain *smmu_domain,
> - u32 ssid)
> +static __le64 *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, u32 ssid)
> {
> __le64 *l1ptr;
> unsigned int idx;
> struct arm_smmu_l1_ctx_desc *l1_desc;
> - struct arm_smmu_device *smmu = smmu_domain->smmu;
struct arm_smmu_device *smmu = master->smmu;
Then ...
> @@ -1044,19 +1036,19 @@ static __le64 *arm_smmu_get_cd_ptr(struct arm_smmu_domain *smmu_domain,
> idx = ssid >> CTXDESC_SPLIT;
> l1_desc = &cdcfg->l1_desc[idx];
> if (!l1_desc->l2ptr) {
> - if (arm_smmu_alloc_cd_leaf_table(smmu, l1_desc))
> + if (arm_smmu_alloc_cd_leaf_table(master->smmu, l1_desc))
... no need to change this.
> @@ -1101,11 +1094,11 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_domain *smmu_domain, int ssid,
> cdptr[3] = cpu_to_le64(cd->mair);
>
> /*
> - * STE is live, and the SMMU might read dwords of this CD in any
> - * order. Ensure that it observes valid values before reading
> - * V=1.
> + * STE may be live, and the SMMU might read dwords of this CD
> + * in any order. Ensure that it observes valid values before
> + * reading V=1.
This seems to be true only after the following patch? If so, we
should move this part over there too.
Thanks
Nicolin
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 26+ messages in thread* Re: [PATCH v1 6/7] iommu/arm-smmu-v3: Refactor write_ctx_desc
2023-07-27 21:37 ` Nicolin Chen
@ 2023-07-28 7:34 ` Michael Shavit
2023-07-28 10:31 ` Michael Shavit
0 siblings, 1 reply; 26+ messages in thread
From: Michael Shavit @ 2023-07-28 7:34 UTC (permalink / raw)
To: Nicolin Chen
Cc: Will Deacon, Robin Murphy, Joerg Roedel, jean-philippe, jgg,
baolu.lu, linux-arm-kernel, iommu, linux-kernel
On Fri, Jul 28, 2023 at 5:38 AM Nicolin Chen <nicolinc@nvidia.com> wrote:
> > @@ -1101,11 +1094,11 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_domain *smmu_domain, int ssid,
> > cdptr[3] = cpu_to_le64(cd->mair);
> >
> > /*
> > - * STE is live, and the SMMU might read dwords of this CD in any
> > - * order. Ensure that it observes valid values before reading
> > - * V=1.
> > + * STE may be live, and the SMMU might read dwords of this CD
> > + * in any order. Ensure that it observes valid values before
> > + * reading V=1.
>
> This seems to be true only after the following patch? If so, we
> should move this part over there too.
This comment is more in theme with the next commit so I can move it
over. But FWIW, the fact that the STE is not necessarily live at this
location is true before this patch, in this patch, and after the
following patch. Fixing this comment is just a drive-by, not a result
of any of these changes.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v1 6/7] iommu/arm-smmu-v3: Refactor write_ctx_desc
2023-07-28 7:34 ` Michael Shavit
@ 2023-07-28 10:31 ` Michael Shavit
0 siblings, 0 replies; 26+ messages in thread
From: Michael Shavit @ 2023-07-28 10:31 UTC (permalink / raw)
To: Nicolin Chen
Cc: Will Deacon, Robin Murphy, Joerg Roedel, jean-philippe, jgg,
baolu.lu, linux-arm-kernel, iommu, linux-kernel
On Fri, Jul 28, 2023 at 3:34 PM Michael Shavit <mshavit@google.com> wrote:
>
> On Fri, Jul 28, 2023 at 5:38 AM Nicolin Chen <nicolinc@nvidia.com> wrote:
> > > @@ -1101,11 +1094,11 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_domain *smmu_domain, int ssid,
> > > cdptr[3] = cpu_to_le64(cd->mair);
> > >
> > > /*
> > > - * STE is live, and the SMMU might read dwords of this CD in any
> > > - * order. Ensure that it observes valid values before reading
> > > - * V=1.
> > > + * STE may be live, and the SMMU might read dwords of this CD
> > > + * in any order. Ensure that it observes valid values before
> > > + * reading V=1.
> >
> > This seems to be true only after the following patch? If so, we
> > should move this part over there too.
>
> This comment is more in theme with the next commit so I can move it
> over. But FWIW, the fact that the STE is not necessarily live at this
> location is true before this patch, in this patch, and after the
> following patch. Fixing this comment is just a drive-by, not a result
> of any of these changes.
Whoops, I mean more in theme with the previous commit.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 26+ messages in thread
* [PATCH v1 7/7] iommu/arm-smmu-v3: Move CD table to arm_smmu_master
2023-07-27 18:26 [PATCH v1 0/7] Refactor the SMMU's CD table ownership Michael Shavit
` (5 preceding siblings ...)
2023-07-27 18:26 ` [PATCH v1 6/7] iommu/arm-smmu-v3: Refactor write_ctx_desc Michael Shavit
@ 2023-07-27 18:26 ` Michael Shavit
2023-07-27 18:43 ` Jason Gunthorpe
2023-07-27 20:19 ` [PATCH v1 0/7] Refactor the SMMU's CD table ownership Nicolin Chen
7 siblings, 1 reply; 26+ messages in thread
From: Michael Shavit @ 2023-07-27 18:26 UTC (permalink / raw)
To: Will Deacon, Robin Murphy, Joerg Roedel
Cc: Michael Shavit, jean-philippe, nicolinc, jgg, baolu.lu,
linux-arm-kernel, iommu, linux-kernel
Each master is now allocated a CD table at probe time, and attaching a
stage 1 domain now installs CD entries into the master's CD table. SVA
writes its CD entries into each master's CD table if the domain is
shared across masters.
Signed-off-by: Michael Shavit <mshavit@google.com>
---
v4->v5: The master's CD table allocation was previously split to a
different commit. This change now atomically allocates the new CD
table, uses it, and removes the old one.
---
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 65 +++++++++------------
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 4 +-
2 files changed, 28 insertions(+), 41 deletions(-)
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
index b211424a85fb2..a58a0f811d531 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
@@ -985,7 +985,7 @@ static void arm_smmu_sync_cd(struct arm_smmu_master *master,
},
};
- if (!master->domain->cd_table.installed)
+ if (!master->cd_table.installed)
return;
smmu = master->smmu;
@@ -1028,7 +1028,7 @@ static __le64 *arm_smmu_get_cd_ptr(struct arm_smmu_master *master, u32 ssid)
__le64 *l1ptr;
unsigned int idx;
struct arm_smmu_l1_ctx_desc *l1_desc;
- struct arm_smmu_ctx_desc_cfg *cdcfg = &master->domain->cd_table;
+ struct arm_smmu_ctx_desc_cfg *cdcfg = &master->cd_table;
if (!cdcfg->l1_desc)
return cdcfg->cdtab + ssid * CTXDESC_CD_DWORDS;
@@ -1065,7 +1065,7 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_master *master, int ssid,
u64 val;
bool cd_live;
__le64 *cdptr;
- struct arm_smmu_ctx_desc_cfg *cd_table = &master->domain->cd_table;
+ struct arm_smmu_ctx_desc_cfg *cd_table = &master->cd_table;
if (WARN_ON(ssid >= (1 << cd_table->max_cds_bits)))
return -E2BIG;
@@ -1128,14 +1128,13 @@ int arm_smmu_write_ctx_desc(struct arm_smmu_master *master, int ssid,
return 0;
}
-static int arm_smmu_alloc_cd_tables(struct arm_smmu_domain *smmu_domain,
- struct arm_smmu_master *master)
+static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master)
{
int ret;
size_t l1size;
size_t max_contexts;
struct arm_smmu_device *smmu = master->smmu;
- struct arm_smmu_ctx_desc_cfg *cdcfg = &smmu_domain->cd_table;
+ struct arm_smmu_ctx_desc_cfg *cdcfg = &master->cd_table;
cdcfg->stall_enabled = master->stall_enabled;
cdcfg->max_cds_bits = master->ssid_bits;
@@ -1177,12 +1176,12 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_domain *smmu_domain,
return ret;
}
-static void arm_smmu_free_cd_tables(struct arm_smmu_domain *smmu_domain)
+static void arm_smmu_free_cd_tables(struct arm_smmu_master *master)
{
int i;
size_t size, l1size;
- struct arm_smmu_device *smmu = smmu_domain->smmu;
- struct arm_smmu_ctx_desc_cfg *cdcfg = &smmu_domain->cd_table;
+ struct arm_smmu_device *smmu = master->smmu;
+ struct arm_smmu_ctx_desc_cfg *cdcfg = &master->cd_table;
if (cdcfg->l1_desc) {
size = CTXDESC_L2_ENTRIES * (CTXDESC_CD_DWORDS << 3);
@@ -1290,7 +1289,7 @@ static void arm_smmu_write_strtab_ent(struct arm_smmu_master *master, u32 sid,
if (smmu_domain) {
switch (smmu_domain->stage) {
case ARM_SMMU_DOMAIN_S1:
- cd_table = &smmu_domain->cd_table;
+ cd_table = &master->cd_table;
break;
case ARM_SMMU_DOMAIN_S2:
case ARM_SMMU_DOMAIN_NESTED:
@@ -2081,14 +2080,10 @@ static void arm_smmu_domain_free(struct iommu_domain *domain)
free_io_pgtable_ops(smmu_domain->pgtbl_ops);
- /* Free the CD and ASID, if we allocated them */
+ /* Free the ASID or VMID */
if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) {
- struct arm_smmu_ctx_desc_cfg *cdcfg = &smmu_domain->cd_table;
-
/* Prevent SVA from touching the CD while we're freeing it */
mutex_lock(&arm_smmu_asid_lock);
- if (cdcfg->cdtab)
- arm_smmu_free_cd_tables(smmu_domain);
arm_smmu_free_asid(&smmu_domain->cd);
mutex_unlock(&arm_smmu_asid_lock);
} else {
@@ -2100,7 +2095,7 @@ static void arm_smmu_domain_free(struct iommu_domain *domain)
kfree(smmu_domain);
}
-static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain,
+static int arm_smmu_domain_finalise_cd(struct arm_smmu_domain *smmu_domain,
struct arm_smmu_master *master,
struct io_pgtable_cfg *pgtbl_cfg)
{
@@ -2119,10 +2114,6 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain,
if (ret)
goto out_unlock;
- ret = arm_smmu_alloc_cd_tables(smmu_domain, master);
- if (ret)
- goto out_free_asid;
-
cd->asid = (u16)asid;
cd->ttbr = pgtbl_cfg->arm_lpae_s1_cfg.ttbr;
cd->tcr = FIELD_PREP(CTXDESC_CD_0_TCR_T0SZ, tcr->tsz) |
@@ -2134,17 +2125,9 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain,
CTXDESC_CD_0_TCR_EPD1 | CTXDESC_CD_0_AA64;
cd->mair = pgtbl_cfg->arm_lpae_s1_cfg.mair;
- ret = arm_smmu_write_ctx_desc(master, 0, cd);
- if (ret)
- goto out_free_cd_tables;
-
mutex_unlock(&arm_smmu_asid_lock);
return 0;
-out_free_cd_tables:
- arm_smmu_free_cd_tables(smmu_domain);
-out_free_asid:
- arm_smmu_free_asid(cd);
out_unlock:
mutex_unlock(&arm_smmu_asid_lock);
return ret;
@@ -2207,7 +2190,7 @@ static int arm_smmu_domain_finalise(struct iommu_domain *domain,
ias = min_t(unsigned long, ias, VA_BITS);
oas = smmu->ias;
fmt = ARM_64_LPAE_S1;
- finalise_stage_fn = arm_smmu_domain_finalise_s1;
+ finalise_stage_fn = arm_smmu_domain_finalise_cd;
break;
case ARM_SMMU_DOMAIN_NESTED:
case ARM_SMMU_DOMAIN_S2:
@@ -2447,16 +2430,7 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
} else if (smmu_domain->smmu != smmu) {
ret = -EINVAL;
goto out_unlock;
- } else if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1 &&
- master->ssid_bits != smmu_domain->cd_table.max_cds_bits) {
- ret = -EINVAL;
- goto out_unlock;
- } else if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1 &&
- smmu_domain->cd_table.stall_enabled != master->stall_enabled) {
- ret = -EINVAL;
- goto out_unlock;
}
-
master->domain = smmu_domain;
/*
@@ -2469,6 +2443,14 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
if (smmu_domain->stage != ARM_SMMU_DOMAIN_BYPASS)
master->ats_enabled = arm_smmu_ats_supported(master);
+ if (smmu_domain->stage == ARM_SMMU_DOMAIN_S1) {
+ ret = arm_smmu_write_ctx_desc(master, 0, &smmu_domain->cd);
+ if (ret) {
+ master->domain = NULL;
+ goto out_unlock;
+ }
+ }
+
arm_smmu_install_ste_for_dev(master);
spin_lock_irqsave(&smmu_domain->devices_lock, flags);
@@ -2706,6 +2688,12 @@ static struct iommu_device *arm_smmu_probe_device(struct device *dev)
smmu->features & ARM_SMMU_FEAT_STALL_FORCE)
master->stall_enabled = true;
+ ret = arm_smmu_alloc_cd_tables(master);
+ if (ret) {
+ arm_smmu_disable_pasid(master);
+ arm_smmu_remove_master(master);
+ goto err_free_master;
+ }
return &smmu->iommu;
err_free_master:
@@ -2723,6 +2711,7 @@ static void arm_smmu_release_device(struct device *dev)
arm_smmu_detach_dev(master);
arm_smmu_disable_pasid(master);
arm_smmu_remove_master(master);
+ arm_smmu_free_cd_tables(master);
kfree(master);
}
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
index a8cc2de0cc254..ebd082b552699 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
@@ -696,6 +696,7 @@ struct arm_smmu_master {
struct arm_smmu_domain *domain;
struct list_head domain_head;
struct arm_smmu_stream *streams;
+ struct arm_smmu_ctx_desc_cfg cd_table;
unsigned int num_streams;
bool ats_enabled;
bool stall_enabled;
@@ -722,10 +723,7 @@ struct arm_smmu_domain {
enum arm_smmu_domain_stage stage;
union {
- struct {
struct arm_smmu_ctx_desc cd;
- struct arm_smmu_ctx_desc_cfg cd_table;
- };
struct arm_smmu_s2_cfg s2_cfg;
};
--
2.41.0.585.gd2178a4bd4-goog
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 26+ messages in thread* Re: [PATCH v1 7/7] iommu/arm-smmu-v3: Move CD table to arm_smmu_master
2023-07-27 18:26 ` [PATCH v1 7/7] iommu/arm-smmu-v3: Move CD table to arm_smmu_master Michael Shavit
@ 2023-07-27 18:43 ` Jason Gunthorpe
2023-07-28 7:52 ` Michael Shavit
2023-07-28 11:11 ` Michael Shavit
0 siblings, 2 replies; 26+ messages in thread
From: Jason Gunthorpe @ 2023-07-27 18:43 UTC (permalink / raw)
To: Michael Shavit
Cc: Will Deacon, Robin Murphy, Joerg Roedel, jean-philippe, nicolinc,
baolu.lu, linux-arm-kernel, iommu, linux-kernel
On Fri, Jul 28, 2023 at 02:26:23AM +0800, Michael Shavit wrote:
> Each master is now allocated a CD table at probe time,
Currently it is allocated during arm_smmu_domain_finalise_s1(), so it
isn't allocated at probe time.
I think the right place to put the allocation is during the attach op,
the first time we need a CD table then go and allocate it. If we can't
then domain attach fails with -ENOMEM.
Then you can put the free in a detach op once the CD table becomes
empty and it behaves much like it already does.
Jason
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v1 7/7] iommu/arm-smmu-v3: Move CD table to arm_smmu_master
2023-07-27 18:43 ` Jason Gunthorpe
@ 2023-07-28 7:52 ` Michael Shavit
2023-07-28 11:11 ` Michael Shavit
1 sibling, 0 replies; 26+ messages in thread
From: Michael Shavit @ 2023-07-28 7:52 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: Will Deacon, Robin Murphy, Joerg Roedel, jean-philippe, nicolinc,
baolu.lu, linux-arm-kernel, iommu, linux-kernel
On Fri, Jul 28, 2023 at 2:43 AM Jason Gunthorpe <jgg@nvidia.com> wrote:
>
> On Fri, Jul 28, 2023 at 02:26:23AM +0800, Michael Shavit wrote:
> > Each master is now allocated a CD table at probe time,
>
> Currently it is allocated during arm_smmu_domain_finalise_s1(), so it
> isn't allocated at probe time.
Urh right, I meant that this patch moves the allocation to the probe,
but that was misleading wording for sure.
> I think the right place to put the allocation is during the attach op,
> the first time we need a CD table then go and allocate it. If we can't
> then domain attach fails with -ENOMEM.
>
> Then you can put the free in a detach op once the CD table becomes
> empty and it behaves much like it already does.
Hmmm fair. I can't think of a reason that the table *must* be
pre-allocated for the PASID feature, and that could always be a
different commit if it turns out to be necessary.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v1 7/7] iommu/arm-smmu-v3: Move CD table to arm_smmu_master
2023-07-27 18:43 ` Jason Gunthorpe
2023-07-28 7:52 ` Michael Shavit
@ 2023-07-28 11:11 ` Michael Shavit
2023-07-28 12:25 ` Jason Gunthorpe
1 sibling, 1 reply; 26+ messages in thread
From: Michael Shavit @ 2023-07-28 11:11 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: Will Deacon, Robin Murphy, Joerg Roedel, jean-philippe, nicolinc,
baolu.lu, linux-arm-kernel, iommu, linux-kernel
On Fri, Jul 28, 2023 at 2:43 AM Jason Gunthorpe <jgg@nvidia.com> wrote:
> Then you can put the free in a detach op once the CD table becomes
> empty and it behaves much like it already does.
This turns out to be a bit tricky; the SMMU driver detaches the
currently attached domain whenever a new domain is attached with
attach_dev(). More generally, do we really want to be de-allocating
the table whenever we switch between an S1 domain and other domain
types that don't make use of the table (such as IDENTITY or NESTED)?
One solution is to defer the allocation to the first attach_op, but
only free when the master is freed (this patch's v1 behavior).
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v1 7/7] iommu/arm-smmu-v3: Move CD table to arm_smmu_master
2023-07-28 11:11 ` Michael Shavit
@ 2023-07-28 12:25 ` Jason Gunthorpe
0 siblings, 0 replies; 26+ messages in thread
From: Jason Gunthorpe @ 2023-07-28 12:25 UTC (permalink / raw)
To: Michael Shavit
Cc: Will Deacon, Robin Murphy, Joerg Roedel, jean-philippe, nicolinc,
baolu.lu, linux-arm-kernel, iommu, linux-kernel
On Fri, Jul 28, 2023 at 07:11:46PM +0800, Michael Shavit wrote:
> On Fri, Jul 28, 2023 at 2:43 AM Jason Gunthorpe <jgg@nvidia.com> wrote:
>
> > Then you can put the free in a detach op once the CD table becomes
> > empty and it behaves much like it already does.
>
> This turns out to be a bit tricky; the SMMU driver detaches the
> currently attached domain whenever a new domain is attached with
> attach_dev().
Oh, yeah, it is a bit quirky that way
> More generally, do we really want to be de-allocating
> the table whenever we switch between an S1 domain and other domain
> types that don't make use of the table (such as IDENTITY or NESTED)?
Probably.
> One solution is to defer the allocation to the first attach_op, but
> only free when the master is freed (this patch's v1 behavior).
That seems reasonable, just don't allocate it at probe time since
PASID is very rarely used.
Jason
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 26+ messages in thread
* Re: [PATCH v1 0/7] Refactor the SMMU's CD table ownership
2023-07-27 18:26 [PATCH v1 0/7] Refactor the SMMU's CD table ownership Michael Shavit
` (6 preceding siblings ...)
2023-07-27 18:26 ` [PATCH v1 7/7] iommu/arm-smmu-v3: Move CD table to arm_smmu_master Michael Shavit
@ 2023-07-27 20:19 ` Nicolin Chen
2023-07-28 7:18 ` Michael Shavit
7 siblings, 1 reply; 26+ messages in thread
From: Nicolin Chen @ 2023-07-27 20:19 UTC (permalink / raw)
To: Michael Shavit
Cc: Will Deacon, Robin Murphy, Joerg Roedel, jean-philippe, jgg,
baolu.lu, linux-arm-kernel, iommu, linux-kernel
Hi Michael,
Thanks for sending this!
On Fri, Jul 28, 2023 at 02:26:16AM +0800, Michael Shavit wrote:
> This series refactors stage 1 domains so that they describe a single CD
> entry. These entries are now inserted into a CD table that is owned by
> the arm_smmu_master instead of the domain.
> This is conceptually cleaner and unblocks other features, such as
> attaching domains with PASID (for unmanaged/dma domains).
>
> This patch series was originally part of a larger patch series that
> implemented the set_dev_pasid callback for non-SVA domains but is now
> split into a distinct series.
>
> This patch series is also available on gerrit with Jean's SMMU test
> engine patches cherry-picked on top for testing:
> https://linux-review.git.corp.google.com/c/linux/kernel/git/torvalds/linux/+/24729
The link isn't accessible for public. I guess it should be this?
https://linux-review.googlesource.com/c/linux/kernel/git/torvalds/linux/+/24729
Nicolin
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 26+ messages in thread* Re: [PATCH v1 0/7] Refactor the SMMU's CD table ownership
2023-07-27 20:19 ` [PATCH v1 0/7] Refactor the SMMU's CD table ownership Nicolin Chen
@ 2023-07-28 7:18 ` Michael Shavit
0 siblings, 0 replies; 26+ messages in thread
From: Michael Shavit @ 2023-07-28 7:18 UTC (permalink / raw)
To: Nicolin Chen
Cc: Will Deacon, Robin Murphy, Joerg Roedel, jean-philippe, jgg,
baolu.lu, linux-arm-kernel, iommu, linux-kernel
On Fri, Jul 28, 2023 at 4:20 AM Nicolin Chen <nicolinc@nvidia.com> wrote:
> The link isn't accessible for public. I guess it should be this?
> https://linux-review.googlesource.com/c/linux/kernel/git/torvalds/linux/+/24729
Whoops sorry yeah that's the correct link.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 26+ messages in thread