All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, alex.bennee@linaro.org
Subject: [RISU 6/9] Add magic and size to the trace header
Date: Wed, 13 May 2020 11:09:50 -0700	[thread overview]
Message-ID: <20200513180953.20376-7-richard.henderson@linaro.org> (raw)
In-Reply-To: <20200513180953.20376-1-richard.henderson@linaro.org>

Sanity check that we're not getting out of sync with
the trace stream.  This will be especially bad with
the change in size of the sve save data.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 risu.h    |  6 +++++-
 reginfo.c | 42 ++++++++++++++++++++++++++++++++----------
 2 files changed, 37 insertions(+), 11 deletions(-)

diff --git a/risu.h b/risu.h
index e2b4508..3fc198f 100644
--- a/risu.h
+++ b/risu.h
@@ -62,10 +62,14 @@ extern void *memblock;
 struct reginfo;
 
 typedef struct {
-   uintptr_t pc;
+   uint32_t magic;
+   uint32_t size;
    uint32_t risu_op;
+   uintptr_t pc;
 } trace_header_t;
 
+#define RISU_MAGIC  (('R' << 24) | ('i' << 16) | ('S' << 8) | 'u')
+
 /* Functions operating on reginfo */
 
 /* Function prototypes for read/write helper functions.
diff --git a/reginfo.c b/reginfo.c
index 1b2a821..a4f7da6 100644
--- a/reginfo.c
+++ b/reginfo.c
@@ -26,20 +26,45 @@ int send_register_info(write_fn write_fn, void *uc)
     struct reginfo ri;
     trace_header_t header;
     int op;
+    void *extra;
 
     reginfo_init(&ri, uc);
     op = get_risuop(&ri);
 
     /* Write a header with PC/op to keep in sync */
+    header.magic = RISU_MAGIC;
     header.pc = get_pc(&ri);
     header.risu_op = op;
+
+    switch (op) {
+    case OP_TESTEND:
+    case OP_COMPARE:
+    default:
+        header.size = reginfo_size();
+        extra = &ri;
+        break;
+
+    case OP_SETMEMBLOCK:
+    case OP_GETMEMBLOCK:
+        header.size = 0;
+        extra = NULL;
+        break;
+
+    case OP_COMPAREMEM:
+        header.size = MEMBLOCKLEN;
+        extra = memblock;
+        break;
+    }
+
     if (write_fn(&header, sizeof(header)) != 0) {
         return -1;
     }
+    if (extra && write_fn(extra, header.size) != 0) {
+        return -1;
+    }
 
     switch (op) {
     case OP_TESTEND:
-        write_fn(&ri, reginfo_size());
         /* if we are tracing write_fn will return 0 unlike a remote
            end, hence we force return of 1 here */
         return 1;
@@ -51,14 +76,9 @@ int send_register_info(write_fn write_fn, void *uc)
                               get_reginfo_paramreg(&ri) + (uintptr_t)memblock);
         break;
     case OP_COMPAREMEM:
-        return write_fn(memblock, MEMBLOCKLEN);
-        break;
     case OP_COMPARE:
     default:
-        /* Do a simple register compare on (a) explicit request
-         * (b) end of test (c) a non-risuop UNDEF
-         */
-        return write_fn(&ri, reginfo_size());
+        break;
     }
     return 0;
 }
@@ -84,7 +104,7 @@ int recv_and_compare_register_info(read_fn read_fn,
         return -1;
     }
 
-    if (header.risu_op != op) {
+    if (header.magic != RISU_MAGIC || header.risu_op != op) {
         /* We are out of sync */
         resp = 2;
         resp_fn(resp);
@@ -101,7 +121,8 @@ int recv_and_compare_register_info(read_fn read_fn,
         /* Do a simple register compare on (a) explicit request
          * (b) end of test (c) a non-risuop UNDEF
          */
-        if (read_fn(&apprentice_ri, reginfo_size())) {
+        if (header.size != reginfo_size() ||
+            read_fn(&apprentice_ri, header.size)) {
             packet_mismatch = 1;
             resp = 2;
         } else if (!reginfo_is_eq(&master_ri, &apprentice_ri)) {
@@ -121,7 +142,8 @@ int recv_and_compare_register_info(read_fn read_fn,
         break;
     case OP_COMPAREMEM:
         mem_used = 1;
-        if (read_fn(apprentice_memblock, MEMBLOCKLEN)) {
+        if (header.size != MEMBLOCKLEN ||
+            read_fn(apprentice_memblock, MEMBLOCKLEN)) {
             packet_mismatch = 1;
             resp = 2;
         } else if (memcmp(memblock, apprentice_memblock, MEMBLOCKLEN) != 0) {
-- 
2.20.1



  parent reply	other threads:[~2020-05-13 18:18 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-13 18:09 [RISU 0/9] risu cleanups and improvements Richard Henderson
2020-05-13 18:09 ` [RISU 1/9] Use bool for tracing variables Richard Henderson
2020-05-18 15:51   ` Peter Maydell
2020-05-13 18:09 ` [RISU 2/9] Unify master_fd and apprentice_fd to comm_fd Richard Henderson
2020-05-18 15:51   ` Peter Maydell
2020-05-13 18:09 ` [RISU 3/9] Hoist trace file opening Richard Henderson
2020-05-18 15:52   ` Peter Maydell
2020-05-13 18:09 ` [RISU 4/9] Adjust tracefile open for write Richard Henderson
2020-05-18 15:53   ` Peter Maydell
2020-05-13 18:09 ` [RISU 5/9] Use EXIT_FAILURE, EXIT_SUCCESS Richard Henderson
2020-05-18 15:54   ` Peter Maydell
2020-05-18 16:46     ` Richard Henderson
2020-05-13 18:09 ` Richard Henderson [this message]
2020-05-13 18:09 ` [RISU 7/9] Compute reginfo_size based on the reginfo Richard Henderson
2020-05-13 18:09 ` [RISU 8/9] aarch64: Reorg sve reginfo to save space Richard Henderson
2020-05-13 18:09 ` [RISU 9/9] Add --dump option to inspect trace files Richard Henderson
2020-05-18 18:39 ` [RISU 0/9] risu cleanups and improvements Peter Maydell
2020-05-18 19:14   ` Alex Bennée
2020-05-18 19:33   ` Richard Henderson
2020-05-18 19:43     ` Richard Henderson

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=20200513180953.20376-7-richard.henderson@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /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 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.