All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH  v1 00/10] plugins/next (disas, monitor, docs, execlog)
@ 2022-09-21 16:07 Alex Bennée
  2022-09-21 16:07 ` [PATCH v1 01/10] monitor: expose monitor_puts to rest of code Alex Bennée
                   ` (9 more replies)
  0 siblings, 10 replies; 21+ messages in thread
From: Alex Bennée @ 2022-09-21 16:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: minyihh, ma.mandourr, Luke.Craig, cota, aaron, kuhn.chenqun,
	robhenry, mahmoudabdalghany, Alex Bennée

Hi,

It has been a while since I last posted the state of my plugins queue.
These are mostly small cleanups and documentation tweaks. I also did a
little bit of tidying up in the disas interface.

The following still need review:

 - docs/devel: document the test plugins
 - contrib/plugins: reset skip when matching in execlog
 - docs/devel: move API to end of tcg-plugins.rst
 - docs/devel: clean-up qemu invocations in tcg-plugins
 - tests/tcg: add memory-sve test for aarch64

Alex Bennée (9):
  monitor: expose monitor_puts to rest of code
  disas: generalise plugin_printf and use for monitor_disas
  disas: use result of ->read_memory_func
  tests/tcg: add memory-sve test for aarch64
  plugins: extend execlog to filter matches
  docs/devel: clean-up qemu invocations in tcg-plugins
  docs/devel: move API to end of tcg-plugins.rst
  contrib/plugins: reset skip when matching in execlog
  docs/devel: document the test plugins

Richard Henderson (1):
  plugins: Assert mmu_idx in range before use in qemu_plugin_get_hwaddr

 docs/devel/tcg-plugins.rst                | 175 +++++++++++++++++++---
 docs/devel/writing-monitor-commands.rst   |   2 +-
 include/monitor/monitor.h                 |   1 +
 monitor/monitor-internal.h                |   1 -
 block/monitor/block-hmp-cmds.c            |  10 +-
 contrib/plugins/execlog.c                 |  99 ++++++++++--
 disas.c                                   |  43 +++---
 disas/capstone.c                          |  73 +++++----
 hw/misc/mos6522.c                         |   2 +-
 monitor/hmp-cmds.c                        |   8 +-
 monitor/hmp.c                             |   2 +-
 plugins/api.c                             |   2 +
 target/i386/helper.c                      |   2 +-
 tests/tcg/aarch64/Makefile.softmmu-target |   7 +
 tests/tcg/aarch64/system/boot.S           |   3 +-
 15 files changed, 336 insertions(+), 94 deletions(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH  v1 01/10] monitor: expose monitor_puts to rest of code
  2022-09-21 16:07 [PATCH v1 00/10] plugins/next (disas, monitor, docs, execlog) Alex Bennée
@ 2022-09-21 16:07 ` Alex Bennée
  2022-09-21 17:34   ` Philippe Mathieu-Daudé via
                     ` (2 more replies)
  2022-09-21 16:07 ` [PATCH v1 02/10] disas: generalise plugin_printf and use for monitor_disas Alex Bennée
                   ` (8 subsequent siblings)
  9 siblings, 3 replies; 21+ messages in thread
From: Alex Bennée @ 2022-09-21 16:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: minyihh, ma.mandourr, Luke.Craig, cota, aaron, kuhn.chenqun,
	robhenry, mahmoudabdalghany, Alex Bennée, Richard Henderson,
	Kevin Wolf, Hanna Reitz, Mark Cave-Ayland,
	Dr. David Alan Gilbert, Markus Armbruster,
	open list:Block layer core, open list:New World (mac99)

This helps us construct strings elsewhere before echoing to the
monitor. It avoids having to jump through hoops like:

  monitor_printf(mon, "%s", s->str);

It will be useful in following patches but for now convert all
existing plain "%s" printfs to use the _puts api.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

---
v2
  - s/monitor_printf(mon, "%s"/monitor_puts(mon, /
---
 docs/devel/writing-monitor-commands.rst |  2 +-
 include/monitor/monitor.h               |  1 +
 monitor/monitor-internal.h              |  1 -
 block/monitor/block-hmp-cmds.c          | 10 +++++-----
 hw/misc/mos6522.c                       |  2 +-
 monitor/hmp-cmds.c                      |  8 ++++----
 monitor/hmp.c                           |  2 +-
 target/i386/helper.c                    |  2 +-
 8 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/docs/devel/writing-monitor-commands.rst b/docs/devel/writing-monitor-commands.rst
index 4aa2bb904d..2fefedcd98 100644
--- a/docs/devel/writing-monitor-commands.rst
+++ b/docs/devel/writing-monitor-commands.rst
@@ -716,7 +716,7 @@ message. Here's the implementation of the "info roms" HMP command::
      if (hmp_handle_error(mon, err)) {
          return;
      }
-     monitor_printf(mon, "%s", info->human_readable_text);
+     monitor_puts(mon, info->human_readable_text);
  }
 
 Also, you have to add the function's prototype to the hmp.h file.
diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h
index a4b40e8391..737e750670 100644
--- a/include/monitor/monitor.h
+++ b/include/monitor/monitor.h
@@ -31,6 +31,7 @@ void monitor_resume(Monitor *mon);
 int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp);
 int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp);
 
+int monitor_puts(Monitor *mon, const char *str);
 int monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
     G_GNUC_PRINTF(2, 0);
 int monitor_printf(Monitor *mon, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
diff --git a/monitor/monitor-internal.h b/monitor/monitor-internal.h
index caa2e90ef2..a2cdbbf646 100644
--- a/monitor/monitor-internal.h
+++ b/monitor/monitor-internal.h
@@ -174,7 +174,6 @@ extern int mon_refcount;
 
 extern HMPCommand hmp_cmds[];
 
-int monitor_puts(Monitor *mon, const char *str);
 void monitor_data_init(Monitor *mon, bool is_qmp, bool skip_flush,
                        bool use_io_thread);
 void monitor_data_destroy(Monitor *mon);
diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c
index bfb3c043a0..939a520d17 100644
--- a/block/monitor/block-hmp-cmds.c
+++ b/block/monitor/block-hmp-cmds.c
@@ -638,16 +638,16 @@ static void print_block_info(Monitor *mon, BlockInfo *info,
     assert(!info || !info->has_inserted || info->inserted == inserted);
 
     if (info && *info->device) {
-        monitor_printf(mon, "%s", info->device);
+        monitor_puts(mon, info->device);
         if (inserted && inserted->has_node_name) {
             monitor_printf(mon, " (%s)", inserted->node_name);
         }
     } else {
         assert(info || inserted);
-        monitor_printf(mon, "%s",
-                       inserted && inserted->has_node_name ? inserted->node_name
-                       : info && info->has_qdev ? info->qdev
-                       : "<anonymous>");
+        monitor_puts(mon,
+                     inserted && inserted->has_node_name ? inserted->node_name
+                     : info && info->has_qdev ? info->qdev
+                     : "<anonymous>");
     }
 
     if (inserted) {
diff --git a/hw/misc/mos6522.c b/hw/misc/mos6522.c
index f9e646350e..fe38c44426 100644
--- a/hw/misc/mos6522.c
+++ b/hw/misc/mos6522.c
@@ -595,7 +595,7 @@ void hmp_info_via(Monitor *mon, const QDict *qdict)
     if (hmp_handle_error(mon, err)) {
         return;
     }
-    monitor_printf(mon, "%s", info->human_readable_text);
+    monitor_puts(mon, info->human_readable_text);
 }
 
 static const MemoryRegionOps mos6522_ops = {
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index c6cd6f91dd..f90eea8d01 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -730,7 +730,7 @@ static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
     monitor_printf(mon, "    ");
 
     if (dev->class_info->has_desc) {
-        monitor_printf(mon, "%s", dev->class_info->desc);
+        monitor_puts(mon, dev->class_info->desc);
     } else {
         monitor_printf(mon, "Class %04" PRId64, dev->class_info->q_class);
     }
@@ -2258,12 +2258,12 @@ static void print_stats_schema_value(Monitor *mon, StatsSchemaValue *value)
     if (unit && value->base == 10 &&
         value->exponent >= -18 && value->exponent <= 18 &&
         value->exponent % 3 == 0) {
-        monitor_printf(mon, "%s", si_prefix(value->exponent));
+        monitor_puts(mon, si_prefix(value->exponent));
     } else if (unit && value->base == 2 &&
                value->exponent >= 0 && value->exponent <= 60 &&
                value->exponent % 10 == 0) {
 
-        monitor_printf(mon, "%s", iec_binary_prefix(value->exponent));
+        monitor_puts(mon, iec_binary_prefix(value->exponent));
     } else if (value->exponent) {
         /* Use exponential notation and write the unit's English name */
         monitor_printf(mon, "* %d^%d%s",
@@ -2273,7 +2273,7 @@ static void print_stats_schema_value(Monitor *mon, StatsSchemaValue *value)
     }
 
     if (value->has_unit) {
-        monitor_printf(mon, "%s", unit ? unit : StatsUnit_str(value->unit));
+        monitor_puts(mon, unit ? unit : StatsUnit_str(value->unit));
     }
 
     /* Print bucket size for linear histograms */
diff --git a/monitor/hmp.c b/monitor/hmp.c
index a3375d0341..43fd69f984 100644
--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -1094,7 +1094,7 @@ static void hmp_info_human_readable_text(Monitor *mon,
         return;
     }
 
-    monitor_printf(mon, "%s", info->human_readable_text);
+    monitor_puts(mon, info->human_readable_text);
 }
 
 static void handle_hmp_command_exec(Monitor *mon,
diff --git a/target/i386/helper.c b/target/i386/helper.c
index fa409e9c44..b954ccda50 100644
--- a/target/i386/helper.c
+++ b/target/i386/helper.c
@@ -415,7 +415,7 @@ static void do_inject_x86_mce(CPUState *cs, run_on_cpu_data data)
         if (need_reset) {
             emit_guest_memory_failure(MEMORY_FAILURE_ACTION_RESET, ar,
                                       recursive);
-            monitor_printf(params->mon, "%s", msg);
+            monitor_puts(params->mon, msg);
             qemu_log_mask(CPU_LOG_RESET, "%s\n", msg);
             qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
             return;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v1 02/10] disas: generalise plugin_printf and use for monitor_disas
  2022-09-21 16:07 [PATCH v1 00/10] plugins/next (disas, monitor, docs, execlog) Alex Bennée
  2022-09-21 16:07 ` [PATCH v1 01/10] monitor: expose monitor_puts to rest of code Alex Bennée
