All of lore.kernel.org
 help / color / mirror / Atom feed
From: Johannes Weiner <hannes@cmpxchg.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: 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: Re: [patch 2/3] mm: use generic follow_pte() in follow_phys()
Date: Mon, 4 May 2009 12:08:03 +0200	[thread overview]
Message-ID: <20090504100803.GA12726@cmpxchg.org> (raw)
In-Reply-To: <1241430874-12667-2-git-send-email-hannes@cmpxchg.org>

On Mon, May 04, 2009 at 11:54:33AM +0200, Johannes Weiner wrote:
> Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
> ---
>  mm/memory.c |   37 ++++++-------------------------------
>  1 files changed, 6 insertions(+), 31 deletions(-)
> 
> diff --git a/mm/memory.c b/mm/memory.c
> index a621319..aee167d 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -3051,50 +3051,25 @@ int follow_phys(struct vm_area_struct *vma,
>  		unsigned long address, unsigned int flags,
>  		unsigned long *prot, resource_size_t *phys)
>  {
> -	pgd_t *pgd;
> -	pud_t *pud;
> -	pmd_t *pmd;
> +	int ret = -EINVAL;
>  	pte_t *ptep, pte;
>  	spinlock_t *ptl;
> -	resource_size_t phys_addr = 0;
> -	struct mm_struct *mm = vma->vm_mm;
> -	int ret = -EINVAL;
>  
>  	if (!(vma->vm_flags & (VM_IO | VM_PFNMAP)))
>  		goto out;
>  
> -	pgd = pgd_offset(mm, address);
> -	if (pgd_none(*pgd) || unlikely(pgd_bad(*pgd)))
> -		goto out;
> -
> -	pud = pud_offset(pgd, address);
> -	if (pud_none(*pud) || unlikely(pud_bad(*pud)))
> -		goto out;
> -
> -	pmd = pmd_offset(pud, address);
> -	if (pmd_none(*pmd) || unlikely(pmd_bad(*pmd)))
> -		goto out;
> -
> -	/* We cannot handle huge page PFN maps. Luckily they don't exist. */
> -	if (pmd_huge(*pmd))
> +	if (follow_pte(vma->vm_mm, address, &ptep, &ptl))
>  		goto out;
> -
> -	ptep = pte_offset_map_lock(mm, pmd, address, &ptl);
> -	if (!ptep)
> -		goto out;
> -
>  	pte = *ptep;
> -	if (!pte_present(pte))
> -		goto unlock;
> +
>  	if ((flags & FOLL_WRITE) && !pte_write(pte))
>  		goto unlock;
> -	phys_addr = pte_pfn(pte);
> -	phys_addr <<= PAGE_SHIFT; /* Shift here to avoid overflow on PAE */
>  
>  	*prot = pgprot_val(pte_pgprot(pte));
> -	*phys = phys_addr;
> -	ret = 0;
> +	/* Shift here to avoid overflow on PAE */
> +	*phys = pte_pfn(pte) << PAGE_SHIFT;

Yuk, had my head in the butt here.  Changed to

	*phys = (resource_size_t)pte_pfn(pte) << PAGE_SHIFT;

---
From: Johannes Weiner <hannes@cmpxchg.org>
Subject: mm: use generic follow_pte() in follow_phys()

Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
---
 mm/memory.c |   36 +++++-------------------------------
 1 files changed, 5 insertions(+), 31 deletions(-)

diff --git a/mm/memory.c b/mm/memory.c
index a621319..c047950 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3051,50 +3051,24 @@ int follow_phys(struct vm_area_struct *vma,
 		unsigned long address, unsigned int flags,
 		unsigned long *prot, resource_size_t *phys)
 {
-	pgd_t *pgd;
-	pud_t *pud;
-	pmd_t *pmd;
+	int ret = -EINVAL;
 	pte_t *ptep, pte;
 	spinlock_t *ptl;
-	resource_size_t phys_addr = 0;
-	struct mm_struct *mm = vma->vm_mm;
-	int ret = -EINVAL;
 
 	if (!(vma->vm_flags & (VM_IO | VM_PFNMAP)))
 		goto out;
 
-	pgd = pgd_offset(mm, address);
-	if (pgd_none(*pgd) || unlikely(pgd_bad(*pgd)))
-		goto out;
-
-	pud = pud_offset(pgd, address);
-	if (pud_none(*pud) || unlikely(pud_bad(*pud)))
-		goto out;
-
-	pmd = pmd_offset(pud, address);
-	if (pmd_none(*pmd) || unlikely(pmd_bad(*pmd)))
-		goto out;
-
-	/* We cannot handle huge page PFN maps. Luckily they don't exist. */
-	if (pmd_huge(*pmd))
+	if (follow_pte(vma->vm_mm, address, &ptep, &ptl))
 		goto out;
-
-	ptep = pte_offset_map_lock(mm, pmd, address, &ptl);
-	if (!ptep)
-		goto out;
-
 	pte = *ptep;
-	if (!pte_present(pte))
-		goto unlock;
+
 	if ((flags & FOLL_WRITE) && !pte_write(pte))
 		goto unlock;
-	phys_addr = pte_pfn(pte);
-	phys_addr <<= PAGE_SHIFT; /* Shift here to avoid overflow on PAE */
 
 	*prot = pgprot_val(pte_pgprot(pte));
-	*phys = phys_addr;
-	ret = 0;
+	*phys = (resource_size_t)pte_pfn(pte) << PAGE_SHIFT;
 
+	ret = 0;
 unlock:
 	pte_unmap_unlock(ptep, ptl);
 out:
-- 
1.6.2.1.135.gde769


WARNING: multiple messages have this Message-ID (diff)
From: Johannes Weiner <hannes@cmpxchg.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: 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: Re: [patch 2/3] mm: use generic follow_pte() in follow_phys()
Date: Mon, 4 May 2009 12:08:03 +0200	[thread overview]
Message-ID: <20090504100803.GA12726@cmpxchg.org> (raw)
In-Reply-To: <1241430874-12667-2-git-send-email-hannes@cmpxchg.org>

On Mon, May 04, 2009 at 11:54:33AM +0200, Johannes Weiner wrote:
> Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
> ---
>  mm/memory.c |   37 ++++++-------------------------------
>  1 files changed, 6 insertions(+), 31 deletions(-)
> 
> diff --git a/mm/memory.c b/mm/memory.c
> index a621319..aee167d 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -3051,50 +3051,25 @@ int follow_phys(struct vm_area_struct *vma,
>  		unsigned long address, unsigned int flags,
>  		unsigned long *prot, resource_size_t *phys)
>  {
> -	pgd_t *pgd;
> -	pud_t *pud;
> -	pmd_t *pmd;
> +	int ret = -EINVAL;
>  	pte_t *ptep, pte;
>  	spinlock_t *ptl;
> -	resource_size_t phys_addr = 0;
> -	struct mm_struct *mm = vma->vm_mm;
> -	int ret = -EINVAL;
>  
>  	if (!(vma->vm_flags & (VM_IO | VM_PFNMAP)))
>  		goto out;
>  
> -	pgd = pgd_offset(mm, address);
> -	if (pgd_none(*pgd) || unlikely(pgd_bad(*pgd)))
> -		goto out;
> -
> -	pud = pud_offset(pgd, address);
> -	if (pud_none(*pud) || unlikely(pud_bad(*pud)))
> -		goto out;
> -
> -	pmd = pmd_offset(pud, address);
> -	if (pmd_none(*pmd) || unlikely(pmd_bad(*pmd)))
> -		goto out;
> -
> -	/* We cannot handle huge page PFN maps. Luckily they don't exist. */
> -	if (pmd_huge(*pmd))
> +	if (follow_pte(vma->vm_mm, address, &ptep, &ptl))
>  		goto out;
> -
> -	ptep = pte_offset_map_lock(mm, pmd, address, &ptl);
> -	if (!ptep)
> -		goto out;
> -
>  	pte = *ptep;
> -	if (!pte_present(pte))
> -		goto unlock;
> +
>  	if ((flags & FOLL_WRITE) && !pte_write(pte))
>  		goto unlock;
> -	phys_addr = pte_pfn(pte);
> -	phys_addr <<= PAGE_SHIFT; /* Shift here to avoid overflow on PAE */
>  
>  	*prot = pgprot_val(pte_pgprot(pte));
> -	*phys = phys_addr;
> -	ret = 0;
> +	/* Shift here to avoid overflow on PAE */
> +	*phys = pte_pfn(pte) << PAGE_SHIFT;

Yuk, had my head in the butt here.  Changed to

	*phys = (resource_size_t)pte_pfn(pte) << PAGE_SHIFT;

---
From: Johannes Weiner <hannes@cmpxchg.org>
Subject: mm: use generic follow_pte() in follow_phys()

Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
---
 mm/memory.c |   36 +++++-------------------------------
 1 files changed, 5 insertions(+), 31 deletions(-)

diff --git a/mm/memory.c b/mm/memory.c
index a621319..c047950 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -3051,50 +3051,24 @@ int follow_phys(struct vm_area_struct *vma,
 		unsigned long address, unsigned int flags,
 		unsigned long *prot, resource_size_t *phys)
 {
-	pgd_t *pgd;
-	pud_t *pud;
-	pmd_t *pmd;
+	int ret = -EINVAL;
 	pte_t *ptep, pte;
 	spinlock_t *ptl;
-	resource_size_t phys_addr = 0;
-	struct mm_struct *mm = vma->vm_mm;
-	int ret = -EINVAL;
 
 	if (!(vma->vm_flags & (VM_IO | VM_PFNMAP)))
 		goto out;
 
-	pgd = pgd_offset(mm, address);
-	if (pgd_none(*pgd) || unlikely(pgd_bad(*pgd)))
-		goto out;
-
-	pud = pud_offset(pgd, address);
-	if (pud_none(*pud) || unlikely(pud_bad(*pud)))
-		goto out;
-
-	pmd = pmd_offset(pud, address);
-	if (pmd_none(*pmd) || unlikely(pmd_bad(*pmd)))
-		goto out;
-
-	/* We cannot handle huge page PFN maps. Luckily they don't exist. */
-	if (pmd_huge(*pmd))
+	if (follow_pte(vma->vm_mm, address, &ptep, &ptl))
 		goto out;
-
-	ptep = pte_offset_map_lock(mm, pmd, address, &ptl);
-	if (!ptep)
-		goto out;
-
 	pte = *ptep;
-	if (!pte_present(pte))
-		goto unlock;
+
 	if ((flags & FOLL_WRITE) && !pte_write(pte))
 		goto unlock;
-	phys_addr = pte_pfn(pte);
-	phys_addr <<= PAGE_SHIFT; /* Shift here to avoid overflow on PAE */
 
 	*prot = pgprot_val(pte_pgprot(pte));
-	*phys = phys_addr;
-	ret = 0;
+	*phys = (resource_size_t)pte_pfn(pte) << PAGE_SHIFT;
 
+	ret = 0;
 unlock:
 	pte_unmap_unlock(ptep, ptl);
 out:
-- 
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>

  reply	other threads:[~2009-05-04 10:09 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 [this message]
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         ` [patch 3/3 v2] " Johannes Weiner
2009-05-04 13:13           ` 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=20090504100803.GA12726@cmpxchg.org \
    --to=hannes@cmpxchg.org \
    --cc=akpm@linux-foundation.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.