All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libxc x86-64 domU support
@ 2005-06-02 19:54 Jerone Young
  2005-06-03  1:10 ` Jerone Young
  0 siblings, 1 reply; 4+ messages in thread
From: Jerone Young @ 2005-06-02 19:54 UTC (permalink / raw)
  To: xen-devel

[-- Attachment #1: Type: text/plain, Size: 311 bytes --]

Here are patches need for domU startup for x86-64. While the code seems to work.
There are problems within Xen that are preventing a full domain launch at this moment.

Signed-off-by: Jerone Young <jyoung5@us.ibm.com>
-- 
Jerone Young
IBM Linux Technology Center
jyoung5@us.ibm.com
512-838-1157 (T/L: 678-1157)

[-- Attachment #2: xc_linux_build.c.diff --]
[-- Type: text/x-patch, Size: 8176 bytes --]

--- tools/libxc/xc_linux_build.orig	2005-06-02 09:31:23.000000000 -0500
+++ tools/libxc/xc_linux_build.c	2005-06-02 09:23:39.000000000 -0500
@@ -3,13 +3,32 @@
  */
 
 #include "xc_private.h"
+
+#if defined(__i386__)
 #define ELFSIZE 32
+#endif
+
+#if defined(__x86_64__)
+#define ELFSIZE 64
+#endif
+
+
 #include "xc_elf.h"
 #include <stdlib.h>
 #include <zlib.h>
 
+#if defined(__i386__)
 #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)
 #define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
+#endif
+
+#if defined(__x86_64__)
+#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_USER)
+#define L2_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
+#define L3_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
+#define L4_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED|_PAGE_DIRTY|_PAGE_USER)
+#endif
+
 
 #define round_pgup(_p)    (((_p)+(PAGE_SIZE-1))&PAGE_MASK)
 #define round_pgdown(_p)  ((_p)&PAGE_MASK)
@@ -54,9 +73,17 @@ static int setup_guest(int xc_handle,
 {
     l1_pgentry_t *vl1tab=NULL, *vl1e=NULL;
     l2_pgentry_t *vl2tab=NULL, *vl2e=NULL;
+#if defined(__x86_64__)
+    l3_pgentry_t *vl3tab=NULL, *vl3e=NULL;
+    l4_pgentry_t *vl4tab=NULL, *vl4e=NULL;
+#endif
     unsigned long *page_array = NULL;
-    unsigned long l2tab;
-    unsigned long l1tab;
+    unsigned long l2tab = 0;
+    unsigned long l1tab = 0;
+#if defined(__x86_64__)
+    unsigned long l3tab = 0;
+    unsigned long l4tab = 0;
+#endif
     unsigned long count, i;
     start_info_t *start_info;
     shared_info_t *shared_info;
@@ -111,30 +138,45 @@ static int setup_guest(int xc_handle,
         vstartinfo_end   = vstartinfo_start + PAGE_SIZE;
         vstack_start     = vstartinfo_end;
         vstack_end       = vstack_start + PAGE_SIZE;
-        v_end            = (vstack_end + (1<<22)-1) & ~((1<<22)-1);
-        if ( (v_end - vstack_end) < (512 << 10) )
-            v_end += 1 << 22; /* Add extra 4MB to get >= 512kB padding. */
+        v_end            = (vstack_end + (1UL<<22)-1) & ~((1UL<<22)-1);
+        if ( (v_end - vstack_end) < (512UL << 10) )
+            v_end += 1UL << 22; /* Add extra 4MB to get >= 512kB padding. */
+#if defined(__i386__)
         if ( (((v_end - dsi.v_start + ((1<<L2_PAGETABLE_SHIFT)-1)) >> 
                L2_PAGETABLE_SHIFT) + 1) <= nr_pt_pages )
             break;
+#endif
+#if defined(__x86_64__)
+#define NR(_l,_h,_s) \
+    (((((_h) + ((1UL<<(_s))-1)) & ~((1UL<<(_s))-1)) - \
+    ((_l) & ~((1UL<<(_s))-1))) >> (_s))
+    if ( (1 + /* # L4 */
+        NR(dsi.v_start, v_end, L4_PAGETABLE_SHIFT) + /* # L3 */
+        NR(dsi.v_start, v_end, L3_PAGETABLE_SHIFT) + /* # L2 */
+        NR(dsi.v_start, v_end, L2_PAGETABLE_SHIFT))  /* # L1 */
+        <= nr_pt_pages )
+            break;
+#endif
     }
 
+#define _p(a) ((void *) (a))
+
     printf("VIRTUAL MEMORY ARRANGEMENT:\n"
-           " Loaded kernel: %08lx->%08lx\n"
-           " Init. ramdisk: %08lx->%08lx\n"
-           " Phys-Mach map: %08lx->%08lx\n"
-           " Page tables:   %08lx->%08lx\n"
-           " Start info:    %08lx->%08lx\n"
-           " Boot stack:    %08lx->%08lx\n"
-           " TOTAL:         %08lx->%08lx\n",
-           dsi.v_kernstart, dsi.v_kernend, 
-           vinitrd_start, vinitrd_end,
-           vphysmap_start, vphysmap_end,
-           vpt_start, vpt_end,
-           vstartinfo_start, vstartinfo_end,
-           vstack_start, vstack_end,
-           dsi.v_start, v_end);
-    printf(" ENTRY ADDRESS: %08lx\n", dsi.v_kernentry);
+           " Loaded kernel: %p->%p\n"
+           " Init. ramdisk: %p->%p\n"
+           " Phys-Mach map: %p->%p\n"
+           " Page tables:   %p->%p\n"
+           " Start info:    %p->%p\n"
+           " Boot stack:    %p->%p\n"
+           " TOTAL:         %p->%p\n",
+           _p(dsi.v_kernstart), _p(dsi.v_kernend), 
+           _p(vinitrd_start), _p(vinitrd_end),
+           _p(vphysmap_start), _p(vphysmap_end),
+           _p(vpt_start), _p(vpt_end),
+           _p(vstartinfo_start), _p(vstartinfo_end),
+           _p(vstack_start), _p(vstack_end),
+           _p(dsi.v_start), _p(v_end));
+    printf(" ENTRY ADDRESS: %p\n", _p(dsi.v_kernentry));
 
     if ( (v_end - dsi.v_start) > (nr_pages * PAGE_SIZE) )
     {
@@ -178,6 +220,7 @@ static int setup_guest(int xc_handle,
     if ( (mmu = init_mmu_updates(xc_handle, dom)) == NULL )
         goto error_out;
 
+#if defined(__i386__)
     /* First allocate page for page dir. */
     ppt_alloc = (vpt_start - dsi.v_start) >> PAGE_SHIFT;
     l2tab = page_array[ppt_alloc++] << PAGE_SHIFT;
@@ -217,6 +260,74 @@ static int setup_guest(int xc_handle,
     }
     munmap(vl1tab, PAGE_SIZE);
     munmap(vl2tab, PAGE_SIZE);
+#endif
+#if defined(__x86_64__)
+
+#define alloc_pt(ltab, vltab) \
+        ltab = page_array[ppt_alloc++] << PAGE_SHIFT; \
+        if (vltab != NULL) { \
+            munmap(vltab, PAGE_SIZE); \
+        } \
+        if ((vltab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE, \
+                          PROT_READ|PROT_WRITE, \
+                          ltab >> PAGE_SHIFT)) == NULL) { \
+            munmap(vltab, PAGE_SIZE); \
+            goto error_out; \
+        } \
+        memset(vltab, 0, PAGE_SIZE);
+
+    /* First allocate page for page dir. */
+    ppt_alloc = (vpt_start - dsi.v_start) >> PAGE_SHIFT;
+    l4tab = page_array[ppt_alloc++] << PAGE_SHIFT;
+    ctxt->pt_base = l4tab;
+    
+    /* Intiliaize page table */
+    if ( (vl4tab = xc_map_foreign_range(xc_handle, dom, PAGE_SIZE,
+                                        PROT_READ|PROT_WRITE,
+                                        l4tab >> PAGE_SHIFT)) == NULL )
+            goto error_out;
+    memset(vl4tab, 0, PAGE_SIZE);
+    vl4e = &vl4tab[l4_table_offset(dsi.v_start)];
+    
+    for ( count = 0; count < ((v_end-dsi.v_start)>>PAGE_SHIFT); count++)
+    {
+        if ( !((unsigned long)vl1e & (PAGE_SIZE-1)) )
+        {
+            alloc_pt(l1tab, vl1tab);
+            
+                if ( !((unsigned long)vl2e & (PAGE_SIZE-1)) )
+                {
+                    alloc_pt(l2tab, vl2tab);
+                    if ( !((unsigned long)vl3e & (PAGE_SIZE-1)) )
+                    {
+                        alloc_pt(l3tab, vl3tab);
+                        vl3e = &vl3tab[l3_table_offset(dsi.v_start + (count<<PAGE_SHIFT))];
+                        *vl4e = l3tab | L4_PROT;
+                        vl4e++;
+                    }
+                    vl2e = &vl2tab[l2_table_offset(dsi.v_start + (count<<PAGE_SHIFT))];
+                    *vl3e = l2tab | L3_PROT;
+                    vl3e++;
+                }
+            vl1e = &vl1tab[l1_table_offset(dsi.v_start + (count<<PAGE_SHIFT))];
+            *vl2e = l1tab | L2_PROT;
+            vl2e++;
+        }
+        
+        *vl1e = (page_array[count] << PAGE_SHIFT) | L1_PROT;
+        if ( (count >= ((vpt_start-dsi.v_start)>>PAGE_SHIFT)) &&
+            (count <  ((vpt_end  -dsi.v_start)>>PAGE_SHIFT)) ) 
+        {
+                *vl1e &= ~_PAGE_RW;
+        }
+            vl1e++;
+    }
+     
+    munmap(vl1tab, PAGE_SIZE);
+    munmap(vl2tab, PAGE_SIZE);
+    munmap(vl3tab, PAGE_SIZE);
+    munmap(vl4tab, PAGE_SIZE);
+#endif
 
     /* Write the phys->machine and machine->phys table entries. */
     physmap_pfn = (vphysmap_start - dsi.v_start) >> PAGE_SHIFT;
@@ -243,13 +354,23 @@ static int setup_guest(int xc_handle,
     }
     munmap(physmap, PAGE_SIZE);
     
+#if defined(__i386__)
     /*
      * Pin down l2tab addr as page dir page - causes hypervisor to provide
      * correct protection for the page
      */ 
     if ( pin_table(xc_handle, MMUEXT_PIN_L2_TABLE, l2tab>>PAGE_SHIFT, dom) )
         goto error_out;
+#endif
 
+#if defined(__x86_64__)
+    /*
+     * Pin down l4tab addr as page dir page - causes hypervisor to  provide
+     * correct protection for the page
+     */
+     if ( pin_table(xc_handle, MMUEXT_PIN_L4_TABLE, l4tab>>PAGE_SHIFT, dom) )
+        goto error_out;
+#endif
     start_info = xc_map_foreign_range(
         xc_handle, dom, PAGE_SIZE, PROT_READ|PROT_WRITE,
         page_array[(vstartinfo_start-dsi.v_start)>>PAGE_SHIFT]);

[-- Attachment #3: libxc_x64_xc_private_patch.diff --]
[-- Type: text/x-patch, Size: 1815 bytes --]

--- xen-unstable.orig/tools/libxc/xc_private.h	2005-03-18 22:33:27.000000000 -0600
+++ xen-unstable/tools/libxc/xc_private.h	2005-03-19 19:30:35.000000000 -0600
@@ -29,12 +29,25 @@
 #define _PAGE_PSE       0x080
 #define _PAGE_GLOBAL    0x100
 
-
+#if defined(__i386__)
 #define L1_PAGETABLE_SHIFT       12
 #define L2_PAGETABLE_SHIFT       22
- 
+#elif defined(__x86_64__)
+#define L1_PAGETABLE_SHIFT      12
+#define L2_PAGETABLE_SHIFT      21
+#define L3_PAGETABLE_SHIFT      30
+#define L4_PAGETABLE_SHIFT      39
+#endif
+
+#if defined(__i386__) 
 #define ENTRIES_PER_L1_PAGETABLE 1024
 #define ENTRIES_PER_L2_PAGETABLE 1024
+#elif defined(__x86_64__)
+#define L1_PAGETABLE_ENTRIES    512
+#define L2_PAGETABLE_ENTRIES    512
+#define L3_PAGETABLE_ENTRIES    512
+#define L4_PAGETABLE_ENTRIES    512
+#endif
  
 #define PAGE_SHIFT              L1_PAGETABLE_SHIFT
 #define PAGE_SIZE               (1UL << PAGE_SHIFT)
@@ -42,11 +55,26 @@
 
 typedef unsigned long l1_pgentry_t;
 typedef unsigned long l2_pgentry_t;
+#if defined(__x86_64__)
+typedef unsigned long l3_pgentry_t;
+typedef unsigned long l4_pgentry_t;
+#endif
 
+#if defined(__i386__)
 #define l1_table_offset(_a) \
           (((_a) >> L1_PAGETABLE_SHIFT) & (ENTRIES_PER_L1_PAGETABLE - 1))
 #define l2_table_offset(_a) \
           ((_a) >> L2_PAGETABLE_SHIFT)
+#elif defined(__x86_64__)
+#define l1_table_offset(_a) \
+  (((_a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES - 1))
+#define l2_table_offset(_a) \
+  (((_a) >> L2_PAGETABLE_SHIFT) & (L2_PAGETABLE_ENTRIES - 1))
+#define l3_table_offset(_a) \
+	(((_a) >> L3_PAGETABLE_SHIFT) & (L3_PAGETABLE_ENTRIES - 1))
+#define l4_table_offset(_a) \
+	(((_a) >> L4_PAGETABLE_SHIFT) & (L4_PAGETABLE_ENTRIES - 1))
+#endif
 
 #define ERROR(_m, _a...)  \
     fprintf(stderr, "ERROR: " _m "\n" , ## _a )

[-- Attachment #4: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] libxc x86-64 domU support
  2005-06-02 19:54 [PATCH] libxc x86-64 domU support Jerone Young
@ 2005-06-03  1:10 ` Jerone Young
  2005-06-03  5:01   ` Jerone Young
  0 siblings, 1 reply; 4+ messages in thread
From: Jerone Young @ 2005-06-03  1:10 UTC (permalink / raw)
  To: xen-devel

This patch is missing a small change that is needed.
Signed-off-by: Jerone Young

--- tools/libxc/xc_linux_build.c.orig   2005-06-02 15:08:54.000000000
-0500
+++ tools/libxc/xc_linux_build.c        2005-06-02 15:09:44.000000000
-0500
@@ -409,7 +409,11 @@ int xc_linux_build(int xc_handle,
     ctxt->user_regs.es = FLAT_KERNEL_DS;
     ctxt->user_regs.fs = FLAT_KERNEL_DS;
     ctxt->user_regs.gs = FLAT_KERNEL_DS;
+#if defined(__x86_64__)
     ctxt->user_regs.ss = FLAT_KERNEL_SS;
+#else
+    ctxt->user_regs.ss = FLAT_KERNEL_DS;
+#endif
     ctxt->user_regs.cs = FLAT_KERNEL_CS;
     ctxt->user_regs.eip = vkern_entry;
     ctxt->user_regs.esp = vstartinfo_start + 2*PAGE_SIZE;


On Thu, 2005-06-02 at 14:54 -0500, Jerone Young wrote:
> Here are patches need for domU startup for x86-64. While the code seems to work.
> There are problems within Xen that are preventing a full domain launch at this moment.
> 
> Signed-off-by: Jerone Young <jyoung5@us.ibm.com>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xensource.com
> http://lists.xensource.com/xen-devel

-- 
Jerone Young
IBM Linux Technology Center
jyoung5@us.ibm.com
512-838-1157 (T/L: 678-1157)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] libxc x86-64 domU support
  2005-06-03  1:10 ` Jerone Young
