public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "gaoliming" <gaoliming@byosoft.com.cn>
To: "'Rebecca Cran'" <rebecca@nuviainc.com>, <devel@edk2.groups.io>
Cc: "'Jiewen Yao'" <jiewen.yao@intel.com>,
	"'Jian J Wang'" <jian.j.wang@intel.com>,
	"'Michael D Kinney'" <michael.d.kinney@intel.com>,
	"'Zhiguang Liu'" <zhiguang.liu@intel.com>,
	"'Ard Biesheuvel'" <ardb+tianocore@kernel.org>,
	"'Sami Mujawar'" <Sami.Mujawar@arm.com>
Subject: 回复: [PATCH 1/3] MdePkg/BaseLib: Add support for ARMv8.5 RNG instructions
Date: Thu, 29 Apr 2021 09:08:36 +0800	[thread overview]
Message-ID: <003d01d73c94$2e7e6260$8b7b2720$@byosoft.com.cn> (raw)
In-Reply-To: <20210428204415.25454-2-rebecca@nuviainc.com>

Rebecca:
  Can you submit one BZ for this new feature? 

Thanks
Liming
> -----邮件原件-----
> 发件人: Rebecca Cran <rebecca@nuviainc.com>
> 发送时间: 2021年4月29日 4:44
> 收件人: devel@edk2.groups.io
> 抄送: Rebecca Cran <rebecca@nuviainc.com>; Jiewen Yao
> <jiewen.yao@intel.com>; Jian J Wang <jian.j.wang@intel.com>; Michael D
> Kinney <michael.d.kinney@intel.com>; Liming Gao
> <gaoliming@byosoft.com.cn>; Zhiguang Liu <zhiguang.liu@intel.com>; Ard
> Biesheuvel <ardb+tianocore@kernel.org>; Sami Mujawar
> <Sami.Mujawar@arm.com>
> 主题: [PATCH 1/3] MdePkg/BaseLib: Add support for ARMv8.5 RNG
> instructions
> 
> Add support for the optional ARMv8.5 RNDR and RNDRRS instructions that
> are a part of FEAT_RNG to BaseLib, and add a function to read the ISAR0
> register which indicates whether the CPU supports FEAT_RNG.
> 
> Signed-off-by: Rebecca Cran <rebecca@nuviainc.com>
> ---
>  MdePkg/Library/BaseLib/BaseLib.inf                |  4 ++
>  MdePkg/Include/Library/BaseLib.h                  | 47
> +++++++++++++++++
>  MdePkg/Library/BaseLib/BaseLibInternals.h         |  6 +++
>  MdePkg/Library/BaseLib/AArch64/ArmReadIdIsar0.S   | 29 +++++++++++
>  MdePkg/Library/BaseLib/AArch64/ArmReadIdIsar0.asm | 28 ++++++++++
>  MdePkg/Library/BaseLib/AArch64/ArmRng.S           | 51
> ++++++++++++++++++
>  MdePkg/Library/BaseLib/AArch64/ArmRng.asm         | 55
> ++++++++++++++++++++
>  7 files changed, 220 insertions(+)
> 
> diff --git a/MdePkg/Library/BaseLib/BaseLib.inf
> b/MdePkg/Library/BaseLib/BaseLib.inf
> index b76f3af380ea..7f582079d786 100644
> --- a/MdePkg/Library/BaseLib/BaseLib.inf
> +++ b/MdePkg/Library/BaseLib/BaseLib.inf
> @@ -380,6 +380,8 @@ [Sources.AARCH64]
>    AArch64/SetJumpLongJump.S         | GCC
>    AArch64/CpuBreakpoint.S           | GCC
>    AArch64/SpeculationBarrier.S      | GCC
> +  AArch64/ArmRng.S                  | GCC
> +  AArch64/ArmReadIdIsar0.S          | GCC
> 
>    AArch64/MemoryFence.asm           | MSFT
>    AArch64/SwitchStack.asm           | MSFT
> @@ -389,6 +391,8 @@ [Sources.AARCH64]
>    AArch64/SetJumpLongJump.asm       | MSFT
>    AArch64/CpuBreakpoint.asm         | MSFT
>    AArch64/SpeculationBarrier.asm    | MSFT
> +  AArch64/ArmRng.asm                | MSFT
> +  AArch64/ArmReadIdIsar0.asm        | MSFT
> 
>  [Sources.RISCV64]
>    Math64.c
> diff --git a/MdePkg/Include/Library/BaseLib.h
> b/MdePkg/Include/Library/BaseLib.h
> index 7253997a6f8c..60cf559b0849 100644
> --- a/MdePkg/Include/Library/BaseLib.h
> +++ b/MdePkg/Include/Library/BaseLib.h
> @@ -7519,4 +7519,51 @@ PatchInstructionX86 (
>    );
> 
>  #endif // defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
> +
> +#if defined (MDE_CPU_AARCH64)
> +
> +/**
> +  Reads the ID_AA64ISAR0 Register.
> +
> +  @return The contents of the ID_AA64ISAR0 Register
> +
> +**/
> +UINT64
> +EFIAPI
> +ArmReadIdIsar0 (
> +  VOID
> +  );
> +
> +/**
> +  Generates a random number using the RNDR instruction.
> +
> +  @param[out]  The generated random number
> +
> +  @retval TRUE  Success: a random number was successfully generated
> +  @retval FALSE Failure: a random number was unable to be generated
> +
> +**/
> +BOOLEAN
> +EFIAPI
> +ArmRndr (
> +  OUT UINT64 *Rand
> +  );
> +
> +/**
> +  Generates a random number using the RNDRRS instruction.
> +
> +  @param[out]  The generated random number
> +
> +  @retval TRUE  Success: a random number was successfully generated
> +  @retval FALSE Failure: a random number was unable to be generated
> +
> +**/
> +BOOLEAN
> +EFIAPI
> +ArmRndrrs (
> +  OUT UINT64 *Rand
> +  );
> +

