mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Andrew Morton <akpm@osdl.org>, Linus Torvalds <torvalds@osdl.org>
Cc: linuxppc64-dev@ozlabs.org, linux-kernel@vger.kernel.org
Subject: powerpc: More hugepage boundary case fixes
Date: Thu, 24 Nov 2005 13:34:56 +1100	[thread overview]
Message-ID: <20051124023456.GA3024@localhost.localdomain> (raw)

Please apply,

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" in -mm

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>

Index: working-2.6/include/asm-powerpc/page_64.h
===================================================================
--- working-2.6.orig/include/asm-powerpc/page_64.h	2005-11-24 11:15:38.000000000 +1100
+++ working-2.6/include/asm-powerpc/page_64.h	2005-11-24 13:09:28.000000000 +1100
@@ -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)
Index: working-2.6/arch/powerpc/mm/hugetlbpage.c
===================================================================
--- working-2.6.orig/arch/powerpc/mm/hugetlbpage.c	2005-11-24 11:15:38.000000000 +1100
+++ working-2.6/arch/powerpc/mm/hugetlbpage.c	2005-11-24 13:18:41.000000000 +1100
@@ -295,7 +295,7 @@ int prepare_hugepage_range(unsigned long
 	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) {

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

                 reply	other threads:[~2005-11-24  2:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20051124023456.GA3024@localhost.localdomain \
    --to=david@gibson.dropbear.id.au \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc64-dev@ozlabs.org \
    --cc=torvalds@osdl.org \
    /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

Powered by JetHome