From patchwork Fri Nov 17 04:30:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huacai Chen X-Patchwork-Id: 10062277 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 8D64F601D3 for ; Fri, 17 Nov 2017 04:30:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D1302A76F for ; Fri, 17 Nov 2017 04:30:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6ED4E2A80D; Fri, 17 Nov 2017 04:30:08 +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.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SBL, 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 381122A76F for ; Fri, 17 Nov 2017 04:30:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933072AbdKQEaE (ORCPT ); Thu, 16 Nov 2017 23:30:04 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:44636 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932695AbdKQEaD (ORCPT ); Thu, 16 Nov 2017 23:30:03 -0500 Received: by mail-pg0-f66.google.com with SMTP id c123so1035934pga.11; Thu, 16 Nov 2017 20:30:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=HlFPZ2vv3wKFNKegXFlum9G3VqkBUVQbaJNpFeSdQ+E=; b=XkD6xLjIpspo9umRUOmJU5jIkHdxmIthKLKYSsf60MwOKk9uAE2tAT+1hQ1o6MOqUm WSu/aTbkDazEm9aPVKcBUCUTUJ2o8UKwnRVTURDQQwkDTHDuI2XuIiT+gZ6uu/5yDcrF dANaiJpKwmTHkFrU+sLH/9cqflziQ7uv9T6/GP3M3nOziw32xwPa2RUZkvHSmKF/O8p7 3z753fzB1fIGOOz6K7iY8s25eXBzgPYbw8HBKHNL164GZcULUgaALdHgTaYfXdAkE5me qal3JEaIgYBnAnnGFq85r+ZdJlj8KzFdFmdasmvF+amEtgpBOqKDR374zb8SKChFHb/P pjdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=HlFPZ2vv3wKFNKegXFlum9G3VqkBUVQbaJNpFeSdQ+E=; b=ncLTMwpfKg5NhLRDH2hs7rlekeQ50n2tM3DIvSsDOjpyX1gfXk8w9aHtA3sesZiJ32 5OHl3hiBPmQ9U55j74Rdi/kDOSGPde50c1WIFdOQoDnikSbxE3wS+r8aFYswyDQjN/ql td7LLxapixeb9Uco8w0JRrD5Iw3qUljTvbsqAj88YOoabcY5HlEHJ+jNikuIBP+DcaAn cM0XKACrHL7DVHZluyeY7qdHMryZD3j4aF7cwrP38dKx9VsXCQJl2sK0y7OXEeoEsK1e BN1N0v4R6yJKROwczldU8KnfrtlhamZg0NiwU1VeBtt/pMT1y3CS5jXDtPGgjMuY2Mg4 6ong== X-Gm-Message-State: AJaThX6QAREttQdRWYzS6fYiPlMoW8on6/wMw6gCTvBUe4zuk9waq1rp qI9M0U0TBi5qi2HUqkqx4Z0= X-Google-Smtp-Source: AGs4zMaJ8NkLoxsms7P9DG6vRY0lNWU3zoYFybdu4FjRRbi8jqjCZGisR0BrCNcaVrq2Cl0uj7m//w== X-Received: by 10.98.192.202 with SMTP id g71mr685030pfk.33.1510893003455; Thu, 16 Nov 2017 20:30:03 -0800 (PST) Received: from software.domain.org ([172.247.34.138]) by smtp.gmail.com with ESMTPSA id i3sm4550658pgc.88.2017.11.16.20.30.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 16 Nov 2017 20:30:02 -0800 (PST) From: Huacai Chen To: Christoph Hellwig Cc: Marek Szyprowski , Robin Murphy , Andrew Morton , Fuxin Zhang , linux-mips@linux-mips.org, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Huacai Chen Subject: [PATCH V10 3/4] scsi: Align block queue to dma_get_cache_alignment() Date: Fri, 17 Nov 2017 12:30:05 +0800 Message-Id: <1510893005-325-1-git-send-email-chenhc@lemote.com> X-Mailer: git-send-email 2.7.0 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 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, 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. Signed-off-by: Huacai Chen --- 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 1cbc497..cc4ac97 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -2148,11 +2148,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);