From nobody Mon Feb 9 17:57:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1636043572; cv=none; d=zohomail.com; s=zohoarc; b=jnG7BCtCrwLu0tGSZuVwFKqS9AWFmkPfnGadF7Tde8uh7Ql3g6q7emB5etFVZczF6nssL/Y8p7xnbyrQK+fdkxOC+YuW69xVtMGOWu31FmjK82USttzxdwUn4mi3RTaz1/uWNDkzlZ3p04XfEwHDZHPCr4XhjHuPe9vyy5vr9CQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1636043572; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=dkQePM/GmueTFq+2rPlOp15wW38Uz7R2PZ5SMoAvWgg=; b=dnF4D+DLbyrJeX52DYG1xKrV7+L0eqNiTS0mnPa/cNrHkJlRW/QVFjKrbHcAdWjLnpCB+9LNaeDvAkH78v/nf0LsAJbZUyAEHSfVY9nmYO2D9kshAyB25h0V/261IsEwLUnCB4hjDeDCVHStj6qG+pnBBphPzIKQo+5YqFpa/D8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1636043572717748.9383584105354; Thu, 4 Nov 2021 09:32:52 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-257-LPxiWTbRPkG4DJMgS513mw-1; Thu, 04 Nov 2021 12:32:49 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 24DD510168CC; Thu, 4 Nov 2021 16:32:44 +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 00C455D740; Thu, 4 Nov 2021 16:32:43 +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 BD2354EA3C; Thu, 4 Nov 2021 16:32:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1A4GRbcw026482 for ; Thu, 4 Nov 2021 12:27:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5A10619730; Thu, 4 Nov 2021 16:27:37 +0000 (UTC) Received: from work.speedport.ip (unknown [10.39.193.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id A640B19C79; Thu, 4 Nov 2021 16:27:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636043571; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=dkQePM/GmueTFq+2rPlOp15wW38Uz7R2PZ5SMoAvWgg=; b=JYft/oohSfux5JgmAFyY4bOs3PvGQb/6PnDcW2yf4k3i6T0Aiy4hfUN8/3rwl+MTXCtEMy Q6cMysyp7kSEUL9sgArXDLzuzV1J6MZWIltGzaXWI5pRgswLMS0wIB3/nAvFEUIHMVgugP RQIqlsU3UH/qZ2cT7XMgBMVOdK8b7As= X-MC-Unique: LPxiWTbRPkG4DJMgS513mw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 15/20] virhostcpu: Add virHostCPUGetCPUID Date: Thu, 4 Nov 2021 17:27:15 +0100 Message-Id: <20211104162720.108973-16-twiederh@redhat.com> In-Reply-To: <20211104162720.108973-1-twiederh@redhat.com> References: <20211104162720.108973-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1636043573824100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake --- 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 665db255a6..e92670c85d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2396,6 +2396,7 @@ virHookPresent; # util/virhostcpu.h virHostCPUGetAvailableCPUsBitmap; virHostCPUGetCount; +virHostCPUGetCPUID; virHostCPUGetHaltPollTime; virHostCPUGetInfo; virHostCPUGetKVMMaxVCPUs; diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index 5dd2baf2df..3563a662d5 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -1336,6 +1336,41 @@ virHostCPUGetMSR(unsigned long index, } =20 =20 +struct kvm_cpuid2 * +virHostCPUGetCPUID(void) +{ + size_t i; + VIR_AUTOCLOSE fd =3D open(KVM_DEVICE, O_RDONLY); + + if (fd < 0) { + virReportSystemError(errno, _("Unable to open %s"), KVM_DEVICE); + return NULL; + } + + for (i =3D 1; i < INT32_MAX; i *=3D 2) { + g_autofree struct kvm_cpuid2 *kvm_cpuid =3D NULL; + kvm_cpuid =3D g_malloc0(sizeof(struct kvm_cpuid2) + + sizeof(struct kvm_cpuid_entry2) * i); + kvm_cpuid->nent =3D i; + + if (ioctl(fd, KVM_GET_SUPPORTED_CPUID, kvm_cpuid) =3D=3D 0) { + /* filter out local apic id */ + for (i =3D 0; i < kvm_cpuid->nent; ++i) { + struct kvm_cpuid_entry2 *entry =3D &kvm_cpuid->entries[i]; + if (entry->function =3D=3D 0x01 && entry->index =3D=3D 0x0= 0) + entry->ebx &=3D 0x00ffffff; + if (entry->function =3D=3D 0x0b) + entry->edx &=3D 0xffffff00; + } + + return g_steal_pointer(&kvm_cpuid); + } + } + + virReportSystemError(errno, "%s", _("Cannot read host CPUID")); + return NULL; +} + /* * This function should only be called when the host CPU supports invarian= t TSC * (invtsc CPUID feature). @@ -1391,6 +1426,14 @@ virHostCPUGetTscInfo(void) =20 #else =20 +struct kvm_cpuid2 * +virHostCPUGetCPUID(void) +{ + virReportSystemError(ENOSYS, "%s", + _("Reading CPUID is not supported on this platfor= m")); + return NULL; +} + int virHostCPUGetMSR(unsigned long index G_GNUC_UNUSED, uint64_t *msr G_GNUC_UNUSED) diff --git a/src/util/virhostcpu.h b/src/util/virhostcpu.h index d98385d53f..a96dd5afba 100644 --- a/src/util/virhostcpu.h +++ b/src/util/virhostcpu.h @@ -80,6 +80,8 @@ virHostCPUGetMicrocodeVersion(virArch hostArch) G_GNUC_NO= _INLINE; int virHostCPUGetMSR(unsigned long index, uint64_t *msr); =20 +struct kvm_cpuid2 *virHostCPUGetCPUID(void); + virHostCPUTscInfo *virHostCPUGetTscInfo(void); =20 int virHostCPUGetSignature(char **signature); --=20 2.31.1