@ 2005-06-03  5:01   ` Jerone Young
  2005-06-03  7:46     ` Keir Fraser
  0 siblings, 1 reply; 4+ messages in thread
From: Jerone Young @ 2005-06-03  5:01 UTC (permalink / raw)
  To: xen-devel

Another (last one) small change that is needed also.
Signed-off-by: Jerone Young

--- tools/libxc/xc_linux_build.c.orig   2005-06-02 15:08:54.000000000
-0500
+++ tools/libxc/xc_linux_build.c        2005-06-02 18:00:26.000000000
-0500
@@ -432,9 +432,16 @@ int xc_linux_build(int xc_handle,
     /* Use the default Xen-provided GDT. */
     ctxt->gdt_ents = 0;

+#if defined(__i386__)
     /* Ring 1 stack is the initial stack. */
     ctxt->kernel_ss = FLAT_KERNEL_DS;
     ctxt->kernel_sp = vstartinfo_start + 2*PAGE_SIZE;
+#endif
+
+#if defined(__x86_64__)
+    ctxt->kernel_ss = FLAT_KERNEL_SS;
+    ctxt->kernel_sp = vstartinfo_start + 2*PAGE_SIZE;
+#endif

     /* No debugging. */
     memset(ctxt->debugreg, 0, sizeof(ctxt->debugreg));
On Thu, 2005-06-02 at 20:10 -0500, Jerone Young wrote:
> This patch is missing a small change that is needed.
> Signed-off-by: Jerone Young
> 
> --- tools/libxc/xc_linux_build.c.orig   2005-06-02 15:08:54.000000000
> -0500
> +++ tools/libxc/xc_linux_build.c        2005-06-02 15:09:44.000000000
> -0500
> @@ -409,7 +409,11 @@ int xc_linux_build(int xc_handle,
>      ctxt->user_regs.es = FLAT_KERNEL_DS;
>      ctxt->user_regs.fs = FLAT_KERNEL_DS;
>      ctxt->user_regs.gs = FLAT_KERNEL_DS;
> +#if defined(__x86_64__)
>      ctxt->user_regs.ss = FLAT_KERNEL_SS;
> +#else
> +    ctxt->user_regs.ss = FLAT_KERNEL_DS;
> +#endif
>      ctxt->user_regs.cs = FLAT_KERNEL_CS;
>      ctxt->user_regs.eip = vkern_entry;
>      ctxt->user_regs.esp = vstartinfo_start + 2*PAGE_SIZE;
> 
> 
> On Thu, 2005-06-02 at 14:54 -0500, Jerone Young wrote:
> > Here are patches need for domU startup for x86-64. While the code seems to work.
> > There are problems within Xen that are preventing a full domain launch at this moment.
> > 
> > Signed-off-by: Jerone Young <jyoung5@us.ibm.com>
> > _______________________________________________
> > Xen-devel mailing list
> > Xen-devel@lists.xensource.com
> > http://lists.xensource.com/xen-devel
> 
-- 
Jerone Young
IBM Linux Technology Center
jyoung5@us.ibm.com
512-838-1157 (T/L: 678-1157)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] libxc x86-64 domU support
  2005-06-03  5:01   ` Jerone Young
@ 2005-06-03  7:46     ` Keir Fraser
  0 siblings, 0 replies; 4+ messages in thread
From: Keir Fraser @ 2005-06-03  7:46 UTC (permalink / raw)
  To: Jerone Young; +Cc: xen-devel


On 3 Jun 2005, at 06:01, Jerone Young wrote:

> Another (last one) small change that is needed also.
> Signed-off-by: Jerone Young

The last two patches you sent need not be ifdef x86_64 --- x86_32 has a 
valid value for FLAT_KERNEL_SS that you can use (it's the same as 
FLAT_KERNEL_DS).

  -- Keir

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-06-03  7:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-06-02 19:54 [PATCH] libxc x86-64 domU support Jerone Young
2005-06-03  1:10 ` Jerone Young
2005-06-03  5:01   ` Jerone Young
2005-06-03  7:46     ` Keir Fraser

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.