add disable-tcg option for x86 build
v4 cover add disable-tcg option for x86 build
changes from v3:
- patch 2: place ;; on a separate line [Daniel]
- patch 14: do not touch include/exec/helper-proto.h [Richard]
- patch 16: moved cpu_report_tpr_access hunk later [Richard]
- patch 18: renamed tcg_update_mxcsr [Richard], added missing call to cpu_post_load
- patch 20: do not touch bpt_helper.c, adjust caller in machine.c [Richard]
- patch 21: compile out bpt_helper.c [Richard]
Paolo Bonzini (10):
configure: factor out list of supported Xen/KVM/HAX targets
configure: early test for supported targets
configure: add --disable-tcg configure option
vl: convert -tb-size to qemu_strtoul
monitor: disable "info jit" and "info opcount" if !TCG
vapic: use tcg_enabled
tcg: move tb_lock out of translate-all.h
exec: elide calls to tb_lock and tb_unlock target/i386: move TLB refill function out of helper.c
configure: warn on untested --disable-tcg
Yang Zhong (12):
vl: add tcg_enabled() for tcg related code
tcg: move page_size_init() function
tcg: tcg_handle_interrupt() function
tcg: make tcg_allowed global
tcg: add the tcg-stub.c file into accel/stubs/
tcg: add CONFIG_TCG guards in headers
tcg: add the CONFIG_TCG into Makefiles
target/i386: move cpu_sync_bndcs_hflags() function target/i386: make cpu_get_fp80()/cpu_set_fp80() static target/i386: split cpu_set_mxcsr() and make cpu_set_fpuc() inline target/i386: add the tcg_enabled() in target/i386/ target/i386: add the CONFIG_TCG into Makefiles
Makefile.target | 4 +- accel/Makefile.objs | 2 +- accel/stubs/Makefile.objs | 1 + accel/stubs/tcg-stub.c | 22 +++ accel/tcg/Makefile.objs | 2 +- accel/tcg/cpu-exec-common.c | 2 + accel/tcg/tcg-all.c | 35 +++- accel/tcg/translate-all.c | 29 +--- accel/tcg/translate-common.c | 56 ------- bsd-user/main.c | 1 - configure | 191 +++++++++++++++------- exec.c | 23 +++ hmp-commands-info.hx | 4 + hw/i386/kvmvapic.c | 5 +- include/exec/cpu-defs.h | 4 +- include/exec/cputlb.h | 2 +- include/exec/exec-all.h | 57 ++++--- include/qemu-common.h | 7 +- include/sysemu/accel.h | 2 +- monitor.c | 2 + qom/cpu.c | 2 + target/i386/Makefile.objs | 8 +- target/i386/cpu.c | 4 +- target/i386/cpu.h | 31 +++- target/i386/excp_helper.c | 343 +++++++++++++++++++++++++++++++++++++++ target/i386/fpu_helper.c | 29 +--- target/i386/helper.c | 376 ++++--------------------------------------- target/i386/machine.c | 31 +++- target/i386/mpx_helper.c | 30 ---- tcg/tcg.h | 4 - vl.c | 14 +- 31 files changed, 721 insertions(+), 602 deletions(-) create mode 100644 accel/stubs/tcg-stub.c delete mode 100644 accel/tcg/translate-common.c
Signature · 1 line
1.8.3.1
PATCH v4 1/22 configure: factor out list of supported Xen/KVM/HAX targets
This will be useful when the functions are called, early in the configure process, to filter out targets that do not support hardware acceleration.
--- configure | 90 ++++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 35 deletions(-)
configure +55 -35
@@ -163,6 +163,50 @@ have_backend () { echo "$trace_backends" | grep "$1" >/dev/null } +glob() { + eval test -z '"${1#'"$2"'}"' +} + +supported_hax_target() { + test "$hax" = "yes" || return 1 + glob "$1" "*-softmmu" || return 1 + case "${1%-softmmu}" in + i386|x86_64) + return 0 + ;; + esac + return 1 +} + +supported_kvm_target() { + test "$kvm" = "yes" || return 1 + glob "$1" "*-softmmu" || return 1 + case "${1%-softmmu}:$cpu" in + arm:arm | aarch64:aarch64 | \ + i386:i386 | i386:x86_64 | i386:x32 | \ + x86_64:i386 | x86_64:x86_64 | x86_64:x32 | \ + mips:mips | mipsel:mips | \ + ppc:ppc | ppcemb:ppc | ppc64:ppc | \ + ppc:ppc64 | ppcemb:ppc64 | ppc64:ppc64 | \ + s390x:s390x) + return 0 + ;; + esac + return 1 +} + +supported_xen_target() { + test "$xen" = "yes" || return 1 + glob "$1" "*-softmmu" || return 1 + case "${1%-softmmu}:$cpu" in + arm:arm | aarch64:aarch64 | \ + i386:i386 | i386:x86_64 | x86_64:i386 | x86_64:x86_64) + return 0 + ;; + esac + return 1 +} + # default parameters source_path=$(dirname "$0") cpu=""
@@ -6178,46 +6222,22 @@ echo "TARGET_ABI_DIR=$TARGET_ABI_DIR" >> $config_target_mak if [ "$HOST_VARIANT_DIR" != "" ]; then echo "HOST_VARIANT_DIR=$HOST_VARIANT_DIR" >> $config_target_mak fi -case "$target_name" in - i386|x86_64) - if test "$xen" = "yes" -a "$target_softmmu" = "yes" ; then - echo "CONFIG_XEN=y" >> $config_target_mak - if test "$xen_pci_passthrough" = yes; then + +if supported_xen_target $target; then + echo "CONFIG_XEN=y" >> $config_target_mak + if test "$xen_pci_passthrough" = yes; then echo "CONFIG_XEN_PCI_PASSTHROUGH=y" >> "$config_target_mak" - fi fi - ;; - *) -esac -case "$target_name" in - aarch64|arm|i386|x86_64|ppcemb|ppc|ppc64|s390x|mipsel|mips) - # Make sure the target and host cpus are compatible - if test "$kvm" = "yes" -a "$target_softmmu" = "yes" -a \ - \( "$target_name" = "$cpu" -o \ - \( "$target_name" = "ppcemb" -a "$cpu" = "ppc" \) -o \ - \( "$target_name" = "ppc64" -a "$cpu" = "ppc" \) -o \ - \( "$target_name" = "ppc" -a "$cpu" = "ppc64" \) -o \ - \( "$target_name" = "ppcemb" -a "$cpu" = "ppc64" \) -o \ - \( "$target_name" = "mipsel" -a "$cpu" = "mips" \) -o \ - \( "$target_name" = "x86_64" -a "$cpu" = "i386" \) -o \ - \( "$target_name" = "i386" -a "$cpu" = "x86_64" \) -o \ - \( "$target_name" = "x86_64" -a "$cpu" = "x32" \) -o \ - \( "$target_name" = "i386" -a "$cpu" = "x32" \) \) ; then - echo "CONFIG_KVM=y" >> $config_target_mak - if test "$vhost_net" = "yes" ; then +fi +if supported_kvm_target $target; then + echo "CONFIG_KVM=y" >> $config_target_mak + if test "$vhost_net" = "yes" ; then echo "CONFIG_VHOST_NET=y" >> $config_target_mak echo "CONFIG_VHOST_NET_TEST_$target_name=y" >> $config_host_mak - fi fi -esac -if test "$hax" = "yes" ; then - if test "$target_softmmu" = "yes" ; then - case "$target_name" in - i386|x86_64) - echo "CONFIG_HAX=y" >> $config_target_mak - ;; - esac - fi +fi +if supported_hax_target $target; then + echo "CONFIG_HAX=y" >> $config_target_mak fi if test "$target_bigendian" = "yes" ; then echo "TARGET_WORDS_BIGENDIAN=y" >> $config_target_mak
Signature · 1 line
1.8.3.1
PATCH v4 2/22 configure: early test for supported targets
In reply to Paolo BonziniCheck for unsupported targets in target_list, and print an error early in the configuration process.
---
v2: place ;; on a separate line [Daniel]
configure | 70 +++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 22 deletions(-)
configure +48 -22
@@ -40,14 +40,18 @@ printf " '%s'" "$0" "$@" >> config.log echo >> config.log echo "#" >> config.log -error_exit() { - echo +print_error() { + (echo echo "ERROR: $1" while test -n "$2"; do echo " $2" shift done - echo + echo) >&2 +} + +error_exit() { + print_error "$@" exit 1 }
@@ -207,6 +211,30 @@ supported_xen_target() { return 1 } +supported_target() { + case "$1" in + *-softmmu) + ;; + *-linux-user) + if test "$linux" != "yes"; then + print_error "Target '$target' is only available on a Linux host" + return 1 + fi + ;; + *-bsd-user) + if test "$bsd" != "yes"; then + print_error "Target '$target' is only available on a BSD host" + return 1 + fi + ;; + *) + print_error "Invalid target name '$target'" + return 1 + ;; + esac + return 0 +} + # default parameters source_path=$(dirname "$0") cpu=""
@@ -1734,23 +1762,27 @@ if test "$solaris" = "yes" ; then fi if test -z "${target_list+xxx}" ; then - target_list="$default_target_list" + for target in $default_target_list; do + supported_target $target 2>/dev/null && \ + target_list="$target_list $target" + done + target_list="${target_list# }" else target_list=$(echo "$target_list" | sed -e 's/,/ /g') + for target in $target_list; do + # Check that we recognised the target name; this allows a more + # friendly error message than if we let it fall through. + case " $default_target_list " in + *" $target "*) + ;; + *) + error_exit "Unknown target name '$target'" + ;; + esac + supported_target $target || exit 1 + done fi -# Check that we recognised the target name; this allows a more -# friendly error message than if we let it fall through. -for target in $target_list; do - case " $default_target_list " in - *" $target "*) - ;; - *) - error_exit "Unknown target name '$target'" - ;; - esac -done - # see if system emulation was really requested case " $target_list " in *"-softmmu "*) softmmu=yes
@@ -6050,16 +6082,10 @@ case "$target" in target_softmmu="yes" ;; ${target_name}-linux-user) - if test "$linux" != "yes" ; then - error_exit "Target '$target' is only available on a Linux host" - fi target_user_only="yes" target_linux_user="yes" ;; ${target_name}-bsd-user) - if test "$bsd" != "yes" ; then - error_exit "Target '$target' is only available on a BSD host" - fi target_user_only="yes" target_bsd_user="yes" ;;
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 02/22] configure: early test for supported targets
Quoted 10 lines · Paolo Bonzini
Check for unsupported targets in
target_list, and print an error early in the configuration process.Reviewed-by Richard Henderson <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>---
v2: place ;; on a separate line [Daniel]configure | 70 +++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 22 deletions(-)
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v4 3/22 configure: add --disable-tcg configure option
In reply to Paolo BonziniFrom: Anthony Liguori <[email protected]>
This lets you build without TCG (hardware accelerationor qtest only). When this flag is passed to configure, it will automatically filter out the target list to only those that support KVM or Xen or HAX.
--- configure | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-)
configure +21 -5
@@ -232,7 +232,12 @@ supported_target() { return 1 ;; esac - return 0 + test "$tcg" = "yes" && return 0 + supported_kvm_target "$1" && return 0 + supported_xen_target "$1" && return 0 + supported_hax_target "$1" && return 0 + print_error "TCG disabled, but hardware accelerator not available for '$target'" + return 1 } # default parameters
@@ -296,6 +301,7 @@ cap_ng="" attr="" libattr="" xfs="" +tcg="yes" vhost_net="no" vhost_scsi="no"
@@ -1033,6 +1039,10 @@ for opt do ;; --enable-cap-ng) cap_ng="yes" ;; + --disable-tcg) tcg="no" + ;; + --enable-tcg) tcg="yes" + ;; --disable-spice) spice="no" ;; --enable-spice) spice="yes"
@@ -5195,7 +5205,6 @@ echo "module support $modules" echo "host CPU $cpu" echo "host big endian $bigendian" echo "target list $target_list" -echo "tcg debug enabled $debug_tcg" echo "gprof enabled $gprof" echo "sparse enabled $sparse" echo "strip binaries $strip_opt"
@@ -5250,8 +5259,12 @@ echo "ATTR/XATTR support $attr" echo "Install blobs $blobs" echo "KVM support $kvm" echo "HAX support $hax" +echo "TCG support $tcg" +if test "$tcg" = "yes" ; then + echo "TCG debug enabled $debug_tcg" + echo "TCG interpreter $tcg_interpreter" +fi echo "RDMA support $rdma" -echo "TCG interpreter $tcg_interpreter" echo "fdt support $fdt" echo "preadv support $preadv" echo "fdatasync $fdatasync"
@@ -5694,8 +5707,11 @@ fi if test "$signalfd" = "yes" ; then echo "CONFIG_SIGNALFD=y" >> $config_host_mak fi -if test "$tcg_interpreter" = "yes" ; then - echo "CONFIG_TCG_INTERPRETER=y" >> $config_host_mak +if test "$tcg" = "yes"; then + echo "CONFIG_TCG=y" >> $config_host_mak + if test "$tcg_interpreter" = "yes" ; then + echo "CONFIG_TCG_INTERPRETER=y" >> $config_host_mak + fi fi if test "$fdatasync" = "yes" ; then echo "CONFIG_FDATASYNC=y" >> $config_host_mak
Signature · 1 line
1.8.3.1
PATCH v4 4/22 vl: convert -tb-size to qemu_strtoul
In reply to Paolo Bonzini--- accel/tcg/tcg-all.c | 2 +- include/sysemu/accel.h | 2 +- vl.c | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-)
accel/tcg/tcg-all.c +1 -1
@@ -28,7 +28,7 @@#include "sysemu/sysemu.h" #include "qom/object.h" -int tcg_tb_size; +unsigned long tcg_tb_size;static bool tcg_allowed = true;static int tcg_init (MachineState *ms)
include/sysemu/accel.h +1 -1
@@ -63,7 +63,7 @@ typedef struct AccelClass {#define ACCEL_GET_CLASS (obj) \ OBJECT_GET_CLASS(AccelClass, (obj), TYPE_ACCEL) -extern int tcg_tb_size; +extern unsigned long tcg_tb_size;void configure_accelerator (MachineState *ms);/* Register accelerator specific global properties */
vl.c +3 -3
@@ -3933,9 +3933,9 @@ int main(int argc, char **argv, char **envp)configure_rtc (opts);break ;case QEMU_OPTION_tb_size: - tcg_tb_size =strtol (optarg,NULL ,0 ); -if (tcg_tb_size <0 ) { - tcg_tb_size =0 ; +if (qemu_strtoul (optarg,NULL ,0 , &tcg_tb_size) <0 ) { +error_report ("Invalid argument to -tb-size" ); +exit (1 ); }break ;case QEMU_OPTION_icount:
Signature · 1 line
1.8.3.1
PATCH v4 5/22 vl: add tcg_enabled() for tcg related code
In reply to Paolo BonziniFrom: Yang Zhong <[email protected]>
Need to disable the tcg related code in the vl.c if the disable-tcg option is added into ./configure command.
--- vl.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
vl.c +7 -1
@@ -3933,6 +3933,10 @@ int main(int argc, char **argv, char **envp)configure_rtc (opts);break ;case QEMU_OPTION_tb_size: +if (!tcg_enabled ()) { +error_report ("TCG is disabled" ); +exit (1 ); + }if (qemu_strtoul (optarg,NULL ,0 , &tcg_tb_size) <0 ) {error_report ("Invalid argument to -tb-size" );exit (1 );
@@ -4481,7 +4485,9 @@ int main(int argc, char **argv, char **envp)qemu_opts_del (icount_opts); } -qemu_tcg_configure (accel_opts, &error_fatal); +if (tcg_enabled ()) { +qemu_tcg_configure (accel_opts, &error_fatal); + }if (default_net) {QemuOptsList *net =qemu_find_opts ("net" );
Signature · 1 line
1.8.3.1
PATCH v4 6/22 tcg: move page_size_init() function
In reply to Paolo BonziniFrom: Yang Zhong <[email protected]>
translate-all.c will be disabled if tcg is disabled in the build, so page_size_init() function and related variables will be moved to exec.c file.
--- accel/tcg/translate-all.c | 18 ------------------ exec.c | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 18 deletions(-)
accel/tcg/translate-all.c +0 -18
@@ -112,9 +112,6 @@ typedef struct PageDesc {#define V_L2_BITS 10#define V_L2_SIZE (1 << V_L2_BITS) -uintptr_t qemu_host_page_size; -intptr_t qemu_host_page_mask; -/* * L1 Mapping properties */
@@ -363,21 +360,6 @@ bool cpu_restore_state(CPUState *cpu, uintptr_t retaddr)return r; } -void page_size_init (void ) -{ -/* NOTE: we can always suppose that qemu_host_page_size >= -TARGET_PAGE_SIZE */ - qemu_real_host_page_size =getpagesize (); - qemu_real_host_page_mask = -(intptr_t )qemu_real_host_page_size; -if (qemu_host_page_size ==0 ) { - qemu_host_page_size = qemu_real_host_page_size; - } -if (qemu_host_page_size <TARGET_PAGE_SIZE ) { - qemu_host_page_size =TARGET_PAGE_SIZE ; - } - qemu_host_page_mask = -(intptr_t )qemu_host_page_size; -} -static void page_init (void ) {page_size_init ();
exec.c +20 -0
@@ -118,6 +118,11 @@ __thread CPUState *current_cpu;2 = Adaptive rate instruction counting. */ int use_icount; +uintptr_t qemu_host_page_size; +intptr_t qemu_host_page_mask; +uintptr_t qemu_real_host_page_size; +intptr_t qemu_real_host_page_mask; +bool set_preferred_target_page_bits (int bits) {/* The target page size is the lowest common denominator for all
@@ -3590,3 +3595,18 @@ err: }#endif + +void page_size_init (void ) +{ +/* NOTE: we can always suppose that qemu_host_page_size >= +TARGET_PAGE_SIZE */ + qemu_real_host_page_size =getpagesize (); + qemu_real_host_page_mask = -(intptr_t )qemu_real_host_page_size; +if (qemu_host_page_size ==0 ) { + qemu_host_page_size = qemu_real_host_page_size; + } +if (qemu_host_page_size <TARGET_PAGE_SIZE ) { + qemu_host_page_size =TARGET_PAGE_SIZE ; + } + qemu_host_page_mask = -(intptr_t )qemu_host_page_size; +}
Signature · 1 line
1.8.3.1
PATCH v4 7/22 tcg: tcg_handle_interrupt() function
In reply to Paolo BonziniFrom: Yang Zhong <[email protected]>
Move tcg_handle_interrupt() from translate-common.c to accel/tcg/tcg-all.c.
--- accel/tcg/Makefile.objs | 2 +- accel/tcg/tcg-all.c | 32 +++++++++++++++++++++++++ accel/tcg/translate-common.c | 56 -------------------------------------------- qom/cpu.c | 2 ++ 4 files changed, 35 insertions(+), 57 deletions(-) delete mode 100644 accel/tcg/translate-common.c
accel/tcg/Makefile.objs +1 -1
@@ -1,3 +1,3 @@ obj-$(CONFIG_SOFTMMU) += tcg-all.o obj-$(CONFIG_SOFTMMU) += cputlb.o -obj-y += cpu-exec.o cpu-exec-common.o translate-all.o translate-common.o +obj-y += cpu-exec.o cpu-exec-common.o translate-all.o
accel/tcg/tcg-all.c +32 -0
@@ -27,13 +27,45 @@#include "sysemu/accel.h" #include "sysemu/sysemu.h" #include "qom/object.h" +#include "qemu-common.h" +#include "qom/cpu.h" +#include "sysemu/cpus.h" +#include "qemu/main-loop.h" unsigned long tcg_tb_size;static bool tcg_allowed = true; +#ifndef CONFIG_USER_ONLY +/* mask must never be zero, except for A20 change call */ +static void tcg_handle_interrupt (CPUState *cpu,int mask) +{ +int old_mask; +g_assert (qemu_mutex_iothread_locked ()); + + old_mask = cpu->interrupt_request; + cpu->interrupt_request |= mask; + +/* +* If called from iothread context, wake the target cpu in +* case its halted. +*/ +if (!qemu_cpu_is_self (cpu)) { +qemu_cpu_kick (cpu); + }else { + cpu->icount_decr.u16.high =-1 ; +if (use_icount && + !cpu->can_do_io + && (mask & ~old_mask) !=0 ) { +cpu_abort (cpu,"Raised interrupt while not in I/O function" ); + } + } +} +#endif +static int tcg_init (MachineState *ms) {tcg_exec_init (tcg_tb_size *1024 *1024 ); + cpu_interrupt_handler = tcg_handle_interrupt;return 0 ; }
accel/tcg/translate-common.c deleted +0 -56
56 lines not on this page · raw message
qom/cpu.c +2 -0
@@ -31,6 +31,8 @@#include "hw/qdev-properties.h" #include "trace-root.h" +CPUInterruptHandler cpu_interrupt_handler; +bool cpu_exists (int64_t id) {CPUState *cpu;
Signature · 1 line
1.8.3.1
PATCH v4 8/22 tcg: make tcg_allowed global
In reply to Paolo BonziniFrom: Yang Zhong <[email protected]>
Change the tcg_enabled() and make sure user build still enable tcg even x86 softmmu disable tcg.
--- accel/tcg/cpu-exec-common.c | 2 ++ accel/tcg/tcg-all.c | 1 - accel/tcg/translate-all.c | 6 +----- include/qemu-common.h | 7 ++++++- 4 files changed, 9 insertions(+), 7 deletions(-)
accel/tcg/cpu-exec-common.c +2 -0
@@ -23,6 +23,8 @@#include "exec/exec-all.h" #include "exec/memory-internal.h" +bool tcg_allowed; +/* exit the current TB, but without causing any exception to be raised */ void cpu_loop_exit_noexc (CPUState *cpu) {
accel/tcg/tcg-all.c +0 -1
@@ -33,7 +33,6 @@#include "qemu/main-loop.h" unsigned long tcg_tb_size; -static bool tcg_allowed = true;#ifndef CONFIG_USER_ONLY /* mask must never be zero, except for A20 change call */
accel/tcg/translate-all.c +1 -5
@@ -784,6 +784,7 @@ static void tb_htable_init(void)size. */ void tcg_exec_init (unsigned long tb_size) { + tcg_allowed = true;cpu_gen_init ();page_init ();tb_htable_init ();
@@ -795,11 +796,6 @@ void tcg_exec_init(unsigned long tb_size)#endif } -bool tcg_enabled (void ) -{ -return tcg_ctx.code_gen_buffer !=NULL ; -} -/* * Allocate a new translation block. Flush the translation buffer if * too many translation blocks or too much generated code.
include/qemu-common.h +6 -1
@@ -76,8 +76,13 @@ int qemu_openpty_raw(int *aslave, char *pty_name); sendto(sockfd, buf, len, flags, destaddr, addrlen)#endif +extern bool tcg_allowed;void tcg_exec_init (unsigned long tb_size); -bool tcg_enabled (void ); +#ifdef CONFIG_TCG +#define tcg_enabled () (tcg_allowed) +#else +#define tcg_enabled () 0 +#endif void cpu_exec_init_all (void );void cpu_exec_step_atomic (CPUState *cpu);
Signature · 1 line
1.8.3.1
PATCH v4 9/22 monitor: disable "info jit" and "info opcount" if !TCG
In reply to Paolo Bonzini--- accel/tcg/translate-all.c | 5 +++++ hmp-commands-info.hx | 4 ++++ monitor.c | 2 ++ 3 files changed, 11 insertions(+)
accel/tcg/translate-all.c +5 -0
@@ -1851,6 +1851,11 @@ void dump_exec_info(FILE *f, fprintf_function cpu_fprintf)tb_lock (); +if (!tcg_enabled ()) { +cpu_fprintf (f,"TCG not enabled\n" ); +return ; + } + target_code_size =0 ; max_target_code_size =0 ; cross_page =0 ;
hmp-commands-info.hx +4 -0
@@ -261,6 +261,7 @@ STEXI Show memory tree. ETEXI +#if defined(CONFIG_TCG) { .name = "jit", .args_type = "",
@@ -268,6 +269,7 @@ ETEXI .help = "show dynamic compiler info", .cmd = hmp_info_jit, }, +#endif STEXI @item info jit
@@ -275,6 +277,7 @@ STEXI Show dynamic compiler info. ETEXI +#if defined(CONFIG_TCG) { .name = "opcount", .args_type = "",
@@ -282,6 +285,7 @@ ETEXI .help = "show dynamic compiler opcode counters", .cmd = hmp_info_opcount, }, +#endif STEXI @item info opcount
monitor.c +2 -0
@@ -1098,6 +1098,7 @@ static void hmp_info_registers(Monitor *mon, const QDict *qdict) } } +#ifdef CONFIG_TCG static void hmp_info_jit (Monitor *mon,const QDict *qdict) {if (!tcg_enabled ()) {
@@ -1113,6 +1114,7 @@ static void hmp_info_opcount(Monitor *mon, const QDict *qdict) {dump_opcount_info ((FILE *)mon, monitor_fprintf); } +#endif static void hmp_info_history (Monitor *mon,const QDict *qdict) {
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 09/22] monitor: disable "info jit" and "info opcount" if !TCG
Quoted 13 lines · Paolo Bonzini
Reviewed-by Richard Henderson <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- accel/tcg/translate-all.c | 5 +++++ hmp-commands-info.hx | 4 ++++ monitor.c | 2 ++ 3 files changed, 11 insertions(+)accel/tcg/translate-all.c +0
-0
accel/tcg/translate-all.c void dump_exec_info(FILE *f, fprintf_function cpu_fprintf) · line 1857
Quoted 7 lines
accel/tcg/translate-all.c +4
-0@@ -1851,6 +1851,11 @@ void dump_exec_info(FILE *f, fprintf_function cpu_fprintf)tb_lock (); +if (!tcg_enabled ()) { +cpu_fprintf (f,"TCG not enabled\n" ); +return ; + }
Sorry I missed this before it was merged, but:
- We're returning with tb_lock held
- This check is redundant; see b7da97eef ("monitor: Check whether TCG is enabled before running the "info jit" code") which was merged in April (hmp_info_jit is the only caller of dump_exec_info).
I suggest we get rid of the check, although moving it above tb_lock is also OK with me.
Thanks,
Emilio
Re: [Qemu-devel] [PATCH 09/22] monitor: disable "info jit" and "info opcount" if !TCG
Quoted 3 lines · Emilio G. Cota
Quoted 2 lines · Paolo Bonzini
Reviewed-by Richard Henderson <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>
(snip)
Quoted 12 lines
accel/tcg/translate-all.c void dump_exec_info(FILE *f, fprintf_function cpu_fprintf) · line 1857
Quoted 9 lines
+++
b/accel/tcg/translate-all.caccel/tcg/translate-all.c +4
-0@@ -1851,6 +1851,11 @@ void dump_exec_info(FILE *f, fprintf_function cpu_fprintf)tb_lock (); +if (!tcg_enabled ()) { +cpu_fprintf (f,"TCG not enabled\n" ); +return ; + }Sorry I missed this before it was merged, but:
Quoted 7 lines
- We're returning with
tb_lockheld
- This check is redundant; seeb7da97eef("monitor: Check whether TCG is enabled before running the "info jit" code") which was merged in April (hmp_info_jitis the only caller ofdump_exec_info).I suggest we get rid of the check, although moving it above
tb_lockis also OK with me.
Patch here:
https://lists.nongnu.org/archive/html/qemu-devel/2017-07/msg02072.html
This other patch fixes another issue introduced in this series, please have a look as well:
https://lists.nongnu.org/archive/html/qemu-devel/2017-07/msg02058.html
Cheers,
Emilio
PATCH v4 10/22 vapic: use tcg_enabled
In reply to Paolo Bonzini--- hw/i386/kvmvapic.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
hw/i386/kvmvapic.c +3 -2
@@ -410,7 +410,8 @@ static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulong ip) handlers = &s->rom_state.mp; } -if (!kvm_enabled ()) { +if (tcg_enabled ()) { +cpu_restore_state (cs, cs->mem_io_pc);cpu_get_tb_cpu_state (env, ¤t_pc, ¤t_cs_base, ¤t_flags);/* Account this instruction, because we will exit the tb.
@@ -456,7 +457,7 @@ static void patch_instruction(VAPICROMState *s, X86CPU *cpu, target_ulong ip)resume_all_vcpus (); -if (!kvm_enabled ()) { +if (tcg_enabled ()) {/* Both tb_lock and iothread_mutex will be reset when * longjmps back into the cpu_exec loop. */ tb_lock ();
Signature · 1 line
1.8.3.1
PATCH v4 11/22 tcg: add the tcg-stub.c file into accel/stubs/
In reply to Paolo BonziniFrom: Yang Zhong <[email protected]>
If tcg is disabled, the functions in tcg-stub.c file will be called. This file is target-independent file, do not include any platform related stub functions into this file.
--- accel/stubs/Makefile.objs | 1 + accel/stubs/tcg-stub.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 accel/stubs/tcg-stub.c
accel/stubs/Makefile.objs +1 -0
@@ -1 +1,2 @@ obj-$(call lnot,$(CONFIG_KVM)) += kvm-stub.o +obj-$(call lnot,$(CONFIG_TCG)) += tcg-stub.o
accel/stubs/tcg-stub.c new file +22 -0
@@ -0,0 +1,22 @@ +/* +* QEMU TCG accelerator stub +* +* Copyright Red Hat, Inc. 2013 +* +* Author: Paolo Bonzini <[email protected]> +* +* 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 "qemu/osdep.h" +#include "qemu-common.h" +#include "cpu.h" +#include "tcg/tcg.h" +#include "exec/cpu-common.h" +#include "exec/exec-all.h" + +void tb_flush (CPUState *cpu) +{ +}
Signature · 1 line
1.8.3.1
PATCH v4 12/22 tcg: move tb_lock out of translate-all.h
In reply to Paolo Bonzini--- bsd-user/main.c | 1 - include/exec/exec-all.h | 4 ++++ tcg/tcg.h | 4 ---- 3 files changed, 4 insertions(+), 5 deletions(-)
bsd-user/main.c +0 -1
@@ -25,7 +25,6 @@#include "qemu/config-file.h" #include "qemu/path.h" #include "qemu/help_option.h" -/* For tb_lock */ #include "cpu.h" #include "exec/exec-all.h" #include "tcg.h"
include/exec/exec-all.h +4 -0
@@ -467,6 +467,10 @@ extern uintptr_t tci_tb_ptr;smaller than 4 bytes, so we don't worry about special-casing this. */ #define GETPC_ADJ 2 +void tb_lock (void ); +void tb_unlock (void ); +void tb_lock_reset (void ); +#if !defined(CONFIG_USER_ONLY ) struct MemoryRegion *iotlb_to_region(CPUState *cpu,
tcg/tcg.h +0 -4
@@ -757,10 +757,6 @@ void *tcg_malloc_internal(TCGContext *s, int size);void tcg_pool_reset (TCGContext *s);TranslationBlock *tcg_tb_alloc (TCGContext *s); -void tb_lock (void ); -void tb_unlock (void ); -void tb_lock_reset (void ); -/* Called with tb_lock held. */ static inline void *tcg_malloc (int size) {
Signature · 1 line
1.8.3.1
PATCH v4 13/22 exec: elide calls to tb_lock and tb_unlock
In reply to Paolo BonziniAdding assertions fixes link errors.
--- exec.c | 3 +++ 1 file changed, 3 insertions(+)
exec.c +3 -0
@@ -2317,6 +2317,7 @@ static void notdirty_mem_write(void *opaque, hwaddr ram_addr, {bool locked = false; +assert (tcg_enabled ());if (!cpu_physical_memory_get_dirty_flag (ram_addr,DIRTY_MEMORY_CODE )) { locked = true;tb_lock ();
@@ -2375,6 +2376,7 @@ static void check_watchpoint(int offset, int len, MemTxAttrs attrs, int flags)CPUWatchpoint *wp;uint32_t cpu_flags; +assert (tcg_enabled ());if (cpu->watchpoint_hit) {/* We re-entered the check after replacing the TB. Now raise * the debug interrupt so that is will trigger after the
@@ -2820,6 +2822,7 @@ static void invalidate_and_set_dirty(MemoryRegion *mr, hwaddr addr,cpu_physical_memory_range_includes_clean (addr, length, dirty_log_mask); }if (dirty_log_mask & (1 <<DIRTY_MEMORY_CODE )) { +assert (tcg_enabled ());tb_lock ();tb_invalidate_phys_range (addr, addr + length);tb_unlock ();
Signature · 1 line
1.8.3.1
PATCH v4 14/22 tcg: add CONFIG_TCG guards in headers
In reply to Paolo BonziniFrom: Yang Zhong <[email protected]>
Add the CONFIG_TCG for exec-all.h. Since function tlb_set_page_with_attrs() is defined in ./accel/tcg/cputlb.c, which will be disabled if tcg is disabled. This function need be implemented in accel/stubs/tcg-stub.c for disable-tcg.
---
v2: do not touch include/exec/helper-proto.h [Richard]
include/exec/cpu-defs.h | 4 +++- include/exec/cputlb.h | 2 +- include/exec/exec-all.h | 53 ++++++++++++++++++++++++++----------------------- 3 files changed, 32 insertions(+), 27 deletions(-)
include/exec/cpu-defs.h +3 -1
@@ -25,7 +25,9 @@#include "qemu/host-utils.h" #include "qemu/queue.h" +#ifdef CONFIG_TCG #include "tcg-target.h" +#endif #ifndef CONFIG_USER_ONLY #include "exec/hwaddr.h" #endif
@@ -54,7 +56,7 @@ typedef uint64_t target_ulong;#error TARGET_LONG_SIZE undefined#endif -#if !defined(CONFIG_USER_ONLY ) +#if !defined(CONFIG_USER_ONLY ) && defined(CONFIG_TCG )/* use a fully associative victim tlb of 8 entries */ #define CPU_VTLB_SIZE 8
include/exec/cputlb.h +1 -1
@@ -19,7 +19,7 @@#ifndef CPUTLB_H #define CPUTLB_H -#if !defined(CONFIG_USER_ONLY ) +#if !defined(CONFIG_USER_ONLY ) && defined(CONFIG_TCG )/* cputlb.c */ void tlb_protect_code (ram_addr_t ram_addr);void tlb_unprotect_code (ram_addr_t ram_addr);
include/exec/exec-all.h +28 -25
65 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 14/22] tcg: add CONFIG_TCG guards in headers
Quoted 8 lines · Paolo Bonzini
From: Yang Zhong<[email protected]>
Add the
CONFIG_TCGforexec-all.h. Since functiontlb_set_page_with_attrs()is defined in./accel/tcg/cputlb.c, which will be disabled if tcg is disabled. This function need be implemented inaccel/stubs/tcg-stub.cfor disable-tcg.Signed-off-by Yang Zhong<[email protected]>Signed-off-by Paolo Bonzini<[email protected]>
Quoted 7 lines
---
v2: do not touchinclude/exec/helper-proto.h[Richard]include/exec/cpu-defs.h | 4 +++- include/exec/cputlb.h | 2 +- include/exec/exec-all.h | 53 ++++++++++++++++++++++++++----------------------- 3 files changed, 32 insertions(+), 27 deletions(-)
r~
PATCH v4 15/22 tcg: add the CONFIG_TCG into Makefiles
In reply to Paolo BonziniFrom: Yang Zhong <[email protected]>
Add the CONFIG_TCG for frontend and backend's files in the related Makefiles.
--- Makefile.target | 4 ++-- accel/Makefile.objs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
Makefile.target +2 -2
@@ -90,8 +90,8 @@ all: $(PROGS) stap # cpu emulator library obj-y += exec.o obj-y += accel/ -obj-y += tcg/tcg.o tcg/tcg-op.o tcg/optimize.o -obj-y += tcg/tcg-common.o tcg/tcg-runtime.o +obj-$(CONFIG_TCG) += tcg/tcg.o tcg/tcg-op.o tcg/optimize.o +obj-$(CONFIG_TCG) += tcg/tcg-common.o tcg/tcg-runtime.o obj-$(CONFIG_TCG_INTERPRETER) += tcg/tci.o obj-$(CONFIG_TCG_INTERPRETER) += disas/tci.o obj-y += fpu/softfloat.o
accel/Makefile.objs +1 -1
@@ -1,4 +1,4 @@ obj-$(CONFIG_SOFTMMU) += accel.o obj-y += kvm/ -obj-y += tcg/ +obj-$(CONFIG_TCG) += tcg/ obj-y += stubs/
Signature · 1 line
1.8.3.1
PATCH v4 16/22 target/i386: move cpu_sync_bndcs_hflags() function
In reply to Paolo BonziniFrom: Yang Zhong <[email protected]>
Move cpu_sync_bndcs_hflags() function from mpx_helper.c to helper.c because mpx_helper.c need be disabled when tcg is disabled.
---
v2: moved cpu_report_tpr_access hunk later [Richard]
target/i386/helper.c | 30 ++++++++++++++++++++++++++++++ target/i386/mpx_helper.c | 30 ------------------------------ 2 files changed, 30 insertions(+), 30 deletions(-)
target/i386/helper.c +30 -0
@@ -29,6 +29,36 @@#include "hw/i386/apic_internal.h" #endif +void cpu_sync_bndcs_hflags (CPUX86State *env) +{ +uint32_t hflags = env->hflags; +uint32_t hflags2 = env->hflags2; +uint32_t bndcsr; + +if ((hflags &HF_CPL_MASK ) ==3 ) { + bndcsr = env->bndcs_regs.cfgu; + }else { + bndcsr = env->msr_bndcfgs; + } + +if ((env->cr[4 ] &CR4_OSXSAVE_MASK ) + && (env->xcr0 &XSTATE_BNDCSR_MASK ) + && (bndcsr &BNDCFG_ENABLE )) { + hflags |=HF_MPX_EN_MASK ; + }else { + hflags &= ~HF_MPX_EN_MASK ; + } + +if (bndcsr &BNDCFG_BNDPRESERVE ) { + hflags2 |=HF2_MPX_PR_MASK ; + }else { + hflags2 &= ~HF2_MPX_PR_MASK ; + } + + env->hflags = hflags; + env->hflags2 = hflags2; +} +static void cpu_x86_version (CPUX86State *env,int *family,int *model) {int cpuver = env->cpuid_version;
target/i386/mpx_helper.c +0 -30
@@ -24,36 +24,6 @@#include "exec/exec-all.h" -void cpu_sync_bndcs_hflags (CPUX86State *env) -{ -uint32_t hflags = env->hflags; -uint32_t hflags2 = env->hflags2; -uint32_t bndcsr; - -if ((hflags &HF_CPL_MASK ) ==3 ) { - bndcsr = env->bndcs_regs.cfgu; - }else { - bndcsr = env->msr_bndcfgs; - } - -if ((env->cr[4 ] &CR4_OSXSAVE_MASK ) - && (env->xcr0 &XSTATE_BNDCSR_MASK ) - && (bndcsr &BNDCFG_ENABLE )) { - hflags |=HF_MPX_EN_MASK ; - }else { - hflags &= ~HF_MPX_EN_MASK ; - } - -if (bndcsr &BNDCFG_BNDPRESERVE ) { - hflags2 |=HF2_MPX_PR_MASK ; - }else { - hflags2 &= ~HF2_MPX_PR_MASK ; - } - - env->hflags = hflags; - env->hflags2 = hflags2; -} -void helper_bndck (CPUX86State *env,uint32_t fail) {if (unlikely (fail)) {
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 16/22] target/i386: move cpu_sync_bndcs_hflags() function
Quoted 6 lines · Paolo Bonzini
From: Yang Zhong<[email protected]>
Move
cpu_sync_bndcs_hflags()function frommpx_helper.ctohelper.cbecausempx_helper.cneed be disabled when tcg is disabled.
Quoted 8 lines
Signed-off-by Yang Zhong<[email protected]>Signed-off-by Paolo Bonzini<[email protected]>---
v2: movedcpu_report_tpr_accesshunk later [Richard]target/i386/helper.c | 30 ++++++++++++++++++++++++++++++ target/i386/mpx_helper.c | 30 ------------------------------ 2 files changed, 30 insertions(+), 30 deletions(-)
r~
PATCH v4 17/22 target/i386: make cpu_get_fp80()/cpu_set_fp80() static
In reply to Paolo BonziniFrom: Yang Zhong <[email protected]>
Move cpu_get_fp80()/cpu_set_fp80() from fpu_helper.c to machine.c because fpu_helper.c will be disabled if tcg is disabled in the build.
--- target/i386/cpu.h | 2 -- target/i386/fpu_helper.c | 18 ------------------ target/i386/machine.c | 18 ++++++++++++++++++ 3 files changed, 18 insertions(+), 20 deletions(-)
target/i386/cpu.h +0 -2
@@ -1418,8 +1418,6 @@ int cpu_x86_get_descr_debug(CPUX86State *env, unsigned int selector,/* op_helper.c */ /* used for debug or cpu save/restore */ -void cpu_get_fp80 (uint64_t *pmant,uint16_t *pexp,floatx80 f); -floatx80 cpu_set_fp80 (uint64_t mant,uint16_t upper);/* cpu-exec.c */ /* the following helpers are only usable in user mode simulation as
target/i386/fpu_helper.c +0 -18
@@ -1539,24 +1539,6 @@ void helper_xsetbv(CPUX86State *env, uint32_t ecx, uint64_t mask)raise_exception_ra (env,EXCP0D_GPF ,GETPC ()); } -void cpu_get_fp80 (uint64_t *pmant,uint16_t *pexp,floatx80 f) -{ -CPU_LDoubleU temp; - - temp.d = f; - *pmant = temp.l.lower; - *pexp = temp.l.upper; -} - -floatx80 cpu_set_fp80 (uint64_t mant,uint16_t upper) -{ -CPU_LDoubleU temp; - - temp.l.upper = upper; - temp.l.lower = mant; -return temp.d; -} -/* MMX/SSE */ /* XXX: optimize by storing fptt and fptags in the static cpu state */
target/i386/machine.c +18 -0
@@ -142,6 +142,24 @@ typedef struct x86_FPReg_tmp {uint16_t tmp_exp; } x86_FPReg_tmp; +static void cpu_get_fp80 (uint64_t *pmant,uint16_t *pexp,floatx80 f) +{ +CPU_LDoubleU temp; + + temp.d = f; + *pmant = temp.l.lower; + *pexp = temp.l.upper; +} + +static floatx80 cpu_set_fp80 (uint64_t mant,uint16_t upper) +{ +CPU_LDoubleU temp; + + temp.l.upper = upper; + temp.l.lower = mant; +return temp.d; +} +static void fpreg_pre_save (void *opaque) {x86_FPReg_tmp *tmp = opaque;
Signature · 1 line
1.8.3.1
PATCH v4 18/22 target/i386: split cpu_set_mxcsr() and make cpu_set_fpuc() inline
In reply to Paolo BonziniFrom: Yang Zhong <[email protected]>
Split the cpu_set_mxcsr() and make cpu_set_fpuc() inline with specific tcg code.
---
v2: renamed tcg_update_mxcsr [Richard],
added missing call to cpu_post_load
target/i386/cpu.h | 21 ++++++++++++++++++--- target/i386/fpu_helper.c | 11 ++--------- target/i386/machine.c | 5 ++++- 3 files changed, 24 insertions(+), 13 deletions(-)
target/i386/cpu.h +18 -3
@@ -1594,7 +1594,6 @@ void QEMU_NORETURN raise_interrupt(CPUX86State *nenv, int intno, int is_int,/* cc_helper.c */ extern const uint8_t parity_table[256 ];uint32_t cpu_cc_compute_all (CPUX86State *env1,int op); -void update_fp_status (CPUX86State *env);static inline uint32_t cpu_compute_eflags (CPUX86State *env) {
@@ -1643,8 +1642,24 @@ static inline int32_t x86_get_a20_mask(CPUX86State *env) }/* fpu_helper.c */ -void cpu_set_mxcsr (CPUX86State *env,uint32_t val); -void cpu_set_fpuc (CPUX86State *env,uint16_t val); +void update_fp_status (CPUX86State *env); +void update_mxcsr_status (CPUX86State *env); + +static inline void cpu_set_mxcsr (CPUX86State *env,uint32_t mxcsr) +{ + env->mxcsr = mxcsr; +if (tcg_enabled ()) { +update_mxcsr_status (env); + } +} + +static inline void cpu_set_fpuc (CPUX86State *env,uint16_t fpuc) +{ + env->fpuc = fpuc; +if (tcg_enabled ()) { +update_fp_status (env); + } +}/* mem_helper.c */ void helper_lock_init (void );
target/i386/fpu_helper.c +2 -9
@@ -1550,12 +1550,11 @@ void helper_xsetbv(CPUX86State *env, uint32_t ecx, uint64_t mask)#define SSE_RC_CHOP 0x6000#define SSE_FZ 0x8000 -void cpu_set_mxcsr (CPUX86State *env,uint32_t mxcsr) +void update_mxcsr_status (CPUX86State *env) { +uint32_t mxcsr = env->mxcsr;int rnd_type; - env->mxcsr = mxcsr; -/* set rounding mode */ switch (mxcsr &SSE_RC_MASK ) {default :
@@ -1581,12 +1580,6 @@ void cpu_set_mxcsr(CPUX86State *env, uint32_t mxcsr)set_flush_to_zero ((mxcsr &SSE_FZ ) ?1 :0 , &env->fp_status); } -void cpu_set_fpuc (CPUX86State *env,uint16_t val) -{ - env->fpuc = val; -update_fp_status (env); -} -void helper_ldmxcsr (CPUX86State *env,uint32_t val) {cpu_set_mxcsr (env, val);
target/i386/machine.c +4 -1
@@ -280,7 +280,10 @@ static int cpu_post_load(void *opaque, int version_id)for (i =0 ; i <8 ; i++) { env->fptags[i] = (env->fptag_vmstate >> i) &1 ; } -update_fp_status (env); +if (tcg_enabled ()) { +update_fp_status (env); +update_mxcsr_status (env); + }cpu_breakpoint_remove_all (cs,BP_CPU );cpu_watchpoint_remove_all (cs,BP_CPU );
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 18/22] target/i386: split cpu_set_mxcsr() and make cpu_set_fpuc() inline
Quoted 10 lines · Paolo Bonzini
From: Yang Zhong<[email protected]>
Split the
cpu_set_mxcsr()and makecpu_set_fpuc()inline with specific tcg code.Signed-off-by Yang Zhong<[email protected]>Signed-off-by Paolo Bonzini<[email protected]>---
v2: renamedtcg_update_mxcsr[Richard],
added missing call tocpu_post_load
r~
PATCH v4 19/22 target/i386: move TLB refill function out of helper.c
In reply to Paolo BonziniThis function calls tlb_set_page_with_attrs, which is not available when TCG is disabled. Move it to excp_helper.c.
--- target/i386/excp_helper.c | 343 +++++++++++++++++++++++++++++++++++++++++++++ target/i386/helper.c | 344 +--------------------------------------------- 2 files changed, 344 insertions(+), 343 deletions(-)
target/i386/excp_helper.c +343 -0
@@ -136,3 +136,346 @@ void raise_exception_ra(CPUX86State *env, int exception_index, uintptr_t retaddr {raise_interrupt2 (env, exception_index,0 ,0 ,0 , retaddr); } + +#if defined(CONFIG_USER_ONLY ) +int x86_cpu_handle_mmu_fault (CPUState *cs,vaddr addr, +int is_write,int mmu_idx) +{ +X86CPU *cpu =X86_CPU (cs); +CPUX86State *env = &cpu->env; + +/* user mode only emulation */ + is_write &=1 ; + env->cr[2 ] = addr; + env->error_code = (is_write <<PG_ERROR_W_BIT ); + env->error_code |=PG_ERROR_U_MASK ; + cs->exception_index =EXCP0E_PAGE ; + env->exception_is_int =0 ; + env->exception_next_eip =-1 ; +return 1 ; +} + +#else + +/* return value: +* -1 = cannot handle fault +* 0 = nothing more to do +* 1 = generate PF fault +*/ +int x86_cpu_handle_mmu_fault (CPUState *cs,vaddr addr, +int is_write1,int mmu_idx) +{ +X86CPU *cpu =X86_CPU (cs); +CPUX86State *env = &cpu->env; +uint64_t ptep, pte; +int32_t a20_mask; +target_ulong pde_addr, pte_addr; +int error_code =0 ; +int is_dirty, prot, page_size, is_write, is_user; +hwaddr paddr; +uint64_t rsvd_mask =PG_HI_RSVD_MASK ; +uint32_t page_offset; +target_ulong vaddr; + + is_user = mmu_idx ==MMU_USER_IDX ; +#if defined(DEBUG_MMU ) +printf ("MMU fault: addr=%" VADDR_PRIx" w=%d u=%d eip=" TARGET_FMT_lx"\n" , + addr, is_write1, is_user, env->eip); +#endif + is_write = is_write1 &1 ; + + a20_mask =x86_get_a20_mask (env); +if (!(env->cr[0 ] &CR0_PG_MASK )) { + pte = addr; +#ifdef TARGET_X86_64 +if (!(env->hflags &HF_LMA_MASK )) { +/* Without long mode we can only address 32bits in real mode */ + pte = (uint32_t )pte; + } +#endif + prot =PAGE_READ |PAGE_WRITE |PAGE_EXEC ; + page_size =4096 ; + goto do_mapping; + } + +if (!(env->efer &MSR_EFER_NXE )) { + rsvd_mask |=PG_NX_MASK ; + } + +if (env->cr[4 ] &CR4_PAE_MASK ) { +uint64_t pde, pdpe; +target_ulong pdpe_addr; + +#ifdef TARGET_X86_64 +if (env->hflags &HF_LMA_MASK ) { +bool la57 = env->cr[4 ] &CR4_LA57_MASK ; +uint64_t pml5e_addr, pml5e; +uint64_t pml4e_addr, pml4e; +int32_t sext; + +/* test virtual address sign extension */ + sext = la57 ? (int64_t )addr >>56 : (int64_t )addr >>47 ; +if (sext !=0 && sext !=-1 ) { + env->error_code =0 ; + cs->exception_index =EXCP0D_GPF ; +return 1 ; + } + +if (la57) { + pml5e_addr = ((env->cr[3 ] & ~0xfff ) + + (((addr >>48 ) &0x1ff ) <<3 )) & a20_mask; + pml5e =x86_ldq_phys (cs, pml5e_addr); +if (!(pml5e &PG_PRESENT_MASK )) { + goto do_fault; + } +if (pml5e & (rsvd_mask |PG_PSE_MASK )) { + goto do_fault_rsvd; + } +if (!(pml5e &PG_ACCESSED_MASK )) { + pml5e |=PG_ACCESSED_MASK ; +x86_stl_phys_notdirty (cs, pml5e_addr, pml5e); + } + ptep = pml5e ^PG_NX_MASK ; + }else { + pml5e = env->cr[3 ]; + ptep =PG_NX_MASK |PG_USER_MASK |PG_RW_MASK ; + } + + pml4e_addr = ((pml5e &PG_ADDRESS_MASK ) + + (((addr >>39 ) &0x1ff ) <<3 )) & a20_mask; + pml4e =x86_ldq_phys (cs, pml4e_addr); +if (!(pml4e &PG_PRESENT_MASK )) { + goto do_fault; + } +if (pml4e & (rsvd_mask |PG_PSE_MASK )) { + goto do_fault_rsvd; + } +if (!(pml4e &PG_ACCESSED_MASK )) { + pml4e |=PG_ACCESSED_MASK ; +x86_stl_phys_notdirty (cs, pml4e_addr, pml4e); + } + ptep &= pml4e ^PG_NX_MASK ; + pdpe_addr = ((pml4e &PG_ADDRESS_MASK ) + (((addr >>30 ) &0x1ff ) <<3 )) & + a20_mask; + pdpe =x86_ldq_phys (cs, pdpe_addr); +if (!(pdpe &PG_PRESENT_MASK )) { + goto do_fault; + } +if (pdpe & rsvd_mask) { + goto do_fault_rsvd; + } + ptep &= pdpe ^PG_NX_MASK ; +if (!(pdpe &PG_ACCESSED_MASK )) { + pdpe |=PG_ACCESSED_MASK ; +x86_stl_phys_notdirty (cs, pdpe_addr, pdpe); + } +if (pdpe &PG_PSE_MASK ) { +/* 1 GB page */ + page_size =1024 *1024 *1024 ; + pte_addr = pdpe_addr; + pte = pdpe; + goto do_check_protect; + } + } else +#endif + { +/* XXX: load them when cr3 is loaded ? */ + pdpe_addr = ((env->cr[3 ] & ~0x1f ) + ((addr >>27 ) &0x18 )) & + a20_mask; + pdpe =x86_ldq_phys (cs, pdpe_addr); +if (!(pdpe &PG_PRESENT_MASK )) { + goto do_fault; + } + rsvd_mask |=PG_HI_USER_MASK ; +if (pdpe & (rsvd_mask |PG_NX_MASK )) { + goto do_fault_rsvd; + } + ptep =PG_NX_MASK |PG_USER_MASK |PG_RW_MASK ; + } + + pde_addr = ((pdpe &PG_ADDRESS_MASK ) + (((addr >>21 ) &0x1ff ) <<3 )) & + a20_mask; + pde =x86_ldq_phys (cs, pde_addr); +if (!(pde &PG_PRESENT_MASK )) { + goto do_fault; + } +if (pde & rsvd_mask) { + goto do_fault_rsvd; + } + ptep &= pde ^PG_NX_MASK ; +if (pde &PG_PSE_MASK ) { +/* 2 MB page */ + page_size =2048 *1024 ; + pte_addr = pde_addr; + pte = pde; + goto do_check_protect; + } +/* 4 KB page */ +if (!(pde &PG_ACCESSED_MASK )) { + pde |=PG_ACCESSED_MASK ; +x86_stl_phys_notdirty (cs, pde_addr, pde); + } + pte_addr = ((pde &PG_ADDRESS_MASK ) + (((addr >>12 ) &0x1ff ) <<3 )) & + a20_mask; + pte =x86_ldq_phys (cs, pte_addr); +if (!(pte &PG_PRESENT_MASK )) { + goto do_fault; + } +if (pte & rsvd_mask) { + goto do_fault_rsvd; + } +/* combine pde and pte nx, user and rw protections */ + ptep &= pte ^PG_NX_MASK ; + page_size =4096 ; + }else { +uint32_t pde; + +/* page directory entry */ + pde_addr = ((env->cr[3 ] & ~0xfff ) + ((addr >>20 ) &0xffc )) & + a20_mask; + pde =x86_ldl_phys (cs, pde_addr); +if (!(pde &PG_PRESENT_MASK )) { + goto do_fault; + } + ptep = pde |PG_NX_MASK ; + +/* if PSE bit is set, then we use a 4MB page */ +if ((pde &PG_PSE_MASK ) && (env->cr[4 ] &CR4_PSE_MASK )) { + page_size =4096 *1024 ; + pte_addr = pde_addr; + +/* Bits 20-13 provide bits 39-32 of the address, bit 21 is reserved. +* Leave bits 20-13 in place for setting accessed/dirty bits below. +*/ + pte = pde | ((pde &0x1fe000LL ) << (32 -13 )); + rsvd_mask =0x200000 ; + goto do_check_protect_pse36; + } + +if (!(pde &PG_ACCESSED_MASK )) { + pde |=PG_ACCESSED_MASK ; +x86_stl_phys_notdirty (cs, pde_addr, pde); + } + +/* page directory entry */ + pte_addr = ((pde & ~0xfff ) + ((addr >>10 ) &0xffc )) & + a20_mask; + pte =x86_ldl_phys (cs, pte_addr); +if (!(pte &PG_PRESENT_MASK )) { + goto do_fault; + } +/* combine pde and pte user and rw protections */ + ptep &= pte |PG_NX_MASK ; + page_size =4096 ; + rsvd_mask =0 ; + } + +do_check_protect: + rsvd_mask |= (page_size -1 ) &PG_ADDRESS_MASK & ~PG_PSE_PAT_MASK ; +do_check_protect_pse36: +if (pte & rsvd_mask) { + goto do_fault_rsvd; + } + ptep ^=PG_NX_MASK ; + +/* can the page can be put in the TLB? prot will tell us */ +if (is_user && !(ptep &PG_USER_MASK )) { + goto do_fault_protect; + } + + prot =0 ; +if (mmu_idx !=MMU_KSMAP_IDX || !(ptep &PG_USER_MASK )) { + prot |=PAGE_READ ; +if ((ptep &PG_RW_MASK ) || (!is_user && !(env->cr[0 ] &CR0_WP_MASK ))) { + prot |=PAGE_WRITE ; + } + } +if (!(ptep &PG_NX_MASK ) && + (mmu_idx ==MMU_USER_IDX || + !((env->cr[4 ] &CR4_SMEP_MASK ) && (ptep &PG_USER_MASK )))) { + prot |=PAGE_EXEC ; + } +if ((env->cr[4 ] &CR4_PKE_MASK ) && (env->hflags &HF_LMA_MASK ) && + (ptep &PG_USER_MASK ) && env->pkru) { +uint32_t pk = (pte &PG_PKRU_MASK ) >>PG_PKRU_BIT ; +uint32_t pkru_ad = (env->pkru >> pk *2 ) &1 ; +uint32_t pkru_wd = (env->pkru >> pk *2 ) &2 ; +uint32_t pkru_prot =PAGE_READ |PAGE_WRITE |PAGE_EXEC ; + +if (pkru_ad) { + pkru_prot &= ~(PAGE_READ |PAGE_WRITE ); + }else if (pkru_wd && (is_user || env->cr[0 ] &CR0_WP_MASK )) { + pkru_prot &= ~PAGE_WRITE ; + } + + prot &= pkru_prot; +if ((pkru_prot & (1 << is_write1)) ==0 ) { +assert (is_write1 !=2 ); + error_code |=PG_ERROR_PK_MASK ; + goto do_fault_protect; + } + } + +if ((prot & (1 << is_write1)) ==0 ) { + goto do_fault_protect; + } + +/* yes, it can! */ + is_dirty = is_write && !(pte &PG_DIRTY_MASK ); +if (!(pte &PG_ACCESSED_MASK ) || is_dirty) { + pte |=PG_ACCESSED_MASK ; +if (is_dirty) { + pte |=PG_DIRTY_MASK ; + } +x86_stl_phys_notdirty (cs, pte_addr, pte); + } + +if (!(pte &PG_DIRTY_MASK )) { +/* only set write access if already dirty... otherwise wait +for dirty access */ +assert (!is_write); + prot &= ~PAGE_WRITE ; + } + + do_mapping: + pte = pte & a20_mask; + +/* align to page_size */ + pte &=PG_ADDRESS_MASK & ~(page_size -1 ); + +/* Even if 4MB pages, we map only one 4KB page in the cache to +avoid filling it too fast */ + vaddr = addr &TARGET_PAGE_MASK ; + page_offset = vaddr & (page_size -1 ); + paddr = pte + page_offset; + +assert (prot & (1 << is_write1)); +tlb_set_page_with_attrs (cs, vaddr, paddr,cpu_get_mem_attrs (env), + prot, mmu_idx, page_size); +return 0 ; + do_fault_rsvd: + error_code |=PG_ERROR_RSVD_MASK ; + do_fault_protect: + error_code |=PG_ERROR_P_MASK ; + do_fault: + error_code |= (is_write <<PG_ERROR_W_BIT ); +if (is_user) + error_code |=PG_ERROR_U_MASK ; +if (is_write1 ==2 && + (((env->efer &MSR_EFER_NXE ) && + (env->cr[4 ] &CR4_PAE_MASK )) || + (env->cr[4 ] &CR4_SMEP_MASK ))) + error_code |=PG_ERROR_I_D_MASK ; +if (env->intercept_exceptions & (1 <<EXCP0E_PAGE )) { +/* cr2 is not modified in case of exceptions */ +x86_stq_phys (cs, + env->vm_vmcb + offsetof(struct vmcb, control.exit_info_2), + addr); + }else { + env->cr[2 ] = addr; + } + env->error_code = error_code; + cs->exception_index =EXCP0E_PAGE ; +return 1 ; +} +#endif
target/i386/helper.c +1 -343
350 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH v4 20/22 target/i386: add the tcg_enabled() in target/i386/
In reply to Paolo BonziniFrom: Yang Zhong <[email protected]>
Add the tcg_enabled() where the x86 target needs to disable TCG-specific code.
---
v2: do not touch bpt_helper.c, adjust caller in machine.c [Richard]
target/i386/cpu.c | 4 +++- target/i386/cpu.h | 8 +++++++- target/i386/helper.c | 2 +- target/i386/machine.c | 10 +++++----- 4 files changed, 16 insertions(+), 8 deletions(-)
target/i386/cpu.c +3 -1
@@ -4040,8 +4040,10 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data) cc->class_by_name = x86_cpu_class_by_name; cc->parse_features = x86_cpu_parse_featurestr; cc->has_work = x86_cpu_has_work; +#ifdef CONFIG_TCG cc->do_interrupt = x86_cpu_do_interrupt; cc->cpu_exec_interrupt = x86_cpu_exec_interrupt; +#endif cc->dump_state = x86_cpu_dump_state; cc->get_crash_info = x86_cpu_get_crash_info; cc->set_pc = x86_cpu_set_pc;
@@ -4070,7 +4072,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data) cc->gdb_core_xml_file ="i386-32bit.xml" ; cc->gdb_num_core_regs =41 ;#endif -#ifndef CONFIG_USER_ONLY +#if defined(CONFIG_TCG ) && !defined(CONFIG_USER_ONLY ) cc->debug_excp_handler = breakpoint_handler;#endif cc->cpu_exec_enter = x86_cpu_exec_enter;
target/i386/cpu.h +7 -1
@@ -52,7 +52,9 @@#include "exec/cpu-defs.h" +#ifdef CONFIG_TCG #include "fpu/softfloat.h" +#endif #define R_EAX 0#define R_ECX 1
@@ -1597,7 +1599,11 @@ uint32_t cpu_cc_compute_all(CPUX86State *env1, int op);static inline uint32_t cpu_compute_eflags (CPUX86State *env) { -return env->eflags |cpu_cc_compute_all (env,CC_OP ) | (env->df &DF_MASK ); +uint32_t eflags = env->eflags; +if (tcg_enabled ()) { + eflags |=cpu_cc_compute_all (env,CC_OP ) | (env->df &DF_MASK ); + } +return eflags; }/* NOTE: the translator must set DisasContext.cc_op to CC_OP_EFLAGS
target/i386/helper.c +1 -1
@@ -990,7 +990,7 @@ void cpu_report_tpr_access(CPUX86State *env, TPRAccess access) env->tpr_access_type = access;cpu_interrupt (cs,CPU_INTERRUPT_TPR ); - }else { + }else if (tcg_enabled ()) {cpu_restore_state (cs, cs->mem_io_pc);apic_handle_tpr_access_report (cpu->apic_state, env->eip, access);
target/i386/machine.c +5 -5
@@ -281,16 +281,16 @@ static int cpu_post_load(void *opaque, int version_id) env->fptags[i] = (env->fptag_vmstate >> i) &1 ; }if (tcg_enabled ()) { +target_ulong dr7;update_fp_status (env);update_mxcsr_status (env); - } -cpu_breakpoint_remove_all (cs,BP_CPU ); -cpu_watchpoint_remove_all (cs,BP_CPU ); - { +cpu_breakpoint_remove_all (cs,BP_CPU ); +cpu_watchpoint_remove_all (cs,BP_CPU ); +/* Indicate all breakpoints disabled, as they are, then let the helper re-enable them. */ -target_ulong dr7 = env->dr[7 ]; + dr7 = env->dr[7 ]; env->dr[7 ] = dr7 & ~(DR7_GLOBAL_BP_MASK |DR7_LOCAL_BP_MASK );cpu_x86_update_dr7 (env, dr7); }
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 20/22] target/i386: add the tcg_enabled() in target/i386/
Quoted 9 lines · Paolo Bonzini
From: Yang Zhong<[email protected]>
Add the
tcg_enabled()where the x86 target needs to disable TCG-specific code.Signed-off-by Yang Zhong<[email protected]>Signed-off-by Paolo Bonzini<[email protected]>---
v2: do not touchbpt_helper.c, adjust caller inmachine.c[Richard]
r~
PATCH v4 21/22 target/i386: add the CONFIG_TCG into Makefiles
In reply to Paolo BonziniFrom: Yang Zhong <[email protected]>
Add the CONFIG_TCG for frontend and backend's files in the related Makefiles.
---
v2: compile out bpt_helper.c [Richard]
target/i386/Makefile.objs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
target/i386/Makefile.objs +5 -3
@@ -1,7 +1,9 @@ -obj-y += translate.o helper.o cpu.o bpt_helper.o -obj-y += excp_helper.o fpu_helper.o cc_helper.o int_helper.o svm_helper.o -obj-y += smm_helper.o misc_helper.o mem_helper.o seg_helper.o mpx_helper.o +obj-y += helper.o cpu.o obj-y += gdbstub.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 +obj-$(CONFIG_TCG) += seg_helper.o smm_helper.o svm_helper.o obj-$(CONFIG_SOFTMMU) += machine.o arch_memory_mapping.o arch_dump.o monitor.o obj-$(CONFIG_KVM) += kvm.o hyperv.o obj-$(call lnot,$(CONFIG_KVM)) += kvm-stub.o
Signature · 1 line
1.8.3.1
PATCH v4 22/22 configure: warn on untested --disable-tcg
In reply to Paolo Bonzini--disable-tcg will almost certainly fail to compile on non-x86 platforms, so issue a warning.
--- configure | 7 +++++++ 1 file changed, 7 insertions(+)
configure +7 -0
@@ -1771,6 +1771,13 @@ if test "$solaris" = "yes" ; then fi fi +if test "$tcg" = no; then + case "$cpu" in + i386 | x86_64) ;; + *) echo "WARNING: --disable-tcg not supported on this host, compilation may fail" ;; + esac +fi + if test -z "${target_list+xxx}" ; then for target in $default_target_list; do supported_target $target 2>/dev/null && \
Signature · 1 line
1.8.3.1