9ae3a8
From 63d9ae740b30071f01c5fd1196f077b635491530 Mon Sep 17 00:00:00 2001
9ae3a8
From: Markus Armbruster <armbru@redhat.com>
9ae3a8
Date: Tue, 6 Aug 2013 13:17:03 +0200
9ae3a8
Subject: [PATCH 10/28] Fix -machine options accel, kernel_irqchip, kvm_shadow_mem
9ae3a8
9ae3a8
RH-Author: Markus Armbruster <armbru@redhat.com>
9ae3a8
Message-id: <1375795025-28674-5-git-send-email-armbru@redhat.com>
9ae3a8
Patchwork-id: 52993
9ae3a8
O-Subject: [PATCH 7.0 qemu-kvm 4/6] Fix -machine options accel, kernel_irqchip, kvm_shadow_mem
9ae3a8
Bugzilla: 980782
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Michal Novotny <minovotn@redhat.com>
9ae3a8
RH-Acked-by: Orit Wasserman <owasserm@redhat.com>
9ae3a8
9ae3a8
Multiple -machine options with the same ID are merged.  All but the
9ae3a8
one without an ID are to be silently ignored.
9ae3a8
9ae3a8
In most places, we query these options with a null ID.  This is
9ae3a8
correct.
9ae3a8
9ae3a8
In some places, we instead query whatever options come first in the
9ae3a8
list.  This is wrong.  When the -machine processed first happens to
9ae3a8
have an ID, options are taken from that ID, and the ones specified
9ae3a8
without ID are silently ignored.
9ae3a8
9ae3a8
Example:
9ae3a8
9ae3a8
    $ upstream-qemu -nodefaults -S -display none -monitor stdio -machine id=foo -machine accel=kvm,usb=on
9ae3a8
    $ upstream-qemu -nodefaults -S -display none -monitor stdio -machine id=foo,accel=kvm,usb=on -machine accel=xen
9ae3a8
    $ upstream-qemu -nodefaults -S -display none -monitor stdio -machine accel=xen -machine id=foo,accel=kvm,usb=on
9ae3a8
9ae3a8
    $ qemu-system-x86_64 -nodefaults -S -display none -monitor stdio -machine accel=kvm,usb=on
9ae3a8
    QEMU 1.5.50 monitor - type 'help' for more information
9ae3a8
    (qemu) info kvm
9ae3a8
    kvm support: enabled
9ae3a8
    (qemu) info usb
9ae3a8
    (qemu) q
9ae3a8
    $ qemu-system-x86_64 -nodefaults -S -display none -monitor stdio -machine id=foo -machine accel=kvm,usb=on
9ae3a8
    QEMU 1.5.50 monitor - type 'help' for more information
9ae3a8
    (qemu) info kvm
9ae3a8
    kvm support: disabled
9ae3a8
    (qemu) info usb
9ae3a8
    (qemu) q
9ae3a8
    $ qemu-system-x86_64 -nodefaults -S -display none -monitor stdio -machine id=foo,accel=kvm,usb=on -machine accel=xen
9ae3a8
    QEMU 1.5.50 monitor - type 'help' for more information
9ae3a8
    (qemu) info kvm
9ae3a8
    kvm support: enabled
9ae3a8
    (qemu) info usb
9ae3a8
    USB support not enabled
9ae3a8
    (qemu) q
9ae3a8
    $ qemu-system-x86_64 -nodefaults -S -display none -monitor stdio -machine accel=xen -machine id=foo,accel=kvm,usb=on
9ae3a8
    xc: error: Could not obtain handle on privileged command interface (2 = No such file or directory): Internal error
9ae3a8
    xen be core: can't open xen interface
9ae3a8
    failed to initialize Xen: Operation not permitted
9ae3a8
9ae3a8
Option usb is queried correctly, and the one without an ID wins,
9ae3a8
regardless of option order.
9ae3a8
9ae3a8
Option accel is queried incorrectly, and which one wins depends on
9ae3a8
option order and ID.
9ae3a8
9ae3a8
Affected options are accel (and its sugared forms -enable-kvm and
9ae3a8
-no-kvm), kernel_irqchip, kvm_shadow_mem.
9ae3a8
9ae3a8
Additionally, option kernel_irqchip is normally on by default, except
9ae3a8
it's off when no -machine options are given.  Bug can't bite, because
9ae3a8
kernel_irqchip is used only when KVM is enabled, KVM is off by
9ae3a8
default, and enabling always creates -machine options.  Downstreams
9ae3a8
that enable KVM by default do get bitten, though.
9ae3a8
9ae3a8
Use qemu_get_machine_opts() to fix these bugs.
9ae3a8
9ae3a8
Signed-off-by: Markus Armbruster <armbru@redhat.com>
9ae3a8
Message-id: 1372943363-24081-5-git-send-email-armbru@redhat.com
9ae3a8
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
9ae3a8
(cherry picked from commit 36ad0e948e15d8d86c8dec1c17a8588d87b0107d)
9ae3a8
9ae3a8
Conflicts:
9ae3a8
	hw/ppc/e500.c
