public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: Make copy_from_user() in migrate.c statically predictable
@ 2010-02-18 22:43 H. Peter Anvin
  2010-02-18 23:02 ` Linus Torvalds
  0 siblings, 1 reply; 7+ messages in thread
From: H. Peter Anvin @ 2010-02-18 22:43 UTC (permalink / raw)
  To: torvalds
  Cc: linux-kernel, H. Peter Anvin, Arjan van de Ven, Andrew Morton,
	KOSAKI Motohiro, Christoph Lameter, Hugh Dickins, Rik van Riel,
	Ingo Molnar, Thomas Gleixner

From: H. Peter Anvin <hpa@zytor.com>

x86-32 has had a static test for copy_on_user() overflow for a while.
This test currently fails in mm/migrate.c resulting in an
allyesconfig/allmodconfig build failure on x86-32:

In function ‘copy_from_user’,
    inlined from ‘do_pages_stat’ at
    /home/hpa/kernel/git/mm/migrate.c:1012:
/home/hpa/kernel/git/arch/x86/include/asm/uaccess_32.h:212: error:
    call to ‘copy_from_user_overflow’ declared

Make the logic more explicit and therefore easier for gcc to
understand.

Reported-by: Len Brown <lenb@kernel.org>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Cc: Arjan van de Ven <arjan@linux.kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Christoph Lameter <cl@linux-foundation.org>
Cc: Hugh Dickins <hugh.dickins@tiscali.co.uk>
Cc: Rik van Riel <riel@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
---

NOTE: Sending this patch directly rather than queueing it up since it is a
current build failure.

 mm/migrate.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/mm/migrate.c b/mm/migrate.c
index 9a0db5b..1a12f15 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -1002,12 +1002,12 @@ static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages,
 #define DO_PAGES_STAT_CHUNK_NR 16
 	const void __user *chunk_pages[DO_PAGES_STAT_CHUNK_NR];
 	int chunk_status[DO_PAGES_STAT_CHUNK_NR];
-	unsigned long i, chunk_nr = DO_PAGES_STAT_CHUNK_NR;
+	unsigned long i, chunk_nr;
 	int err;
 
 	for (i = 0; i < nr_pages; i += chunk_nr) {
-		if (chunk_nr > nr_pages - i)
-			chunk_nr = nr_pages - i;
+		chunk_nr = min(nr_pages - i,
+			       (unsigned long)DO_PAGES_STAT_CHUNK_NR);
 
 		err = copy_from_user(chunk_pages, &pages[i],
 				     chunk_nr * sizeof(*chunk_pages));
-- 
1.6.5.2


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

* Re: [PATCH] mm: Make copy_from_user() in migrate.c statically predictable
  2010-02-18 22:43 [PATCH] mm: Make copy_from_user() in migrate.c statically predictable H. Peter Anvin
@ 2010-02-18 23:02 ` Linus Torvalds
  2010-02-19  0:17   ` H. Peter Anvin
  0 siblings, 1 reply; 7+ messages in thread
From: Linus Torvalds @ 2010-02-18 23:02 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: linux-kernel, H. Peter Anvin, Arjan van de Ven, Andrew Morton,
	KOSAKI Motohiro, Christoph Lameter, Hugh Dickins, Rik van Riel,
	Ingo Molnar, Thomas Gleixner



On Thu, 18 Feb 2010, H. Peter Anvin wrote:
> 
> Make the logic more explicit and therefore easier for gcc to
> understand.

Hmm. When making simplifications like this, I would really suggest you 
also move the declaration of the variable itself into the block where it 
is now used, rather than leaving it be function-wide.

Yes, it's used in the final condition of the for-loop, but that whole loop 
is just screwy. The 'err' handling is insane. Sometimes 'err' is a return 
value form copy_to/from_user, and sometimes it's a errno. The two are 
_not_ the same thing, they don't even have the same type!

And 'i' is totally useless too.

So that whole loop should be rewritten.

I don't even have page migration enabled, so I haven't even compile-tested 
this, but wouldn't something like this work? It's smaller, gets rid of two 
pointless variables, and looks simpler to me. Hmm?

		Linus

---
 mm/migrate.c |   36 ++++++++++++++----------------------
 1 files changed, 14 insertions(+), 22 deletions(-)

diff --git a/mm/migrate.c b/mm/migrate.c
index 9a0db5b..933d5b1 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -999,36 +999,28 @@ static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages,
 			 const void __user * __user *pages,
 			 int __user *status)
 {
-#define DO_PAGES_STAT_CHUNK_NR 16
+#define DO_PAGES_STAT_CHUNK_NR 16ul
 	const void __user *chunk_pages[DO_PAGES_STAT_CHUNK_NR];
 	int chunk_status[DO_PAGES_STAT_CHUNK_NR];
-	unsigned long i, chunk_nr = DO_PAGES_STAT_CHUNK_NR;
-	int err;
 
-	for (i = 0; i < nr_pages; i += chunk_nr) {
-		if (chunk_nr > nr_pages - i)
-			chunk_nr = nr_pages - i;
+	while (nr_pages) {
+		unsigned long chunk_nr;
 
-		err = copy_from_user(chunk_pages, &pages[i],
-				     chunk_nr * sizeof(*chunk_pages));
-		if (err) {
-			err = -EFAULT;
-			goto out;
-		}
+		chunk_nr = min(nr_pages, DO_PAGES_STAT_CHUNK_NR);
+
+		if (copy_from_user(chunk_pages, pages, chunk_nr * sizeof(*pages)))
+			break;
 
 		do_pages_stat_array(mm, chunk_nr, chunk_pages, chunk_status);
 
-		err = copy_to_user(&status[i], chunk_status,
-				   chunk_nr * sizeof(*chunk_status));
-		if (err) {
-			err = -EFAULT;
-			goto out;
-		}
-	}
-	err = 0;
+		if (copy_to_user(status, chunk_status, chunk_nr * sizeof(*status)))
+			break;
 
-out:
-	return err;
+		pages += chunk_nr;
+		status += chunk_nr;
+		nr_pages -= chunk_nr;
+	}
+	return nr_pages ? -EFAULT : 0;
 }
 
 /*

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

* Re: [PATCH] mm: Make copy_from_user() in migrate.c statically predictable
  2010-02-18 23:02 ` Linus Torvalds
