From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.codeaurora.org (smtp.codeaurora.org [198.145.29.96]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3qZ9mf6SK0zDq5d for ; Tue, 29 Mar 2016 23:57:54 +1100 (AEDT) Subject: Re: [PATCH 2/3] swiotlb: prefix dma_to_phys and phys_to_dma functions To: Stefano Stabellini , Konrad Rzeszutek Wilk References: <1458252137-24497-1-git-send-email-okaya@codeaurora.org> <1458252137-24497-2-git-send-email-okaya@codeaurora.org> <56EBF09A.1060503@arm.com> <56EC1805.5060207@codeaurora.org> Cc: Robin Murphy , linux-arm-kernel@lists.infradead.org, timur@codeaurora.org, cov@codeaurora.org, nwatters@codeaurora.org, linux-mips@linux-mips.org, linux-ia64@vger.kernel.org, linux-xtensa@linux-xtensa.org, Catalin Marinas , Will Deacon , Max Filippov , Chris Metcalf , Paul Mackerras , "H. Peter Anvin" , Huacai Chen , Guan Xuetao , Marek Szyprowski , Jisheng Zhang , Florian Fainelli , Russell King , Aaro Koskinen , Michael Ellerman , X86 , Ingo Molnar , Benjamin Herrenschmidt , Guenter Roeck , Fenghua Yu , Denys Vlasenko , Arnd Bergmann , Konrad Rzeszutek Wilk , Akinobu Mita , Bjorn Helgaas , Thomas Gleixner , Valentin Rothberg , Chris Zankel , Tony Luck , linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Dean Nelson , LKML , Ralf Baechle , "Suthikulpanit, Suravee" , Joe Perches , Andrew Morton From: Sinan Kaya Message-ID: <56FA7BC9.2010903@codeaurora.org> Date: Tue, 29 Mar 2016 08:57:45 -0400 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , On 3/29/2016 8:44 AM, Stefano Stabellini wrote: > Could you please explain what is the problem that you are trying to > solve? In other words, what is the issue with assuming that physical > address = dma address (and the current dma_to_phys and phys_to_dma > static inlines) if no arm64 platforms violate it? That's pretty much > what is done on x86 too (without X86_DMA_REMAP). > > If you want to make sure that the assumption is not violated, you can > introduce a boot time check or a BUG_ON somewhere. > > If there is an arm64 platform with phys_addr != dma_addr, we need proper > support for it. In fact even if there is an IOMMU on that platform, when > running Xen on it, the IOMMU would be used by the hypervisor and Linux > would still end up without it, using the swiotlb. The problem is that device drivers are trying to use dma_to_phys and phys_to_dma APIs to do address translation even though these two API do not exist in DMA mapping layer. (see patch #1 and I made the same mistake in my HIDMA code) Especially, when a device is behind an IOMMU; the DMA addresses are not equal to physical addresses. Usage of dma_to_phys causes a crash on the system. I'm trying to prefix the dma_to_phys and phys_to_dma API with swiotlb so that we know what it is intended for and usage of these API in drivers need to be discouraged in the future during code reviews. Since I renamed the API, Robin Murphy made a suggestion to convert this phys_to_virt(swiotlb_dma_to_phys(dev, dma_handle)) to this #define swiotlb_to_virt(addr) phys_to_virt((phys_addr_t)(addr)) swiotlb_to_virt(dma_handle) just to reduce code clutter since we know swiotlb_dma_to_phys returns phys already for ARM64 architecture. I think we can do this exercise later. I'll undo this change for the moment. Let's focus on the API rename. I don't want this general purpose dma_to_phys API returning phys=dma value. This is not correct. -- Sinan Kaya Qualcomm Technologies, Inc. on behalf of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project