From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751913AbdIODBT (ORCPT ); Thu, 14 Sep 2017 23:01:19 -0400 Received: from smtpbgau2.qq.com ([54.206.34.216]:43363 "EHLO smtpbgau2.qq.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751733AbdIODBS (ORCPT ); Thu, 14 Sep 2017 23:01:18 -0400 X-QQ-mid: bizesmtp13t1505444467t2x5ierc X-QQ-SSF: 01100000008000F0FNF0000A0000000 X-QQ-FEAT: +c2Kczbw9d1JDNRRWWpiV2m5vdpoRw/z7waLcgAbp1ZCsUZS9Eh70tRRyc/+S RWyKOEsM2JXWjrVwwMrban58iq9eZVonhNB1G6bHgp8t5HW2zgQMc0pvuRzpzeVlsemLHAf Tcs+HqlXfs/8pjC30kuM+8SvRJQ868ayaskrAYxCZM4h0IQRwHSCIhygpi9UBd4NHnnlXFz b0Bsbe8HPIgYph8b/n9nnpAqYC0qHMsXuZ6yowpzffheBrWrdhUo90i954ljSE1T0m8OUKS FR8lorutNXjJwccsydHN9lw14VR8r8QKr9FSVJyXeBnOHP X-QQ-GoodBg: 0 From: Huacai Chen To: "James E . J . Bottomley" Cc: "Martin K . Petersen" , Andrew Morton , Fuxin Zhang , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Huacai Chen , stable@vger.kernel.org Subject: [PATCH V4 3/3] scsi: Align queue to ARCH_DMA_MINALIGN in non-coherent DMA mode Date: Fri, 15 Sep 2017 11:02:49 +0800 Message-Id: <1505444569-21379-1-git-send-email-chenhc@lemote.com> X-Mailer: git-send-email 2.7.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:lemote.com:qybgforeign:qybgforeign1 X-QQ-Bgrelay: 1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/scsi/scsi_lib.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 9cf6a80..79433ad 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -2132,11 +2132,14 @@ 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); + if (plat_device_is_coherent(dev)) + blk_queue_dma_alignment(q, 0x04 - 1); + else + blk_queue_dma_alignment(q, dma_get_cache_alignment() - 1); } EXPORT_SYMBOL_GPL(__scsi_init_queue); -- 2.7.0