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: 138440 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp612938lji; Wed, 13 Jun 2018 04:49:12 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK2++txyxKU2ap9ROqeQ71wMKRvApgRC4psKaZ/h4DInqep6KZTQ046QAyYebGQNiikcuXd X-Received: by 2002:a37:e103:: with SMTP id c3-v6mr4106101qkm.69.1528890551990; Wed, 13 Jun 2018 04:49:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528890551; cv=none; d=google.com; s=arc-20160816; b=hKrCJQNjMt4d8wW3x41YyNtrzRoF7Cs475mMZ0nKB0w9GTCnrzJpLRNCyW8ahnmoYC 7kj5+OpauoFzrp0GMxNQCHFTPpGA5vhKV+kw48ptLCN3dHvTaT8zOiACTkhq4PsKKFPo BOm8zWsdDp45xhzHIyCBHumi63EcZorn200W/Y9hovn6fWxQvbi6maJwZhYjKAiXDmQy Y5/9uOP5to1SnnN2cAxmBYmzCa0Zlb84BOSsUnT1eXVcfwRS60PJw36GXoZeLDfeqiTG vHM6dCB7Gxq3V1+IMxdbIt5g5iO1f0VOwC74KmNnKq6jik1KT90Ivzdsvmi9lx6isDsX i6ag== 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:message-id:date:to:from :dkim-signature:arc-authentication-results; bh=jgwnPRRh27YQYslsZ8Dh2Suw4Hfu3PHVCPixgXnYnqw=; b=u44737bNE9edv/vovb+sislJpTJW4o6caGvt89qRnWsqPHq6mD1N5XwH9F43rVEQRP 3thfxXRdFq7AZr4eQR/sVXpPRssUM/VudHeUmdL/AENWiJy78CJfaAM9dCtJaTBdVzq/ kb8lWtiyXzAPQsdhD3aE2rt1bIKaPr1FKHahD/9bDlt2m6sryjx6RcdMHzm6u1Qq27AJ pLrM7Z3d3lQopUiTkCwF5jTQZvx1eN4AWxgESwmCr1VXRhbDVpapm5xnMmEzoroNKTL3 CGDUaQPq+DOGRS8x1ZOQEUgFqhV1/1C4xbtFwx08gXvuBRADXheMPkk1XVeePTVbsxvl lJdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=aTuvvlVt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id w1-v6si2431285qtw.289.2018.06.13.04.49.11 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 13 Jun 2018 04:49:11 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=aTuvvlVt; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org" Received: from localhost ([::1]:33335 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fT4H1-0000Ei-Ha for patch@linaro.org; Wed, 13 Jun 2018 07:49:11 -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-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+patch=linaro.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(+) -- 2.17.1 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",