revert "elevator: acquire q->sysfs_lock in elevator_change()"
Merge tag 'v3.4.87' into exp-4.4

94b139b Linux 3.4.87
b280b28 powernow-k6: reorder frequencies
b255b6c powernow-k6: correctly initialize default parameters
d1ec820 powernow-k6: disable cache when changing frequency
a40d0aa media: omap_vout: find_vma() needs ->mmap_sem held
21bb61a media: v4l: Reset subdev v4l2_dev field to NULL if registration fails
7ac5824 media: gspca_kinect: add Kinect for Windows USB id
fbedbee sb_edac: Avoid overflow errors at memory size calculation
af7dc7e mmc: mxs-mmc: fix deadlock caused by recursion loop
ff4d5a0 OMAPFB: fix framebuffer console colors
412d9e6 hwmon: Prevent some divide by zeros in FAN_TO_REG()
46bff02 hwmon: (applesmc) Always read until end of data
5f5407d hwmon: (coretemp) Add support for Atom CE4110/4150/4170
37048ba hwmon: (coretemp) Improve support for TjMax detection on Atom CPUs
480c7ed hwmon: (coretemp) Add support for Atom D2000 and N2000 series CPU models
24a8df0 hwmon: (coretemp) Improve support of recent Atom CPU models
f085857 ALSA: hda/realtek - Add support of ALC231 codec
adb7974 ALSA: pcsp: Fix the order of input device unregistration
dda11de ALSA: hda - hdmi: Fallback to ALSA allocation when selecting CA
14c92b5 ALSA: 6fire: make buffers DMA-able (midi)
a79a4cb ALSA: 6fire: make buffers DMA-able (pcm)
05e5104 ALSA: 6fire: fix DMA issues with URB transfer_buffer usage
73af4c7 ALSA: ak4xx-adda: info leak in ak4xxx_capture_source_info()
5e55723 ALSA: usb: Parse UAC2 extension unit like for UAC1
1acf589 ALSA: usb-audio: skip UAC2 EFFECT_UNIT
8e3f04e ALSA: hda - Add another GPU codec ID to snd-hda
6b06792 ALSA: hda - Add new GPU codec ID to snd-hda
0bffc80 ALSA: hda - Cache the MUX selection for generic HDMI
94eac74 xhci: Limit the spurious wakeup fix only to HP machines
79ecb50 xhci: Fix spurious wakeups after S5 on Haswell
1946867 xhci: quirk for extra long delay for S4
6ea54be usb: hub: Clear Port Reset Change during init/resume
69ede95 ahci: Add Device IDs for Intel Wildcat Point-LP
24e9216 ahci: AHCI-mode SATA patch for Intel Coleto Creek DeviceIDs
f70e9e5 ahci: Add Device IDs for Intel Wellsburg PCH
43d9771 USB: ftdi_sio: fixed handling of unsupported CSIZE setting
15d4d0e usb: wusbcore: change WA_SEGS_MAX to a legal value
af0c43e usb: wusbcore: set the RPIPE wMaxPacketSize value correctly
bdbea93 usb: dwc3: add support for Merrifield
490a933 usb: dwc3: pci: add support for BayTrail
0a909d3 usb: Disable USB 2.0 Link PM before device reset.
a69987b USB: fix PM config symbol in uhci-hcd, ehci-hcd, and xhci-hcd
083fcbf USB: fix build error when CONFIG_PM_SLEEP isn't enabled
d8737ac USB: OHCI: Allow runtime PM without system sleep
3cae635 USB: keyspan: fix null-deref at disconnect and release
d50ef35 USB: ti_usb_3410_5052: fix big-endian firmware handling
02fb61f USB: adutux: fix big-endian device-type reporting
e5df243 USB: mos7840: fix race in register handling
769c677 USB: mos7840: fix memory leak in open
32904c9 USB: pl2303: fix device initialisation at open
2b2eff2 USB: spcp8x5: fix device initialisation at open
f18dcf3 usb: dwc3: gadget: free trb pool only from epnum 2
6dc1c36 USB: ftdi_sio: enable two UART ports on ST Microconnect Lite
e2e3e92 USB: serial: fix hang when opening port
f728755 USB: ti_usb_3410_5052: fix use-after-free in TIOCMIWAIT
83adaff USB: ssu100: fix use-after-free in TIOCMIWAIT
b2e9bfc USB: spcp8x5: fix use-after-free in TIOCMIWAIT
c8c09e1 USB: pl2303: fix use-after-free in TIOCMIWAIT
4a8dd74 USB: oti6858: fix use-after-free in TIOCMIWAIT
ffa4619 USB: mos7840: fix use-after-free in TIOCMIWAIT
50359ec USB: mos7840: fix broken TIOCMIWAIT
fd45b1f USB: mct_u232: fix use-after-free in TIOCMIWAIT
db4d8d5 USB: io_ti: fix use-after-free in TIOCMIWAIT
82616dd USB: io_edgeport: fix use-after-free in TIOCMIWAIT
6c72792 USB: ftdi_sio: fix use-after-free in TIOCMIWAIT
50bbd81 USB: cypress_m8: fix use-after-free in TIOCMIWAIT
50477ea USB: ch341: fix use-after-free in TIOCMIWAIT
ee71b1b USB: ark3116: fix use-after-free in TIOCMIWAIT
5a45b08 USB: serial: add modem-status-change wait queue
f273f0a ALSA: hda - Fix internal mic for Lenovo Ideapad U300s
f82bb3f ALSA: hda - Always turn on pins for HDMI/DP
3a5274b Revert "ALSA: hda - Shut up pins at power-saving mode with Conexnat codecs"
5548ad5 ALSA: hda - Add Conexant CX20751/2/3/4 codec support
34f7c0c ALSA: hda - Fix non-snoop page handling
b94c4ae ALSA: aloop: Fix Oops while PM resume
2b3d8c8 ALSA: usb: Add quirk for 192KHz recording on E-Mu devices
a75b7b7 usb: Add USB_QUIRK_RESET_RESUME for all Logitech UVC webcams
3d9dbfb usb: Add quirk detection based on interface information
14c83c8 USB: Add device quirk for Microsoft VX700 webcam
2641936 USB: EHCI: bugfix: urb->hcpriv should not be NULL
6ecd7b5 ath9k_hw: Enable hw PLL power save for AR9462
5991651 ath9k_hw: Fix RX gain initvals for AR9485
3f1475c ath9k_hw: fix chain swap setting when setting rx chainmask to 5
38769eb ath9k_htc: fix signal strength handling issues
45349fa ath9k_hw: Assign default xlna config for AR9485
a4bbd83 ath9k: fill channel mode in caldata
39a4acf ath9k: Fix noisefloor calibration
d3c97df ARM: 7791/1: a.out: remove partial a.out support
05496ab ARM: 7628/1: head.S: map one extra section for the ATAG/DTB area
d3bc3d4 ARM: Orion: Set eth packet size csum offload limit
e3c3850 ARM: pxa: prevent PXA270 occasional reboot freezes
81543c3 ARM: footbridge: fix VGA initialisation
d9df9ae ARM: 7742/1: topology: export cpu_topology
a947adc ARM: u300: fix ages old copy/paste bug
978eb79 ARM: w90x900: fix legacy assembly syntax
de24923 ARM: dts: imx51-babbage: fix esdhc cd/wp properties
d92ab46 HID: hidraw: correctly deallocate memory on device disconnect
dd3f5d5 HID: usbhid: fix build problem
8cf8c0a HID: usbhid: quirk for MSI GX680R led panel
303acf4 HID: clean up quirk for Sony RF receivers
7c91b2f HID: add support for Sony RF receiver with USB product id 0x0374
48d4ed8 HID: apple: Add Apple wireless keyboard 2011 ANSI PID
ab267c7 HID: hidraw: improve error handling in hidraw_init()
f2bfdc8 HID: hidraw: fix list->buffer memleak
cd0e036 HID: fix return value of hidraw_report_event() when !CONFIG_HIDRAW
03c8248 HID: hidraw: add proper error handling to raw event reporting
1553bd2 HID: multitouch: validate indexes details
1b00508 HID: usbhid: quirk for Formosa IR receiver
323478e HID: add quirk for Freescale i.MX28 ROM recovery
777dea3 intel_idle: Check cpu_idle_get_driver() for NULL before dereferencing it.
c765975 selinux: correctly label /proc inodes in use before the policy is loaded
ecadc52 pps: Fix a use-after free bug when unregistering a source.
d1aad79 pps: Use pps_lookup_dev to reduce ldisc coupling
1d6ec1c pps: Add pps_lookup_dev() function
e494b68 idr: idr_for_each_entry() macro
050bda2 ipc, msg: fix message length check for negative values
854ca2c compiler/gcc4: Add quirk for 'asm goto' miscompilation bug
c18c162 compiler-gcc.h: Add gcc-recommended GCC_VERSION macro
307df0a workqueue: cond_resched() after processing each work item
15a0c53 printk: Fix rq->lock vs logbuf_lock unlock lock inversion
8d6f850 audit: wait_for_auditd() should use TASK_UNINTERRUPTIBLE
631c8c5 idr: fix top layer handling
c5f1f94 proc: pid/status: show all supplementary groups
intelliactive: add upstream patches

