All of lore.kernel.org
 help / color / mirror / Atom feed
* [BUGFIX][PATCH] pagemap: set pagemap walk limit to PMD boundary
@ 2010-11-19  9:07 Naoya Horiguchi
  2010-11-22  3:01   ` KAMEZAWA Hiroyuki
  0 siblings, 1 reply; 5+ messages in thread
From: Naoya Horiguchi @ 2010-11-19  9:07 UTC (permalink / raw)
  To: LKML
  Cc: linux-mm, Andrew Morton, Jun'ichi Nomura, KAMEZAWA Hiroyuki,
	Matt Mackall

Currently one pagemap_read() call walks in PAGEMAP_WALK_SIZE bytes
(== 512 pages.)  But there is a corner case where walk_pmd_range()
accidentally runs over a VMA associated with a hugetlbfs file.

For example, when a process has mappings to VMAs as shown below:

  # cat /proc/<pid>/maps
  ...
  3a58f6d000-3a58f72000 rw-p 00000000 00:00 0
  7fbd51853000-7fbd51855000 rw-p 00000000 00:00 0
  7fbd5186c000-7fbd5186e000 rw-p 00000000 00:00 0
  7fbd51a00000-7fbd51c00000 rw-s 00000000 00:12 8614   /hugepages/test

then pagemap_read() goes into walk_pmd_range() path and walks in the range
0x7fbd51853000-0x7fbd51a53000, but the hugetlbfs VMA should be handled
by walk_hugetlb_range(). Otherwise PMD for the hugepage is considered bad
and cleared, which causes undesirable results.

This patch fixes it by separating pagemap walk range into one PMD.

Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jun'ichi Nomura <j-nomura@ce.jp.nec.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Cc: Matt Mackall <mpm@selenic.com>
---
 fs/proc/task_mmu.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index da6b01d..c126c83 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -706,6 +706,7 @@ static int pagemap_hugetlb_range(pte_t *pte, unsigned long hmask,
  * skip over unmapped regions.
  */
 #define PAGEMAP_WALK_SIZE	(PMD_SIZE)
+#define PAGEMAP_WALK_MASK	(PMD_MASK)
 static ssize_t pagemap_read(struct file *file, char __user *buf,
 			    size_t count, loff_t *ppos)
 {
@@ -776,7 +777,7 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
 		unsigned long end;
 
 		pm.pos = 0;
-		end = start_vaddr + PAGEMAP_WALK_SIZE;
+		end = (start_vaddr + PAGEMAP_WALK_SIZE) & PAGEMAP_WALK_MASK;
 		/* overflow ? */
 		if (end < start_vaddr || end > end_vaddr)
 			end = end_vaddr;
-- 
1.7.2.3

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [BUGFIX][PATCH] pagemap: set pagemap walk limit to PMD boundary
  2010-11-19  9:07 [BUGFIX][PATCH] pagemap: set pagemap walk limit to PMD boundary Naoya Horiguchi
@ 2010-11-22  3:01   ` KAMEZAWA Hiroyuki
  0 siblings, 0 replies; 5+ messages in thread
From: KAMEZAWA Hiroyuki @ 2010-11-22  3:01 UTC (permalink / raw)
  To: Naoya Horiguchi
  Cc: LKML, linux-mm, Andrew Morton, Jun'ichi Nomura, Matt Mackall

On Fri, 19 Nov 2010 18:07:45 +0900
Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> wrote:

