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: 12876670 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F37A1C433EF for ; Fri, 10 Jun 2022 08:14:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343996AbiFJIOx (ORCPT ); Fri, 10 Jun 2022 04:14:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346746AbiFJIOv (ORCPT ); Fri, 10 Jun 2022 04:14:51 -0400 X-Greylist: delayed 393 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 10 Jun 2022 01:14:49 PDT Received: from mail.baikalelectronics.com (mail.baikalelectronics.com [87.245.175.230]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C10D3A5AAA; Fri, 10 Jun 2022 01:14:49 -0700 (PDT) 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) Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.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,