Skip to content

Commit c1fc2dd

Browse files
committed
Merge tag 'uefi-20250321-pull-request' of https://gitlab.com/kraxel/qemu into staging
hw/uefi-vars: bug fixes hw/uefi-vars: support riscv and loongarch docs: update firmware.json spec # -----BEGIN PGP SIGNATURE----- # # iQIzBAABCgAdFiEEoDKM/7k6F6eZAf59TLbY7tPocTgFAmfdXR0ACgkQTLbY7tPo # cThurBAA2xXMSS5HxU+8kAgkQQ5UC0c9cSQj//HJB5dAmsZ/I8WEgwv1+XLGnjf0 # SOpAiR0PshTipXdtcUVGpqufAghy+8WkAoYplMqY40o/Bsv8egQzb4XvNPSxqvon # dTDmScn2ns1mtSOOY8LWSFIXFDlYK0uKyXcHSKvw/HNjYsVOb22IAokznyh9eZa0 # OwjhUc9oqTR0s8MrZbu+tKqEfoqGRMIDYVKk1vzjAigw6jfgvaUZ0dtldcwTktsH # w7SyMowUJnNcjnzZxqchj94377feS4OG/QKO7LpnhfdYYHf7CT1BC72xG1Ivloma # A3xK/AnFqbzYuwL3Mtmuk5xV5s98dP/dWvxTc7kZFT++fJ4bljnRhcyqckvWwHD5 # jYjm8ssAn2ukuVDM+O7+tRNMcyBXYc1pgmQCa10XjT0Ds0WulIynITwoguolvCPv # rH/ILe8N2vXa7xxB7DledPMzX74+SWXaHv4n+SKEHoVlSiaP3M85ZNcSYjXf9P37 # hrMyUWgjO0AXJ2aDaCSn9nLJT8jRMcYh9HN03Y7KmyT0SZnksbHvPLF0kB1zFNfa # NBQZUhZacu7iZoNpHx3uT+D1z9GM16S2skkxvryMrS/05iM6amc2kCJPxOp2vbYc # eiyihjFHtW/dfhRmOG92EJ1FRMLx/dB/dBG90oGmTyHMlev6tEQ= # =VN7r # -----END PGP SIGNATURE----- # gpg: Signature made Fri 21 Mar 2025 08:35:41 EDT # gpg: using RSA key A0328CFFB93A17A79901FE7D4CB6D8EED3E87138 # gpg: Good signature from "Gerd Hoffmann (work) <[email protected]>" [full] # gpg: aka "Gerd Hoffmann <[email protected]>" [full] # gpg: aka "Gerd Hoffmann (private) <[email protected]>" [full] # Primary key fingerprint: A032 8CFF B93A 17A7 9901 FE7D 4CB6 D8EE D3E8 7138 * tag 'uefi-20250321-pull-request' of https://gitlab.com/kraxel/qemu: docs/firmware: add feature flag for host uefi variable store hw/uefi-vars-sysbus: allow for loongarch virt hw/uefi-vars-sysbus: allow for riscv virt hw/uefi: fix error handling in uefi_vars_json_load hw/uefi: fix error handling in uefi_vars_json_save hw/uefi: flush variable store to disk in post load Signed-off-by: Stefan Hajnoczi <[email protected]>
2 parents 330ad56 + 5e5d18d commit c1fc2dd

File tree

6 files changed

+36
-7
lines changed

6 files changed

+36
-7
lines changed

docs/interop/firmware.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,23 @@
214214
# PL011 UART. @verbose-static is mutually exclusive
215215
# with @verbose-dynamic.
216216
#
217+
# @host-uefi-vars: The firmware expects the host to provide an uefi
218+
# variable store. qemu supports that via
219+
# "uefi-vars-sysbus" (aarch64, riscv64, loongarch64)
220+
# or "uefi-vars-x64" (x86_64) devices. The firmware
221+
# will not use flash for nvram. When loading the
222+
# firmware into flash the 'stateless' setup should be
223+
# used. It is recommened to load the firmware into
224+
# memory though.
225+
#
217226
# Since: 3.0
218227
##
219228
{ 'enum' : 'FirmwareFeature',
220229
'data' : [ 'acpi-s3', 'acpi-s4',
221230
'amd-sev', 'amd-sev-es', 'amd-sev-snp',
222231
'intel-tdx',
223-
'enrolled-keys', 'requires-smm', 'secure-boot',
232+
'enrolled-keys', 'requires-smm',
233+
'secure-boot', 'host-uefi-vars',
224234
'verbose-dynamic', 'verbose-static' ] }
225235

226236
##

