From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=104.47.2.76; helo=eur01-db5-obe.outbound.protection.outlook.com; envelope-from=udit.kumar@nxp.com; receiver=edk2-devel@lists.01.org Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on0076.outbound.protection.outlook.com [104.47.2.76]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 613E5207E540B for ; Wed, 9 May 2018 14:09:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=RgiGW0yqzSDqsyeIuTSvz3uFaWRdSBjO4sx69+rdZro=; b=gLDWniGbD4++zFsfOzOXGrLdvCidJGD3eDr7aYZq2GXwyV4umEejC6ukuFhopN9e7SCP1D6TDJj30SZEB5Z/5J/+yEO9jY4GR6Z5bDFxQLZZBNhWVKkBo1ple4BL8BFsOJlKyWNPmchgTE34cdMFCHmPqVN2MACbsNlamO8vCX8= Received: from AM6PR0402MB3334.eurprd04.prod.outlook.com (52.133.18.151) by AM6PR0402MB3559.eurprd04.prod.outlook.com (52.133.19.160) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.735.17; Wed, 9 May 2018 21:09:37 +0000 Received: from AM6PR0402MB3334.eurprd04.prod.outlook.com ([fe80::adae:b328:3790:b1dd]) by AM6PR0402MB3334.eurprd04.prod.outlook.com ([fe80::adae:b328:3790:b1dd%13]) with mapi id 15.20.0735.021; Wed, 9 May 2018 21:09:37 +0000 From: Udit Kumar To: Supreeth Venkatesh , "edk2-devel@lists.01.org" CC: "ard.biesheuvel@linaro.org" , "leif.lindholm@linaro.org" , "jiewen.yao@intel.com" , "liming.gao@intel.com" , "michael.d.kinney@intel.com" Thread-Topic: [edk2] [PATCH v2 04/17] ArmPkg/ArmMmuLib: Add MMU Library suitable for use in S-EL0. Thread-Index: AQHT4+hUVxAn4zqS+kmxS5POpRi0UKQn6kOw Date: Wed, 9 May 2018 21:09:37 +0000 Message-ID: References: <20180504204109.3354-1-supreeth.venkatesh@arm.com> <20180504204109.3354-5-supreeth.venkatesh@arm.com> In-Reply-To: <20180504204109.3354-5-supreeth.venkatesh@arm.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=udit.kumar@nxp.com; x-originating-ip: [92.121.36.198] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM6PR0402MB3559; 7:HnziFV5pR8+wJkqd66kxLMse+lrlBkhXPqskk9NVWlIFKlYjmT6KtSW//kpNoJ7xbuu7xQAvnWJMCNr2n7iGT986nBrzL1wcZYZqLwBLsJOTQ6CE8YjwQDSUaQd59YfClb3R4sSRljm1S0+y3QAYTWCxnoRusXKla/UW388Mfgn2HLlLXiYtYXPLgcrpa6zqGzBjxWTj8eWUtijnnVtVSj5gPDXRK2MUU7Ubde1XXJgkaiCv1QcHN33YkKLtwVRE x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(48565401081)(2017052603328)(7153060)(7193020); SRVR:AM6PR0402MB3559; x-ms-traffictypediagnostic: AM6PR0402MB3559: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(180628864354917)(189930954265078)(162533806227266)(45079756050767)(228905959029699); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3231254)(944501410)(52105095)(93006095)(93001095)(3002001)(10201501046)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(20161123560045)(6072148)(201708071742011); SRVR:AM6PR0402MB3559; BCL:0; PCL:0; RULEID:; SRVR:AM6PR0402MB3559; x-forefront-prvs: 0667289FF8 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39860400002)(39380400002)(396003)(346002)(366004)(376002)(199004)(189003)(13464003)(966005)(66066001)(44832011)(102836004)(45080400002)(478600001)(53546011)(2900100001)(5250100002)(6506007)(14454004)(229853002)(99286004)(76176011)(25786009)(59450400001)(105586002)(7696005)(74316002)(316002)(54906003)(110136005)(5660300001)(2501003)(106356001)(97736004)(11346002)(486006)(446003)(476003)(68736007)(16799955002)(3846002)(6116002)(2906002)(8676002)(81156014)(86362001)(575784001)(55016002)(6306002)(3280700002)(9686003)(6246003)(3660700001)(81166006)(53936002)(186003)(6436002)(4326008)(8936002)(26005)(305945005)(7736002)(33656002)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM6PR0402MB3559; H:AM6PR0402MB3334.eurprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 55AoI16Vh9w2dSjrs1uxc+YmhgO5OWuxQWTEQ7sA9o+QFydEgbF5rPyKvrdNmCC8iop6LEU5iGMblvV711oROiOuXn+esCWkzMUGHXLToO/y2T3naSTJ3N21fwm8HWOX7t1WgGGnMckd8hRuq4leuBtvDNlQeHwxEjfaRUENaklwTOqYHW59BvzStXCq6CXl spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 0eace9b0-59b8-4ef1-ce9f-08d5b5f12c0c X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0eace9b0-59b8-4ef1-ce9f-08d5b5f12c0c X-MS-Exchange-CrossTenant-originalarrivaltime: 09 May 2018 21:09:37.2482 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR0402MB3559 Subject: Re: [PATCH v2 04/17] ArmPkg/ArmMmuLib: Add MMU Library suitable for use in S-EL0. 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, 09 May 2018 21:09:40 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Supreeth,=20 One question on this patch=20 We are asking permission on base-address and changing the permission of=20 memory based upon base and size.=20 I haven't looked at other part of code which manage this ,=20 But will there be possibility that, base address is given correctly and len= gth=20 may over-lap the other MMU entry. Regards Udit=20 > -----Original Message----- > From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of > Supreeth Venkatesh > Sent: Saturday, May 5, 2018 2:11 AM > To: edk2-devel@lists.01.org > Cc: ard.biesheuvel@linaro.org; leif.lindholm@linaro.org; jiewen.yao@intel= .com; > liming.gao@intel.com; michael.d.kinney@intel.com > Subject: [edk2] [PATCH v2 04/17] ArmPkg/ArmMmuLib: Add MMU Library > suitable for use in S-EL0. >=20 > The Standalone MM environment runs in S-EL0 in AArch64 on ARM Standard > Platforms. Privileged firmware e.g. ARM Trusted Firmware sets up its > architectural context including the initial translation tables for the > S-EL1/EL0 translation regime. The MM environment will still request ARM > TF to change the memory attributes of memory regions during > initialization. >=20 > The Standalone MM image is a FV that encapsulates the MM foundation > and drivers. These are PE-COFF images with data and text segments. > To initialise the MM environment, Arm Trusted Firmware has to create > translation tables with sane default attributes for the memory > occupied by the FV. This library sends SVCs to ARM Trusted Firmware > to request memory permissions change for data and text segments. >=20 > This patch adds a simple MMU library suitable for execution in S-EL0 and > requesting memory permissions change operations from Arm Trusted Firmware= . >=20 > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Achin Gupta > Signed-off-by: Supreeth Venkatesh > --- > .../ArmMmuLib/AArch64/ArmMmuStandaloneMmCoreLib.c | 195 > +++++++++++++++++++++ > 1 file changed, 195 insertions(+) > create mode 100644 > ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuStandaloneMmCoreLib.c >=20 > diff --git > a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuStandaloneMmCoreLib.c > b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuStandaloneMmCoreLib.c > new file mode 100644 > index 0000000000..0f5e68d2d4 > --- /dev/null > +++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuStandaloneMmCoreLib.c > @@ -0,0 +1,195 @@ > +/** @file > +* File managing the MMU for ARMv8 architecture in S-EL0 > +* > +* Copyright (c) 2017 - 2018, 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 ma= y be > found at > +* > https://emea01.safelinks.protection.outlook.com/?url=3Dhttp%3A%2F%2Fopens= o > urce.org%2Flicenses%2Fbsd- > license.php&data=3D02%7C01%7Cudit.kumar%40nxp.com%7C776b728240f7402b > 029708d5b1ff7179%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C63 > 6610633113917388&sdata=3DKGmnTNpIKqIXyS2sdVH1I2EaCd8rhm%2BKI05JuxYv8 > Aw%3D&reserved=3D0 > +* > +* 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 > +#include > +#include > +#include > +#include > + > +EFI_STATUS > +GetMemoryPermissions ( > + IN EFI_PHYSICAL_ADDRESS BaseAddress, > + OUT UINT32 *MemoryAttributes > + ) > +{ > + ARM_SVC_ARGS GetMemoryPermissionsSvcArgs =3D {0}; > + > + GetMemoryPermissionsSvcArgs.Arg0 =3D > ARM_SVC_ID_SP_GET_MEM_ATTRIBUTES_AARCH64; > + GetMemoryPermissionsSvcArgs.Arg1 =3D BaseAddress; > + GetMemoryPermissionsSvcArgs.Arg2 =3D 0; > + GetMemoryPermissionsSvcArgs.Arg3 =3D 0; > + > + ArmCallSvc (&GetMemoryPermissionsSvcArgs); > + if (GetMemoryPermissionsSvcArgs.Arg0 =3D=3D > ARM_SVC_SPM_RET_INVALID_PARAMS) { > + *MemoryAttributes =3D 0; > + return EFI_INVALID_PARAMETER; > + } > + > + *MemoryAttributes =3D GetMemoryPermissionsSvcArgs.Arg0; > + return EFI_SUCCESS; > +} > + > +EFI_STATUS > +RequestMemoryPermissionChange ( > + IN EFI_PHYSICAL_ADDRESS BaseAddress, > + IN UINT64 Length, > + IN UINTN Permissions > + ) > +{ > + EFI_STATUS Status; > + ARM_SVC_ARGS ChangeMemoryPermissionsSvcArgs =3D {0}; > + > + ChangeMemoryPermissionsSvcArgs.Arg0 =3D > ARM_SVC_ID_SP_SET_MEM_ATTRIBUTES_AARCH64; > + ChangeMemoryPermissionsSvcArgs.Arg1 =3D BaseAddress; > + ChangeMemoryPermissionsSvcArgs.Arg2 =3D (Length >=3D EFI_PAGE_SIZE) ? = \ > + Length >> EFI_PAGE_SHIFT : 1; > + ChangeMemoryPermissionsSvcArgs.Arg3 =3D Permissions; > + > + ArmCallSvc (&ChangeMemoryPermissionsSvcArgs); > + > + Status =3D ChangeMemoryPermissionsSvcArgs.Arg0; > + > + switch (Status) { > + case ARM_SVC_SPM_RET_SUCCESS: > + Status =3D EFI_SUCCESS; > + break; > + > + case ARM_SVC_SPM_RET_NOT_SUPPORTED: > + Status =3D EFI_UNSUPPORTED; > + break; > + > + case ARM_SVC_SPM_RET_INVALID_PARAMS: > + Status =3D EFI_INVALID_PARAMETER; > + break; > + > + case ARM_SVC_SPM_RET_DENIED: > + Status =3D EFI_ACCESS_DENIED; > + break; > + > + case ARM_SVC_SPM_RET_NO_MEMORY: > + Status =3D EFI_BAD_BUFFER_SIZE; > + break; > + > + default: > + Status =3D EFI_ACCESS_DENIED; > + ASSERT (0); > + } > + > + return Status; > +} > + > +EFI_STATUS > +ArmSetMemoryRegionNoExec ( > + IN EFI_PHYSICAL_ADDRESS BaseAddress, > + IN UINT64 Length > + ) > +{ > + EFI_STATUS Status; > + UINT32 MemoryAttributes; > + > + Status =3D GetMemoryPermissions (BaseAddress, &MemoryAttributes); > + if (Status !=3D EFI_INVALID_PARAMETER) { You can reduce to=20 if( ! GetMemoryPermissions (BaseAddress, &MemoryAttributes)) { return RequestMemoryPermissionChange (BaseAddress } Status is not used post this.=20 GetMemoryPermissions is giving two errors anyway=20 =20 > + return RequestMemoryPermissionChange (BaseAddress, > + Length, > + MemoryAttributes | > + (SET_MEM_ATTR_CODE_PERM_XN << > SET_MEM_ATTR_CODE_PERM_SHIFT)); > + } > + return EFI_INVALID_PARAMETER; > +} > + > +EFI_STATUS > +ArmClearMemoryRegionNoExec ( > + IN EFI_PHYSICAL_ADDRESS BaseAddress, > + IN UINT64 Length > + ) > +{ > + EFI_STATUS Status; > + UINT32 MemoryAttributes; > + > + Status =3D GetMemoryPermissions (BaseAddress, &MemoryAttributes); > + if (Status !=3D EFI_INVALID_PARAMETER) { > + return RequestMemoryPermissionChange (BaseAddress, > + Length, > + MemoryAttributes & > + ~(SET_MEM_ATTR_CODE_PERM_XN << > SET_MEM_ATTR_CODE_PERM_SHIFT)); > + } > + return EFI_INVALID_PARAMETER; > +} > + > +EFI_STATUS > +ArmSetMemoryRegionReadOnly ( > + IN EFI_PHYSICAL_ADDRESS BaseAddress, > + IN UINT64 Length > + ) > +{ > + EFI_STATUS Status; > + UINT32 MemoryAttributes; > + > + Status =3D GetMemoryPermissions (BaseAddress, &MemoryAttributes); > + if (Status !=3D EFI_INVALID_PARAMETER) { > + return RequestMemoryPermissionChange (BaseAddress, > + Length, > + MemoryAttributes | > + (SET_MEM_ATTR_DATA_PERM_RO << > SET_MEM_ATTR_DATA_PERM_SHIFT)); > + } > + return EFI_INVALID_PARAMETER; > +} > +EFI_STATUS > +ArmClearMemoryRegionReadOnly ( > + IN EFI_PHYSICAL_ADDRESS BaseAddress, > + IN UINT64 Length > + ) > +{ > + EFI_STATUS Status; > + UINT32 MemoryAttributes; > + > + Status =3D GetMemoryPermissions (BaseAddress, &MemoryAttributes); > + if (Status !=3D EFI_INVALID_PARAMETER) { > + return RequestMemoryPermissionChange (BaseAddress, > + Length, > + SET_MEM_ATTR_MAKE_PERM_REQUEST > + ( \ > + SET_MEM_ATTR_DATA_PERM_RW, = \ > + MemoryAttributes)); > + } > + return EFI_INVALID_PARAMETER; > +} > + > +EFI_STATUS > +EFIAPI > +ArmConfigureMmu ( > + IN ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable, > + OUT VOID **TranslationTableBase OPTIONAL, > + OUT UINTN *TranslationTableSize OPTIONAL > + ) > +{ > + return EFI_UNSUPPORTED; > +} > + > +EFI_STATUS > +EFIAPI > +ArmMmuStandaloneMmCoreLibConstructor ( > + IN EFI_HANDLE ImageHandle, > + IN EFI_MM_SYSTEM_TABLE *MmSystemTable > + ) > +{ > + return EFI_SUCCESS; > +} > -- > 2.16.2 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://emea01.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Flist= s.01 > .org%2Fmailman%2Flistinfo%2Fedk2- > devel&data=3D02%7C01%7Cudit.kumar%40nxp.com%7C776b728240f7402b02970 > 8d5b1ff7179%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C6366106 > 33113917388&sdata=3Dk1Rdt0%2B0CNMRyz66bckTHkT6lFtINt7nc1FaIoZE4%2FA > %3D&reserved=3D0