From patchwork Thu May 1 17:06:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 29524 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f200.google.com (mail-ve0-f200.google.com [209.85.128.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 27DBB20675 for ; Thu, 1 May 2014 17:09:32 +0000 (UTC) Received: by mail-ve0-f200.google.com with SMTP id jw12sf9218609veb.7 for ; Thu, 01 May 2014 10:09:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:date:from:to:cc:subject:message-id :references:mime-version:in-reply-to:user-agent:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe :content-type:content-disposition; bh=60M0U0XKvOoOG5ukGfQzIQu0BuIMwM6HsA2az9Fy8lY=; b=gvOikd9qbLQEQ/606PBJdp3PBDWubPZg2Cpt0H6wJekeL/VwLRxjPjJFRRCFMiB1du fG7U/WB+qnG+sy1d/MN3gQYoPlD6C3RnYoJtf9gInyUjo+dpAJhpbykfimqLQp3U/6Db 2wIaKQSaArNVwGSiTUF5SZmCqzkvbP0OaUdDql+q/Ch17am+GvsAuVMzHWI0897/mbIo CspdkW2/ivaVazC0WTMTgmjGJXbXbZOmLOKdRg8cw/+V4vaWN0SAOh6tuCkD8UoUFWdw Vr6aytI9MILdOEap59Mza+uBQODy5iUG+UsBikfEM+uiPtig5OQ4LMYEvcZsnC7Ix35/ +8Aw== X-Gm-Message-State: ALoCoQmXtXdHLPo1Tr32624Kmbd3KiCS+sYUd4VuLshDx1t63k9a+dZ4Nz7K2CmhjLuz0gxrDDbe X-Received: by 10.236.231.52 with SMTP id k50mr5563089yhq.52.1398964171851; Thu, 01 May 2014 10:09:31 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.84.239 with SMTP id l102ls1230097qgd.81.gmail; Thu, 01 May 2014 10:09:31 -0700 (PDT) X-Received: by 10.221.58.144 with SMTP id wk16mr9356966vcb.23.1398964171739; Thu, 01 May 2014 10:09:31 -0700 (PDT) Received: from mail-vc0-f179.google.com (mail-vc0-f179.google.com [209.85.220.179]) by mx.google.com with ESMTPS id sc12si6162805veb.133.2014.05.01.10.09.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 10:09:31 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.220.179; Received: by mail-vc0-f179.google.com with SMTP id ij19so4149674vcb.24 for ; Thu, 01 May 2014 10:09:31 -0700 (PDT) X-Received: by 10.220.191.134 with SMTP id dm6mr9500366vcb.16.1398964171634; Thu, 01 May 2014 10:09:31 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp39345vcb; Thu, 1 May 2014 10:09:31 -0700 (PDT) X-Received: by 10.66.65.169 with SMTP id y9mr23178655pas.145.1398964170702; Thu, 01 May 2014 10:09:30 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id wh9si21274289pac.377.2014.05.01.10.09.29; Thu, 01 May 2014 10:09:29 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751214AbaEARHB (ORCPT + 28 others); Thu, 1 May 2014 13:07:01 -0400 Received: from fw-tnat.austin.arm.com ([217.140.110.23]:26364 "EHLO collaborate-mta1.arm.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750818AbaEARG7 (ORCPT ); Thu, 1 May 2014 13:06:59 -0400 Received: from arm.com (e102109-lin.cambridge.arm.com [10.1.203.182]) by collaborate-mta1.arm.com (Postfix) with ESMTPS id 7B6BE13F8F4; Thu, 1 May 2014 12:06:43 -0500 (CDT) Date: Thu, 1 May 2014 18:06:10 +0100 From: Catalin Marinas To: Jaegeuk Kim Cc: "Linux Kernel, Mailing List" , "linux-mm@kvack.org" , Johannes Weiner Subject: Re: [BUG] kmemleak on __radix_tree_preload Message-ID: <20140501170610.GB28745@arm.com> References: <1398390340.4283.36.camel@kjgkr> MIME-Version: 1.0 In-Reply-To: <1398390340.4283.36.camel@kjgkr> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: catalin.marinas@arm.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Content-Disposition: inline On Fri, Apr 25, 2014 at 10:45:40AM +0900, Jaegeuk Kim wrote: > 2. Bug > This is one of the results, but all the results indicate > __radix_tree_preload. > > unreferenced object 0xffff88002ae2a238 (size 576): > comm "fsstress", pid 25019, jiffies 4295651360 (age 2276.104s) > hex dump (first 32 bytes): > 01 00 00 00 81 ff ff ff 00 00 00 00 00 00 00 00 ................ > 40 7d 37 81 ff ff ff ff 50 a2 e2 2a 00 88 ff ff @}7.....P..*.... > backtrace: > [] kmemleak_alloc+0x26/0x50 > [] kmem_cache_alloc+0xdc/0x190 > [] __radix_tree_preload+0x49/0xc0 > [] radix_tree_maybe_preload+0x21/0x30 > [] add_to_page_cache_lru+0x3c/0xc0 > [] grab_cache_page_write_begin+0x98/0xf0 > [] f2fs_write_begin+0xa1/0x370 [f2fs] > [] generic_perform_write+0xc7/0x1e0 > [] __generic_file_aio_write+0x1d0/0x400 > [] generic_file_aio_write+0x60/0xe0 > [] do_sync_write+0x5a/0x90 > [] vfs_write+0xc5/0x1f0 > [] SyS_write+0x52/0xb0 > [] system_call_fastpath+0x16/0x1b > [] 0xffffffffffffffff Do all the backtraces look like the above (coming from add_to_page_cache_lru)? There were some changes in lib/radix-tree.c since 3.14, maybe you could try reverting them and see if the leaks still appear (cc'ing Johannes). It could also be a false positive. An issue with debugging such cases is that the preloading is common for multiple radix trees, so the actual radix_tree_node_alloc() could be on a different path. You could give the patch below a try to see what backtrace you get (it updates backtrace in radix_tree_node_alloc()). --- 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/ 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/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); 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 *