(Mostly) x86 fixes for QEMU 7.0.0-rc2
The following changes since commit 15ef89d2a1a7b93845a6b09c2ee8e1979f6eb30b:
Update version for v7.0.0-rc1 release (2022-03-22 22:58:44 +0000)
are available in the Git repository at:
https://gitlab.com/bonzini/qemu.git tags/for-upstream
for you to fetch changes up to 9584d3d00a454f47b0341465142bcf0735d734ae:
build: disable fcf-protection on -march=486 -m16 (2022-03-24 18:44:07 +0100)
----------------------------------------------------------------
Bugfixes.
----------------------------------------------------------------
Christian Ehrhardt (1):
build: disable fcf-protection on -march=486 -m16
Paolo Bonzini (4):
KVM: x86: workaround invalid CPUID[0xD,9] info on some AMD processors
configure: remove dead int128 test
target/i386: tcg: high bits SSE cmp operation must be ignored target/i386: properly reset TSC on reset
Philippe Mathieu-Daudé (1):
target/i386/kvm: Free xsave_buf when destroying vCPU
luofei (1):
i386: Set MCG_STATUS_RIPV bit for mce SRAR error
configure | 18 ------------------ pc-bios/optionrom/Makefile | 4 ++++ target/i386/cpu.c | 17 +++++++++++++++-- target/i386/cpu.h | 4 +++- target/i386/kvm/kvm-cpu.c | 19 ++++++++++++------- target/i386/kvm/kvm.c | 4 +++- target/i386/tcg/translate.c | 6 ++---- 7 files changed, 39 insertions(+), 33 deletions(-)
Signature · 1 line
2.35.1
[PULL 3/7] KVM: x86: workaround invalid CPUID[0xD, 9] info on some AMD processors
Some AMD processors expose the PKRU extended save state even if they do not have the related PKU feature in CPUID. Worse, when they do they report a size of 64, whereas the expected size of the PKRU extended save state is 8, therefore the esa->size == eax assertion does not hold.
The state is already ignored by KVM_GET_SUPPORTED_CPUID because it was not enabled in the host XCR0. However, QEMU kvm_cpu_xsave_init() runs before QEMU invokes arch_prctl() to enable dynamically-enabled save states such as XTILEDATA, and KVM_GET_SUPPORTED_CPUID hides save states that have yet to be enabled. Therefore, kvm_cpu_xsave_init() needs to consult the host CPUID instead of KVM_GET_SUPPORTED_CPUID, and dies with an assertion failure.
When setting up the ExtSaveArea array to match the host, ignore features that KVM does not report as supported. This will cause QEMU to skip the incorrect CPUID leaf instead of tripping the assertion.
--- target/i386/cpu.c | 4 ++-- target/i386/cpu.h | 2 ++ target/i386/kvm/kvm-cpu.c | 19 ++++++++++++------- 3 files changed, 16 insertions(+), 9 deletions(-)
target/i386/cpu.c +2 -2
@@ -4981,8 +4981,8 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp)return cpu_list; } -static uint64_t x86_cpu_get_supported_feature_word (FeatureWord w, -bool migratable_only) +uint64_t x86_cpu_get_supported_feature_word (FeatureWord w, +bool migratable_only) {FeatureWordInfo *wi = &feature_word_info[w];uint64_t r =0 ;
target/i386/cpu.h +2 -0
@@ -606,6 +606,8 @@ typedef enum FeatureWord { } FeatureWord;typedef uint64_t FeatureWordArray [FEATURE_WORDS ]; +uint64_t x86_cpu_get_supported_feature_word (FeatureWord w, +bool migratable_only);/* cpuid_features bits */ #define CPUID_FP87 (1U << 0)
target/i386/kvm/kvm-cpu.c +12 -7
@@ -99,13 +99,18 @@ static void kvm_cpu_xsave_init(void)for (i =XSTATE_SSE_BIT +1 ; i <XSAVE_STATE_AREA_COUNT ; i++) {ExtSaveArea *esa = &x86_ext_save_areas[i]; -if (esa->size) { -host_cpuid (0xd , i, &eax, &ebx, &ecx, &edx); -if (eax !=0 ) { -assert (esa->size == eax); - esa->offset = ebx; - esa->ecx = ecx; - } +if (!esa->size) { +continue ; + } +if ((x86_cpu_get_supported_feature_word (esa->feature, false) & esa->bits) + != esa->bits) { +continue ; + } +host_cpuid (0xd , i, &eax, &ebx, &ecx, &edx); +if (eax !=0 ) { +assert (esa->size == eax); + esa->offset = ebx; + esa->ecx = ecx; } } }
Signature · 1 line
2.35.1
[PULL 2/7] i386: Set MCG_STATUS_RIPV bit for mce SRAR error
In reply to Paolo BonziniFrom: luofei <[email protected]>
In the physical machine environment, when a SRAR error occurs, the IA32_MCG_STATUS RIPV bit is set, but qemu does not set this bit. When qemu injects an SRAR error into virtual machine, the virtual machine kernel just call do_machine_check() to kill the current task, but not call memory_failure() to isolate the faulty page, which will cause the faulty page to be allocated and used repeatedly. If used by the virtual machine kernel, it will cause the virtual machine to crash
Message-Id: <[email protected]>
--- target/i386/kvm/kvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/kvm/kvm.c +1 -1
@@ -569,7 +569,7 @@ static void kvm_mce_inject(X86CPU *cpu, hwaddr paddr, int code)if (code ==BUS_MCEERR_AR ) { status |=MCI_STATUS_AR |0x134 ; - mcg_status |=MCG_STATUS_EIPV ; + mcg_status |=MCG_STATUS_RIPV |MCG_STATUS_EIPV ; }else { status |=0xc0 ; mcg_status |=MCG_STATUS_RIPV ;
Signature · 1 line
2.35.1
[PULL 1/7] target/i386/kvm: Free xsave_buf when destroying vCPU
In reply to Paolo BonziniFrom: Philippe Mathieu-Daudé <[email protected]>
Fix vCPU hot-unplug related leak reported by Valgrind:
==132362== 4,096 bytes in 1 blocks are definitely lost in loss record 8,440 of 8,549
==132362== at 0x4C3B15F: memalign (vg_replace_malloc.c:1265) ==132362== by 0x4C3B288: posix_memalign (vg_replace_malloc.c:1429) ==132362== by 0xB41195: qemu_try_memalign (memalign.c:53) ==132362== by 0xB41204: qemu_memalign (memalign.c:73) ==132362== by 0x7131CB: kvm_init_xsave (kvm.c:1601) ==132362== by 0x7148ED: kvm_arch_init_vcpu (kvm.c:2031) ==132362== by 0x91D224: kvm_init_vcpu (kvm-all.c:516) ==132362== by 0x9242C9: kvm_vcpu_thread_fn (kvm-accel-ops.c:40) ==132362== by 0xB2EB26: qemu_thread_start (qemu-thread-posix.c:556) ==132362== by 0x7EB2159: start_thread (in /usr/lib64/libpthread-2.28.so) ==132362== by 0x9D45DD2: clone (in /usr/lib64/libc-2.28.so)
Message-Id: <[email protected]>
--- target/i386/kvm/kvm.c | 2 ++ 1 file changed, 2 insertions(+)
target/i386/kvm/kvm.c +2 -0
@@ -2081,6 +2081,8 @@ int kvm_arch_destroy_vcpu(CPUState *cs)X86CPU *cpu =X86_CPU (cs);CPUX86State *env = &cpu->env; +g_free (env->xsave_buf); +if (cpu->kvm_msr_buf) {g_free (cpu->kvm_msr_buf); cpu->kvm_msr_buf =NULL ;
Signature · 1 line
2.35.1
[PULL 6/7] target/i386: properly reset TSC on reset
In reply to Paolo BonziniSome versions of Windows hang on reboot if their TSC value is greater than 2^54. The calibration of the Hyper-V reference time overflows and fails; as a result the processors' clock sources are out of sync.
The issue is that the TSC _should_ be reset to 0 on CPU reset and QEMU tries to do that. However, KVM special cases writing 0 to the TSC and thinks that QEMU is trying to hot-plug a CPU, which is correct the first time through but not later. Thwart this valiant effort and reset the TSC to 1 instead, but only if the CPU has been run once.
For this to work, env->tsc has to be moved to the part of CPUArchState that is not zeroed at the beginning of x86_cpu_reset.
Supersedes: <[email protected]>
--- target/i386/cpu.c | 13 +++++++++++++ target/i386/cpu.h | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-)
target/i386/cpu.c +13 -0
@@ -5931,6 +5931,19 @@ static void x86_cpu_reset(DeviceState *dev) env->xstate_bv =0 ; env->pat =0x0007040600070406ULL ; + +if (kvm_enabled ()) { +/* +* KVM handles TSC = 0 specially and thinks we are hot-plugging +* a new CPU, use 1 instead to force a reset. +*/ +if (env->tsc !=0 ) { + env->tsc =1 ; + } + }else { + env->tsc =0 ; + } + env->msr_ia32_misc_enable =MSR_IA32_MISC_ENABLE_DEFAULT ;if (env->features[FEAT_1_ECX ] &CPUID_EXT_MONITOR ) { env->msr_ia32_misc_enable |=MSR_IA32_MISC_ENABLE_MWAIT ;
target/i386/cpu.h +1 -1
@@ -1554,7 +1554,6 @@ typedef struct CPUArchState {target_ulong kernelgsbase;#endif -uint64_t tsc;uint64_t tsc_adjust;uint64_t tsc_deadline;uint64_t tsc_aux;
@@ -1708,6 +1707,7 @@ typedef struct CPUArchState {int64_t tsc_khz;int64_t user_tsc_khz;/* for sanity check only */ uint64_t apic_bus_freq; +uint64_t tsc;#if defined(CONFIG_KVM ) || defined(CONFIG_HVF )void *xsave_buf;uint32_t xsave_buf_len;
Signature · 1 line
2.35.1
[PULL 4/7] configure: remove dead int128 test
In reply to Paolo Bonzini--- configure | 18 ------------------ 1 file changed, 18 deletions(-)
configure +0 -18
@@ -2463,24 +2463,6 @@ else # "$safe_stack" = "" fi fi -######################################## -# check if __[u]int128_t is usable. - -int128=no -cat > $TMPC << EOF -__int128_t a; -__uint128_t b; -int main (void) { - a = a + b; - b = a * b; - a = a * a; - return 0; -} -EOF -if compile_prog "" "" ; then - int128=yes -fi - ######################################## # check if ccache is interfering with # semantic analysis of macros
Signature · 1 line
2.35.1
[PULL 5/7] target/i386: tcg: high bits SSE cmp operation must be ignored
In reply to Paolo BonziniHigh bits in the immediate operand of SSE comparisons are ignored, they do not result in an undefined opcode exception. This is mentioned explicitly in the Intel documentation.
--- target/i386/tcg/translate.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
target/i386/tcg/translate.c +2 -4
@@ -4509,10 +4509,8 @@ static void gen_sse(CPUX86State *env, DisasContext *s, int b,sse_fn_ppi (s->ptr0, s->ptr1,tcg_const_i32 (val));break ;case 0xc2 : -/* compare insns */ - val =x86_ldub_code (env, s); -if (val >=8 ) - goto unknown_op; +/* compare insns, bits 7:3 (7:5 for AVX) are ignored */ + val =x86_ldub_code (env, s) &7 ; sse_fn_epp = sse_op_table4[val][b1];tcg_gen_addi_ptr (s->ptr0, cpu_env, op1_offset);
Signature · 1 line
2.35.1
[PULL 7/7] build: disable fcf-protection on -march=486 -m16
In reply to Paolo BonziniFrom: Christian Ehrhardt <[email protected]>
Some of the roms build with -march=i486 -m16 which is incompatible with -fcf-protection. That in turn is can be set by default, for example in Ubuntu [1].
That causes:
cc1: error: ‘-fcf-protection’ is not compatible with this target
This won't work on -march=i486 -m16 and no matter if set or not we can override it to "none" if the option is known to the compiler to be able to build reliably.
[1]: https://wiki.ubuntu.com/ToolChain/CompilerFlags#A-fcf-protection
Message-Id: <[email protected]>
--- pc-bios/optionrom/Makefile | 4 ++++ 1 file changed, 4 insertions(+)
pc-bios/optionrom/Makefile +4 -0
@@ -14,6 +14,10 @@ cc-option = $(if $(shell $(CC) $1 -c -o /dev/null -xc /dev/null >/dev/null 2>&1 override CFLAGS += -march=i486 -Wall +# If -fcf-protection is enabled in flags or compiler defaults that will +# conflict with -march=i486 +override CFLAGS += $(call cc-option, -fcf-protection=none) + # Flags for dependency generation override CPPFLAGS += -MMD -MP -MT $@ -MF $(@D)/$(*F).d
Signature · 1 line
2.35.1
Peter Maydell
AppliedQuoted 7 lines · Paolo Bonzini
The following changes since commit
15ef89d2a1a7b93845a6b09c2ee8e1979f6eb30b:Update version for v7.0.0-rc1 release (2022-03-22 22:58:44 +0000)
are available in the Git repository at:
Quoted 9 lines
https://gitlab.com/bonzini/qemu.git tags/for-upstream
for you to fetch changes up to
9584d3d00a454f47b0341465142bcf0735d734ae:build: disable fcf-protection on -march=486 -m16 (2022-03-24 18:44:07 +0100)
----------------------------------------------------------------
Bugfixes.
Applied, thanks.
Please update the changelog at https://wiki.qemu.org/ChangeLog/7.0
for any user-visible changes.
-- PMM