thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
0a122b
From f69bd1c99d908b9de5ba4f335a55597a3e8fd947 Mon Sep 17 00:00:00 2001
0a122b
Message-Id: <f69bd1c99d908b9de5ba4f335a55597a3e8fd947.1387276076.git.minovotn@redhat.com>
0a122b
In-Reply-To: <e610718166120379517e80d1a7aa12d60294209b.1387276076.git.minovotn@redhat.com>
0a122b
References: <e610718166120379517e80d1a7aa12d60294209b.1387276076.git.minovotn@redhat.com>
0a122b
From: Alex Williamson <alex.williamson@redhat.com>
0a122b
Date: Mon, 9 Dec 2013 17:52:56 +0100
0a122b
Subject: [PATCH 07/16] kvm: Query KVM for available memory slots
0a122b
0a122b
RH-Author: Alex Williamson <alex.williamson@redhat.com>
0a122b
Message-id: <20131209175223.22125.66085.stgit@bling.home>
0a122b
Patchwork-id: 56092
0a122b
O-Subject: [RHEL7 qemu-kvm PATCH] kvm: Query KVM for available memory slots
0a122b
Bugzilla: 921490
0a122b
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
RH-Acked-by: Eduardo Habkost <ehabkost@redhat.com>
0a122b
RH-Acked-by: Bandan Das <bsd@redhat.com>
0a122b
RH-Acked-by: Amos Kong <akong@redhat.com>
0a122b
0a122b
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=921490
0a122b
Brew: http://brewweb.devel.redhat.com/brew/taskinfo?taskID=6696277
0a122b
Upstream: fb541ca59c8b55911821c9f794c3dbe5de9ba9d8
0a122b
0a122b
KVM reports the number of available memory slots (KVM_CAP_NR_MEMSLOTS)
0a122b
using the extension interface.  Both x86 and s390 implement this, ARM
0a122b
and powerpc do not yet enable it.  Convert the static slots array to
0a122b
be dynamically allocated, supporting more slots when available.
0a122b
Default to 32 when KVM_CAP_NR_MEMSLOTS is not implemented.  The
0a122b
motivation for this change is to support more assigned devices, where
0a122b
memory mapped PCI MMIO BARs typically take one slot each.
0a122b
0a122b
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
0a122b
Reviewed-by: Thomas Huth <thuth@linux.vnet.ibm.com>
0a122b
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
0a122b
---
0a122b
 kvm-all.c |   30 +++++++++++++++++++++---------
0a122b
 1 file changed, 21 insertions(+), 9 deletions(-)
0a122b
0a122b
Signed-off-by: Michal Novotny <minovotn@redhat.com>
0a122b
---
0a122b
 kvm-all.c | 30 +++++++++++++++++++++---------
0a122b
 1 file changed, 21 insertions(+), 9 deletions(-)
0a122b
0a122b
diff --git a/kvm-all.c b/kvm-all.c
0a122b
index f2f68d6..0e21494 100644
0a122b
--- a/kvm-all.c
0a122b
+++ b/kvm-all.c
0a122b
@@ -72,7 +72,8 @@ typedef struct kvm_dirty_log KVMDirtyLog;
0a122b
 
0a122b
 struct KVMState
0a122b
 {
0a122b
-    KVMSlot slots[32];
0a122b
+    KVMSlot *slots;
0a122b
+    int nr_slots;
0a122b
     int fd;
0a122b
     int vmfd;
0a122b
     int coalesced_mmio;
0a122b
@@ -122,7 +123,7 @@ static KVMSlot *kvm_alloc_slot(KVMState *s)
0a122b
 {
0a122b
     int i;
0a122b
 
0a122b
-    for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
0a122b
+    for (i = 0; i < s->nr_slots; i++) {
0a122b
         if (s->slots[i].memory_size == 0) {
0a122b
             return &s->slots[i];
0a122b
         }
0a122b
@@ -138,7 +139,7 @@ static KVMSlot *kvm_lookup_matching_slot(KVMState *s,
0a122b
 {
0a122b
     int i;
0a122b
 
0a122b
-    for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
0a122b
+    for (i = 0; i < s->nr_slots; i++) {
0a122b
         KVMSlot *mem = &s->slots[i];
0a122b
 
0a122b
         if (start_addr == mem->start_addr &&
0a122b
@@ -160,7 +161,7 @@ static KVMSlot *kvm_lookup_overlapping_slot(KVMState *s,
0a122b
     KVMSlot *found = NULL;
0a122b
     int i;
0a122b
 
0a122b
-    for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
0a122b
+    for (i = 0; i < s->nr_slots; i++) {
0a122b
         KVMSlot *mem = &s->slots[i];
0a122b
 
0a122b
         if (mem->memory_size == 0 ||
0a122b
@@ -182,7 +183,7 @@ int kvm_physical_memory_addr_from_host(KVMState *s, void *ram,
0a122b
 {
0a122b
     int i;
0a122b
 
0a122b
-    for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
0a122b
+    for (i = 0; i < s->nr_slots; i++) {
0a122b
         KVMSlot *mem = &s->slots[i];
0a122b
 
0a122b
         if (ram >= mem->ram && ram < mem->ram + mem->memory_size) {
0a122b
@@ -342,7 +343,7 @@ static int kvm_set_migration_log(int enable)
0a122b
 
0a122b
     s->migration_log = enable;
0a122b
 
0a122b
-    for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
0a122b
+    for (i = 0; i < s->nr_slots; i++) {
0a122b
         mem = &s->slots[i];
0a122b
 
0a122b
         if (!mem->memory_size) {
0a122b
@@ -1328,9 +1329,6 @@ int kvm_init(void)
0a122b
 #ifdef KVM_CAP_SET_GUEST_DEBUG
0a122b
     QTAILQ_INIT(&s->kvm_sw_breakpoints);
0a122b
 #endif
0a122b
-    for (i = 0; i < ARRAY_SIZE(s->slots); i++) {
0a122b
-        s->slots[i].slot = i;
0a122b
-    }
0a122b
     s->vmfd = -1;
0a122b
     s->fd = qemu_open("/dev/kvm", O_RDWR);
0a122b
     if (s->fd == -1) {
0a122b
@@ -1354,6 +1352,19 @@ int kvm_init(void)
0a122b
         goto err;
0a122b
     }
0a122b
 
0a122b
+    s->nr_slots = kvm_check_extension(s, KVM_CAP_NR_MEMSLOTS);
0a122b
+
0a122b
+    /* If unspecified, use the default value */
0a122b
+    if (!s->nr_slots) {
0a122b
+        s->nr_slots = 32;
0a122b
+    }
0a122b
+
0a122b
+    s->slots = g_malloc0(s->nr_slots * sizeof(KVMSlot));
0a122b
+
0a122b
+    for (i = 0; i < s->nr_slots; i++) {
0a122b
+        s->slots[i].slot = i;
0a122b
+    }
0a122b
+
0a122b
     /* check the vcpu limits */
0a122b
     soft_vcpus_limit = kvm_recommended_vcpus(s);
0a122b
     hard_vcpus_limit = kvm_max_vcpus(s);
0a122b
@@ -1467,6 +1478,7 @@ err:
0a122b
     if (s->fd != -1) {
0a122b
         close(s->fd);
0a122b
     }
0a122b
+    g_free(s->slots);
0a122b
     g_free(s);
0a122b
 
0a122b
     return ret;
0a122b
-- 
0a122b
1.7.11.7
0a122b