From patchwork Fri May 10 01:24:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163795 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1724566ilr; Thu, 9 May 2019 18:31:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqzr7lsi8dZMuMmXwMJZFTKSsRMTO7LbLoB/t8ftTtxYJa5mmRXs9+IXoogjTWZVu+8rrCuB X-Received: by 2002:a1c:a550:: with SMTP id o77mr452319wme.28.1557451892459; Thu, 09 May 2019 18:31:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557451892; cv=none; d=google.com; s=arc-20160816; b=e2VZTgT2uaJ6J1epyGbJfPp2ju+EoyR9Ql/TC1bhYy47BBiXfJPCe8QgM8jCptZX7F YqaaslIGfazMTdymlQP8EJRDwWtM4y35lP+HYKyLUPekEI0huMXL/y8QLnAWy9XRRUPE Hz7up0aEVs+TowEQ8QWn6VvF2LqeIB49wdXwVVPnW0sZLO1wAV6v6JFf/1DdXQJUNV8H RO1XhefpeRBGo1qAcNU1nj1Qw9H/g1kHMOYyiV1gtlNOqerKj7lJGndpRxt5Rq4Vnu+h rhbtV8S4np2ty60i3roGkq2KqOapBrZ19n+bCc1yOX/sAE0u4UAiN4VtO0gZZml189AJ 53dw== 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=dA7IdM9XxYp0KA0mciB9Wmn94LeseL1766ubkiFpUuY=; b=i7+l8UFyLsI+edfPtWLUXoM2QZe3ZWJL+sJ+6bNywy9D8/j1KYtxABNxUAjoviSREa qsrScxycrs9b497IUBfN62wq4kmGQY0WTOr7iEu7FJRE+LZjvekecASUKXcy0YpvbE/o XoBnY6jeMc7M3mQc3jQ4THNYTcvcgjQFhIIhvECowbXBaV8tCfzKwf5zhRfPL3ucnzst SOTkk973DNMEb7kuStEw0qPRg8bu6xd9teH/ZsD39HHwJJK/YljTriFaOZOuDKyNDbM1 QqgRD6fBGCYFJ5sLVF251tmghZ+fOHoW1UatuTGMlFz0IydlCCCgq3yiaRjxsBKtbJQK nWRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=R9QrGTMb; 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 a12si3383961wrf.357.2019.05.09.18.31.32 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:31:32 -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=R9QrGTMb; 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]:35090 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuNn-0003mo-9p for patch@linaro.org; Thu, 09 May 2019 21:31:31 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58958) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHy-0006TY-Ee 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-0001Q7-Ib for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:30 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:40871) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHx-0001Pc-D8 for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:29 -0400 Received: by mail-pl1-x641.google.com with SMTP id b3so1992003plr.7 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:subject:date:message-id:in-reply-to:references; bh=dA7IdM9XxYp0KA0mciB9Wmn94LeseL1766ubkiFpUuY=; b=R9QrGTMbhpFv2ooDE+rHY1/EyvH3DxR/YxJSC/g2s5Gs6Rr70N9h6O+6AU6/5WBRfC U72/8Oa50Lb3jN6+s1dizVR/WJfPz/mCAcOOefsqRuNoQeLmWoPnVf8DAka9HXfnEHCA Q2N+OMuQ353YW+xHvdX032IyOWr9b0EoXAfyERsO7N15QDd9lIdyygdvxRzGmGCjSfP/ 2sO/ytnNDccHpuILQ1Vo3xizTzd84J6FuauNfCJhiPp/DKI9cv2yJ7u+EeAHGsezZEJE PNfLcEHkUg7zAHrv9zo4FONf69Wk8aTbjuW6Pv9VCwWunqulpknwewDqXNua8gsztflC 1qAA== 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=dA7IdM9XxYp0KA0mciB9Wmn94LeseL1766ubkiFpUuY=; b=nIBGEZzhobfw2AwAD4Yqa2JuPGO1yZooQ7pEBQPdJ7QnMZxqaVl8su91mqE/hJM/v1 GNOspaQWja5NQFKxocteeQ6cX1VXfMfOFrImthGmj2dXMkWD9YbV1u4kS1hV5LR9WB2Z 8/yBINcPbRj51CWjWI6q8zP3R8/GTpNgxOCG7xe3aaBZGnvrkPFestm1OQUPrzSLsonJ slHW3XuTUXTZD3kb1zL/Hi90kX95Lm01plPHUM3hYC8A68cELrM/OapBA3zMrixi3bws CCMMZk9brPKqQmrnfcSv9L00GlBXhdPloojo7BJc1VmfmGfYDH6tgxi/u9TuRM1/H/5n zyNg== X-Gm-Message-State: APjAAAXswqowxkGDn0toRC9DSA4MPTBkuIN/jed58dFmwPxhW7FxcaKz Ew6mMBx61yLAVu4CDUwWh0L7LHICoy4= X-Received: by 2002:a17:902:b202:: with SMTP id t2mr9102123plr.69.1557451528176; Thu, 09 May 2019 18:25:28 -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.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:57 -0700 Message-Id: <20190510012458.22706-24-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::641 Subject: [Qemu-devel] [PATCH v5 23/24] target/ppc: Use qemu_guest_getrandom for DARN 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" We now have an interface for guest visible random numbers. Acked-by: David Gibson Signed-off-by: Richard Henderson --- v5: Do not loop for darn64; use sizeof. --- target/ppc/int_helper.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) -- 2.17.1 Reviewed-by: Laurent Vivier diff --git a/target/ppc/int_helper.c b/target/ppc/int_helper.c index f6a088ac08..9af779ad38 100644 --- a/target/ppc/int_helper.c +++ b/target/ppc/int_helper.c @@ -23,6 +23,8 @@ #include "exec/helper-proto.h" #include "crypto/aes.h" #include "fpu/softfloat.h" +#include "qapi/error.h" +#include "qemu/guest-random.h" #include "helper_regs.h" /*****************************************************************************/ @@ -158,25 +160,38 @@ uint32_t helper_cmpeqb(target_ulong ra, target_ulong rb) #undef hasvalue /* - * Return invalid random number. - * - * FIXME: Add rng backend or other mechanism to get cryptographically suitable - * random number + * Return a random number. */ -target_ulong helper_darn32(void) +uint64_t helper_darn32(void) { - return -1; + Error *err = NULL; + uint32_t ret; + + if (qemu_guest_getrandom(&ret, sizeof(ret), &err) < 0) { + qemu_log_mask(LOG_UNIMP, "darn: Crypto failure: %s", + error_get_pretty(err)); + error_free(err); + return -1; + } + + return ret; } -target_ulong helper_darn64(void) +uint64_t helper_darn64(void) { - return -1; + Error *err = NULL; + uint64_t ret; + + if (qemu_guest_getrandom(&ret, sizeof(ret), &err) < 0) { + qemu_log_mask(LOG_UNIMP, "darn: Crypto failure: %s", + error_get_pretty(err)); + error_free(err); + return -1; + } + + return ret; } -#endif - -#if defined(TARGET_PPC64) - uint64_t helper_bpermd(uint64_t rs, uint64_t rb) { int i;