@ 2010-02-19  0:17   ` H. Peter Anvin
  2010-02-19  1:25     ` KOSAKI Motohiro
  2010-02-19 14:55     ` Christoph Lameter
  0 siblings, 2 replies; 7+ messages in thread
From: H. Peter Anvin @ 2010-02-19  0:17 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: linux-kernel, H. Peter Anvin, Arjan van de Ven, Andrew Morton,
	KOSAKI Motohiro, Christoph Lameter, Hugh Dickins, Rik van Riel,
	Ingo Molnar, Thomas Gleixner

[-- Attachment #1: Type: text/plain, Size: 1577 bytes --]

On 02/18/2010 03:02 PM, Linus Torvalds wrote:
> 
> Hmm. When making simplifications like this, I would really suggest you 
> also move the declaration of the variable itself into the block where it 
> is now used, rather than leaving it be function-wide.
> 
> Yes, it's used in the final condition of the for-loop, but that whole loop 
> is just screwy. The 'err' handling is insane. Sometimes 'err' is a return 
> value form copy_to/from_user, and sometimes it's a errno. The two are 
> _not_ the same thing, they don't even have the same type!
> 
> And 'i' is totally useless too.
> 
> So that whole loop should be rewritten.
> 

OK, I was trying to make the minimal set of changes given the late -rc
status.

> I don't even have page migration enabled, so I haven't even compile-tested 
> this, but wouldn't something like this work? It's smaller, gets rid of two 
> pointless variables, and looks simpler to me. Hmm?

The code definitely looks cleaner, and it's a much more standard
"chunked data loop" form.  Weirdly enough, though, gcc 4.4.2 can't
figure out the copy_from_user() that way... despite having the same
min() structure as my code.

However, if I change it to:

		chunk_nr = nr_pages;
		if (chunk_nr > DO_PAGES_STAT_CHUNK_NR)
			chunk_nr = DO_PAGES_STAT_CHUNK_NR;

... then it works!

Overall, it looks like gcc is rather fragile with regards to its ability
to constant-propagate.  It's probably no coincidence that chunked loops
is the place where we really have problems with this kind of stuff.

Updated patch, which compile-tests for me, attached.

	-hpa

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-mm-Make-copy_from_user-in-migrate.c-statically-predi.patch --]
[-- Type: text/x-patch; name="0001-mm-Make-copy_from_user-in-migrate.c-statically-predi.patch", Size: 2814 bytes --]

>From 90585838c29ef62fd80e776d0985c40bbffd852a Mon Sep 17 00:00:00 2001
From: H. Peter Anvin <hpa@zytor.com>
Date: Thu, 18 Feb 2010 16:13:40 -0800
Subject: [PATCH] mm: Make copy_from_user() in migrate.c statically predictable
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

x86-32 has had a static test for copy_on_user() overflow for a while.
This test currently fails in mm/migrate.c resulting in an
allyesconfig/allmodconfig build failure on x86-32:

In function ‘copy_from_user’,
    inlined from ‘do_pages_stat’ at
    /home/hpa/kernel/git/mm/migrate.c:1012:
/home/hpa/kernel/git/arch/x86/include/asm/uaccess_32.h:212: error:
    call to ‘copy_from_user_overflow’ declared

Make the logic more explicit and therefore easier for gcc to
understand.

v2: rewrite the loop entirely using a more normal structure for a
    chunked-data loop (Linus Torvalds)

Reported-by: Len Brown <lenb@kernel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Cc: Arjan van de Ven <arjan@linux.kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Christoph Lameter <cl@linux-foundation.org>
Cc: Hugh Dickins <hugh.dickins@tiscali.co.uk>
Cc: Rik van Riel <riel@redhat.com>
---
 mm/migrate.c |   36 +++++++++++++++---------------------
 1 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/mm/migrate.c b/mm/migrate.c
index 9a0db5b..880bd59 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -1002,33 +1002,27 @@ static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages,
 #define DO_PAGES_STAT_CHUNK_NR 16
 	const void __user *chunk_pages[DO_PAGES_STAT_CHUNK_NR];
 	int chunk_status[DO_PAGES_STAT_CHUNK_NR];
-	unsigned long i, chunk_nr = DO_PAGES_STAT_CHUNK_NR;
-	int err;
 
-	for (i = 0; i < nr_pages; i += chunk_nr) {
-		if (chunk_nr > nr_pages - i)
-			chunk_nr = nr_pages - i;
+	while (nr_pages) {
+		unsigned long chunk_nr;
 
-		err = copy_from_user(chunk_pages, &pages[i],
-				     chunk_nr * sizeof(*chunk_pages));
-		if (err) {
-			err = -EFAULT;
-			goto out;
-		}
+		chunk_nr = nr_pages;
+		if (chunk_nr > DO_PAGES_STAT_CHUNK_NR)
+			chunk_nr = DO_PAGES_STAT_CHUNK_NR;
+
+		if (copy_from_user(chunk_pages, pages, chunk_nr * sizeof(*chunk_pages)))
+			break;
 
 		do_pages_stat_array(mm, chunk_nr, chunk_pages, chunk_status);
 
-		err = copy_to_user(&status[i], chunk_status,
-				   chunk_nr * sizeof(*chunk_status));
-		if (err) {
-			err = -EFAULT;
-			goto out;
-		}
-	}
-	err = 0;
+		if (copy_to_user(status, chunk_status, chunk_nr * sizeof(*status)))
+			break;
 
-out:
-	return err;
+		pages += chunk_nr;
+		status += chunk_nr;
+		nr_pages -= chunk_nr;
+	}
+	return nr_pages ? -EFAULT : 0;
 }
 
 /*
-- 
1.6.5.2


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

* Re: [PATCH] mm: Make copy_from_user() in migrate.c statically predictable
  2010-02-19  0:17   ` H. Peter Anvin
