From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72096C2D0A3 for ; Fri, 6 Nov 2020 15:31:33 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0CC36208C7 for ; Fri, 6 Nov 2020 15:31:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="REpsJB0F" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0CC36208C7 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=misterjones.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Type: Content-Transfer-Encoding:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Message-ID:References:In-Reply-To:Subject:To:From: Date:MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=IvFbWqn6d8WWnvQatmU3+kHHlFavYa2XdF/iKd9t4IU=; b=REpsJB0FUj7dxbIl8UD/02P1n 7OCYSRaW2AX1TmbqQzi6XSNJCfTLzob+QxRzs2uudNHIPK1yaDfTgL+JfNIvTKKdCqbD3fTp6XgZi FdRBtlDfxnKMg+u79VhwLp/lIGYYnCeR74qrAdtJ/C0GK4322IYOReyYxjv5zwK+fppuJ55N4JJnf 7g9ZgJ//ibwI5TXOnzFSAvo6Mcn0w3exP99xFiY9dMXCuoe1GB8G5skofJOa74G2Sl0HB4jmsJFN4 Hvvy+eMaGApbeoDP/s9jMDGATpvXAD91TdsLfDIDXf/cCzTh6Ck7ConyDHLfDWikG17HvfViPS9mb L9ycTwwgg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kb3gu-0005km-Vs; Fri, 06 Nov 2020 15:30:17 +0000 Received: from disco-boy.misterjones.org ([51.254.78.96]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kb3gr-0005k4-W5 for linux-arm-kernel@lists.infradead.org; Fri, 06 Nov 2020 15:30:14 +0000 Received: from disco-boy.misterjones.org ([51.254.78.96] helo=www.loen.fr) by disco-boy.misterjones.org with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94) (envelope-from ) id 1kb3gc-008Eeb-Vr; Fri, 06 Nov 2020 15:29:59 +0000 MIME-Version: 1.0 Date: Fri, 06 Nov 2020 15:29:58 +0000 From: Marc Zyngier To: Andre Przywara Subject: Re: [PATCH v2 3/5] ARM: implement support for SMCCC TRNG entropy source In-Reply-To: <20201105125656.25259-4-andre.przywara@arm.com> References: <20201105125656.25259-1-andre.przywara@arm.com> <20201105125656.25259-4-andre.przywara@arm.com> User-Agent: Roundcube Webmail/1.4.9 Message-ID: <7b36daa49c78d60dc788bbb3c9c1bdaa@misterjones.org> X-Sender: maz@misterjones.org X-SA-Exim-Connect-IP: 51.254.78.96 X-SA-Exim-Rcpt-To: andre.przywara@arm.com, will@kernel.org, catalin.marinas@arm.com, ardb@kernel.org, linux@armlinux.org.uk, lorenzo.pieralisi@arm.com, linus.walleij@linaro.org, linux-kernel@vger.kernel.org, broonie@kernel.org, sudeep.holla@arm.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org X-SA-Exim-Mail-From: maz@misterjones.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201106_103014_052653_CA39CE5F X-CRM114-Status: GOOD ( 24.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Lorenzo Pieralisi , Catalin Marinas , Linus Walleij , Russell King , linux-kernel@vger.kernel.org, Mark Brown , kvmarm@lists.cs.columbia.edu, Sudeep Holla , Will Deacon , Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2020-11-05 12:56, Andre Przywara wrote: > From: Ard Biesheuvel > > Implement arch_get_random_seed_*() for ARM based on the firmware > or hypervisor provided entropy source described in ARM DEN0098. > > This will make the kernel's random number generator consume entropy > provided by this interface, at early boot, and periodically at > runtime when reseeding. > > Cc: Linus Walleij > Cc: Russell King > Signed-off-by: Ard Biesheuvel > [Andre: rework to be initialised by the SMCCC firmware driver] > Signed-off-by: Andre Przywara > --- > arch/arm/Kconfig | 4 ++ > arch/arm/include/asm/archrandom.h | 64 +++++++++++++++++++++++++++++++ > 2 files changed, 68 insertions(+) > > diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig > index fe2f17eb2b50..06fda4f954fd 100644 > --- a/arch/arm/Kconfig > +++ b/arch/arm/Kconfig > @@ -1667,6 +1667,10 @@ config STACKPROTECTOR_PER_TASK > Enable this option to switch to a different method that uses a > different canary value for each task. > > +config ARCH_RANDOM > + def_bool y > + depends on HAVE_ARM_SMCCC > + > endmenu > > menu "Boot options" > diff --git a/arch/arm/include/asm/archrandom.h > b/arch/arm/include/asm/archrandom.h > index a8e84ca5c2ee..f3e96a5b65f8 100644 > --- a/arch/arm/include/asm/archrandom.h > +++ b/arch/arm/include/asm/archrandom.h > @@ -2,9 +2,73 @@ > #ifndef _ASM_ARCHRANDOM_H > #define _ASM_ARCHRANDOM_H > > +#ifdef CONFIG_ARCH_RANDOM > + > +#include > +#include > + > +#define ARM_SMCCC_TRNG_MIN_VERSION 0x10000UL > + > +extern bool smccc_trng_available; > + > +static inline bool __init smccc_probe_trng(void) > +{ > + struct arm_smccc_res res; > + > + arm_smccc_1_1_invoke(ARM_SMCCC_TRNG_VERSION, &res); > + if ((s32)res.a0 < 0) > + return false; > + if (res.a0 >= ARM_SMCCC_TRNG_MIN_VERSION) { > + /* double check that the 32-bit flavor is available */ > + arm_smccc_1_1_invoke(ARM_SMCCC_TRNG_FEATURES, > + ARM_SMCCC_TRNG_RND32, > + &res); > + if ((s32)res.a0 >= 0) > + return true; > + } > + > + return false; > +} > + > +static inline bool __must_check arch_get_random_long(unsigned long *v) > +{ > + return false; > +} > + > +static inline bool __must_check arch_get_random_int(unsigned int *v) > +{ > + return false; > +} > + > +static inline bool __must_check arch_get_random_seed_long(unsigned > long *v) > +{ > + struct arm_smccc_res res; > + > + if (smccc_trng_available) { > + arm_smccc_1_1_invoke(ARM_SMCCC_TRNG_RND32, 8 * sizeof(*v), &res); > + > + if (res.a0 != 0) > + return false; > + > + *v = res.a3; > + return true; > + } > + > + return false; > +} > + > +static inline bool __must_check arch_get_random_seed_int(unsigned int > *v) > +{ > + return arch_get_random_seed_long((unsigned long *)v); I don't think this cast is safe. At least not on 64bit. M. -- Who you jivin' with that Cosmik Debris? _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel