From: "Ørjan Eide" <orjan.eide@arm.com>
To: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
linux-rockchip@lists.infradead.org
Cc: djkurtz@chromium.org
Subject: [PATCH 2/2] ARM: DMA: Use vm_pgoff for IOMMU mmap
Date: Thu, 16 Apr 2015 16:41:52 +0200 [thread overview]
Message-ID: <1429195312-25898-2-git-send-email-orjan.eide@arm.com> (raw)
In-Reply-To: <1429195312-25898-1-git-send-email-orjan.eide@arm.com>
arm_iommu_mmap_attrs() ignores the page offset in vma->vm_pgoff that was
specified in the mmap call. Any user of dma_mmap_* will get an
unexpected result when the device uses the IOMMU DMA ops.
Some DRM driver that use dma_mmap_* seems to depend on it ignoring
vma->vm_pgoff. Both the Samsung Exynos DRM driver before v3.18, and the
current Rockchip DRM driver, use the page offset to pass GEM cookies
that are used to look up the GEM buffers and then call dma_mmap_attrs()
with the cookie value still in vma->vm_pgoff.
rockchip_gem_mmap_buf() in drivers/gpu/drm/rockchip/rockchip_drm_gem.c
still does this. It should be fixed before fixing
arm_iommu_mmap_attrs().
Signed-off-by: Ørjan Eide <orjan.eide@arm.com>
---
arch/arm/mm/dma-mapping.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index c274476..07d571b 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -1364,6 +1364,9 @@ static int arm_iommu_mmap_attrs(struct device *dev, struct vm_area_struct *vma,
{
unsigned long uaddr = vma->vm_start;
unsigned long usize = vma->vm_end - vma->vm_start;
+ unsigned long nr_vma_pages = usize >> PAGE_SHIFT;
+ unsigned long nr_pages = PAGE_ALIGN(size) >> PAGE_SHIFT;
+ unsigned long off = vma->vm_pgoff;
struct page **pages = __iommu_get_pages(cpu_addr, attrs);
vma->vm_page_prot = __get_dma_pgprot(attrs, vma->vm_page_prot);
@@ -1371,6 +1374,11 @@ static int arm_iommu_mmap_attrs(struct device *dev, struct vm_area_struct *vma,
if (!pages)
return -ENXIO;
+ if (off >= nr_pages || nr_vma_pages > (nr_pages - off))
+ return -ENXIO;
+
+ pages += off;
+
do {
int ret = vm_insert_page(vma, uaddr, *pages++);
if (ret) {
--
1.9.1
next prev parent reply other threads:[~2015-04-16 14:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-16 14:41 [PATCH 1/2] drm: rockchip: Don't pass DRM fake offset to dma-api Ørjan Eide
2015-04-16 14:41 ` Ørjan Eide [this message]
2015-04-20 4:13 ` [PATCH 2/2] ARM: DMA: Use vm_pgoff for IOMMU mmap Daniel Kurtz
2015-04-18 16:55 ` [PATCH 1/2] drm: rockchip: Don't pass DRM fake offset to dma-api Heiko Stübner
2015-04-20 5:34 ` Mark yao
2015-04-20 5:44 ` Mark yao
2015-07-07 7:02 ` Daniel Kurtz
2015-04-20 4:13 ` Daniel Kurtz
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=1429195312-25898-2-git-send-email-orjan.eide@arm.com \
--to=orjan.eide@arm.com \
--cc=djkurtz@chromium.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.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
all inboxes | Powered by JetHome®