Re: 2.6.33 pagemap endless read loop

From: Wu Fengguang
Date: Thu Jan 14 2010 - 03:15:13 EST


On Thu, Jan 14, 2010 at 02:10:13PM +0800, Andrew Morton wrote:
> On Thu, 14 Jan 2010 13:53:19 +0800 Wu Fengguang <fengguang.wu@xxxxxxxxx> wrote:
>
> > On Thu, Jan 14, 2010 at 07:15:02AM +0800, Andrew Morton wrote:

> > @@ -740,6 +740,11 @@ static ssize_t pagemap_read(struct file
> > if (!ptrace_may_access(task, PTRACE_MODE_READ))
> > goto out_task;
> >
> > + /* stop dumb cp/cat */
> > + ret = -EFAULT;
> > + if (!*ppos)
> > + goto out_task;
> > +
> > ret = -EINVAL;
> > /* file position must be aligned */
> > if ((*ppos % PM_ENTRY_BYTES) || (count % PM_ENTRY_BYTES))
>
> Seems simple. But is there a usecase for reading at that offset?
> I think it's possible to map a page at 0 with MAP_FIXED. I forget..

How about this trick?
Tests show that cp/cat will exit if read nothing :)

---
pagemap: early return on unmapped areas

This helps stop dumb cp/cat early instead of loop for days:

http://bugzilla.kernel.org/show_bug.cgi?id=15041

This also serves as an optimization to normal pagemap users (eg.
page-types).

CC: Andi Kleen <andi@xxxxxxxxxxxxxx>
CC: Matt Mackall <mpm@xxxxxxxxxxx>
CC: <stable@xxxxxxxxxx>
Signed-off-by: Wu Fengguang <fengguang.wu@xxxxxxxxx>
---
fs/proc/task_mmu.c | 4 ++++
1 file changed, 4 insertions(+)

--- linux-mm.orig/fs/proc/task_mmu.c 2010-01-14 13:38:44.000000000 +0800
+++ linux-mm/fs/proc/task_mmu.c 2010-01-14 15:54:28.000000000 +0800
@@ -586,6 +586,10 @@ static int pagemap_pte_hole(unsigned lon
struct pagemapread *pm = walk->private;
unsigned long addr;
int err = 0;
+
+ if ((end - start) / PAGE_SIZE > pm->end - pm->out)
+ return PM_END_OF_BUFFER;
+
for (addr = start; addr < end; addr += PAGE_SIZE) {
err = add_to_pagemap(addr, PM_NOT_PRESENT, pm);
if (err)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/