Skip to contentSkip to conversation

Final bits for 9.1-rc0 (docker, plugins, gdbstub, semihosting)

GIT PULL Alex Bennée 3 participants 22 messages Jul 22, 2024 – Sep 6, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

warn: No match for commit c135d5eaafe7aa2533da663d8e5a34a424b71eb9 found at https://gitlab.com/stsquad/qemu.git
warn: Are you sure you pushed 'pull-target-arm-20240711-209-gc135d5eaaf' there?
The following changes since commit a7ddb48bd1363c8bcdf42776d320289c42191f01:

Merge tag 'pull-aspeed-20240721' of https://github.com/legoater/qemu into staging (2024-07-22 07:52:05 +1000)

are available in the Git repository at:

https://gitlab.com/stsquad/qemu.git pull-target-arm-20240711-209-gc135d5eaaf

for you to fetch changes up to c135d5eaafe7aa2533da663d8e5a34a424b71eb9:

tests/tcg/aarch64: Fix test-mte.py (2024-07-22 09:38:17 +0100)

----------------------------------------------------------------
Alex Bennée (3):
testing: bump to latest libvirt-ci
gdbstub: Re-factor gdb command extensions tests/plugins: use qemu_plugin_outs for inline stats

Frédéric Pétrot (1):
plugins/execlog.c: correct dump of registers values

Philippe Mathieu-Daudé (8):
semihosting: Include missing 'gdbstub/syscalls.h' header target/m68k: Add semihosting stub
target/mips: Add semihosting stub
target/m68k: Restrict semihosting to TCG target/mips: Restrict semihosting to TCG target/riscv: Restrict semihosting to TCG target/xtensa: Restrict semihosting to TCG
semihosting: Restrict to TCG

Pierrick Bouvier (1):
plugins: fix mem callback array size

Richard Henderson (1):
tests/tcg/aarch64: Fix test-mte.py

Simon Hamelin (1):
plugins/stoptrigger: TCG plugin to stop execution under conditions

Thomas Huth (1):
tests/avocado: Remove non-working sparc leon3 test

 MAINTAINERS                               |   1 -
 docs/devel/tcg-plugins.rst                |  22 +++++
 include/gdbstub/commands.h                |  19 ++--
 include/semihosting/syscalls.h            |   2 +
 target/arm/internals.h                    |   4 +-
 accel/tcg/plugin-gen.c                    |   3 +-
 contrib/plugins/execlog.c                 |   2 +-
 contrib/plugins/stoptrigger.c             | 151 ++++++++++++++++++++++++++++++
 gdbstub/gdbstub.c                         | 141 ++++++++++++++++------------
 target/arm/gdbstub.c                      |  16 +---
 target/arm/gdbstub64.c                    |  11 +--
 target/m68k/semihosting-stub.c            |  15 +++
 target/mips/tcg/sysemu/semihosting-stub.c |  15 +++
 tests/plugin/inline.c                     |  58 +++++++-----
 .gitlab-ci.d/cirrus/freebsd-13.vars       |   2 +-
 contrib/plugins/Makefile                  |   1 +
 semihosting/Kconfig                       |   1 +
 target/m68k/Kconfig                       |   2 +-
 target/m68k/meson.build                   |   5 +-
 target/mips/Kconfig                       |   2 +-
 target/mips/tcg/sysemu/meson.build        |   6 +-
 target/riscv/Kconfig                      |   4 +-
 target/xtensa/Kconfig                     |   2 +-
 tests/avocado/machine_sparc_leon3.py      |  37 --------
 tests/lcitool/libvirt-ci                  |   2 +-
 tests/tcg/aarch64/gdbstub/test-mte.py     |   2 +-
 tests/vm/generated/freebsd.json           |  14 +--
 27 files changed, 370 insertions(+), 170 deletions(-)
 create mode 100644 contrib/plugins/stoptrigger.c
 create mode 100644 target/m68k/semihosting-stub.c
 create mode 100644 target/mips/tcg/sysemu/semihosting-stub.c
 delete mode 100644 tests/avocado/machine_sparc_leon3.py
Signature · 1 line
2.39.2
#1 lore raw

[PULL 03/16] gdbstub: Re-factor gdb command extensions

Coverity reported a memory leak (CID 1549757) in this code and its admittedly rather clumsy handling of extending the command table. Instead of handing over a full array of the commands lets use the lighter weight GPtrArray and simply test for the presence of each entry as we go. This avoids complications of transferring ownership of arrays and keeps the final command entries as static entries in the target code.

Cc Akihiko Odaki <[email protected]>
Cc Gustavo Bueno Romero <[email protected]>
Cc Peter Maydell <[email protected]>

Message-Id: <[email protected]>

include/gdbstub/commands.h +12 -7
index f3058f9dda..40f0514fe9 100644
@@ -74,23 +74,28 @@ int gdb_put_packet(const char *buf);
 
 /**
  * gdb_extend_query_table() - Extend query table.
- * @table: The table with the additional query packet handlers.
- * @size: The number of handlers to be added.
+ * @table: GPtrArray of GdbCmdParseEntry entries.
+ *
+ * The caller should free @table afterwards
  */
