Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2073853ybp; Thu, 10 Oct 2019 01:42:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqzMAdoOi883uoOgGfLr66XTMuD4PklGGjebgr5gyl7AOTGTbA+aTDo+aJ6OMQ032gCePD62 X-Received: by 2002:a17:906:a88e:: with SMTP id ha14mr6801615ejb.92.1570696962669; Thu, 10 Oct 2019 01:42:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570696962; cv=none; d=google.com; s=arc-20160816; b=yl3IS3UQPQTz+ERXUCJA2OgeJHS4Kqe3lBsGSKaNkm7678SDRy3fufmkPlBUkBnzQe dfSnLKyzpxvM57x1cNF2cIMm+6Rkg878Xsq/J57mSRThtJEhUkegG/gpwL9bV4LlB9hw WPU+LFI5P+6xFSgyzf05Z1Psr/bzy/7IySg4vI9hrU3kwTK03xI9+3aL0V0vK8x3Ue45 K/V5eGAGWth7sI3vJlg1Om81Ab4+APo/Nl20DD2m46SpSnGQ3x1twY6u7suCmmmN3VL2 PjT/NhjhcfnzSqoIm6jdw8sQYG17OmLXwpE7GOG4OzLJpF96K6fvBWwcikLtPmHlVsDh YYTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rR8Es4xlMkkmtk0zugTEKmlJ8SLOPb5dCf86ARKGbfc=; b=a74qKbLfaXgSekDFX0zppmora3B2uqD1j0n20bHDpUb95ikf1+m4s8OeBYuXGBlO1h Ixyg+BH+j00asgyEw3V0hzvXo4oNS6W8E5Utqr9IGPMo7qkqZ1Xo4moT5q//3xLyZLnY nQPZ6rYNdOZwAliOkkPd2+HovzjPUI9OFITlOXIB1pldIjPHI/Ry6Z/y24blCwa7MStW 8rq8eDhtNhc70fPabO57RwUl+PcZ+WzzOUDcv9QKcBYvQWEukG6yhKSyiBQUUPPueomR KZ3ZBRQtzPbcdxn+2uCgq0IhIIe9/UXdYYmSHv5QszKzQxROdVv9KQHpyXC2QOO0i9Zj lJ6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Z6yeVNSs; 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 l20si2675389ejb.111.2019.10.10.01.42.19; Thu, 10 Oct 2019 01:42:42 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=Z6yeVNSs; 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 S2388230AbfJJIk7 (ORCPT + 99 others); Thu, 10 Oct 2019 04:40:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:45178 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388223AbfJJIk6 (ORCPT ); Thu, 10 Oct 2019 04:40:58 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DE3B32054F; Thu, 10 Oct 2019 08:40:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570696857; bh=YCv08OtIP8ALu1K/EyVpY57KtMBqX6VgQaWNOZT7QrU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z6yeVNSs6AaQKAHGHH2qM+ywMTj6c5L6385PdBrlxAf/VMBv36n3xBi87GLP6OPAz v/c6+D3JWlNCazjAtLU5hYiJgIsSoaXZ7IJj3Si2FXrUpBNUceCGpVxo0GtK7w6n00 m9lEEnufom0u/hRXp6AsnbkIKIZeUn7UofGo82uM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Russell King , Adrian Hunter , Ulf Hansson Subject: [PATCH 5.3 076/148] mmc: sdhci-of-esdhc: set DMA snooping based on DMA coherence Date: Thu, 10 Oct 2019 10:35:37 +0200 Message-Id: <20191010083615.965680999@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191010083609.660878383@linuxfoundation.org> References: <20191010083609.660878383@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Russell King commit 121bd08b029e03404c451bb237729cdff76eafed upstream. We must not unconditionally set the DMA snoop bit; if the DMA API is assuming that the device is not DMA coherent, and the device snoops the CPU caches, the device can see stale cache lines brought in by speculative prefetch. This leads to the device seeing stale data, potentially resulting in corrupted data transfers. Commonly, this results in a descriptor fetch error such as: mmc0: ADMA error mmc0: sdhci: ============ SDHCI REGISTER DUMP =========== mmc0: sdhci: Sys addr: 0x00000000 | Version: 0x00002202 mmc0: sdhci: Blk size: 0x00000008 | Blk cnt: 0x00000001 mmc0: sdhci: Argument: 0x00000000 | Trn mode: 0x00000013 mmc0: sdhci: Present: 0x01f50008 | Host ctl: 0x00000038 mmc0: sdhci: Power: 0x00000003 | Blk gap: 0x00000000 mmc0: sdhci: Wake-up: 0x00000000 | Clock: 0x000040d8 mmc0: sdhci: Timeout: 0x00000003 | Int stat: 0x00000001 mmc0: sdhci: Int enab: 0x037f108f | Sig enab: 0x037f108b mmc0: sdhci: ACmd stat: 0x00000000 | Slot int: 0x00002202 mmc0: sdhci: Caps: 0x35fa0000 | Caps_1: 0x0000af00 mmc0: sdhci: Cmd: 0x0000333a | Max curr: 0x00000000 mmc0: sdhci: Resp[0]: 0x00000920 | Resp[1]: 0x001d8a33 mmc0: sdhci: Resp[2]: 0x325b5900 | Resp[3]: 0x3f400e00 mmc0: sdhci: Host ctl2: 0x00000000 mmc0: sdhci: ADMA Err: 0x00000009 | ADMA Ptr: 0x000000236d43820c mmc0: sdhci: ============================================ mmc0: error -5 whilst initialising SD card but can lead to other errors, and potentially direct the SDHCI controller to read/write data to other memory locations (e.g. if a valid descriptor is visible to the device in a stale cache line.) Fix this by ensuring that the DMA snoop bit corresponds with the behaviour of the DMA API. Since the driver currently only supports DT, use of_dma_is_coherent(). Note that device_get_dma_attr() can not be used as that risks re-introducing this bug if/when the driver is converted to ACPI. Signed-off-by: Russell King Acked-by: Adrian Hunter Cc: stable@vger.kernel.org Signed-off-by: Ulf Hansson Signed-off-by: Greg Kroah-Hartman --- drivers/mmc/host/sdhci-of-esdhc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/drivers/mmc/host/sdhci-of-esdhc.c +++ b/drivers/mmc/host/sdhci-of-esdhc.c @@ -495,7 +495,12 @@ static int esdhc_of_enable_dma(struct sd dma_set_mask_and_coherent(dev, DMA_BIT_MASK(40)); value = sdhci_readl(host, ESDHC_DMA_SYSCTL); - value |= ESDHC_DMA_SNOOP; + + if (of_dma_is_coherent(dev->of_node)) + value |= ESDHC_DMA_SNOOP; + else + value &= ~ESDHC_DMA_SNOOP; + sdhci_writel(host, value, ESDHC_DMA_SYSCTL); return 0; }