From patchwork Fri Jun 22 14:12:02 2018 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: 139671 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp957313lji; Fri, 22 Jun 2018 07:43:35 -0700 (PDT) X-Google-Smtp-Source: AAOMgpewvDXQhilgvUJ4UGg6rukdjhxSUpjT/NZnHivLGOfLCHkF6jwuWBqOWWcRawNaAoH1FyxC X-Received: by 2002:a0c:b5e9:: with SMTP id o41-v6mr1591472qvf.189.1529678615341; Fri, 22 Jun 2018 07:43:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529678615; cv=none; d=google.com; s=arc-20160816; b=fk8W2P25LrT42HTRMGYFSks9YxTzGRkXMX9rxkGt3omt83ZPFcmCsw/ZPuTPHuj7K1 96oBuQ/dZjpxjdXghy9+rsVNkSdDWTR2G0fEnZZg9t+LjtZ1hpFmkuM4xEflvHvI7Vq6 05VfQ1/nNs4yflRBntls7cme8iMpkYMhOw22MVHclR+vyBUGdCFcX0K4GKniAiVxo7jw cWTk9kkEofHx14BX7Ao/VKA9sT7nDd/WRCv59kmEADt2RiTSSseeLpZu62cSpiGfOwlH xyv5S18wepXk7D9tarqSp1fP40o4B0IrGlZUqGtlaU5U7CHli2158Pzv3ZYeHnzHQ7Wi zD3Q== 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=mWP40Stc1rcVLV+euOPJVniIvKfcUEsxA1LKizFB7t4=; b=VmMyEAWqlj3lEuxlBlDrmVJ2VaJMWubOQnUA5mvXa7tAbdi+19oDdXMTKcnzRLZPHU HZ5oTQ351+gEwQuB3Hl9NzWcHETmab5wc5AiTOiWQgn+73KDIkb8F5yghD9vVKWVLMVj nVcsDCBC6waK2OiiFZZTT7CoULmUbDfjMdBlb6FP2ZIX3eJUcjKdt4qY+4J4fEThYf25 sKs3jbK8fbwS+APNYY/1SHtXyuPN5iK1cBDp4cAg2DtVOuXmQHFsNzOljEwR8VEBU5KB uSRM6RvvszUSY+FogJaSRbineTpSsEkci7TDe4X+gkmdoL2mvT56s0fKiWS2wbKAyDFW 0Alw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=M+0AoNUz; 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 g9-v6si375440qta.301.2018.06.22.07.43.35 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 22 Jun 2018 07:43:35 -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.s=google header.b=M+0AoNUz; 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]:34487 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fWNHi-0007Ef-Mn for patch@linaro.org; Fri, 22 Jun 2018 10:43:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41824) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fWMwy-0005wD-Gn for qemu-devel@nongnu.org; Fri, 22 Jun 2018 10:22:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fWMww-0003YS-V3 for qemu-devel@nongnu.org; Fri, 22 Jun 2018 10:22:08 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:54514) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fWMww-0003XS-KQ for qemu-devel@nongnu.org; Fri, 22 Jun 2018 10:22:06 -0400 Received: by mail-wm0-x244.google.com with SMTP id o13-v6so2421348wmf.4 for ; Fri, 22 Jun 2018 07:22:06 -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=mWP40Stc1rcVLV+euOPJVniIvKfcUEsxA1LKizFB7t4=; b=M+0AoNUz42eJ5KLm0HLfWzlDB0m+qpF+1TabXLaYvc5Vnu1WsDCiDqBkHAHkJRypqZ xCW7sAiZRT2iBu3HAPGv5TaQDFNNEOC7ud0sO8ZosjJOaEOa9bV3ugJrefGxNx038i5/ gBfLaBB1strQr/DPCu0wqG3pia7hmM2VCQTG8= 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=mWP40Stc1rcVLV+euOPJVniIvKfcUEsxA1LKizFB7t4=; b=mFGCfOMRrmZ0BAE2eODdpNJUrtStBs11qIikUzZx7JGkFO9KD/l4d3l7b5sT9UWh9H 7CFvv3d9+CG9wqnFV+J1/ORS4k/mDypT2F3DW8tm7+CN9dAk3BdLO3k8P5s8vxNgHQ1F 4pStR6zprZ9ciTINbFyA9GH9aagmzSiheLVFXr8AJqCvSyfe+ptYrACpZ5PlGcuc0PzA HIv2E89sYKFbwBTt0Rm+TI43DEKbNmiUqXJSq6XgN0evFmCx5PD0xjwnGPvJBov/qpmW kzZCMrWW/pKLM6KdWtDL4ERX848nH7H0brNQHXpv+nbEb4bepIa30wOrf4oOTs+DtfKN 3QHg== X-Gm-Message-State: APt69E2tU/tr6BIhjUr3EPjMTrTUDwENUYipkARjY5si7s9l/zcJsld5 gS/VtgyFV1WtE/ae4Wq7SdvbpQ== X-Received: by 2002:a1c:3fd1:: with SMTP id m200-v6mr2032714wma.88.1529677325477; Fri, 22 Jun 2018 07:22:05 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id n16-v6sm2022714wrq.43.2018.06.22.07.22.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 22 Jun 2018 07:22:04 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 4103E3E0C98; Fri, 22 Jun 2018 15:12:06 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Fri, 22 Jun 2018 15:12:02 +0100 Message-Id: <20180622141205.16306-20-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180622141205.16306-1-alex.bennee@linaro.org> References: <20180622141205.16306-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:c09::244 Subject: [Qemu-devel] [RISU PATCH v4 19/22] risu_reginfo_aarch64: add support for copying SVE register state 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-arm@nongnu.org, richard.henderson@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Add the ability to save SVE registers from the signal context. This is controlled with an optional flag --test-sve. The whole thing is conditionally compiled when SVE support is in the sigcontext headers. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson --- v2 - support EXTRA_MAGIC contexts v3 - handle conditional bits - include in reginfo.h - move from helper function to main init function - (void *) cast for memcpy - additional ifdef SVE_MAGIC stuff --- risu_reginfo_aarch64.c | 107 ++++++++++++++++++++++++++++++++++++----- risu_reginfo_aarch64.h | 16 ++++++ 2 files changed, 110 insertions(+), 13 deletions(-) -- 2.17.1 diff --git a/risu_reginfo_aarch64.c b/risu_reginfo_aarch64.c index 3ccaf0e..79db5dd 100644 --- a/risu_reginfo_aarch64.c +++ b/risu_reginfo_aarch64.c @@ -16,13 +16,26 @@ #include /* for FPSIMD_MAGIC */ #include #include -#include +#include #include "risu.h" #include "risu_reginfo_aarch64.h" +#ifndef SVE_MAGIC const struct option * const arch_long_opts; const char * const arch_extra_help; +#else + +/* Should we test SVE register state */ +static int test_sve; +static const struct option extra_opts[] = { + {"test-sve", no_argument, &test_sve, 1}, + {0, 0, 0, 0} +}; + +const struct option * const arch_long_opts = &extra_opts[0]; +const char * const arch_extra_help = " --test-sve Compare SVE registers\n"; +#endif void process_arch_opt(int opt, const char *arg) { @@ -31,8 +44,12 @@ void process_arch_opt(int opt, const char *arg) const int reginfo_size(void) { - const int size = offsetof(struct reginfo, simd.end); - assert(sizeof(struct reginfo)==size); + int size = offsetof(struct reginfo, simd.end); +#ifdef SVE_MAGIC + if (test_sve) { + size = offsetof(struct reginfo, sve.end); + } +#endif return size; } @@ -40,8 +57,12 @@ const int reginfo_size(void) void reginfo_init(struct reginfo *ri, ucontext_t *uc) { int i; - struct _aarch64_ctx *ctx; - struct fpsimd_context *fp; + struct _aarch64_ctx *ctx, *extra = NULL; + struct fpsimd_context *fp = NULL; +#ifdef SVE_MAGIC + struct sve_context *sve = NULL; +#endif + /* necessary to be able to compare with memcmp later */ memset(ri, 0, sizeof(*ri)); @@ -57,21 +78,81 @@ void reginfo_init(struct reginfo *ri, ucontext_t *uc) ri->faulting_insn = *((uint32_t *) uc->uc_mcontext.pc); ctx = (struct _aarch64_ctx *) &uc->uc_mcontext.__reserved[0]; - - while (ctx->magic != FPSIMD_MAGIC && ctx->size != 0) { - ctx += (ctx->size + sizeof(*ctx) - 1) / sizeof(*ctx); + while (ctx) { + switch (ctx->magic) { + case FPSIMD_MAGIC: + fp = (void *)ctx; + break; +#ifdef SVE_MAGIC + case SVE_MAGIC: + sve = (void *)ctx; + break; + case EXTRA_MAGIC: + extra = (void *)((struct extra_context *)(ctx))->datap; + break; +#endif + case 0: + /* End of list. */ + ctx = extra; + extra = NULL; + continue; + default: + /* Unknown record -- skip it. */ + break; + } + ctx = (void *)ctx + ctx->size; } - if (ctx->magic != FPSIMD_MAGIC || ctx->size != sizeof(*fp)) { - fprintf(stderr, - "risu_reginfo_aarch64: failed to get FP/SIMD state\n"); + if (!fp || fp->head.size != sizeof(*fp)) { + fprintf(stderr, "risu_reginfo_aarch64: failed to get FP/SIMD state\n"); return; } - - fp = (struct fpsimd_context *) ctx; ri->fpsr = fp->fpsr; ri->fpcr = fp->fpcr; +#ifdef SVE_MAGIC + if (test_sve) { + int vq = sve_vq_from_vl(sve->vl); /* number of quads for whole vl */ + + if (sve == NULL) { + fprintf(stderr, "risu_reginfo_aarch64: failed to get SVE state\n"); + return; + } + + ri->sve.vl = sve->vl; + + if (sve->head.size < SVE_SIG_CONTEXT_SIZE(vq)) { + if (sve->head.size == sizeof(*sve)) { + /* SVE state is empty -- not an error. */ + } else { + fprintf(stderr, "risu_reginfo_aarch64: " + "failed to get complete SVE state\n"); + } + return; + } + + /* Copy ZREG's one at a time */ + for (i = 0; i < SVE_NUM_ZREGS; i++) { + memcpy(&ri->sve.zregs[i], + (void *)sve + SVE_SIG_ZREG_OFFSET(vq, i), + SVE_SIG_ZREG_SIZE(vq)); + } + + /* Copy PREG's one at a time */ + for (i = 0; i < SVE_NUM_PREGS; i++) { + memcpy(&ri->sve.pregs[i], + (void *)sve + SVE_SIG_PREG_OFFSET(vq, i), + SVE_SIG_PREG_SIZE(vq)); + } + + /* Finally the FFR */ + memcpy(&ri->sve.ffr,(void *)sve + SVE_SIG_FFR_OFFSET(vq), + SVE_SIG_FFR_SIZE(vq)); + + return; + } +#endif + for (i = 0; i < 32; i++) { ri->simd.vregs[i] = fp->vregs[i]; } diff --git a/risu_reginfo_aarch64.h b/risu_reginfo_aarch64.h index ef97622..b3701b3 100644 --- a/risu_reginfo_aarch64.h +++ b/risu_reginfo_aarch64.h @@ -13,11 +13,24 @@ #ifndef RISU_REGINFO_AARCH64_H #define RISU_REGINFO_AARCH64_H +#include /* for SVE_MAGIC */ + struct simd_reginfo { __uint128_t vregs[32]; char end[0]; }; +#ifdef SVE_MAGIC +struct sve_reginfo { + /* SVE */ + uint16_t vl; /* current VL */ + __uint128_t zregs[SVE_NUM_ZREGS][SVE_VQ_MAX]; + uint16_t pregs[SVE_NUM_PREGS][SVE_VQ_MAX]; + uint16_t ffr[SVE_VQ_MAX]; + char end[0]; +}; +#endif + struct reginfo { uint64_t fault_address; uint64_t regs[31]; @@ -32,6 +45,9 @@ struct reginfo { union { struct simd_reginfo simd; +#ifdef SVE_MAGIC + struct sve_reginfo sve; +#endif }; };