ia64/xen-unstable

changeset 10054:93379554837c

Re-enables ptrace for paravirtualized guests.

Changes:

- Added to_ma function which translates a physical address to a
machine address for HVM guests and just returns the address for PV
guests.

- Use to_ma() in map_domain_va_32, map_domain_va_pae and
map_domain_va_64 to abstract away differences between HVM and PV
guests.

- (From Keir, Ryan) Export CR0 to PV guests as well.

I've removed the address checks against 0 since the last version since
physical/machine address 0 should be valid. Invalid translations
should be catched in xc_map_foreign_domain.

Signed-Off-By: Simon Kagstrom <simon.kagstrom@bth.se>
author kaf24@firebug.cl.cam.ac.uk
date Fri May 12 15:26:39 2006 +0100 (2006-05-12)
parents b4842d0f49da
children 8e6835fa7c4b
files tools/libxc/xc_ptrace.c xen/arch/x86/domain.c
line diff
     1.1 --- a/tools/libxc/xc_ptrace.c	Fri May 12 15:21:12 2006 +0100
     1.2 +++ b/tools/libxc/xc_ptrace.c	Fri May 12 15:26:39 2006 +0100
     1.3 @@ -157,6 +157,27 @@ online_vcpus_changed(cpumap_t cpumap)
     1.4  static long                     nr_pages = 0;
     1.5  static unsigned long           *page_array = NULL;
     1.6  
     1.7 +
     1.8 +/*
     1.9 + * Translates physical addresses to machine addresses for HVM
    1.10 + * guests. For paravirtual domains the function will just return the
    1.11 + * given address.
    1.12 + *
    1.13 + * This function should be used when reading page directories/page
    1.14 + * tables.
    1.15 + *
    1.16 + */
    1.17 +static unsigned long
    1.18 +to_ma(int cpu,
    1.19 +      unsigned long in_addr)
    1.20 +{
    1.21 +    unsigned long maddr = in_addr;
    1.22 +
    1.23 +    if ( (ctxt[cpu].flags & VGCF_HVM_GUEST) && paging_enabled(&ctxt[cpu]) )
    1.24 +        maddr = page_array[maddr >> PAGE_SHIFT] << PAGE_SHIFT;
    1.25 +    return maddr;
    1.26 +}
    1.27 +
    1.28  static void *
    1.29  map_domain_va_32(
    1.30      int xc_handle,
    1.31 @@ -188,10 +209,7 @@ map_domain_va_32(
    1.32          if ( cr3_virt[cpu] == NULL )
    1.33              return NULL;
    1.34      }
    1.35 -    if ( (pde = cr3_virt[cpu][vtopdi(va)]) == 0 )
    1.36 -        return NULL;
    1.37 -    if ( (ctxt[cpu].flags & VGCF_HVM_GUEST) && paging_enabled(&ctxt[cpu]) )
    1.38 -        pde = page_array[pde >> PAGE_SHIFT] << PAGE_SHIFT;
    1.39 +    pde = to_ma(cpu, cr3_virt[cpu][vtopdi(va)]);
    1.40      if ( pde != pde_phys[cpu] )
    1.41      {
    1.42          pde_phys[cpu] = pde;
    1.43 @@ -203,10 +221,8 @@ map_domain_va_32(
    1.44          if ( pde_virt[cpu] == NULL )
    1.45              return NULL;
    1.46      }
    1.47 -    if ( (page = pde_virt[cpu][vtopti(va)]) == 0 )
    1.48 -        return NULL;
    1.49 -    if (ctxt[cpu].flags & VGCF_HVM_GUEST)
    1.50 -        page = page_array[page >> PAGE_SHIFT] << PAGE_SHIFT;
    1.51 +    page = to_ma(cpu, pde_virt[cpu][vtopti(va)]);
    1.52 +
    1.53      if ( (page != page_phys[cpu]) || (perm != prev_perm[cpu]) )
    1.54      {
    1.55          page_phys[cpu] = page;
    1.56 @@ -243,25 +259,22 @@ map_domain_va_pae(
    1.57      if ( l3 == NULL )
    1.58          return NULL;
    1.59  
    1.60 -    l2p = l3[l3_table_offset_pae(va)] >> PAGE_SHIFT;
    1.61 -    l2p = page_array[l2p];
    1.62 -    l2 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l2p);
    1.63 +    l2p = to_ma(cpu, l3[l3_table_offset_pae(va)]);
    1.64 +    l2 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l2p >> PAGE_SHIFT);
    1.65      munmap(l3, PAGE_SIZE);
    1.66      if ( l2 == NULL )
    1.67          return NULL;
    1.68  
    1.69 -    l1p = l2[l2_table_offset_pae(va)] >> PAGE_SHIFT;
    1.70 -    l1p = page_array[l1p];
    1.71 -    l1 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, l1p);
    1.72 +    l1p = to_ma(cpu, l2[l2_table_offset_pae(va)]);
    1.73 +    l1 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, l1p >> PAGE_SHIFT);
    1.74      munmap(l2, PAGE_SIZE);
    1.75      if ( l1 == NULL )
    1.76          return NULL;
    1.77  
    1.78 -    p = l1[l1_table_offset_pae(va)] >> PAGE_SHIFT;
    1.79 -    p = page_array[p];
    1.80 +    p = to_ma(cpu, l1[l1_table_offset_pae(va)]);
    1.81      if ( v != NULL )
    1.82          munmap(v, PAGE_SIZE);
    1.83 -    v = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, p);
    1.84 +    v = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, p >> PAGE_SHIFT);
    1.85      munmap(l1, PAGE_SIZE);
    1.86      if ( v == NULL )
    1.87          return NULL;
    1.88 @@ -289,38 +302,35 @@ map_domain_va_64(
    1.89      if ( l4 == NULL )
    1.90          return NULL;
    1.91  
    1.92 -    l3p = l4[l4_table_offset(va)] >> PAGE_SHIFT;
    1.93 -    l3p = page_array[l3p];
    1.94 -    l3 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l3p);
    1.95 +    l3p = to_ma(cpu, l4[l4_table_offset(va)]);
    1.96 +    l3 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l3p >> PAGE_SHIFT);
    1.97      munmap(l4, PAGE_SIZE);
    1.98      if ( l3 == NULL )
    1.99          return NULL;
   1.100  
   1.101 -    l2p = l3[l3_table_offset(va)] >> PAGE_SHIFT;
   1.102 -    l2p = page_array[l2p];
   1.103 -    l2 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l2p);
   1.104 +    l2p = to_ma(cpu, l3[l3_table_offset(va)]);
   1.105 +    l2 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, PROT_READ, l2p >> PAGE_SHIFT);
   1.106      munmap(l3, PAGE_SIZE);
   1.107      if ( l2 == NULL )
   1.108          return NULL;
   1.109  
   1.110      l1 = NULL;
   1.111 -    l1e = l2[l2_table_offset(va)];
   1.112 +    l1e = to_ma(cpu, l2[l2_table_offset(va)]);
   1.113      l1p = l1e >> PAGE_SHIFT;
   1.114      if (l1e & 0x80)  { /* 2M pages */
   1.115 -        p = (l1p + l1_table_offset(va));
   1.116 +        p = to_ma(cpu, (l1p + l1_table_offset(va)) << PAGE_SHIFT);
   1.117      } else { /* 4K pages */
   1.118 -        l1p = page_array[l1p];
   1.119 -        l1 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, l1p);
   1.120 +        l1p = to_ma(cpu, l1e[l1_table_offset(va)]);
   1.121 +        l1 = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, l1p >> PAGE_SHIFT);
   1.122          munmap(l2, PAGE_SIZE);
   1.123          if ( l1 == NULL )
   1.124              return NULL;
   1.125  
   1.126 -        p = l1[l1_table_offset(va)] >> PAGE_SHIFT;
   1.127 +        p = to_ma(cpu, l1[l1_table_offset(va)]);
   1.128      }
   1.129 -    p = page_array[p];
   1.130      if ( v != NULL )
   1.131          munmap(v, PAGE_SIZE);
   1.132 -    v = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, p);
   1.133 +    v = xc_map_foreign_range(xc_handle, current_domid, PAGE_SIZE, perm, p >> PAGE_SHIFT);
   1.134      if (l1)
   1.135          munmap(l1, PAGE_SIZE);
   1.136      if ( v == NULL )
   1.137 @@ -381,7 +391,7 @@ map_domain_va(
   1.138          if ( v != NULL )
   1.139              munmap(v, PAGE_SIZE);
   1.140  
   1.141 -        page = page_array[va >> PAGE_SHIFT] << PAGE_SHIFT;
   1.142 +        page = to_ma(cpu, page_array[va >> PAGE_SHIFT]);
   1.143  
   1.144          v = xc_map_foreign_range( xc_handle, current_domid, PAGE_SIZE,
   1.145                  perm, page >> PAGE_SHIFT);
     2.1 --- a/xen/arch/x86/domain.c	Fri May 12 15:21:12 2006 +0100
     2.2 +++ b/xen/arch/x86/domain.c	Fri May 12 15:26:39 2006 +0100
     2.3 @@ -286,6 +286,11 @@ int arch_set_info_guest(
     2.4          v->arch.flags |= TF_kernel_mode;
     2.5  
     2.6      memcpy(&v->arch.guest_context, c, sizeof(*c));
     2.7 +
     2.8 +    /* Only CR0.TS is modifiable by guest or admin. */
     2.9 +    v->arch.guest_context.ctrlreg[0] &= X86_CR0_TS;
    2.10 +    v->arch.guest_context.ctrlreg[0] |= read_cr0() & ~X86_CR0_TS;
    2.11 +
    2.12      init_int80_direct_trap(v);
    2.13  
    2.14      if ( !(c->flags & VGCF_HVM_GUEST) )