From nobody Mon Feb 9 02:42:31 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1565021699; cv=none; d=zoho.com; s=zohoarc; b=fGCzpXauNm/5Tj/JG/007gHrVKZXd3hy5P1fDREcKyBctk58s/8eFuxhc/yPnCSJFAC4yuiiVsqEBuO3eXPcncTXItuWjAWXbUcuPoaqvJ3gi6LEMIgmI1jTFOsrCnSj2edlIVsq++N12BLXT7JCfKvNm6wK3hozA9Pe4OwmnNI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565021699; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Utnh43utJllwdV/C0/yH6SuB51p9FXVR5IGTL8Ypbyk=; b=DV37O/TRvPfRmRHkdaftQOKfY1rlDpaPHSQn9PDFgeZd/EMNO2LjnuLdFh9UO4ArSyn+BEE/+bXUHuaLRQEecYtpcw0bFMrz9AKZPOEavhpRuAyzzKInCQD37qmziZ5pomFR1Von7pIm5mdVn+lSkYX59n8eXCBVRSwnA7syu3w= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1565021699166591.3626054010884; Mon, 5 Aug 2019 09:14:59 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ADCF530EA18D; Mon, 5 Aug 2019 16:14:57 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 71A9360605; Mon, 5 Aug 2019 16:14:57 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3120618005C7; Mon, 5 Aug 2019 16:14:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x75GEeqs026343 for ; Mon, 5 Aug 2019 12:14:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id C4EEA60A97; Mon, 5 Aug 2019 16:14:40 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-137.brq.redhat.com [10.40.204.137]) by smtp.corp.redhat.com (Postfix) with ESMTP id 43E23608C1 for ; Mon, 5 Aug 2019 16:14:40 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 5 Aug 2019 18:14:23 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/5] qemu_firmware: Extend qemuFirmwareGetSupported to return FW paths X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 05 Aug 2019 16:14:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" The qemuFirmwareGetSupported() function is called from qemu driver to generate domain capabilities XML based on FW descriptor files. However, the function currently reports only some features from domcapabilities XML and not actual FW image paths. The paths reported in the domcapabilities XML still from from pre-FW descriptor era and therefore the XML might be a bit confusing. For instance, it may say that secure boot is supported but secboot enabled FW is not in the listed FW image paths. To resolve this problem, change qemuFirmwareGetSupported() so that it also returns a list of FW images (we have the list anyway). Luckily, we already have a structure to represent a FW image - virFirmware. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1733940 Signed-off-by: Michal Privoznik --- src/qemu/qemu_capabilities.c | 3 +- src/qemu/qemu_firmware.c | 62 +++++++++++++++++++++++++++++++++++- src/qemu/qemu_firmware.h | 5 ++- tests/qemufirmwaretest.c | 2 +- 4 files changed, 68 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 2388f145af..db1fc31cd9 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -5165,7 +5165,8 @@ virQEMUCapsFillDomainOSCaps(virDomainCapsOSPtr os, os->supported =3D VIR_TRISTATE_BOOL_YES; os->firmware.report =3D true; =20 - if (qemuFirmwareGetSupported(machine, arch, privileged, &autoFirmwares= , &secure) < 0) + if (qemuFirmwareGetSupported(machine, arch, privileged, + &autoFirmwares, &secure, NULL, NULL) < 0) return -1; =20 if (autoFirmwares & (1ULL << VIR_DOMAIN_OS_DEF_FIRMWARE_BIOS)) diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c index 8fbe8952ba..9ba38477cc 100644 --- a/src/qemu/qemu_firmware.c +++ b/src/qemu/qemu_firmware.c @@ -1420,6 +1420,8 @@ qemuFirmwareFillDomain(virQEMUDriverPtr driver, * @privileged: whether running as privileged user * @supported: returned bitmap of supported interfaces * @secure: true if at least one secure boot enabled FW was found + * @fws: (optional) list of found firmwares + * @nfws: (optional) number of members in @fws * * Parse all FW descriptors (depending whether running as @privileged this= may * or may not include user's $HOME) and for given combination of @machine = and @@ -1429,6 +1431,15 @@ qemuFirmwareFillDomain(virQEMUDriverPtr driver, * FW descriptor signalizes secure boot (although, this is checked against= SMM * rather than SECURE_BOOT because reasons). * + * If @fws and @nfws are not NULL, then @fws is allocated (must be freed by + * caller when no longer needed) and contains list of firmwares found in f= orm + * of virFirmware. This can be useful if caller wants to know the paths to + * firmware images (e.g. to present them in domain capabilities XML). + * Moreover, to allow the caller distinguish between no FW descriptors fou= nd + * and no matching FW descriptors found (nfws =3D=3D 0 in both cases), the= @fws is + * going to be allocated in case of the latter anyway (with no real content + * though). + * * Returns: 0 on success, * -1 otherwise. */ @@ -1437,7 +1448,9 @@ qemuFirmwareGetSupported(const char *machine, virArch arch, bool privileged, uint64_t *supported, - bool *secure) + bool *secure, + virFirmwarePtr **fws, + size_t *nfws) { qemuFirmwarePtr *firmwares =3D NULL; ssize_t nfirmwares =3D 0; @@ -1446,12 +1459,21 @@ qemuFirmwareGetSupported(const char *machine, *supported =3D VIR_DOMAIN_OS_DEF_FIRMWARE_NONE; *secure =3D false; =20 + if (fws) { + *fws =3D NULL; + *nfws =3D 0; + } + if ((nfirmwares =3D qemuFirmwareFetchParsedConfigs(privileged, &firmwares, NULL)) < = 0) return -1; =20 for (i =3D 0; i < nfirmwares; i++) { qemuFirmwarePtr fw =3D firmwares[i]; + const qemuFirmwareMappingFlash *flash =3D &fw->mapping.data.flash; + const qemuFirmwareMappingMemory *memory =3D &fw->mapping.data.memo= ry; + const char *fwpath =3D NULL; + const char *nvrampath =3D NULL; size_t j; =20 if (!qemuFirmwareMatchesMachineArch(fw, machine, arch)) @@ -1491,8 +1513,46 @@ qemuFirmwareGetSupported(const char *machine, break; } } + + switch (fw->mapping.device) { + case QEMU_FIRMWARE_DEVICE_FLASH: + fwpath =3D flash->executable.filename; + nvrampath =3D flash->nvram_template.filename; + break; + + case QEMU_FIRMWARE_DEVICE_MEMORY: + fwpath =3D memory->filename; + break; + + case QEMU_FIRMWARE_DEVICE_KERNEL: + case QEMU_FIRMWARE_DEVICE_NONE: + case QEMU_FIRMWARE_DEVICE_LAST: + break; + } + + if (fws && fwpath) { + VIR_AUTOPTR(virFirmware) tmp =3D NULL; + + /* Append only unique pairs. */ + for (j =3D 0; j < *nfws; j++) { + if (STREQ((*fws)[j]->name, fwpath) && + STREQ_NULLABLE((*fws)[j]->nvram, nvrampath)) + break; + } + + if (j =3D=3D *nfws && + (VIR_ALLOC(tmp) < 0 || + VIR_STRDUP(tmp->name, fwpath) < 0 || + VIR_STRDUP(tmp->nvram, nvrampath) < 0 || + VIR_APPEND_ELEMENT(*fws, *nfws, tmp) < 0)) + return -1; + } } =20 + if (fws && !*fws && nfirmwares && + VIR_REALLOC_N(*fws, 0) < 0) + return -1; + for (i =3D 0; i < nfirmwares; i++) qemuFirmwareFree(firmwares[i]); VIR_FREE(firmwares); diff --git a/src/qemu/qemu_firmware.h b/src/qemu/qemu_firmware.h index 6a3b6061f4..28e8322ec9 100644 --- a/src/qemu/qemu_firmware.h +++ b/src/qemu/qemu_firmware.h @@ -24,6 +24,7 @@ #include "qemu_conf.h" #include "virautoclean.h" #include "virarch.h" +#include "virfirmware.h" =20 typedef struct _qemuFirmware qemuFirmware; typedef qemuFirmware *qemuFirmwarePtr; @@ -53,6 +54,8 @@ qemuFirmwareGetSupported(const char *machine, virArch arch, bool privileged, uint64_t *supported, - bool *secure); + bool *secure, + virFirmwarePtr **fws, + size_t *nfws); =20 verify(VIR_DOMAIN_OS_DEF_FIRMWARE_LAST <=3D 64); diff --git a/tests/qemufirmwaretest.c b/tests/qemufirmwaretest.c index 2228359a7b..bab23f696e 100644 --- a/tests/qemufirmwaretest.c +++ b/tests/qemufirmwaretest.c @@ -123,7 +123,7 @@ testSupportedFW(const void *opaque) expectedInterfaces |=3D 1ULL << data->interfaces[i]; =20 if (qemuFirmwareGetSupported(data->machine, data->arch, false, - &actualInterfaces, &actualSecure) < 0) { + &actualInterfaces, &actualSecure, NULL, N= ULL) < 0) { fprintf(stderr, "Unable to get list of supported interfaces\n"); return -1; } --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list