From d1814e08c0409d9f352f9ea7fab377bcee1286b8 Mon Sep 17 00:00:00 2001 From: Stefano Stabellini Date: Thu, 19 Jan 2012 15:56:11 +0000 Subject: xen: record physmap changes to xenstore Write to xenstore any physmap changes so that the hypervisor can be aware of them. Read physmap changes from xenstore on boot. Signed-off-by: Stefano Stabellini --- xen-all.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) (limited to 'xen-all.c') diff --git a/xen-all.c b/xen-all.c index b0ed1ed193..f2cad8227e 100644 --- a/xen-all.c +++ b/xen-all.c @@ -65,7 +65,7 @@ static inline ioreq_t *xen_vcpu_ioreq(shared_iopage_t *shared_page, int vcpu) typedef struct XenPhysmap { target_phys_addr_t start_addr; ram_addr_t size; - MemoryRegion *mr; + char *name; target_phys_addr_t phys_offset; QLIST_ENTRY(XenPhysmap) list; @@ -237,6 +237,7 @@ static int xen_add_to_physmap(XenIOState *state, XenPhysmap *physmap = NULL; target_phys_addr_t pfn, start_gpfn; target_phys_addr_t phys_offset = memory_region_get_ram_addr(mr); + char path[80], value[17]; if (get_physmapping(state, start_addr, size)) { return 0; @@ -275,6 +276,7 @@ go_physmap: physmap->start_addr = start_addr; physmap->size = size; + physmap->name = (char *)mr->name; physmap->phys_offset = phys_offset; QLIST_INSERT_HEAD(&state->physmap, physmap, list); @@ -283,6 +285,30 @@ go_physmap: start_addr >> TARGET_PAGE_BITS, (start_addr + size) >> TARGET_PAGE_BITS, XEN_DOMCTL_MEM_CACHEATTR_WB); + + snprintf(path, sizeof(path), + "/local/domain/0/device-model/%d/physmap/%"PRIx64"/start_addr", + xen_domid, (uint64_t)phys_offset); + snprintf(value, sizeof(value), "%"PRIx64, (uint64_t)start_addr); + if (!xs_write(state->xenstore, 0, path, value, strlen(value))) { + return -1; + } + snprintf(path, sizeof(path), + "/local/domain/0/device-model/%d/physmap/%"PRIx64"/size", + xen_domid, (uint64_t)phys_offset); + snprintf(value, sizeof(value), "%"PRIx64, (uint64_t)size); + if (!xs_write(state->xenstore, 0, path, value, strlen(value))) { + return -1; + } + if (mr->name) { + snprintf(path, sizeof(path), + "/local/domain/0/device-model/%d/physmap/%"PRIx64"/name", + xen_domid, (uint64_t)phys_offset); + if (!xs_write(state->xenstore, 0, path, mr->name, strlen(mr->name))) { + return -1; + } + } + return 0; } @@ -911,6 +937,55 @@ int xen_init(void) return 0; } +static void xen_read_physmap(XenIOState *state) +{ + XenPhysmap *physmap = NULL; + unsigned int len, num, i; + char path[80], *value = NULL; + char **entries = NULL; + + snprintf(path, sizeof(path), + "/local/domain/0/device-model/%d/physmap", xen_domid); + entries = xs_directory(state->xenstore, 0, path, &num); + if (entries == NULL) + return; + + for (i = 0; i < num; i++) { + physmap = g_malloc(sizeof (XenPhysmap)); + physmap->phys_offset = strtoull(entries[i], NULL, 16); + snprintf(path, sizeof(path), + "/local/domain/0/device-model/%d/physmap/%s/start_addr", + xen_domid, entries[i]); + value = xs_read(state->xenstore, 0, path, &len); + if (value == NULL) { + free(physmap); + continue; + } + physmap->start_addr = strtoull(value, NULL, 16); + free(value); + + snprintf(path, sizeof(path), + "/local/domain/0/device-model/%d/physmap/%s/size", + xen_domid, entries[i]); + value = xs_read(state->xenstore, 0, path, &len); + if (value == NULL) { + free(physmap); + continue; + } + physmap->size = strtoull(value, NULL, 16); + free(value); + + snprintf(path, sizeof(path), + "/local/domain/0/device-model/%d/physmap/%s/name", + xen_domid, entries[i]); + physmap->name = xs_read(state->xenstore, 0, path, &len); + + QLIST_INSERT_HEAD(&state->physmap, physmap, list); + } + free(entries); + return; +} + int xen_hvm_init(void) { int i, rc; @@ -986,6 +1061,7 @@ int xen_hvm_init(void) xen_be_register("console", &xen_console_ops); xen_be_register("vkbd", &xen_kbdmouse_ops); xen_be_register("qdisk", &xen_blkdev_ops); + xen_read_physmap(state); return 0; } -- cgit v1.2.1 From cd1ba7de230b3a85fb4dba53bb681b7ea626b4eb Mon Sep 17 00:00:00 2001 From: Anthony PERARD Date: Wed, 18 Jan 2012 12:21:38 +0000 Subject: xen mapcache: check if memory region has moved. This patch changes the xen_map_cache behavior. Before trying to map a guest addr, mapcache will look into the list of range of address that have been moved (physmap/set_memory). There is currently one memory space like this, the vram, "moved" from were it's allocated to were the guest will look into. This help to have a succefull migration. Signed-off-by: Anthony PERARD Signed-off-by: Stefano Stabellini --- xen-all.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'xen-all.c') diff --git a/xen-all.c b/xen-all.c index f2cad8227e..972cffd5ba 100644 --- a/xen-all.c +++ b/xen-all.c @@ -225,6 +225,22 @@ static XenPhysmap *get_physmapping(XenIOState *state, return NULL; } +static target_phys_addr_t xen_phys_offset_to_gaddr(target_phys_addr_t start_addr, + ram_addr_t size, void *opaque) +{ + target_phys_addr_t addr = start_addr & TARGET_PAGE_MASK; + XenIOState *xen_io_state = opaque; + XenPhysmap *physmap = NULL; + + QLIST_FOREACH(physmap, &xen_io_state->physmap, list) { + if (range_covers_byte(physmap->phys_offset, physmap->size, addr)) { + return physmap->start_addr; + } + } + + return start_addr; +} + #if CONFIG_XEN_CTRL_INTERFACE_VERSION >= 340 static int xen_add_to_physmap(XenIOState *state, target_phys_addr_t start_addr, @@ -1043,7 +1059,7 @@ int xen_hvm_init(void) } /* Init RAM management */ - xen_map_cache_init(); + xen_map_cache_init(xen_phys_offset_to_gaddr, state); xen_ram_init(ram_size); qemu_add_vm_change_state_handler(xen_hvm_change_state_handler, state); -- cgit v1.2.1 From c234572ded381423abca9801ebf5a32abd2495ef Mon Sep 17 00:00:00 2001 From: Anthony PERARD Date: Wed, 25 Jan 2012 12:36:06 +0000 Subject: xen: do not allocate RAM during INMIGRATE runstate Signed-off-by: Anthony PERARD Signed-off-by: Stefano Stabellini --- xen-all.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'xen-all.c') diff --git a/xen-all.c b/xen-all.c index 972cffd5ba..10d53d168c 100644 --- a/xen-all.c +++ b/xen-all.c @@ -190,6 +190,14 @@ void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr) xen_pfn_t *pfn_list; int i; + if (runstate_check(RUN_STATE_INMIGRATE)) { + /* RAM already populated in Xen */ + fprintf(stderr, "%s: do not alloc "RAM_ADDR_FMT + " bytes of ram at "RAM_ADDR_FMT" when runstate is INMIGRATE\n", + __func__, size, ram_addr); + return; + } + if (mr == &ram_memory) { return; } -- cgit v1.2.1