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.69]) by mx.groups.io with SMTP id smtpd.web11.2347.1636582527618038776 for ; Wed, 10 Nov 2021 14:15:27 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=T44iBIk2; 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.69, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XS5n9mSgPUM7LkKegcTJGGVuBghoAvgf8ljEy2TtWXBL4MNHK81SwC9MWLjV1xs/Ywr9mXM35l2+5uE+MVs0kr2EbvynXZYIEgVdP2KjRJsyKIn7fAuGp5ulX0Jy6zawJFOLXeNYUCfNz+eMa8Peg4qsTcdnAx8+zwb/xXPkIF1MDonzhzNSN9NgZnE1906PP7Dj0c8mTyyeAFFUWpJSgxUPXUovAVioynfM9RkCrp/Zh0rLO2OzaysmMWBDv40h0sDr6iX3hfFRl/bgPcJK0kpBt5ZAWHKLnl4WM5PhY/O+UPSMCXRvwqur3aK0WWaD4hrXdj027tsOwyLIfQxE6g== 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=gjnDNMl5GJYHhAhUZ75aelRkjnDjVbbJvRz2/B7enUYrKC/MpQC5V1lrVIuK8GJwkS43x1oYsD/uNPt8xzDxEnDu3c44gqGk1FlnwxxRyp36SJC4Nwnm+G1yTHWTnw46cwJWoIuPJHxOTlfgoUHQ/Am42cND9QPG4cPeqlm5PoOySsfk1rj0W/6BT4o37GvC5zJ2bSMJJ58x+JxUVQ+7LfLiA0ZA8yzLEv6wreQXSCu/lCuEaLGDU4ZRa0A/+VksKLia1kL6Z5kNrFckyfxrNAnromsWYgzq83CFWgHY0xD/2L3yPebg/sjLu42sHxAKiT6R4Nz6AumUstvuFkG0UQ== 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=T44iBIk2dACGDL5NCKajoMh0pg2C8LZ8pdEAa8UMHwcS4FkAn1a1zutjYoGbUB2RPYFuns8d3tLZyZIo5c7qKZKGmzfc6tk5WUI3nIF/DPtdWdlY2IMwqy3iIJwbLvmesVjMbDl1f06Jml/ZRyHRmqM5OTQcbDqCs6g0vwRn1Ws= Received: from BN6PR2001CA0024.namprd20.prod.outlook.com (2603:10b6:404:b4::34) by BL0PR12MB4690.namprd12.prod.outlook.com (2603:10b6:208:8e::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.11; Wed, 10 Nov 2021 22:15:23 +0000 Received: from BN8NAM11FT066.eop-nam11.prod.protection.outlook.com (2603:10b6:404:b4:cafe::56) by BN6PR2001CA0024.outlook.office365.com (2603:10b6:404:b4::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4669.13 via Frontend Transport; Wed, 10 Nov 2021 22:15:23 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; 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 BN8NAM11FT066.mail.protection.outlook.com (10.13.177.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4690.15 via Frontend Transport; Wed, 10 Nov 2021 22:15:20 +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; Wed, 10 Nov 2021 16:15:19 -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 v12 12/32] OvmfPkg/PlatformPei: register GHCB gpa for the SEV-SNP guest Date: Wed, 10 Nov 2021 16:14:37 -0600 Message-ID: <20211110221457.2397234-13-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211110221457.2397234-1-brijesh.singh@amd.com> References: <20211110221457.2397234-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: e186c135-5971-44cf-f2c7-08d9a49795b6 X-MS-TrafficTypeDiagnostic: BL0PR12MB4690: 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: zKm8sECGnNa5El4P6cK/4joUp5ai9RCN/XlseZnwjpYmvu9OWM31oboDAIFTaIcABqm9Gw5b4AV+POhhBLgpYcHZ1Zoxhp5Ie4i2A2whWyHsyj/RU/ZWP8BacvTXgzC/ofM0JQ2WNVODo6fsnC1a2Q9YvH1+iHpAM2lb6EfVowlOyrP172jGeiOwh5DbseHszvHO7ziK7ZDGCLO9geRAahrFMOD5HGNo6BGJLr8g0B11OGZKdSm4GurKqjNzAVmRS1KT+tM8NJcSeAsOhQzZD5JJj00k8mtucRTFuriRRuownInvwCWuqtLpuBBFSifyXgLt6nMdJgubuBGRVrqobIaCoLkdLqFfUrfc5ZBLL8de1m6pqNN8o/BUoPFrXs51+8B/i4lNq6YFM4UNoy9BuRL0mu0X3Lng60tLbWPCTG/1Wm/r2HUVXwCU59voEWMikThDBfjP1HdKBLcQ+5S++Vlv+CItEvinPBubI6A1PfwsJfPOs+iUbPcsMif9fC1mD8+qqFvsTbgH39Dz7+12l+yAjdqxOPtO56GUGEN0Bc8BY51p9NVwvVtKmRMaobMsveUnZfMScgVsvCPWcRySpzvsmsFcvI9OXV5zfHZiuXXMG1UxrX/hfJYpM1bMuUhRv3atPjCC8i3a6hydttnWTZnpb6VVqi4hQnuz2qksg5Epwy0B+l89lHVMHTHQs3JtcJVDuNQ5gASS25zXBzhb7qKavQ9nn32Qv5sCPpGbpro3/FaRpEdSrU34cOIFpekCpjaaHEf9u+RX74sAdaffLFTuEK3faZ68CaC1OKTd6S0Qk1aKbvf206bXsz45Xtu7 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)(46966006)(36840700001)(70206006)(508600001)(36756003)(70586007)(6666004)(7696005)(356005)(5660300002)(2906002)(2616005)(82310400003)(4326008)(47076005)(36860700001)(6916009)(83380400001)(8936002)(81166007)(7416002)(8676002)(316002)(44832011)(966005)(426003)(86362001)(336012)(16526019)(54906003)(1076003)(186003)(26005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Nov 2021 22:15:20.8007 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e186c135-5971-44cf-f2c7-08d9a49795b6 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: BN8NAM11FT066.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB4690 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