-void gdb_extend_query_table(GdbCmdParseEntry *table, int size);
+void gdb_extend_query_table(GPtrArray *table);
 
 /**
  * gdb_extend_set_table() - Extend set table.
- * @table: The table with the additional set packet handlers.
- * @size: The number of handlers to be added.
+ * @table: GPtrArray of GdbCmdParseEntry entries.
+ *
+ * The caller should free @table afterwards
  */
-void gdb_extend_set_table(GdbCmdParseEntry *table, int size);
+void gdb_extend_set_table(GPtrArray *table);
 
 /**
  * gdb_extend_qsupported_features() - Extend the qSupported features string.
  * @qsupported_features: The additional qSupported feature(s) string. The string
  * should start with a semicolon and, if there are more than one feature, the
- * features should be separate by a semiocolon.
+ * features should be separate by a semicolon.
+ *
+ * The caller should free @qsupported_features afterwards if
+ * dynamically allocated.
  */
 void gdb_extend_qsupported_features(char *qsupported_features);
 
target/arm/internals.h +2 -2
index da22d04121..757b1fae92 100644
@@ -359,8 +359,8 @@ void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu);
 void arm_translate_init(void);
 
 void arm_cpu_register_gdb_commands(ARMCPU *cpu);
-void aarch64_cpu_register_gdb_commands(ARMCPU *cpu, GString *, GArray *,
-                                       GArray *);
+void aarch64_cpu_register_gdb_commands(ARMCPU *cpu, GString *,
+                                       GPtrArray *, GPtrArray *);
 
 void arm_restore_state_to_opc(CPUState *cs,
                               const TranslationBlock *tb,
gdbstub/gdbstub.c +81 -60

218 lines not on this page · raw message

target/arm/gdbstub.c +5 -11
index c3a9b5eb1e..554b8736bb 100644
@@ -477,11 +477,9 @@ static GDBFeature *arm_gen_dynamic_m_secextreg_feature(CPUState *cs,
 
 void arm_cpu_register_gdb_commands(ARMCPU *cpu)
 {
-    GArray *query_table =
-        g_array_new(FALSE, FALSE, sizeof(GdbCmdParseEntry));
-    GArray *set_table =
-        g_array_new(FALSE, FALSE, sizeof(GdbCmdParseEntry));
-    GString *qsupported_features = g_string_new(NULL);
+    g_autoptr(GPtrArray) query_table = g_ptr_array_new();
+    g_autoptr(GPtrArray) set_table = g_ptr_array_new();
+    g_autoptr(GString) qsupported_features = g_string_new(NULL);
 
     if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) {
     #ifdef TARGET_AARCH64
@@ -492,16 +490,12 @@ void arm_cpu_register_gdb_commands(ARMCPU *cpu)
 
     /* Set arch-specific handlers for 'q' commands. */
     if (query_table->len) {
-        gdb_extend_query_table(&g_array_index(query_table,
-                                              GdbCmdParseEntry, 0),
-                                              query_table->len);
+        gdb_extend_query_table(query_table);
     }
 
     /* Set arch-specific handlers for 'Q' commands. */
     if (set_table->len) {
-        gdb_extend_set_table(&g_array_index(set_table,
-                             GdbCmdParseEntry, 0),
-                             set_table->len);
+        gdb_extend_set_table(set_table);
     }
 
     /* Set arch-specific qSupported feature. */
target/arm/gdbstub64.c +5 -6
index 2e2bc2700b..c8cef8cbc0 100644
@@ -564,7 +564,7 @@ enum Command {
     NUM_CMDS
 };
 
-static GdbCmdParseEntry cmd_handler_table[NUM_CMDS] = {
+static const GdbCmdParseEntry cmd_handler_table[NUM_CMDS] = {
     [qMemTags] = {
         .handler = handle_q_memtag,
         .cmd_startswith = true,
@@ -590,17 +590,16 @@ static GdbCmdParseEntry cmd_handler_table[NUM_CMDS] = {
 #endif /* CONFIG_USER_ONLY */
 
 void aarch64_cpu_register_gdb_commands(ARMCPU *cpu, GString *qsupported,
-                                       GArray *qtable, GArray *stable)
+                                       GPtrArray *qtable, GPtrArray *stable)
 {
 #ifdef CONFIG_USER_ONLY
     /* MTE */
     if (cpu_isar_feature(aa64_mte, cpu)) {
         g_string_append(qsupported, ";memory-tagging+");
 
-        g_array_append_val(qtable, cmd_handler_table[qMemTags]);
-        g_array_append_val(qtable, cmd_handler_table[qIsAddressTagged]);
-
-        g_array_append_val(stable, cmd_handler_table[QMemTags]);
+        g_ptr_array_add(qtable, (gpointer) &cmd_handler_table[qMemTags]);
+        g_ptr_array_add(qtable, (gpointer) &cmd_handler_table[qIsAddressTagged]);
+        g_ptr_array_add(stable, (gpointer) &cmd_handler_table[QMemTags]);
     }
 #endif
 }
Signature · 1 line
2.39.2
#2 lore raw

[PULL 16/16] tests/tcg/aarch64: Fix test-mte.py

In reply to Alex Bennée

From: Richard Henderson <[email protected]>

Python 3.12 warns:

TEST gdbstub MTE support on aarch64
/home/rth/qemu/src/tests/tcg/aarch64/gdbstub/test-mte.py:21: SyntaxWarning: invalid escape sequence '\('
PATTERN_0 = "Memory tags for address 0x[0-9a-f]+ match \(0x[0-9a-f]+\)."

Double up the \ to pass one through to the pattern.

Message-Id: <[email protected]>

tests/tcg/aarch64/gdbstub/test-mte.py +1 -1
index 2db0663c1a..66f9c25f8a 100644
@@ -18,7 +18,7 @@
 from test_gdbstub import main, report
 
 
-PATTERN_0 = "Memory tags for address 0x[0-9a-f]+ match \(0x[0-9a-f]+\)."
+PATTERN_0 = "Memory tags for address 0x[0-9a-f]+ match \\(0x[0-9a-f]+\\)."
 PATTERN_1 = ".*(0x[0-9a-f]+)"
 
 
Signature · 1 line
2.39.2
#3 lore raw

[PULL 01/16] testing: bump to latest libvirt-ci

In reply to Alex Bennée

This brings in the latest python mappings for the BSD updates.

Message-Id: <[email protected]>

.gitlab-ci.d/cirrus/freebsd-13.vars +1 -1
index 3785afca36..29ab9645f9 100644
@@ -11,6 +11,6 @@ MAKE='/usr/local/bin/gmake'
 NINJA='/usr/local/bin/ninja'
 PACKAGING_COMMAND='pkg'
 PIP3='/usr/local/bin/pip-3.8'
-PKGS='alsa-lib bash bison bzip2 ca_root_nss capstone4 ccache cmocka ctags curl cyrus-sasl dbus diffutils dtc flex fusefs-libs3 gettext git glib gmake gnutls gsed gtk3 json-c libepoxy libffi libgcrypt libjpeg-turbo libnfs libslirp libspice-server libssh libtasn1 llvm lzo2 meson mtools ncurses nettle ninja opencv pixman pkgconf png py39-numpy py39-pillow py39-pip py39-sphinx py39-sphinx_rtd_theme py39-tomli py39-yaml python3 rpm2cpio sdl2 sdl2_image snappy sndio socat spice-protocol tesseract usbredir virglrenderer vte3 xorriso zstd'
+PKGS='alsa-lib bash bison bzip2 ca_root_nss capstone4 ccache cmocka ctags curl cyrus-sasl dbus diffutils dtc flex fusefs-libs3 gettext git glib gmake gnutls gsed gtk3 json-c libepoxy libffi libgcrypt libjpeg-turbo libnfs libslirp libspice-server libssh libtasn1 llvm lzo2 meson mtools ncurses nettle ninja opencv pixman pkgconf png py311-numpy py311-pillow py311-pip py311-sphinx py311-sphinx_rtd_theme py311-tomli py311-yaml python3 rpm2cpio sdl2 sdl2_image snappy sndio socat spice-protocol tesseract usbredir virglrenderer vte3 xorriso zstd'
 PYPI_PKGS=''
 PYTHON='/usr/local/bin/python3'
tests/lcitool/libvirt-ci +1 -1
index 0e9490cebc..789b4601bc 160000
@@ -1 +1 @@
-Subproject commit 0e9490cebc726ef772b6c9e27dac32e7ae99f9b2
+Subproject commit 789b4601bce4e01f43fdb6ad4ce5ab4e46674440
tests/vm/generated/freebsd.json +7 -7
index 2d5895ebed..2a361cecd0 100644
@@ -51,13 +51,13 @@
     "pixman",
     "pkgconf",
     "png",
-    "py39-numpy",
-    "py39-pillow",
-    "py39-pip",
-    "py39-sphinx",
-    "py39-sphinx_rtd_theme",
-    "py39-tomli",
-    "py39-yaml",
+    "py311-numpy",
+    "py311-pillow",
+    "py311-pip",
+    "py311-sphinx",
+    "py311-sphinx_rtd_theme",
+    "py311-tomli",
+    "py311-yaml",
     "python3",
     "rpm2cpio",
     "sdl2",
Signature · 1 line
2.39.2
#4 lore raw

[PULL 07/16] plugins/execlog.c: correct dump of registers values

In reply to Alex Bennée

From: Frédéric Pétrot <[email protected]>

Register values are dumped as 'sz' chunks of two nibbles in the execlog plugin, sz was 1 too big.

Message-Id: <[email protected]>

Message-Id: <[email protected]>

contrib/plugins/execlog.c +1 -1
index 371db97eb1..1c1601cc0b 100644
@@ -101,7 +101,7 @@ static void insn_check_regs(CPU *cpu)
             GByteArray *temp = reg->last;
             g_string_append_printf(cpu->last_exec, ", %s -> 0x", reg->name);
             /* TODO: handle BE properly */
-            for (int i = sz; i >= 0; i--) {
+            for (int i = sz - 1; i >= 0; i--) {
                 g_string_append_printf(cpu->last_exec, "%02x",
                                        reg->new->data[i]);
             }
Signature · 1 line
2.39.2
#5 lore raw

[PULL 09/16] target/m68k: Add semihosting stub

In reply to Alex Bennée

From: Philippe Mathieu-Daudé <[email protected]>

Since the SEMIHOSTING feature is optional, we need a stub to link when it is disabled.

Message-Id: <[email protected]>

Message-Id: <[email protected]>

target/m68k/semihosting-stub.c new file +15 -0
new file mode 100644
index 0000000000..d6a5965e29
@@ -0,0 +1,15 @@
+/*
+ *  m68k/ColdFire semihosting stub
+ *
+ * SPDX-FileContributor: Philippe Mathieu-Daudé <[email protected]>
+ * SPDX-FileCopyrightText: 2024 Linaro Ltd.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "cpu.h"
+
+void do_m68k_semihosting(CPUM68KState *env, int nr)
+{
+    g_assert_not_reached();
+}
target/m68k/meson.build +4 -1
index 8d3f9ce288..4d213daaf6 100644
@@ -11,9 +11,12 @@ m68k_ss.add(files(
 
 m68k_system_ss = ss.source_set()
 m68k_system_ss.add(files(
-  'm68k-semi.c',
   'monitor.c'
 ))
+m68k_system_ss.add(when: ['CONFIG_SEMIHOSTING'],
+  if_true: files('m68k-semi.c'),
+  if_false: files('semihosting-stub.c')
+)
 
 target_arch += {'m68k': m68k_ss}
 target_system_arch += {'m68k': m68k_system_ss}
Signature · 1 line
2.39.2
#6 lore raw

[PULL 04/16] plugins/stoptrigger: TCG plugin to stop execution under conditions

In reply to Alex Bennée

From: Simon Hamelin <[email protected]>

This new plugin allows to stop emulation using conditions on the emulation state. By setting this plugin arguments, it is possible to set an instruction count limit and/or trigger address(es) to stop at. The code returned at emulation exit can be customized.

This plugin demonstrates how someone could stop QEMU execution. It could be used for research purposes to launch some code and deterministically stop it and understand where its execution flow went.

Message-Id: <[email protected]>

Message-Id: <[email protected]>

docs/devel/tcg-plugins.rst +22 -0
index f7d7b9e3a4..954623f9bf 100644
@@ -642,6 +642,28 @@ The plugin has a number of arguments, all of them are optional:
   configuration arguments implies ``l2=on``.
   (default: N = 2097152 (2MB), B = 64, A = 16)
 
+- contrib/plugins/stoptrigger.c
+
+The stoptrigger plugin allows to setup triggers to stop emulation.
+It can be used for research purposes to launch some code and precisely stop it
+and understand where its execution flow went.
+
+Two types of triggers can be configured: a count of instructions to stop at,
+or an address to stop at. Multiple triggers can be set at once.
+
+By default, QEMU will exit with return code 0. A custom return code can be
+configured for each trigger using ``:CODE`` syntax.
+
+For example, to stop at the 20-th instruction with return code 41, at address
+0xd4 with return code 0 or at address 0xd8 with return code 42::
+
+  $ qemu-system-aarch64 $(QEMU_ARGS) \
+    -plugin ./contrib/plugins/libstoptrigger.so,icount=20:41,addr=0xd4,addr=0xd8:42 -d plugin
+
+The plugin will log the reason of exit, for example::
+
+  0xd4 reached, exiting
+
 Plugin API
 ==========
 
contrib/plugins/stoptrigger.c new file +151 -0

151 lines not on this page · raw message

contrib/plugins/Makefile +1 -0
index 449ead1130..98a89d5c40 100644
@@ -28,6 +28,7 @@ NAMES += hwprofile
 NAMES += cache
 NAMES += drcov
 NAMES += ips
+NAMES += stoptrigger
 
 ifeq ($(CONFIG_WIN32),y)
 SO_SUFFIX := .dll
Signature · 1 line
2.39.2
#7 lore raw

[PULL 05/16] plugins: fix mem callback array size

In reply to Alex Bennée

From: Pierrick Bouvier <[email protected]>

data was correctly copied, but size of array was not set (g_array_sized_new only reserves memory, but does not set size).

As a result, callbacks were not called for code path relying on plugin_register_vcpu_mem_cb().

Found when trying to trigger mem access callbacks for atomic instructions.

Message-Id: <[email protected]>
Message-Id: <[email protected]>

accel/tcg/plugin-gen.c +1 -2
index b6bae32b99..ec89a085b4 100644
@@ -85,8 +85,7 @@ static void gen_enable_mem_helper(struct qemu_plugin_tb *ptb,
     len = insn->mem_cbs->len;
     arr = g_array_sized_new(false, false,
                             sizeof(struct qemu_plugin_dyn_cb), len);
-    memcpy(arr->data, insn->mem_cbs->data,
-           len * sizeof(struct qemu_plugin_dyn_cb));
+    g_array_append_vals(arr, insn->mem_cbs->data, len);
     qemu_plugin_add_dyn_cb_arr(arr);
 
     tcg_gen_st_ptr(tcg_constant_ptr((intptr_t)arr), tcg_env,
Signature · 1 line
2.39.2
#8 lore raw

[PULL 02/16] tests/avocado: Remove non-working sparc leon3 test

In reply to Alex Bennée

From: Thomas Huth <[email protected]>

The test has been marked as broken more than 4 years ago, and so far nobody ever cared to fix it. Thus let's simply remove it now ... if somebody ever needs it again, they can restore the file from an older version of QEMU.

Message-Id: <[email protected]>

[AJB: fix MAINTAINERS]

Message-Id: <[email protected]>

MAINTAINERS +0 -1
index 7d9811458c..d5ff6c2498 100644
@@ -1727,7 +1727,6 @@ S: Maintained
 F: hw/sparc/leon3.c
 F: hw/*/grlib*
 F: include/hw/*/grlib*
-F: tests/avocado/machine_sparc_leon3.py
 
 S390 Machines
 -------------
tests/avocado/machine_sparc_leon3.py deleted +0 -37
deleted file mode 100644
index e61b223185..0000000000
@@ -1,37 +0,0 @@
-# Functional test that boots a Leon3 machine and checks its serial console.
-#
-# Copyright (c) Philippe Mathieu-Daudé <[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.
-
-from avocado_qemu import QemuSystemTest
-from avocado_qemu import wait_for_console_pattern
-from avocado import skip
-
-
-class Leon3Machine(QemuSystemTest):
-
-    timeout = 60
-
-    @skip("Test currently broken")
-    # A Window Underflow exception occurs before booting the kernel,
-    # and QEMU exit calling cpu_abort(), which makes this test to fail.
-    def test_leon3_helenos_uimage(self):
-        """
-        :avocado: tags=arch:sparc
-        :avocado: tags=machine:leon3_generic
-        :avocado: tags=binfmt:uimage
-        """
-        kernel_url = ('http://www.helenos.org/releases/'
-                      'HelenOS-0.6.0-sparc32-leon3.bin')
-        kernel_hash = 'a88c9cfdb8430c66650e5290a08765f9bf049a30'
-        kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash)
-
-        self.vm.set_console()
-        self.vm.add_args('-kernel', kernel_path)
-
-        self.vm.launch()
-
-        wait_for_console_pattern(self, 'Copyright (c) 2001-2014 HelenOS project')
-        wait_for_console_pattern(self, 'Booting the kernel ...')
Signature · 1 line
2.39.2
#9 lore raw

[PULL 11/16] target/m68k: Restrict semihosting to TCG

In reply to Alex Bennée

From: Philippe Mathieu-Daudé <[email protected]>

The semihosting feature depends on TCG (due to the probe_access API access). Although TCG is the single accelerator currently available for the m68k target, use the Kconfig "imply" directive which is more correct (if we were to support a different accel).

Message-Id: <[email protected]>

Message-Id: <[email protected]>

target/m68k/Kconfig +1 -1
index 9eae71486f..23aae24ebe 100644
@@ -1,3 +1,3 @@
 config M68K
     bool
-    select SEMIHOSTING
+    imply SEMIHOSTING if TCG
Signature · 1 line
2.39.2
#10 lore raw

[PULL 08/16] semihosting: Include missing 'gdbstub/syscalls.h' header

In reply to Alex Bennée

From: Philippe Mathieu-Daudé <[email protected]>

"semihosting/syscalls.h" requires definitions from "gdbstub/syscalls.h", include it in order to avoid:

include/semihosting/syscalls.h:23:38: error: unknown type name 'gdb_syscall_complete_cb' void semihost_sys_open(CPUState *cs, gdb_syscall_complete_cb complete,

                                       ^

Message-Id: <[email protected]>

Message-Id: <[email protected]>

include/semihosting/syscalls.h +2 -0
index 3a5ec229eb..b5937c619a 100644
@@ -9,6 +9,8 @@
 #ifndef SEMIHOSTING_SYSCALLS_H
 #define SEMIHOSTING_SYSCALLS_H
 
+#include "gdbstub/syscalls.h"
+
 /*
  * Argument loading from the guest is performed by the caller;
  * results are returned via the 'complete' callback.
Signature · 1 line
2.39.2
#11 lore raw

[PULL 06/16] tests/plugins: use qemu_plugin_outs for inline stats

In reply to Alex Bennée

Using bare printf's in plugins is perfectly acceptable but they do rather mess up the output of "make check-tcg". Convert the printfs to use g_string and then output with the plugin output helper which will already be captured to .pout files by the test harness.

Message-Id: <[email protected]>

tests/plugin/inline.c +33 -25
index cd63827b7d..73dde99578 100644
@@ -71,10 +71,12 @@ static void stats_insn(void)
     const uint64_t cond_track_left = qemu_plugin_u64_sum(insn_cond_track_count);
     const uint64_t conditional =
         cond_num_trigger * cond_trigger_limit + cond_track_left;
-    printf("insn: %" PRIu64 "\n", expected);
-    printf("insn: %" PRIu64 " (per vcpu)\n", per_vcpu);
-    printf("insn: %" PRIu64 " (per vcpu inline)\n", inl_per_vcpu);
-    printf("insn: %" PRIu64 " (cond cb)\n", conditional);
+    g_autoptr(GString) stats = g_string_new("");
+    g_string_append_printf(stats, "insn: %" PRIu64 "\n", expected);
+    g_string_append_printf(stats, "insn: %" PRIu64 " (per vcpu)\n", per_vcpu);
+    g_string_append_printf(stats, "insn: %" PRIu64 " (per vcpu inline)\n", inl_per_vcpu);
+    g_string_append_printf(stats, "insn: %" PRIu64 " (cond cb)\n", conditional);
+    qemu_plugin_outs(stats->str);
     g_assert(expected > 0);
     g_assert(per_vcpu == expected);
     g_assert(inl_per_vcpu == expected);
@@ -91,10 +93,12 @@ static void stats_tb(void)
     const uint64_t cond_track_left = qemu_plugin_u64_sum(tb_cond_track_count);
     const uint64_t conditional =
         cond_num_trigger * cond_trigger_limit + cond_track_left;
-    printf("tb: %" PRIu64 "\n", expected);
-    printf("tb: %" PRIu64 " (per vcpu)\n", per_vcpu);
-    printf("tb: %" PRIu64 " (per vcpu inline)\n", inl_per_vcpu);
-    printf("tb: %" PRIu64 " (conditional cb)\n", conditional);
+    g_autoptr(GString) stats = g_string_new("");
+    g_string_append_printf(stats, "tb: %" PRIu64 "\n", expected);
+    g_string_append_printf(stats, "tb: %" PRIu64 " (per vcpu)\n", per_vcpu);
+    g_string_append_printf(stats, "tb: %" PRIu64 " (per vcpu inline)\n", inl_per_vcpu);
+    g_string_append_printf(stats, "tb: %" PRIu64 " (conditional cb)\n", conditional);
+    qemu_plugin_outs(stats->str);
     g_assert(expected > 0);
     g_assert(per_vcpu == expected);
     g_assert(inl_per_vcpu == expected);
@@ -107,9 +111,11 @@ static void stats_mem(void)
     const uint64_t per_vcpu = qemu_plugin_u64_sum(count_mem);
     const uint64_t inl_per_vcpu =
         qemu_plugin_u64_sum(count_mem_inline);
-    printf("mem: %" PRIu64 "\n", expected);
-    printf("mem: %" PRIu64 " (per vcpu)\n", per_vcpu);
-    printf("mem: %" PRIu64 " (per vcpu inline)\n", inl_per_vcpu);
+    g_autoptr(GString) stats = g_string_new("");
+    g_string_append_printf(stats, "mem: %" PRIu64 "\n", expected);
+    g_string_append_printf(stats, "mem: %" PRIu64 " (per vcpu)\n", per_vcpu);
+    g_string_append_printf(stats, "mem: %" PRIu64 " (per vcpu inline)\n", inl_per_vcpu);
+    qemu_plugin_outs(stats->str);
     g_assert(expected > 0);
     g_assert(per_vcpu == expected);
     g_assert(inl_per_vcpu == expected);
@@ -118,6 +124,7 @@ static void stats_mem(void)
 static void plugin_exit(qemu_plugin_id_t id, void *udata)
 {
     const unsigned int num_cpus = qemu_plugin_num_vcpus();
+    g_autoptr(GString) stats = g_string_new("");
     g_assert(num_cpus == max_cpu_index + 1);
 
     for (int i = 0; i < num_cpus ; ++i) {
@@ -135,20 +142,21 @@ static void plugin_exit(qemu_plugin_id_t id, void *udata)
             qemu_plugin_u64_get(insn_cond_num_trigger, i);
         const uint64_t insn_cond_left =
             qemu_plugin_u64_get(insn_cond_track_count, i);
-        printf("cpu %d: tb (%" PRIu64 ", %" PRIu64
-               ", %" PRIu64 " * %" PRIu64 " + %" PRIu64
-               ") | "
-               "insn (%" PRIu64 ", %" PRIu64
-               ", %" PRIu64 " * %" PRIu64 " + %" PRIu64
-               ") | "
-               "mem (%" PRIu64 ", %" PRIu64 ")"
-               "\n",
-               i,
-               tb, tb_inline,
-               tb_cond_trigger, cond_trigger_limit, tb_cond_left,
-               insn, insn_inline,
-               insn_cond_trigger, cond_trigger_limit, insn_cond_left,
-               mem, mem_inline);
+        g_string_printf(stats, "cpu %d: tb (%" PRIu64 ", %" PRIu64
+                        ", %" PRIu64 " * %" PRIu64 " + %" PRIu64
+                        ") | "
+                        "insn (%" PRIu64 ", %" PRIu64
+                        ", %" PRIu64 " * %" PRIu64 " + %" PRIu64
+                        ") | "
+                        "mem (%" PRIu64 ", %" PRIu64 ")"
+                        "\n",
+                        i,
+                        tb, tb_inline,
+                        tb_cond_trigger, cond_trigger_limit, tb_cond_left,
+                        insn, insn_inline,
+                        insn_cond_trigger, cond_trigger_limit, insn_cond_left,
+                        mem, mem_inline);
+        qemu_plugin_outs(stats->str);
         g_assert(tb == tb_inline);
         g_assert(insn == insn_inline);
         g_assert(mem == mem_inline);
Signature · 1 line
2.39.2
#12 lore raw

[PULL 10/16] target/mips: Add semihosting stub

In reply to Alex Bennée

From: Philippe Mathieu-Daudé <[email protected]>

Since the SEMIHOSTING feature is optional, we need a stub to link when it is disabled.

Message-Id: <[email protected]>

Message-Id: <[email protected]>

target/mips/tcg/sysemu/semihosting-stub.c new file +15 -0
new file mode 100644
index 0000000000..7ae27d746f
@@ -0,0 +1,15 @@
+/*
+ *  MIPS semihosting stub
+ *
+ * SPDX-FileContributor: Philippe Mathieu-Daudé <[email protected]>
+ * SPDX-FileCopyrightText: 2024 Linaro Ltd.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "internal.h"
+
+void mips_semihosting(CPUMIPSState *env)
+{
+    g_assert_not_reached();
+}
target/mips/tcg/sysemu/meson.build +4 -2
index ec665a4b1e..911341ac37 100644
@@ -1,10 +1,12 @@
 mips_system_ss.add(files(
   'cp0_helper.c',
-  'mips-semi.c',
   'special_helper.c',
   'tlb_helper.c',
 ))
-
+mips_system_ss.add(when: ['CONFIG_SEMIHOSTING'],
+  if_true: files('mips-semi.c'),
+  if_false: files('semihosting-stub.c')
+)
 mips_system_ss.add(when: 'TARGET_MIPS64', if_true: files(
   'lcsr_helper.c',
 ))
Signature · 1 line
2.39.2
#13 lore raw

[PULL 15/16] semihosting: Restrict to TCG

In reply to Alex Bennée

From: Philippe Mathieu-Daudé <[email protected]>

Semihosting currently uses the TCG probe_access API. It is pointless to have it in the binary when TCG isn't.

Message-Id: <[email protected]>

Message-Id: <[email protected]>

semihosting/Kconfig +1 -0
index eaf3a20ef5..fbe6ac87f9 100644
@@ -1,6 +1,7 @@
 
 config SEMIHOSTING
        bool
+       depends on TCG
 
 config ARM_COMPATIBLE_SEMIHOSTING
        bool
Signature · 1 line
2.39.2
#14 lore raw

[PULL 12/16] target/mips: Restrict semihosting to TCG

In reply to Alex Bennée

From: Philippe Mathieu-Daudé <[email protected]>

Semihosting currently uses the TCG probe_access API. To prepare for encoding the TCG dependency in Kconfig, do not enable it unless TCG is available.

Message-Id: <[email protected]>

Message-Id: <[email protected]>

target/mips/Kconfig +1 -1
index eb19c94c7d..876048b150 100644
@@ -1,6 +1,6 @@
 config MIPS
     bool
-    select SEMIHOSTING
+    imply SEMIHOSTING if TCG
 
 config MIPS64
     bool
Signature · 1 line
2.39.2
#15 lore raw

[PULL 14/16] target/xtensa: Restrict semihosting to TCG

In reply to Alex Bennée

From: Philippe Mathieu-Daudé <[email protected]>

The semihosting feature depends on TCG (due to the probe_access API access). Although TCG is the single accelerator currently available for the xtensa target, use the Kconfig "imply" directive which is more correct (if we were to support a different accel).

Message-Id: <[email protected]>

Message-Id: <[email protected]>

target/xtensa/Kconfig +1 -1
index 5e46049262..e8c2598c4d 100644
@@ -1,3 +1,3 @@
 config XTENSA
     bool
-    select SEMIHOSTING
+    imply SEMIHOSTING if TCG
Signature · 1 line
2.39.2
#16 lore raw

[PULL 13/16] target/riscv: Restrict semihosting to TCG

In reply to Alex Bennée

From: Philippe Mathieu-Daudé <[email protected]>

Semihosting currently uses the TCG probe_access API. To prepare for encoding the TCG dependency in Kconfig, do not enable it unless TCG is available.

Message-Id: <[email protected]>

Message-Id: <[email protected]>

target/riscv/Kconfig +2 -2
index 5f30df22f2..c332616d36 100644
@@ -1,9 +1,9 @@
 config RISCV32
     bool
-    select ARM_COMPATIBLE_SEMIHOSTING # for do_common_semihosting()
+    imply ARM_COMPATIBLE_SEMIHOSTING if TCG
     select DEVICE_TREE # needed by boot.c
 
 config RISCV64
     bool
-    select ARM_COMPATIBLE_SEMIHOSTING # for do_common_semihosting()
+    imply ARM_COMPATIBLE_SEMIHOSTING if TCG
     select DEVICE_TREE # needed by boot.c
Signature · 1 line
2.39.2
#17 lore raw

Re: [PULL 13/16] target/riscv: Restrict semihosting to TCG

Quoted 19 lines · Alex Bennée

From: Philippe Mathieu-Daudé <[email protected]>

Semihosting currently uses the TCG probe_access API. To prepare for encoding the TCG dependency in Kconfig, do not enable it unless TCG is available.

Message-Id: <[email protected]>

Message-Id: <[email protected]>

target/riscv/Kconfig +0 -0
index 5f30df22f2..c332616d36 100644
@@ -1,9 +1,9 @@
  config RISCV32

target/riscv/Kconfig line 9

Quoted 10 lines
target/riscv/Kconfig +2 -2
      bool
-    select ARM_COMPATIBLE_SEMIHOSTING # for do_common_semihosting()
+    imply ARM_COMPATIBLE_SEMIHOSTING if TCG
      select DEVICE_TREE # needed by boot.c
 
  config RISCV64
      bool
-    select ARM_COMPATIBLE_SEMIHOSTING # for do_common_semihosting()
+    imply ARM_COMPATIBLE_SEMIHOSTING if TCG
      select DEVICE_TREE # needed by boot.c

Hi,

this patch broke compilation with "--without-default-devices":

/usr/bin/ld: libqemu-riscv64-softmmu.a.p/target_riscv_cpu_helper.c.o: in function `riscv_cpu_do_interrupt':
.../qemu/target/riscv/cpu_helper.c:1678:(.text+0x283c): undefined reference to `do_common_semihosting'

Could you please have a look? I think we either have to revert to "select" instead of "imply", or you might need to put some "#if CONFIG_ARM_COMPATIBLE_SEMIHOSTING" into the code that calls do_common_semihosting() ...?

Thomas

#18 lore raw

Re: [PULL 13/16] target/riscv: Restrict semihosting to TCG

Quoted 32 lines · Thomas Huth
Quoted 20 lines · Alex Bennée

From: Philippe Mathieu-Daudé <[email protected]>

Semihosting currently uses the TCG probe_access API. To prepare for encoding the TCG dependency in Kconfig, do not enable it unless TCG is available.

Message-Id: <[email protected]>

Message-Id: <[email protected]>

target/riscv/Kconfig +0 -0
index 5f30df22f2..c332616d36 100644
@@ -1,9 +1,9 @@

  config RISCV32
      bool

Quoted 8 lines

-    select ARM_COMPATIBLE_SEMIHOSTING # for do_common_semihosting() +    imply ARM_COMPATIBLE_SEMIHOSTING if TCG
      select DEVICE_TREE # needed by boot.c
  config RISCV64
      bool
-    select ARM_COMPATIBLE_SEMIHOSTING # for do_common_semihosting() +    imply ARM_COMPATIBLE_SEMIHOSTING if TCG
      select DEVICE_TREE # needed by boot.c

 Hi,

Quoted 6 lines

this patch broke compilation with "--without-default-devices":

/usr/bin/ld: libqemu-riscv64-softmmu.a.p/target_riscv_cpu_helper.c.o: in function `riscv_cpu_do_interrupt':
.../qemu/target/riscv/cpu_helper.c:1678:(.text+0x283c): undefined reference to `do_common_semihosting'

Could you please have a look? I think we either have to revert to "select" instead of "imply", or you might need to put some "#if CONFIG_ARM_COMPATIBLE_SEMIHOSTING" into the code that calls do_common_semihosting() ...?

Suggested a patch here now:

https://lore.kernel.org/qemu-devel/[email protected]/

Thomas

#19 lore raw
In reply to Alex Bennée

Hi Alex,

Quoted 2 lines · Alex Bennée

warn: No match for commit c135d5eaafe7aa2533da663d8e5a34a424b71eb9 found at https://gitlab.com/stsquad/qemu.git
warn: Are you sure you pushed 'pull-target-arm-20240711-209-gc135d5eaaf' there?

Is this warning expected?

Quoted 13 lines

The following changes since commit a7ddb48bd1363c8bcdf42776d320289c42191f01:

   Merge tag 'pull-aspeed-20240721' of https://github.com/legoater/qemu into staging (2024-07-22 07:52:05 +1000)

are available in the Git repository at:

   https://gitlab.com/stsquad/qemu.git pull-target-arm-20240711-209-gc135d5eaaf

for you to fetch changes up to c135d5eaafe7aa2533da663d8e5a34a424b71eb9:

   tests/tcg/aarch64: Fix test-mte.py (2024-07-22 09:38:17 +0100)

----------------------------------------------------------------

#20 lore raw
Quoted 7 lines · Philippe Mathieu-Daudé

Hi Alex,

Quoted 2 lines · Alex Bennée

warn: No match for commit c135d5eaafe7aa2533da663d8e5a34a424b71eb9 found at https://gitlab.com/stsquad/qemu.git
warn: Are you sure you pushed 'pull-target-arm-20240711-209-gc135d5eaaf' there?

Is this warning expected?

Apparently the tag you pushed is pull-maintainer-9.1-rc0-220724-1.

Quoted 15 lines
Quoted 14 lines

The following changes since commit a7ddb48bd1363c8bcdf42776d320289c42191f01:

   Merge tag 'pull-aspeed-20240721' of https://github.com/legoater/qemu into staging (2024-07-22 07:52:05 +1000)

are available in the Git repository at:

   https://gitlab.com/stsquad/qemu.git pull-target-arm-20240711-209-gc135d5eaaf

for you to fetch changes up to c135d5eaafe7aa2533da663d8e5a34a424b71eb9:

   tests/tcg/aarch64: Fix test-mte.py (2024-07-22 09:38:17 +0100)

----------------------------------------------------------------

#21 lore raw
Quoted 10 lines · Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

Hi Alex,

Quoted 4 lines · Alex Bennée

warn: No match for commit c135d5eaafe7aa2533da663d8e5a34a424b71eb9 found at https://gitlab.com/stsquad/qemu.git
warn: Are you sure you pushed 'pull-target-arm-20240711-209-gc135d5eaaf' there?

Is this warning expected?

Apparently the tag you pushed is pull-maintainer-9.1-rc0-220724-1.

doh - I fixed up a checkpatch warning and forgot to push the new tag, let me send v2.

Quoted 20 lines
Quoted 20 lines
Quoted 19 lines

The following changes since commit
a7ddb48bd1363c8bcdf42776d320289c42191f01:

   Merge tag 'pull-aspeed-20240721' of
https://github.com/legoater/qemu into staging (2024-07-22 07:52:05 +1000)

are available in the Git repository at:

   https://gitlab.com/stsquad/qemu.git
pull-target-arm-20240711-209-gc135d5eaaf

for you to fetch changes up to c135d5eaafe7aa2533da663d8e5a34a424b71eb9:

   tests/tcg/aarch64: Fix test-mte.py (2024-07-22 09:38:17 +0100)

----------------------------------------------------------------

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro