All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sasha.levin@oracle.com>
To: stable@vger.kernel.org, stable-commits@vger.kernel.org
Cc: Jialing Fu <jlfu@marvell.com>,
	Shawn Lin <shawn.lin@rock-chips.com>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	Sasha Levin <sasha.levin@oracle.com>
Subject: [added to the 3.18 stable tree] mmc: core: fix race condition in mmc_wait_data_done
Date: Wed, 28 Oct 2015 01:22:05 -0400	[thread overview]
Message-ID: <1446009925-26739-29-git-send-email-sasha.levin@oracle.com> (raw)
In-Reply-To: <1446009925-26739-1-git-send-email-sasha.levin@oracle.com>

From: Jialing Fu <jlfu@marvell.com>

This patch has been added to the 3.18 stable tree. If you have any
objections, please let us know.

===============

[ Upstream commit 71f8a4b81d040b3d094424197ca2f1bf811b1245 ]

The following panic is captured in ker3.14, but the issue still exists
in latest kernel.
---------------------------------------------------------------------
[   20.738217] c0 3136 (Compiler) Unable to handle kernel NULL pointer dereference
at virtual address 00000578
......
[   20.738499] c0 3136 (Compiler) PC is at _raw_spin_lock_irqsave+0x24/0x60
[   20.738527] c0 3136 (Compiler) LR is at _raw_spin_lock_irqsave+0x20/0x60
[   20.740134] c0 3136 (Compiler) Call trace:
[   20.740165] c0 3136 (Compiler) [<ffffffc0008ee900>] _raw_spin_lock_irqsave+0x24/0x60
[   20.740200] c0 3136 (Compiler) [<ffffffc0000dd024>] __wake_up+0x1c/0x54
[   20.740230] c0 3136 (Compiler) [<ffffffc000639414>] mmc_wait_data_done+0x28/0x34
[   20.740262] c0 3136 (Compiler) [<ffffffc0006391a0>] mmc_request_done+0xa4/0x220
[   20.740314] c0 3136 (Compiler) [<ffffffc000656894>] sdhci_tasklet_finish+0xac/0x264
[   20.740352] c0 3136 (Compiler) [<ffffffc0000a2b58>] tasklet_action+0xa0/0x158
[   20.740382] c0 3136 (Compiler) [<ffffffc0000a2078>] __do_softirq+0x10c/0x2e4
[   20.740411] c0 3136 (Compiler) [<ffffffc0000a24bc>] irq_exit+0x8c/0xc0
[   20.740439] c0 3136 (Compiler) [<ffffffc00008489c>] handle_IRQ+0x48/0xac
[   20.740469] c0 3136 (Compiler) [<ffffffc000081428>] gic_handle_irq+0x38/0x7c
----------------------------------------------------------------------
Because in SMP, "mrq" has race condition between below two paths:
path1: CPU0: <tasklet context>
  static void mmc_wait_data_done(struct mmc_request *mrq)
  {
     mrq->host->context_info.is_done_rcv = true;
     //
     // If CPU0 has just finished "is_done_rcv = true" in path1, and at
     // this moment, IRQ or ICache line missing happens in CPU0.
     // What happens in CPU1 (path2)?
     //
     // If the mmcqd thread in CPU1(path2) hasn't entered to sleep mode:
     // path2 would have chance to break from wait_event_interruptible
     // in mmc_wait_for_data_req_done and continue to run for next
     // mmc_request (mmc_blk_rw_rq_prep).
     //
     // Within mmc_blk_rq_prep, mrq is cleared to 0.
     // If below line still gets host from "mrq" as the result of
     // compiler, the panic happens as we traced.
     wake_up_interruptible(&mrq->host->context_info.wait);
  }

path2: CPU1: <The mmcqd thread runs mmc_queue_thread>
  static int mmc_wait_for_data_req_done(...
  {
     ...
     while (1) {
           wait_event_interruptible(context_info->wait,
                   (context_info->is_done_rcv ||
                    context_info->is_new_req));
     	   static void mmc_blk_rw_rq_prep(...
           {
           ...
           memset(brq, 0, sizeof(struct mmc_blk_request));

This issue happens very coincidentally; however adding mdelay(1) in
mmc_wait_data_done as below could duplicate it easily.

   static void mmc_wait_data_done(struct mmc_request *mrq)
   {
     mrq->host->context_info.is_done_rcv = true;
+    mdelay(1);
     wake_up_interruptible(&mrq->host->context_info.wait);
    }

At runtime, IRQ or ICache line missing may just happen at the same place
of the mdelay(1).

This patch gets the mmc_context_info at the beginning of function, it can
avoid this race condition.

Signed-off-by: Jialing Fu <jlfu@marvell.com>
Tested-by: Shawn Lin <shawn.lin@rock-chips.com>
Fixes: 2220eedfd7ae ("mmc: fix async request mechanism ....")
Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
---
 drivers/mmc/core/core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 297b4f9..9a8cb9c 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -314,8 +314,10 @@ EXPORT_SYMBOL(mmc_start_bkops);
  */
 static void mmc_wait_data_done(struct mmc_request *mrq)
 {
-	mrq->host->context_info.is_done_rcv = true;
-	wake_up_interruptible(&mrq->host->context_info.wait);
+	struct mmc_context_info *context_info = &mrq->host->context_info;
+
+	context_info->is_done_rcv = true;
+	wake_up_interruptible(&context_info->wait);
 }
 
 static void mmc_wait_done(struct mmc_request *mrq)
-- 
2.1.4


  parent reply	other threads:[~2015-10-28  5:27 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-28  5:21 [added to the 3.18 stable tree] blk-mq: fix buffer overflow when reading sysfs file of 'pending' Sasha Levin
2015-10-28  5:21 ` [added to the 3.18 stable tree] unshare: Unsharing a thread does not require unsharing a vm Sasha Levin
2015-10-28  5:21 ` [added to the 3.18 stable tree] tg3: Fix temperature reporting Sasha Levin
2015-10-28  5:21 ` [added to the 3.18 stable tree] mac80211: enable assoc check for mesh interfaces Sasha Levin
2015-10-28  5:21 ` [added to the 3.18 stable tree] arm64: kconfig: Move LIST_POISON to a safe value Sasha Levin
2015-10-28  5:21 ` [added to the 3.18 stable tree] arm64: compat: fix vfp save/restore across signal handlers in big-endian Sasha Levin
2015-10-28  5:21 ` [added to the 3.18 stable tree] arm64: head.S: initialise mdcr_el2 in el2_setup Sasha Levin
2015-10-28  5:21 ` [added to the 3.18 stable tree] arm64: errata: add module build workaround for erratum #843419 Sasha Levin
2015-10-28  5:21 ` [added to the 3.18 stable tree] arm64: KVM: Disable virtual timer even if the guest is not using it Sasha Levin
2015-10-28  5:21 ` [added to the 3.18 stable tree] Input: evdev - do not report errors form flush() Sasha Levin
2015-10-28  5:21 ` [added to the 3.18 stable tree] ALSA: hda - Enable headphone jack detect on old Fujitsu laptops Sasha Levin
2015-10-28  5:21 ` [added to the 3.18 stable tree] ALSA: hda - Use ALC880_FIXUP_FUJITSU for FSC Amilo M1437 Sasha Levin
2015-10-28  5:21 ` [added to the 3.18 stable tree] powerpc/mm: Fix pte_pagesize_index() crash on 4K w/64K hash Sasha Levin
2015-10-28  5:21 ` [added to the 3.18 stable tree] powerpc/rtas: Introduce rtas_get_sensor_fast() for IRQ handlers Sasha Levin
2015-10-28  5:21 ` [added to the 3.18 stable tree] powerpc/mm: Recompute hash value after a failed update Sasha Levin
2015-10-28  5:21 ` [added to the 3.18 stable tree] CIFS: fix type confusion in copy offload ioctl Sasha Levin
2015-10-28  5:21 ` [added to the 3.18 stable tree] Add radeon suspend/resume quirk for HP Compaq dc5750 Sasha Levin
2015-10-28  5:21 ` [added to the 3.18 stable tree] x86/mm: Initialize pmd_idx in page_table_range_init_count() Sasha Levin
2015-10-28  5:21 ` [added to the 3.18 stable tree] [media] rc-core: fix remove uevent generation Sasha Levin
2015-10-28  5:21 ` [added to the 3.18 stable tree] [media] v4l: omap3isp: Fix sub-device power management code Sasha Levin
2015-10-28  5:21 ` [added to the 3.18 stable tree] Btrfs: check if previous transaction aborted to avoid fs corruption Sasha Levin
2015-10-28  5:21 ` [added to the 3.18 stable tree] NFSv4: don't set SETATTR for O_RDONLY|O_EXCL Sasha Levin
2015-10-28  5:21 ` [added to the 3.18 stable tree] NFS: Fix a NULL pointer dereference of migration recovery ops for v4.2 client Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] NFS: nfs_set_pgio_error sometimes misses errors Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] parisc: Use double word condition in 64bit CAS operation Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] parisc: Filter out spurious interrupts in PA-RISC irq handler Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] vmscan: fix increasing nr_isolated incurred by putback unevictable pages Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] fs: if a coredump already exists, unlink and recreate with O_EXCL Sasha Levin
2015-10-28  5:22 ` Sasha Levin [this message]
2015-10-28  5:22 ` [added to the 3.18 stable tree] md/raid10: always set reshape_safe when initializing reshape_position Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] hfs: fix B-tree corruption after insertion at position 0 Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] IB/qib: Change lkey table allocation to support more MRs Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] IB/uverbs: reject invalid or unknown opcodes Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] IB/uverbs: Fix race between ib_uverbs_open and remove_one Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] IB/mlx4: Forbid using sysfs to change RoCE pkeys Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] IB/mlx4: Use correct SL on AH query under RoCE Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] hfs,hfsplus: cache pages correctly between bnode_create and bnode_free Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] if_link: Add an additional parameter to ifla_vf_info for RSS querying Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] rtnetlink: verify IFLA_VF_INFO attributes before passing them to driver Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] ip6_gre: release cached dst on tunnel removal Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] usbnet: Get EVENT_NO_RUNTIME_PM bit before it is cleared Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] ipv6: fix exthdrs offload registration in out_rt path Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] net/ipv6: Correct PIM6 mrt_lock handling Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] netlink, mmap: transform mmap skb into full skb on taps Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] sctp: fix race on protocol/netns initialization Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] openvswitch: Zero flows on allocation Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] fib_rules: fix fib rule dumps across multiple skbs Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] packet: missing dev_put() in packet_do_bind() Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] udp: fix dst races with multicast early demux Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] bna: fix interrupts storm caused by erroneous packets Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] x86/nmi/64: Improve nested NMI comments Sasha Levin
2015-10-28  5:22 ` [added to the 3.18 stable tree] x86/nmi/64: Reorder nested NMI checks Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1446009925-26739-29-git-send-email-sasha.levin@oracle.com \
    --to=sasha.levin@oracle.com \
    --cc=jlfu@marvell.com \
    --cc=shawn.lin@rock-chips.com \
    --cc=stable-commits@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=ulf.hansson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.