9ae3a8
From 18238ae670fb38f5ca7002bc8da7b7aa9d612f68 Mon Sep 17 00:00:00 2001
9ae3a8
From: Laszlo Ersek <lersek@redhat.com>
9ae3a8
Date: Sat, 11 Jan 2014 17:59:58 +0100
9ae3a8
Subject: [PATCH 08/22] pc_sysfw: allow flash (-pflash) memory to be used with KVM
9ae3a8
9ae3a8
RH-Author: Laszlo Ersek <lersek@redhat.com>
9ae3a8
Message-id: <1389463208-6278-9-git-send-email-lersek@redhat.com>
9ae3a8
Patchwork-id: 56621
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH 08/18] pc_sysfw: allow flash (-pflash) memory to be used with KVM
9ae3a8
Bugzilla: 1032346
9ae3a8
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
RH-Acked-by: Amos Kong <akong@redhat.com>
9ae3a8
RH-Acked-by: Andrew Jones <drjones@redhat.com>
9ae3a8
9ae3a8
From: Jordan Justen <jordan.l.justen@intel.com>
9ae3a8
9ae3a8
When pc-sysfw.rom_only == 0, flash memory will be
9ae3a8
usable with kvm. In order to enable flash memory mode,
9ae3a8
a pflash device must be created. (For example, by
9ae3a8
using the -pflash command line parameter.)
9ae3a8
9ae3a8
Usage of a flash memory device with kvm requires
9ae3a8
KVM_CAP_READONLY_MEM, and kvm will abort if
9ae3a8
a flash device is used with an older kvm which does
9ae3a8
not support this capability.
9ae3a8
9ae3a8
If a flash device is not used, then qemu/kvm will
9ae3a8
operate in the original rom-mode.
9ae3a8
9ae3a8
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
9ae3a8
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
9ae3a8
Message-id: 1369816047-16384-5-git-send-email-jordan.l.justen@intel.com
9ae3a8
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
9ae3a8
(cherry picked from commit dafb82e0fc89b631d25f8def649fbfd14fec3db2)
9ae3a8
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
---
9ae3a8
 hw/block/pc_sysfw.c | 50 +++++++++++++++++++++++++++++++-------------------
9ae3a8
 1 file changed, 31 insertions(+), 19 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 hw/block/pc_sysfw.c |   50 +++++++++++++++++++++++++++++++-------------------
9ae3a8
 1 files changed, 31 insertions(+), 19 deletions(-)
9ae3a8
9ae3a8
diff --git a/hw/block/pc_sysfw.c b/hw/block/pc_sysfw.c
9ae3a8
index 4d82c70..76932fc 100644
9ae3a8
--- a/hw/block/pc_sysfw.c
9ae3a8
+++ b/hw/block/pc_sysfw.c
9ae3a8
@@ -217,28 +217,40 @@ void pc_system_firmware_init(MemoryRegion *rom_memory)
9ae3a8
 
9ae3a8
     qdev_init_nofail(DEVICE(sysfw_dev));
9ae3a8
 
9ae3a8
-    if (sysfw_dev->rom_only) {
9ae3a8
-        old_pc_system_rom_init(rom_memory, sysfw_dev->isapc_ram_fw);
9ae3a8
-        return;
9ae3a8
-    }
9ae3a8
-
9ae3a8
     pflash_drv = drive_get(IF_PFLASH, 0, 0);
9ae3a8
 
9ae3a8
-    /* Currently KVM cannot execute from device memory.
9ae3a8
-       Use old rom based firmware initialization for KVM. */
9ae3a8
-    /*
9ae3a8
-     * This is a Bad Idea, because it makes enabling/disabling KVM
9ae3a8
-     * guest-visible.  Let's fix it for real in QEMU 1.6.
9ae3a8
-     */
9ae3a8
-    if (kvm_enabled()) {
9ae3a8
-        if (pflash_drv != NULL) {
9ae3a8
-            fprintf(stderr, "qemu: pflash cannot be used with kvm enabled\n");
9ae3a8
-            exit(1);
9ae3a8
-        } else {
9ae3a8
-            sysfw_dev->rom_only = 1;
9ae3a8
-            old_pc_system_rom_init(rom_memory, sysfw_dev->isapc_ram_fw);
9ae3a8
-            return;
9ae3a8
+    if (pc_sysfw_flash_vs_rom_bug_compatible) {
9ae3a8
+        /*
9ae3a8
+         * This is a Bad Idea, because it makes enabling/disabling KVM
9ae3a8
+         * guest-visible.  Do it only in bug-compatibility mode.
9ae3a8
+         */
9ae3a8
+        if (kvm_enabled()) {
9ae3a8
+            if (pflash_drv != NULL) {
9ae3a8
+                fprintf(stderr, "qemu: pflash cannot be used with kvm enabled\n");
9ae3a8
+                exit(1);
9ae3a8
+            } else {
9ae3a8
+                /* In old pc_sysfw_flash_vs_rom_bug_compatible mode, we assume
9ae3a8
+                 * that KVM cannot execute from device memory. In this case, we
9ae3a8
+                 * use old rom based firmware initialization for KVM. But, since
9ae3a8
+                 * this is different from non-kvm mode, this behavior is
9ae3a8
+                 * undesirable */
9ae3a8
+                sysfw_dev->rom_only = 1;
9ae3a8
+            }
9ae3a8
         }
9ae3a8
+    } else if (pflash_drv == NULL) {
9ae3a8
+        /* When a pflash drive is not found, use rom-mode */
9ae3a8
+        sysfw_dev->rom_only = 1;
9ae3a8
+    } else if (kvm_enabled() && !kvm_readonly_mem_enabled()) {
9ae3a8
+        /* Older KVM cannot execute from device memory. So, flash memory
9ae3a8
+         * cannot be used unless the readonly memory kvm capability is present. */
9ae3a8
+        fprintf(stderr, "qemu: pflash with kvm requires KVM readonly memory support\n");
9ae3a8
+        exit(1);
9ae3a8
+    }
9ae3a8
+
9ae3a8
+    /* If rom-mode is active, use the old pc system rom initialization. */
9ae3a8
+    if (sysfw_dev->rom_only) {
9ae3a8
+        old_pc_system_rom_init(rom_memory, sysfw_dev->isapc_ram_fw);
9ae3a8
+        return;
9ae3a8
     }
9ae3a8
 
9ae3a8
     /* If a pflash drive is not found, then create one using
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8