From nobody Mon Feb 9 16:34:15 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1626101818; cv=none; d=zohomail.com; s=zohoarc; b=D++WxJ3OUPisVVxj8IvBOEyRamh88oZr4BxEviO7sKjh93VSZ0P8ICDMYhIkAJHVmTXKfRlG1IJGaxkc5UiABrXVB/fqS+7kxK1aC5TcUjkSN2elNIBiUXClXvaV4jgpOOjKu/IipjnZlMeRm3muZ+8QPXaVX2TDmBby7qGlLeQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1626101818; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=pr73z4riZQUbj21EVzdxkGvVJGIDtuJRt8AUdT1a9D4=; b=IrxzWvlbSzFrVfn0bkUQxVMoa+8IKFKADU8TU/dpYjdzfeK15HNL0SfWBZLH5bVms+HMDwSXjymeEp8N+7zopjCu04rmOLHnCUpraAU9TqWEqTHqEohMWcmtz22NsjQCj/7NhRsX+gOvp3bxbvILeHvB9xfEAqGgVefL1XEil1g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1626101818702670.2565119816055; Mon, 12 Jul 2021 07:56:58 -0700 (PDT) Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-286-M9B0Ig0uM9yjcmv7YIz7Rg-1; Mon, 12 Jul 2021 10:56:56 -0400 Received: by mail-wr1-f71.google.com with SMTP id 32-20020adf82a30000b029013b21c75294so6049296wrc.14 for ; Mon, 12 Jul 2021 07:56:56 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (abayonne-654-1-142-116.w86-222.abo.wanadoo.fr. [86.222.93.116]) by smtp.gmail.com with ESMTPSA id z7sm12313419wmp.34.2021.07.12.07.56.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jul 2021 07:56:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626101817; 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=pr73z4riZQUbj21EVzdxkGvVJGIDtuJRt8AUdT1a9D4=; b=AXvctFBqnfsh8Hv0X+ASjA8gxcyd7+qbis8BRA7H94Cw3IjejQqGs7vU3McuewjNIzChMK sC6vnExzes4McenvmDuRVWppBHklDyVjNVdysmjXyL/H2Lo5SAw0hOrsYNKPjYsdlZ6wH1 czsp5SinBnABqvOKbjmSOspcU4UY4rI= X-MC-Unique: M9B0Ig0uM9yjcmv7YIz7Rg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pr73z4riZQUbj21EVzdxkGvVJGIDtuJRt8AUdT1a9D4=; b=L0xhDjh0iIU9LJR/WA5KwAsha8x6XzQJN5ouBRds2nZAOmsXh7O12TYZZn/5x9+T+j mNr2o5guvCe/EV3JNL0m0B/XalB//2FeBnXdXgTqYHfxKLXeygmMP0n8DsjhQrHKOrSH iElBb6BFf+um9sh5oEI2AsPLFAksEvKp2FaZp/21A9Plpt6ZlrkR68Gj8qUsMVh+p8Wj fGr3wvbRlwAWIFcpI+FlqWoGuqmL53/CT7IlHrXSGQH/ce3H0HXSq7i1aUvBluB2gBld c+mYqVr2CIP43IBAELQWda407nEOsQgH1u2th8ZCkVg1uMM0gRw0y11hrXOLaTnLhc2N kE7Q== X-Gm-Message-State: AOAM530zalWx4nbyn8H+zPuymR+e4KnM64bBOfNKjqwx+H+HzzBTsp1x D+sXzO6e35EiOlKhkicuZG04S7fqf9sx8ogCJixm18o+5sOWLMDg4oVtxhqxiWOK5BRuK+WG8UC p3MoNJr4slSlOPQ== X-Received: by 2002:a1c:7c08:: with SMTP id x8mr6699414wmc.2.1626101814941; Mon, 12 Jul 2021 07:56:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxia9FQ0/7cnrX5xaBytJQY23tsuOxQRzwCFtemAmZsbqrcCGXHW/A+NHktNZAixf8snQuTiQ== X-Received: by 2002:a1c:7c08:: with SMTP id x8mr6699382wmc.2.1626101814700; Mon, 12 Jul 2021 07:56:54 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Dov Murik , "Michael S. Tsirkin" , Laszlo Ersek , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 3/4] hw/i386: Introduce X86_FW_OVMF Kconfig symbol Date: Mon, 12 Jul 2021 16:56:29 +0200 Message-Id: <20210712145630.2857814-4-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210712145630.2857814-1-philmd@redhat.com> References: <20210712145630.2857814-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1626101820170100001 Introduce the X86_FW_OVMF Kconfig symbol for OVMF-specific code. Move the OVMF-specific code from pc_sysfw.c to pc_sysfw_ovmf.c, adding a pair of stubs. Update MAINTAINERS to reach OVMF maintainers when these new files are modified. This fixes when building the microvm machine standalone: /usr/bin/ld: libqemu-i386-softmmu.fa.p/target_i386_monitor.c.o: in function `qmp_sev_inject_launch_secret': target/i386/monitor.c:749: undefined reference to `pc_system_ovmf_table_f= ind' Fixes: f522cef9b35 ("sev: update sev-inject-launch-secret to make gpa optio= nal") Signed-off-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Michael S. Tsirkin Message-Id: <20210616204328.2611406-22-philmd@redhat.com> --- include/hw/i386/pc.h | 1 + hw/i386/pc_sysfw.c | 123 --------------------------- hw/i386/pc_sysfw_ovmf-stubs.c | 26 ++++++ hw/i386/pc_sysfw_ovmf.c | 151 ++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + hw/i386/Kconfig | 4 + hw/i386/meson.build | 2 + 7 files changed, 185 insertions(+), 123 deletions(-) create mode 100644 hw/i386/pc_sysfw_ovmf-stubs.c create mode 100644 hw/i386/pc_sysfw_ovmf.c diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 87294f2632e..0775f945d70 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -188,6 +188,7 @@ void pc_system_flash_cleanup_unused(PCMachineState *pcm= s); void pc_system_firmware_init(PCMachineState *pcms, MemoryRegion *rom_memor= y); 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); =20 =20 /* acpi-build.c */ diff --git a/hw/i386/pc_sysfw.c b/hw/i386/pc_sysfw.c index 6ddce92a861..68d6b1f783e 100644 --- a/hw/i386/pc_sysfw.c +++ b/hw/i386/pc_sysfw.c @@ -124,129 +124,6 @@ void pc_system_flash_cleanup_unused(PCMachineState *p= cms) } } =20 -#define OVMF_TABLE_FOOTER_GUID "96b582de-1fb2-45f7-baea-a366c55a082d" - -static bool ovmf_flash_parsed; -static uint8_t *ovmf_table; -static int ovmf_table_len; - -static void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, size_t flash_si= ze) -{ - uint8_t *ptr; - QemuUUID guid; - int tot_len; - - /* should only be called once */ - if (ovmf_flash_parsed) { - return; - } - - ovmf_flash_parsed =3D true; - - if (flash_size < TARGET_PAGE_SIZE) { - return; - } - - /* - * if this is OVMF there will be a table footer - * guid 48 bytes before the end of the flash file. If it's - * not found, silently abort the flash parsing. - */ - qemu_uuid_parse(OVMF_TABLE_FOOTER_GUID, &guid); - guid =3D qemu_uuid_bswap(guid); /* guids are LE */ - ptr =3D flash_ptr + flash_size - 48; - if (!qemu_uuid_is_equal((QemuUUID *)ptr, &guid)) { - return; - } - - /* if found, just before is two byte table length */ - ptr -=3D sizeof(uint16_t); - tot_len =3D le16_to_cpu(*(uint16_t *)ptr) - sizeof(guid) - sizeof(uint= 16_t); - - if (tot_len <=3D 0) { - return; - } - - ovmf_table =3D g_malloc(tot_len); - ovmf_table_len =3D tot_len; - - /* - * ptr is the foot of the table, so copy it all to the newly - * allocated ovmf_table and then set the ovmf_table pointer - * to the table foot - */ - memcpy(ovmf_table, ptr - tot_len, tot_len); - ovmf_table +=3D tot_len; -} - -/** - * pc_system_ovmf_table_find - Find the data associated with an entry in O= VMF's - * reset vector GUIDed table. - * - * @entry: GUID string of the entry to lookup - * @data: Filled with a pointer to the entry's value (if not NULL) - * @data_len: Filled with the length of the entry's value (if not NULL). P= ass - * NULL here if the length of data is known. - * - * Return: true if the entry was found in the OVMF table; false otherwise. - */ -bool pc_system_ovmf_table_find(const char *entry, uint8_t **data, - int *data_len) -{ - uint8_t *ptr =3D ovmf_table; - int tot_len =3D ovmf_table_len; - QemuUUID entry_guid; - - assert(ovmf_flash_parsed); - - if (qemu_uuid_parse(entry, &entry_guid) < 0) { - return false; - } - - if (!ptr) { - return false; - } - - entry_guid =3D qemu_uuid_bswap(entry_guid); /* guids are LE */ - while (tot_len >=3D sizeof(QemuUUID) + sizeof(uint16_t)) { - int len; - QemuUUID *guid; - - /* - * The data structure is - * arbitrary length data - * 2 byte length of entire entry - * 16 byte guid - */ - guid =3D (QemuUUID *)(ptr - sizeof(QemuUUID)); - len =3D le16_to_cpu(*(uint16_t *)(ptr - sizeof(QemuUUID) - - sizeof(uint16_t))); - - /* - * just in case the table is corrupt, wouldn't want to spin in - * the zero case - */ - if (len < sizeof(QemuUUID) + sizeof(uint16_t)) { - return false; - } else if (len > tot_len) { - return false; - } - - ptr -=3D len; - tot_len -=3D len; - if (qemu_uuid_is_equal(guid, &entry_guid)) { - if (data) { - *data =3D ptr; - } - if (data_len) { - *data_len =3D len - sizeof(QemuUUID) - sizeof(uint16_t); - } - return true; - } - } - return false; -} - /* * Map the pcms->flash[] from 4GiB downward, and realize. * Map them in descending order, i.e. pcms->flash[0] at the top, diff --git a/hw/i386/pc_sysfw_ovmf-stubs.c b/hw/i386/pc_sysfw_ovmf-stubs.c new file mode 100644 index 00000000000..aabe78b2710 --- /dev/null +++ b/hw/i386/pc_sysfw_ovmf-stubs.c @@ -0,0 +1,26 @@ +/* + * QEMU PC System Firmware (OVMF stubs) + * + * Copyright (c) 2021 Red Hat, Inc. + * + * Author: + * Philippe Mathieu-Daud=C3=A9 + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "hw/i386/pc.h" + +bool pc_system_ovmf_table_find(const char *entry, uint8_t **data, int *dat= a_len) +{ + g_assert_not_reached(); +} + +void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, size_t flash_size) +{ + g_assert_not_reached(); +} diff --git a/hw/i386/pc_sysfw_ovmf.c b/hw/i386/pc_sysfw_ovmf.c new file mode 100644 index 00000000000..f4dd92c5882 --- /dev/null +++ b/hw/i386/pc_sysfw_ovmf.c @@ -0,0 +1,151 @@ +/* + * QEMU PC System Firmware (OVMF specific) + * + * Copyright (c) 2003-2004 Fabrice Bellard + * Copyright (c) 2011-2012 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "hw/i386/pc.h" +#include "cpu.h" + +#define OVMF_TABLE_FOOTER_GUID "96b582de-1fb2-45f7-baea-a366c55a082d" + +static bool ovmf_flash_parsed; +static uint8_t *ovmf_table; +static int ovmf_table_len; + +void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, size_t flash_size) +{ + uint8_t *ptr; + QemuUUID guid; + int tot_len; + + /* should only be called once */ + if (ovmf_flash_parsed) { + return; + } + + ovmf_flash_parsed =3D true; + + if (flash_size < TARGET_PAGE_SIZE) { + return; + } + + /* + * if this is OVMF there will be a table footer + * guid 48 bytes before the end of the flash file. If it's + * not found, silently abort the flash parsing. + */ + qemu_uuid_parse(OVMF_TABLE_FOOTER_GUID, &guid); + guid =3D qemu_uuid_bswap(guid); /* guids are LE */ + ptr =3D flash_ptr + flash_size - 48; + if (!qemu_uuid_is_equal((QemuUUID *)ptr, &guid)) { + return; + } + + /* if found, just before is two byte table length */ + ptr -=3D sizeof(uint16_t); + tot_len =3D le16_to_cpu(*(uint16_t *)ptr) - sizeof(guid) - sizeof(uint= 16_t); + + if (tot_len <=3D 0) { + return; + } + + ovmf_table =3D g_malloc(tot_len); + ovmf_table_len =3D tot_len; + + /* + * ptr is the foot of the table, so copy it all to the newly + * allocated ovmf_table and then set the ovmf_table pointer + * to the table foot + */ + memcpy(ovmf_table, ptr - tot_len, tot_len); + ovmf_table +=3D tot_len; +} + +/** + * pc_system_ovmf_table_find - Find the data associated with an entry in O= VMF's + * reset vector GUIDed table. + * + * @entry: GUID string of the entry to lookup + * @data: Filled with a pointer to the entry's value (if not NULL) + * @data_len: Filled with the length of the entry's value (if not NULL). P= ass + * NULL here if the length of data is known. + * + * Return: true if the entry was found in the OVMF table; false otherwise. + */ +bool pc_system_ovmf_table_find(const char *entry, uint8_t **data, + int *data_len) +{ + uint8_t *ptr =3D ovmf_table; + int tot_len =3D ovmf_table_len; + QemuUUID entry_guid; + + assert(ovmf_flash_parsed); + + if (qemu_uuid_parse(entry, &entry_guid) < 0) { + return false; + } + + if (!ptr) { + return false; + } + + entry_guid =3D qemu_uuid_bswap(entry_guid); /* guids are LE */ + while (tot_len >=3D sizeof(QemuUUID) + sizeof(uint16_t)) { + int len; + QemuUUID *guid; + + /* + * The data structure is + * arbitrary length data + * 2 byte length of entire entry + * 16 byte guid + */ + guid =3D (QemuUUID *)(ptr - sizeof(QemuUUID)); + len =3D le16_to_cpu(*(uint16_t *)(ptr - sizeof(QemuUUID) - + sizeof(uint16_t))); + + /* + * just in case the table is corrupt, wouldn't want to spin in + * the zero case + */ + if (len < sizeof(QemuUUID) + sizeof(uint16_t)) { + return false; + } else if (len > tot_len) { + return false; + } + + ptr -=3D len; + tot_len -=3D len; + if (qemu_uuid_is_equal(guid, &entry_guid)) { + if (data) { + *data =3D ptr; + } + if (data_len) { + *data_len =3D len - sizeof(QemuUUID) - sizeof(uint16_t); + } + return true; + } + } + return false; +} diff --git a/MAINTAINERS b/MAINTAINERS index 3026b979b7f..7a2bd2e7184 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2943,6 +2943,7 @@ EDK2 Firmware M: Laszlo Ersek M: Philippe Mathieu-Daud=C3=A9 S: Supported +F: hw/i386/*ovmf* F: pc-bios/descriptors/??-edk2-*.json F: pc-bios/edk2-* F: roms/Makefile.edk2 diff --git a/hw/i386/Kconfig b/hw/i386/Kconfig index aacb6f6d964..bad6cf5b4e6 100644 --- a/hw/i386/Kconfig +++ b/hw/i386/Kconfig @@ -1,5 +1,9 @@ +config X86_FW_OVMF + bool + config SEV bool + select X86_FW_OVMF depends on KVM =20 config PC diff --git a/hw/i386/meson.build b/hw/i386/meson.build index e5d109f5c64..80dad29f2ba 100644 --- a/hw/i386/meson.build +++ b/hw/i386/meson.build @@ -24,6 +24,8 @@ 'pc_sysfw.c', 'acpi-build.c', 'port92.c')) +i386_ss.add(when: 'CONFIG_X86_FW_OVMF', if_true: files('pc_sysfw_ovmf.c'), + if_false: files('pc_sysfw_ovmf-stu= bs.c')) =20 subdir('kvm') subdir('xen') --=20 2.31.1