dm io: fix the sync/async helper

Without this patch they are actually the same thing since the changes
against the rw field does not get passed to the under level routines.

It seems like a mistake during rebase to RHEL 2.6.32-220.

Signed-off-by: Zhu Yanhai <gaoyang.zyh@taobao.com>
pidns: Use task_active_pid_ns where appropriate

The expressions tsk->nsproxy->pid_ns and task_active_pid_ns
aka ns_of_pid(task_pid(tsk)) should have the same number of
cache line misses with the practical difference that
ns_of_pid(task_pid(tsk)) is released later in a processes life.

Furthermore by using task_active_pid_ns it becomes trivial
to write an unshare implementation for the the pid namespace.

So I have used task_active_pid_ns everywhere I can.

In fork since the pid has not yet been attached to the
process I use ns_of_pid, to achieve the same effect.

[Note from Zheng Liu]
We need to backport this patch for fixing a panic in our cgroup system.
It will cause a panic when we stop a instance.

Reference: 17cf22c33e1f1b5e435469c84e43872579497653
Patch-mainline: v3.7-rc3-9-g17cf22c
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
tcp: [BUG] call dst_release() in tcp_v4_conn_request()

Before merging TFO patch set, in tcp_v4_conn_request() we always call
__tcp_v4_send_synack() to send a packet with syn and ack flag.  In
__tcp_v4_send_synack() function it always calls dst_release() to
decrease the ref count for a dst_entry.  But after applying TFO patch
set this function is never called.  So we will meet a bug like below:

unregister_netdevice: waiting for lo to become free.  Usage count = 3

Patch-mainline: in-house
Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
ipv4: Don't add TCP-code in inet_sock_destruct

[Note from Zheng Liu]
This patch fixes a bug that meets in our product system in alipay.

Reference: bb68b64724a4fd6b93d83b39aeffa4aadb2562fc
Patch-mainline: v3.6-rc5-987-gbb68b64
Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
Acked-by: H.K. Jerry Chu <hkchu@google.com>
Acked-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Merge pull request #73 from jesuszhu/dm-fix

dm io: fix the sync/async helper
Merge pull request #76 from gnehzuil/tfo-bug-fix

Tfo bug fix
Merge pull request #74 from gnehzuil/ns-pid

pidns: Use task_active_pid_ns where appropriate
kthread: implement kthread_worker

Backport upstream commit: b56c0d8937e665a27d90517ee7a746d0aa05af46

Implement simple work processor for kthread.  This is to ease using
kthread.  Single thread workqueue used to be used for things like this
but workqueue won't guarantee fixed kthread association anymore to
enable worker sharing.

This can be used in cases where specific kthread association is
necessary, for example, when it should have RT priority or be assigned
to certain cgroup.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Backport-by: Xun Ni <xun.ni@intel.com>
kthread_worker: reorganize to prepare for flush_kthread_work() reimplementation

Backport upstream commit: 9a2e03d8ed518a61154f18d83d6466628e519f94

Make the following two non-functional changes.

* Separate out insert_kthread_work() from queue_kthread_work().

* Relocate struct kthread_flush_work and kthread_flush_work_fn()
  definitions above flush_kthread_work().

v2: Added lockdep_assert_held() in insert_kthread_work() as suggested
    by Andy Walls.

Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Andy Walls <awalls@md.metrocast.net>
Backport-by: Xun Ni <xun.ni@intel.com>
kthread_worker: reimplement flush_kthread_work() to allow freeing the work item being executed

Backport upstream commit: 46f3d976213452350f9d10b0c2780c2681f7075b

kthread_worker provides minimalistic workqueue-like interface for
users which need a dedicated worker thread (e.g. for realtime
priority).  It has basic queue, flush_work, flush_worker operations
which mostly match the workqueue counterparts; however, due to the way
flush_work() is implemented, it has a noticeable difference of not
allowing work items to be freed while being executed.

While the current users of kthread_worker are okay with the current
behavior, the restriction does impede some valid use cases.  Also,
removing this difference isn't difficult and actually makes the code
easier to understand.

This patch reimplements flush_kthread_work() such that it uses a
flush_work item instead of queue/done sequence numbers.

