x86 queue, 2021-06-01
The following changes since commit 52848929b70dcf92a68aedcfd90207be81ba3274:
Merge remote-tracking branch 'remotes/kraxel/tags/usb-20210528-pull-request' into staging (2021-05-30 20:10:30 +0100)
are available in the Git repository at:
https://gitlab.com/ehabkost/qemu.git tags/x86-next-pull-request
for you to fetch changes up to d47b85502b92fe8015d38904cde54eb4d3364326:
sev: add missing firmware error conditions (2021-06-01 09:32:48 -0400)
----------------------------------------------------------------
x86 queue, 2021-06-01
Features:
* Add CPU model versions supporting 'xsaves' (Vitaly Kuznetsov)
* Support AVX512 ZMM regs dump (Robert Hoo)
Bug fixes:
* Use better matching family/model/stepping for generic CPUs (Daniel P. Berrangé)
Cleanups:
* Hyper-V feature initialization cleanup (Vitaly Kuznetsov)
* SEV firmware error list touchups (Connor Kuehl)
* Constify CPUCaches and X86CPUDefinition (Philippe Mathieu-Daudé)
* Document when features can be added to kvm_default_props (Eduardo Habkost)
----------------------------------------------------------------
Brijesh Singh (1):
target/i386/sev: add support to query the attestation report
Connor Kuehl (2):
sev: use explicit indices for mapping firmware error codes to strings
sev: add missing firmware error conditions
Daniel P. Berrangé (2):
i386: use better matching family/model/stepping for 'qemu64' CPU
i386: use better matching family/model/stepping for 'max' CPU
Eduardo Habkost (1):
i386: Document when features can be added to kvm_default_props
Philippe Mathieu-Daudé (2):
target/i386/cpu: Constify CPUCaches
target/i386/cpu: Constify X86CPUDefinition
Robert Hoo (1):
i386/cpu_dump: support AVX512 ZMM regs dump
Vitaly Kuznetsov (15):
target/i386: Add CPU model versions supporting 'xsaves'
i386: keep hyperv_vendor string up-to-date
i386: invert hyperv_spinlock_attempts setting logic with
hv_passthrough
i386: always fill Hyper-V CPUID feature leaves from X86CPU data
i386: stop using env->features[] for filling Hyper-V CPUIDs
i386: introduce hyperv_feature_supported()
i386: introduce hv_cpuid_get_host()
i386: drop FEAT_HYPERV feature leaves
i386: introduce hv_cpuid_cache
i386: split hyperv_handle_properties() into
hyperv_expand_features()/hyperv_fill_cpuids()
i386: move eVMCS enablement to hyperv_init_vcpu()
i386: switch hyperv_expand_features() to using error_setg()
i386: adjust the expected KVM_GET_SUPPORTED_HV_CPUID array size
i386: prefer system KVM_GET_SUPPORTED_HV_CPUID ioctl over vCPU's one
i386: use global kvm_state in hyperv_enabled() check
linux-headers/linux/kvm.h | 8 + target/i386/cpu.h | 6 +- target/i386/sev_i386.h | 2 + hw/i386/pc.c | 6 +- qapi/misc-target.json | 38 +++ target/i386/cpu-dump.c | 63 +++-- target/i386/cpu-sysemu.c | 2 +- target/i386/cpu.c | 290 +++++++++------------- target/i386/kvm/kvm-cpu.c | 5 + target/i386/kvm/kvm.c | 510 +++++++++++++++++++++----------------- target/i386/monitor.c | 6 + target/i386/sev-stub.c | 7 + target/i386/sev.c | 115 +++++++-- target/i386/trace-events | 1 + 14 files changed, 614 insertions(+), 445 deletions(-)
Signature · 1 line
2.30.2
[PULL 22/24] target/i386/sev: add support to query the attestation report
From: Brijesh Singh <[email protected]>
The SEV FW >= 0.23 added a new command that can be used to query the attestation report containing the SHA-256 digest of the guest memory and VMSA encrypted with the LAUNCH_UPDATE and sign it with the PEK.
Note, we already have a command (LAUNCH_MEASURE) that can be used to query the SHA-256 digest of the guest memory encrypted through the LAUNCH_UPDATE. The main difference between previous and this command is that the report is signed with the PEK and unlike the LAUNCH_MEASURE command the ATTESATION_REPORT command can be called while the guest is running.
Add a QMP interface "query-sev-attestation-report" that can be used to get the report encoded in base64.
Message-Id: <[email protected]>
--- linux-headers/linux/kvm.h | 8 +++++ target/i386/sev_i386.h | 2 ++ qapi/misc-target.json | 38 ++++++++++++++++++++++ target/i386/monitor.c | 6 ++++ target/i386/sev-stub.c | 7 ++++ target/i386/sev.c | 67 +++++++++++++++++++++++++++++++++++++++ target/i386/trace-events | 1 + 7 files changed, 129 insertions(+)
linux-headers/linux/kvm.h +8 -0
@@ -1591,6 +1591,8 @@ enum sev_cmd_id {KVM_SEV_DBG_ENCRYPT ,/* Guest certificates commands */ KVM_SEV_CERT_EXPORT , +/* Attestation report */ +KVM_SEV_GET_ATTESTATION_REPORT , KVM_SEV_NR_MAX, };
@@ -1643,6 +1645,12 @@ struct kvm_sev_dbg {__u32 len; }; +struct kvm_sev_attestation_report { +__u8 mnonce[16 ]; +__u64 uaddr; +__u32 len; +}; +#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)#define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1)#define KVM_DEV_ASSIGN_MASK_INTX (1 << 2)
target/i386/sev_i386.h +2 -0
@@ -35,5 +35,7 @@ extern uint32_t sev_get_cbit_position(void);extern uint32_t sev_get_reduced_phys_bits (void );extern char *sev_get_launch_measurement (void );extern SevCapability *sev_get_capabilities (Error **errp); +extern SevAttestationReport * +sev_get_attestation_report (const char *mnonce,Error **errp);#endif
qapi/misc-target.json +38 -0
@@ -285,3 +285,41 @@ ## { 'command': 'query-gic-capabilities', 'returns': ['GICCapability'], 'if': 'defined(TARGET_ARM)' } + + +## +# @SevAttestationReport: +# +# The struct describes attestation report for a Secure Encrypted Virtualization +# feature. +# +# @data: guest attestation report (base64 encoded) +# +# +# Since: 6.1 +## +{ 'struct': 'SevAttestationReport', + 'data': { 'data': 'str'}, + 'if': 'defined(TARGET_I386)' } + +## +# @query-sev-attestation-report: +# +# This command is used to get the SEV attestation report, and is supported on AMD +# X86 platforms only. +# +# @mnonce: a random 16 bytes value encoded in base64 (it will be included in report) +# +# Returns: SevAttestationReport objects. +# +# Since: 6.1 +# +# Example: +# +# -> { "execute" : "query-sev-attestation-report", "arguments": { "mnonce": "aaaaaaa" } } +# <- { "return" : { "data": "aaaaaaaabbbddddd"} } +# +## +{ 'command': 'query-sev-attestation-report', 'data': { 'mnonce': 'str' }, + 'returns': 'SevAttestationReport', + 'if': 'defined(TARGET_I386)' }
target/i386/monitor.c +6 -0
@@ -757,3 +757,9 @@ void qmp_sev_inject_launch_secret(const char *packet_hdr,sev_inject_launch_secret (packet_hdr, secret, gpa, errp); } + +SevAttestationReport * +qmp_query_sev_attestation_report (const char *mnonce,Error **errp) +{ +return sev_get_attestation_report (mnonce, errp); +}
target/i386/sev-stub.c +7 -0
@@ -74,3 +74,10 @@ int sev_es_save_reset_vector(void *flash_ptr, uint64_t flash_size) {abort (); } + +SevAttestationReport * +sev_get_attestation_report (const char *mnonce,Error **errp) +{ +error_setg (errp,"SEV is not available in this QEMU" ); +return NULL ; +}
target/i386/sev.c +67 -0
73 lines not on this page · raw message
target/i386/trace-events +1 -0
@@ -10,3 +10,4 @@ kvm_sev_launch_update_data(void *addr, uint64_t len) "addr %p len 0x%" PRIx64 kvm_sev_launch_measurement(const char *value) "data %s" kvm_sev_launch_finish(void) "" kvm_sev_launch_secret(uint64_t hpa, uint64_t hva, uint64_t secret, int len) "hpa 0x%" PRIx64 " hva 0x%" PRIx64 " data 0x%" PRIx64 " len %d" +kvm_sev_attestation_report(const char *mnonce, const char *data) "mnonce %s data %s"
Signature · 1 line
2.30.2
[PULL 01/24] target/i386: Add CPU model versions supporting 'xsaves'
In reply to Eduardo HabkostFrom: Vitaly Kuznetsov <[email protected]>
Hyper-V 2016 refuses to boot on Skylake+ CPU models because they lack 'xsaves'/'vmx-xsaves' features and this diverges from real hardware. The same issue emerges with AMD "EPYC" CPU model prior to version 3 which got 'xsaves' added. EPYC-Rome/EPYC-Milan CPU models have 'xsaves' enabled from the very beginning so the comment blaming KVM to explain why other CPUs lack 'xsaves' is likely outdated.
Message-Id: <[email protected]>
--- target/i386/cpu.c | 150 +++++++++++++++++++++++++++++----------------- 1 file changed, 94 insertions(+), 56 deletions(-)
target/i386/cpu.c +94 -56
@@ -2802,12 +2802,7 @@ static X86CPUDefinition builtin_x86_defs[] = {CPUID_7_0_EBX_BMI2 |CPUID_7_0_EBX_ERMS |CPUID_7_0_EBX_INVPCID |CPUID_7_0_EBX_RTM |CPUID_7_0_EBX_RDSEED |CPUID_7_0_EBX_ADX | CPUID_7_0_EBX_SMAP, -/* Missing: XSAVES (not supported by some Linux versions, -* including v4.1 to v4.12). -* KVM doesn't yet expose any XSAVES state save component, -* and the only one defined in Skylake (processor tracing) -* probably will block migration anyway. -*/ +/* XSAVES is added in version 4 */ .features[FEAT_XSAVE ] =CPUID_XSAVE_XSAVEOPT |CPUID_XSAVE_XSAVEC | CPUID_XSAVE_XGETBV1,
@@ -2883,6 +2878,15 @@ static X86CPUDefinition builtin_x86_defs[] = { {/* end of list */ } } }, + { + .version = 4, + .note = "IBRS, XSAVES, no TSX", + .props = (PropValue[]) { + { "xsaves", "on" }, + { "vmx-xsaves", "on" }, + { /* end of list */ } + } + }, {/* end of list */ } } },
@@ -2922,12 +2926,7 @@ static X86CPUDefinition builtin_x86_defs[] = { CPUID_7_0_EBX_AVX512VL | CPUID_7_0_EBX_CLFLUSHOPT, .features[FEAT_7_0_ECX ] = CPUID_7_0_ECX_PKU, -/* Missing: XSAVES (not supported by some Linux versions, -* including v4.1 to v4.12). -* KVM doesn't yet expose any XSAVES state save component, -* and the only one defined in Skylake (processor tracing) -* probably will block migration anyway. -*/ +/* XSAVES is added in version 5 */ .features[FEAT_XSAVE ] =CPUID_XSAVE_XSAVEOPT |CPUID_XSAVE_XSAVEC | CPUID_XSAVE_XGETBV1,
@@ -3015,6 +3014,15 @@ static X86CPUDefinition builtin_x86_defs[] = { {/* end of list */ } } }, + { + .version = 5, + .note = "IBRS, XSAVES, EPT switching, no TSX", + .props = (PropValue[]) { + { "xsaves", "on" }, + { "vmx-xsaves", "on" }, + { /* end of list */ } + } + }, {/* end of list */ } } },
@@ -3057,12 +3065,7 @@ static X86CPUDefinition builtin_x86_defs[] = { CPUID_7_0_ECX_AVX512VNNI, .features[FEAT_7_0_EDX ] = CPUID_7_0_EDX_SPEC_CTRL | CPUID_7_0_EDX_SPEC_CTRL_SSBD, -/* Missing: XSAVES (not supported by some Linux versions, -* including v4.1 to v4.12). -* KVM doesn't yet expose any XSAVES state save component, -* and the only one defined in Skylake (processor tracing) -* probably will block migration anyway. -*/ +/* XSAVES is added in version 5 */ .features[FEAT_XSAVE ] =CPUID_XSAVE_XSAVEOPT |CPUID_XSAVE_XSAVEC | CPUID_XSAVE_XGETBV1,
@@ -3146,6 +3149,14 @@ static X86CPUDefinition builtin_x86_defs[] = { {/* end of list */ } }, }, + { .version = 5, + .note = "ARCH_CAPABILITIES, EPT switching, XSAVES, no TSX", + .props = (PropValue[]) { + { "xsaves", "on" }, + { "vmx-xsaves", "on" }, + { /* end of list */ } + }, + }, {/* end of list */ } } },
@@ -3195,13 +3206,7 @@ static X86CPUDefinition builtin_x86_defs[] = { MSR_ARCH_CAP_PSCHANGE_MC_NO | MSR_ARCH_CAP_TAA_NO, .features[FEAT_7_1_EAX ] = CPUID_7_1_EAX_AVX_VNNI | CPUID_7_1_EAX_AVX512_BF16, -/* -* Missing: XSAVES (not supported by some Linux versions, -* including v4.1 to v4.12). -* KVM doesn't yet expose any XSAVES state save component, -* and the only one defined in Skylake (processor tracing) -* probably will block migration anyway. -*/ +/* XSAVES is added in version 2 */ .features[FEAT_XSAVE ] =CPUID_XSAVE_XSAVEOPT |CPUID_XSAVE_XSAVEC | CPUID_XSAVE_XGETBV1,
@@ -3257,6 +3262,18 @@ static X86CPUDefinition builtin_x86_defs[] = { .features[FEAT_VMX_VMFUNC] = MSR_VMX_VMFUNC_EPT_SWITCHING, .xlevel = 0x80000008, .model_id = "Intel Xeon Processor (Cooperlake)", + .versions = (X86CPUVersionDefinition []) { + { .version =1 }, + { .version =2 , + .note ="XSAVES" , + .props = (PropValue []) { + {"xsaves" ,"on" }, + {"vmx-xsaves" ,"on" }, + {/* end of list */ } + }, + }, + {/* end of list */ } + } }, { .name = "Icelake-Client",
@@ -3299,12 +3316,7 @@ static X86CPUDefinition builtin_x86_defs[] = { CPUID_7_0_ECX_AVX512_VPOPCNTDQ, .features[FEAT_7_0_EDX ] = CPUID_7_0_EDX_SPEC_CTRL | CPUID_7_0_EDX_SPEC_CTRL_SSBD, -/* Missing: XSAVES (not supported by some Linux versions, -* including v4.1 to v4.12). -* KVM doesn't yet expose any XSAVES state save component, -* and the only one defined in Skylake (processor tracing) -* probably will block migration anyway. -*/ +/* XSAVES is added in version 3 */ .features[FEAT_XSAVE ] =CPUID_XSAVE_XSAVEOPT |CPUID_XSAVE_XSAVEC | CPUID_XSAVE_XGETBV1,
@@ -3372,6 +3384,15 @@ static X86CPUDefinition builtin_x86_defs[] = { {/* end of list */ } }, }, + { + .version = 3, + .note = "no TSX, XSAVES, deprecated", + .props = (PropValue[]) { + { "xsaves", "on" }, + { "vmx-xsaves", "on" }, + { /* end of list */ } + }, + }, {/* end of list */ } }, .deprecation_note = "use Icelake-Server instead"
@@ -3420,12 +3441,7 @@ static X86CPUDefinition builtin_x86_defs[] = { CPUID_7_0_ECX_AVX512_VPOPCNTDQ | CPUID_7_0_ECX_LA57, .features[FEAT_7_0_EDX ] = CPUID_7_0_EDX_SPEC_CTRL | CPUID_7_0_EDX_SPEC_CTRL_SSBD, -/* Missing: XSAVES (not supported by some Linux versions, -* including v4.1 to v4.12). -* KVM doesn't yet expose any XSAVES state save component, -* and the only one defined in Skylake (processor tracing) -* probably will block migration anyway. -*/ +/* XSAVES is added in version 5 */ .features[FEAT_XSAVE ] =CPUID_XSAVE_XSAVEOPT |CPUID_XSAVE_XSAVEC | CPUID_XSAVE_XGETBV1,
@@ -3518,6 +3534,15 @@ static X86CPUDefinition builtin_x86_defs[] = { {/* end of list */ } }, }, + { + .version = 5, + .note = "XSAVES", + .props = (PropValue[]) { + { "xsaves", "on" }, + { "vmx-xsaves", "on" }, + { /* end of list */ } + }, + }, {/* end of list */ } } },
@@ -3552,13 +3577,7 @@ static X86CPUDefinition builtin_x86_defs[] = { .features[FEAT_7_0_EDX] =CPUID_7_0_EDX_SPEC_CTRL |CPUID_7_0_EDX_ARCH_CAPABILITIES | CPUID_7_0_EDX_SPEC_CTRL_SSBD, -/* -* Missing: XSAVES (not supported by some Linux versions, -* including v4.1 to v4.12). -* KVM doesn't yet expose any XSAVES state save component, -* and the only one defined in Skylake (processor tracing) -* probably will block migration anyway. -*/ +/* XSAVES is added in version 3 */ .features[FEAT_XSAVE ] = CPUID_XSAVE_XSAVEOPT | CPUID_XSAVE_XSAVEC | CPUID_XSAVE_XGETBV1, .features[FEAT_6_EAX] =
@@ -3625,6 +3644,15 @@ static X86CPUDefinition builtin_x86_defs[] = { { /* end of list */ }, }, }, + { + .version = 3, + .note = "XSAVES, no MPX, no MONITOR", + .props = (PropValue[]) { + { "xsaves", "on" }, + { "vmx-xsaves", "on" }, + { /* end of list */ }, + }, + }, { /* end of list */ }, }, },
@@ -3683,13 +3711,7 @@ static X86CPUDefinition builtin_x86_defs[] = { CPUID_7_0_EDX_CORE_CAPABILITY, .features[FEAT_CORE_CAPABILITY ] = MSR_CORE_CAP_SPLIT_LOCK_DETECT, -/* -* Missing: XSAVES (not supported by some Linux versions, -* including v4.1 to v4.12). -* KVM doesn't yet expose any XSAVES state save component, -* and the only one defined in Skylake (processor tracing) -* probably will block migration anyway. -*/ +/* XSAVES is is added in version 3 */ .features[FEAT_XSAVE ] =CPUID_XSAVE_XSAVEOPT |CPUID_XSAVE_XSAVEC | CPUID_XSAVE_XGETBV1,
@@ -3754,6 +3776,15 @@ static X86CPUDefinition builtin_x86_defs[] = { { /* end of list */ }, }, }, + { + .version = 3, + .note = "XSAVES, no MPX", + .props = (PropValue[]) { + { "xsaves", "on" }, + { "vmx-xsaves", "on" }, + { /* end of list */ }, + }, + }, { /* end of list */ }, }, },
@@ -4035,11 +4066,7 @@ static X86CPUDefinition builtin_x86_defs[] = {CPUID_7_0_EBX_FSGSBASE |CPUID_7_0_EBX_BMI1 |CPUID_7_0_EBX_AVX2 |CPUID_7_0_EBX_SMEP |CPUID_7_0_EBX_BMI2 |CPUID_7_0_EBX_RDSEED | CPUID_7_0_EBX_ADX | CPUID_7_0_EBX_SMAP | CPUID_7_0_EBX_CLFLUSHOPT, -/* -* Missing: XSAVES (not supported by some Linux versions, -* including v4.1 to v4.12). -* KVM doesn't yet expose any XSAVES state save component. -*/ +/* XSAVES is added in version 2 */ .features[FEAT_XSAVE ] =CPUID_XSAVE_XSAVEOPT |CPUID_XSAVE_XSAVEC | CPUID_XSAVE_XGETBV1,
@@ -4050,6 +4077,17 @@ static X86CPUDefinition builtin_x86_defs[] = { .xlevel = 0x8000001E, .model_id = "Hygon Dhyana Processor", .cache_info = &epyc_cache_info, + .versions = (X86CPUVersionDefinition []) { + { .version =1 }, + { .version =2 , + .note ="XSAVES" , + .props = (PropValue []) { + {"xsaves" ,"on" }, + {/* end of list */ } + }, + }, + {/* end of list */ } + } }, { .name = "EPYC-Rome",
Signature · 1 line
2.30.2
[PULL 03/24] target/i386/cpu: Constify CPUCaches
In reply to Eduardo HabkostFrom: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <[email protected]>
--- target/i386/cpu.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
target/i386/cpu.c +4 -4
@@ -1576,7 +1576,7 @@ typedef struct X86CPUDefinition {int stepping;FeatureWordArray features;const char *model_id; -CPUCaches *cache_info; +const CPUCaches *const cache_info;/* * Definitions for alternative versions of CPU model. * List is terminated by item with version == 0.
@@ -1619,7 +1619,7 @@ static const X86CPUVersionDefinition *x86_cpu_def_get_versions(X86CPUDefinitionreturn def->versions ?: default_version_list; } -static CPUCaches epyc_cache_info = { +static const CPUCaches epyc_cache_info = { .l1d_cache = &(CPUCacheInfo ) { .type =DATA_CACHE , .level =1 ,
@@ -1669,7 +1669,7 @@ static CPUCaches epyc_cache_info = { }, }; -static CPUCaches epyc_rome_cache_info = { +static const CPUCaches epyc_rome_cache_info = { .l1d_cache = &(CPUCacheInfo ) { .type =DATA_CACHE , .level =1 ,
@@ -1719,7 +1719,7 @@ static CPUCaches epyc_rome_cache_info = { }, }; -static CPUCaches epyc_milan_cache_info = { +static const CPUCaches epyc_milan_cache_info = { .l1d_cache = &(CPUCacheInfo ) { .type =DATA_CACHE , .level =1 ,
Signature · 1 line
2.30.2
[PULL 11/24] i386: stop using env->features[] for filling Hyper-V CPUIDs
In reply to Eduardo HabkostFrom: Vitaly Kuznetsov <[email protected]>
As a preparatory patch to dropping Hyper-V CPUID leaves from feature_word_info[] stop using env->features[] as a temporary storage of Hyper-V CPUIDs, just build Hyper-V CPUID leaves directly from kvm_hyperv_properties[] data.
Message-Id: <[email protected]>
--- target/i386/cpu.h | 1 + target/i386/kvm/kvm.c | 80 +++++++++++++++++++++++-------------------- 2 files changed, 43 insertions(+), 38 deletions(-)
target/i386/cpu.h +1 -0
@@ -1699,6 +1699,7 @@ struct X86CPU {uint32_t hyperv_interface_id[4 ];uint32_t hyperv_version_id[4 ];uint32_t hyperv_limits[3 ]; +uint32_t hyperv_nested[4 ];bool check_cpuid;bool enforce_cpuid;
target/i386/kvm/kvm.c +42 -38
148 lines not on this page · raw message
Signature · 1 line
2.30.2
[PULL 05/24] i386/cpu_dump: support AVX512 ZMM regs dump
In reply to Eduardo HabkostFrom: Robert Hoo <[email protected]>
Since commit fa4518741e (target-i386: Rename struct XMMReg to ZMMReg), CPUX86State.xmm_regs[] has already been extended to 512bit to support AVX512.
Also, other qemu level supports for AVX512 registers are there for years.
But in x86_cpu_dump_state(), still only dump XMM registers no matter YMM/ZMM is enabled.
This patch is to complement this, let it dump XMM/YMM/ZMM accordingly.
Message-Id: <[email protected]>
--- target/i386/cpu-dump.c | 63 ++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 15 deletions(-)
target/i386/cpu-dump.c +48 -15
@@ -478,6 +478,11 @@ void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags)qemu_fprintf (f,"EFER=%016" PRIx64"\n" , env->efer);if (flags &CPU_DUMP_FPU ) {int fptag; +const uint64_t avx512_mask =XSTATE_OPMASK_MASK | \ + XSTATE_ZMM_Hi256_MASK | \ + XSTATE_Hi16_ZMM_MASK | \ +XSTATE_YMM_MASK |XSTATE_SSE_MASK , + avx_mask =XSTATE_YMM_MASK |XSTATE_SSE_MASK ; fptag =0 ;for (i =0 ; i <8 ; i++) { fptag |= ((!env->fptags[i]) << i);
@@ -499,21 +504,49 @@ void x86_cpu_dump_state(CPUState *cs, FILE *f, int flags)else qemu_fprintf (f," " ); } -if (env->hflags &HF_CS64_MASK ) - nb =16 ; -else - nb =8 ; -for (i=0 ;i<nb;i++) { -qemu_fprintf (f,"XMM%02d=%08x%08x%08x%08x" , - i, - env->xmm_regs[i].ZMM_L (3 ), - env->xmm_regs[i].ZMM_L (2 ), - env->xmm_regs[i].ZMM_L (1 ), - env->xmm_regs[i].ZMM_L (0 )); -if ((i &1 ) ==1 ) -qemu_fprintf (f,"\n" ); -else -qemu_fprintf (f," " ); + +if ((env->xcr0 & avx512_mask) == avx512_mask) { +/* XSAVE enabled AVX512 */ +for (i =0 ; i <NB_OPMASK_REGS ; i++) { +qemu_fprintf (f,"Opmask%02d=%016" PRIx64"%s" , i, + env->opmask_regs[i], ((i &3 ) ==3 ) ?"\n" :" " ); + } + + nb = (env->hflags &HF_CS64_MASK ) ?32 :8 ; +for (i =0 ; i < nb; i++) { +qemu_fprintf (f,"ZMM%02d=%016" PRIx64" %016" PRIx64" %016" PRIx64 +" %016" PRIx64" %016" PRIx64" %016" PRIx64 +" %016" PRIx64" %016" PRIx64"\n" , + i, + env->xmm_regs[i].ZMM_Q (7 ), + env->xmm_regs[i].ZMM_Q (6 ), + env->xmm_regs[i].ZMM_Q (5 ), + env->xmm_regs[i].ZMM_Q (4 ), + env->xmm_regs[i].ZMM_Q (3 ), + env->xmm_regs[i].ZMM_Q (2 ), + env->xmm_regs[i].ZMM_Q (1 ), + env->xmm_regs[i].ZMM_Q (0 )); + } + }else if ((env->xcr0 & avx_mask) == avx_mask) { +/* XSAVE enabled AVX */ + nb = env->hflags &HF_CS64_MASK ?16 :8 ; +for (i =0 ; i < nb; i++) { +qemu_fprintf (f,"YMM%02d=%016" PRIx64" %016" PRIx64" %016" PRIx64 +" %016" PRIx64"\n" , i, + env->xmm_regs[i].ZMM_Q (3 ), + env->xmm_regs[i].ZMM_Q (2 ), + env->xmm_regs[i].ZMM_Q (1 ), + env->xmm_regs[i].ZMM_Q (0 )); + } + }else {/* SSE and below cases */ + nb = env->hflags &HF_CS64_MASK ?16 :8 ; +for (i =0 ; i < nb; i++) { +qemu_fprintf (f,"XMM%02d=%016" PRIx64" %016" PRIx64"%s" , + i, + env->xmm_regs[i].ZMM_Q (1 ), + env->xmm_regs[i].ZMM_Q (0 ), + (i &1 ) ?"\n" :" " ); + } } }if (flags &CPU_DUMP_CODE ) {
Signature · 1 line
2.30.2
[PULL 02/24] i386: Document when features can be added to kvm_default_props
In reply to Eduardo HabkostIt's very easy to mistakenly extend kvm_default_props to include features that require a kernel version that's too recent. Add a comment warning about that, pointing to the documentation file where the minimum kernel version for KVM is documented.
Message-Id: <[email protected]>
--- target/i386/kvm/kvm-cpu.c | 5 +++++ 1 file changed, 5 insertions(+)
target/i386/kvm/kvm-cpu.c +5 -0
@@ -47,6 +47,11 @@ static bool kvm_cpu_realizefn(CPUState *cs, Error **errp)/* * KVM-specific features that are automatically added/removed * from all CPU models when KVM is enabled. +* +* NOTE: features can be enabled by default only if they were +* already available in the oldest kernel version supported +* by the KVM accelerator (see "OS requirements" section at +* docs/system/target-i386.rst) */ static PropValue kvm_default_props[] = { {"kvmclock" ,"on" },
Signature · 1 line
2.30.2
[PULL 23/24] sev: use explicit indices for mapping firmware error codes to strings
In reply to Eduardo HabkostFrom: Connor Kuehl <[email protected]>
This can help lower any margin for error when making future additions to the list, especially if they're made out of order.
While doing so, make capitalization of ASID consistent with its usage in the SEV firmware spec (Asid -> ASID).
Message-Id: <[email protected]>
--- target/i386/sev.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-)
target/i386/sev.c +23 -23
@@ -87,29 +87,29 @@ static SevGuestState *sev_guest;static Error *sev_mig_blocker;static const char *const sev_fw_errlist[] = { -"" , -"Platform state is invalid" , -"Guest state is invalid" , -"Platform configuration is invalid" , -"Buffer too small" , -"Platform is already owned" , -"Certificate is invalid" , -"Policy is not allowed" , -"Guest is not active" , -"Invalid address" , -"Bad signature" , -"Bad measurement" , -"Asid is already owned" , -"Invalid ASID" , -"WBINVD is required" , -"DF_FLUSH is required" , -"Guest handle is invalid" , -"Invalid command" , -"Guest is active" , -"Hardware error" , -"Hardware unsafe" , -"Feature not supported" , -"Invalid parameter" + [SEV_RET_SUCCESS ] ="" , + [SEV_RET_INVALID_PLATFORM_STATE ] ="Platform state is invalid" , + [SEV_RET_INVALID_GUEST_STATE ] ="Guest state is invalid" , + [SEV_RET_INAVLID_CONFIG ] ="Platform configuration is invalid" , + [SEV_RET_INVALID_LEN ] ="Buffer too small" , + [SEV_RET_ALREADY_OWNED ] ="Platform is already owned" , + [SEV_RET_INVALID_CERTIFICATE ] ="Certificate is invalid" , + [SEV_RET_POLICY_FAILURE ] ="Policy is not allowed" , + [SEV_RET_INACTIVE ] ="Guest is not active" , + [SEV_RET_INVALID_ADDRESS ] ="Invalid address" , + [SEV_RET_BAD_SIGNATURE ] ="Bad signature" , + [SEV_RET_BAD_MEASUREMENT ] ="Bad measurement" , + [SEV_RET_ASID_OWNED ] ="ASID is already owned" , + [SEV_RET_INVALID_ASID ] ="Invalid ASID" , + [SEV_RET_WBINVD_REQUIRED ] ="WBINVD is required" , + [SEV_RET_DFFLUSH_REQUIRED ] ="DF_FLUSH is required" , + [SEV_RET_INVALID_GUEST ] ="Guest handle is invalid" , + [SEV_RET_INVALID_COMMAND ] ="Invalid command" , + [SEV_RET_ACTIVE ] ="Guest is active" , + [SEV_RET_HWSEV_RET_PLATFORM ] ="Hardware error" , + [SEV_RET_HWSEV_RET_UNSAFE ] ="Hardware unsafe" , + [SEV_RET_UNSUPPORTED ] ="Feature not supported" , + [SEV_RET_INVALID_PARAM ] ="Invalid parameter" , };#define SEV_FW_MAX_ERROR ARRAY_SIZE(sev_fw_errlist)
Signature · 1 line
2.30.2
[PULL 06/24] i386: use better matching family/model/stepping for 'qemu64' CPU
In reply to Eduardo HabkostFrom: Daniel P. Berrangé <[email protected]>
The 'qemu64' CPUID currently reports a family/model/stepping that approximately corresponds to an AMD K7 vintage architecture. The K7 series predates the introduction of 64-bit support by AMD in the K8 series. This has been reported to lead to LLVM complaints about generating 64-bit code for a 32-bit CPU target
LLVM ERROR: 64-bit code requested on a subtarget that doesn't support it!
It appears LLVM looks at the family/model/stepping, despite qemu64 reporting it is 64-bit capable.
This patch changes 'qemu64' to report a CPUID with the family, model and stepping taken from a
AMD Athlon(tm) 64 X2 Dual Core Processor 4000+
which is one of the first 64-bit AMD CPUs.
Closes https://gitlab.com/qemu-project/qemu/-/issues/191
Message-Id: <[email protected]>
--- hw/i386/pc.c | 6 +++++- target/i386/cpu.c | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-)
hw/i386/pc.c +5 -1
@@ -94,7 +94,11 @@#include "trace.h" #include CONFIG_DEVICES -GlobalProperty pc_compat_6_0[] = {}; +GlobalProperty pc_compat_6_0[] = { + {"qemu64" "-" TYPE_X86_CPU ,"family" ,"6" }, + {"qemu64" "-" TYPE_X86_CPU ,"model" ,"6" }, + {"qemu64" "-" TYPE_X86_CPU ,"stepping" ,"3" }, +};const size_t pc_compat_6_0_len =G_N_ELEMENTS (pc_compat_6_0);GlobalProperty pc_compat_5_2[] = {
target/i386/cpu.c +3 -3
@@ -1803,9 +1803,9 @@ static const X86CPUDefinition builtin_x86_defs[] = { .name = "qemu64", .level = 0xd, .vendor = CPUID_VENDOR_AMD, - .family = 6, - .model = 6, - .stepping = 3, + .family = 15, + .model = 107, + .stepping = 1, .features[FEAT_1_EDX ] =PPRO_FEATURES | CPUID_MTRR | CPUID_CLFLUSH | CPUID_MCA |
Signature · 1 line
2.30.2
[PULL 04/24] target/i386/cpu: Constify X86CPUDefinition
In reply to Eduardo HabkostFrom: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <[email protected]>
--- target/i386/cpu.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
target/i386/cpu.c +7 -6
@@ -1589,7 +1589,7 @@ typedef struct X86CPUDefinition {/* Reference to a specific CPU model version */ struct X86CPUModel {/* Base CPU definition */ -X86CPUDefinition *cpudef; +const X86CPUDefinition *cpudef;/* CPU model version */ X86CPUVersion version;const char *note;
@@ -1601,14 +1601,15 @@ struct X86CPUModel { };/* Get full model name for CPU version */ -static char *x86_cpu_versioned_model_name (X86CPUDefinition *cpudef, +static char *x86_cpu_versioned_model_name (const X86CPUDefinition *cpudef,X86CPUVersion version) {assert (version >0 );return g_strdup_printf ("%s-v%d" , cpudef->name, (int )version); } -static const X86CPUVersionDefinition *x86_cpu_def_get_versions (X86CPUDefinition *def) +static const X86CPUVersionDefinition * +x86_cpu_def_get_versions (const X86CPUDefinition *def) {/* When X86CPUDefinition::versions is NULL, we register only v1 */ static const X86CPUVersionDefinition default_version_list[] = {
@@ -1797,7 +1798,7 @@ static const CPUCaches epyc_milan_cache_info = {* PT in VMX operation */ -static X86CPUDefinition builtin_x86_defs[] = { +static const X86CPUDefinition builtin_x86_defs[] = { { .name ="qemu64" , .level =0xd ,
@@ -5061,7 +5062,7 @@ static void x86_cpu_apply_version_props(X86CPU *cpu, X86CPUModel *model)*/ static void x86_cpu_load_model (X86CPU *cpu,X86CPUModel *model) { -X86CPUDefinition *def = model->cpudef; +const X86CPUDefinition *def = model->cpudef;CPUX86State *env = &cpu->env;FeatureWord w;
@@ -5148,7 +5149,7 @@ static void x86_register_cpu_model_type(const char *name, X86CPUModel *model)type_register (&ti); } -static void x86_register_cpudef_types (X86CPUDefinition *def) +static void x86_register_cpudef_types (const X86CPUDefinition *def) {X86CPUModel *m;const X86CPUVersionDefinition *vdef;
Signature · 1 line
2.30.2
[PULL 08/24] i386: keep hyperv_vendor string up-to-date
In reply to Eduardo HabkostFrom: Vitaly Kuznetsov <[email protected]>
When cpu->hyperv_vendor is not set manually we default to "Microsoft Hv" and in 'hv_passthrough' mode we get the information from the host. This information is stored in cpu->hyperv_vendor_id[] array but we don't update cpu->hyperv_vendor string so e.g. QMP's query-cpu-model-expansion output is incorrect.
Message-Id: <[email protected]>
--- target/i386/cpu.c | 19 +++++++++---------- target/i386/kvm/kvm.c | 5 +++++ 2 files changed, 14 insertions(+), 10 deletions(-)
target/i386/cpu.c +9 -10
@@ -6141,17 +6141,16 @@ static void x86_cpu_hyperv_realize(X86CPU *cpu)/* Hyper-V vendor id */ if (!cpu->hyperv_vendor) { -memcpy (cpu->hyperv_vendor_id,"Microsoft Hv" ,12 ); - }else { - len =strlen (cpu->hyperv_vendor); - -if (len >12 ) { -warn_report ("hv-vendor-id truncated to 12 characters" ); - len =12 ; - } -memset (cpu->hyperv_vendor_id,0 ,12 ); -memcpy (cpu->hyperv_vendor_id, cpu->hyperv_vendor, len); +object_property_set_str (OBJECT (cpu),"hv-vendor-id" ,"Microsoft Hv" , + &error_abort); + } + len =strlen (cpu->hyperv_vendor); +if (len >12 ) { +warn_report ("hv-vendor-id truncated to 12 characters" ); + len =12 ; } +memset (cpu->hyperv_vendor_id,0 ,12 ); +memcpy (cpu->hyperv_vendor_id, cpu->hyperv_vendor, len);/* 'Hv#1' interface identification*/ cpu->hyperv_interface_id[0 ] =0x31237648 ;
target/i386/kvm/kvm.c +5 -0
@@ -1216,6 +1216,11 @@ static int hyperv_handle_properties(CPUState *cs, cpu->hyperv_vendor_id[0 ] = c->ebx; cpu->hyperv_vendor_id[1 ] = c->ecx; cpu->hyperv_vendor_id[2 ] = c->edx; + cpu->hyperv_vendor =g_realloc (cpu->hyperv_vendor, +sizeof (cpu->hyperv_vendor_id) +1 ); +memcpy (cpu->hyperv_vendor, cpu->hyperv_vendor_id, +sizeof (cpu->hyperv_vendor_id)); + cpu->hyperv_vendor[sizeof (cpu->hyperv_vendor_id)] =0 ; } c =cpuid_find_entry (cpuid,HV_CPUID_INTERFACE ,0 );
Signature · 1 line
2.30.2
[PULL 10/24] i386: always fill Hyper-V CPUID feature leaves from X86CPU data
In reply to Eduardo HabkostFrom: Vitaly Kuznetsov <[email protected]>
We have all the required data in X86CPU already and as we are about to split hyperv_handle_properties() into hyperv_expand_features()/ hyperv_fill_cpuids() we can remove the blind copy. The functional change is that QEMU won't pass CPUID leaves it doesn't currently know about to the guest but arguably this is a good change.
Message-Id: <[email protected]>
--- target/i386/kvm/kvm.c | 9 --------- 1 file changed, 9 deletions(-)
target/i386/kvm/kvm.c +0 -9
@@ -1208,9 +1208,6 @@ static int hyperv_handle_properties(CPUState *cs, }if (cpu->hyperv_passthrough) { -memcpy (cpuid_ent, &cpuid->entries[0 ], - cpuid->nent *sizeof (cpuid->entries[0 ])); - c =cpuid_find_entry (cpuid,HV_CPUID_VENDOR_AND_MAX_FUNCTIONS ,0 );if (c) { cpu->hyperv_vendor_id[0 ] = c->ebx;
@@ -1310,12 +1307,6 @@ static int hyperv_handle_properties(CPUState *cs, goto free; } -if (cpu->hyperv_passthrough) { -/* We already copied all feature words from KVM as is */ - r = cpuid->nent; - goto free; - } - c = &cpuid_ent[cpuid_i++]; c->function =HV_CPUID_VENDOR_AND_MAX_FUNCTIONS ; c->eax = hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS) ?
Signature · 1 line
2.30.2
[PULL 20/24] i386: prefer system KVM_GET_SUPPORTED_HV_CPUID ioctl over vCPU's one
In reply to Eduardo HabkostFrom: Vitaly Kuznetsov <[email protected]>
KVM_GET_SUPPORTED_HV_CPUID was made a system wide ioctl which can be called prior to creating vCPUs and we are going to use that to expand Hyper-V cpu features early. Use it when it is supported by KVM.
Message-Id: <[email protected]>
--- target/i386/kvm/kvm.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
target/i386/kvm/kvm.c +13 -4
@@ -929,7 +929,8 @@ static struct { }, }; -static struct kvm_cpuid2 *try_get_hv_cpuid (CPUState *cs,int max) +static struct kvm_cpuid2 *try_get_hv_cpuid (CPUState *cs,int max, +bool do_sys_ioctl) {struct kvm_cpuid2 *cpuid;int r, size;
@@ -938,7 +939,11 @@ static struct kvm_cpuid2 *try_get_hv_cpuid(CPUState *cs, int max) cpuid =g_malloc0 (size); cpuid->nent = max; - r =kvm_vcpu_ioctl (cs,KVM_GET_SUPPORTED_HV_CPUID , cpuid); +if (do_sys_ioctl) { + r =kvm_ioctl (kvm_state,KVM_GET_SUPPORTED_HV_CPUID , cpuid); + }else { + r =kvm_vcpu_ioctl (cs,KVM_GET_SUPPORTED_HV_CPUID , cpuid); + }if (r ==0 && cpuid->nent >= max) { r = -E2BIG ; }
@@ -965,13 +970,17 @@ static struct kvm_cpuid2 *get_supported_hv_cpuid(CPUState *cs)/* 0x40000000..0x40000005, 0x4000000A, 0x40000080..0x40000080 leaves */ int max =10 ;int i; +bool do_sys_ioctl; + + do_sys_ioctl = +kvm_check_extension (kvm_state,KVM_CAP_SYS_HYPERV_CPUID ) >0 ;/* * When the buffer is too small, KVM_GET_SUPPORTED_HV_CPUID fails with * -E2BIG, however, it doesn't report back the right size. Keep increasing * it and re-trying until we succeed. */ -while ((cpuid =try_get_hv_cpuid (cs, max)) ==NULL ) { +while ((cpuid =try_get_hv_cpuid (cs, max, do_sys_ioctl)) ==NULL ) { max++; }
@@ -981,7 +990,7 @@ static struct kvm_cpuid2 *get_supported_hv_cpuid(CPUState *cs)* information early, just check for the capability and set the bit * manually. */ -if (kvm_check_extension (cs->kvm_state, +if (!do_sys_ioctl &&kvm_check_extension (cs->kvm_state,KVM_CAP_HYPERV_ENLIGHTENED_VMCS ) >0 ) {for (i =0 ; i < cpuid->nent; i++) {if (cpuid->entries[i].function ==HV_CPUID_ENLIGHTMENT_INFO ) {
Signature · 1 line
2.30.2
[PULL 07/24] i386: use better matching family/model/stepping for 'max' CPU
In reply to Eduardo HabkostFrom: Daniel P. Berrangé <[email protected]>
The 'max' CPU under TCG currently reports a family/model/stepping that approximately corresponds to an AMD K7 vintage architecture. The K7 series predates the introduction of 64-bit support by AMD in the K8 series. This has been reported to lead to LLVM complaints about generating 64-bit code for a 32-bit CPU target
LLVM ERROR: 64-bit code requested on a subtarget that doesn't support it!
It appears LLVM looks at the family/model/stepping, despite qemu64 reporting it is 64-bit capable.
This patch changes 'max' to report a CPUID with the family, model and stepping taken from a
AMD Athlon(tm) 64 X2 Dual Core Processor 4000+
which is one of the first 64-bit AMD CPUs.
Closes https://gitlab.com/qemu-project/qemu/-/issues/191
Message-Id: <[email protected]>
--- target/i386/cpu.c | 6 ++++++ 1 file changed, 6 insertions(+)
target/i386/cpu.c +6 -0
@@ -4285,9 +4285,15 @@ static void max_x86_cpu_initfn(Object *obj)*/ object_property_set_str (OBJECT (cpu),"vendor" ,CPUID_VENDOR_AMD , &error_abort); +#ifdef TARGET_X86_64 +object_property_set_int (OBJECT (cpu),"family" ,15 , &error_abort); +object_property_set_int (OBJECT (cpu),"model" ,107 , &error_abort); +object_property_set_int (OBJECT (cpu),"stepping" ,1 , &error_abort); +#else object_property_set_int (OBJECT (cpu),"family" ,6 , &error_abort);object_property_set_int (OBJECT (cpu),"model" ,6 , &error_abort);object_property_set_int (OBJECT (cpu),"stepping" ,3 , &error_abort); +#endif object_property_set_str (OBJECT (cpu),"model-id" ,"QEMU TCG CPU version " QEMU_HW_VERSION , &error_abort);
Signature · 1 line
2.30.2
[PULL 09/24] i386: invert hyperv_spinlock_attempts setting logic with hv_passthrough
In reply to Eduardo HabkostFrom: Vitaly Kuznetsov <[email protected]>
There is no need to have this special case: like all other Hyper-V enlightenments we can just use kernel's supplied value in hv_passthrough mode.
Message-Id: <[email protected]>
--- target/i386/kvm/kvm.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
target/i386/kvm/kvm.c +1 -5
@@ -1257,11 +1257,7 @@ static int hyperv_handle_properties(CPUState *cs, c =cpuid_find_entry (cpuid,HV_CPUID_ENLIGHTMENT_INFO ,0 );if (c) { env->features[FEAT_HV_RECOMM_EAX ] = c->eax; - -/* hv-spinlocks may have been overriden */ -if (cpu->hyperv_spinlock_attempts !=HYPERV_SPINLOCK_NEVER_NOTIFY ) { - c->ebx = cpu->hyperv_spinlock_attempts; - } + cpu->hyperv_spinlock_attempts = c->ebx; } c =cpuid_find_entry (cpuid,HV_CPUID_NESTED_FEATURES ,0 );if (c) {
Signature · 1 line
2.30.2
[PULL 12/24] i386: introduce hyperv_feature_supported()
In reply to Eduardo HabkostFrom: Vitaly Kuznetsov <[email protected]>
Clean up hv_cpuid_check_and_set() by separating hyperv_feature_supported() off it. No functional change intended.
Message-Id: <[email protected]>
--- target/i386/kvm/kvm.c | 49 ++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 19 deletions(-)
target/i386/kvm/kvm.c +30 -19
@@ -1108,13 +1108,33 @@ static int hv_cpuid_get_fw(struct kvm_cpuid2 *cpuid, int fw, uint32_t *r)return 0 ; } +static bool hyperv_feature_supported (struct kvm_cpuid2 *cpuid,int feature) +{ +uint32_t r, fw, bits; +int i; + +for (i =0 ; i <ARRAY_SIZE (kvm_hyperv_properties[feature].flags); i++) { + fw = kvm_hyperv_properties[feature].flags[i].fw; + bits = kvm_hyperv_properties[feature].flags[i].bits; + +if (!fw) { +continue ; + } + +if (hv_cpuid_get_fw (cpuid, fw, &r) || (r & bits) != bits) { +return false; + } + } + +return true; +} +static int hv_cpuid_check_and_set (CPUState *cs,struct kvm_cpuid2 *cpuid,int feature) {X86CPU *cpu =X86_CPU (cs); -uint32_t r, fw, bits;uint64_t deps; -int i, dep_feat; +int dep_feat;if (!hyperv_feat_enabled (cpu, feature) && !cpu->hyperv_passthrough) {return 0 ;
@@ -1133,23 +1153,14 @@ static int hv_cpuid_check_and_set(CPUState *cs, struct kvm_cpuid2 *cpuid, deps &= ~(1ull << dep_feat); } -for (i =0 ; i <ARRAY_SIZE (kvm_hyperv_properties[feature].flags); i++) { - fw = kvm_hyperv_properties[feature].flags[i].fw; - bits = kvm_hyperv_properties[feature].flags[i].bits; - -if (!fw) { -continue ; - } - -if (hv_cpuid_get_fw (cpuid, fw, &r) || (r & bits) != bits) { -if (hyperv_feat_enabled (cpu, feature)) { -fprintf (stderr, -"Hyper-V %s is not supported by kernel\n" , - kvm_hyperv_properties[feature].desc); -return 1 ; - }else { -return 0 ; - } +if (!hyperv_feature_supported (cpuid, feature)) { +if (hyperv_feat_enabled (cpu, feature)) { +fprintf (stderr, +"Hyper-V %s is not supported by kernel\n" , + kvm_hyperv_properties[feature].desc); +return 1 ; + }else { +return 0 ; } }
Signature · 1 line
2.30.2
[PULL 17/24] i386: move eVMCS enablement to hyperv_init_vcpu()
In reply to Eduardo HabkostFrom: Vitaly Kuznetsov <[email protected]>
hyperv_expand_features() will be called before we create vCPU so evmcs enablement should go away. hyperv_init_vcpu() looks like the right place.
Message-Id: <[email protected]>
--- target/i386/kvm/kvm.c | 60 ++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 23 deletions(-)
target/i386/kvm/kvm.c +37 -23
@@ -963,6 +963,7 @@ static struct kvm_cpuid2 *get_supported_hv_cpuid(CPUState *cs) {struct kvm_cpuid2 *cpuid;int max =7 ;/* 0x40000000..0x40000005, 0x4000000A */ +int i;/* * When the buffer is too small, KVM_GET_SUPPORTED_HV_CPUID fails with
@@ -972,6 +973,22 @@ static struct kvm_cpuid2 *get_supported_hv_cpuid(CPUState *cs)while ((cpuid =try_get_hv_cpuid (cs, max)) ==NULL ) { max++; } + +/* +* KVM_GET_SUPPORTED_HV_CPUID does not set EVMCS CPUID bit before +* KVM_CAP_HYPERV_ENLIGHTENED_VMCS is enabled but we want to get the +* information early, just check for the capability and set the bit +* manually. +*/ +if (kvm_check_extension (cs->kvm_state, +KVM_CAP_HYPERV_ENLIGHTENED_VMCS ) >0 ) { +for (i =0 ; i < cpuid->nent; i++) { +if (cpuid->entries[i].function ==HV_CPUID_ENLIGHTMENT_INFO ) { + cpuid->entries[i].eax |=HV_ENLIGHTENED_VMCS_RECOMMENDED ; + } + } + } +return cpuid; }
@@ -1201,24 +1218,6 @@ static int hyperv_expand_features(CPUState *cs)if (!hyperv_enabled (cpu))return 0 ; -if (hyperv_feat_enabled (cpu,HYPERV_FEAT_EVMCS ) || - cpu->hyperv_passthrough) { -uint16_t evmcs_version; - - r =kvm_vcpu_enable_cap (cs,KVM_CAP_HYPERV_ENLIGHTENED_VMCS ,0 , - (uintptr_t )&evmcs_version); - -if (hyperv_feat_enabled (cpu,HYPERV_FEAT_EVMCS ) && r) { -fprintf (stderr,"Hyper-V %s is not supported by kernel\n" , - kvm_hyperv_properties[HYPERV_FEAT_EVMCS ].desc); -return -ENOSYS ; - } - -if (!r) { - cpu->hyperv_nested[0 ] = evmcs_version; - } - } -if (cpu->hyperv_passthrough) { cpu->hyperv_vendor_id[0 ] =hv_cpuid_get_host (cs,HV_CPUID_VENDOR_AND_MAX_FUNCTIONS ,R_EBX );
@@ -1456,6 +1455,21 @@ static int hyperv_init_vcpu(X86CPU *cpu) } } +if (hyperv_feat_enabled (cpu,HYPERV_FEAT_EVMCS )) { +uint16_t evmcs_version; + + ret =kvm_vcpu_enable_cap (cs,KVM_CAP_HYPERV_ENLIGHTENED_VMCS ,0 , + (uintptr_t )&evmcs_version); + +if (ret <0 ) { +fprintf (stderr,"Hyper-V %s is not supported by kernel\n" , + kvm_hyperv_properties[HYPERV_FEAT_EVMCS ].desc); +return ret; + } + + cpu->hyperv_nested[0 ] = evmcs_version; + } +return 0 ; }
@@ -1520,6 +1534,11 @@ int kvm_arch_init_vcpu(CPUState *cs) }if (hyperv_enabled (cpu)) { + r =hyperv_init_vcpu (cpu); +if (r) { +return r; + } + cpuid_i =hyperv_fill_cpuids (cs, cpuid_data.entries); kvm_base =KVM_CPUID_SIGNATURE_NEXT ; has_msr_hv_hypercall = true;
@@ -1869,11 +1888,6 @@ int kvm_arch_init_vcpu(CPUState *cs)kvm_init_msrs (cpu); - r =hyperv_init_vcpu (cpu); -if (r) { - goto fail; - } -return 0 ; fail:
Signature · 1 line
2.30.2
[PULL 13/24] i386: introduce hv_cpuid_get_host()
In reply to Eduardo HabkostFrom: Vitaly Kuznetsov <[email protected]>
As a preparation to implementing hv_cpuid_cache intro introduce hv_cpuid_get_host(). No functional change intended.
Message-Id: <[email protected]>
--- target/i386/kvm/kvm.c | 102 +++++++++++++++++++++++------------------- 1 file changed, 57 insertions(+), 45 deletions(-)
target/i386/kvm/kvm.c +57 -45
@@ -1108,6 +1108,19 @@ static int hv_cpuid_get_fw(struct kvm_cpuid2 *cpuid, int fw, uint32_t *r)return 0 ; } +static uint32_t hv_cpuid_get_host (struct kvm_cpuid2 *cpuid,uint32_t func, +int reg) +{ +struct kvm_cpuid_entry2 *entry; + + entry =cpuid_find_entry (cpuid, func,0 ); +if (!entry) { +return 0 ; + } + +return cpuid_entry_get_reg (entry, reg); +} +static bool hyperv_feature_supported (struct kvm_cpuid2 *cpuid,int feature) {uint32_t r, fw, bits;
@@ -1204,7 +1217,7 @@ static int hyperv_handle_properties(CPUState *cs, {X86CPU *cpu =X86_CPU (cs);struct kvm_cpuid2 *cpuid; -struct kvm_cpuid_entry2 *c, *c2; +struct kvm_cpuid_entry2 *c;uint32_t cpuid_i =0 ;int r;
@@ -1236,46 +1249,47 @@ static int hyperv_handle_properties(CPUState *cs, }if (cpu->hyperv_passthrough) { - c =cpuid_find_entry (cpuid,HV_CPUID_VENDOR_AND_MAX_FUNCTIONS ,0 ); -if (c) { - cpu->hyperv_vendor_id[0 ] = c->ebx; - cpu->hyperv_vendor_id[1 ] = c->ecx; - cpu->hyperv_vendor_id[2 ] = c->edx; - cpu->hyperv_vendor =g_realloc (cpu->hyperv_vendor, -sizeof (cpu->hyperv_vendor_id) +1 ); -memcpy (cpu->hyperv_vendor, cpu->hyperv_vendor_id, -sizeof (cpu->hyperv_vendor_id)); - cpu->hyperv_vendor[sizeof (cpu->hyperv_vendor_id)] =0 ; - } - - c =cpuid_find_entry (cpuid,HV_CPUID_INTERFACE ,0 ); -if (c) { - cpu->hyperv_interface_id[0 ] = c->eax; - cpu->hyperv_interface_id[1 ] = c->ebx; - cpu->hyperv_interface_id[2 ] = c->ecx; - cpu->hyperv_interface_id[3 ] = c->edx; - } - - c =cpuid_find_entry (cpuid,HV_CPUID_VERSION ,0 ); -if (c) { - cpu->hyperv_version_id[0 ] = c->eax; - cpu->hyperv_version_id[1 ] = c->ebx; - cpu->hyperv_version_id[2 ] = c->ecx; - cpu->hyperv_version_id[3 ] = c->edx; - } - - c =cpuid_find_entry (cpuid,HV_CPUID_IMPLEMENT_LIMITS ,0 ); -if (c) { - cpu->hv_max_vps = c->eax; - cpu->hyperv_limits[0 ] = c->ebx; - cpu->hyperv_limits[1 ] = c->ecx; - cpu->hyperv_limits[2 ] = c->edx; - } - - c =cpuid_find_entry (cpuid,HV_CPUID_ENLIGHTMENT_INFO ,0 ); -if (c) { - cpu->hyperv_spinlock_attempts = c->ebx; - } + cpu->hyperv_vendor_id[0 ] = +hv_cpuid_get_host (cpuid,HV_CPUID_VENDOR_AND_MAX_FUNCTIONS ,R_EBX ); + cpu->hyperv_vendor_id[1 ] = +hv_cpuid_get_host (cpuid,HV_CPUID_VENDOR_AND_MAX_FUNCTIONS ,R_ECX ); + cpu->hyperv_vendor_id[2 ] = +hv_cpuid_get_host (cpuid,HV_CPUID_VENDOR_AND_MAX_FUNCTIONS ,R_EDX ); + cpu->hyperv_vendor =g_realloc (cpu->hyperv_vendor, +sizeof (cpu->hyperv_vendor_id) +1 ); +memcpy (cpu->hyperv_vendor, cpu->hyperv_vendor_id, +sizeof (cpu->hyperv_vendor_id)); + cpu->hyperv_vendor[sizeof (cpu->hyperv_vendor_id)] =0 ; + + cpu->hyperv_interface_id[0 ] = +hv_cpuid_get_host (cpuid,HV_CPUID_INTERFACE ,R_EAX ); + cpu->hyperv_interface_id[1 ] = +hv_cpuid_get_host (cpuid,HV_CPUID_INTERFACE ,R_EBX ); + cpu->hyperv_interface_id[2 ] = +hv_cpuid_get_host (cpuid,HV_CPUID_INTERFACE ,R_ECX ); + cpu->hyperv_interface_id[3 ] = +hv_cpuid_get_host (cpuid,HV_CPUID_INTERFACE ,R_EDX ); + + cpu->hyperv_version_id[0 ] = +hv_cpuid_get_host (cpuid,HV_CPUID_VERSION ,R_EAX ); + cpu->hyperv_version_id[1 ] = +hv_cpuid_get_host (cpuid,HV_CPUID_VERSION ,R_EBX ); + cpu->hyperv_version_id[2 ] = +hv_cpuid_get_host (cpuid,HV_CPUID_VERSION ,R_ECX ); + cpu->hyperv_version_id[3 ] = +hv_cpuid_get_host (cpuid,HV_CPUID_VERSION ,R_EDX ); + + cpu->hv_max_vps =hv_cpuid_get_host (cpuid,HV_CPUID_IMPLEMENT_LIMITS , +R_EAX ); + cpu->hyperv_limits[0 ] = +hv_cpuid_get_host (cpuid,HV_CPUID_IMPLEMENT_LIMITS ,R_EBX ); + cpu->hyperv_limits[1 ] = +hv_cpuid_get_host (cpuid,HV_CPUID_IMPLEMENT_LIMITS ,R_ECX ); + cpu->hyperv_limits[2 ] = +hv_cpuid_get_host (cpuid,HV_CPUID_IMPLEMENT_LIMITS ,R_EDX ); + + cpu->hyperv_spinlock_attempts = +hv_cpuid_get_host (cpuid,HV_CPUID_ENLIGHTMENT_INFO ,R_EBX ); }/* Features */
@@ -1349,10 +1363,8 @@ static int hyperv_handle_properties(CPUState *cs,if (cpu->hyperv_no_nonarch_cs ==ON_OFF_AUTO_ON ) { c->eax |=HV_NO_NONARCH_CORESHARING ; }else if (cpu->hyperv_no_nonarch_cs ==ON_OFF_AUTO_AUTO ) { - c2 =cpuid_find_entry (cpuid,HV_CPUID_ENLIGHTMENT_INFO ,0 ); -if (c2) { - c->eax |= c2->eax &HV_NO_NONARCH_CORESHARING ; - } + c->eax |=hv_cpuid_get_host (cpuid,HV_CPUID_ENLIGHTMENT_INFO ,R_EAX ) & +HV_NO_NONARCH_CORESHARING ; } c = &cpuid_ent[cpuid_i++];
Signature · 1 line
2.30.2
[PULL 15/24] i386: introduce hv_cpuid_cache
In reply to Eduardo HabkostFrom: Vitaly Kuznetsov <[email protected]>
Just like with cpuid_cache, it makes no sense to call KVM_GET_SUPPORTED_HV_CPUID more than once and instead of (ab)using env->features[] and/or trying to keep all the code in one place, it is better to introduce persistent hv_cpuid_cache and hv_cpuid_get_host() accessor to it.
Note, hv_cpuid_get_fw() is converted to using hv_cpuid_get_host() just to be removed later with Hyper-V specific feature words.
Message-Id: <[email protected]>
--- target/i386/kvm/kvm.c | 109 ++++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 53 deletions(-)
target/i386/kvm/kvm.c +56 -53
@@ -129,6 +129,7 @@ static int has_exception_payload;static bool has_msr_mcg_ext_ctl;static struct kvm_cpuid2 *cpuid_cache; +static struct kvm_cpuid2 *hv_cpuid_cache;static struct kvm_msr_list *kvm_feature_msrs;int kvm_has_pit_state2 (void )
@@ -1067,10 +1068,25 @@ static struct kvm_cpuid2 *get_supported_hv_cpuid_legacy(CPUState *cs)return cpuid; } -static uint32_t hv_cpuid_get_host (struct kvm_cpuid2 *cpuid,uint32_t func, -int reg) +static uint32_t hv_cpuid_get_host (CPUState *cs,uint32_t func,int reg) {struct kvm_cpuid_entry2 *entry; +struct kvm_cpuid2 *cpuid; + +if (hv_cpuid_cache) { + cpuid = hv_cpuid_cache; + }else { +if (kvm_check_extension (kvm_state,KVM_CAP_HYPERV_CPUID ) >0 ) { + cpuid =get_supported_hv_cpuid (cs); + }else { + cpuid =get_supported_hv_cpuid_legacy (cs); + } + hv_cpuid_cache = cpuid; + } + +if (!cpuid) { +return 0 ; + } entry =cpuid_find_entry (cpuid, func,0 );if (!entry) {
@@ -1080,7 +1096,7 @@ static uint32_t hv_cpuid_get_host(struct kvm_cpuid2 *cpuid, uint32_t func,return cpuid_entry_get_reg (entry, reg); } -static bool hyperv_feature_supported (struct kvm_cpuid2 *cpuid,int feature) +static bool hyperv_feature_supported (CPUState *cs,int feature) {uint32_t func, bits;int i, reg;
@@ -1095,7 +1111,7 @@ static bool hyperv_feature_supported(struct kvm_cpuid2 *cpuid, int feature)continue ; } -if ((hv_cpuid_get_host (cpuid, func, reg) & bits) != bits) { +if ((hv_cpuid_get_host (cs, func, reg) & bits) != bits) {return false; } }
@@ -1103,8 +1119,7 @@ static bool hyperv_feature_supported(struct kvm_cpuid2 *cpuid, int feature)return true; } -static int hv_cpuid_check_and_set (CPUState *cs,struct kvm_cpuid2 *cpuid, -int feature) +static int hv_cpuid_check_and_set (CPUState *cs,int feature) {X86CPU *cpu =X86_CPU (cs);uint64_t deps;
@@ -1127,7 +1142,7 @@ static int hv_cpuid_check_and_set(CPUState *cs, struct kvm_cpuid2 *cpuid, deps &= ~(1ull << dep_feat); } -if (!hyperv_feature_supported (cpuid, feature)) { +if (!hyperv_feature_supported (cs, feature)) {if (hyperv_feat_enabled (cpu, feature)) { fprintf(stderr, "Hyper-V %s is not supported by kernel\n",
@@ -1180,7 +1195,6 @@ static int hyperv_handle_properties(CPUState *cs, struct kvm_cpuid_entry2 *cpuid_ent) {X86CPU *cpu =X86_CPU (cs); -struct kvm_cpuid2 *cpuid;struct kvm_cpuid_entry2 *c;uint32_t cpuid_i =0 ;int r;
@@ -1206,19 +1220,13 @@ static int hyperv_handle_properties(CPUState *cs, } } -if (kvm_check_extension (cs->kvm_state,KVM_CAP_HYPERV_CPUID ) >0 ) { - cpuid =get_supported_hv_cpuid (cs); - }else { - cpuid =get_supported_hv_cpuid_legacy (cs); - } -if (cpu->hyperv_passthrough) { cpu->hyperv_vendor_id[0 ] = -hv_cpuid_get_host (cpuid,HV_CPUID_VENDOR_AND_MAX_FUNCTIONS ,R_EBX ); +hv_cpuid_get_host (cs,HV_CPUID_VENDOR_AND_MAX_FUNCTIONS ,R_EBX ); cpu->hyperv_vendor_id[1 ] = -hv_cpuid_get_host (cpuid,HV_CPUID_VENDOR_AND_MAX_FUNCTIONS ,R_ECX ); +hv_cpuid_get_host (cs,HV_CPUID_VENDOR_AND_MAX_FUNCTIONS ,R_ECX ); cpu->hyperv_vendor_id[2 ] = -hv_cpuid_get_host (cpuid,HV_CPUID_VENDOR_AND_MAX_FUNCTIONS ,R_EDX ); +hv_cpuid_get_host (cs,HV_CPUID_VENDOR_AND_MAX_FUNCTIONS ,R_EDX ); cpu->hyperv_vendor =g_realloc (cpu->hyperv_vendor,sizeof (cpu->hyperv_vendor_id) +1 ); memcpy(cpu->hyperv_vendor, cpu->hyperv_vendor_id,
@@ -1226,52 +1234,52 @@ static int hyperv_handle_properties(CPUState *cs, cpu->hyperv_vendor[sizeof (cpu->hyperv_vendor_id)] =0 ; cpu->hyperv_interface_id[0 ] = -hv_cpuid_get_host (cpuid,HV_CPUID_INTERFACE ,R_EAX ); +hv_cpuid_get_host (cs,HV_CPUID_INTERFACE ,R_EAX ); cpu->hyperv_interface_id[1 ] = -hv_cpuid_get_host (cpuid,HV_CPUID_INTERFACE ,R_EBX ); +hv_cpuid_get_host (cs,HV_CPUID_INTERFACE ,R_EBX ); cpu->hyperv_interface_id[2 ] = -hv_cpuid_get_host (cpuid,HV_CPUID_INTERFACE ,R_ECX ); +hv_cpuid_get_host (cs,HV_CPUID_INTERFACE ,R_ECX ); cpu->hyperv_interface_id[3 ] = -hv_cpuid_get_host (cpuid,HV_CPUID_INTERFACE ,R_EDX ); +hv_cpuid_get_host (cs,HV_CPUID_INTERFACE ,R_EDX ); cpu->hyperv_version_id[0 ] = -hv_cpuid_get_host (cpuid,HV_CPUID_VERSION ,R_EAX ); +hv_cpuid_get_host (cs,HV_CPUID_VERSION ,R_EAX ); cpu->hyperv_version_id[1 ] = -hv_cpuid_get_host (cpuid,HV_CPUID_VERSION ,R_EBX ); +hv_cpuid_get_host (cs,HV_CPUID_VERSION ,R_EBX ); cpu->hyperv_version_id[2 ] = -hv_cpuid_get_host (cpuid,HV_CPUID_VERSION ,R_ECX ); +hv_cpuid_get_host (cs,HV_CPUID_VERSION ,R_ECX ); cpu->hyperv_version_id[3 ] = -hv_cpuid_get_host (cpuid,HV_CPUID_VERSION ,R_EDX ); +hv_cpuid_get_host (cs,HV_CPUID_VERSION ,R_EDX ); - cpu->hv_max_vps =hv_cpuid_get_host (cpuid,HV_CPUID_IMPLEMENT_LIMITS , + cpu->hv_max_vps =hv_cpuid_get_host (cs,HV_CPUID_IMPLEMENT_LIMITS ,R_EAX ); cpu->hyperv_limits[0 ] = -hv_cpuid_get_host (cpuid,HV_CPUID_IMPLEMENT_LIMITS ,R_EBX ); +hv_cpuid_get_host (cs,HV_CPUID_IMPLEMENT_LIMITS ,R_EBX ); cpu->hyperv_limits[1 ] = -hv_cpuid_get_host (cpuid,HV_CPUID_IMPLEMENT_LIMITS ,R_ECX ); +hv_cpuid_get_host (cs,HV_CPUID_IMPLEMENT_LIMITS ,R_ECX ); cpu->hyperv_limits[2 ] = -hv_cpuid_get_host (cpuid,HV_CPUID_IMPLEMENT_LIMITS ,R_EDX ); +hv_cpuid_get_host (cs,HV_CPUID_IMPLEMENT_LIMITS ,R_EDX ); cpu->hyperv_spinlock_attempts = -hv_cpuid_get_host (cpuid,HV_CPUID_ENLIGHTMENT_INFO ,R_EBX ); +hv_cpuid_get_host (cs,HV_CPUID_ENLIGHTMENT_INFO ,R_EBX ); }/* Features */ - r =hv_cpuid_check_and_set (cs, cpuid,HYPERV_FEAT_RELAXED ); - r |=hv_cpuid_check_and_set (cs, cpuid,HYPERV_FEAT_VAPIC ); - r |=hv_cpuid_check_and_set (cs, cpuid,HYPERV_FEAT_TIME ); - r |=hv_cpuid_check_and_set (cs, cpuid,HYPERV_FEAT_CRASH ); - r |=hv_cpuid_check_and_set (cs, cpuid,HYPERV_FEAT_RESET ); - r |=hv_cpuid_check_and_set (cs, cpuid,HYPERV_FEAT_VPINDEX ); - r |=hv_cpuid_check_and_set (cs, cpuid,HYPERV_FEAT_RUNTIME ); - r |=hv_cpuid_check_and_set (cs, cpuid,HYPERV_FEAT_SYNIC ); - r |=hv_cpuid_check_and_set (cs, cpuid,HYPERV_FEAT_STIMER ); - r |=hv_cpuid_check_and_set (cs, cpuid,HYPERV_FEAT_FREQUENCIES ); - r |=hv_cpuid_check_and_set (cs, cpuid,HYPERV_FEAT_REENLIGHTENMENT ); - r |=hv_cpuid_check_and_set (cs, cpuid,HYPERV_FEAT_TLBFLUSH ); - r |=hv_cpuid_check_and_set (cs, cpuid,HYPERV_FEAT_EVMCS ); - r |=hv_cpuid_check_and_set (cs, cpuid,HYPERV_FEAT_IPI ); - r |=hv_cpuid_check_and_set (cs, cpuid,HYPERV_FEAT_STIMER_DIRECT ); + r =hv_cpuid_check_and_set (cs,HYPERV_FEAT_RELAXED ); + r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_VAPIC ); + r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_TIME ); + r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_CRASH ); + r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_RESET ); + r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_VPINDEX ); + r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_RUNTIME ); + r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_SYNIC ); + r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_STIMER ); + r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_FREQUENCIES ); + r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_REENLIGHTENMENT ); + r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_TLBFLUSH ); + r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_EVMCS ); + r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_IPI ); + r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_STIMER_DIRECT );/* Additional dependencies not covered by kvm_hyperv_properties[] */ if (hyperv_feat_enabled(cpu, HYPERV_FEAT_SYNIC) &&
@@ -1284,8 +1292,7 @@ static int hyperv_handle_properties(CPUState *cs, }if (r) { - r = -ENOSYS ; - goto free; +return -ENOSYS ; } c = &cpuid_ent[cpuid_i++];
@@ -1327,7 +1334,7 @@ static int hyperv_handle_properties(CPUState *cs,if (cpu->hyperv_no_nonarch_cs ==ON_OFF_AUTO_ON ) { c->eax |=HV_NO_NONARCH_CORESHARING ; }else if (cpu->hyperv_no_nonarch_cs ==ON_OFF_AUTO_AUTO ) { - c->eax |=hv_cpuid_get_host (cpuid,HV_CPUID_ENLIGHTMENT_INFO ,R_EAX ) & + c->eax |=hv_cpuid_get_host (cs,HV_CPUID_ENLIGHTMENT_INFO ,R_EAX ) &HV_NO_NONARCH_CORESHARING ; }
@@ -1352,12 +1359,8 @@ static int hyperv_handle_properties(CPUState *cs, c->function =HV_CPUID_NESTED_FEATURES ; c->eax = cpu->hyperv_nested[0 ]; } - r = cpuid_i; -free: -g_free (cpuid); - -return r; +return cpuid_i; }static Error *hv_passthrough_mig_blocker;
Signature · 1 line
2.30.2
[PULL 14/24] i386: drop FEAT_HYPERV feature leaves
In reply to Eduardo HabkostFrom: Vitaly Kuznetsov <[email protected]>
Hyper-V feature leaves are weird. We have some of them in feature_word_info[] array but we don't use feature_word_info magic to enable them. Neither do we use feature_dependencies[] mechanism to validate the configuration as it doesn't allign well with Hyper-V's many-to-many dependency chains. Some of the feature leaves hold not only feature bits, but also values. E.g. FEAT_HV_NESTED_EAX contains both features and the supported Enlightened VMCS range.
Hyper-V features are already represented in 'struct X86CPU' with uint64_t hyperv_features so duplicating them in env->features adds little (or zero) benefits. THe other half of Hyper-V emulation features is also stored with values in hyperv_vendor_id[], hyperv_limits[],... so env->features[] is already incomplete.
Remove Hyper-V feature leaves from env->features[] completely. kvm_hyperv_properties[] is converted to using raw CPUID func/reg pairs for features, this allows us to get rid of hv_cpuid_get_fw() conversion.
Message-Id: <[email protected]>
--- target/i386/cpu.h | 5 -- target/i386/cpu-sysemu.c | 2 +- target/i386/cpu.c | 88 ------------------------------- target/i386/kvm/kvm.c | 108 +++++++++++++-------------------------- 4 files changed, 37 insertions(+), 166 deletions(-)
target/i386/cpu.h +0 -5
@@ -531,11 +531,6 @@ typedef enum FeatureWord {FEAT_C000_0001_EDX ,/* CPUID[C000_0001].EDX */ FEAT_KVM ,/* CPUID[4000_0001].EAX (KVM_CPUID_FEATURES) */ FEAT_KVM_HINTS ,/* CPUID[4000_0001].EDX */ -FEAT_HYPERV_EAX ,/* CPUID[4000_0003].EAX */ -FEAT_HYPERV_EBX ,/* CPUID[4000_0003].EBX */ -FEAT_HYPERV_EDX ,/* CPUID[4000_0003].EDX */ -FEAT_HV_RECOMM_EAX ,/* CPUID[4000_0004].EAX */ -FEAT_HV_NESTED_EAX ,/* CPUID[4000_000A].EAX */ FEAT_SVM ,/* CPUID[8000_000A].EDX */ FEAT_XSAVE ,/* CPUID[EAX=0xd,ECX=1].EAX */ FEAT_6_EAX, /* CPUID[6].EAX */
target/i386/cpu-sysemu.c +1 -1
@@ -312,7 +312,7 @@ GuestPanicInformation *x86_cpu_get_crash_info(CPUState *cs)CPUX86State *env = &cpu->env;GuestPanicInformation *panic_info =NULL ; -if (env->features[FEAT_HYPERV_EDX ] &HV_GUEST_CRASH_MSR_AVAILABLE ) { +if (hyperv_feat_enabled (cpu,HYPERV_FEAT_CRASH )) { panic_info =g_malloc0 (sizeof (GuestPanicInformation)); panic_info->type =GUEST_PANIC_INFORMATION_TYPE_HYPER_V ;
target/i386/cpu.c +0 -88
94 lines not on this page · raw message
target/i386/kvm/kvm.c +36 -72
250 lines not on this page · raw message
Signature · 1 line
2.30.2
[PULL 19/24] i386: adjust the expected KVM_GET_SUPPORTED_HV_CPUID array size
In reply to Eduardo HabkostFrom: Vitaly Kuznetsov <[email protected]>
SYNDBG leaves were recently (Linux-5.8) added to KVM but we haven't updated the expected size of KVM_GET_SUPPORTED_HV_CPUID output in KVM so we now make serveral tries before succeeding. Update the default.
Message-Id: <[email protected]>
--- target/i386/kvm/kvm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
target/i386/kvm/kvm.c +2 -1
@@ -962,7 +962,8 @@ static struct kvm_cpuid2 *try_get_hv_cpuid(CPUState *cs, int max)static struct kvm_cpuid2 *get_supported_hv_cpuid (CPUState *cs) {struct kvm_cpuid2 *cpuid; -int max =7 ;/* 0x40000000..0x40000005, 0x4000000A */ +/* 0x40000000..0x40000005, 0x4000000A, 0x40000080..0x40000080 leaves */ +int max =10 ;int i;/*
Signature · 1 line
2.30.2
[PULL 18/24] i386: switch hyperv_expand_features() to using error_setg()
In reply to Eduardo HabkostFrom: Vitaly Kuznetsov <[email protected]>
Use standard error_setg() mechanism in hyperv_expand_features().
Message-Id: <[email protected]>
--- target/i386/kvm/kvm.c | 101 +++++++++++++++++++++++++----------------- 1 file changed, 61 insertions(+), 40 deletions(-)
target/i386/kvm/kvm.c +61 -40
@@ -1136,7 +1136,7 @@ static bool hyperv_feature_supported(CPUState *cs, int feature)return true; } -static int hv_cpuid_check_and_set (CPUState *cs,int feature) +static int hv_cpuid_check_and_set (CPUState *cs,int feature,Error **errp) {X86CPU *cpu =X86_CPU (cs);uint64_t deps;
@@ -1150,20 +1150,18 @@ static int hv_cpuid_check_and_set(CPUState *cs, int feature)while (deps) { dep_feat =ctz64 (deps);if (!(hyperv_feat_enabled (cpu, dep_feat))) { -fprintf (stderr, -"Hyper-V %s requires Hyper-V %s\n" , - kvm_hyperv_properties[feature].desc, - kvm_hyperv_properties[dep_feat].desc); -return 1 ; +error_setg (errp,"Hyper-V %s requires Hyper-V %s" , + kvm_hyperv_properties[feature].desc, + kvm_hyperv_properties[dep_feat].desc); +return 1 ; } deps &= ~(1ull << dep_feat); }if (!hyperv_feature_supported (cs, feature)) {if (hyperv_feat_enabled (cpu, feature)) { -fprintf (stderr, -"Hyper-V %s is not supported by kernel\n" , - kvm_hyperv_properties[feature].desc); +error_setg (errp,"Hyper-V %s is not supported by kernel" , + kvm_hyperv_properties[feature].desc);return 1 ; }else {return 0 ;
@@ -1210,13 +1208,12 @@ static uint32_t hv_build_cpuid_leaf(CPUState *cs, uint32_t func, int reg)* of 'hv_passthrough' mode and fills the environment with all supported * Hyper-V features. */ -static int hyperv_expand_features (CPUState *cs) +static void hyperv_expand_features (CPUState *cs,Error **errp) {X86CPU *cpu =X86_CPU (cs); -int r;if (!hyperv_enabled (cpu)) -return 0 ; +return ;if (cpu->hyperv_passthrough) { cpu->hyperv_vendor_id[0] =
@@ -1263,37 +1260,60 @@ static int hyperv_expand_features(CPUState *cs) }/* Features */ - r =hv_cpuid_check_and_set (cs,HYPERV_FEAT_RELAXED ); - r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_VAPIC ); - r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_TIME ); - r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_CRASH ); - r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_RESET ); - r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_VPINDEX ); - r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_RUNTIME ); - r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_SYNIC ); - r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_STIMER ); - r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_FREQUENCIES ); - r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_REENLIGHTENMENT ); - r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_TLBFLUSH ); - r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_EVMCS ); - r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_IPI ); - r |=hv_cpuid_check_and_set (cs,HYPERV_FEAT_STIMER_DIRECT ); +if (hv_cpuid_check_and_set (cs,HYPERV_FEAT_RELAXED , errp)) { +return ; + } +if (hv_cpuid_check_and_set (cs,HYPERV_FEAT_VAPIC , errp)) { +return ; + } +if (hv_cpuid_check_and_set (cs,HYPERV_FEAT_TIME , errp)) { +return ; + } +if (hv_cpuid_check_and_set (cs,HYPERV_FEAT_CRASH , errp)) { +return ; + } +if (hv_cpuid_check_and_set (cs,HYPERV_FEAT_RESET , errp)) { +return ; + } +if (hv_cpuid_check_and_set (cs,HYPERV_FEAT_VPINDEX , errp)) { +return ; + } +if (hv_cpuid_check_and_set (cs,HYPERV_FEAT_RUNTIME , errp)) { +return ; + } +if (hv_cpuid_check_and_set (cs,HYPERV_FEAT_SYNIC , errp)) { +return ; + } +if (hv_cpuid_check_and_set (cs,HYPERV_FEAT_STIMER , errp)) { +return ; + } +if (hv_cpuid_check_and_set (cs,HYPERV_FEAT_FREQUENCIES , errp)) { +return ; + } +if (hv_cpuid_check_and_set (cs,HYPERV_FEAT_REENLIGHTENMENT , errp)) { +return ; + } +if (hv_cpuid_check_and_set (cs,HYPERV_FEAT_TLBFLUSH , errp)) { +return ; + } +if (hv_cpuid_check_and_set (cs,HYPERV_FEAT_EVMCS , errp)) { +return ; + } +if (hv_cpuid_check_and_set (cs,HYPERV_FEAT_IPI , errp)) { +return ; + } +if (hv_cpuid_check_and_set (cs,HYPERV_FEAT_STIMER_DIRECT , errp)) { +return ; + }/* Additional dependencies not covered by kvm_hyperv_properties[] */ if (hyperv_feat_enabled (cpu,HYPERV_FEAT_SYNIC ) && !cpu->hyperv_synic_kvm_only && !hyperv_feat_enabled (cpu,HYPERV_FEAT_VPINDEX )) { -fprintf (stderr,"Hyper-V %s requires Hyper-V %s\n" , - kvm_hyperv_properties[HYPERV_FEAT_SYNIC ].desc, - kvm_hyperv_properties[HYPERV_FEAT_VPINDEX ].desc); - r |=1 ; - } - -if (r) { -return -ENOSYS ; +error_setg (errp,"Hyper-V %s requires Hyper-V %s" , + kvm_hyperv_properties[HYPERV_FEAT_SYNIC ].desc, + kvm_hyperv_properties[HYPERV_FEAT_VPINDEX ].desc); } - -return 0 ; }/*
@@ -1528,9 +1548,10 @@ int kvm_arch_init_vcpu(CPUState *cs) env->apic_bus_freq =KVM_APIC_BUS_FREQUENCY ;/* Paravirtualization CPUIDs */ - r =hyperv_expand_features (cs); -if (r <0 ) { -return r; +hyperv_expand_features (cs, &local_err); +if (local_err) { +error_report_err (local_err); +return -ENOSYS ; }if (hyperv_enabled (cpu)) {
Signature · 1 line
2.30.2
[PULL 16/24] i386: split hyperv_handle_properties() into hyperv_expand_features()/hyperv_fill_cpuids()
In reply to Eduardo HabkostFrom: Vitaly Kuznetsov <[email protected]>
The intention is to call hyperv_expand_features() early, before vCPUs are created and use the acquired data later when we set guest visible CPUID data.
Message-Id: <[email protected]>
--- target/i386/kvm/kvm.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-)
target/i386/kvm/kvm.c +24 -10
@@ -1187,16 +1187,15 @@ static uint32_t hv_build_cpuid_leaf(CPUState *cs, uint32_t func, int reg) }/* -* Fill in Hyper-V CPUIDs. Returns the number of entries filled in cpuid_ent in -* case of success, errno < 0 in case of failure and 0 when no Hyper-V -* extentions are enabled. +* Expand Hyper-V CPU features. In partucular, check that all the requested +* features are supported by the host and the sanity of the configuration +* (that all the required dependencies are included). Also, this takes care +* of 'hv_passthrough' mode and fills the environment with all supported +* Hyper-V features. */ -static int hyperv_handle_properties (CPUState *cs, -struct kvm_cpuid_entry2 *cpuid_ent) +static int hyperv_expand_features (CPUState *cs) {X86CPU *cpu =X86_CPU (cs); -struct kvm_cpuid_entry2 *c; -uint32_t cpuid_i =0 ;int r;if (!hyperv_enabled (cpu))
@@ -1295,6 +1294,19 @@ static int hyperv_handle_properties(CPUState *cs,return -ENOSYS ; } +return 0 ; +} + +/* +* Fill in Hyper-V CPUIDs. Returns the number of entries filled in cpuid_ent. +*/ +static int hyperv_fill_cpuids (CPUState *cs, +struct kvm_cpuid_entry2 *cpuid_ent) +{ +X86CPU *cpu =X86_CPU (cs); +struct kvm_cpuid_entry2 *c; +uint32_t cpuid_i =0 ; + c = &cpuid_ent[cpuid_i++]; c->function =HV_CPUID_VENDOR_AND_MAX_FUNCTIONS ; c->eax = hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS) ?
@@ -1502,11 +1514,13 @@ int kvm_arch_init_vcpu(CPUState *cs) env->apic_bus_freq =KVM_APIC_BUS_FREQUENCY ;/* Paravirtualization CPUIDs */ - r =hyperv_handle_properties (cs, cpuid_data.entries); + r =hyperv_expand_features (cs);if (r <0 ) {return r; - }else if (r >0 ) { - cpuid_i = r; + } + +if (hyperv_enabled (cpu)) { + cpuid_i =hyperv_fill_cpuids (cs, cpuid_data.entries); kvm_base =KVM_CPUID_SIGNATURE_NEXT ; has_msr_hv_hypercall = true; }
Signature · 1 line
2.30.2
[PULL 21/24] i386: use global kvm_state in hyperv_enabled() check
In reply to Eduardo HabkostFrom: Vitaly Kuznetsov <[email protected]>
There is no need to use vCPU-specific kvm state in hyperv_enabled() check and we need to do that when feature expansion happens early, before vCPU specific KVM state is created.
Message-Id: <[email protected]>
--- target/i386/kvm/kvm.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
target/i386/kvm/kvm.c +1 -2
@@ -716,8 +716,7 @@ unsigned long kvm_arch_vcpu_id(CPUState *cs)static bool hyperv_enabled (X86CPU *cpu) { -CPUState *cs =CPU (cpu); -return kvm_check_extension (cs->kvm_state,KVM_CAP_HYPERV ) >0 && +return kvm_check_extension (kvm_state,KVM_CAP_HYPERV ) >0 && ((cpu->hyperv_spinlock_attempts !=HYPERV_SPINLOCK_NEVER_NOTIFY ) || cpu->hyperv_features || cpu->hyperv_passthrough); }
Signature · 1 line
2.30.2
[PULL 24/24] sev: add missing firmware error conditions
In reply to Eduardo HabkostFrom: Connor Kuehl <[email protected]>
The SEV userspace header[1] exports a couple of other error conditions that aren't listed in QEMU's SEV implementation, so let's just round out the list.
[1] linux-headers/linux/psp-sev.h
Message-Id: <[email protected]>
--- target/i386/sev.c | 2 ++ 1 file changed, 2 insertions(+)
target/i386/sev.c +2 -0
@@ -110,6 +110,8 @@ static const char *const sev_fw_errlist[] = { [SEV_RET_HWSEV_RET_UNSAFE] = "Hardware unsafe", [SEV_RET_UNSUPPORTED] = "Feature not supported", [SEV_RET_INVALID_PARAM] = "Invalid parameter", + [SEV_RET_RESOURCE_LIMIT] = "Required firmware resource depleted", + [SEV_RET_SECURE_DATA_INVALID] = "Part-specific integrity check failure", };#define SEV_FW_MAX_ERROR ARRAY_SIZE(sev_fw_errlist)
Signature · 1 line
2.30.2
Peter Maydell
AppliedQuoted 24 lines · Eduardo Habkost
The following changes since commit
52848929b70dcf92a68aedcfd90207be81ba3274:Merge remote-tracking branch 'remotes/kraxel/tags/usb-20210528-pull-request' into staging (2021-05-30 20:10:30 +0100)
are available in the Git repository at:
https://gitlab.com/ehabkost/qemu.git tags/x86-next-pull-request
for you to fetch changes up to
d47b85502b92fe8015d38904cde54eb4d3364326:sev: add missing firmware error conditions (2021-06-01 09:32:48 -0400)
----------------------------------------------------------------
x86 queue, 2021-06-01Features:
* Add CPU model versions supporting 'xsaves' (Vitaly Kuznetsov)
* Support AVX512 ZMM regs dump (Robert Hoo)Bug fixes:
* Use better matching family/model/stepping for generic CPUs (Daniel P. Berrangé)
Quoted 7 lines
Cleanups:
* Hyper-V feature initialization cleanup (Vitaly Kuznetsov)
* SEV firmware error list touchups (Connor Kuehl)
* Constify CPUCaches and X86CPUDefinition (Philippe Mathieu-Daudé)
* Document when features can be added tokvm_default_props(Eduardo Habkost)
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/6.1
for any user-visible changes.
-- PMM