PM: Prevent runtime suspend during system resume

This patch (as1591) moves the pm_runtime_get_noresume() and
pm_runtime_put_sync() calls from __device_suspend() and
device_resume() to device_prepare() and device_complete() in the PM
core.

The reason for doing this is to make sure that parent devices remain
at full power (i.e., don't go into runtime suspend) while their
children are being resumed from a system sleep.

The PCI core already contained equivalent code to serve the same
purpose.  The patch removes the duplicated code, since it is no longer
needed.  One of the comments from the PCI core gets moved into the PM
core, and a second comment is added to explain whe the _get_noresume
and _put_sync calls are present.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>

Change-Id: I82d1e2d08c85cfe795bad58761059f385299efd4
(cherry picked from commit 88d26136a256576e444db312179e17af6dd0ea87)
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
ata: ahci: Fix re-entrancy in suspend routines

If the AHCI controller is already runtime suspended,
do not try to suspend again during platform suspend.
During resume activate the device and update the
runtime PM status to reflect the actual post-system
sleep status.

CRs-Fixed: 449549
Change-Id: Ia5dbac391804519edfec709ab4af46fa46adf563
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>

(cherry picked from commit 468315e15e74788327521357c2520f1d197c9ba7)
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
Merge "PM: Prevent runtime suspend during system resume"
Merge "ata: ahci: Fix re-entrancy in suspend routines"
mm: show migration types in show_mem

This is useful to diagnose the reason for page allocation failure for
cases where there appear to be several free pages.

Example, with this alloc_pages(GFP_ATOMIC) failure:

 swapper/0: page allocation failure: order:0, mode:0x0
 ...
 Mem-info:
 Normal per-cpu:
 CPU    0: hi:   90, btch:  15 usd:  48
 CPU    1: hi:   90, btch:  15 usd:  21
 Normal free:16104kB min:2296kB low:2868kB high:3444kB active_anon:0kB
 isolated(anon):0kB isolated(file):0kB present:331776kB mlocked:0kB
 lowmem_reserve[]: 0 0

Before the patch, it's hard (for me, at least) to say why all these free
chunks weren't considered for allocation:

 1*1024kB 1*2048kB 3*4096kB = 16128kB

After the patch, it's obvious that the reason is that all of these are
in the MIGRATE_CMA (C) freelist:

 (C) 1*1024kB (C) 1*2048kB (C) 3*4096kB (C) = 16128kB

(cherry picked from commit 394b808b232daea1a92c0b41dfc3d3134788ed46)

Change-Id: Ib4924802b89a063c9145522a57319f02d5e938b1
 active_anon:0 inactive_anon:0 isolated_anon:0
  active_file:0 inactive_file:84 isolated_file:0
  unevictable:0 dirty:0 writeback:0 unstable:0
  free:4026 slab_reclaimable:75 slab_unreclaimable:484
  mapped:0 shmem:0 pagetables:0 bounce:0
 inactive_anon:0kB active_file:0kB inactive_file:336kB unevictable:0kB
 dirty:0kB writeback:0kB mapped:0kB shmem:0kB slab_reclaimable:300kB
 slab_unreclaimable:1936kB kernel_stack:328kB pagetables:0kB unstable:0kB
 bounce:0kB writeback_tmp:0kB pages_scanned:0 all_unreclaimable? no
 Normal: 0*4kB 0*8kB 0*16kB 0*32kB 0*64kB 0*128kB 1*256kB 1*512kB
 Normal: 0*4kB 0*8kB 0*16kB 0*32kB 0*64kB 0*128kB 1*256kB (C) 1*512kB
Signed-off-by: Rabin Vincent <rabin.vincent@stericsson.com>
Cc: Mel Gorman <mel@csn.ul.ie>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
(cherry picked from commit 072827d57bab5196bbf4465d8bed7d116cc7e8f7)

Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
mm: cma: on movable allocations try MIGRATE_CMA first

It has been observed that system tends to keep a lot of CMA free pages
even in very high memory pressure use cases.  The CMA fallback for
movable pages is used very rarely, only when system is completely
pruned from MOVABLE pages.  This means that the out-of-memory is
triggered for unmovable allocations even when there are many CMA pages
available.  This problem was not observed previously since movable
pages were used as a fallback for unmovable allocations.

To avoid such situation this commit changes the allocation order so
that on movable allocations the MIGRATE_CMA pageblocks are used first.

This change means that the MIGRATE_CMA can be removed from fallback
path of the MIGRATE_MOVABLE type.  This means that the
__rmqueue_fallback() function will never deal with CMA pages and thus
all the checks around MIGRATE_CMA can be removed from that function.

(cherry picked from commit b5662d64fa5ee483b985b351dec993402422fee3)

Change-Id: Iaadcb2dd5c8fe870271145c8fe2cf1e130631f15
CRs-Fixed: 435287
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
Cc: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Laura Abbott <lauraa@codeaurora.org>
(cherry picked from commit ad779e78cd0e183e8d11a0d59f961b1def2e268b)

Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
mmc: msm_sdcc: Hard reset controller on errors

For APQ8064 V2 (SDCC version = 0x06000018) doing a soft
reset on errors doesn't reset the state machine that
handles side-band signalling with SPS-BAM fully and can
lead to controller hang for the data transfers after
the reset.

Since there is no register interface to soft reset such
state machine inside the controller, we do hard reset of
the controller in case of errors. SDCC hard reset is
defined as assert and de-assert of asynchronous clock
reset line of the controller.

CRs-Fixed: 451632
Change-Id: I366856e7508a3843688c8acead8a701e7b06fc19
Signed-off-by: Sujit Reddy Thumma <sthumma@codeaurora.org>
(cherry picked from commit aa9a364c6d0e36199ddc2fe0628e5fbdc95e4f33)

Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
USB: ehci_hcd: Don't panic on receiving FATAL ERROR

"commit 105d07f EHCI: HSIC: Add debug support for HSIC system error"
has introduced panic() on receiving FATAL STATUS interrupt. For OTG
and 2nd/3rd HSUSB instance this panic() is not required as the system
can still be functional with USB system error, hence avoiding this
panic() for OTG and 2nd/3rd HSUSB instances.

CRs-Fixed: 447040
Change-Id: I94dc63c5e8ac612ce9bbe42d2ef8266816be2693
Signed-off-by: Chiranjeevi Velempati <cvelempa@codeaurora.org>
msm: pcie: add support for MPQ8064 Hybrid

PCIe has different regulator numbers on various MPQ8064 platforms.
Add the support in PCIe driver for various platforms.

Change-Id: Ifa7af576702a0fb756f7929f0d8814a58a1e4b55
Signed-off-by: Bamidi RaviKiran <bamidir@codeaurora.org>
Merge "mm: show migration types in show_mem"
Merge "mm: cma: on movable allocations try MIGRATE_CMA first"
Merge "mmc: msm_sdcc: Hard reset controller on errors"
msm_fb:display: Enable LVDS panel support

The JB MR1 update was not recognizing the LVDS panel and hence
throwing an invalid panel error. Adding check for LVDS panel to
enable display on 8064 CDP

Change-Id: Ib125cc797b288ca027f91778d9892acfa00a3214
Signed-off-by: Siddhartha Agrawal <agrawals@codeaurora.org>
msmfb: initialize return value for a var in PCC block

Set ret to 0 to handle PCC disable case.

Change-Id: I25bf84dda98e8e4087174f485aa954d181e372f3
Signed-off-by: Kalyan Thota <kalyant@codeaurora.org>
Merge "USB: ehci_hcd: Don't panic on receiving FATAL ERROR"
msm: mpq8064: support PCIe for MPQ8064 Hybrid

PCIe has different GPIO numbers and regulator numbers on MPQ8064
Hybrid. Add the support for PCIe on MPQ8064 Hybrid.

Change-Id: If23dd7d27d1cb89a294f0c46d5a90fde3e192aa6
Signed-off-by: Bamidi RaviKiran <bamidir@codeaurora.org>
Merge "msm: pcie: add support for MPQ8064 Hybrid"
Merge "msm: mpq8064: support PCIe for MPQ8064 Hybrid"
kernel/sys.c: fix stack memory content leak via UNAME26

Calling uname() with the UNAME26 personality set allows a leak of kernel
stack contents.  This fixes it by defensively calculating the length of
copy_to_user() call, making the len argument unsigned, and initializing
the stack buffer to zero (now technically unneeded, but hey, overkill).

CVE-2012-0957

Reported-by: PaX Team <pageexec@freemail.hu>
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: PaX Team <pageexec@freemail.hu>
Cc: Brad Spengler <spender@grsecurity.net>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit 061f13fca219a2164870ea479de6599717312e3d)

Change-Id: Idd324e6167788bf379aad19a7266fb4764330949
Signed-off-by: Sridhar Gujje <sgujje@codeaurora.org>
Merge "kernel/sys.c: fix stack memory content leak via UNAME26"