From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.71]) by mx.groups.io with SMTP id smtpd.web10.391.1636738831228789848 for ; Fri, 12 Nov 2021 09:40:31 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=t+zCHmff; 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.236.71, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=axVBAJ/sxa6WNAMPi0Vf3VvsEOcrtai2SB4ZHTbZNY9O0DQ5tjiYsi1LI/tC2lypXzMzjtp1XqFMr3xIoXXNqwwKlgAR1OWCDXz2B+A/WVwEnf0sxpb0ocsaS2tsCveyA7bKNSrcKxvNIsyrdyovLLPwJa+/E5tA3PrqZrjUd9OHH45kWuvQgW1894695K/w6oNzGSsMokcab1wyTID2KN77pDHTqX3kmo+K9/UM8hFqhdSVacwmXg3dcQxE5clZ4ylW+Lthxc+RvEitni3Lqk06wQ74t/U2fzzdVf3HSncITxkEJkauztD6k9GJudzf0Ht9Xl+bTet/sZ1eJp2m5A== 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=BwmJhnqvTds5tO5aEnJH3O/TNjCJ5n+UJoYRfAP85j0=; b=ZxvoiUfOI4mgwGCn+gsUmtnG6MFJDLiR8U0cyOUeK2Whfsep9YjOyMLW+WwETkfRwHA+H0BZLqsbTsTdxXoMqddcEnubul89AhYiNMgn/tSxvwdpMm3k3biY24qGddtyOw/URVPrCsYC7U5OqcCT6UZEkrRQXV74dyIe4bNyZhpGSCykHWA6VlFQmEEq36BZqmx66MqkWp5lVcbO0MW0oNnG8JoWSxRFVB6g3EnEirv7xXir+F5nU0J0g60//3Ab75uT0SjbYHPvhGuIsXRnhHg8GF5Ar7RQV4CX+Xai3Q0M3R7C5ebrKEupe58EyXp86D9xrKVbFRMOjZD7JuZEMw== 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=BwmJhnqvTds5tO5aEnJH3O/TNjCJ5n+UJoYRfAP85j0=; b=t+zCHmffItNh3e3AGkoY53zSKIokQCkVScmC2glKsC7hBY5QpuE+xccX/Rs8jVnjFW9eULcTfgQDG7x6yvKTqsky/KvljO3Yt93z7BDHxdt4zQeZ6SaW2lZwC/D8T6u2EdjEQF/Vik16lmvqnN8hv6mGwSY+AbRYE64nFs682e4= Received: from BN0PR04CA0201.namprd04.prod.outlook.com (2603:10b6:408:e9::26) by CY4PR12MB1126.namprd12.prod.outlook.com (2603:10b6:903:3d::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.17; Fri, 12 Nov 2021 17:40:27 +0000 Received: from BN8NAM11FT014.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e9:cafe::a9) by BN0PR04CA0201.outlook.office365.com (2603:10b6:408:e9::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.16 via Frontend Transport; Fri, 12 Nov 2021 17:40:27 +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; Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT014.mail.protection.outlook.com (10.13.177.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4690.15 via Frontend Transport; Fri, 12 Nov 2021 17:40:27 +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.2375.17; Fri, 12 Nov 2021 11:40:26 -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 v13 12/32] OvmfPkg/PlatformPei: register GHCB gpa for the SEV-SNP guest Date: Fri, 12 Nov 2021 11:39:39 -0600 Message-ID: <20211112173959.2505972-13-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211112173959.2505972-1-brijesh.singh@amd.com> References: <20211112173959.2505972-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: 65a2335f-43ad-4916-116c-08d9a60383e0 X-MS-TrafficTypeDiagnostic: CY4PR12MB1126: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +USVqgyXFTAwIkBY7Z0+P8a9fbYDm2/oYub2xMrvvUK/FP9Q9GQzjUkY5w57IAUQAWbL6Isc/h3Y1WdAio78ecAOBb91yFUR3PTcGzSvvMp/XvJmqsBuMYDpmp5J3XuP+B0RP+euvw9FpzUfvEXp0V4ZD5AGtdT2NcQZfgNNVRJ+5yza+LpBwGapxbvgT0PJDzV5iryORszaKBdqskmuiNQgD3bO2FwTnZcRa/j/3NscMuBu+sQEXM6RJ3B0uS/mAEo7TrNPxZ2GssXHnF3WZ3IVSNl3mpt/Digw3Ri0ueDKAcDz7BDAjavyfedbxTodKCbZkErptu0u9EV23QpddLu+iY8mAUhXOt2bKDemHGbYbR6WVzQxjZYJbhCWTRsraPK/LWlqyzr369+VN2eCpX42JGcO/zjoh9NcQwnMD6/FG+EN328x9i3akdmlWgm9b7xLzJxcy2TVesMoaSXrFAa9WzXxLTOkJzvnb8YVmHT2R5T3/qwtv3vQQf+OzT0V7DTdeDHw69Zb0ZqiZ53/5rqS3CDT7AQMnFB6irDYM+RuM0ex6XwXJsVvX8bG2x9h39uP6uqcW8cozri6kijC/dqYIJcB/Wfn3QuAJY7O+ZBDszSqCXEemGScPLnI6Wf8DXDxWMZyyqF3dyZWJu46SHGfpBKdvTsePHEG6j/dOso4YnUYtaztMB0VtAqvRvaVnhStWYBpZB7GQZ9WaeBKNq8k/1Hc+rILPqG9siKU6GWUWeZRWnnMgfK0MonJWDjOlDloSaXdtkJmUvQcyzhiWoOlvDcq7gf9G5lcblEPh6qWzgW+OE7SbFVQr3hPhmzI 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)(356005)(7696005)(47076005)(966005)(316002)(16526019)(508600001)(4326008)(36756003)(82310400003)(81166007)(83380400001)(36860700001)(8936002)(2906002)(8676002)(5660300002)(426003)(1076003)(6916009)(7416002)(2616005)(70206006)(86362001)(70586007)(44832011)(26005)(6666004)(54906003)(336012)(186003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2021 17:40:27.6758 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 65a2335f-43ad-4916-116c-08d9a60383e0 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: BN8NAM11FT014.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1126 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 | 87 ++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index a8bf610022ba..ba69f581893b 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -19,9 +19,89 @@ #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. @@ -109,6 +189,13 @@ AmdSevEsInitialize ( "SEV-ES is enabled, %lu GHCB backup pages allocated starting at 0x%p\n= ", (UINT64)GhcbBackupPageCount, 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