From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=40.107.1.79; helo=eur02-he1-obe.outbound.protection.outlook.com; envelope-from=achin.gupta@arm.com; receiver=edk2-devel@lists.01.org Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-eopbgr10079.outbound.protection.outlook.com [40.107.1.79]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 35994226612BE for ; Wed, 25 Apr 2018 03:34:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=awiY7uKpMFqJqSICWnrZHK+YjsYLQ04ANyVNhULeg2M=; b=MWXAhAXGKloWoYe24q5cHaok3NK4LRm9o7EapciCo/+IniBI9Y8/ghUvMAl6w+BUuut6VDEZtoDUCsR1eo/BNq7WwF7Fd4R7LXSsecE7dIPthhUTv0RYOeQhTUZ4SbbxzGTL44mSrzos2oYnLLYKFlQFDBIPsDpwUvzZr/D9kmA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Achin.Gupta@arm.com; Received: from e104320-lin (217.140.96.140) by AM0PR08MB2980.eurprd08.prod.outlook.com (2603:10a6:208:5b::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.696.12; Wed, 25 Apr 2018 10:34:08 +0000 Date: Wed, 25 Apr 2018 11:35:36 +0100 From: Achin Gupta To: "Yao, Jiewen" Cc: Supreeth Venkatesh , "ard.biesheuvel@linaro.org" , "edk2-devel@lists.01.org" , "leif.lindholm@linaro.org" , "Gao, Liming" , "Kinney, Michael D" , "nd@arm.com" Message-ID: <20180425103535.GL663@e104320-lin> References: <20180406144223.10931-1-supreeth.venkatesh@arm.com> <20180406144223.10931-9-supreeth.venkatesh@arm.com> <20180416151258.GP663@e104320-lin> <74D8A39837DF1E4DA445A8C0B3885C503AB659B5@SHSMSX104.ccr.corp.intel.com> MIME-Version: 1.0 In-Reply-To: <74D8A39837DF1E4DA445A8C0B3885C503AB659B5@SHSMSX104.ccr.corp.intel.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Originating-IP: [217.140.96.140] X-ClientProxiedBy: AM0PR06CA0021.eurprd06.prod.outlook.com (2603:10a6:208:ab::34) To AM0PR08MB2980.eurprd08.prod.outlook.com (2603:10a6:208:5b::25) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603328)(7153060)(7193020); SRVR:AM0PR08MB2980; X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB2980; 3:EYjFDpQv6bJ2f2h+qQ2e4/46a7gTWOFq77KXTS05w45DCGvo5TiwF+lAh7odxJ0bhJcfO7sazvCZYVluPDESY370CIKxH4m+/4xO4gDLgHr0B6NuRM7O4ikvYxmMfkVLjmYK49j3/2hSHrEIgs11hqUy1eKLMY6qs9O65UteEqCnG7vtgkPccySh/wwzZDTTS6J9I2N3LwKoRWoTNqhASPPTx/PUj2kcHH5HvbcanuLaEA2e+xX3pWPeyCG0d6bt; 25:CFne10zbU7y58+xvVo/XOJv6b/7Hi6ojUAUvaYjdZesguuFwPd1hURS7/zC4aQANxL/WsmuluNZolD3BJCbq2A2ovCMcPcm2PDTbt7BHl7ZilUCNgWwg4xQ93t3ixpoe1PwMaHKcr/lFHm8DrffpxHGXqmJoamNY8YGNYt33lfT8bMlTfVgcdMTDYjo8pY/pXEut/LiWPOi448+1D01U3FQhvhmPyUFb3N2lfRfGrm7dUB2LwRgAgvTEZyn+xYQ44rxIJ0Mgkc6JM2CNRH2CavqmeNYw1bgv+1DKrRc7JnhtN0S+lz6o3Gv1n35RR3opxEoRqvs1zlr0oqyKKiV0cA==; 31:ppSG/m/vGSDC5n2ySrAPSyEkk2fZK4PWzCFbL7MpxMAUonIrzUXjfkf1vbL354haU5JPga/QoKTrK0SlUSX/88w0p4/j9c3K8twPa+rP+kXec0K8z4iLhI0F6ASF1XzMdsnOoAh6F1V2zmH8SEFQS7TsYZ0xjGezStHnvsz74EysDC/cPRIwlY0EtXdmy2hQ9swFD/1gZc4eykOQZAThf53K4bsvNREI4lrYo3e8bqc= X-MS-TrafficTypeDiagnostic: AM0PR08MB2980: NoDisclaimer: True X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB2980; 20:mdYK9xYq4h8ZU4RIYEyWkGqoKJVv1vaTm6bOtm2daLaV1DXPu1TVhBX7+45DjII7wiCd9wxBzel3GqX8fgVbCA7y1JqpjkO4Iskc8tlkpB2npJDGnvziVR7XFRVPke7LrC5FxsRv7nrC4al7EvbP5FJUuXF8GhfFkH5O0yBOCVmbguQWfvCgocTs4tcvtxRukoLJBo5cAMtezfglibh1T0d0gUOWBjdvx+8WPiVfrJaFvGb8prSISXfQ0TIolTI4; 4:6cdbfpPW9/VD0AUa0pHaf2rDVKmqyxP95hoXyaKtGFkNv8K2qV0E/emCZ96eyk6SnxP70McvS5UeTV42CNEslx0KunDu0922AMF7Jo0tY9NaCt+zyAmthS3d6SXKL4nw7NHeStflJorpBvbvCMBDlPHmr5DrOIcSEjrP3+UiyipEQH9dBEm1DBlOr0W9J5/2J0esmUeksgpfDjyh9yRFkeUzpa5YiFjIpZ3jFimxsL90cKUyWGTfuh4kpBYol0JPKA78khK1295k3JFCs0ZX7yRVWshbwoNxZLmck/dtpKADd6VZYFFtuxlW5gVqyH85+ehqIFaQ5tMQBzcpDIuuh3KTy38QljusWjxZXLqkIus6erMqX0sfhOp6oiZDueX0yXZ2VXeFMcBaVUUEmv2e8hMmGZog5utIlJlop2zULEg= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917)(192374486261705)(162533806227266)(228905959029699); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231232)(944501410)(52105095)(3002001)(10201501046)(93006095)(93001095)(6055026)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(6072148)(201708071742011); SRVR:AM0PR08MB2980; BCL:0; PCL:0; RULEID:; SRVR:AM0PR08MB2980; X-Forefront-PRVS: 06530126A4 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6029001)(346002)(376002)(366004)(39860400002)(39380400002)(396003)(199004)(13464003)(189003)(25786009)(26005)(8936002)(81156014)(47776003)(33896004)(59450400001)(53376002)(52116002)(53546011)(15188155005)(476003)(76176011)(53936002)(55016002)(93886005)(316002)(6496006)(44832011)(6246003)(5660300001)(8676002)(58126008)(11346002)(81166006)(23726003)(66066001)(446003)(486006)(54906003)(966005)(229853002)(4326008)(105586002)(33716001)(106356001)(7736002)(9686003)(72206003)(6116002)(1076002)(6666003)(2906002)(16586007)(305945005)(97736004)(68736007)(186003)(50466002)(86362001)(6916009)(386003)(956004)(16799955002)(6306002)(478600001)(33656002)(3846002)(16526019)(18370500001)(107986001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR08MB2980; H:e104320-lin; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM0PR08MB2980; 23:vIe1NbTgO+wEZyHDSFUR2yyuKTeiPeHDpQthCdyFq?= =?us-ascii?Q?NK5+yN7VO/uURUtFgS6+mBDdycWmCqBCtn8lTYmYTyeNWQ9ywIQYjhs+ilUa?= =?us-ascii?Q?I0jLBF4jxLnTlTeXpfygakp0s0VRqXFL6fzttPl7Ub0oY+9N8qVKdyYLlzcX?= =?us-ascii?Q?UJtm2qzOaxezP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mXCmM/Lwnpa4mqsR7OgzDwr4U6KAEOgXrOoocQe5J0Vu6hW/Bz2D7PuMn4DdxnpSzHkof8qGE4qwzJ0AxZncTclziwWpGhIiGIqVfJ7yE0MhU61x9edu+gczWTeEsE2Kck3fyO1L1y3k2B2nZ7FpF2yUQRxX84Xpxyw1L7FU93cOM9X5Jkul73h09uAlEylBB755FBbNPmaJAb9Am+iPw4NsGTms2nDxQu0jIVpLBbfr8k1/7qitN7uGhxZuqRcpjhGbjGLS5SM6lzxhFGHj8iEp57doiZc+b9xioGvPprq5FQYqLRynw1aAM9IQdQ==; 5:E0SgrXShLYhNzyXFCpHOT0L//tEEI0Ip3do40ZVXYs7diypbdHBDxGg9a5BSeKJiar6kow6NlfOW/7nY5UivOduAhwkeB0Qgzqu8yKEfFTcU9hqP2GkmpH81ZKwpXMDwe6pk+E18/BflqfZqyAMru8TwRnUgeXN7hyNG/C3endU=; 24:p3CSGK5LDt4xkectga9Ryu46dqrC2JrNaad9f5MgdpDxKn78YrL9tBGjVJqZDl+P3IqkmmzoIE0ICKJiyOtE9ueJdY66sLC+6Zrh4QelnNY= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB2980; 7:0WVAXIzeRSwtVJ4b9fIAp5zc4PZNiVTTrzlhiXPUT3c1STrcazP/sOSQRmzUijmAZZ0hcyFDJu62Xt9fX/KHNgTS+GNEuFJZjuBJMOWFXjKhOzyCEQj1qE0dpveR9AtqQ1pz5JBR9qI6elGqgCUJ63VpLtSQ0NJLL0zNjMqDVyHewnMUOaEGyrC1fwjyijSYStp6iCREeaGPB4pzs2kzcAj+HU26tIfBgA4vdWXZ2+hnIDEHki2GPfr0Ectcc3oq X-MS-Office365-Filtering-Correlation-Id: f9742a47-9e15-4d0c-8688-08d5aa981396 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Apr 2018 10:34:08.1144 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f9742a47-9e15-4d0c-8688-08d5aa981396 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB2980 Subject: Re: [PATCH v1 08/18] StandaloneMmPkg/MemLib: AARCH64 Specific instance of memory check library. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Apr 2018 10:34:14 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 > > Cc: ard.biesheuvel@linaro.org; edk2-devel@lists.01.org; > > leif.lindholm@linaro.org; Yao, Jiewen ; Gao, Liming > > ; Kinney, Michael D ; > > 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 > > > Signed-off-by: Supreeth Venkatesh > > > --- > > > 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.
> > > + Copyright (c) 2016 - 2017, ARM Limited. All rights reserved.
> > > + > > > + 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.
> > > + Copyright (c) 2016 - 2017, ARM Limited. All rights reserved.
> > > + > > > + 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 > > > + > > > +#include > > > +#include > > > +#include > > > + > > > +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.
> > > +# Copyright (c) 2016 - 2017, ARM Limited. All rights reserved.
> > > +# > > > +# 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