From patchwork Tue Nov 21 13:23:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10068035 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 12908602B7 for ; Tue, 21 Nov 2017 13:23:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06668295D7 for ; Tue, 21 Nov 2017 13:23:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EF7E7295DC; Tue, 21 Nov 2017 13:23:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 188C7295DE for ; Tue, 21 Nov 2017 13:23:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751238AbdKUNXw (ORCPT ); Tue, 21 Nov 2017 08:23:52 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:43036 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751115AbdKUNXv (ORCPT ); Tue, 21 Nov 2017 08:23:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=xVPNMYhfkp2QK5DBpkcKOUP9xQvyV+NzQqYfREw2gS0=; b=j4NtjO/wWvH2tHx6wboTCV+B5 U0+tkbvlelu5JbpDcAn9j5saJPAWdapCp34j9mbH5ViSo9pdAb2rXf29k2+JLuQNRiGR8kfRfDsWP 90c314++3LlzWIT874nm+8wet29ovJY7VH07zG1Q9boOPsKLZ2YtEqdbukSZygEvGBVTG8d2c6iZ6 KnsBVM+JnVt5THY/8VwcDkJ0uiOAnrc06Vr1fg33wlrMRMoy1oO+YzyH+rLq2523/9gCfM3831sv5 CKy8TOhNrB/ZiuqR3GFwhDWI5glQV/b9tcjNG6vbVTeW4GTAH2hGw5hCdgwiFV2jKlEqVSFF5qXAx wxMKHwFeg==; Received: from clnet-p099-196.ikbnet.co.at ([83.175.99.196] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.87 #1 (Red Hat Linux)) id 1eH8Wi-0007S3-ER; Tue, 21 Nov 2017 13:23:48 +0000 From: Christoph Hellwig To: "Martin K. Petersen" Cc: Huacai Chen , linux-scsi@vger.kernel.org, iommu@lists.linux-foundation.org, stable@vger.kernel.org Subject: [PATCH 2/3] scsi: use dma_get_cache_alignment() as minimum DMA alignment Date: Tue, 21 Nov 2017 14:23:38 +0100 Message-Id: <20171121132339.1702-3-hch@lst.de> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171121132339.1702-1-hch@lst.de> References: <20171121132339.1702-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Huacai Chen 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: stable@vger.kernel.org Signed-off-by: Huacai Chen [hch: rebased and updated the comment and changelog] Signed-off-by: Christoph Hellwig --- drivers/scsi/scsi_lib.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 1cbc497e00bd..00742c50cd44 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -2148,11 +2148,13 @@ 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 - * 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); } EXPORT_SYMBOL_GPL(__scsi_init_queue);