From nobody Sat Apr 20 05:17:49 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+59856+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+59856+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 1589925092323950.583084084847; Tue, 19 May 2020 14:51:32 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id wKxpYY1788612xrphLyinxvo; Tue, 19 May 2020 14:51:32 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.87]) by mx.groups.io with SMTP id smtpd.web12.956.1589925091268137670 for ; Tue, 19 May 2020 14:51:31 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e9t7KNgTaqEQkE9jayxuqAXB8r9unLODt0Jnv+aTOsQb+9RlRqgZXJeY6EAY6D+ztcrHWWJxxnVlUGyd8TPTM+Bi5yZ2toqmSAZ2k+MFhqTlycCYSx6ItwKz4kbijuzxcDxZysX6tE7dpcjWcFhu7SJAQH2kpZ8d039ujyzWF6sLe/hlxKsSUdpD6d6I8b7xjHZbbHoXIQ17oyOW91ofa/AY+21uzYdRsCHun9LPYiG1W1tp8B1Je2jjS9Vqsvd0DhyFF+4FxyaTiFUyB4TaK9jKKo6HzXgZaj8cGN6WJUdub9UXhVFu4i11vaajiA6rhNE6dC+Bizmg+9E4jKsbCQ== 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=6GMfZpqaDCveBhfY9SpKC+k3XFWgR1F4AnC1i8PPp8A=; b=kZ5aMDZJLq9S7uJYd2wLLvUtnBmY9DLpvJW3++sLHK5hxlo4kQcTt9k8p+ZO5QmXn+w/TRmU8bBzOuzjC08h21GphZNwstYi6C+OC16OkEfMlMajcM3WjwkOP93rB8hjBg+H5rLWGXkxPml7vthLgwrsHkWg5ZFSdH70MKNay3PM4FavdmogM2Rsv+ZXQ7hAN1L7D7yKz0M6NE++etRGzl5vDPwvydA9ztig4cho/YywFBrAR31VKXUpTXmstc13FWN6CxPu8LzALsxg4hGs8OfWBGfXrVVC8fPwoCiW7aYkYFIYaOP+7JeH1P5PbimjBHeMzbtj93TSwdyFRfvF3Q== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:30 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:30 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Jian J Wang , Hao A Wu Subject: [edk2-devel] [PATCH v8 01/46] MdeModulePkg: Create PCDs to be used in support of SEV-ES Date: Tue, 19 May 2020 16:50:29 -0500 Message-Id: In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51:29 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d689cebd-82eb-475d-946d-08d7fc3ec9a9 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: VHEsLCGFfXw1jfnAqThSXbZCMnbLef8buPtGXAANOSqyDSxh5RU0TGB1DrHeNHQNpId5jAa/hLS0p+MP5HCVprNnKtK0tRYDMzpGuMcjAcUPpALrOtDzyOEz2YRh7Z9diIP49oro/0XnhnAJxrdUnYT2FLCUwgERzS7Z4TdMHyrOAePy0SAHdNjmlbkWAjpXuhYyF08KDwDKaxQOdLmYPl/PvHV/21zWKod2XgyUf7j7lTq2ToGTxzQ9rvrJLzIGNoAC0F4BGSGIdBm9Xe5ivdt3E53vQ/ySq+05tSNeS6J5UgniGRE5RS8+19RX0bjuLdb2FycUc0ZNwrIdCE80Gx9/44BCsTjaji3yNc9z/qOZ3cqvT9Am/CPEnTYDtFCVsGOzxLZTY71o1T43pj1ge8s5cKN8IXvjyVfBslqT+Epra6rMuCAhEArBFDgWjW5ZHKgPuDgP32AcLntQlLIzuIfV2KDUbP0fw99dNMRnnsPpChHOT2ROmmdA3xbFtFa46ErbeT6lI6NbeT3ubCnhA1/O9pvtf//KhhCTXMLXMy64BdHtUBj+PHqZqwpdiy2dUHJnazjMNJJnDaYviV/28w== X-MS-Exchange-AntiSpam-MessageData: 4pTquLEb0LtCbpif774MWspSomqIokiRg7Je7P68XgL9739iLEv0dPG7npdC8xxdsCtEnzzn1oQOlvruy/ybWj+gIzutn4OziW0vbpM9VVJhub7qu9BMLkLAzl9U0Pi0dtmKKxn8cdNqSjp9LTVSpTVSMsUBfUKnZ2IvhQ2/rcwjK4oL0h27OFKonmKADd0TOa5URapg0lR6A3fXijk+5XnJ9yyikHeoqSGwEncvO9Cyjy/hgNOJVo3TEF47+E9i5A15lI0hsQ3n44XmyCgIAK/ZwBoqGXQcHc/RDRXL/Ia0cZdTLNEyssEeWSPub0DuKsvKBs8E7VLKLDsqBpG/t2VgySfFHGkR3zlY+PK37a47FQoWmIa+i9Wkog3+xOWNHnrApBjQAN7o9k9fI6zIYXJek3cbKpcCzn1C5s+7RkELiUaY95s7iVffp3EVw6kRpgXGQ2KGXY7yHoXHj9/UjClXnLv6hq1Qu1TDwUNb6Kc= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d689cebd-82eb-475d-946d-08d7fc3ec9a9 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:29.9249 (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: d2ARXHX6L1znfU6MJ0V64tTH3sgvL7CqbSSR/T/RtG07/TV8SmczknHHBQ6QJjyU1f+DTCA0D7QRezYFkeKqag== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: VgOpUn8T2WdIzHNiR0ekjoTUx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925092; bh=MXaMxYic91fqz6ofqVa2LeAAEtAX0S4MZlyIjlb4Qoo=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=t79xo33nuOl1B3Y3zWgapDWYu/JhPJbDjxQ28hp+Ht5g7RnN/L6ecPzhV2xVDBcc4Me 7FE9SVlPBPTCDLEdCImXLs3IZB0KwMHh2lLddl6MMVgx5HlvccwLCbcREzIqL7nmkEJ+3 ZmkVnM6yEfnPurTYuCt08/BYBxVZG5h5ZEo= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 4f44af694862..8085e761bbeb 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.17.1 -=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 (#59856): https://edk2.groups.io/g/devel/message/59856 Mute This Topic: https://groups.io/mt/74336550/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 Sat Apr 20 05:17:49 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+59858+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+59858+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 1589925093550694.4794362007068; Tue, 19 May 2020 14:51:33 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id hLkLYY1788612xEh1akL4UGM; Tue, 19 May 2020 14:51:33 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web12.956.1589925091268137670 for ; Tue, 19 May 2020 14:51:32 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QBfLFkKM+bIJAH6vNgFimVFKG7z85i14vtZPRWQE0xf7BnOKGC2nBO1f9WdfiTAPTiAe+69YcZ3XLMxMN5WfHfoBTofY/P5rQPtkI3nRrI2o605wMc+GFW09l0Qdq5czcsCxM6R1IIQSeT1BPzQmIsBPfN9s4Mti/ldZ4avmFjSHqFA1Xtb1CDgJAcadfGTiUyAM4XRTBs6bV+tn1+8geNrdeD+zcJximG6K/TkpXmH74SRyHFLedaTcFssTYZSrPyM8uqf6MxPI+PHnG4mG9cwLtyqUibWohySrFoKYaK5W6KW1JhKxjW1HYL/7RUQVuy+SgCQyxbS09Qur75cNRA== 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=romRUZDQ42NjMy1cHnfhmPsUh6YlACPdpxmvXAReJRI=; b=m2m5bzGzX3ylWLQ0HCxEoLrtnaWHItzI0ZaG42mrw4+7iagWr+WPCCCyXu5shsgQJha3x+iyuY9r3pHbTxiZivQjHMz6yaktDdRS8vZLSzKbqZoDZ0FMsUWrhdNZ8QaSwO6pCPNuCGGsXfhTc+EXh+vjVi20vRaIZ9UFVjbWQEyub9DLpcUeCoi3JD53kVi6RrWP8ix9+N9F2j6/hUTmg7YIal9654/c61bmK++aEwOlucmb3gNGhweY3o/d9Im2pA1RZe5iefCcoUgUW2wwKEKsPBdJ4+aM/5UJosqn3SqNiLy07/AorWKDJ344pFcCJI9tBGPlOv+u8Is4/5fxBA== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:31 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:30 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh Subject: [edk2-devel] [PATCH v8 02/46] UefiCpuPkg: Create PCD to be used in support of SEV-ES Date: Tue, 19 May 2020 16:50:30 -0500 Message-Id: <0fcf90a82f791cbb8b72e41bac6820c5dcc03f72.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51: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: 01103022-a3b6-4b29-eee0-08d7fc3eca31 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: ELyPong3rpO2IKI4+QseMWS4R8jPWyiXx/7/BxQIxpycLdRvnIc4sJ/oTQs2ZCPCVNc/1e0rvXbWyUmBmpaH//lwxeOUXAVGKazzgHzNneocS6807CDlux0w2QzXzyg5KZkwNfHvVkhbk+NUeiCPDQDKiFLqI95MtFCS4kt+z2pTZLbpYsBeC2ih5Lh5GuLSXPwMHCc3oLZbTX5Vw6Kw1IIGOJUJBZzNM4exJc8WtcfYJ2vbGOER0ka2VJs5LK+3/zXUlkR21MpNog9YNLjQp/cCBQdMdB6Dl4Tyzr2iLDXW6XteNsd2A28yhJew4io6DboaoeFYiWAzSUwSfiWjjh7zeoEBfxJxE/sheNUm+CpbKZt4G/V1LVYwYhbGfjpesSUzu4PEJcDVi/eJvtTHdIGNkqCy/oO65XCR8v3CDG653rnGIkJwjv2ixD1TEf+5rFXCnNJVy9kCygZs1voOwVpc+N7p4nHuphd7S32J1CDNN1HIPkDVzTvqoomCvKpsDyEP64JlY9heATXBpJFSqNs6pQEZ4Xmw8DjtoVS3dzRMVIuAatjWXIIGZ2zi1qEZJNgwSZI9Nigy/+WpYKWTGQ== X-MS-Exchange-AntiSpam-MessageData: hpMiLsEcJmcX38Gjrz0AEUZMutsl5yAGZRwo2uOivAAEskrU1YtUi0ilfCSinHztSupnMR5v7s+07t0qg4C4yo1yAiSAS0bNFIiaKdgJsM7Suc+iMP6MalIr7kozPVK2pKR0PxAPTqPmlxUKiKJrxqNQY63uMJphBa1VQbCnps5vHCFd3VNtbW5txtE6k86AUXxj/vu36VyjoZXtH7/Ie1HZEkZOQd1TnwAw0DShlfBSGkKl4wvZdF9BxufLmleNdZNBC7RROuj0oKsyuAHYRH3LF2DPPvjvAf8oPnx4gEhGlE4f7GSxIp4T0gBxUTy4UxmEq7hkjUxVkLqwdKqhxoZAEbG5Tps27ZU3dmfQqCzLnuwOMVMOtDHIH1ThYYjXmdM7PWSzSk3AEGBPFcYND5qIAUYlsRIQDlxLySDV2xErYfQ2VJnkRqAGCn5eJpALyQabkP4oF0Qp/NPQMDk/g7odgA5SIReRt0OBovJcvfI= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 01103022-a3b6-4b29-eee0-08d7fc3eca31 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:30.8385 (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: T9V5sCim/WzwaijJTSSe18SQ8/ogmr/cdAh6tRf5lpc+uu2tFeVt5AyCfdRyM9xD6gYUryC2dBYw9qqN1ccmFA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: LatowUtEWCMfVuBC1OPlJgTxx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925093; bh=G7NMhlEKTelegUuIcJqYqz7rK47jlYvQqn1qmX2Brb0=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=JTKIJRfXmtjr9dTN/MSeb5yN1P8ZFFsoVnVTkAyURUiJplBMQHZ1nNM/e2lkJ067n5/ F42AzIDMSb+77mnrGIE0xIi1n6X8RiZXmIudGAuE9FFnlKxiFzN+oVM1pVhYTGkJ1mVio YlFwVVowL7TGWk5IsHGOBxHY67ucygpOIWg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 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.17.1 -=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 (#59858): https://edk2.groups.io/g/devel/message/59858 Mute This Topic: https://groups.io/mt/74336552/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 Sat Apr 20 05:17:49 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+59859+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+59859+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 1589925094192148.90772652032513; Tue, 19 May 2020 14:51:34 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id SYHvYY1788612xmZYP77gqBA; Tue, 19 May 2020 14:51:33 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.55]) by mx.groups.io with SMTP id smtpd.web12.957.1589925093267123920 for ; Tue, 19 May 2020 14:51:33 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VAi/f347sz35F8/EUxmVRM9U22fDu9EFZXAaXoj87wWU3TnAJYinPp7EQlwm0w35PH0VeKr6ugSUoMLsF+W8Yrz5s2rkACRNCHHvbjwS0UiXGg5xWAhUHUhr1lxpetSLpWIDGrWzDTT8Hyx0XOjcv9GVYiB9zYDwu/cFzyjLBp44U0UvM0KInvi049xHUuetpF2dBBRW0rWOy/WN5IRtzXwCWMY2wMhBIps9rQvQNq3bVt9yhQihbWZFhCIaWJ4J0P6r+RNljr1iJ5Wwyjs1QmSePrgPbNEayEqL2Y04URhlXpYZwDF2RvwUg0E+FbcaJ+o88ZxDMA2r+Iog6Bw7nw== 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=l3ojZ8CbgPloJQdyqiVfJyKHXZ0KVTSBlRyirGVUmCE=; b=KF6ThE6VtVTCv/YocgvCmm4cR7LmchxjTmBT6m7P60rfnJb2cpoyy27iHJgi3Vn/PZ1I1ZFIfmwWKNfRravaBSePhbooqIpE53ioxRXaH5I/t5ocp6SfG9ibUZOMO39yGCh8Aa9V4wcBVrB9+N94I6FiXMRFkVCjF2eOttR2KkwiPseL/urf9CE3Pi1eD9QewqDRB1ElqcjSz+DgAIjpXn2py7e8kHF05XlnScBryyZbWjZleJr5sJ8auEeEUGDgd82lJSRLeu7hN5vZilY8AdIHRc4dm6ueSSwXxys4BkufPJsZcXlOIFovfIvwzVaN9L6DZpPH7ezgAeaQrAoNRw== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:31 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:31 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh Subject: [edk2-devel] [PATCH v8 03/46] MdePkg: Add the MSR definition for the GHCB register Date: Tue, 19 May 2020 16:50:31 -0500 Message-Id: <10d70669378bc8c3f0bca336815502278dbe9a0e.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51:31 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 02d8fde3-550b-4aec-e0be-08d7fc3ecac5 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: MycN8siIxcIl6UFMEM9X3aO2qTXsSJNT3hFeAxtvdh79ChTBrqbp+WcrkFh5p+XTw0qhZI8oQs1GGSre4AM4YoPPmu25pDSIG2QTXAJ0GA01baeou3ECzWHfaSldrJhIFb05JJ/rvWWNV+6qOuFwvgxD6IiLLyzgTZ0WLN9Nh8MFg+gJkiBifliN0HY1hTRkvJ5a8QBrTzYUxUzYkYHuf6wMi5O+ij+d9k7qhUQ1+J4NiLX6ewY6XS8pLRt57wPL7uvqZJKFizylXcfhNBinPgpHukjzNnFgS0rkep1LM8gNFxDAy5zIou3KLb34cIg+M43SDD3EXA0H7wwkk2nd3/vpc5LDRZTO8HGfMBfMQ3D94d4G/a/VJt5xmrsy6Tb6b3Ed0zdiYg1YDaosZEpGTvgbPafoD6/sJJJyC7oTmFhVGaD8tRSOxwXbv9AdrN+nGJj/wUUX+JzE/EsHUEvjh9LO1UxXBmcXDEa/F+7s4NRvLoeGH617Ptin9mX6lGO/UufBg0zBW+LqE1wSjhqRimXtbCuyRCABfz/homCJjv5mCBuQ8zuirgptyh747Pkt/64oA2L/prmzPY8PKvK2HA== X-MS-Exchange-AntiSpam-MessageData: 1QzXUh7EDda9PAFUhi2yeSOrwfpAd9nYFGkk+B7I+EG0Bz+hi06u77i1ZGRcpMrJRTi0aKSfEvaqhihTlKn64MJXokOzpOEA69QJv6ZVS4r49/FPQxj+tDpFjq7ONNecE6pt8cHhAFXs+KECQAzPQ92wIonRaZrdfMjcFMIFXI6tltcgD+7XZZEWXl3FZPnjNMYTpNnqkEpoNQLhkRuKt7YNneAstmpFlWgFJ5O3bHA8BavqDIu/AC5GgKgylse7fweGvUAveM8F8yhCwR7W5AVnw4s9APPjTtmQ5SqTLKXL6jBO3gEApasbZs86X04QgXacdODyctYkLHWTW9ID3PIRJuP9Z4Ngf0XSzoMMACFEU6nsobZDbn72dowBcZmvo7EXCR8iJ520wX51LcJthMB5vzQDxCOjfvEqJY/CDfFuzf77fsSfn89uZFjxnq/xFptm7UzLEHxeSvf4uhTADziry1tp8Ujof5wAXfpNxxg= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 02d8fde3-550b-4aec-e0be-08d7fc3ecac5 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:31.8501 (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: 61Waf+XHqd1owocoxoiTeAkPlSfSMJn01/zfvDb8lQSfQQx9WOi2Cimd+bnvC9zl6PGvpeGxuaAAehdF5mCKHQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: qnKrCSnfw72ZQu6El9QaDgADx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925093; bh=lrm52Ln7Srqk5wor9reattf7KzfPY14gPeA4DOw4mZc=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=HnW2BU/3bbnq+dIwMFAXIJgiZwOg1OIKOzKPV5AdpIAjp5uuA3nDxcNel6Wtnp6tHYd iceQxv3HtMI/nROQgNqwXw5WnQhqFwcyR67NjUFGqO97UCm5sjIL0YHa3tev6md30eszV K35FqtyM8wLM7+Ey8X8Nw9AWxIdyFyfL36U= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 | 42 ++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/MdePkg/Include/Register/Amd/Fam17Msr.h b/MdePkg/Include/Regist= er/Amd/Fam17Msr.h index 6ef45a9b21d3..466a3143599c 100644 --- a/MdePkg/Include/Register/Amd/Fam17Msr.h +++ b/MdePkg/Include/Register/Amd/Fam17Msr.h @@ -17,6 +17,48 @@ #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 { + UINT64 Function:12; + } GhcbInfo; + + struct { + UINT8 Reserved[3]; + UINT8 SevEncryptionBitPos; + UINT16 SevEsProtocolMin; + UINT16 SevEsProtocolMax; + } GhcbProtocol; + + struct { + UINT64 Function:12; + UINT64 ReasonCodeSet:4; + UINT64 ReasonCode:8; + } 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.17.1 -=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 (#59859): https://edk2.groups.io/g/devel/message/59859 Mute This Topic: https://groups.io/mt/74336553/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 Sat Apr 20 05:17:49 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+59860+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+59860+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 1589925094968773.9408031164908; Tue, 19 May 2020 14:51:34 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 1soUYY1788612xoSnLqQ1KRM; Tue, 19 May 2020 14:51:34 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.59]) by mx.groups.io with SMTP id smtpd.web12.958.1589925094160160233 for ; Tue, 19 May 2020 14:51:34 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fO66DSsQKQRr/i39eqZio5HRL4uqn9UmToySPYL8Zm12mJraOjpzwhKEyn7glKnNuHQ/DexUYP1QxuG5thBCyEsTW0vUjCwncCNncYJEhW04jVAizDEKQW+wRzfWso9uoeYX5LUItV4JGHDv9Ibp75HF5NxXFmn3hcwA1hTtS3LNkjoss8y/jUUSMeZsqsCtVD0pe6IEsF0KT5dqXB+2gwKU2rRpXdDvMEyG0pOzBq2NngXmUYyJwquufVEd/K7YEs54ZD1p928faPfoLg/JPwJymzzbGy2xwon+BEke5+dufk5Da6fjCbnTkjaSE8h0Rr/jghjbXHOOvkP8GyuBUA== 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=bJvpHZ8a4/BTfd4DkjAqo/sBAEePCSW7xQd9xbaLgiY=; b=kiutTFAoKjavJpCHVKPKLulRt5c/t7jujBexRovWpJymAeDehowfWcw5JVAqEEzzNyU0m34KWnMAmBmKwvPm+coEmRAlAPMSdUCCOGGe3gUln097vLYCzhDM04OIx+cTpKEd9shzGA/WIJWFwcVn1AFdWouk2kHQZneMYJutG/f+5x1bEEYgNNbpdF8QXEn+Px8z7eBmpqFlBhDrbPT/LC4kO0vPjOrG05wypvvqGoVjrjAs0KxtPsvXs5VhD09uFWyuwLHRaovueU8SqE5ZHxhwQrN3JiQFKWV+HU7QSC+pGe+dy/bPVf6g7lfrKUjVq5OkXWi2O96h6xLbBcuKRw== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:32 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:32 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh Subject: [edk2-devel] [PATCH v8 04/46] MdePkg: Add a structure definition for the GHCB Date: Tue, 19 May 2020 16:50:32 -0500 Message-Id: <2aad13129d9be447f8c2b1a6ec8cc05cc9913e58.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51:32 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 23a5f924-34e0-469b-733a-08d7fc3ecb58 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: lamBK8SdfsGCKElxOBmljKyorqwSEJMywEhYBEe1kwlOQCwXnJkFzlaReTwo9j5w5kd31m+apDW6p2q+vII7J8OMRGpQW4/cLceocMlS8lhp6/qXjKFTYDT4bKKsyVG1TtR6cuNpZw5bH9VlEqF2pKrZPe5BDmpEuTrhd6mZpBCW4zqBGXTD/3s43eyhQPvoMa1uSvuo0tisoY/Hln2f1M5+tHfuyPCBdlSMEcbqygdsxZisrZbVBJ12qNCqK1yF253mFi0jLKgZ3/sKwtzh0q3/3BMUM7luGcb1wqLa9Gg9jTKJVt9F/Bl4hGtfhDOHydRUOwijpwaq6D/syQ9trxMjKw9LDcuWuUK8o3nqLQdvQlm9mK1rh4Ly17YS4+VN08oyA81xa0CAgHOuNZV0c3c3XCQwQMr5RlA2wcj7B0uH2GRF/CZoigJgvPD1tABMPmG0Vu6YrZ6zPEhz0MpAAz0fFX3WWMfSZw1fwmqK/HrRcFJ1VLrfFeeZjqyLaJXphWHcQFhRi0u5XxN2aPuU/63CM/g2xE2kfIjQptk2YyVVZyguxKpgJfpAWVviNZz0qND0TCQUHHhXA251Y7De6w== X-MS-Exchange-AntiSpam-MessageData: 6IXkfwteLLmmgpxuTk+cNPxEkaEeCS3OkZvpShvmZ+o37J+q8+GC/8/g+XMig0eNIRNtBmjqqyfsQnCbvP1zPGfUt8ETc8zWa4n1isQaUx0NNamlABCY9N6rJ9zdEBWyUGmbY+kEOUu4g5S7AE37/HKgthoFKkP6Ty/RRti4dJxxXdgVo1IuhfqrRA0oxJqWY2VbfJED6yvn+z11Jzak/zqi4Bd34rIuyHFnRBXYtZ/3qkVUiXsQOVLP0owvQ8jL7IYv1a+LV1XykEt4Qu8F6hhFnnVhCRj585sRiAs885xCYKrlEyXoGRxfkaThhu+59q5EeOgei0FsAmBSHwqwn+TtuYmf7aaiwZW0NY2VQrm6noww5MkGd0jXGTzRUfbZxySck7fz9RHqaJIURzIdUUnIDxQdbkL9KNAG+uiph2SadilRQF22VU5H5PirDP0UW/jGTkcAFX9hBHUvBOiAHB/oaojeJYq+UzC5N7AyTv8= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 23a5f924-34e0-469b-733a-08d7fc3ecb58 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:32.8236 (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: tmpiJuEtP2tEKYQA5pdP/c0F4eQJgHpwyv8pnLLanm21JF7rmUXYhPmaHf2DM9o7lQVSlLb278wFqMakfO6HhA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: TrXRAGTmPS7Jdi38PCJ1tZrBx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925094; bh=RB75VkpgTa0ALGvmY8mDlTyODp2MipmaK6DUYYI8E3Y=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=BxAOUWE4mYGHxy4ddDLK7r03Kcqw497/5Jd99oHZBoaOvDJWGi3DPmsBOqBxAgQXowo J9F7xGb323IMPImmuObSNjxL14DyfLLVJmyR2BrORbm9EOYyxcwHgha7JwXJrDQk8EqlA VXX9jJPno9HFQoMHGbYEdLnxSwV83uNeX3E= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 | 134 +++++++++++++++++++++++++++++ 1 file changed, 134 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..25c7823238b5 --- /dev/null +++ b/MdePkg/Include/Register/Amd/Ghcb.h @@ -0,0 +1,134 @@ +/** @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 + +#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 + +#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 Exits +#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 + +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.17.1 -=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 (#59860): https://edk2.groups.io/g/devel/message/59860 Mute This Topic: https://groups.io/mt/74336554/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 Sat Apr 20 05:17:49 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+59861+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+59861+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 158992509738234.89125283670296; Tue, 19 May 2020 14:51:37 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 09ynYY1788612xZ6u5OGxJcS; Tue, 19 May 2020 14:51:36 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.53]) by mx.groups.io with SMTP id smtpd.web11.953.1589925096378722884 for ; Tue, 19 May 2020 14:51:36 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JABSCLZsmiQj6O/T14tZBc3jhccaZFuXTSQv1dZpxMybcVOdLcMegNLepAhKrXXvg0ek4iAclmJixVEB+PwmKO3Jy9f6Viq6p7RffMKbyc3skyJoV1ha1vG+e3OwisQ1TqvYAfRBU/2xkiQihCxZgOW0tG1k+JZH1EcNgpMXkTOZyvpVF/E4RFLoLM9v9SadEy4PfCh42hLIV6pG5vApdQL7zfeI0DuwTbN3YckDVz+v9l4ko/kFrJ9mAvJ3yplAlmOeRHduhXRs9jgMc7zml6V7aSaai1P6VI80kp71C2XN+rU9D7V0uIfKkPidw24eWD5PNsoZfEUnRQnxkb+ZhA== 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=GwQZEKptP+Iav8rKOpSDnOYrnxvMyawKFaUSVpFerbI=; b=PF5kE/SEBw9Y5LcmdZziSV1E7sKOYGi9DwIOZCXdeUxPrC9swCr2Sru4UORySeT5z2i9J1WvDJ2Rg/95ac6m2nsn+0dzrafk8obFliXXDtlMtScTFLl4jf9NH/9xrqgocM1RrO/6as91vcpVKzWUFtLaWEVXfpe273QMaLI87YkwU4GpjnHLPeWegH0HQTDHdSsgC/ItW+Fk4aWLkkRngwXmcaheUReZvd42AB4SS757p3PkiFE+lSC462CvEi3566qjJy43K3ibkPBdCLqbAPHtyIp6F6sAXAGq5mcxvnS4AU9vJzHVU5edhNEWZ+iC7kv/3A8c2FW8AC9mm2++bg== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:34 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:34 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Jian J Wang , Hao A Wu , Dandan Bi Subject: [edk2-devel] [PATCH v8 05/46] MdeModulePkg/DxeIplPeim: Support GHCB pages when creating page tables Date: Tue, 19 May 2020 16:50:33 -0500 Message-Id: In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51:33 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: fc74f19e-2c56-4134-d2d9-08d7fc3ecc3f X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: io1X2Z9YwL1/akhygZR0TN+rYGnNg0WQlLtZlb9zA708sQeENVizujMMG5nZKBH2nImqFf3826j1sO/AboCgyDp09IbGCdd2UYVgGO6hsYw46e/3ECST32rwsqjowm3PEBo5NcLCVwFijbTo57UOuH6aWA0/kN2twraYewZAaGhwJoqzhVnmQtku8/uLrWFPuNlukbl+zU2UWyhU2zU1F03n/AG6AQ/n1R9ijAmk98Vb4epislkUTCN1PBRk5oz8tTx4ICJygJlIp5BrjcaTWMI/ZkGoCJ56ByVcmmLDSJlOvdjc+gQA5NrV2l9GfDnTXSgTmzz19LTUdkzNSX7EH7M3aXEBF8847BECD7epUxr7TzMDN1oXZBW5b/wy4rtQsW5IKi+4ldnkDWc3x5TYN7HUzFnBk5Rb/dRnNNW3Ra37+d9OcylUp57J5dCSon+2wu221Ud1A22AJ87gcDZLDQeAhxdmH5v4uU5GNOBr2XosGHi/nleCoOJ59ZS9IKsdkykw9OMZQElExBvQ8SKm7Dlbu8ewit6+2f9tj5wzGGNSE/7Y1Jo9G2dCUHW5ydmVpq7i3+xEx9ScKjyfBxN42Q== X-MS-Exchange-AntiSpam-MessageData: 0jZjGqazD+vH0uaK3im5j+1MuOKjpVgDTvCYb0hgyOR+iudi6dRF6g27LpW5fBwBRuNoSHGtuCo7S0NlVrxFW/rPdHQKi1JyZXxzzyZxDrzxrUeFFFRoSljsWQRqDwmY2gRwKZj9lXstXXheNkNZ9sAJRo5yfMUda/tey64cZrDKh/4ujibJ9yvZuM3uJ8vibVXgZo2sRTDYLD0W+KCQqsKs+fH3M6+BywBxCIoX6Rg3NKof2DXjw5LMM7PaIBXD6CM9s4jCD+tvEJjGQIB5krKlQbLQw4GXQvbXMWqBUqNR/HtjjRaitfjV9LRClNY20b4Fu1Ubn2Y3hzXnOf3Rj1tJHDySdiE+lWIZb+t/RM3Z6yMZk7Cs0cepaaGB2UDTvXzrIbQq8BXRl7CdFLDUZpz4+qGfwloECo8mPptwldT4gMJMyZTEQZrnDgYCyGbej75gPOcVohcFB1r3ZEgJeBeej4+0rd2kPe4K1XRalas= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: fc74f19e-2c56-4134-d2d9-08d7fc3ecc3f X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:34.2850 (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: aHeQ5GQhqHTGu2XlHVqG86PcMfqJz6xHkuvSAAvmWhQ9XDsPbZjt5yimsmxAcGc3QbKbQneut6Nk0Efzzm4dqA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: UCKqMQQcDn0cWQXffIH5GVrpx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925096; bh=gXAhVDTZiMfr1dEEXTV8nWRzzuXh9BKkhq4lA07Hp6Y=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=qzcJpvy25oAuPlRe0Jge+tK6RHidIB2M0tqHq6VAnS2Qhfrf5/xfzClSmF6K/4uW8YP 9e64pQdmYb4VGgPtlb6IvNEkBM7Y7pSXmVGeyFt/rwjL6KZr5uYfhDPyBSX84UEYlgXUM UXYDCIsl/xist0OU5/sj666rtCiWIrmBzqU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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..e097508d72af 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) & 0x1000)) { + 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.17.1 -=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 (#59861): https://edk2.groups.io/g/devel/message/59861 Mute This Topic: https://groups.io/mt/74336556/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 Sat Apr 20 05:17:49 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+59862+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+59862+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 1589925097918656.8346555192545; Tue, 19 May 2020 14:51:37 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ZernYY1788612xU7iLd9Hogr; Tue, 19 May 2020 14:51:37 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web11.953.1589925096378722884 for ; Tue, 19 May 2020 14:51:36 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d3vkOh8cedW/w6K6vT+A/8KBteoYx8YESFCaKfPx6lKpdeYtCYOrQtw9F1juyyDm0nS41iERstW8jKbFOVWyNEwCCzDilZ72eVf58TbEUPGCOLRSGB4Rcicayd42P4HakoVbQ/fjG45kQj9B4S205yQf1UeYOskhQ7jp9tFoLl5LDTlzFSkopnZqOWTSPq9ksJDozME/l4Vwj4mNs4ZYae3rOtYhAj4MVwhIAEEbcIvvQodtO0ujaPw+jVA/IorRoMwMeIaYgQ+VET16r4KUQqH46WysAYOhMk3c/AxHR7KwcfHJD7aT0fl52jjnovpOdAtFG1TZJh0lzkMpl/GrGg== 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=FQXvgh6i13tXJ8dQf2PIsIdb1vVr+hWSJKwgj4cvK+0=; b=gbvVshBp0BRHF64/V6ofQ6eSf4FskM8BOAQk/GY1Uowg1+4P5XeoccFVCmRoVgHn0VBuhNmsFuUgmXs4AUf2x0IK2DTKFB7gFrVTjJz18OhKz6agUOXU+PB8bcwIUiCYHMEa7wob3I+1v50DFepxW9f5BzlMUIQKacZA5CTczalvv3FqlfaUVvAkYjmtwAt+RlYVGnOxEABm3rxVR9CC8tnfbHpvCrifb2DLPOkuKXUq12niGyCV1On4IBel4AkowixhtC9zRwsqC6IzjduBRGUI8w3gEO4WdcHQJ2GsLNDyX1xw8BOsN6w5u8C5RLi0dHXyjs7WU4ZXfKxzdJPGzQ== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:35 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:35 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh Subject: [edk2-devel] [PATCH v8 06/46] MdePkg/BaseLib: Add support for the XGETBV instruction Date: Tue, 19 May 2020 16:50:34 -0500 Message-Id: <2e5aa32c158ac550e0b4b6481e4945258292f01a.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51: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: 2c5c511a-d321-4b69-8d0c-08d7fc3eccc0 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: chzFxCNSjBjpxlANyrMasyVcWptFzl/l4O2dpWVSQZbVNLXTTNoUlV0zX76pj8v4I5enJyaqoaRvXvSt+7YrccQsdL02hYA5ZyoPjBdFtD65J2tq8fF2bX96PGwqRrU6Ak2n6KsfHAKQf9aHWyt0NZTXIfOKFWE8IYHKhUyk+ChyD/QiqTktW+S8+cUDk2eEoTPw0J68Dz4xQyVKUfXMofGpokYxZQVcjkuKGWuLSomnPGF16/rL2cbmBSL5Zb4HUGtV9pCgv8yIwG36PC3sQex4+zxpoiSW3QmxNPeW+fo/w4kQRuG4QP+3jmL8PAi7FpJwK15QZ49bwYwKgrgoYNGLpNSQanbDiWFZzkoL1xypmMBiA4gkTFkLH1Jqo1wXpU+8iuwzh6zdtPKjlQdT84fEJPY051MktYVKGklGMx+iZ6CuW2pSids2vi3LP3wm6/EFoR7GNjaQI9MJR9xddbbfd+dEJP52P3das00Py/z63zC/Y631mBGOReAqKZRdFvzio0Wejv2uUhpXKY87ONfV9BObtWulj9oatmTw65lXvuqziJ/zYW1VTdypuinU8TMMqfvfpAUoDOvxgVB4cA== X-MS-Exchange-AntiSpam-MessageData: EnStyN9cyWk5tqVBHLO0jnKY6veKO2ELv+tFAcDkZ0IMuy1aeYovM2J00mMC/Za16OJK1XgslgMsNFbPKprb8N7g/QWx0wuoAH5h2iHf0x7lFCFGifNATGOKrDqxjyHC2WPq20w6M4a+GlwFx75I7KarwbyLAaApdnG/dcZ5en25ASvZkDt7L5SNqRvZk/WI17P/AiYwmJCwLkHUXfFhNLEh0dhsWcqMdi+iP+kiDgnCwnsHJN7tyigEoBgiaotGeTlJlpdy/jF4aw0a2oYl/bj0N1AV4Zcd8SSGLbpiHI4/nWcwv7MyvrCxvtKa1EUKvUPA/VdioZj09J61kjTmiWnvsBk1lAOvkoGXa9gMTy5EeBRPBc4uPRRUG6UUqCq6iXgpQvgGhNbvBFmUUMPVjjpD5g32HJtCefkFIMLfVDjjE8g8OBOk1tymC7FNrCkm/mxdG+I/eQn9QPjtkk6blwMXMJvNFlwlVp2+P63sLI8= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2c5c511a-d321-4b69-8d0c-08d7fc3eccc0 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:35.1116 (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: xvR2fhWAHQ6V8yWjZsLUvqBarerDZ0HWArlCHTrOwTWR9WJYTc7J9FNarat02b8VKW9AGQ5I8n57n0frVJfVuA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: EE6xjloR6UkWpPhhYsIj63M3x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925097; bh=1hoPKz0uHZr79cmn3jsnWjMx+u76dh7d67dDp5XM+KA=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=Y+sPkZnWJRzbvRtaAkvwewIJBz6ih2uQplv7esESFnF9c1rIw4IKix5SvXvsu8sKlJU vObI4cE/UNfLdjGEqJ0sULCl8cQDMltOhYS43+j0dNLO7VZStQORrNbm6a6dS+HquJDbG zulngOonYJHOk0dZ+9HhTQU0kYL4InhDmXI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 b0bbe8cef834..049fd1b872b8 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -7942,6 +7942,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 + + @retval 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..591f0bb0e097 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 + + @retval 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..3eed1205adb2 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 + + @retval 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.17.1 -=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 (#59862): https://edk2.groups.io/g/devel/message/59862 Mute This Topic: https://groups.io/mt/74336558/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 Sat Apr 20 05:17:49 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+59863+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+59863+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 1589925098898790.9973394080464; Tue, 19 May 2020 14:51:38 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 5H6lYY1788612xw1768nAMG7; Tue, 19 May 2020 14:51:38 -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.954.1589925097911028907 for ; Tue, 19 May 2020 14:51:38 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l4VVV98sRjxE8iHY5M3h+KJ1UOW+0DHE8ZmRfSI1Nz8WMqFCGPgcyFIU/hQIM7n78KBRNk8sn4tC9gLcghoTvssRJYdsvj0CQyBIkn/xsBb8x20DB6Mey/3ToOrrWaLpFydav1A0rJy40jlHO4Uzw4mgMag6CKMzYMJXnN35czypUaPNea78s9nfCzHBVB4nBBS1BJ7B8P++kXme39m5U3uWituqPnroaOHJgiqnsBWp2bJ3+BokNp7eFRt/lXaNo18AaLnQ7kHGuw3XEfEd06Tj52FPhRRFmEHSKgVcnzO3imbhKpijLbfpLJ/d5viLptsjfqlp9YwUCizN5Lh7HA== 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=twip0zpfQL+ol70EosxC9Jd77pWuFjGjzs3em7gK+GE=; b=MYfkmnao62eFCYZBxI2Q/bBRw77k4tioqWfgusF+Btm2n5wXIG5kfPFY73QYuQQhOzqAJD8ueOYg/TxMghHPrb5+wu2V3EQONDyGtUbOt5zM0BGABohmFpRF8+3QRSkOPdv3KA0EcdJeeDG5/dU1rhqgEhY9m7oEcoJNIJJwK6oi+v7WvuYBlfypARx0DJwnQw02d+Gz/iGy1d//a7lyQhydqOFVQsonLrH/2LTr4j/7vKu+IAivo+k+IKDKYC5sAjr4aYztM6bLwAzGZRKhv19zJP83jYFiTiIaaOMfpzdFm9wfgACDahEV6SSuIkaBLcB1m/8n2PqEmc6G/6KFbg== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:36 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:36 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh Subject: [edk2-devel] [PATCH v8 07/46] MdePkg/BaseLib: Add support for the VMGEXIT instruction Date: Tue, 19 May 2020 16:50:35 -0500 Message-Id: In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51:35 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: a1547d8e-6394-4b23-c945-08d7fc3ecd44 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: tGLcGffUDQZQ5aQQTi0D+J0lh9e5NI4mkw5OTqzZQv/0CYFxSA9fPImY8GJrfjwtk2/bOAmQ2eZwPmN10IIVF/qL8zfmsAwsEezR2N7FB9PYw4h+n3dLfMBc7P4aU5h6TFXPBE3PggK2ZBN5FKGMWGX5d5/+iyIqdKrZzUqDvIjJydG/fmXxTCIbv5Cxba5HC5jDp+gMjtEx4x6reDzqnSHvHjyCpb0A11dr2C3xTKVHfujHG8L8nhfR1BYRMXKjP/t27x/t7Qx/M7MA7Htwwsh3Q7be2X/PwziPVNb7AixOYnOCx6cUA3SQ74vmFQcxvE7OXs9OCip9WRV9eozae45mOq83yq9II26COknm2HNsyWn2xqCDNrCBWIDQSbZZBB5hOV9lM8JyX+11BCj60Uw6KLq0qIVRTfucPKhSgB/MNgD3qvCsMuRWP1opv4FirqtBNc77isfn/aySRYK9QFkXG/2CWU///qYnXjYmtvXb6Hrq7T63I0Rd9WKxt9qeCtZvDJ1V88/n7kPXSsH8da7+DR5B0f46xEu0sKtUvvi/Jf4r/dZddLxzBOegJqqtmKBoDbkuogzYs6MlAU29xg== X-MS-Exchange-AntiSpam-MessageData: lNtuHro9e3NUCWRi7imX+W5bzN5nuU63rm90La75v532ifGe3nJPMp/kC/pQlIXbyPua4nVRb3N3ApssHXNJ0NJNzkeSyqYdrIRXQJiftghiaEHxKKvnhljS+D2Re4gVIGQQsH6RVDjslaJFaP+OLYi0fRTyzl/ZA+NnWhdGGuoABm6eUbPIsnlLwVB15jaU2pE9u6xhZJK3DOiAONWceWNwafSIbijnBZu98C8gZc4nbN/kzHeaO/i07tO3J7IkW1uf9nmxMtta6+rktC+6McYuLKhHBTdxd5hqY67VmgMprXGArZg3+oRDekiVbRd0B6LLTYSa1CiO7llcr1rHrU/AHLI5e+MDRl4Q+rBFEbz5BBMpqY7ocj7mVTLOdGqCDcTVDIBuE81fcaFxS1Wg5hBhM8xWHOsSLndWRW/vyPKIp0/+ly4hIQp+LGYBOniTyhoQp2C2hXJnVI4OIdZZ6gXmMhAiYzYyYxV4QL2gH9w= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a1547d8e-6394-4b23-c945-08d7fc3ecd44 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:36.0532 (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: KWYtuit+xKZMVxEcx0wNzTIRQfuj/uyeaRX8nDV0gTsLePquPz9SbpaEBIx7y4PwHidIAveWkoIL1GFpXW+WXA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: Zrwi2LqlxWYBW0SPmcMh6X5Yx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925098; bh=sk05aiykP6kGfSwoMiIZlkLZ1p/hhuVBs86Px9nkYgc=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=fy+XJXjLProxt2lGxjvht2aAy9MqnVvt2UH1ZYImV2K49Aa0IUv+VgMjsw9JDsf2FTY d6KLEwn2TabfteWF435XwvwsuKRGsgENLCRk/cgdUBoSIFDP4Z7cMJnE6FYVweuKUBmbe tnllhHXCx3SoN9IloNifkzXDetws7eaPsO8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 049fd1b872b8..2d131b2ac8a1 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -7959,6 +7959,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 591f0bb0e097..ee8c62c79c93 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 3eed1205adb2..277974eff9ee 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.17.1 -=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 (#59863): https://edk2.groups.io/g/devel/message/59863 Mute This Topic: https://groups.io/mt/74336559/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 Sat Apr 20 05:17:49 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+59864+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+59864+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 1589925099338797.7152781060129; Tue, 19 May 2020 14:51:39 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ENcUYY1788612xy5MQP9pfQL; Tue, 19 May 2020 14:51:39 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web11.954.1589925097911028907 for ; Tue, 19 May 2020 14:51:38 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lmFzXpfKmhWk2goiwlP9P6gk6D/5SlprhLzH1ux7JrJG1Fu3HCmdUIfBOB1vRclLvKVhaXYiUfZZkS+WqFA39w48l63/71OFJ5lFhi+LG9d3IuqVZeVciel3bkqq2GhaPufJ6kYsJd6c4tS/Rdazz3/eRFnEDIRJooCbvlBWC5Ck7Pvyx7HZIqcD94yv2BLh0+BUGCltUwjKI/R1ZgNmiWtVIg5uYFHwFZOxLEXTeFn6ZwputCKwwJfAIJCksHEkcKlflRUtAz88DCeC1lMBdUjLvuPh/uUwh6DDfn0g1le48LruLjC6YKYao0tpjpq91/4XSE8wiqUrJoOXQPJUaw== 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=4gMCJT54SPZQvA5qB5957RpaNn4pIOl5/rHRaUt2VWg=; b=NgsUui7RQ6MrlYvMk+Y9cVxvfPCcnGRTWUXBYKu2KIOjT1JbXA6aXlfswYyatmdZV9vpB1GnvVvnEMaSe4cwnMto2z85wLq6b80/FkU0jDPWwe0a2KeFTUwt05AF3lV3LVVfaiHBTYpU5hBBJrBR+fmkZYmw1S5m+tV9ZdNMn6cZWxqXS3Sy2oxUK3X8ioqEvwVIR4NAeKzttAyz4RYy2Ey8J9pPCYGdYFTKWPJrzfJPjXSPDLzG1W8rmu90hWUBqYyVn3GCuUZmz424bPO6g67fky+T7HnOTwwOyVTgM4ObpwCCwBpHFL/JWZ9zSpRSJ4bsTLNcrbL4fHWckAWRzw== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:37 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:37 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh Subject: [edk2-devel] [PATCH v8 08/46] UefiCpuPkg: Implement library support for VMGEXIT Date: Tue, 19 May 2020 16:50:36 -0500 Message-Id: <355fbfecee251613126bbbaecbb130db4c6303c0.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51: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: 46ab172b-5ffc-4390-b256-08d7fc3ecddc X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: 6tCKQ8vz8kMFZDiRf/drxbvYjgaWutM4NHo/NNwCSqi0jnfld+0salZf6auX/IOmosp0E2G/krzrwefw3nKMWT2mGBfEktBVZ+ek9wOXB5RpCrT3Zua2t4ByvCQIQL90jHy1TV3KAFE62h8XnDgPaZOPY+J5FinY/qRcYdQ78XPgiJd4DggtDywFP4iRqhJNRBNEZJB9gjSDNZo9wR/Rz4lmZNR4+ZkyzshNtbi4sZtg8mJWFtgU1bR1R9c4bB2PgqW991fDSYh0GM+bzFZwBkrOpABlBEgZeOHzX2+VqXIp9cfv8IdiIt+ng78ProrhYE2xbLdgU0pWM7vK7uGqfBFYNt6nUG7zho0Y4YMPA/8yl60kd90Jd9vJQqzI8jx3CWUXe/ST/Ke5jpvhzWmye/j8Rnmr12c9ySf3KIW4ZNBoYMiPoW2dC4x9enntbzmmWH5Sdi9bTrmUMlvK9kVygOkK0Em9LsXvLDepkNx2YLHLn2f829Mcl8jB+T1WZLGXpWGTuMYhm0EPJL9ZuqpVoiw6PV2O398nj+NrBR5BhvpJCUnpMGYE0RvUwnU4kLVxkytAmEpLe7toQDK1ZTVaHQ== X-MS-Exchange-AntiSpam-MessageData: ohjdWMtZ/GXgyC2kozvdFkzlL5LsNOS7CnaLNLmRFA/twTYEY/9EnLQcicNo3fjvTQTslAirV8EY/LpTuDd28imGBz8WOpmEbQOCfEHTDux9ompjUtsqEXJ0Wo/szkKn6pghad7JQf91g9U2a4GrJghjstksTMS/Pocq8HEE9xoOSdTEu4k9ygui+apqfstrO1N0wR93DO7khVKkgSSwMGWyaCHI4VDcBxN178x7ItxArovZ/spZQ6k/bgCk5eFavmr9SH9rMuMd0zAXf1vtCvx1YbHC0bqMQebDRiIViKvcfU7i6z5UKMMtBC/zHv9nn0sRpqFu8KpDXKlyuSszuoD805IwcHYqzkIxB5ph6yy9pGugtcpfi9nC2qXodUmTRiqYAnxI/PJajKLNibISkFXiS2oIewTAkQ+8V3tpUO8yGtbaTFHS5RBhTmas9/YyEtJmSp3hHtDuUEZm0pHxmKpCYJ5STYYhScvnyhtWCaE= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 46ab172b-5ffc-4390-b256-08d7fc3ecddc X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:37.0018 (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: Mjy5wL8f6r7LCHpE7Ih+p1z0IRKaw0byc89OZJhVZQCC4UmJQ5ZHBpriywI1gWJaGZIhmKzxxy5iif82VNRaBA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: 34N59AOchDeu8P8xDsZLwWgfx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925099; bh=gZkP7Dv5s08xu/onRyD9nziNzqaCo6tqGB+z0E4BUbc=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=jswRQ4mx1nNZY7TON6x7WUzcOLaehSaV334W23CYOd+JIbI4vK5GRnIrPyX4v92eug0 WnXh6YbVqc5UkAuVSlOjm6LNAFz7GKHmwOEvm3eRurdbe5OLoQbZcefUxd+0gTDuWN8Lg Pi6QSXOLaAskR2M5hWdJ5zhh5RKF2/RtQ7k= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 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..e7282a7e225d --- /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. + @retval Others VMGEXIT processing did not succeed. Exception + number to be propagated. + +**/ +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..da680ced5b09 --- /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. + @retval Others VMGEXIT processing did not succeed. Exception + event to be propagated. + +**/ +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.17.1 -=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 (#59864): https://edk2.groups.io/g/devel/message/59864 Mute This Topic: https://groups.io/mt/74336560/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 Sat Apr 20 05:17:49 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+59865+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+59865+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 1589925101001523.778816972941; Tue, 19 May 2020 14:51:41 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ly4cYY1788612xgwP0jLqBOK; Tue, 19 May 2020 14:51:40 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.64]) by mx.groups.io with SMTP id smtpd.web11.955.1589925099321816511 for ; Tue, 19 May 2020 14:51:39 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gwLxPQFRLlC/lQ2F08hlLocVkhN9ACia+HskoaHxVIjWO/8mA1IwH+eJxe5i8Sf/oOXqzO/RiwXcUKzrCR73ubGjIDav3D0dhOdKFKenuenFfoigS12ARqNVZ8I8zNbYK9xkyV1AGsyWlmGAuGKASzMBFaExVcvmWEgP6R9QXvzybqkDtTuZe0mpFatpYVIMzn9hyWtKoGn9GFq0w1zRP1exLVfseP9QYB2alkR/UOfeMqVLnnWM8dCC077Jl9NOrVAlIuePwPwTobXn9lam3rjI9hfFKtqLCy8Lnmr6sFGnN7dOs/aVYW7L3s+Mj/E0gtQqjuqEKP/mdscLiTtMzw== 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=aCnxxixgRQ0vBmP3L1gsmtgc4zbXHvtzoNYAWxTj98c=; b=hEV2ta31AoULTZXskZl+0IYZxkRCOe82g5r8RWBA0JdVqExTq/80GFaLhLh5o3thbggFH5EH52csWXkyLA2O8fnwFCe/WHo4k3FMAN7HRTlyx8SD1TMu+CM5xAxJ9Er8juEjA7EIBpl7847mGh495tjLu9x8xPUznHAh2STGU3NaPg3epkWg8V3UuxkqO7rakb+fXGe3jrl9NlBGtPSnLvoDTAjj584zAsFQA3riwbwXJwRjA5D2ogZBdmczEWc7Mia+U5MqWJB9nuNIJwteAfWZqYh9obUdB+/F6tyP04niGQW6UEGoCdMlYWqCDImVqPbJnAD+QQ7Afytv8LtAvg== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:38 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:38 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Anthony Perard , Julien Grall Subject: [edk2-devel] [PATCH v8 09/46] OvmfPkg: Prepare OvmfPkg to use the VmgExitLib library Date: Tue, 19 May 2020 16:50:37 -0500 Message-Id: <2fd73ece7e6cfc0212b31646f4ea4bae6f6d51a8.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51:37 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 66a4c97e-6cfa-43e0-e566-08d7fc3ece6d X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: BFg40DPW+CHWwZFCDEaVhPgvvWNGUhvz0Lb+JvpEfQ6GLlrU2CsQc0B9/Mq4DoZjAvQeXV06Ab2MUYd0poEa6H+Mi6pKAfVPbZ1Dh5vFxbM4AeE0nz+Kw1EUT21JZshLQ9NWZMsBwQALzgGHbKeYJRz7psOZKZhQ7V64LvH5czfznPtWBwfKNZ5aIpTTjbNh2aVtZ629RveD1X3zoPn890rx9mQ3EQDohnPBpkLs+s8l2wEzztVwJhcfR3c4UYAahC/aSoc0tjatiCqdSXZzrlhYLeVE1nGyYxtzaKz0bk/JH5iC+P5o4CC24Jh8BrQXTDgD0U9gkZjUcw5BOT+tf1rB7Bu1XvXqxTb+D74/E9Oql3S0NS6SHadz/qpVVLagE0OScmwaC+6VPSB2FfMb8nOfCa75zbttdFrvBzJgMuuEySZzcUOJ4wQ1cXAQ4ByKJhhsMiarshFeK0HgYKqgV6LiRcHBuy09dvVUwfjjXUxg/wjmnpzxFLHMCw0RSkKGA9+P5M4DvfeV2U4UCTfk+MaJCRb+UPm1B9O7bo9OF5e1vXW8bYjkwlRsSJtG1eEJ0RvYS9hjS3UkGDOSnBdOZw== X-MS-Exchange-AntiSpam-MessageData: Dt/G0eeelDlI2jj4s3czTMja3VHZ0SOFgGflPMzGHQ+ZlFkjSCWj2or/sDJ9SajuthTqb+qfziU/2FJ0JG0gk7IqPZFcUX6doOtESNeMZB0BUkwZmzvihoVa1tSHp7No4scJxNJnzA0kl+l4XpxMVDF/0ZoTJ57RxG0vfTRD5xlCP/MiKXpohs4E+7j0jJfHYw4exkBs8f7ZK9QQAfXLQsIumf6kJ28NSZabUx/nl3YKx7YbhN57ARWBowphRLyevRkcXET6nsPslh+Ew0m4D65razefP6C/+HrkuQihhWbumFMFy8L/2jrDDhz2K75EzLmzyNxg8K1Qqt1pr33nAhYj3fjUvTIALY0m1Bd4/fLzNzAI4OGr2s6SDDTU8Xkn3kv2QrIrOVLsuqEGBxsBc7O6kyEV/MMSYbIdIopPZMOdLA8G6qfuFjqKiLk5GQUy89Tz9idIm4NtOMko7sSZ3G7mKXGQ/vVuT9URAEj4l+Q= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 66a4c97e-6cfa-43e0-e566-08d7fc3ece6d X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:37.9524 (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: aOmIeqQcaq/a8+rili5JO/4E4WXdwf2cUZMH9WX0pSTgq0sGAzpcPUhor7YfzngDupzqFJaIR0QYFCouMY/8eg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: vMWFxBXJRAq9WzubVyw8VTkNx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925100; bh=cN7LztsnF19PYkPNb29vt+RnYDMDonFHwFbR0tHK55s=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=bX/Gzg2vmNYLwNBLUX7PQpwuXdse9ixtMlmll0na14CXZCw/pEWDfcOOU2BunGPzykh 2B9HciJIpgZ53CyiB9Z+Ip709ip1ednokCEUq3/PejY9suItkm73VbMpohD6lu7cI/M22 fyKzXYS/ib0Z9VTVI9RslwuilBCChbf5jpA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 d0df9cbbfb2b..7d7297aa1cd8 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 b3ae62fee92b..c85e988372ec 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 f7fe75ebf531..0b9189ab1e38 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 3af0ee705407..a3ba96f7002a 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.17.1 -=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 (#59865): https://edk2.groups.io/g/devel/message/59865 Mute This Topic: https://groups.io/mt/74336561/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 Sat Apr 20 05:17:49 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+59866+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+59866+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 1589925101571978.0706581424467; Tue, 19 May 2020 14:51:41 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id zG7mYY1788612xIAIdiBFfp5; Tue, 19 May 2020 14:51:41 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.56]) by mx.groups.io with SMTP id smtpd.web11.956.1589925100696833396 for ; Tue, 19 May 2020 14:51:40 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KrcKvIyDRIbjFr0DYSXPaAx2Mdn2N55lmfj809fz/xpl3tGM4ATikRjBfWQ44/IhZ+pf/GytnC83Epxg//phTbf8TSTzYNWotiGO4UcAInw9vQ0DiTr+ZOXhQ/dbWlONiccX9KqbcC4VlL/TuMae8P7Fs1HULXmsNumu2/jW0b61sboonCotJhm9GI56GGJM6vc2RPVH3XA9QqQZ5rpCooP4z3wiuimwSav6yPFe1aTyw4kJjZFOBMT0V4itWIgCWywFy4imIPTd5GCIeOrc6lVFyjxHrtnoJVLOCjuhCA0ISWAQjG/U2XawLf0BqIMmsbMdBU540U/gZQQsi/MgqQ== 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=j7a/tBtXoA1sxyy9CFowgvmE+PvBfmLepSZfF7FmpRI=; b=RCjMlJCgQyGDMqg9WgUfWt6pQpgDViWVIl0jW/gWrm7fhw8bFMrK5/pskbljh2MYZTVu9T0P8dAGwF34O3kzCfY6Rkf7pLLzsPEG7KbCX7Y8AZE0bZHBeKgFlBaue5/iRr4Y524KRcbmEbF89hjD7T9wG1L+vvOH9cOl6zc27LWsJzSoQrPpBgtF5/j93nnlNzW1QUcasPs78kBkFJaHtz1N/ranYi/bk0OSnkZEkERpgY4GKe9ckiCUMliXGXKUV6VlMsVKKScj0bqaG8alulAyJObBEblJf1LOgdfwficECz3P5sdPCj4hWaZGDf3X+VaPeJYkIwatwGQxgurHsg== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:39 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:39 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Maurice Ma , Guo Dong , Benjamin You Subject: [edk2-devel] [PATCH v8 10/46] UefiPayloadPkg: Prepare UefiPayloadPkg to use the VmgExitLib library Date: Tue, 19 May 2020 16:50:38 -0500 Message-Id: <21041fa953f3a95d5e673bbe7cff3420578e0608.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51:38 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 0809d91a-f6fb-4c8c-c54e-08d7fc3ecf12 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: l4lfcqABL74yNZgAekRYB+aU0l3iq2MWTyn1lGsMDgFLRoTuFLsgS/kCoadYU/qRrhx5lUKkHTr4X1XIcWwWZkrAtC6NaTh/y04pgeAtPxFoyJ52kIoDNX5X/X1XLWQpW3rYKgfJfRQKIgmjDhvNjKvLRyr7+xqryvjlSkwY6blJ17lWESHn3McZZ1k+B1mmBBD3WmPIdCzoj31mIsXjC9QBHiSARPLcYs3OdsGW3/Pmboe5Wks0wkjAntSFb7sb+wT0eHTlDI0I/3e4zY+tk7twWRPZDAyweQqONNI2H2+Ao0aKmsTOKln4wcotIOz33GosXz7gZqmgLC4LBUY/HqWx9QJbgiG1L2ePJZoeSaNTW4hlTwcVbBvMQQi3iNBj0Y47BcRsuwekjYBz8AHign3cENQh4BjZCRW6+CgCw5Ovxr5cqmUD/QUu6KnblJpP8bTGkWVDv7IwypUnQh3Mh7DmtFHflCvh9x4d9PGumlpu+JD3OWgZpSbuYviILtbjV6XE4+ePXX6eq3qdSiWEvvje4DWFXzObt4gT7nZhxkQkfirGHNJbVEzHKM0Lr28D8PEjir3fLufbti8d9qFOZA== X-MS-Exchange-AntiSpam-MessageData: mJwSH6kOqRjYjpueJfCFQW9HAfXyqHX8j/Jsappcf84FsA6BFNb0yDfqMTuLv12bAIIEZzl7BZicH59PmxvgGYF0aaq8SgH2BYobRPTqjNbkr6SN0SqIqF/JxTfLoNdO1cCcvw0zX3YE4BN2ZZYubIZJ2UBl2PTmfG936Imuo+BdDe0WBXhOWOjTx3FVfC32cZcDiD/+/5dvsxBqge5Cx9xqXZSId07x8/WAkx+Bocn1d3C9CFqvNnl1QYqH+GGWAemKsk1rXN5KZn3gRkiE/u3OmG/smIUVP3GN0ZqrrWMrfcDvrs80eYrAmtxxV/YusL/E+JwHTPieS7Ejxbph1hby19lueTbYpYR43kuNjTWsNfuT8532+KRWjFDuRdqEQaaxv81f6OQ+9n2Km6L3weB8ZaLBb5kkw/7CFHT9m0OBaKeTiGoHafszozeKtb7NefSkwAWUhTVKlmp72x2XaitLHBy0slwQjaA8zYrgSGI= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0809d91a-f6fb-4c8c-c54e-08d7fc3ecf12 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:39.1139 (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: 5grSOHg/fFon59NM/IkMS0BY9lAao1B7U8sAAwTCllPrIO8c6wkWb298mGlJtjKKOdYeg/tp6jzdvpSBXlfwlQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: Abs02bqc2GKXPFcosaLky0Onx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925101; bh=s5/CzYOogbCcRx/cEmEXOcoDp0JlKCj5ctf59xWSxX8=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=I0KBW2XHuLa7UT2HJJfx7SRRocW1grNmpV8fL25BVJQ0Lnhb2JfJSVR+cFqqw6pSP37 NUDkADGS7jg14Tuyd8k09SqTI2eF1M6xw+DKzdNhdGMYDNEOFdkpBmQlCFQxI8f2/c/L4 jGmmRjeryv7psUAhIoPNtihUOnzrqRWTSwc= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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 d52945442e0e..810de274652c 100644 --- a/UefiPayloadPkg/UefiPayloadPkgIa32.dsc +++ b/UefiPayloadPkg/UefiPayloadPkgIa32.dsc @@ -233,6 +233,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 @@ -245,6 +246,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 0736cd995476..adb754b28baa 100644 --- a/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc +++ b/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc @@ -234,6 +234,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 @@ -246,6 +247,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.17.1 -=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 (#59866): https://edk2.groups.io/g/devel/message/59866 Mute This Topic: https://groups.io/mt/74336562/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 Sat Apr 20 05:17:49 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+59867+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+59867+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 1589925102555758.0105381263534; Tue, 19 May 2020 14:51:42 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 4w0vYY1788612xwrGgSpLeTL; Tue, 19 May 2020 14:51:42 -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.web10.917.1589925101534012417 for ; Tue, 19 May 2020 14:51:41 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eZ/xO/RkXtpWXuxQBbfb5AQBf0N3l89ryBzw0HJB4xw8AiJKlMvZ/XHQoqNNwTqUkG3FpyjV8p6u08macRBI667bI9Lv77ZmNVuOXIg6PCCwIWF/7GNTjdtsX916hb8YTp0ipJLflwevUHbNKyScR3v54l+5Kbhlc8J2UDqwo0TvMMpMzOFr6QO+XIIQIJVH0YxWm4LFO2hjfQI+8VD26y5WksJnukZnm5jlVfCvLDCNJgBBBW0KvUk5YXai1GGGWYF4APR8FyJA/tmCLrbcsbbWuz1vMOIYlzJGTeia4UYYrXWUSaifYMjQ2/wmh+hQnQJgLZq1QKwkMa3jIIFNvg== 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=/ewc0TaNORPHSDy+iUAVkNXQsfH4TeUnFQLU0Apm/GU=; b=bkVu3a7ipaRnO3oi1KuNCvOEKnQP8PaTVtZJggU9E/tvFC0wrvu0ud4rcbB0+YNm7SnJslTIgPHpSDIKqIXe9GGFDnA5zoa1nchMgT1jeiNM1y7hR/iDsbhGOyININTFke871pdUuCXBzUpLE7TwTAESkYJphF8HDoYXOX4fPjRYuhF8rSyxx9zmb6AQWKQiiCW0Fipikp3LYpoEd1IsSc/JO7Mg6yyFYQzAZdlZzNifxoETFEzsCkvIatDMSvlFiomBk4NZ0WGdgmdAwFwktowKfd2LAmolbiYlicjOimHje4pnezqxukrlyY4gXag2p41W6Dm4GfcNC/E3fKqj+A== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:40 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:40 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh Subject: [edk2-devel] [PATCH v8 11/46] UefiCpuPkg/CpuExceptionHandler: Add base support for the #VC exception Date: Tue, 19 May 2020 16:50:39 -0500 Message-Id: In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51: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: 4092bc91-7715-4e6d-159d-08d7fc3ecfc3 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: sxMl+OOw5ZcXVVnpxuWxUvS6R3bfdoDRT+pSozn6WwwkJmj+GuLoq5p5ifCVPCdmVEc4b4szqIKOTCVh6vUQ8AMVdXFZBC60fcd/Tbtbx9iQQKEbhLJbItqSEbOdF3paq0aLsYglABVKiICIa5N1xk6NSHLXzefHHq02XB5a7Bv2nhcX0R4PUOUrJXmXKmXv3gXZmEc054sotscROrlTGggdKHnqYrw7rVmZeifiXbo0mb+Ft+iYmFUU3nBnenDzL/HRL6QEmxrG4V2hKa3W5zB/NrieZwTI7Q0X2XAX0gvJTaSZNO9iCDav9UiKRzv2gphaPGasVWg3NEVKOHXn8mYagAHalxaEOfuzc5gMEvrr3jqsP1VTSbXZZuDdCUKZyNgrhMhRXyx7Y6yc/7nIFZERho/ayoYgFjazOCmcuO5MrzMwqNax+aXPiEdWEg3EImA5gGom/S6CAeGtoQBTNvKd1vXWvWyZQiZAyEZeA75nycr6/K4k245WZGUR5UtRbcitSvgCUHogYBQ1smEATGLFscPPJAwMW/KZYXBWsDm4gxCMEnlub3arqRVD+DRsqxmij9534YB8vvyoQn0aDIKm5+yyETc8bAJOTnHUrtY= X-MS-Exchange-AntiSpam-MessageData: 2D78ylQbrRkUwGFDPUHXzCw2KIthGx/6ieZWFWryb8uEYB+8fLk7ikAGuNzWUmN1HtxLjt9CBEkuXyGsrM5vxg4nPoYXXvGt3T2Wm+IRQpIvlBL56OoLkiiacvg6jJIgtIlTk9ZUraYZkAkCdNPR/JxgUuiiJALZABZg0FW+K8mE9BuvGZUn+mHujaX4R154yOdaLLIulKvaBTGt4zK634FhqQuNHpvUNmaOzEeQ2RUE2VEU+tisYtvLtjavTyyZI7mfZNTy0OdSIDnQx0iFqREl7d5ceVEFF1TGiGveN+Lhqp0Y1nXDa7HMSNjOWz6XxRfCf5DIJyK5zGMzQruSlUx71Vl2BuL0rqkpVwj1OVYqP1iCAx85vtawlluDtP0S6x0IfdbD6b/QjxoNFAZQIMuRtAk3NN+m5peqWWkJsTJ0EntSzn44SleQw1zfjwNDEm2rAH4nac1/u3dJQyf4h6wwl1SgnvCuPZ9d9XpcN1Q= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4092bc91-7715-4e6d-159d-08d7fc3ecfc3 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:40.2184 (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: ZreTK/G0JxZhxCNKF7GrGiRlFCUSCLgYUsbNQDS6sfVdV6K6QaFZp1lU/NwUJ6TtzoP2h+dP/y3wP0LMoHtK+A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: zyWC9ihjJlz6oM8549sD8rQ7x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925102; bh=+zSb6RGWq67E4tuOvEJcTWeCdmayGDJQFXFSLhomaoY=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=bQ5/fwKe/DL05dS2Vzt/VKSZhVtz7OEu8AkDwjMeHZRSHi4lX59JM8Fm09koAoFL5ab GqrlqtwQz7bq9Az+7zkFOjda6GUn75CH846E8leOLSfr8AUEv+D77ivWx60NTCqwvdBmH CL5iAE9B/9qPvCiJBLgPasS3HMYJI9fL3Qk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek 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 ++++++++++++++++++ 8 files changed, 52 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. // --=20 2.17.1 -=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 (#59867): https://edk2.groups.io/g/devel/message/59867 Mute This Topic: https://groups.io/mt/74336564/1787277 Mute #vc: https://groups.io/mk?hashtag=3Dvc&subid=3D3901457 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 Sat Apr 20 05:17:49 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+59868+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+59868+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 1589925105032833.6982315091996; Tue, 19 May 2020 14:51:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id u4F3YY1788612xVfywJWbx5v; Tue, 19 May 2020 14:51:44 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.83]) by mx.groups.io with SMTP id smtpd.web11.960.1589925103650720677 for ; Tue, 19 May 2020 14:51:43 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Hni1piqDU/p1BFpSbX4islTbSW4G41g+9JIVWXJqbwx2KKP9n61ovGYpOvkzLH8mA2ZxpDOrWVmbmrQwjM6yE+z9y/gA3HOBukBwPPZJFehT3Ri0e6htjxYpUxomhj6oqiNKPLYCUplgGWJdSTNvav+lwV7+WaGkO0asXtDCZBFED8HBHaxXsEwsLH8WYI4STXtjTR5WArq+HP/3rFcgnTPuGXK+RGG30IGd7Eb4p3038YZ9ckE6dNtTakrhM7KRmFcyAlX9olE9DAw4m3UuwQEcn7wY8aHfoIPAG1JXBJuGDQfUkLy1OFUAW5NiSWugSqzi0LpC3Rru7GVeywotxw== 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=GMAaxZ8iyWh1OhrY9VuBCouZWkTWtrYqv9hp1ZRhXeU=; b=CejVzqoG8J9QNHxhqndOEnTqz5miG6QHkm+T4OlTbOkhfEkyYkBQH/7+Xzr73hGo/bceWItSAPplJk12dTZa68qYmLZoQvbZID9dpyY3zht1ZCj+6Xj1bj9W36m7gynoUipTy7yQ39cifXWqz4MM0Xa0HQ0mFS8Oj09C3jsm6A88rxUSTBtb4yGmecZDwu5GHRHYCSCzU5vTRMeS+q2465VBtmDlpQj2GUbZBWUoXK929a42JSj8F4ddRoIjV16Kw7eVF7RESq1SEopZ5GcbON2FsUMa8UeoGH1mPohRbLKZAk54I0356C/C0X4BhZR0duU7Dp6bonHPLSyquo6zAw== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:41 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:41 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Ard Biesheuvel Subject: [edk2-devel] [PATCH v8 12/46] OvmfPkg/VmgExitLib: Implement library support for VmgExitLib in OVMF Date: Tue, 19 May 2020 16:50:40 -0500 Message-Id: In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51:40 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 4199a42f-83e9-4125-b359-08d7fc3ed085 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: ePz4vm9gYcL9E96JlfXBN+LJOle73FxtRSE8BBd0MP6DMYhASZvztR0O+8aJ1XnembEoU0quXsa4K0erK2PCY/Wxn5GOu/AhGDPy49pSzJgU40N9Ni02bdCWesZhOupCLvUfLD8RYZ2bmsv/fnwALFuCRSfuutsibdcKSoU/E6VhLxwZhuISdxKAjo63LHNA+kM72EqFXB2+xp/1ImL9SoJz/OFTeyXluFA/YopFf6WVZiujf/BdzS02WYExEEvj9DI4HY0y01OjsIxsmPpuVq+H+yMfpr4p2/wjDj9sMa0AzOvEVCD6e3icXAhtMI1zuWSx9t0SU5NVgBTX4kG8r852qPEtAvSf+o7pDK++9Vc+1FSaiH9/APr9Dua5qZN9dYITG5DnbirsP1X/u5dyClwN1gqSCXZy+dn8tVryfm5B4O9q4o2zQQbc0OQ7hJ206J1I91FFxIUGY6iW8uujzy4ThGasw5zuT4yay3ZAQmmM1PvqzDItSHwYwCq8tvFX X-MS-Exchange-AntiSpam-MessageData: YGw+8518fGD74RO9TeoZ4B59JHQdBFP+6C05tAPg9JDrybGqbY2yCyoS35pD8Npu0uAkJp5gr8e1i/7xPGwmEGhoNIRfQ3/Ext/MVdjNwNll+pikmuqGD6UM/8WDobvIzaOLejVhJsn8UuaK9hq8EnvWLUQ0L2bqOIn/DzNUu4IPGbaA4+W3IpmCkYCMzytiI+cGke1QuDWWtyEuHpN/9sYEZLzGseqDkUQBj63ANyo1mO8EC6E6inEva1IVgdOyTUO1H0YK9s+T/mlU2AKmgGb9xI+WdEJUocQlmdLrWH0kGIHgArT9sRAiocEhU2jtHunqy2wwZ7v94M6RSXRlNk3OU8w7qAP1epOfu6Qm/Rrz3n2Df/XI49by49p0ejhleas1Tx2RAnLtA7c2zobCvCpxiJZTYDIUIbTdnl9NBZhZ6r9y17SpbePuf0fSylA5NUkHPAiQEkGyoIy1x4McmKWewIAkRnK27GwbQ7wGrok= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4199a42f-83e9-4125-b359-08d7fc3ed085 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:41.5558 (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: zfrOYCUk2id9oucm9WCyqQ5f74CZZ41z001AAlItr276gGoftTZEvzaj7eTWSeQtNma+O+yYJdg8q8X5xvrkhQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: lCA4HLwO8zAz44OffSc3WeM5x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925104; bh=YHwCrYpLA2htenZl6hqXnf31me2tD5znFn6iLbsC1qE=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=UT56DA0LOUQaCA6LMcCEwpIkDhaK/j+H5T4k52vALqlyo8nZ1ZbvnoCi35qIhwV1F5K U2FTcgYhxSen5E+xiJxBMr7MjFv7gZrnH01iBvZT0CZL0NYkX1gI7IO4W1lcKbJqj3D4d Z2Ns7lV3AziyXMRSOgUqSaiTcszg9zJXn7M= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Tom Lendacky Acked-by: Laszlo Ersek --- OvmfPkg/OvmfPkgX64.dsc | 2 +- OvmfPkg/Library/VmgExitLib/VmgExitLib.inf | 36 ++++ OvmfPkg/Library/VmgExitLib/VmgExitLib.c | 155 ++++++++++++++++++ .../Library/VmgExitLib/X64/VmgExitVcHandler.c | 81 +++++++++ OvmfPkg/Library/VmgExitLib/VmgExitLib.uni | 15 ++ 5 files changed, 288 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/X64/VmgExitVcHandler.c create mode 100644 OvmfPkg/Library/VmgExitLib/VmgExitLib.uni diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 0b9189ab1e38..b5f3859420d0 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..0e6bc8432314 --- /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 + MODULE_UNI_FILE =3D VmgExitLib.uni + 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.X64] + X64/VmgExitVcHandler.c + +[Sources.common] + VmgExitLib.c + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitLib.c b/OvmfPkg/Library/VmgE= xitLib/VmgExitLib.c new file mode 100644 index 000000000000..7b7ebea85256 --- /dev/null +++ b/OvmfPkg/Library/VmgExitLib/VmgExitLib.c @@ -0,0 +1,155 @@ +/** @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. + @retval Others VMGEXIT processing did not succeed. Exception num= ber to + be propagated. + +**/ +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. + @retval Others VMGEXIT processing did not succeed. Exception + event to be propagated. + +**/ +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/X64/VmgExitVcHandler.c b/OvmfPkg/Li= brary/VmgExitLib/X64/VmgExitVcHandler.c new file mode 100644 index 000000000000..036f030d6b34 --- /dev/null +++ b/OvmfPkg/Library/VmgExitLib/X64/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) { + 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; +} diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitLib.uni b/OvmfPkg/Library/Vm= gExitLib/VmgExitLib.uni new file mode 100644 index 000000000000..a919b484c319 --- /dev/null +++ b/OvmfPkg/Library/VmgExitLib/VmgExitLib.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 "OVMF VMGEXIT Supp= ort Library." + +#string STR_MODULE_DESCRIPTION #language en-US "OVMF VMGEXIT Supp= ort Library." + --=20 2.17.1 -=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 (#59868): https://edk2.groups.io/g/devel/message/59868 Mute This Topic: https://groups.io/mt/74336565/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 Sat Apr 20 05:17:49 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+59869+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+59869+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 1589925105973527.0805594023849; Tue, 19 May 2020 14:51:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id SHeYYY1788612xDQi7tOQzIy; Tue, 19 May 2020 14:51:45 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.51]) by mx.groups.io with SMTP id smtpd.web10.919.1589925104949452645 for ; Tue, 19 May 2020 14:51:45 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VB96MVhlKDP8+uJrw1oSBnZSv5Jommn0kqrRj04VpSL6UHkV4pt6SyTrBQeuzM5Kxz7VeNFnMhbHUBed9D8zqa22NHwhThx7CLZ/zZuBsXMiqdq1OfqvyIqgFSIqGqVOT+TAaf0xmnTcO1T4sOHjSGySCyx32JLfRmBICUUH+yp2Zfi56P2m5JJ3+/5HBVrEb+g0tAXrFVi0jsN9/2EICmD2mnsxLLEjanukcCUe207YyB70xhUH7PiebedGW2SCfDfX850fg6+6i9svYk74NGE5k0Yk6vB+SVo3JH+uS3WwIcVsXZozuW5xRym3R3FHiukUaxqnixUo4/XzEwbgkg== 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=vv1RPTU3U6pyjlQvLciqqJrBLO2U9YXhskr8OR43xp0=; b=W18EFJNoj5rIlF4Y1sEMHlGfu4tZBRmM4Bz3ZcNbo+0zBTiol848ykQThiL6lwXtEKVaZx0j1CNwGp3WJakI9IVfwNo01WzE9WkGQ+1HZ2jM7cFbMbCk8Pk27toqeN+NYlFD3Bd8RckfPW+P1FhoicCZBu/CIXavqveRGYZjQuk0sEoM8hK85ddV1dgE6DNlaWSSJRL8d8FK4MkTjniLxed2BuURx32S3S3c4nnBn9qwQUIR1NcquXP8jnr1Qwi2hUqxM6YE/WQUa6oNOP175eKDbYQuibfseC600++GTUfvU/+2oM+BzLuH27KxyOqzKZ/toahuTsufJiRZfzeknA== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:42 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:42 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Ard Biesheuvel Subject: [edk2-devel] [PATCH v8 13/46] OvmfPkg/VmgExitLib: Add support for IOIO_PROT NAE events Date: Tue, 19 May 2020 16:50:41 -0500 Message-Id: <735eff31b5d88a9b453ca8b4f4a672eeaed3fc50.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51:41 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 38d5cb92-f9ca-4879-d82e-08d7fc3ed137 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: ftTYMZIAU8T2OCk51cA9C5g3hz5LfMn5TThXEdORZUQIbRzzG4u7HsWRt2JxV7emvhc0kDquURn25B9OTFrfzvIU9ViVQ0loXMgyuwGpBUWiMrl8FTlXwG+v6fEbWSlg8vPWNpkOOog5evCZxGWhbmHJ/2Ih/UQbU4Ay+EEGklj14M2TxJN4BsI9poBq1xouHemgVAWGaz4GP1G29x6av5eX3uHjbKT/Q252RLLOlBQgO48ruHek99y8hqRjibQfdSDFU+71DUPQTWvRWtxw54YskOp4kCuLM7BVWn0HVPyXBRAcpNPgxcFerJRPZ4CiIPdo4pVtK2RtkbHhHmsipSNV2Dl1KoD5xRZQlaWtW8EkvPvq8SEsR7sl+diiC7v6BPCJQVXhwNhSSUkZOQG1bauT8zNKpo0PTGpAKZiwXYAg8WAprBIC9xBxlXnOao6cXMa9U1jwKkOvQPeN1HGvuX662anaWZPa2jQQVfAXBnnD40el/pyRJPr5NPAUGXJ8751FF4+QmWb8Yb2HqjZyQfEETf56KWi4gOS+O4QjX9lT4seg7TnbVMRUB9Q96tVzwgUs/Eb4bWiGagXtbmEsGg== X-MS-Exchange-AntiSpam-MessageData: KVwCOk1ESDqa9+d1/OCYOqdbCPniK0iXbk2Zzl73CCy11laS0UpmVaw+0F6sOkBnIuovVXBmHg21TMZdTUoU2k5WBXteULl0YjMJrboI9wEUAiAp/ye6b9QgtgIagaaUfAKcx+qSvvQWnf4api1LjESd7ALCrRDyKVkMN83DCJcOGF6RZQveqMTTNC9zI0phGXS1ka8Ntqb572r9kaxGtZnyjE8AiZqIKX6od4bRl5VN/91wIYJPyJY3Y4wLsr1U2FcVH2ZEoylcTCiG6goOrBrquriFm22niaL2OwNDUXwYbUxT8G2LCEajEvdtiMgF4w4nEhFGIPZGyAmazNi/Idf6L4T1UbhVGiujf57E0rHjqsbrsKjFHQdSUYn3Eh1RsNxlojN++9V+4kC7gVOFpBbpHPZstS9gl8NVHuKPWUBVPI3DW+mNtBaLQJv0Px9m//DuJmgRzD4SnIwt1pQUwlY+Rz/KwfqxE2KiNahvhWg= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 38d5cb92-f9ca-4879-d82e-08d7fc3ed137 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:42.6663 (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: L6r8SeszGSimfBTox4jzrksjwGH1D85sc7rDIfcnnlGdf2xqBP+5h7kxFJbA3etiS8QrWR4QDKNGgg4wHqSVpw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: lf7JV4aNnf1UnEr9vzQBUc2ax1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925105; bh=CtypACgNuFxJN5UMgAJj1Y57/+1UV4DGDzMuAFvnBVY=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=bCOMGgbTtBhBmaaxRVNVbGhdDqdJpATy/QxNY/l16uf9h2t0ZN53aAEDqGo4ZsnkLMp xPaGxZ9hFoaNH4xT9jD1ONgnf2gSAq1NGe8GPMKONctJ8xaKx9+Qzb+nk+BYS5XYA1PXp PXfx+4jEJqP+0ZK38TOnQmmWSMqvXQPKvxM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Tom Lendacky --- .../Library/VmgExitLib/X64/VmgExitVcHandler.c | 604 +++++++++++++++++- 1 file changed, 590 insertions(+), 14 deletions(-) diff --git a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c b/OvmfPkg/Li= brary/VmgExitLib/X64/VmgExitVcHandler.c index 036f030d6b34..b4578ae922c1 100644 --- a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c @@ -12,6 +12,573 @@ #include #include =20 +// +// 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; + +// +// 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; +} SEV_ES_INSTRUCTION_REX_PREFIX; + +// +// Instruction ModRM definition +// +typedef union { + struct { + UINT8 Rm:3; + UINT8 Reg:3; + UINT8 Mod:2; + } Bits; + + UINT8 Uint8; +} SEV_ES_INSTRUCTION_MODRM; + +typedef struct { + UINT8 Rm; + UINT8 Reg; + UINT8 Mod; +} SEV_ES_INSTRUCTION_MODRM_EXT; + +// +// Instruction SIB definition +// +typedef union { + struct { + UINT8 Base:3; + UINT8 Index:3; + UINT8 Scale:2; + } Bits; + + UINT8 Uint8; +} SEV_ES_INSTRUCTION_SIB; + +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; + + SEV_ES_INSTRUCTION_REX_PREFIX RexPrefix; + + BOOLEAN ModRmPresent; + SEV_ES_INSTRUCTION_MODRM ModRm; + + BOOLEAN SibPresent; + SEV_ES_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)); +} + +/** + 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; + + /*TODO: Determine current mode - 64-bit for now */ + 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 0x40) && (*Byte <=3D 0x4F)) { + InstructionData->RexPrefix.Uint8 =3D *Byte; + if (*Byte & 0x08) + InstructionData->DataSize =3D Size64Bits; + continue; + } + + switch (*Byte) { + case 0x26: + case 0x2E: + case 0x36: + case 0x3E: + if (Mode !=3D LongMode64Bit) { + InstructionData->SegmentSpecified =3D TRUE; + InstructionData->Segment =3D (*Byte >> 3) & 3; + } + break; + + case 0x64: + InstructionData->SegmentSpecified =3D TRUE; + InstructionData->Segment =3D *Byte & 7; + break; + + case 0x66: + if (!InstructionData->RexPrefix.Uint8) { + InstructionData->DataSize =3D + (Mode =3D=3D LongMode64Bit) ? Size16Bits : + (Mode =3D=3D LongModeCompat32Bit) ? Size16Bits : + (Mode =3D=3D LongModeCompat16Bit) ? Size32Bits : 0; + } + break; + + case 0x67: + InstructionData->AddrSize =3D + (Mode =3D=3D LongMode64Bit) ? Size32Bits : + (Mode =3D=3D LongModeCompat32Bit) ? Size16Bits : + (Mode =3D=3D LongModeCompat16Bit) ? Size32Bits : 0; + break; + + case 0xF0: + break; + + case 0xF2: + InstructionData->RepMode =3D RepZ; + break; + + case 0xF3: + InstructionData->RepMode =3D RepNZ; + break; + + default: + InstructionData->OpCodes =3D Byte; + InstructionData->OpCodeSize =3D (*Byte =3D=3D 0x0F) ? 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 + + @retval 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 + + @retval 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; +} + +#define IOIO_TYPE_STR (1 << 2) +#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 (1 << 3) + +#define IOIO_ADDR_64 (1 << 9) +#define IOIO_ADDR_32 (1 << 8) +#define IOIO_ADDR_16 (1 << 7) + +#define IOIO_DATA_32 (1 << 6) +#define IOIO_DATA_16 (1 << 5) +#define IOIO_DATA_8 (1 << 4) +#define IOIO_DATA_BYTES(x) (((x) & 0x70) >> 4) + +#define IOIO_SEG_ES (0 << 10) +#define IOIO_SEG_DS (3 << 10) + +/** + 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 + + @retval Others 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)) { + case 0xE4: + case 0xE6: + case 0xEC: + case 0xEE: + // Single-byte opcodes + ExitInfo |=3D IOIO_DATA_8; + break; + + default: + // Length determined by instruction parsing + 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) { + 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 + @retval Others 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) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + + if (ExitInfo1 & IOIO_TYPE_IN) { + 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) { + return Status; + } + + if (ExitInfo1 & IOIO_TYPE_IN) { + if (!GhcbIsRegValid (Ghcb, GhcbRax)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + CopyMem (&Regs->Rax, &Ghcb->SaveArea.Rax, IOIO_DATA_BYTES (ExitInfo1)); + } + + return 0; +} + /** Handle a #VC exception. =20 @@ -38,6 +605,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 +623,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) { + Regs->ExceptionData =3D Event.Elements.ErrorCode; } else { - GHCB_EVENT_INJECTION Event; - - Event.Uint64 =3D Status; - if (Event.Elements.ErrorCodeValid) { - 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.17.1 -=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 (#59869): https://edk2.groups.io/g/devel/message/59869 Mute This Topic: https://groups.io/mt/74336567/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 Sat Apr 20 05:17:49 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+59870+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+59870+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 1589925107710928.7609642998642; Tue, 19 May 2020 14:51:47 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id LnHFYY1788612xgEOx553ufC; Tue, 19 May 2020 14:51:47 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web10.919.1589925104949452645 for ; Tue, 19 May 2020 14:51:46 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i9yhsRQzZCcs2zu/49uj2P7/Hs5lD1pGgtpStdvaV+0CuuLek9SJ16dNlfYdPT//oiNnLjcJo8MZxJomztYYIbIb3D9y0H4yDDqzuabkAuJU9rdwSCoHgGvX0g1vMrsWo0BK1CnkUYdOeD0qBjSTSVdTwbmE0rIKeQaJdeu7N65drdHdXo/hCSDHTTjjfSxytTOLqWsOsib52F73hUJlWiqQdfBbOeZdtjNf+dF4k/KaQQYhYtnzchRGKqGtUKiTxL6rCIpuRf+b7Qv4gP0s3BlKH7hxY5DHJXlxRZ980cNAwB+cEDSP8nNc+jDR0D2FMyeqttLrtS+Mk8SjoJltDg== 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=ml7B94NA4Peh6+nRzEMjMn69VDEs4N2m48ed2KIn/HA=; b=iQRUc7LWxw2c/dS85kFbM/zh5r9RTuposgD1TmyxFSsxVP+nWFBt9YneuJsTf/vasbU5FO8HfNc4gVtMngTkbhkMFEGz0b22Vk+haIEWlj9alhi/EftcKXYzDGGlR8KdGYmy9ZKQ8ozep8PY9GXVvZBO5aCv78+oojt7rqp4TJ8cadaS/seGEUXv+4o5BxHXmNQ7WdW9YjYfKi29v7KzPUuDdTUD2IApqz/aom1pGIalAcjyrVmFzbsNLhBnAoetlScAJ0v4qgKrpgFRMAbEZPpm6dkpwA5X20XawqdXMfK0xDBO2V5ikIFlQu4fwxdMUFD1i7SPYBjvEYwq/tEMhw== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:43 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:43 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Ard Biesheuvel Subject: [edk2-devel] [PATCH v8 14/46] OvmfPkg/VmgExitLib: Support string IO for IOIO_PROT NAE events Date: Tue, 19 May 2020 16:50:42 -0500 Message-Id: <96260a004ba86ab5e7ad440d40415fda3814ab3c.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51:42 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d7d0bf50-1a46-4da8-fe13-08d7fc3ed1ce X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: yNhpkfRlCmxZ2U3QGqgWVLz48dZUqSl0XLMTc6k2k9/e8VufVQp6bR0PWpkjM1v7p2FLfd64MR3OzKhHwP6taivk4n4ZprDINiB9PWISg3Kem84W1uw9g1N9ty6DPLZC2SCYcOnW5E47MhdkGRPcX4VJaFmL68PrnE+GBpoNBUNP2AYiOn34wlXKPgqCnhmqleE4XuA14TCTLJx3GES3DeS+z5NL41N2uDg5hGbsABQHI/Tmit4KK7Rmc0cYpv17rR71CvIbU65yS7HBvCPejTzkLc1WoJlbKuS5aKC9CO28/LVwKBVaXs7VHG71PJJ9FgDzfUmk+S2NWilxot2dfaCA/RBDhraiuib4Q4TyR2yiFW9zEHPECpZWxCOVpeR445tOaS5sfvpFmUMcRufQiiQTTPUfpwUA2ypTekzCj4HYqWyFTZkrwkRfsT+UIJd+8kR8ASzMZypwH3h+zUYmywdrr/RqPZz7fF8Cw1w4cZbZpDUuu3IibZHjw7p+tItF+t42sFP9Q/xGXJCuV/kq9gYO0WmpCLP7VIv4V5ino23MP1i/bx15i58RbbCwqIKamU5mAIQTdvXrQ5xTrQhK7Q== X-MS-Exchange-AntiSpam-MessageData: vp2VGh7JpNwQ2gNjr7D+SRKaPFP1dFx4kxtl20lAQUjclxqseimUXVV2N2m7XzLCGfVwoTgGhEpMfFl0udXK+CB0vx+hdAF/ii1mGdKuZwyUAv2/GjnNuVFph/wxa+lz5xJ/zWIJYcpaKaJ+1euYZf/9w7bSAnlVOoMYvQ/pKxAXKKOqCqYwFw4G2pl2P94bfFXaa/jKtnSCw3hEe4a1yi7zkIcXGinPoSUpRhEt4Xe/bwNZ/3ZGpXo7PhhWKKnc1ct0LlD6rOgcLWeJBT84x6Z2Vol9B4Onl6K1Zdfsb3YsgjFoJW/jLJk8pcwqRJQKKNg37tiVrplEBK77uVfPiTIJIrWlbIN0rOWTkS0+Jbcnd5SWZuQ6mIsJHX01fFZoLH7iqQ7M14kRO1WIvcONqAvjIICa4qeQDjOPE8/n/EkbuweAiisGB1d+7GU+oTd3PX1ak6xwia2PzgiP8yWWHZO7OZyNJswOU3ko0XMDiqU= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d7d0bf50-1a46-4da8-fe13-08d7fc3ed1ce X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:43.6559 (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: jxHKWck5RbeQbLEnJ8ISA8r1AWJuSykm57psqFZl1Yik4DM9SXsJHPfvtgzFBY2FcvfyPVbm2OjtPKIVU5hDBw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: xa5y5iomFY5J4PrxQ74vKESIx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925107; bh=WugxaKVv8XEyRKihx7uJe5xUDESVDKnbeR5XSLtX+dg=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=UBil6bQKd5N811ixmsg5lOO+JhIyjxSudJ83DCFqfFI5ySSGON7YUusZU8i78Fiq5SF Ifo+06lMN94/z3sbzdDfea6H77p5dzSvjGpW1u1AqGRyTaiB8eeGfDF4ofvIBUOvTENJi +ZMV/mACsW/MGjurQezbSGVz8gb3lXkYgcw= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Tom Lendacky Acked-by: Laszlo Ersek --- .../Library/VmgExitLib/X64/VmgExitVcHandler.c | 86 ++++++++++++++++--- 1 file changed, 72 insertions(+), 14 deletions(-) diff --git a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c b/OvmfPkg/Li= brary/VmgExitLib/X64/VmgExitVcHandler.c index b4578ae922c1..906b32e93d53 100644 --- a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c @@ -453,6 +453,22 @@ 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 case 0xE4: case 0xE5: @@ -490,6 +506,8 @@ IoioExitInfo ( } =20 switch (*(InstructionData->OpCodes)) { + case 0x6C: + case 0x6E: case 0xE4: case 0xE6: case 0xEC: @@ -550,30 +568,70 @@ IoioExit ( IN SEV_ES_INSTRUCTION_DATA *InstructionData ) { - UINT64 ExitInfo1, Status; + UINT64 ExitInfo1, ExitInfo2, Status; + BOOLEAN String; =20 ExitInfo1 =3D IoioExitInfo (Regs, InstructionData); if (!ExitInfo1) { return UnsupportedExit (Ghcb, Regs, InstructionData); } =20 - if (ExitInfo1 & IOIO_TYPE_IN) { - Ghcb->SaveArea.Rax =3D 0; + String =3D (ExitInfo1 & IOIO_TYPE_STR) ? TRUE : FALSE; + if (String) { + UINTN IoBytes, VmgExitBytes; + UINTN GhcbCount, OpCount; + + Status =3D 0; + + IoBytes =3D (ExitInfo1 >> 4) & 0x7; + GhcbCount =3D sizeof (Ghcb->SharedBuffer) / IoBytes; + + OpCount =3D (ExitInfo1 & IOIO_REP) ? Regs->Rcx : 1; + while (OpCount) { + ExitInfo2 =3D MIN (OpCount, GhcbCount); + VmgExitBytes =3D ExitInfo2 * IoBytes; + + if (!(ExitInfo1 & IOIO_TYPE_IN)) { + 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) { + return Status; + } + + if (ExitInfo1 & IOIO_TYPE_IN) { + CopyMem ((VOID *) Regs->Rdi, Ghcb->SharedBuffer, VmgExitBytes); + Regs->Rdi +=3D VmgExitBytes; + } + + if (ExitInfo1 & IOIO_REP) { + 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) { + 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) { - return Status; - } + Status =3D VmgExit (Ghcb, SVM_EXIT_IOIO_PROT, ExitInfo1, 0); + if (Status) { + return Status; + } =20 - if (ExitInfo1 & IOIO_TYPE_IN) { - if (!GhcbIsRegValid (Ghcb, GhcbRax)) { - return UnsupportedExit (Ghcb, Regs, InstructionData); + if (ExitInfo1 & IOIO_TYPE_IN) { + 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.17.1 -=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 (#59870): https://edk2.groups.io/g/devel/message/59870 Mute This Topic: https://groups.io/mt/74336568/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 Sat Apr 20 05:17:49 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+59871+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+59871+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 1589925108183138.75673002678184; Tue, 19 May 2020 14:51:48 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id HcP4YY1788612xx3wL07pEqK; Tue, 19 May 2020 14:51:47 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.88]) by mx.groups.io with SMTP id smtpd.web10.921.1589925107171473827 for ; Tue, 19 May 2020 14:51:47 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jTnJECVLfXdBGdLkdb7n8SuushMFuwdSOWE2+pKBcRbuAejIN5K3xtymDtmj2mfkLijNBY7SWN4dvcRoMHBDj26aeSPAnBbumSoZfLsfNx0cuulHm6Hj4KIoepW9J9N+tFwR/qZcgr/NpGpBmseNhE/phfrRPaO3wmxlDh2pLEYBbESPIBH34bdFkfMUFlBJ+G4WPWUMP5TEBHGs3kBXyomN7oYe/yC8T82Avs9jKgL8tAxwLuyCEuTqxK8jHhyasa5KQatB+8UuqJSBW6CCaEmAclQ9wbud/R7Mmy46/WwZn90F6Uj2rcccsqGAcp32BISGNqpZ8XuKG81ViotBBA== 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=pHdzE836zVc4g0nsIYL6nk36Ff1OB0kMjtgKa8Xd3DE=; b=ivl/hlrdBWZojDnx+YxdyjszAEjFGqprWcHeMU7IweD2BBdFWaTlf6xwWByT4LtutDveXvQdEWfY1EGyWtCRCDgVsN1G4rGmpqQH8lVNvm7MAxPgccTUf1KoSf181V6LcVzHeY7V5doBi/0E6SxVEzuEC6niRSugvOso4aEiLCm9aaxSfdmLmgAzhHIWsH/jvEw1WuF4EGE8QdmrjJCdp6Db+c3G1DMLosh6aaz9bCw8vmB5dxCwU10dUmuVdwAUci8Gs3vfOTmG2XFe8xgdd4JH4rUAjg1c3N6iNL2rhYm51jZFjOwNzVjW6NApczyGPl/CZ660ezrzHj0gFd45dg== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:44 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:44 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Ard Biesheuvel Subject: [edk2-devel] [PATCH v8 15/46] OvmfPkg/VmgExitLib: Add support for CPUID NAE events Date: Tue, 19 May 2020 16:50:43 -0500 Message-Id: In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51: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: 019f11ef-0b76-42df-8758-08d7fc3ed26e X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: xGKeKfiaQ8cPIVCz3HqA1me4QEGEUQiZNgoH5rJdd32j3LPsyHKDXfhgYMaSIu8nh/9It5NHvfNkAeGMKXVwjSAFPU5m28SbIzcPcJtjfRf/dN7TxIf4gLERqROSxAgx8+seTV2uFxu9kIu5WMM6mStiPGhZ5b77PAOYakKyhaGFUyj504cblsGY+DCLRZXZCcS/ih1prL0WT9WLM+Nv+pXuPkQSYokuIN2UFWYRBp8JL/YyU92DfybxNqpVTNt8TKlBxvWzB5tV7hH7vHuRTeSkl5/htktd4CJ3URSGFyIh++mcE/Jf0aWiU8eeplgMzFYNVuWUySSdi+J0OMcSKYaTM+ZXxYFn9oa2EfROsF8RMnnHQHW/d1p7JnR4z1LB4BxSFSd17cB/SR8aDFecwUGUtfPiiOBnpsZsHEkFVafaunFpf/vz6EvGclYSeXYa35R6wrjcGOJea6Ukw7H6cLuB/tG/vr/LTbiUGCGFegDGzvdccXKH9YXbqqO+qn9yrrMxQDCVPlinQF/WMGPRQbJsu4sY3cpXdh9TEsUj42og8BjNwQEUjIwppbJGWB1ikPq8eyrOIJ0oyb5Dj9/icQ== X-MS-Exchange-AntiSpam-MessageData: sNgGI3KXfCwuuT1fQ+V6SjE4Yz/BPJawR6qp9/4aMvRMsxxEznQHIf6z/vdvvQBdrr22sixvXJNJaUSJ3Il+ChNGhJdvg1IeOoD/eB+X91EV5hvY2dw8cJ92FpGdF7T9oYnu8kxyhgJTva8CofqFSDwLWM4k5OT3vPlx5sHUxgC/9+2kWnUPuLi0d39TZuXcKuObgEfBhfghk3Mf+Wz1ESyU4XiVeDfDkZBbxJwXRwIqpwUjtsxFVla8uIdrA0nD+GKaWFkT4au9+oFFyn7rjffqWxjkUiXLEZ+rd7VleexByboHv43M40Um6t2XWhTiGBLv1L+G9ZMaJwfF+08i6L0WtSrFzU+ttxr/6t0N9kSZrRGiQKFKPt6uTEHQEBx5wmFLKRTNjfQe58NDwrmClV9a6qCmb6VWXdlh2TFRwnB0u0ITwdpM3HU/7fT80xmtXguuG+TD0Fcv86ovTc6Z1GknnAdje0XRjGcHfao2rFo= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 019f11ef-0b76-42df-8758-08d7fc3ed26e X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:44.6604 (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: FzPtk/QPsq4O72ZQHLzFkpPNJDMk7JhTtjh4HN97L9vZRRbedAeMJuKLViuOyWvGKWDhI4AApDVZrie2FJahWQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: o5PHv6HC1sYaywhOAqGJmpymx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925107; bh=5NcrWxe4hy/EzhIe29SJI2HaefIIpIa49kPiI2m2jxc=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=JOxH8OhqhdQyvU77PL0of7rBA6rUTFwFaWHXIdH23Au56GKyl5ZibOZPdai5LPa0JGw TadnGRmYJQiaoiaufgVCdnjk2Dby/jftLzFIRteMN/0WInaQV9xO7xwUwRlvHyQsm8JHx +B6dANnrzBl0ljDcoyctuJbPnRYfVd4cZaU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 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 Signed-off-by: Tom Lendacky Acked-by: Laszlo Ersek --- .../Library/VmgExitLib/X64/VmgExitVcHandler.c | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c b/OvmfPkg/Li= brary/VmgExitLib/X64/VmgExitVcHandler.c index 906b32e93d53..2f62795edf61 100644 --- a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c @@ -12,6 +12,8 @@ #include #include =20 +#define CR4_OSXSAVE (1 << 18) + // // Instruction execution mode definition // @@ -637,6 +639,58 @@ 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 + @retval Others 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 0x0000000d) { + Ghcb->SaveArea.XCr0 =3D (AsmReadCr4 () & CR4_OSXSAVE) ? AsmXGetBv (0) = : 1; + GhcbSetRegValid (Ghcb, GhcbXCr0); + } + + Status =3D VmgExit (Ghcb, SVM_EXIT_CPUID, 0, 0); + if (Status) { + 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 @@ -681,6 +735,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.17.1 -=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 (#59871): https://edk2.groups.io/g/devel/message/59871 Mute This Topic: https://groups.io/mt/74336569/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 Sat Apr 20 05:17:49 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+59872+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+59872+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 1589925108632251.37804032200074; Tue, 19 May 2020 14:51:48 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id JjBVYY1788612x5FLiJ5kAQd; Tue, 19 May 2020 14:51:48 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web10.921.1589925107171473827 for ; Tue, 19 May 2020 14:51:47 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g6+hYi3rpdedipYl75FbVani7EDrMpniAeq65BqoMLi627fBNPy4Qzkesl2oqznfGsE6y/F1EK//cbpOGLV3q/pfrDwphH5PpkHXx11+B2sB4XyEWdv2xmNGoS2v6RshClUBYJMXhGRGjmSUw5xXgoXLToXdDsm8hE1OgK10tuHj143y4eO2hWRXsv5i3HmsewkpOvQrmMsjZctKYBsMz67d8X7m9j5JS/4Fn5+tFJKWK8jm0aDWjnqN5vQgW4Umz2GVzXSmR6+jNrY3JUvYcAXWHcWHKLF6mZ2XcFhgcnyes6s5DdmitmYXXmtT74kuaQfe5pS6sAk9ZBQ2wRRh2w== 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=HhbV/jlpH4VFF+4g3Z4YBGMDxneVSeIv9RfgxMMNmIU=; b=gsJovfvCBtS8aOKHx4vXWnDzawAK5QcKtgAXq1CH2q7/6K3cPejT6xGbpE6vw61Sa3Xz2g/tSwflUdPqvMwCkKSeWVVDJko89x3UKlrVZOj4N272FzMj0QAshXPYC0JnPz17n43sYxq9vAtR9Cy4Fi/8/7265WPastqeIs3lsarG2tpL7MnYcqeRPHCtxcNVrvaed7mhhnVDj5x2VF0NK8dWe8Wus2+mBhuKtcJRybBcsdwQMR0NW7cEfQQJIE5lzNQ9asu8WfQRSGDc9lY4LJ6KcBWuFPoAYFbOKVPZK8NIknnuNtyUZLYmCMVCY4FW05ZongqyY/FfDiFpKJ0kdA== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:46 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:45 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Ard Biesheuvel Subject: [edk2-devel] [PATCH v8 16/46] OvmfPkg/VmgExitLib: Add support for MSR_PROT NAE events Date: Tue, 19 May 2020 16:50:44 -0500 Message-Id: <0c535885cd63be2633ae1f421014f5d2598fe0cc.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51: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: bbaa557e-1f10-4e63-49b0-08d7fc3ed2fd X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: 47dhoHoxJlO9jKddkZJTnSTqL2Du5Gbg81AZ990BjhnC1srMkljE+MYGyjtPZHwcTXloltbaNIvk95UguclGCcsPqmdBgIx6EITYbWqws2nqONCPO+C1vo1/OVDTKrSDb4WoUzV6tp+C6+XvAocguvu1PScI745FeS4GZvfN4O2hL4urjx1bW+VGd7ZBHFYlIYoDM86PYWSUcQK6Z8XMHqqVz3cwRnAGI+4+sBOKgYLmd4Rfs9m8vYHFJfZnYWNO+GFIawJl1BFvS0wRMXQmnK+pS30D73sbZjKSEZ/FRTDvZCpS7ZeOTItZVTNUtOtDEMYSKKJCDtWi7ncdpGlWknyqNQ9NtH8sfi+GVHn5gkNnQjztHN0o9zCyDNLglDrEEEQpI5hh4g6O/VvTvRDx6pSgYG58pE0tAHBg9TznOt3kiNVp0q9/1lMxtt8y2sEcRJNVKV+VHUHUaBnOG7mLqQ07xXPUHbnPnYENUVsvGQq6ipfJzP1X6oJg4djFJx6zA2nx3Iv6y7ALdwfjSJGcmfMqKybZ/DM2NSuD7EedWD3ho6XLqnFfOl3rPns+xniyr4ki3MIe0JxIsoVSV9wtog== X-MS-Exchange-AntiSpam-MessageData: DKtBNCfKbrITaaVlUs/0YKWz4yiKfzuVi1GVogu9V5uoc2EhGZfkpU0YkuX1iqadHKGQ1Pr2p/Llv93wEV/OoqQi6qtn9k+3rkzH19vISYNMelaM5fdT0+FiuVXwa37awkMuymvqyOzxEad8UZM+iY3Y/kMEfmcPD7LvGKtqK2wGJAWtg+Lm/GG6/0c4PzQWF+moCEJs7hBCv2sVMltzIQ4DugECKfcZXnzmBJdOwSNOzUtRnD9VsZsMImJPUgYJHSzqczW77HKp2P4lnrvRo7WKXBOFA4hDNrsmuVONeayo+ztEwB016iBY5uUmbFt6aPm/odxua34vBScQgn3pYTwltfekt1E7W0b4vVJdlIkdqOMkw/vxfNSPPi4g9gnRLMWwRbQlg5ylrYm+60VxnSEjABCv3TnXv9sy6YAHxRGvzib/uNWr4ehW73RfErgdP6WgnC/eSa+FPqbBwvDdh6aKqfdAFp+OOpkeHwhzZII= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: bbaa557e-1f10-4e63-49b0-08d7fc3ed2fd X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:45.6150 (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: VpA0/54OB120/bn092WI0++jpC2Q66yovEFGSqX0K/+rCT1IG8BMAv26UR2urAWnhHvn7gwvUKdETjbWXA4e7A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: g7rTSiupYrmrkBFJb0FT4f1Ax1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925108; bh=/+g8o+I4ReXB2ZJFpaTCSgs3yQejwvdJ2jyI0GP0v8c=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=KBAJT1RWQqzBF6sx+9j5dU0kgr32yOgRM00aew8ibmiQEPL1VdlIeMx6HqntQ59jjeI qxjFni/e/6QhOalMy0H8S6YHpGsdtrxtGDENka5vVwWEeur0s3RmsfiAiQxX3rJ7kVfWH npqMK+HbF1SY7Ter0ApHf/OvvxkhSAZDIZg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Tom Lendacky Acked-by: Laszlo Ersek --- .../Library/VmgExitLib/X64/VmgExitVcHandler.c | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c b/OvmfPkg/Li= brary/VmgExitLib/X64/VmgExitVcHandler.c index 2f62795edf61..1c6b472a47c4 100644 --- a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c @@ -411,6 +411,65 @@ 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 + @retval Others 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); + /* Fallthrough */ + 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) { + return Status; + } + + if (!ExitInfo1) { + 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; +} + #define IOIO_TYPE_STR (1 << 2) #define IOIO_TYPE_IN 1 #define IOIO_TYPE_INS (IOIO_TYPE_IN | IOIO_TYPE_STR) @@ -743,6 +802,10 @@ VmgExitHandleVc ( NaeExit =3D IoioExit; break; =20 + case SVM_EXIT_MSR: + NaeExit =3D MsrExit; + break; + default: NaeExit =3D UnsupportedExit; } --=20 2.17.1 -=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 (#59872): https://edk2.groups.io/g/devel/message/59872 Mute This Topic: https://groups.io/mt/74336570/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 Sat Apr 20 05:17:49 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+59873+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+59873+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 1589925109075922.4879890022592; Tue, 19 May 2020 14:51:49 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id uuzQYY1788612xS5PqYiynn3; Tue, 19 May 2020 14:51:48 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web10.921.1589925107171473827 for ; Tue, 19 May 2020 14:51:48 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PqmBxhZhfstiwsbJCmyJ1fTOx3uIJYRfY9+m3inxp/Fe3wgdYRTqJ51S2icdWHuqNt9JaG0ZSDCl7msL5fKoGXssRX4QnMBKS++LDGukUks5GS7A3I2jm2EzvHCMUb8pupca6lB4KxsNakGA+sKAbPJ1KoGVMzC1vyOpzSGec5lvIp35G+BPBZlhkmTW1eF84jif4LB/eh/FIDlEFnwPfpewTLr2FsLQ+8F9NSdoil/qal3ZYxvXEWV9iPpE1BLiIwv+uAjTSEf4scOXXv/4oYkruRJfLb4q6vgfLAwpPGU7hoUJtgX13sBW8ZypvenXXEwADSY1XVQiW0FWB70Sxw== 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=hnqlc+EaXTFfhtNNFca28U3waLn14gxVLejE7G1nohA=; b=GyXddPDcYd224DS0ygU+hBhqpInTbVY66u0iUSa7E2I3OtUnrbBjzdCt72lRQBVce/sc9baca3Mie3wEoASi+geuq/QSUVmWrbaH56QJ2ld0TMDCU6ISfdNroOZWXt654Ug6NRVOMZbkOMXdbOutokzIAh7CRDD3RtgCwA4onLR5FbFJIzGldiFWe/2mP6vDLTIbatMLHjOqgUKlcgTqSlAF1J5bVhelXpQTQS+YhDPBedvkAsi/5DEisowrZlbv1rZRghEV976ZafCCBOo4IqkwpV41Au9DgRuLUFLco5d33FZU+GeNOWOJq8NoE1Gy8PKLnEJFYkYTdi3KfiOHww== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:46 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:46 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Ard Biesheuvel Subject: [edk2-devel] [PATCH v8 17/46] OvmfPkg/VmgExitLib: Add support for NPF NAE events (MMIO) Date: Tue, 19 May 2020 16:50:45 -0500 Message-Id: <1a5f159a487e2f20b5ad7bff83659fb1442ecbcd.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51:45 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: f98625e6-dedc-4447-d76c-08d7fc3ed39a X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: OQY9cM9bw42RCD6AZQ3JYaL6q+9C+gNeowy2gCbxKaBlcVhv0IJXSxqds51OO+pQ696gD5pbL355+Z214bRh5gZD9A4qFpf3pnkTcEehOdFDJb964lKHrVYvSA8QD1BivFI76/ExJcYRuArG3w8i1M+zmkhnLPTxlCSJT6JbD6Aut/Y0PvtSP9LtLekfErQDwUcSo02Os+2+vxaeTa4eJ6IpK03lH99O4yTiKhCPmOob2tvte3hbNz8zHsvQPPJLzkfXyjjICRhnbJz5SWcIIaowGkmjVyjWzIpRbKyjjN6G/7qsM2G4CY7Flq0AG6J1rC3qQID4w4sIUE8udmUwpZ+hEVWh746WYjcDnMelNZnLt5RDkx8CAqM2wsGWcafqA9QPwgda6cDtoBrRhWoEKCD4Mr+xpEOg9R53i2KwrYpN78ZEGF5cmyAmeylbizDPbT5B/tHKIMglA2hL+ZXt9HEUfsww+cheYsiLhG0cZDWGGHprbc3Q/Fz+cib16x8+TdISVrHyQ1RUT0Ruefot3pj5iDeBPmK96yZ5XnIam8v+A0UkiTLyfOahOCY2QTtEDlZ4IhPIStTs1UYbaZZEqw== X-MS-Exchange-AntiSpam-MessageData: NdYlZC/gfBaB0lFagZCWSJfeHNGkfj9x0dVJYUeB0WJKQhZXpciYVXeqZbczxrDKzJcMCZGgD1lSRa8nz9rZz3fdIi8Ho5C/hycAMiyHp/nnYzmFpfjWxKpGlgUgKW+Q9bKPeAe6QAantOvVsUDDymN+sVh/dfhLjYCqmZfl6sVDpucZQ6n5m6Ihu7gCJ2UpSm52DaTjPC/yu5XGgP3L5O0NEmisv8GWKt1WcQIU5xMVNcBQwwqa2n2OjFqDiyO8CxFVsfH4tqi2IvIhihhKF761hQ+cPfVoc2S3EPBi4xiS30IZkoiRddNSmBfWT68sSZezvwUSgOlFhwyf2PiCd1Jxi+/4FN2K8AG6jhuwvrouc6V2KHtq0wYaoPGlX3JTA/GhIYifdnTyQPtyaw7JOOYKIM29AIiXAREmvxYjxkme9iisCmodYq3sikVoEbK71gVeYIZHwWAYVGsbIV2tim665m4mcvFeMwzqZNyDIXY= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: f98625e6-dedc-4447-d76c-08d7fc3ed39a X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:46.6645 (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: epcfqL6U1ms488KZGanIQoNrVyqMD+fHMkc7z6aa/zRsNTqtHZpKqCpWQjwuNfOJLywYa04sneb5Az6nqYrHRg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: 7aCo0s7xunUakAPHPTubPk07x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925108; bh=ine+m1/f89xRHa7UKHJQzsUj9+1qOOlpk54S4+/52ok=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=ZUXYy0+mW9VG3LC8R828XiULax6Bv+gxLsOlV7q36mimhw3rjrYZXQ882i10J7VWQSq zRlKnww4nHJRXQe8/v0AXpseLG+uCSzfh7J0OLyKxmClkPq1UKqM9v+fiLQFnl2jjxRcw /f0X2BL3g/3Qlg3uTeDTOezbhHcQ8ZYed08= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Tom Lendacky --- .../Library/VmgExitLib/X64/VmgExitVcHandler.c | 436 ++++++++++++++++++ 1 file changed, 436 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c b/OvmfPkg/Li= brary/VmgExitLib/X64/VmgExitVcHandler.c index 1c6b472a47c4..50199845ceef 100644 --- a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c @@ -224,6 +224,263 @@ 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 + + @retval Pointer to the contents of the requested register + +**/ +STATIC +INT64 * +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 (INT64 *) 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 + + @retval The memory operand effective address + +**/ +STATIC +UINTN +GetEffectiveMemoryAddress ( + IN EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + SEV_ES_INSTRUCTION_OPCODE_EXT *Ext; + INTN 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); + return (UINTN) ((INTN) Regs->Rip + RipRelative); + } + + switch (Ext->ModRm.Mod) { + case 1: + UpdateForDisplacement (InstructionData, 1); + EffectiveAddress +=3D (INT8) (*(INT8 *) (InstructionData->Displacement= )); + break; + case 2: + switch (InstructionData->AddrSize) { + case Size16Bits: + UpdateForDisplacement (InstructionData, 2); + EffectiveAddress +=3D (INT16) (*(INT16 *) (InstructionData->Displace= ment)); + break; + default: + UpdateForDisplacement (InstructionData, 4); + EffectiveAddress +=3D (INT32) (*(INT32 *) (InstructionData->Displace= ment)); + break; + } + break; + } + + if (InstructionData->SibPresent) { + if (Ext->Sib.Index !=3D 4) { + EffectiveAddress +=3D (*GetRegisterPointer (Regs, Ext->Sib.Index) <<= Ext->Sib.Scale); + } + + if ((Ext->Sib.Base !=3D 5) || Ext->ModRm.Mod) { + EffectiveAddress +=3D *GetRegisterPointer (Regs, Ext->Sib.Base); + } else { + UpdateForDisplacement (InstructionData, 4); + EffectiveAddress +=3D (INT32) (*(INT32 *) (InstructionData->Displace= ment)); + } + } else { + EffectiveAddress +=3D *GetRegisterPointer (Regs, Ext->ModRm.Rm); + } + + return (UINTN) 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_REX_PREFIX *RexPrefix; + SEV_ES_INSTRUCTION_OPCODE_EXT *Ext; + SEV_ES_INSTRUCTION_MODRM *ModRm; + SEV_ES_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 @@ -411,6 +668,181 @@ 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 + @retval Others 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; + INTN *Register; + UINT8 OpCode, SignByte; + + Bytes =3D 0; + + OpCode =3D *(InstructionData->OpCodes); + if (OpCode =3D=3D 0x0F) { + OpCode =3D *(InstructionData->OpCodes + 1); + } + + switch (OpCode) { + /* MMIO write */ + case 0x88: + Bytes =3D 1; + case 0x89: + DecodeModRm (Regs, InstructionData); + Bytes =3D (Bytes) ? 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) { + return Status; + } + break; + + case 0xC6: + Bytes =3D 1; + case 0xC7: + DecodeModRm (Regs, InstructionData); + Bytes =3D (Bytes) ? 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) { + return Status; + } + break; + + /* MMIO read */ + case 0x8A: + Bytes =3D 1; + case 0x8B: + DecodeModRm (Regs, InstructionData); + Bytes =3D (Bytes) ? 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) { + 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 */ + case 0xB6: + Bytes =3D 1; + case 0xB7: + Bytes =3D (Bytes) ? 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) { + 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 */ + case 0xBE: + Bytes =3D 1; + case 0xBF: + Bytes =3D (Bytes) ? 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) { + return Status; + } + + if (Bytes =3D=3D 1) { + UINT8 *Data =3D (UINT8 *) Ghcb->SharedBuffer; + + SignByte =3D (*Data & 0x80) ? 0xFF : 0x00; + } else { + UINT16 *Data =3D (UINT16 *) Ghcb->SharedBuffer; + + SignByte =3D (*Data & 0x8000) ? 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 @@ -806,6 +1238,10 @@ VmgExitHandleVc ( NaeExit =3D MsrExit; break; =20 + case SVM_EXIT_NPF: + NaeExit =3D MmioExit; + break; + default: NaeExit =3D UnsupportedExit; } --=20 2.17.1 -=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 (#59873): https://edk2.groups.io/g/devel/message/59873 Mute This Topic: https://groups.io/mt/74336571/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 Sat Apr 20 05:17:49 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+59874+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+59874+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 1589925109953913.3785542164703; Tue, 19 May 2020 14:51:49 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id NgSmYY1788612xGUEfYa1q0F; Tue, 19 May 2020 14:51:49 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.74]) by mx.groups.io with SMTP id smtpd.web12.961.1589925109062763784 for ; Tue, 19 May 2020 14:51:49 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nuLULj1UP7qQVMam3jp1HwvuU7ahLwLoT8CiLjs3fP0tXzulzt0pT+HbFuT3eVLZbvXQNm/hjZTBn7AOgd0BbbQD1kcj74kJtKSCnHN41/ALt6QMb79pDSVNAtBKwv83cPuG7+/1jRv62J1Bm+ckNSeVdWp8TeR1VG0tQ6GXvCPfxuSs1yic6vGPoVYeVM4lYs5qhQoIXbqYqd2CBSJKQPuPPxR31DSGqcbarolI9cgCZjEc4YrgXoWoINFLJ+U4O4LT/PdY/Nvx4ys/5s5qcKF8JGmbpKOBFeg3ANs1/DVbUdgBaErahXW+VLodHdd/CWBBORPruiniOC3hlr51LQ== 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=VRkXr9wafBx+JkQkLZlLYUNcNBMHtSDbqgVTYcK9XGw=; b=iEiBJ+h6koiT9TAoMymvfpBbaV0R2NEVZwMTSayu5LHTsFBJsyxnGGtzMM/WUA44ai5pxJQjPcqRo+YVtp8WNWOLkwsxd8ZuoUXrm8na4E+Op/++ZNYOC9H9S6dEL/ciWg1EHN04ITDPGjRLEaUKnnnfzDLrLm6HQxJe1xmwfqUB1BY3XwyVdWCeFnKYVsiihvE/+Br7ui4WJD5TEsQ+cdkRwuJr2+b90X3mRvOlSvsrhCDErWEecwpZPm6BZAEkBcD1f2z9BP0kk6MCqNBEDrWU5Yk4SXO/AyDDtDaZf3er3p8M9C+Pt0F/oNumI63G83r0TxEPgd0DK69+asjNJA== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:47 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:47 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Ard Biesheuvel Subject: [edk2-devel] [PATCH v8 18/46] OvmfPkg/VmgExitLib: Add support for WBINVD NAE events Date: Tue, 19 May 2020 16:50:46 -0500 Message-Id: In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51:46 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 2a71024a-6482-4d66-a244-08d7fc3ed42e X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: YyR/REEgDP7mdgFLCDYWzYSvT+DndT5PSo17WaHPO07/NrSuw5idFrBB9Bq4sw8AIMx6gqkdr1kn2HF5O7cKhuctDMETygcFyDMUClsY+A8AcNcsj6TG4YUzUR6HGuxW0wF1U4H6Q5WpfsZ1CCgBC4cO+V2QQ6VSfhoY0gy4MCuKKgxrz++cXqgxUi6vizi4tHSU2oVwNzMYgziJy76xa4PNLUYb6HuRFezIsMCHSQ5dTJthoG9CCe5CFQEu413qYu1mKW2vpWvSWvxj7j55hSrz5Oi8cR7JGTqU8gy+O4BsXR9g8nIzN6q0GMmyhYUqzk0GN5tdNQhMq9B08Yl3Rfd62/ZvqoFC26CFM/Me1PgU70PSXrfQGbNy6xw9fab/la1fDMuxUCJ5v61LVCuxLeLf4ZYvLeB3OsD9LrECiRTFK044iLk48p7N+aHtC6+zpLoDlKJym2y7MxYceYZCdk1FdAC/qhm+0iLKoseGfON9RfopAHHpvHTiTb4GixeErhsroOFU1UAPPciBnJ0CTK/r7DXD5QGSVc+B8fkzhUyJ2Rm7mbzWzmfeSOR1RIvadJyxDyZqR2UTpqaSx/h+kA== X-MS-Exchange-AntiSpam-MessageData: DJaQSMap0rj4cwNuoKFeDQZiy1lFDu6W56G60VMo3u4kb+CLK9EGhGw/jz+a3ANfavkUnQBFJ/yiuvvuedM+IGtgKnVbVBKnCYxPGjOY/Ahzvwdw5r0BBbltsm2OJruev6kt7HrgTgMpAKhunR2J35PrPAb8V4kVpY+xQQdMKPuqfMq/Wrh/vE2H4SXJzsNBqEl8QyU+mKAIbMneJU6m4Ya+diXyhPX5SKjLt+cMxnrfhbLA2hu7HJlZSq0qgU2WsMLL8aHPICU3F3n+4f7XZgnG/M1cLRoCUqB/51p2oEHGh1q4z93kBJ2NW4wNjMdBt0HFe++36WMcbtzMKo/uCSftO6g2XmBkPvEpxEq9SxULZeLsWhXShY38ttbOg9HrzYcq5AeyyvosZVEPLzztFOkP9nNNV29KSJigVkKS+qmu2tkYwjofJ/wWT+0nCszqdm7crcgH7S90yKwIUamYFp58yYqQcVT3iHBjB/1Fp5c= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2a71024a-6482-4d66-a244-08d7fc3ed42e X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:47.6631 (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: Om0ziKHyTB9oSkZzQ3W3CZyZSsQEf9pUzTsFwGS7ClYIjOqGc/hC6jf5m4StQodTJk0uXUf8x9zehrfwPcyTtw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: 1a3DsgMlvyu0yFxo6LMUK9SUx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925109; bh=FU/xJla4cdHHaDbLhjn394sr4KZYxcBFhcWnwt7m0XU=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=uAHxEBwRua9DSZCIwwPFc1bxj49G/orMZhh51zL7QR5xBibqFsprjkyJioIremNP+D8 qzOjgnB16PECHNsoLMINcev8df2HITnlpVryVglZOhix8wGYYsKErzPmrIhXtUg0qawba o0t60Bo3VHSRNv8Tai83Jc/x33mQIMQu4qY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Tom Lendacky Acked-by: Laszlo Ersek --- .../Library/VmgExitLib/X64/VmgExitVcHandler.c | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c b/OvmfPkg/Li= brary/VmgExitLib/X64/VmgExitVcHandler.c index 50199845ceef..0cf26c052b32 100644 --- a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c @@ -843,6 +843,38 @@ 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 + @retval Others 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 + ) +{ + UINT64 Status; + + Status =3D VmgExit (Ghcb, SVM_EXIT_WBINVD, 0, 0); + if (Status) { + return Status; + } + + return 0; +} + /** Handle an MSR event. =20 @@ -1238,6 +1270,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.17.1 -=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 (#59874): https://edk2.groups.io/g/devel/message/59874 Mute This Topic: https://groups.io/mt/74336572/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 Sat Apr 20 05:17:49 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+59875+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+59875+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 1589925111396599.0309546792266; Tue, 19 May 2020 14:51:51 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id x1lDYY1788612xCBfmXFvQqp; Tue, 19 May 2020 14:51:51 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.45]) by mx.groups.io with SMTP id smtpd.web11.961.1589925110091328852 for ; Tue, 19 May 2020 14:51:50 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V3yeYrQaLItfrOZDAfkFyFiCX4ogMQB2glvJxgR81fPPOhTki+76Tj5Z2QaMwqA4wZMOJfxR55DaKYkWpOSF6sap5CL0t5uKT07j4BCbMzp+dcfreL4fedySVI2v4tgH6TvwF9lQaO4xqd8EboIJSmajrnVcDdSRfd/AZYEULbIOPl7PqEacf/AiVAoa9DZUxDumJA0B1fUenD39nj1B9RFzwFUBapke/SuuxRhaDZxvX1ZJxWICeJ3UHC6B33+QoDnR/oBx+cf2A33JAA/hmzi59uDBvfKohYICsbyyfe/RtRJmrAF21JQ7RydZE6ccrs4QIZzmIaqjmafswDswTw== 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=bI10WG+KAAk+daGwfE/hqSTcIf9P06YRdZ0Ctm0S3xE=; b=VgmG7/XzFiaM8hRK9CnAidGm+F1CqT4teQon3S0MBRC+GxOUuFugwVcMIV9RyBzzYz/giuwcITtREx810P9+voFTWX2BDjmEyZrvhxuWdY2PdPD0drma8+G93qnBo4l+FK8LYK//fJmXDary84DVObG8dS/cmZAkyUxH64dB1Z6JiTMgNMZDITbKalMmuw8sGn1JqQGLsHaB5ctXk+sqiOuf88qevMloQm9lGIVsOXtrX+tjrBgWdlyDk6dmVmu9P/uEepU2AWoiScPGl7P4fNBehit4Mg+ch9QlH8hRh3e3+hnQqgiYlb2Szyx1C6qlHy5LRTUO+AhB6FxlFUJxnA== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:49 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:48 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Ard Biesheuvel Subject: [edk2-devel] [PATCH v8 19/46] OvmfPkg/VmgExitLib: Add support for RDTSC NAE events Date: Tue, 19 May 2020 16:50:47 -0500 Message-Id: <675998211a44fb140d5847db486c8a644e0ec003.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51: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: 21d614e3-3896-43d1-d920-08d7fc3ed4cf X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: 8R9/wd69GL2PXD8l5mfIhqbnj6NEXg6Pc8eITC2DlldMsrtRzkmSOU0fiJrHH8a+HROaq035afVp3Pgd0GuWwFwHVKvBd+t2rYknowBHP+/b4XiyCfRFp6iH2xLw9xv/2R9EhKqpoBXVnF9O0GBhxrjm7McVVkgn7I/aD/VIGpIGaBazeVuESKeJJXTeNYtma8iz8NA04Yk+NuLu6rJScQjxuSzzB7mzT5p4GVjrJ8SpxLzoYR5LUGriq/qLnqXtAThfQDZT/IQLL99M1/dF/e7mzBhOtYE2p6n/VqguN2OOsL2nyDKGxJuYKEveilYl5eXaHknXL/glW+yZbdu+7w0ADBmMR6SJVwWluRb4TkDuNt0YA6eC5vGSCf/JV40Q9o5bBWduvak40PNgEqdV4PaZzW878mrhOvYF2zaEPq+uahEFQGUNWY28Y67uFfh1loY5yzv7sECDYT0hldNkQv0TT90I22JlLuudkwTXtNx9JhkPQ6zLQDZKiuprk0fQ00ZYGCQ17XyYcogLwJxHdBHSyYqyiy5sDKNjdpbUKkbWHJFE1NGm+PWJYpZz1i2egbnsegEtYPfyD0yeGqNpiA== X-MS-Exchange-AntiSpam-MessageData: nbxH8nHcClv7DlI3Qt87mIlqwbQ83haOc6DTMStWpzlu4ofgK58d1wVBZ6ipb7UM9giDFveCb13ZD9cbxQN+RnK5jXrn8jlWJzArP46k2AIGhrXGQak4Fy8RdwQO12aazO6KtkiWwpvIAx1Iizv4+e0bmZ1WxihS2L/LzJfgR9/0Wu3VkvphAQ96n/uBgu5WVK8l5aqvU5OQKAQnz3pOS3WR+mzIcdYMOEjvIrf6Ry0w1GrS0/QGBHkI5YSXPhTIyzgESt9+IWIAcugSx9Yh08w9WihLU5w4uNzb5vJxFxTIZGxtWejB5i/kd+dX+rj6LTU5eOBdB+tqdbw6/WGmdx9i/TCngbWgzAXd7IFYxGOYqktNEgaKW0GZUIe8bItZWc95tBQnioruSEb+bMnTCIYWs4QVmQoYHp6baCT/PhI3DFavJxFhT8xU03Id24c3VI9eOq2buZ3D1kKof6RE4q+iHJRb0h9fG/stKeNbix4= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 21d614e3-3896-43d1-d920-08d7fc3ed4cf X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:48.7956 (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: B2N5+CIMFoMHZH7RgF8Df1XEnOQ/fN62TKAYsIPVed4I+qOuQG99KIkyoFB+dCPs8sK0zlJCocX9Q37DT3hjdg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: RzACULRXlbcvoVxYdNZbjEYbx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925111; bh=hQY0GcUp+ENu0ec/ugmdV4wU6KgcaGMhmEChZTSr2fY=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=VZMjM9pJIhEeHf7V/DkSe6/wM3qp/HKFqPoZ8KtIFMfw1xPKdcNotDR0+iHD46bgn6z ZDuGm7GwW9uP5hD/tZtNdq78GWmbiQFBvcD4Fx9yTVxQioC6fuKtTk/NsXW6zYFxOL+5I 4UWJRC5ySrb7+YvnMsigSePeGN5DVOqPtyI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Tom Lendacky Acked-by: Laszlo Ersek --- .../Library/VmgExitLib/X64/VmgExitVcHandler.c | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c b/OvmfPkg/Li= brary/VmgExitLib/X64/VmgExitVcHandler.c index 0cf26c052b32..3d2a9c6f9bc9 100644 --- a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c @@ -1214,6 +1214,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 + @retval Others 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) { + 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 @@ -1258,6 +1297,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.17.1 -=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 (#59875): https://edk2.groups.io/g/devel/message/59875 Mute This Topic: https://groups.io/mt/74336573/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 Sat Apr 20 05:17:49 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+59876+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+59876+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 1589925112190961.0545993798946; Tue, 19 May 2020 14:51:52 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id sfhEYY1788612x6fdDRRkjtV; Tue, 19 May 2020 14:51:51 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.81]) by mx.groups.io with SMTP id smtpd.web11.963.1589925111316428485 for ; Tue, 19 May 2020 14:51:51 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iicR3W7brPQ68QnaNWwPa+nWCClFx3IM71f2+bk5uVnFnvbz48yIISksJaLdQ1gHPtDufYGd8j0CrM8EpPlHmmWp8I0W9WvKEB8hyJ7yBgtW3ChaYZi1TzHpCuIYnhznR+Muk/2RLUpSblKFWhFYCh9hFEWIxyG0RquyC5zd4lNyGsfXaNYd4XIrGQDwUNTzCXRBLE3TYr0/7Cn7BKabIPv/SQ/CSUEvOsrxTZAGZZOWK+4qM8s9BD54vD1QSFjEmpy73fjfdSOR/mB3ElIwebIhgILpUCv9NKJgvA+EIV6EAUeE6+668na5NTZBBBSLXOtkCft6h7WFUS7j3jEiHw== 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=/WlyPof15v7rTYJGsx9wr/NCRY8pwhrTZqKa/GL9i1w=; b=bm48Hq8p0QFZ+t4u43EC7rAU/8AD9nzY7szcYBH2ZeDI1qAkR5ttZoQAGDCWyhCq537OQLffF+fOnTFgC12HKjekNN8BYRuLO9IJn5CACXVAD5M5zPhMoGy5e7jpMfQVacJ37LYUJTR0Ka0IXLmK+sMhPmdGcM9om3GAuYy+3EcHCNKxgZyNIy7byZERqxC7fgs33LNIQo+4tsXqo1hLfZGFqp2QTED56/gCZeJUUz2uEuQLWMpYxY7NDBVm0iNwTBwmkhwh8tluNDM91R7rTWhyDLrLim633TbABA5aBjRZXSc2qLfH5kIp8dcM1Vi6WekpJXzurQcSb91nHHrDnw== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:50 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:50 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Ard Biesheuvel Subject: [edk2-devel] [PATCH v8 20/46] OvmfPkg/VmgExitLib: Add support for RDPMC NAE events Date: Tue, 19 May 2020 16:50:48 -0500 Message-Id: <3aeaebbc0ec807d8a953be4a74017e5073fa60be.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51:49 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 7820f88e-ba42-4087-3aba-08d7fc3ed581 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: zCOqDfedimOH8t58tbKCMYzLJHrjzDc5dS3ZUil2ooXhgYSkgNwwApWA5aItN4vJBIKMvPh/qK14p2RApajE3GXrVYI72pO8GlIss0fygCRhhEgRBD2A7B40u3FOftrdj0IU+pzaycvyz2m8ggpNvJebRJoHhg6UfsNpLSZ31XGbhREqKB3GF5JQRXjarVTj53wTSRBOG7LYIwxn1+1yqAL9sD134BKHHGOSLgum1m5yn/ldVffLNqJ9/f9efMoX+9fJ0S241a/Xwci/TDl1G0etsbMfTBprq9sZilDUfJjyS/8I7IABJgH5Pn5A5oxNSd95oFGNHotETG6LTj1TuEzRADTV0g9vYFzuVzXIfrdTIdfCmwdOYI8rNHQVWKtd0n9TBttfgu93L+xQpAZD3xO72Lk0StLO3zi0UICqbfg3svrx3GpnzTmZ4akvVBPVHU0SlYahqa3rl8Zlrup3br5HPa63IE42ihO1xr4wnQbLx1gABnrRbkVUZErHhAUnHWbSkVkwRI4rHrpJBdkkJrPonRvB0naPI7/od6GTVrP8fer0QY2GhnhEmlIsoZ2nNo3brHkfbGP5vGkysBzlWQ== X-MS-Exchange-AntiSpam-MessageData: 1t2cT2KBKNyYAlXX0sviqPrwJpyJZPcpZI1ub8LrrgakvqjZXNEnznC2Q1zaSrjsyC6CUZYxfMENvlwLbwhvIM6IoJWUBYHq0gENZVoNCHn38JrxxkjjTR/MO9nifX/qjED6hnQ68GE5sQAQYwmkjEiyIil1NjiIusCdQ6EKwnz7Ol791X/ZZ6Wkno4Mv4AWRDQ+T2mx1NUs4T4a86ViRJStyrWXl8vrQZMbCm+J9zKWUsWXKPkcc8n1AmSn2rn6DvU6f1Kzw+WJjVvjlyNCS8WvBucS/d1Yw1s2c7MG3gy8EVjoJ+j4wlSfZeRYfRM5tI0yfwJvWLlJ/3/0P5lXkymu1zYCV6a8Dosc8YvSw1QnZNte3tlnASZH7x9vXsZMSyuCoWVWkk7FT84GckELvGLU3OoURmt7iIRn2PI6elrnZHYa71HOrz6/TaDRR0IcL91APxyM6KkN0o5TIColucKvibz7ioKvm2C+4ERFTb0= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7820f88e-ba42-4087-3aba-08d7fc3ed581 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:49.9211 (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: Z6o1fQ8n58xhLKFeztQF9YIuu/GOm0dyk8TlwP48/BeRZ5U9iDoAU1aRxbRmaGo6H4rBG7xg2A/WsUHxshlf+w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: GnrRkiX5FHwWzpkRUixQntVEx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925111; bh=WuMDJtLin6myFdNyNuXcvbd4DMN52RAVfWKsMjotHcM=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=PToJzBdsOXeGue43t+sBIDfqtj4bFBgOmQAEJoBuhMX2oEHQu0tGdAM1upJ4eWXHVFF uMzbVhNk7HqQ26Miw4TyH2asRuyWMyzUxQHC/3+8VV4gl5OAu5tniPCDEIqPQFKCVqA6j veCCe9mg/xkdP4GCCuzT1OasxYrBXnk9BEs= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Tom Lendacky Acked-by: Laszlo Ersek --- .../Library/VmgExitLib/X64/VmgExitVcHandler.c | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c b/OvmfPkg/Li= brary/VmgExitLib/X64/VmgExitVcHandler.c index 3d2a9c6f9bc9..d6b35b3019c3 100644 --- a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c @@ -1214,6 +1214,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 + @retval Others 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) { + 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 @@ -1301,6 +1343,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.17.1 -=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 (#59876): https://edk2.groups.io/g/devel/message/59876 Mute This Topic: https://groups.io/mt/74336575/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 Sat Apr 20 05:17:49 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+59877+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+59877+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 1589925113245625.8247322858361; Tue, 19 May 2020 14:51:53 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ycUKYY1788612xSXCnlJ5W0F; Tue, 19 May 2020 14:51:52 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.69]) by mx.groups.io with SMTP id smtpd.web10.923.1589925112403000242 for ; Tue, 19 May 2020 14:51:52 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cFBkzqiCSfveMLAvSemFkr2rA9AlR/tdJPG1T6IZGnvGeAez03gsKYFnSxQG1mF7ESwgENduAzCaPB4ZgqFqrZWInaeJB7VYUDemLRwduQvbVNAXr9zMjRF5WLuaZxBQR1+wKfF3C6XhL+qQvaFSYouel0CpIX+JU+x4HzbLFFppWY/fsLTon2KmqTsuV3Aeg70zmKqaiGP8kfZ3UtKjBBL3PCKe0lQLn/o7PynU55i+di7wH5NJd0Xjj1UxH/7VG2yusmJ99DKVmqkStIvPDjVZkM0/NP/Tt7FP5kBfWCBabAr6Jzuoj0DtCgV+rCyRSc17BdT0mjEzhRgOIZzkVA== 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=taMMfOYuYl8YDRQPYa3HOJxw4YrqSGuNefbBhcXxYNI=; b=NdZaIYztyntgU7ckSvcCRjxckAMihtI9qE1cNUFn6ho917mmX9PihrwgxxbO0rSaSWKamd+9zoe2CZiI7zDR4hBqvLm7b4rAI7DmDCxgTQ3KlFjAO66HKS+Ta2I9EJ7h1Dwx5uznh4EqHyCAgQjHqngltwmKExPVf0oIDEcgtSo4dzZ88N3F/G94GFY10R3P+OAJzHG84r61h0mY1ZxmH0Z9ANSlBV7zhq3uDT0AzYdvAZ1Le+XhuGf5fVIp+SEUtkT62XnZ3aBoKG2hWeFBItyj5kmEEa0mxWf87iuS9Lf25NiW0+BC/DSd8nmiH9gizFx1hzGO74hK9ZrZjGPtsg== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:51 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:50 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Ard Biesheuvel Subject: [edk2-devel] [PATCH v8 21/46] OvmfPkg/VmgExitLib: Add support for INVD NAE events Date: Tue, 19 May 2020 16:50:49 -0500 Message-Id: <2649c46e37aa68b17ba5af83ee4cad225ce0d47b.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51:50 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: a6e02d8c-ecd1-4eab-1f09-08d7fc3ed624 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: 1GbcmO+BPmwWECczkD2vT6mbVCKnAKIIGT+kOh/VPjXIjqmi9C5QBMcDJRuX3P/TdlJlGgesvGY6q/m7whpgFTAUw8nZbwKN530+EEFgBi+KtTws2DMZm7NZKx5jbUDeLIoszVI0ZWlvs1ZHgVpd6XFnzP05nKfxzrOw3RWNnelfDHLk8clUHAYNJ6NEL9+bCXPpEFzXTEDtpZC4GUF6lahqX/K6elU3nWx3jGpP80g5D7F8xgxGeYZzXZSkN8833ieycxcVn74wwlUjaODLaFnAwo8CtebFhkWVDdU1JXNWyVVYaBFaXxlMyH2RIU5BSDkonYkLoLCX19S2XhRHklBNyCOS93o603ThpVFqDW8FF4+jKYd7wBpF9xgaj2z/N8IaqI81CqeuqB16N/KKhOnPzpjjinvA44y9pn1lIKrFOuinzB2YeiKp+CT0KKHQRfGDmj6qEsNqBFmmi2+aCj/dPojT5vY97VYnp4+pauqZ8b6mruE3AIzmPfLL4wl+wj4akuJ3gk+eT+aTBhxGFoGLqU94hQrx/BRKrPQeCSYcB/LATk+KOEGE3dZ6Wy7+N/qbgdYguHFBL66AZQK0Iw== X-MS-Exchange-AntiSpam-MessageData: tm2xO32JsjHDUud8DhBdSj98pUqdMm9zqIXv1eOuRyCjRXhuRFI1HoFvMMcUO8RnGUwS1TFa9YuzRNyyHNgpmbw+cQbONGmapS8t7fAxHFrvILyCSzvisvvK5opuRKrx3lYdEwaMBqGwGK8BxrIEBuO7OyWkqdZsBYlPzu1PnUHXT8f5RTdgzDzdiy8iybJy2drp2Nh2bTzu+X4I0hFRF9DpPOOMAlNI64+unck07mCJdGfsZzZARiPokRocNbBoHnN+jQLDhWINXDkcx38SxIgFvLjF4YR7lWsrXF+t6R17xMTb0yft4fVGVGoDL3idsiqQy/6QngzkjsQBwxicggSDy8oujBIFdyDfe5lkE3K7D1fGwxi+PgFh/1iWivDXCgZsWT9XXQmnnzRpkspiViL8xIeh3RS5JrQxUKUke+YRJJf3KIWjgbfY4RFTJjpDMLhCxqPS6njZr0xbkVpXvLfhiONFql7AyuHtqWPssTQ= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a6e02d8c-ecd1-4eab-1f09-08d7fc3ed624 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:50.8627 (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: SHfv6q8yT/iSo+5K49KiqJ5SUNMaTqYkLxDNgRX+sEDVruBovTGT6DUF6a1z2RhVTahIkb2dukyVSpc9VAVE1g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: YPSKoIOZiwTE7J5HduBMGWLDx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925112; bh=u9buUl1EiX4nelXuW4eAEVTv4TnDhvIwRrvtL0ss8XM=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=Y41x2arAOtqug6GdIFRp8Z+Xtixe2XaxYXAowJGRg0zVSfxZez4gPUKSlckUthXiShp T0rqpYDaKxTgWbli5uCJ85Ebnsr2lwv/hhJcZUpWI+LDbBKGcpkujV7SVyaeNsHBDFx+U yX47rrdmLpHdNVGkVfgDTFxVxIbeLcS6xBQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Tom Lendacky Acked-by: Laszlo Ersek --- .../Library/VmgExitLib/X64/VmgExitVcHandler.c | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c b/OvmfPkg/Li= brary/VmgExitLib/X64/VmgExitVcHandler.c index d6b35b3019c3..0b7f24fd962c 100644 --- a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c @@ -1162,6 +1162,38 @@ 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 + @retval Others 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 + ) +{ + UINT64 Status; + + Status =3D VmgExit (Ghcb, SVM_EXIT_INVD, 0, 0); + if (Status) { + return Status; + } + + return 0; +} + /** Handle a CPUID event. =20 @@ -1351,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.17.1 -=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 (#59877): https://edk2.groups.io/g/devel/message/59877 Mute This Topic: https://groups.io/mt/74336576/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 Sat Apr 20 05:17:49 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+59878+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+59878+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 1589925114118154.21314755939068; Tue, 19 May 2020 14:51:54 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id xT9qYY1788612xf6OUzZuJvB; Tue, 19 May 2020 14:51:53 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.53]) by mx.groups.io with SMTP id smtpd.web11.964.1589925113172337211 for ; Tue, 19 May 2020 14:51:53 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Sh3QfpV7Z7Vyc7h/i6OjLnP+xXLB4LdS5D62O3DlV8Y4rqcJa06S/D/utTpJ2g1IUozJR2mYDURaD/QXJd5vBOfcFsC1cvUY4+UsMni4jxL9l5xwPJ2yzwCWDRn45N/+k3rUixjOnSBhAoU/eV3nYi7g3xzXqUt7WYA4qN+sVuWIljHijYwLujp3xBhElza0cPBOUMDz1EHX48Uxxr84RmEuM2VsxWaefTt5y+MxCRTg3sjWfOqyRKUs02c0wzvi/bKsgQ/gnO0EfdzFT4/DPI57D2ADlg4ooHzgW34D/k6bbqhtXiR7/kYkKff9A/E9Sr4Q1qHMEVx5yAaGqz3mKA== 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=FJfPdhnSMeXMfIkAm/2BbaDdZ0VvBaioJXEf8mhb3Ww=; b=Xz9DKhyyoKg4d8ojrRiB6Xp38CwWIqC3kFF6E7kvje18EpNp5ALxvq1bRrDW/cemf6Kaz5MHn4W+Olpiyp3WQX8YDCBDnYPgp5HGbZyIq7QlINs5xvP/8n6Fe6akx2XEO5AyjGP+agjyxwvPVMQNqSqki7tH7q4DN8YBnTRVaHv1znfSYD6X6t/LRn2f7ZO58gSKleTaC3zU5t0TSB7mjEWqohcu3snr3c5eWgdAfbkHNfqnvpFBoFRDzyY7pyDw0OmZQVCq66lajGKyAiic0zhj0JQRWHnK/ko7RtgMqfH+l2A/JX1k+dw5Hb7MTPS+LTgvB9lLCfoJ1CV6T8VkcA== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:51 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:51 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Ard Biesheuvel Subject: [edk2-devel] [PATCH v8 22/46] OvmfPkg/VmgExitLib: Add support for VMMCALL NAE events Date: Tue, 19 May 2020 16:50:50 -0500 Message-Id: <0b9f13ded4d404ffee90a73848fc67b91010269f.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51: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: ee254765-b09f-4fa9-6c94-08d7fc3ed6a9 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: NshD4MzfIL0+/RmqzheH6+2rhvA7yhcWmNYMxvwocV1VcR8qdDvXJz3mAyZcAlCy1AWLyYOFk9FAgtfgMwSmBVfcjTL3DX94fj0Tu2bpA8jZ5LOovf45Vn/f4nLVllip6hlfXAQ4xuc7vFNY5Pthr86KWXkhyk/2pHd4ie75PQFPhSe+r3hsr8HS2Xt/fps/hoyGAf5sp17bCbi3r22XXyzHWsT5CioCq2+gOB84kRy4zHvRq9llCkEGSoAsJjFHgRaeUWJXgRm23EhPlkQj/Mn0VV+dvU+ZB9J5i9jphbYcvlHvZpaXZH3Hj8VDf8y6y/9kG1Wb4EXeo8qOV5+eHXwyp9+Tqxdq1JNYX9ZL0BF29ZpgrX4eTLXctKdUERF3IPc3wA6rTdTrRATdvz5SGZULTEw+d6WjEFRhfeSjy5tnCZxayTra5G1Ydmrv3y6zXB138wtSA/H2aeGIVxgnEeFPeet8+BlcYNea10aDXqtAtnKuij5LKFQL3dg+0xCYe7vruDY8Azlu0bI4aQOHsMo+TJO+gMASq+bxqk2pUeZiRoRdZ3ASe39AgvLsN8Irq1R8V31nL1vD5s2QikIQGA== X-MS-Exchange-AntiSpam-MessageData: KAfVnGcrym3B2cY+4jUF+ZgDfxl1Un5ggOsDXZ0JJMrnIwZdtuyoB1gc0xyYIE/HLDnpztXKLCpnhDHJgmXAuaUqCIZ3rnoJ12Nawrw3JzFq4xr8CWlOrRQjU6N1A0et+tHR4LqIGu52bqKb5+/F2+XAkmgY2W69pfzRdZmmYjAUkwYfbECLiGUBamRbC0rgBYhprOEfr4G28Ell32BnU5HB1R0lZMAtmouF7s1d64yQ1MFsu4BeMtKAH0QwTMsvQfNgj7bYA1CDbuOPGgoiUlSxvm93mFw0Avstlbq+sPgGgdDK+qhL06RovRXIgXu4/q1vjqJNWHEhy9O9WJkHVgm1+gjxZz2iGF22kqZgfN/KB0UKcU/HpIJvozWxhmX2A8VqdlDe3MooGK4qwzylUPkTDUBNzDHjeFXeHekHkbKvRgAcO40x3heUB4iQTwUXnq3zD+3MwuQn+9W0m58bK8NlSN/f0/vVM4tNlX408sE= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ee254765-b09f-4fa9-6c94-08d7fc3ed6a9 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:51.7553 (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: +H5pthu7UwJwBcMlAM72cNThjzHtHL/RYRhGiAdbaB2K7Te1TzS2tijEiT2lIe8NJUMykDarHTwuoXczqKntlQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: vtVV2xCIHb5zszUG9zU28aQCx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925113; bh=OKuuXySr4u1qI9N4Fk/jewMSQaLRxtU83DFx0sgr6BY=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=GvAYCL0DsW5Oxt9MnfuQM5MjOdtD1B1WRy/celfzfWt0KzDYyYthbgoHgBsNGeJmr9Z ahlmHd8WQ8Kg5/FnzGABnekxtTdcjNFHhMYLMutym3L1PS0zb2X3xr47ID4w4o1hrafNi FU+sCiL6tnrj3sDVLuAqrQFFaX5ahcX/SQM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Tom Lendacky Acked-by: Laszlo Ersek --- .../Library/VmgExitLib/X64/VmgExitVcHandler.c | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c b/OvmfPkg/Li= brary/VmgExitLib/X64/VmgExitVcHandler.c index 0b7f24fd962c..bf1555234d69 100644 --- a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c @@ -875,6 +875,50 @@ WbinvdExit ( return 0; } =20 +/** + Handle a VMMCALL event. + + Use the VMGEXIT instruction to handle either 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 + @retval Others 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) { + 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.17.1 -=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 (#59878): https://edk2.groups.io/g/devel/message/59878 Mute This Topic: https://groups.io/mt/74336577/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 Sat Apr 20 05:17:49 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+59879+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+59879+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 1589925115236165.56586276686915; Tue, 19 May 2020 14:51:55 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id HwxVYY1788612xKA05fm7m46; Tue, 19 May 2020 14:51:54 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.86]) by mx.groups.io with SMTP id smtpd.web12.962.1589925114308049267 for ; Tue, 19 May 2020 14:51:54 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Nw1b+MgAMhxUil4UHzQoknE2AGLVeSpSI+VjmwJmxjycBqb+oV4L/hwKrsr+a6RHVwSFDnAi4gf0tYlzr5ZWxzpFBoQlQkMsiwWb3Mi5fLxGqqF0BBF3jJVuIwwc7wlxc93Bh93z0btsOBjPCK964F8EaRIXN+jgDgSi/Jc6slTkIxizRyn9n7OgLEnN8R+AcJ5xx/xMDUyrmMkg60ekN2pY2Zbb/PsBmxxwJLu54KCzNkgKGkvvzkHMTOm1/jgEDIsa/qerkmSKLBGHa4gj6LtiQfXnbcPfuOsI2AaFNUp/IIS2N6MELsq9+m5NMw4B5dqW8Mpkk650xphvFNF3BA== 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=bsNtPGzXyTDEfHWeyGjki7d+5TkTidcbbzyaO6JXthQ=; b=KgpLJST8LzxVcS9dsPSnLu+2rM+8D0Y19n2RHhG3tBYS2UrNFLil8H+LXI0WrqVTnFPBHxL8CLaLlM0hA+44KDEPoVtq7H6dY0t45q2plxFXEVJDK7pRj4g5igTMl8apn6CfEndKr1JH8ytTN3ECAIXHRaNwDcmhseL/OEoN7pbQj8O9QXv1MX25sezJnqaNWXXbntNLn4pdW3V1/38llcTs6G+1iodlCGSn52oJ5Bsjaz4Mk9FPXEtwYjU65C53USPWXt/Ohwhwrfn/pfxE/rl64AVrz/ES/Mtfv89vxqF928204OFfegYFngAFXVijOLxhDoWvqWaXJA9EUr8V3g== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:52 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:52 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Ard Biesheuvel Subject: [edk2-devel] [PATCH v8 23/46] OvmfPkg/VmgExitLib: Add support for RDTSCP NAE events Date: Tue, 19 May 2020 16:50:51 -0500 Message-Id: <34048298c36c60cf6c72f11cd9c51cba64910ce6.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51:52 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 557f521e-f1d3-4a0a-7436-08d7fc3ed73c X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: LsfJ4w5/3Lyozzz7sy2FcVWpHTtCas/OxcT5JdBDwBWF9DjjPh+1pF2cILQRUtfASH48seI140bpb14umVVHcl7Fei5m1NHJNO8zBooTfUyim2dJJ2X/eskfbT8J37Q4fGrCv6pA0RUkeBq2/Lqsp5GQgQ5nfobjnl0wqmhEKd7CL5nbPGYeUtVp0AX93ae5PY7R/KWShSPeb5JKOPEdxXt3shafctQktIaAyCcrsuZeSZYKqpWsbhGdNjYjx/eEq5Hp8hCRIfwttR5lj7732LI5kkCgNkODLQF9b/CGWIxuX+vPxyhNoKv7L+Z1y4Gewf9xb8Qk0TxhLoZuMz3ckrzlbT7CNXnuMbnDSllDS+r1u0ryhTp7IpT6alBguDCUT2dkNPonkqOv5Yzv9+6ltp/c+1HFpwc9eQQhD+oiCsQZ+1FHU9kxiTEGm3yu9u2G9oxdlQS45SoVII+ykZutLGjMBmnvU0DiZFN9R/Shvs6aKV0vdpS4+aioCOXwhBBbr+qYj3h1GMBaxPLTuYC6AYZG0hObdmLYQPZU8/ouS6eD9IEl4gM+SN0qEH33YoTTnrQP2cCSocTuK+PMZ1sxcQ== X-MS-Exchange-AntiSpam-MessageData: 4b1JxJk03rC6u+n97jHzMlRDj8db2l5aOCyDJ/gBdwdgJqfCI/5433iUNEzzATyUv26PKi+zco18rRDCU8ebohrBYccqxZMgz9IUJCVxAUJIFBzuFj3QJRsV4TX11TcyE5mUy9K09b31WUKgUuyi9OUWSAc0VOsYtPJdg3OmuM8y6c4NWX0J2GRXCyW1Na0EWyDLN7EAQ8gyARogOqnoswDdYf3vDnYcB/iHuubzQL2DXI36mdIfG4rIHjiQ0On8y/eQlM4UQamBCHMrTkEfAXBu9UhScyxZy9qonFdlO7aptV4UMuiWAb2f3Lncd3nFBiJ+VGzBCE2SVt3FIoQmr0mKYOvzCchw5KSDbhUc0gkJyPfFbKs/uhSXPIf3MOjRyNjmg8AYbn/b3ISr9s/o3lKZDx9U2m1aaJCRtxpiLwW8aF9gGztSv54OsgORBiAUnXXBdlAgOtQsOxRjcub/6oDxVd9JTpC1m3xs6GZG2YM= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 557f521e-f1d3-4a0a-7436-08d7fc3ed73c X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:52.7418 (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: 0x7cTKODhtJ+r3VhBuqP3HOXfFfh39iJc+4J8748PFxX/niMiwwUNsm2wRmJpk4wLGxdI6LbsnoRyV3ge+RdEw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: 001tPaMbkpBMIFeEdvHGDEmBx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925114; bh=nWcwNYEsT36oVBaeUeXQPCL8cneueZgh52+Us8etLyE=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=VMTJobIOlCeWraEWnj1Zn28rmU4sU0w9Z/3oR72U9to1pIyKVP57lw64fvS66ivfOu6 YTn/BIEuOPMTKufGLxQQYYYX3A+8exDPV4oSloaqs0/8QZL6oy5PS3b+gI/29Q/wEQ+8V fd8IdZMHNky1vS2bDZtyIN7EtUnPc8QTlwE= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Tom Lendacky Acked-by: Laszlo Ersek --- .../Library/VmgExitLib/X64/VmgExitVcHandler.c | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c b/OvmfPkg/Li= brary/VmgExitLib/X64/VmgExitVcHandler.c index bf1555234d69..716f21a9ee0e 100644 --- a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c @@ -875,6 +875,49 @@ WbinvdExit ( return 0; } =20 +/** + Handle a RDTSCP event. + + Use the VMGEXIT instruction to handle either 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 + @retval Others 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) { + 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.17.1 -=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 (#59879): https://edk2.groups.io/g/devel/message/59879 Mute This Topic: https://groups.io/mt/74336578/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 Sat Apr 20 05:17:49 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+59880+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+59880+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 1589925117715467.40940893165646; Tue, 19 May 2020 14:51:57 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id gPFHYY1788612x4qBdS8F3Lk; Tue, 19 May 2020 14:51:57 -0700 X-Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.87]) by mx.groups.io with SMTP id smtpd.web10.924.1589925116921850878 for ; Tue, 19 May 2020 14:51:57 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oaIGVev5hgPLdn2nAAao1RS4nKU3ckeV+huI9VsphKwgHW3RPOWciMGD5UyYZ+CV4geMAIMOrDOxq/Ad1KSyCjcFnnQ/XycfldB8SxQSnhNB6Ay4xhiclXrk7EBtkjf+aen5EyrvqmyBtUV4ICD8ucMxBP29LpGeDFz8OpFvKiXJTKWejey3sfmrfO2KwAbUjjz5RY5oIqNvOjBcXqDVVwrNEgyW6rfWQC9GhbAefXmGm04A9C1zhE95mWin0c40FNSRhLB7HiLlCf211Smdb8P+IyURLGV1RrftT2aoTO6KpMNDA0N1GLTOQBN9LeCWawVCEDf6aCaWOn+WR2u94w== 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=ItdpWsxoiGnM4ukmjeGzml4BDQQ3BYGPCMEVZVYeMVQ=; b=BkAVyuJqRdTeDuByfmr2Fp2poq6cMMqukmI6afSV1GcFukW3rTJ4GeLosRBY8vfyPiup27V8p/9DdRGX0zhExTn5FJT+jXVvaG+ejEAa1PepNZUnccfeB4eevTLxGcJUihmlCDH4g8UkYZ7xRTfmbDTOuFNvinvmcn5Y1e23MQ2YIlD91j/NaL0ed1DRT99N/krvE+rpq7evnfbu0ufXU6LvRsXjROLW5oqkKDG64EqULG3R+yW7wc8D47rm+51hWmbhqBLSDEGOCCKViQ45syiK2p+sqdI4gDhyls8nEp3vR/E0F3HIFC/lWhUOf8NDMzdA+Q43U2RqKC3l1s7Yjw== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:54 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:53 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Ard Biesheuvel Subject: [edk2-devel] [PATCH v8 24/46] OvmfPkg/VmgExitLib: Add support for MONITOR/MONITORX NAE events Date: Tue, 19 May 2020 16:50:52 -0500 Message-Id: <9d7a3e2445c91d65b508049a96f4461594fe4ba4.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51:53 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: ac5529a3-f07d-471a-0140-08d7fc3ed7ec X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: nFTonOia+ZIpITGX6lfrlvj2EWsSsVApxIJcO2whzL4QI6zt9YW6VWi4JjZ1qFtbjqPU8GyBETFz2J9dZDe6MduE91pQH+jBD+sjaZxueTFAsBbU2Z7M5FNCvvp7wSOJRNgPgDFABxxnHPTWrEmL7eL2SfDa8tHeQU0pdpKhW94TiRpgyiKSAQch0JM1HUgPeU2DmaTHD07RF5Lg/3uToZPuu+yJnqR6I3TfQ5W0dQ8nJZolVxl+QMnhh1P4VaWACJBcor0hjDHlj9wIUY8pkui2NU258WYcRc5Hyk7dYk+1gu0j+UqVUVAvw+lzJXzOYHQXp1cTT8hj+X9c5TBAMwUnSlzBpuNnZLZYNxObmpataCjpx+pcm7zF4rJjdrpkW5WaftD78HuXaPvv8YqBH/Fgcnf4vn2I6RHow4FzYFRYYDfQCxafGKTL4m1b1eQBz/xFtX2jWDI0FJKyrI/wQZumLmd/LTarSCHgBP6ynNLy86RrXJil5j29ySkwxq5t5uFhaXDec1xwvQSfTqk0mNZRId/X+Pn+Z+rh4I1tO0m5DlrGsEWTroVUfKdpaFi/JfAjKfybfjnk05eCz592zw== X-MS-Exchange-AntiSpam-MessageData: uFDm5Ktb1uLOruEb6CQEmsfcmZ+zwKQNteXLCafcV5iMQP4GcjVjpI72tdvYJiea382eMu/Hn50vYA8+o4ukiBONxNBahZ9qSu9dx4sLoSlLRVTnSxMqdE3K7qhxcnx1Ml21TPHRf1P5tYhbL/+sAd29xyfO0/XkUaejmahcKcV1xO4shPlWB+u1M4UKGMDcaqzdIx2Tm/5YEFd8pzsBCq9zacL7RV97gyBm50drs2ppvMH2yNWd75NaZ69UFlf5h1L2fYkU38z90OtxR+OfMho7GwkDu+D7B2CpxiH1V7u7ZYT03f2U4lv+TVF9vMifXgWadhU8MBztPu6hNgwBCp7ffJ+JZJ5KOD/cUpX1EAunf6k9kCH+93uu4Ol+HPelGGqveNe9K3gox4g2bO5jYuNRUgy9iWK/ZHcSyJ6pe8Fx3dx/MBcDTtpGIZBWws52prMQKkmHHxWU0ASExvCZEv4HtSf7J8kX0ZgJf8SnHOQ= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ac5529a3-f07d-471a-0140-08d7fc3ed7ec X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:53.8543 (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: JfN+oZ5hIy++bYeqFxIOA0hBm4Tx/olv53oeeIAqK55z3qPbBzwXPcqTifL7JlC1wPkvPMjYdqy9u0BAFr2+OA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: p6tBtguT8ZMQ9f8jDTedIYIZx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925117; bh=efHvvtMK36rHdxj9cFwSsuB+Jfh5xCifwPikz4tGRJU=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=TS0MHe9+pi/38xB233u9GGkaJEogEnUVP/nViio6KHzQNiYprYXhC8JaH60BoM8rBA6 GLzFapKcI26lYekyP4Iukkid/wRDuxAErsZSxk3fLyyBVnl0mVs9JrFPn2A83y3JL9BNs xzbKemeLqoe8IE5BGfAtFweudd1kHCbZCkQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Tom Lendacky Acked-by: Laszlo Ersek --- .../Library/VmgExitLib/X64/VmgExitVcHandler.c | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c b/OvmfPkg/Li= brary/VmgExitLib/X64/VmgExitVcHandler.c index 716f21a9ee0e..9b7639069276 100644 --- a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c @@ -843,6 +843,47 @@ 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 + @retval Others 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 + ) +{ + UINT64 Status; + + 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); + + Status =3D VmgExit (Ghcb, SVM_EXIT_MONITOR, 0, 0); + if (Status) { + return Status; + } + + return 0; +} + /** Handle a WBINVD event. =20 @@ -1494,6 +1535,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.17.1 -=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 (#59880): https://edk2.groups.io/g/devel/message/59880 Mute This Topic: https://groups.io/mt/74336580/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 Sat Apr 20 05:17:49 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+59881+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+59881+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 1589925118562839.5085299861383; Tue, 19 May 2020 14:51:58 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id wtEBYY1788612xHeYVQIls6m; Tue, 19 May 2020 14:51:58 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.86]) by mx.groups.io with SMTP id smtpd.web12.964.1589925117656726354 for ; Tue, 19 May 2020 14:51:57 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c5O7bEWwHWxY2nYVao8n7HPD0Eac7MelFDl8m4aGZzvfcSAUwir6pwaVBlNNduEPoaYDo0bXiOj1JrR7RCN2qFz8Fbb2TOYF8kF/bSNWUJ31QJDs/Ps11q5GnF7PfMDcF0y5uFM0CdT9I57ltIQ06o3u0rcYTc4MzIiw16vTJY5vSQsHiOzrRF9AXk8iH3542mKpKD2QB8joRA7p87dk93nk8GruNwqpgI28K7WimbP2sNotVxOvW0XATadG+c4hIQW3QrGlRJNhBwhvgiU85RgEEzI6kbsXYo2nLo5hi6/Vxz5eYEgXdq2KuqvPU2ezsVBTmq7VFqGl6lmWvCAqlw== 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=QHD6v5WFOJIeOr34QY6bahHQiQ+TTLhz2DIMF3kxPl4=; b=DI2QzRTbfJAfpgOlF9eyGzflEtcWfy+Gaq+1RxSVs3FCb5JDWRbxCN+nzkpWaJ4YT56vZenxMkSUCP0+R0X/fgRmZifAL8jw6ZGHKS4CXW30cLdMV9Zo9Kpb70SbuYEmbLmX4oTOCIAyPKzpSB9NAj9FWuGR4K9E1LF0o8dBaP7jXhyV4vsZuZyNYDpBE27RIPbJ0Ji48vy6DIKI4qUZl+xmL9M0EHsR9Fu8qK6Egx/gZOEAzV6VVwlHC4fb9YWSzYKsX7lQLp6nW5xR6qmOOGrQ8LwiM5EfIV1ZsV1lzY6q9s22rcsjV8ARn/v74YinAfHXDd25AmOnjF31mle7zA== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:56 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:54 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Ard Biesheuvel Subject: [edk2-devel] [PATCH v8 25/46] OvmfPkg/VmgExitLib: Add support for MWAIT/MWAITX NAE events Date: Tue, 19 May 2020 16:50:53 -0500 Message-Id: In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51:54 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: a459ad39-19fa-4b1e-6436-08d7fc3ed879 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: HKvxjW8IH3yBGhxhshaYIIxbZZgfOJEPdaeIQLd8n8Swz1ZNsWwLBLoP+F4H7akKiPxYpByQKCp2K8dAqzGULPYgEsdw9nP3zGE/p6ATY1MR4NDhPj8rOFJeqb9z61UzN/jGN2PyR7nv74l9fZNBL7DT3iUSSWAeIh3GY7gXPnV5mfHBp+Se8Eb0CnJubAlHisemyCSzswPYU667UQXknjqVXpQorIxj+byZRcf18eG+a4+ydgZxQSslvd5DeIaT8NW5rJJy9Zl3UxuaXlWPljBZ7bX38rnElNb4qmw1+1Y3m+jFPtcUbvkhAinbPMkzNE1+uiWPe1IHHe2ozuUgENWz5Eqmf2aOQs/Era8q6YoQjhVn+IVCW+QNND8a1PMKALZjopCglkmVnMtbFNLdPHg0gK/B1HMD7YgIdQzEs4AOI0nc6pwmlToiR9djUxbM3LNbs3cpCgoBRam3tqeofLqv5A0Yqy5EHvb5DmifNKKtRHyWKHxU2C24cFKP3uITnMUxU04OFRQjJTMteP0bBikUOjRK61KLTzwsr9ZWAXC8/j8Q4vKtDoGZwVo4/u1VnGe1SuIQq6VuijlxsmcbOw== X-MS-Exchange-AntiSpam-MessageData: dFNgkV77bT7sb5mtUQbH+lH5ta4qKItJYAQ5b+PbeTV+INSGeqPogQ6jsogFEVRVqVsw42J750CUKCkQBSDFzRjkc5s0IwpSX8Z8qdmVVPxGeLI3x/Y4oBVxVMtX7bu5la+sYHUa1QcYqDW6xbWGU+OGiuZaTDXQ+JYL3XG2zbyvGu2g1bEWZFpiNVxilzm1OyeA3DDZ8ORiewTfV4rgP3hOwcI14Aw1eN8aF3DkQTVMmpt8mLBO5G5o2cVNlTWGVR1ic5aY4MVgFvLfaWD8/JM8Pkfgnn37ZzXdRq20c3soehuxYcCfpzeFz7li2PEmMsswVuRnpiqsBYFui+q9gQQ+ubX40+lqN5VkNIuskklqY7CG8ur2hm3fe7BzXy/kUlDpUnRdKQqgQ4f8IPy8G/DJJCwKcdQAHjMirHwuMfKlDMEnT+bEQU7yhJBkHUTrE/rf87RS9UttK2QfMi5Ef3aOqzt5nPQVPURNN++rmWs= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a459ad39-19fa-4b1e-6436-08d7fc3ed879 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:54.8189 (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: nJhtNIQRGC2SRj+Kd6A2PG6HbMcSbSXPO6q6Z1ZfJNxWqOXAcODqS9BO5mEdbwYlyPm/5K8zW4M5fwjHXc+VaQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: HW1swINRV9tX3S6q79DaFhuxx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925118; bh=SfEVsR5Bh0DRF9WiqJkHcZ0VJtTSnJFC2JdEuc6nAJs=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=pzMzPiPnB/XnGCMhDsg7Us/Hpf0dS1111PV56w5OfHe24xA/phGMgH+wTSwz5wqsR61 eqg4ogEdvS9E6XU/cu7YdjUcS8KKB5KL5QZJTtxSdkOcnbsWldL9VRWcgDWX40zM7b4lq VYjwWxv5jWG/My5bHrp9GS0XR7oaPCTBuJk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Tom Lendacky Acked-by: Laszlo Ersek --- .../Library/VmgExitLib/X64/VmgExitVcHandler.c | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c b/OvmfPkg/Li= brary/VmgExitLib/X64/VmgExitVcHandler.c index 9b7639069276..b028b20f255a 100644 --- a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c @@ -843,6 +843,45 @@ 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 + @retval Others 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 + ) +{ + UINT64 Status; + + DecodeModRm (Regs, InstructionData); + + Ghcb->SaveArea.Rax =3D Regs->Rax; + GhcbSetRegValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Rcx =3D Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + + Status =3D VmgExit (Ghcb, SVM_EXIT_MWAIT, 0, 0); + if (Status) { + return Status; + } + + return 0; +} + /** Handle a MONITOR event. =20 @@ -1539,6 +1578,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.17.1 -=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 (#59881): https://edk2.groups.io/g/devel/message/59881 Mute This Topic: https://groups.io/mt/74336581/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 Sat Apr 20 05:17:49 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+59882+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+59882+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 1589925119024858.7805898909758; Tue, 19 May 2020 14:51:59 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id UXZ3YY1788612xGnjADlCM3u; Tue, 19 May 2020 14:51:58 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web12.964.1589925117656726354 for ; Tue, 19 May 2020 14:51:58 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RZftmVKizZmYL6J3CTwTnBT2gNZxp6wL4MWG6lnBGGsIGZ1aZB/NLGqzkIYyqFRxTsVLvYsTphgcGFNpcp9n4nMKNTq8wYBMgLudwrBJQAlHx1NhpDRqH32WhlkyxcpxNDDegH+u6e9AXXYsfKkL9a3lWY/8oZb7e6Vr4Sz990ACW6dpJ0nVanpu1x8ARxGUelDIUOIU03xddM+yuNFDl2r+J0xNgIilBA4jQxae3PASrw1wqmpQqwqirFQ+HjW4OaWCr+4DLI0O4DF0YT4BO786r3xE1AQcLZlP2wI80CaFMc9Pm7En2pWwIRkR0eTW0dckUiYFUz0ejNP+J4XlcA== 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=jb8XDnYDlrqRcpE+3wTfiDcmln9WoOzil+B7HS59ynA=; b=e6frKAXZsGnIlRWXlQZVTzgg31DMu31lROvGnnxD+VXdz1uwn2j1vFDbtODXOgbpVMqIOfpoJvCSMV2KNyjvI7JHlEi9iu8svHaYXvFBuXViKV3KWeYPD7QOvdzhERPGVPrFUCPrYTnDB6sPYHAjWPOZcS+RdKEid+hQkY+lDwPAkn5ZhK70acr50hRHA6A2EBmAUARKbAuH4mZzIKXQC/RkASeHZkVExHmRIS6n4O9XNSfHqCnvsxiY/+pyzENwQCuFuvhwUWGZm72C8+ZTkgyZGoTQ6UQ7EjHnK6YWMdks8LlUtERz8Q4Fo9+k2UxJC5b690ECS+FMb1bJ6S9NyA== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:56 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:56 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Ard Biesheuvel Subject: [edk2-devel] [PATCH v8 26/46] OvmfPkg/VmgExitLib: Add support for DR7 Read/Write NAE events Date: Tue, 19 May 2020 16:50:54 -0500 Message-Id: <7015dcd00bb075c9875b3e4f5507a3281817cef4.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51: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: 859f1792-1a73-4976-2692-08d7fc3ed908 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: ErrZES/pXC1VEqSjUe2otiTuKmaEnAKwzlWZdxOCFJief6R6Z5OJBRRoA1TTA+IDaqcOVUf7ninPcr2Vw3FYKYvL+ORWPOWpka4KZ8cb7p6V6chGNBCucgdKGdvWbUKKWxvZE6Ltk4HywPSUsOIKFLyPM6W6+5y0UoUnSgPODEYLZa+ghvc6I8JiLAWsI0iXIuGC5oE5B4GSe6JACRvDkMQ3lrNtIn9wgnA1mWFRFnRgl2vYDkIU+TvlDaL5Jh6mKWs3IhZgflFYAM0O/L76urAqI2kfikGze4xtWk+9x53ziPV3iPlBmqElFMHb7A7F5gMT3HJJQ3xeSs2eBSUDZqixvLTOODp57LS14WQPe8i7FyMEY7ZaZnCGQ1bn9grZu2Y7kalViqgoIWlAP46w7oVGiFzg7suwHnfV9XBDeWpKYfzIJhQ7hf08HIyKQ39nhf29uZFlfA9iwroFkKmDbcau6MYGa3nX8rZsS8LqB0LICd3smytrHyVpMR63bpJeYbEiVh9C6cXIcqKz6ceOHPVkpFSzr7QYqnZ2NTa9DHB6ZqVdADukzo5+z+FxGbJbu8PcflfYzp3C7+tbTSkaYQ== X-MS-Exchange-AntiSpam-MessageData: 6sKoHn4h2iJtnhSoS0snoSpd2KvLmvYy+XZcxi92HF+AZKfK3igXc3Uhacwq7yZU9ouc9tTKXfrdmVjd+9+lTXNoNB7CrPkK3WSkdtirjK5xUBEJUyjqxQtRM/PWQnLYEcXjaVFLIus2D7+r01aGR5z35JhgzlwxA/hW+EE/WJOuQb7YxVHpFbvZNLXEHB3IXshRQDWk9quKoMCp3GZOwBHQ32r4BZGowK+I9VRvu53K6BNNRHu6NRadT06eJMZ5FLEKvvRgi3OZ4Vid5/oVDg66lceRJqIEWL6p4ApqDMMMNIyiwBPEbU66D78gd2dIuXg9gu8bdXUjAL9+W0Lg6soIzLWFEy2eL9EQoYiZQ/Ni9SjvVckT5TD+7C5NzBye7tTWgEnZsmRHyLDU9DdFXyBnY3Ar8eCXFqQ+UgqDGgIl0ZDvTddQ7fst8bDvP9YxF7Fky7yx0wYJ3y/1mwWHARH47rtd89EgTXTmVvnFZYU= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 859f1792-1a73-4976-2692-08d7fc3ed908 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:55.7195 (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: SBRWNtnK332Kf1cUQcDXmBHW2Lec9RPQ7/oD+XNMI1sVEl7e8jYRrTkBptRK5l/5nrstJcES8uq0x/AcxcWUUA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: S0rFUS5rnoZtBR6V1h1gOiMrx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925118; bh=h885zjQkxULQ7ayc5J/MurBzHrAqJrlcgHDArtX2ehI=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=rp+fZ3fthHDuDxhRw50RmdnI5ikW0iaMHoBqDZBNGCbPCHnwJc7GT/lsCwM2WaymuIZ ef63P2a9cYy21AO1eVz0sVVuGdZ+VFP2Sm+z7S2G7CNCZzgN+Yb/iJtAEIhHN4nI+k4Mv 09u8dJf5MZaDrVF00odE7zQEUl3f47ykO+4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. 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 saved context. Cc: Eric Dong Cc: Ray Ni Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Signed-off-by: Tom Lendacky --- .../Library/VmgExitLib/X64/VmgExitVcHandler.c | 105 ++++++++++++++++++ .../X64/ExceptionHandlerAsm.nasm | 17 +++ .../X64/Xcode5ExceptionHandlerAsm.nasm | 17 +++ 3 files changed, 139 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c b/OvmfPkg/Li= brary/VmgExitLib/X64/VmgExitVcHandler.c index b028b20f255a..e4072d79d704 100644 --- a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c @@ -14,6 +14,16 @@ =20 #define CR4_OSXSAVE (1 << 18) =20 +#define DR7_RESET_VALUE 0x400 + +// +// Per-CPU data mapping structure +// +typedef struct { + BOOLEAN Dr7Cached; + UINT64 Dr7; +} SEV_ES_PER_CPU_DATA; + // // Instruction execution mode definition // @@ -1494,6 +1504,93 @@ 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 + @retval Others 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; + INTN *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) { + 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; + INTN *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); + *Register =3D (SevEsData->Dr7Cached) ? SevEsData->Dr7 : DR7_RESET_VALUE; + + return 0; +} + /** Handle a #VC exception. =20 @@ -1538,6 +1635,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; 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.17.1 -=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 (#59882): https://edk2.groups.io/g/devel/message/59882 Mute This Topic: https://groups.io/mt/74336582/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 Sat Apr 20 05:17:49 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+59883+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+59883+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 15899251194611011.8610856981637; Tue, 19 May 2020 14:51:59 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id tcVqYY1788612xGDwvgTB9se; Tue, 19 May 2020 14:51:59 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web12.964.1589925117656726354 for ; Tue, 19 May 2020 14:51:58 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ab4kb/iwJB/eujVAIPKcs1trXdEsgSFQocHiNFcp8bGdSWSjw6Y+OZr22UixGIbMmQ/MawrJeyEHF7w0NADYFo0JVDsMk9clBU7xy4nG1HZa52FraQdxS6tvh0FTw1a3NWbV8d/FWlWS2bTvep+hdHwpb7vL5NS71xVkgyOUaeW3J7YO9+rVzKNmGBTmYsBprySZbuyfvCmOhdzVYoIAT3pPRpS6t1TYJtvLP/IXBa30Ry1+ItKb0bN907SEvI8X7M62M9m4sfmchElkYHe+D2TO0+aDetXUyAofz887WzcviiTPqcsrR5DWVZxYgHZeDCO3lgMpgccvKlPLPAF48A== 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=3WkepNWWK6vq4wZfGGkzEK+MfX/RzAQc/39Mizzg0ds=; b=mC+D3Hphf5e5DSBMMVwy+OoJ5oHgYgH2aXBG2zfHUpbOgWO7z2UnVvVoSdQZBUd4STdRuiVf0pWpaV+/BOMNit0xPfB+5HpWu+jgpZhAPh111Bwbvp+JXurSuWqqyKk+nEcRNciV1lN/pXvu4f//Inc+2QMgsTpp5uPg2DmGs1RL+0pziWykpkRu10bIOa5SiOlwKma8pROjDlVu7hYndcY2E51w28V+jBON0Euwh2jYo6S+XElhYjUWLXjuebjv3uI7DnDxEaWeiB2UaTsOqQLkpPDP7EDlwDZvJ/jCZXmVSIHJV0QZuyCGWDOYaKaVGuAFEhTF0RS2CecRnitbzA== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:57 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:57 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh Subject: [edk2-devel] [PATCH v8 27/46] OvmfPkg/MemEncryptSevLib: Add an SEV-ES guest indicator function Date: Tue, 19 May 2020 16:50:55 -0500 Message-Id: In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51: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: deef2ff1-1972-46c4-9b81-08d7fc3ed984 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: r9+CPQkEIo4oiDWzJA6HnO4TayL1dUMzztX2BvFe4dVHMfu2kMjbcUrXYrJexl04zMqugQbe93Y/Rzv2O69KxVFxzboUBJxSATlUS70qBtlzwMCJFWKYm5IvD7jHFPqCRaIPEg91JX5cRftzm74Pc15epeHWRCMpTzuo5Ng1MV4+T+ycN7l9B3OqT6oL+1sV58s9W+AAO+dpyWKX8gHLCVvOXMIDwwkPP547Mhx2WiGf1e4PpXgNzuJYBI6o0Dpb7V3H3oyYzcH8Q9X5aq36VUe5K7HNoCzHMcKjGYdt3d4+4jC03tQZs4OqBjLy1Y/+pvEavCzz0EcXhzcHLskQQjRH8K7fNjhc5AjohR8GnAqhUTZbkRtWxbfX42Nub0vvTD1NVgEtI/VO0alJM/fOFJPjrTrWKuZ9p1rGET/IS5/VJKXwRht/ori5fCySCfiNJXQ47RME7RGY93cm3EJ4oj4MB3N2pNcAmeXa7OzHDvO407RuS56Ifa5SW4CAgCl0+Q0ps8RFk8yDgGt8fh4BifPiJ5MJ+Oni3F+FENvCiTPIJGZMGJit7S1A4HagD85ifpfHb4jmdJXEOGRiN2nLyw== X-MS-Exchange-AntiSpam-MessageData: f9J7aDKS9slcsf/12H87IhrH0yC3VmliIqi6sW1UNwmBY6E+zBUj3fZG/WAdhm+x5mcIBfkTn+qO7mRZUmU8JzegCPvunDDRiJekldRSm+vfb00JPe2AaYUZwIO1mrsuoEMq3JdcBJVZb2/TwkvIrCVz/hImfLTcC/5TWPhp26/3au9ep7XScRcCEJuW434+KSMiEJ1tukxbnr25h9rG9stgyJj+/VXvb2GDZA4tUQsqhcnpuLDpZ+gHSDv75QL41y2fACzGor8LsC0P64Fuykf+QuE9t/pCyIB0SIaScM9W4MN+546DdlUoVaCTHT2T1rVgb+wE6uFRM6Zjc+/CyMyp/lAuClxJ1LdpCdcT6VCdRysp7HP72V6ZjfOIIDDQCi0hWxC6OKkdWFqgXjn9KDOZjsPU7PyY8FcrDuuQ4gwVhBnlkTc1A62PbpGH96GUHfGpqib/u3ngXwuRUdxNKHUxl80HHNO7qbS7S7GndMc= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: deef2ff1-1972-46c4-9b81-08d7fc3ed984 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:56.5442 (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: zFrYi3x09BzIOglhNV8h/Rzi/PxwjwCsqdIM5hB9InuSZ3mOW9yDPSDbgxyqND0dtvGlQduN1MCGjsHskiyCNg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: aBv5hgSyv6Eoes1sNqM2AUWcx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925119; bh=lrih8ovTz/l00v8+4q0i7km8I8k21TY2RRgsTPuXK3E=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=gTAvz0IAQzhk2XSoIyQSwy0H+MWjtHX9QTdGw7VP8GWO2k0dSOyhgK4fEcsw/KJDTG4 CVF0E2/Lz04RAvjVNGko8mA1/BI7xw6jUdODgIK4EttsSe/WiBnfAHyfTPsWJQjyDCZSh Q9L3shxA+BPSyGHqlbSC1l0TAA8Kotf8vWs= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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.17.1 -=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 (#59883): https://edk2.groups.io/g/devel/message/59883 Mute This Topic: https://groups.io/mt/74336583/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 Sat Apr 20 05:17:49 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+59884+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+59884+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 1589925119892617.7953327077673; Tue, 19 May 2020 14:51:59 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id hXFFYY1788612xZuEg3gHjm2; Tue, 19 May 2020 14:51:59 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web12.964.1589925117656726354 for ; Tue, 19 May 2020 14:51:58 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iOohnXNO7Y8dwfWy9UiYrYGGaJefQFvaNvl7FvhKwXOl4kuUsgpTSBV4c0lR8JIesxltNG/TEsrqs2EyvHQgBw5zM9mSyjJ8mxoNAvTZJD6Q8eTo7lEjGZOu7H/M6vjGF8LLFb3zonFLh1i7YYXNXJBjChaT0gWr0tgiMJtKfK0hRngchFGBV7qnl2Nn/lJ+qFENrr+J+cXcBIpg+4lmmgDk40oS7z0wT7aIv6nDD4K59GJBJZt6THHpLEFNYGwml/9s17yv7WshDoyjGZpL1UOn0Eey8diM9L1XWrru4ZjLQnLAycgj6oYBOQA/k1dqo+ReSfgaAVf8cINnBhOWgQ== 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=rII2G9ok5sqgs6xoyidfXKZD9xj4WEtq+2F2wiUv75w=; b=nEnGVgQmGpVguxIIrmumLC9/vmC4FGj34eubr6lNl+uycQ1v8H36bG0boJMTo0kTFNdZyDqxRPomNWu/UetgRZMJ/2RNOJ39MeyB5X6E0CjubIU/Da60gUn53DNGsnTFoTciHI8vKLPO9KcyHsnqjn0jpn9nQ0NSQQrqbfxnHQ1T1SyqWL2ddq4CqF4e4Yw1Ltp1zIuCosT4r2B8pE0e00CkeJh40YXTlq+6GidazlKq1GmAmSGG+/VgUgCJgE2uOqEQ78SlC7JAlsPAc5fa2J0YwRtOxE7n1/RGNomEZ9GUey6HjlwwYQ1YkiOeIhsO/lxg18i5iB7uvQJDfq/jPw== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:57 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:57 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh Subject: [edk2-devel] [PATCH v8 28/46] OvmfPkg: Add support to perform SEV-ES initialization Date: Tue, 19 May 2020 16:50:56 -0500 Message-Id: In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51:56 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 13d09e77-dad9-4d51-6297-08d7fc3eda08 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: 4IIGMGXXzpriVg28J1gmUR1c0YI7j4OLIgBZ8Z9tnE1QXu/kF2mzHXWwnxYZ08HNvZZ5vVMq46EPu3qM4ZdIHFWMiCSHEJVvCmjGawNjhb0rmLhdfKcZk5GEfEAjzMtqLp7T4FW5eyy/IOQmKBfSD6tZUxB97KEXU1X9f4WVHkHXQLUoNpsHRadDJY6oyGgVWO/rolRQQWMgmJ1W8h4CEmlBUPKg+8dS20AUdyzHtc54nsBYAMRyXUihVO9ts8tdkdFmS34qRAAgQfYZSNGrMrctaX3B7UQT5PQTTk5z/k0yrBwsz0e5WP2HTdvX1HkD5x3pN9e9n2WO762v2qPwkWT1DUC8qA2aDwJvwt2UZRlTtax1OM+7nkljHqanJlTdzzijLiOQ5dIxPn4AU7+ogwCbUV9HNIhFM+6RN+A0pi1ZehUiN2imsxkLIiX6BY0ss9Yips8jKz9KBXMcXWPDTfH41Gg6JmFm45l9yrAGvQdxefhZ+5cFdFElmSWWSSNm3wQ3VOGR0MdmKqOmSw3NTFIA1nYJd1l4tT3vl7iUuW/0Hb8BcJ7x0QOmaoDjYIe145uOYm9XLGDyZ+6+LJzmOg== X-MS-Exchange-AntiSpam-MessageData: 0N7x857ugnHc5m5c6xdVzY8g/Mhjb9LxT10JfLCRDcjWSr3/U7njkRiigFn3SalgVDApAZyHfusbdA6BsptPV2cyBb+kQg5gHPnsNOdTfh4lIqP7HGpG1GZqjIMpw35S05Pr2Y34VHGCNBnxY+cgbMe9RQQ7lHP9SgQYcjFVIR27GiQZWMiD2j2L4m8PA9fd7LAiIxV5d+Z56yjDJa9jO0KA4EX1vv/V1amK+o6Wj1hA3Xy9sx08Rfp5wcMVMrtoA7Tmzusnr2hKrZDE8mnMw4oCZIa8iM7xtMvKRFCAqHB8rXT5MM9wSgNp541pnr/PiN2VD5BZ0QaZJi+8EKJlQqt236/Z8RKN1oBaZggmJWQ2Cyv2eNB5qO14V+2Zg5PQ8JFN393RZBbtbwWtb9G7rKJPgk/U4/ScGoVBb4HtqkeaeqfoR0WgH7KDFr9JMuLZ2mWeOj/tQ5pp0aR1E6bGVat8eYumObWw9vXfG/YEZZA= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 13d09e77-dad9-4d51-6297-08d7fc3eda08 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:57.3938 (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: wOgK3ECUXeE7iY8jpZDKATupwBHnVXSPiRc6jwFXYISh0aVkvAnSjfpsctdDqXd+JbFxNgJqoHEGOSePCrN9XQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: ZgmkQdJjaddxqdvzvLfcA4gXx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925119; bh=ZRb7FtLEwxt7SM14SCPK9h9vYTUQ/fNoEvID4LzWDEk=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=PdGjTrY1ScxFgHaEf7D4KXrAzw8haO8MtJ11BTjXfTbY7rn9e8Ub+18kEee//YYs5OG +5oDIDxZoL679WAzbP7/JPPCT7FeOtZqOygEP0r2Er/j3zmEgivzMpChwyLxoEhmez8eE 4yFTIEpT/XjKLOhx9CGcv16oLX5BwaG341Y= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 7d7297aa1cd8..b289260c1f2d 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -610,6 +610,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 c85e988372ec..00faf5036670 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -622,6 +622,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 b5f3859420d0..58671828c5fe 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -620,6 +620,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.17.1 -=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 (#59884): https://edk2.groups.io/g/devel/message/59884 Mute This Topic: https://groups.io/mt/74336584/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 Sat Apr 20 05:17:49 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+59885+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+59885+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 1589925121232693.2307552284038; Tue, 19 May 2020 14:52:01 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id jxtmYY1788612xfy8FuRyWGM; Tue, 19 May 2020 14:52:00 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.60]) by mx.groups.io with SMTP id smtpd.web11.965.1589925119868289267 for ; Tue, 19 May 2020 14:52:00 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DDUbDi2cEnr6aM1qkgJVGRs6KJy9fo0C+9X9VJLe6LpV2Cxhdqw1O6hzXrwrpzTpoAXiQnlbB4ZIsKp4l5lwcWtigGKtZzoXlQGAq2bB0mIECVWmXnHDTxQgwOhatnhEIPFe0dZHpGjUMeJShIJBohIlk6aB+GDdrhb7SbeHYJJbX1pmsCIpZU39T6rEA6LL76/RiRO9SEAuJ2jRdAypiIWsSsTEncVdgrTAitbycN3Ev89iYAWyS/WVrN/td6P4ZAvgWIZv6WBr/xRS572bDCjaQAu8roy74h7phTq3DjqM/BGw6kya93KLI+4wgYcYMsDWXT79skmhbnUGXPsyRQ== 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=F61qTh+JsRgVnG0SKZqbw3/NTWEiwWNzHzVSb1SlgAQ=; b=h2G+noUJlY+VVII11R8lNppqZfRHhAiUzGBvJRkRtc7jf/atRc4Re9mfPT7D01jzLx+lJvwa/8HY50d+NGF+rprk1ikSmZbDGB8rJ0QlZeBHkW6S+eQZV9W7a0gFYw94rSZaMa28SUKzR6n228qAHDe8CyJ1+HkNyIq7zviyUL4t6taXHVrM3CDIyoH22+fpGmCWUU3eLIRvAy4aJemkBHuf8zpXONN7DqWkk5M7GXQt4F8kw9JrbbrEtJYSqQ61jzxFTR+rBMJ0jOwl0tty9z+MneQhAjeeCQ5D1m40bl3TzTsoAB81PXyZrK+JKurXcdlqlkGpDVJ+Ewqbc94L0g== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:58 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:58 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh Subject: [edk2-devel] [PATCH v8 29/46] OvmfPkg: Create a GHCB page for use during Sec phase Date: Tue, 19 May 2020 16:50:57 -0500 Message-Id: <85002209886afa16aa3599e4b1cb844c06f236f5.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51:57 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: eeaa01c0-deda-437e-e46a-08d7fc3eda87 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: lVqysqjo4aMA3bNx2yWrb2VfzgTKuA+RTSpikCogQkvAsk1Gdg+8Ge3IEz8HE7KkeKvcxbgar8xFnnZxMnglj76fAkapzxe/3ifkJwO6FIMABhuSPLi2A14kllpGIYw2bYjWwDyolga376+Y4YumikXEL8Hf3Ma5vG9UmtHSWem+ojTlefdzalRPyUHKqaFJ4uakPrrFl8482zeR52dP+h2oaVCwxgSiGc9DUUrSRt1AU9e+5Enq6eHshSvU13ksIJ88K1vqiMCY8KWyJrTeF6usKKDlnEkEoqsgDKTqUjPcUeQAe1dLY+eZbB08QdTTR7N30U3iurNucKqOuvXlj60VD+QFHZ+fZno6XM/zvaTA6ZTXW1YRxHEReveaZtrO2zW6ni8eCQ0V+ArVG/xNPpK7MZk84Ta1Y69Rs7Ol5smcWWsBqu/GkXwIXuRej8q8dCcfX6Kg/r8yE5EiHXQNakabi6y4vgfZGnRcvxaixj9oQI/Mx4l4dADviwk/vvrMCBLRfv8X4fCuFY+z7ttObf98kmAD/NlmH7XcgPZ6d0PHJfvxzGfX4uBsIG6KMs+/wV/f8wWDwNSQQ3qcYixc8w== X-MS-Exchange-AntiSpam-MessageData: dSA8syH3kkNwj4p7Gs9XW9zEpSP4NxX2l9qonQkSd5okGYlBgFDSPJe8UTYkUdZ1t/KLPxCHHGyYHMDDRBQdjE9jDQ9l4S79pQbYPFG9BP396U3iXdFrz2PXSNZtKdmK1JvaHhCMlbytMghWknZ8N0TZxg6TVisGkmpPbcq7pOKCHaFCXNzPKS+rCYyhpRnFb4VBx0SUFwLzwAps/6vcKm7l6dpPbjXC40g7Yn5C3FxD3rEVtCUlcBMdQs+mncINa3ItCMlnzb605OnSsmKg5PaBQmPBAKw51H2r37bcKVw1ENAh97jak6oQGBdsTeBtkctH0l7Qazt014+nPP+4DfoJiR+5PbAeEUXTbiT+6m5H2cHNbWI5Pqu1/vboNMfk2C/tHMYC+Hf5ef7bpE2j8drtJOiKlThVqFcmgFI6f8pkdu2D1EkqZ5aztmrB0wsgJT43R2C65an/oM54opOWCACLj8mq9AHt3g3Q9tO4S2Q= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: eeaa01c0-deda-437e-e46a-08d7fc3eda87 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:58.4083 (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: GNfblwaaA3XJCBECoYs700gOcKq+NvQuHomYbQa9d81uXyMPtBXuXDMBEyvuXlr7+6OUv6vkXNLIUcv/m/60fQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: 3PFZvn5EQyscaaottrEYAxJux1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925120; bh=C/kLOMQU3RO7EiVVmg4QohXMJKlHOWBTgXA7BBshoPk=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=wzidiG1DpDdJPFjRLh3NUV9m6CQ9vXwXkRhmSX3tpqae/5Pa48ZPN+TbpD/k3ZPS8PW MzJXTPe2pvvupBp9aMqftBrBp7v01D5ljgeSyFNo1ArVRAwFVbMiLRGwT9eZkbLVg2mjf 4xgFiCxj4CodLLQYJh8stynvxAalYZi67Fk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Two new fixed PCDs are needed to support the SEC GHCB page: - PcdOvmfSecGhcbBase UINT64 value that is the base address of the GHCB used during the SEC phase. - PcdOvmfSecGhcbSize UINT64 value that is the size, in bytes, of the GHCB area used during the SEC phase. 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 | 70 +++++++++++++++++++++++ OvmfPkg/ResetVector/ResetVector.nasmb | 17 ++++++ 5 files changed, 107 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..c3587a1b7814 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,40 @@ 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 + +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.17.1 -=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 (#59885): https://edk2.groups.io/g/devel/message/59885 Mute This Topic: https://groups.io/mt/74336585/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 Sat Apr 20 05:17:49 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+59886+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+59886+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 1589925152045888.0166799456629; Tue, 19 May 2020 14:52:32 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id PTPyYY1788612xHeWpxMN11j; Tue, 19 May 2020 14:52:31 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.49]) by mx.groups.io with SMTP id smtpd.web12.973.1589925151073622217 for ; Tue, 19 May 2020 14:52:31 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Rn/1q7tqcZeG9CMj5M0k5asMDSRWbFqLXdyv2Bt7wQKfc0r3sDtHugODewwI7teW2IoqLXoe7U14He3dsMJv9wXtQD4Sj+/p6IcdIOH73dQjd5HdM0JULjjBjuWux5wHlyijBC4kJq3MuBWp6NhiGL7h0tIYsGzm2Z3aoYfvnp5PJ78nK1fek0e1vdqEDFoC4qYOLa/GgcPEe4b4tLJrsnQOOfJgpHqXAPEz4c5GCGNIeP7kONCQjNTuUaMnHHE16P9rm2FAVmrnHVUoVhlofwqjrtagPsJcULlsPC0cljZKa/Hol06G1uanp1RyoXZoKeTizlaCkREF6+sd7UEPPQ== 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=2fA5Z2zwtPJE5v1KbAW/ggaY837HukmpvR4LTBNo2qo=; b=NpBZYXBsnH0S6e1F6TrGDMyoF4VugBVKbjpjj1jMfoMq6FzCWZvTZijtj5IyCm70+UeRZyoMvD8Q+qgWcr23IsVVw/5BGgSLxtUnwHjnTFa/QU/j06SRb9n40knf/RM1Oyp3nZjXBW21JFiHIFvhGAr/M0TQgPnpBZ81edBUlQi2ZazroUQ/qMdpVLTqEgJVCIJ1Ko/ftJzAvJCzDWQrD4vWh/wTzE15nTj/OQ2fUkttUmHZOQAE07cSaC50r13r6rR7ZiIaptGg4+wLmPhx36gGPb1MWtgOWUoNO7vlNixbegaUpd06M+np+W6On4z4IPt6XHPQ5V4EQuskAfDhPw== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:52:29 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:52:29 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Anthony Perard , Julien Grall Subject: [edk2-devel] [PATCH v8 30/46] OvmfPkg/PlatformPei: Reserve GHCB-related areas if S3 is supported Date: Tue, 19 May 2020 16:50:58 -0500 Message-Id: <11d4c9282287ba54b6ad19efc8744a491cdc2edb.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51:58 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: c2d7402f-87be-48b4-cf91-08d7fc3edb5c X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: R+fquzKe4CD4nTxz3+HHhgMzyNsSJxP+WQBXC0bfAibt0e7BQOfs1/nl9NSqVw02TcX3BEPdtwcNPi5ekCVUCk1Q+Nn5/k8OUi31M19+nxDS9Ud82RI38erwYBC+fLHJpfKHamyvyzfxXc1jZUPbKfkxHM7lqBhsMyFWIvUUooKtDec3EF2iJmoZnZFkl00hGQLebUj6x7G/TczckfPL7kIwlNYe1G2ySOsbvuxdKEm6eBdoUhRhM/lzOq5bbCyB6K/Op/4gBIZ6q86QALisved8gP6fueS8Ls2Z7HpByTT6g1RmKN7h83GV2TxlLSiGUUG6YLlJaWZAJq/MBejC/Yam2Re/xu3EcT6wvsZusoF6J0D2XMpKY7K8a0cgB3dvm8f3AiDBhjA79tj/uD2TbnRupZLHVdYXrz5WESka1JNPTGa8N7/PbVFfi8Y7cRj+byNITv9Aa5eAQRhcRg9l1xaFk9IDZgQgp2TUrZEKOcTlv1avLfn8UrnmiEYcPO+QNlOfJC0aX+3J/8yVl5tv4SZ2gu2uBOBq6Xfl1jKQV2je3J8HPXqaZBn95+PL0hVhc81uvONu4S15TNX6b/XYQQ== X-MS-Exchange-AntiSpam-MessageData: aoUqyDNsPvw5OvMZsD0lO7NYXhXNIbtwUbdYcjhS4Y0aslztBB5EsHh4bURVDhTl4h/EGFrvWSDDb9vu52wx7xyVKJY3CLaRno1VVgBhSDsOk9emSSlu1VyKpVn+qJXiDavIlVNjd5JMyGkrSKufsNy32l85DKs1sz/gBxxCUU6U0y7Ciuxt4pubYj5LZ+gjxMyyg3Us0BEP9qEu9O/nBxli+I+BZ3Pi07PLmDY3Buq8vLX2O4XETNnn6FLGiMqBGiFFposfuYNUbz5NUXOUWZulMeEG39gW8DxC0x9GeWQcL/hFz5kx7HNRGRbGZBvqQx7sJMXPdsG8Ii0J/NPLlIezUJiIy+t/Od69xxYEVG0TQqjpnxRvMDthOjv9F0Hb6cG9zkC7hzBtL4889xHAWuOjexh4y7Jj9B+tLOEG6ZMTIm6JcjMufunxd27hEQTtbNproLVCSIlrPYpHNfiOHMB7JCTBxKKDUsCeha6kqO8= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: c2d7402f-87be-48b4-cf91-08d7fc3edb5c X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:59.6458 (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: +OIMWoSUjgUUiE/Pq7I7EkxE8P2BxLdT+AoXLXCeKERKz0TYfetPZ54q9fZ9IDt3+MVmstQcL1cx3XE1rUHVEA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: TZdr9UimGcscQ7PvGX6IRD4Fx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925151; bh=313D3NRMlXpFJAvT19TU/kbX9Pj6awCiRlh/8wwfdc0=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=CMh1YfljkOiGjpTA2xBQ8Jpo/x1JMVoXnq7J7KQmyuaPfI3RxzbBykb/pxw/yjqoUOS S4EE0wX0dP1pfc9IsxB8DlLQvRQsJp1YXM7safAcA0XbN4aHAwOT219LffGF3WbQdFfll 3f0vbiPrHPedEBUOgCn76SZ9m42c7zut2Ig= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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.17.1 -=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 (#59886): https://edk2.groups.io/g/devel/message/59886 Mute This Topic: https://groups.io/mt/74336591/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 Sat Apr 20 05:17:49 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+59887+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+59887+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 1589925152762891.8048777965101; Tue, 19 May 2020 14:52:32 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Os1dYY1788612xJdVNJpcKyL; Tue, 19 May 2020 14:52:32 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web12.973.1589925151073622217 for ; Tue, 19 May 2020 14:52:31 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZVTt4gnv3hr9XrZhQWxomFWgq5NdPxYgV3SIuYH5LxtZ63cWOVw9YBCEE3ncCarMeWt8lk1CZ+ule7MPEaYlVFVZ2lBnPu4f3z50MjW6iLDH/bjAyGRiyZ/v5ruxvqX3tQvKPBHJGB8lZT5BjKyMWWPrbsNXr6NweTkgk7uh+QOcOlq2gV3Od/vnLUdeTjfl20zLkEQrnZ3abTs+FNoRE2zW4wpJ1oJ3NLbUyxpyWKmXqpkftD+cJbbcpDgeTUYRln09ZBdbDSFu2vMLxIlvJ05MpxSYJAxQGSnXE9yfTxQ8pAibByMx0vBv8xehQ3AP+R1KDzHuHSQdpIHWhj3p1A== 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=/rr7ltsRuYtUHRnGszvTM9RPMohuNK82vyD2Gdog1PI=; b=SuxZupbRbiHIBIJOlJFLjDuekwCyzAy6wgu4D/N1OYHtyjLfhfI80Zx2MHt+kEuy5eDx2H7nyIzj/58AZs0KDjf9mtqRCydbbIvhCMRT1fB84XcGnNjJV8k/TLEV11Ys8ZuYuqiGLYw506L2qDlEWz37nfVBulmP97h4fbwNVqvj9ApfG68q4G6la0WaSalJgOYli4/IIB+YDBbouVcuJfjxQ8H/dqqTyhBYcQk4Ri/R7NiGoYVyd4IP/zf2hHrT2FyT+UH8PowStcbPTT9UIYlwe51cRwSSOAKNgKflyhuwcmvaMle+loD/XxbnDgumBoIcuFbjqApEVBObd0yq5Q== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:52:30 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:52:30 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh Subject: [edk2-devel] [PATCH v8 31/46] OvmfPkg: Create GHCB pages for use during Pei and Dxe phase Date: Tue, 19 May 2020 16:50:59 -0500 Message-Id: <7597094ec951d2224f9527c2fc18cf93fb939f26.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51: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: 02343ede-f082-4977-b947-08d7fc3edbe2 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: LR92cceCaoM1Z/w9CBrwcLwebQwfD1Nbb+oms55n8E+cH6SBnEXs6fqtIPCrHk6dUZrbJFmWTWL3dcXTG+TQB/Z5cIDsKOXpgY+QbroQ2w6rwcs7em/wbIrXIn/bzk96xL9uJUuRpbKYQtx+QBNQmCUdzqpRZxXJGaJTUiZJ6fn0BUg9xiZg/u1rm9+umSuerXq/nFZGfuTHKyJ0KI/w2VZSnFXR5I4Oq8xKBn4SdYbQOdHNEFEvKt18MdQJ7Eovg8DPanWjbVZuJc/yQ+1XLdIIgd1YP53tgLIYrrhTYCCRPr5gDXQHH/jJuiuLW7U0iQThdPwnHJTlIFhvlWenFTzTKPNTtuWD5i1HZEdf7tvs32pQ4ON0dgdsjDnmyXuMryLlFsk80ZqcGjxgUjlZEOXmNfYWneHXGLMk73Wc+ZCs1FVYd4IjlBpYBdp1XBr1WPtE/w0ZWNPGi/QDF8IP0IZ/3xR8Zs7DZfw7iA6TsAL9yzXAFUDwh7WEFqHoal56Qa/HJyGdt7/IQkd+4WbyXsOVlbBk/1jmML2R5nCmQ6ZOF8cekx8q9NYabolMZdpzWcjiwBx941eD9wMA9X6EXg== X-MS-Exchange-AntiSpam-MessageData: BrumDrTa4lgrG8OXvLCTkBRPa5JnJhRmszt9PL2ebyJReWqYvFt/2cyM0T/j1WwcDQv9IGRbhQwc3KSZhyMQ2LDA8KYPZZkVd45zR8/Q0NAtK5D4M36Eh++GRJ3A7HfTdSt1oTbUtTJ/hLFHCj/wLx+7O8K8yTHY+HLzW1lSfNH8bB+/gDOGU+rJQ+OnvLAxVqh5GGFXtBGc8VTLvroOTrXdj8UiogsTyO8Ai5eqz9YVmX/dPaN7SlzZ1LE6z/lPmCoq3hpj9y3AVl+ufBf7m4msDwnBS5zz4GfRF5GLPNs+GhXnMSqaPkATgDNIw9pvLBuu55FtNVzL5zCOr3oQLa95HM2c2iq8l1B3VnMASeYuaTNZyXnbZjA3m7PMliNjZGQkQMeYwBKztcnVjUmp7Qej3fFK4l4WwVUsDmZFtk2dh4mmUNr3MVhWtxZUTI5SAhcD7TcC2NT0Earzi55WA7XFoPIydGtxhT9ZbUYDKRY= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 02343ede-f082-4977-b947-08d7fc3edbe2 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:52:00.5494 (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: DVEH64vLkIdLfRzYijbFOEKp7CJASNwmxtDkQQ9tDkaOLNy2XFTnjzt9dF3rBKaHxEDHDh6sCs6bFZmcLw3wEg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: qUCUTmCu5tnA1qPr1Ndh1nIhx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925152; bh=4KUr0kBfnZmnwZiofXjH2IB3+1us/1cR0FMQYJ3AjE0=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=W1IibUHMpH+nMrCJL/y9XGlC+vpueq9lk1vGb82OHvHnMBt/u007JK/2dV0nNxkC+Fc 7B+PUk8eHN2FzV+Qhgc9wpgqMbn6Ju6BKRQjj1KjY/Xhg7mI7URhShqPCVbhikTp2iJQr FL8q3DQhoLdBAk35nSE0hW/9I5EEOsVb8bY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 b289260c1f2d..f849a7d698cd 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -611,6 +611,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 00faf5036670..d1b4ffedc6af 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -623,6 +623,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 58671828c5fe..ebc903d922cf 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -621,6 +621,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.17.1 -=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 (#59887): https://edk2.groups.io/g/devel/message/59887 Mute This Topic: https://groups.io/mt/74336592/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 Sat Apr 20 05:17:49 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+59888+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+59888+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 1589925153027252.01832132495588; Tue, 19 May 2020 14:52:33 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id jsHOYY1788612xjfCHst8fK5; Tue, 19 May 2020 14:52:32 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web12.973.1589925151073622217 for ; Tue, 19 May 2020 14:52:32 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bNr2TmxRHnm6Da4A2PUYojTykbuIKliy2rro+yOO3teVpW+tVnIRd3A5xdzwB3rNKfDB1f9A5d4jP8gkdSU7CYRQvyaRio0tuUq1JixQOlZdUy5pf60mtQisgyIVqLZdXAa0fzLy82xHyjpjnVUfy/t7NmV79vX8oyw4sEm7efYZpMHYl/zZ0fQF9afaofk8o44iqOI5ZnawsOhklnysbXxZZmlkc0cfDJ4tu5ECqBEzaje80hZlEqBUfpoJXMbBRPNWvBhWGlYMPz3/iZVMoVaGuyd5XUE/2OBUPO3uVcg5T5DLLFSDHsYD0PeCpB+lM0TmHod+VSskZmIYw8RZcA== 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=bhYNcWe9Dmh6ZVNNV+RLaBP3kJL4aqhaTuiWyDwt+ts=; b=KkkQGsjx27+OiEBLrVIRvUt0FdsCcMe4Y99vmZeLm/QRIqbNEfjmcy9J7MyCPyiVzkfF0yMP87Dukmu0IILBW9XCkspWjpxkFnQ+lmo9vyGdERSsAX1rv5ZdKrzRwMYi3VWsn9SUcSgf+eMoADOI6m9DRhvwMLq/7vhj9oXqzil9/PHzbPYWgvJ7QtqQ3Yy9ePyUOCKDurgmwOvq+/kHElOL8sH13C7Sj+SgHEwp3GlDlfZxjVg9jnmjmUIyPeEDIak4yI31iqi1gDaW1VXDwjWx6j1CaWmEl6PQB7ZT0WRRXRHg8Wp8iS1J/YPPQm3rm/PlkSGz2TLT6j9X5OvUDg== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:52:30 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:52:30 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh Subject: [edk2-devel] [PATCH v8 32/46] OvmfPkg/PlatformPei: Move early GDT into ram when SEV-ES is enabled Date: Tue, 19 May 2020 16:51:00 -0500 Message-Id: <710be72175adbe91d24731bce13079a05868face.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:52: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: 2e3951db-ae8c-4bcd-a300-08d7fc3edc68 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: ngDy5m/Ow6vEKLdn11U/330miuEJBdVvnVkZlpkyD6rutbG25Zv3WU03zM+mwoKlUySsZ9vRnoCFwU9MXNuuOlyOlBc2DdBUdhAeQrw9KnZe4pUSaJOBbAG4QLoFwvOXrQsBiOpTOUz4FIWk1dJW0Zm7W2kA6Ly661ejPJxxUUgF81Sm3fgjdzjMjgRRPLZ+cDHrLxlGfLZU8SyQSdM6htxSrIMc1hzcyQFdsdwZDyEt2fnY4neyguXqZMo9suUi17ubKkv61E5vkRb1hA/1HoRcD+Bhmv2tWl/BmMai4Oa5JrseyPbLeuBk23oancyupoyYlfBUPFKbUDt0LdlosUFDUkSpmkj2K4jIBlF9khe7rRI6Q3jnGYBOh09u7bw8zRqxA1LT3/Pm+DDCvjlbargSJj+wWDG5Ugf2GNhB9/BARy8z77IBGfAqs98mXI76tUH8CmAGK/s5K5TYK9Jn3uk2pIXD9OrTfvL66kYxaV6WB64tKCfFY2nrNz6f4JZ1JkxmS2+z71QpDh4Z+hGfRZV943IuUyuoh1L2WNJQ8OlcVKgdyhFi/U3rgIAxNV9yp9NBxCs4t3ihliKA5ws7SA== X-MS-Exchange-AntiSpam-MessageData: hEV/2D618oAMwvaNz19HcmvMBJltTBT3+7M2GudcK6wJhcPBh++7rXHzA66OshIi4F8amfVD+k30UJTY65NrpDJQk0RbrGS8FMpq102duzt+IRpS53xN6ZxRArYVJwnFQXpVVk6vPAz4mLzQF5VQvaxOYx8sFzfs0G/sOEReW/aJbhdElSKRL58uQ4RnshSi/VxfkQzHq8KbCFx1V4W64jD2S6NdbMYLvxKUn2y4yKwM7hzaAE5mS5SdSZuWVFw+srVp143CMZph5kYUqVJ0Hot0gy/oZi9Lh77gR6aCP4TO6sTBsDkDVso+5DJ8ZxoBHWjmORHU3tHvd8+wqI1ddHC+nQ+kT5UD1wOoThdRLRqYSl0+oslx1emtWbKFPUJwWoyuErHfJbuAQ3UDNIPV35N7OLuAZukxqId6Pf7Ba2/tlfwslfJNsrO5CF9Zras7BLLQvD6T1KpZvLf9HdrzzIofupu1iAAUMrO4y7Hc6ec= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2e3951db-ae8c-4bcd-a300-08d7fc3edc68 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:52:01.3930 (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: gsZhlSSi6bj+IlreeDaifeI8Kn/gcnOSSArmGmdFqzuWrOZ9EyxPfZRevHGjWfPJ0UG5ab9ZIzmtuWcLmA+PLQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: ZTJpMV3nl2v7j6kSYjlGhT27x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925152; bh=eJ4B7nQ6VnCbv/P78KQXN28Lb5y9jvQPoYxHJ9bdCK8=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=LyZQGqbWDax6O7+6EQ79aW5DSQuF6eTxgVG2UkMYWekZDzPxzjeWd2RM1FnVY8MJIL6 ZcZVQrJShjVmTqLe73r3/jc/SJG/b7fUVpFQQMaxrWIINnNFPhSUUFhhwFNBFtF9wzjYO NuKsga2sddONFks9vd8UMuqGnUHOO9QS7P4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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.17.1 -=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 (#59888): https://edk2.groups.io/g/devel/message/59888 Mute This Topic: https://groups.io/mt/74336593/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 Sat Apr 20 05:17:49 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+59889+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+59889+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 1589925154310501.8519435730826; Tue, 19 May 2020 14:52:34 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ZQN8YY1788612xTwiTO0jJDj; Tue, 19 May 2020 14:52:34 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web12.973.1589925151073622217 for ; Tue, 19 May 2020 14:52:33 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IjAUsJb4c2TlBFvCUqujYIs9o/2Ljvu2E0BLL/d947BjTMPectDV1yULZfFzvf3+aTFb8yo4umskhW2xYdCy37jJdc+p3J89ox8S4ury818/ugGVZ5jEsvbWlwUQC2VKbkcAE+ImHkL3ykNQCcTzvisVAz0J7xCfCKC9vzudwq4tvPGIGgkMyJ0gS5IxG3pkMIme3YEbcmbgHyiBHosZssEgmcyXPdi1sRJAcv+TGPrAgBv2intbUMo4kl+oEtxdiP5r7wLpyOmGpAVGzWVqZrWnpe6RlG5aqZ8LEAtl6248WDlthVZ3ZBCEpXlBX3zrwiTmiy3JQjwGGK7jw78qUw== 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=pmi0pHZi9uUgnzA9mevxfBeN8ESF+qwImSEwuPFGXBc=; b=asThokwN5AKF38G5htu8s98vWrqhPkyUqhkQEyntIBuvAa8BSswurmsugQ2He+n04U8Nr0ZLOe/d4ASUtEtj6ZdHygzrvAF4eVYWWJTOayaVknIGNWgcI6IspdtM7X7vbhWH9j5fhO3+TSviyYdapRK+LKGiqifj9YoskxGv6HLEI5f9qOiQBg9NsvrMlflxlWmMA5YjnFucFJcIFubuX7LiPU4gSRiHOxIecf1aZPIK+tl28n9FLlkBL1iGeL7VuskMcet4BnMaGts1TrD3QHBQzKzCQDxTtpH4SlZvMx46SiI+6Jz8j7X8C7X4gK/CUAQ7L8maB0tOShAuQMbG8Q== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:52:30 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:52:30 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh Subject: [edk2-devel] [PATCH v8 33/46] UefiCpuPkg: Create an SEV-ES workarea PCD Date: Tue, 19 May 2020 16:51:01 -0500 Message-Id: In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:52:01 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 4cc221fb-0236-4828-843d-08d7fc3edce9 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: NNAWXxryDMHDdLAsjxsgF5mwpPXfkXB2pCG3kuIi1NYiD7MZESwOEvDVgMIpV8gGtTuMM8uskotl7UOk9yOK+ZKzPvmpr+ZTBEgheI5hN1yLEItCbaKqQEyZsT4jPUipUX1C0ZYvMRq1qRk3Sfo9dDRhciRjo3D+5m+9FKCHfNbwCps1LVQQ1a1fadPRSgzu88H0SgswBFZE4reUM9a5L6N2pTXpQCQVDQ1pkGjlSObnxy1oVyZPavWzKgANhrg2/eiXo466HIh2EFXIIqrSP4AuVvcNMTHRkMTdXjb5AE31cpDWhZmXGzKOvv+HKJYUnLsQ9F6aCJCb7vs0xM9cv5naBlWKi3JQ3P2K43z73ULN/Zku55b4UXLhZPLnPZ3dqtNHLkaMqQAPEsGpQirLt8Udu9jc/UgwbbTJzCqj/XSYQAeM7s1Sj6tAf+8XEdeaP+wYrguMIK2e/GPGka9306ec1glmT5UPPCjxuuGCiBQG4QRT2AxaYY4yEuG55QxS0eHbp/cSHZgNznE5q7BKA8RijV08LfPVoTP3qcMy0g8+hH/rBt+pZhWhq5DuXxb+IslIJc6voExB84r0pr+bBw== X-MS-Exchange-AntiSpam-MessageData: fTaAR/SPjyQP1VDHvYOuHwc2I8cUWWYU9iH4j0nb5QJUUfoe/wiFjeGl17CteeP2G5DNpZPGO2OcPxLQbPfQiBCiDA/p1RFLPmyXLNLd78RILLcEraxEB4s2L9uFwZwA/9hveUDt4ScGbI1GKa+w/XEfz5ep31G3rvoGr+9BSE9QiQhugTdCJNthxA5hwD/lTNda/B6ehbF4TbsLScvGyrB7ps61Np6nUn0cuiQRpzOrVccV9ZMqfVnwYotgxDNVVuM/CNdWKlp3swTWx6JaDhECn34N1u7RW6zuiJ3y4UZw81aCSKW/kh5BmfCu8E8K8PAnt1ZHY5zi1tFOMCeUziwErRXbJ7oScvinP9PumzN7Avf5rFBWPr0++iT+/NQrKfp0Ve2ZbGvI9G3cmrpec0iO4joB+a2dKtw5Efp4xb26ACBwnErcR+aAdy2jBL87Wy1JBd8dy1HxIq9GeBTQTXkz1GOJAfF2lnLcbp4fMEs= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4cc221fb-0236-4828-843d-08d7fc3edce9 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:52:02.2406 (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: ry/rFqUCh7iDXJRRWBFqGQw6kcz34yA4E0s0ILAxD/yrWr+mTvQ8pNNbXPZmgAzjrXb0Y8vamfSDu62jJTW+Yw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: LhJcOXdYkhFcoAcjQdvtsArwx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925154; bh=ZV0rUJuoGrJoBwKtWCNcjGp92JbdNsYNWArROb7T9jw=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=J222Syr4PbYIXfqvSDDAVME1xPd5/g+QEqLwHgZwpXaZPgYpgyNrKuT72SXivoRrlwX 0oGTVf1MaEqdhQYU8Mksg76GvPBIcAc5v6IB2aw4/LbD/w9BAdNGWF3mCIDaxcnwuegYZ lDSOBqb9Zw9Lt95vnXlcMvaZWGST0CrcFTA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 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.17.1 -=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 (#59889): https://edk2.groups.io/g/devel/message/59889 Mute This Topic: https://groups.io/mt/74336595/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 Sat Apr 20 05:17:49 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+59890+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+59890+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 1589925154874996.522707052338; Tue, 19 May 2020 14:52:34 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id BYNZYY1788612xBk1OlGcnng; Tue, 19 May 2020 14:52:34 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web12.973.1589925151073622217 for ; Tue, 19 May 2020 14:52:33 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hrHWmHQgnhK3YUkgllRldM+tSPxsJd6sVveio9vHG7/ypGEg0/hRh6zrNs5NpLt/owzSoyLeqdtoADvLv4wgOj4ZOYgNgehdxt25oy8ljXkr3uUM629S1r9fNbbf/4wvIQqoUUq4CvJK6cMYIGJBk+Z6/X772tgFXejdf3un3QovmOpWAkOInyE1U10zyTmahfAQrkQRDoyO/P2vGmgnIWLFbCm9aUXlO9RCfO7KCAmdHqmgaKzvEJ0qd2yQop1PBC20JZ3IEQHyGv08s0/qjD1Kzsf7LqP3H05Osr15VTItfPOQf7htRUL7eaTNkbwFf783ko+JlWEEHhjGU8MBtg== 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=RepnN4jAl+qcMYuMagJ366cTMOI8PD5sPTAurOYPvdI=; b=esAsDBMavZrEqVijf4eEj+8rZZXsyd5hdyjOpNOtl7EzYJXvTo9walFbwoh13R9mbGKo5yfBJsiAJoXva0j6wtY8+LWOy6GfbXUWKvoYYcbRTN5o1VJqTzMOqPeltsIApzx41AtW2w2yqPkiiFo3qNJ0M60JLsu8v62s1k4toTDusHo8QVPAlMEvai0W5DQUMzNRlNX4xYr6ETnxwmHIj6KKhIJdLjmQYZUNIX2TUPHDJvjHEcTn8O1ZrAYlkJ9NYDvA//iT69TQARqzsLv/6xpfkgo0Ma3OeL19TLFnXVZWVK6gNtHYYC4XPqE7Vy3zI0DfgIpN3KyILrn86qVeaQ== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:52:31 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:52:31 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh Subject: [edk2-devel] [PATCH v8 34/46] OvmfPkg: Reserve a page in memory for the SEV-ES usage Date: Tue, 19 May 2020 16:51:02 -0500 Message-Id: <5f3a4f30804261206adde675b983f42b777dd5d8.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:52:02 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d9510ab4-646a-46e2-8824-08d7fc3edd6c X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: zvIL5bokm1AWzX0zb8AGzFdMwwsEBVN1nTx0Ql4mw6MhqDFaVU1IKXTzZJZ0jUrPfEFU6ZXPktRAJAmNLfDLMywqbzY2g4z3jbGcjxAwSJ/dcSZEPbnJKmwR98GzQ214D6pwU7x8b0k5y7nCzqR/cDByUR2QeRMTWTDb81z/BKxccKXYU/uO1YzYav5KMl8F4AQmNvgKLOdqDnk9v8gBFATLjrRHIrk21zJzzxpY5WgMZxxnG/m79f+8SaZwtyjlmLe2c6WikX34XM97kEhIg8Op/7vfJLu1IbWA3bIjpXTlhq2GRs3rGZ84OYWQxY1AfR4/dv1gKSnKA5VfOyJPuI39PZrLl7NC1SC14cLlu+8MEfb8cpG/sjBSPRrWURpOlhPiNXA3jgvoU/1kRAlxLUR2eZXFcGb5x+CvGgvyWWaAID5mTh79ImfAqs6kXQ4ulnLQRZSf+QYjNHrQQcGY5T3teYLqj1R81K/GZgw0XxAosoH8J9cJSjq6ZgXBZtMAYIkEzIKQbz/vtTLX4UD7qloeZLwG0T9cfciHZP7CVuzPzS7vDb9xxA7JEPvLz5hWstoU/BgnvDRYRWuO6CGr3A== X-MS-Exchange-AntiSpam-MessageData: 3k40kV+zkvNwnwEostykwe8+7zmhezMXlcf7DCtk1w9PLa6h9zYuQtswm3O12CwDFUF/TfZB8BZRZJDPoNQTJq77uSv7bdDLv6NGXKQ5CtNTo/C2682w2aiEI8Vk6hIREWJe9ewXqDYk6DDMlREFhG605FO/gRMtaTwqe5NptEyWPIKutjsr4EKhUpMjdmd2PVhClLRj1K6TrMYiBNOZL77pqcXtV4qftFYDeSynho1P7+/Cu6+IZAz5DUnXa2/D/09OABJeOTZsWglaaIZrxqF+YoDS2Q64C/3/18CXIlhbRWnjrGaIVRrRKoLVaaSbnzGJK1NuPlv5HkHju3gYeErTobfro0FALW3rQHhe4Uto+kfWP4mSPzOocrgCMvWnxMFmX4hgRfXTzdD+UGUNMH16NVWI0PO/iLj4WkUpzp1rTa/A9XKJG+ZVktrbt7qUIjaHHSq7X0dlaPuiLu5gW/SCUlfghdFFVuVCqQ87nYs= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d9510ab4-646a-46e2-8824-08d7fc3edd6c X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:52:03.1123 (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: CM6tkhEqzceKsuHZ79F36CJg1X2zN8HpkK2bnmFAOTxwlMk1VNyAddr2wlFV9gYksaunqsEldkfHyB5A5iHavQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: lGni0C7jdjU33WBbPaHC0586x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925154; bh=3fJatW0a4azmAt3DZ89+HMNUPZ4o/h7IsIF4HYDktKo=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=pUjMczym4pYuxcX+PmwlMhzES1f8S7uCWDXY6qh+OovYbiCVfFkVmZx9baNlewdu9Le suQ2IOFDMgN/r7Ij1S53ibtdEpdYi/W2azK0HKi32ZpZPo7hQ5fY3+8KBov9CSJsa6D+Y wECnJ5dMqANnj9EgMtNzUB37Rr2ZpbNXGKs= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 +++ OvmfPkg/ResetVector/ResetVector.inf | 1 + OvmfPkg/ResetVector/Ia32/PageTables64.asm | 11 +++++++++++ OvmfPkg/ResetVector/ResetVector.nasmb | 1 + 4 files changed, 16 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 diff --git a/OvmfPkg/ResetVector/ResetVector.inf b/OvmfPkg/ResetVector/Rese= tVector.inf index 483fd90fe785..e94e1bfcce7e 100644 --- a/OvmfPkg/ResetVector/ResetVector.inf +++ b/OvmfPkg/ResetVector/ResetVector.inf @@ -34,6 +34,7 @@ [BuildOptions] *_*_X64_NASMB_FLAGS =3D -I$(WORKSPACE)/UefiCpuPkg/ResetVector/Vtf0/ =20 [Pcd] + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableBase diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm b/OvmfPkg/ResetVecto= r/Ia32/PageTables64.asm index c3587a1b7814..73a4eaadb1b6 100644 --- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm +++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm @@ -89,6 +89,10 @@ SevExit: ; If SEV-ES is disabled then EAX will be zero. ; CheckSevEsFeature: + ; Initialize the first byte of the workarea to zero to communicate to + ; the SEC phase that SEV-ES is not enabled. + mov byte[SEV_ES_WORK_AREA], 0 + xor eax, eax =20 ; SEV-ES can't be enabled if SEV isn't, so first check the encryption @@ -108,6 +112,13 @@ CheckSevEsFeature: ; Restore encryption mask mov edx, ebx =20 + test eax, eax + jz NoSevEs + + ; 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 + NoSevEs: OneTimeCallRet CheckSevEsFeature =20 diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb b/OvmfPkg/ResetVector/Re= setVector.nasmb index bfb77e439105..2967617bfaa0 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -72,6 +72,7 @@ %define GHCB_PT_ADDR (FixedPcdGet32 (PcdOvmfSecGhcbPageTableBase)) %define GHCB_BASE (FixedPcdGet32 (PcdOvmfSecGhcbBase)) %define GHCB_SIZE (FixedPcdGet32 (PcdOvmfSecGhcbSize)) + %define SEV_ES_WORK_AREA (FixedPcdGet32 (PcdSevEsWorkAreaBase)) %include "Ia32/PageTables64.asm" %endif =20 --=20 2.17.1 -=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 (#59890): https://edk2.groups.io/g/devel/message/59890 Mute This Topic: https://groups.io/mt/74336596/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 Sat Apr 20 05:17:49 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+59891+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+59891+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 1589925155348868.95624654887; Tue, 19 May 2020 14:52:35 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ClSCYY1788612xKV272Kukwa; Tue, 19 May 2020 14:52:35 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.53]) by mx.groups.io with SMTP id smtpd.web11.983.1589925154464670122 for ; Tue, 19 May 2020 14:52:34 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QGSrsBhpKVzdHoPmt49i83wtxVgr7ff/4lz8b4aYEE/JK8TG4Q+ktFB/76ZPdGkL0fLO9F6hCsj6BKokOtWFyoRV+dnsQldqwPFzaLGtFqAee9vPwtB1+e7LHy+mSphLU34rMFlZxwhdkSJnw3xk1By+ic4y+RlUEHOAuFILDWB3QPxPiGmh3JYyjA4xe44+00ZwnueVE1HVjN5KbqmT1RRCbCDrmH7HIuc1VqOQxWBdvlzhrxtcqpvx/3+CxkVNnSKrghhLYsQzudRU4TiBN+15WTZz0BEw5rgz/un+ZEy8/+HrP5A4xrQ+vqd5g+4rM/RTZCw2U8dg1EbFz96hRw== 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=0b1LbnyzWL6MhHhbC6SyUam6dJ1XU7uVcJRYFhYCqSA=; b=MR5eP2doZq2+GpA14v1iHFzcl7QQgu5dly3ytmnKPAg8ZZ2MEqB9gNXoLyh3I9rnuxrc7F/zeZBnBm7jZpS3eOvDaN/rI9LLYM8n9OdgaWGNXEnee7655BgS8fW5Yig22qUe1rNXStTjrDcx4ij0moXTAke/cQ44P9kivTEFVs2vnELvGByr5q655VArYRReJrkb2LVe703OPVLd3essNG67Y0ZWESr0UHvv31sveg9Ytu4av/w8Yw4H7xx9BqqGU9Hwz+LVOyCH+lSQZ7/DFXyUd+rjSA5ceByIxFkGzRXHQqHpJ+PQTrfDtgFRXolBCm+B/+EBO/Al5B5MBg5pPA== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:52:31 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:52:31 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh , Ard Biesheuvel , Anthony Perard , Julien Grall Subject: [edk2-devel] [PATCH v8 35/46] OvmfPkg/PlatformPei: Reserve SEV-ES work area if S3 is supported Date: Tue, 19 May 2020 16:51:03 -0500 Message-Id: In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:52:03 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: faa9d040-0f44-4461-11cc-08d7fc3ede03 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: ZZmfqWyqVkZz8EpQ5vbo5tQnjCtmh/N2sVC9ZSUmG7d//+oKX9kMwGkE9bteXzFIUCe1d3udDMjRSyt55KUjymnu+IdO7EuHDzSxHSFhxC3RJcu8r+wpXAcPkcZIrlMss3pzsmfMF0FkAXkBp5uw/BH5rnqB88mcBbQLq8p7b0UzkPw3xp0iQBVaO7Z+ebAdvUCRcDPjHZApO5ewbNDPKWl4zLlmojN/f/ull1O0hmFMCz5I+G5tE6eu6yYhMuRfZy8z7hvGuj0BoVGMNlMtYUgqJFHYYdBB/qBdtsu+uVHIFZFIgTiW/4l6QlutMnuxkMUheff0tilYK24BRYGQgMxZOS6kAJ2yZ2MwUR+ejvmvkmY2Be7yDrpzfYlxpZCvcgIdEZZwrAGiKnbfeQm4xpWe5QqrY8iq48vN9SlfDJUY3xklJckgMEKksas+wcujTcDa1843x+xvr6uwnopOlYLodXoXv3eP7OiiVlIVFm1NuX/FXZHN8+n/Tfg1ZbqPdFSs5vzwSXdaScc5gHOEHdjbEQqXifEbNsSf8jAHF5ezkYfn5tL9DYMcFGDsfSV5VAWZP08C238XkV3I/3O3sw== X-MS-Exchange-AntiSpam-MessageData: vu7191C+K1SrqICoQ9cZgOWIr9jUnPKWKa5PM8fgFQ2kzajjJLTxEn7B8/YRvhry9/PD7TtszxiaoESe4Sr8AjK5tTMj8sT3xiNrUleuw2erpXnsV7lOsxxVtMdWPpFwO4Y67Iw0WpxbuqBhqQWiaMcROIxayoiycSvkzKtPsT9a4aMYl1qMfU+/CPnmOt7PLcDHpKU9UP9kxQFAdmQdK5FlEh5ERYavzTGz0hBixqBhxEy5by9N84ODEnuRSMiUVsOfo6TkZYUGomnuUJhn80fLbb5rJ0CfmHDN41F8qkuigBuWRzw10NKaLb/UpVklpDEFEdx/JYbicSPRiGkYQuhIMSsbxrQ5fz8thocxeGwfzy26AftlPmB+0GQwZScNHEA/fM8A4LnnqhRvfByu+8A01ARj9rTd6hlfgp913Ae+LDKil3VlAZqE3L8G0Q1cJjj6AkVO/MRR5nU6zvu+k0BNC5OpMhsoqRDDlZ3XffU= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: faa9d040-0f44-4461-11cc-08d7fc3ede03 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:52:04.0758 (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: o6DAh+YumBr/rxXsiY/x2gTHh+Z29+vPePIK/Va6hruNmYtuTR7e9bWvXCZUJxGOcZnoxXLE2mIpx8OPptEKCg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: mLBKY5Uxn2Lxy7H1JUR4OXDOx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925155; bh=Q/3d3MyAMhVUVF57MpN+UiSh0v/bK2AzhSVAA4ZrlgU=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=OPlzpR4l7jqMYl798TnmgDj3kjtBLJQEV4EFkNPdlTazVNhJaxqAenb//LytoKY8MuX 9KBz5LODr5tLDvXKXXWh+rO/pHYWGzdjqJ8EA/WEQPL4fSgVsKL6aYS8NuxHYt1Hwdm8E GZ2262jOXqsn6oz1Dn7HSLBlZNCOXAYq17Q= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Tom Lendacky Reviewed-by: Laszlo Ersek --- 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.17.1 -=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 (#59891): https://edk2.groups.io/g/devel/message/59891 Mute This Topic: https://groups.io/mt/74336597/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 Sat Apr 20 05:17:49 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+59892+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+59892+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 1589925156822462.08364895086095; Tue, 19 May 2020 14:52:36 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id FOhYYY1788612xeKkTM4sctk; Tue, 19 May 2020 14:52:36 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web11.983.1589925154464670122 for ; Tue, 19 May 2020 14:52:35 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cF+tps4wAnzPqMWQsuJj0c3qacNc94hzjtB6lReG0lBg+M7ayfATaExWPAGe8fP19vsf4NcMK1M3nHIHeRa4FycV8pW8+i7eVR0hq+tVdCvEa45/4mAgD5uYY0fnJznQGPe6DMlbWUWLlXnIqeLMsl7gb/V0lRPpTKJfQMtbEwbRnJlTQDOwEmK43iZx7D5O9RlWNdY0s3TxM61a8pRndfd5OhIuLfldQM/I2DJvCWui+965OnJPQ87qT2a1K7Hq6Nz4CxuINiY3cN4uSzs/ALBnE0KcUftMnfnW0SNhOTg2nMrr/bDXzDulvVPuJal9ozIbCuallxfcfYgxCIIKgQ== 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=M8Zcl9eP6bSEXmFyDIKwqgBUPRkcXLo3J99VAnhCDc8=; b=odKHimRxyRyWhLNW3DYAWewaqKNO7mv6yY/njVDRKorBMhp5+0z1HkALnGVP1arDanKuvPimh5f+lYSRNyMhUOomiro9XnDrHBM1mtVOs6g0S43GHLMV/2WfP7ZXaDk0MU7Kep86cnfzLE9h4t45blY+OX4iFE0W/a090tDJ30x2xVFmsFPAZf0FzVFX8OfPKmPGBlhRS5BxI6q4oZqwlekaMj6QeoxWsc7aoZC7m9ENb13K0cZsTDao0G6DRSbUquP+ckOZRhid4r2Yybtb/DL40OeN4M/jQ9aQnqbHeHg6m1Asxao2uo3GLNni6zf3ER9wKvNxI2QXSh4N3hpQAw== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:52:31 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:52:31 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh Subject: [edk2-devel] [PATCH v8 36/46] OvmfPkg/ResetVector: Add support for a 32-bit SEV check Date: Tue, 19 May 2020 16:51:04 -0500 Message-Id: In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:52:04 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 619fdb3f-fba1-4239-49e8-08d7fc3ede80 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: 8WsHG9q8hReZijGmBDsShXMjpy0wI7qLEN0UHhnBJLwGdyJXwYdVdU0BmXWA1JFKZytGDxL55w4/4Zo81/+riO5vb2Y8rQNKzCXco/TBgy6rWGAPgPa6u04TUNhTH6nhOCbViB56gFQ1ZHO2DuNdw6ToPOVu+fl0onz0J4mUmQmCNP4PyEqsyUbac89RlxAaXoOcsiJNiIMeE+IUC5RXmx6F7/RZsZW95wMhPMNy1fVbQcQJGAIhJwMqbr/rUmi5SGTTuPAhWWWND3YE6egSUzoT6NAfLg2mGxX7Bx1bd+D4cJywvvsrUIfiIPBrvzzQsRoD/m4Lz34Io14GpurL33CSALqE7aUCMfXZranJe/uVf5KqRrCbB9Pir2mxbvATTrQUJDM3FDVcDH8uCyLslE6HyLJsT8PBVJUmgSnUYPK35+erSpKCRibRQCS3FBExnQn+/W3KsNHttdBgR2Vo4uz14M4caIHtyIk0OQLjKf35TrJjrQ3Ycj/rE7PqDp5AN55BWhpBZHhHcpJUshIUE2KvYx5Aj9Qz60xJ9yYLfNBFvIwZdzAjUMeWUq0ibTwjWk8lnxLFSnCC/N74SH7d9Q== X-MS-Exchange-AntiSpam-MessageData: HiGsYrPI3IjnHD63lL8caO+Zv3wDpNOQQcs6sXuw+9l62UrApoCUe1ELfcTnEIs80BZ0ry4P+5dRyBRBJ/Bqhvp1HLu9XuM9RFX8L4dsuIt7V36IcQfkW/awS3MUSZrnYfNsbbgASgWlSNdshco6aioeYiTWQG+bHi6/bn+hLyJ2HigHuh5sIvuEEMMLC9MMDzLfN6QP5fWrixeJWLpJB72CRmxflsTANNn+6RNU1Qbdi5cNwmLBr1XRlm6S9iILlYLAndkmoC+SnjlV8Fy/u9sRVQxN2E0u2b6ADK3K7QynJqivkwEN2w9Z9zQPpdQFIjaQwRa/NDQ6VKittsHva3L2LEsp3ZFULXrFaPYIkW7TiIMtEEXkJS1+Gj7UXEtEwsCXh36tPY6j3LFUiJ+aP4FG2xBkuBFh0PKVb5c1/1jp+Da89mTcKAdvSkX2qjHSntyq+MTqY0ICs9C9h9B1q6rL0M0sP4ObIy2p5QIJyfg= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 619fdb3f-fba1-4239-49e8-08d7fc3ede80 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:52:04.8935 (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: RlP3bGgjPG1nl2GpcbysUMg9Txj0aFrIu++ljIxsQ3K0v+y5F7mzqsO/DX3MCi1w9omclruVKlB6DtohIkQnvA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: tSVr7onJRRRMX6JJhk0EDPQvx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925156; bh=wFzVRORI6uRnPyrdTwU4iYg1kQVCRiBhC+k65vKWvNc=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=hsd5kf+CL4mNe5rchWOdu7BnZR7jtfMAwEe8amibD7jIfJ8UkNq3RDSnNsNZavv4Yoc IxSgFe4Sn7PBCvChRQf7T9++ZRPNfRiGwcZ2xKA8DxL9xSOhIMbKdYalaDfdTNpa3dKkQ V5+UoDVkZxmxF1A5i3CYXmL3/Ccw0fErSMI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 | 2 + OvmfPkg/ResetVector/Ia32/PageTables64.asm | 329 +++++++++++++++++++--- OvmfPkg/ResetVector/ResetVector.nasmb | 1 + 3 files changed, 294 insertions(+), 38 deletions(-) diff --git a/OvmfPkg/ResetVector/ResetVector.inf b/OvmfPkg/ResetVector/Rese= tVector.inf index e94e1bfcce7e..a53ae6c194ae 100644 --- a/OvmfPkg/ResetVector/ResetVector.inf +++ b/OvmfPkg/ResetVector/ResetVector.inf @@ -41,3 +41,5 @@ [Pcd] 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 73a4eaadb1b6..8a24e7fd42f6 100644 --- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm +++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm @@ -36,13 +36,56 @@ BITS 32 PAGE_READ_WRITE + \ PAGE_PRESENT) =20 -; Check if Secure Encrypted Virtualization (SEV) feature is enabled ; -; If SEV is enabled then EAX will be at least 32 +; 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) features are enabled +; +; 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: +CheckSevFeatures: + ; Initialize the first byte of the workarea to zero to communicate to + ; the SEC phase that SEV-ES is not enabled. + 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 +96,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 @@ -67,6 +110,16 @@ CheckSevFeature: bt eax, 0 jnc NoSev =20 + ; Check if SEV-ES is enabled + ; MSR_0xC0010131 - Bit 1 (SEV-ES enabled) + bt eax, 1 + jnc NoSevEs + + ; 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 + +NoSevEs: ; Get pte bit position to enable memory encryption ; CPUID Fn8000_001F[EBX] - Bits 5:0 ; @@ -78,56 +131,44 @@ NoSev: xor eax, eax =20 SevExit: - OneTimeCallRet CheckSevFeature + ; + ; Clear exception handlers and stack + ; + push eax + mov eax, ADDR_OF(IdtrClear) + lidt [cs:eax] + pop eax + mov esp, 0 + + OneTimeCallRet CheckSevFeatures =20 ; Check if Secure Encrypted Virtualization - Encrypted State (SEV-ES) feat= ure ; is enabled. ; -; Modified: EAX, EBX, ECX +; Modified: EAX ; ; If SEV-ES is enabled then EAX will be non-zero. ; If SEV-ES is disabled then EAX will be zero. ; -CheckSevEsFeature: - ; Initialize the first byte of the workarea to zero to communicate to - ; the SEC phase that SEV-ES is not enabled. - mov byte[SEV_ES_WORK_AREA], 0 - +IsSevEsEnabled: xor eax, eax =20 - ; SEV-ES can't be enabled if SEV isn't, so first check the encryption - ; mask. - test edx, edx - jz NoSevEs + ; During CheckSevFeatures, the SEV_ES_WORK_AREA was set to 1 if + ; SEV-ES is enabled. + cmp byte[SEV_ES_WORK_AREA], 0 + jz SevEsDisabled =20 - ; Save current value of encryption mask - mov ebx, edx + mov eax, 1 =20 - ; 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 - - test eax, eax - jz NoSevEs - - ; 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 - -NoSevEs: - OneTimeCallRet CheckSevEsFeature +SevEsDisabled: + OneTimeCallRet IsSevEsEnabled =20 ; ; Modified: EAX, EBX, ECX, EDX ; SetCr3ForPageTables64: =20 - OneTimeCall CheckSevFeature + OneTimeCall CheckSevFeatures xor edx, edx test eax, eax jz SevNotActive @@ -186,7 +227,7 @@ pageTableEntriesLoop: mov [(ecx * 8 + PT_ADDR (0x2000 - 8)) + 4], edx loop pageTableEntriesLoop =20 - OneTimeCall CheckSevEsFeature + OneTimeCall IsSevEsEnabled test eax, eax jz SetCr3 =20 @@ -227,3 +268,215 @@ 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 + ; + + 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 2967617bfaa0..762661115d50 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -73,6 +73,7 @@ %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.17.1 -=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 (#59892): https://edk2.groups.io/g/devel/message/59892 Mute This Topic: https://groups.io/mt/74336598/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 Sat Apr 20 05:17:49 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+59893+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+59893+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 1589925156383358.30665278133904; Tue, 19 May 2020 14:52:36 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 5plAYY1788612xzSCd5ji6Xd; Tue, 19 May 2020 14:52:36 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web11.983.1589925154464670122 for ; Tue, 19 May 2020 14:52:35 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eTk9CjUJN2Wk73B7P8VPJkJjcek5MMTEHDAGMD8g9DeNXSpfUd9k6/wSR4ohUY3XvJAyGIHp2pWTawzxZXH9PiWmMyHA/HENjChzKp7dYGZccGC0jvu+4Ekb0XY2NSUoS63m6Y7Q1oMOCQqh7hl8TTtZ3okZPEn76NHuyKUZVOjMw4CPh4U++Xkx7gXio6kxK/OddGZyyDIqdk6KkmDX/kHgWtzxmjEA8mGvZ67/oXOPAqWIINK0zeljdl6gdhxsgWOa7AFYiXvqK0h4Z2qOJqG/OM8qLIB2fj/ZzZuc8EjurG5Q8w/KDCNFBPj5CaNsXqQjE6u4AGz6DaySliWgEA== 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=eKEFA2uuqO/N/ZKjYVCrCpPRVfH/BqoPSF1WMOT5bpw=; b=GI03EM70DIs+dgnBZmwSqYEkhQpbbpomFwEU2fhYL3Mco9WX31MzHRZP1DiH0DKgWcZAWfe8s9l+ecUUy7tbSVZ9V7W9J3S5ESGDsupbBWY7Ok459rRbldvqj4c9tatzL4a1cW3n8S7T4nHCQ5+qCNnSjhMdmZl36bF7BjlpHPj1wimURxAq+GaXAMqYRXMsB19lm6LAJKx/rblmF8c6qlRyU/DDUTC873seOpkl8BHWGU7WFUpGwt0e+LOR6wN/BICzcWMhWHE3EoQnwC+Y9X5EpkMU7sh5Lg34Sf6Bf5tHTR/zmeCB3fMwqCTyPjAqeGG3VUJGvnJNKXMX+E9zNA== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:52:33 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:52:33 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh Subject: [edk2-devel] [PATCH v8 37/46] OvmfPkg/Sec: Add #VC exception handling for Sec phase Date: Tue, 19 May 2020 16:51:05 -0500 Message-Id: In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:52: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: fd46a6c9-4036-4ee2-f73b-08d7fc3edefd X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: aNGZ91mxWYwqD365hzgeMehRlzklaaDKmN54e4dTuOYRDQl4yNzofJy7vYBuDWilqtnthIjXt30Lfr7ftkphds6LB4oBc7dDA1Bzjy/sOkYCgf6iSorCfNS3B30tl2KRS02141NDBPTHqE7TFJF8TgyjHpuoiXA6X0AKtQNzPcIzHbToRJPmCKgP+0krl/oyMC3rSsH9WxDHvwiSeH28vXhDT3gVXVso+qRF4KH77txRtw32g8XHxz4J2XxHlckXDbNtFU5AR4HoqCPXmeai7xK/n0jCrE8ykuUGwbpI+zP9IHGbeYojV8bFxdXnM30LFDfrp0OlHrpUu9QhZDaj1WHDIyxHPXCWtx5x1GcYkymxI7lUYos6IymURBRwHyNgB3EjHzP6z/ATB3yh/Vv26yhaudml2y83i4d04d8Mm+o8P0zo6B+O6xoIV6iUsq+XimsETS62SKlHYhv5qXM9ABo/aZSp9NH7AwjGSiXRWFBWwQm8uCxzj+1+VoEilXQJ491HafD3x6s1Qj6jhuOomyIQsC9Nxu3RHNXFSbpbR8vc0hcBRcXrgyle42w72LVv69TmHvFDRLdZ/AqMB61RuA== X-MS-Exchange-AntiSpam-MessageData: DRoFakKTD3m1Ij9BJXb7zW69ANeCmg1+b7yA2mmmMbkNWSMtWpHuQyyh1eejMzgV5zrGgWzxosmg1M2fzaBcLy83CI/iLXiCglLLxZJtx4BnfNxZmPtBmeMGIwVlyNXvLD6CPlz9LIGOAV1Fd/p5wIoGxJPDH0UKt6eFkjt5FnsKPnkdyP6cWXA8hcRDMHuaXjH+U1/eiHk5az/H6K6GeVU8lCy1uFcOVLAD1e76YYBakIptr68HOCoBCRp4UmJKhXBqn6xc1/3LTEaZt5VwMP4z9Bx9/0XYqM4MADVF+IGJ1vz4cHGEqvemW/cy5tdnMgMOQ4G783bxmQjLnDGYFajLBH8a4IkS4StPEFXCIqZb9Rj8xiB002yZzWwr7C/cnPv5CjYhEQiJjkCJff1tFUbSo4tujApBBNeYsF578H+t1+LfF/CQ6UP0fIiHFHahbsaI+PszHobNr9+NiGkDf/DcWgzlyONWZHHYMHxpA5E= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: fd46a6c9-4036-4ee2-f73b-08d7fc3edefd X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:52:05.7431 (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: XVfrEBPpkzDE1Pehbga5mSm9TN5mBp6JKqQIcJIu6OkiYvPChVVoppZegH8yNddf//lCqFaZpwrDoqXfcLy5iA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: wfWraMjVXadYpz3RXRHpi1pZx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925156; bh=rurYkvIBUh3pVTNd7cWyKOyUWMRcUSSukZGrHw55PFI=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=XVuF4aJBfhA13azBEpCJ0aAu1XY5KI+BLapwha0drSqklOyEklQGgDfhvPGvVOIV7bN JjECAvtZdMBxI7SeKtraT6D+NVjaDjou+xfYXGYpEL9cj0AQdWIcqeFbcluUhTgm3wQNg SFn+IhFoCxX9ijDVghxYk31/2jymNxdeRJY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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.17.1 -=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 (#59893): https://edk2.groups.io/g/devel/message/59893 Mute This Topic: https://groups.io/mt/74336599/1787277 Mute #vc: https://groups.io/mk?hashtag=3Dvc&subid=3D3901457 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 Sat Apr 20 05:17:49 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+59894+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+59894+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 1589925157420494.5920220319075; Tue, 19 May 2020 14:52:37 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 8QoVYY1788612xntvSCvZoFU; Tue, 19 May 2020 14:52:37 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web11.983.1589925154464670122 for ; Tue, 19 May 2020 14:52:35 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AgSXj/4iMpI75sdFpDfLmjXzkvucq1AzKzlqZUNTPyPk9y2YpmHjdGlD/4b+AIe+a0k+sEiqS3gU1LWbqx/FFCABFfX/SIXzqgeaQUs0Tdo02Er5DTHZLKUXIzFHYN5dPwR67YXOwy4Z6d4k1fw1SDJI6YWXmBPSSrWA6TAA3MXgE+gnAq2jyPPcnxqVMqeaVJjE7Gn6wh55Pjk+mPTXPW0V3lqcrHQQ2txX4FwMgoACCNzosGsDieExI4D5gVSUvQkrNPBi7lKjKdnttQ9qN3xWLbFpsa9OT2gy4YdZbjCIXLgb3VrHrkx6b2E3AKLp95mtV9N6gFaESy7pyg2GEQ== 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=uTNUDSqZxk73oGCIYrc8BMnR0zSGGSggrRFtzx/2BRM=; b=GuOTSefinxOeeRVDRWrLIrsx5EzMLAOTRgqlLEJHwtv6cOh4Dvizjenkl5U5suuDRpaMXGvJW62gOjyRL84dmjdg1GbeMTWhJtQvfq0KXzjnmMvMD6P+RCmMERegfrLhzvsHowiqr52DJLvk5FR0VauvS4CVogKBk5YfKN6NgUv6K6vK0CXoWoOH+2oiFeTy8J0EW7MkEPFuLufJQV+Fdfqmd2FNjJYxRaTX0SOc/kRjtVKW3ZIVTGRucxAN0ipNXi2dZ5k+3MmCZGGfTjnDxpFdowP5aoh9T/RHZ097P8qbg184MP1jHzFvt9SXb9Hat8I5eZnrZp9X90bEHh3PqA== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:52:34 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:52:33 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh Subject: [edk2-devel] [PATCH v8 38/46] OvmfPkg/Sec: Enable cache early to speed up booting Date: Tue, 19 May 2020 16:51:06 -0500 Message-Id: <3089d2e23db33e4a33b1e91469c2163e16569afd.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:52: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: c5017989-8071-48d2-5a78-08d7fc3edf82 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: hZhIAkdscmu2i9YPbFkQ9JwU4+mlOqAPVaqFmEE1G7ypViQylqX5krogyfQBH5TujdhyrCrpqVEJ3+rTTAKYWeCBQb7HumE9NScqQsHK+5SPedZ3x9s1s89m+6ylQhIK8hb2Y+zIh3gvVFjS+BtjR18Q2xP1zbt/OlG8THB/wwobO1+IezsCoG65s2aPACUMIkUX4WqKnz4pRal9F12J0485tKeoCh5PiiP8vtxMO6+huX0dxHXWTBGd+97U+sagFvTZ4tuBxZahEJnZAXQOtxY4TyMtBp/fRwn0KbILS9iUBcmoGMXKMNsW0C4+uGwInjAH23PZJ6DQCvzaoB3FAYEOdfUczgZp4DDi7acraPyUiq/3YIz5ZThcz8HCBoD68RFvB6ik+Cs7qIeYvpfUm4TOD/G65dRv6Ow12UWJQbprxB7dn1ruv7Tfn2UKECbwMMTNwfiK2XkXpDFrW9HV7BQUb8bBbHfozVPSsGuD0XV2koxIINtf3ATTHoXKCP2JwF0+LEbRxbMb0sXjN+yvcOVx9VOO11ftTA9oUH5XmAKPh8I0QVHfyhqg6lh4DGvqmnN/mEwjWT3ArmfUsVafhg== X-MS-Exchange-AntiSpam-MessageData: 6tHWy0OIxsqgNuKT6b37Hopp12F4LfeO252+4sB9rjWpdchy6i5fdEAeqMJ2KCjp9081jYibO6Kf+139UwxXwPbHlQ84GbEEd6JnDlVSh7Ck6+OuESYhyWKwt1O3QZrDAfT3JTaKYkv2S0sn5RNL5LtKes57q3iCC7FgUZiUj8K814GJ3YfhFhyVbFjI5yhAsGZklrA/luNKgSJRva2K/XeZ853+Tsoltojp14hbWpKFFxvPoe3mzvp7ClJ0rx8XQX2+ATmzT+xsJo5i6fNrKnqx6YgZb1pu+goO/um7CL1b5fCUZQYZM64ohupoynp8dEY0GBZCGnKtmSoH7Xu0TqAf9puiLOC9C+Dp2le9vJPmmXwa0BDhutZySGrMyOj+Oy/eYn/BoPcWBiYQIhnEu+m1ExKWeMVk0kGb5iFoOgdXjGcSj+6vsHjaNhxkBBUGEVxllo989J1+HB/XNJ0B73dzlPlIBPX7V1TkRCap4Iw= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: c5017989-8071-48d2-5a78-08d7fc3edf82 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:52:06.5757 (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: d0ieic610wDFdFumrbQRa/7TnX+hXx5AucjHNTRiMisH3V/kWGmMFDkp6dxMGtRJ73z4eREgtazj0oM0xgh3mQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: wYH39QEdQCuvoj2EkZnjq01Rx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925157; bh=ZVbR/H6Riw1RUIiqcoPvluGQ8ddTXLh5zRKaxFJK/o0=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=Re7JJu/jadEtyQwuN8+7yMiVFu6ic4hx1BBfQg8QhEDXymZPRp1LUgg7bLzPR1AWRXU dun5J9zsK26VBU1BiFnbNa3drNQ0cShuTRLecK7gL8unluuZV2ItW14BR+lnvxCWpeQuU ePvBT8R5gWByJexurYzQ5aUUrctfbtZey3Y= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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.17.1 -=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 (#59894): https://edk2.groups.io/g/devel/message/59894 Mute This Topic: https://groups.io/mt/74336600/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 Sat Apr 20 05:17:49 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+59895+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+59895+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 1589925157852735.976383177169; Tue, 19 May 2020 14:52:37 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id W3wBYY1788612xLQr4OxgYHQ; Tue, 19 May 2020 14:52:37 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web11.983.1589925154464670122 for ; Tue, 19 May 2020 14:52:36 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k7NRwn5ELm6qD7jf/Wxi+C0acWU++7mNwmNq6cHwJdZ72P9lpabxTEFDfeNBuZFFHEJ04QXnudUU0zOgCy0xTz3vbXHQsilsLXfxSRWCLwqCY/cPbo4DmtPXsQB4n9Gi+v1YZQrSGEV9IzncnAtuYPg2AqvwB2wIwhJxSCgoWnO1heYC5yj7pRGlD+bdUGXtDwTmrWZWvi/CPteBJ3w6y9qyOFcbQRFtbyvUgXlEUHC4pIfPaPv1+sgEEOfM93ST731dD2GMW2NXdRi+D3IlwxJ7DPUdm3fFHUcky3Nc0eF8yfROa53r6WU7uCFHr0PjVsTzGaPfnXYUQXT4ORrUKQ== 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=eIlMcsHOhx8qFXHaH8TGYjsdiaFluaWTXfgZbwVlRS8=; b=QKc6XCh6HnPFHN8i2OD3YeY77sq4AoxgIn/IhIj97VAWUhtDbz7tRoEilpPvjQqlBTSljwwT+sW/aBKYg43arpvE8Y0v4dI7qUpqjm2zLAawus5lKm4IzcY3tsQJF8I3CsmjWSeX2m5wJdZgRyHFQWr9QIVG8uVBxdErkf7vnC06AxXjy1YWBcw96NTZq4cgA9vlscSegwAjTBrvq3oB+ZPNHzGAck1tjSnOdRLDp4U3rvSNH41ZrwbcBCP7iuBLivk1QzwffqNLD4HrxFERMwtnXMXnuceFsnWsAf22k90I8k9QIT+UTkp4Wh9zMFFIs39f2NsW6TK/s4yzdaKebw== 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:52:34 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:52:34 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , Brijesh Singh Subject: [edk2-devel] [PATCH v8 39/46] OvmfPkg/QemuFlashFvbServicesRuntimeDxe: Bypass flash detection with SEV-ES Date: Tue, 19 May 2020 16:51:07 -0500 Message-Id: <4d35621f7ac33a99cd1d473adc559aa4a5aad8c0.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:52: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: 7e6414e4-40d7-4633-80fa-08d7fc3ee007 X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: 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: bg6wVZp1jFj4FgR2saWANWZvvLAoocq2gR9pl9/Dxwx07L+Gx3NOUZZowXNFe/DUuhi18Lb9BkXu6tq2BESAtIEnIr3GzL+xL+0I//L1VcOBGUqlfC/LNWZmTL10AkyID41AxkfYhFNtT9+kjcjnCetnyELJExd9C3bl71xWK7cVUshteOPVn4K1YgXu8QRTEu2fpo3nFtc4Uw9Eyz+dqe8wGwBHAkyooXICEis6Wx+aonQv7DlymtHlqIiuUUKcnjVxKgWCNB6/rR9br3QRpB3/1Bq+mSFJWvMHrgYpC2w8A8ri9BTkU5rrIl/hJFO56bRsHy6u1o3jJdEu9RzUgnq5BBZPGwOIyfqVxWCN3i4zTKoyYnpFCPAGKcBW1N/dSAkNGuxlhfR8j74kYptg2UyvOj7M2ddRiA2t1r2MhA5yI4LDhXaKtgk4hdPiW4iHz3/TKp0eZb+Vi9pk+H+WBZpUMhy6ys95aTbxJo9lSW9gSApYG0ytrm5FgixjTIXhH5iDYF5f0ns7DhfsypfC/M2dDAthJKsjdmgs4Pyczt+7IASgeWQPkkxH2uOuvdCEEh8bPHgfpvZJFngPClVXwSjPf4bE2HFvjyftXFAE8rM= X-MS-Exchange-AntiSpam-MessageData: mWOq0wEZi1J/YRsNVPDiSHNUmtscsXm77U31Y9uAADOkRRwlAc5/CpRHQnclNi+vzaznHKUO2DhUXx9mSV5kC0E3rN1zf4eb5ipoRF9zHNk9kLaUNtEKdJLtWTMxUNEiCckZUJadYPg3qea/HE+VcutXql/m7F1GFaO5W1cdW/YwzDF905MQecjTwwvlQ4+khrN9OkRwIw1SKiM49gikVQP0BqhGINn+cyQM7u4bqMXZ1iJi8/YoHVs6mT2+6f8m/eoNEs3X01Jo8vUpduaNOKpXqAEGBsFOs5X3V+XDLCzB6mlBFGiiLpV50nlFfN7FAtLCOmLdl5EWrDSug0OD3atrdgKlqJQYCZmE7/U9zsTVzQDN3riIeLvKCRgV217XHiTzdyvUnInoN0SymOaTuyWzefVEvVTUGSEsbP/4fzJis3RnAmE3IIDR2bauoHnVsxZe/c++a9LPfLP+HqvPUoThl9LdNx3zVUjJUhlE1b8= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7e6414e4-40d7-4633-80fa-08d7fc3ee007 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:52:07.4773 (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: TQIbqm1bwGqIlhPKHuiJ37qruOAQYjYlD6EWS818gkjHANURi6rWGU/4/VTF1HDtRPaWmDg13/mXfhbrrINgSg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: TCsziKuSy1yMyoUhYXkX6iF5x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589925157; bh=3X6h7RHOC+n93Mt50szFi0nYs0WXtPsV9261H1a/Yw8=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=nIWuddxfjHDLajX5FDf2MCkECByT3GeCDoOmmIxRi8NBYo+H2tQI780oilFVTl0a1q0 MMBo0TjgbZtRoZyCgxfXEt8rkHJ43BPraE572Z9rdn7/dOUCx8EbiTT5Cjin/LHHCZq1y FIh3Xy9iq0Zh+0/RawRja9ZQl41nef4OPzU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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.17.1 -=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 (#59895): https://edk2.groups.io/g/devel/message/59895 Mute This Topic: https://groups.io/mt/74336601/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 Sat Apr 20 05:17:49 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+59976+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+59976+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 1589993814346117.39799384748619; Wed, 20 May 2020 09:56:54 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id PRYWYY1788612xsCLKekw9pc; Wed, 20 May 2020 09:56:54 -0700 X-Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.63]) by mx.groups.io with SMTP id smtpd.web10.1396.1589993812542578844 for ; Wed, 20 May 2020 09:56:52 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k/in9DBUigYCeM/Xyrmjz5omJpDIjwPlD4Hu7ao+IDMFs/sY96f8lKBhSJ/ay+IlSWONEBoVeb6WR2764PKzEzKPMK29wEcyAV2PC/Klu/xKu2xywD1+2NHmlFtRnxUi2SSUVKweSr9teOwPxXiRK4ubfmyWNSRqorHSvMqQyt/6G84oBelkVcNF13gBA/hle/f40Pt9zCmzcWsFY5Filfud3GRNho2GG0si/KpNRQep2f57Js3+S8CUfIs0SE2LEDaeGwVhN9Ew86j+0dZNB/LnW9RDHoaM9z/J4PUobSlf9fUk79wb6CQf6FxH/tHkHgVnWnGvJXAApzd1Bpthug== 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=BCXW0VlBNxFKe7TLdmP2duy+TVugjwUt5Ezd1A2+LX4=; b=IyLG5XGXB6Vh8XrUAvUEIHH+ig+dVXn/M25ISeHVbJ3MKN3znbVCLPIHZfjoH8hIii6niZawG3ONUD/Bl/jEyhVSE0m+8DYMoICbxUf/fYqF3dVFd4zg45D5bIeFoP1SKOQoLSepmZETrD070J1nR/WX4vewF6RuLDL18VN/PKE5fFDngatu0YVMy3JIDu4ck1A6keM8jAA1Q5p7fkSS/rTGeMdKGb1XLHAymCm0WElWj5eX9sy8lTckcEW8LIQ1pVkNvHpAJMGRIq3IzLToWeNuO2Du7z1klQJLVIUVqL+9Ju/n/Z5EUF6hUBiicaGkqQamhaMV0XzgcY+ERmAeLQ== 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 DM5PR12MB1243.namprd12.prod.outlook.com (2603:10b6:3:74::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25; Wed, 20 May 2020 16:56:50 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Wed, 20 May 2020 16:56:50 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v8 40/46] UefiCpuPkg: Add a 16-bit protected mode code segment descriptor Date: Wed, 20 May 2020 11:56:33 -0500 Message-Id: In-Reply-To: References: X-ClientProxiedBy: DM6PR08CA0026.namprd08.prod.outlook.com (2603:10b6:5:80::39) 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 DM6PR08CA0026.namprd08.prod.outlook.com (2603:10b6:5:80::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.23 via Frontend Transport; Wed, 20 May 2020 16:56:50 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 6bf64227-f9c3-453c-9c72-08d7fcdeca4a X-MS-TrafficTypeDiagnostic: DM5PR12MB1243: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: a2SKRvW+MZ9uIJwLjmNe7LgwuSUaIiusaCKdOSjJO1Ano6iRBsQxvQiHz/2fhPbtlryi8E1SVC58JIWvrVusWXAImyfguw2dj78epPbV83DfrwTxVqZ4XKCIw7sTXKyQle49e3grDVyRtkkPEd+PFj4iSGTJFSl1/mP7PC2Gn1yrnb9+Q4o+QqBHlQoM5nqj4CRGbmCwzdmVQ6obX3cDCrChwsOziE5MPyBGhjgbMVFKEgy2T6REZBMsVwRlT0F84MOaKJ5BWcWi2O2kfeAZcF79oWnlDXJaooAxNMIw2zNjLZOKYvPd08Q0psW1M/btSUj0gOVmyBjOl9UWmFcigMd6GktTLf8eR+WpzS9RwJdshASkd6ZmB1EYclW2EeX/6A3KY/N4IZB+fbtd9fGUN+duKf/bINZ0BMsbs53VB7F0EpOsGo5YERSqQWJcxHbbKkt083VVBSuBIL1yrEHFWwEwuf+n6CtaEAzErXoYls26Hg9d3M/c+3ZTFNIn9AIv5eoM5hdQytentM9QtDUfrwvYbdP5ea9YDVM6vfskE9aZfly82Hv2RgaWVKTlUHEYteo76x9+ovJpcSXyjsKUYg== X-MS-Exchange-AntiSpam-MessageData: y2ZdOUj7BZ9WHWrrcgdYqvScCoGElCy0wtPGI1JtJahPDV9wGb3+Ng9IFGFi+JwPJCWc44mwUr+2B/i1SUKqtbF1V6yClPE8lQC6Yhz305Obwl/M/fwvYFNwfsPcVBc9cvjwA1Ok7ZabvechsyUKPxDgBWKGdRlJ25jB6hCTfHle+/XHnvN1F5EnM8jSKHNe7bTEpTMqQeZ2jiMS99RRIynRrh4RcK9tagniV6TzgvF1qafsRAZN22DOgc+7iJHxaoFOqicfABLBJLqCN2UsnuhxQlabMRh26XaEEAhMjv7wlVGxH8hyJ1UBOOH/um9Skxej8vj4YoyoUSTya2K6Ac5w5Oq6lSPvxYCEsL+xpjVKmnwDsV7MrtDTfv92t0aUyR9m4jOcKUyTSGcoPVR7DOjEQBc7kg4hN/eCNMifqnb8xw4NBZHbsVoUCkdmdBFPvQdX6BbGyrMdR7+S9UcxqyQI5+oS6FjviiJPSc/NXVc= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6bf64227-f9c3-453c-9c72-08d7fcdeca4a X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 May 2020 16:56:50.5190 (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: Yaxl41bw5cIBNzxK0yLTGSJb/s9V37hCCzRhMrWfl7EhcMgqtEj4c+sObV4abSAGVS2l/xewWNlolQXRTpte7w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1243 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: GLsanZOg4B85OABIWqGtJBlUx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589993814; bh=DaAGCLU1mXxLX4j/1VOUm1P+Pfm/HuiaI4Gj6n7T3Fg=; h=Content-Type:Date:From:Reply-To:Subject:To; b=ngJ8TGo9b7bsjLP3KkGZj7ijgo7lKx9V0TUiUQZ/YSYLT44up/xTzaR8N0/avgTWVJD oJphQYxizCXLe1RC4/xkAYKviqMfSCW83OTrPSXROzq2xTrSvSioN4ClcqlhlFA7OzgVL wbs4VHNmw5t1XAvZ4oXa9/KguRGu0EP42VE= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 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.17.1 -=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 (#59976): https://edk2.groups.io/g/devel/message/59976 Mute This Topic: https://groups.io/mt/74354972/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 Sat Apr 20 05:17:49 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+59977+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+59977+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 15899938146251017.3831702242325; Wed, 20 May 2020 09:56:54 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id jHZdYY1788612xGBf7q1VNOH; Wed, 20 May 2020 09:56:54 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.74]) by mx.groups.io with SMTP id smtpd.web11.1414.1589993812441821053 for ; Wed, 20 May 2020 09:56:52 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YJxDP8r5lHRWJC4Lp+OMUdvh0n8LNKAiYn3pwFOu8jP6xSGuT335WhI3gg+GDyntawvWEDJYMKX3u/HpdyqEvaNE91/Lo0ffPUV2WwRRuVdK/10TS5J55CA1gzG2jcFHW4bQsaOpYp3HP1JXKOJxn6mQ3GWDh7kbjv4bZQ7Wsp+zFCCj8Xp28iOhXhbkNNoWgbOH8H8RFrSZWJQS8VgtnvqrDkwpqt9dKTFiewqrUBIKbcOi2muCqthC6ZjHgtKREVzWUKUZ+sbeuU4t5DoBvp0pHM039NBV3EFeEnj/VzKzUpZJSNCNPzntX4YdjRbP41D4ckPBOVqGfnFJDTsROw== 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=VORA6Rcit0Cs6Q5RnlvCED550RUltaOpv/GoZ+imiIY=; b=GKn6MYJPsxRBg2EIGrWGw4eWZZMv/fFrrJvTJA/g2uGm4AEPf6s7HsBtINu52DMiykym5mQikqv8QBmmBdcrLApxBew/0lPE3nHqRTfaH0vKz3Xlg8apFAV+rVVr8wBVQsvps1ADdTRL3Gh1k7t89Z3Lsdjl3JKiNHU3lNDZd/BWKcZu7Sys40FWbpinC/hgbk6xtK9J0uWOsjncKrBeC2tnX60ZzXMzvtClSBT/VRMjuXoPRZ2a/Mq11qM0/2TSj8d/uZeQZYoi3nsDRfvhpkOPs7JC+jZolddehO1OBDJcwr8Pem6l1pC2A7vo/LJlnhRxnq0XZKNMeRGCPx7oWA== 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 DM5PR12MB1578.namprd12.prod.outlook.com (2603:10b6:4:e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25; Wed, 20 May 2020 16:56:51 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Wed, 20 May 2020 16:56:51 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v8 41/46] UefiCpuPkg/MpInitLib: Add CPU MP data flag to indicate if SEV-ES is enabled Date: Wed, 20 May 2020 11:56:34 -0500 Message-Id: In-Reply-To: References: X-ClientProxiedBy: DM6PR08CA0026.namprd08.prod.outlook.com (2603:10b6:5:80::39) 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 DM6PR08CA0026.namprd08.prod.outlook.com (2603:10b6:5:80::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.23 via Frontend Transport; Wed, 20 May 2020 16:56:50 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 5c3ee4d8-4c5d-4e10-f8f3-08d7fcdeca9c X-MS-TrafficTypeDiagnostic: DM5PR12MB1578: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: bHiUC7uQAAGp1ICosWa8sy4ccmVnpKFk075fppLPcXkSFL91pt2anPkxNO+tOo6XLDWKPXwjtwSJNL++SWMbU38JqugeXNL8fl/x3iukEQ6xA2VqCJJwPv3U4ydgc6xHJZ8iDYaE2DfRFHwexkDpA0LBEj7oMiGWAyU4pgsa01LZnqGlXEVKQlMTR8zIdJtmBd1OJJoM0gGUpPar1RQaCeYuZv+r+GvCaQ7Yo655lSCBeeBpPlsJ43n5IcdzhwDbX1VRPCmGGuN3hwn11nFKCIIVC8hMyFyXB/qWji/11G2WM2kucaComqfYzn32Lta9XC+2cThC79rEEGUsfEXhsDBZ7F0RfYSqELeYInqswgFwQ9vA2y8zRRPkHHSLhexSm5xyeKC8XJt1yDLsRo5BdlOIvB2rNtpWNeVM08l4uRVZki5chCR7lIFydb8sPecJjtgNKikbJcyjGl3Y+sI78SKO9K553orUXBFwOr5a27OcRvt+G0/pGM2ApdNVOQc2K/ZSNnDi48W2IPzeNH2BxZCQ/6Pe1rwOITtdWWndMwhhsWmid00bW9M+8icjsu1v9a0Sj0ECe5/ES/0xvNALAw== X-MS-Exchange-AntiSpam-MessageData: W0SLEcdLpYg3xt/anssUFS/NyFtzTjj9bSmoJRgFziEZkJmyQ/75GkhRPdcA0d4erWd85Ap4WO3UtGGs4lg5+uxtXJAqqncK68bLdRomq5iFdenqb3Ry7Q85EuFaemCINm01g6VE8FRYRob20g2hOwjgeilYy3MMPdHhNiblEeYSSAUIR9TndROSB6fZVgJVh2X25d3kFBIOIVIB8N+w//9k9CEVN0GiuOqaES1q5qlLDfzL6tcc1RHurVMYPpWhz8CIy7DF/PhWX5ffmQcHxtKcju3nCcBGSccBJS0l2Aq2J1fSoPAaOFfGziYCwnFHwe/ELBVIyQEwTaLDJur7l3BSn7FUOTp/DF24+fWXSFycL1vwemMENGoEJJYWkc2TQjXdXR8AqdzHKgQV7AQs7fNKV3HapqrJ7Q9bXbB4KxMwFPsxtOF44OKu6fSBjCF/dNzfAACYeBT9Zo1bD0x7yTsoRSdt25Jal8Y10YGSTzg= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5c3ee4d8-4c5d-4e10-f8f3-08d7fcdeca9c X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 May 2020 16:56:51.0207 (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: Brgl6Z895K9m7iaPxuVEVRH0F7xOhMKH08rsHvBgPOQMbGiBgUnsZ7TBWnxW/Rg8Z+GDZKlGzXQB2dvoqzPX/g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1578 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: 0GAc5MZ4fG1jxqVRwnY121OPx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589993814; bh=bgDYi/dXYLQCjUEm67aCgWNcubwEBSrAPW+Qa5/GEcs=; h=Content-Type:Date:From:Reply-To:Subject:To; b=WN3UOVnOFMAt0m7ztomJwmDmFktzrHEK00P0a7Z86+suD6L7IW14+yiqAAecF9DTqm8 mMvKqBCOKMSDZQFql7ZgAgeQigq6E9aldcHF9s5GCoFnY5UXw0XveXFeYrJw3TJXQKEE/ bGP/YfP8maMLF345eVIRc+r2FMDzMpkAR0g= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 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 ab7a8ed6633a..a8b605f569bf 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -1727,6 +1727,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.17.1 -=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 (#59977): https://edk2.groups.io/g/devel/message/59977 Mute This Topic: https://groups.io/mt/74354973/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 Sat Apr 20 05:17:49 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+59978+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+59978+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 1589993817138761.7953196214111; Wed, 20 May 2020 09:56:57 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id tj0xYY1788612xhAldK8xlwX; Wed, 20 May 2020 09:56:54 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.79]) by mx.groups.io with SMTP id smtpd.web12.1408.1589993813327368455 for ; Wed, 20 May 2020 09:56:53 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nX+x333w7di9Ussy7/TrRSTZEyZwk8OImJHtqxub75CkP+KRLk8TC4HiYXw9PQozh9rvJn7idhAdnLfoc1pd7mW7dRNkKrkt+LoyWkELQJPymVSAwyP4gYG1BBKxSeeLuJ3AKGu38UK+bE4Vfp8KMdd+Dxv+pTm1I26YPOuQRdjaxaTR+Ds5L+57jIOTe2l1CCcEJMuoS6ObVNt6wlqD6HiqZpqruXSa/v6r9UW0zntBxg3cReqhFPlLI11Ap1eAPnvBWFYMYqeh0rxmhp3OHbltiFahlYn+SPDgg50Pp9CjwJgFM4h9cGlyrPEXM5yhtPKpbmwZSCD1QkH/RU0cwA== 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=gEQoAyqIt/x7kj2KvpqAKLnuxbxvh5iZHG0fj5cRr2w=; b=MAFaJL0McET9+SoJb9q1bj2xNMq4oxa4RPZN6xwEmPd7PDp1HtLdx7N/w/qI2Lls7WKpLpTBudSMzjQrDjI2J9rf9m5E9n1vRtX2tW+WS6ndxHFDTcgfGj1mmZpS8GUcimA1BiwHq5BMFO5bht/nbEM6gA2Jpt4cEfSYOSpN7h6OzIJRaV6smsiVIHmD+f23kpQrmvwmVqlWpicl9EgLXrplRxtavbAh3sFmmQPK6Hn7lyd8qhd8fPW4B+LAilhqLQZbBdL6xuGAlWq6/sr2/D1QyA2MAIkFOjoMlMvClppLweboqrcoAqz20l56BxSWxxoKaMT65q0fiBzb8P/gig== 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 DM5PR12MB1578.namprd12.prod.outlook.com (2603:10b6:4:e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25; Wed, 20 May 2020 16:56:51 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Wed, 20 May 2020 16:56:51 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v8 42/46] UefiCpuPkg: Allow AP booting under SEV-ES Date: Wed, 20 May 2020 11:56:35 -0500 Message-Id: <9405aed8ea6894167ee83bb1a7c95049bec1dea0.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR08CA0026.namprd08.prod.outlook.com (2603:10b6:5:80::39) 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 DM6PR08CA0026.namprd08.prod.outlook.com (2603:10b6:5:80::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.23 via Frontend Transport; Wed, 20 May 2020 16:56: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: e93f1e2c-88c1-4533-b93c-08d7fcdecaee X-MS-TrafficTypeDiagnostic: DM5PR12MB1578: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: OiekhVafrTpik1ANw8Bv5Irp6sL13o4JH0rWoYPwBn+rhlBYfpLw3qCB/+cvunnCfEG1P0D74/GBS24UfXYvWl096z4SvZEJ49YERfsoVSZ0drw5iu7116VbyyXCdFpM1T2hFbILdBLyeF+96uoxeFT+UQWGsIKiv60be99wlkSjSb/j+Xh7JhHsDTWgGRY9FIrGs7QuL/WI6LxAGY9Ru6v2iCV/MMxjP4XVgAibGJqssOua3Mph96dsvZvPVPjZybiPCy7urhXf9zuG1TdQSm+KZYEStgjWAFteOEXKTEoIoLl43tYbLA/8V4C6v62lkxxKA8TWvFSCfq0eWLkPDpn+dYKDTgLT8Fu343hv8wiiZulkh/ZEbS4UUTYMsFlJsU1AjmUoT0urM15XQTo9hmdKmR2ixAZozIMBghvNz6EKSswyT+LAFANBa2MvSrVVSRWy85IgymNsS+4xoJghhoeByq1upEkJxyiGxGLM4NhEL4AuaV1P0VkoP9yIJyeNXSfcPieWUzIU81qpwVkw12VSZHuRdX3UcQ3rXZxjd+b0GInaJ+O+JXcI5KJOKj3cwYJC9kCBTOZJ/KgLCjI7bw== X-MS-Exchange-AntiSpam-MessageData: kqU9qMPw7d6KY101mWC3BDekpcbx6MLixn2Lg720RkaMPJcg7PhqDsOMZcjPamBfhvQB0jsQoDPbS79Qf2eoxfX9YvrFhQ1ZKJGzP3UJa33woRD1NJkqMYUYLS1XYwrcj33a2195L2D1UQhrIxxVfQcwOr4kN2+Jdq6PSBY2YkDFsOGPhXoF0ZI2cywe4QQuDaSFqpl/asFCRLxOpWLhNmOpgcJIaNQBUgzTczmbCFbYCp7n+Y4IxVBk4I3c5JTLcryfY5lhoXPkV/UKWdOT/6GDRw9rUaSLO3g/mdI1M8nHGTM7LY7S6QlMZTfJRLsze+SE+iooTpND4dJPJlH5IZ0KazMERUouuPg8pW8C9H++LPHxQbluKiPzpf849CZW7rhr0nrPA8nCrcZzrdlV6CWDNzRumYmZ6qd1nqY7ZzR6OewVHluSsvy/WbqcE51IT/+6yyHzE7uNNrYorxu6Y1Eq+5F4PaKv0OHvd+znIzc= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e93f1e2c-88c1-4533-b93c-08d7fcdecaee X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 May 2020 16:56:51.7474 (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: XQzT3CZiwYRApzTANQRe69r3NtZaB2Ge+cZ2w0al3Fu/z/+lWPuUzI94veKooU6M3aHsXOh/KqsI+da8eEh3AQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1578 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: lj8nMnhsI4ANcSnh9u7Ayi2mx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589993814; bh=W/0h5a6ymNN6XEBeEMBzXi+8dS8tIayHbRD+7IZlhVc=; h=Content-Type:Date:From:Reply-To:Subject:To; b=Fmu8ZXiictecoxw0pw/6o1SD54eQrnyWNvvbjr9sIURutqSp2fEeRJhK0BVojlbAMzz tzMeGSz6wrlLdU9mrq/kp3x0U03h2cnOsAe6fZE+4XuBHiVvUTL2G+VCqN9gBmGQN2yPu auJ8j+2TMALRWUR4OZuXf+46HL5EqM2SoJo= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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 | 312 +++++++++++++++++- 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, 714 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..f0cbb3763b5d 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. + + @retval other 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..19527300ff3a 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. + + @retval other 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 a8b605f569bf..aeab575bb525 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 @@ -314,6 +317,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) { @@ -610,6 +621,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 @@ -671,7 +788,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 @@ -778,7 +902,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) { + CpuMpData =3D CpuMpData->NewCpuMpData; + } + + MpInitLibSevEsAPReset (Ghcb, CpuMpData); + } else { + CpuSleep (); + } CpuPause (); } } @@ -891,6 +1060,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 // @@ -917,8 +1089,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 + @@ -971,7 +1144,8 @@ BackupAndPrepareWakeupBuffer( CopyMem ( (VOID *) CpuMpData->WakeupBuffer, (VOID *) CpuMpData->AddressMap.RendezvousFunnelAddress, - CpuMpData->AddressMap.RendezvousFunnelSize + CpuMpData->AddressMap.RendezvousFunnelSize + + CpuMpData->AddressMap.SwitchToRealSize ); } =20 @@ -992,6 +1166,44 @@ RestoreWakeupBuffer( ); } =20 +/** + Calculate the size of the reset stack. + + @retval 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. + + @retval 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 @@ -1005,16 +1217,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); } @@ -1029,7 +1247,31 @@ 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; + } } =20 /** @@ -1066,6 +1308,7 @@ WakeUpAP ( CpuMpData->InitFlag !=3D ApInitDone) { ResetVectorRequired =3D TRUE; AllocateResetVector (CpuMpData); + AllocateSevEsAPMemory (CpuMpData); FillExchangeInfoData (CpuMpData); SaveLocalApicTimerSetting (CpuMpData); } @@ -1102,6 +1345,50 @@ 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) { + SEV_ES_AP_JMP_FAR *JmpFar; + UINT32 Offset, InsnByte; + UINT8 LoNib, HiNib; + + JmpFar =3D (SEV_ES_AP_JMP_FAR *) FixedPcdGet32 (PcdSevEsWorkAreaBa= se); + 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 wi= ll + // 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 loc= ation) + 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 lea= st + // 16-byte aligned, so Rip is set to 0). + // + JmpFar->Rip =3D 0; + JmpFar->Segment =3D (UINT16) (ExchangeInfo->BufferStart >> 4); + } // // Wakeup all APs // @@ -1669,7 +1956,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 @@ -1728,6 +2015,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. @@ -1786,6 +2075,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..e17a351e5cfd 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. + + @retval other 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.17.1 -=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 (#59978): https://edk2.groups.io/g/devel/message/59978 Mute This Topic: https://groups.io/mt/74354974/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 Sat Apr 20 05:17:49 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+59979+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+59979+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 1589993817423411.02471948768175; Wed, 20 May 2020 09:56:57 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id tuplYY1788612x1dKxLvheAg; Wed, 20 May 2020 09:56:57 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web12.1408.1589993813327368455 for ; Wed, 20 May 2020 09:56:53 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lkmqfvP8xHs6WseBy/eH5uxfVv3WpYLeLLqJOsAqrUPaiC6kSbqBxkGjBYEEvRfcwu52c2Cs8X6JJx6QU/Q5srpXC9+JT58vVBYctcsF9C5N4N+zw39HAdLsXhKWbGIm1GCy8DnLCp3GtXpRgibaS/bXNV7zBXpaoWNX385MIzXU1CgnoNXj5BbciDkOhG+OR+V0I4gmORrpUm1LjEJGVUXNu1PdDuplIjKaqVszhEdR+Tr7qPZ9v1/y4F75CB16ar+OiIDz8D1GWBBpC7SQ9xEMv1uIhQcZdjS/CQ92MCXjS1XIYhEfWLHM2JNTQA/sLlhMC/yALzSz0LNl3gwFWQ== 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=UK0zJ7oKdKIkfCp86vjF1LGBpYpwKKwnd/UC+Y3g/MU=; b=K9SE297xJxsWbco2cgtvkJcQpEfSezYDjqYDgoYuzF8WYVU0/qlXLrF+02n2lU5n3qNsGyzfJvrejbxiMEP4fPSRsInpUBY5kyYtHr78Pi517aJbU1tY5Yt7cezwp7RoHw9yx4GrI9WKZvhho0arJKTjGCFre7A2vBfhHlv4h5aI3lmRL52/T7UcYTpGobmJ9d0zNgUSncToM1OdPHJ14EwVaq8cjIZJi1lNDK2b5D0JbMxCBtzTldH+vQK/SETakhIpIey4Ur/N/FxyNi/jDu0mfE2Uf5BxnskuMD24QGodJOeEUgkLeZnMLF+BcUBci5YD0zUHBR6oHdQZ+azdOg== 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 DM5PR12MB1578.namprd12.prod.outlook.com (2603:10b6:4:e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25; Wed, 20 May 2020 16:56:52 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Wed, 20 May 2020 16:56:52 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v8 43/46] OvmfPkg: Use the SEV-ES work area for the SEV-ES AP reset vector Date: Wed, 20 May 2020 11:56:36 -0500 Message-Id: <3b290a5ae8f104bcb03f0f3a28f9c101cd0811d0.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR08CA0026.namprd08.prod.outlook.com (2603:10b6:5:80::39) 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 DM6PR08CA0026.namprd08.prod.outlook.com (2603:10b6:5:80::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.23 via Frontend Transport; Wed, 20 May 2020 16:56:52 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 08a1cc46-ea68-4496-73c7-08d7fcdecb66 X-MS-TrafficTypeDiagnostic: DM5PR12MB1578: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: vzDNgS1m1QdmTkSEjZTt729JmRDcaLuDCOGu4kDVnqcc8gIsrHaclCF0dRc0EYm8cSvg9kjO+Daml+qFox/I14EsWr2Uh8voHkMtz4Mc+Ch8uldw84s+xfXQd8Y8h8Mt1plqUyeOqP42e93XvJsgfyhO2rcChCl36l9mHCXJaUeDFyvm987ogjZBs8/jdjlSmuCmC7GvO+9X27uvUF4GMqJ5l3IsjpEZPSZ3lnLeK7kcDXJTt5Uya6sPF2iPDvvT6uTcZKR+G9EtsEljEpUalck5rA8x2SqtalUm55jfz2Ftv6LfWjPJAFvXLNpD3jlcFMoWZEZwfJtdQeNnCStKvO+qiyLxIkMFiH9VGI/FsGDt7MS91+Xt9ZwavR7Z4wm68MdidCifcyN9HE3xW/fkqGqniikeUowfpBsTvVJDUaT8ikK3Av4zzt7g7fRkqnTPwvruudKmk24xDBvEKAPlExRr/AimIK9hgJ2/DvczNrix43lrlQQ/1ue02gmEVfD4lI9WTXgYC1q2HmgrxcnPA+xjl0rpCLG/XaZDcc3Sfj39nLGafIJyDJhoYEADRzvp0lJSwWBaQ6x8QErk8Ou/RA== X-MS-Exchange-AntiSpam-MessageData: C6gvExgVd/56gr+0X0TXuTrTgQ6b/2n8QZNLs+gIXL2JNzPYdZNrt+m3Ulm7aMWr0OeknGgqh/Led7rcRVHsoreeP7tTO39ho6IcYnJXqjSSL0jPG6uoMHYQdmX2hQz5/VQ6Jxej/8O0ocM3mptVUT1SwZCzkFwoVIrZ6SqY06Ob2CEwFTMM827cu85saf5nEYv/PzXwwwiFhMo/N8GszgIRVNQiKTbXyGhEAm958XBzTWijABrS3JD9UiBYCWBzYCh817QOmfc9DdnKhLCZiJ1O/lUhwa9z9/F5/QOgTv77x6clWLu8ZhzoG8o2znlZYRjixT11AcEjDnSuiUz/qGlTLspXUvRjECo3eQ+mCtNUYJaLxlkyvOfisp8IjCtUt131VuGqjiuZICjsP7osjnzYEMXf8zGaN0tkHcmcJ1OyIZg7pklV+x+icVCTYbK7o5FkCUYoCTSDZa+lPMWTDpFH6P/wPj7RsZ2DsUGJJ54= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 08a1cc46-ea68-4496-73c7-08d7fcdecb66 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 May 2020 16:56:52.4731 (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: vpuLy4hDv6Wou6QzGASAyDAsQ0EBH4LkGkLxnKJrtFffye6zaHIpP53i8uYa9eTzuakd/CSgX+QQHKbgf9Mk+Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1578 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: K2MtFS2MiDZ6ESImAkohQENlx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589993817; bh=xQFGQrvHsuZkCUha9W+V/3C1KJ7aKEIF79E95CbVJNY=; h=Content-Type:Date:From:Reply-To:Subject:To; b=TyH79h4s7Twg877gOtK8CSvCXskPuJxf+Xs0Dhh596CxayO3CMnMbZXAIr8SLrsOl+Q rzcpUSd9m/ReGsbqdFUAWnASjj6ktNvTIwKFct/1bcfLog7tNWtjpBIDiNvmOZM6IwMmZ O/LZH2JtA5HXlFnHMDAAW63o68lb6C6oS6o= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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.17.1 -=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 (#59979): https://edk2.groups.io/g/devel/message/59979 Mute This Topic: https://groups.io/mt/74354975/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 Sat Apr 20 05:17:49 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+59980+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+59980+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 158999381836247.25846189432059; Wed, 20 May 2020 09:56:58 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id mfPXYY1788612x0QcLU85nGX; Wed, 20 May 2020 09:56:57 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web12.1408.1589993813327368455 for ; Wed, 20 May 2020 09:56:54 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ye+yroEbJ6CrBSM9GBN8/tsjUMCUVc6Bv+9YnqdJjTsFq8b1TOoWe34REVA4xaYe/issHSkQZdChzmAQ07x8MN2pALRDh5UiDDkMMjfRq7agxklZNXKp4gs7e4l3zMUwAeFyv9asjI3OGIJ74hcFDNE3UxrnQMKK34SoP/QlUzhf4hys/DNkDv+CNgvCRnatL3oTx4djJ9dF5bUz/YJBeZ0q5pY3/54uFa4cDJsV7+7ChdDDTRNJKZntI9TlP3Y5/bX1ySgV7LI61+kfoiQ0JAJAIEMeY4wn8HcTsTMyxaCNE/MysEciYRnJSZagNtOKdhct3IRhjYuX1KN+0M5jzw== 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=h/HsJtfcCrSFBrqeh53xWY83LTIhtvHdgADj1Yi5fEg=; b=ivI3lLvjlX/89++8Q9GsWSFFNQ5zLypLhp+8HoZGnarPqzeOSeYFf7W6rVnFIDKegyQBJB8sThKiOeAdWr7plLpaYW/Lm9Ua4QI0DXQjvw+sXUT3fxWtUsLlK864JJWqxIVVhGZIBhPoVaPD9qfX6IdNZGnYd7rNQuxgJVxOo468Q0PB14qRa83QeP8oQIh2VUyNW8qBFxWmXgNCG6gOOEHVNB6GUzXYu8TQ19tPo/GpjJ83XT5+l6fjWrsUxHzJDEt5uAqDTaaXRDVg5T94bBsEEsX1Ssa4YK6E+EGwLHz2SClC6XV2/Mszokm2T+HeZgEtwq7O3zvbqudBHQzA+Q== 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 DM5PR12MB1578.namprd12.prod.outlook.com (2603:10b6:4:e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25; Wed, 20 May 2020 16:56:53 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Wed, 20 May 2020 16:56:53 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v8 44/46] OvmfPkg: Move the GHCB allocations into reserved memory Date: Wed, 20 May 2020 11:56:37 -0500 Message-Id: In-Reply-To: References: X-ClientProxiedBy: DM6PR08CA0026.namprd08.prod.outlook.com (2603:10b6:5:80::39) 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 DM6PR08CA0026.namprd08.prod.outlook.com (2603:10b6:5:80::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.23 via Frontend Transport; Wed, 20 May 2020 16:56:52 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 1ab7a1b0-4d60-46fa-cf97-08d7fcdecbca X-MS-TrafficTypeDiagnostic: DM5PR12MB1578: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3044; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: ZElFWV6I1y/SGbGOMV6gtEcb//4VSYpGcIzm1wSKk+y/e5lrSuk11QNxe5i+ulAh3PyWtEIlo3ep+mPtoT2JrQzZz/UrxAkVUKrLlZx+hIGowJ9qR6wFswHn4AkY/zEiwJAR0xZ1KDp8e5EOn3YJD5CZaRa7NY/5Sv1xZWHx1srocz2o9SVKBAkvfhnWxPg7iDlSh9ugVXKHVFfphJC/V3aEp1+ljfAgiOpAOyIEwW+YumX5wf7sG5JVxOE8XZhTFBV/KcqlQFW7XBGQC8KyCs8CzE5bRiuBAeCW61OmuYjx8Nq90sQqN4OR1w3VvG4Dh9rG3V3IWDLDZFURavwg0b43GrrbG8ivf5aOZmf86rT5XnXGXjaH5EKgdTcIpnt1HMiKleCUr7+29HGEVKdcgY0ISIwUaGUqDyjTmtVF+Y8hULAxgTMTFcF+EISIVAEBqGeqy8WGl6BEhOoIkjzbYCSl1+5qao6VZFMbKBin3oCuuBCzialwkDl+aEi675PxhfMz5JIAyLc3ccHjMPa1P7k0SsM7Jck9Viq4uvbaBny5z86QXxEOAeKMIsK74oq0NhXYhYBMi1WUUVMXK0xXyw== X-MS-Exchange-AntiSpam-MessageData: hvoV+NEVkMHaph7y3dX31hNutISkg1ci7ukI71OkEHqXxkdaw8vftKJbQqY2mLcU2uBxByXS+Z6zT8ddGCfeZDEi3/kuVcDsMDptGvQaDZE0KgI+5cLtmEKEhk7R91EC9aZiCZcH5MVMim2obDG+RfK9OESE5C0zjwT0g2ROjnLgN2E4A7CHZE5eVazXAHdDu2Wb5Qr7B4YwlAziB9xv7e8z8x8D3O2JP75VsAmg8ebBnbmVHl5jYxINm+78+V0EQGJ9jfEYHV0IaE7ddy0iTmF4mJX83fyz9Qi9gM1DRWvAt+daN2tr0gr8kKNt9Fnv5asMOOHLb0/YgRjFOm3D8KJLmoSeDvSMkJTAEmbuGvVQaHC+BMsAe2bzgMjIcS8hIuSy5rjCWsrJSukCCKJ/lF5FXcqDtuolQi7JX+dBS3RVKn8jYAKlfKsBuxJ59S9+Rd5wciTuO4exRPOAfdwaB5+qcs8m0I32Y0KB2YBea4Q= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1ab7a1b0-4d60-46fa-cf97-08d7fcdecbca X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 May 2020 16:56:53.0938 (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: Rk7ESgVLPyo7ODTJ/K7XGmx0QHSx4nqLP/7xphygvvdLdW+Aq9PoraX2eWr97ZE2XknC6DMbnCLJ24gqlHfE2g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1578 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: EWEj2Qc4NbMvTt1Z7uKJIrlKx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589993817; bh=LdKksGH+67C9ga6mi5STtjCPVdfuoF8F1FwP8u87Bgg=; h=Content-Type:Date:From:Reply-To:Subject:To; b=WnThqDwwHKq01Ll9KLfTwaOM13ynx3Tv9/TH+fQFZ/vqNdYc6dacNhFRIqnmgnRq7f/ nItcEnBFeY4gce9IWbXWXvSgzXkpSu/+rfCECSIhJtwJJfTLfGRVrVf33eVIGl3Yjc0ly ZPZkoZQRm6ASGEyI25yncnbh0gvEfBy/DT8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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.17.1 -=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 (#59980): https://edk2.groups.io/g/devel/message/59980 Mute This Topic: https://groups.io/mt/74354976/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 Sat Apr 20 05:17:49 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+59981+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+59981+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 1589993818889283.814109769781; Wed, 20 May 2020 09:56:58 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id QrY8YY1788612xAenKdfEOiU; Wed, 20 May 2020 09:56:58 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.48]) by mx.groups.io with SMTP id smtpd.web10.1397.1589993815501238004 for ; Wed, 20 May 2020 09:56:55 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bUlylAbGzb9flFoJ/V9xirvzy+364C9tPOh30bApug4EJHgieRRqQ8FI4alU8EVEiA5vX3cxRlb9bFM/aOYXqeCidauGt+lyU/YBVe8p0DeJZ+y0uvUz0f5j1wfX0xz2fCFQwjNmPcEPfKKpaKxaYmj+UqMG0NLHmt5HkiuHY8vIvDE5nTLAdhEfSlZefyBJCKqAHMrLPC+vdpdRmXoq4bM1k4N4bhpESHq74x4TqJ/fXGFaEwQjIwBQXq5GJk7Xe5Abs/ANsvN2/lcL5M1NX3IySS0uN4f9fFryEMkK0COP/6A6+1Cjc0xgqNcHKDyBIpLaQ9HINQE+I6S5vBQXUg== 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=qGad29pUeQyKFdiv2BnzarjetJ7d2B+2Lu1jiTkN0fs=; b=kTnzGk3FCjmPxVhUtXyedS+a1CE6Ev3zLWCFE5JD5nIAEs5L0xwqy2HRZyrM7bK9VoaVhhs8Hi4wqDgUKgcHzcs8rZ8psMRQICu0XKfr2GwOn2oDnriRHcn7RMGtkVozw5MeJqnvxD/DaRUOtKus/BPqpz8rwaE+qAQ8ve3c9x4tuGshtwMyU3xryeV7dBG7tvcsDW05b8q6geiIbXIQY3Y7r6h6epYvTPPhBrNeq2c751DGhEWlLd07DTx42HKnF/XztaIkF3P/0vQ8PPviR+sk/JKkAX4zVEkiE9CqG9jAAWrPoDk7s1jviVitNPYmbT/A1uRA7z54+wye1ctErQ== 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 DM5PR12MB1243.namprd12.prod.outlook.com (2603:10b6:3:74::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25; Wed, 20 May 2020 16:56:54 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Wed, 20 May 2020 16:56:54 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v8 45/46] UefiCpuPkg/MpInitLib: Prepare SEV-ES guest APs for OS use Date: Wed, 20 May 2020 11:56:38 -0500 Message-Id: <97e958f889657a6d7afbe112b472cf69faca81ca.1589925074.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR08CA0026.namprd08.prod.outlook.com (2603:10b6:5:80::39) 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 DM6PR08CA0026.namprd08.prod.outlook.com (2603:10b6:5:80::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.23 via Frontend Transport; Wed, 20 May 2020 16:56:53 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 6d2f56c1-1390-43c6-7c9a-08d7fcdecc51 X-MS-TrafficTypeDiagnostic: DM5PR12MB1243: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: lIj2BU9wO42Qzr/87l7rx0bDUTk/btRuq1PnOBQaol046LEj3tGnRmBHYwYJZkwrJN19EmCMU7WQkD+YNr6tdB+GB6f2fK5bSxbhWFBtDX5bIzTEWJcTYKNSJFxdutRoLNEgZsDVZ0M9WQUhHOen0ZP0msKyS8wJXdrfxsOozfrFUzroFhEhJU5FYevz2PM6UZcnPF3m0gYqALeRb2X/sqfuAIMm+ODnRRemAKbQY1aVG2TYlz0bDdIkU4fBVulowqH4S9ugVJm3n7eyxR8cGs20Pgjo8S3K+nXSTIpldaWIGXxoAiozIPP55k6cK+iRtqUGHFWTYzNTivsCPiJsI0dvxfnple1aoHDS4zaDPEOraMrIq240I5GZepqXaRNXsMTrpw6ckPklt0FX4KTZyECMnt+ER+gQ+f2O0D27+WUPFLGcmhvefFo4MhUa4ChBacr/pGHMdsJIqDBxeiHMHa/QPB06TSdJai/C+09pQBrTU2c/QpbYQ0TbAd+4/rZzBZeNHD4mVRcNiu2bORQ8YWBBrpg6aliQm08Octgb3nnj5QEtoEPr/mmNya8Olsx3Ca68VqKOrgKGe4cZBCLE8w== X-MS-Exchange-AntiSpam-MessageData: /nCi693khW6WxQhRDRZBiGzeCN6JTqby6SvsZl9kFNCcZtWIWDyijESYDsbh9vHIT6LHr69pvwl7RNbJZ1C62Jr/lTOax5q/z1IDNdFdBtWRk+ImcmloJafVzBOFB9J3GMTKW2Go2CGFwOh/tEHuHsdwvskD82ORE0cUQRJZtA+igaHQC1W7UBrNCUzlE70uiTYvvlmiT/mx8EqsJLKY/SAqXJE1dZKPyjMFS5yCJ8sbcDjC/GTpGkn/nMk1aBXVyvh2N5a6Q4FG+YNANkCQGh2AZKk98wrN0d74PW84OXlu38qzMOimLs+Jefy2xI+ohx/KKxRZ9R7o3bCqW1aLuYiAobIhSJ/fjXvRDyWuC82dmNi1LrjUOHPkUPeTVhwHv4y8/YDLJK9ZaZFmref9GWglxJ+Q/w6Xw0L+EUOyPmjkOyX1RQjZCAl8eug9MKu2pq6Cj3nqrt2RhEIstl18LRhmFqwxRRanZR/dJAdazyA= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6d2f56c1-1390-43c6-7c9a-08d7fcdecc51 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 May 2020 16:56:54.1544 (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: 0GOQmpE7Ab3pJ8uFWVGTsrtNMma9gRVrVvyDRYdOmcgLRpWXU42U1XPzS6wOHw9W4gnDe6+BBLH9r6mzAOwxrA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1243 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: wJH0YvYPP4UrbP0KiL17Uw4Ux1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589993818; bh=b/CiXBbkWDuD8afMwZq88VtOdKDF3ZZBPwMgn5Au10g=; h=Content-Type:Date:From:Reply-To:Subject:To; b=q9thAPdWVmlAbJBe/G1M9mK1OnqRDvgysBa5ElyL+/LyiuGCWqDawSp2Pp4dmJ5IDpg KIBfUUf4VBVziytT94pAPpvo8A+5pf/nKDt7zpwx5H6ibqtzecq9YEP4WXccuPeErIuDo 6GbX3Rmr4naapTAe5CaNvrSDL19D/BGOC5E= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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 f0cbb3763b5d..f576937890c9 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 19527300ff3a..869c895ef27c 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.17.1 -=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 (#59981): https://edk2.groups.io/g/devel/message/59981 Mute This Topic: https://groups.io/mt/74354977/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 Sat Apr 20 05:17:49 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+59982+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+59982+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 1589993819047447.92244000260666; Wed, 20 May 2020 09:56:59 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id vWBvYY1788612xQbMnCuzkJm; Wed, 20 May 2020 09:56:58 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web10.1397.1589993815501238004 for ; Wed, 20 May 2020 09:56:56 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gGUcByKDV6DeM6oTcKYOy9sryANTiAEUmlDKURQPayDc8buQ0VtSxZB+5o5IYh53KlbtFvErLfwgGnUvWMn3BkC9xsXNGnKJdL6HLZ3iZqZcwGfo7/nfpay7ysE1q+Zgyp0dhWLbWMJQNaDeLKs78moUUhrgKiKKLAWUzufPe6SunJdrGHQtC+G4ywkKrtFdvplH9BmQJ7AdHT7a58YsNiJscWuEmSokEhoBMiZcmMfDXVjExRCJuZHI4gFTJlnvIjglPxuBSyy2GTjIJ/zlNOvML2L+bVRAnGmjVW5wwRZzvqsoot+I2sq7ow1y5m8X3oHYnT330WJlRObBxJC6DQ== 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=EtPBw8qoVwUSlUnL2A4o1t56D2K/aJtl0Gucpb/5muw=; b=ZeA0JxmuJ4fXRbjjI+Hv1ew8FyCfUy0d8vZErU9/xgwopAqf0AY/aulxW1PBC+fKITIUfWgyQJH1skPH5VJwmFBz05/ThiV3QSejmUh7chFDxdzJPoGtExaZb72t5k44eoTMneMpfPFf9m6QFDFCIEF8JGHlTZm7WPImg3SXSk6YVnnOoYroN/I3XCrF/0bcUG5EV1upAfnbJD6t1VKDEsbEfqQ3Rf1ZeV0ByVUFbveBGT+QK3vuWVoW1tOd8co/xX9nWWZRNQMKHKU0RvlN6iftOf0l7qUMsRGFMvwZVwxF/ETLDB+dAoI3IryOxiXr5t3yX8sWk/HOHT6jZp08zg== 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 DM5PR12MB1243.namprd12.prod.outlook.com (2603:10b6:3:74::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25; Wed, 20 May 2020 16:56:55 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Wed, 20 May 2020 16:56:55 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v8 46/46] Maintainers.txt: Add reviewers for the OvmfPkg SEV-related files Date: Wed, 20 May 2020 11:56:39 -0500 Message-Id: In-Reply-To: References: X-ClientProxiedBy: DM6PR08CA0026.namprd08.prod.outlook.com (2603:10b6:5:80::39) 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 DM6PR08CA0026.namprd08.prod.outlook.com (2603:10b6:5:80::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.23 via Frontend Transport; Wed, 20 May 2020 16:56:54 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 827d0b4b-a363-4bfb-775e-08d7fcdecce1 X-MS-TrafficTypeDiagnostic: DM5PR12MB1243: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2449; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: E8nKeZrMHM91TKtC9jyin5MPL1QwhYB2jr5Qart99XgL+o9RLpawHj0AEgzgtuY8cge2lw23BrLSFiKF+IDJyqzzBUBG/x4ibt5BrOR+MuueddfOoZYUSBdrGx7O0RIeuHd3LayzlJLnOBVQbKHzJtjJEKrz6601AfLtX1S0jP+8KJcoNH2ZinyhYqQTku3d+/o1Tm69UzizqfYpc0ibz99fOe4AG96KjHLDDXUvX+WoOZPh6uNB7IQ8264yVyEryorhy2uFMxVDDoIsU+CpLNPalyOZ5R1LH9vNGEnkhMhJ+RethhghBpQbWek7RNZzxSxZRNj68cpq8f+c56rlKsV7gONeGCa7yTQdZnw97QZc5NfCRIMzWf7zIuRF6Jp6GqJ8bpi8CuK3IqtJjJA60pe0g3Uz1ZAFSEVQV+WMumZoitBL+tqSsS+FPKSHPde14Neb98HlgPMPePpHQNGk3GJnDybyh+ZMwWONTHrwpB/wYiDry9oc6NnqMwFqV1t93jsRm3+2Jtvf6mKmJDbbUjZWiAyUzgS/qn9ZRHFPyciGWpmLMhd5TEmC0XZXNnL06Fk87xT9xv+FljtxHsq0fw== X-MS-Exchange-AntiSpam-MessageData: HjW4tsxxqwkG5F4nYjEfIFzpK1Nr0wv3CQe+VypRjDYya8fiMVXfZXMNmJjxQh+F0JYtb5KJJFC9dhHN2bg7416G1r03Smy0FVL6G96XFlxAHIEU4dXhiSFXU0hK248nTDkxUA+KLGGyQSgHbdh2X+aBe3cpH7hVCeLikmnYGLejMa58JH77h61Cm3P4aUg59lgaWagUzcw9C5B6Z2xqc4gd6BGqfXQhBoPcw1TX5h2zjP5x7a78fHQwazNteIvlyIBFCiQ5Vf8PCWL3kriHA80LJF79nIOsf4TWqVOKCxIQP8z+xmrc6vmlAKp+gDy0ZI9N5a8GtF3I7Koa5Y7NfVjE24ntM3a8UtmPA26lrJhbpop8kAmPnk7VVkcQ3O1bt2lnaeT0RAzoprsH+rg885GowEO8nzM0ut3u/HTrXdRNW5SsSws25MFN57/QEQFlfNRJmwgUotabGuVKbtXsLPNLO39NmLEKS7D2shU4c38= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 827d0b4b-a363-4bfb-775e-08d7fcdecce1 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 May 2020 16:56:54.8671 (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: e1DMLia+w0cf3Y2EzMzJ7iJrqWRKMtu/WjYOPr0AIzwEurGv0P/dApuP3GFr5wEJEW4ZHmUqAZfnjHI7FEWSvw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1243 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: V7YbodoGjvlGEbCUqoPOkixIx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589993818; bh=ChWclQzR4uzV23YsVBweJFIBV9MG0Wd731vHzhAeMHE=; h=Content-Type:Date:From:Reply-To:Subject:To; b=qRfSOw4metmnKLbT3sH28j9KkjF/A8TN2ZINLlJfTSuVpVVSKmTcEhUP8SxiHXA3dIw v+PhBt0A/B9bmfGt7ptJmR1LLVkZmP48aWtnsCkzPEE9y8mZZSzWi0TpT8HwKRKBN+p8S OaE2dstacuuEH5H7+g5apps3rwFlru/hzRY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Tom Lendacky Acked-By: Brijesh Singh Reviewed-by: Laszlo Ersek --- Maintainers.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Maintainers.txt b/Maintainers.txt index 896ac5821fc6..76f336b7dcc4 100644 --- a/Maintainers.txt +++ b/Maintainers.txt @@ -441,6 +441,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 + PcAtChipsetPkg F: PcAtChipsetPkg/ W: https://github.com/tianocore/tianocore.github.io/wiki/PcAtChipsetPkg --=20 2.17.1 -=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 (#59982): https://edk2.groups.io/g/devel/message/59982 Mute This Topic: https://groups.io/mt/74354978/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-