public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ilias Apalodimas" <ilias.apalodimas@linaro.org>
To: Pierre <pierre.gondois@arm.com>
Cc: devel@edk2.groups.io, Sami Mujawar <Sami.Mujawar@arm.com>
Subject: Re: [edk2-devel] [PATCH 1/2 v5] Drivers/OpTeeRpmb: Add an OP-TEE backed RPMB driver
Date: Tue, 9 Mar 2021 01:33:44 +0200	[thread overview]
Message-ID: <CAC_iWj+QZn=1Z_JFrpa7mdVyO9rwARqrR3r3Cpx7L0egy_ZSig@mail.gmail.com> (raw)
In-Reply-To: <ade96a28-d4c9-c1f2-0ff1-77b425189015@arm.com>

On Fri, Mar 05, 2021 at 05:58:49PM +0000, Pierre wrote:
> Hi Ilias,
> Here is the rest of the review. Sorry to do it in 2 times.

No worries, I'll try to pick up all the comments.

>
> Regards,
>
> Pierre
>
>
> >
> > +/**
> >
> > +  Fixup the Pcd values for variable storage
> >
> > +
> >
> > +  Since the upper layers of EDK2 expect a memory mapped interface and
> > we can't
> >
> > +  offer that from an RPMB, the driver allocates memory on init and
> > passes that
> >
> > +  on the upper layers. Since the memory is dynamically allocated and we
> > can't set the
> >
> > +  PCD is StMM context, we need to patch it correctly on each access
> >
> > +
> >
> > +  @retval EFI_SUCCESS Protocol was found and PCDs patched up
> The error codes are missing.

Yea, but I'll remove the overflow check on v6 so that should be fine as-is.

> >
> > +
> >
> > + **/
> >
> > +EFI_STATUS
> >
> > +EFIAPI
> >
> >

[...]

