public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Achin Gupta <achin.gupta@arm.com>
To: "Yao, Jiewen" <jiewen.yao@intel.com>
Cc: Supreeth Venkatesh <supreeth.venkatesh@arm.com>,
	"ard.biesheuvel@linaro.org" <ard.biesheuvel@linaro.org>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>,
	"leif.lindholm@linaro.org" <leif.lindholm@linaro.org>,
	"Gao, Liming" <liming.gao@intel.com>,
	"Kinney, Michael D" <michael.d.kinney@intel.com>,
	"nd@arm.com" <nd@arm.com>
Subject: Re: [PATCH v1 08/18] StandaloneMmPkg/MemLib: AARCH64 Specific instance of memory check library.
Date: Wed, 25 Apr 2018 11:35:36 +0100	[thread overview]
Message-ID: <20180425103535.GL663@e104320-lin> (raw)
In-Reply-To: <74D8A39837DF1E4DA445A8C0B3885C503AB659B5@SHSMSX104.ccr.corp.intel.com>

Hi Jiewen,

On Mon, Apr 16, 2018 at 10:30:55PM +0000, Yao, Jiewen wrote:
> Hi
> I don't think this lib is generic, because it hardcode the physical address bits.
> 
> PhysicalAddressBits = 36;
> 
> For X86 CPU, we get it from CPUID. :-)
> 
> As enhancement, we may put most common C-code logic (such as CopyMem, or memmap calculation) to StandaloneMmPkg/MemLib, and only include the PhysicalAddresBit calculation under StandaloneMmPkg/MemLib/Arm folder.
> 
> As such, we know clearly on which one is ARM specific.

My point was that the hardocoded PA bits were not introduced to make this code
work on Arm. This has been present in the StandaloneMmPkg from the outset. I
guess for x86 you have moved on to getting this information from the
CPUID. Afaics, this function is not be used on Arm platforms but Supreeth will
double check. If that is the case then only the generic library will be required
minus this function.

cheers,
Achin

