qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Lluís Vilanova" <vilanova@ac.upc.edu>,
	"Stefan Hajnoczi" <stefanha@redhat.com>
Subject: [Qemu-devel] [PULL 02/42] trace: [all] Add "guest_mem_before" event
Date: Fri, 17 Jun 2016 16:59:13 +0100	[thread overview]
Message-ID: <1466179193-11232-3-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1466179193-11232-1-git-send-email-stefanha@redhat.com>

From: Lluís Vilanova <vilanova@ac.upc.edu>

The event is described in "trace-events". Note that the "MO_AMASK" flag
is not traced, since it does not seem to affect the visible semantics of
instructions.

Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
Reviewed-by: Richard Henderson <rth@twiddle.net>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Message-id: 146549350711.18437.726780393247474362.stgit@fimbulvetr.bsc.es
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 include/exec/cpu_ldst_template.h          | 25 +++++++++++++++++
 include/exec/cpu_ldst_useronly_template.h | 22 +++++++++++++++
 tcg/tcg-op.c                              | 10 +++++++
 trace-events                              | 21 ++++++++++++++
 trace/mem-internal.h                      | 46 +++++++++++++++++++++++++++++++
 trace/mem.h                               | 34 +++++++++++++++++++++++
 6 files changed, 158 insertions(+)
 create mode 100644 trace/mem-internal.h
 create mode 100644 trace/mem.h

diff --git a/include/exec/cpu_ldst_template.h b/include/exec/cpu_ldst_template.h
index 3091c00..eaf69a1 100644
--- a/include/exec/cpu_ldst_template.h
+++ b/include/exec/cpu_ldst_template.h
@@ -23,6 +23,13 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
+
+#if !defined(SOFTMMU_CODE_ACCESS)
+#include "trace.h"
+#endif
+
+#include "trace/mem.h"
+
 #if DATA_SIZE == 8
 #define SUFFIX q
 #define USUFFIX q
