From patchwork Tue May 14 19:16:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164249 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp3015592ili; Tue, 14 May 2019 12:35:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqyaeW3Gt9ZWK1M6AYvmtEyBdvoa250rxhGOXG3Cgwza4sIubER92i6Hu6IHJoLganKXCvnP X-Received: by 2002:a17:906:61c3:: with SMTP id t3mr10850559ejl.273.1557862513696; Tue, 14 May 2019 12:35:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557862513; cv=none; d=google.com; s=arc-20160816; b=r+3X50iz5/VKM5NA9VYTMSf0yRruVZ244jwTJ76ozt09TDRPbrGJRbCWkRZp9kUbQI nS6zJbgYnFxNoUwUHjttubaYIwcODnwyNcOzSYoDi4z0LQahyihVMWVMAN1fsZVs0qTb ZG5jOkJpjl5ccr9Zu9OKfn+LTOAKSxZque0wXzbYi5ypqGxMF1qHvZXfFRaTfLsQtkUU AosXy01JzeCAX99P3tFjt9JELzjy6bNcfX92k3JkCvirMvl9m4cdaD+Di0It48vFn+jz e8MIFDENS4UMUr9U/nVxacYZ5Jx5gws5FbeCDsmTvN4hD4iWZw+L0I0pBx9mvUwoKnDG mqfw== 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=wKy5ep5gzBeVJvdgqxMAwC/EHW/NEI1i+sUaPM2vsGg=; b=jjvD3nVxz05/7YcYZcpK9INpvxl291HItJGAmwhF9qEGRwMynTF/QYcxrgv4wVopt7 2Xayb0pHMj2Jjt61DbDIuyS/Hq+Cv6sA8TVKDx5ZT2/QMeTkYURTvd+on32ISTRhq/JZ wJKTrPjcv97MLzrk827Irz9nNAbzATiqQk9OpObbWhsVBm53H3ffHcHnkgBeBJctPz50 +KEMS2C4+/wLUGrKKZUbIqGqFXXlg93VZe/FoUCWjLicLBNcNOj7cc1BATDjzL8Pjb8G uvsCW+Z64Erc97qhvAS1nflxLWsOCMPqJGhlC1OVhTjRejGCa/ZjLmOKs3YAVO3ae1Z0 2c2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=HUMjL7Yb; 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 e41si328132edd.236.2019.05.14.12.35.13 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 14 May 2019 12:35:13 -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=HUMjL7Yb; 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]:53179 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQdCi-0000zd-KI for patch@linaro.org; Tue, 14 May 2019 15:35:12 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48960) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQcvV-0002hM-Bs for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hQcvT-00076f-3A for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:25 -0400 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:44350) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hQcvR-00073d-IH for qemu-devel@nongnu.org; Tue, 14 May 2019 15:17:21 -0400 Received: by mail-pg1-x541.google.com with SMTP id z16so34264pgv.11 for ; Tue, 14 May 2019 12:17:20 -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=wKy5ep5gzBeVJvdgqxMAwC/EHW/NEI1i+sUaPM2vsGg=; b=HUMjL7YbNsLvockZ2JWS36HhF7Fu+KVAC98o3BcIpBR1mnssHseBVExELZPJO3y24P iskIXmWNnsyrl+hwNmr4KCejZOOjzsP/Bf7Qv+5S9v9qi6/qm4/aTfquomhrUckKf6TB 2rk/3ex0QtBwMEhVD4/V4xfT8i9e42C7Aq9vC7ECEnTvgYOLntqzayUSyuzn0h2cys/4 EsmGJvTBQL68MEA7vMzt05MiZQXMciYXywLfPT7UO+A4hQdFa/ccCcVw5xI33uvg93x6 r0liswMq8iDa0jInLwEnBl4LjuQPX8bXg6vJUWNdrCxXYxyavQAXrvKwb4m6D+zG4NIu pBCA== 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=wKy5ep5gzBeVJvdgqxMAwC/EHW/NEI1i+sUaPM2vsGg=; b=jLJZBC7JEQ/oR/gH65Oky6faO/J4RGcXyy1112/eMMZDlStsv6ZPHNTLXn4J1OYFPX FQPS7iOPHAnbFIf8LH/zoaz4SQsoPqDQqdTQv97jOvYDMvAzJTL1YkYLBOJ28s5jg7W6 MoO4FT8fYkvOSwwY54aBrPAmNUX1B83AMLnnMmtFPuaUTP6I8WL21tOipPUOnATIVHxL x2z12Q77Ld0/PM6DubIlYiTfwehu+1yXE6QIewmZ4mJhS7Gvo8l0fiRZQ8aoYrFSY++Y v3JA8wy0fajc5E7VshoKFIP0HtBhBUHc8EKzkFdlNs7bnj/vPqOpx47al+oweg68HPTI zOFA== X-Gm-Message-State: APjAAAWGNIjkqi9vzc/dg/6Uh/SgeHeoU3ddP/ocNZ6e4dyCDnZY7FXl QH0MvKsMpkuQvugfrm0u2iLCQG9eFNA= X-Received: by 2002:aa7:8d81:: with SMTP id i1mr14308617pfr.244.1557861439629; Tue, 14 May 2019 12:17:19 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id o6sm18682982pfa.88.2019.05.14.12.17.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 May 2019 12:17:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 14 May 2019 12:16:47 -0700 Message-Id: <20190514191653.31488-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190514191653.31488-1-richard.henderson@linaro.org> References: <20190514191653.31488-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::541 Subject: [Qemu-devel] [PATCH v7 18/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: lvivier@redhat.com, berrange@redhat.com, armbru@redhat.com 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. 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; }