From patchwork Fri May 10 01:24:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163812 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1737718ilr; Thu, 9 May 2019 18:48:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqz9uWraf5/02scvxvCmDRqGJL7LGYL/bRj98izaY9otktQEEdi+c7iPyDHrWCybnkz88Xwu X-Received: by 2002:adf:ce06:: with SMTP id p6mr5536214wrn.278.1557452900541; Thu, 09 May 2019 18:48:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557452900; cv=none; d=google.com; s=arc-20160816; b=TYh2JfZKbpulN9JQYuaY77cmjg5o5eR7/9p31YoSXs6/JlzRgP0fGAlH3Pa/v4zc3p eZCne1Pl7ZJ+et2qUtHWpaZwabFWZa8sWxb03gnio2XOQXD8+OvrCWmDlFB0bdaXX5Y2 TynwMn2VwjufLqOU+TxhfQ1hnfAIezr+RJ5PJZ6IDTa1RpAu/9F61L0s2My5KXieyqpr AcStdiqKHz/iQ37+yUkTthox/SYNHae9cEi/2+AsuMR0bLF1/CdCJ2RIDkjDs0qbxjVG oO786ONAX3iwRldcFGFxne6tSmSm23ZPXugzoVUNYjzpD8iG7EJwTdziO+l9exK4yUHT dUDQ== 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=6a5iGBwRtD5hTTLS6rzCG4hSulwi7yefRB4mjcj/bzk=; b=NhR/1Ke8KuPY4imPZfDfcnzma0xiXu7qZybSovtUyNrAiLYODBGlwzbMbEHE4pZyR5 +nwjN95xQmb4x0jj218kfnlixnOrDjt0+pVvtXGmYPl9C/AdfYNcKcXm0fN0FMWrtvXZ Qrv+V2iLJgbS4qzNL6Q5nE4eI5Nw2TzXy84aDnhBt6FLZ9lsqRz0JTPzhW8dGfjUZqbN YT2oWcBoYWi8ugMAJR6gdZR5vmcoHGr1YBQzh3ySngYiv7ulUhblfvdWRl/Gg4TpG8zB ThmTw7joSFHEnwUl4QNWfLL08wWxlNYjxkqo4FVbeUQlUHiS6xtfZdPRdu2xZxzI7Xmn KRsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=uBPl2xjN; 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 a3si2934029wrm.296.2019.05.09.18.48.20 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:48:20 -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=uBPl2xjN; 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]:35305 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOue3-0000SZ-K2 for patch@linaro.org; Thu, 09 May 2019 21:48:19 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58953) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHy-0006TX-9r for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHx-0001Pq-8C for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:30 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:44641) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHx-0001PK-2Z for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:29 -0400 Received: by mail-pf1-x443.google.com with SMTP id g9so2244747pfo.11 for ; Thu, 09 May 2019 18:25:29 -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=6a5iGBwRtD5hTTLS6rzCG4hSulwi7yefRB4mjcj/bzk=; b=uBPl2xjNQdlFp1d6IlgqDxsR/CXuB/2pc+qELra6ukOQq81OpdorQYN2Y6Ip9JhnhX vgfcZh1UHJygFhYKM0NV44O60dIbwVcjjuiOICF74Vw6l1ZIa5yDV1SY8+nRGBFZEMz9 ozzSXJy3Wh5QVM9GyS2RU1CSsvtgFmPf87TbC2g5oUIih31ebSpW1Heu9fQrqxNaKjGh jiH920xo0vySE85FRBVkk7IMj+dn9C8qELkM2nhjgTqd3G4HXitFauLFc8ViNNhMuQzA j+hfTWNCeT2SoG6Sc7NEqKv0szrMhR0PFGgSCMe+rjmK0cahE4CtR+sUXsYVH7vFd3wq kFRA== 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=6a5iGBwRtD5hTTLS6rzCG4hSulwi7yefRB4mjcj/bzk=; b=X9+WrDr+HGO05sSyTUI/+Ur0CWpId4fHJRZdL2OT/vXdCZcfle4Uzo+ox/4Y6O8WCW 2QEPRFKcox2cPrrdcpm/mjn5TzVcjzm0zW4NgAOQzd6e6PmTtXLKCkqu1qq0t7NamZDm PC+h0cYqeWtP25+Ia2QmnAvEGZvjUXOUnN0QsszA7/0sijeeoEJSJBRfMd47AeQFNyx7 OlkuRFGk/FoEnU3xbD/rODuRWPH5BHfDFocUlscKgQRQPK+BrK2QecJ1WBZGUW9+6yNg 5ot8w0GLCpdFJN8Jbma1RcPmP+liBJtcxVsA97AdJPYrhn9G8SZogAtsAKZd3H9z2tCP NXeA== X-Gm-Message-State: APjAAAXu1HNmHReu/SEEgws3mVDiWnKg3xIRPAiw5DQFh7h9xnlgMWBG WvNPLh5vE7rexPbXfkydrv4lD/yat6o= X-Received: by 2002:a63:cf:: with SMTP id 198mr9672036pga.228.1557451527252; Thu, 09 May 2019 18:25:27 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id n18sm8252700pfi.48.2019.05.09.18.25.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:56 -0700 Message-Id: <20190510012458.22706-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510012458.22706-1-richard.henderson@linaro.org> References: <20190510012458.22706-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 v5 22/24] 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 , qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Cc: qemu-arm@nongnu.org Cc: Peter Maydell Signed-off-by: Richard Henderson --- v3: Log errors with -d unimp, for lack of a better flag. --- target/arm/cpu.h | 5 +++++ target/arm/cpu64.c | 1 + target/arm/helper.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) -- 2.17.1 Reviewed-by: Peter Maydell 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..9642070194 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, + .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, + .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 /*