public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Wu Fengguang <fengguang.wu@intel.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Matt Mackall <mpm@selenic.com>, Andi Kleen <andi@firstfloor.org>,
	LKML <linux-kernel@vger.kernel.org>,
	"Rafael J. Wysocki" <rjw@sisk.pl>
Subject: Re: 2.6.33 pagemap endless read loop
Date: Thu, 14 Jan 2010 16:06:01 +0800	[thread overview]
Message-ID: <20100114080600.GA4739@localhost> (raw)
In-Reply-To: <20100113221013.b1beecb4.akpm@linux-foundation.org>

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@intel.com> 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@firstfloor.org> 
CC: Matt Mackall <mpm@selenic.com>
CC: <stable@kernel.org>
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
---
 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)

  parent reply	other threads:[~2010-01-14  8:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-10  2:09 2.6.33 pagemap endless read loop Andi Kleen
2010-01-10  6:33 ` Américo Wang
2010-01-10 12:37   ` Andi Kleen
2010-01-12  5:59     ` Mike Galbraith
2010-01-12 15:32     ` Américo Wang
2010-01-12 16:28       ` Andi Kleen
2010-01-13  2:08         ` Américo Wang
     [not found] ` <20100113141648.42eff724.akpm@linux-foundation.org>
     [not found]   ` <1263421562.29868.5000.camel@calx>
     [not found]     ` <20100113143055.7bea30c5.akpm@linux-foundation.org>
     [not found]       ` <1263423916.29868.5009.camel@calx>
     [not found]         ` <20100113151502.fa425247.akpm@linux-foundation.org>
     [not found]           ` <20100114055319.GA17671@localhost>
     [not found]             ` <20100113221013.b1beecb4.akpm@linux-foundation.org>
2010-01-14  8:06               ` Wu Fengguang [this message]
2010-01-14  8:30                 ` Andi Kleen
2010-01-14  8:52                   ` [PATCH] pagemap: early return on unmapped areas Wu Fengguang
2010-01-14 17:02                     ` Matt Mackall

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=20100114080600.GA4739@localhost \
    --to=fengguang.wu@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=andi@firstfloor.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpm@selenic.com \
    --cc=rjw@sisk.pl \
    /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