* [PATCH] MIPS: Fix `dma_alloc_coherent' returning a non-coherent allocation [not found] ` <20181101051359.GA4164@lst.de> @ 2018-11-01 7:54 ` Maciej W. Rozycki 2018-11-01 8:33 ` Christoph Hellwig 2018-11-05 18:10 ` Paul Burton 0 siblings, 2 replies; 4+ messages in thread From: Maciej W. Rozycki @ 2018-11-01 7:54 UTC (permalink / raw) To: Christoph Hellwig, Paul Burton Cc: iommu, Marek Szyprowski, Robin Murphy, Greg Kroah-Hartman, linux-mips, linux-kernel, stable Fix a MIPS `dma_alloc_coherent' regression from commit bc3ec75de545 ("dma-mapping: merge direct and noncoherent ops") that causes a cached allocation to be returned on noncoherent cache systems. This is due to an inverted check now used in the MIPS implementation of `arch_dma_alloc' on the result from `dma_direct_alloc_pages' before doing the cached-to-uncached mapping of the allocation address obtained. The mapping has to be done for a non-NULL rather than NULL result, because a NULL result means the allocation has failed. Invert the check for correct operation then. Signed-off-by: Maciej W. Rozycki <macro@linux-mips.org> Fixes: bc3ec75de545 ("dma-mapping: merge direct and noncoherent ops") Cc: stable@vger.kernel.org # 4.19+ --- On Thu, 1 Nov 2018, Christoph Hellwig wrote: > Fails to compile for me with: > > cc1: error: ‘-march=r3000’ requires ‘-mfp32’ > > using the x86_64 corss gcc 8 from Debian testing. Hmm, that seems related to the FPXX ABI, which the R3000 does not support and which they may have configured as the default for GCC (`-mfpxx'). That's not relevant to the kernel, so we probably just ought to force `-mfp32' and `-mfp64' for 32-bit and 64-bit builds respectively these days. > Either way the config looks like we have all the required bits for > non-coherent dma support. The only guess is that somehow > dma_cache_wback_inv aren't hooked up to the right functions for some > reason, but I can't really think off why. Well, `dma_cache_wback_inv' isn't actually called and with the 64-bit configuration I switched to the address returned is in the XKPHYS cached noncoherent space, as proved with a simple diagnostic patch applied to `dma_direct_alloc' showing the results of `dev_is_dma_coherent' and the actual allocation: tc1: DEFTA at MMIO addr = 0x1e900000, IRQ = 20, Hardware addr = 08-00-2b-a3-a3-29 defxx tc1: dma_direct_alloc: coherent: 0 defxx tc1: dma_direct_alloc: returned: 9800000003db8000 tc1: registered as fddi0 (the value of 3 in bits 61:59 of the virtual address denotes the cached noncoherent attribute). The cause is commit bc3ec75de545 ("dma-mapping: merge direct and noncoherent ops") reversed the interpretation of the `dma_direct_alloc*' result in `arch_dma_alloc'. I guess this change was unlucky not to have this part of the API actually verified at run-time by anyone anywhere. Fixed thus, with debug output now as expected: defxx tc1: dma_direct_alloc: coherent: 0 defxx tc1: dma_direct_alloc: returned: 9000000003db8000 showing the address returned in the XKPHYS uncached space (the value of 2 in bits 61:59 of the virtual address denotes the uncached attribute), and the network interface working properly. Please apply, and backport as required. Maciej --- arch/mips/mm/dma-noncoherent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) linux-mips-arch-dma-alloc-err.patch Index: linux-20181028-4maxp64-defconfig/arch/mips/mm/dma-noncoherent.c =================================================================== --- linux-20181028-4maxp64-defconfig.orig/arch/mips/mm/dma-noncoherent.c +++ linux-20181028-4maxp64-defconfig/arch/mips/mm/dma-noncoherent.c @@ -50,7 +50,7 @@ void *arch_dma_alloc(struct device *dev, void *ret; ret = dma_direct_alloc_pages(dev, size, dma_handle, gfp, attrs); - if (!ret && !(attrs & DMA_ATTR_NON_CONSISTENT)) { + if (ret && !(attrs & DMA_ATTR_NON_CONSISTENT)) { dma_cache_wback_inv((unsigned long) ret, size); ret = (void *)UNCAC_ADDR(ret); } ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] MIPS: Fix `dma_alloc_coherent' returning a non-coherent allocation 2018-11-01 7:54 ` [PATCH] MIPS: Fix `dma_alloc_coherent' returning a non-coherent allocation Maciej W. Rozycki @ 2018-11-01 8:33 ` Christoph Hellwig 2018-11-01 14:30 ` Maciej W. Rozycki 2018-11-05 18:10 ` Paul Burton 1 sibling, 1 reply; 4+ messages in thread From: Christoph Hellwig @ 2018-11-01 8:33 UTC (permalink / raw) To: Maciej W. Rozycki Cc: Christoph Hellwig, Paul Burton, iommu, Marek Szyprowski, Robin Murphy, Greg Kroah-Hartman, linux-mips, linux-kernel, stable On Thu, Nov 01, 2018 at 07:54:24AM +0000, Maciej W. Rozycki wrote: > Fix a MIPS `dma_alloc_coherent' regression from commit bc3ec75de545 > ("dma-mapping: merge direct and noncoherent ops") that causes a cached > allocation to be returned on noncoherent cache systems. > > This is due to an inverted check now used in the MIPS implementation of > `arch_dma_alloc' on the result from `dma_direct_alloc_pages' before > doing the cached-to-uncached mapping of the allocation address obtained. > The mapping has to be done for a non-NULL rather than NULL result, > because a NULL result means the allocation has failed. > > Invert the check for correct operation then. > > Signed-off-by: Maciej W. Rozycki <macro@linux-mips.org> > Fixes: bc3ec75de545 ("dma-mapping: merge direct and noncoherent ops") > Cc: stable@vger.kernel.org # 4.19+ Oops, yes this looks good: Reviewed-by: Christoph Hellwig <hch@lst.de> ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] MIPS: Fix `dma_alloc_coherent' returning a non-coherent allocation 2018-11-01 8:33 ` Christoph Hellwig @ 2018-11-01 14:30 ` Maciej W. Rozycki 0 siblings, 0 replies; 4+ messages in thread From: Maciej W. Rozycki @ 2018-11-01 14:30 UTC (permalink / raw) To: Christoph Hellwig Cc: Paul Burton, iommu, Marek Szyprowski, Robin Murphy, Greg Kroah-Hartman, linux-mips, linux-kernel, stable On Thu, 1 Nov 2018, Christoph Hellwig wrote: > Oops, yes this looks good: BTW, for anyone missing hardware suitable for serious DMA testing I can recommend getting a pair of DEFPA cards, the ubiquitous PCI version of this board, cheaply available, which is the same except for a different host bus bridge ASIC, developed later. They can be wired back to back similarly to Ethernet adapters (or in a loop if you have 2 or more dual attachment versions), no other hardware is required save for patch cords. Version 3 (DEFPA-xC) boards support universal PCI signalling, older ones are 5V-only. These devices are a stellar example of fine engineering[1]. Our `defxx' driver, which I believe has been adapted from the DEC OSF/1 one referred in the said document, has some latency and other issues that I plan to address sometime, once I have sorted higher-priority issues, however hardware itself is excellent. References: [1] Chran-Ham Chang et al., "High-performance TCP/IP and UDP/IP Networking in DEC OSF/1 for Alpha AXP", Digital Technical Journal, vol. 5, no. 1 (Winter 1993), "Network Adapter Characteristics", p. 7 <ftp://ftp.linux-mips.org/pub/linux/mips/people/macro/DEC/DTJ/DTJ904/DTJ904PF.PDF> Maciej ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] MIPS: Fix `dma_alloc_coherent' returning a non-coherent allocation 2018-11-01 7:54 ` [PATCH] MIPS: Fix `dma_alloc_coherent' returning a non-coherent allocation Maciej W. Rozycki 2018-11-01 8:33 ` Christoph Hellwig @ 2018-11-05 18:10 ` Paul Burton 1 sibling, 0 replies; 4+ messages in thread From: Paul Burton @ 2018-11-05 18:10 UTC (permalink / raw) To: Maciej W. Rozycki Cc: Christoph Hellwig, iommu@lists.linux-foundation.org, Marek Szyprowski, Robin Murphy, Greg Kroah-Hartman, linux-mips@linux-mips.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Hi Maciej, On Thu, Nov 01, 2018 at 07:54:24AM +0000, Maciej W. Rozycki wrote: > Fix a MIPS `dma_alloc_coherent' regression from commit bc3ec75de545 > ("dma-mapping: merge direct and noncoherent ops") that causes a cached > allocation to be returned on noncoherent cache systems. > > This is due to an inverted check now used in the MIPS implementation of > `arch_dma_alloc' on the result from `dma_direct_alloc_pages' before > doing the cached-to-uncached mapping of the allocation address obtained. > The mapping has to be done for a non-NULL rather than NULL result, > because a NULL result means the allocation has failed. > > Invert the check for correct operation then. > > Signed-off-by: Maciej W. Rozycki <macro@linux-mips.org> > Fixes: bc3ec75de545 ("dma-mapping: merge direct and noncoherent ops") > Cc: stable@vger.kernel.org # 4.19+ > --- > arch/mips/mm/dma-noncoherent.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) Thanks, nice catch! Applied to mips-fixes. Paul ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-11-06 3:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20180914095808.22202-1-hch@lst.de>
[not found] ` <20180914095808.22202-5-hch@lst.de>
[not found] ` <alpine.LFD.2.21.1810311414200.20378@eddie.linux-mips.org>
[not found] ` <alpine.LFD.2.21.1810311559590.20378@eddie.linux-mips.org>
[not found] ` <20181031203206.GA28337@lst.de>
[not found] ` <alpine.LFD.2.21.1810312043250.20378@eddie.linux-mips.org>
[not found] ` <20181101051359.GA4164@lst.de>
2018-11-01 7:54 ` [PATCH] MIPS: Fix `dma_alloc_coherent' returning a non-coherent allocation Maciej W. Rozycki
2018-11-01 8:33 ` Christoph Hellwig
2018-11-01 14:30 ` Maciej W. Rozycki
2018-11-05 18:10 ` Paul Burton
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox