From: Will Deacon <will@kernel.org>
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>,
Michael Shavit <mshavit@google.com>,
Nicolin Chen <nicolinc@nvidia.com>,
patches@lists.linux.dev, Ryan Roberts <ryan.roberts@arm.com>,
Mostafa Saleh <smostafa@google.com>
Subject: Re: [PATCH v3 9/9] iommu/arm-smmu-v3: Reorganize struct arm_smmu_ctx_desc_cfg
Date: Fri, 6 Sep 2024 14:22:22 +0100 [thread overview]
Message-ID: <20240906132222.GD16959@willie-the-truck> (raw)
In-Reply-To: <9-v3-9fef8cdc2ff6+150d1-smmuv3_tidy_jgg@nvidia.com>
On Tue, Aug 06, 2024 at 08:31:23PM -0300, Jason Gunthorpe wrote:
> @@ -1373,8 +1368,6 @@ void arm_smmu_clear_cd(struct arm_smmu_master *master, ioasid_t ssid)
>
> 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 *cd_table = &master->cd_table;
> @@ -1385,71 +1378,67 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master)
> if (!(smmu->features & ARM_SMMU_FEAT_2_LVL_CDTAB) ||
> max_contexts <= CTXDESC_L2_ENTRIES) {
> cd_table->s1fmt = STRTAB_STE_0_S1FMT_LINEAR;
> - cd_table->num_l1_ents = max_contexts;
> + cd_table->linear.num_ents = max_contexts;
>
> - l1size = max_contexts * sizeof(struct arm_smmu_cd);
> + cd_table->linear.table = dma_alloc_coherent(
> + smmu->dev, max_contexts * sizeof(struct arm_smmu_cd),
> + &cd_table->cdtab_dma, GFP_KERNEL);
> + if (!cd_table->linear.table)
> + return -ENOMEM;
> } else {
> cd_table->s1fmt = STRTAB_STE_0_S1FMT_64K_L2;
> - cd_table->num_l1_ents = DIV_ROUND_UP(max_contexts,
> - CTXDESC_L2_ENTRIES);
> + cd_table->l2.num_l1_ents =
> + DIV_ROUND_UP(max_contexts, CTXDESC_L2_ENTRIES);
>
> - cd_table->l1_desc = kcalloc(cd_table->num_l1_ents,
> - sizeof(*cd_table->l1_desc),
> - GFP_KERNEL);
> - if (!cd_table->l1_desc)
> + cd_table->l2.l2ptrs = kcalloc(cd_table->l2.num_l1_ents,
> + sizeof(*cd_table->l2.l2ptrs),
> + GFP_KERNEL);
> + if (!cd_table->l2.l2ptrs)
> return -ENOMEM;
>
> - l1size = cd_table->num_l1_ents *
> - sizeof(struct arm_smmu_cdtab_l1);
> + cd_table->l2.l1tab = dma_alloc_coherent(
> + smmu->dev,
> + cd_table->l2.num_l1_ents *
> + sizeof(struct arm_smmu_cdtab_l1),
> + &cd_table->cdtab_dma, GFP_KERNEL);
> + if (!cd_table->l2.l1tab) {
> + kfree(cd_table->l2.l2ptrs);
> + cd_table->l2.l2ptrs = NULL;
> + return -ENOMEM;
> + }
> }
> -
> - cd_table->cdtab = dma_alloc_coherent(smmu->dev, l1size,
> - &cd_table->cdtab_dma, GFP_KERNEL);
> - if (!cd_table->cdtab) {
> - dev_warn(smmu->dev, "failed to allocate context descriptor\n");
> - ret = -ENOMEM;
> - goto err_free_l1;
> - }
> -
> return 0;
> -
> -err_free_l1:
> - if (cd_table->l1_desc) {
> - kfree(cd_table->l1_desc);
> - cd_table->l1_desc = NULL;
> - }
> - return ret;
Why inline the error path here? Sure, I get that it works both ways, but
it seems a little gratuitous to me.
Will
next prev parent reply other threads:[~2024-09-06 13:23 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-06 23:31 [PATCH v3 0/9] Tidy some minor things in the stream table/cd table area Jason Gunthorpe
2024-08-06 23:31 ` [PATCH v3 1/9] iommu/arm-smmu-v3: Use the new rb tree helpers Jason Gunthorpe
2024-09-06 13:23 ` Will Deacon
2024-08-06 23:31 ` [PATCH v3 2/9] iommu/arm-smmu-v3: Add arm_smmu_strtab_l1/2_idx() Jason Gunthorpe
2024-09-06 13:18 ` Will Deacon
2024-09-06 14:40 ` Jason Gunthorpe
2024-08-06 23:31 ` [PATCH v3 3/9] iommu/arm-smmu-v3: Add types for each level of the 2 level stream table Jason Gunthorpe
2024-08-06 23:31 ` [PATCH v3 4/9] iommu/arm-smmu-v3: Reorganize struct arm_smmu_strtab_cfg Jason Gunthorpe
2024-09-06 13:19 ` Will Deacon
2024-09-06 15:06 ` Jason Gunthorpe
2024-08-06 23:31 ` [PATCH v3 5/9] iommu/arm-smmu-v3: Remove strtab_base/cfg Jason Gunthorpe
2024-08-06 23:31 ` [PATCH v3 6/9] iommu/arm-smmu-v3: Do not use devm for the cd table allocations Jason Gunthorpe
2024-08-06 23:31 ` [PATCH v3 7/9] iommu/arm-smmu-v3: Shrink the cdtab l1_desc array Jason Gunthorpe
2024-09-06 13:21 ` Will Deacon
2024-08-06 23:31 ` [PATCH v3 8/9] iommu/arm-smmu-v3: Add types for each level of the CD table Jason Gunthorpe
2024-08-06 23:31 ` [PATCH v3 9/9] iommu/arm-smmu-v3: Reorganize struct arm_smmu_ctx_desc_cfg Jason Gunthorpe
2024-09-06 13:22 ` Will Deacon [this message]
2024-09-06 15:13 ` Jason Gunthorpe
2024-09-05 19:25 ` [PATCH v3 0/9] Tidy some minor things in the stream table/cd table area Jason Gunthorpe
2024-09-05 20:10 ` Nicolin Chen
2024-09-06 14:35 ` Will Deacon
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=20240906132222.GD16959@willie-the-truck \
--to=will@kernel.org \
--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=smostafa@google.com \
/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