ia64/xen-unstable

changeset 10168:ed696467fe64

[PTRACE] Fix ptrace for hvm guests.
Signed-off-by: Nitin A Kamble <nitin.a.kamble@intel.com>
author kaf24@firebug.cl.cam.ac.uk
date Wed May 24 14:12:40 2006 +0100 (2006-05-24)
parents 52cec91b7560
children 041127f2c687
files tools/libxc/xc_ptrace.c tools/libxc/xc_ptrace.h tools/libxc/xc_ptrace_core.c tools/libxc/xg_private.h
line diff
     1.1 --- a/tools/libxc/xc_ptrace.c	Wed May 24 12:01:25 2006 +0100
     1.2 +++ b/tools/libxc/xc_ptrace.c	Wed May 24 14:12:40 2006 +0100
     1.3 @@ -185,7 +185,7 @@ map_domain_va_32(
     1.4      void *guest_va,
     1.5      int perm)
     1.6  {
     1.7 -    unsigned long l1p, p, va = (unsigned long)guest_va;
     1.8 +    unsigned long l2e, l1e, l1p, p, va = (unsigned long)guest_va;
     1.9      uint32_t *l2, *l1;
    1.10      static void *v[MAX_VIRT_CPUS];
    1.11  
    1.12 @@ -194,18 +194,20 @@ map_domain_va_32(
    1.13      if ( l2 == NULL )
    1.14          return NULL;
    1.15  
    1.16 -    l1p = to_ma(cpu, l2[l2_table_offset(va)]);
    1.17 +    l2e = l2[l2_table_offset_i386(va)];
    1.18      munmap(l2, PAGE_SIZE);
    1.19 -    if ( !(l1p & _PAGE_PRESENT) )
    1.20 +    if ( !(l2e & _PAGE_PRESENT) )
    1.21          return NULL;
    1.22 +    l1p = to_ma(cpu, l2e);
    1.23      l1 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l1p >> PAGE_SHIFT);
    1.24      if ( l1 == NULL )
    1.25          return NULL;
    1.26  
    1.27 -    p = to_ma(cpu, l1[l1_table_offset(va)]);
    1.28 +    l1e = l1[l1_table_offset_i386(va)];
    1.29      munmap(l1, PAGE_SIZE);
    1.30 -    if ( !(p & _PAGE_PRESENT) )
    1.31 +    if ( !(l1e & _PAGE_PRESENT) )
    1.32          return NULL;
    1.33 +    p = to_ma(cpu, l1e);
    1.34      if ( v[cpu] != NULL )
    1.35          munmap(v[cpu], PAGE_SIZE);
    1.36      v[cpu] = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, p >> PAGE_SHIFT);
    1.37 @@ -223,7 +225,7 @@ map_domain_va_pae(
    1.38      void *guest_va,
    1.39      int perm)
    1.40  {
    1.41 -    unsigned long l2p, l1p, p, va = (unsigned long)guest_va;
    1.42 +    unsigned long l3e, l2e, l1e, l2p, l1p, p, va = (unsigned long)guest_va;
    1.43      uint64_t *l3, *l2, *l1;
    1.44      static void *v[MAX_VIRT_CPUS];
    1.45  
    1.46 @@ -232,26 +234,29 @@ map_domain_va_pae(
    1.47      if ( l3 == NULL )
    1.48          return NULL;
    1.49  
    1.50 -    l2p = to_ma(cpu, l3[l3_table_offset_pae(va)]);
    1.51 +    l3e = l3[l3_table_offset_pae(va)];
    1.52      munmap(l3, PAGE_SIZE);
    1.53 -    if ( !(l2p & _PAGE_PRESENT) )
    1.54 +    if ( !(l3e & _PAGE_PRESENT) )
    1.55          return NULL;
    1.56 +    l2p = to_ma(cpu, l3e);
    1.57      l2 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l2p >> PAGE_SHIFT);
    1.58      if ( l2 == NULL )
    1.59          return NULL;
    1.60  
    1.61 -    l1p = to_ma(cpu, l2[l2_table_offset_pae(va)]);
    1.62 +    l2e = l2[l2_table_offset_pae(va)];
    1.63      munmap(l2, PAGE_SIZE);
    1.64 -    if ( !(l1p & _PAGE_PRESENT) )
    1.65 +    if ( !(l2e & _PAGE_PRESENT) )
    1.66          return NULL;
    1.67 +    l1p = to_ma(cpu, l2e);
    1.68      l1 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, l1p >> PAGE_SHIFT);
    1.69      if ( l1 == NULL )
    1.70          return NULL;
    1.71  
    1.72 -    p = to_ma(cpu, l1[l1_table_offset_pae(va)]);
    1.73 +    l1e = l1[l1_table_offset_pae(va)];
    1.74      munmap(l1, PAGE_SIZE);
    1.75 -    if ( !(p & _PAGE_PRESENT) )
    1.76 +    if ( !(l1e & _PAGE_PRESENT) )
    1.77          return NULL;
    1.78 +    p = to_ma(cpu, l1e);
    1.79      if ( v[cpu] != NULL )
    1.80          munmap(v[cpu], PAGE_SIZE);
    1.81      v[cpu] = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, p >> PAGE_SHIFT);
    1.82 @@ -269,10 +274,11 @@ map_domain_va_64(
    1.83      void *guest_va,
    1.84      int perm)
    1.85  {
    1.86 -    unsigned long l3p, l2p, l1p, l1e, p, va = (unsigned long)guest_va;
    1.87 +    unsigned long l4e, l3e, l2e, l1e, l3p, l2p, l1p, p, va = (unsigned long)guest_va;
    1.88      uint64_t *l4, *l3, *l2, *l1;
    1.89      static void *v[MAX_VIRT_CPUS];
    1.90  
    1.91 +
    1.92      if ((ctxt[cpu].ctrlreg[4] & 0x20) == 0 ) /* legacy ia32 mode */
    1.93          return map_domain_va_32(xc_handle, cpu, guest_va, perm);
    1.94  
    1.95 @@ -281,40 +287,41 @@ map_domain_va_64(
    1.96      if ( l4 == NULL )
    1.97          return NULL;
    1.98  
    1.99 -    l3p = to_ma(cpu, l4[l4_table_offset(va)]);
   1.100 +    l4e = l4[l4_table_offset(va)];
   1.101      munmap(l4, PAGE_SIZE);
   1.102 -    if ( !(l3p & _PAGE_PRESENT) )
   1.103 +    if ( !(l4e & _PAGE_PRESENT) )
   1.104          return NULL;
   1.105 +    l3p = to_ma(cpu, l4e);
   1.106      l3 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l3p >> PAGE_SHIFT);
   1.107      if ( l3 == NULL )
   1.108          return NULL;
   1.109  
   1.110 -    l2p = to_ma(cpu, l3[l3_table_offset(va)]);
   1.111 +    l3e = l3[l3_table_offset(va)];
   1.112      munmap(l3, PAGE_SIZE);
   1.113 -    if ( !(l2p & _PAGE_PRESENT) )
   1.114 +    if ( !(l3e & _PAGE_PRESENT) )
   1.115          return NULL;
   1.116 +    l2p = to_ma(cpu, l3e);
   1.117      l2 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l2p >> PAGE_SHIFT);
   1.118      if ( l2 == NULL )
   1.119          return NULL;
   1.120  
   1.121      l1 = NULL;
   1.122 -    l1e = to_ma(cpu, l2[l2_table_offset(va)]);
   1.123 -    if ( !(l1e & _PAGE_PRESENT) )
   1.124 -    {
   1.125 -        munmap(l2, PAGE_SIZE);
   1.126 +    l2e = l2[l2_table_offset(va)];
   1.127 +    munmap(l2, PAGE_SIZE);
   1.128 +    if ( !(l2e & _PAGE_PRESENT) )
   1.129          return NULL;
   1.130 -    }
   1.131 -    l1p = l1e >> PAGE_SHIFT;
   1.132 -    if (l1e & 0x80)  { /* 2M pages */
   1.133 +    l1p = to_ma(cpu, l2e);
   1.134 +    if (l2e & 0x80)  { /* 2M pages */
   1.135          p = to_ma(cpu, (l1p + l1_table_offset(va)) << PAGE_SHIFT);
   1.136      } else { /* 4K pages */
   1.137 -        l1p = to_ma(cpu, l1p);
   1.138          l1 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, l1p >> PAGE_SHIFT);
   1.139 -        munmap(l2, PAGE_SIZE);
   1.140          if ( l1 == NULL )
   1.141              return NULL;
   1.142  
   1.143 -        p = to_ma(cpu, l1[l1_table_offset(va)]);
   1.144 +        l1e = l1[l1_table_offset(va)];
   1.145 +        if ( !(l1e & _PAGE_PRESENT) )
   1.146 +            return NULL;
   1.147 +        p = to_ma(cpu, l1e);
   1.148      }
   1.149      if ( v[cpu] != NULL )
   1.150          munmap(v[cpu], PAGE_SIZE);
     2.1 --- a/tools/libxc/xc_ptrace.h	Wed May 24 12:01:25 2006 +0100
     2.2 +++ b/tools/libxc/xc_ptrace.h	Wed May 24 14:12:40 2006 +0100
     2.3 @@ -7,7 +7,6 @@
     2.4  #define X86_CR0_PE              0x00000001 /* Enable Protected Mode    (RW) */
     2.5  #define X86_CR0_PG              0x80000000 /* Paging                   (RW) */
     2.6  #define BSD_PAGE_MASK (PAGE_SIZE-1)
     2.7 -#define PDRSHIFT        22
     2.8  #define PSL_T  0x00000100 /* trace enable bit */
     2.9  
    2.10  #ifdef __x86_64__
    2.11 @@ -162,8 +161,6 @@ struct gdb_regs {
    2.12  #endif
    2.13  
    2.14  #define printval(x) printf("%s = %lx\n", #x, (long)x);
    2.15 -#define vtopdi(va) ((va) >> PDRSHIFT)
    2.16 -#define vtopti(va) (((va) >> PAGE_SHIFT) & 0x3ff)
    2.17  #endif
    2.18  
    2.19  typedef void (*thr_ev_handler_t)(long);
     3.1 --- a/tools/libxc/xc_ptrace_core.c	Wed May 24 12:01:25 2006 +0100
     3.2 +++ b/tools/libxc/xc_ptrace_core.c	Wed May 24 14:12:40 2006 +0100
     3.3 @@ -3,6 +3,7 @@
     3.4  #include <sys/ptrace.h>
     3.5  #include <sys/wait.h>
     3.6  #include "xc_private.h"
     3.7 +#include "xg_private.h"
     3.8  #include "xc_ptrace.h"
     3.9  #include <time.h>
    3.10  
    3.11 @@ -54,7 +55,7 @@ map_domain_va_core(unsigned long domfd, 
    3.12          }
    3.13          cr3_virt[cpu] = v;
    3.14      }
    3.15 -    if ((pde = cr3_virt[cpu][vtopdi(va)]) == 0) /* logical address */
    3.16 +    if ((pde = cr3_virt[cpu][l2_table_offset_i386(va)]) == 0) /* logical address */
    3.17          return NULL;
    3.18      if (ctxt[cpu].flags & VGCF_HVM_GUEST)
    3.19          pde = p2m_array[pde >> PAGE_SHIFT] << PAGE_SHIFT;
    3.20 @@ -70,7 +71,7 @@ map_domain_va_core(unsigned long domfd, 
    3.21              return NULL;
    3.22          pde_virt[cpu] = v;
    3.23      }
    3.24 -    if ((page = pde_virt[cpu][vtopti(va)]) == 0) /* logical address */
    3.25 +    if ((page = pde_virt[cpu][l1_table_offset_i386(va)]) == 0) /* logical address */
    3.26          return NULL;
    3.27      if (ctxt[cpu].flags & VGCF_HVM_GUEST)
    3.28          page = p2m_array[page >> PAGE_SHIFT] << PAGE_SHIFT;
    3.29 @@ -84,7 +85,7 @@ map_domain_va_core(unsigned long domfd, 
    3.30              map_mtop_offset(page_phys[cpu]));
    3.31          if (v == MAP_FAILED)
    3.32          {
    3.33 -            printf("cr3 %lx pde %lx page %lx pti %lx\n", cr3[cpu], pde, page, vtopti(va));
    3.34 +            printf("cr3 %lx pde %lx page %lx pti %lx\n", cr3[cpu], pde, page, l1_table_offset_i386(va));
    3.35              page_phys[cpu] = 0;
    3.36              return NULL;
    3.37          }
     4.1 --- a/tools/libxc/xg_private.h	Wed May 24 12:01:25 2006 +0100
     4.2 +++ b/tools/libxc/xg_private.h	Wed May 24 14:12:40 2006 +0100
     4.3 @@ -48,6 +48,8 @@ unsigned long csum_page (void * page);
     4.4  #define L2_PAGETABLE_SHIFT_PAE   21
     4.5  #define L3_PAGETABLE_SHIFT_PAE   30
     4.6  
     4.7 +#define L2_PAGETABLE_SHIFT_I386  22
     4.8 +
     4.9  #if defined(__i386__)
    4.10  #define L1_PAGETABLE_SHIFT       12
    4.11  #define L2_PAGETABLE_SHIFT       22
    4.12 @@ -62,6 +64,9 @@ unsigned long csum_page (void * page);
    4.13  #define L2_PAGETABLE_ENTRIES_PAE  512
    4.14  #define L3_PAGETABLE_ENTRIES_PAE    4
    4.15  
    4.16 +#define L1_PAGETABLE_ENTRIES_I386 1024
    4.17 +#define L2_PAGETABLE_ENTRIES_I386 1024
    4.18 +
    4.19  #if defined(__i386__)
    4.20  #define L1_PAGETABLE_ENTRIES   1024
    4.21  #define L2_PAGETABLE_ENTRIES   1024
    4.22 @@ -95,6 +100,11 @@ typedef unsigned long l4_pgentry_t;
    4.23  #define l3_table_offset_pae(_a) \
    4.24    (((_a) >> L3_PAGETABLE_SHIFT_PAE) & (L3_PAGETABLE_ENTRIES_PAE - 1))
    4.25  
    4.26 +#define l1_table_offset_i386(_a) \
    4.27 +  (((_a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES_I386 - 1))
    4.28 +#define l2_table_offset_i386(_a) \
    4.29 +  (((_a) >> L2_PAGETABLE_SHIFT_I386) & (L2_PAGETABLE_ENTRIES_I386 - 1))
    4.30 +
    4.31  #if defined(__i386__)
    4.32  #define l1_table_offset(_a) \
    4.33            (((_a) >> L1_PAGETABLE_SHIFT) & (L1_PAGETABLE_ENTRIES - 1))