From patchwork Tue May 7 17:15:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jordan.l.justen@intel.com X-Patchwork-Id: 242422 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 996F62C016E for ; Wed, 8 May 2013 03:17:45 +1000 (EST) Received: from localhost ([::1]:52237 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZlWJ-0000HJ-Ot for incoming@patchwork.ozlabs.org; Tue, 07 May 2013 13:17:43 -0400 Received: from eggs.gnu.org ([208.118.235.92]:58460) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZlVc-00006C-NB for qemu-devel@nongnu.org; Tue, 07 May 2013 13:17:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UZlVX-0006HS-Di for qemu-devel@nongnu.org; Tue, 07 May 2013 13:17:00 -0400 Received: from mga14.intel.com ([143.182.124.37]:53017) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZlVX-0006FI-6c for qemu-devel@nongnu.org; Tue, 07 May 2013 13:16:55 -0400 Received: from azsmga001.ch.intel.com ([10.2.17.19]) by azsmga102.ch.intel.com with ESMTP; 07 May 2013 10:16:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.87,629,1363158000"; d="scan'208";a="298984373" Received: from unknown (HELO jljusten-ivy.amr.corp.intel.com) ([10.255.12.93]) by azsmga001.ch.intel.com with ESMTP; 07 May 2013 10:16:04 -0700 From: Jordan Justen To: qemu-devel@nongnu.org Date: Tue, 7 May 2013 10:15:46 -0700 Message-Id: <1367946947-17109-6-git-send-email-jordan.l.justen@intel.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1367946947-17109-1-git-send-email-jordan.l.justen@intel.com> References: <1367946947-17109-1-git-send-email-jordan.l.justen@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 143.182.124.37 Cc: Jordan Justen Subject: [Qemu-devel] [PATCH v4 5/6] pc_sysfw: allow flash (-pflash) memory to be used with KVM X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When pc-sysfw.rom_only != 0, flash memory will be usable with kvm. In order to enable flash memory mode, a pflash device must be created. (For example, by using the -pflash command line parameter.) Usage of a flash memory device with kvm requires the KVM READONLY memory capability, and kvm will abort if a flash device is used with an older kvm which does not support this capability. If a flash device is not used, then qemu/kvm will operate in the original rom-mode. Signed-off-by: Jordan Justen --- hw/block/pc_sysfw.c | 50 +++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/hw/block/pc_sysfw.c b/hw/block/pc_sysfw.c index 90894af..d8a499d 100644 --- a/hw/block/pc_sysfw.c +++ b/hw/block/pc_sysfw.c @@ -220,28 +220,40 @@ void pc_system_firmware_init(MemoryRegion *rom_memory) qdev_init_nofail(DEVICE(sysfw_dev)); - if (sysfw_dev->rom_only) { - old_pc_system_rom_init(rom_memory, sysfw_dev->isapc_ram_fw); - return; - } - pflash_drv = drive_get(IF_PFLASH, 0, 0); - /* Currently KVM cannot execute from device memory. - Use old rom based firmware initialization for KVM. */ - /* - * This is a Bad Idea, because it makes enabling/disabling KVM - * guest-visible. Do it only in bug-compatibility mode. - */ - if (pc_sysfw_flash_vs_rom_bug_compatible && kvm_enabled()) { - if (pflash_drv != NULL) { - fprintf(stderr, "qemu: pflash cannot be used with kvm enabled\n"); - exit(1); - } else { - sysfw_dev->rom_only = 1; - old_pc_system_rom_init(rom_memory); - return; + if (pc_sysfw_flash_vs_rom_bug_compatible) { + /* + * This is a Bad Idea, because it makes enabling/disabling KVM + * guest-visible. Do it only in bug-compatibility mode. + */ + if (kvm_enabled()) { + if (pflash_drv != NULL) { + fprintf(stderr, "qemu: pflash cannot be used with kvm enabled\n"); + exit(1); + } else { + /* In old pc_sysfw_flash_vs_rom_bug_compatible mode, we assume + * that KVM cannot execute from device memory. In this case, we + * use old rom based firmware initialization for KVM. But, since + * this is different from non-kvm mode, this behavior is + * undesirable */ + sysfw_dev->rom_only = 1; + } } + } else if (pflash_drv == NULL) { + /* When a pflash drive is not found, use rom-mode */ + sysfw_dev->rom_only = 1; + } else if (kvm_enabled() && !kvm_readonly_mem_enabled()) { + /* Older KVM cannot execute from device memory. So, flash memory + * cannot be used unless the readonly memory kvm capability is present. */ + fprintf(stderr, "qemu: pflash with kvm requires KVM readonly memory support\n"); + exit(1); + } + + /* If rom-mode is active, use the old pc system rom initialization. */ + if (sysfw_dev->rom_only) { + old_pc_system_rom_init(rom_memory, sysfw_dev->isapc_ram_fw); + return; } /* If a pflash drive is not found, then create one using