@ 2010-02-19  1:25     ` KOSAKI Motohiro
  2010-02-19  1:27       ` H. Peter Anvin
  2010-02-21 11:45       ` KOSAKI Motohiro
  2010-02-19 14:55     ` Christoph Lameter
  1 sibling, 2 replies; 7+ messages in thread
From: KOSAKI Motohiro @ 2010-02-19  1:25 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: kosaki.motohiro, Linus Torvalds, linux-kernel, H. Peter Anvin,
	Arjan van de Ven, Andrew Morton, Christoph Lameter, Hugh Dickins,
	Rik van Riel, Ingo Molnar, Thomas Gleixner

> On 02/18/2010 03:02 PM, Linus Torvalds wrote:
> > 
> > Hmm. When making simplifications like this, I would really suggest you 
> > also move the declaration of the variable itself into the block where it 
> > is now used, rather than leaving it be function-wide.
> > 
> > Yes, it's used in the final condition of the for-loop, but that whole loop 
> > is just screwy. The 'err' handling is insane. Sometimes 'err' is a return 
> > value form copy_to/from_user, and sometimes it's a errno. The two are 
> > _not_ the same thing, they don't even have the same type!
> > 
> > And 'i' is totally useless too.
> > 
> > So that whole loop should be rewritten.
> > 
> 
> OK, I was trying to make the minimal set of changes given the late -rc
> status.
> 
> > I don't even have page migration enabled, so I haven't even compile-tested 
> > this, but wouldn't something like this work? It's smaller, gets rid of two 
> > pointless variables, and looks simpler to me. Hmm?
> 
> The code definitely looks cleaner, and it's a much more standard
> "chunked data loop" form.  Weirdly enough, though, gcc 4.4.2 can't
> figure out the copy_from_user() that way... despite having the same
> min() structure as my code.
> 
> However, if I change it to:
> 
> 		chunk_nr = nr_pages;
> 		if (chunk_nr > DO_PAGES_STAT_CHUNK_NR)
> 			chunk_nr = DO_PAGES_STAT_CHUNK_NR;
> 
> ... then it works!
> 
> Overall, it looks like gcc is rather fragile with regards to its ability
> to constant-propagate.  It's probably no coincidence that chunked loops
> is the place where we really have problems with this kind of stuff.
> 
> Updated patch, which compile-tests for me, attached.

