Received: by 10.223.185.116 with SMTP id b49csp6341978wrg; Wed, 28 Feb 2018 07:53:14 -0800 (PST) X-Google-Smtp-Source: AH8x226yFH44DQupMIoM0QvvQr+ctnfpINBI2A1jBHvYOFVBcfmrqwRiRodrFE9964xFzItfrdSe X-Received: by 2002:a17:902:6e0f:: with SMTP id u15-v6mr18055273plk.78.1519833194819; Wed, 28 Feb 2018 07:53:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519833194; cv=none; d=google.com; s=arc-20160816; b=LGnjKDvRdYCoMWIhHhoCnaE54yKVRgnaSRsz3DncaXa4FYdc7TgZUGqoOpCom+c/Z2 FDOaG/OE+NZZA+oHPyV5YKiFK+pQcBOB14YTMSROeFy5YwYOdnoFyPuku0YlzyxXBKBT eStiDyovuHpKL3PkO2NGmfiUKomLw63rB939VFT2smQzHU65AMH3n5131g/1Hez+Gez3 /ti9dfUeayRHrJnX7HqM3rRO8Fb27W/SZNx+yZv7DRaiHCT98/JusmfwDLZPniFdYWIv +uz3Djxc31/X3/5OzHqZDUsbccUdYz5uTAl8ALaLHBVFgRcGUx9Xr0eV7+61SAsaDddZ lscw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=AJFVcwphBEL0FVCYObQLdazLSkEdO3KkROLt0r//DSE=; b=GrGeKs64OMVhOk6MdvLGXNjDys8K9cpIuQJu+kgXdNmXgK3gHQR1WGLtsQIPHmhdL7 dC/ksYBJT182X3myk9lf2DCuOPpbSGLEwXsjTlyIGP3ptJlegDwU4Bo19YXvD0nLYR5O oayTy7Q8VfV7bYzsEQL4DvfkjjolK+zRf9u+uTaH/K4KUoTsJBmTw2aJbbetibHJVo66 OgBxaserGcwTgOwwWUvDggXKRWG3+jRugnAW8VMIp6GT4+XBB6YSiZjXlWcFM+z6i/Mi g/MIAQUJ7vDaWqZHjpR1tfljEwzXqEqGPYqlktcJGoCYmvkuUOJEzrLGwna4AcUEwdjM /9Eg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f1-v6si1450083plb.73.2018.02.28.07.52.59; Wed, 28 Feb 2018 07:53:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933834AbeB1PwQ (ORCPT + 99 others); Wed, 28 Feb 2018 10:52:16 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:34385 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933786AbeB1PwO (ORCPT ); Wed, 28 Feb 2018 10:52:14 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1er3Yv-0006XQ-Fr; Wed, 28 Feb 2018 15:22:33 +0000 Received: from ben by deadeye with local (Exim 4.90_1) (envelope-from ) id 1er3Yd-0008MV-0P; Wed, 28 Feb 2018 15:22:15 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Martin K. Petersen" , "Huacai Chen" , "Christoph Hellwig" Date: Wed, 28 Feb 2018 15:20:18 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 009/254] scsi: use dma_get_cache_alignment() as minimum DMA alignment In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.55-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Huacai Chen 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. Signed-off-by: Huacai Chen [hch: rebased and updated the comment and changelog] Signed-off-by: Christoph Hellwig Signed-off-by: Martin K. Petersen [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- drivers/scsi/scsi_lib.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1671,11 +1671,13 @@ struct request_queue *__scsi_alloc_queue 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); return q; }