@ 2022-09-21 16:07 ` Alex Bennée
  2022-09-21 16:07 ` [PATCH v1 03/10] disas: use result of ->read_memory_func Alex Bennée
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 21+ messages in thread
From: Alex Bennée @ 2022-09-21 16:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: minyihh, ma.mandourr, Luke.Craig, cota, aaron, kuhn.chenqun,
	robhenry, mahmoudabdalghany, Alex Bennée, Richard Henderson

Rather than assembling our output piecemeal lets use the same approach
as the plugin disas interface to build the disassembly string before
printing it.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 disas.c | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/disas.c b/disas.c
index e31438f349..f07b6e760b 100644
--- a/disas.c
+++ b/disas.c
@@ -239,7 +239,7 @@ void target_disas(FILE *out, CPUState *cpu, target_ulong code,
     }
 }
 
-static int plugin_printf(FILE *stream, const char *fmt, ...)
+static int gstring_printf(FILE *stream, const char *fmt, ...)
 {
     /* We abuse the FILE parameter to pass a GString. */
     GString *s = (GString *)stream;
@@ -270,7 +270,7 @@ char *plugin_disas(CPUState *cpu, uint64_t addr, size_t size)
     GString *ds = g_string_new(NULL);
 
     initialize_debug_target(&s, cpu);
-    s.info.fprintf_func = plugin_printf;
+    s.info.fprintf_func = gstring_printf;
     s.info.stream = (FILE *)ds;  /* abuse this slot */
     s.info.buffer_vma = addr;
     s.info.buffer_length = size;
@@ -358,15 +358,19 @@ void monitor_disas(Monitor *mon, CPUState *cpu,
 {
     int count, i;
     CPUDebug s;
+    g_autoptr(GString) ds = g_string_new("");
 
     initialize_debug_target(&s, cpu);
-    s.info.fprintf_func = qemu_fprintf;
+    s.info.fprintf_func = gstring_printf;
+    s.info.stream = (FILE *)ds;  /* abuse this slot */
+
     if (is_physical) {
         s.info.read_memory_func = physical_read_memory;
     }
     s.info.buffer_vma = pc;
 
     if (s.info.cap_arch >= 0 && cap_disas_monitor(&s.info, pc, nb_insn)) {
+        monitor_puts(mon, ds->str);
         return;
     }
 
@@ -376,13 +380,16 @@ void monitor_disas(Monitor *mon, CPUState *cpu,
         return;
     }
 
-    for(i = 0; i < nb_insn; i++) {
-	monitor_printf(mon, "0x" TARGET_FMT_lx ":  ", pc);
+    for (i = 0; i < nb_insn; i++) {
+        g_string_append_printf(ds, "0x" TARGET_FMT_lx ":  ", pc);
         count = s.info.print_insn(pc, &s.info);
-	monitor_printf(mon, "\n");
-	if (count < 0)
-	    break;
+        g_string_append_c(ds, '\n');
+        if (count < 0) {
+            break;
+        }
         pc += count;
     }
+
+    monitor_puts(mon, ds->str);
 }
 #endif
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH  v1 03/10] disas: use result of ->read_memory_func
  2022-09-21 16:07 [PATCH v1 00/10] plugins/next (disas, monitor, docs, execlog) Alex Bennée
  2022-09-21 16:07 ` [PATCH v1 01/10] monitor: expose monitor_puts to rest of code Alex Bennée
  2022-09-21 16:07 ` [PATCH v1 02/10] disas: generalise plugin_printf and use for monitor_disas Alex Bennée
@ 2022-09-21 16:07 ` Alex Bennée
  2022-09-21 17:37   ` Philippe Mathieu-Daudé via
  2022-09-21 16:07 ` [PATCH v1 04/10] tests/tcg: add memory-sve test for aarch64 Alex Bennée
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 21+ messages in thread
From: Alex Bennée @ 2022-09-21 16:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: minyihh, ma.mandourr, Luke.Craig, cota, aaron, kuhn.chenqun,
	robhenry, mahmoudabdalghany, Alex Bennée, Richard Henderson

This gets especially confusing if you start plugging in host addresses
from a trace and you wonder why the output keeps changing. Report when
read_memory_func fails instead of blindly disassembling the buffer
contents.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 disas.c          | 20 ++++++-------
 disas/capstone.c | 73 ++++++++++++++++++++++++++++--------------------
 2 files changed, 53 insertions(+), 40 deletions(-)

diff --git a/disas.c b/disas.c
index f07b6e760b..94d3b45042 100644
--- a/disas.c
+++ b/disas.c
@@ -83,18 +83,18 @@ static int print_insn_objdump(bfd_vma pc, disassemble_info *info,
                               const char *prefix)
 {
     int i, n = info->buffer_length;
-    uint8_t *buf = g_malloc(n);
-
-    info->read_memory_func(pc, buf, n, info);
-
-    for (i = 0; i < n; ++i) {
-        if (i % 32 == 0) {
-            info->fprintf_func(info->stream, "\n%s: ", prefix);
+    g_autofree uint8_t *buf = g_malloc(n);
+
+    if (info->read_memory_func(pc, buf, n, info) == 0) {
+        for (i = 0; i < n; ++i) {
+            if (i % 32 == 0) {
+                info->fprintf_func(info->stream, "\n%s: ", prefix);
+            }
+            info->fprintf_func(info->stream, "%02x", buf[i]);
         }
-        info->fprintf_func(info->stream, "%02x", buf[i]);
+    } else {
+        info->fprintf_func(info->stream, "unable to read memory");
     }
-
-    g_free(buf);
     return n;
 }
 
diff --git a/disas/capstone.c b/disas/capstone.c
index 20bc8f9669..fe3efb0d3c 100644
--- a/disas/capstone.c
+++ b/disas/capstone.c
@@ -191,37 +191,43 @@ bool cap_disas_target(disassemble_info *info, uint64_t pc, size_t size)
         size_t tsize = MIN(sizeof(cap_buf) - csize, size);
         const uint8_t *cbuf = cap_buf;
 
-        info->read_memory_func(pc + csize, cap_buf + csize, tsize, info);
-        csize += tsize;
-        size -= tsize;
+        if (info->read_memory_func(pc + csize, cap_buf + csize, tsize, info) == 0) {
+            csize += tsize;
+            size -= tsize;
 
-        while (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) {
-            cap_dump_insn(info, insn);
-        }
+            while (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) {
+                cap_dump_insn(info, insn);
+            }
+
+            /* If the target memory is not consumed, go back for more... */
+            if (size != 0) {
+                /*
+                 * ... taking care to move any remaining fractional insn
+                 * to the beginning of the buffer.
+                 */
+                if (csize != 0) {
+                    memmove(cap_buf, cbuf, csize);
+                }
+                continue;
+            }
 
-        /* If the target memory is not consumed, go back for more... */
-        if (size != 0) {
             /*
-             * ... taking care to move any remaining fractional insn
-             * to the beginning of the buffer.
+             * Since the target memory is consumed, we should not have
+             * a remaining fractional insn.
              */
             if (csize != 0) {
-                memmove(cap_buf, cbuf, csize);
+                info->fprintf_func(info->stream,
+                                   "Disassembler disagrees with translator "
+                                   "over instruction decoding\n"
+                                   "Please report this to qemu-devel@nongnu.org\n");
             }
-            continue;
-        }
+            break;
 
-        /*
-         * Since the target memory is consumed, we should not have
-         * a remaining fractional insn.
-         */
-        if (csize != 0) {
+        } else {
             info->fprintf_func(info->stream,
-                "Disassembler disagrees with translator "
-                "over instruction decoding\n"
-                "Please report this to qemu-devel@nongnu.org\n");
+                               "0x%08" PRIx64 ": unable to read memory\n", pc);
+            break;
         }
-        break;
     }
 
     cs_close(&handle);
@@ -286,16 +292,23 @@ bool cap_disas_monitor(disassemble_info *info, uint64_t pc, int count)
 
         /* Make certain that we can make progress.  */
         assert(tsize != 0);
-        info->read_memory_func(pc + csize, cap_buf + csize, tsize, info);
-        csize += tsize;
-
-        if (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) {
-            cap_dump_insn(info, insn);
-            if (--count <= 0) {
-                break;
+        if (info->read_memory_func(pc + csize, cap_buf + csize,
+                                   tsize, info) == 0)
+        {
+            csize += tsize;
+
+            if (cs_disasm_iter(handle, &cbuf, &csize, &pc, insn)) {
+                cap_dump_insn(info, insn);
+                if (--count <= 0) {
+                    break;
+                }
             }
+            memmove(cap_buf, cbuf, csize);
+        } else {
+            info->fprintf_func(info->stream,
+                               "0x%08" PRIx64 ": unable to read memory\n", pc);
+            break;
         }
-        memmove(cap_buf, cbuf, csize);
     }
 
     cs_close(&handle);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH  v1 04/10] tests/tcg: add memory-sve test for aarch64
  2022-09-21 16:07 [PATCH v1 00/10] plugins/next (disas, monitor, docs, execlog) Alex Bennée
                   ` (2 preceding siblings ...)
  2022-09-21 16:07 ` [PATCH v1 03/10] disas: use result of ->read_memory_func Alex Bennée
@ 2022-09-21 16:07 ` Alex Bennée
  2022-09-28 22:54   ` Richard Henderson
  2022-09-21 16:07 ` [PATCH v1 05/10] plugins: extend execlog to filter matches Alex Bennée
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 21+ messages in thread
From: Alex Bennée @ 2022-09-21 16:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: minyihh, ma.mandourr, Luke.Craig, cota, aaron, kuhn.chenqun,
	robhenry, mahmoudabdalghany, Alex Bennée, Peter Maydell,
	open list:ARM TCG CPUs

This will be helpful in debugging problems with tracking SVE memory
accesses via the TCG plugins system.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Cc: Robert Henry <robhenry@microsoft.com>
Cc: Aaron Lindsay <aaron@os.amperecomputing.com>
---
 tests/tcg/aarch64/Makefile.softmmu-target | 7 +++++++
 tests/tcg/aarch64/system/boot.S           | 3 ++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/tests/tcg/aarch64/Makefile.softmmu-target b/tests/tcg/aarch64/Makefile.softmmu-target
index f6fcd4829e..26701b718c 100644
--- a/tests/tcg/aarch64/Makefile.softmmu-target
+++ b/tests/tcg/aarch64/Makefile.softmmu-target
@@ -31,6 +31,13 @@ LDFLAGS+=-static -nostdlib $(CRT_OBJS) $(MINILIB_OBJS) -lgcc
 
 memory: CFLAGS+=-DCHECK_UNALIGNED=1
 
+memory-sve: memory.c $(LINK_SCRIPT) $(CRT_OBJS) $(MINILIB_OBJS)
+	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS)
+
+memory-sve: CFLAGS+=-DCHECK_UNALIGNED=1 -march=armv8.1-a+sve -O3 -fno-tree-loop-distribute-patterns
+
+TESTS+=memory-sve
+
 # Running
 QEMU_BASE_MACHINE=-M virt -cpu max -display none
 QEMU_OPTS+=$(QEMU_BASE_MACHINE) -semihosting-config enable=on,target=native,chardev=output -kernel
diff --git a/tests/tcg/aarch64/system/boot.S b/tests/tcg/aarch64/system/boot.S
index e190b1efa6..f136363d2a 100644
--- a/tests/tcg/aarch64/system/boot.S
+++ b/tests/tcg/aarch64/system/boot.S
@@ -179,12 +179,13 @@ __start:
 	isb
 
 	/*
-	 * Enable FP registers. The standard C pre-amble will be
+	 * Enable FP/SVE registers. The standard C pre-amble will be
 	 * saving these and A-profile compilers will use AdvSIMD
 	 * registers unless we tell it not to.
 	*/
 	mrs	x0, cpacr_el1
 	orr	x0, x0, #(3 << 20)
+	orr	x0, x0, #(3 << 16)
 	msr	cpacr_el1, x0
 
 	/* Setup some stack space and enter the test code.
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH  v1 05/10] plugins: extend execlog to filter matches
  2022-09-21 16:07 [PATCH v1 00/10] plugins/next (disas, monitor, docs, execlog) Alex Bennée
                   ` (3 preceding siblings ...)
  2022-09-21 16:07 ` [PATCH v1 04/10] tests/tcg: add memory-sve test for aarch64 Alex Bennée
@ 2022-09-21 16:07 ` Alex Bennée
  2022-09-21 16:07 ` [PATCH v1 06/10] plugins: Assert mmu_idx in range before use in qemu_plugin_get_hwaddr Alex Bennée
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 21+ messages in thread
From: Alex Bennée @ 2022-09-21 16:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: minyihh, ma.mandourr, Luke.Craig, cota, aaron, kuhn.chenqun,
	robhenry, mahmoudabdalghany, Alex Bennée, Alexandre Iooss

Sometimes the whole execlog is just two much so add the ability to
filter by instruction opcode or address.

[AJB: this shows for example

 .qemu-system-aarch64 -display none -serial mon:stdio \
   -M virt -cpu max \
   -semihosting-config enable=on \
   -kernel ./tests/tcg/aarch64-softmmu/memory-sve \
   -plugin ./contrib/plugins/libexeclog.so,ifilter=st1w,afilter=0x40001808 -d plugin -D plugin.out

the st1w SVE instruction is not instrumenting its stores.]

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Alexandre Iooss <erdnaxe@crans.org>
Cc: Robert Henry <robhenry@microsoft.com>
Cc: Aaron Lindsay <aaron@os.amperecomputing.com>
---
 docs/devel/tcg-plugins.rst |  9 +++-
 contrib/plugins/execlog.c  | 96 ++++++++++++++++++++++++++++++++------
 2 files changed, 90 insertions(+), 15 deletions(-)

diff --git a/docs/devel/tcg-plugins.rst b/docs/devel/tcg-plugins.rst
index a7cc44aa20..a503d44cee 100644
--- a/docs/devel/tcg-plugins.rst
+++ b/docs/devel/tcg-plugins.rst
@@ -346,7 +346,7 @@ The execlog tool traces executed instructions with memory access. It can be used
 for debugging and security analysis purposes.
 Please be aware that this will generate a lot of output.
 
-The plugin takes no argument::
+The plugin needs default argument::
 
   qemu-system-arm $(QEMU_ARGS) \
     -plugin ./contrib/plugins/libexeclog.so -d plugin
@@ -364,6 +364,13 @@ which will output an execution trace following this structure::
   0, 0xd34, 0xf9c8f000, "bl #0x10c8"
   0, 0x10c8, 0xfff96c43, "ldr r3, [r0, #0x44]", load, 0x200000e4, RAM
 
+the output can be filtered to only track certain instructions or
+addresses using the `ifilter` or `afilter` options. You can stack the
+arguments if required::
+
+  qemu-system-arm $(QEMU_ARGS) \
+    -plugin ./contrib/plugins/libexeclog.so,ifilter=st1w,afilter=0x40001808 -d plugin
+
 - contrib/plugins/cache.c
 
 Cache modelling plugin that measures the performance of a given L1 cache
diff --git a/contrib/plugins/execlog.c b/contrib/plugins/execlog.c
index a5275dcc15..e659ac9cbb 100644
--- a/contrib/plugins/execlog.c
+++ b/contrib/plugins/execlog.c
@@ -20,6 +20,9 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
 /* Store last executed instruction on each vCPU as a GString */
 GArray *last_exec;
 
+static GPtrArray *imatches;
+static GArray *amatches;
+
 /**
  * Add memory read or write information to current instruction log
  */
@@ -85,12 +88,13 @@ static void vcpu_insn_exec(unsigned int cpu_index, void *udata)
 static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
 {
     struct qemu_plugin_insn *insn;
-    uint64_t insn_vaddr;
-    uint32_t insn_opcode;
-    char *insn_disas;
+    bool skip = (imatches || amatches) ? true : false;
 
     size_t n = qemu_plugin_tb_n_insns(tb);
     for (size_t i = 0; i < n; i++) {
+        char *insn_disas;
+        uint64_t insn_vaddr;
+
         /*
          * `insn` is shared between translations in QEMU, copy needed data here.
          * `output` is never freed as it might be used multiple times during
@@ -99,20 +103,52 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
          * a limitation for CISC architectures.
          */
         insn = qemu_plugin_tb_get_insn(tb, i);
-        insn_vaddr = qemu_plugin_insn_vaddr(insn);
-        insn_opcode = *((uint32_t *)qemu_plugin_insn_data(insn));
         insn_disas = qemu_plugin_insn_disas(insn);
-        char *output = g_strdup_printf("0x%"PRIx64", 0x%"PRIx32", \"%s\"",
-                                       insn_vaddr, insn_opcode, insn_disas);
+        insn_vaddr = qemu_plugin_insn_vaddr(insn);
+
+        /*
+         * If we are filtering we better check out if we have any
+         * hits. The skip "latches" so we can track memory accesses
+         * after the instruction we care about.
+         */
+        if (skip && imatches) {
+            int j;
+            for (j = 0; j < imatches->len && skip; j++) {
+                char *m = g_ptr_array_index(imatches, j);
+                if (g_str_has_prefix(insn_disas, m)) {
+                    skip = false;
+                }
+            }
+        }
+
+        if (skip && amatches) {
+            int j;
+            for (j = 0; j < amatches->len && skip; j++) {
+                uint64_t v = g_array_index(amatches, uint64_t, j);
+                if (v == insn_vaddr) {
+                    skip = false;
+                }
+            }
+        }
 
-        /* Register callback on memory read or write */
-        qemu_plugin_register_vcpu_mem_cb(insn, vcpu_mem,
-                                         QEMU_PLUGIN_CB_NO_REGS,
-                                         QEMU_PLUGIN_MEM_RW, NULL);
+        if (skip) {
+            g_free(insn_disas);
+        } else {
+            uint32_t insn_opcode;
+            insn_opcode = *((uint32_t *)qemu_plugin_insn_data(insn));
+            char *output = g_strdup_printf("0x%"PRIx64", 0x%"PRIx32", \"%s\"",
+                                           insn_vaddr, insn_opcode, insn_disas);
+
+            /* Register callback on memory read or write */
+            qemu_plugin_register_vcpu_mem_cb(insn, vcpu_mem,
+                                             QEMU_PLUGIN_CB_NO_REGS,
+                                             QEMU_PLUGIN_MEM_RW, NULL);
+
+            /* Register callback on instruction */
+            qemu_plugin_register_vcpu_insn_exec_cb(insn, vcpu_insn_exec,
+                                                   QEMU_PLUGIN_CB_NO_REGS, output);
+        }
 
-        /* Register callback on instruction */
-        qemu_plugin_register_vcpu_insn_exec_cb(insn, vcpu_insn_exec,
-                                               QEMU_PLUGIN_CB_NO_REGS, output);
     }
 }
 
@@ -132,6 +168,25 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
     }
 }
 
