From patchwork Mon Jun 19 10:46:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 105822 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp810518qgd; Mon, 19 Jun 2017 03:51:21 -0700 (PDT) X-Received: by 10.176.95.197 with SMTP id g5mr4615858uaj.71.1497869481306; Mon, 19 Jun 2017 03:51:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497869481; cv=none; d=google.com; s=arc-20160816; b=DQWFQSXZ9d7/JlsVc7q6vc75viTGwtW+0qoNNr7Bvw8Nd9fmeC12T2k+Zi1toGCYgk WWpUqXmggjsSBXiQiyvODjIIC/DCUvh70KA0LNEWMqZNujCKz1PSAGiMaE6lnj2On5yD HDAd8x56tDkook5YmHXBTrhOFUj1+pQx5LJdLQj9HoQbJIH4IGeudAhEXn8Nok5p/mxj AHvroebPM6rmrh0peh5Y2QyGBUeFA/14MToK8YBOt6CsOaB7FHq4etrWfqCcRXmE8iR/ XYlKx8Q5em9NenWSpSkfGfOiifGF0TWrbrRgtM73xAcp3ZNs8N0DCFSm/7UAvbrYfBjp 6w8g== 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:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=TBIRtBraaZUoWYnyV2EFHQ+IcMfM6qc8m1AGLo5N1X4=; b=Ai9OGb8or/82zAsQup2MoCU1LUYE9DyRu/V9cfR/dOEKtYo8UEcnum6TrOm8B8fFpl oCafDA6YV3cJa4uPW2An/mi6W/OA17nfNGYv9bzym6VJ10vmTOwNrMU0Vn4r1/fUKJW8 yEJ3IpeIfviC3F93nJyVg+VhqjkFy9DVr/AjxI+AFqDovAtNHk4y3BZWHWIu2CXNLi7x OSsSklBJfFYNPUaqcvujYzdNyP0u9fL9oMuYwMyE6cuw+PJxX+SZoBslj9LIo9IAAiZN kqm1H9XOQgGYcS22QQvJMaK1N3ZWjSSdfzGEPAUPgl5GDOOGVwtU/cj5GkAaVIG+og28 ro8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.b=ExelOIS0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id p22si5314803uah.107.2017.06.19.03.51.21 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 19 Jun 2017 03:51:21 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.b=ExelOIS0; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:41668 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dMuHA-0002qW-Pk for patch@linaro.org; Mon, 19 Jun 2017 06:51:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40721) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dMuCT-0007Lo-ED for qemu-devel@nongnu.org; Mon, 19 Jun 2017 06:46:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dMuCS-0004tY-6L for qemu-devel@nongnu.org; Mon, 19 Jun 2017 06:46:29 -0400 Received: from mail-wr0-x22a.google.com ([2a00:1450:400c:c0c::22a]:34411) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dMuCR-0004su-TK for qemu-devel@nongnu.org; Mon, 19 Jun 2017 06:46:28 -0400 Received: by mail-wr0-x22a.google.com with SMTP id 77so69495261wrb.1 for ; Mon, 19 Jun 2017 03:46:27 -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=TBIRtBraaZUoWYnyV2EFHQ+IcMfM6qc8m1AGLo5N1X4=; b=ExelOIS0OcleU5avgD5I3iPr/7lBPtgEe8t6Qeuf6CHT6gF8zF1dbsiw8BW7JOzvgF wx8Sx2xhXcf8RoKR+ImiMabuIbv3IAHKX/kuA+FzniXQLlErkRAQXhLOCoGx+KTs+kqu TstJM3xXe4IsdMEX5P8r89YyUzbVEpIuFAGIM= 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=TBIRtBraaZUoWYnyV2EFHQ+IcMfM6qc8m1AGLo5N1X4=; b=s9rNJrS6w00eaYSTlReVRAHg8CR1SWaqByingmTtqFIvfYWPiYM55r5J7qAz/THJ4x dMHW/jVam5YyHiT7fESo/oGMbyZQCYnFExfKT68IzVAW1gXPkedw3H6RATF9m/+QGXXH CnVu7BQVCeyr/JpZb31aT/K+V7nrLh9oOeIsCAWARNOHVDDlU7Wb0yx0RCE8llsn1ouc 77lG32Qd3ko9zwoxBKeBHfp4LHT3/YshncF1xR0sIiOyJjCY9IkZFXLn5DZHW73vfu+P mUpX1h/kCLzj/lDJrDEEp2vXLH/j6Sr8HMZlTgYS+sop6gR0PuzHMqTB/3PVFmKqdBev 5lew== X-Gm-Message-State: AKS2vOxK0mni/55O3pp84SsvCHrmwVtgLZ7k8ahWjeOEJbUUrWnCJ0TV w6pEmrLMEUHvyIBZ X-Received: by 10.223.167.15 with SMTP id c15mr17784668wrd.79.1497869186724; Mon, 19 Jun 2017 03:46:26 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 139sm11629578wmw.15.2017.06.19.03.46.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Jun 2017 03:46:23 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 5D38F3E0BD4; Mon, 19 Jun 2017 11:47:00 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Mon, 19 Jun 2017 11:46:49 +0100 Message-Id: <20170619104655.31104-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170619104655.31104-1-alex.bennee@linaro.org> References: <20170619104655.31104-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22a Subject: [Qemu-devel] [RISU PATCH v5 07/13] risu: paramterise send/receive functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This is a precursor to record/playback support. Instead of passing the socket fd we now pass helper functions for reading/writing and responding. This will allow us to do the rest of the record/playback cleanly outside of the main worker function. Signed-off-by: Alex Bennée --- v5 - re-base without tab/format cleanps v4 - split header code - fix formatting foo-bar's v3 - new for v3 - arm, aarch64, ppc64 --- reginfo.c | 39 +++++++++++++++++++-------------------- risu.c | 23 +++++++++++++++++++++-- risu.h | 11 +++++++++-- 3 files changed, 49 insertions(+), 24 deletions(-) -- 2.13.0 diff --git a/reginfo.c b/reginfo.c index 31bb99f..90cea8f 100644 --- a/reginfo.c +++ b/reginfo.c @@ -21,7 +21,7 @@ uint8_t apprentice_memblock[MEMBLOCKLEN]; static int mem_used; static int packet_mismatch; -int send_register_info(int sock, void *uc) +int send_register_info(write_fn write_fn, void *uc) { struct reginfo ri; int op; @@ -29,24 +29,25 @@ int send_register_info(int sock, void *uc) op = get_risuop(&ri); switch (op) { - case OP_COMPARE: case OP_TESTEND: - default: - /* Do a simple register compare on (a) explicit request - * (b) end of test (c) a non-risuop UNDEF - */ - return send_data_pkt(sock, &ri, sizeof(ri)); + write_fn(&ri, sizeof(ri)); + return 1; case OP_SETMEMBLOCK: - memblock = (void *) (uintptr_t) get_reginfo_paramreg(&ri); + memblock = (void *)(uintptr_t)get_reginfo_paramreg(&ri); break; case OP_GETMEMBLOCK: set_ucontext_paramreg(uc, - get_reginfo_paramreg(&ri) + - (uintptr_t) memblock); + get_reginfo_paramreg(&ri) + (uintptr_t)memblock); break; case OP_COMPAREMEM: - return send_data_pkt(sock, memblock, MEMBLOCKLEN); + 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, sizeof(ri)); } return 0; } @@ -59,7 +60,7 @@ int send_register_info(int sock, void *uc) * that says whether it is register or memory data, so if the two * sides get out of sync then we will fail obscurely. */ -int recv_and_compare_register_info(int sock, void *uc) +int recv_and_compare_register_info(read_fn read_fn, respond_fn resp_fn, void *uc) { int resp = 0, op; @@ -73,36 +74,34 @@ int recv_and_compare_register_info(int sock, void *uc) /* Do a simple register compare on (a) explicit request * (b) end of test (c) a non-risuop UNDEF */ - if (recv_data_pkt(sock, &apprentice_ri, sizeof(apprentice_ri))) { + if (read_fn(&apprentice_ri, sizeof(apprentice_ri))) { packet_mismatch = 1; resp = 2; - } else if (!reginfo_is_eq(&master_ri, &apprentice_ri)) { /* register mismatch */ resp = 2; - } else if (op == OP_TESTEND) { resp = 1; } - send_response_byte(sock, resp); + resp_fn(resp); break; case OP_SETMEMBLOCK: - memblock = (void *) (uintptr_t) get_reginfo_paramreg(&master_ri); + memblock = (void *)(uintptr_t)get_reginfo_paramreg(&master_ri); break; case OP_GETMEMBLOCK: set_ucontext_paramreg(uc, get_reginfo_paramreg(&master_ri) + - (uintptr_t) memblock); + (uintptr_t)memblock); break; case OP_COMPAREMEM: mem_used = 1; - if (recv_data_pkt(sock, apprentice_memblock, MEMBLOCKLEN)) { + if (read_fn(apprentice_memblock, MEMBLOCKLEN)) { packet_mismatch = 1; resp = 2; } else if (memcmp(memblock, apprentice_memblock, MEMBLOCKLEN) != 0) { /* memory mismatch */ resp = 2; } - send_response_byte(sock, resp); + resp_fn(resp); break; } diff --git a/risu.c b/risu.c index a10422a..88e586c 100644 --- a/risu.c +++ b/risu.c @@ -37,9 +37,28 @@ sigjmp_buf jmpbuf; /* Should we test for FP exception status bits? */ int test_fp_exc; +/* Master functions */ + +int read_sock(void *ptr, size_t bytes) +{ + return recv_data_pkt(master_socket, ptr, bytes); +} + +void respond_sock(int r) +{ + send_response_byte(master_socket, r); +} + +/* Apprentice function */ + +int write_sock(void *ptr, size_t bytes) +{ + return send_data_pkt(apprentice_socket, ptr, bytes); +} + void master_sigill(int sig, siginfo_t *si, void *uc) { - switch (recv_and_compare_register_info(master_socket, uc)) { + switch (recv_and_compare_register_info(read_sock, respond_sock, uc)) { case 0: /* match OK */ advance_pc(uc); @@ -52,7 +71,7 @@ void master_sigill(int sig, siginfo_t *si, void *uc) void apprentice_sigill(int sig, siginfo_t *si, void *uc) { - switch (send_register_info(apprentice_socket, uc)) { + switch (send_register_info(write_sock, uc)) { case 0: /* match OK */ advance_pc(uc); diff --git a/risu.h b/risu.h index 78a7313..32241bc 100644 --- a/risu.h +++ b/risu.h @@ -53,17 +53,24 @@ struct reginfo; /* Functions operating on reginfo */ +/* To keep the read/write logic from multiplying across all arches + * we wrap up the function here to keep all the changes in one place + */ +typedef int (*write_fn) (void *ptr, size_t bytes); +typedef int (*read_fn) (void *ptr, size_t bytes); +typedef void (*respond_fn) (int response); + /* Send the register information from the struct ucontext down the socket. * Return the response code from the master. * NB: called from a signal handler. */ -int send_register_info(int sock, void *uc); +int send_register_info(write_fn write_fn, void *uc); /* Read register info from the socket and compare it with that from the * ucontext. Return 0 for match, 1 for end-of-test, 2 for mismatch. * NB: called from a signal handler. */ -int recv_and_compare_register_info(int sock, void *uc); +int recv_and_compare_register_info(read_fn read_fn, respond_fn respond, void *uc); /* Print a useful report on the status of the last comparison * done in recv_and_compare_register_info(). This is called on