All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Revert "sd: remove __data_len hack for WRITE SAME"
@ 2017-01-25 21:43 Bart Van Assche
  2017-01-25 22:20 ` Christoph Hellwig
  2017-01-31 15:57 ` Lee Duncan
  0 siblings, 2 replies; 5+ messages in thread
From: Bart Van Assche @ 2017-01-25 21:43 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Christoph Hellwig, Hannes Reinecke, Sagi Grimberg, Jens Axboe,
	Lee Duncan, Chris Leech, linux-scsi

This patch reverts commit f80de881d8df and avoids that sending a
WRITE SAME command to the iSCSI initiator triggers the following:

BUG: unable to handle kernel NULL pointer dereference at 0000000000000014
TARGET_CORE[iSCSI]: Expected Transfer Length: 260096 does not match SCSI CDB Length: 512 for SAM Opcode: 0x41
IP: iscsi_tcp_segment_done+0x20b/0x310 [libiscsi_tcp]

Oops: 0000 [#1] SMP
Modules linked in: target_core_user uio target_core_iblock target_core_file iscsi_target_mod target_core_mod netconsole configfs crct10dif_pclmul crc32_pclmul ghash_clmulni_intel aesni_intel aes_x86_64 crypto_simd cryptd glue_helper virtio_console virtio_rng virtio_balloon serio_raw i2c_piix4 acpi_cpufreq button iscsi_tcp libiscsi_tcp libiscsi scsi_transport_iscsi ext4 jbd2 mbcache virtio_blk virtio_net psmouse floppy drm_kms_helper syscopyarea
sysfillrect sysimgblt fb_sys_fops ttm drm virtio_pci
CPU: 2 PID: 5 Comm: kworker/u8:0 Not tainted 4.10.0-rc5-debug+ #3
Workqueue: iscsi_q_0 iscsi_xmitworker [libiscsi]
RIP: 0010:iscsi_tcp_segment_done+0x20b/0x310 [libiscsi_tcp]
Call Trace:
 iscsi_sw_tcp_xmit_segment+0x84/0x120 [iscsi_tcp]
 iscsi_sw_tcp_pdu_xmit+0x51/0x180 [iscsi_tcp]
 iscsi_tcp_task_xmit+0xb3/0x290 [libiscsi_tcp]
 iscsi_xmit_task+0x4e/0xc0 [libiscsi]
 iscsi_xmitworker+0x243/0x330 [libiscsi]
 process_one_work+0x1d8/0x4b0
 worker_thread+0x49/0x4a0
 kthread+0x102/0x140

Fixes: f80de881d8df ("sd: remove __data_len hack for WRITE SAME")
Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Sagi Grimberg <sagi@grimberg.me>
Cc: Jens Axboe <axboe@fb.com>
Cc: Lee Duncan <lduncan@suse.com>
Cc: Chris Leech <cleech@redhat.com>
---
 drivers/scsi/sd.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 0b09638fa39b..6e6d4a41613f 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -836,6 +836,7 @@ static int sd_setup_write_same_cmnd(struct scsi_cmnd *cmd)
 	struct bio *bio = rq->bio;
 	sector_t sector = blk_rq_pos(rq);
 	unsigned int nr_sectors = blk_rq_sectors(rq);
+	unsigned int nr_bytes = blk_rq_bytes(rq);
 	int ret;
 
 	if (sdkp->device->no_write_same)
@@ -868,7 +869,21 @@ static int sd_setup_write_same_cmnd(struct scsi_cmnd *cmd)
 
 	cmd->transfersize = sdp->sector_size;
 	cmd->allowed = SD_MAX_RETRIES;
-	return scsi_init_io(cmd);
+
+	/*
+	 * For WRITE SAME the data transferred via the DATA OUT buffer is
+	 * different from the amount of data actually written to the target.
+	 *
+	 * We set up __data_len to the amount of data transferred via the
+	 * DATA OUT buffer so that blk_rq_map_sg sets up the proper S/G list
+	 * to transfer a single sector of data first, but then reset it to
+	 * the amount of data to be written right after so that the I/O path
+	 * knows how much to actually write.
+	 */
+	rq->__data_len = sdp->sector_size;
+	ret = scsi_init_io(cmd);
+	rq->__data_len = nr_bytes;
+	return ret;
 }
 
 static int sd_setup_flush_cmnd(struct scsi_cmnd *cmd)
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Revert "sd: remove __data_len hack for WRITE SAME"
  2017-01-25 21:43 [PATCH] Revert "sd: remove __data_len hack for WRITE SAME" Bart Van Assche
