ia64/xen-unstable

changeset 6766:219d96d545fc

merge?
author cl349@firebug.cl.cam.ac.uk
date Mon Sep 12 20:00:41 2005 +0000 (2005-09-12)
parents cdaaaa027bf8 888094e5ac07
children d22091179975
files linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c tools/examples/Makefile tools/examples/block-enbd tools/examples/block-file tools/examples/xen-backend.agent tools/libxc/xc_linux_restore.c tools/libxc/xc_vmx_build.c tools/python/xen/xend/XendDomainInfo.py tools/vnet/Make.env tools/vnet/examples/vnet-insert tools/vnet/libxutil/mem_stream.c tools/vnet/libxutil/mem_stream.h tools/vnet/vnet-module/varp_util.c tools/vnet/vnet-module/varp_util.h xen/arch/x86/domain.c xen/arch/x86/vmx.c
line diff
     1.1 --- a/tools/libxc/xc_linux_restore.c	Mon Sep 12 19:59:40 2005 +0000
     1.2 +++ b/tools/libxc/xc_linux_restore.c	Mon Sep 12 20:00:41 2005 +0000
     1.3 @@ -42,18 +42,18 @@ read_exact(int fd, void *buf, size_t cou
     1.4      unsigned char *b = buf;
     1.5  
     1.6      while (r < count) {
     1.7 -	s = read(fd, &b[r], count - r);
     1.8 -	if (s <= 0)
     1.9 -	    break;
    1.10 -	r += s;
    1.11 +        s = read(fd, &b[r], count - r);
    1.12 +        if (s <= 0)
    1.13 +            break;
    1.14 +        r += s;
    1.15      }
    1.16  
    1.17      return r;
    1.18  }
    1.19  
    1.20  int xc_linux_restore(int xc_handle, int io_fd, u32 dom, unsigned long nr_pfns,
    1.21 -		     unsigned int store_evtchn, unsigned long *store_mfn,
    1.22 -		     unsigned int console_evtchn, unsigned long *console_mfn)
    1.23 +                     unsigned int store_evtchn, unsigned long *store_mfn,
    1.24 +                     unsigned int console_evtchn, unsigned long *console_mfn)
    1.25  {
    1.26      dom0_op_t op;
    1.27      int rc = 1, i, n, k;
    1.28 @@ -91,6 +91,8 @@ int xc_linux_restore(int xc_handle, int 
    1.29      /* A temporary mapping of the guest's start_info page. */
    1.30      start_info_t *start_info;
    1.31  
    1.32 +    int pt_levels = 2; /* XXX auto-detect this */
    1.33 +
    1.34      char *region_base;
    1.35  
    1.36      xc_mmu_t *mmu = NULL;
    1.37 @@ -112,8 +114,8 @@ int xc_linux_restore(int xc_handle, int 
    1.38      }
    1.39  
    1.40      if (read_exact(io_fd, pfn_to_mfn_frame_list, PAGE_SIZE) != PAGE_SIZE) {
    1.41 -	ERR("read pfn_to_mfn_frame_list failed");
    1.42 -	goto out;
    1.43 +        ERR("read pfn_to_mfn_frame_list failed");
    1.44 +        goto out;
    1.45      }
    1.46  
    1.47      /* We want zeroed memory so use calloc rather than malloc. */
    1.48 @@ -289,10 +291,10 @@ int xc_linux_restore(int xc_handle, int 
    1.49                          if ( xpfn >= nr_pfns )
    1.50                          {
    1.51                              ERR("Frame number in type %lu page "
    1.52 -                                       "table is out of range. i=%d k=%d "
    1.53 -                                       "pfn=0x%lx nr_pfns=%lu", 
    1.54 -                                       region_pfn_type[i]>>28, i, 
    1.55 -                                       k, xpfn, nr_pfns);
    1.56 +                                "table is out of range. i=%d k=%d "
    1.57 +                                "pfn=0x%lx nr_pfns=%lu", 
    1.58 +                                region_pfn_type[i]>>28, i, 
    1.59 +                                k, xpfn, nr_pfns);
    1.60                              goto out;
    1.61                          }
    1.62  
    1.63 @@ -317,10 +319,10 @@ int xc_linux_restore(int xc_handle, int 
    1.64                          if ( xpfn >= nr_pfns )
    1.65                          {
    1.66                              ERR("Frame number in type %lu page"
    1.67 -                                       " table is out of range. i=%d k=%d "
    1.68 -                                       "pfn=%lu nr_pfns=%lu",
    1.69 -                                       region_pfn_type[i]>>28, i, k, 
    1.70 -                                       xpfn, nr_pfns);
    1.71 +                                " table is out of range. i=%d k=%d "
    1.72 +                                "pfn=%lu nr_pfns=%lu",
    1.73 +                                region_pfn_type[i]>>28, i, k, 
    1.74 +                                xpfn, nr_pfns);
    1.75                              goto out;
    1.76                          }
    1.77  
    1.78 @@ -334,8 +336,8 @@ int xc_linux_restore(int xc_handle, int 
    1.79  
    1.80              default:
    1.81                  ERR("Bogus page type %lx page table is "
    1.82 -                           "out of range. i=%d nr_pfns=%lu", 
    1.83 -                           region_pfn_type[i], i, nr_pfns);
    1.84 +                    "out of range. i=%d nr_pfns=%lu", 
    1.85 +                    region_pfn_type[i], i, nr_pfns);
    1.86                  goto out;
    1.87  
    1.88              } /* end of page type switch statement */
    1.89 @@ -362,8 +364,8 @@ int xc_linux_restore(int xc_handle, int 
    1.90              }
    1.91  
    1.92              if ( xc_add_mmu_update(xc_handle, mmu,
    1.93 -				   (mfn<<PAGE_SHIFT) | MMU_MACHPHYS_UPDATE,
    1.94 -				   pfn) )
    1.95 +                                   (mfn<<PAGE_SHIFT) | MMU_MACHPHYS_UPDATE,
    1.96 +                                   pfn) )
    1.97              {
    1.98                  printf("machpys mfn=%ld pfn=%ld\n",mfn,pfn);
    1.99                  goto out;
   1.100 @@ -377,6 +379,33 @@ int xc_linux_restore(int xc_handle, int 
   1.101  
   1.102      DPRINTF("Received all pages\n");
   1.103  
   1.104 +    if ( pt_levels == 3 )
   1.105 +    {
   1.106 +        /* Get all PGDs below 4GB. */
   1.107 +        for ( i = 0; i < nr_pfns; i++ )
   1.108 +        {
   1.109 +            if ( ((pfn_type[i] & LTABTYPE_MASK) == L3TAB) &&
   1.110 +                 (pfn_to_mfn_table[i] > 0xfffffUL) )
   1.111 +            {
   1.112 +                unsigned long new_mfn = xc_make_page_below_4G(
   1.113 +                    xc_handle, dom, pfn_to_mfn_table[i]);
   1.114 +                if ( new_mfn == 0 )
   1.115 +                {
   1.116 +                    fprintf(stderr, "Couldn't get a page below 4GB :-(\n");
   1.117 +                    goto out;
   1.118 +                }
   1.119 +                pfn_to_mfn_table[i] = new_mfn;
   1.120 +                if ( xc_add_mmu_update(
   1.121 +                    xc_handle, mmu, (new_mfn << PAGE_SHIFT) |
   1.122 +                    MMU_MACHPHYS_UPDATE, i) )
   1.123 +                {
   1.124 +                    fprintf(stderr, "Couldn't m2p on PAE root pgdir\n");
   1.125 +                    goto out;
   1.126 +                }
   1.127 +            }
   1.128 +        }
   1.129 +    }
   1.130 +
   1.131      if ( xc_finish_mmu_updates(xc_handle, mmu) )
   1.132          goto out;
   1.133  
   1.134 @@ -410,57 +439,57 @@ int xc_linux_restore(int xc_handle, int 
   1.135  
   1.136      /* Get the list of PFNs that are not in the psuedo-phys map */
   1.137      {
   1.138 -	unsigned int count;
   1.139 +        unsigned int count;
   1.140          unsigned long *pfntab;
   1.141 -	int rc;
   1.142 -
   1.143 -	if ( read_exact(io_fd, &count, sizeof(count)) != sizeof(count) )
   1.144 -	{
   1.145 -	    ERR("Error when reading pfn count");
   1.146 -	    goto out;
   1.147 -	}
   1.148 +        int rc;
   1.149  
   1.150 -	pfntab = malloc( sizeof(unsigned int) * count );
   1.151 -	if ( pfntab == NULL )
   1.152 -	{
   1.153 -	    ERR("Out of memory");
   1.154 -	    goto out;
   1.155 -	}
   1.156 +        if ( read_exact(io_fd, &count, sizeof(count)) != sizeof(count) )
   1.157 +        {
   1.158 +            ERR("Error when reading pfn count");
   1.159 +            goto out;
   1.160 +        }
   1.161  
   1.162 -	if ( read_exact(io_fd, pfntab, sizeof(unsigned int)*count) !=
   1.163 +        pfntab = malloc( sizeof(unsigned int) * count );
   1.164 +        if ( pfntab == NULL )
   1.165 +        {
   1.166 +            ERR("Out of memory");
   1.167 +            goto out;
   1.168 +        }
   1.169 +
   1.170 +        if ( read_exact(io_fd, pfntab, sizeof(unsigned int)*count) !=
   1.171               sizeof(unsigned int)*count )
   1.172 -	{
   1.173 -	    ERR("Error when reading pfntab");
   1.174 -	    goto out;
   1.175 -	}
   1.176 +        {
   1.177 +            ERR("Error when reading pfntab");
   1.178 +            goto out;
   1.179 +        }
   1.180  
   1.181 -	for ( i = 0; i < count; i++ )
   1.182 -	{
   1.183 -	    unsigned long pfn = pfntab[i];
   1.184 -	    pfntab[i]=pfn_to_mfn_table[pfn];
   1.185 -	    pfn_to_mfn_table[pfn] = 0x80000001;  // not in pmap
   1.186 -	}
   1.187 +        for ( i = 0; i < count; i++ )
   1.188 +        {
   1.189 +            unsigned long pfn = pfntab[i];
   1.190 +            pfntab[i]=pfn_to_mfn_table[pfn];
   1.191 +            pfn_to_mfn_table[pfn] = 0x80000001;  // not in pmap
   1.192 +        }
   1.193  
   1.194 -	if ( count > 0 )
   1.195 -	{
   1.196 +        if ( count > 0 )
   1.197 +        {
   1.198              struct xen_memory_reservation reservation = {
   1.199                  .extent_start = pfntab,
   1.200                  .nr_extents   = count,
   1.201                  .extent_order = 0,
   1.202                  .domid        = dom
   1.203              };
   1.204 -	    if ( (rc = xc_memory_op(xc_handle,
   1.205 +            if ( (rc = xc_memory_op(xc_handle,
   1.206                                      XENMEM_decrease_reservation,
   1.207                                      &reservation)) != count )
   1.208 -	    {
   1.209 -		ERR("Could not decrease reservation : %d",rc);
   1.210 -		goto out;
   1.211 -	    }
   1.212 -	    else
   1.213 -	    {
   1.214 -		printf("Decreased reservation by %d pages\n", count);
   1.215 -	    }
   1.216 -	}	
   1.217 +            {
   1.218 +                ERR("Could not decrease reservation : %d",rc);
   1.219 +                goto out;
   1.220 +            }
   1.221 +            else
   1.222 +            {
   1.223 +                printf("Decreased reservation by %d pages\n", count);
   1.224 +            }
   1.225 +        } 
   1.226      }
   1.227  
   1.228      if ( read_exact(io_fd, &ctxt,            sizeof(ctxt)) != sizeof(ctxt) ||
   1.229 @@ -484,10 +513,10 @@ int xc_linux_restore(int xc_handle, int 
   1.230      start_info->shared_info = shared_info_frame << PAGE_SHIFT;
   1.231      start_info->flags       = 0;
   1.232      *store_mfn = start_info->store_mfn   =
   1.233 -	pfn_to_mfn_table[start_info->store_mfn];
   1.234 +        pfn_to_mfn_table[start_info->store_mfn];
   1.235      start_info->store_evtchn = store_evtchn;
   1.236      *console_mfn = start_info->console_mfn   =
   1.237 -	pfn_to_mfn_table[start_info->console_mfn];
   1.238 +        pfn_to_mfn_table[start_info->console_mfn];
   1.239      start_info->console_evtchn = console_evtchn;
   1.240      munmap(start_info, PAGE_SIZE);
   1.241  
   1.242 @@ -522,7 +551,7 @@ int xc_linux_restore(int xc_handle, int 
   1.243  
   1.244      /* clear any pending events and the selector */
   1.245      memset(&(shared_info->evtchn_pending[0]), 0,
   1.246 -	   sizeof (shared_info->evtchn_pending));
   1.247 +           sizeof (shared_info->evtchn_pending));
   1.248      for ( i = 0; i < MAX_VIRT_CPUS; i++ )
   1.249          shared_info->vcpu_data[i].evtchn_pending_sel = 0;
   1.250  
   1.251 @@ -548,7 +577,7 @@ int xc_linux_restore(int xc_handle, int 
   1.252      }
   1.253      
   1.254      if ( (live_pfn_to_mfn_table = 
   1.255 -	  xc_map_foreign_batch(xc_handle, dom, 
   1.256 +          xc_map_foreign_batch(xc_handle, dom, 
   1.257                                 PROT_WRITE,
   1.258                                 pfn_to_mfn_frame_list,
   1.259                                 (nr_pfns+1023)/1024 )) == 0 )
     2.1 --- a/tools/libxc/xc_vmx_build.c	Mon Sep 12 19:59:40 2005 +0000
     2.2 +++ b/tools/libxc/xc_vmx_build.c	Mon Sep 12 20:00:41 2005 +0000
     2.3 @@ -578,15 +578,6 @@ static int setup_guest(int xc_handle,
     2.4      sp->sp_global.eport = control_evtchn;
     2.5      munmap(sp, PAGE_SIZE);
     2.6  
     2.7 -    /*
     2.8 -     * Pin down l2tab addr as page dir page - causes hypervisor to provide
     2.9 -     * correct protection for the page
    2.10 -     */ 
    2.11 -#ifdef __i386__
    2.12 -    if ( pin_table(xc_handle, MMUEXT_PIN_L2_TABLE, l2tab>>PAGE_SHIFT, dom) )
    2.13 -        goto error_out;
    2.14 -#endif
    2.15 -
    2.16      /* Send the page update requests down to the hypervisor. */
    2.17      if ( xc_finish_mmu_updates(xc_handle, mmu) )
    2.18          goto error_out;
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/vnet/Make.env	Mon Sep 12 20:00:41 2005 +0000
     3.3 @@ -0,0 +1,20 @@
     3.4 +# -*- mode: Makefile; -*-
     3.5 +
     3.6 +export XEN_ROOT        = $(shell cd $(VNET_ROOT)/../.. && pwd)
     3.7 +export LINUX_SERIES   ?= 2.6
     3.8 +
     3.9 +DISTDIR               ?= $(XEN_ROOT)/dist
    3.10 +export DESTDIR        ?= $(DISTDIR)/install
    3.11 +
    3.12 +export VNET_MODULE_DIR = $(VNET_ROOT)/vnet-module
    3.13 +export VNETD_DIR       = $(VNET_ROOT)/vnetd
    3.14 +export LIBXUTIL_DIR    = $(VNET_ROOT)/libxutil
    3.15 +
    3.16 +export GC_DIR          = $(VNET_ROOT)/build/gc
    3.17 +export GC_INCLUDE      = $(GC_DIR)/include
    3.18 +export GC_LIB_DIR      = $(GC_DIR)/lib
    3.19 +export GC_LIB_A        = $(GC_LIB_DIR)/libgc.a
    3.20 +export GC_LIB_SO       = $(GC_LIB_DIR)/libgc.so
    3.21 +
    3.22 +#$(warning XEN_ROOT  = $(XEN_ROOT))
    3.23 +#$(warning DESTDIR   = $(DESTDIR))
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tools/vnet/examples/vnet-insert	Mon Sep 12 20:00:41 2005 +0000
     4.3 @@ -0,0 +1,28 @@
     4.4 +#!/bin/bash
     4.5 +
     4.6 +# Insert the vnet module if it can be found and
     4.7 +# it's not already there.
     4.8 +vnet_insert () {
     4.9 +    local module="vnet_module"
    4.10 +    local mod_dir=/lib/modules/$(uname -r)
    4.11 +    local mod_obj=""
    4.12 +
    4.13 +    if lsmod | grep -q ${module} ; then
    4.14 +        echo "VNET: ${module} loaded"
    4.15 +        return
    4.16 +    fi
    4.17 +    local mods=$(find ${mod_dir} -name "${module}.*o")
    4.18 +    if [[ ${mods} ]] ; then
    4.19 +        for mod_obj in ${mods} ; do
    4.20 +            break
    4.21 +        done
    4.22 +    fi
    4.23 +    if [ -z "${mod_obj}" ] ; then
    4.24 +        echo "VNET: ${module} not found"
    4.25 +        exit 1
    4.26 +    fi
    4.27 +    echo "VNET: Loading ${module} from ${mod_obj}"
    4.28 +    insmod ${mod_obj} "$@"
    4.29 +}
    4.30 +
    4.31 +vnet_insert "$@"
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/vnet/libxutil/mem_stream.c	Mon Sep 12 20:00:41 2005 +0000
     5.3 @@ -0,0 +1,319 @@
     5.4 +/*
     5.5 + * Copyright (C) 2005 Mike Wray <mike.wray@hp.com>
     5.6 + *
     5.7 + * This library is free software; you can redistribute it and/or modify
     5.8 + * it under the terms of the GNU Lesser General Public License as published by
     5.9 + * the Free Software Foundation; either version 2.1 of the License, or
    5.10 + * (at your option) any later version.
    5.11 + *
    5.12 + * This library is distributed in the hope that it will be useful,
    5.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.15 + * GNU Lesser General Public License for more details.
    5.16 + *
    5.17 + * You should have received a copy of the GNU Lesser General Public License
    5.18 + * along with this library; if not, write to the Free Software
    5.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    5.20 + */
    5.21 +
    5.22 +/** @file
    5.23 + * IOStream subtype for input and output to memory.
    5.24 + * Usable from user or kernel code (with __KERNEL__ defined).
    5.25 + */
    5.26 +
    5.27 +#include "sys_string.h"
    5.28 +#include "mem_stream.h"
    5.29 +#include "allocate.h"
    5.30 +
    5.31 +/** Internal state for a memory stream.
    5.32 + *
    5.33 + * The memory stream buffer is treated as a circular buffer.
    5.34 + * The lo and hi markers indicate positions in the buffer, but
    5.35 + * are not reduced modulo the buffer size. This avoids the ambiguity
    5.36 + * between a full and empty buffer when using reduced values.
    5.37 + *
    5.38 + * If x is a marker, then buf + (x % buf_n) is the corresponding
    5.39 + * pointer into the buffer. When the buffer is empty, lo == hi,
    5.40 + * and the corresponding pointers are equal. When the buffer is
    5.41 + * full, hi == lo + buf_n, and the corresponding pointers
    5.42 + * are also equal.
    5.43 + *
    5.44 + * Data is written after the high pointer and read from the lo pointer.
    5.45 + * The value hi - lo is the number of bytes in the buffer.
    5.46 + */
    5.47 +typedef struct MemData {
    5.48 +    /** Data buffer. */
    5.49 +    char *buf;
    5.50 +    /** Low marker - start of readable area. */
    5.51 +    unsigned long lo;
    5.52 +    /** High marker - end of readable area, start of writeable area. */
    5.53 +    unsigned long hi;
    5.54 +    /** Size of the buffer. */
    5.55 +    unsigned int buf_n;
    5.56 +    /** Maximum size the buffer can grow to. */
    5.57 +    unsigned int buf_max;
    5.58 +    /** Error code. */
    5.59 +    int err;
    5.60 +} MemData;
    5.61 +
    5.62 +/** Get number of bytes available to read.
    5.63 + *
    5.64 + * @param data mem stream
    5.65 + * @return bytes
    5.66 + */
    5.67 +static inline int mem_len(struct MemData *data){
    5.68 +    return data->hi - data->lo;
    5.69 +}
    5.70 +
    5.71 +/** Get available space left in the buffer.
    5.72 + *
    5.73 + * @param data mem stream
    5.74 + * @return bytes
    5.75 + */
    5.76 +static inline int mem_room(struct MemData *data){
    5.77 +    return data->buf_n - mem_len(data);
    5.78 +}
    5.79 +
    5.80 +/** Get a pointer to the start of the data in the buffer.
    5.81 + *
    5.82 + * @param data mem stream
    5.83 + * @return lo pointer
    5.84 + */
    5.85 +static inline char * mem_lo(struct MemData *data){
    5.86 +    return data->buf + (data->lo % data->buf_n);
    5.87 +}
    5.88 +
    5.89 +/** Get a pointer to the end of the data in the buffer.
    5.90 + *
    5.91 + * @param data mem stream
    5.92 + * @return hi pointer
    5.93 + */
    5.94 +static inline char * mem_hi(struct MemData *data){
    5.95 +    return data->buf + (data->hi % data->buf_n);
    5.96 +}
    5.97 +
    5.98 +/** Get a pointer to the end of the buffer.
    5.99 + *
   5.100 + * @param data mem stream
   5.101 + * @return end pointer
   5.102 + */
   5.103 +static inline char * mem_end(struct MemData *data){
   5.104 +    return data->buf + data->buf_n;
   5.105 +}
   5.106 +
   5.107 +static int mem_error(IOStream *io);
   5.108 +static int mem_close(IOStream *io);
   5.109 +static void mem_free(IOStream *io);
   5.110 +static int mem_write(IOStream *io, const void *msg, size_t n);
   5.111 +static int mem_read(IOStream *io, void *buf, size_t n);
   5.112 +
   5.113 +/** Minimum delta used to increment the buffer. */
   5.114 +static int delta_min = 256;
   5.115 +
   5.116 +/** Methods for a memory stream. */
   5.117 +static IOMethods mem_methods = {
   5.118 +    read:  mem_read,
   5.119 +    write: mem_write,
   5.120 +    error: mem_error,
   5.121 +    close: mem_close,
   5.122 +    free:  mem_free,
   5.123 +};
   5.124 +
   5.125 +/** Get the memory stream state.
   5.126 + *
   5.127 + * @param io memory stream
   5.128 + * @return state
   5.129 + */
   5.130 +static inline MemData *get_mem_data(IOStream *io){
   5.131 +    return (MemData*)io->data;
   5.132 +}
   5.133 +
   5.134 +/** Get the number of bytes available to read.
   5.135 + *
   5.136 + * @param io memory stream
   5.137 + * @return number of bytes
   5.138 + */
   5.139 +int mem_stream_avail(IOStream *io){
   5.140 +    MemData *data = get_mem_data(io);
   5.141 +    return (data->err ? -data->err : mem_len(data));
   5.142 +}
   5.143 +
   5.144 +/** Copy bytes from a memory stream into a buffer.
   5.145 + *
   5.146 + * @param data mem stream
   5.147 + * @param buf buffer
   5.148 + * @param n number of bytes to copy
   5.149 + */
   5.150 +static void mem_get(MemData *data, char *buf, size_t n){
   5.151 +    char *start = mem_lo(data);
   5.152 +    char *end = mem_end(data);
   5.153 +    if (start + n < end) {
   5.154 +        memcpy(buf, start, n);
   5.155 +    } else {
   5.156 +        int k = end - start;
   5.157 +        memcpy(buf, start, k);
   5.158 +        memcpy(buf + k, data->buf, n - k);
   5.159 +    }
   5.160 +}
   5.161 +
   5.162 +/** Copy bytes from a buffer into a memory stream.
   5.163 + *
   5.164 + * @param data mem stream
   5.165 + * @param buf buffer
   5.166 + * @param n number of bytes to copy
   5.167 + */
   5.168 +static void mem_put(MemData *data, const char *buf, size_t n){
   5.169 +    char *start = mem_hi(data);
   5.170 +    char *end = mem_end(data);
   5.171 +    if(start + n < end){
   5.172 +        memcpy(start, buf, n);
   5.173 +    } else {
   5.174 +        int k = end - start;
   5.175 +        memcpy(start, buf, k);
   5.176 +        memcpy(data->buf, buf + k, n - k);
   5.177 +    }
   5.178 +}
   5.179 +
   5.180 +/** Expand the buffer used by a memory stream.
   5.181 + *
   5.182 + * @param data mem stream
   5.183 + * @param extra number of bytes to expand by
   5.184 + * @return 0 on success, negative error otherwise
   5.185 + */
   5.186 +static int mem_expand(MemData *data, size_t extra){
   5.187 +    int err = -ENOMEM;
   5.188 +    int delta = (extra < delta_min ? delta_min : extra);
   5.189 +    if(data->buf_max > 0){
   5.190 +        int delta_max = data->buf_max - data->buf_n;
   5.191 +        if(delta > delta_max){
   5.192 +            delta = extra;
   5.193 +            if(delta > delta_max) goto exit;
   5.194 +        }
   5.195 +    }
   5.196 +    int buf_n = data->buf_n + delta;
   5.197 +    char *buf = allocate(buf_n);
   5.198 +    if(!buf) goto exit;
   5.199 +    mem_get(data, buf, mem_len(data));
   5.200 +    data->hi = mem_len(data);
   5.201 +    data->lo = 0;
   5.202 +    deallocate(data->buf);
   5.203 +    data->buf = buf;
   5.204 +    data->buf_n = buf_n;
   5.205 +    err = 0;
   5.206 +  exit:
   5.207 +    if(err){
   5.208 +        data->err = -err;
   5.209 +    }
   5.210 +    return err;
   5.211 +}
   5.212 +
   5.213 +/** Write bytes from a buffer into a memory stream.
   5.214 + * The internal buffer is expanded as needed to hold the data,
   5.215 + * up to the stream maximum (if specified). If the buffer cannot
   5.216 + * be expanded -ENOMEM is returned.
   5.217 + *
   5.218 + * @param io mem stream
   5.219 + * @param buf buffer
   5.220 + * @param n number of bytes to write
   5.221 + * @return number of bytes written on success, negative error code otherwise
   5.222 + */
   5.223 +static int mem_write(IOStream *io, const void *msg, size_t n){
   5.224 +    MemData *data = get_mem_data(io);
   5.225 +    if(data->err) return -data->err;
   5.226 +    int room = mem_room(data);
   5.227 +    if(n > room){
   5.228 +        int err = mem_expand(data, n - room);
   5.229 +        if(err) return err;
   5.230 +    }
   5.231 +    mem_put(data, msg, n);
   5.232 +    data->hi += n;
   5.233 +    return n;
   5.234 +}
   5.235 +
   5.236 +/** Read bytes from a memory stream into a buffer.
   5.237 + *
   5.238 + * @param io mem stream
   5.239 + * @param buf buffer
   5.240 + * @param n maximum number of bytes to read
   5.241 + * @return number of bytes read on success, negative error code otherwise
   5.242 + */
   5.243 +static int mem_read(IOStream *io, void *buf, size_t n){
   5.244 +    MemData *data = get_mem_data(io);
   5.245 +    if(data->err) return -data->err;
   5.246 +    int k = mem_len(data);
   5.247 +    if(n > k){
   5.248 +        n = k;
   5.249 +    }
   5.250 +    mem_get(data, buf, n);
   5.251 +    data->lo += n;
   5.252 +    return n;
   5.253 +}
   5.254 +
   5.255 +/** Test if a memory stream has an error.
   5.256 + *
   5.257 + * @param io mem stream
   5.258 + * @return 0 if ok, error code otherwise
   5.259 + */
   5.260 +static int mem_error(IOStream *io){
   5.261 +    MemData *data = get_mem_data(io);
   5.262 +    return data->err;
   5.263 +}
   5.264 +
   5.265 +/** Close a memory stream.
   5.266 + *
   5.267 + * @param io mem stream
   5.268 + * @return 0
   5.269 + */
   5.270 +static int mem_close(IOStream *io){
   5.271 +    MemData *data = get_mem_data(io);
   5.272 +    if(!data->err){
   5.273 +        data->err = ENOTCONN;
   5.274 +    }
   5.275 +    return 0;
   5.276 +}
   5.277 +
   5.278 +/** Free a memory stream.
   5.279 + *
   5.280 + * @param io mem stream
   5.281 + */
   5.282 +static void mem_free(IOStream *io){
   5.283 +    MemData *data = get_mem_data(io);
   5.284 +    deallocate(data->buf);
   5.285 +    memzero(data, sizeof(*data));
   5.286 +    deallocate(data);
   5.287 +}
   5.288 +
   5.289 +/** Allocate and initialise a memory stream.
   5.290 + *
   5.291 + * @param buf_n initial buffer size (0 means default)
   5.292 + * @param buf_max maximum buffer size (0 means no max)
   5.293 + * @return new stream (free using IOStream_close)
   5.294 + */
   5.295 +IOStream *mem_stream_new_size(size_t buf_n, size_t buf_max){
   5.296 +    int err = -ENOMEM;
   5.297 +    MemData *data = ALLOCATE(MemData);
   5.298 +    if(!data) goto exit;
   5.299 +    IOStream *io = ALLOCATE(IOStream);
   5.300 +    if(!io) goto exit;
   5.301 +    if(buf_n <= delta_min){
   5.302 +        buf_n = delta_min;
   5.303 +    }
   5.304 +    if(buf_max > 0 && buf_max < buf_n){
   5.305 +        buf_max = buf_n;
   5.306 +    }
   5.307 +    data->buf = allocate(buf_n);
   5.308 +    if(!data->buf) goto exit;
   5.309 +    data->buf_n = buf_n;
   5.310 +    data->buf_max = buf_max;
   5.311 +    io->methods = &mem_methods;
   5.312 +    io->data = data;
   5.313 +    io->nofree = 0;
   5.314 +    err = 0;
   5.315 +  exit:
   5.316 +    if(err){
   5.317 +        deallocate(data);
   5.318 +        deallocate(io);
   5.319 +        io = NULL;
   5.320 +    }
   5.321 +    return io;
   5.322 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tools/vnet/libxutil/mem_stream.h	Mon Sep 12 20:00:41 2005 +0000
     6.3 @@ -0,0 +1,32 @@
     6.4 +/*
     6.5 + * Copyright (C) 2005 Mike Wray <mike.wray@hp.com>
     6.6 + *
     6.7 + * This library is free software; you can redistribute it and/or modify
     6.8 + * it under the terms of the GNU Lesser General Public License as published by
     6.9 + * the Free Software Foundation; either version 2.1 of the License, or
    6.10 + * (at your option) any later version.
    6.11 + *
    6.12 + * This library is distributed in the hope that it will be useful,
    6.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.15 + * GNU Lesser General Public License for more details.
    6.16 + *
    6.17 + * You should have received a copy of the GNU Lesser General Public License
    6.18 + * along with this library; if not, write to the Free Software
    6.19 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    6.20 + */
    6.21 +
    6.22 +#ifndef _XUTIL_MEM_STREAM_H_
    6.23 +#define _XUTIL_MEM_STREAM_H_
    6.24 +
    6.25 +#include "iostream.h"
    6.26 +
    6.27 +extern IOStream *mem_stream_new_size(size_t buf_n, size_t buf_max);
    6.28 +
    6.29 +extern int mem_stream_avail(IOStream *io);
    6.30 +
    6.31 +static inline IOStream *mem_stream_new(void){
    6.32 +    return mem_stream_new_size(0, 0);
    6.33 +}
    6.34 +
    6.35 +#endif /* !_XUTIL_MEM_STREAM_H_ */
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/tools/vnet/vnet-module/varp_util.c	Mon Sep 12 20:00:41 2005 +0000
     7.3 @@ -0,0 +1,77 @@
     7.4 +/*
     7.5 + * Copyright (C) 2005 Mike Wray <mike.wray@hp.com>
     7.6 + *
     7.7 + * This program is free software; you can redistribute it and/or modify
     7.8 + * it under the terms of the GNU General Public License as published by the 
     7.9 + * Free Software Foundation; either version 2 of the License, or (at your
    7.10 + * option) any later version.
    7.11 + * 
    7.12 + * This program is distributed in the hope that it will be useful, but
    7.13 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    7.14 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
    7.15 + * for more details.
    7.16 + *
    7.17 + * You should have received a copy of the GNU General Public License along
    7.18 + * with this program; if not, write to the Free software Foundation, Inc.,
    7.19 + * 59 Temple Place, suite 330, Boston, MA 02111-1307 USA
    7.20 + *
    7.21 + */
    7.22 +
    7.23 +static int hex16(char *s, uint16_t *val)
    7.24 +{
    7.25 +    int err = -EINVAL;
    7.26 +    uint16_t v = 0;
    7.27 +    
    7.28 +    for( ; *s; s++){
    7.29 +        v <<= 4;
    7.30 +        if('0' <= *s && *s <= '9'){
    7.31 +            v |= *s - '0';
    7.32 +        } else if('A' <= *s && *s <= 'F'){
    7.33 +            v |= *s - 'A' + 10;
    7.34 +        } else if('a' <= *s && *s <= 'f'){
    7.35 +            v |= *s - 'a' + 10;
    7.36 +        } else {
    7.37 +            goto exit;
    7.38 +        }
    7.39 +    }
    7.40 +    err = 0;
    7.41 +  exit:
    7.42 +    *val = (err ? 0 : v);
    7.43 +    return err;
    7.44 +}
    7.45 +
    7.46 +int VnetId_aton(const char *s, VnetId *vnet){
    7.47 +    int err = -EINVAL;
    7.48 +    const char *p, *q;
    7.49 +    uint16_t v;
    7.50 +    char buf[5];
    7.51 +    int buf_n = sizeof(buf) - 1;
    7.52 +    int i, n;
    7.53 +    const int elts_n = 8;
    7.54 +
    7.55 +    q = s;
    7.56 +    p = strchr(q, ':');
    7.57 +    i = (p ? 0 : elts_n - 1);
    7.58 +    do {
    7.59 +        if(!p){
    7.60 +            if(i < elts_n - 1) goto exit;
    7.61 +            p = s + strlen(s);
    7.62 +        }
    7.63 +        n = p - q;
    7.64 +        if(n > buf_n) goto exit;
    7.65 +        memcpy(buf, q, n);
    7.66 +        buf[n] = '\0';
    7.67 +        err = hex16(buf, &v);
    7.68 +        if(err) goto exit;
    7.69 +        vnet->u.vnet16[i] = htons(v);
    7.70 +        q = p+1;
    7.71 +        p = strchr(q, ':');
    7.72 +        i++;
    7.73 +    } while(i < elts_n);
    7.74 +    err = 0;
    7.75 +  exit:
    7.76 +    if(err){
    7.77 +        *vnet = (VnetId){};
    7.78 +    }
    7.79 +    return err;
    7.80 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/tools/vnet/vnet-module/varp_util.h	Mon Sep 12 20:00:41 2005 +0000
     8.3 @@ -0,0 +1,142 @@
     8.4 +/*
     8.5 + * Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
     8.6 + *
     8.7 + * This program is free software; you can redistribute it and/or modify
     8.8 + * it under the terms of the GNU General Public License as published by the 
     8.9 + * Free Software Foundation; either version 2 of the License, or (at your
    8.10 + * option) any later version.
    8.11 + * 
    8.12 + * This program is distributed in the hope that it will be useful, but
    8.13 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    8.14 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
    8.15 + * for more details.
    8.16 + *
    8.17 + * You should have received a copy of the GNU General Public License along
    8.18 + * with this program; if not, write to the Free software Foundation, Inc.,
    8.19 + * 59 Temple Place, suite 330, Boston, MA 02111-1307 USA
    8.20 + *
    8.21 + */
    8.22 +#ifndef _VNET_VARP_UTIL_H
    8.23 +#define _VNET_VARP_UTIL_H
    8.24 +
    8.25 +#include "hash_table.h"
    8.26 +
    8.27 +/** Size of a string buffer to store a varp address. */
    8.28 +#define VARP_ADDR_BUF 56
    8.29 +
    8.30 +/** Size of a string buffer to store a vnet id. */
    8.31 +#define VNET_ID_BUF 56
    8.32 +
    8.33 +#ifndef NIPQUAD
    8.34 +#define NIPQUAD(addr) \
    8.35 +	((unsigned char *)&addr)[0], \
    8.36 +	((unsigned char *)&addr)[1], \
    8.37 +	((unsigned char *)&addr)[2], \
    8.38 +	((unsigned char *)&addr)[3]
    8.39 +#endif
    8.40 +
    8.41 +#ifndef NIP6
    8.42 +#define NIP6(addr) \
    8.43 +	ntohs((addr).s6_addr16[0]), \
    8.44 +	ntohs((addr).s6_addr16[1]), \
    8.45 +	ntohs((addr).s6_addr16[2]), \
    8.46 +	ntohs((addr).s6_addr16[3]), \
    8.47 +	ntohs((addr).s6_addr16[4]), \
    8.48 +	ntohs((addr).s6_addr16[5]), \
    8.49 +	ntohs((addr).s6_addr16[6]), \
    8.50 +	ntohs((addr).s6_addr16[7])
    8.51 +#endif
    8.52 +
    8.53 +
    8.54 +static inline const char *VarpAddr_ntoa(VarpAddr *addr, char buf[VARP_ADDR_BUF])
    8.55 +{
    8.56 +    switch(addr->family){
    8.57 +    default:
    8.58 +    case AF_INET:
    8.59 +        sprintf(buf, "%u.%u.%u.%u",
    8.60 +                NIPQUAD(addr->u.ip4));
    8.61 +        break;
    8.62 +    case AF_INET6:
    8.63 +        sprintf(buf, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
    8.64 +                NIP6(addr->u.ip6));
    8.65 +        break;
    8.66 +    }
    8.67 +    return buf;
    8.68 +}
    8.69 +
    8.70 +static inline const char *VnetId_ntoa(VnetId *vnet, char buf[VNET_ID_BUF])
    8.71 +{
    8.72 +    sprintf(buf, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
    8.73 +            ntohs(vnet->u.vnet16[0]), \
    8.74 +            ntohs(vnet->u.vnet16[1]), \
    8.75 +            ntohs(vnet->u.vnet16[2]), \
    8.76 +            ntohs(vnet->u.vnet16[3]), \
    8.77 +            ntohs(vnet->u.vnet16[4]), \
    8.78 +            ntohs(vnet->u.vnet16[5]), \
    8.79 +            ntohs(vnet->u.vnet16[6]), \
    8.80 +            ntohs(vnet->u.vnet16[7]));
    8.81 +    return buf;
    8.82 +}
    8.83 +
    8.84 +extern int VnetId_aton(const char *s, VnetId *vnet);
    8.85 +
    8.86 +/** Convert an unsigned in host order to a vnet id.
    8.87 + */
    8.88 +static inline struct VnetId toVnetId(uint32_t vnetid){
    8.89 +    struct VnetId vnet = {};
    8.90 +    vnet.u.vnet32[3] = htonl(vnetid);
    8.91 +    return vnet;
    8.92 +}
    8.93 +
    8.94 +static inline uint32_t VnetId_hash(uint32_t h, VnetId *vnet)
    8.95 +{
    8.96 +    h = hash_hul(h, vnet->u.vnet32[0]);
    8.97 +    h = hash_hul(h, vnet->u.vnet32[1]);
    8.98 +    h = hash_hul(h, vnet->u.vnet32[2]);
    8.99 +    h = hash_hul(h, vnet->u.vnet32[3]);
   8.100 +    return h;
   8.101 +}
   8.102 +
   8.103 +static inline int VnetId_eq(VnetId *vnet1, VnetId *vnet2)
   8.104 +{
   8.105 +    return memcmp(vnet1, vnet2, sizeof(VnetId)) == 0;
   8.106 +}
   8.107 +
   8.108 +static inline uint32_t VarpAddr_hash(uint32_t h, VarpAddr *addr)
   8.109 +{
   8.110 +    h = hash_hul(h, addr->family);
   8.111 +    if(addr->family == AF_INET6){
   8.112 +        h = hash_hul(h, addr->u.ip6.s6_addr32[0]);
   8.113 +        h = hash_hul(h, addr->u.ip6.s6_addr32[1]);
   8.114 +        h = hash_hul(h, addr->u.ip6.s6_addr32[2]);
   8.115 +        h = hash_hul(h, addr->u.ip6.s6_addr32[3]);
   8.116 +    } else {
   8.117 +        h = hash_hul(h, addr->u.ip4.s_addr);
   8.118 +    }
   8.119 +    return h;
   8.120 +}
   8.121 +
   8.122 +static inline int VarpAddr_eq(VarpAddr *addr1, VarpAddr*addr2)
   8.123 +{
   8.124 +    return memcmp(addr1, addr2, sizeof(VarpAddr)) == 0;
   8.125 +}
   8.126 +
   8.127 +static inline uint32_t Vmac_hash(uint32_t h, Vmac *vmac)
   8.128 +{
   8.129 +    h = hash_hul(h,
   8.130 +                 (vmac->mac[0] << 24) |
   8.131 +                 (vmac->mac[1] << 16) |
   8.132 +                 (vmac->mac[2] <<  8) |
   8.133 +                 (vmac->mac[3]      ));
   8.134 +    h = hash_hul(h, 
   8.135 +                 (vmac->mac[4] <<   8) |
   8.136 +                 (vmac->mac[5]       ));
   8.137 +    return h;
   8.138 +}
   8.139 +
   8.140 +static inline int Vmac_eq(Vmac *vmac1, Vmac *vmac2)
   8.141 +{
   8.142 +    return memcmp(vmac1, vmac2, sizeof(Vmac)) == 0;
   8.143 +}
   8.144 +
   8.145 +#endif /* _VNET_VARP_UTIL_H */
     9.1 --- a/xen/arch/x86/domain.c	Mon Sep 12 19:59:40 2005 +0000
     9.2 +++ b/xen/arch/x86/domain.c	Mon Sep 12 20:00:41 2005 +0000
     9.3 @@ -461,14 +461,11 @@ int arch_set_info_guest(
     9.4          if ( !get_page(&frame_table[phys_basetab>>PAGE_SHIFT], d) )
     9.5              return -EINVAL;
     9.6      }
     9.7 -    else
     9.8 +    else if ( !(c->flags & VGCF_VMX_GUEST) )
     9.9      {
    9.10 -#ifdef __x86_64__
    9.11 -        if ( !(c->flags & VGCF_VMX_GUEST) )
    9.12 -#endif
    9.13 -            if ( !get_page_and_type(&frame_table[phys_basetab>>PAGE_SHIFT], d, 
    9.14 -                                    PGT_base_page_table) )
    9.15 -                return -EINVAL;
    9.16 +        if ( !get_page_and_type(&frame_table[phys_basetab>>PAGE_SHIFT], d, 
    9.17 +                                PGT_base_page_table) )
    9.18 +            return -EINVAL;
    9.19      }
    9.20  
    9.21      if ( (rc = (int)set_gdt(v, c->gdt_frames, c->gdt_ents)) != 0 )
    10.1 --- a/xen/arch/x86/vmx.c	Mon Sep 12 19:59:40 2005 +0000
    10.2 +++ b/xen/arch/x86/vmx.c	Mon Sep 12 20:00:41 2005 +0000
    10.3 @@ -1082,11 +1082,6 @@ static int vmx_set_cr0(unsigned long val
    10.4              VMX_DBG_LOG(DBG_LEVEL_1, "enable PAE on cr4\n");
    10.5              __vmwrite(GUEST_CR4, crn | X86_CR4_PAE);
    10.6          }
    10.7 -#elif defined( __i386__)
    10.8 -        unsigned long old_base_mfn;
    10.9 -        old_base_mfn = pagetable_get_pfn(d->arch.guest_table);
   10.10 -        if (old_base_mfn)
   10.11 -            put_page(pfn_to_page(old_base_mfn));
   10.12  #endif
   10.13          /*
   10.14           * Now arch.guest_table points to machine physical.