From patchwork Tue May 19 02:53:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 186917 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp3448766ilb; Mon, 18 May 2020 20:00:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxaOLSPdHdqXF2ZdQAPlwtpkAyv/+INuPbenh5Aik1vjBuhqaEnCCThE6TDlKkGm7lQd3oE X-Received: by 2002:a37:8e45:: with SMTP id q66mr19091546qkd.497.1589857206341; Mon, 18 May 2020 20:00:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589857206; cv=none; d=google.com; s=arc-20160816; b=EYU9ZeY8mcZAA86T/iHZZqxBAg7oY+jICeAFn89IX0SAbrzzH1ftiamvgGC0wsm5ly x7AGwjdFdYmxz35DTF93qEZK6zqj+mLfVZy2ZtvcVUSMvAxFAvMC7UMI8XwWml5+MDM9 TcpSkodGuAIpE/2bcoQY+E+HO1AaRUxsroAkaeKrMCeGJ+WkzxfhZ9zXwpDF1vkGTI9f OT+7+7B+vfg/7ufIxjiXtb8bVqdz72CxVImx8W+nP8T1IxhqSx53Wf8BQiw2d2INznYh KbNzlbYPag2kdjywJNSAyVuCBvblESokxZKZAkiQZDRaq66BS2JeQrQjLgc7/jKCpLqo QV5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=ryftU8k2hkpE8SBKJnjLqyziikg8zbnLkzl+yDCUuSA=; b=LknFt6dsmJF3tWjqf5bmTFerURAGazbh8kUThCMBZALacj3x0XMiPTM3K/V3OqatKX vCyRFlgO9fN4YS3JEyLxRq0sBqOef6PS3TyWs9AYa3aO1ftZE8fQ3e0LMOHREb4Mb6UJ zJ5oZF0ThSyujNY16VUejuLBh3ZLjPNwVC2iIbYeyt3atJxmUzpvrffwdq18MwNA5Q72 jTK0VhXveCKunDhxgbWrx3RBF7X/mluep2FJK8sokeuVoSxSIh1H0GkoXawRn4MJD2lE b1K8WXgJ9D7fAFuwRXt5IyGRHyCvB7lwfnq3OOjCnrDTsOYQWCpwRWANxwq/3FHHmgIS hAcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=im9OAiLa; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id 13si6607171qka.296.2020.05.18.20.00.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 May 2020 20:00:06 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=im9OAiLa; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:56798 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jasU9-0000gl-K6 for patch@linaro.org; Mon, 18 May 2020 23:00:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46902) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jasOZ-0005ap-9G for qemu-devel@nongnu.org; Mon, 18 May 2020 22:54:19 -0400 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]:46372) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jasOX-0002Ur-N1 for qemu-devel@nongnu.org; Mon, 18 May 2020 22:54:18 -0400 Received: by mail-pg1-x534.google.com with SMTP id p21so5721614pgm.13 for ; Mon, 18 May 2020 19:54:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ryftU8k2hkpE8SBKJnjLqyziikg8zbnLkzl+yDCUuSA=; b=im9OAiLamHIqOafI3tQsbysVXK8ot/8ZbuSUFqTn9R6Rb+StXyuOfV7yA+4Eu2x4lm mYeTJggiGdxC1GfX9Og90vqS4XXvwxpu3Q9rBP5yA5QKAup7/oLB6y8XSFweP+T4BF8f P0JckyFsavmmG0KbZWuTO8RmTH4uVg31dypak3+BEbtXbR4l33cKOemnLiA9G7BxrLKB bWVKQassqREJEzsF2J1T1keHfG1V7YxGwMdGJNayTc08P8+UI7Zrp3+7pOt9GvNonnBp FoqjzjDvrR9lPE3BR4lVzfp+fXcvgm31xjb+dk2bjE0gUYzAX+buYeMCynkTJYuG2Y80 vG5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ryftU8k2hkpE8SBKJnjLqyziikg8zbnLkzl+yDCUuSA=; b=FKUDOjn/G2EzLdMUj7HmSNak8XWjcJavSmvqQp+VG3rHHDG81ZX+4ltH3G4vmWOznE SVB/Jj7VUjtMR93UO6UjRtHZPyZkwMwg+It+VyOM7GZ97cjFUn67qVr/CtfHIGve5ere vbEoo970pNFfpbZx4sE0WXjCUOUoD1Fh2bkCYfwO7afHFUwCfi47+/5VJN+2rA/Ac7xW HZbUCgQTaz9OkZc7YS/aWgjAV0yNw6hWBd6niP+b5dTiCgwoCWZHTMfTpYorTBNs+uGf AvDMmx7kMuG2r5M2LL8Zd/8MJk4tZ60lGvGgwZyp9rweqlVygCi0M1gMMvwRDtLFivUn s9wA== X-Gm-Message-State: AOAM530Rgc7rlKerVFL0Aj2e4mMqOYtaGn/uWtgqRw56GhrpbItx4COq NZFIu2G7MCcZtzI3WWxUU4kHsEbBGNI= X-Received: by 2002:a63:f90a:: with SMTP id h10mr17788269pgi.57.1589856855815; Mon, 18 May 2020 19:54:15 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id a2sm8772418pgh.57.2020.05.18.19.54.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 19:54:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [RISU v2 14/17] Add magic and size to the trace header Date: Mon, 18 May 2020 19:53:52 -0700 Message-Id: <20200519025355.4420-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200519025355.4420-1-richard.henderson@linaro.org> References: <20200519025355.4420-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::534; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x534.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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 --- risu.h | 8 ++- reginfo.c | 160 ++++++++++++++++++++++++++++++++++++++++++++---------- risu.c | 6 ++ 3 files changed, 143 insertions(+), 31 deletions(-) -- 2.20.1 diff --git a/risu.h b/risu.h index b234f93..eeb6775 100644 --- a/risu.h +++ b/risu.h @@ -56,6 +56,7 @@ typedef enum { RES_END, RES_MISMATCH_REG, RES_MISMATCH_MEM, + RES_MISMATCH_HEAD, RES_BAD_IO, } RisuResult; @@ -70,10 +71,14 @@ typedef enum { 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') + /* Socket related routines */ int master_connect(int port); int apprentice_connect(const char *hostname, int port); @@ -111,6 +116,7 @@ RisuResult recv_and_compare_register_info(void *uc); * done in recv_and_compare_register_info(). */ void report_mismatch_reg(void); +void report_mismatch_header(void); /* Interface provided by CPU-specific code: */ diff --git a/reginfo.c b/reginfo.c index a007f16..f187d9c 100644 --- a/reginfo.c +++ b/reginfo.c @@ -16,6 +16,7 @@ static struct reginfo master_ri, apprentice_ri; static uint8_t master_memblock[MEMBLOCKLEN]; +static trace_header_t master_header; RisuResult send_register_info(void *uc) { @@ -23,32 +24,57 @@ RisuResult send_register_info(void *uc) trace_header_t header; RisuResult res; RisuOp 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: + case OP_SIGILL: + 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; + + default: + abort(); + } + res = write_buffer(&header, sizeof(header)); if (res != RES_OK) { return res; } + if (extra) { + res = write_buffer(extra, header.size); + if (res != RES_OK) { + return res; + } + } switch (op) { case OP_COMPARE: - case OP_TESTEND: case OP_SIGILL: - /* - * Do a simple register compare on (a) explicit request - * (b) end of test (c) a non-risuop UNDEF - */ - res = write_buffer(&ri, reginfo_size()); - /* For OP_TEST_END, force exit. */ - if (res == RES_OK && op == OP_TESTEND) { - res = RES_END; - } + case OP_COMPAREMEM: break; + case OP_TESTEND: + return RES_END; case OP_SETMEMBLOCK: memblock = (void *)(uintptr_t)get_reginfo_paramreg(&ri); break; @@ -56,12 +82,10 @@ RisuResult send_register_info(void *uc) set_ucontext_paramreg(uc, get_reginfo_paramreg(&ri) + (uintptr_t)memblock); break; - case OP_COMPAREMEM: - return write_buffer(memblock, MEMBLOCKLEN); default: abort(); } - return res; + return RES_OK; } /* Read register info from the socket and compare it with that from the @@ -75,34 +99,48 @@ RisuResult send_register_info(void *uc) RisuResult recv_and_compare_register_info(void *uc) { RisuResult res; - trace_header_t header; + size_t extra_size; RisuOp op; reginfo_init(&apprentice_ri, uc); op = get_risuop(&apprentice_ri); - res = read_buffer(&header, sizeof(header)); - if (res != RES_OK) { - return res; + switch (op) { + case OP_TESTEND: + case OP_COMPARE: + case OP_SIGILL: + extra_size = reginfo_size(); + break; + case OP_SETMEMBLOCK: + case OP_GETMEMBLOCK: + extra_size = 0; + break; + case OP_COMPAREMEM: + extra_size = MEMBLOCKLEN; + break; + default: + abort(); } - if (header.risu_op != op) { - /* We are out of sync. Tell master to exit. */ - respond(RES_END); - return RES_BAD_IO; + res = read_buffer(&master_header, sizeof(master_header)); + if (res != RES_OK) { + goto fail_header; + } + if (master_header.magic != RISU_MAGIC || + master_header.risu_op != op || + master_header.size != extra_size) { + res = RES_MISMATCH_HEAD; + goto fail_header; } /* send OK for the header */ respond(RES_OK); switch (op) { - case OP_COMPARE: case OP_TESTEND: + case OP_COMPARE: case OP_SIGILL: - /* Do a simple register compare on (a) explicit request - * (b) end of test (c) a non-risuop UNDEF - */ - res = read_buffer(&master_ri, reginfo_size()); + res = read_buffer(&master_ri, extra_size); if (res != RES_OK) { /* fail */ } else if (!reginfo_is_eq(&master_ri, &apprentice_ri)) { @@ -111,15 +149,17 @@ RisuResult recv_and_compare_register_info(void *uc) } else if (op == OP_TESTEND) { res = RES_END; } - respond(res == RES_OK ? RES_OK : RES_END); break; + case OP_SETMEMBLOCK: memblock = (void *)(uintptr_t)get_reginfo_paramreg(&apprentice_ri); - break; + return RES_OK; + case OP_GETMEMBLOCK: set_ucontext_paramreg(uc, get_reginfo_paramreg(&apprentice_ri) + (uintptr_t)memblock); - break; + return RES_OK; + case OP_COMPAREMEM: res = read_buffer(master_memblock, MEMBLOCKLEN); if (res != RES_OK) { @@ -128,12 +168,14 @@ RisuResult recv_and_compare_register_info(void *uc) /* memory mismatch */ res = RES_MISMATCH_MEM; } - respond(res == RES_OK ? RES_OK : RES_END); break; + default: abort(); } + fail_header: + respond(res == RES_OK ? RES_OK : RES_END); return res; } @@ -149,3 +191,61 @@ void report_mismatch_reg(void) reginfo_dump(&apprentice_ri, stderr); reginfo_dump_mismatch(&master_ri, &apprentice_ri, stderr); } + +void report_mismatch_header(void) +{ + fprintf(stderr, "header mismatch detail (master : apprentice):\n"); + if (master_header.magic != RISU_MAGIC) { + fprintf(stderr, " magic: %08x vs %08x\n", + master_header.magic, RISU_MAGIC); + /* If the magic number is wrong, everything else is garbage too. */ + return; + } + + RisuOp a_op = get_risuop(&apprentice_ri); + RisuOp m_op = master_header.risu_op; + if (a_op != m_op) { + fprintf(stderr, " op : %d != %d\n", m_op, a_op); + /* If the opcode is mismatched, we can't compute size. */ + } else { + const char *kind; + size_t m_sz = master_header.size; + size_t a_sz; + + switch (a_op) { + case OP_TESTEND: + case OP_COMPARE: + case OP_SIGILL: + kind = "reginfo"; + a_sz = reginfo_size(); + break; + case OP_SETMEMBLOCK: + case OP_GETMEMBLOCK: + kind = "unexpected"; + a_sz = 0; + break; + case OP_COMPAREMEM: + kind = "memblock"; + a_sz = MEMBLOCKLEN; + break; + default: + abort(); + } + if (a_sz != m_sz) { + fprintf(stderr, " size : %zd != %zd (%s)\n", + m_sz, a_sz, kind); + } else { + /* If magic, op, and size are the same, how did we get here? */ + abort(); + } + } + + uint64_t a_pc = get_pc(&apprentice_ri); + uint64_t m_pc = master_header.pc; + if (a_pc != m_pc) { + fprintf(stderr, " pc : %016" PRIx64 " vs %016" PRIx64 "\n", + m_pc, a_pc); + } else { + fprintf(stderr, " pc : %016" PRIx64 "\n", a_pc); + } +} diff --git a/risu.c b/risu.c index 398faac..95b4674 100644 --- a/risu.c +++ b/risu.c @@ -233,6 +233,12 @@ static int apprentice(void) fprintf(stderr, "mismatch mem after %zd checkpoints\n", signal_count); return EXIT_FAILURE; + case RES_MISMATCH_HEAD: + fprintf(stderr, "mismatch header after %zd checkpoints\n", + signal_count); + report_mismatch_header(); + return EXIT_FAILURE; + case RES_BAD_IO: fprintf(stderr, "i/o error after %zd checkpoints\n", signal_count); return EXIT_FAILURE;