From patchwork Fri May 10 17:30:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163929 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2688674ilr; Fri, 10 May 2019 10:52:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqyOHRMOL7rjzPk9sZ38riMigCWkfk2CZjoZhhzvba55d2TAlL0volmTEpcuHDfdnBkQXjMF X-Received: by 2002:a17:906:4911:: with SMTP id b17mr4249851ejq.3.1557510770945; Fri, 10 May 2019 10:52:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557510770; cv=none; d=google.com; s=arc-20160816; b=fG9a+I3CIAqFR6z6GS48Vkm5BCZeuH1jXAf1ocnFm9+wBQWAUnJVcE3fVZrLI774Y4 mV6wm9lCHId/ZVCUVodXJleYGkExhjAQ37dwGsDqEXaD0BnysRpHVUF66ukvEDDo+v6K 2NQPiBCRE5VDoxGcQ8c37bXuRF7gpa2IeSO99je0QVjmCiqJJf0oNPcUqGuYP+ioaJB8 BUn/tyrlqsbjfHVjlXYLW/Ppelq0T040G2NDRXB8Ws99FlGe9FcLiOKlhCKDegum29A6 8Fvd+uxgBHLJwyW1cjU3zBV850tYd8c0gAU+rRGIgJWD3ET1hGQJF7XJeDgdCF4WCor5 U5SA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=SX/dz0O8302ZA9gggUBt45HSk3FSPauZ2uFWTG4hibA=; b=L+qonXmQhJ0ToSUZro7guP4zKVwYAtAy5t6BwvkhxfnpeMzXrxlYeOTDq8cP4AjrtH PFFE3aBLSK9EtLSOhsapVwWJzSSk4TnA3avJswwxyZyhhh1ozRIYBBnYS3A+pUo4JFgI mxQYct7uAEit4a7Vya0pIKyLM6uISibOaAKm5aHWa9KZjF6rsynW0qjFcd6WG5AWWd3j ilfaM6/VRGqc83X63FZtpTKkgiz8TsHQuSw08IgHs1P6uPl5JjtViKh2zNdq6+fWPfIL fReruY2B2sdvdTSCANEgow/XCuppNYhUWSwbihCvpv6dEierDOxkZrfx1IFng3VYGRGV 5abg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=BWxEVid8; 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=fail (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 h41si783728edh.55.2019.05.10.10.52.50 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:52:50 -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=fail header.i=@linaro.org header.s=google header.b=BWxEVid8; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:47799 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9hR-0003Jq-R5 for patch@linaro.org; Fri, 10 May 2019 13:52:49 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59298) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9Mf-0007ai-4h for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9Md-0006Dl-Uo for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:21 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:37844) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9Md-0006DT-P4 for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:19 -0400 Received: by mail-pf1-x443.google.com with SMTP id g3so3586529pfi.4 for ; Fri, 10 May 2019 10:31:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=SX/dz0O8302ZA9gggUBt45HSk3FSPauZ2uFWTG4hibA=; b=BWxEVid8g0IB1NkSu1PCLteNgYoe2HC4H0H23zw8WGcT/P/anQWho+6cYetSGuquZT Z/GlGnWmaKcHrRyrsuuFw7p0j6e4QdD5Qgc1HtZSYeiOpa9biiw9EvFIfYnCZZaGPMET sxJaI3mVSoLeMO9CM3MwYxGigN6W1xVLxb9IO8xpZW3TZLecPvQ2vgBwwHSCpnxZzHz/ Hhcgfgr/z27aOU2VTcBmtgrsS7U7md29HA/ouYN8gZ//cHjFbi/csGLr9zrbcF0QEaZ7 g1BVLyohX8Pr9BtX67hR6E6M6f4DJp1jzioMg/QcXlPB1Q7/Sv8UfVyoXhLi68v19sDR VbmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=SX/dz0O8302ZA9gggUBt45HSk3FSPauZ2uFWTG4hibA=; b=fnbnhN0G+FKgOFPU3J0fiG97catu+N4H5Rw/RYZZd7VhTYUNoSQo4xo0Q5kWzYUJcf yhK/JkR8j3qCPIJ1lhACOApIV90A59Yxw62SaFAta0Hj3JxjlppAWHAxwCmY+XnGzu/8 IlKlkwS8QhleUy+u9qcwhN1/lTT01AHdL3BNDS9CkcSh7+7VIVF6hgKdXhFxASSO7EEm UTEYCQpVbY+Z0TqCQ5te7GoxnRs2seMWVTkPmESKYJnqueXcpwk+tBkXhT0j2kYwP5zE qV71B6N0L/60shk/lXgZLfdd6HNrpJVWD/WxEKqIXvAw2KLfJeu/UecbimRDL9xlaTMf 2NXQ== X-Gm-Message-State: APjAAAUxOt/FF7d4JyX2XU8rC3iazHYz7SUpp14404vL2sHE0pYdQzf3 lTOK51Cve4fBm6Qtt40+e1ZfZTRMzow= X-Received: by 2002:a65:4489:: with SMTP id l9mr14968075pgq.1.1557509478522; Fri, 10 May 2019 10:31:18 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.31.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:31:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:46 -0700 Message-Id: <20190510173049.28171-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::443 Subject: [Qemu-devel] [PATCH v6 22/25] target/arm: Implement ARMv8.5-RNG 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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- v3: Log errors with -d unimp, for lack of a better flag. v6: Add ARM_CP_IO for -icount. --- target/arm/cpu.h | 5 +++++ target/arm/cpu64.c | 1 + target/arm/helper.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) -- 2.17.1 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 892f9a4ad2..c34207611b 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3521,6 +3521,11 @@ static inline bool isar_feature_aa64_condm_5(const ARMISARegisters *id) return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, TS) >= 2; } +static inline bool isar_feature_aa64_rndr(const ARMISARegisters *id) +{ + return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, RNDR) != 0; +} + static inline bool isar_feature_aa64_jscvt(const ARMISARegisters *id) { return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, JSCVT) != 0; diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 228906f267..835f73cceb 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -310,6 +310,7 @@ static void aarch64_max_initfn(Object *obj) t = FIELD_DP64(t, ID_AA64ISAR0, DP, 1); t = FIELD_DP64(t, ID_AA64ISAR0, FHM, 1); t = FIELD_DP64(t, ID_AA64ISAR0, TS, 2); /* v8.5-CondM */ + t = FIELD_DP64(t, ID_AA64ISAR0, RNDR, 1); cpu->isar.id_aa64isar0 = t; t = cpu->isar.id_aa64isar1; diff --git a/target/arm/helper.c b/target/arm/helper.c index 7e88b2cadd..1e90f4d722 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -22,6 +22,8 @@ #include "fpu/softfloat.h" #include "qemu/range.h" #include "qapi/qapi-commands-target.h" +#include "qapi/error.h" +#include "qemu/guest-random.h" #define ARM_CPU_FREQ 1000000000 /* FIXME: 1 GHz, should be configurable */ @@ -5746,6 +5748,45 @@ static const ARMCPRegInfo pauth_reginfo[] = { .fieldoffset = offsetof(CPUARMState, keys.apib.hi) }, REGINFO_SENTINEL }; + +static uint64_t rndr_readfn(CPUARMState *env, const ARMCPRegInfo *ri) +{ + Error *err = NULL; + uint64_t ret; + + /* Success sets NZCV = 0000. */ + env->NF = env->CF = env->VF = 0, env->ZF = 1; + + if (qemu_guest_getrandom(&ret, sizeof(ret), &err) < 0) { + /* + * ??? Failed, for unknown reasons in the crypto subsystem. + * The best we can do is log the reason and return the + * timed-out indication to the guest. There is no reason + * we know to expect this failure to be transitory, so the + * guest may well hang retrying the operation. + */ + qemu_log_mask(LOG_UNIMP, "%s: Crypto failure: %s", + ri->name, error_get_pretty(err)); + error_free(err); + + env->ZF = 0; /* NZCF = 0100 */ + return 0; + } + return ret; +} + +/* We do not support re-seeding, so the two registers operate the same. */ +static const ARMCPRegInfo rndr_reginfo[] = { + { .name = "RNDR", .state = ARM_CP_STATE_AA64, + .type = ARM_CP_NO_RAW | ARM_CP_SUPPRESS_TB_END | ARM_CP_IO, + .opc0 = 3, .opc1 = 3, .crn = 2, .crm = 4, .opc2 = 0, + .access = PL0_R, .readfn = rndr_readfn }, + { .name = "RNDRRS", .state = ARM_CP_STATE_AA64, + .type = ARM_CP_NO_RAW | ARM_CP_SUPPRESS_TB_END | ARM_CP_IO, + .opc0 = 3, .opc1 = 3, .crn = 2, .crm = 4, .opc2 = 1, + .access = PL0_R, .readfn = rndr_readfn }, + REGINFO_SENTINEL +}; #endif static CPAccessResult access_predinv(CPUARMState *env, const ARMCPRegInfo *ri, @@ -6690,6 +6731,9 @@ void register_cp_regs_for_features(ARMCPU *cpu) if (cpu_isar_feature(aa64_pauth, cpu)) { define_arm_cp_regs(cpu, pauth_reginfo); } + if (cpu_isar_feature(aa64_rndr, cpu)) { + define_arm_cp_regs(cpu, rndr_reginfo); + } #endif /*