From nobody Fri Dec 19 07:48:42 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1667576640; cv=none; d=zohomail.com; s=zohoarc; b=RPi30cruVrx1BsDcbh02MqTT8OQE9WWNwoQzR0nn+hFY2dIAxuyaiGCdsA+wRD+RiULjMyzWrF3pY5VrUAbx3TTdzkuZPPf7apy+fNPtHr7j3gYMEvlE17TEopujnrhAA9PtOWwZbO52crdDMdR3C/5UBNU6iq7h8o9gbnmV7uc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667576640; 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=E8GAKfl2mhYLz7sH+4uPeuFn8HspM9FGt1UIX3uK1o4=; b=TZcSAWj3n45brxfLonW8/fRE3mFDCn5vMiVIoxKZNvT7bmU2TDNAxzyX+gW5B5tYVNn2uRWpCyqLR0co3Xl0AQosVC/NHgc41aikR59sonP89mS4FT7sYfzSa16zvzxnS0qb40dKcGUX3GjhLf4n+zFRGNwGraV/qOzRsh50lr4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1667576640780399.50102704635674; Fri, 4 Nov 2022 08:44:00 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-556-9q_DorVvPB-JEGL6TmobDA-1; Fri, 04 Nov 2022 11:43:55 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E8FB9811E81; Fri, 4 Nov 2022 15:43:50 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id D58CD1121315; Fri, 4 Nov 2022 15:43:50 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CB4121946587; Fri, 4 Nov 2022 15:43:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 687ED1946587 for ; Fri, 4 Nov 2022 15:43:49 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 5B45AC2DF67; Fri, 4 Nov 2022 15:43:49 +0000 (UTC) Received: from work.fritz.box (unknown [10.39.193.200]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1B7EC569C2; Fri, 4 Nov 2022 15:43:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667576639; 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=E8GAKfl2mhYLz7sH+4uPeuFn8HspM9FGt1UIX3uK1o4=; b=XC5geTB3iufX9CqsYeWmdSxotJgkj1Iys/i2YZoJedRnfEnwHzlRIaUyXuw8s7M+RDraAs Wkfc27cXnmikoy7rUybTa5Fadh4Ps4/RLgAwNLTXUVGx7y68Gjmx+h/qQhqULBzTSWuHp+ VwpO/s+9Imw8FmyBGpEemDZIQGXVLjI= X-MC-Unique: 9q_DorVvPB-JEGL6TmobDA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v3 04/24] cpu_map: Add script to sync from QEMU i386 cpu features Date: Fri, 4 Nov 2022 16:43:24 +0100 Message-Id: <20221104154344.213211-5-twiederh@redhat.com> In-Reply-To: <20221104154344.213211-1-twiederh@redhat.com> References: <20221104154344.213211-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tim Wiederhake Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: 1667576642685100003 Content-Type: text/plain; charset="utf-8"; x-default="true" This script is intended to help in synchronizing i386 QEMU cpu feature definitions with libvirt. QEMU's attribute list for the "max-x86_64-cpu" contains non-cpu-feature items and needs to be filtered before being useful. Signed-off-by: Tim Wiederhake --- src/cpu_map/sync_qemu_features_i386.py | 278 +++++++++++++++++++++++++ 1 file changed, 278 insertions(+) create mode 100755 src/cpu_map/sync_qemu_features_i386.py diff --git a/src/cpu_map/sync_qemu_features_i386.py b/src/cpu_map/sync_qemu= _features_i386.py new file mode 100755 index 0000000000..e268d93e8a --- /dev/null +++ b/src/cpu_map/sync_qemu_features_i386.py @@ -0,0 +1,278 @@ +#!/usr/bin/env python3 + +import argparse +import json +import subprocess +import xml.etree.ElementTree + + +def ignore_feature(feature): + ignored_features =3D [ + # VIA/Cyrix/Centaur-defined CPU features + # CPUID level 0xC0000001, word 5 + "ace2", + "ace2-en", + "phe", + "phe-en", + "pmm", + "pmm-en", + "xcrypt", + "xcrypt-en", + "xstore", + "xstore-en", + + # non-features + "check", + "cpuid-0xb", + "enforce", + "fill-mtrr-mask", + "full-cpuid-auto-level", + "full-width-write", + "host-cache-info", + "host-phys-bits", + "hotpluggable", + "hotplugged", + "hv-apicv", + "hv-avic", + "hv-crash", + "hv-emsr-bitmap", + "hv-enforce-cpuid", + "hv-evmcs", + "hv-frequencies", + "hv-ipi", + "hv-passthrough", + "hv-reenlightenment", + "hv-relaxed", + "hv-reset", + "hv-runtime", + "hv-stimer", + "hv-stimer-direct", + "hv-syndbg", + "hv-synic", + "hv-time", + "hv-tlbflush", + "hv-tlbflush-direct", + "hv-tlbflush-ext", + "hv-vapic", + "hv-vpindex", + "hv-xmm-input", + "kvm", + "kvm-asyncpf", + "kvm-asyncpf-int", + "kvm-hint-dedicated", + "kvm-mmu", + "kvm-msi-ext-dest-id", + "kvm-no-smi-migration", + "kvm-nopiodelay", + "kvm-poll-control", + "kvm-pv-enforce-cpuid", + "kvm-pv-eoi", + "kvm-pv-ipi", + "kvm-pv-sched-yield", + "kvm-pv-tlb-flush", + "kvm-pv-unhalt", + "kvm-steal-time", + "kvm_asyncpf", + "kvm_asyncpf_int", + "kvm_mmu", + "kvm_nopiodelay", + "kvm_poll_control", + "kvm_pv_eoi", + "kvm_pv_unhalt", + "kvm_steal_time", + "kvmclock", + "kvmclock-stable-bit", + "l3-cache", + "legacy-cache", + "lmce", + "migratable", + "pmu", + "realized", + "start-powered-off", + "tcg-cpuid", + "vmware-cpuid-freq", + "vmx-activity-hlt", + "vmx-activity-shutdown", + "vmx-activity-wait-sipi", + "vmx-apicv-register", + "vmx-apicv-vid", + "vmx-apicv-x2apic", + "vmx-apicv-xapic", + "vmx-cr3-load-noexit", + "vmx-cr3-store-noexit", + "vmx-cr8-load-exit", + "vmx-cr8-store-exit", + "vmx-desc-exit", + "vmx-encls-exit", + "vmx-entry-ia32e-mode", + "vmx-entry-load-bndcfgs", + "vmx-entry-load-efer", + "vmx-entry-load-pat", + "vmx-entry-load-perf-global-ctrl", + "vmx-entry-load-pkrs", + "vmx-entry-load-rtit-ctl", + "vmx-entry-noload-debugctl", + "vmx-ept", + "vmx-ept-1gb", + "vmx-ept-2mb", + "vmx-ept-advanced-exitinfo", + "vmx-ept-execonly", + "vmx-eptad", + "vmx-eptp-switching", + "vmx-exit-ack-intr", + "vmx-exit-clear-bndcfgs", + "vmx-exit-clear-rtit-ctl", + "vmx-exit-load-efer", + "vmx-exit-load-pat", + "vmx-exit-load-perf-global-ctrl", + "vmx-exit-load-pkrs", + "vmx-exit-nosave-debugctl", + "vmx-exit-save-efer", + "vmx-exit-save-pat", + "vmx-exit-save-preemption-timer", + "vmx-flexpriority", + "vmx-hlt-exit", + "vmx-ins-outs", + "vmx-intr-exit", + "vmx-invept", + "vmx-invept-all-context", + "vmx-invept-single-context", + "vmx-invept-single-context-noglobals", + "vmx-invlpg-exit", + "vmx-invpcid-exit", + "vmx-invvpid", + "vmx-invvpid-all-context", + "vmx-invvpid-single-addr", + "vmx-io-bitmap", + "vmx-io-exit", + "vmx-monitor-exit", + "vmx-movdr-exit", + "vmx-msr-bitmap", + "vmx-mtf", + "vmx-mwait-exit", + "vmx-nmi-exit", + "vmx-page-walk-4", + "vmx-page-walk-5", + "vmx-pause-exit", + "vmx-ple", + "vmx-pml", + "vmx-posted-intr", + "vmx-preemption-timer", + "vmx-rdpmc-exit", + "vmx-rdrand-exit", + "vmx-rdseed-exit", + "vmx-rdtsc-exit", + "vmx-rdtscp-exit", + "vmx-secondary-ctls", + "vmx-shadow-vmcs", + "vmx-store-lma", + "vmx-true-ctls", + "vmx-tsc-offset", + "vmx-tsc-scaling", + "vmx-unrestricted-guest", + "vmx-vintr-pending", + "vmx-vmfunc", + "vmx-vmwrite-vmexit-fields", + "vmx-vnmi", + "vmx-vnmi-pending", + "vmx-vpid", + "vmx-wbinvd-exit", + "vmx-xsaves", + "vmx-zero-len-inject", + ] + + if feature["type"] !=3D "bool": + return True + + name =3D feature["name"] + + if name.startswith("x-"): + return True + + if name in ignored_features: + return True + + return False + + +def get_qemu_feature_list(path_to_qemu): + cmd =3D [ + path_to_qemu, + "-machine", "accel=3Dkvm", + "-cpu", "host", + "-nodefaults", + "-nographic", + "-qmp", + "stdio" + ] + + request =3D """ + { + "execute": "qmp_capabilities" + } + { + "execute": "qom-list-properties", + "arguments": { + "typename": "max-x86_64-cpu" + }, + "id": "qom-list-properties" + } + { + "execute": "quit" + } + """ + + decoder =3D json.JSONDecoder() + output =3D subprocess.check_output(cmd, input=3Drequest, text=3DTrue) + while output: + obj, idx =3D decoder.raw_decode(output) + output =3D output[idx:].strip() + if obj.get("id") !=3D "qom-list-properties": + continue + for feature in obj["return"]: + if ignore_feature(feature): + continue + yield feature["name"] + + +def get_libvirt_feature_list(path_to_featuresfile): + dom =3D xml.etree.ElementTree.parse(path_to_featuresfile) + for feature in dom.getroot().iter("feature"): + yield feature.get("name") + for alias in feature: + if alias.tag =3D=3D "alias" and alias.get("source") =3D=3D "qe= mu": + yield alias.get("name") + + +def main(): + parser =3D argparse.ArgumentParser( + description=3D"Synchronize x86 cpu features from QEMU i386 target.= ") + parser.add_argument( + "--qemu", + help=3D"Path to qemu executable", + default=3D"qemu-system-x86_64", + type=3Dstr) + parser.add_argument( + "--features", + help=3D"Path to 'src/cpu_map/x86_features.xml' file in " + "the libvirt repository", + default=3D"x86_features.xml", + type=3Dstr) + + args =3D parser.parse_args() + + qfeatures =3D get_qemu_feature_list(args.qemu) + lfeatures =3D list(get_libvirt_feature_list(args.features)) + missing =3D [f for f in sorted(qfeatures) if f not in lfeatures] + + if missing: + print("The following features were reported by qemu but are " + "unknown to libvirt:") + for feature in missing: + print(" *", feature) + + return len(missing) !=3D 0 + + +if __name__ =3D=3D "__main__": + exit(main()) --=20 2.36.1