From: Johannes Weiner <hannes@cmpxchg.org>
To: Christoph Hellwig <hch@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Magnus Damm <magnus.damm@gmail.com>,
linux-media@vger.kernel.org, Hans Verkuil <hverkuil@xs4all.nl>,
Paul Mundt <lethal@linux-sh.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [patch 3/3 v2] mm: introduce follow_pfn()
Date: Mon, 4 May 2009 15:13:59 +0200 [thread overview]
Message-ID: <20090504131359.GA17887@cmpxchg.org> (raw)
In-Reply-To: <20090504110841.GA19646@infradead.org>
Analoguous to follow_phys(), add a helper that looks up the PFN at a
user virtual address in an IO mapping or a raw PFN mapping.
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
---
include/linux/mm.h | 2 ++
mm/memory.c | 29 +++++++++++++++++++++++++++++
2 files changed, 31 insertions(+), 0 deletions(-)
On Mon, May 04, 2009 at 07:08:41AM -0400, Christoph Hellwig wrote:
> On Mon, May 04, 2009 at 11:54:34AM +0200, Johannes Weiner wrote:
> > Analoguous to follow_phys(), add a helper that looks up the PFN
> > instead. It also only allows IO mappings or PFN mappings.
>
> A kerneldoc describing what it does and the limitations would be
> extremly helpful.
Agreed. How is this?
diff --git a/include/linux/mm.h b/include/linux/mm.h
index bff1f0d..1cca8b6 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -794,6 +794,8 @@ int copy_page_range(struct mm_struct *dst, struct mm_struct *src,
struct vm_area_struct *vma);
void unmap_mapping_range(struct address_space *mapping,
loff_t const holebegin, loff_t const holelen, int even_cows);
+int follow_pfn(struct vm_area_struct *vma, unsigned long address,
+ unsigned long *pfn);
int follow_phys(struct vm_area_struct *vma, unsigned long address,
unsigned int flags, unsigned long *prot, resource_size_t *phys);
int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
diff --git a/mm/memory.c b/mm/memory.c
index c047950..f86aee1 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3046,6 +3046,35 @@ out:
return -EINVAL;
}
+/**
+ * follow_pfn - look up PFN at a user virtual address
+ * @vma: memory mapping
+ * @address: user virtual address
+ * @pfn: location to store found PFN
+ *
+ * Only IO mappings and raw PFN mappings are allowed.
+ *
+ * Returns zero and the pfn at @pfn on success, -ve otherwise.
+ */
+int follow_pfn(struct vm_area_struct *vma, unsigned long address,
+ unsigned long *pfn)
+{
+ int ret = -EINVAL;
+ spinlock_t *ptl;
+ pte_t *ptep;
+
+ if (!(vma->vm_flags & (VM_IO | VM_PFNMAP)))
+ return ret;
+
+ ret = follow_pte(vma->vm_mm, address, &ptep, &ptl);
+ if (ret)
+ return ret;
+ *pfn = pte_pfn(*ptep);
+ pte_unmap_unlock(ptep, ptl);
+ return 0;
+}
+EXPORT_SYMBOL(follow_pfn);
+
#ifdef CONFIG_HAVE_IOREMAP_PROT
int follow_phys(struct vm_area_struct *vma,
unsigned long address, unsigned int flags,
--
1.6.2.1.135.gde769
WARNING: multiple messages have this Message-ID (diff)
From: Johannes Weiner <hannes@cmpxchg.org>
To: Christoph Hellwig <hch@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Magnus Damm <magnus.damm@gmail.com>,
linux-media@vger.kernel.org, Hans Verkuil <hverkuil@xs4all.nl>,
Paul Mundt <lethal@linux-sh.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [patch 3/3 v2] mm: introduce follow_pfn()
Date: Mon, 4 May 2009 15:13:59 +0200 [thread overview]
Message-ID: <20090504131359.GA17887@cmpxchg.org> (raw)
In-Reply-To: <20090504110841.GA19646@infradead.org>
Analoguous to follow_phys(), add a helper that looks up the PFN at a
user virtual address in an IO mapping or a raw PFN mapping.
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
---
include/linux/mm.h | 2 ++
mm/memory.c | 29 +++++++++++++++++++++++++++++
2 files changed, 31 insertions(+), 0 deletions(-)
On Mon, May 04, 2009 at 07:08:41AM -0400, Christoph Hellwig wrote:
> On Mon, May 04, 2009 at 11:54:34AM +0200, Johannes Weiner wrote:
> > Analoguous to follow_phys(), add a helper that looks up the PFN
> > instead. It also only allows IO mappings or PFN mappings.
>
> A kerneldoc describing what it does and the limitations would be
> extremly helpful.
Agreed. How is this?
diff --git a/include/linux/mm.h b/include/linux/mm.h
index bff1f0d..1cca8b6 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -794,6 +794,8 @@ int copy_page_range(struct mm_struct *dst, struct mm_struct *src,
struct vm_area_struct *vma);
void unmap_mapping_range(struct address_space *mapping,
loff_t const holebegin, loff_t const holelen, int even_cows);
+int follow_pfn(struct vm_area_struct *vma, unsigned long address,
+ unsigned long *pfn);
int follow_phys(struct vm_area_struct *vma, unsigned long address,
unsigned int flags, unsigned long *prot, resource_size_t *phys);
int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
diff --git a/mm/memory.c b/mm/memory.c
index c047950..f86aee1 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3046,6 +3046,35 @@ out:
return -EINVAL;
}
+/**
+ * follow_pfn - look up PFN at a user virtual address
+ * @vma: memory mapping
+ * @address: user virtual address
+ * @pfn: location to store found PFN
+ *
+ * Only IO mappings and raw PFN mappings are allowed.
+ *
+ * Returns zero and the pfn at @pfn on success, -ve otherwise.
+ */
+int follow_pfn(struct vm_area_struct *vma, unsigned long address,
+ unsigned long *pfn)
+{
+ int ret = -EINVAL;
+ spinlock_t *ptl;
+ pte_t *ptep;
+
+ if (!(vma->vm_flags & (VM_IO | VM_PFNMAP)))
+ return ret;
+
+ ret = follow_pte(vma->vm_mm, address, &ptep, &ptl);
+ if (ret)
+ return ret;
+ *pfn = pte_pfn(*ptep);
+ pte_unmap_unlock(ptep, ptl);
+ return 0;
+}
+EXPORT_SYMBOL(follow_pfn);
+
#ifdef CONFIG_HAVE_IOREMAP_PROT
int follow_phys(struct vm_area_struct *vma,
unsigned long address, unsigned int flags,
--
1.6.2.1.135.gde769
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2009-05-04 13:16 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-28 9:01 [PATCH] videobuf-dma-contig: zero copy USERPTR support V2 Magnus Damm
2009-04-28 9:01 ` Magnus Damm
2009-05-01 3:26 ` Magnus Damm
2009-05-01 3:26 ` Magnus Damm
2009-05-01 18:14 ` Johannes Weiner
2009-05-01 18:14 ` Johannes Weiner
2009-05-04 9:54 ` [patch 1/3] mm: introduce follow_pte() Johannes Weiner
2009-05-04 9:54 ` Johannes Weiner
2009-05-05 19:24 ` Andrew Morton
2009-05-05 19:24 ` Andrew Morton
2009-05-05 20:38 ` Johannes Weiner
2009-05-05 20:38 ` Johannes Weiner
2009-05-05 21:05 ` Andrew Morton
2009-05-05 21:05 ` Andrew Morton
2009-05-05 21:21 ` Johannes Weiner
2009-05-05 21:21 ` Johannes Weiner
2009-05-08 8:51 ` Magnus Damm
2009-05-08 8:51 ` Magnus Damm
2009-05-04 9:54 ` [patch 2/3] mm: use generic follow_pte() in follow_phys() Johannes Weiner
2009-05-04 9:54 ` Johannes Weiner
2009-05-04 10:08 ` Johannes Weiner
2009-05-04 10:08 ` Johannes Weiner
2009-05-04 9:54 ` [patch 3/3] mm: introduce follow_pfn() Johannes Weiner
2009-05-04 9:54 ` Johannes Weiner
2009-05-04 11:08 ` Christoph Hellwig
2009-05-04 11:08 ` Christoph Hellwig
2009-05-04 13:13 ` Johannes Weiner [this message]
2009-05-04 13:13 ` [patch 3/3 v2] " Johannes Weiner
2009-05-04 14:31 ` Christoph Hellwig
2009-05-04 14:31 ` Christoph Hellwig
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=20090504131359.GA17887@cmpxchg.org \
--to=hannes@cmpxchg.org \
--cc=akpm@linux-foundation.org \
--cc=hch@infradead.org \
--cc=hverkuil@xs4all.nl \
--cc=lethal@linux-sh.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=magnus.damm@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.