hehe, I'm ESPer. I think you hope I do runtime-test, plz wait 12 hour :-)




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

* Re: [PATCH] mm: Make copy_from_user() in migrate.c statically predictable
  2010-02-19  1:25     ` KOSAKI Motohiro
@ 2010-02-19  1:27       ` H. Peter Anvin
  2010-02-21 11:45       ` KOSAKI Motohiro
  1 sibling, 0 replies; 7+ messages in thread
From: H. Peter Anvin @ 2010-02-19  1:27 UTC (permalink / raw)
  To: KOSAKI Motohiro
  Cc: Linus Torvalds, linux-kernel, H. Peter Anvin, Arjan van de Ven,
	Andrew Morton, Christoph Lameter, Hugh Dickins, Rik van Riel,
	Ingo Molnar, Thomas Gleixner

On 02/18/2010 05:25 PM, KOSAKI Motohiro wrote:
>>
>> Updated patch, which compile-tests for me, attached.
> 
> hehe, I'm ESPer. I think you hope I do runtime-test, plz wait 12 hour :-)
> 

That would be most appreciated ;)

	-hpa


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

* Re: [PATCH] mm: Make copy_from_user() in migrate.c statically predictable
  2010-02-19  0:17   ` H. Peter Anvin
  2010-02-19  1:25     ` KOSAKI Motohiro
@ 2010-02-19 14:55     ` Christoph Lameter
  1 sibling, 0 replies; 7+ messages in thread