+/* Add a match to the array of matches */
+static void parse_insn_match(char *match)
+{
+    if (!imatches) {
+        imatches = g_ptr_array_new();
+    }
+    g_ptr_array_add(imatches, match);
+}
+
+static void parse_vaddr_match(char *match)
+{
+    uint64_t v = g_ascii_strtoull(match, NULL, 16);
+
+    if (!amatches) {
+        amatches = g_array_new(false, true, sizeof(uint64_t));
+    }
+    g_array_append_val(amatches, v);
+}
+
 /**
  * Install the plugin
  */
@@ -145,6 +200,19 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
      */
     last_exec = g_array_new(FALSE, FALSE, sizeof(GString *));
 
+    for (int i = 0; i < argc; i++) {
+        char *opt = argv[i];
+        g_autofree char **tokens = g_strsplit(opt, "=", 2);
+        if (g_strcmp0(tokens[0], "ifilter") == 0) {
+            parse_insn_match(tokens[1]);
+        } else if (g_strcmp0(tokens[0], "afilter") == 0) {
+            parse_vaddr_match(tokens[1]);
+        } else {
+            fprintf(stderr, "option parsing failed: %s\n", opt);
+            return -1;
+        }
+    }
+
     /* Register translation block and exit callbacks */
     qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans);
     qemu_plugin_register_atexit_cb(id, plugin_exit, NULL);
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v1 06/10] plugins: Assert mmu_idx in range before use in qemu_plugin_get_hwaddr
  2022-09-21 16:07 [PATCH v1 00/10] plugins/next (disas, monitor, docs, execlog) Alex Bennée
                   ` (4 preceding siblings ...)
  2022-09-21 16:07 ` [PATCH v1 05/10] plugins: extend execlog to filter matches Alex Bennée
