From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yh0-f43.google.com (mail-yh0-f43.google.com [209.85.213.43]) by kanga.kvack.org (Postfix) with ESMTP id B996C6B0036 for ; Fri, 2 May 2014 09:41:48 -0400 (EDT) Received: by mail-yh0-f43.google.com with SMTP id f10so4130797yha.30 for ; Fri, 02 May 2014 06:41:48 -0700 (PDT) Received: from cam-smtp0.cambridge.arm.com (fw-tnat.cambridge.arm.com. [217.140.96.21]) by mx.google.com with ESMTPS id h54si38479697yhf.153.2014.05.02.06.41.47 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 02 May 2014 06:41:47 -0700 (PDT) From: Catalin Marinas Subject: [PATCH 0/6] Kmemleak updates Date: Fri, 2 May 2014 14:41:04 +0100 Message-Id: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> Sender: owner-linux-mm@kvack.org List-ID: To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton Hi, This series contains a few kmemleak updates: - Avoid false positives caused by not tracking all memblock allocations and disabling the kmemleak early logging slightly earlier - Debugging improvements for places where pre-allocation happens (mempool and radix tree) - minor printk correction Catalin Marinas (5): mm: Introduce kmemleak_update_trace() lib: Update the kmemleak allocation stack trace for kmemleak mm: Update the kmemleak stack trace for mempool allocations mm: Call kmemleak directly from memblock_(alloc|free) mm: Postpone the disabling of kmemleak early logging Jianpeng Ma (1): mm/kmemleak.c: Use %u to print ->checksum. Documentation/kmemleak.txt | 1 + include/linux/kmemleak.h | 4 ++++ lib/radix-tree.c | 6 ++++++ mm/kmemleak.c | 43 ++++++++++++++++++++++++++++++++++++++----- mm/memblock.c | 9 ++++++++- mm/mempool.c | 6 ++++++ mm/nobootmem.c | 2 -- 7 files changed, 63 insertions(+), 8 deletions(-) -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yk0-f182.google.com (mail-yk0-f182.google.com [209.85.160.182]) by kanga.kvack.org (Postfix) with ESMTP id CA1CC6B0037 for ; Fri, 2 May 2014 09:41:48 -0400 (EDT) Received: by mail-yk0-f182.google.com with SMTP id 9so116385ykp.41 for ; Fri, 02 May 2014 06:41:48 -0700 (PDT) Received: from cam-smtp0.cambridge.arm.com (fw-tnat.cambridge.arm.com. [217.140.96.21]) by mx.google.com with ESMTPS id o25si46456236yhj.106.2014.05.02.06.41.47 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 02 May 2014 06:41:47 -0700 (PDT) From: Catalin Marinas Subject: [PATCH 5/6] mm: Call kmemleak directly from memblock_(alloc|free) Date: Fri, 2 May 2014 14:41:09 +0100 Message-Id: <1399038070-1540-6-git-send-email-catalin.marinas@arm.com> In-Reply-To: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> References: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> Sender: owner-linux-mm@kvack.org List-ID: To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton Kmemleak could ignore memory blocks allocated via memblock_alloc() leading to false positives during scanning. This patch adds the corresponding callbacks and removes kmemleak_free_* calls in mm/nobootmem.c to avoid duplication. The kmemleak_alloc() in mm/nobootmem.c is kept since __alloc_memory_core_early() does not use memblock_alloc() directly. Signed-off-by: Catalin Marinas Cc: Andrew Morton --- mm/memblock.c | 9 ++++++++- mm/nobootmem.c | 2 -- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/mm/memblock.c b/mm/memblock.c index e9d6ca9a01a9..8813a31d7fbd 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -681,6 +681,7 @@ int __init_memblock memblock_free(phys_addr_t base, phys_addr_t size) (unsigned long long)base + size - 1, (void *)_RET_IP_); + kmemleak_free_part(__va(base), size); return __memblock_remove(&memblock.reserved, base, size); } @@ -985,8 +986,14 @@ static phys_addr_t __init memblock_alloc_base_nid(phys_addr_t size, align = SMP_CACHE_BYTES; found = memblock_find_in_range_node(size, align, 0, max_addr, nid); - if (found && !memblock_reserve(found, size)) + if (found && !memblock_reserve(found, size)) { + /* + * The min_count is set to 0 so that memblock allocations are + * never reported as leaks. + */ + kmemleak_alloc(__va(found), size, 0, 0); return found; + } return 0; } diff --git a/mm/nobootmem.c b/mm/nobootmem.c index 04a9d94333a5..7ed58602e71b 100644 --- a/mm/nobootmem.c +++ b/mm/nobootmem.c @@ -197,7 +197,6 @@ unsigned long __init free_all_bootmem(void) void __init free_bootmem_node(pg_data_t *pgdat, unsigned long physaddr, unsigned long size) { - kmemleak_free_part(__va(physaddr), size); memblock_free(physaddr, size); } @@ -212,7 +211,6 @@ void __init free_bootmem_node(pg_data_t *pgdat, unsigned long physaddr, */ void __init free_bootmem(unsigned long addr, unsigned long size) { - kmemleak_free_part(__va(addr), size); memblock_free(addr, size); } -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by kanga.kvack.org (Postfix) with ESMTP id 0726C6B0036 for ; Fri, 2 May 2014 09:41:48 -0400 (EDT) Received: by mail-ie0-f180.google.com with SMTP id as1so5072927iec.39 for ; Fri, 02 May 2014 06:41:48 -0700 (PDT) Received: from cam-smtp0.cambridge.arm.com (fw-tnat.cambridge.arm.com. [217.140.96.21]) by mx.google.com with ESMTPS id j10si3325995igx.20.2014.05.02.06.41.47 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 02 May 2014 06:41:48 -0700 (PDT) From: Catalin Marinas Subject: [PATCH 6/6] mm: Postpone the disabling of kmemleak early logging Date: Fri, 2 May 2014 14:41:10 +0100 Message-Id: <1399038070-1540-7-git-send-email-catalin.marinas@arm.com> In-Reply-To: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> References: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> Sender: owner-linux-mm@kvack.org List-ID: To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton Currently, kmemleak_early_log is disabled at the beginning of the kmemleak_init() function, before the full kmemleak tracing is actually enabled. In this small window, kmem_cache_create() is called by kmemleak which triggers additional memory allocation that are not traced. This patch moves the kmemleak_early_log disabling further down and at the same time with full kmemleak enabling. Signed-off-by: Catalin Marinas Cc: Andrew Morton --- mm/kmemleak.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 61a64ed2fbef..0cd6aabd45a0 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -1809,8 +1809,6 @@ void __init kmemleak_init(void) int i; unsigned long flags; - kmemleak_early_log = 0; - #ifdef CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF if (!kmemleak_skip_disable) { kmemleak_disable(); @@ -1833,8 +1831,9 @@ void __init kmemleak_init(void) if (kmemleak_error) { local_irq_restore(flags); return; - } else - kmemleak_enabled = 1; + } + kmemleak_early_log = 0; + kmemleak_enabled = 1; local_irq_restore(flags); /* -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yk0-f170.google.com (mail-yk0-f170.google.com [209.85.160.170]) by kanga.kvack.org (Postfix) with ESMTP id 2CF416B003B for ; Fri, 2 May 2014 09:41:49 -0400 (EDT) Received: by mail-yk0-f170.google.com with SMTP id 79so3843581ykr.29 for ; Fri, 02 May 2014 06:41:48 -0700 (PDT) Received: from cam-smtp0.cambridge.arm.com (fw-tnat.cambridge.arm.com. [217.140.96.21]) by mx.google.com with ESMTPS id 42si46440648yhp.196.2014.05.02.06.41.47 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 02 May 2014 06:41:47 -0700 (PDT) From: Catalin Marinas Subject: [PATCH 4/6] mm: Update the kmemleak stack trace for mempool allocations Date: Fri, 2 May 2014 14:41:08 +0100 Message-Id: <1399038070-1540-5-git-send-email-catalin.marinas@arm.com> In-Reply-To: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> References: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> Sender: owner-linux-mm@kvack.org List-ID: To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton When mempool_alloc() returns an existing pool object, kmemleak_alloc() is no longer called and the stack trace corresponds to the original object allocation. This patch updates the kmemleak allocation stack trace for such objects to make it more useful for debugging. Signed-off-by: Catalin Marinas Cc: Andrew Morton --- mm/mempool.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/mempool.c b/mm/mempool.c index 905434f18c97..e7c4be024f1a 100644 --- a/mm/mempool.c +++ b/mm/mempool.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -220,6 +221,11 @@ repeat_alloc: spin_unlock_irqrestore(&pool->lock, flags); /* paired with rmb in mempool_free(), read comment there */ smp_wmb(); + /* + * Update the allocation stack trace as this is more useful + * for debugging. + */ + kmemleak_update_trace(element); return element; } -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ig0-f171.google.com (mail-ig0-f171.google.com [209.85.213.171]) by kanga.kvack.org (Postfix) with ESMTP id B77F76B0038 for ; Fri, 2 May 2014 09:41:50 -0400 (EDT) Received: by mail-ig0-f171.google.com with SMTP id c1so1862461igq.16 for ; Fri, 02 May 2014 06:41:50 -0700 (PDT) Received: from cam-smtp0.cambridge.arm.com (fw-tnat.cambridge.arm.com. [217.140.96.21]) by mx.google.com with ESMTPS id gw5si1117371icb.40.2014.05.02.06.41.49 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 02 May 2014 06:41:50 -0700 (PDT) From: Catalin Marinas Subject: [PATCH 1/6] mm/kmemleak.c: Use %u to print ->checksum. Date: Fri, 2 May 2014 14:41:05 +0100 Message-Id: <1399038070-1540-2-git-send-email-catalin.marinas@arm.com> In-Reply-To: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> References: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> Sender: owner-linux-mm@kvack.org List-ID: To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Jianpeng Ma , Andrew Morton From: Jianpeng Ma Signed-off-by: Jianpeng Ma Signed-off-by: Catalin Marinas Cc: Andrew Morton --- mm/kmemleak.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 91d67eaee050..3a36e2b16cba 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -387,7 +387,7 @@ static void dump_object_info(struct kmemleak_object *object) pr_notice(" min_count = %d\n", object->min_count); pr_notice(" count = %d\n", object->count); pr_notice(" flags = 0x%lx\n", object->flags); - pr_notice(" checksum = %d\n", object->checksum); + pr_notice(" checksum = %u\n", object->checksum); pr_notice(" backtrace:\n"); print_stack_trace(&trace, 4); } -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ie0-f176.google.com (mail-ie0-f176.google.com [209.85.223.176]) by kanga.kvack.org (Postfix) with ESMTP id 42B4C6B003A for ; Fri, 2 May 2014 09:41:51 -0400 (EDT) Received: by mail-ie0-f176.google.com with SMTP id rd18so4858953iec.7 for ; Fri, 02 May 2014 06:41:51 -0700 (PDT) Received: from cam-smtp0.cambridge.arm.com (fw-tnat.cambridge.arm.com. [217.140.96.21]) by mx.google.com with ESMTPS id yk6si1120675icb.17.2014.05.02.06.41.50 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 02 May 2014 06:41:50 -0700 (PDT) From: Catalin Marinas Subject: [PATCH 3/6] lib: Update the kmemleak stack trace for radix tree allocations Date: Fri, 2 May 2014 14:41:07 +0100 Message-Id: <1399038070-1540-4-git-send-email-catalin.marinas@arm.com> In-Reply-To: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> References: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> Sender: owner-linux-mm@kvack.org List-ID: To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Johannes Weiner Since radix_tree_preload() stack trace is not always useful for debugging an actual radix tree memory leak, this patch updates the kmemleak allocation stack trace in the radix_tree_node_alloc() function. Signed-off-by: Catalin Marinas Cc: Andrew Morton Cc: Johannes Weiner --- lib/radix-tree.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/radix-tree.c b/lib/radix-tree.c index 9599aa72d7a0..5297f8e09096 100644 --- a/lib/radix-tree.c +++ b/lib/radix-tree.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -200,6 +201,11 @@ radix_tree_node_alloc(struct radix_tree_root *root) rtp->nodes[rtp->nr - 1] = NULL; rtp->nr--; } + /* + * Update the allocation stack trace as this is more useful + * for debugging. + */ + kmemleak_update_trace(ret); } if (ret == NULL) ret = kmem_cache_alloc(radix_tree_node_cachep, gfp_mask); -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ie0-f174.google.com (mail-ie0-f174.google.com [209.85.223.174]) by kanga.kvack.org (Postfix) with ESMTP id 72F176B003D for ; Fri, 2 May 2014 09:41:51 -0400 (EDT) Received: by mail-ie0-f174.google.com with SMTP id ar20so4856146iec.5 for ; Fri, 02 May 2014 06:41:51 -0700 (PDT) Received: from cam-smtp0.cambridge.arm.com (fw-tnat.cambridge.arm.com. [217.140.96.21]) by mx.google.com with ESMTPS id g20si3313073igf.36.2014.05.02.06.41.50 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 02 May 2014 06:41:50 -0700 (PDT) From: Catalin Marinas Subject: [PATCH 2/6] mm: Introduce kmemleak_update_trace() Date: Fri, 2 May 2014 14:41:06 +0100 Message-Id: <1399038070-1540-3-git-send-email-catalin.marinas@arm.com> In-Reply-To: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> References: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> Sender: owner-linux-mm@kvack.org List-ID: To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Johannes Weiner The memory allocation stack trace is not always useful for debugging a memory leak (e.g. radix_tree_preload). This function, when called, updates the stack trace for an already allocated object. Signed-off-by: Catalin Marinas Cc: Andrew Morton Cc: Johannes Weiner --- Documentation/kmemleak.txt | 1 + include/linux/kmemleak.h | 4 ++++ mm/kmemleak.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/Documentation/kmemleak.txt b/Documentation/kmemleak.txt index a7563ec4ea7b..b772418bf064 100644 --- a/Documentation/kmemleak.txt +++ b/Documentation/kmemleak.txt @@ -142,6 +142,7 @@ kmemleak_alloc_percpu - notify of a percpu memory block allocation kmemleak_free - notify of a memory block freeing kmemleak_free_part - notify of a partial memory block freeing kmemleak_free_percpu - notify of a percpu memory block freeing +kmemleak_update_trace - update object allocation stack trace kmemleak_not_leak - mark an object as not a leak kmemleak_ignore - do not scan or report an object as leak kmemleak_scan_area - add scan areas inside a memory block diff --git a/include/linux/kmemleak.h b/include/linux/kmemleak.h index 5bb424659c04..057e95971014 100644 --- a/include/linux/kmemleak.h +++ b/include/linux/kmemleak.h @@ -30,6 +30,7 @@ extern void kmemleak_alloc_percpu(const void __percpu *ptr, size_t size) __ref; extern void kmemleak_free(const void *ptr) __ref; extern void kmemleak_free_part(const void *ptr, size_t size) __ref; extern void kmemleak_free_percpu(const void __percpu *ptr) __ref; +extern void kmemleak_update_trace(const void *ptr) __ref; extern void kmemleak_not_leak(const void *ptr) __ref; extern void kmemleak_ignore(const void *ptr) __ref; extern void kmemleak_scan_area(const void *ptr, size_t size, gfp_t gfp) __ref; @@ -83,6 +84,9 @@ static inline void kmemleak_free_recursive(const void *ptr, unsigned long flags) static inline void kmemleak_free_percpu(const void __percpu *ptr) { } +static inline void kmemleak_update_trace(const void *ptr) +{ +} static inline void kmemleak_not_leak(const void *ptr) { } diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 3a36e2b16cba..61a64ed2fbef 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -990,6 +990,40 @@ void __ref kmemleak_free_percpu(const void __percpu *ptr) EXPORT_SYMBOL_GPL(kmemleak_free_percpu); /** + * kmemleak_update_trace - update object allocation stack trace + * @ptr: pointer to beginning of the object + * + * Override the object allocation stack trace for cases where the actual + * allocation place is not always useful. + */ +void __ref kmemleak_update_trace(const void *ptr) +{ + struct kmemleak_object *object; + unsigned long flags; + + pr_debug("%s(0x%p)\n", __func__, ptr); + + if (!kmemleak_enabled || IS_ERR_OR_NULL(ptr)) + return; + + object = find_and_get_object((unsigned long)ptr, 1); + if (!object) { +#ifdef DEBUG + kmemleak_warn("Updating stack trace for unknown object at %p\n", + ptr); +#endif + return; + } + + spin_lock_irqsave(&object->lock, flags); + object->trace_len = __save_stack_trace(object->trace); + spin_unlock_irqrestore(&object->lock, flags); + + put_object(object); +} +EXPORT_SYMBOL(kmemleak_update_trace); + +/** * kmemleak_not_leak - mark an allocated object as false positive * @ptr: pointer to beginning of the object * -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ee0-f47.google.com (mail-ee0-f47.google.com [74.125.83.47]) by kanga.kvack.org (Postfix) with ESMTP id A64646B0036 for ; Fri, 2 May 2014 09:48:10 -0400 (EDT) Received: by mail-ee0-f47.google.com with SMTP id b15so3176984eek.34 for ; Fri, 02 May 2014 06:48:09 -0700 (PDT) Received: from zene.cmpxchg.org (zene.cmpxchg.org. [2a01:238:4224:fa00:ca1f:9ef3:caee:a2bd]) by mx.google.com with ESMTPS id y6si1666108eep.347.2014.05.02.06.48.08 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 02 May 2014 06:48:09 -0700 (PDT) Date: Fri, 2 May 2014 09:48:04 -0400 From: Johannes Weiner Subject: Re: [PATCH 3/6] lib: Update the kmemleak stack trace for radix tree allocations Message-ID: <20140502134804.GL23420@cmpxchg.org> References: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> <1399038070-1540-4-git-send-email-catalin.marinas@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1399038070-1540-4-git-send-email-catalin.marinas@arm.com> Sender: owner-linux-mm@kvack.org List-ID: To: Catalin Marinas Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton On Fri, May 02, 2014 at 02:41:07PM +0100, Catalin Marinas wrote: > Since radix_tree_preload() stack trace is not always useful for > debugging an actual radix tree memory leak, this patch updates the > kmemleak allocation stack trace in the radix_tree_node_alloc() function. > > Signed-off-by: Catalin Marinas > Cc: Andrew Morton > Cc: Johannes Weiner Acked-by: Johannes Weiner Thanks Catalin! -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) by kanga.kvack.org (Postfix) with ESMTP id 50B888299E for ; Tue, 6 May 2014 11:20:41 -0400 (EDT) Received: by mail-vc0-f176.google.com with SMTP id lg15so1132192vcb.21 for ; Tue, 06 May 2014 08:20:41 -0700 (PDT) Received: from userp1040.oracle.com (userp1040.oracle.com. [156.151.31.81]) by mx.google.com with ESMTPS id n36si17036312yhf.169.2014.05.06.08.20.39 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 06 May 2014 08:20:39 -0700 (PDT) Message-ID: <5368FDBB.8070106@oracle.com> Date: Tue, 06 May 2014 11:20:27 -0400 From: Sasha Levin MIME-Version: 1.0 Subject: Re: [PATCH 6/6] mm: Postpone the disabling of kmemleak early logging References: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> <1399038070-1540-7-git-send-email-catalin.marinas@arm.com> In-Reply-To: <1399038070-1540-7-git-send-email-catalin.marinas@arm.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Catalin Marinas Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton On 05/02/2014 09:41 AM, Catalin Marinas wrote: > Currently, kmemleak_early_log is disabled at the beginning of the > kmemleak_init() function, before the full kmemleak tracing is actually > enabled. In this small window, kmem_cache_create() is called by kmemleak > which triggers additional memory allocation that are not traced. This > patch moves the kmemleak_early_log disabling further down and at the > same time with full kmemleak enabling. > > Signed-off-by: Catalin Marinas > Cc: Andrew Morton This patch makes the kernel die during the boot process: [ 24.471801] BUG: unable to handle kernel paging request at ffffffff922f2b93 [ 24.472496] IP: [] log_early+0x0/0xcd [ 24.473021] PGD 10e30067 PUD 10e31063 PMD 12200062 [ 24.473544] Oops: 0010 [#1] PREEMPT SMP DEBUG_PAGEALLOC [ 24.474129] Dumping ftrace buffer: [ 24.474535] (ftrace buffer empty) [ 24.474901] Modules linked in: [ 24.475220] CPU: 0 PID: 1 Comm: swapper/0 Tainted: G W 3.15.0-rc4-sasha-00193-g315d7bf #442 [ 24.476094] task: ffff88025c540000 ti: ffff880036210000 task.ti: ffff880036210000 [ 24.476807] RIP: 0010:[] [] log_early+0x0/0xcd [ 24.477561] RSP: 0000:ffff880036211c20 EFLAGS: 00010246 [ 24.478075] RAX: 0000000000000000 RBX: ffff880034e26458 RCX: 0000000000000001 [ 24.478727] RDX: 0000000000000400 RSI: ffff880034e26458 RDI: 0000000000000000 [ 24.479400] RBP: ffff880036211c48 R08: 0000000000000000 R09: 0000000000000000 [ 24.480064] R10: 0000000000000001 R11: 0000000000000001 R12: 0000000000000400 [ 24.480171] R13: 0000000000000001 R14: 0000000000000001 R15: ffff88003680e600 [ 24.480171] FS: 0000000000000000(0000) GS:ffff880036c00000(0000) knlGS:0000000000000000 [ 24.480171] CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b [ 24.480171] CR2: ffffffff922f2b93 CR3: 0000000010e2d000 CR4: 00000000000006b0 [ 24.480171] Stack: [ 24.480171] ffffffff8f4fb6ac ffff880036ddb210 ffff880034e26458 0000000000000020 [ 24.480171] ffff88003680e600 ffff880036211cc8 ffffffff8c2e0bf1 0000000000000002 [ 24.480171] 000000008c19b731 ffffffff8cb07a03 0000000000000000 0000000000000400 [ 24.480171] Call Trace: [ 24.480171] [] ? kmemleak_alloc+0xac/0xd0 [ 24.480171] [] kmem_cache_alloc_node_trace+0x201/0x3d0 [ 24.480171] [] ? alloc_cpumask_var_node+0x23/0x90 [ 24.480171] [] ? preempt_count_sub+0xd8/0x130 [ 24.480171] [] ? alloc_pte_page+0x80/0x80 [ 24.480171] [] alloc_cpumask_var_node+0x23/0x90 [ 24.480171] [] alloc_cpumask_var+0xe/0x10 [ 24.480171] [] native_send_call_func_ipi+0x2a/0x130 [ 24.480171] [] ? cpumask_next_and+0xae/0xd0 [ 24.480171] [] ? alloc_pte_page+0x80/0x80 [ 24.480171] [] ? alloc_pte_page+0x80/0x80 [ 24.480171] [] smp_call_function_many+0x29b/0x390 [ 24.480171] [] ? alloc_pte_page+0x80/0x80 [ 24.480171] [] smp_call_function+0x46/0x80 [ 24.480171] [] ? alloc_pte_page+0x80/0x80 [ 24.480171] [] on_each_cpu+0x3e/0x110 [ 24.480171] [] change_page_attr_set_clr+0x40b/0x4f0 [ 24.480171] [] ? get_parent_ip+0x11/0x50 [ 24.480171] [] set_memory_np+0x2f/0x40 [ 24.480171] [] free_init_pages+0x8d/0xb0 [ 24.480171] [] ? rest_init+0x140/0x140 [ 24.480171] [] free_initmem+0x23/0x30 [ 24.480171] [] kernel_init+0x18/0x100 [ 24.480171] [] ret_from_fork+0x7c/0xb0 [ 24.480171] [] ? rest_init+0x140/0x140 [ 24.480171] Code: Bad RIP value. [ 24.480171] RIP [] log_early+0x0/0xcd [ 24.480171] RSP [ 24.480171] CR2: ffffffff922f2b93 Thanks, Sasha -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f44.google.com (mail-pa0-f44.google.com [209.85.220.44]) by kanga.kvack.org (Postfix) with ESMTP id 3C7BA6B005A for ; Tue, 6 May 2014 13:06:32 -0400 (EDT) Received: by mail-pa0-f44.google.com with SMTP id ld10so6190869pab.17 for ; Tue, 06 May 2014 10:06:31 -0700 (PDT) Received: from collaborate-mta1.arm.com (fw-tnat.austin.arm.com. [217.140.110.23]) by mx.google.com with ESMTP id qa3si400927pbb.149.2014.05.06.10.06.30 for ; Tue, 06 May 2014 10:06:31 -0700 (PDT) Date: Tue, 6 May 2014 18:05:49 +0100 From: Catalin Marinas Subject: Re: [PATCH 6/6] mm: Postpone the disabling of kmemleak early logging Message-ID: <20140506170549.GM23957@arm.com> References: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> <1399038070-1540-7-git-send-email-catalin.marinas@arm.com> <5368FDBB.8070106@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5368FDBB.8070106@oracle.com> Sender: owner-linux-mm@kvack.org List-ID: To: Sasha Levin Cc: "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , Andrew Morton On Tue, May 06, 2014 at 04:20:27PM +0100, Sasha Levin wrote: > On 05/02/2014 09:41 AM, Catalin Marinas wrote: > > Currently, kmemleak_early_log is disabled at the beginning of the > > kmemleak_init() function, before the full kmemleak tracing is actually > > enabled. In this small window, kmem_cache_create() is called by kmemleak > > which triggers additional memory allocation that are not traced. This > > patch moves the kmemleak_early_log disabling further down and at the > > same time with full kmemleak enabling. > > > > Signed-off-by: Catalin Marinas > > Cc: Andrew Morton > > This patch makes the kernel die during the boot process: > > [ 24.471801] BUG: unable to handle kernel paging request at ffffffff922f2b93 > [ 24.472496] IP: [] log_early+0x0/0xcd Thanks for reporting this. I assume you run with CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF enabled and kmemleak_early_log remains set even though kmemleak is not in use. Does the patch below fix it? diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 0cd6aabd45a0..e7f74091c024 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -1811,6 +1811,7 @@ void __init kmemleak_init(void) #ifdef CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF if (!kmemleak_skip_disable) { + kmemleak_early_log = 0; kmemleak_disable(); return; } Thanks. -- Catalin -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ie0-f179.google.com (mail-ie0-f179.google.com [209.85.223.179]) by kanga.kvack.org (Postfix) with ESMTP id 32C696B0071 for ; Tue, 6 May 2014 14:16:09 -0400 (EDT) Received: by mail-ie0-f179.google.com with SMTP id lx4so10242693iec.38 for ; Tue, 06 May 2014 11:16:08 -0700 (PDT) Received: from aserp1040.oracle.com (aserp1040.oracle.com. [141.146.126.69]) by mx.google.com with ESMTPS id d19si20397771igz.8.2014.05.06.11.16.08 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 06 May 2014 11:16:08 -0700 (PDT) Message-ID: <536926DD.30402@oracle.com> Date: Tue, 06 May 2014 14:15:57 -0400 From: Sasha Levin MIME-Version: 1.0 Subject: Re: [PATCH 6/6] mm: Postpone the disabling of kmemleak early logging References: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> <1399038070-1540-7-git-send-email-catalin.marinas@arm.com> <5368FDBB.8070106@oracle.com> <20140506170549.GM23957@arm.com> In-Reply-To: <20140506170549.GM23957@arm.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Sender: owner-linux-mm@kvack.org List-ID: To: Catalin Marinas Cc: "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , Andrew Morton On 05/06/2014 01:05 PM, Catalin Marinas wrote: > On Tue, May 06, 2014 at 04:20:27PM +0100, Sasha Levin wrote: >> On 05/02/2014 09:41 AM, Catalin Marinas wrote: >>> Currently, kmemleak_early_log is disabled at the beginning of the >>> kmemleak_init() function, before the full kmemleak tracing is actually >>> enabled. In this small window, kmem_cache_create() is called by kmemleak >>> which triggers additional memory allocation that are not traced. This >>> patch moves the kmemleak_early_log disabling further down and at the >>> same time with full kmemleak enabling. >>> >>> Signed-off-by: Catalin Marinas >>> Cc: Andrew Morton >> >> This patch makes the kernel die during the boot process: >> >> [ 24.471801] BUG: unable to handle kernel paging request at ffffffff922f2b93 >> [ 24.472496] IP: [] log_early+0x0/0xcd > > Thanks for reporting this. I assume you run with > CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF enabled and kmemleak_early_log remains > set even though kmemleak is not in use. > > Does the patch below fix it? Nope, that didn't help as I don't have DEBUG_KMEMLEAK_DEFAULT_OFF enabled. For reference: $ cat .config | grep KMEMLEAK CONFIG_HAVE_DEBUG_KMEMLEAK=y CONFIG_DEBUG_KMEMLEAK=y CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE=400 # CONFIG_DEBUG_KMEMLEAK_TEST is not set # CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF is not set Thanks, Sasha -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wi0-f172.google.com (mail-wi0-f172.google.com [209.85.212.172]) by kanga.kvack.org (Postfix) with ESMTP id 97A9E6B0036 for ; Tue, 6 May 2014 17:52:19 -0400 (EDT) Received: by mail-wi0-f172.google.com with SMTP id hi2so3937535wib.5 for ; Tue, 06 May 2014 14:52:19 -0700 (PDT) Received: from mail-wi0-x22f.google.com (mail-wi0-x22f.google.com [2a00:1450:400c:c05::22f]) by mx.google.com with ESMTPS id vo1si6106871wjc.237.2014.05.06.14.52.18 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 06 May 2014 14:52:18 -0700 (PDT) Received: by mail-wi0-f175.google.com with SMTP id f8so4305553wiw.2 for ; Tue, 06 May 2014 14:52:18 -0700 (PDT) Subject: Re: [PATCH 6/6] mm: Postpone the disabling of kmemleak early logging Mime-Version: 1.0 (Mac OS X Mail 7.2 \(1874\)) Content-Type: text/plain; charset=windows-1252 From: Catalin Marinas In-Reply-To: <536926DD.30402@oracle.com> Date: Tue, 6 May 2014 22:52:16 +0100 Content-Transfer-Encoding: quoted-printable Message-Id: <49655FE2-17CA-433C-8F4A-76DD6C2FEF61@arm.com> References: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> <1399038070-1540-7-git-send-email-catalin.marinas@arm.com> <5368FDBB.8070106@oracle.com> <20140506170549.GM23957@arm.com> <536926DD.30402@oracle.com> Sender: owner-linux-mm@kvack.org List-ID: To: Sasha Levin Cc: "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , Andrew Morton , Li Zefan On 6 May 2014, at 19:15, Sasha Levin wrote: > On 05/06/2014 01:05 PM, Catalin Marinas wrote: >> On Tue, May 06, 2014 at 04:20:27PM +0100, Sasha Levin wrote: >>> On 05/02/2014 09:41 AM, Catalin Marinas wrote: >>>> Currently, kmemleak_early_log is disabled at the beginning of the >>>> kmemleak_init() function, before the full kmemleak tracing is = actually >>>> enabled. In this small window, kmem_cache_create() is called by = kmemleak >>>> which triggers additional memory allocation that are not traced. = This >>>> patch moves the kmemleak_early_log disabling further down and at = the >>>> same time with full kmemleak enabling. >>>>=20 >>>> Signed-off-by: Catalin Marinas >>>> Cc: Andrew Morton >>>=20 >>> This patch makes the kernel die during the boot process: >>>=20 >>> [ 24.471801] BUG: unable to handle kernel paging request at = ffffffff922f2b93 >>> [ 24.472496] IP: [] log_early+0x0/0xcd >>=20 >> Thanks for reporting this. I assume you run with >> CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF enabled and kmemleak_early_log = remains >> set even though kmemleak is not in use. >>=20 >> Does the patch below fix it? >=20 > Nope, that didn't help as I don't have DEBUG_KMEMLEAK_DEFAULT_OFF = enabled. >=20 > For reference: >=20 > $ cat .config | grep KMEMLEAK > CONFIG_HAVE_DEBUG_KMEMLEAK=3Dy > CONFIG_DEBUG_KMEMLEAK=3Dy > CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE=3D400 > # CONFIG_DEBUG_KMEMLEAK_TEST is not set > # CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF is not set I assume your dmesg shows some kmemleak error during boot? I=92ll send another patch tomorrow. The code around kmemleak_init was changed by commit 8910ae896c8c (kmemleak: change some global variables to int). It looks like it wasn=92t just a simple conversion but slightly changed the kmemleak_early_log logic which led to false positives for the kmemleak cache objects and that=92s what my patch was trying to solve. The failure is caused by kmemleak_alloc() still calling log_early() much later after the __init section has been freed because kmemleak_early_log hasn=92t been set to 0 (the default off is one path, another is the kmemleak_error path). Catalin= -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yk0-f176.google.com (mail-yk0-f176.google.com [209.85.160.176]) by kanga.kvack.org (Postfix) with ESMTP id 25ED56B0035 for ; Tue, 6 May 2014 19:08:36 -0400 (EDT) Received: by mail-yk0-f176.google.com with SMTP id q9so165086ykb.21 for ; Tue, 06 May 2014 16:08:35 -0700 (PDT) Received: from aserp1040.oracle.com (aserp1040.oracle.com. [141.146.126.69]) by mx.google.com with ESMTPS id e20si6465805yhf.213.2014.05.06.16.08.35 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 06 May 2014 16:08:35 -0700 (PDT) Message-ID: <53696B65.6070807@oracle.com> Date: Tue, 06 May 2014 19:08:21 -0400 From: Sasha Levin MIME-Version: 1.0 Subject: Re: [PATCH 6/6] mm: Postpone the disabling of kmemleak early logging References: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> <1399038070-1540-7-git-send-email-catalin.marinas@arm.com> <5368FDBB.8070106@oracle.com> <20140506170549.GM23957@arm.com> <536926DD.30402@oracle.com> <49655FE2-17CA-433C-8F4A-76DD6C2FEF61@arm.com> In-Reply-To: <49655FE2-17CA-433C-8F4A-76DD6C2FEF61@arm.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Sender: owner-linux-mm@kvack.org List-ID: To: Catalin Marinas Cc: "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , Andrew Morton , Li Zefan On 05/06/2014 05:52 PM, Catalin Marinas wrote: > On 6 May 2014, at 19:15, Sasha Levin wrote: >> On 05/06/2014 01:05 PM, Catalin Marinas wrote: >>> On Tue, May 06, 2014 at 04:20:27PM +0100, Sasha Levin wrote: >>>> On 05/02/2014 09:41 AM, Catalin Marinas wrote: >>>>> Currently, kmemleak_early_log is disabled at the beginning of the >>>>> kmemleak_init() function, before the full kmemleak tracing is actually >>>>> enabled. In this small window, kmem_cache_create() is called by kmemleak >>>>> which triggers additional memory allocation that are not traced. This >>>>> patch moves the kmemleak_early_log disabling further down and at the >>>>> same time with full kmemleak enabling. >>>>> >>>>> Signed-off-by: Catalin Marinas >>>>> Cc: Andrew Morton >>>> >>>> This patch makes the kernel die during the boot process: >>>> >>>> [ 24.471801] BUG: unable to handle kernel paging request at ffffffff922f2b93 >>>> [ 24.472496] IP: [] log_early+0x0/0xcd >>> >>> Thanks for reporting this. I assume you run with >>> CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF enabled and kmemleak_early_log remains >>> set even though kmemleak is not in use. >>> >>> Does the patch below fix it? >> >> Nope, that didn't help as I don't have DEBUG_KMEMLEAK_DEFAULT_OFF enabled. >> >> For reference: >> >> $ cat .config | grep KMEMLEAK >> CONFIG_HAVE_DEBUG_KMEMLEAK=y >> CONFIG_DEBUG_KMEMLEAK=y >> CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE=400 >> # CONFIG_DEBUG_KMEMLEAK_TEST is not set >> # CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF is not set > > I assume your dmesg shows some kmemleak error during boot? I?ll send > another patch tomorrow. Besides the BUG, I have these kmemleak messages: $ grep kmemleak out.txt [ 0.000000] kmemleak: Kernel memory leak detector disabled [ 0.000000] kmemleak: Early log buffer exceeded (2742), please increase DEBUG_KMEMLEAK_EARLY_LOG_SIZE Thanks, Sasha -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@kvack.org. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: email@kvack.org From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752315AbaEBNlw (ORCPT ); Fri, 2 May 2014 09:41:52 -0400 Received: from fw-tnat.cambridge.arm.com ([217.140.96.21]:52187 "EHLO cam-smtp0.cambridge.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751990AbaEBNlt (ORCPT ); Fri, 2 May 2014 09:41:49 -0400 From: Catalin Marinas To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton Subject: [PATCH 5/6] mm: Call kmemleak directly from memblock_(alloc|free) Date: Fri, 2 May 2014 14:41:09 +0100 Message-Id: <1399038070-1540-6-git-send-email-catalin.marinas@arm.com> X-Mailer: git-send-email 1.7.12.3 In-Reply-To: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> References: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Kmemleak could ignore memory blocks allocated via memblock_alloc() leading to false positives during scanning. This patch adds the corresponding callbacks and removes kmemleak_free_* calls in mm/nobootmem.c to avoid duplication. The kmemleak_alloc() in mm/nobootmem.c is kept since __alloc_memory_core_early() does not use memblock_alloc() directly. Signed-off-by: Catalin Marinas Cc: Andrew Morton --- mm/memblock.c | 9 ++++++++- mm/nobootmem.c | 2 -- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/mm/memblock.c b/mm/memblock.c index e9d6ca9a01a9..8813a31d7fbd 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -681,6 +681,7 @@ int __init_memblock memblock_free(phys_addr_t base, phys_addr_t size) (unsigned long long)base + size - 1, (void *)_RET_IP_); + kmemleak_free_part(__va(base), size); return __memblock_remove(&memblock.reserved, base, size); } @@ -985,8 +986,14 @@ static phys_addr_t __init memblock_alloc_base_nid(phys_addr_t size, align = SMP_CACHE_BYTES; found = memblock_find_in_range_node(size, align, 0, max_addr, nid); - if (found && !memblock_reserve(found, size)) + if (found && !memblock_reserve(found, size)) { + /* + * The min_count is set to 0 so that memblock allocations are + * never reported as leaks. + */ + kmemleak_alloc(__va(found), size, 0, 0); return found; + } return 0; } diff --git a/mm/nobootmem.c b/mm/nobootmem.c index 04a9d94333a5..7ed58602e71b 100644 --- a/mm/nobootmem.c +++ b/mm/nobootmem.c @@ -197,7 +197,6 @@ unsigned long __init free_all_bootmem(void) void __init free_bootmem_node(pg_data_t *pgdat, unsigned long physaddr, unsigned long size) { - kmemleak_free_part(__va(physaddr), size); memblock_free(physaddr, size); } @@ -212,7 +211,6 @@ void __init free_bootmem_node(pg_data_t *pgdat, unsigned long physaddr, */ void __init free_bootmem(unsigned long addr, unsigned long size) { - kmemleak_free_part(__va(addr), size); memblock_free(addr, size); } From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752433AbaEBNmK (ORCPT ); Fri, 2 May 2014 09:42:10 -0400 Received: from fw-tnat.cambridge.arm.com ([217.140.96.21]:52224 "EHLO cam-smtp0.cambridge.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752261AbaEBNlv (ORCPT ); Fri, 2 May 2014 09:41:51 -0400 From: Catalin Marinas To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Johannes Weiner Subject: [PATCH 2/6] mm: Introduce kmemleak_update_trace() Date: Fri, 2 May 2014 14:41:06 +0100 Message-Id: <1399038070-1540-3-git-send-email-catalin.marinas@arm.com> X-Mailer: git-send-email 1.7.12.3 In-Reply-To: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> References: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The memory allocation stack trace is not always useful for debugging a memory leak (e.g. radix_tree_preload). This function, when called, updates the stack trace for an already allocated object. Signed-off-by: Catalin Marinas Cc: Andrew Morton Cc: Johannes Weiner --- Documentation/kmemleak.txt | 1 + include/linux/kmemleak.h | 4 ++++ mm/kmemleak.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/Documentation/kmemleak.txt b/Documentation/kmemleak.txt index a7563ec4ea7b..b772418bf064 100644 --- a/Documentation/kmemleak.txt +++ b/Documentation/kmemleak.txt @@ -142,6 +142,7 @@ kmemleak_alloc_percpu - notify of a percpu memory block allocation kmemleak_free - notify of a memory block freeing kmemleak_free_part - notify of a partial memory block freeing kmemleak_free_percpu - notify of a percpu memory block freeing +kmemleak_update_trace - update object allocation stack trace kmemleak_not_leak - mark an object as not a leak kmemleak_ignore - do not scan or report an object as leak kmemleak_scan_area - add scan areas inside a memory block diff --git a/include/linux/kmemleak.h b/include/linux/kmemleak.h index 5bb424659c04..057e95971014 100644 --- a/include/linux/kmemleak.h +++ b/include/linux/kmemleak.h @@ -30,6 +30,7 @@ extern void kmemleak_alloc_percpu(const void __percpu *ptr, size_t size) __ref; extern void kmemleak_free(const void *ptr) __ref; extern void kmemleak_free_part(const void *ptr, size_t size) __ref; extern void kmemleak_free_percpu(const void __percpu *ptr) __ref; +extern void kmemleak_update_trace(const void *ptr) __ref; extern void kmemleak_not_leak(const void *ptr) __ref; extern void kmemleak_ignore(const void *ptr) __ref; extern void kmemleak_scan_area(const void *ptr, size_t size, gfp_t gfp) __ref; @@ -83,6 +84,9 @@ static inline void kmemleak_free_recursive(const void *ptr, unsigned long flags) static inline void kmemleak_free_percpu(const void __percpu *ptr) { } +static inline void kmemleak_update_trace(const void *ptr) +{ +} static inline void kmemleak_not_leak(const void *ptr) { } diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 3a36e2b16cba..61a64ed2fbef 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -990,6 +990,40 @@ void __ref kmemleak_free_percpu(const void __percpu *ptr) EXPORT_SYMBOL_GPL(kmemleak_free_percpu); /** + * kmemleak_update_trace - update object allocation stack trace + * @ptr: pointer to beginning of the object + * + * Override the object allocation stack trace for cases where the actual + * allocation place is not always useful. + */ +void __ref kmemleak_update_trace(const void *ptr) +{ + struct kmemleak_object *object; + unsigned long flags; + + pr_debug("%s(0x%p)\n", __func__, ptr); + + if (!kmemleak_enabled || IS_ERR_OR_NULL(ptr)) + return; + + object = find_and_get_object((unsigned long)ptr, 1); + if (!object) { +#ifdef DEBUG + kmemleak_warn("Updating stack trace for unknown object at %p\n", + ptr); +#endif + return; + } + + spin_lock_irqsave(&object->lock, flags); + object->trace_len = __save_stack_trace(object->trace); + spin_unlock_irqrestore(&object->lock, flags); + + put_object(object); +} +EXPORT_SYMBOL(kmemleak_update_trace); + +/** * kmemleak_not_leak - mark an allocated object as false positive * @ptr: pointer to beginning of the object * From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752397AbaEBNmI (ORCPT ); Fri, 2 May 2014 09:42:08 -0400 Received: from fw-tnat.cambridge.arm.com ([217.140.96.21]:52225 "EHLO cam-smtp0.cambridge.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752270AbaEBNlw (ORCPT ); Fri, 2 May 2014 09:41:52 -0400 From: Catalin Marinas To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Johannes Weiner Subject: [PATCH 3/6] lib: Update the kmemleak stack trace for radix tree allocations Date: Fri, 2 May 2014 14:41:07 +0100 Message-Id: <1399038070-1540-4-git-send-email-catalin.marinas@arm.com> X-Mailer: git-send-email 1.7.12.3 In-Reply-To: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> References: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since radix_tree_preload() stack trace is not always useful for debugging an actual radix tree memory leak, this patch updates the kmemleak allocation stack trace in the radix_tree_node_alloc() function. Signed-off-by: Catalin Marinas Cc: Andrew Morton Cc: Johannes Weiner --- lib/radix-tree.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/radix-tree.c b/lib/radix-tree.c index 9599aa72d7a0..5297f8e09096 100644 --- a/lib/radix-tree.c +++ b/lib/radix-tree.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -200,6 +201,11 @@ radix_tree_node_alloc(struct radix_tree_root *root) rtp->nodes[rtp->nr - 1] = NULL; rtp->nr--; } + /* + * Update the allocation stack trace as this is more useful + * for debugging. + */ + kmemleak_update_trace(ret); } if (ret == NULL) ret = kmem_cache_alloc(radix_tree_node_cachep, gfp_mask); From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752276AbaEBNlv (ORCPT ); Fri, 2 May 2014 09:41:51 -0400 Received: from fw-tnat.cambridge.arm.com ([217.140.96.21]:52186 "EHLO cam-smtp0.cambridge.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751983AbaEBNlt (ORCPT ); Fri, 2 May 2014 09:41:49 -0400 From: Catalin Marinas To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton Subject: [PATCH 6/6] mm: Postpone the disabling of kmemleak early logging Date: Fri, 2 May 2014 14:41:10 +0100 Message-Id: <1399038070-1540-7-git-send-email-catalin.marinas@arm.com> X-Mailer: git-send-email 1.7.12.3 In-Reply-To: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> References: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, kmemleak_early_log is disabled at the beginning of the kmemleak_init() function, before the full kmemleak tracing is actually enabled. In this small window, kmem_cache_create() is called by kmemleak which triggers additional memory allocation that are not traced. This patch moves the kmemleak_early_log disabling further down and at the same time with full kmemleak enabling. Signed-off-by: Catalin Marinas Cc: Andrew Morton --- mm/kmemleak.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 61a64ed2fbef..0cd6aabd45a0 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -1809,8 +1809,6 @@ void __init kmemleak_init(void) int i; unsigned long flags; - kmemleak_early_log = 0; - #ifdef CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF if (!kmemleak_skip_disable) { kmemleak_disable(); @@ -1833,8 +1831,9 @@ void __init kmemleak_init(void) if (kmemleak_error) { local_irq_restore(flags); return; - } else - kmemleak_enabled = 1; + } + kmemleak_early_log = 0; + kmemleak_enabled = 1; local_irq_restore(flags); /* From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752548AbaEBNmn (ORCPT ); Fri, 2 May 2014 09:42:43 -0400 Received: from fw-tnat.cambridge.arm.com ([217.140.96.21]:52216 "EHLO cam-smtp0.cambridge.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751643AbaEBNlv (ORCPT ); Fri, 2 May 2014 09:41:51 -0400 From: Catalin Marinas To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Jianpeng Ma , Andrew Morton Subject: [PATCH 1/6] mm/kmemleak.c: Use %u to print ->checksum. Date: Fri, 2 May 2014 14:41:05 +0100 Message-Id: <1399038070-1540-2-git-send-email-catalin.marinas@arm.com> X-Mailer: git-send-email 1.7.12.3 In-Reply-To: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> References: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jianpeng Ma Signed-off-by: Jianpeng Ma Signed-off-by: Catalin Marinas Cc: Andrew Morton --- mm/kmemleak.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 91d67eaee050..3a36e2b16cba 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -387,7 +387,7 @@ static void dump_object_info(struct kmemleak_object *object) pr_notice(" min_count = %d\n", object->min_count); pr_notice(" count = %d\n", object->count); pr_notice(" flags = 0x%lx\n", object->flags); - pr_notice(" checksum = %d\n", object->checksum); + pr_notice(" checksum = %u\n", object->checksum); pr_notice(" backtrace:\n"); print_stack_trace(&trace, 4); } From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752197AbaEBNlu (ORCPT ); Fri, 2 May 2014 09:41:50 -0400 Received: from fw-tnat.cambridge.arm.com ([217.140.96.21]:52185 "EHLO cam-smtp0.cambridge.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751643AbaEBNlt (ORCPT ); Fri, 2 May 2014 09:41:49 -0400 From: Catalin Marinas To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton Subject: [PATCH 0/6] Kmemleak updates Date: Fri, 2 May 2014 14:41:04 +0100 Message-Id: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> X-Mailer: git-send-email 1.7.12.3 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, This series contains a few kmemleak updates: - Avoid false positives caused by not tracking all memblock allocations and disabling the kmemleak early logging slightly earlier - Debugging improvements for places where pre-allocation happens (mempool and radix tree) - minor printk correction Catalin Marinas (5): mm: Introduce kmemleak_update_trace() lib: Update the kmemleak allocation stack trace for kmemleak mm: Update the kmemleak stack trace for mempool allocations mm: Call kmemleak directly from memblock_(alloc|free) mm: Postpone the disabling of kmemleak early logging Jianpeng Ma (1): mm/kmemleak.c: Use %u to print ->checksum. Documentation/kmemleak.txt | 1 + include/linux/kmemleak.h | 4 ++++ lib/radix-tree.c | 6 ++++++ mm/kmemleak.c | 43 ++++++++++++++++++++++++++++++++++++++----- mm/memblock.c | 9 ++++++++- mm/mempool.c | 6 ++++++ mm/nobootmem.c | 2 -- 7 files changed, 63 insertions(+), 8 deletions(-) From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752576AbaEBNnR (ORCPT ); Fri, 2 May 2014 09:43:17 -0400 Received: from fw-tnat.cambridge.arm.com ([217.140.96.21]:52188 "EHLO cam-smtp0.cambridge.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751995AbaEBNlt (ORCPT ); Fri, 2 May 2014 09:41:49 -0400 From: Catalin Marinas To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton Subject: [PATCH 4/6] mm: Update the kmemleak stack trace for mempool allocations Date: Fri, 2 May 2014 14:41:08 +0100 Message-Id: <1399038070-1540-5-git-send-email-catalin.marinas@arm.com> X-Mailer: git-send-email 1.7.12.3 In-Reply-To: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> References: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When mempool_alloc() returns an existing pool object, kmemleak_alloc() is no longer called and the stack trace corresponds to the original object allocation. This patch updates the kmemleak allocation stack trace for such objects to make it more useful for debugging. Signed-off-by: Catalin Marinas Cc: Andrew Morton --- mm/mempool.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/mempool.c b/mm/mempool.c index 905434f18c97..e7c4be024f1a 100644 --- a/mm/mempool.c +++ b/mm/mempool.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -220,6 +221,11 @@ repeat_alloc: spin_unlock_irqrestore(&pool->lock, flags); /* paired with rmb in mempool_free(), read comment there */ smp_wmb(); + /* + * Update the allocation stack trace as this is more useful + * for debugging. + */ + kmemleak_update_trace(element); return element; } From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752320AbaEBNsJ (ORCPT ); Fri, 2 May 2014 09:48:09 -0400 Received: from zene.cmpxchg.org ([85.214.230.12]:60157 "EHLO zene.cmpxchg.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752076AbaEBNsI (ORCPT ); Fri, 2 May 2014 09:48:08 -0400 Date: Fri, 2 May 2014 09:48:04 -0400 From: Johannes Weiner To: Catalin Marinas Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton Subject: Re: [PATCH 3/6] lib: Update the kmemleak stack trace for radix tree allocations Message-ID: <20140502134804.GL23420@cmpxchg.org> References: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> <1399038070-1540-4-git-send-email-catalin.marinas@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1399038070-1540-4-git-send-email-catalin.marinas@arm.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 02, 2014 at 02:41:07PM +0100, Catalin Marinas wrote: > Since radix_tree_preload() stack trace is not always useful for > debugging an actual radix tree memory leak, this patch updates the > kmemleak allocation stack trace in the radix_tree_node_alloc() function. > > Signed-off-by: Catalin Marinas > Cc: Andrew Morton > Cc: Johannes Weiner Acked-by: Johannes Weiner Thanks Catalin! From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757860AbaEFPUl (ORCPT ); Tue, 6 May 2014 11:20:41 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:29636 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755170AbaEFPUk (ORCPT ); Tue, 6 May 2014 11:20:40 -0400 Message-ID: <5368FDBB.8070106@oracle.com> Date: Tue, 06 May 2014 11:20:27 -0400 From: Sasha Levin User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: Catalin Marinas CC: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton Subject: Re: [PATCH 6/6] mm: Postpone the disabling of kmemleak early logging References: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> <1399038070-1540-7-git-send-email-catalin.marinas@arm.com> In-Reply-To: <1399038070-1540-7-git-send-email-catalin.marinas@arm.com> X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Source-IP: ucsinet21.oracle.com [156.151.31.93] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/02/2014 09:41 AM, Catalin Marinas wrote: > Currently, kmemleak_early_log is disabled at the beginning of the > kmemleak_init() function, before the full kmemleak tracing is actually > enabled. In this small window, kmem_cache_create() is called by kmemleak > which triggers additional memory allocation that are not traced. This > patch moves the kmemleak_early_log disabling further down and at the > same time with full kmemleak enabling. > > Signed-off-by: Catalin Marinas > Cc: Andrew Morton This patch makes the kernel die during the boot process: [ 24.471801] BUG: unable to handle kernel paging request at ffffffff922f2b93 [ 24.472496] IP: [] log_early+0x0/0xcd [ 24.473021] PGD 10e30067 PUD 10e31063 PMD 12200062 [ 24.473544] Oops: 0010 [#1] PREEMPT SMP DEBUG_PAGEALLOC [ 24.474129] Dumping ftrace buffer: [ 24.474535] (ftrace buffer empty) [ 24.474901] Modules linked in: [ 24.475220] CPU: 0 PID: 1 Comm: swapper/0 Tainted: G W 3.15.0-rc4-sasha-00193-g315d7bf #442 [ 24.476094] task: ffff88025c540000 ti: ffff880036210000 task.ti: ffff880036210000 [ 24.476807] RIP: 0010:[] [] log_early+0x0/0xcd [ 24.477561] RSP: 0000:ffff880036211c20 EFLAGS: 00010246 [ 24.478075] RAX: 0000000000000000 RBX: ffff880034e26458 RCX: 0000000000000001 [ 24.478727] RDX: 0000000000000400 RSI: ffff880034e26458 RDI: 0000000000000000 [ 24.479400] RBP: ffff880036211c48 R08: 0000000000000000 R09: 0000000000000000 [ 24.480064] R10: 0000000000000001 R11: 0000000000000001 R12: 0000000000000400 [ 24.480171] R13: 0000000000000001 R14: 0000000000000001 R15: ffff88003680e600 [ 24.480171] FS: 0000000000000000(0000) GS:ffff880036c00000(0000) knlGS:0000000000000000 [ 24.480171] CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b [ 24.480171] CR2: ffffffff922f2b93 CR3: 0000000010e2d000 CR4: 00000000000006b0 [ 24.480171] Stack: [ 24.480171] ffffffff8f4fb6ac ffff880036ddb210 ffff880034e26458 0000000000000020 [ 24.480171] ffff88003680e600 ffff880036211cc8 ffffffff8c2e0bf1 0000000000000002 [ 24.480171] 000000008c19b731 ffffffff8cb07a03 0000000000000000 0000000000000400 [ 24.480171] Call Trace: [ 24.480171] [] ? kmemleak_alloc+0xac/0xd0 [ 24.480171] [] kmem_cache_alloc_node_trace+0x201/0x3d0 [ 24.480171] [] ? alloc_cpumask_var_node+0x23/0x90 [ 24.480171] [] ? preempt_count_sub+0xd8/0x130 [ 24.480171] [] ? alloc_pte_page+0x80/0x80 [ 24.480171] [] alloc_cpumask_var_node+0x23/0x90 [ 24.480171] [] alloc_cpumask_var+0xe/0x10 [ 24.480171] [] native_send_call_func_ipi+0x2a/0x130 [ 24.480171] [] ? cpumask_next_and+0xae/0xd0 [ 24.480171] [] ? alloc_pte_page+0x80/0x80 [ 24.480171] [] ? alloc_pte_page+0x80/0x80 [ 24.480171] [] smp_call_function_many+0x29b/0x390 [ 24.480171] [] ? alloc_pte_page+0x80/0x80 [ 24.480171] [] smp_call_function+0x46/0x80 [ 24.480171] [] ? alloc_pte_page+0x80/0x80 [ 24.480171] [] on_each_cpu+0x3e/0x110 [ 24.480171] [] change_page_attr_set_clr+0x40b/0x4f0 [ 24.480171] [] ? get_parent_ip+0x11/0x50 [ 24.480171] [] set_memory_np+0x2f/0x40 [ 24.480171] [] free_init_pages+0x8d/0xb0 [ 24.480171] [] ? rest_init+0x140/0x140 [ 24.480171] [] free_initmem+0x23/0x30 [ 24.480171] [] kernel_init+0x18/0x100 [ 24.480171] [] ret_from_fork+0x7c/0xb0 [ 24.480171] [] ? rest_init+0x140/0x140 [ 24.480171] Code: Bad RIP value. [ 24.480171] RIP [] log_early+0x0/0xcd [ 24.480171] RSP [ 24.480171] CR2: ffffffff922f2b93 Thanks, Sasha From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751556AbaEFRG1 (ORCPT ); Tue, 6 May 2014 13:06:27 -0400 Received: from fw-tnat.austin.arm.com ([217.140.110.23]:14157 "EHLO collaborate-mta1.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750830AbaEFRGZ (ORCPT ); Tue, 6 May 2014 13:06:25 -0400 Date: Tue, 6 May 2014 18:05:49 +0100 From: Catalin Marinas To: Sasha Levin Cc: "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , Andrew Morton Subject: Re: [PATCH 6/6] mm: Postpone the disabling of kmemleak early logging Message-ID: <20140506170549.GM23957@arm.com> References: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> <1399038070-1540-7-git-send-email-catalin.marinas@arm.com> <5368FDBB.8070106@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5368FDBB.8070106@oracle.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 06, 2014 at 04:20:27PM +0100, Sasha Levin wrote: > On 05/02/2014 09:41 AM, Catalin Marinas wrote: > > Currently, kmemleak_early_log is disabled at the beginning of the > > kmemleak_init() function, before the full kmemleak tracing is actually > > enabled. In this small window, kmem_cache_create() is called by kmemleak > > which triggers additional memory allocation that are not traced. This > > patch moves the kmemleak_early_log disabling further down and at the > > same time with full kmemleak enabling. > > > > Signed-off-by: Catalin Marinas > > Cc: Andrew Morton > > This patch makes the kernel die during the boot process: > > [ 24.471801] BUG: unable to handle kernel paging request at ffffffff922f2b93 > [ 24.472496] IP: [] log_early+0x0/0xcd Thanks for reporting this. I assume you run with CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF enabled and kmemleak_early_log remains set even though kmemleak is not in use. Does the patch below fix it? diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 0cd6aabd45a0..e7f74091c024 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -1811,6 +1811,7 @@ void __init kmemleak_init(void) #ifdef CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF if (!kmemleak_skip_disable) { + kmemleak_early_log = 0; kmemleak_disable(); return; } Thanks. -- Catalin From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753315AbaEFSQL (ORCPT ); Tue, 6 May 2014 14:16:11 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:36983 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752326AbaEFSQJ (ORCPT ); Tue, 6 May 2014 14:16:09 -0400 Message-ID: <536926DD.30402@oracle.com> Date: Tue, 06 May 2014 14:15:57 -0400 From: Sasha Levin User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: Catalin Marinas CC: "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , Andrew Morton Subject: Re: [PATCH 6/6] mm: Postpone the disabling of kmemleak early logging References: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> <1399038070-1540-7-git-send-email-catalin.marinas@arm.com> <5368FDBB.8070106@oracle.com> <20140506170549.GM23957@arm.com> In-Reply-To: <20140506170549.GM23957@arm.com> X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Source-IP: acsinet21.oracle.com [141.146.126.237] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/06/2014 01:05 PM, Catalin Marinas wrote: > On Tue, May 06, 2014 at 04:20:27PM +0100, Sasha Levin wrote: >> On 05/02/2014 09:41 AM, Catalin Marinas wrote: >>> Currently, kmemleak_early_log is disabled at the beginning of the >>> kmemleak_init() function, before the full kmemleak tracing is actually >>> enabled. In this small window, kmem_cache_create() is called by kmemleak >>> which triggers additional memory allocation that are not traced. This >>> patch moves the kmemleak_early_log disabling further down and at the >>> same time with full kmemleak enabling. >>> >>> Signed-off-by: Catalin Marinas >>> Cc: Andrew Morton >> >> This patch makes the kernel die during the boot process: >> >> [ 24.471801] BUG: unable to handle kernel paging request at ffffffff922f2b93 >> [ 24.472496] IP: [] log_early+0x0/0xcd > > Thanks for reporting this. I assume you run with > CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF enabled and kmemleak_early_log remains > set even though kmemleak is not in use. > > Does the patch below fix it? Nope, that didn't help as I don't have DEBUG_KMEMLEAK_DEFAULT_OFF enabled. For reference: $ cat .config | grep KMEMLEAK CONFIG_HAVE_DEBUG_KMEMLEAK=y CONFIG_DEBUG_KMEMLEAK=y CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE=400 # CONFIG_DEBUG_KMEMLEAK_TEST is not set # CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF is not set Thanks, Sasha From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752145AbaEFVwU (ORCPT ); Tue, 6 May 2014 17:52:20 -0400 Received: from mail-wi0-f174.google.com ([209.85.212.174]:63415 "EHLO mail-wi0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751110AbaEFVwT convert rfc822-to-8bit (ORCPT ); Tue, 6 May 2014 17:52:19 -0400 Subject: Re: [PATCH 6/6] mm: Postpone the disabling of kmemleak early logging Mime-Version: 1.0 (Mac OS X Mail 7.2 \(1874\)) Content-Type: text/plain; charset=windows-1252 From: Catalin Marinas In-Reply-To: <536926DD.30402@oracle.com> Date: Tue, 6 May 2014 22:52:16 +0100 Cc: "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , Andrew Morton , Li Zefan Content-Transfer-Encoding: 8BIT Message-Id: <49655FE2-17CA-433C-8F4A-76DD6C2FEF61@arm.com> References: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> <1399038070-1540-7-git-send-email-catalin.marinas@arm.com> <5368FDBB.8070106@oracle.com> <20140506170549.GM23957@arm.com> <536926DD.30402@oracle.com> To: Sasha Levin X-Mailer: Apple Mail (2.1874) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6 May 2014, at 19:15, Sasha Levin wrote: > On 05/06/2014 01:05 PM, Catalin Marinas wrote: >> On Tue, May 06, 2014 at 04:20:27PM +0100, Sasha Levin wrote: >>> On 05/02/2014 09:41 AM, Catalin Marinas wrote: >>>> Currently, kmemleak_early_log is disabled at the beginning of the >>>> kmemleak_init() function, before the full kmemleak tracing is actually >>>> enabled. In this small window, kmem_cache_create() is called by kmemleak >>>> which triggers additional memory allocation that are not traced. This >>>> patch moves the kmemleak_early_log disabling further down and at the >>>> same time with full kmemleak enabling. >>>> >>>> Signed-off-by: Catalin Marinas >>>> Cc: Andrew Morton >>> >>> This patch makes the kernel die during the boot process: >>> >>> [ 24.471801] BUG: unable to handle kernel paging request at ffffffff922f2b93 >>> [ 24.472496] IP: [] log_early+0x0/0xcd >> >> Thanks for reporting this. I assume you run with >> CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF enabled and kmemleak_early_log remains >> set even though kmemleak is not in use. >> >> Does the patch below fix it? > > Nope, that didn't help as I don't have DEBUG_KMEMLEAK_DEFAULT_OFF enabled. > > For reference: > > $ cat .config | grep KMEMLEAK > CONFIG_HAVE_DEBUG_KMEMLEAK=y > CONFIG_DEBUG_KMEMLEAK=y > CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE=400 > # CONFIG_DEBUG_KMEMLEAK_TEST is not set > # CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF is not set I assume your dmesg shows some kmemleak error during boot? I’ll send another patch tomorrow. The code around kmemleak_init was changed by commit 8910ae896c8c (kmemleak: change some global variables to int). It looks like it wasn’t just a simple conversion but slightly changed the kmemleak_early_log logic which led to false positives for the kmemleak cache objects and that’s what my patch was trying to solve. The failure is caused by kmemleak_alloc() still calling log_early() much later after the __init section has been freed because kmemleak_early_log hasn’t been set to 0 (the default off is one path, another is the kmemleak_error path). Catalin From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753395AbaEFXIh (ORCPT ); Tue, 6 May 2014 19:08:37 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:29088 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750912AbaEFXIg (ORCPT ); Tue, 6 May 2014 19:08:36 -0400 Message-ID: <53696B65.6070807@oracle.com> Date: Tue, 06 May 2014 19:08:21 -0400 From: Sasha Levin User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: Catalin Marinas CC: "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , Andrew Morton , Li Zefan Subject: Re: [PATCH 6/6] mm: Postpone the disabling of kmemleak early logging References: <1399038070-1540-1-git-send-email-catalin.marinas@arm.com> <1399038070-1540-7-git-send-email-catalin.marinas@arm.com> <5368FDBB.8070106@oracle.com> <20140506170549.GM23957@arm.com> <536926DD.30402@oracle.com> <49655FE2-17CA-433C-8F4A-76DD6C2FEF61@arm.com> In-Reply-To: <49655FE2-17CA-433C-8F4A-76DD6C2FEF61@arm.com> X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Source-IP: ucsinet21.oracle.com [156.151.31.93] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/06/2014 05:52 PM, Catalin Marinas wrote: > On 6 May 2014, at 19:15, Sasha Levin wrote: >> On 05/06/2014 01:05 PM, Catalin Marinas wrote: >>> On Tue, May 06, 2014 at 04:20:27PM +0100, Sasha Levin wrote: >>>> On 05/02/2014 09:41 AM, Catalin Marinas wrote: >>>>> Currently, kmemleak_early_log is disabled at the beginning of the >>>>> kmemleak_init() function, before the full kmemleak tracing is actually >>>>> enabled. In this small window, kmem_cache_create() is called by kmemleak >>>>> which triggers additional memory allocation that are not traced. This >>>>> patch moves the kmemleak_early_log disabling further down and at the >>>>> same time with full kmemleak enabling. >>>>> >>>>> Signed-off-by: Catalin Marinas >>>>> Cc: Andrew Morton >>>> >>>> This patch makes the kernel die during the boot process: >>>> >>>> [ 24.471801] BUG: unable to handle kernel paging request at ffffffff922f2b93 >>>> [ 24.472496] IP: [] log_early+0x0/0xcd >>> >>> Thanks for reporting this. I assume you run with >>> CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF enabled and kmemleak_early_log remains >>> set even though kmemleak is not in use. >>> >>> Does the patch below fix it? >> >> Nope, that didn't help as I don't have DEBUG_KMEMLEAK_DEFAULT_OFF enabled. >> >> For reference: >> >> $ cat .config | grep KMEMLEAK >> CONFIG_HAVE_DEBUG_KMEMLEAK=y >> CONFIG_DEBUG_KMEMLEAK=y >> CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE=400 >> # CONFIG_DEBUG_KMEMLEAK_TEST is not set >> # CONFIG_DEBUG_KMEMLEAK_DEFAULT_OFF is not set > > I assume your dmesg shows some kmemleak error during boot? I’ll send > another patch tomorrow. Besides the BUG, I have these kmemleak messages: $ grep kmemleak out.txt [ 0.000000] kmemleak: Kernel memory leak detector disabled [ 0.000000] kmemleak: Early log buffer exceeded (2742), please increase DEBUG_KMEMLEAK_EARLY_LOG_SIZE Thanks, Sasha