ia64/xen-unstable

changeset 12594:2ae4e4e89d6d

[XEN] Cleanups to phys/mach address handling.

1. Balloon driver does not need to set M2P entry.
This is done by the populate_physmap hypercall.

2. Xen now translates foreign mappings from GMFN->MFN.
Tools are simplified because of this.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Mon Nov 27 14:20:44 2006 +0000 (2006-11-27)
parents c242b6d6a64a
children 7c0f72918cec
files linux-2.6-xen-sparse/arch/i386/mm/hypervisor.c linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypervisor.h linux-2.6-xen-sparse/include/asm-ia64/maddr.h tools/ioemu/vl.c tools/libxc/xc_domain.c tools/libxc/xc_hvm_build.c tools/libxc/xc_linux_build.c tools/libxc/xc_linux_restore.c tools/libxc/xc_private.c tools/libxc/xenctrl.h xen/arch/x86/mm.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/i386/mm/hypervisor.c	Mon Nov 27 13:50:02 2006 +0000
     1.2 +++ b/linux-2.6-xen-sparse/arch/i386/mm/hypervisor.c	Mon Nov 27 14:20:44 2006 +0000
     1.3 @@ -99,18 +99,6 @@ void xen_l4_entry_update(pgd_t *ptr, pgd
     1.4  }
     1.5  #endif /* CONFIG_X86_64 */
     1.6  
     1.7 -void xen_machphys_update(unsigned long mfn, unsigned long pfn)
     1.8 -{
     1.9 -	mmu_update_t u;
    1.10 -	if (xen_feature(XENFEAT_auto_translated_physmap)) {
    1.11 -		BUG_ON(pfn != mfn);
    1.12 -		return;
    1.13 -	}
    1.14 -	u.ptr = ((unsigned long long)mfn << PAGE_SHIFT) | MMU_MACHPHYS_UPDATE;
    1.15 -	u.val = pfn;
    1.16 -	BUG_ON(HYPERVISOR_mmu_update(&u, 1, NULL, DOMID_SELF) < 0);
    1.17 -}
    1.18 -
    1.19  void xen_pt_switch(unsigned long ptr)
    1.20  {
    1.21  	struct mmuext_op op;
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Mon Nov 27 13:50:02 2006 +0000
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Mon Nov 27 14:20:44 2006 +0000
     2.3 @@ -215,9 +215,7 @@ static int increase_reservation(unsigned
     2.4  		BUG_ON(!xen_feature(XENFEAT_auto_translated_physmap) &&
     2.5  		       phys_to_machine_mapping_valid(pfn));
     2.6  
     2.7 -		/* Update P->M and M->P tables. */
     2.8  		set_phys_to_machine(pfn, frame_list[i]);
     2.9 -		xen_machphys_update(frame_list[i], pfn);
    2.10  
    2.11  		/* Link back into the page tables if not highmem. */
    2.12  		if (pfn < max_low_pfn) {
     3.1 --- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypervisor.h	Mon Nov 27 13:50:02 2006 +0000
     3.2 +++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/hypervisor.h	Mon Nov 27 14:20:44 2006 +0000
     3.3 @@ -98,7 +98,6 @@ void xen_pgd_pin(unsigned long ptr);
     3.4  void xen_pgd_unpin(unsigned long ptr);
     3.5  
     3.6  void xen_set_ldt(unsigned long ptr, unsigned long bytes);
     3.7 -void xen_machphys_update(unsigned long mfn, unsigned long pfn);
     3.8  
     3.9  #ifdef CONFIG_SMP
    3.10  #include <linux/cpumask.h>
     4.1 --- a/linux-2.6-xen-sparse/include/asm-ia64/maddr.h	Mon Nov 27 13:50:02 2006 +0000
     4.2 +++ b/linux-2.6-xen-sparse/include/asm-ia64/maddr.h	Mon Nov 27 14:20:44 2006 +0000
     4.3 @@ -96,11 +96,6 @@ mfn_to_local_pfn(unsigned long mfn)
     4.4  #define virt_to_machine(virt) __pa(virt) // for tpmfront.c
     4.5  
     4.6  #define set_phys_to_machine(pfn, mfn) do { } while (0)
     4.7 -#ifdef CONFIG_VMX_GUEST
     4.8 -extern void xen_machphys_update(unsigned long mfn, unsigned long pfn);
     4.9 -#else /* CONFIG_VMX_GUEST */
    4.10 -#define xen_machphys_update(mfn, pfn) do { } while (0)
    4.11 -#endif /* CONFIG_VMX_GUEST */
    4.12  
    4.13  typedef unsigned long maddr_t;	// to compile netback, netfront
    4.14  
     5.1 --- a/tools/ioemu/vl.c	Mon Nov 27 13:50:02 2006 +0000
     5.2 +++ b/tools/ioemu/vl.c	Mon Nov 27 14:20:44 2006 +0000
     5.3 @@ -5787,9 +5787,6 @@ int set_mm_mapping(int xc_handle, uint32
     5.4                     unsigned long nr_pages, unsigned int address_bits,
     5.5                     xen_pfn_t *extent_start)
     5.6  {
     5.7 -#if 0
     5.8 -    int i;
     5.9 -#endif
    5.10      xc_dominfo_t info;
    5.11      int err = 0;
    5.12  
    5.13 @@ -5808,19 +5805,6 @@ int set_mm_mapping(int xc_handle, uint32
    5.14          return -1;
    5.15      }
    5.16  
    5.17 -    err = xc_domain_translate_gpfn_list(xc_handle, domid, nr_pages,
    5.18 -                                        extent_start, extent_start);
    5.19 -    if (err) {
    5.20 -        fprintf(stderr, "Failed to translate gpfn list\n");
    5.21 -        return -1;
    5.22 -    }
    5.23 -
    5.24 -#if 0 /* Generates lots of log file output - turn on for debugging */
    5.25 -    for (i = 0; i < nr_pages; i++)
    5.26 -        fprintf(stderr, "set_map result i %x result %lx\n", i,
    5.27 -                extent_start[i]);
    5.28 -#endif
    5.29 -
    5.30      return 0;
    5.31  }
    5.32  
    5.33 @@ -6425,12 +6409,6 @@ int main(int argc, char **argv)
    5.34  #if defined(__i386__) || defined(__x86_64__)
    5.35      for ( i = 0; i < tmp_nr_pages; i++)
    5.36          page_array[i] = i;
    5.37 -    if (xc_domain_translate_gpfn_list(xc_handle, domid, tmp_nr_pages,
    5.38 -                                      page_array, page_array)) {
    5.39 -        fprintf(logfile, "xc_domain_translate_gpfn_list returned error %d\n",
    5.40 -                errno);
    5.41 -        exit(-1);
    5.42 -    }
    5.43  
    5.44      phys_ram_base = xc_map_foreign_batch(xc_handle, domid,
    5.45                                           PROT_READ|PROT_WRITE, page_array,
     6.1 --- a/tools/libxc/xc_domain.c	Mon Nov 27 13:50:02 2006 +0000
     6.2 +++ b/tools/libxc/xc_domain.c	Mon Nov 27 14:20:44 2006 +0000
     6.3 @@ -430,22 +430,6 @@ int xc_domain_memory_populate_physmap(in
     6.4      return err;
     6.5  }
     6.6  
     6.7 -int xc_domain_translate_gpfn_list(int xc_handle,
     6.8 -                                  uint32_t domid,
     6.9 -                                  unsigned long nr_gpfns,
    6.10 -                                  xen_pfn_t *gpfn_list,
    6.11 -                                  xen_pfn_t *mfn_list)
    6.12 -{
    6.13 -    struct xen_translate_gpfn_list op = {
    6.14 -        .domid        = domid,
    6.15 -        .nr_gpfns     = nr_gpfns,
    6.16 -    };
    6.17 -    set_xen_guest_handle(op.gpfn_list, gpfn_list);
    6.18 -    set_xen_guest_handle(op.mfn_list, mfn_list);
    6.19 -
    6.20 -    return xc_memory_op(xc_handle, XENMEM_translate_gpfn_list, &op);
    6.21 -}
    6.22 -
    6.23  int xc_domain_max_vcpus(int xc_handle, uint32_t domid, unsigned int max)
    6.24  {
    6.25      DECLARE_DOMCTL;
     7.1 --- a/tools/libxc/xc_hvm_build.c	Mon Nov 27 13:50:02 2006 +0000
     7.2 +++ b/tools/libxc/xc_hvm_build.c	Mon Nov 27 14:20:44 2006 +0000
     7.3 @@ -245,13 +245,6 @@ static int setup_guest(int xc_handle,
     7.4          goto error_out;
     7.5      }
     7.6  
     7.7 -    if ( xc_domain_translate_gpfn_list(xc_handle, dom, nr_pages,
     7.8 -                                       page_array, page_array) )
     7.9 -    {
    7.10 -        PERROR("Could not translate addresses of HVM guest.\n");
    7.11 -        goto error_out;
    7.12 -    }
    7.13 -
    7.14      loadelfimage(image, xc_handle, dom, page_array, &dsi);
    7.15  
    7.16      if ( set_hvm_info(xc_handle, dom, page_array, vcpus, acpi) )
     8.1 --- a/tools/libxc/xc_linux_build.c	Mon Nov 27 13:50:02 2006 +0000
     8.2 +++ b/tools/libxc/xc_linux_build.c	Mon Nov 27 14:20:44 2006 +0000
     8.3 @@ -509,12 +509,6 @@ static int setup_guest(int xc_handle,
     8.4          PERROR("Could not allocate memory for PV guest.\n");
     8.5          goto error_out;
     8.6      }
     8.7 -    if ( xc_domain_translate_gpfn_list(xc_handle, dom, nr_pages,
     8.8 -                                       page_array, page_array) )
     8.9 -    {
    8.10 -        PERROR("Could not translate addresses of PV guest.\n");
    8.11 -        goto error_out;
    8.12 -    }
    8.13  
    8.14      dsi.v_start    = round_pgdown(dsi.v_start);
    8.15      vinitrd_start  = round_pgup(dsi.v_end);
     9.1 --- a/tools/libxc/xc_linux_restore.c	Mon Nov 27 13:50:02 2006 +0000
     9.2 +++ b/tools/libxc/xc_linux_restore.c	Mon Nov 27 14:20:44 2006 +0000
     9.3 @@ -265,13 +265,16 @@ int xc_linux_restore(int xc_handle, int 
     9.4      }
     9.5      shared_info_frame = domctl.u.getdomaininfo.shared_info_frame;
     9.6  
     9.7 -    if(xc_domain_setmaxmem(xc_handle, dom, PFN_TO_KB(max_pfn)) != 0) {
     9.8 +    if (xc_domain_setmaxmem(xc_handle, dom, PFN_TO_KB(max_pfn)) != 0) {
     9.9          errno = ENOMEM;
    9.10          goto out;
    9.11      }
    9.12  
    9.13 -    if(xc_domain_memory_increase_reservation(
    9.14 -           xc_handle, dom, max_pfn, 0, 0, NULL) != 0) {
    9.15 +    for ( pfn = 0; pfn < max_pfn; pfn++ )
    9.16 +        p2m[pfn] = pfn;
    9.17 +
    9.18 +    if (xc_domain_memory_populate_physmap(xc_handle, dom, max_pfn,
    9.19 +                                          0, 0, p2m) != 0) {
    9.20          ERROR("Failed to increase reservation by %lx KB", PFN_TO_KB(max_pfn));
    9.21          errno = ENOMEM;
    9.22          goto out;
    9.23 @@ -279,18 +282,11 @@ int xc_linux_restore(int xc_handle, int 
    9.24  
    9.25      DPRINTF("Increased domain reservation by %lx KB\n", PFN_TO_KB(max_pfn));
    9.26  
    9.27 -    /* Build the pfn-to-mfn table. We choose MFN ordering returned by Xen. */
    9.28 -    if (xc_get_pfn_list(xc_handle, dom, p2m, max_pfn) != max_pfn) {
    9.29 -        ERROR("Did not read correct number of frame numbers for new dom");
    9.30 -        goto out;
    9.31 -    }
    9.32 -
    9.33      if(!(mmu = xc_init_mmu_updates(xc_handle, dom))) {
    9.34          ERROR("Could not initialise for MMU updates");
    9.35          goto out;
    9.36      }
    9.37  
    9.38 -
    9.39      DPRINTF("Reloading memory pages:   0%%\n");
    9.40  
    9.41      /*
    10.1 --- a/tools/libxc/xc_private.c	Mon Nov 27 13:50:02 2006 +0000
    10.2 +++ b/tools/libxc/xc_private.c	Mon Nov 27 14:20:44 2006 +0000
    10.3 @@ -134,10 +134,7 @@ int xc_memory_op(int xc_handle,
    10.4      DECLARE_HYPERCALL;
    10.5      struct xen_memory_reservation *reservation = arg;
    10.6      struct xen_machphys_mfn_list *xmml = arg;
    10.7 -    struct xen_translate_gpfn_list *trans = arg;
    10.8      xen_pfn_t *extent_start;
    10.9 -    xen_pfn_t *gpfn_list;
   10.10 -    xen_pfn_t *mfn_list;
   10.11      long ret = -EINVAL;
   10.12  
   10.13      hypercall.op     = __HYPERVISOR_memory_op;
   10.14 @@ -186,28 +183,6 @@ int xc_memory_op(int xc_handle,
   10.15              goto out1;
   10.16          }
   10.17          break;
   10.18 -    case XENMEM_translate_gpfn_list:
   10.19 -        if ( lock_pages(trans, sizeof(*trans)) != 0 )
   10.20 -        {
   10.21 -            PERROR("Could not lock");
   10.22 -            goto out1;
   10.23 -        }
   10.24 -        get_xen_guest_handle(gpfn_list, trans->gpfn_list);
   10.25 -        if ( lock_pages(gpfn_list, trans->nr_gpfns * sizeof(xen_pfn_t)) != 0 )
   10.26 -        {
   10.27 -            PERROR("Could not lock");
   10.28 -            unlock_pages(trans, sizeof(*trans));
   10.29 -            goto out1;
   10.30 -        }
   10.31 -        get_xen_guest_handle(mfn_list, trans->mfn_list);
   10.32 -        if ( lock_pages(mfn_list, trans->nr_gpfns * sizeof(xen_pfn_t)) != 0 )
   10.33 -        {
   10.34 -            PERROR("Could not lock");
   10.35 -            unlock_pages(gpfn_list, trans->nr_gpfns * sizeof(xen_pfn_t));
   10.36 -            unlock_pages(trans, sizeof(*trans));
   10.37 -            goto out1;
   10.38 -        }
   10.39 -        break;
   10.40      }
   10.41  
   10.42      ret = do_xen_hypercall(xc_handle, &hypercall);
   10.43 @@ -232,13 +207,6 @@ int xc_memory_op(int xc_handle,
   10.44      case XENMEM_add_to_physmap:
   10.45          unlock_pages(arg, sizeof(struct xen_add_to_physmap));
   10.46          break;
   10.47 -    case XENMEM_translate_gpfn_list:
   10.48 -            get_xen_guest_handle(mfn_list, trans->mfn_list);
   10.49 -            unlock_pages(mfn_list, trans->nr_gpfns * sizeof(xen_pfn_t));
   10.50 -            get_xen_guest_handle(gpfn_list, trans->gpfn_list);
   10.51 -            unlock_pages(gpfn_list, trans->nr_gpfns * sizeof(xen_pfn_t));
   10.52 -            unlock_pages(trans, sizeof(*trans));
   10.53 -        break;
   10.54      }
   10.55  
   10.56   out1:
    11.1 --- a/tools/libxc/xenctrl.h	Mon Nov 27 13:50:02 2006 +0000
    11.2 +++ b/tools/libxc/xenctrl.h	Mon Nov 27 14:20:44 2006 +0000
    11.3 @@ -439,12 +439,6 @@ int xc_domain_memory_populate_physmap(in
    11.4                                        unsigned int address_bits,
    11.5                                        xen_pfn_t *extent_start);
    11.6  
    11.7 -int xc_domain_translate_gpfn_list(int xc_handle,
    11.8 -                                  uint32_t domid,
    11.9 -                                  unsigned long nr_gpfns,
   11.10 -                                  xen_pfn_t *gpfn_list,
   11.11 -                                  xen_pfn_t *mfn_list);
   11.12 -
   11.13  int xc_domain_ioport_permission(int xc_handle,
   11.14                                  uint32_t domid,
   11.15                                  uint32_t first_port,
    12.1 --- a/xen/arch/x86/mm.c	Mon Nov 27 13:50:02 2006 +0000
    12.2 +++ b/xen/arch/x86/mm.c	Mon Nov 27 14:20:44 2006 +0000
    12.3 @@ -1240,6 +1240,10 @@ static int mod_l1_entry(l1_pgentry_t *pl
    12.4  
    12.5      if ( l1e_get_flags(nl1e) & _PAGE_PRESENT )
    12.6      {
    12.7 +        /* Translate foreign guest addresses. */
    12.8 +        nl1e = l1e_from_pfn(gmfn_to_mfn(FOREIGNDOM, l1e_get_pfn(nl1e)),
    12.9 +                            l1e_get_flags(nl1e));
   12.10 +
   12.11          if ( unlikely(l1e_get_flags(nl1e) & L1_DISALLOW_MASK) )
   12.12          {
   12.13              MEM_LOG("Bad L1 flags %x",
   12.14 @@ -1814,12 +1818,17 @@ static int set_foreigndom(domid_t domid)
   12.15      if ( likely(domid == DOMID_SELF) )
   12.16          goto out;
   12.17  
   12.18 -    if ( domid == d->domain_id )
   12.19 +    if ( unlikely(domid == d->domain_id) )
   12.20      {
   12.21          MEM_LOG("Dom %u tried to specify itself as foreign domain",
   12.22                  d->domain_id);
   12.23          okay = 0;
   12.24      }
   12.25 +    else if ( unlikely(shadow_mode_translate(d)) )
   12.26 +    {
   12.27 +        MEM_LOG("Cannot mix foreign mappings with translated domains");
   12.28 +        okay = 0;
   12.29 +    }
   12.30      else if ( !IS_PRIV(d) )
   12.31      {
   12.32          switch ( domid )
   12.33 @@ -1857,14 +1866,6 @@ static int set_foreigndom(domid_t domid)
   12.34          }
   12.35      }
   12.36  
   12.37 -    if ( unlikely(shadow_mode_translate(d)) )
   12.38 -    {
   12.39 -        MEM_LOG("%s: can not mix foreign mappings with translated domains",
   12.40 -                __func__);
   12.41 -        info->foreign = NULL;
   12.42 -        okay = 0; 
   12.43 -    }
   12.44 -
   12.45   out:
   12.46      return okay;
   12.47  }
   12.48 @@ -2340,13 +2341,15 @@ int do_mmu_update(
   12.49                  break;
   12.50              }
   12.51  
   12.52 -            if ( shadow_mode_translate(FOREIGNDOM) )
   12.53 -                shadow_guest_physmap_add_page(FOREIGNDOM, gpfn, mfn);
   12.54 -            else 
   12.55 -                set_gpfn_from_mfn(mfn, gpfn);
   12.56 +            if ( unlikely(shadow_mode_translate(FOREIGNDOM)) )
   12.57 +            {
   12.58 +                MEM_LOG("Mach-phys update on shadow-translate guest");
   12.59 +                break;
   12.60 +            }
   12.61 +
   12.62 +            set_gpfn_from_mfn(mfn, gpfn);
   12.63              okay = 1;
   12.64  
   12.65 -            // Mark the new gfn dirty...
   12.66              mark_dirty(FOREIGNDOM, mfn);
   12.67  
   12.68              put_page(mfn_to_page(mfn));
   12.69 @@ -2557,10 +2560,7 @@ static int destroy_grant_va_mapping(
   12.70      }
   12.71      ol1e = *pl1e;
   12.72  
   12.73 -    /*
   12.74 -     * Check that the virtual address supplied is actually mapped to
   12.75 -     * frame.
   12.76 -     */
   12.77 +    /* Check that the virtual address supplied is actually mapped to frame. */
   12.78      if ( unlikely(l1e_get_pfn(ol1e) != frame) )
   12.79      {
   12.80          MEM_LOG("PTE entry %lx for address %lx doesn't match frame %lx",
   12.81 @@ -2574,7 +2574,7 @@ static int destroy_grant_va_mapping(
   12.82      {
   12.83          MEM_LOG("Cannot delete PTE entry at %p", (unsigned long *)pl1e);
   12.84          rc = GNTST_general_error;
   12.85 -        goto out; // this is redundant & unnecessary, but informative
   12.86 +        goto out;
   12.87      }
   12.88  
   12.89   out: