x86: QEMU side support on MSR based features
v3 cover x86: QEMU side support on MSR based features
KVM side has added the framework (kvm.git:d1d93fa90) to support MSR based features. Here is the QEMU part, including data structure changes/expanding, referring functions changes, and the implementations on KVM_GET_MSR_FEATURE_INDEX_LIST and KVM_GET_MSRS system ioctl.
Changelog:
v3: patch 2&3 in v2 are corrupted. Re-format patches.
v2: coding style changes to pass ./scripts/checkpatch.pl.
----------------
Robert Hoo (3):
x86: Data structure changes to support MSR based features
kvm: Add support to KVM_GET_MSR_FEATURE_INDEX_LIST and KVM_GET_MSRS
system ioctl
Change other funcitons referring to feature_word_info[]
include/sysemu/kvm.h | 2 + target/i386/cpu.c | 210 +++++++++++++++++++++++++++++++++++++-------------- target/i386/cpu.h | 5 ++ target/i386/kvm.c | 79 +++++++++++++++++++ 4 files changed, 238 insertions(+), 58 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v3 1/3 x86: Data structure changes to support MSR based features
Define FeatureWordType.
Expand FeatureWordInfo to support both CPUID type feature word as well as MSR type's.
Change feature_word_info[] accordingly.
--- target/i386/cpu.c | 133 ++++++++++++++++++++++++++++++++++++++---------------- target/i386/cpu.h | 5 ++ 2 files changed, 99 insertions(+), 39 deletions(-)
target/i386/cpu.c +94 -39
@@ -770,17 +770,36 @@ static void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1,/* missing: CPUID_XSAVE_XSAVEC, CPUID_XSAVE_XSAVES */ +typedef enum FeatureWordType { +CPUID_FEATURE_WORD , +MSR_FEATURE_WORD , +}FeatureWordType ; + typedef struct FeatureWordInfo { - /* feature flags names are taken from "Intel Processor Identification and + FeatureWordType type; + /* feature flags names are taken from "Intel Processor Identification and * the CPUID Instruction" and AMD's "CPUID Specification". * In cases of disagreement between feature naming conventions, * aliases may be added. */ const char *feat_names[32]; - uint32_t cpuid_eax; /* Input EAX for CPUID */ - bool cpuid_needs_ecx; /* CPUID instruction uses ECX as input */ - uint32_t cpuid_ecx; /* Input ECX value for CPUID */ - int cpuid_reg; /* output register (R_* constant) */ + union { + /* If type==CPUID_FEATURE_WORD */ + struct { + uint32_t eax; /* Input EAX for CPUID */ + bool needs_ecx; /* CPUID instruction uses ECX as input */ + uint32_t ecx; /* Input ECX value for CPUID */ + int reg; /* output register (R_* constant) */ + } cpuid; + /* If type==MSR_FEATURE_WORD */ + struct { + uint32_t index; + struct { /*CPUID that enumerate this MSR*/ + FeatureWord cpuid_class; + uint32_t cpuid_flag; + } cpuid_dep; + } msr; + }; uint32_t tcg_features; /* Feature flags supported by TCG */ uint32_t unmigratable_flags; /* Feature flags known to be unmigratable */ uint32_t migratable_flags; /* Feature flags known to be migratable */
@@ -790,6 +809,7 @@ typedef struct FeatureWordInfo {static FeatureWordInfo feature_word_info[FEATURE_WORDS ] = { [FEAT_1_EDX ] = { + .type =CPUID_FEATURE_WORD , .feat_names = {"fpu" ,"vme" ,"de" ,"pse" ,"tsc" ,"msr" ,"pae" ,"mce" ,
@@ -800,10 +820,11 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {"fxsr" ,"sse" ,"sse2" ,"ss" , "ht" /* Intel htt */, "tm", "ia64", "pbe", }, - .cpuid_eax = 1, .cpuid_reg = R_EDX, + .cpuid = {.eax = 1, .reg = R_EDX, }, .tcg_features = TCG_FEATURES, }, [FEAT_1_ECX] = { + .type =CPUID_FEATURE_WORD , .feat_names = {"pni" /* Intel,AMD sse3 */ ,"pclmulqdq" ,"dtes64" ,"monitor" , "ds-cpl", "vmx", "smx", "est",
@@ -814,7 +835,7 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = { "tsc-deadline", "aes", "xsave", NULL /* osxsave */, "avx", "f16c", "rdrand", "hypervisor", }, - .cpuid_eax = 1, .cpuid_reg = R_ECX, + .cpuid = { .eax = 1, .reg = R_ECX, }, .tcg_features = TCG_EXT_FEATURES, },/* Feature names that are already defined on feature_name[] but
@@ -823,6 +844,7 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {* to features[FEAT_8000_0001_EDX] if and only if CPU vendor is AMD. */ [FEAT_8000_0001_EDX] = { + .type = CPUID_FEATURE_WORD, .feat_names = {NULL /* fpu */ ,NULL /* vme */ ,NULL /* de */ ,NULL /* pse */ , NULL /* tsc */, NULL /* msr */, NULL /* pae */, NULL /* mce */,
@@ -833,10 +855,11 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {NULL /* fxsr */ ,"fxsr-opt" ,"pdpe1gb" ,"rdtscp" , NULL, "lm", "3dnowext", "3dnow", }, - .cpuid_eax = 0x80000001, .cpuid_reg = R_EDX, + .cpuid = { .eax = 0x80000001, .reg = R_EDX, }, .tcg_features = TCG_EXT2_FEATURES, }, [FEAT_8000_0001_ECX] = { + .type =CPUID_FEATURE_WORD , .feat_names = {"lahf-lm" ,"cmp-legacy" ,"svm" ,"extapic" , "cr8legacy", "abm", "sse4a", "misalignsse",
@@ -847,10 +870,11 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {"perfctr-nb" ,NULL ,NULL ,NULL , NULL, NULL, NULL, NULL, }, - .cpuid_eax = 0x80000001, .cpuid_reg = R_ECX, + .cpuid = { .eax = 0x80000001, .reg = R_ECX, }, .tcg_features = TCG_EXT3_FEATURES, }, [FEAT_C000_0001_EDX] = { + .type =CPUID_FEATURE_WORD , .feat_names = {NULL ,NULL ,"xstore" ,"xstore-en" , NULL, NULL, "xcrypt", "xcrypt-en",
@@ -861,10 +885,11 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {NULL ,NULL ,NULL ,NULL , NULL, NULL, NULL, NULL, }, - .cpuid_eax = 0xC0000001, .cpuid_reg = R_EDX, + .cpuid = { .eax = 0xC0000001, .reg = R_EDX, }, .tcg_features = TCG_EXT4_FEATURES, }, [FEAT_KVM] = { + .type =CPUID_FEATURE_WORD , .feat_names = {"kvmclock" ,"kvm-nopiodelay" ,"kvm-mmu" ,"kvmclock" , "kvm-asyncpf", "kvm-steal-time", "kvm-pv-eoi", "kvm-pv-unhalt",
@@ -875,10 +900,11 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {"kvmclock-stable-bit" ,NULL ,NULL ,NULL , NULL, NULL, NULL, NULL, }, - .cpuid_eax = KVM_CPUID_FEATURES, .cpuid_reg = R_EAX, + .cpuid = { .eax = KVM_CPUID_FEATURES, .reg = R_EAX, }, .tcg_features = TCG_KVM_FEATURES, }, [FEAT_KVM_HINTS] = { + .type =CPUID_FEATURE_WORD , .feat_names = {"kvm-hint-dedicated" ,NULL ,NULL ,NULL , NULL, NULL, NULL, NULL,
@@ -889,7 +915,7 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {NULL ,NULL ,NULL ,NULL , NULL, NULL, NULL, NULL, }, - .cpuid_eax = KVM_CPUID_FEATURES, .cpuid_reg = R_EDX, + .cpuid = { .eax = KVM_CPUID_FEATURES, .reg = R_EDX, }, .tcg_features =TCG_KVM_FEATURES ,/* * KVM hints aren't auto-enabled by -cpu host, they need to be
@@ -898,6 +924,7 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = { .no_autoenable_flags = ~0U, }, [FEAT_HYPERV_EAX] = { + .type = CPUID_FEATURE_WORD, .feat_names = {NULL /* hv_msr_vp_runtime_access */ ,NULL /* hv_msr_time_refcount_access */ , NULL /* hv_msr_synic_access */, NULL /* hv_msr_stimer_access */,
@@ -912,9 +939,10 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {NULL ,NULL ,NULL ,NULL , NULL, NULL, NULL, NULL, }, - .cpuid_eax = 0x40000003, .cpuid_reg = R_EAX, + .cpuid = { .eax = 0x40000003, .reg = R_EAX, }, }, [FEAT_HYPERV_EBX] = { + .type =CPUID_FEATURE_WORD , .feat_names = {NULL /* hv_create_partitions */ ,NULL /* hv_access_partition_id */ , NULL /* hv_access_memory_pool */, NULL /* hv_adjust_message_buffers */,
@@ -928,9 +956,10 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {NULL ,NULL ,NULL ,NULL , NULL, NULL, NULL, NULL, }, - .cpuid_eax = 0x40000003, .cpuid_reg = R_EBX, + .cpuid = { .eax = 0x40000003, .reg = R_EBX, }, }, [FEAT_HYPERV_EDX] = { + .type =CPUID_FEATURE_WORD , .feat_names = {NULL /* hv_mwait */ ,NULL /* hv_guest_debugging */ , NULL /* hv_perf_monitor */, NULL /* hv_cpu_dynamic_part */,
@@ -943,9 +972,10 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {NULL ,NULL ,NULL ,NULL , NULL, NULL, NULL, NULL, }, - .cpuid_eax = 0x40000003, .cpuid_reg = R_EDX, + .cpuid = { .eax = 0x40000003, .reg = R_EDX, }, }, [FEAT_SVM] = { + .type =CPUID_FEATURE_WORD , .feat_names = {"npt" ,"lbrv" ,"svm-lock" ,"nrip-save" , "tsc-scale", "vmcb-clean", "flushbyasid", "decodeassists",
@@ -956,10 +986,11 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {NULL ,NULL ,NULL ,NULL , NULL, NULL, NULL, NULL, }, - .cpuid_eax = 0x8000000A, .cpuid_reg = R_EDX, + .cpuid = { .eax = 0x8000000A, .reg = R_EDX, }, .tcg_features = TCG_SVM_FEATURES, }, [FEAT_7_0_EBX] = { + .type =CPUID_FEATURE_WORD , .feat_names = {"fsgsbase" ,"tsc-adjust" ,NULL ,"bmi1" , "hle", "avx2", NULL, "smep",
@@ -970,12 +1001,13 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {"clwb" ,"intel-pt" ,"avx512pf" ,"avx512er" , "avx512cd", "sha-ni", "avx512bw", "avx512vl", }, - .cpuid_eax =7 , - .cpuid_needs_ecx = true, .cpuid_ecx = 0, - .cpuid_reg = R_EBX, + .cpuid = { .eax = 7, + .needs_ecx = true, .ecx = 0, + .reg = R_EBX, }, .tcg_features = TCG_7_0_EBX_FEATURES, }, [FEAT_7_0_ECX] = { + .type =CPUID_FEATURE_WORD , .feat_names = {NULL ,"avx512vbmi" ,"umip" ,"pku" , NULL /* ospke */, NULL, "avx512vbmi2", NULL,
@@ -986,12 +1018,13 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = { NULL, "cldemote", NULL, NULL,NULL ,NULL ,NULL ,NULL , }, - .cpuid_eax = 7, - .cpuid_needs_ecx = true, .cpuid_ecx = 0, - .cpuid_reg = R_ECX, + .cpuid = { .eax = 7, + .needs_ecx = true, .ecx =0 , + .reg =R_ECX , }, .tcg_features = TCG_7_0_ECX_FEATURES, }, [FEAT_7_0_EDX] = { + .type =CPUID_FEATURE_WORD , .feat_names = {NULL ,NULL ,"avx512-4vnniw" ,"avx512-4fmaps" ,NULL ,NULL ,NULL ,NULL ,
@@ -1002,13 +1035,14 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {NULL ,NULL ,"spec-ctrl" ,NULL , NULL, "arch-capabilities", NULL, "ssbd", }, - .cpuid_eax =7 , - .cpuid_needs_ecx = true, .cpuid_ecx = 0, - .cpuid_reg = R_EDX, + .cpuid = { .eax = 7, + .needs_ecx = true, .ecx = 0, + .reg = R_EDX, }, .tcg_features =TCG_7_0_EDX_FEATURES , .unmigratable_flags = CPUID_7_0_EDX_ARCH_CAPABILITIES, }, [FEAT_8000_0007_EDX] = { + .type =CPUID_FEATURE_WORD , .feat_names = {NULL ,NULL ,NULL ,NULL , NULL, NULL, NULL, NULL,
@@ -1019,12 +1053,12 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {NULL ,NULL ,NULL ,NULL , NULL, NULL, NULL, NULL, }, - .cpuid_eax =0x80000007 , - .cpuid_reg = R_EDX, + .cpuid = { .eax = 0x80000007, .reg = R_EDX, }, .tcg_features =TCG_APM_FEATURES , .unmigratable_flags = CPUID_APM_INVTSC, }, [FEAT_8000_0008_EBX] = { + .type =CPUID_FEATURE_WORD , .feat_names = {NULL ,NULL ,NULL ,NULL , NULL, NULL, NULL, NULL,
@@ -1035,12 +1069,12 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {"amd-ssbd" ,"virt-ssbd" ,"amd-no-ssb" ,NULL , NULL, NULL, NULL, NULL, }, - .cpuid_eax =0x80000008 , - .cpuid_reg = R_EBX, + .cpuid = { .eax = 0x80000008, .reg = R_EBX, }, .tcg_features =0 , .unmigratable_flags = 0, }, [FEAT_XSAVE] = { + .type =CPUID_FEATURE_WORD , .feat_names = {"xsaveopt" ,"xsavec" ,"xgetbv1" ,"xsaves" , NULL, NULL, NULL, NULL,
@@ -1051,12 +1085,13 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {NULL ,NULL ,NULL ,NULL , NULL, NULL, NULL, NULL, }, - .cpuid_eax =0xd , - .cpuid_needs_ecx = true, .cpuid_ecx = 1, - .cpuid_reg = R_EAX, + .cpuid = { .eax = 0xd, + .needs_ecx = true, .ecx = 1, + .reg = R_EAX, }, .tcg_features = TCG_XSAVE_FEATURES, }, [FEAT_6_EAX] = { + .type =CPUID_FEATURE_WORD , .feat_names = {NULL ,NULL ,"arat" ,NULL , NULL, NULL, NULL, NULL,
@@ -1067,13 +1102,14 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = {NULL ,NULL ,NULL ,NULL , NULL, NULL, NULL, NULL, }, - .cpuid_eax = 6, .cpuid_reg = R_EAX, + .cpuid = { .eax = 6, .reg = R_EAX, }, .tcg_features = TCG_6_EAX_FEATURES, }, [FEAT_XSAVE_COMP_LO] = { - .cpuid_eax =0xD , - .cpuid_needs_ecx = true, .cpuid_ecx = 0, - .cpuid_reg = R_EAX, + .type =CPUID_FEATURE_WORD , + .cpuid = { .eax = 0xD, + .needs_ecx = true, .ecx = 0, + .reg = R_EAX, }, .tcg_features = ~0U , .migratable_flags = XSTATE_FP_MASK | XSTATE_SSE_MASK | XSTATE_YMM_MASK | XSTATE_BNDREGS_MASK | XSTATE_BNDCSR_MASK |
@@ -1081,11 +1117,30 @@ static FeatureWordInfo feature_word_info[FEATURE_WORDS] = { XSTATE_PKRU_MASK, }, [FEAT_XSAVE_COMP_HI] = { - .cpuid_eax = 0xD, - .cpuid_needs_ecx = true, .cpuid_ecx = 0, - .cpuid_reg = R_EDX, + .type = CPUID_FEATURE_WORD, + .cpuid = { .eax = 0xD, + .needs_ecx = true, .ecx = 0, + .reg = R_EDX, }, .tcg_features = ~0U, }, +/*Below are MSR exposed features*/ + [FEATURE_WORDS_ARCH_CAPABILITIES] = { + .type = MSR_FEATURE_WORD, + .feat_names = { + "rdctl-no", "ibrs-all", "rsba", NULL, + "ssb-no", NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + }, + .msr = { .index = MSR_IA32_ARCH_CAPABILITIES, + .cpuid_dep = { FEAT_7_0_EDX, + CPUID_7_0_EDX_ARCH_CAPABILITIES } + }, + }, }; typedef struct X86RegisterInfo32 {
target/i386/cpu.h +5 -0
@@ -502,9 +502,14 @@ typedef enum FeatureWord {FEAT_6_EAX ,/* CPUID[6].EAX */ FEAT_XSAVE_COMP_LO ,/* CPUID[EAX=0xd,ECX=0].EAX */ FEAT_XSAVE_COMP_HI ,/* CPUID[EAX=0xd,ECX=0].EDX */ +FEATURE_WORDS_NUM_CPUID , +FEATURE_WORDS_FIRST_MSR =FEATURE_WORDS_NUM_CPUID , +FEATURE_WORDS_ARCH_CAPABILITIES =FEATURE_WORDS_FIRST_MSR ,FEATURE_WORDS , } FeatureWord; +#define FEATURE_WORDS_NUM_MSRS (FEATURE_WORDS - FEATURE_WORDS_FIRST_MSR) +typedef uint32_t FeatureWordArray [FEATURE_WORDS ];/* cpuid_features bits */
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 1/3] x86: Data structure changes to support MSR based features
Hi,
Thanks for the patch and sorry for taking so long to review. Comments below:
Quoted 47 lines · Robert Hoo
Define FeatureWordType.
Expand FeatureWordInfo to support both CPUID type feature word as well as MSR type's.
Change feature_word_info[] accordingly.Signed-off-by Robert Hoo <[email protected]>--- target/i386/cpu.c | 133 ++++++++++++++++++++++++++++++++++++++---------------- target/i386/cpu.h | 5 ++ 2 files changed, 99 insertions(+), 39 deletions(-)target/i386/cpu.c +17
-5@@ -770,17 +770,36 @@ static void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1,/* missing: CPUID_XSAVE_XSAVEC, CPUID_XSAVE_XSAVES */ +typedef enum FeatureWordType { +CPUID_FEATURE_WORD , +MSR_FEATURE_WORD , +}FeatureWordType ; + typedef struct FeatureWordInfo { - /* feature flags names are taken from "Intel Processor Identification and + FeatureWordType type; + /* feature flags names are taken from "Intel Processor Identification and * the CPUID Instruction" and AMD's "CPUID Specification". * In cases of disagreement between feature naming conventions, * aliases may be added. */ const char *feat_names[32]; - uint32_t cpuid_eax; /* Input EAX for CPUID */ - bool cpuid_needs_ecx; /* CPUID instruction uses ECX as input */ - uint32_t cpuid_ecx; /* Input ECX value for CPUID */ - int cpuid_reg; /* output register (R_* constant) */ + union { + /* If type==CPUID_FEATURE_WORD */ + struct { + uint32_t eax; /* Input EAX for CPUID */ + bool needs_ecx; /* CPUID instruction uses ECX as input */ + uint32_t ecx; /* Input ECX value for CPUID */ + int reg; /* output register (R_* constant) */ + } cpuid; + /* If type==MSR_FEATURE_WORD */ + struct {
target/i386/cpu.c static void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1, · line 805
Quoted 10 lines
target/i386/cpu.c +7
-0+uint32_t index; +struct {/*CPUID that enumerate this MSR*/ +FeatureWord cpuid_class; +uint32_t cpuid_flag; + } cpuid_dep; + } msr; + };uint32_t tcg_features;/* Feature flags supported by TCG */ uint32_t unmigratable_flags;/* Feature flags known to be unmigratable */ uint32_t migratable_flags;/* Feature flags known to be migratable */
The data structure change looks good, but you are breaking the build if you touch them without updating the existing code. If you break the build in your series, you break git-bisect.
[...]
Quoted 8 lines
target/i386/cpu.c +8
-0+ /*Below are MSR exposed features*/ + [FEATURE_WORDS_ARCH_CAPABILITIES] = { + .type = MSR_FEATURE_WORD, + .feat_names = { +"rdctl-no" ,"ibrs-all" ,"rsba" ,NULL , +"ssb-no" ,NULL ,NULL ,NULL , +NULL ,NULL ,NULL ,NULL , + NULL, NULL, NULL, NULL,
target/i386/cpu.c static FeatureWordInfo feature_word_info[FEATURE_WORDS] = { · line 1143
Quoted 10 lines
target/i386/cpu.c +10
-0+ NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + }, + .msr = { .index = MSR_IA32_ARCH_CAPABILITIES, + .cpuid_dep = { FEAT_7_0_EDX, + CPUID_7_0_EDX_ARCH_CAPABILITIES } + }, + },
I suggest moving this hunk to a separate patch: first we refactor the existing code without changing behavior or adding new features, then we add the new features.
Quoted 26 lines
};
typedef struct X86RegisterInfo32 {
target/i386/cpu.h +5
-0@@ -502,9 +502,14 @@ typedef enum FeatureWord {FEAT_6_EAX ,/* CPUID[6].EAX */ FEAT_XSAVE_COMP_LO ,/* CPUID[EAX=0xd,ECX=0].EAX */ FEAT_XSAVE_COMP_HI ,/* CPUID[EAX=0xd,ECX=0].EDX */ +FEATURE_WORDS_NUM_CPUID , +FEATURE_WORDS_FIRST_MSR =FEATURE_WORDS_NUM_CPUID , +FEATURE_WORDS_ARCH_CAPABILITIES =FEATURE_WORDS_FIRST_MSR ,FEATURE_WORDS , } FeatureWord; +#define FEATURE_WORDS_NUM_MSRS (FEATURE_WORDS - FEATURE_WORDS_FIRST_MSR) +typedef uint32_t FeatureWordArray [FEATURE_WORDS ];/* cpuid_features bits */ Signature · 1 line
1.8.3.1
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v3 1/3] x86: Data structure changes to support MSR based features
On Fri, 2018-08-17 at 00:10 -0300, Eduardo Habkost wrote:
[trim...]
Quoted 35 lines
Quoted 24 lines
target/i386/cpu.c +13
-5+ typedef struct FeatureWordInfo { - /* feature flags names are taken from "Intel Processor Identification and + FeatureWordType type; + /* feature flags names are taken from "Intel Processor Identification and * the CPUID Instruction" and AMD's "CPUID Specification". * In cases of disagreement between feature naming conventions, * aliases may be added. */ const char *feat_names[32]; - uint32_t cpuid_eax; /* Input EAX for CPUID */ - bool cpuid_needs_ecx; /* CPUID instruction uses ECX as input */ - uint32_t cpuid_ecx; /* Input ECX value for CPUID */ - int cpuid_reg; /* output register (R_* constant) */ + union { + /* If type==CPUID_FEATURE_WORD */ + struct { + uint32_t eax; /* Input EAX for CPUID */ + bool needs_ecx; /* CPUID instruction uses ECX as input */ + uint32_t ecx; /* Input ECX value for CPUID */ + int reg; /* output register (R_* constant) */ + } cpuid; + /* If type==MSR_FEATURE_WORD */ + struct {target/i386/cpu.c static void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1, · line 805
Quoted 10 lines
target/i386/cpu.c +7
-0+uint32_t index; +struct {/*CPUID that enumerate this MSR*/ +FeatureWord cpuid_class; +uint32_t cpuid_flag; + } cpuid_dep; + } msr; + };uint32_t tcg_features;/* Feature flags supported by TCG */ uint32_t unmigratable_flags;/* Feature flags known to be unmigratable */ uint32_t migratable_flags;/* Feature flags known to be migratable */
Quoted 4 lines
The data structure change looks good, but you are breaking the build if you touch them without updating the existing code. If you break the build in your series, you break git-bisect.
I had tested in my environment before send out, build has no even a warning. Is it because this patch is based on master + previous icelake cpu model set? I see you are pulling in previous icelake cpu model patch set. I will rebase this patch to then master. Will previous icelake cpu model patch set appear in master soon?
Quoted 21 lines
[...]
Quoted 8 lines
target/i386/cpu.c +8
-0+ /*Below are MSR exposed features*/ + [FEATURE_WORDS_ARCH_CAPABILITIES] = { + .type = MSR_FEATURE_WORD, + .feat_names = { +"rdctl-no" ,"ibrs-all" ,"rsba" ,NULL , +"ssb-no" ,NULL ,NULL ,NULL , +NULL ,NULL ,NULL ,NULL , + NULL, NULL, NULL, NULL,target/i386/cpu.c static FeatureWordInfo feature_word_info[FEATURE_WORDS] = { · line 1143
Quoted 10 lines
target/i386/cpu.c +10
-0+ NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + }, + .msr = { .index = MSR_IA32_ARCH_CAPABILITIES, + .cpuid_dep = { FEAT_7_0_EDX, + CPUID_7_0_EDX_ARCH_CAPABILITIES } + }, + },
Quoted 4 lines
I suggest moving this hunk to a separate patch: first we refactor the existing code without changing behavior or adding new features, then we add the new features.
Sure.
Quoted 27 lines
Quoted 26 lines
};
typedef struct X86RegisterInfo32 {
target/i386/cpu.h +5
-0@@ -502,9 +502,14 @@ typedef enum FeatureWord {FEAT_6_EAX ,/* CPUID[6].EAX */ FEAT_XSAVE_COMP_LO ,/* CPUID[EAX=0xd,ECX=0].EAX */ FEAT_XSAVE_COMP_HI ,/* CPUID[EAX=0xd,ECX=0].EDX */ +FEATURE_WORDS_NUM_CPUID , +FEATURE_WORDS_FIRST_MSR =FEATURE_WORDS_NUM_CPUID , +FEATURE_WORDS_ARCH_CAPABILITIES =FEATURE_WORDS_FIRST_MSR ,FEATURE_WORDS , } FeatureWord; +#define FEATURE_WORDS_NUM_MSRS (FEATURE_WORDS - FEATURE_WORDS_FIRST_MSR) +typedef uint32_t FeatureWordArray [FEATURE_WORDS ];/* cpuid_features bits */ Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 1/3] x86: Data structure changes to support MSR based features
Quoted 41 lines · Robert Hoo
On Fri, 2018-08-17 at 00:10 -0300, Eduardo Habkost wrote:
[trim...]Quoted 35 lines
Quoted 24 lines
target/i386/cpu.c +13
-5+ typedef struct FeatureWordInfo { - /* feature flags names are taken from "Intel Processor Identification and + FeatureWordType type; + /* feature flags names are taken from "Intel Processor Identification and * the CPUID Instruction" and AMD's "CPUID Specification". * In cases of disagreement between feature naming conventions, * aliases may be added. */ const char *feat_names[32]; - uint32_t cpuid_eax; /* Input EAX for CPUID */ - bool cpuid_needs_ecx; /* CPUID instruction uses ECX as input */ - uint32_t cpuid_ecx; /* Input ECX value for CPUID */ - int cpuid_reg; /* output register (R_* constant) */ + union { + /* If type==CPUID_FEATURE_WORD */ + struct { + uint32_t eax; /* Input EAX for CPUID */ + bool needs_ecx; /* CPUID instruction uses ECX as input */ + uint32_t ecx; /* Input ECX value for CPUID */ + int reg; /* output register (R_* constant) */ + } cpuid; + /* If type==MSR_FEATURE_WORD */ + struct {target/i386/cpu.c static void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1, · line 805
Quoted 10 lines
target/i386/cpu.c +7
-0+uint32_t index; +struct {/*CPUID that enumerate this MSR*/ +FeatureWord cpuid_class; +uint32_t cpuid_flag; + } cpuid_dep; + } msr; + };uint32_t tcg_features;/* Feature flags supported by TCG */ uint32_t unmigratable_flags;/* Feature flags known to be unmigratable */ uint32_t migratable_flags;/* Feature flags known to be migratable */ Quoted 4 lines
The data structure change looks good, but you are breaking the build if you touch them without updating the existing code. If you break the build in your series, you break git-bisect.
Quoted 5 lines
I had tested in my environment before send out, build has no even a warning. Is it because this patch is based on master + previous icelake cpu model set? I see you are pulling in previous icelake cpu model patch set. I will rebase this patch to then master. Will previous icelake cpu model patch set appear in master soon?
or you mean each single patch in a series should be individually built pass? then it will a huge one here: data structure changes + reference functions.
Quoted 56 lines
Quoted 21 lines
[...]
Quoted 8 lines
target/i386/cpu.c +8
-0+ /*Below are MSR exposed features*/ + [FEATURE_WORDS_ARCH_CAPABILITIES] = { + .type = MSR_FEATURE_WORD, + .feat_names = { +"rdctl-no" ,"ibrs-all" ,"rsba" ,NULL , +"ssb-no" ,NULL ,NULL ,NULL , +NULL ,NULL ,NULL ,NULL , + NULL, NULL, NULL, NULL,target/i386/cpu.c static FeatureWordInfo feature_word_info[FEATURE_WORDS] = { · line 1143
Quoted 10 lines
target/i386/cpu.c +10
-0+ NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + }, + .msr = { .index = MSR_IA32_ARCH_CAPABILITIES, + .cpuid_dep = { FEAT_7_0_EDX, + CPUID_7_0_EDX_ARCH_CAPABILITIES } + }, + },Quoted 4 lines
I suggest moving this hunk to a separate patch: first we refactor the existing code without changing behavior or adding new features, then we add the new features.
Sure.
Quoted 27 lines
Quoted 26 lines
};
typedef struct X86RegisterInfo32 {
target/i386/cpu.h +5
-0@@ -502,9 +502,14 @@ typedef enum FeatureWord {FEAT_6_EAX ,/* CPUID[6].EAX */ FEAT_XSAVE_COMP_LO ,/* CPUID[EAX=0xd,ECX=0].EAX */ FEAT_XSAVE_COMP_HI ,/* CPUID[EAX=0xd,ECX=0].EDX */ +FEATURE_WORDS_NUM_CPUID , +FEATURE_WORDS_FIRST_MSR =FEATURE_WORDS_NUM_CPUID , +FEATURE_WORDS_ARCH_CAPABILITIES =FEATURE_WORDS_FIRST_MSR ,FEATURE_WORDS , } FeatureWord; +#define FEATURE_WORDS_NUM_MSRS (FEATURE_WORDS - FEATURE_WORDS_FIRST_MSR) +typedef uint32_t FeatureWordArray [FEATURE_WORDS ];/* cpuid_features bits */ Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 1/3] x86: Data structure changes to support MSR based features
----- Original Message -----
Quoted 59 lines
From: "Robert Hoo" <[email protected]>
To: "Eduardo Habkost" <[email protected]>
Cc: "robert hu" <[email protected]>, "robert hu" <[email protected]>, [email protected], [email protected], "thomas lendacky" <[email protected]>, [email protected], "jingqi liu" <[email protected]>
Sent: Saturday, August 18, 2018 7:48:43 AM
Subject: Re: [Qemu-devel] [PATCH v3 1/3] x86: Data structure changes to support MSR based featuresQuoted 45 lines · Robert Hoo
On Fri, 2018-08-17 at 00:10 -0300, Eduardo Habkost wrote:
[trim...]Quoted 39 lines
Quoted 28 lines
target/i386/cpu.c +1
-1+ typedef struct FeatureWordInfo { - /* feature flags names are taken from "Intel ProcessorIdentification and
(quoted diff) +2
-0+ FeatureWordType type; + /* feature flags names are taken from "Intel ProcessorIdentification and
* the CPUID Instruction" and AMD's "CPUID Specification".
* In cases of disagreement between feature naming conventions,
* aliases may be added.
*/
const char *feat_names[32];target/i386/cpu.c +12
-4-uint32_t cpuid_eax;/* Input EAX for CPUID */ -bool cpuid_needs_ecx;/* CPUID instruction uses ECX as input */ -uint32_t cpuid_ecx;/* Input ECX value for CPUID */ -int cpuid_reg;/* output register (R_* constant) */ + union { + /* If type==CPUID_FEATURE_WORD */ + struct { + uint32_t eax; /* Input EAX for CPUID */ + bool needs_ecx; /* CPUID instruction uses ECX as input */ + uint32_t ecx; /* Input ECX value for CPUID */ + int reg; /* output register (R_* constant) */ + } cpuid; + /* If type==MSR_FEATURE_WORD */ + struct { + uint32_t index; + struct { /*CPUID that enumerate this MSR*/target/i386/cpu.c static void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1,
Quoted 10 lines
target/i386/cpu.c +5
-0+FeatureWord cpuid_class; +uint32_t cpuid_flag; + } cpuid_dep; + } msr; + };uint32_t tcg_features;/* Feature flags supported by TCG */ uint32_t unmigratable_flags;/* Feature flags known to be unmigratable */ uint32_t migratable_flags;/* Feature flags known to be migratable */ Quoted 4 lines
The data structure change looks good, but you are breaking the build if you touch them without updating the existing code. If you break the build in your series, you break git-bisect.
Quoted 5 lines
I had tested in my environment before send out, build has no even a warning. Is it because this patch is based on master + previous icelake cpu model set? I see you are pulling in previous icelake cpu model patch set. I will rebase this patch to then master. Will previous icelake cpu model patch set appear in master soon?
Quoted 3 lines
or you mean each single patch in a series should be individually built pass? then it will a huge one here: data structure changes + reference functions.
Yes, each patch should individually build and pass. That's why you should first introduce the changes to CPUID feature words (data structure and functions) and then add support for MSR features.
Paolo
Re: [Qemu-devel] [PATCH v3 1/3] x86: Data structure changes to support MSR based features
In reply to Robert Hootarget/i386/cpu.c static void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1, · line 776
Quoted 4 lines · Robert Hoo
target/i386/cpu.c +4
-0+typedef enum FeatureWordType { +CPUID_FEATURE_WORD , +MSR_FEATURE_WORD , +}FeatureWordType ;
This enum probably should be defined with QAPI, so that it can be reused in the feature-words property:
# @X86CPUFeatureWordType:
#
# Kinds of X86 CPU feature words
#
# @cpuid: A CPUID leaf
#
# @msr: An MSR
##
{ 'enum': 'X86CPUFeatureWordType',
'data': 'cpuid', 'msr' }
The names will be X86_CPU_FEATURE_WORD_TYPE_CPUID and X86_CPU_FEATURE_WORD_TYPE_MSR.
Thanks,
Paolo
Re: [Qemu-devel] [PATCH v3 1/3] x86: Data structure changes to support MSR based features
Quoted 20 lines · Paolo Bonzini
target/i386/cpu.c static void x86_cpu_vendor_words2str(char *dst, uint32_t vendor1, · line 776
Quoted 4 lines · Robert Hoo
target/i386/cpu.c +4
-0+typedef enum FeatureWordType { +CPUID_FEATURE_WORD , +MSR_FEATURE_WORD , +}FeatureWordType ;This enum probably should be defined with QAPI, so that it can be reused in the feature-words property:
# @X86CPUFeatureWordType:
#
# Kinds of X86 CPU feature words
#
# @cpuid: A CPUID leaf
#
# @msr: An MSR
##
{ 'enum': 'X86CPUFeatureWordType',
'data': 'cpuid', 'msr' }
Quoted 2 lines
The names will be
X86_CPU_FEATURE_WORD_TYPE_CPUIDandX86_CPU_FEATURE_WORD_TYPE_MSR.
I wouldn't like to make this an external API unless really necessary. I would rather deprecate the "feature-words" property because nobody ended up using it.
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v3 1/3] x86: Data structure changes to support MSR based features
Quoted 5 lines · Eduardo Habkost
Quoted 2 lines
The names will be
X86_CPU_FEATURE_WORD_TYPE_CPUIDandX86_CPU_FEATURE_WORD_TYPE_MSR.I wouldn't like to make this an external API unless really necessary. I would rather deprecate the "feature-words" property because nobody ended up using it.
I think we should either remove it directly, or extend it to support MSR features. Deprecating and only supporting CPUID features is the worst of both worlds...
Paolo
[Qemu-devel] X86CPU "feature-words" property on QEMU (was Re: [PATCH v3 1/3] x86: Data structure changes to support MSR based) features
Quoted 10 lines · Paolo Bonzini
Quoted 5 lines · Eduardo Habkost
Quoted 2 lines
The names will be
X86_CPU_FEATURE_WORD_TYPE_CPUIDandX86_CPU_FEATURE_WORD_TYPE_MSR.I wouldn't like to make this an external API unless really necessary. I would rather deprecate the "feature-words" property because nobody ended up using it.
I think we should either remove it directly, or extend it to support MSR features. Deprecating and only supporting CPUID features is the worst of both worlds...
So let's do what's necessary to remove it. But I don't think the removal of "feature-words" should block the inclusion of this series.
Now, should QOM properties follow our feature deprecation policy, or they were never a supported external API and we can remove it immediately?
CCing Jiri and libvir-list, because I just found that there's code on libvirt that uses it, but I don't know exactly it does with that info.
Signature · 1 line
Eduardo
Re: [Qemu-devel] X86CPU "feature-words" property on QEMU (was Re: [PATCH v3 1/3] x86: Data structure changes to support MSR based) features
Quoted 11 lines · Eduardo Habkost
So let's do what's necessary to remove it. But I don't think the removal of "feature-words" should block the inclusion of this series.
Now, should QOM properties follow our feature deprecation policy, or they were never a supported external API and we can remove it immediately?
CCing Jiri and libvir-list, because I just found that there's code on libvirt that uses it, but I don't know exactly it does with that info.
It is used to check whether the host supports invtsc and pv-unhalt and avoid changing the guest ABI when migrating: see
https://marc.info/?l=libvir-list&m=152445761414746&w=2 for a patch that introduces one user.
I think we should extend it to MSRs, not remove it.
Paolo
Re: [Qemu-devel] X86CPU "feature-words" property on QEMU (was Re: [PATCH v3 1/3] x86: Data structure changes to support MSR based) features
Quoted 13 lines · Paolo Bonzini
Quoted 11 lines · Eduardo Habkost
So let's do what's necessary to remove it. But I don't think the removal of "feature-words" should block the inclusion of this series.
Now, should QOM properties follow our feature deprecation policy, or they were never a supported external API and we can remove it immediately?
CCing Jiri and libvir-list, because I just found that there's code on libvirt that uses it, but I don't know exactly it does with that info.
Quoted 6 lines
It is used to check whether the host supports invtsc and pv-unhalt and avoid changing the guest ABI when migrating: see
https://marc.info/?l=libvir-list&m=152445761414746&w=2 for a patch that introduces one user.I think we should extend it to MSRs, not remove it.
Well, I would prefer if libvirt simply did (e.g.) "qom-get property=invtsc" instead of fetching raw feature-words data. But if we do have an existing user, I now agree with you:
let's keep it working and extend it to include MSR info too.
BTW, libvirt must stop using this hardcoded QOM path:
#define QOM_CPU_PATH "/machine/unattached/device[0]"
It should use the "qom_path" field of "query-cpus" instead.
Signature · 1 line
Eduardo
PATCH v3 2/3 kvm: Add support to KVM_GET_MSR_FEATURE_INDEX_LIST and KVM_GET_MSRS system ioctl
In reply to Robert HooAdd kvm_get_supported_feature_msrs() to get supported MSR feature index list. Add kvm_arch_get_supported_msr_feature() to get each MSR features value.
kvm_get_supported_feature_msrs() is called in kvm_arch_init(). kvm_arch_get_supported_msr_feature() is called by x86_cpu_get_supported_feature_word().
--- include/sysemu/kvm.h | 2 ++ target/i386/kvm.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+)
include/sysemu/kvm.h +2 -0
@@ -463,6 +463,8 @@ int kvm_vm_check_extension(KVMState *s, unsigned int extension);uint32_t kvm_arch_get_supported_cpuid (KVMState *env,uint32_t function,uint32_t index,int reg); +uint32_t kvm_arch_get_supported_msr_feature (KVMState *s,uint32_t index); +void kvm_set_sigmask_len (KVMState *s,unsigned int sigmask_len);
target/i386/kvm.c +79 -0
104 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 2/3] kvm: Add support to KVM_GET_MSR_FEATURE_INDEX_LIST and KVM_GET_MSRS system ioctl
Thanks for the patch, comments below:
Quoted 31 lines · Robert Hoo
Add
kvm_get_supported_feature_msrs()to get supported MSR feature index list. Addkvm_arch_get_supported_msr_feature()to get each MSR features value.
kvm_get_supported_feature_msrs()is called inkvm_arch_init().kvm_arch_get_supported_msr_feature()is called byx86_cpu_get_supported_feature_word().Signed-off-by Robert Hoo <[email protected]>--- include/sysemu/kvm.h | 2 ++ target/i386/kvm.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+)include/sysemu/kvm.h +2
-0@@ -463,6 +463,8 @@ int kvm_vm_check_extension(KVMState *s, unsigned int extension);uint32_t kvm_arch_get_supported_cpuid (KVMState *env,uint32_t function,uint32_t index,int reg); +uint32_t kvm_arch_get_supported_msr_feature (KVMState *s,uint32_t index); +void kvm_set_sigmask_len (KVMState *s,unsigned int sigmask_len);target/i386/kvm.c +0
-0
target/i386/kvm.c static int has_pit_state2; · line 110
Quoted 4 lines
target/i386/kvm.c +1
-0@@ -107,6 +107,7 @@ static int has_pit_state2;static bool has_msr_mcg_ext_ctl;static struct kvm_cpuid2 *cpuid_cache; +static struct kvm_msr_list *kvm_feature_msrs;
I was going to suggest moving this to KVMState, but KVMState is a arch-independent struct. I guess we'll have to live with this by now.
Quoted 12 lines
target/i386/kvm.c +5
-0int kvm_has_pit_state2 (void ) {@@ -420,6 +421,41 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,return ret; } +uint32_t kvm_arch_get_supported_msr_feature (KVMState *s,uint32_t index) +{ +struct { +struct kvm_msrs info; +struct kvm_msr_entry entries[1 ];
target/i386/kvm.c uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, · line 438
Quoted 10 lines
target/i386/kvm.c +10
-0+ } msr_data; +uint32_t ret; + +/*Check if the requested feature MSR is supported*/ +int i; +for (i =0 ; i < kvm_feature_msrs->nmsrs; i++) { +if (index == kvm_feature_msrs->indices[i]) { +break ; + } + }
We are duplicating the logic that's already inside KVM (checking the list of supported MSRs and returning an error). Can't we make this simpler and just remove this check? If the MSR is not supported, KVM_GET_MSRS would just return 0.
target/i386/kvm.c uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, · line 440
Quoted 2 lines
target/i386/kvm.c +2
-0+if (i >= kvm_feature_msrs->nmsrs) { +fprintf (stderr,"Requested MSR (index= %d) is not supported.\n" , index);
This error message is meaningless for QEMU users. Do we really need to print it?
target/i386/kvm.c uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, · line 441
Quoted 1 line
target/i386/kvm.c +1
-0+return 0 ;
Returning 0 for MSRs that are not supported is probably OK, but we need to see this function being used, to be sure (I didn't look at all the patches in this series yet).
target/i386/kvm.c uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, · line 452
Quoted 11 lines
target/i386/kvm.c +11
-0+ } + + msr_data.info.nmsrs =1 ; + msr_data.entries[0 ].index = index; + + ret =kvm_ioctl (s,KVM_GET_MSRS , &msr_data); + +if (ret !=1 ) { +fprintf (stderr,"KVM get MSR (index=0x%x) feature failed, %s\n" , + index,strerror (-ret)); +exit (1 );
I'm not a fan of APIs that write to stdout/stderr or exit(), unless they are clearly just initialization functions that should never fail in normal circumstances.
But if you call KVM_GET_MSRS for all MSRs at kvm_get_supported_feature_msrs() below, this function would never need to report an error.
We are already going through the trouble of allocating kvm_feature_msrs in kvm_get_supported_feature_msrs() anyway.
target/i386/kvm.c void kvm_arch_do_init_vcpu(X86CPU *cpu) · line 1276
Quoted 13 lines
target/i386/kvm.c +6
-0+ } + +return msr_data.entries[0 ].data; +} + + typedef struct HWPoisonPage { ram_addr_t ram_addr; QLIST_ENTRY(HWPoisonPage) list;@@ -1238,7 +1274,45 @@ void kvm_arch_do_init_vcpu(X86CPU *cpu) env->mp_state =KVM_MP_STATE_INIT_RECEIVED ; } }
Nit: please add an extra newline between functions.
target/i386/kvm.c void kvm_arch_do_init_vcpu(X86CPU *cpu) · line 1282
Quoted 6 lines
target/i386/kvm.c +6
-0+static int kvm_get_supported_feature_msrs (KVMState *s) +{ +static int kvm_supported_feature_msrs; +int ret =0 ; + +if (kvm_supported_feature_msrs ==0 ) {
Do you really need the kvm_supported_feature_msrs variable? You could just check if kvm_feature_msrs is NULL.
I also suggest doing this:
if (already initialized) {
return 0;
}
/* regular initialization code here */to reduce one indentation level.
target/i386/kvm.c void kvm_arch_do_init_vcpu(X86CPU *cpu) · line 1290
Quoted 8 lines
target/i386/kvm.c +8
-0+struct kvm_msr_list msr_list; + + kvm_supported_feature_msrs++; + + msr_list.nmsrs =0 ; + ret =kvm_ioctl (s,KVM_GET_MSR_FEATURE_INDEX_LIST , &msr_list); +if (ret <0 && ret != -E2BIG ) { +return ret;
What if the host KVM version doesn't supportKVM_GET_MSR_FEATURE_INDEX_LIST?
target/i386/kvm.c void kvm_arch_do_init_vcpu(X86CPU *cpu) · line 1297
Quoted 7 lines
target/i386/kvm.c +7
-0+ } + +assert (msr_list.nmsrs >0 ); + kvm_feature_msrs = (struct kvm_msr_list *) \ +g_malloc0 (sizeof (msr_list) + + msr_list.nmsrs *sizeof (msr_list.indices[0 ])); +if (kvm_feature_msrs ==NULL ) {
g_malloc0() never returns NULL on failure. See
https://developer.gnome.org/glib/2.56/glib-Memory-Allocation.html#glib-Memory-Allocation.description
target/i386/kvm.c void kvm_arch_do_init_vcpu(X86CPU *cpu) · line 1306
Quoted 9 lines
target/i386/kvm.c +8
-0+fprintf (stderr,"Failed to allocate space for KVM Feature MSRs" +"which has %d MSRs\n" , msr_list.nmsrs); +return -1 ; + } + + kvm_feature_msrs->nmsrs = msr_list.nmsrs; + ret =kvm_ioctl (s,KVM_GET_MSR_FEATURE_INDEX_LIST , kvm_feature_msrs); +if (ret <0 ) {/*ioctl failure*/
Small nit: the "ioctl failure" comment seems unnecessary, I would just remove it.
target/i386/kvm.c void kvm_arch_do_init_vcpu(X86CPU *cpu) · line 1315
Quoted 9 lines
target/i386/kvm.c +9
-0+fprintf (stderr,"Fetch KVM feature MSRs failed: %s\n" , +strerror (-ret)); +g_free (kvm_feature_msrs); +return ret; + } + } + +return 0 ; +}
Same as above: please add an extra newline between functions.
Quoted 19 lines
target/i386/kvm.c +5
-0static int kvm_get_supported_msrs (KVMState *s) {static int kvm_supported_msrs;@@ -1400,6 +1474,11 @@ int kvm_arch_init(MachineState *ms, KVMState *s)return ret; } + ret =kvm_get_supported_feature_msrs (s); +if (ret <0 ) { +return ret; + } +uname (&utsname); lm_capable_kernel =strcmp (utsname.machine,"x86_64" ) ==0 ;Signature · 1 line
1.8.3.1
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v3 2/3] kvm: Add support to KVM_GET_MSR_FEATURE_INDEX_LIST and KVM_GET_MSRS system ioctl
Quoted 62 lines · Eduardo Habkost
Thanks for the patch, comments below:
Quoted 31 lines · Robert Hoo
Add
kvm_get_supported_feature_msrs()to get supported MSR feature index list. Addkvm_arch_get_supported_msr_feature()to get each MSR features value.
kvm_get_supported_feature_msrs()is called inkvm_arch_init().kvm_arch_get_supported_msr_feature()is called byx86_cpu_get_supported_feature_word().Signed-off-by Robert Hoo <[email protected]>--- include/sysemu/kvm.h | 2 ++ target/i386/kvm.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+)include/sysemu/kvm.h +2
-0@@ -463,6 +463,8 @@ int kvm_vm_check_extension(KVMState *s, unsigned int extension);uint32_t kvm_arch_get_supported_cpuid (KVMState *env,uint32_t function,uint32_t index,int reg); +uint32_t kvm_arch_get_supported_msr_feature (KVMState *s,uint32_t index); +void kvm_set_sigmask_len (KVMState *s,unsigned int sigmask_len);target/i386/kvm.c +0
-0target/i386/kvm.c static int has_pit_state2; · line 110
Quoted 4 lines
target/i386/kvm.c +1
-0@@ -107,6 +107,7 @@ static int has_pit_state2;static bool has_msr_mcg_ext_ctl;static struct kvm_cpuid2 *cpuid_cache; +static struct kvm_msr_list *kvm_feature_msrs;I was going to suggest moving this to KVMState, but KVMState is a arch-independent struct. I guess we'll have to live with this by now.
Quoted 19 lines
target/i386/kvm.c +12
-0int kvm_has_pit_state2 (void ) {@@ -420,6 +421,41 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,return ret; } +uint32_t kvm_arch_get_supported_msr_feature (KVMState *s,uint32_t index) +{ +struct { +struct kvm_msrs info; +struct kvm_msr_entry entries[1 ]; + } msr_data; +uint32_t ret; + +/*Check if the requested feature MSR is supported*/ +int i; +for (i =0 ; i < kvm_feature_msrs->nmsrs; i++) { +if (index == kvm_feature_msrs->indices[i]) {
Quoted 8 lines
target/i386/kvm.c uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, · line 438
Quoted 3 lines
target/i386/kvm.c +3
-0+break ; + } + }We are duplicating the logic that's already inside KVM (checking the list of supported MSRs and returning an error). Can't we make this simpler and just remove this check? If the MSR is not supported,
KVM_GET_MSRSwould just return 0.
Yes, seems dup. but if we remove this hunk, the kvm_get_supported_feature_msrs() is unnecessary at all.
Quoted 29 lines
target/i386/kvm.c uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, · line 440
Quoted 3 lines
target/i386/kvm.c +2
-0+if (i >= kvm_feature_msrs->nmsrs) { +fprintf (stderr,"Requested MSR (index= %d) is not supported.\n" , index);This error message is meaningless for QEMU users. Do we really need to print it?
target/i386/kvm.c uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, · line 441
Quoted 1 line
target/i386/kvm.c +1
-0+return 0 ;Returning 0 for MSRs that are not supported is probably OK, but we need to see this function being used, to be sure (I didn't look at all the patches in this series yet).
target/i386/kvm.c uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, · line 452
Quoted 11 lines
target/i386/kvm.c +11
-0+ } + + msr_data.info.nmsrs =1 ; + msr_data.entries[0 ].index = index; + + ret =kvm_ioctl (s,KVM_GET_MSRS , &msr_data); + +if (ret !=1 ) { +fprintf (stderr,"KVM get MSR (index=0x%x) feature failed, %s\n" , + index,strerror (-ret)); +exit (1 );I'm not a fan of APIs that write to stdout/stderr or
exit(), unless they are clearly just initialization functions that should never fail in normal circumstances.
Quoted 6 lines
But if you call
KVM_GET_MSRSfor all MSRs atkvm_get_supported_feature_msrs()below, this function would never need to report an error.We are already going through the trouble of allocating
kvm_feature_msrsinkvm_get_supported_feature_msrs()anyway.
I had looked into KVM KVM_GET_MSRS handling, though less likely, still have changes copy_from/to_user() fail. Therefore I added the check and warning here, in that seldom case happens.
exit() or not, I'm also not sure. Seems not necessary, while my usual programming philosophy is never let wrong goes further. For in the case of ioctl(KVM_GET_MSRS) returns failure, something goes wrong underlying, I would prefer to let user know this, rather than let it pass and goes further.
Quoted 29 lines
Quoted 11 lines
target/i386/kvm.c +6
-0+ } + +return msr_data.entries[0 ].data; +} + + typedef struct HWPoisonPage { ram_addr_t ram_addr; QLIST_ENTRY(HWPoisonPage) list;target/i386/kvm.c void kvm_arch_do_init_vcpu(X86CPU *cpu) · line 1276
Quoted 3 lines
target/i386/kvm.c +0
-0@@ -1238,7 +1274,45 @@ void kvm_arch_do_init_vcpu(X86CPU *cpu) env->mp_state =KVM_MP_STATE_INIT_RECEIVED ; } }Nit: please add an extra newline between functions.
target/i386/kvm.c void kvm_arch_do_init_vcpu(X86CPU *cpu) · line 1282
Quoted 6 lines
target/i386/kvm.c +6
-0+static int kvm_get_supported_feature_msrs (KVMState *s) +{ +static int kvm_supported_feature_msrs; +int ret =0 ; + +if (kvm_supported_feature_msrs ==0 ) {Do you really need the
kvm_supported_feature_msrsvariable? You could just check ifkvm_feature_msrsis NULL.I also suggest doing this:
Quoted 8 lines
if (already initialized) { return 0; } /* regular initialization code here */to reduce one indentation level.
Right.
Quoted 12 lines
target/i386/kvm.c void kvm_arch_do_init_vcpu(X86CPU *cpu) · line 1290
Quoted 9 lines
target/i386/kvm.c +8
-0+struct kvm_msr_list msr_list; + + kvm_supported_feature_msrs++; + + msr_list.nmsrs =0 ; + ret =kvm_ioctl (s,KVM_GET_MSR_FEATURE_INDEX_LIST , &msr_list); +if (ret <0 && ret != -E2BIG ) { +return ret;What if the host KVM version doesn't support
KVM_GET_MSR_FEATURE_INDEX_LIST?
Going to add kvm_check_extension(s, KVM_CAP_GET_MSR_FEATURES) before this ioctl. if not support, return -1. (Then the kvm_init will fail and exit.)
Quoted 9 lines
target/i386/kvm.c void kvm_arch_do_init_vcpu(X86CPU *cpu) · line 1297
Quoted 8 lines
target/i386/kvm.c +7
-0+ } + +assert (msr_list.nmsrs >0 ); + kvm_feature_msrs = (struct kvm_msr_list *) \ +g_malloc0 (sizeof (msr_list) + + msr_list.nmsrs *sizeof (msr_list.indices[0 ])); +if (kvm_feature_msrs ==NULL ) {
Quoted 3 lines
g_malloc0()never returns NULL on failure. See
https://developer.gnome.org/glib/2.56/glib-Memory-Allocation.html#glib-Memory-Allocation.description
Thanks!
Quoted 45 lines
target/i386/kvm.c void kvm_arch_do_init_vcpu(X86CPU *cpu) · line 1306
Quoted 9 lines
target/i386/kvm.c +8
-0+fprintf (stderr,"Failed to allocate space for KVM Feature MSRs" +"which has %d MSRs\n" , msr_list.nmsrs); +return -1 ; + } + + kvm_feature_msrs->nmsrs = msr_list.nmsrs; + ret =kvm_ioctl (s,KVM_GET_MSR_FEATURE_INDEX_LIST , kvm_feature_msrs); +if (ret <0 ) {/*ioctl failure*/ Small nit: the "ioctl failure" comment seems unnecessary, I would just remove it.
target/i386/kvm.c void kvm_arch_do_init_vcpu(X86CPU *cpu) · line 1315
Quoted 9 lines
target/i386/kvm.c +9
-0+fprintf (stderr,"Fetch KVM feature MSRs failed: %s\n" , +strerror (-ret)); +g_free (kvm_feature_msrs); +return ret; + } + } + +return 0 ; +}Same as above: please add an extra newline between functions.
Quoted 19 lines
target/i386/kvm.c +5
-0static int kvm_get_supported_msrs (KVMState *s) {static int kvm_supported_msrs;@@ -1400,6 +1474,11 @@ int kvm_arch_init(MachineState *ms, KVMState *s)return ret; } + ret =kvm_get_supported_feature_msrs (s); +if (ret <0 ) { +return ret; + } +uname (&utsname); lm_capable_kernel =strcmp (utsname.machine,"x86_64" ) ==0 ;Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 2/3] kvm: Add support to KVM_GET_MSR_FEATURE_INDEX_LIST and KVM_GET_MSRS system ioctl
Quoted 72 lines · Robert Hoo
Quoted 62 lines · Eduardo Habkost
Thanks for the patch, comments below:
Quoted 31 lines · Robert Hoo
Add
kvm_get_supported_feature_msrs()to get supported MSR feature index list. Addkvm_arch_get_supported_msr_feature()to get each MSR features value.
kvm_get_supported_feature_msrs()is called inkvm_arch_init().kvm_arch_get_supported_msr_feature()is called byx86_cpu_get_supported_feature_word().Signed-off-by Robert Hoo <[email protected]>--- include/sysemu/kvm.h | 2 ++ target/i386/kvm.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+)include/sysemu/kvm.h +2
-0@@ -463,6 +463,8 @@ int kvm_vm_check_extension(KVMState *s, unsigned int extension);uint32_t kvm_arch_get_supported_cpuid (KVMState *env,uint32_t function,uint32_t index,int reg); +uint32_t kvm_arch_get_supported_msr_feature (KVMState *s,uint32_t index); +void kvm_set_sigmask_len (KVMState *s,unsigned int sigmask_len);target/i386/kvm.c +0
-0target/i386/kvm.c static int has_pit_state2; · line 110
Quoted 4 lines
target/i386/kvm.c +1
-0@@ -107,6 +107,7 @@ static int has_pit_state2;static bool has_msr_mcg_ext_ctl;static struct kvm_cpuid2 *cpuid_cache; +static struct kvm_msr_list *kvm_feature_msrs;I was going to suggest moving this to KVMState, but KVMState is a arch-independent struct. I guess we'll have to live with this by now.
Quoted 19 lines
target/i386/kvm.c +12
-0int kvm_has_pit_state2 (void ) {@@ -420,6 +421,41 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,return ret; } +uint32_t kvm_arch_get_supported_msr_feature (KVMState *s,uint32_t index) +{ +struct { +struct kvm_msrs info; +struct kvm_msr_entry entries[1 ]; + } msr_data; +uint32_t ret; + +/*Check if the requested feature MSR is supported*/ +int i; +for (i =0 ; i < kvm_feature_msrs->nmsrs; i++) { +if (index == kvm_feature_msrs->indices[i]) {Quoted 8 lines
target/i386/kvm.c uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, · line 438
Quoted 3 lines
target/i386/kvm.c +3
-0+break ; + } + }We are duplicating the logic that's already inside KVM (checking the list of supported MSRs and returning an error). Can't we make this simpler and just remove this check? If the MSR is not supported,
KVM_GET_MSRSwould just return 0.
Quoted 2 lines
Yes, seems dup. but if we remove this hunk, the
kvm_get_supported_feature_msrs()is unnecessary at all.
So maybe kvm_get_supported_feature_msrs() really is unnecessary?
We seem to have two alternatives:
* calling KVM_GET_MSRS for all MSRs only once, at kvm_get_supported_feature_msrs() (as I had suggested previously);
* calling KVM_GET_MSRS for one MSR unconditionally here, but _not_ treating 0 as a fatal error.
I prefer the former, but I would be OK with both alternatives. Note that we need to check for KVM capabilities in both cases.
Quoted 40 lines
Quoted 29 lines
target/i386/kvm.c uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, · line 440
Quoted 3 lines
target/i386/kvm.c +2
-0+if (i >= kvm_feature_msrs->nmsrs) { +fprintf (stderr,"Requested MSR (index= %d) is not supported.\n" , index);This error message is meaningless for QEMU users. Do we really need to print it?
target/i386/kvm.c uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, · line 441
Quoted 1 line
target/i386/kvm.c +1
-0+return 0 ;Returning 0 for MSRs that are not supported is probably OK, but we need to see this function being used, to be sure (I didn't look at all the patches in this series yet).
target/i386/kvm.c uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, · line 452
Quoted 11 lines
target/i386/kvm.c +11
-0+ } + + msr_data.info.nmsrs =1 ; + msr_data.entries[0 ].index = index; + + ret =kvm_ioctl (s,KVM_GET_MSRS , &msr_data); + +if (ret !=1 ) { +fprintf (stderr,"KVM get MSR (index=0x%x) feature failed, %s\n" , + index,strerror (-ret)); +exit (1 );I'm not a fan of APIs that write to stdout/stderr or
exit(), unless they are clearly just initialization functions that should never fail in normal circumstances.Quoted 6 lines
But if you call
KVM_GET_MSRSfor all MSRs atkvm_get_supported_feature_msrs()below, this function would never need to report an error.We are already going through the trouble of allocating
kvm_feature_msrsinkvm_get_supported_feature_msrs()anyway.I had looked into KVM
KVM_GET_MSRShandling, though less likely, still have changes copy_from/to_user() fail. Therefore I added the check and warning here, in that seldom case happens.
Quoted 5 lines
exit()or not, I'm also not sure. Seems not necessary, while my usual programming philosophy is never let wrong goes further. For in the case ofioctl(KVM_GET_MSRS)returns failure, something goes wrong underlying, I would prefer to let user know this, rather than let it pass and goes further.
We probably have no option other than exiting if KVM_GET_MSRS returns an unexpected error. It's just that I find the code harder to review, because we need to be sure this won't terminate QEMU under normal circumstances.
But if you demonstrate that all errors here are truly fatal and unexpected, calling exit() may be OK. (See the KVM_CAP_GET_MSR_FEATURES comment below for one example where exiting is not going to be OK.)
Proper error reporting using Error** would be even better than exiting, but considering that none of the functions at i386/cpu.c return errors using Error**, I won't force you to do that.
Quoted 1 line
Quoted 1 line
[...]
Quoted 12 lines
Quoted 11 lines
target/i386/kvm.c void kvm_arch_do_init_vcpu(X86CPU *cpu) · line 1290
Quoted 8 lines
target/i386/kvm.c +8
-0+struct kvm_msr_list msr_list; + + kvm_supported_feature_msrs++; + + msr_list.nmsrs =0 ; + ret =kvm_ioctl (s,KVM_GET_MSR_FEATURE_INDEX_LIST , &msr_list); +if (ret <0 && ret != -E2BIG ) { +return ret;What if the host KVM version doesn't support
KVM_GET_MSR_FEATURE_INDEX_LIST?
Quoted 3 lines
Going to add
kvm_check_extension(s, KVM_CAP_GET_MSR_FEATURES)before this ioctl. if not support, return -1. (Then thekvm_initwill fail and exit.)
We don't want QEMU to refuse to run if the kernel doesn't have KVM_CAP_GET_MSR_FEATURES. We can treat missing capability as equivalent to returning an empty list of MSRs.
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v3 2/3] kvm: Add support to KVM_GET_MSR_FEATURE_INDEX_LIST and KVM_GET_MSRS system ioctl
Quoted 28 lines · Eduardo Habkost
Quoted 28 lines
Quoted 27 lines
Quoted 12 lines
int
kvm_has_pit_state2(void)
{target/i386/kvm.c +5
-0@@ -420,6 +421,41 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,return ret; } +uint32_t kvm_arch_get_supported_msr_feature (KVMState *s,uint32_t index) +{ +struct { +struct kvm_msrs info; +struct kvm_msr_entry entries[1 ];target/i386/kvm.c uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, · line 438
Quoted 10 lines
target/i386/kvm.c +10
-0+ } msr_data; +uint32_t ret; + +/*Check if the requested feature MSR is supported*/ +int i; +for (i =0 ; i < kvm_feature_msrs->nmsrs; i++) { +if (index == kvm_feature_msrs->indices[i]) { +break ; + } + }We are duplicating the logic that's already inside KVM (checking the list of supported MSRs and returning an error). Can't we make this simpler and just remove this check? If the MSR is not supported,
KVM_GET_MSRSwould just return 0.
Quoted 4 lines
Quoted 2 lines
Yes, seems dup. but if we remove this hunk, the
kvm_get_supported_feature_msrs()is unnecessary at all.So maybe
kvm_get_supported_feature_msrs()really is unnecessary?
I'll keep it, for 1) check KVM_CAP_GET_MSR_FEATURES capabilities; 2) get kvm_feature_msrs, so later kvm_arch_get_supported_msr_feature() use it to check if MSR features are supported.
Quoted 8 lines
We seem to have two alternatives:
* callingKVM_GET_MSRSfor all MSRs only once, atkvm_get_supported_feature_msrs()(as I had suggested previously);
* callingKVM_GET_MSRSfor one MSR unconditionally here, but _not_ treating 0 as a fatal error.
Quoted 4 lines
I prefer the former, but I would be OK with both alternatives. Note that we need to check for KVM capabilities in both cases.
I'll choose the latter :).
Quoted 51 lines
Quoted 40 lines
Quoted 29 lines
target/i386/kvm.c uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, · line 440
Quoted 3 lines
target/i386/kvm.c +2
-0+if (i >= kvm_feature_msrs->nmsrs) { +fprintf (stderr,"Requested MSR (index= %d) is not supported.\n" , index);This error message is meaningless for QEMU users. Do we really need to print it?
Review uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, · line 441
Quoted 1 line
(quoted diff) +1
-0+ return 0;Returning 0 for MSRs that are not supported is probably OK, but we need to see this function being used, to be sure (I didn't look at all the patches in this series yet).
target/i386/kvm.c uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, · line 452
Quoted 11 lines
target/i386/kvm.c +11
-0+ } + + msr_data.info.nmsrs =1 ; + msr_data.entries[0 ].index = index; + + ret =kvm_ioctl (s,KVM_GET_MSRS , &msr_data); + +if (ret !=1 ) { +fprintf (stderr,"KVM get MSR (index=0x%x) feature failed, %s\n" , + index,strerror (-ret)); +exit (1 );I'm not a fan of APIs that write to stdout/stderr or
exit(), unless they are clearly just initialization functions that should never fail in normal circumstances.Quoted 6 lines
But if you call
KVM_GET_MSRSfor all MSRs atkvm_get_supported_feature_msrs()below, this function would never need to report an error.We are already going through the trouble of allocating
kvm_feature_msrsinkvm_get_supported_feature_msrs()anyway.I had looked into KVM
KVM_GET_MSRShandling, though less likely, still have changes copy_from/to_user() fail. Therefore I added the check and warning here, in that seldom case happens.Quoted 5 lines
exit()or not, I'm also not sure. Seems not necessary, while my usual programming philosophy is never let wrong goes further. For in the case ofioctl(KVM_GET_MSRS)returns failure, something goes wrong underlying, I would prefer to let user know this, rather than let it pass and goes further.We probably have no option other than exiting if
KVM_GET_MSRSreturns an unexpected error. It's just that I find the code harder to review, because we need to be sure this won't terminate QEMU under normal circumstances.
Quoted 9 lines
But if you demonstrate that all errors here are truly fatal and unexpected, calling
exit()may be OK. (See theKVM_CAP_GET_MSR_FEATUREScomment below for one example where exiting is not going to be OK.)Proper error reporting using Error** would be even better than exiting, but considering that none of the functions at
i386/cpu.creturn errors using Error**, I won't force you to do that.
Thanks.
Quoted 15 lines
Quoted 2 lines
Quoted 2 lines
[...]
Quoted 12 lines
Quoted 11 lines
target/i386/kvm.c void kvm_arch_do_init_vcpu(X86CPU *cpu) · line 1290
Quoted 8 lines
target/i386/kvm.c +8
-0+struct kvm_msr_list msr_list; + + kvm_supported_feature_msrs++; + + msr_list.nmsrs =0 ; + ret =kvm_ioctl (s,KVM_GET_MSR_FEATURE_INDEX_LIST , &msr_list); +if (ret <0 && ret != -E2BIG ) { +return ret;What if the host KVM version doesn't support
KVM_GET_MSR_FEATURE_INDEX_LIST?
Quoted 7 lines
Quoted 3 lines
Going to add
kvm_check_extension(s, KVM_CAP_GET_MSR_FEATURES)before this ioctl. if not support, return -1. (Then thekvm_initwill fail and exit.)We don't want QEMU to refuse to run if the kernel doesn't have
KVM_CAP_GET_MSR_FEATURES. We can treat missing capability as equivalent to returning an empty list of MSRs.
Yes. I'll let caller (kvm_arch_init) ignore the return value but a simple warning.
Quoted 1 line
Re: [Qemu-devel] [PATCH v3 2/3] kvm: Add support to KVM_GET_MSR_FEATURE_INDEX_LIST and KVM_GET_MSRS system ioctl
Quoted 1 line · Robert Hoo
On Sat, 2018-08-18 at 12:05 -0300, Eduardo Habkost wrote:
[...]
Quoted 5 lines
Quoted 3 lines
We don't want QEMU to refuse to run if the kernel doesn't have
KVM_CAP_GET_MSR_FEATURES. We can treat missing capability as equivalent to returning an empty list of MSRs.Yes. I'll let caller (
kvm_arch_init) ignore the return value but a simple warning.
Warnings tend to be ignored and are generally a sign that QEMU isn't doing the right thing. Sometimes we have no choice, but I don't think that's the case here.
As far as I can see, we have only two possibilities here:
1) The host can run a VM that behaves exactly as requested on the command-line (no warning required).
2) The host can't run the requested configuration (fatal error, not a warning).
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v3 2/3] kvm: Add support to KVM_GET_MSR_FEATURE_INDEX_LIST and KVM_GET_MSRS system ioctl
Quoted 9 lines · Eduardo Habkost
Quoted 5 lines
Quoted 3 lines
We don't want QEMU to refuse to run if the kernel doesn't have
KVM_CAP_GET_MSR_FEATURES. We can treat missing capability as equivalent to returning an empty list of MSRs.Yes. I'll let caller (
kvm_arch_init) ignore the return value but a simple warning.Warnings tend to be ignored and are generally a sign that QEMU isn't doing the right thing. Sometimes we have no choice, but I don't think that's the case here.
Quoted 5 lines
As far as I can see, we have only two possibilities here:
1) The host can run a VM that behaves exactly as requested on the command-line (no warning required).
2) The host can't run the requested configuration (fatal error, not a warning).
Right, but if KVM_CAP_GET_MSR_FEATURES is not available I guess you can assume the MSRs to be zero for everything except "-cpu host".
Paolo
Re: [Qemu-devel] [PATCH v3 2/3] kvm: Add support to KVM_GET_MSR_FEATURE_INDEX_LIST and KVM_GET_MSRS system ioctl
Quoted 10 lines · Paolo Bonzini
Quoted 9 lines · Eduardo Habkost
Quoted 5 lines
Quoted 3 lines
We don't want QEMU to refuse to run if the kernel doesn't have
KVM_CAP_GET_MSR_FEATURES. We can treat missing capability as equivalent to returning an empty list of MSRs.Yes. I'll let caller (
kvm_arch_init) ignore the return value but a simple warning.Warnings tend to be ignored and are generally a sign that QEMU isn't doing the right thing. Sometimes we have no choice, but I don't think that's the case here.
Quoted 8 lines
Quoted 5 lines
As far as I can see, we have only two possibilities here:
1) The host can run a VM that behaves exactly as requested on the command-line (no warning required).
2) The host can't run the requested configuration (fatal error, not a warning).Right, but if
KVM_CAP_GET_MSR_FEATURESis not available I guess you can assume the MSRs to be zero for everything except "-cpu host".
Yes, that would be simplest way to implement the above. Then QEMU would refuse to run if the feature was part of the requested configuration (2), or not care at all because the feature was not set in the configuration (1).
But I'm not sure I follow the suggestion to not consider the MSR to be zero on "-cpu host". If we don't need and KVM-side code to support a given MSR feature, we can enable it on all models. IF we need KVM-side code, we can't enable it even on "-cpu host". This is not different from CPUID-based features.
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v3 2/3] kvm: Add support to KVM_GET_MSR_FEATURE_INDEX_LIST and KVM_GET_MSRS system ioctl
Quoted 10 lines · Eduardo Habkost
Quoted 2 lines
Right, but if
KVM_CAP_GET_MSR_FEATURESis not available I guess you can assume the MSRs to be zero for everything except "-cpu host".Yes, that would be simplest way to implement the above. Then QEMU would refuse to run if the feature was part of the requested configuration (2), or not care at all because the feature was not set in the configuration (1).
But I'm not sure I follow the suggestion to not consider the MSR to be zero on "-cpu host". If we don't need and KVM-side code to support a given MSR feature, we can enable it on all models.
The case I was thinking about, is where there is no KVM-side code to support the MSR feature, but you still need the host CPU to have it. Without KVM's feature MSR support, you cannot read the host value of the MSR.
My idea was that feature MSRs will default to the host value returned by KVM_GET_MSR on the /dev/kvm file descriptor, so "-cpu host" could just ignore KVM_CAP_GET_MSR_FEATURES and use KVM's default value of the MSRs.
However, I guess we can just use the default value for _all_ CPU models, because in practice the only effect would be on nested VMX MSRs, and nested VMX can only be migrated on kernels that have KVM_CAP_GET_MSR_FEATURES. So in practice people using nested VMX are using "-cpu host" anyway, not "-cpu SandyBridge,+vmx".
My proposalis: basically, if KVM_CAP_GET_MSR_FEATURES is unavailable:
- MSR-based features would cause an error if specified on the command line;
- kvm_arch_init_vcpu would skip the KVM_SET_MSR for feature MSRs completely.
What do you think?
Paolo
Re: [Qemu-devel] [PATCH v3 2/3] kvm: Add support to KVM_GET_MSR_FEATURE_INDEX_LIST and KVM_GET_MSRS system ioctl
Quoted 8 lines · Paolo Bonzini
Quoted 7 lines · Eduardo Habkost
Quoted 2 lines
Right, but if
KVM_CAP_GET_MSR_FEATURESis not available I guess you can assume the MSRs to be zero for everything except "-cpu host".Yes, that would be simplest way to implement the above. Then QEMU would refuse to run if the feature was part of the requested configuration (2), or not care at all because the feature was not set in the configuration (1).
Quoted 8 lines
Quoted 3 lines
But I'm not sure I follow the suggestion to not consider the MSR to be zero on "-cpu host". If we don't need and KVM-side code to support a given MSR feature, we can enable it on all models.
The case I was thinking about, is where there is no KVM-side code to support the MSR feature, but you still need the host CPU to have it. Without KVM's feature MSR support, you cannot read the host value of the MSR.
Don't we always need some KVM code to support the feature, even if it's just to make KVM enable the feature by default?
Quoted 10 lines
My idea was that feature MSRs will default to the host value returned by
KVM_GET_MSRon the/dev/kvmfile descriptor, so "-cpu host" could just ignoreKVM_CAP_GET_MSR_FEATURESand use KVM's default value of the MSRs.However, I guess we can just use the default value for _all_ CPU models, because in practice the only effect would be on nested VMX MSRs, and nested VMX can only be migrated on kernels that have
KVM_CAP_GET_MSR_FEATURES. So in practice people using nested VMX are using "-cpu host" anyway, not "-cpu SandyBridge,+vmx".
If the default is to use the host value, I see two problems:
1) we can't use the default on any migration-safe CPU model (i.e. all except "host"); 2) it will be unsafe for older QEMU versions (that don't know yet how to call KVM_SET_MSR for that MSR).
If this is just about VMX caps, this shouldn't be a problem because we already treat VMX as not migration-safe. We will need to keep that in mind if we want to make VMX migration-safe in the future, though.
Quoted 6 lines
My proposalis: basically, if
KVM_CAP_GET_MSR_FEATURESis unavailable:- MSR-based features would cause an error if specified on the command line;
-
kvm_arch_init_vcpuwould skip theKVM_SET_MSRfor feature MSRs completely.
If we already had some MSR features being enabled by default before KVM_CAP_GET_MSR_FEATURES was introduced (I didn't know we had such cases), this sense. But I don't think we should do it for new MSRs.
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v3 2/3] kvm: Add support to KVM_GET_MSR_FEATURE_INDEX_LIST and KVM_GET_MSRS system ioctl
In reply to Eduardo HabkostQuoted 13 lines · Eduardo Habkost
Quoted 1 line · Robert Hoo
On Sat, 2018-08-18 at 12:05 -0300, Eduardo Habkost wrote:
[...]
Quoted 5 lines
Quoted 3 lines
We don't want QEMU to refuse to run if the kernel doesn't have
KVM_CAP_GET_MSR_FEATURES. We can treat missing capability as equivalent to returning an empty list of MSRs.Yes. I'll let caller (
kvm_arch_init) ignore the return value but a simple warning.Warnings tend to be ignored and are generally a sign that QEMU isn't doing the right thing. Sometimes we have no choice, but I don't think that's the case here.
Quoted 6 lines
As far as I can see, we have only two possibilities here:
1) The host can run a VM that behaves exactly as requested on the command-line (no warning required).
2) The host can't run the requested configuration (fatal error, not a warning).
I mean the kvm_arch_init() --> kvm_get_supported_feature_msrs(), when kvm_get_supported_feature_msrs() returns error, can we ignore it? The cases of kvm_get_supported_feature_msrs() returning error:
1) underlying KVM doesn't support GET_MSR_FEATURES capability.
2) error in KVM_GET_MSR_FEATURE_INDEX_LIST.
given the principle you guided before, I think we can ignore above error cases, and later kvm_arch_get_supported_msr_feature() would always return 0 (of course, except those special cases like IA32_ARCH_CAPABILITIES.RSBA)
Re: [Qemu-devel] [PATCH v3 2/3] kvm: Add support to KVM_GET_MSR_FEATURE_INDEX_LIST and KVM_GET_MSRS system ioctl
Quoted 26 lines · Robert Hoo
Quoted 13 lines · Eduardo Habkost
Quoted 1 line · Robert Hoo
On Sat, 2018-08-18 at 12:05 -0300, Eduardo Habkost wrote:
[...]
Quoted 5 lines
Quoted 3 lines
We don't want QEMU to refuse to run if the kernel doesn't have
KVM_CAP_GET_MSR_FEATURES. We can treat missing capability as equivalent to returning an empty list of MSRs.Yes. I'll let caller (
kvm_arch_init) ignore the return value but a simple warning.Warnings tend to be ignored and are generally a sign that QEMU isn't doing the right thing. Sometimes we have no choice, but I don't think that's the case here.
Quoted 6 lines
As far as I can see, we have only two possibilities here:
1) The host can run a VM that behaves exactly as requested on the command-line (no warning required).
2) The host can't run the requested configuration (fatal error, not a warning).I mean the
kvm_arch_init()-->kvm_get_supported_feature_msrs(), whenkvm_get_supported_feature_msrs()returns error, can we ignore it? The cases ofkvm_get_supported_feature_msrs()returning error:
1) underlying KVM doesn't supportGET_MSR_FEATUREScapability.
2) error inKVM_GET_MSR_FEATURE_INDEX_LIST.
Quoted 4 lines
given the principle you guided before, I think we can ignore above error cases, and later
kvm_arch_get_supported_msr_feature()would always return 0 (of course, except those special cases like IA32_ARCH_CAPABILITIES.RSBA)
Making kvm_arch_get_supported_msr_feature() return 0 if the capability isn't available (except for RSBA) seems to be enough to ensure we do the right thing on both cases (1 and 2 above).
Now, if KVM_GET_MSR_FEATURE_INDEX_LIST returns an unexpected error, it sounds like an exceptional situation that can justify a fatal error (or at least a warning).
Signature · 1 line
Eduardo
PATCH v3 3/3 Change other funcitons referring to feature_word_info[]
In reply to Robert HooAdd an util function feature_word_description(), which help construct the string describing the feature word (both CPUID and MSR types).
report_unavailable_features(): add MSR_FEATURE_WORD type support. x86_cpu_get_feature_words(): limit to CPUID_FEATURE_WORD only. x86_cpu_get_supported_feature_word(): add MSR_FEATURE_WORD type support. x86_cpu_adjust_feat_level(): assert the requested feature must be CPUID_FEATURE_WORD type.
--- target/i386/cpu.c | 77 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 19 deletions(-)
target/i386/cpu.c +58 -19
@@ -3024,21 +3024,51 @@ static const TypeInfo host_x86_cpu_type_info = {#endif +/* +*caller should have input str no less than 64 byte length. +*/ +#define FEATURE_WORD_DESCPTION_LEN 64 +static int feature_word_description (char str[],FeatureWordInfo *f, +uint32_t bit) +{ +int ret; + +assert (f->type ==CPUID_FEATURE_WORD || + f->type ==MSR_FEATURE_WORD ); +switch (f->type) { +case CPUID_FEATURE_WORD : + { +const char *reg =get_register_name_32 (f->cpuid.reg); +assert (reg); + ret =snprintf (str,FEATURE_WORD_DESCPTION_LEN , +"CPUID.%02XH:%s%s%s [bit %d]" , + f->cpuid.eax, reg, + f->feat_names[bit] ?"." :"" , + f->feat_names[bit] ? f->feat_names[bit] :"" , bit); +break ; + } +case MSR_FEATURE_WORD : + ret =snprintf (str,FEATURE_WORD_DESCPTION_LEN , +"MSR(%xH).%s [bit %d]" , + f->msr.index, + f->feat_names[bit] ? f->feat_names[bit] :"" , bit); +break ; + } +return ret >0 ; +} +static void report_unavailable_features (FeatureWord w,uint32_t mask) {FeatureWordInfo *f = &feature_word_info[w];int i; +char feat_word_dscrp_str[FEATURE_WORD_DESCPTION_LEN ];for (i =0 ; i <32 ; ++i) {if ((1UL << i) & mask) { -const char *reg =get_register_name_32 (f->cpuid_reg); -assert (reg); -warn_report ("%s doesn't support requested feature: " -"CPUID.%02XH:%s%s%s [bit %d]" , +feature_word_description (feat_word_dscrp_str, f, i); +warn_report ("%s doesn't support requested feature: %s" ,accel_uses_host_cpuid () ?"host" :"TCG" , - f->cpuid_eax, reg, - f->feat_names[i] ?"." :"" , - f->feat_names[i] ? f->feat_names[i] :"" , i); + feat_word_dscrp_str); } } }
@@ -3276,17 +3306,17 @@ static void x86_cpu_get_feature_words(Object *obj, Visitor *v, {uint32_t *array = (uint32_t *)opaque;FeatureWord w; -X86CPUFeatureWordInfo word_infos[FEATURE_WORDS ] = { }; -X86CPUFeatureWordInfoList list_entries[FEATURE_WORDS ] = { }; +X86CPUFeatureWordInfo word_infos[FEATURE_WORDS_NUM_CPUID ] = { }; +X86CPUFeatureWordInfoList list_entries[FEATURE_WORDS_NUM_CPUID ] = { };X86CPUFeatureWordInfoList *list =NULL ; -for (w =0 ; w <FEATURE_WORDS ; w++) { +for (w =0 ; w <FEATURE_WORDS_NUM_CPUID ; w++) {FeatureWordInfo *wi = &feature_word_info[w];X86CPUFeatureWordInfo *qwi = &word_infos[w]; - qwi->cpuid_input_eax = wi->cpuid_eax; - qwi->has_cpuid_input_ecx = wi->cpuid_needs_ecx; - qwi->cpuid_input_ecx = wi->cpuid_ecx; - qwi->cpuid_register = x86_reg_info_32[wi->cpuid_reg].qapi_enum; + qwi->cpuid_input_eax = wi->cpuid.eax; + qwi->has_cpuid_input_ecx = wi->cpuid.needs_ecx; + qwi->cpuid_input_ecx = wi->cpuid.ecx; + qwi->cpuid_register = x86_reg_info_32[wi->cpuid.reg].qapi_enum; qwi->features = array[w];/* List will be in reverse order, but order shouldn't matter */
@@ -3659,12 +3689,20 @@ static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w, bool migratable_only) {FeatureWordInfo *wi = &feature_word_info[w]; -uint32_t r; +uint32_t r =0 ;if (kvm_enabled ()) { - r =kvm_arch_get_supported_cpuid (kvm_state, wi->cpuid_eax, - wi->cpuid_ecx, - wi->cpuid_reg); +switch (wi->type) { +case CPUID_FEATURE_WORD : + r =kvm_arch_get_supported_cpuid (kvm_state, wi->cpuid.eax, + wi->cpuid.ecx, + wi->cpuid.reg); +break ; +case MSR_FEATURE_WORD : + r =kvm_arch_get_supported_msr_feature (kvm_state, + wi->msr.index); +break ; + } }else if (hvf_enabled ()) { r = hvf_get_supported_cpuid(wi->cpuid_eax, wi->cpuid_ecx,
@@ -4732,9 +4770,10 @@ static void x86_cpu_adjust_feat_level(X86CPU *cpu, FeatureWord w) {CPUX86State *env = &cpu->env;FeatureWordInfo *fi = &feature_word_info[w]; -uint32_t eax = fi->cpuid_eax; +uint32_t eax = fi->cpuid.eax;uint32_t region = eax &0xF0000000 ; +assert (feature_word_info[w].type ==CPUID_FEATURE_WORD );if (!env->features[w]) {return ; }
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 3/3] Change other funcitons referring to feature_word_info[]
On 08/10/2018 09:06 AM, Robert Hoo wrote:
In the subject: s/funcitons/functions/
Also, it may be worth using a topic prefix (most of our commit messages resemble:
topic: Description of patch
to make it easier to spot patches by topic).
Quoted 1 line
Add an util function
feature_word_description(), which help construct the string
s/an util/a util/
s/help/helps/
Quoted 18 lines
describing the feature word (both CPUID and MSR types).
report_unavailable_features(): addMSR_FEATURE_WORDtype support.x86_cpu_get_feature_words(): limit toCPUID_FEATURE_WORDonly.x86_cpu_get_supported_feature_word(): addMSR_FEATURE_WORDtype support.x86_cpu_adjust_feat_level(): assert the requested feature must beCPUID_FEATURE_WORDtype.Signed-off-by Robert Hoo <[email protected]>--- target/i386/cpu.c | 77 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 19 deletions(-)target/i386/cpu.c +0
-0
target/i386/cpu.c static const TypeInfo host_x86_cpu_type_info = { · line 3030
Quoted 7 lines
target/i386/cpu.c +4
-0@@ -3024,21 +3024,51 @@ static const TypeInfo host_x86_cpu_type_info = {#endif +/* +*caller should have input str no less than 64 byte length. +*/ +#define FEATURE_WORD_DESCPTION_LEN 64
s/DESCPTION/DESCRIPTION/
target/i386/cpu.c static const TypeInfo host_x86_cpu_type_info = { · line 3033
Quoted 3 lines
target/i386/cpu.c +3
-0+static int feature_word_description (char str[],FeatureWordInfo *f, +uint32_t bit) +{
Prone to buffer overflow if the caller doesn't pass in the length. Would it be better to just g_strdup_printf() into a malloc'd result instead of trying to snprintf()'ing into a buffer that you hope the caller sized large enough?
Quoted 23 lines
target/i386/cpu.c +23
-0+int ret; + +assert (f->type ==CPUID_FEATURE_WORD || + f->type ==MSR_FEATURE_WORD ); +switch (f->type) { +case CPUID_FEATURE_WORD : + { +const char *reg =get_register_name_32 (f->cpuid.reg); +assert (reg); + ret =snprintf (str,FEATURE_WORD_DESCPTION_LEN , +"CPUID.%02XH:%s%s%s [bit %d]" , + f->cpuid.eax, reg, + f->feat_names[bit] ?"." :"" , + f->feat_names[bit] ? f->feat_names[bit] :"" , bit); +break ; + } +case MSR_FEATURE_WORD : + ret =snprintf (str,FEATURE_WORD_DESCPTION_LEN , +"MSR(%xH).%s [bit %d]" , + f->msr.index, + f->feat_names[bit] ? f->feat_names[bit] :"" , bit); +break ; + }
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v3 3/3] Change other funcitons referring to feature_word_info[]
Quoted 7 lines · Eric Blake
On 08/10/2018 09:06 AM, Robert Hoo wrote:
In the subject: s/funcitons/functions/
Also, it may be worth using a topic prefix (most of our commit messages resemble:
Quoted 9 lines
topic: Description of patch
to make it easier to spot patches by topic).
Quoted 1 line
Add an util function
feature_word_description(), which help construct the strings/an util/a util/
s/help/helps/
Thanks Eric, will fix these typos in v2.
Quoted 28 lines
Quoted 18 lines
describing the feature word (both CPUID and MSR types).
report_unavailable_features(): addMSR_FEATURE_WORDtype support.x86_cpu_get_feature_words(): limit toCPUID_FEATURE_WORDonly.x86_cpu_get_supported_feature_word(): addMSR_FEATURE_WORDtype support.x86_cpu_adjust_feat_level(): assert the requested feature must beCPUID_FEATURE_WORDtype.Signed-off-by Robert Hoo <[email protected]>--- target/i386/cpu.c | 77 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 19 deletions(-)target/i386/cpu.c +0
-0target/i386/cpu.c static const TypeInfo host_x86_cpu_type_info = { · line 3030
Quoted 7 lines
target/i386/cpu.c +4
-0@@ -3024,21 +3024,51 @@ static const TypeInfo host_x86_cpu_type_info = {#endif +/* +*caller should have input str no less than 64 byte length. +*/ +#define FEATURE_WORD_DESCPTION_LEN 64s/DESCPTION/DESCRIPTION/
Quoted 9 lines
target/i386/cpu.c static const TypeInfo host_x86_cpu_type_info = { · line 3033
Quoted 3 lines
target/i386/cpu.c +3
-0+static int feature_word_description (char str[],FeatureWordInfo *f, +uint32_t bit) +{Prone to buffer overflow if the caller doesn't pass in the length. Would it be better to just
g_strdup_printf()into a malloc'd result instead of trying to snprintf()'ing into a buffer that you hope the caller sized large enough?
Oh, wasn't aware of such good util functions. Sure I'd like to use them. Is there some web page introducing them?
Eduardo/Paolo, do you have more comments?
Quoted 24 lines
Quoted 23 lines
target/i386/cpu.c +23
-0+int ret; + +assert (f->type ==CPUID_FEATURE_WORD || + f->type ==MSR_FEATURE_WORD ); +switch (f->type) { +case CPUID_FEATURE_WORD : + { +const char *reg =get_register_name_32 (f->cpuid.reg); +assert (reg); + ret =snprintf (str,FEATURE_WORD_DESCPTION_LEN , +"CPUID.%02XH:%s%s%s [bit %d]" , + f->cpuid.eax, reg, + f->feat_names[bit] ?"." :"" , + f->feat_names[bit] ? f->feat_names[bit] :"" , bit); +break ; + } +case MSR_FEATURE_WORD : + ret =snprintf (str,FEATURE_WORD_DESCPTION_LEN , +"MSR(%xH).%s [bit %d]" , + f->msr.index, + f->feat_names[bit] ? f->feat_names[bit] :"" , bit); +break ; + }
Re: [Qemu-devel] [PATCH v3 3/3] Change other funcitons referring to feature_word_info[]
In reply to Robert HooQuoted 19 lines · Robert Hoo
Add an util function
feature_word_description(), which help construct the string describing the feature word (both CPUID and MSR types).
report_unavailable_features(): addMSR_FEATURE_WORDtype support.x86_cpu_get_feature_words(): limit toCPUID_FEATURE_WORDonly.x86_cpu_get_supported_feature_word(): addMSR_FEATURE_WORDtype support.x86_cpu_adjust_feat_level(): assert the requested feature must beCPUID_FEATURE_WORDtype.Signed-off-by Robert Hoo <[email protected]>--- target/i386/cpu.c | 77 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 19 deletions(-)target/i386/cpu.c +0
-0
target/i386/cpu.c static const TypeInfo host_x86_cpu_type_info = { · line 3032
Quoted 9 lines
target/i386/cpu.c +6
-0@@ -3024,21 +3024,51 @@ static const TypeInfo host_x86_cpu_type_info = {#endif +/* +*caller should have input str no less than 64 byte length. +*/ +#define FEATURE_WORD_DESCPTION_LEN 64 +static int feature_word_description (char str[],FeatureWordInfo *f, +uint32_t bit)
I agree with Eric: g_strup_printf() would be much simpler here.
Quoted 12 lines
target/i386/cpu.c +12
-0+{ +int ret; + +assert (f->type ==CPUID_FEATURE_WORD || + f->type ==MSR_FEATURE_WORD ); +switch (f->type) { +case CPUID_FEATURE_WORD : + { +const char *reg =get_register_name_32 (f->cpuid.reg); +assert (reg); + ret = snprintf(str, FEATURE_WORD_DESCPTION_LEN, + "CPUID.%02XH:%s%s%s [bit %d]",
target/i386/cpu.c static const TypeInfo host_x86_cpu_type_info = { · line 3054
Quoted 10 lines
target/i386/cpu.c +10
-0+ f->cpuid.eax, reg, + f->feat_names[bit] ?"." :"" , + f->feat_names[bit] ? f->feat_names[bit] : "", bit); +break ; + } +case MSR_FEATURE_WORD : + ret =snprintf (str,FEATURE_WORD_DESCPTION_LEN , +"MSR(%xH).%s [bit %d]" , + f->msr.index, + f->feat_names[bit] ? f->feat_names[bit] :"" , bit);
What about leaving the (f->feat_names[bit] ? ... : ...) part in report_unavailable_features() and just make this function return "CPUID[...]" or "MSR[...]"?
Quoted 39 lines
target/i386/cpu.c +12
-10+break ; + } +return ret >0 ; +} +static void report_unavailable_features (FeatureWord w,uint32_t mask) {FeatureWordInfo *f = &feature_word_info[w];int i; +char feat_word_dscrp_str[FEATURE_WORD_DESCPTION_LEN ];for (i =0 ; i <32 ; ++i) {if ((1UL << i) & mask) { -const char *reg =get_register_name_32 (f->cpuid_reg); -assert (reg); -warn_report ("%s doesn't support requested feature: " -"CPUID.%02XH:%s%s%s [bit %d]" , +feature_word_description (feat_word_dscrp_str, f, i); +warn_report ("%s doesn't support requested feature: %s" ,accel_uses_host_cpuid () ?"host" :"TCG" , - f->cpuid_eax, reg, - f->feat_names[i] ?"." :"" , - f->feat_names[i] ? f->feat_names[i] :"" , i); + feat_word_dscrp_str); } } }@@ -3276,17 +3306,17 @@ static void x86_cpu_get_feature_words(Object *obj, Visitor *v, {uint32_t *array = (uint32_t *)opaque;FeatureWord w; -X86CPUFeatureWordInfo word_infos[FEATURE_WORDS ] = { }; -X86CPUFeatureWordInfoList list_entries[FEATURE_WORDS ] = { }; +X86CPUFeatureWordInfo word_infos[FEATURE_WORDS_NUM_CPUID ] = { }; +X86CPUFeatureWordInfoList list_entries[FEATURE_WORDS_NUM_CPUID ] = { };X86CPUFeatureWordInfoList *list =NULL ; -for (w =0 ; w <FEATURE_WORDS ; w++) { +for (w =0 ; w <FEATURE_WORDS_NUM_CPUID ; w++) {
target/i386/cpu.c static void x86_cpu_get_feature_words(Object *obj, Visitor *v, · line 3319
Quoted 10 lines
target/i386/cpu.c +4
-4FeatureWordInfo *wi = &feature_word_info[w];X86CPUFeatureWordInfo *qwi = &word_infos[w]; - qwi->cpuid_input_eax = wi->cpuid_eax; - qwi->has_cpuid_input_ecx = wi->cpuid_needs_ecx; - qwi->cpuid_input_ecx = wi->cpuid_ecx; - qwi->cpuid_register = x86_reg_info_32[wi->cpuid_reg].qapi_enum; + qwi->cpuid_input_eax = wi->cpuid.eax; + qwi->has_cpuid_input_ecx = wi->cpuid.needs_ecx; + qwi->cpuid_input_ecx = wi->cpuid.ecx; + qwi->cpuid_register = x86_reg_info_32[wi->cpuid.reg].qapi_enum;
Looks OK, but I would add anassert(wi->type == CPUID_FEATURE_WORD) on every block of code that uses the wi->cpuid field.
I would also get rid of FEATURE_WORDS_NUM_CPUID and FEATURE_WORDS_FIRST_MSR to reduce the chance of future mistakes. We can use FEATURE_WORDS in this loop and just check wi->type on each iteration.
Quoted 14 lines
target/i386/cpu.c +1
-4qwi->features = array[w];/* List will be in reverse order, but order shouldn't matter */ @@ -3659,12 +3689,20 @@ static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w, bool migratable_only) {FeatureWordInfo *wi = &feature_word_info[w]; -uint32_t r; +uint32_t r =0 ;if (kvm_enabled ()) { - r =kvm_arch_get_supported_cpuid (kvm_state, wi->cpuid_eax, - wi->cpuid_ecx, - wi->cpuid_reg);
target/i386/cpu.c static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w, · line 3704
Quoted 10 lines
target/i386/cpu.c +10
-0+switch (wi->type) { +case CPUID_FEATURE_WORD : + r =kvm_arch_get_supported_cpuid (kvm_state, wi->cpuid.eax, + wi->cpuid.ecx, + wi->cpuid.reg); +break ; +case MSR_FEATURE_WORD : + r =kvm_arch_get_supported_msr_feature (kvm_state, + wi->msr.index); +break ;
I'm not sure this is correct in the case of IA32_ARCH_CAPABILITIES.RSBA: we do want to be able to set RSBA even if the host doesn't have it set.
Probably you need to handle IA32_ARCH_CAPABILITIES.RSBA as a special case inside kvm_arch_get_supported_msr_feature().
(And we do want to warn the user in some way if RSBA is set in the host but not in the guest. But that's a separate problem.)
Quoted 20 lines
target/i386/cpu.c +3
-1+ } }else if (hvf_enabled ()) { r = hvf_get_supported_cpuid(wi->cpuid_eax, wi->cpuid_ecx,@@ -4732,9 +4770,10 @@ static void x86_cpu_adjust_feat_level(X86CPU *cpu, FeatureWord w) {CPUX86State *env = &cpu->env;FeatureWordInfo *fi = &feature_word_info[w]; -uint32_t eax = fi->cpuid_eax; +uint32_t eax = fi->cpuid.eax;uint32_t region = eax &0xF0000000 ; +assert (feature_word_info[w].type ==CPUID_FEATURE_WORD );if (!env->features[w]) {return ; }Signature · 1 line
1.8.3.1
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v3 3/3] Change other funcitons referring to feature_word_info[]
Quoted 23 lines · Eduardo Habkost
Quoted 22 lines · Robert Hoo
Add an util function
feature_word_description(), which help construct the string describing the feature word (both CPUID and MSR types).
report_unavailable_features(): addMSR_FEATURE_WORDtype support.x86_cpu_get_feature_words(): limit toCPUID_FEATURE_WORDonly.x86_cpu_get_supported_feature_word(): addMSR_FEATURE_WORDtype support.x86_cpu_adjust_feat_level(): assert the requested feature must beCPUID_FEATURE_WORDtype.Signed-off-by Robert Hoo <[email protected]>--- target/i386/cpu.c | 77 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 19 deletions(-)target/i386/cpu.c +0
-0@@ -3024,21 +3024,51 @@ static const TypeInfo host_x86_cpu_type_info = {#endif
Quoted 9 lines
target/i386/cpu.c static const TypeInfo host_x86_cpu_type_info = { · line 3032
Quoted 6 lines
target/i386/cpu.c +6
-0+/* +*caller should have input str no less than 64 byte length. +*/ +#define FEATURE_WORD_DESCPTION_LEN 64 +static int feature_word_description (char str[],FeatureWordInfo *f, +uint32_t bit)I agree with Eric:
g_strup_printf()would be much simpler here.
1 question: I think caller should g_free() the returned str after it warn_report(), right?
Quoted 116 lines
Quoted 12 lines
target/i386/cpu.c +12
-0+{ +int ret; + +assert (f->type ==CPUID_FEATURE_WORD || + f->type ==MSR_FEATURE_WORD ); +switch (f->type) { +case CPUID_FEATURE_WORD : + { +const char *reg =get_register_name_32 (f->cpuid.reg); +assert (reg); + ret = snprintf(str, FEATURE_WORD_DESCPTION_LEN, + "CPUID.%02XH:%s%s%s [bit %d]",target/i386/cpu.c static const TypeInfo host_x86_cpu_type_info = { · line 3054
Quoted 10 lines
target/i386/cpu.c +10
-0+ f->cpuid.eax, reg, + f->feat_names[bit] ?"." :"" , + f->feat_names[bit] ? f->feat_names[bit] : "", bit); +break ; + } +case MSR_FEATURE_WORD : + ret =snprintf (str,FEATURE_WORD_DESCPTION_LEN , +"MSR(%xH).%s [bit %d]" , + f->msr.index, + f->feat_names[bit] ? f->feat_names[bit] :"" , bit);What about leaving the (f->feat_names[bit] ? ... : ...) part in
report_unavailable_features()and just make this function return "CPUID[...]" or "MSR[...]"?Quoted 39 lines
target/i386/cpu.c +12
-10+break ; + } +return ret >0 ; +} +static void report_unavailable_features (FeatureWord w,uint32_t mask) {FeatureWordInfo *f = &feature_word_info[w];int i; +char feat_word_dscrp_str[FEATURE_WORD_DESCPTION_LEN ];for (i =0 ; i <32 ; ++i) {if ((1UL << i) & mask) { -const char *reg =get_register_name_32 (f->cpuid_reg); -assert (reg); -warn_report ("%s doesn't support requested feature: " -"CPUID.%02XH:%s%s%s [bit %d]" , +feature_word_description (feat_word_dscrp_str, f, i); +warn_report ("%s doesn't support requested feature: %s" ,accel_uses_host_cpuid () ?"host" :"TCG" , - f->cpuid_eax, reg, - f->feat_names[i] ?"." :"" , - f->feat_names[i] ? f->feat_names[i] :"" , i); + feat_word_dscrp_str); } } }@@ -3276,17 +3306,17 @@ static void x86_cpu_get_feature_words(Object *obj, Visitor *v, {uint32_t *array = (uint32_t *)opaque;FeatureWord w; -X86CPUFeatureWordInfo word_infos[FEATURE_WORDS ] = { }; -X86CPUFeatureWordInfoList list_entries[FEATURE_WORDS ] = { }; +X86CPUFeatureWordInfo word_infos[FEATURE_WORDS_NUM_CPUID ] = { }; +X86CPUFeatureWordInfoList list_entries[FEATURE_WORDS_NUM_CPUID ] = { };X86CPUFeatureWordInfoList *list =NULL ; -for (w =0 ; w <FEATURE_WORDS ; w++) { +for (w =0 ; w <FEATURE_WORDS_NUM_CPUID ; w++) {target/i386/cpu.c static void x86_cpu_get_feature_words(Object *obj, Visitor *v, · line 3319
Quoted 10 lines
target/i386/cpu.c +4
-4FeatureWordInfo *wi = &feature_word_info[w];X86CPUFeatureWordInfo *qwi = &word_infos[w]; - qwi->cpuid_input_eax = wi->cpuid_eax; - qwi->has_cpuid_input_ecx = wi->cpuid_needs_ecx; - qwi->cpuid_input_ecx = wi->cpuid_ecx; - qwi->cpuid_register = x86_reg_info_32[wi->cpuid_reg].qapi_enum; + qwi->cpuid_input_eax = wi->cpuid.eax; + qwi->has_cpuid_input_ecx = wi->cpuid.needs_ecx; + qwi->cpuid_input_ecx = wi->cpuid.ecx; + qwi->cpuid_register = x86_reg_info_32[wi->cpuid.reg].qapi_enum;Looks OK, but I would add an
assert(wi->type == CPUID_FEATURE_WORD)on every block of code that uses thewi->cpuidfield.I would also get rid of
FEATURE_WORDS_NUM_CPUIDandFEATURE_WORDS_FIRST_MSRto reduce the chance of future mistakes. We can useFEATURE_WORDSin this loop and just checkwi->typeon each iteration.Quoted 14 lines
target/i386/cpu.c +1
-4qwi->features = array[w];/* List will be in reverse order, but order shouldn't matter */ @@ -3659,12 +3689,20 @@ static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w, bool migratable_only) {FeatureWordInfo *wi = &feature_word_info[w]; -uint32_t r; +uint32_t r =0 ;if (kvm_enabled ()) { - r =kvm_arch_get_supported_cpuid (kvm_state, wi->cpuid_eax, - wi->cpuid_ecx, - wi->cpuid_reg);target/i386/cpu.c static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w, · line 3704
Quoted 10 lines
target/i386/cpu.c +10
-0+switch (wi->type) { +case CPUID_FEATURE_WORD : + r =kvm_arch_get_supported_cpuid (kvm_state, wi->cpuid.eax, + wi->cpuid.ecx, + wi->cpuid.reg); +break ; +case MSR_FEATURE_WORD : + r =kvm_arch_get_supported_msr_feature (kvm_state, + wi->msr.index); +break ;I'm not sure this is correct in the case of IA32_ARCH_CAPABILITIES.RSBA: we do want to be able to set RSBA even if the host doesn't have it set.
Quoted 5 lines
Probably you need to handle IA32_ARCH_CAPABILITIES.RSBA as a special case inside
kvm_arch_get_supported_msr_feature().(And we do want to warn the user in some way if RSBA is set in the host but not in the guest. But that's a separate problem.)
The first part is easy to do. the latter, "to warn the user in some way if RSBA is set in the host but not in the guest", in kvm_arch_get_supported_msr_feature(), how can I know if guest has enabled IA32_ARCH_CAPABILITIES.RSBA or not? or you mean check in some other place, where is it?
Quoted 22 lines
Quoted 21 lines
target/i386/cpu.c +3
-1+ } }else if (hvf_enabled ()) { r = hvf_get_supported_cpuid(wi->cpuid_eax, wi->cpuid_ecx,@@ -4732,9 +4770,10 @@ static void x86_cpu_adjust_feat_level(X86CPU *cpu, FeatureWord w) {CPUX86State *env = &cpu->env;FeatureWordInfo *fi = &feature_word_info[w]; -uint32_t eax = fi->cpuid_eax; +uint32_t eax = fi->cpuid.eax;uint32_t region = eax &0xF0000000 ; +assert (feature_word_info[w].type ==CPUID_FEATURE_WORD );if (!env->features[w]) {return ; }Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH v3 3/3] Change other funcitons referring to feature_word_info[]
Quoted 154 lines · Robert Hoo
Quoted 23 lines · Eduardo Habkost
Quoted 22 lines · Robert Hoo
Add an util function
feature_word_description(), which help construct the string describing the feature word (both CPUID and MSR types).
report_unavailable_features(): addMSR_FEATURE_WORDtype support.x86_cpu_get_feature_words(): limit toCPUID_FEATURE_WORDonly.x86_cpu_get_supported_feature_word(): addMSR_FEATURE_WORDtype support.x86_cpu_adjust_feat_level(): assert the requested feature must beCPUID_FEATURE_WORDtype.Signed-off-by Robert Hoo <[email protected]>--- target/i386/cpu.c | 77 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 58 insertions(+), 19 deletions(-)target/i386/cpu.c +0
-0@@ -3024,21 +3024,51 @@ static const TypeInfo host_x86_cpu_type_info = {#endif Quoted 9 lines
target/i386/cpu.c static const TypeInfo host_x86_cpu_type_info = { · line 3032
Quoted 6 lines
target/i386/cpu.c +6
-0+/* +*caller should have input str no less than 64 byte length. +*/ +#define FEATURE_WORD_DESCPTION_LEN 64 +static int feature_word_description (char str[],FeatureWordInfo *f, +uint32_t bit)I agree with Eric:
g_strup_printf()would be much simpler here.1 question: I think caller should
g_free()the returned str after itwarn_report(), right?Quoted 119 lines
Quoted 12 lines
target/i386/cpu.c +12
-0+{ +int ret; + +assert (f->type ==CPUID_FEATURE_WORD || + f->type ==MSR_FEATURE_WORD ); +switch (f->type) { +case CPUID_FEATURE_WORD : + { +const char *reg =get_register_name_32 (f->cpuid.reg); +assert (reg); + ret = snprintf(str, FEATURE_WORD_DESCPTION_LEN, + "CPUID.%02XH:%s%s%s [bit %d]",target/i386/cpu.c static const TypeInfo host_x86_cpu_type_info = { · line 3054
Quoted 10 lines
target/i386/cpu.c +10
-0+ f->cpuid.eax, reg, + f->feat_names[bit] ?"." :"" , + f->feat_names[bit] ? f->feat_names[bit] : "", bit); +break ; + } +case MSR_FEATURE_WORD : + ret =snprintf (str,FEATURE_WORD_DESCPTION_LEN , +"MSR(%xH).%s [bit %d]" , + f->msr.index, + f->feat_names[bit] ? f->feat_names[bit] :"" , bit);What about leaving the (f->feat_names[bit] ? ... : ...) part in
report_unavailable_features()and just make this function return "CPUID[...]" or "MSR[...]"?Quoted 39 lines
target/i386/cpu.c +12
-10+break ; + } +return ret >0 ; +} +static void report_unavailable_features (FeatureWord w,uint32_t mask) {FeatureWordInfo *f = &feature_word_info[w];int i; +char feat_word_dscrp_str[FEATURE_WORD_DESCPTION_LEN ];for (i =0 ; i <32 ; ++i) {if ((1UL << i) & mask) { -const char *reg =get_register_name_32 (f->cpuid_reg); -assert (reg); -warn_report ("%s doesn't support requested feature: " -"CPUID.%02XH:%s%s%s [bit %d]" , +feature_word_description (feat_word_dscrp_str, f, i); +warn_report ("%s doesn't support requested feature: %s" ,accel_uses_host_cpuid () ?"host" :"TCG" , - f->cpuid_eax, reg, - f->feat_names[i] ?"." :"" , - f->feat_names[i] ? f->feat_names[i] :"" , i); + feat_word_dscrp_str); } } }@@ -3276,17 +3306,17 @@ static void x86_cpu_get_feature_words(Object *obj, Visitor *v, {uint32_t *array = (uint32_t *)opaque;FeatureWord w; -X86CPUFeatureWordInfo word_infos[FEATURE_WORDS ] = { }; -X86CPUFeatureWordInfoList list_entries[FEATURE_WORDS ] = { }; +X86CPUFeatureWordInfo word_infos[FEATURE_WORDS_NUM_CPUID ] = { }; +X86CPUFeatureWordInfoList list_entries[FEATURE_WORDS_NUM_CPUID ] = { };X86CPUFeatureWordInfoList *list =NULL ; -for (w =0 ; w <FEATURE_WORDS ; w++) { +for (w =0 ; w <FEATURE_WORDS_NUM_CPUID ; w++) {target/i386/cpu.c static void x86_cpu_get_feature_words(Object *obj, Visitor *v, · line 3319
Quoted 10 lines
target/i386/cpu.c +4
-4FeatureWordInfo *wi = &feature_word_info[w];X86CPUFeatureWordInfo *qwi = &word_infos[w]; - qwi->cpuid_input_eax = wi->cpuid_eax; - qwi->has_cpuid_input_ecx = wi->cpuid_needs_ecx; - qwi->cpuid_input_ecx = wi->cpuid_ecx; - qwi->cpuid_register = x86_reg_info_32[wi->cpuid_reg].qapi_enum; + qwi->cpuid_input_eax = wi->cpuid.eax; + qwi->has_cpuid_input_ecx = wi->cpuid.needs_ecx; + qwi->cpuid_input_ecx = wi->cpuid.ecx; + qwi->cpuid_register = x86_reg_info_32[wi->cpuid.reg].qapi_enum;Looks OK, but I would add an
assert(wi->type == CPUID_FEATURE_WORD)on every block of code that uses thewi->cpuidfield.I would also get rid of
FEATURE_WORDS_NUM_CPUIDandFEATURE_WORDS_FIRST_MSRto reduce the chance of future mistakes. We can useFEATURE_WORDSin this loop and just checkwi->typeon each iteration.Quoted 14 lines
target/i386/cpu.c +1
-4qwi->features = array[w];/* List will be in reverse order, but order shouldn't matter */ @@ -3659,12 +3689,20 @@ static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w, bool migratable_only) {FeatureWordInfo *wi = &feature_word_info[w]; -uint32_t r; +uint32_t r =0 ;if (kvm_enabled ()) { - r =kvm_arch_get_supported_cpuid (kvm_state, wi->cpuid_eax, - wi->cpuid_ecx, - wi->cpuid_reg);target/i386/cpu.c static uint32_t x86_cpu_get_supported_feature_word(FeatureWord w, · line 3704
Quoted 10 lines
target/i386/cpu.c +10
-0+switch (wi->type) { +case CPUID_FEATURE_WORD : + r =kvm_arch_get_supported_cpuid (kvm_state, wi->cpuid.eax, + wi->cpuid.ecx, + wi->cpuid.reg); +break ; +case MSR_FEATURE_WORD : + r =kvm_arch_get_supported_msr_feature (kvm_state, + wi->msr.index); +break ;I'm not sure this is correct in the case of IA32_ARCH_CAPABILITIES.RSBA: we do want to be able to set RSBA even if the host doesn't have it set.
Probably you need to handle IA32_ARCH_CAPABILITIES.RSBA as a special case inside
kvm_arch_get_supported_msr_feature().
Quoted 8 lines
Quoted 2 lines
(And we do want to warn the user in some way if RSBA is set in the host but not in the guest. But that's a separate problem.)
The first part is easy to do. the latter, "to warn the user in some way if RSBA is set in the host but not in the guest", in
kvm_arch_get_supported_msr_feature(), how can I know if guest has enabled IA32_ARCH_CAPABILITIES.RSBA or not? or you mean check in some other place, where is it?
Probably X86CPU realize function is an obvious place, but the main problem is that we don't have an appropriate channel to report that warning except stderr (making the warning useless for users that are not running QEMU directly).
We also need to ensure QEMU is doing its job before it complains to the user: before printing a warning about unsafe configuration, we should try to make QEMU enable safe configuration by default.
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v3 3/3] Change other funcitons referring to feature_word_info[]
In reply to Robert HooQuoted 1 line · Robert Hoo
x86_cpu_get_feature_words(): limit toCPUID_FEATURE_WORDonly.
This should also grow support for MSR feature words.
My suggestion is that you add another patch after patch 1 that expands the definition of X86CPUFeatureWordInfo like this, and adjusts x86_cpu_get_feature_words() to match the new C structs. Then this patch can add MSR feature support somewhat easily.
The QAPI definitions would then look like this:
qapi/misc.json +36 -3
@@ -2663,9 +2663,9 @@ 'data': [ 'EAX', 'EBX', 'ECX', 'EDX', 'ESP', 'EBP', 'ESI', 'EDI' ] } ## -# @X86CPUFeatureWordInfo: +# @X86CPUIDFeatureWordInfo: # -# Information about a X86 CPU feature word +# Information about an X86 CPUID feature word # # @cpuid-input-eax: Input EAX value for CPUID instruction for that feature word #
@@ -2678,12 +2690,45 @@ # # Since: 1.5 ## -{ 'struct': 'X86CPUFeatureWordInfo', +{ 'struct': 'X86CPUIDFeatureWordInfo', 'data': { 'cpuid-input-eax': 'int', '*cpuid-input-ecx': 'int', 'cpuid-register': 'X86CPURegister32', 'features': 'int' } } +## +# @X86MSRFeatureWordInfo: +# +# Information about an X86 MSR feature word +# +# @index: Index of the model specific register +# +# @cpuid-feature: CPUID feature name that communicates the existance of the MSR +# +# @features: value of output register, containing the feature bits +# +# Since: 3.1 +## +{ 'struct': 'X86MSRFeatureWordInfo', + 'data': { 'index': 'int', + 'cpuid-feature': 'str', + 'features': 'int' } } + +## +# @X86CPUFeatureWordInfo: +# +# A discriminated record of X86 CPU feature words +# +# Since: 3.1 +## + +{ 'union': 'X86CPUFeatureWordInfo', + 'base': { 'type': 'X86CPUFeatureWordType' }, + 'discriminator': 'type', + 'data': { + 'cpuid': 'X86CPUIDFeatureWordInfo', + 'msr': 'X86MSRFeatureWordInfo' }} + ## # @DummyForceArrays: #
I'm not sure if the cpuid-feature field is useful for libvirt and other management applications. Eduardo, what do you think?
Thanks,
Paolo
Re: [Qemu-devel] [PATCH v3 3/3] Change other funcitons referring to feature_word_info[]
Quoted 11 lines · Paolo Bonzini
Quoted 1 line · Robert Hoo
x86_cpu_get_feature_words(): limit toCPUID_FEATURE_WORDonly.This should also grow support for MSR feature words.
My suggestion is that you add another patch after patch 1 that expands the definition of X86CPUFeatureWordInfo like this, and adjusts
x86_cpu_get_feature_words()to match the new C structs. Then this patch can add MSR feature support somewhat easily.The QAPI definitions would then look like this:
I'm not familiar with json language. Can someone else compose this part?
Quoted 71 lines
qapi/misc.json +36
-3@@ -2663,9 +2663,9 @@ 'data': [ 'EAX', 'EBX', 'ECX', 'EDX', 'ESP', 'EBP', 'ESI', 'EDI' ] } ## -# @X86CPUFeatureWordInfo: +# @X86CPUIDFeatureWordInfo: # -# Information about a X86 CPU feature word +# Information about an X86 CPUID feature word # # @cpuid-input-eax: Input EAX value for CPUID instruction for that feature word #@@ -2678,12 +2690,45 @@ # # Since: 1.5 ## -{ 'struct': 'X86CPUFeatureWordInfo', +{ 'struct': 'X86CPUIDFeatureWordInfo', 'data': { 'cpuid-input-eax': 'int', '*cpuid-input-ecx': 'int', 'cpuid-register': 'X86CPURegister32', 'features': 'int' } } +## +# @X86MSRFeatureWordInfo: +# +# Information about an X86 MSR feature word +# +# @index: Index of the model specific register +# +# @cpuid-feature: CPUID feature name that communicates the existance of the MSR +# +# @features: value of output register, containing the feature bits +# +# Since: 3.1 +## +{ 'struct': 'X86MSRFeatureWordInfo', + 'data': { 'index': 'int', + 'cpuid-feature': 'str', + 'features': 'int' } } + +## +# @X86CPUFeatureWordInfo: +# +# A discriminated record of X86 CPU feature words +# +# Since: 3.1 +## + +{ 'union': 'X86CPUFeatureWordInfo', + 'base': { 'type': 'X86CPUFeatureWordType' }, + 'discriminator': 'type', + 'data': { + 'cpuid': 'X86CPUIDFeatureWordInfo', + 'msr': 'X86MSRFeatureWordInfo' }} + ## # @DummyForceArrays: #I'm not sure if the cpuid-feature field is useful for libvirt and other management applications. Eduardo, what do you think?
Thanks,
Paolo
Re: [Qemu-devel] [PATCH v3 3/3] Change other funcitons referring to feature_word_info[]
In reply to Paolo BonziniQuoted 65 lines · Paolo Bonzini
Quoted 1 line · Robert Hoo
x86_cpu_get_feature_words(): limit toCPUID_FEATURE_WORDonly.This should also grow support for MSR feature words.
My suggestion is that you add another patch after patch 1 that expands the definition of X86CPUFeatureWordInfo like this, and adjusts
x86_cpu_get_feature_words()to match the new C structs. Then this patch can add MSR feature support somewhat easily.The QAPI definitions would then look like this:
qapi/misc.json +29
-3@@ -2663,9 +2663,9 @@ 'data': [ 'EAX', 'EBX', 'ECX', 'EDX', 'ESP', 'EBP', 'ESI', 'EDI' ] } ## -# @X86CPUFeatureWordInfo: +# @X86CPUIDFeatureWordInfo: # -# Information about a X86 CPU feature word +# Information about an X86 CPUID feature word # # @cpuid-input-eax: Input EAX value for CPUID instruction for that feature word #@@ -2678,12 +2690,45 @@ # # Since: 1.5 ## -{ 'struct': 'X86CPUFeatureWordInfo', +{ 'struct': 'X86CPUIDFeatureWordInfo', 'data': { 'cpuid-input-eax': 'int', '*cpuid-input-ecx': 'int', 'cpuid-register': 'X86CPURegister32', 'features': 'int' } } +## +# @X86MSRFeatureWordInfo: +# +# Information about an X86 MSR feature word +# +# @index: Index of the model specific register +# +# @cpuid-feature: CPUID feature name that communicates the existance of the MSR +# +# @features: value of output register, containing the feature bits +# +# Since: 3.1 +## +{ 'struct': 'X86MSRFeatureWordInfo', + 'data': { 'index': 'int', + 'cpuid-feature': 'str', + 'features': 'int' } } + +## +# @X86CPUFeatureWordInfo: +# +# A discriminated record of X86 CPU feature words +# +# Since: 3.1 +## +
qapi/misc.json line 2734
Quoted 10 lines
qapi/misc.json +7
-0+{ 'union': 'X86CPUFeatureWordInfo', + 'base': { 'type': 'X86CPUFeatureWordType' }, + 'discriminator': 'type', + 'data': { + 'cpuid': 'X86CPUIDFeatureWordInfo', + 'msr': 'X86MSRFeatureWordInfo' }} + ## # @DummyForceArrays: #
[root@robert-ivt qemu]# git diff qapi/misc.json
qapi/misc.json +2 -3
@@ -2663,25 +2663,25 @@ 'data': [ 'EAX', 'EBX', 'ECX', 'EDX', 'ESP', 'EBP', 'ESI', 'EDI' ] } ## -# @X86CPUFeatureWordInfo: +# @X86CPUIDFeatureWordInfo: # -# Information about a X86 CPU feature word +# Information about a X86 CPUID feature word # -# @cpuid-input-eax: Input EAX value for CPUID instruction for that
feature word
+# @input-eax: Input EAX value for CPUID instruction for that feature word
#
-# @cpuid-input-ecx: Input ECX value for CPUID instruction for that +# @input-ecx: Input ECX value for CPUID instruction for that
# feature word
#
-# @cpuid-register: Output register containing the feature bits +# @register: Output register containing the feature bits
#
# @features: value of output register, containing the feature bits #
# Since: 1.5
##
-{ 'struct': 'X86CPUFeatureWordInfo',
- 'data': { 'cpuid-input-eax': 'int',
- '*cpuid-input-ecx': 'int',
- 'cpuid-register': 'X86CPURegister32',
+{ 'struct': 'X86CPUIDFeatureWordInfo',
+ 'data': { 'input-eax': 'int',
+ '*input-ecx': 'int',
+ 'register': 'X86CPURegister32',
'features': 'int' } }
##
@@ -2694,6 +2694,50 @@
{ 'struct': 'DummyForceArrays',
'data': { 'unused': ['X86CPUFeatureWordInfo'] } }
+##
+# @X86MSRFeatureWordInfo:
+#
+# Information about an X86 MSR feature word
+#
+# @index: Index of the model specific register
+#
+# @cpuid-feature: CPUID feature name that communicates the existance of the MSR
+#
+# @features: value of output register, containing the feature bits +#
+# Since: 3.1
+##
+{ 'struct': 'X86MSRFeatureWordInfo',
+ 'data': { 'index': 'int',
+ 'cpuid-feature': 'str',
+ 'features': 'int' } }
+
+##
+# @X86CPUFeatureWordType:
+#
+# Kinds of X86 CPU feature words
+#
+# @cpuid: A CPUID leaf
+#
+# @msr: An MSR
+##
+{ 'enum': 'X86CPUFeatureWordType',
+ 'data': [ 'cpuid', 'msr' ] }
+
+##
+# @X86CPUFeatureWordInfo:
+#
+# A discriminated record of X86 CPU feature words
+#
+# Since: 3.1
+##
+{ 'union': 'X86CPUFeatureWordInfo',
+ 'base': { 'type': 'X86CPUFeatureWordType' },
+ 'discriminator': 'type',
+ 'data': {+ 'cpuid': 'X86CPUIDFeatureWordInfo',
+ 'msr': 'X86MSRFeatureWordInfo' }}
+
##
# @NumaOptionsType:
Hi Paolo,
above is my draft change on the qapi json file. 1 question:
struct X86MSRFeatureWordInfo {
int64_t index;
char *cpuid_feature;
int64_t features;
};how to have a "const" prefix the "char *"?
Quoted 7 lines
I'm not sure if the cpuid-feature field is useful for libvirt and other management applications. Eduardo, what do you think?
Thanks,
Paolo
Re: [Qemu-devel] [PATCH v3 3/3] Change other funcitons referring to feature_word_info[]
Question to the QAPI schema maintainers below:
Quoted 157 lines · Robert Hoo
Quoted 65 lines · Paolo Bonzini
Quoted 1 line · Robert Hoo
x86_cpu_get_feature_words(): limit toCPUID_FEATURE_WORDonly.This should also grow support for MSR feature words.
My suggestion is that you add another patch after patch 1 that expands the definition of X86CPUFeatureWordInfo like this, and adjusts
x86_cpu_get_feature_words()to match the new C structs. Then this patch can add MSR feature support somewhat easily.The QAPI definitions would then look like this:
qapi/misc.json +29
-3@@ -2663,9 +2663,9 @@ 'data': [ 'EAX', 'EBX', 'ECX', 'EDX', 'ESP', 'EBP', 'ESI', 'EDI' ] } ## -# @X86CPUFeatureWordInfo: +# @X86CPUIDFeatureWordInfo: # -# Information about a X86 CPU feature word +# Information about an X86 CPUID feature word # # @cpuid-input-eax: Input EAX value for CPUID instruction for that feature word #@@ -2678,12 +2690,45 @@ # # Since: 1.5 ## -{ 'struct': 'X86CPUFeatureWordInfo', +{ 'struct': 'X86CPUIDFeatureWordInfo', 'data': { 'cpuid-input-eax': 'int', '*cpuid-input-ecx': 'int', 'cpuid-register': 'X86CPURegister32', 'features': 'int' } } +## +# @X86MSRFeatureWordInfo: +# +# Information about an X86 MSR feature word +# +# @index: Index of the model specific register +# +# @cpuid-feature: CPUID feature name that communicates the existance of the MSR +# +# @features: value of output register, containing the feature bits +# +# Since: 3.1 +## +{ 'struct': 'X86MSRFeatureWordInfo', + 'data': { 'index': 'int', + 'cpuid-feature': 'str', + 'features': 'int' } } + +## +# @X86CPUFeatureWordInfo: +# +# A discriminated record of X86 CPU feature words +# +# Since: 3.1 +## +qapi/misc.json line 2734
Quoted 10 lines
qapi/misc.json +7
-0+{ 'union': 'X86CPUFeatureWordInfo', + 'base': { 'type': 'X86CPUFeatureWordType' }, + 'discriminator': 'type', + 'data': { + 'cpuid': 'X86CPUIDFeatureWordInfo', + 'msr': 'X86MSRFeatureWordInfo' }} + ## # @DummyForceArrays: #[root@robert-ivt qemu]# git diff
qapi/misc.jsonqapi/misc.json +2
-3@@ -2663,25 +2663,25 @@ 'data': [ 'EAX', 'EBX', 'ECX', 'EDX', 'ESP', 'EBP', 'ESI', 'EDI' ] } ## -# @X86CPUFeatureWordInfo: +# @X86CPUIDFeatureWordInfo: # -# Information about a X86 CPU feature word +# Information about a X86 CPUID feature word # -# @cpuid-input-eax: Input EAX value for CPUID instruction for thatfeature word
+# @input-eax: Input EAX value for CPUID instruction for that feature word
#qapi/misc.json +14
-6-# @cpuid-input-ecx: Input ECX value for CPUID instruction for that +# @input-ecx: Input ECX value for CPUID instruction for that # feature word # -# @cpuid-register: Output register containing the feature bits +# @register: Output register containing the feature bits # # @features: value of output register, containing the feature bits # # Since: 1.5 ## -{ 'struct': 'X86CPUFeatureWordInfo', - 'data': { 'cpuid-input-eax': 'int', - '*cpuid-input-ecx': 'int', - 'cpuid-register': 'X86CPURegister32', +{ 'struct': 'X86CPUIDFeatureWordInfo', + 'data': { 'input-eax': 'int', + '*input-ecx': 'int', + 'register': 'X86CPURegister32', 'features': 'int' } } ##@@ -2694,6 +2694,50 @@ { 'struct': 'DummyForceArrays', 'data': { 'unused': ['X86CPUFeatureWordInfo'] } } +## +# @X86MSRFeatureWordInfo: +# +# Information about an X86 MSR feature word +# +# @index: Index of the model specific register +# +# @cpuid-feature: CPUID feature name that communicates the existance ofthe MSR
qapi/misc.json +25
-0+# +# @features: value of output register, containing the feature bits +# +# Since: 3.1 +## +{ 'struct': 'X86MSRFeatureWordInfo', + 'data': { 'index': 'int', + 'cpuid-feature': 'str', + 'features': 'int' } } + +## +# @X86CPUFeatureWordType: +# +# Kinds of X86 CPU feature words +# +# @cpuid: A CPUID leaf +# +# @msr: An MSR +## +{ 'enum': 'X86CPUFeatureWordType', + 'data': [ 'cpuid', 'msr' ] } + +## +# @X86CPUFeatureWordInfo: +#
qapi/misc.json
Quoted 10 lines
qapi/misc.json +10
-0+# A discriminated record of X86 CPU feature words +# +# Since: 3.1 +## +{ 'union': 'X86CPUFeatureWordInfo', + 'base': { 'type': 'X86CPUFeatureWordType' }, + 'discriminator': 'type', + 'data': { + 'cpuid': 'X86CPUIDFeatureWordInfo', + 'msr': 'X86MSRFeatureWordInfo' }}
Question to the QAPI maintainers: is this really allowed? With this change, data that conforms to the new schema may not conform to the old schema, because now the "input-eax" field will become optional.
AFAICS, this will break the existing libvirt code: it will make qemuMonitorJSONParseCPUx86Features() error out because it won't find the "input-eax" field on all X86CPUFeatureWordInfo elements.
Quoted 7 lines
+
##
# @NumaOptionsType:Hi Paolo,
Quoted 7 lines
above is my draft change on the qapi json file. 1 question:
struct X86MSRFeatureWordInfo { int64_t index; char *cpuid_feature; int64_t features; };how to have a "const" prefix the "char *"?
QAPI will make qapi_free_X86MSRFeatureWordInfo(i) call g_free(i->cpuid_feature), which means you aren't supposed to use a const char pointer here. You can use g_strdup() if necessary.
Quoted 3 lines
Quoted 3 lines
I'm not sure if the cpuid-feature field is useful for libvirt and other management applications. Eduardo, what do you think?
It looks like a very limited way to represent dependencies between CPU features because it applies only to MSRs. I would prefer to represent feature dependencies in a more generic way later, and only if really necessary.
Quoted 6 lines
Quoted 4 lines
Thanks,
Paolo
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v3 3/3] Change other funcitons referring to feature_word_info[]
Quoted 13 lines · Eduardo Habkost
Question to the QAPI schema maintainers below:
Review
Quoted 10 lines
##
(quoted diff) +4
-4-{ 'struct': 'X86CPUFeatureWordInfo', - 'data': { 'cpuid-input-eax': 'int', - '*cpuid-input-ecx': 'int', - 'cpuid-register': 'X86CPURegister32', +{ 'struct': 'X86CPUIDFeatureWordInfo', + 'data': { 'input-eax': 'int', + '*input-ecx': 'int', + 'register': 'X86CPURegister32', 'features': 'int' } }
You are renaming the struct (which is not visible over the wire), as well as renaming members within the struct (which is visible, if this type appears on the wire).
However, 'grep FeatureWordInfo qapi/qapi-introspect.c' has no hits either before or after this patch (well, first you have to build with my currently-pending patch as part of Markus' pull request for this trick to work, https://lists.gnu.org/archive/html/qemu-devel/2018-08/msg05968.html). Or, even without my patch, grepping for 'input-eax' has no hits as a member name in any struct. Which means that there are no QMP commands currently exposing this struct over the wire.
Quoted 6 lines
Question to the QAPI maintainers: is this really allowed? With this change, data that conforms to the new schema may not conform to the old schema, because now the "input-eax" field will become optional.
Yes, you can do whatever you want to QAPI structs that are not part of the QMP API, since they exist merely to make your C code easier. You don't have to worry about backwards compatibility, because the only clients of such structs are being compiled at the same time as you make modifications to that struct. Only once the struct appears in QMP introspection do you start having to worry about back-compat. There, the rules are the struct names don't matter, but member names do; if the struct is used on input, then removing members is bad, adding mandatory members is bad, but adding optional members is okay (older clients don't know to pass in the new members, and may continue to pass in the member name you no longer want to use); if the struct is used on output, then removing non-optional members is bad, removing optional members is okay, and adding members is okay (clients are supposed to ignore unknown members, but may break if a previously mandatory member disappears).
Quoted 4 lines
AFAICS, this will break the existing libvirt code: it will make
qemuMonitorJSONParseCPUx86Features()error out because it won't find the "input-eax" field on all X86CPUFeatureWordInfo elements.
No, this change can't break libvirt, since I just proved there is no QMP command that libvirt could be using that either supplies an input member or expects an output member named "input-eax" in the first place.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v3 3/3] Change other funcitons referring to feature_word_info[]
Quoted 19 lines · Eric Blake
Quoted 13 lines · Eduardo Habkost
Question to the QAPI schema maintainers below:
Review
Quoted 10 lines
##
(quoted diff) +4
-4-{ 'struct': 'X86CPUFeatureWordInfo', - 'data': { 'cpuid-input-eax': 'int', - '*cpuid-input-ecx': 'int', - 'cpuid-register': 'X86CPURegister32', +{ 'struct': 'X86CPUIDFeatureWordInfo', + 'data': { 'input-eax': 'int', + '*input-ecx': 'int', + 'register': 'X86CPURegister32', 'features': 'int' } }You are renaming the struct (which is not visible over the wire), as well as renaming members within the struct (which is visible, if this type appears on the wire).
Quoted 7 lines
However, 'grep FeatureWordInfo
qapi/qapi-introspect.c' has no hits either before or after this patch (well, first you have to build with my currently-pending patch as part of Markus' pull request for this trick to work, https://lists.gnu.org/archive/html/qemu-devel/2018-08/msg05968.html).
Or, even without my patch, grepping for 'input-eax' has no hits as a member name in any struct. Which means that there are no QMP commands currently exposing this struct over the wire.
There is one: qom-get.
Quoted 24 lines
Quoted 7 lines
Question to the QAPI maintainers: is this really allowed? With this change, data that conforms to the new schema may not conform to the old schema, because now the "input-eax" field will become optional.
Yes, you can do whatever you want to QAPI structs that are not part of the QMP API, since they exist merely to make your C code easier. You don't have to worry about backwards compatibility, because the only clients of such structs are being compiled at the same time as you make modifications to that struct. Only once the struct appears in QMP introspection do you start having to worry about back-compat. There, the rules are the struct names don't matter, but member names do; if the struct is used on input, then removing members is bad, adding mandatory members is bad, but adding optional members is okay (older clients don't know to pass in the new members, and may continue to pass in the member name you no longer want to use); if the struct is used on output, then removing non-optional members is bad, removing optional members is okay, and adding members is okay (clients are supposed to ignore unknown members, but may break if a previously mandatory member disappears).
Quoted 1 line
Quoted 7 lines
Quoted 3 lines
AFAICS, this will break the existing libvirt code: it will make
qemuMonitorJSONParseCPUx86Features()error out because it won't find the "input-eax" field on all X86CPUFeatureWordInfo elements.No, this change can't break libvirt, since I just proved there is no QMP command that libvirt could be using that either supplies an input member or expects an output member named "input-eax" in the first place.
I'm sure it will break libvirt. libvirt uses "qom-get path=<cpu-path> property=feature-words" to get X86FeatureWordInfo data, and it expects the returned data to have a "input-eax" field.
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v3 3/3] Change other funcitons referring to feature_word_info[]
Quoted 28 lines · Eduardo Habkost
Quoted 19 lines · Eric Blake
Quoted 13 lines · Eduardo Habkost
Question to the QAPI schema maintainers below:
Review
Quoted 10 lines
##(quoted diff) +4
-4-{ 'struct': 'X86CPUFeatureWordInfo', - 'data': { 'cpuid-input-eax': 'int', - '*cpuid-input-ecx': 'int', - 'cpuid-register': 'X86CPURegister32', +{ 'struct': 'X86CPUIDFeatureWordInfo', + 'data': { 'input-eax': 'int', + '*input-ecx': 'int', + 'register': 'X86CPURegister32', 'features': 'int' } }You are renaming the struct (which is not visible over the wire), as well as renaming members within the struct (which is visible, if this type appears on the wire).
Quoted 7 lines
However, 'grep FeatureWordInfo
qapi/qapi-introspect.c' has no hits either before or after this patch (well, first you have to build with my currently-pending patch as part of Markus' pull request for this trick to work, https://lists.gnu.org/archive/html/qemu-devel/2018-08/msg05968.html).
Or, even without my patch, grepping for 'input-eax' has no hits as a member name in any struct. Which means that there are no QMP commands currently exposing this struct over the wire.
Quoted 1 line
There is one: qom-get.
Oh, right, the nasty exception that is not visible to introspection :(
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
AFAICS, this will break the existing libvirt code: it will make
qemuMonitorJSONParseCPUx86Features()error out because it won't find the "input-eax" field on all X86CPUFeatureWordInfo elements.
Quoted 8 lines
Quoted 3 lines
No, this change can't break libvirt, since I just proved there is no QMP command that libvirt could be using that either supplies an input member or expects an output member named "input-eax" in the first place.
I'm sure it will break libvirt. libvirt uses "qom-get path=<cpu-path> property=feature-words" to get X86FeatureWordInfo data, and it expects the returned data to have a "input-eax" field.
Yeah, since this type is used in the qom-get backdoor that evades introspection, it's even more important that you follow the backwards-compatibility rules and not rename or delete any previously-mandatory members, since libvirt CAN'T introspect if such changes have happened.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v3 3/3] Change other funcitons referring to feature_word_info[]
Quoted 55 lines
-----Original Message-----
From: Eric Blake [mailto:[email protected]]
Sent: Thursday, September 6, 2018 1:41
To: Eduardo Habkost <[email protected]>
Cc: Robert Hoo <[email protected]>; Paolo Bonzini <[email protected]>; Hu, Robert <[email protected]>; [email protected]; [email protected]; [email protected]; Liu, Jingqi <[email protected]>; Markus Armbruster <[email protected]>; Jiri Denemark <[email protected]>
Subject: Re: [PATCH v3 3/3] Change other funcitons referring to feature_word_info[]Quoted 20 lines · Eduardo Habkost
Quoted 19 lines · Eric Blake
Quoted 13 lines · Eduardo Habkost
Question to the QAPI schema maintainers below:
Review
Quoted 10 lines
##(quoted diff) +4
-4-{ 'struct': 'X86CPUFeatureWordInfo', - 'data': { 'cpuid-input-eax': 'int', - '*cpuid-input-ecx': 'int', - 'cpuid-register': 'X86CPURegister32', +{ 'struct': 'X86CPUIDFeatureWordInfo', + 'data': { 'input-eax': 'int', + '*input-ecx': 'int', + 'register': 'X86CPURegister32', 'features': 'int' } }You are renaming the struct (which is not visible over the wire), as well as renaming members within the struct (which is visible, if this type appears on the wire).
Quoted 4 lines
Quoted 4 lines
However, 'grep FeatureWordInfo
qapi/qapi-introspect.c' has no hits either before or after this patch (well, first you have to build with my currently-pending patch as part of Markus' pull request for this trick to work, https://lists.gnu.org/archive/html/qemu-devel/2018-08/msg05968.html).
Quoted 5 lines
Quoted 3 lines
Or, even without my patch, grepping for 'input-eax' has no hits as a member name in any struct. Which means that there are no QMP commands currently exposing this struct over the wire.
There is one: qom-get.
Oh, right, the nasty exception that is not visible to introspection :(
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
AFAICS, this will break the existing libvirt code: it will make
qemuMonitorJSONParseCPUx86Features()error out because it won't find the "input-eax" field on all X86CPUFeatureWordInfo elements.No, this change can't break libvirt, since I just proved there is no QMP command that libvirt could be using that either supplies an input member or expects an output member named "input-eax" in the first place.
Quoted 9 lines
Quoted 3 lines
I'm sure it will break libvirt. libvirt uses "qom-get path=<cpu-path> property=feature-words" to get X86FeatureWordInfo data, and it expects the returned data to have a "input-eax" field.
Yeah, since this type is used in the qom-get backdoor that evades introspection, it's even more important that you follow the backwards-compatibility rules and not rename or delete any previously-mandatory members, since libvirt CAN'T introspect if such changes have happened.
[Robert Hoo]
Oh, this is more complicated than my thought.
So, Eduardo, how about leave the QAPI expansion for MSR based features to other professional people?
Quoted 4 lines
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v3 3/3] Change other funcitons referring to feature_word_info[]
Quoted 64 lines · Robert
Quoted 55 lines
-----Original Message-----
From: Eric Blake [mailto:[email protected]]
Sent: Thursday, September 6, 2018 1:41
To: Eduardo Habkost <[email protected]>
Cc: Robert Hoo <[email protected]>; Paolo Bonzini <[email protected]>; Hu, Robert <[email protected]>; [email protected]; [email protected]; [email protected]; Liu, Jingqi <[email protected]>; Markus Armbruster <[email protected]>; Jiri Denemark <[email protected]>
Subject: Re: [PATCH v3 3/3] Change other funcitons referring to feature_word_info[]Quoted 20 lines · Eduardo Habkost
Quoted 19 lines · Eric Blake
Quoted 13 lines · Eduardo Habkost
Question to the QAPI schema maintainers below:
Review
Quoted 10 lines
##(quoted diff) +4
-4-{ 'struct': 'X86CPUFeatureWordInfo', - 'data': { 'cpuid-input-eax': 'int', - '*cpuid-input-ecx': 'int', - 'cpuid-register': 'X86CPURegister32', +{ 'struct': 'X86CPUIDFeatureWordInfo', + 'data': { 'input-eax': 'int', + '*input-ecx': 'int', + 'register': 'X86CPURegister32', 'features': 'int' } }You are renaming the struct (which is not visible over the wire), as well as renaming members within the struct (which is visible, if this type appears on the wire).
Quoted 4 lines
Quoted 4 lines
However, 'grep FeatureWordInfo
qapi/qapi-introspect.c' has no hits either before or after this patch (well, first you have to build with my currently-pending patch as part of Markus' pull request for this trick to work, https://lists.gnu.org/archive/html/qemu-devel/2018-08/msg05968.html).
Quoted 5 lines
Quoted 3 lines
Or, even without my patch, grepping for 'input-eax' has no hits as a member name in any struct. Which means that there are no QMP commands currently exposing this struct over the wire.
There is one: qom-get.
Oh, right, the nasty exception that is not visible to introspection :(
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
AFAICS, this will break the existing libvirt code: it will make
qemuMonitorJSONParseCPUx86Features()error out because it won't find the "input-eax" field on all X86CPUFeatureWordInfo elements.No, this change can't break libvirt, since I just proved there is no QMP command that libvirt could be using that either supplies an input member or expects an output member named "input-eax" in the first place.
Quoted 9 lines
Quoted 3 lines
I'm sure it will break libvirt. libvirt uses "qom-get path=<cpu-path> property=feature-words" to get X86FeatureWordInfo data, and it expects the returned data to have a "input-eax" field.
Yeah, since this type is used in the qom-get backdoor that evades introspection, it's even more important that you follow the backwards-compatibility rules and not rename or delete any previously-mandatory members, since libvirt CAN'T introspect if such changes have happened.
Quoted 4 lines
[Robert Hoo]
Oh, this is more complicated than my thought.
So, Eduardo, how about leave the QAPI expansion for MSR based features to other professional people?
I think it's now clear that we can't add MSR features to "feature-words" in a compatible way, so any mechanism to introspect MSR features will need a separate property or QMP command.
I also think "feature-words" needs to be replaced with something better. Probably libvirt should be able to grab all information it needs by looking at the boolean QOM properties instead of the low-level info at "feature-words".
This means I agree to leave this functionality out of the MSR feature patch series for now.
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v3 3/3] Change other funcitons referring to feature_word_info[]
Quoted 23 lines · Eduardo Habkost
Quoted 11 lines · Robert
Quoted 10 lines
Yeah, since this type is used in the qom-get backdoor that evades introspection,
it's even more important that you follow the backwards- compatibility rules and
not rename or delete any previously-mandatory members, since libvirt CAN'T
introspect if such changes have happened.Quoted 5 lines
[Robert Hoo]
Oh, this is more complicated than my thought.
So, Eduardo, how about leave the QAPI expansion for MSR based features to other
professional people?I think it's now clear that we can't add MSR features to "feature-words" in a compatible way, so any mechanism to introspect MSR features will need a separate property or QMP command.
Quoted 7 lines
I also think "feature-words" needs to be replaced with something better. Probably libvirt should be able to grab all information it needs by looking at the boolean QOM properties instead of the low-level info at "feature-words".
This means I agree to leave this functionality out of the MSR feature patch series for now.
Thanks Eduardo. Clear to me now.