@ 2022-09-21 16:07 ` Alex Bennée
  2022-09-21 17:40   ` Philippe Mathieu-Daudé via
  2022-09-21 16:07 ` [PATCH v1 07/10] docs/devel: clean-up qemu invocations in tcg-plugins Alex Bennée
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 21+ messages in thread
From: Alex Bennée @ 2022-09-21 16:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: minyihh, ma.mandourr, Luke.Craig, cota, aaron, kuhn.chenqun,
	robhenry, mahmoudabdalghany, Richard Henderson, Damien Hedde,
	Alex Bennée, Alexandre Iooss

From: Richard Henderson <richard.henderson@linaro.org>

Coverity reports out-of-bound accesses here.  This should be a
false positive due to how the index is decoded from MemOpIdx.

Fixes: Coverity CID 1487201
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Damien Hedde <damien.hedde@greensocs.com>
Message-Id: <20220401190233.329360-1-richard.henderson@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 plugins/api.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/plugins/api.c b/plugins/api.c
index 7bf71b189d..2078b16edb 100644
--- a/plugins/api.c
+++ b/plugins/api.c
@@ -289,6 +289,8 @@ struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu_plugin_meminfo_t info,
     enum qemu_plugin_mem_rw rw = get_plugin_meminfo_rw(info);
     hwaddr_info.is_store = (rw & QEMU_PLUGIN_MEM_W) != 0;
 
+    assert(mmu_idx < NB_MMU_MODES);
+
     if (!tlb_plugin_lookup(cpu, vaddr, mmu_idx,
                            hwaddr_info.is_store, &hwaddr_info)) {
         error_report("invalid use of qemu_plugin_get_hwaddr");
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v1 07/10] docs/devel: clean-up qemu invocations in tcg-plugins
  2022-09-21 16:07 [PATCH v1 00/10] plugins/next (disas, monitor, docs, execlog) Alex Bennée
                   ` (5 preceding siblings ...)
  2022-09-21 16:07 ` [PATCH v1 06/10] plugins: Assert mmu_idx in range before use in qemu_plugin_get_hwaddr Alex Bennée
@ 2022-09-21 16:07 ` Alex Bennée
  2022-09-21 17:39   ` Philippe Mathieu-Daudé via
  2022-09-21 16:07 ` [PATCH v1 08/10] docs/devel: move API to end of tcg-plugins.rst Alex Bennée
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 21+ messages in thread
From: Alex Bennée @ 2022-09-21 16:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: minyihh, ma.mandourr, Luke.Craig, cota, aaron, kuhn.chenqun,
	robhenry, mahmoudabdalghany, Alex Bennée, Alexandre Iooss

