public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "PierreGondois" <pierre.gondois@arm.com>
To: Leif Lindholm <quic_llindhol@quicinc.com>
Cc: devel@edk2.groups.io, Jiewen Yao <jiewen.yao@intel.com>,
	Yi Li <yi1.li@intel.com>, Xiaoyu Lu <xiaoyu1.lu@intel.com>,
	Guomin Jiang <guomin.jiang@intel.com>,
	Ard Biesheuvel <ardb+tianocore@kernel.org>,
	Sami Mujawar <sami.mujawar@arm.com>,
	Gerd Hoffmann <kraxel@redhat.com>
Subject: Re: [edk2-devel] [PATCH v4 5/6] CryptoPkg/OpensslLib: Add AArch64Cap for arch specific hooks
Date: Tue, 21 Nov 2023 09:49:00 +0100	[thread overview]
Message-ID: <999c8c28-0ee8-4a05-aff6-3c774327e172@arm.com> (raw)
In-Reply-To: <ZVun9YOzEt5m8TYo@qc-i7.hemma.eciton.net>



On 11/20/23 19:39, Leif Lindholm wrote:
> On Mon, Nov 20, 2023 at 14:48:25 +0100, Pierre Gondois wrote:
>> Add AARCH64 specific implementations of:
>> - OPENSSL_cpuid_setup(), probing hardware capabilitie
>>    (presence of FEAT_AES, etc.)
>> - OPENSSL_rdtsc(), returning non-trusted entropy by accessing
>>    system counter.
>>
>> Acked-by: Gerd Hoffmann <kraxel@redhat.com>
>> Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
>> ---
>>   .../Library/OpensslLib/OpensslLibAccel.inf    |  7 ++
>>   .../OpensslLib/OpensslLibFullAccel.inf        |  7 ++
>>   .../OpensslLib/OpensslStub/AArch64Cap.c       | 84 +++++++++++++++++++
>>   3 files changed, 98 insertions(+)
>>   create mode 100644 CryptoPkg/Library/OpensslLib/OpensslStub/AArch64Cap.c
>>
>> diff --git a/CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf b/CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf
>> index 3d1a9638b1c1..08e8be6ea9e1 100644
>> --- a/CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf
>> +++ b/CryptoPkg/Library/OpensslLib/OpensslLibAccel.inf
>> @@ -1329,6 +1329,7 @@ [Sources.X64]
>>   # Autogenerated files list ends here
>>   
>>   [Sources.AARCH64]
>> +  OpensslStub/AArch64Cap.c
>>   # Autogenerated files list starts here
>>     $(OPENSSL_PATH)/crypto/aes/aes_cbc.c
>>     $(OPENSSL_PATH)/crypto/aes/aes_cfb.c
>> @@ -1955,11 +1956,17 @@ [Packages]
>>     MdePkg/MdePkg.dec
>>     CryptoPkg/CryptoPkg.dec
>>   
>> +[Packages.AARCH64]
>> +  ArmPkg/ArmPkg.dec
>> +
>>   [LibraryClasses]
>>     BaseLib
>>     DebugLib
>>     RngLib
>>   
>> +[LibraryClasses.AARCH64]
>> +  ArmLib
>> +
>>   [BuildOptions]
>>     #
>>     # Disables the following Visual Studio compiler warnings brought by openssl source,
>> diff --git a/CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf b/CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf
>> index e7e83d419f4b..2a01ffe06bd7 100644
>> --- a/CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf
>> +++ b/CryptoPkg/Library/OpensslLib/OpensslLibFullAccel.inf
>> @@ -1432,6 +1432,7 @@ [Sources.X64]
>>   # Autogenerated files list ends here
>>   
>>   [Sources.AARCH64]
>> +  OpensslStub/AArch64Cap.c
>>   # Autogenerated files list starts here
>>     $(OPENSSL_PATH)/crypto/aes/aes_cbc.c
>>     $(OPENSSL_PATH)/crypto/aes/aes_cfb.c
>> @@ -2107,11 +2108,17 @@ [Packages]
>>     MdePkg/MdePkg.dec
>>     CryptoPkg/CryptoPkg.dec
>>   
>> +[Packages.AARCH64]
>> +  ArmPkg/ArmPkg.dec
>> +
>>   [LibraryClasses]
>>     BaseLib
>>     DebugLib
>>     RngLib
>>   
>> +[LibraryClasses.AARCH64]
>> +  ArmLib
>> +
>>   [BuildOptions]
>>     #
>>     # Disables the following Visual Studio compiler warnings brought by openssl source,
>> diff --git a/CryptoPkg/Library/OpensslLib/OpensslStub/AArch64Cap.c b/CryptoPkg/Library/OpensslLib/OpensslStub/AArch64Cap.c
>> new file mode 100644
>> index 000000000000..7468ef3ab54e
>> --- /dev/null
>> +++ b/CryptoPkg/Library/OpensslLib/OpensslStub/AArch64Cap.c
>> @@ -0,0 +1,84 @@
>> +/** @file
>> +  Arm capabilities probing.
>> +
>> +  Copyright (c) 2023, Arm Limited. All rights reserved.<BR>
>> +
>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
>> +**/
>> +
>> +#include <openssl/types.h>
>> +#include "crypto/arm_arch.h"
>> +
>> +#include <Library/ArmLib.h>
>> +
>> +/** Get bits from a value.
>> +
>> +  Shift the input value from 'shift' bits and apply 'mask'.
>> +
>> +  @param   value    The value to get the bits from.
>> +  @param   shift    Index of the bits to read.
>> +  @param   mask     Mask to apply to the value once shifted.
>> +
>> +  @return  The desired bitfield from the value.
>> +**/
>> +#define GET_BITFIELD(value, shift, mask)    \
>> +  ((value >> shift) & mask)
> 
> (This macro appears unused here now.)
> 
>> +
>> +UINT32  OPENSSL_armcap_P = 0;
>> +
>> +void
>> +OPENSSL_cpuid_setup (
>> +  void
>> +  )
>> +{
>> +  OPENSSL_armcap_P = 0;
>> +
>> +  /* Access to EL0 registers is possible from higher ELx. */
>> +  OPENSSL_armcap_P |= ARMV8_CPUID;
>> +  /* Access to Physical timer is possible. */
>> +  OPENSSL_armcap_P |= ARMV7_TICK;
>> +
>> +  /* Neon support is not guaranteed, but it is assumed to be present.
>> +     Arm ARM for Armv8, sA1.5 Advanced SIMD and floating-point support
>> +  */
>> +  OPENSSL_armcap_P |= ARMV7_NEON;
>> +
>> +  if (ArmHasAes ())
>> +  {
> 
> And I think that curly bracket is supposed to be on the previous line
> (and similarly below), but this may be intional to align with nearby
> code?

I think it was changed by uncrustify. I changed it back.
Thanks for the review,

Regards,
Pierre

> 
> Anyway, this is a big readability improvement, thank you very much!
> Acked-by: Leif Lindholm <quic_llindhol@quicinc.com>
> 
> /
>      Leif
> 
>> +    OPENSSL_armcap_P |= ARMV8_AES;
>> +  }
>> +
>> +  if (ArmHasSha1 ())
>> +  {
>> +    OPENSSL_armcap_P |= ARMV8_SHA1;
>> +  }
>> +
>> +  if (ArmHasSha256 ())
>> +  {
>> +    OPENSSL_armcap_P |= ARMV8_SHA256;
>> +  }
>> +
>> +  if (ArmHasPmull ())
>> +  {
>> +    OPENSSL_armcap_P |= ARMV8_PMULL;
>> +  }
>> +
>> +  if (ArmHasSha512 ())
>> +  {
>> +    OPENSSL_armcap_P |= ARMV8_SHA512;
>> +  }
>> +}
>> +
>> +/** Read system counter value.
>> +
>> +  Used to get some non-trusted entropy.
>> +
>> +  @return Lower bits of the physical counter.
>> +**/
>> +uint32_t
>> +OPENSSL_rdtsc (
>> +  void
>> +  )
>> +{
>> +  return (UINT32)ArmReadCntPct ();
>> +}
>> -- 
>> 2.25.1
>>


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#111540): https://edk2.groups.io/g/devel/message/111540
Mute This Topic: https://groups.io/mt/102707267/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



  reply	other threads:[~2023-11-21  8:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-20 13:48 [edk2-devel] [PATCH v4 0/6] CryptoPkg: Enable Openssl native instruction support for AARCH64 PierreGondois
2023-11-20 13:48 ` [edk2-devel] [PATCH v4 1/6] ArmPkg/ArmLib: Add macros/helper functions around AA64Isar0 register PierreGondois
2023-11-20 18:27   ` Leif Lindholm
2023-11-20 13:48 ` [edk2-devel] [PATCH v4 2/6] CryptoPkg/CryptoPkg.ci.yaml: Allow dependency upon ArmPkg PierreGondois
2023-11-20 13:48 ` [edk2-devel] [PATCH v4 3/6] CryptoPkg/OpensslLib: Add native instruction support for AARCH64 PierreGondois
2023-11-20 13:48 ` [edk2-devel] [PATCH v4 4/6] CryptoPkg/OpensslLib: Generate files for AARCH64 native support PierreGondois
2023-11-20 13:48 ` [edk2-devel] [PATCH v4 5/6] CryptoPkg/OpensslLib: Add AArch64Cap for arch specific hooks PierreGondois
2023-11-20 18:39   ` Leif Lindholm
2023-11-21  8:49     ` PierreGondois [this message]
2023-11-20 13:48 ` [edk2-devel] [PATCH v4 6/6] CryptoPkg: Enable Openssl Accel builds for AARCH64 PierreGondois

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=999c8c28-0ee8-4a05-aff6-3c774327e172@arm.com \
    --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