From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.92.22.100]) by mx.groups.io with SMTP id smtpd.web10.7738.1614917671350976979 for ; Thu, 04 Mar 2021 20:14:31 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@outlook.com header.s=selector1 header.b=XCsqh2HL; spf=pass (domain: outlook.com, ip: 40.92.22.100, mailfrom: kun.q@outlook.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kkHpEB/6Ta6k/jDgcv/luTORAYCXWCUgfgR9+Gx5D8aLpSRF1bHZ51bEb3XQaSh5LqlLHh5yADFPNKm76ALWpJSYpuyIM79IGe5TRryNHMJwASehSe79LVf4COM+7W3aeuQxW0xq5w1NPT4TXBpM+tR8rsoEN/UKaR2LPIkuQ9vycUFWOiHlrsqgtIbGWSXJLGQ3PKDSRaKCL19yHFBnyDrgusdMLHpneVI2nmmWS1XYbsXmkerorVeZlxGaaf/t+e2BCHMyPOJ0pNK1q5bSMvRefsIGR7gp8Vw8VbA2IJg5t8u0Ytxh8L3r1/AN9hSGL2fLv7F3vZgthOyH+WGnvw== 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=MUSUmm2msAss4ENxva47wMVsdTxRcEBwnNBt2ARcwpo=; b=Z9wAgZVfflYx+p13OluTRnHi65YXI+VY1Kay62susrWSNGVomXiN2oHvqUK6Af5a84wQ4j1Vnh02Ib/EEkbipeX8UEj1XaaYq1uEnG1PY6aiZhlIO6tHgf9WQsWNUVVSnDWs8YYnWpn2EZGcM1IVBIHhoTblGvJwwl/IJdOCqEw1g4tS8vGtRJ3PwPtTE4B0CKy3TGgH7V0lzE7ZayYLBP4KJZewcHkmJScQXDadK+MQb37mDsvIpeNtK7kkLgQt0hETSMVjilfdkD11FNfkvVONQ2SKAo54nXO+PJ3K3EFlnfKhq8ToDh75OxW3rjBxcuHKmGziMHz8QNrmChL+Gg== 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=MUSUmm2msAss4ENxva47wMVsdTxRcEBwnNBt2ARcwpo=; b=XCsqh2HLcXFMukB2UC9qoA4jm5bP1+qpvRYpuT/84mgtlUQ6BEv/HgNji88yl2EBWBYtWxPXPHvb9Qa0AZbqAaBFVynL83/rxJ/Am0ipQTPPMw3HsrzyLMrYeZDQpyZd/gMFYtZJG3Jvy8d/bUPiRY1Og0qEX2uPFLVMFhzOTC5rvVRTjEkyC4gb4Iyy/KR4dCK2N1jJb1ptSa1mQyajyoxMcD703PNdYVtspYXqzwCTtay5mMBubhDS0z361ejC6XqyaeKPbMVUid6PhbAR6pLKetZ4vXK81//rXXlizE6v66c5UahM8+v7RWIazz3fHoAckaFHx6WagI+66BBPcg== Received: from DM6NAM12FT067.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc64::4f) by DM6NAM12HT199.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc64::208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.9; Fri, 5 Mar 2021 04:14:30 +0000 Received: from MWHPR06MB3102.namprd06.prod.outlook.com (2a01:111:e400:fc64::40) by DM6NAM12FT067.mail.protection.outlook.com (2a01:111:e400:fc64::397) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.9 via Frontend Transport; Fri, 5 Mar 2021 04:14:30 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:2F06D41D8CD1764DAE23B79A1D3EF6EEE40E7CFB74460EAB46487F72F7803E5F;UpperCasedChecksum:C735F5C0B970F4D97D1BBC8DF73398719DB84299FC7D7F08E06E154377AAE55A;SizeAsReceived:7340;Count:45 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; Fri, 5 Mar 2021 04:14:30 +0000 From: "Kun Qin" To: devel@edk2.groups.io CC: Jian J Wang , Hao A Wu , Liming Gao Subject: [PATCH v6 3/7] MdeModulePkg: VariableSmmRuntimeDxe: Added request unblock memory interface Date: Thu, 4 Mar 2021 20:14:11 -0800 Message-ID: X-Mailer: git-send-email 2.30.0.windows.1 X-TMN: [J00kRY9RS46kvg1JlWRTAmazb9O1j1uY] X-ClientProxiedBy: MWHPR04CA0046.namprd04.prod.outlook.com (2603:10b6:300:ee::32) To MWHPR06MB3102.namprd06.prod.outlook.com (2603:10b6:301:3e::35) Return-Path: kun.q@outlook.com X-Microsoft-Original-Message-ID: <20210305041415.1733-1-kun.q@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (50.35.88.161) by MWHPR04CA0046.namprd04.prod.outlook.com (2603:10b6:300:ee::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3912.17 via Frontend Transport; Fri, 5 Mar 2021 04:14:30 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 45 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: c3bb2d37-22ae-49fd-8a89-08d8df8d2c7a X-MS-TrafficTypeDiagnostic: DM6NAM12HT199: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: U1KqDyi6O35vwAcdt+A9h/FQo1SKzOG6xYxI6YNru44xOm360js+UXLtf0rM57PhN5bHMHArKCpxTZqcgEAziozB2EdpgZMIbxgyH2aKO3uZfEijI8i/hkXfNcfBIbgOG6naSC9RY//fHugWRjRsW1Ga1xzt6Qzw1YD0u3/st3HkdtMeFuJP/jjr2g0ANGYTwfQv/vgBLOiCxtzSxTdcKBElOFEkvN7fJxxptjy1tx3wH/OJ5575VnTmXiMp79cHsBBPTRRas7xZL4WHYiEqFtwbspX7EF8f99prieGXyNco312J/5OUcaHGPW/lhPf1KtSo6/hW+M2n2Iog3yxkk1Io8xV0Ik73bjJOwTKnixpXb+Rs07BxLYsdugKTla0HrV4Idbq+e6muThdIEycZKA== X-MS-Exchange-AntiSpam-MessageData: BqAwQtA4nv3jYx1ZhIOhiPaxDMMQuXOFSAivh+hTQZ2Dl6cJxYPlKM/ViotAx+ubKpsYoX6i7PPQIdb6tV2qHFxHJt8e2lr14V1NRlKjP0Aw1AgEEf0Eq1X/2tRoUiTB1CycoATk1GHeJ9Slfh0DvA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c3bb2d37-22ae-49fd-8a89-08d8df8d2c7a X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Mar 2021 04:14:30.4485 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: DM6NAM12FT067.eop-nam12.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: DM6NAM12HT199 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: v6: - Previously reviewed, no change. =20 v5: - Previously reviewed, no change. =20 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