Skip to contentSkip to conversation

comment request: dom0 dma on large memory systems

PATCH Scott Parish 2 participants 2 messages Jun 3, 2005

lore
Share & tools
lore
#0 lore raw

purpose:

The patches i'm working on is taking more work then i was expecting; this email's purpose is to get confirmation that the solution i'm working on is the preferred one.

problem:

On x86_64 with 6gig ram, dom0's initial allocation is from memory above the pci hole (referred to as "high memory" in this email) if dom0_mem is set to 2g or higher. The only problem is that most io/dma devices (non-dac) can only dma to the first 32bits worth of machine addresses--thus for some configurations, dom0 has no memory which is dma-able.

This is realized, in my experience, with dom0 unable to find any partitions on scan and panicking because it can't mount root.

proposed solution to xen:

The attached patch is a (non-functional) prototype of my proposed solution to the xen. The idea is to add a third MEMZONE for dma'able memory, change the alloc_domheap_pages() interface so the caller can request only dma memory if needed. Finally, internal to common/page_alloc.c, split memory between MEMZONE_DOM and MEMZONE_DMADOM based on the address.

proposed solution to dom0:

Dom0 might have memory allocated to it from both high and low memory. The easiest solution would probably be to scan for and preallocate a chunk of memory that will work for dma, something like what pci-gart.c does. (or work on letting pci-gart.c work under xen)

sRp

