[GIT PULL] dma-mapping fix for 5.9
The following changes since commit 15bc20c6af4ceee97a1f90b43c0e386643c071b4: Merge tag 'tty-5.9-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty (2020-08-26 10:58:20 -0700) are available in the Git repository at: git://git.infradead.org/users/hch/dma-mapping.git tags/dma-mapping-5.9-2 for you to fetch changes up to 892fc9f6835ecf075efac20789b012c5c9997fcc: dma-pool: Fix an uninitialized variable bug in atomic_pool_expand() (2020-08-27 09:22:56 +0200) dma-mapping fixes: - fix a possibly uninitialized variable (Dan Carpenter) Dan Carpenter (1): dma-pool: Fix an uninitialized variable bug in atomic_pool_expand() kernel/dma/pool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) ___ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH 09/18] iommu/mediatek-v1: Add IOMMU_DOMAIN_DMA support
On Thu, 2020-08-20 at 16:08 +0100, Robin Murphy wrote: > Now that arch/arm is wired up for default domains and iommu-dma, > implement the corresponding driver-side support for groups and DMA > domains to replace the shared mapping workaround. > > Signed-off-by: Robin Murphy > --- > drivers/iommu/mtk_iommu.h| 2 - > drivers/iommu/mtk_iommu_v1.c | 153 +++ > 2 files changed, 48 insertions(+), 107 deletions(-) Hi Robin, Thanks very much for this patch, It makes the code much cleaner. Please help squash the little change in this patch, --- a/drivers/iommu/mtk_iommu_v1.c +++ b/drivers/iommu/mtk_iommu_v1.c @@ -555,6 +555,7 @@ static int mtk_iommu_probe(struct platform_device *pdev) return ret; iommu_device_set_ops(&data->iommu, &mtk_iommu_ops); + iommu_device_set_fwnode(&data->iommu, &dev->of_node->fwnode); ret = iommu_device_register(&data->iommu); if (ret) Then, Tested-by: Yong Wu > > diff --git a/drivers/iommu/mtk_iommu.h b/drivers/iommu/mtk_iommu.h > index 122925dbe547..6253e98d810c 100644 > --- a/drivers/iommu/mtk_iommu.h > +++ b/drivers/iommu/mtk_iommu.h > @@ -67,8 +67,6 @@ struct mtk_iommu_data { > struct iommu_device iommu; > const struct mtk_iommu_plat_data *plat_data; > > - struct dma_iommu_mapping*mapping; /* For mtk_iommu_v1.c */ > - > struct list_headlist; > struct mtk_smi_larb_iommu larb_imu[MTK_LARB_NR_MAX]; > }; > diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c > index 82ddfe9170d4..40c89b8d3ac4 100644 > --- a/drivers/iommu/mtk_iommu_v1.c > +++ b/drivers/iommu/mtk_iommu_v1.c > @@ -28,7 +28,6 @@ > #include > #include > #include > -#include > #include > #include > #include > @@ -240,13 +239,18 @@ static struct iommu_domain > *mtk_iommu_domain_alloc(unsigned type) > { > struct mtk_iommu_domain *dom; > > - if (type != IOMMU_DOMAIN_UNMANAGED) > + if (type != IOMMU_DOMAIN_UNMANAGED && type != IOMMU_DOMAIN_DMA) > return NULL; > > dom = kzalloc(sizeof(*dom), GFP_KERNEL); > if (!dom) > return NULL; > > + if (type == IOMMU_DOMAIN_DMA && iommu_get_dma_cookie(&dom->domain)) { > + kfree(dom); > + return NULL; > + } > + > return &dom->domain; > } > > @@ -257,6 +261,7 @@ static void mtk_iommu_domain_free(struct iommu_domain > *domain) > > dma_free_coherent(data->dev, M2701_IOMMU_PGT_SIZE, > dom->pgt_va, dom->pgt_pa); > + iommu_put_dma_cookie(domain); > kfree(to_mtk_domain(domain)); > } > > @@ -265,14 +270,8 @@ static int mtk_iommu_attach_device(struct iommu_domain > *domain, > { > struct mtk_iommu_data *data = dev_iommu_priv_get(dev); > struct mtk_iommu_domain *dom = to_mtk_domain(domain); > - struct dma_iommu_mapping *mtk_mapping; > int ret; > > - /* Only allow the domain created internally. */ > - mtk_mapping = data->mapping; > - if (mtk_mapping->domain != domain) > - return 0; > - > if (!data->m4u_dom) { > data->m4u_dom = dom; > ret = mtk_iommu_domain_finalise(data); > @@ -358,18 +357,39 @@ static phys_addr_t mtk_iommu_iova_to_phys(struct > iommu_domain *domain, > > static const struct iommu_ops mtk_iommu_ops; > > -/* > - * MTK generation one iommu HW only support one iommu domain, and all the > client > - * sharing the same iova address space. > - */ > -static int mtk_iommu_create_mapping(struct device *dev, > - struct of_phandle_args *args) > +static struct iommu_device *mtk_iommu_probe_device(struct device *dev) > { > struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); > struct mtk_iommu_data *data; > + > + if (!fwspec || fwspec->ops != &mtk_iommu_ops) > + return ERR_PTR(-ENODEV); /* Not a iommu client device */ > + > + data = dev_iommu_priv_get(dev); > + > + return &data->iommu; > +} > + > +static void mtk_iommu_release_device(struct device *dev) > +{ > + struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev); > + > + if (!fwspec || fwspec->ops != &mtk_iommu_ops) > + return; > + > + iommu_fwspec_free(dev); > +} > + > +static struct iommu_group *mtk_iommu_device_group(struct device *dev) > +{ > + struct mtk_iommu_data *data = dev_iommu_priv_get(dev); > + > + return iommu_group_ref_get(data->m4u_group); > +} > + > +static int mtk_iommu_of_xlate(struct device *dev, struct of_phandle_args > *args) > +{ > struct platform_device *m4updev; > - struct dma_iommu_mapping *mtk_mapping; > - int ret; > > if (args->args_count != 1) { > dev_err(dev, "invalid #iommu-cells(%d) property for IOMMU\n", > @@ -377,15 +397,6 @@ static int mtk_iommu_create_mapping(struct device *dev, > return -EINVAL; > } > > - if (!fwsp
Re: a saner API for allocating DMA addressable pages
Hi Christoph, On 19.08.20 08:55, Christoph Hellwig wrote: > this series replaced the DMA_ATTR_NON_CONSISTENT flag to dma_alloc_attrs > with a separate new dma_alloc_pages API, which is available on all > platforms. In addition to cleaning up the convoluted code path, this > ensures that other drivers that have asked for better support for > non-coherent DMA to pages with incurring bounce buffering over can finally > be properly supported. > > A git tree is available here: > > git://git.infradead.org/users/hch/misc.git dma_alloc_pages I've tested this tree on my parisc machine which uses the 53c700 and lasi_82596 drivers. Everything worked as expected, so you may add: Tested-by: Helge Deller # parisc Thanks! Helge > > Gitweb: > > > http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/dma_alloc_pages > > > Diffstat: > Documentation/core-api/dma-api.rst | 92 ++ > Documentation/core-api/dma-attributes.rst|8 > Documentation/userspace-api/media/v4l/buffer.rst | 17 - > Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst |1 > arch/alpha/kernel/pci_iommu.c|2 > arch/arm/include/asm/dma-direct.h|4 > arch/arm/mm/dma-mapping-nommu.c |2 > arch/arm/mm/dma-mapping.c|4 > arch/ia64/Kconfig|3 > arch/ia64/hp/common/sba_iommu.c |2 > arch/ia64/kernel/dma-mapping.c | 14 > arch/ia64/mm/init.c |3 > arch/mips/Kconfig|1 > arch/mips/bmips/dma.c|4 > arch/mips/cavium-octeon/dma-octeon.c |4 > arch/mips/include/asm/dma-direct.h |4 > arch/mips/include/asm/jazzdma.h |2 > arch/mips/jazz/jazzdma.c | 102 +-- > arch/mips/loongson2ef/fuloong-2e/dma.c |4 > arch/mips/loongson2ef/lemote-2f/dma.c|4 > arch/mips/loongson64/dma.c |4 > arch/mips/mm/dma-noncoherent.c | 48 +-- > arch/mips/pci/pci-ar2315.c |4 > arch/mips/pci/pci-xtalk-bridge.c |4 > arch/mips/sgi-ip32/ip32-dma.c|4 > arch/parisc/Kconfig |1 > arch/parisc/kernel/pci-dma.c |6 > arch/powerpc/include/asm/dma-direct.h|4 > arch/powerpc/kernel/dma-iommu.c |2 > arch/powerpc/platforms/ps3/system-bus.c |4 > arch/powerpc/platforms/pseries/vio.c |2 > arch/s390/pci/pci_dma.c |2 > arch/x86/kernel/amd_gart_64.c|8 > drivers/gpu/drm/exynos/exynos_drm_gem.c |2 > drivers/gpu/drm/nouveau/nvkm/subdev/instmem/gk20a.c |3 > drivers/iommu/dma-iommu.c|2 > drivers/iommu/intel/iommu.c |6 > drivers/media/common/videobuf2/videobuf2-core.c | 36 -- > drivers/media/common/videobuf2/videobuf2-dma-contig.c| 19 - > drivers/media/common/videobuf2/videobuf2-dma-sg.c|3 > drivers/media/common/videobuf2/videobuf2-v4l2.c | 12 > drivers/net/ethernet/amd/au1000_eth.c| 15 - > drivers/net/ethernet/i825xx/lasi_82596.c | 36 +- > drivers/net/ethernet/i825xx/lib82596.c | 148 +- > drivers/net/ethernet/i825xx/sni_82596.c | 23 - > drivers/net/ethernet/seeq/sgiseeq.c | 24 - > drivers/nvme/host/pci.c | 79 ++--- > drivers/parisc/ccio-dma.c|2 > drivers/parisc/sba_iommu.c |2 > drivers/scsi/53c700.c| 120 > drivers/scsi/53c700.h|9 > drivers/scsi/sgiwd93.c | 14 > drivers/xen/swiotlb-xen.c|2 > include/linux/dma-direct.h | 55 ++- > include/linux/dma-mapping.h | 32 +- > include/linux/dma-noncoherent.h | 21 - > include/linux/dmapool.h | 23 + > include/linux/gfp.h |6 > include/media/videobuf2-core.h |3 > include/uapi/linux/videodev2.h |2 > kernel/dma/Kconfig
Re: [RESEND PATCH v4] iommu/mediatek: check 4GB mode by reading infracfg
On Thu, 2020-08-27 at 20:27 +0100, Robin Murphy wrote: > On 2020-08-27 06:31, Yong Wu wrote: > > On Wed, 2020-08-26 at 16:56 +0800, Miles Chen wrote: > >> In previous discussion [1] and [2], we found that it is risky to > >> use max_pfn or totalram_pages to tell if 4GB mode is enabled. > >> > >> Check 4GB mode by reading infracfg register, remove the usage > >> of the un-exported symbol max_pfn. > >> > >> This is a step towards building mtk_iommu as a kernel module. > >> > >> [1] > >> https://lore.kernel.org/lkml/20200603161132.2441-1-miles.c...@mediatek.com/ > >> [2] > >> https://lore.kernel.org/lkml/20200604080120.2628-1-miles.c...@mediatek.com/ > >> [3] https://lore.kernel.org/lkml/20200715205120.GA778876@bogus/ > >> > >> Cc: Mike Rapoport > >> Cc: David Hildenbrand > >> Cc: Yong Wu > >> Cc: Yingjoe Chen > >> Cc: Christoph Hellwig > >> Cc: Rob Herring > >> Cc: Matthias Brugger > >> Signed-off-by: Miles Chen > >> > >> --- > >> > >> Change since v3 > >> - use lore.kernel.org links > >> - move "change since..." after "---" > >> > >> Change since v2: > >> - determine compatible string by m4u_plat > >> - rebase to next-20200720 > >> - add "---" > >> > >> Change since v1: > >> - remove the phandle usage, search for infracfg instead [3] > >> - use infracfg instead of infracfg_regmap > >> - move infracfg definitaions to linux/soc/mediatek/infracfg.h > >> - update enable_4GB only when has_4gb_mode > >> --- > >> drivers/iommu/mtk_iommu.c | 34 +++ > >> include/linux/soc/mediatek/infracfg.h | 3 +++ > >> 2 files changed, 32 insertions(+), 5 deletions(-) > >> > >> diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c > >> index 785b228d39a6..adc350150492 100644 > >> --- a/drivers/iommu/mtk_iommu.c > >> +++ b/drivers/iommu/mtk_iommu.c > >> @@ -3,7 +3,6 @@ > >>* Copyright (c) 2015-2016 MediaTek Inc. > >>* Author: Yong Wu > >>*/ > >> -#include > >> #include > >> #include > >> #include > >> @@ -15,13 +14,16 @@ > >> #include > >> #include > >> #include > >> +#include > >> #include > >> #include > >> #include > >> #include > >> #include > >> +#include > >> #include > >> #include > >> +#include > >> #include > >> #include > >> > >> @@ -640,8 +642,11 @@ static int mtk_iommu_probe(struct platform_device > >> *pdev) > >>struct resource *res; > >>resource_size_t ioaddr; > >>struct component_match *match = NULL; > >> + struct regmap *infracfg; > >>void*protect; > >>int i, larb_nr, ret; > >> + u32 val; > >> + char*p; > >> > >>data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); > >>if (!data) > >> @@ -655,10 +660,29 @@ static int mtk_iommu_probe(struct platform_device > >> *pdev) > >>return -ENOMEM; > >>data->protect_base = ALIGN(virt_to_phys(protect), MTK_PROTECT_PA_ALIGN); > >> > >> - /* Whether the current dram is over 4GB */ > >> - data->enable_4GB = !!(max_pfn > (BIT_ULL(32) >> PAGE_SHIFT)); > >> - if (!MTK_IOMMU_HAS_FLAG(data->plat_data, HAS_4GB_MODE)) > >> - data->enable_4GB = false; > >> + data->enable_4GB = false; > > Nit: this isn't really necessary, since the structure is kzalloc()ed. Thanks for the comment, I will remove this this in v5. > > >> + if (MTK_IOMMU_HAS_FLAG(data->plat_data, HAS_4GB_MODE)) { > >> + switch (data->plat_data->m4u_plat) { > >> + case M4U_MT2712: > >> + p = "mediatek,mt2712-infracfg"; > >> + break; > >> + case M4U_MT8173: > >> + p = "mediatek,mt8173-infracfg"; > >> + break; > >> + default: > >> + p = NULL; > >> + } > >> + > > > > This can be simplified: > > > > if (data->plat_data->m4u_plat == M4U_MT2712) > > p = "mediatek,mt2712-infracfg"; > > else if(data->plat_data->m4u_plat == M4U_MT8173) > > p = "mediatek,mt8173-infracfg"; > > else > > return -EINVAL; > > Right, at this point the HAS_4GB_MODE flag is entirely redundant and > should be removed. FWIW I still think your suggestion of putting the > infracfg names into plat_data would be even better and cleaner - there's > plenty of precedent for that sort of thing (see "git grep '\.clk_name'" > for example). > > Robin. hmm, I have no strong opinion about this. We have discussed this approach before and built this patch based on the discussion. https://lore.kernel.org/patchwork/patch/1276801/ Miles > > > > > Then, > > Reviewed-by: Yong Wu > > > > > >> + infracfg = syscon_regmap_lookup_by_compatible(p); > >> + > >> + if (IS_ERR(infracfg)) > >> + return PTR_ERR(infracfg); > >> + > >> + ret = regmap_read(infracfg, REG_INFRA_MISC, &val); > >> + if (ret) > >> + return ret; > >>