From 9665d389e453d852eef4bc4ae3699ee11d15c999 Mon Sep 17 00:00:00 2001 From: Julius Werner Date: Fri, 13 Sep 2013 18:21:46 -0700 Subject: libpayload: dma_malloc: Prevent warm reboot problems and add debugging Since the DMA memory is allocated by Coreboot (outside of the payload's linker script), it won't get zeroed upon loading like the heap. Therefore, a warm reboot that doesn't reset memory may leave stale malloc cookies lying around and misinterpret them as memory that is still in use on the next boot. After several boots this may fill up the whole DMA memory and lead to OOM conditions. Therefore, this patch explicitly wipes the first cookie in init_dma_memory() to prevent that from happening. It also expands the existing memory allocator debugging code to cover the DMA parts, which was very helpful in identifying this particular problem. Change-Id: I6e2083c286ff8ec865b22dd922c39c456944b451 Signed-off-by: Julius Werner Reviewed-on: https://chromium-review.googlesource.com/169455 Reviewed-by: Stefan Reinauer (cherry picked from commit 8e5e1784638563b865553125cd5dab1d36a5d2cb) Signed-off-by: Isaac Christensen Reviewed-on: http://review.coreboot.org/6645 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer Reviewed-by: Paul Menzel --- payloads/libpayload/include/stdlib.h | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'payloads/libpayload/include') diff --git a/payloads/libpayload/include/stdlib.h b/payloads/libpayload/include/stdlib.h index d3448b96cc..1ed92d5cfd 100644 --- a/payloads/libpayload/include/stdlib.h +++ b/payloads/libpayload/include/stdlib.h @@ -101,7 +101,35 @@ printf("PRE memalign\n"); \ print_malloc_map(); \ ptr = memalign(a,s); \ - printf("POST realloc (ptr = %p)\n", ptr); \ + printf("POST memalign (ptr = %p)\n", ptr); \ + print_malloc_map(); \ + ptr; \ + }) +#define dma_malloc(s) \ + ({ \ + extern void print_malloc_map(void); \ + extern void *dma_malloc(size_t); \ + void *ptr; \ + printf("dma_malloc(%u) called from %s:%s:%d...\n", s, __FILE__, \ + __func__, __LINE__);\ + printf("PRE dma_malloc\n"); \ + print_malloc_map(); \ + ptr = dma_malloc(s); \ + printf("POST dma_malloc (ptr = %p)\n", ptr); \ + print_malloc_map(); \ + ptr; \ + }) +#define dma_memalign(a,s) \ + ({ \ + extern void print_malloc_map(void); \ + extern void *dma_memalign(size_t, size_t); \ + void *ptr; \ + printf("dma_memalign(%u, %u) called from %s:%s:%d...\n", a, s, \ + __FILE__, __func__, __LINE__);\ + printf("PRE dma_memalign\n"); \ + print_malloc_map(); \ + ptr = dma_memalign(a,s); \ + printf("POST dma_memalign (ptr = %p)\n", ptr); \ print_malloc_map(); \ ptr; \ }) @@ -111,10 +139,10 @@ void *malloc(size_t size); void *calloc(size_t nmemb, size_t size); void *realloc(void *ptr, size_t size); void *memalign(size_t align, size_t size); -#endif -void init_dma_memory(void *start, u32 size); void *dma_malloc(size_t size); void *dma_memalign(size_t align, size_t size); +#endif +void init_dma_memory(void *start, u32 size); int dma_initialized(void); int dma_coherent(void *ptr); /** @} */ -- cgit v1.2.3