From patchwork Wed May 22 18:42:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164861 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1227407ili; Wed, 22 May 2019 12:02:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqxZoLJh4Iif8uwe1SFlinO8TBem3rwVQ3gRPqwvGyL+03pTqzUG1p8+c4LsEWqph7n4lGsK X-Received: by 2002:a50:896b:: with SMTP id f40mr91804692edf.152.1558551762121; Wed, 22 May 2019 12:02:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558551762; cv=none; d=google.com; s=arc-20160816; b=LgsEQMbawv4NoHwMeNrZD+FGUTyv2xccUwtin8Pn7NzPEAo5v9/kux/sVVQh9LoGRn jlx3TkylSeFAVryfNgQ6bbmgpd41CMdqryPfEmSpxTadzbjCqcP5+lPs5WSoYd2tvs0N OEDqA5kehdOPRsuWcqHybY6qLNzlvo122kdVjGpZVPixu9hT7+sGgdiWrfxHct+EtuTr gqb67mlM5JuS05nrzPoi3Yqrfg8IWAr6OzT1UAt9lm408ZnLLCcB9unxJsFNAqr1enf5 hIrBBD9B6WYfTShd6Qm3tIjWxOHBQYHcnBuRCPcsqt5RWp528GKdWtQ2WVwplMmqWCgv z1Pg== 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=xX5Sq/fnvJXk/U2dim12UrZgYGhHnb5zK0ie6tu19bUxzIM/zRqZnWQL+E9k6xBNrk bCwxrbJ+yBOXtGpzF6mPJjMeFW7k/PorDDZMej5+70zaWV7umDOcriFLvIDWIxx+/aZz 5L834v7Qi7Ht22ZVwyaw1d8nw3eJzk0Zc42XNBxTzlaW/4AranKbBf4COA7mOAmSrHaz rJXJFpdFxRBzy7JPZB49BkxaRvYWvj0zEivNLurz0u6BOztNhnUF8S47IMrST4nhbb1N 0WJh0VcChX8dgvKryUs4mB/sF4BY5s0/qOs+5+np7m5c7UvsTQFoetUoxK9sGLo7Jxb5 wd5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=D6Au61lO; 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 w11si7018034edc.148.2019.05.22.12.02.41 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 22 May 2019 12:02:42 -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=D6Au61lO; 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]:49737 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWVd-0007Vi-43 for patch@linaro.org; Wed, 22 May 2019 15:02:41 -0400 Received: from eggs.gnu.org ([209.51.188.92]:34793) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTWOn-00086d-RV for qemu-devel@nongnu.org; Wed, 22 May 2019 14:55:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTWCQ-0008As-3b for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:52 -0400 Received: from mail-yw1-xc44.google.com ([2607:f8b0:4864:20::c44]:46557) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTWCP-0008AK-Tu for qemu-devel@nongnu.org; Wed, 22 May 2019 14:42:50 -0400 Received: by mail-yw1-xc44.google.com with SMTP id a130so1226271ywe.13 for ; Wed, 22 May 2019 11:42: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=D6Au61lOK217c6i5LElq05rVyQKQbmn2pNey3boFrtxtSEThXVHUu3ot12gV+CkRWd 6UQAxBzpWOy9ixwBm/LAaJy6zViddRGqqI7M1zAVESCGxT3sleVAvUkHfXM5nlrnr0UT JOyIyfv7O64xd7l8E+0RdOLxGYLWbUsx4NKle+UvNquTt+vIoOK8SYzauVVYYRAgOsvL cP9z+zQUd0HRe7AE+mCWDT5AY7OTWUd5leOoyBgFNa81UZtgmKKCgpr07GYE0+PNXKCe lbb/1cbsIb140iath7U2DEMxYpEXtidHLQEeWIX8/IZ/4PKV+qeRWRW+Pspbp4V2xRQn pl4Q== 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=Qq7l+iZs2UxPf82rZbf38TgFIvcHkMHXJEYWuIOAPVM1H6iojjckq6IbHWa2blAuog ssCa2NWf4TTNWoSMd69c8rDRCbdXjtNSe693cD+9UnA/b1Hmrnj1f7PHoohs66LTtye3 ExHoaXwb09t59evxUXjBUCRHfK7832WiFNMX5pHW9q6WzhEgC5zQFRiv560D7WRVha2f nkOaxIIe1mha3IJ1Mu973H10KJyDttgZqMn9uy1wgRrqQbPml1jOFwaTTIDkWcrQp3MA EhCgygfVZopkBVuh+76mRqzsPxFHEVnY/rkB6doTT0qrO+wbwyKT+AlbGj+oJbzuSWa5 Z+Og== X-Gm-Message-State: APjAAAWhnRO9YL7DA8OaMQcaDjhvq00h1A3cAFqxTwxtniPesT7MAqs9 VmojBXabfW6JCptjPBf5uhkfg1WGA+U= X-Received: by 2002:a81:3c13:: with SMTP id j19mr24625854ywa.483.1558550568683; Wed, 22 May 2019 11:42:48 -0700 (PDT) Received: from localhost.localdomain ([71.46.56.17]) by smtp.gmail.com with ESMTPSA id 206sm1299445ywq.74.2019.05.22.11.42.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 May 2019 11:42:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Wed, 22 May 2019 14:42:20 -0400 Message-Id: <20190522184226.17871-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190522184226.17871-1-richard.henderson@linaro.org> References: <20190522184226.17871-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::c44 Subject: [Qemu-devel] [PULL 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: peter.maydell@linaro.org 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; }