From 9db11c69fcc3147d158943930ce3f2c32620054d Mon Sep 17 00:00:00 2001 From: Vova Sharaienko Date: Tue, 23 Jun 2026 00:08:20 +0000 Subject: dma-coherent: fix spacing coding style issue Fixed spacing around * coding style issue Signed-off-by: Vova Sharaienko [mszyprow: changed patch prefix] Signed-off-by: Marek Szyprowski Link: https://lore.kernel.org/r/20260623000821.2269955-1-sharaienko@google.com --- kernel/dma/coherent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/dma/coherent.c b/kernel/dma/coherent.c index bcdc0f76d2e8..480dd1766ece 100644 --- a/kernel/dma/coherent.c +++ b/kernel/dma/coherent.c @@ -28,7 +28,7 @@ static inline struct dma_coherent_mem *dev_get_coherent_memory(struct device *de } static inline dma_addr_t dma_get_device_base(struct device *dev, - struct dma_coherent_mem * mem) + struct dma_coherent_mem *mem) { if (mem->use_dev_dma_pfn_offset) return phys_to_dma(dev, PFN_PHYS(mem->pfn_base)); -- cgit v1.2.3 From dbcc3cd58083521d77f0e43db615bca2c17b0dbf Mon Sep 17 00:00:00 2001 From: Vova Sharaienko Date: Mon, 29 Jun 2026 22:37:58 +0000 Subject: dma-coherent: use KiB in DMA allocation logs Update DMA reserved memory pool allocation log messages to display sizes in KiB instead of MiB. Using MiB caused allocations less than 1 MiB to be logged as 0 MiB due to integer truncation. KiB provides better precision for smaller memory regions specified in the Device Tree. Signed-off-by: Vova Sharaienko Signed-off-by: Marek Szyprowski Link: https://lore.kernel.org/r/20260629223759.2637162-1-sharaienko@google.com --- kernel/dma/coherent.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel/dma/coherent.c b/kernel/dma/coherent.c index 480dd1766ece..5e005e0679f8 100644 --- a/kernel/dma/coherent.c +++ b/kernel/dma/coherent.c @@ -69,8 +69,8 @@ out_free_dma_mem: kfree(dma_mem); out_unmap_membase: memunmap(mem_base); - pr_err("Reserved memory: failed to init DMA memory pool at %pa, size %zd MiB\n", - &phys_addr, size / SZ_1M); + pr_err("Reserved memory: failed to init DMA memory pool at %pa, size %zu KiB\n", + &phys_addr, size / SZ_1K); return ERR_PTR(-ENOMEM); } @@ -384,8 +384,8 @@ static int __init rmem_dma_setup(unsigned long node, struct reserved_mem *rmem) } #endif - pr_info("Reserved memory: created DMA memory pool at %pa, size %ld MiB\n", - &rmem->base, (unsigned long)rmem->size / SZ_1M); + pr_info("Reserved memory: created DMA memory pool at %pa, size %llu KiB\n", + &rmem->base, (unsigned long long)(rmem->size / SZ_1K)); return 0; } -- cgit v1.2.3 From 1acce29926d93f3eba427696fe3da6451504dae2 Mon Sep 17 00:00:00 2001 From: Honglei Huang Date: Fri, 3 Jul 2026 11:37:29 +0800 Subject: iommu/dma: simplify dma_iova_destroy() and drop the free_iova helper dma_iova_destroy() frees the IOVA space through __iommu_dma_iova_unlink() using a "free_iova" boolean, which duplicates the IOVA free logic in dma_iova_free(). And it frees using the unmapped @mapped_len, which for a partially linked reservation is smaller than the reserved size. This results in a benign waste as pointed out by Robin, not a leak. So this is a cleanup, not a fix. Drop the duplicated free path. Fold __iommu_dma_iova_unlink into dma_iova_unlink and remove the free_iova parameter so it only unmaps. dma_iova_destroy then unlinks the mapped range if mapped_len is set and unconditionally calls dma_iova_free, which frees the whole reservation via dma_iova_size. The freed size now always matches the reserved size, and destroy reads as unlink then free. Note that dma_iova_destroy() no longer routes the free through the flush queue; teardown now unmaps synchronously and frees directly, matching dma_iova_free(). No functional change intended for callers. Suggested-by: Leon Romanovsky Signed-off-by: Honglei Huang Signed-off-by: Marek Szyprowski Link: https://lore.kernel.org/r/20260703033729.455358-1-honghuan@amd.com --- drivers/iommu/dma-iommu.c | 57 ++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 35 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 9abaec0703ef..5598ed4bff72 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -2068,10 +2068,20 @@ static void iommu_dma_iova_unlink_range_slow(struct device *dev, arch_sync_dma_flush(); } -static void __iommu_dma_iova_unlink(struct device *dev, - struct dma_iova_state *state, size_t offset, size_t size, - enum dma_data_direction dir, unsigned long attrs, - bool free_iova) +/** + * dma_iova_unlink - Unlink a range of IOVA space + * @dev: DMA device + * @state: IOVA state + * @offset: offset into the IOVA state to unlink + * @size: size of the buffer + * @dir: DMA direction + * @attrs: attributes of mapping properties + * + * Unlink a range of IOVA space for the given IOVA state. + */ +void dma_iova_unlink(struct device *dev, struct dma_iova_state *state, + size_t offset, size_t size, enum dma_data_direction dir, + unsigned long attrs) { struct iommu_domain *domain = iommu_get_dma_domain(dev); struct iommu_dma_cookie *cookie = domain->iova_cookie; @@ -2087,35 +2097,13 @@ static void __iommu_dma_iova_unlink(struct device *dev, iommu_dma_iova_unlink_range_slow(dev, addr, size, dir, attrs); iommu_iotlb_gather_init(&iotlb_gather); - iotlb_gather.queued = free_iova && READ_ONCE(cookie->fq_domain); size = iova_align(iovad, size + iova_start_pad); addr -= iova_start_pad; unmapped = iommu_unmap_fast(domain, addr, size, &iotlb_gather); WARN_ON(unmapped != size); - if (!iotlb_gather.queued) - iommu_iotlb_sync(domain, &iotlb_gather); - if (free_iova) - iommu_dma_free_iova(domain, addr, size, &iotlb_gather); -} - -/** - * dma_iova_unlink - Unlink a range of IOVA space - * @dev: DMA device - * @state: IOVA state - * @offset: offset into the IOVA state to unlink - * @size: size of the buffer - * @dir: DMA direction - * @attrs: attributes of mapping properties - * - * Unlink a range of IOVA space for the given IOVA state. - */ -void dma_iova_unlink(struct device *dev, struct dma_iova_state *state, - size_t offset, size_t size, enum dma_data_direction dir, - unsigned long attrs) -{ - __iommu_dma_iova_unlink(dev, state, offset, size, dir, attrs, false); + iommu_iotlb_sync(domain, &iotlb_gather); } EXPORT_SYMBOL_GPL(dma_iova_unlink); @@ -2136,14 +2124,13 @@ void dma_iova_destroy(struct device *dev, struct dma_iova_state *state, unsigned long attrs) { if (mapped_len) - __iommu_dma_iova_unlink(dev, state, 0, mapped_len, dir, attrs, - true); - else - /* - * We can be here if first call to dma_iova_link() failed and - * there is nothing to unlink, so let's be more clear. - */ - dma_iova_free(dev, state); + dma_iova_unlink(dev, state, 0, mapped_len, dir, attrs); + + /* + * We can be here if the first call to dma_iova_link() failed and + * there is nothing to unlink, so let's be more clear. + */ + dma_iova_free(dev, state); } EXPORT_SYMBOL_GPL(dma_iova_destroy); -- cgit v1.2.3 From 0188616c057d3eba8d8a4af62a59b5e7f2362571 Mon Sep 17 00:00:00 2001 From: Marek Szyprowski Date: Mon, 13 Jul 2026 10:30:22 +0200 Subject: dma-direct: Improve readability of the dma_direct_map_sg() for P2PDMA case Improve readability of the sg_dma_len assignment in the P2PDMA cases by removing duplicated code, which was a direct result of the d0d08f4bd7f6 ("dma-direct: Fix missing sg_dma_len assignment in P2PDMA bus mappings") fix. No functional change. Suggested-by: Leon Romanovsky Link: https://lore.kernel.org/all/20260604071856.GA245424@unreal/ Reviewed-by: Pranjal Shrivastava Reviewed-by: Leon Romanovsky Reviewed-by: Logan Gunthorpe Link: https://lore.kernel.org/r/20260713083022.1110993-1-m.szyprowski@samsung.com Signed-off-by: Marek Szyprowski --- kernel/dma/direct.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index 4391b797d4db..d8219efe3273 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -489,9 +489,8 @@ int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl, int nents, case PCI_P2PDMA_MAP_BUS_ADDR: sg->dma_address = pci_p2pdma_bus_addr_map( p2pdma_state.mem, sg_phys(sg)); - sg_dma_len(sg) = sg->length; sg_dma_mark_bus_address(sg); - continue; + break; default: ret = -EREMOTEIO; goto out_unmap; -- cgit v1.2.3