From nobody Thu May 15 03:03:37 2025 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 151507791367070.41518450024171; Thu, 4 Jan 2018 06:58:33 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3CB0B2F7C3F; Thu, 4 Jan 2018 14:58:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 15BB2609B4; Thu, 4 Jan 2018 14:58:32 +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 CCC9218033DB; Thu, 4 Jan 2018 14:58:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w04EwUCJ026613 for ; Thu, 4 Jan 2018 09:58:30 -0500 Received: by smtp.corp.redhat.com (Postfix) id C5CA560C82; Thu, 4 Jan 2018 14:58:30 +0000 (UTC) Received: from virval.usersys.redhat.com (unknown [10.43.2.105]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 99ADE609B5 for ; Thu, 4 Jan 2018 14:58:23 +0000 (UTC) Received: by virval.usersys.redhat.com (Postfix, from userid 500) id B36581015E3; Thu, 4 Jan 2018 15:58:21 +0100 (CET) From: Jiri Denemark To: libvir-list@redhat.com Date: Thu, 4 Jan 2018 15:58:09 +0100 Message-Id: <494959266554e1ad13e43d7fc81a431098afe11a.1515077784.git.jdenemar@redhat.com> In-Reply-To: References: In-Reply-To: References: Mail-Followup-To: libvir-list@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/5] util: introduce virHostCPUGetMicrocodeVersion 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 04 Jan 2018 14:58:32 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini This new API reads host's CPU microcode version from /proc/cpuinfo. Unfortunately, there is no other way of reading microcode version which would be usable from both system and session daemon. Signed-off-by: Paolo Bonzini Signed-off-by: Jiri Denemark --- src/libvirt_private.syms | 1 + src/util/virhostcpu.c | 43 +++++++++++++++++++++++++++++++++++++++++++ src/util/virhostcpu.h | 2 ++ 3 files changed, 46 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 8d583e3e74..a705fa846d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1869,6 +1869,7 @@ virHostCPUGetCount; virHostCPUGetInfo; virHostCPUGetKVMMaxVCPUs; virHostCPUGetMap; +virHostCPUGetMicrocodeVersion; virHostCPUGetOnline; virHostCPUGetOnlineBitmap; virHostCPUGetPresentBitmap; diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index c485a97211..713fdec553 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -1206,3 +1206,46 @@ virHostCPUGetKVMMaxVCPUs(void) return -1; } #endif /* HAVE_LINUX_KVM_H */ + + +#ifdef __linux__ + +unsigned int +virHostCPUGetMicrocodeVersion(void) +{ + char *outbuf =3D NULL; + char *cur; + unsigned int version =3D 0; + + if (virFileReadHeaderQuiet(CPUINFO_PATH, 4096, &outbuf) < 0) { + char ebuf[1024]; + VIR_DEBUG("Failed to read microcode version from %s: %s", + CPUINFO_PATH, virStrerror(errno, ebuf, sizeof(ebuf))); + return 0; + } + + /* Account for format 'microcode : XXXX'*/ + if (!(cur =3D strstr(outbuf, "microcode")) || + !(cur =3D strchr(cur, ':'))) + goto cleanup; + cur++; + + /* Linux places the microcode revision in a 32-bit integer, so + * ui is fine for us too. */ + if (virStrToLong_ui(cur, &cur, 0, &version) < 0) + goto cleanup; + + cleanup: + VIR_FREE(outbuf); + return version; +} + +#else + +unsigned int +virHostCPUGetMicrocodeVersion(void) +{ + return 0; +} + +#endif diff --git a/src/util/virhostcpu.h b/src/util/virhostcpu.h index 67033de842..f9f3359288 100644 --- a/src/util/virhostcpu.h +++ b/src/util/virhostcpu.h @@ -66,4 +66,6 @@ virBitmapPtr virHostCPUGetSiblingsList(unsigned int cpu); =20 int virHostCPUGetOnline(unsigned int cpu, bool *online); =20 +unsigned int virHostCPUGetMicrocodeVersion(void); + #endif /* __VIR_HOSTCPU_H__*/ --=20 2.15.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list