From fa22b6d1349801e8bfb636cea7a0ae346c96e797 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sat, 23 May 2020 17:01:40 +0000 Subject: [PATCH] scst_local: Require that data buffers are page aligned When using SG_IO it is easy to submit data buffers that do not match the alignment requirements of vdisk_blockio. Make the submitter copy buffers that are not aligned. See also the blk_rq_map_user() call in the Linux kernel source file drivers/scsi/sg.c. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@8953 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- scst_local/scst_local.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/scst_local/scst_local.c b/scst_local/scst_local.c index ec0cb3c11..acdbf492a 100644 --- a/scst_local/scst_local.c +++ b/scst_local/scst_local.c @@ -1175,15 +1175,24 @@ static int scst_local_change_queue_depth(struct scsi_device *sdev, int qdepth) static int scst_local_slave_alloc(struct scsi_device *sdev) { + struct request_queue *q = sdev->request_queue; + #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 17, 0) && \ !defined(CONFIG_SUSE_KERNEL) #if !defined(RHEL_MAJOR) || RHEL_MAJOR -0 >= 6 - queue_flag_set_unlocked(QUEUE_FLAG_BIDI, sdev->request_queue); + queue_flag_set_unlocked(QUEUE_FLAG_BIDI, q); #endif #elif LINUX_VERSION_CODE < KERNEL_VERSION(5, 1, 0) - blk_queue_flag_set(QUEUE_FLAG_BIDI, sdev->request_queue); + blk_queue_flag_set(QUEUE_FLAG_BIDI, q); #endif + /* + * vdisk_blockio requires that data buffers have block_size alignment + * and supports block sizes from 512 up to 4096. See also + * https://github.com/sahlberg/libiscsi/issues/302. + */ + blk_queue_dma_alignment(q, 4095); + return 0; }