* [PATCH v2] iommu: Improve the performance for direct_mapping
@ 2020-12-07 9:35 Yong Wu
2020-12-07 11:05 ` Will Deacon
0 siblings, 1 reply; 2+ messages in thread
From: Yong Wu @ 2020-12-07 9:35 UTC (permalink / raw)
To: Joerg Roedel, Will Deacon, Robin Murphy
Cc: Matthias Brugger, Krzysztof Kozlowski, Tomasz Figa,
linux-mediatek, srv_heupstream, linux-kernel, linux-arm-kernel,
iommu, yong.wu, youlin.pei, Nicolas Boichat, anan.sun, chao.hao
Currently direct_mapping always use the smallest pgsize which is SZ_4K
normally to mapping. This is unnecessary. we could gather the size, and
call iommu_map then, iommu_map could decide how to map better with the
just right pgsize.
From the original comment, we should take care overlap, otherwise,
iommu_map may return -EEXIST. In this overlap case, we should map the
previous region before overlap firstly. then map the left part.
Each a iommu device will call this direct_mapping when its iommu
initialize, This patch is effective to improve the boot/initialization
time especially while it only needs level 1 mapping.
Signed-off-by: Anan Sun <anan.sun@mediatek.com>
Signed-off-by: Yong Wu <yong.wu@mediatek.com>
---
change notes:
v2: Refine the code flow.
v1: https://lore.kernel.org/linux-iommu/20201120090628.6566-1-yong.wu@mediatek.com/
base on v5.10-rc1.
---
drivers/iommu/iommu.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 8c470f451a32..1a91decb95fa 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -737,6 +737,7 @@ static int iommu_create_device_direct_mappings(struct iommu_group *group,
/* We need to consider overlapping regions for different devices */
list_for_each_entry(entry, &mappings, list) {
dma_addr_t start, end, addr;
+ size_t map_size = 0;
if (domain->ops->apply_resv_region)
domain->ops->apply_resv_region(dev, domain, entry);
@@ -748,16 +749,27 @@ static int iommu_create_device_direct_mappings(struct iommu_group *group,
entry->type != IOMMU_RESV_DIRECT_RELAXABLE)
continue;
- for (addr = start; addr < end; addr += pg_size) {
+ for (addr = start; addr <= end; addr += pg_size) {
phys_addr_t phys_addr;
+ if (addr == end)
+ goto map_end;
+
phys_addr = iommu_iova_to_phys(domain, addr);
- if (phys_addr)
+ if (!phys_addr) {
+ map_size += pg_size;
continue;
+ }
- ret = iommu_map(domain, addr, addr, pg_size, entry->prot);
- if (ret)
- goto out;
+map_end:
+ if (map_size) {
+ ret = iommu_map(domain, addr - map_size,
+ addr - map_size, map_size,
+ entry->prot);
+ if (ret)
+ goto out;
+ map_size = 0;
+ }
}
}
--
2.18.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] iommu: Improve the performance for direct_mapping
2020-12-07 9:35 [PATCH v2] iommu: Improve the performance for direct_mapping Yong Wu
@ 2020-12-07 11:05 ` Will Deacon
0 siblings, 0 replies; 2+ messages in thread
From: Will Deacon @ 2020-12-07 11:05 UTC (permalink / raw)
To: Yong Wu, Robin Murphy, Joerg Roedel
Cc: catalin.marinas, kernel-team, Will Deacon, srv_heupstream,
linux-arm-kernel, youlin.pei, chao.hao, anan.sun, iommu,
linux-kernel, linux-mediatek, Nicolas Boichat, Tomasz Figa,
Krzysztof Kozlowski, Matthias Brugger
On Mon, 7 Dec 2020 17:35:53 +0800, Yong Wu wrote:
> Currently direct_mapping always use the smallest pgsize which is SZ_4K
> normally to mapping. This is unnecessary. we could gather the size, and
> call iommu_map then, iommu_map could decide how to map better with the
> just right pgsize.
>
> >From the original comment, we should take care overlap, otherwise,
> iommu_map may return -EEXIST. In this overlap case, we should map the
> previous region before overlap firstly. then map the left part.
>
> [...]
Applied to arm64 (for-next/iommu/misc), thanks!
[1/1] iommu: Improve the performance for direct_mapping
https://git.kernel.org/arm64/c/093b32a849b3
Cheers,
--
Will
https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-12-07 11:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-07 9:35 [PATCH v2] iommu: Improve the performance for direct_mapping Yong Wu
2020-12-07 11:05 ` Will Deacon
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).