From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 1CE9B7A014 for ; Thu, 28 Oct 2021 13:42:32 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C91BF1F9BA for ; Thu, 28 Oct 2021 13:42:01 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 829CE1F91E for ; Thu, 28 Oct 2021 13:41:57 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 54203469B2 for ; Thu, 28 Oct 2021 13:41:57 +0200 (CEST) From: Stefan Reiter To: pve-devel@lists.proxmox.com Date: Thu, 28 Oct 2021 13:41:42 +0200 Message-Id: <20211028114150.3245864-2-s.reiter@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211028114150.3245864-1-s.reiter@proxmox.com> References: <20211028114150.3245864-1-s.reiter@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.394 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment PROLO_LEO1 0.1 Meta Catches all Leo drug variations so far SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [RFC pve-qemu 1/9] Add -list-flags command line option X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Oct 2021 11:42:32 -0000 Useful for retrieving flags from default CPU models. Signed-off-by: Stefan Reiter --- ...E-Add-list-flags-command-line-option.patch | 213 ++++++++++++++++++ debian/patches/series | 1 + 2 files changed, 214 insertions(+) create mode 100644 debian/patches/pve/0049-PVE-Add-list-flags-command-line-option.patch diff --git a/debian/patches/pve/0049-PVE-Add-list-flags-command-line-option.patch b/debian/patches/pve/0049-PVE-Add-list-flags-command-line-option.patch new file mode 100644 index 0000000..56ced90 --- /dev/null +++ b/debian/patches/pve/0049-PVE-Add-list-flags-command-line-option.patch @@ -0,0 +1,213 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Stefan Reiter +Date: Wed, 27 May 2020 13:51:52 +0200 +Subject: [PATCH] PVE: Add -list-flags command line option + +Prints all flags for a given cpu model to stdout. + +Signed-off-by: Stefan Reiter +--- + include/sysemu/cpus.h | 1 + + qemu-options.hx | 8 ++++++ + softmmu/cpus.c | 10 +++++++ + softmmu/vl.c | 20 ++++++++++++++ + target/i386/cpu-sysemu.c | 2 +- + target/i386/cpu.c | 58 ++++++++++++++++++++++++++++++++++++++++ + target/i386/cpu.h | 4 +++ + 7 files changed, 102 insertions(+), 1 deletion(-) + +diff --git a/include/sysemu/cpus.h b/include/sysemu/cpus.h +index 868f1192de..433265b166 100644 +--- a/include/sysemu/cpus.h ++++ b/include/sysemu/cpus.h +@@ -56,5 +56,6 @@ extern int smp_threads; + #endif + + void list_cpus(const char *optarg); ++int list_cpu_flags(const char *model_name, Error **errp); + + #endif +diff --git a/qemu-options.hx b/qemu-options.hx +index 83aa59a920..33a8a31aa4 100644 +--- a/qemu-options.hx ++++ b/qemu-options.hx +@@ -137,6 +137,14 @@ SRST + selection) + ERST + ++DEF("list-flags", 0, QEMU_OPTION_list_flags, ++ "-list-flags list all flags of specified -cpu on stdout, then exit. Respects -machine versions.\n", QEMU_ARCH_I386) ++SRST ++``-list-flags`` ++ List all flags of specified -cpu on stdout, then exit. Respects ++ -machine versions. ++ERST ++ + DEF("accel", HAS_ARG, QEMU_OPTION_accel, + "-accel [accel=]accelerator[,prop[=value][,...]]\n" + " select accelerator (kvm, xen, hax, hvf, nvmm, whpx or tcg; use 'help' for a list)\n" +diff --git a/softmmu/cpus.c b/softmmu/cpus.c +index 071085f840..f8351e2154 100644 +--- a/softmmu/cpus.c ++++ b/softmmu/cpus.c +@@ -726,6 +726,16 @@ void list_cpus(const char *optarg) + #endif + } + ++int list_cpu_flags(const char *model_name, Error **errp) ++{ ++#if defined(cpu_list_flags) ++ return cpu_list_flags(model_name, errp); ++#endif ++ ++ fprintf(stderr, "-list-flags not available for this architecture\n"); ++ return 1; ++} ++ + void qmp_memsave(int64_t addr, int64_t size, const char *filename, + bool has_cpu, int64_t cpu_index, Error **errp) + { +diff --git a/softmmu/vl.c b/softmmu/vl.c +index 5ca11e7469..f47f076a1f 100644 +--- a/softmmu/vl.c ++++ b/softmmu/vl.c +@@ -145,6 +145,7 @@ typedef struct ObjectOption { + } ObjectOption; + + static const char *cpu_option; ++bool list_cpu_flags_opt = false; + static const char *mem_path; + static const char *incoming; + static const char *loadvm; +@@ -2817,6 +2818,9 @@ void qemu_init(int argc, char **argv, char **envp) + /* hw initialization will check this */ + cpu_option = optarg; + break; ++ case QEMU_OPTION_list_flags: ++ list_cpu_flags_opt = true; ++ break; + case QEMU_OPTION_hda: + case QEMU_OPTION_hdb: + case QEMU_OPTION_hdc: +@@ -3635,6 +3639,22 @@ void qemu_init(int argc, char **argv, char **envp) + } + trace_init_file(); + ++ /* list flags if requested, then exit */ ++ if (list_cpu_flags_opt) { ++ if (!cpu_option) { ++ printf("-cpu argument required for -list-flags\n"); ++ exit(1); ++ } ++ ++ /* Check for and remove cpu parameters other than model */ ++ char *commaIdx = strchr(cpu_option, ','); ++ if (commaIdx != NULL) { ++ *commaIdx = 0; ++ } ++ ++ exit(list_cpu_flags(cpu_option, &error_fatal)); ++ } ++ + qemu_init_main_loop(&error_fatal); + cpu_timers_init(); + +diff --git a/target/i386/cpu-sysemu.c b/target/i386/cpu-sysemu.c +index 1078e3d157..1ebff3d847 100644 +--- a/target/i386/cpu-sysemu.c ++++ b/target/i386/cpu-sysemu.c +@@ -142,7 +142,7 @@ static void object_apply_props(Object *obj, QDict *props, Error **errp) + } + + /* Create X86CPU object according to model+props specification */ +-static X86CPU *x86_cpu_from_model(const char *model, QDict *props, Error **errp) ++X86CPU *x86_cpu_from_model(const char *model, QDict *props, Error **errp) + { + X86CPU *xc = NULL; + X86CPUClass *xcc; +diff --git a/target/i386/cpu.c b/target/i386/cpu.c +index 34a7ce865b..a972dff4ed 100644 +--- a/target/i386/cpu.c ++++ b/target/i386/cpu.c +@@ -6855,3 +6855,61 @@ static void x86_cpu_register_types(void) + } + + type_init(x86_cpu_register_types) ++ ++int x86_cpu_list_flags(const char *model_name, Error **errp) { ++ X86CPU *cpu; ++ ++ cpu = x86_cpu_from_model(model_name, NULL, errp); ++ if (!cpu) { ++ fprintf(stderr, "Unknown CPU model '%s'\n", model_name); ++ return 1; ++ } ++ ++ strList *result = NULL; ++ x86_cpu_list_feature_names(cpu->env.features, &result); ++ if (!result) { ++ fprintf(stderr, "No flags found for CPU model '%s'\n", model_name); ++ return 1; ++ } ++ ++ strList *flag = result; ++ strList *seen = NULL; ++ strList **seenPtr; ++ ++ while (flag) { ++ /* with 'host' and 'max' there are some flags without a value */ ++ if (!flag->value) { ++ goto nextLoop; ++ } ++ ++ /* don't print duplicates */ ++ bool newFlag = true; ++ seenPtr = &seen; ++ while (*seenPtr) { ++ if (newFlag && strcmp((*seenPtr)->value, flag->value) == 0) { ++ newFlag = false; ++ } ++ seenPtr = &(*seenPtr)->next; ++ } ++ ++ if (newFlag) { ++ printf("%s ", flag->value); ++ ++ /* insert into 'seen' list; seenPtr points to first empty '->next' ++ * after loop above, so we can insert there directly */ ++ strList *new = g_new0(strList, 1); ++ new->value = g_strdup(flag->value); ++ *seenPtr = new; ++ } ++ ++nextLoop: ++ flag = flag->next; ++ } ++ printf("\n"); ++ ++ if (seen) { ++ g_free(seen); ++ } ++ g_free(result); ++ return 0; ++} +diff --git a/target/i386/cpu.h b/target/i386/cpu.h +index 6c50d3ab4f..bb88f53a2d 100644 +--- a/target/i386/cpu.h ++++ b/target/i386/cpu.h +@@ -2013,6 +2013,7 @@ uint64_t cpu_get_tsc(CPUX86State *env); + + #define cpu_signal_handler cpu_x86_signal_handler + #define cpu_list x86_cpu_list ++#define cpu_list_flags x86_cpu_list_flags + + /* MMU modes definitions */ + #define MMU_KSMAP_IDX 0 +@@ -2246,4 +2247,7 @@ static inline uint64_t cr4_reserved_bits(CPUX86State *env) + # define TARGET_VSYSCALL_PAGE (UINT64_C(-10) << 20) + #endif + ++X86CPU *x86_cpu_from_model(const char *model, QDict *props, Error **errp); ++int x86_cpu_list_flags(const char *model_name, Error **errp); ++ + #endif /* I386_CPU_H */ diff --git a/debian/patches/series b/debian/patches/series index fb5c213..70ce86e 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -59,3 +59,4 @@ pve/0045-block-io-accept-NULL-qiov-in-bdrv_pad_request.patch pve/0046-block-add-alloc-track-driver.patch pve/0047-PVE-whitelist-invalid-QAPI-names-for-backwards-compa.patch pve/0048-PVE-savevm-async-register-yank-before-migration_inco.patch +pve/0049-PVE-Add-list-flags-command-line-option.patch -- 2.30.2