public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Fix bug in PPC64 hugepage support
@ 2004-04-05  7:41 David Gibson
  0 siblings, 0 replies; only message in thread
From: David Gibson @ 2004-04-05  7:41 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Benjamin Herrenschmidt, Anton Blanchard, linux-kernel,
	linuxppc64-dev

Andrew, please apply.  Came across this nasty bug while working on
some hugepage extensions.

The PPC64 version of is_aligned_hugepage_range() is buggy.  It is
supposed to test not only that the given range is hugepage aligned,
but that it lies within the address space allowed for hugepages.  We
were checking only that the given range intersected the hugepage
range, not that it lay entirely within it.  This patch fixes the
problem and changes the name of some macros to make it less likely to
make that misunderstanding again.


Index: working-2.6/arch/ppc64/mm/hugetlbpage.c
===================================================================
--- working-2.6.orig/arch/ppc64/mm/hugetlbpage.c	2004-04-05 14:04:36.000000000 +1000
+++ working-2.6/arch/ppc64/mm/hugetlbpage.c	2004-04-05 17:29:59.477683088 +1000
@@ -230,7 +230,8 @@
 		return -EINVAL;
 	if (addr & ~HPAGE_MASK)
 		return -EINVAL;
-	if (! is_hugepage_only_range(addr, len))
+	if (! (within_hugepage_low_range(addr, len)
+	       || within_hugepage_high_range(addr, len)) )
 		return -EINVAL;
 	return 0;
 }
@@ -300,9 +301,9 @@
 
 int prepare_hugepage_range(unsigned long addr, unsigned long len)
 {
-	if (is_hugepage_high_range(addr, len))
+	if (within_hugepage_high_range(addr, len))
 		return 0;
-	else if (is_hugepage_low_range(addr, len))
+	else if (within_hugepage_low_range(addr, len))
 		return open_32bit_htlbpage_range(current->mm);
 
 	return -EINVAL;
Index: working-2.6/include/asm-ppc64/page.h
===================================================================
--- working-2.6.orig/include/asm-ppc64/page.h	2004-04-05 15:36:38.440651616 +1000
+++ working-2.6/include/asm-ppc64/page.h	2004-04-05 17:23:02.572693960 +1000
@@ -40,15 +40,19 @@
 #define ARCH_HAS_HUGEPAGE_ONLY_RANGE
 #define ARCH_HAS_PREPARE_HUGEPAGE_RANGE
 
-#define is_hugepage_low_range(addr, len) \
+#define touches_hugepage_low_range(addr, len) \
 	(((addr) > (TASK_HPAGE_BASE_32-(len))) && ((addr) < TASK_HPAGE_END_32))
-#define is_hugepage_high_range(addr, len) \
+#define touches_hugepage_high_range(addr, len) \
 	(((addr) > (TASK_HPAGE_BASE-(len))) && ((addr) < TASK_HPAGE_END))
+#define within_hugepage_low_range(addr, len) (((addr) >= TASK_HPAGE_BASE_32) \
+	  && ((addr)+(len) <= TASK_HPAGE_END_32) && ((addr)+(len) >= (addr)))
+#define within_hugepage_high_range(addr, len) (((addr) >= TASK_HPAGE_BASE) \
+	  && ((addr)+(len) <= TASK_HPAGE_END) && ((addr)+(len) >= (addr)))
 
 #define is_hugepage_only_range(addr, len) \
-	(is_hugepage_high_range((addr), (len)) || \
+	(touches_hugepage_high_range((addr), (len)) || \
 	 (current->mm->context.low_hpages \
-	  && is_hugepage_low_range((addr), (len))))
+	  && touches_hugepage_low_range((addr), (len))))
 #define hugetlb_free_pgtables free_pgtables
 #define HAVE_ARCH_HUGETLB_UNMAPPED_AREA
 



-- 
David Gibson			| For every complex problem there is a
david AT gibson.dropbear.id.au	| solution which is simple, neat and
				| wrong.
http://www.ozlabs.org/people/dgibson

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-04-05  7:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-05  7:41 Fix bug in PPC64 hugepage support David Gibson

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