Re: [PATCH 5.3 076/148] mmc: sdhci-of-esdhc: set DMA snooping based on DMA coherence
On Thu, Oct 10, 2019 at 09:49:12AM +0100, Russell King - ARM Linux admin wrote: > Hi Greg, > > On 5th October, Christian Zigotzky reported a > problem with this on PowerPC (at a guess, it looks like there's a > PowerPC user of this where the DT does not mark the device as > dma-coherent, but the hardware requires it to be DMA coherent.) > > However, despite sending a reply to him within minutes of his email > arriving, I've heard nothing since, so there's been no progress on > working out what is really going on. > > Given that the reporter hasn't responded to my reply, I'm not sure > what we should be doing with this... maybe the reporter has solved > his problem, maybe he was using an incorrect DT, we just don't know. Let's just leave this in, and if this did cause a problem, whatever fix is made will be sent to Linus and we can then take that fix into stable as well. thanks, greg k-h
Re: [PATCH 5.3 076/148] mmc: sdhci-of-esdhc: set DMA snooping based on DMA coherence
Hi Greg, On 5th October, Christian Zigotzky reported a problem with this on PowerPC (at a guess, it looks like there's a PowerPC user of this where the DT does not mark the device as dma-coherent, but the hardware requires it to be DMA coherent.) However, despite sending a reply to him within minutes of his email arriving, I've heard nothing since, so there's been no progress on working out what is really going on. Given that the reporter hasn't responded to my reply, I'm not sure what we should be doing with this... maybe the reporter has solved his problem, maybe he was using an incorrect DT, we just don't know. On Thu, Oct 10, 2019 at 10:35:37AM +0200, Greg Kroah-Hartman wrote: > 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: 0x | Version: 0x2202 > mmc0: sdhci: Blk size: 0x0008 | Blk cnt: 0x0001 > mmc0: sdhci: Argument: 0x | Trn mode: 0x0013 > mmc0: sdhci: Present: 0x01f50008 | Host ctl: 0x0038 > mmc0: sdhci: Power: 0x0003 | Blk gap: 0x > mmc0: sdhci: Wake-up: 0x | Clock:0x40d8 > mmc0: sdhci: Timeout: 0x0003 | Int stat: 0x0001 > mmc0: sdhci: Int enab: 0x037f108f | Sig enab: 0x037f108b > mmc0: sdhci: ACmd stat: 0x | Slot int: 0x2202 > mmc0: sdhci: Caps: 0x35fa | Caps_1: 0xaf00 > mmc0: sdhci: Cmd: 0x333a | Max curr: 0x > mmc0: sdhci: Resp[0]: 0x0920 | Resp[1]: 0x001d8a33 > mmc0: sdhci: Resp[2]: 0x325b5900 | Resp[3]: 0x3f400e00 > mmc0: sdhci: Host ctl2: 0x > mmc0: sdhci: ADMA Err: 0x0009 | ADMA Ptr: 0x00236d43820c > 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: sta...@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; > } > > > -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps up
[PATCH 5.3 076/148] mmc: sdhci-of-esdhc: set DMA snooping based on DMA coherence
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: 0x | Version: 0x2202 mmc0: sdhci: Blk size: 0x0008 | Blk cnt: 0x0001 mmc0: sdhci: Argument: 0x | Trn mode: 0x0013 mmc0: sdhci: Present: 0x01f50008 | Host ctl: 0x0038 mmc0: sdhci: Power: 0x0003 | Blk gap: 0x mmc0: sdhci: Wake-up: 0x | Clock:0x40d8 mmc0: sdhci: Timeout: 0x0003 | Int stat: 0x0001 mmc0: sdhci: Int enab: 0x037f108f | Sig enab: 0x037f108b mmc0: sdhci: ACmd stat: 0x | Slot int: 0x2202 mmc0: sdhci: Caps: 0x35fa | Caps_1: 0xaf00 mmc0: sdhci: Cmd: 0x333a | Max curr: 0x mmc0: sdhci: Resp[0]: 0x0920 | Resp[1]: 0x001d8a33 mmc0: sdhci: Resp[2]: 0x325b5900 | Resp[3]: 0x3f400e00 mmc0: sdhci: Host ctl2: 0x mmc0: sdhci: ADMA Err: 0x0009 | ADMA Ptr: 0x00236d43820c 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: sta...@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; }