From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62504+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62504+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594736930688449.9441399959976; Tue, 14 Jul 2020 07:28:50 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 3FyYYY1788612xPPEGVb0ReK; Tue, 14 Jul 2020 07:28:50 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.53]) by mx.groups.io with SMTP id smtpd.web10.21004.1594736929615139220 for ; Tue, 14 Jul 2020 07:28:49 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J00XZPhcZ8bnSU1/qdWWXs0EOA5V4Ogozt8+0ZJC5xwPnH2zlFHoaOrILrqme1IJBGDMSQykbdO/UlLsc9DG7giC7rLqkn6kg7MfoBokq74fOHpb10ZsfPVvyAVze/xREvhA4xNFaqplMDDw0LpM5+uYU9Bmg/QpFV3H1LRaxdke3S57S4aHS95VEVD/vszR1IpOQfh0KPnDvPsyJBU+5pDDj95BsZiQArhBFWQdqScQV0BQo1N4ebw8R6HAIum6dNSHM6LvQbvht486HtbKcAxrJbVShuNeIL/qc5l2/fdd2ZJaIrJJAeST/VGd79bCevqQNrGIqTgD3dVoh6G98w== 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=Hqe1rDuCswusit5U/Sbl9vY8AnSbuBv1xrlSJIgoLm4=; b=TvFV5ne/T0AX8DnAsRP3rPWexXyQuuI83eIvcWioFt636qHaVNN00m15xljexaW83I3/3+8B3avn8Tn+9jM/YSiDmBgmqoE5E/3cGuTnB5IUUef2OHHYPC/ZPCIVzXtLWZA+8tdhYc1Pvy+N+g8h3yps4NgRtW412qfpDlhhBJDqKhL07lVYIQyxPcJkB7AhBM01W2IksqBzToCaTpz7yZerWCbSEZTBGW8zCbw0HkLKe/OxX2nbGQ31UpQkTL7AsOfEf66gpS2YdZPOMRrttZmy8mNTQg7t7HRoFl6qgg/Oy9A38jIcty7MVJgrWglWWHGsjxLgs6fs0nXdfCNdsQ== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:28:48 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:28:48 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni , Jian J Wang , Hao A Wu Subject: [edk2-devel] [PATCH v10 01/46] MdeModulePkg: Create PCDs to be used in support of SEV-ES Date: Tue, 14 Jul 2020 09:27:32 -0500 Message-ID: <8303617f29e455a510a296dfeb67e6a8ae10e9ad.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0110.namprd05.prod.outlook.com (2603:10b6:803:42::27) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0501CA0110.namprd05.prod.outlook.com (2603:10b6:803:42::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.9 via Frontend Transport; Tue, 14 Jul 2020 14:28:47 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 5b32a019-1a7f-49d7-393f-08d828023893 X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: AbvM891E0S53Jltf90vDlPkwFzEElV4YhVvpSM7aSK5jxQ1jYiXAd+jVU7sdrpoMZ0FAGBUc43ORg/iqjcg//kT+/SC3PTS7ZGjX7WAqrBOD2dT/aX70yOUzJWesdPSqmLIj54PhgDl5h/IB5w0n6OAcFK2xErv2HlXH7X2ZfNysy9sxyeGYZGYELfPWohJjWxcJXW/Xgkp4z6XGyUL8dpTKJqwN5VTJIxCnplW9Mvdy4GvC5ILH3g9HFcCz7H81Wza5f7v32h/RFpUr+FQg/Vspgvmu+2gZ+B+aeaOLex02C6TdK+qzVaQ+EYlw2afSlg7Ro5griByR0v7yJ5mukXGoGTmHuF78qKloXDFYbGQtjk0hPu09PFQc69QhT4tW1jcmXCey0AUbtJNw7txUSpeiq9Fs/FiXT5PLhxV0/At3X39YMP7hfgxnYZtskdPfo5Y5wdNKO/VaEBMc9GxZgQ== X-MS-Exchange-AntiSpam-MessageData: bwX3tUKPKV8sMpVPtmuesRY7VvtgNWB14gCjj2yGOx0qqJ5VG6KHZEAzbsPt9ptu5e9vfd9Z1ccobPlfzj4LgYFZD+TEVE00pA/1TCZuimN8DHZJrKEK6oBHZdmeQllEko5SOGk52Ui0GEfdSZoLxCBh0EniccJ1W4mbkMDUplj5ey4BaRpp7UKNq9mgBWgCN7RAQ9sRM7SxL1urvws83D+hGr1E8D3EpSXdzuDDKhnVSaM2J/zEDV3rV3HKLwkKnucjViSY5nZJF07fZR7y2fz/Fjkt4RVxLo+uHJFBps9D+Yi2p8pSYwT06J+LhSdG520ryRPYFdcjSzW4+rExnIyHNVvWux4/Jx+4VeMabloFyoPeY7e5szfUd9Q/C6bCnQMCvIh39rEwPMW34Km43cBHoEprpvzVu1sYc6Yh7ZoLocYm5u6eD/XlNgmG3iqh+Nn2n+tcQRYZ2M373IcM7DVzSxnwPQOIwbccxn1ABYo= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5b32a019-1a7f-49d7-393f-08d828023893 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:28:48.0541 (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: lBUeKUm42jc7hAOongx+AZdX1hDKQsyNoCFaWmN7kcbiYdMtuWLXBc19POl5jzVvClc31iEPu8D8qE/QbMIPEw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: 5JeFQgVJLnblKiwg2PDLoSWPx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594736930; bh=1Z8U/F6CUZ4BB13rg5DlglOLJJl1gJQFaERL9ZSMBqo=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=ZAz8930pXyt4BFdpzqsAMRuJgNUq6BaCJ5InHJ4AxLvRVJ49rdrjo9LqyYEGD6fLrQb 4ASd83REvBaEu0C95PtgZcD+5W9MMx6nyqm2kcW3q7JsvpnAl9rn4GYeboQZ7zbpJ4asX HzGuUFZuEozNaoDklcwNhIc+Z3eLLfzz6Uc= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Two new dynamic MdeModulePkg PCDs are needed to support SEV-ES under OVMF: - PcdGhcbBase: UINT64 value that is the base address of the GHCB allocation. - PcdGhcbSize: UINT64 value that is the size, in bytes, of the GHCB allocation (size is dependent on the number of APs). Cc: Jian J Wang Cc: Hao A Wu Signed-off-by: Tom Lendacky --- MdeModulePkg/MdeModulePkg.dec | 9 +++++++++ MdeModulePkg/MdeModulePkg.uni | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 843e963ad34b..f8cd9239b4ce 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -2051,6 +2051,15 @@ [PcdsDynamic, PcdsDynamicEx] # @Prompt If there is any test key used by the platform. gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed|FALSE|BOOLEAN|0x00030003 =20 + ## This dynamic PCD holds the base address of the GHCB pool allocation. + # @Prompt GHCB Pool Base Address + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase|0|UINT64|0x00030007 + + ## This dynamic PCD holds the total size of the GHCB pool allocation. + # The amount of memory allocated for GHCBs is dependent on the number o= f APs. + # @Prompt GHCB Pool Size + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize|0|UINT64|0x00030008 + [PcdsDynamicEx] ## This dynamic PCD enables the default variable setting. # Its value is the default store ID value. The default value is zero as= Standard default. diff --git a/MdeModulePkg/MdeModulePkg.uni b/MdeModulePkg/MdeModulePkg.uni index 2007e0596c4f..2f8cca03e527 100644 --- a/MdeModulePkg/MdeModulePkg.uni +++ b/MdeModulePkg/MdeModulePkg.uni @@ -1297,3 +1297,11 @@ #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTcgPfpMeasurementRevision_PR= OMPT #language en-US "TCG Platform Firmware Profile revision" =20 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTcgPfpMeasurementRevision_HE= LP #language en-US "Indicates which TCG Platform Firmware Profile revision = the EDKII firmware follows." + +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdGhcbBase_PROMPT #language en= -US "GHCB Pool Base Address" + +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdGhcbBase_HELP #language en-U= S "Used with SEV-ES support to identify an address range that is not to be = encrypted." + +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdGhcbSize_PROMPT #language en= -US "GHCB Pool Base Size" + +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdGhcbSize_HELP #language en-U= S "Used with SEV-ES support to identify the size of the address range that = is not to be encrypted." --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62504): https://edk2.groups.io/g/devel/message/62504 Mute This Topic: https://groups.io/mt/75499722/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62505+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62505+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594736945242724.0724416961156; Tue, 14 Jul 2020 07:29:05 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 9JFbYY1788612xNyXwpsDmyZ; Tue, 14 Jul 2020 07:29:04 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.79]) by mx.groups.io with SMTP id smtpd.web11.21030.1594736944110498140 for ; Tue, 14 Jul 2020 07:29:04 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j7PbELE2oXg6Km2BYU6ITsaZoVO5NCD4G96AWFWWEkwmm2gIVbCS6WYeOnwjAKlXyOUwFoKahI/VeZAYaYOdTcnsnbvSklY8hpr6ioQJl8bmEu24CBnBjC6/dI0ns3v7ep413ouAmHzZjnhfXsvLaCPPFcdEYgCzqHL146kVVxe6q+9WafnLdInHwXM3aBk2QI06t9B20/W2uHjRypibsJndHUX3Yg0m94V4Db5znqgQgxSgaTTql+cJmtKKj0ogguVlTKeK3uoxUqyOSQSM8eTibT5o3ni7uDj7T9zdUWesrlSfrSpZb7g2452r8G00DI+ZhbLPnGQuBDjuCPoPgw== 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=iUIg1b4EwDhKpEO96e51MuPrwJUs/s5zD1/37hv4dng=; b=f37FjbWxtruwKF3Xe5Ukz0KIKuQiBTDuYXeDletZvQ00uL9FG45Aeui0s0OmmeDo4SJImg9TInbhdXQiJWFF6ydPvM1M7x2YnLpnXqehZGEegBMQ/Vh140HjZevS22XvoMHviGvEImqpDcexf3h3vu4UN7OU9AP3LU31RNPUUO/wX0USxxk+i2PbGbXO8RXeFx+Q1voNPuOdQoh4cFsL8DXfux1LwWQjpO04OTMj7+5fkCXHG3jxQPfnYkCPPyLuA9FHjnuB2kjoVy1kLH7lgtlhaweZbHTBkzbcS1ZhtecRmSoIaHqWSaw6Y91xl19DxCUuFmqw/7VKFpqyFs3DOg== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:29:01 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:29:01 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 02/46] UefiCpuPkg: Create PCD to be used in support of SEV-ES Date: Tue, 14 Jul 2020 09:27:33 -0500 Message-ID: <7e7b57be598c02f85b1c7d95fef7c2301eb1ccbd.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SA9PR03CA0012.namprd03.prod.outlook.com (2603:10b6:806:20::17) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SA9PR03CA0012.namprd03.prod.outlook.com (2603:10b6:806:20::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22 via Frontend Transport; Tue, 14 Jul 2020 14:29:00 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: bb5637f6-95da-4a8a-d3ca-08d8280240c6 X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: NZexbMs3vpmxucI6KMxnNTkRclR5N+5Y2sbTwDBP6ArRlEqTjYYdonDqZm0ga3exLHnem3njuXnNXXx/hCZpFH4KFZI5evxgndrB9dF5ZoI2/vCmiSyNVkBNidMH7JM/RwVNR4j5wRFtC3LWdCTVJCgvCyirukg/J3Z4fpJadR3a4bwO00B8sI2SjBdBbWROpN9HgJ1/WWZ+62nxrHzUkPOnod5grormRObxo/7C9gyIB3yqHUJqrIMbYBR4qv2TXWi3w28tXbAcrmOzEw9CtIYofaDoU8PXPf/BtPTOELzzqDgp7iojzBbhN9LcLEvg7KUmDG9R7JUPPjPO6sR6/cthgIyVhtHJIDvuRkd4AU4Qj/P1OBSPx7qMZxYutJFGPPABIWdNOls4C3b9wcNMiJ72FhaDODfKqQ8s4KEAfBj6pow/kodi0iMwUAHJksVylT6NTfn479LNV1/7zwDBWA== X-MS-Exchange-AntiSpam-MessageData: 4mHyuUMXQrpct8efskBA+fIQp3iRrzPy9gVmiBesXzAlhMUuY+El2tjc0P2Z+MThEjJRb2T/nkdlp3f3WynHPxePxkg4X6kWwMRs0Jwn16NftZ8JlrAecuNxax2SYgK0iy+T6hekV6xPq+fQd8Y3sxiq18B9GIchRlXdk6BjHMQ5mvUSd0+B2JqzHyeSmJi4SHbTSACNwayHpGdVvwfMagEl2ycIlZLjPC6cwwSAgXoAogFrOFCkVEzkLnCDYqncsyNGwdwj+PHJ4X+PUCgURfNbO2WzSCNINeNEsxSLhb5yGglGEscLTcgkktv8TnRi9tfpefR1oUbA3K3R6qvFE+M1ahcZIgKrW/PkKfVjXB3+crucTFjXcp0HDSD35N5Q4sf2J/AzjMXHOVAzZTAV1jNrvK06HSqXCPvr57BrQeAWBr3PUzGojwk3pF+pn68lDutOAlis8ni5cR2+4/HvgafLOtxokAQrJ/jrONjwFOw= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: bb5637f6-95da-4a8a-d3ca-08d8280240c6 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:29:01.7721 (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: MC9bgYeTCqKQCqrEYZjR/bBXcO4QJDF/UtaQ+NKC36/AUVjAgYMywg3rrawWJBOSuGC+et5koslpitOeSwUHPg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: NFSnPbdZX5VGxgcIajJiilPXx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594736944; bh=Pq+kUCDrq6E3SD8uNLwZtBec76U5smMB4pD55kpbH6k=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=L0V8b80NzNOEI1/f0zDaHvocizEHtNFLeVgPBnb7CO/+CVEraIHH2qbIhhxX8t8/q5y fA3fQ29kJrOdY8QOKa0+mxLHTnC1JaWqNysC78P6/V3jzUQboSgpNdvpkwwb1T5PKcSR5 xGessBji9cv3kyrJozh5HXWEXfmF8q4qdiU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 A new dynamic UefiCpuPkg PCD is needed to support SEV-ES under OVMF: - PcdSevEsIsEnabled: BOOLEAN value used to indicate if SEV-ES is enabled Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Reviewed-by: Eric Dong Signed-off-by: Tom Lendacky --- UefiCpuPkg/UefiCpuPkg.dec | 6 ++++++ UefiCpuPkg/UefiCpuPkg.uni | 3 +++ 2 files changed, 9 insertions(+) diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 762badf5d239..df5d02bae6b4 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -370,5 +370,11 @@ [PcdsDynamic, PcdsDynamicEx] # @ValidRange 0x80000001 | 0 - 1 gUefiCpuPkgTokenSpaceGuid.PcdCpuProcTraceOutputScheme|0x0|UINT8|0x600000= 15 =20 + ## This dynamic PCD indicates whether SEV-ES is enabled + # TRUE - SEV-ES is enabled + # FALSE - SEV-ES is not enabled + # @Prompt SEV-ES Status + gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|FALSE|BOOLEAN|0x60000016 + [UserExtensions.TianoCore."ExtraFiles"] UefiCpuPkgExtra.uni diff --git a/UefiCpuPkg/UefiCpuPkg.uni b/UefiCpuPkg/UefiCpuPkg.uni index 1780dfdc126d..f4a0c72f6293 100644 --- a/UefiCpuPkg/UefiCpuPkg.uni +++ b/UefiCpuPkg/UefiCpuPkg.uni @@ -278,3 +278,6 @@ =20 #string STR_gUefiCpuPkgTokenSpaceGuid_PcdCpuApStatusCheckIntervalInMicroSe= conds_PROMPT #language en-US "Periodic interval value in microseconds for = AP status check in DXE.\n" #string STR_gUefiCpuPkgTokenSpaceGuid_PcdCpuApStatusCheckIntervalInMicroSe= conds_HELP #language en-US "Periodic interval value in microseconds for = the status check of APs for StartupAllAPs() and StartupThisAP() executed in= non-blocking mode in DXE phase.\n" + +#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsIsEnabled_PROMPT #language = en-US "Specifies whether SEV-ES is enabled" +#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsIsEnabled_HELP #language = en-US "Set to TRUE when running as an SEV-ES guest, FALSE otherwise." --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62505): https://edk2.groups.io/g/devel/message/62505 Mute This Topic: https://groups.io/mt/75499738/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62506+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62506+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594736957602110.27560234150212; Tue, 14 Jul 2020 07:29:17 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ZLdwYY1788612xqs2ARTkRj5; Tue, 14 Jul 2020 07:29:17 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.83]) by mx.groups.io with SMTP id smtpd.web11.21037.1594736956399793735 for ; Tue, 14 Jul 2020 07:29:16 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dBhRyxb9Bl3qeK1/wCbq7AC5FC6IMnN5FctT4yJ6hAHzNJ5yfBHMjo5mfA+J97THBIgQ5ffm4R1zQ9iazOw7h5laAhUSMCpsy4PamrleDhwD5oTIsaGY6IeKTEjahFXa+2bVDP25Oy4e9NU2iTW/UdEFJv1dPpLLT7F00vtGXoyEyXEdxCYlzOpVzsWqENM2XkNq4Hwkg+EwF8ZSnf7Pzufe2qagbHd2CxlY/z98EJJPbZDp3S+72HWanXshl91vIEUtItV0i4b/cEzMyQwpvlMFkZw7USowaOorjDAkKWmfSwCFvxKR4T4TMW4Df3sVjiaz7NNKweogLvQ0Z1jCAg== 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=zoB4WdNcnMndSIE8frIBiBw/orhv555JRD+2P5oKvXs=; b=Pc3fn9KwjBtE6unQ8UyKiOK8HbhGCRSGroLko+bokcfziQQ9caDOg0uNGad7fv1Z4SFWk1zF54f5WTCyvNoQwDIHZL57LKLK0hMZgtXaGkdXFIkzwHdXC2gxFdh1e5MK0MhIy+DbqMCCX4ezcyCTSCEVyLXMqkgD4BMxzbgpCuVDuFg7coSZbxOk9x2HDmUeLgBS+PZ5HxVRT17hte3PgpIQ16Oey2RghykAT4c6tkAx2xteIf10UEa281iHAjTLugek+QR45fWSqGhDsYnhTs5isMN+dud8ra6Bmogy0aHK70cVuG51vJfwytjVUR8EJcyhLKo2muSgbFvmB0TqZA== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:29:15 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:29:15 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 03/46] MdePkg: Add the MSR definition for the GHCB register Date: Tue, 14 Jul 2020 09:27:34 -0500 Message-ID: <26a406c31a55f96509c0b298bd45f540d285aa01.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0401CA0004.namprd04.prod.outlook.com (2603:10b6:803:21::14) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0401CA0004.namprd04.prod.outlook.com (2603:10b6:803:21::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17 via Frontend Transport; Tue, 14 Jul 2020 14:29:14 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 613e8676-474f-449f-2329-08d8280248a9 X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: Hv3Xw9YOeizJ3Rj8Iu1gUizodm61OwBgcETSwL5Faj3F4FOcIsirIpsJRF+/5L9ltN+wI2rFu6WoC+nllTYMEFuLv37SM/iilHQHzti+lGEuOjUNm96RtBht0lr/m6bbMMWrp+jo5iG6p+dg0iiRf/lnubbUR0mUYqiq7iFD94EIQwigWZoRl2LxOoKvwG84qHj+CX4R8M5nKZKQ5Z5cIDMLMNGiJAn0yaEVA97oH3VdhB5AfcGguK8Re3lOoAUBjFRXxIg/gf7j/fk0PsCjZ+fkZzcM3pC+T41HSe6vSZCQIlhYa14Iq42D6/1OP7HMoBw/CZH5e0/H6dK+A87HRUzR6EQa9FUeGlQRXx99Lc8wHFP/LWvCuq/oCwhPGGwbAnmgQLw1/FtRAJ1DO3cmdMK50pXk/ygBPV/IUaMReBFFyd+8j9Mas+VSjRLTrVbI2bxqDRBYjQLsgosBo/6NSQ== X-MS-Exchange-AntiSpam-MessageData: aKshpDgC79MNKLAY+7S4FNoyzEBTohwaPaCHjepia0N6NjDrzelNwvQLQtdIvA2hHLAM7n8OHkQ5/XO8pYvUGwYm5K9cmEt33uzH9Ro0mmkFaqOzDYor8/sGDWMvPlzLH5KyTW8S3J+ElHi2NEWpyVEwbHoH7oYVdqMI5EzGbr1U4DXTq8MA3TUrrfqW9VtSeXha/dPu7eaX8pK7dSwWkuv8V9UQ1mwM9APa87WGqRF2GqLfmuthHOsofflJTvgTNXnOSz0byZuQCX/N0ZsrSvoy/8v0HqEmXoYyvlhDCNV19HWseOyL1MERd+Yw/Fx0LmdKjQZj1FVPL0oAFyrJ6MIwjlw7OHp+kJHHSF1JdzAjJk9bhRAn/oq/l/4vsIjHaAGjlKMmM/OkgvViISmK3UwSRFoSJpgdDqiDEOmab/tLuP8xN4SS4DsvoNaK8wkfGDb8/d4puQmmmKTMgGlj/kicuqKoRYPKlHMGuhQEvCA= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 613e8676-474f-449f-2329-08d8280248a9 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:29:15.0883 (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: cZr5+gJU00hQ/auSIqBUEat5uDoMEFS+Xv2q3x+xOd/yfIlzTSbdYjXGU8KFr8WaLjeGmjgrYbgMadlDSbTjYw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: EAsHhJ9mzFcyy7zUaSI9UYX6x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594736957; bh=aGhNShm3nAMhG9KhK5wmXKWf3i/5BlQxUMryieyMIxI=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=ueUUXlQTZoJK6Y9BkN9vHmmV+eRy5dAJCvxmp+V7T0Mm/s+3zm+wo4+2WfXtKnwYrRf uYL6uaNeeaZe3Z5q+o3/OK1IKTBM7XeW+7CNVaibDvNq+AY3rvaMSzrIB5miO49VhZ6ED Q4luy76mLmP8rPuoeDA9R2LrAC7LwviUVlo= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 For SEV-ES, the GHCB page address is stored in the GHCB MSR register (0xc0010130). Define the register and the format used for register during GHCB protocol negotiation. Cc: Michael D Kinney Cc: Liming Gao Signed-off-by: Tom Lendacky --- MdePkg/Include/Register/Amd/Fam17Msr.h | 46 ++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/MdePkg/Include/Register/Amd/Fam17Msr.h b/MdePkg/Include/Regist= er/Amd/Fam17Msr.h index 6ef45a9b21d3..e4db09c5184c 100644 --- a/MdePkg/Include/Register/Amd/Fam17Msr.h +++ b/MdePkg/Include/Register/Amd/Fam17Msr.h @@ -17,6 +17,52 @@ #ifndef __FAM17_MSR_H__ #define __FAM17_MSR_H__ =20 +/** + Secure Encrypted Virtualization - Encrypted State (SEV-ES) GHCB register + +**/ +#define MSR_SEV_ES_GHCB 0xc0010130 + +/** + MSR information returned for #MSR_SEV_ES_GHCB +**/ +typedef union { + struct { + UINT32 Function:12; + UINT32 Reserved1:20; + UINT32 Reserved2:32; + } GhcbInfo; + + struct { + UINT8 Reserved[3]; + UINT8 SevEncryptionBitPos; + UINT16 SevEsProtocolMin; + UINT16 SevEsProtocolMax; + } GhcbProtocol; + + struct { + UINT32 Function:12; + UINT32 ReasonCodeSet:4; + UINT32 ReasonCode:8; + UINT32 Reserved1:8; + UINT32 Reserved2:32; + } GhcbTerminate; + + VOID *Ghcb; + + UINT64 GhcbPhysicalAddress; +} MSR_SEV_ES_GHCB_REGISTER; + +#define GHCB_INFO_SEV_INFO 1 +#define GHCB_INFO_SEV_INFO_GET 2 +#define GHCB_INFO_CPUID_REQUEST 4 +#define GHCB_INFO_CPUID_RESPONSE 5 +#define GHCB_INFO_TERMINATE_REQUEST 256 + +#define GHCB_TERMINATE_GHCB 0 +#define GHCB_TERMINATE_GHCB_GENERAL 0 +#define GHCB_TERMINATE_GHCB_PROTOCOL 1 + /** Secure Encrypted Virtualization (SEV) status register =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62506): https://edk2.groups.io/g/devel/message/62506 Mute This Topic: https://groups.io/mt/75499744/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62507+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62507+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594736970974122.67103338254822; Tue, 14 Jul 2020 07:29:30 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 9MHLYY1788612xmau7guO1Ha; Tue, 14 Jul 2020 07:29:30 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.72]) by mx.groups.io with SMTP id smtpd.web12.20808.1594736969831762012 for ; Tue, 14 Jul 2020 07:29:29 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oFhEimQyDiKy2nZr8tEWA82ddwD5hKvgIwoe3S3gvHsWaiU1BrGyxpzQQr+S8EYWCXPJn4/CiXbI9yBCy0SJ+x4Wy21I1CMwBH2B9a7T9DpLeo0TpBZSqPH4TorjrRy5/T4AekcjjL4AG1VZOdS6kCSrcepU7N6+HFRKHSNAmjmcpyCyWfYqFPxMFNDpAMUuLqyn5A+rGR1t/aGhmB6KP2NHx91OrIRHtbzf/+FXNCFB8kkD/Dlt9VoUfKY5EI/N5SDgyLpdwnX+rxZDveVpKG3O//tQfg3EdrjmiMA6p6bZetawTOSlYs+pqyxNp4SsIJgYCPRRffBMqnPwFHGJFw== 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=ZgE2Sj67C3LtS3PnR3u+8JIYDmbxku5n7Xkbew9f6S4=; b=VpGtwIDj8HsgNicbym8L8sM6+Q/s4SesC0nTWnq53aT7RL9I0enens8k6CZu/16BONdJJ7GQ4N/QyYJrjw5NKCkpEWaTd4gDixUAjVg8Qyw0OH077CdgOf2ARqcoUa3OMLC1Oe7iVIcmSCwFIZBHxKX7HLRHwmFNEUa9DsqFtrjfz/W351yckayDhtjmcbs3OUBSKBfg0uTFkC9TbQ91ssXNHgOh2PZ9T2Td76Usoqv/MDFqymH8Y24BHLUrMmv7qGtkdpb0jkWER3ky5Qca/11BJkhD13MzNW3ZfCj+0+5CDuMCZj8ipVt+ZcOpjf03aQURCXNxov2leRR62PwfkA== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:29:28 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:29:28 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 04/46] MdePkg: Add a structure definition for the GHCB Date: Tue, 14 Jul 2020 09:27:35 -0500 Message-ID: <2477eaab824041dcfb61ed24c6ace8fa01839486.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0146.namprd05.prod.outlook.com (2603:10b6:803:2c::24) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0501CA0146.namprd05.prod.outlook.com (2603:10b6:803:2c::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.10 via Frontend Transport; Tue, 14 Jul 2020 14:29:27 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 15a8eb18-ac91-4bc4-672c-08d82802505b X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: xl/pijJdAJZXb8/Rakkf26waYz7Sq34mLgks5Xn420uPoEZGZP5FnuonxKMZ1j6M2JygcptsWY5T+AWq4M+j4qEG8UJdcOuGmrKzN4U6uO3ISM00nrPlHM5PIUZW0h+pjOz4K+Rsqakxx3r7wNdN0CljE0mrJvJfBqsIHQS3jwgENFFV5wTidXXSbbd8nNkx4kdo+OxVhmNSRkQIqkbPfItaSNBPg0wSLMS7kOGkyGmB91a3wJ7g7ZgcDqEOk4SfOlnHIYk3odMbK+YPiI/8NSOMemtTMwOQC6ZckLsJb4gFHK8ywd/36NSjqmqcgfqutWu8sTGEG3KbqmgM3uq/j7nmd020qYywfKwISWb7vmfOeRBP6kw96viKfMLIgjG+SpRlUcYb4kT5VmoBRw8UhLhc/nq3hkrUNzU7ckV4dymZHpWuSBalfCgx6sgdzFpCDOD7grrMmLXMnOQFGvrkAw== X-MS-Exchange-AntiSpam-MessageData: nPHE+HxFGt7d47t84voi19/6BRn7knfDhoCR5U3brNE+CTYyugXqtpgpjn//f/rF6coirs6eoJOahdKpF+l9aimwAMA0zt/aiDrtoRdS3Sj1kOQ5Bdl+XEcLCMmMW0TM7VaGpcCyiSs4Z1mhoI2xMuUv//9xhNj3qvHUKuHmC8d4OA3eH73FCqYNqiw1jKUR1NhGvOgaeo3KE4oEz6x486QD1sBgosXpBYldo7NzgCPSaqjonrCjU8QIvUaJfKtAQcN4kTXJewbwlrODvJFLB84nleS7NsdLwYViqKilQcjjCOks1iHgULNbOmqK3UT9VtM6xoafIBvW3Wg0ckvAbF6kqcKNyyy0xs4B7/f8EQz0exVJPbntY6SsJeXOVm+gbR1V7+r3d9826KhE0MnOqfZUBP+/jO918OTom58GZd6LQKCA2gFnOutsgX4ysfeJ5XQYF2/JHQ1uvqz2hIXrl5ofqmJCvWVyNANWlYh0d7o= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 15a8eb18-ac91-4bc4-672c-08d82802505b X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:29:27.9106 (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: nxB4hB/heIVK5kfp2LcXeuFkMQ+1UB6ZWPu/PdnoyhlF5sZM3UBfU7nBwDdyCLH3QDRFNyXyseUbVtdhMxxaRw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: swjuvCGuAKF4acHZ2ZMfBpeAx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594736970; bh=zhH1hTksAFlEGRFSsITX5rS6ubfJTeB3i2OxoTma1dY=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=wx/ylcMXliDG5bRBfnqxPfwxSZmRCoV5qW3x81SkrYgU77LnLK1lcPyTSukGMwZpO+z JzoYvzZoAknPeM2uExklh6s/V/dBZ2Lnb4EjgmN/fzP6NeYliqTzgeH00ciACkQMo7MW4 AOnl0JaIAxtAxntKiujmTxAyc6rpMHbslRQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 The GHCB is used by an SEV-ES guest for communicating between the guest and the hypervisor. Create the GHCB definition as defined by the GHCB protocol definition. Cc: Michael D Kinney Cc: Liming Gao Signed-off-by: Tom Lendacky --- MdePkg/Include/Register/Amd/Ghcb.h | 166 +++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 MdePkg/Include/Register/Amd/Ghcb.h diff --git a/MdePkg/Include/Register/Amd/Ghcb.h b/MdePkg/Include/Register/A= md/Ghcb.h new file mode 100644 index 000000000000..54a80da0f6d7 --- /dev/null +++ b/MdePkg/Include/Register/Amd/Ghcb.h @@ -0,0 +1,166 @@ +/** @file + Guest-Hypervisor Communication Block (GHCB) Definition. + + Provides data types allowing an SEV-ES guest to interact with the hyperv= isor + using the GHCB protocol. + + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Specification Reference: + SEV-ES Guest-Hypervisor Communication Block Standardization + +**/ + +#ifndef __GHCB_H__ +#define __GHCB_H__ + +#include +#include +#include + +#define UD_EXCEPTION 6 +#define GP_EXCEPTION 13 +#define VC_EXCEPTION 29 + +#define GHCB_VERSION_MIN 1 +#define GHCB_VERSION_MAX 1 + +#define GHCB_STANDARD_USAGE 0 + +// +// SVM Exit Codes +// +#define SVM_EXIT_DR7_READ 0x27ULL +#define SVM_EXIT_DR7_WRITE 0x37ULL +#define SVM_EXIT_RDTSC 0x6EULL +#define SVM_EXIT_RDPMC 0x6FULL +#define SVM_EXIT_CPUID 0x72ULL +#define SVM_EXIT_INVD 0x76ULL +#define SVM_EXIT_IOIO_PROT 0x7BULL +#define SVM_EXIT_MSR 0x7CULL +#define SVM_EXIT_VMMCALL 0x81ULL +#define SVM_EXIT_RDTSCP 0x87ULL +#define SVM_EXIT_WBINVD 0x89ULL +#define SVM_EXIT_MONITOR 0x8AULL +#define SVM_EXIT_MWAIT 0x8BULL +#define SVM_EXIT_NPF 0x400ULL + +// +// VMG Special Exit Codes +// +#define SVM_EXIT_MMIO_READ 0x80000001ULL +#define SVM_EXIT_MMIO_WRITE 0x80000002ULL +#define SVM_EXIT_NMI_COMPLETE 0x80000003ULL +#define SVM_EXIT_AP_RESET_HOLD 0x80000004ULL +#define SVM_EXIT_AP_JUMP_TABLE 0x80000005ULL +#define SVM_EXIT_UNSUPPORTED 0x8000FFFFULL + +// +// IOIO Exit Information +// +#define IOIO_TYPE_STR BIT2 +#define IOIO_TYPE_IN 1 +#define IOIO_TYPE_INS (IOIO_TYPE_IN | IOIO_TYPE_STR) +#define IOIO_TYPE_OUT 0 +#define IOIO_TYPE_OUTS (IOIO_TYPE_OUT | IOIO_TYPE_STR) + +#define IOIO_REP BIT3 + +#define IOIO_ADDR_64 BIT9 +#define IOIO_ADDR_32 BIT8 +#define IOIO_ADDR_16 BIT7 + +#define IOIO_DATA_32 BIT6 +#define IOIO_DATA_16 BIT5 +#define IOIO_DATA_8 BIT4 +#define IOIO_DATA_MASK (BIT6 | BIT5 | BIT4) +#define IOIO_DATA_OFFSET 4 +#define IOIO_DATA_BYTES(x) (((x) & IOIO_DATA_MASK) >> IOIO_DATA_OFFSET) + +#define IOIO_SEG_ES 0 +#define IOIO_SEG_DS (BIT11 | BIT10) + + +typedef enum { + GhcbCpl =3D 25, + GhcbRflags =3D 46, + GhcbRip, + GhcbRsp =3D 59, + GhcbRax =3D 63, + GhcbRcx =3D 97, + GhcbRdx, + GhcbRbx, + GhcbRbp =3D 101, + GhcbRsi, + GhcbRdi, + GhcbR8, + GhcbR9, + GhcbR10, + GhcbR11, + GhcbR12, + GhcbR13, + GhcbR14, + GhcbR15, + GhcbXCr0 =3D 125, +} GHCB_REGISTER; + +typedef PACKED struct { + UINT8 Reserved1[203]; + UINT8 Cpl; + UINT8 Reserved2[148]; + UINT64 Dr7; + UINT8 Reserved3[144]; + UINT64 Rax; + UINT8 Reserved4[264]; + UINT64 Rcx; + UINT64 Rdx; + UINT64 Rbx; + UINT8 Reserved5[112]; + UINT64 SwExitCode; + UINT64 SwExitInfo1; + UINT64 SwExitInfo2; + UINT64 SwScratch; + UINT8 Reserved6[56]; + UINT64 XCr0; + UINT8 ValidBitmap[16]; + UINT64 X87StateGpa; + UINT8 Reserved7[1016]; +} GHCB_SAVE_AREA; + +typedef PACKED struct { + GHCB_SAVE_AREA SaveArea; + UINT8 SharedBuffer[2032]; + UINT8 Reserved1[10]; + UINT16 ProtocolVersion; + UINT32 GhcbUsage; +} GHCB; + +typedef union { + struct { + UINT32 Lower32Bits; + UINT32 Upper32Bits; + } Elements; + + UINT64 Uint64; +} GHCB_EXIT_INFO; + +typedef union { + struct { + UINT32 Vector:8; + UINT32 Type:3; + UINT32 ErrorCodeValid:1; + UINT32 Rsvd:19; + UINT32 Valid:1; + UINT32 ErrorCode; + } Elements; + + UINT64 Uint64; +} GHCB_EVENT_INJECTION; + +#define GHCB_EVENT_INJECTION_TYPE_INT 0 +#define GHCB_EVENT_INJECTION_TYPE_NMI 2 +#define GHCB_EVENT_INJECTION_TYPE_EXCEPTION 3 +#define GHCB_EVENT_INJECTION_TYPE_SOFT_INT 4 + +#endif --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62507): https://edk2.groups.io/g/devel/message/62507 Mute This Topic: https://groups.io/mt/75499749/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62508+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62508+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594736982970708.5442451866401; Tue, 14 Jul 2020 07:29:42 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id pWRcYY1788612xaw3064wICS; Tue, 14 Jul 2020 07:29:42 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.73]) by mx.groups.io with SMTP id smtpd.web10.21035.1594736981910208944 for ; Tue, 14 Jul 2020 07:29:42 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ktveEYcNkxrOqiTkqZtrWDudG3WP/4r8CQlSry53mtHeWsieoH9mm2ZuD7Hh2QsSha5lQpmbspZ+EypeOnCINCRlXGPnU9u6c65XhxkkerYrCUHbL5mt3hmkCwV3l8jiC2jYOyv1FnTSNpF3TMdXM4eqB037rxY7xxQo2n3GiwJ7wbfNfgNXaInvZZr1xbbnCOT6/M6WGsKzzucwdWZ6QRp+YRy4eIH4uUNeTNlT2afSx1k6SXgve2cuNvUI+s/wLHms89Z9gJR4qNNAI6sce66JSqq3LG64Q+8uvLpDe8zJ3LmcyiyKa03+VnP1sY8M5+60FRjyvSGjXxGxD5cT4Q== 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=1CQV39IMQU98kDP7Cw8EBWMcqMw2WdJpQzO/hKKOH84=; b=WdAeXGHrT5qAvO7V+e7poLavfi1ufBfPb6fugWswOlUUOz283IoqOehxk9fUEb+scPJ35FCen5T5VTbuh79Z263Hww9T8JhaiSsqGvmB6nsctgu54hcjGVBzA988OAANdKjwXAjfUcEH4pgK7dn0kKKdnpLaowN4jRRnyTdMjmYtF6T0E0jKs/o/8OsLeVR4efNlViFMJE/oPUWxWPJQVptckAnqP+pQvsokCQLekKeiB6/G0yHUnlFs7TkmVzYOtpu9mjS3VWxvoSGeOMv1mj5OYLZIhmEfbibASU8lkz2onLy2NgTJfasrZuY4XA/tomr6k6dfZIVWRqRIGEE7mQ== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:29:40 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:29:40 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni , Jian J Wang , Hao A Wu , Dandan Bi Subject: [edk2-devel] [PATCH v10 05/46] MdeModulePkg/DxeIplPeim: Support GHCB pages when creating page tables Date: Tue, 14 Jul 2020 09:27:36 -0500 Message-ID: <1730cc8f57d24b5b0b73067d4dc72ec6d2d02889.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0701CA0001.namprd07.prod.outlook.com (2603:10b6:803:28::11) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0701CA0001.namprd07.prod.outlook.com (2603:10b6:803:28::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17 via Frontend Transport; Tue, 14 Jul 2020 14:29:39 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 5ecc02ba-8359-430a-b376-08d82802579f X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: pV0TaHTJp0w5eMo5pc7EBQETt1hdNFkrvl5yM3M80fMwrO2mNNe8zFfl61ojgzf/p+cpcVxtl5nB/LRFXnqWpNiqdhXVWK0+SaWIRqADCcH59wV1sdydWP+I7ZI2xjlo51OZC4Y8+blBwkPT0ukAOe3B9ZAwhLU0s/H50EVEWcR1eoCgR+gSGBhY+Ao4wRXxwLj8dSNY6zkqM/vlVfQi/mfvkNhOSGOC2evUd0aZlMWNpVTNZmv6Z0AzHvNcgGhO2qjXeH+S9dGVy/l43gOZmAedJIftE7YRhibsSLh5hW12K7c6tVrl1tfyXNUaxgPmPdodTiedp/hlRmDpah/g8QnQghu7xxQreZVXlpZEAe4bkP9sfQYL74s+P0t018Wyohwe21xZbbAPKF1drV4/wTKsK50ewu2WcLSTCUcw2RQlrSo6i/bMFRnJg3KHcKIWs1eYfPEOWrmx+MjhECNHiA== X-MS-Exchange-AntiSpam-MessageData: YeVpReSnxGIIjqZGMhoED8xAqPnjCdLgwP6SSc/MfhkcUrTEyFPPGHzYY/G4kZ8qQ59+Gt2+5kNvrpSTydjIcCZVz3F8Zc7soI+BJ2XBVCRhfk4yuVMe8bqvM07DxSW2YHcVD4PwMXGSVN8AlVYb8teFyXzHb8YGScL+0VBmrmBgg/TQGod91t4LlPDCmmZjC2nu9B95YmoXCwcdhJKHQlyZe3+W7yluc05vW3XOtpKuYkZME7aBNG4z02DHOT1T3+oPerYsnadK3k4nrMu+cEesSgG0WL4J5Dk1orOBBjRUfENgAop32GoCtq89uZj9Vi9cA78cvIXR8pX4x/PInlvithwaByWnCUFB6NxIvZY7fKgWTx6AbLGLc5SxAk62JOO+KBjHWpWlnD6zHuNPhHAUaX2FmD5TC4tJuqc7sPRykRocMbzOSg7Ue4NuU505mgiEz41RprcADvtQrthqlpEj5iejsBteyz5ZTnZUepQ= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5ecc02ba-8359-430a-b376-08d82802579f X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:29:40.0653 (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: 9Y/Lc11skn+ZZqbaZGrUoA7c9uHWZHhTusgR1+QLi0u0C/lNYcEQLsnqhFu7hE1gU9lkmLvDYktvGHhcn4LhZg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: nEPI2P9oR1VqFVMZVKgHFaA1x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594736982; bh=YW5L2W2rDC+8/fB5/Hq0ITRoZUeS1CHifskLPVaELrY=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=ijBmD0yrVHg/WrJ6cSvGgqtSCfj2xOe0K9/VwkLUDD4kRrG4zFEPhyUYFMdqOgizxBG kYx43PCsTtuur5tsRQX6n2NynUm2VTiKs6ksVoUNqMcCo2LCII/Fm7p2mQFEah+B2kuER p2+HHzvUdOZujnPKBuC5Ken592Rv8v3bM8E= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 GHCB pages must be mapped as shared pages, so modify the process of creating identity mapped pagetable entries so that GHCB entries are created without the encryption bit set. The GHCB range consists of two pages per CPU, the first being the GHCB and the second being a per-CPU variable page. Only the GHCB page is mapped as shared. Cc: Jian J Wang Cc: Hao A Wu Cc: Dandan Bi Cc: Liming Gao Signed-off-by: Tom Lendacky --- MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf | 2 + .../Core/DxeIplPeim/X64/VirtualMemory.h | 12 +++- .../Core/DxeIplPeim/Ia32/DxeLoadFunc.c | 4 +- .../Core/DxeIplPeim/X64/DxeLoadFunc.c | 11 +++- .../Core/DxeIplPeim/X64/VirtualMemory.c | 57 +++++++++++++++---- 5 files changed, 70 insertions(+), 16 deletions(-) diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf b/MdeModulePkg/Core/Dx= eIplPeim/DxeIpl.inf index 3f1702854660..19b8a4c8aefa 100644 --- a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf +++ b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf @@ -115,6 +115,8 @@ [Pcd.IA32,Pcd.X64] gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPropertyMask ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdUse5LevelPageTable ##= SOMETIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase ##= CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize ##= CONSUMES =20 [Pcd.IA32,Pcd.X64,Pcd.ARM,Pcd.AARCH64] gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ## SOMETIM= ES_CONSUMES diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h b/MdeModulePk= g/Core/DxeIplPeim/X64/VirtualMemory.h index 2d0493f109e8..6b7c38a441d6 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h +++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h @@ -201,6 +201,8 @@ EnableExecuteDisableBit ( @param[in, out] PageEntry2M Pointer to 2M page entry. @param[in] StackBase Stack base address. @param[in] StackSize Stack size. + @param[in] GhcbBase GHCB page area base address. + @param[in] GhcbSize GHCB page area size. =20 **/ VOID @@ -208,7 +210,9 @@ Split2MPageTo4K ( IN EFI_PHYSICAL_ADDRESS PhysicalAddress, IN OUT UINT64 *PageEntry2M, IN EFI_PHYSICAL_ADDRESS StackBase, - IN UINTN StackSize + IN UINTN StackSize, + IN EFI_PHYSICAL_ADDRESS GhcbBase, + IN UINTN GhcbSize ); =20 /** @@ -217,6 +221,8 @@ Split2MPageTo4K ( =20 @param[in] StackBase Stack base address. @param[in] StackSize Stack size. + @param[in] GhcbBase GHCB page area base address. + @param[in] GhcbSize GHCB page area size. =20 @return The address of 4 level page map. =20 @@ -224,7 +230,9 @@ Split2MPageTo4K ( UINTN CreateIdentityMappingPageTables ( IN EFI_PHYSICAL_ADDRESS StackBase, - IN UINTN StackSize + IN UINTN StackSize, + IN EFI_PHYSICAL_ADDRESS GhcbBase, + IN UINTN GhcbkSize ); =20 =20 diff --git a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c b/MdeModulePkg= /Core/DxeIplPeim/Ia32/DxeLoadFunc.c index 6e8ca824d469..284b34818ca7 100644 --- a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c +++ b/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c @@ -123,7 +123,7 @@ Create4GPageTablesIa32Pae ( // // Need to split this 2M page that covers stack range. // - Split2MPageTo4K (PhysicalAddress, (UINT64 *) PageDirectoryEntry, S= tackBase, StackSize); + Split2MPageTo4K (PhysicalAddress, (UINT64 *) PageDirectoryEntry, S= tackBase, StackSize, 0, 0); } else { // // Fill in the Page Directory entries @@ -282,7 +282,7 @@ HandOffToDxeCore ( // // Create page table and save PageMapLevel4 to CR3 // - PageTables =3D CreateIdentityMappingPageTables (BaseOfStack, STACK_SIZ= E); + PageTables =3D CreateIdentityMappingPageTables (BaseOfStack, STACK_SIZ= E, 0, 0); =20 // // End of PEI phase signal diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c b/MdeModulePkg/= Core/DxeIplPeim/X64/DxeLoadFunc.c index f465eb1d8ac4..156a477d8467 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c +++ b/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c @@ -35,6 +35,8 @@ HandOffToDxeCore ( UINT32 Index; EFI_VECTOR_HANDOFF_INFO *VectorInfo; EFI_PEI_VECTOR_HANDOFF_INFO_PPI *VectorHandoffInfoPpi; + VOID *GhcbBase; + UINTN GhcbSize; =20 // // Clear page 0 and mark it as allocated if NULL pointer detection is en= abled. @@ -81,12 +83,19 @@ HandOffToDxeCore ( TopOfStack =3D (VOID *) ((UINTN) BaseOfStack + EFI_SIZE_TO_PAGES (STACK_= SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT); TopOfStack =3D ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT); =20 + // + // Get the address and size of the GHCB pages + // + GhcbBase =3D (VOID *) PcdGet64 (PcdGhcbBase); + GhcbSize =3D PcdGet64 (PcdGhcbSize); + PageTables =3D 0; if (FeaturePcdGet (PcdDxeIplBuildPageTables)) { // // Create page table and save PageMapLevel4 to CR3 // - PageTables =3D CreateIdentityMappingPageTables ((EFI_PHYSICAL_ADDRESS)= (UINTN) BaseOfStack, STACK_SIZE); + PageTables =3D CreateIdentityMappingPageTables ((EFI_PHYSICAL_ADDRESS)= (UINTN) BaseOfStack, STACK_SIZE, + (EFI_PHYSICAL_ADDRESS) (= UINTN) GhcbBase, GhcbSize); } else { // // Set NX for stack feature also require PcdDxeIplBuildPageTables be T= RUE diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c b/MdeModulePk= g/Core/DxeIplPeim/X64/VirtualMemory.c index 516cf908bc88..6831946c54d3 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c +++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c @@ -181,6 +181,8 @@ EnableExecuteDisableBit ( @param Size Size of the given physical memory. @param StackBase Base address of stack. @param StackSize Size of stack. + @param GhcbBase Base address of GHCB pages. + @param GhcbSize Size of GHCB area. =20 @retval TRUE Page table should be split. @retval FALSE Page table should not be split. @@ -190,7 +192,9 @@ ToSplitPageTable ( IN EFI_PHYSICAL_ADDRESS Address, IN UINTN Size, IN EFI_PHYSICAL_ADDRESS StackBase, - IN UINTN StackSize + IN UINTN StackSize, + IN EFI_PHYSICAL_ADDRESS GhcbBase, + IN UINTN GhcbSize ) { if (IsNullDetectionEnabled () && Address =3D=3D 0) { @@ -209,6 +213,12 @@ ToSplitPageTable ( } } =20 + if (GhcbBase !=3D 0) { + if ((Address < GhcbBase + GhcbSize) && ((Address + Size) > GhcbBase)) { + return TRUE; + } + } + return FALSE; } /** @@ -322,6 +332,8 @@ AllocatePageTableMemory ( @param[in, out] PageEntry2M Pointer to 2M page entry. @param[in] StackBase Stack base address. @param[in] StackSize Stack size. + @param[in] GhcbBase GHCB page area base address. + @param[in] GhcbSize GHCB page area size. =20 **/ VOID @@ -329,7 +341,9 @@ Split2MPageTo4K ( IN EFI_PHYSICAL_ADDRESS PhysicalAddress, IN OUT UINT64 *PageEntry2M, IN EFI_PHYSICAL_ADDRESS StackBase, - IN UINTN StackSize + IN UINTN StackSize, + IN EFI_PHYSICAL_ADDRESS GhcbBase, + IN UINTN GhcbSize ) { EFI_PHYSICAL_ADDRESS PhysicalAddress4K; @@ -355,7 +369,20 @@ Split2MPageTo4K ( // // Fill in the Page Table entries // - PageTableEntry->Uint64 =3D (UINT64) PhysicalAddress4K | AddressEncMask; + PageTableEntry->Uint64 =3D (UINT64) PhysicalAddress4K; + + // + // The GHCB range consists of two pages per CPU, the GHCB and a + // per-CPU variable page. The GHCB page needs to be mapped as an + // unencrypted page while the per-CPU variable page needs to be + // mapped encrypted. These pages alternate in assignment. + // + if ((GhcbBase =3D=3D 0) + || (PhysicalAddress4K < GhcbBase) + || (PhysicalAddress4K >=3D GhcbBase + GhcbSize) + || (((PhysicalAddress4K - GhcbBase) & SIZE_4KB) !=3D 0)) { + PageTableEntry->Uint64 |=3D AddressEncMask; + } PageTableEntry->Bits.ReadWrite =3D 1; =20 if ((IsNullDetectionEnabled () && PhysicalAddress4K =3D=3D 0) || @@ -383,6 +410,8 @@ Split2MPageTo4K ( @param[in, out] PageEntry1G Pointer to 1G page entry. @param[in] StackBase Stack base address. @param[in] StackSize Stack size. + @param[in] GhcbBase GHCB page area base address. + @param[in] GhcbSize GHCB page area size. =20 **/ VOID @@ -390,7 +419,9 @@ Split1GPageTo2M ( IN EFI_PHYSICAL_ADDRESS PhysicalAddress, IN OUT UINT64 *PageEntry1G, IN EFI_PHYSICAL_ADDRESS StackBase, - IN UINTN StackSize + IN UINTN StackSize, + IN EFI_PHYSICAL_ADDRESS GhcbBase, + IN UINTN GhcbSize ) { EFI_PHYSICAL_ADDRESS PhysicalAddress2M; @@ -413,11 +444,11 @@ Split1GPageTo2M ( =20 PhysicalAddress2M =3D PhysicalAddress; for (IndexOfPageDirectoryEntries =3D 0; IndexOfPageDirectoryEntries < 51= 2; IndexOfPageDirectoryEntries++, PageDirectoryEntry++, PhysicalAddress2M += =3D SIZE_2MB) { - if (ToSplitPageTable (PhysicalAddress2M, SIZE_2MB, StackBase, StackSiz= e)) { + if (ToSplitPageTable (PhysicalAddress2M, SIZE_2MB, StackBase, StackSiz= e, GhcbBase, GhcbSize)) { // // Need to split this 2M page that covers NULL or stack range. // - Split2MPageTo4K (PhysicalAddress2M, (UINT64 *) PageDirectoryEntry, S= tackBase, StackSize); + Split2MPageTo4K (PhysicalAddress2M, (UINT64 *) PageDirectoryEntry, S= tackBase, StackSize, GhcbBase, GhcbSize); } else { // // Fill in the Page Directory entries @@ -616,6 +647,8 @@ EnablePageTableProtection ( =20 @param[in] StackBase Stack base address. @param[in] StackSize Stack size. + @param[in] GhcbBase GHCB base address. + @param[in] GhcbSize GHCB size. =20 @return The address of 4 level page map. =20 @@ -623,7 +656,9 @@ EnablePageTableProtection ( UINTN CreateIdentityMappingPageTables ( IN EFI_PHYSICAL_ADDRESS StackBase, - IN UINTN StackSize + IN UINTN StackSize, + IN EFI_PHYSICAL_ADDRESS GhcbBase, + IN UINTN GhcbSize ) { UINT32 RegEax; @@ -809,8 +844,8 @@ CreateIdentityMappingPageTables ( PageDirectory1GEntry =3D (VOID *) PageDirectoryPointerEntry; =20 for (IndexOfPageDirectoryEntries =3D 0; IndexOfPageDirectoryEntrie= s < 512; IndexOfPageDirectoryEntries++, PageDirectory1GEntry++, PageAddress= +=3D SIZE_1GB) { - if (ToSplitPageTable (PageAddress, SIZE_1GB, StackBase, StackSiz= e)) { - Split1GPageTo2M (PageAddress, (UINT64 *) PageDirectory1GEntry,= StackBase, StackSize); + if (ToSplitPageTable (PageAddress, SIZE_1GB, StackBase, StackSiz= e, GhcbBase, GhcbSize)) { + Split1GPageTo2M (PageAddress, (UINT64 *) PageDirectory1GEntry,= StackBase, StackSize, GhcbBase, GhcbSize); } else { // // Fill in the Page Directory entries @@ -840,11 +875,11 @@ CreateIdentityMappingPageTables ( PageDirectoryPointerEntry->Bits.Present =3D 1; =20 for (IndexOfPageDirectoryEntries =3D 0; IndexOfPageDirectoryEntr= ies < 512; IndexOfPageDirectoryEntries++, PageDirectoryEntry++, PageAddress= +=3D SIZE_2MB) { - if (ToSplitPageTable (PageAddress, SIZE_2MB, StackBase, StackS= ize)) { + if (ToSplitPageTable (PageAddress, SIZE_2MB, StackBase, StackS= ize, GhcbBase, GhcbSize)) { // // Need to split this 2M page that covers NULL or stack rang= e. // - Split2MPageTo4K (PageAddress, (UINT64 *) PageDirectoryEntry,= StackBase, StackSize); + Split2MPageTo4K (PageAddress, (UINT64 *) PageDirectoryEntry,= StackBase, StackSize, GhcbBase, GhcbSize); } else { // // Fill in the Page Directory entries --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62508): https://edk2.groups.io/g/devel/message/62508 Mute This Topic: https://groups.io/mt/75499754/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62509+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62509+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594736996559442.87649329332885; Tue, 14 Jul 2020 07:29:56 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Vn7TYY1788612xVhtMM2gou7; Tue, 14 Jul 2020 07:29:56 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.42]) by mx.groups.io with SMTP id smtpd.web12.20815.1594736994006770336 for ; Tue, 14 Jul 2020 07:29:54 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C2EDQqCIF9ldBsYAlPgx+s5Cu5F7Do7Oba4aWFQXH4sNNpRZNS29SD5HvsYi1QnZEk8wKqYf8ndyAEDtlXhcLrMWRcHNyyNftccQMmR7gWoy4c0YjR6gRgxbJMJYOMCuVa9B69sDmHmeppET96LBhqS2IzmMwUSy2iGvbHFh+T2AUDpTlTE+0uzpwT6JIphXQm9tgs6eNcqt6bVgt2WdtGBNxw8tnuKj4uTEPyqF32+8SCXCyaUm/Epl+MAk++psBCrl2HiF/rF9at0ZRL3CDk1/2qq9JkAU4CGWi2Cmm7ltiz864/Egb4oKblTtZ3M747kOUKGD/lWdoeOX9p7Fog== 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=wHT+9p3Ix04N8NYMbxglSKlPnBzGdXyERAysc3OSUPU=; b=YTodY8jnZ6mh/ARjmwbXP4b1Gp+8H4DADVRAj3AAhJD+ljfl2p7ZRq2LhhIDpq0F0qyIHNPa+32B2wSgXJGg/I3HVHN9gbTma8toB2znaJXnSQyTvIqidSQK0uJLhE8QdzveRJ5ps1sZ9SuzKEaCI59iapAi/V+h6k14xqe69VlRCY1ePrcR7LRnZs7WMHqTerbA9w+PfmVZBfbt6+Fp7In1c1JDpuy0t3Xx1E27O4T9RAjm+ZgC4LBcOgvsu4VrJMLrFw7TAsS30vd4iDEfQxl9EaEgRAUXbSMbYIM9sbdu7PyxEFCtcLz0HvakxHHj47jB8WvKObmjt2sOkQhETA== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:29:52 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:29:52 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 06/46] MdePkg/BaseLib: Add support for the XGETBV instruction Date: Tue, 14 Jul 2020 09:27:37 -0500 Message-ID: <20ddae98568fa4379cf10a73baef1418f5de307f.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN1PR12CA0073.namprd12.prod.outlook.com (2603:10b6:802:20::44) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN1PR12CA0073.namprd12.prod.outlook.com (2603:10b6:802:20::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22 via Frontend Transport; Tue, 14 Jul 2020 14:29:51 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: be1ea107-e926-4e92-c06a-08d828025f2c X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: OjN7euM0fRDvl8l5zvd6K9RadTxCLwki9/vwcK36XyZuIWk92MXF1p0sktWkSLaCICQJ3IcoMuEBXa7ranGGGiPe1AVcXWAxEYshCsEE0QM5R/PgC8B8Mv/6Wnc6CSzB6umchixca8zWD6bEIG//tffztl0n0PrS+tYA/Q75QppwUN3JERQi1RxEPHfcV2JYaNNc87vxO6djeL5XkKAys6cUc91nyB0he4WPG+o6wEaM2DB2PDv4CEces02BdGTMd9zHPHxwX6P0TFNX0rLEo+/lea2VtNBubxa7WxHrdSksFj7w3LjoofyJUAxhU460SEsO67S32pmrOn/UGqGUs+Q0MDuf4Bn3jW6SGV5fwNU30bpP8bLVGU5c2uWoS9jHEst/QVBvKEJiPYEg7E6fUTNOhDaWI9UYteBpGp3S/q7G4MWu1+fBB2HFjEP1/YL5AjKlNpxa7zXBXg13EBmAdA== X-MS-Exchange-AntiSpam-MessageData: OIQjglk6eNsDottI8SD/6vOQR0kERRiDkSu9eIIhNwBjeN99ReKXT9p67Io3vTU34JG2h6w+PhasI+FvMT791BVCc3W7dr/viwe5fRvoddEKokOhwF0F1MPUuZXMj8I4/Y/8HtylCNUM2HpJiwAbXPYb2I/TKC58b63l9eF6ijjfo7bFhC2V2hJ/GxZKmCrjaN6ZR137MkqfpB36N5Ig1UwGDL9CQCSAi00CfpOw3FmKcz86nhyXNFYKvqhGIsamEADTFjRdRHSFn+S9mbd5BYr+NkpNcrLirFLOYIwT1jSIpmFObSc2NR2/6go7uMVJNX5HP/zr9tSYrV2GQessx5NKH+xnpleMaHqg/l+uUyLKeaAPdZMqxF8ppuSgp1dPomRPVqdwNqCA/Wez8mdTOVYI+EzqkRwLzvTgeAOe/cbJQQ1ihw3Vcy3TJWS2e7GTLtNZ28JMNa8LL2Nb30h15EPrM/wIP0YN7qMr7RDGnn4= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: be1ea107-e926-4e92-c06a-08d828025f2c X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:29:52.7338 (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: jDNgVglkHve2CCZcVkVWmmz+v89o4UhJXfKl2SWT8rSiT/yJt6EBzcK6uv5nK+ot2YmkCIP/M7K9K9PXRDQg3w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: Mil509kyodDziWqrckzb7PVNx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594736996; bh=lgDE1IMXbrCoCG9bvgKuyNkeWChWtFK431nyConjCWI=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=rdzxXvsJZ4EnyPn7h6BkLMnnXNFkOSiptPeqLoDoeEiAYht8vlECJIkS14u+UKhWtxe va538RbFXXIM5NwZFddVqhKO/jae0ixdXVUFoBc0nRRUP6YCDmMbnjlzflTrnmL8iWLLZ WCHtpPYTnjllhJGJVXBLvjVgptrw4t83L9c= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a CPUID instruction requires the current value of the XCR0 register. In order to retrieve that value, the XGETBV instruction needs to be executed. Provide the necessary support to execute the XGETBV instruction. Cc: Michael D Kinney Cc: Liming Gao Signed-off-by: Tom Lendacky --- MdePkg/Library/BaseLib/BaseLib.inf | 2 ++ MdePkg/Include/Library/BaseLib.h | 17 +++++++++++++ MdePkg/Library/BaseLib/Ia32/GccInline.c | 28 ++++++++++++++++++++ MdePkg/Library/BaseLib/X64/GccInline.c | 30 ++++++++++++++++++++++ MdePkg/Library/BaseLib/Ia32/XGetBv.nasm | 31 ++++++++++++++++++++++ MdePkg/Library/BaseLib/X64/XGetBv.nasm | 34 +++++++++++++++++++++++++ 6 files changed, 142 insertions(+) create mode 100644 MdePkg/Library/BaseLib/Ia32/XGetBv.nasm create mode 100644 MdePkg/Library/BaseLib/X64/XGetBv.nasm diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/Ba= seLib.inf index a57ae2da31f3..da6bc22a3e2b 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -153,6 +153,7 @@ [Sources.Ia32] Ia32/ARShiftU64.c | MSFT Ia32/EnableCache.c | MSFT Ia32/DisableCache.c | MSFT + Ia32/XGetBv.nasm | MSFT =20 =20 Ia32/GccInline.c | GCC @@ -287,6 +288,7 @@ [Sources.X64] X64/ReadCr2.nasm| MSFT X64/ReadCr0.nasm| MSFT X64/ReadEflags.nasm| MSFT + X64/XGetBv.nasm | MSFT =20 =20 X64/Non-existing.c diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Base= Lib.h index 8e7b87cbda4e..7edf0051a0a0 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -7831,6 +7831,23 @@ AsmLfence ( VOID ); =20 +/** + Executes a XGETBV instruction + + Executes a XGETBV instruction. This function is only available on IA-32 = and + x64. + + @param[in] Index Extended control register index + + @return The current value of the extended control regist= er +**/ +UINT64 +EFIAPI +AsmXGetBv ( + IN UINT32 Index + ); + + /** Patch the immediate operand of an IA32 or X64 instruction such that the = byte, word, dword or qword operand is encoded at the end of the instruction's diff --git a/MdePkg/Library/BaseLib/Ia32/GccInline.c b/MdePkg/Library/BaseL= ib/Ia32/GccInline.c index 5287200f8754..c962bcfa4617 100644 --- a/MdePkg/Library/BaseLib/Ia32/GccInline.c +++ b/MdePkg/Library/BaseLib/Ia32/GccInline.c @@ -1763,3 +1763,31 @@ AsmFlushCacheLine ( } =20 =20 +/** + Executes a XGETBV instruction + + Executes a XGETBV instruction. This function is only available on IA-32 = and + x64. + + @param[in] Index Extended control register index + + @return The current value of the extended control regist= er +**/ +UINT64 +EFIAPI +AsmXGetBv ( + IN UINT32 Index + ) +{ + UINT64 Data; + + __asm__ __volatile__ ( + "xgetbv" + : "=3DA" (Data) + : "c" (Index) + ); + + return Data; +} + + diff --git a/MdePkg/Library/BaseLib/X64/GccInline.c b/MdePkg/Library/BaseLi= b/X64/GccInline.c index 154ce1f57e92..915555198f9f 100644 --- a/MdePkg/Library/BaseLib/X64/GccInline.c +++ b/MdePkg/Library/BaseLib/X64/GccInline.c @@ -1798,3 +1798,33 @@ AsmFlushCacheLine ( } =20 =20 +/** + Executes a XGETBV instruction + + Executes a XGETBV instruction. This function is only available on IA-32 = and + x64. + + @param[in] Index Extended control register index + + @return The current value of the extended control regist= er +**/ +UINT64 +EFIAPI +AsmXGetBv ( + IN UINT32 Index + ) +{ + UINT32 LowData; + UINT32 HighData; + + __asm__ __volatile__ ( + "xgetbv" + : "=3Da" (LowData), + "=3Dd" (HighData) + : "c" (Index) + ); + + return (((UINT64)HighData) << 32) | LowData; +} + + diff --git a/MdePkg/Library/BaseLib/Ia32/XGetBv.nasm b/MdePkg/Library/BaseL= ib/Ia32/XGetBv.nasm new file mode 100644 index 000000000000..9f7b03bbff35 --- /dev/null +++ b/MdePkg/Library/BaseLib/Ia32/XGetBv.nasm @@ -0,0 +1,31 @@ +;-------------------------------------------------------------------------= ----- +; +; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent +; +; Module Name: +; +; XGetBv.Asm +; +; Abstract: +; +; AsmXgetBv function +; +; Notes: +; +;-------------------------------------------------------------------------= ----- + + SECTION .text + +;-------------------------------------------------------------------------= ----- +; UINT64 +; EFIAPI +; AsmXGetBv ( +; IN UINT32 Index +; ); +;-------------------------------------------------------------------------= ----- +global ASM_PFX(AsmXGetBv) +ASM_PFX(AsmXGetBv): + mov ecx, [esp + 4] + xgetbv + ret diff --git a/MdePkg/Library/BaseLib/X64/XGetBv.nasm b/MdePkg/Library/BaseLi= b/X64/XGetBv.nasm new file mode 100644 index 000000000000..09f3be8ae0a8 --- /dev/null +++ b/MdePkg/Library/BaseLib/X64/XGetBv.nasm @@ -0,0 +1,34 @@ +;-------------------------------------------------------------------------= ----- +; +; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent +; +; Module Name: +; +; XGetBv.Asm +; +; Abstract: +; +; AsmXgetBv function +; +; Notes: +; +;-------------------------------------------------------------------------= ----- + + DEFAULT REL + SECTION .text + +;-------------------------------------------------------------------------= ----- +; UINT64 +; EFIAPI +; AsmXGetBv ( +; IN UINT32 Index +; ); +;-------------------------------------------------------------------------= ----- +global ASM_PFX(AsmXGetBv) +ASM_PFX(AsmXGetBv): + xgetbv + shl rdx, 32 + or rax, rdx + ret + --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62509): https://edk2.groups.io/g/devel/message/62509 Mute This Topic: https://groups.io/mt/75499760/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62510+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62510+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594737010093496.8605751470542; Tue, 14 Jul 2020 07:30:10 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id iLxJYY1788612x6Xpa4mXz2p; Tue, 14 Jul 2020 07:30:09 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.64]) by mx.groups.io with SMTP id smtpd.web12.20825.1594737009017022499 for ; Tue, 14 Jul 2020 07:30:09 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nr0SvLZ8dkX1J2+XXdtxN52vro50e0xJ6tSczqBbBKFt3ABVWp6edmGsKeSu1uqSX1Ehu5KZVcLyd0L3yk21+gDYeOyBoooWOAF59qCOVdmhHxVerl3MbnnBwatrTlx4fNpNbAuWMglvpd5YQEokrLbJ0GWNWqrb9P26O3oECEYbSsEoDwhyMbM2J4POMGYTpLvL86umWbfGAN+dc6rY4pnj4svVnMeA0J5uZAQWQZgAVUUUKw45svmZZmFIjXcXvCL+y6sGgLL9Au/FX2tnh/n/i/75oCdtN4X/22vMrzE6UGWF1oeO6qAF334gRgztabu2eT1JMNxKLhgCDorrpw== 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=mXGdTj/oZNZnIsvWPfSMO+dFD7IT2Ixch+ABgjZXfkc=; b=St1BWTbw7e7n3Xcn6QtmgAeSs4EjZYKzLsquu1z88FDKk+pZrabUoJj3w3zhCrkfZ2dmuhptA/+4zaeDiJNtGmohqZdmLrF8OhouWwZHsy56tTEqMngk9Bmw+f9pAo3xRpzR9J6Sl7C4zv7+nUIHtmA68SZURiIxoNbmnPNYx3JfuiWD+juQ7LDPPTIwpROdemcDGq6FxZVEOBJ5DlP2OQSV/TtVuGp4XCHxHNpJ6O+NeDPWGDbjxxXzXVFFs1d/SBPZgx9t+0z5mqNcHYeYT5MarZNSSxY0HiAHDN80poDnVOc6HbDBCfzqR73UlWMi5p2JtdP6DmgYw/h+fF4FjA== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:30:06 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:30:06 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 07/46] MdePkg/BaseLib: Add support for the VMGEXIT instruction Date: Tue, 14 Jul 2020 09:27:38 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN4PR0201CA0039.namprd02.prod.outlook.com (2603:10b6:803:2e::25) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0201CA0039.namprd02.prod.outlook.com (2603:10b6:803:2e::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22 via Frontend Transport; Tue, 14 Jul 2020 14:30:05 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 33dd205c-bd17-4c4c-140d-08d82802670d X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: CbYDge3XU3To/0od80+J95nYcTFSsj8Rxhb79sBgduVI4c+GQrS2CKSJUY7zFyRhtmlCBlyQftlZt6Xx48+cEKdBUobc33xg/1snemdzfhJZ/ResPp54db0HgnAxvNRn+khRFm0GLXWjzcA3Pftxc6CMqEBwzv8J7qsINj1aOFxxUWiJMOPtgRHcpfrCXyGVAOWG0Cpa8umgVsvOTgqJP4b5lHAUlTodl3+jtR8cmAfzb9pMp5B7B9RPJXP0faV7FlLEpIu7bdYOYvLU8Cy+yMQk/Lfr4RoVoDq7SZsBrlTliVJZs+Vt84Mvq67a/QdZ9/VU3TGIybYLgINgNiD1ZgMiemEdje0N6UKtvj9c5HY1kzYA8Z8obWfwuC/zBqOdJCxUVGQOYywDsXVUOy3yftvhxNGa9CmvnIN9RwIUraoahQPXtLTnQ+xvFTzy91AAikyovdmQehpgZUJpD0SY8g== X-MS-Exchange-AntiSpam-MessageData: 4sed9gcMYkn/UjS5yHvOMAs/zZxA+iW18CU0hMgR6f8U4KEb1Y5zOuKti/VRGu/cwp/AJu3DjFZDC/QMJch7BeLSM+zAol6wNh5NT3UlBNzETe8SWRuu7GWCS7lRD47k+TyPBiUUuAy8qi2UNTkYzJRktyPbnbliNC7BrTzfOy2iZttHhLYfTS6xkn5tAiv/ViOXy5phKwwNEQZkhxdGvXUFMQZ8XGYo3Og8j5PPm4ywJI4QecEbH60tXcmpl+4Tlzjc5qoRGAJQcquIIMMqW2NXkZb6WV5fSxWKiHK/iENwT0lEBK7aZ9T9aDEH+Ax0MCHqiR4Vot/k45mhSxTx5wG4sleITk3gsgrg3bsP4kSMjJGapQZylyyGu6NO+L2OxMr9GEmjzao6Yha1N4X/cpNVFlQfPm15gVcDwPYUJ0SbLzAJm1bS3AMgPrhzSDkX153OdaFMdIISGFvSM1eq141vHbjKaxtjJa3hViCe5mQ= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 33dd205c-bd17-4c4c-140d-08d82802670d X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:30:05.9330 (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: DC5smlibgvkHq8GrKJORDNu4VDSijfe2eGAtMW125gbfYjWN5yBlAYpY0LkkHxPGukDTZMcVWX5yl4GgRSCCBg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: eY4EI8Fisqd4hqDsI7vNMyVtx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737009; bh=rR2CNqhvOsZt6hkSr9tLaEAU6ZmYKHN9weH1zZlIxwg=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=v6amXfnAIQqCJbqL8ruJcqyjKEOR1Lt/d+0oxoVjzSVYFwalGz1+DCR+FtCRyXb0owz nWzzV9QHjg5aFIOHf7qB7S1uKDaJzwbkBXlTj23EcXPGNSnDysFiQilh+PwfAimlobM/s EsG/BS+vwqdi0Wauc+x8lEb/6uHSovnNpcY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 VMGEXIT is a new instruction used for Hypervisor/Guest communication when running as an SEV-ES guest. A VMGEXIT will cause an automatic exit (AE) to occur, resulting in a #VMEXIT with an exit code value of 0x403. Provide the necessary support to execute the VMGEXIT instruction, which is "rep; vmmcall". Cc: Michael D Kinney Cc: Liming Gao Signed-off-by: Tom Lendacky --- MdePkg/Library/BaseLib/BaseLib.inf | 2 ++ MdePkg/Include/Library/BaseLib.h | 14 +++++++++ MdePkg/Library/BaseLib/Ia32/GccInline.c | 17 +++++++++++ MdePkg/Library/BaseLib/X64/GccInline.c | 17 +++++++++++ MdePkg/Library/BaseLib/Ia32/VmgExit.nasm | 37 ++++++++++++++++++++++++ MdePkg/Library/BaseLib/X64/VmgExit.nasm | 32 ++++++++++++++++++++ 6 files changed, 119 insertions(+) create mode 100644 MdePkg/Library/BaseLib/Ia32/VmgExit.nasm create mode 100644 MdePkg/Library/BaseLib/X64/VmgExit.nasm diff --git a/MdePkg/Library/BaseLib/BaseLib.inf b/MdePkg/Library/BaseLib/Ba= seLib.inf index da6bc22a3e2b..7cf6467fa77b 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -154,6 +154,7 @@ [Sources.Ia32] Ia32/EnableCache.c | MSFT Ia32/DisableCache.c | MSFT Ia32/XGetBv.nasm | MSFT + Ia32/VmgExit.nasm | MSFT =20 =20 Ia32/GccInline.c | GCC @@ -289,6 +290,7 @@ [Sources.X64] X64/ReadCr0.nasm| MSFT X64/ReadEflags.nasm| MSFT X64/XGetBv.nasm | MSFT + X64/VmgExit.nasm | MSFT =20 =20 X64/Non-existing.c diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Base= Lib.h index 7edf0051a0a0..04fb329eaabb 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -7848,6 +7848,20 @@ AsmXGetBv ( ); =20 =20 +/** + Executes a VMGEXIT instruction (VMMCALL with a REP prefix) + + Executes a VMGEXIT instruction. This function is only available on IA-32= and + x64. + +**/ +VOID +EFIAPI +AsmVmgExit ( + VOID + ); + + /** Patch the immediate operand of an IA32 or X64 instruction such that the = byte, word, dword or qword operand is encoded at the end of the instruction's diff --git a/MdePkg/Library/BaseLib/Ia32/GccInline.c b/MdePkg/Library/BaseL= ib/Ia32/GccInline.c index c962bcfa4617..d6a7581b36f6 100644 --- a/MdePkg/Library/BaseLib/Ia32/GccInline.c +++ b/MdePkg/Library/BaseLib/Ia32/GccInline.c @@ -1791,3 +1791,20 @@ AsmXGetBv ( } =20 =20 +/** + Executes a VMGEXIT instruction. + + Executes a VMGEXIT instruction. This function is only available on IA-32= and + X64. + +**/ +VOID +EFIAPI +AsmVmgExit ( + VOID + ) +{ + __asm__ __volatile__ ("rep; vmmcall":::"memory"); +} + + diff --git a/MdePkg/Library/BaseLib/X64/GccInline.c b/MdePkg/Library/BaseLi= b/X64/GccInline.c index 915555198f9f..0685337bbb56 100644 --- a/MdePkg/Library/BaseLib/X64/GccInline.c +++ b/MdePkg/Library/BaseLib/X64/GccInline.c @@ -1828,3 +1828,20 @@ AsmXGetBv ( } =20 =20 +/** + Executes a VMGEXIT instruction. + + Executes a VMGEXIT instruction. This function is only available on IA-32= and + X64. + +**/ +VOID +EFIAPI +AsmVmgExit ( + VOID + ) +{ + __asm__ __volatile__ ("rep; vmmcall":::"memory"); +} + + diff --git a/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm b/MdePkg/Library/Base= Lib/Ia32/VmgExit.nasm new file mode 100644 index 000000000000..a4b37385cc7a --- /dev/null +++ b/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm @@ -0,0 +1,37 @@ +;-------------------------------------------------------------------------= ----- +; +; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent +; +; Module Name: +; +; VmgExit.Asm +; +; Abstract: +; +; AsmVmgExit function +; +; Notes: +; +;-------------------------------------------------------------------------= ----- + + SECTION .text + +;-------------------------------------------------------------------------= ----- +; VOID +; EFIAPI +; AsmVmgExit ( +; VOID +; ); +;-------------------------------------------------------------------------= ----- +global ASM_PFX(AsmVmgExit) +ASM_PFX(AsmVmgExit): +; +; NASM doesn't support the vmmcall instruction in 32-bit mode, so work aro= und +; this by temporarily switching to 64-bit mode. +; +BITS 64 + rep vmmcall +BITS 32 + ret + diff --git a/MdePkg/Library/BaseLib/X64/VmgExit.nasm b/MdePkg/Library/BaseL= ib/X64/VmgExit.nasm new file mode 100644 index 000000000000..26f034593c67 --- /dev/null +++ b/MdePkg/Library/BaseLib/X64/VmgExit.nasm @@ -0,0 +1,32 @@ +;-------------------------------------------------------------------------= ----- +; +; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent +; +; Module Name: +; +; VmgExit.Asm +; +; Abstract: +; +; AsmVmgExit function +; +; Notes: +; +;-------------------------------------------------------------------------= ----- + + DEFAULT REL + SECTION .text + +;-------------------------------------------------------------------------= ----- +; VOID +; EFIAPI +; AsmVmgExit ( +; VOID +; ); +;-------------------------------------------------------------------------= ----- +global ASM_PFX(AsmVmgExit) +ASM_PFX(AsmVmgExit): + rep vmmcall + ret + --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62510): https://edk2.groups.io/g/devel/message/62510 Mute This Topic: https://groups.io/mt/75499784/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62511+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62511+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594737021592314.94915342985416; Tue, 14 Jul 2020 07:30:21 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id TxKNYY1788612xcfKS7vAjdY; Tue, 14 Jul 2020 07:30:21 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.64]) by mx.groups.io with SMTP id smtpd.web11.21057.1594737020640897226 for ; Tue, 14 Jul 2020 07:30:20 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hHmaeiZSGiHEerL4UhmZ+qik/1QQAfnpUVHk0VSLSb8xOiK+oX/LIHXu6HmDKNqDomofl+dOng/+VIv5ppIt8fohWItQ/bWNN2YY7NLLhGpB/1YzyFNWNQA19iB8jqgYr0N3bIAFRoNSwIAU19EO3k2Zm9ByotWja0Ua+7iJo2x5Imwm+AN/vA7rloPcBpCDlI4/bMgOL3Y1xOuAgBgnUhoDO45wQTMjIlqmbHwiEMIeqgY/px4S+5YfavBvk75Y+mT+gvA8PXhiuT6iSTgz/QFHpQEZC5JXkpvqXj/SNku9Bj1hmKjStEhyAehCXufSfMbb93W04LcpX1OTgOa2dA== 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=/BJELomezd9RuQOtYb+gTmMe10Anbl6BkYn9LkHsNc0=; b=brs0p9og1/qBdjkGpMjdIzsGRg3bWvQq06T7yC6uGm6pmmIlXmO3NyxNSmv4Z7AO/wHlHThf+YNvmfSHaNJsGoAicckff/Z+peGyCWimrCzlIUfxbe4+i7cKcXGmEn7t5/7yKbTPWZmGdHUS3+V/MWLVKltWqXLvAY8xpYwx083kdMBZa37UlStcYjDb4iOo//cFQdDWFeRjf9y2sXGETtkSk31wL9vLIbNiFG+1nmHNmCXtQKDfmcrzGHCwn6kRH1JSQpykJoscA/o2cROR2vdmuvz7oLlcTylArUV1kBUE/knszXBqDk7KgrCHrkaauRAsw2qPi21SjuMkEKqkQQ== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:30:19 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:30:19 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 08/46] UefiCpuPkg: Implement library support for VMGEXIT Date: Tue, 14 Jul 2020 09:27:39 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN6PR04CA0084.namprd04.prod.outlook.com (2603:10b6:805:f2::25) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR04CA0084.namprd04.prod.outlook.com (2603:10b6:805:f2::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 14:30:18 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 07951c51-b2a3-4d3d-edd7-08d828026ef7 X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: JU1G1Eq9dYvgJOVlCyvLz3DFmS1AGmlNCDN/ULR8J5iOrAAc4KA8lCyqW3XZq1iq1BILacEARB9XT0C29e+mn0OIiOSRX89ian4lO1qd/KAQwG29v0cqpnbN9Qtqh6Sznw8dPh5tw4dgcBz15NxGFaCAOHXwpG/lot0n93h5aH0lD5Gcp8uKH6KHrvNPZhhwX04aDMpM4htV7A+YDYgu+sCuQLiSa2c32M18N2AUmrhhAEbj8ImInk5mQLJ+oXlfoK8aM38qBe56HvbEPc8dODLuVwbyKlPh758aoAJeqNjjNfwcdAd0PGZf65uyDQCniJhIrGXBn0xcv8YX5fOinUrplnKOoEkhVkCfoqFPsM3jzlPaSBMUjryniN5tF/pecRakoLf/RsFe8c41igGOd2VoReRa4zqSGT8TIIyii33wx59Y5QIiIsxkucW5J+fpERTud2h14fcJRK884ndGaQ== X-MS-Exchange-AntiSpam-MessageData: 8YCpqI9+wQGXH+7u08UVsVsy5TOZlAEgZ1X0VLiVSHwrJHsobzBZ3Fo3rrDuk9hvp5oJQIx654CmrRDBptsjA7JIPjOF/u0QPt5gZJFNNW+9Nv2fFtosDhyaiAYX+90pAqv2V3GU/HoST3aNbGustpu6Q+klx2h990CI9nH1RDW7NmQ+9TgNucsMVOy6/25/voN4vFlLHDWxUpGQIi6E7lmiEt3ZQ3IE8ov8dMk/vgKOc8dPxBcH1LEO9toQEK3mucECaWHqNtpWCpiMqoxk8XCzvn7Gi0Np8zHtMPCiqFiGFmh1m/1TztatOQ1+JNUFaS2zlnrIYcjx7r5HoKbE2upljEP8x7qIA6s0K+AcoVCQm8/VV7kDug7MhrBrkyBgCyxxH01FKPhXiCRg6WhRli/GZ718dn1doWj/4eegtpQoSrZ2apMY/e2utOqv3YzXkFXc2309H/LKhXtXYEgL0a9lm1RbhSXEtxp0gaPpNUQ= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 07951c51-b2a3-4d3d-edd7-08d828026ef7 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:30:19.2531 (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: eJASrzIaHe9ssUOfv3zDG/4ZgQMUKDzUPXe+Rr4k+3MunFF1pyz5mHLhSnHPozMUAvj//nH+vKIK1dGXIsjMPA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: VaDiQjPeSZr5BFLeGOjR0wB6x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737021; bh=d8PWwMjO6UraVd69JoAJSiG3LuUsDk812KLSY6Xv9qw=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=BPgxznC+1dSJeL1us9XyGplVwWZXJhtuaScSBuydARTYaERYrXrPJffIsIL9ufhvmyf j0AFoX9Cj4QCdNkF18oaYqMjRy3x/I4uAe5CqTk4eLMgV4ggNi70hjdLmH7UFQq8T39+7 I8NDDnDz/gmZ+UF3U0W/wtO7pCOHvSIMbx8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 To support handling #VC exceptions and issuing VMGEXIT instructions, create a library with functions that can be used to perform these #VC/VMGEXIT related operations. This includes functions for: - Handling #VC exceptions - Preparing for and issuing a VMGEXIT - Performing MMIO-related write operations to support flash emulation - Performing AP related boot opeations The base functions in this driver will not do anything and will return an error if a return value is required. It is expected that other packages (like OvmfPkg) will create a version of the library to fully support an SEV-ES guest. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Reviewed-by: Eric Dong Signed-off-by: Tom Lendacky --- UefiCpuPkg/UefiCpuPkg.dec | 3 + UefiCpuPkg/UefiCpuPkg.dsc | 2 + .../Library/VmgExitLibNull/VmgExitLibNull.inf | 27 ++++ UefiCpuPkg/Include/Library/VmgExitLib.h | 103 +++++++++++++++ .../Library/VmgExitLibNull/VmgExitLibNull.c | 121 ++++++++++++++++++ .../Library/VmgExitLibNull/VmgExitLibNull.uni | 15 +++ 6 files changed, 271 insertions(+) create mode 100644 UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf create mode 100644 UefiCpuPkg/Include/Library/VmgExitLib.h create mode 100644 UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c create mode 100644 UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index df5d02bae6b4..cb92f34b6f55 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -53,6 +53,9 @@ [LibraryClasses.IA32, LibraryClasses.X64] ## MpInitLib|Include/Library/MpInitLib.h =20 + ## @libraryclass Provides function to support VMGEXIT processing. + VmgExitLib|Include/Library/VmgExitLib.h + [Guids] gUefiCpuPkgTokenSpaceGuid =3D { 0xac05bf33, 0x995a, 0x4ed4, { 0xaa,= 0xb8, 0xef, 0x7a, 0xe8, 0xf, 0x5c, 0xb0 }} gMsegSmramGuid =3D { 0x5802bce4, 0xeeee, 0x4e33, { 0xa1,= 0x30, 0xeb, 0xad, 0x27, 0xf0, 0xe4, 0x39 }} diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index afa304128221..f0e58b90ff0a 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -56,6 +56,7 @@ [LibraryClasses] PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeC= offGetEntryPointLib.inf PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeC= offExtraActionLibNull.inf TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurem= entLibNull.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 [LibraryClasses.common.SEC] PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.= inf @@ -143,6 +144,7 @@ [Components.IA32, Components.X64] UefiCpuPkg/Library/SmmCpuPlatformHookLibNull/SmmCpuPlatformHookLibNull.i= nf UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf + UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.inf UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationSmm.inf UefiCpuPkg/SecCore/SecCore.inf diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf b/UefiCpu= Pkg/Library/VmgExitLibNull/VmgExitLibNull.inf new file mode 100644 index 000000000000..d8770a21c355 --- /dev/null +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf @@ -0,0 +1,27 @@ +## @file +# VMGEXIT Support Library. +# +# Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D VmgExitLibNull + MODULE_UNI_FILE =3D VmgExitLibNull.uni + FILE_GUID =3D 3cd7368f-ef9b-4a9b-9571-2ed93813677e + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D VmgExitLib + +[Sources.common] + VmgExitLibNull.c + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + diff --git a/UefiCpuPkg/Include/Library/VmgExitLib.h b/UefiCpuPkg/Include/L= ibrary/VmgExitLib.h new file mode 100644 index 000000000000..45fc27d35e29 --- /dev/null +++ b/UefiCpuPkg/Include/Library/VmgExitLib.h @@ -0,0 +1,103 @@ +/** @file + Public header file for the VMGEXIT Support library class. + + This library class defines some routines used when invoking the VMGEXIT + instruction in support of SEV-ES and to handle #VC exceptions. + + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef __VMG_EXIT_LIB_H__ +#define __VMG_EXIT_LIB_H__ + +#include +#include + + +/** + Perform VMGEXIT. + + Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction a= nd + then handles the return actions. + + @param[in, out] Ghcb A pointer to the GHCB + @param[in] ExitCode VMGEXIT code to be assigned to the SwExitCode + field of the GHCB. + @param[in] ExitInfo1 VMGEXIT information to be assigned to the + SwExitInfo1 field of the GHCB. + @param[in] ExitInfo2 VMGEXIT information to be assigned to the + SwExitInfo2 field of the GHCB. + + @retval 0 VMGEXIT succeeded. + @return Exception number to be propagated, VMGEXIT + processing did not succeed. + +**/ +UINT64 +EFIAPI +VmgExit ( + IN OUT GHCB *Ghcb, + IN UINT64 ExitCode, + IN UINT64 ExitInfo1, + IN UINT64 ExitInfo2 + ); + +/** + Perform pre-VMGEXIT initialization/preparation. + + Performs the necessary steps in preparation for invoking VMGEXIT. Must be + called before setting any fields within the GHCB. + + @param[in, out] Ghcb A pointer to the GHCB + +**/ +VOID +EFIAPI +VmgInit ( + IN OUT GHCB *Ghcb + ); + +/** + Perform post-VMGEXIT cleanup. + + Performs the necessary steps to cleanup after invoking VMGEXIT. Must be + called after obtaining needed fields within the GHCB. + + @param[in, out] Ghcb A pointer to the GHCB + +**/ +VOID +EFIAPI +VmgDone ( + IN OUT GHCB *Ghcb + ); + +/** + Handle a #VC exception. + + Performs the necessary processing to handle a #VC exception. + + The base library function returns an error equal to VC_EXCEPTION, + to be propagated to the standard exception handling stack. + + @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be s= et + as value to use on error. + @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT + + @retval EFI_SUCCESS Exception handled + @retval EFI_UNSUPPORTED #VC not supported, (new) exception value= to + propagate provided + @retval EFI_PROTOCOL_ERROR #VC handling failed, (new) exception val= ue to + propagate provided + +**/ +EFI_STATUS +EFIAPI +VmgExitHandleVc ( + IN OUT EFI_EXCEPTION_TYPE *ExceptionType, + IN OUT EFI_SYSTEM_CONTEXT SystemContext + ); + +#endif diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c b/UefiCpuPk= g/Library/VmgExitLibNull/VmgExitLibNull.c new file mode 100644 index 000000000000..bb265e1700d2 --- /dev/null +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c @@ -0,0 +1,121 @@ +/** @file + VMGEXIT Base Support Library. + + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include + +/** + Perform VMGEXIT. + + Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction a= nd + then handles the return actions. + + The base library function returns an error in the form of a + GHCB_EVENT_INJECTION representing a GP_EXCEPTION. + + @param[in, out] Ghcb A pointer to the GHCB + @param[in] ExitCode VMGEXIT code to be assigned to the SwExitCode + field of the GHCB. + @param[in] ExitInfo1 VMGEXIT information to be assigned to the + SwExitInfo1 field of the GHCB. + @param[in] ExitInfo2 VMGEXIT information to be assigned to the + SwExitInfo2 field of the GHCB. + + @retval 0 VMGEXIT succeeded. + @return Exception number to be propagated, VMGEXIT + processing did not succeed. + +**/ +UINT64 +EFIAPI +VmgExit ( + IN OUT GHCB *Ghcb, + IN UINT64 ExitCode, + IN UINT64 ExitInfo1, + IN UINT64 ExitInfo2 + ) +{ + GHCB_EVENT_INJECTION Event; + + Event.Uint64 =3D 0; + Event.Elements.Vector =3D GP_EXCEPTION; + Event.Elements.Type =3D GHCB_EVENT_INJECTION_TYPE_EXCEPTION; + Event.Elements.Valid =3D 1; + + return Event.Uint64; +} + +/** + Perform pre-VMGEXIT initialization/preparation. + + Performs the necessary steps in preparation for invoking VMGEXIT. Must be + called before setting any fields within the GHCB. + + The base library function does nothing. + + @param[in, out] Ghcb A pointer to the GHCB + +**/ +VOID +EFIAPI +VmgInit ( + IN OUT GHCB *Ghcb + ) +{ +} + +/** + Perform post-VMGEXIT cleanup. + + Performs the necessary steps to cleanup after invoking VMGEXIT. Must be + called after obtaining needed fields within the GHCB. + + The base library function does nothing. + + @param[in, out] Ghcb A pointer to the GHCB + +**/ +VOID +EFIAPI +VmgDone ( + IN OUT GHCB *Ghcb + ) +{ +} + +/** + Handle a #VC exception. + + Performs the necessary processing to handle a #VC exception. + + The base library function returns an error equal to VC_EXCEPTION, + to be propagated to the standard exception handling stack. + + @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be s= et + as value to use on error. + @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT + + @retval EFI_SUCCESS Exception handled + @retval EFI_UNSUPPORTED #VC not supported, (new) exception value= to + propagate provided + @retval EFI_PROTOCOL_ERROR #VC handling failed, (new) exception val= ue to + propagate provided + +**/ +EFI_STATUS +EFIAPI +VmgExitHandleVc ( + IN OUT EFI_EXCEPTION_TYPE *ExceptionType, + IN OUT EFI_SYSTEM_CONTEXT SystemContext + ) +{ + *ExceptionType =3D VC_EXCEPTION; + + return EFI_UNSUPPORTED; +} diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni b/UefiCpu= Pkg/Library/VmgExitLibNull/VmgExitLibNull.uni new file mode 100644 index 000000000000..8639bc0e8ce9 --- /dev/null +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni @@ -0,0 +1,15 @@ +// /** @file +// VMGEXIT support library instance. +// +// VMGEXIT support library instance. +// +// Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved. +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "VMGEXIT support N= ULL library instance" + +#string STR_MODULE_DESCRIPTION #language en-US "VMGEXIT support N= ULL library instance." + --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62511): https://edk2.groups.io/g/devel/message/62511 Mute This Topic: https://groups.io/mt/75499789/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62512+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62512+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 159473703408513.188357493006492; Tue, 14 Jul 2020 07:30:34 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id TIjjYY1788612xS1tkZp4xud; Tue, 14 Jul 2020 07:30:33 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.49]) by mx.groups.io with SMTP id smtpd.web10.21059.1594737033244276327 for ; Tue, 14 Jul 2020 07:30:33 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dMEwhnOuUXQhnSJkmv1Tkb+deQEQ0MfXSFnsKtyF0l5F8HfGVD5F6f+IUJPhpFsB+YPThPTUh5plg/iGQ24RglV5NgkdtiRZOIjTCjBprbZsa0QkYEfd5vJyoyyFh4DpIGm8aPhrwfKi4jGVpU8shdBXO+EHW9kjZHnLbDzetqVDUrqXrCmuJFIKM1CQV3gxfIsMClmmjPrTQ2rM0PYZwxz1GhK6J79LCG2bSIkl3VJzK33V7IRhBuyUlo02F0aYmZC+DCIE+30TH03JvfypCcBbimjR7wSoAyuzsEb2xUP3FXVA9oc8AlNics324e6TOTeW3P7OyIIsgG7u/HcGeA== 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=OxttOTgzdegAV1YWCYyGem4R9s8oQ3VG39IsysQR0G0=; b=AX+eappfquROPo/r/X2qefEKxURd5Iovf8uJzQT2J0SnCdQ/OYOC37q8ioyo4hzZcaBpuKIDgfTqIR9k0UEaZwZmpY6WU4ZPbmhFfyKK1pKw5GSeuZ8BhUy5f4CG+xee3qvWx/4iPbjQnf9Wi6tNNfuPdQ2Ah9IvD0Y/oFCulAcdfv+VQcG7FE8JoflLHdAgEV1PktSWPs1NiBGoFA7ctz08cSZuRNf2QITzp8PRv929hw+MAZWDgURMVRKqUkJqKeMeeJsni3n1NKEkDb4UZIAvxZCo+6NpmENw0DEufzhNc4dunlFgI4rg06WbN90pWIY7TM0+4Aneb3CfPuBODA== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:30:32 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:30:32 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni , Anthony Perard , Julien Grall Subject: [edk2-devel] [PATCH v10 09/46] OvmfPkg: Prepare OvmfPkg to use the VmgExitLib library Date: Tue, 14 Jul 2020 09:27:40 -0500 Message-ID: <209c986fcfaac835d06f03f38f76d1050ba76f16.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0601CA0003.namprd06.prod.outlook.com (2603:10b6:803:2f::13) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0601CA0003.namprd06.prod.outlook.com (2603:10b6:803:2f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17 via Frontend Transport; Tue, 14 Jul 2020 14:30:30 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d056413c-d8f6-4c0e-8ebb-08d828027677 X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2276; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: HV1wBADyQOtfweA6lKy/nzJuj+rBuqlc/djSjiSEGb6nToBEx2T6N6WUEkkMjrLWRktnZqT2KauP0ht7VURNC7KbnKr+evteSzOouwx8IF4QUBSlRsDW23GDL6otKXHG+AT5mU13YEXW1CCS8UcoKWyrZZJutRLRy9RfBRrhxa5Io4c4EkwC56Gz1u0gq0+eTnVeab/lR5IIRnKsNHsly0Cf+mRLdr2wajUfxRB7u8osiYRJT51BKharRQBknp3imQwu7eo3JEhVr36gCD97SGsknfxLwYM66F9jGWMtENGCbPUMMIP1kEn1rE5WlwUM0sSOgHOXZgzIiCJr4SxMC324FUHnwUwFEQLcAkbzL7fuH7IHqbYiOqfxq8S5zzV2MZtHAfq6V2XqsdouxgH0/97Jx/bWIeLh3b52aVMYku2OJJem4NBHMLjykUJEMqLTSfAebTTzC0hkvOb6ex1xBA== X-MS-Exchange-AntiSpam-MessageData: Gkp5iIH5BylPDcJrJICtLwdG6Q6JJckrWnW3S2KVaIl5mz0JDGrua1w7mjHXyvhf3iYmsMbcduS924tUzb+XN31uJ1RrnFLoO6TSvJRGWQ3hndGFnVAR2ks8wUf7G/wHUhAzaKR/Bf4xIQsr0tBN8xaoRt1MEAhA4iJns45RdnuMQxxIhdawPmCQQbezd/AsWFkaPvnIZhUsWwHKnd+KN3GCJRJjF0e8oXXV62nEHTNynAeGHxbFW+sYMN/LqY5VkJhtTNXY4xG+2499otp3HTstoCjbw/ZjZYTJBf3igROgY7wlXjlC2Qmd6rFqeqfc9p4cZttP1KTgEA9rt0iazK8TpR3RCDXSngwK+B/UZjjg+aQKraKJIk5Zvux5F6HBgnrvBc2jph+A6Q3aVyOyEqPvYje2cgohnMiR6hKL4bxOUd3BPQsWMMy8MqIdCjw11Zx78jRB93MCiDmLPwkNJL24w5rTh4KVq6VdBh7hoa8= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d056413c-d8f6-4c0e-8ebb-08d828027677 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:30:31.8266 (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: SmO6lztWOauvQ1NBR+pcTbohh0sy/MBnOdemEVBShPVNj5KpgXd1ADQL5qq+yGTk2bcdoYegsAy4NLMVAKO5vQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: kIZaGIabTXvi228qcRun2Yl1x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737033; bh=0UtO0QyxB0aaXoL+3A26hvgF2gV/Jx+PlVXuhSrc5Vw=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=gU1lrJJEiSLmjz7j9u5nLz3lX1wc6TUbMor6PiAmO+aF+Z2rrbnZ3vzD/sFLNFRWcA5 OPUK9sYF4PpCwczl9DB90BfNny6otvng7bLhz486AaI1obNWQv+EUf7UA/+J0qjkhi+w7 G601PCumAU2Hx16btauYUNuu5XAuRG/AlQo= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Various CpuExceptionHandlerLib libraries will updated to use the new VmgExitLib library. To prevent any build breakage, update the OvmfPkg DSC files that use a form of the CpuExceptionHandlerLib library to include the VmgExitLib library. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Anthony Perard Cc: Julien Grall Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/OvmfXen.dsc | 1 + 4 files changed, 4 insertions(+) diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index b4ee7376791b..b6f98af8183c 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -228,6 +228,7 @@ [LibraryClasses] =20 [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 [LibraryClasses.common.SEC] TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index ed68b080f2a2..d147aca168be 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -232,6 +232,7 @@ [LibraryClasses] =20 [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 [LibraryClasses.common.SEC] TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index cb7e8068a3d8..269b6d973188 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -232,6 +232,7 @@ [LibraryClasses] =20 [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 [LibraryClasses.common.SEC] TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index 782803cb2787..37b63a874067 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -213,6 +213,7 @@ [LibraryClasses] =20 [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 [LibraryClasses.common.SEC] QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSecLib.inf --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62512): https://edk2.groups.io/g/devel/message/62512 Mute This Topic: https://groups.io/mt/75499796/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62513+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62513+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594737047154299.33924438626605; Tue, 14 Jul 2020 07:30:47 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id LmLOYY1788612xGSo7ADwCG2; Tue, 14 Jul 2020 07:30:46 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.42]) by mx.groups.io with SMTP id smtpd.web12.20848.1594737046253542284 for ; Tue, 14 Jul 2020 07:30:46 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UONhHwGHZhcgUTb3tE0ea8RTMQNeGt9VCgo7y3+pAZxv8v/VFjpja3Esp3ooxYAi/RdhXqoBB7+FuKWzx4fWE++3fmVKdQXJnp5jdYCHdcAma412zqc704ta0eyWdvpLPPGwUUrySkg5H3OkSLjKS4AZzk7tSBNCQk1Y9H+ZeZp6Iusbq60PmEMnv+O6ZcgvY6Avydb4V34Q0gaw4q1jbQP2vMB0faT3oFpblIwweQPeuK4EJb94LOYDSdJ4l9EkYExZd30yRpP/zZowfq8dE9Jg74dAQoMvMV7LXDyJMG7AZzzNvTNItEvKotQexTOFpgj1TYgmccpxLLRE3k7R8w== 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=R6g4oY7VhjAGLEjmfdF6fdsktsJytcOsu/iq/uLdJSA=; b=jW82HV1Ggk8SaHxTCsG2GxCtuUT+YxeoMTsFURFjh8sy6klGaZYeTOjNiaLvi7zRK1FfPxH5RPn7npcxcL3ICWBo/e6GgWLubPNyeLWCO6hG1Aqv1n8QLCic7ZXD7wxeJ0ubrZo7VSUpGCSV9Iz2uytJAz0AlNhLUb02JyRZS9O2/Ju0MwAk+55/HXtNBAeCRfQ8oP7TJo5Hq/2xxZ1kEuoCFMPE7y9BLkALzt6xPyBh1NSY0mEGuMsRPsb6flpPSMcKynEjBKmRF2TcSTjmtRhkpD4uFRn6P8Z0qmnye0VmCYFxZFAkJx105ciq6Qu4wzRISvnx0xqtihi/IczmaQ== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:30:44 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:30:44 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni , Maurice Ma , Guo Dong , Benjamin You Subject: [edk2-devel] [PATCH v10 10/46] UefiPayloadPkg: Prepare UefiPayloadPkg to use the VmgExitLib library Date: Tue, 14 Jul 2020 09:27:41 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0046.namprd05.prod.outlook.com (2603:10b6:803:41::23) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0501CA0046.namprd05.prod.outlook.com (2603:10b6:803:41::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.9 via Frontend Transport; Tue, 14 Jul 2020 14:30:43 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 8e7240fe-53e4-40d8-d031-08d828027df5 X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2733; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: gciESJmquYasIh5bbjDX3Ml7j/eY167MRMP1iaknXiva3eSVKflvQRv7872cV92770Ja1re4Bd83UNYPIrhzrHOGXzqRsOWj+rujgeZ/pFEqmxBcO8URYWnYgvPTs7ttQJ0P+wMf6Pd5vOK2y0+ZQE9mkarI350z3aGQ1/F9OWQJkDq/zo7ar9Bd5irTgYVwHTaQLN0sY2dwC8yd3BnpXet94vyblPub+Fs48llhebrVZZ++t9/GOZKp010s4v9ygO4AFk26MLuA5ks/+67OoTxjMp+3zTxUINeQ6WKaPyihg/UOPDZvvnHKrLYMX9W1JH6xmT+2mKfeFSpmlY7YSf3RGdjKhOkVZyMUASbxwKrTRNCTH+bbMUWtGbO/YkaHR1HxzivY44vDrLnohsHdD/l5BBIMkW8q6xMBFE9Gjs+sI8tic/y6VRVGWRvFDkvuSgcPSTxB4yoZSE3nTAxUTw== X-MS-Exchange-AntiSpam-MessageData: gjfFkk3+/OxAMtgXPPJUrJm9lvWj1sRF6baLHfIQlPmV8vTosU6i1eUG8FjgoqO68NM+kW0xI93+HmHwa3fnkbDByLUanoo82s8SaNPOv0IeiQrujWznrjsGmGCjJxny5xRYMOoOJcsDBKpcfTB8Yka8nqtn0u5pIRQmntcigWxbK7RUcyqXmX2ADI57VJAj3NeeXzCd/5TaNM9pUZno3oPJTTebwhQ7pmrqnEsi+TfPd/J54xbVMdNCnyPM+uuCOjk8KGs7CZt0SXTB2OGtv7/0s7XVWfpTwWrCqPVVnIR7Mj19IWfULyM2p9Jwgrd9NTFutq+lsHwwOXtYmNeG/T/KI+4zvyJiRJtGNWpXblzAD/hqCzzAbTccbqqcGs6MO35xyfFFGhYlLBWX6qmwvYe0HxZktjfUELDqkDFOxVwh3G/esLkIidq1P+tq5H9Y1Qm19lGmE7V8eMmPpjloTdUSumteDuEl46NV5qELqeM= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8e7240fe-53e4-40d8-d031-08d828027df5 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:30:44.3811 (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: BmzFlJ3wgX3C1qDs19sKcSTiFZoM20SZ8Xwj+2rVzfQPggf5f37TrJT3+3gMuR7ysdQ1r+LTx6AfCrFjjEyuZQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: rGi08Ri3IebH7JJAiGQPuXodx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737046; bh=YUiv/jp8RdVNoXgKUvGcsnAz8tOPRF/DFwcRMrCTris=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=vNiLnUlHWb+z27TuygOprudaFfA+IcXNXExrxzLWy6wVRruWQm/IO+cFf2GhJ/bZEwT br1IrTzRcNpFNTJ7RWHP94bddIB34F8Uz705dEEZ2ZHuBq6DNlHm09IWHU5OP5iCerp80 fQNoTRHbUFJQEq2sS/laBMF4JKq+ezeqLWI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Various CpuExceptionHandlerLib libraries will updated to use the new VmgExitLib library. To prevent any build breakage, update the UefiPayloadPkg DSC files that use a form of the CpuExceptionHandlerLib library to include the VmgExitLib library. Cc: Maurice Ma Cc: Guo Dong Cc: Benjamin You Reviewed-by: Guo Dong Signed-off-by: Tom Lendacky Reviewed-by: Maurice Ma --- UefiPayloadPkg/UefiPayloadPkgIa32.dsc | 2 ++ UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc | 2 ++ 2 files changed, 4 insertions(+) diff --git a/UefiPayloadPkg/UefiPayloadPkgIa32.dsc b/UefiPayloadPkg/UefiPay= loadPkgIa32.dsc index 9a9ca3060e47..460da1c504dc 100644 --- a/UefiPayloadPkg/UefiPayloadPkgIa32.dsc +++ b/UefiPayloadPkg/UefiPayloadPkgIa32.dsc @@ -237,6 +237,7 @@ [LibraryClasses.common.DXE_CORE] DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuE= xceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 [LibraryClasses.common.DXE_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf @@ -249,6 +250,7 @@ [LibraryClasses.common.DXE_DRIVER] !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuE= xceptionHandlerLib.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 [LibraryClasses.common.DXE_RUNTIME_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf diff --git a/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc b/UefiPayloadPkg/Uefi= PayloadPkgIa32X64.dsc index a768a8702c66..942bc9076634 100644 --- a/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc +++ b/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc @@ -238,6 +238,7 @@ [LibraryClasses.common.DXE_CORE] DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuE= xceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 [LibraryClasses.common.DXE_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf @@ -250,6 +251,7 @@ [LibraryClasses.common.DXE_DRIVER] !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuE= xceptionHandlerLib.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 [LibraryClasses.common.DXE_RUNTIME_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62513): https://edk2.groups.io/g/devel/message/62513 Mute This Topic: https://groups.io/mt/75499809/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62514+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62514+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594737059080628.497499760471; Tue, 14 Jul 2020 07:30:59 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 9XVhYY1788612xsFNdW2Hpa9; Tue, 14 Jul 2020 07:30:58 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.42]) by mx.groups.io with SMTP id smtpd.web11.21072.1594737058179044780 for ; Tue, 14 Jul 2020 07:30:58 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=n4pBxbnn1pCwvs3VuBsoqIFgN8+7ieeZCPZch0jlm1cthhoF78hT6uUTXtGyMnt/qpme0vMvwNLyXeVGIA7RIfISmM5V/b16GO8sq7NKxZl2yk2O3gV5ZFypzKSNEFb9r4z3hogGgWqhngWRdmtmi7wleRnI/OihBHlyAEfFsCXyYseTazyxi6toDfabsjZgqWJnDnFQimLjcprt0gdafg8/Vkuoyb/22b/L9ArskZ4CZMM4W6KFK5rK0Ao2ISGMQDtuvoKDQg/K1Q7s9wmPUzGc6S1WS5uk1qdeyO1dnA1sSWstvL3bbIY3M2kFAHHJtg6R28H0M4D23oArDrS2rg== 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=5xOrmFSZA+Wi3b0xrnNBRCIpwsGnmCOwMSFuIiVOZU0=; b=CB2yCEo/Vy5TlS9j9YVsgMZvlejK8/ecSpr+KUEn1rfEeWTzsFV02rD6eZvFSxu03Wn7x6bAeNZNbGYOM/epSSHcy37k4Fgs3EL5mWLTOJNxnNkUJfrvCEX7RI53Gush/hnrWILClms2xjVs2JbVWIvW++HmFMaGT3ZZLvEMSRiaWVfyFfgoJl9ccI+W6WxPIISOXE8NoeSHUDNwfRq/QVfCrD+5WOAL/a/KX9Al4oYdwHq3KQ05JRE+6jTdBuCtl7zewbEn8ptBwWT9FR3Mj86DpEwAWRA87i+OJkt7KhwMdWlG896hfWEE748lo91+pRL9Dxt1+WmAONqQf2T9gQ== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:30:56 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:30:56 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 11/46] UefiCpuPkg/CpuExceptionHandler: Add base support for the #VC exception Date: Tue, 14 Jul 2020 09:27:42 -0500 Message-ID: <24fa89cbb4579ab4e0996afdf4968e1174e9e7b5.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN6PR05CA0018.namprd05.prod.outlook.com (2603:10b6:805:de::31) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR05CA0018.namprd05.prod.outlook.com (2603:10b6:805:de::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.10 via Frontend Transport; Tue, 14 Jul 2020 14:30:55 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d0096109-a81b-480b-54c8-08d82802853b X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: HQKpWimhzWD6A8lUzIL83kvSehR1Q/eWbz6VCGmPMpsQ6ys0kt7t/H10KAE7JBJRxS/KEg3wdT1pWOBipIj6cHGiwuPDvddkGC271b3Kje/w6bzANVbpkiLYhzfwCKBGolXWfCKcpMUQJLtpxEuNsEhWECdfR6+GsKEHNP28hzvQ1C815z4BwrGd4PRox7lzFTU88bGxFqdiRQXJmycdlL7G/aombOWL7LIXWiR0VQOgDZzkL4BlXHRQK0yRhsOqvOy37qXGzCSUpK5v40xatExkhWOckTeA3Gme2GI+nRWrUW1/GugzmKG6N6dmsBrcS6KJTzb76zcelcGjVk7ItIlSO5bDYYsrAt+Is4mpEvEPba7eFCsxI0O8tjpQO/3hQLpQiuIWrZPxLYZEUgJ2wAH1TBydAKZRPokYj7Lef1/G+uHN5FUyDBkJar/Z+ei6IM61NTs1atSjl7FhfxSux7b14f8EIZErsKzoX8H6Zjcx8ny9OccI3R8JlMj1zjpS X-MS-Exchange-AntiSpam-MessageData: 7WlCBZuN5L5TB5guRqFQHTuRASHYcSiK145qONYiFm25q9o+cYieqX5dprpJl68emULsM8d6WSDUxq31ZBwKfRbcMZewMm6lo5oZmTgVc3f6PF8DLlsyUJZG0pRPW4FRb139Wdspbh+7yZ8kvfVzvXWcoHqIEm+KyxfWBnjxXIj8VSWwLEygFS4RDuiyO7jdYsCX3zPadFthtUs3vSUeT06NMokF3dUo1Kp8+6DHXCvdD1shINQLy/ZKCC0SEdyCKls5ppuOaXtbD7YbGimIrYGJ1xB+jax7vH0ySnwmRy+kpoSPPdXoDtZvDocitinflo7ej2cJ52l3nxXfmgasjSjDUWUeTokOdrnH8rOJJYIIDNrrxydQJCxTrdzLa+EZgyrCK7tNfhGl7D2GmvQWamOtXcPxCSHEWCh83Od/L9K6jgEsVo4g4IXlv+W10TJc29PvtkhRKaNoPXy0/GKd/QZuqDRDEPmIHN0pGvzjUYY= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d0096109-a81b-480b-54c8-08d82802853b X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:30:56.6307 (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: sHWodsHAwzCt3ARkxhGYTXUSDEWUOJyVgpgy6MbeQp9PhPRZkGbDc79sNJsk8XSwKQahVMB9VblHNMRgULqHDQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: DNvztCH5ZFFbbFdcGIn3Tjimx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737058; bh=bWSQtFYlgYGWyMN22ijK05OqyTg9NRKVQ7jRVLMnyhg=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=RUDcwDBkG+YF4xkMNFHsAKl+Zxfi3I4o64ThfGCTw1cz+A7odcPCp/ivjLHG19SbVDG cQyTCOsQzPH+CDGVdLZ3TMlFoh3E/hNe7of5fvd10qNVCptmixz3+fnx125gX7Shxid9X Bc2dCx8AQ52KjKW4wCnoOVWtHGBuQD9SIEg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Add base support to handle #VC exceptions. Update the common exception handlers to invoke the VmgExitHandleVc () function of the VmgExitLib library when a #VC is encountered. A non-zero return code will propagate to the targeted exception handler. Under SEV-ES, a DR7 read or write intercept generates a #VC exception. To avoid exception recursion, a #VC exception will not try to read and push the actual debug registers into the EFI_SYSTEM_CONTEXT_X64 struct and instead push zeroes. The #VC exception handler does not make use of the debug registers from the saved context and the exception processing exit code does not attempt to restore the debug register values. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Reviewed-by: Eric Dong Signed-off-by: Tom Lendacky --- .../DxeCpuExceptionHandlerLib.inf | 1 + .../PeiCpuExceptionHandlerLib.inf | 1 + .../SecPeiCpuExceptionHandlerLib.inf | 1 + .../SmmCpuExceptionHandlerLib.inf | 1 + .../Xcode5SecPeiCpuExceptionHandlerLib.inf | 1 + .../CpuExceptionCommon.c | 10 +++++++++- .../PeiDxeSmmCpuException.c | 20 ++++++++++++++++++- .../SecPeiCpuException.c | 19 ++++++++++++++++++ .../X64/ExceptionHandlerAsm.nasm | 17 ++++++++++++++++ .../X64/Xcode5ExceptionHandlerAsm.nasm | 17 ++++++++++++++++ 10 files changed, 86 insertions(+), 2 deletions(-) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandl= erLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandle= rLib.inf index 61e2ec30b089..07b34c92a892 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.i= nf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.i= nf @@ -57,3 +57,4 @@ [LibraryClasses] PeCoffGetEntryPointLib MemoryAllocationLib DebugLib + VmgExitLib diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandl= erLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandle= rLib.inf index 093374944df6..feae7b3e06de 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.i= nf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.i= nf @@ -52,6 +52,7 @@ [LibraryClasses] HobLib MemoryAllocationLib SynchronizationLib + VmgExitLib =20 [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard # CONSUMES diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHa= ndlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException= HandlerLib.inf index 6d25cafe2ca3..967cb61ba6d9 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLi= b.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLi= b.inf @@ -48,3 +48,4 @@ [LibraryClasses] PrintLib LocalApicLib PeCoffGetEntryPointLib + VmgExitLib diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandl= erLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandle= rLib.inf index 2ffbbccc302f..4cdb11c04ea0 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.i= nf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.i= nf @@ -51,4 +51,5 @@ [LibraryClasses] LocalApicLib PeCoffGetEntryPointLib DebugLib + VmgExitLib =20 diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExcep= tionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPei= CpuExceptionHandlerLib.inf index 7e21beaab6f2..743c2aa76684 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHan= dlerLib.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHan= dlerLib.inf @@ -53,3 +53,4 @@ [LibraryClasses] PrintLib LocalApicLib PeCoffGetEntryPointLib + VmgExitLib diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c= b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c index 8adbd43fefb4..c9003b10e552 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c @@ -14,7 +14,7 @@ // // 1 means an error code will be pushed, otherwise 0 // -CONST UINT32 mErrorCodeFlag =3D 0x00227d00; +CONST UINT32 mErrorCodeFlag =3D 0x20227d00; =20 // // Define the maximum message length @@ -45,6 +45,14 @@ CONST CHAR8 *mExceptionNameStr[] =3D { "#XM - SIMD floating-point", "#VE - Virtualization", "#CP - Control Protection" + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "#VC - VMM Communication", }; =20 #define EXCEPTION_KNOWN_NAME_NUM (sizeof (mExceptionNameStr) / sizeof (CH= AR8 *)) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuExceptio= n.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c index 6a2670d55918..892d349d4b37 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c @@ -6,8 +6,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 -#include "CpuExceptionCommon.h" #include +#include +#include "CpuExceptionCommon.h" =20 /** Internal worker function for common exception handler. @@ -27,6 +28,23 @@ CommonExceptionHandlerWorker ( RESERVED_VECTORS_DATA *ReservedVectors; EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler; =20 + if (ExceptionType =3D=3D VC_EXCEPTION) { + EFI_STATUS Status; + // + // #VC needs to be handled immediately upon enabling exception handling + // and therefore can't use the RegisterCpuInterruptHandler() interface. + // + // Handle the #VC: + // On EFI_SUCCESS - Exception has been handled, return + // On other - ExceptionType contains (possibly new) exception + // value + // + Status =3D VmgExitHandleVc (&ExceptionType, SystemContext); + if (!EFI_ERROR (Status)) { + return; + } + } + ExceptionHandlerContext =3D (EXCEPTION_HANDLER_CONTEXT *) (UINTN) (Syst= emContext.SystemContextIa32); ReservedVectors =3D ExceptionHandlerData->ReservedVectors; ExternalInterruptHandler =3D ExceptionHandlerData->ExternalInterruptHand= ler; diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c= b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c index 20148db74cf8..52c6886f0372 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c @@ -7,6 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 #include +#include #include "CpuExceptionCommon.h" =20 CONST UINTN mDoFarReturnFlag =3D 0; @@ -24,6 +25,24 @@ CommonExceptionHandler ( IN EFI_SYSTEM_CONTEXT SystemContext ) { + if (ExceptionType =3D=3D VC_EXCEPTION) { + EFI_STATUS Status; + // + // #VC needs to be handled immediately upon enabling exception handling + // and therefore can't use the RegisterCpuInterruptHandler() interface + // (which isn't supported under Sec and Pei anyway). + // + // Handle the #VC: + // On EFI_SUCCESS - Exception has been handled, return + // On other - ExceptionType contains (possibly new) exception + // value + // + Status =3D VmgExitHandleVc (&ExceptionType, SystemContext); + if (!EFI_ERROR (Status)) { + return; + } + } + // // Initialize the serial port before dumping. // diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandler= Asm.nasm b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAs= m.nasm index 3814f9de3703..2a5545ecfd41 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm @@ -18,6 +18,8 @@ ; CommonExceptionHandler() ; =20 +%define VC_EXCEPTION 29 + extern ASM_PFX(mErrorCodeFlag) ; Error code flags for exceptions extern ASM_PFX(mDoFarReturnFlag) ; Do far return flag extern ASM_PFX(CommonExceptionHandler) @@ -224,6 +226,9 @@ HasErrorCode: push rax =20 ;; UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7; + cmp qword [rbp + 8], VC_EXCEPTION + je VcDebugRegs ; For SEV-ES (#VC) Debug registers ignored + mov rax, dr7 push rax mov rax, dr6 @@ -236,7 +241,19 @@ HasErrorCode: push rax mov rax, dr0 push rax + jmp DrFinish =20 +VcDebugRegs: +;; UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7 are skipped for #VC to avoid excep= tion recursion + xor rax, rax + push rax + push rax + push rax + push rax + push rax + push rax + +DrFinish: ;; FX_SAVE_STATE_X64 FxSaveState; sub rsp, 512 mov rdi, rsp diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionH= andlerAsm.nasm b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5Except= ionHandlerAsm.nasm index 19198f273137..26cae56cc5cf 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerA= sm.nasm +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerA= sm.nasm @@ -18,6 +18,8 @@ ; CommonExceptionHandler() ; =20 +%define VC_EXCEPTION 29 + extern ASM_PFX(mErrorCodeFlag) ; Error code flags for exceptions extern ASM_PFX(mDoFarReturnFlag) ; Do far return flag extern ASM_PFX(CommonExceptionHandler) @@ -225,6 +227,9 @@ HasErrorCode: push rax =20 ;; UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7; + cmp qword [rbp + 8], VC_EXCEPTION + je VcDebugRegs ; For SEV-ES (#VC) Debug registers ignored + mov rax, dr7 push rax mov rax, dr6 @@ -237,7 +242,19 @@ HasErrorCode: push rax mov rax, dr0 push rax + jmp DrFinish =20 +VcDebugRegs: +;; UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7 are skipped for #VC to avoid excep= tion recursion + xor rax, rax + push rax + push rax + push rax + push rax + push rax + push rax + +DrFinish: ;; FX_SAVE_STATE_X64 FxSaveState; sub rsp, 512 mov rdi, rsp --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62514): https://edk2.groups.io/g/devel/message/62514 Mute This Topic: https://groups.io/mt/75499813/1787277 Mute #vc: https://groups.io/g/edk2/mutehashtag/vc Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62515+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62515+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 15947370720521014.2498056411549; Tue, 14 Jul 2020 07:31:12 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id SuZyYY1788612x0XzWQPZkdt; Tue, 14 Jul 2020 07:31:11 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.85]) by mx.groups.io with SMTP id smtpd.web12.20864.1594737071084053811 for ; Tue, 14 Jul 2020 07:31:11 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cGStTQ2TV4LKWzjXDetGByy8f1hHpS1Led7mpQACAoisqSa8boP9JUq2R1/IMB7mmriqKkqlBACbCaZQ6ZY0hxKNzM4aU2IKIZLUwDtYjJDQGSF8e0r3zyJnC3gVt4mtQvhVHDVTcROHz4rm6vezAfUsNYKO0rES3cBitMt8KHP2DCnBoUaid3KV0M50jwUqCk3swbaHLC6eib8v7znKtq7dv46rexI2yFlsvI4HVo9+fR9gG33AD6EUM9JkxKpafKhM0H4IiSeUA1v7AIqk9Y5CSdhFQ/BpCUkHQT+T687iu5m+z1r3OEE16UVLGFTL/a+yNjVPCap5RyoU5Rzofw== 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=ZHQl+SU/KHOEnSdZxqtPoUFC/KO2ZWkU5Q8Wgy4/AQ8=; b=nZIehLYfjqFTRUfMoCnD9HNdqlInFEXlGQ0uxp6HV4o39Ns0WHLaHtYbaNpmU77dcWOwjdxq7loQF/egAJa1ccISt3Z2C/H8Kailh0Mhn4B4mUhv7nDddBhFZkh3BCaIB+1rbZgObYgnSepb6NJnGrCscrnHF4YNE83Z6XoJJDMINgq+y4FQpzrw2tnta7ek5HL7KPXmKQ/zhSvnar+JmhXvfBYeIy3OVg8LMP6NTfU+PvSjFMZMk/hP2MA2lEIsVm8f+cA6nxW0qAPtX5IYVV+79pWtKZRd+4AZSmSlSBR7ANU2utFj1cogQo851rpDfMN6paN4mgtJzsC5Nqk8PQ== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:31:09 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:31:09 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 12/46] OvmfPkg/VmgExitLib: Implement library support for VmgExitLib in OVMF Date: Tue, 14 Jul 2020 09:27:43 -0500 Message-ID: <09b154fb3e7bbb0da48a130a125878f66a394a7f.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN1PR12CA0102.namprd12.prod.outlook.com (2603:10b6:802:21::37) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN1PR12CA0102.namprd12.prod.outlook.com (2603:10b6:802:21::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22 via Frontend Transport; Tue, 14 Jul 2020 14:31:08 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 8e606170-34df-46ff-f719-08d828028d09 X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: 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-Message-Info: ZBpkuEoX37ZjJLNjyzPxj2kNDOdWBnXyldRNdMdQ5HaBpi0TqMIr8WY1s5TsB1LYI3LdzgpEPuPucZMHEo4gnjOwUeNojPTbYv5VlwySFdqC4KNoMJ8Dg0f3JsyZWjVez9skS7YVzKXnHpiNiZhdpvsbNkIWy9Hcb/q8qemD4Pw8BEqjuhLVUu4GEnUm1IKWror/RUSJLvouLFJBHtbu5CFiAvfVucFTKsmpFv8nOCeuXwhwIYyYxS6Mt0elsH30sG3SRNpP5AliSIxgDEgltYYke7RR42Ae2dd8StXYYyiTiGg1CRBh5sPa0+baPX/PVMqRbUBFLcHRvgNFCxNqNXq/Q1UQy3b6pZts42tdjQ+twYr2/dFYlmUVXBTzTLLi X-MS-Exchange-AntiSpam-MessageData: Se/o+RRzFxgZWJP31PxblsDUdw/8WSOZKxuSBd9y5roTcMRq21q2sepAUxyqBC7WFnWCYuqNKfMtWKXIdGKiUyqMr5MH9KXBUi1AsI6qL7pzuYZkH8YrCY4xnSC+8Kt66osSkn6Oe6PmG8yapFQC/sllHZjQFxr26lzD0Lih6EVWgYK/e2qnbgBACElAgmzKJ58FqP4V5x0C+TzjxWlDAo/bXhsxKVcyxR2xeKe7FZxg4T+gh1ntZ1gV6J5tW+KykwtjTYkDMHDoGjQSRjM5va6JQsPdP2Cy7xKQrKaw8i0FuMM7YrBzl8dnN0+X4d0sI/hEGoYeL3ZDjpD+5emzigMYtGZDVLyfldXu7SsZm4UC4cvwXW1N4kAfCFrd6S5czw8PKXIfTbrYQbM4V/VSJV2MT/L+aGaLRqL5smP64cRb6nvKrTlm78/kDItxdRi3JcqBWR28Hb1TYy+OmduC6OT6cGxe58LbHIPXFrd0BFM= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8e606170-34df-46ff-f719-08d828028d09 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:31:09.6910 (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: oS0UWJpTkvkqtiNYN56WBldasw9gKj4Jbl1LhgUs2j9C75Z2GlPEwHxzVVZAo11g1oM8q9erHK7LGpaLuDiE4A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: 6cbcA159p6WX1wyAKTuyFLY6x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737071; bh=TjmFtfg68U4dXbzDZViVYZ2nzuOUxI1qkoYsfsdaW1Q=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=hwiOWd7t9Suozt4AdDVIzbNQkiOqgxWdZ3p8ggNxZ6X+OXhGrNktnNwpO/kIFI52vE0 HEFW4i7W89p/JF5iGE6cUtWfeJchuzslpCeLGR3WHsDubtJcjOAFsAIwEz+BQX7BPJZtY fpGPFuOugZPQtktVwlmrTy+Yn1ce/fGVEjI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky The base VmgExitLib library provides a default limited interface. As it does not provide full support, create an OVMF version of this library to begin the process of providing full support of SEV-ES within OVMF. SEV-ES support is only provided for X64 builds, so only OvmfPkgX64.dsc is updated to make use of the OvmfPkg version of the library. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/OvmfPkgX64.dsc | 2 +- OvmfPkg/Library/VmgExitLib/VmgExitLib.inf | 36 ++++ OvmfPkg/Library/VmgExitLib/VmgExitLib.c | 159 ++++++++++++++++++ OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 81 +++++++++ 4 files changed, 277 insertions(+), 1 deletion(-) create mode 100644 OvmfPkg/Library/VmgExitLib/VmgExitLib.inf create mode 100644 OvmfPkg/Library/VmgExitLib/VmgExitLib.c create mode 100644 OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 269b6d973188..6db1f0b51c7c 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -232,7 +232,7 @@ [LibraryClasses] =20 [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf - VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf + VmgExitLib|OvmfPkg/Library/VmgExitLib/VmgExitLib.inf =20 [LibraryClasses.common.SEC] TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitLib.inf b/OvmfPkg/Library/Vm= gExitLib/VmgExitLib.inf new file mode 100644 index 000000000000..d003ac63173e --- /dev/null +++ b/OvmfPkg/Library/VmgExitLib/VmgExitLib.inf @@ -0,0 +1,36 @@ +## @file +# VMGEXIT Support Library. +# +# Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D VmgExitLib + FILE_GUID =3D 0e923c25-13cd-430b-8714-ffe85652a97b + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D VmgExitLib + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D X64 +# + +[Sources.common] + VmgExitLib.c + VmgExitVcHandler.c + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitLib.c b/OvmfPkg/Library/VmgE= xitLib/VmgExitLib.c new file mode 100644 index 000000000000..53040cc6f649 --- /dev/null +++ b/OvmfPkg/Library/VmgExitLib/VmgExitLib.c @@ -0,0 +1,159 @@ +/** @file + VMGEXIT Support Library. + + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include + +/** + Check for VMGEXIT error + + Check if the hypervisor has returned an error after completion of the VM= GEXIT + by examining the SwExitInfo1 field of the GHCB. + + @param[in] Ghcb A pointer to the GHCB + + @retval 0 VMGEXIT succeeded. + @return Exception number to be propagated, VMGEXIT proces= sing + did not succeed. + +**/ +STATIC +UINT64 +VmgExitErrorCheck ( + IN GHCB *Ghcb + ) +{ + GHCB_EVENT_INJECTION Event; + GHCB_EXIT_INFO ExitInfo; + UINT64 Status; + + ExitInfo.Uint64 =3D Ghcb->SaveArea.SwExitInfo1; + ASSERT ((ExitInfo.Elements.Lower32Bits =3D=3D 0) || + (ExitInfo.Elements.Lower32Bits =3D=3D 1)); + + Status =3D 0; + if (ExitInfo.Elements.Lower32Bits =3D=3D 0) { + return Status; + } + + if (ExitInfo.Elements.Lower32Bits =3D=3D 1) { + ASSERT (Ghcb->SaveArea.SwExitInfo2 !=3D 0); + + // + // Check that the return event is valid + // + Event.Uint64 =3D Ghcb->SaveArea.SwExitInfo2; + if (Event.Elements.Valid && + Event.Elements.Type =3D=3D GHCB_EVENT_INJECTION_TYPE_EXCEPTION) { + switch (Event.Elements.Vector) { + case GP_EXCEPTION: + case UD_EXCEPTION: + // + // Use returned event as return code + // + Status =3D Event.Uint64; + } + } + } + + if (Status =3D=3D 0) { + GHCB_EVENT_INJECTION GpEvent; + + GpEvent.Uint64 =3D 0; + GpEvent.Elements.Vector =3D GP_EXCEPTION; + GpEvent.Elements.Type =3D GHCB_EVENT_INJECTION_TYPE_EXCEPTION; + GpEvent.Elements.Valid =3D 1; + + Status =3D GpEvent.Uint64; + } + + return Status; +} + +/** + Perform VMGEXIT. + + Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction a= nd + then handles the return actions. + + @param[in, out] Ghcb A pointer to the GHCB + @param[in] ExitCode VMGEXIT code to be assigned to the SwExitCode + field of the GHCB. + @param[in] ExitInfo1 VMGEXIT information to be assigned to the + SwExitInfo1 field of the GHCB. + @param[in] ExitInfo2 VMGEXIT information to be assigned to the + SwExitInfo2 field of the GHCB. + + @retval 0 VMGEXIT succeeded. + @return Exception number to be propagated, VMGEXIT + processing did not succeed. + +**/ +UINT64 +EFIAPI +VmgExit ( + IN OUT GHCB *Ghcb, + IN UINT64 ExitCode, + IN UINT64 ExitInfo1, + IN UINT64 ExitInfo2 + ) +{ + Ghcb->SaveArea.SwExitCode =3D ExitCode; + Ghcb->SaveArea.SwExitInfo1 =3D ExitInfo1; + Ghcb->SaveArea.SwExitInfo2 =3D ExitInfo2; + + // + // Guest memory is used for the guest-hypervisor communication, so fence + // the invocation of the VMGEXIT instruction to ensure GHCB accesses are + // synchronized properly. + // + MemoryFence (); + AsmVmgExit (); + MemoryFence (); + + return VmgExitErrorCheck (Ghcb); +} + +/** + Perform pre-VMGEXIT initialization/preparation. + + Performs the necessary steps in preparation for invoking VMGEXIT. Must be + called before setting any fields within the GHCB. + + @param[in, out] Ghcb A pointer to the GHCB + +**/ +VOID +EFIAPI +VmgInit ( + IN OUT GHCB *Ghcb + ) +{ + SetMem (&Ghcb->SaveArea, sizeof (Ghcb->SaveArea), 0); +} + +/** + Perform post-VMGEXIT cleanup. + + Performs the necessary steps to cleanup after invoking VMGEXIT. Must be + called after obtaining needed fields within the GHCB. + + @param[in, out] Ghcb A pointer to the GHCB + +**/ +VOID +EFIAPI +VmgDone ( + IN OUT GHCB *Ghcb + ) +{ +} + diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c new file mode 100644 index 000000000000..b6a955ed8088 --- /dev/null +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -0,0 +1,81 @@ +/** @file + X64 #VC Exception Handler functon. + + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include + +/** + Handle a #VC exception. + + Performs the necessary processing to handle a #VC exception. + + @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be s= et + as value to use on error. + @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT + + @retval EFI_SUCCESS Exception handled + @retval EFI_UNSUPPORTED #VC not supported, (new) exception value= to + propagate provided + @retval EFI_PROTOCOL_ERROR #VC handling failed, (new) exception val= ue to + propagate provided + +**/ +EFI_STATUS +EFIAPI +VmgExitHandleVc ( + IN OUT EFI_EXCEPTION_TYPE *ExceptionType, + IN OUT EFI_SYSTEM_CONTEXT SystemContext + ) +{ + MSR_SEV_ES_GHCB_REGISTER Msr; + EFI_SYSTEM_CONTEXT_X64 *Regs; + GHCB *Ghcb; + UINT64 ExitCode, Status; + EFI_STATUS VcRet; + + VcRet =3D EFI_SUCCESS; + + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + ASSERT (Msr.GhcbInfo.Function =3D=3D 0); + ASSERT (Msr.Ghcb !=3D 0); + + Regs =3D SystemContext.SystemContextX64; + Ghcb =3D Msr.Ghcb; + + VmgInit (Ghcb); + + ExitCode =3D Regs->ExceptionData; + switch (ExitCode) { + default: + Status =3D VmgExit (Ghcb, SVM_EXIT_UNSUPPORTED, ExitCode, 0); + if (Status =3D=3D 0) { + Regs->ExceptionData =3D 0; + *ExceptionType =3D GP_EXCEPTION; + } else { + GHCB_EVENT_INJECTION Event; + + Event.Uint64 =3D Status; + if (Event.Elements.ErrorCodeValid !=3D 0) { + Regs->ExceptionData =3D Event.Elements.ErrorCode; + } else { + Regs->ExceptionData =3D 0; + } + + *ExceptionType =3D Event.Elements.Vector; + } + + VcRet =3D EFI_PROTOCOL_ERROR; + } + + VmgDone (Ghcb); + + return VcRet; +} --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62515): https://edk2.groups.io/g/devel/message/62515 Mute This Topic: https://groups.io/mt/75499815/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62516+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62516+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594737085269272.22114276789546; Tue, 14 Jul 2020 07:31:25 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id VwYYYY1788612xLHCfA0YgvY; Tue, 14 Jul 2020 07:31:24 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.53]) by mx.groups.io with SMTP id smtpd.web10.21086.1594737084324296317 for ; Tue, 14 Jul 2020 07:31:24 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EoFoFmXZLuci1IMJTrcdYE4CZYky9jdMGgM7qj/2uYdKA1lC59VLRSFOO/l3S9DlBa0+n9sJTVU0HunJOI/PE7bHMt1cKCe3Z7whQN1EO08AZ553WHUrQzu5pCRpgpkioieOQKe8GIsFkKR/pOTe5IdhbslBSVyH8zbeauHz/Neb235i80oAIbJKxTL9YR90Be244O9/vyv/02nqqxXMiWTtlP/KGA1Ie/YaLr9L8T4e/TszF+3m8p6txRZl9K4CbEk/gcNTorrkfUfbR8qHgx+TZ89zqSEHY7DH8Uk2BHw3rapK3JpzctFYjNyU5dZ0LAKd5jGidOux16PvQrSxmA== 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=YLiynLfWPYBI3p6aciiysyOQa+ljPEYq8UZEiba60Qk=; b=cv8wPD4NpGSlDY+x4tgMcvbt9fBoPf4VKd1DgDEu9mbKJI13CGmvkOqjfX9DDw8YpWBLQcnCksAalXVj+V/VqaMHHv/oXa37Uh/MECRiIhZVxULqr18L94TqwgQJ+qosB2boxureviFmZ//XtaZR6jJycFzEKgi2d4E3gTz+ioiXMSadlO+w2XGZorGOU+blpQOeaUYhQ4HcP0b8uZDwGDN4tSoaj+2KkbkcoNasjeTVLdfU6hnIW6DsvWPE0E+ITYts5XxoUa4k92+UgRORFCnL+AALnrYVL6M+CSD1GWtMHjmh4e8pR92ym37wnQu7vTqXUO1r+rwfF/kudkV/FQ== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:31:22 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:31:22 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 13/46] OvmfPkg/VmgExitLib: Add support for IOIO_PROT NAE events Date: Tue, 14 Jul 2020 09:27:44 -0500 Message-ID: <469d858b701644a3b2597616d606f8fe0ed1d24f.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SA9PR03CA0020.namprd03.prod.outlook.com (2603:10b6:806:20::25) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SA9PR03CA0020.namprd03.prod.outlook.com (2603:10b6:806:20::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.23 via Frontend Transport; Tue, 14 Jul 2020 14:31:21 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: cb6b6b29-6b0d-466b-3f66-08d8280294ba X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: sCoYLPy7tFmsRpxuiXNL8fbBRxRQv8HpjNXyMe/8KNHzUpC/UBtlmCj3sJXrye7gHwx78Co/7ZEWk4Y172pXebdcw6yyf56rkvCqMBEoyGVXsqDRXX8JApRhIudRFw9SypYSO1mhYrpP/bkIexAylBSf6eE4OZn3+cfu1WEJN3MgPSY3neBu6jsL2Hev6geDZbhRcFiQVZtq7FpiJy6H5mUWYg5TPeSGaT3Q7UDjHUE0wWpMpAYZu79f0r8YKlXVBiJNH7rBuvnIeMKUySH5lUE6OGghVo16R/NRawIZtS/Be75BJ5Rw7pbwt8R6vnd+/IjWVprQ+2MM4Cun4A7uvRKZQDkjh8tbycjI4M1IE42dmo2PO1BKACHhQvjAkB+ziVZme/EhGsQOwnBX/S05ZcY4V91aGWtSTQYSRYW/7V7E73fFANKVIxA5WPt32/b3yHccpS18rFZGcSonJqQsQg== X-MS-Exchange-AntiSpam-MessageData: dvlMjzFfUGL6OIlS62PTCVxjs75LBNpXg6WJQtoauFyrTDt/vqVOMB9+LxG5Cb2AWwp5ddVcCg02CaX36vPwrjB9uRVTVMGDyb244USkDrqXyluF2DTAGUjDkAdVMXYaRq/K7iprQSe5x12DJfddEorMZLMi6gIjuWTuZN/4KR4UXh0GpXpq8dBx83Tx5OKpq4Vd+1uc3Xs7OfOf/UzDHOnWj2+77W6WLkKO/Tu35vT3L+p0zJGHKS1q9WYeZ3fC1vC6VRfA1RYr/9GQYERx2dM1bJjZDTkMj8BXhL6AzmaGXQBj7VuYthlTTCSojEsirp/G3dJrSZyGdXZUtEvPUtdzPjJiBZwMjHCstq4czSbCXLxCXRgiZpqPU/N5IIR1wTpogDHR82FyqjjYaSCj272WybofWOHE4UbCP6wyhIvaQ37kNCe3bWZ9v8TVnw4rEygQveWlbYeDFPaLdGFduVvkGHy3RmUWA99LQqdEiAc= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: cb6b6b29-6b0d-466b-3f66-08d8280294ba X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:31:22.6693 (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: TUfJeBvkmMwISSiYYe0JKGCpysQftnRGC5+Qwuqg0pNqimPkNH0QH65BrVine7EXc3OhOMQ/Ei8w8NIE2iULhQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: QVFY7XfezRzJmMf0in9OhiRPx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737084; bh=w3qBpPujZqRvFxHXgQM8IdlEzJBc9l7wHqyvpnonVVI=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=AQMqHjKk9Y7dqf+MqBeosi6PPthRf2NzUCO+iyvjI/AJzxKdPDeuyQih/C95NOewE5Z Y23n+xTyVd47hgPG0kcAZYMuriY1zrH34lhG1vvwd1z8UZJm0bFu3los1SoykwfSa9+PI IxrzY9PBJkQ9FJCnyIl62m7erA3fEVdqD6c= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a IOIO_PROT intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Add support to construct the required GHCB values to support a IOIO_PROT NAE event. Parse the instruction that generated the #VC exception, setting the required register values in the GHCB and creating the proper SW_EXITINFO1 value in the GHCB. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- .../IndustryStandard/InstructionParsing.h | 83 +++ OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 560 +++++++++++++++++- 2 files changed, 629 insertions(+), 14 deletions(-) create mode 100644 OvmfPkg/Include/IndustryStandard/InstructionParsing.h diff --git a/OvmfPkg/Include/IndustryStandard/InstructionParsing.h b/OvmfPk= g/Include/IndustryStandard/InstructionParsing.h new file mode 100644 index 000000000000..149ff328e06c --- /dev/null +++ b/OvmfPkg/Include/IndustryStandard/InstructionParsing.h @@ -0,0 +1,83 @@ +/** @file + Instruction parsing support definitions. + + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef __INSTRUCTION_PARSING_H__ +#define __INSTRUCTION_PARSING_H__ + +#include +#include + +// +// Instruction REX prefix definition +// +typedef union { + struct { + UINT8 BitB:1; + UINT8 BitX:1; + UINT8 BitR:1; + UINT8 BitW:1; + UINT8 Rex:4; + } Bits; + + UINT8 Uint8; +} INSTRUCTION_REX_PREFIX; + +// +// Instruction ModRM definition +// +typedef union { + struct { + UINT8 Rm:3; + UINT8 Reg:3; + UINT8 Mod:2; + } Bits; + + UINT8 Uint8; +} INSTRUCTION_MODRM; + +// +// Instruction SIB definition +// +typedef union { + struct { + UINT8 Base:3; + UINT8 Index:3; + UINT8 Scale:2; + } Bits; + + UINT8 Uint8; +} INSTRUCTION_SIB; + +// +// Legacy Instruction Prefixes +// +#define OVERRIDE_SEGMENT_CS 0x2E +#define OVERRIDE_SEGMENT_DS 0x3E +#define OVERRIDE_SEGMENT_ES 0x26 +#define OVERRIDE_SEGMENT_SS 0x36 +#define OVERRIDE_SEGMENT_FS 0x64 +#define OVERRIDE_SEGMENT_GS 0x65 +#define OVERRIDE_OPERAND_SIZE 0x66 +#define OVERRIDE_ADDRESS_SIZE 0x67 +#define LOCK_PREFIX 0xF0 +#define REPNZ_PREFIX 0xF2 +#define REPZ_PREFIX 0xF3 + +// +// REX Prefixes +// +#define REX_PREFIX_START 0x40 +#define REX_PREFIX_STOP 0x4F +#define REX_64BIT_OPERAND_SIZE_MASK 0x08 + +// +// Two-byte Opcode Flag +// +#define TWO_BYTE_OPCODE_ESCAPE 0x0F + +#endif diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index b6a955ed8088..04e8b8aebf7d 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -11,6 +11,529 @@ #include #include #include +#include + +// +// Instruction execution mode definition +// +typedef enum { + LongMode64Bit =3D 0, + LongModeCompat32Bit, + LongModeCompat16Bit, +} SEV_ES_INSTRUCTION_MODE; + +// +// Instruction size definition (for operand and address) +// +typedef enum { + Size8Bits =3D 0, + Size16Bits, + Size32Bits, + Size64Bits, +} SEV_ES_INSTRUCTION_SIZE; + +// +// Intruction segment definition +// +typedef enum { + SegmentEs =3D 0, + SegmentCs, + SegmentSs, + SegmentDs, + SegmentFs, + SegmentGs, +} SEV_ES_INSTRUCTION_SEGMENT; + +// +// Instruction rep function definition +// +typedef enum { + RepNone =3D 0, + RepZ, + RepNZ, +} SEV_ES_INSTRUCTION_REP; + +typedef struct { + UINT8 Rm; + UINT8 Reg; + UINT8 Mod; +} SEV_ES_INSTRUCTION_MODRM_EXT; + +typedef struct { + UINT8 Base; + UINT8 Index; + UINT8 Scale; +} SEV_ES_INSTRUCTION_SIB_EXT; + +// +// Instruction opcode definition +// +typedef struct { + SEV_ES_INSTRUCTION_MODRM_EXT ModRm; + + SEV_ES_INSTRUCTION_SIB_EXT Sib; + + UINTN RegData; + UINTN RmData; +} SEV_ES_INSTRUCTION_OPCODE_EXT; + +// +// Instruction parsing context definition +// +typedef struct { + GHCB *Ghcb; + + SEV_ES_INSTRUCTION_MODE Mode; + SEV_ES_INSTRUCTION_SIZE DataSize; + SEV_ES_INSTRUCTION_SIZE AddrSize; + BOOLEAN SegmentSpecified; + SEV_ES_INSTRUCTION_SEGMENT Segment; + SEV_ES_INSTRUCTION_REP RepMode; + + UINT8 *Begin; + UINT8 *End; + + UINT8 *Prefixes; + UINT8 *OpCodes; + UINT8 *Displacement; + UINT8 *Immediate; + + INSTRUCTION_REX_PREFIX RexPrefix; + + BOOLEAN ModRmPresent; + INSTRUCTION_MODRM ModRm; + + BOOLEAN SibPresent; + INSTRUCTION_SIB Sib; + + UINTN PrefixSize; + UINTN OpCodeSize; + UINTN DisplacementSize; + UINTN ImmediateSize; + + SEV_ES_INSTRUCTION_OPCODE_EXT Ext; +} SEV_ES_INSTRUCTION_DATA; + +// +// Non-automatic Exit function prototype +// +typedef +UINT64 +(*NAE_EXIT) ( + GHCB *Ghcb, + EFI_SYSTEM_CONTEXT_X64 *Regs, + SEV_ES_INSTRUCTION_DATA *InstructionData + ); + + +/** + Checks the GHCB to determine if the specified register has been marked v= alid. + + The ValidBitmap area represents the areas of the GHCB that have been mar= ked + valid. Return an indication of whether the area of the GHCB that holds t= he + specified register has been marked valid. + + @param[in] Ghcb Pointer to the Guest-Hypervisor Communication Block + @param[in] Reg Offset in the GHCB of the register to check + + @retval TRUE Register has been marked vald in the GHCB + @retval FALSE Register has not been marked valid in the GHCB + +**/ +STATIC +BOOLEAN +GhcbIsRegValid ( + IN GHCB *Ghcb, + IN GHCB_REGISTER Reg + ) +{ + UINT32 RegIndex; + UINT32 RegBit; + + RegIndex =3D Reg / 8; + RegBit =3D Reg & 0x07; + + return ((Ghcb->SaveArea.ValidBitmap[RegIndex] & (1 << RegBit)) !=3D 0); +} + +/** + Marks a register as valid in the GHCB. + + The ValidBitmap area represents the areas of the GHCB that have been mar= ked + valid. Set the area of the GHCB that holds the specified register as val= id. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communication Bl= ock + @param[in] Reg Offset in the GHCB of the register to mark valid + +**/ +STATIC +VOID +GhcbSetRegValid ( + IN OUT GHCB *Ghcb, + IN GHCB_REGISTER Reg + ) +{ + UINT32 RegIndex; + UINT32 RegBit; + + RegIndex =3D Reg / 8; + RegBit =3D Reg & 0x07; + + Ghcb->SaveArea.ValidBitmap[RegIndex] |=3D (1 << RegBit); +} + +/** + Decode instruction prefixes. + + Parse the instruction data to track the instruction prefixes that have + been used. + + @param[in] Regs x64 processor context + @param[in, out] InstructionData Instruction parsing context + +**/ +STATIC +VOID +DecodePrefixes ( + IN EFI_SYSTEM_CONTEXT_X64 *Regs, + IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + SEV_ES_INSTRUCTION_MODE Mode; + SEV_ES_INSTRUCTION_SIZE ModeDataSize; + SEV_ES_INSTRUCTION_SIZE ModeAddrSize; + UINT8 *Byte; + + // + // Always in 64-bit mode + // + Mode =3D LongMode64Bit; + ModeDataSize =3D Size32Bits; + ModeAddrSize =3D Size64Bits; + + InstructionData->Mode =3D Mode; + InstructionData->DataSize =3D ModeDataSize; + InstructionData->AddrSize =3D ModeAddrSize; + + InstructionData->Prefixes =3D InstructionData->Begin; + + Byte =3D InstructionData->Prefixes; + for ( ; ; Byte++, InstructionData->PrefixSize++) { + // + // Check the 0x40 to 0x4F range using an if statement here since some + // compilers don't like the "case 0x40 ... 0x4F:" syntax. This avoids + // 16 case statements below. + // + if ((*Byte >=3D REX_PREFIX_START) && (*Byte <=3D REX_PREFIX_STOP)) { + InstructionData->RexPrefix.Uint8 =3D *Byte; + if ((*Byte & REX_64BIT_OPERAND_SIZE_MASK) !=3D 0) { + InstructionData->DataSize =3D Size64Bits; + } + continue; + } + + switch (*Byte) { + case OVERRIDE_SEGMENT_CS: + case OVERRIDE_SEGMENT_DS: + case OVERRIDE_SEGMENT_ES: + case OVERRIDE_SEGMENT_SS: + if (Mode !=3D LongMode64Bit) { + InstructionData->SegmentSpecified =3D TRUE; + InstructionData->Segment =3D (*Byte >> 3) & 3; + } + break; + + case OVERRIDE_SEGMENT_FS: + case OVERRIDE_SEGMENT_GS: + InstructionData->SegmentSpecified =3D TRUE; + InstructionData->Segment =3D *Byte & 7; + break; + + case OVERRIDE_OPERAND_SIZE: + if (InstructionData->RexPrefix.Uint8 =3D=3D 0) { + InstructionData->DataSize =3D + (Mode =3D=3D LongMode64Bit) ? Size16Bits : + (Mode =3D=3D LongModeCompat32Bit) ? Size16Bits : + (Mode =3D=3D LongModeCompat16Bit) ? Size32Bits : 0; + } + break; + + case OVERRIDE_ADDRESS_SIZE: + InstructionData->AddrSize =3D + (Mode =3D=3D LongMode64Bit) ? Size32Bits : + (Mode =3D=3D LongModeCompat32Bit) ? Size16Bits : + (Mode =3D=3D LongModeCompat16Bit) ? Size32Bits : 0; + break; + + case LOCK_PREFIX: + break; + + case REPZ_PREFIX: + InstructionData->RepMode =3D RepZ; + break; + + case REPNZ_PREFIX: + InstructionData->RepMode =3D RepNZ; + break; + + default: + InstructionData->OpCodes =3D Byte; + InstructionData->OpCodeSize =3D (*Byte =3D=3D TWO_BYTE_OPCODE_ESCAPE= ) ? 2 : 1; + + InstructionData->End =3D Byte + InstructionData->OpCodeSize; + InstructionData->Displacement =3D InstructionData->End; + InstructionData->Immediate =3D InstructionData->End; + return; + } + } +} + +/** + Determine instruction length + + Return the total length of the parsed instruction. + + @param[in] InstructionData Instruction parsing context + + @return Length of parsed instruction + +**/ +STATIC +UINT64 +InstructionLength ( + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + return (UINT64) (InstructionData->End - InstructionData->Begin); +} + +/** + Initialize the instruction parsing context. + + Initialize the instruction parsing context, which includes decoding the + instruction prefixes. + + @param[in, out] InstructionData Instruction parsing context + @param[in] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in] Regs x64 processor context + +**/ +STATIC +VOID +InitInstructionData ( + IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData, + IN GHCB *Ghcb, + IN EFI_SYSTEM_CONTEXT_X64 *Regs + ) +{ + SetMem (InstructionData, sizeof (*InstructionData), 0); + InstructionData->Ghcb =3D Ghcb; + InstructionData->Begin =3D (UINT8 *) Regs->Rip; + InstructionData->End =3D (UINT8 *) Regs->Rip; + + DecodePrefixes (Regs, InstructionData); +} + +/** + Report an unsupported event to the hypervisor + + Use the VMGEXIT support to report an unsupported event to the hypervisor. + + @param[in] Ghcb Pointer to the Guest-Hypervisor Communication + Block + @param[in] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @return New exception value to propagate + +**/ +STATIC +UINT64 +UnsupportedExit ( + IN GHCB *Ghcb, + IN EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + Status =3D VmgExit (Ghcb, SVM_EXIT_UNSUPPORTED, Regs->ExceptionData, 0); + if (Status =3D=3D 0) { + GHCB_EVENT_INJECTION Event; + + Event.Uint64 =3D 0; + Event.Elements.Vector =3D GP_EXCEPTION; + Event.Elements.Type =3D GHCB_EVENT_INJECTION_TYPE_EXCEPTION; + Event.Elements.Valid =3D 1; + + Status =3D Event.Uint64; + } + + return Status; +} + +/** + Build the IOIO event information. + + The IOIO event information identifies the type of IO operation to be per= formed + by the hypervisor. Build this information based on the instruction data. + + @param[in] Regs x64 processor context + @param[in, out] InstructionData Instruction parsing context + + @return IOIO event information value + +**/ +STATIC +UINT64 +IoioExitInfo ( + IN EFI_SYSTEM_CONTEXT_X64 *Regs, + IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 ExitInfo; + + ExitInfo =3D 0; + + switch (*(InstructionData->OpCodes)) { + // + // IN immediate opcodes + // + case 0xE4: + case 0xE5: + InstructionData->ImmediateSize =3D 1; + InstructionData->End++; + ExitInfo |=3D IOIO_TYPE_IN; + ExitInfo |=3D ((*(InstructionData->OpCodes + 1)) << 16); + break; + + // + // OUT immediate opcodes + // + case 0xE6: + case 0xE7: + InstructionData->ImmediateSize =3D 1; + InstructionData->End++; + ExitInfo |=3D IOIO_TYPE_OUT; + ExitInfo |=3D ((*(InstructionData->OpCodes + 1)) << 16) | IOIO_TYPE_OU= T; + break; + + // + // IN register opcodes + // + case 0xEC: + case 0xED: + ExitInfo |=3D IOIO_TYPE_IN; + ExitInfo |=3D ((Regs->Rdx & 0xffff) << 16); + break; + + // + // OUT register opcodes + // + case 0xEE: + case 0xEF: + ExitInfo |=3D IOIO_TYPE_OUT; + ExitInfo |=3D ((Regs->Rdx & 0xffff) << 16); + break; + + default: + return 0; + } + + switch (*(InstructionData->OpCodes)) { + // + // Single-byte opcodes + // + case 0xE4: + case 0xE6: + case 0xEC: + case 0xEE: + ExitInfo |=3D IOIO_DATA_8; + break; + + // + // Length determined by instruction parsing + // + default: + ExitInfo |=3D (InstructionData->DataSize =3D=3D Size16Bits) ? IOIO_DAT= A_16 + : IOIO_DATA_32; + } + + switch (InstructionData->AddrSize) { + case Size16Bits: + ExitInfo |=3D IOIO_ADDR_16; + break; + + case Size32Bits: + ExitInfo |=3D IOIO_ADDR_32; + break; + + case Size64Bits: + ExitInfo |=3D IOIO_ADDR_64; + break; + + default: + break; + } + + if (InstructionData->RepMode !=3D 0) { + ExitInfo |=3D IOIO_REP; + } + + return ExitInfo; +} + +/** + Handle an IOIO event. + + Use the VMGEXIT instruction to handle an IOIO event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +IoioExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 ExitInfo1, Status; + + ExitInfo1 =3D IoioExitInfo (Regs, InstructionData); + if (ExitInfo1 =3D=3D 0) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + + if ((ExitInfo1 & IOIO_TYPE_IN) !=3D 0) { + Ghcb->SaveArea.Rax =3D 0; + } else { + CopyMem (&Ghcb->SaveArea.Rax, &Regs->Rax, IOIO_DATA_BYTES (ExitInfo1)); + } + GhcbSetRegValid (Ghcb, GhcbRax); + + Status =3D VmgExit (Ghcb, SVM_EXIT_IOIO_PROT, ExitInfo1, 0); + if (Status !=3D 0) { + return Status; + } + + if ((ExitInfo1 & IOIO_TYPE_IN) !=3D 0) { + if (!GhcbIsRegValid (Ghcb, GhcbRax)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + CopyMem (&Regs->Rax, &Ghcb->SaveArea.Rax, IOIO_DATA_BYTES (ExitInfo1)); + } + + return 0; +} =20 /** Handle a #VC exception. @@ -38,6 +561,8 @@ VmgExitHandleVc ( MSR_SEV_ES_GHCB_REGISTER Msr; EFI_SYSTEM_CONTEXT_X64 *Regs; GHCB *Ghcb; + NAE_EXIT NaeExit; + SEV_ES_INSTRUCTION_DATA InstructionData; UINT64 ExitCode, Status; EFI_STATUS VcRet; =20 @@ -54,24 +579,31 @@ VmgExitHandleVc ( =20 ExitCode =3D Regs->ExceptionData; switch (ExitCode) { + case SVM_EXIT_IOIO_PROT: + NaeExit =3D IoioExit; + break; + default: - Status =3D VmgExit (Ghcb, SVM_EXIT_UNSUPPORTED, ExitCode, 0); - if (Status =3D=3D 0) { - Regs->ExceptionData =3D 0; - *ExceptionType =3D GP_EXCEPTION; + NaeExit =3D UnsupportedExit; + } + + InitInstructionData (&InstructionData, Ghcb, Regs); + + Status =3D NaeExit (Ghcb, Regs, &InstructionData); + if (Status =3D=3D 0) { + Regs->Rip +=3D InstructionLength (&InstructionData); + } else { + GHCB_EVENT_INJECTION Event; + + Event.Uint64 =3D Status; + if (Event.Elements.ErrorCodeValid !=3D 0) { + Regs->ExceptionData =3D Event.Elements.ErrorCode; } else { - GHCB_EVENT_INJECTION Event; - - Event.Uint64 =3D Status; - if (Event.Elements.ErrorCodeValid !=3D 0) { - Regs->ExceptionData =3D Event.Elements.ErrorCode; - } else { - Regs->ExceptionData =3D 0; - } - - *ExceptionType =3D Event.Elements.Vector; + Regs->ExceptionData =3D 0; } =20 + *ExceptionType =3D Event.Elements.Vector; + VcRet =3D EFI_PROTOCOL_ERROR; } =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62516): https://edk2.groups.io/g/devel/message/62516 Mute This Topic: https://groups.io/mt/75499818/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62517+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62517+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 159473709956330.8598863497989; Tue, 14 Jul 2020 07:31:39 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id EQCVYY1788612x5gqaFvBakL; Tue, 14 Jul 2020 07:31:39 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.79]) by mx.groups.io with SMTP id smtpd.web12.20876.1594737098343427693 for ; Tue, 14 Jul 2020 07:31:38 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=a4FEjteb4MEGp9BaYJ3KBK0BlSNks34ep0suhggg2+dp60aLsVf4pr0HGMoMfo45Mk4B7oYZKM69By97kARb/SePsxDMV8JwlT2u3w1KSpssKjouRfE17Rc0UwXu7uas5lBBeoH3FT6YeBG/Z2fIi/jviZVJJph0Uz93cmW24wQj0zHPEf0dzoaYqKROM1FWYZVC92JX4xLSW5yUZh0dvuu8tOjOJrgNjWkzBnqINOSmPuxoDfB6O/ixu6LmRYQbgO+CARnNupM3ktcfJuzdq2s8qkMPkA0bhtg7KZtZKG9YczBiAaPq2QLkdHqqmeJNg5StjWSwEE+X0ByF5cZ8iw== 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=QsU9z538ohZ+gSll/ViYNK4rF8hs9EY7Z10fIy3XOy0=; b=Le3BWxUqDSN4N6mPS8lftnPnojYx8NwWR++1I/IJ6vpO5LNBl5ssaHTJ82dt1DRHyd6ylDaF1HthOIfrg5T0wwc+WWwn5clcnDqnojmi+GQrOkMnbA+o9rIi4+7tm3uksdQSB/hkKmGB55LHuBHMho2WaOqp3R6NXOZ9ceRfHalOSWGw70WPr/vZ5/TIVyuokdNkOD1uF2rc28HP7NYuWDIvC6G0W10Uqh7o/p+0hy2I0ODHNSRo1nHAtCasQpLFnzG9t0tuv86Wpk8yHT8Lpa2usAtm6zxO64y+TQc3ITXTIaoqrrhc9GAC1P+XUOMsT1hi9j5BbY9A5/5SPrWGQQ== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:31:36 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:31:36 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 14/46] OvmfPkg/VmgExitLib: Support string IO for IOIO_PROT NAE events Date: Tue, 14 Jul 2020 09:27:45 -0500 Message-ID: <60a44c3029fcbe2f7f8ee329147130ab8be2357c.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0201CA0006.namprd02.prod.outlook.com (2603:10b6:803:2b::16) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0201CA0006.namprd02.prod.outlook.com (2603:10b6:803:2b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22 via Frontend Transport; Tue, 14 Jul 2020 14:31:34 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 4c881592-076e-4872-8886-08d828029ccb X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: kGs2do5rX5HWzHW2sfa6K0hFpLbWmv23ErwMx0cJ60fwiMoOJxsNPSQ0xdbZ5ehuDYDex523AcKZb11uZBkK+tWePoTcHF2jlpdSn7l+ewZrRfq8lKu8xCAfMqnZsdaQEO2WBXCmUPFz+IOtOQNsC3Av2g4+8aVKsXhxnnH77TpJN9ZcTBcAE2vJeXWve00oMh1GW2PAikbs/feyM32KRDfYeu+Gp1d1vw9d/1+HSzE2KHGNOMYIPha6mGBKYBGfIpYc9MbHkFPJHW+u4T91NneITUHzC9A1iM+OF6caNFigsVhmCtXZjYMW5I+ZiERtysvL6/w32e2Eqdr2q8D88gthScd/VnZ4TcJRfH/hWvO8jUDfUL15ZL8IayrthgGXmDs4PEOWwHWrbXIgDEhHfDrqq7Cmgxo5rSim4xba+2LkwV+N51CFSlfJToxYhV1/6FTcID7t62sZ+9DG8dw5ZA== X-MS-Exchange-AntiSpam-MessageData: Uyu7UqcpkITLkVp8EIiu/V2tN0lJL8J7GUs6r9desKzY5nVJ0bbsUrdrSAo0v4E+9YdLvQZG6gcoDLh08tJUp7g2ETgOf5P8JUqstIFj59JbRTrGJ++K3zF7NyC5krj2Ek+X3LNxR4JpktLaq69SpnEx4gatyz33v6jUb4PdkHedLDDIDeMxzp0gFIEJwLMXegjNI9G6/txyX1PPfnbHctjdwYCcXjaziNSBukuiPrJu3exGlu3INP+LrnDe8F7rHYXKPzrn0GpL4RX+aKfpBjOH0qcuVQaW/O/CXnaHlWoA9WeN5pZu2e8lypKst8Y2DPTFHtoBGHkD6aKF6z/BgcDVB1MCdZJDCw7alhl5ATxuQ2JIsmCgEEc1ecLKTHncYsbm8CL/UAWbsKEIQH4nUNw9HbYX8cbKNvHJNxyUsnfKblReM50zPFb3gIxP9MfHDIkilf/wZ84CpMsx112VrwMzpLkTKjgR2nSB942ImtU= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4c881592-076e-4872-8886-08d828029ccb X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:31:36.1244 (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: OGf6V96FV4wsH9r7j0HTyJdhXHyGWuGQv3jeWof5i3WN2wSLV/82XAVCpPuPh/o1sdvKZQcF4EPa48WxkTfFfQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: gQ05h4bmFa508rywOzNnt3k1x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737099; bh=WYmdPYjAojG7j7DoaAKvak9r4n1Pcm7Xm4gDLRbQ8NY=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=pbA/dnoO2/OJ+Q/we3bkXmax6YlqFAr6lxrWRRlPpvMUvSTbbXuhcDeacVVUxB3EqPt A1fFAoqEMjK3Uqy201TKnFBnsQxOYD7oSVx1qKVt+XOmeBSJjLqHHv5u5W4xuvy/gk44t 08W9m4+EqTYM/QD93ZZTP8BguCWFWaFzm+A= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Add support to the #VC exception handler to handle string IO. This requires expanding the IO instruction parsing to recognize string based IO instructions as well as preparing an un-encrypted buffer to be used to transfer (either to or from the guest) the string contents for the IO operation. The SW_EXITINFO2 and SW_SCRATCH fields of the GHCB are set appropriately for the operation. Multiple VMGEXIT invocations may be needed to complete the string IO operation. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 90 ++++++++++++++++--- 1 file changed, 76 insertions(+), 14 deletions(-) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index 04e8b8aebf7d..b6ac3552894f 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -397,6 +397,26 @@ IoioExitInfo ( ExitInfo =3D 0; =20 switch (*(InstructionData->OpCodes)) { + // + // INS opcodes + // + case 0x6C: + case 0x6D: + ExitInfo |=3D IOIO_TYPE_INS; + ExitInfo |=3D IOIO_SEG_ES; + ExitInfo |=3D ((Regs->Rdx & 0xffff) << 16); + break; + + // + // OUTS opcodes + // + case 0x6E: + case 0x6F: + ExitInfo |=3D IOIO_TYPE_OUTS; + ExitInfo |=3D IOIO_SEG_DS; + ExitInfo |=3D ((Regs->Rdx & 0xffff) << 16); + break; + // // IN immediate opcodes // @@ -445,6 +465,8 @@ IoioExitInfo ( // // Single-byte opcodes // + case 0x6C: + case 0x6E: case 0xE4: case 0xE6: case 0xEC: @@ -506,30 +528,70 @@ IoioExit ( IN SEV_ES_INSTRUCTION_DATA *InstructionData ) { - UINT64 ExitInfo1, Status; + UINT64 ExitInfo1, ExitInfo2, Status; + BOOLEAN IsString; =20 ExitInfo1 =3D IoioExitInfo (Regs, InstructionData); if (ExitInfo1 =3D=3D 0) { return UnsupportedExit (Ghcb, Regs, InstructionData); } =20 - if ((ExitInfo1 & IOIO_TYPE_IN) !=3D 0) { - Ghcb->SaveArea.Rax =3D 0; + IsString =3D ((ExitInfo1 & IOIO_TYPE_STR) !=3D 0) ? TRUE : FALSE; + if (IsString) { + UINTN IoBytes, VmgExitBytes; + UINTN GhcbCount, OpCount; + + Status =3D 0; + + IoBytes =3D IOIO_DATA_BYTES (ExitInfo1); + GhcbCount =3D sizeof (Ghcb->SharedBuffer) / IoBytes; + + OpCount =3D ((ExitInfo1 & IOIO_REP) !=3D 0) ? Regs->Rcx : 1; + while (OpCount) { + ExitInfo2 =3D MIN (OpCount, GhcbCount); + VmgExitBytes =3D ExitInfo2 * IoBytes; + + if ((ExitInfo1 & IOIO_TYPE_IN) =3D=3D 0) { + CopyMem (Ghcb->SharedBuffer, (VOID *) Regs->Rsi, VmgExitBytes); + Regs->Rsi +=3D VmgExitBytes; + } + + Ghcb->SaveArea.SwScratch =3D (UINT64) Ghcb->SharedBuffer; + Status =3D VmgExit (Ghcb, SVM_EXIT_IOIO_PROT, ExitInfo1, ExitInfo2); + if (Status !=3D 0) { + return Status; + } + + if ((ExitInfo1 & IOIO_TYPE_IN) !=3D 0) { + CopyMem ((VOID *) Regs->Rdi, Ghcb->SharedBuffer, VmgExitBytes); + Regs->Rdi +=3D VmgExitBytes; + } + + if ((ExitInfo1 & IOIO_REP) !=3D 0) { + Regs->Rcx -=3D ExitInfo2; + } + + OpCount -=3D ExitInfo2; + } } else { - CopyMem (&Ghcb->SaveArea.Rax, &Regs->Rax, IOIO_DATA_BYTES (ExitInfo1)); - } - GhcbSetRegValid (Ghcb, GhcbRax); + if ((ExitInfo1 & IOIO_TYPE_IN) !=3D 0) { + Ghcb->SaveArea.Rax =3D 0; + } else { + CopyMem (&Ghcb->SaveArea.Rax, &Regs->Rax, IOIO_DATA_BYTES (ExitInfo1= )); + } + GhcbSetRegValid (Ghcb, GhcbRax); =20 - Status =3D VmgExit (Ghcb, SVM_EXIT_IOIO_PROT, ExitInfo1, 0); - if (Status !=3D 0) { - return Status; - } + Status =3D VmgExit (Ghcb, SVM_EXIT_IOIO_PROT, ExitInfo1, 0); + if (Status !=3D 0) { + return Status; + } =20 - if ((ExitInfo1 & IOIO_TYPE_IN) !=3D 0) { - if (!GhcbIsRegValid (Ghcb, GhcbRax)) { - return UnsupportedExit (Ghcb, Regs, InstructionData); + if ((ExitInfo1 & IOIO_TYPE_IN) !=3D 0) { + if (!GhcbIsRegValid (Ghcb, GhcbRax)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + CopyMem (&Regs->Rax, &Ghcb->SaveArea.Rax, IOIO_DATA_BYTES (ExitInfo1= )); } - CopyMem (&Regs->Rax, &Ghcb->SaveArea.Rax, IOIO_DATA_BYTES (ExitInfo1)); } =20 return 0; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62517): https://edk2.groups.io/g/devel/message/62517 Mute This Topic: https://groups.io/mt/75499827/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62518+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62518+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594737111230677.7243491619988; Tue, 14 Jul 2020 07:31:51 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id zNUSYY1788612xjL5JKovzOm; Tue, 14 Jul 2020 07:31:50 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.47]) by mx.groups.io with SMTP id smtpd.web11.21093.1594737110379995715 for ; Tue, 14 Jul 2020 07:31:50 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RCcj0COhVneXc8ut1UDl8EuFIIlBehUjkIqss7FB3xuOClSVKc/Neikb8isk5uwlCRRZlFIHWNGfbkNi6tvUXU/1ccxFAXkJKmwjV99skmb4tfllU8n84EpK8BUOdvkDHaqstq/l4IQGvNuk8QEvVfyg+FOwXkRpI5d5+Xh0W246X1S4r1OqRWcvoqQ6h/YagErh9M7LwaV5NZpIFmBi0gjfisY2moZA0U41VufIs9b1zMIyi4ChCZ48ZtflDfH3K303UGna/79GrsbYQzJiuM1AAou1YHDtODVuqMIsJpboe2D1gY6WrOTNWgpp/wZQq5cys6LK5LvyCgczSr7UFA== 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=DefcxGXcet0YpbciDB6cqSIPAFoRtyFhEUPqxpHT3rE=; b=D0mwmt8Oy8745ByHzLQQsqUQ8WdK6zejbjR1XgYHHuPhWuwdu2SV5A/sVqj2VZLmtWgn+fIry6Ifv82C2XYXluQGHQNkVp0fu9M+gl5jdfxSUyg4xo8dOjLjVSt42erbPfNrJW3wCrZbQVGBTp8TFGpH78lN9kEThu3uphPz7UR2lpe8RSxyLxeP+g67VzS4IcfE7576FtJlPB8VO97caG27t65s/tlxKKvXEsQ4cWiRbCFv/glKGA+agwaR3x8odPKfY+EfKlJADAfJarA2/IBxrGqgFNbVaQXE7e9bp48Um/YSWiG0aCtMqIeyaDQhLpVArC1K0AV9RtW5wE7byA== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:31:48 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:31:48 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 15/46] OvmfPkg/VmgExitLib: Add support for CPUID NAE events Date: Tue, 14 Jul 2020 09:27:46 -0500 Message-ID: <6d0f22b47916200abf1690f87ff926f1ebcd5623.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN6PR01CA0030.prod.exchangelabs.com (2603:10b6:805:b6::43) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR01CA0030.prod.exchangelabs.com (2603:10b6:805:b6::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22 via Frontend Transport; Tue, 14 Jul 2020 14:31:47 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 31545f1f-c194-4755-0b20-08d82802a447 X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: PIEccOTly4iQzZ2Sp9q9ybxuk9rUlN2gVYy9cRkt+/xjhNoG9YRSVmCA1M6o5aXhZ6/c5eV8Zo2cYCmOLTwTXb2bNvzWEazEabAJN8wcCNNb53sDueN7OcmozBAUISHPoEDel2Z+KInQ0LwB5AWea5q9vy8K3b9DiHqVMNwwS+nMHMhzmju2y2VmEA/ZKJbv8nhNVHuG2q5/CT74j9iQBkdILC1JipJr8ugpcuwBi649M+4EeyZqm02ABb0sdC8q4HN3NVCk1n33NUoiCczET2wHbNNAsQM6azKlQA1FSDs3zoqgZUdGVEGZwIgpHr3tbesNDcHhEcyGBpsnhou3FzettJNLDLv+Piwp7zdUc1ufpwTccV97MpcCOOD565R+7KJxwWZV+7PexTYgWwHMD6LBt6iZoCSiOq3KieSWq+jeR/M11wDaKt659bYKx5tU5e9lkhveix3fFVDRumkksQ== X-MS-Exchange-AntiSpam-MessageData: ZCdDXvIU3y/uiXTzn4WZeF+pYUPmJWw7zzQQIPj2uRGOWZzmaAef26nEonxRKxnRIl0/Q1/cK7Jecpon90lKowIQXNKb10dj50MNybGYPY1uSk0uQnSeOsbTaHa45QOvSWz7+Mq+g4deeMyFHJqKWSLInO9EvYf6ED8ufBCFFNQljl9BHQ4yTgbYnehilRIZIVb7w5AuQZO1hjQBd5N2vMwXdNcNP27KwEitcJvlcjdRa+d4nDqRP7K0M/BNA+zttWM1vfp+WYyip7VDu8FbvYD79pHMIY0iO2+9qjbxoYROhfeQZSU0wGofBuUbt3s0bdMPRSaDGrz0hV3eIQdau7tR+Incl4rMcVXe2Z7/qEXqjuwTb1/b1MaAajyBrbK3hyFHK3M+i/FsV6F88VZNHL0sqBx2f9LuwZRHWAenJUsHt02DN00Z3wAAcuAiCtYip6OS5YSVYXsD9lGCdUFZhv4fkykuC37f4E/iC9a8efg= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 31545f1f-c194-4755-0b20-08d82802a447 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:31:48.6948 (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: I4aza2lB2TeabVHe6Qz9N/1ZIW//bvLmXPKYPI2Guy+pmaGZTZ2+74jRzBNWD+LMojP6BB0Iw7UXVnFi6Dk3Tg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: ZvTLAN8XAgJ6gMUtwSQVydH4x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737110; bh=FAgQcGRkZkkfkCs0r0fwXvOzbrTvSlEYuqrQ6904QGM=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=CMEIM4fXbSZuYPiOe8F1/qgozAS8wQqlscOIG8VzfrcD6dGkSXL6zoTbFtOEfK8PFcz tvqBResNqJ8krebrDTlTiWspgTA9Iewbzt7DIW8sFL8sQb7kwSDdP6qj0g5cmzI/pWdym ow4cTgY8tw+zsl71ZZ9odMpLtdQ0dmv5k+w= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a CPUID intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Add support to construct the required GHCB values to support a CPUID NAE event. Additionally, CPUID 0x0000_000d (CPUID_EXTENDED_STATE) requires XCR0 to be supplied in the GHCB, so add support to issue the XGETBV instruction. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index b6ac3552894f..1c9c272a250e 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -11,6 +11,7 @@ #include #include #include +#include #include =20 // @@ -597,6 +598,61 @@ IoioExit ( return 0; } =20 +/** + Handle a CPUID event. + + Use the VMGEXIT instruction to handle a CPUID event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +CpuidExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + Ghcb->SaveArea.Rax =3D Regs->Rax; + GhcbSetRegValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Rcx =3D Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + if (Regs->Rax =3D=3D CPUID_EXTENDED_STATE) { + IA32_CR4 Cr4; + + Cr4.UintN =3D AsmReadCr4 (); + Ghcb->SaveArea.XCr0 =3D (Cr4.Bits.OSXSAVE =3D=3D 1) ? AsmXGetBv (0) : = 1; + GhcbSetRegValid (Ghcb, GhcbXCr0); + } + + Status =3D VmgExit (Ghcb, SVM_EXIT_CPUID, 0, 0); + if (Status !=3D 0) { + return Status; + } + + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRbx) || + !GhcbIsRegValid (Ghcb, GhcbRcx) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; + Regs->Rbx =3D Ghcb->SaveArea.Rbx; + Regs->Rcx =3D Ghcb->SaveArea.Rcx; + Regs->Rdx =3D Ghcb->SaveArea.Rdx; + + return 0; +} + /** Handle a #VC exception. =20 @@ -641,6 +697,10 @@ VmgExitHandleVc ( =20 ExitCode =3D Regs->ExceptionData; switch (ExitCode) { + case SVM_EXIT_CPUID: + NaeExit =3D CpuidExit; + break; + case SVM_EXIT_IOIO_PROT: NaeExit =3D IoioExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62518): https://edk2.groups.io/g/devel/message/62518 Mute This Topic: https://groups.io/mt/75499834/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62519+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62519+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594737123945892.9772036586467; Tue, 14 Jul 2020 07:32:03 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ifNAYY1788612xezYit5IbCo; Tue, 14 Jul 2020 07:32:03 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.69]) by mx.groups.io with SMTP id smtpd.web11.21098.1594737122996080576 for ; Tue, 14 Jul 2020 07:32:03 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Sa7DIyNlfiPRDX8hm07nuXP90QqoXazKEMueMRZAWAA6cEg1Ng48hhsC+GThGw8DKWZWZYPbjOgXmjYM48YHCj8yQBCKNn/6HN7esvqLSCperUSH2RiUQ2la9gjQ/ut9El+oucRroByNF64eEab1OuUfT/cgvSIIAGaTnpQb+t1OxLAefN1TBfKgNEAstvaV4UBCT+ld4m0RzmrH/jb8291aTAOqPGMAsT98o3cxZmChAZSvLs3r2PF7+0hZcfhEHNPiG22EqWZKtrBhpWcJQn1URerOOfTcxedsYhxzliOI19NZnIk4IT90fFDYb+sm2kNT0plhKyt7rlcqvW0aNw== 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=z7KM/QY3QdiNzO0sLsMAJB/dGUXDqeKlzSZHqwBk/3M=; b=eBmR9KB6lqv/SoSydfYkNABhlv1MkFrfLyI/DHC1ZtMTiXkIAa4ScuL15968WYT6he8ma4A2/z+mAeQ1XbpGyy4BEPjDANbhDhdWjtZpzrg4E2WUjz9sjis80UnzGVMP7/KZynUtWJUDTL6yIYhRZcC2z73DMWY1sORt8EkzVNcLLezywMFrgxccAVGz3wmWPYbkQNl7k3S/T4NP6ux8ybFavKiYz4R4wJZ+8ENNwDgV4tGfJHVrA21PTtQ/dWkin6jUM2/3ZZBNLP38dMfQ8fzi5rZrFUTCxeeRn/JvLhC/gYq0dU5bV/d/y7UgxOd9ztVZSTvIl+SaWtVLIveXFA== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:32:00 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:32:00 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 16/46] OvmfPkg/VmgExitLib: Add support for MSR_PROT NAE events Date: Tue, 14 Jul 2020 09:27:47 -0500 Message-ID: <3daa8d5e420de73e5d63a71d79910523abcf0f5b.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0027.namprd21.prod.outlook.com (2603:10b6:805:106::37) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR2101CA0027.namprd21.prod.outlook.com (2603:10b6:805:106::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.7 via Frontend Transport; Tue, 14 Jul 2020 14:31:59 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 25260f7f-2253-40a0-d120-08d82802ab80 X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: iR7tDdObiE/ZBLX83PBYfkkfqBGqFBmANEO0XuIdM2gjrwvvbGDjk9bhu7mVd/6xRVirzGJ1qkegAtdM4eJOfcotHDrHcoHwqY+OG1s8ojHYC42jwbtzHwmGpgpgDBWvTgE8WONHuByadPRILLpfONGHYyWKA8GPQ/HIBVdFtaaideUVziV31FM1AEmPSu6XZLdiSQGZPbZLcM+8FzCa8rEpTOqDmmoU8nWPSFu8gcDDhQrYs3f29OezqzhvMASGw4j9x6dpYaAupAhGkpC+qH0/14gZQA2JIRNdnvR7d1ZQXPBGdKDeakH9QN6P1vY1VW87HHlB+P1Jds+7lHTfa0VLlWaR+SdlCm5z1p/VU4l5uAiJWc0tbDUeDelH9M+FkwdTpv4f2KanLIoVrsIsteB78gqzqBDx816rAqUQqVrOPnFnHghXrcb85B1irsBuLdnXjbzhIXi90thmMBJD3Q== X-MS-Exchange-AntiSpam-MessageData: 7PCWe/C5xV//qZi6qXJzWveYZsiLM8mGWfaGGVqAQimmJnGgfcjw4Nbp+zziuagv8r60sDyiRKBq2m5EvJyG20LBeuLgHmn7fqiOvmuVjePTjs55g4bvB74q4MqdGpo5NZnWsCrqix4DGA7xfsGCLDgydJZfh58Bz/KXufBOUD+E0vRhZuVYZ5pQrahhoTD4tZRELqmg2tWRlWM+kMtvi3noDOCRmLFV1/LJ9JN/A8DSvMD7gaCdb2JrKK61kxqrXtIR7NYWUagYA8W1+0BelxR13zCaW0u1HFzwSsbHjM2/kHmJgad+F8R7XIbohYAP8RNEQuen73vL0pKqBCuG4OLVQV36g0pHUGdI9WAl/ewzfAu4N/uOOEOyu+Or0y7mMixi8iztHKeEDTryBpvttIvj6T39c79vUgXFoXI2zHRNL6RvUKHvyXK4LsiBLpTnrgTGDtjrRKF7DPK7E98j81Hy9sHfrYeEmxsuK3Ihc+Y= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 25260f7f-2253-40a0-d120-08d82802ab80 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:32:00.7995 (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: UYJ+RpNoAMvWN25Uz1/V3e9GIAf076rwipZOgf1MruUccEU3JqIF0oDmFwqmsEXfA8A8C6h2gCDFVlKzVNSpdg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: j64KJD0CYJNEI4uPpvcA8x6fx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737123; bh=7B6s0vKW1Hwq9OTSyaevM7RWNdQVtcxGwadq0q+f+8g=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=vdGedN4Hbl6j4mAjQW/Ptk2N+iciCDLh92K9ya94n7mOBBpnHIkTTnFNHpSrDJhTIjQ DTEotJj5HakByF5GqK73x8eoCf2C56exsK92xpnAcOEmOPjrVSwJQvT/9TMacreoBJNvM 6yHtChxfEPA1sf6aUOAAxzqVblMKGKYOy+8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a MSR_PROT intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Add support to construct the required GHCB values to support an MSR_PROT NAE event. Parse the instruction that generated the #VC exception to determine whether it is RDMSR or WRMSR, setting the required register register values in the GHCB and creating the proper SW_EXIT_INFO1 value in the GHCB. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index 1c9c272a250e..dbedd4e9f95d 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -374,6 +374,67 @@ UnsupportedExit ( return Status; } =20 +/** + Handle an MSR event. + + Use the VMGEXIT instruction to handle either a RDMSR or WRMSR event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +MsrExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 ExitInfo1, Status; + + ExitInfo1 =3D 0; + + switch (*(InstructionData->OpCodes + 1)) { + case 0x30: // WRMSR + ExitInfo1 =3D 1; + Ghcb->SaveArea.Rax =3D Regs->Rax; + GhcbSetRegValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Rdx =3D Regs->Rdx; + GhcbSetRegValid (Ghcb, GhcbRdx); + // + // fall through + // + case 0x32: // RDMSR + Ghcb->SaveArea.Rcx =3D Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + break; + default: + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + + Status =3D VmgExit (Ghcb, SVM_EXIT_MSR, ExitInfo1, 0); + if (Status !=3D 0) { + return Status; + } + + if (ExitInfo1 =3D=3D 0) { + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; + Regs->Rdx =3D Ghcb->SaveArea.Rdx; + } + + return 0; +} + /** Build the IOIO event information. =20 @@ -705,6 +766,10 @@ VmgExitHandleVc ( NaeExit =3D IoioExit; break; =20 + case SVM_EXIT_MSR: + NaeExit =3D MsrExit; + break; + default: NaeExit =3D UnsupportedExit; } --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62519): https://edk2.groups.io/g/devel/message/62519 Mute This Topic: https://groups.io/mt/75499840/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62520+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62520+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594737135772898.7774541789555; Tue, 14 Jul 2020 07:32:15 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 9jbCYY1788612xSvt2ddcYm0; Tue, 14 Jul 2020 07:32:15 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.53]) by mx.groups.io with SMTP id smtpd.web11.21102.1594737134653047228 for ; Tue, 14 Jul 2020 07:32:14 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=juJaVAGAq829LU9JA+5240WPw/o7act2wjAGcCVaDohsetslAR/AwKfxUvdolsigYMqYg/yURHACXwCWQlYzsqQyMcwM+ClyBc6vNbQMb1QY+B2Gd4+cw0Ngox/7CSbmmUKmtIJeOTjMpKWMl033raTd4Ah3phvpAtS9CNSFAHaMnROZJWN6ObUktqEtiyFcLG2ExllYjwWNHLgzac46UhL4jFlVCvMtSNGAC9SSlHD6DSuLFWxZvDWUthLTqBXGgTWuybLOzJGWp7qwsdBYgN2LkJOeDdhb6Bitzrn76hBhx/xXEEsQFJUZrrHBKueSSNkgbDhJtkggEGwUvocnrg== 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=3fv0LySMv02Eoii4eBNtz7XCoDCF4qBd0ZrJwx44Uo0=; b=cd+M9SR7v6ShZtg9CPkTwF5IvLutK0kI74mNvXvG7EVpIj2KUKf9pdhnlnLxvFqPESltSHlSPcHouE35hYV+4aRGYmG4I2wLMA3pCKOYK6SU4Y2gqvI97WYapa2d2HOiTGxrPM6n+vTdLMXBjhhjaL6VDUYZYcDlQDHMj7bQGTQ+26JR87CNnWdkPdnUGbhVxBZ3CBKwq2O55JQgTe+C0OjURRzxYXLB7fz+7nYXiS7f1WZV+5bREJ+iKluVgsqv3JjiAUujpDaTXso8UtlR/byRUoQhihaK3lJexVZ+ZfLSqHexLDXIGIqMCa/iis3gv9u3Z0niVMUkXHEOy+xG7A== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:32:13 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:32:13 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 17/46] OvmfPkg/VmgExitLib: Add support for NPF NAE events (MMIO) Date: Tue, 14 Jul 2020 09:27:48 -0500 Message-ID: <5d684a30f2d5ab378244521445036e7e2539cfea.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0103.namprd05.prod.outlook.com (2603:10b6:803:42::20) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0501CA0103.namprd05.prod.outlook.com (2603:10b6:803:42::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.9 via Frontend Transport; Tue, 14 Jul 2020 14:32:12 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: f5c792dd-9b37-475e-2168-08d82802b2cc X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 1ViYYqlzTtdtMDy2zQvNGf9DPbMGsnsheWmFA83GBdJf9x9qRrXk2jMhorFEVLxlBt3IzRpKv0aSuUVcIMjalRmDXOQ0bR9rt8lZQz+jMEYDnkmc7xvfK1uRbIjGgd/bsIcBUb65C09WdKz2k0/OJio90CGIvCSifIPYpMZSvZeZh8C1ocr/8Z4ai8Z6CQDox3Er+v1Vt4fDA4KbQr6y/bTEEDIyr6rTxwRpSpAqB71hYgjzy7YJcUAiM+vMpGp+cj3iKVlUtDvx2qKm+a+W/bGbQ4xWqxR7DNXccTW+l/Q2Ew2VCdhKOJpXS/puVd03LZH/9bBdXdhd0CJNPiL9kPzusNBAADrwmLGv43K40f0nSo8eRbDte9BQ58E59NAANwqm3gNvAHYkLwA+4U5WayCzEptTsN01I1U7chmd7oyC6dl3+edxMw/ZlhfKt7w8+WPjZy8Xn8a/oVldn1f1sg== X-MS-Exchange-AntiSpam-MessageData: nNhc7sBgh1dTETaX7rL6D75+92PypwrVNPpuPCglvFgOHjoJDEKjjUYwKIR0qet+nqhdYl4N6ZKQx+QfJEtniC/z2/+Qu62zxMZWZ1+mjjpq+fFdjLNKERHvwtaKsbVnIFbcUtTQXez7DoZnWXTQgp+n+ee8vQCMgG0SriyuhwOz8dmpZop4BrjnTGjfh3hAsZpQ1Joam5oroxg4atIpN66dfWH8OzUbeDXcU5vxeZn7xDIFriuNJVvM65KMatwS7PXygM1rpxER0+uwjDejmBYPewpAIR5qDmwVUjKLs+PG0UcNxR7Hp56PsY/jSan484snKfSk1LVPU+07VcOa6q4qS2Q+iuLhsmhYoHMhA4nRbfffVHt0l2O7hs8sNTa60wyHiy1Kl5co8aEn9toVf/auCCypv/6v2oSdN3o7I2AqNHd/maZC0zJU3TL/r9x1IxhcVBzWFWwEnAlESyzn/Uw0VGddjyHnqik58WQxq6M= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: f5c792dd-9b37-475e-2168-08d82802b2cc X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:32:13.0441 (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: H44/uCvlKDxJQfHwY59sX1hxuwhsQ8Cvya8kL/EUVo/MNSX9j1M+N7a+Z3kvIX1tTVzC6cEbsjyyFJHJTTfDcA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: HLZY5d0ZNNh7lILdgPegJb5fx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737135; bh=nAeXIg3/Zm11g0ESFJ8cBtWmN7tXVPqUiVlX83nkN0U=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=rx2NORPA0yqYryXPDxrs0x45EIDp/tNuhnri5TJ356MaIEYn+u12hiaTimvLuwcPwye B1tQAytnDHHE0qeEFJGS3KAosSt9cuvKff2IXMbCQcCA0MOvVBrjXomvuP6PuFwm4M5Di /m/WvVKQB56YiUIGMWD4H8jsLzwqqpZ3w7I= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a NPF intercept for an NPT entry with a reserved bit set generates a #VC exception. This condition is assumed to be an MMIO access. VMGEXIT must be used to allow the hypervisor to handle this intercept. Add support to construct the required GHCB values to support a NPF NAE event for MMIO. Parse the instruction that generated the #VC exception, setting the required register values in the GHCB and creating the proper SW_EXIT_INFO1, SW_EXITINFO2 and SW_SCRATCH values in the GHCB. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 486 ++++++++++++++++++ 1 file changed, 486 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index dbedd4e9f95d..0e502ac14819 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -183,6 +183,281 @@ GhcbSetRegValid ( Ghcb->SaveArea.ValidBitmap[RegIndex] |=3D (1 << RegBit); } =20 +/** + Return a pointer to the contents of the specified register. + + Based upon the input register, return a pointer to the registers contents + in the x86 processor context. + + @param[in] Regs x64 processor context + @param[in] Register Register to obtain pointer for + + @return Pointer to the contents of the requested register + +**/ +STATIC +UINT64 * +GetRegisterPointer ( + IN EFI_SYSTEM_CONTEXT_X64 *Regs, + IN UINT8 Register + ) +{ + UINT64 *Reg; + + switch (Register) { + case 0: + Reg =3D &Regs->Rax; + break; + case 1: + Reg =3D &Regs->Rcx; + break; + case 2: + Reg =3D &Regs->Rdx; + break; + case 3: + Reg =3D &Regs->Rbx; + break; + case 4: + Reg =3D &Regs->Rsp; + break; + case 5: + Reg =3D &Regs->Rbp; + break; + case 6: + Reg =3D &Regs->Rsi; + break; + case 7: + Reg =3D &Regs->Rdi; + break; + case 8: + Reg =3D &Regs->R8; + break; + case 9: + Reg =3D &Regs->R9; + break; + case 10: + Reg =3D &Regs->R10; + break; + case 11: + Reg =3D &Regs->R11; + break; + case 12: + Reg =3D &Regs->R12; + break; + case 13: + Reg =3D &Regs->R13; + break; + case 14: + Reg =3D &Regs->R14; + break; + case 15: + Reg =3D &Regs->R15; + break; + default: + Reg =3D NULL; + } + ASSERT (Reg !=3D NULL); + + return Reg; +} + +/** + Update the instruction parsing context for displacement bytes. + + @param[in, out] InstructionData Instruction parsing context + @param[in] Size The instruction displacement size + +**/ +STATIC +VOID +UpdateForDisplacement ( + IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData, + IN UINTN Size + ) +{ + InstructionData->DisplacementSize =3D Size; + InstructionData->Immediate +=3D Size; + InstructionData->End +=3D Size; +} + +/** + Determine if an instruction address if RIP relative. + + Examine the instruction parsing context to determine if the address offs= et + is relative to the instruction pointer. + + @param[in] InstructionData Instruction parsing context + + @retval TRUE Instruction addressing is RIP relative + @retval FALSE Instruction addressing is not RIP relative + +**/ +STATIC +BOOLEAN +IsRipRelative ( + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + SEV_ES_INSTRUCTION_OPCODE_EXT *Ext; + + Ext =3D &InstructionData->Ext; + + return ((InstructionData->Mode =3D=3D LongMode64Bit) && + (Ext->ModRm.Mod =3D=3D 0) && + (Ext->ModRm.Rm =3D=3D 5) && + (InstructionData->SibPresent =3D=3D FALSE)); +} + +/** + Return the effective address of a memory operand. + + Examine the instruction parsing context to obtain the effective memory + address of a memory operand. + + @param[in] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @return The memory operand effective address + +**/ +STATIC +UINT64 +GetEffectiveMemoryAddress ( + IN EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + SEV_ES_INSTRUCTION_OPCODE_EXT *Ext; + UINT64 EffectiveAddress; + + Ext =3D &InstructionData->Ext; + EffectiveAddress =3D 0; + + if (IsRipRelative (InstructionData)) { + // + // RIP-relative displacement is a 32-bit signed value + // + INT32 RipRelative; + + RipRelative =3D *(INT32 *) InstructionData->Displacement; + + UpdateForDisplacement (InstructionData, 4); + + // + // Negative displacement is handled by standard UINT64 wrap-around. + // + return Regs->Rip + (UINT64) RipRelative; + } + + switch (Ext->ModRm.Mod) { + case 1: + UpdateForDisplacement (InstructionData, 1); + EffectiveAddress +=3D (UINT64) (*(INT8 *) (InstructionData->Displaceme= nt)); + break; + case 2: + switch (InstructionData->AddrSize) { + case Size16Bits: + UpdateForDisplacement (InstructionData, 2); + EffectiveAddress +=3D (UINT64) (*(INT16 *) (InstructionData->Displac= ement)); + break; + default: + UpdateForDisplacement (InstructionData, 4); + EffectiveAddress +=3D (UINT64) (*(INT32 *) (InstructionData->Displac= ement)); + break; + } + break; + } + + if (InstructionData->SibPresent) { + INT64 Displacement; + + if (Ext->Sib.Index !=3D 4) { + CopyMem ( + &Displacement, + GetRegisterPointer (Regs, Ext->Sib.Index), + sizeof (Displacement) + ); + Displacement *=3D (INT64)(1 << Ext->Sib.Scale); + + // + // Negative displacement is handled by standard UINT64 wrap-around. + // + EffectiveAddress +=3D (UINT64) Displacement; + } + + if ((Ext->Sib.Base !=3D 5) || Ext->ModRm.Mod) { + EffectiveAddress +=3D *GetRegisterPointer (Regs, Ext->Sib.Base); + } else { + UpdateForDisplacement (InstructionData, 4); + EffectiveAddress +=3D (UINT64) (*(INT32 *) (InstructionData->Displac= ement)); + } + } else { + EffectiveAddress +=3D *GetRegisterPointer (Regs, Ext->ModRm.Rm); + } + + return EffectiveAddress; +} + +/** + Decode a ModRM byte. + + Examine the instruction parsing context to decode a ModRM byte and the S= IB + byte, if present. + + @param[in] Regs x64 processor context + @param[in, out] InstructionData Instruction parsing context + +**/ +STATIC +VOID +DecodeModRm ( + IN EFI_SYSTEM_CONTEXT_X64 *Regs, + IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + SEV_ES_INSTRUCTION_OPCODE_EXT *Ext; + INSTRUCTION_REX_PREFIX *RexPrefix; + INSTRUCTION_MODRM *ModRm; + INSTRUCTION_SIB *Sib; + + RexPrefix =3D &InstructionData->RexPrefix; + Ext =3D &InstructionData->Ext; + ModRm =3D &InstructionData->ModRm; + Sib =3D &InstructionData->Sib; + + InstructionData->ModRmPresent =3D TRUE; + ModRm->Uint8 =3D *(InstructionData->End); + + InstructionData->Displacement++; + InstructionData->Immediate++; + InstructionData->End++; + + Ext->ModRm.Mod =3D ModRm->Bits.Mod; + Ext->ModRm.Reg =3D (RexPrefix->Bits.BitR << 3) | ModRm->Bits.Reg; + Ext->ModRm.Rm =3D (RexPrefix->Bits.BitB << 3) | ModRm->Bits.Rm; + + Ext->RegData =3D *GetRegisterPointer (Regs, Ext->ModRm.Reg); + + if (Ext->ModRm.Mod =3D=3D 3) { + Ext->RmData =3D *GetRegisterPointer (Regs, Ext->ModRm.Rm); + } else { + if (ModRm->Bits.Rm =3D=3D 4) { + InstructionData->SibPresent =3D TRUE; + Sib->Uint8 =3D *(InstructionData->End); + + InstructionData->Displacement++; + InstructionData->Immediate++; + InstructionData->End++; + + Ext->Sib.Scale =3D Sib->Bits.Scale; + Ext->Sib.Index =3D (RexPrefix->Bits.BitX << 3) | Sib->Bits.Index; + Ext->Sib.Base =3D (RexPrefix->Bits.BitB << 3) | Sib->Bits.Base; + } + + Ext->RmData =3D GetEffectiveMemoryAddress (Regs, InstructionData); + } +} + /** Decode instruction prefixes. =20 @@ -374,6 +649,213 @@ UnsupportedExit ( return Status; } =20 +/** + Handle an MMIO event. + + Use the VMGEXIT instruction to handle either an MMIO read or an MMIO wri= te. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in, out] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +MmioExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 ExitInfo1, ExitInfo2, Status; + UINTN Bytes; + UINT64 *Register; + UINT8 OpCode, SignByte; + + Bytes =3D 0; + + OpCode =3D *(InstructionData->OpCodes); + if (OpCode =3D=3D TWO_BYTE_OPCODE_ESCAPE) { + OpCode =3D *(InstructionData->OpCodes + 1); + } + + switch (OpCode) { + // + // MMIO write (MOV reg/memX, regX) + // + case 0x88: + Bytes =3D 1; + // + // fall through + // + case 0x89: + DecodeModRm (Regs, InstructionData); + Bytes =3D ((Bytes !=3D 0) ? Bytes : + (InstructionData->DataSize =3D=3D Size16Bits) ? 2 : + (InstructionData->DataSize =3D=3D Size32Bits) ? 4 : + (InstructionData->DataSize =3D=3D Size64Bits) ? 8 : + 0); + + if (InstructionData->Ext.ModRm.Mod =3D=3D 3) { + // + // NPF on two register operands??? + // + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + + ExitInfo1 =3D InstructionData->Ext.RmData; + ExitInfo2 =3D Bytes; + CopyMem (Ghcb->SharedBuffer, &InstructionData->Ext.RegData, Bytes); + + Ghcb->SaveArea.SwScratch =3D (UINT64) Ghcb->SharedBuffer; + Status =3D VmgExit (Ghcb, SVM_EXIT_MMIO_WRITE, ExitInfo1, ExitInfo2); + if (Status !=3D 0) { + return Status; + } + break; + + // + // MMIO write (MOV reg/memX, immX) + // + case 0xC6: + Bytes =3D 1; + // + // fall through + // + case 0xC7: + DecodeModRm (Regs, InstructionData); + Bytes =3D ((Bytes !=3D 0) ? Bytes : + (InstructionData->DataSize =3D=3D Size16Bits) ? 2 : + (InstructionData->DataSize =3D=3D Size32Bits) ? 4 : + 0); + + InstructionData->ImmediateSize =3D Bytes; + InstructionData->End +=3D Bytes; + + ExitInfo1 =3D InstructionData->Ext.RmData; + ExitInfo2 =3D Bytes; + CopyMem (Ghcb->SharedBuffer, InstructionData->Immediate, Bytes); + + Ghcb->SaveArea.SwScratch =3D (UINT64) Ghcb->SharedBuffer; + Status =3D VmgExit (Ghcb, SVM_EXIT_MMIO_WRITE, ExitInfo1, ExitInfo2); + if (Status !=3D 0) { + return Status; + } + break; + + // + // MMIO read (MOV regX, reg/memX) + // + case 0x8A: + Bytes =3D 1; + // + // fall through + // + case 0x8B: + DecodeModRm (Regs, InstructionData); + Bytes =3D ((Bytes !=3D 0) ? Bytes : + (InstructionData->DataSize =3D=3D Size16Bits) ? 2 : + (InstructionData->DataSize =3D=3D Size32Bits) ? 4 : + (InstructionData->DataSize =3D=3D Size64Bits) ? 8 : + 0); + if (InstructionData->Ext.ModRm.Mod =3D=3D 3) { + // + // NPF on two register operands??? + // + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + + ExitInfo1 =3D InstructionData->Ext.RmData; + ExitInfo2 =3D Bytes; + + Ghcb->SaveArea.SwScratch =3D (UINT64) Ghcb->SharedBuffer; + Status =3D VmgExit (Ghcb, SVM_EXIT_MMIO_READ, ExitInfo1, ExitInfo2); + if (Status !=3D 0) { + return Status; + } + + Register =3D GetRegisterPointer (Regs, InstructionData->Ext.ModRm.Reg); + if (Bytes =3D=3D 4) { + // + // Zero-extend for 32-bit operation + // + *Register =3D 0; + } + CopyMem (Register, Ghcb->SharedBuffer, Bytes); + break; + + // + // MMIO read w/ zero-extension ((MOVZX regX, reg/memX) + // + case 0xB6: + Bytes =3D 1; + // + // fall through + // + case 0xB7: + Bytes =3D (Bytes !=3D 0) ? Bytes : 2; + + ExitInfo1 =3D InstructionData->Ext.RmData; + ExitInfo2 =3D Bytes; + + Ghcb->SaveArea.SwScratch =3D (UINT64) Ghcb->SharedBuffer; + Status =3D VmgExit (Ghcb, SVM_EXIT_MMIO_READ, ExitInfo1, ExitInfo2); + if (Status !=3D 0) { + return Status; + } + + Register =3D GetRegisterPointer (Regs, InstructionData->Ext.ModRm.Reg); + SetMem (Register, InstructionData->DataSize, 0); + CopyMem (Register, Ghcb->SharedBuffer, Bytes); + break; + + // + // MMIO read w/ sign-extension (MOVSX regX, reg/memX) + // + case 0xBE: + Bytes =3D 1; + // + // fall through + // + case 0xBF: + Bytes =3D (Bytes !=3D 0) ? Bytes : 2; + + ExitInfo1 =3D InstructionData->Ext.RmData; + ExitInfo2 =3D Bytes; + + Ghcb->SaveArea.SwScratch =3D (UINT64) Ghcb->SharedBuffer; + Status =3D VmgExit (Ghcb, SVM_EXIT_MMIO_READ, ExitInfo1, ExitInfo2); + if (Status !=3D 0) { + return Status; + } + + if (Bytes =3D=3D 1) { + UINT8 *Data =3D (UINT8 *) Ghcb->SharedBuffer; + + SignByte =3D ((*Data & BIT7) !=3D 0) ? 0xFF : 0x00; + } else { + UINT16 *Data =3D (UINT16 *) Ghcb->SharedBuffer; + + SignByte =3D ((*Data & BIT15) !=3D 0) ? 0xFF : 0x00; + } + + Register =3D GetRegisterPointer (Regs, InstructionData->Ext.ModRm.Reg); + SetMem (Register, InstructionData->DataSize, SignByte); + CopyMem (Register, Ghcb->SharedBuffer, Bytes); + break; + + default: + Status =3D GP_EXCEPTION; + ASSERT (FALSE); + } + + return Status; +} + /** Handle an MSR event. =20 @@ -770,6 +1252,10 @@ VmgExitHandleVc ( NaeExit =3D MsrExit; break; =20 + case SVM_EXIT_NPF: + NaeExit =3D MmioExit; + break; + default: NaeExit =3D UnsupportedExit; } --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62520): https://edk2.groups.io/g/devel/message/62520 Mute This Topic: https://groups.io/mt/75499843/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62521+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62521+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594737148620826.8169616869462; Tue, 14 Jul 2020 07:32:28 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 4JTdYY1788612xF0TvajL6Ky; Tue, 14 Jul 2020 07:32:27 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.65]) by mx.groups.io with SMTP id smtpd.web11.21105.1594737146786174466 for ; Tue, 14 Jul 2020 07:32:26 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fEjEeR9FK8AJJP5QJuUnYkSPLnE0mbDp54s2iorzkcBnPRgEwq/w0mLc2k5yWzPZYYB/iHfKBwYL/GJzXjdau1XfxowWvaMFj5Icvuv3b5xhyrpMUpNVODniRiQKpi3tBSCwsWNY2LiqSP8G0OrCe7gIF37jW1MrUzNjhThmX/dFzx9nEUM7IcuWhWDQIRk3nQMoaG16SOTq9yJ77BC4iLguzHZ88Smgm7OZXva2yD0JFs0o2H/YPDpTE+1pSvLcctLBxjLknj5lwN/BUB5IRoiIA7DS8YZUrKTOTgZaLfY3SMF6W+0kJkr4mW4Y9skka9nJ/cLvOEKUfGKwtOO8Cg== 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=crbmyZ65afRC34Vt1/yjGXXSEbQgatvY+leMn0es1AI=; b=j/I5pi7FrD44MCVqVtJBZVCRtR5yIwuIGmg8Bx9u2b5gDCl8O1HbZ5zu73fdMd0VeqWmQcOWgah/rfBFpP5ePpI0YzLJITA+bXqCmmfODcTZfsFt6qsGauLqH+YbvRbN5PhcCCVS70KLsbEiYMGPU8sPO3iTwN7Yydc/7CefspXike9EWkjJGjaNW3GlkyILOR49iI1PPdht9MWBDzOkdNCnRh9osaZl/IZ6Z2i8/ix+YrS6Yxsif3S/m7m+owWSk7B6JjcO1uvwktb3xxebFRjMmJmw55Z8FHfWY3MRMLTdOumnsubDsOBPEbpKCbWhLPtY86Bp/pfejdFES86Mlw== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:32:25 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:32:25 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 18/46] OvmfPkg/VmgExitLib: Add support for WBINVD NAE events Date: Tue, 14 Jul 2020 09:27:49 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR2001CA0012.namprd20.prod.outlook.com (2603:10b6:4:16::22) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR2001CA0012.namprd20.prod.outlook.com (2603:10b6:4:16::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17 via Frontend Transport; Tue, 14 Jul 2020 14:32:24 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 83643a29-6b3d-43bd-829b-08d82802ba21 X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: Il0+yUJJeQvHOuku384pu6QjjOhDosbw+RrdVqfHDAmRqvGkTGT5nHKy8txpcPi5bmbviFQV74v02h3+sVbG2IUqXML/nlOUQuibtwDoHy++9swiVEAmXqy2tCCGh8kqR9gZu/IvrHPZPbmIbJkem/2sLzWi/5wEpEuPwarRIjI7+94t3wwADe2/7CGGKrMbnP1NSilAIAKkAulOe1nYYy3ECoyC+PpcTx/fpIKuEVh5/CSsCQWmX36YDq9Z1JChlrxPNKG+GPMOartGadP+8rmAFINoQ2ifxUTsipvWc1W0wI5MnvOVgJNcAfI66b9afQ2nM130jUuzPVueDAr+xRsld+NEhoiTfvO3KHqomaFjOJk1D4Qym+DUZ1pQUECteezMKUu7aHmUfEPkmS5tjzL53xBsyq5bwZvuojg7RavOIbJJPXQ3Vntk/wM97eoDyqLu6LaEnyUo3VeVXIJ5cw== X-MS-Exchange-AntiSpam-MessageData: CyUuUnROCY1rF7X51n6L2fcm+/EuldIVDHE88Vo+2fWetP44Cg73g+/Z4Gq6zN5AfSXd/D2Y4y7SJFDVsyPQbHmVQCV3PxL+sVyMqt0IvY61ojPgJ/eIns4NVmbbwsN+7JgzEvWqKQb2Yoqmbxb3FjR2+2x2u9lT1EHYEgvpr9Me4nLVWzqt0UPoP6/uHyUHEn7xKS0hgP4zR46Qruzgzbls3fBgKQW/eFG1AHVxLv9oEA98knY014qskPMZD6Hxb7O+qmiUNHk8BDrOmr/j6kqfm8u01CbZcZ5j32f5HOFqL9R7ELE0V/T5/bwVk9Jk30lE05KejMAHA6UqW9NNK1C1QC0kTZySH97pylAR1K+404mcgcx7tzxyg78M+hohKul0c5pK51DWWMe8vM0wiNvU3dxc5Jat1Nqk0indOun3mZbK6Bl18S1E92BnovfXLrzhsNpvHSMFXnInAh9pMQoeN1W3CoS/FhL7qYmPmhA= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 83643a29-6b3d-43bd-829b-08d82802ba21 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:32:25.3078 (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: xCuH91VnvuwP1u3kmSTrr5JPN4H1/bxL7i8qJXx4sxVc90eh2ut5F7PxHSpgIfnXyUzsAiZ4mFNxlQjVTPFcBw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: 1VJ9s9bxhqvxvqRQcQllrEL9x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737147; bh=VRVcoab8/a9JflTz64/d0qKrwdQO0xyfEUtiunxY5Kg=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=cjG4BRmOJ5r//qu3uXmIbW0gq7Yu53GJavyUzCuAo7Jz/RUKSnYmYBaZMJY1TsvLxjQ 15/hqiHTkMmTI2X/5Sw6sDLGlp07Ap+6PYOQAGiotHZ69vu1TbPC4qc0UwNYuOtJw023+ VUBBJxV+DY9fwROvfktBGcnoQkWuAoO659s= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a WBINVD intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index 0e502ac14819..bf07f960e380 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -856,6 +856,31 @@ MmioExit ( return Status; } =20 +/** + Handle a WBINVD event. + + Use the VMGEXIT instruction to handle a WBINVD event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +WbinvdExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + return VmgExit (Ghcb, SVM_EXIT_WBINVD, 0, 0); +} + /** Handle an MSR event. =20 @@ -1252,6 +1277,10 @@ VmgExitHandleVc ( NaeExit =3D MsrExit; break; =20 + case SVM_EXIT_WBINVD: + NaeExit =3D WbinvdExit; + break; + case SVM_EXIT_NPF: NaeExit =3D MmioExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62521): https://edk2.groups.io/g/devel/message/62521 Mute This Topic: https://groups.io/mt/75499846/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62522+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62522+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594737161372262.8074967259038; Tue, 14 Jul 2020 07:32:41 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id dVlcYY1788612xDP6Gif8K3F; Tue, 14 Jul 2020 07:32:40 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.72]) by mx.groups.io with SMTP id smtpd.web11.21114.1594737158438570483 for ; Tue, 14 Jul 2020 07:32:38 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mGZS0gk0L7kQ/z3Eo5YfLiAYbIQUQKoWS6P3nB6f88bb11gg5J5R/yNpwNl09hTm5qwm7Ak1/KLvFtiPztR0HiIpj1goSM2rh+X30dgjQPjVswf08FbdOZ1ZWKIez9sj6oHcN0BNsuBHWvGJmv2vaT3k5ZteY07QvSqv+Q4bCKLAOGdTuW23Hp7rNjHacz2X2BTpvp6QR1+Li2HfcmK4SnCGeXAOqtG+zQj0Q1b4+U7HW1/LF3+WjlY1c8Z0GiHk0KURrSh7HpWi16ktU1bS5GkwbkppWtCxRRB/ltnrGx8ssHzljesT7CuVwDJnt1HsbjbrNl6EBJKp2+XojGMcig== 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=d00K2p9wGq3eOi/6hoKeg0U80JcDhc9VJVDfMfmKMog=; b=AyfSvExDBut3kwLvFUjhgUfL0CeFVsTH89f/XvmpZnGH6bQ1cxXoNkNa/wdsVbRZ7poNqQkveI45jUXDjLFDmsY3+hFykwCoyayV3E2rqSn5YYtqStJEEQgkT9U2wiTPuqSmne7ZQkcEjEy6IwDoHgC3YOiwA11WqoNB5sdsI3aNpmsk9OK3oQ/cL8zhuSMBRVN6OnkkcAma5m6ImM2vtxXmcnMT6Tar1/4zgPXJCBSzGc8x6g5YcfO3Xd6dWeOBdY64jIcpVteeoMwg/X/16YN3PHJ/PAAFY3M20P+nEtdeRRtfnTqG0nR8vmi/l17fvrMShtf3jA40jfb16R9YNQ== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:32:37 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:32:37 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 19/46] OvmfPkg/VmgExitLib: Add support for RDTSC NAE events Date: Tue, 14 Jul 2020 09:27:50 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR07CA0104.namprd07.prod.outlook.com (2603:10b6:4:ae::33) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR07CA0104.namprd07.prod.outlook.com (2603:10b6:4:ae::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22 via Frontend Transport; Tue, 14 Jul 2020 14:32:36 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 558cd2f9-3554-45c4-afff-08d82802c0f7 X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: LnQyDhjiz2KLzJxja7cCO201qdfGS7VOdjdFAyNoHnMW9gwGixMEMAd5g9aeHtzMzDyQbKze2l1q6FEvHwqypKiXp/mfJ8Fvsf1OiHdi1rS4vOB7H7myup6A33SIxOaq0vYXXWLMDOGsem7w5KhLmHuWd6reeFt59d2SUzlZNpoS1wVfyOciiZ62DIcIxUOMwn/BV2n0+UmQyVowt8140xpjcq3hTNYyErjegks3VZfjcUnjxwuiI3cJCW2cipQ3JDXRkcUnvH2mx47hjrgBQOhtlbp1SclMbxkF7QsrxAJjHEigZXpSHI8TFXh2BLDNgZEgV4scB+auWJahLn+BNu58Rurfm6PJMMe6u1iiblokPJ7rg+qId9FZiYlqn5TogPEAgm+BdBEx4d8mMd7gjVqZvUaUD+Ybr2bLLv5gGaDFgNJWtUoofvSLMJt62H5pvW4OAdhAXUkIHK1/s36zdA== X-MS-Exchange-AntiSpam-MessageData: OdoAt7XnhRCSydP0Ij+UUF/I8glntMjZrpNzqA3e3f9VTVfEoFEyXvMf2j6R57zYhINtcWdqDY7fztA1G4BkmX+ZwXUH22/B2E9L0jzRy7/Tpluliz/wyXvntTeCJsDJPkiMFQPA2PKAW3sZe4ca9TWG0kSDXxRRzpBXb09rYdXZEmoMAMgl/JbTWKFBVl/wZTnH+x9IAyL1UWFz5cXxpk8Y4py4C2Oh9mYLjs5JebrK4KsaOBjEwe7gNDJ9+7jCgyqz2P/kI0gZPZW854JLxpYfIbrGWS4Ln1WpWqag8fcZMG4QVnqRXrZ6C4BlZCUqhLNJbJdzHVxaYWTlUp0sPMeHpA29N+6s+SMElHw18JkelkL+lDxmzdDai7uMLevq+oUX+M2qK3Zj9P7j04Wk8PhFTRMckx7d/05tZP72241oS6MgGInaBJmdHtgfLBJWbOfh8KjX/ogbd4oATto8G1iIYsC6gRPNaSwvZvk4njo= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 558cd2f9-3554-45c4-afff-08d82802c0f7 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:32:36.9007 (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: PNFFMt/c+/vzYFNhzYNmo2hkJLRXutw7FOHl5SMyBinl214nent8sdOVxM5q9n6UGfZtk5FFsUWwTfKcxR8C7g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: tRy0Sc7Vkz0jfYrMwN7Xnrv9x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737160; bh=r5cCo+K2qrTHH88QRLRWwSXT41fHSLl+wpyqJYh+hqk=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=G7Bihdhfakl1gaco/P5Q5qAHUgXlG1HUdFoSWhn/FFa4QItvRXtJteXDk6ozP2OTBwF Xo4Q70FBnnSpbjQROulVB9C4ubeR6NvJRljC16HMAjOZZ6xpVODwsEG8JnYgkO7olcjey 3j21lo2vOjo75DKinZPrnJNsn67m3uZMlPo= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a RDTSC intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index bf07f960e380..65af57046063 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -1221,6 +1221,45 @@ CpuidExit ( return 0; } =20 +/** + Handle a RDTSC event. + + Use the VMGEXIT instruction to handle a RDTSC event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +RdtscExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + Status =3D VmgExit (Ghcb, SVM_EXIT_RDTSC, 0, 0); + if (Status !=3D 0) { + return Status; + } + + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; + Regs->Rdx =3D Ghcb->SaveArea.Rdx; + + return 0; +} + /** Handle a #VC exception. =20 @@ -1265,6 +1304,10 @@ VmgExitHandleVc ( =20 ExitCode =3D Regs->ExceptionData; switch (ExitCode) { + case SVM_EXIT_RDTSC: + NaeExit =3D RdtscExit; + break; + case SVM_EXIT_CPUID: NaeExit =3D CpuidExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62522): https://edk2.groups.io/g/devel/message/62522 Mute This Topic: https://groups.io/mt/75499861/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62523+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62523+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 159473717131358.4396789761056; Tue, 14 Jul 2020 07:32:51 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id o3hDYY1788612x2iLIDJZLha; Tue, 14 Jul 2020 07:32:50 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.57]) by mx.groups.io with SMTP id smtpd.web11.21122.1594737170371274409 for ; Tue, 14 Jul 2020 07:32:50 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Vrdp5aowtOLu9vhE8pBl8c+DRz3s7UjLP+bhGvNxGSYtPrrb8aZlRJV5OYRl14r6LLPJewp0092i1hdYjmFqAHjJXb/4TzQ2hku0uG/yev4qwzYbIomeonEh1sdbmGF+Peq4YA42w09wo68BCO1jUceyrl2bckg99kOz3Vx0j54DXS+0iUAPONoToopr7IdrUgZoUwgTZQhvvLb/VU5LjA1bgEIt2Ims0bbMtZRJCnXg4hwu3Fb8TyaoIukr7RnVM8pF8OO3vlDCI7i87vehhW+2HUCxAI/FAyvJ+OGxg3Es9uuyJQmLu3Dpy5hRQMTC1gOySJSrIvrKKyku3pLDcw== 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=4O6+S0hN1CMnpBWLQIazWEUnN+r5+tUBAtS8g+NsqAw=; b=YDrRg1u/JTywx9134oK2vE9+CS2u6YIvUYIy+ZNn2o8qvCUvdYe6vF+SRSpo+aOxsWWPCs2m/8rm/kMDrlN8fYm7V+YXcpwYud+H/3y4xbJnCDLxlj0pwaoscHk70wMeE2y2j9dNwpiCPoJsqecaYHNdGNYQH3BDBBsOo/2MVPUI0T0MYA4VrqVNia5z+A4bVwoOk2Mx4+4PxRK3e0lnvj0K2ClYM7d0kS5wUvpfrAtR/tPWzw1HD1Ie+axNCHyho2jQTQbaiSe7R+69HYS2+VxlfhEMrLbRbfQiIQrcdpEsJDhlmdrDT7HqjMGUhebF7RyaDYJxizTiLGGihfqUYQ== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:32:49 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:32:49 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 20/46] OvmfPkg/VmgExitLib: Add support for RDPMC NAE events Date: Tue, 14 Jul 2020 09:27:51 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR15CA0057.namprd15.prod.outlook.com (2603:10b6:3:ae::19) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR15CA0057.namprd15.prod.outlook.com (2603:10b6:3:ae::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22 via Frontend Transport; Tue, 14 Jul 2020 14:32:48 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: be0414c9-435d-4835-2c4e-08d82802c82f X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: SKqPM/tuRtTNFtZ0UiFFMDtyVoF/ElVHbqEo+ZAP9Aun4q2MB7wAkPMxBBqi2/Hy2DcM+xV8jU9A9A8Fb/fldHhatctt5Ia/DCwODoCLRdXO6HaZlCpkN67NFdnH9jQCoD3+W3ViM4yoQDlNgTVipB8StojI9kNQCEuwqtF57qe0qLmewJDvcN5/KTAcktSo1O4aaSzPhi8h5pI+PArW4ij9YK21XLEEMFknk3Uz73sOHlh+6pMvmWSZMzLrUoTSkN6KMAzkZ/jaKS7TXKiZ5PaV+S6nlgCRfumQdOuE+PG7T+rvhFIoNaoCRtymcLCcJKwsDA3WZamikai+MO7GLT2s7Ym5dRGQPGMhD9Q/87hB5oYF6++7SgVov3oe1lpx4qty4Mqz9aieqrmfL4xvOAUkOikE9eOaZjtZvdPNA2V++o8jQY1G8hN/TtzAMp3S1nYUsQNxx1RkmTHq7TXfoQ== X-MS-Exchange-AntiSpam-MessageData: KAziSrDzfuPQrQvedYoJkDjx7eDM/QfTwm5cjqcDjwsrHyy4yS3esh7sZ9jZ3xQ7ThaNCyRZSvhUcvYIcQc9XABhL9kioWVoXwokTau0AIZjIAGI7pI3RMzVbOjFVXA4fY9PzZ1E+Bn7tevHfak6ztg1FVrhsT2ZglxBL/sDuvSZOkMGLiXdh75o2qOBovHMkMOovKT6GPh+X2/mZO8JeNY9P1s4S2ZE6b2iCvQPJ/MamU/oiL6Xd7EzmZMPgvll576ALP+bRxR0WWJLOppfo7x+sH5EFRU6b89WyCe6hfy3oAEgkpkSErzeCcxb6nsbs9X3Fz/JjrEMtPVPYCASf5MEuGxwqbZkJDEUZME3LEZtAbPMLoYeC/i3IDfxjwK52eqDAECEsy2MFVJD7US/SGCfiBRz7GrYNIwjgEP0/gHSoCtu3pnf3TFz5Q6JaAQjPhTc+e0PBDNg3ndQOHIowvXrQJ4DIQRemm9drO1qQys= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: be0414c9-435d-4835-2c4e-08d82802c82f X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:32:49.0773 (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: RBZJ2ej5NevAOC9GKUu0stSiOWqKqkkSOEgZ7seKj3M+xWTcJe+4eQMj545wx78ZnjFpmNVYq8N608+MBYWcuw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: QoZr7GM1hQZi0Ze6OhAR1rXbx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737170; bh=qJNF+hTvks5HmZlHUrHrRxts2MOiUkJe25VY33S7RCQ=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=o2vVafx6sD4Mgq9BO+X/8ba9WrEbMZyMUbhZcM7xn5fYxWub1qj+l2BgRgEsWYIbQi2 tcbiJgCkTx9VW1niac+CWbm82zT1kQdLn6QNSfNtWtAlFFQbAXDfVS/gLjT9rKUXkIp2r +havHFqGrA9PJR6+34ceuZDG2ftBK7r7gVk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a RDPMC intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index 65af57046063..b19bd3ee8906 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -1221,6 +1221,48 @@ CpuidExit ( return 0; } =20 +/** + Handle a RDPMC event. + + Use the VMGEXIT instruction to handle a RDPMC event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +RdpmcExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + Ghcb->SaveArea.Rcx =3D Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + + Status =3D VmgExit (Ghcb, SVM_EXIT_RDPMC, 0, 0); + if (Status !=3D 0) { + return Status; + } + + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; + Regs->Rdx =3D Ghcb->SaveArea.Rdx; + + return 0; +} + /** Handle a RDTSC event. =20 @@ -1308,6 +1350,10 @@ VmgExitHandleVc ( NaeExit =3D RdtscExit; break; =20 + case SVM_EXIT_RDPMC: + NaeExit =3D RdpmcExit; + break; + case SVM_EXIT_CPUID: NaeExit =3D CpuidExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62523): https://edk2.groups.io/g/devel/message/62523 Mute This Topic: https://groups.io/mt/75499864/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62524+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62524+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 15947371828294.836625425578177; Tue, 14 Jul 2020 07:33:02 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Re4VYY1788612xjOu1W2utFI; Tue, 14 Jul 2020 07:33:02 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.75]) by mx.groups.io with SMTP id smtpd.web10.21137.1594737182003850058 for ; Tue, 14 Jul 2020 07:33:02 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gwAKJV9okKJ/s4cgWDaRrTU3j884fDHjj9oq4olGEjoTR1+rSCjFja9or69pC28cGC1KCA0ZbI+CaiK7nqBNvcBt+Z1Bb42QAXmxnVbEGIjkSWQ6iW8ZYxQi+yArDlKLyjYXtoyLZn7lEHovz41/ReQDDeDKPLyfhSrtH4b/OvWQzQzn9snvwrJIFmyFnKIfp+KKSGOPZVMKY+8tHLZtRPJAHR+bxdY4HC7I3V+x6pRiOWhML/9JRxwnt8TfdZxZGmwUdo+bJVe3KnR1+xsVfnutva9H9DPpFf5kW8W1OiHbB0dUIzvstuQxo4eMqeC2l+wgKLL+7yZTXcC+3q+mkg== 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=VWf8IlBLc5H2/zm6u8ihdDB1OPHPbvu83zMDyNap3VM=; b=ii/cER8J1TzGPiy9lBlRq+GW9kijPmqm/bvWAoE3XcAKSNYEcUqgu+fZO9H8ooaJP0Xu9HvKpd27+SrLkxbEaWFQ96opVIMPuVDX8cROUZoCTZ4MLzhxnulHx6X9xLSou+gSrRuzSJtw610B2L01JUiGZzgti4oU8kGgDiVPdX13qOrjfCW4G8S4ttkPjl9cqhjJBdsPRmXkZRhjRkeLd3I47WzxazMm32AjtWnXWuNvCsUsW8MpoPvSArs5nb+V0qVbEEZBoWNC6sJ8L0ukTn13xzZhL1qMs3YRxtx5HMpb2FqIMyV0x9VpYr2URgvT5Z00tYcOmlN3obi2lYGBkw== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:33:00 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:33:00 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 21/46] OvmfPkg/VmgExitLib: Add support for INVD NAE events Date: Tue, 14 Jul 2020 09:27:52 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR12CA0058.namprd12.prod.outlook.com (2603:10b6:3:103::20) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR12CA0058.namprd12.prod.outlook.com (2603:10b6:3:103::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22 via Frontend Transport; Tue, 14 Jul 2020 14:32:59 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 84bfefac-001d-44e9-8842-08d82802cf25 X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 7CYykr31WbGvLqBDq/L3iOP/lv6xZuWrLWcDcIwp5eJGnQu9gA3/r9KeUaykAILooXf4TeQ4Z4KkEOoZow9IQCUUcqNPc9dr0hYP1O/B94qqQPxaTmzninGjrtxpqqwa/5TQrmZz0KnbQuCEiCZYc5fjzyTrKTVEu/KnB+vQ8KezCBM3sfDC02EOm6Yfz+04y1Hs090XAZo78FpjxsaUzf+2WJWTF8PcNmulFCKAo9TLpIICmGTBKN2uSAc+evZU+zCgx0lAKCTaZSsRpPtPJVNc5u/QTvNWE1W6qQ7SRzqe9Pf00mSrw/DqSSHRwO6e2ECL0TFB4S6qoQZDpYLXNgzcSE8MHpr2omKmDcQyPq566eKcGvegjmIii4MyLN/utxipKCHXGy2AaOWs6qHX5DSEm+XglKoU7yV2ZVmJKimYuCOAqf8iWQbTMcS8KEG20s0UFi+ZSmeBGw4r7RBEcA== X-MS-Exchange-AntiSpam-MessageData: RflvKV0B1p7H2/XO4oRJarWkqLtJ7f9vUj6Rigukfxg/2BkIHACLJERhm8BhW5hgqLe8HdHD08Xv+AInT8toPn0yjzJL1uioBDikcH93j3zqaR7S3YopSPmRKzExWp7k7Sx1cvrzICCip1DGTF2Jwj2j3KXuGiUX9aoX6at27w5lOYlr9AsI50yODhMVgTH/WvgSfSb1UwpiNkY9nFzr/fI29abnFK0bs9cpPCBxphfs51XrF+xYVk6JgZ8lu4qoe6clLFwT4YXioaSNzXHzHMyIJ8EZ0i7nb3LHQGbg0yyVXcCrYaRb/VVR/5d4olkzmuztFowEpr+UBdnZ9jFhBjuJEcaZxL/RSysWSD+VOUv8e4gAhRCwukDYQRTmZuOuYHEzp+l7SEJH6S/o59FA8W81lgCq2YtUCZOzX3bhZNIosS+wDH2BdzfAcb7DP/Qf9/YbDq3CKvREEes6ihGKQfDcScswQKkyWarnkVbFG6s= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 84bfefac-001d-44e9-8842-08d82802cf25 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:33:00.6262 (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: rH5goYlrpvO4y16JyZ4PpP+xBeYljobPABm+SUHRs5iB+qWd3iQYV5+jweb2l8OFLHh0wfdNGS81KRBZU5iIDw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: Fhevqu7elJG1zP5HABPyYsJGx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737182; bh=dO1VaebMK7bTTbLZIBiUnR7m2QgSBBDNpW0wOG2VtYo=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=RLiFwa4kCXEJFAYpHcwWosuaVzb1MlBvGd47Sk7cIZFKWb0bqsNVxe1F1RyWpX0Dj1/ 7rE3RE86LfHbHCTpuDphqg7/O04qa1U0yhvmO1GJgo4iHlmX4Apk5YuUfbQvAtb0uBhez Tt5rys0CCMoHaazlukY8q5vLPa0I1eZ/1oU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a INVD intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index b19bd3ee8906..af5264095b98 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -1166,6 +1166,31 @@ IoioExit ( return 0; } =20 +/** + Handle a INVD event. + + Use the VMGEXIT instruction to handle a INVD event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +InvdExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + return VmgExit (Ghcb, SVM_EXIT_INVD, 0, 0); +} + /** Handle a CPUID event. =20 @@ -1358,6 +1383,10 @@ VmgExitHandleVc ( NaeExit =3D CpuidExit; break; =20 + case SVM_EXIT_INVD: + NaeExit =3D InvdExit; + break; + case SVM_EXIT_IOIO_PROT: NaeExit =3D IoioExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62524): https://edk2.groups.io/g/devel/message/62524 Mute This Topic: https://groups.io/mt/75499869/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62525+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62525+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 159473719479193.41456301011112; Tue, 14 Jul 2020 07:33:14 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id G1ReYY1788612xNoufIODgTS; Tue, 14 Jul 2020 07:33:14 -0700 X-Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.71]) by mx.groups.io with SMTP id smtpd.web12.20912.1594737193906501283 for ; Tue, 14 Jul 2020 07:33:14 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XN37fRhBEk6Hi1ry/q+uFmqK6gmV3uQtHDyGl9HiQsTavfaWjZcEhM/mBT/tIXGk5GjR43ovM/JD/hkw8Ly/io9x+AwlP+/OEK5swQ0mQk8IpTv2l/N+3TcPu8Sojk1fCDc2HIc+hILLe6FQvR3bL7XzARPaNPYgIyIlriT4emVROMED2HTX4bbAtFs16mGjLYEi7oF0MMzxfscamfniXdFkvanK/4eR0PqAv3btQio86vltLgIP4nojO43Gw8fvywf50E3h+ENOtbzrXl2PtB/EQMz/Nj76RLMIPZgzi7cws/h8ss/3em8sF/kd9+6eciqYGjZXdl1aaQSUlsOuTQ== 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=8NTCnoZUa8l7fJRJjHTmN6rj4HEhSC81uhz1zBZyzhs=; b=NMPb2DyPxj0yOa9+e9VCW5ST3X7DuNsFnWk1h/ymyLGRNfpO9+KGfLZ5hKyQ4UoQI+1IbQl0C5i2eRlXEE4jXTik4aENzxRTxxNXH+RMc+pcWyPkP9wL1+v1Q6D2kZf8U/lNZ9RfyRkfYmQQpkF/aPtLh8QkbIRpiyAkowN7nJWjTdpe2Q+vj2cDdIJn+tWAS0RmUSltZvYXF9aG6lOkGh1+cuZWsTUXYECk9kWQ80Fmlnr7JoXeYMIXwwnmWQ3zvSqFZJUA4omx19POONvLT4tWoNMr5ihTo4Xg5gUs6LJsulHchtPDtnMrzx5H0uxahr7pEPbACaoZFnSIDE01uw== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:33:12 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:33:12 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 22/46] OvmfPkg/VmgExitLib: Add support for VMMCALL NAE events Date: Tue, 14 Jul 2020 09:27:53 -0500 Message-ID: <6101d91ac6c43213197c43e6864fb96d9aa412ac.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR13CA0060.namprd13.prod.outlook.com (2603:10b6:3:117::22) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR13CA0060.namprd13.prod.outlook.com (2603:10b6:3:117::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.10 via Frontend Transport; Tue, 14 Jul 2020 14:33:11 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 59e8d15a-000c-4f38-521f-08d82802d5f3 X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: UAf++jTP2DcPSbA/8DI3ZLBzuZpTx7JyhpTNvZs7mbYFVNEgWjw9fDSOkxNgmQqcwyH+pirY39x7/XI5NCwUEFsiicMghjqcRUTwmiWcU4d8hWgUn2two+LqonbKTCP6oYgpbMizKC6/+oU5D679QkNahZZjUwhieTd6Qk0tmF4lMq84Oc9Cu73O5klAdBCZnWvAbL+r+jMzH/RoVa566ZqfEsGSZ9UdymD0toZFuTO/6I0L9U0IG5blTuvYSV/4NosBe4jaGLj6rl4d9R/fdluF+xLNbWzdJG0l49/2iUM9ixaXOIDU2oDXeqan7ljbBZE8FBSjNoRq78xGQ7vF9yHIvxsbY3ME0P2e6EVBiOJR/5SUhZmCYN+i/0WwqIsn1C9iqSHSDHeCYn0miFHruZ6fG2NU3O+7EUZnGHrVNgSJMHyoMXor4FszY6HfmPsJ0gRYvGEajp1XPm7k7nzrdw== X-MS-Exchange-AntiSpam-MessageData: YlxS9HIogIbQaD4ASOk503Kyqhsmuz1TZPUPpBCcP2jg6Vdj/bcY/JVcdYg20FSZV/x/lzhOlbUoIWp3pfrALhxQQIUtqGer6NMoqZ6+HfTyqpA9XXegE+2D+RJ41s979fPJahIpyRJYwxZnEFLhcM58rWuHnhC5lIwpvToQMPA//Sq4cKE7wMVC0Olkk3HFVFEI+QGwPmUWe9Rt+w0vRQNxv4g/+vKKAADvkDpyA3lejQDRgktyMfko86oe8o6igOqd7P6icD+1Puq8oSGnGga3HydzefVIms3nbJoiU3ETzh1chvObAdzZTES1HrOHEh2ajg6PkxLaWDVMuDD3FBNF7alUnvFUgY3j59Xyu2hhQEFOqQWI0+vSrFkeajzdnDnP/UeaSypu5+p0r1kNH/y/mEbQXQyHvpSGiVLAwRfIIqUfn/pgFtnD2C7ES1s6SxEwBQEHiE5fLkD005Fz3VKzsB45eBMEDNg5Q98w5RU= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 59e8d15a-000c-4f38-521f-08d82802d5f3 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:33:12.0132 (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: izC2661ndM3s0J9loDH180+J+nv8gDRdj3fnRZI0aKQuF8Sywo1G3Iga+8o6gRvT2xhMoi6oj36GS4qzGKarGA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: jAr9vfX3e8e3hYLrIoDFalMZx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737194; bh=p8Pymp0eVK/WIWOb1xhUWc918dO0y9xpXXgPiAGh5lc=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=g6qWu82az3/QmKXkEZI1shGoCa87C0qqZzetb+w4y+MYY2ZLy+0aXxTsUw9VtRv6PSd Ox/ea6lgU7YqYSaAXpbncIJwvxarq62z9l8i4sHanUQuBqHWBUiBnOTdOVjMG23jF9sLP 2MltR2enD47cfXrKeMcxBrcj7gmM86qHHxI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a VMMCALL intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index af5264095b98..54134f37e614 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -881,6 +881,50 @@ WbinvdExit ( return VmgExit (Ghcb, SVM_EXIT_WBINVD, 0, 0); } =20 +/** + Handle a VMMCALL event. + + Use the VMGEXIT instruction to handle a VMMCALL event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +VmmCallExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + DecodeModRm (Regs, InstructionData); + + Ghcb->SaveArea.Rax =3D Regs->Rax; + GhcbSetRegValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Cpl =3D (UINT8) (Regs->Cs & 0x3); + GhcbSetRegValid (Ghcb, GhcbCpl); + + Status =3D VmgExit (Ghcb, SVM_EXIT_VMMCALL, 0, 0); + if (Status !=3D 0) { + return Status; + } + + if (!GhcbIsRegValid (Ghcb, GhcbRax)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; + + return 0; +} + /** Handle an MSR event. =20 @@ -1395,6 +1439,10 @@ VmgExitHandleVc ( NaeExit =3D MsrExit; break; =20 + case SVM_EXIT_VMMCALL: + NaeExit =3D VmmCallExit; + break; + case SVM_EXIT_WBINVD: NaeExit =3D WbinvdExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62525): https://edk2.groups.io/g/devel/message/62525 Mute This Topic: https://groups.io/mt/75499877/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62526+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62526+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594737207722950.2701751801153; Tue, 14 Jul 2020 07:33:27 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id PTfjYY1788612x2YXOJPgM1H; Tue, 14 Jul 2020 07:33:25 -0700 X-Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.67]) by mx.groups.io with SMTP id smtpd.web10.21144.1594737205291627281 for ; Tue, 14 Jul 2020 07:33:25 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Tb+3alFcdbZoQCYwc5Xsfxg1iqIQAG5aAgC6p9H2xt88dbfc5hjAEWXuqmRGCq0N43C7ftIRV27H8xqODTMfxI0OHoOSuIxo5HhpXJrVs2sDTBXunPXLXhydZ6YAetcosuVHLGUrn6HNJttT86QTLMgWFZ1lQh0Avs+BzdKGtlz+ea5/Ack2ZoKb+M1MaO/V0pTIzIvP6u6bU3bwhv20r+34uTRKi2JeYDTWYKzomhruGKvhtl6z0u+rmdVU0Dwpf47SiD9/NgSbfKLVyTxGW4bsEhp9Pistnq8MLXHZnzIFIX1qjvlEdDHsgamgBX6Qox8rNDkKSdKJ3aT8TyuaSQ== 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=5teiAq1eAXmkeZ9hYTs+aZivrTRKKj5B0JXYx2XU70w=; b=oBWDxXnHukjvK49bnXDV3N45PuQd+dm2QdQKmnDGEjzdMu424E4MVus/RzovfhIZHsIpPjY9op7ajkEHTTqjdlGpH2RfrhIPIZSiXZPoIkEWQXkaZatIA8tvAo/uWE4+q6dl/UMRd1MRyeXq7yKqODUotlMrLvWCn/nS4eEqgnvN62rCT01u0YUrw8Gmp3ni70IomnKbxGM/D95/xat4ZtNcIqO6stWZ9zsmDAyEPz1MYDJTXL/rBPV/j/mmxE1xiZv068wbtE/dCwsbglv1ZALP08vDPzIPh5nS3rexLApEtBcZaV3AI/msTf6U5Z152HPyBp2YTGLv2gP6dx5ZYQ== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:33:23 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:33:23 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 23/46] OvmfPkg/VmgExitLib: Add support for RDTSCP NAE events Date: Tue, 14 Jul 2020 09:27:54 -0500 Message-ID: <932ba54006096fe3ccd61279fb290fa2c20db3ca.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM3PR12CA0089.namprd12.prod.outlook.com (2603:10b6:0:57::33) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM3PR12CA0089.namprd12.prod.outlook.com (2603:10b6:0:57::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22 via Frontend Transport; Tue, 14 Jul 2020 14:33:22 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 75c8c924-f384-44ab-e7ff-08d82802dcb6 X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: R+xFOlaXvBEg4dUroJEDKkfbxskygL8xQI7q4kat/lNYEnLAyz1wr6gzEzEegTYX9rZsdXuUun8Jt+s1zVFp3k1Eoq7OgbTQKmfbBzJUzJ7hafneJdHxHcoV+RP+56yYUKHMQzLnjHzCk18puKxfQvU/Y/8Eb7zvUh5QtkObF4Su14zNATh3CaQa9bdsGdsC8ygS+Ks8UE3ErDQGdxfyEJUENyaRBDpkZgUToo7MhR4vKunLgkTkFMQxPOwjC8jeRz0q1MmEf1BFE/BOzZ3QiEEF94lkfuzC5KT5b1drgap6LbX/0YAAd/hYGoJ/yPKEjzSeHH3Cx+v4V6TrcNHteCjUbS6fFZmLIfwPtzRoBGBypLXq3gxZQWKlnWpGrmK5UQcp5A2cxej8PNA8IVnFDHHf085yUmT6Wk8qMnaTdBpI7t5Bqxy2uaib2llZdOoLxWnily4YaBzpfd5r01zXug== X-MS-Exchange-AntiSpam-MessageData: SZDBriEvF8SIinw7M2AvQ/j2o90bXOqjAg2PpUvZXaVMWTmVxMF6k3ZbJttNUYdmIFhBj/T6BPFR7n2wwgaHEef1FVb5nfrkV/BwCBGmODi77j456duEP5CNHq2mcvretUiNBzLsZ7K/JExmCK+aATm9WCqyfhsN2A4ccMSO84nLt7Zcu32fU3BrS0DSQfp+SpY0+DhmvlbmiZCDMhBL9q75cRx/8MPXEv/vTEMEpr4vSNST+b9kLz4wBWFTzfYgG5fBT3eFP4KukMoEwahCo5KjYFaT4r2uVX63ddtPUSlMf0QskNINjANgLO+RV/nEHKd/0lw1jKgi/kz+FI1OJIP3ao/+jsWzHfBXNNiQF61+rjkeKzPUwYwgtVlsvRWEhDmbnvu66F6JnJnZJYkS1XQz+SgaKqtNsRIvDm3ZNF7jweTU3qU/PvnkH1nnP/vQ14DaE8xCGkAPs2WYnBF2ecnStgSSFnC2s68rZ+yG0BA= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 75c8c924-f384-44ab-e7ff-08d82802dcb6 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:33:23.3674 (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: vWm4m9xjs1BaTr9yuAxCDb9Jj4/7nLTEdSmYt9kilogT3tFUG3zcoRO6D9S/iolGDzLP3HOrklxmNXfgbu3oIA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: Re3SNujKu4KeZ68cZ24QQqmWx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737205; bh=gqzTuIftsSEB7VqS8zm8voCngD8LAU/UqKnUbYRgB3w=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=wUr2714JTI/Wlv3bnEI2mFXl+cSd3QWQ79ApOfuoq09+d4iUcjaV0mSEKgnzGinxLx/ /S+hedkiKYTQPC5ECxYDH62+JlAlsxESqdhTyjEdfRdA5iJaADB/bGZG6qmJvTZIX/c7O T4Jt0gqeSWb3FyaaCu0A1useP9JEXY8fZnQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a RDTSCP intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index 54134f37e614..a1cf792d4d0b 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -881,6 +881,49 @@ WbinvdExit ( return VmgExit (Ghcb, SVM_EXIT_WBINVD, 0, 0); } =20 +/** + Handle a RDTSCP event. + + Use the VMGEXIT instruction to handle a RDTSCP event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +RdtscpExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + DecodeModRm (Regs, InstructionData); + + Status =3D VmgExit (Ghcb, SVM_EXIT_RDTSCP, 0, 0); + if (Status !=3D 0) { + return Status; + } + + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRcx) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; + Regs->Rcx =3D Ghcb->SaveArea.Rcx; + Regs->Rdx =3D Ghcb->SaveArea.Rdx; + + return 0; +} + /** Handle a VMMCALL event. =20 @@ -1443,6 +1486,10 @@ VmgExitHandleVc ( NaeExit =3D VmmCallExit; break; =20 + case SVM_EXIT_RDTSCP: + NaeExit =3D RdtscpExit; + break; + case SVM_EXIT_WBINVD: NaeExit =3D WbinvdExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62526): https://edk2.groups.io/g/devel/message/62526 Mute This Topic: https://groups.io/mt/75499881/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62527+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62527+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594737218956130.69931045586543; Tue, 14 Jul 2020 07:33:38 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 4TyCYY1788612xaMd68pMwPb; Tue, 14 Jul 2020 07:33:38 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.86]) by mx.groups.io with SMTP id smtpd.web11.21137.1594737218070746006 for ; Tue, 14 Jul 2020 07:33:38 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=goHOVTVpAeFJskowtqIEk+c8GRUalT9fKrXmIIPfXcoaGZuXMWjjB1s2ytuA1Fkq53ZXB9Le+ljQ2uzEWs6BzMW50DuPPqRdKqrYWFhwOqOxxjWJXXGJnHVt+trLEMwcVV+xR9wY5f7YIGEe9vxb4tkZ/0596ZRRr6uswx7Av6WT4QzlvaweTGJpLzbayYUXmbpa3Rol5sckGY8e9Yxzx6v64bTLXRYbeBd1I9UDOXN2cGvZrNNrDyjhfb7TRWo/9SEeTvOoLXVsQ5svfpBSITMLEEiIrZwOCKUbXXZC7jLW1s3rPDrX5PzZ5umL5k28aNo9h/UcHE5QCGszInmbBA== 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=8ngCipJpXdBRXheijMbZLSMbkg66Y4aDLYNKKgZfARY=; b=hYocCpCTduTZGrJEsxXhrPWj/Df3OJTf3lnoMQRwVrtCx07G6hVbDL3Ls1ViFbEforuFUfTvlV0ZHSclFkM8gz54Zu7QmCvsq5ijGS+EBs7qE4jS3elVS1l6s7xt0xM/SEdVmi8pdFBkHHUpIIPim1EfqDqtFEtWLOjlcOm5STysN+lNCafHf64IZzZTTcTgZ37gJMfEuLsv41/k8A2ESddq32kbAwsuGrdOUYeMCCvEphx/Ggs9R6cyw3y+Mlk2jGOgfIyF4xAX+bqsWDQgEQvTb5kZhZuxrLzBaeShgRsWiZCDpHnqofDDk8LXAcrRDPNcrY+IplUaQHdAbBxONg== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB4219.namprd12.prod.outlook.com (2603:10b6:5:217::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 14:33:35 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:33:35 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 24/46] OvmfPkg/VmgExitLib: Add support for MONITOR/MONITORX NAE events Date: Tue, 14 Jul 2020 09:27:55 -0500 Message-ID: <39ba43a83dee27d8ac1650d2bf0a58d11c110855.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR06CA0037.namprd06.prod.outlook.com (2603:10b6:5:54::14) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM6PR06CA0037.namprd06.prod.outlook.com (2603:10b6:5:54::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 14:33:34 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: ba175775-b619-4101-098b-08d82802e3c4 X-MS-TrafficTypeDiagnostic: DM6PR12MB4219: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 1N4QvfNv0czW+eam4atkFs7vZgLeyf5e7UpWEm+uaWxicz7udNyzXKommgQPdmJ1r+Qq1k7eInkYI8yGp938aFR+YpW5eh6tvJnYogeRXqqmFEhFVxZCJWBhfAdzKFPc4IuNgzLP6TehxMnuYMgqa45Hr+yq/xCcS+JkgZTykKUuqXVT2gWZn3yn61fdwlMWHND0yuzsNujLcah3mC7JTnJN9XGa6yHZ5bFZMDnQ640fD/c+76GKcJNZytqwDhkMpslH94Y0ZPVS80vHcRODh1FAiLXA7oCLvAOHBkpGIw4Qv3vz6cvg9poxZH/dF7N/kIvJ+1XZ+hb1pfpElRyJHq92cWk9jMWdQSYSGlqccAdZd3bGdWgAgIzrZoE2HHDPC/6l4Kjq1CGUPhf3tb0qD0dTU30D6ySjEdbCssCYThlbMXh4auDG8iE5n5Q782HvAtsTeKGcI6p5u9oxIE6d1Q== X-MS-Exchange-AntiSpam-MessageData: hDAXcMaZbpYsuDaO9lv1FCPa5e+f6zH8yMzQ/1zNj9mT80vLcauFBLhdFeEGQwhDbpMVKB0pR4vDn8yNFjXQUgr35JUeu5Wa66ZlReqNly3FHyrF0Ku5QzbrYN2Y5CdKSHxDDycpsVWgUzptX6aBUUBpgIfMsB8gw9po8byWXVnjih4qGd5NHC6sRcFRlEUdLAQkq0rzam6h9eZaQAmfvp4eTusVieG1QdJQHrTBEPx7NGnMUBDfAgkU87O+yZgPzKboIP0gdSaZZRNBW+WcOmW8XygRzB7VP3ZHtE7uypKfJ7r20mvrk49Yd/qoD6SeKgkKFOhuUkDkq+f6YERyl9gX/ad39wdQKMRM792cJzBPEvyahLkaw4LnHIB7ShkH0Qv34APYY0IWYJNqoEwrDlHg2dsVzmbuBLnnDjZTX+vtXZQldBGPQPdI/TVaMmCSDQ40HDsKP2lkKgLbNbGxYuojlF8NWv5DuEim+vvUvWk= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ba175775-b619-4101-098b-08d82802e3c4 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:33:35.2804 (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: NwNShIIgSJ6P5WiBMMNKx1wjAcVDQe9ZYBSmKj/HI4yCaaRuhbVz72XCS5pLw6TY81iCtJO5Ii73Nh5BaBlvQw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4219 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: 97KB5qOvYcWTS3DZgyuayKX0x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737218; bh=14W2WVobk1OqASzbBr89Q/WW3MwZQzzgkD6L09kfgPY=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=SPCSC+I57iunvE9LQXGonxUgwmZ7VEhB7mGyxwf2yF50HyUV+iUqhzz2WSTqtE2orBx SR/aSffc4uRQ7G9AYUsnToBn7PS/1Q7v1EhWgpRqY2/B59OsU5UvR4tWzUpif8whk2ir6 kHr8Qev+t9M9hwdUWfUksMx7voIJw2f5jvU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a MONITOR/MONITORX intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index a1cf792d4d0b..fe08b1e0ff49 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -856,6 +856,40 @@ MmioExit ( return Status; } =20 +/** + Handle a MONITOR event. + + Use the VMGEXIT instruction to handle a MONITOR event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +MonitorExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + DecodeModRm (Regs, InstructionData); + + Ghcb->SaveArea.Rax =3D Regs->Rax; // Identity mapped, so VA =3D PA + GhcbSetRegValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Rcx =3D Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + Ghcb->SaveArea.Rdx =3D Regs->Rdx; + GhcbSetRegValid (Ghcb, GhcbRdx); + + return VmgExit (Ghcb, SVM_EXIT_MONITOR, 0, 0); +} + /** Handle a WBINVD event. =20 @@ -1494,6 +1528,10 @@ VmgExitHandleVc ( NaeExit =3D WbinvdExit; break; =20 + case SVM_EXIT_MONITOR: + NaeExit =3D MonitorExit; + break; + case SVM_EXIT_NPF: NaeExit =3D MmioExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62527): https://edk2.groups.io/g/devel/message/62527 Mute This Topic: https://groups.io/mt/75499885/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62528+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62528+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594737494860775.2643608820842; Tue, 14 Jul 2020 07:38:14 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id hwhQYY1788612xuFRfw8WBHR; Tue, 14 Jul 2020 07:38:14 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.41]) by mx.groups.io with SMTP id smtpd.web11.21252.1594737490560993734 for ; Tue, 14 Jul 2020 07:38:10 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lX+LcTAcPuNyUkSQq0YSyp6uTsDjFaOd/hy33gum7NqzK6OBP3WSaIaEY9MJujAoX5qvv+RH+QU0twM70naABsIgtylmME08kSOjE8wsB8so3J+8H+lVHD8+81K6eeceqILwd5LT7oOrMvSlVor/HAheyV8GmeF/S6qV3j4cjdB1RdWCq3JWOpoiXpNqfLOE0XMRTdYYAUGkVvDdXniQix3u3mi27Ikd+NJCq8e2l+ertE0QBFGL7R9pnw23F0izouiBPh1EjfjEVfvpBrvZ2s0mDssZQxl3PJryUUoiITs8XeYd2gy4KLq18IUQfW2JGLxQFII+W7qEPklUY48w1A== 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=4ovVcxdgW2M+goyz4Wril5Z4GVk0Gp8R9simGO5DPIA=; b=F8TjkvupE/Ud+ZsVI2VlYYedDjAsqbWb2ARs7Fy8WgK+onHQ/+KIlXUR9nwF4n0snrmgUtvHSkU1ueRoliLLCEfsBJ04Y6J9gPk/OGiAJY86dmI4GuH5bwVIIZ1NKek1LkHHEOixN4yOjiqBKddmntpsfWZGpoBYt2oNCno+9U2zI50lkLGaPTxHe66wkAevXCmWWl2O0J6qjQ2ZUUJ3lW8TE/V93WH0TQnxOa5UDsRHKejFsnW8pg7SlGBx3IqYl9AP/kDaFea7diHeRYpGzPpL1csHsO577dLZtp3Jzr3oxPSOjCAHBqc2bqo5M55jjmwTM4uh7FZjKmmCkG9OPA== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB4219.namprd12.prod.outlook.com (2603:10b6:5:217::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 14:38:07 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:38:07 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 25/46] OvmfPkg/VmgExitLib: Add support for MWAIT/MWAITX NAE events Date: Tue, 14 Jul 2020 09:37:32 -0500 Message-ID: <7daa9f497e0ef2da547d71404f20c02be6123381.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 14:38:06 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 275a66a9-f397-4384-2426-08d828038620 X-MS-TrafficTypeDiagnostic: DM6PR12MB4219: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: YuO85O9m1PmVblX3jYw6u9eLQ9kQaiKCFZs+OxZ4XIfaUxp0vJGqRcsItqm2WOwDJxH427f7u7rm2pdiacE77zZSK0hlztdth3UR5rd5dIS8FvhiVGCHXTMD7LoF7pAQ5778WUVnluYWQ6U9votVNhTr5zi9nsBTp+CTxr2bxbz1pGJ1dEuceVTrEUd3FfBw3Mdxt3MgreW+xQFRSoP6hC1Il/jyrEq6xMK2KzXcggcKbWI7zT6dG/823CUpQi82CYf5lzoLDUvPuZqsgiwA4FTdr7NVS+VmI2a/Whk7zNfN4sTq6dVbq7tt4M9rixptmSj38GhWVF4EdpK6zCXjFrLiKsQX6kg4m/8238xa/duUQuEOZq5iaeyVvwCRakSx7WLzMpbu+S7Q9zp6nUCUqszfaKM20UWlMwd1X1e9Sh4kCOSglmowGhmLZXENSpPEDTZ49vME7NesFU7gw2aEmg== X-MS-Exchange-AntiSpam-MessageData: 8tI1hjEOq9I+McKCmrzS6uXw21yETBs8tmb0PusYC/n+bpz6AeWCQgEBpUyPg2RUKYwUOlJiltMXuu+94G1QZHDSqNAaV6Hnd3JNKV3MNoTIGNLu4Baa+6aAwZ1NtZjb+j2L8po/Q6DuqBAv9kyOJiQH1CfqDJdotu7JZ1A6HNgI0Uhij4d+/rSBr5nyXexOMXP3rLEacRnea15D+7Nc+mtb2ylUiSfOqnd6YYYbAVAsgcglCrFDjSfsMOcXRayXGYPMwm7o7+p7JDAZ0yIV65LHMDqfcaWpeN39dGQqbOzFHc1Se/hzGA+1DnDBJsylIgttHneyWnlK/8DDVlsCUCEF8coyMBWTkZbzMSJR3XJYFZoXz5+hcjlPFQehs9SyZclmoGBpynRc56/LpCvlKZXPeyfOpraZ/yqoe/HKNz5PfsGeUzG+vk1IOAFlqLvKXRnIxMI8t7vTvOijoaKS/CE7tfq6kARC6pdZEhCaMFY= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 275a66a9-f397-4384-2426-08d828038620 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:38:07.5711 (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: OCvkB3ccfMNd0cfldV84Jek5pF4uZZEXLhiWqVmn2JFQCXPUv+T8fq4IQeA989Z+PSB2cixrfeWWOjMI1nLAuQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4219 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: GoAPARVwUCSSsEs3I0uBzv4px1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737494; bh=caBlfG/yAtylm+abx/TVDWX5IYbXzzRLnoeSjoCGKlI=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=ewrPCA3qblbxxIMN+LZfEhc/lioHWGS1p+q3laW0qTJ8oj1i4pDwBOqjpTl3piCl0/0 8m1l8hzOeceTn/TH0qIQAc6yUTdwe35HhXD/Ha6WVgOyIyMG93VBEqJnWSgax6rIWsVoW qupnxmgKfPCM/QEAsiWzYlHKOmJUB4y738Y= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a MWAIT/MWAITX intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index fe08b1e0ff49..e70e0ef82f68 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -856,6 +856,38 @@ MmioExit ( return Status; } =20 +/** + Handle a MWAIT event. + + Use the VMGEXIT instruction to handle a MWAIT event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +MwaitExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + DecodeModRm (Regs, InstructionData); + + Ghcb->SaveArea.Rax =3D Regs->Rax; + GhcbSetRegValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Rcx =3D Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + + return VmgExit (Ghcb, SVM_EXIT_MWAIT, 0, 0); +} + /** Handle a MONITOR event. =20 @@ -1532,6 +1564,10 @@ VmgExitHandleVc ( NaeExit =3D MonitorExit; break; =20 + case SVM_EXIT_MWAIT: + NaeExit =3D MwaitExit; + break; + case SVM_EXIT_NPF: NaeExit =3D MmioExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62528): https://edk2.groups.io/g/devel/message/62528 Mute This Topic: https://groups.io/mt/75500006/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62529+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62529+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594737492179318.44460964394545; Tue, 14 Jul 2020 07:38:12 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id VMqaYY1788612xnyUAYPtK22; Tue, 14 Jul 2020 07:38:11 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web11.21252.1594737490560993734 for ; Tue, 14 Jul 2020 07:38:11 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZCODR9/UPZ76cHHnGmdVSoT8HSmJwX/qGY3wd/BNCL9Nrxy3m7+RE49RS0B1PVFiLPGGMUdYe6Bm8ROqX65f8Ce6regFge1icNYXLXRfBGS/q28XbFc18AIarnEGD/eKu4YZ6eU/FsdhBF0up1skmCvDFOgYYMDWX2veeLXMLHnDyj1s/dpxTBaK/hjXb6zNe/Z9ffyc/BO5E7oOQU1JBN6E78QnUjMQ25hBIZGbOqQK/g3GzCzE3owYRpGRwjuuIPHbLn3UeKDMC+oaaNtJOPBBVjxMS1u4bn0nkJtorAR2h1rI60VoeP8uyi8UGPWab0+6uMC5wvCmy2Z5zba1rQ== 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=eqxKEl1jkDkoQSy0tcmI5Mo0oyJK/DNNn+LhL12PTF0=; b=a/fiOrxuW3tLSoZ74Q+Ckq7ashgq2Ic6FdlJte2+X9MGs0bKk9dlYX+c10X+LMUVGFrz1TbxP+L1b3JGO1hKiiD59IqiUzBcp+SY+0oAr+TTBFAEK+Wo0RpeZXXjw8YETVMvUC3sWrrwva2XWOtp3TSe7QFBQQFaYjUoVNHZw+vFDXXgZQ+0dmSGNTAIHtDq8/Cg3ka+ZPsuZ7vFMtqMg69Br84lD9pKIijiaIFJ6GG0TkSenTQ2Y7MhI+OtqNq5bnp4Oyx51JL3tIJAzTh6nC0Z25203koeml4VhcndpxcHK5AE5D/BLBaQrRGqtAB7M3tCxIwZCTiE4my7B4433Q== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB4219.namprd12.prod.outlook.com (2603:10b6:5:217::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 14:38:09 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:38:08 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 26/46] OvmfPkg/VmgExitLib: Add support for DR7 Read/Write NAE events Date: Tue, 14 Jul 2020 09:37:33 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 14:38:07 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 551e2c5c-9500-4373-68f7-08d8280386b2 X-MS-TrafficTypeDiagnostic: DM6PR12MB4219: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: dY9sju8WOJjF2SmI/g+XdOQ/WPqHO92RAQb/5NeVfgh55Y/ITRnuJRuCq8PDzZV8jNM7Dx+nftlzjUpPRw5FmqxgXJyQI6YJNgoRT4WlCRPZt51SNmrHK/uNcpUGRtglgwh/UtltuENa8XJdxCKyBBdq9DNUGlLHUcUHQ/xT7UUc5LjroWpJ6Y6Dn1qWRq4Ayc4LAwtMgGYJT7LeEw4EUeB6KjGsmEKPbztXpIBxYocdx0racxEcCTmuvXV4S39xJVkrEh7zzcvbucvimksi/DPvxS7bLfRX4x1A3/4urRAJMyaODA5Wk3AaMQwr7ffsr16f1CMWlFRfXIHarM0jj4m5tvhZMroPOV1eODK/M0FP+cFRmsvTAuA5sRcLP10S+8QOD9ZJd2eteH29aHvIMOMzBr46QQvtcaE+NbVR9H0phs+HDARSaMZDTt4RMWqYkd89BpfbQzn9k3I0QtNZ9A== X-MS-Exchange-AntiSpam-MessageData: lfwsgfPKCq4i8TXDLDxCASkloLfHm+Izw4rUmtOuJb2G5y08f5n8o1YliwW/xnN29J8x3fHMXqu/o1D+H/jWwFmAwZGscQYeIQ21giVdnSqbN9i/WFo5D+HqviNuwZWgLx7d9W3Q61bAmBp2va5w16PRHQEh5P9UCfVTejH72/spFIIobIxjrzcCxMwBOgAwbAfIsIU6FrmgjvF9/gt/YMtOlwkOUBHQW8aPLA1SRdZoRls3t6/Enh5O8Csq47h1L2L3lb94BXq2O+9NCF0jZ3IDzLtRyBZn4H0KbTfYBOOZ3XOn6iwwlItrMySezdCBpqZf61/tC+rIma1aaJ59ZHZ4olU+JaQDSiGEwKwtK8WOfjC1OHu8jO0S4wbgduLqhunQD1MxQ0+/mJWsPfJvFuEEXaxuhqgZ8ES/zAVzcn4aHbQujh8PN2tHHGKnJ4m98ognwa2qf/7/L6fr00s27cNo9eOcNHYMIPA2EC15mAM= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 551e2c5c-9500-4373-68f7-08d8280386b2 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:38:08.5556 (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: 7KlqsR3waAbxC+QmPQx43bUXTF+qspgSy941h5yByCYeJMH7Bp035731k3W2AsyM7Q76JJLNuy6rGwLtXdL6mg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4219 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: PjGDy8kZIeTXOHY1F74erlDgx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737491; bh=lVMIdxAxtgB+FisuJD40CAfOEK1UkGLRLO+b8ZtbeIM=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=WlxvFm+yWatYxiv8+vzTd3ERiK5Xc5JopOcLu/d2H6sd9rX5Tlk+j3EA2krVj8C3pcf WyYl8SH4ZHuwP2qZoFjUHc6/pXEfnKGhf9LHDSNyHK+ebQvN7aLaLoD8wEz41iTmDxcZb NTqqb1kQFbIfJMH2z5rc6xd+JmlLUNkcQGg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a DR7 read or write intercept generates a #VC exception. The #VC handler must provide special support to the guest for this. On a DR7 write, the #VC handler must cache the value and issue a VMGEXIT to notify the hypervisor of the write. However, the #VC handler must not actually set the value of the DR7 register. On a DR7 read, the #VC handler must return the cached value of the DR7 register to the guest. VMGEXIT is not invoked for a DR7 register read. The caching of the DR7 values will make use of the per-CPU data pages that are allocated along with the GHCB pages. The per-CPU page for a vCPU is the page that immediately follows the vCPU's GHCB page. Since each GHCB page is unique for a vCPU, the page that follows becomes unique for that vCPU. The SEC phase will reserves an area of memory for a single GHCB and per-CPU page for use by the BSP. After transitioning to the PEI phase, new GHCB and per-CPU pages are allocated for the BSP and all APs. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index e70e0ef82f68..c57c8c4ba203 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -126,6 +126,14 @@ UINT64 SEV_ES_INSTRUCTION_DATA *InstructionData ); =20 +// +// Per-CPU data mapping structure +// +typedef struct { + BOOLEAN Dr7Cached; + UINT64 Dr7; +} SEV_ES_PER_CPU_DATA; + =20 /** Checks the GHCB to determine if the specified register has been marked v= alid. @@ -1480,6 +1488,104 @@ RdtscExit ( return 0; } =20 +/** + Handle a DR7 register write event. + + Use the VMGEXIT instruction to handle a DR7 write event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +Dr7WriteExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + SEV_ES_INSTRUCTION_OPCODE_EXT *Ext; + SEV_ES_PER_CPU_DATA *SevEsData; + UINT64 *Register; + UINT64 Status; + + Ext =3D &InstructionData->Ext; + SevEsData =3D (SEV_ES_PER_CPU_DATA *) (Ghcb + 1); + + DecodeModRm (Regs, InstructionData); + + // + // MOV DRn always treats MOD =3D=3D 3 no matter how encoded + // + Register =3D GetRegisterPointer (Regs, Ext->ModRm.Rm); + + // + // Using a value of 0 for ExitInfo1 means RAX holds the value + // + Ghcb->SaveArea.Rax =3D *Register; + GhcbSetRegValid (Ghcb, GhcbRax); + + Status =3D VmgExit (Ghcb, SVM_EXIT_DR7_WRITE, 0, 0); + if (Status !=3D 0) { + return Status; + } + + SevEsData->Dr7 =3D *Register; + SevEsData->Dr7Cached =3D TRUE; + + return 0; +} + +/** + Handle a DR7 register read event. + + Use the VMGEXIT instruction to handle a DR7 read event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + +**/ +STATIC +UINT64 +Dr7ReadExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + SEV_ES_INSTRUCTION_OPCODE_EXT *Ext; + SEV_ES_PER_CPU_DATA *SevEsData; + UINT64 *Register; + + Ext =3D &InstructionData->Ext; + SevEsData =3D (SEV_ES_PER_CPU_DATA *) (Ghcb + 1); + + DecodeModRm (Regs, InstructionData); + + // + // MOV DRn always treats MOD =3D=3D 3 no matter how encoded + // + Register =3D GetRegisterPointer (Regs, Ext->ModRm.Rm); + + // + // If there is a cached valued for DR7, return that. Otherwise return the + // DR7 standard reset value of 0x400 (no debug breakpoints set). + // + *Register =3D (SevEsData->Dr7Cached) ? SevEsData->Dr7 : 0x400; + + return 0; +} + /** Handle a #VC exception. =20 @@ -1524,6 +1630,14 @@ VmgExitHandleVc ( =20 ExitCode =3D Regs->ExceptionData; switch (ExitCode) { + case SVM_EXIT_DR7_READ: + NaeExit =3D Dr7ReadExit; + break; + + case SVM_EXIT_DR7_WRITE: + NaeExit =3D Dr7WriteExit; + break; + case SVM_EXIT_RDTSC: NaeExit =3D RdtscExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62529): https://edk2.groups.io/g/devel/message/62529 Mute This Topic: https://groups.io/mt/75500007/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62530+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62530+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594737493083185.19260607222247; Tue, 14 Jul 2020 07:38:13 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id W1YMYY1788612xNi9U19ZL5q; Tue, 14 Jul 2020 07:38:12 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web11.21252.1594737490560993734 for ; Tue, 14 Jul 2020 07:38:12 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fBexgz3jzL8Bkq2V1Apt2n9w4rgsdO2yk6qVcpYTiDmueV3qhWpNKcFe+Y0nXFTMCfUnZswSYSnozgQnygZNamP0cbZQNxItz5dU7cifUYYH4t0wIWa7KXj3GDnVv4HnI+40nesOKpc+eAjOKUhnTDOfW5coXO3+jlSBXCMh89SshuNZ46k+Yv50E1V9voldo1QNRUhImuKDpaljPvToVMXJ+zcUmLwHWaBHNFtJtw+PkrIpY7hu+znL8IYIn5DPdICWhCDaljBz9WKdfLnmG637mAJ+9QJb+G2tUyBPuHHlYQR97GheVcHVxeTySm6o3DW8ICmxmrM9p9jWjzvqSg== 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=vjUCEgWiruW32rdghdGFw/QPeneWsq53gmsGSiMfqdM=; b=M/mosxCa8xxI7VMwza7iwIohGqRSdPTQPQr4OBxFw6BO73yPupqCy3rxNgptlTsHXxY91k+GVz22ZvIpijv9z22GFeTeJ5adv5VcTZ7+Cq07YlVUCmD1eWhfPyBj88rYhmr7zi+8i9K9icDNVY7Cdq/hGyN74GbHHjqejaZHP5COkOOlF6PDViwEQxbYIPYF9C+r14NpYuC3nn1xVULdmrC5V4/yPtTJyAOt6N5dHAzWIlZxlzcqUmvMFgGVDeJvXx2DAfmYCDnMeBGh7/mshMos36j7BOSUTQph2oYaTXI04iTPN0/iuIRhEaW52C9IAVhxqyXjr/N+d7n5hAZgMA== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB4219.namprd12.prod.outlook.com (2603:10b6:5:217::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 14:38:10 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:38:10 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 27/46] OvmfPkg/MemEncryptSevLib: Add an SEV-ES guest indicator function Date: Tue, 14 Jul 2020 09:37:34 -0500 Message-ID: <3f0e4480d375c3d99bba383714bf12d43d91b51b.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 14:38:08 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 4140905b-af60-4a8a-1e85-08d828038747 X-MS-TrafficTypeDiagnostic: DM6PR12MB4219: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: jzYOZ5A+e1HBtQFwM0ccdQzcTSh8TnlgeP25wQSb6572z4iP31HPeZZXrJH5rmAIouHFVRlUpjGmRq2JgUeTn7H/9hpoSa5Amqfoh5Azli1dLwrTLZYFjgcnk+zSD38vqFQiapNo9FXWWCwoDlHZfas4tNsSVNWKYVuhantdusMVfDH106whjk7Gzrn7iP1ulRulDiBcQ9vrjHenT2p0KcQJ8wf3vQcvJHrOqylsG2bNFBaFv3KpsBSL7rVUjZhdaVeXjy776UepgFqIcoLXDv2nvFFEBcsjn+Uu4Sr7XKqv+bc0d3odB2MABzTWMXIZZQXPCfDYIhDc7Nwm1djUx99Xjs9bDLnMF0TSAmSWgAMUpCM+CeV+6Ym4qka2SVL5Xt1hy3RtgaoDRn0rRVMnxqy5o4gTu//18B4p1Jb5ifpZKXhhdqKE0YmSoNgbJXwbZtG+v54gBlXpkUDbkJpAyQ== X-MS-Exchange-AntiSpam-MessageData: FQZxR1qnDR9KTW6Ct8PCWCEnFAW844uyba2OH0jv/5lXxrb3m8JqzaNvxKCL42OlZFOrq07jfBr+UCsm1aVEJLTr1FAmY5NRGYQRBvJn6bqDKcv4eOT23kGapO7Uxf614EpDpqAXgSgYBkpEp1nlkckVnSBiy/z5D4y3DjW4KKboYjRzM3X7QtHNyJ/EqjJ1KTD7TnrdOKltt1XTzlKR7j57EBnXRa2EZFjxFZ8xKujMg//P6V7ea+OPe5OZRi0heGIpUdz1etl1RgLKM6e6ZhVxJmd7N8XMeGxXk8v4UDTeh9FndPESZeKYtihKXv/YBcWI/DXA7rlIWgSvYJUvI9hVCX0cwGi24Lx44AaycMjH5VLOl7BE+ZVFDfY3RGwwyRO5h9mwPR57R1Ttfsvl3VuSeCFH4CmcDHrG4p4LdGV71uCiaQ61mjZraGtQ82FlpSHRfR4r9yOuF1X6shuGtYn2RcWqZxstcVDXROGHjcU= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4140905b-af60-4a8a-1e85-08d828038747 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:38:09.5122 (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: 6T01cu3pEVr7kslg11gx0PtUTEg8ncK/Pg3bt9bD47EcH/YGYBcMWyj3eSqW5Cv2uldwo8FBvEO3RuSXF7tPsQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4219 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: KOCizyLnlyEjnMvNaa6WjBrIx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737492; bh=/1ngmzg36nnGknYnpJPHnn67unnOU0+j5Ds+TVf+uVM=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=ORuyppX6skHxTvj3t+gs5DidtJQLx77qAIAUa3s8gXUhmpsO2OSd2mtMT896fIy7g2M 2JhV5NFXy4igmgujxXtOc1pQk/386By26PqIppC7Y8Upl1LKkZkLdCym1yLF+oG3vDxbV NhPzkH1xlUH9HX2iEmox+NMh1Wf3Dd/OXXI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Create a function that can be used to determine if the VM is running as an SEV-ES guest. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Include/Library/MemEncryptSevLib.h | 12 +++ .../MemEncryptSevLibInternal.c | 75 ++++++++++++------- 2 files changed, 60 insertions(+), 27 deletions(-) diff --git a/OvmfPkg/Include/Library/MemEncryptSevLib.h b/OvmfPkg/Include/L= ibrary/MemEncryptSevLib.h index 64dd6977b0f8..a50a0de9c870 100644 --- a/OvmfPkg/Include/Library/MemEncryptSevLib.h +++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h @@ -13,6 +13,18 @@ =20 #include =20 +/** + Returns a boolean to indicate whether SEV-ES is enabled + + @retval TRUE SEV-ES is enabled + @retval FALSE SEV-ES is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevEsIsEnabled ( + VOID + ); + /** Returns a boolean to indicate whether SEV is enabled =20 diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.= c b/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c index 96a66e373f11..3301c5c2862f 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c @@ -20,19 +20,17 @@ #include =20 STATIC BOOLEAN mSevStatus =3D FALSE; +STATIC BOOLEAN mSevEsStatus =3D FALSE; STATIC BOOLEAN mSevStatusChecked =3D FALSE; =20 /** + Reads and sets the status of SEV features =20 - Returns a boolean to indicate whether SEV is enabled - - @retval TRUE SEV is enabled - @retval FALSE SEV is not enabled **/ STATIC -BOOLEAN +VOID EFIAPI -InternalMemEncryptSevIsEnabled ( +InternalMemEncryptSevStatus ( VOID ) { @@ -56,32 +54,55 @@ InternalMemEncryptSevIsEnabled ( // Msr.Uint32 =3D AsmReadMsr32 (MSR_SEV_STATUS); if (Msr.Bits.SevBit) { - return TRUE; + mSevStatus =3D TRUE; + } + + // + // Check MSR_0xC0010131 Bit 1 (Sev-Es Enabled) + // + if (Msr.Bits.SevEsBit) { + mSevEsStatus =3D TRUE; } } } =20 - return FALSE; -} - -/** - Returns a boolean to indicate whether SEV is enabled - - @retval TRUE SEV is enabled - @retval FALSE SEV is not enabled -**/ -BOOLEAN -EFIAPI -MemEncryptSevIsEnabled ( - VOID - ) -{ - if (mSevStatusChecked) { - return mSevStatus; - } - - mSevStatus =3D InternalMemEncryptSevIsEnabled(); mSevStatusChecked =3D TRUE; +} + +/** + Returns a boolean to indicate whether SEV-ES is enabled + + @retval TRUE SEV-ES is enabled + @retval FALSE SEV-ES is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevEsIsEnabled ( + VOID + ) +{ + if (!mSevStatusChecked) { + InternalMemEncryptSevStatus (); + } + + return mSevEsStatus; +} + +/** + Returns a boolean to indicate whether SEV is enabled + + @retval TRUE SEV is enabled + @retval FALSE SEV is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevIsEnabled ( + VOID + ) +{ + if (!mSevStatusChecked) { + InternalMemEncryptSevStatus (); + } =20 return mSevStatus; } --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62530): https://edk2.groups.io/g/devel/message/62530 Mute This Topic: https://groups.io/mt/75500008/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62531+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62531+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594737497460174.28581569037487; Tue, 14 Jul 2020 07:38:17 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id BvVMYY1788612x8veCdCAcUF; Tue, 14 Jul 2020 07:38:17 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web11.21252.1594737490560993734 for ; Tue, 14 Jul 2020 07:38:12 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=j8oxI0cS3LYoCtKndz5w/ZJnTXyEGgNOejgha2UNPLORG+G13i8SYXIsyYLXLzVxTCOIvVimDHD95RnHajnuLTjAzXOA+/B4k2oMLEancLwyCtphDJEoBemk1f09nzf7+RDHGAyGiF7zmGSYmZZ+dmoVuYtGy0uYijaqDrI4y/XSFRTKY3u/Urj0DGKtrx2elgQC/pal6e5yTxpbpNZjcAw0HupWkFFbONMVDZGekWv1HOHC1BOZlxBDG7/S1xyHsmKZKNB4xB/uHQqfYGeJxw+fV9vqWRxapxhmWYlvpU1TIB4EAJYhUR/RxFlAZDx1JlG/U+SHIKEi9wCQ1cgneg== 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=215PQ7ca99/bfEAHV/uLbIlFpjqLGfOl7zXhdvtrLLU=; b=bg7K5bkYqbTPxrg4xaRD7KNc9zX6pbh8GR9hXXvj/el8mM1EXEFvgxbMD+bnpJcTcK0JmTt/4KaFS8cRyo43giVpmelKRaTNs68xYkhj56Ekw1QH9B8rO6bWZ6E/dEPtAqXzanm94o3CBlZHjOrwvU0a6t07y8TLkeWXBCuh67/uWCor7wkgM6KhnQ0dJfjOyrIONhX4fmaj5ia8xCCX+ikRwdeUSAv7MIXLJN9IC8RXzI05bIkscJ1U13iutaceLnCkyh9p0Jttm6BfKmg1n3P08kDVxKxv1M7NRmxKqJjnKHM6g7hZw6AvP9vWWcPgBdWbV0nxDhIMoIaFwzWUAw== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB4219.namprd12.prod.outlook.com (2603:10b6:5:217::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 14:38:10 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:38:10 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 28/46] OvmfPkg: Add support to perform SEV-ES initialization Date: Tue, 14 Jul 2020 09:37:35 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 14:38:09 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: fa9041bd-64b3-4f63-dcda-08d8280387d7 X-MS-TrafficTypeDiagnostic: DM6PR12MB4219: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: Ocpkt8Rv/CfS/gh6T69s28IUI/meOPUDpT0YQqgjvXN+2ZJh+5mXLEN8JIzbyVOfKF/DLKzudg6wlPvVmCQVMI/4sLgzgqAkdCCubXdypW0RafKAnJyTgg9vTOR9dRN8LzBEQBoVyIlb7Xvx+DSlEv0JbkVDamNMauMC/P52CGrJkZzV8RWHvMqVYQTiUIpyI5bZ6i5/umFdRvz+cOYRFGJFRo8DClv7gPiBsJyXvGuzLjDgRUOBmq+yPSZ2e/cxOxH3hbhgz9QDrcYslyp9GPY7rKS7TMZLPaIHD5hJrrIVny1tfwZOdB9PTCafmLaEjNywPKl8aNBubiL3JOh3XCLtmJMzfDw3icJDKJ0mp1RCk3Llzat7BIVpLc+7xI6b3+MVUf/3fI3F/rNJiDgJnu+d+JOhsft7jSNomB8qzbK3z9SR44+AjPrDVd1Pa/YVjVGaG6RUvlGc2+peo+sYVQ== X-MS-Exchange-AntiSpam-MessageData: 7ItEEZhx/VuX6j2iH6/C5vyb69F+/C1uHXQOXoy0wNrykVfXw1XWEyJh8n7JQp40gihV15/qIpR4ox2vuDYbrkOcOiAzdk4guhG5IY7FikONPUKplqzQwOk3pYYugcKFHRDLDDk73+hN8aa1C6yVcUGX7ADHfStrK7AZrkGh4xJ76DG5L249bQjG4p1Dfs1Y/tt8jbKp8cq6iIUfJSWQG0uyhR7GjYDdSj9JNbj3XToCc6wmodbA/G5YGFt16IDAu+8bAc9FuWImez+SVnlK+bVIVU9QN5cFI7hgvFHcH2pXaaEVuebW7UKxk5SJQwBC34uMOL+aD2XuuEfxlZF5dd80vq1gQuzx9EDJdAFs43+Ue6Vflbv/YXy6DCKvexWRufvzIlPzVppZKVsvZNcz0ylMNMzRBkaKuQXxKwsjqpWI0ydSYJ6ZiJ7d1Ed2jDGD6FoCf68Cs3+7yGxCUB87rMyMSOlnQmRegyB4l4KDQqo= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: fa9041bd-64b3-4f63-dcda-08d8280387d7 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:38:10.4737 (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: eZx24CF1Mfj5rUx4cJOV72g6jbbFaobyn//x+8XYYXwJBXGNqbZC9A4/nO3TmcgDUXWzRiWS8jnL2OJhNTF27Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4219 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: 6eDd4Ce7zeeXMF22vwHEBbnUx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737497; bh=u+AtYfUJyI0kzQVSMHZw2fG/geE1SyJ8LiY6BYKBFfg=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=g2EDN035RVzrryX/bVnkx49TkzhIDoNKnNGaBJdHvLA7Wjcxgl3obLXd8BDTG2NQr/i sdu9PKllDI52Z1ZHfu5cleq/3aZttQdegaXDlAInoxmMdgmEOW4owA8g0fqlehSnNrML2 K35zRCIuHrDkUW1sa1YwFCZJPDOIKmeyNP0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 When SEV-ES is enabled, then SEV is also enabled. Add support to the SEV initialization function to also check for SEV-ES being enabled, and if enabled, set the SEV-ES enabled PCD (PcdSevEsIsEnabled). Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/OvmfPkgIa32.dsc | 3 +++ OvmfPkg/OvmfPkgIa32X64.dsc | 3 +++ OvmfPkg/OvmfPkgX64.dsc | 3 +++ OvmfPkg/PlatformPei/PlatformPei.inf | 1 + OvmfPkg/PlatformPei/AmdSev.c | 26 ++++++++++++++++++++++++++ 5 files changed, 36 insertions(+) diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index b6f98af8183c..494b67c5c073 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -606,6 +606,9 @@ [PcdsDynamicDefault] # Set memory encryption mask gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask|0x0 =20 + # Set SEV-ES defaults + gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|0 + !if $(SMM_REQUIRE) =3D=3D TRUE gUefiOvmfPkgTokenSpaceGuid.PcdQ35TsegMbytes|8 gUefiOvmfPkgTokenSpaceGuid.PcdQ35SmramAtDefaultSmbase|FALSE diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index d147aca168be..14ecfb24912d 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -618,6 +618,9 @@ [PcdsDynamicDefault] # Set memory encryption mask gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask|0x0 =20 + # Set SEV-ES defaults + gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|0 + !if $(SMM_REQUIRE) =3D=3D TRUE gUefiOvmfPkgTokenSpaceGuid.PcdQ35TsegMbytes|8 gUefiOvmfPkgTokenSpaceGuid.PcdQ35SmramAtDefaultSmbase|FALSE diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 6db1f0b51c7c..ec11ec914556 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -616,6 +616,9 @@ [PcdsDynamicDefault] # Set memory encryption mask gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask|0x0 =20 + # Set SEV-ES defaults + gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|0 + !if $(SMM_REQUIRE) =3D=3D TRUE gUefiOvmfPkgTokenSpaceGuid.PcdQ35TsegMbytes|8 gUefiOvmfPkgTokenSpaceGuid.PcdQ35SmramAtDefaultSmbase|FALSE diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index ff397b3ee9d7..00feb96c9308 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -103,6 +103,7 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber gUefiCpuPkgTokenSpaceGuid.PcdCpuBootLogicalProcessorNumber gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize + gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled =20 [FixedPcd] gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index e484f4b311fe..4dc5340caa7a 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -21,6 +21,27 @@ =20 #include "Platform.h" =20 +/** + + Initialize SEV-ES support if running as an SEV-ES guest. + + **/ +STATIC +VOID +AmdSevEsInitialize ( + VOID + ) +{ + RETURN_STATUS PcdStatus; + + if (!MemEncryptSevEsIsEnabled ()) { + return; + } + + PcdStatus =3D PcdSetBoolS (PcdSevEsIsEnabled, TRUE); + ASSERT_RETURN_ERROR (PcdStatus); +} + /** =20 Function checks if SEV support is available, if present then it sets @@ -103,4 +124,9 @@ AmdSevInitialize ( ); } } + + // + // Check and perform SEV-ES initialization if required. + // + AmdSevEsInitialize (); } --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62531): https://edk2.groups.io/g/devel/message/62531 Mute This Topic: https://groups.io/mt/75500009/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62532+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62532+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594737497947993.541462139211; Tue, 14 Jul 2020 07:38:17 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id QVLiYY1788612xAghI4kTpoY; Tue, 14 Jul 2020 07:38:17 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web11.21252.1594737490560993734 for ; Tue, 14 Jul 2020 07:38:13 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nh0tt/CH03QwyoAC/8jplFuuguFlGNreIE09vAMtPluCPvmO4XZOGyTTazlziYyLwn8Ks85HH2iQf7Q8yEZtP6Xw8Vi8KQnEuYScDGa4YvGXNp5G9+08HQ23QiW2bA4ZUPOEWlRBYGOfL/RSjZYv3ink9sfI5Zbc4V1PRNMkQL+eLvfoW9R3imJo/42oB1eYBVGRPGSbQxEspk8GphgAKE6aDksOIhJTqlfzZRm2Z8gvfmse3G2++MsD1P5a2qbUkwq/5/iTB+YMbaWVMLtGlQ++PbMcwUAETIEjzUBjH+GTJHDjBwITSqPFAD0w4m5MhOXnXbwiTjBCnBaJMm/yrw== 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=hFp5TN5HSx1rQbonOygjUz+P8H9LR4ZK4FXzQ0TXkyA=; b=KTlhu//KOuoNvvcAsXr5cI5kTNLwb3CEPBd4vbIPwK3PGyuNDNFbyrj+PB1EEdEo7545BOFuhSjogR59YIzY22vydF3yxw8NCN5WUeulhTvtMFKmesSDfIk2Zgkrgy+gnMCsRiTX8CXXKiedt7c++G1PkMUlorFlTR6H9W1OUYHEfbUSFURAaxyKS+vHOZ9ZMtiBVFgGudRUGRyznMco7e2eC/36hv2kdWKOIzkv4FRH8Q0cgAN5ES9vaWqmh6aR/S5BwFX/b6ExUWP6Av9fQHXHjFmG2yybe7W8ZgE5g5t+mIuqj7djl3Ds8tJaVKFcPaAk32Hd4FtqXkhERZkB6w== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB4219.namprd12.prod.outlook.com (2603:10b6:5:217::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 14:38:12 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:38:11 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 29/46] OvmfPkg: Create a GHCB page for use during Sec phase Date: Tue, 14 Jul 2020 09:37:36 -0500 Message-ID: <4ab7276bd5beb459b6f504c623d24012acfba95e.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 14:38:10 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: b56d64a7-4df9-49e8-6289-08d828038870 X-MS-TrafficTypeDiagnostic: DM6PR12MB4219: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: R3rb7lEuDUXSAhYZQCCGEUMjBFtSo8trThoVVJYtrvnW1bWjSkLmDqiD1rviXftqwUywa2aeY4Q3DvtF+db09ACUZHAwZFWl21t9n+Kw9EnIsOai9M7WSQ69VM0r695SzYGx3etoDbgE6LKApRsft4YH/1iOT98wRAzbcpo2nYR66/XpOzkBd3GnV8OQHXHzJrh3i3AfOQGlbGdJjkIb0LMQ5oEPZ0x9IhgeGTI2bLhbxEaROTcFe5vPNHj4U9w6KobCggUwu1QgNzHzFfq08n1qmufkM1QEsleIjUPdcYDP/ehPxiPUDQB9jEVtIP5JDGCfuWJ9IZI5gLX/QGHW1yn2v+HFOSBi+pmYxDjLi9xBvj1OtGcY/R+aYpXg8uDoWIWsXYjbqy/Y32z7MoDDeGzWOJ4vvUqHamoSy8lzfiZ1kfTWYuMk8H0obrBzY0XdOmVODI7Vb5ceZ2mhYtFw5Q== X-MS-Exchange-AntiSpam-MessageData: iHwg1P5/FiR/Dj9SDLWVexWhcpidp0DK/BQq7SqW9F/lUwF+y+xoq2hxnXcnWOAvw79uReXP+S6dFmkXH+w1Qsf7kguOkvxOlkTKqCC2SxPGS0YizQ3Sxr2W0R5ou9Qz/Zzra1uKJHFHk54gGc8Lq2HdDtVVSIWsOjMMVXT96igB9AsYCQ9gR9v9HL04DotLHOzmfCEuGZPnSXjNAaz1P6zlvu7drMQDCvRIlqopanoLAG1hLsFCqE2WT7TmhYtsihc4YlzSS4hJO/3ZmCyzUzMdaeaCjyIpodT2U2m+lkU5FlJVc/V4PwEtuLC65kK8DQysBvL7PRtwDlAEc1HuT6AkoBLXSauzDmsIfUsVEQnNQ1elKYas+7cahxh4ZkVjZ0XCY6dYRbiuzh1UbQea8UlL5W0bl+SQO2FPr/mQ/C85F04JcmNrfL8M7plDszOqzhV/IMZg+rUNXYVQlCYvM4b6+z8yObUFjDSdvyqVkYk= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b56d64a7-4df9-49e8-6289-08d828038870 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:38:11.5283 (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: Ncjas3LFpAAIJHhJNxmx4QA7ZzooyfFhotFS8CMbylXHVK163bULU1XAMuJJhRmlT3M9w1NrjOUiUgZN6OyNcg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4219 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: nxztt50hpFZtUZboyfT7jXZGx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737497; bh=3ZrzW5HArMm/R2Jstv9IjzDT/7CWsGrrZ/6EbyMtA/A=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=bheMW1aho8gw0NXERdwn26DZqHmUM3oQB6DFCqeBbKl6j9/RG+iGEmusF2M2Y+iDBev joCzS13YMtlXUvNVF8USZnRH9fSL+QjNzsrGnnJHMzuuuEVZa2Ba8xXZCNGKiJdQYNwip sUBXQTIlRsokr61UQehFLzqpI6Ab8uURIYo= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 A GHCB page is needed during the Sec phase, so this new page must be created. Since the #VC exception handler routines assume that a per-CPU variable area is immediately after the GHCB, this per-CPU variable area must also be created. Since the GHCB must be marked as an un-encrypted, or shared, page, an additional pagetable page is required to break down the 2MB region where the GHCB page lives into 4K pagetable entries. Create a new entry in the OVMF memory layout for the new page table page and for the SEC GHCB and per-CPU variable pages. After breaking down the 2MB page, update the GHCB page table entry to remove the encryption mask. The GHCB page will be used by the SEC #VC exception handler. The #VC exception handler will fill in the necessary fields of the GHCB and exit to the hypervisor using the VMGEXIT instruction. The hypervisor then accesses the GHCB in order to perform the requested function. Four new fixed PCDs are needed to support the SEC GHCB page: - PcdOvmfSecGhcbBase UINT32 value that is the base address of the GHCB used during the SEC phase. - PcdOvmfSecGhcbSize UINT32 value that is the size, in bytes, of the GHCB area used during the SEC phase. - PcdOvmfSecGhcbPageTableBase UINT32 value that is address of a page table page used to break down the 2MB page into 512 4K pages. - PcdOvmfSecGhcbPageTableSize UINT32 value that is the size, in bytes, of the page table page. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/OvmfPkg.dec | 9 +++ OvmfPkg/OvmfPkgX64.fdf | 6 ++ OvmfPkg/ResetVector/ResetVector.inf | 5 ++ OvmfPkg/ResetVector/Ia32/PageTables64.asm | 76 +++++++++++++++++++++++ OvmfPkg/ResetVector/ResetVector.nasmb | 17 +++++ 5 files changed, 113 insertions(+) diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 65bb2bb0eb4c..02ad62ed9f43 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -281,6 +281,15 @@ [PcdsFixedAtBuild] ## Number of page frames to use for storing grant table entries. gUefiOvmfPkgTokenSpaceGuid.PcdXenGrantFrames|4|UINT32|0x33 =20 + ## Specify the extra page table needed to mark the GHCB as unencrypted. + # The value should be a multiple of 4KB for each. + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableBase|0x0|UINT32|0x3a + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableSize|0x0|UINT32|0x3b + + ## The base address of the SEC GHCB page used by SEV-ES. + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase|0|UINT32|0x3c + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize|0|UINT32|0x3d + [PcdsDynamic, PcdsDynamicEx] gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x10 diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf index bfca1eff9e83..88b1e880e603 100644 --- a/OvmfPkg/OvmfPkgX64.fdf +++ b/OvmfPkg/OvmfPkgX64.fdf @@ -76,6 +76,12 @@ [FD.MEMFD] 0x007000|0x001000 gEfiMdePkgTokenSpaceGuid.PcdGuidedExtractHandlerTableAddress|gUefiOvmfPkgT= okenSpaceGuid.PcdGuidedExtractHandlerTableSize =20 +0x008000|0x001000 +gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableBase|gUefiOvmfPkgTokenSp= aceGuid.PcdOvmfSecGhcbPageTableSize + +0x009000|0x002000 +gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase|gUefiOvmfPkgTokenSpaceGuid.P= cdOvmfSecGhcbSize + 0x010000|0x010000 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase|gUefiOvmfPkgTokenSpace= Guid.PcdOvmfSecPeiTempRamSize =20 diff --git a/OvmfPkg/ResetVector/ResetVector.inf b/OvmfPkg/ResetVector/Rese= tVector.inf index b0ddfa5832a2..483fd90fe785 100644 --- a/OvmfPkg/ResetVector/ResetVector.inf +++ b/OvmfPkg/ResetVector/ResetVector.inf @@ -26,6 +26,7 @@ [Sources] [Packages] OvmfPkg/OvmfPkg.dec MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec UefiCpuPkg/UefiCpuPkg.dec =20 [BuildOptions] @@ -33,5 +34,9 @@ [BuildOptions] *_*_X64_NASMB_FLAGS =3D -I$(WORKSPACE)/UefiCpuPkg/ResetVector/Vtf0/ =20 [Pcd] + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm b/OvmfPkg/ResetVecto= r/Ia32/PageTables64.asm index abad009f20f5..9f86ddf6f08f 100644 --- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm +++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm @@ -21,6 +21,11 @@ BITS 32 %define PAGE_2M_MBO 0x080 %define PAGE_2M_PAT 0x01000 =20 +%define PAGE_4K_PDE_ATTR (PAGE_ACCESSED + \ + PAGE_DIRTY + \ + PAGE_READ_WRITE + \ + PAGE_PRESENT) + %define PAGE_2M_PDE_ATTR (PAGE_2M_MBO + \ PAGE_ACCESSED + \ PAGE_DIRTY + \ @@ -75,6 +80,37 @@ NoSev: SevExit: OneTimeCallRet CheckSevFeature =20 +; Check if Secure Encrypted Virtualization - Encrypted State (SEV-ES) feat= ure +; is enabled. +; +; Modified: EAX, EBX, ECX +; +; If SEV-ES is enabled then EAX will be non-zero. +; If SEV-ES is disabled then EAX will be zero. +; +CheckSevEsFeature: + xor eax, eax + + ; SEV-ES can't be enabled if SEV isn't, so first check the encryption + ; mask. + test edx, edx + jz NoSevEs + + ; Save current value of encryption mask + mov ebx, edx + + ; Check if SEV-ES is enabled + ; MSR_0xC0010131 - Bit 1 (SEV-ES enabled) + mov ecx, 0xc0010131 + rdmsr + and eax, 2 + + ; Restore encryption mask + mov edx, ebx + +NoSevEs: + OneTimeCallRet CheckSevEsFeature + ; ; Modified: EAX, EBX, ECX, EDX ; @@ -139,6 +175,46 @@ pageTableEntriesLoop: mov [(ecx * 8 + PT_ADDR (0x2000 - 8)) + 4], edx loop pageTableEntriesLoop =20 + OneTimeCall CheckSevEsFeature + test eax, eax + jz SetCr3 + + ; + ; The initial GHCB will live at GHCB_BASE and needs to be un-encrypted. + ; This requires the 2MB page for this range be broken down into 512 4KB + ; pages. All will be marked encrypted, except for the GHCB. + ; + mov ecx, (GHCB_BASE >> 21) + mov eax, GHCB_PT_ADDR + PAGE_PDP_ATTR + mov [ecx * 8 + PT_ADDR (0x2000)], eax + + ; + ; Page Table Entries (512 * 4KB entries =3D> 2MB) + ; + mov ecx, 512 +pageTableEntries4kLoop: + mov eax, ecx + dec eax + shl eax, 12 + add eax, GHCB_BASE & 0xFFE0_0000 + add eax, PAGE_4K_PDE_ATTR + mov [ecx * 8 + GHCB_PT_ADDR - 8], eax + mov [(ecx * 8 + GHCB_PT_ADDR - 8) + 4], edx + loop pageTableEntries4kLoop + + ; + ; Clear the encryption bit from the GHCB entry + ; + mov ecx, (GHCB_BASE & 0x1F_FFFF) >> 12 + mov [ecx * 8 + GHCB_PT_ADDR + 4], strict dword 0 + + mov ecx, GHCB_SIZE / 4 + xor eax, eax +clearGhcbMemoryLoop: + mov dword[ecx * 4 + GHCB_BASE - 4], eax + loop clearGhcbMemoryLoop + +SetCr3: ; ; Set CR3 now that the paging structures are available ; diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb b/OvmfPkg/ResetVector/Re= setVector.nasmb index 75cfe16654b1..bfb77e439105 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -53,8 +53,25 @@ %error "This implementation inherently depends on PcdOvmfSecPageTables= Size" %endif =20 + %if (FixedPcdGet32 (PcdOvmfSecGhcbPageTableSize) !=3D 0x1000) + %error "This implementation inherently depends on PcdOvmfSecGhcbPageTa= bleSize" + %endif + + %if (FixedPcdGet32 (PcdOvmfSecGhcbSize) !=3D 0x2000) + %error "This implementation inherently depends on PcdOvmfSecGhcbSize" + %endif + + %if ((FixedPcdGet32 (PcdOvmfSecGhcbBase) >> 21) !=3D \ + ((FixedPcdGet32 (PcdOvmfSecGhcbBase) + FixedPcdGet32 (PcdOvmfSecGhc= bSize) - 1) >> 21)) + %error "This implementation inherently depends on PcdOvmfSecGhcbBase n= ot straddling a 2MB boundary" + %endif + %define PT_ADDR(Offset) (FixedPcdGet32 (PcdOvmfSecPageTablesBase) + (Off= set)) %include "Ia32/Flat32ToFlat64.asm" + + %define GHCB_PT_ADDR (FixedPcdGet32 (PcdOvmfSecGhcbPageTableBase)) + %define GHCB_BASE (FixedPcdGet32 (PcdOvmfSecGhcbBase)) + %define GHCB_SIZE (FixedPcdGet32 (PcdOvmfSecGhcbSize)) %include "Ia32/PageTables64.asm" %endif =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62532): https://edk2.groups.io/g/devel/message/62532 Mute This Topic: https://groups.io/mt/75500010/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62533+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62533+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 159473749839476.13207905907586; Tue, 14 Jul 2020 07:38:18 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id hHJ4YY1788612xAFeadix7oS; Tue, 14 Jul 2020 07:38:17 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web11.21252.1594737490560993734 for ; Tue, 14 Jul 2020 07:38:13 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TZDe9DTapMlB5eqNsuCPRLSGxZSLLI3B541wIdeplZUA9MVgpmmBjbmHfHD3SMTvwochlTP6cotElsjs98edYl8SoMP3osMPPzudKzELKLZPdL7vlKcnIO0H6H7Aqgum0Jrdy06i5GPDMVsF1gAicwUXJA/aBfYxfua0cBI+wmoOUOV/HwTkqE1vY+KUK3HfVOgxpwLMWFNOcOPnblw4XgtbWB07aihE7OMZuCS4/U+okhSevlVp0hKV2S2807jsENHeueTmJmrl/E1IaPD52XX8HHLKach5qjRlT5zka7UpQ+jcR6D+auJe3hZgxJTmD7G+++8Dhl0S/cVD5Q7Vlg== 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=JR+MS9LL61uEdrhA9WIjPAHChgJxbHnfKw/wTMqc9/Y=; b=dVgfBjmWKb8mYNa1yW44T9v59BhWYJh2/OGQlAuB+ChFgnN90s5ooxaM1v3r2z33yKLbEH3cd4mZ9cQpvm0besq7SvyPKygSUMbdce5W2Z6bCIIoAE15ytGSOzEAx6P3sQKxXqR7YoKPkD0g/cmyhHzHzpAqfFiilIDfgCY9fZx3+rtaMaZ9WpMAFPnpn5B7yAT7+wFYC5KfoNO8eazpoH+6K5/8PXNKb1qDOwd3gEiinRjSnDq6vXmqqui1xWa0YicdjzDip53ulIh46ncEQBBNiRW0fhULkTmnfFP+1kLGWiL5LgG2Ztl1PsYDFzsdf6YWsfRhmBpjAxwS6lCFVA== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB4219.namprd12.prod.outlook.com (2603:10b6:5:217::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 14:38:12 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:38:12 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni , Anthony Perard , Julien Grall Subject: [edk2-devel] [PATCH v10 30/46] OvmfPkg/PlatformPei: Reserve GHCB-related areas if S3 is supported Date: Tue, 14 Jul 2020 09:37:37 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 14:38:11 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: cab62eeb-f7f2-4f54-0623-08d828038916 X-MS-TrafficTypeDiagnostic: DM6PR12MB4219: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 4esOwt3b6F0zIxRLn661xkyUK8G6BQxMc6AFmoUYMm6vtM8EJ2w+ybSdRTxCglPSeUzGlwdtmVQO81Qew327PVXDwplBjHFJUBeYwJohetzm/66Quloee0ko398A6RGhecyo7jA6e8lwdRzD6kl0T+aZAQfLPgAOrVddfjkR+FGwBN+/Hum6V4ulX4J6m87x1qqhPyV2+CMxS9Qc3s2Mbwvj/45NmesUm/f7rPF0JQNuBotWwnX+ZIvS2vGJSB1+Hzl4wUksyZGh7Kn6VXQkrWUEcEKYVVbZZQESxRLnsu2HRXgKRYGsYoAQJMOa6fkot8F3wLp83loEqTm5tdgOqIQGs89/aLAs3Kg0OBaEv4Q27mlkZTAl16XX33hYMNTrygVzSnl6pKUVj585gTfTyKTkikHhqZvz/8TLgyHJO8+79oyQID5pq8WWYldlKrFSHLh1DX5qC0QcpFgNFCzmvQ== X-MS-Exchange-AntiSpam-MessageData: qfv+KafpqhcQWrd2cy6exsOaqxJuceDpbKWaYef+d16zqO+7BBtbHPWFkdShv3qPE0/QFsYwmIJ2cjGLZuEtp0EcujyzlGzZMn8zvs1DY5xGuM8+ZfPlxxOa9iLoUFzhEeocpanf94HmksbnVAXj7+4JbBCNEaH8gF9BGH11a7F6K14Bl9enhZD0cCtz+1pnHkxjAklqtE0J5bW0vW2CCwPASzIqmJZgwY60f3WSl5j9h5rUNR0cf6xd7bO/eh+YMmGyZizVhG8gzgGPC88Q606l4rZMhfRCQRiCTJU9cTxMzsiF0lynRW3CjBDCvdzqFiIOFsrWYbTGkRgoS8ghyE4bozZ3al5WdF4w7cnhNcVXUFRo5WnhxAjmsRWt//af2iHfQn6hQphfzQ1o+u2Ru0F8VO9FTKOtmfVXRJi1ptCmCwraw7M14QUwFe9OyowVzF8gBXonDtwDL4TZOLYSVvLrNzvrlO5pYMWgc2e8isU= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: cab62eeb-f7f2-4f54-0623-08d828038916 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:38:12.5169 (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: DfIInvHD+nX89RHSwUZO/22ARKwVYHRqWUy1zcmrNnt7TGp+X3SXRqEi+MgqWJ7mZTDyy6LtLdAx6jIpagkpLQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4219 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: KJ865zfMiEVFdeQIcuRTnb34x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737497; bh=m+xfLDs1BnOAUcYUSKBcT6sHETQQ2Nr7awE6CUINHW8=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=KmM4GhwDwTG9vWMJ9Sy8wZJKMI+EfBRB2eIAWbqZHe5xfin6wYmssTe6Mr9TUWxYxoZ luGCyDmVpOJCJCnzjLPz5hlsCzQnDOcjiR1qranWZC2ma1JdYOV7c/ow4OH3Kn4ihJmGg KrG1jo3kexA2P8XfebUm/f4xs3CFZGJAzvU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Protect the memory used by an SEV-ES guest when S3 is supported. This includes the page table used to break down the 2MB page that contains the GHCB so that it can be marked un-encrypted, as well as the GHCB area. Regarding the lifecycle of the GHCB-related memory areas: PcdOvmfSecGhcbPageTableBase PcdOvmfSecGhcbBase (a) when and how it is initialized after first boot of the VM If SEV-ES is enabled, the GHCB-related areas are initialized during the SEC phase [OvmfPkg/ResetVector/Ia32/PageTables64.asm]. (b) how it is protected from memory allocations during DXE If S3 and SEV-ES are enabled, then InitializeRamRegions() [OvmfPkg/PlatformPei/MemDetect.c] protects the ranges with an AcpiNVS memory allocation HOB, in PEI. If S3 is disabled, then these ranges are not protected. DXE's own page tables are first built while still in PEI (see HandOffToDxeCore() [MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c]). Those tables are located in permanent PEI memory. After CR3 is switched over to them (which occurs before jumping to the DXE core entry point), we don't have to preserve PcdOvmfSecGhcbPageTableBase. PEI switches to GHCB pages in permanent PEI memory and DXE will use these PEI GHCB pages, so we don't have to preserve PcdOvmfSecGhcbBase. (c) how it is protected from the OS If S3 is enabled, then (b) reserves it from the OS too. If S3 is disabled, then the range needs no protection. (d) how it is accessed on the S3 resume path It is rewritten same as in (a), which is fine because (b) reserved it. (e) how it is accessed on the warm reset path It is rewritten same as in (a). Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Anthony Perard Cc: Julien Grall Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/PlatformPei/PlatformPei.inf | 4 ++++ OvmfPkg/PlatformPei/MemDetect.c | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index 00feb96c9308..a54d10ba90d5 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -75,6 +75,10 @@ [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageSize gUefiOvmfPkgTokenSpaceGuid.PcdGuidedExtractHandlerTableSize diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetec= t.c index 3b46ea431ade..6b5fee166b5d 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -27,6 +27,7 @@ Module Name: #include #include #include +#include #include #include #include @@ -866,6 +867,28 @@ InitializeRamRegions ( (UINT64)(UINTN) PcdGet32 (PcdOvmfSecPageTablesSize), EfiACPIMemoryNVS ); + + if (MemEncryptSevEsIsEnabled ()) { + // + // If SEV-ES is enabled, reserve the GHCB-related memory area. This + // includes the extra page table used to break down the 2MB page + // mapping into 4KB page entries where the GHCB resides and the + // GHCB area itself. + // + // Since this memory range will be used by the Reset Vector on S3 + // resume, it must be reserved as ACPI NVS. + // + BuildMemoryAllocationHob ( + (EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfSecGhcbPageTableBas= e), + (UINT64)(UINTN) PcdGet32 (PcdOvmfSecGhcbPageTableSize), + EfiACPIMemoryNVS + ); + BuildMemoryAllocationHob ( + (EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfSecGhcbBase), + (UINT64)(UINTN) PcdGet32 (PcdOvmfSecGhcbSize), + EfiACPIMemoryNVS + ); + } #endif } =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62533): https://edk2.groups.io/g/devel/message/62533 Mute This Topic: https://groups.io/mt/75500011/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62534+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62534+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 159473749786682.59562365734757; Tue, 14 Jul 2020 07:38:17 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Gr96YY1788612x7cb7jMp9Kn; Tue, 14 Jul 2020 07:38:17 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.65]) by mx.groups.io with SMTP id smtpd.web12.21047.1594737494692983989 for ; Tue, 14 Jul 2020 07:38:14 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=byf2lY527qJjiDSNkIHIqrrFqedElHsjmTPkUt3f+iWpO4xByLwwcnvpjfhWr1SgulIRU3DTNPutnLHiiQGMfYxxHHQ2/hYNaEb1SFjulOrydSVEm/aHjyWTcB9HSuhjN9aH5e3RY+MTOI9RMVgnDCFUxCqzQtszPDg+4h0NqU+oMKSV+ImKlxwngyZLMv9f29L46+hTxJtBtBQGCBeOxXPVLYaNX+aAUaCwG4sG5TuV4yYqPc1g3WW3Ao9irHUtXd7SWEWsYqNhBG+uL1dPrc106XpoyyPm2uyiV+F57Zf0XIwGmxoy+PMA1mFFlq76yvijLlp2eKlprmhbzIeZDQ== 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=9H9lpHwTEQm1Mr7PGRVCwa2vJ+MenFhwPSQ15HaL2l8=; b=L+e40Dw0Qme94si5dLKouUsIk66Nr53cbB3DwTrkKl7Dw2WqQDO8Z3CMuzx/tt4P0bNfDP14SsUnwLbs/zsqU1+USkGJc/hYGhX5ARgAK1VZ9dfJIB+migRLvOA5aVzYoHQ/XL5ywSemWxs0/NUMdgafR0j20RL/SwOyY5pwFmQWrsMdn+cxUC6VlYGi1B1FzQ9wElQQjOqbHrguKAGsto7wxgZanv+m1bks1QozEq7wp8x0SI256shcDeflhhoPcheMvwBJBeberDyWGUDAMGrQ0EbrAojAbq72ZKEaCbI7bvsiOCxVaBBVpWQwjn1I3IXobT/DMFgU/HiK3XsXMQ== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB4219.namprd12.prod.outlook.com (2603:10b6:5:217::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 14:38:13 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:38:13 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 31/46] OvmfPkg: Create GHCB pages for use during Pei and Dxe phase Date: Tue, 14 Jul 2020 09:37:38 -0500 Message-ID: <36a971361c8336892362e047c5b45b87293576f6.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 14:38:12 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: fe0bc470-2b7b-452c-2850-08d8280389a6 X-MS-TrafficTypeDiagnostic: DM6PR12MB4219: 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-Message-Info: yIjUBZbeb0ItY8+1koNg4kK9sYbTRy51Dfd1i8zdKFrdbtFX4oRTL5gT7f27F2irYflMRFXzrtMYk97eHOLpCsH5tyRjKVN44EwE3DJYmGfUbhiMCcDOlW7IsuNlA8PycZxcwZJDuoqK4jbt7uM+CqdLKgtl8S59GEFwjSu1SHA3zn0ZCRHxVd9yJBM2oHQUTJnVk+nFKf9oKK3obBPrt92+rInJZnBq2rezERdMlgy1YgZ6J/4b7/CA0FrmbB8ds8/WeJJG1hNkumypKkLtfCtSgqXi2DDyBICqKXCI72hoNyqzMVAwcfSu94En+oezX/W4JM7NtU5jaH0dFdjmieQgkcd+zPYpWGPnsdWt89VopA3a+mNomf0ov+u1yUZJXE13qDHL9kCfUZZH4MV1usNg0D0rge/HZn14deV24wZGQ7LpvrSbW15aHuqYUGnbv7T0diVarOindfyRs1g6dw== X-MS-Exchange-AntiSpam-MessageData: +dyaEaBXyGrovawMNcdPyZJ+eb4T7p0DkWownHcXgskCnwUN7LJR8gaQqaGbkpZM6fKzE3nQufpEuw7cMidcYuuNecSyftSQqLKr1tR/aedh2rIEiPMCOCkO4AcJaryr0v+T/o/Bt7fMUNF7T0BwAVpnwBDn4v4t0aS94a/WJcocBbaSi3zOcuI2+rN3QijULRQrbVNVqhNtK76UB4iqVvbX7TP7tVGBysw7dvNJCmAt/tc4aFOOsAVqxEFXYV1cYOQNzUnykQNZ7bR9Dk4+diKP01rHPxTGgv+xpu5tk/V4RzpG+8dSbDDt13MjmeCzygaghJawxayzW84mK4PGoU3TyYxvy97ixlOWE88WNMWNw/FSQfThLQJGMu9oYy69lz4wjXaD6HqYToGkWBWCoZ8NkOsjkZjUuaynTrECMllrLq0gTEGB9cvmtPO4b07gFoJAKEePWyIxG9E4HHSjHe127lIxMYEp6HJFsaCuKng= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: fe0bc470-2b7b-452c-2850-08d8280389a6 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:38:13.5024 (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: RX5GdomOrKcIr89JkO9QVu0WG3MsRGvwKg68DDPxP975WVcBFrDedg2bupfLvjau8JzAMuI0jTXHC9Z/mbYuTg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4219 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: 8RW5r2TaL9MKev3q4bfOs5cex1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737497; bh=7+CMiYhDXxMEkwvg4Ov+gR36XMYBPZVK7xrEvaeSi7k=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=SU43Y7jGFiVrF9GeK/AwK135VlC+5cUKCT6td0JpurdwxojXECWJ43Fa5+6854Gr4wM pV5RkpYgNJ7/8OiIS0Xv8+QJiZOCsyJ8IYCtO8hpoU9QjlMZ25rmPWhDlPZuxZmhKTG6T LjUSLBkhsS/9Hqhk6GdsZPg4egRCBos8wYk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Allocate memory for the GHCB pages and the per-CPU variable pages during SEV initialization for use during Pei and Dxe phases. The GHCB page(s) must be shared pages, so clear the encryption mask from the current page table entries. Upon successful allocation, set the GHCB PCDs (PcdGhcbBase and PcdGhcbSize). The per-CPU variable page needs to be unique per AP. Using the page after the GHCB ensures that it is unique per AP. Only the GHCB page is marked as shared, keeping the per-CPU variable page encyrpted. The same logic is used in DXE using CreateIdentityMappingPageTables() before switching to the DXE pagetables. The GHCB pages (one per vCPU) will be used by the PEI and DXE #VC exception handlers. The #VC exception handler will fill in the necessary fields of the GHCB and exit to the hypervisor using the VMGEXIT instruction. The hypervisor then accesses the GHCB associated with the vCPU in order to perform the requested function. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/OvmfPkgIa32.dsc | 2 ++ OvmfPkg/OvmfPkgIa32X64.dsc | 2 ++ OvmfPkg/OvmfPkgX64.dsc | 2 ++ OvmfPkg/PlatformPei/PlatformPei.inf | 2 ++ OvmfPkg/PlatformPei/AmdSev.c | 45 ++++++++++++++++++++++++++++- 5 files changed, 52 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 494b67c5c073..0090cc10ab01 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -607,6 +607,8 @@ [PcdsDynamicDefault] gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask|0x0 =20 # Set SEV-ES defaults + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase|0 + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize|0 gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|0 =20 !if $(SMM_REQUIRE) =3D=3D TRUE diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 14ecfb24912d..84d91e2ccb91 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -619,6 +619,8 @@ [PcdsDynamicDefault] gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask|0x0 =20 # Set SEV-ES defaults + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase|0 + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize|0 gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|0 =20 !if $(SMM_REQUIRE) =3D=3D TRUE diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index ec11ec914556..da37f767fc47 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -617,6 +617,8 @@ [PcdsDynamicDefault] gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask|0x0 =20 # Set SEV-ES defaults + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase|0 + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize|0 gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|0 =20 !if $(SMM_REQUIRE) =3D=3D TRUE diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index a54d10ba90d5..4742e1bdf42b 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -102,6 +102,8 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize gEfiSecurityPkgTokenSpaceGuid.PcdOptionRomImageVerificationPolicy gUefiCpuPkgTokenSpaceGuid.PcdCpuLocalApicBaseAddress gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index 4dc5340caa7a..4fd4534cabea 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -10,12 +10,15 @@ // The package level header files this module uses // #include +#include #include #include #include +#include #include #include #include +#include #include #include =20 @@ -32,7 +35,10 @@ AmdSevEsInitialize ( VOID ) { - RETURN_STATUS PcdStatus; + VOID *GhcbBase; + PHYSICAL_ADDRESS GhcbBasePa; + UINTN GhcbPageCount, PageCount; + RETURN_STATUS PcdStatus, DecryptStatus; =20 if (!MemEncryptSevEsIsEnabled ()) { return; @@ -40,6 +46,43 @@ AmdSevEsInitialize ( =20 PcdStatus =3D PcdSetBoolS (PcdSevEsIsEnabled, TRUE); ASSERT_RETURN_ERROR (PcdStatus); + + // + // Allocate GHCB and per-CPU variable pages. + // + GhcbPageCount =3D mMaxCpuCount * 2; + GhcbBase =3D AllocatePages (GhcbPageCount); + ASSERT (GhcbBase !=3D NULL); + + GhcbBasePa =3D (PHYSICAL_ADDRESS)(UINTN) GhcbBase; + + // + // Each vCPU gets two consecutive pages, the first is the GHCB and the + // second is the per-CPU variable page. Loop through the allocation and + // only clear the encryption mask for the GHCB pages. + // + for (PageCount =3D 0; PageCount < GhcbPageCount; PageCount +=3D 2) { + DecryptStatus =3D MemEncryptSevClearPageEncMask ( + 0, + GhcbBasePa + EFI_PAGES_TO_SIZE (PageCount), + 1, + TRUE + ); + ASSERT_RETURN_ERROR (DecryptStatus); + } + + ZeroMem (GhcbBase, EFI_PAGES_TO_SIZE (GhcbPageCount)); + + PcdStatus =3D PcdSet64S (PcdGhcbBase, GhcbBasePa); + ASSERT_RETURN_ERROR (PcdStatus); + PcdStatus =3D PcdSet64S (PcdGhcbSize, EFI_PAGES_TO_SIZE (GhcbPageCount)); + ASSERT_RETURN_ERROR (PcdStatus); + + DEBUG ((DEBUG_INFO, + "SEV-ES is enabled, %lu GHCB pages allocated starting at 0x%p\n", + (UINT64)GhcbPageCount, GhcbBase)); + + AsmWriteMsr64 (MSR_SEV_ES_GHCB, GhcbBasePa); } =20 /** --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62534): https://edk2.groups.io/g/devel/message/62534 Mute This Topic: https://groups.io/mt/75500013/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62535+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62535+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594737499207209.54809516397427; Tue, 14 Jul 2020 07:38:19 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id NKEbYY1788612xKMPlGf9WRg; Tue, 14 Jul 2020 07:38:18 -0700 X-Received: from NAM04-CO1-obe.outbound.protection.outlook.com (NAM04-CO1-obe.outbound.protection.outlook.com [40.107.69.79]) by mx.groups.io with SMTP id smtpd.web10.21266.1594737497164468311 for ; Tue, 14 Jul 2020 07:38:17 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XAdHPvuTdF8t+qFQI+CxPV64ma/7IGk9OHtRHSRVJhKikN6q+X9a+ILPOiJyrnE8fxmoVQ2kRZ5zO53Z8zEY+rQhYfPFTnK/VIOFH450KAhN5N+IPRySlHp8Jg1xUH/45PHbz3BrtPBaYsPRHbKNBjFt/mPzWyciejh8MVofaZbaNEt5jlK7mvZCVnpe4XizKTTrGcRiWDhvBya6K2+yvOD/OCB/miO7aKAfzrSV48MRY89QXZmjqleA2kvfQSsw3oX1T/rL4T837w/uD9+a0ipslBK88VGUdJPbNAfXx9/PMDjp6aUk0Dh/W6bZ/ChiwbMhERqpNajKDBdWy0vG6w== 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=LKE7+qHjsZIcvRUcMZufAvxligKtvF8CIKEGq/A8VMQ=; b=auoqU4kqTA2R2M8fApP+jFKCY2Eg34TJT3arPpqrZyDHg3lBfpGBF/GSAmlqYv7cx5LHGf3TvbEmPOnMlyiGdtVaaNJnYcrY5+zC51NyPMKGvlU38pvshno7MLkSQZuE31SKcQOk8vhnbld3TrWA61RJe+Q9/rUHK/16BrsEqIMaGDP5JxUfwLbunGWvg/aiZEeuct2kj7yoVdoMM4FbJ0o1pkfilGFQBfSzQg5gAGZTn/0obbhCVUIF55JU6DGKtt4eAuOg0XuSUW3HTDA+Sc3C+dSvPFqmjZMa/pLrkP6fyBoGkIs6fzekG/9sCPl9KjbV9EXoLfDVChz66zCr+g== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB4219.namprd12.prod.outlook.com (2603:10b6:5:217::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 14:38:14 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:38:14 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 32/46] OvmfPkg/PlatformPei: Move early GDT into ram when SEV-ES is enabled Date: Tue, 14 Jul 2020 09:37:39 -0500 Message-ID: <3d74eb72b996226fc2faeddbd33506691d5c680a.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 14:38:13 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 8449699e-e0f3-4dca-a9df-08d828038a37 X-MS-TrafficTypeDiagnostic: DM6PR12MB4219: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: fE02PkcBhYnu+dge3e1dUL70UjJW16RXAz1sdg5s/GowCUYb71Xd4Fz+MJyUPKcqv3TnjTvvZe+aqeGIBVYR42+FEp0UbT1cy1V+uytYKweQrQ/EYAgs9toMylebRz0GhJU2KlnWycHrbxzUkICrvqNY17avEYONzDEei32Su/kJVQxj2ZA+iUp2X4U7DTRB8lzE29xdLvIuIc60TQ92uodzE1cHXCLoKpw3pG/RhOWne3du6bZ3cxpNBPjZc4319xS+5xZXxQ/f2eDruh7q2hb0/TJJNyeX8J2f3iWV5h+Nw6ZlAgE9LGOE7DrDDfZ0/hXrBooNlzNLPK1DWZe6YOgvRm0uHV19QkdYk5ALFXVayiycFfdCH8HNBPw/iNJZUsGH6J926nO6zDFRJTaCLCvGvtzfVJHlVW90rXzKtJnxrdWWHYYuPn+QajEPPCftOHNs8D9ambyJK3zGqqP+ag== X-MS-Exchange-AntiSpam-MessageData: OW9/Aqmz4EIvcwbxdY3XDGhJks3u2NNroxBJgD+6s9iPag8fgFVksGoqkCHqL9uD1j8fxc9u6kMzURUdWo3prq6S0+XhiAjW/3h+rzwuV14/LZOZacxFLbcI363B9EZ7+J/7dCpy0SnLjJFuGzKYf6c7YDGw0A7EoMvWk5BdGFHA0B+HAAG4ZPk6siR4IhgxZ2NIUoJ7r2hCpBpIyTOmtPdoDN2VNrBe3otEKEGMbmY+tEeM2/RWg3yFCcZY05/VXjd+9si2kGRgh1HfTGwN05WMTJDj1IazIy4bu+LDkZyJsD+XnTNQLmfmktDtxg6d8rUT8Nh//l5qCRqxr9jMGw/NtpaxFTRhM9ibylXklbjoIXT3o2JWHFGxzzXM9D4ECmXtigQhJjxTbCA2URVu8WlYScT1sHsguVhqFe+dxlP2ebojdrjNFaoyPpZaEcYbGCl7GS3+u8sK2srGy7NDUOMqtMv4QtUQBBL/qqEbA6M= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8449699e-e0f3-4dca-a9df-08d828038a37 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:38:14.5340 (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: WW6So6xodNie6/V9+cUZvgySvHK1/8DP4baBX7dtHumq1BceKZ1SGDiqTU+zJNqA222kAVQQjuU83kJYSQztBA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4219 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: U40MXcDjdqqpsy0kX79ImOfCx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737498; bh=9G0xk1fdFK0ceebOBLo+CXrw0iybbLHnOqZVtz1paWM=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=EHp6KTeHSZwV2rDhH7MIgSAfat85TZiRIO4o5b+638O7zB7YP4woNRpJuecQ4nYht/j uodByQiL7QzKC0CL9W6qGHT32EvhTnutaDwMaOJBln/aBDmtG+8uWijys+A+M00L3FbCH bGTmVXfiitl6ICuawfZYjrNz0+fJC3g2exA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 The SEV support will clear the C-bit from non-RAM areas. The early GDT lives in a non-RAM area, so when an exception occurs (like a #VC) the GDT will be read as un-encrypted even though it is encrypted. This will result in a failure to be able to handle the exception. Move the GDT into RAM so it can be accessed without error when running as an SEV-ES guest. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/PlatformPei/AmdSev.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index 4fd4534cabea..a2b38c591236 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -39,6 +39,8 @@ AmdSevEsInitialize ( PHYSICAL_ADDRESS GhcbBasePa; UINTN GhcbPageCount, PageCount; RETURN_STATUS PcdStatus, DecryptStatus; + IA32_DESCRIPTOR Gdtr; + VOID *Gdt; =20 if (!MemEncryptSevEsIsEnabled ()) { return; @@ -83,6 +85,22 @@ AmdSevEsInitialize ( (UINT64)GhcbPageCount, GhcbBase)); =20 AsmWriteMsr64 (MSR_SEV_ES_GHCB, GhcbBasePa); + + // + // The SEV support will clear the C-bit from non-RAM areas. The early G= DT + // lives in a non-RAM area, so when an exception occurs (like a #VC) the= GDT + // will be read as un-encrypted even though it was created before the C-= bit + // was cleared (encrypted). This will result in a failure to be able to + // handle the exception. + // + AsmReadGdtr (&Gdtr); + + Gdt =3D AllocatePages (EFI_SIZE_TO_PAGES ((UINTN) Gdtr.Limit + 1)); + ASSERT (Gdt !=3D NULL); + + CopyMem (Gdt, (VOID *) Gdtr.Base, Gdtr.Limit + 1); + Gdtr.Base =3D (UINTN) Gdt; + AsmWriteGdtr (&Gdtr); } =20 /** --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62535): https://edk2.groups.io/g/devel/message/62535 Mute This Topic: https://groups.io/mt/75500015/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62536+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62536+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594737499594468.07691473791533; Tue, 14 Jul 2020 07:38:19 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id y7RNYY1788612xqmGRp2ppd4; Tue, 14 Jul 2020 07:38:19 -0700 X-Received: from NAM04-CO1-obe.outbound.protection.outlook.com (NAM04-CO1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web10.21266.1594737497164468311 for ; Tue, 14 Jul 2020 07:38:17 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MRDlZ5CC0NMOdpCHqh8hEDepX3297Ga+EMCoxW2U5ZbWP9eURVGzLNXKwhJJnTYA56fpUZC25wJ479bBe8cXYQ2CM0hKbY8AOZgLFdshe0XWD3JSJezqFGu59cqjVo0G4r+VpM8bUdLTyDyyWBHW+CC6pHMz81XtqrEVQEUR0fqGD2ajh+uNGcazNG68I9yGhRFSVw3plTrC1sPCWu7tP2vFbKsNNRP+IU1LlUc/cxkR13EMtn+RSxLHi6tFGy6xNcMafiTxYN3ELkLX4415knkeJrTEIGcGZ7y94g0j+/5LOMUFAjDEUKqLh4e9auSLdoGnFBhcfpXBrHmJEOmEAg== 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=RmbqkIxYiPPEKoCZtNux7cvM35+H6P1bYXxGk/GrTms=; b=mkPOar+Z9KLgPK3Yc8pPe2BWiBTj+cztnG0VDJ2k4DqpsGEsUtXKz0tXVnH5w1zUFr027ZiI+00lowk7CN23hsCT593K15nYzPR5BcEKpa26JlBJS5lVtDbD6jEsnxpIT2SX0gSbqhR5fcIvlBWEP3ruaXf5ZRJwaSs07j3tAurGOcG40xPbPiuvxC9d1AKiUmFp0lFFJzVy8X3RLMEtvB9V7gvoghdc43widRzx2BcRYbb0tmACkKyFhkC12bHPELo6VdDmzukWuUipw3oq3xrj6AX87et2MYdpaa2dUelR5+4Ut/CvgMXBE1mN8OSZrme8u5A2VGE705hZRRS+Mw== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB4219.namprd12.prod.outlook.com (2603:10b6:5:217::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 14:38:16 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:38:15 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 33/46] UefiCpuPkg: Create an SEV-ES workarea PCD Date: Tue, 14 Jul 2020 09:37:40 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 14:38:14 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d79edc05-7608-4ac9-b149-08d828038adc X-MS-TrafficTypeDiagnostic: DM6PR12MB4219: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 4zWXndBAmzeuWBVWY1rtE2brr5UTTRgaEEbJqFSmLNKbRU5X/WEIBRNGomz7EiUeoH6AJiRp5Meuacx9DQ29bAU/h91ypZtWGujMddLKBfcvPfWWRqSUL6rZ3gBSr9gTHyl3cnlKiO67pLT7oHlRbsZ+TZan2IDj3P5Ku45OZ/hwCXO63w//VhmRFHayeRUCXujJqNvhxSlPqjp10UB7YhopyTTHHyHIoPUBGNk3kG+Zh3OB9k/1LVrpGLxm1V56rcpdnOZmTOtGY5Ulpvm8B/sZa1hjj6b4mCFAqMxU9KPsJqZ9dJZQIDM7dl/ZrtXkfLUe/pC9ZeRWPY32VBMrhrqYwiR25rVUh0nq/FvTTMKnYxW9q3tOdTv95Dr0YpZacLGYDssmy6AEs4hYhoc8sgTJGPTWTgHSPkYsFaAqh5QBNL3kc+8av1fo8EWXAPVDLjTsOSY9dFYKszkH3Cz4UQ== X-MS-Exchange-AntiSpam-MessageData: EV8lyjbtXwVkV6LlMBE40Ws4hCDRfgBVTpJ9KeJ83TKdBzY4j/8wUhRkbz7Elu2bqCF5vXBNkci/L2ck7bOX8rbzbcDoYWjLkHCFs1bo8hgTsiYv5y8yjbXYMhQ3axAD73EzZAV1PnPaNU+FwtyTny6OjK9IVsrroiLycsGD4Z7vMuhppzhp8nmkAB4PclkKEOI2PdQgHVG73F6re3ZgoYu9WaFr7lz71Hw3B/Nq9341DzyoixilP5/Hjs+mV8qQPmVkuytehyY+wb+aQEaMgtf19dAr33w1EyyJmmtxdYPzB04wS/Tit4XRrQ3OloHbl7vu9OOA3AlgJtKAlh18rum+bVPTu+9xqmH6ta4Lwcxe9PbY2/E5giXUNIFghvsdZvY8e0sTIROnMtv4wpLijH+z0kNUQNFVkhpHRz2pNyOSLxrppVTAsJST7R4ehXIgKNEZrwDBZ6rgSWY9Vk55Ftfo8L7TyYlUvEeazYuQ2+0= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d79edc05-7608-4ac9-b149-08d828038adc X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:38:15.5775 (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: bkk6FDhEKbLDBlHidWIE3tWyIlJU8LiKSw5F8cs1Q7F+cT6n+sYfyFttEmIN0PZySWlMRbPCFdNpWSLgk4ddBA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4219 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: LjyXrcDKTmPJAZJnkkg36DPMx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737499; bh=DDiabhjq47zboNPBhX6G51pGMVao7CoUygUpNW/Igdc=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=qN/XTP4onk+wqA574wXzEaUaRmnNOqdQKPFvqsbtq+PZ1J6JzIj3Di3lIGco+6ibK6I VcxXLROI/yS6lx6XKr58TeVd7OPRZGxK1H765606oiPZ7jEbyK48dgsS3VNei8dgUXXJy dGq7oih9u0qqL81o2wL1hwa4B4tYbON0QCk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Create an SEV-ES workarea PCD. This PCD will be used for BSP communication during SEC and for AP startup during PEI and DXE phases, the latter is the reason for creating it in the UefiCpuPkg. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Reviewed-by: Eric Dong Signed-off-by: Tom Lendacky --- UefiCpuPkg/UefiCpuPkg.dec | 8 ++++++++ UefiCpuPkg/UefiCpuPkg.uni | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index cb92f34b6f55..8c614f9b42bd 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -161,6 +161,14 @@ [PcdsFixedAtBuild] # @Prompt Specify the count of pre allocated SMM MP tokens per chunk. gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmMpTokenCountPerChunk|64|UINT32|0x3000= 2002 =20 + ## Area of memory where the SEV-ES work area block lives. + # @Prompt Configure the SEV-ES work area base + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase|0x0|UINT32|0x30002005 + + ## Size of teh area of memory where the SEV-ES work area block lives. + # @Prompt Configure the SEV-ES work area base + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaSize|0x0|UINT32|0x30002006 + [PcdsFixedAtBuild, PcdsPatchableInModule] ## This value is the CPU Local APIC base address, which aligns the addre= ss on a 4-KByte boundary. # @Prompt Configure base address of CPU Local APIC diff --git a/UefiCpuPkg/UefiCpuPkg.uni b/UefiCpuPkg/UefiCpuPkg.uni index f4a0c72f6293..219c1963bf08 100644 --- a/UefiCpuPkg/UefiCpuPkg.uni +++ b/UefiCpuPkg/UefiCpuPkg.uni @@ -281,3 +281,11 @@ =20 #string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsIsEnabled_PROMPT #language = en-US "Specifies whether SEV-ES is enabled" #string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsIsEnabled_HELP #language = en-US "Set to TRUE when running as an SEV-ES guest, FALSE otherwise." + +#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsWorkAreaBase_PROMPT #langua= ge en-US "Specify the address of the SEV-ES work area" + +#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsWorkAreaBase_HELP #langua= ge en-US "Specifies the address of the work area used by an SEV-ES guest." + +#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsWorkAreaSize_PROMPT #langua= ge en-US "Specify the size of the SEV-ES work area" + +#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsWorkAreaSize_HELP #langua= ge en-US "Specifies the size of the work area used by an SEV-ES guest." --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62536): https://edk2.groups.io/g/devel/message/62536 Mute This Topic: https://groups.io/mt/75500016/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62537+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62537+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594737500012994.1846361322348; Tue, 14 Jul 2020 07:38:20 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id L0iNYY1788612xqx3Vjb0vXO; Tue, 14 Jul 2020 07:38:19 -0700 X-Received: from NAM04-CO1-obe.outbound.protection.outlook.com (NAM04-CO1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web10.21266.1594737497164468311 for ; Tue, 14 Jul 2020 07:38:18 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dkQnRyRdPmi1p2YudXL1NcbiaOjZbhN6shuGzj8Eu0KNGFO4++RHBXhaAv0n/mLsELgTOjPgZcHgvEMtUSV/USocm6JA+W6LWl9t7K7eph+dM+idzeVkXZ5EIKR6d/iTC5kK0Jt+VEmatX6zNpVQhEI39/UjmuZ2zbiArJgEH1sKW3tTDwiv231RmThzWM0NdGxzDygtYpQ/8ponNwPcyHCquuy5FAQxs7IzVCkCvtETCMtYkLXN2g1U2CTlvp3bsNQrYgYUtMAh0Oihuo5PKzFNShGSheTJrTF9KZk7amUu1PLMCZfPga1m/bWHLpkAs8QoQzAEZ61Y0GvA/UZ6Tw== 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=SpCA+LlmwRtqIOCvR5uY1p6ubmClF6u8O79Ox8zcOuc=; b=Ee2/BLL0OECwqRuBfJ6yfGqkBwERKn2YaGmQQZpWU7FqD0Rc53rjgrS40mHmkXAiI1d5kWc593otYOlgnjuPTRNr8dUzdfZDzlZyKt1mSLZGAqpkosyMtzsqjeeT8q/wjOJcTjgGdsCupurVZLls2KXHcaVZcpl9ih/NgKRQ73oW2D+umvWgCi/a8j/aTWxYYzlVod6KuAoHSaVNUy7vbw6dbjd+Tv7soaIHoSHMgzHgSxOKKeNlm567AX9G1269pHQcBVK+OmPvh/+KBR83cYDwQOVCNBKpXFgPyN4C8otXKhkvSvOosI9NoaLeuPkUl6zcy1hOz5ixfS+PyGxt5A== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB4219.namprd12.prod.outlook.com (2603:10b6:5:217::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 14:38:16 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:38:16 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 34/46] OvmfPkg: Reserve a page in memory for the SEV-ES usage Date: Tue, 14 Jul 2020 09:37:41 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 14:38:15 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 824bed06-86ed-43db-ca01-08d828038b82 X-MS-TrafficTypeDiagnostic: DM6PR12MB4219: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: OQ8u4knq/ZCD6KlcNsrMJIc2OLEMxrjvr+OEbT50crIIKh24oulCFGf53O24GUHnaikzEUrEktm2fqObEbl+3dKjIefd6CGsF2KU3JHJOFu2OHc6tZTZq32Ghd/b4+qU7AgEnm0IhbnLKDipQPXFUduHzhX1LfIHnY/OV3fsuvzcy5iMZRAYeQXqFrM5m5SPlfTnmLq2dwLZp4ogaihKzCNjOhACL06wuBxXKJ7/6k5yo/3a/ey5sLF2kkEMuRidAn1lnFRpaZnZLXkmg6HiTd4fmpHkxVI342PUsCOaanGxPGGjwEmW8UfI72Kkk2owcnFn2c4+qwpQyPUYcbLvK/JcUC1WMGpgBoHpYJK6VMwOSITRIeILN7ofw+5y0HAngrxZeLwx2xHPfp0xIxkyyVDmAACiJKtuQe6SNyYxxyP2OOaDijUN+EhO13s+JApp/c/FVOTSfehac1FpBdDiGg== X-MS-Exchange-AntiSpam-MessageData: hHQPIPQxIbCQPgpA/kLDpUR9VveDmOTz1zwfawyojkYRKhNVD/bc21QyJSrjZ7JOzep59HPD5YPK50xYkWprseO2EXVrKeULOlO4WTq7Aep2v3EHBfWfrKWaqB20nyAa2Y3GCHxYEyNiLVFJwAp+0o2BCvPR44zNzSbKvQMqjMhyiOwfMajVI0G3oxWHcw8NHKuUbc/J/Pqf8FyvYDD3UhQzjAdsh0iI9JWbereRv6EJ4ugxmmQ0YpK+PigjXoQ7I2WFykWgmOqcRJ9gJAu+j9qAcNkIzFWL139wZ8xNKRDyMLEN2FAVRxrEuOQhNPriuT0T3l761FafQAvK6LAPhYunc1uj1XsvVYgcnzbvUGThGjULLTc9dTNfKX8r3yxVUXXUKdD9osR4GbDXrxe7q+f33jDp+BO+rPvDb7CXDzoItVJaqE21h+nrOgL1scOCp0tpUQ5JCxkN/laeYw2k7K9omPY3hBaYJaazY9eQi+k= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 824bed06-86ed-43db-ca01-08d828038b82 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:38:16.6231 (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: TH1VTn1aM3uTWZ+QRtLdjrtzNr49zvk+WExNIEaShvsiNIQnpkZSd8OcdLXFefxYWkFZ/06xQE0GJSPApuhizg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4219 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: KHpgYcs7e65B0KYmwutKEP03x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737499; bh=l6GsV9V4FIlGzl9Q/UUgStrBhKpgMpJWSV3i68VMhuA=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=f3p586vJI0SKYOC2ltXP/qUiRGn/RVwd7xDdbLcq8Z/1CkDfmPdGpHmyT8Ceg8vxAZH Z7cptbhrBs5AtAncdMv4zskElsHJ16BrNfG55I4y7h/oHU0qZ3p5DMgUfAOkUzKyAkv/K Ub2jpelspLdz2le6m4y7o0QPwm//a4GTyeE= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Reserve a fixed area of memory for SEV-ES use and set a fixed PCD, PcdSevEsWorkAreaBase, to this value. This area will be used by SEV-ES support for two purposes: 1. Communicating the SEV-ES status during BSP boot to SEC: Using a byte of memory from the page, the BSP reset vector code can communicate the SEV-ES status to SEC for use before exception handling can be enabled in SEC. After SEC, this field is no longer valid and the standard way of determine if SEV-ES is active should be used. 2. Establishing an area of memory for AP boot support: A hypervisor is not allowed to update an SEV-ES guest's register state, so when booting an SEV-ES guest AP, the hypervisor is not allowed to set the RIP to the guest requested value. Instead an SEV-ES AP must be re-directed from within the guest to the actual requested staring location as specified in the INIT-SIPI-SIPI sequence. Use this memory for reset vector code that can be programmed to have the AP jump to the desired RIP location after starting the AP. This is required for only the very first AP reset. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/OvmfPkgX64.fdf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf index 88b1e880e603..8836b30a0cef 100644 --- a/OvmfPkg/OvmfPkgX64.fdf +++ b/OvmfPkg/OvmfPkgX64.fdf @@ -82,6 +82,9 @@ [FD.MEMFD] 0x009000|0x002000 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase|gUefiOvmfPkgTokenSpaceGuid.P= cdOvmfSecGhcbSize =20 +0x00B000|0x001000 +gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase|gUefiCpuPkgTokenSpaceGuid.P= cdSevEsWorkAreaSize + 0x010000|0x010000 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase|gUefiOvmfPkgTokenSpace= Guid.PcdOvmfSecPeiTempRamSize =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62537): https://edk2.groups.io/g/devel/message/62537 Mute This Topic: https://groups.io/mt/75500017/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62538+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62538+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594737500677608.9632294978372; Tue, 14 Jul 2020 07:38:20 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id XH7tYY1788612xL6Aaub6TvQ; Tue, 14 Jul 2020 07:38:20 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.84]) by mx.groups.io with SMTP id smtpd.web12.21050.1594737498874057781 for ; Tue, 14 Jul 2020 07:38:19 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S+jhBlpWsQZt5JCwisIbZ8nmsmipDDMPWAMTX9OYknB92j6YyCRTXe6cK+aw96itwgvGxcsOBBMna3cf9LqzPMFUj4qBSIyO8YRZjA0aBzGl56JRu+4YocN4rv79wMgxEhawA291/fjmSsJadOuMlirba/VeNmziBQR3t3Mfea2uOvspppg6WGx99Xd+FkCDc+O4xZ+ss9ToSe2SfvNWBa6WVvRqVrffkuDmuU86xmq7NYE1TAnaszkyBGfbRFBjX7nspIZRAi9jxLnOuOY0uc+SLJjX1kdFlJj7gKbT0/TCGzrSvxlD0yoUL5ifSa4XXdRqW29HHiG3nqRvBbqRwQ== 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=JkyhLOofvIbow8VdM+XsfKiaUSck6a3v3S8jdpNjfQo=; b=JMMyOUSzLpgKCkP2EJsbCGKWGY0ptEMbl6UsuG9Wkrqk0BxAhdrEXjDn4PNHSR6tguQ5NexzxutMw/bwAjvIwFc8anGAbDlICRId9VEsUU5adVaVRwwOXutnndAB5G2liYogUpy1Jh7OU/82/Ez2qUbGprCttYWzCMxCyeHEaNTFDOEw/l2NKTrAFpPKU/nDo+i2qQb61lC4DfYXJOcbt0rYHQzZubR5FRRzpc987pqJhcf7MEpA+Hv9GC15iY8VaY5S89YtxCzAwy127pc97dyAR08r/koMwec6nEACPhjQFM9tJqhkH3k/Vy5lmo+QJoTbveerNsMOnLLTy8TZKg== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB4219.namprd12.prod.outlook.com (2603:10b6:5:217::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 14:38:17 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:38:17 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni , Anthony Perard , Julien Grall Subject: [edk2-devel] [PATCH v10 35/46] OvmfPkg/PlatformPei: Reserve SEV-ES work area if S3 is supported Date: Tue, 14 Jul 2020 09:37:42 -0500 Message-ID: <1c1874d966a84ac5be778df4ce682dd33821fd49.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 14:38:16 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 2d6f8ab4-dd7f-4098-0144-08d828038c24 X-MS-TrafficTypeDiagnostic: DM6PR12MB4219: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: bzQfgKRpds+n+nbOekdfeduqxjW4MJJDseG7ADH2AHfRvRsidDD8dYuFWdT8krto3AV611qIZE70iDErBux8yxIwitlHrwMszhIjequ0nnp3nDeFXJfBvyiu/RaRrQYHTkAN487NgnMO346OT5W8ahnVKKIVnlQKeQ/V0Afp+7lFbUt0svwCqFm+IcCUnaosKtWbQ9CS01wFzMLI9K9XcLZKBw0QY7KKjUOpt59DRnAPxyfgFWBvZICzLPP2DrKABDWRHCoiZ1XYtp+twORs4bQ99ntA5KMLjyCsr+UtyGGvVyKC7PcblSeBJtpIl0Wud9O4b5SUfKIlkStPpaBCQNK7xCIzLYesp5xhyIE6UrN7aOTykRpRXxBBen9+1/Z2jzv9D1xIV18hzBg2t7ki0vMoKOh3yeFV+QKwyl0DoTR2YFrc6TaxLW5YJ+UDk4W7WaWZicThgMj1SKKUuo5s9Q== X-MS-Exchange-AntiSpam-MessageData: ZQEOGmTkH+YsV34daRhJ+7cWq82pBxsuiehYElct57Fh4Sg29RONe9IF9Jl6PngczQRB3M0N+SHAyDEXecXkVRgWTYqu0BbAosyYp3CCCPQ7g5hv5K2DQZMMOjaimDoi4xQy7z2vlpxQ9KiugmA4nj5j/z2ERcZZAYKamrQWTF5kcim27PtvbvYDL+vh18CxMKwq0qAcBY/VI4s0C7qmzX+ZvuayzyYeaCfLbFvBs3LjGFqD7oxoXNBr5UZQPiLLAaTREW7bEYQbPK/53+rLy37PBz3woBxlpVShTrMgSQofjCoXt2ApNDKgYTJHxKBZmUmZ1Q/uVEV5kxDDAZNFy3fV0cWTh2w+QwGRujksgM6in5+hBhyiaM4aVv+cUTdeYOqQGYLUD9fjEeqiIAO00x+9+K3/uV/vBBknzkSATcpZ2QjTx+FntRGW1IVx3CgXHDeXySwfDpYGaMXTHEA/Dqglvt1bYcygb6YEjc+1qQs= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2d6f8ab4-dd7f-4098-0144-08d828038c24 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:38:17.6876 (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: w71ah+DR4+Yl3wXA48krJQLVOyG3P0YvsCXpx9ZIkTszE3jFio5q/dePKlySSwkm27iE/6s3vvrspw/T4K3IRg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4219 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: iEOiTU2KuMY0WrEkeClM0G7fx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737500; bh=lHuu6GaP4Sctgc3ysXaYxvyX/k3Io5ejV/P9eYNrUNU=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=PZlR3Z4VgJOPApuj4qG20V7T7KqxzVeG3KpcIA2jIl3N3Id8M3vGkjd2stI+P6dnoo2 LU31tB1u4UkjOBeEPAvffIiWTEwQTteS1xB2bxwAsD2SWGZRknbvdnEyrRt/YOCNiYbi7 ite7YehyXMRadwDTvLwh4+TcFdglipDvjr8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Protect the SEV-ES work area memory used by an SEV-ES guest. Regarding the lifecycle of the SEV-ES memory area: PcdSevEsWorkArea (a) when and how it is initialized after first boot of the VM If SEV-ES is enabled, the SEV-ES area is initialized during the SEC phase [OvmfPkg/ResetVector/Ia32/PageTables64.asm]. (b) how it is protected from memory allocations during DXE If SEV-ES is enabled, then InitializeRamRegions() [OvmfPkg/PlatformPei/MemDetect.c] protects the ranges with either an AcpiNVS (S3 enabled) or BootServicesData (S3 disabled) memory allocation HOB, in PEI. (c) how it is protected from the OS If S3 is enabled, then (b) reserves it from the OS too. If S3 is disabled, then the range needs no protection. (d) how it is accessed on the S3 resume path It is rewritten same as in (a), which is fine because (b) reserved it. (e) how it is accessed on the warm reset path It is rewritten same as in (a). Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Anthony Perard Cc: Julien Grall Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/PlatformPei/PlatformPei.inf | 2 ++ OvmfPkg/PlatformPei/MemDetect.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index 4742e1bdf42b..c53be2f4925c 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -118,6 +118,8 @@ [FixedPcd] gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaSize =20 [FeaturePcd] gUefiOvmfPkgTokenSpaceGuid.PcdCsmEnable diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetec= t.c index 6b5fee166b5d..ffbbef891a11 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -940,5 +940,25 @@ InitializeRamRegions ( ); } } + +#ifdef MDE_CPU_X64 + if (MemEncryptSevEsIsEnabled ()) { + // + // If SEV-ES is enabled, reserve the SEV-ES work area. + // + // Since this memory range will be used by the Reset Vector on S3 + // resume, it must be reserved as ACPI NVS. + // + // If S3 is unsupported, then various drivers might still write to t= he + // work area. We ought to prevent DXE from serving allocation reques= ts + // such that they would overlap the work area. + // + BuildMemoryAllocationHob ( + (EFI_PHYSICAL_ADDRESS)(UINTN) FixedPcdGet32 (PcdSevEsWorkAreaBase), + (UINT64)(UINTN) FixedPcdGet32 (PcdSevEsWorkAreaSize), + mS3Supported ? EfiACPIMemoryNVS : EfiBootServicesData + ); + } +#endif } } --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62538): https://edk2.groups.io/g/devel/message/62538 Mute This Topic: https://groups.io/mt/75500018/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62539+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62539+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594737502321707.2085903309944; Tue, 14 Jul 2020 07:38:22 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id vNbpYY1788612xkB3x0TkySy; Tue, 14 Jul 2020 07:38:22 -0700 X-Received: from NAM04-CO1-obe.outbound.protection.outlook.com (NAM04-CO1-obe.outbound.protection.outlook.com [40.107.69.80]) by mx.groups.io with SMTP id smtpd.web10.21267.1594737501370482114 for ; Tue, 14 Jul 2020 07:38:21 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ezax17kJ+dkZjwGJI+RaEIpX4TBGs9OtySpMNVyN+paj4k6LTimtEu3NEBVYQfuV+BaUCGs/VaoUQLHV5G3jlpJ9nxQMJzAZzp9itHvEsrE3Y5eKMY5xcvtz1GOnFXuHiArfTmdy64l3635DDp3LAV7nj/2eu7xviCRjK6sDV+pi93lbtHrZ3OKHWf0KavP8Kok+/kVPjOjECTKFu0qDd08HeBMIPWtzaI685D4/RJ2JqiLZW6+MeD3fGHQ49pgzooo0WieZ1Ikhw/XhHFT6n8Vopjt25LEgpgRN/bUBCxxmi7qVgK1rM+KcFebYlzMtIVM2/j3e6rJFadT2oX89HA== 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=TPNpIjuNhjb8J+fWbM5hVjQ7IHF8lsFxPXU/EZJhZFw=; b=Yk9lpdvx5tis5UtmOzSb0iBvp0bOGKChdV+Ecsxssrf5beLbFopB0Cu6LJa1lyxVJKFNpRV4Nj/X8QJ//Xu3iYZXE7M7R0XEy6OvqcANBqznR3Z/rdL3YJJz6eFq/Kf9wFDzX+1UPnB3sjZCmCgGTa6ch8oo1gykH/G8tXpykmFlON8abOQ+D5o1wHt87XVn5O1LUAxRkWslF5IW06c2dMeNH9FaZN9Ty3+xrOacwHDUNIPWyRmgNgSO6EBLpFOMOYNJoVLtR5weUHFBRMJtRL35jGXHDGcajzelxEmi63zgGhIkmPaniDFEqzLYUFexDts7ULylFNSL12W+btkTjA== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB4219.namprd12.prod.outlook.com (2603:10b6:5:217::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 14:38:18 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:38:18 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 36/46] OvmfPkg/ResetVector: Add support for a 32-bit SEV check Date: Tue, 14 Jul 2020 09:37:43 -0500 Message-ID: <955dfdccee8beaa914ebb837c5ad6c45fe8d0b48.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 14:38:18 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e5eefccd-9c6b-40d2-fbc9-08d828038cc5 X-MS-TrafficTypeDiagnostic: DM6PR12MB4219: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: Ng+QkKSXHwRt8uB2O+3kaDOg6n2PQse+VUUIcUmqvky/qjuMXtIsVg9p8knf0T8WkN+aEXGbgD2QRXI4EiprnJykNkGNs9cBQkOHb4PJG8ngRteoKd1pMCXq7sV1WPk75+vBWHs3PCtJwDqwi93OvTbSenTRagV+EePshWzJprCNnl3gcF2qLFXaUqOZQm1k+McSY7quoQR10QMRM8jW3xmIXRyC78JmY3LPDjG7VFwvKlPl8hFXxvcx8d40mnslKcifC19mWDIfkbI2BoyXLDtH6slPBY8LFFhmEt6nfSpUYpFUV+TE3O+PVBqoKHLmOHqbLBqGZ/LhQLm6dpjUZTx8ysM0qG2tp0gPubU5GvwARHbZxQKJCUbsDUDMTaPV0Hmyai98yg156gYJm2XWtw/2nVIL28A1dVhS3ky40ZoKDnEnkTG5kPgGKQy6gcwIqRkLWsOWesGaGX/7njoiqw== X-MS-Exchange-AntiSpam-MessageData: rXo5HWaRIoDEg4aEJ8oSgQ7KNkXLKM9cooBlQISs+W64dKZ8dMHHeGiyNsxvFjK2bs3uPzonFS+27qRFXJeI5J75bcGYqesqAMCiCBdDogaYhEMGD+oo4zxQBMlIkOU6YA9ChmXQq+BLm2929n8OrTvIZ7Zx5rpVLBZ77J7YITl35rIxCbepsesCQyRrQFRl95unj6RQph1zJJI783A8QeOqg2fIRd45NBnV6o3a/NPuiJrW+yOerhgjRLJVRyzwcOzbb116xg/y6R+vkU+67i9nPOvCnq8EPIZI6Jv3pXzA9AywnS6DBSdfyKc8nIhHYLWRXlM+K/bc5Adz5ZjvwdfwR6eerCcsSp9HmVeCqyT3LxLLxF9e9HAIABwfSCxTMB+GaudTLUDkxSJwiNOXDbM66iRMmKB30Kt99HHhL62h8bR7VN+lexWd1FzX1M49NGMF76Z8OJQ4yNKJlFwSVRfp6zda5WmXG+U+WpyuoO8= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e5eefccd-9c6b-40d2-fbc9-08d828038cc5 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:38:18.7832 (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: 2rrtJpxXUkSbvgiyyaaRPPeRLFs/Jkytgq03syiBOEOqfqPyyf/K+9iJxaWamq6gOWKRQ/W6wYzkj3t5Vk4Mwg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4219 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: IYpGoUxecp6zCSZMUQ1HuCD9x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737502; bh=s7AT8QYu2YnnDnxAiSxH/v2ikR6ZSMLKwbdbWy9TaCQ=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=ZVB/IJyFP9BrtQ56dp/QzrqqFkFcvINmsI0DJSmKlWeoAWIXy/6BzTq0EFAuhqg+qNq QgWgq6Blh4jJyjj4Vzek39nBfKpZsiGZ+rX9vdd3TtLvlUOJbH/nvR7neT+wXPRHjQJJG cHM02NoRagXrr+blUkxz4QWu20AZGUuw9gQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 During BSP startup, the reset vector code will issue a CPUID instruction while in 32-bit mode. When running as an SEV-ES guest, this will trigger a #VC exception. Add exception handling support to the early reset vector code to catch these exceptions. Also, since the guest is in 32-bit mode at this point, writes to the GHCB will be encrypted and thus not able to be read by the hypervisor, so use the GHCB CPUID request/response protocol to obtain the requested CPUID function values and provide these to the guest. The exception handling support is active during the SEV check and uses the OVMF temporary RAM space for a stack. After the SEV check is complete, the exception handling support is removed and the stack pointer cleared. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/ResetVector/ResetVector.inf | 3 + OvmfPkg/ResetVector/Ia32/PageTables64.asm | 275 +++++++++++++++++++++- OvmfPkg/ResetVector/ResetVector.nasmb | 2 + 3 files changed, 277 insertions(+), 3 deletions(-) diff --git a/OvmfPkg/ResetVector/ResetVector.inf b/OvmfPkg/ResetVector/Rese= tVector.inf index 483fd90fe785..a53ae6c194ae 100644 --- a/OvmfPkg/ResetVector/ResetVector.inf +++ b/OvmfPkg/ResetVector/ResetVector.inf @@ -34,9 +34,12 @@ [BuildOptions] *_*_X64_NASMB_FLAGS =3D -I$(WORKSPACE)/UefiCpuPkg/ResetVector/Vtf0/ =20 [Pcd] + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm b/OvmfPkg/ResetVecto= r/Ia32/PageTables64.asm index 9f86ddf6f08f..7c72128a84d6 100644 --- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm +++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm @@ -36,13 +36,58 @@ BITS 32 PAGE_READ_WRITE + \ PAGE_PRESENT) =20 +; +; SEV-ES #VC exception handler support +; +; #VC handler local variable locations +; +%define VC_CPUID_RESULT_EAX 0 +%define VC_CPUID_RESULT_EBX 4 +%define VC_CPUID_RESULT_ECX 8 +%define VC_CPUID_RESULT_EDX 12 +%define VC_GHCB_MSR_EDX 16 +%define VC_GHCB_MSR_EAX 20 +%define VC_CPUID_REQUEST_REGISTER 24 +%define VC_CPUID_FUNCTION 28 + +; #VC handler total local variable size +; +%define VC_VARIABLE_SIZE 32 + +; #VC handler GHCB CPUID request/response protocol values +; +%define GHCB_CPUID_REQUEST 4 +%define GHCB_CPUID_RESPONSE 5 +%define GHCB_CPUID_REGISTER_SHIFT 30 +%define CPUID_INSN_LEN 2 + + ; Check if Secure Encrypted Virtualization (SEV) feature is enabled ; -; If SEV is enabled then EAX will be at least 32 +; Modified: EAX, EBX, ECX, EDX, ESP +; +; If SEV is enabled then EAX will be at least 32. ; If SEV is disabled then EAX will be zero. ; CheckSevFeature: + ; Set the first byte of the workarea to zero to communicate to the SEC + ; phase that SEV-ES is not enabled. If SEV-ES is enabled, the CPUID + ; instruction will trigger a #VC exception where the first byte of the + ; workarea will be set to one. + mov byte[SEV_ES_WORK_AREA], 0 + + ; + ; Set up exception handlers to check for SEV-ES + ; Load temporary RAM stack based on PCDs (see SevEsIdtVmmComm for + ; stack usage) + ; Establish exception handlers + ; + mov esp, SEV_ES_VC_TOP_OF_STACK + mov eax, ADDR_OF(Idtr) + lidt [cs:eax] + ; Check if we have a valid (0x8000_001F) CPUID leaf + ; CPUID raises a #VC exception if running as an SEV-ES guest mov eax, 0x80000000 cpuid =20 @@ -53,8 +98,8 @@ CheckSevFeature: jl NoSev =20 ; Check for memory encryption feature: - ; CPUID Fn8000_001F[EAX] - Bit 1 - ; + ; CPUID Fn8000_001F[EAX] - Bit 1 + ; CPUID raises a #VC exception if running as an SEV-ES guest mov eax, 0x8000001f cpuid bt eax, 1 @@ -78,6 +123,15 @@ NoSev: xor eax, eax =20 SevExit: + ; + ; Clear exception handlers and stack + ; + push eax + mov eax, ADDR_OF(IdtrClear) + lidt [cs:eax] + pop eax + mov esp, 0 + OneTimeCallRet CheckSevFeature =20 ; Check if Secure Encrypted Virtualization - Encrypted State (SEV-ES) feat= ure @@ -222,3 +276,218 @@ SetCr3: mov cr3, eax =20 OneTimeCallRet SetCr3ForPageTables64 + +; +; Start of #VC exception handling routines +; + +SevEsIdtNotCpuid: + ; + ; Use VMGEXIT to request termination. + ; 1 - #VC was not for CPUID + ; + mov eax, 1 + jmp SevEsIdtTerminate + +SevEsIdtNoCpuidResponse: + ; + ; Use VMGEXIT to request termination. + ; 2 - GHCB_CPUID_RESPONSE not received + ; + mov eax, 2 + +SevEsIdtTerminate: + ; + ; Use VMGEXIT to request termination. At this point the reason code is + ; located in EAX, so shift it left 16 bits to the proper location. + ; + ; EAX[11:0] =3D> 0x100 - request termination + ; EAX[15:12] =3D> 0x1 - OVMF + ; EAX[23:16] =3D> 0xXX - REASON CODE + ; + shl eax, 16 + or eax, 0x1100 + xor edx, edx + mov ecx, 0xc0010130 + wrmsr + ; + ; Issue VMGEXIT - NASM doesn't support the vmmcall instruction in 32-b= it + ; mode, so work around this by temporarily switching to 64-bit mode. + ; +BITS 64 + rep vmmcall +BITS 32 + + ; + ; We shouldn't come back from the VMGEXIT, but if we do, just loop. + ; +SevEsIdtHlt: + hlt + jmp SevEsIdtHlt + iret + + ; + ; Total stack usage for the #VC handler is 44 bytes: + ; - 12 bytes for the exception IRET (after popping error code) + ; - 32 bytes for the local variables. + ; +SevEsIdtVmmComm: + ; + ; If we're here, then we are an SEV-ES guest and this + ; was triggered by a CPUID instruction + ; + ; Set the first byte of the workarea to one to communicate to the SEC + ; phase that SEV-ES is enabled. + mov byte[SEV_ES_WORK_AREA], 1 + + pop ecx ; Error code + cmp ecx, 0x72 ; Be sure it was CPUID + jne SevEsIdtNotCpuid + + ; Set up local variable room on the stack + ; CPUID function : + 28 + ; CPUID request register : + 24 + ; GHCB MSR (EAX) : + 20 + ; GHCB MSR (EDX) : + 16 + ; CPUID result (EDX) : + 12 + ; CPUID result (ECX) : + 8 + ; CPUID result (EBX) : + 4 + ; CPUID result (EAX) : + 0 + sub esp, VC_VARIABLE_SIZE + + ; Save the CPUID function being requested + mov [esp + VC_CPUID_FUNCTION], eax + + ; The GHCB CPUID protocol uses the following mapping to request + ; a specific register: + ; 0 =3D> EAX, 1 =3D> EBX, 2 =3D> ECX, 3 =3D> EDX + ; + ; Set EAX as the first register to request. This will also be used as a + ; loop variable to request all register values (EAX to EDX). + xor eax, eax + mov [esp + VC_CPUID_REQUEST_REGISTER], eax + + ; Save current GHCB MSR value + mov ecx, 0xc0010130 + rdmsr + mov [esp + VC_GHCB_MSR_EAX], eax + mov [esp + VC_GHCB_MSR_EDX], edx + +NextReg: + ; + ; Setup GHCB MSR + ; GHCB_MSR[63:32] =3D CPUID function + ; GHCB_MSR[31:30] =3D CPUID register + ; GHCB_MSR[11:0] =3D CPUID request protocol + ; + mov eax, [esp + VC_CPUID_REQUEST_REGISTER] + cmp eax, 4 + jge VmmDone + + shl eax, GHCB_CPUID_REGISTER_SHIFT + or eax, GHCB_CPUID_REQUEST + mov edx, [esp + VC_CPUID_FUNCTION] + mov ecx, 0xc0010130 + wrmsr + + ; + ; Issue VMGEXIT - NASM doesn't support the vmmcall instruction in 32-b= it + ; mode, so work around this by temporarily switching to 64-bit mode. + ; +BITS 64 + rep vmmcall +BITS 32 + + ; + ; Read GHCB MSR + ; GHCB_MSR[63:32] =3D CPUID register value + ; GHCB_MSR[31:30] =3D CPUID register + ; GHCB_MSR[11:0] =3D CPUID response protocol + ; + mov ecx, 0xc0010130 + rdmsr + mov ecx, eax + and ecx, 0xfff + cmp ecx, GHCB_CPUID_RESPONSE + jne SevEsIdtNoCpuidResponse + + ; Save returned value + shr eax, GHCB_CPUID_REGISTER_SHIFT + mov [esp + eax * 4], edx + + ; Next register + inc word [esp + VC_CPUID_REQUEST_REGISTER] + + jmp NextReg + +VmmDone: + ; + ; At this point we have all CPUID register values. Restore the GHCB MS= R, + ; set the return register values and return. + ; + mov eax, [esp + VC_GHCB_MSR_EAX] + mov edx, [esp + VC_GHCB_MSR_EDX] + mov ecx, 0xc0010130 + wrmsr + + mov eax, [esp + VC_CPUID_RESULT_EAX] + mov ebx, [esp + VC_CPUID_RESULT_EBX] + mov ecx, [esp + VC_CPUID_RESULT_ECX] + mov edx, [esp + VC_CPUID_RESULT_EDX] + + add esp, VC_VARIABLE_SIZE + + ; Update the EIP value to skip over the now handled CPUID instruction + ; (the CPUID instruction has a length of 2) + add word [esp], CPUID_INSN_LEN + iret + +ALIGN 2 + +Idtr: + dw IDT_END - IDT_BASE - 1 ; Limit + dd ADDR_OF(IDT_BASE) ; Base + +IdtrClear: + dw 0 ; Limit + dd 0 ; Base + +ALIGN 16 + +; +; The Interrupt Descriptor Table (IDT) +; This will be used to determine if SEV-ES is enabled. Upon execution +; of the CPUID instruction, a VMM Communication Exception will occur. +; This will tell us if SEV-ES is enabled. We can use the current value +; of the GHCB MSR to determine the SEV attributes. +; +IDT_BASE: +; +; Vectors 0 - 28 (No handlers) +; +%rep 29 + dw 0 ; Offset low bits 15..0 + dw 0x10 ; Selector + db 0 ; Reserved + db 0x8E ; Gate Type (IA32_IDT_GAT= E_TYPE_INTERRUPT_32) + dw 0 ; Offset high bits 31..16 +%endrep +; +; Vector 29 (VMM Communication Exception) +; + dw (ADDR_OF(SevEsIdtVmmComm) & 0xffff) ; Offset low bits 15..0 + dw 0x10 ; Selector + db 0 ; Reserved + db 0x8E ; Gate Type (IA32_IDT_GAT= E_TYPE_INTERRUPT_32) + dw (ADDR_OF(SevEsIdtVmmComm) >> 16) ; Offset high bits 31..16 +; +; Vectors 30 - 31 (No handlers) +; +%rep 2 + dw 0 ; Offset low bits 15..0 + dw 0x10 ; Selector + db 0 ; Reserved + db 0x8E ; Gate Type (IA32_IDT_GAT= E_TYPE_INTERRUPT_32) + dw 0 ; Offset high bits 31..16 +%endrep +IDT_END: diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb b/OvmfPkg/ResetVector/Re= setVector.nasmb index bfb77e439105..762661115d50 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -72,6 +72,8 @@ %define GHCB_PT_ADDR (FixedPcdGet32 (PcdOvmfSecGhcbPageTableBase)) %define GHCB_BASE (FixedPcdGet32 (PcdOvmfSecGhcbBase)) %define GHCB_SIZE (FixedPcdGet32 (PcdOvmfSecGhcbSize)) + %define SEV_ES_WORK_AREA (FixedPcdGet32 (PcdSevEsWorkAreaBase)) + %define SEV_ES_VC_TOP_OF_STACK (FixedPcdGet32 (PcdOvmfSecPeiTempRamBase)= + FixedPcdGet32 (PcdOvmfSecPeiTempRamSize)) %include "Ia32/PageTables64.asm" %endif =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62539): https://edk2.groups.io/g/devel/message/62539 Mute This Topic: https://groups.io/mt/75500019/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62540+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62540+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594737503117720.8126178919968; Tue, 14 Jul 2020 07:38:23 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id QN1mYY1788612xXEctj1bC2j; Tue, 14 Jul 2020 07:38:22 -0700 X-Received: from NAM04-CO1-obe.outbound.protection.outlook.com (NAM04-CO1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web10.21267.1594737501370482114 for ; Tue, 14 Jul 2020 07:38:21 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YnrjEH1UpSv0k8fF/Ln1Ohs014PaJxD/dTnqRk/m4UnJQU1sbo2FTD+z9RRR+XO90s136XU9rnEVSKdSqqCFdfEY8NiZnXxrpOIFwDyj9ZWibAOZbDTPjOMuBujVyUpTmjDe3mPjb2uqcEDlLoRNeRXvRiXotY8B3EYxPbLAzcsQkJU6p8EOxBg0XVL4HCvipxRgzXhMJSVlahcN+rnC4TXhaMc4+7XOzupvNp8u0meZquDAmmykBWvABfiMgrpd9XGoumI+JEY6Qe9/mncsKgV+cle2R01TdSvUCejYZq7RSgT8anDwcnZiso1f0AiloXsbwxdsDjnrvnInqs0JkA== 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=S26Dux0cwurzGpks92C9p7rCgsyx41XUiYYP5lYQTJU=; b=Nbswl+WUyULp6Viw7aX48BOlYrfHteqOqNpWwpmVI80wdjvyzGqq5DUj51NM3mqwfY/fmoN0Gff1y5NJfsAzh8oJgfHrF5fZ9rtiUB9jWwMnVadg32lBFM5c/ypOj5+m/KvxYUXsSF3raOMM9l0ZAUD5eZnmAvq2j1LRIqFnb2x9euCEFJv0IYhLBFDcMdA75oxR0fuwYi/32+w7mIDJug6P96Mcs+2Xb4xVfrOF/yyn0jd1jwaJf4H3OIIY7bSjTM9pxgKmpcRL0f4uLT8aTs6UEsSSXdCJI+gsQKZXH73r7jGLDbtz4eAtjEaF/xgjxhnfya/wDk38ZLNlmFQ28Q== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB4219.namprd12.prod.outlook.com (2603:10b6:5:217::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 14:38:20 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:38:20 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 37/46] OvmfPkg/Sec: Add #VC exception handling for Sec phase Date: Tue, 14 Jul 2020 09:37:44 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 14:38:19 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 44b090e0-6690-46b9-ed79-08d828038d6b X-MS-TrafficTypeDiagnostic: DM6PR12MB4219: 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-Message-Info: ocAuadb/ZkppdLPM8C2xihOv45u0BfN1yLkBHkvuFoSKy67Nq6jWINxFVuy5H+mDfpfzrrP5mA7T1oldHl2W8dveXjFbdJhjN/dD+kJCdRu2b3OvaLcRLlg7xfGd+8+VxKifuzEddlrOniNKvcNRg148aJe2Y8CMjLoiFLigJgP82Q8v4UOb3lcI+pV1cS+46xg1jkwkPd8bywIOwRG8ebBYdWB3M359G0TDjXUVQFL7HNEI06p08CDeZ5xAQfTWWCE+6DxET8POE6S/yniW0rxQXX1GOz5uU6Gs70N4TkHnHebgumZoPVA99LY3twrds16U1XdVDzccB1KUWkKAGLbCcHdnaVRdtQXtJ3DYHLK/Iba5SYb41dgTd/ouyFCGRLtss52aQIcWMl/x6XUUfO4ACzWl8J3uajQKS61PphqJxWDg5r18tCxqV9BjYyYphrn4LzGN06at8tMVz+WrpQ== X-MS-Exchange-AntiSpam-MessageData: Rm4GEpY0M0HHQwkEILAQ4Dt+GshVVxWheTH5h7n/211+uPT5MVi6JXkAVzv+XkEEEaP5FIucGnJLikO8mJ6MpKP7PEhWScQqNCipPmjeHTnN6FWE5iqbVqH2mz4sdctPwDEWb6ItL3foMukCTQ/79FwBS9tgwoter0pWDygLh7Sb3YRm+83drOSgIhhw2wcmGpo2RDiRbLmGTLKDLZRmIWsf5MH7e0M3rHbyIJmLacCvrStOFB9cAQdsxJ86/5i6F0lXe2msgZNWVQufaDbpz7xC2WyaYQKdd12Mn0UyaVpE0o7bGWczTQJasKGqXXPymfudunt6BxqwMoLHQaFqkGDhhmJ50XLh01sl1RgZg6sll1heuCJMwQFih//RUXJ+sU2mK/tR7VuUVGL5WKdDvwcr1vXaX33AIDfcGea7vamAlrtrT7tP/XX09bvLJwjhe1E52R11GNE1KLeKUVjGGp6NR7WyGDLYmQQAQVzmg2s= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 44b090e0-6690-46b9-ed79-08d828038d6b X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:38:19.8897 (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: QLweQSlJO7W2jNJyuXtuBGQJhN2WcSJayBZL6kCeMj5gGE/aG+si9kuTMZTqJJ08ReUOYfttbzfLE1O207ldBg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4219 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: 6zqrKUwwrAMOOSBtPZgB6cvtx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737502; bh=jPLC2ifNbO6kceYqR4Kkrklntmbq3By5AVvzx5Ae8BU=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Agok5cHWDr9XQZrDiW68ZQOVlcGcdtHr+/MqORjTCcXKinj0vASzr7JU8zCiB7bSedT VH/RNo/SBb3e5IMzBW9nrVJj152kD9EDHUhYb4mT93ZkZ+JL8ilC79ll/9k9/2qkzHfDW m2ER8pi6T2cLWdqQ3gxNSChYf7KyeQf20h4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 An SEV-ES guest will generate a #VC exception when it encounters a non-automatic exit (NAE) event. It is expected that the #VC exception handler will communicate with the hypervisor using the GHCB to handle the NAE event. NAE events can occur during the Sec phase, so initialize exception handling early in the OVMF Sec support. Before establishing the exception handling, validate that the supported version of the SEV-ES protocol in OVMF is supported by the hypervisor. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Sec/SecMain.inf | 4 + OvmfPkg/Sec/SecMain.c | 181 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 172 insertions(+), 13 deletions(-) diff --git a/OvmfPkg/Sec/SecMain.inf b/OvmfPkg/Sec/SecMain.inf index 63ba4cb555fb..7f78dcee2772 100644 --- a/OvmfPkg/Sec/SecMain.inf +++ b/OvmfPkg/Sec/SecMain.inf @@ -50,15 +50,19 @@ [LibraryClasses] PeCoffExtraActionLib ExtractGuidedSectionLib LocalApicLib + CpuExceptionHandlerLib =20 [Ppis] gEfiTemporaryRamSupportPpiGuid # PPI ALWAYS_PRODUCED =20 [Pcd] + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/SecMain.c index 6dea6e771a29..c2a35463dce4 100644 --- a/OvmfPkg/Sec/SecMain.c +++ b/OvmfPkg/Sec/SecMain.c @@ -24,6 +24,9 @@ #include #include #include +#include +#include +#include =20 #include =20 @@ -34,6 +37,10 @@ typedef struct _SEC_IDT_TABLE { IA32_IDT_GATE_DESCRIPTOR IdtTable[SEC_IDT_ENTRY_COUNT]; } SEC_IDT_TABLE; =20 +typedef struct _SEC_SEV_ES_WORK_AREA { + UINT8 SevEsEnabled; +} SEC_SEV_ES_WORK_AREA; + VOID EFIAPI SecStartupPhase2 ( @@ -712,6 +719,120 @@ FindAndReportEntryPoints ( return; } =20 +/** + Handle an SEV-ES/GHCB protocol check failure. + + Notify the hypervisor using the VMGEXIT instruction that the SEV-ES guest + 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 (); +} + +/** + Validate the SEV-ES/GHCB protocol level. + + Verify that the level of SEV-ES/GHCB protocol supported by the hypervisor + and the guest intersect. If they don't intersect, request termination. + +**/ +STATIC +VOID +SevEsProtocolCheck ( + VOID + ) +{ + MSR_SEV_ES_GHCB_REGISTER Msr; + GHCB *Ghcb; + + // + // Use the GHCB MSR Protocol to obtain the GHCB SEV-ES Information for + // protocol checking + // + Msr.GhcbPhysicalAddress =3D 0; + Msr.GhcbInfo.Function =3D GHCB_INFO_SEV_INFO_GET; + AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress); + + AsmVmgExit (); + + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + + if (Msr.GhcbInfo.Function !=3D GHCB_INFO_SEV_INFO) { + SevEsProtocolFailure (GHCB_TERMINATE_GHCB_GENERAL); + } + + if (Msr.GhcbProtocol.SevEsProtocolMin > Msr.GhcbProtocol.SevEsProtocolMa= x) { + SevEsProtocolFailure (GHCB_TERMINATE_GHCB_PROTOCOL); + } + + if ((Msr.GhcbProtocol.SevEsProtocolMin > GHCB_VERSION_MAX) || + (Msr.GhcbProtocol.SevEsProtocolMax < GHCB_VERSION_MIN)) { + SevEsProtocolFailure (GHCB_TERMINATE_GHCB_PROTOCOL); + } + + // + // SEV-ES protocol checking succeeded, set the initial GHCB address + // + Msr.GhcbPhysicalAddress =3D FixedPcdGet32 (PcdOvmfSecGhcbBase); + AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress); + + Ghcb =3D Msr.Ghcb; + SetMem (Ghcb, sizeof (*Ghcb), 0); + + // + // Set the version to the maximum that can be supported + // + Ghcb->ProtocolVersion =3D MIN (Msr.GhcbProtocol.SevEsProtocolMax, GHCB_V= ERSION_MAX); + Ghcb->GhcbUsage =3D GHCB_STANDARD_USAGE; +} + +/** + Determine if SEV-ES is active. + + During early booting, SEV-ES support code will set a flag to indicate th= at + SEV-ES is enabled. Return the value of this flag as an indicator that SE= V-ES + is enabled. + + @retval TRUE SEV-ES is enabled + @retval FALSE SEV-ES is not enabled + +**/ +STATIC +BOOLEAN +SevEsIsEnabled ( + VOID + ) +{ + SEC_SEV_ES_WORK_AREA *SevEsWorkArea; + + SevEsWorkArea =3D (SEC_SEV_ES_WORK_AREA *) FixedPcdGet32 (PcdSevEsWorkAr= eaBase); + + return ((SevEsWorkArea !=3D NULL) && (SevEsWorkArea->SevEsEnabled !=3D 0= )); +} + VOID EFIAPI SecCoreStartupWithStack ( @@ -737,8 +858,55 @@ SecCoreStartupWithStack ( Table[Index] =3D 0; } =20 + // + // Initialize IDT - Since this is before library constructors are called, + // we use a loop rather than CopyMem. + // + IdtTableInStack.PeiService =3D NULL; + for (Index =3D 0; Index < SEC_IDT_ENTRY_COUNT; Index ++) { + UINT8 *Src, *Dst; + UINTN Byte; + + Src =3D (UINT8 *) &mIdtEntryTemplate; + Dst =3D (UINT8 *) &IdtTableInStack.IdtTable[Index]; + for (Byte =3D 0; Byte < sizeof (mIdtEntryTemplate); Byte++) { + Dst[Byte] =3D Src[Byte]; + } + } + + IdtDescriptor.Base =3D (UINTN)&IdtTableInStack.IdtTable; + IdtDescriptor.Limit =3D (UINT16)(sizeof (IdtTableInStack.IdtTable) - 1); + + if (SevEsIsEnabled ()) { + SevEsProtocolCheck (); + + // + // For SEV-ES guests, the exception handler is needed before calling + // ProcessLibraryConstructorList() because some of the library constru= ctors + // perform some functions that result in #VC exceptions being generate= d. + // + // Due to this code executing before library constructors, *all* libra= ry + // API calls are theoretically interface contract violations. However, + // because this is SEC (executing in flash), those constructors cannot + // write variables with static storage duration anyway. Furthermore, o= nly + // a small, restricted set of APIs, such as AsmWriteIdtr() and + // InitializeCpuExceptionHandlers(), are called, where we require that= the + // underlying library not require constructors to have been invoked and + // that the library instance not trigger any #VC exceptions. + // + AsmWriteIdtr (&IdtDescriptor); + InitializeCpuExceptionHandlers (NULL); + } + ProcessLibraryConstructorList (NULL, NULL); =20 + if (!SevEsIsEnabled ()) { + // + // For non SEV-ES guests, just load the IDTR. + // + AsmWriteIdtr (&IdtDescriptor); + } + DEBUG ((DEBUG_INFO, "SecCoreStartupWithStack(0x%x, 0x%x)\n", (UINT32)(UINTN)BootFv, @@ -751,19 +919,6 @@ SecCoreStartupWithStack ( // InitializeFloatingPointUnits (); =20 - // - // Initialize IDT - // - IdtTableInStack.PeiService =3D NULL; - for (Index =3D 0; Index < SEC_IDT_ENTRY_COUNT; Index ++) { - CopyMem (&IdtTableInStack.IdtTable[Index], &mIdtEntryTemplate, sizeof = (mIdtEntryTemplate)); - } - - IdtDescriptor.Base =3D (UINTN)&IdtTableInStack.IdtTable; - IdtDescriptor.Limit =3D (UINT16)(sizeof (IdtTableInStack.IdtTable) - 1); - - AsmWriteIdtr (&IdtDescriptor); - #if defined (MDE_CPU_X64) // // ASSERT that the Page Tables were set by the reset vector code to --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62540): https://edk2.groups.io/g/devel/message/62540 Mute This Topic: https://groups.io/mt/75500020/1787277 Mute #vc: https://groups.io/g/edk2/mutehashtag/vc Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62541+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62541+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 15947375038031004.5752399808815; Tue, 14 Jul 2020 07:38:23 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id IzsFYY1788612x0lov18aFGP; Tue, 14 Jul 2020 07:38:23 -0700 X-Received: from NAM04-CO1-obe.outbound.protection.outlook.com (NAM04-CO1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web10.21267.1594737501370482114 for ; Tue, 14 Jul 2020 07:38:22 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I7huv8/fzLf1ghKkg/cY4k7/uJMLBm5HBCaskq58U3jPboEp+nBmNVGl2qJOw3VnjY5xaBQBT/6za/r9jPQ2BxI6uQU64vekL6evBSFI1dTddGs4BFZnwHtsZaI/yQPvTxLR9KSH34kti6UCWY0Kb2ypNb8GcrNk0pMLuKhiJ9i2YbsDOUgSx7kz6MBoQzDF/hThEt8xgpg1d6vRqx5F4RCfBKw4noW/lE2erYowEI+SWZYUqTYhp0ArUBYQP6bynyRfYoE2ZZO+dxgXfxjNyo+aOU30ivHmmJ4YnCNuZFKMlz9hEQl1/i6u5k4UHGa9Wp1mrc6NwQfHlsX5O8TiBA== 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=3E0ymlPSxNH6aH1t6SQyGEJdjjI6yseFWWKhpBgBa7E=; b=VCTqQRVsUHmvrzRW1qbExUMUO+qodKIJEjiiJWqoDo6BC4ETRnV/t/tDT357Mm85WD/LiDcAro05/EIpuY1Pt14pP5OFd5vsU/sn3Auu/0SYxZCrr8JCOrYONQ+MlzbQaQUmtIz7NdzFnxnvWoG9M3miTFS1G87HI9yMKlhEVagxn+BUGjDew665q1y5fIO66SK7I8qEAIwauj5YPOV0II+zEw5fCw1EZjgiqe55BEI0JumRmIrOv7rF5J6OwjjHkBu8c1ESq8RjWLG3sPtYUQRxi7L4YsPpgCOtWK8djcwIrnG063yWvFGGM1xmmYEt20kvwfraw8ATA9XtvTPsMA== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB4219.namprd12.prod.outlook.com (2603:10b6:5:217::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 14:38:21 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:38:21 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 38/46] OvmfPkg/Sec: Enable cache early to speed up booting Date: Tue, 14 Jul 2020 09:37:45 -0500 Message-ID: <28caffee502a6f98eface77131ef6db91afb7896.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 14:38:20 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 2496a382-0c23-4849-dac0-08d828038e13 X-MS-TrafficTypeDiagnostic: DM6PR12MB4219: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: C1y5siMLm1WEcXli2K2yGrQKS8fIW8rB2N8CsRveKHCjzW1ks/d0v85P79i/wbQ2oHjQusj/C6QNBuVkoGCPRtyJ70YASxLiyW4wr6O0qkKLOJxvqyzggZx1DP4yrOb1Y990XbYFycyUZwchlCUzvHzOIz4giIaZHjxjuycwuNtHjwg/1iL4e0nNlKadAzQ8AuUiD9VgfA1AygVBIcK6qZlqD5282xIN96jOwRUTWP6poYHWmjegbjP+8zR42Um8qdtG1SXK/2KUXiZpt2G6FoYQNfO8sC0NtlusCBT5s6tWGJPF9CHLG32TjCpdmDURDjxAlVe+s+76K1XxY12IPX+65NFT21RGNXvuedZej1xqsDU89MjcOiKfwHG34C3qe8z4ynrlK8pSQe9uM5+Ryn+PuEm2S1kr05Dy8k1DLeYAfsOnwOVO3pPCYU0Y4UoJRys6aorvmGoJpYEUxy/6SA== X-MS-Exchange-AntiSpam-MessageData: 9K7CODd9efV2a87iqj5hkqI+tbItIWWoJiQvuCi9frhItvF5rKdJzqE4MqZjZYqj+Mqzr9WHEF44Veaq+wcwe/fGQ0czKMMEc+tG4LbOwYYfTZOIx6T1oIDJM6tLO/9OHNK3fnPP6DWVE2HAQNfh53/yB5a0RB5WCggQhwzRlG1nK0Fc/SWMv7vnXK0y98PsZSldHxX88fTq/TuQsOwX4CMZPEcnjaADjDW9+gF8xbebjtUxburM/AlU1B1ST4JJ3h6Ccbb0ds/zMiG+XTu58gujQgK3WYbVjwYrAm1Hh7HHtFdyalOa5sSHItwThX9H6ER5tbRXShBj/2sLMtw4RKg0g2BIhJL64uHs/tapXHU+zAu06CXwSpNLQJSJvMENpdh/Qwv7MBIutuKqKKo+S75Qgih08oAs2rUM/wUjpFo5O79VU7aBvduCf3Wy1XTPO3Q6jg2G8V1Kq5/Gf5B4R1baHV/jP/hHq+pyd2/W6+o= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2496a382-0c23-4849-dac0-08d828038e13 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:38:20.9022 (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: uFcxzPkOp5nQ/eqzKD8CTRyQjL6zjJ4EU7Jbzdvc/MA9KUP9vyoPjIYbKajpU9rMtUtDBErJpdYfXb027KeTSw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4219 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: FFofGsBihPjcrnI5yxMftSiWx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737503; bh=ZiMpQzdljhPS7Pwb7QW46yuP/V7jyW5+qlP0Ln+9U+o=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=EL29YW1A8KF9eoZae0EWuJKddRzKDAsPGj/aF6T4PVKq17DEUG4MBHUcGfIifp2eWNK WzHh879WTAbkqkd+9EiztS/Vqo9g9GWxNO0Po//VG7j3+poNflRSf2pWrpAlkCJRdXNBx nUbgYFE/6rYB8i6QO9OeeqH887TGs34ex8c= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Currently, the OVMF code relies on the hypervisor to enable the cache support on the processor in order to improve the boot speed. However, with SEV-ES, the hypervisor is not allowed to change the CR0 register to enable caching. Update the OVMF Sec support to enable caching in order to improve the boot speed when running as an SEV-ES guest. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Sec/SecMain.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/SecMain.c index c2a35463dce4..271a06348ed8 100644 --- a/OvmfPkg/Sec/SecMain.c +++ b/OvmfPkg/Sec/SecMain.c @@ -905,6 +905,13 @@ SecCoreStartupWithStack ( // For non SEV-ES guests, just load the IDTR. // AsmWriteIdtr (&IdtDescriptor); + } else { + // + // Under SEV-ES, the hypervisor can't modify CR0 and so can't enable + // caching in order to speed up the boot. Enable caching early for + // an SEV-ES guest. + // + AsmEnableCache (); } =20 DEBUG ((DEBUG_INFO, --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62541): https://edk2.groups.io/g/devel/message/62541 Mute This Topic: https://groups.io/mt/75500021/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62542+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62542+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594737504179818.5613374313833; Tue, 14 Jul 2020 07:38:24 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Yv8gYY1788612xYIbBdobqFq; Tue, 14 Jul 2020 07:38:23 -0700 X-Received: from NAM04-CO1-obe.outbound.protection.outlook.com (NAM04-CO1-obe.outbound.protection.outlook.com [40.107.69.40]) by mx.groups.io with SMTP id smtpd.web12.21053.1594737503119574890 for ; Tue, 14 Jul 2020 07:38:23 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=odJWV3lPhRCCUO293BWgEdeAa1MHyRtcGP7frFBh9KvHxi6Tu1eCXx92kRLzxdYMQJLJEeSxrhP5aTJg/xCa9lN/5rU9A8Q7cox9etAZAdwfPUvHvaNQPtKYwmqfNeM09/gO+wTTO0v0PiSH65dFy2MdKDrcnpeEk5clbJpU5ZuYFGsFqiaJcWRCJ9qudMGBdTM6pQwjbjZPUviL9LWSbfbXfvqbvdMWy86ANncTZNMX79A1QulTasKCbPeYqFDRcbx1RMQ2qrFibMnmnW6q/VCZWPc2s9V6MmhDu/BNL0mNRKCKU0KU5S5GrZyDRsKrhNy9gzgibfVwrCMjapmOrQ== 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=9SL7ZuvVbtegSaUIJvRjeIedgAr9HaaB2JEMJds61HY=; b=aMfQsPFaeFI1P3QxiMMgzZF2xUPJw4bX5BRNPKQ6sTlc8YSJpG1HHiwlyMejr/2Heg7jp4ZwNfAjkFl/GEb15Zugt3jSf0/DsvgOz394z9JPhIpAtWHLn2qMRuqiylLALjoqYvKv0CGjAJxpT9BVkoVkB8C/9pcNfeIkjy1SH7tEGY15pE1H0XK4tGHQEsKdvvLob+uzYFBNYGV4aeIZysqndDbP5QaHEL5a98+4AxwD+NlWvROMEcUJ2ILcsz64t1BRjqJsJGDNzXdXOUpLvxRy4tBlUYQCk6AOw9ipC+MpYQIJw+HPbjYvGla0mlFMzBFENagagWV8xdoPbdAw3A== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB4219.namprd12.prod.outlook.com (2603:10b6:5:217::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 14:38:22 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 14:38:22 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v10 39/46] OvmfPkg/QemuFlashFvbServicesRuntimeDxe: Bypass flash detection with SEV-ES Date: Tue, 14 Jul 2020 09:37:46 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR20CA0032.namprd20.prod.outlook.com (2603:10b6:3:13d::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 14:38:21 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 5b836ba9-7025-43a1-cd0a-08d828038ea7 X-MS-TrafficTypeDiagnostic: DM6PR12MB4219: 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-Message-Info: drVAsM85hdmayBHx3bC0AwMFdyICCVAl+5VQ8uQ3YeWdgn3FiTH2h7qVgsF0ZTeweRNOMm+8Adca4k1YqKH9lnrlqnjLDeLLAUxPlZG8g3fTfwcgaWJG1Xcu/r5XbwzQULczhgb7rSk3gaC+tGuxqQILXmN7WyOlhIcBrPtTcdWZDiaE22kriFOLY5pWSzNxbw9zyVMUnkc6Tj/Onn2YxWxmmgDcf6YR9k5L6YrWtigc0SUp5+nWJ/AmMR1ib92/Z2pcYk77tU7mcM5bgOBl9BKHziSNy8qKQO4ApUU+eWU0QReyTPMaJeCyLKiDoQBpjJJ+2PgWmtkU/DMX7/lAGgLke+z5bRzcbhwlZtQu2xlUkUWjQDjN7GFsIZ43JHT1/Z1tTiba/IF/rq//0Ex2Yilxh4m2CvG6m/dwhb2JQJK+Tr0o5/g8fVVpiSNceNPD/PQtE/7/KLerCKSuEJ9WEB+K63b9C+sMavzrxVsfubQ= X-MS-Exchange-AntiSpam-MessageData: INKhl2aKG0OTDqkAkJHbSnvdsYMZUM3imy8sknDgGUadeUdzMorkNt2Ex9awmt77W23FAM97Od9ER7RFx4Q3WEjuKBUGYb8O63pw6sN3tqpoMKhEGyF2YgmPZE1UTQdMHNUDUO7gJLHK2vVDgQFTg2V4GkxRg186UJoirfj+jSnfMon1KRljfPiLgGlv9A6N9sAj2txNgyH8HBZsiJ1Pi+nt0SyjUeeevk34o7wo+UnCNhaUuxyw59p7FD3/wQi7LxpR2zj57nvmyd+Otz72iZH1Gljcv+Z5tq06K+RYashuSBEjugTmGkSup+aWsBbtOp0YtN/lyVdn1JCRCwd9Mlho339e/LMLqahbceGEEqloXISwtJ1f1va08TBpW/x1Sk8un+RAsaJBvy9uyEUHZOFIu6SBTTgVaOlXKlN2jMAlUv6bRykwPLX0MTcj4Gc/Dz0AIxd3yYEU0Nzy21dVdn3Dzw5ppaC9MtEMZbsmgeQ= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5b836ba9-7025-43a1-cd0a-08d828038ea7 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:38:21.9008 (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: IXI5HolDIQqFImVXUhcmKvLe+qeqe+NxlHhs/FPBtb/31qxB+eGlbNyeh/2U2iju2soMjvL4mwqfMrPV3aWHng== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4219 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: s5HQSB5byJpwsVbfsK5fI2n5x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594737503; bh=J25YDAsWOsCC3XV1YGWq09VUcbMDV1W6MdTfulJ6pK0=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=aXbpDDmWflzJKt5HGbQHqQB7a/2nXrMf1x0Nd4LMKqgol+wmLnX0L/m6Dc4YjneQ23v WbxBg8qdNCsV9P6Xqmdpaor/M00zu2VZbuMBVszxfTRt1S26fli5uMUip79WWc1DFAmpR t529tuKXvEYFqES5E5j4Nb5WEJKk3sP//js= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 The flash detection routine will attempt to determine how the flash device behaves (e.g. ROM, RAM, Flash). But when SEV-ES is enabled and the flash device behaves as a ROM device (meaning it is marked read-only by the hypervisor), this check may result in an infinite nested page fault because of the attempted write. Since the instruction cannot be emulated when SEV-ES is enabled, the RIP is never advanced, resulting in repeated nested page faults. When SEV-ES is enabled, exit the flash detection early and assume that the FD behaves as Flash. This will result in QemuFlashWrite() being called to store EFI variables, which will also result in an infinite nested page fault when the write is performed. In this case, update QemuFlashWrite() to use the VMGEXIT MMIO write support to have the hypervisor perform the write without having to emulate the instruction. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- .../FvbServicesRuntimeDxe.inf | 2 + .../QemuFlash.h | 13 ++++++ .../QemuFlash.c | 23 +++++++++-- .../QemuFlashDxe.c | 40 +++++++++++++++++++ .../QemuFlashSmm.c | 16 ++++++++ 5 files changed, 91 insertions(+), 3 deletions(-) diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.i= nf b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf index 72cabba4357d..8bb2325157ea 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf @@ -38,6 +38,7 @@ [Sources] [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec + UefiCpuPkg/UefiCpuPkg.dec OvmfPkg/OvmfPkg.dec =20 [LibraryClasses] @@ -52,6 +53,7 @@ [LibraryClasses] UefiBootServicesTableLib UefiDriverEntryPoint UefiRuntimeLib + VmgExitLib =20 [Guids] gEfiEventVirtualAddressChangeGuid # ALWAYS_CONSUMED diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h b/OvmfPkg/Q= emuFlashFvbServicesRuntimeDxe/QemuFlash.h index f1afabcbe6ae..219d0d6e83cf 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h @@ -89,5 +89,18 @@ QemuFlashBeforeProbe ( IN UINTN FdBlockCount ); =20 +/** + Write to QEMU Flash + + @param[in] Ptr Pointer to the location to write. + @param[in] Value The value to write. + +**/ +VOID +QemuFlashPtrWrite ( + IN volatile UINT8 *Ptr, + IN UINT8 Value + ); + #endif =20 diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c b/OvmfPkg/Q= emuFlashFvbServicesRuntimeDxe/QemuFlash.c index 1b0d6c053f1a..0d29bf701aca 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c @@ -9,6 +9,7 @@ =20 #include #include +#include #include =20 #include "QemuFlash.h" @@ -80,6 +81,21 @@ QemuFlashDetected ( =20 DEBUG ((DEBUG_INFO, "QEMU Flash: Attempting flash detection at %p\n", Pt= r)); =20 + if (MemEncryptSevEsIsEnabled ()) { + // + // When SEV-ES is enabled, the check below can result in an infinite + // loop with respect to a nested page fault. When the memslot is mapped + // read-only, the nested page table entry is read-only. The check below + // will cause a nested page fault that cannot be emulated, causing + // the instruction to retried over and over. For SEV-ES, acknowledge t= hat + // the FD appears as ROM and not as FLASH, but report FLASH anyway bec= ause + // FLASH behavior can be simulated using VMGEXIT. + // + DEBUG ((DEBUG_INFO, + "QEMU Flash: SEV-ES enabled, assuming FD behaves as FLASH\n")); + return TRUE; + } + OriginalUint8 =3D *Ptr; *Ptr =3D CLEAR_STATUS_CMD; ProbeUint8 =3D *Ptr; @@ -181,8 +197,9 @@ QemuFlashWrite ( // Ptr =3D QemuFlashPtr (Lba, Offset); for (Loop =3D 0; Loop < *NumBytes; Loop++) { - *Ptr =3D WRITE_BYTE_CMD; - *Ptr =3D Buffer[Loop]; + QemuFlashPtrWrite (Ptr, WRITE_BYTE_CMD); + QemuFlashPtrWrite (Ptr, Buffer[Loop]); + Ptr++; } =20 @@ -190,7 +207,7 @@ QemuFlashWrite ( // Restore flash to read mode // if (*NumBytes > 0) { - *(Ptr - 1) =3D READ_ARRAY_CMD; + QemuFlashPtrWrite (Ptr - 1, READ_ARRAY_CMD); } =20 return EFI_SUCCESS; diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c b/OvmfPk= g/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c index 5aabe9d7b59c..565383ee26d2 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c @@ -10,6 +10,9 @@ **/ =20 #include +#include +#include +#include =20 #include "QemuFlash.h" =20 @@ -32,3 +35,40 @@ QemuFlashBeforeProbe ( // Do nothing // } + +/** + Write to QEMU Flash + + @param[in] Ptr Pointer to the location to write. + @param[in] Value The value to write. + +**/ +VOID +QemuFlashPtrWrite ( + IN volatile UINT8 *Ptr, + IN UINT8 Value + ) +{ + if (MemEncryptSevEsIsEnabled ()) { + MSR_SEV_ES_GHCB_REGISTER Msr; + GHCB *Ghcb; + + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + Ghcb =3D Msr.Ghcb; + + // + // Writing to flash is emulated by the hypervisor through the use of w= rite + // protection. This won't work for an SEV-ES guest because the write w= on't + // be recognized as a true MMIO write, which would result in the requi= red + // #VC exception. Instead, use the the VMGEXIT MMIO write support dire= ctly + // to perform the update. + // + VmgInit (Ghcb); + Ghcb->SharedBuffer[0] =3D Value; + Ghcb->SaveArea.SwScratch =3D (UINT64) (UINTN) Ghcb->SharedBuffer; + VmgExit (Ghcb, SVM_EXIT_MMIO_WRITE, (UINT64) (UINTN) Ptr, 1); + VmgDone (Ghcb); + } else { + *Ptr =3D Value; + } +} diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashSmm.c b/OvmfPk= g/QemuFlashFvbServicesRuntimeDxe/QemuFlashSmm.c index 7eb426e03855..7eb80bfeffae 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashSmm.c +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashSmm.c @@ -46,3 +46,19 @@ QemuFlashBeforeProbe ( ); ASSERT_EFI_ERROR (Status); } + +/** + Write to QEMU Flash + + @param[in] Ptr Pointer to the location to write. + @param[in] Value The value to write. + +**/ +VOID +QemuFlashPtrWrite ( + IN volatile UINT8 *Ptr, + IN UINT8 Value + ) +{ + *Ptr =3D Value; +} --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62542): https://edk2.groups.io/g/devel/message/62542 Mute This Topic: https://groups.io/mt/75500022/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62562+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62562+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594756239455679.7292577612136; Tue, 14 Jul 2020 12:50:39 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id hlCLYY1788612x8UanXOGxud; Tue, 14 Jul 2020 12:50:39 -0700 X-Received: from NAM02-CY1-obe.outbound.protection.outlook.com (NAM02-CY1-obe.outbound.protection.outlook.com [40.107.76.74]) by mx.groups.io with SMTP id smtpd.web11.4815.1594756238311396655 for ; Tue, 14 Jul 2020 12:50:38 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NPWmR9Wx0dVKtp8DTHkzEU1g8+sHqmyiaZCSsbIUe8PiPmMb7A18cvOFuBY10x7o1qnqLCs2n2aRHhIzufoiYMT+fT9soTeg9FN3gdKIg46gGmdhi93MlJqfrTRmmvKLaA5u3MTkPvlwzsvhJsQAjthEPNz1g9qqoezYgIs7XS8anRbIfUbdmRgysfeU+dgSH9suBK17RT0/U0ynU25O4/JFo+7u20ZCDSS6BjiIbaKTE2R+rBlNcrUrlj9NQenaZ/qXsaYv/L0NjWm+YqH4AF8NjipFGxSsyVMH0Vc1pHbXaYlwBXvA8lfXAzu56xZeUO+HqqeNkcMVr6iZPGZHrQ== 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=y42cNfhmfyz07xseYeQYH9zbpfMlzMLWf83yCfosPcg=; b=lUqTI5+FhCwVw2iUGnDswEttI8wl+nurDaUs2AthUul1zRieGm6KEO3Y+bFjkvHKpa7UtCvzXgzYmtaP8J2u56CYyDau6+5ygvdCeEiB/WyRuzgVfWpOaX3wjBCjl53+zbeFpxdex8KqQeROKHn45yiAlbRx2ZCLe74UZ2NOCf5MFWFIl6JEXSlHgn5Zr/EwtKsVg08z8ZpEv5NJfFHkHgvlQkiAGXDgOOUupsqbdXwkhcFK0QN/Oq0SY3/tAUe3ecVut50m9EgchQvIztmirvB4o3xoMNSGjSCav/oKeiSaW1WvSMoJkLCZSbI24qwNYd6sDmQiPVuN8wYBWo8Hag== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB1834.namprd12.prod.outlook.com (2603:10b6:3:10a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 19:50:37 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 19:50:37 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v10 40/46] UefiCpuPkg: Add a 16-bit protected mode code segment descriptor Date: Tue, 14 Jul 2020 14:50:20 -0500 Message-ID: <3eb2b59947bbe3875e68638a7f64d1bcf917ef3d.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0016.namprd21.prod.outlook.com (2603:10b6:805:106::26) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR2101CA0016.namprd21.prod.outlook.com (2603:10b6:805:106::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.7 via Frontend Transport; Tue, 14 Jul 2020 19:50:36 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: a3074498-0161-4a94-70f0-08d8282f2d9a X-MS-TrafficTypeDiagnostic: DM5PR12MB1834: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: VBgYDaWto3NojdGFfijpspjv2FgkhZdEscGp/aN4AY6aomr1KMnaf2Z1+mntgo1L2CJiBQEiVag6gqIhaCFhNWHLtlWOieOevCTdySfEfJDQln9hzZ8FHPGnUFB3boTpdO3qLpuEptVnAG2h4245XnVXxsQ50ydp8hULe1Z0SuEjoPUtL06bkp07tPqIBGFeLyB48rsLzJwBz730viCQKFCgMFFObUFPe8Gmxlsd4oP8x2t8lxrom918c/jgyGpJ/0lSYrfkI6b0C2SNqkBtRczheTxNQ2VqvX8AKYT45VWwh6Qk0NBiRQlPgQl7S0+tElGsKXEZgXrC/zv27S0stD26bVoPy/SmKgCQl4DU9k67e7+UcBXwXXWhB3/0WRMGzWDZIxqSYVXJn+9za9lkhM67GpIXURgDnktIREXbMvpw3sw/snjhxIGHuuBgVgwp/w/rg3YiTpYpWofHKxhseA== X-MS-Exchange-AntiSpam-MessageData: YWP3hawbNuwBLcsXBxDBwZxcpdtJepPdIXx1vPPPzXVMFSr/hcVpDzAhCW7Ow9zZ+OV/25IO6L9AvgkadwMEout7jGRYbpUwDqsgGUMEK9jlciudkEtWyxQtcOyJPl/Dc46bL4HrNdxVj6sjZfyXzg/jLJQxGw/6cUZ8hcUuisR4kMmAH6d6wG9AOJ/eOknqTjuy+HXiXMcSXCEnLqopXTHCq99/Sz4BOchwd93FqTQThKF4kuzTDdmxAhYo7CC4elPCGxmtPFdw1MLCPqz1c/2fbxQfFLZT2hJM+J6pONYCufxS05QXwIMRTBu+9AVZU/BATaFAEKfHQRxYoP8z53Eallopby7ZAS8vaFeaLnmhxkpgd8tmQ7C9no7cH5rPRySiW1LnRmcZrJmvHdnJCzHOpP2P2T0KYf6R8EXbo1xwF96PkEYwmQ9ZIeOd63BgBNbiZ1ziezGtsMW+rEph+VAzge7tbhovk6dBpr9CEK0= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a3074498-0161-4a94-70f0-08d8282f2d9a X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 19:50:36.8854 (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: 1WYipZwCckiNLQwJl8dVoVEB0/vIblm/5tru3M8gHT8Zp44p677KTROrgsLbdRtSDLQj9VA2OMi/uaQs9yKp3g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1834 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: J73zLBuWyStXfaNatRrnzBA4x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594756239; bh=RGh2nvQDR66fCvjhWSO/Zgy2pZA5tbHXYHl8y3KqpCA=; h=Content-Type:Date:From:Reply-To:Subject:To; b=YeSyX1jAKqUFUsIhUrvYRW1dSMouJsUjJsso6KwBIeKo20TcEUCuWUMdAZHf8jmsGTz 3yfV+eOetmOcdcAapskRaPeQhyMol9OG9s3jASt4N6SksxWtMp07uqmaHexGzbWRFDvCr t/ncDJ24GVukqlWxXVyDN9oqpzxagW8OMmk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 A hypervisor is not allowed to update an SEV-ES guests register state, so when booting an SEV-ES guest AP, the hypervisor is not allowed to set the RIP to the guest requested value. Instead, an SEV-ES AP must be transition from 64-bit long mode to 16-bit real mode in response to an INIT-SIPI-SIPI sequence. This requires a 16-bit code segment descriptor. For PEI, create this descriptor in the reset vector GDT table. For DXE, create this descriptor from the newly reserved entry at location 0x28. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Reviewed-by: Eric Dong Signed-off-by: Tom Lendacky --- UefiCpuPkg/CpuDxe/CpuGdt.h | 4 ++-- UefiCpuPkg/CpuDxe/CpuGdt.c | 8 ++++---- UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm | 9 +++++++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/UefiCpuPkg/CpuDxe/CpuGdt.h b/UefiCpuPkg/CpuDxe/CpuGdt.h index 3a0210b2f172..1c94487cbee8 100644 --- a/UefiCpuPkg/CpuDxe/CpuGdt.h +++ b/UefiCpuPkg/CpuDxe/CpuGdt.h @@ -36,7 +36,7 @@ struct _GDT_ENTRIES { GDT_ENTRY LinearCode; GDT_ENTRY SysData; GDT_ENTRY SysCode; - GDT_ENTRY Spare4; + GDT_ENTRY SysCode16; GDT_ENTRY LinearData64; GDT_ENTRY LinearCode64; GDT_ENTRY Spare5; @@ -49,7 +49,7 @@ struct _GDT_ENTRIES { #define LINEAR_CODE_SEL OFFSET_OF (GDT_ENTRIES, LinearCode) #define SYS_DATA_SEL OFFSET_OF (GDT_ENTRIES, SysData) #define SYS_CODE_SEL OFFSET_OF (GDT_ENTRIES, SysCode) -#define SPARE4_SEL OFFSET_OF (GDT_ENTRIES, Spare4) +#define SYS_CODE16_SEL OFFSET_OF (GDT_ENTRIES, SysCode16) #define LINEAR_DATA64_SEL OFFSET_OF (GDT_ENTRIES, LinearData64) #define LINEAR_CODE64_SEL OFFSET_OF (GDT_ENTRIES, LinearCode64) #define SPARE5_SEL OFFSET_OF (GDT_ENTRIES, Spare5) diff --git a/UefiCpuPkg/CpuDxe/CpuGdt.c b/UefiCpuPkg/CpuDxe/CpuGdt.c index 64efadeba601..a1ab543f2da5 100644 --- a/UefiCpuPkg/CpuDxe/CpuGdt.c +++ b/UefiCpuPkg/CpuDxe/CpuGdt.c @@ -70,14 +70,14 @@ STATIC GDT_ENTRIES GdtTemplate =3D { 0x0, }, // - // SPARE4_SEL + // SYS_CODE16_SEL // { - 0x0, // limit 15:0 + 0x0FFFF, // limit 15:0 0x0, // base 15:0 0x0, // base 23:16 - 0x0, // type - 0x0, // limit 19:16, flags + 0x09A, // present, ring 0, code, execute/read + 0x08F, // page-granular, 16-bit 0x0, // base 31:24 }, // diff --git a/UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm b/UefiCpuP= kg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm index ce4ebfffb688..0e79a3984b16 100644 --- a/UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm +++ b/UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm @@ -129,5 +129,14 @@ LINEAR_CODE64_SEL equ $-GDT_BASE DB 0 ; base 31:24 %endif =20 +; linear code segment descriptor +LINEAR_CODE16_SEL equ $-GDT_BASE + DW 0xffff ; limit 15:0 + DW 0 ; base 15:0 + DB 0 ; base 23:16 + DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE32_TYPE) + DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(0)|CODE64_FLAG(0)|UPPER_LIM= IT(0xf) + DB 0 ; base 31:24 + GDT_END: =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62562): https://edk2.groups.io/g/devel/message/62562 Mute This Topic: https://groups.io/mt/75506899/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62563+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62563+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594756248396290.22117560915365; Tue, 14 Jul 2020 12:50:48 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id oLiWYY1788612x8UkOGO8qI2; Tue, 14 Jul 2020 12:50:48 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.47]) by mx.groups.io with SMTP id smtpd.web12.4689.1594756247116778398 for ; Tue, 14 Jul 2020 12:50:47 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GCsDRxtc54jEPTX5/BePmiiruess+BGNJYkS9sQ1k19yZGnlXbs94NaFIqc0ewyo5c+LyFEUDAMiXrLUj/lLVxnpuDgImrgRs7bk6v8iIU5oixQtbaEFH/32+m5aCwx2jDyIqGL5ZiVb9/2Xei08kpg3YNo3aXKEt/MKTZrjENhiMXDtY9eJ7bgsxZwYMlwckh4doZWyopan0A5rw7Ap4DMk/WPDyAxW6f4yEGhc9CHIa/pvTErrZZvVom2ScbXtLO4IxW5ZMNO6B7+A45QT/NsXqgfqOv90Us7DUaPXJ/mTEKQUjKWGIAd4RCvXV5kmNb8ioTSnBHGmaPXrCtjxOg== 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=2xL2RAVEP5XW/LxYrRr+kHwaYvf60goYc3Dt2uOHhXI=; b=oUWaeELNSZrb79mTZeuM3jqogaWt+skecDpn/RWjoE2y8o897UhuTv2qyO1ZdJ4eMXe0OGT3FzbbKy2WCFIr8vtSoRhxwiHUW9PnN51h6SSZuUfqV1+nldbQZAhks50+URVVhplL+SIsflu3ycXykpFWpaQdBNKw8TCxiDKLHkVbwUwYvwQQf6N+vFEiMIVnsTa5FEZKw/hbonSrBEZr6fN4nSzm/I60e14Wm7JP8BeRrqmzRvTpeq767lkYPBLZ4qyCcbUPSspXy/im4ofMlvY7KIHhbpkxp8yvmuO57zcnJF2pUDkP1vzhKFm9XjwGeDGFYwdNqaeIpbkG/PWx8Q== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB1834.namprd12.prod.outlook.com (2603:10b6:3:10a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 19:50:44 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 19:50:44 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v10 41/46] UefiCpuPkg/MpInitLib: Add CPU MP data flag to indicate if SEV-ES is enabled Date: Tue, 14 Jul 2020 14:50:21 -0500 Message-ID: <2ff5bc297b876c8426b7c5515380450efad27203.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN1PR12CA0085.namprd12.prod.outlook.com (2603:10b6:802:21::20) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN1PR12CA0085.namprd12.prod.outlook.com (2603:10b6:802:21::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17 via Frontend Transport; Tue, 14 Jul 2020 19:50:44 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: cc168aa4-124a-4fc8-bbec-08d8282f3211 X-MS-TrafficTypeDiagnostic: DM5PR12MB1834: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: HutvJVS/d/mdOr+Wrrmd39BEjcgH0nQyYtuDU6XTEczrHCnJTi3YvTYZqqa2cT3VsFM65Fdhfl14sShsW9KEh7folZ+g7neTCNrhsxED+H+FUzqhU8IWKafz3AbuAGO4gkmpv1o8srSqa/EEvs3egP5aMTD7++nzpkWssyCqALNPiOE99dHrsOMge4Ui/rX1rvtkUwKiTegnsJi9mznUKhb5qSDZ9caMgWRmmdrCmQWp8NjFgR00iDxOfKB4GEWngioLQJkjQrdQV900u7ZFJHk57DqyhwA9kB1CUXde9vFFebnx0Rm1OH1+hlR0pdiDEBZ9Fb5xo77fChT25cbyjg+bRzwSjtzqj9U78TfRwUyMymrGFM/+n9YnpgfOe1ougyChya7suSXqoKJdM0z+w7s0F5m8SOZXfEp7nFRcod9TqqQT+d8rcpDgl+Ihayhg2nIckcVUkFAtPE524pcsLA== X-MS-Exchange-AntiSpam-MessageData: ztdrmsqP41SUJj06N288L71d1K+A3bUCAj6SjT073v+fkHmf6/c+NadngR5TcJ+/4gtlUHuaVDk1SWw4YzwKC57ZajU8wkp/9ucoGGTm68JLq2lGwjJicucbkRAHZZ/+rbB1J7CW2eNA/FgnUobOgQWdKXzMfR2e2Q8tngvuyhX3Ng9V1UlNKUtQG1VJ7sbL5D1RpbdY7nkEsYUvj4ZaEv09+WMcOb+8KvTSp1aB8SsdgDBI2fLK6rFQAfxt9CvSArhLdrgg8ssuQSoQtUUsd8BL2NmA4LJEtsAARUBLGUDpLkZ8gvLOFv43ZB+rkD2ZaTwIKIT/gizccrPt1q5/+tI1K9SD3j1Mfh+F14GHXg6KNd91lUdqJCs/nsl7Fx0/AqUjGjwwVOrw/YaPaeiAtN6NOPFQvgu34BabL1ZyWQ0rg8l/zoeJFVPWwV12RdsgidmwpnfljPxOO8g1IXsgr8xUfUFFenfD38ZebWyNgfo= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: cc168aa4-124a-4fc8-bbec-08d8282f3211 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 19:50:44.2901 (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: lBZdWsnM8mEGRctW2hLkRHgKuklj2gMD7A1QRw1NjXKkViBHHfubpmRIQt0VLek9I0b2qW0sJqGIdyo28I2WWA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1834 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: ndCRxJ397vAbjXZpSmvxK1qQx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594756248; bh=NmH363YyjhlX3lAsfVw2C8FBUZy3pxsEXYdN5TMdcdk=; h=Content-Type:Date:From:Reply-To:Subject:To; b=FJX9e5wKIEyKriwJjHLoyEjrq1uFC4xuC3VeLgOO3uZODqAyoyroc2219gQB2myPldN rhOsnFDPIJQlJeC2CxE4JPOYpSiUolh6Q9KWTe+Q2jlxb21U0xLVZAmzwUdi8FPDWwEVD rSDVI0H6eQVJERD3FtZ9GH1KTkIAQpy6YKc= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 When starting APs in an SMP configuration, the AP needs to know if it is running as an SEV-ES guest in order to assign a GHCB page. Add a field to the CPU_MP_DATA structure that will indicate if SEV-ES is enabled. This new field is set during MP library initialization with the PCD value PcdSevEsIsEnabled. This flag can then be used to determine if SEV-ES is enabled. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Reviewed-by: Eric Dong Signed-off-by: Tom Lendacky --- UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf | 1 + UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf | 1 + UefiCpuPkg/Library/MpInitLib/MpLib.h | 2 ++ UefiCpuPkg/Library/MpInitLib/MpLib.c | 1 + 4 files changed, 5 insertions(+) diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/DxeMpInitLib.inf index 9907f4157b09..583276595619 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf @@ -71,4 +71,5 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuApLoopMode ## = CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate ## = SOMETIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApStatusCheckIntervalInMicroSeconds ## = CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled ## = CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ## = CONSUMES diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/PeiMpInitLib.inf index 89ee9a79d8c5..4b3d39fbf36c 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf @@ -61,6 +61,7 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchRegionSize ## CONS= UMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApLoopMode ## CONS= UMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate ## SOME= TIMES_CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled ## CONS= UMES =20 [Ppis] gEdkiiPeiShadowMicrocodePpiGuid ## SOMETIMES_CONSUMES diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index a8ca03efb8e3..5b46c295b6b2 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -276,6 +276,8 @@ struct _CPU_MP_DATA { // driver. // BOOLEAN WakeUpByInitSipiSipi; + + BOOLEAN SevEsIsEnabled; }; =20 extern EFI_GUID mCpuInitMpLibHobGuid; diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 9b0660a5d4ea..2a3fbeef35f7 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -1704,6 +1704,7 @@ MpInitLibInitialize ( CpuMpData->CpuData =3D (CPU_AP_DATA *) (CpuMpData + 1); CpuMpData->CpuInfoInHob =3D (UINT64) (UINTN) (CpuMpData->CpuData + M= axLogicalProcessorNumber); InitializeSpinLock(&CpuMpData->MpLock); + CpuMpData->SevEsIsEnabled =3D PcdGetBool (PcdSevEsIsEnabled); =20 // // Make sure no memory usage outside of the allocated buffer. --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62563): https://edk2.groups.io/g/devel/message/62563 Mute This Topic: https://groups.io/mt/75506902/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62564+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62564+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594756255410698.4922767215878; Tue, 14 Jul 2020 12:50:55 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id k68oYY1788612xjFBwfEz8AH; Tue, 14 Jul 2020 12:50:55 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.50]) by mx.groups.io with SMTP id smtpd.web11.4822.1594756253872913325 for ; Tue, 14 Jul 2020 12:50:54 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TGUoIyKj8pJ5CRt1+tviJ3lnFY6t4GY3gFXV3gNZ9jXkCaPJ/PWSyAyEHs27kum2aCVMqGF6qk92Td1qmxlEF8xgay4Z6GWjv9t+PUz4V7l46+sXkQ2YfF199hr0ESP6A9O9Lcnklf8heeX4XnU0/KsbEirCmr9wUBY+25B49DOY1wz40qKl9NMTtSdAp7GowZFcUFqy4g0nYgx0yFf6h/bqUGvk2xL6S1JmG/KIqQo9929jMRPnHAzjvscVGyqY0Mx5bzqhU3hV7g3ngZkQlhgNlo5LGH44ra150mbZsmi2+GMsFnYBOvtFeqU5LWfvCv/HgMUY8cMOASD/B7tEhg== 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=V1pSSQpiriFnKN4ZsJ65oCFFFtP7LbLiC6pkSiYbIQ4=; b=kWKOG5p2/P6PoFRhZRH7oR3BnzlziJzdYFTrGxotSjPgsukNjxRZF72IfhJHCBbnfg0vEiRvYvEaZkbTajLMiTVw7s/L4OhCtQYvcN4mJfnHMel17aXm3lqze8lojW5GF3pTzbfU4rRO6HpXu0GaV6AzYpw3MTdC0xICltAHqxnFw1HnWcP14sn3p/5Sal5QRevYsjsf1CZ7/rY+Z7UWGGz6gVvSfNjtcdA3EOIEBz5Eo+FRkPl+UAZbNpYcejA6NVRZaM81X377g/ttjMYOm9fuyY642iRdTAzCqZ5kVDQ0VAKw7z5tZcjtdlf3sACpDllvYjk0ZiRAgUw/EL1ovQ== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB1834.namprd12.prod.outlook.com (2603:10b6:3:10a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 19:50:52 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 19:50:52 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v10 42/46] UefiCpuPkg: Allow AP booting under SEV-ES Date: Tue, 14 Jul 2020 14:50:22 -0500 Message-ID: <1dab98378f132f176345756ed09a602c86dab6d6.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN6PR08CA0014.namprd08.prod.outlook.com (2603:10b6:805:66::27) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR08CA0014.namprd08.prod.outlook.com (2603:10b6:805:66::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22 via Frontend Transport; Tue, 14 Jul 2020 19:50:51 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 477c60d1-734e-49e6-d2ab-08d8282f368e X-MS-TrafficTypeDiagnostic: DM5PR12MB1834: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: Sj00VOizORM96TxzbXqKl04kIKMoF6hi3GKNriskmaWAdSOhbRsdEBeQJf3/8l0LjPfw+KNig9YYoh/bf7fJ7TQ9Jz20QvTedtiyTAZ9rRVP2v8wQd60YhzjkvYm7dM9d/KfYUQJ0u7hHQe5I3Lm65iNza4UxOumaaXLKFiFA55AxCW75LyiURZx7/LpIbFfX86Bm1sxdpQKxSJ97pBVvmW+rx5ULeTK3MplGC4M7rmrPqEHbcOaNRFoimRcie5sBxKaI7l2EZMJzb7xq2WVNo+qCN7XRIJCfFhdwbiJY2dv2Rul+LSsZjS3vLTnizb0NUoVn3JOC6emwTL7999NIcC2B85FGKOw+tDisvf0jJAVieGTxCr2+BOSnWqIsz0lKal8KY8IyGG2gBDD2Ix2a8yxcRrZvKHWjQ0AoH3ABbOMMEA77FuFSGCIRYnOOUi5U0609SclwdmOje18eFAnjQ== X-MS-Exchange-AntiSpam-MessageData: RZI3GTncL36i3CkkgMJ+XdUUDAn98rl3N1sEdggOZSfOxk8ydEE/N+f6YgRGmm8uwkpo2C2RyviQmB3EJvYLJxiY/IXscwdjM6EzrXDs5sUs+GztbhO6SXf8SR6zKYy0HKApbu92d7Tju6joLfHrGTQmWniO5Yp/9QBaUreWgQmKLizrg56AWXeRCIzDLp6HZNawPSE4xSZ6D7pDlkd1bK3q77O6LxcFbNqcykU5RtHvG/fBwH8oUHpY0XtpK3oXshrw+ZYAhe28v2OQFvojYfdjrcDDSpZuXtWgXJhSz0NlE3ilivJfJUV7ehX5IC6aWTLW+OfLLFuL/BCUHxB9RVoLVHmi8+Srkmi9ohF5U/fvZdBKHVPI+8rqciUoZRHOVY7NnTVLJ4I0+HQCOarmWaSNu0rde/tymF/mr/bxvsyTeQ/2u92nID9mAhSw+Ln4ydeSNSHqxuVONl5sMLmmb0zVq5eUORQb2kTocgyqeVw= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 477c60d1-734e-49e6-d2ab-08d8282f368e X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 19:50:52.0337 (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: c4MS7cZEiX5cjirG91ub3ntpkRex4H1TdX1/4TQSEVtflDXXeUC2GUJCrRXT2UU+2SWtZyQPr+68OPg4sNHoLw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1834 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: 86fHX3b9kAyH85Q4cwHd4v59x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594756255; bh=VOLUAFrWBji/OFs1V+QrnQTZWvmg28ZePWLzsKlb3j8=; h=Content-Type:Date:From:Reply-To:Subject:To; b=RbqyiP3ymJ4cxnV7iboivg1pDP+JsTaS7T+9785WBuQRdooTLnvskMXc6mmxmTEiCql DcHGNaYoIuepT65WuWJ3t6Ni7XKXz4i/A4C5WdtGsRm58d9OdU/0eNEzeJFkcjPfU6sYG McWAfIIMfGRF3ZVflwKTUSZmgir0KuzAGPI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Typically, an AP is booted using the INIT-SIPI-SIPI sequence. This sequence is intercepted by the hypervisor, which sets the AP's registers to the values requested by the sequence. At that point, the hypervisor can start the AP, which will then begin execution at the appropriate location. Under SEV-ES, AP booting presents some challenges since the hypervisor is not allowed to alter the AP's register state. In this situation, we have to distinguish between the AP's first boot and AP's subsequent boots. First boot: Once the AP's register state has been defined (which is before the guest is first booted) it cannot be altered. Should the hypervisor attempt to alter the register state, the change would be detected by the hardware and the VMRUN instruction would fail. Given this, the first boot for the AP is required to begin execution with this initial register state, which is typically the reset vector. This prevents the BSP from directing the AP startup location through the INIT-SIPI-SIPI sequence. To work around this, the firmware will provide a build time reserved area that can be used as the initial IP value. The hypervisor can extract this location value by checking for the SEV-ES reset block GUID that must be located 48-bytes from the end of the firmware. The format of the SEV-ES reset block area is: 0x00 - 0x01 - SEV-ES Reset IP 0x02 - 0x03 - SEV-ES Reset CS Segment Base[31:16] 0x04 - 0x05 - Size of the SEV-ES reset block 0x06 - 0x15 - SEV-ES Reset Block GUID (00f771de-1a7e-4fcb-890e-68c77e2fb44e) The total size is 22 bytes. Any expansion to this block must be done by adding new values before existing values. The hypervisor will use the IP and CS values obtained from the SEV-ES reset block to set as the AP's initial values. The CS Segment Base represents the upper 16 bits of the CS segment base and must be left shifted by 16 bits to form the complete CS segment base value. Before booting the AP for the first time, the BSP must initialize the SEV-ES reset area. This consists of programming a FAR JMP instruction to the contents of a memory location that is also located in the SEV-ES reset area. The BSP must program the IP and CS values for the FAR JMP based on values drived from the INIT-SIPI-SIPI sequence. Subsequent boots: Again, the hypervisor cannot alter the AP register state, so a method is required to take the AP out of halt state and redirect it to the desired IP location. If it is determined that the AP is running in an SEV-ES guest, then instead of calling CpuSleep(), a VMGEXIT is issued with the AP Reset Hold exit code (0x80000004). The hypervisor will put the AP in a halt state, waiting for an INIT-SIPI-SIPI sequence. Once the sequence is recognized, the hypervisor will resume the AP. At this point the AP must transition from the current 64-bit long mode down to 16-bit real mode and begin executing at the derived location from the INIT-SIPI-SIPI sequence. Another change is around the area of obtaining the (x2)APIC ID during AP startup. During AP startup, the AP can't take a #VC exception before the AP has established a stack. However, the AP stack is set by using the (x2)APIC ID, which is obtained through CPUID instructions. A CPUID instruction will cause a #VC, so a different method must be used. The GHCB protocol supports a method to obtain CPUID information from the hypervisor through the GHCB MSR. This method does not require a stack, so it is used to obtain the necessary CPUID information to determine the (x2)APIC ID. The new 16-bit protected mode GDT entry is used in order to transition from 64-bit long mode down to 16-bit real mode. A new assembler routine is created that takes the AP from 64-bit long mode to 16-bit real mode. This is located under 1MB in memory and transitions from 64-bit long mode to 32-bit compatibility mode to 16-bit protected mode and finally 16-bit real mode. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Signed-off-by: Tom Lendacky Reviewed-by: Eric Dong --- UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf | 3 + UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf | 3 + UefiCpuPkg/Library/MpInitLib/MpLib.h | 60 ++++ UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 70 +++- UefiCpuPkg/Library/MpInitLib/MpLib.c | 336 +++++++++++++++++- UefiCpuPkg/Library/MpInitLib/PeiMpLib.c | 19 + UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmFuncsArch.c | 2 +- UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc | 2 +- .../Library/MpInitLib/Ia32/MpFuncs.nasm | 15 + UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc | 4 +- UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 239 +++++++++++++ 11 files changed, 738 insertions(+), 15 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/DxeMpInitLib.inf index 583276595619..1771575c69c1 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf @@ -52,6 +52,7 @@ [LibraryClasses] DebugAgentLib SynchronizationLib PcdLib + VmgExitLib =20 [Protocols] gEfiTimerArchProtocolGuid ## SOMETIMES_CONSUMES @@ -72,4 +73,6 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate ## = SOMETIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApStatusCheckIntervalInMicroSeconds ## = CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled ## = CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase ## = SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ## = CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase ## = CONSUMES diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/PeiMpInitLib.inf index 4b3d39fbf36c..34abf25d43cd 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf @@ -51,6 +51,7 @@ [LibraryClasses] SynchronizationLib PeiServicesLib PcdLib + VmgExitLib =20 [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber ## CONS= UMES @@ -62,6 +63,8 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuApLoopMode ## CONS= UMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate ## SOME= TIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled ## CONS= UMES + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase ## SOME= TIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase ## CONS= UMES =20 [Ppis] gEdkiiPeiShadowMicrocodePpiGuid ## SOMETIMES_CONSUMES diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index 5b46c295b6b2..b1a9d99cb3eb 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -173,6 +173,11 @@ typedef struct { UINT8 *RelocateApLoopFuncAddress; UINTN RelocateApLoopFuncSize; UINTN ModeTransitionOffset; + UINTN SwitchToRealSize; + UINTN SwitchToRealOffset; + UINTN SwitchToRealNoNxOffset; + UINTN SwitchToRealPM16ModeOffset; + UINTN SwitchToRealPM16ModeSize; } MP_ASSEMBLY_ADDRESS_MAP; =20 typedef struct _CPU_MP_DATA CPU_MP_DATA; @@ -211,6 +216,8 @@ typedef struct { // Enable5LevelPaging indicates whether 5-level paging is enabled in lon= g mode. // BOOLEAN Enable5LevelPaging; + BOOLEAN SevEsIsEnabled; + UINTN GhcbBase; } MP_CPU_EXCHANGE_INFO; =20 #pragma pack() @@ -257,6 +264,7 @@ struct _CPU_MP_DATA { UINT8 ApLoopMode; UINT8 ApTargetCState; UINT16 PmCodeSegment; + UINT16 Pm16CodeSegment; CPU_AP_DATA *CpuData; volatile MP_CPU_EXCHANGE_INFO *MpCpuExchangeInfo; =20 @@ -278,8 +286,47 @@ struct _CPU_MP_DATA { BOOLEAN WakeUpByInitSipiSipi; =20 BOOLEAN SevEsIsEnabled; + UINTN SevEsAPBuffer; + UINTN SevEsAPResetStackStart; + CPU_MP_DATA *NewCpuMpData; + + UINT64 GhcbBase; }; =20 +#define AP_RESET_STACK_SIZE 64 + +#pragma pack(1) + +typedef struct { + UINT8 InsnBuffer[8]; + UINT16 Rip; + UINT16 Segment; +} SEV_ES_AP_JMP_FAR; + +#pragma pack() + +/** + Assembly code to move an AP from long mode to real mode. + + Move an AP from long mode to real mode in preparation to invoking + the reset vector. This is used for SEV-ES guests where a hypervisor + is not allowed to set the CS and RIP to point to the reset vector. + + @param[in] BufferStart The reset vector target. + @param[in] Code16 16-bit protected mode code segment value. + @param[in] Code32 32-bit protected mode code segment value. + @param[in] StackStart The start of a stack to be used for transitioni= ng + from long mode to real mode. +**/ +typedef +VOID +(EFIAPI AP_RESET) ( + IN UINTN BufferStart, + IN UINT16 Code16, + IN UINT16 Code32, + IN UINTN StackStart + ); + extern EFI_GUID mCpuInitMpLibHobGuid; =20 /** @@ -385,6 +432,19 @@ GetModeTransitionBuffer ( IN UINTN BufferSize ); =20 +/** + Return the address of the SEV-ES AP jump table. + + This buffer is required in order for an SEV-ES guest to transition from + UEFI into an OS. + + @return Return SEV-ES AP jump table buffer +**/ +UINTN +GetSevEsAPMemory ( + VOID + ); + /** This function will be called by BSP to wakeup AP. =20 diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/M= pInitLib/DxeMpLib.c index 8ccddf8e9f9c..9115ff9e3e30 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c @@ -12,6 +12,8 @@ #include #include #include +#include +#include =20 #include =20 @@ -144,6 +146,39 @@ GetModeTransitionBuffer ( return (UINTN)StartAddress; } =20 +/** + Return the address of the SEV-ES AP jump table. + + This buffer is required in order for an SEV-ES guest to transition from + UEFI into an OS. + + @return Return SEV-ES AP jump table buffer +**/ +UINTN +GetSevEsAPMemory ( + VOID + ) +{ + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS StartAddress; + + // + // Allocate 1 page for AP jump table page + // + StartAddress =3D BASE_4GB - 1; + Status =3D gBS->AllocatePages ( + AllocateMaxAddress, + EfiReservedMemoryType, + 1, + &StartAddress + ); + ASSERT_EFI_ERROR (Status); + + DEBUG ((DEBUG_INFO, "Dxe: SevEsAPMemory =3D %lx\n", (UINTN) StartAddress= )); + + return (UINTN) StartAddress; +} + /** Checks APs status and updates APs status if needed. =20 @@ -218,6 +253,38 @@ CheckApsStatus ( } } =20 +/** + Get Protected mode code segment with 16-bit default addressing + from current GDT table. + + @return Protected mode 16-bit code segment value. +**/ +UINT16 +GetProtectedMode16CS ( + VOID + ) +{ + IA32_DESCRIPTOR GdtrDesc; + IA32_SEGMENT_DESCRIPTOR *GdtEntry; + UINTN GdtEntryCount; + UINT16 Index; + + Index =3D (UINT16) -1; + AsmReadGdtr (&GdtrDesc); + GdtEntryCount =3D (GdtrDesc.Limit + 1) / sizeof (IA32_SEGMENT_DESCRIPTOR= ); + GdtEntry =3D (IA32_SEGMENT_DESCRIPTOR *) GdtrDesc.Base; + for (Index =3D 0; Index < GdtEntryCount; Index++) { + if (GdtEntry->Bits.L =3D=3D 0) { + if (GdtEntry->Bits.Type > 8 && GdtEntry->Bits.DB =3D=3D 0) { + break; + } + } + GdtEntry++; + } + ASSERT (Index !=3D GdtEntryCount); + return Index * 8; +} + /** Get Protected mode code segment from current GDT table. =20 @@ -238,7 +305,7 @@ GetProtectedModeCS ( GdtEntry =3D (IA32_SEGMENT_DESCRIPTOR *) GdtrDesc.Base; for (Index =3D 0; Index < GdtEntryCount; Index++) { if (GdtEntry->Bits.L =3D=3D 0) { - if (GdtEntry->Bits.Type > 8 && GdtEntry->Bits.L =3D=3D 0) { + if (GdtEntry->Bits.Type > 8 && GdtEntry->Bits.DB =3D=3D 1) { break; } } @@ -300,6 +367,7 @@ MpInitChangeApLoopCallback ( =20 CpuMpData =3D GetCpuMpData (); CpuMpData->PmCodeSegment =3D GetProtectedModeCS (); + CpuMpData->Pm16CodeSegment =3D GetProtectedMode16CS (); CpuMpData->ApLoopMode =3D PcdGet8 (PcdCpuApLoopMode); mNumberToFinish =3D CpuMpData->CpuCount - 1; WakeUpAP (CpuMpData, TRUE, 0, RelocateApLoop, NULL, TRUE); diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 2a3fbeef35f7..90416c81b616 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -9,6 +9,9 @@ **/ =20 #include "MpLib.h" +#include +#include +#include =20 EFI_GUID mCpuInitMpLibHobGuid =3D CPU_INIT_MP_LIB_HOB_GUID; =20 @@ -291,6 +294,14 @@ GetApLoopMode ( // ApLoopMode =3D ApInHltLoop; } + + if (PcdGetBool (PcdSevEsIsEnabled)) { + // + // For SEV-ES, force AP in Hlt-loop mode in order to use the GHCB + // protocol for starting APs + // + ApLoopMode =3D ApInHltLoop; + } } =20 if (ApLoopMode !=3D ApInMwaitLoop) { @@ -587,6 +598,112 @@ InitializeApData ( SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateIdle); } =20 +/** + Get Protected mode code segment with 16-bit default addressing + from current GDT table. + + @return Protected mode 16-bit code segment value. +**/ +STATIC +UINT16 +GetProtectedMode16CS ( + VOID + ) +{ + IA32_DESCRIPTOR GdtrDesc; + IA32_SEGMENT_DESCRIPTOR *GdtEntry; + UINTN GdtEntryCount; + UINT16 Index; + + Index =3D (UINT16) -1; + AsmReadGdtr (&GdtrDesc); + GdtEntryCount =3D (GdtrDesc.Limit + 1) / sizeof (IA32_SEGMENT_DESCRIPTOR= ); + GdtEntry =3D (IA32_SEGMENT_DESCRIPTOR *) GdtrDesc.Base; + for (Index =3D 0; Index < GdtEntryCount; Index++) { + if (GdtEntry->Bits.L =3D=3D 0 && + GdtEntry->Bits.DB =3D=3D 0 && + GdtEntry->Bits.Type > 8) { + break; + } + GdtEntry++; + } + ASSERT (Index !=3D GdtEntryCount); + return Index * 8; +} + +/** + Get Protected mode code segment with 32-bit default addressing + from current GDT table. + + @return Protected mode 32-bit code segment value. +**/ +STATIC +UINT16 +GetProtectedMode32CS ( + VOID + ) +{ + IA32_DESCRIPTOR GdtrDesc; + IA32_SEGMENT_DESCRIPTOR *GdtEntry; + UINTN GdtEntryCount; + UINT16 Index; + + Index =3D (UINT16) -1; + AsmReadGdtr (&GdtrDesc); + GdtEntryCount =3D (GdtrDesc.Limit + 1) / sizeof (IA32_SEGMENT_DESCRIPTOR= ); + GdtEntry =3D (IA32_SEGMENT_DESCRIPTOR *) GdtrDesc.Base; + for (Index =3D 0; Index < GdtEntryCount; Index++) { + if (GdtEntry->Bits.L =3D=3D 0 && + GdtEntry->Bits.DB =3D=3D 1 && + GdtEntry->Bits.Type > 8) { + break; + } + GdtEntry++; + } + ASSERT (Index !=3D GdtEntryCount); + return Index * 8; +} + +/** + Reset an AP when in SEV-ES mode. + + If successful, this function never returns. + + @param[in] Ghcb Pointer to the GHCB + @param[in] CpuMpData Pointer to CPU MP Data + +**/ +STATIC +VOID +MpInitLibSevEsAPReset ( + IN GHCB *Ghcb, + IN CPU_MP_DATA *CpuMpData + ) +{ + UINT16 Code16, Code32; + AP_RESET *APResetFn; + UINTN BufferStart; + UINTN StackStart; + + Code16 =3D GetProtectedMode16CS (); + Code32 =3D GetProtectedMode32CS (); + + if (CpuMpData->WakeupBufferHigh !=3D 0) { + APResetFn =3D (AP_RESET *) (CpuMpData->WakeupBufferHigh + CpuMpData->A= ddressMap.SwitchToRealNoNxOffset); + } else { + APResetFn =3D (AP_RESET *) (CpuMpData->MpCpuExchangeInfo->BufferStart = + CpuMpData->AddressMap.SwitchToRealOffset); + } + + BufferStart =3D CpuMpData->MpCpuExchangeInfo->BufferStart; + StackStart =3D CpuMpData->SevEsAPResetStackStart - + (AP_RESET_STACK_SIZE * GetApicId ()); + + // + // This call never returns. + // + APResetFn (BufferStart, Code16, Code32, StackStart); +} + /** This function will be called from AP reset code if BSP uses WakeUpAP. =20 @@ -648,7 +765,14 @@ ApWakeupFunction ( InitializeApData (CpuMpData, ProcessorNumber, BistData, ApTopOfStack= ); ApStartupSignalBuffer =3D CpuMpData->CpuData[ProcessorNumber].Startu= pApSignal; =20 - InterlockedDecrement ((UINT32 *) &CpuMpData->MpCpuExchangeInfo->NumA= psExecuting); + // + // Delay decrementing the APs executing count when SEV-ES is enabled + // to allow the APs to issue an AP_RESET_HOLD before the BSP possibly + // performs another INIT-SIPI-SIPI sequence. + // + if (!CpuMpData->SevEsIsEnabled) { + InterlockedDecrement ((UINT32 *) &CpuMpData->MpCpuExchangeInfo->Nu= mApsExecuting); + } } else { // // Execute AP function if AP is ready @@ -755,7 +879,52 @@ ApWakeupFunction ( // while (TRUE) { DisableInterrupts (); - CpuSleep (); + if (CpuMpData->SevEsIsEnabled) { + MSR_SEV_ES_GHCB_REGISTER Msr; + GHCB *Ghcb; + UINT64 Status; + BOOLEAN DoDecrement; + + if (CpuMpData->InitFlag =3D=3D ApInitConfig) { + DoDecrement =3D TRUE; + } + + while (TRUE) { + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + Ghcb =3D Msr.Ghcb; + + VmgInit (Ghcb); + + if (DoDecrement) { + DoDecrement =3D FALSE; + + // + // Perform the delayed decrement just before issuing the fir= st + // VMGEXIT with AP_RESET_HOLD. + // + InterlockedDecrement ((UINT32 *) &CpuMpData->MpCpuExchangeIn= fo->NumApsExecuting); + } + + Status =3D VmgExit (Ghcb, SVM_EXIT_AP_RESET_HOLD, 0, 0); + if ((Status =3D=3D 0) && (Ghcb->SaveArea.SwExitInfo2 !=3D 0)) { + VmgDone (Ghcb); + break; + } + + VmgDone (Ghcb); + } + + // + // Awakened in a new phase? Use the new CpuMpData + // + if (CpuMpData->NewCpuMpData !=3D NULL) { + CpuMpData =3D CpuMpData->NewCpuMpData; + } + + MpInitLibSevEsAPReset (Ghcb, CpuMpData); + } else { + CpuSleep (); + } CpuPause (); } } @@ -868,6 +1037,9 @@ FillExchangeInfoData ( ExchangeInfo->Enable5LevelPaging =3D (BOOLEAN) (Cr4.Bits.LA57 =3D=3D 1); DEBUG ((DEBUG_INFO, "%a: 5-Level Paging =3D %d\n", gEfiCallerBaseName, E= xchangeInfo->Enable5LevelPaging)); =20 + ExchangeInfo->SevEsIsEnabled =3D CpuMpData->SevEsIsEnabled; + ExchangeInfo->GhcbBase =3D (UINTN) CpuMpData->GhcbBase; + // // Get the BSP's data of GDT and IDT // @@ -894,8 +1066,9 @@ FillExchangeInfoData ( // EfiBootServicesCode to avoid page fault if NX memory protection is en= abled. // if (CpuMpData->WakeupBufferHigh !=3D 0) { - Size =3D CpuMpData->AddressMap.RendezvousFunnelSize - - CpuMpData->AddressMap.ModeTransitionOffset; + Size =3D CpuMpData->AddressMap.RendezvousFunnelSize + + CpuMpData->AddressMap.SwitchToRealSize - + CpuMpData->AddressMap.ModeTransitionOffset; CopyMem ( (VOID *)CpuMpData->WakeupBufferHigh, CpuMpData->AddressMap.RendezvousFunnelAddress + @@ -948,7 +1121,8 @@ BackupAndPrepareWakeupBuffer( CopyMem ( (VOID *) CpuMpData->WakeupBuffer, (VOID *) CpuMpData->AddressMap.RendezvousFunnelAddress, - CpuMpData->AddressMap.RendezvousFunnelSize + CpuMpData->AddressMap.RendezvousFunnelSize + + CpuMpData->AddressMap.SwitchToRealSize ); } =20 @@ -969,6 +1143,44 @@ RestoreWakeupBuffer( ); } =20 +/** + Calculate the size of the reset stack. + + @return Total amount of memory required for stacks +**/ +STATIC +UINTN +GetApResetStackSize ( + VOID + ) +{ + return AP_RESET_STACK_SIZE * PcdGet32(PcdCpuMaxLogicalProcessorNumber); +} + +/** + Calculate the size of the reset vector. + + @param[in] AddressMap The pointer to Address Map structure. + + @return Total amount of memory required for the AP reset= area +**/ +STATIC +UINTN +GetApResetVectorSize ( + IN MP_ASSEMBLY_ADDRESS_MAP *AddressMap + ) +{ + UINTN Size; + + Size =3D ALIGN_VALUE (AddressMap->RendezvousFunnelSize + + AddressMap->SwitchToRealSize + + sizeof (MP_CPU_EXCHANGE_INFO), + CPU_STACK_ALIGNMENT); + Size +=3D GetApResetStackSize (); + + return Size; +} + /** Allocate reset vector buffer. =20 @@ -982,16 +1194,22 @@ AllocateResetVector ( UINTN ApResetVectorSize; =20 if (CpuMpData->WakeupBuffer =3D=3D (UINTN) -1) { - ApResetVectorSize =3D CpuMpData->AddressMap.RendezvousFunnelSize + - sizeof (MP_CPU_EXCHANGE_INFO); + ApResetVectorSize =3D GetApResetVectorSize (&CpuMpData->AddressMap); =20 CpuMpData->WakeupBuffer =3D GetWakeupBuffer (ApResetVectorSize); CpuMpData->MpCpuExchangeInfo =3D (MP_CPU_EXCHANGE_INFO *) (UINTN) - (CpuMpData->WakeupBuffer + CpuMpData->AddressMap.Rende= zvousFunnelSize); + (CpuMpData->WakeupBuffer + + CpuMpData->AddressMap.RendezvousFunnelSize + + CpuMpData->AddressMap.SwitchToRealSize); CpuMpData->WakeupBufferHigh =3D GetModeTransitionBuffer ( - CpuMpData->AddressMap.RendezvousFunnel= Size - + CpuMpData->AddressMap.RendezvousFunnel= Size + + CpuMpData->AddressMap.SwitchToRealSize= - CpuMpData->AddressMap.ModeTransitionOf= fset ); + // + // The reset stack starts at the end of the buffer. + // + CpuMpData->SevEsAPResetStackStart =3D CpuMpData->WakeupBuffer + ApRese= tVectorSize; } BackupAndPrepareWakeupBuffer (CpuMpData); } @@ -1006,7 +1224,80 @@ FreeResetVector ( IN CPU_MP_DATA *CpuMpData ) { - RestoreWakeupBuffer (CpuMpData); + // + // If SEV-ES is enabled, the reset area is needed for AP parking and + // and AP startup in the OS, so the reset area is reserved. Do not + // perform the restore as this will overwrite memory which has data + // needed by SEV-ES. + // + if (!CpuMpData->SevEsIsEnabled) { + RestoreWakeupBuffer (CpuMpData); + } +} + +/** + Allocate the SEV-ES AP jump table buffer. + + @param[in, out] CpuMpData The pointer to CPU MP Data structure. +**/ +VOID +AllocateSevEsAPMemory ( + IN OUT CPU_MP_DATA *CpuMpData + ) +{ + if (CpuMpData->SevEsAPBuffer =3D=3D (UINTN) -1) { + CpuMpData->SevEsAPBuffer =3D + CpuMpData->SevEsIsEnabled ? GetSevEsAPMemory () : 0; + } +} + +/** + Program the SEV-ES AP jump table buffer. + + @param[in] SipiVector The SIPI vector used for the AP Reset +**/ +VOID +SetSevEsJumpTable ( + IN UINTN SipiVector + ) +{ + SEV_ES_AP_JMP_FAR *JmpFar; + UINT32 Offset, InsnByte; + UINT8 LoNib, HiNib; + + JmpFar =3D (SEV_ES_AP_JMP_FAR *) FixedPcdGet32 (PcdSevEsWorkAreaBase); + ASSERT (JmpFar !=3D NULL); + + // + // Obtain the address of the Segment/Rip location in the workarea. + // This will be set to a value derived from the SIPI vector and will + // be the memory address used for the far jump below. + // + Offset =3D FixedPcdGet32 (PcdSevEsWorkAreaBase); + Offset +=3D sizeof (JmpFar->InsnBuffer); + LoNib =3D (UINT8) Offset; + HiNib =3D (UINT8) (Offset >> 8); + + // + // Program the workarea (which is the initial AP boot address) with + // far jump to the SIPI vector (where XX and YY represent the + // address of where the SIPI vector is stored. + // + // JMP FAR [CS:XXYY] =3D> 2E FF 2E YY XX + // + InsnByte =3D 0; + JmpFar->InsnBuffer[InsnByte++] =3D 0x2E; // CS override prefix + JmpFar->InsnBuffer[InsnByte++] =3D 0xFF; // JMP (FAR) + JmpFar->InsnBuffer[InsnByte++] =3D 0x2E; // ModRM (JMP memory location) + JmpFar->InsnBuffer[InsnByte++] =3D LoNib; // YY offset ... + JmpFar->InsnBuffer[InsnByte++] =3D HiNib; // XX offset ... + + // + // Program the Segment/Rip based on the SIPI vector (always at least + // 16-byte aligned, so Rip is set to 0). + // + JmpFar->Rip =3D 0; + JmpFar->Segment =3D (UINT16) (SipiVector >> 4); } =20 /** @@ -1043,6 +1334,7 @@ WakeUpAP ( CpuMpData->InitFlag !=3D ApInitDone) { ResetVectorRequired =3D TRUE; AllocateResetVector (CpuMpData); + AllocateSevEsAPMemory (CpuMpData); FillExchangeInfoData (CpuMpData); SaveLocalApicTimerSetting (CpuMpData); } @@ -1079,6 +1371,15 @@ WakeUpAP ( } } if (ResetVectorRequired) { + // + // For SEV-ES, the initial AP boot address will be defined by + // PcdSevEsWorkAreaBase. The Segment/Rip must be the jump address + // from the original INIT-SIPI-SIPI. + // + if (CpuMpData->SevEsIsEnabled) { + SetSevEsJumpTable (ExchangeInfo->BufferStart); + } + // // Wakeup all APs // @@ -1170,6 +1471,16 @@ WakeUpAP ( *(UINT32 *) CpuData->StartupApSignal =3D WAKEUP_AP_SIGNAL; if (ResetVectorRequired) { CpuInfoInHob =3D (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob; + + // + // For SEV-ES, the initial AP boot address will be defined by + // PcdSevEsWorkAreaBase. The Segment/Rip must be the jump address + // from the original INIT-SIPI-SIPI. + // + if (CpuMpData->SevEsIsEnabled) { + SetSevEsJumpTable (ExchangeInfo->BufferStart); + } + SendInitSipiSipi ( CpuInfoInHob[ProcessorNumber].ApicId, (UINT32) ExchangeInfo->BufferStart @@ -1646,7 +1957,7 @@ MpInitLibInitialize ( ASSERT (MaxLogicalProcessorNumber !=3D 0); =20 AsmGetAddressMap (&AddressMap); - ApResetVectorSize =3D AddressMap.RendezvousFunnelSize + sizeof (MP_CPU_E= XCHANGE_INFO); + ApResetVectorSize =3D GetApResetVectorSize (&AddressMap); ApStackSize =3D PcdGet32(PcdCpuApStackSize); ApLoopMode =3D GetApLoopMode (&MonitorFilterSize); =20 @@ -1705,6 +2016,8 @@ MpInitLibInitialize ( CpuMpData->CpuInfoInHob =3D (UINT64) (UINTN) (CpuMpData->CpuData + M= axLogicalProcessorNumber); InitializeSpinLock(&CpuMpData->MpLock); CpuMpData->SevEsIsEnabled =3D PcdGetBool (PcdSevEsIsEnabled); + CpuMpData->SevEsAPBuffer =3D (UINTN) -1; + CpuMpData->GhcbBase =3D PcdGet64 (PcdGhcbBase); =20 // // Make sure no memory usage outside of the allocated buffer. @@ -1763,6 +2076,7 @@ MpInitLibInitialize ( // APs have been wakeup before, just get the CPU Information // from HOB // + OldCpuMpData->NewCpuMpData =3D CpuMpData; CpuMpData->CpuCount =3D OldCpuMpData->CpuCount; CpuMpData->BspNumber =3D OldCpuMpData->BspNumber; CpuMpData->CpuInfoInHob =3D OldCpuMpData->CpuInfoInHob; diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c b/UefiCpuPkg/Library/M= pInitLib/PeiMpLib.c index a548fed23fa7..3989bd6a7a9f 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c @@ -280,6 +280,25 @@ GetModeTransitionBuffer ( return 0; } =20 +/** + Return the address of the SEV-ES AP jump table. + + This buffer is required in order for an SEV-ES guest to transition from + UEFI into an OS. + + @return Return SEV-ES AP jump table buffer +**/ +UINTN +GetSevEsAPMemory ( + VOID + ) +{ + // + // PEI phase doesn't need to do such transition. So simply return 0. + // + return 0; +} + /** Checks APs status and updates APs status if needed. =20 diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmFuncsArch.c b/UefiCpuPkg/PiSm= mCpuDxeSmm/X64/SmmFuncsArch.c index 6298571e29b2..28f8e8e133e5 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmFuncsArch.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmFuncsArch.c @@ -121,7 +121,7 @@ GetProtectedModeCS ( GdtEntry =3D (IA32_SEGMENT_DESCRIPTOR *) GdtrDesc.Base; for (Index =3D 0; Index < GdtEntryCount; Index++) { if (GdtEntry->Bits.L =3D=3D 0) { - if (GdtEntry->Bits.Type > 8 && GdtEntry->Bits.L =3D=3D 0) { + if (GdtEntry->Bits.Type > 8 && GdtEntry->Bits.DB =3D=3D 1) { break; } } diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc b/UefiCpuPkg/Libra= ry/MpInitLib/Ia32/MpEqu.inc index efb1bc2bf7cb..4f5a7c859a56 100644 --- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc +++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc @@ -19,7 +19,7 @@ CPU_SWITCH_STATE_IDLE equ 0 CPU_SWITCH_STATE_STORED equ 1 CPU_SWITCH_STATE_LOADED equ 2 =20 -LockLocation equ (RendezvousFunnelProcEnd - Rendez= vousFunnelProcStart) +LockLocation equ (SwitchToRealProcEnd - Rendezvous= FunnelProcStart) StackStartAddressLocation equ LockLocation + 04h StackSizeLocation equ LockLocation + 08h ApProcedureLocation equ LockLocation + 0Ch diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm b/UefiCpuPkg/Li= brary/MpInitLib/Ia32/MpFuncs.nasm index b74046b76af3..309d53bf3b37 100644 --- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm +++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm @@ -215,6 +215,16 @@ CProcedureInvoke: jmp $ ; Never reach here RendezvousFunnelProcEnd: =20 +;-------------------------------------------------------------------------= ------------ +;SwitchToRealProc procedure follows. +;NOT USED IN 32 BIT MODE. +;-------------------------------------------------------------------------= ------------ +global ASM_PFX(SwitchToRealProc) +ASM_PFX(SwitchToRealProc): +SwitchToRealProcStart: + jmp $ ; Never reach here +SwitchToRealProcEnd: + ;-------------------------------------------------------------------------= ------------ ; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfAp= Stack, CountTofinish); ;-------------------------------------------------------------------------= ------------ @@ -263,6 +273,11 @@ ASM_PFX(AsmGetAddressMap): mov dword [ebx + 0Ch], AsmRelocateApLoopStart mov dword [ebx + 10h], AsmRelocateApLoopEnd - AsmRelocateApLoop= Start mov dword [ebx + 14h], Flat32Start - RendezvousFunnelProcStart + mov dword [ebx + 18h], SwitchToRealProcEnd - SwitchToRealProcSt= art ; SwitchToRealSize + mov dword [ebx + 1Ch], SwitchToRealProcStart - RendezvousFunnel= ProcStart ; SwitchToRealOffset + mov dword [ebx + 20h], SwitchToRealProcStart - Flat32Start = ; SwitchToRealNoNxOffset + mov dword [ebx + 24h], 0 = ; SwitchToRealPM16ModeOffset + mov dword [ebx + 28h], 0 = ; SwitchToRealPM16ModeSize =20 popad ret diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc b/UefiCpuPkg/Librar= y/MpInitLib/X64/MpEqu.inc index 58ef369342a7..c92daaaffd6b 100644 --- a/UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc +++ b/UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc @@ -19,7 +19,7 @@ CPU_SWITCH_STATE_IDLE equ 0 CPU_SWITCH_STATE_STORED equ 1 CPU_SWITCH_STATE_LOADED equ 2 =20 -LockLocation equ (RendezvousFunnelProcEnd - Rendez= vousFunnelProcStart) +LockLocation equ (SwitchToRealProcEnd - Rendezvous= FunnelProcStart) StackStartAddressLocation equ LockLocation + 08h StackSizeLocation equ LockLocation + 10h ApProcedureLocation equ LockLocation + 18h @@ -41,3 +41,5 @@ ModeTransitionSegmentLocation equ LockLocation + 9= 8h ModeHighMemoryLocation equ LockLocation + 9Ah ModeHighSegmentLocation equ LockLocation + 9Eh Enable5LevelPagingLocation equ LockLocation + 0A0h +SevEsIsEnabledLocation equ LockLocation + 0A1h +GhcbBaseLocation equ LockLocation + 0A2h diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm b/UefiCpuPkg/Lib= rary/MpInitLib/X64/MpFuncs.nasm index 87f2523e856f..6956b408d004 100644 --- a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm +++ b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm @@ -184,9 +184,97 @@ Releaselock: add edi, StackStartAddressLocation add rax, qword [edi] mov rsp, rax + + lea edi, [esi + SevEsIsEnabledLocation] + cmp byte [edi], 1 ; SevEsIsEnabled + jne CProcedureInvoke + + ; + ; program GHCB + ; Each page after the GHCB is a per-CPU page, so the calculation pro= grams + ; a GHCB to be every 8KB. + ; + mov eax, SIZE_4KB + shl eax, 1 ; EAX =3D SIZE_4K * 2 + mov ecx, ebx + mul ecx ; EAX =3D SIZE_4K * 2 * C= puNumber + mov edi, esi + add edi, GhcbBaseLocation + add rax, qword [edi] + mov rdx, rax + shr rdx, 32 + mov rcx, 0xc0010130 + wrmsr jmp CProcedureInvoke =20 GetApicId: + lea edi, [esi + SevEsIsEnabledLocation] + cmp byte [edi], 1 ; SevEsIsEnabled + jne DoCpuid + + ; + ; Since we don't have a stack yet, we can't take a #VC + ; exception. Use the GHCB protocol to perform the CPUID + ; calls. + ; + mov rcx, 0xc0010130 + rdmsr + shl rdx, 32 + or rax, rdx + mov rdi, rax ; RDI now holds the original GHCB GPA + + mov rdx, 0 ; CPUID function 0 + mov rax, 0 ; RAX register requested + or rax, 4 + wrmsr + rep vmmcall + rdmsr + cmp edx, 0bh + jb NoX2ApicSevEs ; CPUID level below CPUID_EXTENDED_TOP= OLOGY + + mov rdx, 0bh ; CPUID function 0x0b + mov rax, 040000000h ; RBX register requested + or rax, 4 + wrmsr + rep vmmcall + rdmsr + test edx, 0ffffh + jz NoX2ApicSevEs ; CPUID.0BH:EBX[15:0] is zero + + mov rdx, 0bh ; CPUID function 0x0b + mov rax, 0c0000000h ; RDX register requested + or rax, 4 + wrmsr + rep vmmcall + rdmsr + + ; Processor is x2APIC capable; 32-bit x2APIC ID is now in EDX + jmp RestoreGhcb + +NoX2ApicSevEs: + ; Processor is not x2APIC capable, so get 8-bit APIC ID + mov rdx, 1 ; CPUID function 1 + mov rax, 040000000h ; RBX register requested + or rax, 4 + wrmsr + rep vmmcall + rdmsr + shr edx, 24 + +RestoreGhcb: + mov rbx, rdx ; Save x2APIC/APIC ID + + mov rdx, rdi ; RDI holds the saved GHCB GPA + shr rdx, 32 + mov eax, edi + wrmsr + + mov rdx, rbx + + ; x2APIC ID or APIC ID is in EDX + jmp GetProcessorNumber + +DoCpuid: mov eax, 0 cpuid cmp eax, 0bh @@ -253,12 +341,158 @@ CProcedureInvoke: =20 RendezvousFunnelProcEnd: =20 +;-------------------------------------------------------------------------= ------------ +;SwitchToRealProc procedure follows. +;ALSO THIS PROCEDURE IS EXECUTED BY APs TRANSITIONING TO 16 BIT MODE. HENC= E THIS PROC +;IS IN MACHINE CODE. +; SwitchToRealProc (UINTN BufferStart, UINT16 Code16, UINT16 Code32, UINT= N StackStart) +; rcx - Buffer Start +; rdx - Code16 Selector Offset +; r8 - Code32 Selector Offset +; r9 - Stack Start +;-------------------------------------------------------------------------= ------------ +global ASM_PFX(SwitchToRealProc) +ASM_PFX(SwitchToRealProc): +SwitchToRealProcStart: +BITS 64 + cli + + ; + ; Get RDX reset value before changing stacks since the + ; new stack won't be able to accomodate a #VC exception. + ; + push rax + push rbx + push rcx + push rdx + + mov rax, 1 + cpuid + mov rsi, rax ; Save off the reset value for = RDX + + pop rdx + pop rcx + pop rbx + pop rax + + ; + ; Establish stack below 1MB + ; + mov rsp, r9 + + ; + ; Push ultimate Reset Vector onto the stack + ; + mov rax, rcx + shr rax, 4 + push word 0x0002 ; RFLAGS + push ax ; CS + push word 0x0000 ; RIP + push word 0x0000 ; For alignment, will be discar= ded + + ; + ; Get address of "16-bit operand size" label + ; + lea rbx, [PM16Mode] + + ; + ; Push addresses used to change to compatibility mode + ; + lea rax, [CompatMode] + push r8 + push rax + + ; + ; Clear R8 - R15, for reset, before going into 32-bit mode + ; + xor r8, r8 + xor r9, r9 + xor r10, r10 + xor r11, r11 + xor r12, r12 + xor r13, r13 + xor r14, r14 + xor r15, r15 + + ; + ; Far return into 32-bit mode + ; +o64 retf + +BITS 32 +CompatMode: + ; + ; Set up stack to prepare for exiting protected mode + ; + push edx ; Code16 CS + push ebx ; PM16Mode label address + + ; + ; Disable paging + ; + mov eax, cr0 ; Read CR0 + btr eax, 31 ; Set PG=3D0 + mov cr0, eax ; Write CR0 + + ; + ; Disable long mode + ; + mov ecx, 0c0000080h ; EFER MSR number + rdmsr ; Read EFER + btr eax, 8 ; Set LME=3D0 + wrmsr ; Write EFER + + ; + ; Disable PAE + ; + mov eax, cr4 ; Read CR4 + btr eax, 5 ; Set PAE=3D0 + mov cr4, eax ; Write CR4 + + mov edx, esi ; Restore RDX reset value + + ; + ; Switch to 16-bit operand size + ; + retf + +BITS 16 + ; + ; At entry to this label + ; - RDX will have its reset value + ; - On the top of the stack + ; - Alignment data (two bytes) to be discarded + ; - IP for Real Mode (two bytes) + ; - CS for Real Mode (two bytes) + ; +PM16Mode: + mov eax, cr0 ; Read CR0 + btr eax, 0 ; Set PE=3D0 + mov cr0, eax ; Write CR0 + + pop ax ; Discard alignment data + + ; + ; Clear registers (except RDX and RSP) before going into 16-bit mode + ; + xor eax, eax + xor ebx, ebx + xor ecx, ecx + xor esi, esi + xor edi, edi + xor ebp, ebp + + iret + +SwitchToRealProcEnd: + ;-------------------------------------------------------------------------= ------------ ; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfAp= Stack, CountTofinish); ;-------------------------------------------------------------------------= ------------ global ASM_PFX(AsmRelocateApLoop) ASM_PFX(AsmRelocateApLoop): AsmRelocateApLoopStart: +BITS 64 cli ; Disable interrupt before switching to 3= 2-bit mode mov rax, [rsp + 40] ; CountTofinish lock dec dword [rax] ; (*CountTofinish)-- @@ -324,6 +558,11 @@ ASM_PFX(AsmGetAddressMap): mov qword [rcx + 18h], rax mov qword [rcx + 20h], AsmRelocateApLoopEnd - AsmRelocateApLoop= Start mov qword [rcx + 28h], Flat32Start - RendezvousFunnelProcStart + mov qword [rcx + 30h], SwitchToRealProcEnd - SwitchToRealProcSt= art ; SwitchToRealSize + mov qword [rcx + 38h], SwitchToRealProcStart - RendezvousFunnel= ProcStart ; SwitchToRealOffset + mov qword [rcx + 40h], SwitchToRealProcStart - Flat32Start = ; SwitchToRealNoNxOffset + mov qword [rcx + 48h], PM16Mode - RendezvousFunnelProcStart = ; SwitchToRealPM16ModeOffset + mov qword [rcx + 50h], SwitchToRealProcEnd - PM16Mode = ; SwitchToRealPM16ModeSize ret =20 ;-------------------------------------------------------------------------= ------------ --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62564): https://edk2.groups.io/g/devel/message/62564 Mute This Topic: https://groups.io/mt/75506904/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62565+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62565+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594756261890100.92612189041711; Tue, 14 Jul 2020 12:51:01 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id AbWYYY1788612xOKUSdFJCeQ; Tue, 14 Jul 2020 12:51:01 -0700 X-Received: from NAM02-CY1-obe.outbound.protection.outlook.com (NAM02-CY1-obe.outbound.protection.outlook.com [40.107.76.89]) by mx.groups.io with SMTP id smtpd.web10.4692.1594756260825820068 for ; Tue, 14 Jul 2020 12:51:00 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Uj2F95Q2WWNC/beqw1Yu3IG79OtIqjNAm/Y6f3Ti0RiA+0FsAw5KsVOSqrRewjey1sX/L4VgO0eeJaRgeSEWC9z7/nMYn/kwG4/i6Zla/ujbAwB3IkwGAi8U3L0jDAfLqom9P9iOdCQF+BPQmWTeUkrVyl4F+t9Ns5x5wJj2O02HOF3zMRr4HLpWhT1a9JlICCOm1aLUoTakGNOCFQ5XTvqg090VA6PbBp7qIXsDxC4XQCOtrOWRIssSg0i1bhJQ1N427IaRpip3xTmooxOPddb1C2CYFWUBmFulyJnKJPMHmuUm9sy+nnsSZ9clsZbqRUP3DGATu6VM9efMGjD2mQ== 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=Cly63GpVgtcX7Qni9pbo9m94/AhxXLuSc1r4QOxC/u8=; b=LiXeqFMF0aHEKJlWnSOReZWX0EmEgAvyL64yi2+Bt6l90S798B2/FSEYk5cU+oIAyzURWMT0m/CRtrXW7yxWI27saetaSkw39R5uJZbfES7sDbhXzBdc9eWtH4j2iu1i7NUoiogK6P4lyya6MNns9+r/OJybOGU4rQiJVf9jVLGf18e9V+nGmO1nQfvbc5CzSaOqdNu5Wc3LeVlmLS2n2wE6z5/0fP3toICpzIFhj1S+0KHq3LHOJPbhsC9SUgHKX/FCw6kAmTBAQmWy9N71NpfrvO22RDzf164B3IpmavKY+I3CiOxc+etFPZESt3KZ45OJ66FPLxVy8uRytQVNvw== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB1834.namprd12.prod.outlook.com (2603:10b6:3:10a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 19:50:59 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 19:50:59 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v10 43/46] OvmfPkg: Use the SEV-ES work area for the SEV-ES AP reset vector Date: Tue, 14 Jul 2020 14:50:23 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN6PR05CA0029.namprd05.prod.outlook.com (2603:10b6:805:de::42) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR05CA0029.namprd05.prod.outlook.com (2603:10b6:805:de::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.9 via Frontend Transport; Tue, 14 Jul 2020 19:50:59 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 28934cf9-4c49-4805-c167-08d8282f3b26 X-MS-TrafficTypeDiagnostic: DM5PR12MB1834: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: 4oL1Lz9FU69KJUSMUji1iL+r+NoJNsLPjBRAJI05KzpxC+/rp6DLRQmHgJjQB5BVQ0jGYyQr73aEjourWT51Kg0WV0TbCg8cQVcBdMAhorSsOK8zkGv6KFvJstApplyhuWN+Fn5pfeZKlDTNOw2E4BvIRKsCcplSOKex0v8VyMdm1klzBRaYZic0QtYLZkq1aJtRnZ5QBwqDvtsSzPkABoO2ftJRNwOKHNDZxC8vWWcF1aIm92uOcT2inx5eXJ+f07KzTVDjeUhHW0nu5WQNUTfKbh25h/86kpOUUMslRNwvRuik4CGjAz4p4XWPhLvtz1KFbizPv3+xXV5XiVI2IfIn8qNKXgHSDa108cla07nLBVnbJDAgQQrAn+gpmFpwHliov8PkTdAfTiWXeg4ukhDXNkbNmM0bBHhnfBd7xH1n28KsGeqx6EdbO/S/aLe6X1+o/3o6NvkD1j1BfdW0YA== X-MS-Exchange-AntiSpam-MessageData: NTh4N6Wpe7Y6K51MNriP68BfIbPT7g3mcMtOY8e7np15or78te06ikQccPdCeUiP3mh/QVpwOYYlbEafb15QcIIloVzNeWLjPj/K8WrsRxrX/EVR+Vat2GBUIgbv6YCOLSsjapCnreVyk5k4YaLfYKUPSZrblbFGDXErvD3TMWEm6rxtAR8fzmg7V3xVkBWoBibITKZSDrz4M78IkGQqQpL3/BTB9UEC7oFMKzK9/Xpo8J0O9kU5dxQRBYgZ+E8y5ynQl2ucdQDZVNnGBcXgkwLObIPqO+dlNxAkpawW7qzdMwGX1yXb+uhk75DbgXpgjGzk2COr2CKCOQjHsXZYqJ76xSlMSq7o/v8JO8xfnd7rtS2ty6BfcKYUnc08cL9DhDV98RdfU7m1Y4IU0aVZLxkRXWY61k/yHGEBlmSoVoHu6dybgWASvsvJp4K95cP6FY84E2G4bF2Kj0ONBDazUSh8NSf5VTHhNZ221OqrC58= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 28934cf9-4c49-4805-c167-08d8282f3b26 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 19:50:59.5723 (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: U2ndthJbsshQp+TNOE6SvE8Wn/BHjsW05LXLGN2q3VLd0KwjQHX3YdkXnn8pQ0br4S5U+5Ulcmd9Esf/avE7mA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1834 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: jX3HMsBxzXXptfLBLIMuB1Iwx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594756261; bh=0kB4npKACCixC9MTWRHE+82Sg589nsMgffj6bq0ro7Y=; h=Content-Type:Date:From:Reply-To:Subject:To; b=uAgnekn25CtidR4z7ExIzmac0TKL34EzYlQSQhqUrPT2Cuo0Sx7vFHijW0FFDJ4HKgK 1WQ3yP6J7a0bVKe1350KrL+IdqsP5g+R8J59t53xFOSeNSGkd9KWjQJc9sBxw8bH8YMQq T0wj5pUBzmIZ9HIMiD2nVU7EoVBRl3zrzMg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 A hypervisor is not allowed to update an SEV-ES guest's register state, so when booting an SEV-ES guest AP, the hypervisor is not allowed to set the RIP to the guest requested value. Instead an SEV-ES AP must be re-directed from within the guest to the actual requested staring location as specified in the INIT-SIPI-SIPI sequence. Use the SEV-ES work area for the reset vector code that contains support to jump to the desired RIP location after having been started. This is required for only the very first AP reset. This new OVMF source file, ResetVectorVtf0.asm, is used in place of the original file through the use of the include path order set in OvmfPkg/ResetVector/ResetVector.inf under "[BuildOptions]". Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm | 100 +++++++++++++++++++ OvmfPkg/ResetVector/ResetVector.nasmb | 1 + 2 files changed, 101 insertions(+) create mode 100644 OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm diff --git a/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm b/OvmfPkg/ResetVe= ctor/Ia16/ResetVectorVtf0.asm new file mode 100644 index 000000000000..980e0138e7fe --- /dev/null +++ b/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm @@ -0,0 +1,100 @@ +;-------------------------------------------------------------------------= ----- +; @file +; First code executed by processor after resetting. +; Derived from UefiCpuPkg/ResetVector/Vtf0/Ia16/ResetVectorVtf0.asm +; +; Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent +; +;-------------------------------------------------------------------------= ----- + +BITS 16 + +ALIGN 16 + +; +; Pad the image size to 4k when page tables are in VTF0 +; +; If the VTF0 image has page tables built in, then we need to make +; sure the end of VTF0 is 4k above where the page tables end. +; +; This is required so the page tables will be 4k aligned when VTF0 is +; located just below 0x100000000 (4GB) in the firmware device. +; +%ifdef ALIGN_TOP_TO_4K_FOR_PAGING + TIMES (0x1000 - ($ - EndOfPageTables) - 0x20) DB 0 +%endif + +; +; SEV-ES Processor Reset support +; +; sevEsResetBlock: +; For the initial boot of an AP under SEV-ES, the "reset" RIP must be +; programmed to the RAM area defined by SEV_ES_AP_RESET_IP. A known offs= et +; and GUID will be used to locate this block in the firmware and extract +; the build time RIP value. The GUID must always be 48 bytes from the +; end of the firmware. +; +; 0xffffffca (-0x36) - IP value +; 0xffffffcc (-0x34) - CS segment base [31:16] +; 0xffffffce (-0x32) - Size of the SEV-ES reset block +; 0xffffffd0 (-0x30) - SEV-ES reset block GUID +; (00f771de-1a7e-4fcb-890e-68c77e2fb44e) +; +; A hypervisor reads the CS segement base and IP value. The CS segment b= ase +; value represents the high order 16-bits of the CS segment base, so the +; hypervisor must left shift the value of the CS segement base by 16 bit= s to +; form the full CS segment base for the CS segment register. It would th= en +; program the EIP register with the IP value as read. +; + +TIMES (32 - (sevEsResetBlockEnd - sevEsResetBlockStart)) DB 0 + +sevEsResetBlockStart: + DD SEV_ES_AP_RESET_IP + DW sevEsResetBlockEnd - sevEsResetBlockStart + DB 0xDE, 0x71, 0xF7, 0x00, 0x7E, 0x1A, 0xCB, 0x4F + DB 0x89, 0x0E, 0x68, 0xC7, 0x7E, 0x2F, 0xB4, 0x4E +sevEsResetBlockEnd: + +ALIGN 16 + +applicationProcessorEntryPoint: +; +; Application Processors entry point +; +; GenFv generates code aligned on a 4k boundary which will jump to this +; location. (0xffffffe0) This allows the Local APIC Startup IPI to be +; used to wake up the application processors. +; + jmp EarlyApInitReal16 + +ALIGN 8 + + DD 0 + +; +; The VTF signature +; +; VTF-0 means that the VTF (Volume Top File) code does not require +; any fixups. +; +vtfSignature: + DB 'V', 'T', 'F', 0 + +ALIGN 16 + +resetVector: +; +; Reset Vector +; +; This is where the processor will begin execution +; + nop + nop + jmp EarlyBspInitReal16 + +ALIGN 16 + +fourGigabytes: + diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb b/OvmfPkg/ResetVector/Re= setVector.nasmb index 762661115d50..4913b379a993 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -82,5 +82,6 @@ =20 %include "Main.asm" =20 + %define SEV_ES_AP_RESET_IP FixedPcdGet32 (PcdSevEsWorkAreaBase) %include "Ia16/ResetVectorVtf0.asm" =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62565): https://edk2.groups.io/g/devel/message/62565 Mute This Topic: https://groups.io/mt/75506909/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62566+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62566+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594756269107731.3776921305047; Tue, 14 Jul 2020 12:51:09 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id HAMbYY1788612xDZt37vO38D; Tue, 14 Jul 2020 12:51:08 -0700 X-Received: from NAM02-CY1-obe.outbound.protection.outlook.com (NAM02-CY1-obe.outbound.protection.outlook.com [40.107.76.70]) by mx.groups.io with SMTP id smtpd.web12.4696.1594756268258668135 for ; Tue, 14 Jul 2020 12:51:08 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lMfry+mLMllIqNxmi2AAlK9Pse3IdJb7T6izT2h0OwiBjK0KhY6OjCZwee8Jum6qeBok2LS45qofIOcnsvv362Jsn3+orA+wAVo0ePe+Hu2lbyvmBA4axDS6W5+9WQeLUNtYvyCBT0DbyZQC7jVDqSQfNt/wwuys91n/UiJfPGDT+92XKCbbo7WGhyr1CgdaUjI29m87NWz5iKbxKuyLdJG8XsD8Zkp7q5IzubRKiQOyLmZKDBXS5O7xH3sW+HhdNHsikHN4rQB8CBem952kIi5EfAPng8G5xGiIzUfR4igAaYFZxvbQbiPdTSbXpyQpg7wDCiEimvpw2OVN/kqwXQ== 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=cYWmh/fcAwIXIlWubzjDdUIKKdxtd9nRLkFVJO7hvKY=; b=hOzRAUXWVeQ6wEdl7TozimjQXxlLIMnsnmTNG8XfEGI50y72kFkRVt8Mz6rQBAw4YWHKIXeyOOGIy8WokgLrDHH9VIgnmFt/9yBDK99H7OdQpSnEJ4o18eujJkKV5109b/++nLTNXF8bKuVjh2aSY04pUR90PHmDqSf0ne5jEt2yJ4+g5pA9hNZTpUZMPkvWLhYPJIlgMNRkX9yqIBwaJzAztV5jwibBmhke3Vh2JANrl+c5TRBIaPvtdEMmR10jq/RNQVoSNDYEckmvclShKqUhFMaQ8l5UoHgLnlPks4G5MVsxIr5oul3zuCXW65sMJy+nISTyF6x43k+q5cs3Jw== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB1834.namprd12.prod.outlook.com (2603:10b6:3:10a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 19:51:07 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 19:51:07 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v10 44/46] OvmfPkg: Move the GHCB allocations into reserved memory Date: Tue, 14 Jul 2020 14:50:24 -0500 Message-ID: <2fb723fe6cecc060c587abd5cfdcf0c12a484fd0.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN2PR01CA0041.prod.exchangelabs.com (2603:10b6:804:2::51) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN2PR01CA0041.prod.exchangelabs.com (2603:10b6:804:2::51) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22 via Frontend Transport; Tue, 14 Jul 2020 19:51:06 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 632ec85d-8bd4-4911-6f48-08d8282f3fb8 X-MS-TrafficTypeDiagnostic: DM5PR12MB1834: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3044; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: LMIToNNYZrqvz3LzsgZdr2/dPJv6f1CELrN6SFjjlXjn51z3utnPNGJ8iMNliyCnyXBLUyW3YaqxFUGFdZkY08oW173PXwKb9llI6OcBKNBrBfOTec2a3ASJYv5sN4vdh9LYkRD8g08u5ongGTug5SOJTm9kwJpmGDoVXF3rNy/DGUCW10MML4m8WfzVrQqZJIpYqYBuwzSuUtfkpouH1LtxsUFi2ycA5vWVmULqSxqAbw96UVNZn9y6pQjq84vFVHdrVho2Eab4Q0vXHQ105RBcQ/u3C/rcl9FeqSRpLckFQcJZJz3t/YzGNKbQKlwigrYoLb0dcS3+k5Ov/SH3BlxOi8j8H2rWr4VAq/rIn7MsrLcIYpeT6KAW4Ax0ipDIPpZ06z2cyiADBo0QNI8RhpU2u/CqnrX5rewQL/yxE7sDAS+gnm/XaiACkl7yw341HJhNLl1L5o36L3f2ESXmZA== X-MS-Exchange-AntiSpam-MessageData: lgpdd3U26mpJTjHK03ZbIYdxpa5vJOy7nJ9ierpI/KZcj4uIAHZJ8uo7kNk8Cq6SvovTtb2iq4FzH34Sp6h/QOyVHSOy6YxDbrloMT+7PUz5X/8VuQOt8oIbI3zsy+3L5+vF+xmp7h7tqSk16XR0T3F0HL/tI9VEHpSCoV0sGIvqqdSRuluUutrhe/N0h4zavL+WDv+xGbOGnVtJa1wM1QA7zi05GqSckb6fEfNZpRYKiDNpo+/VK7tMuDtgWUWIw8WaFAk+NUY42X8rHYItnQbccr2I6X25ueFIJdPGTe+IWjCcyCVWpu56uaW7WkSIf2dhLU9f2nQJVWmSjBANp8z2TtHKeXXdlAwd0T7CaJZUmNr7rcnUDYKhDKyuz9mfKcTTJ4Tid/rqJhY1UT1g6xvPb+qi6ZldsYITXD3GRu3mfcr7cgU29bFy4Jo1YgYRKjfFb2MyWbU9MCCnLbtcXruofqGBoGXABaap/3IGd0s= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 632ec85d-8bd4-4911-6f48-08d8282f3fb8 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 19:51:07.2050 (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: jb2rIDe3SYCMIzX0HZrw6rRbfkRQ5NI9KWedmu2pWtSEq9igN2YE2zavwqZR8Dp+kmNnjvBuGhq4clAIr4H0ug== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1834 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: lQXs6DLS7MqhktahLskKZK7nx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594756268; bh=x6V47Tbvd04jl1qjpLSmXyxHk3lqlF5YFmhnSjbqazs=; h=Content-Type:Date:From:Reply-To:Subject:To; b=UQwYge/Qoah8akjOaZCmynVunljS0Jesy4xkWMh+T03A5VcZdMhYI9DFarMdR6bDIx8 Dx3kFwhL2YdCLgJETNCcwdbSCUlhZEtfdXTUKP9HVkw7xsM2H3i6ti+0bntrjkp1hY+10 7tMQexS6AHmds3g6Me9Sqr1cwBU2MkgdsCw= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 After having transitioned from UEFI to the OS, the OS will need to boot the APs. For an SEV-ES guest, the APs will have been parked by UEFI using GHCB pages allocated by UEFI. The hypervisor will write to the GHCB SW_EXITINFO2 field of the GHCB when the AP is booted. As a result, the GHCB pages must be marked reserved so that the OS does not attempt to use them and experience memory corruption because of the hypervisor write. Change the GHCB allocation from the default boot services memory to reserved memory. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/PlatformPei/AmdSev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index a2b38c591236..4a515a484720 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -51,9 +51,11 @@ AmdSevEsInitialize ( =20 // // Allocate GHCB and per-CPU variable pages. + // Since the pages must survive across the UEFI to OS transition + // make them reserved. // GhcbPageCount =3D mMaxCpuCount * 2; - GhcbBase =3D AllocatePages (GhcbPageCount); + GhcbBase =3D AllocateReservedPages (GhcbPageCount); ASSERT (GhcbBase !=3D NULL); =20 GhcbBasePa =3D (PHYSICAL_ADDRESS)(UINTN) GhcbBase; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62566): https://edk2.groups.io/g/devel/message/62566 Mute This Topic: https://groups.io/mt/75506912/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62567+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62567+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594756276645430.12483764954857; Tue, 14 Jul 2020 12:51:16 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Kgg1YY1788612xLmTBHy2i3p; Tue, 14 Jul 2020 12:51:16 -0700 X-Received: from NAM02-CY1-obe.outbound.protection.outlook.com (NAM02-CY1-obe.outbound.protection.outlook.com [40.107.76.58]) by mx.groups.io with SMTP id smtpd.web12.4699.1594756275673239021 for ; Tue, 14 Jul 2020 12:51:15 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WaI2mItQrY+GrfginZJ4PAxeM0Ku8Fs2ejA/aIriHkB191VkfeyugK35YeeHvlJIO81QOZQZAI7DkorTm886nwpxOw2GvP+F7uch3ndRENFL0Wv/VyAGYk0fsVP7oY5VRW1JqRwmy1hOP+wYRkvts1AJ3Ux/aGtX/iuxLmPP1VKN8ZFe9yAtsKvQAWrjhMTN1CBzG82UbhcTiycvClTdNS1KGKEV4GYOx185tIxGFHomrqqHX1b/QYdIzei5gmDI41455Zg6TjkLfixU6AguWH2zaqfKKecu6zIkF2auv786y7IRdKwuEwPYeCC/nz5bF5yzgMv/BcEhZBZHR9Cmpw== 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=FUzs3S9BaIQfJltPi5n3XHickIJ8ovUrZRQmzQEHQf8=; b=ltNCkT+wgDIVcZe/zRTLTc+LxtAbT5urwA81EtAMYFu0bLf0ifcmAFzN/ks+My5spXC/L07zwWFsRpsjatZ9lHEdehZSl2SwTqammQkMH1j5QcQsv7MW+6OM+Vk7lHn5ipL99mMk9mPdjp1Gm44dSp7syBAZgRFFhh2M33WrlXpY/NsencjpjDUF59Xu7bo9qMT5RTv9zNBxj+vF5GgZLM54GfQrGB0KyOn/ME4Ev3Pz9+8GpO/yCAg98bLxJdxnJ5tPeS2i5AqNzLmfY7d8ezsv4lMN5h6R1/Z6cnvHogj4w1Q8O8qxAYaM7/AhtosZ4z8SjdWFcIA5Wtp25E8KEg== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB1834.namprd12.prod.outlook.com (2603:10b6:3:10a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 19:51:14 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 19:51:14 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v10 45/46] UefiCpuPkg/MpInitLib: Prepare SEV-ES guest APs for OS use Date: Tue, 14 Jul 2020 14:50:25 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN2PR01CA0007.prod.exchangelabs.com (2603:10b6:804:2::17) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN2PR01CA0007.prod.exchangelabs.com (2603:10b6:804:2::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 19:51:14 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 68edc6b7-1c69-4eee-a195-08d8282f440e X-MS-TrafficTypeDiagnostic: DM5PR12MB1834: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: yDPs5MqqMUnul/fuYRD5U/liH4JTpAh4ph+jhO4d5A++DUDZc4KahH8HBjnoinbAIHvyOhqQsVmpuOhaGSVT0LX6QBt1v0VEcOBtYYIg1iNfg+xwFHMRncOrv1jg0fZpptB5DOPJFw3fHmqmDRisK9JWr8/hq9/J+kJTQY1GwvFlvlcnZYCUTwX5hndMBHbMjrExDxZgnJx4opKqj3LF58sSJkMiOU4Ve3RMFDSxn2tONvlV2c49GPmbd9QiSZVehHf6xSqKpn2zH+A1b5J4npmdhIGB3OX+x1lf/v6XCBupDTM8pdTEhJxXQV+u8p39Fv+4xHjNdi9lBx827lEnT9Ze7Rmomxi1klQBApCKQzXexOSluW/4qEYj6CHwDg88QKEf1o10qNJdwCHZAzoC3WBGnHgihoe29nJIL8JG5iCNFw4tNejyq7QSBH8YKmyXqaQQXMoxfodFNJOATGHDyA== X-MS-Exchange-AntiSpam-MessageData: cInMxsYb9IS0OOLPs8ORO976UdraK+970jLbKWpr67zKZukcROraDVyiWc/pQZTaAgGsHMC0sSWGQMs9HtZMyClcvEwyTDmaEgweuIxDpHsNwkyWGnFVVZUXYzrbNkAsOYNfM6qgxjFYd2cDkWHIllq9rv0UnwrwyhapqiBGzF5nIKwuKYgBFZA9gJWlQ/BhzRjpzHAjp/J7fSoVKJqAcOEWbTrG0Yx4FzeUd5ZihdQ9PpBWdYBorN8nY1te0uX6wXfLfyzlgILmzXrQM3YFm/1YbgWqe7nJNUUEcpVcMevC42lxUOgLcRxVjkYP2n91FUwqYwtcERw2+3jIPBopr/eDM8u2nJYQKWTKIHj3BTKOE7NrI4JOS/UrEqm31LcfKzKQEQ3wAZLgd5g+ut690nCJMi2PmTfOvEXFf8QUz5Tu2ZoC+OHjCyuoHjIdyN9624hQz2ArJZ+Sm79v4J39oIkeatTGzJxmFL4Zifly6g0= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 68edc6b7-1c69-4eee-a195-08d8282f440e X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 19:51:14.5017 (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: TuY6I/MAYxVrji4VHgmJpHjpJp8kPNKYnnwRQbhYJzzcsIHUg11zw3yAHnYhJtw/W2zRaa5Ra9hVA/8xF+aL9w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1834 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: ofsWwtyIuXYy7L6swK7hFpBex1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594756276; bh=sKMupI1kn5yCY/7KhzJ8qejIghid4EyTHFJI+6mHOso=; h=Content-Type:Date:From:Reply-To:Subject:To; b=VCF4ma1mjSnBlacJyZ/0hlJwbtjmRWmoNdlYnf5938s7rwoXa4945xIcrieE+cZgqdI rUvjmKM1Dwh+gK9BdJsqlrYBEYFla+HoXFwA6QwaOtWmWUPid8n0DXTrFpg6SOig3qNo8 cUgqFOcl7TEclr3y6IeJMCQLOkh+Jb5JC7g= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Before UEFI transfers control to the OS, it must park the AP. This is done using the AsmRelocateApLoop function to transition into 32-bit non-paging mode. For an SEV-ES guest, a few additional things must be done: - AsmRelocateApLoop must be updated to support SEV-ES. This means performing a VMGEXIT AP Reset Hold instead of an MWAIT or HLT loop. - Since the AP must transition to real mode, a small routine is copied to the WakeupBuffer area. Since the WakeupBuffer will be used by the AP during OS booting, it must be placed in reserved memory. Additionally, the AP stack must be located where it can be accessed in real mode. - Once the AP is in real mode it will transfer control to the destination specified by the OS in the SEV-ES AP Jump Table. The SEV-ES AP Jump Table address is saved by the hypervisor for the OS using the GHCB VMGEXIT AP Jump Table exit code. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Signed-off-by: Tom Lendacky Reviewed-by: Eric Dong --- UefiCpuPkg/Library/MpInitLib/MpLib.h | 8 +- UefiCpuPkg/Library/MpInitLib/DxeMpLib.c | 54 +++++++- UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 131 ++++++++++++++++-- 3 files changed, 175 insertions(+), 18 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index b1a9d99cb3eb..267aa5201c50 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -293,7 +293,8 @@ struct _CPU_MP_DATA { UINT64 GhcbBase; }; =20 -#define AP_RESET_STACK_SIZE 64 +#define AP_SAFE_STACK_SIZE 128 +#define AP_RESET_STACK_SIZE AP_SAFE_STACK_SIZE =20 #pragma pack(1) =20 @@ -349,8 +350,11 @@ VOID IN BOOLEAN MwaitSupport, IN UINTN ApTargetCState, IN UINTN PmCodeSegment, + IN UINTN Pm16CodeSegment, IN UINTN TopOfApStack, - IN UINTN NumberToFinish + IN UINTN NumberToFinish, + IN UINTN SevEsAPJumpTable, + IN UINTN WakeupBuffer ); =20 /** diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/M= pInitLib/DxeMpLib.c index 9115ff9e3e30..7165bcf3124a 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include =20 @@ -85,6 +86,13 @@ GetWakeupBuffer ( { EFI_STATUS Status; EFI_PHYSICAL_ADDRESS StartAddress; + EFI_MEMORY_TYPE MemoryType; + + if (PcdGetBool (PcdSevEsIsEnabled)) { + MemoryType =3D EfiReservedMemoryType; + } else { + MemoryType =3D EfiBootServicesData; + } =20 // // Try to allocate buffer below 1M for waking vector. @@ -97,7 +105,7 @@ GetWakeupBuffer ( StartAddress =3D 0x88000; Status =3D gBS->AllocatePages ( AllocateMaxAddress, - EfiBootServicesData, + MemoryType, EFI_SIZE_TO_PAGES (WakeupBufferSize), &StartAddress ); @@ -159,8 +167,10 @@ GetSevEsAPMemory ( VOID ) { - EFI_STATUS Status; - EFI_PHYSICAL_ADDRESS StartAddress; + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS StartAddress; + MSR_SEV_ES_GHCB_REGISTER Msr; + GHCB *Ghcb; =20 // // Allocate 1 page for AP jump table page @@ -176,6 +186,16 @@ GetSevEsAPMemory ( =20 DEBUG ((DEBUG_INFO, "Dxe: SevEsAPMemory =3D %lx\n", (UINTN) StartAddress= )); =20 + // + // Save the SevEsAPMemory as the AP jump table. + // + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + Ghcb =3D Msr.Ghcb; + + VmgInit (Ghcb); + VmgExit (Ghcb, SVM_EXIT_AP_JUMP_TABLE, 0, (UINT64) (UINTN) StartAddress); + VmgDone (Ghcb); + return (UINTN) StartAddress; } =20 @@ -330,17 +350,26 @@ RelocateApLoop ( BOOLEAN MwaitSupport; ASM_RELOCATE_AP_LOOP AsmRelocateApLoopFunc; UINTN ProcessorNumber; + UINTN StackStart; =20 MpInitLibWhoAmI (&ProcessorNumber); CpuMpData =3D GetCpuMpData (); MwaitSupport =3D IsMwaitSupport (); + if (CpuMpData->SevEsIsEnabled) { + StackStart =3D CpuMpData->SevEsAPResetStackStart; + } else { + StackStart =3D mReservedTopOfApStack; + } AsmRelocateApLoopFunc =3D (ASM_RELOCATE_AP_LOOP) (UINTN) mReservedApLoop= Func; AsmRelocateApLoopFunc ( MwaitSupport, CpuMpData->ApTargetCState, CpuMpData->PmCodeSegment, - mReservedTopOfApStack - ProcessorNumber * AP_SAFE_STACK_SIZE, - (UINTN) &mNumberToFinish + CpuMpData->Pm16CodeSegment, + StackStart - ProcessorNumber * AP_SAFE_STACK_SIZE, + (UINTN) &mNumberToFinish, + CpuMpData->SevEsAPBuffer, + CpuMpData->WakeupBuffer ); // // It should never reach here @@ -374,6 +403,21 @@ MpInitChangeApLoopCallback ( while (mNumberToFinish > 0) { CpuPause (); } + + if (CpuMpData->SevEsIsEnabled && (CpuMpData->WakeupBuffer !=3D (UINTN) -= 1)) { + // + // There are APs present. Re-use reserved memory area below 1MB from + // WakeupBuffer as the area to be used for transitioning to 16-bit mode + // in support of booting of the AP by an OS. + // + CopyMem ( + (VOID *) CpuMpData->WakeupBuffer, + (VOID *) (CpuMpData->AddressMap.RendezvousFunnelAddress + + CpuMpData->AddressMap.SwitchToRealPM16ModeOffset), + CpuMpData->AddressMap.SwitchToRealPM16ModeSize + ); + } + DEBUG ((DEBUG_INFO, "%a() done!\n", __FUNCTION__)); } =20 diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm b/UefiCpuPkg/Lib= rary/MpInitLib/X64/MpFuncs.nasm index 6956b408d004..3b8ec477b8b3 100644 --- a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm +++ b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm @@ -465,6 +465,10 @@ BITS 16 ; - IP for Real Mode (two bytes) ; - CS for Real Mode (two bytes) ; + ; This label is also used with AsmRelocateApLoop. During MP finalizati= on, + ; the code from PM16Mode to SwitchToRealProcEnd is copied to the start= of + ; the WakeupBuffer, allowing a parked AP to be booted by an OS. + ; PM16Mode: mov eax, cr0 ; Read CR0 btr eax, 0 ; Set PE=3D0 @@ -487,32 +491,95 @@ PM16Mode: SwitchToRealProcEnd: =20 ;-------------------------------------------------------------------------= ------------ -; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfAp= Stack, CountTofinish); +; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, Pm16Cod= eSegment, TopOfApStack, CountTofinish, SevEsAPJumpTable, WakeupBuffer); ;-------------------------------------------------------------------------= ------------ global ASM_PFX(AsmRelocateApLoop) ASM_PFX(AsmRelocateApLoop): AsmRelocateApLoopStart: BITS 64 + cmp qword [rsp + 56], 0 + je NoSevEs + + ; + ; Perform some SEV-ES related setup before leaving 64-bit mode + ; + push rcx + push rdx + + ; + ; Get the RDX reset value using CPUID + ; + mov rax, 1 + cpuid + mov rsi, rax ; Save off the reset value for RDX + + ; + ; Prepare the GHCB for the AP_HLT_LOOP VMGEXIT call + ; - Must be done while in 64-bit long mode so that writes to + ; the GHCB memory will be unencrypted. + ; - No NAE events can be generated once this is set otherwise + ; the AP_RESET_HOLD SW_EXITCODE will be overwritten. + ; + mov rcx, 0xc0010130 + rdmsr ; Retrieve current GHCB address + shl rdx, 32 + or rdx, rax + + mov rdi, rdx + xor rax, rax + mov rcx, 0x800 + shr rcx, 3 + rep stosq ; Clear the GHCB + + mov rax, 0x80000004 ; VMGEXIT AP_RESET_HOLD + mov [rdx + 0x390], rax + + pop rdx + pop rcx + +NoSevEs: cli ; Disable interrupt before switching to 3= 2-bit mode - mov rax, [rsp + 40] ; CountTofinish + mov rax, [rsp + 48] ; CountTofinish lock dec dword [rax] ; (*CountTofinish)-- - mov rsp, r9 - push rcx - push rdx =20 - lea rsi, [PmEntry] ; rsi <- The start address of transition = code + mov rax, [rsp + 56] ; SevEsAPJumpTable + mov rbx, [rsp + 64] ; WakeupBuffer + mov rsp, [rsp + 40] ; TopOfApStack + + push rax ; Save SevEsAPJumpTable + push rbx ; Save WakeupBuffer + push r9 ; Save Pm16CodeSegment + push rcx ; Save MwaitSupport + push rdx ; Save ApTargetCState + + lea rax, [PmEntry] ; rax <- The start address of transition = code =20 push r8 - push rsi - DB 0x48 - retf + push rax + + ; + ; Clear R8 - R15, for reset, before going into 32-bit mode + ; + xor r8, r8 + xor r9, r9 + xor r10, r10 + xor r11, r11 + xor r12, r12 + xor r13, r13 + xor r14, r14 + xor r15, r15 + + ; + ; Far return into 32-bit mode + ; +o64 retf + BITS 32 PmEntry: mov eax, cr0 btr eax, 31 ; Clear CR0.PG mov cr0, eax ; Disable paging and caches =20 - mov ebx, edx ; Save EntryPoint to rbx, for rdmsr will = overwrite rdx mov ecx, 0xc0000080 rdmsr and ah, ~ 1 ; Clear LME @@ -525,6 +592,8 @@ PmEntry: add esp, 4 pop ecx, add esp, 4 + +MwaitCheck: cmp cl, 1 ; Check mwait-monitor support jnz HltLoop mov ebx, edx ; Save C-State to ebx @@ -538,10 +607,50 @@ MwaitLoop: shl eax, 4 mwait jmp MwaitLoop + HltLoop: + pop edx ; PM16CodeSegment + add esp, 4 + pop ebx ; WakeupBuffer + add esp, 4 + pop eax ; SevEsAPJumpTable + add esp, 4 + cmp eax, 0 ; Check for SEV-ES + je DoHlt + + cli + ; + ; SEV-ES is enabled, use VMGEXIT (GHCB information already + ; set by caller) + ; +BITS 64 + rep vmmcall +BITS 32 + + ; + ; Back from VMGEXIT AP_HLT_LOOP + ; Push the FLAGS/CS/IP values to use + ; + push word 0x0002 ; EFLAGS + xor ecx, ecx + mov cx, [eax + 2] ; CS + push cx + mov cx, [eax] ; IP + push cx + push word 0x0000 ; For alignment, will be discarded + + push edx + push ebx + + mov edx, esi ; Restore RDX reset value + + retf + +DoHlt: cli hlt - jmp HltLoop + jmp DoHlt + BITS 64 AsmRelocateApLoopEnd: =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62567): https://edk2.groups.io/g/devel/message/62567 Mute This Topic: https://groups.io/mt/75506915/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Mon Apr 29 11:16:25 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62568+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62568+1787277+3901457@groups.io; arc=fail (BodyHash is different from the expected one) Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1594756283748999.0970881453604; Tue, 14 Jul 2020 12:51:23 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id lstLYY1788612xOgmhwLHd8u; Tue, 14 Jul 2020 12:51:23 -0700 X-Received: from NAM02-CY1-obe.outbound.protection.outlook.com (NAM02-CY1-obe.outbound.protection.outlook.com [40.107.76.79]) by mx.groups.io with SMTP id smtpd.web11.4838.1594756282911149843 for ; Tue, 14 Jul 2020 12:51:23 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iw0WKmeN5UMNLzfAcSSuSQq5yEnqL4qDudAQrI9lMR2TXaxulmZKmDGehAhJVPMw6Vw8aVIKBnyfO4pGUjADenefJRdVPUBOTDR/5wR07q9qimL4HDzVSoJw5vy2E5lvsnaDQjFKYw7VTU3rD4KZRiyiSUnsDpmjLVetUSXLbfzHqiR1BU6RAxCOnBK4TMr8UiEd7z21iss7f8M9z2Kmh7L5bnb74KfELhfmoGBr8x+U7LUbHW6rG2Qul4xXPrIekA1er8G7vHmBxW+FTZKWhSOlUECcBraDvDECYoZs0v4v4SX1Cp2REZH4sNy/+0TtzaN4O1syhe30zOHpOBQ7PQ== 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=RJnvsUW8pGH0FlnyXYPciLJvjM743rV+Njd+2QVVvbg=; b=bc0Jlv2BZ5Lucu2nu84uoOeHEhkFxQJYX+cL4C7i5wgngfbqIsJ+n6toHrv2jaJpr108HZUEB8UuJHxtOYLhTU26c8lDFXKx/Sw3m5u6qKYhbm+dI90oOo+8J3Eni36qU8e1gWdTMQc0OGQ9OQyGejW9pq5WD3dOCtkwFBVtgBMLqtLz13sdIeyZ7yVtxH5iGvzPSjg3Dp4HOMmOVXQPvpioxtlUfWiQz5tdkQwmndCYgenj5D8vhaNKg1BEgHyHpADmDGMoLpKytp0GdXlB7DG66Gh8BsHD3qCmndSKiKCVXH44hk4nheJaXQCYIQylkvGOJNEd6S0q3eUYcyshXA== 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 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB1834.namprd12.prod.outlook.com (2603:10b6:3:10a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 19:51:22 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 19:51:22 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v10 46/46] Maintainers.txt: Add reviewers for the OvmfPkg SEV-related files Date: Tue, 14 Jul 2020 14:50:26 -0500 Message-ID: <2ae764e8d8d30ee2a1baf302c4ec4fbbff9faf63.1594736896.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR18CA0093.namprd18.prod.outlook.com (2603:10b6:3:3::31) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR18CA0093.namprd18.prod.outlook.com (2603:10b6:3:3::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Tue, 14 Jul 2020 19:51:21 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: cbe25566-36b5-4be4-1467-08d8282f4874 X-MS-TrafficTypeDiagnostic: DM5PR12MB1834: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2449; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: Nnfa1VIYyVVgseFoXDfp1qhr6GxvTCvt160WGEZN5scoIbduet6/csAz7A+gauar4Xozv3Frv5cyDUDQn3VUvncprtt7Fxdt17+feuOfOdrvW3WiwSpKBJkmGK8dYXnmF/hPCcf/xXPCd0YHrKZjmq6AWoStgBAeOB2FyXi5Iww4qNJ9JPSUba5/iWXN9xBEDFn/YV3i760IjGAdP4fXThwm6BDfaQTzUGckb4+gKRKPAWIXbVVGsDWzVx0TRz/oJS0Vsky2sh1lL0QVFyL2jaCI3EjeeM61mFdGPKbPEnc4Tp5EsZGlhqPrJICcl5pLZ78ULhw8DHz//C6ACqPAmSmZYCN7HnME55saWKLdkOOTZfN3NMK/OSGnlp26Gy3z X-MS-Exchange-AntiSpam-MessageData: UvaWPY99/AGR3wU+9h+U4vFtABKTYYmopbcEGqRCgO6rXoJf9/8AVtF5W7u6c3gGYJD2TBaBFPgtHwvhRof62VBL+ZRxkI+wG+lEDDMp4FX/GPqG+vSKYFFeLO7iZcEyM8T03+uyrVRTa4n3BX/2BfscHXc9XvSP6N5Fd0iRo5124SZ6pYINLC/0LQIUaxwFj1eFRbETEywmWK/fQZjQraN4JMQfsDvXFVNvJOYhPYb/bmCGmEmiYa4MnBKtmyT4bvpnnM2+TI8YxGiIANzvfxP9bFB1Q3ycQDD677Zr/MevS8m36SNn++oiybfH76BMoOdK+3uhdzTVYZpWKcW5tydyOL44ciNA5GUzsHTSD0coB2YQscFGiH1VnnNuDSTlDASPEQEU9ekHttewSeWOgxjRHl4dV7kMHiHxYoSBCom56nNfy3J5d+DDdNweuy3y9/+EXWuKTJt3O1ZrGg1uGHctROGZTBnEHa+JHLXrURE= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: cbe25566-36b5-4be4-1467-08d8282f4874 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 19:51:21.8645 (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: noZaoDHm2yvw3cK4jZop0uNi+T2NNf1wVv2f8FzUo99yC8OiIw77E/FzwAwNxziAGXa2vnkZxTwWgRdI70SJ2g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1834 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,thomas.lendacky@amd.com X-Gm-Message-State: O1EpfDW1pO7kzkMZc356Jimqx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594756283; bh=qZtMMDh71mJYHlP6V+wNJp7kwJvP2LYCemAhKfaiLHk=; h=Content-Type:Date:From:Reply-To:Subject:To; b=pHQ/FyKv4yc56K2LbLwjMnTgdGlTWYl6qlD7/R7wif2YEbwxyNoonhXhz3nBsaStz/q /4fKgB1SktnV4ABxAAImSboX/BoLQKCC/z0VBO1eXIOF92rjNBF6mQ61VK8C/94t5FJdl gaE5Yz+qyvQKLdVPuHOFJ5wK0JSxsRHkU5E= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky Register reviewers for the SEV-related files in OvmfPkg. Cc: Andrew Fish Cc: Laszlo Ersek Cc: Leif Lindholm Cc: Michael D Kinney Cc: Brijesh Singh Acked-by: Brijesh Singh Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- Maintainers.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Maintainers.txt b/Maintainers.txt index 32c9003a6209..cd10dc5e95fd 100644 --- a/Maintainers.txt +++ b/Maintainers.txt @@ -406,6 +406,16 @@ F: OvmfPkg/PvScsiDxe/ R: Liran Alon R: Nikita Leshenko =20 +OvmfPkg: SEV-related modules +F: OvmfPkg/AmdSevDxe/ +F: OvmfPkg/Include/Library/MemEncryptSevLib.h +F: OvmfPkg/IoMmuDxe/AmdSevIoMmu.* +F: OvmfPkg/Library/BaseMemEncryptSevLib/ +F: OvmfPkg/Library/VmgExitLib/ +F: OvmfPkg/PlatformPei/AmdSev.c +R: Tom Lendacky +R: Brijesh Singh + OvmfPkg: TCG- and TPM2-related modules F: OvmfPkg/Include/IndustryStandard/QemuTpm.h F: OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#62568): https://edk2.groups.io/g/devel/message/62568 Mute This Topic: https://groups.io/mt/75506919/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-