Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756568AbYK2Kpd (ORCPT ); Sat, 29 Nov 2008 05:45:33 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1756167AbYK2Knw (ORCPT ); Sat, 29 Nov 2008 05:43:52 -0500 Received: from cam-admin0.cambridge.arm.com ([193.131.176.58]:41370 "EHLO cam-admin0.cambridge.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756155AbYK2Knv (ORCPT ); Sat, 29 Nov 2008 05:43:51 -0500 Subject: [PATCH 06/15] kmemleak: Add the vmalloc memory allocation/freeing hooks To: linux-kernel@vger.kernel.org From: Catalin Marinas Cc: Ingo Molnar Date: Sat, 29 Nov 2008 10:43:40 +0000 Message-ID: <20081129104340.16726.60236.stgit@pc1117.cambridge.arm.com> In-Reply-To: <20081129103908.16726.24264.stgit@pc1117.cambridge.arm.com> References: <20081129103908.16726.24264.stgit@pc1117.cambridge.arm.com> User-Agent: StGit/0.14.3.288.gdd3f MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 29 Nov 2008 10:43:40.0423 (UTC) FILETIME=[57966170:01C9520F] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2365 Lines: 83 This patch adds the callbacks to memleak_(alloc|free) functions from vmalloc/vfree. Signed-off-by: Catalin Marinas Cc: Ingo Molnar --- mm/vmalloc.c | 29 ++++++++++++++++++++++++++--- 1 files changed, 26 insertions(+), 3 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index ba6b0f5..c0340ac 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -1173,6 +1174,9 @@ static void __vunmap(const void *addr, int deallocate_pages) void vfree(const void *addr) { BUG_ON(in_interrupt()); + + memleak_free(addr); + __vunmap(addr, 1); } EXPORT_SYMBOL(vfree); @@ -1282,8 +1286,17 @@ fail: void *__vmalloc_area(struct vm_struct *area, gfp_t gfp_mask, pgprot_t prot) { - return __vmalloc_area_node(area, gfp_mask, prot, -1, - __builtin_return_address(0)); + void *addr = __vmalloc_area_node(area, gfp_mask, prot, -1, + __builtin_return_address(0)); + + /* + * This needs ref_count = 2 since vm_struct also contains a + * pointer to this address. The guard page is also subtracted + * from the size. + */ + memleak_alloc(addr, area->size - PAGE_SIZE, 2); + + return addr; } /** @@ -1302,6 +1315,8 @@ static void *__vmalloc_node(unsigned long size, gfp_t gfp_mask, pgprot_t prot, int node, void *caller) { struct vm_struct *area; + void *addr; + unsigned long real_size = size; size = PAGE_ALIGN(size); if (!size || (size >> PAGE_SHIFT) > num_physpages) @@ -1313,7 +1328,15 @@ static void *__vmalloc_node(unsigned long size, gfp_t gfp_mask, pgprot_t prot, if (!area) return NULL; - return __vmalloc_area_node(area, gfp_mask, prot, node, caller); + addr = __vmalloc_area_node(area, gfp_mask, prot, node, caller); + + /* + * This needs ref_count = 2 since the vm_struct also contains + * a pointer to this address. + */ + memleak_alloc(addr, real_size, 2); + + return addr; } void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/