From patchwork Fri May 17 02:39:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164375 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1609817ili; Thu, 16 May 2019 19:54:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqwjV/fEbMWir7mOwmzl1d7koJTJRxHl0bOQwyhzVx0bcXQc0eKzGuK2zTflslix7qDHEW5m X-Received: by 2002:a50:95b0:: with SMTP id w45mr54611396eda.221.1558061670070; Thu, 16 May 2019 19:54:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558061670; cv=none; d=google.com; s=arc-20160816; b=Y/mOUu3feheFlvdW9MFdG8bj9YJAYpkWeNe7UZB7rykNRcIK5m1mN6B0UM+QDRrhhU 5E4kYlMq4ztbSKZuNyvH6K9CtZJYX7+yEON3YabHWcVs0eDzDfCT5lelGmlWi9fH73n1 RoV4Bx/8H+W4I+VuwkoqPycY78kMIc2fFFoaHp7dAjBVoNmHeOXvFvxA3G2pBqowc/PM UnYdNhdo2H1aMhJWpOfozFp2d929sLAqdch2ap2PtWWiPup8N++kBN51H+CjU2I2nDcS 6nHB2T3s5jX9cmjH690nsmJEObl4bbhider/4ZQl0Fhjr6T5fAPbqdCUxyFQn514Tuu0 gkqQ== 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:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=ztXvGPgxsfNQ6iDCN/IIJ1leMuVNwtZhgkaITTqSNbM=; b=HnlF3X3YUMnF+ai7ryl1Ly9Y/l1L5d/dA1DL1RKCZRqnTfvECAHJmeZO9BEKQPAdjV +IJqMnpuSIuZ6SPpn+jsrQE5BPYQsL5TAX7Ujl+wu0D4iodhdF8uOWKJJiOfRlG5jhgQ pO3P/rnQZ6RpCF6eT7lMGpiDWWcsWqQdQ1qA3BOBe45c5rXg8SZbr8Bw5kFZz/ee5Lpb uCJVmT39ACBQgVdyaQixmhpcaP6/3YgTdrQ15YCVjfBOsA8jNs1HyPl4KMhouOBZCHs4 geMJSlAq+itiWicWAGvDgsY+HXE3l+nYpTEfL7ChD7txu+bGfc4R67L2jGKipxY+kQw7 Tl2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=QLq8jxm1; 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 e26si838324edd.76.2019.05.16.19.54.29 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 16 May 2019 19:54:30 -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=QLq8jxm1; 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]:40299 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRT0u-0000Y6-Ub for patch@linaro.org; Thu, 16 May 2019 22:54:28 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39182) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRSn0-0005t0-NZ for qemu-devel@nongnu.org; Thu, 16 May 2019 22:40:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hRSmv-0002Fu-8Q for qemu-devel@nongnu.org; Thu, 16 May 2019 22:40:03 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:40530) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hRSmr-0002DC-7T for qemu-devel@nongnu.org; Thu, 16 May 2019 22:39:58 -0400 Received: by mail-pf1-x443.google.com with SMTP id u17so2870602pfn.7 for ; Thu, 16 May 2019 19:39:54 -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; bh=ztXvGPgxsfNQ6iDCN/IIJ1leMuVNwtZhgkaITTqSNbM=; b=QLq8jxm1a1vrzIbzd8yx3g8ZzwJmjyNuJ8C2sbuEPKAzOiZ3EA5Qg48QOvlDgApib+ wywOneEeew6Z9g04YLAg14noWzxQunr02zlFu9G6pMF2BsiIzjJiTwXnFohtwaveXj2Q GqULDLzTUwAWgXQi7cIxETy3EY3zTE0kDItlecAVKMHzV92SMz8R1EHfnAV5fuXatYDT EV48ZGJOwzFHP4/bLzesowLl4A9+KvnI/CKlKXgt0lM9SE2d4BLwTZ736JbNa0ykC5Db AjAz++VG+58PG0HbW4kuwQOyYkxUU24GyqWYlyrfCtDrPaKrz05nd3Oovedec/PiTBB8 4D2w== 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; bh=ztXvGPgxsfNQ6iDCN/IIJ1leMuVNwtZhgkaITTqSNbM=; b=IF5F62mHwGdAa+wk05AsIZlFD9KppvR/Rmvh1xzoO7oiD+AmYcre1DCYs8v6hwzX5J T6ewicIYryiUW1li2SeExe27pEw8cTj1MvnWmdUeJLtg0Q8Yf7QzXNHiItwaDYfo3aH4 899xk8MwzyLhK6uwEuqvphlWGBsqUUHl8r2K2KWyzGSaBeSE5jrueMgRf9MHayGfcaPt JTxqiiKYQ+lqRXPjmRGwbAGItjMLt4BW1/ZP2eprABUaOTzdIOS4sAamqM8C8ZoGe//2 9ToKvaw6B9ck1zLu+fz7JYuVYp1jBeLi3EC+vS7099fAXaoOXGe1eGYV1bmSAypaOvTv qwrA== X-Gm-Message-State: APjAAAWXFBeeb67XKBquVaxiq865rQ+xQw7bh5y+EF5slpyMhPacmpfu Uz6/tRvSn7znmWlijwZGyzpKh6MgNAU= X-Received: by 2002:a65:6116:: with SMTP id z22mr54300257pgu.50.1558060793591; Thu, 16 May 2019 19:39:53 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id w6sm6984152pge.30.2019.05.16.19.39.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 May 2019 19:39:52 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 16 May 2019 19:39:21 -0700 Message-Id: <20190517023924.1686-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190517023924.1686-1-richard.henderson@linaro.org> References: <20190517023924.1686-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 v8 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: , Cc: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Use the newly introduced infrastructure for guest random numbers. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- 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 /*