From nobody Tue Feb 10 07:42:48 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=1558061744; cv=none; d=zoho.com; s=zohoarc; b=oBtfNAQc64QNPuEvBKoRCedTaaUlpoFPrgob598w3U6vgo5j5oqz1Gp16rAn7dnYuvgln/msrk0jvkfTLiJfoLQrS3sfljMGByggkkJB9rbA581vKbfwgkQ/zDYyz0EB7o0V+YwZjz+gfX2Xf6a/h7FmXzu/tNQiaFXHgQ1/E4A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558061744; 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=U/idfU+tCwyyiAuB3MOaVyz0PJLzD+075C9mLIFtF4k/Iy6h9Ah3jHnwvPxmhhwY8zjqSUlAjU8RP15U0TkV6Dy6Iqp4rD33/99EdC+Snr+TGiTS9ZPl1lADiEajLq3hfPVN3iX9vYvPIfkNjEPjLutgjzyKb4mUwYGbmJKhA2Q= 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 (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1558061744812446.920571006194; Thu, 16 May 2019 19:55:44 -0700 (PDT) Received: from localhost ([127.0.0.1]:40325 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRT22-0001LE-Pr for importer@patchew.org; Thu, 16 May 2019 22:55:38 -0400 Received: from eggs.gnu.org ([209.51.188.92]:39264) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRSnK-0006BV-Vq for qemu-devel@nongnu.org; Thu, 16 May 2019 22:40:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hRSnE-0002Sh-KQ for qemu-devel@nongnu.org; Thu, 16 May 2019 22:40:22 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:34142) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hRSnB-0002BM-Ev for qemu-devel@nongnu.org; Thu, 16 May 2019 22:40:18 -0400 Received: by mail-pf1-x443.google.com with SMTP id n19so2884909pfa.1 for ; Thu, 16 May 2019 19:39:51 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id w6sm6984152pge.30.2019.05.16.19.39.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 May 2019 19:39:49 -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=LWt+ECBZy7DAmGZIWxNFA7O1YEWE1cDEP0DGP8rugWir3Hp5IadPSKoyaocN42DwQ2 5Y3Zshm3bC4DAJeI9uNPiKGGXkKkUFTRcYaTRm2ttit1I4YsOiDgEMy3oAHnzPyy8NGC gqNXg8YTlkH3jBVDLyKWRzx9jMm6t3T6swMAT0bBdAQkBLPn94fnSlHQwNlEIrUtctx1 eV9etY0qf2lzD0e9dMLDodG3bluhAyciPKINY+zWfYm2vlzNb60VFtPVb5dTzsxFL/j4 kBkOBm1zkdntJtnVUThBsMVv4Fax4Cjt8dPMdal/qA+plLyL3KQltAF3diaUVwV6z8eC nD+g== 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=VYDS2JFZLs8BrSYaJ9X0CrU/fow93bUc2jX2UPeP8z5V31FAN+C04pSJFhhoOQcZDb M/w2Ei32McmX9qkzQ656ZLPNc8wuFobHFa+YMIiYl1x6IyiCXgg0UkheKRQrAtdoY0Ew YsaWzBwWikUQqQujxUyxYUHKaGa+2Oj7pV9Fu61fOyHyeOyvHo7FY5ZcYrSQhHb5Tvqw HK2AYU86XATXXQEAFPzlJP85iussmE+S6SVh8LlRmlkwyOMotEPmrO/7/pxus5O8z1Qr sofAU5hnAzmFSn3ovZ2evbtSynOK0uUz0ym+C0w/kwHQ/Ly7pvXnWvdlOA9JbWlQf0mf l9iA== X-Gm-Message-State: APjAAAXsiWh/pmAdpCf5Pb6UqqSHTzMZQ7tCuCGDj7p/tC5SOXyv8Rbd AuUi9O3raAnaq7DqLFhWpEREeGIjHxw= X-Google-Smtp-Source: APXvYqxysR8/jBWxoMlvD+PdoX4BOmu8GCVZL/CzgauPMIJCv76cuW5TBpR46co97hcjYPJ7c/HLUA== X-Received: by 2002:a63:42:: with SMTP id 63mr54224522pga.337.1558060789991; Thu, 16 May 2019 19:39:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 16 May 2019 19:39:18 -0700 Message-Id: <20190517023924.1686-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190517023924.1686-1-richard.henderson@linaro.org> References: <20190517023924.1686-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::443 Subject: [Qemu-devel] [PATCH v8 19/25] 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