All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ezequiel Garcia <elezegarcia@gmail.com>
To: <linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>
Cc: Ezequiel Garcia <elezegarcia@gmail.com>,
	Pekka Enberg <penberg@kernel.org>
Subject: [PATCH 05/10] mm, util: Use dup_user to duplicate user memory
Date: Sat,  8 Sep 2012 17:47:54 -0300	[thread overview]
Message-ID: <1347137279-17568-5-git-send-email-elezegarcia@gmail.com> (raw)
In-Reply-To: <1347137279-17568-1-git-send-email-elezegarcia@gmail.com>

Previously the strndup_user allocation was being done through memdup_user,
and the caller was wrongly traced as being strndup_user
(the correct trace must report the caller of strndup_user).

This is a common problem: in order to get accurate callsite tracing,
a utils function can't allocate through another utils function,
but instead do the allocation himself (or inlined).

Here we fix this by creating an always inlined dup_user() function to
performed the real allocation and to be used by memdup_user and strndup_user.

Cc: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Ezequiel Garcia <elezegarcia@gmail.com>
---
 mm/util.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/mm/util.c b/mm/util.c
index dc3036c..48d3ff8b 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -76,14 +76,14 @@ void *kmemdup(const void *src, size_t len, gfp_t gfp)
 EXPORT_SYMBOL(kmemdup);
 
 /**
- * memdup_user - duplicate memory region from user space
+ * dup_user - duplicate memory region from user space
  *
  * @src: source address in user space
  * @len: number of bytes to copy
  *
  * Returns an ERR_PTR() on failure.
  */
-void *memdup_user(const void __user *src, size_t len)
+static __always_inline void *dup_user(const void __user *src, size_t len)
 {
 	void *p;
 
@@ -103,6 +103,11 @@ void *memdup_user(const void __user *src, size_t len)
 
 	return p;
 }
