* [U-Boot] [PATCH] Make kmalloc'ed memory really DMA-safe
@ 2018-08-24 10:30 Masahiro Yamada
2018-08-31 21:07 ` [U-Boot] " Tom Rini
0 siblings, 1 reply; 2+ messages in thread
From: Masahiro Yamada @ 2018-08-24 10:30 UTC (permalink / raw)
To: u-boot
In Linux, the memory returned by kmalloc() is DMA-capable.
However, it is not true in U-Boot.
At a glance, kmalloc() in U-Boot returns address aligned with
ARCH_DMA_MINALIGN. However, it never pads the allocated memory.
This half-way house is completely useless because calling kmalloc()
and malloc() in this order causes a cache sharing problem.
Change the implementation to call malloc_cache_aligned(), which
allocates really DMA-capable memory.
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
lib/linux_compat.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/lib/linux_compat.c b/lib/linux_compat.c
index a936a7e..6373b44 100644
--- a/lib/linux_compat.c
+++ b/lib/linux_compat.c
@@ -1,5 +1,6 @@
#include <common.h>
+#include <memalign.h>
#include <linux/compat.h>
struct p_current cur = {
@@ -18,7 +19,7 @@ void *kmalloc(size_t size, int flags)
{
void *p;
- p = memalign(ARCH_DMA_MINALIGN, size);
+ p = malloc_cache_aligned(size);
if (flags & __GFP_ZERO)
memset(p, 0, size);
@@ -37,5 +38,5 @@ struct kmem_cache *get_mem(int element_sz)
void *kmem_cache_alloc(struct kmem_cache *obj, int flag)
{
- return memalign(ARCH_DMA_MINALIGN, obj->sz);
+ return malloc_cache_aligned(obj->sz);
}
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [U-Boot] Make kmalloc'ed memory really DMA-safe
2018-08-24 10:30 [U-Boot] [PATCH] Make kmalloc'ed memory really DMA-safe Masahiro Yamada
@ 2018-08-31 21:07 ` Tom Rini
0 siblings, 0 replies; 2+ messages in thread
From: Tom Rini @ 2018-08-31 21:07 UTC (permalink / raw)
To: u-boot
On Fri, Aug 24, 2018 at 07:30:15PM +0900, Masahiro Yamada wrote:
> In Linux, the memory returned by kmalloc() is DMA-capable.
> However, it is not true in U-Boot.
>
> At a glance, kmalloc() in U-Boot returns address aligned with
> ARCH_DMA_MINALIGN. However, it never pads the allocated memory.
> This half-way house is completely useless because calling kmalloc()
> and malloc() in this order causes a cache sharing problem.
>
> Change the implementation to call malloc_cache_aligned(), which
> allocates really DMA-capable memory.
>
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Applied to u-boot/master, thanks!
--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180831/bc4e2f84/attachment.sig>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-08-31 21:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-24 10:30 [U-Boot] [PATCH] Make kmalloc'ed memory really DMA-safe Masahiro Yamada
2018-08-31 21:07 ` [U-Boot] " Tom Rini
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.