From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) by mx.groups.io with SMTP id smtpd.web10.1621.1619665317751157736 for ; Wed, 28 Apr 2021 20:01:58 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20150623.gappssmtp.com header.s=20150623 header.b=nZ+9ydTt; spf=pass (domain: nuviainc.com, ip: 209.85.208.172, mailfrom: rebecca@nuviainc.com) Received: by mail-lj1-f172.google.com with SMTP id o16so74657875ljp.3 for ; Wed, 28 Apr 2021 20:01:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=cBiqtDMyxh/VD5fm9C9SnfR5fiHR2I+E+W5D3SOZ2Mk=; b=nZ+9ydTtFCE6WT7esj/nsmBbBcKTw+YvBXWo8bkP+tNWX3lejL2QJWu5jNETAFMrR1 tVB6CGtpAfWX4FEKbeJUbHh1Pz/Y7d+IlR8nRycx+nwsUtmAekVi8Y2wjn44foyP8D1e VIrsraBKtjVzDRKxkKQBytnhlXemF/mK52j1dyGyOqn2i8ARfdkDtksHYezn+M+R6+p6 mAzvOcBRicn484Ev0pAMVe8T+txRvJJxgHPFQ0D/iXFwJd1JE7iOsITkBocOC4jQuT9z eA6SnGAWCgCtfabJE7VyDe8oGgEXX0BGDOa1aEYdk+iuvY86FDq45lPw93xsoLQQRILw pXiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=cBiqtDMyxh/VD5fm9C9SnfR5fiHR2I+E+W5D3SOZ2Mk=; b=GiO+8bBWt9h2Zjtwgs32e6OQVmhbMeLfCO8AScFpGgjcqWt50zxXndxKQK3t72HLJX q758DUfE+exlJnwtYICNeRexovtte3CAaxQeUp0oCDWAiWJ0v1UM96H6IvVLS8jth2y+ xSLvkSf18m0Bv89rZAvBU2ui2UJVqC/7EJXD2hs/9Huv7SJ4m+xZjSyGz8v6FGq7cj/i 5kKoAPJhNzmq22Y3BU+c0/xB/SPeLTao+FfGMce/2Qgy6AXUZXhh1RPF7SqXdqDb01Zj UMhfhbu77dtmt7CrAjzH/2sGDZDMuKwxBl7OGlL+YLPxV9OI5oMb2215YS8zBDbJtJdR Q4ZA== X-Gm-Message-State: AOAM532K4C/8wmqH35pMVL4gBomLUWc3lkcav/kpgKScvDgR6SLVk8HY iMj5zxPPxRZqjUoYk3MAkXdFUw== X-Google-Smtp-Source: ABdhPJw2nHWvipKRrYe/Dn+49FxolXm54j6TbK3cqsdab3t+n75ZZc4UXqyFk9dKEMxq+PGuAsXDMw== X-Received: by 2002:a05:651c:1190:: with SMTP id w16mr19053943ljo.386.1619665315918; Wed, 28 Apr 2021 20:01:55 -0700 (PDT) Return-Path: Received: from [10.0.10.142] (c-174-52-16-57.hsd1.ut.comcast.net. [174.52.16.57]) by smtp.gmail.com with ESMTPSA id c4sm367275ljd.115.2021.04.28.20.01.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Apr 2021 20:01:55 -0700 (PDT) Subject: =?UTF-8?B?UmU6IFtlZGsyLWRldmVsXSDlm57lpI06IFtQQVRDSCAyLzNdIE1kZVBrZzogUmVmYWN0b3IgQmFzZVJuZ0xpYiB0byBzdXBwb3J0IEFBUkNINjQgaW4gYWRkaXRpb24gdG8gWDg2?= To: devel@edk2.groups.io, gaoliming@byosoft.com.cn Cc: 'Jiewen Yao' , 'Jian J Wang' , 'Michael D Kinney' , 'Zhiguang Liu' , 'Ard Biesheuvel' , 'Sami Mujawar' References: <20210428204415.25454-1-rebecca@nuviainc.com> <20210428204415.25454-3-rebecca@nuviainc.com> <003e01d73c94$60ffeb50$22ffc1f0$@byosoft.com.cn> From: "Rebecca Cran" Message-ID: <90416570-8902-3a6b-add3-175e15a2544e@nuviainc.com> Date: Wed, 28 Apr 2021 21:01:51 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <003e01d73c94$60ffeb50$22ffc1f0$@byosoft.com.cn> Content-Type: text/plain; charset=gbk; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit On 4/28/21 7:10 PM, gaoliming wrote: > Rebecca: > >> -----邮件原件----- >> 发件人: Rebecca Cran >> 发送时间: 2021年4月29日 4:44 >> 收件人: devel@edk2.groups.io >> 抄送: Rebecca Cran ; Jiewen Yao >> ; Jian J Wang ; Michael D >> Kinney ; Liming Gao >> ; Zhiguang Liu ; Ard >> Biesheuvel ; Sami Mujawar >> >> 主题: [PATCH 2/3] MdePkg: Refactor BaseRngLib to support AARCH64 in >> addition to X86 >> >> Make BaseRngLib more generic by moving x86 specific functionality from >> BaseRng.c into Rand/RdRand.c, and adding AArch64/Rndr.c, which supports >> the optional ARMv8.5 RNG instructions RNDR and RNDRRS that are a part of >> FEAT_RNG. >> >> Signed-off-by: Rebecca Cran >> --- >> MdePkg/MdePkg.dec | 9 +- >> MdePkg/MdePkg.dsc | 4 +- >> MdePkg/Library/BaseRngLib/BaseRngLib.inf | 16 ++- >> MdePkg/Library/BaseRngLib/BaseRngLibInternals.h | 31 +++++ >> MdePkg/Library/BaseRngLib/AArch64/Rndr.c | 121 >> ++++++++++++++++++++ >> MdePkg/Library/BaseRngLib/BaseRng.c | 55 +++------ >> MdePkg/Library/BaseRngLib/Rand/RdRand.c | 103 >> +++++++++++++++++ >> MdePkg/Library/BaseRngLib/BaseRngLib.uni | 6 +- >> 8 files changed, 291 insertions(+), 54 deletions(-) >> >> diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec >> index 8965e903e093..b49f88d8e18f 100644 >> --- a/MdePkg/MdePkg.dec >> +++ b/MdePkg/MdePkg.dec >> @@ -267,6 +267,11 @@ [LibraryClasses] >> # >> RegisterFilterLib|Include/Library/RegisterFilterLib.h >> >> +[LibraryClasses.IA32, LibraryClasses.X64, LibraryClasses.AARCH64] >> + ## @libraryclass Provides services to generate random number. >> + # >> + RngLib|Include/Library/RngLib.h >> + >> [LibraryClasses.IA32, LibraryClasses.X64] >> ## @libraryclass Abstracts both S/W SMI generation and detection. >> ## >> @@ -288,10 +293,6 @@ [LibraryClasses.IA32, LibraryClasses.X64] >> # >> SmmPeriodicSmiLib|Include/Library/SmmPeriodicSmiLib.h >> >> - ## @libraryclass Provides services to generate random number. >> - # >> - RngLib|Include/Library/RngLib.h >> - >> ## @libraryclass Provides services to log the SMI handler > registration. >> SmiHandlerProfileLib|Include/Library/SmiHandlerProfileLib.h >> >> diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc >> index d363419006ea..a94959169b2f 100644 >> --- a/MdePkg/MdePkg.dsc >> +++ b/MdePkg/MdePkg.dsc >> @@ -145,6 +145,9 @@ [Components.IA32, Components.X64, >> Components.ARM, Components.AARCH64] >> >> MdePkg/Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLibSmm.inf >> >> MdePkg/Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLibUefiShell.in >> f >> >> +[Components.IA32, Components.X64, Components.AARCH64] >> + MdePkg/Library/BaseRngLib/BaseRngLib.inf >> + >> [Components.IA32, Components.X64] >> MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf >> MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsicSev.inf >> @@ -168,7 +171,6 @@ [Components.IA32, Components.X64] >> MdePkg/Library/BaseS3StallLib/BaseS3StallLib.inf >> MdePkg/Library/SmmMemLib/SmmMemLib.inf >> MdePkg/Library/SmmIoLib/SmmIoLib.inf >> - MdePkg/Library/BaseRngLib/BaseRngLib.inf >> MdePkg/Library/SmmPciExpressLib/SmmPciExpressLib.inf >> MdePkg/Library/SmiHandlerProfileLibNull/SmiHandlerProfileLibNull.inf >> MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf >> diff --git a/MdePkg/Library/BaseRngLib/BaseRngLib.inf >> b/MdePkg/Library/BaseRngLib/BaseRngLib.inf >> index 31740751c69c..1dc3249a8c20 100644 >> --- a/MdePkg/Library/BaseRngLib/BaseRngLib.inf >> +++ b/MdePkg/Library/BaseRngLib/BaseRngLib.inf >> @@ -1,9 +1,10 @@ >> ## @file >> # Instance of RNG (Random Number Generator) Library. >> # >> -# BaseRng Library that uses CPU RdRand instruction access to provide >> -# high-quality random numbers. >> +# BaseRng Library that uses CPU RNG instructions (e.g. RdRand) to >> +# provide high-quality random numbers. >> # >> +# Copyright (c) 2020, NUVIA Inc. All rights reserved.
>> # Copyright (c) 2015, Intel Corporation. All rights reserved.
>> # >> # SPDX-License-Identifier: BSD-2-Clause-Patent >> @@ -22,11 +23,18 @@ [Defines] >> CONSTRUCTOR = BaseRngLibConstructor >> >> # >> -# VALID_ARCHITECTURES = IA32 X64 >> +# VALID_ARCHITECTURES = IA32 X64 AARCH64 >> # >> >> -[Sources.Ia32, Sources.X64] >> +[Sources] >> BaseRng.c >> + BaseRngLibInternals.h >> + >> +[Sources.Ia32, Sources.X64] >> + Rand/RdRand.c >> + >> +[Sources.AARCH64] >> + AArch64/Rndr.c >> >> [Packages] >> MdePkg/MdePkg.dec >> diff --git a/MdePkg/Library/BaseRngLib/BaseRngLibInternals.h >> b/MdePkg/Library/BaseRngLib/BaseRngLibInternals.h >> new file mode 100644 >> index 000000000000..44fda69c9eec >> --- /dev/null >> +++ b/MdePkg/Library/BaseRngLib/BaseRngLibInternals.h >> @@ -0,0 +1,31 @@ >> +/** @file >> + >> + Architecture specific interface to RNG functionality. >> + >> +Copyright (c) 2020, NUVIA Inc. All rights reserved.
>> + >> +SPDX-License-Identifier: BSD-2-Clause-Patent >> + >> +**/ >> + >> +#ifndef BASE_RNGLIB_INTERNALS_H_ >> + >> +BOOLEAN >> +EFIAPI >> +ArchGetRandomNumber16 ( >> + OUT UINT16 *Rand >> + ); >> + >> +BOOLEAN >> +EFIAPI >> +ArchGetRandomNumber32 ( >> + OUT UINT32 *Rand >> + ); >> + >> +BOOLEAN >> +EFIAPI >> +ArchGetRandomNumber64 ( >> + OUT UINT64 *Rand >> + ); >> + >> +#endif // BASE_RNGLIB_INTERNALS_H_ >> diff --git a/MdePkg/Library/BaseRngLib/AArch64/Rndr.c >> b/MdePkg/Library/BaseRngLib/AArch64/Rndr.c >> new file mode 100644 >> index 000000000000..19643237923a >> --- /dev/null >> +++ b/MdePkg/Library/BaseRngLib/AArch64/Rndr.c >> @@ -0,0 +1,121 @@ >> +/** @file >> + Random number generator service that uses the RNDR instruction >> + to provide high-quality random numbers. >> + >> + Copyright (c) 2020, NUVIA Inc. All rights reserved.
>> + Copyright (c) 2015, Intel Corporation. All rights reserved.
>> + >> + SPDX-License-Identifier: BSD-2-Clause-Patent >> + >> +**/ >> + >> +#include >> +#include >> + >> +#include >> + >> +#include "BaseRngLibInternals.h" >> + >> +// >> +// Bit mask used to determine if RNDR instruction is supported. >> +// >> +#define RNDR_MASK ((UINT64)MAX_UINT16 << 60U) >> + >> +/** >> + The constructor function checks whether or not RNDR instruction is >> supported >> + by the host hardware. >> + >> + The constructor function checks whether or not RNDR instruction is >> supported. >> + It will ASSERT() if RNDR instruction is not supported. >> + It will always return RETURN_SUCCESS. >> + >> + @retval RETURN_SUCCESS The constructor always returns >> EFI_SUCCESS. >> + >> +**/ >> +RETURN_STATUS >> +EFIAPI >> +BaseRngLibConstructor ( >> + VOID >> + ) >> +{ >> + UINT64 Isar0; >> + // >> + // Determine RNDR support by examining bits 63:60 of the ISAR0 register >> returned by >> + // MSR. A non-zero value indicates that the processor supports the RNDR >> instruction. >> + // >> + Isar0 = ArmReadIdIsar0 (); >> + ASSERT ((Isar0 & RNDR_MASK) != 0); >> + (void)Isar0; >> + > > What behavior for this statement "(void)Isar0;"? It causes Isar0 to be 'used' in builds where ASSERT is compiled out, avoiding a warning/error. -- Rebecca Cran