We currently have the final binaries in the root of the build dir so
the build prefix is superfluous. Additionally add a shell prompt to be
more in line with the rest of the code.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 docs/devel/tcg-plugins.rst | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/docs/devel/tcg-plugins.rst b/docs/devel/tcg-plugins.rst
index a503d44cee..a6fdde01f8 100644
--- a/docs/devel/tcg-plugins.rst
+++ b/docs/devel/tcg-plugins.rst
@@ -172,7 +172,7 @@ slightly faster (but not thread safe) counters.
 
 Example::
 
-  ./aarch64-linux-user/qemu-aarch64 \
+  $ qemu-aarch64 \
     -plugin contrib/plugins/libhotblocks.so -d plugin \
     ./tests/tcg/aarch64-linux-user/sha1
   SHA1=15dd99a1991e0b3826fede3deffc1feba42278e6
@@ -186,7 +186,7 @@ Example::
 
 Similar to hotblocks but this time tracks memory accesses::
 
-  ./aarch64-linux-user/qemu-aarch64 \
+  $ qemu-aarch64 \
     -plugin contrib/plugins/libhotpages.so -d plugin \
     ./tests/tcg/aarch64-linux-user/sha1
   SHA1=15dd99a1991e0b3826fede3deffc1feba42278e6
@@ -220,7 +220,7 @@ counted. You can give a value to the ``count`` argument for a class of
 instructions to break it down fully, so for example to see all the system
 registers accesses::
 
-  ./aarch64-softmmu/qemu-system-aarch64 $(QEMU_ARGS) \
+  $ qemu-system-aarch64 $(QEMU_ARGS) \
     -append "root=/dev/sda2 systemd.unit=benchmark.service" \
     -smp 4 -plugin ./contrib/plugins/libhowvec.so,count=sreg -d plugin
 
@@ -288,10 +288,10 @@ for the plugin is a path for the socket the two instances will
 communicate over::
 
 
-  ./sparc-softmmu/qemu-system-sparc -monitor none -parallel none \
+  $ qemu-system-sparc -monitor none -parallel none \
     -net none -M SS-20 -m 256 -kernel day11/zImage.elf \
     -plugin ./contrib/plugins/liblockstep.so,sockpath=lockstep-sparc.sock \
-  -d plugin,nochain
+    -d plugin,nochain
 
 which will eventually report::
 
@@ -348,7 +348,7 @@ Please be aware that this will generate a lot of output.
 
 The plugin needs default argument::
 
-  qemu-system-arm $(QEMU_ARGS) \
+  $ qemu-system-arm $(QEMU_ARGS) \
     -plugin ./contrib/plugins/libexeclog.so -d plugin
 
 which will output an execution trace following this structure::
@@ -365,10 +365,10 @@ which will output an execution trace following this structure::
   0, 0x10c8, 0xfff96c43, "ldr r3, [r0, #0x44]", load, 0x200000e4, RAM
 
 the output can be filtered to only track certain instructions or
-addresses using the `ifilter` or `afilter` options. You can stack the
+addresses using the ``ifilter`` or ``afilter`` options. You can stack the
 arguments if required::
 
-  qemu-system-arm $(QEMU_ARGS) \
+  $ qemu-system-arm $(QEMU_ARGS) \
     -plugin ./contrib/plugins/libexeclog.so,ifilter=st1w,afilter=0x40001808 -d plugin
 
 - contrib/plugins/cache.c
@@ -377,7 +377,7 @@ Cache modelling plugin that measures the performance of a given L1 cache
 configuration, and optionally a unified L2 per-core cache when a given working
 set is run::
 
-    qemu-x86_64 -plugin ./contrib/plugins/libcache.so \
+  $ qemu-x86_64 -plugin ./contrib/plugins/libcache.so \
       -d plugin -D cache.log ./tests/tcg/x86_64-linux-user/float_convs
 
 will report the following::
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH  v1 08/10] docs/devel: move API to end of tcg-plugins.rst
  2022-09-21 16:07 [PATCH v1 00/10] plugins/next (disas, monitor, docs, execlog) Alex Bennée
                   ` (6 preceding siblings ...)
  2022-09-21 16:07 ` [PATCH v1 07/10] docs/devel: clean-up qemu invocations in tcg-plugins Alex Bennée
@ 2022-09-21 16:07 ` Alex Bennée
  2022-09-21 17:39   ` Philippe Mathieu-Daudé via
  2022-09-21 16:08 ` [PATCH v1 09/10] contrib/plugins: reset skip when matching in execlog Alex Bennée
  2022-09-21 16:08 ` [PATCH v1 10/10] docs/devel: document the test plugins Alex Bennée
  9 siblings, 1 reply; 21+ messages in thread
From: Alex Bennée @ 2022-09-21 16:07 UTC (permalink / raw)
  To: qemu-devel
  Cc: minyihh, ma.mandourr, Luke.Craig, cota, aaron, kuhn.chenqun,
	robhenry, mahmoudabdalghany, Alex Bennée, Alexandre Iooss

The API documentation is quite dry and doesn't flow nicely with the
rest of the document. Move it to its own section at the bottom along
with a little leader text to remind people to update it.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 docs/devel/tcg-plugins.rst | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/docs/devel/tcg-plugins.rst b/docs/devel/tcg-plugins.rst
index a6fdde01f8..8b40b2a606 100644
--- a/docs/devel/tcg-plugins.rst
+++ b/docs/devel/tcg-plugins.rst
@@ -110,11 +110,6 @@ details are opaque to plugins. The plugin is able to query select
 details of instructions and system configuration only through the
 exported *qemu_plugin* functions.
 
-API
-~~~
-
-.. kernel-doc:: include/qemu/qemu-plugin.h
-
 Internals
 ---------
 
