From patchwork Fri May 10 01:24:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163806 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1731819ilr; Thu, 9 May 2019 18:40:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqzXerE3dNscmJ9DBbAQXscC3T/topXT7PkxPxLAvw8XquBrv4NeLgq0GoazPINdaCWrcA0k X-Received: by 2002:a1c:6c1a:: with SMTP id h26mr4741442wmc.89.1557452445904; Thu, 09 May 2019 18:40:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557452445; cv=none; d=google.com; s=arc-20160816; b=G3MzBg03I585Fk0FagxOrPmgMKhgjw48pa50lGTHuBFwIflfl5XrJ7qtzr6J6dkF6Z +c5bxPYwUbLG1q+QToCT9Y6s4vi92NUv+r3hyakD8bytlLP6iEREKIeqzR/nmx60bgRF s9bE5+RyLEa4YuJjIJ5ccwLF1WqhXY1vbCtZPTU4RQotOxEMP98R+kKD6AFS3mnphs3/ inLiiTUT+iYkRK+mhEY0+FA+QYWVxOQaCXM6JZXA5xLMQqgtdb68el+t9UW/NiNi7tzc JrOpyFtPTdxbMnkSeE7r74+XpIEmq++G+BVwgDGnYa39XEJzxqCJjBkhWdvfru5tCL9f O9xA== 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 :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=CbChhlXQdosoI4MWUK/zk2WTRGwUvizy4vwPQDmKAqs=; b=l/SjgPbzaMhpfK2khuBCYRKj0LGf7Bu8Jp2oL7uCSgu+zb6VtTiV5x0LO4cPnoKbRt cFNb3HP2gAIDXjP8zmV2Ji2nso44OcCGW/Z4W9gLfn3RJtktadQYlfllzmmlDDZP08PT UQIFQojNrtwMxtFsss+aw2VatGBK9je5C5+YeQ8RDAHXczEq0Ylc1qQQ3LGFM0WQgO/A sP9F9VlSrkmoynk25raWbMs6uqotX3jpmsbcd/Ip6bPDDfMMYjIyKPjTUflTIzFQ/s9x TQwR+p6noiMYKM7fAnUxTs6weiEB4uPiFGuEEZsU/14agDjPoUpj1q6NXB8FwJm59FmX VMoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=mGlxs+Ik; 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 i8si3027881wrp.407.2019.05.09.18.40.45 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 09 May 2019 18:40:45 -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=mGlxs+Ik; 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]:35220 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuWi-00035G-RL for patch@linaro.org; Thu, 09 May 2019 21:40:44 -0400 Received: from eggs.gnu.org ([209.51.188.92]:58886) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hOuHu-0006P3-Bc for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hOuHt-0001LZ-BA for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:26 -0400 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]:37563) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hOuHt-0001Jn-5i for qemu-devel@nongnu.org; Thu, 09 May 2019 21:25:25 -0400 Received: by mail-pg1-x52d.google.com with SMTP id e6so2127761pgc.4 for ; Thu, 09 May 2019 18:25:25 -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 :mime-version:content-transfer-encoding; bh=CbChhlXQdosoI4MWUK/zk2WTRGwUvizy4vwPQDmKAqs=; b=mGlxs+IkXNYa9y7ymy9eoOjb1uY9oIleFJoAdb2sQNqtgw9XGoWKqDvOQQ0KHuyHWP GBqOzvAQZXaQyKYddxNliA2cj/LQ+BWNKktDhMxaziCB7gQ7eQ3VxC7waceUkjIci+vh O6F/UBGLbxI86EhfpCRx7vInAa41BvVpwauHa30wEjgyaWmYCLFSo7utNrSdLnlnv6d6 bcY754D/Va8ma506KyuJpKTtNv1e+Ikep8BjK3GEjxEEFggMz6xAGUxoZYkrKskARBD3 +ujpaYssXBI0o3IXk/rID2La/D7wGbflEbA0gXG8cvQU8wKXyak0+36rK8oM8lnzXXzZ fmLA== 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:mime-version:content-transfer-encoding; bh=CbChhlXQdosoI4MWUK/zk2WTRGwUvizy4vwPQDmKAqs=; b=mKSB4FldhNIZW2U5qt/uVrJ1iZnp6g3W2wGede2Opm7/W+fJY8BDA+ow9LTUPyGFIB B9xzaWoTX+02E1qbnN5jykqf+Lpc7FH0kfxI1nwitO9QBk1OyS7EYNrQywtvB9Vm4eot qaMHe1OdXa3aAnOWx3SwAUmYw0OhkUjXrFfkwdYgjmA4uilD41q5hTMkqz/lcMMZTyd1 RTnvIlhKxhORXl1HNjs5BCj+XgTdkHXL8/kCCN+txPGhRDiK/fHZwsN7wElvr0EIOVhK 5fO3NYR3D36TPqGRcPeljjX8693DZtbc39Py3FINFyZ8p4k3xUW445AR5UHj4QJUWpzQ 16wA== X-Gm-Message-State: APjAAAU9lGRRz406PS8uJdToOI/ZjhG9icV4uG1RIUnS/fEMsrmAN1zb IdRY4bJmZo8G+gLcZY/sOuinK8WPMTw= X-Received: by 2002:a63:6804:: with SMTP id d4mr9965353pgc.240.1557451523832; Thu, 09 May 2019 18:25:23 -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.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 May 2019 18:25:23 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 9 May 2019 18:24:53 -0700 Message-Id: <20190510012458.22706-20-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> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::52d Subject: [Qemu-devel] [PATCH v5 19/24] hw/misc/bcm2835_rng: Use qemu_guest_getrandom_nofail 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: qemu-arm@nongnu.org, Andrew Baumann Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The random number is intended for use by the guest. As such, we should honor the -seed argument for reproducibility. Use the *_nofail routine instead of rolling our own error handling locally. Cc: qemu-arm@nongnu.org Cc: Andrew Baumann Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- hw/misc/bcm2835_rng.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) -- 2.17.1 diff --git a/hw/misc/bcm2835_rng.c b/hw/misc/bcm2835_rng.c index 4d62143b24..fe59c868f5 100644 --- a/hw/misc/bcm2835_rng.c +++ b/hw/misc/bcm2835_rng.c @@ -9,30 +9,26 @@ #include "qemu/osdep.h" #include "qemu/log.h" -#include "qapi/error.h" -#include "crypto/random.h" +#include "qemu/guest-random.h" #include "hw/misc/bcm2835_rng.h" static uint32_t get_random_bytes(void) { uint32_t res; - Error *err = NULL; - if (qcrypto_random_bytes((uint8_t *)&res, sizeof(res), &err) < 0) { - /* On failure we don't want to return the guest a non-random - * value in case they're really using it for cryptographic - * purposes, so the best we can do is die here. - * This shouldn't happen unless something's broken. - * In theory we could implement this device's full FIFO - * and interrupt semantics and then just stop filling the - * FIFO. That's a lot of work, though, so we assume any - * errors are systematic problems and trust that if we didn't - * fail as the guest inited then we won't fail later on - * mid-run. - */ - error_report_err(err); - exit(1); - } + /* + * On failure we don't want to return the guest a non-random + * value in case they're really using it for cryptographic + * purposes, so the best we can do is die here. + * This shouldn't happen unless something's broken. + * In theory we could implement this device's full FIFO + * and interrupt semantics and then just stop filling the + * FIFO. That's a lot of work, though, so we assume any + * errors are systematic problems and trust that if we didn't + * fail as the guest inited then we won't fail later on + * mid-run. + */ + qemu_guest_getrandom_nofail(&res, sizeof(res)); return res; }