From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.63]) by mx.groups.io with SMTP id smtpd.web08.2778.1634962490078241606 for ; Fri, 22 Oct 2021 21:14:51 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=N8xeWzBi; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.244.63, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XwjbtvbgIuGub6tClKxxxWbmjXNtNbcHSv+PN2ITJOu1yfLf3D6iOM2F/GxL+ji8vUfew46ZsiO7ZV+8bz3x43b/bWD5sYFXJIj8/rANqKA/ytCv5PJKXAXRNEdtUOfGaJEmQHo/Y9X7aMllHyTj1OoytEn2NPd1WDURQlx4q/nlsRp3YTfclEAiwsTwUnLPtz9D/g/Q2mj5mcOkQ3qVVZYxUzBKvfewoYuEHdgRSMdU2V4k3TAp4jeP0opR03APubXcfZq8f0yEHn/RhyEwXfE1/ZkVZ4hT6EKtbXLiQMMHT/i9e/9lGoU0KmFHY0tuR+1GFCsjRwiL6Zmp5948rg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=oMctcOtIeTQj92ywG7bJsh7OcgCIv1l6OfNWVL8ygi8=; b=W+YsG2mApjXrwfJhJL4+jbKbXOs9qsUSvcBsOyXuuVxCOaWqywMBhkEvqvrN4+QAewQgbT5koqcpntb0582tbLYQSfV/U9dlndudWAKHezmMTCcuXbA1lJ/oBOGso/nAJxaC7clZPzDdpB/Lf6XxaZTlBCvvsDYfVT+oEJBAUWPzZWrePRH2B/qjaKMaURzzg89gNO8bZlw6zsB1de0SX76rkGjQIOIjZT1bdkDzb2jJMgbzQma+/RkVUBR50BhhdWe9yBdh0aqBI4yA4bK3i5I3f1iwNAkyZi+6MOWpFwoHiyewAzli8v3EzGT9COG9AC7Nc/lbqfMu7TUPzauePQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oMctcOtIeTQj92ywG7bJsh7OcgCIv1l6OfNWVL8ygi8=; b=N8xeWzBioYEhTezIIiJJo1qiSg3F33FiAIs4yMVR0KfsjCn5VWNzaqGJXlG+BOWLHPk3d86t1Ro2ZYd7xjGyKdH27/6GAee8Jl3Ur9oevWcrevaj/eYoth+ZipdaEPKofyrF7rdPxHT3EUl1daxWMCRF5voQ6X9LP1JuXz2B0AU= Received: from BN6PR2001CA0048.namprd20.prod.outlook.com (2603:10b6:405:16::34) by MN2PR12MB3790.namprd12.prod.outlook.com (2603:10b6:208:164::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.18; Sat, 23 Oct 2021 04:14:47 +0000 Received: from BN8NAM11FT063.eop-nam11.prod.protection.outlook.com (2603:10b6:405:16:cafe::75) by BN6PR2001CA0048.outlook.office365.com (2603:10b6:405:16::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18 via Frontend Transport; Sat, 23 Oct 2021 04:14:47 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT063.mail.protection.outlook.com (10.13.177.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4628.16 via Frontend Transport; Sat, 23 Oct 2021 04:14:47 +0000 Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.15; Fri, 22 Oct 2021 23:14:43 -0500 From: "Brijesh Singh" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [PATCH v11 29/32] OvmfPkg/MemEncryptSevLib: skip page state change for Mmio address Date: Fri, 22 Oct 2021 23:13:46 -0500 Message-ID: <20211023041349.1263726-30-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211023041349.1263726-1-brijesh.singh@amd.com> References: <20211023041349.1263726-1-brijesh.singh@amd.com> MIME-Version: 1.0 Return-Path: brijesh.singh@amd.com X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e5e67711-8d5d-48e5-fcbd-08d995dba696 X-MS-TrafficTypeDiagnostic: MN2PR12MB3790: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 84SxpgNSNjm+ug3UFTc+zFoxQjnv/dUUtek/68Ayouzst/Cyp3dgl7LTxFPZ02ITz+5sVhjLHP4fJ9sU7IUl/WYjZo2qrxvFcXRXysTi1JozbSu3/BCwiRaq/Dd1oRSITS0Nj6Q2Pj8XtOizdQu5nDQDK2Ngu08PrankRi5xBUHcev7KoZua6avXydf1aLVRL3StweCEEUZYKFY8hjGGXIZyx20vr785M8/2euWgX5IC7xv1N7g3VDCFhfSLJsn6fGgE/UwIL157ddOgCfLN2ppS4tCy5nmd4SUYxo4loAz3NDR/8gPHaYScl26mbi82cTRx1Bz5vTKVo3M7VIcnUwlqtBKMw+OGdjeuhVMh9xxzVQgXwdlyYQn9s5okpK+0nEFnLHGoVreJ6yLfhjgKS2bfX2emQbOyyePItUvOyjijlGpFp2TsJj9tmhQqxA4dbTfiygviohafKgSEuqRfIb2f/bLdUTgmHYtuFFpx/r+z/mL4G+7d2qtaJJNNacTnS8WQv1cJ+Ykxbn5DVHEaAFWQadsefMplkw1/dXWX8aK8P1jYjuUfTQcGKmA5uvuAH1YrpudQLiHwa/Xp/3KJxKDW2Tn1DspT06s/z+47GP8HQx62R4sPI/GbdR/R7+SKJTJTzSn7/Y4yyTmjRowUqB5fbRj9LMWuJ/RhOAWencNkvAeAlJaGfA4P8oCxzwwHAvbghtpZavah1xhBuYYBfb7YVtiKW+S2rIyvh5bDzwQ= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(46966006)(36840700001)(1076003)(54906003)(70586007)(83380400001)(70206006)(316002)(7696005)(6916009)(47076005)(19627235002)(508600001)(356005)(2616005)(5660300002)(2906002)(8936002)(8676002)(16526019)(26005)(36860700001)(4326008)(426003)(186003)(336012)(36756003)(82310400003)(81166007)(86362001)(44832011)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 04:14:47.4505 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e5e67711-8d5d-48e5-fcbd-08d995dba696 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT063.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3790 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain The SetMemoryEncDec() is used by the higher level routines to set or clear the page encryption mask for system RAM and Mmio address. When SEV-SNP is active, in addition to set/clear page mask it also updates the RMP table. The RMP table updates are required for the system RAM address and not the Mmio address. Add a new parameter in SetMemoryEncDec() to tell whether the specified address is Mmio. If its Mmio then skip the page state change in the RMP table. Cc: Michael Roth Cc: James Bottomley Cc: Min Xu Cc: Jiewen Yao Cc: Tom Lendacky Cc: Jordan Justen Cc: Ard Biesheuvel Cc: Erdem Aktas Cc: Gerd Hoffmann Acked-by: Gerd Hoffmann Acked-by: Jiewen Yao Signed-off-by: Brijesh Singh --- .../X64/PeiDxeVirtualMemory.c | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c= b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c index 56db1e4b6ecf..0bb86d768017 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c @@ -673,6 +673,7 @@ InternalMemEncryptSevCreateIdentityMap1G ( @param[in] Mode Set or Clear mode @param[in] CacheFlush Flush the caches before applying the encryption mask + @param[in] Mmio The physical address specified is Mm= io =20 @retval RETURN_SUCCESS The attributes were cleared for the memory region. @@ -688,7 +689,8 @@ SetMemoryEncDec ( IN PHYSICAL_ADDRESS PhysicalAddress, IN UINTN Length, IN MAP_RANGE_MODE Mode, - IN BOOLEAN CacheFlush + IN BOOLEAN CacheFlush, + IN BOOLEAN Mmio ) { PAGE_MAP_AND_DIRECTORY_POINTER *PageMapLevel4Entry; @@ -711,14 +713,15 @@ SetMemoryEncDec ( =20 DEBUG (( DEBUG_VERBOSE, - "%a:%a: Cr3Base=3D0x%Lx Physical=3D0x%Lx Length=3D0x%Lx Mode=3D%a Cach= eFlush=3D%u\n", + "%a:%a: Cr3Base=3D0x%Lx Physical=3D0x%Lx Length=3D0x%Lx Mode=3D%a Cach= eFlush=3D%u Mmio=3D%u\n", gEfiCallerBaseName, __FUNCTION__, Cr3BaseAddress, PhysicalAddress, (UINT64)Length, (Mode =3D=3D SetCBit) ? "Encrypt" : "Decrypt", - (UINT32)CacheFlush + (UINT32)CacheFlush, + (UINT32)Mmio )); =20 // @@ -760,7 +763,7 @@ SetMemoryEncDec ( // // The InternalSetPageState() is used for setting the page state in the = RMP table. // - if ((Mode =3D=3D ClearCBit) && MemEncryptSevSnpIsEnabled ()) { + if (!Mmio && (Mode =3D=3D ClearCBit) && MemEncryptSevSnpIsEnabled ()) { InternalSetPageState (PhysicalAddress, EFI_SIZE_TO_PAGES (Length), Sev= SnpPageShared, FALSE); } =20 @@ -998,7 +1001,8 @@ InternalMemEncryptSevSetMemoryDecrypted ( PhysicalAddress, Length, ClearCBit, - TRUE + TRUE, + FALSE ); } =20 @@ -1031,7 +1035,8 @@ InternalMemEncryptSevSetMemoryEncrypted ( PhysicalAddress, Length, SetCBit, - TRUE + TRUE, + FALSE ); } =20 @@ -1064,6 +1069,7 @@ InternalMemEncryptSevClearMmioPageEncMask ( PhysicalAddress, Length, ClearCBit, - FALSE + FALSE, + TRUE ); } --=20 2.25.1