@@ -448,3 +443,13 @@ The plugin has a number of arguments, all of them are optional:
   associativity of the L2 cache, respectively. Setting any of the L2
   configuration arguments implies ``l2=on``.
   (default: N = 2097152 (2MB), B = 64, A = 16)
+
+API
+---
+
+The following API is generated from the inline documentation in
+``include/qemu/qemu-plugin.h``. Please ensure any updates to the API
+include the full kernel-doc annotations.
+
+.. kernel-doc:: include/qemu/qemu-plugin.h
+
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH v1 09/10] contrib/plugins: reset skip when matching in execlog
  2022-09-21 16:07 [PATCH v1 00/10] plugins/next (disas, monitor, docs, execlog) Alex Bennée
                   ` (7 preceding siblings ...)
  2022-09-21 16:07 ` [PATCH v1 08/10] docs/devel: move API to end of tcg-plugins.rst Alex Bennée
@ 2022-09-21 16:08 ` Alex Bennée
  2022-09-21 17:38   ` Philippe Mathieu-Daudé via
  2022-09-28 22:59   ` Richard Henderson
  2022-09-21 16:08 ` [PATCH v1 10/10] docs/devel: document the test plugins Alex Bennée
  9 siblings, 2 replies; 21+ messages in thread
From: Alex Bennée @ 2022-09-21 16:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: minyihh, ma.mandourr, Luke.Craig, cota, aaron, kuhn.chenqun,
	robhenry, mahmoudabdalghany, Alex Bennée, Alexandre Iooss

The purpose of the matches was to only track the execution of
instructions we care about. Without resetting skip to the value at the
start of the block we end up dumping all instructions after the match
with the consequent load on the instrumentation.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Cc: Alexandre Iooss <erdnaxe@crans.org>
---
 contrib/plugins/execlog.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/contrib/plugins/execlog.c b/contrib/plugins/execlog.c
index e659ac9cbb..b5360f2c8e 100644
--- a/contrib/plugins/execlog.c
+++ b/contrib/plugins/execlog.c
@@ -147,6 +147,9 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
             /* Register callback on instruction */
             qemu_plugin_register_vcpu_insn_exec_cb(insn, vcpu_insn_exec,
                                                    QEMU_PLUGIN_CB_NO_REGS, output);
+
+            /* reset skip */
+            skip = (imatches || amatches) ? true : false;
         }
 
     }
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH  v1 10/10] docs/devel: document the test plugins
  2022-09-21 16:07 [PATCH v1 00/10] plugins/next (disas, monitor, docs, execlog) Alex Bennée
                   ` (8 preceding siblings ...)
  2022-09-21 16:08 ` [PATCH v1 09/10] contrib/plugins: reset skip when matching in execlog Alex Bennée
@ 2022-09-21 16:08 ` Alex Bennée
  9 siblings, 0 replies; 21+ messages in thread
From: Alex Bennée @ 2022-09-21 16:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: minyihh, ma.mandourr, Luke.Craig, cota, aaron, kuhn.chenqun,
	robhenry, mahmoudabdalghany, Alex Bennée, Alexandre Iooss

Although the test plugins are fairly basic they are still useful for
some things so we should document their existence.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
 docs/devel/tcg-plugins.rst | 137 +++++++++++++++++++++++++++++++++++--
 1 file changed, 133 insertions(+), 4 deletions(-)

diff --git a/docs/devel/tcg-plugins.rst b/docs/devel/tcg-plugins.rst
index 8b40b2a606..9740a70406 100644
--- a/docs/devel/tcg-plugins.rst
+++ b/docs/devel/tcg-plugins.rst
@@ -145,12 +145,141 @@ Example Plugins
 
 There are a number of plugins included with QEMU and you are
 encouraged to contribute your own plugins plugins upstream. There is a
-``contrib/plugins`` directory where they can go.
+``contrib/plugins`` directory where they can go. There are also some
+basic plugins that are used to test and exercise the API during the
+``make check-tcg`` target in ``tests\plugins``.
 
-- tests/plugins
+- tests/plugins/empty.c
 
-These are some basic plugins that are used to test and exercise the
-API during the ``make check-tcg`` target.
+Purely a test plugin for measuring the overhead of the plugins system
+itself. Does no instrumentation.
+
+- tests/plugins/bb.c
+
+A very basic plugin which will measure execution in course terms as
+each basic block is executed. By default the results are shown once
+execution finishes::
+
+  $ qemu-aarch64 -plugin tests/plugin/libbb.so \
+      -d plugin ./tests/tcg/aarch64-linux-user/sha1
+  SHA1=15dd99a1991e0b3826fede3deffc1feba42278e6
+  bb's: 2277338, insns: 158483046
+
+Behaviour can be tweaked with the following arguments:
+
+ * inline=true|false
+
+ Use faster inline addition of a single counter. Not per-cpu and not
+ thread safe.
+
+ * idle=true|false
+
+ Dump the current execution stats whenever the guest vCPU idles
+
+- tests/plugins/insn.c
+
+This is a basic instruction level instrumentation which can count the
+number of instructions executed on each core/thread::
+
+  $ qemu-aarch64 -plugin tests/plugin/libinsn.so \
+      -d plugin ./tests/tcg/aarch64-linux-user/threadcount
+  Created 10 threads
+  Done
+  cpu 0 insns: 46765
+  cpu 1 insns: 3694
+  cpu 2 insns: 3694
+  cpu 3 insns: 2994
+  cpu 4 insns: 1497
+  cpu 5 insns: 1497
+  cpu 6 insns: 1497
+  cpu 7 insns: 1497
+  total insns: 63135
+
+Behaviour can be tweaked with the following arguments:
+
+ * inline=true|false
+
+ Use faster inline addition of a single counter. Not per-cpu and not
+ thread safe.
+
+ * sizes=true|false
+
+ Give a summary of the instruction sizes for the execution
+
+ * match=<string>
+
+ Only instrument instructions matching the string prefix. Will show
+ some basic stats including how many instructions have executed since
+ the last execution. For example::
+
+   $ qemu-aarch64 -plugin tests/plugin/libinsn.so,match=bl \
+       -d plugin ./tests/tcg/aarch64-linux-user/sha512-vector
+   ...
+   0x40069c, 'bl #0x4002b0', 10 hits, 1093 match hits, Δ+1257 since last match, 98 avg insns/match
+   0x4006ac, 'bl #0x403690', 10 hits, 1094 match hits, Δ+47 since last match, 98 avg insns/match 
+   0x4037fc, 'bl #0x4002b0', 18 hits, 1095 match hits, Δ+22 since last match, 98 avg insns/match 
+   0x400720, 'bl #0x403690', 10 hits, 1096 match hits, Δ+58 since last match, 98 avg insns/match 
+   0x4037fc, 'bl #0x4002b0', 19 hits, 1097 match hits, Δ+22 since last match, 98 avg insns/match 
+   0x400730, 'bl #0x403690', 10 hits, 1098 match hits, Δ+33 since last match, 98 avg insns/match 
+   0x4037ac, 'bl #0x4002b0', 12 hits, 1099 match hits, Δ+20 since last match, 98 avg insns/match 
+   ...
+
+For more detailed execution tracing see the ``execlog`` plugin for
+other options.
+
+- tests/plugins/mem.c
+
+Basic instruction level memory instrumentation::
+
+  $ qemu-aarch64 -plugin tests/plugin/libmem.so,inline=true \
+      -d plugin ./tests/tcg/aarch64-linux-user/sha1
+  SHA1=15dd99a1991e0b3826fede3deffc1feba42278e6
+  inline mem accesses: 79525013
+
+Behaviour can be tweaked with the following arguments:
+
+ * inline=true|false
+
+ Use faster inline addition of a single counter. Not per-cpu and not
+ thread safe.
+
+ * callback=true|false
+
+ Use callbacks on each memory instrumentation.
+
+ * hwaddr=true|false
+
+ Count IO accesses (only for system emulation)
+
+- tests/plugins/syscall.c
+
+A basic syscall tracing plugin. This only works for user-mode. By
+default it will give a summary of syscall stats at the end of the
+run::
+
+  $ qemu-aarch64 -plugin tests/plugin/libsyscall \
+      -d plugin ./tests/tcg/aarch64-linux-user/threadcount
+  Created 10 threads
+  Done
+  syscall no.  calls  errors
+  226          12     0
+  99           11     11
+  115          11     0
+  222          11     0
+  93           10     0
+  220          10     0
+  233          10     0
+  215          8      0
+  214          4      0
+  134          2      0
+  64           2      0
+  96           1      0
+  94           1      0
+  80           1      0
+  261          1      0
+  78           1      0
+  160          1      0
+  135          1      0
 
 - contrib/plugins/hotblocks.c
 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [PATCH v1 01/10] monitor: expose monitor_puts to rest of code
  2022-09-21 16:07 ` [PATCH v1 01/10] monitor: expose monitor_puts to rest of code Alex Bennée
