From nobody Tue Feb 10 08:40:56 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1557862489; cv=none; d=zoho.com; s=zohoarc; b=myjV9gwnjdKh1elxRIZMvIRl5m4lRG1zKTtDjD3fLJ2JaWdyFVlTavPoxmAAq/420/P27OYrlg5anUPwWsGsxrpZ3SmBvh4EqHQG3+vhmIMuFNggJg5yDcBvJZXxCiuTkSk4x+g4l40zRfYEcAfixXJS15ULjPo1LeLEmJfmWns= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557862489; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=wKy5ep5gzBeVJvdgqxMAwC/EHW/NEI1i+sUaPM2vsGg=; b=hyO5mlg/6M1k1z8VYEOnqH5Gaawn6p3g2U/bGD9p2xXpTFFWRzrOzw2Jvy432I/V7Qb6/iAb9YLl5SDUZN59l8F2Z2TXEUsmLUrLroCOlr0uULwxslkj7YU6txKW9HrPAEM7ankHdXeacFpFZRzyfKf+BNBrSIwlYsupnl6tHdc= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1557862489717660.0406539686494; Tue, 14 May 2019 12:34:49 -0700 (PDT) Received: from localhost ([127.0.0.1]:53144 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hQdBv-0008Pf-Vz for importer@patchew.org; Tue, 14 May 2019 15:34:24 -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) 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) 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-Google-Smtp-Source: APXvYqyOgMnuN63CxFx71LWU6oKE7bVwvuFxqvEwpxfZXimI9r7lrhxk9aiLv0uM0e6e2OtSt2NG3A== X-Received: by 2002:aa7:8d81:: with SMTP id i1mr14308617pfr.244.1557861439629; Tue, 14 May 2019 12:17:19 -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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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=C3=A9 Signed-off-by: Richard Henderson --- hw/misc/bcm2835_rng.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) 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 @@ =20 #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" =20 static uint32_t get_random_bytes(void) { uint32_t res; - Error *err =3D NULL; =20 - 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; } =20 --=20 2.17.1