Signature · 2 lines
Scott Parish
Signed-off-by: [email protected]
xen/arch/x86/domain_build.c +6 -4
diff -rN -u -p old-xen-64-4/xen/arch/x86/domain_build.c new-xen-64-4/xen/arch/x86/domain_build.c
@@ -57,13 +57,14 @@ boolean_param("dom0_translate", opt_dom0
 #define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
 #define round_pgdown(_p)  ((_p)&PAGE_MASK)
 
-static struct pfn_info *alloc_largest(struct domain *d, unsigned long max)
+static struct pfn_info *alloc_largest(struct domain *d, unsigned long max,
+                                      unsigned long flags)
 {
     struct pfn_info *page;
     unsigned int order = get_order(max * PAGE_SIZE);
     if ( (max & (max-1)) != 0 )
         order--;
-    while ( (page = alloc_domheap_pages(d, order)) == NULL )
+    while ( (page = alloc_domheap_pages(d, order, flags)) == NULL )
         if ( order-- == 0 )
             break;
     return page;
@@ -143,7 +144,7 @@ int construct_dom0(struct domain *d,
         nr_pages = avail_domheap_pages() +
             ((initrd_len + PAGE_SIZE - 1) >> PAGE_SHIFT) +
             ((image_len  + PAGE_SIZE - 1) >> PAGE_SHIFT);
-    if ( (page = alloc_largest(d, nr_pages)) == NULL )
+    if ( (page = alloc_largest(d, nr_pages, ALLOC_DMADOM_ONLY)) == NULL )
         panic("Not enough RAM for DOM0 reservation.\n");
     alloc_start = page_to_phys(page);
     alloc_end   = alloc_start + (d->tot_pages << PAGE_SHIFT);
@@ -554,7 +555,8 @@ int construct_dom0(struct domain *d,
     }
     while ( pfn < nr_pages )
     {
-        if ( (page = alloc_largest(d, nr_pages - d->tot_pages)) == NULL )
+        if ( (page = alloc_largest(d, nr_pages - d->tot_pages,
+                                   ALLOC_DOM_ANY)) == NULL )
             panic("Not enough RAM for DOM0 reservation.\n");
         while ( pfn < d->tot_pages )
         {
xen/arch/x86/x86_32/mm.c +2 -1
diff -rN -u -p old-xen-64-4/xen/arch/x86/x86_32/mm.c new-xen-64-4/xen/arch/x86/x86_32/mm.c
@@ -82,7 +82,8 @@ void __init paging_init(void)
         mpt_size = 4*1024*1024;
     for ( i = 0; i < (mpt_size >> L2_PAGETABLE_SHIFT); i++ )
     {
-        if ( (pg = alloc_domheap_pages(NULL, PAGETABLE_ORDER)) == NULL )
+        if ( (pg = alloc_domheap_pages(NULL, PAGETABLE_ORDER,
+              						   ALLOC_DOM_ANY) == NULL )
             panic("Not enough memory to bootstrap Xen.\n");
         idle_pg_table_l2[l2_linear_offset(RDWR_MPT_VIRT_START) + i] =
             l2e_from_page(pg, __PAGE_HYPERVISOR | _PAGE_PSE);
xen/arch/x86/x86_64/mm.c +1 -1
diff -rN -u -p old-xen-64-4/xen/arch/x86/x86_64/mm.c new-xen-64-4/xen/arch/x86/x86_64/mm.c
@@ -99,7 +99,7 @@ void __init paging_init(void)
      */
     for ( i = 0; i < max_page; i += ((1UL << L2_PAGETABLE_SHIFT) / 8) )
     {
-        pg = alloc_domheap_pages(NULL, PAGETABLE_ORDER);
+        pg = alloc_domheap_pages(NULL, PAGETABLE_ORDER, ALLOC_DOM_ANY);
         if ( pg == NULL )
             panic("Not enough memory for m2p table\n");
         map_pages_to_xen(
xen/common/dom_mem_ops.c +2 -1
diff -rN -u -p old-xen-64-4/xen/common/dom_mem_ops.c new-xen-64-4/xen/common/dom_mem_ops.c
@@ -55,7 +55,8 @@ alloc_dom_mem(struct domain *d, 
     {
         PREEMPT_CHECK(MEMOP_increase_reservation);
 
-        if ( unlikely((page = alloc_domheap_pages(d, extent_order)) == NULL) )
+        if ( unlikely((page = alloc_domheap_pages(d, extent_order,
+                                                  ALLOC_DOM_ANY)) == NULL) )
         {
             DPRINTK("Could not allocate a frame\n");
             return i;
xen/common/page_alloc.c +30 -13

106 lines not on this page · raw message

xen/include/xen/mm.h +6 -2
diff -rN -u -p old-xen-64-4/xen/include/xen/mm.h new-xen-64-4/xen/include/xen/mm.h
@@ -32,12 +32,16 @@ void free_xenheap_pages(unsigned long p,
 
 /* Domain suballocator. These functions are *not* interrupt-safe.*/
 void init_domheap_pages(unsigned long ps, unsigned long pe);
-struct pfn_info *alloc_domheap_pages(struct domain *d, unsigned int order);
+struct pfn_info *alloc_domheap_pages(
+    struct domain *d, unsigned int order, unsigned int flags);
 void free_domheap_pages(struct pfn_info *pg, unsigned int order);
 unsigned long avail_domheap_pages(void);
-#define alloc_domheap_page(_d) (alloc_domheap_pages(_d,0))
+#define alloc_domheap_page(_d) (alloc_domheap_pages(_d,0,ALLOC_DOM_ANY))
 #define free_domheap_page(_p) (free_domheap_pages(_p,0))
 
+#define ALLOC_DMADOM_ONLY 1
+#define ALLOC_DOM_ANY 0
+
 /* Automatic page scrubbing for dead domains. */
 extern struct list_head page_scrub_list;
 #define page_scrub_schedule_work()              \

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

Yes, something like this is obviously required, and introducing a concept of zones seems a sensible way to go. I haven't looked at your patch in great detail but it looks along the right lines. :-)

-- Keir

Quoted 14 lines · Scott Parish

The attached patch is a (non-functional) prototype of my proposed solution to the xen. The idea is to add a third MEMZONE for dma'able memory, change the alloc_domheap_pages() interface so the caller can request only dma memory if needed. Finally, internal to common/page_alloc.c, split memory between MEMZONE_DOM and MEMZONE_DMADOM based on the address.

proposed solution to dom0:

Dom0 might have memory allocated to it from both high and low memory. The easiest solution would probably be to scan for and preallocate a chunk of memory that will work for dma, something like what pci-gart.c does. (or work on letting pci-gart.c work under xen)