From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: [PATCH kvm-unit-tests v2 12/14] api: Add support for creating an identity map with a hole Date: Wed, 15 Dec 2010 18:09:41 +0200 Message-ID: <1292429383-15326-13-git-send-email-avi@redhat.com> References: <1292429383-15326-1-git-send-email-avi@redhat.com> To: Marcelo Tosatti , kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:10652 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752220Ab0LOQKI (ORCPT ); Wed, 15 Dec 2010 11:10:08 -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 oBFGA8si027140 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 15 Dec 2010 11:10:08 -0500 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id oBFGA4v7015653 for ; Wed, 15 Dec 2010 11:10:08 -0500 In-Reply-To: <1292429383-15326-1-git-send-email-avi@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: The hole may be used for mmio or dirty logging. Signed-off-by: Avi Kivity --- api/api-sample.cc | 3 ++- api/identity.cc | 23 +++++++++++++++++++++-- api/identity.hh | 17 ++++++++++++++++- config-x86-common.mak | 1 + 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/api/api-sample.cc b/api/api-sample.cc index 8d57c09..524ad7b 100644 --- a/api/api-sample.cc +++ b/api/api-sample.cc @@ -15,7 +15,8 @@ int test_main(int ac, char** av) { kvm::system system; kvm::vm vm(system); - identity::setup_vm(vm); + mem_map memmap(vm); + identity::vm ident_vm(vm, memmap); kvm::vcpu vcpu(vm, 0); identity::vcpu thread(vcpu, set_global); vcpu.run(); diff --git a/api/identity.cc b/api/identity.cc index de52f68..e04231b 100644 --- a/api/identity.cc +++ b/api/identity.cc @@ -6,9 +6,28 @@ namespace identity { typedef unsigned long ulong; -void setup_vm(kvm::vm& vm) +hole::hole() + : address(), size() { - vm.set_memory_region(0, NULL, 0, 3UL << 30); +} + +hole::hole(void* address, size_t size) + : address(address), size(size) +{ +} + +vm::vm(kvm::vm& vm, mem_map& mmap, hole h) +{ + uint64_t hole_gpa = reinterpret_cast(h.address); + char* hole_hva = static_cast(h.address); + if (h.address) { + _slots.push_back(mem_slot_ptr(new mem_slot(mmap, 0, hole_gpa, NULL))); + } + uint64_t hole_end = hole_gpa + h.size; + uint64_t end = 3U << 30; + _slots.push_back(mem_slot_ptr(new mem_slot(mmap, hole_end, + end - hole_end, + hole_hva + h.size))); vm.set_tss_addr(3UL << 30); } diff --git a/api/identity.hh b/api/identity.hh index 7401826..4491043 100644 --- a/api/identity.hh +++ b/api/identity.hh @@ -2,12 +2,27 @@ #define API_IDENTITY_HH #include "kvmxx.hh" +#include "memmap.hh" #include +#include #include namespace identity { -void setup_vm(kvm::vm& vm); +struct hole { + hole(); + hole(void* address, size_t size); + void* address; + size_t size; +}; + +class vm { +public: + vm(kvm::vm& vm, mem_map& mmap, hole address_space_hole = hole()); +private: + typedef std::tr1::shared_ptr mem_slot_ptr; + std::vector _slots; +}; class vcpu { public: diff --git a/config-x86-common.mak b/config-x86-common.mak index 3e8e641..436f4bd 100644 --- a/config-x86-common.mak +++ b/config-x86-common.mak @@ -89,3 +89,4 @@ api/api-sample: LDLIBS += -lstdc++ api/api-sample: LDFLAGS += -m32 api/api-sample: api/api-sample.o api/kvmxx.o api/identity.o api/exception.o +api/api-sample: api/memmap.o \ No newline at end of file -- 1.7.1