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.40]) by mx.groups.io with SMTP id smtpd.web08.6787.1639020518851867678 for ; Wed, 08 Dec 2021 19:28:39 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=kwl8jKxs; 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.40, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hgK8tcWfQ5E37N7/qDLB+lwY/3cAMnBBRvtVjGLUDgelJXWo3eQ9N6eUipSclRumL4YtloBot2xcx5AisFIK6W6pYtDCGjcD4mI7VaQ+W5Aky6emHpVBLF4dStQfaeNtsl0YxnHh/eyVwyCjDM157/zvboarSimYFwNSkQVKPkAegsh36Lai6gnYYdojyQDSJTZJSb8NwzxmbzWeXgH1AkO4DF95C1RGFW19ujnqZFThxa8haM5GyUzssxEQwsGMobgP2sfZoBtY9Gsp6PdqbSRDFU49mZHewSG8Q9rfwiWLLw1pr6GEmrxSpHewN49A65nDGKCewo6BH/MRpZb3yA== 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=el/WEuoKDl//KHbz1kXl7a/KRU4s9V+K3LPpbeEJmMM=; b=NTss+HuTJrRyz3c8q3wZJzzelOCmVaJS1VDSC1Xd7J6ZwERtSkk9/05ee0XybRUecpuGkIIRV0GLg3b+IPQ/PnEOFk8iexT+1phJzeYyrpoY8Fb4rOMerZ8aXeDRMygMefB42FCYqA99N6XNObQGMQIragKi4VPZhPxKogJJ2F2uBtKDc21t9uKgEOrTFE29YccFaTNDekrQIh6r1GPdjR2mUWWJpl2l3XnLImnWXzdJZ4LI4l27SCqVhFwOPLdiBqdOhbuEzANJflgFJdDO2hxOh0+UmOkPxiEgkPXu4rkMWKEo28CeEnsfhOPQyXY1xV8gpreCvi+UoDl4JrRdxw== 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=el/WEuoKDl//KHbz1kXl7a/KRU4s9V+K3LPpbeEJmMM=; b=kwl8jKxsxayAPMkgUxpsiBmfRIXi1t4jcXrMl/mLL48hPOst7k5T0BhwufVzCL3qkR39geXhe4OTsDrT6qS0HwwjXxbAhGcH1VmVSCMtgsdkOL1SffGLBnrBYjuruW0DfELg8s1GYIm8TKMmiOjEh7bRBSlTUWw96nFFojbzGKY= Received: from MWHPR07CA0014.namprd07.prod.outlook.com (2603:10b6:300:116::24) by MWHPR12MB1726.namprd12.prod.outlook.com (2603:10b6:300:110::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.21; Thu, 9 Dec 2021 03:28:35 +0000 Received: from CO1NAM11FT048.eop-nam11.prod.protection.outlook.com (2603:10b6:300:116:cafe::dc) by MWHPR07CA0014.outlook.office365.com (2603:10b6:300:116::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.20 via Frontend Transport; Thu, 9 Dec 2021 03:28:35 +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=SATLEXMB03.amd.com; Received: from SATLEXMB03.amd.com (165.204.84.17) by CO1NAM11FT048.mail.protection.outlook.com (10.13.175.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4755.13 via Frontend Transport; Thu, 9 Dec 2021 03:28:34 +0000 Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Wed, 8 Dec 2021 21:28:30 -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 v14 12/32] OvmfPkg/PlatformPei: register GHCB gpa for the SEV-SNP guest Date: Wed, 8 Dec 2021 21:27:40 -0600 Message-ID: <20211209032800.3802995-13-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211209032800.3802995-1-brijesh.singh@amd.com> References: <20211209032800.3802995-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 SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8313fb04-762a-4b7d-334b-08d9bac3fb7b X-MS-TrafficTypeDiagnostic: MWHPR12MB1726:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Wel8I+TSPcBKw+P2+iuK3Vuw4v6jlImp2aLNlHcu7c18d+j1Z4T5uAhQVzNltJkwhKXJVEjkFYjv5EKsVgzZZlLCB5mSpUDR1UR9jx7A0ZqEw06IrP7nS1JnR+PBoAHrHraUe24uwfWWg3urzJexMdPc5zl1PLD8znjrfYJZKfbJnnHL/xITTs4bacBCQ/mldu2mS4yKBIyD/g3dhFjlqt6WAEK2oZY93x7KVeizhkJvxcj2QrrVR8WbxGrbR7z29Uhb3wbhfl1BUqIUI5zdC2xJP3w7jktRmo89OqWnFhqhfY9iz7iiimQJQ7ClbhcQLuqaTCZUqfEnqrXS/wnVWWeGXoe9vOXYOKOeTt9UOSfaViwBiwpY1S6vzvGrisqsyJUkUTBHSjl1VnsLzojoCm0xjdf3Xp/xYUI3hu8I4DYeZOARDj8WtRhUuw5Yp9FokyiRdctr5maBVxQK3CYRAMlYTw8xCdatgvFO96Rtd8VRXUcuPS0afKVJRW8PI1JVwqVpXnn9u3U61K+VoF2jrP/QzPlhdXNboQNuZMGkYAyAA70bkg7zogl8JG9DOg9ZU7ccAwUgQvA+VQbgQiT9SNMeou7UTORkm/qglGTwGpKRzQRiNYOeHLVELu80alzcT2VfkEREOSIh+ukBJGPdWM8gX+8IGjTGh3jJZcgoCVtoSLSscpCLeTG3ksEsfcR9UJ0z+nu9vyTXn3NkvR/zfxHFCgeLhcshC95w5Fnjnd9YuwVOOw3V/k0FZ0SxGmLKnmZogAaWlwl+mY2mTRTnrKPokbsPJaltZhFYs1yymzgLWgxUtHX4Iw2BaQ5eZk5Sh50LnwrcSL2y5ZxsSaxjPSj7t756X7YN1lrgS/7Mv11yG8ZylFaTy9izdhMS/Wph X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(40470700001)(81166007)(40460700001)(186003)(4326008)(16526019)(36860700001)(6666004)(426003)(26005)(7416002)(83380400001)(47076005)(966005)(82310400004)(356005)(44832011)(316002)(36756003)(70206006)(5660300002)(336012)(54906003)(6916009)(70586007)(508600001)(8936002)(1076003)(2906002)(86362001)(8676002)(2616005)(7696005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2021 03:28:34.8633 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8313fb04-762a-4b7d-334b-08d9bac3fb7b 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=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT048.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1726 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3275 The SEV-SNP guest requires that GHCB GPA must be registered before using. See the GHCB specification section 2.3.2 for more details. 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 --- OvmfPkg/PlatformPei/AmdSev.c | 88 ++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index 3991edfd1e82..f66e0a7f4a10 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -19,9 +19,90 @@ #include #include #include +#include =20 #include "Platform.h" =20 +/** + Handle an SEV-SNP/GHCB protocol check failure. + + Notify the hypervisor using the VMGEXIT instruction that the SEV-SNP gue= st + wishes to be terminated. + + @param[in] ReasonCode Reason code to provide to the hypervisor for the + termination request. + +**/ +STATIC +VOID +SevEsProtocolFailure ( + IN UINT8 ReasonCode + ) +{ + MSR_SEV_ES_GHCB_REGISTER Msr; + + // + // Use the GHCB MSR Protocol to request termination by the hypervisor + // + Msr.GhcbPhysicalAddress =3D 0; + Msr.GhcbTerminate.Function =3D GHCB_INFO_TERMINATE_REQUEST; + Msr.GhcbTerminate.ReasonCodeSet =3D GHCB_TERMINATE_GHCB; + Msr.GhcbTerminate.ReasonCode =3D ReasonCode; + AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress); + + AsmVmgExit (); + + ASSERT (FALSE); + CpuDeadLoop (); +} + +/** + + This function can be used to register the GHCB GPA. + + @param[in] Address The physical address to be registered. + +**/ +STATIC +VOID +GhcbRegister ( + IN EFI_PHYSICAL_ADDRESS Address + ) +{ + MSR_SEV_ES_GHCB_REGISTER Msr; + MSR_SEV_ES_GHCB_REGISTER CurrentMsr; + + // + // Save the current MSR Value + // + CurrentMsr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + + // + // Use the GHCB MSR Protocol to request to register the GPA. + // + Msr.GhcbPhysicalAddress =3D Address & ~EFI_PAGE_MASK; + Msr.GhcbGpaRegister.Function =3D GHCB_INFO_GHCB_GPA_REGISTER_REQUEST; + AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress); + + AsmVmgExit (); + + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + + // + // If hypervisor responded with a different GPA than requested then fail= . + // + if ((Msr.GhcbGpaRegister.Function !=3D GHCB_INFO_GHCB_GPA_REGISTER_RESPO= NSE) || + ((Msr.GhcbPhysicalAddress & ~EFI_PAGE_MASK) !=3D Address)) + { + SevEsProtocolFailure (GHCB_TERMINATE_GHCB_GENERAL); + } + + // + // Restore the MSR + // + AsmWriteMsr64 (MSR_SEV_ES_GHCB, CurrentMsr.GhcbPhysicalAddress); +} + /** =20 Initialize SEV-ES support if running as an SEV-ES guest. @@ -115,6 +196,13 @@ AmdSevEsInitialize ( GhcbBackupBase )); =20 + // + // SEV-SNP guest requires that GHCB GPA must be registered before using = it. + // + if (MemEncryptSevSnpIsEnabled ()) { + GhcbRegister (GhcbBasePa); + } + AsmWriteMsr64 (MSR_SEV_ES_GHCB, GhcbBasePa); =20 // --=20 2.25.1