9ae3a8
9ae3a8
Conflicts, because we don't have commit d85937e "kvm/openpic:
9ae3a8
in-kernel mpic support".  Resolution is trivial: drop the hunk.
9ae3a8
9ae3a8
There's a pasto in upstream's commit message.  The first paragraph
9ae3a8
after "Example:" shouldn't be there.
9ae3a8
---
9ae3a8
 kvm-all.c         |  5 +----
9ae3a8
 target-i386/kvm.c | 17 +++++++----------
9ae3a8
 vl.c              |  8 ++------
9ae3a8
 3 files changed, 10 insertions(+), 20 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 kvm-all.c         |    5 +----
9ae3a8
 target-i386/kvm.c |   17 +++++++----------
9ae3a8
 vl.c              |    8 ++------
9ae3a8
 3 files changed, 10 insertions(+), 20 deletions(-)
9ae3a8
9ae3a8
diff --git a/kvm-all.c b/kvm-all.c
9ae3a8
index 8222729..6c9d51e 100644
9ae3a8
--- a/kvm-all.c
9ae3a8
+++ b/kvm-all.c
9ae3a8
@@ -1256,12 +1256,9 @@ int kvm_irqchip_remove_irqfd_notifier(KVMState *s, EventNotifier *n, int virq)
9ae3a8
 
9ae3a8
 static int kvm_irqchip_create(KVMState *s)
9ae3a8
 {
9ae3a8
-    QemuOptsList *list = qemu_find_opts("machine");
9ae3a8
     int ret;
9ae3a8
 
9ae3a8
-    if (QTAILQ_EMPTY(&list->head) ||
9ae3a8
-        !qemu_opt_get_bool(QTAILQ_FIRST(&list->head),
9ae3a8
-                           "kernel_irqchip", true) ||
9ae3a8
+    if (!qemu_opt_get_bool(qemu_get_machine_opts(), "kernel_irqchip", true) ||
9ae3a8
         !kvm_check_extension(s, KVM_CAP_IRQCHIP)) {
9ae3a8
         return 0;
9ae3a8
     }
9ae3a8
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
9ae3a8
index 9ffb6ca..8da6a0d 100644
9ae3a8
--- a/target-i386/kvm.c
9ae3a8
+++ b/target-i386/kvm.c
9ae3a8
@@ -741,7 +741,6 @@ static int kvm_get_supported_msrs(KVMState *s)
9ae3a8
 
9ae3a8
 int kvm_arch_init(KVMState *s)
9ae3a8
 {
9ae3a8
-    QemuOptsList *list = qemu_find_opts("machine");
9ae3a8
     uint64_t identity_base = 0xfffbc000;
9ae3a8
     uint64_t shadow_mem;
9ae3a8
     int ret;
9ae3a8
@@ -790,15 +789,13 @@ int kvm_arch_init(KVMState *s)
9ae3a8
     }
9ae3a8
     qemu_register_reset(kvm_unpoison_all, NULL);
9ae3a8
 
9ae3a8
-    if (!QTAILQ_EMPTY(&list->head)) {
9ae3a8
-        shadow_mem = qemu_opt_get_size(QTAILQ_FIRST(&list->head),
9ae3a8
-                                       "kvm_shadow_mem", -1);
9ae3a8
-        if (shadow_mem != -1) {
9ae3a8
-            shadow_mem /= 4096;
9ae3a8
-            ret = kvm_vm_ioctl(s, KVM_SET_NR_MMU_PAGES, shadow_mem);
9ae3a8
-            if (ret < 0) {
9ae3a8
-                return ret;
9ae3a8
-            }
9ae3a8
+    shadow_mem = qemu_opt_get_size(qemu_get_machine_opts(),
9ae3a8
+                                   "kvm_shadow_mem", -1);
9ae3a8
+    if (shadow_mem != -1) {
9ae3a8
+        shadow_mem /= 4096;
9ae3a8
+        ret = kvm_vm_ioctl(s, KVM_SET_NR_MMU_PAGES, shadow_mem);
9ae3a8
+        if (ret < 0) {
9ae3a8
+            return ret;
9ae3a8
         }
9ae3a8
     }
9ae3a8
     return 0;
9ae3a8
diff --git a/vl.c b/vl.c
9ae3a8
index fe58eff..0ed9257 100644
9ae3a8
--- a/vl.c
9ae3a8
+++ b/vl.c
9ae3a8
@@ -2661,17 +2661,13 @@ static struct {
9ae3a8
 
9ae3a8
 static int configure_accelerator(void)
9ae3a8
 {
9ae3a8
-    const char *p = NULL;
9ae3a8
+    const char *p;
9ae3a8
     char buf[10];
9ae3a8
     int i, ret;
9ae3a8
     bool accel_initialised = false;
9ae3a8
     bool init_failed = false;
9ae3a8
 
9ae3a8
-    QemuOptsList *list = qemu_find_opts("machine");
9ae3a8
-    if (!QTAILQ_EMPTY(&list->head)) {
9ae3a8
-        p = qemu_opt_get(QTAILQ_FIRST(&list->head), "accel");
9ae3a8
-    }
9ae3a8
-
9ae3a8
+    p = qemu_opt_get(qemu_get_machine_opts(), "accel");
9ae3a8
     if (p == NULL) {
9ae3a8
         /* Use the default "accelerator", tcg */
9ae3a8
         p = "kvm:tcg";
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8