Signed-off-by: Tejun Heo <tj@kernel.org>
Backport-by: Xun Ni <xun.ni@intel.com>
libsas: introduce scmd_dbg() to quiet false positive timeout messages

Backport upstream commit: 3af74a3c07d93e34fce3d6c6dcd73676d8381d21

libsas sometimes short circuits timeouts to force commands into error
recovery.  It is misleading to log that the command timed-out in
sas_scsi_timed_out() when in fact it was just queued for error handling.
It's also redundant in the case of a true timeout as libata eh will
detect and report timeouts via it's AC_ERR_TIMEOUT facility.

Given that some environments consider "timeout" errors to be indicative
of impending device failure demote the sas_scsi_timed_out() timeout
message to be disabled by default.  This parallels ata_scsi_timed_out().

[jejb: checkpatch fix]
Reported-by: Xun Ni <xun.ni@intel.com>
Tested-by: Nelson Cheng <nelson.cheng@intel.com>
Acked-by: Lukasz Dorau <lukasz.dorau@intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
Backport-by: Xun Ni <xun.ni@intel.com>
libsas: use right function to alloc smp response

Backport upstream commit: 95c9f4d4da6c4e445a9dd58c8382356520ea91a0

In fact the disc_resp buffer will be overwrite by smp response, so we never
found this typo, correct it by using the right one.

Signed-off-by: John Gong <john_gong@usish.com>
Signed-off-by: Jack Wang <jack_wang@usish.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
Backport-by: Xun Ni <xun.ni@intel.com>
libata: add @ap to ata_wait_register() and introduce ata_msleep()

Backport upstream commit: 97750cebb3000a9cc08f8ce8dc8c7143be7d7201

Add optional @ap argument to ata_wait_register() and replace msleep()
calls with ata_msleep() which take optional @ap in addition to the
duration.  These will be used to implement EH exclusion.

This patch doesn't cause any behavior difference.

Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
Backport-by: Xun Ni <xun.ni@intel.com>
libata: implement cross-port EH exclusion

Backport upstream commit: c0c362b60e259e3480a36ef70280d545818844f0

In libata, the non-EH code paths should always take and release
ap->lock explicitly when accessing hardware or shared data structures.
However, once EH is active, it's assumed that the port is owned by EH
and EH methods don't explicitly take ap->lock unless race from irq
handler or other code paths are expected.  However, libata EH didn't
guarantee exclusion among EHs for ports of the same host.  IOW,
multiple EHs may execute in parallel on multiple ports of the same
controller.

In many cases, especially in SATA, the ports are completely
independent of each other and this doesn't cause problems; however,
there are cases where different ports share the same resource, which
lead to obscure timing related bugs such as the one fixed by commit
213373cf (ata_piix: fix locking around SIDPR access).

This patch implements exclusion among EHs of the same host.  When EH
begins, it acquires per-host EH ownership by calling ata_eh_acquire().
When EH finishes, the ownership is released by calling
ata_eh_release().  EH ownership is also released whenever the EH
thread goes to sleep from ata_msleep() or explicitly and reacquired
after waking up.

This ensures that while EH is actively accessing the hardware, it has
exclusive access to it while allowing EHs to interleave and progress
in parallel as they hit waiting stages, which dominate the time spent
in EH.  This achieves cross-port EH exclusion without pervasive and
fragile changes while still allowing parallel EH for the most part.

This was first reported by yuanding02@gmail.com more than three years
ago in the following bugzilla.  :-)

  https://bugzilla.kernel.org/show_bug.cgi?id=8223

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Reported-by: yuanding02@gmail.com
Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
Backport-by: Xun Ni <xun.ni@intel.com>
hrtimer: Prevent all reprogramming if hang detected

Backport upstream commit: 6c6c0d5a1c949d2e084706f9e5fb1fccc175b265

If the last hrtimer interrupt detected a hang it sets hang_detected=1
and programs the clock event device with a delay to let the system
make progress.

If hang_detected == 1, we prevent reprogramming of the clock event
device in hrtimer_reprogram() but not in hrtimer_force_reprogram().

This can lead to the following situation:

hrtimer_interrupt()
   hang_detected = 1;
   program ce device to Xms from now (hang delay)