+
+void *memdup_user(const void __user *src, size_t len)
+{
+	return dup_user(src, len);
+}
 EXPORT_SYMBOL(memdup_user);
 
 static __always_inline void *__do_krealloc(const void *p, size_t new_size,
@@ -214,7 +219,7 @@ char *strndup_user(const char __user *s, long n)
 	if (length > n)
 		return ERR_PTR(-EINVAL);
 
-	p = memdup_user(s, length);
+	p = dup_user(s, length);
 
 	if (IS_ERR(p))
 		return p;
-- 
1.7.8.6


WARNING: multiple messages have this Message-ID (diff)
From: Ezequiel Garcia <elezegarcia@gmail.com>
To: linux-kernel@vger.kernel.org, linux-mm@kvack.org
Cc: Ezequiel Garcia <elezegarcia@gmail.com>,
	Pekka Enberg <penberg@kernel.org>
Subject: [PATCH 05/10] mm, util: Use dup_user to duplicate user memory
Date: Sat,  8 Sep 2012 17:47:54 -0300	[thread overview]
Message-ID: <1347137279-17568-5-git-send-email-elezegarcia@gmail.com> (raw)
In-Reply-To: <1347137279-17568-1-git-send-email-elezegarcia@gmail.com>

Previously the strndup_user allocation was being done through memdup_user,
and the caller was wrongly traced as being strndup_user
(the correct trace must report the caller of strndup_user).

This is a common problem: in order to get accurate callsite tracing,
a utils function can't allocate through another utils function,
but instead do the allocation himself (or inlined).

Here we fix this by creating an always inlined dup_user() function to
performed the real allocation and to be used by memdup_user and strndup_user.

Cc: Pekka Enberg <penberg@kernel.org>
Signed-off-by: Ezequiel Garcia <elezegarcia@gmail.com>
---
 mm/util.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/mm/util.c b/mm/util.c
index dc3036c..48d3ff8b 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -76,14 +76,14 @@ void *kmemdup(const void *src, size_t len, gfp_t gfp)
 EXPORT_SYMBOL(kmemdup);
 
 /**
- * memdup_user - duplicate memory region from user space
+ * dup_user - duplicate memory region from user space
  *
  * @src: source address in user space
  * @len: number of bytes to copy
  *
  * Returns an ERR_PTR() on failure.
  */
-void *memdup_user(const void __user *src, size_t len)
+static __always_inline void *dup_user(const void __user *src, size_t len)
 {
 	void *p;
 
@@ -103,6 +103,11 @@ void *memdup_user(const void __user *src, size_t len)
 
 	return p;
 }
+
+void *memdup_user(const void __user *src, size_t len)
+{
+	return dup_user(src, len);
+}
 EXPORT_SYMBOL(memdup_user);
 
 static __always_inline void *__do_krealloc(const void *p, size_t new_size,
@@ -214,7 +219,7 @@ char *strndup_user(const char __user *s, long n)
 	if (length > n)
 		return ERR_PTR(-EINVAL);
 
-	p = memdup_user(s, length);
+	p = dup_user(s, length);
 
 	if (IS_ERR(p))
 		return p;
-- 
1.7.8.6

--
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:[~2012-09-08 20:50 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-08 20:47 [PATCH 01/10] Makefile: Add option CONFIG_DISABLE_GCC_AUTOMATIC_INLINING Ezequiel Garcia
2012-09-08 20:47 ` Ezequiel Garcia
2012-09-08 20:47 ` [PATCH 02/10] mm, slob: Use NUMA_NO_NODE instead of -1 Ezequiel Garcia
2012-09-08 20:47   ` Ezequiel Garcia
2012-09-09 21:27   ` David Rientjes
2012-09-09 21:27     ` David Rientjes
2012-09-24 17:13     ` Ezequiel Garcia
2012-09-24 17:13       ` Ezequiel Garcia
2012-09-25  7:37       ` Pekka Enberg
2012-09-25  7:37         ` Pekka Enberg
2012-09-25 10:13         ` Ezequiel Garcia
2012-09-25 10:13           ` Ezequiel Garcia
2012-09-08 20:47 ` [PATCH 03/10] mm, slab: Remove silly function slab_buffer_size() Ezequiel Garcia
2012-09-08 20:47   ` Ezequiel Garcia
2012-09-09 21:28   ` David Rientjes
2012-09-09 21:28     ` David Rientjes
2012-09-08 20:47 ` [PATCH 04/10] mm, slob: Add support for kmalloc_track_caller() Ezequiel Garcia
2012-09-08 20:47   ` Ezequiel Garcia
2012-09-25 19:53   ` [patch slab/next] mm, slob: fix build breakage in __kmalloc_node_track_caller David Rientjes
2012-09-25 19:53     ` David Rientjes
2012-09-25 19:55     ` Ezequiel Garcia
2012-09-25 19:55       ` Ezequiel Garcia
2012-09-08 20:47 ` Ezequiel Garcia [this message]
2012-09-08 20:47   ` [PATCH 05/10] mm, util: Use dup_user to duplicate user memory Ezequiel Garcia
2012-09-25  7:15   ` Pekka Enberg
2012-09-25  7:15     ` Pekka Enberg
2012-09-25 21:29   ` Andrew Morton
2012-09-25 21:29     ` Andrew Morton
2012-09-26  1:15     ` Ezequiel Garcia
2012-09-26  1:15       ` Ezequiel Garcia
2012-09-26 21:42       ` Andrew Morton
2012-09-26 21:42         ` Andrew Morton
2012-09-26 21:51         ` Ezequiel Garcia
2012-09-26 21:51           ` Ezequiel Garcia
2012-09-08 20:47 ` [PATCH 06/10] mm, slab: Replace 'caller' type, void* -> unsigned long Ezequiel Garcia
2012-09-08 20:47   ` Ezequiel Garcia
2012-09-08 20:47 ` [PATCH 07/10] mm, slab: Match SLAB and SLUB kmem_cache_alloc_xxx_trace() prototype Ezequiel Garcia
2012-09-08 20:47   ` Ezequiel Garcia
2012-09-08 20:47 ` [PATCH 08/10] mm, slab: Rename __cache_alloc() -> slab_alloc() Ezequiel Garcia
2012-09-08 20:47   ` Ezequiel Garcia
2012-09-08 20:47 ` [PATCH 09/10] mm, slub: Rename slab_alloc() -> slab_alloc_node() to match SLAB Ezequiel Garcia
2012-09-08 20:47   ` Ezequiel Garcia
2012-09-08 20:47 ` [PATCH 10/10] mm: Factor SLAB and SLUB common code Ezequiel Garcia
2012-09-08 20:47   ` Ezequiel Garcia
2012-09-08 21:43 ` [PATCH 01/10] Makefile: Add option CONFIG_DISABLE_GCC_AUTOMATIC_INLINING Sam Ravnborg
2012-09-08 21:43   ` Sam Ravnborg
2012-09-09 21:25 ` David Rientjes
2012-09-09 21:25   ` David Rientjes
2012-09-13  0:30   ` Ezequiel Garcia
2012-09-13  0:30     ` Ezequiel Garcia
2012-09-13  7:17     ` Michal Marek
2012-09-13  7:17       ` Michal Marek
2012-09-13  9:16       ` Ezequiel Garcia
2012-09-13  9:16         ` Ezequiel Garcia

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=1347137279-17568-5-git-send-email-elezegarcia@gmail.com \
    --to=elezegarcia@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=penberg@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.