HAP 1GB: Add corner case handling for 1GB super page.
authorKeir Fraser <keir.fraser@citrix.com>
Thu, 22 Apr 2010 08:41:36 +0000 (09:41 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Thu, 22 Apr 2010 08:41:36 +0000 (09:41 +0100)
 - Without the check, guest memory allocation will never reach the
   boundary of a 1GB super page.

Signed-off-by: Dongxiao Xu <dongxiao.xu@intel.com>
tools/libxc/xc_hvm_build.c

index f77497897701e4a650d06815c50611767ab09512..47486907bead4a1ccc1056dc257315ba6f92cfd6 100644 (file)
@@ -203,6 +203,14 @@ static int setup_guest(int xc_handle,
         if ( count > max_pages )
             count = max_pages;
         
+        /* Take care the corner cases of super page tails */
+        if ( ((cur_pages & (SUPERPAGE_1GB_NR_PFNS-1)) != 0) &&
+             (count > (-cur_pages & (SUPERPAGE_1GB_NR_PFNS-1))) )
+            count = -cur_pages & (SUPERPAGE_1GB_NR_PFNS-1);
+        else if ( ((count & (SUPERPAGE_1GB_NR_PFNS-1)) != 0) &&
+                  (count > SUPERPAGE_1GB_NR_PFNS) )
+            count &= ~(SUPERPAGE_1GB_NR_PFNS - 1);
+
         /* Attemp to allocate 1GB super page. Because in each pass we only
          * allocate at most 1GB, we don't have to clip super page boundaries.
          */