From nobody Sun Feb 8 21:29:00 2026 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1560937215; cv=none; d=zoho.com; s=zohoarc; b=LfiA2vW9Fn+lYDfqwMxVrF7MJuSGiZanJxEZfzaRdTZmehaG1JxL8bZ8YX5emUW7KFh0ALKxqbvRYVmdIvU+DQHNfB1qq9TovJvGpVMpy5nHPDqBpPumzE8TaLxcqo67Y/db0GfD4jVLVXmFey4fo6Pm8KONhMLrIRKi1Wknha4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1560937215; h=Content-Type:Content-Transfer-Encoding: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:ARC-Authentication-Results; bh=pkyEFHE/bWTG4KetooXXLkASQFDnvaGdrb5YAhHBYDk=; b=CAOvR6DxvTfamhr9BiXBXvDKLO2oH50tLczqZkRu7pgeVKGFHThLqDoQlwcrU+L6wgHKun6gY6fb8/Z6YrQsWVeQ2CXEdZE/fOJGkZI3pBQ+aB8jW5qiEmk93QrrT3mrnohBGvpcBeEbxUNQhu/N4BjYVJyO8ylp9ll7rWXOuHo= ARC-Authentication-Results: i=1; mx.zoho.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=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1560937215634298.46454094809667; Wed, 19 Jun 2019 02:40:15 -0700 (PDT) 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 17F5ADD9F4; Wed, 19 Jun 2019 09:40:09 +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 E228617A70; Wed, 19 Jun 2019 09:40:08 +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 9644F1806B1B; Wed, 19 Jun 2019 09:40:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5J9cVrh024402 for ; Wed, 19 Jun 2019 05:38:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 96DD15D719; Wed, 19 Jun 2019 09:38:31 +0000 (UTC) Received: from orkuz.int.mamuti.net (ovpn-204-21.brq.redhat.com [10.40.204.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 41E4C5D70D for ; Wed, 19 Jun 2019 09:38:31 +0000 (UTC) Received: by orkuz.int.mamuti.net (Postfix, from userid 500) id C3CFE2A4129; Wed, 19 Jun 2019 11:38:23 +0200 (CEST) From: Jiri Denemark To: libvir-list@redhat.com Date: Wed, 19 Jun 2019 11:38:18 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 21/24] qemu: Introduce generic qemuMonitorGetGuestCPU 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: , 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.38]); Wed, 19 Jun 2019 09:40:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Unlike the old version (which is now called qemuMonitorGetGuestCPUx86), this monitor API checks for individual features by their names rather than processing CPUID bits. Thus we can get the list of enabled and disabled features for both CPUID and MSR features. Signed-off-by: Jiri Denemark --- src/qemu/qemu_monitor.c | 36 ++++++ src/qemu/qemu_monitor.h | 10 ++ src/qemu/qemu_monitor_json.c | 211 +++++++++++++++++++++++++++++++++++ src/qemu/qemu_monitor_json.h | 7 ++ 4 files changed, 264 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 344aac09f0..99aadba2e2 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -4107,6 +4107,42 @@ qemuMonitorGetGuestCPUx86(qemuMonitorPtr mon, } =20 =20 +/** + * qemuMonitorGetGuestCPU: + * @mon: Pointer to the monitor + * @arch: CPU architecture + * @translate: callback for translating CPU feature names from QEMU to lib= virt + * @opaque: data for @translate callback + * @enabled: returns the CPU data for all enabled features + * @disabled: returns the CPU data for features which we asked for + * (either explicitly or via a named CPU model) but QEMU disabled them + * + * Retrieve the definition of the guest CPU from a running QEMU instance. + * + * Returns 0 on success, -1 on error. + */ +int +qemuMonitorGetGuestCPU(qemuMonitorPtr mon, + virArch arch, + qemuMonitorCPUFeatureTranslationCallback translate, + void *opaque, + virCPUDataPtr *enabled, + virCPUDataPtr *disabled) +{ + VIR_DEBUG("arch=3D%s translate=3D%p opaque=3D%p enabled=3D%p disabled= =3D%p", + virArchToString(arch), translate, opaque, enabled, disabled); + + QEMU_CHECK_MONITOR(mon); + + *enabled =3D NULL; + if (disabled) + *disabled =3D NULL; + + return qemuMonitorJSONGetGuestCPU(mon, arch, translate, opaque, + enabled, disabled); +} + + /** * qemuMonitorRTCResetReinjection: * @mon: Pointer to the monitor diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index ac2499c22a..f5be74f461 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1154,6 +1154,16 @@ int qemuMonitorGetGuestCPUx86(qemuMonitorPtr mon, virCPUDataPtr *data, virCPUDataPtr *disabled); =20 +typedef const char *(*qemuMonitorCPUFeatureTranslationCallback)(const char= *name, + void *opaq= ue); + +int qemuMonitorGetGuestCPU(qemuMonitorPtr mon, + virArch arch, + qemuMonitorCPUFeatureTranslationCallback transl= ate, + void *opaque, + virCPUDataPtr *enabled, + virCPUDataPtr *disabled); + int qemuMonitorRTCResetReinjection(qemuMonitorPtr mon); =20 typedef struct _qemuMonitorIOThreadInfo qemuMonitorIOThreadInfo; diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index efcef211ed..1662e47301 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -6137,6 +6137,64 @@ int qemuMonitorJSONGetObjectProperty(qemuMonitorPtr = mon, } =20 =20 +static int +qemuMonitorJSONGetStringListProperty(qemuMonitorPtr mon, + const char *path, + const char *property, + char ***strList) +{ + virJSONValuePtr cmd; + virJSONValuePtr reply =3D NULL; + virJSONValuePtr data; + char **list =3D NULL; + size_t n; + size_t i; + int ret =3D -1; + + *strList =3D NULL; + + if (!(cmd =3D qemuMonitorJSONMakeCommand("qom-get", + "s:path", path, + "s:property", property, + NULL))) + return -1; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; + + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) + goto cleanup; + + data =3D virJSONValueObjectGetArray(reply, "return"); + n =3D virJSONValueArraySize(data); + + if (VIR_ALLOC_N(list, n + 1) < 0) + goto cleanup; + + for (i =3D 0; i < n; i++) { + virJSONValuePtr item =3D virJSONValueArrayGet(data, i); + + if (virJSONValueGetType(item) !=3D VIR_JSON_TYPE_STRING) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected value in %s array"), property); + goto cleanup; + } + + if (VIR_STRDUP(list[i], virJSONValueGetString(item)) < 0) + goto cleanup; + } + + VIR_STEAL_PTR(*strList, list); + ret =3D n; + + cleanup: + virJSONValueFree(cmd); + virJSONValueFree(reply); + virStringListFree(list); + return ret; +} + + #define MAKE_SET_CMD(STRING, VALUE) \ cmd =3D qemuMonitorJSONMakeCommand("qom-set", \ "s:path", path, \ @@ -7369,6 +7427,159 @@ qemuMonitorJSONGetGuestCPUx86(qemuMonitorPtr mon, return -1; } =20 + +static int +qemuMonitorJSONGetCPUProperties(qemuMonitorPtr mon, + char ***props) +{ + virJSONValuePtr cmd; + virJSONValuePtr reply =3D NULL; + int ret =3D -1; + + *props =3D NULL; + + if (!(cmd =3D qemuMonitorJSONMakeCommand("qom-list", + "s:path", QOM_CPU_PATH, + NULL))) + return -1; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; + + if (qemuMonitorJSONHasError(reply, "DeviceNotFound")) { + ret =3D 0; + goto cleanup; + } + + ret =3D qemuMonitorJSONParsePropsList(cmd, reply, "bool", props); + + cleanup: + virJSONValueFree(reply); + virJSONValueFree(cmd); + return ret; +} + + +static int +qemuMonitorJSONGetCPUData(qemuMonitorPtr mon, + qemuMonitorCPUFeatureTranslationCallback transla= te, + void *opaque, + virCPUDataPtr data) +{ + qemuMonitorJSONObjectProperty prop =3D { .type =3D QEMU_MONITOR_OBJECT= _PROPERTY_BOOLEAN }; + char **props; + char **p; + int ret =3D -1; + + if (qemuMonitorJSONGetCPUProperties(mon, &props) < 0) + goto cleanup; + + for (p =3D props; p && *p; p++) { + const char *name =3D *p; + + if (qemuMonitorJSONGetObjectProperty(mon, QOM_CPU_PATH, name, &pro= p) < 0) + goto cleanup; + + if (!prop.val.b) + continue; + + if (translate) + name =3D translate(name, opaque); + + if (virCPUDataAddFeature(data, name) < 0) + goto cleanup; + } + + ret =3D 0; + + cleanup: + virStringListFree(props); + return ret; +} + + +static int +qemuMonitorJSONGetCPUDataDisabled(qemuMonitorPtr mon, + qemuMonitorCPUFeatureTranslationCallback= translate, + void *opaque, + virCPUDataPtr data) +{ + char **props; + char **p; + int ret =3D -1; + + if (qemuMonitorJSONGetStringListProperty(mon, QOM_CPU_PATH, + "unavailable-features", &prop= s) < 0) + goto cleanup; + + for (p =3D props; p && *p; p++) { + const char *name =3D *p; + + if (translate) + name =3D translate(name, opaque); + + if (virCPUDataAddFeature(data, name) < 0) + goto cleanup; + } + + ret =3D 0; + + cleanup: + virStringListFree(props); + return ret; +} + + +/** + * qemuMonitorJSONGetGuestCPU: + * @mon: Pointer to the monitor + * @arch: CPU architecture + * @translate: callback for translating CPU feature names from QEMU to lib= virt + * @opaque: data for @translate callback + * @enabled: returns the CPU data for all enabled features + * @disabled: returns the CPU data for features which we asked for + * (either explicitly or via a named CPU model) but QEMU disabled them + * + * Retrieve the definition of the guest CPU from a running QEMU instance. + * + * Returns 0 on success, -1 on error. + */ +int +qemuMonitorJSONGetGuestCPU(qemuMonitorPtr mon, + virArch arch, + qemuMonitorCPUFeatureTranslationCallback transl= ate, + void *opaque, + virCPUDataPtr *enabled, + virCPUDataPtr *disabled) +{ + virCPUDataPtr cpuEnabled =3D NULL; + virCPUDataPtr cpuDisabled =3D NULL; + int ret =3D -1; + + if (!(cpuEnabled =3D virCPUDataNew(arch)) || + !(cpuDisabled =3D virCPUDataNew(arch))) + goto cleanup; + + if (qemuMonitorJSONGetCPUData(mon, translate, opaque, cpuEnabled) < 0) + goto cleanup; + + if (disabled && + qemuMonitorJSONGetCPUDataDisabled(mon, translate, opaque, cpuDisab= led) < 0) + goto cleanup; + + VIR_STEAL_PTR(*enabled, cpuEnabled); + if (disabled) + VIR_STEAL_PTR(*disabled, cpuDisabled); + + ret =3D 0; + + cleanup: + virCPUDataFree(cpuEnabled); + virCPUDataFree(cpuDisabled); + return ret; +} + + int qemuMonitorJSONRTCResetReinjection(qemuMonitorPtr mon) { diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 424861b531..a874c9c01c 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -493,6 +493,13 @@ int qemuMonitorJSONGetGuestCPUx86(qemuMonitorPtr mon, virCPUDataPtr *data, virCPUDataPtr *disabled); =20 +int qemuMonitorJSONGetGuestCPU(qemuMonitorPtr mon, + virArch arch, + qemuMonitorCPUFeatureTranslationCallback tr= anslate, + void *opaque, + virCPUDataPtr *enabled, + virCPUDataPtr *disabled); + int qemuMonitorJSONRTCResetReinjection(qemuMonitorPtr mon); =20 int qemuMonitorJSONGetIOThreads(qemuMonitorPtr mon, --=20 2.22.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list