qemu: Invalidate capabilities cache on host cpuid mismatch

See https://bugzilla.redhat.com/show_bug.cgi?id=1953389.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Tim Wiederhake 2021-08-02 16:44:30 +02:00
parent f3f67d4ecd
commit 3bc6f46d30
3 changed files with 15 additions and 5 deletions

View File

@ -4907,6 +4907,13 @@ virQEMUCapsIsValid(void *data,
return false;
}
if (virCPUDataIsIdentical(priv->cpuData, qemuCaps->cpuData) !=
VIR_CPU_COMPARE_IDENTICAL) {
VIR_DEBUG("Outdated capabilities for '%s': host cpuid changed",
qemuCaps->binary);
return false;
}
kvmSupportsNesting = virQEMUCapsKVMSupportsNesting();
if (kvmSupportsNesting != qemuCaps->kvmSupportsNesting) {
VIR_DEBUG("Outdated capabilities for '%s': kvm kernel nested "
@ -5387,7 +5394,8 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
gid_t runGid,
const char *hostCPUSignature,
unsigned int microcodeVersion,
const char *kernelVersion)
const char *kernelVersion,
virCPUData* cpuData)
{
g_autoptr(virQEMUCaps) qemuCaps = NULL;
struct stat sb;
@ -5435,7 +5443,7 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) {
qemuCaps->hostCPUSignature = g_strdup(hostCPUSignature);
qemuCaps->microcodeVersion = microcodeVersion;
qemuCaps->cpuData = NULL;
qemuCaps->cpuData = virCPUDataNewCopy(cpuData);
qemuCaps->kernelVersion = g_strdup(kernelVersion);
@ -5460,7 +5468,8 @@ virQEMUCapsNewData(const char *binary,
priv->runGid,
priv->hostCPUSignature,
virHostCPUGetMicrocodeVersion(priv->hostArch),
priv->kernelVersion);
priv->kernelVersion,
priv->cpuData);
}

View File

@ -35,7 +35,8 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
gid_t runGid,
const char *hostCPUSignature,
unsigned int microcodeVersion,
const char *kernelVersion);
const char *kernelVersion,
virCPUData* cpuData);
int virQEMUCapsLoadCache(virArch hostArch,
virQEMUCaps *qemuCaps,

View File

@ -79,7 +79,7 @@ main(int argc, char **argv)
return EXIT_FAILURE;
if (!(caps = virQEMUCapsNewForBinaryInternal(VIR_ARCH_NONE, argv[1], "/tmp",
-1, -1, NULL, 0, NULL)))
-1, -1, NULL, 0, NULL, NULL)))
return EXIT_FAILURE;
host = virArchFromHost();