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 B480E941BBD for ; Fri, 26 Jan 2024 22:15:17 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=tUG1JUq5xU3ePcW1OrYrKebSJ6z4UOUFUItfjkFKZHk=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results: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=20140610; t=1706307316; v=1; b=hORCs3Qqjazh9PBrFSRLbsotMfhk0mMThZpqfzI0yYtwCOChx4D2ALM1DMAByKX+t4/zkum5 xk+jQGjnJVtKpZ+JFeTLF4httd8nZqFd8H5uBqAahf/c3AxkVDmQJ7t62bbLqkar56bOeFGTvZ/ 64x4F8ybwMG1cLroIHPG65rQ= X-Received: by 127.0.0.2 with SMTP id OBWqYY7687511xdXK2BbrQ2v; Fri, 26 Jan 2024 14:15:16 -0800 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.81]) by mx.groups.io with SMTP id smtpd.web10.2903.1706307315827846235 for ; Fri, 26 Jan 2024 14:15:15 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HYVyIFvlWuwMFi/Wp4Kb8bHZYZod7OOOryoYxtvAECfmbNduVIx8vym1ghB4h9aChP7Det+zqZAx9jRMMZh7+xb7HUzvrXCVDvtkem+2KCA5vKjzFmLC0tDnYDjOmmH0aVm1H3nirMh5c9ToxeeAMk24HQPJ42jskYWsT8qvkYni50GJHZt7txGb5eklGDKefShhghEaHpwJ3ojO091/yOS9CXcmzmq+aqXlO7IQB1ygradvow3sId7FNkmgTsbtcl9d3TIeSxW8xtANOnX0FNrTVDIbswpKVFZm2E9tFZaLdyYZ3hVDUnzFp9I9Y/Trqs/9niHFCskbn4eqAAHE/A== 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=5VBpusCbGYtPmbKzIMXKNmJrFasYclLsstgXtYgu+So=; b=hn/tCu2QrZnCzHN+C01Jb6nAB37IYxdSYDDX6iSZD0pFRMMgx3KSIc67AtotoBM9lmckWU8s382jzc98lG1c7m/YFdnnfnwrl7uNOvRZQQSBN60o1mtVDoX1CrmM6mBsuGGi4hN676Ld2vqr16/0wco1f+unl7HwyHdTOQiUwaSHvT17Hl10ceRFh/p/Q3QrOVz2Bi9xmPBYoPpng3jeknbVp6fRRgX7KgLvhsTOC4R8sDT+VwKFqFSXXwk99y8Vm+EaDuEoMHddscHQTztuNR9M9O3qcobaHXf8UB86EvMYsEErzh5LjUH7fsDyj8+HWpTLlHkVDY6KOdWXrN39NQ== 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 (0) X-Received: from DS7PR05CA0047.namprd05.prod.outlook.com (2603:10b6:8:2f::26) by PH7PR12MB6810.namprd12.prod.outlook.com (2603:10b6:510:1b4::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.27; Fri, 26 Jan 2024 22:15:11 +0000 X-Received: from DS1PEPF00017091.namprd03.prod.outlook.com (2603:10b6:8:2f:cafe::15) by DS7PR05CA0047.outlook.office365.com (2603:10b6:8:2f::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.15 via Frontend Transport; Fri, 26 Jan 2024 22:15:11 +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 DS1PEPF00017091.mail.protection.outlook.com (10.167.17.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7202.16 via Frontend Transport; Fri, 26 Jan 2024 22:15:11 +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.34; Fri, 26 Jan 2024 16:15:09 -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 14/16] UefiCpuPkg/MpInitLib: AP creation support under an SVSM Date: Fri, 26 Jan 2024 16:13:13 -0600 Message-ID: In-Reply-To: References: MIME-Version: 1.0 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-TrafficTypeDiagnostic: DS1PEPF00017091:EE_|PH7PR12MB6810:EE_ X-MS-Office365-Filtering-Correlation-Id: fdb67c06-4747-4969-bada-08dc1ebc434c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: 6il1svhPHLqzZLb1y276TfIWN2/g3IsPGQaApOseFrpUn8j00P4z04gBUN0KYrDuuSH/2cDpQDEVu64GzJaSVF49NMEexJkBSnCW+g+0sKGDJYcOGnS0XIXPuLAMqDHS8sedLh8g9MZqfdJ8BdnKgOxx57JqgVzf8ljNaASHTT+sMclGtymCMTQteamG2xAs+4fBwtwpu/MqU5qYYVdmvo+qnO7uBEhNKT+4Kv8okA0sbOL2btzk8CwggGUhp8nTBn2hqy74JHdRq+f/OMuw6DvgXQCEn4xDK5c7xCgAF6QlDs9pnL8RVwdzK8Cx8+ROwLzsoKnxcfbbNQUTHaNlr47u5YA5yPZm5AFbA5a7hse+cC6aQfilQMrIKDw5Q3e9OxhWY2HOlD0tOTbRbVQrQ4luIkdmKO3xvmzhp/tXb61zA8cCEsP8/uSUI3nUe5I4AqNp+9n5jy9yS0GXFf7EOgo5olpolYYTNLZQNqlfGCWmdIKlCRmnmPbLswmklTE04an/Bi8vVgfOnV+C5XyGHDqZMQz4LdRdXcEW9ET6JMRdj9pttZIBrvf+MjURHpJHpSxWSfX5M9TYUHOPl0JkxgkjvNQ0vyOYfhDbRY/Q4H6RRmHSSVg/j0nSlubls7gCwh8J9bwf/AQFYSQDq0P0PoEIThqP/dX1PljCftKLGWMaJ8PVkadyQFSzheW0etqe1W0uBeVIzlYJBRHgI4o/+ZPDVSnBNEAcPGljI1XleBlV4VLZGBTWlmrdMHVmjm9ceLKHRGzwp7nDCTk/wn8tDw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2024 22:15:11.0617 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fdb67c06-4747-4969-bada-08dc1ebc434c 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: DS1PEPF00017091.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB6810 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: 1AvFLyBjdsEzC5MXL94WYhdDx7686176AA= 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=20140610 header.b=hORCs3Qq; dmarc=none; 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. Signed-off-by: Tom Lendacky --- UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c b/UefiCpuPkg/Library= /MpInitLib/X64/AmdSev.c index 6186a8d71521..9b00c945e13d 100644 --- a/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c +++ b/UefiCpuPkg/Library/MpInitLib/X64/AmdSev.c @@ -55,6 +55,7 @@ SevSnpPerformApAction ( } =20 ExitInfo1 =3D (UINT64)ApicId << 32; + ExitInfo1 |=3D (UINT64)SaveArea->Vmpl << 16; ExitInfo1 |=3D Action; ExitInfo2 =3D (UINT64)(UINTN)SaveArea; =20 @@ -115,6 +116,7 @@ SevSnpCreateSaveArea ( UINT32 ApicId ) { + UINTN PageCount; UINT8 *Pages; SEV_ES_SAVE_AREA *SaveArea; IA32_CR0 ApCr0; @@ -124,13 +126,18 @@ SevSnpCreateSaveArea ( UINTN StartIp; UINT8 SipiVector; =20 + // + // When running under an SVSM, a Calling Area page is also needed + // + PageCount =3D CcExitSnpSvsmPresent () ? 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; } @@ -139,12 +146,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); @@ -162,7 +169,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 @@ -238,10 +245,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 CcExitSnpGetVmpl (); SaveArea->SevFeatures =3D AsmReadMsr64 (MSR_SEV_STATUS) >> 2; =20 SevSnpPerformApAction (SaveArea, ApicId, SVM_VMGEXIT_SNP_AP_CREATE); --=20 2.42.0 -=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 (#114640): https://edk2.groups.io/g/devel/message/114640 Mute This Topic: https://groups.io/mt/103986475/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-