* [RFC PATCH] dma-coherent: use KiB in DMA allocation logs
@ 2026-06-24 0:05 Vova Sharaienko
2026-06-24 6:22 ` Ankit Soni
0 siblings, 1 reply; 2+ messages in thread
From: Vova Sharaienko @ 2026-06-24 0:05 UTC (permalink / raw)
To: Marek Szyprowski, Robin Murphy
Cc: android-mm, Vova Sharaienko, kernel-team, iommu, linux-kernel
We are proposing to 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.
This is currently marked as an RFC because we would like feedback on
a KiB unit change.
Signed-off-by: Vova Sharaienko <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..3ede8da395ce 100644
--- a/kernel/dma/coherent.c
+++ b/kernel/dma/coherent.c
@@ -69,8 +69,8 @@ static struct dma_coherent_mem *dma_init_coherent_memory(phys_addr_t phys_addr,
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 %lu KiB\n",
+ &phys_addr, (unsigned long)(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 %lu KiB\n",
+ &rmem->base, (unsigned long)(rmem->size / SZ_1K));
return 0;
}
--
2.55.0.rc0.799.gd6f94ed593-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [RFC PATCH] dma-coherent: use KiB in DMA allocation logs
2026-06-24 0:05 [RFC PATCH] dma-coherent: use KiB in DMA allocation logs Vova Sharaienko
@ 2026-06-24 6:22 ` Ankit Soni
0 siblings, 0 replies; 2+ messages in thread
From: Ankit Soni @ 2026-06-24 6:22 UTC (permalink / raw)
To: Vova Sharaienko
Cc: Marek Szyprowski, Robin Murphy, android-mm, kernel-team, iommu,
linux-kernel
On Wed, Jun 24, 2026 at 12:05:15AM +0000, Vova Sharaienko wrote:
> We are proposing to 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.
>
> This is currently marked as an RFC because we would like feedback on
> a KiB unit change.
>
> Signed-off-by: Vova Sharaienko <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..3ede8da395ce 100644
> --- a/kernel/dma/coherent.c
> +++ b/kernel/dma/coherent.c
> @@ -69,8 +69,8 @@ static struct dma_coherent_mem *dma_init_coherent_memory(phys_addr_t phys_addr,
> 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 %lu KiB\n",
> + &phys_addr, (unsigned long)(size / SZ_1K));
'size' here is a size_t, so the portable specifier is %zu, which also
lets you drop the cast.
> 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 %lu KiB\n",
> + &rmem->base, (unsigned long)(rmem->size / SZ_1K));
rmem->size is a phys_addr_t, which can be 64-bit on a 32-bit kernel.
Casting to unsigned long may truncate. It's an unlikely corner case,
but casting to the widest(%llu) type can avoid it.
-Ankit
> return 0;
> }
>
> --
> 2.55.0.rc0.799.gd6f94ed593-goog
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-24 6:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-24 0:05 [RFC PATCH] dma-coherent: use KiB in DMA allocation logs Vova Sharaienko
2026-06-24 6:22 ` Ankit Soni
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.