From: Huacai Chen <chenhc@lemote.com>
To: Christoph Hellwig <hch@lst.de>
Cc: Marek Szyprowski <m.szyprowski@samsung.com>,
Robin Murphy <robin.murphy@arm.com>,
Andrew Morton <akpm@linux-foundation.org>,
Fuxin Zhang <zhangfx@lemote.com>,
linux-kernel@vger.kernel.org,
"James E . J . Bottomley" <jejb@linux.vnet.ibm.com>,
"Martin K . Petersen" <martin.petersen@oracle.com>,
linux-scsi@vger.kernel.org, Huacai Chen <chenhc@lemote.com>,
stable@vger.kernel.org
Subject: [PATCH V6 3/3] scsi: Align block queue to dma_get_cache_alignment()
Date: Tue, 19 Sep 2017 16:52:41 +0800 [thread overview]
Message-ID: <1505811161-25246-3-git-send-email-chenhc@lemote.com> (raw)
In-Reply-To: <1505811161-25246-1-git-send-email-chenhc@lemote.com>
In non-coherent DMA mode, kernel uses cache flushing operations to
maintain I/O coherency, so scsi's block queue should be aligned to
ARCH_DMA_MINALIGN. Otherwise, it will cause data corruption, at least
on MIPS:
Step 1, dma_map_single
Step 2, cache_invalidate (no writeback)
Step 3, dma_from_device
Step 4, dma_unmap_single
If a DMA buffer and a kernel structure share a same cache line, and if
the kernel structure has dirty data, cache_invalidate (no writeback)
will cause data lost.
Cc: stable@vger.kernel.org
Signed-off-by: Huacai Chen <chenhc@lemote.com>
---
drivers/scsi/scsi_lib.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 9cf6a80..19abc2e 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -2132,11 +2132,11 @@ void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q)
q->limits.cluster = 0;
/*
- * set a reasonable default alignment on word boundaries: the
- * host and device may alter it using
+ * set a reasonable default alignment on word/cacheline boundaries:
+ * the host and device may alter it using
* blk_queue_update_dma_alignment() later.
*/
- blk_queue_dma_alignment(q, 0x03);
+ blk_queue_dma_alignment(q, max(4, dma_get_cache_alignment(dev)) - 1);
}
EXPORT_SYMBOL_GPL(__scsi_init_queue);
--
2.7.0
next prev parent reply other threads:[~2017-09-19 8:52 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-19 8:52 [PATCH V6 1/3] dma-mapping: Introduce device_is_coherent() as a helper Huacai Chen
2017-09-19 8:52 ` [PATCH V6 2/3] dma-mapping: Rework dma_get_cache_alignment() function Huacai Chen
2017-09-19 15:02 ` Christoph Hellwig
2017-09-21 4:28 ` [PATCH V6 2/3] dma-mapping: Rework dma_get_cache_alignment()function 陈华才
2017-09-21 14:36 ` Christoph Hellwig
2017-09-19 8:52 ` Huacai Chen [this message]
2017-09-24 3:45 ` [PATCH V6 3/3] scsi: Align block queue to dma_get_cache_alignment() kbuild test robot
2017-09-21 10:47 ` [PATCH V6 1/3] dma-mapping: Introduce device_is_coherent() as a helper Robin Murphy
2017-09-22 2:13 ` [PATCH V6 1/3] dma-mapping: Introduce device_is_coherent() as ahelper 陈华才
2017-09-22 13:44 ` Robin Murphy
2017-09-22 13:49 ` Christoph Hellwig
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=1505811161-25246-3-git-send-email-chenhc@lemote.com \
--to=chenhc@lemote.com \
--cc=akpm@linux-foundation.org \
--cc=hch@lst.de \
--cc=jejb@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=martin.petersen@oracle.com \
--cc=robin.murphy@arm.com \
--cc=stable@vger.kernel.org \
--cc=zhangfx@lemote.com \
/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