[PATCH 3/7] perf, x86: Add copy_from_user_nmi_nochk for best effort copy

From: Jiri Olsa
Date: Fri Jul 27 2012 - 08:24:33 EST


Adding copy_from_user_nmi_nochk that provides the best effort
copy regardless the requesting size crossing the task boundary.

This is going to be useful for stack dump we need in post
DWARF CFI based unwind, where we have predefined size of
the user stack to dump, and we need to store the most of
the requested dump size, regardless this size is crossing
the task boundary.

Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
arch/x86/include/asm/uaccess.h | 2 ++
arch/x86/lib/usercopy.c | 15 +++++++++++----
2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
index e1f3a17..d8d6bcd 100644
--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -562,6 +562,8 @@ struct __large_struct { unsigned long buf[100]; };
#endif /* CONFIG_X86_WP_WORKS_OK */

extern unsigned long
+copy_from_user_nmi_nochk(void *to, const void __user *from, unsigned long n);
+extern unsigned long
copy_from_user_nmi(void *to, const void __user *from, unsigned long n);
extern __must_check long
strncpy_from_user(char *dst, const char __user *src, long count);
diff --git a/arch/x86/lib/usercopy.c b/arch/x86/lib/usercopy.c
index 4f74d94..29ca1c7 100644
--- a/arch/x86/lib/usercopy.c
+++ b/arch/x86/lib/usercopy.c
@@ -14,7 +14,7 @@
* best effort, GUP based copy_from_user() that is NMI-safe
*/
unsigned long
-copy_from_user_nmi(void *to, const void __user *from, unsigned long n)
+copy_from_user_nmi_nochk(void *to, const void __user *from, unsigned long n)
{
unsigned long offset, addr = (unsigned long)from;
unsigned long size, len = 0;
@@ -22,9 +22,6 @@ copy_from_user_nmi(void *to, const void __user *from, unsigned long n)
void *map;
int ret;

- if (__range_not_ok(from, n, TASK_SIZE))
- return len;
-
do {
ret = __get_user_pages_fast(addr, 1, 0, &page);
if (!ret)
@@ -46,4 +43,14 @@ copy_from_user_nmi(void *to, const void __user *from, unsigned long n)

return len;
}
+EXPORT_SYMBOL_GPL(copy_from_user_nmi_nochk);
+
+unsigned long
+copy_from_user_nmi(void *to, const void __user *from, unsigned long n)
+{
+ if (__range_not_ok(from, n, TASK_SIZE) == 0)
+ return 0;
+
+ return copy_from_user_nmi_nochk(to, from, n);
+}
EXPORT_SYMBOL_GPL(copy_from_user_nmi);
--
1.7.7.6

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/