ia64/xen-unstable

changeset 17707:90c37c32182c

stubdom: complete libxc support

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Fri May 23 09:35:23 2008 +0100 (2008-05-23)
parents 2e6a51378451
children f05795acfca9
files extras/mini-os/Config.mk extras/mini-os/Makefile extras/mini-os/arch/ia64/mm.c extras/mini-os/include/lib.h extras/mini-os/include/mm.h extras/mini-os/include/x86/arch_mm.h extras/mini-os/lib/sys.c tools/libxc/Makefile tools/libxc/xc_core.c tools/libxc/xc_minios.c xen/common/libelf/libelf-private.h
line diff
     1.1 --- a/extras/mini-os/Config.mk	Thu May 22 15:11:06 2008 +0100
     1.2 +++ b/extras/mini-os/Config.mk	Fri May 23 09:35:23 2008 +0100
     1.3 @@ -41,10 +41,7 @@ include $(MINI-OS_ROOT)/$(TARGET_ARCH_DI
     1.4  extra_incl := $(foreach dir,$(EXTRA_INC),-I$(MINI-OS_ROOT)/include/$(dir))
     1.5  
     1.6  DEF_CPPFLAGS += -I$(MINI-OS_ROOT)/include
     1.7 -
     1.8 -ifeq ($(stubdom),y)
     1.9 -DEF_CPPFLAGS += -DCONFIG_STUBDOM
    1.10 -endif
    1.11 +DEF_CPPFLAGS += -D__MINIOS__
    1.12  
    1.13  ifeq ($(libc),y)
    1.14  DEF_CPPFLAGS += -DHAVE_LIBC
     2.1 --- a/extras/mini-os/Makefile	Thu May 22 15:11:06 2008 +0100
     2.2 +++ b/extras/mini-os/Makefile	Fri May 23 09:35:23 2008 +0100
     2.3 @@ -96,7 +96,7 @@ APP_LDLIBS +=
     2.4  endif
     2.5  
     2.6  ifeq ($(libc),y)
     2.7 -LDLIBS += -L$(XEN_ROOT)/stubdom/libxc -lxenctrl -lxenguest
     2.8 +APP_LDLIBS += -L$(XEN_ROOT)/stubdom/libxc -whole-archive -lxenguest -lxenctrl -no-whole-archive
     2.9  APP_LDLIBS += -lpci
    2.10  APP_LDLIBS += -lz
    2.11  LDLIBS += -lc
     3.1 --- a/extras/mini-os/arch/ia64/mm.c	Thu May 22 15:11:06 2008 +0100
     3.2 +++ b/extras/mini-os/arch/ia64/mm.c	Fri May 23 09:35:23 2008 +0100
     3.3 @@ -131,6 +131,14 @@ arch_init_demand_mapping_area(unsigned l
     3.4  }
     3.5  
     3.6  /* Helper function used in gnttab.c. */
     3.7 +void do_map_frames(unsigned long addr,
     3.8 +        unsigned long *f, unsigned long n, unsigned long stride,
     3.9 +	unsigned long increment, domid_t id, int may_fail, unsigned long prot)
    3.10 +{
    3.11 +	/* TODO */
    3.12 +	ASSERT(0);
    3.13 +}
    3.14 +
    3.15  void*
    3.16  map_frames_ex(unsigned long* frames, unsigned long n, unsigned long stride,
    3.17  	unsigned long increment, unsigned long alignment, domid_t id,
     4.1 --- a/extras/mini-os/include/lib.h	Thu May 22 15:11:06 2008 +0100
     4.2 +++ b/extras/mini-os/include/lib.h	Fri May 23 09:35:23 2008 +0100
     4.3 @@ -136,6 +136,7 @@ enum fd_type {
     4.4      FTYPE_CONSOLE,
     4.5      FTYPE_FILE,
     4.6      FTYPE_XENBUS,
     4.7 +    FTYPE_XC,
     4.8      FTYPE_EVTCHN,
     4.9      FTYPE_SOCKET,
    4.10      FTYPE_TAP,
     5.1 --- a/extras/mini-os/include/mm.h	Thu May 22 15:11:06 2008 +0100
     5.2 +++ b/extras/mini-os/include/mm.h	Fri May 23 09:35:23 2008 +0100
     5.3 @@ -67,6 +67,9 @@ void arch_init_p2m(unsigned long max_pfn
     5.4  void *map_frames_ex(unsigned long *f, unsigned long n, unsigned long stride,
     5.5  	unsigned long increment, unsigned long alignment, domid_t id,
     5.6  	int may_fail, unsigned long prot);
     5.7 +void do_map_frames(unsigned long addr,
     5.8 +        unsigned long *f, unsigned long n, unsigned long stride,
     5.9 +	unsigned long increment, domid_t id, int may_fail, unsigned long prot);
    5.10  #ifdef HAVE_LIBC
    5.11  extern unsigned long heap, brk, heap_mapped, heap_end;
    5.12  #endif
     6.1 --- a/extras/mini-os/include/x86/arch_mm.h	Thu May 22 15:11:06 2008 +0100
     6.2 +++ b/extras/mini-os/include/x86/arch_mm.h	Fri May 23 09:35:23 2008 +0100
     6.3 @@ -219,11 +219,6 @@ static __inline__ paddr_t machine_to_phy
     6.4  
     6.5  #define map_frames(f, n) map_frames_ex(f, n, 1, 0, 1, DOMID_SELF, 0, L1_PROT)
     6.6  #define map_zero(n, a) map_frames_ex(&mfn_zero, n, 0, 0, a, DOMID_SELF, 0, L1_PROT_RO)
     6.7 -#ifndef __ASSEMBLY__
     6.8 -void do_map_frames(unsigned long addr,
     6.9 -        unsigned long *f, unsigned long n, unsigned long stride,
    6.10 -	unsigned long increment, domid_t id, int may_fail, unsigned long prot);
    6.11 -#endif
    6.12  #define do_map_zero(start, n) do_map_frames(start, &mfn_zero, n, 0, 0, DOMID_SELF, 0, L1_PROT_RO)
    6.13  
    6.14  #endif /* _ARCH_MM_H_ */
     7.1 --- a/extras/mini-os/lib/sys.c	Thu May 22 15:11:06 2008 +0100
     7.2 +++ b/extras/mini-os/lib/sys.c	Fri May 23 09:35:23 2008 +0100
     7.3 @@ -81,6 +81,7 @@
     7.4  
     7.5  #define NOFILE 32
     7.6  extern int xc_evtchn_close(int fd);
     7.7 +extern int xc_interface_close(int fd);
     7.8  
     7.9  pthread_mutex_t fd_lock = PTHREAD_MUTEX_INITIALIZER;
    7.10  struct file files[NOFILE] = {
    7.11 @@ -259,10 +260,7 @@ int read(int fd, void *buf, size_t nbyte
    7.12  	    }
    7.13  	    return ret * sizeof(union xenfb_in_event);
    7.14          }
    7.15 -	case FTYPE_NONE:
    7.16 -	case FTYPE_XENBUS:
    7.17 -	case FTYPE_EVTCHN:
    7.18 -	case FTYPE_BLK:
    7.19 +	default:
    7.20  	    break;
    7.21      }
    7.22      printk("read(%d): Bad descriptor\n", fd);
    7.23 @@ -295,12 +293,7 @@ int write(int fd, const void *buf, size_
    7.24  	case FTYPE_TAP:
    7.25  	    netfront_xmit(files[fd].tap.dev, (void*) buf, nbytes);
    7.26  	    return nbytes;
    7.27 -	case FTYPE_NONE:
    7.28 -	case FTYPE_XENBUS:
    7.29 -	case FTYPE_EVTCHN:
    7.30 -	case FTYPE_BLK:
    7.31 -	case FTYPE_KBD:
    7.32 -	case FTYPE_FB:
    7.33 +	default:
    7.34  	    break;
    7.35      }
    7.36      printk("write(%d): Bad descriptor\n", fd);
    7.37 @@ -351,15 +344,7 @@ int fsync(int fd) {
    7.38  	    }
    7.39  	    return 0;
    7.40  	}
    7.41 -	case FTYPE_NONE:
    7.42 -	case FTYPE_CONSOLE:
    7.43 -	case FTYPE_SOCKET:
    7.44 -	case FTYPE_XENBUS:
    7.45 -	case FTYPE_EVTCHN:
    7.46 -	case FTYPE_TAP:
    7.47 -	case FTYPE_BLK:
    7.48 -	case FTYPE_KBD:
    7.49 -	case FTYPE_FB:
    7.50 +	default:
    7.51  	    break;
    7.52      }
    7.53      printk("fsync(%d): Bad descriptor\n", fd);
    7.54 @@ -391,6 +376,9 @@ int close(int fd)
    7.55  	    files[fd].type = FTYPE_NONE;
    7.56  	    return res;
    7.57  	}
    7.58 +	case FTYPE_XC:
    7.59 +	    xc_interface_close(fd);
    7.60 +	    return 0;
    7.61  	case FTYPE_EVTCHN:
    7.62              xc_evtchn_close(fd);
    7.63              return 0;
    7.64 @@ -495,13 +483,7 @@ int fstat(int fd, struct stat *buf)
    7.65  	    stat_from_fs(buf, &stat);
    7.66  	    return 0;
    7.67  	}
    7.68 -	case FTYPE_NONE:
    7.69 -	case FTYPE_XENBUS:
    7.70 -	case FTYPE_EVTCHN:
    7.71 -	case FTYPE_TAP:
    7.72 -	case FTYPE_BLK:
    7.73 -	case FTYPE_KBD:
    7.74 -	case FTYPE_FB:
    7.75 +	default:
    7.76  	    break;
    7.77      }
    7.78  
    7.79 @@ -522,15 +504,7 @@ int ftruncate(int fd, off_t length)
    7.80  	    }
    7.81  	    return 0;
    7.82  	}
    7.83 -	case FTYPE_NONE:
    7.84 -	case FTYPE_CONSOLE:
    7.85 -	case FTYPE_SOCKET:
    7.86 -	case FTYPE_XENBUS:
    7.87 -	case FTYPE_EVTCHN:
    7.88 -	case FTYPE_TAP:
    7.89 -	case FTYPE_BLK:
    7.90 -	case FTYPE_KBD:
    7.91 -	case FTYPE_FB:
    7.92 +	default:
    7.93  	    break;
    7.94      }
    7.95  
    7.96 @@ -636,9 +610,10 @@ static const char file_types[] = {
    7.97      [FTYPE_NONE]	= 'N',
    7.98      [FTYPE_CONSOLE]	= 'C',
    7.99      [FTYPE_FILE]	= 'F',
   7.100 -    [FTYPE_XENBUS]	= 'X',
   7.101 +    [FTYPE_XENBUS]	= 'S',
   7.102 +    [FTYPE_XC]		= 'X',
   7.103      [FTYPE_EVTCHN]	= 'E',
   7.104 -    [FTYPE_SOCKET]	= 'S',
   7.105 +    [FTYPE_SOCKET]	= 's',
   7.106      [FTYPE_TAP]		= 'T',
   7.107      [FTYPE_BLK]		= 'B',
   7.108      [FTYPE_KBD]		= 'K',
   7.109 @@ -722,7 +697,7 @@ static int select_poll(int nfds, fd_set 
   7.110      /* Then see others as well. */
   7.111      for (i = 0; i < nfds; i++) {
   7.112  	switch(files[i].type) {
   7.113 -	case FTYPE_NONE:
   7.114 +	default:
   7.115  	    if (FD_ISSET(i, readfds) || FD_ISSET(i, writefds) || FD_ISSET(i, exceptfds))
   7.116  		printk("bogus fd %d in select\n", i);
   7.117  	    /* Fallthrough.  */
   7.118 @@ -1083,14 +1058,20 @@ int clock_gettime(clockid_t clk_id, stru
   7.119  
   7.120  void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
   7.121  {
   7.122 +    unsigned long n = (length + PAGE_SIZE - 1) / PAGE_SIZE;
   7.123 +
   7.124      ASSERT(!start);
   7.125 -    length = (length + PAGE_SIZE - 1) & PAGE_MASK;
   7.126      ASSERT(prot == (PROT_READ|PROT_WRITE));
   7.127 -    ASSERT(flags == (MAP_SHARED|MAP_ANON) || flags == (MAP_PRIVATE|MAP_ANON));
   7.128 -    ASSERT(fd == -1);
   7.129 +    ASSERT((fd == -1 && (flags == (MAP_SHARED|MAP_ANON) || flags == (MAP_PRIVATE|MAP_ANON)))
   7.130 +        || (fd != -1 && flags == MAP_SHARED));
   7.131      ASSERT(offset == 0);
   7.132  
   7.133 -    return map_zero(length / PAGE_SIZE, 1);
   7.134 +    if (fd == -1)
   7.135 +        return map_zero(n, 1);
   7.136 +    else if (files[fd].type == FTYPE_XC) {
   7.137 +        unsigned long zero = 0;
   7.138 +        return map_frames_ex(&zero, n, 0, 0, 1, DOMID_SELF, 0, 0);
   7.139 +    } else ASSERT(0);
   7.140  }
   7.141  #if defined(__x86_64__) || defined(__ia64__)
   7.142  __typeof__(mmap) mmap64 __attribute__((__alias__("mmap")));
   7.143 @@ -1110,7 +1091,7 @@ int munmap(void *start, size_t length)
   7.144  	call[i].args[0] = (unsigned long) &data[i];
   7.145  	call[i].args[1] = 0;
   7.146  	call[i].args[2] = 0;
   7.147 -	call[i].args[3] = UVMF_INVLPG | UVMF_ALL;
   7.148 +	call[i].args[3] = UVMF_INVLPG;
   7.149      }
   7.150  
   7.151      ret = HYPERVISOR_multicall(call, n);
     8.1 --- a/tools/libxc/Makefile	Thu May 22 15:11:06 2008 +0100
     8.2 +++ b/tools/libxc/Makefile	Fri May 23 09:35:23 2008 +0100
     8.3 @@ -5,11 +5,9 @@ MAJOR    = 3.2
     8.4  MINOR    = 0
     8.5  
     8.6  CTRL_SRCS-y       :=
     8.7 -ifneq ($(stubdom),y)
     8.8  CTRL_SRCS-y       += xc_core.c
     8.9  CTRL_SRCS-$(CONFIG_X86) += xc_core_x86.c
    8.10  CTRL_SRCS-$(CONFIG_IA64) += xc_core_ia64.c
    8.11 -endif
    8.12  CTRL_SRCS-y       += xc_domain.c
    8.13  CTRL_SRCS-y       += xc_evtchn.c
    8.14  CTRL_SRCS-y       += xc_misc.c
    8.15 @@ -21,9 +19,7 @@ CTRL_SRCS-y       += xc_sedf.c
    8.16  CTRL_SRCS-y       += xc_csched.c
    8.17  CTRL_SRCS-y       += xc_tbuf.c
    8.18  CTRL_SRCS-y       += xc_pm.c
    8.19 -ifneq ($(stubdom),y)
    8.20  CTRL_SRCS-y       += xc_resume.c
    8.21 -endif
    8.22  CTRL_SRCS-$(CONFIG_X86) += xc_pagetab.c
    8.23  CTRL_SRCS-$(CONFIG_Linux) += xc_linux.c
    8.24  CTRL_SRCS-$(CONFIG_SunOS) += xc_solaris.c
    8.25 @@ -33,15 +29,12 @@ CTRL_SRCS-$(CONFIG_MiniOS) += xc_minios.
    8.26  
    8.27  GUEST_SRCS-y :=
    8.28  GUEST_SRCS-y += xg_private.c
    8.29 -ifneq ($(stubdom),y)
    8.30  GUEST_SRCS-$(CONFIG_MIGRATE) += xc_domain_restore.c xc_domain_save.c
    8.31  GUEST_SRCS-$(CONFIG_HVM) += xc_hvm_build.c
    8.32 -endif
    8.33  
    8.34  VPATH = ../../xen/common/libelf
    8.35  CFLAGS += -I../../xen/common/libelf
    8.36  
    8.37 -ifneq ($(stubdom),y)
    8.38  GUEST_SRCS-y += libelf-tools.c libelf-loader.c
    8.39  GUEST_SRCS-y += libelf-dominfo.c libelf-relocate.c
    8.40  
    8.41 @@ -55,7 +48,6 @@ GUEST_SRCS-y                 += xc_dom_c
    8.42  GUEST_SRCS-$(CONFIG_X86)     += xc_dom_x86.c
    8.43  GUEST_SRCS-$(CONFIG_X86)     += xc_cpuid_x86.c
    8.44  GUEST_SRCS-$(CONFIG_IA64)    += xc_dom_ia64.c
    8.45 -endif
    8.46  
    8.47  -include $(XEN_TARGET_ARCH)/Makefile
    8.48  
     9.1 --- a/tools/libxc/xc_core.c	Thu May 22 15:11:06 2008 +0100
     9.2 +++ b/tools/libxc/xc_core.c	Fri May 23 09:35:23 2008 +0100
     9.3 @@ -64,7 +64,7 @@
     9.4  /* string table */
     9.5  struct xc_core_strtab {
     9.6      char       *strings;
     9.7 -    uint16_t    current;
     9.8 +    uint16_t    length;
     9.9      uint16_t    max;
    9.10  };
    9.11  
    9.12 @@ -89,7 +89,7 @@ xc_core_strtab_init(void)
    9.13  
    9.14      /* index 0 represents none */
    9.15      strtab->strings[0] = '\0';
    9.16 -    strtab->current = 1;
    9.17 +    strtab->length = 1;
    9.18  
    9.19      return strtab;
    9.20  }
    9.21 @@ -107,14 +107,14 @@ xc_core_strtab_get(struct xc_core_strtab
    9.22      uint16_t ret = 0;
    9.23      uint16_t len = strlen(name) + 1;
    9.24  
    9.25 -    if ( strtab->current > UINT16_MAX - len )
    9.26 +    if ( strtab->length > UINT16_MAX - len )
    9.27      {
    9.28          PERROR("too long string table");
    9.29          errno = E2BIG;
    9.30          return ret;
    9.31      }
    9.32      
    9.33 -    if ( strtab->current + len > strtab->max )
    9.34 +    if ( strtab->length + len > strtab->max )
    9.35      {
    9.36          char *tmp;
    9.37          if ( strtab->max > UINT16_MAX / 2 )
    9.38 @@ -135,9 +135,9 @@ xc_core_strtab_get(struct xc_core_strtab
    9.39          strtab->max *= 2;
    9.40      }
    9.41  
    9.42 -    ret = strtab->current;
    9.43 -    strcpy(strtab->strings + strtab->current, name);
    9.44 -    strtab->current += len;
    9.45 +    ret = strtab->length;
    9.46 +    strcpy(strtab->strings + strtab->length, name);
    9.47 +    strtab->length += len;
    9.48      return ret;
    9.49  }
    9.50  
    9.51 @@ -669,7 +669,7 @@ xc_domain_dumpcore_via_callback(int xc_h
    9.52      offset += filesz;
    9.53  
    9.54      /* fixing up section header string table section header */
    9.55 -    filesz = strtab->current;
    9.56 +    filesz = strtab->length;
    9.57      sheaders->shdrs[strtab_idx].sh_offset = offset;
    9.58      sheaders->shdrs[strtab_idx].sh_size = filesz;
    9.59  
    9.60 @@ -829,7 +829,7 @@ copy_done:
    9.61          goto out;
    9.62  
    9.63      /* elf section header string table: .shstrtab */
    9.64 -    sts = dump_rtn(args, strtab->strings, strtab->current);
    9.65 +    sts = dump_rtn(args, strtab->strings, strtab->length);
    9.66      if ( sts != 0 )
    9.67          goto out;
    9.68  
    10.1 --- a/tools/libxc/xc_minios.c	Thu May 22 15:11:06 2008 +0100
    10.2 +++ b/tools/libxc/xc_minios.c	Fri May 23 09:35:23 2008 +0100
    10.3 @@ -35,11 +35,12 @@ extern struct wait_queue_head event_queu
    10.4  
    10.5  int xc_interface_open(void)
    10.6  {
    10.7 -    return 0;
    10.8 +    return alloc_fd(FTYPE_XC);
    10.9  }
   10.10  
   10.11  int xc_interface_close(int xc_handle)
   10.12  {
   10.13 +    files[xc_handle].type = FTYPE_NONE;
   10.14      return 0;
   10.15  }
   10.16  
   10.17 @@ -79,8 +80,12 @@ void *xc_map_foreign_range(int xc_handle
   10.18  int xc_map_foreign_ranges(int xc_handle, uint32_t dom,
   10.19                            privcmd_mmap_entry_t *entries, int nr)
   10.20  {
   10.21 -    printf("xc_map_foreign_ranges, TODO\n");
   10.22 -    do_exit();
   10.23 +    int i;
   10.24 +    for (i = 0; i < nr; i++) {
   10.25 +	unsigned long mfn = entries[i].mfn;
   10.26 +        do_map_frames(entries[i].va, &mfn, entries[i].npages, 0, 1, dom, 0, L1_PROT);
   10.27 +    }
   10.28 +    return 0;
   10.29  }
   10.30  
   10.31  int do_xen_hypercall(int xc_handle, privcmd_hypercall_t *hypercall)
   10.32 @@ -294,6 +299,12 @@ int xc_evtchn_unmask(int xce_handle, evt
   10.33      return 0;
   10.34  }
   10.35  
   10.36 +/* Optionally flush file to disk and discard page cache */
   10.37 +void discard_file_cache(int fd, int flush)
   10.38 +{
   10.39 +    if (flush)
   10.40 +        fsync(fd);
   10.41 +}
   10.42  /*
   10.43   * Local variables:
   10.44   * mode: C
    11.1 --- a/xen/common/libelf/libelf-private.h	Thu May 22 15:11:06 2008 +0100
    11.2 +++ b/xen/common/libelf/libelf-private.h	Fri May 23 09:35:23 2008 +0100
    11.3 @@ -43,7 +43,7 @@
    11.4  #define bswap_16(x) swap16(x)
    11.5  #define bswap_32(x) swap32(x)
    11.6  #define bswap_64(x) swap64(x)
    11.7 -#elif defined(__linux__) || defined(__Linux__)
    11.8 +#elif defined(__linux__) || defined(__Linux__) || defined(__MINIOS__)
    11.9  #include <byteswap.h>
   11.10  #else
   11.11  #error Unsupported OS