> 
> Thank you
> Yao Jiewen
> 
> > -----Original Message-----
> > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Achin
> > Gupta
> > Sent: Monday, April 16, 2018 11:13 PM
> > To: Supreeth Venkatesh <supreeth.venkatesh@arm.com>
> > Cc: ard.biesheuvel@linaro.org; edk2-devel@lists.01.org;
> > leif.lindholm@linaro.org; Yao, Jiewen <jiewen.yao@intel.com>; Gao, Liming
> > <liming.gao@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>;
> > nd@arm.com
> > Subject: Re: [edk2] [PATCH v1 08/18] StandaloneMmPkg/MemLib: AARCH64
> > Specific instance of memory check library.
> > 
> > Hi Supreeth,
> > 
> > On Fri, Apr 06, 2018 at 03:42:13PM +0100, Supreeth Venkatesh wrote:
> > > MM memory check library library implementation. This library consumes
> > > MM_ACCESS_PROTOCOL to get MMRAM information. In order to use this
> > > library instance, the platform should produce all MMRAM range via
> > > MM_ACCESS_PROTOCOL, including the range for firmware (like MM Core
> > > and MM driver) and/or specific dedicated hardware.
> > >
> > > This patch provides services for MM Memory Operation.
> > > The management mode Mem Library provides function for checking if buffer
> > > is outside MMRAM and valid. It also provides functions for copy data
> > > from MMRAM to non-MMRAM, from non-MMRAM to MMRAM,
> > > from non-MMRAM to non-MMRAM, or set data in non-MMRAM.
> > >
> > > Contributed-under: TianoCore Contribution Agreement 1.1
> > > Signed-off-by: Achin Gupta <achin.gupta@arm.com>
> > > Signed-off-by: Supreeth Venkatesh <supreeth.venkatesh@arm.com>
> > > ---
> > >  StandaloneMmPkg/Include/Library/MemLib.h    | 140 ++++++++++++++
> > >  StandaloneMmPkg/Library/MemLib/Arm/MemLib.c | 276
> > ++++++++++++++++++++++++++++
> > 
> > Why is this Library Arm specific. Apart from cosmetics tweaks, it has not
> > changed since it was originally contributed?
> > 
> > cheers,
> > Achin
> > 
> > >  StandaloneMmPkg/Library/MemLib/MemLib.inf   |  47 +++++
> > >  3 files changed, 463 insertions(+)
> > >  create mode 100644 StandaloneMmPkg/Include/Library/MemLib.h
> > >  create mode 100644 StandaloneMmPkg/Library/MemLib/Arm/MemLib.c
> > >  create mode 100644 StandaloneMmPkg/Library/MemLib/MemLib.inf
> > >
> > > diff --git a/StandaloneMmPkg/Include/Library/MemLib.h
> > b/StandaloneMmPkg/Include/Library/MemLib.h
> > > new file mode 100644
> > > index 0000000000..3264f10010
> > > --- /dev/null
> > > +++ b/StandaloneMmPkg/Include/Library/MemLib.h
> > > @@ -0,0 +1,140 @@
> > > +/** @file
> > > +  Provides services for MM Memory Operation.
> > > +
> > > +  The MM Mem Library provides function for checking if buffer is outside
> > MMRAM and valid.
> > > +  It also provides functions for copy data from MMRAM to non-MMRAM,
> > from non-MMRAM to MMRAM,
> > > +  from non-MMRAM to non-MMRAM, or set data in non-MMRAM.
> > > +
> > > +  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
> > > +  Copyright (c) 2016 - 2017, ARM Limited. All rights reserved.<BR>
> > > +
> > > +  This program and the accompanying materials
> > > +  are licensed and made available under the terms and conditions of the BSD
> > License
> > > +  which accompanies this distribution.  The full text of the license may be
> > found at
> > > +  http://opensource.org/licenses/bsd-license.php
> > > +
> > > +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
> > BASIS,
> > > +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
> > EXPRESS OR IMPLIED.
> > > +
> > > +**/
> > > +
> > > +#ifndef _MM_MEM_LIB_H_
> > > +#define _MM_MEM_LIB_H_
> > > +
> > > +/**
> > > +  This function check if the buffer is valid per processor architecture and not
> > overlap with MMRAM.
> > > +
> > > +  @param Buffer  The buffer start address to be checked.
> > > +  @param Length  The buffer length to be checked.
> > > +
> > > +  @retval TRUE  This buffer is valid per processor architecture and not
> > overlap with MMRAM.
> > > +  @retval FALSE This buffer is not valid per processor architecture or overlap
> > with MMRAM.
> > > +**/
> > > +BOOLEAN
> > > +EFIAPI
> > > +MmIsBufferOutsideMmValid (
> > > +  IN EFI_PHYSICAL_ADDRESS  Buffer,
> > > +  IN UINT64                Length
> > > +  );
> > > +
> > > +/**
> > > +  Copies a source buffer (non-MMRAM) to a destination buffer (MMRAM).
> > > +
> > > +  This function copies a source buffer (non-MMRAM) to a destination buffer
> > (MMRAM).
> > > +  It checks if source buffer is valid per processor architecture and not overlap
> > with MMRAM.
> > > +  If the check passes, it copies memory and returns EFI_SUCCESS.
> > > +  If the check fails, it return EFI_SECURITY_VIOLATION.
> > > +  The implementation must be reentrant.
> > > +
> > > +  @param  DestinationBuffer   The pointer to the destination buffer of the
> > memory copy.
> > > +  @param  SourceBuffer        The pointer to the source buffer of the
> > memory copy.
> > > +  @param  Length              The number of bytes to copy from
> > SourceBuffer to DestinationBuffer.
> > > +
> > > +  @retval EFI_SECURITY_VIOLATION The SourceBuffer is invalid per
> > processor architecture or overlap with MMRAM.
> > > +  @retval EFI_SUCCESS            Memory is copied.
> > > +
> > > +**/
> > > +EFI_STATUS
> > > +EFIAPI
> > > +MmCopyMemToSmram (
> > > +  OUT VOID       *DestinationBuffer,
> > > +  IN CONST VOID  *SourceBuffer,
> > > +  IN UINTN       Length
> > > +  );
> > > +
> > > +/**
> > > +  Copies a source buffer (MMRAM) to a destination buffer (NON-MMRAM).
> > > +
> > > +  This function copies a source buffer (non-MMRAM) to a destination buffer
> > (MMRAM).
> > > +  It checks if destination buffer is valid per processor architecture and not
> > overlap with MMRAM.
> > > +  If the check passes, it copies memory and returns EFI_SUCCESS.
> > > +  If the check fails, it returns EFI_SECURITY_VIOLATION.
> > > +  The implementation must be reentrant.
> > > +
> > > +  @param  DestinationBuffer   The pointer to the destination buffer of the
> > memory copy.
> > > +  @param  SourceBuffer        The pointer to the source buffer of the
> > memory copy.
> > > +  @param  Length              The number of bytes to copy from
> > SourceBuffer to DestinationBuffer.
> > > +
> > > +  @retval EFI_SECURITY_VIOLATION The DesinationBuffer is invalid per
> > processor architecture or overlap with MMRAM.
> > > +  @retval EFI_SUCCESS            Memory is copied.
> > > +
> > > +**/
> > > +EFI_STATUS
> > > +EFIAPI
> > > +MmCopyMemFromSmram (
> > > +  OUT VOID       *DestinationBuffer,
> > > +  IN CONST VOID  *SourceBuffer,
> > > +  IN UINTN       Length
> > > +  );
> > > +
> > > +/**
> > > +  Copies a source buffer (NON-MMRAM) to a destination buffer
> > (NON-MMRAM).
> > > +
> > > +  This function copies a source buffer (non-MMRAM) to a destination buffer
> > (MMRAM).
> > > +  It checks if source buffer and destination buffer are valid per processor
> > architecture and not overlap with MMRAM.
> > > +  If the check passes, it copies memory and returns EFI_SUCCESS.
> > > +  If the check fails, it returns EFI_SECURITY_VIOLATION.
> > > +  The implementation must be reentrant, and it must handle the case where
> > source buffer overlaps destination buffer.
> > > +
> > > +  @param  DestinationBuffer   The pointer to the destination buffer of the
> > memory copy.
> > > +  @param  SourceBuffer        The pointer to the source buffer of the
> > memory copy.
> > > +  @param  Length              The number of bytes to copy from
> > SourceBuffer to DestinationBuffer.
> > > +
> > > +  @retval EFI_SECURITY_VIOLATION The DesinationBuffer is invalid per
> > processor architecture or overlap with MMRAM.
> > > +  @retval EFI_SECURITY_VIOLATION The SourceBuffer is invalid per
> > processor architecture or overlap with MMRAM.
> > > +  @retval EFI_SUCCESS            Memory is copied.
> > > +
> > > +**/
> > > +EFI_STATUS
> > > +EFIAPI
> > > +MmCopyMem (
> > > +  OUT VOID       *DestinationBuffer,
> > > +  IN CONST VOID  *SourceBuffer,
> > > +  IN UINTN       Length
> > > +  );
> > > +
> > > +/**
> > > +  Fills a target buffer (NON-MMRAM) with a byte value.
> > > +
> > > +  This function fills a target buffer (non-MMRAM) with a byte value.
> > > +  It checks if target buffer is valid per processor architecture and not overlap
> > with MMRAM.
> > > +  If the check passes, it fills memory and returns EFI_SUCCESS.
> > > +  If the check fails, it returns EFI_SECURITY_VIOLATION.
> > > +
> > > +  @param  Buffer    The memory to set.
> > > +  @param  Length    The number of bytes to set.
> > > +  @param  Value     The value with which to fill Length bytes of Buffer.
> > > +
> > > +  @retval EFI_SECURITY_VIOLATION The Buffer is invalid per processor
> > architecture or overlap with MMRAM.
> > > +  @retval EFI_SUCCESS            Memory is set.
> > > +
> > > +**/
> > > +EFI_STATUS
> > > +EFIAPI
> > > +MmSetMem (
> > > +  OUT VOID  *Buffer,
> > > +  IN UINTN  Length,
> > > +  IN UINT8  Value
> > > +  );
> > > +
> > > +#endif
> > > diff --git a/StandaloneMmPkg/Library/MemLib/Arm/MemLib.c
> > b/StandaloneMmPkg/Library/MemLib/Arm/MemLib.c
> > > new file mode 100644
> > > index 0000000000..432a45698b
> > > --- /dev/null
> > > +++ b/StandaloneMmPkg/Library/MemLib/Arm/MemLib.c
> > > @@ -0,0 +1,276 @@
> > > +/** @file
> > > +  Instance of MM memory check library.
> > > +
> > > +  MM memory check library library implementation. This library consumes
> > MM_ACCESS_PROTOCOL
> > > +  to get MMRAM information. In order to use this library instance, the
> > platform should produce
> > > +  all MMRAM range via MM_ACCESS_PROTOCOL, including the range for
> > firmware (like MM Core
> > > +  and MM driver) and/or specific dedicated hardware.
> > > +
> > > +  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
> > > +  Copyright (c) 2016 - 2017, ARM Limited. All rights reserved.<BR>
> > > +
> > > +  This program and the accompanying materials
> > > +  are licensed and made available under the terms and conditions of the BSD
> > License
> > > +  which accompanies this distribution.  The full text of the license may be
> > found at
> > > +  http://opensource.org/licenses/bsd-license.php
> > > +
> > > +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
> > BASIS,
> > > +  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
> > EXPRESS OR IMPLIED.
> > > +
> > > +**/
> > > +
> > > +
> > > +#include <PiMm.h>
> > > +
> > > +#include <Library/BaseLib.h>
> > > +#include <Library/BaseMemoryLib.h>
> > > +#include <Library/DebugLib.h>
> > > +
> > > +EFI_MMRAM_DESCRIPTOR *mMmMemLibInternalMmramRanges;
> > > +UINTN                mMmMemLibInternalMmramCount;
> > > +
> > > +//
> > > +// Maximum support address used to check input buffer
> > > +//
> > > +EFI_PHYSICAL_ADDRESS  mMmMemLibInternalMaximumSupportAddress =
> > 0;
> > > +
> > > +/**
> > > +  Calculate and save the maximum support address.
> > > +
> > > +**/
> > > +VOID
> > > +MmMemLibInternalCalculateMaximumSupportAddress (
> > > +  VOID
> > > +  )
> > > +{
> > > +  UINT8        PhysicalAddressBits;
> > > +
> > > +  PhysicalAddressBits = 36;
> > > +
> > > +  //
> > > +  // Save the maximum support address in one global variable
> > > +  //
> > > +  mMmMemLibInternalMaximumSupportAddress =
> > (EFI_PHYSICAL_ADDRESS)(UINTN)(LShiftU64 (1, PhysicalAddressBits) - 1);
> > > +  DEBUG ((DEBUG_INFO, "mMmMemLibInternalMaximumSupportAddress =
> > 0x%lx\n", mMmMemLibInternalMaximumSupportAddress));
> > > +}
> > > +
> > > +/**
> > > +  This function check if the buffer is valid per processor architecture and not
> > overlap with MMRAM.
> > > +
> > > +  @param Buffer  The buffer start address to be checked.
> > > +  @param Length  The buffer length to be checked.
> > > +
> > > +  @retval TRUE  This buffer is valid per processor architecture and not
> > overlap with MMRAM.
> > > +  @retval FALSE This buffer is not valid per processor architecture or overlap
> > with MMRAM.
> > > +**/
> > > +BOOLEAN
> > > +EFIAPI
> > > +MmIsBufferOutsideMmValid (
> > > +  IN EFI_PHYSICAL_ADDRESS  Buffer,
> > > +  IN UINT64                Length
> > > +  )
> > > +{
> > > +  UINTN  Index;
> > > +
> > > +  //
> > > +  // Check override.
> > > +  // NOTE: (B:0->L:4G) is invalid for IA32, but (B:1->L:4G-1)/(B:4G-1->L:1) is
> > valid.
> > > +  //
> > > +  if ((Length > mMmMemLibInternalMaximumSupportAddress) ||
> > > +      (Buffer > mMmMemLibInternalMaximumSupportAddress) ||
> > > +      ((Length != 0) && (Buffer >
> > (mMmMemLibInternalMaximumSupportAddress - (Length - 1)))) ) {
> > > +    //
> > > +    // Overflow happen
> > > +    //
> > > +    DEBUG ((
> > > +      DEBUG_ERROR,
> > > +      "MmIsBufferOutsideMmValid: Overflow: Buffer (0x%lx) - Length
> > (0x%lx), MaximumSupportAddress (0x%lx)\n",
> > > +      Buffer,
> > > +      Length,
> > > +      mMmMemLibInternalMaximumSupportAddress
> > > +      ));
> > > +    return FALSE;
> > > +  }
> > > +
> > > +  for (Index = 0; Index < mMmMemLibInternalMmramCount; Index ++) {
> > > +    if (((Buffer >= mMmMemLibInternalMmramRanges[Index].CpuStart) &&
> > (Buffer < mMmMemLibInternalMmramRanges[Index].CpuStart +
> > mMmMemLibInternalMmramRanges[Index].PhysicalSize)) ||
> > > +        ((mMmMemLibInternalMmramRanges[Index].CpuStart >= Buffer)
> > && (mMmMemLibInternalMmramRanges[Index].CpuStart < Buffer + Length))) {
> > > +      DEBUG ((
> > > +        DEBUG_ERROR,
> > > +        "MmIsBufferOutsideMmValid: Overlap: Buffer (0x%lx) - Length
> > (0x%lx), ",
> > > +        Buffer,
> > > +        Length
> > > +        ));
> > > +      DEBUG ((
> > > +        DEBUG_ERROR,
> > > +        "CpuStart (0x%lx) - PhysicalSize (0x%lx)\n",
> > > +        mMmMemLibInternalMmramRanges[Index].CpuStart,
> > > +        mMmMemLibInternalMmramRanges[Index].PhysicalSize
> > > +        ));
> > > +      return FALSE;
> > > +    }
> > > +  }
> > > +
> > > +  return TRUE;
> > > +}
> > > +
> > > +/**
> > > +  Copies a source buffer (non-MMRAM) to a destination buffer (MMRAM).
> > > +
> > > +  This function copies a source buffer (non-MMRAM) to a destination buffer
> > (MMRAM).
> > > +  It checks if source buffer is valid per processor architecture and not overlap
> > with MMRAM.
> > > +  If the check passes, it copies memory and returns EFI_SUCCESS.
> > > +  If the check fails, it return EFI_SECURITY_VIOLATION.
> > > +  The implementation must be reentrant.
> > > +
> > > +  @param  DestinationBuffer   The pointer to the destination buffer of the
> > memory copy.
> > > +  @param  SourceBuffer        The pointer to the source buffer of the
> > memory copy.
> > > +  @param  Length              The number of bytes to copy from
> > SourceBuffer to DestinationBuffer.
> > > +
> > > +  @retval EFI_SECURITY_VIOLATION The SourceBuffer is invalid per
> > processor architecture or overlap with MMRAM.
> > > +  @retval EFI_SUCCESS            Memory is copied.
> > > +
> > > +**/
> > > +EFI_STATUS
> > > +EFIAPI
> > > +MmCopyMemToMmram (
> > > +  OUT VOID       *DestinationBuffer,
> > > +  IN CONST VOID  *SourceBuffer,
> > > +  IN UINTN       Length
> > > +  )
> > > +{
> > > +  if (!MmIsBufferOutsideMmValid
> > ((EFI_PHYSICAL_ADDRESS)(UINTN)SourceBuffer, Length)) {
> > > +    DEBUG ((DEBUG_ERROR, "MmCopyMemToMmram: Security Violation:
> > Source (0x%x), Length (0x%x)\n", SourceBuffer, Length));
> > > +    return EFI_SECURITY_VIOLATION;
> > > +  }
> > > +  CopyMem (DestinationBuffer, SourceBuffer, Length);
> > > +  return EFI_SUCCESS;
> > > +}
> > > +
> > > +/**
> > > +  Copies a source buffer (MMRAM) to a destination buffer (NON-MMRAM).
> > > +
> > > +  This function copies a source buffer (non-MMRAM) to a destination buffer
> > (MMRAM).
> > > +  It checks if destination buffer is valid per processor architecture and not
> > overlap with MMRAM.
> > > +  If the check passes, it copies memory and returns EFI_SUCCESS.
> > > +  If the check fails, it returns EFI_SECURITY_VIOLATION.
> > > +  The implementation must be reentrant.
> > > +
> > > +  @param  DestinationBuffer   The pointer to the destination buffer of the
> > memory copy.
> > > +  @param  SourceBuffer        The pointer to the source buffer of the
> > memory copy.
> > > +  @param  Length              The number of bytes to copy from
> > SourceBuffer to DestinationBuffer.
> > > +
> > > +  @retval EFI_SECURITY_VIOLATION The DesinationBuffer is invalid per
> > processor architecture or overlap with MMRAM.
> > > +  @retval EFI_SUCCESS            Memory is copied.
> > > +
> > > +**/
> > > +EFI_STATUS
> > > +EFIAPI
> > > +MmCopyMemFromMmram (
> > > +  OUT VOID       *DestinationBuffer,
> > > +  IN CONST VOID  *SourceBuffer,
> > > +  IN UINTN       Length
> > > +  )
> > > +{
> > > +  if (!MmIsBufferOutsideMmValid
> > ((EFI_PHYSICAL_ADDRESS)(UINTN)DestinationBuffer, Length)) {
> > > +    DEBUG ((DEBUG_ERROR, "MmCopyMemFromMmram: Security
> > Violation: Destination (0x%x), Length (0x%x)\n", DestinationBuffer, Length));
> > > +    return EFI_SECURITY_VIOLATION;
> > > +  }
> > > +  CopyMem (DestinationBuffer, SourceBuffer, Length);
> > > +  return EFI_SUCCESS;
> > > +}
> > > +
> > > +/**
> > > +  Copies a source buffer (NON-MMRAM) to a destination buffer
> > (NON-MMRAM).
> > > +
> > > +  This function copies a source buffer (non-MMRAM) to a destination buffer
> > (MMRAM).
> > > +  It checks if source buffer and destination buffer are valid per processor
> > architecture and not overlap with MMRAM.
> > > +  If the check passes, it copies memory and returns EFI_SUCCESS.
> > > +  If the check fails, it returns EFI_SECURITY_VIOLATION.
> > > +  The implementation must be reentrant, and it must handle the case where
> > source buffer overlaps destination buffer.
> > > +
> > > +  @param  DestinationBuffer   The pointer to the destination buffer of the
> > memory copy.
> > > +  @param  SourceBuffer        The pointer to the source buffer of the
> > memory copy.
> > > +  @param  Length              The number of bytes to copy from
> > SourceBuffer to DestinationBuffer.
> > > +
> > > +  @retval EFI_SECURITY_VIOLATION The DesinationBuffer is invalid per
> > processor architecture or overlap with MMRAM.
> > > +  @retval EFI_SECURITY_VIOLATION The SourceBuffer is invalid per
> > processor architecture or overlap with MMRAM.
> > > +  @retval EFI_SUCCESS            Memory is copied.
> > > +
> > > +**/
> > > +EFI_STATUS
> > > +EFIAPI
> > > +MmCopyMem (
> > > +  OUT VOID       *DestinationBuffer,
> > > +  IN CONST VOID  *SourceBuffer,
> > > +  IN UINTN       Length
> > > +  )
> > > +{
> > > +  if (!MmIsBufferOutsideMmValid
> > ((EFI_PHYSICAL_ADDRESS)(UINTN)DestinationBuffer, Length)) {
> > > +    DEBUG ((DEBUG_ERROR, "MmCopyMem: Security Violation: Destination
> > (0x%x), Length (0x%x)\n", DestinationBuffer, Length));
> > > +    return EFI_SECURITY_VIOLATION;
> > > +  }
> > > +  if (!MmIsBufferOutsideMmValid
> > ((EFI_PHYSICAL_ADDRESS)(UINTN)SourceBuffer, Length)) {
> > > +    DEBUG ((DEBUG_ERROR, "MmCopyMem: Security Violation: Source
> > (0x%x), Length (0x%x)\n", SourceBuffer, Length));
> > > +    return EFI_SECURITY_VIOLATION;
> > > +  }
> > > +  CopyMem (DestinationBuffer, SourceBuffer, Length);
> > > +  return EFI_SUCCESS;
> > > +}
> > > +
> > > +/**
> > > +  Fills a target buffer (NON-MMRAM) with a byte value.
> > > +
> > > +  This function fills a target buffer (non-MMRAM) with a byte value.
> > > +  It checks if target buffer is valid per processor architecture and not overlap
> > with MMRAM.
> > > +  If the check passes, it fills memory and returns EFI_SUCCESS.
> > > +  If the check fails, it returns EFI_SECURITY_VIOLATION.
> > > +
> > > +  @param  Buffer    The memory to set.
> > > +  @param  Length    The number of bytes to set.
> > > +  @param  Value     The value with which to fill Length bytes of Buffer.
> > > +
> > > +  @retval EFI_SECURITY_VIOLATION The Buffer is invalid per processor
> > architecture or overlap with MMRAM.
> > > +  @retval EFI_SUCCESS            Memory is set.
> > > +
> > > +**/
> > > +EFI_STATUS
> > > +EFIAPI
> > > +MmSetMem (
> > > +  OUT VOID  *Buffer,
> > > +  IN UINTN  Length,
> > > +  IN UINT8  Value
> > > +  )
> > > +{
> > > +  if (!MmIsBufferOutsideMmValid ((EFI_PHYSICAL_ADDRESS)(UINTN)Buffer,
> > Length)) {
> > > +    DEBUG ((DEBUG_ERROR, "MmSetMem: Security Violation: Source
> > (0x%x), Length (0x%x)\n", Buffer, Length));
> > > +    return EFI_SECURITY_VIOLATION;
> > > +  }
> > > +  SetMem (Buffer, Length, Value);
> > > +  return EFI_SUCCESS;
> > > +}
> > > +
> > > +/**
> > > +  The constructor function initializes the Mm Mem library
> > > +
> > > +  @param  ImageHandle   The firmware allocated handle for the EFI
> > image.
> > > +  @param  SystemTable   A pointer to the EFI System Table.
> > > +
> > > +  @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.
> > > +
> > > +**/
> > > +EFI_STATUS
> > > +EFIAPI
> > > +MemLibConstructor (
> > > +  IN EFI_HANDLE             ImageHandle,
> > > +  IN EFI_MM_SYSTEM_TABLE    *MmSystemTable
> > > +  )
> > > +{
> > > +
> > > +  //
> > > +  // Calculate and save maximum support address
> > > +  //
> > > +  MmMemLibInternalCalculateMaximumSupportAddress ();
> > > +
> > > +  return EFI_SUCCESS;
> > > +}
> > > diff --git a/StandaloneMmPkg/Library/MemLib/MemLib.inf
> > b/StandaloneMmPkg/Library/MemLib/MemLib.inf
> > > new file mode 100644
> > > index 0000000000..52b7c06397
> > > --- /dev/null
> > > +++ b/StandaloneMmPkg/Library/MemLib/MemLib.inf
> > > @@ -0,0 +1,47 @@
> > > +## @file
> > > +#  Instance of MM memory check library.
> > > +#
> > > +#  MM memory check library library implementation. This library consumes
> > MM_ACCESS_PROTOCOL
> > > +#  to get MMRAM information. In order to use this library instance, the
> > platform should produce
> > > +#  all MMRAM range via MM_ACCESS_PROTOCOL, including the range for
> > firmware (like MM Core
> > > +#  and MM driver) and/or specific dedicated hardware.
> > > +#
> > > +#  Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
> > > +#  Copyright (c) 2016 - 2017, ARM Limited. All rights reserved.<BR>
> > > +#
> > > +#  This program and the accompanying materials
> > > +#  are licensed and made available under the terms and conditions of the
> > BSD License
> > > +#  which accompanies this distribution.  The full text of the license may be
> > found at
> > > +#  http://opensource.org/licenses/bsd-license.php
> > > +#
> > > +#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
> > BASIS,
> > > +#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
> > EXPRESS OR IMPLIED.
> > > +#
> > > +##
> > > +
> > > +[Defines]
> > > +  INF_VERSION                    = 0x0001001A
> > > +  BASE_NAME                      = MemLib
> > > +  FILE_GUID                      =
> > EA355F14-6409-4716-829F-37B3BC7C7F26
> > > +  MODULE_TYPE                    = MM_STANDALONE
> > > +  VERSION_STRING                 = 1.0
> > > +  PI_SPECIFICATION_VERSION       = 0x00010032
> > > +  LIBRARY_CLASS                  = MemLib|MM_STANDALONE
> > MM_CORE_STANDALONE
> > > +  CONSTRUCTOR                    = MemLibConstructor
> > > +
> > > +#
> > > +# The following information is for reference only and not required by the
> > build tools.
> > > +#
> > > +#  VALID_ARCHITECTURES           = AARCH64
> > > +#
> > > +
> > > +[Sources.AARCH64]
> > > +  Arm/MemLib.c
> > > +
> > > +[Packages]
> > > +  MdePkg/MdePkg.dec
> > > +  StandaloneMmPkg/StandaloneMmPkg.dec
> > > +
> > > +[LibraryClasses]
> > > +  BaseMemoryLib
> > > +  DebugLib
> > > --
> > > 2.16.2
> > >
> > _______________________________________________
> > edk2-devel mailing list
> > edk2-devel@lists.01.org
> > https://lists.01.org/mailman/listinfo/edk2-devel


  reply	other threads:[~2018-04-25 10:34 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-06 14:42 [PATCH v1 00/18] *** Standalone Management Mode Core Interface for AARCH64 Platforms *** Supreeth Venkatesh
2018-04-06 14:42 ` [PATCH v1 01/18] ArmPkg: Add PCDs needed for MM communication driver Supreeth Venkatesh
2018-04-11 14:43   ` Achin Gupta
     [not found]     ` <AM4PR0802MB23063743A3B2F5A552BE320580870@AM4PR0802MB2306.eurprd08.prod.outlook.com>
2018-05-04 23:13       ` Supreeth Venkatesh
2018-05-04 23:17     ` Supreeth Venkatesh
2018-04-06 14:42 ` [PATCH v1 02/18] ArmPkg/Drivers: Add EFI_MM_COMMUNICATION_PROTOCOL DXE driver Supreeth Venkatesh
2018-04-11 14:00   ` Achin Gupta
2018-05-04 23:18     ` Supreeth Venkatesh
2018-04-06 14:42 ` [PATCH v1 03/18] ArmPkg/Include: Add MM interface SVC return codes Supreeth Venkatesh
2018-04-11 14:38   ` Achin Gupta
2018-05-04 23:19     ` Supreeth Venkatesh
2018-04-06 14:42 ` [PATCH v1 04/18] ArmPkg/ArmMmuLib: Add MMU Library suitable for use in S-EL0 Supreeth Venkatesh
2018-04-11 19:21   ` Achin Gupta
2018-05-04 23:19     ` Supreeth Venkatesh
2018-04-06 14:42 ` [PATCH v1 05/18] ArmPkg/ArmMmuLib: Add MMU library inf file " Supreeth Venkatesh
2018-04-11 19:24   ` Achin Gupta
2018-05-04 23:19     ` Supreeth Venkatesh
2018-04-06 14:42 ` [PATCH v1 06/18] StandaloneMmPkg: Add an AArch64 specific entry point library Supreeth Venkatesh
2018-04-16 14:04   ` Achin Gupta
2018-05-04 23:20     ` Supreeth Venkatesh
2018-04-06 14:42 ` [PATCH v1 07/18] StandaloneMmPkg/FvLib: Add a common FV Library for management mode Supreeth Venkatesh
2018-04-16 14:44   ` Achin Gupta
2018-05-04 23:21     ` Supreeth Venkatesh
2018-04-06 14:42 ` [PATCH v1 08/18] StandaloneMmPkg/MemLib: AARCH64 Specific instance of memory check library Supreeth Venkatesh
2018-04-16 15:12   ` Achin Gupta
2018-04-16 22:30     ` Yao, Jiewen
2018-04-25 10:35       ` Achin Gupta [this message]
2018-04-26 13:02         ` Yao, Jiewen
2018-05-04 23:21     ` Supreeth Venkatesh
2018-04-06 14:42 ` [PATCH v1 09/18] StandaloneMmPkg/MemoryAllocationLib: Add MM memory allocation library Supreeth Venkatesh
2018-04-25 14:33   ` Achin Gupta
2018-04-26 13:05     ` Yao, Jiewen
2018-05-04 23:23       ` Supreeth Venkatesh
2018-05-04 23:21     ` Supreeth Venkatesh
2018-04-06 14:42 ` [PATCH v1 10/18] StandaloneMmPkg/HobLib: Add AARCH64 Specific HOB Library for management mode Supreeth Venkatesh
2018-04-25 14:50   ` Achin Gupta
2018-04-26 13:04     ` Yao, Jiewen
2018-05-04 23:22       ` Supreeth Venkatesh
2018-05-04 23:25     ` Supreeth Venkatesh
2018-04-06 14:42 ` [PATCH v1 11/18] StandaloneMmPkg: MM driver entry point library Supreeth Venkatesh
2018-04-30 14:29   ` Achin Gupta
2018-05-04 23:24     ` Supreeth Venkatesh
2018-04-06 14:42 ` [PATCH v1 12/18] StandaloneMmPkg/CpuMm: Add CPU driver suitable for ARM Platforms Supreeth Venkatesh
2018-04-18 22:09   ` Daniil Egranov
2018-05-04 23:25     ` Supreeth Venkatesh
2018-04-30 15:50   ` Achin Gupta
2018-05-04 23:24     ` Supreeth Venkatesh
2018-04-06 14:42 ` [PATCH v1 13/18] StandaloneMmPkg/Core: Implementation of Standalone MM Core Module Supreeth Venkatesh
2018-04-30 19:19   ` Achin Gupta
2018-04-30 19:28     ` Ard Biesheuvel
2018-04-30 20:17       ` Achin Gupta
2018-05-01  8:18       ` Laszlo Ersek
2018-05-04 23:28     ` Supreeth Venkatesh
2018-04-06 14:42 ` [PATCH v1 14/18] StandaloneMmPkg: Describe the declaration, definition and fdf files Supreeth Venkatesh
2018-04-18 19:50   ` Daniil Egranov
2018-05-04 23:29     ` Supreeth Venkatesh
2018-04-30 19:32   ` Achin Gupta
2018-05-04 23:28     ` Supreeth Venkatesh
2018-04-06 14:42 ` [PATCH v1 15/18] ArmPkg: Extra action to update permissions for S-ELO MM Image Supreeth Venkatesh
2018-04-30 19:49   ` Achin Gupta
2018-05-04 23:30     ` Supreeth Venkatesh
2018-04-06 14:42 ` [PATCH v1 16/18] BaseTools/AutoGen: Update header file for MM modules Supreeth Venkatesh
2018-04-30 19:52   ` Achin Gupta
2018-05-04 23:30     ` Supreeth Venkatesh
2018-04-06 14:42 ` [PATCH v1 17/18] StandaloneMmPkg: Add application to test MM communication protocol Supreeth Venkatesh
2018-04-30 20:02   ` Achin Gupta
2018-05-04 23:31     ` Supreeth Venkatesh
2018-04-06 14:42 ` [PATCH v1 18/18] StandaloneMmPkg: Add handler to handle event received from Normal World Supreeth Venkatesh
2018-04-08  6:01 ` [PATCH v1 00/18] *** Standalone Management Mode Core Interface for AARCH64 Platforms *** Yao, Jiewen
2018-05-04 23:15   ` Supreeth Venkatesh

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=20180425103535.GL663@e104320-lin \
    --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