qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, lersek@redhat.com,
	avi.kivity@gmail.com, kraxel@redhat.com
Subject: [Qemu-devel] [PATCH 4/7] kvm-all: add KVM address space
Date: Fri, 15 May 2015 18:37:00 +0200	[thread overview]
Message-ID: <1431707823-51230-5-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1431707823-51230-1-git-send-email-pbonzini@redhat.com>

Until now, KVM_SET_USER_MEMORY_REGION has been working on
address_space_memory.  However, KVM's memory slots are the
CPU view of the memory, which does not exactly match
address_space_memory.

Let the architecture-specific code build the CPU view of the
memory by combining address_space_memory and other MemoryRegions.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 include/sysemu/kvm_int.h |  3 +++
 kvm-all.c                | 21 ++++++++++++++++++---
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/include/sysemu/kvm_int.h b/include/sysemu/kvm_int.h
index d5f746f..5e4090d 100644
--- a/include/sysemu/kvm_int.h
+++ b/include/sysemu/kvm_int.h
@@ -60,6 +60,9 @@ struct KVMState
     QTAILQ_HEAD(msi_hashtab, KVMMSIRoute) msi_hashtab[KVM_MSI_HASHTAB_SIZE];
     bool direct_msi;
 #endif
+
+    AddressSpace kvm_as;
+    MemoryRegion kvm_as_root, kvm_as_mem;
 };
 
 #define TYPE_KVM_ACCEL ACCEL_CLASS_NAME("kvm")
diff --git a/kvm-all.c b/kvm-all.c
index 215ed33..c70436e 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1401,6 +1401,7 @@ static int kvm_init(MachineState *ms)
     const char *kvm_type;
 
     s = KVM_STATE(ms->accelerator);
+    kvm_state = s;
 
     /*
      * On systems where the kernel can support different base page
@@ -1578,9 +1579,21 @@ static int kvm_init(MachineState *ms)
     kvm_vm_attributes_allowed =
         (kvm_check_extension(s, KVM_CAP_VM_ATTRIBUTES) > 0);
 
+    /* An outer container, with normal system memory inside.
+     * kvm_arch_init can add more.
+     */
+    memory_region_init(&s->kvm_as_root, OBJECT(s), "mem-container", ~0ull);
+    memory_region_set_enabled(&s->kvm_as_root, true);
+    memory_region_init_alias(&s->kvm_as_mem, OBJECT(s), "memory",
+                             get_system_memory(), 0, ~0ull);
+    memory_region_set_enabled(&s->kvm_as_mem, true);
+    memory_region_add_subregion_overlap(&s->kvm_as_root, 0, &s->kvm_as_mem, 0);
+
+    address_space_init(&s->kvm_as, &s->kvm_as_root, "KVM");
+
     ret = kvm_arch_init(ms, s);
     if (ret < 0) {
-        goto err;
+        goto err_as_destroy;
     }
 
     ret = kvm_irqchip_create(ms, s);
@@ -1588,8 +1601,7 @@ static int kvm_init(MachineState *ms)
         goto err;
     }
 
-    kvm_state = s;
-    memory_listener_register(&kvm_memory_listener, &address_space_memory);
+    memory_listener_register(&kvm_memory_listener, &s->kvm_as);
     memory_listener_register(&kvm_io_listener, &address_space_io);
 
     s->many_ioeventfds = kvm_check_many_ioeventfds();
@@ -1598,6 +1610,8 @@ static int kvm_init(MachineState *ms)
 
     return 0;
 
+err_as_destroy:
+    address_space_destroy(&s->kvm_as);
 err:
     assert(ret < 0);
     if (s->vmfd >= 0) {
@@ -1607,6 +1621,7 @@ err:
         close(s->fd);
     }
     g_free(s->slots);
+    kvm_state = NULL;
 
     return ret;
 }
-- 
1.8.3.1

  parent reply	other threads:[~2015-05-15 16:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-15 16:36 [Qemu-devel] [RFC PATCH 0/7] x86: SMRAM implementation for KVM Paolo Bonzini
2015-05-15 16:36 ` [Qemu-devel] [PATCH 1/7] kvm-all: put kvm_mem_flags to more work Paolo Bonzini
2015-05-15 16:36 ` [Qemu-devel] [PATCH 2/7] kvm-all: remove useless typedef Paolo Bonzini
2015-05-15 16:36 ` [Qemu-devel] [PATCH 3/7] kvm-all: move KVMState definitions to kvm_int.h Paolo Bonzini
2015-05-15 16:37 ` Paolo Bonzini [this message]
2015-05-15 16:37 ` [Qemu-devel] [PATCH 5/7] memory: add kvm_mem_flags to MemoryRegion Paolo Bonzini
2015-05-15 16:37 ` [Qemu-devel] [PATCH 6/7] i386: disable the region in /machine/smram when SMRAM is open Paolo Bonzini
2015-05-15 16:37 ` [Qemu-devel] [PATCH 7/7] kvm-i386: register SMRAM regions with KVM_MEM_X86_SMRAM Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1431707823-51230-5-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=avi.kivity@gmail.com \
    --cc=kraxel@redhat.com \
    --cc=lersek@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).