From patchwork Mon May 3 22:48:20 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 96585 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o43Mv71Q031888 for ; Mon, 3 May 2010 22:57:07 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759581Ab0ECW5B (ORCPT ); Mon, 3 May 2010 18:57:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38434 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756121Ab0ECW46 (ORCPT ); Mon, 3 May 2010 18:56:58 -0400 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o43MuvoF030054 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 3 May 2010 18:56:57 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o43MuuAJ007134; Mon, 3 May 2010 18:56:56 -0400 Received: from amt.cnet (vpn-8-8.rdu.redhat.com [10.11.8.8]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o43MusGn006969; Mon, 3 May 2010 18:56:55 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 22258656077; Mon, 3 May 2010 19:56:02 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id o43Mu0kR026873; Mon, 3 May 2010 19:56:00 -0300 Message-Id: <20100503224905.127715840@amt.cnet> User-Agent: quilt/0.47-1 Date: Mon, 03 May 2010 19:48:20 -0300 From: Marcelo Tosatti To: kvm@vger.kernel.org Cc: avi@redhat.com, jan.kiszka@web.de, Marcelo Tosatti Subject: [patch 1/6] remove alias support References: <20100503224819.773169076@amt.cnet> Content-Disposition: inline; filename=remove-alias-support X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 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]); Mon, 03 May 2010 22:57:07 +0000 (UTC) Index: qemu-kvm/qemu-kvm.c =================================================================== --- qemu-kvm.orig/qemu-kvm.c +++ qemu-kvm/qemu-kvm.c @@ -1076,20 +1076,6 @@ int kvm_deassign_pci_device(kvm_context_ } #endif -int kvm_destroy_memory_region_works(kvm_context_t kvm) -{ - int ret = 0; - -#ifdef KVM_CAP_DESTROY_MEMORY_REGION_WORKS - ret = - kvm_ioctl(kvm_state, KVM_CHECK_EXTENSION, - KVM_CAP_DESTROY_MEMORY_REGION_WORKS); - if (ret <= 0) - ret = 0; -#endif - return ret; -} - int kvm_reinject_control(kvm_context_t kvm, int pit_reinject) { #ifdef KVM_CAP_REINJECT_CONTROL @@ -2055,11 +2041,6 @@ int kvm_main_loop(void) return 0; } -#ifdef TARGET_I386 -static int destroy_region_works = 0; -#endif - - #if !defined(TARGET_I386) int kvm_arch_init_irq_routing(void) { @@ -2071,6 +2052,10 @@ extern int no_hpet; static int kvm_create_context(void) { + static const char upgrade_note[] = + "Please upgrade to at least kernel 2.6.29 or recent kvm-kmod\n" + "(see http://sourceforge.net/projects/kvm).\n"; + int r; if (!kvm_irqchip) { @@ -2094,9 +2079,16 @@ static int kvm_create_context(void) return -1; } } -#ifdef TARGET_I386 - destroy_region_works = kvm_destroy_memory_region_works(kvm_context); -#endif + + /* There was a nasty bug in < kvm-80 that prevents memory slots from being + * destroyed properly. Since we rely on this capability, refuse to work + * with any kernel without this capability. */ + if (!kvm_check_extension(kvm_state, KVM_CAP_DESTROY_MEMORY_REGION_WORKS)) { + fprintf(stderr, + "KVM kernel module broken (DESTROY_MEMORY_REGION).\n%s", + upgrade_note); + return -EINVAL; + } r = kvm_arch_init_irq_routing(); if (r < 0) { @@ -2134,73 +2126,11 @@ static int kvm_create_context(void) return 0; } -#ifdef TARGET_I386 -static int must_use_aliases_source(target_phys_addr_t addr) -{ - if (destroy_region_works) - return false; - if (addr == 0xa0000 || addr == 0xa8000) - return true; - return false; -} - -static int must_use_aliases_target(target_phys_addr_t addr) -{ - if (destroy_region_works) - return false; - if (addr >= 0xe0000000 && addr < 0x100000000ull) - return true; - return false; -} - -static struct mapping { - target_phys_addr_t phys; - ram_addr_t ram; - ram_addr_t len; -} mappings[50]; -static int nr_mappings; - -static struct mapping *find_ram_mapping(ram_addr_t ram_addr) -{ - struct mapping *p; - - for (p = mappings; p < mappings + nr_mappings; ++p) { - if (p->ram <= ram_addr && ram_addr < p->ram + p->len) { - return p; - } - } - return NULL; -} - -static struct mapping *find_mapping(target_phys_addr_t start_addr) -{ - struct mapping *p; - - for (p = mappings; p < mappings + nr_mappings; ++p) { - if (p->phys <= start_addr && start_addr < p->phys + p->len) { - return p; - } - } - return NULL; -} - -static void drop_mapping(target_phys_addr_t start_addr) -{ - struct mapping *p = find_mapping(start_addr); - - if (p) - *p = mappings[--nr_mappings]; -} -#endif - void kvm_set_phys_mem(target_phys_addr_t start_addr, ram_addr_t size, ram_addr_t phys_offset) { int r = 0; unsigned long area_flags; -#ifdef TARGET_I386 - struct mapping *p; -#endif if (start_addr + size > phys_ram_size) { phys_ram_size = start_addr + size; @@ -2210,19 +2140,13 @@ void kvm_set_phys_mem(target_phys_addr_t area_flags = phys_offset & ~TARGET_PAGE_MASK; if (area_flags != IO_MEM_RAM) { -#ifdef TARGET_I386 - if (must_use_aliases_source(start_addr)) { - kvm_destroy_memory_alias(kvm_context, start_addr); - return; - } - if (must_use_aliases_target(start_addr)) - return; -#endif while (size > 0) { - p = find_mapping(start_addr); - if (p) { - kvm_unregister_memory_area(kvm_context, p->phys, p->len); - drop_mapping(p->phys); + int slot; + + slot = get_slot(start_addr); + if (slot != -1) { + kvm_unregister_memory_area(kvm_context, slots[slot].phys_addr, + slots[slot].len); } start_addr += TARGET_PAGE_SIZE; if (size > TARGET_PAGE_SIZE) { @@ -2241,30 +2165,12 @@ void kvm_set_phys_mem(target_phys_addr_t if (area_flags >= TLB_MMIO) return; -#ifdef TARGET_I386 - if (must_use_aliases_source(start_addr)) { - p = find_ram_mapping(phys_offset); - if (p) { - kvm_create_memory_alias(kvm_context, start_addr, size, - p->phys + (phys_offset - p->ram)); - } - return; - } -#endif - r = kvm_register_phys_mem(kvm_context, start_addr, qemu_get_ram_ptr(phys_offset), size, 0); if (r < 0) { printf("kvm_cpu_register_physical_memory: failed\n"); exit(1); } -#ifdef TARGET_I386 - drop_mapping(start_addr); - p = &mappings[nr_mappings++]; - p->phys = start_addr; - p->ram = phys_offset; - p->len = size; -#endif return; } @@ -2342,10 +2248,6 @@ void kvm_qemu_log_memory(target_phys_add if (log) kvm_dirty_pages_log_enable_slot(kvm_context, start, size); else { -#ifdef TARGET_I386 - if (must_use_aliases_target(start)) - return; -#endif kvm_dirty_pages_log_disable_slot(kvm_context, start, size); } } @@ -2418,12 +2320,6 @@ int kvm_physical_sync_dirty_bitmap(targe target_phys_addr_t end_addr) { #ifndef TARGET_IA64 - -#ifdef TARGET_I386 - if (must_use_aliases_source(start_addr)) - return 0; -#endif - kvm_get_dirty_pages_range(kvm_context, start_addr, end_addr - start_addr, NULL, kvm_get_dirty_bitmap_cb); @@ -2433,11 +2329,6 @@ int kvm_physical_sync_dirty_bitmap(targe int kvm_log_start(target_phys_addr_t phys_addr, ram_addr_t len) { -#ifdef TARGET_I386 - if (must_use_aliases_source(phys_addr)) - return 0; -#endif - #ifndef TARGET_IA64 kvm_qemu_log_memory(phys_addr, len, 1); #endif @@ -2446,11 +2337,6 @@ int kvm_log_start(target_phys_addr_t phy int kvm_log_stop(target_phys_addr_t phys_addr, ram_addr_t len) { -#ifdef TARGET_I386 - if (must_use_aliases_source(phys_addr)) - return 0; -#endif - #ifndef TARGET_IA64 kvm_qemu_log_memory(phys_addr, len, 0); #endif Index: qemu-kvm/qemu-kvm-x86.c =================================================================== --- qemu-kvm.orig/qemu-kvm-x86.c +++ qemu-kvm/qemu-kvm-x86.c @@ -214,71 +214,6 @@ int kvm_arch_run(CPUState *env) return r; } -#define MAX_ALIAS_SLOTS 4 -static struct { - uint64_t start; - uint64_t len; -} kvm_aliases[MAX_ALIAS_SLOTS]; - -static int get_alias_slot(uint64_t start) -{ - int i; - - for (i=0; i