From patchwork Wed Jul 7 20:08:59 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 110694 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o67K94TG009040 for ; Wed, 7 Jul 2010 20:09:04 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757456Ab0GGUJA (ORCPT ); Wed, 7 Jul 2010 16:09:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37764 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755466Ab0GGUJA (ORCPT ); Wed, 7 Jul 2010 16:09:00 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o67K8xHg001746 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 7 Jul 2010 16:09:00 -0400 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o67K8x0k016784; Wed, 7 Jul 2010 16:08:59 -0400 From: Alex Williamson Subject: [PATCH] kvm: merge fixes for vmstate/block name from qemu.git To: kvm@vger.kernel.org Cc: alex.williamson@redhat.com Date: Wed, 07 Jul 2010 14:08:59 -0600 Message-ID: <20100707200344.22503.73686.stgit@localhost.localdomain> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Wed, 07 Jul 2010 20:09:04 +0000 (UTC) diff --git a/cpu-common.h b/cpu-common.h index 4890da4..f430f2d 100644 --- a/cpu-common.h +++ b/cpu-common.h @@ -40,8 +40,10 @@ static inline void cpu_register_physical_memory(target_phys_addr_t start_addr, } ram_addr_t cpu_get_physical_page_desc(target_phys_addr_t addr); -ram_addr_t qemu_ram_map(ram_addr_t size, void *host); +ram_addr_t qemu_ram_map(DeviceState *dev, const char *name, + ram_addr_t size, void *host); ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size); +void qemu_ram_unmap(ram_addr_t addr); void qemu_ram_free(ram_addr_t addr); /* This should only be used for ram local to a device. */ void *qemu_get_ram_ptr(ram_addr_t addr); diff --git a/exec.c b/exec.c index 7c7e7bc..6347e61 100644 --- a/exec.c +++ b/exec.c @@ -2787,33 +2787,6 @@ static void *file_ram_alloc(RAMBlock *block, } #endif -ram_addr_t qemu_ram_map(ram_addr_t size, void *host) -{ - RAMBlock *new_block; - - size = TARGET_PAGE_ALIGN(size); - new_block = qemu_malloc(sizeof(*new_block)); - - new_block->host = host; - - new_block->offset = ram_list.last_offset; - new_block->length = size; - - QLIST_INSERT_HEAD(&ram_list.blocks, new_block, next); - - ram_list.phys_dirty = qemu_realloc(ram_list.phys_dirty, - (ram_list.last_offset + size) >> TARGET_PAGE_BITS); - memset(ram_list.phys_dirty + (ram_list.last_offset >> TARGET_PAGE_BITS), - 0xff, size >> TARGET_PAGE_BITS); - - ram_list.last_offset += size; - - if (kvm_enabled()) - kvm_setup_guest_memory(new_block->host, size); - - return new_block->offset; -} - static ram_addr_t find_ram_offset(ram_addr_t size) { RAMBlock *block, *next_block; @@ -2851,6 +2824,49 @@ static ram_addr_t last_ram_offset(void) return last; } +ram_addr_t qemu_ram_map(DeviceState *dev, const char *name, + ram_addr_t size, void *host) +{ + RAMBlock *new_block, *block; + + size = TARGET_PAGE_ALIGN(size); + new_block = qemu_mallocz(sizeof(*new_block)); + + if (dev && dev->parent_bus && dev->parent_bus->info->get_dev_path) { + char *id = dev->parent_bus->info->get_dev_path(dev); + if (id) { + snprintf(new_block->idstr, sizeof(new_block->idstr), "%s/", id); + qemu_free(id); + } + } + pstrcat(new_block->idstr, sizeof(new_block->idstr), name); + + QLIST_FOREACH(block, &ram_list.blocks, next) { + if (!strcmp(block->idstr, new_block->idstr)) { + fprintf(stderr, "RAMBlock \"%s\" already registered, abort!\n", + new_block->idstr); + abort(); + } + } + + new_block->host = host; + + new_block->offset = find_ram_offset(size); + new_block->length = size; + + QLIST_INSERT_HEAD(&ram_list.blocks, new_block, next); + + ram_list.phys_dirty = qemu_realloc(ram_list.phys_dirty, + last_ram_offset() >> TARGET_PAGE_BITS); + memset(ram_list.phys_dirty + (new_block->offset >> TARGET_PAGE_BITS), + 0xff, size >> TARGET_PAGE_BITS); + + if (kvm_enabled()) + kvm_setup_guest_memory(new_block->host, size); + + return new_block->offset; +} + ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size) { RAMBlock *new_block, *block; @@ -2917,6 +2933,19 @@ ram_addr_t qemu_ram_alloc(DeviceState *dev, const char *name, ram_addr_t size) return new_block->offset; } +void qemu_ram_unmap(ram_addr_t addr) +{ + RAMBlock *block; + + QLIST_FOREACH(block, &ram_list.blocks, next) { + if (addr == block->offset) { + QLIST_REMOVE(block, next); + qemu_free(block); + return; + } + } +} + void qemu_ram_free(ram_addr_t addr) { RAMBlock *block; diff --git a/hw/device-assignment.c b/hw/device-assignment.c index 48ac73c..cbbf37f 100644 --- a/hw/device-assignment.c +++ b/hw/device-assignment.c @@ -571,9 +571,13 @@ static int assigned_dev_register_regions(PCIRegion *io_regions, if (!slow_map) { void *virtbase = pci_dev->v_addrs[i].u.r_virtbase; - - pci_dev->v_addrs[i].memory_index = qemu_ram_map(cur_region->size, - virtbase); + char name[32]; + snprintf(name, sizeof(name), "%s.bar%d", + pci_dev->dev.qdev.info->name, i); + pci_dev->v_addrs[i].memory_index = + qemu_ram_map(&pci_dev->dev.qdev, + name, cur_region->size, + virtbase); } else pci_dev->v_addrs[i].memory_index = 0; @@ -779,9 +783,14 @@ static void free_assigned_device(AssignedDevice *dev) continue; } else if (pci_region->type & IORESOURCE_MEM) { if (region->u.r_virtbase) { - int ret = munmap(region->u.r_virtbase, - (pci_region->size + 0xFFF) & 0xFFFFF000); - if (ret != 0) + if (region->memory_index) { + cpu_register_physical_memory(region->e_physbase, + region->e_size, + IO_MEM_UNASSIGNED); + qemu_ram_unmap(region->memory_index); + } + if (munmap(region->u.r_virtbase, + (pci_region->size + 0xFFF) & 0xFFFFF000)) fprintf(stderr, "Failed to unmap assigned device region: %s\n", strerror(errno)); diff --git a/hw/i8254-kvm.c b/hw/i8254-kvm.c index c62ab6a..6125213 100644 --- a/hw/i8254-kvm.c +++ b/hw/i8254-kvm.c @@ -114,7 +114,7 @@ PITState *kvm_pit_init(int base, qemu_irq irq) s->irq_timer = qemu_new_timer(vm_clock, dummy_timer, s); vmstate_pit.pre_save = kvm_pit_pre_save; vmstate_pit.post_load = kvm_pit_post_load; - vmstate_register(base, &vmstate_pit, pit); + vmstate_register(NULL, base, &vmstate_pit, pit); qemu_register_reset(pit_reset, pit); pit_reset(pit); diff --git a/hw/i8259.c b/hw/i8259.c index 70da847..11060d3 100644 --- a/hw/i8259.c +++ b/hw/i8259.c @@ -658,7 +658,7 @@ static void kvm_i8259_set_irq(void *opaque, int irq, int level) static void kvm_pic_init1(int io_addr, PicState *s) { - vmstate_register(io_addr, &vmstate_pic, s); + vmstate_register(NULL, io_addr, &vmstate_pic, s); qemu_register_reset(pic_reset, s); } diff --git a/kvm-tpr-opt.c b/kvm-tpr-opt.c index 429c2f4..46890e2 100644 --- a/kvm-tpr-opt.c +++ b/kvm-tpr-opt.c @@ -370,7 +370,7 @@ static void vtpr_ioport_write(void *opaque, uint32_t addr, uint32_t val) static void kvm_tpr_opt_setup(void) { - register_savevm("kvm-tpr-opt", 0, 1, tpr_save, tpr_load, NULL); + register_savevm(NULL, "kvm-tpr-opt", 0, 1, tpr_save, tpr_load, NULL); register_ioport_write(0x7e, 1, 1, vtpr_ioport_write, NULL); register_ioport_write(0x7e, 2, 2, vtpr_ioport_write16, NULL); } diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c index 403337a..fd426b7 100644 --- a/qemu-kvm-x86.c +++ b/qemu-kvm-x86.c @@ -598,7 +598,7 @@ int kvm_arch_qemu_create_context(void) #ifdef KVM_CAP_ADJUST_CLOCK if (kvm_check_extension(kvm_state, KVM_CAP_ADJUST_CLOCK)) - vmstate_register(0, &vmstate_kvmclock, &kvmclock_data); + vmstate_register(NULL, 0, &vmstate_kvmclock, &kvmclock_data); #endif r = kvm_set_boot_cpu_id(0);