[PATCH] qemu: Move CPU validation out of PostParse
by Michal Privoznik
The qemuDomainDefCPUPostParse() does a bit more than filling in
missing info. It also validates CPU cache configuration. Move
that code into qemuValidateDomainDefCpu() where the code fits
better.
And since I need to fix indentation of existing code in
qemuValidateDomainDefCpu(), I'm taking this opportunity and move
error messages onto single line. Interestingly, this uncovers a
bug we have in sc_prohibit_diagnostic_without_format syntax-check
rule, because previously a virReportError() with a message
spawned over three lines was not caught but not it is. But
trying to understand that regex is a job for another time.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/qemu/qemu_domain.c | 56 -----------------
src/qemu/qemu_validate.c | 129 +++++++++++++++++++++++++++------------
2 files changed, 89 insertions(+), 96 deletions(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index a53c25f36e..61a7297599 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4373,62 +4373,6 @@ qemuDomainDefCPUPostParse(virDomainDef *def,
if (!def->cpu)
return 0;
- if (def->cpu->cache) {
- virCPUCacheDef *cache = def->cpu->cache;
-
- if (!ARCH_IS_X86(def->os.arch)) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("CPU cache specification is not supported "
- "for '%s' architecture"),
- virArchToString(def->os.arch));
- return -1;
- }
-
- switch (cache->mode) {
- case VIR_CPU_CACHE_MODE_EMULATE:
- if (cache->level != 3) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("CPU cache mode '%s' can only be used with "
- "level='3'"),
- virCPUCacheModeTypeToString(cache->mode));
- return -1;
- }
- break;
-
- case VIR_CPU_CACHE_MODE_PASSTHROUGH:
- if (def->cpu->mode != VIR_CPU_MODE_HOST_PASSTHROUGH &&
- def->cpu->mode != VIR_CPU_MODE_MAXIMUM) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("CPU cache mode '%s' can only be used with "
- "'%s' / '%s' CPUs"),
- virCPUCacheModeTypeToString(cache->mode),
- virCPUModeTypeToString(VIR_CPU_MODE_HOST_PASSTHROUGH),
- virCPUModeTypeToString(VIR_CPU_MODE_MAXIMUM));
- return -1;
- }
-
- if (cache->level != -1) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("unsupported CPU cache level for mode '%s'"),
- virCPUCacheModeTypeToString(cache->mode));
- return -1;
- }
- break;
-
- case VIR_CPU_CACHE_MODE_DISABLE:
- if (cache->level != -1) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("unsupported CPU cache level for mode '%s'"),
- virCPUCacheModeTypeToString(cache->mode));
- return -1;
- }
- break;
-
- case VIR_CPU_CACHE_MODE_LAST:
- break;
- }
- }
-
for (i = 0; i < def->cpu->nfeatures; i++) {
virCPUFeatureDef *feature = &def->cpu->features[i];
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 48bd40db9f..7fa899e411 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -332,52 +332,101 @@ qemuValidateDomainDefCpu(virQEMUDriver *driver,
if (!cpu)
return 0;
- if (!cpu->model && cpu->mode == VIR_CPU_MODE_CUSTOM)
- return 0;
-
- switch ((virCPUMode) cpu->mode) {
- case VIR_CPU_MODE_HOST_PASSTHROUGH:
- if (def->os.arch == VIR_ARCH_ARMV7L &&
- driver->hostarch == VIR_ARCH_AARCH64) {
- if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_AARCH64_OFF)) {
+ if (def->cpu->cache) {
+ virCPUCacheDef *cache = def->cpu->cache;
+
+ if (!ARCH_IS_X86(def->os.arch)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("CPU cache specification is not supported for '%s' architecture"),
+ virArchToString(def->os.arch));
+ return -1;
+ }
+
+ switch (cache->mode) {
+ case VIR_CPU_CACHE_MODE_EMULATE:
+ if (cache->level != 3) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("QEMU binary does not support CPU "
- "host-passthrough for armv7l on "
- "aarch64 host"));
+ _("CPU cache mode '%s' can only be used with level='3'"),
+ virCPUCacheModeTypeToString(cache->mode));
return -1;
}
- }
+ break;
- if (cpu->migratable &&
- cpu->migratable != VIR_TRISTATE_SWITCH_OFF &&
- !virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_MIGRATABLE)) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("Migratable attribute for host-passthrough "
- "CPU is not supported by this QEMU binary"));
- return -1;
- }
- break;
-
- case VIR_CPU_MODE_HOST_MODEL:
- /* qemu_command.c will error out if cpu->mode is HOST_MODEL for
- * every arch but PPC64. However, we can't move this validation
- * here because non-PPC64 archs will translate HOST_MODEL to
- * something else during domain start, changing cpu->mode to
- * CUSTOM.
- */
- break;
-
- case VIR_CPU_MODE_MAXIMUM:
- if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_MAX)) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("maximum CPU is not supported by QEMU binary"));
- return -1;
+ case VIR_CPU_CACHE_MODE_PASSTHROUGH:
+ if (def->cpu->mode != VIR_CPU_MODE_HOST_PASSTHROUGH &&
+ def->cpu->mode != VIR_CPU_MODE_MAXIMUM) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("CPU cache mode '%s' can only be used with '%s' / '%s' CPUs"),
+ virCPUCacheModeTypeToString(cache->mode),
+ virCPUModeTypeToString(VIR_CPU_MODE_HOST_PASSTHROUGH),
+ virCPUModeTypeToString(VIR_CPU_MODE_MAXIMUM));
+ return -1;
+ }
+
+ if (cache->level != -1) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("unsupported CPU cache level for mode '%s'"),
+ virCPUCacheModeTypeToString(cache->mode));
+ return -1;
+ }
+ break;
+
+ case VIR_CPU_CACHE_MODE_DISABLE:
+ if (cache->level != -1) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("unsupported CPU cache level for mode '%s'"),
+ virCPUCacheModeTypeToString(cache->mode));
+ return -1;
+ }
+ break;
+
+ case VIR_CPU_CACHE_MODE_LAST:
+ break;
}
- break;
+ }
+
+ if (cpu->model || cpu->mode != VIR_CPU_MODE_CUSTOM) {
+ switch ((virCPUMode) cpu->mode) {
+ case VIR_CPU_MODE_HOST_PASSTHROUGH:
+ if (def->os.arch == VIR_ARCH_ARMV7L &&
+ driver->hostarch == VIR_ARCH_AARCH64) {
+ if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_AARCH64_OFF)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("QEMU binary does not support CPU host-passthrough for armv7l on aarch64 host"));
+ return -1;
+ }
+ }
- case VIR_CPU_MODE_CUSTOM:
- case VIR_CPU_MODE_LAST:
- break;
+ if (cpu->migratable &&
+ cpu->migratable != VIR_TRISTATE_SWITCH_OFF &&
+ !virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_MIGRATABLE)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("Migratable attribute for host-passthrough CPU is not supported by this QEMU binary"));
+ return -1;
+ }
+ break;
+
+ case VIR_CPU_MODE_HOST_MODEL:
+ /* qemu_command.c will error out if cpu->mode is HOST_MODEL for
+ * every arch but PPC64. However, we can't move this validation
+ * here because non-PPC64 archs will translate HOST_MODEL to
+ * something else during domain start, changing cpu->mode to
+ * CUSTOM.
+ */
+ break;
+
+ case VIR_CPU_MODE_MAXIMUM:
+ if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_CPU_MAX)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("maximum CPU is not supported by QEMU binary"));
+ return -1;
+ }
+ break;
+
+ case VIR_CPU_MODE_CUSTOM:
+ case VIR_CPU_MODE_LAST:
+ break;
+ }
}
return 0;
--
2.35.1
2 years, 4 months
[libvirt PATCH] qemu: Reset stored memlock limit when stopping QEMU
by Jiri Denemark
When resetting private data after stopping QEMU process we should also
reset the original memory locking limit (both normal and pre-migration)
as they are not relevant anymore.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/qemu/qemu_domain.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index a53c25f36e..12c58a25b9 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1705,6 +1705,9 @@ qemuDomainObjPrivateDataClear(qemuDomainObjPrivate *priv)
g_slist_free_full(g_steal_pointer(&priv->dbusVMStateIds), g_free);
priv->dbusVMState = false;
+
+ priv->originalMemlock = 0;
+ priv->preMigrationMemlock = 0;
}
--
2.35.1
2 years, 4 months
[libvirt PATCH] qemu: Do not try to set memlock on inactive domain
by Jiri Denemark
When we call qemuDomainSetMaxMemLock to reset memory locking limit back
to its original value the domain can already be stopped (for example
after the domain shuts down during migration) in which case it does not
make sense to set any limit. Doing so can even be harmful as we may end
up setting the limit for the daemon itself as the PID is 0.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
src/qemu/qemu_domain.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 12c58a25b9..ad6c614d89 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -9461,6 +9461,10 @@ qemuDomainSetMaxMemLock(virDomainObj *vm,
{
unsigned long long current = 0;
+ /* nothing to do if the domain is not running */
+ if (vm->pid <= 0)
+ return 0;
+
if (virProcessGetMaxMemLock(vm->pid, ¤t) < 0)
return -1;
--
2.35.1
2 years, 4 months
[PATCH 0/4] testutilsqemu: Fake TPM versions
by Michal Privoznik
Technically, this is a v2 of:
https://listman.redhat.com/archives/libvir-list/2022-July/233306.html
but not really. Because I've discarded the 3/3 from original series and
implemented Andrea's idea.
Michal Prívozník (4):
src: Export virDomainTPMVersion enum conversion helpers
testutilsqemu: Fake TPM versions
qemu_validate: Validate TPM version
qemuxml2argvtest: Add negative cases for TPM version
src/libvirt_private.syms | 2 ++
src/qemu/qemu_validate.c | 15 ++++++++++++---
tests/domaincapsdata/qemu_3.1.0-q35.x86_64.xml | 3 +++
tests/domaincapsdata/qemu_3.1.0-tcg.x86_64.xml | 3 +++
tests/domaincapsdata/qemu_3.1.0.x86_64.xml | 3 +++
tests/domaincapsdata/qemu_4.0.0-q35.x86_64.xml | 3 +++
tests/domaincapsdata/qemu_4.0.0-tcg.x86_64.xml | 3 +++
tests/domaincapsdata/qemu_4.0.0.x86_64.xml | 3 +++
tests/domaincapsdata/qemu_4.1.0-q35.x86_64.xml | 3 +++
tests/domaincapsdata/qemu_4.1.0-tcg.x86_64.xml | 3 +++
tests/domaincapsdata/qemu_4.1.0.x86_64.xml | 3 +++
tests/domaincapsdata/qemu_4.2.0-q35.x86_64.xml | 3 +++
tests/domaincapsdata/qemu_4.2.0-tcg.x86_64.xml | 3 +++
tests/domaincapsdata/qemu_4.2.0.ppc64.xml | 3 +++
tests/domaincapsdata/qemu_4.2.0.x86_64.xml | 3 +++
tests/domaincapsdata/qemu_5.0.0-q35.x86_64.xml | 3 +++
tests/domaincapsdata/qemu_5.0.0-tcg.x86_64.xml | 3 +++
.../domaincapsdata/qemu_5.0.0-virt.aarch64.xml | 3 +++
tests/domaincapsdata/qemu_5.0.0.aarch64.xml | 3 +++
tests/domaincapsdata/qemu_5.0.0.ppc64.xml | 3 +++
tests/domaincapsdata/qemu_5.0.0.x86_64.xml | 3 +++
tests/domaincapsdata/qemu_5.1.0-q35.x86_64.xml | 3 +++
tests/domaincapsdata/qemu_5.1.0-tcg.x86_64.xml | 3 +++
tests/domaincapsdata/qemu_5.1.0.x86_64.xml | 3 +++
tests/domaincapsdata/qemu_5.2.0-q35.x86_64.xml | 3 +++
tests/domaincapsdata/qemu_5.2.0-tcg.x86_64.xml | 3 +++
.../domaincapsdata/qemu_5.2.0-virt.aarch64.xml | 3 +++
tests/domaincapsdata/qemu_5.2.0.aarch64.xml | 3 +++
tests/domaincapsdata/qemu_5.2.0.ppc64.xml | 3 +++
tests/domaincapsdata/qemu_5.2.0.x86_64.xml | 3 +++
tests/domaincapsdata/qemu_6.0.0-q35.x86_64.xml | 4 ++++
tests/domaincapsdata/qemu_6.0.0-tcg.x86_64.xml | 4 ++++
.../domaincapsdata/qemu_6.0.0-virt.aarch64.xml | 4 ++++
tests/domaincapsdata/qemu_6.0.0.aarch64.xml | 4 ++++
tests/domaincapsdata/qemu_6.0.0.x86_64.xml | 4 ++++
tests/domaincapsdata/qemu_6.1.0-q35.x86_64.xml | 4 ++++
tests/domaincapsdata/qemu_6.1.0-tcg.x86_64.xml | 4 ++++
tests/domaincapsdata/qemu_6.1.0.x86_64.xml | 4 ++++
tests/domaincapsdata/qemu_6.2.0-q35.x86_64.xml | 4 ++++
tests/domaincapsdata/qemu_6.2.0-tcg.x86_64.xml | 4 ++++
.../domaincapsdata/qemu_6.2.0-virt.aarch64.xml | 4 ++++
tests/domaincapsdata/qemu_6.2.0.aarch64.xml | 4 ++++
tests/domaincapsdata/qemu_6.2.0.ppc64.xml | 4 ++++
tests/domaincapsdata/qemu_6.2.0.x86_64.xml | 4 ++++
tests/domaincapsdata/qemu_7.0.0-q35.x86_64.xml | 3 +++
tests/domaincapsdata/qemu_7.0.0-tcg.x86_64.xml | 3 +++
.../domaincapsdata/qemu_7.0.0-virt.aarch64.xml | 3 +++
tests/domaincapsdata/qemu_7.0.0.aarch64.xml | 3 +++
tests/domaincapsdata/qemu_7.0.0.ppc64.xml | 3 +++
tests/domaincapsdata/qemu_7.0.0.x86_64.xml | 3 +++
tests/domaincapsdata/qemu_7.1.0-q35.x86_64.xml | 3 +++
tests/domaincapsdata/qemu_7.1.0-tcg.x86_64.xml | 3 +++
tests/domaincapsdata/qemu_7.1.0.x86_64.xml | 3 +++
tests/domaincapstest.c | 17 ++++++++++++++++-
.../tpm-emulator-tpm2.x86_64-latest.err | 1 +
.../tpm-emulator.x86_64-latest.err | 1 +
tests/qemuxml2argvtest.c | 6 ++++++
tests/testutilsqemu.c | 13 +++++++++++--
tests/testutilsqemu.h | 3 +++
59 files changed, 219 insertions(+), 6 deletions(-)
create mode 100644 tests/qemuxml2argvdata/tpm-emulator-tpm2.x86_64-latest.err
create mode 100644 tests/qemuxml2argvdata/tpm-emulator.x86_64-latest.err
--
2.35.1
2 years, 4 months
[PATCH 0/6] qemu: Remove monitor socket waiting code
by Peter Krempa
We either pre-open a socket and pass the file descriptor to qemu or are
guaranteed that the socket is open by other means.
The qemu monitor code can be simplified a lot.
Peter Krempa (6):
qemu: process: Remove 'retry' argument from qemuConnectMonitor
qemu: monitor: Remove 'timeout' argument from qemuMonitorOpen
qemuMonitorTestNew: Call qemuMonitorOpen with 'retry' false
qemuProcessQMPConnectMonitor: Connect to probing monitor with 'retry'
set to false
qemuMonitorOpenUnix: Remove 'retry' argument
qemuMonitorOpenUnix: Don't overwrite 'ret' needlessly
src/qemu/qemu_monitor.c | 59 +++++-------------------------------
src/qemu/qemu_monitor.h | 4 +--
src/qemu/qemu_process.c | 24 +++------------
tests/qemumonitortestutils.c | 2 --
4 files changed, 13 insertions(+), 76 deletions(-)
--
2.36.1
2 years, 4 months
[PATCH] qemu_capabilities: replace code with function call
by Kristina Hanicova
Since functions virQEMUCapsFillDomainFeatureSEVCaps() and
virQEMUCapsSEVInfoCopy() essentially do the same thing it does
not make sense to have the code duplicated. This patch replaces
the relevant code in the first function with the function call to
the second one.
Signed-off-by: Kristina Hanicova <khanicov(a)redhat.com>
---
Notes:
Pointed out by Michal
src/qemu/qemu_capabilities.c | 13 +------------
1 file changed, 1 insertion(+), 12 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index b002fb98ed..53223417ae 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -6495,18 +6495,7 @@ virQEMUCapsFillDomainFeatureSEVCaps(virQEMUCaps *qemuCaps,
if (!cap)
return;
- domCaps->sev = g_new0(virSEVCapability, 1);
-
- domCaps->sev->pdh = g_strdup(cap->pdh);
- domCaps->sev->cert_chain = g_strdup(cap->cert_chain);
- if (cap->cpu0_id != NULL) {
- domCaps->sev->cpu0_id = g_strdup(cap->cpu0_id);
- }
-
- domCaps->sev->cbitpos = cap->cbitpos;
- domCaps->sev->reduced_phys_bits = cap->reduced_phys_bits;
- domCaps->sev->max_guests = cap->max_guests;
- domCaps->sev->max_es_guests = cap->max_es_guests;
+ virQEMUCapsSEVInfoCopy(&domCaps->sev, cap);
}
--
2.37.1
2 years, 4 months
[libvirt PATCH 0/2] fix console device access in ch driver
by Praveen K Paladugu
Patch1:
Drops the check to only have a console/serial device configured
for ch VMs. This is no longer needed.
Patch2:
Addresses https://gitlab.com/libvirt/libvirt/-/issues/344. Libvirt adds compat
console devices for "hvm" VMs. The added console/serial device type is
initialized to VIR_DOMAIN_CHR_TYPE_NULL, when in fact the device added is a pty
device. This patch modifies the default console device type to "pty".
I looked at NOT adding Compat Console devices for ch VMs. But this looked like
a better fix.
Praveen K Paladugu (2):
ch: drop the check to have a single console/serial
conf: set the default chr device type to pty
src/ch/ch_domain.c | 9 +--------
src/conf/domain_conf.c | 1 +
2 files changed, 2 insertions(+), 8 deletions(-)
--
2.27.0
2 years, 4 months
[PATCH 0/3] testutilsqemu: Fake TPM versions
by Michal Privoznik
I thought I've sent these before the freeze but as I tried to ping them,
I realize I didn't. I'm not sure how critical these are to get into the
release (after all we see no test failing), but they make at least
VIR_TEST_DEBUG output of domcapabilities cleaner.
Michal Prívozník (3):
virtpm: Use corresponding type for argument for virTPM*CapsGet()
testutilsqemu: Mock virTPMSwtpmSetupCapsGet()
testutilsqemu: Fake TPM versions
src/util/virtpm.c | 4 ++--
src/util/virtpm.h | 6 +++---
.../domaincapsdata/qemu_3.1.0-q35.x86_64.xml | 4 ++++
.../domaincapsdata/qemu_3.1.0-tcg.x86_64.xml | 4 ++++
tests/domaincapsdata/qemu_3.1.0.x86_64.xml | 4 ++++
.../domaincapsdata/qemu_4.0.0-q35.x86_64.xml | 4 ++++
.../domaincapsdata/qemu_4.0.0-tcg.x86_64.xml | 4 ++++
tests/domaincapsdata/qemu_4.0.0.x86_64.xml | 4 ++++
.../domaincapsdata/qemu_4.1.0-q35.x86_64.xml | 4 ++++
.../domaincapsdata/qemu_4.1.0-tcg.x86_64.xml | 4 ++++
tests/domaincapsdata/qemu_4.1.0.x86_64.xml | 4 ++++
.../domaincapsdata/qemu_4.2.0-q35.x86_64.xml | 4 ++++
.../domaincapsdata/qemu_4.2.0-tcg.x86_64.xml | 4 ++++
tests/domaincapsdata/qemu_4.2.0.ppc64.xml | 4 ++++
tests/domaincapsdata/qemu_4.2.0.x86_64.xml | 4 ++++
.../domaincapsdata/qemu_5.0.0-q35.x86_64.xml | 4 ++++
.../domaincapsdata/qemu_5.0.0-tcg.x86_64.xml | 4 ++++
.../qemu_5.0.0-virt.aarch64.xml | 4 ++++
tests/domaincapsdata/qemu_5.0.0.aarch64.xml | 4 ++++
tests/domaincapsdata/qemu_5.0.0.ppc64.xml | 4 ++++
tests/domaincapsdata/qemu_5.0.0.x86_64.xml | 4 ++++
.../domaincapsdata/qemu_5.1.0-q35.x86_64.xml | 4 ++++
.../domaincapsdata/qemu_5.1.0-tcg.x86_64.xml | 4 ++++
tests/domaincapsdata/qemu_5.1.0.x86_64.xml | 4 ++++
.../domaincapsdata/qemu_5.2.0-q35.x86_64.xml | 4 ++++
.../domaincapsdata/qemu_5.2.0-tcg.x86_64.xml | 4 ++++
.../qemu_5.2.0-virt.aarch64.xml | 4 ++++
tests/domaincapsdata/qemu_5.2.0.aarch64.xml | 4 ++++
tests/domaincapsdata/qemu_5.2.0.ppc64.xml | 4 ++++
tests/domaincapsdata/qemu_5.2.0.x86_64.xml | 4 ++++
.../domaincapsdata/qemu_6.0.0-q35.x86_64.xml | 4 ++++
.../domaincapsdata/qemu_6.0.0-tcg.x86_64.xml | 4 ++++
.../qemu_6.0.0-virt.aarch64.xml | 4 ++++
tests/domaincapsdata/qemu_6.0.0.aarch64.xml | 4 ++++
tests/domaincapsdata/qemu_6.0.0.x86_64.xml | 4 ++++
.../domaincapsdata/qemu_6.1.0-q35.x86_64.xml | 4 ++++
.../domaincapsdata/qemu_6.1.0-tcg.x86_64.xml | 4 ++++
tests/domaincapsdata/qemu_6.1.0.x86_64.xml | 4 ++++
.../domaincapsdata/qemu_6.2.0-q35.x86_64.xml | 4 ++++
.../domaincapsdata/qemu_6.2.0-tcg.x86_64.xml | 4 ++++
.../qemu_6.2.0-virt.aarch64.xml | 4 ++++
tests/domaincapsdata/qemu_6.2.0.aarch64.xml | 4 ++++
tests/domaincapsdata/qemu_6.2.0.ppc64.xml | 4 ++++
tests/domaincapsdata/qemu_6.2.0.x86_64.xml | 4 ++++
.../domaincapsdata/qemu_7.0.0-q35.x86_64.xml | 4 ++++
.../domaincapsdata/qemu_7.0.0-tcg.x86_64.xml | 4 ++++
.../qemu_7.0.0-virt.aarch64.xml | 4 ++++
tests/domaincapsdata/qemu_7.0.0.aarch64.xml | 4 ++++
tests/domaincapsdata/qemu_7.0.0.ppc64.xml | 4 ++++
tests/domaincapsdata/qemu_7.0.0.x86_64.xml | 4 ++++
.../domaincapsdata/qemu_7.1.0-q35.x86_64.xml | 4 ++++
.../domaincapsdata/qemu_7.1.0-tcg.x86_64.xml | 4 ++++
tests/domaincapsdata/qemu_7.1.0.x86_64.xml | 4 ++++
tests/testutilsqemu.c | 19 +++++++++++++++++++
54 files changed, 228 insertions(+), 5 deletions(-)
--
2.35.1
2 years, 4 months
[PATCH] tpm: Refactor open-coded bitmap 'activePcrBanks' to virBitmap
by Peter Krempa
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
Applies on top of Michal's series to fix 'activePcrBank' handling.
src/conf/domain_conf.c | 17 +++++++++--------
src/conf/domain_conf.h | 2 +-
src/qemu/qemu_tpm.c | 21 +++++++++------------
3 files changed, 19 insertions(+), 21 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ddd6fe1c90..fccb29bc63 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -3255,6 +3255,7 @@ void virDomainTPMDefFree(virDomainTPMDef *def)
virObjectUnref(def->data.emulator.source);
g_free(def->data.emulator.storagepath);
g_free(def->data.emulator.logfile);
+ virBitmapFree(def->data.emulator.activePcrBanks);
break;
case VIR_DOMAIN_TPM_TYPE_LAST:
break;
@@ -10442,6 +10443,8 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt,
if ((nnodes = virXPathNodeSet("./backend/active_pcr_banks/*", ctxt, &nodes)) < 0)
break;
+ if (nnodes > 0)
+ def->data.emulator.activePcrBanks = virBitmapNew(0);
for (i = 0; i < nnodes; i++) {
if ((bank = virDomainTPMPcrBankTypeFromString((const char *)nodes[i]->name)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -10449,7 +10452,7 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt,
nodes[i]->name);
goto error;
}
- def->data.emulator.activePcrBanks |= (1 << bank);
+ virBitmapSetBitExpand(def->data.emulator.activePcrBanks, bank);
}
break;
case VIR_DOMAIN_TPM_TYPE_LAST:
@@ -20671,7 +20674,8 @@ virDomainTPMDefCheckABIStability(virDomainTPMDef *src,
return false;
}
- if (src->data.emulator.activePcrBanks != dst->data.emulator.activePcrBanks) {
+ if (!virBitmapEqual(src->data.emulator.activePcrBanks,
+ dst->data.emulator.activePcrBanks)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Target active PCR banks doesn't match source"));
return false;
@@ -24235,13 +24239,10 @@ virDomainTPMDefFormat(virBuffer *buf,
}
if (def->data.emulator.activePcrBanks) {
g_auto(virBuffer) activePcrBanksBuf = VIR_BUFFER_INIT_CHILD(&backendChildBuf);
- size_t i;
+ ssize_t bank = -1;
- for (i = VIR_DOMAIN_TPM_PCR_BANK_SHA1; i < VIR_DOMAIN_TPM_PCR_BANK_LAST; i++) {
- if ((def->data.emulator.activePcrBanks & (1 << i)))
- virBufferAsprintf(&activePcrBanksBuf, "<%s/>\n",
- virDomainTPMPcrBankTypeToString(i));
- }
+ while ((bank = virBitmapNextSetBit(def->data.emulator.activePcrBanks, bank)) > -1)
+ virBufferAsprintf(&activePcrBanksBuf, "<%s/>\n", virDomainTPMPcrBankTypeToString(bank));
virXMLFormatElement(&backendChildBuf, "active_pcr_banks", NULL, &activePcrBanksBuf);
}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 200a75d705..724265b6b5 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1451,7 +1451,7 @@ struct _virDomainTPMDef {
unsigned char secretuuid[VIR_UUID_BUFLEN];
bool hassecretuuid;
bool persistent_state;
- unsigned int activePcrBanks;
+ virBitmap *activePcrBanks;
} emulator;
} data;
};
diff --git a/src/qemu/qemu_tpm.c b/src/qemu/qemu_tpm.c
index f28dd2e1e9..c08b0851da 100644
--- a/src/qemu/qemu_tpm.c
+++ b/src/qemu/qemu_tpm.c
@@ -444,19 +444,16 @@ qemuTPMEmulatorRunSetup(const char *storagepath,
static char *
-qemuTPMPcrBankBitmapToStr(unsigned int pcrBanks)
+qemuTPMPcrBankBitmapToStr(virBitmap *activePcrBanks)
{
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
- const char *comma = "";
- size_t i;
-
- for (i = VIR_DOMAIN_TPM_PCR_BANK_SHA1; i < VIR_DOMAIN_TPM_PCR_BANK_LAST; i++) {
- if (pcrBanks & (1 << i)) {
- virBufferAsprintf(&buf, "%s%s",
- comma, virDomainTPMPcrBankTypeToString(i));
- comma = ",";
- }
- }
+ ssize_t bank = -1;
+
+ while ((bank = virBitmapNextSetBit(activePcrBanks, bank)) > -1)
+ virBufferAsprintf(&buf, "%s,", virDomainTPMPcrBankTypeToString(bank));
+
+ virBufferTrim(&buf, ",");
+
return virBufferContentAndReset(&buf);
}
@@ -481,7 +478,7 @@ static int
qemuTPMEmulatorReconfigure(const char *storagepath,
uid_t swtpm_user,
gid_t swtpm_group,
- unsigned int activePcrBanks,
+ virBitmap *activePcrBanks,
const char *logfile,
const virDomainTPMVersion tpmversion,
const unsigned char *secretuuid)
--
2.36.1
2 years, 4 months