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 0AA7A94195D for ; Fri, 8 Mar 2024 15:32:38 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=thay0lqXqwYKBTAFgHXb80aDJaJWmVHdkwZKM0jtFnU=; 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=1709911957; v=1; b=0ju8CFCFVCGuxWLpq2DGWBiZ35olqDMTKfDFa8+qludmvnE1ogQoNPAQVcWZRNfCmQtadNe2 AY5ePvIlfCQkzhXxN0VI+rCcm7eSzZFLouep7EAdCz/R6aowBc3xGPykchyZ6V3Eg3W40EBvtDO twhVcvWoXlao8mGjK6+5xyBL1iXSzTz88sF6xYlkqQzup6pBKIqlRqia086D/vusBKx3sdOxcaH Wub6bGJLdYkG56VMMhSUiIq02nTz1A7JMTFKRQ2VrqpuKkh2p3gtUDF7nOglt7bAw7pEoEqAxug u1qM91f4EapRKL0PjlEoYqFkhG9U1sA0RSTxMUop5jlkA== X-Received: by 127.0.0.2 with SMTP id r6unYY7687511xIMDlGtg0cU; Fri, 08 Mar 2024 07:32:37 -0800 X-Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.78]) by mx.groups.io with SMTP id smtpd.web11.24894.1709911957061846119 for ; Fri, 08 Mar 2024 07:32:37 -0800 X-Received: from CYXPR02CA0010.namprd02.prod.outlook.com (2603:10b6:930:cf::21) by BY5PR12MB4177.namprd12.prod.outlook.com (2603:10b6:a03:201::14) 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:34 +0000 X-Received: from CY4PEPF0000E9D5.namprd05.prod.outlook.com (2603:10b6:930:cf:cafe::31) by CYXPR02CA0010.outlook.office365.com (2603:10b6:930:cf::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7362.27 via Frontend Transport; Fri, 8 Mar 2024 15:32:33 +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 CY4PEPF0000E9D5.mail.protection.outlook.com (10.167.241.76) 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:33 +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:32 -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 21/24] OvmfPkg/AmdSvsmLib: Add support for the SVSM create/delete vCPU calls Date: Fri, 08 Mar 2024 07:32:37 -0800 Message-ID: <03d4df5ca93ee29055829d01283b45bfc520f3d1.1709911792.git.thomas.lendacky@amd.com> 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: CY4PEPF0000E9D5:EE_|BY5PR12MB4177:EE_ X-MS-Office365-Filtering-Correlation-Id: d8f77b04-09e5-42c7-4f97-08dc3f84f9c0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Message-Info: +HBZM8VeI407R8tCI/wMxwQFFwGYV/tjLsP/LO+AnM78e8T2jYxAPc2CzfXvxkMuBLik6USMQuI7kC5J80Rpz6YyIEvSuvKyAFUkBxj26xVPSx9it3eRcINwrjV8Un29wghYBoqtOmTvys3jjWB8WcCdA+QNErGfqa3VoO7dNDuJDSEDaiAhtQhmnV4ygVibUN49q6wg/E7LybSMjcK55IqLm6zCaNjVq2kgimUwXV0onW5RVRlL907bV2jpGC5JzMFq3vcO8myf0JL1DXA/CWz9SuU1RIO2HqeXuhcwKnRQURY9KDRdqq1Xl9nYDD2pdm5OH3cPRkISctV4r8PI37jp1CCKG8XeUtLCfg20c5HFZlVh0CXIVyxFsVnQQpTyQtwf4DwNBApcGLWXCfFLBnl2t5ePfRitnpvzqm0+iDZ4tpI69hY0zJMIuP9rNQL/qPeAo2tZ+zUVi4IRTX8NjSvH0QJiMGpXPwOsCHfE5lRjcI0ZfjPaYAI3LXyvP2Q8lRfnalr9+eTAWl7M3VrEiInY6qPEl2Mih7PLd2pLkdS6k0LznVjR7pzcA+2gVVdmOJmUnpJje+MpCheOJ+TL2OuAuGptSeJHL/QQPCr2mBLgefNAsq9luPGOyH6n28UIAvDgttKI8H8dk0jVKpXiq9gFkW6yuOsYDC0VMJLZgeRewXA9AEvadtvjpRaSUdOXyia7k0W1sJmeBSqnSNn1jg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Mar 2024 15:32:33.6880 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d8f77b04-09e5-42c7-4f97-08dc3f84f9c0 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: CY4PEPF0000E9D5.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4177 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: MnVUVZbbFOywaN2mwcQGew4ix7686176AA= 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=0ju8CFCF; 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 The RMPADJUST instruction is used to alter the VMSA attribute of a page, but the VMSA attribute can only be changed when running at VMPL0. When an SVSM is present, use the SVSM_CORE_CREATE_VCPU and SVSM_CORE_DELTE_VCPU calls to add or remove the VMSA attribute on a page instead of issuing the RMPADJUST instruction directly. Implement the AmdSvsmSnpVmsaRmpAdjust() API to perform the proper operation to update the VMSA attribute. Cc: Ard Biesheuvel Cc: Gerd Hoffmann Cc: Jiewen Yao Cc: Laszlo Ersek Acked-by: Gerd Hoffmann Signed-off-by: Tom Lendacky --- OvmfPkg/Library/AmdSvsmLib/AmdSvsmLib.c | 54 +++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/Library/AmdSvsmLib/AmdSvsmLib.c b/OvmfPkg/Library/AmdS= vsmLib/AmdSvsmLib.c index fb3fda70e948..6c79ee7d916b 100644 --- a/OvmfPkg/Library/AmdSvsmLib/AmdSvsmLib.c +++ b/OvmfPkg/Library/AmdSvsmLib/AmdSvsmLib.c @@ -377,6 +377,57 @@ AmdSvsmSnpPvalidate ( AmdSvsmIsSvsmPresent () ? SvsmPvalidate (Info) : BasePvalidate (Info); } =20 +/** + Perform an RMPADJUST operation to alter the VMSA setting of a page. + + Add or remove the VMSA attribute for a page. + + @param[in] Vmsa Pointer to an SEV-ES save area page + @param[in] ApicId APIC ID associated with the VMSA + @param[in] SetVmsa Boolean indicator as to whether to set o= r + or clear the VMSA setting for the page + + @retval EFI_SUCCESS RMPADJUST operation successful + @retval EFI_UNSUPPORTED Operation is not supported + @retval EFI_INVALID_PARAMETER RMPADJUST operation failed, an invalid + parameter was supplied + +**/ +STATIC +EFI_STATUS +SvsmVmsaRmpAdjust ( + IN SEV_ES_SAVE_AREA *Vmsa, + IN UINT32 ApicId, + IN BOOLEAN SetVmsa + ) +{ + SVSM_CALL_DATA SvsmCallData; + SVSM_FUNCTION Function; + UINTN Ret; + + SvsmCallData.Caa =3D (SVSM_CAA *)AmdSvsmSnpGetCaa (); + + Function.Id.Protocol =3D 0; + + if (SetVmsa) { + Function.Id.CallId =3D 2; + + SvsmCallData.RaxIn =3D Function.Uint64; + SvsmCallData.RcxIn =3D (UINT64)(UINTN)Vmsa; + SvsmCallData.RdxIn =3D (UINT64)(UINTN)Vmsa + SIZE_4KB; + SvsmCallData.R8In =3D ApicId; + } else { + Function.Id.CallId =3D 3; + + SvsmCallData.RaxIn =3D Function.Uint64; + SvsmCallData.RcxIn =3D (UINT64)(UINTN)Vmsa; + } + + Ret =3D SvsmMsrProtocol (&SvsmCallData); + + return (Ret =3D=3D 0) ? EFI_SUCCESS : EFI_INVALID_PARAMETER; +} + /** Perform a native RMPADJUST operation to alter the VMSA setting of a page= . =20 @@ -444,5 +495,6 @@ AmdSvsmSnpVmsaRmpAdjust ( IN BOOLEAN SetVmsa ) { - return BaseVmsaRmpAdjust (Vmsa, SetVmsa); + return AmdSvsmIsSvsmPresent () ? SvsmVmsaRmpAdjust (Vmsa, ApicId, SetVms= a) + : BaseVmsaRmpAdjust (Vmsa, SetVmsa); } --=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 (#116546): https://edk2.groups.io/g/devel/message/116546 Mute This Topic: https://groups.io/mt/104810739/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-