From: Mostafa Saleh <smostafa@google.com>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: iommu@lists.linux.dev, Joerg Roedel <joro@8bytes.org>,
linux-arm-kernel@lists.infradead.org,
Robin Murphy <robin.murphy@arm.com>,
Will Deacon <will@kernel.org>,
Michael Shavit <mshavit@google.com>,
Nicolin Chen <nicolinc@nvidia.com>,
patches@lists.linux.dev, Ryan Roberts <ryan.roberts@arm.com>
Subject: Re: [PATCH 1/7] iommu/arm-smmu-v3: Split struct arm_smmu_strtab_cfg.strtab
Date: Tue, 4 Jun 2024 15:52:07 +0000 [thread overview]
Message-ID: <Zl84JwoxGFOLzKSC@google.com> (raw)
In-Reply-To: <1-v1-1b720dce51d1+4f44-smmuv3_tidy_jgg@nvidia.com>
Hi Jason,
On Mon, Jun 03, 2024 at 07:31:27PM -0300, Jason Gunthorpe wrote:
> This is being used as both an array of STEs and an array of L1
> descriptors.
>
> Give the two usages different names and correct types.
>
> Remove STRTAB_STE_DWORDS as most usages were indexing or sizing an array
> of struct arm_smmu_ste.
>
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
> drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 21 +++++++++------------
> drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 9 +++++----
> 2 files changed, 14 insertions(+), 16 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 ab415e107054c1..6b4f1a664288db 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
> @@ -1661,8 +1661,8 @@ static int arm_smmu_init_l2_strtab(struct arm_smmu_device *smmu, u32 sid)
> if (desc->l2ptr)
> return 0;
>
> - size = 1 << (STRTAB_SPLIT + ilog2(STRTAB_STE_DWORDS) + 3);
> - strtab = &cfg->strtab[(sid >> STRTAB_SPLIT) * STRTAB_L1_DESC_DWORDS];
I believe also STRTAB_L1_DESC_DWORDS isn’t needed as l1_desc has the same size.
Especially I already see sizeof(*cfg->l1_desc) used in some places instead of the macro.
So we can remove it also as STRTAB_STE_DWORDS.
> + size = (1 << STRTAB_SPLIT) * sizeof(struct arm_smmu_ste);
> + strtab = &cfg->strtab.l1_desc[sid >> STRTAB_SPLIT];
>
> desc->span = STRTAB_SPLIT + 1;
> desc->l2ptr = dmam_alloc_coherent(smmu->dev, size, &desc->l2ptr_dma,
> @@ -2409,8 +2409,7 @@ arm_smmu_get_step_for_sid(struct arm_smmu_device *smmu, u32 sid)
> return &cfg->l1_desc[idx1].l2ptr[idx2];
> } else {
> /* Simple linear lookup */
> - return (struct arm_smmu_ste *)&cfg
> - ->strtab[sid * STRTAB_STE_DWORDS];
> + return &cfg->strtab.linear[sid];
> }
> }
>
> @@ -3225,17 +3224,15 @@ static int arm_smmu_init_l1_strtab(struct arm_smmu_device *smmu)
> {
> unsigned int i;
> struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg;
> - void *strtab = smmu->strtab_cfg.strtab;
>
> cfg->l1_desc = devm_kcalloc(smmu->dev, cfg->num_l1_ents,
> sizeof(*cfg->l1_desc), GFP_KERNEL);
> if (!cfg->l1_desc)
> return -ENOMEM;
>
> - for (i = 0; i < cfg->num_l1_ents; ++i) {
> - arm_smmu_write_strtab_l1_desc(strtab, &cfg->l1_desc[i]);
> - strtab += STRTAB_L1_DESC_DWORDS << 3;
> - }
> + for (i = 0; i < cfg->num_l1_ents; ++i)
> + arm_smmu_write_strtab_l1_desc(
> + &smmu->strtab_cfg.strtab.l1_desc[i], &cfg->l1_desc[i]);
>
> return 0;
> }
> @@ -3267,7 +3264,7 @@ static int arm_smmu_init_strtab_2lvl(struct arm_smmu_device *smmu)
> l1size);
> return -ENOMEM;
> }
> - cfg->strtab = strtab;
> + cfg->strtab.l1_desc = strtab;
>
> /* Configure strtab_base_cfg for 2 levels */
> reg = FIELD_PREP(STRTAB_BASE_CFG_FMT, STRTAB_BASE_CFG_FMT_2LVL);
> @@ -3285,7 +3282,7 @@ static int arm_smmu_init_strtab_linear(struct arm_smmu_device *smmu)
> u32 size;
> struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg;
>
> - size = (1 << smmu->sid_bits) * (STRTAB_STE_DWORDS << 3);
> + size = (1 << smmu->sid_bits) * sizeof(cfg->strtab.linear[0]);
nit: maybe be consistent with "sizeof(struct arm_smmu_ste)" which was used earlier
this patch and "sizeof(cfg->strtab.linear[0])"
> strtab = dmam_alloc_coherent(smmu->dev, size, &cfg->strtab_dma,
> GFP_KERNEL);
> if (!strtab) {
> @@ -3294,7 +3291,7 @@ static int arm_smmu_init_strtab_linear(struct arm_smmu_device *smmu)
> size);
> return -ENOMEM;
> }
> - cfg->strtab = strtab;
> + cfg->strtab.linear = strtab;
> cfg->num_l1_ents = 1 << smmu->sid_bits;
>
> /* Configure strtab_base_cfg for a linear table covering all SIDs */
> 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 1242a086c9f948..4769780259affc 100644
> --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
> +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h
> @@ -206,10 +206,8 @@
> #define STRTAB_L1_DESC_SPAN GENMASK_ULL(4, 0)
> #define STRTAB_L1_DESC_L2PTR_MASK GENMASK_ULL(51, 6)
>
> -#define STRTAB_STE_DWORDS 8
> -
> struct arm_smmu_ste {
> - __le64 data[STRTAB_STE_DWORDS];
> + __le64 data[8];
> };
>
> #define STRTAB_STE_0_V (1UL << 0)
> @@ -612,7 +610,10 @@ struct arm_smmu_s2_cfg {
> };
>
> struct arm_smmu_strtab_cfg {
> - __le64 *strtab;
> + union {
> + struct arm_smmu_ste *linear;
> + __le64 *l1_desc;
I agree with Nicolin, that it is confusing to have both l1_desc,
I guess a rename is sufficient.
> + } strtab;
> dma_addr_t strtab_dma;
> struct arm_smmu_strtab_l1_desc *l1_desc;
> unsigned int num_l1_ents;
> --
> 2.45.2
>
Thanks,
Mostafa
next prev parent reply other threads:[~2024-06-04 15:52 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-03 22:31 [PATCH 0/7] Tidy some minor things in the stream table/cd table area Jason Gunthorpe
2024-06-03 22:31 ` [PATCH 1/7] iommu/arm-smmu-v3: Split struct arm_smmu_strtab_cfg.strtab Jason Gunthorpe
2024-06-04 8:32 ` Nicolin Chen
2024-06-04 12:59 ` Jason Gunthorpe
2024-06-04 18:28 ` Nicolin Chen
2024-06-04 19:02 ` Jason Gunthorpe
2024-06-04 19:28 ` Nicolin Chen
2024-06-04 15:52 ` Mostafa Saleh [this message]
2024-06-05 23:51 ` Jason Gunthorpe
2024-06-03 22:31 ` [PATCH 2/7] iommu/arm-smmu-v3: Do not zero the strtab twice Jason Gunthorpe
2024-06-04 15:56 ` Mostafa Saleh
2024-06-05 21:22 ` Jason Gunthorpe
2024-06-03 22:31 ` [PATCH 3/7] iommu/arm-smmu-v3: Shrink the strtab l1_desc array Jason Gunthorpe
2024-06-04 16:01 ` Mostafa Saleh
2024-06-03 22:31 ` [PATCH 4/7] iommu/arm-smmu-v3: Split struct arm_smmu_ctx_desc_cfg.cdtab Jason Gunthorpe
2024-06-04 16:07 ` Mostafa Saleh
2024-06-06 23:59 ` Jason Gunthorpe
2024-06-03 22:31 ` [PATCH 5/7] iommu/arm-smmu-v3: Do not use devm for the cd table allocations Jason Gunthorpe
2024-06-03 22:31 ` [PATCH 6/7] iommu/arm-smmu-v3: Shrink the cdtab l1_desc array Jason Gunthorpe
2024-06-04 16:14 ` Mostafa Saleh
2024-06-03 22:31 ` [PATCH 7/7] iommu/arm-smmu-v3: Use the new rb tree helpers Jason Gunthorpe
2024-06-04 16:22 ` Mostafa Saleh
2024-06-03 22:41 ` [PATCH 0/7] Tidy some minor things in the stream table/cd table area Nicolin Chen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Zl84JwoxGFOLzKSC@google.com \
--to=smostafa@google.com \
--cc=iommu@lists.linux.dev \
--cc=jgg@nvidia.com \
--cc=joro@8bytes.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=mshavit@google.com \
--cc=nicolinc@nvidia.com \
--cc=patches@lists.linux.dev \
--cc=robin.murphy@arm.com \
--cc=ryan.roberts@arm.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).