hw/loongarch/virt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "hw/mem/nvdimm.h"
3939
#include "hw/platform-bus.h"
4040
#include "hw/display/ramfb.h"
41+
#include "hw/uefi/var-service-api.h"
4142
#include "hw/mem/pc-dimm.h"
4243
#include "system/tpm.h"
4344
#include "system/block-backend.h"
@@ -1207,6 +1208,7 @@ static void virt_class_init(ObjectClass *oc, void *data)
12071208
object_class_property_set_description(oc, "v-eiointc",
12081209
"Enable Virt Extend I/O Interrupt Controller.");
12091210
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE);
1211+
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_UEFI_VARS_SYSBUS);
12101212
#ifdef CONFIG_TPM
12111213
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_TPM_TIS_SYSBUS);
12121214
#endif

hw/riscv/virt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include "hw/acpi/aml-build.h"
5858
#include "qapi/qapi-visit-common.h"
5959
#include "hw/virtio/virtio-iommu.h"
60+
#include "hw/uefi/var-service-api.h"
6061

6162
/* KVM AIA only supports APLIC MSI. APLIC Wired is always emulated by QEMU. */
6263
static bool virt_use_kvm_aia_aplic_imsic(RISCVVirtAIAType aia_type)
@@ -1935,6 +1936,7 @@ static void virt_machine_class_init(ObjectClass *oc, void *data)
19351936
hc->plug = virt_machine_device_plug_cb;
19361937

19371938
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE);
1939+
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_UEFI_VARS_SYSBUS);
19381940
#ifdef CONFIG_TPM
19391941
machine_class_allow_dynamic_sysbus_dev(mc, TYPE_TPM_TIS_SYSBUS);
19401942
#endif

hw/uefi/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
config UEFI_VARS
22
bool
3-
default y if X86_64 || AARCH64
3+
default y if X86_64 || AARCH64 || RISCV64 || LOONGARCH64

hw/uefi/var-service-core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static int uefi_vars_post_load(void *opaque, int version_id)
2929
uefi_vars_state *uv = opaque;
3030

3131
uefi_vars_update_storage(uv);
32+
uefi_vars_json_save(uv);
3233
uv->buffer = g_malloc(uv->buf_size);
3334
return 0;
3435
}

hw/uefi/var-service-json.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ void uefi_vars_json_init(uefi_vars_state *uv, Error **errp)
178178

179179
void uefi_vars_json_save(uefi_vars_state *uv)
180180
{
181-
GString *gstr;
181+
g_autoptr(GString) gstr = NULL;
182182
int rc;
183183

184184
if (uv->jsonfd == -1) {
@@ -187,18 +187,25 @@ void uefi_vars_json_save(uefi_vars_state *uv)
187187

188188
gstr = uefi_vars_to_json(uv);
189189

190-
lseek(uv->jsonfd, 0, SEEK_SET);
190+
rc = lseek(uv->jsonfd, 0, SEEK_SET);
191+
if (rc < 0) {
192+
warn_report("%s: lseek error", __func__);
193+
return;
194+
}
195+
191196
rc = ftruncate(uv->jsonfd, 0);
192197
if (rc != 0) {
193198
warn_report("%s: ftruncate error", __func__);
199+
return;
194200
}
201+
195202
rc = write(uv->jsonfd, gstr->str, gstr->len);
196203
if (rc != gstr->len) {
197204
warn_report("%s: write error", __func__);
205+
return;
198206
}
199-
fsync(uv->jsonfd);
200207

201-
g_string_free(gstr, true);
208+
fsync(uv->jsonfd);
202209
}
203210

204211
void uefi_vars_json_load(uefi_vars_state *uv, Error **errp)
@@ -207,15 +214,20 @@ void uefi_vars_json_load(uefi_vars_state *uv, Error **errp)
207214
QObject *qobj;
208215
Visitor *v;
209216
char *str;
210-
size_t len;
217+
ssize_t len;
211218
int rc;
212219

213220
if (uv->jsonfd == -1) {
214221
return;
215222
}
216223

217224
len = lseek(uv->jsonfd, 0, SEEK_END);
225+
if (len < 0) {
226+
warn_report("%s: lseek error", __func__);
227+
return;
228+
}
218229
if (len == 0) {
230+
/* empty file */
219231
return;
220232
}
221233

@@ -224,6 +236,8 @@ void uefi_vars_json_load(uefi_vars_state *uv, Error **errp)
224236
rc = read(uv->jsonfd, str, len);
225237
if (rc != len) {
226238
warn_report("%s: read error", __func__);
239+
g_free(str);
240+
return;
227241
}
228242
str[len] = 0;
229243

0 commit comments

Comments
 (0)