maintainer updates for jan '25 (semihosting, gdb, plugins)
cover maintainer updates for jan '25 (semihosting, gdb, plugins)
This covers my remaining trees outside of testing/next and is mostly a consolidation of patches I've pulled from other people.
For semihosting:
- a bunch of cleanups from Philippe to aide single binary builds
For gdbstub (touches system/vl.c as well):
- propagate *Error to setup functions
Ilya, I know about [PATCH v4 0/9] gdbstub: Allow late attachment and will look at that later. I didn't want to delay the rest of my reviews fighting with a messy re-base. If you are up for it you can post a branch on the thread and I can potentially merge from that. Apologies for the rug-pull between v3 and v4.
For plugins
- mostly fixes from Pierrick
- a speculative fix for cpu_io_recompile() case exposed by Julian's discontinuity patches.
Most are already reviewed, the following remain:
accel/tcg: also suppress asynchronous IRQs for cpu_io_recompile
system: propagate Error to gdbserver_start (and other device setups) (1 acks, 1 sobs, 0 tbs)
system: squash usb_parse into a single function
system/vl: more error exit into config enumeration code
semihosting: add guest_error logging for failed opens
There will likely be a v2 anyway once I've got testing/next merged and Ilya's gdbstub patches. I don't think I have anything else pending but do shout if there is.
Alex.
Alex Bennée (5):
semihosting: add guest_error logging for failed opens system/vl: more error exit into config enumeration code
system: squash usb_parse into a single function
system: propagate Error to gdbserver_start (and other device setups) accel/tcg: also suppress asynchronous IRQs for cpu_io_recompile
Philippe Mathieu-Daudé (6):
semihosting/uaccess: Briefly document returned values semihosting/syscalls: Include missing 'exec/cpu-defs.h' header semihosting/uaccess: Include missing 'exec/cpu-all.h' header semihosting/arm-compat: Include missing 'cpu.h' header semihosting/console: Avoid including 'cpu.h' semihosting/meson: Build config.o and console.o once
Pierrick Bouvier (11):
tests/tcg/plugins/insn: remove unused callback parameter contrib/plugins/howvec: ensure we don't regress if this plugin is
extended
tests/tcg/plugins/syscall: fix 32-bit build tests/tcg/plugins/mem: fix 32-bit build contrib/plugins/stoptrigger: fix 32-bit build contrib/plugins/cache: fix 32-bit build contrib/plugins/hotblocks: fix 32-bit build contrib/plugins/cflow: fix 32-bit build contrib/plugins/hwprofile: fix 32-bit build contrib/plugins/hotpages: fix 32-bit build
configure: reenable plugins by default for 32-bit hosts
configure | 21 +------- include/exec/gdbstub.h | 8 ++- include/semihosting/console.h | 2 - include/semihosting/syscalls.h | 1 + include/semihosting/uaccess.h | 55 +++++++++++++++++++ accel/tcg/translate-all.c | 5 +- contrib/plugins/cache.c | 18 +++---- contrib/plugins/cflow.c | 17 +++--- contrib/plugins/hotblocks.c | 29 ++++++++-- contrib/plugins/hotpages.c | 6 +-- contrib/plugins/howvec.c | 7 +-- contrib/plugins/hwprofile.c | 27 ++++++---- contrib/plugins/stoptrigger.c | 48 +++++++++-------- gdbstub/system.c | 22 ++++---- gdbstub/user.c | 20 +++---- linux-user/main.c | 6 +-- monitor/hmp-cmds.c | 2 +- semihosting/arm-compat-semi.c | 1 + semihosting/console.c | 3 +- semihosting/syscalls.c | 2 + semihosting/uaccess.c | 1 + system/vl.c | 99 ++++++++++++++-------------------- tests/tcg/plugins/insn.c | 4 +- tests/tcg/plugins/mem.c | 6 +-- tests/tcg/plugins/syscall.c | 6 +-- semihosting/meson.build | 9 ++-- 26 files changed, 243 insertions(+), 182 deletions(-)
Signature · 1 line
2.39.5
PATCH 1/22 semihosting: add guest_error logging for failed opens
This usually indicates the semihosting call was expecting to find something but didn't.
--- semihosting/syscalls.c | 2 ++ 1 file changed, 2 insertions(+)
semihosting/syscalls.c +2 -0
@@ -7,6 +7,7 @@*/ #include "qemu/osdep.h" +#include "qemu/log.h" #include "cpu.h" #include "gdbstub/syscalls.h" #include "semihosting/guestfd.h"
@@ -287,6 +288,7 @@ static void host_open(CPUState *cs, gdb_syscall_complete_cb complete, ret =open (p, host_flags, mode);if (ret <0 ) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: failed to open %s\n" , __func__, p);complete (cs,-1 , errno); }else {int guestfd =alloc_guestfd ();
Signature · 1 line
2.39.5
Re: [PATCH 01/22] semihosting: add guest_error logging for failed opens
Quoted 21 lines · Alex Bennée
This usually indicates the semihosting call was expecting to find something but didn't.
Signed-off-by Alex Bennée <[email protected]>--- semihosting/syscalls.c | 2 ++ 1 file changed, 2 insertions(+)semihosting/syscalls.c +1
-0@@ -7,6 +7,7 @@*/ #include "qemu/osdep.h" +#include "qemu/log.h" #include "cpu.h" #include "gdbstub/syscalls.h" #include "semihosting/guestfd.h"
semihosting/syscalls.c static void host_open(CPUState *cs, gdb_syscall_complete_cb complete, · line 294
Quoted 7 lines
semihosting/syscalls.c +1
-0@@ -287,6 +288,7 @@ static void host_open(CPUState *cs, gdb_syscall_complete_cb complete, ret =open (p, host_flags, mode);if (ret <0 ) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: failed to open %s\n" , __func__, p);complete (cs,-1 , errno); }else {int guestfd =alloc_guestfd ();
PATCH 2/22 semihosting/uaccess: Briefly document returned values
In reply to Alex BennéeFrom: Philippe Mathieu-Daudé <[email protected]>
Since it is not obvious the get/put_user*() methods can return an error, add brief docstrings about it. Also remind to use *unlock_user() when appropriate.
Message-Id: <[email protected]>
--- include/semihosting/uaccess.h | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
include/semihosting/uaccess.h +55 -0
@@ -19,41 +19,96 @@#include "exec/tswap.h" #include "exec/page-protection.h" +/** +* get_user_u64: +* +* Returns: 0 on success, -1 on error. +*/ #define get_user_u64 (val, addr) \ ({ uint64_t val_ = 0; \ int ret_ = cpu_memory_rw_debug(env_cpu(env), (addr), \ &val_, sizeof(val_), 0); \ (val) = tswap64(val_); ret_; }) +/** +* get_user_u32: +* +* Returns: 0 on success, -1 on error. +*/ #define get_user_u32 (val, addr) \ ({ uint32_t val_ = 0; \ int ret_ = cpu_memory_rw_debug(env_cpu(env), (addr), \ &val_, sizeof(val_), 0); \ (val) = tswap32(val_); ret_; }) +/** +* get_user_u8: +* +* Returns: 0 on success, -1 on error. +*/ #define get_user_u8 (val, addr) \ ({ uint8_t val_ = 0; \ int ret_ = cpu_memory_rw_debug(env_cpu(env), (addr), \ &val_, sizeof(val_), 0); \ (val) = val_; ret_; }) +/** +* get_user_ual: +* +* Returns: 0 on success, -1 on error. +*/ #define get_user_ual (arg, p) get_user_u32(arg, p) +/** +* put_user_u64: +* +* Returns: 0 on success, -1 on error. +*/ #define put_user_u64 (val, addr) \ ({ uint64_t val_ = tswap64(val); \ cpu_memory_rw_debug(env_cpu(env), (addr), &val_, sizeof(val_), 1); }) +/** +* put_user_u32: +* +* Returns: 0 on success, -1 on error. +*/ #define put_user_u32 (val, addr) \ ({ uint32_t val_ = tswap32(val); \ cpu_memory_rw_debug(env_cpu(env), (addr), &val_, sizeof(val_), 1); }) +/** +* put_user_ual: +* +* Returns: 0 on success, -1 on error. +*/ #define put_user_ual (arg, p) put_user_u32(arg, p) +/** +* uaccess_lock_user: +* +* The returned pointer should be freed using uaccess_unlock_user(). +*/ void *uaccess_lock_user (CPUArchState *env,target_ulong addr,target_ulong len,bool copy); +/** +* lock_user: +* +* The returned pointer should be freed using unlock_user(). +*/ #define lock_user (type, p, len, copy) uaccess_lock_user(env, p, len, copy) +/** +* uaccess_lock_user_string: +* +* The returned string should be freed using uaccess_unlock_user(). +*/ char *uaccess_lock_user_string (CPUArchState *env,target_ulong addr); +/** +* uaccess_lock_user_string: +* +* The returned string should be freed using unlock_user(). +*/ #define lock_user_string (p) uaccess_lock_user_string(env, p) void uaccess_unlock_user(CPUArchState *env, void *p,
Signature · 1 line
2.39.5
PATCH 3/22 semihosting/syscalls: Include missing 'exec/cpu-defs.h' header
In reply to Alex BennéeFrom: Philippe Mathieu-Daudé <[email protected]>
target_ulong is defined in each target "cpu-param.h", itself included by "exec/cpu-defs.h".
Include the latter in order to avoid when refactoring:
include/semihosting/syscalls.h:26:24: error: unknown type name 'target_ulong'
26 | target_ulong fname, target_ulong fname_len,
| ^Message-Id: <[email protected]>
--- include/semihosting/syscalls.h | 1 + 1 file changed, 1 insertion(+)
include/semihosting/syscalls.h +1 -0
@@ -9,6 +9,7 @@#ifndef SEMIHOSTING_SYSCALLS_H #define SEMIHOSTING_SYSCALLS_H +#include "exec/cpu-defs.h" #include "gdbstub/syscalls.h" /*
Signature · 1 line
2.39.5
PATCH 4/22 semihosting/uaccess: Include missing 'exec/cpu-all.h' header
In reply to Alex BennéeFrom: Philippe Mathieu-Daudé <[email protected]>
TLB_INVALID_MASK is defined in "exec/cpu-all.h".
Include it in order to avoid when refactoring:
../semihosting/uaccess.c:41:21: error: use of undeclared identifier 'TLB_INVALID_MASK'
41 | if (flags & TLB_INVALID_MASK) {
| ^Message-Id: <[email protected]>
--- semihosting/uaccess.c | 1 + 1 file changed, 1 insertion(+)
semihosting/uaccess.c +1 -0
@@ -8,6 +8,7 @@*/ #include "qemu/osdep.h" +#include "exec/cpu-all.h" #include "exec/exec-all.h" #include "semihosting/uaccess.h"
Signature · 1 line
2.39.5
PATCH 5/22 semihosting/arm-compat: Include missing 'cpu.h' header
In reply to Alex BennéeFrom: Philippe Mathieu-Daudé <[email protected]>
ARM semihosting implementations in "common-semi-target.h" must de-reference the target CPUArchState, which is declared in each target "cpu.h" header. Include it in order to avoid when refactoring:
In file included from ../../semihosting/arm-compat-semi.c:169:
../target/riscv/common-semi-target.h:16:5: error: use of undeclared identifier 'RISCVCPU'
16 | RISCVCPU *cpu = RISCV_CPU(cs);
| ^Message-Id: <[email protected]>
--- semihosting/arm-compat-semi.c | 1 + 1 file changed, 1 insertion(+)
semihosting/arm-compat-semi.c +1 -0
@@ -166,6 +166,7 @@ static LayoutInfo common_semi_find_bases(CPUState *cs)#endif +#include "cpu.h" #include "common-semi-target.h" /*
Signature · 1 line
2.39.5
PATCH 6/22 semihosting/console: Avoid including 'cpu.h'
In reply to Alex BennéeFrom: Philippe Mathieu-Daudé <[email protected]>
The CPUState structure is declared in "hw/core/cpu.h", the EXCP_HALTED definition in "exec/cpu-common.h". Both headers are indirectly include by "cpu.h". In order to remove "cpu.h" from "semihosting/console.h", explicitly include them in console.c, otherwise we'd get:
../semihosting/console.c:88:11: error: incomplete definition of type 'struct CPUState'
88 | cs->exception_index = EXCP_HALTED;
| ~~^
../semihosting/console.c:88:31: error: use of undeclared identifier 'EXCP_HALTED'
88 | cs->exception_index = EXCP_HALTED;
| ^Message-Id: <[email protected]>
--- include/semihosting/console.h | 2 -- semihosting/console.c | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-)
include/semihosting/console.h +0 -2
@@ -9,8 +9,6 @@#ifndef SEMIHOST_CONSOLE_H #define SEMIHOST_CONSOLE_H -#include "cpu.h" -/** * qemu_semihosting_console_read: * @cs: CPUState
semihosting/console.c +2 -1
@@ -18,14 +18,15 @@#include "qemu/osdep.h" #include "semihosting/semihost.h" #include "semihosting/console.h" +#include "exec/cpu-common.h" #include "exec/gdbstub.h" -#include "exec/exec-all.h" #include "qemu/log.h" #include "chardev/char.h" #include "chardev/char-fe.h" #include "qemu/main-loop.h" #include "qapi/error.h" #include "qemu/fifo8.h" +#include "hw/core/cpu.h" /* Access to this structure is protected by the BQL */ typedef struct SemihostingConsole {
Signature · 1 line
2.39.5
PATCH 7/22 semihosting/meson: Build config.o and console.o once
In reply to Alex BennéeFrom: Philippe Mathieu-Daudé <[email protected]>
config.c and console.c don't use any target specific headers anymore, move them from specific_ss[] to system_ss[] so they are built once, but will also be linked once, removing global symbol clash in a single QEMU binary.
Message-Id: <[email protected]>
--- semihosting/meson.build | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
semihosting/meson.build +6 -3
@@ -4,13 +4,16 @@ specific_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files( )) specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_SYSTEM_ONLY'], if_true: files( - 'config.c', - 'console.c', 'uaccess.c', )) common_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_SYSTEM_ONLY'], if_false: files('stubs-all.c')) -system_ss.add(when: ['CONFIG_SEMIHOSTING'], if_false: files('stubs-system.c')) +system_ss.add(when: ['CONFIG_SEMIHOSTING'], if_true: files( + 'config.c', + 'console.c', +), if_false: files( + 'stubs-system.c', +)) specific_ss.add(when: ['CONFIG_ARM_COMPATIBLE_SEMIHOSTING'], if_true: files('arm-compat-semi.c'))
Signature · 1 line
2.39.5
PATCH 8/22 system/vl: more error exit into config enumeration code
In reply to Alex BennéeAll of the failures to configure devices will result in QEMU exiting with an error code. In preparation for passing Error * down the chain re-name the iterator to foreach_device_config_or_exit and exit using &error_fatal instead of returning a failure indication.
--- system/vl.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
system/vl.c +16 -15
@@ -1307,7 +1307,14 @@ static void add_device_config(int type, const char *cmdline)QTAILQ_INSERT_TAIL (&device_configs, conf, next); } -static int foreach_device_config (int type,int (*func)(const char *cmdline)) +/** +* foreach_device_config_or_exit(): process per-device configs +* @type: device_config type +* @func: device specific config function, returning pass/fail +* +* Any failure is fatal and we exit with an error message. +*/ +static void foreach_device_config_or_exit (int type,int (*func)(const char *cmdline)) {struct device_config *conf;int rc;
@@ -1319,10 +1326,10 @@ static int foreach_device_config(int type, int (*func)(const char *cmdline)) rc =func (conf->cmdline);loc_pop (&conf->loc);if (rc) { -return rc; +error_setg (&error_fatal,"failed to configure: %s" , conf->cmdline); +exit (1 ); } } -return 0 ; }static void qemu_disable_default_devices (void )
@@ -2044,12 +2051,9 @@ static void qemu_create_late_backends(void)qemu_opts_foreach (qemu_find_opts ("mon" ), mon_init_func,NULL , &error_fatal); -if (foreach_device_config (DEV_SERIAL , serial_parse) <0 ) -exit (1 ); -if (foreach_device_config (DEV_PARALLEL , parallel_parse) <0 ) -exit (1 ); -if (foreach_device_config (DEV_DEBUGCON , debugcon_parse) <0 ) -exit (1 ); +foreach_device_config_or_exit (DEV_SERIAL , serial_parse); +foreach_device_config_or_exit (DEV_PARALLEL , parallel_parse); +foreach_device_config_or_exit (DEV_DEBUGCON , debugcon_parse);/* now chardevs have been created we may have semihosting to connect */ qemu_semihosting_chardev_init ();
@@ -2670,8 +2674,7 @@ static void qemu_create_cli_devices(void)/* init USB devices */ if (machine_usb (current_machine)) { -if (foreach_device_config (DEV_USB , usb_parse) <0 ) -exit (1 ); +foreach_device_config_or_exit (DEV_USB , usb_parse); }/* init generic devices */
@@ -2718,10 +2721,8 @@ static bool qemu_machine_creation_done(Error **errp)exit (1 ); } -if (foreach_device_config (DEV_GDB , gdbserver_start) <0 ) { -error_setg (errp,"could not start gdbserver" ); -return false; - } +foreach_device_config_or_exit (DEV_GDB , gdbserver_start); +if (!vga_interface_created && !default_vga && vga_interface_type !=VGA_NONE ) { warn_report("A -vga option was passed but this machine "
Signature · 1 line
2.39.5
Re: [PATCH 08/22] system/vl: more error exit into config enumeration code
Quoted 72 lines · Alex Bennée
All of the failures to configure devices will result in QEMU exiting with an error code. In preparation for passing Error * down the chain re-name the iterator to
foreach_device_config_or_exitand exit using&error_fatalinstead of returning a failure indication.Signed-off-by Alex Bennée <[email protected]>--- system/vl.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)system/vl.c +14
-11@@ -1307,7 +1307,14 @@ static void add_device_config(int type, const char *cmdline)QTAILQ_INSERT_TAIL (&device_configs, conf, next); } -static int foreach_device_config (int type,int (*func)(const char *cmdline)) +/** +* foreach_device_config_or_exit(): process per-device configs +* @type: device_config type +* @func: device specific config function, returning pass/fail +* +* Any failure is fatal and we exit with an error message. +*/ +static void foreach_device_config_or_exit (int type,int (*func)(const char *cmdline)) {struct device_config *conf;int rc;@@ -1319,10 +1326,10 @@ static int foreach_device_config(int type, int (*func)(const char *cmdline)) rc =func (conf->cmdline);loc_pop (&conf->loc);if (rc) { -return rc; +error_setg (&error_fatal,"failed to configure: %s" , conf->cmdline); +exit (1 ); } } -return 0 ; }static void qemu_disable_default_devices (void )@@ -2044,12 +2051,9 @@ static void qemu_create_late_backends(void)qemu_opts_foreach (qemu_find_opts ("mon" ), mon_init_func,NULL , &error_fatal); -if (foreach_device_config (DEV_SERIAL , serial_parse) <0 ) -exit (1 ); -if (foreach_device_config (DEV_PARALLEL , parallel_parse) <0 ) -exit (1 ); -if (foreach_device_config (DEV_DEBUGCON , debugcon_parse) <0 ) -exit (1 ); +foreach_device_config_or_exit (DEV_SERIAL , serial_parse); +foreach_device_config_or_exit (DEV_PARALLEL , parallel_parse); +foreach_device_config_or_exit (DEV_DEBUGCON , debugcon_parse);/* now chardevs have been created we may have semihosting to connect */ qemu_semihosting_chardev_init ();@@ -2670,8 +2674,7 @@ static void qemu_create_cli_devices(void)/* init USB devices */ if (machine_usb (current_machine)) { -if (foreach_device_config (DEV_USB , usb_parse) <0 ) -exit (1 ); +foreach_device_config_or_exit (DEV_USB , usb_parse); }/* init generic devices */ @@ -2718,10 +2721,8 @@ static bool qemu_machine_creation_done(Error **errp)exit (1 ); }
system/vl.c static bool qemu_machine_creation_done(Error **errp) · line 2728
Quoted 10 lines
system/vl.c +2
-4-if (foreach_device_config (DEV_GDB , gdbserver_start) <0 ) { -error_setg (errp,"could not start gdbserver" ); -return false; - } +foreach_device_config_or_exit (DEV_GDB , gdbserver_start); +if (!vga_interface_created && !default_vga && vga_interface_type !=VGA_NONE ) { warn_report("A -vga option was passed but this machine "
Re: [PATCH 08/22] system/vl: more error exit into config enumeration code
In reply to Alex BennéeQuoted 9 lines · Alex Bennée
All of the failures to configure devices will result in QEMU exiting with an error code. In preparation for passing Error * down the chain re-name the iterator to
foreach_device_config_or_exitand exit using&error_fatalinstead of returning a failure indication.Signed-off-by Alex Bennée <[email protected]>--- system/vl.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
Yay, simpler.
Re: [PATCH 08/22] system/vl: more error exit into config enumeration code
In reply to Alex BennéeQuoted 9 lines · Alex Bennée
All of the failures to configure devices will result in QEMU exiting with an error code. In preparation for passing Error * down the chain re-name the iterator to
foreach_device_config_or_exitand exit using&error_fatalinstead of returning a failure indication.Signed-off-by Alex Bennée<[email protected]>--- system/vl.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
r~
PATCH 9/22 system: squash usb_parse into a single function
In reply to Alex BennéeWe don't need to wrap usb_device_add as usb_parse is already gated with an if (machine_usb(current_machine)) check. Instead just assert and directly fail if usbdevice_create returns NULL.
--- system/vl.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-)
system/vl.c +4 -18
@@ -811,31 +811,17 @@ static void configure_msg(QemuOpts *opts)/***********************************************************/ /* USB devices */ -static int usb_device_add (const char *devname) +static int usb_parse (const char *cmdline) { -USBDevice *dev =NULL ; +g_assert (machine_usb (current_machine)); -if (!machine_usb (current_machine)) { +if (!usbdevice_create (cmdline)) { +error_report ("could not add USB device '%s'" , cmdline);return -1 ; } - - dev =usbdevice_create (devname); -if (!dev) -return -1 ; -return 0 ; } -static int usb_parse (const char *cmdline) -{ -int r; - r =usb_device_add (cmdline); -if (r <0 ) { -error_report ("could not add USB device '%s'" , cmdline); - } -return r; -} -/***********************************************************/ /* machine registration */
Signature · 1 line
2.39.5
Re: [PATCH 09/22] system: squash usb_parse into a single function
Quoted 8 lines · Alex Bennée
We don't need to wrap
usb_device_addasusb_parseis already gated with an if (machine_usb(current_machine)) check. Instead just assert and directly fail ifusbdevice_createreturns NULL.Signed-off-by Alex Bennée <[email protected]>--- system/vl.c | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-)
PATCH 10/22 system: propagate Error to gdbserver_start (and other device setups)
In reply to Alex BennéeThis started as a clean-up to properly pass a Error handler to the gdbserver_start so we could do the right thing for command line and HMP invocations.
Now that we have cleaned up foreach_device_config_or_exit() in earlier patches we can further simplify by it by passing &error_fatal instead of checking the return value. Having a return value is still useful for HMP though so tweak the return to use a simple bool instead.
---
v2
- split some work into pre-cursor patches
--- include/exec/gdbstub.h | 8 +++++- gdbstub/system.c | 22 ++++++++-------- gdbstub/user.c | 20 ++++++++------- linux-user/main.c | 6 +---- monitor/hmp-cmds.c | 2 +- system/vl.c | 58 ++++++++++++++++++++---------------------- 6 files changed, 59 insertions(+), 57 deletions(-)
include/exec/gdbstub.h +7 -1
@@ -49,12 +49,18 @@ void gdb_unregister_coprocessor_all(CPUState *cpu);/** * gdbserver_start: start the gdb server * @port_or_device: connection spec for gdb +* @errp: error handle * * For CONFIG_USER this is either a tcp port or a path to a fifo. For * system emulation you can use a full chardev spec for your gdbserver * port. +* +* The error handle should be either &error_fatal (for start-up) or +* &error_warn (for QMP/HMP initiated sessions). +* +* Returns true when server successfully started. */ -int gdbserver_start (const char *port_or_device); +bool gdbserver_start (const char *port_or_device,Error **errp);/** * gdb_feature_builder_init() - Initialize GDBFeatureBuilder.
gdbstub/system.c +12 -10
@@ -330,26 +330,27 @@ static void create_processes(GDBState *s)gdb_create_default_process (s); } -int gdbserver_start (const char *device) +bool gdbserver_start (const char *device,Error **errp) {Chardev *chr =NULL ;Chardev *mon_chr;g_autoptr (GString) cs =g_string_new (device);if (!first_cpu) { -error_report ("gdbstub: meaningless to attach gdb to a " -"machine without any CPU." ); -return -1 ; +error_setg (errp,"gdbstub: meaningless to attach gdb to a " +"machine without any CPU." ); +return false; }if (!gdb_supports_guest_debug ()) { -error_report ("gdbstub: current accelerator doesn't " -"support guest debugging" ); -return -1 ; +error_setg (errp,"gdbstub: current accelerator doesn't " +"support guest debugging" ); +return false; }if (cs->len ==0 ) { -return -1 ; +error_setg (errp,"gdbstub: missing connection string" ); +return false; }trace_gdbstub_op_start (cs->str);
@@ -374,7 +375,8 @@ int gdbserver_start(const char *device)*/ chr =qemu_chr_new_noreplay ("gdb" , cs->str, true,NULL );if (!chr) { -return -1 ; +error_setg (errp,"gdbstub: couldn't create chardev" ); +return false; } }
@@ -406,7 +408,7 @@ int gdbserver_start(const char *device) gdbserver_system_state.mon_chr = mon_chr;gdb_syscall_reset (); -return 0 ; +return true; }static void register_types (void )
gdbstub/user.c +11 -9
@@ -13,6 +13,7 @@#include "qemu/bitops.h" #include "qemu/cutils.h" #include "qemu/sockets.h" +#include "qapi/error.h" #include "exec/hwaddr.h" #include "exec/tb-flush.h" #include "exec/gdbstub.h"
@@ -372,15 +373,15 @@ static bool gdb_accept_tcp(int gdb_fd)return true; } -static int gdbserver_open_port (int port) +static int gdbserver_open_port (int port,Error **errp) {struct sockaddr_in sockaddr;int fd, ret; fd =socket (PF_INET ,SOCK_STREAM ,0 );if (fd <0 ) { -perror ("socket" ); -return -1 ; +error_setg (errp,"Failed to bind socket: %s" ,strerror (errno)); +return false; }qemu_set_cloexec (fd);
@@ -405,31 +406,32 @@ static int gdbserver_open_port(int port)return fd; } -int gdbserver_start (const char *port_or_path) +bool gdbserver_start (const char *port_or_path,Error **errp) {int port =g_ascii_strtoull (port_or_path,NULL ,10 );int gdb_fd;if (port >0 ) { - gdb_fd =gdbserver_open_port (port); + gdb_fd =gdbserver_open_port (port, errp); }else { gdb_fd =gdbserver_open_socket (port_or_path); }if (gdb_fd <0 ) { -return -1 ; +return false; }if (port >0 &&gdb_accept_tcp (gdb_fd)) { -return 0 ; +return true; }else if (gdb_accept_socket (gdb_fd)) { gdbserver_user_state.socket_path =g_strdup (port_or_path); -return 0 ; +return true; }/* gone wrong */ close (gdb_fd); -return -1 ; +error_setg (errp,"gdbstub: failed to accept connection" ); +return false; }void gdbserver_fork_start (void )
linux-user/main.c +1 -5
@@ -1023,11 +1023,7 @@ int main(int argc, char **argv, char **envp)target_cpu_copy_regs (env, regs);if (gdbstub) { -if (gdbserver_start (gdbstub) <0 ) { -fprintf (stderr,"qemu: could not open gdbserver on %s\n" , - gdbstub); -exit (EXIT_FAILURE ); - } +gdbserver_start (gdbstub, &error_fatal);gdb_handlesig (cpu,0 ,NULL ,NULL ,0 ); }
monitor/hmp-cmds.c +1 -1
@@ -285,7 +285,7 @@ void hmp_gdbserver(Monitor *mon, const QDict *qdict) device ="tcp::" DEFAULT_GDBSTUB_PORT ; } -if (gdbserver_start (device) <0 ) { +if (!gdbserver_start (device, &error_warn)) {monitor_printf (mon,"Could not open gdbserver on device '%s'\n" , device); }else if (strcmp (device,"none" ) ==0 ) {
system/vl.c +27 -31
129 lines not on this page · raw message
Signature · 1 line
2.39.5
Re: [PATCH 10/22] system: propagate Error to gdbserver_start (and other device setups)
Quoted 12 lines · Alex Bennée
This started as a clean-up to properly pass a Error handler to the
gdbserver_startso we could do the right thing for command line and HMP invocations.Now that we have cleaned up
foreach_device_config_or_exit()in earlier patches we can further simplify by it by passing&error_fatalinstead of checking the return value. Having a return value is still useful for HMP though so tweak the return to use a simple bool instead.Signed-off-by Alex Bennée <[email protected]>Acked-by Ilya Leoshkevich <[email protected]>
<snip>
gdbstub/user.c static bool gdb_accept_tcp(int gdb_fd) · line 376
Quoted 2 lines
gdbstub/user.c +1
-1-static int gdbserver_open_port (int port) +static int gdbserver_open_port (int port,Error **errp)
Did you mean:
static bool gdbserver_open_port...?
With that,
Re: [PATCH 10/22] system: propagate Error to gdbserver_start (and other device setups)
Quoted 13 lines · Pierrick Bouvier
Quoted 11 lines · Alex Bennée
This started as a clean-up to properly pass a Error handler to the
gdbserver_startso we could do the right thing for command line and HMP invocations.
Now that we have cleaned upforeach_device_config_or_exit()in earlier
patches we can further simplify by it by passing&error_fatalinstead of checking the return value. Having a return value is still useful for HMP though so tweak the return to use a simple bool instead.Signed-off-by Alex Bennée <[email protected]>Acked-by Ilya Leoshkevich <[email protected]>
Quoted 7 lines
<snip>
gdbstub/user.c static bool gdb_accept_tcp(int gdb_fd) · line 376
Quoted 2 lines
gdbstub/user.c +1
-1-static int gdbserver_open_port (int port) +static int gdbserver_open_port (int port,Error **errp)Did you mean:
static boolgdbserver_open_port...?
yes, yes I did. Will fix.
Quoted 3 lines
With that,
Reviewed-by Pierrick Bouvier <[email protected]>
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Re: [PATCH 10/22] system: propagate Error to gdbserver_start (and other device setups)
Quoted 17 lines · Alex Bennée
Quoted 15 lines · Pierrick Bouvier
Quoted 11 lines · Alex Bennée
This started as a clean-up to properly pass a Error handler to the
gdbserver_startso we could do the right thing for command line and HMP invocations.
Now that we have cleaned upforeach_device_config_or_exit()in earlier
patches we can further simplify by it by passing&error_fatalinstead of checking the return value. Having a return value is still useful for HMP though so tweak the return to use a simple bool instead.Signed-off-by Alex Bennée <[email protected]>Acked-by Ilya Leoshkevich <[email protected]><snip>
Quoted 7 lines
Quoted 5 lines
gdbstub/user.c static bool gdb_accept_tcp(int gdb_fd) · line 376
Quoted 2 lines
gdbstub/user.c +1
-1-static int gdbserver_open_port (int port) +static int gdbserver_open_port (int port,Error **errp)Did you mean:
static boolgdbserver_open_port...?yes, yes I did. Will fix.
This is returning a socket file descriptor, why bool?
Quoted 5 lines
Quoted 4 lines
With that,
Reviewed-by Pierrick Bouvier <[email protected]>
Re: [PATCH 10/22] system: propagate Error to gdbserver_start (and other device setups)
Quoted 18 lines · Philippe Mathieu-Daudé
Quoted 17 lines · Alex Bennée
Quoted 15 lines · Pierrick Bouvier
Quoted 11 lines · Alex Bennée
This started as a clean-up to properly pass a Error handler to the
gdbserver_startso we could do the right thing for command line and HMP invocations.
Now that we have cleaned upforeach_device_config_or_exit()in earlier
patches we can further simplify by it by passing&error_fatalinstead of checking the return value. Having a return value is still useful for HMP though so tweak the return to use a simple bool instead.Signed-off-by Alex Bennée <[email protected]>Acked-by Ilya Leoshkevich <[email protected]><snip>
Quoted 8 lines
Quoted 6 lines
Quoted 5 lines
gdbstub/user.c static bool gdb_accept_tcp(int gdb_fd) · line 376
Quoted 2 lines
gdbstub/user.c +1
-1-static int gdbserver_open_port (int port) +static int gdbserver_open_port (int port,Error **errp)Did you mean:
static boolgdbserver_open_port...?yes, yes I did. Will fix.
This is returning a socket file descriptor, why bool?
Doh - misread - I thought this was gdbserver_start... let me check.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
With that,
Reviewed-by Pierrick Bouvier <[email protected]>
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Re: [PATCH 10/22] system: propagate Error to gdbserver_start (and other device setups)
In reply to Philippe Mathieu-DaudéQuoted 24 lines · Philippe Mathieu-Daudé
Quoted 23 lines · Alex Bennée
Quoted 20 lines · Pierrick Bouvier
Quoted 11 lines · Alex Bennée
This started as a clean-up to properly pass a Error handler to the
gdbserver_startso we could do the right thing for command line and HMP invocations.
Now that we have cleaned upforeach_device_config_or_exit()in earlier
patches we can further simplify by it by passing&error_fatalinstead of checking the return value. Having a return value is still useful for HMP though so tweak the return to use a simple bool instead.Signed-off-by Alex Bennée <[email protected]>Acked-by Ilya Leoshkevich <[email protected]><snip>
gdbstub/user.c static bool gdb_accept_tcp(int gdb_fd) · line 376
Quoted 2 lines
gdbstub/user.c +1
-1-static int gdbserver_open_port (int port) +static int gdbserver_open_port (int port,Error **errp)Did you mean:
static boolgdbserver_open_port...?
Quoted 4 lines
Quoted 1 line
yes, yes I did. Will fix.
This is returning a socket file descriptor, why bool?
Oops, yes my comment was wrong.
We should return -1, as it was the case before.
Quoted 6 lines
Quoted 5 lines
Quoted 4 lines
With that,
Reviewed-by Pierrick Bouvier <[email protected]>
PATCH 11/22 tests/tcg/plugins/insn: remove unused callback parameter
In reply to Alex BennéeFrom: Pierrick Bouvier <[email protected]>
Message-Id: <[email protected]>
--- tests/tcg/plugins/insn.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
tests/tcg/plugins/insn.c +1 -3
@@ -150,10 +150,8 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu ( insn,QEMU_PLUGIN_INLINE_ADD_U64 , insn_count,1 ); }else { -uint64_t vaddr =qemu_plugin_insn_vaddr (insn);qemu_plugin_register_vcpu_insn_exec_cb ( - insn, vcpu_insn_exec_before,QEMU_PLUGIN_CB_NO_REGS , -GUINT_TO_POINTER (vaddr)); + insn, vcpu_insn_exec_before,QEMU_PLUGIN_CB_NO_REGS ,NULL ); }if (do_size) {
Signature · 1 line
2.39.5
PATCH 12/22 contrib/plugins/howvec: ensure we don't regress if this plugin is extended
In reply to Alex BennéeFrom: Pierrick Bouvier <[email protected]>
Message-Id: <[email protected]>
--- contrib/plugins/howvec.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
contrib/plugins/howvec.c +4 -3
@@ -253,6 +253,8 @@ static struct qemu_plugin_scoreboard *find_counter(int i;uint64_t *cnt =NULL ;uint32_t opcode =0 ; +/* if opcode is greater than 32 bits, we should refactor insn hash table. */ +G_STATIC_ASSERT (sizeof (opcode) ==sizeof (uint32_t ));InsnClassExecCount *class =NULL ;/*
@@ -284,7 +286,7 @@ static struct qemu_plugin_scoreboard *find_counter(g_mutex_lock (&lock); icount = (InsnExecCount *)g_hash_table_lookup (insns, -GUINT_TO_POINTER (opcode)); + (gpointer )(intptr_t ) opcode);if (!icount) { icount =g_new0 (InsnExecCount,1 );
@@ -295,8 +297,7 @@ static struct qemu_plugin_scoreboard *find_counter(qemu_plugin_scoreboard_new (sizeof (uint64_t )); icount->count =qemu_plugin_scoreboard_u64 (score); -g_hash_table_insert (insns,GUINT_TO_POINTER (opcode), - (gpointer ) icount); +g_hash_table_insert (insns, (gpointer )(intptr_t ) opcode, icount); }g_mutex_unlock (&lock);
Signature · 1 line
2.39.5
PATCH 13/22 tests/tcg/plugins/syscall: fix 32-bit build
In reply to Alex BennéeFrom: Pierrick Bouvier <[email protected]>
Message-Id: <[email protected]>
--- tests/tcg/plugins/syscall.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tests/tcg/plugins/syscall.c +3 -3
@@ -76,12 +76,12 @@ static int64_t write_sysno = -1;static SyscallStats *get_or_create_entry (int64_t num) {SyscallStats *entry = - (SyscallStats *)g_hash_table_lookup (statistics,GINT_TO_POINTER (num)); + (SyscallStats *)g_hash_table_lookup (statistics, &num);if (!entry) { entry =g_new0 (SyscallStats,1 ); entry->num = num; -g_hash_table_insert (statistics,GINT_TO_POINTER (num), (gpointer ) entry); +g_hash_table_insert (statistics, &entry->num, entry); }return entry;
@@ -232,7 +232,7 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, }if (!do_print) { - statistics =g_hash_table_new_full (NULL , g_direct_equal,NULL , g_free); + statistics =g_hash_table_new_full (g_int64_hash, g_int64_equal,NULL , g_free); }if (do_log_writes) {
Signature · 1 line
2.39.5
PATCH 14/22 tests/tcg/plugins/mem: fix 32-bit build
In reply to Alex BennéeFrom: Pierrick Bouvier <[email protected]>
Message-Id: <[email protected]>
--- tests/tcg/plugins/mem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tests/tcg/plugins/mem.c +3 -3
@@ -135,14 +135,14 @@ static void update_region_info(uint64_t region, uint64_t offset,g_assert (offset + size <= region_size);g_mutex_lock (&lock); - ri = (RegionInfo *)g_hash_table_lookup (regions,GUINT_TO_POINTER (region)); + ri = (RegionInfo *)g_hash_table_lookup (regions, ®ion);if (!ri) { ri =g_new0 (RegionInfo,1 ); ri->region_address = region; ri->data =g_malloc0 (region_size); ri->seen_all = true; -g_hash_table_insert (regions,GUINT_TO_POINTER (region), (gpointer ) ri); +g_hash_table_insert (regions, &ri->region_address, ri); }if (is_store) {
@@ -392,7 +392,7 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,if (do_region_summary) { region_mask = (region_size -1 ); - regions =g_hash_table_new (NULL , g_direct_equal); + regions =g_hash_table_new (g_int64_hash, g_int64_equal); } counts =qemu_plugin_scoreboard_new (sizeof (CPUCount));
Signature · 1 line
2.39.5
PATCH 15/22 contrib/plugins/stoptrigger: fix 32-bit build
In reply to Alex BennéeFrom: Pierrick Bouvier <[email protected]>
Message-Id: <[email protected]>
--- contrib/plugins/stoptrigger.c | 48 ++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 21 deletions(-)
contrib/plugins/stoptrigger.c +27 -21
@@ -21,9 +21,11 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;/* Scoreboard to track executed instructions count */ typedef struct {uint64_t insn_count; +uint64_t current_pc; }InstructionsCount ;static struct qemu_plugin_scoreboard *insn_count_sb;static qemu_plugin_u64 insn_count; +static qemu_plugin_u64 current_pc;static uint64_t icount;static int icount_exit_code;
@@ -34,6 +36,11 @@ static bool exit_on_address;/* Map trigger addresses to exit code */ static GHashTable *addrs_ht; +typedef struct { +uint64_t exit_addr; +int exit_code; +}ExitInfo ; +static void exit_emulation (int return_code,char *message) {qemu_plugin_outs (message);
@@ -43,23 +50,18 @@ static void exit_emulation(int return_code, char *message)static void exit_icount_reached (unsigned int cpu_index,void *udata) { -uint64_t insn_vaddr =GPOINTER_TO_UINT (udata); +uint64_t insn_vaddr =qemu_plugin_u64_get (current_pc, cpu_index);char *msg =g_strdup_printf ("icount reached at 0x%" PRIx64", exiting\n" , insn_vaddr); -exit_emulation (icount_exit_code, msg); }static void exit_address_reached (unsigned int cpu_index,void *udata) { -uint64_t insn_vaddr =GPOINTER_TO_UINT (udata); -char *msg =g_strdup_printf ("0x%" PRIx64" reached, exiting\n" , insn_vaddr); -int exit_code; - - exit_code =GPOINTER_TO_INT ( -g_hash_table_lookup (addrs_ht,GUINT_TO_POINTER (insn_vaddr))); - -exit_emulation (exit_code, msg); +ExitInfo *ei = udata; +g_assert (ei); +char *msg =g_strdup_printf ("0x%" PRIx64" reached, exiting\n" , ei->exit_addr); +exit_emulation (ei->exit_code, msg); }static void vcpu_tb_trans (qemu_plugin_id_t id,struct qemu_plugin_tb *tb)
@@ -67,23 +69,25 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)size_t tb_n =qemu_plugin_tb_n_insns (tb);for (size_t i =0 ; i < tb_n; i++) {struct qemu_plugin_insn *insn =qemu_plugin_tb_get_insn (tb, i); -gpointer insn_vaddr =GUINT_TO_POINTER (qemu_plugin_insn_vaddr (insn)); +uint64_t insn_vaddr =qemu_plugin_insn_vaddr (insn);if (exit_on_icount) {/* Increment and check scoreboard for each instruction */ qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu ( insn,QEMU_PLUGIN_INLINE_ADD_U64 , insn_count,1 ); +qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu ( + insn,QEMU_PLUGIN_INLINE_STORE_U64 , current_pc, insn_vaddr);qemu_plugin_register_vcpu_insn_exec_cond_cb ( insn, exit_icount_reached,QEMU_PLUGIN_CB_NO_REGS , -QEMU_PLUGIN_COND_EQ , insn_count, icount +1 , insn_vaddr); +QEMU_PLUGIN_COND_EQ , insn_count, icount +1 ,NULL ); }if (exit_on_address) { -if (g_hash_table_contains (addrs_ht, insn_vaddr)) { +ExitInfo *ei =g_hash_table_lookup (addrs_ht, &insn_vaddr); +if (ei) {/* Exit triggered by address */ qemu_plugin_register_vcpu_insn_exec_cb ( - insn, exit_address_reached,QEMU_PLUGIN_CB_NO_REGS , - insn_vaddr); + insn, exit_address_reached,QEMU_PLUGIN_CB_NO_REGS , ei); } } }
@@ -99,11 +103,13 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info, int argc, char **argv) { - addrs_ht =g_hash_table_new (NULL , g_direct_equal); + addrs_ht =g_hash_table_new_full (g_int64_hash, g_int64_equal,NULL , g_free); insn_count_sb =qemu_plugin_scoreboard_new (sizeof (InstructionsCount)); insn_count =qemu_plugin_scoreboard_u64_in_struct ( insn_count_sb, InstructionsCount, insn_count); + current_pc =qemu_plugin_scoreboard_u64_in_struct ( + insn_count_sb, InstructionsCount, current_pc);for (int i =0 ; i < argc; i++) {char *opt = argv[i];
@@ -124,13 +130,13 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, exit_on_icount = true; }else if (g_strcmp0 (tokens[0 ],"addr" ) ==0 ) {g_auto (GStrv) addr_tokens =g_strsplit (tokens[1 ],":" ,2 ); -uint64_t exit_addr =g_ascii_strtoull (addr_tokens[0 ],NULL ,0 ); -int exit_code =0 ; +ExitInfo *ei =g_malloc (sizeof (ExitInfo)); + ei->exit_addr =g_ascii_strtoull (addr_tokens[0 ],NULL ,0 ); + ei->exit_code =0 ;if (addr_tokens[1 ]) { - exit_code =g_ascii_strtoull (addr_tokens[1 ],NULL ,0 ); + ei->exit_code =g_ascii_strtoull (addr_tokens[1 ],NULL ,0 ); } -g_hash_table_insert (addrs_ht,GUINT_TO_POINTER (exit_addr), -GINT_TO_POINTER (exit_code)); +g_hash_table_insert (addrs_ht, &ei->exit_addr, ei); exit_on_address = true; }else {fprintf (stderr,"option parsing failed: %s\n" , opt);
Signature · 1 line
2.39.5
PATCH 16/22 contrib/plugins/cache: fix 32-bit build
In reply to Alex BennéeFrom: Pierrick Bouvier <[email protected]>
Message-Id: <[email protected]>
--- contrib/plugins/cache.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
contrib/plugins/cache.c +6 -12
@@ -208,7 +208,7 @@ static int fifo_get_first_block(Cache *cache, int set)static void fifo_update_on_miss (Cache *cache,int set,int blk_idx) {GQueue *q = cache->sets[set].fifo_queue; -g_queue_push_head (q,GINT_TO_POINTER (blk_idx)); +g_queue_push_head (q, (gpointer )(intptr_t ) blk_idx); }static void fifo_destroy (Cache *cache)
@@ -471,13 +471,8 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) n_insns =qemu_plugin_tb_n_insns (tb);for (i =0 ; i < n_insns; i++) {struct qemu_plugin_insn *insn =qemu_plugin_tb_get_insn (tb, i); -uint64_t effective_addr; - -if (sys) { - effective_addr = (uint64_t )qemu_plugin_insn_haddr (insn); - }else { - effective_addr = (uint64_t )qemu_plugin_insn_vaddr (insn); - } +uint64_t effective_addr = sys ? (uintptr_t )qemu_plugin_insn_haddr (insn) : +qemu_plugin_insn_vaddr (insn);/* * Instructions might get translated multiple times, we do not create
@@ -485,14 +480,13 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)* entry from the hash table and register it for the callback again. */ g_mutex_lock (&hashtable_lock); - data =g_hash_table_lookup (miss_ht,GUINT_TO_POINTER (effective_addr)); + data =g_hash_table_lookup (miss_ht, &effective_addr);if (data ==NULL ) { data =g_new0 (InsnData,1 ); data->disas_str =qemu_plugin_insn_disas (insn); data->symbol =qemu_plugin_insn_symbol (insn); data->addr = effective_addr; -g_hash_table_insert (miss_ht,GUINT_TO_POINTER (effective_addr), - (gpointer ) data); +g_hash_table_insert (miss_ht, &data->addr, data); }g_mutex_unlock (&hashtable_lock);
@@ -853,7 +847,7 @@ int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info,qemu_plugin_register_vcpu_tb_trans_cb (id, vcpu_tb_trans);qemu_plugin_register_atexit_cb (id, plugin_exit,NULL ); - miss_ht =g_hash_table_new_full (NULL , g_direct_equal,NULL , insn_free); + miss_ht =g_hash_table_new_full (g_int64_hash, g_int64_equal,NULL , insn_free);return 0 ; }
Signature · 1 line
2.39.5
PATCH 17/22 contrib/plugins/hotblocks: fix 32-bit build
In reply to Alex BennéeFrom: Pierrick Bouvier <[email protected]>
Message-Id: <[email protected]>
--- contrib/plugins/hotblocks.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-)
contrib/plugins/hotblocks.c +24 -5
@@ -29,7 +29,7 @@ static guint64 limit = 20;* * The internals of the TCG are not exposed to plugins so we can only * get the starting PC for each block. We cheat this slightly by -* xor'ing the number of instructions to the hash to help +* checking the number of instructions as well to help * differentiate. */ typedef struct {
@@ -50,6 +50,20 @@ static gint cmp_exec_count(gconstpointer a, gconstpointer b)return count_a > count_b ?-1 :1 ; } +static guint exec_count_hash (gconstpointer v) +{ +const ExecCount *e = v; +return e->start_addr ^ e->insns; +} + +static gboolean exec_count_equal (gconstpointer v1,gconstpointer v2) +{ +const ExecCount *ea = v1; +const ExecCount *eb = v2; +return (ea->start_addr == eb->start_addr) && + (ea->insns == eb->insns); +} +static void exec_count_free (gpointer key,gpointer value,gpointer user_data) {ExecCount *cnt = value;
@@ -91,7 +105,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)static void plugin_init (void ) { - hotblocks =g_hash_table_new (NULL , g_direct_equal); + hotblocks =g_hash_table_new (exec_count_hash, exec_count_equal); }static void vcpu_tb_exec (unsigned int cpu_index,void *udata)
@@ -111,10 +125,15 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)ExecCount *cnt;uint64_t pc =qemu_plugin_tb_vaddr (tb);size_t insns =qemu_plugin_tb_n_insns (tb); -uint64_t hash = pc ^ insns;g_mutex_lock (&lock); - cnt = (ExecCount *)g_hash_table_lookup (hotblocks, (gconstpointer ) hash); + { +ExecCount e; + e.start_addr = pc; + e.insns = insns; + cnt = (ExecCount *)g_hash_table_lookup (hotblocks, &e); + } +if (cnt) { cnt->trans_count++; }else {
@@ -123,7 +142,7 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) cnt->trans_count =1 ; cnt->insns = insns; cnt->exec_count =qemu_plugin_scoreboard_new (sizeof (uint64_t )); -g_hash_table_insert (hotblocks, (gpointer ) hash, (gpointer ) cnt); +g_hash_table_insert (hotblocks, cnt, cnt); }g_mutex_unlock (&lock);
Signature · 1 line
2.39.5
PATCH 18/22 contrib/plugins/cflow: fix 32-bit build
In reply to Alex BennéeFrom: Pierrick Bouvier <[email protected]>
Message-Id: <[email protected]>
--- contrib/plugins/cflow.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
contrib/plugins/cflow.c +11 -6
@@ -76,6 +76,8 @@ typedef struct {/* We use this to track the current execution state */ typedef struct { + /* address of current translated block */ + uint64_t tb_pc; /* address of end of block */ uint64_t end_block; /* next pc after end of block */
@@ -85,6 +87,7 @@ typedef struct { } VCPUScoreBoard;/* descriptors for accessing the above scoreboard */ +static qemu_plugin_u64 tb_pc;static qemu_plugin_u64 end_block;static qemu_plugin_u64 pc_after_block;static qemu_plugin_u64 last_pc;
@@ -189,10 +192,11 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)static void plugin_init (void ) {g_mutex_init (&node_lock); - nodes =g_hash_table_new (NULL , g_direct_equal); + nodes =g_hash_table_new (g_int64_hash, g_int64_equal); state =qemu_plugin_scoreboard_new (sizeof (VCPUScoreBoard));/* score board declarations */ + tb_pc =qemu_plugin_scoreboard_u64_in_struct (state, VCPUScoreBoard, tb_pc); end_block =qemu_plugin_scoreboard_u64_in_struct (state, VCPUScoreBoard, end_block); pc_after_block = qemu_plugin_scoreboard_u64_in_struct(state, VCPUScoreBoard,
@@ -215,10 +219,10 @@ static NodeData *fetch_node(uint64_t addr, bool create_if_not_found)NodeData *node =NULL ;g_mutex_lock (&node_lock); - node = (NodeData *)g_hash_table_lookup (nodes, (gconstpointer ) addr); + node = (NodeData *)g_hash_table_lookup (nodes, &addr);if (!node && create_if_not_found) { node =create_node (addr); -g_hash_table_insert (nodes, (gpointer ) addr, (gpointer ) node); +g_hash_table_insert (nodes, &node->addr, node); }g_mutex_unlock (&node_lock);return node;
@@ -234,7 +238,7 @@ static void vcpu_tb_branched_exec(unsigned int cpu_index, void *udata)uint64_t lpc =qemu_plugin_u64_get (last_pc, cpu_index);uint64_t ebpc =qemu_plugin_u64_get (end_block, cpu_index);uint64_t npc =qemu_plugin_u64_get (pc_after_block, cpu_index); -uint64_t pc =GPOINTER_TO_UINT (udata); +uint64_t pc =qemu_plugin_u64_get (tb_pc, cpu_index);/* return early for address 0 */ if (!lpc) {
@@ -305,10 +309,11 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)* handle both early block exits and normal branches in the * callback if we hit it. */ -gpointer udata =GUINT_TO_POINTER (pc); +qemu_plugin_register_vcpu_tb_exec_inline_per_vcpu ( + tb,QEMU_PLUGIN_INLINE_STORE_U64 , tb_pc, pc);qemu_plugin_register_vcpu_tb_exec_cond_cb ( tb, vcpu_tb_branched_exec,QEMU_PLUGIN_CB_NO_REGS , -QEMU_PLUGIN_COND_NE , pc_after_block, pc, udata); +QEMU_PLUGIN_COND_NE , pc_after_block, pc,NULL );/* * Now we can set start/end for this block so the next block can
Signature · 1 line
2.39.5
PATCH 19/22 contrib/plugins/hwprofile: fix 32-bit build
In reply to Alex BennéeFrom: Pierrick Bouvier <[email protected]>
Message-Id: <[email protected]>
--- contrib/plugins/hwprofile.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-)
contrib/plugins/hwprofile.c +16 -11
@@ -43,6 +43,8 @@ typedef struct {static GMutex lock;static GHashTable *devices; +static struct qemu_plugin_scoreboard *source_pc_scoreboard; +static qemu_plugin_u64 source_pc;/* track the access pattern to a piece of HW */ static bool pattern;
@@ -159,7 +161,7 @@ static DeviceCounts *new_count(const char *name, uint64_t base) count->name = name; count->base = base;if (pattern || source) { - count->detail =g_hash_table_new (NULL ,NULL ); + count->detail =g_hash_table_new (g_int64_hash, g_int64_equal); }g_hash_table_insert (devices, (gpointer ) name, count);return count;
@@ -169,7 +171,7 @@ static IOLocationCounts *new_location(GHashTable *table, uint64_t off_or_pc) {IOLocationCounts *loc =g_new0 (IOLocationCounts,1 ); loc->off_or_pc = off_or_pc; -g_hash_table_insert (table, (gpointer ) off_or_pc, loc); +g_hash_table_insert (table, &loc->off_or_pc, loc);return loc; }
@@ -224,12 +226,12 @@ static void vcpu_haddr(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo,/* either track offsets or source of access */ if (source) { - off = (uint64_t ) udata; + off =qemu_plugin_u64_get (source_pc, cpu_index); }if (pattern || source) {IOLocationCounts *io_count =g_hash_table_lookup (counts->detail, - (gpointer ) off); + &off);if (!io_count) { io_count =new_location (counts->detail, off); }
@@ -247,10 +249,14 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)for (i =0 ; i < n; i++) {struct qemu_plugin_insn *insn =qemu_plugin_tb_get_insn (tb, i); -gpointer udata = (gpointer) (source ?qemu_plugin_insn_vaddr (insn) :0 ); +if (source) { +uint64_t pc =qemu_plugin_insn_vaddr (insn); +qemu_plugin_register_vcpu_mem_inline_per_vcpu ( + insn, rw,QEMU_PLUGIN_INLINE_STORE_U64 , + source_pc, pc); + }qemu_plugin_register_vcpu_mem_cb (insn, vcpu_haddr, -QEMU_PLUGIN_CB_NO_REGS , - rw, udata); +QEMU_PLUGIN_CB_NO_REGS , rw,NULL ); } }
@@ -306,10 +312,9 @@ int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info,return -1 ; } -/* Just warn about overflow */ -if (info->system.smp_vcpus >64 || - info->system.max_vcpus >64 ) { -fprintf (stderr,"hwprofile: can only track up to 64 CPUs\n" ); +if (source) { + source_pc_scoreboard =qemu_plugin_scoreboard_new (sizeof (uint64_t )); + source_pc =qemu_plugin_scoreboard_u64 (source_pc_scoreboard); }plugin_init ();
Signature · 1 line
2.39.5
PATCH 20/22 contrib/plugins/hotpages: fix 32-bit build
In reply to Alex BennéeFrom: Pierrick Bouvier <[email protected]>
Message-Id: <[email protected]>
--- contrib/plugins/hotpages.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
contrib/plugins/hotpages.c +3 -3
@@ -103,7 +103,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)static void plugin_init (void ) { page_mask = (page_size -1 ); - pages =g_hash_table_new (NULL , g_direct_equal); + pages =g_hash_table_new (g_int64_hash, g_int64_equal); } static void vcpu_haddr(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo,
@@ -130,12 +130,12 @@ static void vcpu_haddr(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, page &= ~page_mask;g_mutex_lock (&lock); - count = (PageCounters *)g_hash_table_lookup (pages,GUINT_TO_POINTER (page)); + count = (PageCounters *)g_hash_table_lookup (pages, &page);if (!count) { count =g_new0 (PageCounters,1 ); count->page_address = page; -g_hash_table_insert (pages,GUINT_TO_POINTER (page), (gpointer ) count); +g_hash_table_insert (pages, &count->page_address, count); }if (qemu_plugin_mem_is_store (meminfo)) { count->writes++;
Signature · 1 line
2.39.5
PATCH 21/22 configure: reenable plugins by default for 32-bit hosts
In reply to Alex BennéeFrom: Pierrick Bouvier <[email protected]>
Message-Id: <[email protected]>
--- configure | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-)
configure +1 -20
@@ -528,25 +528,6 @@ case "$cpu" in ;; esac -# Now we have our CPU_CFLAGS we can check if we are targeting a 32 or -# 64 bit host. - -check_64bit_host() { -cat > $TMPC <<EOF -#if __SIZEOF_POINTER__ != 8 -#error not 64 bit system -#endif -int main(void) { return 0; } -EOF - compile_object "$1" -} - -if check_64bit_host "$CPU_CFLAGS"; then - host_bits=64 -else - host_bits=32 -fi - if test -n "$host_arch" && { ! test -d "$source_path/linux-user/include/host/$host_arch" || ! test -d "$source_path/common-user/host/$host_arch"; }; then
@@ -1072,7 +1053,7 @@ if test "$static" = "yes" ; then fi plugins="no" fi -if test "$plugins" != "no" && test $host_bits -eq 64; then +if test "$plugins" != "no"; then if has_meson_option "-Dtcg_interpreter=true"; then plugins="no" else
Signature · 1 line
2.39.5
PATCH 22/22 accel/tcg: also suppress asynchronous IRQs for cpu_io_recompile
In reply to Alex BennéeWhile it would be technically correct to allow an IRQ to happen (as the offending instruction never really completed) it messes up instrumentation. We already take care to only use memory instrumentation on the block, we should also suppress IRQs.
--- accel/tcg/translate-all.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
accel/tcg/translate-all.c +3 -2
@@ -633,9 +633,10 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr)* Exit the loop and potentially generate a new TB executing the * just the I/O insns. We also limit instrumentation to memory * operations only (which execute after completion) so we don't -* double instrument the instruction. +* double instrument the instruction. Also don't let an IRQ sneak +* in before we execute it. */ - cpu->cflags_next_tb =curr_cflags (cpu) |CF_MEMI_ONLY | n; + cpu->cflags_next_tb =curr_cflags (cpu) |CF_MEMI_ONLY |CF_NOIRQ | n;if (qemu_loglevel_mask (CPU_LOG_EXEC )) {vaddr pc = cpu->cc->get_pc (cpu);
Signature · 1 line
2.39.5
Re: [PATCH 22/22] accel/tcg: also suppress asynchronous IRQs for cpu_io_recompile
Quoted 19 lines · Alex Bennée
While it would be technically correct to allow an IRQ to happen (as the offending instruction never really completed) it messes up instrumentation. We already take care to only use memory instrumentation on the block, we should also suppress IRQs.
Signed-off-by Alex Bennée <[email protected]>Cc Richard Henderson <[email protected]>Cc Julian Ganz <[email protected]>--- accel/tcg/translate-all.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)accel/tcg/translate-all.c +0
-0@@ -633,9 +633,10 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr)* Exit the loop and potentially generate a new TB executing the * just the I/O insns. We also limit instrumentation to memory
accel/tcg/translate-all.c void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr) · line 642
Quoted 10 lines
accel/tcg/translate-all.c +3
-2* operations only (which execute after completion) so we don't -* double instrument the instruction. +* double instrument the instruction. Also don't let an IRQ sneak +* in before we execute it. */ - cpu->cflags_next_tb =curr_cflags (cpu) |CF_MEMI_ONLY | n; + cpu->cflags_next_tb =curr_cflags (cpu) |CF_MEMI_ONLY |CF_NOIRQ | n;if (qemu_loglevel_mask (CPU_LOG_EXEC )) {vaddr pc = cpu->cc->get_pc (cpu);
Thanks for the fix Alex, I confirm it solved the issue observed with discon plugin with aarch64 guest.
Re: [PATCH 22/22] accel/tcg: also suppress asynchronous IRQs for cpu_io_recompile
In reply to Alex BennéeQuoted 11 lines · Alex Bennée
While it would be technically correct to allow an IRQ to happen (as the offending instruction never really completed) it messes up instrumentation. We already take care to only use memory instrumentation on the block, we should also suppress IRQs.
Signed-off-by Alex Bennée <[email protected]>Cc Richard Henderson <[email protected]>Cc Julian Ganz <[email protected]>--- accel/tcg/translate-all.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
r~
Quoted 18 lines
accel/tcg/translate-all.c +3
-2@@ -633,9 +633,10 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr)* Exit the loop and potentially generate a new TB executing the * just the I/O insns. We also limit instrumentation to memory * operations only (which execute after completion) so we don't -* double instrument the instruction. +* double instrument the instruction. Also don't let an IRQ sneak +* in before we execute it. */ - cpu->cflags_next_tb =curr_cflags (cpu) |CF_MEMI_ONLY | n; + cpu->cflags_next_tb =curr_cflags (cpu) |CF_MEMI_ONLY |CF_NOIRQ | n;if (qemu_loglevel_mask (CPU_LOG_EXEC )) {vaddr pc = cpu->cc->get_pc (cpu);
Re: [PATCH 22/22] accel/tcg: also suppress asynchronous IRQs for cpu_io_recompile
In reply to Alex BennéeHi Alex,
Quoted 31 lines · Alex Bennée
While it would be technically correct to allow an IRQ to happen (as the offending instruction never really completed) it messes up instrumentation. We already take care to only use memory instrumentation on the block, we should also suppress IRQs.
Signed-off-by Alex Bennée <[email protected]>Cc Richard Henderson <[email protected]>Cc Julian Ganz <[email protected]>--- accel/tcg/translate-all.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)accel/tcg/translate-all.c +3
-2@@ -633,9 +633,10 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr)* Exit the loop and potentially generate a new TB executing the * just the I/O insns. We also limit instrumentation to memory * operations only (which execute after completion) so we don't -* double instrument the instruction. +* double instrument the instruction. Also don't let an IRQ sneak +* in before we execute it. */ - cpu->cflags_next_tb =curr_cflags (cpu) |CF_MEMI_ONLY | n; + cpu->cflags_next_tb =curr_cflags (cpu) |CF_MEMI_ONLY |CF_NOIRQ | n;if (qemu_loglevel_mask (CPU_LOG_EXEC )) {vaddr pc = cpu->cc->get_pc (cpu);Signature · 1 line
2.39.5