Skip to content

Commit 90addc6

Browse files
chenhuacaimartinkpetersen
authored andcommitted
scsi: use dma_get_cache_alignment() as minimum DMA alignment
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. Cc: [email protected] Signed-off-by: Huacai Chen <[email protected]> [hch: rebased and updated the comment and changelog] Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 860dd44 commit 90addc6

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/scsi/scsi_lib.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,11 +2148,13 @@ void __scsi_init_queue(struct Scsi_Host *shost, struct request_queue *q)
21482148
q->limits.cluster = 0;
21492149

21502150
/*
2151-
* set a reasonable default alignment on word boundaries: the
2152-
* host and device may alter it using
2153-
* blk_queue_update_dma_alignment() later.
2151+
* Set a reasonable default alignment: The larger of 32-byte (dword),
2152+
* which is a common minimum for HBAs, and the minimum DMA alignment,
2153+
* which is set by the platform.
2154+
*
2155+
* Devices that require a bigger alignment can increase it later.
21542156
*/
2155-
blk_queue_dma_alignment(q, 0x03);
2157+
blk_queue_dma_alignment(q, max(4, dma_get_cache_alignment()) - 1);
21562158
}
21572159
EXPORT_SYMBOL_GPL(__scsi_init_queue);
21582160

0 commit comments

Comments
 (0)