On 11/11/26 5:19 PM, Collin Walling wrote:
On 11/11/26 10:51, Boris Fiuczynski wrote:
On 10/20/26 06:15, Rorie Reyes wrote:
Add a new helper qemuProcessCheckS390CPU() in qemu_process.c that wraps the QMP query-cpu-model-comparison probe for s390x and returns a virCPUCompareResult directly. The helper filters out the special "type" responsible-property (which signals a CPU generation mismatch rather than a missing feature) before reporting incompatibility to the caller.
When reporting incompatibility, the differing properties are listed in the error message when available. If no responsible-properties are returned (or all are filtered out), a generic incompatibility message is reported instead.
Wire the helper into qemuProcessUpdateGuestCPU() so that s390x CPU model compatibility is checked for real domain start paths (migration, snapshot restore) when the QEMU_CAPS_QUERY_CPU_MODEL_COMPARISON capability is present. The host CPU is passed as the first argument and the guest CPU as the second, matching qemuConnectCPUModelComparison(). The check is skipped in pretend mode (VIR_QEMU_PROCESS_START_PRETEND) since that path is used for command-line generation and does not involve a running QEMU instance. It is also skipped when the guest CPU definition has no model yet (for example host-model on a fresh start), since that model is resolved from the host CPU later and cannot be incompatible with it.
Simplify qemuConnectCPUModelComparison() in qemu_driver.c to delegate directly to qemuProcessCheckS390CPU().
Signed-off-by: Rorie Reyes <rreyes@linux.ibm.com> --- src/qemu/qemu_driver.c | 23 ++----------- src/qemu/qemu_process.c | 75 +++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_process.h | 9 +++++ 3 files changed, 86 insertions(+), 21 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 199eedca36..ef549a2c02 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12127,27 +12127,8 @@ qemuConnectCPUModelComparison(virQEMUCaps *qemuCaps, virCPUDef *cpu_b, bool failIncompatible) { - g_autoptr(qemuProcessQMP) proc = NULL; - virCPUCompareResult result; - - if (!(proc = qemuProcessQMPNew(virQEMUCapsGetBinary(qemuCaps), - libDir, runUid, runGid, false))) - return VIR_CPU_COMPARE_ERROR; - - if (qemuProcessQMPStart(proc) < 0) - return VIR_CPU_COMPARE_ERROR; - - result = qemuMonitorGetCPUModelComparison(proc->mon, cpu_a, cpu_b, NULL); - - if (result == VIR_CPU_COMPARE_ERROR) - return VIR_CPU_COMPARE_ERROR; - - if (failIncompatible && result == VIR_CPU_COMPARE_INCOMPATIBLE) { - virReportError(VIR_ERR_CPU_INCOMPATIBLE, NULL); - return VIR_CPU_COMPARE_ERROR; - } - - return result; + return qemuProcessCheckS390CPU(qemuCaps, libDir, runUid, runGid, + cpu_a, cpu_b, failIncompatible); }
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 3f1960f314..dfb9e0785a 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6708,6 +6708,20 @@ qemuProcessUpdateGuestCPU(virDomainDef *def, VIR_QEMU_CAPS_HOST_CPU_FULL, true) < 0) return -1;
+ if (!(flags & VIR_QEMU_PROCESS_START_PRETEND) && + def->cpu->model && + ARCH_IS_S390(hostarch) && + virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_COMPARISON)) { Shouldn't there be def->cpu->check != VIR_CPU_CHECK_NONE && included here?
You're right. If '<cpu check='none'>' is specified, libvirt should skip host CPU compatibility checks. I'll add your suggestion to the condition for v3
+ virCPUDef *hvCPU = virQEMUCapsGetHostModel(qemuCaps, def->virtType, + VIR_QEMU_CAPS_HOST_CPU_REPORTED); + + if (hvCPU && hvCPU->fallback == VIR_CPU_FALLBACK_FORBID && + qemuProcessCheckS390CPU(qemuCaps, cfg->libDir, + cfg->user, cfg->group, + hvCPU, def->cpu, true) == VIR_CPU_COMPARE_ERROR) Collin and Rorie, I am bit concerned and did not have the time to test it but didn't we specifically reuse the existing qemu comparecpu method calling it with reversing the host and guest cpu parameters for checking the migration scenario? How does that work out on the regular start pattern? Yes, as the idea when going into the design of this code was with the mindset of: "we need to explicitly compare the guest CPU model to the host's CPU model". Within the context of the migration code, this was fine. We also extended the JSON monitor code for compare to recognize SUPERSET for this.
Now, this is being used as a precheck for guest creation as well, we have to acknowledge that the precendent of comparing host-to-guest was there. It makes more sense to follow this scheme to reduce changes elsewhere.
It makes no difference if the comparison is guest-to-host or host-to-guest. The former considers SUPERSET as incompatible, the latter SUBSET as incompatible. That is the only difference.
Note about the reported properties: the query-cpu-model-comparison's properties do not indicate which model is missing the reported features. So comparing reverse or original does not produce a different result w.r.t. reported properties.
As Collin explained, passing (hvCPU, def->cpu) evaluates whether the host provides everything the guest requires, which applies equally to incoming migration and local guest startup. As Jiri pointed out in v1, libvirt handles CPU validation for both paths in qemuProcessUpdateGuestCPU().
Also note that now when starting there is always an extra qemu process being spawned which we did not do for the required expansion fetching it from the cached probed qemu capabilities.
Fair point. According to the commit message, guest start using host-model should skip this precheck, since host-model should be safe to run anyway.
I'd like to verify this on my end to make sure, and see if there are any edge cases missed. (e.g. verify skip on host-model, use custom, host-model with deprecated_features=on|off... let me know if you think of others).
In the worst case: it's an ephemeral QEMU instance. I don't think it'll have much of an impact on a single guest-start. Though I am unsure of the cost when the number of concurrent guest-starts scales up.
Regarding the ephemeral QEMU process on start: 1. Fresh starts using 'host-model' (the default) have def->cpu->model == NULL at this point, so fresh host-model starts will skip this probe entirely 2. For 'custom' CPU models (with check != 'none'), running the probe ensures we detect missing features early and report the responsible properties rather than failing with an unhelpful error during QEMU startup.
+ return -1; + } + /* When starting a fresh domain we disable all features removed from * the specified CPU model to make sure they are only used if * explicitly requested. But when we are restoring a previously running @@ -10589,6 +10603,67 @@ qemuProcessQMPStart(qemuProcessQMP *proc) }
+virCPUCompareResult +qemuProcessCheckS390CPU(virQEMUCaps *qemuCaps, + const char *libDir, + uid_t runUid, + gid_t runGid, + virCPUDef *cpu_a, + virCPUDef *cpu_b, + bool failIncompatible) +{ + g_autoptr(qemuProcessQMP) proc = NULL; + g_auto(GStrv) responsibleProps = NULL; + virCPUCompareResult result; + + if (!(proc = qemuProcessQMPNew(virQEMUCapsGetBinary(qemuCaps), + libDir, runUid, runGid, false))) + return VIR_CPU_COMPARE_ERROR; + + if (qemuProcessQMPStart(proc) < 0) + return VIR_CPU_COMPARE_ERROR; + + result = qemuMonitorGetCPUModelComparison(proc->mon, cpu_a, cpu_b, + &responsibleProps); + + if (result == VIR_CPU_COMPARE_ERROR) + return VIR_CPU_COMPARE_ERROR; + + if (result == VIR_CPU_COMPARE_IDENTICAL || result == VIR_CPU_COMPARE_SUPERSET) + return result; + + /* result is VIR_CPU_COMPARE_INCOMPATIBLE — filter out the special "type" + * property which signals a CPU generation mismatch rather than a missing + * feature and should not be reported as such to the user. */ + if (responsibleProps) { + size_t i, j; + for (i = 0, j = 0; responsibleProps[i]; i++) { + if (STRNEQ(responsibleProps[i], "type")) + responsibleProps[j++] = responsibleProps[i]; + else + g_free(responsibleProps[i]); + } + responsibleProps[j] = NULL; + } + + if (failIncompatible) { + if (responsibleProps && responsibleProps[0]) { + g_autofree char *props = g_strjoinv(", ", responsibleProps); + + virReportError(VIR_ERR_CPU_INCOMPATIBLE, + _("guest CPU model is not compatible with the destination host CPU model, differing properties: %1$s"), + props); + } else { + virReportError(VIR_ERR_CPU_INCOMPATIBLE, "%s", + _("guest CPU model is not compatible with the destination host CPU model")); + } + return VIR_CPU_COMPARE_ERROR; + } + + return VIR_CPU_COMPARE_INCOMPATIBLE; +} + + void qemuProcessHandleNbdkitExit(qemuNbdkitProcess *nbdkit, virDomainObj *vm) diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index 5d8f1f89d5..d9dd5e185e 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -258,6 +258,15 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuProcessQMP, qemuProcessQMPFree);
int qemuProcessQMPStart(qemuProcessQMP *proc);
+virCPUCompareResult +qemuProcessCheckS390CPU(virQEMUCaps *qemuCaps, + const char *libDir, + uid_t runUid, + gid_t runGid, + virCPUDef *cpu_a, + virCPUDef *cpu_b, + bool failIncompatible); + void qemuProcessCleanupMigrationJob(virQEMUDriver *driver, virDomainObj *vm);