Skip to contentSkip to conversation

Patch "scsi: use dma_get_cache_alignment() as minimum DMA alignment" has been added to the 3.18-stable tree

PATCH [email protected] 1 participant 1 message Dec 11, 2017

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

scsi: use dma_get_cache_alignment() as minimum DMA alignment

to the 3.18-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
scsi-use-dma_get_cache_alignment-as-minimum-dma-alignment.patch
and it can be found in the queue-3.18 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

Quoted 1 line

From 90addc6b3c9cda0146fbd62a08e234c2b224a80c Mon Sep 17 00:00:00 2001

From: Huacai Chen <[email protected]>
Date: Tue, 21 Nov 2017 14:23:38 +0100
Subject: scsi: use dma_get_cache_alignment() as minimum DMA alignment

From: Huacai Chen <[email protected]>

commit 90addc6b3c9cda0146fbd62a08e234c2b224a80c upstream.

In non-coherent DMA mode, kernel uses cache flushing operations to maintain I/O coherency, so scsi's block queue should be aligned to the value returned by dma_get_cache_alignment(). Otherwise, 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 corruption.

[hch: rebased and updated the comment and changelog]
---
 drivers/scsi/scsi_lib.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/scsi/scsi_lib.c +6 -4
@@ -2028,11 +2028,13 @@ static void __scsi_init_queue(struct Scs
 		q->limits.cluster = 0;
 
 	/*
-	 * set a reasonable default alignment on word boundaries: the
-	 * host and device may alter it using
-	 * blk_queue_update_dma_alignment() later.
+	 * Set a reasonable default alignment:  The larger of 32-byte (dword),
+	 * which is a common minimum for HBAs, and the minimum DMA alignment,
+	 * which is set by the platform.
+	 *
+	 * Devices that require a bigger alignment can increase it later.
 	 */
-	blk_queue_dma_alignment(q, 0x03);
+	blk_queue_dma_alignment(q, max(4, dma_get_cache_alignment()) - 1);
 }
 
 struct request_queue *__scsi_alloc_queue(struct Scsi_Host *shost,

Patches currently in stable-queue which might be from [email protected] are

queue-3.18/scsi-use-dma_get_cache_alignment-as-minimum-dma-alignment.patch