From nobody Fri Apr 26 09:00:35 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; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1545998821052507.2547227373774; Fri, 28 Dec 2018 04:07:01 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E99EF7DD28; Fri, 28 Dec 2018 12:06:56 +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 BBFC817C43; Fri, 28 Dec 2018 12:06:53 +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 1D8EA3F7CD; Fri, 28 Dec 2018 12:06:47 +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 wBSC6iBA008920 for ; Fri, 28 Dec 2018 07:06:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id C1E2D608F3; Fri, 28 Dec 2018 12:06:44 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B90B3608F2 for ; Fri, 28 Dec 2018 12:06:41 +0000 (UTC) Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ED9C07FD42 for ; Fri, 28 Dec 2018 12:06:39 +0000 (UTC) Received: from [10.94.3.220] (helo=dim-vz7.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gcquU-00034F-C4 for libvir-list@redhat.com; Fri, 28 Dec 2018 15:06:38 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Fri, 28 Dec 2018 15:06:36 +0300 Message-Id: <1545998796-257414-1-git-send-email-nshirokovskiy@virtuozzo.com> X-Greylist: Sender passed SPF test, ACL 238 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 28 Dec 2018 12:06:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 28 Dec 2018 12:06:40 +0000 (UTC) for IP:'185.231.240.75' DOMAIN:'relay.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: -0.001 (SPF_PASS) 185.231.240.75 relay.sw.ru 185.231.240.75 relay.sw.ru X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH RFC] qemu: caps: invalidate kvm capable qemu binaries on every restart 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 28 Dec 2018 12:06:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" If qemu binary exposes kvm then caps depends heavily on host state. We are already check explicitly some host features - kernel version, microcode version, nested flag state. This won't nesserily help if somebody change CPU on host. Let's instead invalidate such caps on every daemon restart. This makes kernel version and microcode version check excessive but nested flag is still need to be checked. Cache invalidating on restart is archived by keeping list of binaries that whose caps cache was validated at least once. If binary in not yet validated and supports kvm then we need to invalidate it's caps cache. Signed-off-by: Nikolay Shirokovskiy --- If the patch will be accepted then I'll send a patch which removes mentioned excessive checks also. src/qemu/qemu_capabilities.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 51bf97b..649aba2 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -3264,6 +3264,7 @@ struct _virQEMUCapsCachePriv { virArch hostArch; unsigned int microcodeVersion; char *kernelVersion; + virHashTablePtr validated; =20 /* cache whether /dev/kvm is usable as runUid:runGuid */ virTristateBool kvmUsable; @@ -3280,6 +3281,7 @@ virQEMUCapsCachePrivFree(void *privData) =20 VIR_FREE(priv->libDir); VIR_FREE(priv->kernelVersion); + virHashFree(priv->validated); VIR_FREE(priv); } =20 @@ -3952,10 +3954,19 @@ virQEMUCapsIsValid(void *data, bool kvmUsable; struct stat sb; bool kvmSupportsNesting; + bool validated =3D true; =20 if (!qemuCaps->binary) return true; =20 + if (!virHashLookup(priv->validated, qemuCaps->binary)) { + validated =3D false; + + /* If we fail to remember this binary is validated it is not probl= em, + * it will be validated again next time once again */ + virHashAddEntry(priv->validated, qemuCaps->binary, (void*)1); + } + if (qemuCaps->libvirtCtime !=3D virGetSelfLastChanged() || qemuCaps->libvirtVersion !=3D LIBVIR_VERSION_NUMBER) { VIR_DEBUG("Outdated capabilities for '%s': libvirt changed " @@ -4011,6 +4022,12 @@ virQEMUCapsIsValid(void *data, } =20 if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) { + if (!validated) { + VIR_DEBUG("Capabilities for QEMU that supports KVM need to be " + "updated after daemon restart"); + return false; + } + if (priv->microcodeVersion !=3D qemuCaps->microcodeVersion) { VIR_DEBUG("Outdated capabilities for '%s': microcode version " "changed (%u vs %u)", @@ -4809,6 +4826,9 @@ virQEMUCapsCacheNew(const char *libDir, if (VIR_STRDUP(priv->libDir, libDir) < 0) goto error; =20 + if (!(priv->validated =3D virHashCreate(1, NULL))) + goto error; + priv->hostArch =3D virArchFromHost(); =20 priv->runUid =3D runUid; --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list