add disable-tcg option for x86 build
v3 cover add disable-tcg option for x86 build
Most of this series is the same as Yang Zhong's, except for:
1) less stubs usage
2) splitting patch 2 ("vl: add tcg_enabled() for tcg related code") [Thomas]
3) reworked configure [Thomas, Daniel]
Please review!
Paolo
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 | 186 ++++++++++++++------- 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/exec/helper-proto.h | 2 + include/qemu-common.h | 7 +- include/sysemu/accel.h | 2 +- monitor.c | 2 + qom/cpu.c | 2 + target/i386/Makefile.objs | 7 +- target/i386/bpt_helper.c | 32 ++-- target/i386/cpu.c | 4 +- target/i386/cpu.h | 28 +++- target/i386/excp_helper.c | 343 +++++++++++++++++++++++++++++++++++++++ target/i386/fpu_helper.c | 29 +--- target/i386/helper.c | 378 ++++--------------------------------------- target/i386/machine.c | 23 ++- target/i386/mpx_helper.c | 30 ---- tcg/tcg.h | 4 - vl.c | 14 +- 33 files changed, 735 insertions(+), 607 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 v3 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
Re: [Qemu-devel] [PATCH 01/22] configure: factor out list of supported Xen/KVM/HAX targets
Quoted 7 lines · Paolo Bonzini
This will be useful when the functions are called, early in the configure process, to filter out targets that do not support hardware acceleration.
Signed-off-by Paolo Bonzini<[email protected]>--- configure | 90 ++++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 35 deletions(-)
r~
Re: [Qemu-devel] [PATCH 01/22] configure: factor out list of supported Xen/KVM/HAX targets
In reply to Paolo BonziniQuoted 28 lines · Paolo Bonzini
This will be useful when the functions are called, early in the configure process, to filter out targets that do not support hardware acceleration.
Signed-off-by Paolo Bonzini <[email protected]>--- configure | 90 ++++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 35 deletions(-)configure +12
-0@@ -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
configure have_backend () { · line 187
Quoted 10 lines
configure +10
-0+ 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 | \
IIUC, 'x86_64:i386' is claiming that you can run x86_64 KVM guests on an i386 host. I thought that was impossible, only 32-on-64 being allowed not 64-on-32.
configure have_backend () { · line 190
Quoted 3 lines
configure +3
-0+ mips:mips | mipsel:mips | \ + ppc:ppc | ppcemb:ppc | ppc64:ppc | \ + ppc:ppc64 | ppcemb:ppc64 | ppc64:ppc64 | \
Same question here with ppc64:ppc suggesting you can run 64-bit guest with KVM on a 32-bit host ?
configure have_backend () { · line 203
Quoted 13 lines
configure +13
-0+ 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)
This again is claiming support for 64-bit guests with Xen on a 32-bit host, which AFAIK is impossible.
configure have_backend () { · line 179
Quoted 5 lines
configure +5
-0+ return 0 + ;; + esac + return 1 +}
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 :|
Re: [Qemu-devel] [PATCH 01/22] configure: factor out list of supported Xen/KVM/HAX targets
Quoted 11 lines · Daniel P. Berrange
configure have_backend () { · line 187
Quoted 7 lines
configure +7
-0+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 | \IIUC, 'x86_64:i386' is claiming that you can run
x86_64KVM guests on an i386 host. I thought that was impossible, only 32-on-64 being allowed not 64-on-32.
You can use qemu-system-x86_64 to run i386 KVM guests, by disabling long mode with -cpu. It's not a common scenario though.
Quoted 6 lines
configure have_backend () { · line 190
Quoted 3 lines
configure +3
-0+ mips:mips | mipsel:mips | \ + ppc:ppc | ppcemb:ppc | ppc64:ppc | \ + ppc:ppc64 | ppcemb:ppc64 | ppc64:ppc64 | \Same question here with ppc64:ppc suggesting you can run 64-bit guest with KVM on a 32-bit host ?
I'm not sure about this one, but right now it is allowed so this patch is not changing anything.
Quoted 7 lines
Quoted 7 lines
configure +7
-0+ s390x:s390x) + return 0 + ;; + esac + return 1 +} +
Quoted 8 lines
configure have_backend () { · line 203
Quoted 6 lines
configure +6
-0+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)This again is claiming support for 64-bit guests with Xen on a 32-bit host, which AFAIK is impossible.
32-bit dom0 with 64-bit guests actually is not only possible, but also widely used.
Paolo
Daniel P. Berrange
Reviewed-byRe: [Qemu-devel] [PATCH 01/22] configure: factor out list of supported Xen/KVM/HAX targets
Quoted 11 lines · Paolo Bonzini
Quoted 8 lines · Daniel P. Berrange
Quoted 7 lines
configure +7
-0+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 | \
Quoted 6 lines
Quoted 3 lines
IIUC, 'x86_64:i386' is claiming that you can run
x86_64KVM guests on an i386 host. I thought that was impossible, only 32-on-64 being allowed not 64-on-32.You can use qemu-system-x86_64 to run i386 KVM guests, by disabling long mode with -cpu. It's not a common scenario though.
Wow, obscure :-)
Quoted 27 lines
Quoted 7 lines
configure have_backend () { · line 190
Quoted 4 lines
configure +3
-0+ mips:mips | mipsel:mips | \ + ppc:ppc | ppcemb:ppc | ppc64:ppc | \ + ppc:ppc64 | ppcemb:ppc64 | ppc64:ppc64 | \Same question here with ppc64:ppc suggesting you can run 64-bit guest with KVM on a 32-bit host ?
I'm not sure about this one, but right now it is allowed so this patch is not changing anything.
Quoted 7 lines
Quoted 7 lines
configure +7
-0+ s390x:s390x) + return 0 + ;; + esac + return 1 +} +Quoted 8 lines
configure have_backend () { · line 203
Quoted 6 lines
configure +6
-0+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)This again is claiming support for 64-bit guests with Xen on a 32-bit host, which AFAIK is impossible.
Quoted 2 lines
32-bit dom0 with 64-bit guests actually is not only possible, but also widely used.
Oh, i guess I'm missing the distinction between 64-bit hypervisor vs 32-bit dom-0, which still lets you use 64-bit dom-U.
In that case,
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 v3 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.
--- configure | 65 ++++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 22 deletions(-)
configure +43 -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,25 @@ supported_xen_target() { return 1 } +supported_target() { + case "$1" in + ${target_name}-softmmu) ;; + ${target_name}-linux-user) + if test "$linux" != "yes"; then + print_error "Target '$target' is only available on a Linux host" + return 1 + fi + ;; + ${target_name}-bsd-user) + if test "$bsd" != "yes"; then + print_error "Target '$target' is only available on a BSD host" + return 1 + fi + ;; + esac + return 0 +} + # default parameters source_path=$(dirname "$0") cpu=""
@@ -1734,23 +1757,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 +6077,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 7 lines · Paolo Bonzini
Check for unsupported targets in
target_list, and print an error early in the configuration process.Signed-off-by Paolo Bonzini<[email protected]>--- configure | 65 ++++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 22 deletions(-)
r~
Re: [Qemu-devel] [PATCH 02/22] configure: early test for supported targets
In reply to Paolo BonziniQuoted 35 lines · Paolo Bonzini
Check for unsupported targets in
target_list, and print an error early in the configuration process.Signed-off-by Paolo Bonzini <[email protected]>--- configure | 65 ++++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 22 deletions(-)configure +7
-3@@ -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 }
configure supported_xen_target() { · line 216
Quoted 6 lines
configure +3
-0@@ -207,6 +211,25 @@ supported_xen_target() { return 1 } +supported_target() { + case "$1" in + ${target_name}-softmmu) ;;
Nit-pick, I'd prefer the ';;' on a separate line, as currently it at first looks like the -softmmu line will fallthrough to the -linux-user block below. Took a while before I noticed the trailing ;;
Or alternatively add a blank line between cases
configure supported_xen_target() { · line 228
Quoted 12 lines
configure +12
-0+ ${target_name}-linux-user) + if test "$linux" != "yes"; then + print_error "Target '$target' is only available on a Linux host" + return 1 + fi + ;; + ${target_name}-bsd-user) + if test "$bsd" != "yes"; then + print_error "Target '$target' is only available on a BSD host" + return 1 + fi + ;;
Add a wildcard match as a catch-all to avoid falling through to the success codepath on unknown items ?
Quoted 8 lines
configure +4
-0+ esac + return 0 +} + # default parameters source_path=$(dirname "$0") cpu=""
configure if test "$solaris" = "yes" ; then · line 1763
Quoted 8 lines
configure +4
-1@@ -1734,23 +1757,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
I'm not sure what the benefit of this change is ? It is calling supported_target but throwing away anything it prints. So if there was a mistake in the default target list setup, we'd never see it, just silently discard it.
Quoted 19 lines
configure +13
-2+ 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.
configure if test "$solaris" = "yes" ; then · line 1753
Quoted 10 lines
configure +0
-10-for target in $target_list; do - case " $default_target_list " in - *" $target "*) - ;; - *) - error_exit "Unknown target name '$target'" - ;; - esac -done -
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 :|
Re: [Qemu-devel] [PATCH 02/22] configure: early test for supported targets
Quoted 11 lines · Daniel P. Berrange
configure if test "$solaris" = "yes" ; then · line 1763
Quoted 6 lines
if test -z "${target_list+xxx}" ; then
configure +4
-1- target_list="$default_target_list" + for target in $default_target_list; do + supported_target $target 2>/dev/null && \ + target_list="$target_list $target" + doneI'm not sure what the benefit of this change is ? It is calling
supported_targetbut throwing away anything it prints. So if there was a mistake in the default target list setup, we'd never see it, just silently discard it.
As of this patch there is no benefit, but it is what makes patch 3 drop non-hardware-accelerated targets for --disable-tcg.
Paolo
PATCH v3 3/22 configure: add --disable-tcg configure option
In reply to Paolo BonziniThis 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
@@ -227,7 +227,12 @@ supported_target() { fi ;; 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
@@ -291,6 +296,7 @@ cap_ng="" attr="" libattr="" xfs="" +tcg="yes" vhost_net="no" vhost_scsi="no"
@@ -1028,6 +1034,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"
@@ -5190,7 +5200,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"
@@ -5245,8 +5254,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"
@@ -5689,8 +5702,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
Re: [Qemu-devel] [PATCH 03/22] configure: add --disable-tcg configure option
Quoted 9 lines · Paolo Bonzini
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.
Signed-off-by Anthony Liguori<[email protected]>Signed-off-by Paolo Bonzini<[email protected]>--- configure | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-)
r~
Re: [Qemu-devel] [PATCH 03/22] configure: add --disable-tcg configure option
In reply to Paolo BonziniQuoted 9 lines · Paolo Bonzini
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.
Signed-off-by Anthony Liguori <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- configure | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 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 v3 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
Re: [Qemu-devel] [PATCH 04/22] vl: convert -tb-size to qemu_strtoul
include/sysemu/accel.h typedef struct AccelClass { · line 66
Quoted 2 lines · Paolo Bonzini
include/sysemu/accel.h +1
-1-extern int tcg_tb_size; +extern unsigned long tcg_tb_size;
size_t would be more natural.
I don't think we support any hosts for which sizeof(size_t) != sizeof(unsigned long), but perhaps
unsigned lomg tmp;
if (qemu_strtoul(optarg, NULL, 0, &tmp) < 0
|| tmp != (size_t)tmp) {
error_report("Invalid argument to -tb-size");
exit(1);
}
tcg_tb_size = tmp;where I'd expect the extra comparison to be optimized away.
But I'm not overly concerned either way, so
r~
Re: [Qemu-devel] [PATCH 04/22] vl: convert -tb-size to qemu_strtoul
Quoted 8 lines · Richard Henderson
include/sysemu/accel.h typedef struct AccelClass { · line 66
Quoted 2 lines · Paolo Bonzini
include/sysemu/accel.h +1
-1-extern int tcg_tb_size; +extern unsigned long tcg_tb_size;
size_twould be more natural.I don't think we support any hosts for which
sizeof(size_t)!= sizeof(unsigned long), but perhaps
There's Win64... Another place where to do the range check could be tcg_exec_init. That's where the actual bug lies.
The previous code's error handling was even worse, since strtol's output was completely unchecked. tcg_exec_init can be fixed later.
Paolo
Quoted 16 lines
unsigned lomg tmp; if (qemu_strtoul(optarg, NULL, 0, &tmp) < 0 || tmp != (size_t)tmp) { error_report("Invalid argument to -tb-size"); exit(1); } tcg_tb_size = tmp;where I'd expect the extra comparison to be optimized away.
But I'm not overly concerned either way, so
Reviewed-by Richard Henderson <[email protected]>r~
Re: [Qemu-devel] [PATCH 04/22] vl: convert -tb-size to qemu_strtoul
In reply to Richard HendersonQuoted 17 lines · Richard Henderson
include/sysemu/accel.h typedef struct AccelClass { · line 66
Quoted 2 lines · Paolo Bonzini
include/sysemu/accel.h +1
-1-extern int tcg_tb_size; +extern unsigned long tcg_tb_size;
size_twould be more natural.I don't think we support any hosts for which
sizeof(size_t)!= sizeof(unsigned long), but perhapsunsigned lomg tmp; if (qemu_strtoul(optarg, NULL, 0, &tmp) < 0 || tmp != (size_t)tmp) { error_report("Invalid argument to -tb-size"); exit(1); } tcg_tb_size = tmp;
Quoted 1 line
where I'd expect the extra comparison to be optimized away.
If we wanted to use size_t, then I'd suggest we added a qemu_strtoXXX variant that directly returned a size_t, and did suitabled bounds checking
Quoted 1 line
But I'm not overly concerned either way, so
Agreed, doesn't need fixing now
Quoted 1 line
Reviewed-by Richard Henderson <[email protected]>
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 v3 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
Re: [Qemu-devel] [PATCH 05/22] vl: add tcg_enabled() for tcg related code
Quoted 10 lines · Paolo Bonzini
From: Yang Zhong<[email protected]>
Need to disable the tcg related code in the
vl.cif the disable-tcg option is added into ./configure command.Signed-off-by Yang Zhong<[email protected]>Signed-off-by Paolo Bonzini<[email protected]>--- vl.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
r~
PATCH v3 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
Re: [Qemu-devel] [PATCH 06/22] tcg: move page_size_init() function
Quoted 6 lines · Paolo Bonzini
From: Yang Zhong<[email protected]>
translate-all.cwill be disabled if tcg is disabled in the build, sopage_size_init()function and related variables will be moved toexec.cfile.
Quoted 6 lines
Signed-off-by Yang Zhong<[email protected]>Signed-off-by Paolo Bonzini<[email protected]>--- accel/tcg/translate-all.c | 18 ------------------ exec.c | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 18 deletions(-)
r~
PATCH v3 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
Re: [Qemu-devel] [PATCH 07/22] tcg: tcg_handle_interrupt() function
Quoted 7 lines · Paolo Bonzini
From: Yang Zhong<[email protected]>
Move
tcg_handle_interrupt()fromtranslate-common.ctoaccel/tcg/tcg-all.c.Signed-off-by Yang Zhong<[email protected]>Signed-off-by Paolo Bonzini<[email protected]>
Quoted 7 lines
--- 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
r~
PATCH v3 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
Re: [Qemu-devel] [PATCH 08/22] tcg: make tcg_allowed global
Quoted 5 lines · Paolo Bonzini
From: Yang Zhong<[email protected]>
Change the
tcg_enabled()and make sure user build still enable tcg even x86 softmmu disable tcg.
Quoted 8 lines
Signed-off-by Yang Zhong<[email protected]>Signed-off-by Paolo Bonzini<[email protected]>--- 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(-)
r~
PATCH v3 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 6 lines · Paolo Bonzini
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(+)
r~
PATCH v3 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
Re: [Qemu-devel] [PATCH 10/22] vapic: use tcg_enabled
Quoted 4 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini<[email protected]>--- hw/i386/kvmvapic.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
r~
PATCH v3 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
Re: [Qemu-devel] [PATCH 11/22] tcg: add the tcg-stub.c file into accel/stubs/
Quoted 6 lines · Paolo Bonzini
From: Yang Zhong<[email protected]>
If tcg is disabled, the functions in
tcg-stub.cfile will be called. This file is target-independent file, do not include any platform related stub functions into this file.
Quoted 7 lines
Signed-off-by Yang Zhong<[email protected]>Signed-off-by Paolo Bonzini<[email protected]>--- accel/stubs/Makefile.objs | 1 + accel/stubs/tcg-stub.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+)create mode 100644
accel/stubs/tcg-stub.c
r~
PATCH v3 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
Re: [Qemu-devel] [PATCH 12/22] tcg: move tb_lock out of translate-all.h
Quoted 6 lines · Paolo Bonzini
Signed-off-by Paolo Bonzini<[email protected]>--- bsd-user/main.c | 1 - include/exec/exec-all.h | 4 ++++ tcg/tcg.h | 4 ---- 3 files changed, 4 insertions(+), 5 deletions(-)
r~
PATCH v3 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
Re: [Qemu-devel] [PATCH 13/22] exec: elide calls to tb_lock and tb_unlock
Quoted 6 lines · Paolo Bonzini
Adding assertions fixes link errors.
Signed-off-by Paolo Bonzini<[email protected]>--- exec.c | 3 +++ 1 file changed, 3 insertions(+)
r~
PATCH v3 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.
--- include/exec/cpu-defs.h | 4 +++- include/exec/cputlb.h | 2 +- include/exec/exec-all.h | 53 ++++++++++++++++++++++++--------------------- include/exec/helper-proto.h | 2 ++ 4 files changed, 34 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
include/exec/helper-proto.h +2 -0
@@ -28,7 +28,9 @@ dh_ctype(ret) HELPER(name) (dh_ctype(t1), dh_ctype(t2), dh_ctype(t3), \#include "helper.h" #include "trace/generated-helpers.h" +#ifdef CONFIG_TCG #include "tcg-runtime.h" +#endif #undef DEF_HELPER_FLAGS_0#undef DEF_HELPER_FLAGS_1
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 14/22] tcg: add CONFIG_TCG guards in headers
include/exec/helper-proto.h dh_ctype(ret) HELPER(name) (dh_ctype(t1), dh_ctype(t2), dh_ctype(t3), \ · line 33
Quoted 9 lines · Paolo Bonzini
include/exec/helper-proto.h +2
-0@@ -28,7 +28,9 @@ dh_ctype(ret) HELPER(name) (dh_ctype(t1), dh_ctype(t2), dh_ctype(t3), \#include "helper.h" #include "trace/generated-helpers.h" +#ifdef CONFIG_TCG #include "tcg-runtime.h" +#endif
Do we really want to define any of the helpers if !CONFIG_TCG? Perhaps it's the user of this header that needs adjustment.
r~
Re: [Qemu-devel] [PATCH 14/22] tcg: add CONFIG_TCG guards in headers
Quoted 13 lines · Richard Henderson
include/exec/helper-proto.h dh_ctype(ret) HELPER(name) (dh_ctype(t1), · line 33
Quoted 9 lines · Paolo Bonzini
include/exec/helper-proto.h +2
-0@@ -28,7 +28,9 @@ dh_ctype(ret) HELPER(name) (dh_ctype(t1),dh_ctype (t2),dh_ctype (t3), \ #include "helper.h"#include "trace/generated-helpers.h" +#ifdef CONFIG_TCG #include "tcg-runtime.h" +#endif Do we really want to define any of the helpers if !CONFIG_TCG? Perhaps it's the user of this header that needs adjustment.
Indeed, this hunk is not needed anymore after my other cleanups.
Paolo
PATCH v3 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
Re: [Qemu-devel] [PATCH 15/22] tcg: add the CONFIG_TCG into Makefiles
Quoted 11 lines · Paolo Bonzini
From: Yang Zhong<[email protected]>
Add the
CONFIG_TCGfor frontend and backend's files in the related Makefiles.Signed-off-by Yang Zhong<[email protected]>Signed-off-by Paolo Bonzini<[email protected]>--- Makefile.target | 4 ++-- accel/Makefile.objs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
r~
PATCH v3 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.
--- target/i386/helper.c | 34 +++++++++++++++++++++++++++++++++- target/i386/mpx_helper.c | 30 ------------------------------ 2 files changed, 33 insertions(+), 31 deletions(-)
target/i386/helper.c +33 -1
@@ -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;
@@ -1302,10 +1332,12 @@ 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); + }else { +abort (); } }#endif /* !CONFIG_USER_ONLY */
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 4 lines · Paolo Bonzini
target/i386/helper.c +0
-0@@ -1302,10 +1332,12 @@ void cpu_report_tpr_access(CPUX86State *env, TPRAccess access) env->tpr_access_type = access;cpu_interrupt (cs,CPU_INTERRUPT_TPR );
target/i386/helper.c void cpu_report_tpr_access(CPUX86State *env, TPRAccess access) · line 1343
Quoted 10 lines
target/i386/helper.c +3
-1- } else { + } else if (tcg_enabled()) {cpu_restore_state (cs, cs->mem_io_pc);apic_handle_tpr_access_report (cpu->apic_state, env->eip, access); + }else { +abort (); } }#endif /* !CONFIG_USER_ONLY */
This hunk belongs in another patch.
r~
PATCH v3 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
Re: [Qemu-devel] [PATCH 17/22] target/i386: make cpu_get_fp80()/cpu_set_fp80() static
Quoted 6 lines · Paolo Bonzini
From: Yang Zhong<[email protected]>
Move cpu_get_fp80()/cpu_set_fp80() from
fpu_helper.ctomachine.cbecausefpu_helper.cwill be disabled if tcg is disabled in the build.
Quoted 7 lines
Signed-off-by Yang Zhong<[email protected]>Signed-off-by Paolo Bonzini<[email protected]>--- target/i386/cpu.h | 2 -- target/i386/fpu_helper.c | 18 ------------------ target/i386/machine.c | 18 ++++++++++++++++++ 3 files changed, 18 insertions(+), 20 deletions(-)
r~
PATCH v3 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.
--- target/i386/cpu.h | 18 ++++++++++++++++-- target/i386/fpu_helper.c | 11 ++--------- 2 files changed, 18 insertions(+), 11 deletions(-)
target/i386/cpu.h +16 -2
@@ -1643,8 +1643,22 @@ 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 tcg_update_mxcsr (CPUX86State *env); +static inline void cpu_set_mxcsr (CPUX86State *env,uint32_t mxcsr) +{ + env->mxcsr = mxcsr; +if (tcg_enabled ()) { +tcg_update_mxcsr (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 tcg_update_mxcsr (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);
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
target/i386/cpu.h static inline int32_t x86_get_a20_mask(CPUX86State *env) · line 1651
Quoted 5 lines · Paolo Bonzini
target/i386/cpu.h +5
-0+static inline void cpu_set_mxcsr (CPUX86State *env,uint32_t mxcsr) +{ + env->mxcsr = mxcsr; +if (tcg_enabled ()) { +tcg_update_mxcsr (env);
I'd prefer update_mxcsr_status for this new name.
target/i386/cpu.h static inline int32_t x86_get_a20_mask(CPUX86State *env) · line 1661
Quoted 10 lines
target/i386/cpu.h +10
-0+ } +} + +static inline void cpu_set_fpuc (CPUX86State *env,uint16_t fpuc) +{ + env->fpuc = fpuc; +if (tcg_enabled ()) { +update_fp_status (env); + } +}
to match this, and to avoid the implication that it's a function in tcg/.
r~
Re: [Qemu-devel] [PATCH 18/22] target/i386: split cpu_set_mxcsr() and make cpu_set_fpuc() inline
Quoted 9 lines · Richard Henderson
target/i386/cpu.h static inline int32_t x86_get_a20_mask(CPUX86State *env) · line 1651
Quoted 5 lines · Paolo Bonzini
target/i386/cpu.h +5
-0+static inline void cpu_set_mxcsr (CPUX86State *env,uint32_t mxcsr) +{ + env->mxcsr = mxcsr; +if (tcg_enabled ()) { +tcg_update_mxcsr (env);I'd prefer
update_mxcsr_statusfor this new name.
Quoted 12 lines
target/i386/cpu.h static inline int32_t x86_get_a20_mask(CPUX86State *env) · line 1661
Quoted 10 lines
target/i386/cpu.h +10
-0+ } +} + +static inline void cpu_set_fpuc (CPUX86State *env,uint16_t fpuc) +{ + env->fpuc = fpuc; +if (tcg_enabled ()) { +update_fp_status (env); + } +}to match this, and to avoid the implication that it's a function in tcg/.
Good. Also, the existing place in machine.c that calls update_fp_status should call update_mxcsr_status as well.
Paolo
PATCH v3 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
Re: [Qemu-devel] [PATCH 19/22] target/i386: move TLB refill function out of helper.c
Quoted 8 lines · Paolo Bonzini
This function calls
tlb_set_page_with_attrs, which is not available when TCG is disabled. Move it toexcp_helper.c.Signed-off-by Paolo Bonzini<[email protected]>--- target/i386/excp_helper.c | 343 +++++++++++++++++++++++++++++++++++++++++++++ target/i386/helper.c | 344 +--------------------------------------------- 2 files changed, 344 insertions(+), 343 deletions(-)
r~
PATCH v3 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.
--- target/i386/bpt_helper.c | 32 +++++++++++++++++++++++--------- target/i386/cpu.c | 4 +++- target/i386/cpu.h | 8 +++++++- target/i386/machine.c | 5 +++-- 4 files changed, 36 insertions(+), 13 deletions(-)
target/i386/bpt_helper.c +23 -9
@@ -215,10 +215,12 @@ void breakpoint_handler(CPUState *cs)if (cs->watchpoint_hit) {if (cs->watchpoint_hit->flags &BP_CPU ) { cs->watchpoint_hit =NULL ; -if (check_hw_breakpoints (env, false)) { -raise_exception (env,EXCP01_DB ); - }else { -cpu_loop_exit_noexc (cs); +if (tcg_enabled ()) { +if (check_hw_breakpoints (env, false)) { +raise_exception (env,EXCP01_DB ); + }else { +cpu_loop_exit_noexc (cs); + } } } }else {
@@ -226,7 +228,9 @@ void breakpoint_handler(CPUState *cs)if (bp->pc == env->eip) {if (bp->flags &BP_CPU ) {check_hw_breakpoints (env, true); -raise_exception (env,EXCP01_DB ); +if (tcg_enabled ()) { +raise_exception (env,EXCP01_DB ); + } }break ; }
@@ -241,7 +245,9 @@ void helper_single_step(CPUX86State *env)check_hw_breakpoints (env, true); env->dr[6 ] |=DR6_BS ;#endif -raise_exception (env,EXCP01_DB ); +if (tcg_enabled ()) { +raise_exception (env,EXCP01_DB ); + } }void helper_rechecking_single_step (CPUX86State *env)
@@ -282,7 +288,9 @@ void helper_set_dr(CPUX86State *env, int reg, target_ulong t0)cpu_x86_update_dr7 (env, t0); return; } -raise_exception_err_ra (env,EXCP06_ILLOP ,0 ,GETPC ()); +if (tcg_enabled ()) { +raise_exception_err_ra (env,EXCP06_ILLOP ,0 ,GETPC ()); + }#endif }
@@ -304,7 +312,11 @@ target_ulong helper_get_dr(CPUX86State *env, int reg)return env->dr[7 ]; } } -raise_exception_err_ra (env,EXCP06_ILLOP ,0 ,GETPC ()); +if (tcg_enabled ()) { +raise_exception_err_ra (env,EXCP06_ILLOP ,0 ,GETPC ()); + }else { +return 0 ; + } }/* Check if Port I/O is trapped by a breakpoint. */
@@ -329,7 +341,9 @@ void helper_bpt_io(CPUX86State *env, uint32_t port,if (hit) { env->dr[6 ] = (env->dr[6 ] & ~0xf ) | hit; env->eip = next_eip; -raise_exception (env,EXCP01_DB ); +if (tcg_enabled ()) { +raise_exception (env,EXCP01_DB ); + } }#endif }
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
@@ -1598,7 +1600,11 @@ void update_fp_status(CPUX86State *env);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/machine.c +3 -2
@@ -280,8 +280,9 @@ 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); + }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 20/22] target/i386: add the tcg_enabled() in target/i386/
Quoted 4 lines · Paolo Bonzini
target/i386/bpt_helper.c +0
-0@@ -215,10 +215,12 @@ void breakpoint_handler(CPUState *cs)if (cs->watchpoint_hit) {if (cs->watchpoint_hit->flags &BP_CPU ) { cs->watchpoint_hit =NULL ;
target/i386/bpt_helper.c void breakpoint_handler(CPUState *cs) · line 223
Quoted 10 lines
target/i386/bpt_helper.c +6
-4-if (check_hw_breakpoints (env, false)) { -raise_exception (env,EXCP01_DB ); - }else { -cpu_loop_exit_noexc (cs); +if (tcg_enabled ()) { +if (check_hw_breakpoints (env, false)) { +raise_exception (env,EXCP01_DB ); + }else { +cpu_loop_exit_noexc (cs); + }
This seems like an odd place for the tcg_enabled check. It seems like it should be much higher in the if/call chain.
Why are we doing all these bp checks only to disable the final raising of an exception?
Indeed, what in bpt_helper.c needs to be compiled in when !tcg_enabled?
r~
Re: [Qemu-devel] [PATCH 20/22] target/i386: add the tcg_enabled() in target/i386/
Quoted 19 lines · Richard Henderson
Quoted 4 lines · Paolo Bonzini
target/i386/bpt_helper.c +0
-0@@ -215,10 +215,12 @@ void breakpoint_handler(CPUState *cs)if (cs->watchpoint_hit) {if (cs->watchpoint_hit->flags &BP_CPU ) { cs->watchpoint_hit =NULL ;target/i386/bpt_helper.c void breakpoint_handler(CPUState *cs) · line 223
Quoted 10 lines
target/i386/bpt_helper.c +6
-4-if (check_hw_breakpoints (env, false)) { -raise_exception (env,EXCP01_DB ); - }else { -cpu_loop_exit_noexc (cs); +if (tcg_enabled ()) { +if (check_hw_breakpoints (env, false)) { +raise_exception (env,EXCP01_DB ); + }else { +cpu_loop_exit_noexc (cs); + }This seems like an odd place for the
tcg_enabledcheck. It seems like it should be much higher in the if/call chain.
Quoted 4 lines
Why are we doing all these bp checks only to disable the final raising of an exception?
Indeed, what in
bpt_helper.cneeds to be compiled in when !tcg_enabled?
Only cpu_x86_update_dr7, but it's not used by KVM (I was worried about guest debug aka gdbstub mode). So that's my own brain fart; I'll wrap the cpu_x86_update_dr7 with tcg_enabled and drop the file altogether.
Paolo
PATCH v3 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.
--- target/i386/Makefile.objs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
target/i386/Makefile.objs +4 -3
@@ -1,6 +1,7 @@ -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 bpt_helper.o +obj-$(CONFIG_TCG) += translate.o +obj-$(CONFIG_TCG) += excp_helper.o fpu_helper.o int_helper.o svm_helper.o cc_helper.o +obj-$(CONFIG_TCG) += smm_helper.o misc_helper.o mem_helper.o seg_helper.o mpx_helper.o obj-y += gdbstub.o obj-$(CONFIG_SOFTMMU) += machine.o arch_memory_mapping.o arch_dump.o monitor.o obj-$(CONFIG_KVM) += kvm.o hyperv.o
Signature · 1 line
1.8.3.1
Re: [Qemu-devel] [PATCH 21/22] target/i386: add the CONFIG_TCG into Makefiles
Quoted 17 lines · Paolo Bonzini
From: Yang Zhong <[email protected]>
Add the
CONFIG_TCGfor frontend and backend's files in the related Makefiles.Signed-off-by Yang Zhong <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- target/i386/Makefile.objs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)target/i386/Makefile.objs +0
-0
target/i386/Makefile.objs line 7
Quoted 10 lines
target/i386/Makefile.objs +4
-3@@ -1,6 +1,7 @@ -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 bpt_helper.o +obj-$(CONFIG_TCG) += translate.o +obj-$(CONFIG_TCG) += excp_helper.o fpu_helper.o int_helper.o svm_helper.o cc_helper.o +obj-$(CONFIG_TCG) += smm_helper.o misc_helper.o mem_helper.o seg_helper.o mpx_helper.o obj-y += gdbstub.o obj-$(CONFIG_SOFTMMU) += machine.o arch_memory_mapping.o arch_dump.o monitor.o obj-$(CONFIG_KVM) += kvm.o hyperv.o
Modulo my final question for patch 20,
r~
PATCH v3 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
@@ -1766,6 +1766,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
Re: [Qemu-devel] [PATCH 22/22] configure: warn on untested --disable-tcg
Quoted 7 lines · Paolo Bonzini
--disable-tcg will almost certainly fail to compile on non-x86 platforms, so issue a warning.
Signed-off-by Paolo Bonzini<[email protected]>--- configure | 7 +++++++ 1 file changed, 7 insertions(+)
r~
Re: [Qemu-devel] [PATCH 22/22] configure: warn on untested --disable-tcg
In reply to Paolo BonziniQuoted 7 lines · Paolo Bonzini
--disable-tcg will almost certainly fail to compile on non-x86 platforms, so issue a warning.
Signed-off-by Paolo Bonzini <[email protected]>--- configure | 7 +++++++ 1 file changed, 7 insertions(+)
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 :|