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: 50850 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 76999B7D2B for ; Sat, 24 Apr 2010 03:19:36 +1000 (EST) Received: from localhost ([127.0.0.1]:38708 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O5MXN-0000Mc-3h for incoming@patchwork.ozlabs.org; Fri, 23 Apr 2010 13:19:33 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O5MN4-0006kD-Rd for qemu-devel@nongnu.org; Fri, 23 Apr 2010 13:08:55 -0400 Received: from [140.186.70.92] (port=53502 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O5MN1-0006hD-W1 for qemu-devel@nongnu.org; Fri, 23 Apr 2010 13:08:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O5MMw-0002WJ-Bl for qemu-devel@nongnu.org; Fri, 23 Apr 2010 13:08:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38111) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O5MMw-0002Vn-4V for qemu-devel@nongnu.org; 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 References: <20100423170410.914857113@amt.cnet> Content-Disposition: inline; filename=memslot-logging-count X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Marcelo Tosatti , qemu-devel@nongnu.org Subject: [Qemu-devel] [uq/master patch 2/5] kvm: add logging count to slots X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Otherwise there is no way to differentiate between global and slot specific logging, so for example vga dirty log start migration start migration fail Disables dirty logging for the vga slot. Signed-off-by: Marcelo Tosatti 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",