@@ -80,6 +87,12 @@ glue(glue(glue(cpu_ld, USUFFIX), MEMSUFFIX), _ra)(CPUArchState *env,
     int mmu_idx;
     TCGMemOpIdx oi;
 
+#if !defined(SOFTMMU_CODE_ACCESS)
+    trace_guest_mem_before_exec(
+        ENV_GET_CPU(env), ptr,
+        trace_mem_build_info(SHIFT, false, MO_TE, false));
+#endif
+
     addr = ptr;
     page_index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
     mmu_idx = CPU_MMU_INDEX;
@@ -112,6 +125,12 @@ glue(glue(glue(cpu_lds, SUFFIX), MEMSUFFIX), _ra)(CPUArchState *env,
     int mmu_idx;
     TCGMemOpIdx oi;
 
+#if !defined(SOFTMMU_CODE_ACCESS)
+    trace_guest_mem_before_exec(
+        ENV_GET_CPU(env), ptr,
+        trace_mem_build_info(SHIFT, true, MO_TE, false));
+#endif
+
     addr = ptr;
     page_index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
     mmu_idx = CPU_MMU_INDEX;
@@ -148,6 +167,12 @@ glue(glue(glue(cpu_st, SUFFIX), MEMSUFFIX), _ra)(CPUArchState *env,
     int mmu_idx;
     TCGMemOpIdx oi;
 
+#if !defined(SOFTMMU_CODE_ACCESS)
+    trace_guest_mem_before_exec(
+        ENV_GET_CPU(env), ptr,
+        trace_mem_build_info(SHIFT, false, MO_TE, true));
+#endif
+
     addr = ptr;
     page_index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1);
     mmu_idx = CPU_MMU_INDEX;
diff --git a/include/exec/cpu_ldst_useronly_template.h b/include/exec/cpu_ldst_useronly_template.h
index 040b147..b1378bf 100644
--- a/include/exec/cpu_ldst_useronly_template.h
+++ b/include/exec/cpu_ldst_useronly_template.h
@@ -22,6 +22,13 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
+
+#if !defined(CODE_ACCESS)
+#include "trace.h"
+#endif
+
+#include "trace/mem.h"
+
 #if DATA_SIZE == 8
 #define SUFFIX q
 #define USUFFIX q
@@ -53,6 +60,11 @@
 static inline RES_TYPE
 glue(glue(cpu_ld, USUFFIX), MEMSUFFIX)(CPUArchState *env, target_ulong ptr)
 {
+#if !defined(CODE_ACCESS)
+    trace_guest_mem_before_exec(
+        ENV_GET_CPU(env), ptr,
+        trace_mem_build_info(DATA_SIZE, false, MO_TE, false));
+#endif
     return glue(glue(ld, USUFFIX), _p)(g2h(ptr));
 }
 
@@ -68,6 +80,11 @@ glue(glue(glue(cpu_ld, USUFFIX), MEMSUFFIX), _ra)(CPUArchState *env,
 static inline int
 glue(glue(cpu_lds, SUFFIX), MEMSUFFIX)(CPUArchState *env, target_ulong ptr)
 {
+#if !defined(CODE_ACCESS)
+    trace_guest_mem_before_exec(
+        ENV_GET_CPU(env), ptr,
+        trace_mem_build_info(DATA_SIZE, true, MO_TE, false));
+#endif
     return glue(glue(lds, SUFFIX), _p)(g2h(ptr));
 }
 
@@ -85,6 +102,11 @@ static inline void
 glue(glue(cpu_st, SUFFIX), MEMSUFFIX)(CPUArchState *env, target_ulong ptr,
                                       RES_TYPE v)
 {
+#if !defined(CODE_ACCESS)
+    trace_guest_mem_before_exec(
+        ENV_GET_CPU(env), ptr,
+        trace_mem_build_info(DATA_SIZE, false, MO_TE, true));
+#endif
     glue(glue(st, SUFFIX), _p)(g2h(ptr), v);
 }
 
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 54c0277..569cdc6 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -28,6 +28,8 @@
 #include "exec/exec-all.h"
 #include "tcg.h"
 #include "tcg-op.h"
+#include "trace-tcg.h"
+#include "trace/mem.h"
 
 /* Reduce the number of ifdefs below.  This assumes that all uses of
    TCGV_HIGH and TCGV_LOW are properly protected by a conditional that
@@ -1910,12 +1912,16 @@ static void gen_ldst_i64(TCGOpcode opc, TCGv_i64 val, TCGv addr,
 void tcg_gen_qemu_ld_i32(TCGv_i32 val, TCGv addr, TCGArg idx, TCGMemOp memop)
 {
     memop = tcg_canonicalize_memop(memop, 0, 0);
+    trace_guest_mem_before_tcg(tcg_ctx.cpu, tcg_ctx.tcg_env,
+                               addr, trace_mem_get_info(memop, 0));
     gen_ldst_i32(INDEX_op_qemu_ld_i32, val, addr, memop, idx);
 }
 
 void tcg_gen_qemu_st_i32(TCGv_i32 val, TCGv addr, TCGArg idx, TCGMemOp memop)
 {
     memop = tcg_canonicalize_memop(memop, 0, 1);
+    trace_guest_mem_before_tcg(tcg_ctx.cpu, tcg_ctx.tcg_env,
+                               addr, trace_mem_get_info(memop, 1));
     gen_ldst_i32(INDEX_op_qemu_st_i32, val, addr, memop, idx);
 }
 
@@ -1932,6 +1938,8 @@ void tcg_gen_qemu_ld_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop)
     }
 
     memop = tcg_canonicalize_memop(memop, 1, 0);
+    trace_guest_mem_before_tcg(tcg_ctx.cpu, tcg_ctx.tcg_env,
+                               addr, trace_mem_get_info(memop, 0));
     gen_ldst_i64(INDEX_op_qemu_ld_i64, val, addr, memop, idx);
 }
 
@@ -1943,5 +1951,7 @@ void tcg_gen_qemu_st_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop)
     }
 
     memop = tcg_canonicalize_memop(memop, 1, 1);
+    trace_guest_mem_before_tcg(tcg_ctx.cpu, tcg_ctx.tcg_env,
+                               addr, trace_mem_get_info(memop, 1));
     gen_ldst_i64(INDEX_op_qemu_st_i64, val, addr, memop, idx);
 }
diff --git a/trace-events b/trace-events
index 104b64f..de46b9d 100644
--- a/trace-events
+++ b/trace-events
@@ -2164,3 +2164,24 @@ e1000e_cfg_support_virtio(bool support) "Virtio header supported: %d"
 
 e1000e_vm_state_running(void) "VM state is running"
 e1000e_vm_state_stopped(void) "VM state is stopped"
+
+### Guest events, keep at bottom
+
+# @vaddr: Access' virtual address.
+# @info : Access' information (see below).
+#
+# Start virtual memory access (before any potential access violation).
+#
+# Does not include memory accesses performed by devices.
+#
+# Access information can be parsed as:
+#
+# struct mem_info {
+#     uint8_t size_shift : 2; /* interpreted as "1 << size_shift" bytes */
+#     bool    sign_extend: 1; /* sign-extended */
+#     uint8_t endianness : 1; /* 0: little, 1: big */
+#     bool    store      : 1; /* wheter it's a store operation */
+# };
+#
+# Targets: TCG(all)
+disable vcpu tcg guest_mem_before(TCGv vaddr, uint8_t info) "info=%d", "vaddr=0x%016"PRIx64" info=%d"
diff --git a/trace/mem-internal.h b/trace/mem-internal.h
new file mode 100644
index 0000000..d575bb3
--- /dev/null
+++ b/trace/mem-internal.h
@@ -0,0 +1,46 @@
+/*
+ * Helper functions for guest memory tracing
+ *
+ * Copyright (C) 2016 Lluís Vilanova <vilanova@ac.upc.edu>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef TRACE__MEM_INTERNAL_H
+#define TRACE__MEM_INTERNAL_H
+
+static inline uint8_t trace_mem_get_info(TCGMemOp op, bool store)
+{
+    uint8_t res = op;
+    bool be = (op & MO_BSWAP) == MO_BE;
+
+    /* remove untraced fields */
+    res &= (1ULL << 4) - 1;
+    /* make endianness absolute */
+    res &= ~MO_BSWAP;
+    if (be) {
+        res |= 1ULL << 3;
+    }
+    /* add fields */
+    if (store) {
+        res |= 1ULL << 4;
+    }
+
+    return res;
+}
+
+static inline inline uint8_t trace_mem_build_info(
+    TCGMemOp size, bool sign_extend, TCGMemOp endianness, bool store)
+{
+    uint8_t res = 0;
+    res |= size;
+    res |= (sign_extend << 2);
+    if (endianness == MO_BE) {
+        res |= (1ULL << 3);
+    }
+    res |= (store << 4);
+    return res;
+}
+
+#endif  /* TRACE__MEM_INTERNAL_H */
diff --git a/trace/mem.h b/trace/mem.h
new file mode 100644
index 0000000..c76a572
--- /dev/null
+++ b/trace/mem.h
@@ -0,0 +1,34 @@
+/*
+ * Helper functions for guest memory tracing
+ *
+ * Copyright (C) 2016 Lluís Vilanova <vilanova@ac.upc.edu>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef TRACE__MEM_H
+#define TRACE__MEM_H
+
+#include "tcg/tcg.h"
+
+
+/**
+ * trace_mem_get_info:
+ *
+ * Return a value for the 'info' argument in guest memory access traces.
+ */
+static uint8_t trace_mem_get_info(TCGMemOp op, bool store);
+
+/**
+ * trace_mem_build_info:
+ *
+ * Return a value for the 'info' argument in guest memory access traces.
+ */
+static uint8_t trace_mem_build_info(TCGMemOp size, bool sign_extend,
+                                    TCGMemOp endianness, bool store);
+
+
+#include "trace/mem-internal.h"
+
+#endif  /* TRACE__MEM_H */
-- 
2.5.5

  parent reply	other threads:[~2016-06-17 16:00 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-17 15:59 [Qemu-devel] [PULL 00/42] Tracing patches Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 01/42] exec: [tcg] Track which vCPU is performing translation and execution Stefan Hajnoczi
2016-06-17 15:59 ` Stefan Hajnoczi [this message]
2016-06-17 15:59 ` [Qemu-devel] [PULL 03/42] trace: add build framework for merging trace-events files Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 04/42] trace: split out trace events for util/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 05/42] trace: split out trace events for crypto/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 06/42] trace: split out trace events for io/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 07/42] trace: split out trace events for migration/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 08/42] trace: split out trace events for block/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 09/42] trace: split out trace events for hw/block/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 10/42] trace: split out trace events for hw/char/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 11/42] trace: split out trace events for hw/intc/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 12/42] trace: split out trace events for hw/net/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 13/42] trace: split out trace events for hw/virtio/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 14/42] trace: split out trace events for hw/audio/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 15/42] trace: split out trace events for hw/misc/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 16/42] trace: split out trace events for hw/usb/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 17/42] trace: split out trace events for hw/scsi/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 18/42] trace: split out trace events for hw/nvram/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 19/42] trace: split out trace events for hw/display/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 20/42] trace: split out trace events for hw/input/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 21/42] trace: split out trace events for hw/timer/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 22/42] trace: split out trace events for hw/dma/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 23/42] trace: split out trace events for hw/sparc/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 24/42] trace: split out trace events for hw/sd/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 25/42] trace: split out trace events for hw/isa/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 26/42] trace: split out trace events for hw/i386/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 27/42] trace: split out trace events for hw/9pfs/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 28/42] trace: split out trace events for hw/ppc/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 29/42] trace: split out trace events for hw/pci/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 30/42] trace: split out trace events for hw/s390x/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 31/42] trace: split out trace events for hw/vfio/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 32/42] trace: split out trace events for hw/acpi/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 33/42] trace: split out trace events for hw/arm/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 34/42] trace: split out trace events for hw/alpha/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 35/42] trace: split out trace events for ui/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 36/42] trace: split out trace events for audio/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 37/42] trace: split out trace events for net/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 38/42] trace: split out trace events for target-sparc/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 39/42] trace: split out trace events for target-s390x/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 40/42] trace: split out trace events for target-ppc/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 41/42] trace: split out trace events for qom/ directory Stefan Hajnoczi
2016-06-17 15:59 ` [Qemu-devel] [PULL 42/42] trace: split out trace events for linux-user/ directory Stefan Hajnoczi
2016-06-20  8:45 ` [Qemu-devel] [PULL 00/42] Tracing patches Peter Maydell
  -- strict thread matches above, loose matches on Subject: below --
2016-06-20 20:29 Stefan Hajnoczi
2016-06-20 20:29 ` [Qemu-devel] [PULL 02/42] trace: [all] Add "guest_mem_before" event Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1466179193-11232-3-git-send-email-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vilanova@ac.upc.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).