target/i386: hax: Move hax_setup_qemu_emulator.
PATCH 1/1 target/i386: hax: Move hax_setup_qemu_emulator.
hax_setup_qemu_emulator reference env->efer which is updated in hax_get_msrs, so it has to be called after hax_get_msrs. This fix the bug that sometimes dump_state show 32 bits regs even in 64 bits mode.
--- target/i386/hax-all.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
target/i386/hax-all.c +1 -3
@@ -887,9 +887,6 @@ static int hax_sync_vcpu_register(CPUArchState *env, int set)return -1 ; } } -if (!set) { -hax_setup_qemu_emulator (env); - }return 0 ; }
@@ -1070,6 +1067,7 @@ static int hax_arch_get_registers(CPUArchState *env)return ret; } +hax_setup_qemu_emulator (env);return 0 ; }
Signature · 1 line
2.16.0.rc1.238.g530d649a79-goog
Paolo Bonzini
AppliedQuoted 26 lines · Tao Wu
hax_setup_qemu_emulatorreferenceenv->eferwhich is updated inhax_get_msrs, so it has to be called afterhax_get_msrs. This fix the bug that sometimesdump_stateshow 32 bits regs even in 64 bits mode.Signed-off-by Tao Wu <[email protected]>--- target/i386/hax-all.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)target/i386/hax-all.c +0
-3@@ -887,9 +887,6 @@ static int hax_sync_vcpu_register(CPUArchState *env, int set)return -1 ; } } -if (!set) { -hax_setup_qemu_emulator (env); - }return 0 ; }
target/i386/hax-all.c static int hax_arch_get_registers(CPUArchState *env) · line 1073
Quoted 7 lines
target/i386/hax-all.c +1
-0@@ -1070,6 +1067,7 @@ static int hax_arch_get_registers(CPUArchState *env)return ret; } +hax_setup_qemu_emulator (env);return 0 ; }
Queued, thanks.
Please look into sharing the similar code in target/i386/kvm.c (kvm_get_sregs), since the HAX code has some bugs (for example, HF_CPL_MASK should be SS.DPL, not CS.DPL).
Paolo
Thanks. Then it seems I should put this piece of code in a common function first and then update this CL.
Quoted 42 lines · Paolo Bonzini
Quoted 26 lines · Tao Wu
hax_setup_qemu_emulatorreferenceenv->eferwhich is updated inhax_get_msrs, so it has to be called afterhax_get_msrs. This fix the bug that sometimesdump_stateshow 32 bits regs even in 64 bits mode.Signed-off-by Tao Wu <[email protected]>--- target/i386/hax-all.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)target/i386/hax-all.c +0
-3@@ -887,9 +887,6 @@ static int hax_sync_vcpu_register(CPUArchState *env, int set)return -1 ; } } -if (!set) { -hax_setup_qemu_emulator (env); - }return 0 ; }target/i386/hax-all.c static int hax_arch_get_registers(CPUArchState *env) · line 1073
Quoted 7 lines
target/i386/hax-all.c +1
-0@@ -1070,6 +1067,7 @@ static int hax_arch_get_registers(CPUArchState *env)return ret; } +hax_setup_qemu_emulator (env);return 0 ; }Queued, thanks.
Please look into sharing the similar code in
target/i386/kvm.c(kvm_get_sregs), since the HAX code has some bugs (for example,HF_CPL_MASKshould be SS.DPL, not CS.DPL).Paolo
PATCH v2 1/3 target/i386: move hflags update code to a function
In reply to Tao WuWe will share the same code for hax/kvm.
--- target/i386/Makefile.objs | 2 +- target/i386/common_i386.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++ target/i386/common_i386.h | 14 +++++++++++++ target/i386/kvm.c | 41 ++------------------------------------ 4 files changed, 67 insertions(+), 40 deletions(-) create mode 100644 target/i386/common_i386.c create mode 100644 target/i386/common_i386.h
target/i386/Makefile.objs +1 -1
@@ -1,4 +1,4 @@ -obj-y += helper.o cpu.o gdbstub.o xsave_helper.o +obj-y += helper.o cpu.o gdbstub.o xsave_helper.o common_i386.o obj-$(CONFIG_TCG) += translate.o obj-$(CONFIG_TCG) += bpt_helper.o cc_helper.o excp_helper.o fpu_helper.o obj-$(CONFIG_TCG) += int_helper.o mem_helper.o misc_helper.o mpx_helper.o
target/i386/common_i386.c new file +50 -0
50 lines not on this page · raw message
target/i386/common_i386.h new file +14 -0
@@ -0,0 +1,14 @@ +/* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef TARGET_I386_COMMON_I386_H +#define TARGET_I386_COMMON_I386_H + +#include "qemu/osdep.h" +#include "cpu.h" + +void x86_update_hflags (CPUX86State * env); + +#endif
target/i386/kvm.c +2 -39
59 lines not on this page · raw message
Signature · 1 line
2.16.0.rc1.238.g530d649a79-goog
PATCH v2 2/3 target/i386: hax: change to use x86_update_hflags
Change to use x86_update_hflags instead of keeping another copy at hax side. This also fix bug like HF_CPL_MASK should be SS.DPL, not CS.DPL.
--- target/i386/hax-all.c | 53 ++------------------------------------------------- 1 file changed, 2 insertions(+), 51 deletions(-)
target/i386/hax-all.c +2 -51
@@ -31,6 +31,7 @@#include "qemu-common.h" #include "strings.h" +#include "common_i386.h" #include "hax-i386.h" #include "sysemu/accel.h" #include "sysemu/sysemu.h"
@@ -782,56 +783,6 @@ static int hax_set_segments(CPUArchState *env, struct vcpu_state_t *sregs)return 0 ; } -/* -* After get the state from the kernel module, some -* qemu emulator state need be updated also -*/ -static int hax_setup_qemu_emulator (CPUArchState *env) -{ - -#define HFLAG_COPY_MASK (~( \ - HF_CPL_MASK | HF_PE_MASK | HF_MP_MASK | HF_EM_MASK | \ - HF_TS_MASK | HF_TF_MASK | HF_VM_MASK | HF_IOPL_MASK | \ - HF_OSFXSR_MASK | HF_LMA_MASK | HF_CS32_MASK | \ - HF_SS32_MASK | HF_CS64_MASK | HF_ADDSEG_MASK)) - -uint32_t hflags; - - hflags = (env->segs[R_CS ].flags >>DESC_DPL_SHIFT ) &HF_CPL_MASK ; - hflags |= (env->cr[0 ] &CR0_PE_MASK ) << (HF_PE_SHIFT -CR0_PE_SHIFT ); - hflags |= (env->cr[0 ] << (HF_MP_SHIFT -CR0_MP_SHIFT )) & - (HF_MP_MASK |HF_EM_MASK |HF_TS_MASK ); - hflags |= (env->eflags & (HF_TF_MASK |HF_VM_MASK |HF_IOPL_MASK )); - hflags |= (env->cr[4 ] &CR4_OSFXSR_MASK ) << - (HF_OSFXSR_SHIFT -CR4_OSFXSR_SHIFT ); - -if (env->efer &MSR_EFER_LMA ) { - hflags |=HF_LMA_MASK ; - } - -if ((hflags &HF_LMA_MASK ) && (env->segs[R_CS ].flags &DESC_L_MASK )) { - hflags |=HF_CS32_MASK |HF_SS32_MASK |HF_CS64_MASK ; - }else { - hflags |= (env->segs[R_CS ].flags &DESC_B_MASK ) >> - (DESC_B_SHIFT -HF_CS32_SHIFT ); - hflags |= (env->segs[R_SS ].flags &DESC_B_MASK ) >> - (DESC_B_SHIFT -HF_SS32_SHIFT ); -if (!(env->cr[0 ] &CR0_PE_MASK ) || - (env->eflags &VM_MASK ) || !(hflags &HF_CS32_MASK )) { - hflags |=HF_ADDSEG_MASK ; - }else { - hflags |= ((env->segs[R_DS ].base | - env->segs[R_ES ].base | - env->segs[R_SS ].base) !=0 ) <<HF_ADDSEG_SHIFT ; - } - } - - hflags &= ~HF_SMM_MASK ; - - env->hflags = (env->hflags &HFLAG_COPY_MASK ) | hflags; -return 0 ; -} -static int hax_sync_vcpu_register (CPUArchState *env,int set) {struct vcpu_state_t regs;
@@ -888,7 +839,7 @@ static int hax_sync_vcpu_register(CPUArchState *env, int set) } }if (!set) { -hax_setup_qemu_emulator (env); +x86_update_hflags (env); }return 0 ; }
Signature · 1 line
2.16.0.rc1.238.g530d649a79-goog
PATCH v2 3/3 target/i386: hax: Move x86_update_hflags.
In reply to Tao Wux86_update_hflags reference env->efer which is updated in hax_get_msrs, so it has to be called after hax_get_msrs. This fix the bug that sometimes dump_state show 32 bits regs even in 64 bits mode.
--- target/i386/hax-all.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
target/i386/hax-all.c +1 -3
@@ -838,9 +838,6 @@ static int hax_sync_vcpu_register(CPUArchState *env, int set)return -1 ; } } -if (!set) { -x86_update_hflags (env); - }return 0 ; }
@@ -1021,6 +1018,7 @@ static int hax_arch_get_registers(CPUArchState *env)return ret; } +x86_update_hflags (env);return 0 ; }
Signature · 1 line
2.16.0.rc1.238.g530d649a79-goog
Paolo Bonzini
AppliedRe: [Qemu-devel] [PATCH v2 1/3] target/i386: move hflags update code to a function
In reply to Tao WuQuoted 3 lines · Tao Wu
We will share the same code for hax/kvm.
Signed-off-by Tao Wu <[email protected]>
Merged, thanks.
Paolo
Quoted 162 lines
--- target/i386/Makefile.objs | 2 +- target/i386/common_i386.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++ target/i386/common_i386.h | 14 +++++++++++++ target/i386/kvm.c | 41 ++------------------------------------ 4 files changed, 67 insertions(+), 40 deletions(-) create mode 100644 target/i386/common_i386.c create mode 100644 target/i386/common_i386.htarget/i386/Makefile.objs +1
-1@@ -1,4 +1,4 @@ -obj-y += helper.o cpu.o gdbstub.o xsave_helper.o +obj-y += helper.o cpu.o gdbstub.o xsave_helper.o common_i386.o obj-$(CONFIG_TCG) += translate.o obj-$(CONFIG_TCG) += bpt_helper.o cc_helper.o excp_helper.o fpu_helper.o obj-$(CONFIG_TCG) += int_helper.o mem_helper.o misc_helper.o mpx_helper.otarget/i386/common_i386.c new file +50
-0@@ -0,0 +1,50 @@ +/* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "common_i386.h" + +void x86_update_hflags (CPUX86State *env) +{ +uint32_t hflags; +#define HFLAG_COPY_MASK \ + ~( HF_CPL_MASK | HF_PE_MASK | HF_MP_MASK | HF_EM_MASK | \ + HF_TS_MASK | HF_TF_MASK | HF_VM_MASK | HF_IOPL_MASK | \ + HF_OSFXSR_MASK | HF_LMA_MASK | HF_CS32_MASK | \ + HF_SS32_MASK | HF_CS64_MASK | HF_ADDSEG_MASK) + + hflags = env->hflags &HFLAG_COPY_MASK ; + hflags |= (env->segs[R_SS ].flags >>DESC_DPL_SHIFT ) &HF_CPL_MASK ; + hflags |= (env->cr[0 ] &CR0_PE_MASK ) << (HF_PE_SHIFT -CR0_PE_SHIFT ); + hflags |= (env->cr[0 ] << (HF_MP_SHIFT -CR0_MP_SHIFT )) & + (HF_MP_MASK |HF_EM_MASK |HF_TS_MASK ); + hflags |= (env->eflags & (HF_TF_MASK |HF_VM_MASK |HF_IOPL_MASK )); + +if (env->cr[4 ] &CR4_OSFXSR_MASK ) { + hflags |=HF_OSFXSR_MASK ; + } + +if (env->efer &MSR_EFER_LMA ) { + hflags |=HF_LMA_MASK ; + } + +if ((hflags &HF_LMA_MASK ) && (env->segs[R_CS ].flags &DESC_L_MASK )) { + hflags |=HF_CS32_MASK |HF_SS32_MASK |HF_CS64_MASK ; + }else { + hflags |= (env->segs[R_CS ].flags &DESC_B_MASK ) >> + (DESC_B_SHIFT -HF_CS32_SHIFT ); + hflags |= (env->segs[R_SS ].flags &DESC_B_MASK ) >> + (DESC_B_SHIFT -HF_SS32_SHIFT ); +if (!(env->cr[0 ] &CR0_PE_MASK ) || (env->eflags &VM_MASK ) || + !(hflags &HF_CS32_MASK )) { + hflags |=HF_ADDSEG_MASK ; + }else { + hflags |= ((env->segs[R_DS ].base | env->segs[R_ES ].base | + env->segs[R_SS ].base) !=0 ) <<HF_ADDSEG_SHIFT ; + } + } + env->hflags = hflags; + +return ; +}target/i386/common_i386.h new file +14
-0@@ -0,0 +1,14 @@ +/* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef TARGET_I386_COMMON_I386_H +#define TARGET_I386_COMMON_I386_H + +#include "qemu/osdep.h" +#include "cpu.h" + +void x86_update_hflags (CPUX86State * env); + +#endif target/i386/kvm.c +2
-39@@ -25,6 +25,7 @@#include "sysemu/sysemu.h" #include "sysemu/hw_accel.h" #include "sysemu/kvm_int.h" +#include "common_i386.h" #include "kvm_i386.h" #include "hyperv.h" #include "hyperv-proto.h" @@ -1877,7 +1878,6 @@ static int kvm_get_sregs(X86CPU *cpu) {CPUX86State *env = &cpu->env;struct kvm_sregs sregs; -uint32_t hflags;int bit, i, ret; ret =kvm_vcpu_ioctl (CPU (cpu),KVM_GET_SREGS , &sregs);@@ -1919,44 +1919,7 @@ static int kvm_get_sregs(X86CPU *cpu) env->efer = sregs.efer;/* changes to apic base and cr8/tpr are read back via kvm_arch_post_run */ - -#define HFLAG_COPY_MASK \ - ~( HF_CPL_MASK | HF_PE_MASK | HF_MP_MASK | HF_EM_MASK | \ - HF_TS_MASK | HF_TF_MASK | HF_VM_MASK | HF_IOPL_MASK | \ - HF_OSFXSR_MASK | HF_LMA_MASK | HF_CS32_MASK | \ - HF_SS32_MASK | HF_CS64_MASK | HF_ADDSEG_MASK) - - hflags = env->hflags &HFLAG_COPY_MASK ; - hflags |= (env->segs[R_SS ].flags >>DESC_DPL_SHIFT ) &HF_CPL_MASK ; - hflags |= (env->cr[0 ] &CR0_PE_MASK ) << (HF_PE_SHIFT -CR0_PE_SHIFT ); - hflags |= (env->cr[0 ] << (HF_MP_SHIFT -CR0_MP_SHIFT )) & - (HF_MP_MASK |HF_EM_MASK |HF_TS_MASK ); - hflags |= (env->eflags & (HF_TF_MASK |HF_VM_MASK |HF_IOPL_MASK )); - -if (env->cr[4 ] &CR4_OSFXSR_MASK ) { - hflags |=HF_OSFXSR_MASK ; - } - -if (env->efer &MSR_EFER_LMA ) { - hflags |=HF_LMA_MASK ; - } - -if ((hflags &HF_LMA_MASK ) && (env->segs[R_CS ].flags &DESC_L_MASK )) { - hflags |=HF_CS32_MASK |HF_SS32_MASK |HF_CS64_MASK ; - }else { - hflags |= (env->segs[R_CS ].flags &DESC_B_MASK ) >> - (DESC_B_SHIFT -HF_CS32_SHIFT ); - hflags |= (env->segs[R_SS ].flags &DESC_B_MASK ) >> - (DESC_B_SHIFT -HF_SS32_SHIFT ); -if (!(env->cr[0 ] &CR0_PE_MASK ) || (env->eflags &VM_MASK ) || - !(hflags &HF_CS32_MASK )) { - hflags |=HF_ADDSEG_MASK ; - }else { - hflags |= ((env->segs[R_DS ].base | env->segs[R_ES ].base | - env->segs[R_SS ].base) !=0 ) <<HF_ADDSEG_SHIFT ; - } - } - env->hflags = hflags; +x86_update_hflags (env);return 0 ; }