Skip to content

Commit 0a19684

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
perf: Fix arch_perf_out_copy_user default
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>
1 parent 394570b commit 0a19684

File tree

6 files changed

+33
-16
lines changed

6 files changed

+33
-16
lines changed

arch/x86/kernel/cpu/perf_event.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,7 +1989,7 @@ perf_callchain_user32(struct pt_regs *regs, struct perf_callchain_entry *entry)
19891989
frame.return_address = 0;
19901990

19911991
bytes = copy_from_user_nmi(&frame, fp, sizeof(frame));
1992-
if (bytes != sizeof(frame))
1992+
if (bytes != 0)
19931993
break;
19941994

19951995
if (!valid_user_frame(fp, sizeof(frame)))
@@ -2041,7 +2041,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
20412041
frame.return_address = 0;
20422042

20432043
bytes = copy_from_user_nmi(&frame, fp, sizeof(frame));
2044-
if (bytes != sizeof(frame))
2044+
if (bytes != 0)
20452045
break;
20462046

20472047
if (!valid_user_frame(fp, sizeof(frame)))

arch/x86/kernel/cpu/perf_event_intel_ds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ static int intel_pmu_pebs_fixup_ip(struct pt_regs *regs)
789789

790790
size = ip - to; /* Must fit our buffer, see above */
791791
bytes = copy_from_user_nmi(buf, (void __user *)to, size);
792-
if (bytes != size)
792+
if (bytes != 0)
793793
return 0;
794794

795795
kaddr = buf;

arch/x86/kernel/cpu/perf_event_intel_lbr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ static int branch_type(unsigned long from, unsigned long to, int abort)
491491

492492
/* may fail if text not present */
493493
bytes = copy_from_user_nmi(buf, (void __user *)from, size);
494-
if (bytes != size)
494+
if (bytes != 0)
495495
return X86_BR_NONE;
496496

497497
addr = buf;

arch/x86/lib/usercopy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ copy_from_user_nmi(void *to, const void __user *from, unsigned long n)
3131
ret = __copy_from_user_inatomic(to, from, n);
3232
pagefault_enable();
3333

34-
return n - ret;
34+
return ret;
3535
}
3636
EXPORT_SYMBOL_GPL(copy_from_user_nmi);

arch/x86/oprofile/backtrace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
4747
unsigned long bytes;
4848

4949
bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
50-
if (bytes != sizeof(bufhead))
50+
if (bytes != 0)
5151
return NULL;
5252

5353
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)
9393
unsigned long bytes;
9494

9595
bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
96-
if (bytes != sizeof(bufhead))
96+
if (bytes != 0)
9797
return NULL;
9898

9999
oprofile_add_trace(bufhead[0].return_address);

kernel/events/internal.h

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,16 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
8282
}
8383

8484
#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
85-
static inline unsigned int \
85+
static inline unsigned long \
8686
func_name(struct perf_output_handle *handle, \
87-
const void *buf, unsigned int len) \
87+
const void *buf, unsigned long len) \
8888
{ \
8989
unsigned long size, written; \
9090
\
9191
do { \
92-
size = min_t(unsigned long, handle->size, len); \
93-
\
92+
size = min(handle->size, len); \
9493
written = memcpy_func(handle->addr, buf, size); \
94+
written = size - written; \
9595
\
9696
len -= written; \
9797
handle->addr += written; \
@@ -110,20 +110,37 @@ func_name(struct perf_output_handle *handle, \
110110
return len; \
111111
}
112112

113-
static inline int memcpy_common(void *dst, const void *src, size_t n)
113+
static inline unsigned long
114+
memcpy_common(void *dst, const void *src, unsigned long n)
114115
{
115116
memcpy(dst, src, n);
116-
return n;
117+
return 0;
117118
}
118119

119120
DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
120121

121-
#define MEMCPY_SKIP(dst, src, n) (n)
122+
static inline unsigned long
123+
memcpy_skip(void *dst, const void *src, unsigned long n)
124+
{
125+
return 0;
126+
}
122127

123-
DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
128+
DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
124129

125130
#ifndef arch_perf_out_copy_user
126-
#define arch_perf_out_copy_user __copy_from_user_inatomic
131+
#define arch_perf_out_copy_user arch_perf_out_copy_user
132+
133+
static inline unsigned long
134+
arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
135+
{
136+
unsigned long ret;
137+
138+
pagefault_disable();
139+
ret = __copy_from_user_inatomic(dst, src, n);
140+
pagefault_enable();
141+
142+
return ret;
143+
}
127144
#endif
128145

129146
DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)

0 commit comments

Comments
 (0)