From nobody Sat May 4 00:54:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1642093040312155.49901144859177; Thu, 13 Jan 2022 08:57:20 -0800 (PST) Received: from localhost ([::1]:57954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n83Pb-0002tY-Bp for importer@patchew.org; Thu, 13 Jan 2022 11:57:19 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47290) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n83OL-00018z-7Y for qemu-devel@nongnu.org; Thu, 13 Jan 2022 11:56:01 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:52164) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n83OJ-0004ql-IF for qemu-devel@nongnu.org; Thu, 13 Jan 2022 11:56:00 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-619-JJMeTRw5OjCP2c2k2QYP4g-1; Thu, 13 Jan 2022 11:55:55 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 619901083F61; Thu, 13 Jan 2022 16:55:54 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.33.37.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id CED6578AFE; Thu, 13 Jan 2022 16:55:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642092959; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UZJUlFJvRX6jpStWZ6PETkltlCjxA0ZDCMDyoCDMqqs=; b=VZy26rAkF2rigX/tmW//IK9ODLQH45wtc+356YsrRDaEqf3U14wbt0UJAf+TNyjE+yHCrU JVs+W7zNhgrOprRseyx1hyelf4CmecKYVLvPcillUYS4cTruSoZSADMvVVNwgr0Itu7dJC pesiiBqP43IAg7MyzP2OO04kzFIcdeo= X-MC-Unique: JJMeTRw5OjCP2c2k2QYP4g-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 1/2] hw/i386: refactor logic for setting up SEV firmware Date: Thu, 13 Jan 2022 16:55:10 +0000 Message-Id: <20220113165511.46098-2-berrange@redhat.com> In-Reply-To: <20220113165511.46098-1-berrange@redhat.com> References: <20220113165511.46098-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=berrange@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.594, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , "Michael S. Tsirkin" , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Dr . David Alan Gilbert" , Dov Murik , Gerd Hoffmann , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1642093042130100001 Currently this logic is only run in the pflash codepath but we want to run it in other scenarios too. Signed-off-by: Daniel P. Berrang=C3=A9 --- hw/i386/pc_sysfw.c | 24 +++--------------------- hw/i386/pc_sysfw_ovmf-stubs.c | 10 ++++++++++ hw/i386/pc_sysfw_ovmf.c | 27 +++++++++++++++++++++++++++ include/hw/i386/pc.h | 1 + 4 files changed, 41 insertions(+), 21 deletions(-) diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c index c8b17af953..b056526077 100644 --- a/hw/i386/pc_sysfw.c +++ b/hw/i386/pc_sysfw.c @@ -146,9 +146,6 @@ static void pc_system_flash_map(PCMachineState *pcms, int64_t size; PFlashCFI01 *system_flash; MemoryRegion *flash_mem; - void *flash_ptr; - int flash_size; - int ret; =20 assert(PC_MACHINE_GET_CLASS(pcms)->pci_enabled); =20 @@ -192,24 +189,9 @@ static void pc_system_flash_map(PCMachineState *pcms, flash_mem =3D pflash_cfi01_get_memory(system_flash); pc_isa_bios_init(rom_memory, flash_mem, size); =20 - /* Encrypt the pflash boot ROM */ - if (sev_enabled()) { - flash_ptr =3D memory_region_get_ram_ptr(flash_mem); - flash_size =3D memory_region_size(flash_mem); - /* - * OVMF places a GUIDed structures in the flash, so - * search for them - */ - pc_system_parse_ovmf_flash(flash_ptr, flash_size); - - ret =3D sev_es_save_reset_vector(flash_ptr, flash_size); - if (ret) { - error_report("failed to locate and/or save reset vecto= r"); - exit(1); - } - - sev_encrypt_flash(flash_ptr, flash_size, &error_fatal); - } + pc_system_ovmf_initialize_sev( + memory_region_get_ram_ptr(flash_mem), + memory_region_size(flash_mem)); } } } diff --git a/hw/i386/pc_sysfw_ovmf-stubs.c b/hw/i386/pc_sysfw_ovmf-stubs.c index aabe78b271..d88970af88 100644 --- a/hw/i386/pc_sysfw_ovmf-stubs.c +++ b/hw/i386/pc_sysfw_ovmf-stubs.c @@ -14,6 +14,7 @@ =20 #include "qemu/osdep.h" #include "hw/i386/pc.h" +#include "sev.h" =20 bool pc_system_ovmf_table_find(const char *entry, uint8_t **data, int *dat= a_len) { @@ -24,3 +25,12 @@ void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, size= _t flash_size) { g_assert_not_reached(); } + +void pc_system_ovmf_initialize_sev(void *ptr, size_t size) +{ + if (!sev_enabled()) { + return; + } + + g_assert_not_reached(); +} diff --git a/hw/i386/pc_sysfw_ovmf.c b/hw/i386/pc_sysfw_ovmf.c index f4dd92c588..180500a035 100644 --- a/hw/i386/pc_sysfw_ovmf.c +++ b/hw/i386/pc_sysfw_ovmf.c @@ -24,8 +24,10 @@ */ =20 #include "qemu/osdep.h" +#include "qapi/error.h" #include "hw/i386/pc.h" #include "cpu.h" +#include "sev.h" =20 #define OVMF_TABLE_FOOTER_GUID "96b582de-1fb2-45f7-baea-a366c55a082d" =20 @@ -149,3 +151,28 @@ bool pc_system_ovmf_table_find(const char *entry, uint= 8_t **data, } return false; } + + +void pc_system_ovmf_initialize_sev(void *ptr, size_t size) +{ + int ret; + + /* Encrypt the boot ROM */ + if (!sev_enabled()) { + return; + } + + /* + * OVMF places a GUIDed structures in the flash, so + * search for them + */ + pc_system_parse_ovmf_flash(ptr, size); + + ret =3D sev_es_save_reset_vector(ptr, size); + if (ret) { + error_report("failed to locate and/or save reset vector"); + exit(1); + } + + sev_encrypt_flash(ptr, size, &error_fatal); +} diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 9c9f4ac748..47f5bc82ba 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -191,6 +191,7 @@ void pc_system_firmware_init(PCMachineState *pcms, Memo= ryRegion *rom_memory); bool pc_system_ovmf_table_find(const char *entry, uint8_t **data, int *data_len); void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, size_t flash_size); +void pc_system_ovmf_initialize_sev(void *ptr, size_t size); =20 /* hw/i386/acpi-common.c */ void pc_madt_cpu_entry(AcpiDeviceIf *adev, int uid, --=20 2.33.1 From nobody Sat May 4 00:54:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1642093190736710.7776844596535; Thu, 13 Jan 2022 08:59:50 -0800 (PST) Received: from localhost ([::1]:34118 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n83S1-0006Ta-P1 for importer@patchew.org; Thu, 13 Jan 2022 11:59:49 -0500 Received: from eggs.gnu.org ([209.51.188.92]:47334) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n83Oc-0001gE-UG for qemu-devel@nongnu.org; Thu, 13 Jan 2022 11:56:22 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:30264) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n83OR-0004ra-Pe for qemu-devel@nongnu.org; Thu, 13 Jan 2022 11:56:17 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-240-n063_-LNMV6pfnt-YO_gwA-1; Thu, 13 Jan 2022 11:55:59 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D5CA41018733; Thu, 13 Jan 2022 16:55:57 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.33.37.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id B172C7DE35; Thu, 13 Jan 2022 16:55:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642092967; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UnbELTmcyAtnylRxklQM5J14dTT7Kjm6dMwphBUIj4g=; b=BrGO0R7hKJ1OhahS5vEYR8ZytzLDiR14FSBm3H4IR18oSvgrycFFLuuyM93NKLSlvaXvmX QgWOKdyiEXIIp+ZlmX0m2k2jOAG5aaZdpN0BAMzM8tTm2RNRNI70eIUAg3csTL2V7N0RBt wQ1JSzEB09cu0q7C9OcXoFqsf4+jKvM= X-MC-Unique: n063_-LNMV6pfnt-YO_gwA-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 2/2] hw/i386: support loading OVMF using -bios too Date: Thu, 13 Jan 2022 16:55:11 +0000 Message-Id: <20220113165511.46098-3-berrange@redhat.com> In-Reply-To: <20220113165511.46098-1-berrange@redhat.com> References: <20220113165511.46098-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=berrange@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.594, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, T_SPF_TEMPERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , "Michael S. Tsirkin" , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Dr . David Alan Gilbert" , Dov Murik , Gerd Hoffmann , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1642093191353100001 Traditionally the OVMF firmware has been loaded using the pflash mechanism. This is because it is usually provided as a pair of files, one read-only containing the code and one writable to provided persistence of non-volatile firmware variables. The AMD SEV build of EDK2, however, is provided as a single file that contains only the code. This is intended to be used read-only and explicitly does not provide any ability for persistance of non-volatile firmware variables. While it is possible to configure this with the pflash mechanism, by only providing one of the 2 pflash blobs, conceptually it is a little strange to use pflash if there won't be any persistent data. A stateless OVMF build can be loaded with -bios, however, QEMU does not currently initialize SEV in that scenario. This patch introduces the call needed for SEV initialization of the firmware. Signed-off-by: Daniel P. Berrang=C3=A9 --- hw/i386/x86.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/i386/x86.c b/hw/i386/x86.c index b84840a1bb..c79d84936f 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -45,6 +45,7 @@ #include "target/i386/cpu.h" #include "hw/i386/topology.h" #include "hw/i386/fw_cfg.h" +#include "hw/i386/pc.h" #include "hw/intc/i8259.h" #include "hw/rtc/mc146818rtc.h" #include "target/i386/sev.h" @@ -1157,6 +1158,10 @@ void x86_bios_rom_init(MachineState *ms, const char = *default_firmware, memory_region_add_subregion(rom_memory, (uint32_t)(-bios_size), bios); + + pc_system_ovmf_initialize_sev( + rom_ptr((uint32_t)-bios_size, bios_size), + bios_size); } =20 bool x86_machine_is_smm_enabled(const X86MachineState *x86ms) --=20 2.33.1