From patchwork Thu Nov 22 15:58:14 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 1784231 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 3CF3B3FCAE for ; Thu, 22 Nov 2012 18:31:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752805Ab2KVSao (ORCPT ); Thu, 22 Nov 2012 13:30:44 -0500 Received: from cam-admin0.cambridge.arm.com ([217.140.96.50]:52264 "EHLO cam-admin0.cambridge.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752803Ab2KVSak (ORCPT ); Thu, 22 Nov 2012 13:30:40 -0500 Received: from mudshark.cambridge.arm.com (mudshark.cambridge.arm.com [10.1.79.58]) by cam-admin0.cambridge.arm.com (8.12.6/8.12.6) with ESMTP id qAMFwK53000652; Thu, 22 Nov 2012 15:58:20 GMT Received: by mudshark.cambridge.arm.com (Postfix, from userid 1000) id 2020CC2B14; Thu, 22 Nov 2012 15:58:19 +0000 (GMT) From: Will Deacon To: kvm@vger.kernel.org Cc: penberg@kernel.org, marc.zyngier@arm.com, c.dall@virtualopensystems.com, matt@ozlabs.org, peter.maydell@linaro.org, michael@ellerman.id.au, levinsasha928@gmail.com, kvmarm@lists.cs.columbia.edu, Will Deacon Subject: [PATCH v2 5/8] kvm tools: keep track of registered memory banks in struct kvm Date: Thu, 22 Nov 2012 15:58:14 +0000 Message-Id: <1353599897-15656-6-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 1.8.0 In-Reply-To: <1353599897-15656-1-git-send-email-will.deacon@arm.com> References: <1353599897-15656-1-git-send-email-will.deacon@arm.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org When registering memory banks for a guest, it is useful to keep the range information around for translating between guest and host address spaces. This patch adds a list of kvm_mem_bank structures to struct kvm, which is updated when a new bank is registered. Signed-off-by: Will Deacon --- tools/kvm/include/kvm/kvm.h | 8 ++++++++ tools/kvm/kvm.c | 23 ++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h index cf959ea..9b4a9a4 100644 --- a/tools/kvm/include/kvm/kvm.h +++ b/tools/kvm/include/kvm/kvm.h @@ -35,6 +35,13 @@ struct kvm_ext { int code; }; +struct kvm_mem_bank { + struct list_head list; + u64 guest_phys_addr; + void *host_addr; + u64 size; +}; + struct kvm { struct kvm_arch arch; struct kvm_config cfg; @@ -49,6 +56,7 @@ struct kvm { u64 ram_size; void *ram_start; u64 ram_pagesize; + struct list_head mem_banks; bool nmi_disabled; diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c index b283171..1a10ec0 100644 --- a/tools/kvm/kvm.c +++ b/tools/kvm/kvm.c @@ -6,7 +6,9 @@ #include "kvm/kvm-cpu.h" #include "kvm/kvm-ipc.h" +#include #include +#include #include #include @@ -133,9 +135,16 @@ struct kvm *kvm__new(void) int kvm__exit(struct kvm *kvm) { + struct kvm_mem_bank *bank, *tmp; + kvm__arch_delete_ram(kvm); - free(kvm); + list_for_each_entry_safe(bank, tmp, &kvm->mem_banks, list) { + list_del(&bank->list); + free(bank); + } + + free(kvm); return 0; } core_exit(kvm__exit); @@ -148,8 +157,18 @@ core_exit(kvm__exit); int kvm__register_mem(struct kvm *kvm, u64 guest_phys, u64 size, void *userspace_addr) { struct kvm_userspace_memory_region mem; + struct kvm_mem_bank *bank; int ret; + bank = malloc(sizeof(*bank)); + if (!bank) + return -ENOMEM; + + INIT_LIST_HEAD(&bank->list); + bank->guest_phys_addr = guest_phys; + bank->host_addr = userspace_addr; + bank->size = size; + mem = (struct kvm_userspace_memory_region) { .slot = kvm->mem_slots++, .guest_phys_addr = guest_phys, @@ -161,6 +180,7 @@ int kvm__register_mem(struct kvm *kvm, u64 guest_phys, u64 size, void *userspace if (ret < 0) return -errno; + list_add(&bank->list, &kvm->mem_banks); return 0; } @@ -245,6 +265,7 @@ int kvm__init(struct kvm *kvm) kvm__arch_init(kvm, kvm->cfg.hugetlbfs_path, kvm->cfg.ram_size); + INIT_LIST_HEAD(&kvm->mem_banks); kvm__init_ram(kvm); if (!kvm->cfg.firmware_filename) {