From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id EFEA2941910 for ; Fri, 8 Mar 2024 15:32:45 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=VzVt5YQaTEqtzUQHSHbTTvCfotn7gdE3aJF7LIZCkvs=; c=relaxed/simple; d=groups.io; h=Received-SPF:From:To:CC:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20240206; t=1709911964; v=1; b=1OPxjnJIXLu2kYE7uRYqENpJec4p3fCFlYeimGefhxN5WYqQnfXeddG08eIktiwJpFArfaIk cxH1lGVkdxe/gSciZDClpkV/bpYfCN8cDrGhQ/MhY41L6iYtyAJ1hWNX7t9xxZ0maY2l6x5+d/5 nHB7NSIZSQ8Rg/UyGSXu7cOgLua4xU00qkHDwDstX4OVQaRzCg9W7I/iz3RAeDYWniHRt09760G VQbiQmJuXa4eHau0wfbxG4Uob11OYBYk67eZpHQlYaiEDO5MMb3JDU0KBmRfN1PwC5XqXrPwjpg 48bP4EZOnSlnQ9tAJZ0Dq10P03zcn3S4hHXzogJa2o8bQ== X-Received: by 127.0.0.2 with SMTP id DkjqYY7687511xcfjYyTwPyQ; Fri, 08 Mar 2024 07:32:44 -0800 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.40]) by mx.groups.io with SMTP id smtpd.web11.24899.1709911963998019954 for ; Fri, 08 Mar 2024 07:32:44 -0800 X-Received: from CH0PR03CA0055.namprd03.prod.outlook.com (2603:10b6:610:b3::30) by CY8PR12MB7633.namprd12.prod.outlook.com (2603:10b6:930:9c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.27; Fri, 8 Mar 2024 15:32:41 +0000 X-Received: from CY4PEPF0000E9D6.namprd05.prod.outlook.com (2603:10b6:610:b3:cafe::16) by CH0PR03CA0055.outlook.office365.com (2603:10b6:610:b3::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.48 via Frontend Transport; Fri, 8 Mar 2024 15:32:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;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; pr=C X-Received: from SATLEXMB04.amd.com (165.204.84.17) by CY4PEPF0000E9D6.mail.protection.outlook.com (10.167.241.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7362.11 via Frontend Transport; Fri, 8 Mar 2024 15:32:40 +0000 X-Received: from tlendack-t1.amdoffice.net (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.2507.35; Fri, 8 Mar 2024 09:32:39 -0600 From: "Lendacky, Thomas via groups.io" To: CC: Ard Biesheuvel , Erdem Aktas , Gerd Hoffmann , Jiewen Yao , Laszlo Ersek , Liming Gao , Michael D Kinney , Min Xu , Zhiguang Liu , "Rahul Kumar" , Ray Ni , Michael Roth Subject: [edk2-devel] [PATCH v3 22/24] UefiCpuPkg/MpInitLib: AP creation support under an SVSM Date: Fri, 08 Mar 2024 07:32:44 -0800 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000E9D6:EE_|CY8PR12MB7633:EE_ X-MS-Office365-Filtering-Correlation-Id: c5a2b1a0-d128-44c2-c85a-08dc3f84fdf4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: OHi2+lcnHumrSpBZZEZBQIrj6SluXLZQLv2jVp2Xx9RlwLkoxUKcYqVIvx7/rOgjU4+2NwNgp162/yUCBIL3Lg21IpOprYOB+FvHJQ1gu5DwnSHPq4/r1lA6GS1YhUbiaGvwEFTaFdmNawNeoO3WZLK9Oed5wRG+wm6/TipreY7TUkS6QwsDk/meAcpwPbkQQeT+2t1HjSaAoWuPyYA5+/D0LOpSKH2Vn6zwkt6KO/Pd/nNkJGprfkuYR7Eix7iL3jTntfJNyASQUXZ5Z5eO/OQ0oSK0rYNzCMqzI4lUjPwy/udx/jvgIP8Kg8RdQY3DBKZrgsGvzwTv4nvvCBDLfchzzTqqWzt3qkcrZEjvl7D7fOr31zAztJnr26IY6WdwUpNd7dkUMRr7rGkY6Eg5oflLPveAZtcpgV1OnOIqQdavHErbYh1qB0a7SuP/zK/Yn6w4AXDGk1Nqp/8tuxH9VtZ2seAQtQ//s+z6KKYIqzwaNNfWhPwECUQ5HeTT97UklWMSZTqa2QRT345NyH7YTE9/uE5BotmC8GLxgb0yHQaNdR/iEREuX080dOuN4ETB5rCpTWiV9kHW1h8NnQ0sW6+KOeWQTG2mbaoeh4Ra8MQ8xp9kSuDJyGVX+AH20uMSbrlc1uD8DwyRQq6ZkDlro/0L2ZrRi7AiC4irFaM1E0uLN2Sk2oRbqtmRA9IXA8MQnQgJe0Ml92locfjr3f+HTg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2024 15:32:40.7741 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c5a2b1a0-d128-44c2-c85a-08dc3f84fdf4 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: CY4PEPF0000E9D6.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7633 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 71TsvtzZXl1EWuLOr5DB2Ayyx7686176AA= Content-Transfer-Encoding: quoted-printable Content-Type: text/plain X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20240206 header.b=1OPxjnJI; dmarc=pass (policy=none) header.from=groups.io; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4654 When running under an SVSM, the VMPL level of the APs that are started must match the VMPL level provided by the SVSM. Additionally, each AP must have a Calling Area for use with the SVSM protocol. Update the AP creation to properly support running under an SVSM. Cc: Gerd Hoffmann Cc: Laszlo Ersek Cc: Rahul Kumar Cc: Ray Ni Acked-by: Ray Ni Acked-by: Gerd Hoffmann Signed-off-by: Tom Lendacky --- UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c | 28 +++++++++++++------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c b/UefiCpuPkg/Library= /MpInitLib/X64/AmdSev.c index 981135621384..bbdc47b5a314 100644 --- a/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c +++ b/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c @@ -44,7 +44,8 @@ SevSnpPerformApAction ( =20 if (Action =3D=3D SVM_VMGEXIT_SNP_AP_CREATE) { // - // Turn the page into a recognized VMSA page. + // Turn the page into a recognized VMSA page. When an SVSM is present + // the page following the VMSA is the Calling Area page. // VmsaStatus =3D AmdSvsmSnpVmsaRmpAdjust (SaveArea, ApicId, TRUE); if (EFI_ERROR (VmsaStatus)) { @@ -56,6 +57,7 @@ SevSnpPerformApAction ( } =20 ExitInfo1 =3D (UINT64)ApicId << 32; + ExitInfo1 |=3D (UINT64)SaveArea->Vmpl << 16; ExitInfo1 |=3D Action; ExitInfo2 =3D (UINT64)(UINTN)SaveArea; =20 @@ -87,8 +89,9 @@ SevSnpPerformApAction ( =20 if (Action =3D=3D SVM_VMGEXIT_SNP_AP_DESTROY) { // - // Make the current VMSA not runnable and accessible to be - // reprogrammed. + // Make the current VMSA not runnable and accessible to be reprogramme= d. + // When an SVSM is present the page following the VMSA is the Calling = Area + // page. // VmsaStatus =3D AmdSvsmSnpVmsaRmpAdjust (SaveArea, ApicId, FALSE); if (EFI_ERROR (VmsaStatus)) { @@ -116,6 +119,7 @@ SevSnpCreateSaveArea ( UINT32 ApicId ) { + UINTN PageCount; UINT8 *Pages; SEV_ES_SAVE_AREA *SaveArea; IA32_CR0 ApCr0; @@ -125,13 +129,19 @@ SevSnpCreateSaveArea ( UINTN StartIp; UINT8 SipiVector; =20 + // + // When running under an SVSM, a Calling Area page is also needed and is + // always the page following the VMSA. + // + PageCount =3D AmdSvsmIsSvsmPresent () ? 2 : 1; + if (CpuData->SevEsSaveArea =3D=3D NULL) { // // Allocate a page for the SEV-ES Save Area and initialize it. Due to = AMD // erratum #1467 (VMSA cannot be on a 2MB boundary), allocate an extra= page // to choose from to work around the issue. // - Pages =3D AllocateReservedPages (2); + Pages =3D AllocateReservedPages (PageCount + 1); if (!Pages) { return; } @@ -140,12 +150,12 @@ SevSnpCreateSaveArea ( // Since page allocation works by allocating downward in the address s= pace, // try to always free the first (lower address) page to limit possible= holes // in the memory map. So, if the address of the second page is 2MB ali= gned, - // then use the first page and free the second page. Otherwise, free t= he + // then use the first page and free the last page. Otherwise, free the // first page and use the second page. // if (_IS_ALIGNED (Pages + EFI_PAGE_SIZE, SIZE_2MB)) { SaveArea =3D (SEV_ES_SAVE_AREA *)Pages; - FreePages (Pages + EFI_PAGE_SIZE, 1); + FreePages (Pages + (EFI_PAGE_SIZE * PageCount), 1); } else { SaveArea =3D (SEV_ES_SAVE_AREA *)(Pages + EFI_PAGE_SIZE); FreePages (Pages, 1); @@ -163,7 +173,7 @@ SevSnpCreateSaveArea ( } } =20 - ZeroMem (SaveArea, EFI_PAGE_SIZE); + ZeroMem (SaveArea, EFI_PAGE_SIZE * PageCount); =20 // // Propogate the CR0.NW and CR0.CD setting to the AP @@ -239,10 +249,10 @@ SevSnpCreateSaveArea ( =20 // // Set the SEV-SNP specific fields for the save area: - // VMPL - always VMPL0 + // VMPL - based on current mode // SEV_FEATURES - equivalent to the SEV_STATUS MSR right shifted 2 bit= s // - SaveArea->Vmpl =3D 0; + SaveArea->Vmpl =3D AmdSvsmSnpGetVmpl (); SaveArea->SevFeatures =3D AsmReadMsr64 (MSR_SEV_STATUS) >> 2; =20 SevSnpPerformApAction (SaveArea, ApicId, SVM_VMGEXIT_SNP_AP_CREATE); --=20 2.43.2 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#116547): https://edk2.groups.io/g/devel/message/116547 Mute This Topic: https://groups.io/mt/104810744/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-