RE: [PATCH] iommu/iova: Free all CPU rcache for retry when iova alloc failure

2022-03-06 Thread yf.wang--- via iommu
On Fri, 2022-03-04 at 14:03 +, Robin Murphy wrote: > > OK, so either there's a mystery bug where IOVAs somehow get freed on > offline CPUs, or the hotplug notifier isn't working correctly, or > you've > contrived a situation where alloc_iova_fast() is actually racing > against >

RE: [PATCH] iommu/iova: Free all CPU rcache for retry when iova alloc failure

2022-03-06 Thread yf.wang--- via iommu
On 2022-03-04 9:22, John Garry wrote: > On 04/03/2022 04:46, yf.wang--- via iommu wrote: > > * MEDIATEK Confidentiality Notice > > The > > information contained in this e-mail message (including any > > attachments) may be confidenti

RE: [PATCH] iommu/iova: Free all CPU rcache for retry when iova alloc failure

2022-03-06 Thread yf.wang--- via iommu
On Fri, 2022-03-04 at 14:03 +, Robin Murphy wrote: > > OK, so either there's a mystery bug where IOVAs somehow get freed on > offline CPUs, or the hotplug notifier isn't working correctly, or > you've > contrived a situation where alloc_iova_fast() is actually racing > against >

[PATCH v2] iommu/iova: Reset max32_alloc_size after cleaning rcache in the fail path

