From: "Leizhen \(ThunderTown\) via iommu" <iommu@lists.linux-foundation.org>
To: John Garry <john.garry@huawei.com>, <joro@8bytes.org>,
<will@kernel.org>, <robin.murphy@arm.com>
Cc: jean-philippe@linaro.org, jasowang@redhat.com, mst@redhat.com,
linuxarm@huawei.com, linux-kernel@vger.kernel.org,
virtualization@lists.linux-foundation.org,
iommu@lists.linux-foundation.org
Subject: Re: [PATCH RESEND v5 5/5] iova: Add iova_len argument to iova_domain_init_rcaches()
Date: Thu, 7 Apr 2022 16:27:18 +0800 [thread overview]
Message-ID: <b09aeef5-106c-b477-e16b-a537929cb7c1@huawei.com> (raw)
In-Reply-To: <1649071634-188535-6-git-send-email-john.garry@huawei.com>
On 2022/4/4 19:27, John Garry wrote:
> Add max opt argument to iova_domain_init_rcaches(), and use it to set the
> rcaches range.
>
> Also fix up all users to set this value (at 0, meaning use default),
> including a wrapper for that, iova_domain_init_rcaches_default().
>
> For dma-iommu.c we derive the iova_len argument from the IOMMU group
> max opt DMA size.
>
> Signed-off-by: John Garry <john.garry@huawei.com>
> ---
> drivers/iommu/dma-iommu.c | 15 ++++++++++++++-
> drivers/iommu/iova.c | 19 ++++++++++++++++---
> drivers/vdpa/vdpa_user/iova_domain.c | 4 ++--
> include/linux/iova.h | 3 ++-
> 4 files changed, 34 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
> index 42ca42ff1b5d..19f35624611c 100644
> --- a/drivers/iommu/dma-iommu.c
> +++ b/drivers/iommu/dma-iommu.c
> @@ -525,6 +525,8 @@ static int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base,
> struct iommu_dma_cookie *cookie = domain->iova_cookie;
> unsigned long order, base_pfn;
> struct iova_domain *iovad;
> + size_t max_opt_dma_size;
> + unsigned long iova_len = 0;
> int ret;
>
> if (!cookie || cookie->type != IOMMU_DMA_IOVA_COOKIE)
> @@ -560,7 +562,18 @@ static int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base,
> }
>
> init_iova_domain(iovad, 1UL << order, base_pfn);
> - ret = iova_domain_init_rcaches(iovad);
> +
> + max_opt_dma_size = iommu_group_get_max_opt_dma_size(dev->iommu_group);
> + if (max_opt_dma_size) {
> + unsigned long shift = __ffs(1UL << order);
> +
> + iova_len = roundup_pow_of_two(max_opt_dma_size);
> + iova_len >>= shift;
> + if (!iova_len)
> + iova_len = 1;
How about move "iovad->rcache_max_size = iova_len_to_rcache_max(iova_len);" here? So that,
iova_domain_init_rcaches() can remain the same. And iova_domain_init_rcaches_default() does
not need to be added.
> + }
> +
> + ret = iova_domain_init_rcaches(iovad, iova_len);
> if (ret)
> return ret;
>
> diff --git a/drivers/iommu/iova.c b/drivers/iommu/iova.c
> index 5c22b9187b79..d65e79e132ee 100644
> --- a/drivers/iommu/iova.c
> +++ b/drivers/iommu/iova.c
> @@ -706,12 +706,20 @@ static void iova_magazine_push(struct iova_magazine *mag, unsigned long pfn)
> mag->pfns[mag->size++] = pfn;
> }
>
> -int iova_domain_init_rcaches(struct iova_domain *iovad)
> +static unsigned long iova_len_to_rcache_max(unsigned long iova_len)
> +{
> + return order_base_2(iova_len) + 1;
> +}
> +
> +int iova_domain_init_rcaches(struct iova_domain *iovad, unsigned long iova_len)
> {
> unsigned int cpu;
> int i, ret;
>
> - iovad->rcache_max_size = 6; /* Arbitrarily high default */
> + if (iova_len)
> + iovad->rcache_max_size = iova_len_to_rcache_max(iova_len);
> + else
> + iovad->rcache_max_size = 6; /* Arbitrarily high default */
>
> iovad->rcaches = kcalloc(iovad->rcache_max_size,
> sizeof(struct iova_rcache),
> @@ -755,7 +763,12 @@ int iova_domain_init_rcaches(struct iova_domain *iovad)
> free_iova_rcaches(iovad);
> return ret;
> }
> -EXPORT_SYMBOL_GPL(iova_domain_init_rcaches);
> +
> +int iova_domain_init_rcaches_default(struct iova_domain *iovad)
> +{
> + return iova_domain_init_rcaches(iovad, 0);
> +}
> +EXPORT_SYMBOL_GPL(iova_domain_init_rcaches_default);
>
> /*
> * Try inserting IOVA range starting with 'iova_pfn' into 'rcache', and
> diff --git a/drivers/vdpa/vdpa_user/iova_domain.c b/drivers/vdpa/vdpa_user/iova_domain.c
> index 6daa3978d290..3a2acef98a4a 100644
> --- a/drivers/vdpa/vdpa_user/iova_domain.c
> +++ b/drivers/vdpa/vdpa_user/iova_domain.c
> @@ -514,12 +514,12 @@ vduse_domain_create(unsigned long iova_limit, size_t bounce_size)
> spin_lock_init(&domain->iotlb_lock);
> init_iova_domain(&domain->stream_iovad,
> PAGE_SIZE, IOVA_START_PFN);
> - ret = iova_domain_init_rcaches(&domain->stream_iovad);
> + ret = iova_domain_init_rcaches_default(&domain->stream_iovad);
> if (ret)
> goto err_iovad_stream;
> init_iova_domain(&domain->consistent_iovad,
> PAGE_SIZE, bounce_pfns);
> - ret = iova_domain_init_rcaches(&domain->consistent_iovad);
> + ret = iova_domain_init_rcaches_default(&domain->consistent_iovad);
> if (ret)
> goto err_iovad_consistent;
>
> diff --git a/include/linux/iova.h b/include/linux/iova.h
> index 02f7222fa85a..56281434ce0c 100644
> --- a/include/linux/iova.h
> +++ b/include/linux/iova.h
> @@ -95,7 +95,8 @@ struct iova *reserve_iova(struct iova_domain *iovad, unsigned long pfn_lo,
> unsigned long pfn_hi);
> void init_iova_domain(struct iova_domain *iovad, unsigned long granule,
> unsigned long start_pfn);
> -int iova_domain_init_rcaches(struct iova_domain *iovad);
> +int iova_domain_init_rcaches(struct iova_domain *iovad, unsigned long iova_len);
> +int iova_domain_init_rcaches_default(struct iova_domain *iovad);
> struct iova *find_iova(struct iova_domain *iovad, unsigned long pfn);
> void put_iova_domain(struct iova_domain *iovad);
> #else
>
--
Regards,
Zhen Lei
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu
next prev parent reply other threads:[~2022-04-07 8:27 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-04 11:27 [PATCH RESEND v5 0/5] iommu: Allow IOVA rcache range be configured John Garry via iommu
2022-04-04 11:27 ` [PATCH RESEND v5 1/5] iommu: Refactor iommu_group_store_type() John Garry via iommu
2022-04-07 7:40 ` Leizhen (ThunderTown) via iommu
2022-07-06 12:00 ` Will Deacon
2022-07-06 12:03 ` John Garry via iommu
2022-07-06 12:12 ` Will Deacon
2022-04-04 11:27 ` [PATCH RESEND v5 2/5] iova: Allow rcache range upper limit to be flexible John Garry via iommu
2022-04-07 7:52 ` Leizhen (ThunderTown) via iommu
2022-07-06 12:11 ` Will Deacon
2022-07-06 12:10 ` Will Deacon
2022-04-04 11:27 ` [PATCH RESEND v5 3/5] iommu: Allow iommu_change_dev_def_domain() realloc same default domain type John Garry via iommu
2022-04-04 11:27 ` [PATCH RESEND v5 4/5] iommu: Allow max opt DMA len be set for a group via sysfs John Garry via iommu
2022-04-07 8:21 ` Leizhen (ThunderTown) via iommu
2022-04-07 14:00 ` John Garry via iommu
2022-04-04 11:27 ` [PATCH RESEND v5 5/5] iova: Add iova_len argument to iova_domain_init_rcaches() John Garry via iommu
2022-04-07 8:27 ` Leizhen (ThunderTown) via iommu [this message]
2022-04-07 13:52 ` John Garry via iommu
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=b09aeef5-106c-b477-e16b-a537929cb7c1@huawei.com \
--to=iommu@lists.linux-foundation.org \
--cc=jasowang@redhat.com \
--cc=jean-philippe@linaro.org \
--cc=john.garry@huawei.com \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=mst@redhat.com \
--cc=robin.murphy@arm.com \
--cc=thunder.leizhen@huawei.com \
--cc=virtualization@lists.linux-foundation.org \
--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