From: Christoph Lameter @ 2010-02-19 14:55 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Linus Torvalds, linux-kernel, H. Peter Anvin, Arjan van de Ven,
	Andrew Morton, KOSAKI Motohiro, Hugh Dickins, Rik van Riel,
	Ingo Molnar, Thomas Gleixner

[-- Attachment #1: Type: TEXT/PLAIN, Size: 165 bytes --]

On Thu, 18 Feb 2010, H. Peter Anvin wrote:

> Updated patch, which compile-tests for me, attached.

Looks ok.

Acked-by: Christoph Lameter <cl@linux-foundation.org>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: TEXT/X-PATCH; NAME=0001-mm-Make-copy_from_user-in-migrate.c-statically-predi.patch, Size: 5048 bytes --]

>From 90585838c29ef62fd80e776d0985c40bbffd852a Mon Sep 17 00:00:00 2001
From: H. Peter Anvin <hpa@zytor.com>
Date: Thu, 18 Feb 2010 16:13:40 -0800
Subject: [PATCH] mm: Make copy_from_user() in migrate.c statically predictable
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

x86-32 has had a static test for copy_on_user() overflow for a while.
This test currently fails in mm/migrate.c resulting in an
allyesconfig/allmodconfig build failure on x86-32:

In function ‘copy_from_user’,
    inlined from ‘do_pages_stat’ at
    /home/hpa/kernel/git/mm/migrate.c:1012:
/home/hpa/kernel/git/arch/x86/include/asm/uaccess_32.h:212: error:
    call to ‘copy_from_user_overflow’ declared

Make the logic more explicit and therefore easier for gcc to
understand.

v2: rewrite the loop entirely using a more normal structure for a
    chunked-data loop (Linus Torvalds)

Reported-by: Len Brown <lenb@kernel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Cc: Arjan van de Ven <arjan@linux.kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Christoph Lameter <cl@linux-foundation.org>
Cc: Hugh Dickins <hugh.dickins@tiscali.co.uk>
Cc: Rik van Riel <riel@redhat.com>
---
 mm/migrate.c |   36 +++++++++++++++---------------------
 1 files changed, 15 insertions(+), 21 deletions(-)

diff --git a/mm/migrate.c b/mm/migrate.c
index 9a0db5b..880bd59 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -1002,33 +1002,27 @@ static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages,
 #define DO_PAGES_STAT_CHUNK_NR 16
 	const void __user *chunk_pages[DO_PAGES_STAT_CHUNK_NR];
 	int chunk_status[DO_PAGES_STAT_CHUNK_NR];
-	unsigned long i, chunk_nr = DO_PAGES_STAT_CHUNK_NR;
-	int err;
 