Signed-off-by: Paul Reioux <reioux@gmail.com>
intelliactive: make touch boost interface generic

Signed-off-by: Paul Reioux <reioux@gmail.com>
mm, oom: normalize oom scores to oom_score_adj scale only for userspace

The oom_score_adj scale ranges from -1000 to 1000 and represents the
proportion of memory available to the process at allocation time.  This
means an oom_score_adj value of 300, for example, will bias a process as
though it was using an extra 30.0% of available memory and a value of
-350 will discount 35.0% of available memory from its usage.

The oom killer badness heuristic also uses this scale to report the oom
score for each eligible process in determining the "best" process to
kill.  Thus, it can only differentiate each process's memory usage by
0.1% of system RAM.

On large systems, this can end up being a large amount of memory: 256MB
on 256GB systems, for example.

This can be fixed by having the badness heuristic to use the actual
memory usage in scoring threads and then normalizing it to the
oom_score_adj scale for userspace.  This results in better comparison
between eligible threads for kill and no change from the userspace
perspective.

Suggested-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Tested-by: Dave Jones <davej@redhat.com>
Signed-off-by: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm, oom: fix badness score underflow

If the privileges given to root threads (3% of allowable memory) or a
negative value of /proc/pid/oom_score_adj happen to exceed the amount of
rss of a thread, its badness score overflows as a result of commit
a7f638f999ff ("mm, oom: normalize oom scores to oom_score_adj scale only
for userspace").

Fix this by making the type signed and return 1, meaning the thread is
still eligible for kill, if the value is negative.

Reported-by: Dave Jones <davej@redhat.com>
Acked-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: David Rientjes <rientjes@google.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm, oom: fix and cleanup oom score calculations

The divide in p->signal->oom_score_adj * totalpages / 1000 within
oom_badness() was causing an overflow of the signed long data type.

This adds both the root bias and p->signal->oom_score_adj before doing the
normalization which fixes the issue and also cleans up the calculation.

Tested-by: Dave Jones <davej@redhat.com>
Signed-off-by: David Rientjes <rientjes@google.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Revert "mm: memcg: count pte references from every member of the reclaimed hierarchy"

This reverts commit 16d3319fc9484aca4eb8fbb1da4a4a63740c5be7.
mm, oom: move declaration for mem_cgroup_out_of_memory to oom.h

mem_cgroup_out_of_memory() is defined in mm/oom_kill.c, so declare it in
linux/oom.h rather than linux/memcontrol.h.

Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Acked-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Acked-by: Michal Hocko <mhocko@suse.cz>
Signed-off-by: David Rientjes <rientjes@google.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Paul Reioux <reioux@gmail.com>

Conflicts:
	include/linux/memcontrol.h
mm, oom: introduce helper function to process threads during scan

This patch introduces a helper function to process each thread during the
iteration over the tasklist.  A new return type, enum oom_scan_t, is
defined to determine the future behavior of the iteration:

 - OOM_SCAN_OK: continue scanning the thread and find its badness,

 - OOM_SCAN_CONTINUE: do not consider this thread for oom kill, it's
   ineligible,

 - OOM_SCAN_ABORT: abort the iteration and return, or

 - OOM_SCAN_SELECT: always select this thread with the highest badness
   possible.

There is no functional change with this patch.  This new helper function
will be used in the next patch in the memory controller.

Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Acked-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Reviewed-by: Michal Hocko <mhocko@suse.cz>
Signed-off-by: David Rientjes <rientjes@google.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Reviewed-by: Sha Zhengju <handai.szj@taobao.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm, memcg: introduce own oom handler to iterate only over its own threads

The global oom killer is serialized by the per-zonelist
try_set_zonelist_oom() which is used in the page allocator.  Concurrent
oom kills are thus a rare event and only occur in systems using
mempolicies and with a large number of nodes.

Memory controller oom kills, however, can frequently be concurrent since
there is no serialization once the oom killer is called for oom conditions
in several different memcgs in parallel.

This creates a massive contention on tasklist_lock since the oom killer
requires the readside for the tasklist iteration.  If several memcgs are
calling the oom killer, this lock can be held for a substantial amount of
time, especially if threads continue to enter it as other threads are
exiting.

Since the exit path grabs the writeside of the lock with irqs disabled in
a few different places, this can cause a soft lockup on cpus as a result
of tasklist_lock starvation.

The kernel lacks unfair writelocks, and successful calls to the oom killer
usually result in at least one thread entering the exit path, so an
alternative solution is needed.

This patch introduces a seperate oom handler for memcgs so that they do
not require tasklist_lock for as much time.  Instead, it iterates only
over the threads attached to the oom memcg and grabs a reference to the
selected thread before calling oom_kill_process() to ensure it doesn't
prematurely exit.

This still requires tasklist_lock for the tasklist dump, iterating
children of the selected process, and killing all other threads on the
system sharing the same memory as the selected victim.  So while this
isn't a complete solution to tasklist_lock starvation, it significantly
reduces the amount of time that it is held.

Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Acked-by: Michal Hocko <mhocko@suse.cz>
Signed-off-by: David Rientjes <rientjes@google.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Reviewed-by: Sha Zhengju <handai.szj@taobao.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm, oom: reduce dependency on tasklist_lock

Since exiting tasks require write_lock_irq(&tasklist_lock) several times,
try to reduce the amount of time the readside is held for oom kills.  This
makes the interface with the memcg oom handler more consistent since it
now never needs to take tasklist_lock unnecessarily.

The only time the oom killer now takes tasklist_lock is when iterating the
children of the selected task, everything else is protected by
rcu_read_lock().

This requires that a reference to the selected process, p, is grabbed
before calling oom_kill_process().  It may release it and grab a reference
on another one of p's threads if !p->mm, but it also guarantees that it
will release the reference before returning.

[hughd@google.com: fix duplicate put_task_struct()]
Signed-off-by: David Rientjes <rientjes@google.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Reviewed-by: Michal Hocko <mhocko@suse.cz>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Signed-off-by: Paul Reioux <reioux@gmail.com>

Conflicts:
	mm/oom_kill.c

Conflicts:
	mm/oom_kill.c
Revert "mm, memcg: give exiting processes access to memory reserves"

This reverts commit 0d39cce32ae80b52a37eb756bfd7b59ac370ffee.
mm, memcg: move all oom handling to memcontrol.c

By globally defining check_panic_on_oom(), the memcg oom handler can be
moved entirely to mm/memcontrol.c.  This removes the ugly #ifdef in the
oom killer and cleans up the code.

Signed-off-by: David Rientjes <rientjes@google.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Acked-by: Michal Hocko <mhocko@suse.cz>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Paul Reioux <reioux@gmail.com>

Conflicts:
	mm/oom_kill.c
sched/fair: Optimize find_busiest_queue()

Use for_each_cpu_and() and thereby avoid computing the capacity for
CPUs we know we're not interested in.

Reviewed-by: Paul Turner <pjt@google.com>
Reviewed-by: Preeti U Murthy <preeti@linux.vnet.ibm.com>
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/n/tip-lppceyv6kb3a19g8spmrn20b@git.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Paul Reioux <reioux@gmail.com>

backported for Linux 3.4

Conflicts:
	kernel/sched/fair.c
sched/fair: Optimize cgroup pick_next_task_fair()

Since commit 2f36825b1 ("sched: Next buddy hint on sleep and preempt
path") it is likely we pick a new task from the same cgroup, doing a put
and then set on all intermediate entities is a waste of time, so try to
avoid this.

Measured using:

  mount nodev /cgroup -t cgroup -o cpu
  cd /cgroup
  mkdir a; cd a
  mkdir b; cd b
  mkdir c; cd c
  echo $$ > tasks
  perf stat --repeat 10 -- taskset 1 perf bench sched pipe

PRE :      4.542422684 seconds time elapsed   ( +-  0.33% )
POST:      4.389409991 seconds time elapsed   ( +-  0.32% )

Which shows a significant improvement of ~3.5%

Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Tejun Heo <tj@kernel.org>
Link: http://lkml.kernel.org/r/1328936700.2476.17.camel@laptop
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Paul Reioux <reioux@gmail.com>

Backported for Linux 3.4 kernel

Conflicts:
	kernel/sched/fair.c

Conflicts:
	kernel/sched/fair.c
mm, oom: allow exiting threads to have access to memory reserves

Exiting threads, those with PF_EXITING set, can pagefault and require
memory before they can make forward progress.  This happens, for instance,
when a process must fault task->robust_list, a userspace structure, before
detaching its memory.

These threads also aren't guaranteed to get access to memory reserves
unless oom killed or killed from userspace.  The oom killer won't grant
memory reserves if other threads are also exiting other than current and
stalling at the same point.  This prevents needlessly killing processes
when others are already exiting.

Instead of special casing all the possible situations between PF_EXITING
getting set and a thread detaching its mm where it may allocate memory,
which probably wouldn't get updated when a change is made to the exit
path, the solution is to give all exiting threads access to memory
reserves if they call the oom killer.  This allows them to quickly
allocate, detach its mm, and free the memory it represents.

Summary of Luigi's bug report:

: He had an oom condition where threads were faulting on task->robust_list
: and repeatedly called the oom killer but it would defer killing a thread
: because it saw other PF_EXITING threads.  This can happen anytime we need
: to allocate memory after setting PF_EXITING and before detaching our mm;
: if there are other threads in the same state then the oom killer won't do
: anything unless one of them happens to be killed from userspace.
:
: So instead of only deferring for PF_EXITING and !task->robust_list, it's
: better to just give them access to memory reserves to prevent a potential
: livelock so that any other faults that may be introduced in the future in
: the exit path don't cause the same problem (and hopefully we don't allow
: too many of those!).

Signed-off-by: David Rientjes <rientjes@google.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Tested-by: Luigi Semenzato <semenzato@google.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
oom: use N_MEMORY instead N_HIGH_MEMORY

N_HIGH_MEMORY stands for the nodes that has normal or high memory.
N_MEMORY stands for the nodes that has any memory.

The code here need to handle with the nodes which have memory, we should
use N_MEMORY instead.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Acked-by: Hillf Danton <dhillf@gmail.com>
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Lin Feng <linfeng@cn.fujitsu.com>
Cc: David Rientjes <rientjes@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm, oom: cleanup pagefault oom handler

To lock the entire system from parallel oom killing, it's possible to pass
in a zonelist with all zones rather than using for_each_populated_zone()
for the iteration.  This obsoletes try_set_system_oom() and
clear_system_oom() so that they can be removed.

Signed-off-by: David Rientjes <rientjes@google.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Reviewed-by: Michal Hocko <mhocko@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/oom_kill: remove weird use of ERR_PTR()/PTR_ERR().

The normal expectation for ERR_PTR() is to put a negative errno into a
pointer.  oom_kill puts the magic -1 in the result (and has since
pre-git), which is probably clearer with an explicit cast.

Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>