We have two timers pending:
   T1 expires 50ms from now
   T2 expires 5s from now

Now T1 gets canceled, which causes hrtimer_force_reprogram() to be
invoked, which in turn programs the clock event device to T2 (5
seconds from now).

Any hrtimer_start after that will not reprogram the hardware due to
hang_detected still being set. So we effectivly block all timers until
the T2 event fires and cleans up the hang situation.

Add a check for hang_detected to hrtimer_force_reprogram() which
prevents the reprogramming of the hang delay in the hardware
timer. The subsequent hrtimer_interrupt will resolve all outstanding
issues.

[ tglx: Rewrote subject and changelog and fixed up the comment in
  	hrtimer_force_reprogram() ]

Signed-off-by: Stuart Hayes <stuart.w.hayes@gmail.com>
Link: http://lkml.kernel.org/r/53602DC6.2060101@gmail.com
Cc: stable@vger.kernel.org
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

Backport-by: Xiaochen Shen <xiaochen.shen@intel.com>
support for Intel Wellsburg (PCH) SATA, HD Audio, and SMBUS (I2C)

Backport upstream commit:

884b088f61b64c22a9a34d4ef960ab9c807d8efd
a3fc0ff00a46c4b32e7214961a5be9a1dc39b60e
151743fd8dfb02956c5184b5f4f0f42677eb75bc
efda332cb66d78d6fdf6f98e7b067480f43624f2
3aee8bc52c415aba8148f144e5e5359b0fd75dd1
5e5a4f5d5a08c9c504fe956391ac3dae2c66556d
b55f84e2d527182e7c611d466cd0bb6ddce201de
eac27f04a71e1f39f196f7e520d16dcefc955d77

Backport-by: Xiaochen Shen <xiaochen.shen@intel.com>
support for Avoton (SOC) SATA and SMBUS (I2C)

Backport upstream commit:

aa515277db9585eeb4fdeb4637b9f9df50a1dd9
29e674dd5c8e781589f09c3ee139c80f6da274e4
c2db409cbc8751ccc7e6d2cc2e41af0d12ea637f
488b926923f6da5b90555cddb624ad783f4952b0

Backport-by: Xiaochen Shen <xiaochen.shen@intel.com>
watchdog: Fix rounding bug in get_sample_period()

upstream commit: 70243919d7df9ac41aec4b65b44cbb0d22225ea3

In get_sample_period(), softlockup_thresh is integer divided by
5 before the multiplication by NSEC_PER_SEC. This results in
softlockup_thresh being rounded down to the nearest integer
multiple of 5.

For example, a softlockup_thresh of 4 rounds down to 0.

Signed-off-by: Mandeep Singh Baines <msb@chromium.org>
Cc: Marcin Slusarz <marcin.slusarz@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Link: http://lkml.kernel.org/r/1306127423-3347-1-git-send-email-msb@chromium.org
Signed-off-by: Ingo Molnar <mingo@elte.hu>

Backport-by: Fan Du <fan.du@intel.com>
cpufreq Convert the cpufreq driver lock to a rwlock

Upstream commit: 0d1857a1b987ef874aeb4b99c9c385fa5645bf61

This eliminates the contention I am seeing in __cpufreq_cpu_get.
It also nicely stages the lock to be replaced by the rcu.

Signed-off-by: Nathan Zimmer <nzimmer@sgi.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Backport-by: Youquan Song <youquan.song@intel.com>
i2c: ismt: clear unused buffer

Backport upstream commit: bf4169100c909667ede6af67668b3ecce6928343
"i2c: ismt: initialize DMA buffer"

This patch adds code to initialize the DMA buffer to compensate for
possible hardware data corruption.

Differences between upstream patch and backport patch:
 "memset(priv->dma_buffer, 0, sizeof(priv->dma_buffer))"
  -->
  "if (read_write == I2C_SMBUS_WRITE)
	memset(&data->block[dma_size + 1], 0,
		sizeof(data->block) - dma_size - 1);
  "
Backporting with purpose to clean up the unused buffer.

Signed-off-by: James Ralston <james.d.ralston@intel.com>
[wsa: changed to use 'sizeof']
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Backport-by: Fan Du <fan.du@intel.com>