@ 2017-01-25 22:20 ` Christoph Hellwig
  2017-01-26  2:56   ` Martin K. Petersen
  2017-01-31 15:57 ` Lee Duncan
  1 sibling, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2017-01-25 22:20 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Martin K. Petersen, Christoph Hellwig, Hannes Reinecke,
	Sagi Grimberg, Jens Axboe, Lee Duncan, Chris Leech, linux-scsi

Thanks Bart, and sorry for messing this up.

Acked-by: Christoph Hellwig <hch@lst.de>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Revert "sd: remove __data_len hack for WRITE SAME"
  2017-01-25 22:20 ` Christoph Hellwig
@ 2017-01-26  2:56   ` Martin K. Petersen
  2017-01-26 17:01     ` Jens Axboe
  0 siblings, 1 reply; 5+ messages in thread
From: Martin K. Petersen @ 2017-01-26  2:56 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Bart Van Assche, Martin K. Petersen, Hannes Reinecke,
	Sagi Grimberg, Christoph Hellwig, Lee Duncan, Chris Leech,
	linux-scsi

>>>>> "Christoph" == Christoph Hellwig <hch@lst.de> writes:

Christoph> Thanks Bart, and sorry for messing this up.  Acked-by:
Christoph> Christoph Hellwig <hch@lst.de>

Jens: Since this came in via your tree would you mind reverting it? I'd
prefer to avoid rebasing my fixes branch.

Acked-by: Martin K. Petersen <martin.petersen@oracle.com>

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Revert "sd: remove __data_len hack for WRITE SAME"
  2017-01-26  2:56   ` Martin K. Petersen
@ 2017-01-26 17:01     ` Jens Axboe
  0 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2017-01-26 17:01 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: Bart Van Assche, Hannes Reinecke, Sagi Grimberg,
	Christoph Hellwig, Lee Duncan, Chris Leech, linux-scsi

On 01/25/2017 07:56 PM, Martin K. Petersen wrote:
>>>>>> "Christoph" == Christoph Hellwig <hch@lst.de> writes:
> 
> Christoph> Thanks Bart, and sorry for messing this up.  Acked-by:
> Christoph> Christoph Hellwig <hch@lst.de>
> 
> Jens: Since this came in via your tree would you mind reverting it? I'd
> prefer to avoid rebasing my fixes branch.
> 
> Acked-by: Martin K. Petersen <martin.petersen@oracle.com>

Yep, I have added it, thanks.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Revert "sd: remove __data_len hack for WRITE SAME"
  2017-01-25 21:43 [PATCH] Revert "sd: remove __data_len hack for WRITE SAME" Bart Van Assche
  2017-01-25 22:20 ` Christoph Hellwig
@ 2017-01-31 15:57 ` Lee Duncan
  1 sibling, 0 replies; 5+ messages in thread
From: Lee Duncan @ 2017-01-31 15:57 UTC (permalink / raw)
  To: Bart Van Assche, Martin K. Petersen
  Cc: Christoph Hellwig, Hannes Reinecke, Sagi Grimberg, Jens Axboe,
	Chris Leech, linux-scsi

Acked-by: Lee Duncan <lduncan@suse.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-01-31 16:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-25 21:43 [PATCH] Revert "sd: remove __data_len hack for WRITE SAME" Bart Van Assche
2017-01-25 22:20 ` Christoph Hellwig
2017-01-26  2:56   ` Martin K. Petersen
2017-01-26 17:01     ` Jens Axboe
2017-01-31 15:57 ` Lee Duncan

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.