767 Commits

Author SHA1 Message Date
Daniel Borkmann
2979003e7e bpf, events: fix offset in skb copy handler
This patch fixes the __output_custom() routine we currently use with
bpf_skb_copy(). I missed that when len is larger than the size of the
current handle, we can issue multiple invocations of copy_func, and
__output_custom() advances destination but also source buffer by the
written amount of bytes. When we have __output_custom(), this is actually
wrong since in that case the source buffer points to a non-linear object,
in our case an skb, which the copy_func helper is supposed to walk.
Therefore, since this is non-linear we thus need to pass the offset into
the helper, so that copy_func can use it for extracting the data from
the source object.

Therefore, adjust the callback signatures properly and pass offset
into the skb_header_pointer() invoked from bpf_skb_copy() callback. The
__DEFINE_OUTPUT_COPY_BODY() is adjusted to accommodate for two things:
i) to pass in whether we should advance source buffer or not; this is
a compile-time constant condition, ii) to pass in the offset for
__output_custom(), which we do with help of __VA_ARGS__, so everything
can stay inlined as is currently. Both changes allow for adapting the
__output_* fast-path helpers w/o extra overhead.

Fixes: 555c8a8623a3 ("bpf: avoid stack copy and use skb ctx for event output")
Fixes: 7e3f977edd0b ("perf, events: add non-linear data support for raw records")
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-03-04 20:17:00 +01:00
Daniel Borkmann
c174f26b9f perf, events: add non-linear data support for raw records
This patch adds support for non-linear data on raw records. It
extends raw records to have one or multiple fragments that will
be written linearly into the ring slot, where each fragment can
optionally have a custom callback handler to walk and extract
complex, possibly non-linear data.

If a callback handler is provided for a fragment, then the new
__output_custom() will be used instead of __output_copy() for
the perf_output_sample() part. perf_prepare_sample() does all
the size calculation only once, so perf_output_sample() doesn't
need to redo the same work anymore, meaning real_size and padding
will be cached in the raw record. The raw record becomes 32 bytes
in size without holes; to not increase it further and to avoid
doing unnecessary recalculations in fast-path, we can reuse
next pointer of the last fragment, idea here is borrowed from
ZERO_OR_NULL_PTR(), which should keep the perf_output_sample()
path for PERF_SAMPLE_RAW minimal.

This facility is needed for BPF's event output helper as a first
user that will, in a follow-up, add an additional perf_raw_frag
to its perf_raw_record in order to be able to more efficiently
dump skb context after a linear head meta data related to it.
skbs can be non-linear and thus need a custom output function to
dump buffers. Currently, the skb data needs to be copied twice;
with the help of __output_custom() this work only needs to be
done once. Future users could be things like XDP/BPF programs
that work on different context though and would thus also have
a different callback function.

The few users of raw records are adapted to initialize their frag
data from the raw record itself, no change in behavior for them.
The code is based upon a PoC diff provided by Peter Zijlstra [1].

  [1] http://thread.gmane.org/gmane.linux.network/421294

Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-03-04 20:17:00 +01:00
Arnd Bergmann
422789f905 perf, bpf: fix conditional call to bpf_overflow_handler
The newly added bpf_overflow_handler function is only built of both
CONFIG_EVENT_TRACING and CONFIG_BPF_SYSCALL are enabled, but the caller
only checks the latter:

kernel/events/core.c: In function 'perf_event_alloc':
kernel/events/core.c:9106:27: error: 'bpf_overflow_handler' undeclared (first use in this function)

This changes the caller so we also skip this call if CONFIG_EVENT_TRACING
is disabled entirely.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Fixes: aa6a5f3cb2b2 ("perf, bpf: add perf events core support for BPF_PROG_TYPE_PERF_EVENT programs")
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2022-03-04 20:16:59 +01:00
Yonghong Song
3f2070497f BACKPORT: bpf: permit multiple bpf attachments for a single perf event
This patch enables multiple bpf attachments for a
kprobe/uprobe/tracepoint single trace event.
Each trace_event keeps a list of attached perf events.
When an event happens, all attached bpf programs will
be executed based on the order of attachment.

A global bpf_event_mutex lock is introduced to protect
prog_array attaching and detaching. An alternative will
be introduce a mutex lock in every trace_event_call
structure, but it takes a lot of extra memory.
So a global bpf_event_mutex lock is a good compromise.

The bpf prog detachment involves allocation of memory.
If the allocation fails, a dummy do-nothing program
will replace to-be-detached program in-place.

Signed-off-by: Yonghong Song <yhs@fb.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry picked from commit e87c6bc3852b981e71c757be20771546ce9f76f3)
Signed-off-by: Connor O'Brien <connoro@google.com>
Bug: 121213201
Bug: 138317270
Test: build & boot cuttlefish; attach 2 progs to 1 tracepoint
Change-Id: I390d8c0146888ddb1aed5a6f6e5dae7ef394ebc9
Signed-off-by: Chatur27 <jasonbright2709@gmail.com>
2022-03-04 20:16:56 +01:00
Alexei Starovoitov
b91876bedc perf, bpf: minimize the size of perf_trace_() tracepoint handler
move trace_call_bpf() into helper function to minimize the size
of perf_trace_*() tracepoint handlers.
    text	   data	    bss	    dec	 	   hex	filename
10541679	5526646	2945024	19013349	1221ee5	vmlinux_before
10509422	5526646	2945024	18981092	121a0e4	vmlinux_after

It may seem that perf_fetch_caller_regs() can also be moved,
but that is incorrect, since ip/sp will be wrong.

bpf+tracepoint performance is not affected, since
perf_swevent_put_recursion_context() is now inlined.
export_symbol_gpl can also be dropped.

No measurable change in normal perf tracepoints.

Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Chatur27 <jasonbright2709@gmail.com>
2022-03-04 20:16:56 +01:00
Yonghong Song
c749d9e879 UPSTREAM: bpf: use the same condition in perf event set/free bpf handler
This is a cleanup such that doing the same check in
perf_event_free_bpf_prog as we already do in
perf_event_set_bpf_prog step.

Signed-off-by: Yonghong Song <yhs@fb.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(cherry picked from commit 0b4c6841fee03e096b735074a0c4aab3a8e92986)
Signed-off-by: Connor O'Brien <connoro@google.com>
Bug: 121213201
Bug: 138317270
Test: build & boot cuttlefish
Change-Id: Ie423e73a73be29e8ef50cc22dbb03e14e241c8de
Signed-off-by: Chatur27 <jasonbright2709@gmail.com>
2022-03-04 20:16:56 +01:00
Alexei Starovoitov
a158911930 perf, bpf: add perf events core support for BPF_PROG_TYPE_PERF_EVENT programs
Allow attaching BPF_PROG_TYPE_PERF_EVENT programs to sw and hw perf events
via overflow_handler mechanism.
When program is attached the overflow_handlers become stacked.
The program acts as a filter.
Returning zero from the program means that the normal perf_event_output handler
will not be called and sampling event won't be stored in the ring buffer.

The overflow_handler_context==NULL is an additional safety check
to make sure programs are not attached to hw breakpoints and watchdog
in case other checks (that prevent that now anyway) get accidentally
relaxed in the future.

The program refcnt is incremented in case perf_events are inhereted
when target task is forked.
Similar to kprobe and tracepoint programs there is no ioctl to
detach the program or swap already attached program. The user space
expected to close(perf_event_fd) like it does right now for kprobe+bpf.
That restriction simplifies the code quite a bit.

The invocation of overflow_handler in __perf_event_overflow() is now
done via READ_ONCE, since that pointer can be replaced when the program
is attached while perf_event itself could have been active already.
There is no need to do similar treatment for event->prog, since it's
assigned only once before it's accessed.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Chatur27 <jasonbright2709@gmail.com>
2022-03-04 20:16:53 +01:00
Wang Nan
994c164f35 perf/core: Set event's default ::overflow_handler()
Set a default event->overflow_handler in perf_event_alloc() so don't
need to check event->overflow_handler in __perf_event_overflow().
Following commits can give a different default overflow_handler.

Initial idea comes from Peter:

  http://lkml.kernel.org/r/20130708121557.GA17211@twins.programming.kicks-ass.net

Since the default value of event->overflow_handler is not NULL, existing
'if (!overflow_handler)' checks need to be changed.

is_default_overflow_handler() is introduced for this.

No extra performance overhead is introduced into the hot path because in the
original code we still need to read this handler from memory. A conditional
branch is avoided so actually we remove some instructions.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: <pi3orama@163.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: Zefan Li <lizefan@huawei.com>
Link: http://lkml.kernel.org/r/1459147292-239310-3-git-send-email-wangnan0@huawei.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Chatur27 <jasonbright2709@gmail.com>
2022-03-04 20:16:53 +01:00
Daniel Borkmann
34e63182fd bpf: generally move prog destruction to RCU deferral
Jann Horn reported following analysis that could potentially result
in a very hard to trigger (if not impossible) UAF race, to quote his
event timeline:

 - Set up a process with threads T1, T2 and T3
 - Let T1 set up a socket filter F1 that invokes another filter F2
   through a BPF map [tail call]
 - Let T1 trigger the socket filter via a unix domain socket write,
   don't wait for completion
 - Let T2 call PERF_EVENT_IOC_SET_BPF with F2, don't wait for completion
 - Now T2 should be behind bpf_prog_get(), but before bpf_prog_put()
 - Let T3 close the file descriptor for F2, dropping the reference
   count of F2 to 2
 - At this point, T1 should have looked up F2 from the map, but not
   finished executing it
 - Let T3 remove F2 from the BPF map, dropping the reference count of
   F2 to 1
 - Now T2 should call bpf_prog_put() (wrong BPF program type), dropping
   the reference count of F2 to 0 and scheduling bpf_prog_free_deferred()
   via schedule_work()
 - At this point, the BPF program could be freed
 - BPF execution is still running in a freed BPF program

While at PERF_EVENT_IOC_SET_BPF time it's only guaranteed that the perf
event fd we're doing the syscall on doesn't disappear from underneath us
for whole syscall time, it may not be the case for the bpf fd used as
an argument only after we did the put. It needs to be a valid fd pointing
to a BPF program at the time of the call to make the bpf_prog_get() and
while T2 gets preempted, F2 must have dropped reference to 1 on the other
CPU. The fput() from the close() in T3 should also add additionally delay
to the reference drop via exit_task_work() when bpf_prog_release() gets
called as well as scheduling bpf_prog_free_deferred().

