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: 10939341 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DF6EA76 for ; Fri, 10 May 2019 17:51:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD9D828C2D for ; Fri, 10 May 2019 17:51:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C1B8E28C57; Fri, 10 May 2019 17:51:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6C3B328C2D for ; Fri, 10 May 2019 17:51:20 +0000 (UTC) Received: from localhost ([127.0.0.1]:47785 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9fz-0001ty-IV for patchwork-qemu-devel@patchwork.kernel.org; Fri, 10 May 2019 13:51:19 -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-Google-Smtp-Source: APXvYqxnrAKhvo0c6sSPiWXa7tvxVj86D5Ov7MTK5JqR4LnpORYmsgY5BqoxWy4HN3LvaeGSqEHtvg== 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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(+) 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 /*