From patchwork Wed May 22 18:42:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164870 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1237741ili; Wed, 22 May 2019 12:12:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqzsnWSXIOUuoFRtEX44scNl3dbMNXIAA9NAMwihGobhVYlGz9OQucevnMWRO3IkFQzGymrC X-Received: by 2002:a05:6402:550:: with SMTP id i16mr46470801edx.212.1558552334294; Wed, 22 May 2019 12:12:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558552334; cv=none; d=google.com; s=arc-20160816; b=ef69/Wqu+okiivYckX5qTbVcA/y0rCa7xp9fwZ5FgLRYA1wn5UWyWILeDFq6VvQUHI /j+rDsUebI2Z+wKmLOlBhvW+ycAPmxJ2W7KuMU96NAvGyJjyBdVsVBxhCB/im4yKhGPa rvgcZ1qLZfKnrAuU8jqutDKnzWYbzMl65MNFB28hdthIN89C/AtZkP5d4PEppDRcVSXD ajDW/rMatTbUTy5cFIT5ruNGSPocWHW9rxyvz45NOpzbY7UVMHgxfPjDeDSr3sip6YKM 3YxcVMopm1QXvdb2aR+J9CBvmiDPO538juX4AXnyAgtCXucGFmJMmbzDKCP0nOgDLjwJ dUYA== 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=eQF1EgwSKdQ+jEilzLu3oc5jnuWVHN3zq38+Bl8lFmE=; b=oJgTy6+gXo4mG435hfbhAMNX/M6pB/vki8WmQ6rLWfLykXaOSETdRbKmtnBitX6VMs HQKoARFZtdOWDPvpVWchvzHJIoYyzbSA/OnWrEY7P53QErfRvE0ehZN1/ClBegE93Wro X57/qf2e//KVCDRDKR9vpZ/PMPkdT7uSA32EapM2Rp0WDUfk4/MEOzjEm/hmK7+rsUo2 7N/jdfVRIBl8cm0bx31u5GDXaeO36asO1UO4hDq2Aufj13ADKJsLQDgp3uUMQw03DhG/ ymfg2VvVeiD6qGh0HonpmJrOxngLNt7/24jtPK6woiE6HrO8tH8JqBkM6tjndXBS5G+I JcQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="HSh2u8/D"; 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 a7si9698342edc.327.2019.05.22.12.12.13 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:12:14 -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="HSh2u8/D"; 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]:49873 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWer-0006eb-3U for patch@linaro.org; Wed, 22 May 2019 15:12:13 -0400 Received: from eggs.gnu.org ([209.51.188.92]:35086) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOn-0008Ga-BX for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWCU-0008Ch-8E for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:55 -0400 Received: from mail-yw1-xc41.google.com ([2607:f8b0:4864:20::c41]:40638) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWCU-0008Bk-3l for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:54 -0400 Received: by mail-yw1-xc41.google.com with SMTP id 18so1241479ywe.7 for ; Wed, 22 May 2019 11:42:52 -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=eQF1EgwSKdQ+jEilzLu3oc5jnuWVHN3zq38+Bl8lFmE=; b=HSh2u8/DWaOXOeGfFCromNcDpKZGo42mmhKZKJaXRRO2/rWdn+CJvChECQ2ZfKCKTH PDGdHY9cmkTnRh51F2vzo81xvDADZ9FjjGUmjZUFtFPklj46UBr0X43fQdcXYcGmv9XW QtAH4L+rb4MIDhni+4BqQfOeA3d+FRWPWfeY38rU4WWtuRlwvZ9f/4obucFjb3zkKtgK exC/i22lcCBGQ0FymOqMLL1R/XpQZeGL8USh4adZ4Q158ZGsVLS3ynsr+3qL8QeWtgze cg4qjoOH6VVj4bCJJlIZaC+81BZlyDAnd0YE50kTZ94+q/qasfyyF3Dtni/pf9xpODAR qBtw== 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=eQF1EgwSKdQ+jEilzLu3oc5jnuWVHN3zq38+Bl8lFmE=; b=UOFas/ZbtpitvZTI/OJNFtwGL+8L3n0Lnx6GPIvCZIrcWpNhennUujM02tOxGilHh+ lNddCNEWg2BJVxlU4AzYXa4fRfw/pzfI14ZX40wdX9H45MWJNGoyQlPqI9PzSwO/Kf60 fJFgpUfA9WZQeGiLLwYEkxIDp8Y4v0DXdWigjf5sCUcNHL1NgbdfYFosTLaxjuuchMSJ GUKFivNlE4LKuoLpTLu4NRc7GmYG5CAg/PjNPB7zjp3rgyalSXcVM6G7+rFNzmmZE+xj KBcn2mRwf6sW3TZdRP6R7rZXVZLgP3LXgnqlUy8JbegTKqXlQ6LPSOIHZRcdIvYJB9fS +sCA== X-Gm-Message-State: APjAAAUr5RC6T98kabJFd6Yj7sRlRSN8FZco4fgo/Atc2Lgbi2+DCMF1 eYbFL8rnT4TEqtfZlhK+6hCGAMsQzkE= X-Received: by 2002:a81:1ecd:: with SMTP id e196mr40520973ywe.356.1558550571662; Wed, 22 May 2019 11:42:51 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:23 -0400 Message-Id: <20190522184226.17871-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::c41 Subject: [Qemu-devel] [PULL 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: peter.maydell@linaro.org 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 6b91082b8b..acd23c53ca 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 /*