What usage is for this API ArmRndrrs()? I don't see it is used in RngLib. 

Thanks
Liming
> +#endif // defined (MDE_CPU_AARCH64)
> +
>  #endif // !defined (__BASE_LIB__)
> diff --git a/MdePkg/Library/BaseLib/BaseLibInternals.h
> b/MdePkg/Library/BaseLib/BaseLibInternals.h
> index 6837d67d90cf..4ae79a4e7ab4 100644
> --- a/MdePkg/Library/BaseLib/BaseLibInternals.h
> +++ b/MdePkg/Library/BaseLib/BaseLibInternals.h
> @@ -862,6 +862,12 @@ InternalX86RdRand64  (
>    OUT     UINT64                    *Rand
>    );
> 
> +#elif defined (MDE_CPU_AARCH64)
> +
> +// RNDR, Random Number
> +#define RNDR      S3_3_C2_C4_0
> +#define RNDRRS    S3_3_C2_C4_1
> +
>  #else
> 
>  #endif
> diff --git a/MdePkg/Library/BaseLib/AArch64/ArmReadIdIsar0.S
> b/MdePkg/Library/BaseLib/AArch64/ArmReadIdIsar0.S
> new file mode 100644
> index 000000000000..b31e565c7955
> --- /dev/null
> +++ b/MdePkg/Library/BaseLib/AArch64/ArmReadIdIsar0.S
> @@ -0,0 +1,29 @@
>
+#--------------------------------------------------------------------------
----
> +#
> +# ArmReadIdIsar0() for AArch64
> +#
> +# Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
> +#
> +# SPDX-License-Identifier: BSD-2-Clause-Patent
> +#
>
+#--------------------------------------------------------------------------
----
> +
> +.text
> +.p2align 2
> +GCC_ASM_EXPORT(ArmReadIdIsar0)
> +
> +#/**
> +#  Reads the ID_AA64ISAR0 Register.
> +#
> +#**/
> +#UINT64
> +#EFIAPI
> +#ArmReadIdIsar0 (
> +#  VOID
> +#  );
> +#
> +ASM_PFX(ArmReadIdIsar0):
> +  mrs  x0, id_aa64isar0_el1 // Read ID_AA64ISAR0 Register
> +  ret
> +
> +
> diff --git a/MdePkg/Library/BaseLib/AArch64/ArmReadIdIsar0.asm
> b/MdePkg/Library/BaseLib/AArch64/ArmReadIdIsar0.asm
> new file mode 100644
> index 000000000000..1f1d15626cc2
> --- /dev/null
> +++ b/MdePkg/Library/BaseLib/AArch64/ArmReadIdIsar0.asm
> @@ -0,0 +1,28 @@
>
+;--------------------------------------------------------------------------
----
> +;
> +; ArmReadIdIsar0() for AArch64
> +;
> +; Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
> +;
> +; SPDX-License-Identifier: BSD-2-Clause-Patent
> +;
>
+;--------------------------------------------------------------------------
----
> +
> +  EXPORT ArmReadIdIsar0
> +  AREA BaseLib_LowLevel, CODE, READONLY
> +
> +;/**
> +;  Reads the ID_AA64ISAR0 Register.
> +;
> +;**/
> +;UINT64
> +;EFIAPI
> +;ArmReadIdIsar0 (
> +;  VOID
> +;  );
> +;
> +ArmReadIdIsar0
> +  mrs  x0, id_aa64isar0_el1 // Read ID_AA64ISAR0 Register
> +  ret
> +
> +  END
> diff --git a/MdePkg/Library/BaseLib/AArch64/ArmRng.S
> b/MdePkg/Library/BaseLib/AArch64/ArmRng.S
> new file mode 100644
> index 000000000000..fc2adb660d21
> --- /dev/null
> +++ b/MdePkg/Library/BaseLib/AArch64/ArmRng.S
> @@ -0,0 +1,51 @@
>
+#--------------------------------------------------------------------------
----
> +#
> +# ArmRndr() and ArmRndrrs() for AArch64
> +#
> +# Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
> +#
> +# SPDX-License-Identifier: BSD-2-Clause-Patent
> +#
>
+#--------------------------------------------------------------------------
----
> +
> +#include "BaseLibInternals.h"
> +
> +.text
> +.p2align 2
> +GCC_ASM_EXPORT(ArmRndr)
> +GCC_ASM_EXPORT(ArmRndrrs)
> +
> +#/**
> +#  Generates a random number using RNDR.
> +#  Returns TRUE on success; FALSE on failure.
> +#
> +#**/
> +#BOOLEAN
> +#EFIAPI
> +#ArmRndr (
> +#  OUT UINT64 *Rand
> +#  );
> +#
> +ASM_PFX(ArmRndr):
> +  mrs  x1, RNDR
> +  str  x1, [x0]
> +  cset x0, ne    // RNDR sets NZCV to 0b0100 on failure
> +  ret
> +
> +
> +#/**
> +# Generates a random number using RNDRRS
> +# Returns TRUE on success; FALSE on failure.
> +#
> +#**/
> +#BOOLEAN
> +#EFIAPI
> +#ArmRndrrs (
> +#  OUT UINT64 *Rand
> +#  );
> +#
> +ASM_PFX(ArmRndrrs):
> +  mrs  x1, RNDRRS
> +  str  x1, [x0]
> +  cset x0, ne    // RNDRRS sets NZCV to 0b0100 on failure
> +  ret
> diff --git a/MdePkg/Library/BaseLib/AArch64/ArmRng.asm
> b/MdePkg/Library/BaseLib/AArch64/ArmRng.asm
> new file mode 100644
> index 000000000000..ed8d1a81bdfe
> --- /dev/null
> +++ b/MdePkg/Library/BaseLib/AArch64/ArmRng.asm
> @@ -0,0 +1,55 @@
>
+;--------------------------------------------------------------------------
----
> +;
> +; ArmRndr() and ArmRndrrs() for AArch64
> +;
> +; Copyright (c) 2021, NUVIA Inc. All rights reserved.<BR>
> +;
> +; SPDX-License-Identifier: BSD-2-Clause-Patent
> +;
>
+;--------------------------------------------------------------------------
----
> +
> +#include "BaseLibInternals.h"
> +
> +  EXPORT ArmRndr
> +  EXPORT ArmRndrrs
> +  AREA BaseLib_LowLevel, CODE, READONLY
> +
> +
> +;/**
> +;  Generates a random number using RNDR.
> +;  Returns TRUE on success; FALSE on failure.
> +;
> +;**/
> +;BOOLEAN
> +;EFIAPI
> +;ArmRndr (
> +;  OUT UINT64 *Rand
> +;  );
> +;
> +ArmRndr
> +  mrs  x1, RNDR
> +  str  x1, [x0]
> +  cset x0, ne    // RNDR sets NZCV to 0b0100 on failure
> +  ret
> +
> +  END
> +
> +;/**
> +;  Generates a random number using RNDRRS.
> +;  Returns TRUE on success; FALSE on failure.
> +;
> +;**/
> +;BOOLEAN
> +;EFIAPI
> +;ArmRndrrs (
> +;  OUT UINT64 *Rand
> +;  );
> +;
> +ArmRndrrs
> +  mrs  x1, RNDRRS
> +  str  x1, [x0]
> +  cset x0, ne    // RNDRRS sets NZCV to 0b0100 on failure
> +  ret
> +
> +  END
> +
> --
> 2.26.2




  reply	other threads:[~2021-04-29  1:08 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-28 20:44 [PATCH 0/3] MdePkg,SecurityPkg: Update BaseRngLib and RngDxe to support ARMv8.5 FEAT_RNG Rebecca Cran
2021-04-28 20:44 ` [PATCH 1/3] MdePkg/BaseLib: Add support for ARMv8.5 RNG instructions Rebecca Cran
2021-04-29  1:08   ` gaoliming [this message]
2021-05-05 21:02     ` [edk2-devel] 回复: " Rebecca Cran
2021-05-04 21:06   ` Sami Mujawar
2021-05-04 21:42     ` Rebecca Cran
2021-04-28 20:44 ` [PATCH 2/3] MdePkg: Refactor BaseRngLib to support AARCH64 in addition to X86 Rebecca Cran
2021-04-29  1:10   ` 回复: " gaoliming
2021-04-29  3:01     ` [edk2-devel] " Rebecca Cran
2021-05-04 21:09   ` Sami Mujawar
2021-05-05 19:27     ` [edk2-devel] " Rebecca Cran
2021-05-06 21:47     ` Rebecca Cran
2021-04-28 20:44 ` [PATCH 3/3] SecurityPkg: Add support for RngDxe on AARCH64 Rebecca Cran
2021-04-29  1:13   ` 回复: " gaoliming
2021-04-29 15:50     ` [edk2-devel] " Rebecca Cran
2021-04-29 10:35   ` Ard Biesheuvel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='003d01d73c94$2e7e6260$8b7b2720$@byosoft.com.cn' \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox