]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/3.10.88/libfc-fix-fc_fcp_cleanup_each_cmd.patch
Linux 3.10.88
[thirdparty/kernel/stable-queue.git] / releases / 3.10.88 / libfc-fix-fc_fcp_cleanup_each_cmd.patch
1 From 8f2777f53e3d5ad8ef2a176a4463a5c8e1a16431 Mon Sep 17 00:00:00 2001
2 From: Bart Van Assche <bart.vanassche@sandisk.com>
3 Date: Fri, 5 Jun 2015 14:20:51 -0700
4 Subject: libfc: Fix fc_fcp_cleanup_each_cmd()
5
6 From: Bart Van Assche <bart.vanassche@sandisk.com>
7
8 commit 8f2777f53e3d5ad8ef2a176a4463a5c8e1a16431 upstream.
9
10 Since fc_fcp_cleanup_cmd() can sleep this function must not
11 be called while holding a spinlock. This patch avoids that
12 fc_fcp_cleanup_each_cmd() triggers the following bug:
13
14 BUG: scheduling while atomic: sg_reset/1512/0x00000202
15 1 lock held by sg_reset/1512:
16 #0: (&(&fsp->scsi_pkt_lock)->rlock){+.-...}, at: [<ffffffffc0225cd5>] fc_fcp_cleanup_each_cmd.isra.21+0xa5/0x150 [libfc]
17 Preemption disabled at:[<ffffffffc0225cd5>] fc_fcp_cleanup_each_cmd.isra.21+0xa5/0x150 [libfc]
18 Call Trace:
19 [<ffffffff816c612c>] dump_stack+0x4f/0x7b
20 [<ffffffff810828bc>] __schedule_bug+0x6c/0xd0
21 [<ffffffff816c87aa>] __schedule+0x71a/0xa10
22 [<ffffffff816c8ad2>] schedule+0x32/0x80
23 [<ffffffffc0217eac>] fc_seq_set_resp+0xac/0x100 [libfc]
24 [<ffffffffc0218b11>] fc_exch_done+0x41/0x60 [libfc]
25 [<ffffffffc0225cff>] fc_fcp_cleanup_each_cmd.isra.21+0xcf/0x150 [libfc]
26 [<ffffffffc0225f43>] fc_eh_device_reset+0x1c3/0x270 [libfc]
27 [<ffffffff814a2cc9>] scsi_try_bus_device_reset+0x29/0x60
28 [<ffffffff814a3908>] scsi_ioctl_reset+0x258/0x2d0
29 [<ffffffff814a2650>] scsi_ioctl+0x150/0x440
30 [<ffffffff814b3a9d>] sd_ioctl+0xad/0x120
31 [<ffffffff8132f266>] blkdev_ioctl+0x1b6/0x810
32 [<ffffffff811da608>] block_ioctl+0x38/0x40
33 [<ffffffff811b4e08>] do_vfs_ioctl+0x2f8/0x530
34 [<ffffffff811b50c1>] SyS_ioctl+0x81/0xa0
35 [<ffffffff816cf8b2>] system_call_fastpath+0x16/0x7a
36
37 Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
38 Signed-off-by: Vasu Dev <vasu.dev@intel.com>
39 Signed-off-by: James Bottomley <JBottomley@Odin.com>
40 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
41
42 ---
43 drivers/scsi/libfc/fc_fcp.c | 19 +++++++++++++++++--
44 1 file changed, 17 insertions(+), 2 deletions(-)
45
46 --- a/drivers/scsi/libfc/fc_fcp.c
47 +++ b/drivers/scsi/libfc/fc_fcp.c
48 @@ -1039,11 +1039,26 @@ restart:
49 fc_fcp_pkt_hold(fsp);
50 spin_unlock_irqrestore(&si->scsi_queue_lock, flags);
51
52 - if (!fc_fcp_lock_pkt(fsp)) {
53 + spin_lock_bh(&fsp->scsi_pkt_lock);
54 + if (!(fsp->state & FC_SRB_COMPL)) {
55 + fsp->state |= FC_SRB_COMPL;
56 + /*
57 + * TODO: dropping scsi_pkt_lock and then reacquiring
58 + * again around fc_fcp_cleanup_cmd() is required,
59 + * since fc_fcp_cleanup_cmd() calls into
60 + * fc_seq_set_resp() and that func preempts cpu using
61 + * schedule. May be schedule and related code should be
62 + * removed instead of unlocking here to avoid scheduling
63 + * while atomic bug.
64 + */
65 + spin_unlock_bh(&fsp->scsi_pkt_lock);
66 +
67 fc_fcp_cleanup_cmd(fsp, error);
68 +
69 + spin_lock_bh(&fsp->scsi_pkt_lock);
70 fc_io_compl(fsp);
71 - fc_fcp_unlock_pkt(fsp);
72 }
73 + spin_unlock_bh(&fsp->scsi_pkt_lock);
74
75 fc_fcp_pkt_release(fsp);
76 spin_lock_irqsave(&si->scsi_queue_lock, flags);