From patchwork Fri May 2 13:41:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 29544 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 72017203F3 for ; Fri, 2 May 2014 13:42:21 +0000 (UTC) Received: by mail-ve0-f200.google.com with SMTP id jw12sf13353189veb.3 for ; Fri, 02 May 2014 06:42:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=dyAkqkByIW9l+w7197EjZam5bATDGvvrl4wuQMxkAro=; b=mjih053oVcvqwb67faHptkv1jAKW/gYxxureEwXCaCToiR+rvndq7TehiaYvWN+QUW EMB/gWjt0og9DkO+sKoH5I+eDOJiMrNigTsD3GuA9XlUVogw013eKD2YOnzZ+mPJ5dlu yBEEITeISXS9AI3ixGmbDmuAQ1VzSvFVXgxBQWdPCarnaVZEndD557pVI7scQJzyoB6c YcGUkEHxRsvUejK9OrrqrQJAWYMhYbowsQag9sXFzQKzQNHZphXPGpF8EwCCNZ7Jx+Eo pzGws5rQAq12KFkMZ6f0jq8VK+W/+at25ICZbzP/M7KxMQr/EJK6BWb+fCBXLE7hHATf Wizw== X-Gm-Message-State: ALoCoQnakwaxYFRdGBkBTYW24K/kJ1EarshZzX0RIHXyLvONfN+r3fBWRFsrCatTvYL6M934+7Rw X-Received: by 10.236.231.52 with SMTP id k50mr7972916yhq.52.1399038141225; Fri, 02 May 2014 06:42:21 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.109.200 with SMTP id l66ls1472448qgf.33.gmail; Fri, 02 May 2014 06:42:21 -0700 (PDT) X-Received: by 10.58.46.207 with SMTP id x15mr13931547vem.17.1399038141119; Fri, 02 May 2014 06:42:21 -0700 (PDT) Received: from mail-vc0-f177.google.com (mail-vc0-f177.google.com [209.85.220.177]) by mx.google.com with ESMTPS id o2si6710409vew.115.2014.05.02.06.42.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 02 May 2014 06:42:21 -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.177; Received: by mail-vc0-f177.google.com with SMTP id if11so5362081vcb.36 for ; Fri, 02 May 2014 06:42:21 -0700 (PDT) X-Received: by 10.52.108.164 with SMTP id hl4mr11356015vdb.25.1399038141022; Fri, 02 May 2014 06:42:21 -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 ib8csp103831vcb; Fri, 2 May 2014 06:42:20 -0700 (PDT) X-Received: by 10.66.253.170 with SMTP id ab10mr35013615pad.53.1399038140240; Fri, 02 May 2014 06:42:20 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id xx4si22837834pac.396.2014.05.02.06.42.19 for ; Fri, 02 May 2014 06:42:19 -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 S1752434AbaEBNmK (ORCPT + 28 others); 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 Received: from e102109-lin.cambridge.arm.com (e102109-lin.cambridge.arm.com [10.1.203.182]) by cam-smtp0.cambridge.arm.com (8.13.8/8.13.8) with ESMTP id s42Dfg2i030889; Fri, 2 May 2014 14:41:43 +0100 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 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: , 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(+) -- 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/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 *