ia64/xen-unstable

changeset 260:d5a6350b99c8

bitkeeper revision 1.107 (3e665ab0XNZynD-498WHLN1g1IPRrw)

Merge labyrinth.cl.cam.ac.uk:/usr/groups/xeno/BK/xeno.bk
into labyrinth.cl.cam.ac.uk:/anfs/scratch/boulderdash/ach61/xeno/xeno.bk
author ach61@labyrinth.cl.cam.ac.uk
date Wed Mar 05 20:14:40 2003 +0000 (2003-03-05)
parents 3cc17656be66 9c04a98c7932
children 8d7cbb78020d
files .rootkeys BitKeeper/etc/ignore tools/balloon/Makefile tools/balloon/README tools/balloon/balloon.c tools/domain_builder/dom_builder.c xen/arch/i386/entry.S xen/common/dom_mem_ops.c xen/common/domain.c xen/common/keyhandler.c xen/common/memory.c xen/include/hypervisor-ifs/hypervisor-if.h xen/include/xeno/dom_mem_ops.h xen/include/xeno/sched.h xen/net/dev.c xenolinux-2.4.21-pre4-sparse/Makefile xenolinux-2.4.21-pre4-sparse/arch/xeno/Makefile xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/balloon/Makefile xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/balloon/balloon.c xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/balloon/dom_mem_ops.h xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/dom0/dom0_core.c xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/network/network.c xenolinux-2.4.21-pre4-sparse/include/asm-xeno/hypervisor.h xenolinux-2.4.21-pre4-sparse/include/asm-xeno/page.h
line diff
     1.1 --- a/.rootkeys	Wed Feb 26 19:17:32 2003 +0000
     1.2 +++ b/.rootkeys	Wed Mar 05 20:14:40 2003 +0000
     1.3 @@ -176,6 +176,9 @@ 3ddb79bbP31im-mx2NbfthSeqty1Dg old/xenol
     1.4  3e15d52e0_j129JPvo7xfYGndVFpwQ old/xenolinux-2.4.16-sparse/mm/memory.c
     1.5  3e15d535DLvpzTrLRUIerB69LpJD1g old/xenolinux-2.4.16-sparse/mm/mremap.c
     1.6  3e15d531m1Y1_W8ki64AFOU_ua4C4w old/xenolinux-2.4.16-sparse/mm/swapfile.c
     1.7 +3e6377b24eQqYMsDi9XrFkIgTzZ47A tools/balloon/Makefile
     1.8 +3e6377d6eiFjF1hHIS6JEIOFk62xSA tools/balloon/README
     1.9 +3e6377dbGcgnisKw16DPCaND7oGO3Q tools/balloon/balloon.c
    1.10  3e4d00468-FN2VDeEHo96zxrMHK_mA tools/domain_builder/Makefile
    1.11  3e4d0046SPau_y0sw2WLJz8QkqNoRA tools/domain_builder/README
    1.12  3e4d0046bbdH0GsI9J_1Eb4ZQHfIiQ tools/domain_builder/dom0_defs.h
    1.13 @@ -226,6 +229,7 @@ 3e397e66AyyD5fYraAySWuwi9uqSXg xen/commo
    1.14  3ddb79bddEYJbcURvqqcx99Yl2iAhQ xen/common/block.c
    1.15  3ddb79bdrqnW93GR9gZk1OJe1qK-iQ xen/common/brlock.c
    1.16  3ddb79bdLX_P6iB7ILiblRLWvebapg xen/common/dom0_ops.c
    1.17 +3e6377e4i0c9GtKN65e99OtRbw3AZw xen/common/dom_mem_ops.c
    1.18  3ddb79bdYO5D8Av12NHqPeSviav7cg xen/common/domain.c
    1.19  3e32af9aRnYGl4GMOaDKp7JdfhOGhg xen/common/domain_page.c
    1.20  3ddb79bdeyutmaXEfpQvvxj7eQ0fCw xen/common/event.c
    1.21 @@ -400,6 +404,7 @@ 3ddb79c259jh8hE7vre_8NuE7nwNSA xen/inclu
    1.22  3ddb79c1V44RD26YqCUm-kqIupM37A xen/include/xeno/ctype.h
    1.23  3ddb79c05DdHQ0UxX_jKsXdR4QlMCA xen/include/xeno/delay.h
    1.24  3ddb79c2PMeWTK86y4C3F4MzHw4A1g xen/include/xeno/dom0_ops.h
    1.25 +3e6377eaioRoNm0m_HSDEAd4Vqrq_w xen/include/xeno/dom_mem_ops.h
    1.26  3ddb79c1uaWQZj551j1O0B5z8AnHOg xen/include/xeno/elevator.h
    1.27  3ddb79c0HIghfBF8zFUdmXhOU8i6hA xen/include/xeno/errno.h
    1.28  3ddb79c0rMjudDKkJku_mkm0J-BZgw xen/include/xeno/etherdevice.h
    1.29 @@ -465,6 +470,9 @@ 3e5a4e65IEPjnWPZ5w3TxS5scV8Ewg xenolinux
    1.30  3e5a4e65n-KhsEAs-A4ULiStBp-r6w xenolinux-2.4.21-pre4-sparse/arch/xeno/boot/Makefile
    1.31  3e5a4e65OV_j_DBtjzt5vej771AJsA xenolinux-2.4.21-pre4-sparse/arch/xeno/config.in
    1.32  3e5a4e65TNEycLeXqPSXQJQm_xGecA xenolinux-2.4.21-pre4-sparse/arch/xeno/defconfig
    1.33 +3e6377f5xwPfYZkPHPrDbEq1PRN7uQ xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/balloon/Makefile
    1.34 +3e6377f8Me8IqtvEhb70XFgOvqQH7A xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/balloon/balloon.c
    1.35 +3e6377fbMjXWAQd0XN0FWv4fDEo6fg xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/balloon/dom_mem_ops.h
    1.36  3e5a4e65iHEuC5sjFhj42XALYbLVRw xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/block/Makefile
    1.37  3e5a4e65pP5spJErBW69pJxSSdK9RA xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/block/xl_block.c
    1.38  3e5a4e65GtI9JZRAjuRdXaxt_4ohyQ xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/block/xl_block_test.c
     2.1 --- a/BitKeeper/etc/ignore	Wed Feb 26 19:17:32 2003 +0000
     2.2 +++ b/BitKeeper/etc/ignore	Wed Mar 05 20:14:40 2003 +0000
     2.3 @@ -22,3 +22,134 @@ xenolinux-2.4.16-sparse/scripts/kconfig.
     2.4  xen-2.4.16/foo
     2.5  xen-2.4.16/common/domain.c.smh
     2.6  URK
     2.7 +tools/domain_builder/dom_builder.o
     2.8 +tools/domain_builder/dom_kill.o
     2.9 +tools/domain_builder/domain_builder
    2.10 +tools/domain_builder/kill_domain
    2.11 +xen/arch/i386/acpitable.o
    2.12 +xen/arch/i386/apic.o
    2.13 +xen/arch/i386/arch.o
    2.14 +xen/arch/i386/boot/boot.o
    2.15 +xen/arch/i386/delay.o
    2.16 +xen/arch/i386/entry.o
    2.17 +xen/arch/i386/extable.o
    2.18 +xen/arch/i386/i387.o
    2.19 +xen/arch/i386/i8259.o
    2.20 +xen/arch/i386/idle0_task.o
    2.21 +xen/arch/i386/io_apic.o
    2.22 +xen/arch/i386/ioremap.o
    2.23 +xen/arch/i386/irq.o
    2.24 +xen/arch/i386/mm.o
    2.25 +xen/arch/i386/mpparse.o
    2.26 +xen/arch/i386/pci-dma.o
    2.27 +xen/arch/i386/pci-i386.o
    2.28 +xen/arch/i386/pci-irq.o
    2.29 +xen/arch/i386/pci-pc.o
    2.30 +xen/arch/i386/process.o
    2.31 +xen/arch/i386/rwlock.o
    2.32 +xen/arch/i386/setup.o
    2.33 +xen/arch/i386/smp.o
    2.34 +xen/arch/i386/smpboot.o
    2.35 +xen/arch/i386/time.o
    2.36 +xen/arch/i386/trampoline.o
    2.37 +xen/arch/i386/traps.o
    2.38 +xen/arch/i386/usercopy.o
    2.39 +xen/common/ac_timer.o
    2.40 +xen/common/block.o
    2.41 +xen/common/brlock.o
    2.42 +xen/common/common.o
    2.43 +xen/common/dom0_ops.o
    2.44 +xen/common/domain.o
    2.45 +xen/common/domain_page.o
    2.46 +xen/common/event.o
    2.47 +xen/common/kernel.o
    2.48 +xen/common/keyhandler.o
    2.49 +xen/common/lib.o
    2.50 +xen/common/memory.o
    2.51 +xen/common/network.o
    2.52 +xen/common/page_alloc.o
    2.53 +xen/common/perfc.o
    2.54 +xen/common/resource.o
    2.55 +xen/common/schedule.o
    2.56 +xen/common/slab.o
    2.57 +xen/common/softirq.o
    2.58 +xen/common/timer.o
    2.59 +xen/common/vsprintf.o
    2.60 +xen/drivers/block/blkpg.o
    2.61 +xen/drivers/block/driver.o
    2.62 +xen/drivers/block/elevator.o
    2.63 +xen/drivers/block/genhd.o
    2.64 +xen/drivers/block/ll_rw_blk.o
    2.65 +xen/drivers/block/xen_block.o
    2.66 +xen/drivers/char/driver.o
    2.67 +xen/drivers/char/xen_kbd.o
    2.68 +xen/drivers/char/xen_serial.o
    2.69 +xen/drivers/ide/driver.o
    2.70 +xen/drivers/ide/ide-disk.o
    2.71 +xen/drivers/ide/ide-dma.o
    2.72 +xen/drivers/ide/ide-features.o
    2.73 +xen/drivers/ide/ide-geometry.o
    2.74 +xen/drivers/ide/ide-pci.o
    2.75 +xen/drivers/ide/ide-probe.o
    2.76 +xen/drivers/ide/ide-taskfile.o
    2.77 +xen/drivers/ide/ide-xeno.o
    2.78 +xen/drivers/ide/ide.o
    2.79 +xen/drivers/ide/piix.o
    2.80 +xen/drivers/net/3c59x.o
    2.81 +xen/drivers/net/Space.o
    2.82 +xen/drivers/net/driver.o
    2.83 +xen/drivers/net/e1000/e1000.o
    2.84 +xen/drivers/net/e1000/e1000_ethtool.o
    2.85 +xen/drivers/net/e1000/e1000_hw.o
    2.86 +xen/drivers/net/e1000/e1000_main.o
    2.87 +xen/drivers/net/e1000/e1000_param.o
    2.88 +xen/drivers/net/ne/8390.o
    2.89 +xen/drivers/net/ne/ne.o
    2.90 +xen/drivers/net/ne/ne_drv.o
    2.91 +xen/drivers/net/net_init.o
    2.92 +xen/drivers/net/setup.o
    2.93 +xen/drivers/net/tg3.o
    2.94 +xen/drivers/pci/classlist.h
    2.95 +xen/drivers/pci/compat.o
    2.96 +xen/drivers/pci/devlist.h
    2.97 +xen/drivers/pci/driver.o
    2.98 +xen/drivers/pci/gen-devlist
    2.99 +xen/drivers/pci/names.o
   2.100 +xen/drivers/pci/pci.o
   2.101 +xen/drivers/pci/quirks.o
   2.102 +xen/drivers/pci/setup-res.o
   2.103 +xen/drivers/scsi/aacraid/aachba.o
   2.104 +xen/drivers/scsi/aacraid/aacraid.o
   2.105 +xen/drivers/scsi/aacraid/commctrl.o
   2.106 +xen/drivers/scsi/aacraid/comminit.o
   2.107 +xen/drivers/scsi/aacraid/commsup.o
   2.108 +xen/drivers/scsi/aacraid/dpcsup.o
   2.109 +xen/drivers/scsi/aacraid/linit.o
   2.110 +xen/drivers/scsi/aacraid/rx.o
   2.111 +xen/drivers/scsi/aacraid/sa.o
   2.112 +xen/drivers/scsi/constants.o
   2.113 +xen/drivers/scsi/driver.o
   2.114 +xen/drivers/scsi/hosts.o
   2.115 +xen/drivers/scsi/scsi.o
   2.116 +xen/drivers/scsi/scsi_dma.o
   2.117 +xen/drivers/scsi/scsi_error.o
   2.118 +xen/drivers/scsi/scsi_ioctl.o
   2.119 +xen/drivers/scsi/scsi_lib.o
   2.120 +xen/drivers/scsi/scsi_merge.o
   2.121 +xen/drivers/scsi/scsi_proc.o
   2.122 +xen/drivers/scsi/scsi_queue.o
   2.123 +xen/drivers/scsi/scsi_scan.o
   2.124 +xen/drivers/scsi/scsi_syms.o
   2.125 +xen/drivers/scsi/scsicam.o
   2.126 +xen/drivers/scsi/sd.o
   2.127 +xen/image
   2.128 +xen/image.gz
   2.129 +xen/include/asm
   2.130 +xen/include/linux
   2.131 +xen/net/dev.o
   2.132 +xen/net/dev_mcast.o
   2.133 +xen/net/devinit.o
   2.134 +xen/net/eth.o
   2.135 +xen/net/network.o
   2.136 +xen/net/skbuff.o
   2.137 +xen/tools/elf-reloc
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/balloon/Makefile	Wed Mar 05 20:14:40 2003 +0000
     3.3 @@ -0,0 +1,9 @@
     3.4 +CC = gcc
     3.5 +TARGET=balloon
     3.6 +
     3.7 +TARGET: balloon.c
     3.8 +	$(CC) -O2 -Wall -o $(TARGET) balloon.c
     3.9 +
    3.10 +clean:
    3.11 +	$(RM) *.o $(TARGET) *~
    3.12 +
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tools/balloon/README	Wed Mar 05 20:14:40 2003 +0000
     4.3 @@ -0,0 +1,17 @@
     4.4 +Xeno Balloon driver supports two operations:
     4.5 +
     4.6 +1. Inflating - which means domain giving up pages of mem to xen.
     4.7 +2. Deflating - which means reclaiming memory pages from xen.
     4.8 +
     4.9 +Currently, domain can only claim pages from xen up to the number of 
    4.10 +previously released ones. This is to change. 
    4.11 +
    4.12 +Example:
    4.13 +
    4.14 +# balloon inflate 1000
    4.15 +
    4.16 +Give up 1000 pages to xen.
    4.17 +
    4.18 +# balloon deflate 1000
    4.19 +
    4.20 +Claim 1000 pages from xen.
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/balloon/balloon.c	Wed Mar 05 20:14:40 2003 +0000
     5.3 @@ -0,0 +1,114 @@
     5.4 +/******************************************************************************
     5.5 + * balloon.c
     5.6 + *
     5.7 + * Xeno balloon driver userspace control tool. Used to shrink/grow domain's 
     5.8 + * memory.
     5.9 + *
    5.10 + * Copyright (c) 2003, B Dragovic
    5.11 + */
    5.12 +
    5.13 +#include <stdio.h>
    5.14 +#include <stdlib.h>
    5.15 +#include <string.h>
    5.16 +#include <errno.h>
    5.17 +#include <unistd.h>
    5.18 +#include <sys/types.h>
    5.19 +#include <sys/stat.h>
    5.20 +#include <fcntl.h>
    5.21 +
    5.22 +#define INFLATE_BALLOON      "inflate"   /* return mem to hypervisor */
    5.23 +#define DEFLATE_BALLOON      "deflate"   /* claim mem from hypervisor */
    5.24 +
    5.25 +/* THIS IS TAKEN FROM XENOLINUX BALLOON DRIVER */
    5.26 +#define USER_INFLATE_BALLOON  1   /* return mem to hypervisor */
    5.27 +#define USER_DEFLATE_BALLOON  2   /* claim mem from hypervisor */
    5.28 +typedef struct user_balloon_op {
    5.29 +    unsigned int    op;
    5.30 +    unsigned long   size;
    5.31 +} user_balloon_op_t;
    5.32 +/* END OF CODE TAKEN FROM XENOLINUX BALLOON DRIVER */
    5.33 +
    5.34 +
    5.35 +static int open_balloon_proc()
    5.36 +{
    5.37 +    return open("/proc/xeno/balloon", O_RDWR);
    5.38 +}
    5.39 +
    5.40 +/* inflate balloon function signals to kernel it should relinquish memory */
    5.41 +static int inflate_balloon(unsigned long num_pages)
    5.42 +{
    5.43 +    user_balloon_op_t bop;
    5.44 +    int proc_fd;
    5.45 +
    5.46 +    if((proc_fd = open_balloon_proc()) <= 0){
    5.47 +        printf("Error opening balloon proc file.\n");
    5.48 +        return 0;
    5.49 +    }
    5.50 +
    5.51 +    bop.op   = USER_INFLATE_BALLOON;
    5.52 +    bop.size = num_pages;
    5.53 +    if ( write(proc_fd, &bop, sizeof(bop)) <= 0 )
    5.54 +    {
    5.55 +        printf("Error writing to balloon proc file.\n");
    5.56 +        return 0;
    5.57 +    }
    5.58 +
    5.59 +    close(proc_fd);
    5.60 +    return 1;
    5.61 +}
    5.62 +
    5.63 +/* deflate balloon function signals to kernel it should claim memory */
    5.64 +static int deflate_balloon(unsigned long num_pages)
    5.65 +{
    5.66 +    user_balloon_op_t bop;
    5.67 +    int proc_fd;
    5.68 +
    5.69 +    if((proc_fd = open_balloon_proc()) <= 0){
    5.70 +        printf("Error opening balloon proc file.\n");
    5.71 +        return 0;
    5.72 +    }
    5.73 +
    5.74 +    bop.op   = USER_DEFLATE_BALLOON;
    5.75 +    bop.size = num_pages;
    5.76 +    if(write(proc_fd, &bop, sizeof(bop)) <= 0){
    5.77 +        printf("Error writing to balloon proc file.\n");
    5.78 +        return 0;
    5.79 +    }
    5.80 +
    5.81 +    close(proc_fd);
    5.82 +    return 1;
    5.83 +}
    5.84 +
    5.85 +int main(int argc, char *argv[])
    5.86 +{
    5.87 +    unsigned long num_pages;
    5.88 +
    5.89 +    if(argc < 2){
    5.90 +        printf("Usage: balloon <inflate|deflate> <num_pages>\n");
    5.91 +        return -1;
    5.92 +    }
    5.93 +
    5.94 +    num_pages = atol(argv[2]);
    5.95 +
    5.96 +    if(!strcmp(argv[1], INFLATE_BALLOON)){
    5.97 +        if(!inflate_balloon(num_pages)){
    5.98 +            perror("Inflating balloon failed");
    5.99 +            return -1;
   5.100 +        }
   5.101 +
   5.102 +    } else if (!strcmp(argv[1], DEFLATE_BALLOON)){
   5.103 +        if(!deflate_balloon(num_pages)){
   5.104 +            perror("Deflating balloon failed");
   5.105 +            return -1;
   5.106 +        }
   5.107 +
   5.108 +    } else {
   5.109 +        printf("Unrecognized command line argument.\n");
   5.110 +        return -1;
   5.111 +    }
   5.112 +
   5.113 +    return 0;
   5.114 +}
   5.115 +
   5.116 +    
   5.117 +
     6.1 --- a/tools/domain_builder/dom_builder.c	Wed Feb 26 19:17:32 2003 +0000
     6.2 +++ b/tools/domain_builder/dom_builder.c	Wed Mar 05 20:14:40 2003 +0000
     6.3 @@ -52,10 +52,10 @@ static void dom_mem_cleanup(dom_mem_t * 
     6.4      if(mem_fd < 0){
     6.5          perror(PERR_STRING);
     6.6      }
     6.7 -
     6.8 -	if(write(mem_fd, (dom_mem_t *)dom_mem, sizeof(dom_mem_t)) < 0){
     6.9 -		dbstatus("Error unmapping domain's memory.\n");
    6.10 -	}
    6.11 +    
    6.12 +    if(write(mem_fd, (dom_mem_t *)dom_mem, sizeof(dom_mem_t)) < 0){
    6.13 +	dbstatus("Error unmapping domain's memory.\n");
    6.14 +    }
    6.15  
    6.16      close(mem_fd);
    6.17  }
    6.18 @@ -163,7 +163,7 @@ static dom0_newdomain_t * create_new_dom
    6.19      close(id_fd);
    6.20      
    6.21      sprintf(cmd_path, "Reserved %ld kbytes memory and assigned id %d to the"
    6.22 -                    "new domain.", req_mem, dom_data->domain);
    6.23 +	    " new domain.", req_mem, dom_data->domain);
    6.24      dbstatus(cmd_path);
    6.25  
    6.26      return dom_data;
    6.27 @@ -386,6 +386,7 @@ static int launch_domain(dom_meminfo_t  
    6.28      dbstatus("Launched the new domain!");
    6.29  
    6.30      close(cmd_fd);
    6.31 +    return 0;
    6.32  }
    6.33  
    6.34  int main(int argc, char **argv)
    6.35 @@ -401,51 +402,45 @@ int main(int argc, char **argv)
    6.36      int kernel_fd;
    6.37      int count;
    6.38      int cmd_len;
    6.39 -    int ret = 0;
    6.40 +    int rc = -1;
    6.41  
    6.42 -	unsigned long addr;
    6.43 +    unsigned long addr;
    6.44  
    6.45 -    if(argc < 4){
    6.46 +    if(argc < 4) {
    6.47          dberr("Usage: dom_builder <kbytes_mem> <image> <num_vifs> "
    6.48 -                        "<boot_params>\n");
    6.49 -        ret = -1;
    6.50 +	      "<boot_params>\n");
    6.51          goto out;
    6.52      }
    6.53  
    6.54      /* create new domain and set up all the neccessary mappings */
    6.55  
    6.56      kernel_fd = do_kernel_chcks(argv[2], atol(argv[1]), &load_addr, &ksize);
    6.57 -    if(kernel_fd < 0){
    6.58 -        ret = -1;
    6.59 +    if(kernel_fd < 0) {
    6.60 +	rc = errno; 
    6.61          goto out;
    6.62      }
    6.63 -
    6.64 +    
    6.65      /* request the creation of new domain */
    6.66 -    dom_data = create_new_domain(atol(argv[1]));
    6.67 -    if(dom_data == 0){
    6.68 -        ret = -1;
    6.69 +    if(!(dom_data = create_new_domain(atol(argv[1])))) 
    6.70          goto out;
    6.71 -    }
    6.72  
    6.73      /* map domain's memory */
    6.74 -    if(map_dom_mem(dom_data->pg_head, dom_data->memory_kb >> (PAGE_SHIFT - 10), 
    6.75 -        dom_data->domain, &dom_os_image)){
    6.76 -        ret = -1;
    6.77 +    if(map_dom_mem(dom_data->pg_head, dom_data->memory_kb >> (PAGE_SHIFT-10), 
    6.78 +		   dom_data->domain, &dom_os_image))
    6.79          goto out;
    6.80 -    }
    6.81  
    6.82      /* the following code does the actual domain building */
    6.83 -    meminfo = setup_guestos(dom_data->domain, kernel_fd, load_addr, ksize, 
    6.84 -        &dom_os_image);
    6.85 -    if(meminfo == NULL){
    6.86 -		printf("Domain Builder: debug: meminfo NULL\n");
    6.87 -        ret = -1;
    6.88 -        dom_mem_cleanup(&dom_os_image);
    6.89 +    meminfo = setup_guestos(dom_data->domain, kernel_fd, load_addr, 
    6.90 +			    ksize, &dom_os_image); 
    6.91 +    
    6.92 +    /* and unmap the new domain's memory image since we no longer need it */
    6.93 +    dom_mem_cleanup(&dom_os_image);
    6.94 +
    6.95 +    if(!meminfo) { 
    6.96 +	printf("Domain Builder: debug: meminfo NULL\n");
    6.97          goto out;
    6.98      }
    6.99  
   6.100 -    dom_mem_cleanup(&dom_os_image);
   6.101 -
   6.102      meminfo->virt_load_addr = load_addr;
   6.103      meminfo->num_vifs = atoi(argv[3]);
   6.104      meminfo->cmd_line[0] = '\0';
   6.105 @@ -471,13 +466,11 @@ int main(int argc, char **argv)
   6.106      dbstatus(status);
   6.107      
   6.108      /* and launch the domain */
   6.109 -    if(launch_domain(meminfo) != 0)
   6.110 -	ret = -1;
   6.111 -
   6.112 +    rc = launch_domain(meminfo); 
   6.113      
   6.114  out:
   6.115 -    if( ret >= 0 )
   6.116 +    if( rc >= 0 )
   6.117         return meminfo->domain;
   6.118      else 
   6.119 -       return ret;
   6.120 +       return rc;
   6.121  }
     7.1 --- a/xen/arch/i386/entry.S	Wed Feb 26 19:17:32 2003 +0000
     7.2 +++ b/xen/arch/i386/entry.S	Wed Mar 05 20:14:40 2003 +0000
     7.3 @@ -529,6 +529,7 @@ ENTRY(hypervisor_call_table)
     7.4          .long SYMBOL_NAME(do_get_debugreg)
     7.5          .long SYMBOL_NAME(do_update_descriptor)
     7.6          .long SYMBOL_NAME(do_set_fast_trap)
     7.7 +        .long SYMBOL_NAME(do_dom_mem_op)
     7.8          .rept NR_syscalls-(.-hypervisor_call_table)/4
     7.9          .long SYMBOL_NAME(sys_ni_syscall)
    7.10  	.endr
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/xen/common/dom_mem_ops.c	Wed Mar 05 20:14:40 2003 +0000
     8.3 @@ -0,0 +1,144 @@
     8.4 +/******************************************************************************
     8.5 + * dom_mem_ops.c
     8.6 + *
     8.7 + * Code to handle memory related requests from domains eg. balloon driver.
     8.8 + *
     8.9 + * Copyright (c) 2003, B Dragovic
    8.10 + */
    8.11 +
    8.12 +#include <xeno/config.h>
    8.13 +#include <xeno/types.h>
    8.14 +#include <xeno/lib.h>
    8.15 +#include <xeno/dom_mem_ops.h>
    8.16 +#include <xeno/sched.h>
    8.17 +#include <xeno/event.h>
    8.18 +#include <asm/domain_page.h>
    8.19 +
    8.20 +#if 1
    8.21 +#define DPRINTK(_f, _a...) printk( _f , ## _a )
    8.22 +#else
    8.23 +#define DPRINTK(_f, _a...) ((void)0)
    8.24 +#endif
    8.25 +
    8.26 +static long alloc_dom_mem(struct task_struct *p, balloon_def_op_t bop)
    8.27 +{
    8.28 +    struct list_head *temp;
    8.29 +    struct pfn_info  *pf;     /* pfn_info of current page */
    8.30 +    unsigned long     mpfn;   /* machine frame number of current page */
    8.31 +    void             *va;     /* Xen-usable mapping of current page */
    8.32 +    unsigned long     i;
    8.33 +    unsigned long     flags;
    8.34 +
    8.35 +    /* POLICY DECISION: Each domain has a page limit. */
    8.36 +    if( (p->tot_pages + bop.size) > p->max_pages )
    8.37 +        return -ENOMEM;
    8.38 +
    8.39 +    if ( free_pfns < bop.size ) 
    8.40 +        return -ENOMEM;
    8.41 +    
    8.42 +    spin_lock_irqsave(&free_list_lock, flags);
    8.43 +    
    8.44 +    temp = free_list.next;
    8.45 +    for ( i = 0; i < bop.size; i++ )
    8.46 +    {
    8.47 +        /* Get a free page and add it to the domain's page list. */
    8.48 +        pf = list_entry(temp, struct pfn_info, list);
    8.49 +        pf->flags |= p->domain;
    8.50 +        pf->type_count = pf->tot_count = 0;
    8.51 +        temp = temp->next;
    8.52 +        list_del(&pf->list);
    8.53 +        list_add_tail(&pf->list, &p->pg_head);
    8.54 +        free_pfns--;
    8.55 +
    8.56 +        p->tot_pages++;
    8.57 +
    8.58 +        /* Inform the domain of the new page's machine address. */ 
    8.59 +        mpfn = (unsigned long)(pf - frame_table);
    8.60 +        copy_to_user(bop.pages, &mpfn, sizeof(mpfn));
    8.61 +        bop.pages++; 
    8.62 +
    8.63 +        /* Zero out the page to prevent information leakage. */
    8.64 +        va = map_domain_mem(mpfn << PAGE_SHIFT);
    8.65 +        memset(va, 0, PAGE_SIZE);
    8.66 +        unmap_domain_mem(va);
    8.67 +    }
    8.68 +
    8.69 +    spin_unlock_irqrestore(&free_list_lock, flags);
    8.70 +    
    8.71 +    return bop.size;
    8.72 +}
    8.73 +    
    8.74 +static long free_dom_mem(struct task_struct *p, balloon_inf_op_t bop)
    8.75 +{
    8.76 +    struct list_head *temp;
    8.77 +    struct pfn_info  *pf;     /* pfn_info of current page */
    8.78 +    unsigned long     mpfn;   /* machine frame number of current page */
    8.79 +    unsigned long     i;
    8.80 +    unsigned long     flags;
    8.81 +    long              rc = 0;
    8.82 +
    8.83 +    spin_lock_irqsave(&free_list_lock, flags);
    8.84 +    
    8.85 +    temp = free_list.next;
    8.86 +    for ( i = 0; i < bop.size; i++ )
    8.87 +    {
    8.88 +        copy_from_user(&mpfn, bop.pages, sizeof(mpfn));
    8.89 +        bop.pages++;
    8.90 +        if ( mpfn >= max_page )
    8.91 +        {
    8.92 +            DPRINTK("Domain %d page number out of range (%08lx>=%08lx)\n", 
    8.93 +                    p->domain, mpfn, max_page);
    8.94 +            rc = -EINVAL;
    8.95 +            goto out;
    8.96 +        }
    8.97 +
    8.98 +        pf = &frame_table[mpfn];
    8.99 +        if ( (pf->type_count != 0) || 
   8.100 +             (pf->type_count != 0) ||
   8.101 +             (pf->flags != p->domain) )
   8.102 +        {
   8.103 +            DPRINTK("Bad page free for domain %d (%ld, %ld, %08lx)\n",
   8.104 +                    p->domain, pf->type_count, pf->tot_count, pf->flags);
   8.105 +            rc = -EINVAL;
   8.106 +            goto out;
   8.107 +        }
   8.108 +
   8.109 +        pf->flags = 0;
   8.110 +
   8.111 +        list_del(&pf->list);
   8.112 +        list_add(&pf->list, &free_list);
   8.113 +        free_pfns++;
   8.114 +
   8.115 +        p->tot_pages--;
   8.116 +    }
   8.117 +
   8.118 + out:
   8.119 +    spin_unlock_irqrestore(&free_list_lock, flags);
   8.120 +    
   8.121 +    return rc ? rc : bop.size;
   8.122 +}
   8.123 +    
   8.124 +long do_dom_mem_op(dom_mem_op_t *mem_op)
   8.125 +{
   8.126 +    dom_mem_op_t dmop;
   8.127 +    unsigned long ret = 0;
   8.128 +
   8.129 +    if ( copy_from_user(&dmop, mem_op, sizeof(dom_mem_op_t)) )
   8.130 +        return -EFAULT;
   8.131 +
   8.132 +    switch ( dmop.op )
   8.133 +    {
   8.134 +    case BALLOON_DEFLATE_OP:
   8.135 +        ret = alloc_dom_mem(current, dmop.u.balloon_deflate); 
   8.136 +        break;
   8.137 +
   8.138 +    case BALLOON_INFLATE_OP:
   8.139 +        ret = free_dom_mem(current, dmop.u.balloon_inflate); 
   8.140 +        break;
   8.141 +
   8.142 +    default:
   8.143 +        printk("Bad memory operation request %08x.\n", dmop.op);
   8.144 +    }
   8.145 +
   8.146 +    return ret;    
   8.147 +}
     9.1 --- a/xen/common/domain.c	Wed Feb 26 19:17:32 2003 +0000
     9.2 +++ b/xen/common/domain.c	Wed Mar 05 20:14:40 2003 +0000
     9.3 @@ -63,7 +63,7 @@ struct task_struct *do_newdomain(unsigne
     9.4  
     9.5      p->net_ring_base = (net_ring_t *)(p->shared_info + 1);
     9.6      INIT_LIST_HEAD(&p->pg_head);
     9.7 -    p->tot_pages = 0;
     9.8 +    p->max_pages = p->tot_pages = 0;
     9.9      write_lock_irqsave(&tasklist_lock, flags);
    9.10      SET_LINKS(p);
    9.11      write_unlock_irqrestore(&tasklist_lock, flags);
    9.12 @@ -177,6 +177,9 @@ unsigned int alloc_new_dom_mem(struct ta
    9.13      
    9.14      p->tot_pages = req_pages;
    9.15  
    9.16 +    // temporary, max_pages should be explicitly specified
    9.17 +    p->max_pages = p->tot_pages;
    9.18 +
    9.19      return 0;
    9.20  }
    9.21   
    9.22 @@ -206,6 +209,9 @@ void release_task(struct task_struct *p)
    9.23      REMOVE_LINKS(p);
    9.24      write_unlock_irq(&tasklist_lock);
    9.25  
    9.26 +    /* XXX SMH: so below is screwed currently; need ref counting on vifs,
    9.27 +       vhds, etc and proper clean up. Until then just blow the memory :-( */
    9.28 +#if 0
    9.29      /*
    9.30       * Safe! Only queue skbuffs with tasklist_lock held.
    9.31       * Only access shared_info with tasklist_lock held.
    9.32 @@ -225,6 +231,9 @@ void release_task(struct task_struct *p)
    9.33      free_all_dom_mem(p);
    9.34  
    9.35      free_task_struct(p);
    9.36 +#else 
    9.37 +    printk("XEN::release_task: not freeing memory etc yet XXX FIXME.\n"); 
    9.38 +#endif
    9.39  }
    9.40  
    9.41  
    10.1 --- a/xen/common/keyhandler.c	Wed Feb 26 19:17:32 2003 +0000
    10.2 +++ b/xen/common/keyhandler.c	Wed Mar 05 20:14:40 2003 +0000
    10.3 @@ -76,7 +76,7 @@ void halt_machine(u_char key, void *dev_
    10.4  /* XXX SMH: this is keir's fault */
    10.5  static char *task_states[] = 
    10.6  { 
    10.7 -    "Running", 
    10.8 +    "Runnable", 
    10.9      "Interruptible Sleep", 
   10.10      "Uninterruptible Sleep", 
   10.11      NULL, "Stopped", 
   10.12 @@ -104,9 +104,8 @@ void do_task_queues(u_char key, void *de
   10.13  	    printk("Notifying guest...\n"); 
   10.14  	    set_bit(_EVENT_DEBUG, &s->events); 
   10.15  	}
   10.16 -    }
   10.17 +    } while ( (p = p->next_task) != &idle0_task );
   10.18  
   10.19 -    while ( (p = p->next_task) != &idle0_task );
   10.20      read_unlock_irqrestore(&tasklist_lock, flags); 
   10.21  }
   10.22  
    11.1 --- a/xen/common/memory.c	Wed Feb 26 19:17:32 2003 +0000
    11.2 +++ b/xen/common/memory.c	Wed Mar 05 20:14:40 2003 +0000
    11.3 @@ -768,7 +768,7 @@ int do_process_page_updates(page_update_
    11.4              {
    11.5                  MEM_LOG("Bad domain MPT update (dom %d, pfn %ld)",
    11.6                          current->domain, pfn);
    11.7 -            }
    11.8 +            }            
    11.9              break;
   11.10  
   11.11              /*
    12.1 --- a/xen/include/hypervisor-ifs/hypervisor-if.h	Wed Feb 26 19:17:32 2003 +0000
    12.2 +++ b/xen/include/hypervisor-ifs/hypervisor-if.h	Wed Mar 05 20:14:40 2003 +0000
    12.3 @@ -38,13 +38,13 @@ typedef struct
    12.4   * Extended requests specify command in least 8 bits of 'value'.
    12.5   */
    12.6  /* A normal page-table update request. */
    12.7 -#define PGREQ_NORMAL           0
    12.8 +#define PGREQ_NORMAL            0
    12.9  /* Update an entry in the machine->physical mapping table. */
   12.10 -#define PGREQ_MPT_UPDATE       1
   12.11 +#define PGREQ_MPT_UPDATE        1
   12.12  /* An extended command. */
   12.13 -#define PGREQ_EXTENDED_COMMAND 2
   12.14 +#define PGREQ_EXTENDED_COMMAND  2
   12.15  /* DOM0 can make entirely unchecked updates which do not affect refcnts. */
   12.16 -#define PGREQ_UNCHECKED_UPDATE 3
   12.17 +#define PGREQ_UNCHECKED_UPDATE  3
   12.18      unsigned long ptr, val; /* *ptr = val */
   12.19  /* Announce a new top-level page table. */
   12.20  #define PGEXT_PIN_L1_TABLE      0
   12.21 @@ -90,6 +90,7 @@ typedef struct
   12.22  #define __HYPERVISOR_get_debugreg         13
   12.23  #define __HYPERVISOR_update_descriptor    14
   12.24  #define __HYPERVISOR_set_fast_trap        15
   12.25 +#define __HYPERVISOR_dom_mem_op           16
   12.26  
   12.27  #define TRAP_INSTR "int $0x82"
   12.28  
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/xen/include/xeno/dom_mem_ops.h	Wed Mar 05 20:14:40 2003 +0000
    13.3 @@ -0,0 +1,31 @@
    13.4 +/******************************************************************************
    13.5 + * dom_mem_ops.h
    13.6 + *
    13.7 + * Header file supporting domain related memory operations. N.B. keep in sync
    13.8 + * with xen version. 
    13.9 + *
   13.10 + * Copyright (c) 2003, B Dragovic
   13.11 + */
   13.12 +
   13.13 +#define BALLOON_DEFLATE_OP   0
   13.14 +#define BALLOON_INFLATE_OP   1
   13.15 +
   13.16 +typedef struct balloon_deflate_op {
   13.17 +    unsigned long   size;
   13.18 +    unsigned long   * pages;
   13.19 +} balloon_def_op_t;
   13.20 +
   13.21 +typedef struct balloon_inflate_op {
   13.22 +    unsigned long   size;
   13.23 +    unsigned long   * pages;
   13.24 +} balloon_inf_op_t;
   13.25 +
   13.26 +typedef struct dom_mem_ops
   13.27 +{
   13.28 +    unsigned int op;
   13.29 +    union
   13.30 +    {
   13.31 +        balloon_def_op_t balloon_deflate;
   13.32 +        balloon_inf_op_t balloon_inflate;
   13.33 +    } u;
   13.34 +} dom_mem_op_t;
    14.1 --- a/xen/include/xeno/sched.h	Wed Feb 26 19:17:32 2003 +0000
    14.2 +++ b/xen/include/xeno/sched.h	Wed Mar 05 20:14:40 2003 +0000
    14.3 @@ -68,7 +68,8 @@ struct task_struct {
    14.4      shared_info_t *shared_info;
    14.5      
    14.6      struct list_head pg_head;
    14.7 -    unsigned int tot_pages;
    14.8 +    unsigned int tot_pages;     /* number of pages currently possesed */
    14.9 +    unsigned int max_pages;     /* max number of pages that can be possesed */
   14.10  
   14.11      /* Network I/O */
   14.12      net_ring_t *net_ring_base;
    15.1 --- a/xen/net/dev.c	Wed Feb 26 19:17:32 2003 +0000
    15.2 +++ b/xen/net/dev.c	Wed Mar 05 20:14:40 2003 +0000
    15.3 @@ -657,10 +657,11 @@ static void add_to_net_schedule_list_tai
    15.4  /* Destructor function for tx skbs. */
    15.5  static void tx_skb_release(struct sk_buff *skb)
    15.6  {
    15.7 -    int i;
    15.8 +    int i, send = 0;
    15.9      net_vif_t *vif = sys_vif_list[skb->src_vif];
   15.10      unsigned int idx;
   15.11      tx_shadow_entry_t *tx;
   15.12 +    unsigned long cpu_mask;
   15.13      
   15.14      for ( i = 0; i < skb_shinfo(skb)->nr_frags; i++ )
   15.15          put_page_tot(skb_shinfo(skb)->frags[i].page);
   15.16 @@ -691,9 +692,7 @@ static void tx_skb_release(struct sk_buf
   15.17          if ( idx == vif->shadow_ring->tx_idx ) BUG();
   15.18          tx  = &vif->shadow_ring->tx_ring[idx];
   15.19          vif->shadow_ring->tx_cons = TX_RING_INC(idx);
   15.20 -        if ( vif->shadow_ring->tx_cons == vif->net_ring->tx_event )
   15.21 -            set_bit(_EVENT_NET_TX, 
   15.22 -                    &sys_vif_list[skb->src_vif]->domain->shared_info->events);
   15.23 +        if ( vif->shadow_ring->tx_cons == vif->net_ring->tx_event ) send = 1;
   15.24      } while ( tx->status != RING_STATUS_OK );
   15.25  
   15.26      /* Now skip over any more bad descriptors, up to the next good one. */
   15.27 @@ -705,13 +704,19 @@ static void tx_skb_release(struct sk_buf
   15.28               (tx->status == RING_STATUS_OK) )
   15.29              break;
   15.30          vif->shadow_ring->tx_cons = TX_RING_INC(idx);
   15.31 -        if ( vif->shadow_ring->tx_cons == vif->net_ring->tx_event )
   15.32 -            set_bit(_EVENT_NET_TX, 
   15.33 -                    &sys_vif_list[skb->src_vif]->domain->shared_info->events);
   15.34 +        if ( vif->shadow_ring->tx_cons == vif->net_ring->tx_event ) send = 1;
   15.35      } while ( 1 );
   15.36  
   15.37 -    /* Finally, update shared consumer index to the new private value. */
   15.38 +    /* Update shared consumer index to the new private value. */
   15.39      vif->net_ring->tx_cons = vif->shadow_ring->tx_cons;
   15.40 +
   15.41 +    /* Send a transmit event if requested. */
   15.42 +    if ( send )
   15.43 +    {
   15.44 +        cpu_mask = mark_guest_event(
   15.45 +            sys_vif_list[skb->src_vif]->domain, _EVENT_NET_TX);
   15.46 +        guest_event_notify(cpu_mask);
   15.47 +    }
   15.48  }
   15.49  
   15.50      
    16.1 --- a/xenolinux-2.4.21-pre4-sparse/Makefile	Wed Feb 26 19:17:32 2003 +0000
    16.2 +++ b/xenolinux-2.4.21-pre4-sparse/Makefile	Wed Mar 05 20:14:40 2003 +0000
    16.3 @@ -8,7 +8,8 @@ KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$
    16.4  ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)
    16.5  
    16.6  # Xeno hack XXX
    16.7 -ARCH=xeno
    16.8 +ARCH    := xeno
    16.9 +SUBARCH := i386
   16.10  
   16.11  KERNELPATH=kernel-$(shell echo $(KERNELRELEASE) | sed -e "s/-//g")
   16.12  
   16.13 @@ -361,7 +362,7 @@ include/linux/version.h: ./Makefile
   16.14  comma	:= ,
   16.15  
   16.16  init/version.o: init/version.c include/linux/compile.h include/config/MARKER
   16.17 -	$(CC) $(CFLAGS) $(CFLAGS_KERNEL) -DUTS_MACHINE='"$(ARCH)"' -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) -c -o init/version.o init/version.c
   16.18 +	$(CC) $(CFLAGS) $(CFLAGS_KERNEL) -DUTS_MACHINE='"$(SUBARCH)"' -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) -c -o init/version.o init/version.c
   16.19  
   16.20  init/main.o: init/main.c include/config/MARKER
   16.21  	$(CC) $(CFLAGS) $(CFLAGS_KERNEL) $(PROFILING) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) -c -o $@ $<
    17.1 --- a/xenolinux-2.4.21-pre4-sparse/arch/xeno/Makefile	Wed Feb 26 19:17:32 2003 +0000
    17.2 +++ b/xenolinux-2.4.21-pre4-sparse/arch/xeno/Makefile	Wed Mar 05 20:14:40 2003 +0000
    17.3 @@ -47,12 +47,14 @@ HEAD := arch/xeno/kernel/head.o arch/xen
    17.4  SUBDIRS += arch/xeno/kernel arch/xeno/mm arch/xeno/lib
    17.5  SUBDIRS += arch/xeno/drivers/console arch/xeno/drivers/network
    17.6  SUBDIRS += arch/xeno/drivers/dom0 arch/xeno/drivers/block
    17.7 +SUBDIRS += arch/xeno/drivers/balloon
    17.8  
    17.9  CORE_FILES += arch/xeno/kernel/kernel.o arch/xeno/mm/mm.o
   17.10  CORE_FILES += arch/xeno/drivers/console/con.o
   17.11  CORE_FILES += arch/xeno/drivers/block/blk.o
   17.12  CORE_FILES += arch/xeno/drivers/network/net.o
   17.13  CORE_FILES += arch/xeno/drivers/dom0/dom0.o
   17.14 +CORE_FILES += arch/xeno/drivers/balloon/balloon_driver.o
   17.15  LIBS := $(TOPDIR)/arch/xeno/lib/lib.a $(LIBS) $(TOPDIR)/arch/xeno/lib/lib.a
   17.16  
   17.17  arch/xeno/kernel: dummy
   17.18 @@ -73,6 +75,9 @@ arch/xeno/drivers/block: dummy
   17.19  arch/xeno/drivers/dom0: dummy
   17.20  	$(MAKE) linuxsubdirs SUBDIRS=arch/xeno/drivers/dom0
   17.21  
   17.22 +arch/xeno/drivers/balloon: dummy
   17.23 +	$(MAKE) linuxsubdirs SUBDIRS=arch/xeno/drivers/balloon
   17.24 +
   17.25  MAKEBOOT = $(MAKE) -C arch/$(ARCH)/boot
   17.26  
   17.27  vmlinux: arch/xeno/vmlinux.lds
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/balloon/Makefile	Wed Mar 05 20:14:40 2003 +0000
    18.3 @@ -0,0 +1,3 @@
    18.4 +O_TARGET := balloon_driver.o
    18.5 +obj-y := balloon.o
    18.6 +include $(TOPDIR)/Rules.make
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/balloon/balloon.c	Wed Mar 05 20:14:40 2003 +0000
    19.3 @@ -0,0 +1,275 @@
    19.4 +/******************************************************************************
    19.5 + * balloon.c
    19.6 + *
    19.7 + * Xeno balloon driver - enables returning/claiming memory to/from xen
    19.8 + *
    19.9 + * Copyright (c) 2003, B Dragovic
   19.10 + */
   19.11 +
   19.12 +#include <linux/config.h>
   19.13 +#include <linux/module.h>
   19.14 +#include <linux/kernel.h>
   19.15 +#include <linux/sched.h>
   19.16 +#include <linux/errno.h>
   19.17 +#include <linux/proc_fs.h>
   19.18 +
   19.19 +#include <linux/mm.h>
   19.20 +#include <linux/mman.h>
   19.21 +#include <linux/smp_lock.h>
   19.22 +#include <linux/pagemap.h>
   19.23 +
   19.24 +#include <asm/hypervisor.h>
   19.25 +#include <asm/pgalloc.h>
   19.26 +#include <asm/pgtable.h>
   19.27 +#include <asm/uaccess.h>
   19.28 +#include <asm/tlb.h>
   19.29 +
   19.30 +#include "dom_mem_ops.h"
   19.31 +
   19.32 +/* USER DEFINES -- THESE SHOULD BE COPIED TO USER-SPACE TOOLS */
   19.33 +#define USER_INFLATE_BALLOON  1   /* return mem to hypervisor */
   19.34 +#define USER_DEFLATE_BALLOON  2   /* claim mem from hypervisor */
   19.35 +typedef struct user_balloon_op {
   19.36 +    unsigned int  op;
   19.37 +    unsigned long size;
   19.38 +} user_balloon_op_t;
   19.39 +/* END OF USER DEFINE */
   19.40 +
   19.41 +/* Dead entry written into ballon-owned entries in the PMT. */
   19.42 +#define DEAD 0xdeadbeef
   19.43 +
   19.44 +#define BALLOON_ENTRY    "balloon"
   19.45 +extern struct proc_dir_entry *xeno_base;
   19.46 +
   19.47 +static struct proc_dir_entry *balloon_pde;
   19.48 +unsigned long credit;
   19.49 +
   19.50 +static inline unsigned long get_ppte(unsigned long addr)
   19.51 +{
   19.52 +    unsigned long ppte;
   19.53 +    pgd_t *pgd; pmd_t *pmd; pte_t *ptep;
   19.54 +    pgd = pgd_offset_k(addr);
   19.55 +
   19.56 +    if ( pgd_none(*pgd) || pgd_bad(*pgd) ) BUG();
   19.57 +
   19.58 +    pmd = pmd_offset(pgd, addr);
   19.59 +    if ( pmd_none(*pmd) || pmd_bad(*pmd) ) BUG();
   19.60 +
   19.61 +    ptep = pte_offset(pmd, addr);
   19.62 +    ppte = (unsigned long)__pa(ptep);
   19.63 +
   19.64 +    return ppte;
   19.65 +}
   19.66 +
   19.67 +/* main function for relinquishing bit of memory */
   19.68 +static unsigned long inflate_balloon(unsigned long num_pages)
   19.69 +{
   19.70 +    dom_mem_op_t dom_mem_op;
   19.71 +    unsigned long *parray;
   19.72 +    unsigned long *currp;
   19.73 +    unsigned long ret = 0;
   19.74 +    unsigned long vaddr;
   19.75 +    unsigned long i, j;
   19.76 +
   19.77 +    parray = (unsigned long *)kmalloc(num_pages *
   19.78 +                                      sizeof(unsigned long), GFP_KERNEL);
   19.79 +    currp = parray;
   19.80 +
   19.81 +    for ( i = 0; i < num_pages; i++ )
   19.82 +    {
   19.83 +        /* try to obtain a free page, has to be done with GFP_ATOMIC
   19.84 +         * as we do not want to sleep indefinately.
   19.85 +         */
   19.86 +        vaddr = __get_free_page(GFP_ATOMIC);
   19.87 +
   19.88 +        /* if allocation fails, free all reserved pages */
   19.89 +        if(!vaddr){
   19.90 +            printk("Unable to inflate balloon by %ld, only %ld pages free.",
   19.91 +                   num_pages, i);
   19.92 +            currp = parray;
   19.93 +            for(j = 0; j < i; j++){
   19.94 +                free_page(*currp++);
   19.95 +            }
   19.96 +            goto cleanup;
   19.97 +        }
   19.98 +
   19.99 +        *currp++ = vaddr;
  19.100 +    }
  19.101 +
  19.102 +
  19.103 +    currp = parray;
  19.104 +    for ( i = 0; i < num_pages; i++ )
  19.105 +    {
  19.106 +        queue_l1_entry_update(get_ppte(*currp) | PGREQ_NORMAL, 0);
  19.107 +        phys_to_machine_mapping[__pa(*currp) >> PAGE_SHIFT] = DEAD;
  19.108 +        currp++;
  19.109 +    }
  19.110 +
  19.111 +    XENO_flush_page_update_queue();
  19.112 +
  19.113 +    dom_mem_op.op = BALLOON_INFLATE_OP;
  19.114 +    dom_mem_op.u.balloon_inflate.size  = num_pages;
  19.115 +    dom_mem_op.u.balloon_inflate.pages = parray;
  19.116 +    if ( (ret = HYPERVISOR_dom_mem_op(&dom_mem_op)) != num_pages )
  19.117 +    {
  19.118 +        printk("Unable to deflate balloon, error %lx\n", ret);
  19.119 +        goto cleanup;
  19.120 +    }
  19.121 +
  19.122 +    credit += num_pages;
  19.123 +    ret = num_pages;
  19.124 +
  19.125 + cleanup:
  19.126 +    kfree(parray);
  19.127 +
  19.128 +    return ret;
  19.129 +}
  19.130 +
  19.131 +/* install new mem pages obtained by deflate_balloon. function walks 
  19.132 + * phys->machine mapping table looking for DEAD entries and populates
  19.133 + * them.
  19.134 + */
  19.135 +static unsigned long process_new_pages(unsigned long * parray, 
  19.136 +                                       unsigned long num)
  19.137 +{
  19.138 +    /* currently, this function is rather simplistic as 
  19.139 +     * it is assumed that domain reclaims only number of 
  19.140 +     * pages previously released. this is to change soon
  19.141 +     * and the code to extend page tables etc. will be 
  19.142 +     * incorporated here.
  19.143 +     */
  19.144 +     
  19.145 +    unsigned long tot_pages = start_info.nr_pages;   
  19.146 +    unsigned long * curr = parray;
  19.147 +    unsigned long num_installed;
  19.148 +    unsigned long i;
  19.149 +
  19.150 +    num_installed = 0;
  19.151 +    for ( i = 0; i < tot_pages; i++ )
  19.152 +    {
  19.153 +        if ( phys_to_machine_mapping[i] == DEAD )
  19.154 +        {
  19.155 +            phys_to_machine_mapping[i] = *curr;
  19.156 +            queue_l1_entry_update((i << PAGE_SHIFT) | PGREQ_MPT_UPDATE, i);
  19.157 +            queue_l1_entry_update(
  19.158 +                get_ppte((unsigned long)__va(i << PAGE_SHIFT)) | PGREQ_NORMAL, 
  19.159 +                ((*curr) << PAGE_SHIFT) | L1_PROT);
  19.160 +
  19.161 +            *curr = (unsigned long)__va(i << PAGE_SHIFT);
  19.162 +            curr++;
  19.163 +            num_installed++;
  19.164 +        }
  19.165 +    }
  19.166 +
  19.167 +    /* now, this is tricky (and will also change for machine addrs that 
  19.168 +      * are mapped to not previously released addresses). we free pages
  19.169 +      * that were allocated by get_free_page (the mappings are different 
  19.170 +      * now, of course).
  19.171 +      */
  19.172 +    curr = parray;
  19.173 +    for ( i = 0; i < num_installed; i++ )
  19.174 +    {
  19.175 +        free_page(*curr);
  19.176 +        curr++;
  19.177 +    }
  19.178 +
  19.179 +    return num_installed;
  19.180 +}
  19.181 +
  19.182 +static unsigned long deflate_balloon(unsigned long num_pages)
  19.183 +{
  19.184 +    dom_mem_op_t dom_mem_op;
  19.185 +    unsigned long ret;
  19.186 +    unsigned long * parray;
  19.187 +
  19.188 +    if ( num_pages > credit )
  19.189 +    {
  19.190 +        printk("Can not allocate more pages than previously released.\n");
  19.191 +        return -EAGAIN;
  19.192 +    }
  19.193 +
  19.194 +    parray = (unsigned long *)kmalloc(num_pages * sizeof(unsigned long), 
  19.195 +                                      GFP_KERNEL);
  19.196 +
  19.197 +    dom_mem_op.op = BALLOON_DEFLATE_OP;
  19.198 +    dom_mem_op.u.balloon_deflate.size = num_pages;
  19.199 +    dom_mem_op.u.balloon_deflate.pages = parray;
  19.200 +    if((ret = HYPERVISOR_dom_mem_op(&dom_mem_op)) != num_pages){
  19.201 +        printk("Unable to deflate balloon, error %lx\n", ret);
  19.202 +        goto cleanup;
  19.203 +    }
  19.204 +
  19.205 +    if((ret = process_new_pages(parray, num_pages)) < num_pages){
  19.206 +        printk("Unable to deflate balloon by specified %lx pages, only %lx.\n",
  19.207 +               num_pages, ret);
  19.208 +        goto cleanup;
  19.209 +    }
  19.210 +
  19.211 +    ret = num_pages;
  19.212 +
  19.213 + cleanup:
  19.214 +    kfree(parray);
  19.215 +
  19.216 +    return ret;
  19.217 +}
  19.218 +
  19.219 +static int balloon_write(struct file *file, const char *buffer,
  19.220 +                         u_long count, void *data)
  19.221 +{
  19.222 +    user_balloon_op_t bop;
  19.223 +
  19.224 +    /* Only admin can play with the balloon :) */
  19.225 +    if ( !capable(CAP_SYS_ADMIN) )
  19.226 +        return -EPERM;
  19.227 +
  19.228 +    if ( copy_from_user(&bop, buffer, sizeof(bop)) )
  19.229 +        return -EFAULT;
  19.230 +
  19.231 +    switch ( bop.op )
  19.232 +    {
  19.233 +    case USER_INFLATE_BALLOON:
  19.234 +        if ( inflate_balloon(bop.size) < bop.size )
  19.235 +            return -EAGAIN;
  19.236 +        break;
  19.237 +        
  19.238 +    case USER_DEFLATE_BALLOON:
  19.239 +        deflate_balloon(bop.size);
  19.240 +        break;
  19.241 +
  19.242 +    default:
  19.243 +        printk("Unknown command to balloon driver.");
  19.244 +        return -EFAULT;
  19.245 +    }
  19.246 +
  19.247 +    return sizeof(bop);
  19.248 +}
  19.249 +
  19.250 +/*
  19.251 + * main balloon driver initialization function.
  19.252 + */
  19.253 +static int __init init_module(void)
  19.254 +{
  19.255 +    printk(KERN_ALERT "Starting Xeno Balloon driver\n");
  19.256 +
  19.257 +    credit = 0;
  19.258 +
  19.259 +    balloon_pde = create_proc_entry(BALLOON_ENTRY, 0600, xeno_base);
  19.260 +    if ( balloon_pde == NULL )
  19.261 +    {
  19.262 +        printk(KERN_ALERT "Unable to create balloon driver proc entry!");
  19.263 +        return -1;
  19.264 +    }
  19.265 +
  19.266 +    balloon_pde->write_proc = balloon_write;
  19.267 +
  19.268 +    return 0;
  19.269 +}
  19.270 +
  19.271 +static void __exit cleanup_module(void)
  19.272 +{
  19.273 +}
  19.274 +
  19.275 +module_init(init_module);
  19.276 +module_exit(cleanup_module);
  19.277 +
  19.278 +
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/balloon/dom_mem_ops.h	Wed Mar 05 20:14:40 2003 +0000
    20.3 @@ -0,0 +1,32 @@
    20.4 +/******************************************************************************
    20.5 + * dom_mem_ops.h
    20.6 + *
    20.7 + * Header file supporting domain related memory operations. N.B. keep in sync
    20.8 + * with xen version. 
    20.9 + *
   20.10 + * Copyright (c) 2003, B Dragovic
   20.11 + */
   20.12 +
   20.13 +#define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_USER|_PAGE_ACCESSED)
   20.14 +#define BALLOON_DEFLATE_OP   0
   20.15 +#define BALLOON_INFLATE_OP   1
   20.16 +
   20.17 +typedef struct balloon_deflate_op {
   20.18 +    unsigned long   size;
   20.19 +    unsigned long   * pages;
   20.20 +} balloon_def_op_t;
   20.21 +
   20.22 +typedef struct balloon_inflate_op {
   20.23 +    unsigned long   size;
   20.24 +    unsigned long   * pages;
   20.25 +} balloon_inf_op_t;
   20.26 +
   20.27 +typedef struct dom_mem_ops
   20.28 +{
   20.29 +    unsigned int op;
   20.30 +    union
   20.31 +    {
   20.32 +        balloon_def_op_t balloon_deflate;
   20.33 +        balloon_inf_op_t balloon_inflate;
   20.34 +    }u;
   20.35 +} dom_mem_op_t;
    21.1 --- a/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/dom0/dom0_core.c	Wed Feb 26 19:17:32 2003 +0000
    21.2 +++ b/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/dom0/dom0_core.c	Wed Mar 05 20:14:40 2003 +0000
    21.3 @@ -53,7 +53,7 @@ typedef struct proc_mem_data {
    21.4  
    21.5  #define MAP_DISCONT     1
    21.6  
    21.7 -static struct proc_dir_entry *xeno_base;
    21.8 +struct proc_dir_entry *xeno_base;
    21.9  static struct proc_dir_entry *dom0_cmd_intf;
   21.10  static struct proc_dir_entry *proc_ft;
   21.11  
    22.1 --- a/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/network/network.c	Wed Feb 26 19:17:32 2003 +0000
    22.2 +++ b/xenolinux-2.4.21-pre4-sparse/arch/xeno/drivers/network/network.c	Wed Mar 05 20:14:40 2003 +0000
    22.3 @@ -23,6 +23,7 @@
    22.4  
    22.5  #include <asm/io.h>
    22.6  #include <net/sock.h>
    22.7 +#include <net/pkt_sched.h>
    22.8  
    22.9  #define NET_TX_IRQ _EVENT_NET_TX
   22.10  #define NET_RX_IRQ _EVENT_NET_RX
   22.11 @@ -65,7 +66,20 @@ struct net_private
   22.12      spinlock_t tx_lock;
   22.13  };
   22.14  
   22.15 - 
   22.16 +
   22.17 +static void dbg_network_int(int irq, void *dev_id, struct pt_regs *ptregs)
   22.18 +{
   22.19 +    struct net_device *dev = (struct net_device *)dev_id;
   22.20 +    struct net_private *np = dev->priv;
   22.21 +    printk(KERN_ALERT "tx_full = %d, tx_entries = %d, tx_idx = %d,"
   22.22 +           " tx_cons = %d, tx_prod = %d, tx_event = %d, state=%d\n",
   22.23 +           np->tx_full, atomic_read(&np->tx_entries), np->tx_idx, 
   22.24 +           np->net_ring->tx_cons, np->net_ring->tx_prod, 
   22.25 +           np->net_ring->tx_event,
   22.26 +           test_bit(__LINK_STATE_XOFF, &dev->state));
   22.27 +}
   22.28 +
   22.29 +
   22.30  static int network_open(struct net_device *dev)
   22.31  {
   22.32      struct net_private *np = dev->priv;
   22.33 @@ -123,6 +137,14 @@ static int network_open(struct net_devic
   22.34          goto fail;
   22.35      }
   22.36  
   22.37 +    error = request_irq(_EVENT_DEBUG, dbg_network_int, SA_SHIRQ,
   22.38 +                        "debug", dev);
   22.39 +    if ( error )
   22.40 +    {
   22.41 +        printk(KERN_WARNING "%s: Non-fatal error -- no debug interrupt\n",
   22.42 +               dev->name);
   22.43 +    }
   22.44 +
   22.45      printk("XenoLinux Virtual Network Driver installed as %s\n", dev->name);
   22.46  
   22.47      netif_start_queue(dev);
   22.48 @@ -147,17 +169,28 @@ static void network_tx_buf_gc(struct net
   22.49      struct net_private *np = dev->priv;
   22.50      struct sk_buff *skb;
   22.51      unsigned long flags;
   22.52 +    unsigned int cons;
   22.53  
   22.54      spin_lock_irqsave(&np->tx_lock, flags);
   22.55  
   22.56 -    for ( i = np->tx_idx; i != np->net_ring->tx_cons; i = TX_RING_INC(i) )
   22.57 -    {
   22.58 -        skb = np->tx_skb_ring[i];
   22.59 -        dev_kfree_skb_any(skb);
   22.60 -        atomic_dec(&np->tx_entries);
   22.61 +    do {
   22.62 +        cons = np->net_ring->tx_cons;
   22.63 +
   22.64 +        for ( i = np->tx_idx; i != cons; i = TX_RING_INC(i) )
   22.65 +        {
   22.66 +            skb = np->tx_skb_ring[i];
   22.67 +            dev_kfree_skb_any(skb);
   22.68 +            atomic_dec(&np->tx_entries);
   22.69 +        }
   22.70 +        
   22.71 +        np->tx_idx = i;
   22.72 +        
   22.73 +        /* Set a new event, then check for race with update of tx_cons. */
   22.74 +        np->net_ring->tx_event =
   22.75 +            TX_RING_ADD(cons, (atomic_read(&np->tx_entries)>>1) + 1);
   22.76 +        smp_mb();
   22.77      }
   22.78 -
   22.79 -    np->tx_idx = i;
   22.80 +    while ( cons != np->net_ring->tx_cons );
   22.81  
   22.82      if ( np->tx_full && (atomic_read(&np->tx_entries) < TX_MAX_ENTRIES) )
   22.83      {
   22.84 @@ -262,17 +295,9 @@ static int network_start_xmit(struct sk_
   22.85      {
   22.86          np->tx_full = 1;
   22.87          netif_stop_queue(dev);
   22.88 -        np->net_ring->tx_event = 
   22.89 -            TX_RING_ADD(np->tx_idx, atomic_read(&np->tx_entries) >> 1);
   22.90 -    }
   22.91 -    else
   22.92 -    {
   22.93 -        /* Avoid unnecessary tx interrupts. */
   22.94 -        np->net_ring->tx_event = TX_RING_INC(np->net_ring->tx_prod);
   22.95      }
   22.96      spin_unlock_irq(&np->tx_lock);
   22.97  
   22.98 -    /* Must do this after setting tx_event: race with updates of tx_cons. */
   22.99      network_tx_buf_gc(dev);
  22.100  
  22.101      HYPERVISOR_net_update();
    23.1 --- a/xenolinux-2.4.21-pre4-sparse/include/asm-xeno/hypervisor.h	Wed Feb 26 19:17:32 2003 +0000
    23.2 +++ b/xenolinux-2.4.21-pre4-sparse/include/asm-xeno/hypervisor.h	Wed Mar 05 20:14:40 2003 +0000
    23.3 @@ -313,4 +313,15 @@ static inline int HYPERVISOR_set_fast_tr
    23.4      return ret;
    23.5  }
    23.6  
    23.7 +static inline int HYPERVISOR_dom_mem_op(void *dom_mem_op)
    23.8 +{
    23.9 +    int ret;
   23.10 +    __asm__ __volatile__ (
   23.11 +        TRAP_INSTR
   23.12 +        : "=a" (ret) : "0" (__HYPERVISOR_dom_mem_op),
   23.13 +        "b" (dom_mem_op) : "memory" );
   23.14 +
   23.15 +    return ret;
   23.16 +}
   23.17 +
   23.18  #endif /* __HYPERVISOR_H__ */
    24.1 --- a/xenolinux-2.4.21-pre4-sparse/include/asm-xeno/page.h	Wed Feb 26 19:17:32 2003 +0000
    24.2 +++ b/xenolinux-2.4.21-pre4-sparse/include/asm-xeno/page.h	Wed Mar 05 20:14:40 2003 +0000
    24.3 @@ -173,6 +173,10 @@ static __inline__ int get_order(unsigned
    24.4  #define VM_DATA_DEFAULT_FLAGS	(VM_READ | VM_WRITE | VM_EXEC | \
    24.5  				 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
    24.6  
    24.7 +/* VIRT <-> MACHINE conversion */
    24.8 +#define virt_to_machine(_a) (phys_to_machine(__pa(_a)))
    24.9 +#define machine_to_virt(_m) (__va(machine_to_phys(_m)))
   24.10 +
   24.11  #endif /* __KERNEL__ */
   24.12  
   24.13  #endif /* _I386_PAGE_H */