From patchwork Fri Jun 10 08:08:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Serge Semin X-Patchwork-Id: 12876671 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E9BB2C433EF for ; Fri, 10 Jun 2022 08:17:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:CC :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=XEhby5lB+qhd4OkqQtkilDUjJjKmcwlCN2c4U42GSoU=; b=pf6WnXLa+yqrdh TxxN33+C8RmftwLfNTHoHelFhnYjHAddY5Nqc0hMOW0qvajSxd1jIihs7nWqpt1m2QRBtQeEiy2I1 YdYA5hH5Q6GPqCedp2YgSlIvKOqhZIUUnbpLdhAP6YXrQ9OvkXY9fE0QDJCU/JjiN7SJnOyaYPKtu neEDlZX1i1HL35b+XLcOO1/t1zbPmBkUCfvd1BZsMSD1EDpH8tXWWIkJW3AClu2/RJpNb/zb+olSA EprheWf/bw41+LAGsk+F2oaRCOmpSRenozy15evvUuw+4rqIwGislNDejB6Mb55pNVIyPYQKPr0Pr r1BrFkcu4nMXv7KcVLFA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzZnD-006i6o-M5; Fri, 10 Jun 2022 08:14:55 +0000 Received: from mail.baikalelectronics.com ([87.245.175.230]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nzZn8-006i5Y-VF for linux-arm-kernel@lists.infradead.org; Fri, 10 Jun 2022 08:14:53 +0000 Received: from mail (mail.baikal.int [192.168.51.25]) by mail.baikalelectronics.com (Postfix) with ESMTP id 9473516A0; Fri, 10 Jun 2022 11:08:57 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.baikalelectronics.com 9473516A0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baikalelectronics.ru; s=mail; t=1654848540; bh=P0epdiQ2UfkKeER5KtOFqFsZ8/0xaqJ7ab4vUUQPTCw=; h=From:To:CC:Subject:Date:From; b=FES/RpZBcFEtKNYzfj2ZM1TKH3v4j1D1srCu1QFX0yo+vxrndl74dC/lOEO0AROoD E9WiAns/InODAMwuQ3yGDm0SYSUjNGDlAku4e4gJHtto+ZKLwtUZuRhTH6qiwi2G8o Wx1WzoKWULlo6KhIEebDed0WI8cU+7OfayCvYSmE= Received: from localhost (192.168.53.207) by mail (192.168.51.25) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Fri, 10 Jun 2022 11:08:05 +0300 From: Serge Semin To: Christoph Hellwig , Marek Szyprowski , Robin Murphy , Vladimir Murzin CC: Serge Semin , Serge Semin , Alexey Malahov , Pavel Parkhomenko , Manivannan Sadhasivam , Andrew Lunn , Sebastian Hesselbarth , Gregory Clement , , Srujana Challa , Arnaud Ebalard , Boris Brezillon , , Vinod Koul , , Shawn Guo , Sascha Hauer , Li Yang , Geert Uytterhoeven , Magnus Damm , , Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , "Pan, Xinhui" , David Airlie , Gerd Hoffmann , Tomasz Figa , Oded Gabbay , Arnd Bergmann , Greg Kroah-Hartman , Manivannan Sadhasivam , Andy Gross , Bjorn Andersson , , Sunil Goutham , Linu Cherian , Geetha sowjanya , Jon Mason , Dave Jiang , , , Subject: [PATCH] dma-direct: take dma-ranges/offsets into account in resource mapping Date: Fri, 10 Jun 2022 11:08:02 +0300 Message-ID: <20220610080802.11147-1-Sergey.Semin@baikalelectronics.ru> MIME-Version: 1.0 X-ClientProxiedBy: MAIL.baikal.int (192.168.51.25) To mail (192.168.51.25) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220610_011451_402554_E44ACC4A X-CRM114-Status: GOOD ( 16.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org A basic device-specific linear memory mapping was introduced back in commit ("dma: Take into account dma_pfn_offset") as a single-valued offset preserved in the device.dma_pfn_offset field, which was initialized for instance by means of the "dma-ranges" DT property. Afterwards the functionality was extended to support more than one device-specific region defined in the device.dma_range_map list of maps. But all of these improvements concerned a single pointer, page or sg DMA-mapping methods, while the system resource mapping function turned to miss the corresponding modification. Thus the dma_direct_map_resource() method now just casts the CPU physical address to the device DMA address with no dma-ranges-based mapping taking into account, which is obviously wrong. Let's fix it by using the phys_to_dma_direct() method to get the device-specific bus address from the passed memory resource for the case of the directly mapped DMA. Fixes: 25f1e1887088 ("dma: Take into account dma_pfn_offset") Signed-off-by: Serge Semin --- After a long discussion with Christoph and Robin regarding this patch here: https://lore.kernel.org/lkml/20220324014836.19149-4-Sergey.Semin@baikalelectronics.ru and here https://lore.kernel.org/linux-pci/20220503225104.12108-2-Sergey.Semin@baikalelectronics.ru/ It was decided to consult with wider maintainers audience whether it's ok to accept the change as is or a more sophisticated solution needs to be found for the non-linear direct MMIO mapping. Cc: Christoph Hellwig Cc: Robin Murphy Cc: Manivannan Sadhasivam file: arch/arm/mach-orion5x/board-dt.c Cc: Andrew Lunn Cc: Sebastian Hesselbarth Cc: Gregory Clement Cc: linux-arm-kernel@lists.infradead.org file: drivers/crypto/marvell/cesa/cesa.c Cc: Srujana Challa Cc: Arnaud Ebalard Cc: Boris Brezillon Cc: linux-crypto@vger.kernel.org file: drivers/dma/{fsl-edma-common.c,pl330.c,sh/rcar-dmac.c} Cc: Vinod Koul Cc: dmaengine@vger.kernel.org file: arch/arm/boot/dts/{vfxxx.dtsi,ls1021a.dtsi,imx7ulp.dtsi,fsl-ls1043a.dtsi} Cc: Shawn Guo Cc: Sascha Hauer Cc: Li Yang Cc: linux-arm-kernel@lists.infradead.org file: arch/arm/boot/dts/r8a77*.dtsi, arch/arm64/boot/dts/renesas/r8a77*.dtsi Cc: Geert Uytterhoeven Cc: Magnus Damm Cc: linux-renesas-soc@vger.kernel.org file: drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c Cc: Alex Deucher Cc: "Christian König" Cc: "Pan, Xinhui" file: drivers/gpu/drm/virtio/virtgpu_vram.c Cc: David Airlie Cc: Gerd Hoffmann file: drivers/media/common/videobuf2/videobuf2-dma-contig.c Cc: Tomasz Figa Cc: Marek Szyprowski file: drivers/misc/habanalabs/common/memory.c Cc: Oded Gabbay Cc: Arnd Bergmann Cc: Greg Kroah-Hartman file: drivers/mtd/nand/raw/qcom_nandc.c Cc: Manivannan Sadhasivam file: arch/arm64/boot/dts/qcom/{ipq8074.dtsi,ipq6018.dtsi,qcom-sdx55.dtsi,qcom-ipq4019.dtsi,qcom-ipq8064.dtsi} Cc: Andy Gross Cc: Bjorn Andersson Cc: linux-arm-msm@vger.kernel.org file: drivers/net/ethernet/marvell/octeontx2/af/rvu.c Cc: Sunil Goutham Cc: Linu Cherian Cc: Geetha sowjanya file: drivers/ntb/ntb_transport.c Cc: Jon Mason Cc: Dave Jiang Cc: ntb@lists.linux.dev --- kernel/dma/direct.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index 9743c6ccce1a..bc06db74dfdb 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -497,7 +497,7 @@ int dma_direct_map_sg(struct device *dev, struct scatterlist *sgl, int nents, dma_addr_t dma_direct_map_resource(struct device *dev, phys_addr_t paddr, size_t size, enum dma_data_direction dir, unsigned long attrs) { - dma_addr_t dma_addr = paddr; + dma_addr_t dma_addr = phys_to_dma_direct(dev, paddr); if (unlikely(!dma_capable(dev, dma_addr, size, false))) { dev_err_once(dev,