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.107.92.46]) by mx.groups.io with SMTP id smtpd.web09.436.1636738843835083500 for ; Fri, 12 Nov 2021 09:40:44 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=2RFBUv1v; 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.92.46, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MYUkVCVAlV/xTRBPmYg2n8ImubnqQyVWNeWJ+tFOI1dzxkTT8STk641a0rshgpUk/US3SpanVVl4eyUV/FN5yp2gEOaLAJLr79YnS9fTY35+jPySfI/oTR3l3mkkj/jARob3b1hrlxUhk5Gcbi5xenJxAHKBXBy9fs8b4zaSblAHm9HyzqgJGUCkOIT+/MKv9iveijeHvry/At5tAYkdNoNXxfkPntxdJqxUkcfDnh8Rz2DglR7XR9oHZyePa2AWwP/IggWUHfXIJ1lupgGS0Pb2s2royiEAJqUuNeBz5wZtMmh/7lMaHs5NK4xxmxjxkkXYZLZw4mNBm51WvjEtRg== 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=oCJ2h6zEekfZv8aHolcvUdAp84K55CgnRZJXv+AHsuotvkcEpjuVIL4tBAC43Z2shmY8CeWfbnUBLJvThw7x2ncuN75JOKGC3VEpL34L78m31YIi1lLFvebXdQpRsHkDANKvkSoO/spvtJZ+1ChpERFyVpujyzBqPmql8y/s+p0pOdcJNrgtSY4u7AgQksSqOAPBfp0NkQy0txYnOV4ieJkObIhiRsBS21p/ocfzKUGDm1JFXTHPARAOr7C/WNpv9xnUNwWgOIFZ9+h/ffVgDk19xRr0kufhGMIpZGu82+uCC9NKtdLPfqAhizGAWJMjD7DDGIIqhVj07hxGXFCYEw== 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=2RFBUv1vi9gyhEt0aRiqiIbM8CxeTsNvZxkxtWL7GTTyTyflBsIpVKFKR8lOhKcF5ytqz90uOHKUV9fogoBO7UhdRUPVrZpd4JYJZ8UpY+hwUpwZ6O7rYzhH3b1wD0hXKW0I06bOLstgawbFFTKiem7bPEc29kYO90PpPfh4pUI= Received: from BN6PR19CA0073.namprd19.prod.outlook.com (2603:10b6:404:133::11) by MW2PR12MB2554.namprd12.prod.outlook.com (2603:10b6:907:3::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.13; Fri, 12 Nov 2021 17:40:40 +0000 Received: from BN8NAM11FT052.eop-nam11.prod.protection.outlook.com (2603:10b6:404:133:cafe::19) by BN6PR19CA0073.outlook.office365.com (2603:10b6:404:133::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.13 via Frontend Transport; Fri, 12 Nov 2021 17:40:40 +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 BN8NAM11FT052.mail.protection.outlook.com (10.13.177.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4690.15 via Frontend Transport; Fri, 12 Nov 2021 17:40:40 +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.2375.17; Fri, 12 Nov 2021 11:40:39 -0600 From: "Brijesh Singh" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , "Michael D Kinney" , Liming Gao , Zhiguang Liu , Ray Ni , Rahul Kumar , Eric Dong , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [PATCH v13 29/32] OvmfPkg/MemEncryptSevLib: skip page state change for Mmio address Date: Fri, 12 Nov 2021 11:39:56 -0600 Message-ID: <20211112173959.2505972-30-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211112173959.2505972-1-brijesh.singh@amd.com> References: <20211112173959.2505972-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: 026edd8a-de4e-42cf-a32e-08d9a6038b69 X-MS-TrafficTypeDiagnostic: MW2PR12MB2554: 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: KvTbeJw7HNgcF6DOZBNSLneAtnAefsGmNz51DEVnLeJLAvJ7M9n20OdWNevKfI6cdIrFiG73+iDLLud865DlveeXGI1f2b/FzIHw9WUJqrJ3psnMgdicvPhhnTk3Hlhq7wnIe0EFXbQDekXFXV7OgyIsFvduk2LHX2AHC3707CskThfpoh/xxM+F0E+AsuGhYMPdSM24Pt8+uuBw7f7xQ5t0KKEZXDR985mcErGqzS42RezeDXNvHD1B0JubY5Fu0Q4QDx3Hl2aDfleLbND06WMyaOYOMaZ0HWOmcUNrFfDqACAHHlE8mWqliEU0HoBmw9Xy0koUvOjYImGlI1ffSKvyZMt99xSWLfvhOUUBlYZjGn9O+CiffjYwsLj4nAK/FMzUyLAX+SLiSCMDRxqG3hzsCd905Td4OPmlGXK9cKztkzhxB4edwYpTQN5LtIZVrfZevM3JwcoLn/Yp6sVF7hDLT4DYFWeUcDA29+94KzFgkC3sqLrpmjROvY/Jf6V21RvyRMtpDQNP+8T8OXYCk+dS8qMB1vXQ/GurxfjrN53bHpp+IgALVgtlSuVNDk1hQ6r/Li7so+e2pbdv4vj10/YvtpER1nD1RXHkCKoHKGYD+ns+91/bVWdJ85QQH0vDA//v6uMg7dWvgDH0Q6GPVi405O7IO7SWZUwxdi1cJLnx/tEDo5vn0bm4a0fklw/tqjy+n8oaSqi5xNfE5REu+WrN6nvvKcN/qS9teZ3qNBI= 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)(54906003)(7416002)(36860700001)(316002)(26005)(86362001)(6666004)(426003)(19627235002)(8676002)(336012)(8936002)(82310400003)(186003)(508600001)(16526019)(6916009)(1076003)(4326008)(36756003)(5660300002)(44832011)(7696005)(2616005)(70206006)(70586007)(2906002)(81166007)(47076005)(83380400001)(356005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2021 17:40:40.3274 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 026edd8a-de4e-42cf-a32e-08d9a6038b69 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: BN8NAM11FT052.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR12MB2554 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