From patchwork Fri Apr 23 17:04:12 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 94717 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 o3NH8okG014082 for ; Fri, 23 Apr 2010 17:09:14 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758391Ab0DWRIt (ORCPT ); Fri, 23 Apr 2010 13:08:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:17730 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758334Ab0DWRIq (ORCPT ); Fri, 23 Apr 2010 13:08:46 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o3NH8jmD005797 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 23 Apr 2010 13:08:45 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o3NH8iiY012502; Fri, 23 Apr 2010 13:08:44 -0400 Received: from amt.cnet (vpn-11-16.rdu.redhat.com [10.11.11.16]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o3NH8gW8010352; Fri, 23 Apr 2010 13:08:42 -0400 Received: from amt.cnet (amt.cnet [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id E3DE868A98D; Fri, 23 Apr 2010 14:07:54 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.3/8.14.3/Submit) id o3NH7slu000868; Fri, 23 Apr 2010 14:07:54 -0300 Message-Id: <20100423170645.675040544@amt.cnet> User-Agent: quilt/0.47-1 Date: Fri, 23 Apr 2010 14:04:12 -0300 From: Marcelo Tosatti To: kvm@vger.kernel.org Cc: qemu-devel@nongnu.org, Marcelo Tosatti Subject: [uq/master patch 2/5] kvm: add logging count to slots References: <20100423170410.914857113@amt.cnet> Content-Disposition: inline; filename=memslot-logging-count X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 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]); Fri, 23 Apr 2010 17:09:15 +0000 (UTC) Index: qemu-kvm/kvm-all.c =================================================================== --- qemu-kvm.orig/kvm-all.c +++ qemu-kvm/kvm-all.c @@ -47,6 +47,7 @@ typedef struct KVMSlot ram_addr_t phys_offset; int slot; int flags; + int logging_count; } KVMSlot; typedef struct kvm_dirty_log KVMDirtyLog; @@ -218,20 +219,11 @@ err: /* * dirty pages logging control */ -static int kvm_dirty_pages_log_change(target_phys_addr_t phys_addr, - ram_addr_t size, int flags, int mask) +static int kvm_dirty_pages_log_change(KVMSlot *mem, int flags, int mask) { KVMState *s = kvm_state; - KVMSlot *mem = kvm_lookup_matching_slot(s, phys_addr, phys_addr + size); int old_flags; - if (mem == NULL) { - fprintf(stderr, "BUG: %s: invalid parameters " TARGET_FMT_plx "-" - TARGET_FMT_plx "\n", __func__, phys_addr, - (target_phys_addr_t)(phys_addr + size - 1)); - return -EINVAL; - } - old_flags = mem->flags; flags = (mem->flags & ~mask) | flags; @@ -250,16 +242,42 @@ static int kvm_dirty_pages_log_change(ta int kvm_log_start(target_phys_addr_t phys_addr, ram_addr_t size) { - return kvm_dirty_pages_log_change(phys_addr, size, - KVM_MEM_LOG_DIRTY_PAGES, - KVM_MEM_LOG_DIRTY_PAGES); + KVMState *s = kvm_state; + KVMSlot *mem = kvm_lookup_matching_slot(s, phys_addr, phys_addr + size); + + if (mem == NULL) { + fprintf(stderr, "BUG: %s: invalid parameters " TARGET_FMT_plx "-" + TARGET_FMT_plx "\n", __func__, phys_addr, + (target_phys_addr_t)(phys_addr + size - 1)); + return -EINVAL; + } + + if (mem->logging_count++) + return 0; + + return kvm_dirty_pages_log_change(mem, + KVM_MEM_LOG_DIRTY_PAGES, + KVM_MEM_LOG_DIRTY_PAGES); } int kvm_log_stop(target_phys_addr_t phys_addr, ram_addr_t size) { - return kvm_dirty_pages_log_change(phys_addr, size, - 0, - KVM_MEM_LOG_DIRTY_PAGES); + KVMState *s = kvm_state; + KVMSlot *mem = kvm_lookup_matching_slot(s, phys_addr, phys_addr + size); + + if (mem == NULL) { + fprintf(stderr, "BUG: %s: invalid parameters " TARGET_FMT_plx "-" + TARGET_FMT_plx "\n", __func__, phys_addr, + (target_phys_addr_t)(phys_addr + size - 1)); + return -EINVAL; + } + + if (--mem->logging_count) + return 0; + + return kvm_dirty_pages_log_change(mem, + 0, + KVM_MEM_LOG_DIRTY_PAGES); } static int kvm_set_migration_log(int enable) @@ -273,12 +291,15 @@ static int kvm_set_migration_log(int ena for (i = 0; i < ARRAY_SIZE(s->slots); i++) { mem = &s->slots[i]; - if (!!(mem->flags & KVM_MEM_LOG_DIRTY_PAGES) == enable) { - continue; - } - err = kvm_set_user_memory_region(s, mem); - if (err) { - return err; + if (mem->memory_size) { + if (enable) { + err = kvm_log_start(mem->start_addr, mem->memory_size); + } else { + err = kvm_log_stop(mem->start_addr, mem->memory_size); + } + if (err) { + return err; + } } } return 0; @@ -442,6 +463,7 @@ static void kvm_set_phys_mem(target_phys /* unregister the overlapping slot */ mem->memory_size = 0; + mem->logging_count = 0; err = kvm_set_user_memory_region(s, mem); if (err) { fprintf(stderr, "%s: error unregistering overlapping slot: %s\n",