> Currently one pagemap_read() call walks in PAGEMAP_WALK_SIZE bytes
> (== 512 pages.)  But there is a corner case where walk_pmd_range()
> accidentally runs over a VMA associated with a hugetlbfs file.
> 
> For example, when a process has mappings to VMAs as shown below:
> 
>   # cat /proc/<pid>/maps
>   ...
>   3a58f6d000-3a58f72000 rw-p 00000000 00:00 0
>   7fbd51853000-7fbd51855000 rw-p 00000000 00:00 0
>   7fbd5186c000-7fbd5186e000 rw-p 00000000 00:00 0
>   7fbd51a00000-7fbd51c00000 rw-s 00000000 00:12 8614   /hugepages/test
> 
> then pagemap_read() goes into walk_pmd_range() path and walks in the range
> 0x7fbd51853000-0x7fbd51a53000, but the hugetlbfs VMA should be handled
> by walk_hugetlb_range(). Otherwise PMD for the hugepage is considered bad
> and cleared, which causes undesirable results.
> 
> This patch fixes it by separating pagemap walk range into one PMD.
> 
> Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Jun'ichi Nomura <j-nomura@ce.jp.nec.com>
> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> Cc: Matt Mackall <mpm@selenic.com>
> ---
>  fs/proc/task_mmu.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
> 
> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> index da6b01d..c126c83 100644
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -706,6 +706,7 @@ static int pagemap_hugetlb_range(pte_t *pte, unsigned long hmask,
>   * skip over unmapped regions.
>   */
>  #define PAGEMAP_WALK_SIZE	(PMD_SIZE)
> +#define PAGEMAP_WALK_MASK	(PMD_MASK)
>  static ssize_t pagemap_read(struct file *file, char __user *buf,
>  			    size_t count, loff_t *ppos)
>  {
> @@ -776,7 +777,7 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
>  		unsigned long end;
>  
>  		pm.pos = 0;
> -		end = start_vaddr + PAGEMAP_WALK_SIZE;
> +		end = (start_vaddr + PAGEMAP_WALK_SIZE) & PAGEMAP_WALK_MASK;
>  		/* overflow ? */
>  		if (end < start_vaddr || end > end_vaddr)
>  			end = end_vaddr;

Ack. 

But ALIGN() can't be used ?

Thanks,
-Kame




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [BUGFIX][PATCH] pagemap: set pagemap walk limit to PMD boundary
@ 2010-11-22  3:01   ` KAMEZAWA Hiroyuki
  0 siblings, 0 replies; 5+ messages in thread
From: KAMEZAWA Hiroyuki @ 2010-11-22  3:01 UTC (permalink / raw)
  To: Naoya Horiguchi
  Cc: LKML, linux-mm, Andrew Morton, Jun'ichi Nomura, Matt Mackall

On Fri, 19 Nov 2010 18:07:45 +0900
Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> wrote:

> Currently one pagemap_read() call walks in PAGEMAP_WALK_SIZE bytes
> (== 512 pages.)  But there is a corner case where walk_pmd_range()
> accidentally runs over a VMA associated with a hugetlbfs file.
> 
> For example, when a process has mappings to VMAs as shown below:
> 
>   # cat /proc/<pid>/maps
>   ...
>   3a58f6d000-3a58f72000 rw-p 00000000 00:00 0
>   7fbd51853000-7fbd51855000 rw-p 00000000 00:00 0
>   7fbd5186c000-7fbd5186e000 rw-p 00000000 00:00 0
>   7fbd51a00000-7fbd51c00000 rw-s 00000000 00:12 8614   /hugepages/test
> 
> then pagemap_read() goes into walk_pmd_range() path and walks in the range
> 0x7fbd51853000-0x7fbd51a53000, but the hugetlbfs VMA should be handled
> by walk_hugetlb_range(). Otherwise PMD for the hugepage is considered bad
> and cleared, which causes undesirable results.
> 
> This patch fixes it by separating pagemap walk range into one PMD.
> 
> Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Jun'ichi Nomura <j-nomura@ce.jp.nec.com>
> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
> Cc: Matt Mackall <mpm@selenic.com>
> ---
>  fs/proc/task_mmu.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
> 
> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> index da6b01d..c126c83 100644
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -706,6 +706,7 @@ static int pagemap_hugetlb_range(pte_t *pte, unsigned long hmask,
>   * skip over unmapped regions.
>   */
>  #define PAGEMAP_WALK_SIZE	(PMD_SIZE)
> +#define PAGEMAP_WALK_MASK	(PMD_MASK)
>  static ssize_t pagemap_read(struct file *file, char __user *buf,
>  			    size_t count, loff_t *ppos)
>  {
> @@ -776,7 +777,7 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
>  		unsigned long end;
>  
>  		pm.pos = 0;
> -		end = start_vaddr + PAGEMAP_WALK_SIZE;
> +		end = (start_vaddr + PAGEMAP_WALK_SIZE) & PAGEMAP_WALK_MASK;
>  		/* overflow ? */
>  		if (end < start_vaddr || end > end_vaddr)
>  			end = end_vaddr;

Ack. 

But ALIGN() can't be used ?

Thanks,
-Kame



--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [BUGFIX][PATCH] pagemap: set pagemap walk limit to PMD boundary
  2010-11-22  3:01   ` KAMEZAWA Hiroyuki
@ 2010-11-22  4:09     ` Naoya Horiguchi
  -1 siblings, 0 replies; 5+ messages in thread
From: Naoya Horiguchi @ 2010-11-22  4:09 UTC (permalink / raw)
  To: KAMEZAWA Hiroyuki
  Cc: LKML, linux-mm, Andrew Morton, Jun'ichi Nomura, Matt Mackall

> > @@ -776,7 +777,7 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
> >  		unsigned long end;
> >
> >  		pm.pos = 0;
> > -		end = start_vaddr + PAGEMAP_WALK_SIZE;
> > +		end = (start_vaddr + PAGEMAP_WALK_SIZE) & PAGEMAP_WALK_MASK;
> >  		/* overflow ? */
> >  		if (end < start_vaddr || end > end_vaddr)
> >  			end = end_vaddr;
>
> Ack.
>
> But ALIGN() can't be used ?

ALIGN() returns the same address as the input if it is already aligned,
but what we need here is the next PMD boundary. So something like

                end = IS_ALIGNED(start_vaddr, PAGEMAP_WALK_SIZE) ?
                        start_vaddr + PAGEMAP_WALK_SIZE :
                        ALIGN(start_vaddr, PAGEMAP_WALK_SIZE)          

keeps the semantics, but I don't like it because it's lengthy.

Anyway, thanks for your comment.

Naoya Horiguchi

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [BUGFIX][PATCH] pagemap: set pagemap walk limit to PMD boundary
@ 2010-11-22  4:09     ` Naoya Horiguchi
  0 siblings, 0 replies; 5+ messages in thread
From: Naoya Horiguchi @ 2010-11-22  4:09 UTC (permalink / raw)
  To: KAMEZAWA Hiroyuki
  Cc: LKML, linux-mm, Andrew Morton, Jun'ichi Nomura, Matt Mackall

> > @@ -776,7 +777,7 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
> >  		unsigned long end;
> >
> >  		pm.pos = 0;
> > -		end = start_vaddr + PAGEMAP_WALK_SIZE;
> > +		end = (start_vaddr + PAGEMAP_WALK_SIZE) & PAGEMAP_WALK_MASK;
> >  		/* overflow ? */
> >  		if (end < start_vaddr || end > end_vaddr)
> >  			end = end_vaddr;
>
> Ack.
>
> But ALIGN() can't be used ?

ALIGN() returns the same address as the input if it is already aligned,
but what we need here is the next PMD boundary. So something like

                end = IS_ALIGNED(start_vaddr, PAGEMAP_WALK_SIZE) ?
                        start_vaddr + PAGEMAP_WALK_SIZE :
                        ALIGN(start_vaddr, PAGEMAP_WALK_SIZE)          

keeps the semantics, but I don't like it because it's lengthy.

Anyway, thanks for your comment.

Naoya Horiguchi

--
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/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-11-22  4:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-19  9:07 [BUGFIX][PATCH] pagemap: set pagemap walk limit to PMD boundary Naoya Horiguchi
2010-11-22  3:01 ` KAMEZAWA Hiroyuki
2010-11-22  3:01   ` KAMEZAWA Hiroyuki
2010-11-22  4:09   ` Naoya Horiguchi
2010-11-22  4:09     ` Naoya Horiguchi

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.