That said, it makes nevertheless sense to move the BPF prog destruction
generally after RCU grace period to guarantee that such scenario above,
but also others as recently fixed in ceb56070359b ("bpf, perf: delay release
of BPF prog after grace period") with regards to tail calls won't happen.
Integrating bpf_prog_free_deferred() directly into the RCU callback is
not allowed since the invocation might happen from either softirq or
process context, so we're not permitted to block. Reviewing all bpf_prog_put()
invocations from eBPF side (note, cBPF -> eBPF progs don't use this for
their destruction) with call_rcu() look good to me.

Since we don't know whether at the time of attaching the program, we're
already part of a tail call map, we need to use RCU variant. However, due
to this, there won't be severely more stress on the RCU callback queue:
situations with above bpf_prog_get() and bpf_prog_put() combo in practice
normally won't lead to releases, but even if they would, enough effort/
cycles have to be put into loading a BPF program into the kernel already.

Reported-by: Jann Horn <jannh@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Chatur27 <jasonbright2709@gmail.com>
2022-03-04 20:16:36 +01:00
Arnaldo Carvalho de Melo
940cc3d4cd perf core: Per event callchain limit
Additionally to being able to control the system wide maximum depth via
/proc/sys/kernel/perf_event_max_stack, now we are able to ask for
different depths per event, using perf_event_attr.sample_max_stack for
that.

This uses an u16 hole at the end of perf_event_attr, that, when
perf_event_attr.sample_type has the PERF_SAMPLE_CALLCHAIN, if
sample_max_stack is zero, means use perf_event_max_stack, otherwise
it'll be bounds checked under callchain_mutex.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Milian Wolff <milian.wolff@kdab.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: Wang Nan <wangnan0@huawei.com>
Cc: Zefan Li <lizefan@huawei.com>
Link: http://lkml.kernel.org/n/tip-kolmn1yo40p7jhswxwrc7rrd@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Chatur27 <jasonbright2709@gmail.com>
2022-03-04 20:16:35 +01:00
Arnaldo Carvalho de Melo
b40ef34114 perf core: Pass max stack as a perf_callchain_entry context
This makes perf_callchain_{user,kernel}() receive the max stack
as context for the perf_callchain_entry, instead of accessing
the global sysctl_perf_event_max_stack.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Milian Wolff <milian.wolff@kdab.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: Wang Nan <wangnan0@huawei.com>
Cc: Zefan Li <lizefan@huawei.com>
Link: http://lkml.kernel.org/n/tip-kolmn1yo40p7jhswxwrc7rrd@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Chatur27 <jasonbright2709@gmail.com>
2022-03-04 20:16:35 +01:00
Arnaldo Carvalho de Melo
7d27ed19d4 perf core: Allow setting up max frame stack depth via sysctl
The default remains 127, which is good for most cases, and not even hit
most of the time, but then for some cases, as reported by Brendan, 1024+
deep frames are appearing on the radar for things like groovy, ruby.

And in some workloads putting a _lower_ cap on this may make sense. One
that is per event still needs to be put in place tho.

The new file is:

  # cat /proc/sys/kernel/perf_event_max_stack
  127

Chaging it:

  # echo 256 > /proc/sys/kernel/perf_event_max_stack
  # cat /proc/sys/kernel/perf_event_max_stack
  256

But as soon as there is some event using callchains we get:

  # echo 512 > /proc/sys/kernel/perf_event_max_stack
  -bash: echo: write error: Device or resource busy
  #

Because we only allocate the callchain percpu data structures when there
is a user, which allows for changing the max easily, its just a matter
of having no callchain users at that point.

Reported-and-Tested-by: Brendan Gregg <brendan.d.gregg@gmail.com>
Reviewed-by: Frederic Weisbecker <fweisbec@gmail.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Milian Wolff <milian.wolff@kdab.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: Wang Nan <wangnan0@huawei.com>
Cc: Zefan Li <lizefan@huawei.com>
Link: http://lkml.kernel.org/r/20160426002928.GB16708@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Chatur27 <jasonbright2709@gmail.com>
Change-Id: Ic34ecdb4cc1e61257a2926062aa23c960dbd3b8f
2022-03-04 20:16:33 +01:00
Alexei Starovoitov
073a9fd134 perf: generalize perf_callchain
. avoid walking the stack when there is no room left in the buffer
. generalize get_perf_callchain() to be called from bpf helper

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Chatur27 <jasonbright2709@gmail.com>
2022-03-04 20:16:33 +01:00
Alexei Starovoitov
037c241aeb bpf: sanitize bpf tracepoint access
during bpf program loading remember the last byte of ctx access
and at the time of attaching the program to tracepoint check that
the program doesn't access bytes beyond defined in tracepoint fields

This also disallows access to __dynamic_array fields, but can be
relaxed in the future.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Chatur27 <jasonbright2709@gmail.com>
2022-03-04 20:16:31 +01:00
Alexei Starovoitov
7b67df19f9 perf, bpf: allow bpf programs attach to tracepoints
introduce BPF_PROG_TYPE_TRACEPOINT program type and allow it to be attached
to the perf tracepoint handler, which will copy the arguments into
the per-cpu buffer and pass it to the bpf program as its first argument.
The layout of the fields can be discovered by doing
'cat /sys/kernel/debug/tracing/events/sched/sched_switch/format'
prior to the compilation of the program with exception that first 8 bytes
are reserved and not accessible to the program. This area is used to store
the pointer to 'struct pt_regs' which some of the bpf helpers will use:
+---------+
| 8 bytes | hidden 'struct pt_regs *' (inaccessible to bpf program)
+---------+
| N bytes | static tracepoint fields defined in tracepoint/format (bpf readonly)
+---------+
| dynamic | __dynamic_array bytes of tracepoint (inaccessible to bpf yet)
+---------+

Not that all of the fields are already dumped to user space via perf ring buffer
and broken application access it directly without consulting tracepoint/format.
Same rule applies here: static tracepoint fields should only be accessed
in a format defined in tracepoint/format. The order of fields and
field sizes are not an ABI.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Chatur27 <jasonbright2709@gmail.com>
2022-03-04 20:16:31 +01:00
Alexei Starovoitov
ba222c849b perf: split perf_trace_buf_prepare into alloc and update parts
split allows to move expensive update of 'struct trace_entry' to later phase.
Repurpose unused 1st argument of perf_tp_event() to indicate event type.

While splitting use temp variable 'rctx' instead of '*rctx' to avoid
unnecessary loads done by the compiler due to -fno-strict-aliasing

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Chatur27 <jasonbright2709@gmail.com>
2022-03-04 20:16:31 +01:00
Alexei Starovoitov
2fb3319a95 perf/bpf: Convert perf_event_array to use struct file
Robustify refcounting.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: Wang Nan <wangnan0@huawei.com>
Cc: vince@deater.net
Link: http://lkml.kernel.org/r/20160126045947.GA40151@ast-mbp.thefacebook.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Chatur27 <jasonbright2709@gmail.com>
2022-03-04 20:16:28 +01:00
Anay Wadhera
22c9fac00b Revert "bpf: generally move prog destruction to RCU deferral"
This reverts commit e25dc63aa3.

Signed-off-by: Chatur27 <jasonbright2709@gmail.com>
2022-03-04 20:16:24 +01:00
Michael Bestas
76dea3a479 Merge tag 'v4.4.273' into android-msm-wahoo-4.4
This is the 4.4.273 stable release

# gpg: Signature made Wed Jun 16 12:35:37 2021 EEST
# gpg:                using RSA key 647F28654894E3BD457199BE38DBBDC86092693E
# gpg: Good signature from "Greg Kroah-Hartman <gregkh@kernel.org>" [full]
# gpg: gregkh@kernel.org: Verified 24 signatures in the past 2 hours.  Encrypted
#      0 messages.

# By Chris Packham (4) and others
# Via Greg Kroah-Hartman
* tag 'v4.4.273':
  Linux 4.4.273
  proc: only require mm_struct for writing
  ftrace: Do not blindly read the ip address in ftrace_bug()
  scsi: core: Only put parent device if host state differs from SHOST_CREATED
  NFSv4: nfs4_proc_set_acl needs to restore NFS_CAP_UIDGID_NOMAP on error.
  kvm: fix previous commit for 32-bit builds
  perf session: Correct buffer copying when peeking events
  NFS: Fix a potential NULL dereference in nfs_get_client()
  perf: Fix data race between pin_count increment/decrement
  usb: gadget: eem: fix wrong eem header operation
  USB: serial: quatech2: fix control-request directions
  USB: serial: omninet: add device id for Zyxel Omni 56K Plus
  USB: serial: ftdi_sio: add NovaTech OrionMX product ID
  usb: dwc3: ep0: fix NULL pointer exception
  USB: f_ncm: ncm_bitrate (speed) is unsigned
  cgroup1: don't allow '\n' in renaming
  btrfs: return value from btrfs_mark_extent_written() in case of error
  kvm: avoid speculation-based attacks from out-of-range memslot accesses
  i2c: mpc: implement erratum A-004447 workaround
  i2c: mpc: Make use of i2c_recover_bus()
  powerpc/fsl: set fsl,i2c-erratum-a004447 flag for P1010 i2c controllers
  powerpc/fsl: set fsl,i2c-erratum-a004447 flag for P2041 i2c controllers
  bnx2x: Fix missing error code in bnx2x_iov_init_one()
  MIPS: Fix kernel hang under FUNCTION_GRAPH_TRACER and PREEMPT_TRACER
  net: appletalk: cops: Fix data race in cops_probe1
  net: macb: ensure the device is available before accessing GEMGXL control registers
  scsi: target: qla2xxx: Wait for stop_phase1 at WWN removal
  scsi: vmw_pvscsi: Set correct residual data length
  net/qla3xxx: fix schedule while atomic in ql_sem_spinlock
  net: mdiobus: get rid of a BUG_ON()
  netlink: disable IRQs for netlink_lock_table()
  bonding: init notify_work earlier to avoid uninitialized use
  isdn: mISDN: netjet: Fix crash in nj_probe:
  ASoC: sti-sas: add missing MODULE_DEVICE_TABLE
  net/nfc/rawsock.c: fix a permission check bug
  proc: Track /proc/$pid/attr/ opener mm_struct

Change-Id: Iaff375e5434b97d40db74bc158c9b58b79e3de25
2021-07-24 19:28:23 +03:00
Marco Elver
668bd53c54 perf: Fix data race between pin_count increment/decrement
commit 6c605f8371159432ec61cbb1488dcf7ad24ad19a upstream.

KCSAN reports a data race between increment and decrement of pin_count:

  write to 0xffff888237c2d4e0 of 4 bytes by task 15740 on cpu 1:
   find_get_context		kernel/events/core.c:4617
   __do_sys_perf_event_open	kernel/events/core.c:12097 [inline]
   __se_sys_perf_event_open	kernel/events/core.c:11933
   ...
  read to 0xffff888237c2d4e0 of 4 bytes by task 15743 on cpu 0:
   perf_unpin_context		kernel/events/core.c:1525 [inline]
   __do_sys_perf_event_open	kernel/events/core.c:12328 [inline]
   __se_sys_perf_event_open	kernel/events/core.c:11933
   ...

Because neither read-modify-write here is atomic, this can lead to one
of the operations being lost, resulting in an inconsistent pin_count.
Fix it by adding the missing locking in the CPU-event case.

Fixes: fe4b04fa31 ("perf: Cure task_oncpu_function_call() races")
Reported-by: syzbot+142c9018f5962db69c7e@syzkaller.appspotmail.com
Signed-off-by: Marco Elver <elver@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20210527104711.2671610-1-elver@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-06-16 11:34:53 +02:00
Nathan Chancellor
de02d35734 Merge 4.4.244 into android-msm-wahoo-4.4
Changes in 4.4.244: (64 commits)
        ring-buffer: Fix recursion protection transitions between interrupt context
        gfs2: Wake up when sd_glock_disposal becomes zero
        mm: mempolicy: fix potential pte_unmap_unlock pte error
        time: Prevent undefined behaviour in timespec64_to_ns()
        btrfs: reschedule when cloning lots of extents
        net: xfrm: fix a race condition during allocing spi
        perf tools: Add missing swap for ino_generation
        ALSA: hda: prevent undefined shift in snd_hdac_ext_bus_get_link()
        can: dev: can_get_echo_skb(): prevent call to kfree_skb() in hard IRQ context
        can: dev: __can_get_echo_skb(): fix real payload length return value for RTR frames
        can: can_create_echo_skb(): fix echo skb generation: always use skb_clone()
        can: peak_usb: add range checking in decode operations
        can: peak_usb: peak_usb_get_ts_time(): fix timestamp wrapping
        Btrfs: fix missing error return if writeback for extent buffer never started
        pinctrl: devicetree: Avoid taking direct reference to device name string
        i40e: Wrong truncation from u16 to u8
        i40e: Fix of memory leak and integer truncation in i40e_virtchnl.c
        geneve: add transport ports in route lookup for geneve
        ath9k_htc: Use appropriate rs_datalen type
        usb: gadget: goku_udc: fix potential crashes in probe
        gfs2: Free rd_bits later in gfs2_clear_rgrpd to fix use-after-free
        gfs2: check for live vs. read-only file system in gfs2_fitrim
        drm/amdgpu: perform srbm soft reset always on SDMA resume
        mac80211: fix use of skb payload instead of header
        cfg80211: regulatory: Fix inconsistent format argument
        iommu/amd: Increase interrupt remapping table limit to 512 entries
        xfs: fix a missing unlock on error in xfs_fs_map_blocks
        of/address: Fix of_node memory leak in of_dma_is_coherent
        cosa: Add missing kfree in error path of cosa_write
        perf: Fix get_recursion_context()
        ext4: correctly report "not supported" for {usr,grp}jquota when !CONFIG_QUOTA
        ext4: unlock xattr_sem properly in ext4_inline_data_truncate()
        usb: cdc-acm: Add DISABLE_ECHO for Renesas USB Download mode
        mei: protect mei_cl_mtu from null dereference
        ocfs2: initialize ip_next_orphan
        don't dump the threads that had been already exiting when zapped.
        drm/gma500: Fix out-of-bounds access to struct drm_device.vblank[]
        pinctrl: amd: use higher precision for 512 RtcClk
        pinctrl: amd: fix incorrect way to disable debounce filter
        swiotlb: fix "x86: Don't panic if can not alloc buffer for swiotlb"
        IPv6: Set SIT tunnel hard_header_len to zero
        net/af_iucv: fix null pointer dereference on shutdown
        net/x25: Fix null-ptr-deref in x25_connect
        net: Update window_clamp if SOCK_RCVBUF is set
        random32: make prandom_u32() output unpredictable
        x86/speculation: Allow IBPB to be conditionally enabled on CPUs with always-on STIBP
        xen/events: avoid removing an event channel while handling it
        xen/events: add a proper barrier to 2-level uevent unmasking
        xen/events: fix race in evtchn_fifo_unmask()
        xen/events: add a new "late EOI" evtchn framework
        xen/blkback: use lateeoi irq binding
        xen/netback: use lateeoi irq binding
        xen/scsiback: use lateeoi irq binding
        xen/pciback: use lateeoi irq binding
        xen/events: switch user event channels to lateeoi model
        xen/events: use a common cpu hotplug hook for event channels
        xen/events: defer eoi in case of excessive number of events
        xen/events: block rogue events for some time
        perf/core: Fix race in the perf_mmap_close() function
        Revert "kernel/reboot.c: convert simple_strtoul to kstrtoint"
        reboot: fix overflow parsing reboot cpu number
        ext4: fix leaking sysfs kobject after failed mount
        Convert trailing spaces and periods in path components
        Linux 4.4.244

Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
2020-11-18 19:43:37 -07:00
Jiri Olsa
17b235e6cc perf/core: Fix race in the perf_mmap_close() function
commit f91072ed1b7283b13ca57fcfbece5a3b92726143 upstream.

There's a possible race in perf_mmap_close() when checking ring buffer's
mmap_count refcount value. The problem is that the mmap_count check is
not atomic because we call atomic_dec() and atomic_read() separately.

  perf_mmap_close:
  ...
   atomic_dec(&rb->mmap_count);
   ...
   if (atomic_read(&rb->mmap_count))
      goto out_put;

   <ring buffer detach>
   free_uid

out_put:
  ring_buffer_put(rb); /* could be last */

The race can happen when we have two (or more) events sharing same ring
buffer and they go through atomic_dec() and then they both see 0 as refcount
value later in atomic_read(). Then both will go on and execute code which
is meant to be run just once.

The code that detaches ring buffer is probably fine to be executed more
than once, but the problem is in calling free_uid(), which will later on
demonstrate in related crashes and refcount warnings, like:

  refcount_t: addition on 0; use-after-free.
  ...
  RIP: 0010:refcount_warn_saturate+0x6d/0xf
  ...
  Call Trace:
  prepare_creds+0x190/0x1e0
  copy_creds+0x35/0x172
  copy_process+0x471/0x1a80
  _do_fork+0x83/0x3a0
  __do_sys_wait4+0x83/0x90
  __do_sys_clone+0x85/0xa0
  do_syscall_64+0x5b/0x1e0
  entry_SYSCALL_64_after_hwframe+0x44/0xa9

Using atomic decrease and check instead of separated calls.

Tested-by: Michael Petlan <mpetlan@redhat.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Wade Mealing <wmealing@redhat.com>
Fixes: 9bb5d40cd9 ("perf: Fix mmap() accounting hole");
Link: https://lore.kernel.org/r/20200916115311.GE2301783@krava
[sudip: backport to v4.9.y by using ring_buffer]
Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-11-18 18:25:04 +01:00
Peter Zijlstra
57f9654bde perf: Fix get_recursion_context()
[ Upstream commit ce0f17fc93f63ee91428af10b7b2ddef38cd19e5 ]

One should use in_serving_softirq() to detect SoftIRQ context.

Fixes: 96f6d44443 ("perf_counter: avoid recursion")
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20201030151955.120572175@infradead.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
2020-11-18 18:25:00 +01:00
Nathan Chancellor
a66a3944e1 Merge 4.4.232 into android-msm-wahoo-4.4
Changes in 4.4.232: (55 commits)
        pinctrl: amd: fix npins for uart0 in kerncz_groups
        mac80211: allow rx of mesh eapol frames with default rx key
        scsi: scsi_transport_spi: Fix function pointer check
        xtensa: fix __sync_fetch_and_{and,or}_4 declarations
        xtensa: update *pos in cpuinfo_op.next
        drivers/net/wan/lapbether: Fixed the value of hard_header_len
        net: sky2: initialize return of gm_phy_read
        drm/nouveau/i2c/g94-: increase NV_PMGR_DP_AUXCTL_TRANSACTREQ timeout
        SUNRPC reverting d03727b248d0 ("NFSv4 fix CLOSE not waiting for direct IO compeletion")
        perf/core: Fix locking for children siblings group read
        uprobes: Change handle_swbp() to send SIGTRAP with si_code=SI_KERNEL, to fix GDB regression
        ALSA: info: Drop WARN_ON() from buffer NULL sanity check
        ASoC: rt5670: Correct RT5670_LDO_SEL_MASK
        btrfs: fix double free on ulist after backref resolution failure
        x86/fpu: Disable bottom halves while loading FPU registers
        btrfs: fix mount failure caused by race with umount
        hippi: Fix a size used in a 'pci_free_consistent()' in an error handling path
        ax88172a: fix ax88172a_unbind() failures
        net: dp83640: fix SIOCSHWTSTAMP to update the struct with actual configuration
        net: smc91x: Fix possible memory leak in smc_drv_probe()
        scripts/decode_stacktrace: strip basepath from all paths
        regmap: dev_get_regmap_match(): fix string comparison
        usb: gadget: udc: gr_udc: fix memleak on error handling path in gr_ep_init()
        arm64: Use test_tsk_thread_flag() for checking TIF_SINGLESTEP
        x86: math-emu: Fix up 'cmp' insn for clang ias
        Revert "cifs: Fix the target file was deleted when rename failed."
        staging: wlan-ng: properly check endpoint types
        staging: comedi: addi_apci_1032: check INSN_CONFIG_DIGITAL_TRIG shift
        staging: comedi: ni_6527: fix INSN_CONFIG_DIGITAL_TRIG support
        staging: comedi: addi_apci_1500: check INSN_CONFIG_DIGITAL_TRIG shift
        staging: comedi: addi_apci_1564: check INSN_CONFIG_DIGITAL_TRIG shift
        serial: 8250: fix null-ptr-deref in serial8250_start_tx()
        serial: 8250_mtk: Fix high-speed baud rates clamping
        mm/memcg: fix refcount error while moving and swapping
        parisc: Add atomic64_set_release() define to avoid CPU soft lockups
        ath9k: Fix general protection fault in ath9k_hif_usb_rx_cb
        ath9k: Fix regression with Atheros 9271
        AX.25: Fix out-of-bounds read in ax25_connect()
        AX.25: Prevent out-of-bounds read in ax25_sendmsg()
        net-sysfs: add a newline when printing 'tx_timeout' by sysfs
        net: udp: Fix wrong clean up for IS_UDPLITE macro
        AX.25: Prevent integer overflows in connect and sendmsg
        tcp: allow at most one TLP probe per flight
        rxrpc: Fix sendmsg() returning EPIPE due to recvmsg() returning ENODATA
        ip6_gre: fix null-ptr-deref in ip6gre_init_net()
        drivers/net/wan/x25_asy: Fix to make it work
        Makefile: Fix GCC_TOOLCHAIN_DIR prefix for Clang cross compilation
        regmap: debugfs: check count when read regmap file
        xfs: set format back to extents if xfs_bmap_extents_to_btree
        tools/lib/subcmd/pager.c: do not alias select() params
        perf: Make perf able to build with latest libbfd
        perf tools: Fix snprint warnings for gcc 8
        perf annotate: Use asprintf when formatting objdump command line
        perf probe: Fix to check blacklist address correctly
        Linux 4.4.232

Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
2020-07-31 10:04:56 -07:00
Oleg Nesterov
7a3a171faa uprobes: Change handle_swbp() to send SIGTRAP with si_code=SI_KERNEL, to fix GDB regression
commit fe5ed7ab99c656bd2f5b79b49df0e9ebf2cead8a upstream.

If a tracee is uprobed and it hits int3 inserted by debugger, handle_swbp()
does send_sig(SIGTRAP, current, 0) which means si_code == SI_USER. This used
to work when this code was written, but then GDB started to validate si_code
and now it simply can't use breakpoints if the tracee has an active uprobe:

	# cat test.c
	void unused_func(void)
	{
	}
	int main(void)
	{
		return 0;
	}

	# gcc -g test.c -o test
	# perf probe -x ./test -a unused_func
	# perf record -e probe_test:unused_func gdb ./test -ex run
	GNU gdb (GDB) 10.0.50.20200714-git
	...
	Program received signal SIGTRAP, Trace/breakpoint trap.
	0x00007ffff7ddf909 in dl_main () from /lib64/ld-linux-x86-64.so.2
	(gdb)

The tracee hits the internal breakpoint inserted by GDB to monitor shared
library events but GDB misinterprets this SIGTRAP and reports a signal.

Change handle_swbp() to use force_sig(SIGTRAP), this matches do_int3_user()
and fixes the problem.

This is the minimal fix for -stable, arch/x86/kernel/uprobes.c is equally
wrong; it should use send_sigtrap(TRAP_TRACE) instead of send_sig(SIGTRAP),
but this doesn't confuse GDB and needs another x86-specific patch.

Reported-by: Aaron Merey <amerey@redhat.com>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20200723154420.GA32043@redhat.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-07-31 16:43:12 +02:00
Jiri Olsa
b7fe83d9ae perf/core: Fix locking for children siblings group read
commit 2aeb1883547626d82c597cce2c99f0b9c62e2425 upstream.

We're missing ctx lock when iterating children siblings
within the perf_read path for group reading. Following
race and crash can happen:

User space doing read syscall on event group leader:

T1:
  perf_read
    lock event->ctx->mutex
    perf_read_group
      lock leader->child_mutex
      __perf_read_group_add(child)
        list_for_each_entry(sub, &leader->sibling_list, group_entry)

---->   sub might be invalid at this point, because it could
        get removed via perf_event_exit_task_context in T2

Child exiting and cleaning up its events:

T2:
  perf_event_exit_task_context
    lock ctx->mutex
    list_for_each_entry_safe(child_event, next, &child_ctx->event_list,...
      perf_event_exit_event(child)
        lock ctx->lock
        perf_group_detach(child)
        unlock ctx->lock

---->   child is removed from sibling_list without any sync
        with T1 path above

        ...
        free_event(child)

Before the child is removed from the leader's child_list,
(and thus is omitted from perf_read_group processing), we
need to ensure that perf_read_group touches child's
siblings under its ctx->lock.

Peter further notes:

| One additional note; this bug got exposed by commit:
|
|   ba5213ae6b88 ("perf/core: Correct event creation with PERF_FORMAT_GROUP")
|
| which made it possible to actually trigger this code-path.

Tested-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Fixes: ba5213ae6b88 ("perf/core: Correct event creation with PERF_FORMAT_GROUP")
Link: http://lkml.kernel.org/r/20170720141455.2106-1-jolsa@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-07-31 16:43:12 +02:00
Nathan Chancellor
43380b4983 Merge 4.4.227 into android-msm-wahoo-4.4
Changes in 4.4.227: (37 commits)
        scsi: scsi_devinfo: fixup string compare
        usb: gadget: f_uac2: fix error handling in afunc_bind (again)
        platform/x86: acer-wmi: setup accelerometer when ACPI device was found
        esp6: fix memleak on error path in esp6_input
        IB/mlx4: Fix an error handling path in 'mlx4_ib_rereg_user_mr()'
        ALSA: hda - No loopback on ALC299 codec
        spi: dw: use "smp_mb()" to avoid sending spi data error
        s390/ftrace: save traced function caller
        ARC: Fix ICCM & DCCM runtime size checks
        x86/mmiotrace: Use cpumask_available() for cpumask_var_t variables
        net: bmac: Fix read of MAC address from ROM
        net/ethernet/freescale: rework quiesce/activate for ucc_geth
        net: ethernet: stmmac: Enable interface clocks on probe for IPQ806x
        pppoe: only process PADT targeted at local interfaces
        mmc: fix compilation of user API
        slcan: Fix double-free on slcan_open() error path
        slip: not call free_netdev before rtnl_unlock in slip_open
        scsi: ufs: Release clock if DMA map fails
        devinet: fix memleak in inetdev_init()
        NFC: st21nfca: add missed kfree_skb() in an error path
        vsock: fix timeout in vsock_accept()
        l2tp: add sk_family checks to l2tp_validate_socket
        l2tp: do not use inet_hash()/inet_unhash()
        USB: serial: qcserial: add DW5816e QDL support
        USB: serial: usb_wwan: do not resubmit rx urb on fatal errors
        USB: serial: option: add Telit LE910C1-EUX compositions
        vt: keyboard: avoid signed integer overflow in k_ascii
        staging: rtl8712: Fix IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK
        x86/cpu: Rename cpu_data.x86_mask to cpu_data.x86_stepping
        x86/cpu: Add a steppings field to struct x86_cpu_id
        x86/cpu: Add 'table' argument to cpu_matches()
        x86/speculation: Add Special Register Buffer Data Sampling (SRBDS) mitigation
        x86/speculation: Add SRBDS vulnerability and mitigation documentation
        x86/speculation: Add Ivy Bridge to affected list
        iio: vcnl4000: Fix i2c swapped word reading.
        uprobes: ensure that uprobe->offset and ->ref_ctr_offset are properly aligned
        Linux 4.4.227

Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
2020-06-11 08:44:31 -07:00
Oleg Nesterov
1c66189c16 uprobes: ensure that uprobe->offset and ->ref_ctr_offset are properly aligned
commit 013b2deba9a6b80ca02f4fafd7dedf875e9b4450 upstream.

uprobe_write_opcode() must not cross page boundary; prepare_uprobe()
relies on arch_uprobe_analyze_insn() which should validate "vaddr" but
some architectures (csky, s390, and sparc) don't do this.

We can remove the BUG_ON() check in prepare_uprobe() and validate the
offset early in __uprobe_register(). The new IS_ALIGNED() check matches
the alignment check in arch_prepare_kprobe() on supported architectures,
so I think that all insns must be aligned to UPROBE_SWBP_INSN_SIZE.

Another problem is __update_ref_ctr() which was wrong from the very
beginning, it can read/write outside of kmap'ed page unless "vaddr" is
aligned to sizeof(short), __uprobe_register() should check this too.

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Reviewed-by: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
Tested-by: Sven Schnelle <svens@linux.ibm.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: stable@vger.kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
[ check for ref_ctr_offset removed for backport - gregkh ]
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-06-11 09:21:41 +02:00
Nathan Chancellor
c1b3686825 Merge 4.4.221 into android-msm-wahoo-4.4
Changes in 4.4.221: (71 commits)
        ext4: fix extent_status fragmentation for plain files
        ALSA: hda - Fix incorrect usage of IS_REACHABLE()
        net: ipv4: emulate READ_ONCE() on ->hdrincl bit-field in raw_sendmsg()
        net: ipv4: avoid unused variable warning for sysctl
        crypto: mxs-dcp - make symbols 'sha1_null_hash' and 'sha256_null_hash' static
        vti4: removed duplicate log message.
        scsi: lpfc: Fix kasan slab-out-of-bounds error in lpfc_unreg_login
        ceph: return ceph_mdsc_do_request() errors from __get_parent()
        ceph: don't skip updating wanted caps when cap is stale
        pwm: rcar: Fix late Runtime PM enablement
        scsi: iscsi: Report unbind session event when the target has been removed
        ASoC: Intel: atom: Take the drv->lock mutex before calling sst_send_slot_map()
        kernel/gcov/fs.c: gcov_seq_next() should increase position index
        ipc/util.c: sysvipc_find_ipc() should increase position index
        s390/cio: avoid duplicated 'ADD' uevents
        pwm: renesas-tpu: Fix late Runtime PM enablement
        pwm: bcm2835: Dynamically allocate base
        ipv6: fix restrict IPV6_ADDRFORM operation
        macvlan: fix null dereference in macvlan_device_event()
        net: netrom: Fix potential nr_neigh refcnt leak in nr_add_node
        net/x25: Fix x25_neigh refcnt leak when receiving frame
        tcp: cache line align MAX_TCP_HEADER
        team: fix hang in team_mode_get()
        xfrm: Always set XFRM_TRANSFORMED in xfrm{4,6}_output_finish
        ALSA: hda: Remove ASUS ROG Zenith from the blacklist
        iio: xilinx-xadc: Fix ADC-B powerdown
        iio: xilinx-xadc: Fix clearing interrupt when enabling trigger
        iio: xilinx-xadc: Fix sequencer configuration for aux channels in simultaneous mode
        fs/namespace.c: fix mountpoint reference counter race
        USB: sisusbvga: Change port variable from signed to unsigned
        USB: Add USB_QUIRK_DELAY_CTRL_MSG and USB_QUIRK_DELAY_INIT for Corsair K70 RGB RAPIDFIRE
        drivers: usb: core: Don't disable irqs in usb_sg_wait() during URB submit.
        drivers: usb: core: Minimize irq disabling in usb_sg_cancel()
        USB: core: Fix free-while-in-use bug in the USB S-Glibrary
        USB: hub: Fix handling of connect changes during sleep
        ALSA: usx2y: Fix potential NULL dereference
        ALSA: usb-audio: Fix usb audio refcnt leak when getting spdif
        ALSA: usb-audio: Filter out unsupported sample rates on Focusrite devices
        KVM: Check validity of resolved slot when searching memslots
        KVM: VMX: Enable machine check support for 32bit targets
        tty: hvc: fix buffer overflow during hvc_alloc().
        tty: rocket, avoid OOB access
        usb-storage: Add unusual_devs entry for JMicron JMS566
        audit: check the length of userspace generated audit records
        ASoC: dapm: fixup dapm kcontrol widget
        ARM: imx: provide v7_cpu_resume() only on ARM_CPU_SUSPEND=y
        staging: comedi: dt2815: fix writing hi byte of analog output
        staging: comedi: Fix comedi_device refcnt leak in comedi_open
        staging: vt6656: Fix drivers TBTT timing counter.
        staging: vt6656: Power save stop wake_up_count wrap around.
        UAS: no use logging any details in case of ENODEV
        UAS: fix deadlock in error handling and PM flushing work
        usb: f_fs: Clear OS Extended descriptor counts to zero in ffs_data_reset()
        remoteproc: Fix wrong rvring index computation
        sctp: use right member as the param of list_for_each_entry
        fuse: fix possibly missed wake-up after abort
        mtd: cfi: fix deadloop in cfi_cmdset_0002.c do_write_buffer
        usb: gadget: udc: bdc: Remove unnecessary NULL checks in bdc_req_complete
        net/cxgb4: Check the return from t4_query_params properly
        perf/core: fix parent pid/tid in task exit events
        bpf, x86: Fix encoding for lower 8-bit registers in BPF_STX BPF_B
        scsi: target: fix PR IN / READ FULL STATUS for FC
        xen/xenbus: ensure xenbus_map_ring_valloc() returns proper grant status
        ext4: convert BUG_ON's to WARN_ON's in mballoc.c
        ext4: avoid declaring fs inconsistent due to invalid file handles
        ext4: protect journal inode's blocks using block_validity
        ext4: don't perform block validity checks on the journal inode
        ext4: fix block validity checks for journal inodes using indirect blocks
        ext4: unsigned int compared against zero
        propagate_one(): mnt_set_mountpoint() needs mount_lock
        Linux 4.4.221

Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>

Conflicts:
	drivers/usb/gadget/function/f_fs.c
2020-05-02 08:44:27 -07:00
Ian Rogers
5cc0ce6d61 perf/core: fix parent pid/tid in task exit events
commit f3bed55e850926614b9898fe982f66d2541a36a5 upstream.

Current logic yields the child task as the parent.

Before:
$ perf record bash -c "perf list > /dev/null"
$ perf script -D |grep 'FORK\|EXIT'
4387036190981094 0x5a70 [0x30]: PERF_RECORD_FORK(10472:10472):(10470:10470)
4387036606207580 0xf050 [0x30]: PERF_RECORD_EXIT(10472:10472):(10472:10472)
4387036607103839 0x17150 [0x30]: PERF_RECORD_EXIT(10470:10470):(10470:10470)
                                                   ^
  Note the repeated values here -------------------/

After:
383281514043 0x9d8 [0x30]: PERF_RECORD_FORK(2268:2268):(2266:2266)
383442003996 0x2180 [0x30]: PERF_RECORD_EXIT(2268:2268):(2266:2266)
383451297778 0xb70 [0x30]: PERF_RECORD_EXIT(2266:2266):(2265:2265)

Fixes: 94d5d1b2d8 ("perf_counter: Report the cloning task as parent on perf_counter_fork()")
Reported-by: KP Singh <kpsingh@google.com>
Signed-off-by: Ian Rogers <irogers@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20200417182842.12522-1-irogers@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-05-02 17:20:52 +02:00
Nathan Chancellor
3b04238a2f Merge 4.4.214 into android-msm-wahoo-4.4
Changes in 4.4.214: (90 commits)
        media: iguanair: fix endpoint sanity check
        x86/cpu: Update cached HLE state on write to TSX_CTRL_CPUID_CLEAR
        sparc32: fix struct ipc64_perm type definition
        ASoC: qcom: Fix of-node refcount unbalance to link->codec_of_node
        cls_rsvp: fix rsvp_policy
        net: hsr: fix possible NULL deref in hsr_handle_frame()
        net_sched: fix an OOB access in cls_tcindex
        tcp: clear tp->total_retrans in tcp_disconnect()
        tcp: clear tp->segs_{in|out} in tcp_disconnect()
        media: uvcvideo: Avoid cyclic entity chains due to malformed USB descriptors
        mfd: dln2: More sanity checking for endpoints
        brcmfmac: Fix memory leak in brcmf_usbdev_qinit
        usb: gadget: legacy: set max_speed to super-speed
        usb: gadget: f_ncm: Use atomic_t to track in-flight request
        usb: gadget: f_ecm: Use atomic_t to track in-flight request
        ALSA: dummy: Fix PCM format loop in proc output
        lib/test_kasan.c: fix memory leak in kmalloc_oob_krealloc_more()
        powerpc/pseries: Advance pfn if section is not present in lmb_is_removable()
        mmc: spi: Toggle SPI polarity, do not hardcode it
        PCI: keystone: Fix link training retries initiation
        crypto: api - Check spawn->alg under lock in crypto_drop_spawn
        scsi: qla2xxx: Fix mtcp dump collection failure
        power: supply: ltc2941-battery-gauge: fix use-after-free
        Revert "ovl: modify ovl_permission() to do checks on two inodes"
        of: Add OF_DMA_DEFAULT_COHERENT & select it on powerpc
        dm space map common: fix to ensure new block isn't already in use
        crypto: pcrypt - Do not clear MAY_SLEEP flag in original request
        crypto: api - Fix race condition in crypto_spawn_alg
        crypto: picoxcell - adjust the position of tasklet_init and fix missed tasklet_kill
        btrfs: set trans->drity in btrfs_commit_transaction
        ARM: tegra: Enable PLLP bypass during Tegra124 LP1
        mwifiex: fix unbalanced locking in mwifiex_process_country_ie()
        sunrpc: expiry_time should be seconds not timeval
        KVM: x86: Refactor prefix decoding to prevent Spectre-v1/L1TF attacks
        KVM: x86: Protect DR-based index computations from Spectre-v1/L1TF attacks
        KVM: x86: Protect kvm_hv_msr_[get|set]_crash_data() from Spectre-v1/L1TF attacks
        KVM: x86: Protect ioapic_write_indirect() from Spectre-v1/L1TF attacks
        KVM: x86: Protect MSR-based index computations in pmu.h from Spectre-v1/L1TF attacks
        KVM: x86: Protect ioapic_read_indirect() from Spectre-v1/L1TF attacks
        KVM: x86: Protect MSR-based index computations from Spectre-v1/L1TF attacks in x86.c
        KVM: x86: Protect x86_decode_insn from Spectre-v1/L1TF attacks
        KVM: x86: Protect MSR-based index computations in fixed_msr_to_seg_unit() from Spectre-v1/L1TF attacks
        KVM: PPC: Book3S HV: Uninit vCPU if vcore creation fails
        KVM: PPC: Book3S PR: Free shared page if mmu initialization fails
        KVM: x86: Free wbinvd_dirty_mask if vCPU creation fails
        scsi: qla2xxx: Fix the endianness of the qla82xx_get_fw_size() return type
        scsi: csiostor: Adjust indentation in csio_device_reset
        scsi: qla4xxx: Adjust indentation in qla4xxx_mem_free
        ext2: Adjust indentation in ext2_fill_super
        powerpc/44x: Adjust indentation in ibm4xx_denali_fixup_memsize
        NFC: pn544: Adjust indentation in pn544_hci_check_presence
        ppp: Adjust indentation into ppp_async_input
        net: smc911x: Adjust indentation in smc911x_phy_configure
        net: tulip: Adjust indentation in {dmfe, uli526x}_init_module
        mfd: da9062: Fix watchdog compatible string
        mfd: rn5t618: Mark ADC control register volatile
        net: systemport: Avoid RBUF stuck in Wake-on-LAN mode
        bonding/alb: properly access headers in bond_alb_xmit()
        NFS: Fix memory leaks and corruption in readdir
        NFS: Fix bool initialization/comparison
        NFS: Directory page cache pages need to be locked when read
        Btrfs: fix assertion failure on fsync with NO_HOLES enabled
        btrfs: remove trivial locking wrappers of tree mod log
        Btrfs: fix race between adding and putting tree mod seq elements and nodes
        drm: atmel-hlcdc: enable clock before configuring timing engine
        KVM: x86: drop picdev_in_range()
        KVM: x86: Refactor picdev_write() to prevent Spectre-v1/L1TF attacks
        KVM: x86: Protect pmu_intel.c from Spectre-v1/L1TF attacks
        KVM: x86: Protect kvm_lapic_reg_write() from Spectre-v1/L1TF attacks
        btrfs: flush write bio if we loop in extent_write_cache_pages
        KVM: x86/mmu: Apply max PA check for MMIO sptes to 32-bit KVM
        KVM: VMX: Add non-canonical check on writes to RTIT address MSRs
        KVM: nVMX: vmread should not set rflags to specify success in case of #PF
        cifs: fail i/o on soft mounts if sessionsetup errors out
        clocksource: Prevent double add_timer_on() for watchdog_timer
        perf/core: Fix mlock accounting in perf_mmap()
        ASoC: pcm: update FE/BE trigger order based on the command
        scsi: ufs: Fix ufshcd_probe_hba() reture value in case ufshcd_scsi_add_wlus() fails
        rtc: hym8563: Return -EINVAL if the time is known to be invalid
        ARC: [plat-axs10x]: Add missing multicast filter number to GMAC node
        ARM: dts: at91: sama5d3: fix maximum peripheral clock rates
        ARM: dts: at91: sama5d3: define clock rate range for tcb1
        powerpc/pseries: Allow not having ibm, hypertas-functions::hcall-multi-tce for DDW
        pinctrl: sh-pfc: r8a7778: Fix duplicate SDSELF_B and SD1_CLK_B
        mwifiex: Fix possible buffer overflows in mwifiex_ret_wmm_get_status()
        mwifiex: Fix possible buffer overflows in mwifiex_cmd_append_vsie_tlv()
        libertas: don't exit from lbs_ibss_join_existing() with RCU read lock held
        libertas: make lbs_ibss_join_existing() return error code on rates overflow
        dm: fix potential for q->make_request_fn NULL pointer
        Linux 4.4.214

Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>

Conflicts:
	drivers/of/Kconfig
2020-02-18 13:33:36 -07:00
Song Liu
501f377377 perf/core: Fix mlock accounting in perf_mmap()
commit 003461559ef7a9bd0239bae35a22ad8924d6e9ad upstream.

Decreasing sysctl_perf_event_mlock between two consecutive perf_mmap()s of
a perf ring buffer may lead to an integer underflow in locked memory
accounting. This may lead to the undesired behaviors, such as failures in
BPF map creation.

Address this by adjusting the accounting logic to take into account the
possibility that the amount of already locked memory may exceed the
current limit.

Fixes: c4b75479741c ("perf/core: Make the mlock accounting simple again")
Suggested-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: <stable@vger.kernel.org>
Acked-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Link: https://lkml.kernel.org/r/20200123181146.2238074-1-songliubraving@fb.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-02-14 16:30:01 -05:00
Nathan Chancellor
48a3c041eb Merge 4.4.203 into android-msm-wahoo-4.4
Changes in 4.4.203: (157 commits)
        slip: Fix memory leak in slip_open error path
        ax88172a: fix information leak on short answers
        ALSA: usb-audio: Fix missing error check at mixer resolution test
        ALSA: usb-audio: not submit urb for stopped endpoint
        Input: ff-memless - kill timer in destroy()
        ecryptfs_lookup_interpose(): lower_dentry->d_inode is not stable
        ecryptfs_lookup_interpose(): lower_dentry->d_parent is not stable either
        iommu/vt-d: Fix QI_DEV_IOTLB_PFSID and QI_DEV_EIOTLB_PFSID macros
        mm: memcg: switch to css_tryget() in get_mem_cgroup_from_mm()
        mm: hugetlb: switch to css_tryget() in hugetlb_cgroup_charge_cgroup()
        mmc: sdhci-of-at91: fix quirk2 overwrite
        iio: dac: mcp4922: fix error handling in mcp4922_write_raw
        ALSA: pcm: signedness bug in snd_pcm_plug_alloc()
        ARM: dts: at91/trivial: Fix USART1 definition for at91sam9g45
        ALSA: seq: Do error checks at creating system ports
        gfs2: Don't set GFS2_RDF_UPTODATE when the lvb is updated
        ASoC: dpcm: Properly initialise hw->rate_max
        MIPS: BCM47XX: Enable USB power on Netgear WNDR3400v3
        ARM: dts: exynos: Fix sound in Snow-rev5 Chromebook
        i40e: use correct length for strncpy
        i40e: hold the rtnl lock on clearing interrupt scheme
        i40e: Prevent deleting MAC address from VF when set by PF
        ARM: dts: pxa: fix power i2c base address
        rtl8187: Fix warning generated when strncpy() destination length matches the sixe argument
        net: lan78xx: Bail out if lan78xx_get_endpoints fails
        ASoC: sgtl5000: avoid division by zero if lo_vag is zero
        ath10k: wmi: disable softirq's while calling ieee80211_rx
        mips: txx9: fix iounmap related issue
        of: make PowerMac cache node search conditional on CONFIG_PPC_PMAC
        ARM: dts: omap3-gta04: give spi_lcd node a label so that we can overwrite in other DTS files
        ARM: dts: omap3-gta04: tvout: enable as display1 alias
        ARM: dts: omap3-gta04: make NAND partitions compatible with recent U-Boot
        ARM: dts: omap3-gta04: keep vpll2 always on
        dmaengine: dma-jz4780: Further residue status fix
        signal: Always ignore SIGKILL and SIGSTOP sent to the global init
        signal: Properly deliver SIGILL from uprobes
        signal: Properly deliver SIGSEGV from x86 uprobes
        scsi: sym53c8xx: fix NULL pointer dereference panic in sym_int_sir()
        ARM: imx6: register pm_power_off handler if "fsl,pmic-stby-poweroff" is set
        scsi: pm80xx: Corrected dma_unmap_sg() parameter
        scsi: pm80xx: Fixed system hang issue during kexec boot
        kprobes: Don't call BUG_ON() if there is a kprobe in use on free list
        nvmem: core: return error code instead of NULL from nvmem_device_get
        media: fix: media: pci: meye: validate offset to avoid arbitrary access
        ALSA: intel8x0m: Register irq handler after register initializations
        pinctrl: at91-pio4: fix has_config check in atmel_pctl_dt_subnode_to_map()
        llc: avoid blocking in llc_sap_close()
        powerpc/vdso: Correct call frame information
        ARM: dts: socfpga: Fix I2C bus unit-address error
        pinctrl: at91: don't use the same irqchip with multiple gpiochips
        cxgb4: Fix endianness issue in t4_fwcache()
        power: supply: ab8500_fg: silence uninitialized variable warnings
        power: supply: max8998-charger: Fix platform data retrieval
        kernfs: Fix range checks in kernfs_get_target_path
        s390/qeth: invoke softirqs after napi_schedule()
        PCI/ACPI: Correct error message for ASPM disabling
        serial: mxs-auart: Fix potential infinite loop
        powerpc/iommu: Avoid derefence before pointer check
        powerpc/64s/hash: Fix stab_rr off by one initialization
        powerpc/pseries: Disable CPU hotplug across migrations
        libfdt: Ensure INT_MAX is defined in libfdt_env.h
        power: supply: twl4030_charger: fix charging current out-of-bounds
        power: supply: twl4030_charger: disable eoc interrupt on linear charge
        net: toshiba: fix return type of ndo_start_xmit function
        net: xilinx: fix return type of ndo_start_xmit function
        net: broadcom: fix return type of ndo_start_xmit function
        net: amd: fix return type of ndo_start_xmit function
        usb: chipidea: Fix otg event handler
        ARM: dts: am335x-evm: fix number of cpsw
        ARM: dts: ux500: Correct SCU unit address
        ARM: dts: ux500: Fix LCDA clock line muxing
        ARM: dts: ste: Fix SPI controller node names
        cpufeature: avoid warning when compiling with clang
        bnx2x: Ignore bandwidth attention in single function mode
        net: micrel: fix return type of ndo_start_xmit function
        x86/CPU: Use correct macros for Cyrix calls
        MIPS: kexec: Relax memory restriction
        media: pci: ivtv: Fix a sleep-in-atomic-context bug in ivtv_yuv_init()
        media: davinci: Fix implicit enum conversion warning
        usb: gadget: uvc: configfs: Drop leaked references to config items
        usb: gadget: uvc: configfs: Prevent format changes after linking header
        usb: gadget: uvc: Factor out video USB request queueing
        usb: gadget: uvc: Only halt video streaming endpoint in bulk mode
        misc: kgdbts: Fix restrict error
        misc: genwqe: should return proper error value.
        vfio/pci: Fix potential memory leak in vfio_msi_cap_len
        scsi: libsas: always unregister the old device if going to discover new
        ARM: dts: tegra30: fix xcvr-setup-use-fuses
        ARM: tegra: apalis_t30: fix mmc1 cmd pull-up
        net: smsc: fix return type of ndo_start_xmit function
        EDAC: Raise the maximum number of memory controllers
        Bluetooth: L2CAP: Detect if remote is not able to use the whole MPS
        arm64: dts: amd: Fix SPI bus warnings
        fuse: use READ_ONCE on congestion_threshold and max_background
        Bluetooth: hci_ldisc: Fix null pointer derefence in case of early data
        Bluetooth: hci_ldisc: Postpone HCI_UART_PROTO_READY bit set in hci_uart_set_proto()
        memfd: Use radix_tree_deref_slot_protected to avoid the warning.
        slcan: Fix memory leak in error path
        net: cdc_ncm: Signedness bug in cdc_ncm_set_dgram_size()
        x86/atomic: Fix smp_mb__{before,after}_atomic()
        apparmor: fix uninitialized lsm_audit member
        apparmor: fix update the mtime of the profile file on replacement
        apparmor: fix module parameters can be changed after policy is locked
        kprobes/x86: Prohibit probing on exception masking instructions
        uprobes/x86: Prohibit probing on MOV SS instruction
        fbdev: Remove unused SH-Mobile HDMI driver
        fbdev: Ditch fb_edid_add_monspecs
        block: introduce blk_rq_is_passthrough
        libata: have ata_scsi_rw_xlat() fail invalid passthrough requests
        net: ovs: fix return type of ndo_start_xmit function
        f2fs: return correct errno in f2fs_gc
        SUNRPC: Fix priority queue fairness
        ath10k: fix vdev-start timeout on error
        ath9k: fix reporting calculated new FFT upper max
        usb: gadget: udc: fotg210-udc: Fix a sleep-in-atomic-context bug in fotg210_get_status()
        nl80211: Fix a GET_KEY reply attribute
        dmaengine: ep93xx: Return proper enum in ep93xx_dma_chan_direction
        dmaengine: timb_dma: Use proper enum in td_prep_slave_sg
        mei: samples: fix a signedness bug in amt_host_if_call()
        cxgb4: Use proper enum in cxgb4_dcb_handle_fw_update
        cxgb4: Use proper enum in IEEE_FAUX_SYNC
        powerpc/pseries: Fix DTL buffer registration
        powerpc/pseries: Fix how we iterate over the DTL entries
        mtd: rawnand: sh_flctl: Use proper enum for flctl_dma_fifo0_transfer
        ixgbe: Fix crash with VFs and flow director on interface flap
        IB/mthca: Fix error return code in __mthca_init_one()
        ata: ep93xx: Use proper enums for directions
        ALSA: hda/sigmatel - Disable automute for Elo VuPoint
        KVM: PPC: Book3S PR: Exiting split hack mode needs to fixup both PC and LR
        USB: serial: cypress_m8: fix interrupt-out transfer length
        mtd: physmap_of: Release resources on error
        brcmfmac: fix full timeout waiting for action frame on-channel tx
        NFSv4.x: fix lock recovery during delegation recall
        dmaengine: ioat: fix prototype of ioat_enumerate_channels
        Input: st1232 - set INPUT_PROP_DIRECT property
        x86/olpc: Fix build error with CONFIG_MFD_CS5535=m
        crypto: mxs-dcp - Fix SHA null hashes and output length
        crypto: mxs-dcp - Fix AES issues
        ACPI / SBS: Fix rare oops when removing modules
        fbdev: sbuslib: use checked version of put_user()
        fbdev: sbuslib: integer overflow in sbusfb_ioctl_helper()
        bcache: recal cached_dev_sectors on detach
        proc/vmcore: Fix i386 build error of missing copy_oldmem_page_encrypted()
        backlight: lm3639: Unconditionally call led_classdev_unregister
        printk: Give error on attempt to set log buffer length to over 2G
        media: isif: fix a NULL pointer dereference bug
        GFS2: Flush the GFS2 delete workqueue before stopping the kernel threads
        media: cx231xx: fix potential sign-extension overflow on large shift
        x86/kexec: Correct KEXEC_BACKUP_SRC_END off-by-one error
        gpio: syscon: Fix possible NULL ptr usage
        spi: spidev: Fix OF tree warning logic
        ARM: 8802/1: Call syscall_trace_exit even when system call skipped
        hwmon: (pwm-fan) Silence error on probe deferral
        mac80211: minstrel: fix CCK rate group streams value
        spi: rockchip: initialize dma_slave_config properly
        arm64: uaccess: Ensure PAN is re-enabled after unhandled uaccess fault
        Linux 4.4.203

Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>

Conflicts:
	include/linux/libfdt_env.h
2019-11-25 10:15:14 -07:00
Eric W. Biederman
dc9c09f5ed signal: Properly deliver SIGILL from uprobes
[ Upstream commit 55a3235fc71bf34303e34a95eeee235b2d2a35dd ]

For userspace to tell the difference between a random signal and an
exception, the exception must include siginfo information.

Using SEND_SIG_FORCED for SIGILL is thus wrong, and it will result
in userspace seeing si_code == SI_USER (like a random signal) instead
of si_code == SI_KERNEL or a more specific si_code as all exceptions
deliver.

Therefore replace force_sig_info(SIGILL, SEND_SIG_FORCE, current)
with force_sig(SIG_ILL, current) which gets this right and is
shorter and easier to type.

Fixes: 014940bad8 ("uprobes/x86: Send SIGILL if arch_uprobe_post_xol() fails")
Fixes: 0b5256c7f1 ("uprobes: Send SIGILL if handle_trampoline() fails")
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2019-11-25 15:53:52 +01:00
Nathan Chancellor
c9a29e2bc4 Merge 4.4.190 into android-msm-wahoo-4.4
Changes in 4.4.190: (79 commits)
        usb: iowarrior: fix deadlock on disconnect
        sound: fix a memory leak bug
        x86/mm: Check for pfn instead of page in vmalloc_sync_one()
        x86/mm: Sync also unmappings in vmalloc_sync_all()
        mm/vmalloc: Sync unmappings in __purge_vmap_area_lazy()
        perf db-export: Fix thread__exec_comm()
        usb: yurex: Fix use-after-free in yurex_delete
        can: peak_usb: fix potential double kfree_skb()
        netfilter: nfnetlink: avoid deadlock due to synchronous request_module
        iscsi_ibft: make ISCSI_IBFT dependson ACPI instead of ISCSI_IBFT_FIND
        mac80211: don't warn about CW params when not using them
        hwmon: (nct6775) Fix register address and added missed tolerance for nct6106
        cpufreq/pasemi: fix use-after-free in pas_cpufreq_cpu_init()
        s390/qdio: add sanity checks to the fast-requeue path
        ALSA: compress: Fix regression on compressed capture streams
        ALSA: compress: Prevent bypasses of set_params
        ALSA: compress: Be more restrictive about when a drain is allowed
        perf probe: Avoid calling freeing routine multiple times for same pointer
        ARM: davinci: fix sleep.S build error on ARMv4
        scsi: megaraid_sas: fix panic on loading firmware crashdump
        scsi: ibmvfc: fix WARN_ON during event pool release
        tty/ldsem, locking/rwsem: Add missing ACQUIRE to read_failed sleep loop
        perf/core: Fix creating kernel counters for PMUs that override event->cpu
        can: peak_usb: pcan_usb_pro: Fix info-leaks to USB devices
        can: peak_usb: pcan_usb_fd: Fix info-leaks to USB devices
        hwmon: (nct7802) Fix wrong detection of in4 presence
        ALSA: firewire: fix a memory leak bug
        mac80211: don't WARN on short WMM parameters from AP
        SMB3: Fix deadlock in validate negotiate hits reconnect
        smb3: send CAP_DFS capability during session setup
        mwifiex: fix 802.11n/WPA detection
        scsi: mpt3sas: Use 63-bit DMA addressing on SAS35 HBA
        sh: kernel: hw_breakpoint: Fix missing break in switch statement
        usb: gadget: f_midi: fail if set_alt fails to allocate requests
        USB: gadget: f_midi: fixing a possible double-free in f_midi
        mm/memcontrol.c: fix use after free in mem_cgroup_iter()
        ALSA: hda - Fix a memory leak bug
        HID: holtek: test for sanity of intfdata
        HID: hiddev: avoid opening a disconnected device
        HID: hiddev: do cleanup in failure of opening a device
        Input: kbtab - sanity check for endpoint type
        Input: iforce - add sanity checks
        net: usb: pegasus: fix improper read if get_registers() fail
        xen/pciback: remove set but not used variable 'old_state'
        irqchip/irq-imx-gpcv2: Forward irq type to parent
        perf header: Fix divide by zero error if f_header.attr_size==0
        perf header: Fix use of unitialized value warning
        libata: zpodd: Fix small read overflow in zpodd_get_mech_type()
        scsi: hpsa: correct scsi command status issue after reset
        ata: libahci: do not complain in case of deferred probe
        kbuild: modpost: handle KBUILD_EXTRA_SYMBOLS only for external modules
        IB/core: Add mitigation for Spectre V1
        ocfs2: remove set but not used variable 'last_hash'
        asm-generic: fix -Wtype-limits compiler warnings
        staging: comedi: dt3000: Fix signed integer overflow 'divider * base'
        staging: comedi: dt3000: Fix rounding up of timer divisor
        USB: core: Fix races in character device registration and deregistraion
        usb: cdc-acm: make sure a refcount is taken early enough
        USB: serial: option: add D-Link DWM-222 device ID
        USB: serial: option: Add support for ZTE MF871A
        USB: serial: option: add the BroadMobi BM818 card
        USB: serial: option: Add Motorola modem UARTs
        Backport minimal compiler_attributes.h to support GCC 9
        include/linux/module.h: copy __init/__exit attrs to init/cleanup_module
        arm64: compat: Allow single-byte watchpoints on all addresses
        Input: psmouse - fix build error of multiple definition
        asm-generic: default BUG_ON(x) to if(x)BUG()
        scsi: fcoe: Embed fc_rport_priv in fcoe_rport structure
        RDMA: Directly cast the sockaddr union to sockaddr
        IB/mlx5: Make coding style more consistent
        x86/vdso: Remove direct HPET access through the vDSO
        iommu/amd: Move iommu_init_pci() to .init section
        x86/boot: Disable the address-of-packed-member compiler warning
        net/packet: fix race in tpacket_snd()
        xen/netback: Reset nr_frags before freeing skb
        net/mlx5e: Only support tx/rx pause setting for port owner
        sctp: fix the transport error_count check
        bonding: Add vlan tx offload to hw_enc_features
        Linux 4.4.190

Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>

Conflicts:
	sound/core/compress_offload.c
2019-08-25 08:22:16 -07:00
Leonard Crestez
821bc02558 perf/core: Fix creating kernel counters for PMUs that override event->cpu
[ Upstream commit 4ce54af8b33d3e21ca935fc1b89b58cbba956051 ]

Some hardware PMU drivers will override perf_event.cpu inside their
event_init callback. This causes a lockdep splat when initialized through
the kernel API:

 WARNING: CPU: 0 PID: 250 at kernel/events/core.c:2917 ctx_sched_out+0x78/0x208
 pc : ctx_sched_out+0x78/0x208
 Call trace:
  ctx_sched_out+0x78/0x208
  __perf_install_in_context+0x160/0x248
  remote_function+0x58/0x68
  generic_exec_single+0x100/0x180
  smp_call_function_single+0x174/0x1b8
  perf_install_in_context+0x178/0x188
  perf_event_create_kernel_counter+0x118/0x160

Fix this by calling perf_install_in_context with event->cpu, just like
perf_event_open

Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Frank Li <Frank.li@nxp.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Will Deacon <will@kernel.org>
Link: https://lkml.kernel.org/r/c4ebe0503623066896d7046def4d6b1e06e0eb2e.1563972056.git.leonard.crestez@nxp.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2019-08-25 10:52:51 +02:00
Nathan Chancellor
8fe21d8adf Merge 4.4.186 into android-msm-wahoo-4.4
Changes in 4.4.186: (41 commits)
        Input: elantech - enable middle button support on 2 ThinkPads
        samples, bpf: fix to change the buffer size for read()
        mac80211: mesh: fix RCU warning
        mwifiex: Fix possible buffer overflows at parsing bss descriptor
        dt-bindings: can: mcp251x: add mcp25625 support
        can: mcp251x: add support for mcp25625
        Input: imx_keypad - make sure keyboard can always wake up system
        ARM: davinci: da850-evm: call regulator_has_full_constraints()
        ARM: davinci: da8xx: specify dma_coherent_mask for lcdc
        md: fix for divide error in status_resync
        bnx2x: Check if transceiver implements DDM before access
        udf: Fix incorrect final NOT_ALLOCATED (hole) extent length
        x86/ptrace: Fix possible spectre-v1 in ptrace_get_debugreg()
        x86/tls: Fix possible spectre-v1 in do_get_thread_area()
        mwifiex: Abort at too short BSS descriptor element
        mwifiex: Fix heap overflow in mwifiex_uap_parse_tail_ies()
        fscrypt: don't set policy for a dead directory
        mwifiex: Don't abort on small, spec-compliant vendor IEs
        USB: serial: ftdi_sio: add ID for isodebug v1
        USB: serial: option: add support for GosunCn ME3630 RNDIS mode
        usb: gadget: ether: Fix race between gether_disconnect and rx_submit
        usb: renesas_usbhs: add a workaround for a race condition of workqueue
        staging: comedi: dt282x: fix a null pointer deref on interrupt
        staging: comedi: amplc_pci230: fix null pointer deref on interrupt
        carl9170: fix misuse of device driver API
        VMCI: Fix integer overflow in VMCI handle arrays
        MIPS: Remove superfluous check for __linux__
        e1000e: start network tx queue only when link is up
        perf/core: Fix perf_sample_regs_user() mm check
        ARM: omap2: remove incorrect __init annotation
        be2net: fix link failure after ethtool offline test
        ppp: mppe: Add softdep to arc4
        sis900: fix TX completion
        dm verity: use message limit for data block corruption message
        kvm: x86: avoid warning on repeated KVM_SET_TSS_ADDR
        ARC: hide unused function unw_hdr_alloc
        s390: fix stfle zero padding
        s390/qdio: (re-)initialize tiqdio list entries
        s390/qdio: don't touch the dsci in tiqdio_add_input_queues()
        KVM: x86: protect KVM_CREATE_PIT/KVM_CREATE_PIT2 with kvm->lock
        Linux 4.4.186

Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
2019-07-21 00:35:38 -07:00
Peter Zijlstra
df37b30f96 perf/core: Fix perf_sample_regs_user() mm check
[ Upstream commit 085ebfe937d7a7a5df1729f35a12d6d655fea68c ]

perf_sample_regs_user() uses 'current->mm' to test for the presence of
userspace, but this is insufficient, consider use_mm().

A better test is: '!(current->flags & PF_KTHREAD)', exec() clears
PF_KTHREAD after it sets the new ->mm but before it drops to userspace
for the first time.

Possibly obsoletes: bf05fc25f268 ("powerpc/perf: Fix oops when kthread execs user process")

Reported-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
Reported-by: Young Xiao <92siuyang@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Will Deacon <will.deacon@arm.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Fixes: 4018994f3d ("perf: Add ability to attach user level registers dump to sample")
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2019-07-21 09:07:12 +02:00
Nathan Chancellor
2458b36258 Merge 4.4.183 into android-msm-wahoo-4.4
Changes in 4.4.183: (85 commits)
        fs/fat/file.c: issue flush after the writeback of FAT
        sysctl: return -EINVAL if val violates minmax
        ipc: prevent lockup on alloc_msg and free_msg
        hugetlbfs: on restore reserve error path retain subpool reservation
        mm/cma.c: fix crash on CMA allocation if bitmap allocation fails
        mm/cma_debug.c: fix the break condition in cma_maxchunk_get()
        kernel/sys.c: prctl: fix false positive in validate_prctl_map()
        mfd: intel-lpss: Set the device in reset state when init
        mfd: twl6040: Fix device init errors for ACCCTL register
        perf/x86/intel: Allow PEBS multi-entry in watermark mode
        drm/bridge: adv7511: Fix low refresh rate selection
        ntp: Allow TAI-UTC offset to be set to zero
        f2fs: fix to avoid panic in do_recover_data()
        f2fs: fix to do sanity check on valid block count of segment
        iommu/vt-d: Set intel_iommu_gfx_mapped correctly
        ALSA: hda - Register irq handler after the chip initialization
        nvmem: core: fix read buffer in place
        fuse: retrieve: cap requested size to negotiated max_write
        nfsd: allow fh_want_write to be called twice
        x86/PCI: Fix PCI IRQ routing table memory leak
        platform/chrome: cros_ec_proto: check for NULL transfer function
        soc: mediatek: pwrap: Zero initialize rdata in pwrap_init_cipher
        clk: rockchip: Turn on "aclk_dmac1" for suspend on rk3288
        ARM: dts: imx6sx: Specify IMX6SX_CLK_IPG as "ahb" clock to SDMA
        ARM: dts: imx6sx: Specify IMX6SX_CLK_IPG as "ipg" clock to SDMA
        ARM: dts: imx6qdl: Specify IMX6QDL_CLK_IPG as "ipg" clock to SDMA
        PCI: rpadlpar: Fix leaked device_node references in add/remove paths
        PCI: rcar: Fix a potential NULL pointer dereference
        video: hgafb: fix potential NULL pointer dereference
        video: imsttfb: fix potential NULL pointer dereferences
        PCI: xilinx: Check for __get_free_pages() failure
        gpio: gpio-omap: add check for off wake capable gpios
        dmaengine: idma64: Use actual device for DMA transfers
        pwm: tiehrpwm: Update shadow register for disabling PWMs
        ARM: dts: exynos: Always enable necessary APIO_1V8 and ABB_1V8 regulators on Arndale Octa
        pwm: Fix deadlock warning when removing PWM device
        ARM: exynos: Fix undefined instruction during Exynos5422 resume
        futex: Fix futex lock the wrong page
        Revert "Bluetooth: Align minimum encryption key size for LE and BR/EDR connections"
        ALSA: seq: Cover unsubscribe_port() in list_mutex
        libata: Extend quirks for the ST1000LM024 drives with NOLPM quirk
        mm/list_lru.c: fix memory leak in __memcg_init_list_lru_node
        fs/ocfs2: fix race in ocfs2_dentry_attach_lock()
        signal/ptrace: Don't leak unitialized kernel memory with PTRACE_PEEK_SIGINFO
        ptrace: restore smp_rmb() in __ptrace_may_access()
        i2c: acorn: fix i2c warning
        bcache: fix stack corruption by PRECEDING_KEY()
        cgroup: Use css_tryget() instead of css_tryget_online() in task_get_css()
        ASoC: cs42xx8: Add regcache mask dirty
        Drivers: misc: fix out-of-bounds access in function param_set_kgdbts_var
        scsi: lpfc: add check for loss of ndlp when sending RRQ
        scsi: bnx2fc: fix incorrect cast to u64 on shift operation
        usbnet: ipheth: fix racing condition
        KVM: x86/pmu: do not mask the value that is written to fixed PMUs
        KVM: s390: fix memory slot handling for KVM_SET_USER_MEMORY_REGION
        drm/vmwgfx: integer underflow in vmw_cmd_dx_set_shader() leading to an invalid read
        drm/vmwgfx: NULL pointer dereference from vmw_cmd_dx_view_define()
        USB: Fix chipmunk-like voice when using Logitech C270 for recording audio.
        USB: usb-storage: Add new ID to ums-realtek
        USB: serial: pl2303: add Allied Telesis VT-Kit3
        USB: serial: option: add support for Simcom SIM7500/SIM7600 RNDIS mode
        USB: serial: option: add Telit 0x1260 and 0x1261 compositions
        ax25: fix inconsistent lock state in ax25_destroy_timer
        be2net: Fix number of Rx queues used for flow hashing
        ipv6: flowlabel: fl6_sock_lookup() must use atomic_inc_not_zero
        lapb: fixed leak of control-blocks.
        neigh: fix use-after-free read in pneigh_get_next
        sunhv: Fix device naming inconsistency between sunhv_console and sunhv_reg
        mISDN: make sure device name is NUL terminated
        x86/CPU/AMD: Don't force the CPB cap when running under a hypervisor
        perf/ring_buffer: Fix exposing a temporarily decreased data_head
        perf/ring_buffer: Add ordering to rb->nest increment
        gpio: fix gpio-adp5588 build errors
        net: tulip: de4x5: Drop redundant MODULE_DEVICE_TABLE()
        i2c: dev: fix potential memory leak in i2cdev_ioctl_rdwr
        configfs: Fix use-after-free when accessing sd->s_dentry
        ia64: fix build errors by exporting paddr_to_nid()
        KVM: PPC: Book3S: Use new mutex to synchronize access to rtas token list
        net: sh_eth: fix mdio access in sh_eth_close() for R-Car Gen2 and RZ/A1 SoCs
        scsi: libcxgbi: add a check for NULL pointer in cxgbi_check_route()
        scsi: libsas: delete sas port if expander discover failed
        Revert "crypto: crypto4xx - properly set IV after de- and encrypt"
        coredump: fix race condition between mmget_not_zero()/get_task_mm() and core dumping
        Abort file_remove_privs() for non-reg. files
        Linux 4.4.183

Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>

Conflicts:
	drivers/android/binder.c
2019-06-22 12:48:42 -07:00
Peter Zijlstra
dd961efe8d perf/ring_buffer: Add ordering to rb->nest increment
[ Upstream commit 3f9fbe9bd86c534eba2faf5d840fd44c6049f50e ]

Similar to how decrementing rb->next too early can cause data_head to
(temporarily) be observed to go backward, so too can this happen when
we increment too late.

This barrier() ensures the rb->head load happens after the increment,
both the one in the 'goto again' path, as the one from
perf_output_get_handle() -- albeit very unlikely to matter for the
latter.

Suggested-by: Yabin Cui <yabinc@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: acme@kernel.org
Cc: mark.rutland@arm.com
Cc: namhyung@kernel.org
Fixes: ef60777c9a ("perf: Optimize the perf_output() path by removing IRQ-disables")
Link: http://lkml.kernel.org/r/20190517115418.309516009@infradead.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2019-06-22 08:18:26 +02:00
Yabin Cui
8abd8a9a97 perf/ring_buffer: Fix exposing a temporarily decreased data_head
[ Upstream commit 1b038c6e05ff70a1e66e3e571c2e6106bdb75f53 ]

In perf_output_put_handle(), an IRQ/NMI can happen in below location and
write records to the same ring buffer:

	...
	local_dec_and_test(&rb->nest)
	...                          <-- an IRQ/NMI can happen here
	rb->user_page->data_head = head;
	...

In this case, a value A is written to data_head in the IRQ, then a value
B is written to data_head after the IRQ. And A > B. As a result,
data_head is temporarily decreased from A to B. And a reader may see
data_head < data_tail if it read the buffer frequently enough, which
creates unexpected behaviors.

This can be fixed by moving dec(&rb->nest) to after updating data_head,
which prevents the IRQ/NMI above from updating data_head.

[ Split up by peterz. ]

Signed-off-by: Yabin Cui <yabinc@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: mark.rutland@arm.com
Fixes: ef60777c9a ("perf: Optimize the perf_output() path by removing IRQ-disables")
Link: http://lkml.kernel.org/r/20190517115418.224478157@infradead.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2019-06-22 08:18:25 +02:00
Nathan Chancellor
79a097e001 Merge 4.4.179 into android-msm-wahoo-4.4
Changes in 4.4.179: (170 commits)
        arm64: debug: Don't propagate UNKNOWN FAR into si_code for debug signals
        arm64: debug: Ensure debug handlers check triggering exception level
        ext4: cleanup bh release code in ext4_ind_remove_space()
        lib/int_sqrt: optimize initial value compute
        tty/serial: atmel: Add is_half_duplex helper
        mm: mempolicy: make mbind() return -EIO when MPOL_MF_STRICT is specified
        i2c: core-smbus: prevent stack corruption on read I2C_BLOCK_DATA
        Bluetooth: Fix decrementing reference count twice in releasing socket
        tty/serial: atmel: RS485 HD w/DMA: enable RX after TX is stopped
        CIFS: fix POSIX lock leak and invalid ptr deref
        h8300: use cc-cross-prefix instead of hardcoding h8300-unknown-linux-
        tracing: kdb: Fix ftdump to not sleep
        gpio: gpio-omap: fix level interrupt idling
        sysctl: handle overflow for file-max
        enic: fix build warning without CONFIG_CPUMASK_OFFSTACK
        mm/cma.c: cma_declare_contiguous: correct err handling
        mm/page_ext.c: fix an imbalance with kmemleak
        mm/vmalloc.c: fix kernel BUG at mm/vmalloc.c:512!
        mm/slab.c: kmemleak no scan alien caches
        ocfs2: fix a panic problem caused by o2cb_ctl
        f2fs: do not use mutex lock in atomic context
        fs/file.c: initialize init_files.resize_wait
        cifs: use correct format characters
        dm thin: add sanity checks to thin-pool and external snapshot creation
        cifs: Fix NULL pointer dereference of devname
        fs: fix guard_bio_eod to check for real EOD errors
        tools lib traceevent: Fix buffer overflow in arg_eval
        usb: chipidea: Grab the (legacy) USB PHY by phandle first
        scsi: core: replace GFP_ATOMIC with GFP_KERNEL in scsi_scan.c
        coresight: etm4x: Add support to enable ETMv4.2
        ARM: 8840/1: use a raw_spinlock_t in unwind
        mmc: omap: fix the maximum timeout setting
        e1000e: Fix -Wformat-truncation warnings
        IB/mlx4: Increase the timeout for CM cache
        scsi: megaraid_sas: return error when create DMA pool failed
        perf test: Fix failure of 'evsel-tp-sched' test on s390
        SoC: imx-sgtl5000: add missing put_device()
        media: sh_veu: Correct return type for mem2mem buffer helpers
        media: s5p-jpeg: Correct return type for mem2mem buffer helpers
        media: s5p-g2d: Correct return type for mem2mem buffer helpers
        media: mx2_emmaprp: Correct return type for mem2mem buffer helpers
        leds: lp55xx: fix null deref on firmware load failure
        kprobes: Prohibit probing on bsearch()
        ARM: 8833/1: Ensure that NEON code always compiles with Clang
        ALSA: PCM: check if ops are defined before suspending PCM
        bcache: fix input overflow to cache set sysfs file io_error_halflife
        bcache: fix input overflow to sequential_cutoff
        bcache: improve sysfs_strtoul_clamp()
        fbdev: fbmem: fix memory access if logo is bigger than the screen
        cdrom: Fix race condition in cdrom_sysctl_register
        ASoC: fsl-asoc-card: fix object reference leaks in fsl_asoc_card_probe
        soc: qcom: gsbi: Fix error handling in gsbi_probe()
        mt7601u: bump supported EEPROM version
        ARM: avoid Cortex-A9 livelock on tight dmb loops
        tty: increase the default flip buffer limit to 2*640K
        media: mt9m111: set initial frame size other than 0x0
        hwrng: virtio - Avoid repeated init of completion
        soc/tegra: fuse: Fix illegal free of IO base address
        hpet: Fix missing '=' character in the __setup() code of hpet_mmap_enable
        dmaengine: imx-dma: fix warning comparison of distinct pointer types
        netfilter: physdev: relax br_netfilter dependency
        media: s5p-jpeg: Check for fmt_ver_flag when doing fmt enumeration
        regulator: act8865: Fix act8600_sudcdc_voltage_ranges setting
        wlcore: Fix memory leak in case wl12xx_fetch_firmware failure
        x86/build: Mark per-CPU symbols as absolute explicitly for LLD
        dmaengine: tegra: avoid overflow of byte tracking
        drm/dp/mst: Configure no_stop_bit correctly for remote i2c xfers
        binfmt_elf: switch to new creds when switching to new mm
        kbuild: clang: choose GCC_TOOLCHAIN_DIR not on LD
        x86/build: Specify elf_i386 linker emulation explicitly for i386 objects
        x86: vdso: Use $LD instead of $CC to link
        x86/vdso: Drop implicit common-page-size linker flag
        lib/string.c: implement a basic bcmp
        tty: mark Siemens R3964 line discipline as BROKEN
        tty: ldisc: add sysctl to prevent autoloading of ldiscs
        ipv6: Fix dangling pointer when ipv6 fragment
        ipv6: sit: reset ip header pointer in ipip6_rcv
        net: rds: force to destroy connection if t_sock is NULL in rds_tcp_kill_sock().
        openvswitch: fix flow actions reallocation
        qmi_wwan: add Olicard 600
        sctp: initialize _pad of sockaddr_in before copying to user memory
        tcp: Ensure DCTCP reacts to losses
        netns: provide pure entropy for net_hash_mix()
        net: ethtool: not call vzalloc for zero sized memory request
        ip6_tunnel: Match to ARPHRD_TUNNEL6 for dev type
        ALSA: seq: Fix OOB-reads from strlcpy
        include/linux/bitrev.h: fix constant bitrev
        ASoC: fsl_esai: fix channel swap issue when stream starts
        block: do not leak memory in bio_copy_user_iov()
        genirq: Respect IRQCHIP_SKIP_SET_WAKE in irq_chip_set_wake_parent()
        ARM: dts: at91: Fix typo in ISC_D0 on PC9
        arm64: futex: Fix FUTEX_WAKE_OP atomic ops with non-zero result value
        xen: Prevent buffer overflow in privcmd ioctl
        sched/fair: Do not re-read ->h_load_next during hierarchical load calculation
        xtensa: fix return_address
        PCI: Add function 1 DMA alias quirk for Marvell 9170 SATA controller
        perf/core: Restore mmap record type correctly
        ext4: add missing brelse() in add_new_gdb_meta_bg()
        ext4: report real fs size after failed resize
        ALSA: echoaudio: add a check for ioremap_nocache
        ALSA: sb8: add a check for request_region
        IB/mlx4: Fix race condition between catas error reset and aliasguid flows
        mmc: davinci: remove extraneous __init annotation
        ALSA: opl3: fix mismatch between snd_opl3_drum_switch definition and declaration
        thermal/int340x_thermal: Add additional UUIDs
        thermal/int340x_thermal: fix mode setting
        tools/power turbostat: return the exit status of a command
        perf top: Fix error handling in cmd_top()
        perf evsel: Free evsel->counts in perf_evsel__exit()
        perf tests: Fix a memory leak of cpu_map object in the openat_syscall_event_on_all_cpus test
        perf tests: Fix a memory leak in test__perf_evsel__tp_sched_test()
        x86/hpet: Prevent potential NULL pointer dereference
        x86/cpu/cyrix: Use correct macros for Cyrix calls on Geode processors
        iommu/vt-d: Check capability before disabling protected memory
        x86/hw_breakpoints: Make default case in hw_breakpoint_arch_parse() return an error
        fix incorrect error code mapping for OBJECTID_NOT_FOUND
        ext4: prohibit fstrim in norecovery mode
        rsi: improve kernel thread handling to fix kernel panic
        9p: do not trust pdu content for stat item size
        9p locks: add mount option for lock retry interval
        f2fs: fix to do sanity check with current segment number
        serial: uartps: console_setup() can't be placed to init section
        ARM: samsung: Limit SAMSUNG_PM_CHECK config option to non-Exynos platforms
        ACPI / SBS: Fix GPE storm on recent MacBookPro's
        cifs: fallback to older infolevels on findfirst queryinfo retry
        crypto: sha256/arm - fix crash bug in Thumb2 build
        crypto: sha512/arm - fix crash bug in Thumb2 build
        iommu/dmar: Fix buffer overflow during PCI bus notification
        ARM: 8839/1: kprobe: make patch_lock a raw_spinlock_t
        appletalk: Fix use-after-free in atalk_proc_exit
        lib/div64.c: off by one in shift
        include/linux/swap.h: use offsetof() instead of custom __swapoffset macro
        tpm/tpm_crb: Avoid unaligned reads in crb_recv()
        ovl: fix uid/gid when creating over whiteout
        appletalk: Fix compile regression
        bonding: fix event handling for stacked bonds
        net: atm: Fix potential Spectre v1 vulnerabilities
        net: bridge: multicast: use rcu to access port list from br_multicast_start_querier
        net: fou: do not use guehdr after iptunnel_pull_offloads in gue_udp_recv
        tcp: tcp_grow_window() needs to respect tcp_space()
        ipv4: recompile ip options in ipv4_link_failure
        ipv4: ensure rcu_read_lock() in ipv4_link_failure()
        crypto: crypto4xx - properly set IV after de- and encrypt
        modpost: file2alias: go back to simple devtable lookup
        modpost: file2alias: check prototype of handler
        tpm/tpm_i2c_atmel: Return -E2BIG when the transfer is incomplete
        KVM: x86: Don't clear EFER during SMM transitions for 32-bit vCPU
        iio/gyro/bmg160: Use millidegrees for temperature scale
        iio: ad_sigma_delta: select channel when reading register
        iio: adc: at91: disable adc channel interrupt in timeout case
        io: accel: kxcjk1013: restore the range after resume.
        staging: comedi: vmk80xx: Fix use of uninitialized semaphore
        staging: comedi: vmk80xx: Fix possible double-free of ->usb_rx_buf
        staging: comedi: ni_usb6501: Fix use of uninitialized mutex
        staging: comedi: ni_usb6501: Fix possible double-free of ->usb_rx_buf
        ALSA: core: Fix card races between register and disconnect
        crypto: x86/poly1305 - fix overflow during partial reduction
        arm64: futex: Restore oldval initialization to work around buggy compilers
        x86/kprobes: Verify stack frame on kretprobe
        kprobes: Mark ftrace mcount handler functions nokprobe
        kprobes: Fix error check when reusing optimized probes
        mac80211: do not call driver wake_tx_queue op during reconfig
        Revert "kbuild: use -Oz instead of -Os when using clang"
        sched/fair: Limit sched_cfs_period_timer() loop to avoid hard lockup
        device_cgroup: fix RCU imbalance in error case
        mm/vmstat.c: fix /proc/vmstat format for CONFIG_DEBUG_TLBFLUSH=y CONFIG_SMP=n
        ALSA: info: Fix racy addition/deletion of nodes
        Revert "locking/lockdep: Add debug_locks check in __lock_downgrade()"
        kernel/sysctl.c: fix out-of-bounds access when setting file-max
        Linux 4.4.179

Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>

Conflicts:
	Makefile
	fs/ext4/ioctl.c
2019-04-27 09:07:11 -07:00
Stephane Eranian
e92dc325a5 perf/core: Restore mmap record type correctly
[ Upstream commit d9c1bb2f6a2157b38e8eb63af437cb22701d31ee ]

On mmap(), perf_events generates a RECORD_MMAP record and then checks
which events are interested in this record. There are currently 2
versions of mmap records: RECORD_MMAP and RECORD_MMAP2. MMAP2 is larger.
The event configuration controls which version the user level tool
accepts.

If the event->attr.mmap2=1 field then MMAP2 record is returned.  The
perf_event_mmap_output() takes care of this. It checks attr->mmap2 and
corrects the record fields before putting it in the sampling buffer of
the event.  At the end the function restores the modified MMAP record
fields.

The problem is that the function restores the size but not the type.
Thus, if a subsequent event only accepts MMAP type, then it would
instead receive an MMAP2 record with a size of MMAP record.

This patch fixes the problem by restoring the record type on exit.

Signed-off-by: Stephane Eranian <eranian@google.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Fixes: 13d7a2410f ("perf: Add attr->mmap2 attribute to an event")
Link: http://lkml.kernel.org/r/20190307185233.225521-1-eranian@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2019-04-27 09:33:56 +02:00
Alexander Shishkin
2ba2cca736 perf/ring_buffer: Refuse to begin AUX transaction after rb->aux_mmap_count drops
[ Upstream commit dcb10a967ce82d5ad20570693091139ae716ff76 ]

When ring buffer's AUX area is unmapped and rb->aux_mmap_count drops to
zero, new AUX transactions into this buffer can still be started,
even though the buffer in en route to deallocation.

This patch adds a check to perf_aux_output_begin() for rb->aux_mmap_count
being zero, in which case there is no point starting new transactions,
in other words, the ring buffers that pass a certain point in
perf_mmap_close will not have their events sending new data, which
clears path for freeing those buffers' pages right there and then,
provided that no active transactions are holding the AUX reference.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: vince@deater.net
Link: http://lkml.kernel.org/r/1457098969-21595-2-git-send-email-alexander.shishkin@linux.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2019-04-03 06:23:23 +02:00
Alexander Shishkin
6f311381f3 perf: Synchronously free aux pages in case of allocation failure
[ Upstream commit 45c815f06b80031659c63d7b93e580015d6024dd ]

We are currently using asynchronous deallocation in the error path in
AUX mmap code, which is unnecessary and also presents a problem for users
that wish to probe for the biggest possible buffer size they can get:
they'll get -EINVAL on all subsequent attemts to allocate a smaller
buffer before the asynchronous deallocation callback frees up the pages
from the previous unsuccessful attempt.

Currently, gdb does that for allocating AUX buffers for Intel PT traces.
More specifically, overwrite mode of AUX pmus that don't support hardware
sg (some implementations of Intel PT, for instance) is limited to only
one contiguous high order allocation for its buffer and there is no way
of knowing its size without trying.

This patch changes error path freeing to be synchronous as there won't
be any contenders for the AUX pages at that point.

Reported-by: Markus Metzger <markus.t.metzger@intel.com>
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@infradead.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: vince@deater.net
Link: http://lkml.kernel.org/r/1453216469-9509-1-git-send-email-alexander.shishkin@linux.intel.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2019-04-03 06:23:21 +02:00
Nathan Chancellor
9d7c207ebd Merge tag 'android-9.0.0_r0.72' into android-msm-wahoo-4.4
Android 9.0.0 Release 0.72

* tag 'android-9.0.0_r0.72':
  perf: Cancel the mux hrtimer during CPU hotplug to avoid migration
  qcacld-3.0: Add data validation for avoid frequency command

Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
2019-04-01 12:45:01 -07:00
Nathan Chancellor
b4daa97401 Merge 4.4.175 into android-msm-wahoo-4.4
Changes in 4.4.175: (144 commits)
        drm/bufs: Fix Spectre v1 vulnerability
        staging: iio: adc: ad7280a: handle error from __ad7280_read32()
        ASoC: Intel: mrfld: fix uninitialized variable access
        scsi: lpfc: Correct LCB RJT handling
        ARM: 8808/1: kexec:offline panic_smp_self_stop CPU
        dlm: Don't swamp the CPU with callbacks queued during recovery
        x86/PCI: Fix Broadcom CNB20LE unintended sign extension (redux)
        powerpc/pseries: add of_node_put() in dlpar_detach_node()
        serial: fsl_lpuart: clear parity enable bit when disable parity
        ptp: check gettime64 return code in PTP_SYS_OFFSET ioctl
        staging:iio:ad2s90: Make probe handle spi_setup failure
        staging: iio: ad7780: update voltage on read
        ARM: OMAP2+: hwmod: Fix some section annotations
        modpost: validate symbol names also in find_elf_symbol
        perf tools: Add Hygon Dhyana support
        soc/tegra: Don't leak device tree node reference
        f2fs: move dir data flush to write checkpoint process
        f2fs: fix wrong return value of f2fs_acl_create
        sunvdc: Do not spin in an infinite loop when vio_ldc_send() returns EAGAIN
        nfsd4: fix crash on writing v4_end_grace before nfsd startup
        arm64: ftrace: don't adjust the LR value
        ARM: dts: mmp2: fix TWSI2
        x86/fpu: Add might_fault() to user_insn()
        media: DaVinci-VPBE: fix error handling in vpbe_initialize()
        smack: fix access permissions for keyring
        usb: hub: delay hub autosuspend if USB3 port is still link training
        timekeeping: Use proper seqcount initializer
        ARM: dts: Fix OMAP4430 SDP Ethernet startup
        mips: bpf: fix encoding bug for mm_srlv32_op
        iommu/arm-smmu-v3: Use explicit mb() when moving cons pointer
        sata_rcar: fix deferred probing
        clk: imx6sl: ensure MMDC CH0 handshake is bypassed
        cpuidle: big.LITTLE: fix refcount leak
        i2c-axxia: check for error conditions first
        udf: Fix BUG on corrupted inode
        ARM: pxa: avoid section mismatch warning
        ASoC: fsl: Fix SND_SOC_EUKREA_TLV320 build error on i.MX8M
        memstick: Prevent memstick host from getting runtime suspended during card detection
        tty: serial: samsung: Properly set flags in autoCTS mode
        arm64: KVM: Skip MMIO insn after emulation
        powerpc/uaccess: fix warning/error with access_ok()
        mac80211: fix radiotap vendor presence bitmap handling
        xfrm6_tunnel: Fix spi check in __xfrm6_tunnel_alloc_spi
        Bluetooth: Fix unnecessary error message for HCI request completion
        cw1200: Fix concurrency use-after-free bugs in cw1200_hw_scan()
        drbd: narrow rcu_read_lock in drbd_sync_handshake
        drbd: disconnect, if the wrong UUIDs are attached on a connected peer
        drbd: skip spurious timeout (ping-timeo) when failing promote
        drbd: Avoid Clang warning about pointless switch statment
        video: clps711x-fb: release disp device node in probe()
        fbdev: fbmem: behave better with small rotated displays and many CPUs
        igb: Fix an issue that PME is not enabled during runtime suspend
        fbdev: fbcon: Fix unregister crash when more than one framebuffer
        KVM: x86: svm: report MSR_IA32_MCG_EXT_CTL as unsupported
        NFS: nfs_compare_mount_options always compare auth flavors.
        hwmon: (lm80) fix a missing check of the status of SMBus read
        hwmon: (lm80) fix a missing check of bus read in lm80 probe
        seq_buf: Make seq_buf_puts() null-terminate the buffer
        crypto: ux500 - Use proper enum in cryp_set_dma_transfer
        crypto: ux500 - Use proper enum in hash_set_dma_transfer
        cifs: check ntwrk_buf_start for NULL before dereferencing it
        um: Avoid marking pages with "changed protection"
        niu: fix missing checks of niu_pci_eeprom_read
        scripts/decode_stacktrace: only strip base path when a prefix of the path
        ocfs2: don't clear bh uptodate for block read
        isdn: hisax: hfc_pci: Fix a possible concurrency use-after-free bug in HFCPCI_l1hw()
        gdrom: fix a memory leak bug
        block/swim3: Fix -EBUSY error when re-opening device after unmount
        HID: lenovo: Add checks to fix of_led_classdev_register
        kernel/hung_task.c: break RCU locks based on jiffies
        fs/epoll: drop ovflist branch prediction
        exec: load_script: don't blindly truncate shebang string
        thermal: hwmon: inline helpers when CONFIG_THERMAL_HWMON is not set
        test_hexdump: use memcpy instead of strncpy
        tipc: use destination length for copy string
        string: drop __must_check from strscpy() and restore strscpy() usages in cgroup
        dccp: fool proof ccid_hc_[rt]x_parse_options()
        enic: fix checksum validation for IPv6
        net: dp83640: expire old TX-skb
        skge: potential memory corruption in skge_get_regs()
        net: systemport: Fix WoL with password after deep sleep
        net: dsa: slave: Don't propagate flag changes on down slave interfaces
        ALSA: compress: Fix stop handling on compressed capture streams
        ALSA: hda - Serialize codec registrations
        fuse: call pipe_buf_release() under pipe lock
        fuse: decrement NR_WRITEBACK_TEMP on the right page
        fuse: handle zero sized retrieve correctly
        dmaengine: imx-dma: fix wrong callback invoke
        usb: phy: am335x: fix race condition in _probe
        usb: gadget: udc: net2272: Fix bitwise and boolean operations
        KVM: x86: work around leak of uninitialized stack contents (CVE-2019-7222)
        KVM: nVMX: unconditionally cancel preemption timer in free_nested (CVE-2019-7221)
        perf/x86/intel/uncore: Add Node ID mask
        x86/MCE: Initialize mce.bank in the case of a fatal error in mce_no_way_out()
        perf/core: Don't WARN() for impossible ring-buffer sizes
        perf tests evsel-tp-sched: Fix bitwise operator
        mtd: rawnand: gpmi: fix MX28 bus master lockup problem
        signal: Always notice exiting tasks
        signal: Better detection of synchronous signals
        misc: vexpress: Off by one in vexpress_syscfg_exec()
        debugfs: fix debugfs_rename parameter checking
        mips: cm: reprime error cause
        MIPS: OCTEON: don't set octeon_dma_bar_type if PCI is disabled
        MIPS: VDSO: Include $(ccflags-vdso) in o32,n32 .lds builds
        ARM: iop32x/n2100: fix PCI IRQ mapping
        mac80211: ensure that mgmt tx skbs have tailroom for encryption
        drm/modes: Prevent division by zero htotal
        drm/vmwgfx: Fix setting of dma masks
        drm/vmwgfx: Return error code from vmw_execbuf_copy_fence_user
        HID: debug: fix the ring buffer implementation
        NFC: nxp-nci: Include unaligned.h instead of access_ok.h
        Revert "cifs: In Kconfig CONFIG_CIFS_POSIX needs depends on legacy (insecure cifs)"
        libceph: avoid KEEPALIVE_PENDING races in ceph_con_keepalive()
        xfrm: refine validation of template and selector families
        batman-adv: Avoid WARN on net_device without parent in netns
        batman-adv: Force mac header to start of data on xmit
        Revert "exec: load_script: don't blindly truncate shebang string"
        uapi/if_ether.h: prevent redefinition of struct ethhdr
        ARM: dts: da850-evm: Correct the sound card name
        ARM: dts: kirkwood: Fix polarity of GPIO fan lines
        gpio: pl061: handle failed allocations
        cifs: Limit memory used by lock request calls to a page
        Documentation/network: reword kernel version reference
        Revert "Input: elan_i2c - add ACPI ID for touchpad in ASUS Aspire F5-573G"
        Input: elan_i2c - add ACPI ID for touchpad in Lenovo V330-15ISK
        perf/core: Fix impossible ring-buffer sizes warning
        ALSA: hda - Add quirk for HP EliteBook 840 G5
        ALSA: usb-audio: Fix implicit fb endpoint setup by quirk
        Input: bma150 - register input device after setting private data
        Input: elantech - enable 3rd button support on Fujitsu CELSIUS H780
        alpha: fix page fault handling for r16-r18 targets
        alpha: Fix Eiger NR_IRQS to 128
        tracing/uprobes: Fix output for multiple string arguments
        x86/platform/UV: Use efi_runtime_lock to serialise BIOS calls
        signal: Restore the stop PTRACE_EVENT_EXIT
        x86/a.out: Clear the dump structure initially
        dm thin: fix bug where bio that overwrites thin block ignores FUA
        smsc95xx: Use skb_cow_head to deal with cloned skbs
        ch9200: use skb_cow_head() to deal with cloned skbs
        kaweth: use skb_cow_head() to deal with cloned skbs
        usb: dwc2: Remove unnecessary kfree
        pinctrl: msm: fix gpio-hog related boot issues
        uapi/if_ether.h: move __UAPI_DEF_ETHHDR libc define
        Linux 4.4.175

Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
2019-02-20 10:58:59 -07:00
Ingo Molnar
222b22e1f3 perf/core: Fix impossible ring-buffer sizes warning
commit 528871b456026e6127d95b1b2bd8e3a003dc1614 upstream.

The following commit:

  9dff0aa95a32 ("perf/core: Don't WARN() for impossible ring-buffer sizes")

results in perf recording failures with larger mmap areas:

  root@skl:/tmp# perf record -g -a
  failed to mmap with 12 (Cannot allocate memory)

The root cause is that the following condition is buggy:

	if (order_base_2(size) >= MAX_ORDER)
		goto fail;

The problem is that @size is in bytes and MAX_ORDER is in pages,
so the right test is:

	if (order_base_2(size) >= PAGE_SHIFT+MAX_ORDER)
		goto fail;

Fix it.

Reported-by: "Jin, Yao" <yao.jin@linux.intel.com>
Bisected-by: Borislav Petkov <bp@alien8.de>
Analyzed-by: Peter Zijlstra <peterz@infradead.org>
Cc: Julien Thierry <julien.thierry@arm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: <stable@vger.kernel.org>
Fixes: 9dff0aa95a32 ("perf/core: Don't WARN() for impossible ring-buffer sizes")
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-02-20 10:13:22 +01:00
Mark Rutland
06bbc4838a perf/core: Don't WARN() for impossible ring-buffer sizes
commit 9dff0aa95a324e262ffb03f425d00e4751f3294e upstream.

The perf tool uses /proc/sys/kernel/perf_event_mlock_kb to determine how
large its ringbuffer mmap should be. This can be configured to arbitrary
values, which can be larger than the maximum possible allocation from
kmalloc.

When this is configured to a suitably large value (e.g. thanks to the
perf fuzzer), attempting to use perf record triggers a WARN_ON_ONCE() in
__alloc_pages_nodemask():

   WARNING: CPU: 2 PID: 5666 at mm/page_alloc.c:4511 __alloc_pages_nodemask+0x3f8/0xbc8

Let's avoid this by checking that the requested allocation is possible
before calling kzalloc.

Reported-by: Julien Thierry <julien.thierry@arm.com>
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Julien Thierry <julien.thierry@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: <stable@vger.kernel.org>
Link: https://lkml.kernel.org/r/20190110142745.25495-1-mark.rutland@arm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-02-20 10:13:17 +01:00
Maggie White
9db9532ae3 Merge branch 'android-msm-wahoo-4.4-pi-qpr1' into android-msm-wahoo-4.4-pi-qpr2
APR 2019.3

Bug: 123655259
Change-Id: I3b46e61242a14b6e758af3db21d213edfc0ec37b
Signed-off-by: Maggie White <maggiewhite@google.com>
2019-02-07 16:32:09 -08:00