From nobody Wed May 8 20:41:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+95317+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95317+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1666099833; cv=none; d=zohomail.com; s=zohoarc; b=dFvuh/96vHGJlNWa36irjPb+yfz50OCuDC0Ye5NyVWpqOpSYR4JuT5tIX0n0lfB34hsKsHWvO9U92GWSDOtdkiwDbm+/a25fqJRAw9ANFN8CLFiA3435SMupJMwYmhB6oRDGHErMA/6tDHQx+k3fwiIzI3/3Bv/hV9Sv1q2FRj4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666099833; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=d+BaOcVI3m/ZP4o4sLhGCS1zvUf23yUKebD9zGVe/Fs=; b=Ok5uaf0TKpDlkLgs6/TOdmwLjLDuBU9lVQQqT9OWdLj6bhedEdrVXm1BjLJLt7F9mUw0RCXv9F652YXwpe8KRBXSrkOE70pUM2E5qKPGEA99pkIpyn8h+t12rF+vN4c9c6ZboMN8j4WYlUTxdLDH2NmLy2eA8R8jxO+d5LJXJ3c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95317+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1666099833283595.624235077923; Tue, 18 Oct 2022 06:30:33 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id bLUsYY1788612xU6COIdLSOB; Tue, 18 Oct 2022 06:30:32 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.6805.1666099832318890770 for ; Tue, 18 Oct 2022 06:30:32 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3A19C1758; Tue, 18 Oct 2022 06:30:38 -0700 (PDT) X-Received: from pierre123.arm.com (pierre123.nice.arm.com [10.34.100.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9C7533F792; Tue, 18 Oct 2022 06:30:30 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v8 01/19] ArmPkg: PCD to select conduit for monitor calls Date: Tue, 18 Oct 2022 15:20:34 +0200 Message-Id: <20221018132052.1359530-2-Pierre.Gondois@arm.com> In-Reply-To: <20221018132052.1359530-1-Pierre.Gondois@arm.com> References: <20221018132052.1359530-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: nyLobVC7WFGJpg09dEwd5h4Ox1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1666099832; bh=44lNH4wXFRDUw/xHno9HdECMVCz7F52xUm4PPk7CXgY=; h=Cc:Date:From:Reply-To:Subject:To; b=sprJXjjJ9ZS+XiRZ5rrmpgx6D+jnPpDyzOwZ0lM30nMEnvfZl6erq4VS3WSprxMjIiY IxPdzeKFKPN0UuFAgJPdXI3Thq70Js7bPBceCULQI1NQX72KrUUULFnY+Hoab1+7v4Zp9 PyruSrQtCP3gay7W1C5A/QbVxRG5oRL9dBY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1666099835359100003 Content-Type: text/plain; charset="utf-8" From: Sami Mujawar Define a PCD 'PcdMonitorConduitHvc' to select the conduit to use for monitor calls. PcdMonitorConduitHvc is defined as FALSE by default, meaning the SMC conduit is enabled as default. Adding PcdMonitorConduitHvc allows selection of HVC conduit to be used by virtual firmware implementations. Reviewed-by: Leif Lindholm Signed-off-by: Pierre Gondois --- ArmPkg/ArmPkg.dec | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ArmPkg/ArmPkg.dec b/ArmPkg/ArmPkg.dec index 9da1bbc9f216..bb5cbecbc228 100644 --- a/ArmPkg/ArmPkg.dec +++ b/ArmPkg/ArmPkg.dec @@ -2,7 +2,7 @@ # ARM processor package. # # Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.
-# Copyright (c) 2011 - 2021, ARM Limited. All rights reserved. +# Copyright (c) 2011 - 2022, ARM Limited. All rights reserved. # Copyright (c) 2021, Ampere Computing LLC. All rights reserved. # # SPDX-License-Identifier: BSD-2-Clause-Patent @@ -132,6 +132,11 @@ [PcdsFeatureFlag.common] # Define if the GICv3 controller should use the GICv2 legacy gArmTokenSpaceGuid.PcdArmGicV3WithV2Legacy|FALSE|BOOLEAN|0x00000042 =20 + ## Define the conduit to use for monitor calls. + # Default PcdMonitorConduitHvc =3D FALSE, conduit =3D SMC + # If PcdMonitorConduitHvc =3D TRUE, conduit =3D HVC + gArmTokenSpaceGuid.PcdMonitorConduitHvc|FALSE|BOOLEAN|0x00000047 + [PcdsFeatureFlag.ARM] # Whether to map normal memory as non-shareable. FALSE is the safe choic= e, but # TRUE may be appropriate to fix performance problems if you don't care = about --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95317): https://edk2.groups.io/g/devel/message/95317 Mute This Topic: https://groups.io/mt/94407732/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 8 20:41:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+95318+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95318+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1666099836; cv=none; d=zohomail.com; s=zohoarc; b=bxULTi7H1w8u/5AVFVJrTNlrEyIhGNHzhIbyTGXr50BOpw2Zp0JvVZH4WRTqsGjQ44v2OZ+qvxN4lZ03t+dS2q9paZxFz2Niot9/NPcwu1SmWQZKmmZRmSEFzXehtlwvpPYPo4UQ/S9+e5lgHaQ6oG1bdZErfAMUh9RSo1Wb1LA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666099836; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=a/Zt7lgKIOz1TNp1ne3ybo0EU78YkfjWbrJY3rnHY9g=; b=ZBkajdOoMdm6GoiWbBNTM6pNa0x6s49H+psYtLzzZN3r1zBUqFYMypDDAPgoXv1ScnnWPYhZOijQkX9tVapfFIP3VXuGsyqACuWtRP/Yiu3EPQxtJ/6OB8THgxoM0/b5NKc4b9YyhPsTielBKiDdhAM8T6eJkLyzqTjPZXoOd1E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95318+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1666099836400889.2429517780811; Tue, 18 Oct 2022 06:30:36 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id stRTYY1788612xQfZVAm3Lan; Tue, 18 Oct 2022 06:30:35 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.6885.1666099834399850098 for ; Tue, 18 Oct 2022 06:30:34 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D7721244B; Tue, 18 Oct 2022 06:30:39 -0700 (PDT) X-Received: from pierre123.arm.com (pierre123.nice.arm.com [10.34.100.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 458E13F792; Tue, 18 Oct 2022 06:30:32 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v8 02/19] ArmPkg/ArmMonitorLib: Definition for ArmMonitorLib library class Date: Tue, 18 Oct 2022 15:20:35 +0200 Message-Id: <20221018132052.1359530-3-Pierre.Gondois@arm.com> In-Reply-To: <20221018132052.1359530-1-Pierre.Gondois@arm.com> References: <20221018132052.1359530-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: C0HFvajrasg1zULDiv8uRWX0x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1666099835; bh=CoHqEcJRL403mCep9kv/m5tetyVtcR4HfEbUArQT6Qk=; h=Cc:Date:From:Reply-To:Subject:To; b=HgbAp/bhCP8Zqut9HZrOHRlZyh6I0RAPWqekoN16qqNGJLneVXgxA46VVhPGjKoWX7H nma5ownXMWym4CZf+kEKn5mthY310MEUcfagnD4vR2FkD/Ewap8nT7EB1QAnUP/dJvYQK HeuJWmWoi80bclSN2OK8L9GLB4FZhfdvKXA= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1666099837484100009 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois The ArmMonitorLib provides an abstract interface to issue an HyperVisor Call (HVC) or System Monitor Call (SMC) depending on the default conduit. The PcdMonitorConduitHvc PCD allows to select the default conduit. The new library relies on the ArmHvcLib and ArmSmcLib libraries. A Null instance of these libraries can be used for the unused conduit. Reviewed-by: Leif Lindholm Signed-off-by: Pierre Gondois --- ArmPkg/ArmPkg.dec | 5 +++ ArmPkg/Include/Library/ArmMonitorLib.h | 42 ++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 ArmPkg/Include/Library/ArmMonitorLib.h diff --git a/ArmPkg/ArmPkg.dec b/ArmPkg/ArmPkg.dec index bb5cbecbc228..653942ff63c3 100644 --- a/ArmPkg/ArmPkg.dec +++ b/ArmPkg/ArmPkg.dec @@ -71,6 +71,11 @@ [LibraryClasses.common] # ArmSvcLib|Include/Library/ArmSvcLib.h =20 + ## @libraryclass Provides a Monitor Call interface that will use the + # default conduit (HVC or SMC). + # + ArmMonitorLib|Include/Library/ArmMonitorLib.h + ## @libraryclass Provides a default exception handler. # DefaultExceptionHandlerLib|Include/Library/DefaultExceptionHandlerLib.h diff --git a/ArmPkg/Include/Library/ArmMonitorLib.h b/ArmPkg/Include/Librar= y/ArmMonitorLib.h new file mode 100644 index 000000000000..d6e13b61d63d --- /dev/null +++ b/ArmPkg/Include/Library/ArmMonitorLib.h @@ -0,0 +1,42 @@ +/** @file + + Copyright (c) 2022, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef ARM_MONITOR_LIB_H_ +#define ARM_MONITOR_LIB_H_ + +/** The size of the SMC arguments is different between AArch64 and AArch32. + + The native size is used for the arguments. + It will be casted to either HVC or SMC args. +*/ +typedef struct { + UINTN Arg0; + UINTN Arg1; + UINTN Arg2; + UINTN Arg3; + UINTN Arg4; + UINTN Arg5; + UINTN Arg6; + UINTN Arg7; +} ARM_MONITOR_ARGS; + +/** Monitor call. + + An HyperVisor Call (HVC) or System Monitor Call (SMC) will be issued + depending on the default conduit. PcdMonitorConduitHvc determines the ty= pe + of the call: if true, do an HVC. + + @param [in,out] Args Arguments for the HVC/SMC. +**/ +VOID +EFIAPI +ArmMonitorCall ( + IN OUT ARM_MONITOR_ARGS *Args + ); + +#endif // ARM_MONITOR_LIB_H_ --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95318): https://edk2.groups.io/g/devel/message/95318 Mute This Topic: https://groups.io/mt/94407737/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 8 20:41:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+95319+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95319+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1666099836; cv=none; d=zohomail.com; s=zohoarc; b=ADQyRirOvXbGYbDqmqBA/awA0Guhe12+PXhNdf71WebcRgUUK8RhZli3ov6128VrrKIEwTSiUKGWgpiupQEzOntsmM28CMpwAB6poj6c273ECzOjYh+EsBHN2Ui0XtQX6MSVorVYzTypjfTjQamcz4H8vX3ZQS3CU2tpMh0yhvo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666099836; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=t+fxlsxjfgCwOpm/PxR9MbW8aPX3+rP4L5mby9pFqIM=; b=DPdcD+I8L4GXf4lon5kEQVoOjkNCyLJArLVFTP45Q+3aqqFU5WlnXzplr8fJsiZxmE0LSOXzRylFI9qU1Og3jkLzVXlfvuLXlh3vGNCUpbcMWh+G44Ef7XJ+K0cB/Uspibu31IyWVltIl/Qm5X+D3R1oNIbQo4BaUzTF1oXg+DI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95319+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1666099836911716.2304972766531; Tue, 18 Oct 2022 06:30:36 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id dPVZYY1788612x9XBXFU3tn2; Tue, 18 Oct 2022 06:30:36 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.6886.1666099835726885409 for ; Tue, 18 Oct 2022 06:30:35 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 803322454; Tue, 18 Oct 2022 06:30:41 -0700 (PDT) X-Received: from pierre123.arm.com (pierre123.nice.arm.com [10.34.100.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E2F673F792; Tue, 18 Oct 2022 06:30:33 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v8 03/19] ArmPkg/ArmMonitorLib: Add ArmMonitorLib Date: Tue, 18 Oct 2022 15:20:36 +0200 Message-Id: <20221018132052.1359530-4-Pierre.Gondois@arm.com> In-Reply-To: <20221018132052.1359530-1-Pierre.Gondois@arm.com> References: <20221018132052.1359530-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: tyVMspk6s2ptCrYFKQoM56lWx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1666099836; bh=bh1UFI5AwGU/w/w9S2wg+4LWf4yMRFg9MT7n1FZXV4s=; h=Cc:Date:From:Reply-To:Subject:To; b=iQUCKKyGFCNtiNz2Oq9BOhMJQr/mMfVQcb/2gBNzqnYpmrN5h77txOrWhbC5s4m2/Y7 Q+Hoc077zv0KWcvCfk6dMTgSDNIdJZjwS6IdETg/YUHdI0X8JW0vBPwKe8j/EhMHm+jaD VHFtH4KdLsOu4pBZZ1a1Hzv87WbRQexUEW8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1666099837502100011 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois The ArmMonitorLib provides an abstract interface to issue an HyperVisor Call (HVC) or System Monitor Call (SMC) depending on the default conduit. The PcdMonitorConduitHvc PCD allows to select the default conduit. Reviewed-by: Leif Lindholm Signed-off-by: Pierre Gondois --- ArmPkg/ArmPkg.dsc | 1 + ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.c | 34 +++++++++++++++++++ .../Library/ArmMonitorLib/ArmMonitorLib.inf | 29 ++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.c create mode 100644 ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.inf diff --git a/ArmPkg/ArmPkg.dsc b/ArmPkg/ArmPkg.dsc index 59fd8f295d4f..3afd212f472b 100644 --- a/ArmPkg/ArmPkg.dsc +++ b/ArmPkg/ArmPkg.dsc @@ -135,6 +135,7 @@ [Components.common] ArmPkg/Library/ArmSmcLibNull/ArmSmcLibNull.inf ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf ArmPkg/Library/ArmSvcLib/ArmSvcLib.inf + ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.inf ArmPkg/Library/OpteeLib/OpteeLib.inf =20 ArmPkg/Filesystem/SemihostFs/SemihostFs.inf diff --git a/ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.c b/ArmPkg/Library/= ArmMonitorLib/ArmMonitorLib.c new file mode 100644 index 000000000000..741f5c615744 --- /dev/null +++ b/ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.c @@ -0,0 +1,34 @@ +/** @file + Arm Monitor Library. + + Copyright (c) 2022, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include + +/** Monitor call. + + An HyperVisor Call (HVC) or System Monitor Call (SMC) will be issued + depending on the default conduit. PcdMonitorConduitHvc determines the ty= pe + of the call: if true, do an HVC. + + @param [in,out] Args Arguments for the HVC/SMC. +**/ +VOID +EFIAPI +ArmMonitorCall ( + IN OUT ARM_MONITOR_ARGS *Args + ) +{ + if (FeaturePcdGet (PcdMonitorConduitHvc)) { + ArmCallHvc ((ARM_HVC_ARGS *)Args); + } else { + ArmCallSmc ((ARM_SMC_ARGS *)Args); + } +} diff --git a/ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.inf b/ArmPkg/Librar= y/ArmMonitorLib/ArmMonitorLib.inf new file mode 100644 index 000000000000..f504cb80f1fc --- /dev/null +++ b/ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.inf @@ -0,0 +1,29 @@ +## @file +# Arm Monitor Library +# +# Copyright (c) 2022, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D ArmMonitorLib + FILE_GUID =3D F918DACB-FBB8-4CB6-A61D-08E75AF0E7CD + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D ArmMonitorLib + +[Sources] + ArmMonitorLib.c + +[Packages] + ArmPkg/ArmPkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + ArmHvcLib + ArmSmcLib + +[Pcd] + gArmTokenSpaceGuid.PcdMonitorConduitHvc --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95319): https://edk2.groups.io/g/devel/message/95319 Mute This Topic: https://groups.io/mt/94407738/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 8 20:41:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+95320+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95320+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1666099839; cv=none; d=zohomail.com; s=zohoarc; b=miQK5FI7SN3jO11qtf9XMEdFIBY8IYwCK3NM1g90fON1VJg4QmgmA2A92+bzsGSce3XbuykShgPq5B+k0Gf7dssi47FJCz2y1DhCNt5eQey4u6hNpbMZoUk1imyNgpZ54YAIjuiqC0xD3QPU6XtLshzjk79w4jRESpN5Zu0JJnU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666099839; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=x1heUv2w0+kDuV8T4iZmaxItgWfZ7zjFBOgPdjYFW9E=; b=K3hyXPXxI56RVXkMIF92tv+/SHiCtF+l5c9xDuguv7dmx6Vt42X470a4b4RoogPcZkVdJSrb2WhwleURW29pBb4/NUWe373nrKGBSa1lbC/SUDcrOnN6OhzzMZ4IIxRj5s3MukjjeLVH7ENQspZvWfvHpan+El5td9SGjZvDJkM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95320+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1666099839366751.2521574265708; Tue, 18 Oct 2022 06:30:39 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Df1VYY1788612xIQN6j1zWs3; Tue, 18 Oct 2022 06:30:38 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.6763.1666099837298543000 for ; Tue, 18 Oct 2022 06:30:37 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3281C24C0; Tue, 18 Oct 2022 06:30:43 -0700 (PDT) X-Received: from pierre123.arm.com (pierre123.nice.arm.com [10.34.100.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8BDE43F792; Tue, 18 Oct 2022 06:30:35 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v8 04/19] ArmPkg: Sort HVC/SMC section alphbetically in ArmPkg.dsc Date: Tue, 18 Oct 2022 15:20:37 +0200 Message-Id: <20221018132052.1359530-5-Pierre.Gondois@arm.com> In-Reply-To: <20221018132052.1359530-1-Pierre.Gondois@arm.com> References: <20221018132052.1359530-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: 9OPEsHr0AeEryWtahljziBjEx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1666099838; bh=t2yekGbiN3y0SY1eklpSjPKMRE1J071ZrrSgvra1gs4=; h=Cc:Date:From:Reply-To:Subject:To; b=vSQyZQovrObFvxmiSct26JbqlWPTJAfq9dfzlnW4rpUmGpMDG06Lw0p9YcKH+cwC8qA psrz8LqrdVbGZwKyClqusLIBFikmI/jW7CS8paZu+kHXVmI2/mSUngispjTfrrpMEs1N1 NGiWYTxzYzi0WF5PMmgGnT5QEU+7uKBWXs0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1666099841378100019 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois Sort the section containing HVC/SMC libraries prior to adding new libraries in this specific section. Reviewed-by: Leif Lindholm Signed-off-by: Pierre Gondois --- ArmPkg/ArmPkg.dsc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ArmPkg/ArmPkg.dsc b/ArmPkg/ArmPkg.dsc index 3afd212f472b..13e20a258e9e 100644 --- a/ArmPkg/ArmPkg.dsc +++ b/ArmPkg/ArmPkg.dsc @@ -131,11 +131,11 @@ [Components.common] ArmPkg/Library/ArmGenericTimerPhyCounterLib/ArmGenericTimerPhyCounterLib= .inf ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterL= ib.inf =20 + ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf + ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.inf ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf ArmPkg/Library/ArmSmcLibNull/ArmSmcLibNull.inf - ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf ArmPkg/Library/ArmSvcLib/ArmSvcLib.inf - ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.inf ArmPkg/Library/OpteeLib/OpteeLib.inf =20 ArmPkg/Filesystem/SemihostFs/SemihostFs.inf --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95320): https://edk2.groups.io/g/devel/message/95320 Mute This Topic: https://groups.io/mt/94407739/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 8 20:41:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+95321+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95321+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1666099839; cv=none; d=zohomail.com; s=zohoarc; b=QgljQp900JRLTPycQMCsm51e867uYi3hlfAckbZsKh+ZxKB6/jX/NnSvLuIbHlsqwsXogbt8i0Lyf3Yn2Smsa07qpqDRa7YHwsVv5A3ibu5p9oYU4Hh3gUxYi2wDuXCWbjJTEFaZT/Df+Pcy+1fbDbGjJ5ciV/FKgTPYCqsZ9nU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666099839; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=UBxy8JknWWyjfnR+L/rvL+8EnNG55ceob8Mkgshp4b0=; b=UTGaN8EA445fjo0Qqrs3Ay/Jlr/DuynMW+7LoPU2RVwTwwhP9i6bFbq68A0C2//TPQHhvfMhXJHDugO25+LbMmV8IG/TdyeWyg/5jqK1lMRlfL2Loj3Eao2nDIR/QSDeVWclgX5+6saUuFTUM1eNbPh1wfRo281eGqvflVPHfGU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95321+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1666099839949925.3610955992259; Tue, 18 Oct 2022 06:30:39 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Cp8tYY1788612xyopAIFWFII; Tue, 18 Oct 2022 06:30:39 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.6809.1666099838942711707 for ; Tue, 18 Oct 2022 06:30:39 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CFB5B24E9; Tue, 18 Oct 2022 06:30:44 -0700 (PDT) X-Received: from pierre123.arm.com (pierre123.nice.arm.com [10.34.100.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3DDF43F792; Tue, 18 Oct 2022 06:30:37 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v8 05/19] ArmPkg/ArmHvcLibNull: Add NULL instance of ArmHvcLib Date: Tue, 18 Oct 2022 15:20:38 +0200 Message-Id: <20221018132052.1359530-6-Pierre.Gondois@arm.com> In-Reply-To: <20221018132052.1359530-1-Pierre.Gondois@arm.com> References: <20221018132052.1359530-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: 1vTIML2gsC5LkVnB1m4rQi3Hx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1666099839; bh=toKakd+kwggWCH34OKfsIKQUcozPRxnqDN6YRdITcTU=; h=Cc:Date:From:Reply-To:Subject:To; b=FDzTgOESZP972FaqKqigo8MhFl+p7lU7k0PDSK+rcQXWi8qriEppd8s1k6/UgGAVHLC ZZRTaeS+SPX6fkswK3rMnAK7qjFU1Mnxm9mnwQCNSIO9908PIKHlCIrZ1dOL/V2dMj1X5 bSPFty0IJ/8gxtMsYU+fpUs0HI/yo8vhQGs= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1666099841381100020 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois Add a Null instance of ArmHvcLib in case of library dependencies. Reviewed-by: Leif Lindholm Signed-off-by: Pierre Gondois --- ArmPkg/ArmPkg.dsc | 1 + ArmPkg/Library/ArmHvcLibNull/ArmHvcLibNull.c | 29 +++++++++++++++++++ .../Library/ArmHvcLibNull/ArmHvcLibNull.inf | 22 ++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 ArmPkg/Library/ArmHvcLibNull/ArmHvcLibNull.c create mode 100644 ArmPkg/Library/ArmHvcLibNull/ArmHvcLibNull.inf diff --git a/ArmPkg/ArmPkg.dsc b/ArmPkg/ArmPkg.dsc index 13e20a258e9e..11b473974463 100644 --- a/ArmPkg/ArmPkg.dsc +++ b/ArmPkg/ArmPkg.dsc @@ -132,6 +132,7 @@ [Components.common] ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterL= ib.inf =20 ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf + ArmPkg/Library/ArmHvcLibNull/ArmHvcLibNull.inf ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.inf ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf ArmPkg/Library/ArmSmcLibNull/ArmSmcLibNull.inf diff --git a/ArmPkg/Library/ArmHvcLibNull/ArmHvcLibNull.c b/ArmPkg/Library/= ArmHvcLibNull/ArmHvcLibNull.c new file mode 100644 index 000000000000..8edda01a7f0a --- /dev/null +++ b/ArmPkg/Library/ArmHvcLibNull/ArmHvcLibNull.c @@ -0,0 +1,29 @@ +/** @file + Arm HyperVisor Call (HVC) Null Library. + + Copyright (c) 2022, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include + +/** + Trigger an HVC call + + HVC calls can take up to 8 arguments and return up to 4 return values. + Therefore, the 4 first fields in the ARM_HVC_ARGS structure are used + for both input and output values. + + @param [in,out] Args Arguments for the HVC call. +**/ +VOID +ArmCallHvc ( + IN OUT ARM_HVC_ARGS *Args + ) +{ + ASSERT (FALSE); + return; +} diff --git a/ArmPkg/Library/ArmHvcLibNull/ArmHvcLibNull.inf b/ArmPkg/Librar= y/ArmHvcLibNull/ArmHvcLibNull.inf new file mode 100644 index 000000000000..e390a5fbbe21 --- /dev/null +++ b/ArmPkg/Library/ArmHvcLibNull/ArmHvcLibNull.inf @@ -0,0 +1,22 @@ +## @file +# Arm Hvc Null Library +# +# Copyright (c) 2022, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D ArmHvcLibNull + FILE_GUID =3D 02076A46-D6DB-48DD-8E5F-153172DD73A1 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D ArmHvcLib + +[Sources] + ArmHvcLibNull.c + +[Packages] + ArmPkg/ArmPkg.dec + MdePkg/MdePkg.dec --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95321): https://edk2.groups.io/g/devel/message/95321 Mute This Topic: https://groups.io/mt/94407744/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 8 20:41:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+95322+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95322+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1666099841; cv=none; d=zohomail.com; s=zohoarc; b=Gwt5ns3ZDyCBFuteGZtNaFV1ylAuXVmm6qF1PfKz1vcOmMGkfww0BOdJ7bHAp1YGv4dYHXPSKMHnJ45EWjlidxfYDcluv4lKfVgTfA6T+/SMkm1tyKY8cRwst4aRl7MleTnTw/S4qz09n9RMTaA335GuoiWgDsxNZNnVuOBALJk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666099841; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=kCEABqJGC8xS7AtsNFLoXIg5MY/0lRJzGO5RhX3xK0A=; b=QDrpJcirh5aEQyDc/Jw+adhla+P6Eu9f785eZZKdQsYpoIh9JyVvcGRpUkV8dTR9JqPJLPYKR9Tmh/gPgae0mfeSYgX/QyRD5sZwC4q310vgdgRuviucVjRyQvjIKcGtwKHcIKcdoKWbuXvhbjUX/nOHrMvsC3WBWYeidic+Iug= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95322+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1666099841836772.3140850562526; Tue, 18 Oct 2022 06:30:41 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id R9BfYY1788612xkrtzAMkEIQ; Tue, 18 Oct 2022 06:30:41 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web09.6832.1666099840584355560 for ; Tue, 18 Oct 2022 06:30:40 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 791721758; Tue, 18 Oct 2022 06:30:46 -0700 (PDT) X-Received: from pierre123.arm.com (pierre123.nice.arm.com [10.34.100.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DB70C3F792; Tue, 18 Oct 2022 06:30:38 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v8 06/19] MdePkg/TrngLib: Definition for TRNG library class interface Date: Tue, 18 Oct 2022 15:20:39 +0200 Message-Id: <20221018132052.1359530-7-Pierre.Gondois@arm.com> In-Reply-To: <20221018132052.1359530-1-Pierre.Gondois@arm.com> References: <20221018132052.1359530-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: PJlD4DnQsY3FVMU2E5bH3gDEx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1666099841; bh=fvW6tyj5nupi/reiyBoMp+yOw35+zTCqX9LTizOIAO8=; h=Cc:Date:From:Reply-To:Subject:To; b=Q/eLGNJklyRLYIaEeTMFV72i43lrV7fxBGH9vVJciCED1YRn2z6cuPx3EC81hRLaRI6 TVBBtPRbRzaMlP439sjNYTWH8NrtWy5j8yFAOX/u0K/Eqc2JDj79tfjgQzWeO/J9F6jgl vYl0OMJmmKxZRbFGuGDduM80Zwnaxxgx3aY= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1666099843394100025 Content-Type: text/plain; charset="utf-8" From: Sami Mujawar Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3D3668) The NIST Special Publications 800-90A, 800-90B and 800-90C provide recommendations for random number generation. The NIST 800-90C, Recommendation for Random Bit Generator (RBG) Constructions, defines the GetEntropy() interface that is used to access the entropy source. The GetEntropy() interface is further used by Deterministic Random Bit Generators (DRBG) to generate random numbers. The True Random Number Generator (TRNG) library defines an interface to access the entropy source on a platform. Some platforms/architectures may provide access to the entropy using a firmware interface. In such cases the TRNG library shall be used to provide an abstraction. Signed-off-by: Pierre Gondois --- MdePkg/Include/Library/TrngLib.h | 103 +++++++++++++++++++++++++++++++ MdePkg/MdePkg.dec | 5 ++ 2 files changed, 108 insertions(+) create mode 100644 MdePkg/Include/Library/TrngLib.h diff --git a/MdePkg/Include/Library/TrngLib.h b/MdePkg/Include/Library/Trng= Lib.h new file mode 100644 index 000000000000..535fd53f4305 --- /dev/null +++ b/MdePkg/Include/Library/TrngLib.h @@ -0,0 +1,103 @@ +/** @file + TRNG interface library definitions. + + Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - [1] NIST Special Publication 800-90B, Recommendation for the Entropy + Sources Used for Random Bit Generation. + (https://csrc.nist.gov/publications/detail/sp/800-90b/final) + + @par Glossary: + - TRNG - True Random Number Generator +**/ + +#ifndef TRNG_LIB_H_ +#define TRNG_LIB_H_ + +/** Get the version of the TRNG backend. + + A TRNG may be implemented by the system firmware, in which case this + function shall return the version of the TRNG backend. + The implementation must return NOT_SUPPORTED if a Back end is not presen= t. + + @param [out] MajorRevision Major revision. + @param [out] MinorRevision Minor revision. + + @retval RETURN_SUCCESS The function completed successfully. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Backend not present. +**/ +RETURN_STATUS +EFIAPI +GetTrngVersion ( + OUT UINT16 *MajorRevision, + OUT UINT16 *MinorRevision + ); + +/** Get the UUID of the TRNG backend. + + A TRNG may be implemented by the system firmware, in which case this + function shall return the UUID of the TRNG backend. + Returning the TRNG UUID is optional and if not implemented, RETURN_UNSUP= PORTED + shall be returned. + + Note: The caller must not rely on the returned UUID as a trustworthy TRNG + Back end identity + + @param [out] Guid UUID of the TRNG backend. + + @retval RETURN_SUCCESS The function completed successfully. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Function not implemented. +**/ +RETURN_STATUS +EFIAPI +GetTrngUuid ( + OUT GUID *Guid + ); + +/** Returns maximum number of entropy bits that can be returned in a single + call. + + @return Returns the maximum number of Entropy bits that can be returned + in a single call to GetTrngEntropy(). +**/ +UINTN +EFIAPI +GetTrngMaxSupportedEntropyBits ( + VOID + ); + +/** Returns N bits of conditioned entropy. + + See [1] Section 2.3.1 GetEntropy: An Interface to the Entropy Source + GetEntropy + Input: + bits_of_entropy: the requested amount of entropy + Output: + entropy_bitstring: The string that provides the requested entropy. + status: A Boolean value that is TRUE if the request has been satisfi= ed, + and is FALSE otherwise. + + @param [in] EntropyBits Number of entropy bits requested. + @param [in] BufferSize Size of the Buffer in bytes. + @param [out] Buffer Buffer to return the entropy bits. + + @retval RETURN_SUCCESS The function completed successfully. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Function not implemented. + @retval RETURN_BAD_BUFFER_SIZE Buffer size is too small. + @retval RETURN_NOT_READY No Entropy available. +**/ +RETURN_STATUS +EFIAPI +GetTrngEntropy ( + IN UINTN EntropyBits, + IN UINTN BufferSize, + OUT UINT8 *Buffer + ); + +#endif // TRNG_LIB_H_ diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 4c81cbd75ab2..0a7859fc1d3f 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -8,6 +8,7 @@ # Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
# (C) Copyright 2016 - 2021 Hewlett Packard Enterprise Development LP
# Copyright (c) 2022, Loongson Technology Corporation Limited. All rights = reserved.
+# Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
# # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -279,6 +280,10 @@ [LibraryClasses] ## @libraryclass Provides function for SMM CPU Rendezvous Library. SmmCpuRendezvousLib|Include/Library/SmmCpuRendezvousLib.h =20 + ## @libraryclass Provides services to generate Entropy using a TRNG. + # + TrngLib|Include/Library/TrngLib.h + [LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64] ## @libraryclass Provides services to generate random number. # --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95322): https://edk2.groups.io/g/devel/message/95322 Mute This Topic: https://groups.io/mt/94407745/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 8 20:41:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+95323+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95323+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1666099843; cv=none; d=zohomail.com; s=zohoarc; b=JdMLkCvz7pwmh/vq8Xe+jpcUaP0EdHiG30m/lP/+7oo5z6N61fSvfd02t4ICiqUXAcBqLa01NpLcdAKNubegHDjF8GNDffvlK55pvxbis5T+ouVlNo7mqYEAkS70nXr0FUzcWea16OPvdDwWfN0oLwaTEILVZBErNcwxEhZFFTU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666099843; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=hWghDkw5ze5nWzTQDvhWsAqe4JjxCWd9HZ3mORhT2NY=; b=mEvETPu7qfiWu0RWH2p5wXUpoQAfeQmoCmGDjoXm0eBjANzAoEHQv2W0BLIaJuLRHnSHpjMzA3Ckx6iYzCk+lgDVLsj1qIFCd/WoQ8twl6FQxbzvRTUNJzYOljVANPJPqQlwiiiXlLR3ITatxYfpZOBgmTsNOjkyI4J67o/CXfc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95323+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1666099843524332.67849057796843; Tue, 18 Oct 2022 06:30:43 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 8mZWYY1788612xUz6w92aiYv; Tue, 18 Oct 2022 06:30:43 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.6662.1666099842273696013 for ; Tue, 18 Oct 2022 06:30:42 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 21E8F113E; Tue, 18 Oct 2022 06:30:48 -0700 (PDT) X-Received: from pierre123.arm.com (pierre123.nice.arm.com [10.34.100.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 847BB3F792; Tue, 18 Oct 2022 06:30:40 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v8 07/19] MdePkg/TrngLib: Add NULL instance of TRNG Library Date: Tue, 18 Oct 2022 15:20:40 +0200 Message-Id: <20221018132052.1359530-8-Pierre.Gondois@arm.com> In-Reply-To: <20221018132052.1359530-1-Pierre.Gondois@arm.com> References: <20221018132052.1359530-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: CotJ5TzdYKVVTmqNATjXYgSNx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1666099843; bh=vGu7bzDL/T0jKOhdOlc9SozSdUZCcmTo1zxQM4QjgxE=; h=Cc:Date:From:Reply-To:Subject:To; b=GrGdRLQBDuThoREPWDC5p8N9ggQZdF5yk/HkEvo2t7mqxYixWBZCo6p3UNw5vXQpS/B dxErFaqqAnS3MSdg29MdS7LuZYv0Nm09DaXQvf+8ezxhXMJscOXsd4YNVWrHcP5eFCTiq GvofqUPOEeNG/8iGpGMkSPHyXxvv7CNKV60= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1666099845431100029 Content-Type: text/plain; charset="utf-8" From: Sami Mujawar Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3D3668) The True Random Number Generator (TRNG) library defines an interface to access the entropy source on a platform. On platforms that do not have access to an entropy source, a NULL instance of the TRNG library may be useful to satisfy the build dependency. Therefore, add a NULL instance of the TRNG library. Signed-off-by: Pierre Gondois --- .../Library/BaseTrngLibNull/BaseTrngLibNull.c | 117 ++++++++++++++++++ .../BaseTrngLibNull/BaseTrngLibNull.inf | 30 +++++ .../BaseTrngLibNull/BaseTrngLibNull.uni | 12 ++ MdePkg/MdePkg.dsc | 1 + 4 files changed, 160 insertions(+) create mode 100644 MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.c create mode 100644 MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.inf create mode 100644 MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.uni diff --git a/MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.c b/MdePkg/Libr= ary/BaseTrngLibNull/BaseTrngLibNull.c new file mode 100644 index 000000000000..60774b33dd58 --- /dev/null +++ b/MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.c @@ -0,0 +1,117 @@ +/** @file + Null version of TRNG (True Random Number Generator) services. + + Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - [1] NIST Special Publication 800-90B, Recommendation for the Entropy + Sources Used for Random Bit Generation. + (https://csrc.nist.gov/publications/detail/sp/800-90b/final) + + @par Glossary: + - TRNG - True Random Number Generator +**/ + +#include +#include + +/** Get the version of the TRNG backend. + + A TRNG may be implemented by the system firmware, in which case this + function shall return the version of the TRNG backend. + The implementation must return NOT_SUPPORTED if a Back end is not presen= t. + + @param [out] MajorRevision Major revision. + @param [out] MinorRevision Minor revision. + + @retval RETURN_SUCCESS The function completed successfully. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Backend not present. +**/ +RETURN_STATUS +EFIAPI +GetTrngVersion ( + OUT UINT16 *MajorRevision, + OUT UINT16 *MinorRevision + ) +{ + ASSERT (FALSE); + return RETURN_UNSUPPORTED; +} + +/** Get the UUID of the TRNG backend. + + A TRNG may be implemented by the system firmware, in which case this + function shall return the UUID of the TRNG backend. + Returning the TRNG UUID is optional and if not implemented, RETURN_UNSUP= PORTED + shall be returned. + + Note: The caller must not rely on the returned UUID as a trustworthy TRNG + Back end identity + + @param [out] Guid UUID of the TRNG backend. + + @retval RETURN_SUCCESS The function completed successfully. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Function not implemented. +**/ +RETURN_STATUS +EFIAPI +GetTrngUuid ( + OUT GUID *Guid + ) +{ + ASSERT (FALSE); + return RETURN_UNSUPPORTED; +} + +/** Returns maximum number of entropy bits that can be returned in a single + call. + + @return Returns the maximum number of Entropy bits that can be returned + in a single call to GetTrngEntropy(). +**/ +UINTN +EFIAPI +GetTrngMaxSupportedEntropyBits ( + VOID + ) +{ + ASSERT (FALSE); + return 0; +} + +/** Returns N bits of conditioned entropy. + + See [1] Section 2.3.1 GetEntropy: An Interface to the Entropy Source + GetEntropy + Input: + bits_of_entropy: the requested amount of entropy + Output: + entropy_bitstring: The string that provides the requested entropy. + status: A Boolean value that is TRUE if the request has been satisfi= ed, + and is FALSE otherwise. + + @param [in] EntropyBits Number of entropy bits requested. + @param [in] BufferSize Size of the Buffer in bytes. + @param [out] Buffer Buffer to return the entropy bits. + + @retval RETURN_SUCCESS The function completed successfully. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Function not implemented. + @retval RETURN_BAD_BUFFER_SIZE Buffer size is too small. + @retval RETURN_NOT_READY No Entropy available. +**/ +RETURN_STATUS +EFIAPI +GetTrngEntropy ( + IN UINTN EntropyBits, + IN UINTN BufferSize, + OUT UINT8 *Buffer + ) +{ + ASSERT (FALSE); + return RETURN_UNSUPPORTED; +} diff --git a/MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.inf b/MdePkg/Li= brary/BaseTrngLibNull/BaseTrngLibNull.inf new file mode 100644 index 000000000000..54a4fd3db8cd --- /dev/null +++ b/MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.inf @@ -0,0 +1,30 @@ +## @file +# Null instance of TRNG (True Random Number Generator) Library. +# +# Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D BaseTrngLibNull + MODULE_UNI_FILE =3D BaseTrngLibNull.uni + FILE_GUID =3D ABDE1C87-4F50-4B82-9133-7A79E13F69AB + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D TrngLib + +# +# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 RISCV64 +# + +[Sources] + BaseTrngLibNull.c + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + DebugLib diff --git a/MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.uni b/MdePkg/Li= brary/BaseTrngLibNull/BaseTrngLibNull.uni new file mode 100644 index 000000000000..952e4354c0cc --- /dev/null +++ b/MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.uni @@ -0,0 +1,12 @@ +// /** @file +// Null Instance of TRNG (True Random Number Generator) Library. +// +// Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + +#string STR_MODULE_ABSTRACT #language en-US "Null instance of = TRNG Library" + +#string STR_MODULE_DESCRIPTION #language en-US "This library inst= ance should be used with modules that inherit an (indirect) dependency on t= he TrngLib class, but never actually call TrngLib APIs for consuming Entrop= y." diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index 493a13ec9197..3fe3f9811cad 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -68,6 +68,7 @@ [Components] MdePkg/Library/DxeRngLib/DxeRngLib.inf MdePkg/Library/BaseRngLibNull/BaseRngLibNull.inf MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf + MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.inf =20 MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95323): https://edk2.groups.io/g/devel/message/95323 Mute This Topic: https://groups.io/mt/94407746/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 8 20:41:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+95324+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95324+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1666099845; cv=none; d=zohomail.com; s=zohoarc; b=YEThKWpS5+4YY+c+7u4GVpo1V5xTQauyKgy2nwA8/daB560/TQLS1RFNCv2iGFben+Nv+RgoiNGpVnRhJgRH6ulUDSZkVvMZV9pKAlFSrfDOcEmD4/d1DneRq3g8FuOahtUjghu+QbeCz+38Mp4xUvDjbL7oKjEwzYylKX1luzc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666099845; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=27LlKTv9XuAHRGgc16Jih7LCKMadccM3qassLdoMic8=; b=fT+oETLOrImsslVw+Y+wTnhqrLGTlIBiHqB1INlAsaCPTDzhgC/DcLV38ETi4JAEcaTvcit5Zroqk8AWPRfrv5IeYN22+TRzrU7yX2FFsqAXWCWqx+5IjuLHu9Jy3t5TQjSZ/j4RywNsx10PtyLi/rotT3xWbhYOB9oBZRyyiuU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95324+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1666099845983875.6101238325597; Tue, 18 Oct 2022 06:30:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id RNgvYY1788612x2JbaRP7GWH; Tue, 18 Oct 2022 06:30:44 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.6766.1666099843876608490 for ; Tue, 18 Oct 2022 06:30:44 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BF49E244B; Tue, 18 Oct 2022 06:30:49 -0700 (PDT) X-Received: from pierre123.arm.com (pierre123.nice.arm.com [10.34.100.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2D85B3F792; Tue, 18 Oct 2022 06:30:42 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v8 08/19] ArmPkg: Add FID definitions for Firmware TRNG Date: Tue, 18 Oct 2022 15:20:41 +0200 Message-Id: <20221018132052.1359530-9-Pierre.Gondois@arm.com> In-Reply-To: <20221018132052.1359530-1-Pierre.Gondois@arm.com> References: <20221018132052.1359530-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: BevC0cQCkAS2mYJBznQfnSDzx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1666099844; bh=azUA4yqT4wGsg99eFZRZPjvyL1G0VdQxhC/86KEWd44=; h=Cc:Date:From:Reply-To:Subject:To; b=aK4Q6ia40FAPakC0oiUpWUX5jX7GdKQSV9HWvS32C4etQ87mvvxeIqhhsG+gqaktbvW wUz2Hc6zcEZsXb1XC9hAQ3KA415SXz6iRk1ZzcYaw/3Hybih1JLJer3OWhiBgGRri48u7 qBws/mP7MGkyIkp91gFlw8tGklXNnv105J8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1666099847415100035 Content-Type: text/plain; charset="utf-8" From: Sami Mujawar Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3D3668) The Arm True Random Number Generator Firmware, Interface 1.0, Platform Design Document (https://developer.arm.com/documentation/den0098/latest/) defines an interface between an Operating System (OS) executing at EL1 and Firmware (FW) exposing a conditioned entropy source that is provided by a TRNG back end. New function IDs have been defined by the specification for accessing the TRNG services. Therefore, add these definitions to the Arm standard SMC header. Signed-off-by: Pierre Gondois Reviewed-by: Leif Lindholm --- ArmPkg/Include/IndustryStandard/ArmStdSmc.h | 109 +++++++++++++++++++- 1 file changed, 107 insertions(+), 2 deletions(-) diff --git a/ArmPkg/Include/IndustryStandard/ArmStdSmc.h b/ArmPkg/Include/I= ndustryStandard/ArmStdSmc.h index 78ce77cd734d..374b9ded7f5f 100644 --- a/ArmPkg/Include/IndustryStandard/ArmStdSmc.h +++ b/ArmPkg/Include/IndustryStandard/ArmStdSmc.h @@ -1,13 +1,20 @@ /** @file * * Copyright (c) 2020, NUVIA Inc. All rights reserved.
-* Copyright (c) 2012-2017, ARM Limited. All rights reserved. +* Copyright (c) 2012 - 2022, Arm Limited. All rights reserved. * * SPDX-License-Identifier: BSD-2-Clause-Patent * * @par Revision Reference: -* - SMC Calling Convention version 1.2 +* - [1] SMC Calling Convention version 1.2 * (https://developer.arm.com/documentation/den0028/c/?lang=3Den) +* - [2] Arm True Random Number Generator Firmware, Interface 1.0, +* Platform Design Document. +* (https://developer.arm.com/documentation/den0098/latest/) +* +* @par Glossary: +* - TRNG - True Random Number Generator +* **/ =20 #ifndef ARM_STD_SMC_H_ @@ -139,4 +146,102 @@ /* 0xbf00ff02 is reserved */ #define ARM_SMC_ID_TOS_REVISION 0xbf00ff03 =20 +// Firmware TRNG interface Function IDs + +/* + SMC/HVC call to get the version of the TRNG backend, + Cf. [2], 2.1 TRNG_VERSION + Input values: + W0 0x8400_0050 + W1-W7 Reserved (MBZ) + Return values: + Success (W0 > 0) W0[31] MBZ + W0[30:16] Major revision + W0[15:0] Minor revision + W1 - W3 Reserved (MBZ) + Error (W0 < 0) + NOT_SUPPORTED Function not implemented +*/ +#define ARM_SMC_ID_TRNG_VERSION 0x84000050 + +/* + SMC/HVC call to check if a TRNG function ID is implemented by the backen= d, + Cf. [2], Section 2.2 TRNG_FEATURES + Input Values + W0 0x8400_0051 + W1 trng_func_id + W2-W7 Reserved (MBZ) + Return values: + Success (W0 >=3D 0): + SUCCESS Function is implemented. + > 0 Function is implemented and + has specific capabilities, + see function definition. + Error (W0 < 0) + NOT_SUPPORTED Function with FID=3Dtrng_func_id + is not implemented +*/ +#define ARM_SMC_ID_TRNG_FEATURES 0x84000051 + +/* + SMC/HVC call to get the UUID of the TRNG backend, + Cf. [2], Section 2.3 TRNG_GET_UUID + Input Values: + W0 0x8400_0052 + W1-W7 Reserved (MBZ) + Return Values: + Success (W0 !=3D -1) + W0 UUID[31:0] + W1 UUID[63:32] + W2 UUID[95:64] + W3 UUID[127:96] + Error (W0 =3D -1) + W0 NOT_SUPPORTED +*/ +#define ARM_SMC_ID_TRNG_GET_UUID 0x84000052 + +/* + AARCH32 SMC/HVC call to get entropy bits, Cf. [2], Section 2.4 TRNG_RND. + Input values: + W0 0x8400_0053 + W2-W7 Reserved (MBZ) + Return values: + Success (W0 =3D 0): + W0 MBZ + W1 Entropy[95:64] + W2 Entropy[63:32] + W3 Entropy[31:0] + Error (W0 < 0) + W0 NOT_SUPPORTED + NO_ENTROPY + INVALID_PARAMETERS + W1 - W3 Reserved (MBZ) +*/ +#define ARM_SMC_ID_TRNG_RND_AARCH32 0x84000053 + +/* + AARCH64 SMC/HVC call to get entropy bits, Cf. [2], Section 2.4 TRNG_RND. + Input values: + X0 0xC400_0053 + X2-X7 Reserved (MBZ) + Return values: + Success (X0 =3D 0): + X0 MBZ + X1 Entropy[191:128] + X2 Entropy[127:64] + X3 Entropy[63:0] + Error (X0 < 0) + X0 NOT_SUPPORTED + NO_ENTROPY + INVALID_PARAMETERS + X1 - X3 Reserved (MBZ) +*/ +#define ARM_SMC_ID_TRNG_RND_AARCH64 0xC4000053 + +// Firmware TRNG status codes +#define TRNG_STATUS_SUCCESS (INT32)(0) +#define TRNG_STATUS_NOT_SUPPORTED (INT32)(-1) +#define TRNG_STATUS_INVALID_PARAMETER (INT32)(-2) +#define TRNG_STATUS_NO_ENTROPY (INT32)(-3) + #endif // ARM_STD_SMC_H_ --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95324): https://edk2.groups.io/g/devel/message/95324 Mute This Topic: https://groups.io/mt/94407747/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 8 20:41:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+95325+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95325+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1666099846; cv=none; d=zohomail.com; s=zohoarc; b=HfN8w5Y4N97Qi0F1hTYzejPjOTU3xn8K6j7u7xFEupecVsLkHGjoWy6ab7ZXQS5F9XRo8oA4KuU+tS08GDYM8+LctfA+gZuXxuZFLzw4tL6y148JH7B2B1TZFoH4E5w0aYbgnNXXI+i7H+bBA8YCWlGcaSY1WVc2vTSWI9QJhUs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666099846; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=mNlXSuhj8xUId/sKxbMbEgE9Th5zgrGy0fwn/GjfVEg=; b=gLJGVRWgzH40S23rbFc2BTYEk1YRzXz3BWZ0+hG1Rg6JJ6gJGKHKo+qz600P8YRhNrTNASnd9AjW7aMshIAOIC/lud1WaKQty7V/g1psflHUC4BBAGavLVvG2p1QaoMyrAsh4G2cZskCBYWaw+aKQro4A5l2N4WkX/arC1j16VA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95325+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1666099846845969.1021967356797; Tue, 18 Oct 2022 06:30:46 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id hxvqYY1788612x71j73BWFtC; Tue, 18 Oct 2022 06:30:46 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.6887.1666099845641838256 for ; Tue, 18 Oct 2022 06:30:45 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 874AC2454; Tue, 18 Oct 2022 06:30:51 -0700 (PDT) X-Received: from pierre123.arm.com (pierre123.nice.arm.com [10.34.100.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id CAD483F792; Tue, 18 Oct 2022 06:30:43 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v8 09/19] ArmPkg/TrngLib: Add Arm Firmware TRNG library Date: Tue, 18 Oct 2022 15:20:42 +0200 Message-Id: <20221018132052.1359530-10-Pierre.Gondois@arm.com> In-Reply-To: <20221018132052.1359530-1-Pierre.Gondois@arm.com> References: <20221018132052.1359530-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: s88bQvUUxsuqtJ0FL4lOgWRXx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1666099846; bh=TtKe3EMnDikrypTmC4tLIfrF6AH3jzxZqz6WL4Aw7F4=; h=Cc:Date:From:Reply-To:Subject:To; b=YNcRKoTASh70zaXX8DuZZvZ81mrtji6LCTPtIJbX8OFz5ZBhujEiNcgLR9F2cUePZkc cq4IlQWlC0JPCogv4aebuY4yZkb1AEqsqqzzNvC2P15lI9J7a2RoMzWdKmZy08Js5iHfd HyJxG49taflET2JuTKnUK8Nxx8elOgB/5XU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1666099847457100037 Content-Type: text/plain; charset="utf-8" From: Sami Mujawar Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3D3668) The Arm True Random Number Generator Firmware, Interface 1.0, Platform Design Document (https://developer.arm.com/documentation/den0098/latest/) defines an interface between an Operating System (OS) executing at EL1 and Firmware (FW) exposing a conditioned entropy source that is provided by a TRNG back end. The conditioned entropy, that is provided by the TRNG FW interface, is commonly used to seed deterministic random number generators. This patch adds a TrngLib library that implements the Arm TRNG firmware interface. Acked-by: Leif Lindholm Signed-off-by: Pierre Gondois --- ArmPkg/ArmPkg.dsc | 1 + ArmPkg/Library/ArmFwTrngLib/ArmFwTrngDefs.h | 50 +++ ArmPkg/Library/ArmFwTrngLib/ArmFwTrngLib.c | 388 +++++++++++++++++++ ArmPkg/Library/ArmFwTrngLib/ArmFwTrngLib.inf | 29 ++ 4 files changed, 468 insertions(+) create mode 100644 ArmPkg/Library/ArmFwTrngLib/ArmFwTrngDefs.h create mode 100644 ArmPkg/Library/ArmFwTrngLib/ArmFwTrngLib.c create mode 100644 ArmPkg/Library/ArmFwTrngLib/ArmFwTrngLib.inf diff --git a/ArmPkg/ArmPkg.dsc b/ArmPkg/ArmPkg.dsc index 11b473974463..8726989bc73d 100644 --- a/ArmPkg/ArmPkg.dsc +++ b/ArmPkg/ArmPkg.dsc @@ -131,6 +131,7 @@ [Components.common] ArmPkg/Library/ArmGenericTimerPhyCounterLib/ArmGenericTimerPhyCounterLib= .inf ArmPkg/Library/ArmGenericTimerVirtCounterLib/ArmGenericTimerVirtCounterL= ib.inf =20 + ArmPkg/Library/ArmFwTrngLib/ArmFwTrngLib.inf ArmPkg/Library/ArmHvcLib/ArmHvcLib.inf ArmPkg/Library/ArmHvcLibNull/ArmHvcLibNull.inf ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.inf diff --git a/ArmPkg/Library/ArmFwTrngLib/ArmFwTrngDefs.h b/ArmPkg/Library/A= rmFwTrngLib/ArmFwTrngDefs.h new file mode 100644 index 000000000000..8038a968b50f --- /dev/null +++ b/ArmPkg/Library/ArmFwTrngLib/ArmFwTrngDefs.h @@ -0,0 +1,50 @@ +/** @file + Arm Firmware TRNG definitions. + + Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - [1] Arm True Random Number Generator Firmware, Interface 1.0, + Platform Design Document. + (https://developer.arm.com/documentation/den0098/latest/) + + @par Glossary: + - TRNG - True Random Number Generator + - FID - Function ID +**/ + +#ifndef ARM_FW_TRNG_DEFS_H_ +#define ARM_FW_TRNG_DEFS_H_ + +#include + +// Firmware TRNG revision mask and shift +#define TRNG_REV_MAJOR_MASK 0x7FFF +#define TRNG_REV_MINOR_MASK 0xFFFF +#define TRNG_REV_MAJOR_SHIFT 16 + +#if defined (MDE_CPU_ARM) + +/** FID to use on AArch32 platform to request entropy. +*/ +#define ARM_SMC_ID_TRNG_RND ARM_SMC_ID_TRNG_RND_AARCH32 + +/** Maximum bits of entropy supported on AArch32. +*/ +#define MAX_ENTROPY_BITS 96 +#elif defined (MDE_CPU_AARCH64) + +/** FID to use on AArch64 platform to request entropy. +*/ +#define ARM_SMC_ID_TRNG_RND ARM_SMC_ID_TRNG_RND_AARCH64 + +/** Maximum bits of entropy supported on AArch64. +*/ +#define MAX_ENTROPY_BITS 192 +#else + #error "Firmware TRNG not supported. Unknown chipset." +#endif + +#endif // ARM_FW_TRNG_DEFS_H_ diff --git a/ArmPkg/Library/ArmFwTrngLib/ArmFwTrngLib.c b/ArmPkg/Library/Ar= mFwTrngLib/ArmFwTrngLib.c new file mode 100644 index 000000000000..426a6f221d78 --- /dev/null +++ b/ArmPkg/Library/ArmFwTrngLib/ArmFwTrngLib.c @@ -0,0 +1,388 @@ +/** @file + Arm Firmware TRNG interface library. + + Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Reference(s): + - [1] NIST Special Publication 800-90B, Recommendation for the Entropy + Sources Used for Random Bit Generation. + (https://csrc.nist.gov/publications/detail/sp/800-90b/final) + - [2] Arm True Random Number Generator Firmware, Interface 1.0, + Platform Design Document. + (https://developer.arm.com/documentation/den0098/latest/) + + @par Glossary: + - TRNG - True Random Number Generator + - FID - Function ID +**/ + +#include +#include +#include +#include +#include + +#include "ArmFwTrngDefs.h" + +/** Convert TRNG status codes to RETURN status codes. + + @param [in] TrngStatus TRNG status code. + + @retval RETURN_SUCCESS Success. + @retval RETURN_UNSUPPORTED Function not implemented or + negative return code. + @retval RETURN_INVALID_PARAMETER A parameter is invalid. + @retval RETURN_NOT_READY No Entropy available. +**/ +STATIC +RETURN_STATUS +TrngStatusToReturnStatus ( + IN INT32 TrngStatus + ) +{ + switch (TrngStatus) { + case TRNG_STATUS_NOT_SUPPORTED: + return RETURN_UNSUPPORTED; + + case TRNG_STATUS_INVALID_PARAMETER: + return RETURN_INVALID_PARAMETER; + + case TRNG_STATUS_NO_ENTROPY: + return RETURN_NOT_READY; + + case TRNG_STATUS_SUCCESS: + return RETURN_SUCCESS; + + default: + if (TrngStatus < 0) { + return RETURN_UNSUPPORTED; + } + + return RETURN_SUCCESS; + } +} + +/** Get the version of the TRNG backend. + + A TRNG may be implemented by the system firmware, in which case this + function shall return the version of the TRNG backend. + The implementation must return NOT_SUPPORTED if a Back end is not presen= t. + + @param [out] MajorRevision Major revision. + @param [out] MinorRevision Minor revision. + + @retval RETURN_SUCCESS The function completed successfully. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Backend not present. +**/ +RETURN_STATUS +EFIAPI +GetTrngVersion ( + OUT UINT16 *MajorRevision, + OUT UINT16 *MinorRevision + ) +{ + RETURN_STATUS Status; + ARM_MONITOR_ARGS Parameters; + INT32 Revision; + + if ((MajorRevision =3D=3D NULL) || (MinorRevision =3D=3D NULL)) { + return RETURN_INVALID_PARAMETER; + } + + ZeroMem (&Parameters, sizeof (Parameters)); + + Parameters.Arg0 =3D ARM_SMC_ID_TRNG_VERSION; + ArmMonitorCall (&Parameters); + + Revision =3D (INT32)Parameters.Arg0; + Status =3D TrngStatusToReturnStatus (Revision); + if (RETURN_ERROR (Status)) { + return Status; + } + + *MinorRevision =3D (Revision & TRNG_REV_MINOR_MASK); + *MajorRevision =3D ((Revision >> TRNG_REV_MAJOR_SHIFT) & TRNG_REV_MAJOR_= MASK); + return RETURN_SUCCESS; +} + +/** Get the features supported by the TRNG backend. + + The caller can determine if functions defined in the TRNG ABI are + present in the ABI implementation. + + @param [in] FunctionId Function Id. + @param [out] Capability Function specific capability if present. + + @retval RETURN_SUCCESS The function completed successfully. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Function not implemented. +**/ +STATIC +RETURN_STATUS +EFIAPI +GetTrngFeatures ( + IN CONST UINT32 FunctionId, + OUT UINT32 *Capability OPTIONAL + ) +{ + ARM_MONITOR_ARGS Parameters; + RETURN_STATUS Status; + + ZeroMem (&Parameters, sizeof (Parameters)); + + Parameters.Arg0 =3D ARM_SMC_ID_TRNG_FEATURES; + Parameters.Arg1 =3D FunctionId; + ArmMonitorCall (&Parameters); + + Status =3D TrngStatusToReturnStatus (Parameters.Arg0); + if (RETURN_ERROR (Status)) { + return Status; + } + + if (Capability !=3D NULL) { + *Capability =3D (UINT32)Parameters.Arg0; + } + + return RETURN_SUCCESS; +} + +/** Get the UUID of the TRNG backend. + + A TRNG may be implemented by the system firmware, in which case this + function shall return the UUID of the TRNG backend. + Returning the TRNG UUID is optional and if not implemented, RETURN_UNSUP= PORTED + shall be returned. + + Note: The caller must not rely on the returned UUID as a trustworthy TRNG + Back end identity + + @param [out] Guid UUID of the TRNG backend. + + @retval RETURN_SUCCESS The function completed successfully. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Function not implemented. +**/ +RETURN_STATUS +EFIAPI +GetTrngUuid ( + OUT GUID *Guid + ) +{ + ARM_MONITOR_ARGS Parameters; + + if (Guid =3D=3D NULL) { + return RETURN_INVALID_PARAMETER; + } + + ZeroMem (&Parameters, sizeof (Parameters)); + + Parameters.Arg0 =3D ARM_SMC_ID_TRNG_GET_UUID; + ArmMonitorCall (&Parameters); + + // Only invalid value is TRNG_STATUS_NOT_SUPPORTED (-1). + if ((INT32)Parameters.Arg0 =3D=3D TRNG_STATUS_NOT_SUPPORTED) { + return TrngStatusToReturnStatus ((INT32)Parameters.Arg0); + } + + Guid->Data1 =3D (Parameters.Arg0 & MAX_UINT32); + Guid->Data2 =3D (Parameters.Arg1 & MAX_UINT16); + Guid->Data3 =3D ((Parameters.Arg1 >> 16) & MAX_UINT16); + + Guid->Data4[0] =3D (Parameters.Arg2 & MAX_UINT8); + Guid->Data4[1] =3D ((Parameters.Arg2 >> 8) & MAX_UINT8); + Guid->Data4[2] =3D ((Parameters.Arg2 >> 16) & MAX_UINT8); + Guid->Data4[3] =3D ((Parameters.Arg2 >> 24) & MAX_UINT8); + + Guid->Data4[4] =3D (Parameters.Arg3 & MAX_UINT8); + Guid->Data4[5] =3D ((Parameters.Arg3 >> 8) & MAX_UINT8); + Guid->Data4[6] =3D ((Parameters.Arg3 >> 16) & MAX_UINT8); + Guid->Data4[7] =3D ((Parameters.Arg3 >> 24) & MAX_UINT8); + + DEBUG ((DEBUG_INFO, "FW-TRNG: UUID %g\n", Guid)); + + return RETURN_SUCCESS; +} + +/** Returns maximum number of entropy bits that can be returned in a single + call. + + @return Returns the maximum number of Entropy bits that can be returned + in a single call to GetTrngEntropy(). +**/ +UINTN +EFIAPI +GetTrngMaxSupportedEntropyBits ( + VOID + ) +{ + return MAX_ENTROPY_BITS; +} + +/** Returns N bits of conditioned entropy. + + See [1] Section 2.3.1 GetEntropy: An Interface to the Entropy Source + GetEntropy + Input: + bits_of_entropy: the requested amount of entropy + Output: + entropy_bitstring: The string that provides the requested entropy. + status: A Boolean value that is TRUE if the request has been satisfi= ed, + and is FALSE otherwise. + + @param [in] EntropyBits Number of entropy bits requested. + @param [in] BufferSize Size of the Buffer in bytes. + @param [out] Buffer Buffer to return the entropy bits. + + @retval RETURN_SUCCESS The function completed successfully. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Function not implemented. + @retval RETURN_BAD_BUFFER_SIZE Buffer size is too small. + @retval RETURN_NOT_READY No Entropy available. +**/ +RETURN_STATUS +EFIAPI +GetTrngEntropy ( + IN UINTN EntropyBits, + IN UINTN BufferSize, + OUT UINT8 *Buffer + ) +{ + RETURN_STATUS Status; + ARM_MONITOR_ARGS Parameters; + UINTN EntropyBytes; + UINTN LastValidBits; + UINTN BytesToClear; + UINTN EntropyData[3]; + + if ((EntropyBits =3D=3D 0) || + (EntropyBits > MAX_ENTROPY_BITS) || + (Buffer =3D=3D NULL)) + { + return RETURN_INVALID_PARAMETER; + } + + EntropyBytes =3D (EntropyBits + 7) >> 3; + if (EntropyBytes > BufferSize) { + return RETURN_BAD_BUFFER_SIZE; + } + + ZeroMem (Buffer, BufferSize); + ZeroMem (&Parameters, sizeof (Parameters)); + + Parameters.Arg0 =3D ARM_SMC_ID_TRNG_RND; + Parameters.Arg1 =3D EntropyBits; + ArmMonitorCall (&Parameters); + + Status =3D TrngStatusToReturnStatus ((INT32)Parameters.Arg0); + if (RETURN_ERROR (Status)) { + return Status; + } + + // The entropy data is returned in the Parameters.Arg<3..1> + // With the lower order bytes in Parameters.Arg3 and the higher + // order bytes being stored in Parameters.Arg1. + EntropyData[0] =3D Parameters.Arg3; + EntropyData[1] =3D Parameters.Arg2; + EntropyData[2] =3D Parameters.Arg1; + + CopyMem (Buffer, EntropyData, EntropyBytes); + + // Mask off any unused top bytes, in accordance with specification. + BytesToClear =3D BufferSize - EntropyBytes; + if (BytesToClear !=3D 0) { + ZeroMem (&Buffer[EntropyBytes], BytesToClear); + } + + // Clear the unused MSB bits of the last byte. + LastValidBits =3D EntropyBits & 0x7; + if (LastValidBits !=3D 0) { + Buffer[EntropyBytes - 1] &=3D (0xFF >> (8 - LastValidBits)); + } + + return Status; +} + +/** The constructor checks that the FW-TRNG interface is supported + by the host firmware. + + It will ASSERT() if FW-TRNG is not supported. + It will always return RETURN_SUCCESS. + + @retval RETURN_SUCCESS The constructor always returns RETURN_SUCCESS. +**/ +RETURN_STATUS +EFIAPI +ArmFwTrngLibConstructor ( + VOID + ) +{ + ARM_MONITOR_ARGS Parameters; + RETURN_STATUS Status; + UINT16 MajorRev; + UINT16 MinorRev; + GUID Guid; + + ZeroMem (&Parameters, sizeof (Parameters)); + + Parameters.Arg0 =3D SMCCC_VERSION; + ArmMonitorCall (&Parameters); + Status =3D TrngStatusToReturnStatus ((INT32)Parameters.Arg0); + if (RETURN_ERROR (Status)) { + ASSERT_RETURN_ERROR (Status); + goto ErrorHandler; + } + + // Cf [1] s2.1.3 'Caller responsibilities', + // SMCCC version must be greater or equal than 1.1 + if ((INT32)Parameters.Arg0 < 0x10001) { + ASSERT_RETURN_ERROR (RETURN_UNSUPPORTED); + goto ErrorHandler; + } + + Status =3D GetTrngVersion (&MajorRev, &MinorRev); + if (RETURN_ERROR (Status)) { + ASSERT_RETURN_ERROR (Status); + goto ErrorHandler; + } + + // Check that the required features are present. + Status =3D GetTrngFeatures (ARM_SMC_ID_TRNG_RND, NULL); + if (RETURN_ERROR (Status)) { + ASSERT_RETURN_ERROR (Status); + goto ErrorHandler; + } + + // Check if TRNG UUID is supported and if so trace the GUID. + Status =3D GetTrngFeatures (ARM_SMC_ID_TRNG_GET_UUID, NULL); + if (RETURN_ERROR (Status)) { + ASSERT_RETURN_ERROR (Status); + goto ErrorHandler; + } + + DEBUG_CODE_BEGIN (); + + Status =3D GetTrngUuid (&Guid); + if (RETURN_ERROR (Status)) { + ASSERT_RETURN_ERROR (Status); + goto ErrorHandler; + } + + DEBUG (( + DEBUG_INFO, + "FW-TRNG: Version %d.%d, GUID {%g}\n", + MajorRev, + MinorRev, + Guid + )); + + DEBUG_CODE_END (); + + return RETURN_SUCCESS; + +ErrorHandler: + DEBUG ((DEBUG_ERROR, "ArmFwTrngLib could not be correctly initialized.\n= ")); + return RETURN_SUCCESS; +} diff --git a/ArmPkg/Library/ArmFwTrngLib/ArmFwTrngLib.inf b/ArmPkg/Library/= ArmFwTrngLib/ArmFwTrngLib.inf new file mode 100644 index 000000000000..ae3eb9bcfe7d --- /dev/null +++ b/ArmPkg/Library/ArmFwTrngLib/ArmFwTrngLib.inf @@ -0,0 +1,29 @@ +## @file +# Arm Firmware TRNG interface library. +# +# Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D ArmFwTrngLib + FILE_GUID =3D 10DE97C9-28E4-4C9B-A53E-8D7D1B0DD4E0 + VERSION_STRING =3D 1.0 + MODULE_TYPE =3D BASE + LIBRARY_CLASS =3D TrngLib + CONSTRUCTOR =3D ArmFwTrngLibConstructor + +[Sources] + ArmFwTrngDefs.h + ArmFwTrngLib.c + +[Packages] + ArmPkg/ArmPkg.dec + MdePkg/MdePkg.dec + +[LibraryClasses] + ArmMonitorLib + BaseLib + BaseMemoryLib --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95325): https://edk2.groups.io/g/devel/message/95325 Mute This Topic: https://groups.io/mt/94407749/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 8 20:41:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+95326+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95326+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1666099848; cv=none; d=zohomail.com; s=zohoarc; b=ibojtrfY29ENncxqpe9WcOSRFPXg9jbGpAewjBcpMexMbDUrNfhp30npxfGN3Zzv4c2UCBXFoaMyKUY1lmxUrfCkCSuxJZN3wkz4MyQ754B/HKQGH+8jW6tdhGeJ5xJKIn4vrYftbXSwH7QBhjTBIweXTTLO3iZyYhYS5tvibAk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666099848; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=ClLuvGVjL8KHgSczcIjTNatu9RBltPksDoMwSa2MeHk=; b=DBNNHu11IPijnvcL4xZfseIHD0WmxhD2IBUrRb/z+OXnzvk9s2Uo2AeUfkoUs7vZiWAUCairF/BeiQRsI2VadS2hTGY81E/2nrds/wQN60F1M+PKj/s1nHld6wst4XLQBk9xIbCgDFeIju4KPGUFgqqrWqy2B/2d5kgFkVnafrw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95326+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 16660998486537.685820232358992; Tue, 18 Oct 2022 06:30:48 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id tJADYY1788612xpzwMzKgXba; Tue, 18 Oct 2022 06:30:48 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.6888.1666099847301978012 for ; Tue, 18 Oct 2022 06:30:47 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3093A113E; Tue, 18 Oct 2022 06:30:53 -0700 (PDT) X-Received: from pierre123.arm.com (pierre123.nice.arm.com [10.34.100.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 92D643F792; Tue, 18 Oct 2022 06:30:45 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v8 10/19] SecurityPkg/RngDxe: Rename RdRandGenerateEntropy to generic name Date: Tue, 18 Oct 2022 15:20:43 +0200 Message-Id: <20221018132052.1359530-11-Pierre.Gondois@arm.com> In-Reply-To: <20221018132052.1359530-1-Pierre.Gondois@arm.com> References: <20221018132052.1359530-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: V3ywgAGS0unHFKTTVu6nMP3nx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1666099848; bh=XQsxEZj5MFNArSWlwfemPzfArizsHy0nTDPzyMkektI=; h=Cc:Date:From:Reply-To:Subject:To; b=GXC6Kwq850fSRwOnrIsoEUDgQ5dzWTg96SnJXUpwyxRsDlMXXd8V8MZ4+imNm8dqHhS 1Dq0i1w2XxiqrSRaXY2+PUO2wkG2gpTQd5KhCbHYfOr84rtG2AjZb83XtufQBokPr5Y3g piFOrMq7RHPkKDmWpoGxkZ9kJHuUvs5m0m4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1666099849484100042 Content-Type: text/plain; charset="utf-8" From: Sami Mujawar Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3D3668) Rename RdRandGenerateEntropy() to GenerateEntropy() to provide a common interface to generate entropy on other architectures. GenerateEntropy() is intended to generate high quality entropy. Also move the definition to RngDxeInternals.h Signed-off-by: Pierre Gondois --- .../RngDxe/Rand/RdRand.c | 14 ++++-- .../RngDxe/Rand/RdRand.h | 43 ------------------- .../RngDxe/Rand/RngDxe.c | 7 ++- .../RandomNumberGenerator/RngDxe/RngDxe.inf | 2 +- .../RngDxe/RngDxeInternals.h | 19 ++++++++ 5 files changed, 36 insertions(+), 49 deletions(-) delete mode 100644 SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.h diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.c b/Secur= ityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.c index 5b6644138231..4b011c7e8e49 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.c @@ -1,15 +1,23 @@ /** @file - Support routines for RDRAND instruction access. + Support routines for RDRAND instruction access, which will leverage + Intel Secure Key technology to provide high-quality random numbers for u= se + in applications, or entropy for seeding other random number generators. + Refer to http://software.intel.com/en-us/articles/intel-digital-random-n= umber + -generator-drng-software-implementation-guide/ for more information abou= t Intel + Secure Key technology. =20 +Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
(C) Copyright 2015 Hewlett Packard Enterprise Development LP
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ +#include +#include #include +#include =20 #include "AesCore.h" -#include "RdRand.h" #include "RngDxeInternals.h" =20 /** @@ -87,7 +95,7 @@ RdRandGetSeed128 ( **/ EFI_STATUS EFIAPI -RdRandGenerateEntropy ( +GenerateEntropy ( IN UINTN Length, OUT UINT8 *Entropy ) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.h b/Secur= ityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.h deleted file mode 100644 index 7fdb6891bd63..000000000000 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RdRand.h +++ /dev/null @@ -1,43 +0,0 @@ -/** @file - Header for the RDRAND APIs used by RNG DXE driver. - - Support API definitions for RDRAND instruction access, which will levera= ge - Intel Secure Key technology to provide high-quality random numbers for u= se - in applications, or entropy for seeding other random number generators. - Refer to http://software.intel.com/en-us/articles/intel-digital-random-n= umber - -generator-drng-software-implementation-guide/ for more information abou= t Intel - Secure Key technology. - -Copyright (c) 2013, Intel Corporation. All rights reserved.
-(C) Copyright 2015 Hewlett Packard Enterprise Development LP
-SPDX-License-Identifier: BSD-2-Clause-Patent - -**/ - -#ifndef __RD_RAND_H__ -#define __RD_RAND_H__ - -#include -#include -#include -#include -#include - -/** - Generate high-quality entropy source through RDRAND. - - @param[in] Length Size of the buffer, in bytes, to fill with. - @param[out] Entropy Pointer to the buffer to store the entropy da= ta. - - @retval EFI_SUCCESS Entropy generation succeeded. - @retval EFI_NOT_READY Failed to request random data. - -**/ -EFI_STATUS -EFIAPI -RdRandGenerateEntropy ( - IN UINTN Length, - OUT UINT8 *Entropy - ); - -#endif // __RD_RAND_H__ diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c b/Secur= ityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c index 2df4ed44329a..8d44f0636c3d 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c @@ -14,13 +14,16 @@ - EFI_RNG_ALGORITHM_X9_31_3DES_GUID - Unsupported - EFI_RNG_ALGORITHM_X9_31_AES_GUID - Unsupported =20 + Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
(C) Copyright 2015 Hewlett Packard Enterprise Development LP
SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 -#include "RdRand.h" +#include +#include + #include "RngDxeInternals.h" =20 /** @@ -88,7 +91,7 @@ RngGetRNG ( return EFI_INVALID_PARAMETER; } =20 - Status =3D RdRandGenerateEntropy (RNGValueLength, RNGValue); + Status =3D GenerateEntropy (RNGValueLength, RNGValue); return Status; } =20 diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf b/Security= Pkg/RandomNumberGenerator/RngDxe/RngDxe.inf index f3300971993f..60efb5562ee0 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf @@ -10,6 +10,7 @@ # # Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
# (C) Copyright 2015 Hewlett Packard Enterprise Development LP
+# Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -36,7 +37,6 @@ [Sources.common] [Sources.IA32, Sources.X64] Rand/RngDxe.c Rand/RdRand.c - Rand/RdRand.h Rand/AesCore.c Rand/AesCore.h =20 diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h b/S= ecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h index 224d8bd4ea5f..48d2d27c1608 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h @@ -10,6 +10,8 @@ #ifndef RNGDXE_INTERNALS_H_ #define RNGDXE_INTERNALS_H_ =20 +#include + /** Returns information about the random number generation implementation. =20 @@ -114,4 +116,21 @@ RngGetBytes ( OUT UINT8 *RandBuffer ); =20 +/** + Generate high-quality entropy source using a TRNG or through RDRAND. + + @param[in] Length Size of the buffer, in bytes, to fill with. + @param[out] Entropy Pointer to the buffer to store the entropy da= ta. + + @retval EFI_SUCCESS Entropy generation succeeded. + @retval EFI_NOT_READY Failed to request random data. + +**/ +EFI_STATUS +EFIAPI +GenerateEntropy ( + IN UINTN Length, + OUT UINT8 *Entropy + ); + #endif // RNGDXE_INTERNALS_H_ --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95326): https://edk2.groups.io/g/devel/message/95326 Mute This Topic: https://groups.io/mt/94407751/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 8 20:41:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+95327+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95327+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1666099850; cv=none; d=zohomail.com; s=zohoarc; b=D+F1Edh7APoUakk0hbhsiEc6Tm1iIpU7YuibV4pC5oEEkgCEm8ULWh+Smn1GA69a3JRz6aqH8Ynx/exIzbuWbzx2c9Qwz6JacT3ijuRH56wBbjwkUt/rYF7Pe2IcbzzwKf9kWNVTI67xIOiF70yh59dI1hFG5WFeftgJED9vs1A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666099850; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=wzWMF9j2tR+3XYqru3bBEpIUqW9gci/kMo+JOHQw+dE=; b=NOh3wFMauS5ZYA6zjp69MLjyn/c0UkzjaZYW1+FNUgZn5IXudx9U+Ebo48dp/ztRjzCOzf1+VkRoHRBQLPlE7n4/ukjwE2J75zTht/3n+mDMT/VANeDb3yZR3DVU5N95tuihAYA6hxGq/DAjsCPsyCLrvEY9jkB2p+fE1g4cH/Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95327+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1666099850137420.4898162604446; Tue, 18 Oct 2022 06:30:50 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 3lElYY1788612xUPwwpraJ38; Tue, 18 Oct 2022 06:30:49 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.6889.1666099848958240471 for ; Tue, 18 Oct 2022 06:30:49 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CDCAD1758; Tue, 18 Oct 2022 06:30:54 -0700 (PDT) X-Received: from pierre123.arm.com (pierre123.nice.arm.com [10.34.100.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3C09F3F792; Tue, 18 Oct 2022 06:30:47 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v8 11/19] SecurityPkg/RngDxe: Replace Pcd with Sp80090Ctr256Guid Date: Tue, 18 Oct 2022 15:20:44 +0200 Message-Id: <20221018132052.1359530-12-Pierre.Gondois@arm.com> In-Reply-To: <20221018132052.1359530-1-Pierre.Gondois@arm.com> References: <20221018132052.1359530-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: wAQdMLi0VGBCEBRMQ79eSavpx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1666099849; bh=aauCgY1F7jF75r9U2czPQVOgkhJ5O8Lp1ZLaPc87kag=; h=Cc:Date:From:Reply-To:Subject:To; b=BWITYd365+zsMahSEMWSGq8XodtDg/N04ROjmkzstkfJ2TxxtqLOECByZiQCxy80qlo sQantg19svLNHljCyTEctj8CMeifEwZ2rzbhMNKPEIaCYGMQjLgmQZ/HTuOj95clnp4T1 GZsNdA4e9rd+91EpxZpOiS/LLad1GUbz+U0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1666099851543100045 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois gEfiRngAlgorithmSp80090Ctr256Guid was used as the default algorithm in RngGetRNG(). The commit below set the default algorithm to PcdCpuRngSupportedAlgorithm, which is a zero GUID by default. As the Pcd value is not defined for any platform in the edk2-platfoms repository, assume it was an error and go back to the first version, using gEfiRngAlgorithmSp80090Ctr256Guid. Fixes 4e5ecdbac8bd ("SecurityPkg: Add support for RngDxe on AARCH64") Signed-off-by: Pierre Gondois --- Notes: v4: - Fix: Correctly reference gEfiRngAlgorithmSp80090Ctr256Guid Guid by copying its address (add missing '&'). [Jiewen] SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c b/Secur= ityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c index 8d44f0636c3d..df7db12b771c 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c @@ -126,8 +126,7 @@ ArchGetSupportedRngAlgorithms ( OUT EFI_RNG_ALGORITHM *RNGAlgorithmList ) { - UINTN RequiredSize; - EFI_RNG_ALGORITHM *CpuRngSupportedAlgorithm; + UINTN RequiredSize; =20 RequiredSize =3D 2 * sizeof (EFI_RNG_ALGORITHM); =20 @@ -136,9 +135,7 @@ ArchGetSupportedRngAlgorithms ( return EFI_BUFFER_TOO_SMALL; } =20 - CpuRngSupportedAlgorithm =3D PcdGetPtr (PcdCpuRngSupportedAlgorithm); - - CopyMem (&RNGAlgorithmList[0], CpuRngSupportedAlgorithm, sizeof (EFI_RNG= _ALGORITHM)); + CopyMem (&RNGAlgorithmList[0], &gEfiRngAlgorithmSp80090Ctr256Guid, sizeo= f (EFI_RNG_ALGORITHM)); =20 // x86 platforms also support EFI_RNG_ALGORITHM_RAW via RDSEED CopyMem (&RNGAlgorithmList[1], &gEfiRngAlgorithmRaw, sizeof (EFI_RNG_ALG= ORITHM)); --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95327): https://edk2.groups.io/g/devel/message/95327 Mute This Topic: https://groups.io/mt/94407753/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 8 20:41:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+95328+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95328+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1666099851; cv=none; d=zohomail.com; s=zohoarc; b=WycG+ngCGn4fy8GqGv92c68O8x2vsopKaJ0iBaBgIt6SJIYfMHasGpSZOGjI6LtfzrMds4HvHR2SG7/b8Pv77joHkMZZJ2yLcw8r3lHXb+Ge61hdH7nz8Nn5waF+SD82C2EMHympwp4Y+FCQS8r24tizeeoj3lojzNfqzZHm+0E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666099851; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=AeL3t55oC5+hB5ur8Eaz2Qz7Bj5r/k+UsbwRaZBSrjM=; b=VxxJcB+yY7oPm5hP7A3jovDjhrdiY7AVFHjU45/k9miC3mlrUtIG1qVmnkCQrV2pfcAkiMRMVWOYeUHV+mtC0iZyLmMO0EhgIGY6h1XqB4gWdXnOQs1EFQX7arRzMpbdB6unXBI0V20uh9OVYH/KVG2Lo1jiXduL+NVJgkeI55g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95328+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1666099851510288.85964962784703; Tue, 18 Oct 2022 06:30:51 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id lzt3YY1788612x5mFlQx47Av; Tue, 18 Oct 2022 06:30:51 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.6890.1666099850533716452 for ; Tue, 18 Oct 2022 06:30:50 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 76B06244B; Tue, 18 Oct 2022 06:30:56 -0700 (PDT) X-Received: from pierre123.arm.com (pierre123.nice.arm.com [10.34.100.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D94D63F792; Tue, 18 Oct 2022 06:30:48 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v8 12/19] SecurityPkg/RngDxe: Remove ArchGetSupportedRngAlgorithms() Date: Tue, 18 Oct 2022 15:20:45 +0200 Message-Id: <20221018132052.1359530-13-Pierre.Gondois@arm.com> In-Reply-To: <20221018132052.1359530-1-Pierre.Gondois@arm.com> References: <20221018132052.1359530-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: PGTVOYqEO5xh0PDNn8E1MMuix1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1666099851; bh=MyP5CUUNYBB4Z43m+YJ90M8+Y44HAWi6nGlSkgG+tqU=; h=Cc:Date:From:Reply-To:Subject:To; b=wOi0I3m2FeRZsEj4Tt+3MV10Dd+g5uobJAUGC8HEE7hVUeUng43E+vSqBdaslSpNcm7 4LHRJRB2VTQ/Jfcf6zJzKeLcilMXSPEu0bPEZPkLC9P9xNnZUFRfxvUHjS0HUzxW06sWZ 1sw6klLQHY3twyZbLg9hNIA99O+wG62eSW8= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1666099853472100049 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois RngGetInfo() is one of the 2 functions of the EFI_RNG_PROTOCOL. RngGetInfo() is currently a mere wrapper around ArchGetSupportedRngAlgorithms() which is implemented differently depending on the architecture used. RngGetInfo() does nothing more than calling ArchGetSupportedRngAlgorithms(). So remove it, and let RngGetInfo() be implemented differently according to the architecture. This follows the implementation of the other function of the EFI_RNG_PROTOCOL, RngGetRNG(). Signed-off-by: Pierre Gondois --- .../RngDxe/AArch64/RngDxe.c | 19 +++++-- .../RngDxe/Rand/RngDxe.c | 22 +++++++-- .../RandomNumberGenerator/RngDxe/RngDxe.c | 49 ------------------- .../RngDxe/RngDxeInternals.h | 25 ---------- 4 files changed, 33 insertions(+), 82 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c b/Se= curityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c index 3daf847d46d3..6d989f7ea376 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c @@ -14,6 +14,7 @@ Copyright (c) 2021, NUVIA Inc. All rights reserved.
Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.
(C) Copyright 2015 Hewlett Packard Enterprise Development LP
+ Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -85,6 +86,7 @@ RngGetRNG ( /** Returns information about the random number generation implementation. =20 + @param[in] This A pointer to the EFI_RNG_PROTOCOL in= stance. @param[in,out] RNGAlgorithmListSize On input, the size in bytes of RNGAl= gorithmList. On output with a return code of EFI_= SUCCESS, the size in bytes of the data returned in RNG= AlgorithmList. On output @@ -97,14 +99,19 @@ RngGetRNG ( is the default algorithm for the dri= ver. =20 @retval EFI_SUCCESS The RNG algorithm list was returned = successfully. + @retval EFI_UNSUPPORTED The services is not supported by thi= s driver. + @retval EFI_DEVICE_ERROR The list of algorithms could not be = retrieved due to a + hardware or firmware error. + @retval EFI_INVALID_PARAMETER One or more of the parameters are in= correct. @retval EFI_BUFFER_TOO_SMALL The buffer RNGAlgorithmList is too s= mall to hold the result. =20 **/ -UINTN +EFI_STATUS EFIAPI -ArchGetSupportedRngAlgorithms ( - IN OUT UINTN *RNGAlgorithmListSize, - OUT EFI_RNG_ALGORITHM *RNGAlgorithmList +RngGetInfo ( + IN EFI_RNG_PROTOCOL *This, + IN OUT UINTN *RNGAlgorithmListSize, + OUT EFI_RNG_ALGORITHM *RNGAlgorithmList ) { UINTN RequiredSize; @@ -112,6 +119,10 @@ ArchGetSupportedRngAlgorithms ( =20 RequiredSize =3D sizeof (EFI_RNG_ALGORITHM); =20 + if ((This =3D=3D NULL) || (RNGAlgorithmListSize =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + if (*RNGAlgorithmListSize < RequiredSize) { *RNGAlgorithmListSize =3D RequiredSize; return EFI_BUFFER_TOO_SMALL; diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c b/Secur= ityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c index df7db12b771c..b2d2236380fd 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c @@ -104,6 +104,7 @@ RngGetRNG ( /** Returns information about the random number generation implementation. =20 + @param[in] This A pointer to the EFI_RNG_PROTOCOL in= stance. @param[in,out] RNGAlgorithmListSize On input, the size in bytes of RNGAl= gorithmList. On output with a return code of EFI_= SUCCESS, the size in bytes of the data returned in RNG= AlgorithmList. On output @@ -116,18 +117,27 @@ RngGetRNG ( is the default algorithm for the dri= ver. =20 @retval EFI_SUCCESS The RNG algorithm list was returned = successfully. + @retval EFI_UNSUPPORTED No supported algorithms found. + @retval EFI_DEVICE_ERROR The list of algorithms could not be = retrieved due to a + hardware or firmware error. + @retval EFI_INVALID_PARAMETER One or more of the parameters are in= correct. @retval EFI_BUFFER_TOO_SMALL The buffer RNGAlgorithmList is too s= mall to hold the result. =20 **/ -UINTN +EFI_STATUS EFIAPI -ArchGetSupportedRngAlgorithms ( - IN OUT UINTN *RNGAlgorithmListSize, - OUT EFI_RNG_ALGORITHM *RNGAlgorithmList +RngGetInfo ( + IN EFI_RNG_PROTOCOL *This, + IN OUT UINTN *RNGAlgorithmListSize, + OUT EFI_RNG_ALGORITHM *RNGAlgorithmList ) { UINTN RequiredSize; =20 + if ((This =3D=3D NULL) || (RNGAlgorithmListSize =3D=3D NULL)) { + return EFI_INVALID_PARAMETER; + } + RequiredSize =3D 2 * sizeof (EFI_RNG_ALGORITHM); =20 if (*RNGAlgorithmListSize < RequiredSize) { @@ -135,6 +145,10 @@ ArchGetSupportedRngAlgorithms ( return EFI_BUFFER_TOO_SMALL; } =20 + if (RNGAlgorithmList =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + CopyMem (&RNGAlgorithmList[0], &gEfiRngAlgorithmSp80090Ctr256Guid, sizeo= f (EFI_RNG_ALGORITHM)); =20 // x86 platforms also support EFI_RNG_ALGORITHM_RAW via RDSEED diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c b/SecurityPk= g/RandomNumberGenerator/RngDxe/RngDxe.c index 6f52eeff4a09..6608ca8804a5 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c @@ -28,55 +28,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include "RngDxeInternals.h" =20 -/** - Returns information about the random number generation implementation. - - @param[in] This A pointer to the EFI_RNG_PROTOCOL in= stance. - @param[in,out] RNGAlgorithmListSize On input, the size in bytes of RNGAl= gorithmList. - On output with a return code of EFI_= SUCCESS, the size - in bytes of the data returned in RNG= AlgorithmList. On output - with a return code of EFI_BUFFER_TOO= _SMALL, - the size of RNGAlgorithmList require= d to obtain the list. - @param[out] RNGAlgorithmList A caller-allocated memory buffer fil= led by the driver - with one EFI_RNG_ALGORITHM element f= or each supported - RNG algorithm. The list must not cha= nge across multiple - calls to the same driver. The first = algorithm in the list - is the default algorithm for the dri= ver. - - @retval EFI_SUCCESS The RNG algorithm list was returned = successfully. - @retval EFI_UNSUPPORTED The services is not supported by thi= s driver. - @retval EFI_DEVICE_ERROR The list of algorithms could not be = retrieved due to a - hardware or firmware error. - @retval EFI_INVALID_PARAMETER One or more of the parameters are in= correct. - @retval EFI_BUFFER_TOO_SMALL The buffer RNGAlgorithmList is too s= mall to hold the result. - -**/ -EFI_STATUS -EFIAPI -RngGetInfo ( - IN EFI_RNG_PROTOCOL *This, - IN OUT UINTN *RNGAlgorithmListSize, - OUT EFI_RNG_ALGORITHM *RNGAlgorithmList - ) -{ - EFI_STATUS Status; - - if ((This =3D=3D NULL) || (RNGAlgorithmListSize =3D=3D NULL)) { - return EFI_INVALID_PARAMETER; - } - - // - // Return algorithm list supported by driver. - // - if (RNGAlgorithmList !=3D NULL) { - Status =3D ArchGetSupportedRngAlgorithms (RNGAlgorithmListSize, RNGAlg= orithmList); - } else { - Status =3D EFI_INVALID_PARAMETER; - } - - return Status; -} - // // The Random Number Generator (RNG) protocol // diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h b/S= ecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h index 48d2d27c1608..7ecab140483d 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h @@ -74,31 +74,6 @@ RngGetRNG ( OUT UINT8 *RNGValue ); =20 -/** - Returns information about the random number generation implementation. - - @param[in,out] RNGAlgorithmListSize On input, the size in bytes of RNGAl= gorithmList. - On output with a return code of EFI_= SUCCESS, the size - in bytes of the data returned in RNG= AlgorithmList. On output - with a return code of EFI_BUFFER_TOO= _SMALL, - the size of RNGAlgorithmList require= d to obtain the list. - @param[out] RNGAlgorithmList A caller-allocated memory buffer fil= led by the driver - with one EFI_RNG_ALGORITHM element f= or each supported - RNG algorithm. The list must not cha= nge across multiple - calls to the same driver. The first = algorithm in the list - is the default algorithm for the dri= ver. - - @retval EFI_SUCCESS The RNG algorithm list was returned = successfully. - @retval EFI_BUFFER_TOO_SMALL The buffer RNGAlgorithmList is too s= mall to hold the result. - -**/ -UINTN -EFIAPI -ArchGetSupportedRngAlgorithms ( - IN OUT UINTN *RNGAlgorithmListSize, - OUT EFI_RNG_ALGORITHM *RNGAlgorithmList - ); - /** Runs CPU RNG instruction to fill a buffer of arbitrary size with random = bytes. =20 --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95328): https://edk2.groups.io/g/devel/message/95328 Mute This Topic: https://groups.io/mt/94407755/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 8 20:41:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+95329+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95329+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1666099853; cv=none; d=zohomail.com; s=zohoarc; b=Uygevwy09xzqYi0MCGNUkH6JPgn9byKLN1ZOSIvGZvgB/4RFKrTzIG1XX/vN/OfMy6EDQsLt1wK5vNEm4vp37j2euF422QyEsxJN2uu3doIRk/jRFaCW79OO2VoB9jYBntrN+9LayGZ7r+7es2pnSsfFGgyHE4hj1Ib237uHVOI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666099853; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=gJpPIIP9fYwUk4GFObNjqvj2kOQ5K62HoFBX1chGE8A=; b=iep3TsZGxBTQlJ92z118G5s/gK6zxiKZEwbGOeqzVlIfrF1iymjwAI6U91V3nw7PzoBRfzCFSKChZY1izW44lCAzX7vRMm2XRfJJv7qxRBNbkc9NqUHiaO8DTOFl4UxTOtfHnWQla7JXef9sNpKTdX2OY3d4vqS6roQ1lE/QToA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95329+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1666099853413520.6957260421785; Tue, 18 Oct 2022 06:30:53 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 69XkYY1788612xJIhJHeh8Ze; Tue, 18 Oct 2022 06:30:53 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.6892.1666099852252638484 for ; Tue, 18 Oct 2022 06:30:52 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1FB9A113E; Tue, 18 Oct 2022 06:30:58 -0700 (PDT) X-Received: from pierre123.arm.com (pierre123.nice.arm.com [10.34.100.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 827273F792; Tue, 18 Oct 2022 06:30:50 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v8 13/19] SecurityPkg/RngDxe: Documentation/include/parameter cleanup Date: Tue, 18 Oct 2022 15:20:46 +0200 Message-Id: <20221018132052.1359530-14-Pierre.Gondois@arm.com> In-Reply-To: <20221018132052.1359530-1-Pierre.Gondois@arm.com> References: <20221018132052.1359530-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: 7bqhvzmbPlAz49BxsYZVwlKBx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1666099853; bh=tCCBFMWTzsRfonlhojX4X1SAKgN/7bY5VL86rqpkSCU=; h=Cc:Date:From:Reply-To:Subject:To; b=HIJri6X00utu/EBoT5DW49LALVBJx4zKG6auoUDIjmJdMnM0ykHW0nHseIHc7Fx7vNC CxxzLcrSv7x9gmjYHeCw9tJWzkXSZNr5DZKWkiXR40k+ikigL6CHhXm/81OJficOWs9E6 EtgN+qDEe8XnK6knrcRYyLcFpHYhJf2UQnM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1666099855463100054 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois This patch: -Update RngGetBytes() documentation to align the function definition and declaration. -Improve input parameter checking. Even though 'This' it is not used, the parameter should always point to the current EFI_RNG_PROTOCOL. -Removes TimerLib inclusion as unused. Signed-off-by: Pierre Gondois --- SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c | 3 +-- SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c | 2 +- SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c b/Se= curityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c index 6d989f7ea376..f9c740d761ff 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c @@ -23,7 +23,6 @@ #include #include #include -#include #include =20 #include "RngDxeInternals.h" @@ -61,7 +60,7 @@ RngGetRNG ( { EFI_STATUS Status; =20 - if ((RNGValueLength =3D=3D 0) || (RNGValue =3D=3D NULL)) { + if ((This =3D=3D NULL) || (RNGValueLength =3D=3D 0) || (RNGValue =3D=3D = NULL)) { return EFI_INVALID_PARAMETER; } =20 diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c b/Secur= ityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c index b2d2236380fd..8f5d8e740f5e 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c @@ -59,7 +59,7 @@ RngGetRNG ( { EFI_STATUS Status; =20 - if ((RNGValueLength =3D=3D 0) || (RNGValue =3D=3D NULL)) { + if ((This =3D=3D NULL) || (RNGValueLength =3D=3D 0) || (RNGValue =3D=3D = NULL)) { return EFI_INVALID_PARAMETER; } =20 diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c b/SecurityPk= g/RandomNumberGenerator/RngDxe/RngDxe.c index 6608ca8804a5..d7905a7f4d72 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c @@ -23,7 +23,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include -#include #include =20 #include "RngDxeInternals.h" @@ -72,7 +71,7 @@ RngDriverEntry ( } =20 /** - Calls RDRAND to fill a buffer of arbitrary size with random bytes. + Runs CPU RNG instruction to fill a buffer of arbitrary size with random = bytes. =20 @param[in] Length Size of the buffer, in bytes, to fill with. @param[out] RandBuffer Pointer to the buffer to store the random res= ult. --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95329): https://edk2.groups.io/g/devel/message/95329 Mute This Topic: https://groups.io/mt/94407756/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 8 20:41:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+95330+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95330+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1666099855; cv=none; d=zohomail.com; s=zohoarc; b=m40kmpbNkpKFRkA7dN5tuMl2VhSmCS4xxz669LUZW5VYq8joexwpkTgf/OkD1pTThMToka6IEPZdIoa6yUTICR5mG5VYRK/YvDcD6onjFF+eYJ7iEPRVk5kDSD93YO4hnHorawpoSZ5RA+aLLY6voKDkKa/9iL/nWWyzOio/PvI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666099855; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=lETFtK4tIMtHNLrNSdudT/CjGfnQ1yTMs0jdgEkZrJA=; b=a/1jviE8MIFQ7+W6aBs4iH84ccNld23aLGMwd/wWGn0R5ILLTy0PtI24AL5Z/GLyZMSD0S/LSpuUTFk/x5OwzBZOja+vuiWhJi6yUTrpk8nAqeG8MbfC3vB78DrhHnl22u3opbKBQEA5VWU2lQZYIdQMlh0JhL7lHSjq7inHhuw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95330+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1666099855557819.1272010490362; Tue, 18 Oct 2022 06:30:55 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id xuncYY1788612x2rFDQw6xrs; Tue, 18 Oct 2022 06:30:55 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.6668.1666099854010255304 for ; Tue, 18 Oct 2022 06:30:54 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BCF4C1758; Tue, 18 Oct 2022 06:30:59 -0700 (PDT) X-Received: from pierre123.arm.com (pierre123.nice.arm.com [10.34.100.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2B4E23F792; Tue, 18 Oct 2022 06:30:52 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v8 14/19] SecurityPkg/RngDxe: Check before advertising Cpu Rng algo Date: Tue, 18 Oct 2022 15:20:47 +0200 Message-Id: <20221018132052.1359530-15-Pierre.Gondois@arm.com> In-Reply-To: <20221018132052.1359530-1-Pierre.Gondois@arm.com> References: <20221018132052.1359530-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: moxn9Ed9N956YVsETvCqBLVmx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1666099855; bh=7HkSHiTyFvRwq8DIHguYdjGq49koXgiPM0H44UYv+Uo=; h=Cc:Date:From:Reply-To:Subject:To; b=KLnlWkE1RRqgmtB/4fOBfxVWlL099EytK1sX4c2bL5PC2WjlLD8ZsJX+91anpU+K6b4 ZHfAoHwFXnavAZnV31p5xvppbugeOKqrZrpS/yLTNiCRXTDMDpA/HtN7LdE04Q61txSbE 2CjWs8WFGcVZQ9g/45Y3IHef2fkdY39Qe7g= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1666099857522100058 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois RngGetBytes() relies on the RngLib. The RngLib might use the RNDR instruction if the FEAT_RNG feature is present. RngGetInfo and RngGetRNG both must check that RngGetBytes() is working before advertising/using it. To do so, allocate an array storing the available algorithms. The Rng algorithm at the lowest index will be the default Rng algorithm. The array is shared between RngGetInfo and RngGetRNG. This array is allocated when the driver is loaded, and freed when unloaded. This patch also prevents from having PcdCpuRngSupportedAlgorithm let to a zero GUID, but let the possibility to have no valid Rng algorithm in such case. Signed-off-by: Pierre Gondois --- Notes: v4: - Replace RngInitAvailableAlgoArray() with GetAvailableAlgorithms() and FreeAvailableAlgorithms() and add an implementation of these functions for all archs. - Make mAvailableAlgoArrayCount and mAvailableAlgoArray global variable and dynamically allocated instead of static. - Add UNLOAD_IMAGE function to free mAvailableAlgoArray. - All of this was done in order to remove the: '#ifdef MDE_CPU_AARCH64' statement in the v3 of: SecurityPkg/RngDxe: Add Arm support of RngDxe .../RngDxe/AArch64/RngDxe.c | 87 +++++++++++++++++-- .../RngDxe/Rand/RngDxe.c | 26 ++++++ .../RandomNumberGenerator/RngDxe/RngDxe.c | 40 ++++++++- .../RandomNumberGenerator/RngDxe/RngDxe.inf | 1 + .../RngDxe/RngDxeInternals.h | 27 ++++++ 5 files changed, 172 insertions(+), 9 deletions(-) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c b/Se= curityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c index f9c740d761ff..09a5924a699b 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c @@ -22,11 +22,63 @@ =20 #include #include +#include +#include #include +#include #include =20 #include "RngDxeInternals.h" =20 +// Maximum number of Rng algorithms. +#define RNG_AVAILABLE_ALGO_MAX 1 + +/** Allocate and initialize mAvailableAlgoArray with the available + Rng algorithms. Also update mAvailableAlgoArrayCount. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +EFI_STATUS +EFIAPI +GetAvailableAlgorithms ( + VOID + ) +{ + UINT64 DummyRand; + + // Allocate RNG_AVAILABLE_ALGO_MAX entries to avoid evaluating + // Rng algorithms 2 times, one for the allocation, one to populate. + mAvailableAlgoArray =3D AllocateZeroPool (RNG_AVAILABLE_ALGO_MAX); + if (mAvailableAlgoArray =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // Check RngGetBytes() before advertising PcdCpuRngSupportedAlgorithm. + if (!EFI_ERROR (RngGetBytes (sizeof (DummyRand), (UINT8 *)&DummyRand))) { + CopyMem ( + &mAvailableAlgoArray[mAvailableAlgoArrayCount], + PcdGetPtr (PcdCpuRngSupportedAlgorithm), + sizeof (EFI_RNG_ALGORITHM) + ); + mAvailableAlgoArrayCount++; + } + + return EFI_SUCCESS; +} + +/** Free mAvailableAlgoArray. +**/ +VOID +EFIAPI +FreeAvailableAlgorithms ( + VOID + ) +{ + FreePool (mAvailableAlgoArray); + return; +} + /** Produces and returns an RNG value using either the default or specified = RNG algorithm. =20 @@ -59,6 +111,7 @@ RngGetRNG ( ) { EFI_STATUS Status; + UINTN Index; =20 if ((This =3D=3D NULL) || (RNGValueLength =3D=3D 0) || (RNGValue =3D=3D = NULL)) { return EFI_INVALID_PARAMETER; @@ -68,9 +121,21 @@ RngGetRNG ( // // Use the default RNG algorithm if RNGAlgorithm is NULL. // - RNGAlgorithm =3D PcdGetPtr (PcdCpuRngSupportedAlgorithm); + for (Index =3D 0; Index < mAvailableAlgoArrayCount; Index++) { + if (!IsZeroGuid (&mAvailableAlgoArray[Index])) { + RNGAlgorithm =3D &mAvailableAlgoArray[Index]; + goto FoundAlgo; + } + } + + if (Index =3D=3D mAvailableAlgoArrayCount) { + // No algorithm available. + ASSERT (Index !=3D mAvailableAlgoArrayCount); + return EFI_DEVICE_ERROR; + } } =20 +FoundAlgo: if (CompareGuid (RNGAlgorithm, PcdGetPtr (PcdCpuRngSupportedAlgorithm)))= { Status =3D RngGetBytes (RNGValueLength, RNGValue); return Status; @@ -113,24 +178,30 @@ RngGetInfo ( OUT EFI_RNG_ALGORITHM *RNGAlgorithmList ) { - UINTN RequiredSize; - EFI_RNG_ALGORITHM *CpuRngSupportedAlgorithm; - - RequiredSize =3D sizeof (EFI_RNG_ALGORITHM); + UINTN RequiredSize; =20 if ((This =3D=3D NULL) || (RNGAlgorithmListSize =3D=3D NULL)) { return EFI_INVALID_PARAMETER; } =20 + RequiredSize =3D mAvailableAlgoArrayCount * sizeof (EFI_RNG_ALGORITHM); + + if (RequiredSize =3D=3D 0) { + // No supported algorithms found. + return EFI_UNSUPPORTED; + } + if (*RNGAlgorithmListSize < RequiredSize) { *RNGAlgorithmListSize =3D RequiredSize; return EFI_BUFFER_TOO_SMALL; } =20 - CpuRngSupportedAlgorithm =3D PcdGetPtr (PcdCpuRngSupportedAlgorithm); - - CopyMem (&RNGAlgorithmList[0], CpuRngSupportedAlgorithm, sizeof (EFI_RNG= _ALGORITHM)); + if (RNGAlgorithmList =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } =20 + // There is no gap in the array, so copy the block. + CopyMem (RNGAlgorithmList, mAvailableAlgoArray, RequiredSize); *RNGAlgorithmListSize =3D RequiredSize; return EFI_SUCCESS; } diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c b/Secur= ityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c index 8f5d8e740f5e..677600bed7ab 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Rand/RngDxe.c @@ -26,6 +26,32 @@ =20 #include "RngDxeInternals.h" =20 +/** Allocate and initialize mAvailableAlgoArray with the available + Rng algorithms. Also update mAvailableAlgoArrayCount. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +EFI_STATUS +EFIAPI +GetAvailableAlgorithms ( + VOID + ) +{ + return EFI_SUCCESS; +} + +/** Free mAvailableAlgoArray. +**/ +VOID +EFIAPI +FreeAvailableAlgorithms ( + VOID + ) +{ + return; +} + /** Produces and returns an RNG value using either the default or specified = RNG algorithm. =20 diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c b/SecurityPk= g/RandomNumberGenerator/RngDxe/RngDxe.c index d7905a7f4d72..421abb52b8bf 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.c @@ -27,6 +27,13 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 #include "RngDxeInternals.h" =20 +// +// Array containing the validated Rng algorithm. +// The entry with the lowest index will be the default algorithm. +// +UINTN mAvailableAlgoArrayCount; +EFI_RNG_ALGORITHM *mAvailableAlgoArray; + // // The Random Number Generator (RNG) protocol // @@ -66,8 +73,39 @@ RngDriverEntry ( &mRngRdRand, NULL ); + if (EFI_ERROR (Status)) { + return Status; + } =20 - return Status; + // + // Get the list of available algorithm. + // + return GetAvailableAlgorithms (); +} + +/** + This is the unload handle for RndgDxe module. + + Disconnect the driver specified by ImageHandle from all the devices in t= he handle database. + Uninstall all the protocols installed in the driver entry point. + + @param[in] ImageHandle The drivers' driver image. + + @retval EFI_SUCCESS The image is unloaded. + @retval Others Failed to unload the image. + +**/ +EFI_STATUS +EFIAPI +RngDriverUnLoad ( + IN EFI_HANDLE ImageHandle + ) +{ + // + // Free the list of available algorithm. + // + FreeAvailableAlgorithms (); + return EFI_SUCCESS; } =20 /** diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf b/Security= Pkg/RandomNumberGenerator/RngDxe/RngDxe.inf index 60efb5562ee0..1985dfbb4619 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf @@ -22,6 +22,7 @@ [Defines] MODULE_TYPE =3D DXE_DRIVER VERSION_STRING =3D 1.0 ENTRY_POINT =3D RngDriverEntry + UNLOAD_IMAGE =3D RngDriverUnLoad MODULE_UNI_FILE =3D RngDxe.uni =20 # diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h b/S= ecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h index 7ecab140483d..f75140260820 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxeInternals.h @@ -12,6 +12,33 @@ =20 #include =20 +// +// Array containing the validated Rng algorithm. +// The entry with the lowest index will be the default algorithm. +// +extern UINTN mAvailableAlgoArrayCount; +extern EFI_RNG_ALGORITHM *mAvailableAlgoArray; + +/** Allocate and initialize mAvailableAlgoArray with the available + Rng algorithms. Also update mAvailableAlgoArrayCount. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +EFI_STATUS +EFIAPI +GetAvailableAlgorithms ( + VOID + ); + +/** Free mAvailableAlgoArray. +**/ +VOID +EFIAPI +FreeAvailableAlgorithms ( + VOID + ); + /** Returns information about the random number generation implementation. =20 --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95330): https://edk2.groups.io/g/devel/message/95330 Mute This Topic: https://groups.io/mt/94407759/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 8 20:41:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+95331+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95331+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1666099857; cv=none; d=zohomail.com; s=zohoarc; b=NeGikbC/HZGhu2jfjulu7D4bRCHDZE3koLdcsDGK93g4CXIhySr5kshx1A/AcLQdUmIxKkAr060ztwKYeBAMIVGoJKxU2zc9KBzhUfglIT0raH8tqWhrs5v5N94n6/uaeA6cBTF2jn0eQ6enkAMtC4ijHLyEsnZIBvEQCPrcLvk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666099857; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=HKOM2aadji9s2zLcamYp7ZU7Q2mj6Etla7xxIKuor0U=; b=eaONg/4R5kttz0mMZ2wSlgiG+Vw5MC2z5fLVO2rzq9BoL878a9rt2uT4pXNaKLOu6F8doll5fDLPM3icoswgj5MF06SJdLa1YhR5AmeWbirUoZybHbNFj7iWFU7Iqihpl5r4OgOxqBfF1bf1LOyhE4uTa04UVJ3EHXqhGHQK/ig= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95331+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1666099857475843.2666650167589; Tue, 18 Oct 2022 06:30:57 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id IQqqYY1788612xAZnzSzoV7z; Tue, 18 Oct 2022 06:30:56 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.6811.1666099855467007555 for ; Tue, 18 Oct 2022 06:30:55 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 66660244B; Tue, 18 Oct 2022 06:31:01 -0700 (PDT) X-Received: from pierre123.arm.com (pierre123.nice.arm.com [10.34.100.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C91653F792; Tue, 18 Oct 2022 06:30:53 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v8 15/19] SecurityPkg/RngDxe: Add AArch64 RawAlgorithm support through TrngLib Date: Tue, 18 Oct 2022 15:20:48 +0200 Message-Id: <20221018132052.1359530-16-Pierre.Gondois@arm.com> In-Reply-To: <20221018132052.1359530-1-Pierre.Gondois@arm.com> References: <20221018132052.1359530-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: B5fMX1dMtai34rHxTARS7mOmx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1666099856; bh=a7Qjpt7C+OiEA9dbX0MD0TBPWlAQMnUghPZpybu9l74=; h=Cc:Date:From:Reply-To:Subject:To; b=cAmb9+ZfSnvKgjLuMajX+fwbR2tQlnu5i+PTFOaDt1Im5crulxrsb3VwBBVDOK8Uzb4 uhl1rlM8v4lkp4tyhT+IZkGVcOJ+kuGQekE6aLdJXhewV3yWdwiJRW7h4azO3sqR/vAQE AAhkeKaU3A+KcHmqbGFOZDHoS0M6mM6Mrpk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1666099859686100003 Content-Type: text/plain; charset="utf-8" From: Sami Mujawar Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3D3668) RawAlgorithm is used to provide access to entropy that is suitable for cryptographic applications. Therefore, add RawAlgorithm support that provides access to entropy using the TrngLib. Also remove unused UefiBootServicesTableLib library inclusion and Status variable. Signed-off-by: Pierre Gondois --- Notes: v4: - Use TrngLib from MdePkg instead of ArmPkg. This also allows to not build ArmMonitorLib, ArmSmcLib and ArmHvcLib. [Jiewen, Pierre] .../RngDxe/AArch64/RngDxe.c | 28 ++++++-- .../RandomNumberGenerator/RngDxe/ArmTrng.c | 71 +++++++++++++++++++ .../RandomNumberGenerator/RngDxe/RngDxe.inf | 5 ++ SecurityPkg/SecurityPkg.dsc | 3 + 4 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 SecurityPkg/RandomNumberGenerator/RngDxe/ArmTrng.c diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c b/Se= curityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c index 09a5924a699b..f5910e3b999f 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c @@ -1,11 +1,13 @@ /** @file RNG Driver to produce the UEFI Random Number Generator protocol. =20 - The driver will use the RNDR instruction to produce random numbers. + The driver can use RNDR instruction (through the RngLib and if FEAT_RNG = is + present) to produce random numbers. It also uses the Arm FW-TRNG interfa= ce + to implement EFI_RNG_ALGORITHM_RAW. =20 RNG Algorithms defined in UEFI 2.4: - EFI_RNG_ALGORITHM_SP800_90_CTR_256_GUID - - EFI_RNG_ALGORITHM_RAW - Unsupported + - EFI_RNG_ALGORITHM_RAW - EFI_RNG_ALGORITHM_SP800_90_HMAC_256_GUID - EFI_RNG_ALGORITHM_SP800_90_HASH_256_GUID - EFI_RNG_ALGORITHM_X9_31_3DES_GUID - Unsupported @@ -26,12 +28,14 @@ #include #include #include +#include +#include #include =20 #include "RngDxeInternals.h" =20 // Maximum number of Rng algorithms. -#define RNG_AVAILABLE_ALGO_MAX 1 +#define RNG_AVAILABLE_ALGO_MAX 2 =20 /** Allocate and initialize mAvailableAlgoArray with the available Rng algorithms. Also update mAvailableAlgoArrayCount. @@ -46,8 +50,9 @@ GetAvailableAlgorithms ( ) { UINT64 DummyRand; + UINT16 MajorRevision; + UINT16 MinorRevision; =20 - // Allocate RNG_AVAILABLE_ALGO_MAX entries to avoid evaluating // Rng algorithms 2 times, one for the allocation, one to populate. mAvailableAlgoArray =3D AllocateZeroPool (RNG_AVAILABLE_ALGO_MAX); if (mAvailableAlgoArray =3D=3D NULL) { @@ -64,6 +69,16 @@ GetAvailableAlgorithms ( mAvailableAlgoArrayCount++; } =20 + // Raw algorithm (Trng) + if (!EFI_ERROR (GetTrngVersion (&MajorRevision, &MinorRevision))) { + CopyMem ( + &mAvailableAlgoArray[mAvailableAlgoArrayCount], + &gEfiRngAlgorithmRaw, + sizeof (EFI_RNG_ALGORITHM) + ); + mAvailableAlgoArrayCount++; + } + return EFI_SUCCESS; } =20 @@ -141,6 +156,11 @@ FoundAlgo: return Status; } =20 + // Raw algorithm (Trng) + if (CompareGuid (RNGAlgorithm, &gEfiRngAlgorithmRaw)) { + return GenerateEntropy (RNGValueLength, RNGValue); + } + // // Other algorithms are unsupported by this driver. // diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmTrng.c b/SecurityP= kg/RandomNumberGenerator/RngDxe/ArmTrng.c new file mode 100644 index 000000000000..6100e02b32b0 --- /dev/null +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/ArmTrng.c @@ -0,0 +1,71 @@ +/** @file + RNG Driver to produce the UEFI Random Number Generator protocol. + + The driver implements the EFI_RNG_ALGORITHM_RAW using the FW-TRNG + interface to provide entropy. + + Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include + +#include "RngDxeInternals.h" + +/** + Generate high-quality entropy source using a TRNG or through RDRAND. + + @param[in] Length Size of the buffer, in bytes, to fill with. + @param[out] Entropy Pointer to the buffer to store the entropy da= ta. + + @retval RETURN_SUCCESS The function completed successfully. + @retval RETURN_INVALID_PARAMETER Invalid parameter. + @retval RETURN_UNSUPPORTED Function not implemented. + @retval RETURN_BAD_BUFFER_SIZE Buffer size is too small. + @retval RETURN_NOT_READY No Entropy available. +**/ +EFI_STATUS +EFIAPI +GenerateEntropy ( + IN UINTN Length, + OUT UINT8 *Entropy + ) +{ + EFI_STATUS Status; + UINTN CollectedEntropyBits; + UINTN RequiredEntropyBits; + UINTN EntropyBits; + UINTN Index; + UINTN MaxBits; + + ZeroMem (Entropy, Length); + + RequiredEntropyBits =3D (Length << 3); + Index =3D 0; + CollectedEntropyBits =3D 0; + MaxBits =3D GetTrngMaxSupportedEntropyBits (); + while (CollectedEntropyBits < RequiredEntropyBits) { + EntropyBits =3D MIN ((RequiredEntropyBits - CollectedEntropyBits), Max= Bits); + Status =3D GetTrngEntropy ( + EntropyBits, + (Length - Index), + &Entropy[Index] + ); + if (EFI_ERROR (Status)) { + // Discard the collected bits. + ZeroMem (Entropy, Length); + return Status; + } + + CollectedEntropyBits +=3D EntropyBits; + Index +=3D (EntropyBits >> 3); + } // while + + return Status; +} diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf b/Security= Pkg/RandomNumberGenerator/RngDxe/RngDxe.inf index 1985dfbb4619..f6e08da96140 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf @@ -43,8 +43,10 @@ [Sources.IA32, Sources.X64] =20 [Sources.AARCH64] AArch64/RngDxe.c + ArmTrng.c =20 [Packages] + MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec SecurityPkg/SecurityPkg.dec =20 @@ -57,6 +59,9 @@ [LibraryClasses] TimerLib RngLib =20 +[LibraryClasses.AARCH64] + TrngLib + [Guids] gEfiRngAlgorithmSp80090Hash256Guid ## SOMETIMES_PRODUCES ## GUID = # Unique ID of the algorithm for RNG gEfiRngAlgorithmSp80090Hmac256Guid ## SOMETIMES_PRODUCES ## GUID = # Unique ID of the algorithm for RNG diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc index 6bf53c565882..a6b4952182cb 100644 --- a/SecurityPkg/SecurityPkg.dsc +++ b/SecurityPkg/SecurityPkg.dsc @@ -4,6 +4,7 @@ # Copyright (c) 2009 - 2021, Intel Corporation. All rights reserved.
# (C) Copyright 2015-2020 Hewlett Packard Enterprise Development LP
# Copyright (c) 2022, Loongson Technology Corporation Limited. All rights = reserved.
+# Copyright (c) 2021 - 2022, Arm Limited. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent # ## @@ -89,6 +90,8 @@ [LibraryClasses.ARM, LibraryClasses.AARCH64] =20 ArmSoftFloatLib|ArmPkg/Library/ArmSoftFloatLib/ArmSoftFloatLib.inf =20 + TrngLib|MdePkg/Library/BaseTrngLibNull/BaseTrngLibNull.inf + [LibraryClasses.ARM] RngLib|MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf =20 --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95331): https://edk2.groups.io/g/devel/message/95331 Mute This Topic: https://groups.io/mt/94407761/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 8 20:41:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+95332+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95332+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1666099858; cv=none; d=zohomail.com; s=zohoarc; b=a08k6qTmCUyDQEAZ0wofrTwjIZKX/f3xQvQA3+8vGN1rDn/UF57szrFtMt7m3ZwKgcuV0c/SgGNjgMQR7Tyyj1apLQRSx2rIUovPRieF0TEZPZjEcXSG5thXkB8JYCX+2OFyUtmrJOEar6M7KrC07Oi160UXbXquIHnq6YAOmM0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666099858; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=SZSwHpXCya8vlsBW36vZYX2i0VnWMQ6jabgw1mne9pQ=; b=AkyDVqKEb9edbIHjSk/t5ZlQgUNVrwOSTr4Qcp0OsFdr/AfR0Yl7UlinUW91I0oXZ6mMIuEpPz1fEfUpsmMyaGp5o6t/yJoGccvZzM3MKkV9uwpa6nGi7NWbzlogMCjZajTyxMs2vzYrDml16Ea7/1vogVju+fbWQ63Myulpjlg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95332+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1666099858225666.9841208772211; Tue, 18 Oct 2022 06:30:58 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id byc0YY1788612xQAUJxcRSGF; Tue, 18 Oct 2022 06:30:57 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.6670.1666099857188756322 for ; Tue, 18 Oct 2022 06:30:57 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 19122113E; Tue, 18 Oct 2022 06:31:03 -0700 (PDT) X-Received: from pierre123.arm.com (pierre123.nice.arm.com [10.34.100.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 71F8F3F792; Tue, 18 Oct 2022 06:30:55 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v8 16/19] SecurityPkg/RngDxe: Add debug warning for NULL PcdCpuRngSupportedAlgorithm Date: Tue, 18 Oct 2022 15:20:49 +0200 Message-Id: <20221018132052.1359530-17-Pierre.Gondois@arm.com> In-Reply-To: <20221018132052.1359530-1-Pierre.Gondois@arm.com> References: <20221018132052.1359530-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: j3VlAi8ilBAUgKlhJWlN3xxRx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1666099857; bh=/zrYuwyLNQK0qb6V+gu5tzlDxH6cI5lTlWuJJZtoSks=; h=Cc:Date:From:Reply-To:Subject:To; b=ZQLj/jjQDBwLYHBx2xgGpbt7jGQ1ZZjiY/TKJMfPle0vMk0gtg2PGMaopL271iMsNr8 kfl6XWU5JUL+cw8hI47QMZWfS1wUpvmz3r3p8MClbx29TR399A1a2rAHTM1aKwzLyeAH2 h7E5U/sZTjNTtXGcs2PbyHB6tOVqF6aD8Dk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1666099859629100001 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois PcdCpuRngSupportedAlgorithm should allow to identify the the algorithm used by the RNDR CPU instruction to generate a random number. Add a debug warning if the Pcd is not set. Signed-off-by: Pierre Gondois --- .../RandomNumberGenerator/RngDxe/AArch64/RngDxe.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c b/Se= curityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c index f5910e3b999f..0d853720ecb1 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c @@ -67,6 +67,16 @@ GetAvailableAlgorithms ( sizeof (EFI_RNG_ALGORITHM) ); mAvailableAlgoArrayCount++; + + DEBUG_CODE_BEGIN (); + if (IsZeroGuid (PcdGetPtr (PcdCpuRngSupportedAlgorithm))) { + DEBUG (( + DEBUG_WARN, + "PcdCpuRngSupportedAlgorithm should be a non-zero GUID\n" + )); + } + + DEBUG_CODE_END (); } =20 // Raw algorithm (Trng) --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95332): https://edk2.groups.io/g/devel/message/95332 Mute This Topic: https://groups.io/mt/94407762/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 8 20:41:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+95333+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95333+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1666099859; cv=none; d=zohomail.com; s=zohoarc; b=hEaOkUpQEmwNVMTl1dr6D950UK96nbyDCsruIdUFCo7c6VNa2EJLMbYE0d1deQWWhNAdKGXs3OptCs+smzTiLwUbmkZr6E0IhUpKR74yZnHZTv3d72Nkx8WG/b3s6kXMj192y3myUy9ZfUow0vclipREx6NtZZH1lsO1xbUvpBA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666099859; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=nFrNLtVua19iAl6PhdQxbGPkwIN1w2N6jnICGn91aOw=; b=IULbeZaJ1K1vcJ0PExcYrWt2XJxUEY6ktSQnAHD3T3yoA7gGjrtxPdEMKi+6m0BeLthrmaciDh1yOQdFR1u1zjVZU1gufvErP7weUE2KACCbiPO4wVDnePQYvMPMEdtl41S7oNKkljzcErJ+fzhj/o3WY2J4I2xq6n03Yp7sozU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95333+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1666099859839161.7421214848266; Tue, 18 Oct 2022 06:30:59 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 5hZMYY1788612xa4B7BpmtnP; Tue, 18 Oct 2022 06:30:59 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web11.6671.1666099858834249476 for ; Tue, 18 Oct 2022 06:30:58 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BFE4B2454; Tue, 18 Oct 2022 06:31:04 -0700 (PDT) X-Received: from pierre123.arm.com (pierre123.nice.arm.com [10.34.100.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 251343F792; Tue, 18 Oct 2022 06:30:57 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v8 17/19] SecurityPkg/RngDxe: Rename AArch64/RngDxe.c Date: Tue, 18 Oct 2022 15:20:50 +0200 Message-Id: <20221018132052.1359530-18-Pierre.Gondois@arm.com> In-Reply-To: <20221018132052.1359530-1-Pierre.Gondois@arm.com> References: <20221018132052.1359530-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: 80y04icBfso7zm1CflU96KN2x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1666099859; bh=N34t0RmThF3JztB4Sqh5AtKKkk2ADZnwqQX2A/KdJ4Y=; h=Cc:Date:From:Reply-To:Subject:To; b=rFKgFJyh1I7+nKbpLfx9uX23VNfvlfMsIgwyviJKLlCajCiIZNBwm0s93+7DRKHJlAK gb6uodEBeUKROgCIx0nU4ohl6cOsokLJVQwSGxNvaBwqYfXJxA+3Eq1kvCsmDDw5Fa6dh dfqbzLYGYitxToxUECRKbu4iwBIGttk8e8w= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1666099861485100007 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois To re-use the AArch64/RngDxe.c for an Arm implementation, rename AArch64/RngDxe.c to ArmRngDxe.c. Acked-by: Leif Lindholm Signed-off-by: Pierre Gondois --- .../RngDxe/{AArch64/RngDxe.c =3D> ArmRngDxe.c} | 0 SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename SecurityPkg/RandomNumberGenerator/RngDxe/{AArch64/RngDxe.c =3D> Arm= RngDxe.c} (100%) diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c b/Se= curityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c similarity index 100% rename from SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/RngDxe.c rename to SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf b/Security= Pkg/RandomNumberGenerator/RngDxe/RngDxe.inf index f6e08da96140..337becf5224f 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf @@ -42,7 +42,7 @@ [Sources.IA32, Sources.X64] Rand/AesCore.h =20 [Sources.AARCH64] - AArch64/RngDxe.c + ArmRngDxe.c ArmTrng.c =20 [Packages] --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95333): https://edk2.groups.io/g/devel/message/95333 Mute This Topic: https://groups.io/mt/94407763/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 8 20:41:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+95334+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95334+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1666099861; cv=none; d=zohomail.com; s=zohoarc; b=ePO+muMn6jVETf8Dp+rBq5DsdZeLcfcl1Zuh7yBxYWAbNeBYvc+lybjPwzIgR1JKoXmZxRRBl0RCxSKbryHgSlKvY6K6uQiltRDserSEDkF7+dc2rPh+HFiX/U6i81YxpuyN0QmrYuHM2Kft6mfK1T+8zju10Ft7GEW+5WeYL3M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666099861; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=GZk5q+xplyJyEKB7qn2OP/xYOplm5qisAcGg4EhZfus=; b=LUth1xvOOs9RPHwklFMr5HprCoeN/NaMc4aDQ8WqRW/VgJUC4YCuZZ9p82+wx3mqZBTkEXizfZcbF7caZcJL2v61hvS+VbVDcd4pHEQ0J2XHhnUyzVQwwSEXfJ2ZwmRTUjgvi+8cluuRtLL1VNryRZBIBX53GnkVQ4x9yz+O0dY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95334+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1666099861570562.610661213289; Tue, 18 Oct 2022 06:31:01 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id wv8qYY1788612xFqWYy5buTP; Tue, 18 Oct 2022 06:31:01 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web08.6893.1666099860517258706 for ; Tue, 18 Oct 2022 06:31:00 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6915024C0; Tue, 18 Oct 2022 06:31:06 -0700 (PDT) X-Received: from pierre123.arm.com (pierre123.nice.arm.com [10.34.100.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id CBAA03F792; Tue, 18 Oct 2022 06:30:58 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v8 18/19] SecurityPkg/RngDxe: Add Arm support of RngDxe Date: Tue, 18 Oct 2022 15:20:51 +0200 Message-Id: <20221018132052.1359530-19-Pierre.Gondois@arm.com> In-Reply-To: <20221018132052.1359530-1-Pierre.Gondois@arm.com> References: <20221018132052.1359530-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: f4f0E8QuVo4182oPyNxi5dL5x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1666099861; bh=gjOBABCSVBMoYU04R8/r1T2EYOGeUPsrf5pSAr92Tgk=; h=Cc:Date:From:Reply-To:Subject:To; b=bkvXRg/SMu1ZeuCzR85wtvt5pznltbCnySkSzWre+zgwxhEsZiqnGt4hMmfFl1R5+Vi zsIoFUXtneDYfyLLFyMkYa25jrf7PONIZoGNOdOf5Gi20cLJyeVQpRPUbczRPrUD9l+dV arjHuYnFFxnWO3y+GUCEwNsO3yH7YIPGfiM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1666099863567100012 Content-Type: text/plain; charset="utf-8" From: Pierre Gondois Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3D3668) Add RngDxe support for Arm. This implementation uses the TrngLib to support the RawAlgorithm and doens't support the RNDR instruction. To re-use the RngGetRNG(), RngGetInfo() and FreeAvailableAlgorithms() functions, create Arm/AArch64 files which implement the arch specific function GetAvailableAlgorithms(). Indeed, FEAT_RNG instruction is not supported on Arm. Signed-off-by: Pierre Gondois --- Notes: v4: - Add AArch64/AArch64Algo.c and Arm/ArmAlgo.c that hold an arch specific implementation of GetAvailableAlgorithms(). .../RngDxe/AArch64/AArch64Algo.c | 72 +++++++++++++++++++ .../RngDxe/Arm/ArmAlgo.c | 51 +++++++++++++ .../RandomNumberGenerator/RngDxe/ArmRngDxe.c | 60 ---------------- .../RandomNumberGenerator/RngDxe/RngDxe.inf | 12 +++- SecurityPkg/SecurityPkg.dsc | 2 +- 5 files changed, 133 insertions(+), 64 deletions(-) create mode 100644 SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch6= 4Algo.c create mode 100644 SecurityPkg/RandomNumberGenerator/RngDxe/Arm/ArmAlgo.c diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c= b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c new file mode 100644 index 000000000000..d7e80a0d0d0d --- /dev/null +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/AArch64/AArch64Algo.c @@ -0,0 +1,72 @@ +/** @file + Aarch64 specific code. + + Copyright (c) 2022, Arm Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include +#include + +#include "RngDxeInternals.h" + +// Maximum number of Rng algorithms. +#define RNG_AVAILABLE_ALGO_MAX 2 + +/** Allocate and initialize mAvailableAlgoArray with the available + Rng algorithms. Also update mAvailableAlgoArrayCount. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +EFI_STATUS +EFIAPI +GetAvailableAlgorithms ( + VOID + ) +{ + UINT64 DummyRand; + UINT16 MajorRevision; + UINT16 MinorRevision; + + // Rng algorithms 2 times, one for the allocation, one to populate. + mAvailableAlgoArray =3D AllocateZeroPool (RNG_AVAILABLE_ALGO_MAX); + if (mAvailableAlgoArray =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // Check RngGetBytes() before advertising PcdCpuRngSupportedAlgorithm. + if (!EFI_ERROR (RngGetBytes (sizeof (DummyRand), (UINT8 *)&DummyRand))) { + CopyMem ( + &mAvailableAlgoArray[mAvailableAlgoArrayCount], + PcdGetPtr (PcdCpuRngSupportedAlgorithm), + sizeof (EFI_RNG_ALGORITHM) + ); + mAvailableAlgoArrayCount++; + + DEBUG_CODE_BEGIN (); + if (IsZeroGuid (PcdGetPtr (PcdCpuRngSupportedAlgorithm))) { + DEBUG (( + DEBUG_WARN, + "PcdCpuRngSupportedAlgorithm should be a non-zero GUID\n" + )); + } + + DEBUG_CODE_END (); + } + + // Raw algorithm (Trng) + if (!EFI_ERROR (GetTrngVersion (&MajorRevision, &MinorRevision))) { + CopyMem ( + &mAvailableAlgoArray[mAvailableAlgoArrayCount], + &gEfiRngAlgorithmRaw, + sizeof (EFI_RNG_ALGORITHM) + ); + mAvailableAlgoArrayCount++; + } + + return EFI_SUCCESS; +} diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/Arm/ArmAlgo.c b/Secur= ityPkg/RandomNumberGenerator/RngDxe/Arm/ArmAlgo.c new file mode 100644 index 000000000000..5acef91fe3b2 --- /dev/null +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/Arm/ArmAlgo.c @@ -0,0 +1,51 @@ +/** @file + Arm specific code. + + Copyright (c) 2022, Arm Limited. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include +#include +#include + +#include "RngDxeInternals.h" + +// Maximum number of Rng algorithms. +#define RNG_AVAILABLE_ALGO_MAX 1 + +/** Allocate and initialize mAvailableAlgoArray with the available + Rng algorithms. Also update mAvailableAlgoArrayCount. + + @retval EFI_SUCCESS The function completed successfully. + @retval EFI_OUT_OF_RESOURCES Could not allocate memory. +**/ +EFI_STATUS +EFIAPI +GetAvailableAlgorithms ( + VOID + ) +{ + UINT16 MajorRevision; + UINT16 MinorRevision; + + // Rng algorithms 2 times, one for the allocation, one to populate. + mAvailableAlgoArray =3D AllocateZeroPool (RNG_AVAILABLE_ALGO_MAX); + if (mAvailableAlgoArray =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // Raw algorithm (Trng) + if (!EFI_ERROR (GetTrngVersion (&MajorRevision, &MinorRevision))) { + CopyMem ( + &mAvailableAlgoArray[mAvailableAlgoArrayCount], + &gEfiRngAlgorithmRaw, + sizeof (EFI_RNG_ALGORITHM) + ); + mAvailableAlgoArrayCount++; + } + + return EFI_SUCCESS; +} diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c b/Securit= yPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c index 0d853720ecb1..5ba319899ce9 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c @@ -28,70 +28,10 @@ #include #include #include -#include -#include #include =20 #include "RngDxeInternals.h" =20 -// Maximum number of Rng algorithms. -#define RNG_AVAILABLE_ALGO_MAX 2 - -/** Allocate and initialize mAvailableAlgoArray with the available - Rng algorithms. Also update mAvailableAlgoArrayCount. - - @retval EFI_SUCCESS The function completed successfully. - @retval EFI_OUT_OF_RESOURCES Could not allocate memory. -**/ -EFI_STATUS -EFIAPI -GetAvailableAlgorithms ( - VOID - ) -{ - UINT64 DummyRand; - UINT16 MajorRevision; - UINT16 MinorRevision; - - // Rng algorithms 2 times, one for the allocation, one to populate. - mAvailableAlgoArray =3D AllocateZeroPool (RNG_AVAILABLE_ALGO_MAX); - if (mAvailableAlgoArray =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - // Check RngGetBytes() before advertising PcdCpuRngSupportedAlgorithm. - if (!EFI_ERROR (RngGetBytes (sizeof (DummyRand), (UINT8 *)&DummyRand))) { - CopyMem ( - &mAvailableAlgoArray[mAvailableAlgoArrayCount], - PcdGetPtr (PcdCpuRngSupportedAlgorithm), - sizeof (EFI_RNG_ALGORITHM) - ); - mAvailableAlgoArrayCount++; - - DEBUG_CODE_BEGIN (); - if (IsZeroGuid (PcdGetPtr (PcdCpuRngSupportedAlgorithm))) { - DEBUG (( - DEBUG_WARN, - "PcdCpuRngSupportedAlgorithm should be a non-zero GUID\n" - )); - } - - DEBUG_CODE_END (); - } - - // Raw algorithm (Trng) - if (!EFI_ERROR (GetTrngVersion (&MajorRevision, &MinorRevision))) { - CopyMem ( - &mAvailableAlgoArray[mAvailableAlgoArrayCount], - &gEfiRngAlgorithmRaw, - sizeof (EFI_RNG_ALGORITHM) - ); - mAvailableAlgoArrayCount++; - } - - return EFI_SUCCESS; -} - /** Free mAvailableAlgoArray. **/ VOID diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf b/Security= Pkg/RandomNumberGenerator/RngDxe/RngDxe.inf index 337becf5224f..9f1630161032 100644 --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf @@ -28,7 +28,7 @@ [Defines] # # The following information is for reference only and not required by the = build tools. # -# VALID_ARCHITECTURES =3D IA32 X64 AARCH64 +# VALID_ARCHITECTURES =3D IA32 X64 AARCH64 ARM # =20 [Sources.common] @@ -41,10 +41,16 @@ [Sources.IA32, Sources.X64] Rand/AesCore.c Rand/AesCore.h =20 -[Sources.AARCH64] +[Sources.AARCH64, Sources.ARM] ArmRngDxe.c ArmTrng.c =20 +[Sources.AARCH64] + AArch64/AArch64Algo.c + +[Sources.ARM] + Arm/ArmAlgo.c + [Packages] MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec @@ -59,7 +65,7 @@ [LibraryClasses] TimerLib RngLib =20 -[LibraryClasses.AARCH64] +[LibraryClasses.AARCH64, LibraryClasses.ARM] TrngLib =20 [Guids] diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc index a6b4952182cb..41857bd2c5bb 100644 --- a/SecurityPkg/SecurityPkg.dsc +++ b/SecurityPkg/SecurityPkg.dsc @@ -291,7 +291,7 @@ [Components.IA32, Components.X64, Components.ARM, Compo= nents.AARCH64] SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultKeysApp.inf SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDef= aultKeysDxe.inf =20 -[Components.IA32, Components.X64, Components.AARCH64] +[Components.IA32, Components.X64, Components.AARCH64, Components.ARM] # # Random Number Generator # --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95334): https://edk2.groups.io/g/devel/message/95334 Mute This Topic: https://groups.io/mt/94407764/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 8 20:41:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+95335+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95335+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=arm.com ARC-Seal: i=1; a=rsa-sha256; t=1666099864; cv=none; d=zohomail.com; s=zohoarc; b=afx1ox1m0ZNmMiw3tEIG3fbYFAEVQi9Ts/irqrRHkEPqs8HLjYQNJn+OPdrhvj43ccQMMp8a2iSGo4BGwNlNZ5CAKWAiih+RHMLr8ckNHaeIg2tbCVPGiZlbiqkfSx4xnt+TDEddRfIFViO7+EPNsjfSGQ2C4+q3M/o+Dn7T5+Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666099864; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=6ZAOd3JNGl5Se7TQhyDNV3NHDV5gZLebrx/I4GORQdQ=; b=SOai+vgwmOXdw7O27dU9JqlE/ZvmYXLmrXpoY04ddtvoNPnEM7Lxt1BVTIutREDIhe3ytnj6qEPufjLE9p+hnDnruzr9AwXdJU8hZZRFD7rc3csj0KhGqe1drSaN5LvqKyPyQXIOYnjsv+ArQfUJqtttKTa1qH5hAnvAB5dVlpQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+95335+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 166609986408149.97493971928816; Tue, 18 Oct 2022 06:31:04 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id iQ9SYY1788612xnvITr4i5Va; Tue, 18 Oct 2022 06:31:02 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.6813.1666099862162878277 for ; Tue, 18 Oct 2022 06:31:02 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 120701758; Tue, 18 Oct 2022 06:31:08 -0700 (PDT) X-Received: from pierre123.arm.com (pierre123.nice.arm.com [10.34.100.128]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 74BE23F792; Tue, 18 Oct 2022 06:31:00 -0700 (PDT) From: "PierreGondois" To: devel@edk2.groups.io Cc: Sami Mujawar , Leif Lindholm , Ard Biesheuvel , Rebecca Cran , Michael D Kinney , Liming Gao , Jiewen Yao , Jian J Wang Subject: [edk2-devel] [PATCH v8 19/19] ArmVirtPkg: Kvmtool: Add RNG support using FW-TRNG interface Date: Tue, 18 Oct 2022 15:20:52 +0200 Message-Id: <20221018132052.1359530-20-Pierre.Gondois@arm.com> In-Reply-To: <20221018132052.1359530-1-Pierre.Gondois@arm.com> References: <20221018132052.1359530-1-Pierre.Gondois@arm.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pierre.gondois@arm.com X-Gm-Message-State: cYM4ANfb137I2ZIiMoBQA8Zxx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1666099862; bh=UjI70219GD15y0/OgoIV40FOZP3PvBELG03TRXOSwe0=; h=Cc:Date:From:Reply-To:Subject:To; b=TeW4m51cIS3cizYBjDL/6kcDci9uIHlJz8tssBz29gZrTvxkVgRSFJ2qpmHk8ea2KHu QTp43WABlOCpfaQANBaiqzJN13idVvLouIv8v9YFyo8jUr8ef5/53J3HxJm8vFfZDdnnQ fV77ZRNufZN+DPoxD2V/fOa8/mD0VTMjdp0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1666099865556100017 Content-Type: text/plain; charset="utf-8" From: Sami Mujawar Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3D3668) The EFI_RNG_PROTOCOL published by RngDxe has been updated to implement the EFI_RNG_ALGORITHM_RAW using the Arm FW-TRNG interface to provide access to entropy. Therefore, enable EFI_RNG_PROTOCOL for the Kvmtool guest/virtual firmware. Signed-off-by: Pierre Gondois --- ArmVirtPkg/ArmVirtKvmTool.dsc | 10 ++++++++++ ArmVirtPkg/ArmVirtKvmTool.fdf | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/ArmVirtPkg/ArmVirtKvmTool.dsc b/ArmVirtPkg/ArmVirtKvmTool.dsc index 3bd3ebd6e0b3..847dbdd2af2b 100644 --- a/ArmVirtPkg/ArmVirtKvmTool.dsc +++ b/ArmVirtPkg/ArmVirtKvmTool.dsc @@ -81,6 +81,9 @@ [LibraryClasses.common] HwInfoParserLib|DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtHwInfoPar= serLib.inf DynamicPlatRepoLib|DynamicTablesPkg/Library/Common/DynamicPlatRepoLib/Dy= namicPlatRepoLib.inf =20 + ArmMonitorLib|ArmPkg/Library/ArmMonitorLib/ArmMonitorLib.inf + TrngLib|ArmPkg/Library/ArmFwTrngLib/ArmFwTrngLib.inf + [LibraryClasses.common.SEC, LibraryClasses.common.PEI_CORE, LibraryClasses= .common.PEIM] PciExpressLib|MdePkg/Library/BasePciExpressLib/BasePciExpressLib.inf PlatformHookLib|ArmVirtPkg/Library/Fdt16550SerialPortHookLib/EarlyFdt165= 50SerialPortHookLib.inf @@ -112,6 +115,8 @@ [PcdsFeatureFlag.common] # Use MMIO for accessing RTC controller registers. gPcAtChipsetPkgTokenSpaceGuid.PcdRtcUseMmio|TRUE =20 + gArmTokenSpaceGuid.PcdMonitorConduitHvc|TRUE + [PcdsFixedAtBuild.common] gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x8000000F =20 @@ -362,6 +367,11 @@ [Components.common] OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf OvmfPkg/Virtio10Dxe/Virtio10.inf =20 + # + # Rng Support + # + SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf + !if $(ARCH) =3D=3D AARCH64 # # ACPI Support diff --git a/ArmVirtPkg/ArmVirtKvmTool.fdf b/ArmVirtPkg/ArmVirtKvmTool.fdf index 9e006e83ee5c..4b5c99ef6700 100644 --- a/ArmVirtPkg/ArmVirtKvmTool.fdf +++ b/ArmVirtPkg/ArmVirtKvmTool.fdf @@ -224,6 +224,11 @@ [FV.FvMain] # INF MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf =20 + # + # Rng Support + # + INF SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf + [FV.FVMAIN_COMPACT] FvAlignment =3D 16 ERASE_POLARITY =3D 1 --=20 2.25.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#95335): https://edk2.groups.io/g/devel/message/95335 Mute This Topic: https://groups.io/mt/94407765/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-