From patchwork Wed May 13 18:09:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 186691 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp689448ilb; Wed, 13 May 2020 11:18:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUYq3qPz8x3QJCXUW9SgX6IjfxA7NxLLDXj7dh/xeWKqS8bmtGj/c3Ib/eByn0icieJa4P X-Received: by 2002:ac8:6b19:: with SMTP id w25mr391829qts.147.1589393886178; Wed, 13 May 2020 11:18:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589393886; cv=none; d=google.com; s=arc-20160816; b=B7Gg2xb60ugd5AOPrFkDErs/z1fWhq7FWx/1aiOfYIzrj/AhO+G4ecMsKzdmy4aA3b WCyw+u7XDxLM60KbIDFtQG0ZrJD/NbtcNCxRg2TifRP6nS1TCJReqfhWnevhtgJszP05 hQ8cicNh9YAM5NJkEc12wH8p9c0eFdzldyUGVVc9Fy7/77gBm5vGT/mQzyWi49yZ0aRl a2BcTWcX4qNWH0/6HUZTNZ+VJl79DtrwtxLHjf0aJ4AEzuPCmlwl+sQwTwj200lT52Fy NtAuKBMDj0WfHdj2Pu0YCwQdushqoN+5cPQid45MCISf2YmAkwUTDsvpME3ulpr5tZbk tZ5A== 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=JSmowOO+YiAA0eSN0s8xOlbrTguVMlQ6LjWvJ71pNA4=; b=u3U/LfxaEp2t2z/8kqam/lZJhlJUMMXfI6TP7+v0g9TM1E9pj0ex6wpUpQQTq7xKWl oKNZMN2iPjYlejNPmHzxp8r3Tb2gxXSiC2Tl9iDzYq212xzb5XAx1PdM7PGiGsFG4wVY WQgUK7nwzAvw5hvgbPSQ4GlyKPzmWft3iZRCdPeb9G/Ybgt/LUE53RCRIaS2Gjgp1Nrb 6sSzUFb2yiPdC+qSvhCYGwyB4BTPKnFMU50n4jbz0UZ12o5q7GZO6n6YkAdtRTqJkDoR 5zOqP+8/6pQQt+hoLx+JE4YXVULpqjzmXZ+dpV3MRc/dGW/mY/7RK+cxy1VEZYek2ger xItA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uRuXKhan; 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 e22si178606qvf.81.2020.05.13.11.18.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 May 2020 11:18: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=uRuXKhan; 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]:49218 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jYvxF-0007Lj-J4 for patch@linaro.org; Wed, 13 May 2020 14:18:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36440) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jYvpZ-0003qA-QU for qemu-devel@nongnu.org; Wed, 13 May 2020 14:10:09 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]:42175) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jYvpW-0000Me-E1 for qemu-devel@nongnu.org; Wed, 13 May 2020 14:10:09 -0400 Received: by mail-pl1-x62a.google.com with SMTP id k19so136966pll.9 for ; Wed, 13 May 2020 11:10:05 -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=JSmowOO+YiAA0eSN0s8xOlbrTguVMlQ6LjWvJ71pNA4=; b=uRuXKhanODepsH+nLE0Bb8fz3ZKAZFQjhC1YneZy2V5DmXo9Afaj/r790teAy/xf4P qEX9WC/A+s00ibSqa2gk2EDgt3CJzKts3E1vXGhdTnqjlO4rVwKTC1lZp0EZrs31nDC9 YW6msOereGCOEgUxgkrQZssyah5L+Zd0XJRgmr/OHQ8S9JOtAmLVTtsrdvb2vyJNA8V9 QQy36j+xLsHIkeGZsYTED/iAj8U5rSKIQ9AUIsHOtj8yVDAzmVmVjnrKdR//scCYcJ9g eO9W8jodpSbuXG38j2sK4P1sM+TzNt/EgncxOCtQuIHPaFFAfOhIaU1LP/UBKaWjSHZ3 2ZlQ== 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=JSmowOO+YiAA0eSN0s8xOlbrTguVMlQ6LjWvJ71pNA4=; b=JvvGSQ94vva7VwMMK5vxRRk9RRrcW/f0OOKNqK2RciedXs7i6Ngtr6rqWA/rE1h+ZI gG3u+0QVxAm+JFTZCnFMJC5IqtiEmbL1s9lTbYE9Pb2XL3rO2V3wWHSjwqJAvnhCZB7W YZdF9KcTdUURENOSpaxdIevymAUDkS/OOMKgMV3fBKbBC6EAGqn9SibY0Sixowa4mplL O4qIu7eWJ2nvjtZWTPCEA7HO8KR29fxjDdLAtm2S+Jx4p89OyGa7dimmWUvYzUllJjed Sn4E3B3/8tMP0w1nIRQEKCBYMAphsmE217cVhRs6uWPK4Me4ZK05vkSQr2WJ0DGV/kiR 5EDQ== X-Gm-Message-State: AOAM531HSTl/sOSv8eOeE/sAoFvUcH0S/Fj8FL1BhXQrdZRM1FfutTkZ ALHYRJsU685Xmjp6SLYkIplPDPnC50o= X-Received: by 2002:a17:90a:be09:: with SMTP id a9mr2678962pjs.165.1589393403834; Wed, 13 May 2020 11:10:03 -0700 (PDT) Received: from localhost.localdomain (174-21-143-238.tukw.qwest.net. [174.21.143.238]) by smtp.gmail.com with ESMTPSA id i185sm197361pfg.14.2020.05.13.11.10.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2020 11:10:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [RISU 6/9] Add magic and size to the trace header Date: Wed, 13 May 2020 11:09:50 -0700 Message-Id: <20200513180953.20376-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200513180953.20376-1-richard.henderson@linaro.org> References: <20200513180953.20376-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62a; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62a.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 | 6 +++++- reginfo.c | 42 ++++++++++++++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 11 deletions(-) -- 2.20.1 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) {