From: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
To: Dmitry Osipenko <digetx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
Navneet Kumar <navneetk-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org
Cc: linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
jonathanh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org
Subject: Re: [PATCH 1/5] iommu/tegra-smmu: Fix domain_alloc
Date: Thu, 17 Jan 2019 16:50:08 +0000 [thread overview]
Message-ID: <4f3104b7-120e-d71b-e7ea-9790ed2a3c97@arm.com> (raw)
In-Reply-To: <e55f408d-d518-f12d-4233-1b70263400f4-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
On 17/01/2019 15:13, Dmitry Osipenko wrote:
> 16.01.2019 23:50, Navneet Kumar пишет:
>> * Allocate dma iova cookie for a domain while adding dma iommu
>> devices.
>> * Perform a stricter check for domain type parameter.
>>
>
> Commit message should tell what exactly is getting "fixed". Apparently you're trying to support T132 ARM64 here.
>
>> Signed-off-by: Navneet Kumar <navneetk@nvidia.com>
>> ---
>> drivers/iommu/tegra-smmu.c | 43 +++++++++++++++++++++++++++----------------
>> 1 file changed, 27 insertions(+), 16 deletions(-)
>>
>> diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
>> index 543f7c9..ee4d8a8 100644
>> --- a/drivers/iommu/tegra-smmu.c
>> +++ b/drivers/iommu/tegra-smmu.c
>> @@ -16,6 +16,7 @@
>> #include <linux/platform_device.h>
>> #include <linux/slab.h>
>> #include <linux/dma-mapping.h>
>> +#include <linux/dma-iommu.h>
>>
>> #include <soc/tegra/ahb.h>
>> #include <soc/tegra/mc.h>
>> @@ -271,8 +272,10 @@ static bool tegra_smmu_capable(enum iommu_cap cap)
>> static struct iommu_domain *tegra_smmu_domain_alloc(unsigned type)
>> {
>> struct tegra_smmu_as *as;
>> + int ret;
>>
>> - if (type != IOMMU_DOMAIN_UNMANAGED)
>> + if (type != IOMMU_DOMAIN_UNMANAGED && type != IOMMU_DOMAIN_DMA &&
>> + type != IOMMU_DOMAIN_IDENTITY)
>> return NULL;
>
> Should be better to write these lines like this for the sake of readability:
>
> if (type != IOMMU_DOMAIN_UNMANAGED &&
> type != IOMMU_DOMAIN_DMA &&
> type != IOMMU_DOMAIN_IDENTITY)
> return NULL;
Furthermore, AFAICS there's no special handling being added for identity
domains - don't pretend to support them by giving back a regular
translation domain, that's just misleading and broken.
>
>
>>
>> as = kzalloc(sizeof(*as), GFP_KERNEL);
>> @@ -281,26 +284,22 @@ static struct iommu_domain *tegra_smmu_domain_alloc(unsigned type)
>>
>> as->attr = SMMU_PD_READABLE | SMMU_PD_WRITABLE | SMMU_PD_NONSECURE;
>>
>> + ret = (type == IOMMU_DOMAIN_DMA) ? iommu_get_dma_cookie(&as->domain) :
>> + -ENODEV;
>
> This makes to fail allocation of domain that has type other than IOMMU_DOMAIN_DMA.
>
> Should be:
>
> if (type == IOMMU_DOMAIN_DMA) {
> err = iommu_get_dma_cookie(&as->domain);
> if (err)
> goto free_as;
> }
>
>
>> + if (ret)
>> + goto free_as;
>> +
>> as->pd = alloc_page(GFP_KERNEL | __GFP_DMA | __GFP_ZERO);
>> - if (!as->pd) {
>> - kfree(as);
>> - return NULL;
>> - }
>> + if (!as->pd)
>> + goto put_dma_cookie;
>>
>> as->count = kcalloc(SMMU_NUM_PDE, sizeof(u32), GFP_KERNEL);
>> - if (!as->count) {
>> - __free_page(as->pd);
>> - kfree(as);
>> - return NULL;
>> - }
>> + if (!as->count)
>> + goto free_pd_range;
>>
>> as->pts = kcalloc(SMMU_NUM_PDE, sizeof(*as->pts), GFP_KERNEL);
>> - if (!as->pts) {
>> - kfree(as->count);
>> - __free_page(as->pd);
>> - kfree(as);
>> - return NULL;
>> - }
>> + if (!as->pts)
>> + goto free_pts;
>>
>> /* setup aperture */
>> as->domain.geometry.aperture_start = 0;
>> @@ -308,6 +307,18 @@ static struct iommu_domain *tegra_smmu_domain_alloc(unsigned type)
>> as->domain.geometry.force_aperture = true;
>>
>> return &as->domain;
>> +
>> +free_pts:
>> + kfree(as->pts);
>> +free_pd_range:
>> + __free_page(as->pd);
>> +put_dma_cookie:
>> + if (type == IOMMU_DOMAIN_DMA)
FWIW you don't strictly need that check - since domain->iova_cookie
won't be set for other domain types anyway, iommu_put_dma_cookie() will
simply ignore them.
>> + iommu_put_dma_cookie(&as->domain);
>> +free_as:
>> + kfree(as);
>> +
>> + return NULL;
>> }
>>
>> static void tegra_smmu_domain_free(struct iommu_domain *domain)
How about not leaking the cookie when you free a DMA ops domain?
Robin.
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
next prev parent reply other threads:[~2019-01-17 16:50 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-16 20:50 [PATCH 1/5] iommu/tegra-smmu: Fix domain_alloc Navneet Kumar
[not found] ` <1547671814-30088-1-git-send-email-navneetk-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2019-01-16 20:50 ` [PATCH 2/5] iommu/tegra-smmu: Use non-secure register for flushing Navneet Kumar
[not found] ` <1547671814-30088-2-git-send-email-navneetk-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2019-01-17 15:25 ` Dmitry Osipenko
[not found] ` <340ed36a-297f-f1e6-b863-651454cf39d8-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2019-01-24 18:29 ` navneet kumar
[not found] ` <ece55c12-2a6f-e12f-597c-ef15001e66a3-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2019-01-24 21:27 ` Dmitry Osipenko
2019-01-16 20:50 ` [PATCH 3/5] iommu/tegra-smmu: Fix client enablement order Navneet Kumar
2019-01-16 20:50 ` [PATCH 4/5] iommu/tegra-smmu: Add PCI support Navneet Kumar
2019-01-16 20:50 ` [PATCH 5/5] iommu/tegra-smmu: Add resv_regions ops Navneet Kumar
[not found] ` <1547671814-30088-5-git-send-email-navneetk-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
2019-01-17 17:06 ` Robin Murphy
2019-01-17 15:13 ` [PATCH 1/5] iommu/tegra-smmu: Fix domain_alloc Dmitry Osipenko
[not found] ` <e55f408d-d518-f12d-4233-1b70263400f4-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2019-01-17 16:50 ` Robin Murphy [this message]
[not found] ` <4f3104b7-120e-d71b-e7ea-9790ed2a3c97-5wv7dgnIgG8@public.gmane.org>
2019-01-24 22:15 ` navneet kumar
2019-02-14 11:12 ` Thierry Reding
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=4f3104b7-120e-d71b-e7ea-9790ed2a3c97@arm.com \
--to=robin.murphy-5wv7dgnigg8@public.gmane.org \
--cc=digetx-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=jonathanh-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
--cc=joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org \
--cc=linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=navneetk-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
--cc=thierry.reding-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.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