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.107.243.62]) by mx.groups.io with SMTP id smtpd.web10.2757.1634962490315290061 for ; Fri, 22 Oct 2021 21:14:50 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=eLSWamoo; 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.243.62, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O3XmZvIpmjJNcCDtGuC99xuYq2JVIlmEn09x5yNy3+mwzLWDmSXDocvoSr/kKE9KPbt30tZJMgVimACmaTezbb8r2/0Uq6L2wbYNb3KG5IMfY9ZKRlMQKAd0XhF/X1hFJwGA35GnE4YA49ktozTWyvDr9VoRwUWYKbi2gnpw12odFitGWC6TyxipGumnMR4Hq+8p1tClWZSZQ2yqPhFHT4Q+mTA9YRZiG1jBAxETwI8sCXUgNpHCSlBQA+a2vQ8wyzDpB+Sw6t9GAJ4HPg3HKwrgCjBkSaBol/2DQCZMF9Bz0eETOFozyJm7n3WE/5VKQtedoX1PChKVh46YNucCrQ== 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=AAcfYlxvUwlQEaM0iBzjpB3n0oarjVEg++IMGJfyqoo=; b=m9LLfKoh/r8Am4gHPSd9RkqG8OyySrauZ3RnmAFD4aibe45jn8pwDIrczTWKBFBT/zILE1j15ZC3GbJ/z4ODDB1HXAUTj+hR+P6cnvsLc2/G14sAMDttqKQnin4vzPBhQ5tYhjb2NAsC2niUCU0Gza6uHXKjpJ2AYvqMlQ2P8By3Jy7ef4XrMTenA0CgH0PqgTzPNRaul6MWg3H40A4ZTr2lFY/pqlA4t6s4bsnBYWi9vG+uuzWDG+hsnztbHxjVg3e/gqyJW17XFd89SexmIqBZIPIbx6urDf5//lgHHxxMuL3BZFMRLM7TRMgUqs6L9ND/mRwMIrwB/m4N5ymr8w== 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=AAcfYlxvUwlQEaM0iBzjpB3n0oarjVEg++IMGJfyqoo=; b=eLSWamooA2z1/CoqEFNWP6iLZpAJT4HIPjwck9+7F8beAfsbgyiWacVvp1kgXMyh/DB/oNfvrywUBs9juR6o3gSCl9BP164TPEJpZxBxUVjECuA/raH0k9/M2fleDmt7EOz9/WACkynG8JyDuVygY9gIxJqYvKCBvuiLltJ1ORk= Received: from BN6PR2001CA0034.namprd20.prod.outlook.com (2603:10b6:405:16::20) by PH0PR12MB5467.namprd12.prod.outlook.com (2603:10b6:510:e6::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.18; Sat, 23 Oct 2021 04:14:47 +0000 Received: from BN8NAM11FT063.eop-nam11.prod.protection.outlook.com (2603:10b6:405:16:cafe::70) by BN6PR2001CA0034.outlook.office365.com (2603:10b6:405:16::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4628.15 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:46 +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:42 -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 28/32] OvmfPkg/MemEncryptSevLib: change the page state in the RMP table Date: Fri, 22 Oct 2021 23:13:45 -0500 Message-ID: <20211023041349.1263726-29-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: 7b759efb-6027-402e-0e99-08d995dba627 X-MS-TrafficTypeDiagnostic: PH0PR12MB5467: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eqKVC5Y9OPQGhpq877pI/tF46naKgi2N1r7YFS1vSq8TIsx2qAAIuMnt/LkdQbV3v1XC/kjjBG9plBym9F8ZmrrfksIF5yW9EB0ySkSXpZginFgHtut10LzgLPyFPybYzNkG7VfcOf64W3c9ku2vmVS4w2G1tDLW1y0RZIjAEA/h5TCgqCtuPM2bD3wocqKMnvLrCO/oSannVuILz+cH8CNeFiuzO1Qb7cD5le+2hEb8ns7nSkEbdXmp1J1UR+Sv6VEVVuuzaPcBjyARy+8Ayw/83B5jAVfUIMAKb4fuqig9TTT/yg5eNezLZCpD5aR1/HdUHfGfbZJTroXuutLQsVBH95JF/MWrlBFti1i5Hs/Ped30L3eS3gIdkWbcv/hWNbpcZjbUjj79YdcGwpRuGsY9JvLJo8otHpPhhIJg9vbOrCfN9GoZvvaZo4KBC+Jl7vFDEmsZdii87KFbPxIgS+lKUqrNac1NLDM0IM69cE3Vb4iwHDbDy9iMbiRJPz0WeeIg3W58ld8dxTCm+Kwv2pAK/Yg10UbtqvR9TZIJGYSumNTVbyjKw8dHIHe9LO7oGuz1jgpyxOHeeiKopGUPJRrJ6G2hUAMH7tud9he+zzP5MwzYg3Jb41t1dhOQMjLDb+0GSqzutk9f+5YJwaK9uLPuI1rJ/Gig0JzvX2m3u7tk46iMgVfILEypNqn2PEwqQJ4YbiTd5RPvNB0AzlwQ4bRNBgbDHO3V5lBYA4bRPXCzZmbRF0xhkib+fvw0wrDuhazQBxBf0q3t3ggYnNDoTwwM0LcuKsTnF2wP/QDoz0CAGrfHPA3KltIxGvCX6aN8 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)(36840700001)(46966006)(70586007)(426003)(70206006)(8936002)(2906002)(4326008)(2616005)(19627235002)(7696005)(26005)(44832011)(8676002)(336012)(966005)(54906003)(36860700001)(5660300002)(316002)(16526019)(6916009)(508600001)(186003)(82310400003)(81166007)(83380400001)(47076005)(356005)(86362001)(1076003)(36756003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2021 04:14:46.7160 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7b759efb-6027-402e-0e99-08d995dba627 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: PH0PR12MB5467 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 The MemEncryptSev{Set,Clear}PageEncMask() functions are used to set or clear the memory encryption attribute in the page table. When SEV-SNP is active, we also need to change the page state in the RMP table so that it is in sync with the memory encryption attribute change. 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: Jiewen Yao Acked-by: Gerd Hoffmann Signed-off-by: Brijesh Singh --- .../X64/PeiDxeVirtualMemory.c | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c= b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c index f146f6d61cc5..56db1e4b6ecf 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/X64/PeiDxeVirtualMemory.c @@ -17,6 +17,7 @@ #include =20 #include "VirtualMemory.h" +#include "SnpPageStateChange.h" =20 STATIC BOOLEAN mAddressEncMaskChecked =3D FALSE; STATIC UINT64 mAddressEncMask; @@ -695,10 +696,12 @@ SetMemoryEncDec ( PAGE_MAP_AND_DIRECTORY_POINTER *PageDirectoryPointerEntry; PAGE_TABLE_1G_ENTRY *PageDirectory1GEntry; PAGE_TABLE_ENTRY *PageDirectory2MEntry; + PHYSICAL_ADDRESS OrigPhysicalAddress; PAGE_TABLE_4K_ENTRY *PageTableEntry; UINT64 PgTableMask; UINT64 AddressEncMask; BOOLEAN IsWpEnabled; + UINTN OrigLength; RETURN_STATUS Status; =20 // @@ -751,6 +754,22 @@ SetMemoryEncDec ( =20 Status =3D EFI_SUCCESS; =20 + // + // To maintain the security gurantees we must set the page to shared in = the RMP + // table before clearing the memory encryption mask from the current pag= e table. + // + // The InternalSetPageState() is used for setting the page state in the = RMP table. + // + if ((Mode =3D=3D ClearCBit) && MemEncryptSevSnpIsEnabled ()) { + InternalSetPageState (PhysicalAddress, EFI_SIZE_TO_PAGES (Length), Sev= SnpPageShared, FALSE); + } + + // + // Save the specified length and physical address (we need it later). + // + OrigLength =3D Length; + OrigPhysicalAddress =3D PhysicalAddress; + while (Length !=3D 0) { // @@ -923,6 +942,21 @@ SetMemoryEncDec ( // CpuFlushTlb(); =20 + // + // SEV-SNP requires that all the private pages (i.e pages mapped encrypt= ed) must be + // added in the RMP table before the access. + // + // The InternalSetPageState() is used for setting the page state in the = RMP table. + // + if ((Mode =3D=3D SetCBit) && MemEncryptSevSnpIsEnabled ()) { + InternalSetPageState ( + OrigPhysicalAddress, + EFI_SIZE_TO_PAGES (OrigLength), + SevSnpPagePrivate, + FALSE + ); + } + Done: // // Restore page table write protection, if any. --=20 2.25.1