> > +  ASSERT_EFI_ERROR (Status);
> >
> > +
> >
> > +  Instance = INSTANCE_FROM_FVB_THIS (FvbProtocol);
> >
> > +  // The Pcd is user defined, so make sure we don't overflow
> >
> > +  if (Instance->MemBaseAddress > MAX_UINT64 - PcdGet32
> > (PcdFlashNvStorageVariableSize)) {
> I think this can be removed since the next condition is more strict.

ditto

> >
> > +    return EFI_INVALID_PARAMETER;
> >
> > +  }
> >
> > +
> >
> >
> [...]
> > +STATIC
> >
> > +EFI_STATUS
> >
> > +ReadWriteRpmb (
> >
> > +  UINTN  SvcAct,
> >
> > +  UINTN  Addr,
> >
> > +  UINTN  NumBytes,
> >
> > +  UINTN  Offset
> >
> > +  )
> >
> > +{
> >
> > +  ARM_SVC_ARGS  SvcArgs;
> >
> > +  EFI_STATUS    Status;
> >
> > +
> >
> > +  ZeroMem (&SvcArgs, sizeof (SvcArgs));
> >
> > +
> >
> > +  SvcArgs.Arg0 = ARM_SVC_ID_FFA_MSG_SEND_DIRECT_REQ_AARCH64;
>
> If this is an FFA call, is it possible to:
>  - put a reference in the header to the spec (it should be similar to the
> one at
> edk2/ArmPkg/Library/StandaloneMmMmuLib/AArch64/ArmMmuStandaloneMmLib.c)
>  - check the return status of the SVC call against the ones available at
> edk2/ArmPkg/Include/IndustryStandard/ArmFfaSvc.h
>  - if possible, remove the dependency to <IndustryStandard/ArmMmSvc.h>
>

The call is technically an FFA one but at the moment OP-TEE returns the StMM
return code which is defined in the last header you mention.
The relevant code is in ./core/arch/arm/kernel/stmm_sp.c function
tee2stmm_ret_val().
So unless we redefine that in OP-TEE or (better imho), wait for a full FFA
mechanism to be in place, I'd prefer leaving it as is.
Keep in mind that adding the full FFA will also get rid of the hardcoded IDs
on the beginning of the file.

> >
> > +  SvcArgs.Arg1 = mStorageId;
> > +  //

[...]

> >
> > +  if (   (FwVolHeader->Revision  != EFI_FVH_REVISION)
> >
> > +      || (FwVolHeader->Signature != EFI_FVH_SIGNATURE)
> >
> > +      || (FwVolHeader->FvLength  != FvLength)
> >
> > +      )
> could be on the same line -> ') {'

ok

> >
> > +  {
> >
> >
> > +  if (VariableStoreHeader->Size != VariableStoreLength) {
> >
> > +    DEBUG ((DEBUG_INFO, "%a: Variable Store Length does not match\n",
> >
> > +      __FUNCTION__));
> >
> > +    return EFI_VOLUME_CORRUPTED;
> >
> > +  }
> >
> > +
> >
> > +  return EFI_SUCCESS;
> >
> empty line, could be removed

ok

> > +

> >
> > +    (PcdGet64 (PcdFlashNvStorageFtwWorkingBase64) +
> >
> > +    PcdGet32 (PcdFlashNvStorageFtwWorkingSize)) ==
> >
> > +    PcdGet64 (PcdFlashNvStorageFtwSpareBase64));
> >
> > +
> >
> > +  // Check if the size of the area is at least one block size
> >
> > +  ASSERT (
> >
> > +    (PcdGet32 (PcdFlashNvStorageVariableSize) > 0) &&
> I think the first check (Size > 0) is redundant with the second one (Size >
> BlockSize).

Yea it seems so. This was again a c/p from other drivers handling the
PCD, but we can start
clean here.

> >
> > +    (PcdGet32 (PcdFlashNvStorageVariableSize) / Instance->BlockSize > 0)
> >
> > +    );
> >
> > +  ASSERT (
> >
> > +    (PcdGet32 (PcdFlashNvStorageFtwWorkingSize) > 0) &&


[...]

> > +
> >
> > +  SetMem (&mInstance, sizeof (mInstance), 0);
> NIT: you can use ZeroMem()

Sure

> >
> > +
> >
> > +  mInstance.FvbProtocol.GetPhysicalAddress =
> > OpTeeRpmbFvbGetPhysicalAddress;
> >
> > +  mInstance.FvbProtocol.GetAttributes      = OpTeeRpmbFvbGetAttributes;
> >
> > +  mInstance.FvbProtocol.SetAttributes      = OpTeeRpmbFvbSetAttributes;
> >
> > +  mInstance.FvbProtocol.GetBlockSize       = OpTeeRpmbFvbGetBlockSize;
> >
> > +  mInstance.FvbProtocol.EraseBlocks        = OpTeeRpmbFvbErase;
> >
> > +  mInstance.FvbProtocol.Write              = OpTeeRpmbFvbWrite;
> >
> > +  mInstance.FvbProtocol.Read               = OpTeeRpmbFvbRead;
> >
> > +
> >
> > +  mInstance.MemBaseAddress = (EFI_PHYSICAL_ADDRESS)Addr;
> >
> > +  mInstance.Signature      = FLASH_SIGNATURE;
> >
> > +  mInstance.Initialize     = FvbInitialize;
> >
> > +  mInstance.BlockSize      = EFI_PAGE_SIZE;
> >
> > +  mInstance.NBlocks        = NBlocks;
> >
> > +
> >
> > +  // The Pcd is user defined, so make sure we don't overflow
> >
> > +  if (mInstance.MemBaseAddress > MAX_UINT64 - PcdGet32
> > (PcdFlashNvStorageVariableSize)) {
> >
> I don't think this is necessary to do any check here since the memory has
> just been allocated with the right size.

Yea it's not. I'll probably remove the same piece of code from the
FixupPcd.c as well.

> >
> > +    );
> Do we actually need to set these PCDs ? If the PCDs are persistent, we
> should not need to patch them in FixupPcd.c. FvbInitialize() is using them,
> but it is not called from OpTeeRpmbFvbInit().
> >

I think it is.  There's something 'special' about this driver. The
upper EDK2 lays expect a byte-addressable interface.
So the PCDs are definitely not persistent, they are patchable in module PCDs.
Since RPMB isn't one we are allocating memory and handing that memory
over to EDK2, while syncing the background on the hardware.
Again, it's been a while since I wrote this and memory might be
failing, but I think what's happening here is:

OpTeeRpmbFvbInit is the entry point, which calls in EDK2 code, so you
need to patch them in here, before calling anything. After that the
fixup code runs before calling into the module and fixes up the values
for us.
In any case I'll double check before posting a v6

Thanks
/Ilias

[...]

  reply	other threads:[~2021-03-08 23:34 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-12 17:34 [PATCH 0/2 v5] Add support for running StandaloneMm as OP-TEE TA Ilias Apalodimas
2021-02-12 17:34 ` [PATCH 1/2 v5] Drivers/OpTeeRpmb: Add an OP-TEE backed RPMB driver Ilias Apalodimas
2021-03-03 10:20   ` [edk2-devel] " PierreGondois
2021-03-03 20:02     ` Ilias Apalodimas
2021-03-05 16:08       ` PierreGondois
2021-03-05 17:58   ` PierreGondois
2021-03-08 23:33     ` Ilias Apalodimas [this message]
2021-02-12 17:34 ` [PATCH 2/2 v5] StMMRpmb: Add support for building StandaloneMm image for OP-TEE Ilias Apalodimas
2021-03-03 10:18   ` [edk2-devel] " PierreGondois
2021-03-03 19:24     ` Ilias Apalodimas
2021-03-05 18:07       ` PierreGondois
2021-03-08 11:16         ` Ilias Apalodimas
2021-03-03 11:32 ` [edk2-devel] [PATCH 0/2 v5] Add support for running StandaloneMm as OP-TEE TA Sami Mujawar
2021-03-08 15:57   ` Leif Lindholm

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='CAC_iWj+QZn=1Z_JFrpa7mdVyO9rwARqrR3r3Cpx7L0egy_ZSig@mail.gmail.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