From: Catalin Marinas <catalin.marinas@arm.com>
To: linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@google.com>, Steven Rostedt <rostedt@goodmis.org>
Subject: [PATCH 1/4] kmemleak: Show where early_log issues come from
Date: Thu, 29 Sep 2011 12:02:22 +0100 [thread overview]
Message-ID: <20110929110222.10660.49002.stgit@e102109-lin.cambridge.arm.com> (raw)
In-Reply-To: <20110929105940.10660.76130.stgit@e102109-lin.cambridge.arm.com>
Based on initial patch by Steven Rostedt.
Early kmemleak warnings did not show where the actual kmemleak API had
been called from but rather just a backtrace to the kmemleak_init()
function. By having all early kmemleak logs record the stack_trace, we
can have kmemleak_init() write exactly where the problem occurred. This
patch adds the setting of the kmemleak_warning variable every time a
kmemleak warning is issued. The kmemleak_init() function checks this
variable during early log replaying and prints the log trace if there
was any warning.
Reported-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Andrew Morton <akpm@google.com>
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
---
mm/kmemleak.c | 37 ++++++++++++++++++++++++++++---------
1 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/mm/kmemleak.c b/mm/kmemleak.c
index d6880f5..573152e 100644
--- a/mm/kmemleak.c
+++ b/mm/kmemleak.c
@@ -196,7 +196,9 @@ static atomic_t kmemleak_enabled = ATOMIC_INIT(0);
static atomic_t kmemleak_initialized = ATOMIC_INIT(0);
/* enables or disables early logging of the memory operations */
static atomic_t kmemleak_early_log = ATOMIC_INIT(1);
-/* set if a fata kmemleak error has occurred */
+/* set if a kmemleak warning was issued */
+static atomic_t kmemleak_warning = ATOMIC_INIT(0);
+/* set if a fatal kmemleak error has occurred */
static atomic_t kmemleak_error = ATOMIC_INIT(0);
/* minimum and maximum address that may be valid pointers */
@@ -259,9 +261,10 @@ static void kmemleak_disable(void);
/*
* Print a warning and dump the stack trace.
*/
-#define kmemleak_warn(x...) do { \
- pr_warning(x); \
- dump_stack(); \
+#define kmemleak_warn(x...) do { \
+ pr_warning(x); \
+ dump_stack(); \
+ atomic_set(&kmemleak_warning, 1); \
} while (0)
/*
@@ -403,8 +406,8 @@ static struct kmemleak_object *lookup_object(unsigned long ptr, int alias)
object = prio_tree_entry(node, struct kmemleak_object,
tree_node);
if (!alias && object->pointer != ptr) {
- pr_warning("Found object by alias at 0x%08lx\n", ptr);
- dump_stack();
+ kmemleak_warn("Found object by alias at 0x%08lx\n",
+ ptr);
dump_object_info(object);
object = NULL;
}
@@ -811,8 +814,7 @@ static void __init log_early(int op_type, const void *ptr, size_t size,
log->ptr = ptr;
log->size = size;
log->min_count = min_count;
- if (op_type == KMEMLEAK_ALLOC)
- log->trace_len = __save_stack_trace(log->trace);
+ log->trace_len = __save_stack_trace(log->trace);
crt_early_log++;
local_irq_restore(flags);
}
@@ -1659,6 +1661,17 @@ static int kmemleak_boot_config(char *str)
}
early_param("kmemleak", kmemleak_boot_config);
+static void __init print_log_trace(struct early_log *log)
+{
+ struct stack_trace trace;
+
+ trace.nr_entries = log->trace_len;
+ trace.entries = log->trace;
+
+ pr_notice("Early log backtrace:\n");
+ print_stack_trace(&trace, 2);
+}
+
/*
* Kmemleak initialization.
*/
@@ -1720,7 +1733,13 @@ void __init kmemleak_init(void)
kmemleak_no_scan(log->ptr);
break;
default:
- WARN_ON(1);
+ kmemleak_warn("Unknown early log operation: %d\n",
+ log->op_type);
+ }
+
+ if (atomic_read(&kmemleak_warning)) {
+ print_log_trace(log);
+ atomic_set(&kmemleak_warning, 0);
}
}
}
next prev parent reply other threads:[~2011-09-29 11:02 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-29 11:02 [PATCH 0/4] Kmemleak patches for -next Catalin Marinas
2011-09-29 11:02 ` Catalin Marinas [this message]
2011-09-29 11:02 ` [PATCH 2/4] kmemleak: Handle percpu memory allocation Catalin Marinas
2011-09-29 11:56 ` Eric Dumazet
2011-09-29 17:17 ` Catalin Marinas
2011-09-29 17:57 ` Christoph Lameter
2011-09-29 19:28 ` Tejun Heo
2011-09-30 8:37 ` Catalin Marinas
2011-10-03 15:21 ` Catalin Marinas
2011-10-03 16:14 ` Christoph Lameter
2011-10-04 7:59 ` Tejun Heo
2011-10-04 9:04 ` Catalin Marinas
2011-10-04 9:13 ` Tejun Heo
2011-10-04 9:26 ` Catalin Marinas
2011-10-04 16:59 ` Tejun Heo
2011-10-04 17:06 ` Catalin Marinas
2011-09-29 11:02 ` [PATCH 3/4] kmemleak: When the early log buffer is exceeded, report the actual number Catalin Marinas
2011-09-29 11:02 ` [PATCH 4/4] kmemleak: Report previously found leaks even after an error Catalin Marinas
2011-10-04 17:45 ` Nick Bowler
2011-10-04 20:50 ` Catalin Marinas
2011-10-04 21:14 ` Nick Bowler
2011-10-24 18:57 ` Nick Bowler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110929110222.10660.49002.stgit@e102109-lin.cambridge.arm.com \
--to=catalin.marinas@arm.com \
--cc=akpm@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®