From patchwork Mon Jan 25 14:29:36 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 43635 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 0F9DC1007D2 for ; Tue, 26 Jan 2010 01:44:01 +1100 (EST) Received: from localhost ([127.0.0.1]:35212 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NZQAD-0002h6-QJ for incoming@patchwork.ozlabs.org; Mon, 25 Jan 2010 09:43:37 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NZPzn-0001on-LP for qemu-devel@nongnu.org; Mon, 25 Jan 2010 09:32:51 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NZPzi-0001lF-V8 for qemu-devel@nongnu.org; Mon, 25 Jan 2010 09:32:51 -0500 Received: from [199.232.76.173] (port=46286 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NZPzi-0001l6-O8 for qemu-devel@nongnu.org; Mon, 25 Jan 2010 09:32:46 -0500 Received: from mx20.gnu.org ([199.232.41.8]:64994) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NZPzh-0003E5-UQ for qemu-devel@nongnu.org; Mon, 25 Jan 2010 09:32:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NZPzh-0003wg-4y for qemu-devel@nongnu.org; Mon, 25 Jan 2010 09:32:45 -0500 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 o0PEWgXN026399 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 25 Jan 2010 09:32:42 -0500 Received: from redhat.com (vpn1-4-210.ams2.redhat.com [10.36.4.210]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id o0PEWeUJ017769; Mon, 25 Jan 2010 09:32:41 -0500 Date: Mon, 25 Jan 2010 16:29:36 +0200 From: "Michael S. Tsirkin" To: Anthony Liguori , qemu-devel@nongnu.org, avi@redhat.com, gleb@redhat.com Message-ID: <20100125142936.GD11154@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.19 (2009-01-05) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by mx20.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Subject: [Qemu-devel] [PATCHv2-repost 3/3] kvm: move kvm to use memory notifiers 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 remove direct kvm calls from exec.c, make kvm use memory notifiers framework instead. Signed-off-by: Michael S. Tsirkin Acked-by: Avi Kivity --- exec.c | 17 +---------------- kvm-all.c | 40 ++++++++++++++++++++++++++++++++++------ kvm.h | 8 -------- 3 files changed, 35 insertions(+), 30 deletions(-) diff --git a/exec.c b/exec.c index 56c347b..8a1c08e 100644 --- a/exec.c +++ b/exec.c @@ -1977,12 +1977,6 @@ int cpu_physical_memory_set_dirty_tracking(int enable) { int ret = 0; in_migration = enable; - if (kvm_enabled()) { - ret = kvm_set_migration_log(enable); - } - if (ret < 0) { - return ret; - } ret = cpu_notify_migration_log(!!enable); return ret; } @@ -1995,14 +1989,8 @@ int cpu_physical_memory_get_dirty_tracking(void) int cpu_physical_sync_dirty_bitmap(target_phys_addr_t start_addr, target_phys_addr_t end_addr) { - int ret = 0; + int ret; - if (kvm_enabled()) { - ret = kvm_physical_sync_dirty_bitmap(start_addr, end_addr); - } - if (ret < 0) { - return ret; - } ret = cpu_notify_sync_dirty_bitmap(start_addr, end_addr); return ret; } @@ -2415,9 +2403,6 @@ void cpu_register_physical_memory_offset(target_phys_addr_t start_addr, ram_addr_t orig_size = size; void *subpage; - if (kvm_enabled()) - kvm_set_phys_mem(start_addr, size, phys_offset); - cpu_notify_set_memory(start_addr, size, phys_offset); if (phys_offset == IO_MEM_UNASSIGNED) { diff --git a/kvm-all.c b/kvm-all.c index 4efb653..a312654 100644 --- a/kvm-all.c +++ b/kvm-all.c @@ -257,7 +257,7 @@ int kvm_log_stop(target_phys_addr_t phys_addr, ram_addr_t size) KVM_MEM_LOG_DIRTY_PAGES); } -int kvm_set_migration_log(int enable) +static int kvm_set_migration_log(int enable) { KVMState *s = kvm_state; KVMSlot *mem; @@ -292,8 +292,8 @@ static int test_le_bit(unsigned long nr, unsigned char *addr) * @start_add: start of logged region. * @end_addr: end of logged region. */ -int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr, - target_phys_addr_t end_addr) +static int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr, + target_phys_addr_t end_addr) { KVMState *s = kvm_state; unsigned long size, allocated_size = 0; @@ -394,9 +394,9 @@ int kvm_check_extension(KVMState *s, unsigned int extension) return ret; } -void kvm_set_phys_mem(target_phys_addr_t start_addr, - ram_addr_t size, - ram_addr_t phys_offset) +static void kvm_set_phys_mem(target_phys_addr_t start_addr, + ram_addr_t size, + ram_addr_t phys_offset) { KVMState *s = kvm_state; ram_addr_t flags = phys_offset & ~TARGET_PAGE_MASK; @@ -532,6 +532,33 @@ void kvm_set_phys_mem(target_phys_addr_t start_addr, } } +static void kvm_client_set_memory(struct CPUPhysMemoryClient *client, + target_phys_addr_t start_addr, + ram_addr_t size, + ram_addr_t phys_offset) +{ + kvm_set_phys_mem(start_addr, size, phys_offset); +} + +static int kvm_client_sync_dirty_bitmap(struct CPUPhysMemoryClient *client, + target_phys_addr_t start_addr, + target_phys_addr_t end_addr) +{ + return kvm_physical_sync_dirty_bitmap(start_addr, end_addr); +} + +static int kvm_client_migration_log(struct CPUPhysMemoryClient *client, + int enable) +{ + return kvm_set_migration_log(enable); +} + +static CPUPhysMemoryClient kvm_cpu_phys_memory_client = { + .set_memory = kvm_client_set_memory, + .sync_dirty_bitmap = kvm_client_sync_dirty_bitmap, + .migration_log = kvm_client_migration_log, +}; + int kvm_init(int smp_cpus) { static const char upgrade_note[] = @@ -628,6 +655,7 @@ int kvm_init(int smp_cpus) goto err; kvm_state = s; + cpu_register_phys_memory_client(&kvm_cpu_phys_memory_client); return 0; diff --git a/kvm.h b/kvm.h index 1c93ac5..672d511 100644 --- a/kvm.h +++ b/kvm.h @@ -35,16 +35,8 @@ int kvm_init_vcpu(CPUState *env); int kvm_cpu_exec(CPUState *env); -void kvm_set_phys_mem(target_phys_addr_t start_addr, - ram_addr_t size, - ram_addr_t phys_offset); - -int kvm_physical_sync_dirty_bitmap(target_phys_addr_t start_addr, - target_phys_addr_t end_addr); - int kvm_log_start(target_phys_addr_t phys_addr, ram_addr_t size); int kvm_log_stop(target_phys_addr_t phys_addr, ram_addr_t size); -int kvm_set_migration_log(int enable); int kvm_has_sync_mmu(void); int kvm_has_vcpu_events(void);