@ 2022-09-21 17:34   ` Philippe Mathieu-Daudé via
  2022-09-22  4:30   ` Markus Armbruster
  2022-09-22 15:06   ` Kevin Wolf
  2 siblings, 0 replies; 21+ messages in thread
From: Philippe Mathieu-Daudé via @ 2022-09-21 17:34 UTC (permalink / raw)
  To: Alex Bennée, qemu-devel
  Cc: minyihh, ma.mandourr, Luke.Craig, cota, aaron, kuhn.chenqun,
	robhenry, mahmoudabdalghany, Richard Henderson, Kevin Wolf,
	Hanna Reitz, Mark Cave-Ayland, Dr. David Alan Gilbert,
	Markus Armbruster, open list:Block layer core,
	open list:New World (mac99)

On 21/9/22 18:07, Alex Bennée wrote:
> This helps us construct strings elsewhere before echoing to the
> monitor. It avoids having to jump through hoops like:
> 
>    monitor_printf(mon, "%s", s->str);
> 
> It will be useful in following patches but for now convert all
> existing plain "%s" printfs to use the _puts api.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> 
> ---
> v2
>    - s/monitor_printf(mon, "%s"/monitor_puts(mon, /
> ---
>   docs/devel/writing-monitor-commands.rst |  2 +-
>   include/monitor/monitor.h               |  1 +
>   monitor/monitor-internal.h              |  1 -
>   block/monitor/block-hmp-cmds.c          | 10 +++++-----
>   hw/misc/mos6522.c                       |  2 +-
>   monitor/hmp-cmds.c                      |  8 ++++----
>   monitor/hmp.c                           |  2 +-
>   target/i386/helper.c                    |  2 +-
>   8 files changed, 14 insertions(+), 14 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v1 03/10] disas: use result of ->read_memory_func
  2022-09-21 16:07 ` [PATCH v1 03/10] disas: use result of ->read_memory_func Alex Bennée
@ 2022-09-21 17:37   ` Philippe Mathieu-Daudé via
  0 siblings, 0 replies; 21+ messages in thread
From: Philippe Mathieu-Daudé via @ 2022-09-21 17:37 UTC (permalink / raw)
  To: Alex Bennée, qemu-devel
  Cc: minyihh, ma.mandourr, Luke.Craig, cota, aaron, kuhn.chenqun,
	robhenry, mahmoudabdalghany, Richard Henderson

On 21/9/22 18:07, Alex Bennée wrote:
> This gets especially confusing if you start plugging in host addresses
> from a trace and you wonder why the output keeps changing. Report when
> read_memory_func fails instead of blindly disassembling the buffer
> contents.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   disas.c          | 20 ++++++-------
>   disas/capstone.c | 73 ++++++++++++++++++++++++++++--------------------
>   2 files changed, 53 insertions(+), 40 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v1 09/10] contrib/plugins: reset skip when matching in execlog
  2022-09-21 16:08 ` [PATCH v1 09/10] contrib/plugins: reset skip when matching in execlog Alex Bennée
@ 2022-09-21 17:38   ` Philippe Mathieu-Daudé via
  2022-09-28 22:59   ` Richard Henderson
  1 sibling, 0 replies; 21+ messages in thread
From: Philippe Mathieu-Daudé via @ 2022-09-21 17:38 UTC (permalink / raw)
  To: Alex Bennée, qemu-devel
  Cc: minyihh, ma.mandourr, Luke.Craig, cota, aaron, kuhn.chenqun,
	robhenry, mahmoudabdalghany, Alexandre Iooss

On 21/9/22 18:08, Alex Bennée wrote:
> The purpose of the matches was to only track the execution of
> instructions we care about. Without resetting skip to the value at the
> start of the block we end up dumping all instructions after the match
> with the consequent load on the instrumentation.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Cc: Alexandre Iooss <erdnaxe@crans.org>
> ---
>   contrib/plugins/execlog.c | 3 +++
>   1 file changed, 3 insertions(+)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v1 08/10] docs/devel: move API to end of tcg-plugins.rst
  2022-09-21 16:07 ` [PATCH v1 08/10] docs/devel: move API to end of tcg-plugins.rst Alex Bennée
@ 2022-09-21 17:39   ` Philippe Mathieu-Daudé via
  0 siblings, 0 replies; 21+ messages in thread
From: Philippe Mathieu-Daudé via @ 2022-09-21 17:39 UTC (permalink / raw)
  To: Alex Bennée, qemu-devel
  Cc: minyihh, ma.mandourr, Luke.Craig, cota, aaron, kuhn.chenqun,
	robhenry, mahmoudabdalghany, Alexandre Iooss

On 21/9/22 18:07, Alex Bennée wrote:
> The API documentation is quite dry and doesn't flow nicely with the
> rest of the document. Move it to its own section at the bottom along
> with a little leader text to remind people to update it.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>   docs/devel/tcg-plugins.rst | 15 ++++++++++-----
>   1 file changed, 10 insertions(+), 5 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v1 07/10] docs/devel: clean-up qemu invocations in tcg-plugins
  2022-09-21 16:07 ` [PATCH v1 07/10] docs/devel: clean-up qemu invocations in tcg-plugins Alex Bennée
@ 2022-09-21 17:39   ` Philippe Mathieu-Daudé via
  0 siblings, 0 replies; 21+ messages in thread
From: Philippe Mathieu-Daudé via @ 2022-09-21 17:39 UTC (permalink / raw)
  To: Alex Bennée, qemu-devel
  Cc: minyihh, ma.mandourr, Luke.Craig, cota, aaron, kuhn.chenqun,
	robhenry, mahmoudabdalghany, Alexandre Iooss

On 21/9/22 18:07, Alex Bennée wrote:
> We currently have the final binaries in the root of the build dir so
> the build prefix is superfluous. Additionally add a shell prompt to be
> more in line with the rest of the code.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>   docs/devel/tcg-plugins.rst | 18 +++++++++---------
>   1 file changed, 9 insertions(+), 9 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v1 06/10] plugins: Assert mmu_idx in range before use in qemu_plugin_get_hwaddr
  2022-09-21 16:07 ` [PATCH v1 06/10] plugins: Assert mmu_idx in range before use in qemu_plugin_get_hwaddr Alex Bennée
@ 2022-09-21 17:40   ` Philippe Mathieu-Daudé via
  0 siblings, 0 replies; 21+ messages in thread
From: Philippe Mathieu-Daudé via @ 2022-09-21 17:40 UTC (permalink / raw)
  To: Alex Bennée, qemu-devel
  Cc: minyihh, ma.mandourr, Luke.Craig, cota, aaron, kuhn.chenqun,
	robhenry, mahmoudabdalghany, Richard Henderson, Damien Hedde,
	Alexandre Iooss

