From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.92.40.18]) by mx.groups.io with SMTP id smtpd.web11.1511.1614715500457847042 for ; Tue, 02 Mar 2021 12:05:00 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@outlook.com header.s=selector1 header.b=tN3Kggbz; spf=pass (domain: outlook.com, ip: 40.92.40.18, mailfrom: kun.q@outlook.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fArirZWS5iHk6YKZ0bwU28J5+RI9TVETVhg36Zzerq5rY4PAf3RbOdT2nU98BF3es7HLawsRmz8pk+Gi1i2hxgyj5/PQ49fGONs5nE2yqKbYdlOe3UGfAK2wxTOSZYSbHER5KeWDpIbKy413uc6UedvQZ/G5LzV7LF+F8gD1OTI0oSsG2pXYAPc7nw+2OVqGNy877yF8UFw5q3qksYjkE7SzFYXT7kRQcKvkSNn2gfIchxHBX2NqcrUZUbwTsYnds8eauVkjfau6tL5Vq5oEUpfinCJQnv1CO5sVMDV9TZL5RZFWb4xvtDcd4EeMYNvCK2RZgUvROCPmgD9IcolhEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NM+Fcmh+fdzwqftMUdB3TDhQ+IIqLajRzKheWNqddR8=; b=O0SWv9ynHf7bs8Az7zT1TMl4sZ5P9RItjfpiHkFwFoZuIamEzQg9kQHAbf6WWFmSVHUIdFpe99dSDMSHRvLeoGAt3o/53Ap+hQZAInZs+Xg63iTuotV262PS0cs3PMtjEpQQxzfG2BX3bdRqf2Scp4eMKBkSRmgKdzm/yF8ak2858UFvxUtXTFfJ7z+kgULjqwAI+uLU5RFduuTwugWTX7qmHV94zAlXOPbMxvjsbiCRQXGWFan6QsVWfAu1RI52erOyX84qh8+Iw/ak+/OO2aSSdwKkCgLxg2/U88Uiu06rekDOaEXrozCwtjNr9QhAnLSp08+VNKMP6V3Cciz3XA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NM+Fcmh+fdzwqftMUdB3TDhQ+IIqLajRzKheWNqddR8=; b=tN3KggbzhIgPM7NvseEKNdmgYMmTkvjofEj0HpdFf0CvyoodN7c//Ecc6v2Lpkhr3gvHvEzDdBMZx5Y0T6Nx87xOHfMJekM7tnyahv07ppNWY/1AbsKRxnwyXAGOXWKfzowrsHjRrrlI0wKmRwbimKdqZWYCcup90DgH7GQPxhMGN9hJ8721j+cbquwhnjXPLsu46eK7GdkcShNxEdIXOa0u2xqYNpzVDMtNiNz3GhcudHZtsJMcsUYQf/+M1vVEce6OgWyz41+/IJ3MqA5pXSzIWbjulmJTzPD31sru1HF+d/zPhi0CvrmN7Sbm4HsPgkBdUeViSIJ6xx0cQp73jQ== Received: from BN7NAM10FT040.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e8f::4e) by BN7NAM10HT141.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e8f::406) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.19; Tue, 2 Mar 2021 20:04:59 +0000 Received: from MWHPR06MB3102.namprd06.prod.outlook.com (2a01:111:e400:7e8f::49) by BN7NAM10FT040.mail.protection.outlook.com (2a01:111:e400:7e8f::238) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3890.19 via Frontend Transport; Tue, 2 Mar 2021 20:04:59 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:B24D07620DA8AFC69CBEAFED6C4B8B679ED6DC9E59273D172FC79B044215E4F8;UpperCasedChecksum:06482A6CE1A57EB5E716A3DC5F1D7114F59589B7EC0AE68A154D54847F3ECFC8;SizeAsReceived:7460;Count:47 Received: from MWHPR06MB3102.namprd06.prod.outlook.com ([fe80::d4ee:1260:6f53:3f7b]) by MWHPR06MB3102.namprd06.prod.outlook.com ([fe80::d4ee:1260:6f53:3f7b%7]) with mapi id 15.20.3890.028; Tue, 2 Mar 2021 20:04:59 +0000 From: "Kun Qin" To: devel@edk2.groups.io CC: Jian J Wang , Hao A Wu , Liming Gao Subject: [PATCH v4 3/7] MdeModulePkg: VariableSmmRuntimeDxe: Added request unblock memory interface Date: Tue, 2 Mar 2021 12:04:34 -0800 Message-ID: X-Mailer: git-send-email 2.30.0.windows.1 In-Reply-To: <20210302200438.1901-1-kun.q@outlook.com> References: <20210302200438.1901-1-kun.q@outlook.com> X-TMN: [mx+11LPGKoKfxgcm4VLPYhTaMLJbJsxe] X-ClientProxiedBy: MWHPR19CA0063.namprd19.prod.outlook.com (2603:10b6:300:94::25) To MWHPR06MB3102.namprd06.prod.outlook.com (2603:10b6:301:3e::35) Return-Path: kun.q@outlook.com X-Microsoft-Original-Message-ID: <20210302200438.1901-4-kun.q@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (50.35.88.161) by MWHPR19CA0063.namprd19.prod.outlook.com (2603:10b6:300:94::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.17 via Frontend Transport; Tue, 2 Mar 2021 20:04:57 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 47 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 2d69b6f9-df97-4e70-1b3e-08d8ddb673e7 X-MS-TrafficTypeDiagnostic: BN7NAM10HT141: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: D/r+bMIKMHyG26DcvSjARGLho4IJFX9aK9uc3v7zIOqlKNNzV97UgtVA+qLRx/O6B/NuuPVLeGFSfkSBHQYPRLqrVLIOTyuhVrd8okR5X77PruWwxaIzhUb4wneSLK95eMxacsYdykIXw7ZMPg+SWVQy8VaEu5HAKhZs7qUFtpMyFygPnOrCeoAqSAIFWINs+kfGhjVCcjB+0dsYQrJiPnHwOXMQ70fT9/IK/9sL2VhrRwAhXVVm+yTp4fN9qSJrFmYz8ssxORYzeaLH5LdyVlS0dh3ONs2WewBCU07gqrWcfF/hVbxyE6hyHfcuMxXb0oZKRXeXOWSxJLyCpWJ8ERs+dlBYag31k6KIasEELSEWuw/9BtzR4isJruJikA89T7ZfDcjZjh4J8vgZ5iaZMQ== X-MS-Exchange-AntiSpam-MessageData: 2JNQINN33BqbgywMOmRaWTYOmQNlmSKhL5IOL6mD8uf00S7h+bWNE5aO9bjnzECRUe6wjH1h2zgMThxoHppJuTYErYQl9bZVyJ1FAJ9piXla1+GiaRzJUdzKGs4EWdnf3BiBP1ie0onQe9xb+zvWUw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2d69b6f9-df97-4e70-1b3e-08d8ddb673e7 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2021 20:04:57.4455 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: BN7NAM10FT040.eop-nam10.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7NAM10HT141 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain This changes added usage of MmUnblockMemoryLib to explicitly request runtime cache regions(and its indicators) to be accessible from MM environment when PcdEnableVariableRuntimeCache is enabled. It will bring in compatibility with architectures that supports full memory blockage inside MM. Cc: Jian J Wang Cc: Hao A Wu Cc: Liming Gao Signed-off-by: Kun Qin Reviewed-by: Hao A Wu --- Notes: v4: - Added reviewed-by tag. [Hao] =20 v3: - Removed Dxe prefix to match interface change. [Jiewen] =20 v2: - Newly added in v2. MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c | 42 = ++++++++++++++++++++ MdeModulePkg/MdeModulePkg.dsc | 1 = + MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf | 1 = + 3 files changed, 44 insertions(+) diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeD= xe.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c index c47e614d81f4..a166d284dfe4 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.c @@ -35,6 +35,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include #include #include +#include =20 #include #include @@ -165,6 +166,7 @@ InitVariableCache ( ) { VARIABLE_STORE_HEADER *VariableCacheStorePtr; + EFI_STATUS Status; =20 if (TotalVariableCacheSize =3D=3D NULL) { return EFI_INVALID_PARAMETER; @@ -186,6 +188,18 @@ InitVariableCache ( if (*VariableCacheBuffer =3D=3D NULL) { return EFI_OUT_OF_RESOURCES; } + + // + // Request to unblock the newly allocated cache region to be accessible = from inside MM + // + Status =3D MmUnblockMemoryRequest ( + (EFI_PHYSICAL_ADDRESS) (UINTN) *VariableCacheBuffer, + EFI_SIZE_TO_PAGES (*TotalVariableCacheSize) + ); + if (Status !=3D EFI_UNSUPPORTED && EFI_ERROR (Status)) { + return Status; + } + VariableCacheStorePtr =3D *VariableCacheBuffer; SetMem32 ((VOID *) VariableCacheStorePtr, *TotalVariableCacheSize, (UINT= 32) 0xFFFFFFFF); =20 @@ -1536,6 +1550,34 @@ SendRuntimeVariableCacheContextToSmm ( SmmRuntimeVarCacheContext->ReadLock =3D &mVariableRuntimeCacheReadLock; SmmRuntimeVarCacheContext->HobFlushComplete =3D &mHobFlushComplete; =20 + // + // Request to unblock this region to be accessible from inside MM enviro= nment + // These fields "should" be all on the same page, but just to be on the = safe side... + // + Status =3D MmUnblockMemoryRequest ( + (EFI_PHYSICAL_ADDRESS) ALIGN_VALUE ((UINTN) SmmRuntimeVarCache= Context->PendingUpdate - EFI_PAGE_SIZE + 1, EFI_PAGE_SIZE), + EFI_SIZE_TO_PAGES (sizeof(mVariableRuntimeCachePendingUpdate)) + ); + if (Status !=3D EFI_UNSUPPORTED && EFI_ERROR (Status)) { + goto Done; + } + + Status =3D MmUnblockMemoryRequest ( + (EFI_PHYSICAL_ADDRESS) ALIGN_VALUE ((UINTN) SmmRuntimeVarCache= Context->ReadLock - EFI_PAGE_SIZE + 1, EFI_PAGE_SIZE), + EFI_SIZE_TO_PAGES (sizeof(mVariableRuntimeCacheReadLock)) + ); + if (Status !=3D EFI_UNSUPPORTED && EFI_ERROR (Status)) { + goto Done; + } + + Status =3D MmUnblockMemoryRequest ( + (EFI_PHYSICAL_ADDRESS) ALIGN_VALUE ((UINTN) SmmRuntimeVarCache= Context->HobFlushComplete - EFI_PAGE_SIZE + 1, EFI_PAGE_SIZE), + EFI_SIZE_TO_PAGES (sizeof(mHobFlushComplete)) + ); + if (Status !=3D EFI_UNSUPPORTED && EFI_ERROR (Status)) { + goto Done; + } + // // Send data to SMM. // diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index 7ca4a1bb3080..9272da89a998 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -100,6 +100,7 @@ [LibraryClasses] SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf DisplayUpdateProgressLib|MdeModulePkg/Library/DisplayUpdateProgressLibGr= aphics/DisplayUpdateProgressLibGraphics.inf VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/Var= iablePolicyHelperLib.inf + MmUnblockMemoryLib|MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLibN= ull.inf =20 [LibraryClasses.EBC.PEIM] IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeD= xe.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.i= nf index b6dbc839e023..a0d8b2267e92 100644 --- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf +++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf @@ -60,6 +60,7 @@ [LibraryClasses] TpmMeasurementLib SafeIntLib PcdLib + MmUnblockMemoryLib =20 [Protocols] gEfiVariableWriteArchProtocolGuid ## PRODUCES --=20 2.30.0.windows.1