From patchwork Wed Jun 13 11:48:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 928842 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=jms.id.au Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="aTuvvlVt"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 415Q5c5yQMz9ry1 for ; Wed, 13 Jun 2018 21:49:24 +1000 (AEST) Received: from localhost ([::1]:33335 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fT4HC-0000Ei-I8 for incoming@patchwork.ozlabs.org; Wed, 13 Jun 2018 07:49:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34421) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fT4Gn-0000Ec-IP for qemu-devel@nongnu.org; Wed, 13 Jun 2018 07:48:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fT4Gi-00069u-Tm for qemu-devel@nongnu.org; Wed, 13 Jun 2018 07:48:57 -0400 Received: from mail-pl0-x244.google.com ([2607:f8b0:400e:c01::244]:42942) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fT4Gi-00069L-MY; Wed, 13 Jun 2018 07:48:52 -0400 Received: by mail-pl0-x244.google.com with SMTP id w17-v6so1402688pll.9; Wed, 13 Jun 2018 04:48:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=jgwnPRRh27YQYslsZ8Dh2Suw4Hfu3PHVCPixgXnYnqw=; b=aTuvvlVtO60afbdMg1IDTDK64KZZcsjYJlMu/QNzbGEaq0FRSg03CirOZAZ/InZpzt Jslc14b/RduTYM9d48UgL3TjZh8KHCPaZ2MCGYvHUxMfLqAzDXwB2ApxJjNmzBNvOHUb oYir9ujvm8GnDsshZZfU8x271dFXNfqE2K/oP2NCB/keRf2aVJjQJogcwfmPWu5VAGAO PN0zb04XTcYYIQ8qcdDeJWvaciZw++nRox22Agc302Kdv6VRh4EDZrtqUF97EmxKgtf6 U+JlaJw9RipGdRIy8UzYrNUDrOR6wFO/owBqY9U3n2h2xwsHqaK6ZpVxU6Ciubpmclln J4Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=jgwnPRRh27YQYslsZ8Dh2Suw4Hfu3PHVCPixgXnYnqw=; b=dhDDPBpkfuQ5Rw0WnAF/xZe46UMcQ1r7ppdqzaZrLya4dMrmyFpxjlD2hkZW8uW2sW uTTp/LjLRUgx+24Xse2pLIMatG4OlsxD43rVaQJ5UoYFUaXg0SvF1QfPrQdC2hnbNezz 1jBCppb9cyvSBbqSudkoGrq/tfBkmjhg4+9kywDAU0m/Zkf3qvNctKXbSu1x2WGHVaS6 5Q2hXZcT8Y9IhVVhXDhDbJN42ioGl9Ksq2A87p2ptvVDmj0hxHSFTEwlfb0QrxvpasNu Vpj5hZqOcJxrgb2PVM2lzRGVNhYBzksjXDdOKwHrvKt2OYrUbLPJsq/iCRVyKSUquzX3 NSnQ== X-Gm-Message-State: APt69E2Fm5Q+6a/yQddFVbE3BsvDjX/NcjvIj9XV8L3Vjen6GBWSciGR FEBRnkwfeGM/4Xo0vy4w1ko= X-Google-Smtp-Source: ADUXVKIwPKx+54NKkmUg1mqzGjdHDHyGJUXO/ZpSxW+LEVH649e6WqIP2vhe7wMpcRv8UbYT0y0WCw== X-Received: by 2002:a17:902:1029:: with SMTP id b38-v6mr4771604pla.277.1528890531113; Wed, 13 Jun 2018 04:48:51 -0700 (PDT) Received: from aurora.jms.id.au ([45.124.203.19]) by smtp.gmail.com with ESMTPSA id c67-v6sm4988328pfj.173.2018.06.13.04.48.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 13 Jun 2018 04:48:50 -0700 (PDT) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Wed, 13 Jun 2018 21:18:44 +0930 From: Joel Stanley To: Peter Maydell , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , qemu-devel@nongnu.org, qemu-arm@nongnu.org Date: Wed, 13 Jun 2018 21:18:36 +0930 Message-Id: <20180613114836.9265-1-joel@jms.id.au> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c01::244 Subject: [Qemu-devel] [PATCH v4] aspeed_scu: Implement RNG register 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: Andrew Jeffery Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The ASPEED SoCs contain a single register that returns random data when read. This models that register so that guests can use it. The random number data register has a corresponding control register, however it returns data regardless of the state of the enabled bit, so the model follows this behaviour. When the qcrypto call fails we exit as the guest uses the random number device to feed it's entropy pool, which is used for cryptographic purposes. Reviewed-by: Cédric Le Goater Signed-off-by: Joel Stanley --- v2: - Remove call to qcrypto_random_init as this is done in main() v3: - Add Cédric's reviewed-by - Add a comment about why we don't check for the rng enable bit v4: - Bail out when random number api fails --- hw/misc/aspeed_scu.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hw/misc/aspeed_scu.c b/hw/misc/aspeed_scu.c index 5e6d5744eeca..59315010db9a 100644 --- a/hw/misc/aspeed_scu.c +++ b/hw/misc/aspeed_scu.c @@ -16,6 +16,7 @@ #include "qapi/visitor.h" #include "qemu/bitops.h" #include "qemu/log.h" +#include "crypto/random.h" #include "trace.h" #define TO_REG(offset) ((offset) >> 2) @@ -154,6 +155,19 @@ static const uint32_t ast2500_a1_resets[ASPEED_SCU_NR_REGS] = { [BMC_DEV_ID] = 0x00002402U }; +static uint32_t aspeed_scu_get_random(void) +{ + Error *err = NULL; + uint32_t num; + + if (qcrypto_random_bytes((uint8_t *)&num, sizeof(num), &err)) { + error_report_err(err); + exit(1); + } + + return num; +} + static uint64_t aspeed_scu_read(void *opaque, hwaddr offset, unsigned size) { AspeedSCUState *s = ASPEED_SCU(opaque); @@ -167,6 +181,12 @@ static uint64_t aspeed_scu_read(void *opaque, hwaddr offset, unsigned size) } switch (reg) { + case RNG_DATA: + /* On hardware, RNG_DATA works regardless of + * the state of the enable bit in RNG_CTRL + */ + s->regs[RNG_DATA] = aspeed_scu_get_random(); + break; case WAKEUP_EN: qemu_log_mask(LOG_GUEST_ERROR, "%s: Read of write-only offset 0x%" HWADDR_PRIx "\n",