-	for (i = 0; i < nr_pages; i += chunk_nr) {
-		if (chunk_nr > nr_pages - i)
-			chunk_nr = nr_pages - i;
+	while (nr_pages) {
+		unsigned long chunk_nr;
 
-		err = copy_from_user(chunk_pages, &pages[i],
-				     chunk_nr * sizeof(*chunk_pages));
-		if (err) {
-			err = -EFAULT;
-			goto out;
-		}
+		chunk_nr = nr_pages;
+		if (chunk_nr > DO_PAGES_STAT_CHUNK_NR)
+			chunk_nr = DO_PAGES_STAT_CHUNK_NR;
+
+		if (copy_from_user(chunk_pages, pages, chunk_nr * sizeof(*chunk_pages)))
+			break;
 
 		do_pages_stat_array(mm, chunk_nr, chunk_pages, chunk_status);
 
-		err = copy_to_user(&status[i], chunk_status,
-				   chunk_nr * sizeof(*chunk_status));
-		if (err) {
-			err = -EFAULT;
-			goto out;
-		}
-	}
-	err = 0;
+		if (copy_to_user(status, chunk_status, chunk_nr * sizeof(*status)))
+			break;
 
-out:
-	return err;
+		pages += chunk_nr;
+		status += chunk_nr;
+		nr_pages -= chunk_nr;
+	}
+	return nr_pages ? -EFAULT : 0;
 }
 
 /*
-- 
1.6.5.2

\0\0\0\0\0\0\0\0\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ested] 7+ messages in thread

* Re: [PATCH] mm: Make copy_from_user() in migrate.c statically predictable
  2010-02-19  1:25     ` KOSAKI Motohiro
  2010-02-19  1:27       ` H. Peter Anvin
@ 2010-02-21 11:45       ` KOSAKI Motohiro
  1 sibling, 0 replies; 7+ messages in thread
From: KOSAKI Motohiro @ 2010-02-21 11:45 UTC (permalink / raw)
  To: KOSAKI Motohiro
  Cc: kosaki.motohiro, H. Peter Anvin, Linus Torvalds, linux-kernel,
	H. Peter Anvin, Arjan van de Ven, Andrew Morton,
	Christoph Lameter, Hugh Dickins, Rik van Riel, Ingo Molnar,
	Thomas Gleixner

> > On 02/18/2010 03:02 PM, Linus Torvalds wrote:
> > > 
> > > Hmm. When making simplifications like this, I would really suggest you 
> > > also move the declaration of the variable itself into the block where it 
> > > is now used, rather than leaving it be function-wide.
> > > 
> > > Yes, it's used in the final condition of the for-loop, but that whole loop 
> > > is just screwy. The 'err' handling is insane. Sometimes 'err' is a return 
> > > value form copy_to/from_user, and sometimes it's a errno. The two are 
> > > _not_ the same thing, they don't even have the same type!
> > > 
> > > And 'i' is totally useless too.
> > > 
> > > So that whole loop should be rewritten.
> > > 
> > 
> > OK, I was trying to make the minimal set of changes given the late -rc
> > status.
> > 
> > > I don't even have page migration enabled, so I haven't even compile-tested 
> > > this, but wouldn't something like this work? It's smaller, gets rid of two 
> > > pointless variables, and looks simpler to me. Hmm?
> > 
> > The code definitely looks cleaner, and it's a much more standard
> > "chunked data loop" form.  Weirdly enough, though, gcc 4.4.2 can't
> > figure out the copy_from_user() that way... despite having the same
> > min() structure as my code.
> > 
> > However, if I change it to:
> > 
> > 		chunk_nr = nr_pages;
> > 		if (chunk_nr > DO_PAGES_STAT_CHUNK_NR)
> > 			chunk_nr = DO_PAGES_STAT_CHUNK_NR;
> > 
> > ... then it works!
> > 
> > Overall, it looks like gcc is rather fragile with regards to its ability
> > to constant-propagate.  It's probably no coincidence that chunked loops
> > is the place where we really have problems with this kind of stuff.
> > 
> > Updated patch, which compile-tests for me, attached.
> 
> hehe, I'm ESPer. I think you hope I do runtime-test, plz wait 12 hour :-)

sorry for the delay. I had little machine trouble.
	Reviewed-and-Tested-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>



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

end of thread, other threads:[~2010-02-21 11:46 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-18 22:43 [PATCH] mm: Make copy_from_user() in migrate.c statically predictable H. Peter Anvin
2010-02-18 23:02 ` Linus Torvalds
2010-02-19  0:17   ` H. Peter Anvin
2010-02-19  1:25     ` KOSAKI Motohiro
2010-02-19  1:27       ` H. Peter Anvin
2010-02-21 11:45       ` KOSAKI Motohiro
2010-02-19 14:55     ` Christoph Lameter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox