WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

Re: [Xen-devel] [PATCH] Fix domheap structure allocation when NUMA=on

To: Jan Beulich <jbeulich@xxxxxxxxxx>
Subject: Re: [Xen-devel] [PATCH] Fix domheap structure allocation when NUMA=on
From: "Yang, Xiaowei" <xiaowei.yang@xxxxxxxxx>
Date: Tue, 24 Mar 2009 18:48:31 +0800
Cc: "xen-devel@xxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxx>, Keir Fraser <keir.fraser@xxxxxxxxxxxxx>
Delivery-date: Tue, 24 Mar 2009 03:49:01 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <49C36646.76E4.0078.0@xxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <49C32413.2030505@xxxxxxxxx> <49C35EA9.76E4.0078.0@xxxxxxxxxx> <49C35517.7040706@xxxxxxxxx> <49C36646.76E4.0078.0@xxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Thunderbird 2.0.0.21 (X11/20090318)
Jan Beulich wrote:
"Yang, Xiaowei" <xiaowei.yang@xxxxxxxxx> 20.03.09 09:34 >>>
Jan Beulich wrote:
"Yang, Xiaowei" <xiaowei.yang@xxxxxxxxx> 20.03.09 06:05 >>>
DIRECTMAP_VIRT_END can't be passed to virt_to_mfn(), as it's just beyond direct map boundary and triggers ASSERT very early at boot time.
While I agree to the analysis, I would think that this

+              mfn + needed <= virt_to_mfn(DIRECTMAP_VIRT_END - PAGE_SIZE) )

should rather be

+              mfn + needed <= virt_to_mfn(DIRECTMAP_VIRT_END - 1) + 1 )

virt_to_mfn(DIRECTMAP_VIRT_END - 1) is equal to

Depending on whether DIRECTMAP_VIRT_END is the last byte or the first
following byte. Using "- 1" avoids such a dependency.

virt_to_mfn(DIRECTMAP_VIRT_END - PAGE_SIZE). Why +1? We use '<=' here.

Because on the left side of the comparison we also calculate the first
following mfn, not the last included one.

Jan,
Thanks for the clarification!

Now I found another potential issue. Since mfn+needed could be equal to virt_to_mfn(DIRECTMAP_VIRT_END-1)+1, it can't be passed to mfn_to_virt() directly - the valid range is [0,DIRECT_MAP_BYTES>>PAGE_SHIFT).

Here is the patch to fix it. More assert and 32 bit counterpart are added.

Signed-off-by: Xiaowei Yang <xiaowei.yang@xxxxxxxxx>

Thanks,
xiaowei

diff -r 0477f9061c8a xen/common/page_alloc.c
--- a/xen/common/page_alloc.c   Fri Mar 20 17:42:46 2009 +0000
+++ b/xen/common/page_alloc.c   Mon Mar 23 03:04:18 2009 +0800
@@ -302,7 +302,8 @@ static unsigned long init_node_heap(int 
               (mfn + needed) <= (virt_to_mfn(DIRECTMAP_VIRT_END - 1) + 1) )
     {
         _heap[node] = mfn_to_virt(mfn);
-        avail[node] = mfn_to_virt(mfn + needed) - sizeof(**avail) * NR_ZONES;
+        avail[node] = mfn_to_virt(mfn + needed - 1) +
+                      PAGE_SIZE - sizeof(**avail) * NR_ZONES;
     }
 #endif
     else if ( get_order_from_bytes(sizeof(**_heap)) ==
diff -r 0477f9061c8a xen/include/asm-x86/x86_32/page.h
--- a/xen/include/asm-x86/x86_32/page.h Fri Mar 20 17:42:46 2009 +0000
+++ b/xen/include/asm-x86/x86_32/page.h Mon Mar 23 03:04:18 2009 +0800
@@ -27,9 +27,6 @@
 #define __PAGE_OFFSET           (0xFF000000)
 #define __XEN_VIRT_START        __PAGE_OFFSET
 
-#define virt_to_maddr(va) ((unsigned long)(va)-DIRECTMAP_VIRT_START)
-#define maddr_to_virt(ma) ((void *)((unsigned long)(ma)+DIRECTMAP_VIRT_START))
-
 #define VADDR_BITS              32
 #define VADDR_MASK              (~0UL)
 
@@ -43,6 +40,22 @@
 
 #include <xen/config.h>
 #include <asm/types.h>
+
+static inline unsigned long __virt_to_maddr(unsigned long va)
+{
+    ASSERT(va >= DIRECTMAP_VIRT_START && va < DIRECTMAP_VIRT_END);
+    return va - DIRECTMAP_VIRT_START;
+}
+#define virt_to_maddr(va)       \
+    (__virt_to_maddr((unsigned long)(va)))
+
+static inline void *__maddr_to_virt(unsigned long ma)
+{
+    ASSERT(ma < DIRECTMAP_VIRT_END - DIRECTMAP_VIRT_START);
+    return (void *)(ma + DIRECTMAP_VIRT_START);
+}
+#define maddr_to_virt(ma)       \
+    (__maddr_to_virt((unsigned long)(ma)))
 
 /* read access (should only be used for debug printk's) */
 typedef u64 intpte_t;
diff -r 0477f9061c8a xen/include/asm-x86/x86_64/page.h
--- a/xen/include/asm-x86/x86_64/page.h Fri Mar 20 17:42:46 2009 +0000
+++ b/xen/include/asm-x86/x86_64/page.h Mon Mar 23 03:04:42 2009 +0800
@@ -46,8 +46,14 @@ static inline unsigned long __virt_to_ma
 }
 #define virt_to_maddr(va)       \
     (__virt_to_maddr((unsigned long)(va)))
+
+static inline void *__maddr_to_virt(unsigned long ma)
+{
+    ASSERT(ma < DIRECTMAP_VIRT_END - DIRECTMAP_VIRT_START);
+    return (void *)(ma + DIRECTMAP_VIRT_START);
+}
 #define maddr_to_virt(ma)       \
-    ((void *)((unsigned long)(ma)+DIRECTMAP_VIRT_START))
+    (__maddr_to_virt((unsigned long)(ma)))
 
 /* read access (should only be used for debug printk's) */
 typedef u64 intpte_t;
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel