linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: js1304@gmail.com
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>,
	Alexander Potapenko <glider@google.com>,
	Dmitry Vyukov <dvyukov@google.com>,
	kasan-dev@googlegroups.com, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, Namhyung Kim <namhyung@kernel.org>,
	Wengang Wang <wen.gang.wang@oracle.com>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>
Subject: [PATCH 06/18] lib/stackdepot: Add is_new arg to depot_save_stack
Date: Tue, 28 Nov 2017 16:48:41 +0900	[thread overview]
Message-ID: <1511855333-3570-7-git-send-email-iamjoonsoo.kim@lge.com> (raw)
In-Reply-To: <1511855333-3570-1-git-send-email-iamjoonsoo.kim@lge.com>

From: Namhyung Kim <namhyung@kernel.org>

The is_new argument is to check whether the given stack trace was
already in the stack depot or newly added.  It'll be used by vchecker
callstack in the next patch.

Also add WARN_ONCE if stack depot failed to allocate stack slab for some
reason.  This is unusual as it allocates the stack slab before its use
but sometimes users might want to know its failure.  Passing
__GFP_NOWARN in the alloc_flags will bypass it though.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
---
 include/linux/stackdepot.h |  3 ++-
 lib/stackdepot.c           | 15 +++++++++++++--
 mm/kasan/kasan.c           |  2 +-
 mm/kasan/vchecker.c        |  2 +-
 mm/page_owner.c            |  4 ++--
 5 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/include/linux/stackdepot.h b/include/linux/stackdepot.h
index 7978b3e..93363f2 100644
--- a/include/linux/stackdepot.h
+++ b/include/linux/stackdepot.h
@@ -25,7 +25,8 @@ typedef u32 depot_stack_handle_t;
 
 struct stack_trace;
 
-depot_stack_handle_t depot_save_stack(struct stack_trace *trace, gfp_t flags);
+depot_stack_handle_t depot_save_stack(struct stack_trace *trace, gfp_t flags,
+				      bool *is_new);
 
 void depot_fetch_stack(depot_stack_handle_t handle, struct stack_trace *trace);
 
diff --git a/lib/stackdepot.c b/lib/stackdepot.c
index f87d138..e40ccb6 100644
--- a/lib/stackdepot.c
+++ b/lib/stackdepot.c
@@ -130,8 +130,11 @@ static struct stack_record *depot_alloc_stack(unsigned long *entries, int size,
 			smp_store_release(&next_slab_inited, 0);
 	}
 	init_stack_slab(prealloc);
-	if (stack_slabs[depot_index] == NULL)
+	if (stack_slabs[depot_index] == NULL) {
+		if (!(alloc_flags & __GFP_NOWARN))
+			WARN_ONCE(1, "Stack depot failed to allocate stack_slabs");
 		return NULL;
+	}
 
 	stack = stack_slabs[depot_index] + depot_offset;
 
@@ -198,11 +201,12 @@ EXPORT_SYMBOL_GPL(depot_fetch_stack);
  * depot_save_stack - save stack in a stack depot.
  * @trace - the stacktrace to save.
  * @alloc_flags - flags for allocating additional memory if required.