On 21/9/22 18:07, Alex Bennée wrote:
> From: Richard Henderson <richard.henderson@linaro.org>
> 
> Coverity reports out-of-bound accesses here.  This should be a
> false positive due to how the index is decoded from MemOpIdx.
> 
> Fixes: Coverity CID 1487201
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> Reviewed-by: Damien Hedde <damien.hedde@greensocs.com>
> Message-Id: <20220401190233.329360-1-richard.henderson@linaro.org>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>   plugins/api.c | 2 ++
>   1 file changed, 2 insertions(+)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH  v1 01/10] monitor: expose monitor_puts to rest of code
  2022-09-21 16:07 ` [PATCH v1 01/10] monitor: expose monitor_puts to rest of code Alex Bennée
  2022-09-21 17:34   ` Philippe Mathieu-Daudé via
@ 2022-09-22  4:30   ` Markus Armbruster
  2022-09-22 15:06   ` Kevin Wolf
  2 siblings, 0 replies; 21+ messages in thread
From: Markus Armbruster @ 2022-09-22  4:30 UTC (permalink / raw)
  To: Alex Bennée
  Cc: qemu-devel, minyihh, ma.mandourr, Luke.Craig, cota, aaron,
	kuhn.chenqun, robhenry, mahmoudabdalghany, Richard Henderson,
	Kevin Wolf, Hanna Reitz, Mark Cave-Ayland,
	Dr. David Alan Gilbert, Markus Armbruster,
	open list:Block layer core, open list:New World (mac99)

Alex Bennée <alex.bennee@linaro.org> writes:

> This helps us construct strings elsewhere before echoing to the
> monitor. It avoids having to jump through hoops like:
>
>   monitor_printf(mon, "%s", s->str);
>
> It will be useful in following patches but for now convert all
> existing plain "%s" printfs to use the _puts api.
>
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Markus Armbruster <armbru@redhat.com>



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH  v1 01/10] monitor: expose monitor_puts to rest of code
  2022-09-21 16:07 ` [PATCH v1 01/10] monitor: expose monitor_puts to rest of code Alex Bennée
  2022-09-21 17:34   ` Philippe Mathieu-Daudé via
  2022-09-22  4:30   ` Markus Armbruster
@ 2022-09-22 15:06   ` Kevin Wolf
  2 siblings, 0 replies; 21+ messages in thread
From: Kevin Wolf @ 2022-09-22 15:06 UTC (permalink / raw)
  To: Alex Bennée
  Cc: qemu-devel, minyihh, ma.mandourr, Luke.Craig, cota, aaron,
	kuhn.chenqun, robhenry, mahmoudabdalghany, Richard Henderson,
	Hanna Reitz, Mark Cave-Ayland, Dr. David Alan Gilbert,
	Markus Armbruster, open list:Block layer core,
	open list:New World (mac99)

Am 21.09.2022 um 18:07 hat Alex Bennée geschrieben:
> This helps us construct strings elsewhere before echoing to the
> monitor. It avoids having to jump through hoops like:
> 
>   monitor_printf(mon, "%s", s->str);
> 
> It will be useful in following patches but for now convert all
> existing plain "%s" printfs to use the _puts api.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

Reviewed-by: Kevin Wolf <kwolf@redhat.com>



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v1 04/10] tests/tcg: add memory-sve test for aarch64
  2022-09-21 16:07 ` [PATCH v1 04/10] tests/tcg: add memory-sve test for aarch64 Alex Bennée
@ 2022-09-28 22:54   ` Richard Henderson
  0 siblings, 0 replies; 21+ messages in thread
From: Richard Henderson @ 2022-09-28 22:54 UTC (permalink / raw)
  To: Alex Bennée, qemu-devel
  Cc: minyihh, ma.mandourr, Luke.Craig, cota, aaron, kuhn.chenqun,
	robhenry, mahmoudabdalghany, Peter Maydell,
	open list:ARM TCG CPUs

On 9/21/22 09:07, Alex Bennée wrote:
> This will be helpful in debugging problems with tracking SVE memory
> accesses via the TCG plugins system.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Cc: Robert Henry <robhenry@microsoft.com>
> Cc: Aaron Lindsay <aaron@os.amperecomputing.com>
> ---
>   tests/tcg/aarch64/Makefile.softmmu-target | 7 +++++++
>   tests/tcg/aarch64/system/boot.S           | 3 ++-
>   2 files changed, 9 insertions(+), 1 deletion(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH v1 09/10] contrib/plugins: reset skip when matching in execlog
  2022-09-21 16:08 ` [PATCH v1 09/10] contrib/plugins: reset skip when matching in execlog Alex Bennée
  2022-09-21 17:38   ` Philippe Mathieu-Daudé via
@ 2022-09-28 22:59   ` Richard Henderson
  1 sibling, 0 replies; 21+ messages in thread
From: Richard Henderson @ 2022-09-28 22:59 UTC (permalink / raw)
  To: Alex Bennée, qemu-devel
  Cc: minyihh, ma.mandourr, Luke.Craig, cota, aaron, kuhn.chenqun,
	robhenry, mahmoudabdalghany, Alexandre Iooss

On 9/21/22 09:08, Alex Bennée wrote:
> The purpose of the matches was to only track the execution of
> instructions we care about. Without resetting skip to the value at the
> start of the block we end up dumping all instructions after the match
> with the consequent load on the instrumentation.
> 
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Cc: Alexandre Iooss <erdnaxe@crans.org>
> ---
>   contrib/plugins/execlog.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/contrib/plugins/execlog.c b/contrib/plugins/execlog.c
> index e659ac9cbb..b5360f2c8e 100644
> --- a/contrib/plugins/execlog.c
> +++ b/contrib/plugins/execlog.c
> @@ -147,6 +147,9 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
>               /* Register callback on instruction */
>               qemu_plugin_register_vcpu_insn_exec_cb(insn, vcpu_insn_exec,
>                                                      QEMU_PLUGIN_CB_NO_REGS, output);
> +
> +            /* reset skip */
> +            skip = (imatches || amatches) ? true : false;

Drop the redundant ?:.  Otherwise,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2022-09-28 23:01 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-21 16:07 [PATCH v1 00/10] plugins/next (disas, monitor, docs, execlog) Alex Bennée
2022-09-21 16:07 ` [PATCH v1 01/10] monitor: expose monitor_puts to rest of code Alex Bennée
2022-09-21 17:34   ` Philippe Mathieu-Daudé via
2022-09-22  4:30   ` Markus Armbruster
2022-09-22 15:06   ` Kevin Wolf
2022-09-21 16:07 ` [PATCH v1 02/10] disas: generalise plugin_printf and use for monitor_disas Alex Bennée
2022-09-21 16:07 ` [PATCH v1 03/10] disas: use result of ->read_memory_func Alex Bennée
2022-09-21 17:37   ` Philippe Mathieu-Daudé via
2022-09-21 16:07 ` [PATCH v1 04/10] tests/tcg: add memory-sve test for aarch64 Alex Bennée
2022-09-28 22:54   ` Richard Henderson
2022-09-21 16:07 ` [PATCH v1 05/10] plugins: extend execlog to filter matches Alex Bennée
2022-09-21 16:07 ` [PATCH v1 06/10] plugins: Assert mmu_idx in range before use in qemu_plugin_get_hwaddr Alex Bennée
2022-09-21 17:40   ` Philippe Mathieu-Daudé via
2022-09-21 16:07 ` [PATCH v1 07/10] docs/devel: clean-up qemu invocations in tcg-plugins Alex Bennée
2022-09-21 17:39   ` Philippe Mathieu-Daudé via
2022-09-21 16:07 ` [PATCH v1 08/10] docs/devel: move API to end of tcg-plugins.rst Alex Bennée
2022-09-21 17:39   ` Philippe Mathieu-Daudé via
2022-09-21 16:08 ` [PATCH v1 09/10] contrib/plugins: reset skip when matching in execlog Alex Bennée
2022-09-21 17:38   ` Philippe Mathieu-Daudé via
2022-09-28 22:59   ` Richard Henderson
2022-09-21 16:08 ` [PATCH v1 10/10] docs/devel: document the test plugins Alex Bennée

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.