From: Sinan Kaya <okaya@codeaurora.org>
To: Stefano Stabellini <sstabellini@kernel.org>,
Konrad Rzeszutek Wilk <konrad@kernel.org>
Cc: Robin Murphy <robin.murphy@arm.com>,
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 <catalin.marinas@arm.com>,
Will Deacon <will.deacon@arm.com>,
Max Filippov <jcmvbkbc@gmail.com>,
Chris Metcalf <cmetcalf@ezchip.com>,
Paul Mackerras <paulus@samba.org>,
"H. Peter Anvin" <hpa@zytor.com>, Huacai Chen <chenhc@lemote.com>,
Guan Xuetao <gxt@mprc.pku.edu.cn>,
Marek Szyprowski <m.szyprowski@samsung.com>,
Jisheng Zhang <jszhang@marvell.com>,
Florian Fainelli <f.fainelli@gmail.com>,
Russell King <linux@arm.linux.org.uk>,
Aaro Koskinen <aaro.koskinen@iki.fi>,
Michael Ellerman <mpe@ellerman.id.au>, X86 <x86@kernel.org>,
Ingo Molnar <mingo@redhat.com>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Guenter Roeck <linux@roeck-us.net>,
Fenghua Yu <fenghua.yu@intel.com>,
Denys Vlasenko <dvlasenk@redhat.com>,
Arnd Bergmann <arnd@arndb.de>,
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
Akinobu Mita <akinobu.mita@gmail.com>,
Bjorn Helgaas <bhelgaas@google.com>,
Thomas Gleixner <tglx@linutronix.de>,
Valentin Rothberg <valentinrothberg@gmail.com>,
Chris Zankel <chris@zankel.net>, Tony Luck <tony.luck@intel.com>,
linux-pci@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
Dean Nelson <dnelson@redhat.com>,
LKML <linux-kernel@vger.kernel.org>,
Ralf Baechle <ralf@linux-mips.org>,
"Suthikulpanit, Suravee" <Suravee.Suthikulpanit@amd.com>,
Joe Perches <joe@perches.com>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 2/3] swiotlb: prefix dma_to_phys and phys_to_dma functions
Date: Tue, 29 Mar 2016 08:57:45 -0400 [thread overview]
Message-ID: <56FA7BC9.2010903@codeaurora.org> (raw)
In-Reply-To: <alpine.DEB.2.02.1603291329460.18380@kaball.uk.xensource.com>
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
next prev parent reply other threads:[~2016-03-29 12:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1458252137-24497-1-git-send-email-okaya@codeaurora.org>
2016-03-17 22:02 ` [PATCH 2/3] swiotlb: prefix dma_to_phys and phys_to_dma functions Sinan Kaya
2016-03-18 12:12 ` Robin Murphy
2016-03-18 15:00 ` Sinan Kaya
2016-03-28 18:29 ` Konrad Rzeszutek Wilk
2016-03-29 12:44 ` Stefano Stabellini
2016-03-29 12:57 ` Sinan Kaya [this message]
2016-03-29 19:32 ` Arnd Bergmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56FA7BC9.2010903@codeaurora.org \
--to=okaya@codeaurora.org \
--cc=Suravee.Suthikulpanit@amd.com \
--cc=aaro.koskinen@iki.fi \
--cc=akinobu.mita@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=benh@kernel.crashing.org \
--cc=bhelgaas@google.com \
--cc=catalin.marinas@arm.com \
--cc=chenhc@lemote.com \
--cc=chris@zankel.net \
--cc=cmetcalf@ezchip.com \
--cc=cov@codeaurora.org \
--cc=dnelson@redhat.com \
--cc=dvlasenk@redhat.com \
--cc=f.fainelli@gmail.com \
--cc=fenghua.yu@intel.com \
--cc=gxt@mprc.pku.edu.cn \
--cc=hpa@zytor.com \
--cc=jcmvbkbc@gmail.com \
--cc=joe@perches.com \
--cc=jszhang@marvell.com \
--cc=konrad.wilk@oracle.com \
--cc=konrad@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-ia64@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@linux-mips.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-xtensa@linux-xtensa.org \
--cc=linux@arm.linux.org.uk \
--cc=linux@roeck-us.net \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=m.szyprowski@samsung.com \
--cc=mingo@redhat.com \
--cc=mpe@ellerman.id.au \
--cc=nwatters@codeaurora.org \
--cc=paulus@samba.org \
--cc=ralf@linux-mips.org \
--cc=robin.murphy@arm.com \
--cc=sstabellini@kernel.org \
--cc=tglx@linutronix.de \
--cc=timur@codeaurora.org \
--cc=tony.luck@intel.com \
--cc=valentinrothberg@gmail.com \
--cc=will.deacon@arm.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).