From nobody Sat May 4 13:23:18 2024 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1516618295427624.6426241667023; Mon, 22 Jan 2018 02:51:35 -0800 (PST) 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 73FCB1A407A; Mon, 22 Jan 2018 10:51:34 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 055188889C; Mon, 22 Jan 2018 10:51:34 +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 5D63F3FC74; Mon, 22 Jan 2018 10:51:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0MAkQkh026236 for ; Mon, 22 Jan 2018 05:46:26 -0500 Received: by smtp.corp.redhat.com (Postfix) id 35DC95F736; Mon, 22 Jan 2018 10:46:26 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.105]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D7ACD7A2F6 for ; Mon, 22 Jan 2018 10:46:21 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id DD191100898; Mon, 22 Jan 2018 11:46:19 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Mon, 22 Jan 2018 11:46:14 +0100 Message-Id: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] qemu: Refresh caps cache after booting a different kernel 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: , MIME-Version: 1.0 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.39]); Mon, 22 Jan 2018 10:51:34 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Whenever a different kernel is booted, some capabilities related to KVM (such as CPUID bits) may change. We need to refresh the cache to see the changes. Signed-off-by: Jiri Denemark Reviewed-by: Daniel P. Berrange --- Notes: The capabilities may also change if a parameter passed to a kvm module changes (kvm_intel.nested is a good example) so this is not a complete solution, but we're hopefully getting closer to it :-) src/qemu/qemu_capabilities.c | 57 +++++++++++++++++++++++++++++++++++++---= ---- src/qemu/qemu_capspriv.h | 1 + tests/qemucapsprobe.c | 2 +- 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index ab0ea8ec0d..2c573827f1 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -52,6 +52,7 @@ #include #include #include +#include =20 #define VIR_FROM_THIS VIR_FROM_QEMU =20 @@ -510,6 +511,7 @@ struct _virQEMUCaps { unsigned int libvirtVersion; unsigned int microcodeVersion; char *package; + char *kernelVersion; =20 virArch arch; =20 @@ -2303,6 +2305,9 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemu= Caps) if (VIR_STRDUP(ret->package, qemuCaps->package) < 0) goto error; =20 + if (VIR_STRDUP(ret->kernelVersion, qemuCaps->kernelVersion) < 0) + goto error; + ret->arch =3D qemuCaps->arch; =20 if (qemuCaps->kvmCPUModels) { @@ -2363,6 +2368,7 @@ void virQEMUCapsDispose(void *obj) virBitmapFree(qemuCaps->flags); =20 VIR_FREE(qemuCaps->package); + VIR_FREE(qemuCaps->kernelVersion); VIR_FREE(qemuCaps->binary); =20 VIR_FREE(qemuCaps->gicCapabilities); @@ -3834,6 +3840,7 @@ struct _virQEMUCapsCachePriv { gid_t runGid; virArch hostArch; unsigned int microcodeVersion; + char *kernelVersion; }; typedef struct _virQEMUCapsCachePriv virQEMUCapsCachePriv; typedef virQEMUCapsCachePriv *virQEMUCapsCachePrivPtr; @@ -3845,6 +3852,7 @@ virQEMUCapsCachePrivFree(void *privData) virQEMUCapsCachePrivPtr priv =3D privData; =20 VIR_FREE(priv->libDir); + VIR_FREE(priv->kernelVersion); VIR_FREE(priv); } =20 @@ -3970,6 +3978,12 @@ virQEMUCapsLoadCache(virArch hostArch, goto cleanup; } =20 + if (virXPathBoolean("boolean(./kernelVersion)", ctxt) > 0) { + qemuCaps->kernelVersion =3D virXPathString("string(./kernelVersion= )", ctxt); + if (!qemuCaps->kernelVersion) + goto cleanup; + } + if (!(str =3D virXPathString("string(./arch)", ctxt))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing arch in QEMU capabilities cache")); @@ -4248,6 +4262,10 @@ virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps) virBufferAsprintf(&buf, "%s\n", qemuCaps->package); =20 + if (qemuCaps->kernelVersion) + virBufferAsprintf(&buf, "%s\n", + qemuCaps->kernelVersion); + virBufferAsprintf(&buf, "%s\n", virArchToString(qemuCaps->arch)); =20 @@ -4385,14 +4403,24 @@ virQEMUCapsIsValid(void *data, return false; } =20 - if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM) && - priv->microcodeVersion !=3D qemuCaps->microcodeVersion) { - VIR_DEBUG("Outdated capabilities for '%s': microcode version chang= ed " - "(%u vs %u)", - qemuCaps->binary, - priv->microcodeVersion, - qemuCaps->microcodeVersion); - return false; + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) { + if (priv->microcodeVersion !=3D qemuCaps->microcodeVersion) { + VIR_DEBUG("Outdated capabilities for '%s': microcode version " + "changed (%u vs %u)", + qemuCaps->binary, + priv->microcodeVersion, + qemuCaps->microcodeVersion); + return false; + } + + if (STRNEQ_NULLABLE(priv->kernelVersion, qemuCaps->kernelVersion))= { + VIR_DEBUG("Outdated capabilities for '%s': kernel version chan= ged " + "('%s' vs '%s')", + qemuCaps->binary, + priv->kernelVersion, + qemuCaps->kernelVersion); + return false; + } } =20 return true; @@ -5228,6 +5256,7 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch, uid_t runUid, gid_t runGid, unsigned int microcodeVersion, + const char *kernelVersion, bool qmpOnly) { virQEMUCapsPtr qemuCaps; @@ -5284,9 +5313,13 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch, virQEMUCapsInitHostCPUModel(qemuCaps, hostArch, VIR_DOMAIN_VIRT_KVM); virQEMUCapsInitHostCPUModel(qemuCaps, hostArch, VIR_DOMAIN_VIRT_QEMU); =20 - if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) { qemuCaps->microcodeVersion =3D microcodeVersion; =20 + if (VIR_STRDUP(qemuCaps->kernelVersion, kernelVersion) < 0) + goto error; + } + cleanup: VIR_FREE(qmperr); return qemuCaps; @@ -5309,6 +5342,7 @@ virQEMUCapsNewData(const char *binary, priv->runUid, priv->runGid, priv->microcodeVersion, + priv->kernelVersion, false); } =20 @@ -5397,6 +5431,7 @@ virQEMUCapsCacheNew(const char *libDir, char *capsCacheDir =3D NULL; virFileCachePtr cache =3D NULL; virQEMUCapsCachePrivPtr priv =3D NULL; + struct utsname uts =3D { 0 }; =20 if (virAsprintf(&capsCacheDir, "%s/capabilities", cacheDir) < 0) goto error; @@ -5417,6 +5452,10 @@ virQEMUCapsCacheNew(const char *libDir, priv->runGid =3D runGid; priv->microcodeVersion =3D microcodeVersion; =20 + if (uname(&uts) =3D=3D 0 && + virAsprintf(&priv->kernelVersion, "%s %s", uts.release, uts.versio= n) < 0) + goto error; + cleanup: VIR_FREE(capsCacheDir); return cache; diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h index 98d163b920..222f3368e3 100644 --- a/src/qemu/qemu_capspriv.h +++ b/src/qemu/qemu_capspriv.h @@ -37,6 +37,7 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch, uid_t runUid, gid_t runGid, unsigned int microcodeVersion, + const char *kernelVersion, bool qmpOnly); =20 int virQEMUCapsLoadCache(virArch hostArch, diff --git a/tests/qemucapsprobe.c b/tests/qemucapsprobe.c index a5f5a38b16..7d60246949 100644 --- a/tests/qemucapsprobe.c +++ b/tests/qemucapsprobe.c @@ -72,7 +72,7 @@ main(int argc, char **argv) return EXIT_FAILURE; =20 if (!(caps =3D virQEMUCapsNewForBinaryInternal(VIR_ARCH_NONE, argv[1],= "/tmp", - -1, -1, 0, true))) + -1, -1, 0, NULL, true))) return EXIT_FAILURE; =20 virObjectUnref(caps); --=20 2.16.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list