2022-02-28 Thread yf.wang--- via iommu
From: Yunfei Wang In alloc_iova_fast function, if __alloc_and_insert_iova_range fail, alloc_iova_fast will try flushing rcache and retry alloc iova, but this has an issue: Since __alloc_and_insert_iova_range fail will set the current alloc iova size to max32_alloc_size (iovad->max32_alloc_size

[PATCH] iommu/iova: Reset max32_alloc_size after cleaning rcache in the fail path

2022-02-28 Thread yf.wang--- via iommu
From: Yunfei Wang In alloc_iova_fast function, if __alloc_and_insert_iova_range fail, alloc_iova_fast will try flushing rcache and retry alloc iova, but this has an issue: Since __alloc_and_insert_iova_range fail will set the current alloc iova size to max32_alloc_size (iovad->max32_alloc_size

Re: [PATCH v2] iommu/iova: Reset max32_alloc_size after cleaning

2022-03-03 Thread yf.wang--- via iommu
From: yf.w...@mediatek.com On Thu, 2022-03-03 at 07:52 +0800, Miles Chen wrote: > Thanks for your explanation. > > YF showed me some numbers yesterday and maybe we can have a further > discussion in that test case. (It looks like that some iovas are > freed but > their pfn_lo(s) are less than

[PATCH] iommu/iova: Free all CPU rcache for retry when iova alloc failure

2022-03-03 Thread yf.wang--- via iommu
From: Yunfei Wang In alloc_iova_fast function, if an iova alloc request fail, it will free the iova ranges present in the percpu iova rcaches and free global iova rcache and then retry, but flushing CPU iova rcaches only for each online CPU, which will cause incomplete rcache cleaning, and iova

Re: [PATCH] iommu/iova: Free all CPU rcache for retry when iova alloc failure

2022-03-03 Thread yf.wang--- via iommu
On Fri, 2022-03-04 at 12:46 +0800, yf.w...@mediatek.com wrote: > From: Yunfei Wang > > In alloc_iova_fast function, if an iova alloc request fail, > it will free the iova ranges present in the percpu iova > rcaches and free global iova rcache and then retry, but > flushing CPU iova rcaches only

[PATCH v4 1/2] iommu/io-pgtable-arm-v7s: Add a quirk to allow pgtable PA up to 35bit

2022-05-16 Thread yf.wang--- via iommu
From: Yunfei Wang The calling to kmem_cache_alloc for level 2 pgtable allocation may run in atomic context, and it fails sometimes when DMA32 zone runs out of memory. Since Mediatek IOMMU hardware support at most 35bit PA in pgtable, so add a quirk to allow the PA of pgtables support up to

[PATCH v4 2/2] iomm/mediatek: Allow page table PA up to 35bit

2022-05-16 Thread yf.wang--- via iommu
From: Yunfei Wang Add the quirk IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT support, so that allows page table PA up to 35bit, not only in ZONE_DMA32. Signed-off-by: Ning Li Signed-off-by: Yunfei Wang --- drivers/iommu/mtk_iommu.c | 29 + 1 file changed, 25 insertions(+), 4

[PATCH] iommu/dma: Fix race condition during iova_domain initialization

2022-05-30 Thread yf.wang--- via iommu
From: Yunfei Wang When many devices share the same iova domain, iommu_dma_init_domain() may be called at the same time. The checking of iovad->start_pfn will all get false in iommu_dma_init_domain() and both enter init_iova_domain() to do iovad initialization. Fix this by protecting

[PATCH v3 1/2] iommu/io-pgtable-arm-v7s: Add a quirk to allow pgtable PA up to 35bit

2022-05-12 Thread yf.wang--- via iommu
From: Yunfei Wang The calling to kmem_cache_alloc for level 2 pgtable allocation may run in atomic context, and it fails sometimes when DMA32 zone runs out of memory. Since Mediatek IOMMU hardware support at most 35bit PA in pgtable, so add a quirk to allow the PA of pgtables support up to

[PATCH v3 2/2] iomm/mediatek: Allow page table PA up to 35bit

2022-05-12 Thread yf.wang--- via iommu
From: Yunfei Wang Add the quirk IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT support, so that allows page table PA up to 35bit, not only in ZONE_DMA32. Signed-off-by: Ning Li Signed-off-by: Yunfei Wang --- drivers/iommu/mtk_iommu.c | 29 + 1 file changed, 25 insertions(+), 4

[PATCH v2 2/2] iomm/mediatek: Allow page table PA up to 35bit

2022-05-12 Thread yf.wang--- via iommu
From: Yunfei Wang Add the quirk IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT support, so that allows page table PA up to 35bit, not only in ZONE_DMA32. Signed-off-by: Ning Li Signed-off-by: Yunfei Wang --- drivers/iommu/mtk_iommu.c | 29 + 1 file changed, 25 insertions(+), 4

[PATCH v2 1/2] iommu/io-pgtable-arm-v7s: Add a quirk to allow pgtable PA up to 35bit

2022-05-12 Thread yf.wang--- via iommu
From: Yunfei Wang The calling to kmem_cache_alloc for level 2 pgtable allocation may run in atomic context, and it fails sometimes when DMA32 zone runs out of memory. Since Mediatek IOMMU hardware support at most 35bit PA in pgtable, so add a quirk to allow the PA of pgtables support up to

Re: [PATCH v5 1/2] iommu/io-pgtable-arm-v7s: Add a quirk to allow pgtable PA up to 35bit

2022-05-24 Thread yf.wang--- via iommu
On Thu, 2022-05-19 at 14:27 +0800, Miles Chen wrote: > Hi Yunfei, > > > The calling to kmem_cache_alloc for level 2 pgtable allocation may > > run > > in atomic context, and it fails sometimes when DMA32 zone runs out > > of > > memory. > > > > Since Mediatek IOMMU hardware support at most 35bit

[PATCH v6 2/2] iommu/mediatek: Allow page table PA up to 35bit

2022-05-25 Thread yf.wang--- via iommu
From: Yunfei Wang The level 1 and level 2 pgtable are both allocated in ZONE_DMA32, and may have two possible problem: 1.The level 2 pgtable is allocated in ZONE_DMA32 with atomic flag, and it may fail if ZONE_DMA32 memory is used out. 2.Single memory feature will make ZONE_DMA32 empty, and

[PATCH v6 1/2] iommu/io-pgtable-arm-v7s: Add a quirk to allow pgtable PA up to 35bit

2022-05-25 Thread yf.wang--- via iommu
From: Yunfei Wang The calling to kmem_cache_alloc for level 2 pgtable allocation may run in atomic context, and it fails sometimes when DMA32 zone runs out of memory. Since Mediatek IOMMU hardware support at most 35bit PA in pgtable, so add a quirk to allow the PA of pgtables support up to

Re: [PATCH v5 2/2] iommu/mediatek: Allow page table PA up to 35bit

2022-05-24 Thread yf.wang--- via iommu
On Thu, 2022-05-19 at 14:58 +0800, Yong Wu wrote: > On Mon, 2022-05-16 at 22:16 +0800, yf.w...@mediatek.com wrote: > > From: Yunfei Wang > > > > Add the quirk IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT support, so that > > allows > > page table PA up to 35bit, not only in ZONE_DMA32. > > Comment why

[PATCH v7 2/2] iommu/mediatek: Allow page table PA up to 35bit

2022-05-30 Thread yf.wang--- via iommu
From: Yunfei Wang Single memory zone feature will remove ZONE_DMA32 and ZONE_DMA. So add the quirk IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT to let level 1 and level 2 pgtable support at most 35bit PA. Signed-off-by: Ning Li Signed-off-by: Yunfei Wang --- drivers/iommu/mtk_iommu.c | 29

[PATCH v7 1/2] iommu/io-pgtable-arm-v7s: Add a quirk to allow pgtable PA up to 35bit

2022-05-30 Thread yf.wang--- via iommu
From: Yunfei Wang Single memory zone feature will remove ZONE_DMA32 and ZONE_DMA and cause pgtable PA size larger than 32bit. Since Mediatek IOMMU hardware support at most 35bit PA in pgtable, so add a quirk to allow the PA of pgtables support up to bit35. Signed-off-by: Ning Li

[PATCH v5 1/2] iommu/io-pgtable-arm-v7s: Add a quirk to allow pgtable PA up to 35bit

2022-05-16 Thread yf.wang--- via iommu
From: Yunfei Wang The calling to kmem_cache_alloc for level 2 pgtable allocation may run in atomic context, and it fails sometimes when DMA32 zone runs out of memory. Since Mediatek IOMMU hardware support at most 35bit PA in pgtable, so add a quirk to allow the PA of pgtables support up to

[PATCH v5 2/2] iommu/mediatek: Allow page table PA up to 35bit

2022-05-16 Thread yf.wang--- via iommu
From: Yunfei Wang Add the quirk IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT support, so that allows page table PA up to 35bit, not only in ZONE_DMA32. Signed-off-by: Ning Li Signed-off-by: Yunfei Wang --- drivers/iommu/mtk_iommu.c | 29 + 1 file changed, 25 insertions(+), 4

Re: [PATCH v10 1/2] iommu/io-pgtable-arm-v7s: Add a quirk to allow pgtable PA up to 35bit

2022-06-29 Thread yf.wang--- via iommu
On Wed, 2022-06-22 at 09:28 +0800, Yong Wu wrote: > On Thu, 2022-06-16 at 20:07 +0800, yf.w...@mediatek.com wrote: > > From: Yunfei Wang > > > > Single memory zone feature will remove ZONE_DMA32 and ZONE_DMA and > > cause pgtable PA size larger than 32bit. > > > > Since Mediatek IOMMU hardware

[PATCH v12 1/2] iommu/io-pgtable-arm-v7s: Add a quirk to allow pgtable PA up to 35bit

2022-06-30 Thread yf.wang--- via iommu
From: Yunfei Wang Single memory zone feature will remove ZONE_DMA32 and ZONE_DMA and cause pgtable PA size larger than 32bit. Since Mediatek IOMMU hardware support at most 35bit PA in pgtable, so add a quirk to allow the PA of pgtables support up to bit35. Signed-off-by: Ning Li

[PATCH v12 2/2] iommu/mediatek: Allow page table PA up to 35bit

2022-06-30 Thread yf.wang--- via iommu
From: Yunfei Wang Single memory zone feature will remove ZONE_DMA32 and ZONE_DMA. So add the quirk IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT to let level 1 and level 2 pgtable support at most 35bit PA. Signed-off-by: Ning Li Signed-off-by: Yunfei Wang --- drivers/iommu/mtk_iommu.c | 13 +++--

[PATCH v12 0/2] iommu/mediatek: TTBR up to 35bit support

2022-06-30 Thread yf.wang--- via iommu
This patchset adds MediaTek TTBR up to 35bit support for single normal zone. Changes in v12: - Update [PATCH 1/2]: remove GENMASK(31, 7) - Update [PATCH 2/2]: remove MMU_PT_ADDR_MASK definition. Changes in v11: https://lore.kernel.org/linux-mediatek/20220630062508.23512-1-yf.w...@mediatek.com/ -

Re: [PATCH v8 1/3] iommu/io-pgtable-arm-v7s: Add a quirk to allow pgtable PA up to 35bit

2022-06-15 Thread yf.wang--- via iommu
On Tue, 2022-06-14 at 13:56 +0100, Will Deacon wrote: > Hi, > > For some reason, this series has landed in my spam folder so > apologies > for the delay :/ > > > > +static arm_v7s_iopte paddr_to_iopte(phys_addr_t paddr, int lvl, > > + struct io_pgtable_cfg *cfg) >

[PATCH v9 1/3] iommu/io-pgtable-arm-v7s: Add a quirk to allow pgtable PA up to 35bit

2022-06-15 Thread yf.wang--- via iommu
From: Yunfei Wang Single memory zone feature will remove ZONE_DMA32 and ZONE_DMA and cause pgtable PA size larger than 32bit. Since Mediatek IOMMU hardware support at most 35bit PA in pgtable, so add a quirk to allow the PA of pgtables support up to bit35. Signed-off-by: Ning Li

[PATCH v9 2/3] iommu/mediatek: Rename MTK_IOMMU_TLB_ADDR to MTK_IOMMU_ADDR

2022-06-15 Thread yf.wang--- via iommu
From: Yunfei Wang Rename MTK_IOMMU_TLB_ADDR to MTK_IOMMU_ADDR, and update MTK_IOMMU_ADDR definition for better generality. Signed-off-by: Ning Li Signed-off-by: Yunfei Wang --- drivers/iommu/mtk_iommu.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git

[PATCH v9 3/3] iommu/mediatek: Allow page table PA up to 35bit

2022-06-15 Thread yf.wang--- via iommu
From: Yunfei Wang Single memory zone feature will remove ZONE_DMA32 and ZONE_DMA. So add the quirk IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT to let level 1 and level 2 pgtable support at most 35bit PA. Signed-off-by: Ning Li Signed-off-by: Yunfei Wang --- drivers/iommu/mtk_iommu.c | 14

Re: [PATCH v9 1/3] iommu/io-pgtable-arm-v7s: Add a quirk to allow pgtable PA up to 35bit

2022-06-16 Thread yf.wang--- via iommu
On Wed, 2022-06-15 at 18:03 +0100, Robin Murphy wrote: > On 2022-06-15 17:12, yf.w...@mediatek.com wrote: > > > > static phys_addr_t iopte_to_paddr(arm_v7s_iopte pte, int lvl, > > struct io_pgtable_cfg *cfg) > > { > > @@ -240,10 +245,17 @@ static void

Re: [PATCH v9 2/3] iommu/mediatek: Rename MTK_IOMMU_TLB_ADDR to MTK_IOMMU_ADDR

2022-06-16 Thread yf.wang--- via iommu
On Wed, 2022-06-15 at 18:14 +0100, Robin Murphy wrote: > On 2022-06-15 17:12, yf.wang--- via iommu wrote: > > From: Yunfei Wang > > > > Rename MTK_IOMMU_TLB_ADDR to MTK_IOMMU_ADDR, and update > > MTK_IOMMU_ADDR > > definition for better generality. > > >

[PATCH v10 1/2] iommu/io-pgtable-arm-v7s: Add a quirk to allow pgtable PA up to 35bit

2022-06-16 Thread yf.wang--- via iommu
From: Yunfei Wang Single memory zone feature will remove ZONE_DMA32 and ZONE_DMA and cause pgtable PA size larger than 32bit. Since Mediatek IOMMU hardware support at most 35bit PA in pgtable, so add a quirk to allow the PA of pgtables support up to bit35. Signed-off-by: Ning Li

[PATCH v10 2/2] iommu/mediatek: Allow page table PA up to 35bit

2022-06-16 Thread yf.wang--- via iommu
From: Yunfei Wang Single memory zone feature will remove ZONE_DMA32 and ZONE_DMA. So add the quirk IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT to let level 1 and level 2 pgtable support at most 35bit PA. Signed-off-by: Ning Li Signed-off-by: Yunfei Wang --- drivers/iommu/mtk_iommu.c | 17

Re: [PATCH v9 3/3] iommu/mediatek: Allow page table PA up to 35bit

2022-06-16 Thread yf.wang--- via iommu
On Wed, 2022-06-15 at 18:25 +0100, Robin Murphy wrote: > On 2022-06-15 17:12, yf.wang--- via iommu wrote: > > From: Yunfei Wang > > > > Single memory zone feature will remove ZONE_DMA32 and ZONE_DMA. So > > add > > the quirk IO_PGTABLE_QUIRK_ARM_MTK_TTBR_E

[PATCH v8 2/3] iommu/mediatek: Rename MTK_IOMMU_TLB_ADDR to MTK_IOMMU_ADDR

2022-06-11 Thread yf.wang--- via iommu
From: Yunfei Wang Rename MTK_IOMMU_TLB_ADDR to MTK_IOMMU_ADDR, and update MTK_IOMMU_ADDR definition for better generality. Signed-off-by: Ning Li Signed-off-by: Yunfei Wang --- drivers/iommu/mtk_iommu.c | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git

[PATCH v8 1/3] iommu/io-pgtable-arm-v7s: Add a quirk to allow pgtable PA up to 35bit

2022-06-11 Thread yf.wang--- via iommu
From: Yunfei Wang Single memory zone feature will remove ZONE_DMA32 and ZONE_DMA and cause pgtable PA size larger than 32bit. Since Mediatek IOMMU hardware support at most 35bit PA in pgtable, so add a quirk to allow the PA of pgtables support up to bit35. Signed-off-by: Ning Li

[PATCH v8 3/3] iommu/mediatek: Allow page table PA up to 35bit

2022-06-11 Thread yf.wang--- via iommu
From: Yunfei Wang Single memory zone feature will remove ZONE_DMA32 and ZONE_DMA. So add the quirk IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT to let level 1 and level 2 pgtable support at most 35bit PA. Signed-off-by: Ning Li Signed-off-by: Yunfei Wang --- drivers/iommu/mtk_iommu.c | 14

Re: [PATCH v5 2/2] iommu/mediatek: Allow page table PA up to 35bit

2022-06-11 Thread yf.wang--- via iommu
On Thu, 2022-05-19 at 14:58 +0800, Yong Wu wrote: > On Mon, 2022-05-16 at 22:16 +0800, yf.w...@mediatek.com wrote: > > From: Yunfei Wang > > > > Add the quirk IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT support, so that > > allows > > page table PA up to 35bit, not only in ZONE_DMA32. > > Comment why

[PATCH v11 1/2] iommu/io-pgtable-arm-v7s: Add a quirk to allow pgtable PA up to 35bit

2022-06-30 Thread yf.wang--- via iommu
From: Yunfei Wang Single memory zone feature will remove ZONE_DMA32 and ZONE_DMA and cause pgtable PA size larger than 32bit. Since Mediatek IOMMU hardware support at most 35bit PA in pgtable, so add a quirk to allow the PA of pgtables support up to bit35. Signed-off-by: Ning Li

[PATCH v11 2/2] iommu/mediatek: Allow page table PA up to 35bit

2022-06-30 Thread yf.wang--- via iommu
From: Yunfei Wang Single memory zone feature will remove ZONE_DMA32 and ZONE_DMA. So add the quirk IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT to let level 1 and level 2 pgtable support at most 35bit PA. Signed-off-by: Ning Li Signed-off-by: Yunfei Wang --- drivers/iommu/mtk_iommu.c | 12 +++-

[PATCH] iommu/dma: Fix iova map result check bug

2022-05-07 Thread yf.wang--- via iommu
From: Yunfei Wang The data type of the return value of the iommu_map_sg_atomic is ssize_t, but the data type of iova size is size_t, e.g. one is int while the other is unsigned int. When iommu_map_sg_atomic return value is compared with iova size, it will force the signed int to be converted to

[PATCH 1/2] iommu/io-pgtable-arm-v7s: Add a quirk to support TTBR up to 35bit for MediaTek

2022-04-29 Thread yf.wang--- via iommu
From: Yunfei Wang The calling to kmem_cache_alloc for level 2 page table allocation may run in atomic context, and it fails sometimes when DMA32 zone runs out of memory. Since Mediatek IOMMU hardware support at most 35bit PA in page table, so add a quirk to allow the PA of level 2 pgtable

[PATCH 2/2] iommu/mediatek: Enable allocating page table in normal memory

2022-04-29 Thread yf.wang--- via iommu
From: Yunfei Wang Add the quirk IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT support, so that level 2 page table can allocate in normal memory. Signed-off-by: Ning Li Signed-off-by: Yunfei Wang Cc: # 5.10.* --- drivers/iommu/mtk_iommu.c | 7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) diff