From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM04-DM6-obe.outbound.protection.outlook.com (NAM04-DM6-obe.outbound.protection.outlook.com [40.107.102.61]) by mx.groups.io with SMTP id smtpd.web08.10222.1619716383676501357 for ; Thu, 29 Apr 2021 10:13:03 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=HMA0kN6t; 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.102.61, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PYnDBdcRxp0HbNNE9swPoWUDu2qidDh9RrsD2E+KtWH7x7ISumFHIfjswUELdwoM2EPcm48TIgoXVh912DoRYCprdmVH9snTwmd05uuxfSgpbcfXuVYWvKjnVfWb8miFPyALRCZY2qbT6X4tbWI6Ry8jiLKk0+ykyuVbpHkj/MhM+nzjs8Be15lAWQR3vKdlud5TXLP4S2EqVBlIHgeumBlEAk9KUI0yLfIJ2+kvQYKvz0k1TFLA7xAh1WW2UBqcZiN6AVhnViRPp9Abhv8NettvkMaoCNEG13QstJwVGIs69efpzuglg2IrlpiuotkEQg4VtoniP08WxD1APFTfSg== 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-SenderADCheck; bh=TYJ3yzct9ErxUhPGHz71J6QUlELmwoA7kd6FwVyd7eI=; b=TwywLp8Jl3cJ/kEIbdqqQxbn6jDTwak6fSF1kF/A6aQGDEmBIqb4sbtzYxP1a03goxdNKu8mGqH/prc8f88h+TgjFvpp8DwIsJEWKYgseyGf5KmyQAkuNIw29DRfJjIfjIFL1Xh9j5qrxvHrPNsv4bAcvpjMLCUR0a6y4bYtczqdkaN86L/5BFoaESyker4QEosKiTyVVMHtQch9Ef236Pe4A7WHC2GBLKnpma1S1kx28DKeLKTbS5dB77LDG6LBn2EU3bagoaaojUmH1IUo33+1/BPmcBkER5vRB3k9X7NlzKUP0cvojdC5kXHOCHtRR80CChaUaF2+VDx3tNdYrg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=TYJ3yzct9ErxUhPGHz71J6QUlELmwoA7kd6FwVyd7eI=; b=HMA0kN6tIi4Km/VWZiPecxeI3y8Q23vRgKRXXUIxC5AKnA/l1EB1oQ+XhfLTgYq7k+jE1sqA3/8UM28WTRSaNl7fYyPIRNStgngLQ4IFanWyy6OSBrWidHmRNStfX9vmott3GR2AZIGVALnzVjo0NPS8CrdE3NJNBu4112cyg60= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB4218.namprd12.prod.outlook.com (2603:10b6:5:21b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21; Thu, 29 Apr 2021 17:13:02 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::b914:4704:ad6f:aba9]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::b914:4704:ad6f:aba9%12]) with mapi id 15.20.4065.026; Thu, 29 Apr 2021 17:13:02 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Joerg Roedel , Borislav Petkov , Laszlo Ersek , Ard Biesheuvel , Jordan Justen , Brijesh Singh , Erdem Aktas , James Bottomley , Jiewen Yao , Min Xu , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Stefan Berger Subject: [PATCH v3 4/5] OvmfPkg/Tcg2ConfigPei: Mark TPM MMIO range as unencrypted for SEV-ES Date: Thu, 29 Apr 2021 12:12:13 -0500 Message-ID: <42794cec1f9d5bc24cbfb9dcdbe5e281ef259ef5.1619716333.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.31.0 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SA9PR13CA0120.namprd13.prod.outlook.com (2603:10b6:806:24::35) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) Return-Path: thomas.lendacky@amd.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from tlendack-t1.amd.com (165.204.77.1) by SA9PR13CA0120.namprd13.prod.outlook.com (2603:10b6:806:24::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.8 via Frontend Transport; Thu, 29 Apr 2021 17:13:01 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ca7935f9-05d5-4b03-ef3a-08d90b320b71 X-MS-TrafficTypeDiagnostic: DM6PR12MB4218: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GOWmqpXWRdyqwfJakpz4ROo4NpyxRJI/idUrzPI1nn99rHw/GjAhtjJuWOaP04Jrt39l+qqvB/ZR3jvKCf3nurt0ZC2dpTptjPXFrQyjMOvpV08YqHoEbgDRZUVJgZtzlNolut3p24gNPEYw+DnUN172zWhOehuXk5fczisbcZUls+QSHGnIcAz8Vfk6Tl5V3aQfMRe6q6aoeMnNAaTZBDmlmTroTWaj5qca89ohPdRhQwYMsSL91dP5pLJrUirdm2ipBFJyMxvhLddG/Jm+1kG9QWJm3NraXoHUwZWboMZKmiSkL6MSw3YZopxMjcK2rpq3dHWWQ4P7thrX76bV0rQ532Gx3xo9BDIg6MBKw5ZYzuCxMcK/SPIdfunFdUVtojsjsECE4lOtYj7gzAYtK67Qp7O8SuHcde/0kLJ5SmMavU3HkSr5geVZJ6IRSVXXl89TP1IUqHlew77LF5tCmrJccZM3hSNcgg3EklBudRr1glnTvy4VxGG9LdwRmqLwYbb7pFvXMjBczbYpq72LrUCpGByP0qPpm+limhxV0OYGxnZ1Ga93fqMlvrvYfRcMD+SDiIp8mCC2WtAgSTEUBwIe2Oi4B/RcvyXy+LhcN/XSYhNE+0jqC/7NBHf+FSzfwaNsZO4og9YRAjhDeOFOCsxP2XXs/CsA7XQqLXdAMvhmZQ2Og88F+xagNsT+joj2gp6QEe6rTmx6dMB4QIkK9nUhNuKjVhdQLhswIvt3wPs= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1355.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(136003)(376002)(366004)(346002)(39860400002)(5660300002)(52116002)(66556008)(478600001)(66476007)(16526019)(54906003)(66946007)(83380400001)(956004)(2906002)(8676002)(8936002)(186003)(6916009)(19627235002)(2616005)(38100700002)(6666004)(966005)(26005)(86362001)(7416002)(7696005)(4326008)(38350700002)(6486002)(36756003)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?Y4MYRg7fXzhvCPpo33RJsqjb7QOoxBktEjMUUeQcNidLzoRNzwBvzCysS/di?= =?us-ascii?Q?bDYD+e2hCXkXS2S3WolKXcWy66nAas+ZcGcQw9khHFF3JMPZVS+HoXR/DS96?= =?us-ascii?Q?m0zj1WZR290g4OibB4LGSgj4+VoySGK4qmFOHQz9J0ORVEUN69lZhGncn6SR?= =?us-ascii?Q?7mk7ELyjlu0XVS6Ty0bu8387aUt1lT7tcpvonBdnp++XLTeEea4kjN1yhq+X?= =?us-ascii?Q?s3gFkbB6TXtq2HFfEapKZga7gbFITWglfZRMYutrlAx7BmuLmn/A1yvIByGN?= =?us-ascii?Q?cE3BmVhk/Gv8EewckfUX5+ajqLoiyulnnYknauLyZl9AeGMK2k1+rEaIOaFV?= =?us-ascii?Q?V1mAinMttSQzi2uWNfjwH6rhNxLdahtKcTY0ovX9VSpYEWG+NKKo1UZSP8mi?= =?us-ascii?Q?MNZsf9pg84YV/+hxMxtAn4vtBjq+gBt00lXxC7MsBTA/xkTPZ97jBevnd8jU?= =?us-ascii?Q?YMKFHetxQeb6Xr07rmDVFP6Ebsr7NGF+AyLxyKFMM7RuyPL7AGmmmLMwp4qA?= =?us-ascii?Q?zrumiKIWjXi5sMqktVhsiUx+MmRbcebzJMz1RBpe7CmFH0hkE7DoKD8Kd90d?= =?us-ascii?Q?T7yTgLcESloRASioxf+A2w48FPOrKY9q7LF05zS8TyV8EjATNkpar8drNEep?= =?us-ascii?Q?XujxOK0CR2yCrm1mE+gP6WkF5qBOgv+EMlIDvdoXwKLcHqEz+EGBrKh5+3lh?= =?us-ascii?Q?wnwifAkfbTRrgwyQ9ZdGRuFAb0MQjBLAamDtuSuVnhdxK2WNq3RDsqRsw6An?= =?us-ascii?Q?IalRY9FaaAcLez/JPl2v/9iWQZFKNMAY6u6GzojweJCgQgbSwJVj9lgdL7gV?= =?us-ascii?Q?3//5M9rZhjTDJnycrqAThLtJmctjopLdWbyUKVYeINgVUNWp2hMLpxUEbBuh?= =?us-ascii?Q?qdWML4a8F4Ywc901HA8qAYdEqidSIIeYx7WaFCzcHeuvnV2vcYmyBkLH+i2g?= =?us-ascii?Q?H7g3bxePwvcy/nyGv5nLehoUnzju1y40/A3NdJFB/jPKAa/jGMS0DqxLnYW3?= =?us-ascii?Q?C5pBHOEAOmuqT2oes4ANCeBS81uinJXRgKlIKmhqkwlCjnSD0gYD+H5QjnOE?= =?us-ascii?Q?SfGtFlsLNyR4/beIoKaRGtWPlwgukKr/SPVau4z4z9jE0n/iv+9y7IohDJ9m?= =?us-ascii?Q?MwKpUt6oSBZTrwfj4rMyPQeCgs4BMbFuXB2RLOy9dAIpCyVNfZ60uEM4vmEl?= =?us-ascii?Q?SBubX1peotpyhWfZpUwec0YiML+0peM0+8GZzkNGjV4iRO5EkdCndGk6aSqe?= =?us-ascii?Q?muedNKmI4/PAQZYQmFPzzBjKWWKvNitrkV8GHy2tgKQLflEuZblgB0ZIgLNV?= =?us-ascii?Q?fQYh0len4vOAGfJZuCE+JYmm?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ca7935f9-05d5-4b03-ef3a-08d90b320b71 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2021 17:13:02.0111 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jmuL4iPaFwF9/ZQxCukrE5+9HYJrgMI2kZfZSQqJtH5CdYfIvlXr7oF7XVeK6KRq1fbgADYCbQupCEgeQQT1TA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4218 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3345 During PEI, the MMIO range for the TPM is marked as encrypted when running as an SEV guest. While this isn't an issue for an SEV guest because of the way the nested page fault is handled, it does result in an SEV-ES guest terminating because of a mitigation check in the #VC handler to prevent MMIO to an encrypted address. For an SEV-ES guest, this range must be marked as unencrypted. Create a new x86 PEIM for TPM support that will map the TPM MMIO range as unencrypted when SEV-ES is active. The gOvmfTpmMmioAccessiblePpiGuid PPI will be unconditionally installed before exiting. The PEIM will exit with the EFI_ABORTED status so that the PEIM does not stay resident. This new PEIM will depend on the installation of the permanent PEI RAM, by PlatformPei, so that in case page table splitting is required during the clearing of the encryption bit, the new page table(s) will be allocated from permanent PEI RAM. Update all OVMF Ia32 and X64 build packages to include this new PEIM. Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Brijesh Singh Cc: Erdem Aktas Cc: James Bottomley Cc: Jiewen Yao Cc: Min Xu Cc: Marc-Andr=C3=A9 Lureau Cc: Stefan Berger Signed-off-by: Tom Lendacky --- OvmfPkg/AmdSev/AmdSevX64.dsc | 1 + OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/AmdSev/AmdSevX64.fdf | 1 + OvmfPkg/OvmfPkgIa32.fdf | 1 + OvmfPkg/OvmfPkgIa32X64.fdf | 1 + OvmfPkg/OvmfPkgX64.fdf | 1 + OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf | 40 +++++++++ OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPeim.c | 87 +++++++++++= +++++++++ 10 files changed, 135 insertions(+) diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc index cdb29d53142d..66bbbc80cd18 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.dsc +++ b/OvmfPkg/AmdSev/AmdSevX64.dsc @@ -626,6 +626,7 @@ [Components] OvmfPkg/AmdSev/SecretPei/SecretPei.inf =20 !if $(TPM_ENABLE) =3D=3D TRUE + OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf SecurityPkg/Tcg/TcgPei/TcgPei.inf SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf { diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 1730b6558b5c..33fbd767903e 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -706,6 +706,7 @@ [Components] UefiCpuPkg/CpuMpPei/CpuMpPei.inf =20 !if $(TPM_ENABLE) =3D=3D TRUE + OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf SecurityPkg/Tcg/TcgPei/TcgPei.inf SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf { diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 78a559da0d0b..b13e5cfd9047 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -719,6 +719,7 @@ [Components.IA32] UefiCpuPkg/CpuMpPei/CpuMpPei.inf =20 !if $(TPM_ENABLE) =3D=3D TRUE + OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf SecurityPkg/Tcg/TcgPei/TcgPei.inf SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf { diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index a7d747f6b4ab..999738dc39cd 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -718,6 +718,7 @@ [Components] UefiCpuPkg/CpuMpPei/CpuMpPei.inf =20 !if $(TPM_ENABLE) =3D=3D TRUE + OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf SecurityPkg/Tcg/TcgPei/TcgPei.inf SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf { diff --git a/OvmfPkg/AmdSev/AmdSevX64.fdf b/OvmfPkg/AmdSev/AmdSevX64.fdf index c0098502aa90..dd0030dbf189 100644 --- a/OvmfPkg/AmdSev/AmdSevX64.fdf +++ b/OvmfPkg/AmdSev/AmdSevX64.fdf @@ -147,6 +147,7 @@ [FV.PEIFV] INF OvmfPkg/AmdSev/SecretPei/SecretPei.inf =20 !if $(TPM_ENABLE) =3D=3D TRUE +INF OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf INF OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf INF SecurityPkg/Tcg/TcgPei/TcgPei.inf INF SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf diff --git a/OvmfPkg/OvmfPkgIa32.fdf b/OvmfPkg/OvmfPkgIa32.fdf index f400c845b9c9..b3c8b56f3b60 100644 --- a/OvmfPkg/OvmfPkgIa32.fdf +++ b/OvmfPkg/OvmfPkgIa32.fdf @@ -162,6 +162,7 @@ [FV.PEIFV] INF UefiCpuPkg/CpuMpPei/CpuMpPei.inf =20 !if $(TPM_ENABLE) =3D=3D TRUE +INF OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf INF OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf INF SecurityPkg/Tcg/TcgPei/TcgPei.inf INF SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.fdf b/OvmfPkg/OvmfPkgIa32X64.fdf index d055552fd09f..86592c2364a3 100644 --- a/OvmfPkg/OvmfPkgIa32X64.fdf +++ b/OvmfPkg/OvmfPkgIa32X64.fdf @@ -162,6 +162,7 @@ [FV.PEIFV] INF UefiCpuPkg/CpuMpPei/CpuMpPei.inf =20 !if $(TPM_ENABLE) =3D=3D TRUE +INF OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf INF OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf INF SecurityPkg/Tcg/TcgPei/TcgPei.inf INF SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf index d519f8532822..d6be798fcadd 100644 --- a/OvmfPkg/OvmfPkgX64.fdf +++ b/OvmfPkg/OvmfPkgX64.fdf @@ -174,6 +174,7 @@ [FV.PEIFV] INF UefiCpuPkg/CpuMpPei/CpuMpPei.inf =20 !if $(TPM_ENABLE) =3D=3D TRUE +INF OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf INF OvmfPkg/Tcg/Tcg2Config/Tcg2ConfigPei.inf INF SecurityPkg/Tcg/TcgPei/TcgPei.inf INF SecurityPkg/Tcg/Tcg2Pei/Tcg2Pei.inf diff --git a/OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf b/Ov= mfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf new file mode 100644 index 000000000000..51ad6d0d055d --- /dev/null +++ b/OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPei.inf @@ -0,0 +1,40 @@ +## @file +# Map TPM MMIO range unencrypted when SEV-ES is active. +# Install gOvmfTpmMmioAccessiblePpiGuid unconditionally. +# +# Copyright (C) 2021, Advanced Micro Devices, Inc. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 1.29 + BASE_NAME =3D TpmMmioSevDecryptPei + FILE_GUID =3D F12F698A-E506-4A1B-B32E-6920E55DA1C4 + MODULE_TYPE =3D PEIM + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D TpmMmioSevDecryptPeimEntryPoint + +[Sources] + TpmMmioSevDecryptPeim.c + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + SecurityPkg/SecurityPkg.dec + +[LibraryClasses] + DebugLib + MemEncryptSevLib + PcdLib + PeimEntryPoint + PeiServicesLib + +[Ppis] + gOvmfTpmMmioAccessiblePpiGuid ## PRODUCES + +[FixedPcd] + gEfiSecurityPkgTokenSpaceGuid.PcdTpmBaseAddress ## CONSUMES + +[Depex] + gEfiPeiMemoryDiscoveredPpiGuid diff --git a/OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPeim.c b/Ovm= fPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPeim.c new file mode 100644 index 000000000000..df2ad623308d --- /dev/null +++ b/OvmfPkg/Tcg/TpmMmioSevDecryptPei/TpmMmioSevDecryptPeim.c @@ -0,0 +1,87 @@ +/** @file + Map TPM MMIO range unencrypted when SEV-ES is active. + Install gOvmfTpmMmioAccessiblePpiGuid unconditionally. + + Copyright (C) 2021, Advanced Micro Devices, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + + +#include + +#include +#include +#include +#include + +STATIC CONST EFI_PEI_PPI_DESCRIPTOR mTpmMmioRangeAccessible =3D { + EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST, + &gOvmfTpmMmioAccessiblePpiGuid, + NULL +}; + +/** + The entry point for TPM MMIO range mapping driver. + + @param[in] FileHandle Handle of the file being invoked. + @param[in] PeiServices Describes the list of possible PEI Services. + + @retval EFI_ABORTED No need to keep this PEIM resident +**/ +EFI_STATUS +EFIAPI +TpmMmioSevDecryptPeimEntryPoint ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{ + RETURN_STATUS DecryptStatus; + EFI_STATUS Status; + + DEBUG ((DEBUG_INFO, "%a\n", __FUNCTION__)); + + // + // If SEV is active, MMIO succeeds against an encrypted physical address + // because the nested page fault (NPF) that occurs on access does not + // include the encryption bit in the guest physical address provided to = the + // hypervisor. + // + // If SEV-ES is active, MMIO would succeed against an encrypted physical + // address because the #VC handler uses the virtual address (which is an + // identity mapped physical address without the encryption bit) as the g= uest + // physical address of the MMIO target in the VMGEXIT. + // + // However, if SEV-ES is active, before performing the actual MMIO, an + // additional MMIO mitigation check is performed in the #VC handler to e= nsure + // that MMIO is being done to/from an unencrypted address. To prevent gu= est + // termination in this scenario, mark the range unencrypted ahead of acc= ess. + // + if (MemEncryptSevEsIsEnabled ()) { + DEBUG ((DEBUG_INFO, + "%a: mapping TPM MMIO address range unencrypted\n", + __FUNCTION__)); + + DecryptStatus =3D MemEncryptSevClearPageEncMask ( + 0, + FixedPcdGet64 (PcdTpmBaseAddress), + EFI_SIZE_TO_PAGES ((UINTN) 0x5000), + FALSE + ); + + if (RETURN_ERROR (DecryptStatus)) { + DEBUG ((DEBUG_ERROR, + "%a: failed to map TPM MMIO address range unencrypted\n", + __FUNCTION__)); + ASSERT_RETURN_ERROR (DecryptStatus); + } + } + + // + // MMIO range available + // + Status =3D PeiServicesInstallPpi (&mTpmMmioRangeAccessible); + ASSERT_EFI_ERROR (Status); + + return EFI_ABORTED; +} --=20 2.31.0