From patchwork Fri May 10 17:30:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163915 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp2675711ilr; Fri, 10 May 2019 10:40:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqxDNokqolE5JLkByzYehKFdW+WJnzfUzkSLXpYK5UEEPHKAQtzPt3U4cuNcnwABpVWih3ZU X-Received: by 2002:a50:91d0:: with SMTP id h16mr12576964eda.265.1557510014227; Fri, 10 May 2019 10:40:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557510014; cv=none; d=google.com; s=arc-20160816; b=kBMZnnGZDQOQbP37wVZKpV9phavEYbaORht2EgUfp0+7OSeDgXrz/lNJaIS6lEw1B9 LCyc6Lb4q8/aZZD5aEnnPs7IieqxwiqGz7LnGLRdsHW7Jjj51Fbf2eb9p1LIT26xc2eq vIe9Ca5Xg27RhEZkBK9FMZ1J9I89u+Yfv1xzirGjAjwv1x/6v0EN25Aa0+SI0lZxtwiP t5MDg1BXr0YqF9wjPOoLrK8n2ARSMhvN5m0GXg2l2LzmGkTZDxzqlm1kcS7KO/4CAibi OBYvBXhvyZsQQNY915xCJGuDiODwCx9l8ZrMRKWIfN6wkdNy7ggCxJGWVqCmC/Yxjc8Z 0h+A== 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=X7k/El0TPgLDEVxzuyttJAwl3Xmt/3UQypU/L313RZd9pB/yyT2zQWlgbwHJj3DWpb JNfXVGWu/Vscr59TCs7KHimZ2FrqGTwOxO+isOcy8VmDm095/S+aD/7uzffBBRZ8flfX ADKipO9/1hmtNKqjK3kiAPStTYubQjrGdYdrGPiXFcXVqhlTW7GF9jHfj0yyB4MbUc3M ZNuAVQ1Zfi+OZRB9IBfcYrfm4b2QivjbjyY0oWGPWEeEpiqXQqK9fZGuz3L3/mwOektS 2Lu9zE1hqvgTQksakHiwfGKo1ztWkh5bXXxGUPUCbd2NuEq8aVKj0xBBfPH2EYFTR7tG FFig== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=RjeBll7F; 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 w17si1847777edl.369.2019.05.10.10.40.14 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 10 May 2019 10:40:14 -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=RjeBll7F; 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]:47610 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9VF-0007G7-4F for patch@linaro.org; Fri, 10 May 2019 13:40:13 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59248) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hP9Mb-0007WQ-5s for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hP9Ma-0006BS-4z for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:17 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:41832) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hP9MZ-0006Ax-VS for qemu-devel@nongnu.org; Fri, 10 May 2019 13:31:16 -0400 Received: by mail-pg1-x536.google.com with SMTP id z3so3329166pgp.8 for ; Fri, 10 May 2019 10:31:15 -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=RjeBll7F2XfVW0Fos68V1JZ1XYmFQC/be0V6fR3mzqCne3S7j002nc6dhYdmOjQJ8w OYXEMa6OyvHaH31Pz43TCMnbl+S+Q6DgBitHESuwBq4AXKFZtqGqezx6SiT7Y0ZpL0CK 7lnLGG8yHmsYqd3hhS5kdFhPDXFrvWdcwWwUqDc1223nTv/6I8V5b4fm5QljfV5Y5yza 2Zxag66oHEFOMjDDizUiiwi2imuPuSDkCAWzzy5Vymo4pVXl8lR0tgf1NTn3NL5EaPGl bYRSzYsfzlGrYphoEZQ+btl0ZnRe7E+HVPZIGMSBD1t0zTEFek6Jp7d9ciSyxQRxKBSV 8O3g== 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=JNYc5W+LSqpRG4PWB/JgOaAtKHeteikdHp/EYibk96BHOYmouAXWHUGLupDA2MiXop O8z+FW2+XQOUPealcfdnYap01CK0+4RbvOrAbzjXm9NIoKrF8CvgR5C/Epgfyrkwcb2h LUGOnho+zvZ9zdNWRknXT/GG5BFOyjBoYQOXsuw6sGtEtcS8JxWAJnFR0xAo0XV5D0UT whQJUBuCRvFNZr3OHtDI1Bik8yJGmtIlT5g42dxbqHSVLHHiK3c9logMbwFNMNs8SHbz AIdLWYwDDtc4hX6Ys+7qoby7WrxwTcTA6iQpxcHpTpjBiLUkWcQTrTmPDs6stCHyq/Ud ByfA== X-Gm-Message-State: APjAAAWHEp9XfDUYqjoIbmZyjOrbXAGY1RDn3CTSpIhezpLAeggwIL+N Qvd0gvMhu041FXC66k78InvHJXgUuw0= X-Received: by 2002:a65:644e:: with SMTP id s14mr15629617pgv.290.1557509474699; Fri, 10 May 2019 10:31:14 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id v64sm7936792pfv.106.2019.05.10.10.31.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 10 May 2019 10:31:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Fri, 10 May 2019 10:30:43 -0700 Message-Id: <20190510173049.28171-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510173049.28171-1-richard.henderson@linaro.org> References: <20190510173049.28171-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::536 Subject: [Qemu-devel] [PATCH v6 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: 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; }