+ * @is_new - set #true when @trace was not in the stack depot.
  *
  * Returns the handle of the stack struct stored in depot.
  */
 depot_stack_handle_t depot_save_stack(struct stack_trace *trace,
-				    gfp_t alloc_flags)
+				      gfp_t alloc_flags, bool *is_new)
 {
 	u32 hash;
 	depot_stack_handle_t retval = 0;
@@ -236,6 +240,8 @@ depot_stack_handle_t depot_save_stack(struct stack_trace *trace,
 	 * |next_slab_inited| in depot_alloc_stack() and init_stack_slab().
 	 */
 	if (unlikely(!smp_load_acquire(&next_slab_inited))) {
+		gfp_t orig_flags = alloc_flags;
+
 		/*
 		 * Zero out zone modifiers, as we don't have specific zone
 		 * requirements. Keep the flags related to allocation in atomic
@@ -247,6 +253,9 @@ depot_stack_handle_t depot_save_stack(struct stack_trace *trace,
 		page = alloc_pages(alloc_flags, STACK_ALLOC_ORDER);
 		if (page)
 			prealloc = page_address(page);
+
+		/* restore flags to report failure in depot_alloc_stack() */
+		alloc_flags = orig_flags;
 	}
 
 	spin_lock_irqsave(&depot_lock, flags);
@@ -264,6 +273,8 @@ depot_stack_handle_t depot_save_stack(struct stack_trace *trace,
 			 */
 			smp_store_release(bucket, new);
 			found = new;
+			if (is_new)
+				*is_new = true;
 		}
 	} else if (prealloc) {
 		/*
diff --git a/mm/kasan/kasan.c b/mm/kasan/kasan.c
index 8fc4ad8..1b37e12 100644
--- a/mm/kasan/kasan.c
+++ b/mm/kasan/kasan.c
@@ -454,7 +454,7 @@ static inline depot_stack_handle_t save_stack(gfp_t flags)
 	    trace.entries[trace.nr_entries-1] == ULONG_MAX)
 		trace.nr_entries--;
 
-	return depot_save_stack(&trace, flags);
+	return depot_save_stack(&trace, flags, NULL);
 }
 
 static inline void set_track(struct kasan_track *track, gfp_t flags)
diff --git a/mm/kasan/vchecker.c b/mm/kasan/vchecker.c
index 2e9f461..82d4f1d 100644
--- a/mm/kasan/vchecker.c
+++ b/mm/kasan/vchecker.c
@@ -299,7 +299,7 @@ static noinline depot_stack_handle_t save_stack(void)
 	    trace.entries[trace.nr_entries-1] == ULONG_MAX)
 		trace.nr_entries--;
 
-	return depot_save_stack(&trace, GFP_NOWAIT);
+	return depot_save_stack(&trace, GFP_NOWAIT, NULL);
 }
 
 static ssize_t vchecker_type_write(struct file *filp, const char __user *ubuf,
diff --git a/mm/page_owner.c b/mm/page_owner.c
index f948acc..0e22eee 100644
--- a/mm/page_owner.c
+++ b/mm/page_owner.c
@@ -66,7 +66,7 @@ static __always_inline depot_stack_handle_t create_dummy_stack(void)
 	dummy.skip = 0;
 
 	save_stack_trace(&dummy);
-	return depot_save_stack(&dummy, GFP_KERNEL);
+	return depot_save_stack(&dummy, GFP_KERNEL, NULL);
 }
 
 static noinline void register_dummy_stack(void)
@@ -162,7 +162,7 @@ static noinline depot_stack_handle_t save_stack(gfp_t flags)
 	if (check_recursive_alloc(&trace, _RET_IP_))
 		return dummy_handle;
 
-	handle = depot_save_stack(&trace, flags);
+	handle = depot_save_stack(&trace, flags, NULL);
 	if (!handle)
 		handle = failure_handle;
 
-- 
2.7.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: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2017-11-28  7:49 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-28  7:48 [PATCH 00/18] introduce a new tool, valid access checker js1304
2017-11-28  7:48 ` [PATCH 01/18] mm/kasan: make some kasan functions global js1304
2017-11-28  7:48 ` [PATCH 02/18] vchecker: introduce the valid access checker js1304
2017-11-28 19:41   ` Andi Kleen
2017-11-29  5:36     ` Joonsoo Kim
2017-12-01  5:08   ` kbuild test robot
2017-12-01  8:01     ` Joonsoo Kim
2017-11-28  7:48 ` [PATCH 03/18] vchecker: mark/unmark the shadow of the allocated objects js1304
2017-11-28  7:48 ` [PATCH 04/18] vchecker: prepare per object memory for vchecker js1304
2017-11-28  7:48 ` [PATCH 05/18] vchecker: store/report callstack of value writer js1304
2017-11-28  7:48 ` js1304 [this message]
2017-11-28  7:48 ` [PATCH 07/18] lib/stackdepot: extend stackdepot API to support per-user stackdepot js1304
2017-11-28  7:48 ` [PATCH 08/18] vchecker: Add 'callstack' checker js1304
2017-11-28  7:48 ` [PATCH 09/18] vchecker: Support toggle on/off of callstack check js1304
2017-11-28  7:48 ` [PATCH 10/18] vchecker: Use __GFP_ATOMIC to save stacktrace js1304
2017-11-28  7:48 ` [PATCH 11/18] vchecker: consistently exclude vchecker's stacktrace js1304
2017-11-28  7:48 ` [PATCH 12/18] vchecker: fix 'remove' handling on callstack checker js1304
2017-11-28  7:48 ` [PATCH 13/18] mm/vchecker: support inline KASAN build js1304
2017-11-28  7:48 ` [PATCH 14/18] mm/vchecker: make callstack depth configurable js1304
2017-11-28  7:48 ` [PATCH 15/18] mm/vchecker: pass allocation caller address to vchecker hook js1304
2017-12-01  2:39   ` kbuild test robot
2017-12-01  3:01   ` kbuild test robot
2017-11-28  7:48 ` [PATCH 16/18] mm/vchecker: support allocation caller filter js1304
2017-11-28  7:48 ` [PATCH 17/18] lib/vchecker_test: introduce a sample for vchecker test js1304
2017-11-28  7:48 ` [PATCH 18/18] doc: add vchecker document js1304
2017-11-29  9:27 ` [PATCH 00/18] introduce a new tool, valid access checker Dmitry Vyukov
2017-12-01  7:46   ` Joonsoo Kim
2017-12-22  1:51 ` Joonsoo Kim
2018-01-18 22:39   ` Andrew Morton

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=1511855333-3570-7-git-send-email-iamjoonsoo.kim@lge.com \
    --to=js1304@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=aryabinin@virtuozzo.com \
    --cc=dvyukov@google.com \
    --cc=glider@google.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=namhyung@kernel.org \
    --cc=wen.gang.wang@oracle.com \
    /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;
as well as URLs for NNTP newsgroup(s).