[PATCH] powerpc: More hugepage boundary case fixes
authorDavid Gibson <david@gibson.dropbear.id.au>
Thu, 24 Nov 2005 02:34:56 +0000 (13:34 +1100)
committerPaul Mackerras <paulus@samba.org>
Fri, 25 Nov 2005 11:12:45 +0000 (22:12 +1100)
Blah.  The patch [0] I recently sent fixing errors with
in_hugepage_area() and prepare_hugepage_range() for powerpc itself has
an off-by-one bug.  Furthermore, the related functions
touches_hugepage_*_range() and within_hugepage_*_range() are also
buggy.  Some of the bugs, like those addressed in [0] originated with
commit 7d24f0b8a53261709938ffabe3e00f88f6498df9 where we tweaked the
semantics of where hugepages are allowed.  Other bugs have been there
essentially forever, and are due to the undefined behaviour of '<<'
with shift counts greater than the type width (LOW_ESID_MASK could
return non-zero for high ranges with the right congruences).

The good news is that I now have a testsuite which should pick up
things like this if they creep in again.

[0] "powerpc-fix-for-hugepage-areas-straddling-4gb-boundary"

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Paul Mackerras <paulus@samba.org>
arch/powerpc/mm/hugetlbpage.c
include/asm-powerpc/page_64.h

index f867bba893caf86a8fdaa48019b1d86782f06c66..6bc9dbad7dea20cd744d10f682f74562533f614f 100644 (file)
@@ -295,7 +295,7 @@ int prepare_hugepage_range(unsigned long addr, unsigned long len)
        if (addr < 0x100000000UL)
                err = open_low_hpage_areas(current->mm,
                                          LOW_ESID_MASK(addr, len));
-       if ((addr + len) >= 0x100000000UL)
+       if ((addr + len) > 0x100000000UL)
                err = open_high_hpage_areas(current->mm,
                                            HTLB_AREA_MASK(addr, len));
        if (err) {
index 58a3dd9a79ec3f957f46ed5e84b768c65d44ecef..6642c012500177fc5e6f90a6ddf84e0cfa2e5ec5 100644 (file)
@@ -103,8 +103,9 @@ extern unsigned int HPAGE_SHIFT;
 #define HTLB_AREA_SIZE         (1UL << HTLB_AREA_SHIFT)
 #define GET_HTLB_AREA(x)       ((x) >> HTLB_AREA_SHIFT)
 
-#define LOW_ESID_MASK(addr, len)    (((1U << (GET_ESID(addr+len-1)+1)) \
-                                     - (1U << GET_ESID(addr))) & 0xffff)
+#define LOW_ESID_MASK(addr, len)    \
+       (((1U << (GET_ESID(min((addr)+(len)-1, 0x100000000UL))+1)) \
+         - (1U << GET_ESID(min((addr), 0x100000000UL)))) & 0xffff)
 #define HTLB_AREA_MASK(addr, len)   (((1U << (GET_HTLB_AREA(addr+len-1)+1)) \
                                      - (1U << GET_HTLB_AREA(addr))) & 0xffff)
 
@@ -113,17 +114,21 @@ extern unsigned int HPAGE_SHIFT;
 #define ARCH_HAS_SETCLEAR_HUGE_PTE
 
 #define touches_hugepage_low_range(mm, addr, len) \
-       (LOW_ESID_MASK((addr), (len)) & (mm)->context.low_htlb_areas)
+       (((addr) < 0x100000000UL) \
+        && (LOW_ESID_MASK((addr), (len)) & (mm)->context.low_htlb_areas))
 #define touches_hugepage_high_range(mm, addr, len) \
-       (HTLB_AREA_MASK((addr), (len)) & (mm)->context.high_htlb_areas)
+       ((((addr) + (len)) > 0x100000000UL) \
+         && (HTLB_AREA_MASK((addr), (len)) & (mm)->context.high_htlb_areas))
 
 #define __within_hugepage_low_range(addr, len, segmask) \
-       ((LOW_ESID_MASK((addr), (len)) | (segmask)) == (segmask))
+       ( (((addr)+(len)) <= 0x100000000UL) \
+         && ((LOW_ESID_MASK((addr), (len)) | (segmask)) == (segmask)))
 #define within_hugepage_low_range(addr, len) \
        __within_hugepage_low_range((addr), (len), \
                                    current->mm->context.low_htlb_areas)
 #define __within_hugepage_high_range(addr, len, zonemask) \
-       ((HTLB_AREA_MASK((addr), (len)) | (zonemask)) == (zonemask))
+       ( ((addr) >= 0x100000000UL) \
+         && ((HTLB_AREA_MASK((addr), (len)) | (zonemask)) == (zonemask)))
 #define within_hugepage_high_range(addr, len) \
        __within_hugepage_high_range((addr), (len), \
                                    current->mm->context.high_htlb_areas)