i386, scsi. hostmem fixes for 2024-06-08
Subsystems (2)
The following changes since commit f1572ab94738bd5787b7badcd4bd93a3657f0680:
Merge tag 'for-upstream' of https://gitlab.com/bonzini/qemu into staging (2024-06-05 07:45:23 -0700)
are available in the Git repository at:
https://gitlab.com/bonzini/qemu.git tags/for-upstream
for you to fetch changes up to fc00123f3abeb027cd51eb58ea8845377794b3bc:
python: mkvenv: remove ensure command (2024-06-08 10:33:39 +0200)
----------------------------------------------------------------
* scsi-disk: Don't silently truncate serial number
* backends/hostmem: Report error on unavailable qemu_madvise() features or unaligned memory sizes
* target/i386: fixes and documentation for INHIBIT_IRQ/TF/RF and debugging
* i386/hvf: Adds support for INVTSC cpuid bit
* i386/hvf: Fixes for dirty memory tracking
* i386/hvf: Use hv_vcpu_interrupt() and hv_vcpu_run_until()
* hvf: Cleanups
* stubs: fixes for --disable-system build
* i386/kvm: support for FRED
* i386/kvm: fix MCE handling on AMD hosts
----------------------------------------------------------------
John Allen (3):
i386: Fix MCE support for AMD hosts
i386: Add support for SUCCOR feature
i386: Add support for overflow recovery
Kevin Wolf (1):
scsi-disk: Don't silently truncate serial number
Mark Cave-Ayland (4):
target/i386: use local X86DecodedOp in gen_POP() target/i386: use gen_writeback() within gen_POP() target/i386: fix SP when taking a memory fault during POP target/i386: fix size of EBP writeback in gen_enter()
Michal Privoznik (4):
meson: Don't even detect posix_madvise() on Darwin
osdep: Make qemu_madvise() to set errno in all cases
osdep: Make qemu_madvise() return ENOSYS on unsupported OSes backends/hostmem: Report error when memory size is unaligned
Paolo Bonzini (16):
target/i386: fix pushed value of EFLAGS.RF
target/i386: fix implementation of ICEBP
target/i386: cleanup HLT helpers
target/i386: cleanup PAUSE helpers
target/i386: implement DR7.GD
target/i386: disable/enable breakpoints on vmentry/vmexit target/i386: fix INHIBIT_IRQ/TF/RF handling for VMRUN target/i386: fix INHIBIT_IRQ/TF/RF handling for PAUSE target/i386: fix TF/RF handling for HLT
target/i386: document incorrect semantics of watchpoint following MOV/POP SS target/i386: document use of DISAS_NORETURN
machine: default -M mem-merge to off is QEMU_MADV_MERGEABLE is not available machine, hostmem: improve error messages for unsupported features
hostmem: simplify the code for merge and dump properties
Revert "python: use vendored tomli"
python: mkvenv: remove ensure command
Phil Dennis-Jordan (7):
i386/hvf: Adds support for INVTSC cpuid bit
i386/hvf: Fixes some compilation warnings
hvf: Consistent types for vCPU handles
i386/hvf: Fixes dirty memory tracking by page granularity RX->RWX change i386/hvf: In kick_vcpu use hv_vcpu_interrupt to force exit i386/hvf: Updates API usage to use modern vCPU run function
hvf: Makes assert_hvf_ok report failed expression
Xin Li (5):
target/i386: add support for FRED in CPUID enumeration target/i386: mark CR4.FRED not reserved
vmxcap: add support for VMX FRED controls target/i386: enumerate VMX nested-exception support target/i386: Add get/set/migrate support for FRED MSRs
Zhao Liu (2):
stubs/meson: Fix qemuutil build when --disable-system
docs: i386: pc: Avoid mentioning limit of maximum vCPUs
docs/devel/build-system.rst | 13 ++-- docs/system/target-i386-desc.rst.inc | 3 +- configure | 4 -- meson.build | 14 ++-- include/sysemu/hostmem.h | 2 +- include/sysemu/hvf_int.h | 9 ++- target/i386/cpu.h | 53 ++++++++++++++- target/i386/helper.h | 5 +- target/i386/hvf/vmx.h | 3 +- target/i386/tcg/helper-tcg.h | 13 +++- accel/hvf/hvf-accel-ops.c | 2 +- accel/hvf/hvf-all.c | 51 ++++++-------- backends/hostmem-epc.c | 1 + backends/hostmem-file.c | 1 + backends/hostmem-memfd.c | 1 + backends/hostmem.c | 36 +++++++--- hw/core/machine.c | 11 ++- hw/scsi/scsi-disk.c | 20 +++++- target/i386/cpu.c | 33 ++++++++- target/i386/helper.c | 4 ++ target/i386/hvf/hvf.c | 47 ++++++++++++- target/i386/hvf/x86_cpuid.c | 4 ++ target/i386/hvf/x86_decode.c | 2 +- target/i386/hvf/x86_emu.c | 4 +- target/i386/kvm/kvm.c | 90 ++++++++++++++++++++++--- target/i386/machine.c | 28 ++++++++ target/i386/tcg/excp_helper.c | 20 ++++++ target/i386/tcg/misc_helper.c | 14 ++-- target/i386/tcg/seg_helper.c | 49 ++++++++++++-- target/i386/tcg/sysemu/bpt_helper.c | 18 +++++ target/i386/tcg/sysemu/misc_helper.c | 17 ++--- target/i386/tcg/sysemu/seg_helper.c | 17 ++++- target/i386/tcg/sysemu/svm_helper.c | 71 ++++++++++++------- target/i386/tcg/translate.c | 39 ++++++++++- util/osdep.c | 9 ++- target/i386/tcg/decode-new.c.inc | 19 +++++- target/i386/tcg/emit.c.inc | 37 +++++----- python/scripts/mkvenv.py | 105 ----------------------------- python/scripts/vendor.py | 3 - python/wheels/tomli-2.0.1-py3-none-any.whl | Bin 12757 -> 0 bytes scripts/kvm/vmxcap | 13 ++++ stubs/meson.build | 8 +-- 42 files changed, 617 insertions(+), 276 deletions(-) delete mode 100644 python/wheels/tomli-2.0.1-py3-none-any.whl
Signature · 1 line
2.45.1
[PULL 10/42] target/i386: document incorrect semantics of watchpoint following MOV/POP SS
--- target/i386/tcg/sysemu/bpt_helper.c | 6 ++++++ 1 file changed, 6 insertions(+)
target/i386/tcg/sysemu/bpt_helper.c +6 -0
@@ -215,6 +215,12 @@ void breakpoint_handler(CPUState *cs)if (cs->watchpoint_hit->flags &BP_CPU ) { cs->watchpoint_hit =NULL ;if (check_hw_breakpoints (env, false)) { +/* +* FIXME: #DB should be delayed by one instruction if +* INHIBIT_IRQ is set (STI cannot trigger a watchpoint). +* The delayed #DB should also fuse with one generated +* by ICEBP (aka INT1). +*/ raise_exception (env,EXCP01_DB ); }else {cpu_loop_exit_noexc (cs);
Signature · 1 line
2.45.1
[PULL 02/42] target/i386: fix implementation of ICEBP
In reply to Paolo BonziniICEBP generates a trap-like exception, while gen_exception() produces a fault. Resurrect gen_update_eip_next() to implement the desired semantics.
--- target/i386/helper.h | 1 + target/i386/tcg/helper-tcg.h | 12 +++++++++++- target/i386/tcg/excp_helper.c | 20 ++++++++++++++++++++ target/i386/tcg/translate.c | 13 +++++++++++++ target/i386/tcg/emit.c.inc | 5 ++++- 5 files changed, 49 insertions(+), 2 deletions(-)
target/i386/helper.h +1 -0
@@ -56,6 +56,7 @@ DEF_HELPER_2(sysret, void, env, int) DEF_HELPER_FLAGS_2(pause, TCG_CALL_NO_WG, noreturn, env, int) DEF_HELPER_FLAGS_3(raise_interrupt, TCG_CALL_NO_WG, noreturn, env, int, int) DEF_HELPER_FLAGS_2(raise_exception, TCG_CALL_NO_WG, noreturn, env, int) +DEF_HELPER_FLAGS_1(icebp, TCG_CALL_NO_WG, noreturn, env) DEF_HELPER_3(boundw, void, env, tl, int)DEF_HELPER_3 (boundl, void, env, tl, int)
target/i386/tcg/helper-tcg.h +11 -1
@@ -111,7 +111,17 @@ int exception_has_error_code(int intno);/* smm_helper.c */ void do_smm_enter (X86CPU *cpu); -/* bpt_helper.c */ +/* sysemu/bpt_helper.c */ bool check_hw_breakpoints (CPUX86State *env,bool force_dr6_update); +/* +* Do the tasks usually performed by gen_eob(). Callers of this function +* should also handle TF as appropriate. +*/ +static inline void do_end_instruction (CPUX86State *env) +{ +/* needed if sti is just before */ + env->hflags &= ~HF_INHIBIT_IRQ_MASK ; + env->eflags &= ~HF_RF_MASK ; +}#endif /* I386_HELPER_TCG_H */
target/i386/tcg/excp_helper.c +20 -0
@@ -140,6 +140,26 @@ G_NORETURN void raise_exception_ra(CPUX86State *env, int exception_index,raise_interrupt2 (env, exception_index,0 ,0 ,0 , retaddr); } +G_NORETURN void helper_icebp(CPUX86State *env) +{ +CPUState *cs =env_cpu (env); + +do_end_instruction (env); + +/* +* INT1 aka ICEBP generates a trap-like #DB, but it is pretty special. +* +* "Although the ICEBP instruction dispatches through IDT vector 1, +* that event is not interceptable by means of the #DB exception +* intercept". Instead there is a separate fault-like ICEBP intercept. +*/ + cs->exception_index =EXCP01_DB ; + env->error_code =0 ; + env->exception_is_int =0 ; + env->exception_next_eip = env->eip; +cpu_loop_exit (cs); +} + G_NORETURN void handle_unaligned_access(CPUX86State *env, vaddr vaddr,MMUAccessType access_type,uintptr_t retaddr)
target/i386/tcg/translate.c +13 -0
@@ -549,6 +549,19 @@ static inline void gen_op_st_rm_T0_A0(DisasContext *s, int idx, int d) } } +static void gen_update_eip_next (DisasContext *s) +{ +assert (s->pc_save !=-1 ); +if (tb_cflags (s->base.tb) &CF_PCREL ) { +tcg_gen_addi_tl (cpu_eip, cpu_eip, s->pc - s->pc_save); + }else if (CODE64 (s)) { +tcg_gen_movi_tl (cpu_eip, s->pc); + }else { +tcg_gen_movi_tl (cpu_eip, (uint32_t )(s->pc - s->cs_base)); + } + s->pc_save = s->pc; +} +static void gen_update_eip_cur (DisasContext *s) {assert (s->pc_save !=-1 );
target/i386/tcg/emit.c.inc +4 -1
@@ -1858,7 +1858,10 @@ static void gen_INT(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) static void gen_INT1(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) { - gen_exception(s, EXCP01_DB); + gen_update_cc_op(s); + gen_update_eip_next(s); + gen_helper_icebp(tcg_env); + s->base.is_jmp = DISAS_NORETURN; } static void gen_INT3(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode)
Signature · 1 line
2.45.1
[PULL 20/42] backends/hostmem: Report error when memory size is unaligned
In reply to Paolo BonziniFrom: Michal Privoznik <[email protected]>
If memory-backend-{file,ram} has a size that's not aligned to underlying page size it is not only wasteful, but also may lead to hard to debug behaviour. For instance, in case memory-backend-file and hugepages, madvise() and mbind() fail. Rightfully so, page is the smallest unit they can work with. And even though an error is reported, the root cause it not very clear:
qemu-system-x86_64: Couldn't set property 'dump' on 'memory-backend-file': Invalid argument
After this commit:
qemu-system-x86_64: backend 'memory-backend-file' memory size must be multiple of 2 MiB
Message-ID: <b5b9f9c6bba07879fb43f3c6f496c69867ae3716.1717584048.git.mprivozn@redhat.com>
--- include/sysemu/hostmem.h | 2 +- backends/hostmem-epc.c | 1 + backends/hostmem-file.c | 1 + backends/hostmem-memfd.c | 1 + backends/hostmem.c | 10 ++++++++++ 5 files changed, 14 insertions(+), 1 deletion(-)
include/sysemu/hostmem.h +1 -1
@@ -74,7 +74,7 @@ struct HostMemoryBackend {uint64_t size;bool merge, dump, use_canonical_path;bool prealloc, is_mapped, share, reserve; -bool guest_memfd; +bool guest_memfd, aligned;uint32_t prealloc_threads;ThreadContext *prealloc_context;DECLARE_BITMAP (host_nodes,MAX_NODES +1 );
backends/hostmem-epc.c +1 -0
@@ -36,6 +36,7 @@ sgx_epc_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)return false; } + backend->aligned = true; name =object_get_canonical_path (OBJECT (backend)); ram_flags = (backend->share ?RAM_SHARED :0 ) |RAM_PROTECTED ; return memory_region_init_ram_from_fd(&backend->mr, OBJECT(backend), name,
backends/hostmem-file.c +1 -0
@@ -80,6 +80,7 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)g_assert_not_reached (); } + backend->aligned = true; name =host_memory_backend_get_name (backend); ram_flags = backend->share ?RAM_SHARED :0 ; ram_flags |= fb->readonly ?RAM_READONLY_FD :0 ;
backends/hostmem-memfd.c +1 -0
@@ -52,6 +52,7 @@ memfd_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)return false; } + backend->aligned = true; name =host_memory_backend_get_name (backend); ram_flags = backend->share ?RAM_SHARED :0 ; ram_flags |= backend->reserve ?0 :RAM_NORESERVE ;
backends/hostmem.c +10 -0
@@ -20,6 +20,7 @@#include "qom/object_interfaces.h" #include "qemu/mmap-alloc.h" #include "qemu/madvise.h" +#include "qemu/cutils.h" #include "hw/qdev-core.h" #ifdef CONFIG_NUMA
@@ -325,6 +326,7 @@ host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)HostMemoryBackendClass *bc =MEMORY_BACKEND_GET_CLASS (uc);void *ptr;uint64_t sz; +size_t pagesize;bool async = !phase_check (PHASE_LATE_BACKENDS_CREATED );if (!bc->alloc) {
@@ -336,6 +338,14 @@ host_memory_backend_memory_complete(UserCreatable *uc, Error **errp) ptr =memory_region_get_ram_ptr (&backend->mr); sz =memory_region_size (&backend->mr); + pagesize =qemu_ram_pagesize (backend->mr.ram_block); + +if (backend->aligned && !QEMU_IS_ALIGNED (sz, pagesize)) { + g_autofree char *pagesize_str = size_to_str(pagesize); +error_setg (errp,"backend '%s' memory size must be multiple of %s" , +object_get_typename (OBJECT (uc)), pagesize_str); +return ; + }if (backend->merge) {qemu_madvise (ptr, sz,QEMU_MADV_MERGEABLE );
Signature · 1 line
2.45.1
[PULL 12/42] target/i386: use local X86DecodedOp in gen_POP()
In reply to Paolo BonziniFrom: Mark Cave-Ayland <[email protected]>
This will make subsequent changes a little easier to read.
Message-ID: <[email protected]>
--- target/i386/tcg/emit.c.inc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
target/i386/tcg/emit.c.inc +4 -2
@@ -2575,11 +2575,13 @@ static void gen_PMOVMSKB(DisasContext *s, CPUX86State *env, X86DecodedInsn *deco static void gen_POP(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) { + X86DecodedOp *op = &decode->op[0]; MemOp ot = gen_pop_T0(s); - if (decode->op[0].has_ea) { + + if (op->has_ea) { /* NOTE: order is important for MMU exceptions */ gen_op_st_v(s, ot, s->T0, s->A0); - decode->op[0].unit = X86_OP_SKIP; + op->unit = X86_OP_SKIP; } /* NOTE: writing back registers after update is important for pop %sp */ gen_pop_update(s, ot);
Signature · 1 line
2.45.1
[PULL 09/42] target/i386: fix TF/RF handling for HLT
In reply to Paolo BonziniHLT uses DISAS_NORETURN because the corresponding helper calls cpu_loop_exit(). However, while gen_eob() clears HF_RF_MASK and synthesizes a #DB exception if single-step is active, none of this is done by HLT. Note that the single-step trap is generated after the halt is finished.
--- target/i386/tcg/sysemu/misc_helper.c | 2 +- target/i386/tcg/sysemu/seg_helper.c | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-)
target/i386/tcg/sysemu/misc_helper.c +1 -1
@@ -520,7 +520,7 @@ G_NORETURN void helper_hlt(CPUX86State *env) {CPUState *cs =env_cpu (env); - env->hflags &= ~HF_INHIBIT_IRQ_MASK ;/* needed if sti is just before */ +do_end_instruction (env); cs->halted =1 ; cs->exception_index =EXCP_HLT ;cpu_loop_exit (cs);
target/i386/tcg/sysemu/seg_helper.c +14 -3
@@ -130,15 +130,26 @@ void x86_cpu_do_interrupt(CPUState *cs)bool x86_cpu_exec_halt (CPUState *cpu) { -if (cpu->interrupt_request &CPU_INTERRUPT_POLL ) { -X86CPU *x86_cpu =X86_CPU (cpu); +X86CPU *x86_cpu =X86_CPU (cpu); +CPUX86State *env = &x86_cpu->env; +if (cpu->interrupt_request &CPU_INTERRUPT_POLL ) {bql_lock ();apic_poll_irq (x86_cpu->apic_state);cpu_reset_interrupt (cpu,CPU_INTERRUPT_POLL );bql_unlock (); } -return cpu_has_work (cpu); + +if (!cpu_has_work (cpu)) { +return false; + } + +/* Complete HLT instruction. */ +if (env->eflags &TF_MASK ) { + env->dr[6 ] |=DR6_BS ; +do_interrupt_all (x86_cpu,EXCP01_DB ,0 ,0 , env->eip,0 ); + } +return true; }bool x86_need_replay_interrupt (int interrupt_request)
Signature · 1 line
2.45.1
[PULL 27/42] hvf: Consistent types for vCPU handles
In reply to Paolo BonziniFrom: Phil Dennis-Jordan <[email protected]>
macOS Hypervisor.framework uses different types for identifying vCPUs, hv_vcpu_t or hv_vcpuid_t, depending on host architecture. They are not just differently named typedefs for the same primitive type, but reference different-width integers.
Instead of using an integer type and casting where necessary, this change introduces a typedef which resolves the active architecture’s hvf typedef. It also removes a now-unnecessary cast.
Message-ID: <[email protected]>
--- include/sysemu/hvf_int.h | 4 +++- accel/hvf/hvf-accel-ops.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-)
include/sysemu/hvf_int.h +3 -1
@@ -13,8 +13,10 @@#ifdef __aarch64__#include <Hypervisor/Hypervisor.h> +typedef hv_vcpu_t hvf_vcpuid ;#else #include <Hypervisor/hv.h> +typedef hv_vcpuid_t hvf_vcpuid ;#endif /* hvf_slot flags */
@@ -50,7 +52,7 @@ struct HVFState {extern HVFState *hvf_state;struct AccelCPUState { -uint64_t fd; +hvf_vcpuid fd;void *exit;bool vtimer_masked;sigset_t unblock_ipi_mask;
accel/hvf/hvf-accel-ops.c +1 -1
@@ -400,7 +400,7 @@ static int hvf_init_vcpu(CPUState *cpu) r =hv_vcpu_create (&cpu->accel->fd, (hv_vcpu_exit_t **)&cpu->accel->exit,NULL );#else - r =hv_vcpu_create ((hv_vcpuid_t *)&cpu->accel->fd,HV_VCPU_DEFAULT ); + r =hv_vcpu_create (&cpu->accel->fd,HV_VCPU_DEFAULT );#endif cpu->accel->dirty = true;assert_hvf_ok (r);
Signature · 1 line
2.45.1
[PULL 03/42] target/i386: cleanup HLT helpers
In reply to Paolo BonziniUse decode.c's support for intercepts, doing the check in TCG-generated code rather than the helper. This is cleaner because it allows removing the eip_addend argument to helper_hlt().
--- target/i386/helper.h | 2 +- target/i386/tcg/sysemu/misc_helper.c | 13 ++----------- target/i386/tcg/decode-new.c.inc | 4 ++-- target/i386/tcg/emit.c.inc | 4 ++-- 4 files changed, 7 insertions(+), 16 deletions(-)
target/i386/helper.h +1 -1
@@ -90,7 +90,7 @@ DEF_HELPER_2(vmsave, void, env, int) DEF_HELPER_1(stgi, void, env) DEF_HELPER_1(clgi, void, env) DEF_HELPER_FLAGS_2(flush_page, TCG_CALL_NO_RWG, void, env, tl) -DEF_HELPER_FLAGS_2(hlt, TCG_CALL_NO_WG, noreturn, env, int) +DEF_HELPER_FLAGS_1(hlt, TCG_CALL_NO_WG, noreturn, env) DEF_HELPER_FLAGS_2(monitor, TCG_CALL_NO_WG, void, env, tl) DEF_HELPER_FLAGS_2(mwait, TCG_CALL_NO_WG, noreturn, env, int)DEF_HELPER_1 (rdmsr, void, env)
target/i386/tcg/sysemu/misc_helper.c +2 -11
@@ -516,8 +516,7 @@ void helper_flush_page(CPUX86State *env, target_ulong addr)tlb_flush_page (env_cpu (env), addr); } -static G_NORETURN -void do_hlt(CPUX86State *env) +G_NORETURN void helper_hlt(CPUX86State *env) {CPUState *cs =env_cpu (env);
@@ -527,14 +526,6 @@ void do_hlt(CPUX86State *env)cpu_loop_exit (cs); } -G_NORETURN void helper_hlt(CPUX86State *env, int next_eip_addend) -{ -cpu_svm_check_intercept_param (env,SVM_EXIT_HLT ,0 ,GETPC ()); - env->eip += next_eip_addend; - -do_hlt (env); -} -void helper_monitor (CPUX86State *env,target_ulong ptr) {if ((uint32_t )env->regs[R_ECX ] !=0 ) {
@@ -558,6 +549,6 @@ G_NORETURN void helper_mwait(CPUX86State *env, int next_eip_addend)if (cs->cpu_index !=0 ||CPU_NEXT (cs) !=NULL ) {do_pause (env); }else { -do_hlt (env); +helper_hlt (env); } }
target/i386/tcg/decode-new.c.inc +2 -2
@@ -1496,7 +1496,7 @@ static const X86OpEntry opcodes_root[256] = { [0xE7] = X86_OP_ENTRYrr(OUT, 0,v, I_unsigned,b), /* AX/EAX */ [0xF1] = X86_OP_ENTRY0(INT1, svm(ICEBP)), - [0xF4] = X86_OP_ENTRY0(HLT, chk(cpl0)), + [0xF4] = X86_OP_ENTRY0(HLT, chk(cpl0) svm(HLT)), [0xF5] = X86_OP_ENTRY0(CMC), [0xF6] = X86_OP_GROUP1(group3, E,b), [0xF7] = X86_OP_GROUP1(group3, E,v),
@@ -2539,7 +2539,7 @@ static void disas_insn(DisasContext *s, CPUState *cpu) /* * Checks that result in #GP or VMEXIT come second. Intercepts are - * generally checked after non-memory exceptions (i.e. before all + * generally checked after non-memory exceptions (i.e. after all * exceptions if there is no memory operand). Exceptions are * vm86 checks (INTn, IRET, PUSHF/POPF), RSM and XSETBV (!). *
target/i386/tcg/emit.c.inc +2 -2
@@ -1638,8 +1638,8 @@ static void gen_HLT(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) { #ifdef CONFIG_SYSTEM_ONLY gen_update_cc_op(s); - gen_update_eip_cur(s); - gen_helper_hlt(tcg_env, cur_insn_len_i32(s)); + gen_update_eip_next(s); + gen_helper_hlt(tcg_env); s->base.is_jmp = DISAS_NORETURN; #endif }
Signature · 1 line
2.45.1
[PULL 13/42] target/i386: use gen_writeback() within gen_POP()
In reply to Paolo BonziniFrom: Mark Cave-Ayland <[email protected]>
Instead of directly implementing the writeback using gen_op_st_v(), use the existing gen_writeback() function.
Message-ID: <[email protected]>
--- target/i386/tcg/emit.c.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/tcg/emit.c.inc +2 -2
@@ -2580,9 +2580,9 @@ static void gen_POP(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) if (op->has_ea) { /* NOTE: order is important for MMU exceptions */ - gen_op_st_v(s, ot, s->T0, s->A0); - op->unit = X86_OP_SKIP; + gen_writeback(s, decode, 0, s->T0); } + /* NOTE: writing back registers after update is important for pop %sp */ gen_pop_update(s, ot); }
Signature · 1 line
2.45.1
Re: [PULL 13/42] target/i386: use gen_writeback() within gen_POP()
Hi Mark,
This patch introduces regressions in our x86_64 VxWorks kernels running over qemu. Some page faults are triggered randomly.
Earlier to this patch, the MemOp ot passed to gen_op_st_v was the gen_pop_T0 created a few lines above.
Now, this is op->ot which comes from elsewhere.
Adding op->ot = ot just before calling gen_writeback fixes my regressions. But I'm wondering if there could be some unexpected fallbacks, op->ot possibly being used afterwards.
Thanks,
Clément
Quoted 34 lines · Paolo Bonzini
From: Mark Cave-Ayland <[email protected]>
Instead of directly implementing the writeback using
gen_op_st_v(), use the existinggen_writeback()function.Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Mark Cave-Ayland <[email protected]>Message-ID: <[email protected]>
Signed-off-by Paolo Bonzini <[email protected]>--- target/i386/tcg/emit.c.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/i386/tcg/emit.c.inc +2
-3@@ -2580,9 +2580,9 @@ static void gen_POP(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) if (op->has_ea) { /* NOTE: order is important for MMU exceptions */ - gen_op_st_v(s, ot, s->T0, s->A0); - op->unit = X86_OP_SKIP; + gen_writeback(s, decode, 0, s->T0); } + /* NOTE: writing back registers after update is important for pop %sp */ gen_pop_update(s, ot); } --2.45.1
Re: [PULL 13/42] target/i386: use gen_writeback() within gen_POP()
Quoted 5 lines · Clément Chigot
Hi Mark,
This patch introduces regressions in our
x86_64VxWorks kernels running over qemu. Some page faults are triggered randomly.
Quoted 7 lines
Earlier to this patch, the MemOp
otpassed togen_op_st_vwas thegen_pop_T0created a few lines above.
Now, this isop->otwhich comes from elsewhere.Adding
op->ot = otjust before callinggen_writebackfixes my regressions. But I'm wondering if there could be some unexpected fallbacks,op->otpossibly being used afterwards.
Mark's patch is correct and the (previously latent) mistake is in the decoding table.
The manual correctly says that POP has "default 64-bit" operand; that is, it is 64-bit even without a REX.W prefix. It must be marked as "d64" rather than "v".
Can you test this patch?
target/i386/tcg/decode-new.c.inc +1 -1
@@ -1717,7 +1717,7 @@ static const X86OpEntry opcodes_root[256] = { [0x8C] = X86_OP_ENTRYwr(MOV, E,v, S,w, op0_Mw), [0x8D] = X86_OP_ENTRYwr(LEA, G,v, M,v, nolea), [0x8E] = X86_OP_ENTRYwr(MOV, S,w, E,w), - [0x8F] = X86_OP_GROUPw(group1A, E,v), + [0x8F] = X86_OP_GROUPw(group1A, E,d64), [0x98] = X86_OP_ENTRY1(CBW, 0,v), /* rAX */ [0x99] = X86_OP_ENTRYwr(CWD, 2,v, 0,v), /* rDX, rAX */
target/i386/tcg/emit.c.inc +2 -0
@@ -2788,6 +2788,8 @@ static void gen_POP(DisasContext *s, X86DecodedInsn *decode) X86DecodedOp *op = &decode->op[0]; MemOp ot = gen_pop_T0(s); + /* Only 16/32-bit access in 32-bit mode, 16/64-bit access in long mode. */ + assert(ot == op->ot); if (op->has_ea || op->unit == X86_OP_SEG) { /* NOTE: order is important for MMU exceptions */ gen_writeback(s, decode, 0, s->T0);
Thanks (and it's reassuring that everything else has worked fine for you!),
Paolo
Quoted 40 lines
Thanks,
ClémentQuoted 34 lines · Paolo Bonzini
From: Mark Cave-Ayland <[email protected]>
Instead of directly implementing the writeback using
gen_op_st_v(), use the existinggen_writeback()function.Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Mark Cave-Ayland <[email protected]>Message-ID: <[email protected]>
Signed-off-by Paolo Bonzini <[email protected]>--- target/i386/tcg/emit.c.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/i386/tcg/emit.c.inc +2
-3@@ -2580,9 +2580,9 @@ static void gen_POP(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) if (op->has_ea) { /* NOTE: order is important for MMU exceptions */ - gen_op_st_v(s, ot, s->T0, s->A0); - op->unit = X86_OP_SKIP; + gen_writeback(s, decode, 0, s->T0); } + /* NOTE: writing back registers after update is important for pop %sp */ gen_pop_update(s, ot); } --2.45.1
Re: [PULL 13/42] target/i386: use gen_writeback() within gen_POP()
Quoted 15 lines · Paolo Bonzini
Quoted 5 lines · Clément Chigot
Hi Mark,
This patch introduces regressions in our
x86_64VxWorks kernels running over qemu. Some page faults are triggered randomly.Quoted 7 lines
Earlier to this patch, the MemOp
otpassed togen_op_st_vwas thegen_pop_T0created a few lines above.
Now, this isop->otwhich comes from elsewhere.Adding
op->ot = otjust before callinggen_writebackfixes my regressions. But I'm wondering if there could be some unexpected fallbacks,op->otpossibly being used afterwards.
Quoted 8 lines
Mark's patch is correct and the (previously latent) mistake is in the decoding table.
The manual correctly says that POP has "default 64-bit" operand; that is, it is 64-bit even without a REX.W prefix. It must be marked as "d64" rather than "v".
Can you test this patch?
Yes, it does work. Thanks a lot for it !
Quoted 73 lines
target/i386/tcg/decode-new.c.inc +1
-1@@ -1717,7 +1717,7 @@ static const X86OpEntry opcodes_root[256] = { [0x8C] = X86_OP_ENTRYwr(MOV, E,v, S,w, op0_Mw), [0x8D] = X86_OP_ENTRYwr(LEA, G,v, M,v, nolea), [0x8E] = X86_OP_ENTRYwr(MOV, S,w, E,w), - [0x8F] = X86_OP_GROUPw(group1A, E,v), + [0x8F] = X86_OP_GROUPw(group1A, E,d64), [0x98] = X86_OP_ENTRY1(CBW, 0,v), /* rAX */ [0x99] = X86_OP_ENTRYwr(CWD, 2,v, 0,v), /* rDX, rAX */target/i386/tcg/emit.c.inc +2
-0@@ -2788,6 +2788,8 @@ static void gen_POP(DisasContext *s, X86DecodedInsn *decode) X86DecodedOp *op = &decode->op[0]; MemOp ot = gen_pop_T0(s); + /* Only 16/32-bit access in 32-bit mode, 16/64-bit access in long mode. */ + assert(ot == op->ot); if (op->has_ea || op->unit == X86_OP_SEG) { /* NOTE: order is important for MMU exceptions */ gen_writeback(s, decode, 0, s->T0);Thanks (and it's reassuring that everything else has worked fine for you!),
Paolo
Quoted 40 lines
Thanks,
ClémentQuoted 34 lines · Paolo Bonzini
From: Mark Cave-Ayland <[email protected]>
Instead of directly implementing the writeback using
gen_op_st_v(), use the existinggen_writeback()function.Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Mark Cave-Ayland <[email protected]>Message-ID: <[email protected]>
Signed-off-by Paolo Bonzini <[email protected]>--- target/i386/tcg/emit.c.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)target/i386/tcg/emit.c.inc +2
-3@@ -2580,9 +2580,9 @@ static void gen_POP(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) if (op->has_ea) { /* NOTE: order is important for MMU exceptions */ - gen_op_st_v(s, ot, s->T0, s->A0); - op->unit = X86_OP_SKIP; + gen_writeback(s, decode, 0, s->T0); } + /* NOTE: writing back registers after update is important for pop %sp */ gen_pop_update(s, ot); } --2.45.1
[PULL 26/42] i386/hvf: Fixes some compilation warnings
In reply to Paolo BonziniFrom: Phil Dennis-Jordan <[email protected]>
A bunch of function definitions used empty parentheses instead of (void) syntax, yielding the following warning when building with clang on macOS:
warning: a function declaration without a prototype is deprecated in all versions of C [-Wstrict-prototypes]
In addition to fixing these function headers, it also fixes what appears to be a typo causing a variable to be unused after initialisation.
warning: variable 'entry_ctls' set but not used [-Wunused-but-set-variable]
Message-ID: <[email protected]>
--- target/i386/hvf/vmx.h | 3 +-- target/i386/hvf/x86_decode.c | 2 +- target/i386/hvf/x86_emu.c | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-)
target/i386/hvf/vmx.h +1 -2
@@ -95,8 +95,7 @@ static void enter_long_mode(hv_vcpuid_t vcpu, uint64_t cr0, uint64_t efer) efer |=MSR_EFER_LMA ;wvmcs (vcpu,VMCS_GUEST_IA32_EFER , efer); entry_ctls =rvmcs (vcpu,VMCS_ENTRY_CTLS ); -wvmcs (vcpu,VMCS_ENTRY_CTLS ,rvmcs (vcpu,VMCS_ENTRY_CTLS ) | -VM_ENTRY_GUEST_LMA ); +wvmcs (vcpu,VMCS_ENTRY_CTLS , entry_ctls |VM_ENTRY_GUEST_LMA );uint64_t guest_tr_ar =rvmcs (vcpu,VMCS_GUEST_TR_ACCESS_RIGHTS ); if ((efer & MSR_EFER_LME) &&
target/i386/hvf/x86_decode.c +1 -1
@@ -2111,7 +2111,7 @@ uint32_t decode_instruction(CPUX86State *env, struct x86_decode *decode)return decode->len; } -void init_decoder () +void init_decoder (void ) {int i;
target/i386/hvf/x86_emu.c +2 -2
@@ -1409,7 +1409,7 @@ static struct cmd_handler {static struct cmd_handler _cmd_handler[X86_DECODE_CMD_LAST ]; -static void init_cmd_handler () +static void init_cmd_handler (void ) {int i;for (i =0 ; i <ARRAY_SIZE (handlers); i++) {
@@ -1481,7 +1481,7 @@ bool exec_instruction(CPUX86State *env, struct x86_decode *ins)return true; } -void init_emu () +void init_emu (void ) {init_cmd_handler (); }
Signature · 1 line
2.45.1
[PULL 07/42] target/i386: fix INHIBIT_IRQ/TF/RF handling for VMRUN
In reply to Paolo BonziniFrom vm entry to exit, VMRUN is handled as a single instruction. It uses DISAS_NORETURN in order to avoid processing TF or RF before the first instruction executes in the guest. However, the corresponding handling is missing in vmexit. Add it, and at the same time reorganize the comments with quotes from the manual about the tasks performed by a #VMEXIT.
Another gen_eob() task that is missing in VMRUN is preparing the HF_INHIBIT_IRQ flag for the next instruction, in this case by loading it from the VMCB control state.
--- target/i386/tcg/sysemu/svm_helper.c | 46 +++++++++++++++++++++-------- target/i386/tcg/translate.c | 5 ++++ 2 files changed, 38 insertions(+), 13 deletions(-)
target/i386/tcg/sysemu/svm_helper.c +33 -13
@@ -254,6 +254,13 @@ void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend) control.intercept_exceptions )); + env->hflags &= ~HF_INHIBIT_IRQ_MASK ; +if (x86_ldl_phys (cs, env->vm_vmcb + + offsetof(struct vmcb, control.int_state)) & +SVM_INTERRUPT_SHADOW_MASK ) { + env->hflags |=HF_INHIBIT_IRQ_MASK ; + } + nested_ctl =x86_ldq_phys (cs, env->vm_vmcb + offsetof(struct vmcb , control.nested_ctl)); asid = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb,
@@ -815,8 +822,12 @@ void do_vmexit(CPUX86State *env) env->hflags &= ~HF_GUEST_MASK ; env->intercept =0 ; env->intercept_exceptions =0 ; + +/* Clears the V_IRQ and V_INTR_MASKING bits inside the processor. */ cs->interrupt_request &= ~CPU_INTERRUPT_VIRQ ; env->int_ctl =0 ; + +/* Clears the TSC_OFFSET inside the processor. */ env->tsc_offset =0 ; env->gdt.base = x86_ldq_phys(cs, env->vm_hsave + offsetof(struct vmcb,
@@ -836,6 +847,15 @@ void do_vmexit(CPUX86State *env)cpu_x86_update_cr4 (env,x86_ldq_phys (cs, env->vm_hsave + offsetof(struct vmcb , save.cr4))); + +/* +* Resets the current ASID register to zero (host ASID; TLB flush). +* +* If the host is in PAE mode, the processor reloads the host's PDPEs +* from the page table indicated the host's CR3. FIXME: If the PDPEs +* contain illegal state, the processor causes a shutdown (QEMU does +* not implement PDPTRs). +*/ cpu_x86_update_cr3 (env,x86_ldq_phys (cs, env->vm_hsave + offsetof(struct vmcb , save.cr3)));
@@ -843,12 +863,14 @@ void do_vmexit(CPUX86State *env)set properly */ cpu_load_efer (env,x86_ldq_phys (cs, env->vm_hsave + offsetof(struct vmcb , save.efer))); + +/* Completion of the VMRUN instruction clears the host EFLAGS.RF bit. */ env->eflags =0 ;cpu_load_eflags (env,x86_ldq_phys (cs, env->vm_hsave + offsetof(struct vmcb , save.rflags)), ~(CC_O |CC_S |CC_Z |CC_A |CC_P |CC_C |DF_MASK | -VM_MASK )); +RF_MASK |VM_MASK ));svm_load_seg_cache (env,MMU_PHYS_IDX , env->vm_hsave + offsetof(struct vmcb, save.es), R_ES);
@@ -888,19 +910,17 @@ void do_vmexit(CPUX86State *env) env->hflags2 &= ~HF2_GIF_MASK ; env->hflags2 &= ~HF2_VGIF_MASK ; -/* FIXME: Resets the current ASID register to zero (host ASID). */ -/* Clears the V_IRQ and V_INTR_MASKING bits inside the processor. */ -/* Clears the TSC_OFFSET inside the processor. */ +/* FIXME: Checks the reloaded host state for consistency. */ -/* If the host is in PAE mode, the processor reloads the host's PDPEs -from the page table indicated the host's CR3. If the PDPEs contain -illegal state, the processor causes a shutdown. */ - -/* Checks the reloaded host state for consistency. */ - -/* If the host's rIP reloaded by #VMEXIT is outside the limit of the -host's code segment or non-canonical (in the case of long mode), a -#GP fault is delivered inside the host. */ +/* +* EFLAGS.TF causes a #DB trap after the VMRUN completes on the host +* side (i.e., after the #VMEXIT from the guest). Since we're running +* in the main loop, call do_interrupt_all directly. +*/ +if ((env->eflags &TF_MASK ) !=0 ) { + env->dr[6 ] |=DR6_BS ; +do_interrupt_all (X86_CPU (cs),EXCP01_DB ,0 ,0 , env->eip,0 ); + } }
target/i386/tcg/translate.c +5 -0
@@ -3745,6 +3745,11 @@ static void disas_insn_old(DisasContext *s, CPUState *cpu, int b) }gen_update_cc_op (s);gen_update_eip_cur (s); +/* +* Reloads INHIBIT_IRQ mask as well as TF and RF with guest state. +* The usual gen_eob() handling is performed on vmexit after +* host state is reloaded. +*/ gen_helper_vmrun (tcg_env,tcg_constant_i32 (s->aflag -1 ),cur_insn_len_i32 (s));tcg_gen_exit_tb (NULL ,0 );
Signature · 1 line
2.45.1
[PULL 04/42] target/i386: cleanup PAUSE helpers
In reply to Paolo BonziniUse decode.c's support for intercepts, doing the check in TCG-generated code rather than the helper. This is cleaner because it allows removing the eip_addend argument to helper_pause(), even though it adds a bit of bloat for opcode 0x90's new decoding function.
--- target/i386/helper.h | 2 +- target/i386/tcg/helper-tcg.h | 1 - target/i386/tcg/misc_helper.c | 10 +--------- target/i386/tcg/sysemu/misc_helper.c | 2 +- target/i386/tcg/decode-new.c.inc | 15 ++++++++++++++- target/i386/tcg/emit.c.inc | 20 ++++++++------------ 6 files changed, 25 insertions(+), 25 deletions(-)
target/i386/helper.h +1 -1
@@ -53,7 +53,7 @@ DEF_HELPER_1(sysenter, void, env) DEF_HELPER_2(sysexit, void, env, int) DEF_HELPER_2(syscall, void, env, int) DEF_HELPER_2(sysret, void, env, int) -DEF_HELPER_FLAGS_2(pause, TCG_CALL_NO_WG, noreturn, env, int) +DEF_HELPER_FLAGS_1(pause, TCG_CALL_NO_WG, noreturn, env) DEF_HELPER_FLAGS_3(raise_interrupt, TCG_CALL_NO_WG, noreturn, env, int, int) DEF_HELPER_FLAGS_2(raise_exception, TCG_CALL_NO_WG, noreturn, env, int)DEF_HELPER_FLAGS_1 (icebp,TCG_CALL_NO_WG , noreturn, env)
target/i386/tcg/helper-tcg.h +0 -1
@@ -91,7 +91,6 @@ extern const uint8_t parity_table[256];/* misc_helper.c */ void cpu_load_eflags (CPUX86State *env,int eflags,int update_mask); -G_NORETURN void do_pause(CPUX86State *env);/* sysemu/svm_helper.c */ #ifndef CONFIG_USER_ONLY
target/i386/tcg/misc_helper.c +1 -9
@@ -88,7 +88,7 @@ G_NORETURN void helper_rdpmc(CPUX86State *env)raise_exception_err (env,EXCP06_ILLOP ,0 ); } -G_NORETURN void do_pause(CPUX86State *env) +G_NORETURN void helper_pause(CPUX86State *env) {CPUState *cs =env_cpu (env);
@@ -97,14 +97,6 @@ G_NORETURN void do_pause(CPUX86State *env)cpu_loop_exit (cs); } -G_NORETURN void helper_pause(CPUX86State *env, int next_eip_addend) -{ -cpu_svm_check_intercept_param (env,SVM_EXIT_PAUSE ,0 ,GETPC ()); - env->eip += next_eip_addend; - -do_pause (env); -} -uint64_t helper_rdpkru (CPUX86State *env,uint32_t ecx) {if ((env->cr[4 ] &CR4_PKE_MASK ) ==0 ) {
target/i386/tcg/sysemu/misc_helper.c +1 -1
@@ -547,7 +547,7 @@ G_NORETURN void helper_mwait(CPUX86State *env, int next_eip_addend)/* XXX: not complete but not completely erroneous */ if (cs->cpu_index !=0 ||CPU_NEXT (cs) !=NULL ) { -do_pause (env); +helper_pause (env); }else {helper_hlt (env); }
target/i386/tcg/decode-new.c.inc +14 -1
@@ -1359,6 +1359,19 @@ static void decode_group11(DisasContext *s, CPUX86State *env, X86OpEntry *entry, } } +static void decode_90(DisasContext *s, CPUX86State *env, X86OpEntry *entry, uint8_t *b) +{ + static X86OpEntry pause = X86_OP_ENTRY0(PAUSE, svm(PAUSE)); + static X86OpEntry nop = X86_OP_ENTRY0(NOP); + static X86OpEntry xchg_ax = X86_OP_ENTRY2(XCHG, 0,v, LoBits,v); + + if (REX_B(s)) { + *entry = xchg_ax; + } else { + *entry = (s->prefix & PREFIX_REPZ) ? pause : nop; + } +} + static const X86OpEntry opcodes_root[256] = { [0x00] = X86_OP_ENTRY2(ADD, E,b, G,b, lock), [0x01] = X86_OP_ENTRY2(ADD, E,v, G,v, lock),
@@ -1441,7 +1454,7 @@ static const X86OpEntry opcodes_root[256] = { [0x86] = X86_OP_ENTRY2(XCHG, E,b, G,b, xchg), [0x87] = X86_OP_ENTRY2(XCHG, E,v, G,v, xchg), - [0x90] = X86_OP_ENTRY2(XCHG, 0,v, LoBits,v), + [0x90] = X86_OP_GROUP0(90), [0x91] = X86_OP_ENTRY2(XCHG, 0,v, LoBits,v), [0x92] = X86_OP_ENTRY2(XCHG, 0,v, LoBits,v), [0x93] = X86_OP_ENTRY2(XCHG, 0,v, LoBits,v),
target/i386/tcg/emit.c.inc +8 -12
@@ -2350,6 +2350,14 @@ static void gen_PANDN(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) decode->op[1].offset, vec_len, vec_len); } +static void gen_PAUSE(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) +{ + gen_update_cc_op(s); + gen_update_eip_next(s); + gen_helper_pause(tcg_env); + s->base.is_jmp = DISAS_NORETURN; +} + static void gen_PCMPESTRI(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) { TCGv_i32 imm = tcg_constant8u_i32(decode->immediate);
@@ -4014,18 +4022,6 @@ static void gen_WAIT(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) static void gen_XCHG(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) { - if (decode->b == 0x90 && !REX_B(s)) { - if (s->prefix & PREFIX_REPZ) { - gen_update_cc_op(s); - gen_update_eip_cur(s); - gen_helper_pause(tcg_env, cur_insn_len_i32(s)); - s->base.is_jmp = DISAS_NORETURN; - } - /* No writeback. */ - decode->op[0].unit = X86_OP_SKIP; - return; - } - if (s->prefix & PREFIX_LOCK) { tcg_gen_atomic_xchg_tl(s->T0, s->A0, s->T1, s->mem_index, decode->op[0].ot | MO_LE);
Signature · 1 line
2.45.1
[PULL 31/42] hvf: Makes assert_hvf_ok report failed expression
In reply to Paolo BonziniFrom: Phil Dennis-Jordan <[email protected]>
When a macOS Hypervisor.framework call fails which is checked by assert_hvf_ok(), Qemu exits printing the error value, but not the location
in the code, as regular assert() macro expansions would.
This change turns assert_hvf_ok() into a macro similar to other assertions, which expands to a call to the corresponding _impl() function together with information about the expression that failed the assertion and its location in the code.
Additionally, stringifying the numeric hv_return_t code is factored into a helper function that can be reused for diagnostics and debugging outside of assertions.
Message-ID: <[email protected]>
--- include/sysemu/hvf_int.h | 5 +++- accel/hvf/hvf-all.c | 51 +++++++++++++++++----------------------- 2 files changed, 26 insertions(+), 30 deletions(-)
include/sysemu/hvf_int.h +4 -1
@@ -60,7 +60,10 @@ struct AccelCPUState {bool dirty; }; -void assert_hvf_ok (hv_return_t ret); +void assert_hvf_ok_impl (hv_return_t ret,const char *file,unsigned int line, +const char *exp); +#define assert_hvf_ok (EX ) assert_hvf_ok_impl((EX), __FILE__, __LINE__, #EX) +const char *hvf_return_string (hv_return_t ret);int hvf_arch_init (void );int hvf_arch_init_vcpu (CPUState *cpu);void hvf_arch_vcpu_destroy (CPUState *cpu);
accel/hvf/hvf-all.c +22 -29
62 lines not on this page · raw message
Signature · 1 line
2.45.1
[PULL 14/42] target/i386: fix SP when taking a memory fault during POP
In reply to Paolo BonziniFrom: Mark Cave-Ayland <[email protected]>
When OS/2 Warp configures its segment descriptors, many of them are configured with the P flag clear to allow for a fault-on-demand implementation. In the case where the stack value is POPped into the segment registers, the SP is incremented before calling gen_helper_load_seg() to validate the segment descriptor:
IN:0xffef2c0c: 66 07 popl %es
OP:
ld_i32 loc9,env,$0xfffffffffffffff8
sub_i32 loc9,loc9,$0x1
brcond_i32 loc9,$0x0,lt,$L0
st16_i32 loc9,env,$0xfffffffffffffff8
st8_i32 $0x1,env,$0xfffffffffffffffc
---- 0000000000000c0c 0000000000000000
ext16u_i64 loc0,rsp
add_i64 loc0,loc0,ss_base
ext32u_i64 loc0,loc0
qemu_ld_a64_i64 loc0,loc0,noat+un+leul,5
add_i64 loc3,rsp,$0x4
deposit_i64 rsp,rsp,loc3,$0x0,$0x10
extrl_i64_i32 loc5,loc0
call load_seg,$0x0,$0,env,$0x0,loc5
add_i64 rip,rip,$0x2
ext16u_i64 rip,rip
exit_tb $0x0
set_label $L0
exit_tb $0x7fff58000043
If helper_load_seg() generates a fault when validating the segment descriptor then as the SP has already been incremented, the topmost word of the stack is overwritten by the arguments pushed onto the stack by the CPU before taking the fault handler. As a consequence things rapidly go wrong upon return from the fault handler due to the corrupted stack.
Update the logic for the existing writeback condition so that a POP into the segment registers also calls helper_load_seg() first before incrementing the SP, so that if a fault occurs the SP remains unaltered.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2198
Message-ID: <[email protected]>
--- target/i386/tcg/emit.c.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/tcg/emit.c.inc +1 -1
@@ -2578,7 +2578,7 @@ static void gen_POP(DisasContext *s, CPUX86State *env, X86DecodedInsn *decode) X86DecodedOp *op = &decode->op[0]; MemOp ot = gen_pop_T0(s); - if (op->has_ea) { + if (op->has_ea || op->unit == X86_OP_SEG) { /* NOTE: order is important for MMU exceptions */ gen_writeback(s, decode, 0, s->T0); }
Signature · 1 line
2.45.1
[PULL 34/42] vmxcap: add support for VMX FRED controls
In reply to Paolo BonziniFrom: Xin Li <[email protected]>
Report secondary vm-exit controls and the VMX controls used to save/load FRED MSRs.
Message-ID: <[email protected]>
--- scripts/kvm/vmxcap | 12 ++++++++++++ 1 file changed, 12 insertions(+)
scripts/kvm/vmxcap +12 -0
@@ -24,6 +24,7 @@ MSR_IA32_VMX_TRUE_EXIT_CTLS = 0x48F MSR_IA32_VMX_TRUE_ENTRY_CTLS = 0x490 MSR_IA32_VMX_VMFUNC = 0x491 MSR_IA32_VMX_PROCBASED_CTLS3 = 0x492 +MSR_IA32_VMX_EXIT_CTLS2 = 0x493 class msr(object): def __init__(self):
@@ -219,11 +220,21 @@ controls = [ 23: 'Clear IA32_BNDCFGS', 24: 'Conceal VM exits from PT', 25: 'Clear IA32_RTIT_CTL', + 31: 'Activate secondary VM-exit controls', }, cap_msr = MSR_IA32_VMX_EXIT_CTLS, true_cap_msr = MSR_IA32_VMX_TRUE_EXIT_CTLS, ), + Allowed1Control( + name = 'secondary VM-Exit controls', + bits = { + 0: 'Save IA32 FRED MSRs', + 1: 'Load IA32 FRED MSRs', + }, + cap_msr = MSR_IA32_VMX_EXIT_CTLS2, + ), + Control( name = 'VM-Entry controls', bits = {
@@ -237,6 +248,7 @@ controls = [ 16: 'Load IA32_BNDCFGS', 17: 'Conceal VM entries from PT', 18: 'Load IA32_RTIT_CTL', + 23: 'Load IA32 FRED MSRs', }, cap_msr = MSR_IA32_VMX_ENTRY_CTLS, true_cap_msr = MSR_IA32_VMX_TRUE_ENTRY_CTLS,
Signature · 1 line
2.45.1
[PULL 18/42] osdep: Make qemu_madvise() to set errno in all cases
In reply to Paolo BonziniFrom: Michal Privoznik <[email protected]>
The unspoken premise of qemu_madvise() is that errno is set on error. And it is mostly the case except for posix_madvise() which is documented to return either zero (on success) or a positive error number. This means, we must set errno ourselves. And while at it, make the function return a negative value on error, just like other error paths do.
Message-ID: <af17113e7c1f2cc909ffd36d23f5a411b63b8764.1717584048.git.mprivozn@redhat.com>
--- util/osdep.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
util/osdep.c +6 -1
@@ -57,7 +57,12 @@ int qemu_madvise(void *addr, size_t len, int advice)#if defined(CONFIG_MADVISE )return madvise (addr, len, advice);#elif defined(CONFIG_POSIX_MADVISE ) -return posix_madvise (addr, len, advice); +int rc =posix_madvise (addr, len, advice); +if (rc) { + errno = rc; +return -1 ; + } +return 0 ;#else errno =EINVAL ;return -1 ;
Signature · 1 line
2.45.1
[PULL 41/42] Revert "python: use vendored tomli"
In reply to Paolo BonziniNow that Ubuntu 20.04 is not included anymore, there is no need to ship it as part of QEMU; Ubuntu 22.04 includes it and Leap users anyway need to install all the required dependencies from PyPI.
This mostly reverts commit ec77ee7634de123b7c899739711000fd21dab68b, with just some changes to the wording.
--- docs/devel/build-system.rst | 13 ++++++------- configure | 4 ---- python/scripts/vendor.py | 3 --- python/wheels/tomli-2.0.1-py3-none-any.whl | Bin 12757 -> 0 bytes 4 files changed, 6 insertions(+), 14 deletions(-) delete mode 100644 python/wheels/tomli-2.0.1-py3-none-any.whl
docs/devel/build-system.rst +6 -7
@@ -185,14 +185,13 @@ Bundled Python packages Python packages that are **mandatory** dependencies to build QEMU, but are not available in all supported distros, are bundled with the -QEMU sources. Currently this includes Meson (outdated in CentOS 8 -and derivatives, Ubuntu 20.04 and 22.04, and openSUSE Leap) and tomli -(absent in Ubuntu 20.04). +QEMU sources. The only one is currently Meson (outdated in Ubuntu +22.04 and openSUSE Leap). -If you need to update these, please do so by modifying and rerunning -``python/scripts/vendor.py``. This script embeds the sha256 hash of -package sources and checks it. The pypi.org web site provides an easy -way to retrieve the sha256 hash of the sources. +In order to include a new or updated wheel, modify and rerun the +``python/scripts/vendor.py`` script. The script embeds the +sha256 hash of package sources and checks it. The pypi.org web site +provides an easy way to retrieve the sha256 hash of the sources. Stage 2: Meson
configure +0 -4
@@ -955,10 +955,6 @@ mkvenv="$python ${source_path}/python/scripts/mkvenv.py" # Finish preparing the virtual environment using vendored .whl files -if $python -c 'import sys; sys.exit(sys.version_info >= (3,11))'; then - $mkvenv ensure --dir "${source_path}/python/wheels" \ - 'tomli>=1.2.0' || exit 1 -fi $mkvenv ensuregroup --dir "${source_path}/python/wheels" \ ${source_path}/pythondeps.toml meson || exit 1
python/scripts/vendor.py +0 -3
@@ -43,9 +43,6 @@ def main() -> int: packages = { "meson==1.2.3": "4533a43c34548edd1f63a276a42690fce15bde9409bcf20c4b8fa3d7e4d7cac1", - - "tomli==2.0.1": - "939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc", } vendor_dir = Path(__file__, "..", "..", "wheels").resolve()
python/wheels/tomli-2.0.1-py3-none-any.whl deleted binary +0 -0
Signature · 1 line
2.45.1
[PULL 16/42] machine: default -M mem-merge to off is QEMU_MADV_MERGEABLE is not available
In reply to Paolo BonziniOtherwise, starting any guest on a non-Linux guests results in
qemu-system-arm: Couldn't set property 'merge' on 'memory-backend-ram': Invalid argument
--- hw/core/machine.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/core/machine.c +2 -1
@@ -17,6 +17,7 @@#include "hw/loader.h" #include "qapi/error.h" #include "qapi/qapi-visit-machine.h" +#include "qemu/madvise.h" #include "qom/object_interfaces.h" #include "sysemu/cpus.h" #include "sysemu/sysemu.h"
@@ -1129,7 +1130,7 @@ static void machine_initfn(Object *obj)container_get (obj,"/peripheral-anon" ); ms->dump_guest_core = true; - ms->mem_merge = true; + ms->mem_merge = (QEMU_MADV_MERGEABLE !=QEMU_MADV_INVALID ); ms->enable_graphics = true; ms->kernel_cmdline =g_strdup ("" ); ms->ram_size = mc->default_ram_size;
Signature · 1 line
2.45.1
[PULL 08/42] target/i386: fix INHIBIT_IRQ/TF/RF handling for PAUSE
In reply to Paolo BonziniPAUSE uses DISAS_NORETURN because the corresponding helper calls cpu_loop_exit(). However, while HLT clear HF_INHIBIT_IRQ_MASK to correctly handle "STI; HLT", the same is missing from PAUSE. And also gen_eob() clears HF_RF_MASK and synthesizes a #DB exception if single-step is active; none of this is done by HLT and PAUSE. Start fixing PAUSE, HLT will follow.
--- target/i386/tcg/misc_helper.c | 4 ++++ 1 file changed, 4 insertions(+)
target/i386/tcg/misc_helper.c +4 -0
@@ -92,6 +92,10 @@ G_NORETURN void helper_pause(CPUX86State *env) {CPUState *cs =env_cpu (env); +/* Do gen_eob() tasks before going back to the main loop. */ +do_end_instruction (env); +helper_rechecking_single_step (env); +/* Just let another CPU run. */ cs->exception_index =EXCP_INTERRUPT ;cpu_loop_exit (cs);
Signature · 1 line
2.45.1
[PULL 38/42] i386: Fix MCE support for AMD hosts
In reply to Paolo BonziniFrom: John Allen <[email protected]>
For the most part, AMD hosts can use the same MCE injection code as Intel, but there are instances where the qemu implementation is Intel specific. First, MCE delivery works differently on AMD and does not support broadcast. Second, kvm_mce_inject generates MCEs that include a number of Intel specific status bits. Modify kvm_mce_inject to properly generate MCEs on AMD platforms.
Message-ID: <[email protected]>
--- target/i386/cpu.h | 2 ++ target/i386/helper.c | 4 ++++ target/i386/kvm/kvm.c | 39 +++++++++++++++++++++++++++++++-------- 3 files changed, 37 insertions(+), 8 deletions(-)
target/i386/cpu.h +2 -0
@@ -377,6 +377,8 @@ typedef enum X86Seg {#define MCI_STATUS_PCC (1ULL<<57)/* processor context corrupt */ #define MCI_STATUS_S (1ULL<<56)/* Signaled machine check */ #define MCI_STATUS_AR (1ULL<<55)/* Action required */ +#define MCI_STATUS_DEFERRED (1ULL<<44)/* Deferred error */ +#define MCI_STATUS_POISON (1ULL<<43)/* Poisoned data consumed */ /* MISC register defines */ #define MCM_ADDR_SEGOFF 0/* segment offset */
target/i386/helper.c +4 -0
@@ -91,6 +91,10 @@ int cpu_x86_support_mca_broadcast(CPUX86State *env)int family =0 ;int model =0 ; +if (IS_AMD_CPU (env)) { +return 0 ; + } +cpu_x86_version (env, &family, &model);if ((family ==6 && model >=14 ) || family >6 ) {return 1 ;
target/i386/kvm/kvm.c +31 -8
@@ -638,17 +638,40 @@ static void kvm_mce_inject(X86CPU *cpu, hwaddr paddr, int code) {CPUState *cs =CPU (cpu);CPUX86State *env = &cpu->env; -uint64_t status =MCI_STATUS_VAL |MCI_STATUS_UC |MCI_STATUS_EN | -MCI_STATUS_MISCV |MCI_STATUS_ADDRV |MCI_STATUS_S ; -uint64_t mcg_status =MCG_STATUS_MCIP ; +uint64_t status =MCI_STATUS_VAL |MCI_STATUS_EN |MCI_STATUS_MISCV | +MCI_STATUS_ADDRV ; +uint64_t mcg_status =MCG_STATUS_MCIP |MCG_STATUS_RIPV ;int flags =0 ; -if (code ==BUS_MCEERR_AR ) { - status |=MCI_STATUS_AR |0x134 ; - mcg_status |=MCG_STATUS_RIPV |MCG_STATUS_EIPV ; +if (!IS_AMD_CPU (env)) { + status |=MCI_STATUS_S |MCI_STATUS_UC ; +if (code ==BUS_MCEERR_AR ) { + status |=MCI_STATUS_AR |0x134 ; + mcg_status |=MCG_STATUS_EIPV ; + }else { + status |=0xc0 ; + } }else { - status |=0xc0 ; - mcg_status |=MCG_STATUS_RIPV ; +if (code ==BUS_MCEERR_AR ) { + status |=MCI_STATUS_UC |MCI_STATUS_POISON ; + mcg_status |=MCG_STATUS_EIPV ; + }else { +/* Setting the POISON bit for deferred errors indicates to the +* guest kernel that the address provided by the MCE is valid +* and usable which will ensure that the guest kernel will send +* a SIGBUS_AO signal to the guest process. This allows for +* more desirable behavior in the case that the guest process +* with poisoned memory has set the MCE_KILL_EARLY prctl flag +* which indicates that the process would prefer to handle or +* shutdown due to the poisoned memory condition before the +* memory has been accessed. +* +* While the POISON bit would not be set in a deferred error +* sent from hardware, the bit is not meaningful for deferred +* errors and can be reused in this scenario. +*/ + status |=MCI_STATUS_DEFERRED |MCI_STATUS_POISON ; + } } flags =cpu_x86_support_mca_broadcast (env) ?MCE_INJECT_BROADCAST :0 ;
Signature · 1 line
2.45.1
[PULL 01/42] target/i386: fix pushed value of EFLAGS.RF
In reply to Paolo BonziniWhen preparing an exception stack frame for a fault exception, the value pushed for RF is 1. Take that into account. The same should be true of interrupts for repeated string instructions, but the situation there is complicated.
--- target/i386/tcg/seg_helper.c | 49 ++++++++++++++++++++++++++++++++---- target/i386/tcg/translate.c | 8 ++++++ 2 files changed, 52 insertions(+), 5 deletions(-)
target/i386/tcg/seg_helper.c +44 -5
@@ -526,6 +526,24 @@ static inline unsigned int get_sp_mask(unsigned int e2) } } +static int exception_is_fault (int intno) +{ +switch (intno) { +/* +* #DB can be both fault- and trap-like, but it never sets RF=1 +* in the RFLAGS value pushed on the stack. +*/ +case EXCP01_DB : +case EXCP03_INT3 : +case EXCP04_INTO : +case EXCP08_DBLE : +case EXCP12_MCHK : +return 0 ; + } +/* Everything else including reserved exception is a fault. */ +return 1 ; +} +int exception_has_error_code (int intno) {switch (intno) {
@@ -605,8 +623,9 @@ static void do_interrupt_protected(CPUX86State *env, int intno, int is_int,int type, dpl, selector, ss_dpl, cpl;int has_error_code, new_stack, shift;uint32_t e1, e2, offset, ss =0 , esp, ss_e1 =0 , ss_e2 =0 ; -uint32_t old_eip, sp_mask; +uint32_t old_eip, sp_mask, eflags;int vm86 = env->eflags &VM_MASK ; +bool set_rf; has_error_code =0 ;if (!is_int && !is_hw) {
@@ -614,8 +633,10 @@ static void do_interrupt_protected(CPUX86State *env, int intno, int is_int, }if (is_int) { old_eip = next_eip; + set_rf = false; }else { old_eip = env->eip; + set_rf =exception_is_fault (intno); } dt = &env->idt;
@@ -748,6 +769,15 @@ static void do_interrupt_protected(CPUX86State *env, int intno, int is_int, } push_size <<= shift;#endif + eflags =cpu_compute_eflags (env); +/* +* AMD states that code breakpoint #DBs clear RF=0, Intel leaves it +* as is. AMD behavior could be implemented in check_hw_breakpoints(). +*/ +if (set_rf) { + eflags |=RF_MASK ; + } +if (shift ==1 ) {if (new_stack) {if (vm86) {
@@ -759,7 +789,7 @@ static void do_interrupt_protected(CPUX86State *env, int intno, int is_int,PUSHL (ssp, esp, sp_mask, env->segs[R_SS ].selector);PUSHL (ssp, esp, sp_mask, env->regs[R_ESP ]); } -PUSHL (ssp, esp, sp_mask,cpu_compute_eflags (env)); +PUSHL (ssp, esp, sp_mask, eflags);PUSHL (ssp, esp, sp_mask, env->segs[R_CS ].selector);PUSHL (ssp, esp, sp_mask, old_eip);if (has_error_code) {
@@ -776,7 +806,7 @@ static void do_interrupt_protected(CPUX86State *env, int intno, int is_int,PUSHW (ssp, esp, sp_mask, env->segs[R_SS ].selector);PUSHW (ssp, esp, sp_mask, env->regs[R_ESP ]); } -PUSHW (ssp, esp, sp_mask,cpu_compute_eflags (env)); +PUSHW (ssp, esp, sp_mask, eflags);PUSHW (ssp, esp, sp_mask, env->segs[R_CS ].selector);PUSHW (ssp, esp, sp_mask, old_eip);if (has_error_code) {
@@ -868,8 +898,9 @@ static void do_interrupt64(CPUX86State *env, int intno, int is_int,target_ulong ptr;int type, dpl, selector, cpl, ist;int has_error_code, new_stack; -uint32_t e1, e2, e3, ss; +uint32_t e1, e2, e3, ss, eflags;target_ulong old_eip, esp, offset; +bool set_rf; has_error_code =0 ;if (!is_int && !is_hw) {
@@ -877,8 +908,10 @@ static void do_interrupt64(CPUX86State *env, int intno, int is_int, }if (is_int) { old_eip = next_eip; + set_rf = false; }else { old_eip = env->eip; + set_rf =exception_is_fault (intno); } dt = &env->idt;
@@ -950,9 +983,15 @@ static void do_interrupt64(CPUX86State *env, int intno, int is_int, } esp &= ~0xfLL ;/* align stack */ +/* See do_interrupt_protected. */ + eflags =cpu_compute_eflags (env); +if (set_rf) { + eflags |=RF_MASK ; + } +PUSHQ (esp, env->segs[R_SS ].selector);PUSHQ (esp, env->regs[R_ESP ]); -PUSHQ (esp,cpu_compute_eflags (env)); +PUSHQ (esp, eflags);PUSHQ (esp, env->segs[R_CS ].selector);PUSHQ (esp, old_eip);if (has_error_code) {
target/i386/tcg/translate.c +8 -0
@@ -4630,6 +4630,14 @@ static void i386_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cpu)* If jmp_opt, we want to handle each string instruction individually. * For icount also disable repz optimization so that each iteration * is accounted separately. +* +* FIXME: this is messy; it makes REP string instructions a lot less +* efficient than they should be and it gets in the way of correct +* handling of RF (interrupts or traps arriving after any iteration +* of a repeated string instruction but the last should set RF to 1). +* Perhaps it would be more efficient if REP string instructions were +* always at the beginning of the TB, or even their own TB? That +* would even allow accounting up to 64k iterations at once for icount. */ dc->repz_opt = !dc->jmp_opt && !(cflags &CF_USE_ICOUNT );
Signature · 1 line
2.45.1
[PULL 32/42] target/i386: add support for FRED in CPUID enumeration
In reply to Paolo BonziniFrom: Xin Li <[email protected]>
FRED, i.e., the Intel flexible return and event delivery architecture, defines simple new transitions that change privilege level (ring transitions).
The new transitions defined by the FRED architecture are FRED event delivery and, for returning from events, two FRED return instructions. FRED event delivery can effect a transition from ring 3 to ring 0, but it is used also to deliver events incident to ring 0. One FRED instruction (ERETU) effects a return from ring 0 to ring 3, while the other (ERETS) returns while remaining in ring 0. Collectively, FRED event delivery and the FRED return instructions are FRED transitions.
In addition to these transitions, the FRED architecture defines a new instruction (LKGS) for managing the state of the GS segment register. The LKGS instruction can be used by 64-bit operating systems that do not use the new FRED transitions.
WRMSRNS is an instruction that behaves exactly like WRMSR, with the only difference being that it is not a serializing instruction by default. Under certain conditions, WRMSRNS may replace WRMSR to improve performance. FRED uses it to switch RSP0 in a faster manner.
Search for the latest FRED spec in most search engines with this search pattern:
site:intel.com FRED (flexible return and event delivery) specification
The CPUID feature flag CPUID.(EAX=7,ECX=1):EAX[17] enumerates FRED, and the CPUID feature flag CPUID.(EAX=7,ECX=1):EAX[18] enumerates LKGS, and the CPUID feature flag CPUID.(EAX=7,ECX=1):EAX[19] enumerates WRMSRNS.
Add CPUID definitions for FRED/LKGS/WRMSRNS, and expose them to KVM guests.
Because FRED relies on LKGS and WRMSRNS, add that to feature dependency map.
Message-ID: <[email protected]>
--- target/i386/cpu.h | 6 ++++++ target/i386/cpu.c | 14 +++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-)
target/i386/cpu.h +6 -0
@@ -941,6 +941,12 @@ uint64_t x86_cpu_get_supported_feature_word(FeatureWord w,#define CPUID_7_1_EDX_AMX_COMPLEX (1U << 8)/* PREFETCHIT0/1 Instructions */ #define CPUID_7_1_EDX_PREFETCHITI (1U << 14) +/* Flexible return and event delivery (FRED) */ +#define CPUID_7_1_EAX_FRED (1U << 17) +/* Load into IA32_KERNEL_GS_BASE (LKGS) */ +#define CPUID_7_1_EAX_LKGS (1U << 18) +/* Non-Serializing Write to Model Specific Register (WRMSRNS) */ +#define CPUID_7_1_EAX_WRMSRNS (1U << 19)/* Do not exhibit MXCSR Configuration Dependent Timing (MCDT) behavior */ #define CPUID_7_2_EDX_MCDT_NO (1U << 5)
target/i386/cpu.c +13 -1
@@ -1114,7 +1114,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = {"avx-vnni" ,"avx512-bf16" ,NULL ,"cmpccxadd" ,NULL ,NULL ,"fzrm" ,"fsrs" ,"fsrc" ,NULL ,NULL ,NULL , -NULL ,NULL ,NULL ,NULL , +NULL ,"fred" ,"lkgs" ,"wrmsrns" ,NULL ,"amx-fp16" ,NULL ,"avx-ifma" ,NULL ,NULL ,"lam" ,NULL , NULL, NULL, NULL, NULL,
@@ -1701,6 +1701,18 @@ static FeatureDep feature_dependencies[] = { .from = { FEAT_7_0_ECX, CPUID_7_0_ECX_WAITPKG }, .to = { FEAT_VMX_SECONDARY_CTLS, VMX_SECONDARY_EXEC_ENABLE_USER_WAIT_PAUSE }, }, + { + .from = { FEAT_8000_0001_EDX, CPUID_EXT2_LM }, + .to = { FEAT_7_1_EAX, CPUID_7_1_EAX_FRED }, + }, + { + .from = { FEAT_7_1_EAX, CPUID_7_1_EAX_LKGS }, + .to = { FEAT_7_1_EAX, CPUID_7_1_EAX_FRED }, + }, + { + .from = { FEAT_7_1_EAX, CPUID_7_1_EAX_WRMSRNS }, + .to = { FEAT_7_1_EAX, CPUID_7_1_EAX_FRED }, + }, }; typedef struct X86RegisterInfo32 {
Signature · 1 line
2.45.1
[PULL 19/42] osdep: Make qemu_madvise() return ENOSYS on unsupported OSes
In reply to Paolo BonziniFrom: Michal Privoznik <[email protected]>
Not every OS is capable of madvise() or posix_madvise() even. In that case, errno should be set to ENOSYS as it reflects the cause better.
Message-ID: <b381c23bd8f413f1453a2c1a66e0979beaf27433.1717584048.git.mprivozn@redhat.com>
--- util/osdep.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
util/osdep.c +1 -1
@@ -64,7 +64,7 @@ int qemu_madvise(void *addr, size_t len, int advice) }return 0 ;#else - errno =EINVAL ; + errno =ENOSYS ;return -1 ;#endif }
Signature · 1 line
2.45.1
[PULL 24/42] stubs/meson: Fix qemuutil build when --disable-system
In reply to Paolo BonziniFrom: Zhao Liu <[email protected]>
Compiling without system, user, tools or guest-agent fails with the following error message:
./configure --disable-system --disable-user --disable-tools \
--disable-guest-agent
error message:
/usr/bin/ld: libqemuutil.a.p/util_error-report.c.o: in function `error_printf':
/media/liuzhao/data/qemu-cook/build/../util/error-report.c:38: undefined reference to error_vprintf' /usr/bin/ld: libqemuutil.a.p/util_error-report.c.o: in function vreport':
/media/liuzhao/data/qemu-cook/build/../util/error-report.c:215: undefined reference to `error_vprintf'
collect2: error: ld returned 1 exit status
This is because tests/bench and tests/unit both need qemuutil, which requires error_vprintf stub when system is disabled.
Add error_vprintf stub into stub_ss for all cases other than disabling system.
Message-ID: <[email protected]>
--- stubs/meson.build | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
stubs/meson.build +1 -7
@@ -3,6 +3,7 @@ # below, so that it is clear who needs the stubbed functionality. stub_ss.add(files('cpu-get-clock.c')) +stub_ss.add(files('error-printf.c')) stub_ss.add(files('fdset.c')) stub_ss.add(files('iothread-lock.c')) stub_ss.add(files('is-daemonized.c'))
@@ -45,17 +46,10 @@ if have_block or have_ga stub_ss.add(files('qmp-quit.c')) endif -if have_ga - stub_ss.add(files('error-printf.c')) -endif - if have_block or have_user stub_ss.add(files('qtest.c')) stub_ss.add(files('vm-stop.c')) stub_ss.add(files('vmstate.c')) - - # more symbols provided by the monitor - stub_ss.add(files('error-printf.c')) endif if have_user
Signature · 1 line
2.45.1
[PULL 23/42] scsi-disk: Don't silently truncate serial number
In reply to Paolo BonziniFrom: Kevin Wolf <[email protected]>
Before this commit, scsi-disk accepts a string of arbitrary length for its "serial" property. However, the value visible on the guest is actually truncated to 36 characters. This limitation doesn't come from the SCSI specification, it is an arbitrary limit that was initially picked as 20 and later bumped to 36 by commit 48b62063.
Similarly, device_id was introduced as a copy of the serial number, limited to 20 characters, but commit 48b62063 forgot to actually bump it.
As long as we silently truncate the given string, extending the limit is actually not a harmless change, but break the guest ABI. This is the most important reason why commit 48b62063 was really wrong (and it's also why we can't change device_id to be in sync with the serial number again and use 36 characters now, it would be another guest ABI breakage).
In order to avoid future breakage, don't silently truncate the serial number string any more, but just error out if it would be truncated.
Message-ID: <[email protected]>
--- hw/scsi/scsi-disk.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
hw/scsi/scsi-disk.c +17 -3
@@ -58,6 +58,9 @@#define TYPE_SCSI_DISK_BASE "scsi-disk-base" +#define MAX_SERIAL_LEN 36 +#define MAX_SERIAL_LEN_FOR_DEVID 20 + OBJECT_DECLARE_TYPE(SCSIDiskState, SCSIDiskClass, SCSI_DISK_BASE)struct SCSIDiskClass {
@@ -648,8 +651,8 @@ static int scsi_disk_emulate_vpd_page(SCSIRequest *req, uint8_t *outbuf) } l =strlen (s->serial); -if (l >36 ) { - l =36 ; +if (l >MAX_SERIAL_LEN ) { + l =MAX_SERIAL_LEN ; }trace_scsi_disk_emulate_vpd_page_80 (req->cmd.xfer);
@@ -2501,9 +2504,20 @@ static void scsi_realize(SCSIDevice *dev, Error **errp)if (!s->vendor) { s->vendor =g_strdup ("QEMU" ); } +if (s->serial &&strlen (s->serial) >MAX_SERIAL_LEN ) { +error_setg (errp,"The serial number can't be longer than %d characters" , +MAX_SERIAL_LEN ); +return ; + }if (!s->device_id) {if (s->serial) { - s->device_id =g_strdup_printf ("%.20s" , s->serial); +if (strlen (s->serial) >MAX_SERIAL_LEN_FOR_DEVID ) { +error_setg (errp,"The serial number can't be longer than %d " +"characters when it is also used as the default for " +"device_id" ,MAX_SERIAL_LEN_FOR_DEVID ); +return ; + } + s->device_id =g_strdup (s->serial); }else {const char *str =blk_name (s->qdev.conf.blk);if (str && *str) {
Signature · 1 line
2.45.1
[PULL 15/42] target/i386: fix size of EBP writeback in gen_enter()
In reply to Paolo BonziniFrom: Mark Cave-Ayland <[email protected]>
The calculation of FrameTemp is done using the size indicated by mo_pushpop() before being written back to EBP, but the final writeback to EBP is done using the size indicated by mo_stacksize().
In the case where mo_pushpop() is MO_32 and mo_stacksize() is MO_16 then the final writeback to EBP is done using MO_16 which can leave junk in the top 16-bits of EBP after executing ENTER.
Change the writeback of EBP to use the same size indicated by mo_pushpop() to ensure that the full value is written back.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2198
Message-ID: <[email protected]>
--- target/i386/tcg/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/tcg/translate.c +1 -1
@@ -2138,7 +2138,7 @@ static void gen_enter(DisasContext *s, int esp_addend, int level) }/* Copy the FrameTemp value to EBP. */ -gen_op_mov_reg_v (s, a_ot,R_EBP , s->T1); +gen_op_mov_reg_v (s, d_ot,R_EBP , s->T1);/* Compute the final value of ESP. */ tcg_gen_subi_tl (s->T1, s->T1, esp_addend + size * level);
Signature · 1 line
2.45.1
[PULL 37/42] docs: i386: pc: Avoid mentioning limit of maximum vCPUs
In reply to Paolo BonziniFrom: Zhao Liu <[email protected]>
Different versions of PC machine support different maximum vCPUs, and even different features have limits on the maximum number of vCPUs ( For example, if x2apic is not enabled in the TCG case, the maximum of 255 vCPUs are supported).
It is difficult to list the maximum vCPUs under all restrictions. Thus, to avoid confusion, avoid mentioning specific maximum vCPU number limitations here.
Message-ID: <[email protected]>
--- docs/system/target-i386-desc.rst.inc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
docs/system/target-i386-desc.rst.inc +2 -1
@@ -36,7 +36,8 @@ The QEMU PC System emulator simulates the following peripherals: - PCI UHCI, OHCI, EHCI or XHCI USB controller and a virtual USB-1.1 hub. -SMP is supported with up to 255 CPUs (and 4096 CPUs for PC Q35 machine). +SMP is supported with a large number of virtual CPUs (upper limit is +configuration dependent). QEMU uses the PC BIOS from the Seabios project and the Plex86/Bochs LGPL VGA BIOS.
Signature · 1 line
2.45.1
[PULL 06/42] target/i386: disable/enable breakpoints on vmentry/vmexit
In reply to Paolo BonziniIf the required DR7 (either from the VMCB or from the host save area) disables a breakpoint that was enabled prior to vmentry or vmexit, it is left enabled and will trigger EXCP_DEBUG. This causes a spurious #DB on the next crossing of the breakpoint.
To disable it, vmentry/vmexit must use cpu_x86_update_dr7 to load DR7.
Because cpu_x86_update_dr7 takes a 32-bit argument, check reserved bits prior to calling cpu_x86_update_dr7, and do the same for DR6 as well for consistency.
This scenario is tested by the "host_rflags" test in kvm-unit-tests.
--- target/i386/tcg/sysemu/svm_helper.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
target/i386/tcg/sysemu/svm_helper.c +15 -10
@@ -163,6 +163,8 @@ void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend)uint64_t new_cr0;uint64_t new_cr3;uint64_t new_cr4; +uint64_t new_dr6; +uint64_t new_dr7;if (aflag ==2 ) { addr = env->regs[R_EAX ];
@@ -361,20 +363,22 @@ void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend) env->vm_vmcb + offsetof(struct vmcb, save.rsp)); env->regs[R_EAX ] =x86_ldq_phys (cs, env->vm_vmcb + offsetof(struct vmcb, save.rax)); - env->dr[7 ] =x86_ldq_phys (cs, - env->vm_vmcb + offsetof(struct vmcb, save.dr7)); - env->dr[6 ] =x86_ldq_phys (cs, - env->vm_vmcb + offsetof(struct vmcb, save.dr6)); + + new_dr7 = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.dr7)); + new_dr6 = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.dr6));#ifdef TARGET_X86_64 -if (env->dr[6 ] &DR_RESERVED_MASK ) { +if (new_dr7 &DR_RESERVED_MASK ) {cpu_vmexit (env,SVM_EXIT_ERR ,0 ,GETPC ()); } -if (env->dr[7 ] &DR_RESERVED_MASK ) { +if (new_dr6 &DR_RESERVED_MASK ) {cpu_vmexit (env,SVM_EXIT_ERR ,0 ,GETPC ()); }#endif +cpu_x86_update_dr7 (env, new_dr7); + env->dr[6 ] = new_dr6; +if (is_efer_invalid_state (env)) {cpu_vmexit (env,SVM_EXIT_ERR ,0 ,GETPC ()); }
@@ -864,8 +868,11 @@ void do_vmexit(CPUX86State *env) env->dr[6 ] =x86_ldq_phys (cs, env->vm_hsave + offsetof(struct vmcb, save.dr6)); - env->dr[7 ] =x86_ldq_phys (cs, - env->vm_hsave + offsetof(struct vmcb, save.dr7)); + +/* Disables all breakpoints in the host DR7 register. */ +cpu_x86_update_dr7 (env, +x86_ldq_phys (cs, + env->vm_hsave + offsetof(struct vmcb, save.dr7)) & ~0xff);/* other setups */ x86_stl_phys(cs,
@@ -891,8 +898,6 @@ void do_vmexit(CPUX86State *env)from the page table indicated the host's CR3. If the PDPEs contain illegal state, the processor causes a shutdown. */ -/* Disables all breakpoints in the host DR7 register. */ -/* Checks the reloaded host state for consistency. */ /* If the host's rIP reloaded by #VMEXIT is outside the limit of the
Signature · 1 line
2.45.1
[PULL 36/42] target/i386: Add get/set/migrate support for FRED MSRs
In reply to Paolo BonziniFrom: Xin Li <[email protected]>
FRED CPU states are managed in 9 new FRED MSRs, in addtion to a few existing CPU registers and MSRs, e.g., CR4.FRED and MSR_IA32_PL0_SSP.
Save/restore/migrate FRED MSRs if FRED is exposed to the guest.
Message-ID: <[email protected]>
--- target/i386/cpu.h | 22 +++++++++++++++++++ target/i386/kvm/kvm.c | 49 +++++++++++++++++++++++++++++++++++++++++++ target/i386/machine.c | 28 +++++++++++++++++++++++++ 3 files changed, 99 insertions(+)
target/i386/cpu.h +22 -0
@@ -538,6 +538,17 @@ typedef enum X86Seg {#define MSR_IA32_XFD 0x000001c4#define MSR_IA32_XFD_ERR 0x000001c5 +/* FRED MSRs */ +#define MSR_IA32_FRED_RSP0 0x000001cc/* Stack level 0 regular stack pointer */ +#define MSR_IA32_FRED_RSP1 0x000001cd/* Stack level 1 regular stack pointer */ +#define MSR_IA32_FRED_RSP2 0x000001ce/* Stack level 2 regular stack pointer */ +#define MSR_IA32_FRED_RSP3 0x000001cf/* Stack level 3 regular stack pointer */ +#define MSR_IA32_FRED_STKLVLS 0x000001d0/* FRED exception stack levels */ +#define MSR_IA32_FRED_SSP1 0x000001d1/* Stack level 1 shadow stack pointer in ring 0 */ +#define MSR_IA32_FRED_SSP2 0x000001d2/* Stack level 2 shadow stack pointer in ring 0 */ +#define MSR_IA32_FRED_SSP3 0x000001d3/* Stack level 3 shadow stack pointer in ring 0 */ +#define MSR_IA32_FRED_CONFIG 0x000001d4/* FRED Entrypoint and interrupt stack level */ +#define MSR_IA32_BNDCFGS 0x00000d90#define MSR_IA32_XSS 0x00000da0#define MSR_IA32_UMWAIT_CONTROL 0xe1
@@ -1723,6 +1734,17 @@ typedef struct CPUArchState {target_ulong cstar;target_ulong fmask;target_ulong kernelgsbase; + +/* FRED MSRs */ +uint64_t fred_rsp0; +uint64_t fred_rsp1; +uint64_t fred_rsp2; +uint64_t fred_rsp3; +uint64_t fred_stklvls; +uint64_t fred_ssp1; +uint64_t fred_ssp2; +uint64_t fred_ssp3; +uint64_t fred_config;#endif uint64_t tsc_adjust;
target/i386/kvm/kvm.c +49 -0
67 lines not on this page · raw message
target/i386/machine.c +28 -0
@@ -1544,6 +1544,33 @@ static const VMStateDescription vmstate_msr_xfd = { };#ifdef TARGET_X86_64 +static bool intel_fred_msrs_needed (void *opaque) +{ +X86CPU *cpu = opaque; +CPUX86State *env = &cpu->env; + +return !!(env->features[FEAT_7_1_EAX ] &CPUID_7_1_EAX_FRED ); +} + +static const VMStateDescription vmstate_msr_fred = { + .name ="cpu/fred" , + .version_id =1 , + .minimum_version_id =1 , + .needed = intel_fred_msrs_needed, + .fields = (VMStateField []) { +VMSTATE_UINT64 (env.fred_rsp0,X86CPU ), +VMSTATE_UINT64 (env.fred_rsp1,X86CPU ), +VMSTATE_UINT64 (env.fred_rsp2,X86CPU ), +VMSTATE_UINT64 (env.fred_rsp3,X86CPU ), +VMSTATE_UINT64 (env.fred_stklvls,X86CPU ), +VMSTATE_UINT64 (env.fred_ssp1,X86CPU ), +VMSTATE_UINT64 (env.fred_ssp2,X86CPU ), +VMSTATE_UINT64 (env.fred_ssp3,X86CPU ), +VMSTATE_UINT64 (env.fred_config,X86CPU ), +VMSTATE_END_OF_LIST () + } + }; +static bool amx_xtile_needed (void *opaque) {X86CPU *cpu = opaque;
@@ -1747,6 +1774,7 @@ const VMStateDescription vmstate_x86_cpu = { &vmstate_pdptrs, &vmstate_msr_xfd, #ifdef TARGET_X86_64 + &vmstate_msr_fred, &vmstate_amx_xtile, #endif &vmstate_arch_lbr,
Signature · 1 line
2.45.1
[PULL 42/42] python: mkvenv: remove ensure command
In reply to Paolo BonziniThis was used to bootstrap the venv with a TOML parser, after which ensuregroup is used. Now that we expect it to be present as a system package (either tomli or, for Python 3.11, tomllib), it is not needed anymore.
Note that this means that, when implemented, the hypothetical "isolated" mode that does not use any system packages will only work with Python 3.11+.
--- python/scripts/mkvenv.py | 105 --------------------------------------- 1 file changed, 105 deletions(-)
python/scripts/mkvenv.py +0 -105
@@ -13,7 +13,6 @@ create create a venv post_init post-venv initialization - ensure Ensure that the specified package is installed. ensuregroup Ensure that the specified package group is installed.
@@ -36,18 +35,6 @@ -------------------------------------------------- -usage: mkvenv ensure [-h] [--online] [--dir DIR] dep_spec... - -positional arguments: - dep_spec PEP 508 Dependency specification, e.g. 'meson>=0.61.5' - -options: - -h, --help show this help message and exit - --online Install packages from PyPI, if necessary. - --dir DIR Path to vendored packages where we may install from. - --------------------------------------------------- - usage: mkvenv ensuregroup [-h] [--online] [--dir DIR] file group... positional arguments:
@@ -726,57 +713,6 @@ def _do_ensure( return None -def ensure( - dep_specs: Sequence[str], - online: bool = False, - wheels_dir: Optional[Union[str, Path]] = None, - prog: Optional[str] = None, -) -> None: - """ - Use pip to ensure we have the package specified by @dep_specs. - - If the package is already installed, do nothing. If online and - wheels_dir are both provided, prefer packages found in wheels_dir - first before connecting to PyPI. - - :param dep_specs: - PEP 508 dependency specifications. e.g. ['meson>=0.61.5']. - :param online: If True, fall back to PyPI. - :param wheels_dir: If specified, search this path for packages. - :param prog: - If specified, use this program name for error diagnostics that will - be presented to the user. e.g., 'sphinx-build' can be used as a - bellwether for the presence of 'sphinx'. - """ - - if not HAVE_DISTLIB: - raise Ouch("a usable distlib could not be found, please install it") - - # Convert the depspecs to a dictionary, as if they came - # from a section in a pythondeps.toml file - group: Dict[str, Dict[str, str]] = {} - for spec in dep_specs: - name = distlib.version.LegacyMatcher(spec).name - group[name] = {} - - spec = spec.strip() - pos = len(name) - ver = spec[pos:].strip() - if ver: - group[name]["accepted"] = ver - - if prog: - group[name]["canary"] = prog - prog = None - - result = _do_ensure(group, online, wheels_dir) - if result: - # Well, that's not good. - if result[1]: - raise Ouch(result[0]) - raise SystemExit(f"\n{result[0]}\n\n") - - def _parse_groups(file: str) -> Dict[str, Dict[str, Any]]: if not HAVE_TOMLLIB: if sys.version_info < (3, 11):
@@ -888,39 +824,6 @@ def _add_ensuregroup_subcommand(subparsers: Any) -> None: ) -def _add_ensure_subcommand(subparsers: Any) -> None: - subparser = subparsers.add_parser( - "ensure", help="Ensure that the specified package is installed." - ) - subparser.add_argument( - "--online", - action="store_true", - help="Install packages from PyPI, if necessary.", - ) - subparser.add_argument( - "--dir", - type=str, - action="store", - help="Path to vendored packages where we may install from.", - ) - subparser.add_argument( - "--diagnose", - type=str, - action="store", - help=( - "Name of a shell utility to use for " - "diagnostics if this command fails." - ), - ) - subparser.add_argument( - "dep_specs", - type=str, - action="store", - help="PEP 508 Dependency specification, e.g. 'meson>=0.61.5'", - nargs="+", - ) - - def main() -> int: """CLI interface to make_qemu_venv. See module docstring.""" if os.environ.get("DEBUG") or os.environ.get("GITLAB_CI"):
@@ -944,7 +847,6 @@ def main() -> int: _add_create_subcommand(subparsers) _add_post_init_subcommand(subparsers) - _add_ensure_subcommand(subparsers) _add_ensuregroup_subcommand(subparsers) args = parser.parse_args()
@@ -957,13 +859,6 @@ def main() -> int: ) if args.command == "post_init": post_venv_setup() - if args.command == "ensure": - ensure( - dep_specs=args.dep_specs, - online=args.online, - wheels_dir=args.dir, - prog=args.diagnose, - ) if args.command == "ensuregroup": ensure_group( file=args.file,
Signature · 1 line
2.45.1
[PULL 30/42] i386/hvf: Updates API usage to use modern vCPU run function
In reply to Paolo BonziniFrom: Phil Dennis-Jordan <[email protected]>
macOS 10.15 introduced the more efficient hv_vcpu_run_until() function to supersede hv_vcpu_run(). According to the documentation, there is no longer any reason to use the latter on modern host OS versions, especially after 11.0 added support for an indefinite deadline.
Observed behaviour of the newer function is that as documented, it exits much less frequently - and most of the original function’s exits seem to have been effectively pointless.
Another reason to use the new function is that it is a prerequisite for using newer features such as in-kernel APIC support. (Not covered by this patch.)
This change implements the upgrade by selecting one of three code paths at compile time: two static code paths for the new and old functions respectively, when building for targets where the new function is either not available, or where the built executable won’t run on older platforms lacking the new function anyway. The third code path selects dynamically based on runtime detected availability of the weakly-linked symbol.
Message-ID: <[email protected]>
--- target/i386/hvf/hvf.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
target/i386/hvf/hvf.c +22 -1
@@ -427,6 +427,27 @@ static void hvf_cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, } } +static hv_return_t hvf_vcpu_run (hv_vcpuid_t vcpu_id) +{ +/* +* hv_vcpu_run_until is available and recommended from macOS 10.15+, +* HV_DEADLINE_FOREVER from 11.0. Test for availability at runtime and fall +* back to hv_vcpu_run() only where necessary. +*/ +#ifndef MAC_OS_VERSION_11_0 +return hv_vcpu_run (vcpu_id); +#elif MAC_OS_X_VERSION_MIN_REQUIRED >=MAC_OS_VERSION_11_0 +return hv_vcpu_run_until (vcpu_id,HV_DEADLINE_FOREVER ); +#else /* MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_VERSION_11_0 */ +/* 11.0 SDK or newer, but could be < 11 at runtime */ + if (__builtin_available(macOS 11.0, *)) { +return hv_vcpu_run_until (vcpu_id,HV_DEADLINE_FOREVER ); + }else { +return hv_vcpu_run (vcpu_id); + } +#endif +} +int hvf_vcpu_exec (CPUState *cpu) {X86CPU *x86_cpu =X86_CPU (cpu);
@@ -455,7 +476,7 @@ int hvf_vcpu_exec(CPUState *cpu)return EXCP_HLT ; } -hv_return_t r =hv_vcpu_run (cpu->accel->fd); +hv_return_t r =hvf_vcpu_run (cpu->accel->fd);assert_hvf_ok (r);/* handle VMEXIT */
Signature · 1 line
2.45.1
[PULL 39/42] i386: Add support for SUCCOR feature
In reply to Paolo BonziniFrom: John Allen <[email protected]>
Add cpuid bit definition for the SUCCOR feature. This cpuid bit is required to be exposed to guests to allow them to handle machine check exceptions on AMD hosts.
----
v2:
- Add "succor" feature word.
- Add case to kvm_arch_get_supported_cpuid for the SUCCOR feature.
Message-ID: <[email protected]>
--- target/i386/cpu.h | 4 ++++ target/i386/cpu.c | 18 +++++++++++++++++- target/i386/kvm/kvm.c | 2 ++ 3 files changed, 23 insertions(+), 1 deletion(-)
target/i386/cpu.h +4 -0
@@ -630,6 +630,7 @@ typedef enum FeatureWord {FEAT_7_1_EAX ,/* CPUID[EAX=7,ECX=1].EAX */ FEAT_8000_0001_EDX ,/* CPUID[8000_0001].EDX */ FEAT_8000_0001_ECX ,/* CPUID[8000_0001].ECX */ +FEAT_8000_0007_EBX ,/* CPUID[8000_0007].EBX */ FEAT_8000_0007_EDX ,/* CPUID[8000_0007].EDX */ FEAT_8000_0008_EBX ,/* CPUID[8000_0008].EBX */ FEAT_8000_0021_EAX, /* CPUID[8000_0021].EAX */
@@ -982,6 +983,9 @@ uint64_t x86_cpu_get_supported_feature_word(FeatureWord w,/* Packets which contain IP payload have LIP values */ #define CPUID_14_0_ECX_LIP (1U << 31) +/* RAS Features */ +#define CPUID_8000_0007_EBX_SUCCOR (1U << 1) +/* CLZERO instruction */ #define CPUID_8000_0008_EBX_CLZERO (1U << 0)/* Always save/restore FP error pointers */
target/i386/cpu.c +17 -1
@@ -1180,6 +1180,22 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = { .tcg_features = TCG_APM_FEATURES, .unmigratable_flags = CPUID_APM_INVTSC, }, + [FEAT_8000_0007_EBX] = { + .type = CPUID_FEATURE_WORD, + .feat_names = { +NULL ,"succor" ,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, NULL, NULL, NULL, + }, + .cpuid = { .eax = 0x80000007, .reg = R_EBX, }, + .tcg_features =0 , + .unmigratable_flags = 0, + }, [FEAT_8000_0008_EBX] = { .type =CPUID_FEATURE_WORD , .feat_names = {
@@ -6887,7 +6903,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,break ;case 0x80000007 : *eax =0 ; - *ebx =0 ; + *ebx = env->features[FEAT_8000_0007_EBX ]; *ecx =0 ; *edx = env->features[FEAT_8000_0007_EDX ];break ;
target/i386/kvm/kvm.c +2 -0
@@ -532,6 +532,8 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,*/ cpuid_1_edx =kvm_arch_get_supported_cpuid (s,1 ,0 ,R_EDX ); ret |= cpuid_1_edx &CPUID_EXT2_AMD_ALIASES ; + }else if (function ==0x80000007 && reg ==R_EBX ) { + ret |=CPUID_8000_0007_EBX_SUCCOR ; }else if (function ==KVM_CPUID_FEATURES && reg ==R_EAX ) {/* kvm_pv_unhalt is reported by GET_SUPPORTED_CPUID, but it can't * be enabled without the in-kernel irqchip
Signature · 1 line
2.45.1
Re: [PULL 39/42] i386: Add support for SUCCOR feature
Quoted 16 lines · Paolo Bonzini
From: John Allen <[email protected]>
Add cpuid bit definition for the SUCCOR feature. This cpuid bit is required to be exposed to guests to allow them to handle machine check exceptions on AMD hosts.
----
v2:
- Add "succor" feature word.
- Add case tokvm_arch_get_supported_cpuidfor the SUCCOR feature.Reported-by William Roche <[email protected]>Reviewed-by Joao Martins <[email protected]>Signed-off-by John Allen <[email protected]>Message-ID: <[email protected]>
Signed-off-by Paolo Bonzini <[email protected]>
[snip]
...
target/i386/kvm/kvm.c uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, · line 536
Quoted 10 lines
target/i386/kvm/kvm.c +2
-0@@ -532,6 +532,8 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,*/ cpuid_1_edx =kvm_arch_get_supported_cpuid (s,1 ,0 ,R_EDX ); ret |= cpuid_1_edx &CPUID_EXT2_AMD_ALIASES ; + }else if (function ==0x80000007 && reg ==R_EBX ) { + ret |=CPUID_8000_0007_EBX_SUCCOR ;
IMO, this is incorrect.
Why make it supported unconditionally? Shouldn't there be a KVM patch to report it in KVM_GET_SUPPORTED_CPUID?
If make it supported unconditionally, all VMs boot with "-cpu host/max" will see the CPUID bits, even if it is Intel VMs.
Quoted 3 lines
target/i386/kvm/kvm.c +0
-0}else if (function ==KVM_CPUID_FEATURES && reg ==R_EAX ) {/* kvm_pv_unhalt is reported by GET_SUPPORTED_CPUID, but it can't * be enabled without the in-kernel irqchip
Re: [PULL 39/42] i386: Add support for SUCCOR feature
Quoted 34 lines · Xiaoyao Li
Quoted 16 lines · Paolo Bonzini
From: John Allen <[email protected]>
Add cpuid bit definition for the SUCCOR feature. This cpuid bit is required to be exposed to guests to allow them to handle machine check exceptions on AMD hosts.
----
v2:
- Add "succor" feature word.
- Add case tokvm_arch_get_supported_cpuidfor the SUCCOR feature.Reported-by William Roche <[email protected]>Reviewed-by Joao Martins <[email protected]>Signed-off-by John Allen <[email protected]>Message-ID: <[email protected]>
Signed-off-by Paolo Bonzini <[email protected]>[snip]
...target/i386/kvm/kvm.c uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, · line 536
Quoted 10 lines
target/i386/kvm/kvm.c +2
-0@@ -532,6 +532,8 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,*/ cpuid_1_edx =kvm_arch_get_supported_cpuid (s,1 ,0 ,R_EDX ); ret |= cpuid_1_edx &CPUID_EXT2_AMD_ALIASES ; + }else if (function ==0x80000007 && reg ==R_EBX ) { + ret |=CPUID_8000_0007_EBX_SUCCOR ;IMO, this is incorrect.
Quoted 5 lines
Why make it supported unconditionally? Shouldn't there be a KVM patch to report it in
KVM_GET_SUPPORTED_CPUID?If make it supported unconditionally, all VMs boot with "-cpu host/max" will see the CPUID bits, even if it is Intel VMs.
Paolo,
This change in kvm_arch_get_supported_cpuid was added based on your suggestion here:
https://lore.kernel.org/all/[email protected]/
Is there something missing from the patch needed to prevent the bits from being seen on Intel VMs?
I am planning to send a patch early this week to report the bits for KVM and a patch that removes the above change for qemu. Is there another way you would prefer to handle it?
Thanks,
John
Quoted 6 lines
Quoted 5 lines
target/i386/kvm/kvm.c +0
-0}else if (function ==KVM_CPUID_FEATURES && reg ==R_EAX ) {/* kvm_pv_unhalt is reported by GET_SUPPORTED_CPUID, but it can't * be enabled without the in-kernel irqchip
Re: [PULL 39/42] i386: Add support for SUCCOR feature
In reply to Xiaoyao LiQuoted 35 lines · Xiaoyao Li
Quoted 16 lines · Paolo Bonzini
From: John Allen <[email protected]>
Add cpuid bit definition for the SUCCOR feature. This cpuid bit is required to be exposed to guests to allow them to handle machine check exceptions on AMD hosts.
----
v2:
- Add "succor" feature word.
- Add case tokvm_arch_get_supported_cpuidfor the SUCCOR feature.Reported-by William Roche <[email protected]>Reviewed-by Joao Martins <[email protected]>Signed-off-by John Allen <[email protected]>Message-ID: <[email protected]>
Signed-off-by Paolo Bonzini <[email protected]>[snip]
...target/i386/kvm/kvm.c uint32_t kvm_arch_get_supported_cpuid(KVMState *s, · line 537
Quoted 11 lines
target/i386/kvm/kvm.c +2
-0@@ -532,6 +532,8 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s,uint32_t function, */ cpuid_1_edx = kvm_arch_get_supported_cpuid(s, 1, 0, R_EDX); ret |= cpuid_1_edx & CPUID_EXT2_AMD_ALIASES; + } else if (function == 0x80000007 && reg == R_EBX) { + ret |= CPUID_8000_0007_EBX_SUCCOR;IMO, this is incorrect.
Quoted 1 line
Why make it supported unconditionally? Shouldn't there be a KVM patch to report it in
KVM_GET_SUPPORTED_CPUID?
Yes, but since the bit doesn't need any hypervisor support it is common to also add it in QEMU.
Quoted 1 line
If make it supported unconditionally, all VMs boot with "-cpu host/max" will see the CPUID bits, even if it is Intel VMs.
It should be harmless, but you're right, it's not tidy and we don't know for sure that it doesn't trigger weird paths in guest OSes. I've send a series to fix this.
Paolo
[PULL 35/42] target/i386: enumerate VMX nested-exception support
In reply to Paolo BonziniFrom: Xin Li <[email protected]>
Allow VMX nested-exception support to be exposed in KVM guests, thus nested KVM guests can enumerate it.
Message-ID: <[email protected]>
--- target/i386/cpu.h | 1 + target/i386/cpu.c | 1 + scripts/kvm/vmxcap | 1 + 3 files changed, 3 insertions(+)
target/i386/cpu.h +1 -0
@@ -1071,6 +1071,7 @@ uint64_t x86_cpu_get_supported_feature_word(FeatureWord w,#define MSR_VMX_BASIC_INS_OUTS (1ULL << 54)#define MSR_VMX_BASIC_TRUE_CTLS (1ULL << 55)#define MSR_VMX_BASIC_ANY_ERRCODE (1ULL << 56) +#define MSR_VMX_BASIC_NESTED_EXCEPTION (1ULL << 58)#define MSR_VMX_MISC_PREEMPTION_TIMER_SHIFT_MASK 0x1Full#define MSR_VMX_MISC_STORE_LMA (1ULL << 5)
target/i386/cpu.c +1 -0
@@ -1492,6 +1492,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = { [54] = "vmx-ins-outs", [55] = "vmx-true-ctls", [56] = "vmx-any-errcode", + [58 ] ="vmx-nested-exception" , }, .msr = { .index =MSR_IA32_VMX_BASIC ,
scripts/kvm/vmxcap +1 -0
@@ -117,6 +117,7 @@ controls = [ 54: 'INS/OUTS instruction information', 55: 'IA32_VMX_TRUE_*_CTLS support', 56: 'Skip checks on event error code', + 58: 'VMX nested exception support', }, msr = MSR_IA32_VMX_BASIC, ),
Signature · 1 line
2.45.1
[PULL 22/42] hostmem: simplify the code for merge and dump properties
In reply to Paolo BonziniNo semantic change, just simpler control flow.
--- backends/hostmem.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-)
backends/hostmem.c +8 -14
@@ -178,19 +178,16 @@ static void host_memory_backend_set_merge(Object *obj, bool value, Error **errp)return ; } -if (!host_memory_backend_mr_inited (backend)) { - backend->merge = value; -return ; - } - -if (value != backend->merge) { +if (!host_memory_backend_mr_inited (backend) && + value != backend->merge) {void *ptr =memory_region_get_ram_ptr (&backend->mr);uint64_t sz =memory_region_size (&backend->mr);qemu_madvise (ptr, sz, value ?QEMU_MADV_MERGEABLE :QEMU_MADV_UNMERGEABLE ); - backend->merge = value; } + + backend->merge = value; }static bool host_memory_backend_get_dump (Object *obj,Error **errp)
@@ -212,19 +209,16 @@ static void host_memory_backend_set_dump(Object *obj, bool value, Error **errp)return ; } -if (!host_memory_backend_mr_inited (backend)) { - backend->dump = value; -return ; - } - -if (value != backend->dump) { +if (host_memory_backend_mr_inited (backend) && + value != backend->dump) {void *ptr =memory_region_get_ram_ptr (&backend->mr);uint64_t sz =memory_region_size (&backend->mr);qemu_madvise (ptr, sz, value ?QEMU_MADV_DODUMP :QEMU_MADV_DONTDUMP ); - backend->dump = value; } + + backend->dump = value; }static bool host_memory_backend_get_prealloc (Object *obj,Error **errp)
Signature · 1 line
2.45.1
[PULL 17/42] meson: Don't even detect posix_madvise() on Darwin
In reply to Paolo BonziniFrom: Michal Privoznik <[email protected]>
On Darwin, posix_madvise() has the same return semantics as plain madvise() [1]. That's not really what our usage expects. Fortunately, madvise() is available and preferred anyways so we may stop detecting posix_madvise() on Darwin.
1: https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/man/man2/madvise.2.auto.html
Message-ID: <00f71753bdeb8c0f049fda05fb63b84bb5502fb3.1717584048.git.mprivozn@redhat.com>
--- meson.build | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
meson.build +10 -4
@@ -2556,10 +2556,16 @@ config_host_data.set('CONFIG_OPEN_BY_HANDLE', cc.links(gnu_source_prefix + ''' #else int main(void) { struct file_handle fh; return open_by_handle_at(0, &fh, 0); } #endif''')) -config_host_data.set('CONFIG_POSIX_MADVISE', cc.links(gnu_source_prefix + ''' - #include <sys/mman.h> - #include <stddef.h> - int main(void) { return posix_madvise(NULL, 0, POSIX_MADV_DONTNEED); }''')) + +# On Darwin posix_madvise() has the same return semantics as plain madvise(), +# i.e. errno is set and -1 is returned. That's not really how POSIX defines the +# function. On the flip side, it has madvise() which is preferred anyways. +if host_os != 'darwin' + config_host_data.set('CONFIG_POSIX_MADVISE', cc.links(gnu_source_prefix + ''' + #include <sys/mman.h> + #include <stddef.h> + int main(void) { return posix_madvise(NULL, 0, POSIX_MADV_DONTNEED); }''')) +endif config_host_data.set('CONFIG_PTHREAD_SETNAME_NP_W_TID', cc.links(gnu_source_prefix + ''' #include <pthread.h>
Signature · 1 line
2.45.1
[PULL 29/42] i386/hvf: In kick_vcpu use hv_vcpu_interrupt to force exit
In reply to Paolo BonziniFrom: Phil Dennis-Jordan <[email protected]>
When interrupting a vCPU thread, this patch actually tells the hypervisor to stop running guest code on that vCPU.
Calling hv_vcpu_interrupt actually forces a vCPU exit, analogously to hv_vcpus_exit on aarch64. Alternatively, if the vCPU thread is not
running the VM, it will immediately cause an exit when it attempts to do so.
Previously, hvf_kick_vcpu_thread relied upon hv_vcpu_run returning very frequently, including many spurious exits, which made it less of a problem that nothing was actively done to stop the vCPU thread running guest code. The newer, more efficient hv_vcpu_run_until exits much more rarely, so a true "kick" is needed before switching to that.
Message-ID: <[email protected]>
--- target/i386/hvf/hvf.c | 1 + 1 file changed, 1 insertion(+)
target/i386/hvf/hvf.c +1 -0
@@ -215,6 +215,7 @@ static inline bool apic_bus_freq_is_known(CPUX86State *env)void hvf_kick_vcpu_thread (CPUState *cpu) {cpus_kick_thread (cpu); +hv_vcpu_interrupt (&cpu->accel->fd,1 ); }int hvf_arch_init (void )
Signature · 1 line
2.45.1
[PULL 25/42] i386/hvf: Adds support for INVTSC cpuid bit
In reply to Paolo BonziniFrom: Phil Dennis-Jordan <[email protected]>
This patch adds the INVTSC bit to the Hypervisor.framework accelerator's CPUID bit passthrough allow-list. Previously, specifying +invtsc in the CPU configuration would fail with the following warning despite the host CPU advertising the feature:
qemu-system-x86_64: warning: host doesn't support requested feature:
CPUID.80000007H:EDX.invtsc [bit 8]
x86 macOS itself relies on a fixed rate TSC for its own Mach absolute time timestamp mechanism, so there's no reason we can't enable this bit for guests. When the feature is enabled, a migration blocker is installed.
Message-ID: <[email protected]>
--- target/i386/hvf/hvf.c | 18 ++++++++++++++++++ target/i386/hvf/x86_cpuid.c | 4 ++++ 2 files changed, 22 insertions(+)
target/i386/hvf/hvf.c +18 -0
@@ -49,6 +49,8 @@#include "qemu/osdep.h" #include "qemu/error-report.h" #include "qemu/memalign.h" +#include "qapi/error.h" +#include "migration/blocker.h" #include "sysemu/hvf.h" #include "sysemu/hvf_int.h"
@@ -74,6 +76,8 @@#include "qemu/accel.h" #include "target/i386/cpu.h" +static Error *invtsc_mig_blocker; +void vmx_update_tpr (CPUState *cpu) {/* TODO: need integrate APIC handling */
@@ -221,6 +225,8 @@ int hvf_arch_init_vcpu(CPUState *cpu) {X86CPU *x86cpu =X86_CPU (cpu);CPUX86State *env = &x86cpu->env; +Error *local_err =NULL ; +int r;uint64_t reqCap;init_emu ();
@@ -238,6 +244,18 @@ int hvf_arch_init_vcpu(CPUState *cpu) } } +if ((env->features[FEAT_8000_0007_EDX ] &CPUID_APM_INVTSC ) && + invtsc_mig_blocker ==NULL ) { +error_setg (&invtsc_mig_blocker, +"State blocked by non-migratable CPU device (invtsc flag)" ); + r =migrate_add_blocker (&invtsc_mig_blocker, &local_err); +if (r <0 ) { +error_report_err (local_err); +return r; + } + } + +if (hv_vmx_read_capability (HV_VMX_CAP_PINBASED , &hvf_state->hvf_caps->vmx_cap_pinbased)) {abort ();
target/i386/hvf/x86_cpuid.c +4 -0
@@ -146,6 +146,10 @@ uint32_t hvf_get_supported_cpuid(uint32_t func, uint32_t idx,CPUID_EXT3_3DNOWPREFETCH |CPUID_EXT3_OSVW |CPUID_EXT3_XOP |CPUID_EXT3_FMA4 |CPUID_EXT3_TBM ;break ; +case 0x80000007 : + edx &=CPUID_APM_INVTSC ; + eax = ebx = ecx =0 ; +break ;default :return 0 ; }
Signature · 1 line
2.45.1
[PULL 11/42] target/i386: document use of DISAS_NORETURN
In reply to Paolo BonziniDISAS_NORETURN suppresses the work normally done by gen_eob(), and therefore must be used in special cases only. Document them.
--- target/i386/tcg/translate.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
target/i386/tcg/translate.c +11 -0
@@ -4761,6 +4761,17 @@ static void i386_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)switch (dc->base.is_jmp) {case DISAS_NORETURN : +/* +* Most instructions should not use DISAS_NORETURN, as that suppresses +* the handling of hflags normally done by gen_eob(). We can +* get here: +* - for exception and interrupts +* - for jump optimization (which is disabled by INHIBIT_IRQ/RF/TF) +* - for VMRUN because RF/TF handling for the host is done after vmexit, +* and INHIBIT_IRQ is loaded from the VMCB +* - for HLT/PAUSE/MWAIT to exit the main loop with specific EXCP_* values; +* the helpers handle themselves the tasks normally done by gen_eob(). +*/ break ;case DISAS_TOO_MANY :gen_update_cc_op (dc);
Signature · 1 line
2.45.1
[PULL 33/42] target/i386: mark CR4.FRED not reserved
In reply to Paolo BonziniFrom: Xin Li <[email protected]>
The CR4.FRED bit, i.e., CR4[32], is no longer a reserved bit when FRED is exposed to guests, otherwise it is still a reserved bit.
Message-ID: <[email protected]>
--- target/i386/cpu.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
target/i386/cpu.h +16 -1
@@ -261,6 +261,18 @@ typedef enum X86Seg {#define CR4_PKS_MASK (1U << 24)#define CR4_LAM_SUP_MASK (1U << 28) +#ifdef TARGET_X86_64 +#define CR4_FRED_MASK (1ULL << 32) +#else +#define CR4_FRED_MASK 0 +#endif + +#ifdef TARGET_X86_64 +#define CR4_FRED_MASK (1ULL << 32) +#else +#define CR4_FRED_MASK 0 +#endif +#define CR4_RESERVED_MASK \ (~(target_ulong)(CR4_VME_MASK | CR4_PVI_MASK | CR4_TSD_MASK \ | CR4_DE_MASK | CR4_PSE_MASK | CR4_PAE_MASK \
@@ -269,7 +281,7 @@ typedef enum X86Seg { | CR4_LA57_MASK \ | CR4_FSGSBASE_MASK | CR4_PCIDE_MASK | CR4_OSXSAVE_MASK \ | CR4_SMEP_MASK | CR4_SMAP_MASK | CR4_PKE_MASK | CR4_PKS_MASK \ - | CR4_LAM_SUP_MASK)) + | CR4_LAM_SUP_MASK | CR4_FRED_MASK))#define DR6_BD (1 << 13)#define DR6_BS (1 << 14)
@@ -2613,6 +2625,9 @@ static inline uint64_t cr4_reserved_bits(CPUX86State *env)if (!(env->features[FEAT_7_1_EAX ] &CPUID_7_1_EAX_LAM )) { reserved_bits |=CR4_LAM_SUP_MASK ; } +if (!(env->features[FEAT_7_1_EAX ] &CPUID_7_1_EAX_FRED )) { + reserved_bits |=CR4_FRED_MASK ; + }return reserved_bits; }
Signature · 1 line
2.45.1
[PULL 05/42] target/i386: implement DR7.GD
In reply to Paolo BonziniDR7.GD triggers a #DB exception on any access to debug registers. The GD bit is cleared so that the #DB handler itself can access the debug registers.
--- target/i386/tcg/sysemu/bpt_helper.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
target/i386/tcg/sysemu/bpt_helper.c +12 -0
@@ -238,6 +238,12 @@ target_ulong helper_get_dr(CPUX86State *env, int reg) } } +if (env->dr[7 ] &DR7_GD ) { + env->dr[7 ] &= ~DR7_GD ; + env->dr[6 ] |=DR6_BD ; +raise_exception_ra (env,EXCP01_DB ,GETPC ()); + } +return env->dr[reg]; }
@@ -251,6 +257,12 @@ void helper_set_dr(CPUX86State *env, int reg, target_ulong t0) } } +if (env->dr[7 ] &DR7_GD ) { + env->dr[7 ] &= ~DR7_GD ; + env->dr[6 ] |=DR6_BD ; +raise_exception_ra (env,EXCP01_DB ,GETPC ()); + } +if (reg <4 ) {if (hw_breakpoint_enabled (env->dr[7 ], reg) &&hw_breakpoint_type (env->dr[7 ], reg) !=DR7_TYPE_IO_RW ) {
Signature · 1 line
2.45.1
[PULL 40/42] i386: Add support for overflow recovery
In reply to Paolo BonziniFrom: John Allen <[email protected]>
Add cpuid bit definition for overflow recovery. This is needed in the case where a deferred error has been sent to the guest, a guest process accesses the poisoned memory, but the machine_check_poll function has not yet handled the original deferred error. If overflow recovery is not set in this case, when we handle the uncorrected error from the poisoned memory access, the overflow bit will be set and will result in the guest being shut down.
By the time the MCE reaches the guest, the overflow has been handled by the host and has not caused a shutdown, so include the bit unconditionally.
Message-ID: <[email protected]>
--- target/i386/cpu.h | 1 + target/i386/cpu.c | 2 +- target/i386/kvm/kvm.c | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-)
target/i386/cpu.h +1 -0
@@ -984,6 +984,7 @@ uint64_t x86_cpu_get_supported_feature_word(FeatureWord w,#define CPUID_14_0_ECX_LIP (1U << 31)/* RAS Features */ +#define CPUID_8000_0007_EBX_OVERFLOW_RECOV (1U << 0)#define CPUID_8000_0007_EBX_SUCCOR (1U << 1)/* CLZERO instruction */
target/i386/cpu.c +1 -1
@@ -1183,7 +1183,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = { [FEAT_8000_0007_EBX] = { .type = CPUID_FEATURE_WORD, .feat_names = { -NULL ,"succor" ,NULL ,NULL , +"overflow-recov" ,"succor" ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL , NULL, NULL, NULL, NULL,
target/i386/kvm/kvm.c +1 -1
@@ -533,7 +533,7 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function, cpuid_1_edx =kvm_arch_get_supported_cpuid (s,1 ,0 ,R_EDX ); ret |= cpuid_1_edx &CPUID_EXT2_AMD_ALIASES ; }else if (function ==0x80000007 && reg ==R_EBX ) { - ret |=CPUID_8000_0007_EBX_SUCCOR ; + ret |=CPUID_8000_0007_EBX_OVERFLOW_RECOV |CPUID_8000_0007_EBX_SUCCOR ; }else if (function ==KVM_CPUID_FEATURES && reg ==R_EAX ) {/* kvm_pv_unhalt is reported by GET_SUPPORTED_CPUID, but it can't * be enabled without the in-kernel irqchip
Signature · 1 line
2.45.1
[PULL 21/42] machine, hostmem: improve error messages for unsupported features
In reply to Paolo BonziniDetect early unsupported MADV_MERGEABLE and MADV_DONTDUMP, and print a clearer error message that points to the deficiency of the host.
--- backends/hostmem.c | 16 ++++++++++++++++ hw/core/machine.c | 8 ++++++++ 2 files changed, 24 insertions(+)
backends/hostmem.c +16 -0
@@ -170,6 +170,14 @@ static void host_memory_backend_set_merge(Object *obj, bool value, Error **errp) {HostMemoryBackend *backend =MEMORY_BACKEND (obj); +if (QEMU_MADV_MERGEABLE ==QEMU_MADV_INVALID ) { +if (value) { +error_setg (errp,"Memory merging is not supported on this host" ); + } +assert (!backend->merge); +return ; + } +if (!host_memory_backend_mr_inited (backend)) { backend->merge = value;return ;
@@ -196,6 +204,14 @@ static void host_memory_backend_set_dump(Object *obj, bool value, Error **errp) {HostMemoryBackend *backend =MEMORY_BACKEND (obj); +if (QEMU_MADV_DONTDUMP ==QEMU_MADV_INVALID ) { +if (!value) { +error_setg (errp,"Dumping guest memory cannot be disabled on this host" ); + } +assert (backend->dump); +return ; + } +if (!host_memory_backend_mr_inited (backend)) { backend->dump = value;return ;
hw/core/machine.c +8 -0
@@ -428,6 +428,10 @@ static void machine_set_dump_guest_core(Object *obj, bool value, Error **errp) {MachineState *ms =MACHINE (obj); +if (!value &&QEMU_MADV_DONTDUMP ==QEMU_MADV_INVALID ) { +error_setg (errp,"Dumping guest memory cannot be disabled on this host" ); +return ; + } ms->dump_guest_core = value; }
@@ -442,6 +446,10 @@ static void machine_set_mem_merge(Object *obj, bool value, Error **errp) {MachineState *ms =MACHINE (obj); +if (value &&QEMU_MADV_MERGEABLE ==QEMU_MADV_INVALID ) { +error_setg (errp,"Memory merging is not supported on this host" ); +return ; + } ms->mem_merge = value; }
Signature · 1 line
2.45.1
[PULL 28/42] i386/hvf: Fixes dirty memory tracking by page granularity RX->RWX change
In reply to Paolo BonziniFrom: Phil Dennis-Jordan <[email protected]>
When using x86 macOS Hypervisor.framework as accelerator, detection of dirty memory regions is implemented by marking logged memory region slots as read-only in the EPT, then setting the dirty flag when a guest write causes a fault. The area marked dirty should then be marked writable in order for subsequent writes to succeed without a VM exit.
However, dirty bits are tracked on a per-page basis, whereas the fault handler was marking the whole logged memory region as writable. This change fixes the fault handler so only the protection of the single faulting page is marked as dirty.
(Note: the dirty page tracking appeared to work despite this error because HVF’s hv_vcpu_run() function generated unnecessary EPT fault exits, which ended up causing the dirty marking handler to run even when the memory region had been marked RW. When using hv_vcpu_run_until(), a change planned for a subsequent commit, these spurious exits no longer occur, so dirty memory tracking malfunctions.)
Additionally, the dirty page is set to permit code execution, the same as all other guest memory; changing memory protection from RX to RW not RWX appears to have been an oversight.
Message-ID: <[email protected]>
--- target/i386/hvf/hvf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
target/i386/hvf/hvf.c +3 -2
@@ -135,9 +135,10 @@ static bool ept_emulation_fault(hvf_slot *slot, uint64_t gpa, uint64_t ept_qual)if (write && slot) {if (slot->flags &HVF_SLOT_LOG ) { +uint64_t dirty_page_start = gpa & ~(TARGET_PAGE_SIZE -1u );memory_region_set_dirty (slot->region, gpa - slot->start,1 ); -hv_vm_protect ((hv_gpaddr_t )slot->start, (size_t )slot->size, -HV_MEMORY_READ |HV_MEMORY_WRITE ); +hv_vm_protect (dirty_page_start,TARGET_PAGE_SIZE , +HV_MEMORY_READ |HV_MEMORY_WRITE |HV_MEMORY_EXEC ); } }
Signature · 1 line
2.45.1
Richard Henderson
AppliedQuoted 12 lines · Paolo Bonzini
The following changes since commit
f1572ab94738bd5787b7badcd4bd93a3657f0680:Merge tag 'for-upstream' ofhttps://gitlab.com/bonzini/qemu into staging (2024-06-05 07:45:23 -0700)are available in the Git repository at:
https://gitlab.com/bonzini/qemu.git tags/for-upstream
for you to fetch changes up to
fc00123f3abeb027cd51eb58ea8845377794b3bc:python: mkvenv: remove ensure command (2024-06-08 10:33:39 +0200)
Quoted 11 lines
----------------------------------------------------------------
* scsi-disk: Don't silently truncate serial number
* backends/hostmem: Report error on unavailableqemu_madvise()features or unaligned memory sizes
* target/i386: fixes and documentation for INHIBIT_IRQ/TF/RF and debugging
* i386/hvf: Adds support for INVTSC cpuid bit
* i386/hvf: Fixes for dirty memory tracking
* i386/hvf: Usehv_vcpu_interrupt()andhv_vcpu_run_until()
* hvf: Cleanups
* stubs: fixes for --disable-system build
* i386/kvm: support for FRED
* i386/kvm: fix MCE handling on AMD hosts
Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/9.1 as appropriate.
r~