public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Oliver Smith-Denny" <osde@linux.microsoft.com>
To: devel@edk2.groups.io, nishant.sharma@arm.com
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>,
	Sami Mujawar <sami.mujawar@arm.com>,
	Thomas Abraham <thomas.abraham@arm.com>,
	Sayanta Pattanayak <sayanta.pattanayak@arm.com>,
	Achin Gupta <achin.gupta@arm.com>
Subject: Re: [edk2-devel] [edk2-platforms][PATCH V1 06/20] ArmPkg: Add support for FFA_MEM_PERM_GET/SET ABIs
Date: Wed, 12 Jul 2023 10:43:34 -0700	[thread overview]
Message-ID: <c7114034-a823-9e24-8754-96edeefb4d5a@linux.microsoft.com> (raw)
In-Reply-To: <20230711143658.781597-7-nishant.sharma@arm.com>

On 7/11/2023 7:36 AM, Nishant Sharma wrote:
> From: Achin Gupta <achin.gupta@arm.com>
> 
> This patch uses the FFA_MEM_PERM_GET/SET ABIs to tweak the permissions of a
> set of pages if FF-A v1.1 and above is supported by the SPMC. For FF-A v1.0
> the previous method through FFA_MSG_SEND_DIRECT_REQ/RESP is used.
> 
> Signed-off-by: Achin Gupta <achin.gupta@arm.com>
> Signed-off-by: Nishant Sharma <nishant.sharma@arm.com>
> ---
>   ArmPkg/Include/IndustryStandard/ArmFfaSvc.h               |   2 +
>   ArmPkg/Library/StandaloneMmMmuLib/ArmMmuStandaloneMmLib.c | 132 +++++++++++++++++---
>   2 files changed, 120 insertions(+), 14 deletions(-)
> 
> diff --git a/ArmPkg/Include/IndustryStandard/ArmFfaSvc.h b/ArmPkg/Include/IndustryStandard/ArmFfaSvc.h
> index c80d783fad3f..7987678c996e 100644
> --- a/ArmPkg/Include/IndustryStandard/ArmFfaSvc.h
> +++ b/ArmPkg/Include/IndustryStandard/ArmFfaSvc.h
> @@ -23,6 +23,8 @@
>   #define ARM_SVC_ID_FFA_MSG_SEND_DIRECT_RESP_AARCH64  0xC4000070
>   #define ARM_SVC_ID_FFA_SUCCESS_AARCH32               0x84000061
>   #define ARM_SVC_ID_FFA_SUCCESS_AARCH64               0xC4000061
> +#define ARM_SVC_ID_FFA_MEM_PERM_SET_AARCH32          0x84000089
> +#define ARM_SVC_ID_FFA_MEM_PERM_GET_AARCH32          0x84000088
>   #define ARM_SVC_ID_FFA_ERROR_AARCH32                 0x84000060
>   #define ARM_SVC_ID_FFA_ERROR_AARCH64                 0xC4000060
>   #define ARM_SVC_ID_FFA_MSG_WAIT_AARCH32              0x8400006B
> diff --git a/ArmPkg/Library/StandaloneMmMmuLib/ArmMmuStandaloneMmLib.c b/ArmPkg/Library/StandaloneMmMmuLib/ArmMmuStandaloneMmLib.c
> index 1a41a289ef17..76ef214bcb85 100644
> --- a/ArmPkg/Library/StandaloneMmMmuLib/ArmMmuStandaloneMmLib.c
> +++ b/ArmPkg/Library/StandaloneMmMmuLib/ArmMmuStandaloneMmLib.c
> @@ -25,6 +25,66 @@
>   #include <Library/DebugLib.h>
>   #include <Library/PcdLib.h>
>   
> +
> +/**
> +  Utility function to determine whether ABIs in FF-A v1.1 to set and get
> +  memory permissions can be used. Ideally, this should be invoked once in the
> +  library constructor and set a flag that can be used at runtime. However, the
> +  StMM Core invokes this library before constructors are called and before the
> +  StMM image itself is relocated.
> +
> +  @retval EFI_SUCCESS     The availability of ABIs was correctly determined.
> +  @retval Other value     Software stack is misconfigured.
> +
> +**/
> +STATIC
> +BOOLEAN
> +UseFfaMemPermAbis (
> +  VOID
> +  )
> +{
> +  ARM_SVC_ARGS    SvcArgs;
> +  UINT32          SpmcFfaVersion;
> +  STATIC UINT16   SpmcMajorVer = 0;
> +  STATIC UINT16   SpmcMinorVer = 0;
> +
> +  // Use prefetched version info. if either is not 0, then the version is
> +  // already fetched.
> +  if ((SpmcMajorVer | SpmcMinorVer) != 0) {
> +    return (SpmcMajorVer == SPM_MAJOR_VERSION_FFA) && (SpmcMinorVer >= SPM_MINOR_VERSION_FFA);
> +  }
> +
> +  // Nothing to do if FF-A has not be enabled

nit: "been enabled"

> +  if (FixedPcdGet32 (PcdFfaEnable) == 0) {
> +    return FALSE;
> +  }
> +
> +  // Prepare the message parameters.
> +  ZeroMem (&SvcArgs, sizeof (ARM_SVC_ARGS));
> +  SvcArgs.Arg0 = ARM_SVC_ID_FFA_VERSION_AARCH32;
> +  SvcArgs.Arg1 = FFA_VERSION_COMPILED;
> +
> +  // Invoke the ABI
> +  ArmCallSvc (&SvcArgs);
> +
> +  // Check if FF-A is supported and what version
> +  SpmcFfaVersion = SvcArgs.Arg0;
> +
> +  // Damn! FF-A is not supported at all even though we specified v1.0 as our
> +  // version. However, the feature flag has been turned on. This is a > +  // misconfigured software stack. So, return an error and assert in 
a debug build.
> +  if (SpmcFfaVersion == ARM_FFA_SPM_RET_NOT_SUPPORTED) {
> +    ASSERT (0);

It would be nice to either have the assert be self documenting
(ASSERT (SpmcFfaVersion == ARM_FFA_SPM_RET_NOT_SUPPORTED)) or
to add a print here.

> +    return FALSE;
> +  }
> +
> +  SpmcMajorVer = (SpmcFfaVersion >> FFA_VERSION_MAJOR_SHIFT) & FFA_VERSION_MAJOR_MASK;
> +  SpmcMinorVer = (SpmcFfaVersion >> FFA_VERSION_MINOR_SHIFT) & FFA_VERSION_MINOR_MASK;
> +
> +  return (SpmcMajorVer == SPM_MAJOR_VERSION_FFA) && (SpmcMinorVer >= SPM_MINOR_VERSION_FFA);
> +}
> +
> +
>   /** Send memory permission request to target.
>   
>     @param [in, out]  SvcArgs     Pointer to SVC arguments to send. On
> @@ -55,6 +115,36 @@ SendMemoryPermissionRequest (
>   
>     ArmCallSvc (SvcArgs);
>     if (FixedPcdGet32 (PcdFfaEnable) != 0) {
> +
> +    // Check if FF-A memory permission ABIs were used.
> +    if (UseFfaMemPermAbis()) {
> +      switch (SvcArgs->Arg0) {
> +
> +        case ARM_SVC_ID_FFA_ERROR_AARCH32:
> +        case ARM_SVC_ID_FFA_ERROR_AARCH64:
> +          switch (SvcArgs->Arg2) {
> +          case ARM_FFA_SPM_RET_INVALID_PARAMETERS:
> +            return EFI_INVALID_PARAMETER;
> +          case ARM_FFA_SPM_RET_NOT_SUPPORTED:
> +            return EFI_UNSUPPORTED;
> +          default:
> +            // Undefined error code received.
> +            ASSERT (0);

For these two default cases, can we print out what
error code we received?

Thanks,
Oliver

> +            return EFI_INVALID_PARAMETER;
> +          }
> +
> +        case ARM_SVC_ID_FFA_SUCCESS_AARCH32:
> +        case ARM_SVC_ID_FFA_SUCCESS_AARCH64:
> +          *RetVal = SvcArgs->Arg2;
> +          return EFI_SUCCESS;
> +
> +        default:
> +          // Undefined error code received.
> +          ASSERT (0);
> +          return EFI_INVALID_PARAMETER;
> +      }
> +    }
> +
>       // Get/Set memory attributes is an atomic call, with
>       // StandaloneMm at S-EL0 being the caller and the SPM
>       // core being the callee. Thus there won't be a
> @@ -164,12 +254,18 @@ GetMemoryPermissions (
>     // See [1], Section 13.5.5.1 MM_SP_MEMORY_ATTRIBUTES_GET_AARCH64.
>     ZeroMem (&SvcArgs, sizeof (ARM_SVC_ARGS));
>     if (FixedPcdGet32 (PcdFfaEnable) != 0) {
> -    // See [2], Section 10.2 FFA_MSG_SEND_DIRECT_REQ.
> -    SvcArgs.Arg0 = ARM_SVC_ID_FFA_MSG_SEND_DIRECT_REQ;
> -    SvcArgs.Arg1 = ARM_FFA_DESTINATION_ENDPOINT_ID;
> -    SvcArgs.Arg2 = 0;
> -    SvcArgs.Arg3 = ARM_SVC_ID_SP_GET_MEM_ATTRIBUTES;
> -    SvcArgs.Arg4 = BaseAddress;
> +    // Check if FF-A memory permission ABIs can be used.
> +    if (UseFfaMemPermAbis()) {
> +      SvcArgs.Arg0 = ARM_SVC_ID_FFA_MEM_PERM_GET_AARCH32;
> +      SvcArgs.Arg1 = BaseAddress;
> +    } else {
> +      // See [2], Section 10.2 FFA_MSG_SEND_DIRECT_REQ.
> +      SvcArgs.Arg0 = ARM_SVC_ID_FFA_MSG_SEND_DIRECT_REQ;
> +      SvcArgs.Arg1 = ARM_FFA_DESTINATION_ENDPOINT_ID;
> +      SvcArgs.Arg2 = 0;
> +      SvcArgs.Arg3 = ARM_SVC_ID_SP_GET_MEM_ATTRIBUTES;
> +      SvcArgs.Arg4 = BaseAddress;
> +    }
>     } else {
>       SvcArgs.Arg0 = ARM_SVC_ID_SP_GET_MEM_ATTRIBUTES;
>       SvcArgs.Arg1 = BaseAddress;
> @@ -219,14 +315,22 @@ RequestMemoryPermissionChange (
>     // See [1], Section 13.5.5.2 MM_SP_MEMORY_ATTRIBUTES_SET_AARCH64.
>     ZeroMem (&SvcArgs, sizeof (ARM_SVC_ARGS));
>     if (FixedPcdGet32 (PcdFfaEnable) != 0) {
> -    // See [2], Section 10.2 FFA_MSG_SEND_DIRECT_REQ.
> -    SvcArgs.Arg0 = ARM_SVC_ID_FFA_MSG_SEND_DIRECT_REQ;
> -    SvcArgs.Arg1 = ARM_FFA_DESTINATION_ENDPOINT_ID;
> -    SvcArgs.Arg2 = 0;
> -    SvcArgs.Arg3 = ARM_SVC_ID_SP_SET_MEM_ATTRIBUTES;
> -    SvcArgs.Arg4 = BaseAddress;
> -    SvcArgs.Arg5 = EFI_SIZE_TO_PAGES (Length);
> -    SvcArgs.Arg6 = Permissions;
> +    // Check if FF-A memory permission ABIs can be used.
> +    if (UseFfaMemPermAbis()) {
> +      SvcArgs.Arg0 = ARM_SVC_ID_FFA_MEM_PERM_SET_AARCH32;
> +      SvcArgs.Arg1 = BaseAddress;
> +      SvcArgs.Arg2 = EFI_SIZE_TO_PAGES (Length);
> +      SvcArgs.Arg3 = Permissions;
> +    } else {
> +      // See [2], Section 10.2 FFA_MSG_SEND_DIRECT_REQ.
> +      SvcArgs.Arg0 = ARM_SVC_ID_FFA_MSG_SEND_DIRECT_REQ;
> +      SvcArgs.Arg1 = ARM_FFA_DESTINATION_ENDPOINT_ID;
> +      SvcArgs.Arg2 = 0;
> +      SvcArgs.Arg3 = ARM_SVC_ID_SP_SET_MEM_ATTRIBUTES;
> +      SvcArgs.Arg4 = BaseAddress;
> +      SvcArgs.Arg5 = EFI_SIZE_TO_PAGES (Length);
> +      SvcArgs.Arg6 = Permissions;
> +    }
>     } else {
>       SvcArgs.Arg0 = ARM_SVC_ID_SP_SET_MEM_ATTRIBUTES;
>       SvcArgs.Arg1 = BaseAddress;

  reply	other threads:[~2023-07-12 17:43 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-11 14:36 [edk2-platforms][PATCH V1 00/20] Add the support for ARM Firmware First Framework Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 01/20] ArmPkg: Change PcdFfaEnable flag datatype Nishant Sharma
2023-07-12 17:21   ` [edk2-devel] " Oliver Smith-Denny
2023-07-12 17:23     ` Chris Fernald
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 02/20] StandaloneMmPkg: Allocate and initialise SP stack from internal memory Nishant Sharma
2023-07-12 17:47   ` [edk2-devel] " Chris Fernald
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 03/20] StandaloneMmPkg: Include libfdt in the StMM Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 04/20] ArmPkg: Add data structures to receive FF-A boot information Nishant Sharma
2023-07-12 17:27   ` [edk2-devel] " Oliver Smith-Denny
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 05/20] ArmPkg/ArmFfaSvc: Add helper macros and fids Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 06/20] ArmPkg: Add support for FFA_MEM_PERM_GET/SET ABIs Nishant Sharma
2023-07-12 17:43   ` Oliver Smith-Denny [this message]
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 07/20] StandaloneMmPkg: define new data structure to stage FF-A boot information Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 08/20] StandaloneMmPkg: Add backwards compatible support to detect FF-A v1.1 Nishant Sharma
2023-07-12 20:31   ` [edk2-devel] " Oliver Smith-Denny
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 09/20] StandaloneMmPkg: parse SP manifest and populate new boot information Nishant Sharma
2023-07-13 15:24   ` [edk2-devel] " Girish Mahadevan
2023-07-13 16:48     ` Chris Fernald
2023-07-13 20:49       ` Achin Gupta
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 10/20] StandaloneMmPkg: Populate Hoblist for SP init from StMM " Nishant Sharma
2023-07-12 20:52   ` [edk2-devel] " Oliver Smith-Denny
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 11/20] StandaloneMmPkg: Skip zero sized sections while tweaking page permissions Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 12/20] StandaloneMmPkg: Add global check for FF-A abis Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 13/20] ArmPkg: Bump the StMM SP FF-A minor version to 1 Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 14/20] ArmPkg/MmCommunicationDxe: Introduce FF-A version check Nishant Sharma
2023-07-13 16:56   ` [edk2-devel] " Chris Fernald
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 15/20] ArmPkg/MmCommunicationDxe: Add support for obtaining FF-A partition ID Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 16/20] ArmPkg/MmCommunicationDxe: Register FF-A RX/TX buffers Nishant Sharma
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 17/20] ArmPkg/MmCommunicationDxe: Unmap FF-A RX/TX buffers during ExitBootServices Nishant Sharma
2023-07-12 20:59   ` [edk2-devel] " Oliver Smith-Denny
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 18/20] ArmPkg/MmCommunicationDxe: Discover the StMM SP Nishant Sharma
2023-07-12 21:10   ` [edk2-devel] " Oliver Smith-Denny
2023-07-12 21:48   ` Girish Mahadevan
2023-07-13 17:16   ` Chris Fernald
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 19/20] ArmPkg/MmCommunicationDxe: Use the FF-A transport for MM requests Nishant Sharma
2023-07-11 19:22   ` [edk2-devel] " Kun Qin
2023-07-12 14:21     ` achin.gupta
2023-07-12 17:13       ` Kun Qin
2023-07-12 21:49   ` Girish Mahadevan
2023-07-11 14:36 ` [edk2-platforms][PATCH V1 20/20] StandaloneMmPkg: Add support for MM requests as FF-A direct messages Nishant Sharma
2023-07-12 21:13 ` [edk2-devel] [edk2-platforms][PATCH V1 00/20] Add the support for ARM Firmware First Framework Oliver Smith-Denny

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=c7114034-a823-9e24-8754-96edeefb4d5a@linux.microsoft.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