Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp524845imd; Thu, 1 Nov 2018 00:57:22 -0700 (PDT) X-Google-Smtp-Source: AJdET5dK/tZ+zkmq+lsXU5vfvQbky6EjJRL4RQKneo1SwSCwHP5hKkA5VCZfq5Ni6QV0fHFncXl3 X-Received: by 2002:a17:902:5e3:: with SMTP id f90-v6mr6833628plf.286.1541059042372; Thu, 01 Nov 2018 00:57:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541059042; cv=none; d=google.com; s=arc-20160816; b=YBi6PFVCKLnrvDQP7tf3IXBFiNRM7V81Zh4LVeTtFYd0bHo3EQ+4VK80aoM5t56nvK 4GmXm7C91yUE7ljXPNKvLRI/AOvd20arB8zTAr/cDAiN81n4BcbsCCtIA6hl9KEb4Kn2 J7XjoxPgdP2c8iE9xAUC5Vs+vN4Nq2cWJuPuwnPEu7uLFBpkIQsv2Th0MUs5ZYPSMalX 688+pELaRcaURbQb9SzzLfTJqeG4RgrHlg+F2EtpJGkpCSns+mzIaxWX9n9b2S/VyQRc YFUxB5c0I2lJrtc1Yjoj7h7vVlG6MuvPU9Zx8z6aq5qC2QnzXAmSede+xtlUkJofNgPJ 5PTg== 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:message-id:in-reply-to:subject:cc:to:from :date; bh=9KVG6rbUIdAue2tlddAwh6r2RwVAX6i0wXcUeDUeNxE=; b=lzd8ZbaTKlmvyIMBdCVoikIJFOkLQf/UXhsABU9sM5AdWxrIfk3zf3RZFg+5l0iBFr BAr3IV+iO7a9yoig2bzJYi+xbm/GIcnVrPZvibG04gWpJsVwHA2Lf8qaLVpEq7OB/0Xu RrT5TyQJxlBQTWzwo80Q72unlf3bqVWH19p+D9HZt5f7dxAP1jituVYejFISSNmqvyVn LOsFzFh4dpoJJ0fsJd+8H36FudAQ5oWztlyXXoc8Ou1+vHxvjnWKarI0eLYDeniVxz1h yLCALpGXU0nrTbjQMChCKY4sHl0ZTEsCkvHj/r94tLb9+6sye8JO6wfkgTvg+GKYdpza c2mg== 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 h32-v6si10690998pld.437.2018.11.01.00.57.07; Thu, 01 Nov 2018 00:57:22 -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; 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 S1728073AbeKAQ6G (ORCPT + 99 others); Thu, 1 Nov 2018 12:58:06 -0400 Received: from eddie.linux-mips.org ([148.251.95.138]:47630 "EHLO cvs.linux-mips.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727704AbeKAQ6G (ORCPT ); Thu, 1 Nov 2018 12:58:06 -0400 Received: (from localhost user: 'macro', uid#1010) by eddie.linux-mips.org with ESMTP id S23990474AbeKAHyY1WCoB (ORCPT + 1 other); Thu, 1 Nov 2018 08:54:24 +0100 Date: Thu, 1 Nov 2018 07:54:24 +0000 (GMT) From: "Maciej W. Rozycki" To: Christoph Hellwig , Paul Burton cc: 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 Subject: [PATCH] MIPS: Fix `dma_alloc_coherent' returning a non-coherent allocation In-Reply-To: <20181101051359.GA4164@lst.de> Message-ID: References: <20180914095808.22202-1-hch@lst.de> <20180914095808.22202-5-hch@lst.de> <20181031203206.GA28337@lst.de> <20181101051359.GA4164@lst.de> User-Agent: Alpine 2.21 (LFD 202 2017-01-01) 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 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 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); }