From: Jack Lange Date: Thu, 26 Nov 2009 20:16:19 +0000 (-0600) Subject: various changes... X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=0e097100a26bc43eb8964734fa43130fc4c71429 various changes... --- diff --git a/palacios/include/devices/vnet.h b/palacios/include/devices/vnet.h index 01e387a..91cde55 100644 --- a/palacios/include/devices/vnet.h +++ b/palacios/include/devices/vnet.h @@ -39,13 +39,6 @@ #define ETHERNET_DATA_MAX 1500 #define ETHERNET_PACKET_LEN (ETHERNET_HEADER_LEN + ETHERNET_DATA_MAX) -#define TCP_TYPE 0 -#define UDP_TYPE 1 - -#define TCP_STR "TCP" -#define UDP_STR "UDP" - - //the routing entry struct routing { char src_mac[6]; diff --git a/palacios/include/palacios/vmm_mem.h b/palacios/include/palacios/vmm_mem.h index 553497d..f6338df 100644 --- a/palacios/include/palacios/vmm_mem.h +++ b/palacios/include/palacios/vmm_mem.h @@ -78,7 +78,7 @@ typedef struct v3_shdw_map { -void v3_init_shadow_map(struct guest_info * info); +int v3_init_shadow_map(struct guest_info * info); void v3_delete_shadow_map(struct guest_info * info); diff --git a/palacios/include/palacios/vmm_shadow_paging.h b/palacios/include/palacios/vmm_shadow_paging.h index d7629a1..cd0cb7a 100644 --- a/palacios/include/palacios/vmm_shadow_paging.h +++ b/palacios/include/palacios/vmm_shadow_paging.h @@ -31,9 +31,6 @@ struct shadow_page_state { - // ugly optimization hack - v3_reg_t prev_guest_cr3; - // virtualized control registers v3_reg_t guest_cr3; diff --git a/palacios/src/devices/Makefile b/palacios/src/devices/Makefile index 0e716aa..515b088 100644 --- a/palacios/src/devices/Makefile +++ b/palacios/src/devices/Makefile @@ -16,7 +16,7 @@ obj-$(CONFIG_PCI) += pci.o obj-$(CONFIG_PIIX3) += piix3.o obj-$(CONFIG_RAM_CD) += ram_cd.o obj-$(CONFIG_RAM_HD) += ram_hd.o -obj-$(CONFIG_SYM_SWAP) += sym_swap.o +obj-$(CONFIG_SYM_SWAP) += sym_swap.o tmp_blk.o obj-$(CONFIG_NE2K) += ne2k.o @@ -26,4 +26,4 @@ obj-$(CONFIG_NET_HD) += net_hd.o obj-$(CONFIG_CGA) += cga.o obj-$(CONFIG_TELNET_CONSOLE) += telnet_cons.o -obj-$(CONFIG_PASSTHROUGH_PCI) += pci_passthrough.o \ No newline at end of file +obj-$(CONFIG_PASSTHROUGH_PCI) += pci_passthrough.o diff --git a/palacios/src/devices/tmp_blk.c b/palacios/src/devices/tmp_blk.c new file mode 100644 index 0000000..b8e08b2 --- /dev/null +++ b/palacios/src/devices/tmp_blk.c @@ -0,0 +1,141 @@ +/* + * This file is part of the Palacios Virtual Machine Monitor developed + * by the V3VEE Project with funding from the United States National + * Science Foundation and the Department of Energy. + * + * The V3VEE Project is a joint project between Northwestern University + * and the University of New Mexico. You can find out more at + * http://www.v3vee.org + * + * Copyright (c) 2008, Jack Lange + * Copyright (c) 2008, The V3VEE Project + * All rights reserved. + * + * Author: Jack Lange + * + * This is free software. You are permitted to use, + * redistribute, and modify it as specified in the file "V3VEE_LICENSE". + */ + +#include +#include +#include + + +#define BLK_CAPACITY (500 * 1024 * 1024) + + + + +struct blk_state { + + struct vm_device * blk_dev; + + uint64_t capacity; + uint8_t * blk_space; + addr_t blk_base_addr; +}; + + + +static uint64_t blk_get_capacity(void * private_data) { + struct vm_device * dev = (struct vm_device *)private_data; + struct blk_state * blk = (struct blk_state *)(dev->private_data); + + PrintDebug("SymBlk: Getting Capacity %d\n", (uint32_t)(blk->capacity)); + + return blk->capacity / HD_SECTOR_SIZE; +} + + + +static int blk_read(uint8_t * buf, int sector_count, uint64_t lba, void * private_data) { + struct vm_device * dev = (struct vm_device *)private_data; + struct blk_state * blk = (struct blk_state *)(dev->private_data); + uint32_t offset = lba * HD_SECTOR_SIZE; + uint32_t length = sector_count * HD_SECTOR_SIZE; + + memcpy(buf, blk->blk_space + offset, length); + + return 0; +} + + + + +static int blk_write(uint8_t * buf, int sector_count, uint64_t lba, void * private_data) { + struct vm_device * dev = (struct vm_device *)private_data; + struct blk_state * blk = (struct blk_state *)(dev->private_data); + uint32_t offset = lba * HD_SECTOR_SIZE; + uint32_t length = sector_count * HD_SECTOR_SIZE; + + memcpy(blk->blk_space + offset, buf, length); + + return 0; +} + + +static int blk_free(struct vm_device * dev) { + return -1; +} + + +static struct v3_hd_ops hd_ops = { + .read = blk_read, + .write = blk_write, + .get_capacity = blk_get_capacity, +}; + + + +static struct v3_device_ops dev_ops = { + .free = blk_free, + .reset = NULL, + .start = NULL, + .stop = NULL, +}; + + + + +static int blk_init(struct guest_info * vm, void * cfg_data) { + struct blk_state * blk = NULL; + struct vm_device * virtio_blk = v3_find_dev(vm, (char *)cfg_data); + + if (!virtio_blk) { + PrintError("could not find Virtio backend\n"); + return -1; + } + + PrintDebug("Creating Blk Device\n"); + + if (virtio_blk == NULL) { + PrintError("Blk device requires a virtio block device\n"); + return -1; + } + + blk = (struct blk_state *)V3_Malloc(sizeof(struct blk_state) + ((BLK_CAPACITY / 4096) / 8)); + + blk->blk_dev = virtio_blk; + blk->capacity = BLK_CAPACITY; + + blk->blk_base_addr = (addr_t)V3_AllocPages(blk->capacity / 4096); + blk->blk_space = (uint8_t *)V3_VAddr((void *)(blk->blk_base_addr)); + memset(blk->blk_space, 0, BLK_CAPACITY); + + + struct vm_device * dev = v3_allocate_device("TMP_BLK", &dev_ops, blk); + + if (v3_attach_device(vm, dev) == -1) { + PrintError("Could not attach device %s\n", "TMP_BLK"); + return -1; + } + + + v3_virtio_register_harddisk(virtio_blk, &hd_ops, dev); + + + return 0; +} + +device_register("TMP_BLK", blk_init) diff --git a/palacios/src/palacios/vmm_config.c b/palacios/src/palacios/vmm_config.c index 136213d..886aee7 100644 --- a/palacios/src/palacios/vmm_config.c +++ b/palacios/src/palacios/vmm_config.c @@ -27,6 +27,7 @@ #include #include #include +#include #ifdef CONFIG_SYMBIOTIC #include @@ -48,6 +49,17 @@ #include +/* +static const char * test_cfg_xml = \ +"\n \ +2048\n\ +\n\ +\n\ +\n\ +\n\ +"; +*/ + #include @@ -78,6 +90,29 @@ static int passthrough_mem_write(addr_t guest_addr, void * src, uint_t length, v int v3_pre_config_guest(struct guest_info * info, struct v3_vm_config * config_ptr) { extern v3_cpu_arch_t v3_cpu_types[]; + + /* + { + struct v3_xml * cfg = v3_xml_parse((char *)test_cfg_xml); + struct v3_xml * devs = NULL; + struct v3_xml * tmp = NULL; + PrintError("Parsed XML COnfig %s\n", v3_xml_name(cfg)); + + PrintError("memory=%s\n", v3_xml_txt(v3_xml_child(cfg, "memory"))); + + devs = v3_xml_child(cfg, "devices"); + + for (tmp = v3_xml_child(devs, "device"); tmp; tmp = v3_xml_next(tmp)) { + PrintError("Device: %s, id=%s\n", + v3_xml_name(tmp), + v3_xml_attr(tmp, "id")); + } + v3_xml_free(cfg); + + return -1; + } + */ + // Amount of ram the Guest will have, rounded to a 4K page boundary info->mem_size = config_ptr->mem_size & ~(addr_t)0xfff; @@ -103,7 +138,10 @@ int v3_pre_config_guest(struct guest_info * info, struct v3_vm_config * config_p v3_init_host_events(info); // Initialize the memory map - v3_init_shadow_map(info); + if (v3_init_shadow_map(info) == -1) { + PrintError("Could not initialize shadow map\n"); + return -1; + } if ((v3_cpu_types[info->cpu_id] == V3_SVM_REV3_CPU) && (config_ptr->enable_nested_paging == 1)) { @@ -276,6 +314,7 @@ static int setup_devices(struct guest_info * info, struct v3_vm_config * config_ v3_create_device(info, "LNX_VIRTIO_BLK", "PCI"); v3_create_device(info, "LNX_VIRTIO_BALLOON", "PCI"); v3_create_device(info, "SYM_SWAP", "LNX_VIRTIO_BLK"); + // v3_create_device(info, "TMP_BLK", "LNX_VIRTIO_BLK"); v3_create_device(info, "IDE", &ide_config); @@ -324,6 +363,18 @@ static int setup_devices(struct guest_info * info, struct v3_vm_config * config_ PrintDebug("Creating NET HD\n"); v3_create_device(info, "NET-HD", &cfg); } + + } else if (config_ptr->pri_disk_type == VIRTIO) { + if (config_ptr->pri_disk_con == RAM) { + struct ram_hd_cfg cfg = {"LNX_VIRTIO_BLK", 0, 0, + (addr_t)(config_ptr->pri_disk_info.ram.data_ptr), + config_ptr->pri_disk_info.ram.size}; + + PrintDebug("Creating Virtio RAM HD\n"); + + v3_create_device(info, "RAM-HD", &cfg); + } + } } diff --git a/palacios/src/palacios/vmm_ctrl_regs.c b/palacios/src/palacios/vmm_ctrl_regs.c index bbeaf4c..d3e9360 100644 --- a/palacios/src/palacios/vmm_ctrl_regs.c +++ b/palacios/src/palacios/vmm_ctrl_regs.c @@ -324,21 +324,6 @@ int v3_handle_cr3_write(struct guest_info * info) { } -#ifdef CONFIG_CRAY_XT - - // If Paging is enabled in the guest then we need to change the shadow page tables - if (info->mem_mode == VIRTUAL_MEM) { - if (info->shdw_pg_state.prev_guest_cr3 != info->shdw_pg_state.guest_cr3) { - if (v3_activate_shadow_pt(info) == -1) { - PrintError("Failed to activate 32 bit shadow page table\n"); - return -1; - } - } - } - - info->shdw_pg_state.prev_guest_cr3 = info->shdw_pg_state.guest_cr3; -#else - // If Paging is enabled in the guest then we need to change the shadow page tables if (info->mem_mode == VIRTUAL_MEM) { if (v3_activate_shadow_pt(info) == -1) { @@ -346,9 +331,6 @@ int v3_handle_cr3_write(struct guest_info * info) { return -1; } } - -#endif - PrintDebug("New Shadow CR3=%p; New Guest CR3=%p\n", (void *)(addr_t)(info->ctrl_regs.cr3), diff --git a/palacios/src/palacios/vmm_mem.c b/palacios/src/palacios/vmm_mem.c index b012bc3..8494f47 100644 --- a/palacios/src/palacios/vmm_mem.c +++ b/palacios/src/palacios/vmm_mem.c @@ -41,7 +41,7 @@ static int mem_offset_hypercall(struct guest_info * info, uint_t hcall_id, void } -void v3_init_shadow_map(struct guest_info * info) { +int v3_init_shadow_map(struct guest_info * info) { v3_shdw_map_t * map = &(info->mem_map); addr_t mem_pages = info->mem_size >> 12; @@ -56,9 +56,17 @@ void v3_init_shadow_map(struct guest_info * info) { map->base_region.host_type = SHDW_REGION_ALLOCATED; map->base_region.host_addr = (addr_t)V3_AllocPages(mem_pages); + + if ((void *)map->base_region.host_addr == NULL) { + PrintError("Could not allocate Guest memory\n"); + return -1; + } + //memset(V3_VAddr((void *)map->base_region.host_addr), 0xffffffff, map->base_region.guest_end); v3_register_hypercall(info, MEM_OFFSET_HCALL, mem_offset_hypercall, NULL); + + return 0; } void v3_delete_shadow_map(struct guest_info * info) { diff --git a/palacios/src/palacios/vmm_shadow_paging.c b/palacios/src/palacios/vmm_shadow_paging.c index abe6d88..0afc383 100644 --- a/palacios/src/palacios/vmm_shadow_paging.c +++ b/palacios/src/palacios/vmm_shadow_paging.c @@ -81,8 +81,6 @@ static void telemetry_cb(struct guest_info * info, void * private_data, char * h int v3_init_shadow_page_state(struct guest_info * info) { struct shadow_page_state * state = &(info->shdw_pg_state); - state->prev_guest_cr3 = 0; - state->guest_cr3 = 0; state->guest_cr0 = 0; state->guest_efer.value = 0x0LL;