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.77]) by mx.groups.io with SMTP id smtpd.web12.15082.1634672408753573463 for ; Tue, 19 Oct 2021 12:40:09 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=aqBDUbwv; 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.77, mailfrom: brijesh.singh@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IZuwxYNI79NHb6QXoKchjinmiYxlsm8Z6+orYqwrSBQgyfK4cRZFrOqma2QN+7Etn13Q8tqR83A2h4EBBBpzuRQ3qcEtksc2oXr9+LIU/hNkv98GqRJ1WE2mLF8AoPFzAu79AjMIDVVAwM3KuCohrRuhWA9wgDrtIl8cqjZ7mdkQqOp9IS+pJTRmxjgwVxj2wB+q15CvrnJoyr0ISf0t2LQRtNXHtDRkZHhloPuJ34PvmzUiJbkf3F5/sanIW2sZ0be+b3GuFUprOUty1FYW90WvGGPF5+9ByK6JHzsPIsRMUkMCGDhLBc5Z29CtAp35M6Q0rXKxpsniMqW2yuRWmw== 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=7r6QSglsCZ8XrilVJVQ90P8s7RPdpyp5NEX+d331xr0=; b=B3Z3ecc2ckYV9Svgbd62e8Wpll+ysidIC6FlwVjLOm/LRhnSZhgMXtaVyJrW9eaq7PD7t5o7hMTNN/3+5usTHYkO1aauTWgMtw0Sjs/wgHNY75szugq/t2ZBGEbUuwDnLZma4mtjbe6y1zVcLsSIjTscR1Fhaog80/YLfjVcFsblvLpvtMwiHLdRQBL7LOBmxZbZdWsj/fnRbBYRPD+2qmru/5fwtY+WaSPTcIzdiaz30dtVL9EmrCPglDY/EDKUcq14SK7M8xYgqXaVfsZIbGpWYxzRA0Kk7KDs25XsULmralQJI2/UvQyRY21gkTJ4D7r0EqjYEzRAtg7nZaV1kw== 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=7r6QSglsCZ8XrilVJVQ90P8s7RPdpyp5NEX+d331xr0=; b=aqBDUbwvUdQn/Q8I6Zebm4PC6j7vUzJ9tUQewr4TNQp5vex4FA/43WJIhhdP2pTJxou6XZ5SEm2bDsMwiGJjBAuya0Yn+by71uEX6cHHpxFR/bqP062rr1FQvvsM1woIwvH8X9ZhvXmiSYFhcPGFPPHONZhVDXfwfWiWAYU+SIY= Received: from MWHPR02CA0024.namprd02.prod.outlook.com (2603:10b6:300:4b::34) by DM5PR12MB1545.namprd12.prod.outlook.com (2603:10b6:4:7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.17; Tue, 19 Oct 2021 19:40:06 +0000 Received: from CO1NAM11FT054.eop-nam11.prod.protection.outlook.com (2603:10b6:300:4b:cafe::a4) by MWHPR02CA0024.outlook.office365.com (2603:10b6:300:4b::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4608.16 via Frontend Transport; Tue, 19 Oct 2021 19:40:06 +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 CO1NAM11FT054.mail.protection.outlook.com (10.13.174.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4608.15 via Frontend Transport; Tue, 19 Oct 2021 19:40:05 +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.2308.15; Tue, 19 Oct 2021 14:39:59 -0500 From: "Brijesh Singh" To: CC: James Bottomley , Min Xu , "Jiewen Yao" , Tom Lendacky , "Jordan Justen" , Ard Biesheuvel , Erdem Aktas , "Michael Roth" , Gerd Hoffmann , Brijesh Singh , Michael Roth , Jiewen Yao Subject: [PATCH v10 12/32] OvmfPkg/PlatformPei: register GHCB gpa for the SEV-SNP guest Date: Tue, 19 Oct 2021 14:39:14 -0500 Message-ID: <20211019193934.1052465-13-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211019193934.1052465-1-brijesh.singh@amd.com> References: <20211019193934.1052465-1-brijesh.singh@amd.com> MIME-Version: 1.0 Return-Path: brijesh.singh@amd.com 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-Office365-Filtering-Correlation-Id: f6379fc6-6488-4e77-c4c4-08d99338408d X-MS-TrafficTypeDiagnostic: DM5PR12MB1545: 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: l8ErNd/W8bm1ZvtXipy92Y5zJ9n7ZjY7j6P/xEaZ5XDOKfvwktkf0Ooul57eNxNkI+jG6J8cWjDi2FJnyOqfsJd/HgzsgAP9sKGrFOUuWaEW9PGz5UvNiTEgOfFn5gZYAzomYoSKJzu0zaKvwceZMfudKVbo+x633Qrt3iGVwxQyrp/6yuFkNOk0jGXeT1RbgShCCeGb3LTpB9k1qJ4OA7/ME6+9nY5ZvsGmKwwucJ3YpUFfKfWp7vFN8Ar9r4UOZ1K7PxRm7/Q3JrL+AUkwqwA7PhB+zxmkDresvFrtbcqCrzIe1KsmqYjGRXDcsq+PJo9EVpuie/OylOdPdbVQbf22i/JwIWjSS+1CZQJrU2FVdaiif3Ce8YnxwDrTZQaXn9A5xXxWCwnYqN2YO2O5NZNLQRvhdiiUPPtkZd/7ZEmDPbKIe9OdmJTGbs2TNWm9ZDSMhKXQI2a2eg+B/RvHly/0/o6+oskF1bXHqsJuL3h/kv+ka3y2pwnkBE2XZtmruf+Ptf9iOktUxFvLe4o5c/9DBpAb59TBexqLFWF38jZSspbkR4ERb70oaGRRx00B9tijv1FiIV3z3aGkxSeGvg/hIpNx1/mhWlKRUPpeMuRWLzmQodW7LNSllYLrDXbWWuvN0aXY248UO4raT0kew+b1wHcC7uU9IM7BL2JCpsMhXpUOZFycuvtorvk/eerKZ1tYB7eTiJSpCyO9d4ktn7DDNnekO3Aqrkx33NxGPAYbGD9CbW8aOlEBb5bVx2prZt99FnBf1Pbg9zaoNavF3VfMqHIWwDEQbeFJjdVRBw7QgNk5CBrZI3txCMVSaEIQ 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)(70206006)(70586007)(2616005)(508600001)(8936002)(5660300002)(336012)(426003)(356005)(83380400001)(966005)(82310400003)(26005)(54906003)(6666004)(81166007)(4326008)(2906002)(36860700001)(1076003)(86362001)(7696005)(44832011)(6916009)(8676002)(36756003)(47076005)(316002)(16526019)(186003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2021 19:40:05.8601 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f6379fc6-6488-4e77-c4c4-08d99338408d 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: CO1NAM11FT054.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1545 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 | 91 ++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index a8bf610022ba..de876fdb478e 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -19,9 +19,93 @@ #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; + EFI_PHYSICAL_ADDRESS GuestFrameNumber; + + GuestFrameNumber =3D Address >> EFI_PAGE_SHIFT; + + // + // 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 0; + Msr.GhcbGpaRegister.Function =3D GHCB_INFO_GHCB_GPA_REGISTER_REQUEST; + Msr.GhcbGpaRegister.GuestFrameNumber =3D GuestFrameNumber; + 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.GhcbGpaRegister.GuestFrameNumber !=3D GuestFrameNumber)) { + 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 +193,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