tracing/syscalls: Fix perf syscall tracing when syscall_nr == -1

syscall_get_nr can return -1 in the case that the task is not executing
a system call.

This patch fixes perf_syscall_{enter,exit} to check that the syscall
number is valid before using it as an index into a bitmap.

Link: http://lkml.kernel.org/r/1345137254-7377-1-git-send-email-will.deacon@arm.com

Change-Id: Iedc719957e184c6572b3ad94e241ae2a97a0b533
Cc: Jason Baron <jbaron@redhat.com>
Cc: Wade Farnsworth <wade_farnsworth@mentor.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
tracing/syscalls: Ignore numbers outside NR_syscalls' range

ARM has some private syscalls (for example, set_tls(2)) which lie
outside the range of NR_syscalls.  If any of these are called while
syscall tracing is being performed, out-of-bounds array access will
occur in the ftrace and perf sys_{enter,exit} handlers.

 # trace-cmd record -e raw_syscalls:* true && trace-cmd report
 ...
 true-653   [000]   384.675777: sys_enter:            NR 192 (0, 1000, 3, 4000022, ffffffff, 0)
 true-653   [000]   384.675812: sys_exit:             NR 192 = 1995915264
 true-653   [000]   384.675971: sys_enter:            NR 983045 (76f74480, 76f74000, 76f74b28, 76f74480, 76f76f74, 1)
 true-653   [000]   384.675988: sys_exit:             NR 983045 = 0
 ...

 # trace-cmd record -e syscalls:* true
 [   17.289329] Unable to handle kernel paging request at virtual address aaaaaace
 [   17.289590] pgd = 9e71c000
 [   17.289696] [aaaaaace] *pgd=00000000
 [   17.289985] Internal error: Oops: 5 [#1] PREEMPT SMP ARM
 [   17.290169] Modules linked in:
 [   17.290391] CPU: 0 PID: 704 Comm: true Not tainted 3.18.0-rc2+ #21
 [   17.290585] task: 9f4dab00 ti: 9e710000 task.ti: 9e710000
 [   17.290747] PC is at ftrace_syscall_enter+0x48/0x1f8
 [   17.290866] LR is at syscall_trace_enter+0x124/0x184

Fix this by ignoring out-of-NR_syscalls-bounds syscall numbers.

Commit cd0980fc8add "tracing: Check invalid syscall nr while tracing syscalls"
added the check for less than zero, but it should have also checked
for greater than NR_syscalls.

Link: http://lkml.kernel.org/p/1414620418-29472-1-git-send-email-rabin@rab.in

Fixes: cd0980fc8add "tracing: Check invalid syscall nr while tracing syscalls"
Cc: stable@vger.kernel.org # 2.6.33+
Signed-off-by: Rabin Vincent <rabin@rab.in>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

Conflicts:
	kernel/trace/trace_syscalls.c

Change-Id: I512142f8f1e1b2a8dc063209666dbce9737377e7
Disable Tracer

Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
Remove more kernel debugging

Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
Fix gcc-4.9.0 miscompilation of load_balance() in scheduler

commit 2062afb4f804afef61cbe62a30cac9a46e58e067 upstream.

Michel Dänzer and a couple of other people reported inexplicable random
oopses in the scheduler, and the cause turns out to be gcc mis-compiling
the load_balance() function when debugging is enabled.  The gcc bug
apparently goes back to gcc-4.5, but slight optimization changes means
that it now showed up as a problem in 4.9.0 and 4.9.1.

The instruction scheduling problem causes gcc to schedule a spill
operation to before the stack frame has been created, which in turn can
corrupt the spilled value if an interrupt comes in.  There may be other
effects of this bug too, but that's the code generation problem seen in
Michel's case.

This is fixed in current gcc HEAD, but the workaround as suggested by
Markus Trippelsdorf is pretty simple: use -fno-var-tracking-assignments
when compiling the kernel, which disables the gcc code that causes the
problem.  This can result in slightly worse debug information for
variable accesses, but that is infinitely preferable to actual code
generation problems.

Doing this unconditionally (not just for CONFIG_DEBUG_INFO) also allows
non-debug builds to verify that the debug build would be identical: we
can do

    export GCC_COMPARE_DEBUG=1

to make gcc internally verify that the result of the build is
independent of the "-g" flag (it will make the compiler build everything
twice, toggling the debug flag, and compare the results).

Without the "-fno-var-tracking-assignments" option, the build would fail
(even with 4.8.3 that didn't show the actual stack frame bug) with a gcc
compare failure.

See also gcc bugzilla:

  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801

Reported-by: Michel Dänzer <michel@daenzer.net>
Suggested-by: Markus Trippelsdorf <markus@trippelsdorf.de>
Cc: Jakub Jelinek <jakub@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
makefile: add -DNDEBUG to KBUILD_CFLAGS
mm: vmscan: reduce swappiness to 10%
Fix build with sm-toolchain 4.8.x in the Makefile

-Use CC instead of REAL_CC
-Remove the wrapper, archheaders and archscripts
-Add missing-syscalls

Signed-off-by: Paul Beeler <sparksco@gmail.com>
Add -Ofast optimization option

Change-Id: Iba50c27114e98bd442ae7a058ebf801171fa4a09
Signed-off-by: Josue Rivera <prbassplayer@gmail.com>
Remove ffast-math gcc flag

  * -ffast-math is redundant when using Ofast
     as its the same as -O3 and -ffast-math

Change-Id: Idbb5ca2b422e638b7926d494133b5e7316d2cb4d
Signed-off-by: Josue Rivera <prbassplayer@gmail.com>

Conflicts:
	Makefile
Makefile: unaligned access, should be default anyway

Change-Id: I0b4b734d396864d515a6ce1af01fdb2336d81d33
Signed-off-by: Dennis Rassmann <showp1984@gmail.com>

Conflicts:
	Makefile
Update compiler flags with memory optimizations

Signed-off-by: Paul Beeler <sparksco@gmail.com>

Conflicts:
	Makefile

Change-Id: I8e163ff470a2aea34473d8e9e56526869093003f
Revert "Disable array-bounds warnings"

This reverts commit 66801b0fede360a745595ab6d417efe47a49aba0.
Add optional graphite flags

Conflicts:
	Makefile

Change-Id: I578802a7a0c03693ad8318344099858809315fae
Optimize SM style

Change-Id: Ie8b69a7bbcc4fe518abab0074750c1e937b293df
Clean up some compiler flags

Change-Id: I9d8373e614ed39f11a25e4e826ef2304dbc1889f
Include graphite in KBUILD_CFLAGS for all optimization options

Change-Id: Ibf4c63d769ce4e8b86911df23ae953ff14053ad2
Fix graphite build error in netfilter

Thanks to @PRJosh for the fix

Change-Id: I1b112b6e3f9ca4e22428cc84d5d4abfb7909416e