perf: Fix arch_perf_out_copy_user default
authorPeter Zijlstra <peterz@infradead.org>
Wed, 30 Oct 2013 20:16:22 +0000 (21:16 +0100)
committerIngo Molnar <mingo@kernel.org>
Wed, 6 Nov 2013 11:34:25 +0000 (12:34 +0100)
The arch_perf_output_copy_user() default of
__copy_from_user_inatomic() returns bytes not copied, while all other
argument functions given DEFINE_OUTPUT_COPY() return bytes copied.

Since copy_from_user_nmi() is the odd duck out by returning bytes
copied where all other *copy_{to,from}* functions return bytes not
copied, change it over and ammend DEFINE_OUTPUT_COPY() to expect bytes
not copied.

Oddly enough DEFINE_OUTPUT_COPY() already returned bytes not copied
while expecting its worker functions to return bytes copied.

Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Acked-by: will.deacon@arm.com
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Link: http://lkml.kernel.org/r/20131030201622.GR16117@laptop.programming.kicks-ass.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
arch/x86/kernel/cpu/perf_event.c
arch/x86/kernel/cpu/perf_event_intel_ds.c
arch/x86/kernel/cpu/perf_event_intel_lbr.c
arch/x86/lib/usercopy.c
arch/x86/oprofile/backtrace.c
kernel/events/internal.h

index 8a87a3224121fdeac2d2fd59fb2142f6de8d8a24..8e132931614d618b03b9f7d69a492b793a27bc30 100644 (file)
@@ -1989,7 +1989,7 @@ perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry *entry)
                frame.return_address = 0;
 
                bytes = copy_from_user_nmi(&frame, fp, sizeof(frame));
-               if (bytes != sizeof(frame))
+               if (bytes != 0)
                        break;
 
                if (!valid_user_frame(fp, sizeof(frame)))
@@ -2041,7 +2041,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
                frame.return_address = 0;
 
                bytes = copy_from_user_nmi(&frame, fp, sizeof(frame));
-               if (bytes != sizeof(frame))
+               if (bytes != 0)
                        break;
 
                if (!valid_user_frame(fp, sizeof(frame)))
index c1760ff3c757e35ae804bf6a9625ae701a358e83..ae96cfa5eddd74a30780e4062fae9af8f34ecd82 100644 (file)
@@ -789,7 +789,7 @@ static int intel_pmu_pebs_fixup_ip(struct pt_regs *regs)
 
                size = ip - to; /* Must fit our buffer, see above */
                bytes = copy_from_user_nmi(buf, (void __user *)to, size);
-               if (bytes != size)
+               if (bytes != 0)
                        return 0;
 
                kaddr = buf;
index 90ee6c1d0542664dbb9955ff2570e9f338e076e6..d82d155aca8c7c6c44c9ba7150dae39e88e16fad 100644 (file)
@@ -491,7 +491,7 @@ static int branch_type(unsigned long from, unsigned long to, int abort)
 
                /* may fail if text not present */
                bytes = copy_from_user_nmi(buf, (void __user *)from, size);
-               if (bytes != size)
+               if (bytes != 0)
                        return X86_BR_NONE;
 
                addr = buf;
index 5465b8613944ea514748571fd28e5b4e43d07085..ddf9ecb53cc3e23171ea889dc47339e67ba5d2c8 100644 (file)
@@ -31,6 +31,6 @@ copy_from_user_nmi(void *to, const void __user *from, unsigned long n)
        ret = __copy_from_user_inatomic(to, from, n);
        pagefault_enable();
 
-       return n - ret;
+       return ret;
 }
 EXPORT_SYMBOL_GPL(copy_from_user_nmi);
index d6aa6e8315d13ac718615947077f2b6fd113cb35..5d04be5efb6401b1b7512f4ca519a24a016b20d2 100644 (file)
@@ -47,7 +47,7 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
        unsigned long bytes;
 
        bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
-       if (bytes != sizeof(bufhead))
+       if (bytes != 0)
                return NULL;
 
        fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
@@ -93,7 +93,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
        unsigned long bytes;
 
        bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
-       if (bytes != sizeof(bufhead))
+       if (bytes != 0)
                return NULL;
 
        oprofile_add_trace(bufhead[0].return_address);
index ca6599723be5624cdeb4a3cad5ef5dd10a4e1c7b..569b218782ad6f52053a21495c893935dcde5b10 100644 (file)
@@ -82,16 +82,16 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
 }
 
 #define DEFINE_OUTPUT_COPY(func_name, memcpy_func)                     \
-static inline unsigned int                                             \
+static inline unsigned long                                            \
 func_name(struct perf_output_handle *handle,                           \
-         const void *buf, unsigned int len)                            \
+         const void *buf, unsigned long len)                           \
 {                                                                      \
        unsigned long size, written;                                    \
                                                                        \
        do {                                                            \
-               size = min_t(unsigned long, handle->size, len);         \
-                                                                       \
+               size    = min(handle->size, len);                       \
                written = memcpy_func(handle->addr, buf, size);         \
+               written = size - written;                               \
                                                                        \
                len -= written;                                         \
                handle->addr += written;                                \
@@ -110,20 +110,37 @@ func_name(struct perf_output_handle *handle,                              \
        return len;                                                     \
 }
 
-static inline int memcpy_common(void *dst, const void *src, size_t n)
+static inline unsigned long
+memcpy_common(void *dst, const void *src, unsigned long n)
 {
        memcpy(dst, src, n);
-       return n;
+       return 0;
 }
 
 DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
 
-#define MEMCPY_SKIP(dst, src, n) (n)
+static inline unsigned long
+memcpy_skip(void *dst, const void *src, unsigned long n)
+{
+       return 0;
+}
 
-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
+DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
 
 #ifndef arch_perf_out_copy_user
-#define arch_perf_out_copy_user __copy_from_user_inatomic
+#define arch_perf_out_copy_user arch_perf_out_copy_user
+
+static inline unsigned long
+arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
+{
+       unsigned long ret;
+
+       pagefault_disable();
+       ret = __copy_from_user_inatomic(dst, src, n);
+       pagefault_enable();
+
+       return ret;
+}
 #endif
 
 DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)