msm: smd: provide atomic channel writes

Some smd clients may write from multiple threads, in which case it's
not safe to call smd_write without holding a lock.  smd_write_atomic()
provides the same functionality as smd_write() but obtains the smd
lock first.
(cherry picked from commit f887e2d4b14e6d4ed56a2b6c2391c5a2245a3ebb)
ARM: Stop irqsoff trace on return to user

If the irqsoff tracer is in use, stop tracing the interrupt disable
interval when returning to userspace.  Tracing userspace execution
time as interrupts disabled time is not helpful for kernel
performance analysis purposes.  Only do so if the irqsoff tracer
is enabled, to avoid overhead purely for lockdep, which doesn't
care.
lib: Improve the performance of memcpy and memmove of the general version

The performance of memcpy and memmove of the general version is
very inefficient, this patch improves them.
Do not limit permissions on changing scheduler latency parameters.
net/ipv4: Eliminate kstrdup memory leak

The string clone is only used as a temporary copy of the argument val
within the while loop, and so it should be freed before leaving the
function.  The call to strsep, however, modifies clone, so a pointer to the
front of the string is kept in saved_clone, to make it possible to free it.

The sematic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@r exists@
local idexpression x;
expression E;
identifier l;
statement S;
@@

*x= \(kasprintf\|kstrdup\)(...);
...
if (x == NULL) S
... when != kfree(x)
	when != E = x
if (...) {
  <... when != kfree(x)
* goto l;
  ...>
* return ...;
}
// </smpl>
pids: fix a race in pid generation that causes pids to be reused immediately

A program that repeatedly forks and waits is susceptible to having the
same pid repeated, especially when it competes with another instance of
the same program.  This is really bad for bash implementation.
Furthermore, many shell scripts assume that pid numbers will not be used
for some length of time.

Race Description:

A                                    B

// pid == offset == n                // pid == offset == n + 1
test_and_set_bit(offset, map->page)
									 test_and_set_bit(offset, map->page);
									 pid_ns->last_pid = pid;
pid_ns->last_pid = pid;
									 // pid == n + 1 is freed (wait())

									 // Next fork()...
									 last = pid_ns->last_pid; // == n
									 pid = last + 1;

Code to reproduce it (Running multiple instances is more effective):

#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

// The distance mod 32768 between two pids, where the first pid is expected
// to be smaller than the second.
int PidDistance(pid_t first, pid_t second) {
  return (second + 32768 - first) % 32768;
}

int main(int argc, char* argv[]) {
  int failed = 0;
  pid_t last_pid = 0;
  int i;
  printf("%d\n", sizeof(pid_t));
  for (i = 0; i < 10000000; ++i) {
	if (i % 32786 == 0)
	  printf("Iter: %d\n", i/32768);
	int child_exit_code = i % 256;
	pid_t pid = fork();
	if (pid == -1) {
	  fprintf(stderr, "fork failed, iteration %d, errno=%d", i, errno);
	  exit(1);
	}
	if (pid == 0) {
	  // Child
	  exit(child_exit_code);
	} else {
	  // Parent
	  if (i > 0) {
		int distance = PidDistance(last_pid, pid);
		if (distance == 0 || distance > 30000) {
		  fprintf(stderr,
				  "Unexpected pid sequence: previous fork: pid=%d, "
				  "current fork: pid=%d for iteration=%d.\n",
				  last_pid, pid, i);
		  failed = 1;
		}
	  }
	  last_pid = pid;
	  int status;
	  int reaped = wait(&status);
	  if (reaped != pid) {
		fprintf(stderr,
				"Wait return value: expected pid=%d, "
				"got %d, iteration %d\n",
				pid, reaped, i);
		failed = 1;
	  } else if (WEXITSTATUS(status) != child_exit_code) {
		fprintf(stderr,
				"Unexpected exit status %x, iteration %d\n",
				WEXITSTATUS(status), i);
		failed = 1;
	  }
	}
  }
  exit(failed);
}

Thanks to Ted Tso for the key ideas of this implementation.

Don't set stat->last_index to -1 if the pol->cur has incorrect value.

If the driver submitted an non-existing pol>cur value (say it
used the default initialized value of zero), when the cpufreq
stats tries to setup its initial values it incorrectly sets
stat->last_index to -1 (or 0xfffff...). And cpufreq_stats_update
tries to update at that index location and fails.

This can be caused by:

stat->last_index = freq_table_get_index(stat, policy->cur);

not finding the appropiate frequency in the table (b/c the policy->cur
is wrong) and we end up crashing. The fix however is
concentrated in the 'cpufreq_stats_update' as the last_index
(and old_index) are updated there. Which means it can reset
the last_index to -1 again and on the next iteration cause a crash.

Without this patch, the following crash is observed:

powernow-k8: Found 1 AMD Athlon(tm) 64 Processor 3700+ (1 cpu cores) (version 2.20.00)
powernow-k8: fid 0x2 (1000 MHz), vid 0x12
powernow-k8: fid 0xa (1800 MHz), vid 0xa
powernow-k8: fid 0xc (2000 MHz), vid 0x8
powernow-k8: fid 0xe (2200 MHz), vid 0x8
Marking TSC unstable due to cpufreq changes
powernow-k8: fid trans failed, fid 0x2, curr 0x0
BUG: unable to handle kernel paging request at ffff880807e07b78
IP: [<ffffffff81479163>] cpufreq_stats_update+0x46/0x5b
.. snip..
Pid: 1, comm: swapper Not tainted 3.0.0-rc2 #45 MICRO-STAR INTERNATIONAL CO., LTD MS-7094/MS-7094
..snip..
Call Trace:
 [<ffffffff81479248>] cpufreq_stat_notifier_trans+0x48/0x7c
 [<ffffffff81095d68>] notifier_call_chain+0x32/0x5e
 [<ffffffff81095e6b>] __srcu_notifier_call_chain+0x47/0x63
 [<ffffffff81095e96>] srcu_notifier_call_chain+0xf/0x11
 [<ffffffff81477e7a>] cpufreq_notify_transition+0x111/0x134
 [<ffffffff8147b0d4>] powernowk8_target+0x53b/0x617
 [<ffffffff8147723a>] __cpufreq_driver_target+0x2e/0x30
 [<ffffffff8147a127>] cpufreq_governor_dbs+0x339/0x356
 [<ffffffff81477394>] __cpufreq_governor+0xa8/0xe9
 [<ffffffff81477525>] __cpufreq_set_policy+0x132/0x13e
 [<ffffffff8147848d>] cpufreq_add_dev_interface+0x272/0x28c

mm/vmscan.c: fix mapping use after free

We need lock_page_nosync() here because we have no reference to the
mapping when taking the page lock.