public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	Adam Radford <aradford@gmail.com>,
	James Bottomley <JBottomley@Odin.com>
Subject: [PATCH 3.10 10/19] 3w-xxxx: fix command completion race
Date: Mon, 11 May 2015 10:55:25 -0700	[thread overview]
Message-ID: <20150511175453.312142687@linuxfoundation.org> (raw)
In-Reply-To: <20150511175453.015424013@linuxfoundation.org>

3.10-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Christoph Hellwig <hch@lst.de>

commit 9cd9554615cba14f0877cc9972a6537ad2bdde61 upstream.

The 3w-xxxx driver needs to tear down the dma mappings before returning
the command to the midlayer, as there is no guarantee the sglist and
count are valid after that point.  Also remove the dma mapping helpers
which have another inherent race due to the request_id index.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Adam Radford <aradford@gmail.com>
Signed-off-by: James Bottomley <JBottomley@Odin.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 drivers/scsi/3w-xxxx.c |   42 ++++++------------------------------------
 drivers/scsi/3w-xxxx.h |    5 -----
 2 files changed, 6 insertions(+), 41 deletions(-)

--- a/drivers/scsi/3w-xxxx.c
+++ b/drivers/scsi/3w-xxxx.c
@@ -1283,32 +1283,6 @@ static int tw_initialize_device_extensio
 	return 0;
 } /* End tw_initialize_device_extension() */
 
-static int tw_map_scsi_sg_data(struct pci_dev *pdev, struct scsi_cmnd *cmd)
-{
-	int use_sg;
-
-	dprintk(KERN_WARNING "3w-xxxx: tw_map_scsi_sg_data()\n");
-
-	use_sg = scsi_dma_map(cmd);
-	if (use_sg < 0) {
-		printk(KERN_WARNING "3w-xxxx: tw_map_scsi_sg_data(): pci_map_sg() failed.\n");
-		return 0;
-	}
-
-	cmd->SCp.phase = TW_PHASE_SGLIST;
-	cmd->SCp.have_data_in = use_sg;
-
-	return use_sg;
-} /* End tw_map_scsi_sg_data() */
-
-static void tw_unmap_scsi_data(struct pci_dev *pdev, struct scsi_cmnd *cmd)
-{
-	dprintk(KERN_WARNING "3w-xxxx: tw_unmap_scsi_data()\n");
-
-	if (cmd->SCp.phase == TW_PHASE_SGLIST)
-		scsi_dma_unmap(cmd);
-} /* End tw_unmap_scsi_data() */
-
 /* This function will reset a device extension */
 static int tw_reset_device_extension(TW_Device_Extension *tw_dev)
 {
@@ -1331,8 +1305,8 @@ static int tw_reset_device_extension(TW_
 			srb = tw_dev->srb[i];
 			if (srb != NULL) {
 				srb->result = (DID_RESET << 16);
-				tw_dev->srb[i]->scsi_done(tw_dev->srb[i]);
-				tw_unmap_scsi_data(tw_dev->tw_pci_dev, tw_dev->srb[i]);
+				scsi_dma_unmap(srb);
+				srb->scsi_done(srb);
 			}
 		}
 	}
@@ -1779,8 +1753,8 @@ static int tw_scsiop_read_write(TW_Devic
 	command_packet->byte8.io.lba = lba;
 	command_packet->byte6.block_count = num_sectors;
 
-	use_sg = tw_map_scsi_sg_data(tw_dev->tw_pci_dev, tw_dev->srb[request_id]);
-	if (!use_sg)
+	use_sg = scsi_dma_map(srb);
+	if (use_sg <= 0)
 		return 1;
 
 	scsi_for_each_sg(tw_dev->srb[request_id], sg, use_sg, i) {
@@ -1967,9 +1941,6 @@ static int tw_scsi_queue_lck(struct scsi
 	/* Save the scsi command for use by the ISR */
 	tw_dev->srb[request_id] = SCpnt;
 
-	/* Initialize phase to zero */
-	SCpnt->SCp.phase = TW_PHASE_INITIAL;
-
 	switch (*command) {
 		case READ_10:
 		case READ_6:
@@ -2196,12 +2167,11 @@ static irqreturn_t tw_interrupt(int irq,
 
 				/* Now complete the io */
 				if ((error != TW_ISR_DONT_COMPLETE)) {
+					scsi_dma_unmap(tw_dev->srb[request_id]);
+					tw_dev->srb[request_id]->scsi_done(tw_dev->srb[request_id]);
 					tw_dev->state[request_id] = TW_S_COMPLETED;
 					tw_state_request_finish(tw_dev, request_id);
 					tw_dev->posted_request_count--;
-					tw_dev->srb[request_id]->scsi_done(tw_dev->srb[request_id]);
-					
-					tw_unmap_scsi_data(tw_dev->tw_pci_dev, tw_dev->srb[request_id]);
 				}
 			}
 				
--- a/drivers/scsi/3w-xxxx.h
+++ b/drivers/scsi/3w-xxxx.h
@@ -195,11 +195,6 @@ static unsigned char tw_sense_table[][4]
 #define TW_AEN_SMART_FAIL        0x000F
 #define TW_AEN_SBUF_FAIL         0x0024
 
-/* Phase defines */
-#define TW_PHASE_INITIAL 0
-#define TW_PHASE_SINGLE 1
-#define TW_PHASE_SGLIST 2
-
 /* Misc defines */
 #define TW_ALIGNMENT_6000		      64 /* 64 bytes */
 #define TW_ALIGNMENT_7000                     4  /* 4 bytes */



  parent reply	other threads:[~2015-05-11 18:26 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-11 17:55 [PATCH 3.10 00/19] 3.10.78-stable review Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 01/19] [PATCH] ipv4: Missing sk_nulls_node_init() in ping_unhash() Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 02/19] ALSA: emux: Fix mutex deadlock at unloading Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 03/19] ALSA: emux: Fix mutex deadlock in OSS emulation Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 04/19] ALSA: emu10k1: Fix card shortname string buffer overflow Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 05/19] ALSA: emu10k1: Emu10k2 32 bit DMA mode Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 07/19] serial: of-serial: Remove device_type = "serial" registration Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 08/19] rbd: end I/O the entire obj_request on error Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 09/19] ext4: fix data corruption caused by unwritten and delayed extents Greg Kroah-Hartman
2015-05-11 17:55 ` Greg Kroah-Hartman [this message]
2015-05-11 17:55 ` [PATCH 3.10 11/19] 3w-9xxx: fix command completion race Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 12/19] 3w-sas: " Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 13/19] usb: host: oxu210hp: use new USB_RESUME_TIMEOUT Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 14/19] usb: gadget: printer: enqueue printers response for setup request Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 15/19] staging: panel: fix lcd type Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 16/19] ARM: dts: dove: Fix uart[23] reg property Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 17/19] Drivers: hv: vmbus: Dont wait after requesting offers Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 18/19] UBI: fix soft lockup in ubi_check_volume() Greg Kroah-Hartman
2015-05-11 17:55 ` [PATCH 3.10 19/19] ARC: signal handling robustify Greg Kroah-Hartman
2015-05-11 20:02 ` [PATCH 3.10 00/19] 3.10.78-stable review Guenter Roeck
2015-05-11 23:41 ` Shuah Khan

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=20150511175453.312142687@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=JBottomley@Odin.com \
    --cc=aradford@gmail.com \
    --cc=hch@lst.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox