From nobody Fri Apr 26 07:16:41 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+63305+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+63305+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 1595863608769140.93006429129343; Mon, 27 Jul 2020 08:26:48 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id eH3vYY1788612x6gl9mcc6g1; Mon, 27 Jul 2020 08:26:48 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.52]) by mx.groups.io with SMTP id smtpd.web12.58058.1595863607784951457 for ; Mon, 27 Jul 2020 08:26:47 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XVwQwUz5DkEMizrlEMYbPFikdff2Cra6MOPtS5mpCI52hoIORm8JAigaoXCNpau2DMY+4cyOgoviXjvxNljDKRsBiIuEQoOn+Zkw+O/DwIWduxRQK9XSXZmYZlV/CGOyO2zUCtkswykSFRiO1iSwdu27emCwm1NPPWIBRyNGmmW6hT6kXSnWkCHibUwD2E5ggPOzc7jckANU3OfkRBTE9B4RImX2R9wcxOSKSlSRZGoRwCmxuBjMXXtkBCSG+k2PZluwgd+GWnnLLS0vXY8UqmkVRVQZNtBE3eAb8iBImTXxFleV9sjT00whVdjjMstv0n+JcuiT6ehjKO6+FjnzWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Hqe1rDuCswusit5U/Sbl9vY8AnSbuBv1xrlSJIgoLm4=; b=LUrp1/IW2eKN9VToMljs05020ByPrqzJlJn0OL+URX4kf2VJBgXDAdCO2fcAUT1Vp38E4Mle199FWo+JSimtn8GJygC/9S6MvyndeUPy97JutDVrr8n4Padx7LvLo5+vBDVSf49hepQaDgsZYKU/31RsZJcN6YxBwRMtCABu6aSf5b8u4IuxNk177zslSaCBt5ZdL93hk6QYP7TDv5aqJPutuUNxs9NAJocB1S6UXP+0bzgpmiU5h4+eZGSMKihF7Lh07HNcDR71WtDkc35LeZVLAerLPQrQc08sJJkRHNUAmQ8hQzUKjCKmK/deOOQE6V4f+9X1LoAJ5I+aNCc4rw== 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 DM5PR12MB1641.namprd12.prod.outlook.com (2603:10b6:4:10::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23; Mon, 27 Jul 2020 15:26:46 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:26:45 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni , Jian J Wang , Hao A Wu Subject: [edk2-devel] [PATCH v12 01/46] MdeModulePkg: Create PCDs to be used in support of SEV-ES Date: Mon, 27 Jul 2020 10:25:42 -0500 Message-ID: <2c52c409211b48edf96dd75ed817e9966c27559c.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR12CA0022.namprd12.prod.outlook.com (2603:10b6:4:1::32) 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 DM5PR12CA0022.namprd12.prod.outlook.com (2603:10b6:4:1::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.24 via Frontend Transport; Mon, 27 Jul 2020 15:26: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: c8c071cf-18e2-4d2f-1191-08d832417907 X-MS-TrafficTypeDiagnostic: DM5PR12MB1641: 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: hDpyAjwNIwQz/98OROrtw/AXyBpoZdCAeJo/DNsOLyNauWKsyzTGNDCLkF/b6Yrhm0ZacRNe7p2NpPmwP7LAu9B7fOw7HUnlZVukYvQbkG5+KMFF18JXbtR7/VlJNtwlmZTpySz8LO7zAc7z/EddG7UVUEO7cMf5zOWO5ndSLzJLjDRNhvAQ9luIY1qThx9owPZ5H8dqBPeE+O2kUGJVk+4lY529nKboTCkY+xG/qrGTve2W9zal3lHGiE3/hP88iMhlQ9S63dX/hHntzUg5CXHK76bKX8LQ264IjqizAwxcJcxrVVLcDBfwlWWgzNX76qzIPkIs3QraejhimOj8S+U7yS3Af7yFNv9jOhCTNiC4OFkMd7xOr7UXkIDCz3ehEzInqXG8RXd5kBiMPVnNV0VkLSmD9veWi8qybZ2HEXnSm3TP9s91OqwND0v98urRNo6ZtXJvlaqzl7f7hUUnkg== X-MS-Exchange-AntiSpam-MessageData: HErubzXtsIDKbWERdV5+W9/QcafX7WAPkGsdJmAhTIe1Sq1fXbOqVHz80noftSBI9eZ2+8Oc48oakVGB3fAi7S/iOWW9Q87SvdHC/jAUuUV2O4pVa3B5w2sqogwSUQDTTf11lQA6jB5AjwQ2MZdv8yjHQP/ZWKihxLVSUdMXrm3JrUIPrLmjkii6y59EJYizotxWHuiMZoRDccv/7spBG1lm0upjnoX+VzFfBz+bAP6JfS76twVji/V9OL0AcmYUjc7iQNzgBHpbjvdAztuS68POyvLrCxvhC79l2+YbYKcIr6K7GiHtKRoLfWmBLseV2fEGGuH24HFTdAzQ7DrCGnnljrImXFSGB0DCwPE2Nyo+VTmWC+LuX6FE+1m/gU6vHYXx4TV58Z+JMgEpREUv82dHtrPIWoRKDnEsholgZxZfZhg5lhslN19H4wgtyXiGZByURD0qMzcuR/5mSJievMuANlX+wTHO9uyWYvn25EQ= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: c8c071cf-18e2-4d2f-1191-08d832417907 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:26:45.8854 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Abx5o9Ubci8HsSai2RUF5Gskjo+V1/Awbn5WOHt9ucVeONVO+w7gmIHzF0xhIqb8CnwoQVOHetjHJDIyEVgn8g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1641 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: tjuEr7tUnRs7FYt04zfcJhkHx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863608; bh=U3CDD/tNYo0qYyX/XbEWYiWjwdverXc0esYS6C5IPRs=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=aYLMJOm7t42okAzVnzjBZDf2RwPCVVbyuo4lOZolM+vhb0aZcjxnG7xgsYtt+Mkakf/ ILosjLGcbl2yBWXZW4T+sxAbBKaNhXDGPMnsg4tMRZ3PuhTssqaPt4LMsnQk7ET7S0l87 aOVsx6W4LZLJrbJ+mo+1ERglqN0HzaxECsI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Two new dynamic MdeModulePkg PCDs are needed to support SEV-ES under OVMF: - PcdGhcbBase: UINT64 value that is the base address of the GHCB allocation. - PcdGhcbSize: UINT64 value that is the size, in bytes, of the GHCB allocation (size is dependent on the number of APs). Cc: Jian J Wang Cc: Hao A Wu Signed-off-by: Tom Lendacky --- MdeModulePkg/MdeModulePkg.dec | 9 +++++++++ MdeModulePkg/MdeModulePkg.uni | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 843e963ad34b..f8cd9239b4ce 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -2051,6 +2051,15 @@ [PcdsDynamic, PcdsDynamicEx] # @Prompt If there is any test key used by the platform. gEfiMdeModulePkgTokenSpaceGuid.PcdTestKeyUsed|FALSE|BOOLEAN|0x00030003 =20 + ## This dynamic PCD holds the base address of the GHCB pool allocation. + # @Prompt GHCB Pool Base Address + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase|0|UINT64|0x00030007 + + ## This dynamic PCD holds the total size of the GHCB pool allocation. + # The amount of memory allocated for GHCBs is dependent on the number o= f APs. + # @Prompt GHCB Pool Size + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize|0|UINT64|0x00030008 + [PcdsDynamicEx] ## This dynamic PCD enables the default variable setting. # Its value is the default store ID value. The default value is zero as= Standard default. diff --git a/MdeModulePkg/MdeModulePkg.uni b/MdeModulePkg/MdeModulePkg.uni index 2007e0596c4f..2f8cca03e527 100644 --- a/MdeModulePkg/MdeModulePkg.uni +++ b/MdeModulePkg/MdeModulePkg.uni @@ -1297,3 +1297,11 @@ #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTcgPfpMeasurementRevision_PR= OMPT #language en-US "TCG Platform Firmware Profile revision" =20 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdTcgPfpMeasurementRevision_HE= LP #language en-US "Indicates which TCG Platform Firmware Profile revision = the EDKII firmware follows." + +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdGhcbBase_PROMPT #language en= -US "GHCB Pool Base Address" + +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdGhcbBase_HELP #language en-U= S "Used with SEV-ES support to identify an address range that is not to be = encrypted." + +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdGhcbSize_PROMPT #language en= -US "GHCB Pool Base Size" + +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdGhcbSize_HELP #language en-U= S "Used with SEV-ES support to identify the size of the address range that = is not to be encrypted." --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63305): https://edk2.groups.io/g/devel/message/63305 Mute This Topic: https://groups.io/mt/75824928/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 Fri Apr 26 07:16:41 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+63306+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+63306+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 1595863616704891.475177127195; Mon, 27 Jul 2020 08:26:56 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id t2qoYY1788612xi6BJ9CyZdO; Mon, 27 Jul 2020 08:26:56 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.86]) by mx.groups.io with SMTP id smtpd.web11.58047.1595863615153787482 for ; Mon, 27 Jul 2020 08:26:55 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=agC1hP2YVZkuduoQs68xvnS8ipRTjFKaZklqJqigS5z5+USYNKv+3f0oh/SunqBVxZ/MZ5BQAxxfFAiSysuZbgg7QIlbU5BJEsXCVxotQ1idIFFGjWA7s9D8I58VKq/dvirushlYdN5Ikv8OFXpEITT6s81Etm62y2rqhVqi6q7fK3NBtDMYeHKmITanUFEYKq9BoN5XGi+QvJVYLC2/r5cM5JNL23+rfPW2zbmNZKFr5+ez0ej1dH3UtjKCZgfAmRKszvo97TsePmQhxSqyPgm+wOSVHm7o2/2iatIQXPzbkbHZ17INTzq1hpXwVn+3oxfcNi7ZYPL0vcVggF7Lag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iUIg1b4EwDhKpEO96e51MuPrwJUs/s5zD1/37hv4dng=; b=F7J5vpCfuacdM3iGOVWJCykFF0GosugnhGpKneaBzPQkOYUtDHQQd6E9r/4OMOqNfZvkXBYKXFAS+c1Ng3VmC3G++funBtQCTYANM8cSBeVzrYXTNwtdrMus9w3fCBqxYdWsZu6ElvVhQlF2H51JQfrJmPA3+cJHdGV+8tJH/fLYMFRYWBTOEZ2DSWOSDjaYiz7Y24SjtJUn+5DoOu7B5uX5+zknuPdba9dhnIx+fh4TrJGcSzYXcswpuY8iYEF3tzaqxO/wV0HAFQCOlpnIdwEkBM/rTUOMUKcBMCxBuWlGnRt0BprfARjgeToULZrjji5P1WdmAs27cgCyN9jdJg== 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 DM5PR12MB1641.namprd12.prod.outlook.com (2603:10b6:4:10::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23; Mon, 27 Jul 2020 15:26:53 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:26:53 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 02/46] UefiCpuPkg: Create PCD to be used in support of SEV-ES Date: Mon, 27 Jul 2020 10:25:43 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR2001CA0004.namprd20.prod.outlook.com (2603:10b6:4:16::14) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR2001CA0004.namprd20.prod.outlook.com (2603:10b6:4:16::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.21 via Frontend Transport; Mon, 27 Jul 2020 15:26: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: e00caf1b-cd92-4765-0152-08d832417d9f X-MS-TrafficTypeDiagnostic: DM5PR12MB1641: 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: kDtDCrW7zf4IUukHYsVwH72i3PeBMA+l65D7Lt2sjZx4/kAe7bHxOEGg9Z86Wfizd3a1ahLt4q2yoeRqEeE0bl0frGHezJvYMc9Ett+pFy0WQRzvaWrOMaronUMLgviVYLwlAETcGkyor8Qieg7PHpSv3rq5oCoD7sQPABWmHQz/C2lrSNNmAp4cY4RKg75K/T3kFGcltoVPwCmRfi3s7b2VcpxcITgxZDVEG7H27v62mpxiwgHchlwrRlvwyuucu6/dVSRRB44Gw33SevLlmB0ZPMGTIoLuY+lKUpDZHRMLau3DAy8fdcBX7cULEt9Vp27pLK6JM3QIxjuAHf2QLpKwQitx5nz9vG2Ra8Wsow/Atgw3Q4SlEHxDqZRs5vFBBcZT2c4kctkrbI42Y4oKdfJmEYWWB/sHmLr6G2NSo50ysr+EoYjbmygk7euK2NRYj9wYpfQoOIeiZ8YnLiG7Wg== X-MS-Exchange-AntiSpam-MessageData: Bfpt2dRSKv/s6lOfowdMHxY0nGnRSz79HI4wk3n/P2PEI/q3/Ic7DBfN3REQfGop2gQEJ5Rqpc69M7vOKr3wR+zw+dslFLWRs+Wb/Ey3tLBvWR/3Za0G3dxpcw7DX/NmSmyNhhpW+KacNqNjopnSHd1i5mnrt5e+tCjvNt3Gtox1ji66IrFf3F2HaLvWU7+EGd69ckhLx1d60sKTJnJQRfdEMOiIXpj+KmzCTJFyeSvoowj9lOfXSjPNzKxGucLoWue0kTKQ5vM4Pp0axUVS/PmVFL6l48ehHbzP++XfQiR+NqxcAgKOPdoIuox7GQX0wsF1gD00FgVfSUkXAympdKVc4v69evjkd5fDB1nusTDQtbMmaZ+hOMW/rN2Q9mYEa8vhd8/kKmFb1Of6MdAER9po5IS0nA6+mWVyEg6zXWakBQ3trkIjpTdMQ9ODVa4C2bFs9r+KzSw6EdVANH7D9LWxEFQC3vi5RN1KR+dSdx8= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e00caf1b-cd92-4765-0152-08d832417d9f X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:26:53.5930 (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: Y1EqGFyvg/KHR+RLBZ8H21fkJHLFVmqEGvnV4SzYGEln4tCMe1LRsrC6mEODGLACsQ72MvvqXXjHYIBuewboNQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1641 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: muPzkgoaJphp3apKO2paW7IEx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863616; bh=i01lKD98WqPDok5KjtW/KMipsUnSVj2GFU8DF03CBBQ=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=GElGcUDi7l9y1d6Pt4Y0nxxwGxFKlZZXp60rkkN+vw3RjJbkqBumlKU6U+SQCCVE0sF hk8aPInOazD523mgrQyKMVEPDBpp1A7rrTa+YJyRe4xNqE2kXrHSjkk/zgOkvZRR/l/CQ FX+ZPIX2H9+gDkCIZSXqn3FRom2wS/hjKhA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 A new dynamic UefiCpuPkg PCD is needed to support SEV-ES under OVMF: - PcdSevEsIsEnabled: BOOLEAN value used to indicate if SEV-ES is enabled Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Reviewed-by: Eric Dong Signed-off-by: Tom Lendacky --- UefiCpuPkg/UefiCpuPkg.dec | 6 ++++++ UefiCpuPkg/UefiCpuPkg.uni | 3 +++ 2 files changed, 9 insertions(+) diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index 762badf5d239..df5d02bae6b4 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -370,5 +370,11 @@ [PcdsDynamic, PcdsDynamicEx] # @ValidRange 0x80000001 | 0 - 1 gUefiCpuPkgTokenSpaceGuid.PcdCpuProcTraceOutputScheme|0x0|UINT8|0x600000= 15 =20 + ## This dynamic PCD indicates whether SEV-ES is enabled + # TRUE - SEV-ES is enabled + # FALSE - SEV-ES is not enabled + # @Prompt SEV-ES Status + gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|FALSE|BOOLEAN|0x60000016 + [UserExtensions.TianoCore."ExtraFiles"] UefiCpuPkgExtra.uni diff --git a/UefiCpuPkg/UefiCpuPkg.uni b/UefiCpuPkg/UefiCpuPkg.uni index 1780dfdc126d..f4a0c72f6293 100644 --- a/UefiCpuPkg/UefiCpuPkg.uni +++ b/UefiCpuPkg/UefiCpuPkg.uni @@ -278,3 +278,6 @@ =20 #string STR_gUefiCpuPkgTokenSpaceGuid_PcdCpuApStatusCheckIntervalInMicroSe= conds_PROMPT #language en-US "Periodic interval value in microseconds for = AP status check in DXE.\n" #string STR_gUefiCpuPkgTokenSpaceGuid_PcdCpuApStatusCheckIntervalInMicroSe= conds_HELP #language en-US "Periodic interval value in microseconds for = the status check of APs for StartupAllAPs() and StartupThisAP() executed in= non-blocking mode in DXE phase.\n" + +#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsIsEnabled_PROMPT #language = en-US "Specifies whether SEV-ES is enabled" +#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsIsEnabled_HELP #language = en-US "Set to TRUE when running as an SEV-ES guest, FALSE otherwise." --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63306): https://edk2.groups.io/g/devel/message/63306 Mute This Topic: https://groups.io/mt/75824932/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 Fri Apr 26 07:16:41 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+63307+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+63307+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 159586362415264.81016052587972; Mon, 27 Jul 2020 08:27:04 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id UV0iYY1788612xgT78cbYPfY; Mon, 27 Jul 2020 08:27:03 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.51]) by mx.groups.io with SMTP id smtpd.web11.58052.1595863622601579363 for ; Mon, 27 Jul 2020 08:27:02 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ia7v64SdYP6/yY0e52moAgybH2v8u2uUVGw6Mbi6Pjt1QLrhadT1Raj3Wu53+6bWidJZ4modP+Vo+9NTjC54fpBMqUBdfinwWwl2FUftRvMVfSUMv3uC8MXCg4PcaMb3mNk4olSdH0Y7p52AOxXhGq1cw9m8xe7d/qBtzruStwVms+gmBK0bGeYyd4cqxdIXExjZkoi/9Iu7+GKndLM3hfUGc3tzpQB5zFCWFRTsYAhPE+/TsxyAgsbIrBPrn7+So0h8CpNFEZtuq6gNl7QHJOOZZ1igRGYROzW6gZhbeYDiJGLsQ1XEnjth7Dmn/epq0mwlEbUOL+xkCe9PMBEgaA== 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=tRE7SkFgGOeG66PvdkFIGd/IGhL7swQyOWx8HekFNVI=; b=Rgmh+IWapMhNTE2vus77gVt3pZ8teYR3aL9b7khYEDk3P961MgyOnw0XguDy3MDr9rhRPwNFxghz1tYHg9ThEpblyV79S1V5tA6wYZQYlWRAF4L8NrACSdnZqV/O54f7UsV2fPykotk8jY6KT0FHHYyDLZdHlqjrr6AmmbYYwMbxGmzhe37tNaz5uhHDf/3DduDeiaFp9dj99lKvAq75isH/s5bj+cdu5Bg5XC0nZHdTyzevnyNrNJqm5hfFJpobH/GkRS+okzXDI1O1sEMTzVCS9eVU+Ikj41WUvIxE6dBKe7Xm+5QRiHpgL34G+2wir+gHSYAKU0Dr9uDLeG9W/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 DM5PR12MB1641.namprd12.prod.outlook.com (2603:10b6:4:10::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23; Mon, 27 Jul 2020 15:27:01 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:27:01 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 03/46] MdePkg: Add the MSR definition for the GHCB register Date: Mon, 27 Jul 2020 10:25:44 -0500 Message-ID: <4c660a1d7b33c9d70579015281d459dd74518213.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM3PR12CA0132.namprd12.prod.outlook.com (2603:10b6:0:51::28) 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 DM3PR12CA0132.namprd12.prod.outlook.com (2603:10b6:0:51::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.20 via Frontend Transport; Mon, 27 Jul 2020 15:27: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: 9171e197-1de2-4140-b9fb-08d832418211 X-MS-TrafficTypeDiagnostic: DM5PR12MB1641: 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: ndY+/F8JbTl5QKNBym/u09UGDXvoHfsIgtBL7KRg2+uruuiRlHKyN23NFKo/ot6/dZtLjOAlkVfoRyYJGUedqJng3h/WyHJyklKFztTq/mAQk7/VFli3UTsOjO8PkUNjnRKKvvjOxolkXPjdt9Tk7AuOqNTnhGeX8jTws+U3S9C4uJ+J7n8gywxU8DiAuthZ016+t9jNHjXfz6kEN9M4D9bg/75EZkQZ1fmDoFPvCmHFt5qE09J8R1SBt2le7tLW/5HXPNh6zwqm0RqaHmMcE8+kH3P4/hB50V7TX5SXe93QjNOFQjqhwKp9ZCxeOtofB80TQIuGVyOmHyn+oiqV8iq3TSAp20QEdAgQfHZlVAKKs6XbDYjIKsC4e+u5agHqclsBueDMzbRCb1aUesv0iAH5e46GVDcETxBOqCiSgq/FD2dWsGOSZEi6uluHVyRVTZcmj0+sxPJ5fF4Bs2Nr3w== X-MS-Exchange-AntiSpam-MessageData: RpQ/ne2XEtugFr51EMLNHw3hwfEELWLAGHcv6pHir+AHvh7jO5MXXM4oo1MGjKd55zHWv+EZXDiDCmoREq9lUxPRTMLl1WiILp8DOVG/9198usP58hUEJa4rdD8VPWnTTGJVQoT0Pq6MlfBsBp6SHWr79Nhvy6S5V+weG324hNQOYujYBCxmGzmpv5JG3CLCDDB5UmnJyG8gBD5H/U2fKL3hr2xp8cJPaKtP6p161g0nuFza2esNZYmN12VbnWcvq2N3qPo2sMwuqkl3YfEaN5O46lAqGNOZoOjE/5/Wr3DsTcZkcx6EinCx9iVPdQQjaiRz/ZGKZTh7JkDVu/37e2XHTRrfqIlIRlav5Yz9ytdBXt/n7IEjQ/AqFBe7OtnWL091DLwXwsw326luyd9d8HBj6m7RjD23IE+Nc0mphaj/EnEQSV1rs1LLGkNtkQss2m+xiYiAUa8Cxrvehj3oNn3dDANkzWgM0dmARFjOC04= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9171e197-1de2-4140-b9fb-08d832418211 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:27:01.0557 (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: 8j59uyc8ht2MkEefLexGbnyU+hwg6QEdzjITCwA2vglgomsMXftJ0DXHP7BiypdAZs/sQ/DGos/Cvdk4sIJsjw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1641 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: 5Ib5yrJJuMrb1eKvzuSnXxRRx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863623; bh=33v6orDE30e6cUaX0j01ixud28K/K3/+LtqJM+SL2w4=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=vCxVybjs13NBBNS+7HgYjQBEVsBstSYOfs5VxjdWWs7af7VJEfM8p8YtI1KAIpBgSRZ Njp2VOSYhCBOIpAWHPbzuUJ59yVVMHtTImIllGNJLxAXhH2NzXCNb4lcZOmB4py0aBPVL 8JufbxSiQV6jNGJRcYQ+yU8dDP4OgrK3G7c= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 For SEV-ES, the GHCB page address is stored in the GHCB MSR register (0xc0010130). Define the register and the format used for register during GHCB protocol negotiation. Cc: Michael D Kinney Cc: Liming Gao Reviewed-by: Liming Gao Signed-off-by: Tom Lendacky --- MdePkg/Include/Register/Amd/Fam17Msr.h | 46 ++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/MdePkg/Include/Register/Amd/Fam17Msr.h b/MdePkg/Include/Regist= er/Amd/Fam17Msr.h index 6ef45a9b21d3..e4db09c5184c 100644 --- a/MdePkg/Include/Register/Amd/Fam17Msr.h +++ b/MdePkg/Include/Register/Amd/Fam17Msr.h @@ -17,6 +17,52 @@ #ifndef __FAM17_MSR_H__ #define __FAM17_MSR_H__ =20 +/** + Secure Encrypted Virtualization - Encrypted State (SEV-ES) GHCB register + +**/ +#define MSR_SEV_ES_GHCB 0xc0010130 + +/** + MSR information returned for #MSR_SEV_ES_GHCB +**/ +typedef union { + struct { + UINT32 Function:12; + UINT32 Reserved1:20; + UINT32 Reserved2:32; + } GhcbInfo; + + struct { + UINT8 Reserved[3]; + UINT8 SevEncryptionBitPos; + UINT16 SevEsProtocolMin; + UINT16 SevEsProtocolMax; + } GhcbProtocol; + + struct { + UINT32 Function:12; + UINT32 ReasonCodeSet:4; + UINT32 ReasonCode:8; + UINT32 Reserved1:8; + UINT32 Reserved2:32; + } GhcbTerminate; + + VOID *Ghcb; + + UINT64 GhcbPhysicalAddress; +} MSR_SEV_ES_GHCB_REGISTER; + +#define GHCB_INFO_SEV_INFO 1 +#define GHCB_INFO_SEV_INFO_GET 2 +#define GHCB_INFO_CPUID_REQUEST 4 +#define GHCB_INFO_CPUID_RESPONSE 5 +#define GHCB_INFO_TERMINATE_REQUEST 256 + +#define GHCB_TERMINATE_GHCB 0 +#define GHCB_TERMINATE_GHCB_GENERAL 0 +#define GHCB_TERMINATE_GHCB_PROTOCOL 1 + /** Secure Encrypted Virtualization (SEV) status register =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63307): https://edk2.groups.io/g/devel/message/63307 Mute This Topic: https://groups.io/mt/75824936/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 Fri Apr 26 07:16:41 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+63308+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+63308+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 1595863632788457.7708197601763; Mon, 27 Jul 2020 08:27:12 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id NoOqYY1788612xp1ZQXSDzEh; Mon, 27 Jul 2020 08:27:12 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.46]) by mx.groups.io with SMTP id smtpd.web11.58055.1595863630931071631 for ; Mon, 27 Jul 2020 08:27:11 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LZLhamOdf2mMikqW1qhApUxV4PCfRTiWGSUePG63YUmIoePHALM9CqGPNONS73hQLcd9K4opIyWVBJE0WE3hBFIP0it7A1xIlsNLa2MJacxy8VAHtez4k8T4WChW8DxkDkwsp4hw3oie/aZM2VvBw3LPf/5y2H9g+DJUNfVZmp1V/DmpWn1lqeGCZiKL2W3EO83UVTuQldS2JZs0DDx6wcz5T7RFo5EegWbLvoprSZ7bQ+wZewRjpd/BAU2KEUPcOAnB6lKT+6EuJYbuZo1bIRG/XgHMh2g9t6E+nKWAbx3uw1Rbb7NgRUixpYg8GeDdEXpmtaLyXD8Lfipb+1QahA== 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=YYkVB64VTGSzUnAsN8IQEH1S+2akt7TobPcbdBPWZn8=; b=iew4PMVeW0MaIhXeGFQATcsDlTic15oSkh5/B0/sO1Hryrn0+BVlfH9B5seoAGdWZm5UAPbDMgv0M2I/l1ubnorKAu0h5t3uxbEhide8PE/lXKldf0Kd/k3qFio594NQxLzdouJpi2lZiwXWeg/fcrg3p15hMfdtnDXi406BtCDX0ABN+hU+ATaiZAsffFPhNaK9GMADd8igNllsXkbiDwWeSF6XzGEl5hFmq1qA0hhCl/ZHpdcmNi1byd7FSy5uS9zZBc0rPh5H9L0rn4yHjt50YvRsDQiikU9K1CDRI5awbdiUgW5rwzAGuzv/qJiBlzploINNRvKgZyL+0KS1yA== 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 DM5PR12MB1641.namprd12.prod.outlook.com (2603:10b6:4:10::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23; Mon, 27 Jul 2020 15:27:09 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:27:09 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 04/46] MdePkg: Add a structure definition for the GHCB Date: Mon, 27 Jul 2020 10:25:45 -0500 Message-ID: <92473075ba8e28c21050f80577d70e761de74b40.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0601CA0013.namprd06.prod.outlook.com (2603:10b6:803:2f::23) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0601CA0013.namprd06.prod.outlook.com (2603:10b6:803:2f::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23 via Frontend Transport; Mon, 27 Jul 2020 15:27:08 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 13ea6558-e9de-426c-a3b3-08d8324186d8 X-MS-TrafficTypeDiagnostic: DM5PR12MB1641: 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: Y0bdGdgYdV8AOrQeCuDlOduP4y9LOEO5j5DMhc/RHYjy8lHgcr/mRYj26Bb3pQEl7+/Tgzt0jKQ77vFZKFFMAqK99x2n6lIT/ZKqWfu/eQvZVPgOybgpeE1o0nBRvx2zSxgzfumksafJz2RtQT4ffbAxnicWPmBH3WcOlNf2/22VsGalXpPaL03PyI2JZHxjfQksfFJbHSs4bY3U8K2LK7G6Opu/lTnaGL55HRB/w7VUrACIYKCkdMfKFqjt7hAPIEBNTuaAhuzeY6ygStPA+8q0E1CH0EAi9MLGO4FomQ5WTEYSr3G4+5qZQW9P9MpHFiWeNHR3IQuXdBSs0Y7C02JX6aZaoAEiBjBiiDoYXktzzjN/lqULxci1mD4f07MM7TQ/77DCIcU/l9UbRIvX3IzdReKzBJ7cTc0JmJpQKNpMhFobHWaZzpc8jmpSERx9ZAdJxDjj7a6MolWC8Znjjw== X-MS-Exchange-AntiSpam-MessageData: LanmS4BR5ljoTFUsPAh9ZV6tI/suvBR317pTQRQQDXGmPmVWFKDvrBF7RtjDwKNZZjjdbZOVDnfSFsQkFikt66zPv9bbeAfDeOU3vaKjgTPfpca5k29d3ukwd29paSPlfBJ4d0JdAoxBU3mlV+yigu/z8s3tH2AYeHaXa7VGjlqjZKPQcmp9nm3v/uGlucQtiWYd3lx/s8W7kTgwcTZjYgbkAiJGhcLBXs+IHMd+e0J7RPFe2MCCUR1UVilu+HQBWc6lHzBoNdwuCcO7q6T9wzrrattJgJ9Ria9pTjSJzl9vaVZEZ4diwRAHo1dawyypcryj8w7i7Bj49Mz8v4hEe+iVvXRufrzi8/vstzMJARXLEdoVRCB/4KFXFoP6lkP2XUdHDUlE/h5cbsgBXJitNEAe1Iuv4EllLMbcN/NPORNA+PPUZgIQuop5nnLel9XFJHGsEppDRGFaE0SJp62X1qQzefPWuCa854G5wnbq9yI= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 13ea6558-e9de-426c-a3b3-08d8324186d8 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:27:09.0982 (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: lPPVAgQydVcIlsbHSHik/ttaOKqgwvy+He67lNiWn1tc61Hl+CNVllyTog1hXyWpRfmVJD6jyO8jNLMvcGyXLQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1641 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: sVllPZHuSHrVQaAqpkGOxTdNx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863632; bh=ZMsZo0NIAtwv3sMC7O/vaj4TNrOlatQ7bxvkvNHivK8=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=jh21JHFJl7rwqDtdJuEWTiXBjlkadaU4Zd7yneUvaCAVLbkTEwCU/3f/8wSjWiYJdN3 DXqpg0FG0Ft/vg5JSyVhjXQvGwhPBliIcOzYCAEw1LDXXo5UHZ5S7tYalIqhkN3ucj9wz shE0O36VNH22SBrltnILvV/kbkj6hVfV/bw= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 The GHCB is used by an SEV-ES guest for communicating between the guest and the hypervisor. Create the GHCB definition as defined by the GHCB protocol definition. Cc: Michael D Kinney Cc: Liming Gao Reviewed-by: Liming Gao Signed-off-by: Tom Lendacky --- MdePkg/Include/Register/Amd/Ghcb.h | 166 +++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 MdePkg/Include/Register/Amd/Ghcb.h diff --git a/MdePkg/Include/Register/Amd/Ghcb.h b/MdePkg/Include/Register/A= md/Ghcb.h new file mode 100644 index 000000000000..54a80da0f6d7 --- /dev/null +++ b/MdePkg/Include/Register/Amd/Ghcb.h @@ -0,0 +1,166 @@ +/** @file + Guest-Hypervisor Communication Block (GHCB) Definition. + + Provides data types allowing an SEV-ES guest to interact with the hyperv= isor + using the GHCB protocol. + + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + + @par Specification Reference: + SEV-ES Guest-Hypervisor Communication Block Standardization + +**/ + +#ifndef __GHCB_H__ +#define __GHCB_H__ + +#include +#include +#include + +#define UD_EXCEPTION 6 +#define GP_EXCEPTION 13 +#define VC_EXCEPTION 29 + +#define GHCB_VERSION_MIN 1 +#define GHCB_VERSION_MAX 1 + +#define GHCB_STANDARD_USAGE 0 + +// +// SVM Exit Codes +// +#define SVM_EXIT_DR7_READ 0x27ULL +#define SVM_EXIT_DR7_WRITE 0x37ULL +#define SVM_EXIT_RDTSC 0x6EULL +#define SVM_EXIT_RDPMC 0x6FULL +#define SVM_EXIT_CPUID 0x72ULL +#define SVM_EXIT_INVD 0x76ULL +#define SVM_EXIT_IOIO_PROT 0x7BULL +#define SVM_EXIT_MSR 0x7CULL +#define SVM_EXIT_VMMCALL 0x81ULL +#define SVM_EXIT_RDTSCP 0x87ULL +#define SVM_EXIT_WBINVD 0x89ULL +#define SVM_EXIT_MONITOR 0x8AULL +#define SVM_EXIT_MWAIT 0x8BULL +#define SVM_EXIT_NPF 0x400ULL + +// +// VMG Special Exit Codes +// +#define SVM_EXIT_MMIO_READ 0x80000001ULL +#define SVM_EXIT_MMIO_WRITE 0x80000002ULL +#define SVM_EXIT_NMI_COMPLETE 0x80000003ULL +#define SVM_EXIT_AP_RESET_HOLD 0x80000004ULL +#define SVM_EXIT_AP_JUMP_TABLE 0x80000005ULL +#define SVM_EXIT_UNSUPPORTED 0x8000FFFFULL + +// +// IOIO Exit Information +// +#define IOIO_TYPE_STR BIT2 +#define IOIO_TYPE_IN 1 +#define IOIO_TYPE_INS (IOIO_TYPE_IN | IOIO_TYPE_STR) +#define IOIO_TYPE_OUT 0 +#define IOIO_TYPE_OUTS (IOIO_TYPE_OUT | IOIO_TYPE_STR) + +#define IOIO_REP BIT3 + +#define IOIO_ADDR_64 BIT9 +#define IOIO_ADDR_32 BIT8 +#define IOIO_ADDR_16 BIT7 + +#define IOIO_DATA_32 BIT6 +#define IOIO_DATA_16 BIT5 +#define IOIO_DATA_8 BIT4 +#define IOIO_DATA_MASK (BIT6 | BIT5 | BIT4) +#define IOIO_DATA_OFFSET 4 +#define IOIO_DATA_BYTES(x) (((x) & IOIO_DATA_MASK) >> IOIO_DATA_OFFSET) + +#define IOIO_SEG_ES 0 +#define IOIO_SEG_DS (BIT11 | BIT10) + + +typedef enum { + GhcbCpl =3D 25, + GhcbRflags =3D 46, + GhcbRip, + GhcbRsp =3D 59, + GhcbRax =3D 63, + GhcbRcx =3D 97, + GhcbRdx, + GhcbRbx, + GhcbRbp =3D 101, + GhcbRsi, + GhcbRdi, + GhcbR8, + GhcbR9, + GhcbR10, + GhcbR11, + GhcbR12, + GhcbR13, + GhcbR14, + GhcbR15, + GhcbXCr0 =3D 125, +} GHCB_REGISTER; + +typedef PACKED struct { + UINT8 Reserved1[203]; + UINT8 Cpl; + UINT8 Reserved2[148]; + UINT64 Dr7; + UINT8 Reserved3[144]; + UINT64 Rax; + UINT8 Reserved4[264]; + UINT64 Rcx; + UINT64 Rdx; + UINT64 Rbx; + UINT8 Reserved5[112]; + UINT64 SwExitCode; + UINT64 SwExitInfo1; + UINT64 SwExitInfo2; + UINT64 SwScratch; + UINT8 Reserved6[56]; + UINT64 XCr0; + UINT8 ValidBitmap[16]; + UINT64 X87StateGpa; + UINT8 Reserved7[1016]; +} GHCB_SAVE_AREA; + +typedef PACKED struct { + GHCB_SAVE_AREA SaveArea; + UINT8 SharedBuffer[2032]; + UINT8 Reserved1[10]; + UINT16 ProtocolVersion; + UINT32 GhcbUsage; +} GHCB; + +typedef union { + struct { + UINT32 Lower32Bits; + UINT32 Upper32Bits; + } Elements; + + UINT64 Uint64; +} GHCB_EXIT_INFO; + +typedef union { + struct { + UINT32 Vector:8; + UINT32 Type:3; + UINT32 ErrorCodeValid:1; + UINT32 Rsvd:19; + UINT32 Valid:1; + UINT32 ErrorCode; + } Elements; + + UINT64 Uint64; +} GHCB_EVENT_INJECTION; + +#define GHCB_EVENT_INJECTION_TYPE_INT 0 +#define GHCB_EVENT_INJECTION_TYPE_NMI 2 +#define GHCB_EVENT_INJECTION_TYPE_EXCEPTION 3 +#define GHCB_EVENT_INJECTION_TYPE_SOFT_INT 4 + +#endif --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63308): https://edk2.groups.io/g/devel/message/63308 Mute This Topic: https://groups.io/mt/75824938/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 Fri Apr 26 07:16:41 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+63309+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+63309+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 1595863640326452.079008983039; Mon, 27 Jul 2020 08:27:20 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id jz3rYY1788612xyUp7QTJBWm; Mon, 27 Jul 2020 08:27:19 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.77]) by mx.groups.io with SMTP id smtpd.web12.58068.1595863639289303414 for ; Mon, 27 Jul 2020 08:27:19 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lKRS5L9hx5zlgpm8kXXJns8FPd3/kmLXDbY3G5ax9ZzWZUkBwuCppgotx7jWN8JbhN/0mkszQ29MLxAuRGmf/YRf2xpuUFB4P9v2ahb2FPH+aUSp8jP8jnp1IZipOjPwBm2P8uuPlzLMSezoE5hyjOUKNkxA1S9cRyNHEIuRscU/PEI82GNBJuYq/UIAhQ3zpgQNAsDAbZinwEITtWbTVmrX5oG5rGCMBxPjwBcLYvlwPfxkvD7AwunY82O/oeiPR46/sDA8ru053b4bYnN2AUHVglLrKoPzOzs7bJo6rQpLQuEHk8eGhniBDSqFJVruFsoJI02k5XWcCs7ebfIOKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1CQV39IMQU98kDP7Cw8EBWMcqMw2WdJpQzO/hKKOH84=; b=ZllMJ+yEkF0xYgwHMD22qi62STXpwOhAgJA6xpSnNzewKG+rVS3zqRH+4bwqS5Fo4GH3EVHp1BnF7OUb4jcxh5jpXVJxl/X4K6mY/fl96Ia/T2DYGNI5Vz0wAT3UzSA6PRkFmqKGKWDiXwgZdlwyO/Dau/9cp+CFNmu1AyKy/jyO8wys3h5OUXPUM+T2bVTFb80vx9ooazKvOExPZ9lLUhVteYVBe+wlxQEplK7aTvxeh6/mBG9k2bTQZg3pnTl9MGvY8nAraMZ8B5dSVN7Yx81u1wJrSyb5VcuTTyco9xEZgvvbt2bqOKL3AfCXfqyFkjT+JD8gQNMPBHfJQ4vuIg== 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 DM5PR12MB1641.namprd12.prod.outlook.com (2603:10b6:4:10::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23; Mon, 27 Jul 2020 15:27:17 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:27:17 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni , Jian J Wang , Hao A Wu , Dandan Bi Subject: [edk2-devel] [PATCH v12 05/46] MdeModulePkg/DxeIplPeim: Support GHCB pages when creating page tables Date: Mon, 27 Jul 2020 10:25:46 -0500 Message-ID: <25ebb2ef0237521ab6bf4d3da22696c91832e652.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0401CA0017.namprd04.prod.outlook.com (2603:10b6:803:21::27) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0401CA0017.namprd04.prod.outlook.com (2603:10b6:803:21::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23 via Frontend Transport; Mon, 27 Jul 2020 15:27:16 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e50cbce0-8b36-4a6e-df42-08d832418baf X-MS-TrafficTypeDiagnostic: DM5PR12MB1641: 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: RNzSr5Fg7981l6QPfpQsHfmaQPRJbAO1qE7Nr38GC842EDUqZMoknR+Ep5wJ3PWkxVaz1RkCXu4DZaBBD4joioXpoKVks1De1bwc/vwDXpM6FcLYz6Khj03ohp3EFyhjGI6V2uxj7UKS7V+bSwefjxXKuk7uy5iiac8pU0Rg4EPyz4RJpbjOmaqIY/41ju6v8ChYqNmxUBZOh9GM5QtnX3R0+8qVVJe3psB2eHQmHai5bOsuq98NebVsmkmvuu2kwE8ci8OnoIJYjNM2fUitVvTbWOEN0jp93uEXFQ40h9MdvQ345PlyhihrBWRMssWhbhMIGTgZ3GAqiDa01FojT30TN1tPuPaeq+fGaUDIpQq8Dsj3449WGGtbnOSzIUQyhq3N06NNSeQ6BSJNww1kY8xnuUP0cDPCf3XF35NS/xVGb5fzfxMHNRFj/DY1JWX7Lc9euVHeEXvUfSEwSk0/tA== X-MS-Exchange-AntiSpam-MessageData: M9soE6wLy3k4TKMaa073B+CJKhCY4i2/6Na3QLUxshmJvDcur4wkBi75KgIPxwtSHft0ECHBmE7j1Rjma+EXXB5Uy2gdKBgN6vGW80pDzfdgKGTjS2DAZqpPACR2aQdcUtji7ZOptdx+IUnZCb7sfJPJl0jt7Dz0E741iiSHTH/tPUso/AeazLV3VoDoaGEhXRilKZOyJ1nl1HGvBtPHObME0bo4c945XEMciXZxqWcZjYocL/uBVj33cTjqbQyMwcu278eBiMjSc2AROtLd5cR4oZOfPsLlpipCkPW1gmVqsNZrsLuKg1ll+4HSznIzA0P8I461mzxAHxwNCwTRdR/OZzZ64YErZYAQc4Xdx3RA/WuMMaeRqGVTu6ObWNQJjLL0iW1Yu+hKb/exS5fexRpEmw/ZnPYV19TXhkvApa06dpxfJgtTYdi7oZP0KF9VQGJKkQiQBBzeltBrV+nndVDIW0zjCcxwNjRMqFPey94= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e50cbce0-8b36-4a6e-df42-08d832418baf X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:27:17.2146 (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: WllPqv4zdbb0UGV6y5VvWTo0fhwbCP8+5NE8B/pg5SMmDj9joLrl2aglLpa8IZcwjQNdr4YTEoTnq7BFWxbbVA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1641 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: l39o6J854xEkbuVyUmAHf3BJx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863639; bh=UPSvuM52B4k8WCQvm3t80ju+QMpvcINCMo6QpsA8i/4=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=wAxE6tghTaBl21jMHfjhtLNWBphhMck3SrGVafE9R3w8GDJMRAyJG+C0OjH0evZUlEC O81ATSOutLmIIct3+xM4Bc83vCfJRHv1st34Rar1ApiQio6fIKSNXZJjlGMTEjKZkQWhM TOWFoNzhULlF24Wpcx2wXr3nidI0Lq0F6kc= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 GHCB pages must be mapped as shared pages, so modify the process of creating identity mapped pagetable entries so that GHCB entries are created without the encryption bit set. The GHCB range consists of two pages per CPU, the first being the GHCB and the second being a per-CPU variable page. Only the GHCB page is mapped as shared. Cc: Jian J Wang Cc: Hao A Wu Cc: Dandan Bi Cc: Liming Gao Signed-off-by: Tom Lendacky --- MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf | 2 + .../Core/DxeIplPeim/X64/VirtualMemory.h | 12 +++- .../Core/DxeIplPeim/Ia32/DxeLoadFunc.c | 4 +- .../Core/DxeIplPeim/X64/DxeLoadFunc.c | 11 +++- .../Core/DxeIplPeim/X64/VirtualMemory.c | 57 +++++++++++++++---- 5 files changed, 70 insertions(+), 16 deletions(-) diff --git a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf b/MdeModulePkg/Core/Dx= eIplPeim/DxeIpl.inf index 3f1702854660..19b8a4c8aefa 100644 --- a/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf +++ b/MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf @@ -115,6 +115,8 @@ [Pcd.IA32,Pcd.X64] gEfiMdeModulePkgTokenSpaceGuid.PcdHeapGuardPropertyMask ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ##= CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdUse5LevelPageTable ##= SOMETIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase ##= CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize ##= CONSUMES =20 [Pcd.IA32,Pcd.X64,Pcd.ARM,Pcd.AARCH64] gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack ## SOMETIM= ES_CONSUMES diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h b/MdeModulePk= g/Core/DxeIplPeim/X64/VirtualMemory.h index 2d0493f109e8..6b7c38a441d6 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h +++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h @@ -201,6 +201,8 @@ EnableExecuteDisableBit ( @param[in, out] PageEntry2M Pointer to 2M page entry. @param[in] StackBase Stack base address. @param[in] StackSize Stack size. + @param[in] GhcbBase GHCB page area base address. + @param[in] GhcbSize GHCB page area size. =20 **/ VOID @@ -208,7 +210,9 @@ Split2MPageTo4K ( IN EFI_PHYSICAL_ADDRESS PhysicalAddress, IN OUT UINT64 *PageEntry2M, IN EFI_PHYSICAL_ADDRESS StackBase, - IN UINTN StackSize + IN UINTN StackSize, + IN EFI_PHYSICAL_ADDRESS GhcbBase, + IN UINTN GhcbSize ); =20 /** @@ -217,6 +221,8 @@ Split2MPageTo4K ( =20 @param[in] StackBase Stack base address. @param[in] StackSize Stack size. + @param[in] GhcbBase GHCB page area base address. + @param[in] GhcbSize GHCB page area size. =20 @return The address of 4 level page map. =20 @@ -224,7 +230,9 @@ Split2MPageTo4K ( UINTN CreateIdentityMappingPageTables ( IN EFI_PHYSICAL_ADDRESS StackBase, - IN UINTN StackSize + IN UINTN StackSize, + IN EFI_PHYSICAL_ADDRESS GhcbBase, + IN UINTN GhcbkSize ); =20 =20 diff --git a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c b/MdeModulePkg= /Core/DxeIplPeim/Ia32/DxeLoadFunc.c index 6e8ca824d469..284b34818ca7 100644 --- a/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c +++ b/MdeModulePkg/Core/DxeIplPeim/Ia32/DxeLoadFunc.c @@ -123,7 +123,7 @@ Create4GPageTablesIa32Pae ( // // Need to split this 2M page that covers stack range. // - Split2MPageTo4K (PhysicalAddress, (UINT64 *) PageDirectoryEntry, S= tackBase, StackSize); + Split2MPageTo4K (PhysicalAddress, (UINT64 *) PageDirectoryEntry, S= tackBase, StackSize, 0, 0); } else { // // Fill in the Page Directory entries @@ -282,7 +282,7 @@ HandOffToDxeCore ( // // Create page table and save PageMapLevel4 to CR3 // - PageTables =3D CreateIdentityMappingPageTables (BaseOfStack, STACK_SIZ= E); + PageTables =3D CreateIdentityMappingPageTables (BaseOfStack, STACK_SIZ= E, 0, 0); =20 // // End of PEI phase signal diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c b/MdeModulePkg/= Core/DxeIplPeim/X64/DxeLoadFunc.c index f465eb1d8ac4..156a477d8467 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c +++ b/MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c @@ -35,6 +35,8 @@ HandOffToDxeCore ( UINT32 Index; EFI_VECTOR_HANDOFF_INFO *VectorInfo; EFI_PEI_VECTOR_HANDOFF_INFO_PPI *VectorHandoffInfoPpi; + VOID *GhcbBase; + UINTN GhcbSize; =20 // // Clear page 0 and mark it as allocated if NULL pointer detection is en= abled. @@ -81,12 +83,19 @@ HandOffToDxeCore ( TopOfStack =3D (VOID *) ((UINTN) BaseOfStack + EFI_SIZE_TO_PAGES (STACK_= SIZE) * EFI_PAGE_SIZE - CPU_STACK_ALIGNMENT); TopOfStack =3D ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT); =20 + // + // Get the address and size of the GHCB pages + // + GhcbBase =3D (VOID *) PcdGet64 (PcdGhcbBase); + GhcbSize =3D PcdGet64 (PcdGhcbSize); + PageTables =3D 0; if (FeaturePcdGet (PcdDxeIplBuildPageTables)) { // // Create page table and save PageMapLevel4 to CR3 // - PageTables =3D CreateIdentityMappingPageTables ((EFI_PHYSICAL_ADDRESS)= (UINTN) BaseOfStack, STACK_SIZE); + PageTables =3D CreateIdentityMappingPageTables ((EFI_PHYSICAL_ADDRESS)= (UINTN) BaseOfStack, STACK_SIZE, + (EFI_PHYSICAL_ADDRESS) (= UINTN) GhcbBase, GhcbSize); } else { // // Set NX for stack feature also require PcdDxeIplBuildPageTables be T= RUE diff --git a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c b/MdeModulePk= g/Core/DxeIplPeim/X64/VirtualMemory.c index 516cf908bc88..6831946c54d3 100644 --- a/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c +++ b/MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.c @@ -181,6 +181,8 @@ EnableExecuteDisableBit ( @param Size Size of the given physical memory. @param StackBase Base address of stack. @param StackSize Size of stack. + @param GhcbBase Base address of GHCB pages. + @param GhcbSize Size of GHCB area. =20 @retval TRUE Page table should be split. @retval FALSE Page table should not be split. @@ -190,7 +192,9 @@ ToSplitPageTable ( IN EFI_PHYSICAL_ADDRESS Address, IN UINTN Size, IN EFI_PHYSICAL_ADDRESS StackBase, - IN UINTN StackSize + IN UINTN StackSize, + IN EFI_PHYSICAL_ADDRESS GhcbBase, + IN UINTN GhcbSize ) { if (IsNullDetectionEnabled () && Address =3D=3D 0) { @@ -209,6 +213,12 @@ ToSplitPageTable ( } } =20 + if (GhcbBase !=3D 0) { + if ((Address < GhcbBase + GhcbSize) && ((Address + Size) > GhcbBase)) { + return TRUE; + } + } + return FALSE; } /** @@ -322,6 +332,8 @@ AllocatePageTableMemory ( @param[in, out] PageEntry2M Pointer to 2M page entry. @param[in] StackBase Stack base address. @param[in] StackSize Stack size. + @param[in] GhcbBase GHCB page area base address. + @param[in] GhcbSize GHCB page area size. =20 **/ VOID @@ -329,7 +341,9 @@ Split2MPageTo4K ( IN EFI_PHYSICAL_ADDRESS PhysicalAddress, IN OUT UINT64 *PageEntry2M, IN EFI_PHYSICAL_ADDRESS StackBase, - IN UINTN StackSize + IN UINTN StackSize, + IN EFI_PHYSICAL_ADDRESS GhcbBase, + IN UINTN GhcbSize ) { EFI_PHYSICAL_ADDRESS PhysicalAddress4K; @@ -355,7 +369,20 @@ Split2MPageTo4K ( // // Fill in the Page Table entries // - PageTableEntry->Uint64 =3D (UINT64) PhysicalAddress4K | AddressEncMask; + PageTableEntry->Uint64 =3D (UINT64) PhysicalAddress4K; + + // + // The GHCB range consists of two pages per CPU, the GHCB and a + // per-CPU variable page. The GHCB page needs to be mapped as an + // unencrypted page while the per-CPU variable page needs to be + // mapped encrypted. These pages alternate in assignment. + // + if ((GhcbBase =3D=3D 0) + || (PhysicalAddress4K < GhcbBase) + || (PhysicalAddress4K >=3D GhcbBase + GhcbSize) + || (((PhysicalAddress4K - GhcbBase) & SIZE_4KB) !=3D 0)) { + PageTableEntry->Uint64 |=3D AddressEncMask; + } PageTableEntry->Bits.ReadWrite =3D 1; =20 if ((IsNullDetectionEnabled () && PhysicalAddress4K =3D=3D 0) || @@ -383,6 +410,8 @@ Split2MPageTo4K ( @param[in, out] PageEntry1G Pointer to 1G page entry. @param[in] StackBase Stack base address. @param[in] StackSize Stack size. + @param[in] GhcbBase GHCB page area base address. + @param[in] GhcbSize GHCB page area size. =20 **/ VOID @@ -390,7 +419,9 @@ Split1GPageTo2M ( IN EFI_PHYSICAL_ADDRESS PhysicalAddress, IN OUT UINT64 *PageEntry1G, IN EFI_PHYSICAL_ADDRESS StackBase, - IN UINTN StackSize + IN UINTN StackSize, + IN EFI_PHYSICAL_ADDRESS GhcbBase, + IN UINTN GhcbSize ) { EFI_PHYSICAL_ADDRESS PhysicalAddress2M; @@ -413,11 +444,11 @@ Split1GPageTo2M ( =20 PhysicalAddress2M =3D PhysicalAddress; for (IndexOfPageDirectoryEntries =3D 0; IndexOfPageDirectoryEntries < 51= 2; IndexOfPageDirectoryEntries++, PageDirectoryEntry++, PhysicalAddress2M += =3D SIZE_2MB) { - if (ToSplitPageTable (PhysicalAddress2M, SIZE_2MB, StackBase, StackSiz= e)) { + if (ToSplitPageTable (PhysicalAddress2M, SIZE_2MB, StackBase, StackSiz= e, GhcbBase, GhcbSize)) { // // Need to split this 2M page that covers NULL or stack range. // - Split2MPageTo4K (PhysicalAddress2M, (UINT64 *) PageDirectoryEntry, S= tackBase, StackSize); + Split2MPageTo4K (PhysicalAddress2M, (UINT64 *) PageDirectoryEntry, S= tackBase, StackSize, GhcbBase, GhcbSize); } else { // // Fill in the Page Directory entries @@ -616,6 +647,8 @@ EnablePageTableProtection ( =20 @param[in] StackBase Stack base address. @param[in] StackSize Stack size. + @param[in] GhcbBase GHCB base address. + @param[in] GhcbSize GHCB size. =20 @return The address of 4 level page map. =20 @@ -623,7 +656,9 @@ EnablePageTableProtection ( UINTN CreateIdentityMappingPageTables ( IN EFI_PHYSICAL_ADDRESS StackBase, - IN UINTN StackSize + IN UINTN StackSize, + IN EFI_PHYSICAL_ADDRESS GhcbBase, + IN UINTN GhcbSize ) { UINT32 RegEax; @@ -809,8 +844,8 @@ CreateIdentityMappingPageTables ( PageDirectory1GEntry =3D (VOID *) PageDirectoryPointerEntry; =20 for (IndexOfPageDirectoryEntries =3D 0; IndexOfPageDirectoryEntrie= s < 512; IndexOfPageDirectoryEntries++, PageDirectory1GEntry++, PageAddress= +=3D SIZE_1GB) { - if (ToSplitPageTable (PageAddress, SIZE_1GB, StackBase, StackSiz= e)) { - Split1GPageTo2M (PageAddress, (UINT64 *) PageDirectory1GEntry,= StackBase, StackSize); + if (ToSplitPageTable (PageAddress, SIZE_1GB, StackBase, StackSiz= e, GhcbBase, GhcbSize)) { + Split1GPageTo2M (PageAddress, (UINT64 *) PageDirectory1GEntry,= StackBase, StackSize, GhcbBase, GhcbSize); } else { // // Fill in the Page Directory entries @@ -840,11 +875,11 @@ CreateIdentityMappingPageTables ( PageDirectoryPointerEntry->Bits.Present =3D 1; =20 for (IndexOfPageDirectoryEntries =3D 0; IndexOfPageDirectoryEntr= ies < 512; IndexOfPageDirectoryEntries++, PageDirectoryEntry++, PageAddress= +=3D SIZE_2MB) { - if (ToSplitPageTable (PageAddress, SIZE_2MB, StackBase, StackS= ize)) { + if (ToSplitPageTable (PageAddress, SIZE_2MB, StackBase, StackS= ize, GhcbBase, GhcbSize)) { // // Need to split this 2M page that covers NULL or stack rang= e. // - Split2MPageTo4K (PageAddress, (UINT64 *) PageDirectoryEntry,= StackBase, StackSize); + Split2MPageTo4K (PageAddress, (UINT64 *) PageDirectoryEntry,= StackBase, StackSize, GhcbBase, GhcbSize); } else { // // Fill in the Page Directory entries --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63309): https://edk2.groups.io/g/devel/message/63309 Mute This Topic: https://groups.io/mt/75824943/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 Fri Apr 26 07:16:41 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+63310+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+63310+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 1595863648422968.3725343038013; Mon, 27 Jul 2020 08:27:28 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id IVl7YY1788612xSl3WqXQt7E; Mon, 27 Jul 2020 08:27:28 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.74]) by mx.groups.io with SMTP id smtpd.web11.58061.1595863647348071740 for ; Mon, 27 Jul 2020 08:27:27 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gxDKjDhXl/NUOvgtvYc1K8TYR4yGrrZWHcMcrKQf0X6vNKTqZE1BlzMoDGHlDo9ft1FT5NmwFKkrdWdeRnoYRruSmlMXE8hVxpq8iXUOvx3ua0WZ5j76xKtiiVt+RO1jdfX4ByOCV0n//i4jW79EJwRbo9RS6RkqcC/5YcvmE3d0eSk1WfjP7CxTwAWY3HgN0+M8D0H9mQbN9lyx1L8js0KAEY4injc99ZgTlPF77RI9QD1masNHMvFEM41e/H3Sd8egNurKPE3j6l9ZgiDqbFw2dB6B1GGfYNTKNxKJvpNmtYeD2x7OQ7cePdHScG3Mhy2NeGkkNie/X1bLBVz6Sw== 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=g94cNBqzH3Pv2WbNbKL2BUYjnAJh6O9Iy6b2wbCpMvU=; b=feiwxDo4FEeUobMQG8kkSEBDt50IraA0wD6DX5io+H0u6rvaNHSTsAVLOqRIOq//KEGgdCj2VagyZxEomBKJMhq5itx5K3b1pom3p0SL+B15xAHroageM55Us/1YSJoqH1sAZ6fi+t6xRlgEPct/rM18Ij/HVcKuJZehYGrmL9aq+OTgSHdOEwPYpoeCzgMoouMgDTPvTz0xiZ8Pw+3yo0eeb495RUw4zzGZktPUIch4DS6kuh9a4y3YWlhFa2628UiSau/UC+Rb72Q+3G2xZHJnVK8g2HQU1SgLNH/Em/FkpMxtVwgpp3dNUJNZD+nFXMFr8uFt/puxhxrOVstxHQ== 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 DM5PR12MB1641.namprd12.prod.outlook.com (2603:10b6:4:10::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23; Mon, 27 Jul 2020 15:27:25 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:27:25 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 06/46] MdePkg/BaseLib: Add support for the XGETBV instruction Date: Mon, 27 Jul 2020 10:25:47 -0500 Message-ID: <89f5fd560670f63c480ea2675fa9465b12b6003e.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0057.namprd05.prod.outlook.com (2603:10b6:803:41::34) 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 SN4PR0501CA0057.namprd05.prod.outlook.com (2603:10b6:803:41::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.10 via Frontend Transport; Mon, 27 Jul 2020 15:27:24 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 259056d1-6951-45d3-16bd-08d832419080 X-MS-TrafficTypeDiagnostic: DM5PR12MB1641: 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: gkB9/yYFOL6LtsOvGFBkWW7QbfmIACWCGEQa7MBPK9ZjMdESBw8K56lHtpOIiP7g029aETF9UC8gZUyMpsVFD8OAWjQK7OqxBN0U8pL7oLOxbfzAwi3mYcM8WBeyWmJyELkne8D68oO3h9jB+vgCnkj5uEtWOnYiDyNPSrRdPGtmou1Sir+y+OVPk/3QEeH7NfUUFeZ1zHKcB4h6aHR5CUJPbmywkaOd1JrUcky9yvliGbwKI1K3hd0813E8IkqEM+wllaDj4uO8tkz1baMLp85nJ1QPCvyEuILsL+/f1gmOILWZNVHXJhh5Mq+i5V+41T23p+JltlHzUizh4ZC/TaP4bedqkuBM0bi1xp9rs+9uFgTYYosQfKPUKCLaEtYiCZc7iUbJCOn3CDRRMGRhK3f9ngIMzHumxgi6rHqyrwwxORMiyJr5DIJ+DWrSD9th8ggL46pE0GvNHOBUbqlmbw== X-MS-Exchange-AntiSpam-MessageData: l71qMobmK4Wpg2kXpZ5yunw6pKax4l2ZyfuLR7djB5a2536mwFUUe5EjXRATJsSh3UakALIyKqhNScGm5HJhQy83mCqHbserYVoeWG/ML0ZNibmlb7HwpzqV8bhRtRtntCAwbsdJw4cTTtXYTxAb5cMBPZLuVdfAWX67maopP9qftQSA72TWedwkGAahflI57h5hEwKjIFY+7o5wbJmxOLDIAa1ZJ2jtrIlJnCPzGw4ac2P9eTLnwnK3FfTV1li1wfi6eYJp5j6kwOiSBLzow7V3Sxmzfm2SEelx8BgcPgqn/GkIXHrrI4ki344+QS5G51t6/IiZ7ZFGzLaezG2tnOaTMWh1uHgiwaHzAxBZlWhpR0fFpwabZt2HE7w5I98bmf1I57Jy1aCjdnAx4HXjUuHg8bAkhWANDymC/NJMtGYqSDFvL5E07AB6Kzqm5KzENWCF2tGPiyC+psJrLkdbiaf3mFC6EUHcWBqSPKERMNc= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 259056d1-6951-45d3-16bd-08d832419080 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:27:25.2741 (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: N543GWWYrF2pSnBF6mknRUQoItRr/FI2uAYhUIVMFEKxm6nDgI6KDgVL0ui34waucLjA5XPYrOqG18HS7F3dXQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1641 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: bk9A440MMdRKmWoP0Xv6TWaex1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863648; bh=Kw1HyKiF70tzpx8+fv04v4ADQz/9b7A1yvZa+opEJ/4=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Y6DZcu7/LYn+hr2SHnVLUrfFelC3z61DABqzKnGcPV4YMyRgJehoMNMS8eJuFUB5cpj DekjZDbJNqa40WEhPRu23o8o+oB2FG5XcBQFyxiKeLxsjctjV1SAOIl6c4a7WgqXJZzvl SdsXdZmRi0q2C8Xla7LtdUjzdomRdipWxXo= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a CPUID instruction requires the current value of the XCR0 register. In order to retrieve that value, the XGETBV instruction needs to be executed. Provide the necessary support to execute the XGETBV instruction. Cc: Michael D Kinney Cc: Liming Gao Signed-off-by: Tom Lendacky --- MdePkg/Library/BaseLib/BaseLib.inf | 2 ++ MdePkg/Include/Library/BaseLib.h | 17 +++++++++++++ MdePkg/Library/BaseLib/Ia32/XGetBv.nasm | 31 ++++++++++++++++++++++ MdePkg/Library/BaseLib/X64/XGetBv.nasm | 34 +++++++++++++++++++++++++ 4 files changed, 84 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 c740a819cacf..3b93b5db8d24 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -183,6 +183,7 @@ [Sources.Ia32] Ia32/EnableCache.nasm| GCC Ia32/DisableCache.nasm| GCC Ia32/RdRand.nasm + Ia32/XGetBv.nasm =20 Ia32/DivS64x64Remainder.c Ia32/InternalSwitchStack.c | MSFT @@ -315,6 +316,7 @@ [Sources.X64] X64/EnableDisableInterrupts.nasm X64/DisablePaging64.nasm X64/RdRand.nasm + X64/XGetBv.nasm ChkStkGcc.c | GCC =20 [Sources.EBC] diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Base= Lib.h index 8e7b87cbda4e..7edf0051a0a0 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -7831,6 +7831,23 @@ AsmLfence ( VOID ); =20 +/** + Executes a XGETBV instruction + + Executes a XGETBV instruction. This function is only available on IA-32 = and + x64. + + @param[in] Index Extended control register index + + @return The current value of the extended control regist= er +**/ +UINT64 +EFIAPI +AsmXGetBv ( + IN UINT32 Index + ); + + /** Patch the immediate operand of an IA32 or X64 instruction such that the = byte, word, dword or qword operand is encoded at the end of the instruction's diff --git a/MdePkg/Library/BaseLib/Ia32/XGetBv.nasm b/MdePkg/Library/BaseL= ib/Ia32/XGetBv.nasm new file mode 100644 index 000000000000..9f7b03bbff35 --- /dev/null +++ b/MdePkg/Library/BaseLib/Ia32/XGetBv.nasm @@ -0,0 +1,31 @@ +;-------------------------------------------------------------------------= ----- +; +; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent +; +; Module Name: +; +; XGetBv.Asm +; +; Abstract: +; +; AsmXgetBv function +; +; Notes: +; +;-------------------------------------------------------------------------= ----- + + SECTION .text + +;-------------------------------------------------------------------------= ----- +; UINT64 +; EFIAPI +; AsmXGetBv ( +; IN UINT32 Index +; ); +;-------------------------------------------------------------------------= ----- +global ASM_PFX(AsmXGetBv) +ASM_PFX(AsmXGetBv): + mov ecx, [esp + 4] + xgetbv + ret diff --git a/MdePkg/Library/BaseLib/X64/XGetBv.nasm b/MdePkg/Library/BaseLi= b/X64/XGetBv.nasm new file mode 100644 index 000000000000..09f3be8ae0a8 --- /dev/null +++ b/MdePkg/Library/BaseLib/X64/XGetBv.nasm @@ -0,0 +1,34 @@ +;-------------------------------------------------------------------------= ----- +; +; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent +; +; Module Name: +; +; XGetBv.Asm +; +; Abstract: +; +; AsmXgetBv function +; +; Notes: +; +;-------------------------------------------------------------------------= ----- + + DEFAULT REL + SECTION .text + +;-------------------------------------------------------------------------= ----- +; UINT64 +; EFIAPI +; AsmXGetBv ( +; IN UINT32 Index +; ); +;-------------------------------------------------------------------------= ----- +global ASM_PFX(AsmXGetBv) +ASM_PFX(AsmXGetBv): + xgetbv + shl rdx, 32 + or rax, rdx + ret + --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63310): https://edk2.groups.io/g/devel/message/63310 Mute This Topic: https://groups.io/mt/75824946/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 Fri Apr 26 07:16:41 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+63311+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+63311+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 1595863656830521.2631807676705; Mon, 27 Jul 2020 08:27:36 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id RogFYY1788612xSnYOcszv4X; Mon, 27 Jul 2020 08:27:36 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.86]) by mx.groups.io with SMTP id smtpd.web11.58063.1595863654796106026 for ; Mon, 27 Jul 2020 08:27:35 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gDLSyeninPN/1bDrf3b/tkhAxRJJL0W3M2t+x7Rt+C6lQ3Njt9PQcy+rRdvpvcE3sqYpcFwkhSvXH4ngwEZ10VOXYipiMTTWpatBskjsuuCpW/z4bgKenq08jBO5vzoLdHXOnjuFVEHQxWzr+WhuFeuh0Pwk0eXVsqJpCRrm0B6qPZ4YJOGutnqwEvADhIVvVh1xcqzWL3TYvydbWFawTarmw2Nqz8cWeIXanaatX91Z6D98rBKdfxgummXxVmPSuAFEBHHMwFnZNNvugBDogMB9D2OujgCv66vdgd98T0LnUO0A6V3L4CCf+xYeiOmls8EyYPJHqMPS1MlRYI4Q3g== 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=RN57yb4RJNDqTuZ4cHnGM1ke1psoHmy61BOicJm8d8E=; b=OhInD7CDOKJHN4AFkC+z25oHbCp2i6bo9uro+aLnLMZ3L7Xs/IgQTaj9QLSII41hjvlsgIUEPmCUPj62RJRdLfYJ94RV0QP15m9LrciAWXIvgf4w1gLhIfwKiw2sG199HNYXx23PBUTN+/amyY06JT1WcRi2uj5fLUJ0Pkb/0cbMaIrfkDfQHu5g9El1WpPdtW41pdOo/fnXf9hmq0otshvmXoYvXJH7jFIUzOm00Kgy2jRpLZfXcn41YO4CKGfmv3E6oqQ9UPIw1C3CzM2Q0RedcUFCu4kaIj9bVs/jxWIn00bOcBUUH+4D0YizfXk3dUSXu66TmFQb3WC7E1mR9A== 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 DM5PR12MB1641.namprd12.prod.outlook.com (2603:10b6:4:10::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23; Mon, 27 Jul 2020 15:27:33 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:27:33 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 07/46] MdePkg/BaseLib: Add support for the VMGEXIT instruction Date: Mon, 27 Jul 2020 10:25:48 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SA0PR11CA0004.namprd11.prod.outlook.com (2603:10b6:806:d3::9) 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 SA0PR11CA0004.namprd11.prod.outlook.com (2603:10b6:806:d3::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.20 via Frontend Transport; Mon, 27 Jul 2020 15:27: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: a60a6c5c-2c5a-4fa4-2c8e-08d832419533 X-MS-TrafficTypeDiagnostic: DM5PR12MB1641: 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: w/Qo+/wqYC3wdyo5NwWdOFCth+baV2jyOChbLNDjLuSldlkBgMLZDcrwhOWr5IZTJPAHSd8M/gkG30cqYnyzMLb2GUh+s3DDP501zL/r+4sWtw+zcqMeybq81rNedtrtRBiMtMSK+qEgs0vKgcc99JilbJSxco7gZKO9RvHjKS4NmERg+eTMrftqvdWCngUEKxa/lFuzJUblnhupLfILuMSBeJ2lGv94+lMDSDEC8jmx9fPLLF45FytyTADkkBQd16k759k6Uk/81DZlA5dduJcdk37P4cl6wU4eWeU0O83S+pYEKfG6WEAu/kPXSQ3RcIo6bKLm4qhTmm9gddo2IoBPjeaNur4NWfT758vDVnBIdsAjoZPsqPp+c8p2QkEoS7qJtmn6zKlFnHntNfsthAypIgBkz8FTeD3Q222Snx6ciSW3biEdPK9obqFmH/Hg+W2k6F0OneJOcA7eeCXBQg== X-MS-Exchange-AntiSpam-MessageData: bAAhBqS9uSUKjeJY1Ii4F6u9zZS0AAz7Pj1dUNDwA5NMTr7OW9neAvfcMal1VVy0Hh8V1iGBxFyWKy8Yay4Gq1pI/+LKalFzOkP69G8h4n4pfK9QIMl0C75WxKLOXOPee9tGzaF0MXGtxFlqgoXZtql6Gwo7Lf44mBV8Btr3qj/xxgubNg+ub5s2QMNo7Zs6lNQrs4koDPRmJ1IjGhGsPUzLmSP23vUVapgbfD6sdMhpN3bsnB+4Fz6+9kz0OTel/DwIjh41RiGV7MBEo9sx3NXHgcfa5IgHP+OAyCgL6kzoF1dZEZtWKZCqtk45Hhkob8WLcD4uQg+r8/pQ+sAMYXtMaRmEi5lvGtiOwAt7ICKp6C+QmAbLDrPIL9IU29d1Fc+H6d+qjgWIWOYuaLE0VLvbodv0aWkVYyxfuc1EVgLfH4ODueNVFDIfThOETF2mzqeNThrnildNgomE7yPS/DukgD05+HOTH72Pf0K8c+Q= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a60a6c5c-2c5a-4fa4-2c8e-08d832419533 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:27:33.1396 (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: eM/GFhXt3kfJcxwAqOoPTohTSXKTmbKYSIGSTBg9/A8EWu8Pv7C9cNHIpxZKOZKuBcdsGS+Qs2WYytqHXgzopQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1641 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: rrcNALW9X92f001wTnx3M7Cpx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863656; bh=OyCv2ABSNald9dyyCszWAZHJavTw0K2mlE+V35RXnbw=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=BqN8jZsvxR17M38cV0HBtQIUEHu0ndFVGGY1te6AozVzErVqXChdCr7T7eHnQtmSs20 SPhkK0mZewaOnDKeDVOZLizmPleqRyhgvXN65a9tPjBdGZadYkXCHcBRNgVDzW8KVupHF 23lBueWINKHyuC9+oHQeDue94FVl/8vPJMU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 VMGEXIT is a new instruction used for Hypervisor/Guest communication when running as an SEV-ES guest. A VMGEXIT will cause an automatic exit (AE) to occur, resulting in a #VMEXIT with an exit code value of 0x403. Provide the necessary support to execute the VMGEXIT instruction, which is "rep; vmmcall". Cc: Michael D Kinney Cc: Liming Gao Signed-off-by: Tom Lendacky --- MdePkg/Library/BaseLib/BaseLib.inf | 2 ++ MdePkg/Include/Library/BaseLib.h | 14 +++++++++ MdePkg/Library/BaseLib/Ia32/VmgExit.nasm | 37 ++++++++++++++++++++++++ MdePkg/Library/BaseLib/X64/VmgExit.nasm | 32 ++++++++++++++++++++ 4 files changed, 85 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 3b93b5db8d24..3b85c56c3c03 100644 --- a/MdePkg/Library/BaseLib/BaseLib.inf +++ b/MdePkg/Library/BaseLib/BaseLib.inf @@ -184,6 +184,7 @@ [Sources.Ia32] Ia32/DisableCache.nasm| GCC Ia32/RdRand.nasm Ia32/XGetBv.nasm + Ia32/VmgExit.nasm =20 Ia32/DivS64x64Remainder.c Ia32/InternalSwitchStack.c | MSFT @@ -317,6 +318,7 @@ [Sources.X64] X64/DisablePaging64.nasm X64/RdRand.nasm X64/XGetBv.nasm + X64/VmgExit.nasm ChkStkGcc.c | GCC =20 [Sources.EBC] diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Base= Lib.h index 7edf0051a0a0..04fb329eaabb 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -7848,6 +7848,20 @@ AsmXGetBv ( ); =20 =20 +/** + Executes a VMGEXIT instruction (VMMCALL with a REP prefix) + + Executes a VMGEXIT instruction. This function is only available on IA-32= and + x64. + +**/ +VOID +EFIAPI +AsmVmgExit ( + VOID + ); + + /** Patch the immediate operand of an IA32 or X64 instruction such that the = byte, word, dword or qword operand is encoded at the end of the instruction's diff --git a/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm b/MdePkg/Library/Base= Lib/Ia32/VmgExit.nasm new file mode 100644 index 000000000000..a4b37385cc7a --- /dev/null +++ b/MdePkg/Library/BaseLib/Ia32/VmgExit.nasm @@ -0,0 +1,37 @@ +;-------------------------------------------------------------------------= ----- +; +; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent +; +; Module Name: +; +; VmgExit.Asm +; +; Abstract: +; +; AsmVmgExit function +; +; Notes: +; +;-------------------------------------------------------------------------= ----- + + SECTION .text + +;-------------------------------------------------------------------------= ----- +; VOID +; EFIAPI +; AsmVmgExit ( +; VOID +; ); +;-------------------------------------------------------------------------= ----- +global ASM_PFX(AsmVmgExit) +ASM_PFX(AsmVmgExit): +; +; NASM doesn't support the vmmcall instruction in 32-bit mode, so work aro= und +; this by temporarily switching to 64-bit mode. +; +BITS 64 + rep vmmcall +BITS 32 + ret + diff --git a/MdePkg/Library/BaseLib/X64/VmgExit.nasm b/MdePkg/Library/BaseL= ib/X64/VmgExit.nasm new file mode 100644 index 000000000000..26f034593c67 --- /dev/null +++ b/MdePkg/Library/BaseLib/X64/VmgExit.nasm @@ -0,0 +1,32 @@ +;-------------------------------------------------------------------------= ----- +; +; Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent +; +; Module Name: +; +; VmgExit.Asm +; +; Abstract: +; +; AsmVmgExit function +; +; Notes: +; +;-------------------------------------------------------------------------= ----- + + DEFAULT REL + SECTION .text + +;-------------------------------------------------------------------------= ----- +; VOID +; EFIAPI +; AsmVmgExit ( +; VOID +; ); +;-------------------------------------------------------------------------= ----- +global ASM_PFX(AsmVmgExit) +ASM_PFX(AsmVmgExit): + rep vmmcall + ret + --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63311): https://edk2.groups.io/g/devel/message/63311 Mute This Topic: https://groups.io/mt/75824947/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 Fri Apr 26 07:16:41 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+63312+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+63312+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 1595863665975386.12173160803763; Mon, 27 Jul 2020 08:27:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id a66XYY1788612xEZTt04AzJA; Mon, 27 Jul 2020 08:27:45 -0700 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.83]) by mx.groups.io with SMTP id smtpd.web10.58313.1595863664490719618 for ; Mon, 27 Jul 2020 08:27:44 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E1Kse+tCPiEYKU/2/xNqA7oHRQmjGvR1KuL8UzEpiiZOh0hFaKOO/TL66EH330A4OX4BW1K50InKvAUb8aAQ5tLfaQUmPHxp6SRvxj7JlEWEzmT/fo7GVshRDWwfuweR089fSlRg98YMtXK86U5V+bKzbRq0G7ETfx/tBQYrkuHCPiJ6QaDP5pST5hcKznmsNTRJBUoXhXDH4IY4YyXKmjVHEQuSyyts/m8GErbWelw1Da1toeqMBNYEziw0aVoENJiG1xw4wlD5oR2a/1zQdLwTdB5vwvhG8LrUhGmWtT22fRG4i5o7+PVBVoVnAxEc42X/8nGkHCrT71omowk+6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/BJELomezd9RuQOtYb+gTmMe10Anbl6BkYn9LkHsNc0=; b=NxjWLPnYPxCBnT8ImvP+msck5+/ew0fSRHQWtX3SYR0uR6BSZhPrs44OdTwD7L1HstOS575/QhudBBCQduN8WEo9haiba/f6QD/jzgzR3IpfvEGR3spCYQzrhzhYG1g+yqALAcOWn1m5K7Nkm37P88Dg1fTPwTbrnQnyxWPRqOmD71AGfgA/zljgE3Wq2GDKxA/0vjxubQX+8uhmiOARp1gNUjPb5moZSJOa0RpzF1AzPhr2EICSX81RAtYqma+sUXBrCSQPR3MfrYZaugt3GQ0sZt6AR6pv8FEx1ilRLprmEkca+biBXa5Y3zr1RIiEb1O09tqA9DwIdzp4s+qUFQ== 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 DM5PR12MB1641.namprd12.prod.outlook.com (2603:10b6:4:10::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23; Mon, 27 Jul 2020 15:27:42 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:27:42 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 08/46] UefiCpuPkg: Implement library support for VMGEXIT Date: Mon, 27 Jul 2020 10:25:49 -0500 Message-ID: <9535443922aa016c0f61422654549444c61b0b34.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0126.namprd05.prod.outlook.com (2603:10b6:803:42::43) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0501CA0126.namprd05.prod.outlook.com (2603:10b6:803:42::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.10 via Frontend Transport; Mon, 27 Jul 2020 15:27: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: 5486dee7-3bf5-4c75-3c3b-08d832419a91 X-MS-TrafficTypeDiagnostic: DM5PR12MB1641: 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: uiHLX9Sf8C3X04711+TuTGDttxuE+Iau257oxUovc1nzUVOVVCwbt9KaeGT5T1XYt5sYHH1pON5pidilyHwIKYKUWXviYLV8koXQ2ARGQ9rvJt6x8Aa7XBlTYmJ61dTzQyQ/gUNrUSJttV72u/qrSstd8Q/0mAn5ynXddOLedcMrY1Tjb0ATokp1EK91UVPUEkSraS2asGfZPKccGvZyDSsqzcXkIQZoMLG/YxXeoviZkmUIyKt/wHr3nx6jsYh0pN0GszlGS8EygpPCzvd0X7P8z39tp1ufcCFDNg+rYK8UWmAN7R9dYcHVkDCHNpjdsM1302BKcor3tFj+lawk3839D3Zu3ei7LV4Gw7yv/wl9pl5EULd8923cYmIGWXUvEsEHzvCLmEUTi1+c1rHiBUNIa9b0EEkfk8kbkvUqClV2/bZ5CJnMxqU3MGpF9R5/Ssf8REGV0lzJgpC5UmRrFA== X-MS-Exchange-AntiSpam-MessageData: DtxlgvpKsQeiCAkpnwqhPkkeHh9DZIxdLlskHwyoGbP7qxjyKgarcq/UJcpdMOx+Wh+X7OjwEhAogByESbgsvtIEUkaw3t0JEbOVfzPmrJC1lIlUQyPUiBJdVuEVlTJANlFjn8L54il4ggMu3WXr3OeANC1F4akkCONtX1CzJuu5XgKBlZPJgiCRt36TP7wgZHN+SIHWhXMd6VNx/NI6ecj3dehzsZcYNohp6dKqHIWBynFwGeDlutkNADGBZVQw1pBoFMAKIZ+NFostpitcZyzbzRfCHLu3Fc0hQSNyHmBWwkhoQMM/ebFra68FCdL5+Vxr4cJ8swI37yrPP/Ghr9HXw2568A7yxinGVXbhSthdkAykEybs9MpuKJLn3OWhQVcUZJ61f1F0KJ1dA6rculz8659N3UlZMVnfxEG9Djp4pOdNewt2f6ZWox9D0XxvWKD595Os4ZYw3HtOuw2dpLmlG1mxlqwCsfCEOikpw40= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5486dee7-3bf5-4c75-3c3b-08d832419a91 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:27:42.2076 (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: ZJLWRKFsdzKD6v7UO2D9FL5byICjhoQu6iHO5dZneILXClC0bNxeGnbrYyqSnKhmiIkw0TB+DRXD6tljBjMz4w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1641 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: EeO1zLuxAOR8JQWnkR5Z6cqix1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863665; bh=Y7csS6OQOlSSQrDalGQZ6JtHn5XflpTqAMIA5gy7M84=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=CErx3MBP8n4v9yodFLmsHO3Rmf2VACLeTY5+zlW0REK71ep4OoQUTv033SIcG/8pMVG aVNywCJtKdNk4Xd5WNZ3vB+7HkYHWdehE59h3Xuds8b65BJbQkh8T4oqHRUZVh1KQNvar dVPT7FfPgGUnlEElVcS54+cLcRKGrZrPHUE= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 To support handling #VC exceptions and issuing VMGEXIT instructions, create a library with functions that can be used to perform these #VC/VMGEXIT related operations. This includes functions for: - Handling #VC exceptions - Preparing for and issuing a VMGEXIT - Performing MMIO-related write operations to support flash emulation - Performing AP related boot opeations The base functions in this driver will not do anything and will return an error if a return value is required. It is expected that other packages (like OvmfPkg) will create a version of the library to fully support an SEV-ES guest. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Reviewed-by: Eric Dong Signed-off-by: Tom Lendacky --- UefiCpuPkg/UefiCpuPkg.dec | 3 + UefiCpuPkg/UefiCpuPkg.dsc | 2 + .../Library/VmgExitLibNull/VmgExitLibNull.inf | 27 ++++ UefiCpuPkg/Include/Library/VmgExitLib.h | 103 +++++++++++++++ .../Library/VmgExitLibNull/VmgExitLibNull.c | 121 ++++++++++++++++++ .../Library/VmgExitLibNull/VmgExitLibNull.uni | 15 +++ 6 files changed, 271 insertions(+) create mode 100644 UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf create mode 100644 UefiCpuPkg/Include/Library/VmgExitLib.h create mode 100644 UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c create mode 100644 UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index df5d02bae6b4..cb92f34b6f55 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -53,6 +53,9 @@ [LibraryClasses.IA32, LibraryClasses.X64] ## MpInitLib|Include/Library/MpInitLib.h =20 + ## @libraryclass Provides function to support VMGEXIT processing. + VmgExitLib|Include/Library/VmgExitLib.h + [Guids] gUefiCpuPkgTokenSpaceGuid =3D { 0xac05bf33, 0x995a, 0x4ed4, { 0xaa,= 0xb8, 0xef, 0x7a, 0xe8, 0xf, 0x5c, 0xb0 }} gMsegSmramGuid =3D { 0x5802bce4, 0xeeee, 0x4e33, { 0xa1,= 0x30, 0xeb, 0xad, 0x27, 0xf0, 0xe4, 0x39 }} diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc index afa304128221..f0e58b90ff0a 100644 --- a/UefiCpuPkg/UefiCpuPkg.dsc +++ b/UefiCpuPkg/UefiCpuPkg.dsc @@ -56,6 +56,7 @@ [LibraryClasses] PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeC= offGetEntryPointLib.inf PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BasePeC= offExtraActionLibNull.inf TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurem= entLibNull.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 [LibraryClasses.common.SEC] PlatformSecLib|UefiCpuPkg/Library/PlatformSecLibNull/PlatformSecLibNull.= inf @@ -143,6 +144,7 @@ [Components.IA32, Components.X64] UefiCpuPkg/Library/SmmCpuPlatformHookLibNull/SmmCpuPlatformHookLibNull.i= nf UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLibStm.inf + UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationPei.inf UefiCpuPkg/PiSmmCommunication/PiSmmCommunicationSmm.inf UefiCpuPkg/SecCore/SecCore.inf diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf b/UefiCpu= Pkg/Library/VmgExitLibNull/VmgExitLibNull.inf new file mode 100644 index 000000000000..d8770a21c355 --- /dev/null +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf @@ -0,0 +1,27 @@ +## @file +# VMGEXIT Support Library. +# +# Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D VmgExitLibNull + MODULE_UNI_FILE =3D VmgExitLibNull.uni + FILE_GUID =3D 3cd7368f-ef9b-4a9b-9571-2ed93813677e + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D VmgExitLib + +[Sources.common] + VmgExitLibNull.c + +[Packages] + MdePkg/MdePkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + diff --git a/UefiCpuPkg/Include/Library/VmgExitLib.h b/UefiCpuPkg/Include/L= ibrary/VmgExitLib.h new file mode 100644 index 000000000000..45fc27d35e29 --- /dev/null +++ b/UefiCpuPkg/Include/Library/VmgExitLib.h @@ -0,0 +1,103 @@ +/** @file + Public header file for the VMGEXIT Support library class. + + This library class defines some routines used when invoking the VMGEXIT + instruction in support of SEV-ES and to handle #VC exceptions. + + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef __VMG_EXIT_LIB_H__ +#define __VMG_EXIT_LIB_H__ + +#include +#include + + +/** + Perform VMGEXIT. + + Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction a= nd + then handles the return actions. + + @param[in, out] Ghcb A pointer to the GHCB + @param[in] ExitCode VMGEXIT code to be assigned to the SwExitCode + field of the GHCB. + @param[in] ExitInfo1 VMGEXIT information to be assigned to the + SwExitInfo1 field of the GHCB. + @param[in] ExitInfo2 VMGEXIT information to be assigned to the + SwExitInfo2 field of the GHCB. + + @retval 0 VMGEXIT succeeded. + @return Exception number to be propagated, VMGEXIT + processing did not succeed. + +**/ +UINT64 +EFIAPI +VmgExit ( + IN OUT GHCB *Ghcb, + IN UINT64 ExitCode, + IN UINT64 ExitInfo1, + IN UINT64 ExitInfo2 + ); + +/** + Perform pre-VMGEXIT initialization/preparation. + + Performs the necessary steps in preparation for invoking VMGEXIT. Must be + called before setting any fields within the GHCB. + + @param[in, out] Ghcb A pointer to the GHCB + +**/ +VOID +EFIAPI +VmgInit ( + IN OUT GHCB *Ghcb + ); + +/** + Perform post-VMGEXIT cleanup. + + Performs the necessary steps to cleanup after invoking VMGEXIT. Must be + called after obtaining needed fields within the GHCB. + + @param[in, out] Ghcb A pointer to the GHCB + +**/ +VOID +EFIAPI +VmgDone ( + IN OUT GHCB *Ghcb + ); + +/** + Handle a #VC exception. + + Performs the necessary processing to handle a #VC exception. + + The base library function returns an error equal to VC_EXCEPTION, + to be propagated to the standard exception handling stack. + + @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be s= et + as value to use on error. + @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT + + @retval EFI_SUCCESS Exception handled + @retval EFI_UNSUPPORTED #VC not supported, (new) exception value= to + propagate provided + @retval EFI_PROTOCOL_ERROR #VC handling failed, (new) exception val= ue to + propagate provided + +**/ +EFI_STATUS +EFIAPI +VmgExitHandleVc ( + IN OUT EFI_EXCEPTION_TYPE *ExceptionType, + IN OUT EFI_SYSTEM_CONTEXT SystemContext + ); + +#endif diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c b/UefiCpuPk= g/Library/VmgExitLibNull/VmgExitLibNull.c new file mode 100644 index 000000000000..bb265e1700d2 --- /dev/null +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.c @@ -0,0 +1,121 @@ +/** @file + VMGEXIT Base Support Library. + + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include + +/** + Perform VMGEXIT. + + Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction a= nd + then handles the return actions. + + The base library function returns an error in the form of a + GHCB_EVENT_INJECTION representing a GP_EXCEPTION. + + @param[in, out] Ghcb A pointer to the GHCB + @param[in] ExitCode VMGEXIT code to be assigned to the SwExitCode + field of the GHCB. + @param[in] ExitInfo1 VMGEXIT information to be assigned to the + SwExitInfo1 field of the GHCB. + @param[in] ExitInfo2 VMGEXIT information to be assigned to the + SwExitInfo2 field of the GHCB. + + @retval 0 VMGEXIT succeeded. + @return Exception number to be propagated, VMGEXIT + processing did not succeed. + +**/ +UINT64 +EFIAPI +VmgExit ( + IN OUT GHCB *Ghcb, + IN UINT64 ExitCode, + IN UINT64 ExitInfo1, + IN UINT64 ExitInfo2 + ) +{ + GHCB_EVENT_INJECTION Event; + + Event.Uint64 =3D 0; + Event.Elements.Vector =3D GP_EXCEPTION; + Event.Elements.Type =3D GHCB_EVENT_INJECTION_TYPE_EXCEPTION; + Event.Elements.Valid =3D 1; + + return Event.Uint64; +} + +/** + Perform pre-VMGEXIT initialization/preparation. + + Performs the necessary steps in preparation for invoking VMGEXIT. Must be + called before setting any fields within the GHCB. + + The base library function does nothing. + + @param[in, out] Ghcb A pointer to the GHCB + +**/ +VOID +EFIAPI +VmgInit ( + IN OUT GHCB *Ghcb + ) +{ +} + +/** + Perform post-VMGEXIT cleanup. + + Performs the necessary steps to cleanup after invoking VMGEXIT. Must be + called after obtaining needed fields within the GHCB. + + The base library function does nothing. + + @param[in, out] Ghcb A pointer to the GHCB + +**/ +VOID +EFIAPI +VmgDone ( + IN OUT GHCB *Ghcb + ) +{ +} + +/** + Handle a #VC exception. + + Performs the necessary processing to handle a #VC exception. + + The base library function returns an error equal to VC_EXCEPTION, + to be propagated to the standard exception handling stack. + + @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be s= et + as value to use on error. + @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT + + @retval EFI_SUCCESS Exception handled + @retval EFI_UNSUPPORTED #VC not supported, (new) exception value= to + propagate provided + @retval EFI_PROTOCOL_ERROR #VC handling failed, (new) exception val= ue to + propagate provided + +**/ +EFI_STATUS +EFIAPI +VmgExitHandleVc ( + IN OUT EFI_EXCEPTION_TYPE *ExceptionType, + IN OUT EFI_SYSTEM_CONTEXT SystemContext + ) +{ + *ExceptionType =3D VC_EXCEPTION; + + return EFI_UNSUPPORTED; +} diff --git a/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni b/UefiCpu= Pkg/Library/VmgExitLibNull/VmgExitLibNull.uni new file mode 100644 index 000000000000..8639bc0e8ce9 --- /dev/null +++ b/UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.uni @@ -0,0 +1,15 @@ +// /** @file +// VMGEXIT support library instance. +// +// VMGEXIT support library instance. +// +// Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved. +// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "VMGEXIT support N= ULL library instance" + +#string STR_MODULE_DESCRIPTION #language en-US "VMGEXIT support N= ULL library instance." + --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63312): https://edk2.groups.io/g/devel/message/63312 Mute This Topic: https://groups.io/mt/75824952/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 Fri Apr 26 07:16:41 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+63313+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+63313+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 15958636731496.2853467276331685; Mon, 27 Jul 2020 08:27:53 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id CQEwYY1788612x5Ye0Q184T2; Mon, 27 Jul 2020 08:27:52 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.66]) by mx.groups.io with SMTP id smtpd.web11.58071.1595863672203135406 for ; Mon, 27 Jul 2020 08:27:52 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TRE3W1ovmXcTWqroLFM/K7iOtO748w+MYVTbxgVMZDD1CtuogNVIbQ5gsxRO/mLGmcMFVAWV3sRCQ+fEExF2BTozMGJt75E/2m62sqEb9LP9A+1yTbWZfdYLHaZreH7zwIDft3BmBPpYWYp1G9JS1FWBV5eKYzlVmMSQSPCPx7P6niLkDmpe/7t7cPqu8OzyjGmKZO2C23But5OcI2e5W2pU7hbZ7HA4RPWSnSW72m9omUv0CJpHez2NTFi1USahp3WjhmHeiwlZgKHGEvtjQ59U7Vf0ePrvsv1XEtx1vPgwnTJMOe+W6xZV4qu+8tfsAXOKAXmgvCjpzumUbW2qFw== 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=U9b/kKvH3tVOLRpdFrO8SCIdJMh8PK+H2a8qgSS46bs=; b=oIuE/gp5s+n12uIacMIkVlvrjhdSuDUXKhjl4p0Tca9gI1l+JEOj+9i+R32JDoS2AQr7HSTtqc2KNXT3xoO1U210F2JaT51UwsXMN4YrII+bwqllQbT7GS618jK+gU6uGz+UuXJUqBzjludR4PVJqtNr5sgSGXQWXlR5BgHokiNM+GuIA9ZuvwDbbktYprMuoNXQzPxwVnVAXTBJHzuSqsRFbozy+yEB0Rfq2bE8L4Tj+lLT6ZeznGfdTqJXGkdU1I0yrnZtZ56i5sFg0coeOqZL7rgiWQS+FxC/evyluSZWFe8o6pCEniWA6+U6xC5GEPC2YyEH3oV9WJ8ZaIogfw== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:27:50 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:27:50 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni , Anthony Perard , Julien Grall Subject: [edk2-devel] [PATCH v12 09/46] OvmfPkg: Prepare OvmfPkg to use the VmgExitLib library Date: Mon, 27 Jul 2020 10:25:50 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN4PR0201CA0058.namprd02.prod.outlook.com (2603:10b6:803:20::20) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0201CA0058.namprd02.prod.outlook.com (2603:10b6:803:20::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.21 via Frontend Transport; Mon, 27 Jul 2020 15:27: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: cb5f52c8-9b8f-4fe6-598b-08d832419f64 X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: KpkGCPZojaB8s0bhsE5OpgntyJOiKnqMPceGsZVILwv0WcbBuvn4G5XZuLyaByz0Dw5tsfKDTFSrWKvVVhTSz9SvywFx5h4I8EbK2Vc3WspuZe9trRf5kjhZ/SLLFkMFUFqxmUu4fAJWTF+mh3bdP3R/6rJR2JUUJhY+rQuTfxm74h3aKPd2YAd1acb8qB8ijyJC+wDV5ANkZ8c+/JnSvIGdomxKCIEpoTsREFtkriAot0FZx4NTFHqiB8iSbB66TeKcVj7rppWqwGyrWogj3dj73+IgWf+YeFxePd3/mDM+oHOAhxpS6AKqtrXtm9gBDW50hmxFX3xpFeOoHVqx/SQH4uaVfMySVYHYnQ6D0mBictN/K4kjRXyZq7B5MW3BDY+0CDyRPbRtuU/Ll8k9ROoo7MFXGdHEkW/r/3MoCXNvOdgZvYe/WeMG9l6qM8DeFUSdKQLuW8HcjOrnk1XkMw== X-MS-Exchange-AntiSpam-MessageData: xwnCZd0Jjb+qNKy5yMgoozuA+bHIzVUI0XhkHO4J753mjIaoyK1Q9UyJac+EVHG/EJgr54JFQVpTZXBOhfB4RdMqwG5use602qTjFFLqdekHjHdkBZpZnc41q9ZYwQh3CO9ThESQJSm8Rvkz8XbfR7Js+foZIwyzeQ7txvF1V+Vuis1gZEGnvGaOY6+X7dT7zJs47CRosQPso2bL72GrpnW/kf6p7H44F0/EZbGHZIUapEv/oUbdapJyHEESqMM9wPOknTzf0zJg1yAlPbBpXd5LZzMIvycj2o5/KV7s0XvyWPrZVEsNKDrH5luIo9kDlFUJKXbbpLZ4vubhYALqRk/rYbQLjCO66jZ0JWyvHPGuB1ylViVJYyzVaUZlt1KiJP+ZKNj1gszdGJiROpD2sIH4VX8BC70kIXuAVcoZrgSrJiKQ5xvTQ1FoNQQa4hQIqf07XUCWdijz0IK72q6xyJ+et0mKgi3VStkacziwsYg= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: cb5f52c8-9b8f-4fe6-598b-08d832419f64 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:27:50.2821 (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: Dy4eREyoXRDLDY/2uMdcO+939xp54laYb4lX6GTFidh+GcFYIST+DS1pXoL7fdGvwGoJAxzJ998e+kdWhG9RxQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: kW7aiDJGe4Q3yTgMtAXBqR6bx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863672; bh=TawSDXI7uwa+GjjcFEW/PKAj4n8skjax5KE2VbbQAks=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=g5GgdgZ0CFekm2k+LZvuyg0emqWNGwFYf7EVX6JjjyAD21ImwKNmGQO1K63qPWcZ5bo vb8/D5iHA/OyRr9O6oLbQXiT71lAKBjjZDtjfN+Sl933UtltOcNZa4BzEuGKU4wJb4ndJ KMUS7m47iKhyO8aunjioXg7Ql0wtUvaVoTg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Various CpuExceptionHandlerLib libraries will updated to use the new VmgExitLib library. To prevent any build breakage, update the OvmfPkg DSC files that use a form of the CpuExceptionHandlerLib library to include the VmgExitLib library. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Anthony Perard Cc: Julien Grall Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/OvmfXen.dsc | 1 + 4 files changed, 4 insertions(+) diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 9178ffeb71cb..c57bba1ba197 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -229,6 +229,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 a665f78f0dc7..22e930b12b9b 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -233,6 +233,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 17f345acf4ee..27f5225fc281 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -233,6 +233,7 @@ [LibraryClasses] =20 [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 [LibraryClasses.common.SEC] TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index 782803cb2787..37b63a874067 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -213,6 +213,7 @@ [LibraryClasses] =20 [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 [LibraryClasses.common.SEC] QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgSecLib.inf --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63313): https://edk2.groups.io/g/devel/message/63313 Mute This Topic: https://groups.io/mt/75824954/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 Fri Apr 26 07:16:41 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+63314+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+63314+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 159586368125899.36716047423158; Mon, 27 Jul 2020 08:28:01 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id FpFLYY1788612xxPmgu3DjGb; Mon, 27 Jul 2020 08:28:00 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.88]) by mx.groups.io with SMTP id smtpd.web10.58326.1595863680118894857 for ; Mon, 27 Jul 2020 08:28:00 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gXYrj/Qfs1deqKBOT6G+xWmGcZPEXI3Sm31sXB3YQnwp/OY7VZDTLBZV6bkiCK83pmz+xplNRwTUWOJd6EMPVw+CbY9ziaG20BGTM7tbmeH/svfVejO7FkZS6Kgj4R+rPIT3mTNbfMpG/K+TlrN6JCehV1AU6tMGW0GCR+D/nkMVZQaF0eh14b+zrarCUqVd36pPfIzSJg3cAewvSdQlCfIzulvWF0oRiVsxQoin/TFir+8X90nqdX0b/Zo3K8ZsWRrqnsA4TJ2uNkqxhyHzrk4bdGckmPndi3REIgDtZOsdHiJLjF8LIO+IW+X/ufJsvMN8SomFGQCHNK/CTpT0nw== 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=8gIPuv0Fy7s+RjQntMgos8V2fokI9BA9s2pD9HQviYg=; b=HayzJhlh1GLaOr3KQQNiJuitMU0HneiDL7HMYd2k3yBJ3Uu6g9c5Yb+crs2j+evfOtrweBgHVGg4H4vCFXYLCy6tzXMvoRyK2WCi0cDHOutzcvhpsNC3dpJ8Lar5cVbg7f2g/REb0aP+iWtxNIgemWgk25VPbnWuKnj+xk5NUelPsyqRkZ1qusw46i26rmOMIZftTfAgSZx/n0TQ0xJCaIGqHOBlNHVcKT0iYlIChaVPA06SEwwB2HjWPsIyLpkHZAF7huR3OCcKZMOUX9Uf29frg2sRyliQ0Ch+o4gMlrbaRBrhcpJ9J/ovLGZuhjaQzVc051EvR3OD/9D2DKGyDg== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:27:58 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:27:58 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni , Maurice Ma , Guo Dong , Benjamin You Subject: [edk2-devel] [PATCH v12 10/46] UefiPayloadPkg: Prepare UefiPayloadPkg to use the VmgExitLib library Date: Mon, 27 Jul 2020 10:25:51 -0500 Message-ID: <40a048764bbbec7bee03e370805794f222972a77.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN2PR01CA0049.prod.exchangelabs.com (2603:10b6:800::17) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN2PR01CA0049.prod.exchangelabs.com (2603:10b6:800::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.26 via Frontend Transport; Mon, 27 Jul 2020 15:27: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: 8a9c6c9e-ff4c-4fac-1b42-08d83241a446 X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: YtzX7Pl6T8P0CwRwiRRqDBIUhAe65ESqRbraHLClDmFmaOnPGhcxJFhrG8YqOnXTzsfxjvKODFD9bfXxPYplPXgJW84V07z9vMusLR7h4LZwKyX4KogHfAp1Ze+nfgm7ng6avn+yNSvB/gW9Ceeg3B+kkXtatg4WwcHopzvZtoB7k14/t2mjskydcpc9n3amOS6Zxfdw5339pAhUySrnsDnLTbzLXRpRdCgGXLvFANPuRQNNpbAcU0r2kHUXEgXLNWjhF1RNwMX5ytOazsdZxTRuNIvEa/g6zeJHDScmvpQJ13O5d7dLxcOE9IGvLkBapJqiuQrYYJdB2Bxu6O+xpxZ2v7HSIQdN7Z8BhzFfvJfDvfWs31ThKM3Kl07dZEqcj/V8v7e9qa+av20qIcvfHj9nmogSGVenWWgMk6LladxUJkU9yLUJWg6NSfKkbfVKlNvLz4msSoZvBmZiUUlIKg== X-MS-Exchange-AntiSpam-MessageData: eBId/RYUmOIPej05NuvogEW8jxjZTqPfUFdsDAVS8uFlbagRFRfxeGoU7P6CBCNz33DBCG2nR0xQLRHzJR7Kt/ROvcR9bW9cdSd6RWkgW0VKmPjpiOcSAaRkjVwA9i/BGmXAxusCqIGZ6z6EWgw60+NFtlGT4xVbSbVQfiO9iHEvAxBp4DJ7QUrMJ3CRAHcOa/9+FTNwIH0Upj6ONYqON7Fi5okGqCiO2+Kvq4MRGeonBs5GcQQC3Cdh+GnjLWHNlBqL6qGpQmccsRhZZB42MoL87+wcKlXm4fWAInU/5IgPQ8WmSsGq0avYha6YeFhDw4QMLK17JZqkVj8Wo0WfEIpeVpoD9CLyKP2l+DXHDU3ziy5d4yw+W0LpRsfk/Oo1s7pyIp/qhEWL1skGtDWGkqDBD0LBJVbARtWm67ujD+vsko+EVItD6RvBgXBU9VaoN1fECol+7iRCyKwddZHDsucsAtDNcXW3JdZnmVNLZ5Y= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8a9c6c9e-ff4c-4fac-1b42-08d83241a446 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:27:58.4355 (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: 6renM6hS6sb5uv71LqfCSdARRL39/rzsEwwE03Z/WDwe+Cz7MyVtlKqEduGqhbzEvhJz41jwRHgp7LVfvT4SMA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: leG7ZLlNVXBXGL44HUL96LKFx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863680; bh=pEO0knNruHkQt2wjaaX7Do384D+6NW/SNq/KXe4aqgc=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=fiWzG9z+2YxvaYogye0GuZpnki+ygoEzpCuRtE1kT+juyN4RdgxfscyZOwEdV+ByXdN VTut/sQLZw1dUOJOtcslxl4v9ZWd5Z4nQ0rJYQOr7ECwXAjCahcyHP2Utb8cJlp6NMeCg nUWj1iDB8F+WweuZKS7ZkghyzwY1M3EK+4k= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Various CpuExceptionHandlerLib libraries will updated to use the new VmgExitLib library. To prevent any build breakage, update the UefiPayloadPkg DSC files that use a form of the CpuExceptionHandlerLib library to include the VmgExitLib library. Cc: Maurice Ma Cc: Guo Dong Cc: Benjamin You Reviewed-by: Guo Dong Reviewed-by: Maurice Ma 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 9a9ca3060e47..460da1c504dc 100644 --- a/UefiPayloadPkg/UefiPayloadPkgIa32.dsc +++ b/UefiPayloadPkg/UefiPayloadPkgIa32.dsc @@ -237,6 +237,7 @@ [LibraryClasses.common.DXE_CORE] DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuE= xceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 [LibraryClasses.common.DXE_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf @@ -249,6 +250,7 @@ [LibraryClasses.common.DXE_DRIVER] !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuE= xceptionHandlerLib.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 [LibraryClasses.common.DXE_RUNTIME_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf diff --git a/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc b/UefiPayloadPkg/Uefi= PayloadPkgIa32X64.dsc index a768a8702c66..942bc9076634 100644 --- a/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc +++ b/UefiPayloadPkg/UefiPayloadPkgIa32X64.dsc @@ -238,6 +238,7 @@ [LibraryClasses.common.DXE_CORE] DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuE= xceptionHandlerLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 [LibraryClasses.common.DXE_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf @@ -250,6 +251,7 @@ [LibraryClasses.common.DXE_DRIVER] !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuE= xceptionHandlerLib.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf + VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf =20 [LibraryClasses.common.DXE_RUNTIME_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63314): https://edk2.groups.io/g/devel/message/63314 Mute This Topic: https://groups.io/mt/75824959/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 Fri Apr 26 07:16:41 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+63315+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+63315+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 1595863689484586.2127482903808; Mon, 27 Jul 2020 08:28:09 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id s955YY1788612xb9bHDzp30c; Mon, 27 Jul 2020 08:28:09 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.45]) by mx.groups.io with SMTP id smtpd.web12.58082.1595863687981243655 for ; Mon, 27 Jul 2020 08:28:08 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SCYesZLLzkz4j/SlVm0l1I9cC49MxyrYluV0xvCYV0sphI3nYLoXZdgtecfYIk+fIYbI6z5KRETUAzaUIJHzr52l3j+3ZPqAGtE2soXpkcSSsvr03HT6xEQrDH7In202IcgsCWnSsjFisZKmKtryig41xliGZEuXKJZeiGrEqfomYnR7THy673pd2ambQO6A7Nul66sZ9qYyoiatqNDdU3rHjLDFgou+OOwE+JnpBt2yXRe0o805vWS3tZdo92iYVQBL2Emx8U4XEutIzpS7Cel2ab51JqcXUmrrEP2FV6/1ejPpiHGA7w3Niw+t4T1e++y++BDBtFE7Im49jBhJ+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5xOrmFSZA+Wi3b0xrnNBRCIpwsGnmCOwMSFuIiVOZU0=; b=XO4lOOG152vnNrGU5f5WMr90QFtG5zHH7RF4v+76OpsLKr04IsCPkbiOEC/26Bgc/F1Y4sBl7mbO8wpVXJc9dkRX6kuv4N47R43BBlIpKyhogiClWqPFwWQFtmWZyQDB2XYPehwUGIx9fOHcBlLcrFznbzlSdqGVFGiLSKnyYQbtGnTAdbCD7arEcasxob2CRjzxSuEr71j1cYiPpPe/ndlBYIQgwBF8HdoyfcBwForz3zGf8kX2iBYtmOKuX4nuLNFtSM7wFDBbHxMPEIL4U8wGZW3wMXPH9ZoIuJePVWRaOvMeUUV7O72hw0NBLvJ3JEEb1lmPsmjYtlZd/DyMug== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:28:06 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:28:06 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 11/46] UefiCpuPkg/CpuExceptionHandler: Add base support for the #VC exception Date: Mon, 27 Jul 2020 10:25:52 -0500 Message-ID: <0abd73b2cd1647c852c7cd6683e40a61ffc6e765.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0019.namprd21.prod.outlook.com (2603:10b6:805:106::29) 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 SN6PR2101CA0019.namprd21.prod.outlook.com (2603:10b6:805:106::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.1 via Frontend Transport; Mon, 27 Jul 2020 15:28: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: e4d7aeb1-e927-46bb-a639-08d83241a8f9 X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: RTpAY0CYSOLS9gPGeD2VLuwL1+QmAjFSwMz0/E8g9jnwinbBsuJMPGYdWVw2GmvTXE6liWNTWQM94FhwunBvflr5mDAhl2ZdVmLgx//DB9w5Y1uaTmMzTRsV1lKl9QVm1J8akIMXIs5hlqDF+WB4m2wwqib95kTOP5kkpYkuFsChbI4F2wki6ixe6MWbWLWo9OLgtixLsGd1dIcjOlUxkI02BVX9+XIoQ+YH76qOtIUy4IAn3Lqjwy1wqNDLGdsSgo6ca1M1MFnIMESeQgF5mpH2sb9Bv7D6KFuI9f6TVxAtAJwiRIt5mdwO+rf2VzMv4UE9W1RX3/jt+2KlLRGk+ntcFOxnOr+zn+DAoS5o1SijtYGSC1ztXNUsM84iM0efeFlg5sbMjJbcXVpmGipfbmonZuo0Wx3Ui6PW532P/T/dzPekXTePKlnE69sNyhuZfCuqwQErYDt8scOE2D/ZGvCE5kqo8BQH6dKcFEtQPI5x/EZ67SPOdVgowqqqFJFx X-MS-Exchange-AntiSpam-MessageData: vp/VWZOGrgGa2m7Ky0dI0Uy+W0sfRb5v+BHn8r+sfO4ZNG9Ohi2j36Bwg0GnR2UVPIQiwFgwLtQayReEjfEDX+1BWZ+felwahsohPtcmeIOTch0poXJey/p+/vz2LVu/XvLpe5K75B+1ZKDW4Aj3O4yA63JFwBqzpntmgMxxHf/Q9KiWj10izFlD7Wigm6SUKmHPQu45iclbeftixfl6BQZxwpbsmkcb0zDbcjGFbuQZyuHk0wE5u5NAPFvFhp+1rijlFfJd5EtezG8Ox7T0ApkJjT/Gtsi0kQIkVPhy0XTMJJJjWTCNgVGJNKwcvO214uMOgtbz3TXKuykrbF7lxQikkph/OmDe6BLiP9/DBpuTu/2Ln8afz2E1koqPXaSFOf5CvwkGoPbC61TyRT2GXWqy6bTO8rMUXcuTVylqthgfaD7giU7E5ZXhsn3b7H90YxEA15hs7JO5LxYLMVXyMiWNTn3ziATIDcQqV5bVJkY= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e4d7aeb1-e927-46bb-a639-08d83241a8f9 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:28:06.3710 (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: TnSwdJedhyor4WuDNYLbHR/BCxlw08lKINE4fx/ajvz8+KAzA52O0sJQS5pEZY4b7WU9WI/H0uuzi7G4smwV0g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: t0xJEwGIrja4HNCGCpcBSU8Fx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863689; bh=Kmh0671QypyLibLtEmduJxatb0oywltxjr2edMOuMTw=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=tOGU/cMvrYlZIS1EQtIiVarGtOhvXHRLFMu5w84FIPSDDNmJZoLA8eSn3CirglPxVTy Gq8B9nP+DqQOOrNJfyStTi4dayBxrCzRhgU1fCprRsetHIDtQ8MHCBAxWz5Yul2baFkoF 0NapjsRMPEVDsmJXwSIAMhdxKxGjyM9xoZk= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Add base support to handle #VC exceptions. Update the common exception handlers to invoke the VmgExitHandleVc () function of the VmgExitLib library when a #VC is encountered. A non-zero return code will propagate to the targeted exception handler. Under SEV-ES, a DR7 read or write intercept generates a #VC exception. To avoid exception recursion, a #VC exception will not try to read and push the actual debug registers into the EFI_SYSTEM_CONTEXT_X64 struct and instead push zeroes. The #VC exception handler does not make use of the debug registers from the saved context and the exception processing exit code does not attempt to restore the debug register values. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Reviewed-by: Eric Dong Signed-off-by: Tom Lendacky --- .../DxeCpuExceptionHandlerLib.inf | 1 + .../PeiCpuExceptionHandlerLib.inf | 1 + .../SecPeiCpuExceptionHandlerLib.inf | 1 + .../SmmCpuExceptionHandlerLib.inf | 1 + .../Xcode5SecPeiCpuExceptionHandlerLib.inf | 1 + .../CpuExceptionCommon.c | 10 +++++++++- .../PeiDxeSmmCpuException.c | 20 ++++++++++++++++++- .../SecPeiCpuException.c | 19 ++++++++++++++++++ .../X64/ExceptionHandlerAsm.nasm | 17 ++++++++++++++++ .../X64/Xcode5ExceptionHandlerAsm.nasm | 17 ++++++++++++++++ 10 files changed, 86 insertions(+), 2 deletions(-) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandl= erLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandle= rLib.inf index 61e2ec30b089..07b34c92a892 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.i= nf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.i= nf @@ -57,3 +57,4 @@ [LibraryClasses] PeCoffGetEntryPointLib MemoryAllocationLib DebugLib + VmgExitLib diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandl= erLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandle= rLib.inf index 093374944df6..feae7b3e06de 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.i= nf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuExceptionHandlerLib.i= nf @@ -52,6 +52,7 @@ [LibraryClasses] HobLib MemoryAllocationLib SynchronizationLib + VmgExitLib =20 [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard # CONSUMES diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHa= ndlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException= HandlerLib.inf index 6d25cafe2ca3..967cb61ba6d9 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLi= b.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLi= b.inf @@ -48,3 +48,4 @@ [LibraryClasses] PrintLib LocalApicLib PeCoffGetEntryPointLib + VmgExitLib diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandl= erLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandle= rLib.inf index 2ffbbccc302f..4cdb11c04ea0 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.i= nf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.i= nf @@ -51,4 +51,5 @@ [LibraryClasses] LocalApicLib PeCoffGetEntryPointLib DebugLib + VmgExitLib =20 diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExcep= tionHandlerLib.inf b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPei= CpuExceptionHandlerLib.inf index 7e21beaab6f2..743c2aa76684 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHan= dlerLib.inf +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/Xcode5SecPeiCpuExceptionHan= dlerLib.inf @@ -53,3 +53,4 @@ [LibraryClasses] PrintLib LocalApicLib PeCoffGetEntryPointLib + VmgExitLib diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c= b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c index 8adbd43fefb4..c9003b10e552 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/CpuExceptionCommon.c @@ -14,7 +14,7 @@ // // 1 means an error code will be pushed, otherwise 0 // -CONST UINT32 mErrorCodeFlag =3D 0x00227d00; +CONST UINT32 mErrorCodeFlag =3D 0x20227d00; =20 // // Define the maximum message length @@ -45,6 +45,14 @@ CONST CHAR8 *mExceptionNameStr[] =3D { "#XM - SIMD floating-point", "#VE - Virtualization", "#CP - Control Protection" + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "Reserved", + "#VC - VMM Communication", }; =20 #define EXCEPTION_KNOWN_NAME_NUM (sizeof (mExceptionNameStr) / sizeof (CH= AR8 *)) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuExceptio= n.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c index 6a2670d55918..892d349d4b37 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiDxeSmmCpuException.c @@ -6,8 +6,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 **/ =20 -#include "CpuExceptionCommon.h" #include +#include +#include "CpuExceptionCommon.h" =20 /** Internal worker function for common exception handler. @@ -27,6 +28,23 @@ CommonExceptionHandlerWorker ( RESERVED_VECTORS_DATA *ReservedVectors; EFI_CPU_INTERRUPT_HANDLER *ExternalInterruptHandler; =20 + if (ExceptionType =3D=3D VC_EXCEPTION) { + EFI_STATUS Status; + // + // #VC needs to be handled immediately upon enabling exception handling + // and therefore can't use the RegisterCpuInterruptHandler() interface. + // + // Handle the #VC: + // On EFI_SUCCESS - Exception has been handled, return + // On other - ExceptionType contains (possibly new) exception + // value + // + Status =3D VmgExitHandleVc (&ExceptionType, SystemContext); + if (!EFI_ERROR (Status)) { + return; + } + } + ExceptionHandlerContext =3D (EXCEPTION_HANDLER_CONTEXT *) (UINTN) (Syst= emContext.SystemContextIa32); ReservedVectors =3D ExceptionHandlerData->ReservedVectors; ExternalInterruptHandler =3D ExceptionHandlerData->ExternalInterruptHand= ler; diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c= b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c index 20148db74cf8..52c6886f0372 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuException.c @@ -7,6 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 #include +#include #include "CpuExceptionCommon.h" =20 CONST UINTN mDoFarReturnFlag =3D 0; @@ -24,6 +25,24 @@ CommonExceptionHandler ( IN EFI_SYSTEM_CONTEXT SystemContext ) { + if (ExceptionType =3D=3D VC_EXCEPTION) { + EFI_STATUS Status; + // + // #VC needs to be handled immediately upon enabling exception handling + // and therefore can't use the RegisterCpuInterruptHandler() interface + // (which isn't supported under Sec and Pei anyway). + // + // Handle the #VC: + // On EFI_SUCCESS - Exception has been handled, return + // On other - ExceptionType contains (possibly new) exception + // value + // + Status =3D VmgExitHandleVc (&ExceptionType, SystemContext); + if (!EFI_ERROR (Status)) { + return; + } + } + // // Initialize the serial port before dumping. // diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandler= Asm.nasm b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAs= m.nasm index 3814f9de3703..2a5545ecfd41 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ExceptionHandlerAsm.nasm @@ -18,6 +18,8 @@ ; CommonExceptionHandler() ; =20 +%define VC_EXCEPTION 29 + extern ASM_PFX(mErrorCodeFlag) ; Error code flags for exceptions extern ASM_PFX(mDoFarReturnFlag) ; Do far return flag extern ASM_PFX(CommonExceptionHandler) @@ -224,6 +226,9 @@ HasErrorCode: push rax =20 ;; UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7; + cmp qword [rbp + 8], VC_EXCEPTION + je VcDebugRegs ; For SEV-ES (#VC) Debug registers ignored + mov rax, dr7 push rax mov rax, dr6 @@ -236,7 +241,19 @@ HasErrorCode: push rax mov rax, dr0 push rax + jmp DrFinish =20 +VcDebugRegs: +;; UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7 are skipped for #VC to avoid excep= tion recursion + xor rax, rax + push rax + push rax + push rax + push rax + push rax + push rax + +DrFinish: ;; FX_SAVE_STATE_X64 FxSaveState; sub rsp, 512 mov rdi, rsp diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionH= andlerAsm.nasm b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5Except= ionHandlerAsm.nasm index 19198f273137..26cae56cc5cf 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerA= sm.nasm +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/Xcode5ExceptionHandlerA= sm.nasm @@ -18,6 +18,8 @@ ; CommonExceptionHandler() ; =20 +%define VC_EXCEPTION 29 + extern ASM_PFX(mErrorCodeFlag) ; Error code flags for exceptions extern ASM_PFX(mDoFarReturnFlag) ; Do far return flag extern ASM_PFX(CommonExceptionHandler) @@ -225,6 +227,9 @@ HasErrorCode: push rax =20 ;; UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7; + cmp qword [rbp + 8], VC_EXCEPTION + je VcDebugRegs ; For SEV-ES (#VC) Debug registers ignored + mov rax, dr7 push rax mov rax, dr6 @@ -237,7 +242,19 @@ HasErrorCode: push rax mov rax, dr0 push rax + jmp DrFinish =20 +VcDebugRegs: +;; UINT64 Dr0, Dr1, Dr2, Dr3, Dr6, Dr7 are skipped for #VC to avoid excep= tion recursion + xor rax, rax + push rax + push rax + push rax + push rax + push rax + push rax + +DrFinish: ;; FX_SAVE_STATE_X64 FxSaveState; sub rsp, 512 mov rdi, rsp --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63315): https://edk2.groups.io/g/devel/message/63315 Mute This Topic: https://groups.io/mt/75824962/1787277 Mute #vc: https://groups.io/g/edk2/mutehashtag/vc Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri Apr 26 07:16:41 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+63316+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+63316+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 1595863696834853.6208460579091; Mon, 27 Jul 2020 08:28:16 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ycYbYY1788612xQBAtO0inlv; Mon, 27 Jul 2020 08:28:16 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.69]) by mx.groups.io with SMTP id smtpd.web11.58086.1595863695939129336 for ; Mon, 27 Jul 2020 08:28:16 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VS/sdBxUevIV3Ss4PIgCimE21tmQVcRN5AGnLGIaTah5Gt7MSk0d+LNwDnmZ+cX8vZpoWotMjar6EJFfqQBuNXgKjVkoc5RJ5nGgp3g5cPULfAZIOjDu1C3tPH+OYEoXhDpvcaQ9HETuWY/N+uXY7t4RIZ8xBJh4WvLfoyhIQwwtH1jBTND4R6EPHQgM9YVTC9wfkWQBAA+n2Zs/U/JXEdGAbvx+CfOyg5ALJmpshfkAIkkY2OkBWjhR35ZynAZFP56mLfSaKUg6emEdzX+MKr4vKZCpSX/A0oth+qnkfGeCtczdqEJzXJyO1U5eW9aJ3Tz5/l5Qz4vyaU3hevjleg== 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=j1UHV++AGGkyKk8R3P6uIZpa9edH9ot35jHOpgxb3jM=; b=OJdBggj7lmk8YuE6mILmyF1gjjilLF0camSwGKWwFz8mqjV/+CNBNPUx404o8CCuPuQiPAH8rs1fCzVrzzZIVcTW6CbATf4M8Vrf7esyFjYhNq1safqGz/u7XC9h4vgQGEYInBH0FJl0Y3DdiCs53ePirOYHeA10DRnRj2kKFc1+tVwyMA3lgCGfEgiKFxGWSMpH4tlkegHOO4aoYpZ16SyrwAyagkIQDCW+RR48f3fDVl6YwqfAfmF+pHlko+2UgCNaiqW8Y+YuDa/FiVPNgiMY+Q4pjyAtZ3OWYlh/liv8+mcSDEf4e9LnSoHrLmJbmOmXrYNmhbDtPkj64Z44wA== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:28:14 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:28:14 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 12/46] OvmfPkg/VmgExitLib: Implement library support for VmgExitLib in OVMF Date: Mon, 27 Jul 2020 10:25:53 -0500 Message-ID: <36211d123b5a55d7ed07246f5e2562c0eb5d4d8b.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0015.namprd21.prod.outlook.com (2603:10b6:805:106::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 SN6PR2101CA0015.namprd21.prod.outlook.com (2603:10b6:805:106::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.0 via Frontend Transport; Mon, 27 Jul 2020 15:28:13 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: a7619698-ebb0-4ba0-eae9-08d83241adc3 X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: cT8urevKcTW/iLu2sC9FQLRj296bCDhieGguQXu/RNK1I9XpaDQwgxgyedXVCLTMpH0B+mBvL39357vf7UyTTfDPsgnWhQKyX8LYV7/zfPlRnfbGuUly4dO9c+VJxOHxQHw0YBIh/iZQRhOnZKSD7ebJqpDhQyeQmG703j0rqwez7zQvhn7nZHTgSlWjcut9zpmk8psBwQhuFpXzAkDdFS/4fRPr5VCgT6ei52vxVS1YwyhTuX9mNcius4clCxvoo/24NMBxHZAsFBMe7EuywJW8eNUvdJV8MYzJuAmWKx3kWFg3kzU9Bb69vUNMIbt7gxJlat3DoCkhZlOa/Q7dWD0bl1Q41pAvRqBkbPk/8ejMwZ7kfcrpH2P4kIbnjhTr X-MS-Exchange-AntiSpam-MessageData: UhBnsgVFm5jIF+QWUqtH05qEVfzrUTXNHHiohH3mp9Jna1h00kRkE9Z3Cta8STxjqo4v4YPNQSy4nosdGrs6VRm0hf7oXYHYe8klpDOLBmLm6Aark/h8XoPKwGDYwFux2qH0DaOzzMprZMkGn4VS1V2zKEad8V4WFAaSq2gABS7xTQt2ZqrH41jZKBYCCJRNBJZMDrKU0I4FFa7zNdNPpxRo6TFZnGsD21b5Nof8aZTQtPBuoHePhWiizyktQb04+kxvigy6pV0fHovUvHRbXmvl6SB6yA9FOtI6dbyEhx4IRhyYkicqB6QG6vSfBgY99eNEZwq3sgtRqjPGmLDoF9RrQmw4yaE7FiQ50xTG3dDdPe3s16Wp3e8ShDhIwXEaHS0McwrBK0YjsTqXwzfQHCb/XulXhxew8mLnWcWWCNnalVTlr7vcbejqSs52QvMg241Yda90x2gbfiuewccr/lq/IC6+wf+7NkLxmJSVMd8= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a7619698-ebb0-4ba0-eae9-08d83241adc3 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:28:14.3965 (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: I+hi8Z8+qVAhezCDanASK4O+6GH+44p9xWDUR3TycVIrgWFejJr9pWC711do0qLcb5XUPFzV+paitcWejU/D/Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: 6aR0IY3TcBugQQ9fmioldHpdx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863696; bh=zVxTvhusmhzvtwSMyJTThqP2/W4m5ca8+iH3O4DDxfM=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=u7/mCi2g4egmmqzw+uQa6/SFUHrfD0W3FljvFSimNADyhfwoG585ceqiJilJx2LwZPd B+SUEYUU0+w+FySI8wxk0wD2tYvgellFE7TV1+B3RDnFfLXsqAfmkuSVi1dJCH6K7wKnS XUN3g5vgDbvbmQDYX7eF6FI0MLb9kq8HAGI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky The base VmgExitLib library provides a default limited interface. As it does not provide full support, create an OVMF version of this library to begin the process of providing full support of SEV-ES within OVMF. SEV-ES support is only provided for X64 builds, so only OvmfPkgX64.dsc is updated to make use of the OvmfPkg version of the library. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/OvmfPkgX64.dsc | 2 +- OvmfPkg/Library/VmgExitLib/VmgExitLib.inf | 36 ++++ OvmfPkg/Library/VmgExitLib/VmgExitLib.c | 159 ++++++++++++++++++ OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 81 +++++++++ 4 files changed, 277 insertions(+), 1 deletion(-) create mode 100644 OvmfPkg/Library/VmgExitLib/VmgExitLib.inf create mode 100644 OvmfPkg/Library/VmgExitLib/VmgExitLib.c create mode 100644 OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 27f5225fc281..60be5eae3d2b 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -233,7 +233,7 @@ [LibraryClasses] =20 [LibraryClasses.common] BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf - VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf + VmgExitLib|OvmfPkg/Library/VmgExitLib/VmgExitLib.inf =20 [LibraryClasses.common.SEC] TimerLib|OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.inf diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitLib.inf b/OvmfPkg/Library/Vm= gExitLib/VmgExitLib.inf new file mode 100644 index 000000000000..d003ac63173e --- /dev/null +++ b/OvmfPkg/Library/VmgExitLib/VmgExitLib.inf @@ -0,0 +1,36 @@ +## @file +# VMGEXIT Support Library. +# +# Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved. +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D VmgExitLib + FILE_GUID =3D 0e923c25-13cd-430b-8714-ffe85652a97b + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D VmgExitLib + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D X64 +# + +[Sources.common] + VmgExitLib.c + VmgExitVcHandler.c + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + UefiCpuPkg/UefiCpuPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitLib.c b/OvmfPkg/Library/VmgE= xitLib/VmgExitLib.c new file mode 100644 index 000000000000..53040cc6f649 --- /dev/null +++ b/OvmfPkg/Library/VmgExitLib/VmgExitLib.c @@ -0,0 +1,159 @@ +/** @file + VMGEXIT Support Library. + + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include + +/** + Check for VMGEXIT error + + Check if the hypervisor has returned an error after completion of the VM= GEXIT + by examining the SwExitInfo1 field of the GHCB. + + @param[in] Ghcb A pointer to the GHCB + + @retval 0 VMGEXIT succeeded. + @return Exception number to be propagated, VMGEXIT proces= sing + did not succeed. + +**/ +STATIC +UINT64 +VmgExitErrorCheck ( + IN GHCB *Ghcb + ) +{ + GHCB_EVENT_INJECTION Event; + GHCB_EXIT_INFO ExitInfo; + UINT64 Status; + + ExitInfo.Uint64 =3D Ghcb->SaveArea.SwExitInfo1; + ASSERT ((ExitInfo.Elements.Lower32Bits =3D=3D 0) || + (ExitInfo.Elements.Lower32Bits =3D=3D 1)); + + Status =3D 0; + if (ExitInfo.Elements.Lower32Bits =3D=3D 0) { + return Status; + } + + if (ExitInfo.Elements.Lower32Bits =3D=3D 1) { + ASSERT (Ghcb->SaveArea.SwExitInfo2 !=3D 0); + + // + // Check that the return event is valid + // + Event.Uint64 =3D Ghcb->SaveArea.SwExitInfo2; + if (Event.Elements.Valid && + Event.Elements.Type =3D=3D GHCB_EVENT_INJECTION_TYPE_EXCEPTION) { + switch (Event.Elements.Vector) { + case GP_EXCEPTION: + case UD_EXCEPTION: + // + // Use returned event as return code + // + Status =3D Event.Uint64; + } + } + } + + if (Status =3D=3D 0) { + GHCB_EVENT_INJECTION GpEvent; + + GpEvent.Uint64 =3D 0; + GpEvent.Elements.Vector =3D GP_EXCEPTION; + GpEvent.Elements.Type =3D GHCB_EVENT_INJECTION_TYPE_EXCEPTION; + GpEvent.Elements.Valid =3D 1; + + Status =3D GpEvent.Uint64; + } + + return Status; +} + +/** + Perform VMGEXIT. + + Sets the necessary fields of the GHCB, invokes the VMGEXIT instruction a= nd + then handles the return actions. + + @param[in, out] Ghcb A pointer to the GHCB + @param[in] ExitCode VMGEXIT code to be assigned to the SwExitCode + field of the GHCB. + @param[in] ExitInfo1 VMGEXIT information to be assigned to the + SwExitInfo1 field of the GHCB. + @param[in] ExitInfo2 VMGEXIT information to be assigned to the + SwExitInfo2 field of the GHCB. + + @retval 0 VMGEXIT succeeded. + @return Exception number to be propagated, VMGEXIT + processing did not succeed. + +**/ +UINT64 +EFIAPI +VmgExit ( + IN OUT GHCB *Ghcb, + IN UINT64 ExitCode, + IN UINT64 ExitInfo1, + IN UINT64 ExitInfo2 + ) +{ + Ghcb->SaveArea.SwExitCode =3D ExitCode; + Ghcb->SaveArea.SwExitInfo1 =3D ExitInfo1; + Ghcb->SaveArea.SwExitInfo2 =3D ExitInfo2; + + // + // Guest memory is used for the guest-hypervisor communication, so fence + // the invocation of the VMGEXIT instruction to ensure GHCB accesses are + // synchronized properly. + // + MemoryFence (); + AsmVmgExit (); + MemoryFence (); + + return VmgExitErrorCheck (Ghcb); +} + +/** + Perform pre-VMGEXIT initialization/preparation. + + Performs the necessary steps in preparation for invoking VMGEXIT. Must be + called before setting any fields within the GHCB. + + @param[in, out] Ghcb A pointer to the GHCB + +**/ +VOID +EFIAPI +VmgInit ( + IN OUT GHCB *Ghcb + ) +{ + SetMem (&Ghcb->SaveArea, sizeof (Ghcb->SaveArea), 0); +} + +/** + Perform post-VMGEXIT cleanup. + + Performs the necessary steps to cleanup after invoking VMGEXIT. Must be + called after obtaining needed fields within the GHCB. + + @param[in, out] Ghcb A pointer to the GHCB + +**/ +VOID +EFIAPI +VmgDone ( + IN OUT GHCB *Ghcb + ) +{ +} + diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c new file mode 100644 index 000000000000..b6a955ed8088 --- /dev/null +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -0,0 +1,81 @@ +/** @file + X64 #VC Exception Handler functon. + + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include + +/** + Handle a #VC exception. + + Performs the necessary processing to handle a #VC exception. + + @param[in, out] ExceptionType Pointer to an EFI_EXCEPTION_TYPE to be s= et + as value to use on error. + @param[in, out] SystemContext Pointer to EFI_SYSTEM_CONTEXT + + @retval EFI_SUCCESS Exception handled + @retval EFI_UNSUPPORTED #VC not supported, (new) exception value= to + propagate provided + @retval EFI_PROTOCOL_ERROR #VC handling failed, (new) exception val= ue to + propagate provided + +**/ +EFI_STATUS +EFIAPI +VmgExitHandleVc ( + IN OUT EFI_EXCEPTION_TYPE *ExceptionType, + IN OUT EFI_SYSTEM_CONTEXT SystemContext + ) +{ + MSR_SEV_ES_GHCB_REGISTER Msr; + EFI_SYSTEM_CONTEXT_X64 *Regs; + GHCB *Ghcb; + UINT64 ExitCode, Status; + EFI_STATUS VcRet; + + VcRet =3D EFI_SUCCESS; + + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + ASSERT (Msr.GhcbInfo.Function =3D=3D 0); + ASSERT (Msr.Ghcb !=3D 0); + + Regs =3D SystemContext.SystemContextX64; + Ghcb =3D Msr.Ghcb; + + VmgInit (Ghcb); + + ExitCode =3D Regs->ExceptionData; + switch (ExitCode) { + default: + Status =3D VmgExit (Ghcb, SVM_EXIT_UNSUPPORTED, ExitCode, 0); + if (Status =3D=3D 0) { + Regs->ExceptionData =3D 0; + *ExceptionType =3D GP_EXCEPTION; + } else { + GHCB_EVENT_INJECTION Event; + + Event.Uint64 =3D Status; + if (Event.Elements.ErrorCodeValid !=3D 0) { + Regs->ExceptionData =3D Event.Elements.ErrorCode; + } else { + Regs->ExceptionData =3D 0; + } + + *ExceptionType =3D Event.Elements.Vector; + } + + VcRet =3D EFI_PROTOCOL_ERROR; + } + + VmgDone (Ghcb); + + return VcRet; +} --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63316): https://edk2.groups.io/g/devel/message/63316 Mute This Topic: https://groups.io/mt/75824966/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 Fri Apr 26 07:16:41 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+63317+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+63317+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 1595863705239746.5050709422178; Mon, 27 Jul 2020 08:28:25 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id sTEGYY1788612xiBn9YKYcZg; Mon, 27 Jul 2020 08:28:24 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.76]) by mx.groups.io with SMTP id smtpd.web11.58095.1595863704120569322 for ; Mon, 27 Jul 2020 08:28:24 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fJlCwkrVeEf2J2Ub6D59Ba0qMQCsRrxFH/0PtwTgVgNurwRjnO4pXCb/B1gJrCPnSA1KCvZ3ulndVW2HAhG2G+FZKtXECtCIXaihVGRMD10+rGqYzT6Qpp+/kGMddKUGYEp5HjFQtHsqB+FboVqttLXILinAWLCA3pq5b+OEO9ctRWekkdUh3i6XXDp7CaZFGieAsuY3hPhfUwbI5jNm9FiRlNus/vE1rjCxukGF2MJ/yH2GS4SxD3Kb3XosVVuZtH2Sx51jEXKIt0nWsSREm3a9EdovSD+v8sXVyFIBnM3tWOHdGQpXl4G9T+XTrmGE1FFftusdu6qEFxeL1CqU1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YLiynLfWPYBI3p6aciiysyOQa+ljPEYq8UZEiba60Qk=; b=MW3uyHPksvOczaAPnaUthB0E7Qdd5sHs0Hw2ZH2isp0+21Kfx+znhXpajwsZVXaoU8OxdbCiLQBTYtr7dBx/u4llGBah5BatKFE9BPuVNPyo0+MnMLAVCfspdIS0L3TtWo2GPu0uQ87fD0s8xiC+D8648hVk590qJSV/Rac5lCnmrMl01egwYFbjkQ8Qpm+MEtwGmE/x/VarexRraYU0Wg9TyaR1qCcPE965YgatrgrchUpLwrpEGDnTWzpZnAR4rXmzYXYYnRzfDJpIyIaAEkHGsZuD5zaxrQpbtQZpeb990j3l4mOYXHCiU/wZn2CR0PcEHaR46Yb6u8TthBFeNQ== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:28:22 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:28:22 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 13/46] OvmfPkg/VmgExitLib: Add support for IOIO_PROT NAE events Date: Mon, 27 Jul 2020 10:25:54 -0500 Message-ID: <28a4c22643ec1e2e064e5706e95a8d17ba3ef07f.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN1PR12CA0112.namprd12.prod.outlook.com (2603:10b6:802:21::47) 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 SN1PR12CA0112.namprd12.prod.outlook.com (2603:10b6:802:21::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23 via Frontend Transport; Mon, 27 Jul 2020 15:28:21 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: f9add37c-67ed-4e68-de12-08d83241b274 X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: YCtz4rVyZy+SW8W3Y87q4ahXfezoAI1DNvkJ1QDjiWTkBkX3dHQUTSG6LUF1KD+E3/MgwzDP9wFy87ZhTFEqHhvbC3A9EMLAq22guHWZalFx21TticuwdM6gmxRvVnBnrDBTwdUtqIyBg3e6fkErF8bX9XF9Q/Rb2Y3QSKNKJnUs/R3jYpWiHeAqaVHoPVGIMuPGGrFyqw7xOnGa4TSfaFvO9K2H0r3Q2qBOtSEMGwPW25URfzskzo3+dFn8ZTSM08HHXPF4KvAyH4Hxt9+/05FZlYqooKQ24J62F00z1+DgbYCpnRYHb8POEi33lmrdsJHoga8EJ4TW77LW2yz39EUvpy1KDCCbOHvP9Mx7Ttdc85kN3ZfmFoq6LZtecNzXs17FNRxrP4Kd3QyuVpus4bEUmz/NUyAksBPHn3X1AQ/8vpv3mIWDkd3WUAVYAViFQ4Pg4dUFkyM4XYSvgk17lg== X-MS-Exchange-AntiSpam-MessageData: QGHRclY04leBw/w5pWlLTTXD4AEj7CQ54PfJ6sfH+V5Qyr3YAU3rKjOkKnYEF+Cm7OmNNIp+k7tDY7F+D8Hsd5zZJlrSvnTm7do/8WYI1KqUo75wTtCi8E5Q5jMPlfG4Eq3l9eIY0lwCuy8gXUJRfk6bL3HfS1oeFhSlWjHuq1h8MDNOnuNZ3CcZt7LWd15PHuGKHzODodrZ0tv4DmCepVwIMD/mJbYlZk3we7LGlsLsMD09DP+M2dTCrvHG5p/pVM+e5RC+JhyZK5myAuf3xZSWckBuPU3aYmAvbGx291m94VmOT9yFRdOo6/qQOVbQLaBUlOHQRpti76wyEyD+D2I5BbrITGK41tCUIeiBPYeSb+7/tzbzmUBh5bIUnAwSJNZe25feCPjidWoqGLct+a4vieEmcaNouU0LJ8b6aQlAD/gbHwiEgA0JXHGRtsOUxARTK1QVLAwhoopVCy+3BNWaV+BhMtvCjrdHz95/ps0= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: f9add37c-67ed-4e68-de12-08d83241b274 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:28:22.2751 (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: kRpHDMkDgWi/PcDTYNYNgra5xqwXbpKfTY+OMUuoUNOEbeTxKc+EkNMoGvs8fKf9j4D2FshHoOBJLwM8LqBJbg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: N7AtTX4J4dvNr6gWADmwB2dKx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863704; bh=+hf13d64ZaUnhLh0gcNx/3Vld8oSa1YJNce01IwZKk4=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=kdCmBgC4NmDVG1hHSTjyU4tH/STNK5WfI+1WBx3YPbGhdnLjlWO6CJ9H2/MSAIEn3Zy kKMk2NJ6r22jJepmujAx8RIYxRCj5EOZ53SS4tg+5nY+SxA/ncXknB8tVxbHxUSYrMzuS tfUXLvtRjzC3wia2KMW0XWQrLTkX/S8gmUE= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a IOIO_PROT intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Add support to construct the required GHCB values to support a IOIO_PROT NAE event. Parse the instruction that generated the #VC exception, setting the required register values in the GHCB and creating the proper SW_EXITINFO1 value in the GHCB. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- .../IndustryStandard/InstructionParsing.h | 83 +++ OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 560 +++++++++++++++++- 2 files changed, 629 insertions(+), 14 deletions(-) create mode 100644 OvmfPkg/Include/IndustryStandard/InstructionParsing.h diff --git a/OvmfPkg/Include/IndustryStandard/InstructionParsing.h b/OvmfPk= g/Include/IndustryStandard/InstructionParsing.h new file mode 100644 index 000000000000..149ff328e06c --- /dev/null +++ b/OvmfPkg/Include/IndustryStandard/InstructionParsing.h @@ -0,0 +1,83 @@ +/** @file + Instruction parsing support definitions. + + Copyright (C) 2020, Advanced Micro Devices, Inc. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef __INSTRUCTION_PARSING_H__ +#define __INSTRUCTION_PARSING_H__ + +#include +#include + +// +// Instruction REX prefix definition +// +typedef union { + struct { + UINT8 BitB:1; + UINT8 BitX:1; + UINT8 BitR:1; + UINT8 BitW:1; + UINT8 Rex:4; + } Bits; + + UINT8 Uint8; +} INSTRUCTION_REX_PREFIX; + +// +// Instruction ModRM definition +// +typedef union { + struct { + UINT8 Rm:3; + UINT8 Reg:3; + UINT8 Mod:2; + } Bits; + + UINT8 Uint8; +} INSTRUCTION_MODRM; + +// +// Instruction SIB definition +// +typedef union { + struct { + UINT8 Base:3; + UINT8 Index:3; + UINT8 Scale:2; + } Bits; + + UINT8 Uint8; +} INSTRUCTION_SIB; + +// +// Legacy Instruction Prefixes +// +#define OVERRIDE_SEGMENT_CS 0x2E +#define OVERRIDE_SEGMENT_DS 0x3E +#define OVERRIDE_SEGMENT_ES 0x26 +#define OVERRIDE_SEGMENT_SS 0x36 +#define OVERRIDE_SEGMENT_FS 0x64 +#define OVERRIDE_SEGMENT_GS 0x65 +#define OVERRIDE_OPERAND_SIZE 0x66 +#define OVERRIDE_ADDRESS_SIZE 0x67 +#define LOCK_PREFIX 0xF0 +#define REPNZ_PREFIX 0xF2 +#define REPZ_PREFIX 0xF3 + +// +// REX Prefixes +// +#define REX_PREFIX_START 0x40 +#define REX_PREFIX_STOP 0x4F +#define REX_64BIT_OPERAND_SIZE_MASK 0x08 + +// +// Two-byte Opcode Flag +// +#define TWO_BYTE_OPCODE_ESCAPE 0x0F + +#endif diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index b6a955ed8088..04e8b8aebf7d 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -11,6 +11,529 @@ #include #include #include +#include + +// +// Instruction execution mode definition +// +typedef enum { + LongMode64Bit =3D 0, + LongModeCompat32Bit, + LongModeCompat16Bit, +} SEV_ES_INSTRUCTION_MODE; + +// +// Instruction size definition (for operand and address) +// +typedef enum { + Size8Bits =3D 0, + Size16Bits, + Size32Bits, + Size64Bits, +} SEV_ES_INSTRUCTION_SIZE; + +// +// Intruction segment definition +// +typedef enum { + SegmentEs =3D 0, + SegmentCs, + SegmentSs, + SegmentDs, + SegmentFs, + SegmentGs, +} SEV_ES_INSTRUCTION_SEGMENT; + +// +// Instruction rep function definition +// +typedef enum { + RepNone =3D 0, + RepZ, + RepNZ, +} SEV_ES_INSTRUCTION_REP; + +typedef struct { + UINT8 Rm; + UINT8 Reg; + UINT8 Mod; +} SEV_ES_INSTRUCTION_MODRM_EXT; + +typedef struct { + UINT8 Base; + UINT8 Index; + UINT8 Scale; +} SEV_ES_INSTRUCTION_SIB_EXT; + +// +// Instruction opcode definition +// +typedef struct { + SEV_ES_INSTRUCTION_MODRM_EXT ModRm; + + SEV_ES_INSTRUCTION_SIB_EXT Sib; + + UINTN RegData; + UINTN RmData; +} SEV_ES_INSTRUCTION_OPCODE_EXT; + +// +// Instruction parsing context definition +// +typedef struct { + GHCB *Ghcb; + + SEV_ES_INSTRUCTION_MODE Mode; + SEV_ES_INSTRUCTION_SIZE DataSize; + SEV_ES_INSTRUCTION_SIZE AddrSize; + BOOLEAN SegmentSpecified; + SEV_ES_INSTRUCTION_SEGMENT Segment; + SEV_ES_INSTRUCTION_REP RepMode; + + UINT8 *Begin; + UINT8 *End; + + UINT8 *Prefixes; + UINT8 *OpCodes; + UINT8 *Displacement; + UINT8 *Immediate; + + INSTRUCTION_REX_PREFIX RexPrefix; + + BOOLEAN ModRmPresent; + INSTRUCTION_MODRM ModRm; + + BOOLEAN SibPresent; + INSTRUCTION_SIB Sib; + + UINTN PrefixSize; + UINTN OpCodeSize; + UINTN DisplacementSize; + UINTN ImmediateSize; + + SEV_ES_INSTRUCTION_OPCODE_EXT Ext; +} SEV_ES_INSTRUCTION_DATA; + +// +// Non-automatic Exit function prototype +// +typedef +UINT64 +(*NAE_EXIT) ( + GHCB *Ghcb, + EFI_SYSTEM_CONTEXT_X64 *Regs, + SEV_ES_INSTRUCTION_DATA *InstructionData + ); + + +/** + Checks the GHCB to determine if the specified register has been marked v= alid. + + The ValidBitmap area represents the areas of the GHCB that have been mar= ked + valid. Return an indication of whether the area of the GHCB that holds t= he + specified register has been marked valid. + + @param[in] Ghcb Pointer to the Guest-Hypervisor Communication Block + @param[in] Reg Offset in the GHCB of the register to check + + @retval TRUE Register has been marked vald in the GHCB + @retval FALSE Register has not been marked valid in the GHCB + +**/ +STATIC +BOOLEAN +GhcbIsRegValid ( + IN GHCB *Ghcb, + IN GHCB_REGISTER Reg + ) +{ + UINT32 RegIndex; + UINT32 RegBit; + + RegIndex =3D Reg / 8; + RegBit =3D Reg & 0x07; + + return ((Ghcb->SaveArea.ValidBitmap[RegIndex] & (1 << RegBit)) !=3D 0); +} + +/** + Marks a register as valid in the GHCB. + + The ValidBitmap area represents the areas of the GHCB that have been mar= ked + valid. Set the area of the GHCB that holds the specified register as val= id. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communication Bl= ock + @param[in] Reg Offset in the GHCB of the register to mark valid + +**/ +STATIC +VOID +GhcbSetRegValid ( + IN OUT GHCB *Ghcb, + IN GHCB_REGISTER Reg + ) +{ + UINT32 RegIndex; + UINT32 RegBit; + + RegIndex =3D Reg / 8; + RegBit =3D Reg & 0x07; + + Ghcb->SaveArea.ValidBitmap[RegIndex] |=3D (1 << RegBit); +} + +/** + Decode instruction prefixes. + + Parse the instruction data to track the instruction prefixes that have + been used. + + @param[in] Regs x64 processor context + @param[in, out] InstructionData Instruction parsing context + +**/ +STATIC +VOID +DecodePrefixes ( + IN EFI_SYSTEM_CONTEXT_X64 *Regs, + IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + SEV_ES_INSTRUCTION_MODE Mode; + SEV_ES_INSTRUCTION_SIZE ModeDataSize; + SEV_ES_INSTRUCTION_SIZE ModeAddrSize; + UINT8 *Byte; + + // + // Always in 64-bit mode + // + Mode =3D LongMode64Bit; + ModeDataSize =3D Size32Bits; + ModeAddrSize =3D Size64Bits; + + InstructionData->Mode =3D Mode; + InstructionData->DataSize =3D ModeDataSize; + InstructionData->AddrSize =3D ModeAddrSize; + + InstructionData->Prefixes =3D InstructionData->Begin; + + Byte =3D InstructionData->Prefixes; + for ( ; ; Byte++, InstructionData->PrefixSize++) { + // + // Check the 0x40 to 0x4F range using an if statement here since some + // compilers don't like the "case 0x40 ... 0x4F:" syntax. This avoids + // 16 case statements below. + // + if ((*Byte >=3D REX_PREFIX_START) && (*Byte <=3D REX_PREFIX_STOP)) { + InstructionData->RexPrefix.Uint8 =3D *Byte; + if ((*Byte & REX_64BIT_OPERAND_SIZE_MASK) !=3D 0) { + InstructionData->DataSize =3D Size64Bits; + } + continue; + } + + switch (*Byte) { + case OVERRIDE_SEGMENT_CS: + case OVERRIDE_SEGMENT_DS: + case OVERRIDE_SEGMENT_ES: + case OVERRIDE_SEGMENT_SS: + if (Mode !=3D LongMode64Bit) { + InstructionData->SegmentSpecified =3D TRUE; + InstructionData->Segment =3D (*Byte >> 3) & 3; + } + break; + + case OVERRIDE_SEGMENT_FS: + case OVERRIDE_SEGMENT_GS: + InstructionData->SegmentSpecified =3D TRUE; + InstructionData->Segment =3D *Byte & 7; + break; + + case OVERRIDE_OPERAND_SIZE: + if (InstructionData->RexPrefix.Uint8 =3D=3D 0) { + InstructionData->DataSize =3D + (Mode =3D=3D LongMode64Bit) ? Size16Bits : + (Mode =3D=3D LongModeCompat32Bit) ? Size16Bits : + (Mode =3D=3D LongModeCompat16Bit) ? Size32Bits : 0; + } + break; + + case OVERRIDE_ADDRESS_SIZE: + InstructionData->AddrSize =3D + (Mode =3D=3D LongMode64Bit) ? Size32Bits : + (Mode =3D=3D LongModeCompat32Bit) ? Size16Bits : + (Mode =3D=3D LongModeCompat16Bit) ? Size32Bits : 0; + break; + + case LOCK_PREFIX: + break; + + case REPZ_PREFIX: + InstructionData->RepMode =3D RepZ; + break; + + case REPNZ_PREFIX: + InstructionData->RepMode =3D RepNZ; + break; + + default: + InstructionData->OpCodes =3D Byte; + InstructionData->OpCodeSize =3D (*Byte =3D=3D TWO_BYTE_OPCODE_ESCAPE= ) ? 2 : 1; + + InstructionData->End =3D Byte + InstructionData->OpCodeSize; + InstructionData->Displacement =3D InstructionData->End; + InstructionData->Immediate =3D InstructionData->End; + return; + } + } +} + +/** + Determine instruction length + + Return the total length of the parsed instruction. + + @param[in] InstructionData Instruction parsing context + + @return Length of parsed instruction + +**/ +STATIC +UINT64 +InstructionLength ( + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + return (UINT64) (InstructionData->End - InstructionData->Begin); +} + +/** + Initialize the instruction parsing context. + + Initialize the instruction parsing context, which includes decoding the + instruction prefixes. + + @param[in, out] InstructionData Instruction parsing context + @param[in] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in] Regs x64 processor context + +**/ +STATIC +VOID +InitInstructionData ( + IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData, + IN GHCB *Ghcb, + IN EFI_SYSTEM_CONTEXT_X64 *Regs + ) +{ + SetMem (InstructionData, sizeof (*InstructionData), 0); + InstructionData->Ghcb =3D Ghcb; + InstructionData->Begin =3D (UINT8 *) Regs->Rip; + InstructionData->End =3D (UINT8 *) Regs->Rip; + + DecodePrefixes (Regs, InstructionData); +} + +/** + Report an unsupported event to the hypervisor + + Use the VMGEXIT support to report an unsupported event to the hypervisor. + + @param[in] Ghcb Pointer to the Guest-Hypervisor Communication + Block + @param[in] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @return New exception value to propagate + +**/ +STATIC +UINT64 +UnsupportedExit ( + IN GHCB *Ghcb, + IN EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + Status =3D VmgExit (Ghcb, SVM_EXIT_UNSUPPORTED, Regs->ExceptionData, 0); + if (Status =3D=3D 0) { + GHCB_EVENT_INJECTION Event; + + Event.Uint64 =3D 0; + Event.Elements.Vector =3D GP_EXCEPTION; + Event.Elements.Type =3D GHCB_EVENT_INJECTION_TYPE_EXCEPTION; + Event.Elements.Valid =3D 1; + + Status =3D Event.Uint64; + } + + return Status; +} + +/** + Build the IOIO event information. + + The IOIO event information identifies the type of IO operation to be per= formed + by the hypervisor. Build this information based on the instruction data. + + @param[in] Regs x64 processor context + @param[in, out] InstructionData Instruction parsing context + + @return IOIO event information value + +**/ +STATIC +UINT64 +IoioExitInfo ( + IN EFI_SYSTEM_CONTEXT_X64 *Regs, + IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 ExitInfo; + + ExitInfo =3D 0; + + switch (*(InstructionData->OpCodes)) { + // + // IN immediate opcodes + // + case 0xE4: + case 0xE5: + InstructionData->ImmediateSize =3D 1; + InstructionData->End++; + ExitInfo |=3D IOIO_TYPE_IN; + ExitInfo |=3D ((*(InstructionData->OpCodes + 1)) << 16); + break; + + // + // OUT immediate opcodes + // + case 0xE6: + case 0xE7: + InstructionData->ImmediateSize =3D 1; + InstructionData->End++; + ExitInfo |=3D IOIO_TYPE_OUT; + ExitInfo |=3D ((*(InstructionData->OpCodes + 1)) << 16) | IOIO_TYPE_OU= T; + break; + + // + // IN register opcodes + // + case 0xEC: + case 0xED: + ExitInfo |=3D IOIO_TYPE_IN; + ExitInfo |=3D ((Regs->Rdx & 0xffff) << 16); + break; + + // + // OUT register opcodes + // + case 0xEE: + case 0xEF: + ExitInfo |=3D IOIO_TYPE_OUT; + ExitInfo |=3D ((Regs->Rdx & 0xffff) << 16); + break; + + default: + return 0; + } + + switch (*(InstructionData->OpCodes)) { + // + // Single-byte opcodes + // + case 0xE4: + case 0xE6: + case 0xEC: + case 0xEE: + ExitInfo |=3D IOIO_DATA_8; + break; + + // + // Length determined by instruction parsing + // + default: + ExitInfo |=3D (InstructionData->DataSize =3D=3D Size16Bits) ? IOIO_DAT= A_16 + : IOIO_DATA_32; + } + + switch (InstructionData->AddrSize) { + case Size16Bits: + ExitInfo |=3D IOIO_ADDR_16; + break; + + case Size32Bits: + ExitInfo |=3D IOIO_ADDR_32; + break; + + case Size64Bits: + ExitInfo |=3D IOIO_ADDR_64; + break; + + default: + break; + } + + if (InstructionData->RepMode !=3D 0) { + ExitInfo |=3D IOIO_REP; + } + + return ExitInfo; +} + +/** + Handle an IOIO event. + + Use the VMGEXIT instruction to handle an IOIO event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +IoioExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 ExitInfo1, Status; + + ExitInfo1 =3D IoioExitInfo (Regs, InstructionData); + if (ExitInfo1 =3D=3D 0) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + + if ((ExitInfo1 & IOIO_TYPE_IN) !=3D 0) { + Ghcb->SaveArea.Rax =3D 0; + } else { + CopyMem (&Ghcb->SaveArea.Rax, &Regs->Rax, IOIO_DATA_BYTES (ExitInfo1)); + } + GhcbSetRegValid (Ghcb, GhcbRax); + + Status =3D VmgExit (Ghcb, SVM_EXIT_IOIO_PROT, ExitInfo1, 0); + if (Status !=3D 0) { + return Status; + } + + if ((ExitInfo1 & IOIO_TYPE_IN) !=3D 0) { + if (!GhcbIsRegValid (Ghcb, GhcbRax)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + CopyMem (&Regs->Rax, &Ghcb->SaveArea.Rax, IOIO_DATA_BYTES (ExitInfo1)); + } + + return 0; +} =20 /** Handle a #VC exception. @@ -38,6 +561,8 @@ VmgExitHandleVc ( MSR_SEV_ES_GHCB_REGISTER Msr; EFI_SYSTEM_CONTEXT_X64 *Regs; GHCB *Ghcb; + NAE_EXIT NaeExit; + SEV_ES_INSTRUCTION_DATA InstructionData; UINT64 ExitCode, Status; EFI_STATUS VcRet; =20 @@ -54,24 +579,31 @@ VmgExitHandleVc ( =20 ExitCode =3D Regs->ExceptionData; switch (ExitCode) { + case SVM_EXIT_IOIO_PROT: + NaeExit =3D IoioExit; + break; + default: - Status =3D VmgExit (Ghcb, SVM_EXIT_UNSUPPORTED, ExitCode, 0); - if (Status =3D=3D 0) { - Regs->ExceptionData =3D 0; - *ExceptionType =3D GP_EXCEPTION; + NaeExit =3D UnsupportedExit; + } + + InitInstructionData (&InstructionData, Ghcb, Regs); + + Status =3D NaeExit (Ghcb, Regs, &InstructionData); + if (Status =3D=3D 0) { + Regs->Rip +=3D InstructionLength (&InstructionData); + } else { + GHCB_EVENT_INJECTION Event; + + Event.Uint64 =3D Status; + if (Event.Elements.ErrorCodeValid !=3D 0) { + Regs->ExceptionData =3D Event.Elements.ErrorCode; } else { - GHCB_EVENT_INJECTION Event; - - Event.Uint64 =3D Status; - if (Event.Elements.ErrorCodeValid !=3D 0) { - Regs->ExceptionData =3D Event.Elements.ErrorCode; - } else { - Regs->ExceptionData =3D 0; - } - - *ExceptionType =3D Event.Elements.Vector; + Regs->ExceptionData =3D 0; } =20 + *ExceptionType =3D Event.Elements.Vector; + VcRet =3D EFI_PROTOCOL_ERROR; } =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63317): https://edk2.groups.io/g/devel/message/63317 Mute This Topic: https://groups.io/mt/75824969/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 Fri Apr 26 07:16:41 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+63318+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+63318+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 1595863713671112.00589962889308; Mon, 27 Jul 2020 08:28:33 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 8mNnYY1788612xm7dnzvXUVT; Mon, 27 Jul 2020 08:28:33 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.74]) by mx.groups.io with SMTP id smtpd.web11.58100.1595863712802475943 for ; Mon, 27 Jul 2020 08:28:32 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C3AtjNZOa25w6upmseuAH1cDFI6HxXO1hjJFZ7ItRDzy1e9Nmm+h5ikJ9vv26eYSr7QhJmH+psm72dazWC1lYfYx9X4n/F2+vlWUBLIzFLoEgCvQB8TWfogX6W2TgaoFpIaLTVqdKrgpMgTNAKmTauw9GAeenotYFN/kXS3cDinfZLRQ/GnmapTHYg6UpmEz2T4t87YlMNKpH/Uq0vmcGathWKstqL2sf+l7opjK/PWOZkrDalwMu0azRPsgC82vL7fAayP2Jn6Q82lTmbmOskyIJ2Yt/CNx9LdF0qbPQJu3ijnyIGtpYsFB9tJd4c3RfPqgiRKUKHfyEQvjpb/Ozw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QsU9z538ohZ+gSll/ViYNK4rF8hs9EY7Z10fIy3XOy0=; b=WgIMfJ8OYkikTZJ1D9fxZK3RpdI8V4GyaU4nRTVdwj+8s/tBlfTG27wwR6iXk8NWC4sWpScM2/QUKLt+Ghj1Vx4O6otgA9QjCmAdwY0bF4VCOWVNekSfe2XRQqsBMwo+sj5oxA9QVuPlqvKUhUu6/9Xe9AAFdN1Tx0ga7iR9AyFZRumrhdMOVVtmr59WK7cLA5tzhTJHIjQwsbAGSP6UuvsQ2WIhuIAzCaADNRvFm2ebiYNEnxYzn8Ye0teZ1v7pLgOpWIoH6QghwUwCSERA+ilbjsNSNonWn52bEWbyhnyZqQg2++XlLMQAbzyAH/j92Qbz3DzHfqNK+Ve4DEpQCw== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:28:31 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:28:31 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 14/46] OvmfPkg/VmgExitLib: Support string IO for IOIO_PROT NAE events Date: Mon, 27 Jul 2020 10:25:55 -0500 Message-ID: <66da13b911a4283f3eab35e821b7f7795e119261.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0026.namprd21.prod.outlook.com (2603:10b6:805:106::36) 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 SN6PR2101CA0026.namprd21.prod.outlook.com (2603:10b6:805:106::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.1 via Frontend Transport; Mon, 27 Jul 2020 15:28: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: f63a5e64-555c-4348-e4f4-08d83241b7d6 X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: 06b012IzpW5f+ddcXBrUuwDcd8SuFPMic+5dVp48xqFklRzrp1Ze81LyHrIgXyN8pXH8YM0Tg0wIdyOlmOC1jk7LGq51LkPOEO7TVzZHjnDgH1nI7d/244RJ4J8lRnVh4ACetv6ZYaI+fHxggsEXbZQNyEDNsLRziaW2XJOAtaAcuRoVO4ibIc0pG0a9FiUf3vK/jHc8ii0FN1h2VZHeUyTkCMJ4nAU9zEco3Of+674uRB7orLkZ1pPHtRlhwrm7eX6eOy/JhfGKnacnGwVVM1WYaJOrAYBIB+anmXJAjTR8ta2GYR8SksJ78b6tDac4MZATcLTUAvgRzv1DdijWN/wTEdPx2LUlaZtpZ/I7rXsbejDbXNOntow4Db9H3pAhqG6pbKltGgMZd+Cemkurv6QsGnLydvWhRVCJepZ+MX4gDBtKUDIuMzIxN3PdDRmMx+TT5Wr/07I4uS5K8OIRug== X-MS-Exchange-AntiSpam-MessageData: TM9E5XkZekg+DUlHKoGVtryQt4kWhEC8a/eTIELe8HvJZVs5KKj2SUKUame/4T/Cvgou+bQ7u/UlNBMuua2MKm+k43e4z06/R2TKoC+0Kj2rc2RfZyDXA8AfYzKOrfQGV52gQRd7scPJwsk2PMWjDpnvSoHKaeD7cZjV6eG9FBoG5ReHsZCthBJFj1DOJeBazIWKgFXFcYe9Wy8T27UPAhV42Iu55mH3HJnY3gr4Om8dC7rJI7prJYXZ3B2azpvdhN72Q25LsBNBVCcG5qHm7+yX4obqXRtLO1QLU4xmJCMe64q+wFPhS84xB0z74RHH1XeNnQmYeLDOap+ypj4dBXEjtKSIwalYsFGvQLCORevl7Fp+Vj0giFyWQDhQEcl1Wxd+BZlcbdpNrW9PqPMxDh38YXOM3EHVd7ivTJeVRq6PNQ36T3TEQ+6pg9gnmNLqWUaBki+znh+G/WNJ5PgLaS8iZG0MnvUzy0GlNVm7ovI= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: f63a5e64-555c-4348-e4f4-08d83241b7d6 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:28:31.2981 (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: QqXdep/qg0bTtSZHUdDE4oh2QPR1FMVK7gDp/EcD7Orl+BYEDBRRNxt4Kgyc7t9DGhc6mWG3G3T8MHL/s807cQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: mFKDmlraaIIchLjGPe8oycWox1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863713; bh=GF3kK1u5KY0QrDP9NbsoER3Zt3T2XbYo50phntdb2wU=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=ZwXiYKzXr8H/WVXG5vLtz/mXUICfvLMdBEq6H30MIMUYtJ4LALk5pxphj6TNa+iceX6 KzkkZMeF1sfUIj6fG8iYHFYHBHphsxImYyOnAGYP4b8lAlMZR+uV8ODWZpzW8CUWOAb6m bjY9PdSgEg6z/kDh96gNR7nvxz2SdzlM3xw= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Add support to the #VC exception handler to handle string IO. This requires expanding the IO instruction parsing to recognize string based IO instructions as well as preparing an un-encrypted buffer to be used to transfer (either to or from the guest) the string contents for the IO operation. The SW_EXITINFO2 and SW_SCRATCH fields of the GHCB are set appropriately for the operation. Multiple VMGEXIT invocations may be needed to complete the string IO operation. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 90 ++++++++++++++++--- 1 file changed, 76 insertions(+), 14 deletions(-) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index 04e8b8aebf7d..b6ac3552894f 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -397,6 +397,26 @@ IoioExitInfo ( ExitInfo =3D 0; =20 switch (*(InstructionData->OpCodes)) { + // + // INS opcodes + // + case 0x6C: + case 0x6D: + ExitInfo |=3D IOIO_TYPE_INS; + ExitInfo |=3D IOIO_SEG_ES; + ExitInfo |=3D ((Regs->Rdx & 0xffff) << 16); + break; + + // + // OUTS opcodes + // + case 0x6E: + case 0x6F: + ExitInfo |=3D IOIO_TYPE_OUTS; + ExitInfo |=3D IOIO_SEG_DS; + ExitInfo |=3D ((Regs->Rdx & 0xffff) << 16); + break; + // // IN immediate opcodes // @@ -445,6 +465,8 @@ IoioExitInfo ( // // Single-byte opcodes // + case 0x6C: + case 0x6E: case 0xE4: case 0xE6: case 0xEC: @@ -506,30 +528,70 @@ IoioExit ( IN SEV_ES_INSTRUCTION_DATA *InstructionData ) { - UINT64 ExitInfo1, Status; + UINT64 ExitInfo1, ExitInfo2, Status; + BOOLEAN IsString; =20 ExitInfo1 =3D IoioExitInfo (Regs, InstructionData); if (ExitInfo1 =3D=3D 0) { return UnsupportedExit (Ghcb, Regs, InstructionData); } =20 - if ((ExitInfo1 & IOIO_TYPE_IN) !=3D 0) { - Ghcb->SaveArea.Rax =3D 0; + IsString =3D ((ExitInfo1 & IOIO_TYPE_STR) !=3D 0) ? TRUE : FALSE; + if (IsString) { + UINTN IoBytes, VmgExitBytes; + UINTN GhcbCount, OpCount; + + Status =3D 0; + + IoBytes =3D IOIO_DATA_BYTES (ExitInfo1); + GhcbCount =3D sizeof (Ghcb->SharedBuffer) / IoBytes; + + OpCount =3D ((ExitInfo1 & IOIO_REP) !=3D 0) ? Regs->Rcx : 1; + while (OpCount) { + ExitInfo2 =3D MIN (OpCount, GhcbCount); + VmgExitBytes =3D ExitInfo2 * IoBytes; + + if ((ExitInfo1 & IOIO_TYPE_IN) =3D=3D 0) { + CopyMem (Ghcb->SharedBuffer, (VOID *) Regs->Rsi, VmgExitBytes); + Regs->Rsi +=3D VmgExitBytes; + } + + Ghcb->SaveArea.SwScratch =3D (UINT64) Ghcb->SharedBuffer; + Status =3D VmgExit (Ghcb, SVM_EXIT_IOIO_PROT, ExitInfo1, ExitInfo2); + if (Status !=3D 0) { + return Status; + } + + if ((ExitInfo1 & IOIO_TYPE_IN) !=3D 0) { + CopyMem ((VOID *) Regs->Rdi, Ghcb->SharedBuffer, VmgExitBytes); + Regs->Rdi +=3D VmgExitBytes; + } + + if ((ExitInfo1 & IOIO_REP) !=3D 0) { + Regs->Rcx -=3D ExitInfo2; + } + + OpCount -=3D ExitInfo2; + } } else { - CopyMem (&Ghcb->SaveArea.Rax, &Regs->Rax, IOIO_DATA_BYTES (ExitInfo1)); - } - GhcbSetRegValid (Ghcb, GhcbRax); + if ((ExitInfo1 & IOIO_TYPE_IN) !=3D 0) { + Ghcb->SaveArea.Rax =3D 0; + } else { + CopyMem (&Ghcb->SaveArea.Rax, &Regs->Rax, IOIO_DATA_BYTES (ExitInfo1= )); + } + GhcbSetRegValid (Ghcb, GhcbRax); =20 - Status =3D VmgExit (Ghcb, SVM_EXIT_IOIO_PROT, ExitInfo1, 0); - if (Status !=3D 0) { - return Status; - } + Status =3D VmgExit (Ghcb, SVM_EXIT_IOIO_PROT, ExitInfo1, 0); + if (Status !=3D 0) { + return Status; + } =20 - if ((ExitInfo1 & IOIO_TYPE_IN) !=3D 0) { - if (!GhcbIsRegValid (Ghcb, GhcbRax)) { - return UnsupportedExit (Ghcb, Regs, InstructionData); + if ((ExitInfo1 & IOIO_TYPE_IN) !=3D 0) { + if (!GhcbIsRegValid (Ghcb, GhcbRax)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + CopyMem (&Regs->Rax, &Ghcb->SaveArea.Rax, IOIO_DATA_BYTES (ExitInfo1= )); } - CopyMem (&Regs->Rax, &Ghcb->SaveArea.Rax, IOIO_DATA_BYTES (ExitInfo1)); } =20 return 0; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63318): https://edk2.groups.io/g/devel/message/63318 Mute This Topic: https://groups.io/mt/75824974/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 Fri Apr 26 07:16:41 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+63319+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+63319+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 1595863721664397.38289149134005; Mon, 27 Jul 2020 08:28:41 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id bJjQYY1788612xcrkxSLrmnV; Mon, 27 Jul 2020 08:28:41 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.81]) by mx.groups.io with SMTP id smtpd.web12.58091.1595863720734281419 for ; Mon, 27 Jul 2020 08:28:40 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IMYj7kOTRJkB/lKCq6BYeazCNTDQNhqJ2R3nRpDG5pZ6M4bUY/g4PEtIFwCHUr+wSfJb5c1/EIvvwsQKb3sdyUuS14nCi7ZQNifQWSq0aGdZ+5nQbSvQ7zr6e00sIPsAxJlKubab6dvvus6o57uWkapRYhN2zwT61BTMlvmwri2wEGue2IR3akq5FJDUg63tSlGPw1RS87uN9PH0w2m0Jg+9aOj6LUwcLDqkHdDOYh2dPtjDB9O/z4DtIJgXshXL+9uc0SC8eE6iEZulTPpz+Fsflb/c3AiuPBHzILrdSwOR1X2ljN/wdQ+ckvX8fepJjfH4qDr6OCSFidRHwJdsZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DefcxGXcet0YpbciDB6cqSIPAFoRtyFhEUPqxpHT3rE=; b=FWKCrEtHWYlJzpCKEIN5WbS/IQRqjS58NRPQFFkaiIm1bfFJwg89X0Jx6aKM4vYfgKUzyrzPTNCIHKaXo8fdBBoKZPZmDoPLc6g+zPO6dsUrSXml69+qhFlDdjum1nIkO0/tJn/aKbwgkavl7jbXmsKj8TxSLFQKqWgms3cCJ6Enitne0HqLWXikjU2+XChQQ/uaai/mPUo+bv1CaxFsax6o8rbRS8WL/7tFZ+VxJB4zs07nkC/5loeR8q+ugPbFRxBg2B0lrC5fR7YsCr7ZferPJfqo54/gYbsVUaw+H1S09l4YRUM15RxVBVk751OC82OQr/cBL4p0KACSF1HVOQ== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:28:39 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:28:39 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 15/46] OvmfPkg/VmgExitLib: Add support for CPUID NAE events Date: Mon, 27 Jul 2020 10:25:56 -0500 Message-ID: <3db24fead886864ebc31ccd5c73598faaca86706.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SA9PR03CA0028.namprd03.prod.outlook.com (2603:10b6:806:20::33) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SA9PR03CA0028.namprd03.prod.outlook.com (2603:10b6:806:20::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.24 via Frontend Transport; Mon, 27 Jul 2020 15:28: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: fcf75822-d3ee-4d62-446a-08d83241bc8c X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: LH3Y5ptfgkb8UBZaF472iVimY2GWsWYitfb1ihsQtiUCBQTr29geLdfjbwwK/PiLJTCDLVUY4A4O1nQ8m6dPnGaSVE36lXZ4S43Tkf3OSkdThuoBBtVx6Ax/4nG0HJYOy3ekm+4C7s8M0mrmJKg9zvtXn2lArblayVr8ZEjAJsWIxhZ6jRsOwiGc9OReQmiHPXNVmwgLa3ddxpG/CwNMjCwCANjGfPNQ0wFSSBaRsxyDCOt6JO/gx5wToCS3GAf6MGH0L/gFBnX8wtBVEltEpJqDMdN36LjB6kODlOvfS33+TZykcOezGUkU6M1nHnvcebj+7R+u1YVvE57nmyr/OllzUfO+uaGH2LPFXuMhm8IiwolobeyiGfc23Ve08VGWiCsdDdhkcMgtzpl5ev6eQ2iFIXFaznf4lb9xyhqE6vBs3u8p8tG+GUFtAHsyCG3AVgY4DGW5vD6+YoQk6PL06g== X-MS-Exchange-AntiSpam-MessageData: 6jIKD4/7AclktBgbfJ63gOV2OwGScfjKdhhUvijqNtWJOrwh95L0khbzRz2l7xrUzG3/+MOT8cCML6ene/4IWuk1sgesvVkyO1hcwACmc0TVlNJilfLScQ0wGR4bQccKMdzo/TKuPA2zRDAvp+LekYPG1IcI+L1MOb3+lFQAtX/lM6+6TPnErdH5Rbx3K6U+Q/qDRwIPn7tIGljE38iQZVaYr/zb8Iz5cI3zFgS/WzjJytjBLU1RoaJV8I83weEQaZRhgXwCjzdIn+kaI2bTlqMaMWW9DPpkSAW1bDqTdqODqnL6FlAQAzILOflbqjxs4X99CwoMWPGd/XT4XGoSMmf9JGO0e8qFD/tRu2xXdKKC+BOdQ2gQUpF18FgzdL0v7lw7gc+rfaRerKVmIDqEtJUz61ejyqYiBbmS2UmCINK9Kk2AAR659mNG6y6ah6o6kCUjOQlnYidi3FWckMQhd78QZiWyyDbCV8q3GFtm/C8= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: fcf75822-d3ee-4d62-446a-08d83241bc8c X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:28:39.1806 (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: f7JK2IdZ0ltkkdRelprYVZnFidUGwHudZRci8aIIHj+UYaUCUE+D0OWtL56+Eb1vuKbbHOgnuEwqQeAXDZvzWg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: YAeKyWL0tmjFIispmQ27wTaPx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863721; bh=B/9wJy4G7bbRTLwENbZ+NtEagpgMru3nRRB4QOqArY0=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=J4KkDox3kruZvT4K9yh8sZHPimq5wFpOl7DqfLqt451jJVorUBTuy/y9i8K5/g9c8pV 8ZZDSJkIQMwuJhOFCNc8L5+VYACME7698SXnKiOWbTpf6BgPfJ5v0bs2HADTi+XbFX3Qn VQMS2BD6nbLV5g74ORpGLR2mgn1bdrGKb/w= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a CPUID intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Add support to construct the required GHCB values to support a CPUID NAE event. Additionally, CPUID 0x0000_000d (CPUID_EXTENDED_STATE) requires XCR0 to be supplied in the GHCB, so add support to issue the XGETBV instruction. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index b6ac3552894f..1c9c272a250e 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -11,6 +11,7 @@ #include #include #include +#include #include =20 // @@ -597,6 +598,61 @@ IoioExit ( return 0; } =20 +/** + Handle a CPUID event. + + Use the VMGEXIT instruction to handle a CPUID event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +CpuidExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + Ghcb->SaveArea.Rax =3D Regs->Rax; + GhcbSetRegValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Rcx =3D Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + if (Regs->Rax =3D=3D CPUID_EXTENDED_STATE) { + IA32_CR4 Cr4; + + Cr4.UintN =3D AsmReadCr4 (); + Ghcb->SaveArea.XCr0 =3D (Cr4.Bits.OSXSAVE =3D=3D 1) ? AsmXGetBv (0) : = 1; + GhcbSetRegValid (Ghcb, GhcbXCr0); + } + + Status =3D VmgExit (Ghcb, SVM_EXIT_CPUID, 0, 0); + if (Status !=3D 0) { + return Status; + } + + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRbx) || + !GhcbIsRegValid (Ghcb, GhcbRcx) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; + Regs->Rbx =3D Ghcb->SaveArea.Rbx; + Regs->Rcx =3D Ghcb->SaveArea.Rcx; + Regs->Rdx =3D Ghcb->SaveArea.Rdx; + + return 0; +} + /** Handle a #VC exception. =20 @@ -641,6 +697,10 @@ VmgExitHandleVc ( =20 ExitCode =3D Regs->ExceptionData; switch (ExitCode) { + case SVM_EXIT_CPUID: + NaeExit =3D CpuidExit; + break; + case SVM_EXIT_IOIO_PROT: NaeExit =3D IoioExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63319): https://edk2.groups.io/g/devel/message/63319 Mute This Topic: https://groups.io/mt/75824978/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 Fri Apr 26 07:16:41 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+63320+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+63320+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 1595863729325398.64839767038745; Mon, 27 Jul 2020 08:28:49 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 2uIUYY1788612xibbki3kPGc; Mon, 27 Jul 2020 08:28:49 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.61]) by mx.groups.io with SMTP id smtpd.web11.58105.1595863728428861189 for ; Mon, 27 Jul 2020 08:28:48 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hcTRAX01HIfvxflc3oaDHCoOMBPUfaS9QBzMPkJI8S1vfwMFIjvg3PemWX2HRrHjlyNtftMGRt/210muofoY4DL9KYeMgAeBedcIKL3yWbeb605wahfph2ZXuURO773Ke50wLrR9SRaDfPeRlFqxXrh1agARNSIBHRtEQpVauCZ6i5s6TQmAlPqO83EOwyUryDFGpkGp1uo1uIXaIJel/N5TLVH1xFSi60NwZHcnhfpAw2hZQRU2eEMXfLtrcMxzSU7x+NCsdcUbyhVqHinrYHCKxvDUaR9nSB4i5hUVD6aipiXBIl1+jPsYll8MtBSmAehtYG3a1g2m0bnjNrl7pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=z7KM/QY3QdiNzO0sLsMAJB/dGUXDqeKlzSZHqwBk/3M=; b=RZxNd8cqvo5XTqt6fJwtPI+t5RLbOLZo9fnU6NU38evjWT8Dn/iDDsgmVmnf67O4y8veOoIf1fg7QL5N4NO9ADQfQyxlct99PL1Bss0aCGIiYbEV1+5q6ulC0pIKdA12nV5KnjTo3IQNMBLEG3atlNf0zlJebphFzrPBYewqVeBdG9gNFMnkIXsJmYjkNCuIyNXsaeMuWJM+rYtiYNKTYUoDHPNgTGA6CxHb14ypqN3F+/ko2R3j+3NbKx0Qx+ATou6ggCcnLdm2/NVHqEG/OT9b+O7uFQExO4eiLImWyq+bU+UPx4JPUncLIEfS1j4PVRtNxIms3JM+Zs8fDJOp9g== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:28:47 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:28:47 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 16/46] OvmfPkg/VmgExitLib: Add support for MSR_PROT NAE events Date: Mon, 27 Jul 2020 10:25:57 -0500 Message-ID: <6e72b5c8e75b18fd1c02b06b5cf29ee0924f2017.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN1PR12CA0060.namprd12.prod.outlook.com (2603:10b6:802:20::31) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN1PR12CA0060.namprd12.prod.outlook.com (2603:10b6:802:20::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.21 via Frontend Transport; Mon, 27 Jul 2020 15:28: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: 48c8da94-3562-4049-3fc9-08d83241c14b X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: diW5arVs7xKyxwLQuW0pHvq5fmci/SkFCO4/D8M4hd1WBoCAFDhG9P+HHVz9k2QsvzKsrHaHM8I5QZROxfG6d49WWrwckGLWQdINCYArRRFrajUlFi++DbgIK+w4K0/XHjE/FXDWlzScdTukGBHUQF6SLWX3wcIsiOs6Gw1wHM/u1IBZc6H7YgRLurzT3KgMRgCVotg5DLXY7avUM+aS4S+dFsXile9ko2HJ4qz/DiEYdSPzTI9cRTJTwej+bu8ow7NzS52yigUY95oiEnBhTA3/0utjBP9l3Opw17nsYVhbIy/nfs44xzzlYniltmtPzgKZvZrnP0Dr+z1kyl2sP+YbRKFWK9rijnvzUu99cqrubKabF0jPS9Xr5yfuveKjfAEHJOVyzKRMxiCoQ6KLed9noTKqIjL4exCHHX1X08HRyoeORprTE/PyescKjzhzKgV3P5TNwXZq8u2koCxtQQ== X-MS-Exchange-AntiSpam-MessageData: REktPDWCRb5aQdcsYT9pkWJz0D7UnUPI/Mt9E0c79mliyhzwEUf7LNCByA/1+5rMeNUUNjFrf8jBDDmnykfwh5fW0TOI8wKYJTb7LKN/doP/HYWocsmsBNDoRWxOJC/RNuhrIWOzc0fF/Uzw/SmhXkpTtgsd2kW8kUiQw3S14F5s9SUDuRz2DrfDcc9J6n1zqeIlXhcPGIwtlbp71p4b37wLosUQ07kGlnoPEw2lYZFQoSXjTnPAg/7iSE95G34765PiVJiZ/QW40H4MGl/8TnWBi3lFwi5x8QOLZHyFdRjHDm+W83T9Hs2dXHAfz9z6c3NKWxLHh26UQDhLJRQcsiRus3gGVYmbqv6QsJd99GI7taonm9WmHkfTKBHTd72YuycMCMrHHZpdzc7y1LJPJ/1yuTc+dU9J9P2W+uDVoirg3YjEhvDoKbfFR3+4ICE5n/YQVPJzRXZnFvt6lquvG0GCR6Ee+WrpPAZIloFvYJ0= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 48c8da94-3562-4049-3fc9-08d83241c14b X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:28:47.1221 (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: VUm0BErdv/ydKfvBXZ8h3gq06TPpJS9hGSGzxe+nxp+6hXdYuLETSR9Ska1HQxrZLKYjPqQ2PiXoaHAeXOz02A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: mOFt1DZ1AkkM48hQ9PvMcHSnx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863729; bh=vUabmcSLaPj1k/IwMKMuHX9yj/LBRzJW75ZOykGI2Mc=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=cePFF1JKsKwh/Sg4O1Z5Pm3Bs3B2WmndL2ebNFoJcOo7Y1f9DQX3xVVAdo9U815gexr TfaLnN7QMXNG4dMuW2HQLXBaJzxNaNHgcSo86CO3EzPib7qG2utO1lziZVg3mB0tFKDM+ QW11GFZTTIWutCuQm3gZTNj8d1cQSksNBeo= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a MSR_PROT intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Add support to construct the required GHCB values to support an MSR_PROT NAE event. Parse the instruction that generated the #VC exception to determine whether it is RDMSR or WRMSR, setting the required register register values in the GHCB and creating the proper SW_EXIT_INFO1 value in the GHCB. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index 1c9c272a250e..dbedd4e9f95d 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -374,6 +374,67 @@ UnsupportedExit ( return Status; } =20 +/** + Handle an MSR event. + + Use the VMGEXIT instruction to handle either a RDMSR or WRMSR event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +MsrExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 ExitInfo1, Status; + + ExitInfo1 =3D 0; + + switch (*(InstructionData->OpCodes + 1)) { + case 0x30: // WRMSR + ExitInfo1 =3D 1; + Ghcb->SaveArea.Rax =3D Regs->Rax; + GhcbSetRegValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Rdx =3D Regs->Rdx; + GhcbSetRegValid (Ghcb, GhcbRdx); + // + // fall through + // + case 0x32: // RDMSR + Ghcb->SaveArea.Rcx =3D Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + break; + default: + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + + Status =3D VmgExit (Ghcb, SVM_EXIT_MSR, ExitInfo1, 0); + if (Status !=3D 0) { + return Status; + } + + if (ExitInfo1 =3D=3D 0) { + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; + Regs->Rdx =3D Ghcb->SaveArea.Rdx; + } + + return 0; +} + /** Build the IOIO event information. =20 @@ -705,6 +766,10 @@ VmgExitHandleVc ( NaeExit =3D IoioExit; break; =20 + case SVM_EXIT_MSR: + NaeExit =3D MsrExit; + break; + default: NaeExit =3D UnsupportedExit; } --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63320): https://edk2.groups.io/g/devel/message/63320 Mute This Topic: https://groups.io/mt/75824983/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 Fri Apr 26 07:16:41 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+63321+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+63321+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 159586373755534.851099158928605; Mon, 27 Jul 2020 08:28:57 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id rzDRYY1788612xe81DFagZHH; Mon, 27 Jul 2020 08:28:57 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.82]) by mx.groups.io with SMTP id smtpd.web12.58097.1595863736545529224 for ; Mon, 27 Jul 2020 08:28:56 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J8+lqChoqy/tq6t8GgdHaZToO3/lhi1oy5YyDCnm1mJaTrHTnsYK95kYXJU4y4UX5f/h+2Tw2OQ3Lr3CagHMsYS/7rYbVousAIGT8gw6DDhayIUE+GkGvB4HPLrkfAuNstqlmgj/ii0tHK5bf4jVBFsD2wvzEetkSy5MGnhUsdUVHCTzJLSZsoaOPW3olpED+s1Vv16mCQRkftkNsdQgXuytBoiOgCzCrFNq39wx4pmF8aRJtTfo+kpeh81MFKap363TdPnmfPU8xKbzQZAEYieuA5ZfGNZfWg8Ccu5eXpb6IqqsQQ7JUB73EudYecTN5etNB7Ri5N8z7dD3OXd47Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3fv0LySMv02Eoii4eBNtz7XCoDCF4qBd0ZrJwx44Uo0=; b=mYICv2P6t/hs0YHkzDHYTWnyfOnSuKCvU9xG4/+pEK/AU74xIqQhJBNFTuEKEse70pTZp88GLFhOf6GAlPJo9pg0VOfzV4Fpbju16fjZVkV6eWOpr+luMYKG5Bvoc8zOxLtxpQxCNCk2nyyWwEPBiUJnWdStyj//gxX0D3ePjYBc6psLbU0yyZxbeMTN9NkC8if2Q446NVf31AC9NnzNXnAwj2dN2OrF28ixSXz7eh1yE1zqC+xqswisbpNqzI7/RoisJHBPMhkm9CZ1CDKA17jGtacEzh2yzrZKl7zmU81Q+MxvHU0U2bKJ64Y8pyVJn45n/zuUzWcgWR452EkLXg== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:28:55 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:28:55 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 17/46] OvmfPkg/VmgExitLib: Add support for NPF NAE events (MMIO) Date: Mon, 27 Jul 2020 10:25:58 -0500 Message-ID: <808c62ea2b2d50bc39f8aebf2c530b7b14d069b4.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN2PR01CA0016.prod.exchangelabs.com (2603:10b6:804:2::26) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN2PR01CA0016.prod.exchangelabs.com (2603:10b6:804:2::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23 via Frontend Transport; Mon, 27 Jul 2020 15:28: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: 78ef0d8d-764e-4c95-2151-08d83241c604 X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: tgCKRB9EjLGrKu5CA+zj67CNeTc44MLxdgyBHFLK8Rq0KhSiCwUBrnUsBmtIYK38/HWqs77t6NxWxPi+0LMFRddfLpLym1drrqPJJK6X7WxSNdIf1qjtvcdJnOZLPqEWFVZRAwNVBo4oFBrO2HYgSwboPlRSQuv2SE1QdY//JNmFluQhtFhBDg75bixngdzsf2vM7Brs93GPaKsX4aedLB2JqD29HGFRekQb0fXZRtPzzKdjBWv9bncfvv4oQjBIhugdDazufS3rJy29+hfemBHsRYlp5sbJHK2h+AbnpP6Kb2X2j8C1Vpe7Nayuy8/YsSPDFgADYLQRyIbQWi80mzgzigtIHukf7ObqZZoDj5Df1UiQum4Sun3kBdvmu40FBstrYuay5BAUYCVh/a3z2iqMMqXi/ICFkTk5Roo/v5fppLOtWf00LV/zKTqDd5SVjy8SwxI2OcGOkEEHO52wow== X-MS-Exchange-AntiSpam-MessageData: 03znnTiKYEq6Wa0T3/Ry5nHOe4SgiHFX5lOOa6kgRGRNEsdBP9sPSTvmvDqoXCxClHzYIcaTKC9RqyH9hMtbEXyaUIJes6kPH/7dEWOoqwnrqJUUrnBecW5sVGtc6IFc3aAQvHurTUegi8kddmnegPjc/CP1zf/aSJF61yKDBuG7iCEhKkmc79OEpgESH3O77bhAF7GNW63LqXa1TDMRrEYaZSmgbMA7oM9k5Rga6sVHsZKHUMBOVSKRBjudzOSHAiQcbmT3XaROMZAWXqUttGzdyoNWDD01rMUP1me1r9YAbnicKKtSXi8oxj3kN6HF5FAzLFuDEPrzOq+9Inkxfz7SUA2Upj/i6mciZF3BSeY4eZkMfXygcs1SxUqFbdiiJCK034geYb2Zv8Sx8lFKf0yO9dzhPP2LVC5Wr+J4rBQptit4L0LAC/NeArRfUAOL3gk9HqdsITPH6Xg5B5ycP3udzuCSec1KtvLDvhyHI7E= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 78ef0d8d-764e-4c95-2151-08d83241c604 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:28:55.0677 (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: zx7ggSXlTsx+eNATLu2ME1Iku/mjk5hyRh1tQOmTFT9/IUTwhB2SVoIi8hgdlp8h5hYij+G4gpC67PeXiMrkWw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: 0g4WvAzm9JSKs1nNgXGgzWmEx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863737; bh=XQo20hYq01z7FyyIjbLo2/Ab4CvbrRHFwDSh5EwmRRk=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=qZiVd/UMSbdFJZxyTOsFQVrKU41opYlHnWXjwXYkoBtKq5U1tfwKvm1bkIhJayrOmgM KhMWJrelpuNnzPk3PLcuCSAowyTsaVz639uoG3LHQy19ESaHAgJKDwaKZe9XfayF/h9Sw y4nemgyiIyFwNKDzgsEKZW/SQaDYPNGyPro= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a NPF intercept for an NPT entry with a reserved bit set generates a #VC exception. This condition is assumed to be an MMIO access. VMGEXIT must be used to allow the hypervisor to handle this intercept. Add support to construct the required GHCB values to support a NPF NAE event for MMIO. Parse the instruction that generated the #VC exception, setting the required register values in the GHCB and creating the proper SW_EXIT_INFO1, SW_EXITINFO2 and SW_SCRATCH values in the GHCB. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 486 ++++++++++++++++++ 1 file changed, 486 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index dbedd4e9f95d..0e502ac14819 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -183,6 +183,281 @@ GhcbSetRegValid ( Ghcb->SaveArea.ValidBitmap[RegIndex] |=3D (1 << RegBit); } =20 +/** + Return a pointer to the contents of the specified register. + + Based upon the input register, return a pointer to the registers contents + in the x86 processor context. + + @param[in] Regs x64 processor context + @param[in] Register Register to obtain pointer for + + @return Pointer to the contents of the requested register + +**/ +STATIC +UINT64 * +GetRegisterPointer ( + IN EFI_SYSTEM_CONTEXT_X64 *Regs, + IN UINT8 Register + ) +{ + UINT64 *Reg; + + switch (Register) { + case 0: + Reg =3D &Regs->Rax; + break; + case 1: + Reg =3D &Regs->Rcx; + break; + case 2: + Reg =3D &Regs->Rdx; + break; + case 3: + Reg =3D &Regs->Rbx; + break; + case 4: + Reg =3D &Regs->Rsp; + break; + case 5: + Reg =3D &Regs->Rbp; + break; + case 6: + Reg =3D &Regs->Rsi; + break; + case 7: + Reg =3D &Regs->Rdi; + break; + case 8: + Reg =3D &Regs->R8; + break; + case 9: + Reg =3D &Regs->R9; + break; + case 10: + Reg =3D &Regs->R10; + break; + case 11: + Reg =3D &Regs->R11; + break; + case 12: + Reg =3D &Regs->R12; + break; + case 13: + Reg =3D &Regs->R13; + break; + case 14: + Reg =3D &Regs->R14; + break; + case 15: + Reg =3D &Regs->R15; + break; + default: + Reg =3D NULL; + } + ASSERT (Reg !=3D NULL); + + return Reg; +} + +/** + Update the instruction parsing context for displacement bytes. + + @param[in, out] InstructionData Instruction parsing context + @param[in] Size The instruction displacement size + +**/ +STATIC +VOID +UpdateForDisplacement ( + IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData, + IN UINTN Size + ) +{ + InstructionData->DisplacementSize =3D Size; + InstructionData->Immediate +=3D Size; + InstructionData->End +=3D Size; +} + +/** + Determine if an instruction address if RIP relative. + + Examine the instruction parsing context to determine if the address offs= et + is relative to the instruction pointer. + + @param[in] InstructionData Instruction parsing context + + @retval TRUE Instruction addressing is RIP relative + @retval FALSE Instruction addressing is not RIP relative + +**/ +STATIC +BOOLEAN +IsRipRelative ( + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + SEV_ES_INSTRUCTION_OPCODE_EXT *Ext; + + Ext =3D &InstructionData->Ext; + + return ((InstructionData->Mode =3D=3D LongMode64Bit) && + (Ext->ModRm.Mod =3D=3D 0) && + (Ext->ModRm.Rm =3D=3D 5) && + (InstructionData->SibPresent =3D=3D FALSE)); +} + +/** + Return the effective address of a memory operand. + + Examine the instruction parsing context to obtain the effective memory + address of a memory operand. + + @param[in] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @return The memory operand effective address + +**/ +STATIC +UINT64 +GetEffectiveMemoryAddress ( + IN EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + SEV_ES_INSTRUCTION_OPCODE_EXT *Ext; + UINT64 EffectiveAddress; + + Ext =3D &InstructionData->Ext; + EffectiveAddress =3D 0; + + if (IsRipRelative (InstructionData)) { + // + // RIP-relative displacement is a 32-bit signed value + // + INT32 RipRelative; + + RipRelative =3D *(INT32 *) InstructionData->Displacement; + + UpdateForDisplacement (InstructionData, 4); + + // + // Negative displacement is handled by standard UINT64 wrap-around. + // + return Regs->Rip + (UINT64) RipRelative; + } + + switch (Ext->ModRm.Mod) { + case 1: + UpdateForDisplacement (InstructionData, 1); + EffectiveAddress +=3D (UINT64) (*(INT8 *) (InstructionData->Displaceme= nt)); + break; + case 2: + switch (InstructionData->AddrSize) { + case Size16Bits: + UpdateForDisplacement (InstructionData, 2); + EffectiveAddress +=3D (UINT64) (*(INT16 *) (InstructionData->Displac= ement)); + break; + default: + UpdateForDisplacement (InstructionData, 4); + EffectiveAddress +=3D (UINT64) (*(INT32 *) (InstructionData->Displac= ement)); + break; + } + break; + } + + if (InstructionData->SibPresent) { + INT64 Displacement; + + if (Ext->Sib.Index !=3D 4) { + CopyMem ( + &Displacement, + GetRegisterPointer (Regs, Ext->Sib.Index), + sizeof (Displacement) + ); + Displacement *=3D (INT64)(1 << Ext->Sib.Scale); + + // + // Negative displacement is handled by standard UINT64 wrap-around. + // + EffectiveAddress +=3D (UINT64) Displacement; + } + + if ((Ext->Sib.Base !=3D 5) || Ext->ModRm.Mod) { + EffectiveAddress +=3D *GetRegisterPointer (Regs, Ext->Sib.Base); + } else { + UpdateForDisplacement (InstructionData, 4); + EffectiveAddress +=3D (UINT64) (*(INT32 *) (InstructionData->Displac= ement)); + } + } else { + EffectiveAddress +=3D *GetRegisterPointer (Regs, Ext->ModRm.Rm); + } + + return EffectiveAddress; +} + +/** + Decode a ModRM byte. + + Examine the instruction parsing context to decode a ModRM byte and the S= IB + byte, if present. + + @param[in] Regs x64 processor context + @param[in, out] InstructionData Instruction parsing context + +**/ +STATIC +VOID +DecodeModRm ( + IN EFI_SYSTEM_CONTEXT_X64 *Regs, + IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + SEV_ES_INSTRUCTION_OPCODE_EXT *Ext; + INSTRUCTION_REX_PREFIX *RexPrefix; + INSTRUCTION_MODRM *ModRm; + INSTRUCTION_SIB *Sib; + + RexPrefix =3D &InstructionData->RexPrefix; + Ext =3D &InstructionData->Ext; + ModRm =3D &InstructionData->ModRm; + Sib =3D &InstructionData->Sib; + + InstructionData->ModRmPresent =3D TRUE; + ModRm->Uint8 =3D *(InstructionData->End); + + InstructionData->Displacement++; + InstructionData->Immediate++; + InstructionData->End++; + + Ext->ModRm.Mod =3D ModRm->Bits.Mod; + Ext->ModRm.Reg =3D (RexPrefix->Bits.BitR << 3) | ModRm->Bits.Reg; + Ext->ModRm.Rm =3D (RexPrefix->Bits.BitB << 3) | ModRm->Bits.Rm; + + Ext->RegData =3D *GetRegisterPointer (Regs, Ext->ModRm.Reg); + + if (Ext->ModRm.Mod =3D=3D 3) { + Ext->RmData =3D *GetRegisterPointer (Regs, Ext->ModRm.Rm); + } else { + if (ModRm->Bits.Rm =3D=3D 4) { + InstructionData->SibPresent =3D TRUE; + Sib->Uint8 =3D *(InstructionData->End); + + InstructionData->Displacement++; + InstructionData->Immediate++; + InstructionData->End++; + + Ext->Sib.Scale =3D Sib->Bits.Scale; + Ext->Sib.Index =3D (RexPrefix->Bits.BitX << 3) | Sib->Bits.Index; + Ext->Sib.Base =3D (RexPrefix->Bits.BitB << 3) | Sib->Bits.Base; + } + + Ext->RmData =3D GetEffectiveMemoryAddress (Regs, InstructionData); + } +} + /** Decode instruction prefixes. =20 @@ -374,6 +649,213 @@ UnsupportedExit ( return Status; } =20 +/** + Handle an MMIO event. + + Use the VMGEXIT instruction to handle either an MMIO read or an MMIO wri= te. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in, out] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +MmioExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 ExitInfo1, ExitInfo2, Status; + UINTN Bytes; + UINT64 *Register; + UINT8 OpCode, SignByte; + + Bytes =3D 0; + + OpCode =3D *(InstructionData->OpCodes); + if (OpCode =3D=3D TWO_BYTE_OPCODE_ESCAPE) { + OpCode =3D *(InstructionData->OpCodes + 1); + } + + switch (OpCode) { + // + // MMIO write (MOV reg/memX, regX) + // + case 0x88: + Bytes =3D 1; + // + // fall through + // + case 0x89: + DecodeModRm (Regs, InstructionData); + Bytes =3D ((Bytes !=3D 0) ? Bytes : + (InstructionData->DataSize =3D=3D Size16Bits) ? 2 : + (InstructionData->DataSize =3D=3D Size32Bits) ? 4 : + (InstructionData->DataSize =3D=3D Size64Bits) ? 8 : + 0); + + if (InstructionData->Ext.ModRm.Mod =3D=3D 3) { + // + // NPF on two register operands??? + // + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + + ExitInfo1 =3D InstructionData->Ext.RmData; + ExitInfo2 =3D Bytes; + CopyMem (Ghcb->SharedBuffer, &InstructionData->Ext.RegData, Bytes); + + Ghcb->SaveArea.SwScratch =3D (UINT64) Ghcb->SharedBuffer; + Status =3D VmgExit (Ghcb, SVM_EXIT_MMIO_WRITE, ExitInfo1, ExitInfo2); + if (Status !=3D 0) { + return Status; + } + break; + + // + // MMIO write (MOV reg/memX, immX) + // + case 0xC6: + Bytes =3D 1; + // + // fall through + // + case 0xC7: + DecodeModRm (Regs, InstructionData); + Bytes =3D ((Bytes !=3D 0) ? Bytes : + (InstructionData->DataSize =3D=3D Size16Bits) ? 2 : + (InstructionData->DataSize =3D=3D Size32Bits) ? 4 : + 0); + + InstructionData->ImmediateSize =3D Bytes; + InstructionData->End +=3D Bytes; + + ExitInfo1 =3D InstructionData->Ext.RmData; + ExitInfo2 =3D Bytes; + CopyMem (Ghcb->SharedBuffer, InstructionData->Immediate, Bytes); + + Ghcb->SaveArea.SwScratch =3D (UINT64) Ghcb->SharedBuffer; + Status =3D VmgExit (Ghcb, SVM_EXIT_MMIO_WRITE, ExitInfo1, ExitInfo2); + if (Status !=3D 0) { + return Status; + } + break; + + // + // MMIO read (MOV regX, reg/memX) + // + case 0x8A: + Bytes =3D 1; + // + // fall through + // + case 0x8B: + DecodeModRm (Regs, InstructionData); + Bytes =3D ((Bytes !=3D 0) ? Bytes : + (InstructionData->DataSize =3D=3D Size16Bits) ? 2 : + (InstructionData->DataSize =3D=3D Size32Bits) ? 4 : + (InstructionData->DataSize =3D=3D Size64Bits) ? 8 : + 0); + if (InstructionData->Ext.ModRm.Mod =3D=3D 3) { + // + // NPF on two register operands??? + // + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + + ExitInfo1 =3D InstructionData->Ext.RmData; + ExitInfo2 =3D Bytes; + + Ghcb->SaveArea.SwScratch =3D (UINT64) Ghcb->SharedBuffer; + Status =3D VmgExit (Ghcb, SVM_EXIT_MMIO_READ, ExitInfo1, ExitInfo2); + if (Status !=3D 0) { + return Status; + } + + Register =3D GetRegisterPointer (Regs, InstructionData->Ext.ModRm.Reg); + if (Bytes =3D=3D 4) { + // + // Zero-extend for 32-bit operation + // + *Register =3D 0; + } + CopyMem (Register, Ghcb->SharedBuffer, Bytes); + break; + + // + // MMIO read w/ zero-extension ((MOVZX regX, reg/memX) + // + case 0xB6: + Bytes =3D 1; + // + // fall through + // + case 0xB7: + Bytes =3D (Bytes !=3D 0) ? Bytes : 2; + + ExitInfo1 =3D InstructionData->Ext.RmData; + ExitInfo2 =3D Bytes; + + Ghcb->SaveArea.SwScratch =3D (UINT64) Ghcb->SharedBuffer; + Status =3D VmgExit (Ghcb, SVM_EXIT_MMIO_READ, ExitInfo1, ExitInfo2); + if (Status !=3D 0) { + return Status; + } + + Register =3D GetRegisterPointer (Regs, InstructionData->Ext.ModRm.Reg); + SetMem (Register, InstructionData->DataSize, 0); + CopyMem (Register, Ghcb->SharedBuffer, Bytes); + break; + + // + // MMIO read w/ sign-extension (MOVSX regX, reg/memX) + // + case 0xBE: + Bytes =3D 1; + // + // fall through + // + case 0xBF: + Bytes =3D (Bytes !=3D 0) ? Bytes : 2; + + ExitInfo1 =3D InstructionData->Ext.RmData; + ExitInfo2 =3D Bytes; + + Ghcb->SaveArea.SwScratch =3D (UINT64) Ghcb->SharedBuffer; + Status =3D VmgExit (Ghcb, SVM_EXIT_MMIO_READ, ExitInfo1, ExitInfo2); + if (Status !=3D 0) { + return Status; + } + + if (Bytes =3D=3D 1) { + UINT8 *Data =3D (UINT8 *) Ghcb->SharedBuffer; + + SignByte =3D ((*Data & BIT7) !=3D 0) ? 0xFF : 0x00; + } else { + UINT16 *Data =3D (UINT16 *) Ghcb->SharedBuffer; + + SignByte =3D ((*Data & BIT15) !=3D 0) ? 0xFF : 0x00; + } + + Register =3D GetRegisterPointer (Regs, InstructionData->Ext.ModRm.Reg); + SetMem (Register, InstructionData->DataSize, SignByte); + CopyMem (Register, Ghcb->SharedBuffer, Bytes); + break; + + default: + Status =3D GP_EXCEPTION; + ASSERT (FALSE); + } + + return Status; +} + /** Handle an MSR event. =20 @@ -770,6 +1252,10 @@ VmgExitHandleVc ( NaeExit =3D MsrExit; break; =20 + case SVM_EXIT_NPF: + NaeExit =3D MmioExit; + break; + default: NaeExit =3D UnsupportedExit; } --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63321): https://edk2.groups.io/g/devel/message/63321 Mute This Topic: https://groups.io/mt/75824986/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 Fri Apr 26 07:16:41 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+63322+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+63322+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 1595863746971777.8964113926052; Mon, 27 Jul 2020 08:29:06 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id U2RrYY1788612xw0z8dbDpAC; Mon, 27 Jul 2020 08:29:06 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.45]) by mx.groups.io with SMTP id smtpd.web11.58122.1595863745938667268 for ; Mon, 27 Jul 2020 08:29:06 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WGAcU2XM5hyhD7dfT46zuOEsDQc9wdE8vmHVSL/ef4HFnFwyvOgOvw5PhfwIQ1/IMUzU9kMKDxI+SxElGgifB2NMGxnB65IMR6b24HgYVfknHZfEPYIOoOKIyXKZsMylGF+Jj+KIIq02zjLeENBjztD+R2JGbBMSrIvVm6xFqr23OD5D9utpSnLAo5P6KItzO9kMXSL2C0m9DkDA5Vueg4KcQr/HZpli6+AKSu5P3/JoJAnH/iyNubuN+rKVTOTLRBl6Ft+RSkh6AiOZxzfgALe6uA+iKdy+INQ+z1aZBRuzva0kx5jUXqLQyJWg4kPBXsohzZ4oXq9bYugpCSWYlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=crbmyZ65afRC34Vt1/yjGXXSEbQgatvY+leMn0es1AI=; b=gvaA6Tkaocl6mfvYY90aY04HBnYYawb3vYEx7VzXklK9zSMamMMcR/zSa6Wka8B7xm8KwHET9ZMUN1XoDPsY2tP2iRrFtFNnDi+cxzgG/TGT5SaQ2OAZML4vDnJjEMjY6agu+SdXUsn2pRdYbkerNjhQUU3m6c694bE2ImkVjquYBO6BHJ/9DxTmEktRJegvqJrBdVlfuYP/a9Jl99QPXV1CQu6bktHzVu/G8GWr6WtemhnE44XhV7JvIB0ii29K8FpnRPEwN8lYarIkCZ4BNxAjn/A+VndQ9R4JPP4DJFzUgEyhaC2FB3EmtPOiYrFc+h+A3DbpQROweSF3Acm4ow== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:29:02 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:29:02 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 18/46] OvmfPkg/VmgExitLib: Add support for WBINVD NAE events Date: Mon, 27 Jul 2020 10:25:59 -0500 Message-ID: <16b66c1895c3dc572afe86656e6bcf866ddd8b8f.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR13CA0048.namprd13.prod.outlook.com (2603:10b6:3:7b::34) 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 DM5PR13CA0048.namprd13.prod.outlook.com (2603:10b6:3:7b::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.9 via Frontend Transport; Mon, 27 Jul 2020 15:29: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: 1f627b86-a317-4196-19e9-08d83241ca98 X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: 1UIfRt36NHaaRRPxuEg8WixWdOmm6n9clBigQ9AxLYLVYhNyOZBRuA5nwIcXWMeyNYTClRyhU+38mlrYjVlDRhF5O0zZrn0EDq0CKsNK0ub8pIDNoZj51+YyZi+3gPkdK7Hs9yZsm7hs+Qit9LZkVrRmAz7xviBETY/DhUgn/A64ABh93mtk+ME+q5OlsWc7phfCR3Ywra4kygx58abCjU4JTWFMrFT+63UJ0Bcst3JEI2zz7zNvKK+80PzLhyYXFxSdYMEZdPYmn31sVpbr+7SQW/BO4gVPie3TA8MVG/My9dsEfP4GGo5VO6fIfcTC8DnZabRmdGipDDeDL973SKzFpvZLXXyEUDIMNWJA1jWll0ha/k0IJHSTlhLppAxrbwfmRKHfwzbeUTnOjZhViat0SCZmbs+1x//5GDYqtmXI77I5IPejGm2+fLDztM9hYM+2+MK7/I6WWU0oQRe4/g== X-MS-Exchange-AntiSpam-MessageData: qw+XSvVZ0jwMUMmGxwl4qrfy1QyqMBlAd3pUMOIf2AoMGl2DTiDJWejh33EoFFFA6BXPJw/568AG0lO4Wb3R17d7T5zecvivDr4mg0J6PMCLau/S+EcItb0/LTcbHahlKgfKzV8Fls7MbVyAHktwKvQuY+Zl5yP3P9VOl40Jj3wF1F+P4A19Bx1xMpcRsNmF5zGEbUxc8fXjDraFOYJLIGMSYjaTDZYEKxxZrX4hiLi2Dxb1ykjd4wMMtq++VCVRxbMMNcmTQIDWfF7r7n2DJWbOxP7rc2EtaF2wz6ZtvHpp3mTRB0Tf663ZCupveY0TizNjHHlu1L6gUuHgWv20FEUKG3A3icpkGm3jxzD6OG/xM2S1gGwWKYzpeLnFp/1hCKdd7u/HXJvQs46n4eMMQp1gA0hM/5dPdK+eHsvYeqIb7EgO75iV1XZgxMmL8+GQMAZSWDXgyLECv3g0twDbo4M8m/qoOrN8jSvK3LbGqSQ= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1f627b86-a317-4196-19e9-08d83241ca98 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:29:02.7663 (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: zL8SWRrSek97ZTY+5Q8HsJIrwcZxbqqnzfokLWO4A1TR2K4BjvD+V38iC/dj3F6pGpL560yxc/XokgsCIpbTgA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: WyZ1Gbrbhu1lPL9gUDhlKccVx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863746; bh=HOVi1xejUNHU+BIYqM117BTi9QzqDOhG6Ne9ZLbmZXA=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=TtmdTc2BzXeviqtL9sQTmu0+sZN8B1d+YIpSEE3Sr8qwsa4dfKHJcCH3gKuJxz51Ce0 mQJe966c42+nBQ2uFRPi0J4/UFFNqg7TJW3siLoZ/ykddZl2msx92gxRXzYOMM1R1t08n PnG86REKiNoKZaF9p8Gns/OEVKfsg9jNBQs= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a WBINVD intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index 0e502ac14819..bf07f960e380 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -856,6 +856,31 @@ MmioExit ( return Status; } =20 +/** + Handle a WBINVD event. + + Use the VMGEXIT instruction to handle a WBINVD event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +WbinvdExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + return VmgExit (Ghcb, SVM_EXIT_WBINVD, 0, 0); +} + /** Handle an MSR event. =20 @@ -1252,6 +1277,10 @@ VmgExitHandleVc ( NaeExit =3D MsrExit; break; =20 + case SVM_EXIT_WBINVD: + NaeExit =3D WbinvdExit; + break; + case SVM_EXIT_NPF: NaeExit =3D MmioExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63322): https://edk2.groups.io/g/devel/message/63322 Mute This Topic: https://groups.io/mt/75824992/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 Fri Apr 26 07:16:41 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+63323+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+63323+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 1595863753472901.0755709526454; Mon, 27 Jul 2020 08:29:13 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id BiAYYY1788612xNKBIaPlqX5; Mon, 27 Jul 2020 08:29:13 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.52]) by mx.groups.io with SMTP id smtpd.web10.58347.1595863752176438312 for ; Mon, 27 Jul 2020 08:29:12 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PKnqXywB4fe72AaOU6qc1oZE0aRwofnyXhownZ7jb20bC2qCdYiTcvmG0HvI57bpramSMAr7jX2JLNnVbRflivoTfavqVJourIOuxatMJG5O4Lk3U24drnpG+2oGG7e6n402117bWOUVt74/ln5LwdU53PxY5T6WEYwUMeXOlj/BqDMQfMILHIaxgpHYyeSQnQf70BiedTeVnM9HJcciZ8nymZBEDIzbSoQBntncYlqXabPf0YVJ4ueLU0hFVqnKAuQvK3whih8NzmD6x7IWhdXwJn0HiC1IyauEHUVe0i3dI2+MZCPlFhORDX3oq1OPR116GOnc4krcQihtIN5dBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=d00K2p9wGq3eOi/6hoKeg0U80JcDhc9VJVDfMfmKMog=; b=MPSv4YB/7jHxyvt//lDjjnoB054PPDUxpOML6gwyAvQLC/tdzkR6tkuvwiNs8BN/0g2T9+kOSbfkn3Qmchz6x4R1AFpdVp0UgQ1RGkkedPeFbvRsi5tKcFm2FG7CKtyNmW6/5JXhHqOpLD65gIW3BDu+ufvhZFEdxz/WwXRpcCYfnTTK2nR7Vg/JA5EHifejj6eQk6m7DDW/DiHT7cX4WKMpzxOHv6k5OVcyYrXwG9L01k/AiZi3GFPrXWzq8J89e27hQLB7jVzzeMuk/o/WF+/F0I1BGTJ2XaxuPrNHmJxXtlBJJ1iV4mHCMpGQPPGf0goSFQv14BL1KYUfKmZxtA== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:29:10 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:29:10 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 19/46] OvmfPkg/VmgExitLib: Add support for RDTSC NAE events Date: Mon, 27 Jul 2020 10:26:00 -0500 Message-ID: <81cfcf73a02e055f21744a2af8af134468b9dd30.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM3PR03CA0008.namprd03.prod.outlook.com (2603:10b6:0:50::18) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM3PR03CA0008.namprd03.prod.outlook.com (2603:10b6:0:50::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.22 via Frontend Transport; Mon, 27 Jul 2020 15:29:10 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 0196cf59-92ea-415d-9c04-08d83241cf4f X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: 9XX2klVx+3q0T8Mv/LBlZbGpxmasMNWdO4MkRZVAZi5Mgvugw9xnUBkiZragD1+Ghrq5wvCeUomAXqaexU3Q3VYd2rLKVzJe82etlUE50K3YmVJR/xDVGsKytz9icdIWlr47MDNd9VnND/5GJG9VHSMOjpohsmCkfC0/9KQxeiAsxw077IsiUMBFwjAMIUeP/fr/NB+XgrBnxfHn5D2+rg43N41iBN5AAhmpd0TceS2AwqHhotTAqMfXGuqXxzn90wisDeUXb3FSseExT9J+dfzHI6sCJ4lS89nfG8CXVT/I7CpVXVmLtYdtA9pFb5CyyOfCtBAgk564lAxnhOtaN0vwWj3R6wcppwG2LAYiGqyKPtlMtPxBFA3DEmjTU/pduUtLcIgNazWsQUaI6xEp5/oQ1iUItletEEBEqHYXGbikT16GvryeiL07j71vHJQF1SyfSLaMGoKh62BC1wuRgQ== X-MS-Exchange-AntiSpam-MessageData: F92PAWMGY9G8UcHQdyl7hnloMIe9da/Ya69l8uj35AXBvNcFG47zegkd3nL00ZNxll7hxe3gNNT5TWzYDCZvbI7D5BP8x1I6kmqYlhSGey0kBdX2RkKwFyg03oJkCDcRncTfa5hIJr3i+5vviWcsFuYbdK7ddm02jM2HK0SjsWvhz8Bb91+6jWUlVg6HYg892eoxRPamL6kebBcrznyCMw+5O8hKBggVaerwTZcAm8UokOMIUyl+QJudXxgCWXypMlFuZhryDEyDTBBQhbu2EVYT51FJqi4wNiRLfADbivDgArGKlqpgoklp5UmsE6HvipjpO8BvinO3uZ84K1dIdFoecGuuw+Zh3OMXXd7BSxjJt3NRQcpaQxyB5mwcGOiZUB/OsbFWi4niay8BRVVBVFoVuc+tutsEhgCf/AA9gbdf4q1aJap4Rg8JO8jUA2ZentZ2+bsQOc3xLcxKsuKWC3hk9dnZZfr334zKMNirRA4= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0196cf59-92ea-415d-9c04-08d83241cf4f X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:29:10.6568 (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: pIS/bismkZfu8G01e+ScD9Muii2NjbipxPPzRg/VuUTYVbT4cKSqen9UMAoeR5yn3yUpPeqbm5mVVyQa0/PnpQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: M45gc0pBknyq9CXN6WRhkwxbx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863753; bh=VlQPnBxLkZm0dWhFPbPsp8iuMX6H+DIoy1nnSFzCL4M=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=mEu/TWec+n1m8Mb6U3pi3o8WuaEASrzYm1F+2DOt/oNutjk+ihL10k8rYiha4okoYlW dI+mD8+6NSaoIp68TLskaumLgsTHWMtoR6Fc2J9cZYzhdo4JOQbi6rGcH4BxhGLp7f6VC 9pFkJaI0l3YLKnHgm3ciofL1UWrl4ru79rE= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a RDTSC intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index bf07f960e380..65af57046063 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -1221,6 +1221,45 @@ CpuidExit ( return 0; } =20 +/** + Handle a RDTSC event. + + Use the VMGEXIT instruction to handle a RDTSC event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +RdtscExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + Status =3D VmgExit (Ghcb, SVM_EXIT_RDTSC, 0, 0); + if (Status !=3D 0) { + return Status; + } + + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; + Regs->Rdx =3D Ghcb->SaveArea.Rdx; + + return 0; +} + /** Handle a #VC exception. =20 @@ -1265,6 +1304,10 @@ VmgExitHandleVc ( =20 ExitCode =3D Regs->ExceptionData; switch (ExitCode) { + case SVM_EXIT_RDTSC: + NaeExit =3D RdtscExit; + break; + case SVM_EXIT_CPUID: NaeExit =3D CpuidExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63323): https://edk2.groups.io/g/devel/message/63323 Mute This Topic: https://groups.io/mt/75824993/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 Fri Apr 26 07:16:41 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+63324+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+63324+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 1595863760672234.1907179928687; Mon, 27 Jul 2020 08:29:20 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id OkpgYY1788612xjhyZlkTRNV; Mon, 27 Jul 2020 08:29:20 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.60]) by mx.groups.io with SMTP id smtpd.web10.58351.1595863759715864288 for ; Mon, 27 Jul 2020 08:29:19 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D8tWU5OeWzvHoySFeZPMizmPi8vxUl9R8AuE0l2NxeocoXgOe5so9HxjXF4p7wGp0P03th1EY/nBZS789YOcfcGqx36qss3Zj4nACO+UQf+948rOreUTdCmJSwTp240mb1lmt02M138ePnG1DDYFGwN4ppw3Nr4N4bZMpejN+kIin6AmTIwN2H6U3APj4jWy1m6HfsMlPY6z9FIhT11DGvD8+eWFGBA6LwkTMD9WGtY+3P27tIHUn/lgq2j2bbI5f0fwfiqmOvj0zqUuBKIPUWHofic9WJ1sDOtFMnOT6uCgmNJkhkA36El0W/IylVhQVz9I+CCR4zirFn4V5ay1Nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4O6+S0hN1CMnpBWLQIazWEUnN+r5+tUBAtS8g+NsqAw=; b=FMlZ9tRZDTCBpYA5Jor+nAhYkmSbmabTGD6T6gfkJ85cvPQwwPOqsrUm1XM5W2V84yT7PZPMuh16Z6TDMTLbIjTAc87jV0SBIYkHKeycC9cnQVsLHjVvtMAkRJq3ERI5XglmeflE8NeVKSsjxu42sQ/R7csFaEB7y+XkKV5Eh/g/eL8A5IAiHcmeAJAMZdokB8dOf0lNQ5xYvBk5r5Wr4sR525NgRf5eKEtEKQPK7uexxiE6C3kWdCm9ZFq7/y74QXcc5701qRxpjthjixQC2nAzR/trR4RiZlKjdbg76hrrHBjFlxYWMg56GIpAGz7R/L3a8d5wYHa0Cii10EfXgw== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:29:18 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:29:18 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 20/46] OvmfPkg/VmgExitLib: Add support for RDPMC NAE events Date: Mon, 27 Jul 2020 10:26:01 -0500 Message-ID: <04cde18ab64041e4da9099c975c09ee1b87f7908.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR13CA0002.namprd13.prod.outlook.com (2603:10b6:5:bc::15) 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 DM6PR13CA0002.namprd13.prod.outlook.com (2603:10b6:5:bc::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.9 via Frontend Transport; Mon, 27 Jul 2020 15:29:17 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: a69048e7-bc02-416c-04fa-08d83241d3ef X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: qtr5JsU9+epAK0o5svYmBBR0qPe41saHbFYXVU6sWbXHxzEMm8/tXS4t0R+VI6P+CiM1VZEc8xZjzMOtAD8CVAA6EUIuEqBIL/mdt/IocJ2mp/02GOC1ws/G6G59qnNhkhleHqHdGve/o5Tt5cWQ6DQeV9g8ngc0Os6k1HVPTeJOUliUcB4HYKkmVfiiRSJAXdO07IJOqAOyv2cfJiJe1pLwnSqBsIXXt4o75Ymw2gdQXY7rbxKMcpg8TAGc2m5tzzTDFDlqtafQYz7QGM5FZViN4rxTUhXrU91FVLx42kkE2fGYZcv9OkMd2UBIoZo7xSjN5XUcCZ4wHsvuPUCy9POas4K/fs1F6TXjhFLLtZJCD1vwjdbYVHCF0+rzKXQSrN62Ktk7G0zkhceQTaLXmTm/o/Qz8hoE+x/GFWgT9yOhdJWsn/MAdU0mNzxUbGlGgJ+NSsL+Fw9fgb9TAq1zCw== X-MS-Exchange-AntiSpam-MessageData: 3UKK1xW2U0LeemejFwMI/rFuRANZTWW+mbt4a7iHZTw8+dKv0eyo5yTuQvfF1lU4Y4pWYnhKtFaHZpwAiXkMpvufuBqFJvKwi8i0CvGc2pXjnkdQTRz/RZ8337WJCmqxh9EFPFxOWMNRZWNPhIAz9ZcVV/baQducsOCk4LrwCORK42SfKZOCw9cmZx7yWtWBHxu7HhQDo9pmrOngTMvoH+MheEy6anlTFkCli5VoMCzUOfW9nE0paCpw3BkD/8nukCZx7AMdbmLTrwmhEa9XUEPeBah7vlmQrg4JN+W9JNZDkhR1D3yQPh9vK0mYOkSKzm1yDS9yXlh4o7B0Pl7lC08H1Jseup5NkOGBL2/QVhsru4y0+6+aDJ6gyfEAsqErbiKp+Ltn9eNDOCQP9yWMLiNU3UBa6pqogJZjC7/DkyUAXnsMI/1UnBkI76Gh9avCW0Uy2Pc7TnaxwtVxAOZN0XwC7gWWqkb4Nr9Fks+6TN8= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a69048e7-bc02-416c-04fa-08d83241d3ef X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:29:18.4214 (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: WfT9LqjsYKfLu1Ul/RQ+vDdnFLhM6gGYSl7eXTK5BfWx/FUkBIc+CQfMlWt+uhcG7+Rir/XBxK6ctZ0/z5HE4A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: EqncCNtHvl6U0xVHjP56aO98x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863760; bh=JJzdB+DTa0l40zqWfUfXfhBPD4La4UcwS8V05BIdYsg=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=cSjKa13trDo+a5TwT7M+taIxJ1D27DojYZ6th5ZjKwQ4tsUsz3VBsH1bscy6G0NtmzM brsr4GHxkhBBkpAWozkZXNvO21tHPHJR2kitrIMcsbeQGCZLj9ySar5aRfn7xOhNy1w2e JjImjafd1SMaiMmqR/dBUkkATiPIKS05tvo= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a RDPMC intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index 65af57046063..b19bd3ee8906 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -1221,6 +1221,48 @@ CpuidExit ( return 0; } =20 +/** + Handle a RDPMC event. + + Use the VMGEXIT instruction to handle a RDPMC event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +RdpmcExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + Ghcb->SaveArea.Rcx =3D Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + + Status =3D VmgExit (Ghcb, SVM_EXIT_RDPMC, 0, 0); + if (Status !=3D 0) { + return Status; + } + + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; + Regs->Rdx =3D Ghcb->SaveArea.Rdx; + + return 0; +} + /** Handle a RDTSC event. =20 @@ -1308,6 +1350,10 @@ VmgExitHandleVc ( NaeExit =3D RdtscExit; break; =20 + case SVM_EXIT_RDPMC: + NaeExit =3D RdpmcExit; + break; + case SVM_EXIT_CPUID: NaeExit =3D CpuidExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63324): https://edk2.groups.io/g/devel/message/63324 Mute This Topic: https://groups.io/mt/75824998/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 Fri Apr 26 07:16:41 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+63325+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+63325+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 1595863768917639.1676147220313; Mon, 27 Jul 2020 08:29:28 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id urL1YY1788612xW3H4mAo7Cl; Mon, 27 Jul 2020 08:29:28 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.64]) by mx.groups.io with SMTP id smtpd.web11.58128.1595863768047564703 for ; Mon, 27 Jul 2020 08:29:28 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Is1wF0zqezEN9q8NCv2CW/CYTiTiuENY/0pA7ou6OewDz2mBjzZTAZr/PsIgJYlSp+xlAoUgaexCN/3IMaBLSBe2XKJn8PCQmEPQsYDDkznNfkAJ2CmH2OsixLjl1hfBHSTHDekoCY9GyXlkF+/N4waf8nNxIQtJ0e+jd0BGH3H3ZtAcO8nmvY0uhf1E3fYbMnfMNLRtySBuEyNElssAvsHChB+JtF9QZiTnozEDhwKrJtlPT9vPszYESrPOmpVJD/amClLh+4kZ7TUaIuS4tRcheyVWyp6EXPyulPktKwMdvEkyoyR3/I38zNqN6Fd1NpkZ9DOQVcVY0oaND/2v2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VWf8IlBLc5H2/zm6u8ihdDB1OPHPbvu83zMDyNap3VM=; b=dIKjIl8PF91/UZ/opJfbJm5XOabI1h5zEIkZFy4vJzCtWIVUlvgJQYw7HgEcdQtkgzPXtM+DrGRnwTvv/01kz82thK+/Xp8ZEc7XP8Q7QagJxnBfDp9RuIxFeNQNH0EGGslNST4CgGchpfEV5tJvOaAsy8t5QSsNzTcVphiYbkIsafP5zPTHxbg6cFlg2WpOoV5sbMCwg7U4qTSJj/pnggd+h0FhPh86bFD+E9Vg7g3i6uiWeZOBw0t7WDJ2i04IcJKE6iMEnDYU3w4s5WPAT8VmtZ0mD0VJlINJ9f+qLBDrGi+LnUDiLnr+DPkUyLcv2YF8TqhxqY8RAr3fKHyuqw== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:29:26 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:29:26 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 21/46] OvmfPkg/VmgExitLib: Add support for INVD NAE events Date: Mon, 27 Jul 2020 10:26:02 -0500 Message-ID: <0848e8b3c5fb6c311e22d1a8fbb109f2eab586fa.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR21CA0042.namprd21.prod.outlook.com (2603:10b6:3:ed::28) 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 DM5PR21CA0042.namprd21.prod.outlook.com (2603:10b6:3:ed::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.1 via Frontend Transport; Mon, 27 Jul 2020 15:29:25 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 346f3db6-185a-4b0d-6e98-08d83241d87c X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: 9QYZP3qhv71E3HhzCxH229uyQTZmGnosKuH4JqiN8gSGPMDZbLqoa7AlJ5iUpQpHHz74SyYj7PsGMzRT46+FwZXCVpjLXHyZLtMgCQFBwgTPhmbe+1WN9PzqPtbCQdhu9LvdQXntNYeciHMP8csjUgyB4TXByfelj4ulIAqtGaHju1r4u5DgpGz5jNa5e6MPN7FOMBd0smsDqLWKmVlvKqAx/P+WbWlFAfaEBVczHGzFxGQye1udyR+WGUrRJAce20CB8kVseOIVX10s+YR3zrnsdrAGZx8JhA7h10UxuCw/9gldDtCREhVMLu+pNP91I4NWjscVqYakIyCqUUa+Jp72rCCM0KlZcSndIUZmka+cZAF8GDQD0zmC/14d+8+ojVC+F+0qLIqeHH+vZQalCOp+RIrrNmO9tD0dujXOgMdPrOT8BET2FuP7fczsNwQXMZINNyjzgY69LDDtsPx+Hw== X-MS-Exchange-AntiSpam-MessageData: yvlM/OOPt4yUarX3UqOddBllnMYfIB9ldBOvIFE5ZRY6o0zpYhLunl+9XwrLXTPKrJhBZ6KFlpZfWI+ZtCseFXQOwNa/1RGg5xdCmuxJD5k4U1sPcj5vXl/d79Jsz/5hmwVWABc/w3j/0SxPVSE46ACswKl/ojsoRfug0C7+RnpXkGVDP7UUE9JtTnDVVPdOhDspbizo4J7OyOe5Dt0vGl8mVuNyxNHtoS8GG+lMAPHzNQ9eHpe0uT24VTlGgoZqG5Xgt5HjG+xlduG4u5kWWrAlPhHafXJSY4dBQDcRW1eq2C5nhK+ZZJYQzOA7UsWVi/T6iffDe0oE2hYmrl1VC2vZ14dmXgpnTg/6D0LmhxfHJZHFW7LI5DYU8rkTQJy8976+WgAOMSHVjwCnjL+vxXsdlk/b8iQF/g52Zw9Sax7NUr5E2Vtaxfx6GJRyXPPkapelKikkmxRlMVbgslRqCm4Yc+5KEXVl2rXTDj+/2to= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 346f3db6-185a-4b0d-6e98-08d83241d87c X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:29:26.0621 (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: evDCmY3rjp7ZUWbiz35dCV757wsCSO5ncZlj+NGMdlJj+cMtnwSPBetbt+mfAvGEyeQn+GrMbU7cHz4mWyZqFg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: mqhCsbZYWk1GRPShErtt7yF5x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863768; bh=JedeJe6YY8wnC+7qWNuOPmwb6CECqmkFqJ8YyiyiDcM=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=LfXuugke7OmK7ODNsqyPOrp7sl+X/D1U+H8TAx2rrm8wjPsYE81ZvXsQQTLFhPqa9U2 SjD3dorQ8faxQZamaAGh+VLO32pb2sGD8SR51GRiuD2lG+vvjVhfLn6xDP1wV4nBC3mLs DwO5Qw1Gy4eR1EmCpUwbFkrHwgnZiSBVX4s= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a INVD intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index b19bd3ee8906..af5264095b98 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -1166,6 +1166,31 @@ IoioExit ( return 0; } =20 +/** + Handle a INVD event. + + Use the VMGEXIT instruction to handle a INVD event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +InvdExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + return VmgExit (Ghcb, SVM_EXIT_INVD, 0, 0); +} + /** Handle a CPUID event. =20 @@ -1358,6 +1383,10 @@ VmgExitHandleVc ( NaeExit =3D CpuidExit; break; =20 + case SVM_EXIT_INVD: + NaeExit =3D InvdExit; + break; + case SVM_EXIT_IOIO_PROT: NaeExit =3D IoioExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63325): https://edk2.groups.io/g/devel/message/63325 Mute This Topic: https://groups.io/mt/75825009/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 Fri Apr 26 07:16:41 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+63326+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+63326+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 1595863777351561.1089316209359; Mon, 27 Jul 2020 08:29:37 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 1eGCYY1788612xN6HLq3nD2t; Mon, 27 Jul 2020 08:29:36 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.54]) by mx.groups.io with SMTP id smtpd.web12.58116.1595863775544287367 for ; Mon, 27 Jul 2020 08:29:35 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MgLYZg7F6RayYFH5+p9cHgfLawPZKZ91+mOpYMqMSQJ2XqNXrbLTcTeF3RZvZP91GNmSY+r7zeKBIHKrHmKYhI4m06PFm1N78cDPnSvPbAMd1dEVT/Regsyyf9IjwyBWr3KgSwzJOUpwBkq6U7rcVJAS1iW39TK7Stu3gYj4Bo6xFjRpnkQKFfUAp94wCgtZn3n7n4Ue+XabtrWpjg+jda2PL2fKX7qy9fjngX0ZrgEOVgPdAjRF14FAGjpDO8TZpvwl7siA9c2CSv/ZOSsyFzlLwKjb/CKzsLtBWG6qt+cMbj4C14UAz3q8Tr4hogH2NxJRim87YKoA4u3XBzL4zQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8NTCnoZUa8l7fJRJjHTmN6rj4HEhSC81uhz1zBZyzhs=; b=DAeRzAAioChwu/rAZDcJsbqr/mwEKMBNcnnFbd15dLpT0jj8cvAClmUdE/zE1NdI39m3MeXphO+NbBSS40FIA3wqtwE03TNL8qnkcw93Vyh+T3bxG2Vb+o0Uq/iQbsus9NxXCmYZtpNBBaLRVIUF38DR7ZLjoC9gO49xqwmV1HYyzD8NOp1WWdZ5JhhdQT9xmPgTAQ7Q0/Qo4ROw29EPnrVp/p1vTDsIVBujl+lcwnQPl9dwepul52QcNxFwyMunOKMJJ9IbzvXY7LnET/KK1Oy6dgiE9Q9nfvo8rL9CRySxL4gKWNHzZqrSLyefPgP4KQaNS90eZglQVEll6AhyWQ== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:29:33 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:29:33 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 22/46] OvmfPkg/VmgExitLib: Add support for VMMCALL NAE events Date: Mon, 27 Jul 2020 10:26:03 -0500 Message-ID: <36a4717619ce8a9393c192b2980288eff555d24c.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR17CA0067.namprd17.prod.outlook.com (2603:10b6:3:13f::29) 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 DM5PR17CA0067.namprd17.prod.outlook.com (2603:10b6:3:13f::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.22 via Frontend Transport; Mon, 27 Jul 2020 15:29: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: bba5f657-b4cc-4181-103a-08d83241dd14 X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: 9urbPbHZqaSISmxmlNBs/BNKoQroncobH235eDB/Qtk5UpN4DQCBNSvtfHd9pZRRzW/8dZiZEUE9J8P2SIlzBTlvaLr1SgnieUsbPOOF/4sBiBVuclQ7hd/vtFkp13XxgwC61pQ9Mk02SfhE4BpBy1RhR8/jYkoFDR/jLHU7ND74vvkYlDyVS8hhlLXV7VxHi75T4C0C4X543lHqkuJxXzD5V0VfLF/WQRpOgBVyvCyNRu0J+IRC3fbLQ8nBBs3a9SH2ZSscSzkRnloXsmQsUrzrER/QQiu6t9bzf+5LK+O8ZNpmQQdTEuW1M56L5eVcGnT2YkS0x7KSlIrjiuWvPXXK/G8v5W4Ep3vRTfUM++s4u5iNaFphlwm/QjF3aribOpy3oJ9gYZ5nU+6fos+39ryjdXmIrhc0hd+83c46+X5KOix4J95s7NxPq/Mb2iuEE1UCSc55tiEmAtHGB1i/xA== X-MS-Exchange-AntiSpam-MessageData: YJu/8QKuSNwvz4bUhfZ+I8LCWT0Fh+LDeKdb9hV2/jVqqiR+jeXDkKu2yJhaMXVfiXOTvETTRi87cJtZIov9XcdY3xnBDzTT1s3fZ0HHhRBHpQ/Jt/5yI8WVz9lCWKvkDD5/4QG3dBijpW/pTrp5k1fiJVA459JdLUL14BjPPmVNg6Vh09D4SK5YuELNedJBiG/K1/ZmakmBLrW7/idWxThYIS9UNAlNWe0e50m1s5cVKQPtO2Y1ih0/veG2m2vs4YfczGMif7MCdKU/4WK+xOPGSRmYO1hw8C/fRqUJIa1HKNiGXY7OIBNmfFZg11QXnJzdM6ehTKeYBXaXNZmAcPH//Zm0+eaHn65TPtkV8mgNE5vT9/y6Pi202fv2DykQTFKWxisPqNDrYpwzU8ttBdn3rCopt62XKspmPEy2oOpoOZa1QS6vt4Ays8dJXunWdhrSVo/9P22nHkKJx7U8IjCcZZlflcoPovZE3GeIZzk= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: bba5f657-b4cc-4181-103a-08d83241dd14 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:29:33.7467 (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: x7UQ2ECUoePpTqiniyxK1bvXs310hF1qJ0qQw0dKpfO90St+vbbW9zPoXcHMFEtQZbA2y85WZAiBuIZFXjcjzA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: 7VPaobymbb3vYGAzkCX6NyQAx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863776; bh=nFhE9fWoS/7l4yBQMiSQFqXDLvCbgfUggPREQ1saRJw=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=NjU/rJFCApkSoRR7zGYyZGSIxqxdz8bodKY9EOhRGgsKD9BQXkhhMfd3p/Wr0svOnXq +mAonHRuW+JrubSh8b82XsdhIkuGpOK7nyCZJCjkiDH/8yauvCUG+gp3dMJgFzvMjp+bu SWYZ+IPzovA6UCaELkzovqye5/YLZb71mT4= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a VMMCALL intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index af5264095b98..54134f37e614 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -881,6 +881,50 @@ WbinvdExit ( return VmgExit (Ghcb, SVM_EXIT_WBINVD, 0, 0); } =20 +/** + Handle a VMMCALL event. + + Use the VMGEXIT instruction to handle a VMMCALL event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +VmmCallExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + DecodeModRm (Regs, InstructionData); + + Ghcb->SaveArea.Rax =3D Regs->Rax; + GhcbSetRegValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Cpl =3D (UINT8) (Regs->Cs & 0x3); + GhcbSetRegValid (Ghcb, GhcbCpl); + + Status =3D VmgExit (Ghcb, SVM_EXIT_VMMCALL, 0, 0); + if (Status !=3D 0) { + return Status; + } + + if (!GhcbIsRegValid (Ghcb, GhcbRax)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; + + return 0; +} + /** Handle an MSR event. =20 @@ -1395,6 +1439,10 @@ VmgExitHandleVc ( NaeExit =3D MsrExit; break; =20 + case SVM_EXIT_VMMCALL: + NaeExit =3D VmmCallExit; + break; + case SVM_EXIT_WBINVD: NaeExit =3D WbinvdExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63326): https://edk2.groups.io/g/devel/message/63326 Mute This Topic: https://groups.io/mt/75825017/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 Fri Apr 26 07:16:41 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+63327+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+63327+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 1595863783741437.1068425513216; Mon, 27 Jul 2020 08:29:43 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id uZVfYY1788612xSxaJNAiELS; Mon, 27 Jul 2020 08:29:43 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.87]) by mx.groups.io with SMTP id smtpd.web12.58120.1595863782880763815 for ; Mon, 27 Jul 2020 08:29:43 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hhfCU8H0tzFtUHOc5jpU5/bIpTr3fI15BcardzYEYGquYBd26wM/XiNqbTQ4WIC7kcpmH3aarDlTGuJqDks0LgYJG/l7r0LDLHeHI/XG/tBLty0x91Idr8AL7CavbT6/ToIA+GBQB61lj8eY/MRP7i9rozh7OQ4E/I3Zt/fwpWlYjLqcwUER81ZhFCHTabXiwWVEHxRb+YTvxITDNAPDSulyk8JdTRekeEyJu2iDZN+TDD8ij818s8uvspwaE8RlhhBtTjnwMtdlMCC4IwnlwkfLDXb+hIbBAVqLgGCMw+HTmnIZvKPqE/UAwiFPn79puUAg/t0q8Gg2GEX95qK9Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5teiAq1eAXmkeZ9hYTs+aZivrTRKKj5B0JXYx2XU70w=; b=iMxoM2Mlx4VVnsZXKAGeHPUTZwLjhFYXBCULbr0HR3eqmfPlpU0XvuaUv65dCHqH1vuwd6YZBr5wPjbb7ZRK48NulFE97BhZu3UlHYVf/KW+f03n71STwMbD7gGVrAG/R2hPxV3xxoLRlLMUFcnraMhbs3ZU522oGKzLAs2egFtXOmOrk8B6LSRUu0x3PhUE4dwoYyXbxI9ISlq5LLjI9x5RiHZUDo3PKArSFVNr+9/o9I9hGO05Pp+dLFBCnWQjE71cP6BPqrEng+NzA96WbOjnz25E6lSpp3kDL+6OgU0DdlKJSOJ42tNWhPNuVnnen+mQDVkJtHre4pM4ETouiQ== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:29:41 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:29:41 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 23/46] OvmfPkg/VmgExitLib: Add support for RDTSCP NAE events Date: Mon, 27 Jul 2020 10:26:04 -0500 Message-ID: <56bc2205b02c7d430415547c995d440f75274c6d.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR07CA0062.namprd07.prod.outlook.com (2603:10b6:4:ad::27) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR07CA0062.namprd07.prod.outlook.com (2603:10b6:4:ad::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23 via Frontend Transport; Mon, 27 Jul 2020 15:29: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: 7bc11c7a-ed99-4822-86be-08d83241e1a4 X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: /Gz/Vnjaywy8tNLNaKSMLqH+ES+fuqNRBxBiMNv8aBFGymjrSUIXKHan8GyXjIT9dYEIZuf3Sh3JF5XjxPfLK0Q4OmGc9fFGnSmOasN4wCSILcgj0gXtUiLX3VmAi9XDxNJKCa1ovzMWKzTWR49xhzQEzT7y8cN/OTidung4MmbKVa9L1UqjtUT4wt0BXU5MtkRFZZSLzaR7uE/4l/APZG26vGHWaFSP42l/e+GVWTSRWbqGkHba/IkFqcRHkKfZBhsJhfoL3cAQ7cZG1EHvLWoz6AXDXn84qYTmBGvXsZPBEOdgrww2vZUfwK6lY5YIykHVL/641eqgG8AHfyZExWztsHSECxT/BXh/VDu9iVNPfGVypQ8Pqqbl2w7c0WI/zaQsVn/PV5GGeSvwxIsjaZ/zpXzPHAsrXg53F2Za2u9iqxzAATXEXMV40eg/rvKXxm2sofTZRkURd8OpwZJ0yA== X-MS-Exchange-AntiSpam-MessageData: /zap2+yLJ6oki8FBCoqoTN4Q6sUQ7y/ufPJaoaacHd72o+Re7CFW9zjgfCaC/JQxhDBR8Y2nJBe9g/E2uRcOFUWDiYRk5HIIplIPwwpQxXVGbUlZ3tZgMwZZLRjU80/0kbBJz9hcJTr9xGP/78+i3JNkhLRM8Wy2+9pj100qGqGiKbko62qv/ARuDpzVDS51nWCcylbnai+g82xEbJNsYHEmnIb8cGsfjE665aXDlNw1ChNDPsk6JCCrOkmp+GBJqxc4q9QVJkRNVi6hJNU/BZYU93uHR0symSYg47whVDnG92xAnq0upKcy9iOQKMizoPKvwc1YUH42N85iIv+cIZNRRjCt0RgiVd+QzTKZnzB7oaSWLnbbvBZNgP9nm3sE2BhhU60pw9e4Q7H2Erhcb83p4HEXC92b6OWc+sDDivLoUazZyO+Tl7AWCSIBR8H8+jxXfPlOSnAcHc95aC6sSGL0jasYZD3aMtu80cdAN10= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7bc11c7a-ed99-4822-86be-08d83241e1a4 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:29:41.4303 (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: R1HJsBbo3hr46i7WbG3L6UNLhWb5bKQZP0CsaET+0smApERnyoz58Mj8Hu7abcLd8+8j13C/j1+7GlI7ukUxCw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: 4a6AkStpkQNYUS5hCbPTTN0Tx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863783; bh=1e3rVC2weg6bJ+6FYWQwzVYfNNBrUvxPmEzuQIykNoc=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Y8jyhnrpaNM8BBiAwokzymUCqiTfjbx7kGo6/VxLKgZOYu5DBib7j4vn815R1Izbwyn gMQVlTEyJqaRwo1i8bBOPYtmadKaFiOqgdOvGzwFal5OiV4DOC7Mc49GmZshYF+Um+FsD FaDYxkS8XJJUUIJBwd+Pt1g9iBU1IY/wU6E= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a RDTSCP intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index 54134f37e614..a1cf792d4d0b 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -881,6 +881,49 @@ WbinvdExit ( return VmgExit (Ghcb, SVM_EXIT_WBINVD, 0, 0); } =20 +/** + Handle a RDTSCP event. + + Use the VMGEXIT instruction to handle a RDTSCP event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +RdtscpExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + DecodeModRm (Regs, InstructionData); + + Status =3D VmgExit (Ghcb, SVM_EXIT_RDTSCP, 0, 0); + if (Status !=3D 0) { + return Status; + } + + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRcx) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; + Regs->Rcx =3D Ghcb->SaveArea.Rcx; + Regs->Rdx =3D Ghcb->SaveArea.Rdx; + + return 0; +} + /** Handle a VMMCALL event. =20 @@ -1443,6 +1486,10 @@ VmgExitHandleVc ( NaeExit =3D VmmCallExit; break; =20 + case SVM_EXIT_RDTSCP: + NaeExit =3D RdtscpExit; + break; + case SVM_EXIT_WBINVD: NaeExit =3D WbinvdExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63327): https://edk2.groups.io/g/devel/message/63327 Mute This Topic: https://groups.io/mt/75825019/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 Fri Apr 26 07:16:41 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+63328+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+63328+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 1595863791413969.5058266079244; Mon, 27 Jul 2020 08:29:51 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id KpRJYY1788612x6ZUzVYmwZR; Mon, 27 Jul 2020 08:29:51 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.84]) by mx.groups.io with SMTP id smtpd.web11.58135.1595863790552577121 for ; Mon, 27 Jul 2020 08:29:50 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EWHUUAtwXLJAsLc3/0oUR4DPa2A8CweB8nY810oUiuYbVXM6zogOxsEe5bssRNz7s+GTUVLoxfKqfDv25Kd8CWO/2LHM1JvjfijzlSrGLKXIhABYkyWz+C0oh29WmbsOIV13Rbt+jq+WYFr6P9jnWwG2vGSaat0OyJKrgQY95R1YnVpT7wEWs/olzT6MYtidO9FzSvRSXGJQK8ejU8QugZlsYwi51tOozu993lV+W2dTScNtNJhCkPGac5FrG+GqcmI4NMjoueooiraFOl0gM601EixaTeE/RcXk6LfC+AhmbURApuZH5b4q1xnTExylUuW0TSgE9kUIEINe/nhHWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8ngCipJpXdBRXheijMbZLSMbkg66Y4aDLYNKKgZfARY=; b=BfynjQ5B8a5I1s4lemQ61H5pO7KCIKi/r2VwHDBnd+HKM4iHkHHrSPwvhcFROuLlldbjurDMpqR33/8odM7Ab+jWk4ggyvJSjFqMzbHuXdD0u5h7MWsYHp+yAP4XbsDVjq+ypdW1S2Rv9itvER7Phpd2ocwxEqVoUr5pxYXA9yqwWwLK+JyAcQOw25c2dWMxeQKDh/ccuEVtM9NSKpYuj6MSq2BNZqwnuNmgmyQ0cXEqGKmkXYH+hMAwTTVGWZegib3iNgcEsVLWUkcFL1x6JQ16NI3rt/6RGKK2wN8sUJe4yyTmmKivVLUPRx3lS9XZa6u/zZL48+oy5sGt8GWLpA== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:29:49 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:29:49 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 24/46] OvmfPkg/VmgExitLib: Add support for MONITOR/MONITORX NAE events Date: Mon, 27 Jul 2020 10:26:05 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR08CA0054.namprd08.prod.outlook.com (2603:10b6:4:60::43) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR08CA0054.namprd08.prod.outlook.com (2603:10b6:4:60::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.21 via Frontend Transport; Mon, 27 Jul 2020 15:29:48 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: ef457342-077d-41f7-58f0-08d83241e626 X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: +TrYObIEewsJv5/6kyJgGS/a8NYiGXUkhtbvCg/M9Cg2dnooG3qdHbXJ28it9xxoq1S6+LMN9HUEnFKUHXoHGz0kl9MLSbi2wEZLOkS154BK/tDkTLmhJuhf0CVBKqfcVIMcZOz5Luj7/q48QaFIAQAjAQ7FJFcG8FFg4hdDXiWwzBCsT5xVSFG2n9CPwBEqorVMNrBOK9sW/72Bp9l87nxe03LaIYYeQd7AcvP1WjOeiE1QTwHCn+CDR04jgXxuRPxq6MScz5NY2DliEYqrFaVAdGBzMCojuDJ7aUW4dfb7YsIs2fco8lQ1pe/PfNLOlVEbsBJA64RVweqF0KNU6QV4QgnM5bWb4Q2PY6P/ckUzfBidgxw3/ixIESD4uSExvWpPSHGAJbzFdPysNhGBQsq+j+2cnMqn6QAq507w/PGSuPQ8mRPK0HmCbYgdJFTLxgQL7VSZbUBrHoX3CboG9Q== X-MS-Exchange-AntiSpam-MessageData: EF6U3ZBW2BKSp4U3b0VcRWpD8R0P7wQmTj9q5M2NBYUA6lK6G7dbApsAFIB9SYwBHFGV1aAXarauk5znrGmLS7gloU5umkcHd8zEpeYDDel9A6r/XQ2hqYxXZ5/OEK3eyuf33di4DSZyrevsyA5Fj5MFHFsTTUsepGjWMOGfdj9pFsVSTUgvZjWFznJjfoZx9zWkf2Q/ul3D9RJJamtKFOEdmtbEVZRZVrgfULQ42uI6lqHWBHUn8JNPIxkajw981/IlbP/4ULUb5qW1U+NvXZxESLH/eobBjZdIBd3sX1lkw1FBJPRKPZ0qNSU39FD+e5sbT9h8+Rtubuym7ucB/F3KMnXWtoUEUw2pxAI5WNDnSfC0PO4FqPM2wrdVED+sXDCGGB4l1wvr2yT/k14nvRfORoV2Tp3CiCL/LIiKuB0H+AHFwbnQ3cpCHALP6UbsispkqPgR5WE9nZe6uVIurfBtmQi/MmvWxZA1mxryhOc= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ef457342-077d-41f7-58f0-08d83241e626 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:29:48.9770 (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: ahjGiZxyvDZ+j9zlqRDEtsP6OhixVwtxZLKP9cmjSqDcX2G0+BvwN0dRTCnUvTrNS6KmrM5vo/OuJL9NLkPBLQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: XZ6knM7ue2usCPNphJdhUYItx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863791; bh=OtWazjrUTMUphx1fG9PKKbKxau8rpLlk05G4zqm9Rl4=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=tQl/0TtTZcWzfxgXRx2hDGrpqrQhjY6h/fABREGhLCPKigHrBjZVSxo8uK254djpPQt R6KEFH9WGQmyCAuZyunjVCBCy1lhslI9q4I6ydep92eeM7JlvXT4BcSrYkkK0VaR6jh06 UL1Zq+yZx2aygymgNYCrE1iIJZKIPMo3WF8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a MONITOR/MONITORX intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index a1cf792d4d0b..fe08b1e0ff49 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -856,6 +856,40 @@ MmioExit ( return Status; } =20 +/** + Handle a MONITOR event. + + Use the VMGEXIT instruction to handle a MONITOR event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +MonitorExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + DecodeModRm (Regs, InstructionData); + + Ghcb->SaveArea.Rax =3D Regs->Rax; // Identity mapped, so VA =3D PA + GhcbSetRegValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Rcx =3D Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + Ghcb->SaveArea.Rdx =3D Regs->Rdx; + GhcbSetRegValid (Ghcb, GhcbRdx); + + return VmgExit (Ghcb, SVM_EXIT_MONITOR, 0, 0); +} + /** Handle a WBINVD event. =20 @@ -1494,6 +1528,10 @@ VmgExitHandleVc ( NaeExit =3D WbinvdExit; break; =20 + case SVM_EXIT_MONITOR: + NaeExit =3D MonitorExit; + break; + case SVM_EXIT_NPF: NaeExit =3D MmioExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63328): https://edk2.groups.io/g/devel/message/63328 Mute This Topic: https://groups.io/mt/75825022/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 Fri Apr 26 07:16:41 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+63329+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+63329+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 1595863799062185.8646723559565; Mon, 27 Jul 2020 08:29:59 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id l2QAYY1788612xm5MB1Ktdda; Mon, 27 Jul 2020 08:29:58 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.70]) by mx.groups.io with SMTP id smtpd.web12.58132.1595863797883995085 for ; Mon, 27 Jul 2020 08:29:58 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZjAuQ7PSq3ea5CTQr+FHo3ZDspiutU0al1jK3iuxz+lzk7QsIXDQoBAAIN9RgBRLzDfZ4AyxoftRYmfqGQRf2PUyYGpji6xeZ3VMnoHntbGZ10qNlvvrzJQxNK0yJKTFbhVoF92qvG/hRz7oRGXoHgByA9i3LNShLhPwP/2q5oKR/3dRsmwcdY42L3/2oxjBA++HEa5qwIGpUMAAZ8z2PHcTdbrEO5KYwCfhO9tZEcgd8xaBel3oAg9BujZTVdYKXtsp0NPHjkQ48oIpeP+ovrLkH4335W6vHjoEAADwL6xhuvHM+1cTT85lFe3ZL9wOZWwdmrwWCNP+rCCByAvJvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4ovVcxdgW2M+goyz4Wril5Z4GVk0Gp8R9simGO5DPIA=; b=RLNl8rz40Of3VKV38SpO08gxeAhN1tTzdUGnbCmCKpHXqHy5G5fnJOIz9lY0Ga1Y/MEY26CqXjPyLEZwDwALzb0m+wX0q3FKL+DRJokm4uv1LbxjdoTHho92HEP4Ivuu6LmoKgZc6MM82hSZq2NR2LOq2IFReE01Adw9wqV8a8YoSvzbrSlUUv9pif8EullAc2ABoYLbGmfRHY6z9PpSjVyZNjpJkK1i9kTvEtCfybWzYryFKlL+yWY8TPy49gSDBjbcyl7nTA/uCfpZAH2TNE/dUX2+QpdkntV4VaxlbXGottspnY1JQYNzhsnGbkYi605vz0qI+ev6Y/FjSa9V5A== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:29:56 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:29:56 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 25/46] OvmfPkg/VmgExitLib: Add support for MWAIT/MWAITX NAE events Date: Mon, 27 Jul 2020 10:26:06 -0500 Message-ID: <32a26ee284ebdd085a309fa934b5a8c3d69900e9.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR21CA0003.namprd21.prod.outlook.com (2603:10b6:5:174::13) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM6PR21CA0003.namprd21.prod.outlook.com (2603:10b6:5:174::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.0 via Frontend Transport; Mon, 27 Jul 2020 15:29: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: 4856e3d5-eef2-472d-19c7-08d83241eaa7 X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: tTYaA153OOQorjB7syxgl0W5cZtfjc/Sz9s6loeRJ2YjN8MeU6qp9cUyNrOb5mL1OmlM282HUb/14E9cBvBCOYT6E8tRCbvMCOrTmdqgTR60cKgfkvcyravhiNBkh86VLgbE4N9Z2Yj/sLRcJDCNMonq9ORnIkgO623QSCFrF8X6pT1PPjgl/F5QiLxCE+IeRsFusSqgglcw0M0OEqfMcM7+VFxow4crwHW0X69QvSYrYl2RYXpNsdZBEEjIaDKn765Kjg+qOH9772ZRzN5qHnCo2CijH2CMJYcNDMtp2kOhaJInNY3KRdMyp1T03GosaO6iEWVCn1SmyU/yBgUhlrDK0Qv+TgjatXDiPi3Zinuc14CXNzrRDyH9mRDQ55FpchV63V8PFk9RQwTT7U9+rNHkkHtfC8eNEibjHWLv7C1RjYfZG9BJuE+9roCwmT2CFja+HuWqWLlaYktpnxVvqw== X-MS-Exchange-AntiSpam-MessageData: 1jkidhd5hGGQNDv2zlUPRAo3GUJt1MM4FOaLFrO8n4X0E3ostbdm0yJHRZ5Zha2afVLq3kc1Sll9jJCV0Fkew/G4EAAiV1G7BxgM/p0rF+gNHljslkIXAdfhs7LzQxaZGGffIkWlWAew+Gt3Hk58AGZ3wjb6tt5J8FyHrhMBezo9ZO0PHfQC8arM6D7NbDzzQ5IGEUt/k+AVoZ2td4Kqgg6mgv32lJlnUoHTBOUlFbtQ19aveUQCNkCTLSQQXa2wbEodAVV6OQQuJEcBPBGXMr0927AGIom/Ji4oFSPN+buX+qGvWN7QUCvjOSymPkmpGzRQu2jovhVAMzzU+JVMiCrubN5EjOF569a7cszuZcZ4iOXUGkt0Q8CAy4Ni1F3nVg6xX4ORA6rS6FPKLao4BgU3Jy63+NYrjN+lDlWDu0QJ1hMdErQWEZQiVjAqZkDVnvFtgm+BgTaFdARhDfBmokFC2K1CkxLjGutdEjGyNt0= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4856e3d5-eef2-472d-19c7-08d83241eaa7 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:29:56.5347 (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: gxNc8/nEzm7paF383fh59QAnPM/wIj1cVvNARJvpW58ovIf+CntaY6Cv8EMvpxRErGHPiHBHS/HXZwYgNFJY/A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: XorVPn4IGhPMo7p2sbpP9bzyx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863798; bh=PIGAamtdPzsyPRH4TkSWWcLwHHteHlDTeV6yb8V3uhk=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=IJdFR/ZVx4Y/Q2crW4uNd53UkvwlYcHwjakbIQ0LwicMtAU+GAnN9+ulIkmn/2k3xwA I7nBj1ycVadltYTV15cAyGjQWJO9lG62wB6YAN+8GcS1Dd+9CEjFpaODInU3yvKVZ4Y/V x3o0fh1vbKsIj6p/6XaKudpFZ+SBpYGON94= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a MWAIT/MWAITX intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index fe08b1e0ff49..e70e0ef82f68 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -856,6 +856,38 @@ MmioExit ( return Status; } =20 +/** + Handle a MWAIT event. + + Use the VMGEXIT instruction to handle a MWAIT event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +MwaitExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + DecodeModRm (Regs, InstructionData); + + Ghcb->SaveArea.Rax =3D Regs->Rax; + GhcbSetRegValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Rcx =3D Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + + return VmgExit (Ghcb, SVM_EXIT_MWAIT, 0, 0); +} + /** Handle a MONITOR event. =20 @@ -1532,6 +1564,10 @@ VmgExitHandleVc ( NaeExit =3D MonitorExit; break; =20 + case SVM_EXIT_MWAIT: + NaeExit =3D MwaitExit; + break; + case SVM_EXIT_NPF: NaeExit =3D MmioExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63329): https://edk2.groups.io/g/devel/message/63329 Mute This Topic: https://groups.io/mt/75825026/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 Fri Apr 26 07:16:41 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+63330+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+63330+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 1595863808782121.55969254366335; Mon, 27 Jul 2020 08:30:08 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id mbQDYY1788612xPexuDoNBWc; Mon, 27 Jul 2020 08:30:07 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.89]) by mx.groups.io with SMTP id smtpd.web12.58137.1595863807184112307 for ; Mon, 27 Jul 2020 08:30:07 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A0wnWaXSU5vZmOjxJlNRRaE174ur18+xcAAPxLPqCocaHbF8qXG43W6uo5Vg31IGQy3JbKTTkd6azTJxjpkLho6NHpt/KOdoeEGHO8i80amkdkJCHCrN3KlyAc9nwqb4NF+f0k/g8R0p88AIBu7PqjmzszSdd38yxUPlbExb9xvHeqV1sWzhTCjQgEaaLcEfqhxznvGimptLgT+RrS8SxnJiIvIJqoFQYXomVMYl+wkL/tjhkw2c02k/TZE+4grHJSyysy6gI4IxcD2SEtQI2Vnmk3/YfVnHi/1AYAlwQiCF4NH7yxE01bksomXgguLcd1b0bDbtAGVgYpv57EEyRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eqxKEl1jkDkoQSy0tcmI5Mo0oyJK/DNNn+LhL12PTF0=; b=LpneVv7wYkbabHmrM/eab3cgDW29ogqqqMSFxxCSjWQ57iODi0MH2iSH3L+tmo0/5oFm6vPYb86d/6K3ne2VHYVQp+9p+VG2FMND+Eo92KFK2pGFHNIilNlZErM2FwTlsvGxORXLaCsePxr+mFt8VkJhsMKsI0tPJBco8YUpt8D/EPDizoIFZTgQN4FjKdkzJDi91XxTwIY1/23JliJI6rgDkvx9pz9756F0awmT0EcsR5nZioR4ohAG6jxeXJndk+Fp+mLDzZoYwahp5RkVJgU0xqJV6KvNyqrDh6AEk0+UMtJL9ZRcjT5k/nAt/h6tQ7+zP/8DBY+xrpqO5zBzJQ== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:30:05 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:30:05 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 26/46] OvmfPkg/VmgExitLib: Add support for DR7 Read/Write NAE events Date: Mon, 27 Jul 2020 10:26:07 -0500 Message-ID: <7779e6d2ed997244e6f6bd71b9fcbe1bfe0520b2.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0401CA0014.namprd04.prod.outlook.com (2603:10b6:803:21::24) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0401CA0014.namprd04.prod.outlook.com (2603:10b6:803:21::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.22 via Frontend Transport; Mon, 27 Jul 2020 15:30: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: 54957aca-fc35-4aaa-020f-08d83241f00e X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: AmBarF59dlIXoIc0WZLLJI9afMbqVLL8CS+qADshugrIxeJ+HiRuUaDG06mGLWZY1Uy0hPXKykyyZ5xVvE4BuDaMozyrXLSuXCa9z9rrJZ4yf14slVf6mmjo/S5I6oDfQqPlKlQKapUdN8/gqXhPgoN2Ts8GJq+6FHsfh2iON8DzhgAfX135Q9fDPDLtO7TgapzA50krdqNrHHpOxz8mxFhmxuJrFlwCJnuP41Le3evNFhKetFHfOgttqqSC93V/fElJEjPujLruGIxXAFaFnHDHf7X9zImKHaNIaAcV8EYy0JHJCc1K9oLxhfEppgu/b84Mr7orQdy5itAnhkAuh6UEZi7OeSZJ7tTfVL8AkVN9Ucd0rZKvxVr8oFYn95UHfHb4gbmDTEkd8e16H1bjEUYa8ms8PPAT74AOdMbspCuCOgmTliPJk+6I5XUjBUQUliSJY0jNBjt72fQdvY+sEQ== X-MS-Exchange-AntiSpam-MessageData: djfioq6Xy0H/LYqIhhY8D1NBUs1qL+i2gMkeLfNU5O6erHqzh1CqIFObmyg2OCgDboheaS9kIyYMKS11M2JhxaBpVgwwemi0c5SOmG3i8CoeQ9L5T/r3E1R1KtPLQT3Gjnfo6Uim7ILGEsRGYxjBBePtHw3ADTNxXAxFk34ij/jwZw+OiEtyQxjvtsy9Jz6uKQGl4JHqFpkQhhw8vvDz+HotVaVVr9AXclKidcY+Jhd2i4Yw4/T4wJkKFOdv3O2Fzub03VQ1R75ajB+6aep63Ok/mSos3XlbpfQcBPI0Wt5nI6p78zo563z/wxDpg08CoGje/0lQ3qEbmKk2DOtR43ePBSm3V8IqJ97sq862A9DO4p4N1UucKA0SSIJHRh8du82S7cHR+Nz/jmRg25s+opsZN1Ld5/7vSsME/hMd5BIC6D4S0/NbTR2ZMHab53jAECeJsFhuKabNoqq9gKo0VPTGgJKNFH9cm8K91qHJkQY= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 54957aca-fc35-4aaa-020f-08d83241f00e X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:30:05.6647 (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: U7iB2Dr+8go+t1UbAe1Um8455KV3jCWj28wKK1rpTnSDlQIhHWo7mXKWSv/9FFdY5PzGWMHP9QSjfHj/78mOwA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: L2JHJlDM64YhBHz4TcKmxTSwx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863807; bh=2KcMW2Bo81LqrXPb1QmQtGquZr2lhrJ66NNmYOpTfA4=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=d6cqgfe0esXzFB10PjAGNVVsspJGnxEqV5VOYAdKUK8pbJeJmgzj6nFSvAWocfYfEbk E0vtEveFz6Pt6mcErAUu1zjAonjREomIhggYd8++6A3u91z8BbCey257wtNIRJYkzEQdu 6g1tatHifwRfcTbROtMRvLXCYNrWGiNBSTY= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a DR7 read or write intercept generates a #VC exception. The #VC handler must provide special support to the guest for this. On a DR7 write, the #VC handler must cache the value and issue a VMGEXIT to notify the hypervisor of the write. However, the #VC handler must not actually set the value of the DR7 register. On a DR7 read, the #VC handler must return the cached value of the DR7 register to the guest. VMGEXIT is not invoked for a DR7 register read. The caching of the DR7 values will make use of the per-CPU data pages that are allocated along with the GHCB pages. The per-CPU page for a vCPU is the page that immediately follows the vCPU's GHCB page. Since each GHCB page is unique for a vCPU, the page that follows becomes unique for that vCPU. The SEC phase will reserves an area of memory for a single GHCB and per-CPU page for use by the BSP. After transitioning to the PEI phase, new GHCB and per-CPU pages are allocated for the BSP and all APs. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index e70e0ef82f68..c57c8c4ba203 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -126,6 +126,14 @@ UINT64 SEV_ES_INSTRUCTION_DATA *InstructionData ); =20 +// +// Per-CPU data mapping structure +// +typedef struct { + BOOLEAN Dr7Cached; + UINT64 Dr7; +} SEV_ES_PER_CPU_DATA; + =20 /** Checks the GHCB to determine if the specified register has been marked v= alid. @@ -1480,6 +1488,104 @@ RdtscExit ( return 0; } =20 +/** + Handle a DR7 register write event. + + Use the VMGEXIT instruction to handle a DR7 write event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +Dr7WriteExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + SEV_ES_INSTRUCTION_OPCODE_EXT *Ext; + SEV_ES_PER_CPU_DATA *SevEsData; + UINT64 *Register; + UINT64 Status; + + Ext =3D &InstructionData->Ext; + SevEsData =3D (SEV_ES_PER_CPU_DATA *) (Ghcb + 1); + + DecodeModRm (Regs, InstructionData); + + // + // MOV DRn always treats MOD =3D=3D 3 no matter how encoded + // + Register =3D GetRegisterPointer (Regs, Ext->ModRm.Rm); + + // + // Using a value of 0 for ExitInfo1 means RAX holds the value + // + Ghcb->SaveArea.Rax =3D *Register; + GhcbSetRegValid (Ghcb, GhcbRax); + + Status =3D VmgExit (Ghcb, SVM_EXIT_DR7_WRITE, 0, 0); + if (Status !=3D 0) { + return Status; + } + + SevEsData->Dr7 =3D *Register; + SevEsData->Dr7Cached =3D TRUE; + + return 0; +} + +/** + Handle a DR7 register read event. + + Use the VMGEXIT instruction to handle a DR7 read event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + +**/ +STATIC +UINT64 +Dr7ReadExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + SEV_ES_INSTRUCTION_OPCODE_EXT *Ext; + SEV_ES_PER_CPU_DATA *SevEsData; + UINT64 *Register; + + Ext =3D &InstructionData->Ext; + SevEsData =3D (SEV_ES_PER_CPU_DATA *) (Ghcb + 1); + + DecodeModRm (Regs, InstructionData); + + // + // MOV DRn always treats MOD =3D=3D 3 no matter how encoded + // + Register =3D GetRegisterPointer (Regs, Ext->ModRm.Rm); + + // + // If there is a cached valued for DR7, return that. Otherwise return the + // DR7 standard reset value of 0x400 (no debug breakpoints set). + // + *Register =3D (SevEsData->Dr7Cached) ? SevEsData->Dr7 : 0x400; + + return 0; +} + /** Handle a #VC exception. =20 @@ -1524,6 +1630,14 @@ VmgExitHandleVc ( =20 ExitCode =3D Regs->ExceptionData; switch (ExitCode) { + case SVM_EXIT_DR7_READ: + NaeExit =3D Dr7ReadExit; + break; + + case SVM_EXIT_DR7_WRITE: + NaeExit =3D Dr7WriteExit; + break; + case SVM_EXIT_RDTSC: NaeExit =3D RdtscExit; break; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63330): https://edk2.groups.io/g/devel/message/63330 Mute This Topic: https://groups.io/mt/75825039/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 Fri Apr 26 07:16:41 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+63331+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+63331+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 1595863817529883.2771166466871; Mon, 27 Jul 2020 08:30:17 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id G6yxYY1788612xXHmCTqlliu; Mon, 27 Jul 2020 08:30:17 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.43]) by mx.groups.io with SMTP id smtpd.web10.58373.1595863814959816186 for ; Mon, 27 Jul 2020 08:30:15 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SsukQ0NkJIToNPzOW3ly9LaI4OogTyohP+S51LRNh9MNx6RwqpIPQXCBt28X3rGYQDaPZATMsQYltGNK9SJs22aisvt00h+QLQVJsx4uuhEdY41yhMDIlx5lbE6aTqdLnCSzBlqnHBcYBoq/sm0G95O4GadrEn6oFhxIBSWPax3MX5QH6DDGTWixvoehn5DhLyp4Ss9Usy9VR0RpHDbZ2I1eXzQGN0wnFSVQkNYoeuVJqEhy2k7mactg42LyBGfevFAqBAdyyjvDdMjOSdaeFaFsuJll9866wA0RnOTuT7jrFjyeDkJKkOGC4p9yR7gk8mKntuHOcBJj453YRgOsNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vjUCEgWiruW32rdghdGFw/QPeneWsq53gmsGSiMfqdM=; b=EO9EKDfQd365ECE3kVoa5rDaXrHqPq1CE0RPmG0lVrTk3v2aRNdAwcDSgOQq8BrqixeaBuPV1687lQkgm8Su0TPCpYf+/6CjgJLw/5IOZvv59TQ1P+0f+ETS7NX17pqmEouunAJrkphNZQcutE4h4kqZvVI7efsFCQ1THaIGmHv7hUgtQUDFYeZOM4rnK7roreqBjIpFU++zPF/5/f5V0iT9LXY2OkpJ/gIxEbsQk7ih6l2MWq7HcL5E8aHA+kOrhxMDi/gDQRtXzaY1a4P4yjahuiS9DBR1pvUgGFbgC6KeZfyJfoYXjOuHfBRhqX+6ahujSgUYjcU4grkdiQutNw== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:30:13 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:30:13 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 27/46] OvmfPkg/MemEncryptSevLib: Add an SEV-ES guest indicator function Date: Mon, 27 Jul 2020 10:26:08 -0500 Message-ID: <5640f7c2800169018ff262d5715078904e1dab72.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0401CA0017.namprd04.prod.outlook.com (2603:10b6:803:21::27) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0401CA0017.namprd04.prod.outlook.com (2603:10b6:803:21::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23 via Frontend Transport; Mon, 27 Jul 2020 15:30:12 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 60cfd652-8ca4-43ea-87fc-08d83241f4d5 X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: l27UN4/BX1S2O8XZ8QclTERb5OPsRuwOO9zNtWtxjWc2BU9IipVOBKRYP0Utnm07wKnAVkum76T8i6r/qMyGlRz/ORJb4fN8IPWuI3B9bSZWYQDW9UAxkgNXIW1hw24gVjjVkARvAQ0vEtewEgrV/ICOqggEwpVSvie+4R2rVVCcy2FHGanR09jd2Yasd84xl05BQRIROZCxZ3cb8+JHa1WGvF6a/StNpOdJ0+/YMYMDPPegZvvLH5N32eikShki48+1eX/21uLFMo0m340ZvHOhZM2bd2ghjKSpQtLpNc3LHjm/Z05Fz0jBNaEStC7SJI/uJ8NxsNUSYiCYQTW9iyYg9M44oNBRKK20fqDCsmsUG2F5McVnliISWZLbnrEw+TGuQeFXqXT24UlSK+yVBpn3TbYFrf812KxkZukOgGH4jwVuPR5kLBpNoxNNigRP6bJJtun+eq9884uy2RgdoQ== X-MS-Exchange-AntiSpam-MessageData: suL2PbosIdk3ur+N/Gh5GvhIWKusgmWVWXi9i/WlHBCPAZu55zRK3NUdexT7CDpeW8/+oKCSyG/Ov6wWeltAND85YxZ91CfsLptGd+LBmMtv0rJZ4SXrWHy0yJDQKjT/x0I1vcTus+kUZXL4NX57K5RrWZNtnhu/ppgHu84IMXajxTZJSx5HF2A/fV4OZz/U/C4CVzh5X16XHpaR+bOwfQ+5aY+MTm2dtHHjdtCgl39HxBr+PGW82uWoxyVgJ+ua090oSFHF2y8tv3FLKBKbEcnOUYAS/P/4LbIsP3Ks+VCMl3eZ0rKqdcrm2uL6aAf0mKKpE8IDs2BzEftuQpCmoDEA14PUP/6JZU70VcsaGFWudn7iIbms5BqfuUYY7zwhOuPTsYkfpo8r2jgK0mO2TbVYuHLq1bp6kl34IbHQpwVu8ZEsjQ//Tisi1wNwtE6oNYH2ENSn0rDmEKrdGutSfhNrdNBD9/Utuc1gwYHh+Ag= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 60cfd652-8ca4-43ea-87fc-08d83241f4d5 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:30:13.5882 (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: qXOlsKg9+4KXDlqWPe7UaPJlmW2QsTmCHpmlQbhnqTGqYXLmHa37ry7nLacl/fXWcFTaan+t93ax31BlhLGHdA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: MmDKSgotdcQUOXCbv68aOwXex1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863817; bh=U3jHQqnbzJzLZ88bwCZ5ZsgvHfgetrA/YEaRKOYxCVk=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=i3rrO4f9bx4vTaS+6lSaFr2TiJiuRkK8Cwsp8a39T3PRiw/qackZVsDYA36CwjiB6oV KH+xboE72scf0PGMBVG3RS+z3/Pz1gyaaGO73xw38lTs+c4lf3gU646GXMs7XlR7WAE02 fpeO/QDrbK+4AI9WMNcwNAJTdIAeUJdJcdw= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Create a function that can be used to determine if the VM is running as an SEV-ES guest. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Include/Library/MemEncryptSevLib.h | 12 +++ .../MemEncryptSevLibInternal.c | 75 ++++++++++++------- 2 files changed, 60 insertions(+), 27 deletions(-) diff --git a/OvmfPkg/Include/Library/MemEncryptSevLib.h b/OvmfPkg/Include/L= ibrary/MemEncryptSevLib.h index 64dd6977b0f8..a50a0de9c870 100644 --- a/OvmfPkg/Include/Library/MemEncryptSevLib.h +++ b/OvmfPkg/Include/Library/MemEncryptSevLib.h @@ -13,6 +13,18 @@ =20 #include =20 +/** + Returns a boolean to indicate whether SEV-ES is enabled + + @retval TRUE SEV-ES is enabled + @retval FALSE SEV-ES is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevEsIsEnabled ( + VOID + ); + /** Returns a boolean to indicate whether SEV is enabled =20 diff --git a/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.= c b/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c index 96a66e373f11..3301c5c2862f 100644 --- a/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c +++ b/OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c @@ -20,19 +20,17 @@ #include =20 STATIC BOOLEAN mSevStatus =3D FALSE; +STATIC BOOLEAN mSevEsStatus =3D FALSE; STATIC BOOLEAN mSevStatusChecked =3D FALSE; =20 /** + Reads and sets the status of SEV features =20 - Returns a boolean to indicate whether SEV is enabled - - @retval TRUE SEV is enabled - @retval FALSE SEV is not enabled **/ STATIC -BOOLEAN +VOID EFIAPI -InternalMemEncryptSevIsEnabled ( +InternalMemEncryptSevStatus ( VOID ) { @@ -56,32 +54,55 @@ InternalMemEncryptSevIsEnabled ( // Msr.Uint32 =3D AsmReadMsr32 (MSR_SEV_STATUS); if (Msr.Bits.SevBit) { - return TRUE; + mSevStatus =3D TRUE; + } + + // + // Check MSR_0xC0010131 Bit 1 (Sev-Es Enabled) + // + if (Msr.Bits.SevEsBit) { + mSevEsStatus =3D TRUE; } } } =20 - return FALSE; -} - -/** - Returns a boolean to indicate whether SEV is enabled - - @retval TRUE SEV is enabled - @retval FALSE SEV is not enabled -**/ -BOOLEAN -EFIAPI -MemEncryptSevIsEnabled ( - VOID - ) -{ - if (mSevStatusChecked) { - return mSevStatus; - } - - mSevStatus =3D InternalMemEncryptSevIsEnabled(); mSevStatusChecked =3D TRUE; +} + +/** + Returns a boolean to indicate whether SEV-ES is enabled + + @retval TRUE SEV-ES is enabled + @retval FALSE SEV-ES is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevEsIsEnabled ( + VOID + ) +{ + if (!mSevStatusChecked) { + InternalMemEncryptSevStatus (); + } + + return mSevEsStatus; +} + +/** + Returns a boolean to indicate whether SEV is enabled + + @retval TRUE SEV is enabled + @retval FALSE SEV is not enabled +**/ +BOOLEAN +EFIAPI +MemEncryptSevIsEnabled ( + VOID + ) +{ + if (!mSevStatusChecked) { + InternalMemEncryptSevStatus (); + } =20 return mSevStatus; } --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63331): https://edk2.groups.io/g/devel/message/63331 Mute This Topic: https://groups.io/mt/75825043/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 Fri Apr 26 07:16:41 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+63332+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+63332+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 1595863823942246.67834234065583; Mon, 27 Jul 2020 08:30:23 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id obhxYY1788612xXow9gc6XnK; Mon, 27 Jul 2020 08:30:23 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.82]) by mx.groups.io with SMTP id smtpd.web10.58376.1595863823034126060 for ; Mon, 27 Jul 2020 08:30:23 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bUJzoeK0ozdCdMlVEUF/jE4fCR2sdMr0eH6h6w6XDGoC8xcV7NSK131imqZAiTPM+nECk1A8tKcrROB47aT6iF9c/q7FDjY0GWl3ln69qnq2RQVeR01Exd2dZ1Qfpnmmu56fWxhrTnvdy8+Ql7ZNemJc8fvHEFUS2JOdcjQg8pHzWkr/USD+tMnV/u4pZBKUez+Ym8sVV4LXrLfqk9l9Wz/eWUKrs09ioAxJSXcgWFUxxKzEWT4J4a+B1asGkgSh6Y0UbD1/5jL6KyHzhYVJDwdyMsWKG0LGZ3ulYQDOsjXHcNBVlIo4QGpeyRCGyf8YBvyneTvqTrP0oe4slK1hVw== 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=tpMCGKkJ/vd5g9S5fco/aQoufjhaVtd6vFQYZt6tvPo=; b=CZkp4uO8iUR2Xyktjod+Flm9NTnH0a/R+QvjOpsZzZ/5BQg+aXwXagkMv9MA0rt8U/+/ZxPKLHd/zUdbeW1CnuTNEYxjPON2se24Mk9y+EoV2aXHRRLVH14Q4PxGaxmcmdX2Ocwn8n6eGNJrxUPPhjdN/Iv9MmwZztjI+0aJxeOmqAI2dpEXSTV6aSlmywVbWCkI3v6/9RDr8e74EZ7ERMla5dPJpgRt9cPX5L8KyhVlDnPT88+SmPMK/NhHTCXlqA7XTn8l4TW4ECa6KlWgCCgQpSeY+Wzk1P51LPlbi//wb9wAqIIsJ5kd3/jua4wMnGmtMgGh1pZDIFMEn+00qw== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:30:21 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:30:21 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 28/46] OvmfPkg: Add support to perform SEV-ES initialization Date: Mon, 27 Jul 2020 10:26:09 -0500 Message-ID: <7919055d7213783830256f324428c95df1036842.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0701CA0044.namprd07.prod.outlook.com (2603:10b6:803:2d::17) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0701CA0044.namprd07.prod.outlook.com (2603:10b6:803:2d::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.20 via Frontend Transport; Mon, 27 Jul 2020 15:30:20 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9aa45554-3ac7-4f7f-82aa-08d83241f9a6 X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: sWYXps5uUqPmGwnj1OAsOF8Y1uZeYU5aNG5mpKeqgbP4PsVL5NJf9gUY2EDdEvBQktCGib9q08XDnPVbrPX/dkYSZq/bUZ8U5uTpnRLNhwBXMJG0Xuq2PLLcs7K5RQ422gB+c88y75+wfTn27QG8+Ofrih/hOuobFHUdsB6pYsk4nXCAoao7T4glq4wk4Ct08/w/5sFaY4CHLE+AWfplG4fYbp0e06JLaskfbzwzX5dxLQc+9QvdlVYA2iQXjwJ3FlEml5LsIejHFMWJnQCnYLtowIFI8iXiSqgNBhkuf5jloXg5FyCz7OrRv7pVFom4uB3Bj3t6RVgNNtaadJcbFkPyyNM7V9nazYL7i+Y3Jql9N5K5MNKEj54lTm3b3V8Mqh6MGMP846LbexJ7oZOCO55TKQq+ibIebfI2krbLGpEYXsEHSIxXT+TrXWqTKBQrXMo0OJ4ir/BYby34ULcZrw== X-MS-Exchange-AntiSpam-MessageData: XnKaHFh9bZrsP+1m+/b4cde27VrhtmXAVMhdHSjBGfn84QQrL3s27/Ml5NSHC+Mxm4RhLfIdCp9AnrGJmjegXfyQHxMleQJ8U4xVCkcGGaX6KD6mjrzZRLoVPJqkM2Jit2dsZTmoD1kCDVWqP9OcE/PkkykflOXaYqfIti+IGC1PrbSce533Gql0bOurU3FSvJrPCrM9xmxffy5DMPqYU2cHPMui5bFsoXCm4DsN/TBQi7duTamcQa/hZ+9EjvqCvgserf2cJm/vTYHv6Nwszg+p8DvG79FfjuGyR4KpJFkpl+uruXfAAv3qGYB+uP0MGsnQuoNGqPmH8xqa7AuzSo4Q+vbwn8GrKHLdu3+e8ZLuwtNdMu+uHsxOYXj1Jl5kQ3pG56+mfEPgYPvoRd7aoghAZgL4XzJSKzsy5yBI86GT6wO5lLMVmMo+Eb3F82AJHVMAkC0QNqMSBbXmxoctK0J32dDPj3m+BcrQ6G2xosw= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9aa45554-3ac7-4f7f-82aa-08d83241f9a6 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:30:21.6916 (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: q6y3FFEuyw5QtRK8qbyyzdOT2tZuEkapCodw4f5lUH3bHCdnGttvmwOcEjoRkYOxc+omlnFOTBsLjHCzrqLxaA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: F92TwSkWYKBbfbFI8BfRwkT9x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863823; bh=fOKuOM6JqnzyybGA4auQqZSNX2C3+tdfFmECelMLK08=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=WM8/yPAjuIJNTMq9ERiEn8E6w3J8R/Jn/CJV6Hw1L1m0XMcEVYUb3/OeouLCv+7IFtt 3p5U7Y3HxrkheN1s5zzM083W9zfiXKPfjDNtwH+g3q+sFH87NhX3VJ/tadjnjY0c/ONXb O11sSYT7Y3TC5I9k0Vvc9LIpr58zfG7TxtU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 When SEV-ES is enabled, then SEV is also enabled. Add support to the SEV initialization function to also check for SEV-ES being enabled, and if enabled, set the SEV-ES enabled PCD (PcdSevEsIsEnabled). Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/OvmfPkgIa32.dsc | 3 +++ OvmfPkg/OvmfPkgIa32X64.dsc | 3 +++ OvmfPkg/OvmfPkgX64.dsc | 3 +++ OvmfPkg/PlatformPei/PlatformPei.inf | 1 + OvmfPkg/PlatformPei/AmdSev.c | 26 ++++++++++++++++++++++++++ 5 files changed, 36 insertions(+) diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index c57bba1ba197..f84f23f250ef 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -607,6 +607,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 22e930b12b9b..a66abccf8266 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -619,6 +619,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 60be5eae3d2b..2a8975fd3d29 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -617,6 +617,9 @@ [PcdsDynamicDefault] # Set memory encryption mask gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask|0x0 =20 + # Set SEV-ES defaults + gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|0 + !if $(SMM_REQUIRE) =3D=3D TRUE gUefiOvmfPkgTokenSpaceGuid.PcdQ35TsegMbytes|8 gUefiOvmfPkgTokenSpaceGuid.PcdQ35SmramAtDefaultSmbase|FALSE diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index ff397b3ee9d7..00feb96c9308 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -103,6 +103,7 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber gUefiCpuPkgTokenSpaceGuid.PcdCpuBootLogicalProcessorNumber gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize + gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled =20 [FixedPcd] gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index e484f4b311fe..4dc5340caa7a 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -21,6 +21,27 @@ =20 #include "Platform.h" =20 +/** + + Initialize SEV-ES support if running as an SEV-ES guest. + + **/ +STATIC +VOID +AmdSevEsInitialize ( + VOID + ) +{ + RETURN_STATUS PcdStatus; + + if (!MemEncryptSevEsIsEnabled ()) { + return; + } + + PcdStatus =3D PcdSetBoolS (PcdSevEsIsEnabled, TRUE); + ASSERT_RETURN_ERROR (PcdStatus); +} + /** =20 Function checks if SEV support is available, if present then it sets @@ -103,4 +124,9 @@ AmdSevInitialize ( ); } } + + // + // Check and perform SEV-ES initialization if required. + // + AmdSevEsInitialize (); } --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63332): https://edk2.groups.io/g/devel/message/63332 Mute This Topic: https://groups.io/mt/75825046/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 Fri Apr 26 07:16:41 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+63333+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+63333+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 159586383212037.2976716230163; Mon, 27 Jul 2020 08:30:32 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id YwSxYY1788612xhFJM82IkqB; Mon, 27 Jul 2020 08:30:31 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.70]) by mx.groups.io with SMTP id smtpd.web11.58151.1595863831161677570 for ; Mon, 27 Jul 2020 08:30:31 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=No8Q/gwNGaoUcSV6WDLXog/uYuLIfCDeltEoDkh9T/+JkwALk1FRijBnYyhptIvAK9rvT2SYmE7WrdzwTWd2uUNK/B/Ny3UHe6ZvkjHCdxhDqDR++P84s05KtRU3v5OErYXD1BCd3txNYse4vwifQ8RREQA3qbhpEP9y3psu5adT6JyVkJR59HS5iRL58BPtgpng7y6RF7eTA7k4noc1p2S/nXhBSfdmnnk8NSxD4i9GhWtfz6XYyyKa+8YIC+3LaVnMvAgieocP2AQE6R6Oh7QWulCfsID5LR8f77gNQiESXE8AxrsR17I2i0wOoPtBtqNiIgcb+kpE+x/5br0KAQ== 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=Ke60PaVdSxYJQ3IyGhV7lZu5CXMr29+Cm4iFcbrKpTU=; b=WrAS8lX97Ukjv3p2iOzXMbXxH21w6Fv+xqK7/8A4R7wfXuFr54EGsp9WZo70KXX4Hmr1U1XkzX9Q+tSDTEdlpHQjDre6TJtJDE77N7Lk0/2mPTTf1UA/018NSElSOvisFcCiJ0vjPapp6JjnSuyX2XJnIGjbp4t6zuneoZZHUQcT2xPb2gqRBS8Fe63yEUxi+OBcBn+cbDL8ZhOcXuTjAJaJraxgazwb5R7VexkJzNuPpYHRL20pGEjgWgayUQ/crQdC0PmWwpAJs6uMKbmo0yOP3nIYvL5UJABUjoItRFzXvCu5pnfg/N+QxkGPC9kqW6DGWOXCdxRHnS03tz7oUQ== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:30:29 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:30:29 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 29/46] OvmfPkg: Create a GHCB page for use during Sec phase Date: Mon, 27 Jul 2020 10:26:10 -0500 Message-ID: <71908bf506dd12f05342e80ac351a4dc7eb52928.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN1PR12CA0079.namprd12.prod.outlook.com (2603:10b6:802:21::14) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN1PR12CA0079.namprd12.prod.outlook.com (2603:10b6:802:21::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.20 via Frontend Transport; Mon, 27 Jul 2020 15:30:28 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 26acb4d0-45b1-45ae-0064-08d83241fe60 X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: sEpgVtMXvysIGicWfPTff4QeSGA+NhM52oXQQ3VDqNbYb9jMgBG/0RS2H9mZoB+NZeQW6csST04QvatKSYkn6XNGvKS4xHjBiZHvFbvbrYZX/sqidvL9wvG7+GKBc+jS8F9XxNdkFT6kX8mXv0Y9MZqJftHLu7KTNY4qTmTvX/LKHHRwkXVw+z+R+8mJJh4rjauOcqUfzvg1tNramMAQWAjZkm2PO/vc10Qr1fHauacMs0BxHSsgd+gBuAAsZrdUSUSWdusIu84fZGx1DTZb8WgWjqZ6y5kE4sx0B1lDcUqDUlLewYTMkpUbRHDCjhFde76Pcah6ClE3tOvB98MbaUfqrfhJ3wCKhXI7bMdpr9o7SCph0NhSqtudPqsXG0fymXrsR0AiTva/StyJRq24zU0pwgPqz2a0QiYjTpZtwoRInrwT1uJpq9TUsFxIN1OFE4mMU6WfOysK4Ccfr9a84A== X-MS-Exchange-AntiSpam-MessageData: 6ufHaQJge+UR2EJS8K0hv72UVMEU7GOzo1imVfSof5ydNQk9yCsIhoYaIkhhl6b75OjnBjHLI1nFk21rxeyKHNk3iw1S7qhpMB+pkQ0AdLGc94l4fMdAVWEqg7j3Q/bOOaH02vVmN2ji5mtEAjkCVrEGD9ihjoUa8r4xV8zBowLcfzbfDqdtMFW3Zi4JOT/2ikJJZJbM14pUJigDMzLrqiCGnhpM49J/q5sIbTHPqzUsr8XrAaeuiZ5Oz5X8gL8w9yUkh6Ost6TG0/zV72fQtk6h+efYN+rmx7Y/y8io+pjQcJoLkgREqz/p0Q1y4Trwzz1vUbLirpUs1MMB/sfJ1CsRTqcgK3v2y3HKax3xaifSlTHsG3IFK4FCYINLKRbtLcKL5Fy2DsZj4pQ/uMtbpp3cvFJGE1W2Qd+Tk/br5B7yR0OlewRvJyCq+/qtNCyAslORCaQucVZy8PMoF1dpXZKpUx2BtOcHZ/+/k8a0n4s= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 26acb4d0-45b1-45ae-0064-08d83241fe60 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:30:29.5982 (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: 8tb9qHG1pwy1W0+HeZJSJNti4Z73AKOtBsmaMA/fHSIKJR66n7htjcjtlMrgh0lhg/gWWxlaU2u9s+wG70fO5Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: uDmg5XMdDOnqzn7WsFfgdlZix1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863831; bh=PpL5ToIjB7OcYJa1C3Sy5ixlK+1TDWYscp0ZKv7daIo=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=rqXrOpkMFzEAndAVNWAF57K0Lb8kAJAch740cnFqKWxh7Cq6GnfGzUjVYLexl5lGyCT LZNNQUn2Pq5Ey1L1j2J2E5Wbb4Kvh79ZD6cLOagO7BfBbG/eMdXJL9HrbUeLmwhXKgWNt TpJEYa+LkaDD+U4NyEDafWsE/bZqTIyiSHw= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 A GHCB page is needed during the Sec phase, so this new page must be created. Since the #VC exception handler routines assume that a per-CPU variable area is immediately after the GHCB, this per-CPU variable area must also be created. Since the GHCB must be marked as an un-encrypted, or shared, page, an additional pagetable page is required to break down the 2MB region where the GHCB page lives into 4K pagetable entries. Create a new entry in the OVMF memory layout for the new page table page and for the SEC GHCB and per-CPU variable pages. After breaking down the 2MB page, update the GHCB page table entry to remove the encryption mask. The GHCB page will be used by the SEC #VC exception handler. The #VC exception handler will fill in the necessary fields of the GHCB and exit to the hypervisor using the VMGEXIT instruction. The hypervisor then accesses the GHCB in order to perform the requested function. Four new fixed PCDs are needed to support the SEC GHCB page: - PcdOvmfSecGhcbBase UINT32 value that is the base address of the GHCB used during the SEC phase. - PcdOvmfSecGhcbSize UINT32 value that is the size, in bytes, of the GHCB area used during the SEC phase. - PcdOvmfSecGhcbPageTableBase UINT32 value that is address of a page table page used to break down the 2MB page into 512 4K pages. - PcdOvmfSecGhcbPageTableSize UINT32 value that is the size, in bytes, of the page table page. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/OvmfPkg.dec | 9 +++ OvmfPkg/OvmfPkgX64.fdf | 6 ++ OvmfPkg/ResetVector/ResetVector.inf | 5 ++ OvmfPkg/ResetVector/Ia32/PageTables64.asm | 76 +++++++++++++++++++++++ OvmfPkg/ResetVector/ResetVector.nasmb | 17 +++++ 5 files changed, 113 insertions(+) diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index f16c00ad5b99..74d88f61617c 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -289,6 +289,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|0x3e + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableSize|0x0|UINT32|0x3f + + ## The base address of the SEC GHCB page used by SEV-ES. + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase|0|UINT32|0x40 + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize|0|UINT32|0x41 + [PcdsDynamic, PcdsDynamicEx] gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent|0|UINT64|2 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable|FALSE|BOOLEAN|0x10 diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf index 83ff6aef2e8c..edb03b5464d4 100644 --- a/OvmfPkg/OvmfPkgX64.fdf +++ b/OvmfPkg/OvmfPkgX64.fdf @@ -76,6 +76,12 @@ [FD.MEMFD] 0x007000|0x001000 gEfiMdePkgTokenSpaceGuid.PcdGuidedExtractHandlerTableAddress|gUefiOvmfPkgT= okenSpaceGuid.PcdGuidedExtractHandlerTableSize =20 +0x008000|0x001000 +gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableBase|gUefiOvmfPkgTokenSp= aceGuid.PcdOvmfSecGhcbPageTableSize + +0x009000|0x002000 +gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase|gUefiOvmfPkgTokenSpaceGuid.P= cdOvmfSecGhcbSize + 0x010000|0x010000 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase|gUefiOvmfPkgTokenSpace= Guid.PcdOvmfSecPeiTempRamSize =20 diff --git a/OvmfPkg/ResetVector/ResetVector.inf b/OvmfPkg/ResetVector/Rese= tVector.inf index b0ddfa5832a2..483fd90fe785 100644 --- a/OvmfPkg/ResetVector/ResetVector.inf +++ b/OvmfPkg/ResetVector/ResetVector.inf @@ -26,6 +26,7 @@ [Sources] [Packages] OvmfPkg/OvmfPkg.dec MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec UefiCpuPkg/UefiCpuPkg.dec =20 [BuildOptions] @@ -33,5 +34,9 @@ [BuildOptions] *_*_X64_NASMB_FLAGS =3D -I$(WORKSPACE)/UefiCpuPkg/ResetVector/Vtf0/ =20 [Pcd] + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm b/OvmfPkg/ResetVecto= r/Ia32/PageTables64.asm index abad009f20f5..9f86ddf6f08f 100644 --- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm +++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm @@ -21,6 +21,11 @@ BITS 32 %define PAGE_2M_MBO 0x080 %define PAGE_2M_PAT 0x01000 =20 +%define PAGE_4K_PDE_ATTR (PAGE_ACCESSED + \ + PAGE_DIRTY + \ + PAGE_READ_WRITE + \ + PAGE_PRESENT) + %define PAGE_2M_PDE_ATTR (PAGE_2M_MBO + \ PAGE_ACCESSED + \ PAGE_DIRTY + \ @@ -75,6 +80,37 @@ NoSev: SevExit: OneTimeCallRet CheckSevFeature =20 +; Check if Secure Encrypted Virtualization - Encrypted State (SEV-ES) feat= ure +; is enabled. +; +; Modified: EAX, EBX, ECX +; +; If SEV-ES is enabled then EAX will be non-zero. +; If SEV-ES is disabled then EAX will be zero. +; +CheckSevEsFeature: + xor eax, eax + + ; SEV-ES can't be enabled if SEV isn't, so first check the encryption + ; mask. + test edx, edx + jz NoSevEs + + ; Save current value of encryption mask + mov ebx, edx + + ; Check if SEV-ES is enabled + ; MSR_0xC0010131 - Bit 1 (SEV-ES enabled) + mov ecx, 0xc0010131 + rdmsr + and eax, 2 + + ; Restore encryption mask + mov edx, ebx + +NoSevEs: + OneTimeCallRet CheckSevEsFeature + ; ; Modified: EAX, EBX, ECX, EDX ; @@ -139,6 +175,46 @@ pageTableEntriesLoop: mov [(ecx * 8 + PT_ADDR (0x2000 - 8)) + 4], edx loop pageTableEntriesLoop =20 + OneTimeCall CheckSevEsFeature + test eax, eax + jz SetCr3 + + ; + ; The initial GHCB will live at GHCB_BASE and needs to be un-encrypted. + ; This requires the 2MB page for this range be broken down into 512 4KB + ; pages. All will be marked encrypted, except for the GHCB. + ; + mov ecx, (GHCB_BASE >> 21) + mov eax, GHCB_PT_ADDR + PAGE_PDP_ATTR + mov [ecx * 8 + PT_ADDR (0x2000)], eax + + ; + ; Page Table Entries (512 * 4KB entries =3D> 2MB) + ; + mov ecx, 512 +pageTableEntries4kLoop: + mov eax, ecx + dec eax + shl eax, 12 + add eax, GHCB_BASE & 0xFFE0_0000 + add eax, PAGE_4K_PDE_ATTR + mov [ecx * 8 + GHCB_PT_ADDR - 8], eax + mov [(ecx * 8 + GHCB_PT_ADDR - 8) + 4], edx + loop pageTableEntries4kLoop + + ; + ; Clear the encryption bit from the GHCB entry + ; + mov ecx, (GHCB_BASE & 0x1F_FFFF) >> 12 + mov [ecx * 8 + GHCB_PT_ADDR + 4], strict dword 0 + + mov ecx, GHCB_SIZE / 4 + xor eax, eax +clearGhcbMemoryLoop: + mov dword[ecx * 4 + GHCB_BASE - 4], eax + loop clearGhcbMemoryLoop + +SetCr3: ; ; Set CR3 now that the paging structures are available ; diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb b/OvmfPkg/ResetVector/Re= setVector.nasmb index 75cfe16654b1..bfb77e439105 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -53,8 +53,25 @@ %error "This implementation inherently depends on PcdOvmfSecPageTables= Size" %endif =20 + %if (FixedPcdGet32 (PcdOvmfSecGhcbPageTableSize) !=3D 0x1000) + %error "This implementation inherently depends on PcdOvmfSecGhcbPageTa= bleSize" + %endif + + %if (FixedPcdGet32 (PcdOvmfSecGhcbSize) !=3D 0x2000) + %error "This implementation inherently depends on PcdOvmfSecGhcbSize" + %endif + + %if ((FixedPcdGet32 (PcdOvmfSecGhcbBase) >> 21) !=3D \ + ((FixedPcdGet32 (PcdOvmfSecGhcbBase) + FixedPcdGet32 (PcdOvmfSecGhc= bSize) - 1) >> 21)) + %error "This implementation inherently depends on PcdOvmfSecGhcbBase n= ot straddling a 2MB boundary" + %endif + %define PT_ADDR(Offset) (FixedPcdGet32 (PcdOvmfSecPageTablesBase) + (Off= set)) %include "Ia32/Flat32ToFlat64.asm" + + %define GHCB_PT_ADDR (FixedPcdGet32 (PcdOvmfSecGhcbPageTableBase)) + %define GHCB_BASE (FixedPcdGet32 (PcdOvmfSecGhcbBase)) + %define GHCB_SIZE (FixedPcdGet32 (PcdOvmfSecGhcbSize)) %include "Ia32/PageTables64.asm" %endif =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63333): https://edk2.groups.io/g/devel/message/63333 Mute This Topic: https://groups.io/mt/75825050/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 Fri Apr 26 07:16:41 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+63334+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+63334+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 1595863841441824.1056301895768; Mon, 27 Jul 2020 08:30:41 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id eYkRYY1788612xseKQE6spTw; Mon, 27 Jul 2020 08:30:41 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.55]) by mx.groups.io with SMTP id smtpd.web12.58149.1595863840242348191 for ; Mon, 27 Jul 2020 08:30:40 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fzDUUsMb84f2Uc7bxK3gyBODctnr4LbNmFvjVuIQcV3loT2xnGxcpGc2YEs+uQF7O85rUlXmfIWDTU1R6a8BweA3W/0dMuPfdRkE/jRt/RSfuGrLi46FMWtIda35kQcJLIciv0TI/wC1URdGU2GJCzYeEWt/9aDUmr8VSlS3e3vlSC8pA6uLfxjYb8PIMHh5Ljd1myFGe+GIJ/qUugZTP55rPxqkMqhuRwuNKvQeWL7gM+b4lkIlUurH0+52v+4Fl19elhEs94032OMdD//xfgEKh6sxIAw8eiWs8DkaCJ9pmhQWZY16EZjxSdkjPCooBRg4Llw3DLP4YFF8P4+pqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JR+MS9LL61uEdrhA9WIjPAHChgJxbHnfKw/wTMqc9/Y=; b=S63eQIMsUCO0VBehE4di8hZHcV2drF0lJKxaeFV2MNuW/o0UJgn7C4j6OnV0NDcR02v2WRQyuxJrB9RpvjSkrqWh+/XquC3cL4GsNz0xD9Z80MKtME5USjT9Riy9vocpFrSiK8/QiSuEl7fayjyl8R/24Q9jk4WR5gBnU9fza1utWu1D+UQYFPK1jHTWQ9qy5vELufw9j/ROPl/fko9sH3ddnFmGdVwBQAt6r/xk6LfS8fJEhk8YavYcFZ6yMtXYeYLcvGAKmyr8mu1WXnKY0RPDwDSR4ccv9k2/tn+KtpD3pZL7n6JsFJNxOzr5iKkte/EW6sSFYIACiSyRm/Fbqg== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:30:38 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:30:38 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni , Anthony Perard , Julien Grall Subject: [edk2-devel] [PATCH v12 30/46] OvmfPkg/PlatformPei: Reserve GHCB-related areas if S3 is supported Date: Mon, 27 Jul 2020 10:26:11 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN4PR0701CA0048.namprd07.prod.outlook.com (2603:10b6:803:2d::19) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0701CA0048.namprd07.prod.outlook.com (2603:10b6:803:2d::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.20 via Frontend Transport; Mon, 27 Jul 2020 15:30: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: e96b020f-ba00-4c98-4812-08d8324203c8 X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: KbuLBJQ1C+NaYMu2GYO5KQ6AsM4kaSpnXmlkmH30uBEqGL5rwBaaG8PZID+SRr+61wgEgBxPjL7KyFaUHixil5kmpYDncyGySRVzy+LKrsumQmSxRfaY09+qqJzuhXtGJTGQPhzczsoOC4ltqA+L9w3lyg7VPY1j64YJkb4cJ6g6lY5/cv7lh6/9fI4fhF63lA1Gje8HVm6qpSz1G+capMV1qkMEbU7phz0QO+v5Fl16gxxvtIW1p1+KK1CB9FCrXaQMvjTMk5o35jBIwTlr8eiQ+2+WJ2XPI/V2uk2dTfLZ04yDuEJZzFwJMZOWq0HF5J5gIxQPQK2i1vZWnsSd26CNnHVOJzHGb2GHjzpvEmf8c9zopshPG+Huv8UlPcCCrKuTIsgd4orMe1X9gZmT/ploOsiIbHHnueGaoaQM5EiGv5MZsJqpbNJ7VrNzQpN3vkCLyEJ0yRCOp5g4N84VXg== X-MS-Exchange-AntiSpam-MessageData: +mOQAW+REQHYRJwU2zdQiPeMywn/ABWMLzrobMLkM9KPVLBUDU3j6Qr5pY7/z/tVCxoeAB9eIkXxfroipzp8REIjk49SATJznMjxVeRvy58ZvV7pHPxg2ktRf2EHP2dFpIETdDlso7k1ts+40cGaDYWeFFwzJdyifft6nM5AeKlskisnAlSWfPVkBPU+p8CMqWQyr2LJBAkJm/wCJm/h6IodIah2WbDyPKuXfJxdzqcFLuhcyGu4lJ7rvL3TZXhDumVGHwuWZ0Lbm85yW3ec8/8hHDa6my5qwqSTJL6lKhHhSozNEM5y1/Bilk0xGv9s2cIK1LaLBF64xO5lq6+x2MOozwbSMu3HkbrVapPrtq+ynnLuqY+SC4X6OIjV3aLqEhdbd3MisGrssC61DwtJjJNcyk+GzGt+MIqHOMiNaXOVuM4nobxQdfcs3mv5xVJalT+aXaiQ3olNeg3g0W4I/2T6+jqMqWoLLedOT+PLmx0= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e96b020f-ba00-4c98-4812-08d8324203c8 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:30:38.7072 (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: RKGt3R4KLigh8KQC+gUL0Ljv+MYwzeDjw9zd22u4DYvi5FSe4/wwbcYcn9N1ZGTQE7HD1anxhXCgLB7tRbJvVg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: W3uqvsvKpC2IBwhbjonJGCE1x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863841; bh=k/6Cj60WKUkfJ131VyKF1FTYgB9PDBAPR6dFFx7cKGg=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=aRLNHZ/FmcM03zf08BTYG930SQCktreREwrJnjg42nn4QzWBKu1naQEhx3wr/Q2U2Tn VDwKGPwc4cWAzOVYRNBqevV4EJ3tp1e2CmSbV7TeXMS3PNRK3EB6SAXJbXiASa40s/BXQ JTas7YqBZOHBQUju0XcFd285mDijPS874kE= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Protect the memory used by an SEV-ES guest when S3 is supported. This includes the page table used to break down the 2MB page that contains the GHCB so that it can be marked un-encrypted, as well as the GHCB area. Regarding the lifecycle of the GHCB-related memory areas: PcdOvmfSecGhcbPageTableBase PcdOvmfSecGhcbBase (a) when and how it is initialized after first boot of the VM If SEV-ES is enabled, the GHCB-related areas are initialized during the SEC phase [OvmfPkg/ResetVector/Ia32/PageTables64.asm]. (b) how it is protected from memory allocations during DXE If S3 and SEV-ES are enabled, then InitializeRamRegions() [OvmfPkg/PlatformPei/MemDetect.c] protects the ranges with an AcpiNVS memory allocation HOB, in PEI. If S3 is disabled, then these ranges are not protected. DXE's own page tables are first built while still in PEI (see HandOffToDxeCore() [MdeModulePkg/Core/DxeIplPeim/X64/DxeLoadFunc.c]). Those tables are located in permanent PEI memory. After CR3 is switched over to them (which occurs before jumping to the DXE core entry point), we don't have to preserve PcdOvmfSecGhcbPageTableBase. PEI switches to GHCB pages in permanent PEI memory and DXE will use these PEI GHCB pages, so we don't have to preserve PcdOvmfSecGhcbBase. (c) how it is protected from the OS If S3 is enabled, then (b) reserves it from the OS too. If S3 is disabled, then the range needs no protection. (d) how it is accessed on the S3 resume path It is rewritten same as in (a), which is fine because (b) reserved it. (e) how it is accessed on the warm reset path It is rewritten same as in (a). Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Anthony Perard Cc: Julien Grall Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/PlatformPei/PlatformPei.inf | 4 ++++ OvmfPkg/PlatformPei/MemDetect.c | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index 00feb96c9308..a54d10ba90d5 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -75,6 +75,10 @@ [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfLockBoxStorageSize gUefiOvmfPkgTokenSpaceGuid.PcdGuidedExtractHandlerTableSize diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetec= t.c index 3b46ea431ade..6b5fee166b5d 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -27,6 +27,7 @@ Module Name: #include #include #include +#include #include #include #include @@ -866,6 +867,28 @@ InitializeRamRegions ( (UINT64)(UINTN) PcdGet32 (PcdOvmfSecPageTablesSize), EfiACPIMemoryNVS ); + + if (MemEncryptSevEsIsEnabled ()) { + // + // If SEV-ES is enabled, reserve the GHCB-related memory area. This + // includes the extra page table used to break down the 2MB page + // mapping into 4KB page entries where the GHCB resides and the + // GHCB area itself. + // + // Since this memory range will be used by the Reset Vector on S3 + // resume, it must be reserved as ACPI NVS. + // + BuildMemoryAllocationHob ( + (EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfSecGhcbPageTableBas= e), + (UINT64)(UINTN) PcdGet32 (PcdOvmfSecGhcbPageTableSize), + EfiACPIMemoryNVS + ); + BuildMemoryAllocationHob ( + (EFI_PHYSICAL_ADDRESS)(UINTN) PcdGet32 (PcdOvmfSecGhcbBase), + (UINT64)(UINTN) PcdGet32 (PcdOvmfSecGhcbSize), + EfiACPIMemoryNVS + ); + } #endif } =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63334): https://edk2.groups.io/g/devel/message/63334 Mute This Topic: https://groups.io/mt/75825052/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 Fri Apr 26 07:16:41 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+63335+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+63335+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 1595863850803256.88612719104776; Mon, 27 Jul 2020 08:30:50 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id JGZkYY1788612xfhy7i6xz01; Mon, 27 Jul 2020 08:30:50 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.61]) by mx.groups.io with SMTP id smtpd.web10.58384.1595863848289444262 for ; Mon, 27 Jul 2020 08:30:48 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JOKO67lSyZ6/rF+mb7d7Ve/o8QiAbLMc+ZJs+BlI6doBFZQjP/mBvNKB9vBU4ZYEk5OKXM6WjC4f64ZX5s2NzNjgYwgkhXPF11QLP1n1CathSnpCzZUZ4R+KpSZ17KgX9Jv1IVPfOrfsIxcJ1DPdzfXzDkffbG028di9vvzhia/LD1IGpv4Ab5WSXyer9/2gS/y4T7bWo1pLjGxXbhOMuN1ylKA3CUiv9LyW6FE001jqa6l3mwKkAUcFa+LXIHc6JVDuJctSfVdBSV1pHqKQ5QSJ2zBfabxOq/Qc1Za7d65TyxOYLhwypxORQVeLfJs7IC0OTCBYwpAGAEdXnpA51Q== 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=FTwQOqZtSgveKyDVyv5Xn+OjC06eT2L6v4s746V/714=; b=g9bWAECvsSBEXWPtA/ZIyBsM7yq7DeKA/69TrWvsX4uW1KZcBWYo/NV+vSigJupw3c8Yerfz4/l+pB8rp4hsRr6quitPJ+61IEukiMS6jUmeASbyfWlXPSzlKus/xiJRAlcx0Wt7bK+YNgi1IURbpDrmXWMXE1SRdnunmco5bkTvsJyjhuQDLfqWx0Y6oFZpPZ0OAAamP91V7aa6R5VPy1f20ZIEiFciqVAxSw1bL87DyiWrsmqRMcBFKMUdJ9uBzy2WaEY9gE087OUfjvL9X1EDvCeAvUwpPt49HEU0GRMlwcwhHxkMXrW3NB5TOXydU/A/6rcTxNkG+ecwwbDY/g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:30:46 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:30:46 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 31/46] OvmfPkg: Create GHCB pages for use during Pei and Dxe phase Date: Mon, 27 Jul 2020 10:26:12 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN6PR08CA0030.namprd08.prod.outlook.com (2603:10b6:805:66::43) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR08CA0030.namprd08.prod.outlook.com (2603:10b6:805:66::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23 via Frontend Transport; Mon, 27 Jul 2020 15:30: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: 80d79d69-1a71-4e82-7b2a-08d83242089a X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: PRM3invJ2H5OhdDmEOMRqN6qOz5wbhx28mb9RzqNW0Az1xAPYC8dMcnNp1MhELsxd4rxZbZxb7zz+kiuqewL+85CwjwXvm7t+z9aeXifkb1bxpd03mZRm2VK5VqDhXldU2tKbKc9BC57CQbZwnNeBEEP7XMYfU1WQh+828mGQQ/poSf1jLQJmpDhD53JD/ymt1WlyOjgli7mgjcQkKJZ5G3J9Ku/997oeobuEifNmbLHrHy+PLPTL890x7zXtHGwIBfCbvOTBtWsL68OEgtB3ex1pEdvHZssMC6WDLjG7gWxScRN12SBGjl2hCm0RyzcKTUj0z/mMT/7RaBCq8gnLAB6trnFMwSOheCGH4OpGc/Z61wCdsJP59FPMs0XlONn1BtcG2jreDwmMOUE/thlem990ahHolv7uUTBV/XR/JMpl04TMDQHFuWDdxa0YW9M1Lvqxn20OkOzWZFLLtJTRQ== X-MS-Exchange-AntiSpam-MessageData: bAFkZk98kK2qrLEndIqiMm5KI5Tt7OeUrrs0zR/uZw4iKhNVGayJPWNFEorV96/uNomF+TNXVCY1DMmmcnrBSGBLq1k9L6rStR7iE6U2gw93NH1Yvq3jzAsF1xvGynj+8sJ2QUCBLK45oWPgXSbmxjZpXZnugyjwOQePLIJ0fFz2yMmWUYfYj1GUgb708JDkmTNr1Tm7NFSE5JfM1wwHVqTiP6BHzOlMZ9GtQeFHwrcGKiNoA2giSlQp0CeI4XIbWGRliu4w5Y7l8vNa3mcS6lsctKNZh8G8vwHxAI2g32qPMcSgV08abYGCmF76K6r3Ldq3WvldF/r7mhyoQu+8EsAQ1+ytb5JjhW5MdiRXHJHyiHK0BI+lcD/GMLelxOQYVFWrw462EfaaQ4JtZ6SCoF2u5ikDGujxRYpZd5ElXRRBwxqYbW14yXg5FO3dayeRt4GiGevzzsrv/Kg/uH23xaV+Jk61awcFsmj7ddQ6VPo= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 80d79d69-1a71-4e82-7b2a-08d83242089a X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:30:46.7646 (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: 3gclcxoSAwQU1AI13bkgYJ7u4m+I83fZAR+VlNLXWUg7noYD9L2GTQ/69iN3cw+1DxmT1svm+UsB1BJQ9eaEsQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: p6LYD8EEjYjZSmYCaIWiqGQ3x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863850; bh=UP+Ta0qVBxO3dFlWIytLIG3p31CTD2xrnIM1KlZ1S+g=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=aJ7mLTdF1EQMxtewRm7iA3OjEJ9EDK/YDQcYdQsxkGA7uDEUYUMdV2n/RYiKf5jYWxg i4PGvUbG5pKCceJavTZCMq9Efw+2+T5UK5wtLswue4gQGXJOX7EolZ42F4leo3eX/EszH 30yBR3Ax/qj1bE1VxS4cMMpusxsaY4a+EJ8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Allocate memory for the GHCB pages and the per-CPU variable pages during SEV initialization for use during Pei and Dxe phases. The GHCB page(s) must be shared pages, so clear the encryption mask from the current page table entries. Upon successful allocation, set the GHCB PCDs (PcdGhcbBase and PcdGhcbSize). The per-CPU variable page needs to be unique per AP. Using the page after the GHCB ensures that it is unique per AP. Only the GHCB page is marked as shared, keeping the per-CPU variable page encyrpted. The same logic is used in DXE using CreateIdentityMappingPageTables() before switching to the DXE pagetables. The GHCB pages (one per vCPU) will be used by the PEI and DXE #VC exception handlers. The #VC exception handler will fill in the necessary fields of the GHCB and exit to the hypervisor using the VMGEXIT instruction. The hypervisor then accesses the GHCB associated with the vCPU in order to perform the requested function. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/OvmfPkgIa32.dsc | 2 ++ OvmfPkg/OvmfPkgIa32X64.dsc | 2 ++ OvmfPkg/OvmfPkgX64.dsc | 2 ++ OvmfPkg/PlatformPei/PlatformPei.inf | 2 ++ OvmfPkg/PlatformPei/AmdSev.c | 45 ++++++++++++++++++++++++++++- 5 files changed, 52 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index f84f23f250ef..133a9a93c071 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -608,6 +608,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 a66abccf8266..338c38db29b5 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -620,6 +620,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 2a8975fd3d29..b80710fbdca4 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -618,6 +618,8 @@ [PcdsDynamicDefault] gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask|0x0 =20 # Set SEV-ES defaults + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase|0 + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize|0 gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled|0 =20 !if $(SMM_REQUIRE) =3D=3D TRUE diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index a54d10ba90d5..4742e1bdf42b 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -102,6 +102,8 @@ [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable gEfiMdeModulePkgTokenSpaceGuid.PcdPteMemoryEncryptionAddressOrMask + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbSize gEfiSecurityPkgTokenSpaceGuid.PcdOptionRomImageVerificationPolicy gUefiCpuPkgTokenSpaceGuid.PcdCpuLocalApicBaseAddress gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index 4dc5340caa7a..4fd4534cabea 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -10,12 +10,15 @@ // The package level header files this module uses // #include +#include #include #include #include +#include #include #include #include +#include #include #include =20 @@ -32,7 +35,10 @@ AmdSevEsInitialize ( VOID ) { - RETURN_STATUS PcdStatus; + VOID *GhcbBase; + PHYSICAL_ADDRESS GhcbBasePa; + UINTN GhcbPageCount, PageCount; + RETURN_STATUS PcdStatus, DecryptStatus; =20 if (!MemEncryptSevEsIsEnabled ()) { return; @@ -40,6 +46,43 @@ AmdSevEsInitialize ( =20 PcdStatus =3D PcdSetBoolS (PcdSevEsIsEnabled, TRUE); ASSERT_RETURN_ERROR (PcdStatus); + + // + // Allocate GHCB and per-CPU variable pages. + // + GhcbPageCount =3D mMaxCpuCount * 2; + GhcbBase =3D AllocatePages (GhcbPageCount); + ASSERT (GhcbBase !=3D NULL); + + GhcbBasePa =3D (PHYSICAL_ADDRESS)(UINTN) GhcbBase; + + // + // Each vCPU gets two consecutive pages, the first is the GHCB and the + // second is the per-CPU variable page. Loop through the allocation and + // only clear the encryption mask for the GHCB pages. + // + for (PageCount =3D 0; PageCount < GhcbPageCount; PageCount +=3D 2) { + DecryptStatus =3D MemEncryptSevClearPageEncMask ( + 0, + GhcbBasePa + EFI_PAGES_TO_SIZE (PageCount), + 1, + TRUE + ); + ASSERT_RETURN_ERROR (DecryptStatus); + } + + ZeroMem (GhcbBase, EFI_PAGES_TO_SIZE (GhcbPageCount)); + + PcdStatus =3D PcdSet64S (PcdGhcbBase, GhcbBasePa); + ASSERT_RETURN_ERROR (PcdStatus); + PcdStatus =3D PcdSet64S (PcdGhcbSize, EFI_PAGES_TO_SIZE (GhcbPageCount)); + ASSERT_RETURN_ERROR (PcdStatus); + + DEBUG ((DEBUG_INFO, + "SEV-ES is enabled, %lu GHCB pages allocated starting at 0x%p\n", + (UINT64)GhcbPageCount, GhcbBase)); + + AsmWriteMsr64 (MSR_SEV_ES_GHCB, GhcbBasePa); } =20 /** --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63335): https://edk2.groups.io/g/devel/message/63335 Mute This Topic: https://groups.io/mt/75825055/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 Fri Apr 26 07:16:41 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+63336+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+63336+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 1595863857196161.53577887896552; Mon, 27 Jul 2020 08:30:57 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id OxiSYY1788612xypiTyJEJPG; Mon, 27 Jul 2020 08:30:56 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.80]) by mx.groups.io with SMTP id smtpd.web11.58159.1595863856067914276 for ; Mon, 27 Jul 2020 08:30:56 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UV2hvQW52yKgYkOm2uNIt5JEuEi/N751DEARfyBi9z0bLLqQO6i6xN9Jo/TXFTFncbjuxdZHtF28WMycUOKMGfwIPkpilynfJxTjP77HecbIcMXYmFF8U3e1Zym0Nf9ZvAmGskL51gR3MFx9MWln0w5c7ROR+B1d3IEI3dH8RwXjeKb/3M2ESk8xGqdD0l2PRfayuC6iymFQzX0kbg4GDkn5uxca05WEJPqQ57f8nGHAlF4nvRctoAIDPGa3816MlTRCqm89wf2SuEI8khUQ2PFqBE7ohDsJWv/WBcfQwkZAQeS/rX082lfslGoQNnzDS3hEOlj6yjtd5fEidCSNWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LKE7+qHjsZIcvRUcMZufAvxligKtvF8CIKEGq/A8VMQ=; b=MQK6LEXiki6BpyNU0n8vUQtuVGEbJGtQOdnKC0QcW4h4gcrub9DeA78ahyhSZQVG0C+UtvHQxhD1Y63ADycd8n0b5Sx7RSi8nGTFuOMtrWbpOb+gweUn8vkHnmmWWGldlBfCWOlDy7u+u+R897VW9tqkbdtmqdr937y7w22d3gp8I9Uk37kRRB0RAqiQVqQ7UvRn455v5qOTg6kVkiMQEGDxz6sAj3smnYY3UxoLX4kMTCIKnAv8BSpA/u95vH+G0379ZaoCD8YsOkW066GlNcQgggkVEmwaD0LK0KurLDdLDLb6Ungesfsn1ZAmMDdoXyYVaXk8+A5eni8x/JFGgg== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:30:54 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:30:54 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 32/46] OvmfPkg/PlatformPei: Move early GDT into ram when SEV-ES is enabled Date: Mon, 27 Jul 2020 10:26:13 -0500 Message-ID: <2fa7386ea5277a5c0a833d5af240ac1b889f3884.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0039.namprd05.prod.outlook.com (2603:10b6:803:41::16) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0501CA0039.namprd05.prod.outlook.com (2603:10b6:803:41::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.9 via Frontend Transport; Mon, 27 Jul 2020 15:30: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: 5beea4f8-e9a5-430d-01b3-08d832420d50 X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: fIQxhrc8hMtdWeHu6DucogxregEiZhaEMJw3+v65wDjRAxQl4R5yTtFCmsAufo0tXQfFtKsQX7jW3YSyigVfqy9aAdGULzLzKg6kvFWSvPe9Z9IMXAgSZooyhgyUk0HBW/jwjfZAHDwFJItlkErM4xgdFaFsaf0xKZw5Nulk6bCZwNleHFD0bkh+F2zzLfiPta10xOoEXQNDUf8sb8i2AUuczwbJFtgbu8aPnNUA8o7GNsu7RX2kJsrbLdmCP4usbnyVOt/g8hEZWVXXN6VEEEZVfR+xb3/PwgYKrIZbz2dQDZHB6JXje92J/hX6zDw4zdUJqTRc21yhYOnayNSs1hP1cHjgs7MzP1G+kjrd5CwpD08T+nomSe+CMZdw41tDbswAAo+6iJkfRogUMzMPB5etnMe0xF9GsgA3SoPdp3I/GVUEu50TQhfIhL8t2HsWgVa7HuyBp2UVfe2XgrBSwg== X-MS-Exchange-AntiSpam-MessageData: N3iuoC0c3buBF0H/uU2SNM005In4MpBUU1LExAjCfOlce0DUAg271Y5e0rssMG/dSYRUAjisoNgJaa7NA0Rd7/lHwEw1E3ANZtDl+rIJZ3XlTkPRsxGPugBxQTfKazQoLM1jAttg7eZjrx1Yri2Ow979Qk4FAJ8u4VthuQr4aAQPr5wPYDkunXKps4mqhUIJCxK15bgZ5yIuTHURAhOVpqiGL5BLBDMOYKBVNd5xiLqjeivjYX3QA9smsIhgd633ZSvLEhEmYubt4kcHaBgG1Ttns9PZlVI3De7F/LEl3AfznWU5grgH9WgKNuPvF8Thk1kfUdjhLoxVYsNyYjz1ce6q6KoK37m+U0gMAayaMbY0MbV7i9YYsnlC1ADw31BUt9mTd2g//On+/gK9KrJ+DslQW+AeV+20QLn1j4hDUzRth73MWdlGpP07X2UYQfLLfDO/cE6QLwNkUqole7QvMMHNDgPKztb1FsBWgRlnRes= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5beea4f8-e9a5-430d-01b3-08d832420d50 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:30:54.7051 (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: vuExVB6TUNrmDSt/ayoLElFIHbK19+of+e68p7J0LO6tOWfAYbrQesq5xSU5tB5ZLFPnvOkVVyq1v4YmwsVPXQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: 6NQmiOKOCRuvi4RkOgzKiAJ9x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863856; bh=PHb1VwMm+zDlZAdqGCOKeQxCnKDEuFWCU/CmmTm6bIg=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=PGmGwffc3xDYUpjAbLugFLwOoqXd1qJcIwJYiAbqitGwjBJ1vs84CdcXSCDI+73r4lY bXs/U6zYxhNOfEco95UQHwik1hqtzIkpwYAcEd4HN848gl2ozpMbogrEa2f5gFVPb2Qf5 o36/JKu+zgTna/3S7UswquYwwORphKcWa20= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 The SEV support will clear the C-bit from non-RAM areas. The early GDT lives in a non-RAM area, so when an exception occurs (like a #VC) the GDT will be read as un-encrypted even though it is encrypted. This will result in a failure to be able to handle the exception. Move the GDT into RAM so it can be accessed without error when running as an SEV-ES guest. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/PlatformPei/AmdSev.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index 4fd4534cabea..a2b38c591236 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -39,6 +39,8 @@ AmdSevEsInitialize ( PHYSICAL_ADDRESS GhcbBasePa; UINTN GhcbPageCount, PageCount; RETURN_STATUS PcdStatus, DecryptStatus; + IA32_DESCRIPTOR Gdtr; + VOID *Gdt; =20 if (!MemEncryptSevEsIsEnabled ()) { return; @@ -83,6 +85,22 @@ AmdSevEsInitialize ( (UINT64)GhcbPageCount, GhcbBase)); =20 AsmWriteMsr64 (MSR_SEV_ES_GHCB, GhcbBasePa); + + // + // The SEV support will clear the C-bit from non-RAM areas. The early G= DT + // lives in a non-RAM area, so when an exception occurs (like a #VC) the= GDT + // will be read as un-encrypted even though it was created before the C-= bit + // was cleared (encrypted). This will result in a failure to be able to + // handle the exception. + // + AsmReadGdtr (&Gdtr); + + Gdt =3D AllocatePages (EFI_SIZE_TO_PAGES ((UINTN) Gdtr.Limit + 1)); + ASSERT (Gdt !=3D NULL); + + CopyMem (Gdt, (VOID *) Gdtr.Base, Gdtr.Limit + 1); + Gdtr.Base =3D (UINTN) Gdt; + AsmWriteGdtr (&Gdtr); } =20 /** --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63336): https://edk2.groups.io/g/devel/message/63336 Mute This Topic: https://groups.io/mt/75825057/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 Fri Apr 26 07:16:41 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+63337+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+63337+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 1595863868278103.5659875667692; Mon, 27 Jul 2020 08:31:08 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ZA0NYY1788612x8joqTIt4K9; Mon, 27 Jul 2020 08:31:07 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.70]) by mx.groups.io with SMTP id smtpd.web11.58162.1595863866504623470 for ; Mon, 27 Jul 2020 08:31:06 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N5zM+11XcSgEhm40ujkXSFl9VzmnAhJMFwfey0RX8CCf5mET+sVXuYlM7/wzM8/4lq/Tw6ZkUNl5jGWXRaZ9z21sD/sTeP3smTeTTvLTNVleLZ9uJ+rYnXKb1LQzlk5w8eqiDmlGcUpBu5PHxp+lLY7RTHLmlAL3Zg/Txxob999d4x6oyWx6HG06VVIlWxhuKZmxArsS03tNQJUQ+XohRvWZ9+jlFCEvkQ+hzFMClR8SLanvZ+vq2/crFIarAo1eeYmZWjzHLJdhTBcccULgZOYnn69448rEC0Ua3pWTwho7KU6tUI7HK9aNHjC5dRww4g+Y7CWSVgUZuqzjpVSApw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RmbqkIxYiPPEKoCZtNux7cvM35+H6P1bYXxGk/GrTms=; b=UbzHbNXIC8NZ5LeF13btBUTtPnPrOXwsFnMKAZUWroE1tsTtgTCtA0yY82YtUX6nXF8sidcikwINF3/531IHrZh7gyigqVKKL4lz3zscNLl+rBmitfKnscAbczly6jXuAmjMs/mckJRNdkodHioACZkT5K9B8WXGIcn6f6EdWbFJcOYruCJDxAFLT2siyy3dpv0RI3MUBhIbPnbILle57oSgTfwOzPORN+NGFKAG+5BZL/XGDTUAY7Ik1BrEJ1ni3TiBlKVmOgkl+TXR5SeEx5igHEmsv/Mme1S+4KaJTAiY3Mpd1q1BzLq/sxucYEkR97eeZ92F151GL4EEthNKXA== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:31:02 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:31:02 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 33/46] UefiCpuPkg: Create an SEV-ES workarea PCD Date: Mon, 27 Jul 2020 10:26:14 -0500 Message-ID: <52b339b9a9359639bcfa3d4b5b7b18d7b48faf4c.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0201CA0064.namprd02.prod.outlook.com (2603:10b6:803:20::26) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0201CA0064.namprd02.prod.outlook.com (2603:10b6:803:20::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23 via Frontend Transport; Mon, 27 Jul 2020 15:31: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: 99f5c9cc-20a2-4143-fc67-08d832421220 X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: qlLMJ0V/qRE7SvDY998KJ2HQTsQIJ6gNNlRaDAEQMw6jPOEApDFcobgBN/lRinCvGU8Oe/ovtYZOvB0Te2fSQxBzwiUwE5eONR/5uOYsUcqe/rcK50RMU5O16dSREMTqf6BZZA7Ro7vdfcbMRYgbWVf3xy8xe6Jn+0klF9w38280SQNbZu7JKPG3RsBZIx1EFeEo2hgM+Y8FfbXwqvRGatotzt/z3MekIPkxOL24vsx/M4+F6MOaedFGOUFPPLv2DkFmWPdt7KY3MiPhYyduZWctPFiMb35D0BbL7O+k/LYLH57mj1rrEl/Ja8722C5+AQQsPrHOqeL8pxWfpkelYgwIHX51jeJ6GchkDr0MbjOPcRDL7Qr+c9cxkG0269oTfjm5grPOFtoZxSkwqjYoUYjoXPd4MxHxJf/lVJXD6a78BwmUu9jZB7/GB8mNBF0hHVskRvDN1A4Jofrvj0i6Ww== X-MS-Exchange-AntiSpam-MessageData: MAvrcz8zKeo7F4UbPBaNNnwBvFVENNg99kjWEwqkVnnrB6B4O6QeIDBwufM5kF0mbPz4wDl5L8252o5X9ZVYdA0dITkj2q6zakS2FRaWYEFtV2BCV7RoU6tNUcw+HtcWry+OeAgENt0NBnoF9l2y9obR9sj1WPoSBGGHGAwLGv1h4KOKhnzQi3A0GMKgJ0xCy+oMjMtnofrq1pwVxU+HjT9U8H9eIk8i8VsGvcbsuf5xvVyY1z8/VF/7bAK2YGuW5PDFOrCYC5SMMKwRQT85DFMYnq1V6FASpzCt5KPvFH3j3r/tET2Iu67j54xaxfKU5jq+PHEsP1D1JptApXmcXab0xwB7F7ggN+0lcm4TpeEwidl86DOk/pRcZTpJAci/Cd5K5YDYr4UyNW58XwPW0fjFDTlrAwxmM7tZIzVkG5wdA5rKfAvv4VCbG7WvKL7MhWWSn1ObILeomRP1Kg+lT2cW69p2lDxzSUQfOmL06B0= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 99f5c9cc-20a2-4143-fc67-08d832421220 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:31:02.7646 (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: 8ZNnlKdxZ5zX8ARBFdGBsfyv21UXAFGXV5HqWiqqgZT9WfhMFg6pxx6tVBmcZtMWxYVU/mmfL9jqZ+EPgz0n0g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: EnXm0Kn2G2NclG1bBJmZJoXtx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863867; bh=3CJn6bfams2j5YBDwxCNCwxuFN3HwJz4/DPjQ0iRqQ8=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=obZEEF6s3Dyjpm38pmklZgQafwk4rbl5OYWbRhAloSXSALwrGcN88IR/2vpO5HXkQBy HoTusmbZ37wMvy6SZ3qrQBS9Z/ouVu2+7JdkiDOGIJ1Jr1e4hmA23Eg6Mg4MI1gp6tVEl gKOgVrUlvj4pcgifHqfyGKWnv4/jDPe5KKM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Create an SEV-ES workarea PCD. This PCD will be used for BSP communication during SEC and for AP startup during PEI and DXE phases, the latter is the reason for creating it in the UefiCpuPkg. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Reviewed-by: Eric Dong Signed-off-by: Tom Lendacky --- UefiCpuPkg/UefiCpuPkg.dec | 8 ++++++++ UefiCpuPkg/UefiCpuPkg.uni | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/UefiCpuPkg/UefiCpuPkg.dec b/UefiCpuPkg/UefiCpuPkg.dec index cb92f34b6f55..8c614f9b42bd 100644 --- a/UefiCpuPkg/UefiCpuPkg.dec +++ b/UefiCpuPkg/UefiCpuPkg.dec @@ -161,6 +161,14 @@ [PcdsFixedAtBuild] # @Prompt Specify the count of pre allocated SMM MP tokens per chunk. gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmMpTokenCountPerChunk|64|UINT32|0x3000= 2002 =20 + ## Area of memory where the SEV-ES work area block lives. + # @Prompt Configure the SEV-ES work area base + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase|0x0|UINT32|0x30002005 + + ## Size of teh area of memory where the SEV-ES work area block lives. + # @Prompt Configure the SEV-ES work area base + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaSize|0x0|UINT32|0x30002006 + [PcdsFixedAtBuild, PcdsPatchableInModule] ## This value is the CPU Local APIC base address, which aligns the addre= ss on a 4-KByte boundary. # @Prompt Configure base address of CPU Local APIC diff --git a/UefiCpuPkg/UefiCpuPkg.uni b/UefiCpuPkg/UefiCpuPkg.uni index f4a0c72f6293..219c1963bf08 100644 --- a/UefiCpuPkg/UefiCpuPkg.uni +++ b/UefiCpuPkg/UefiCpuPkg.uni @@ -281,3 +281,11 @@ =20 #string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsIsEnabled_PROMPT #language = en-US "Specifies whether SEV-ES is enabled" #string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsIsEnabled_HELP #language = en-US "Set to TRUE when running as an SEV-ES guest, FALSE otherwise." + +#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsWorkAreaBase_PROMPT #langua= ge en-US "Specify the address of the SEV-ES work area" + +#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsWorkAreaBase_HELP #langua= ge en-US "Specifies the address of the work area used by an SEV-ES guest." + +#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsWorkAreaSize_PROMPT #langua= ge en-US "Specify the size of the SEV-ES work area" + +#string STR_gUefiCpuPkgTokenSpaceGuid_PcdSevEsWorkAreaSize_HELP #langua= ge en-US "Specifies the size of the work area used by an SEV-ES guest." --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63337): https://edk2.groups.io/g/devel/message/63337 Mute This Topic: https://groups.io/mt/75825061/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 Fri Apr 26 07:16:41 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+63338+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+63338+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 1595863873314995.4826532905704; Mon, 27 Jul 2020 08:31:13 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id RLUKYY1788612xPl24sAkJQi; Mon, 27 Jul 2020 08:31:12 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.76]) by mx.groups.io with SMTP id smtpd.web10.58392.1595863872067866343 for ; Mon, 27 Jul 2020 08:31:12 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EY9wSnOZnM1gx0RdRSPUk0foa1U98+linKTSOLWeNVjetg/3EW9hUvoFFCMDchz4Fin5KvU2nUmlvYSvSlAuOJ09kgia0G8oVCXo4+BRpaJLfDZipAo8N8WeSxy3SI2cI/ddACJJcs6IgoveLTLAEbJSSihsguYM1MvUrDRi2Y0egwwTtqwbYPMdKC5jDAX+1CBbT9cj0zaleB6MBPZ7Bhf3ew9popmlMZcrM/CATeHGSQiJPAUSO8KxrpYzPdR4Ccuw2ilqTdu11nOjoBTd3b275y/TsivRPqNXPNRHKrpYBB9rC3k0Q8ySUxrk7ibTayrPotoLNLJ0HlsPIdEJHQ== 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=TjAY63iLn0C9S3DzH549SsJshW3SZE3x2r3RtZTyabw=; b=BEuT3owGiXnsVyonZOGZPaBRFyYnCZW/jf5qI7JHhmbFI+RmbtMvL0yFT12na5kzGqLBlVTVbnguiBjNQYRdmDdlWKVGwlBOpjGfDB4gg/oXcs41FP7dbDp5R5zt3F4Ov4oAKfs3nQcLGiiHvtZOq219FKjxhfMS+HHGVDxeUifF5MGTCzuQG54dJ0rkdmQtT6wmS1vc9HTaeYV9ZoHq+e51nxf7W0KdaPjTgKZi/IQJ//5MRpmmJtWFICNkJPlYLI58Ef+qN2SPIpBZZpVC65/hGSkhj/RCG//8fvv3kjh/b9SR1j6oynRXLUZTED3ama7soy5alOa5vse6w9TEgw== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:31:10 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:31:10 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 34/46] OvmfPkg: Reserve a page in memory for the SEV-ES usage Date: Mon, 27 Jul 2020 10:26:15 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SN4PR0201CA0054.namprd02.prod.outlook.com (2603:10b6:803:20::16) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0201CA0054.namprd02.prod.outlook.com (2603:10b6:803:20::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.20 via Frontend Transport; Mon, 27 Jul 2020 15:31:10 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 740f6af1-9730-4ef0-416c-08d8324216e2 X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: mCDyFpmlzOOLAX0Fm0mhHL8MntEUXuwzSGjLARxsnNkzoIvn+h4kiSfJPSiuhZikhf6cZpqEE34zb6iiWI7jrFhf7TI4LkNY38e3nLSXCkeD/+FL+flEA6hrxg00cy7LkSAcT7VDuFLrkbzYmMFAGYhnQWwS74QZfxwH2ZtwyvPLmCuLjSX6YRd32VnL6cfnKd/jZNh2rIsS6rdfl7YWzgvE5H/y83cYOwVeH4vXNSYC00Rhzxtjw803N/4ZFd14PTenDTaAczeFC2VFY5q/UKrO6eQpMntr/OkHEyc7OAw+eGCX76Q2QDf2WSqE6LhSJxtDI94M4FPxU2VrdK4p4EhJAZgK54hHTKUnZzgkScT2irlGU5TpicT5J7/fn2erhmNdKVNZfOFXz6CsHQktsvwQ9cO+tzYnKAJbvzC+KXn5mydK7U6GyaA/4/fp21hcVGOZ1UZ/8flGou7isDSOyQ== X-MS-Exchange-AntiSpam-MessageData: WzJV2ZO1sm93BspP2qf08KoZaSuFI+Ob15anLs924v0+oNZTqaWvGG/B2qx7G7UTlZkvpG22FmNko6gzFr6xI74Fh4hLTpHvsEVKzu7AxvjVka07tScC6fkiUo82NiMMyP6LtLSRRhR36Rg4DGAbv5r5Wn495Y9YJ3Uf8NaKj60ioVHvOafVppbc1eqw5p3MNb1ofbs1MyHSiSqHIO7dBuQHzFo9zEx60Cpmz7rfUZN5HN6gVXT9ivXRqbC4j1e/dFK+0ujo/T1oofCZOlgR/yEoFSpJBiHDbYf1xqtJT6l7jqKnrRIndU4JVWt+jLjQVeATe+7UMuE1EnK/6t/v0Opb2e20XgDsL0cxPZLhrcv/FwR40SR+j2VHXYKHM22uuo5PQt04d9s7iXY780s07M9nifCSc8kxgK52JRbbUzjlkCD4KlSQqqcTzt+WXM6PeUyiqGdqIhOVsB5c7tT63pdTSRPyF0OgQFKdUUlQ7Ss= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 740f6af1-9730-4ef0-416c-08d8324216e2 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:31:10.7561 (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: zD+sPHBAn9ksfXVAjCKryBFPks8U82F5as9I84Z/DwrUD5g4iuvxNJugwIN+hcoBR7LZr0z/RrJXNRBn693Y2w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: TDmRQw6h33Nt8SqPCagY0x6Gx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863872; bh=PQWZzV6t+vbzmT12kXYQGu/S7UATqyxT+r4QL1xG5Pw=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=auMgc2W7gtMWQvMFfdlnAs0h/7qwWv1zaxNr7+NACbXZBtplKAgrDXpQ7cCZwVtE54l 1V42CQSwwoyg0G1HdCJv1AqfYrvhOEdJna0lifizCwo/2vXe5ZsRgJ9g2ZQoLukU6N/m6 9Hn+3E2AQ3mBXnqxUKizXdgVQJ73sf2z0xA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Reserve a fixed area of memory for SEV-ES use and set a fixed PCD, PcdSevEsWorkAreaBase, to this value. This area will be used by SEV-ES support for two purposes: 1. Communicating the SEV-ES status during BSP boot to SEC: Using a byte of memory from the page, the BSP reset vector code can communicate the SEV-ES status to SEC for use before exception handling can be enabled in SEC. After SEC, this field is no longer valid and the standard way of determine if SEV-ES is active should be used. 2. Establishing an area of memory for AP boot support: A hypervisor is not allowed to update an SEV-ES guest's register state, so when booting an SEV-ES guest AP, the hypervisor is not allowed to set the RIP to the guest requested value. Instead an SEV-ES AP must be re-directed from within the guest to the actual requested staring location as specified in the INIT-SIPI-SIPI sequence. Use this memory for reset vector code that can be programmed to have the AP jump to the desired RIP location after starting the AP. This is required for only the very first AP reset. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/OvmfPkgX64.fdf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf index edb03b5464d4..8da59037e5f0 100644 --- a/OvmfPkg/OvmfPkgX64.fdf +++ b/OvmfPkg/OvmfPkgX64.fdf @@ -82,6 +82,9 @@ [FD.MEMFD] 0x009000|0x002000 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase|gUefiOvmfPkgTokenSpaceGuid.P= cdOvmfSecGhcbSize =20 +0x00B000|0x001000 +gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase|gUefiCpuPkgTokenSpaceGuid.P= cdSevEsWorkAreaSize + 0x010000|0x010000 gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase|gUefiOvmfPkgTokenSpace= Guid.PcdOvmfSecPeiTempRamSize =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63338): https://edk2.groups.io/g/devel/message/63338 Mute This Topic: https://groups.io/mt/75825063/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 Fri Apr 26 07:16:41 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+63339+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+63339+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 1595863881653399.44064108316263; Mon, 27 Jul 2020 08:31:21 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id uv0sYY1788612xmilpt57vxu; Mon, 27 Jul 2020 08:31:21 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.73]) by mx.groups.io with SMTP id smtpd.web11.58166.1595863880275543448 for ; Mon, 27 Jul 2020 08:31:20 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FRMgXm3f1BsQkPM2297Y4+vi7XsnscWdLs4xT/P4obiLCoM3yqq2S5zJ4ov/pQTWEMPm9ugJrSHGD77oZPO2Ri0MhPIFfZuUakzK79AC+auVX9PzoHHv0+MAxSACYWtgPkey9yvSRm+HAx+sFvrdBoqytZD+y7hMddzFzbnvTFQPs/VDrMDtJ7DpocETzRRu84KUiN+KkoDhylIQvaQcRKkufMyW9g4raYQ11H4bU06o7J3p+HISBbJ5YfrJ7jfbW92u4kVv5USDFi3sk/7az0i8Wxo02+g3BEKwbAbPP5AooL888HMyuyRtP9/rZ7+NgC0tXIKgdmu/AcWeRZ2+EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JkyhLOofvIbow8VdM+XsfKiaUSck6a3v3S8jdpNjfQo=; b=adc91n3SLDAZ/UMSdgMOXQOPe9KwM4p8pBsJPbWs/v/8GI1mZe7vdx6oO5WdyhOthTqUHfKrc/xQVbs8YJmehxKl3w5P/Kyd6Xd0CPJiKZYFceaYq6njkrrE/pLWy1wSrwjqSmTgH4ieZ0594tTy0X7QvSbydo7kATIqqYupCkzi4ujAJOZyyAJoWw8kZ9d7rsfKQdnBaOZY6mB0Gd9+5qEeEdZxeLl70DorCievXTDiJ27iqkzGGT+sceU0H0zS5SgZSqVdna8gAiX9QZuwIXXmz4Kz6RHRB3RNpVrT1Pn4HwAYyLCSihDRYzfjSbibehh5D3Q+dJUAkTEdweWNnA== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:31:18 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:31:18 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni , Anthony Perard , Julien Grall Subject: [edk2-devel] [PATCH v12 35/46] OvmfPkg/PlatformPei: Reserve SEV-ES work area if S3 is supported Date: Mon, 27 Jul 2020 10:26:16 -0500 Message-ID: <6de8f3220156163493b3614eb8c6e63f6d1d3095.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN6PR01CA0008.prod.exchangelabs.com (2603:10b6:805:b6::21) 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 SN6PR01CA0008.prod.exchangelabs.com (2603:10b6:805:b6::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.20 via Frontend Transport; Mon, 27 Jul 2020 15:31:17 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: ca996c8d-6fdb-4473-4dcc-08d832421bab X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: e17N9c5UYGCZgv2BGzocYmyNeHmO6D4vwMO5Jg3r2p9iSjw4G6zjYEbb0PYkkltB7RIUIzfZyGOsl+wCYYcxYoh+FIk0tSXy2+LSi4aHx/Ex5WcMdHlyQfmaeFY64c3PZiRfdY/bVU3hG8+8lHZtUJmwihTMfMpTHxWoLEfCEDBehc175RiRxZvfaYhd3/bNqqd6m20wDSowmBe/4zFPmSHBZOAkoC0sC7EMcS0w8kzpvgpQCqaIsSye5dlXraEZ5vAQFhyqNZJdK7ijcvz3MWZ2Ypx+DJT0JQjaVMhU1DZ7UnSJ81eLVS0KpsjNni0b5AosvRmV0VC/V4+tIsXZJosTdOPoVrGE5YMMyrMkkMooWC6GOMSdFoOeAFRmKBSZ+UdnbmVdP/baKjLrH0dX8PN1ljG7jDchAKrmEGxwdyXnKvBtTmZZZ7cSdu+6a2m/RxSlMqt3KaWGkuiaaMITkg== X-MS-Exchange-AntiSpam-MessageData: 7e+HhUV2LhOjkx/hr+EJzH30ha+9ktrrRH2WCGem0kFAw0Hx+PekePWBXPHfaSVF1sU5wAr/t0jmbUVdmroVoubKp9A282rIOdW2LbPSpuN2WN3AYbsd4VEBwYE1Tufihzhq7HfXmOhleuvWSL9MEioSQCXGZJ8H2o3/A/iYtgsVu0NVQ0bZpp8/finU/TIRsJZKiur0j0T9MeioutEzWUrFWzv2swc4x4CwjNEqI5zef9tfuUbGHLfs62HNH+gunDKSgnEkd4jEI5SI9vGqslgG2DSblLZstRTNj50AymeoGjHDCxR3Orm5jMGoqadDX35NaIt7cFdT17IvbwxHzHDUK88qfALIXJ0DQeY5/DwONCBSXymPaUt8hHiBMDeu6+F9BAt66j5/t5JOk6TtVCeYVwzOcwL+0rSpCWv3hmPNx1m3OfWAwgUWk0vPgRwJ0VaXHxo0AAzzYgyM03rOmEE/31/g2wfKpO5bIvTkHws= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ca996c8d-6fdb-4473-4dcc-08d832421bab X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:31:18.7636 (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: a+4oo+HLRmPl8N6k3yjQ6UfM5EcvGCrvldBdCOqTxm17MNysakyOXK2o3yW8uBErOwySyG+opXesFYSsK1zcMg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: lMacujYW2jgC0ZE8yb8KKG4cx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863881; bh=5bBMS9xo5yMtOvg95eafPUjiL/VwEBJLT+6JsEk/Wlo=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=mhfWVRauM0agiJi3mj0zMWqHAUB5IF2JvaR0FNnPxm2LOdhcKPHb8d0DYrio4UEDnP/ MSLE78w6hFKYROSHOQFnNQY8BRwoV5ekNpdBvgSJnhWGG5OAQcOWZNUL4iXuBpfbFb4GK ug+DS/b/8fZ1yDqH/3qMl0lW3bfZooWGtTg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Protect the SEV-ES work area memory used by an SEV-ES guest. Regarding the lifecycle of the SEV-ES memory area: PcdSevEsWorkArea (a) when and how it is initialized after first boot of the VM If SEV-ES is enabled, the SEV-ES area is initialized during the SEC phase [OvmfPkg/ResetVector/Ia32/PageTables64.asm]. (b) how it is protected from memory allocations during DXE If SEV-ES is enabled, then InitializeRamRegions() [OvmfPkg/PlatformPei/MemDetect.c] protects the ranges with either an AcpiNVS (S3 enabled) or BootServicesData (S3 disabled) memory allocation HOB, in PEI. (c) how it is protected from the OS If S3 is enabled, then (b) reserves it from the OS too. If S3 is disabled, then the range needs no protection. (d) how it is accessed on the S3 resume path It is rewritten same as in (a), which is fine because (b) reserved it. (e) how it is accessed on the warm reset path It is rewritten same as in (a). Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Anthony Perard Cc: Julien Grall Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/PlatformPei/PlatformPei.inf | 2 ++ OvmfPkg/PlatformPei/MemDetect.c | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index 4742e1bdf42b..c53be2f4925c 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -118,6 +118,8 @@ [FixedPcd] gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaSize =20 [FeaturePcd] gUefiOvmfPkgTokenSpaceGuid.PcdCsmEnable diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetec= t.c index 6b5fee166b5d..ffbbef891a11 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -940,5 +940,25 @@ InitializeRamRegions ( ); } } + +#ifdef MDE_CPU_X64 + if (MemEncryptSevEsIsEnabled ()) { + // + // If SEV-ES is enabled, reserve the SEV-ES work area. + // + // Since this memory range will be used by the Reset Vector on S3 + // resume, it must be reserved as ACPI NVS. + // + // If S3 is unsupported, then various drivers might still write to t= he + // work area. We ought to prevent DXE from serving allocation reques= ts + // such that they would overlap the work area. + // + BuildMemoryAllocationHob ( + (EFI_PHYSICAL_ADDRESS)(UINTN) FixedPcdGet32 (PcdSevEsWorkAreaBase), + (UINT64)(UINTN) FixedPcdGet32 (PcdSevEsWorkAreaSize), + mS3Supported ? EfiACPIMemoryNVS : EfiBootServicesData + ); + } +#endif } } --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63339): https://edk2.groups.io/g/devel/message/63339 Mute This Topic: https://groups.io/mt/75825064/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 Fri Apr 26 07:16:41 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+63340+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+63340+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 1595863890433889.4167072826948; Mon, 27 Jul 2020 08:31:30 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 2ukqYY1788612xenQVJ1agSb; Mon, 27 Jul 2020 08:31:28 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.41]) by mx.groups.io with SMTP id smtpd.web10.58398.1595863888139131701 for ; Mon, 27 Jul 2020 08:31:28 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DVJQzwbyktxWMempeFJEuPoXGHlQlLFCQOhLh326ztgXQzijdYElnS0TyuwV+52JNCc14dGI6TV/DLc379bLTYO3Y4YXc/AVAUurPeaTApO7j2MSlr+W6fYVGdjRfHSAKlERUnIjnJmpZk+NJNUYeEExNLf9bLtmbg5rki8KzSus364z4uhnZIVOr9JoFPSaCQvHJ4dXWBrjLiz55IDb3dtiLwZFjiqyX9QI/iI5uyHk51lXWma8dqPNBaSO9AqLWalV5DgpXMBGQdPh2rLNGH+SDLmyeWtSxwBXu7+uAW7VhywD/OTKPx9/+DCRX6Mk95cy3Aw9BWjGutDkpS3C7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=TPNpIjuNhjb8J+fWbM5hVjQ7IHF8lsFxPXU/EZJhZFw=; b=Dlpeoho0fDyow1X3rm55H70FnoWntWV3m2bhrC4R8zx3uI9KG9Mo8BpGJuddyOByfYlscfz752wwNuH5hUSGdMpuaJdppOeCZQY2R5fODq2nusQ3E+73AyUoR45hCTg/yHcTOPjAoPAtFJ3wdT7jFkIxpQ1MgyWcKstXHxslUmmpEZsEjjK9G0uj9k0mJTVEFbvzqijBVz2gRykdNUfDs0XgBN6GEvg8vTE4dkGWv1b6WCAopkn28Gnz+g26SAHm/spkhr/gRi45OMFFkpmRwTRTiCV+ZJGPeUF5ycbD7A3ZdWTbQTecnN/aJOhJsZ68Orc8Tz9YDc0LQypmoJbTow== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:31:26 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:31:26 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 36/46] OvmfPkg/ResetVector: Add support for a 32-bit SEV check Date: Mon, 27 Jul 2020 10:26:17 -0500 Message-ID: <5c6ba31e3ac224d7e9c430dbb944bc15982beaea.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0114.namprd05.prod.outlook.com (2603:10b6:803:42::31) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0501CA0114.namprd05.prod.outlook.com (2603:10b6:803:42::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.10 via Frontend Transport; Mon, 27 Jul 2020 15:31:25 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: a505af86-7bee-4ded-68af-08d83242204a X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: rgF5LK9SdmPWJtSYfZ/fiUMWIhUTeQf/YN7evL51ZgXLgXnpW0Pwiuv7q7LaXoxGGegX+DUf4Ezi4D1y7vg0bUHO3VsfkCsE0+9jGG92s4qTbIuP42TIhIS8HTnCINW6UCA/mVQ4rdaHCkDWS+YqAJpe6t/KuvAttOSpZDOgi/VUFY0nq2yciestVuGY7GqZRmS27t1TIqaeLBag5x0lyt7n4EMKh2Gq2ZpVA1nhJtQpxjHPEijPw16JauZ32KZntloH+XcqDS8NtKtKVdDOG9Xi5vI4Y1zAPjA/pZ06SZokkswB2I5niepj0FYi627YAjgy2fBR8PSzukNRm6NiaUX4Qsf8pJpKzA8BVSurYXOkPPM7dfkRqcnGRG74rHH9kHDEYIxwkYwulc5f8H3+9QuptleQOCyHTGXIDlsF4u5RGt59wck3lxqehQ5+3tk/hI7bQcfTtF6hwZb78pXVfw== X-MS-Exchange-AntiSpam-MessageData: gf7vhMHcJ5O3RKq6w66Uu7pLqmNshrFkWj/bfignNWX0MDexGaQZh2kHj/PnrzcNELKaMPVmJ2/HJIG/E6Le2Znhcg8QmlXrIfrPjrRvrXusKmXdJKky2wH0TFTupEIOGHxtVhn1YwIaTLP7kWU/1Wgq1OsH01Qm6IxuZzEESMozCkab98ZzgMtikdjEn1fTfCkuKiYuHXgODe2eeWxdztQQW+yrEcd3qhkXGDR2GnB9zeHxdZykaupGCzCBsy2O2APLIqSnr2aNXKdCc2ylOm3m+czGVSZpElTsJUqlT+sh/+Yd+TZn1Do/vdBSkvqZt0SLRhS1wicypLGB1mL9uMwbQplpy10Idfaf4G+wMwcH4co2z+8jfwqcomxC6wBFs44yaEvrkTJk/CHnsO7z/xSY/QfAo0X6/1Emzk8R+IJ1m7f9y4+SDnWO4X/h0TO3b0nNmq6Yut425RVA0V2h2hWNeAH3JifzEQsK/3OSjaw= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a505af86-7bee-4ded-68af-08d83242204a X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:31:26.5452 (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: g4uGzse2D0+gv9ZmHngl+KNnmW6zjeuXQ7rF0lUvq1QMPwii4n8GcWhhBnOPIacRrLV067sivNib9b5BUUlZ/g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: i0fPM3Opbjhd5n2n2rYiNIvjx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863888; bh=JLEyyHitkgFdvEoy3zjLH4u5ZkwAm79sl5mNaY5bVYM=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=tlntqXym/vMjR2F91GjSYjgSL+QWCMUS8+BzLnCmIHVxXEgQJof/IRYY0Ctofuozt0D Kcz4PvgFKPpifIIzCwMf2LboB4fSsPIZQcQqAjURuyyAleBO8CyONlJ99AtGM1Iuq6E7K BPHky93PhprbhB31TZnQccD8iorbXGKTck8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 During BSP startup, the reset vector code will issue a CPUID instruction while in 32-bit mode. When running as an SEV-ES guest, this will trigger a #VC exception. Add exception handling support to the early reset vector code to catch these exceptions. Also, since the guest is in 32-bit mode at this point, writes to the GHCB will be encrypted and thus not able to be read by the hypervisor, so use the GHCB CPUID request/response protocol to obtain the requested CPUID function values and provide these to the guest. The exception handling support is active during the SEV check and uses the OVMF temporary RAM space for a stack. After the SEV check is complete, the exception handling support is removed and the stack pointer cleared. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/ResetVector/ResetVector.inf | 3 + OvmfPkg/ResetVector/Ia32/PageTables64.asm | 275 +++++++++++++++++++++- OvmfPkg/ResetVector/ResetVector.nasmb | 2 + 3 files changed, 277 insertions(+), 3 deletions(-) diff --git a/OvmfPkg/ResetVector/ResetVector.inf b/OvmfPkg/ResetVector/Rese= tVector.inf index 483fd90fe785..a53ae6c194ae 100644 --- a/OvmfPkg/ResetVector/ResetVector.inf +++ b/OvmfPkg/ResetVector/ResetVector.inf @@ -34,9 +34,12 @@ [BuildOptions] *_*_X64_NASMB_FLAGS =3D -I$(WORKSPACE)/UefiCpuPkg/ResetVector/Vtf0/ =20 [Pcd] + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbPageTableSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm b/OvmfPkg/ResetVecto= r/Ia32/PageTables64.asm index 9f86ddf6f08f..7c72128a84d6 100644 --- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm +++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm @@ -36,13 +36,58 @@ BITS 32 PAGE_READ_WRITE + \ PAGE_PRESENT) =20 +; +; SEV-ES #VC exception handler support +; +; #VC handler local variable locations +; +%define VC_CPUID_RESULT_EAX 0 +%define VC_CPUID_RESULT_EBX 4 +%define VC_CPUID_RESULT_ECX 8 +%define VC_CPUID_RESULT_EDX 12 +%define VC_GHCB_MSR_EDX 16 +%define VC_GHCB_MSR_EAX 20 +%define VC_CPUID_REQUEST_REGISTER 24 +%define VC_CPUID_FUNCTION 28 + +; #VC handler total local variable size +; +%define VC_VARIABLE_SIZE 32 + +; #VC handler GHCB CPUID request/response protocol values +; +%define GHCB_CPUID_REQUEST 4 +%define GHCB_CPUID_RESPONSE 5 +%define GHCB_CPUID_REGISTER_SHIFT 30 +%define CPUID_INSN_LEN 2 + + ; Check if Secure Encrypted Virtualization (SEV) feature is enabled ; -; If SEV is enabled then EAX will be at least 32 +; Modified: EAX, EBX, ECX, EDX, ESP +; +; If SEV is enabled then EAX will be at least 32. ; If SEV is disabled then EAX will be zero. ; CheckSevFeature: + ; Set the first byte of the workarea to zero to communicate to the SEC + ; phase that SEV-ES is not enabled. If SEV-ES is enabled, the CPUID + ; instruction will trigger a #VC exception where the first byte of the + ; workarea will be set to one. + mov byte[SEV_ES_WORK_AREA], 0 + + ; + ; Set up exception handlers to check for SEV-ES + ; Load temporary RAM stack based on PCDs (see SevEsIdtVmmComm for + ; stack usage) + ; Establish exception handlers + ; + mov esp, SEV_ES_VC_TOP_OF_STACK + mov eax, ADDR_OF(Idtr) + lidt [cs:eax] + ; Check if we have a valid (0x8000_001F) CPUID leaf + ; CPUID raises a #VC exception if running as an SEV-ES guest mov eax, 0x80000000 cpuid =20 @@ -53,8 +98,8 @@ CheckSevFeature: jl NoSev =20 ; Check for memory encryption feature: - ; CPUID Fn8000_001F[EAX] - Bit 1 - ; + ; CPUID Fn8000_001F[EAX] - Bit 1 + ; CPUID raises a #VC exception if running as an SEV-ES guest mov eax, 0x8000001f cpuid bt eax, 1 @@ -78,6 +123,15 @@ NoSev: xor eax, eax =20 SevExit: + ; + ; Clear exception handlers and stack + ; + push eax + mov eax, ADDR_OF(IdtrClear) + lidt [cs:eax] + pop eax + mov esp, 0 + OneTimeCallRet CheckSevFeature =20 ; Check if Secure Encrypted Virtualization - Encrypted State (SEV-ES) feat= ure @@ -222,3 +276,218 @@ SetCr3: mov cr3, eax =20 OneTimeCallRet SetCr3ForPageTables64 + +; +; Start of #VC exception handling routines +; + +SevEsIdtNotCpuid: + ; + ; Use VMGEXIT to request termination. + ; 1 - #VC was not for CPUID + ; + mov eax, 1 + jmp SevEsIdtTerminate + +SevEsIdtNoCpuidResponse: + ; + ; Use VMGEXIT to request termination. + ; 2 - GHCB_CPUID_RESPONSE not received + ; + mov eax, 2 + +SevEsIdtTerminate: + ; + ; Use VMGEXIT to request termination. At this point the reason code is + ; located in EAX, so shift it left 16 bits to the proper location. + ; + ; EAX[11:0] =3D> 0x100 - request termination + ; EAX[15:12] =3D> 0x1 - OVMF + ; EAX[23:16] =3D> 0xXX - REASON CODE + ; + shl eax, 16 + or eax, 0x1100 + xor edx, edx + mov ecx, 0xc0010130 + wrmsr + ; + ; Issue VMGEXIT - NASM doesn't support the vmmcall instruction in 32-b= it + ; mode, so work around this by temporarily switching to 64-bit mode. + ; +BITS 64 + rep vmmcall +BITS 32 + + ; + ; We shouldn't come back from the VMGEXIT, but if we do, just loop. + ; +SevEsIdtHlt: + hlt + jmp SevEsIdtHlt + iret + + ; + ; Total stack usage for the #VC handler is 44 bytes: + ; - 12 bytes for the exception IRET (after popping error code) + ; - 32 bytes for the local variables. + ; +SevEsIdtVmmComm: + ; + ; If we're here, then we are an SEV-ES guest and this + ; was triggered by a CPUID instruction + ; + ; Set the first byte of the workarea to one to communicate to the SEC + ; phase that SEV-ES is enabled. + mov byte[SEV_ES_WORK_AREA], 1 + + pop ecx ; Error code + cmp ecx, 0x72 ; Be sure it was CPUID + jne SevEsIdtNotCpuid + + ; Set up local variable room on the stack + ; CPUID function : + 28 + ; CPUID request register : + 24 + ; GHCB MSR (EAX) : + 20 + ; GHCB MSR (EDX) : + 16 + ; CPUID result (EDX) : + 12 + ; CPUID result (ECX) : + 8 + ; CPUID result (EBX) : + 4 + ; CPUID result (EAX) : + 0 + sub esp, VC_VARIABLE_SIZE + + ; Save the CPUID function being requested + mov [esp + VC_CPUID_FUNCTION], eax + + ; The GHCB CPUID protocol uses the following mapping to request + ; a specific register: + ; 0 =3D> EAX, 1 =3D> EBX, 2 =3D> ECX, 3 =3D> EDX + ; + ; Set EAX as the first register to request. This will also be used as a + ; loop variable to request all register values (EAX to EDX). + xor eax, eax + mov [esp + VC_CPUID_REQUEST_REGISTER], eax + + ; Save current GHCB MSR value + mov ecx, 0xc0010130 + rdmsr + mov [esp + VC_GHCB_MSR_EAX], eax + mov [esp + VC_GHCB_MSR_EDX], edx + +NextReg: + ; + ; Setup GHCB MSR + ; GHCB_MSR[63:32] =3D CPUID function + ; GHCB_MSR[31:30] =3D CPUID register + ; GHCB_MSR[11:0] =3D CPUID request protocol + ; + mov eax, [esp + VC_CPUID_REQUEST_REGISTER] + cmp eax, 4 + jge VmmDone + + shl eax, GHCB_CPUID_REGISTER_SHIFT + or eax, GHCB_CPUID_REQUEST + mov edx, [esp + VC_CPUID_FUNCTION] + mov ecx, 0xc0010130 + wrmsr + + ; + ; Issue VMGEXIT - NASM doesn't support the vmmcall instruction in 32-b= it + ; mode, so work around this by temporarily switching to 64-bit mode. + ; +BITS 64 + rep vmmcall +BITS 32 + + ; + ; Read GHCB MSR + ; GHCB_MSR[63:32] =3D CPUID register value + ; GHCB_MSR[31:30] =3D CPUID register + ; GHCB_MSR[11:0] =3D CPUID response protocol + ; + mov ecx, 0xc0010130 + rdmsr + mov ecx, eax + and ecx, 0xfff + cmp ecx, GHCB_CPUID_RESPONSE + jne SevEsIdtNoCpuidResponse + + ; Save returned value + shr eax, GHCB_CPUID_REGISTER_SHIFT + mov [esp + eax * 4], edx + + ; Next register + inc word [esp + VC_CPUID_REQUEST_REGISTER] + + jmp NextReg + +VmmDone: + ; + ; At this point we have all CPUID register values. Restore the GHCB MS= R, + ; set the return register values and return. + ; + mov eax, [esp + VC_GHCB_MSR_EAX] + mov edx, [esp + VC_GHCB_MSR_EDX] + mov ecx, 0xc0010130 + wrmsr + + mov eax, [esp + VC_CPUID_RESULT_EAX] + mov ebx, [esp + VC_CPUID_RESULT_EBX] + mov ecx, [esp + VC_CPUID_RESULT_ECX] + mov edx, [esp + VC_CPUID_RESULT_EDX] + + add esp, VC_VARIABLE_SIZE + + ; Update the EIP value to skip over the now handled CPUID instruction + ; (the CPUID instruction has a length of 2) + add word [esp], CPUID_INSN_LEN + iret + +ALIGN 2 + +Idtr: + dw IDT_END - IDT_BASE - 1 ; Limit + dd ADDR_OF(IDT_BASE) ; Base + +IdtrClear: + dw 0 ; Limit + dd 0 ; Base + +ALIGN 16 + +; +; The Interrupt Descriptor Table (IDT) +; This will be used to determine if SEV-ES is enabled. Upon execution +; of the CPUID instruction, a VMM Communication Exception will occur. +; This will tell us if SEV-ES is enabled. We can use the current value +; of the GHCB MSR to determine the SEV attributes. +; +IDT_BASE: +; +; Vectors 0 - 28 (No handlers) +; +%rep 29 + dw 0 ; Offset low bits 15..0 + dw 0x10 ; Selector + db 0 ; Reserved + db 0x8E ; Gate Type (IA32_IDT_GAT= E_TYPE_INTERRUPT_32) + dw 0 ; Offset high bits 31..16 +%endrep +; +; Vector 29 (VMM Communication Exception) +; + dw (ADDR_OF(SevEsIdtVmmComm) & 0xffff) ; Offset low bits 15..0 + dw 0x10 ; Selector + db 0 ; Reserved + db 0x8E ; Gate Type (IA32_IDT_GAT= E_TYPE_INTERRUPT_32) + dw (ADDR_OF(SevEsIdtVmmComm) >> 16) ; Offset high bits 31..16 +; +; Vectors 30 - 31 (No handlers) +; +%rep 2 + dw 0 ; Offset low bits 15..0 + dw 0x10 ; Selector + db 0 ; Reserved + db 0x8E ; Gate Type (IA32_IDT_GAT= E_TYPE_INTERRUPT_32) + dw 0 ; Offset high bits 31..16 +%endrep +IDT_END: diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb b/OvmfPkg/ResetVector/Re= setVector.nasmb index bfb77e439105..762661115d50 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -72,6 +72,8 @@ %define GHCB_PT_ADDR (FixedPcdGet32 (PcdOvmfSecGhcbPageTableBase)) %define GHCB_BASE (FixedPcdGet32 (PcdOvmfSecGhcbBase)) %define GHCB_SIZE (FixedPcdGet32 (PcdOvmfSecGhcbSize)) + %define SEV_ES_WORK_AREA (FixedPcdGet32 (PcdSevEsWorkAreaBase)) + %define SEV_ES_VC_TOP_OF_STACK (FixedPcdGet32 (PcdOvmfSecPeiTempRamBase)= + FixedPcdGet32 (PcdOvmfSecPeiTempRamSize)) %include "Ia32/PageTables64.asm" %endif =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63340): https://edk2.groups.io/g/devel/message/63340 Mute This Topic: https://groups.io/mt/75825068/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 Fri Apr 26 07:16:41 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+63341+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+63341+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 159586389717668.26067666498136; Mon, 27 Jul 2020 08:31:37 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id JAwLYY1788612xQzVo0zMNX5; Mon, 27 Jul 2020 08:31:36 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.52]) by mx.groups.io with SMTP id smtpd.web11.58173.1595863895895592838 for ; Mon, 27 Jul 2020 08:31:36 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CtW9GQEBLPlR8X5UEVu4AnLXcYBkZX+g3Di/JSdm+YCEfqaHbOR9B1oBoJvb/dfIqu8kkfjVQQyNRWuA5ibhxDECgGHt1MwgimE6hPv5D2BZwDWhajEMOMHfSCq2UDYds7XoFcgLWeHYGwCXGd/pEuCconrLce4F/rPxvr6kBbKN7VPJGmn6fG0rXQ36Vxknpik0heWYr57zxoVDi1XfJvXJ40TOcMWuwo3L4zaWzBsqmH3gr1YMczWEsymvjWk73gcnZua0dEjoKhfaSBoyz7alQ52wrKc2IyfCTJzDOgQepR/d9s7Vw2TNyL4b2MDHuJDVFzX8o9isTrDKtSoBLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=S26Dux0cwurzGpks92C9p7rCgsyx41XUiYYP5lYQTJU=; b=GS9w7YykweUfD2gFDpkUknJpszoXqbpDRIXO/mgK/5JEqFEjt3U71zP/WqejwFV+Hzv1S4OsNUwaUTVJ0ZR88G7jxySwOoMQG7ZHqI7FXYk661uPnpFS+ky2ts0el1JaRtBxf+TZ+QfP/otPwrMjd7ZJYsfT7H0Ba8wtXSZ305rLBwFg3Ufe0qWl6GNqTOWLKfiaOu2NEf0ToiIVbkpX+2L+2nLphlM6CStSlmh3OCRZKgRv9DveJRsZecxMzb8KeFzbQETLKf1bk4HnBcl9D3SgFAjG/WQE/wTurO/HcqCr8nuhkRupN+9hC5CPtFphC0c9GKOaPcLi6dbQg77PYA== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:31:34 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:31:34 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 37/46] OvmfPkg/Sec: Add #VC exception handling for Sec phase Date: Mon, 27 Jul 2020 10:26:18 -0500 Message-ID: <8e6052699baaf81c637c0902de1f646353d276ee.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0026.namprd10.prod.outlook.com (2603:10b6:806:a7::31) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SA9PR10CA0026.namprd10.prod.outlook.com (2603:10b6:806:a7::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23 via Frontend Transport; Mon, 27 Jul 2020 15:31: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: 4da524d9-5802-4be5-ee8a-08d832422511 X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: tw6t/RoPHEtgKlcm2Ecz4xCC2Jp1h5gytiV0eDywHaLfmr/II67fWH9l3hQiJ89rHqBAiJGWyjmr88ifIk0Kusvp3OXvU2KuYhKUNI2tXWRXY3CRhcUDzjujnN+f/oJvhAYkQKuaN0L5ZkJPMMla9ycSnOZsHZGyqf2hu7eGrcOWKDlaD9bwMMpfAsXzkhMx8nCkZu99dffQVurcW8b+kCVMQIZvw4SbKhD8xwtUWAP5DYaFtcSsOFu9CRJyhkjjvyCnaGHYhVsQbAv6VPumFE42OqqjHIIdk88dUj+0z14fbPH1r0bfn5ylzuXJKGoeOM8SSS4jOk2DgjdZSLQFin+sR90c5C5Lb9PfnBC7cGmXu0PyYa6IBbc9A2esoFNgfm4lV5dRIKpndhXfpNjYINQGlMgWGFKbyua8qdhbgEYMxwzma0grOL8ztSWwzo7BsVnjpreqgOYyLmi071apiw== X-MS-Exchange-AntiSpam-MessageData: 2P+vNcfK+I6p40uacF2+fDss3zHGpmTgEzK4gedl558U4bTErXhj/+jjcFEX27FbMMJtR6OPpy6OC7qAD1usIXQ56ysBQjokW4HFpX/ZYYoQqlJkzqrsUXJHzUGk0bCP73SIxbynE3o16Ii0pT5tmKoBX3LKrEkkIhnNyULN3TC5MJrKO0CDfulqmH3PePH5Lm0Ly3Mt07Gn4piwJqrKd7BiuwgGtAGdR+n+S+G4ChLh8pAfY/cPeRs9nZTsHsoeZ6ybJukZutDPt5MyKktLAAuO01SUBNOrf4VmvHkMvYeYWlx4XybLUMCrkiNPiG/bH0IjSYb9vYDQdUJDY5VRQKCFoaa5Nfkdt/Wmj8gNlV5G2EhThEU4Abrjgz0lqthC/+0lKwgPnTE93fceE6VHjxE2lKx3xePP0VUwdYoRNm6JuHYNCxLVTsOlD67KZBR2rYlXHvsZe+PjxFONI7sNs6KoxjnCWuYZtFrHQpYcye0= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4da524d9-5802-4be5-ee8a-08d832422511 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:31:34.5427 (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: /2p9qhQeTMHKE6YrnSIgSfPxmpJalGhFMNfvXs6ZO4xUh4K5k7NjJ/0lIXmqMFdkiZxMbH0xX3PQLx75d0yYWw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: XJ745pqDasv6PMyjdOMRYUNNx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863896; bh=OwFCRGxOQeVex7gqzyn8cLvoNN2Uc21pdf9ohAuce1M=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=bOu+SalAXDe76MCxWDu9fRY2NkMHAEmcC4Ip8pts56qCDxXbUh1JOte8aMy75IyXc8t pu3mD9cIZqj8Cy/mKT0JEu0X0CV3JNKfQCPOBQD5SBZxN8zw3j4z8qSgXUF9vwGm+8O9c pqyKs/FO8Bu59qVEqO26eETO/itPWBM6/bE= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 An SEV-ES guest will generate a #VC exception when it encounters a non-automatic exit (NAE) event. It is expected that the #VC exception handler will communicate with the hypervisor using the GHCB to handle the NAE event. NAE events can occur during the Sec phase, so initialize exception handling early in the OVMF Sec support. Before establishing the exception handling, validate that the supported version of the SEV-ES protocol in OVMF is supported by the hypervisor. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Sec/SecMain.inf | 4 + OvmfPkg/Sec/SecMain.c | 181 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 172 insertions(+), 13 deletions(-) diff --git a/OvmfPkg/Sec/SecMain.inf b/OvmfPkg/Sec/SecMain.inf index 63ba4cb555fb..7f78dcee2772 100644 --- a/OvmfPkg/Sec/SecMain.inf +++ b/OvmfPkg/Sec/SecMain.inf @@ -50,15 +50,19 @@ [LibraryClasses] PeCoffExtraActionLib ExtractGuidedSectionLib LocalApicLib + CpuExceptionHandlerLib =20 [Ppis] gEfiTemporaryRamSupportPpiGuid # PPI ALWAYS_PRODUCED =20 [Pcd] + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvSize + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbBase + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecGhcbSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPageTablesBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSecPeiTempRamSize diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/SecMain.c index 6dea6e771a29..c2a35463dce4 100644 --- a/OvmfPkg/Sec/SecMain.c +++ b/OvmfPkg/Sec/SecMain.c @@ -24,6 +24,9 @@ #include #include #include +#include +#include +#include =20 #include =20 @@ -34,6 +37,10 @@ typedef struct _SEC_IDT_TABLE { IA32_IDT_GATE_DESCRIPTOR IdtTable[SEC_IDT_ENTRY_COUNT]; } SEC_IDT_TABLE; =20 +typedef struct _SEC_SEV_ES_WORK_AREA { + UINT8 SevEsEnabled; +} SEC_SEV_ES_WORK_AREA; + VOID EFIAPI SecStartupPhase2 ( @@ -712,6 +719,120 @@ FindAndReportEntryPoints ( return; } =20 +/** + Handle an SEV-ES/GHCB protocol check failure. + + Notify the hypervisor using the VMGEXIT instruction that the SEV-ES guest + wishes to be terminated. + + @param[in] ReasonCode Reason code to provide to the hypervisor for the + termination request. + +**/ +STATIC +VOID +SevEsProtocolFailure ( + IN UINT8 ReasonCode + ) +{ + MSR_SEV_ES_GHCB_REGISTER Msr; + + // + // Use the GHCB MSR Protocol to request termination by the hypervisor + // + Msr.GhcbPhysicalAddress =3D 0; + Msr.GhcbTerminate.Function =3D GHCB_INFO_TERMINATE_REQUEST; + Msr.GhcbTerminate.ReasonCodeSet =3D GHCB_TERMINATE_GHCB; + Msr.GhcbTerminate.ReasonCode =3D ReasonCode; + AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress); + + AsmVmgExit (); + + ASSERT (FALSE); + CpuDeadLoop (); +} + +/** + Validate the SEV-ES/GHCB protocol level. + + Verify that the level of SEV-ES/GHCB protocol supported by the hypervisor + and the guest intersect. If they don't intersect, request termination. + +**/ +STATIC +VOID +SevEsProtocolCheck ( + VOID + ) +{ + MSR_SEV_ES_GHCB_REGISTER Msr; + GHCB *Ghcb; + + // + // Use the GHCB MSR Protocol to obtain the GHCB SEV-ES Information for + // protocol checking + // + Msr.GhcbPhysicalAddress =3D 0; + Msr.GhcbInfo.Function =3D GHCB_INFO_SEV_INFO_GET; + AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress); + + AsmVmgExit (); + + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + + if (Msr.GhcbInfo.Function !=3D GHCB_INFO_SEV_INFO) { + SevEsProtocolFailure (GHCB_TERMINATE_GHCB_GENERAL); + } + + if (Msr.GhcbProtocol.SevEsProtocolMin > Msr.GhcbProtocol.SevEsProtocolMa= x) { + SevEsProtocolFailure (GHCB_TERMINATE_GHCB_PROTOCOL); + } + + if ((Msr.GhcbProtocol.SevEsProtocolMin > GHCB_VERSION_MAX) || + (Msr.GhcbProtocol.SevEsProtocolMax < GHCB_VERSION_MIN)) { + SevEsProtocolFailure (GHCB_TERMINATE_GHCB_PROTOCOL); + } + + // + // SEV-ES protocol checking succeeded, set the initial GHCB address + // + Msr.GhcbPhysicalAddress =3D FixedPcdGet32 (PcdOvmfSecGhcbBase); + AsmWriteMsr64 (MSR_SEV_ES_GHCB, Msr.GhcbPhysicalAddress); + + Ghcb =3D Msr.Ghcb; + SetMem (Ghcb, sizeof (*Ghcb), 0); + + // + // Set the version to the maximum that can be supported + // + Ghcb->ProtocolVersion =3D MIN (Msr.GhcbProtocol.SevEsProtocolMax, GHCB_V= ERSION_MAX); + Ghcb->GhcbUsage =3D GHCB_STANDARD_USAGE; +} + +/** + Determine if SEV-ES is active. + + During early booting, SEV-ES support code will set a flag to indicate th= at + SEV-ES is enabled. Return the value of this flag as an indicator that SE= V-ES + is enabled. + + @retval TRUE SEV-ES is enabled + @retval FALSE SEV-ES is not enabled + +**/ +STATIC +BOOLEAN +SevEsIsEnabled ( + VOID + ) +{ + SEC_SEV_ES_WORK_AREA *SevEsWorkArea; + + SevEsWorkArea =3D (SEC_SEV_ES_WORK_AREA *) FixedPcdGet32 (PcdSevEsWorkAr= eaBase); + + return ((SevEsWorkArea !=3D NULL) && (SevEsWorkArea->SevEsEnabled !=3D 0= )); +} + VOID EFIAPI SecCoreStartupWithStack ( @@ -737,8 +858,55 @@ SecCoreStartupWithStack ( Table[Index] =3D 0; } =20 + // + // Initialize IDT - Since this is before library constructors are called, + // we use a loop rather than CopyMem. + // + IdtTableInStack.PeiService =3D NULL; + for (Index =3D 0; Index < SEC_IDT_ENTRY_COUNT; Index ++) { + UINT8 *Src, *Dst; + UINTN Byte; + + Src =3D (UINT8 *) &mIdtEntryTemplate; + Dst =3D (UINT8 *) &IdtTableInStack.IdtTable[Index]; + for (Byte =3D 0; Byte < sizeof (mIdtEntryTemplate); Byte++) { + Dst[Byte] =3D Src[Byte]; + } + } + + IdtDescriptor.Base =3D (UINTN)&IdtTableInStack.IdtTable; + IdtDescriptor.Limit =3D (UINT16)(sizeof (IdtTableInStack.IdtTable) - 1); + + if (SevEsIsEnabled ()) { + SevEsProtocolCheck (); + + // + // For SEV-ES guests, the exception handler is needed before calling + // ProcessLibraryConstructorList() because some of the library constru= ctors + // perform some functions that result in #VC exceptions being generate= d. + // + // Due to this code executing before library constructors, *all* libra= ry + // API calls are theoretically interface contract violations. However, + // because this is SEC (executing in flash), those constructors cannot + // write variables with static storage duration anyway. Furthermore, o= nly + // a small, restricted set of APIs, such as AsmWriteIdtr() and + // InitializeCpuExceptionHandlers(), are called, where we require that= the + // underlying library not require constructors to have been invoked and + // that the library instance not trigger any #VC exceptions. + // + AsmWriteIdtr (&IdtDescriptor); + InitializeCpuExceptionHandlers (NULL); + } + ProcessLibraryConstructorList (NULL, NULL); =20 + if (!SevEsIsEnabled ()) { + // + // For non SEV-ES guests, just load the IDTR. + // + AsmWriteIdtr (&IdtDescriptor); + } + DEBUG ((DEBUG_INFO, "SecCoreStartupWithStack(0x%x, 0x%x)\n", (UINT32)(UINTN)BootFv, @@ -751,19 +919,6 @@ SecCoreStartupWithStack ( // InitializeFloatingPointUnits (); =20 - // - // Initialize IDT - // - IdtTableInStack.PeiService =3D NULL; - for (Index =3D 0; Index < SEC_IDT_ENTRY_COUNT; Index ++) { - CopyMem (&IdtTableInStack.IdtTable[Index], &mIdtEntryTemplate, sizeof = (mIdtEntryTemplate)); - } - - IdtDescriptor.Base =3D (UINTN)&IdtTableInStack.IdtTable; - IdtDescriptor.Limit =3D (UINT16)(sizeof (IdtTableInStack.IdtTable) - 1); - - AsmWriteIdtr (&IdtDescriptor); - #if defined (MDE_CPU_X64) // // ASSERT that the Page Tables were set by the reset vector code to --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63341): https://edk2.groups.io/g/devel/message/63341 Mute This Topic: https://groups.io/mt/75825073/1787277 Mute #vc: https://groups.io/g/edk2/mutehashtag/vc Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Fri Apr 26 07:16:41 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+63342+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+63342+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 1595863905138530.3584107670321; Mon, 27 Jul 2020 08:31:45 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id MVjcYY1788612x3n2bQuIoUo; Mon, 27 Jul 2020 08:31:44 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.84]) by mx.groups.io with SMTP id smtpd.web12.58175.1595863903949918649 for ; Mon, 27 Jul 2020 08:31:44 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TiVCmME7yRmyVAAgrqP2QMtdjmDlZn8YFlAUj69QJQEVk+1jh9fFMxPgz9caVvzuvlmdhYZLkFAG6zPwJUUFmMmVAV2AwQCZDCgGnyVa6o/7iorEH7yVHKfZFMxez+XhaLnGquDKQPfIZ91t0o+TVTmBwc+mpU04scrXinpm7+q4Rdsp8/tgbrJI3yxIpcRR7c6tvvZ48/z9KvQHHwBCi+6kdAUnt9jbrNVcS7Atoot5mDD6+b/186Eht5diKhRXtyRi5y5i9d/dI48veHeYpMVrvXYxAk9oKgc+PcUoc8fL98DC5sYEvgFaO6cys9Hqz53js5ySzOKfkaA0YMPj8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3E0ymlPSxNH6aH1t6SQyGEJdjjI6yseFWWKhpBgBa7E=; b=DtTzKOkJb4ecRRu/RJuF5hXFsglrkys9siFKy1cOMNeY2DPTrkw8REc7k9VR/jr/M6DRp7BAYzFrPQAc13hvOhjr3cIqAAVCTlQIZj0iHjmlVyvbn7JOBm3X1WaSl+okClxaEAHkXbRPRr/unZdVSpTfKzcMoJOz95kq66HhorALsLmZDYCqWRWXL11hAOCJ5OdBLTmAgWG+YxUmXJVryCBiIU7SRFAuSfTSXXbJsjGjCWeEFRLsZyvp1idJJComxUlvb0cqnGaGDu86RLI/3+JCa3MmZDdA1YAvBEUN9ZWKRwEiSmG4c8d59VmoT/3MW2AVansRJoR8EFUIEbllyw== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:31:42 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:31:42 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 38/46] OvmfPkg/Sec: Enable cache early to speed up booting Date: Mon, 27 Jul 2020 10:26:19 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: SA9PR10CA0007.namprd10.prod.outlook.com (2603:10b6:806:a7::12) 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 SA9PR10CA0007.namprd10.prod.outlook.com (2603:10b6:806:a7::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.22 via Frontend Transport; Mon, 27 Jul 2020 15:31: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: 441b72a2-bd60-4ba7-ea3a-08d8324229c7 X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: jJr+LkjlrR59uN2FP7tdEwa2XSTv6Y5Kw7MKLGb0V8ooOnUWl6PIjTB95oPxjC9t0ymKnVVMJzaMc/sGIVlrRPd2bcDyORUFBSK2jc/xCWbmSYlHFDNTQHrPl9UsuH5lLuPrXaO9GVFtw8bXL2lUA/3sv/DYJJPoR7YZX1+d4Yfcz7jBqD3Pw0MJcg378AkZCDxToF2wDjv9X6aI4hgq5Jy4H/pAE7jfuWKQQDBJeHGuwrHTV0BL14tDDH8GFsS1l4ctqfa8bl7T+BMCcADcRKL2Dajzw5Abgk8omr6cwDcsf1wk+aJTzCYHAjIoWbZOLHozbrp1y2K5gpvjsP1sGQ8dKf8gDMKfZedBuVq9t/OCJDGt2jdky4VinuGgBF3FfESdz08/hwGGjFPINdrtSRGIszx16I9IcG5nmKcBBTKNbd25D3id9g4fn3E78pWe3C20Qvn1SLsFKtkQkM/qmQ== X-MS-Exchange-AntiSpam-MessageData: IaoqeBV5zsDWvThZjMCTXQoMRUAQHIvXTkNMi/ZMXFWS/WOPtHXGrCdz1nUDxGeWK4lDaSmTNLEdLq/cPq3XtO2G4D0aSm3gxfCKXlXy0JD58OQ8OdSSLWj7mW0r19J/DNmGdK06gJcgh4HmbJj4laPXqPuapwFAl+XzgAIjdhPt30LHlQdMJg3qXpV0ZS63yBxLVFQuyZ/Lnzl/fPZY1hcVWE63P0+dZMeOIlymELWz+NxjfupzKEvSzuA+F0hkCZY7RLxM+asX9RFDK+MqRkPYtOQuByzloIht1QUJXKNCGbfwA/VfEH/QIc6A375deNEzj+SuYmNqkjMzAiagVI2hp2Lw2LofcTcWfJCKwpYijj4pesTwBY39wtyNctqhylVpeIqepnf7OWcvzrox6+E25U+bcPgBbOx2pCEAhjuDl9HEyfRy8/DB2qHpdvSy6UB/F1M0PP5rNLBU6OhoVyA9d0RVCUAabnVfES3CFO4= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 441b72a2-bd60-4ba7-ea3a-08d8324229c7 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:31:42.4912 (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: 8vGvcJUWir+cuBu1VeSbp48fh97WDZ8fBBpQJp9vaqPnj/rz8LSMmQTLVWaSr1Ul1am7jAf3pGPwJGPLdDNgwg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: CamATXSXvZEgOM8DmqS2y1XFx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863904; bh=Tt2+5o38lOQ1i5GNHA/zAACNXslPrpscWN7FE0bSqf4=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=ggJBEccMkiGor2XhHp1hAwMG2eW67pXs9rkUl2sTcwSs4p+ffKshxxiaiFEg2qeHWBW e/woBhsgb2n+ANHTYERX1Qjs1ocb4LMBdE0ddl3k7nuxuxmvWzBfpfg29PUX7TqlsGOj8 RYBMm7+fpDChxfdtIEYGXCJjotllSHWD5BM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Currently, the OVMF code relies on the hypervisor to enable the cache support on the processor in order to improve the boot speed. However, with SEV-ES, the hypervisor is not allowed to change the CR0 register to enable caching. Update the OVMF Sec support to enable caching in order to improve the boot speed when running as an SEV-ES guest. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Sec/SecMain.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/SecMain.c index c2a35463dce4..271a06348ed8 100644 --- a/OvmfPkg/Sec/SecMain.c +++ b/OvmfPkg/Sec/SecMain.c @@ -905,6 +905,13 @@ SecCoreStartupWithStack ( // For non SEV-ES guests, just load the IDTR. // AsmWriteIdtr (&IdtDescriptor); + } else { + // + // Under SEV-ES, the hypervisor can't modify CR0 and so can't enable + // caching in order to speed up the boot. Enable caching early for + // an SEV-ES guest. + // + AsmEnableCache (); } =20 DEBUG ((DEBUG_INFO, --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63342): https://edk2.groups.io/g/devel/message/63342 Mute This Topic: https://groups.io/mt/75825076/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 Fri Apr 26 07:16:41 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+63343+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+63343+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 1595863913847694.2947945235519; Mon, 27 Jul 2020 08:31:53 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Tc4xYY1788612xMtx4mvcG9R; Mon, 27 Jul 2020 08:31:53 -0700 X-Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.84]) by mx.groups.io with SMTP id smtpd.web11.58178.1595863912828154074 for ; Mon, 27 Jul 2020 08:31:52 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kAfVZMmzK7Eyw0en4w9NwYWYn6CxtB7IxnH/u+ytpS/YUqto8pzTu8HftYenoPlOzLLB5251iwE+PHmAIfkP+IAtq9weqms6BsRa736/zLo287K0MiKHcAvVawZcKG8mVLvODQT9VWqd6tQo3XHySD4o+rlwO9Tw3+4A52v3d7OsPFFyfu7PV6YlwYxZwsm2gLHcj+Gv8ZUrd+uhsCZPQDG23qLp6o4yuebhA1w3CaO1yr7jGQI3hiYkS2HO+fMOPaS5YjZ8Ou7XuTb7hzgmuwspT3fdIckXb0T0jic5P6CJXkl8oPHjd7uH55nJV9s2w+TqsFC4fQ2iV6KTdd8efw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9SL7ZuvVbtegSaUIJvRjeIedgAr9HaaB2JEMJds61HY=; b=m3xjgOCF05aOY88c0h7UWiIB7Ows26d0sAvjFbO3gVuhDtAysO4WJG2ifvQNF5F7m/B1x5WoC/q/8NOPCmuuzockDZRxJJg2o6o/EP4Ke1aSsZ8c6QV2Aa/yTF51bEKEO0amx+Z/xtqH0zAJ9BbcC51t9fxnBibzdp6imlclE7fzwqK9u3dNuz9gseiARbMcQbTa+kXQtQYi32Px1DvtPuUXLUia7PRQIe2/Yw6966/4kAFtn67qxkX7HoyVc/7ClaBcEJRkCr1wkAsLx4eomIMmOBooTb0R6OC1W2OWXa/HISfPRO4i9plLCrWFZgyyxS0IILDpnbXy6TjjJmjN8A== 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:31:51 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:31:51 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [edk2-devel] [PATCH v12 39/46] OvmfPkg/QemuFlashFvbServicesRuntimeDxe: Bypass flash detection with SEV-ES Date: Mon, 27 Jul 2020 10:26:20 -0500 Message-ID: <5ad304ebdff11d09e9219dc625613d5ffbb5d5ed.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0089.namprd05.prod.outlook.com (2603:10b6:803:22::27) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by SN4PR0501CA0089.namprd05.prod.outlook.com (2603:10b6:803:22::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.9 via Frontend Transport; Mon, 27 Jul 2020 15:31: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: 2b1acdc9-a1c9-4ce8-2a19-08d832422f19 X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: 8GF/RSt+BGkupp9HIWfRXO/IrvnuYHjFvD48d8u15u0WARkW02p1S58xhK2BSpBYXg+CmKJWiXCUBroY9MYh4VCkhJQ3O7NJlHM1gHWMiqys8E3NPQp/zazO+NbL/Cf5KfyeaozmkDJs8V+O+vIww1KL6gEuj6XmdXtMlHrTkgykg9Oo9h1szpHYmyUnTwRj7ed2Rc4RinwLTIEmPsDIh1PVs1ilY2six+nsVjtBW7UvQcJfJ3s3vqnHBUrJyZkhqut8g2zJzVrqTs4rRoIr1DpRflLWWzg7tAwKjpMAqmylrVkj2zA8rzYDnhMzrqg0oU/pUiOjfNDyt60uCFv8RtKx/WI3RZ5WmWG+MjSrysH0c888LdI4XXv/L+fo4LeD8iCkUDRSwgZqfO2JgXFcBgstBE1irXWco923tVIKooqvj6nxJfx6zu+J3/G2xDzw2PLFg7S7d8YAjcSoRPwloc89Jr9QLym1kw9r/7mpDUrpdm/wJJi/02WRZT/Krblf X-MS-Exchange-AntiSpam-MessageData: 9TFZzdFO8AO1gdvrr6ojZWnX+/+puMkFepmN4BmTH2dckGWjGcHPwu75jP2xWNmLm16dV4AugfmFlPcnxZTIAUv5HjhtFCFxDPjnWMK+d3M9OpkIpupRr6vH7Gb1M2WJnoYwEHA9sgJ9Qn0r/xsrzh4iB4lv0iwEd0jvAYpRo7VKtXjFScls99W5s+fyByrycBPbz0K5Rv/TDYismKP5QkhEslbeiR2Ldb3kURZT77Kt/cdO4Pu2857dSxd+K7N0oGIrG/4IJYMN+cRKlpgalkT2mxmAMI637hP79nd3jb8UakLnBlLa8eTkQfNzWZ4KshVlIxGKfjLfkIs/PVTGuVA6nV+T849HZPE5qMoTrq7uuNNcgaSP/HftJAREl3zdeIjPOrRcbgSBWdjoLqqeJ9UwMj7EvHFdpZmMe9e8e3xhth1JfPx5fKrB4U3n8k8i330Y5P+/87CKuwvGIs+PlWqtI7GC0NoZBIrNYUObGKA= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2b1acdc9-a1c9-4ce8-2a19-08d832422f19 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:31:51.3963 (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: vMdEynGB6QKUxxohQPavNe7//MT7Q8AumGvylsqaJhDx7ERZGGvYdbtT7rKBhhqu4S7YivZE//2dP4IuJTVOaA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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: NO59B0oQgA3qgCDMOPBmRwjOx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595863913; bh=zjzNV50IbOtfU80zY9xYDa6IFjESow2SzDvV1gkr1rY=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=Gga5OZTSEurSTmR3HJEaAlhKC1JJqa3hOTh7HoGU6ZGmWx/lUsTidzpEbCgOk2qe6R7 9hrRr/MyNvwYBJQHtsBXj9Y5lmyuYqJ5jVpXlm4wbD1MNOymkrmR3CW0ljsL4GzSkBNXi fCHU3+sRLLgtG9ZO1hW/EKHp8JQA8HV4zts= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 The flash detection routine will attempt to determine how the flash device behaves (e.g. ROM, RAM, Flash). But when SEV-ES is enabled and the flash device behaves as a ROM device (meaning it is marked read-only by the hypervisor), this check may result in an infinite nested page fault because of the attempted write. Since the instruction cannot be emulated when SEV-ES is enabled, the RIP is never advanced, resulting in repeated nested page faults. When SEV-ES is enabled, exit the flash detection early and assume that the FD behaves as Flash. This will result in QemuFlashWrite() being called to store EFI variables, which will also result in an infinite nested page fault when the write is performed. In this case, update QemuFlashWrite() to use the VMGEXIT MMIO write support to have the hypervisor perform the write without having to emulate the instruction. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- .../FvbServicesRuntimeDxe.inf | 2 + .../QemuFlash.h | 13 ++++++ .../QemuFlash.c | 23 +++++++++-- .../QemuFlashDxe.c | 40 +++++++++++++++++++ .../QemuFlashSmm.c | 16 ++++++++ 5 files changed, 91 insertions(+), 3 deletions(-) diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.i= nf b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf index 72cabba4357d..8bb2325157ea 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf @@ -38,6 +38,7 @@ [Sources] [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec + UefiCpuPkg/UefiCpuPkg.dec OvmfPkg/OvmfPkg.dec =20 [LibraryClasses] @@ -52,6 +53,7 @@ [LibraryClasses] UefiBootServicesTableLib UefiDriverEntryPoint UefiRuntimeLib + VmgExitLib =20 [Guids] gEfiEventVirtualAddressChangeGuid # ALWAYS_CONSUMED diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h b/OvmfPkg/Q= emuFlashFvbServicesRuntimeDxe/QemuFlash.h index f1afabcbe6ae..219d0d6e83cf 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.h @@ -89,5 +89,18 @@ QemuFlashBeforeProbe ( IN UINTN FdBlockCount ); =20 +/** + Write to QEMU Flash + + @param[in] Ptr Pointer to the location to write. + @param[in] Value The value to write. + +**/ +VOID +QemuFlashPtrWrite ( + IN volatile UINT8 *Ptr, + IN UINT8 Value + ); + #endif =20 diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c b/OvmfPkg/Q= emuFlashFvbServicesRuntimeDxe/QemuFlash.c index 1b0d6c053f1a..0d29bf701aca 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlash.c @@ -9,6 +9,7 @@ =20 #include #include +#include #include =20 #include "QemuFlash.h" @@ -80,6 +81,21 @@ QemuFlashDetected ( =20 DEBUG ((DEBUG_INFO, "QEMU Flash: Attempting flash detection at %p\n", Pt= r)); =20 + if (MemEncryptSevEsIsEnabled ()) { + // + // When SEV-ES is enabled, the check below can result in an infinite + // loop with respect to a nested page fault. When the memslot is mapped + // read-only, the nested page table entry is read-only. The check below + // will cause a nested page fault that cannot be emulated, causing + // the instruction to retried over and over. For SEV-ES, acknowledge t= hat + // the FD appears as ROM and not as FLASH, but report FLASH anyway bec= ause + // FLASH behavior can be simulated using VMGEXIT. + // + DEBUG ((DEBUG_INFO, + "QEMU Flash: SEV-ES enabled, assuming FD behaves as FLASH\n")); + return TRUE; + } + OriginalUint8 =3D *Ptr; *Ptr =3D CLEAR_STATUS_CMD; ProbeUint8 =3D *Ptr; @@ -181,8 +197,9 @@ QemuFlashWrite ( // Ptr =3D QemuFlashPtr (Lba, Offset); for (Loop =3D 0; Loop < *NumBytes; Loop++) { - *Ptr =3D WRITE_BYTE_CMD; - *Ptr =3D Buffer[Loop]; + QemuFlashPtrWrite (Ptr, WRITE_BYTE_CMD); + QemuFlashPtrWrite (Ptr, Buffer[Loop]); + Ptr++; } =20 @@ -190,7 +207,7 @@ QemuFlashWrite ( // Restore flash to read mode // if (*NumBytes > 0) { - *(Ptr - 1) =3D READ_ARRAY_CMD; + QemuFlashPtrWrite (Ptr - 1, READ_ARRAY_CMD); } =20 return EFI_SUCCESS; diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c b/OvmfPk= g/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c index 5aabe9d7b59c..565383ee26d2 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashDxe.c @@ -10,6 +10,9 @@ **/ =20 #include +#include +#include +#include =20 #include "QemuFlash.h" =20 @@ -32,3 +35,40 @@ QemuFlashBeforeProbe ( // Do nothing // } + +/** + Write to QEMU Flash + + @param[in] Ptr Pointer to the location to write. + @param[in] Value The value to write. + +**/ +VOID +QemuFlashPtrWrite ( + IN volatile UINT8 *Ptr, + IN UINT8 Value + ) +{ + if (MemEncryptSevEsIsEnabled ()) { + MSR_SEV_ES_GHCB_REGISTER Msr; + GHCB *Ghcb; + + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + Ghcb =3D Msr.Ghcb; + + // + // Writing to flash is emulated by the hypervisor through the use of w= rite + // protection. This won't work for an SEV-ES guest because the write w= on't + // be recognized as a true MMIO write, which would result in the requi= red + // #VC exception. Instead, use the the VMGEXIT MMIO write support dire= ctly + // to perform the update. + // + VmgInit (Ghcb); + Ghcb->SharedBuffer[0] =3D Value; + Ghcb->SaveArea.SwScratch =3D (UINT64) (UINTN) Ghcb->SharedBuffer; + VmgExit (Ghcb, SVM_EXIT_MMIO_WRITE, (UINT64) (UINTN) Ptr, 1); + VmgDone (Ghcb); + } else { + *Ptr =3D Value; + } +} diff --git a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashSmm.c b/OvmfPk= g/QemuFlashFvbServicesRuntimeDxe/QemuFlashSmm.c index 7eb426e03855..7eb80bfeffae 100644 --- a/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashSmm.c +++ b/OvmfPkg/QemuFlashFvbServicesRuntimeDxe/QemuFlashSmm.c @@ -46,3 +46,19 @@ QemuFlashBeforeProbe ( ); ASSERT_EFI_ERROR (Status); } + +/** + Write to QEMU Flash + + @param[in] Ptr Pointer to the location to write. + @param[in] Value The value to write. + +**/ +VOID +QemuFlashPtrWrite ( + IN volatile UINT8 *Ptr, + IN UINT8 Value + ) +{ + *Ptr =3D Value; +} --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63343): https://edk2.groups.io/g/devel/message/63343 Mute This Topic: https://groups.io/mt/75825081/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 Fri Apr 26 07:16:41 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+63355+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+63355+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 1595875424720874.7195029103431; Mon, 27 Jul 2020 11:43:44 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id VtA4YY1788612xh5cvylOHrs; Mon, 27 Jul 2020 11:43:44 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.57]) by mx.groups.io with SMTP id smtpd.web11.62684.1595875423143998355 for ; Mon, 27 Jul 2020 11:43:43 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FvupVWrvVNZBcGkboanR69pZiek0WHqP18tJ4geZ2cwQMInKMZlC52rcsnweG7qQeCv5YV1A2wH3A/yz4jkC1l0aZ7F/5DsLj8v+8fEVktyxa093MjNz3dcgA0VgGozLWhZHQtp0f8hRMEQv4+2K1a9w5+Wnzl9ux54NCeCM6I3ESyPQn86FveygnFXjUkP20nDqD5dX2+JL6JIDU2WdskOFXYdtcuDAz07tzw84iUJr4VKGusxpYTbUtQMSaGtZ08wA7e1ZEGUzzTnRkg6MDCsPQgPposlsexHjVSRol0JhxondPn3+ySikYFjevSZkgnqDcTPSAnKw7no0Tt5hmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=y42cNfhmfyz07xseYeQYH9zbpfMlzMLWf83yCfosPcg=; b=BzkCJSocDNdCYfd9pF6zxZatSpRynSONTD8RtJ8c7JvjLVm28Dxm64Ny03j37mZ5K4+HBPlleiH+dHMIGZ4pMYl/RTgVyECZaRaFlKNvt31BFcgD6wiEwt8t/IUfgy3jPHP8uf2HhQW+m2zgkh+PT8AjRi9LWbonlXccTuY84YDZ99ufxwZOeIvuWONd5VSV6zuIo6kkttwtXI4dutHBjAzE/9UgqhvRh65CQxtq38Jc2C98DzcQpk6ok8miSvuE+VnvRkw1OVS8MO4KDvWcMVX9MO5b3tJ3Frit/7BzgZFQ1i5q4G9ssblgTREqryzwkYhscJdGV6t2HQXfVyK2hg== 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 DM5PR12MB1257.namprd12.prod.outlook.com (2603:10b6:3:74::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.24; Mon, 27 Jul 2020 18:43:41 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 18:43:41 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v12 40/46] UefiCpuPkg: Add a 16-bit protected mode code segment descriptor Date: Mon, 27 Jul 2020 13:43:25 -0500 Message-ID: <3c4bf390c535277d371e95e738fe93da850e1b32.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR02CA0115.namprd02.prod.outlook.com (2603:10b6:5:1b4::17) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM6PR02CA0115.namprd02.prod.outlook.com (2603:10b6:5:1b4::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.20 via Frontend Transport; Mon, 27 Jul 2020 18:43: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: e30d2d0f-30cf-4590-ba8b-08d8325cfb75 X-MS-TrafficTypeDiagnostic: DM5PR12MB1257: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: IdZRFLunDtXm7UoAxjUA7OVNuHFu9PEDLGcfv/tB32ETmx3sqOJoH3q8PhLWE7P09jJ719lIFDY6vaPGggQ5IiBeOdZCu4kxvkX/isvtnI8MGTbCBSuf1w/jHYOsoqA2z67Au27fUyH9EniXwN917pJGw9w23RhkwOG2EpfuNt+tfwenpnhEV5oWQHFG1IQxDMoJeav8eHC1OVPHavptc038fKPgbVYNxebqOnuYhCCDpL4VzlRTznqNSC/jCjUd7lfClLvIxs/SjLjXmkGuKgKG096d+9oSYUpqcna3LyJp6e2GAdgmvA3WSk5Y+j5TzMIAtcdCpXMNrqRGKQ3RY5d1ru/ICob82a3MKrrIFFZyrh1Nw8wJwlfsW9oCGi+6kDE6cX0H5raodDkn4MWp5GQmKMOjiI1KtamvbYpLYx5vMFn34FSvd0Kv7D6cQzoy1kt2GKqEbMuyS1vgx3V8+g== X-MS-Exchange-AntiSpam-MessageData: NL/zFCC7NyyJAfO3X/6HhUUk4sFUUAicYUAhhjgx+tQ1Xd24EAXIxbiQ6NjfajV8dA1JybMalQBUjzaWcTsD/dcogOnJn+pCqoKgqYo//J339WABLdRn+PvLgoDOURS2dQcw96jgMaMevtD3p4AxkKM3wLgHECMV4Nmyapli5Va5+xJ+fUQckReeRpc0+/elHdiXUiKODRw/X0HhbF+XxzM8SNFtgNqKmOL8yq7n+a9t6fPTs1s8nMDYdsmk2AJ/OAtGyFf3uXQF1G+1dyHvhbiPMU5FyT0I8O4eGPLR5fFDebaYlmar2L4DbcY24D1MrBssj4TVDOk8yiU0fbl+W5cJ8m8qREjVBUf0lCkzVsV0XijdLlqDpiEUeQQ3gjse6mPNPUdkUtnLGumnKEeUq/EwGEVz1Zwqlw7M5Vhsk6tWz1QisbdT+ztSwCvJ1MRgYMPd5HSQZLWlVg094m4VZYqxEByCBipfYOUeoDox7Io= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: e30d2d0f-30cf-4590-ba8b-08d8325cfb75 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 18:43:41.1871 (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: SiZf9wIADjw/NXsYUQlZEBiQjnHNkam55cWMf2e1VJb3c3phMA8Bg5pIMk0Ljh5vOnjYTzaDyOY2MzxqaZIzpw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1257 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: FSbGFeGUBYPabx2ETIDs0Rwwx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595875424; bh=qkYHjjlnBSwnCIbWJ9smqiIxohoPAsyqsZ5zsvC4Sxg=; h=Content-Type:Date:From:Reply-To:Subject:To; b=j8UWHCK8GthrLQ3o9aBci3XK1AeDYxXpXchwL68kgLRLUbiJch/CCbtMpFUyUVCeQxN N9+yszphB+etLjE2rJytILzBbypU5vFxbeSnuaj6q7NBugdFXZcy/0RzrsFpsGUlGqAo2 VB/OYbCwFzqrIEB8n3fbYdHXvpOZ7jyZ3CM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 A hypervisor is not allowed to update an SEV-ES guests register state, so when booting an SEV-ES guest AP, the hypervisor is not allowed to set the RIP to the guest requested value. Instead, an SEV-ES AP must be transition from 64-bit long mode to 16-bit real mode in response to an INIT-SIPI-SIPI sequence. This requires a 16-bit code segment descriptor. For PEI, create this descriptor in the reset vector GDT table. For DXE, create this descriptor from the newly reserved entry at location 0x28. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Reviewed-by: Eric Dong Signed-off-by: Tom Lendacky --- UefiCpuPkg/CpuDxe/CpuGdt.h | 4 ++-- UefiCpuPkg/CpuDxe/CpuGdt.c | 8 ++++---- UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm | 9 +++++++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/UefiCpuPkg/CpuDxe/CpuGdt.h b/UefiCpuPkg/CpuDxe/CpuGdt.h index 3a0210b2f172..1c94487cbee8 100644 --- a/UefiCpuPkg/CpuDxe/CpuGdt.h +++ b/UefiCpuPkg/CpuDxe/CpuGdt.h @@ -36,7 +36,7 @@ struct _GDT_ENTRIES { GDT_ENTRY LinearCode; GDT_ENTRY SysData; GDT_ENTRY SysCode; - GDT_ENTRY Spare4; + GDT_ENTRY SysCode16; GDT_ENTRY LinearData64; GDT_ENTRY LinearCode64; GDT_ENTRY Spare5; @@ -49,7 +49,7 @@ struct _GDT_ENTRIES { #define LINEAR_CODE_SEL OFFSET_OF (GDT_ENTRIES, LinearCode) #define SYS_DATA_SEL OFFSET_OF (GDT_ENTRIES, SysData) #define SYS_CODE_SEL OFFSET_OF (GDT_ENTRIES, SysCode) -#define SPARE4_SEL OFFSET_OF (GDT_ENTRIES, Spare4) +#define SYS_CODE16_SEL OFFSET_OF (GDT_ENTRIES, SysCode16) #define LINEAR_DATA64_SEL OFFSET_OF (GDT_ENTRIES, LinearData64) #define LINEAR_CODE64_SEL OFFSET_OF (GDT_ENTRIES, LinearCode64) #define SPARE5_SEL OFFSET_OF (GDT_ENTRIES, Spare5) diff --git a/UefiCpuPkg/CpuDxe/CpuGdt.c b/UefiCpuPkg/CpuDxe/CpuGdt.c index 64efadeba601..a1ab543f2da5 100644 --- a/UefiCpuPkg/CpuDxe/CpuGdt.c +++ b/UefiCpuPkg/CpuDxe/CpuGdt.c @@ -70,14 +70,14 @@ STATIC GDT_ENTRIES GdtTemplate =3D { 0x0, }, // - // SPARE4_SEL + // SYS_CODE16_SEL // { - 0x0, // limit 15:0 + 0x0FFFF, // limit 15:0 0x0, // base 15:0 0x0, // base 23:16 - 0x0, // type - 0x0, // limit 19:16, flags + 0x09A, // present, ring 0, code, execute/read + 0x08F, // page-granular, 16-bit 0x0, // base 31:24 }, // diff --git a/UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm b/UefiCpuP= kg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm index ce4ebfffb688..0e79a3984b16 100644 --- a/UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm +++ b/UefiCpuPkg/ResetVector/Vtf0/Ia16/Real16ToFlat32.asm @@ -129,5 +129,14 @@ LINEAR_CODE64_SEL equ $-GDT_BASE DB 0 ; base 31:24 %endif =20 +; linear code segment descriptor +LINEAR_CODE16_SEL equ $-GDT_BASE + DW 0xffff ; limit 15:0 + DW 0 ; base 15:0 + DB 0 ; base 23:16 + DB PRESENT_FLAG(1)|DPL(0)|SYSTEM_FLAG(1)|DESC_TYPE(CODE32_TYPE) + DB GRANULARITY_FLAG(1)|DEFAULT_SIZE32(0)|CODE64_FLAG(0)|UPPER_LIM= IT(0xf) + DB 0 ; base 31:24 + GDT_END: =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63355): https://edk2.groups.io/g/devel/message/63355 Mute This Topic: https://groups.io/mt/75829470/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 Fri Apr 26 07:16:41 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+63356+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+63356+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 1595875431112433.97012501479526; Mon, 27 Jul 2020 11:43:51 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id fn2bYY1788612x6b0sKg1Yio; Mon, 27 Jul 2020 11:43:50 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.47]) by mx.groups.io with SMTP id smtpd.web12.62773.1595875430051492921 for ; Mon, 27 Jul 2020 11:43:50 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FUcTwTJqYdYY8ebnURZNaxmHPrwnOr3h/GqpvVEuN+gaSKjib94PfESsZUed/vxGD6OkpcD2VXwjgDK7S6LgN5kkdE0vhV75oTuL96UAPdMmSHpbi5ocBPdjVEIMbEy/l9A5qlOidZWiG8ZssJZDJuzorrloFFLciPZkEVYjr6k5TwkYPAqO1d2hqziv4nj6GFknQWvr3FwAsx0jIJpCfi6WjbnIUb7FbFMUAS7m1FkDpzdDPjQNbPIVa8COh3o64R8WksYS6XcROpT+wWHZ3n5xDZcMOyftA5U7mET96bONYBfO7249WKx9I10riYv8XqrmcEwn6DXDLbIDCkd5cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2xL2RAVEP5XW/LxYrRr+kHwaYvf60goYc3Dt2uOHhXI=; b=LjS9T9Dbo1pio/1wY2bW3Qwv+fyEgI7RYrTZZrVlDe7diWfVe2WP1z0WVtq32QMmUS1EOawb1g9XUIitbjSOnKFL/jNP1X+v3RxPz1fFVon0N7dIncK++Uup4DJAI4rvq2M0eB+bAicTSUeUZvuH5qrCb3OzcQhv9N8FUdVmFLHo7uwzUVvNf3x4TAWuJV+rp4wLDsY/17OUSe+mhQCds8eli8qQ9merKcTyV1BVAhT5Y4eBQ0vm4X27rqENYEebl01PuLR9oGOD8PChTf3E/hUJ3N9OhhikBxvN96QdlReHQWOPmAI+9eBzauoklnomuZQAtTKGjpO4UKGKc5lLEQ== 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 DM5PR12MB1257.namprd12.prod.outlook.com (2603:10b6:3:74::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.24; Mon, 27 Jul 2020 18:43:48 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 18:43:48 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v12 41/46] UefiCpuPkg/MpInitLib: Add CPU MP data flag to indicate if SEV-ES is enabled Date: Mon, 27 Jul 2020 13:43:26 -0500 Message-ID: <02616d06071387533c092505be7e2bd54cde9596.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR20CA0031.namprd20.prod.outlook.com (2603:10b6:3:13d::17) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR20CA0031.namprd20.prod.outlook.com (2603:10b6:3:13d::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.23 via Frontend Transport; Mon, 27 Jul 2020 18:43:48 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 71817a88-2313-4d0e-a907-08d8325cffcc X-MS-TrafficTypeDiagnostic: DM5PR12MB1257: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: Z5RJD4JLZLuvlpZzhE/jwhK/GU1QEtCxFhuUY0Iuvd0cOprySvcdu9rNDVnW7ZR/xHjvQOryaTcPjfUKUUtsm3wTOmLvOHaxLoXg85sdXGuETrSSac0VL2G9/nG5YLNVk/Y+taCCBAHT3ClDEY+36y0/Q+OSNqWkYkIa89JLXoDnfIaphj7fT9ahbVHHJR6mc4T8NsnKDfiRM6UDiIQxWXBngdVDMIhrwsuL6wbOK95W22p5I9Nw7bAHoRkjzhms3HybBLsTVXM0p+3epFrRZr+qJZcmcMGwj8BbcZstlQVErxPGMX6LVAjmhmlVBM0DywHfCtfPGnm8CN6PvT/wtAQ9ucgmWqtbsfucXjrPvOMZLzTbIz62Nq/W3WIB5SpbdelMCpk9qv0+rY68a2rMo9nsuJkIB44EabVh/PBsud6Dkukxp0X6ekM34lTJCs/IpWxl2V8JxrQdylYQnvqTRA== X-MS-Exchange-AntiSpam-MessageData: Vlk+0wChLJeG/KNFOpQFsy7wpOEco6RAIV/oFJpUaXTHHm7zrZ8CTiRVzUEtFfQJIBNB6yvJiFelf8lHtmSHEcrnctGaFK0jgmXkPa77GexLwVHHlD5l5FeyDneFPKy9+K4bVJWPcHxT6QeEPi2msHysOt4xW2tFR5fgBFzleaN0Blwd+xwIBAZb3yB2nmet0CABmYBpC89MQLq39U4xZVbdzj/jd49zSFn/MuiXx1ZZEsZrPz8O+fVKsBoz2AaFNXnRLzxgYPd0flzpvqATJdC+hzjwcaijzHQEHuuk1gX4QDLdaq/bIpQYacwW1TxBdACeYtHmzRzkklr0Sh8BC+Z+IREQVXmZdTCEY+L2qxD5Bw5dBMAjop4JTGuDNcvJ/DmxE4ScRs8vMa00+03bH7pEyy0JJP6TxV7qtwXHWkFphUvpIQytR1UTkZwWTQJcVPBBLQ8n1XFNLNn7xClHORtbthrNF57bF7Mcs3Wk36A= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 71817a88-2313-4d0e-a907-08d8325cffcc X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 18:43:48.4807 (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: sT2B10t5VKu8pavp956v98Wi/cqH05S+05Y7e4ks+h/sDUhSQ/GjLPLIcqep3yGbxaU3TgAjpsBs1BP1488q3A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1257 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: A3fiErnbp8aK3oTpWCkI3dNxx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595875430; bh=EVJQf79JTH2SvMdk02gesbCZ3AQuYoz5ZmVAteByuHI=; h=Content-Type:Date:From:Reply-To:Subject:To; b=QnL3sfqcut62MkmznIQGZv2NtpzUQLGy+NNfrSoOzrNooY5OkvnVkt51GGpXoq7nSa3 h4d6UyAdOeNieS3gG/sOhtUKiRJIr42L73DeYFYqFTjXffEjxXIekX3dOQRKRWlFI7a8K Yy+3VwqZmu21YqyIW9hJrrLqLWn6zFmrw9o= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 When starting APs in an SMP configuration, the AP needs to know if it is running as an SEV-ES guest in order to assign a GHCB page. Add a field to the CPU_MP_DATA structure that will indicate if SEV-ES is enabled. This new field is set during MP library initialization with the PCD value PcdSevEsIsEnabled. This flag can then be used to determine if SEV-ES is enabled. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Reviewed-by: Eric Dong Signed-off-by: Tom Lendacky --- UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf | 1 + UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf | 1 + UefiCpuPkg/Library/MpInitLib/MpLib.h | 2 ++ UefiCpuPkg/Library/MpInitLib/MpLib.c | 1 + 4 files changed, 5 insertions(+) diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/DxeMpInitLib.inf index 9907f4157b09..583276595619 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf @@ -71,4 +71,5 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuApLoopMode ## = CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate ## = SOMETIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApStatusCheckIntervalInMicroSeconds ## = CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled ## = CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ## = CONSUMES diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/PeiMpInitLib.inf index 89ee9a79d8c5..4b3d39fbf36c 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf @@ -61,6 +61,7 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuMicrocodePatchRegionSize ## CONS= UMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApLoopMode ## CONS= UMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate ## SOME= TIMES_CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled ## CONS= UMES =20 [Ppis] gEdkiiPeiShadowMicrocodePpiGuid ## SOMETIMES_CONSUMES diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index a8ca03efb8e3..5b46c295b6b2 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -276,6 +276,8 @@ struct _CPU_MP_DATA { // driver. // BOOLEAN WakeUpByInitSipiSipi; + + BOOLEAN SevEsIsEnabled; }; =20 extern EFI_GUID mCpuInitMpLibHobGuid; diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 9b0660a5d4ea..2a3fbeef35f7 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -1704,6 +1704,7 @@ MpInitLibInitialize ( CpuMpData->CpuData =3D (CPU_AP_DATA *) (CpuMpData + 1); CpuMpData->CpuInfoInHob =3D (UINT64) (UINTN) (CpuMpData->CpuData + M= axLogicalProcessorNumber); InitializeSpinLock(&CpuMpData->MpLock); + CpuMpData->SevEsIsEnabled =3D PcdGetBool (PcdSevEsIsEnabled); =20 // // Make sure no memory usage outside of the allocated buffer. --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63356): https://edk2.groups.io/g/devel/message/63356 Mute This Topic: https://groups.io/mt/75829472/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 Fri Apr 26 07:16:41 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+63357+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+63357+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 1595875439281793.9052854333885; Mon, 27 Jul 2020 11:43:59 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id wyL3YY1788612xhTwHJlBC0q; Mon, 27 Jul 2020 11:43:58 -0700 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.72]) by mx.groups.io with SMTP id smtpd.web10.62899.1595875437875742228 for ; Mon, 27 Jul 2020 11:43:58 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d/s9WBukB+m3ZpkhONLhrjhfnj7b5uiH25Ni1ex3QqzN8hLB0CHJcC5OPiqGwtblEUZUCXxVK7Mdw1Z7YfCL3+XCgy8oJbHB+GrKiR9inZ8QDJzIITGQHrMVewEOO1IWnOmrtAAHC/o0jQ7mjqBj+/f+DiKwvlGuQ4h77f12DHX5J97J0inpsKtJ5a8prUyE4GRYVDhJPgRW8V0Wx64futWQvYilcyJ4iJPiVRquLQ58DYalUrvmx1t9cBIxIbIYrJT8a1MECjPEnxyr2kapmwjosvoFkXkzVE+3QsZY4qn9nuu71xSe8vzwUZhqkVFQWquW9Y7ArOmDI+jAycyHBg== 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=WCk/CA+jozBck5AK8R4O4zwmWnyQS6sAEXmZdErb7+k=; b=HUZmr82IqrFReDe1IYr83Q6dbjE4Pj+kPV6Xxnofamd/ucuDFtL/TJsu83bpHH87EYrgbgeqHxfBkx31pP+tWTe+WpzBxbRmSDNTDSwkLmM82J3260SXzA8u1lykpc2MhV2dS5+Qp7DCTo7aM6AdMDPqZIjBfXVw5/Gds2ROtKq0EE8RxLUXnLtTpt3AM1ieOMYFy7MWQ57L4OJWODc7Qk3/rs2pGZowE1FmLZ73q6l6H0kutaKqfB1WSIPqsWQ+ESg7eP9sbRl/vGEtfI+p6uC47+ev/Zf+YE5C8K7QWvCaXyOeyofq6i/nu6W46gUBjjo6vEufeafBqqa4pnJ0tw== 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 DM5PR12MB1257.namprd12.prod.outlook.com (2603:10b6:3:74::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.24; Mon, 27 Jul 2020 18:43:56 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 18:43:56 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v12 42/46] UefiCpuPkg: Allow AP booting under SEV-ES Date: Mon, 27 Jul 2020 13:43:27 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM3PR03CA0020.namprd03.prod.outlook.com (2603:10b6:0:50::30) 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 DM3PR03CA0020.namprd03.prod.outlook.com (2603:10b6:0:50::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.21 via Frontend Transport; Mon, 27 Jul 2020 18:43: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: b22f8cc0-d6e9-4ff1-8e8b-08d8325d0430 X-MS-TrafficTypeDiagnostic: DM5PR12MB1257: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: mFZhGdRsr47WmdvKPjv/SVVicyscN5jG/hPRfEEtCaL5Py7O9Kd8MDIGx7b0i5+Q+wjgHa3a/Mk+5q7gvegOnhVw98hUHTim2Zqs5+Pf+puc1L1Nb6NryuIMV9nCy+HTI9tXSA5/6E2wDEdSlcYhIkKXX3NFE+VHjyYiI83DfUHsirnbmZEVxkz1UREbIrLm3Tn+IE8UWmmu0CWUa3cWmokdT1m7+uK0XhB9QVnvFOOmuSTkOB46krGmGKrJXoVeUtVawkMF8ZwXMvxYNsSJwZKzrjMf+QfIS4JBYICCg743w5/dYhU4UODeelBaxMIJrPf1I5foJgGVf8487qN2yiZo0xj4g398VLO1RBK0zgrYl/56HpFe08srTN8E7cYqbU8oUHQNbtQpJg2cMXxev8W4x6L47M3RV1vQIbtDuZuZneua675ntrDboMp0tOKCpR1WPVug16bwQW3Ynm2x3g== X-MS-Exchange-AntiSpam-MessageData: 5hPTJ0cef4GsiNf2BgYoZXel0wjVvtP+hcM2a1EqbaMkXsMvMLroRdrD/zlzBw5BUfTb98MgzDNBE9n64F4UUdOgJx4jXhT0N/SxFSv0seuss35OT00Nf9JCVHXQSwG/e62enNeacxz21bnPieD6A9iWowoc2E4iNqD6tsOwhAYUse7N1/oO2vdY5KsZk0PtSVQgM0wuR18tiHA3ETVqJG2fnq8c5uSn9fCYgZ/SO10V8lEiRAOtw3WBIiyXTVpjwDYtik4jKYXEnMi2ncGridm3xXJ0tX/uOsxqh3laWS5YeUopRYY6dqO4Xboy8LvLxaNxW6fBrjXM/4b1/gmrDXPaoVtG+esy8G2vwUzUQ8//S1UeANY5hoVBNLGabB0r8Owb+GlcJnmgFRbksy7/YIHHb6waOFBiqwPghW/ofAz+DKXrw4RmtlH44AK+H201g29muvDOfU40P0ARjqKAgmM9kEfq9HynF9N272CwE+A= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b22f8cc0-d6e9-4ff1-8e8b-08d8325d0430 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 18:43:55.9832 (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: N5DRz7afTfvzy851Eg4EBhuo7bWfImUNuSA6y+H4Ktb7u4BXCwtPiHw8I2PDYk9khLw7zkBHNNrSZCn4z9Gdbg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1257 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: pyxL59vIsXpmaqv7mWtzPxyZx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595875438; bh=fQjrqYWmecRYS9+eif1Om/xcOeF61MRt7po/lIM+viw=; h=Content-Type:Date:From:Reply-To:Subject:To; b=r08nPBb3c9KPlmhX8w0rpKl1tcGP6Qm0gW/X2VvG9J4tHQUyqOLWWu3wY/oeRogryZ2 UKExJlU/Lx/in1rjRbPgOslVSDTXGoCXYTy+7ufE9ea73hdd17FZN9UTq1TZf84lMp8ot uKoqlHHa8QyfHR4qW4xLeKESDx5PcCzFAhw= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Typically, an AP is booted using the INIT-SIPI-SIPI sequence. This sequence is intercepted by the hypervisor, which sets the AP's registers to the values requested by the sequence. At that point, the hypervisor can start the AP, which will then begin execution at the appropriate location. Under SEV-ES, AP booting presents some challenges since the hypervisor is not allowed to alter the AP's register state. In this situation, we have to distinguish between the AP's first boot and AP's subsequent boots. First boot: Once the AP's register state has been defined (which is before the guest is first booted) it cannot be altered. Should the hypervisor attempt to alter the register state, the change would be detected by the hardware and the VMRUN instruction would fail. Given this, the first boot for the AP is required to begin execution with this initial register state, which is typically the reset vector. This prevents the BSP from directing the AP startup location through the INIT-SIPI-SIPI sequence. To work around this, the firmware will provide a build time reserved area that can be used as the initial IP value. The hypervisor can extract this location value by checking for the SEV-ES reset block GUID that must be located 48-bytes from the end of the firmware. The format of the SEV-ES reset block area is: 0x00 - 0x01 - SEV-ES Reset IP 0x02 - 0x03 - SEV-ES Reset CS Segment Base[31:16] 0x04 - 0x05 - Size of the SEV-ES reset block 0x06 - 0x15 - SEV-ES Reset Block GUID (00f771de-1a7e-4fcb-890e-68c77e2fb44e) The total size is 22 bytes. Any expansion to this block must be done by adding new values before existing values. The hypervisor will use the IP and CS values obtained from the SEV-ES reset block to set as the AP's initial values. The CS Segment Base represents the upper 16 bits of the CS segment base and must be left shifted by 16 bits to form the complete CS segment base value. Before booting the AP for the first time, the BSP must initialize the SEV-ES reset area. This consists of programming a FAR JMP instruction to the contents of a memory location that is also located in the SEV-ES reset area. The BSP must program the IP and CS values for the FAR JMP based on values drived from the INIT-SIPI-SIPI sequence. Subsequent boots: Again, the hypervisor cannot alter the AP register state, so a method is required to take the AP out of halt state and redirect it to the desired IP location. If it is determined that the AP is running in an SEV-ES guest, then instead of calling CpuSleep(), a VMGEXIT is issued with the AP Reset Hold exit code (0x80000004). The hypervisor will put the AP in a halt state, waiting for an INIT-SIPI-SIPI sequence. Once the sequence is recognized, the hypervisor will resume the AP. At this point the AP must transition from the current 64-bit long mode down to 16-bit real mode and begin executing at the derived location from the INIT-SIPI-SIPI sequence. Another change is around the area of obtaining the (x2)APIC ID during AP startup. During AP startup, the AP can't take a #VC exception before the AP has established a stack. However, the AP stack is set by using the (x2)APIC ID, which is obtained through CPUID instructions. A CPUID instruction will cause a #VC, so a different method must be used. The GHCB protocol supports a method to obtain CPUID information from the hypervisor through the GHCB MSR. This method does not require a stack, so it is used to obtain the necessary CPUID information to determine the (x2)APIC ID. The new 16-bit protected mode GDT entry is used in order to transition from 64-bit long mode down to 16-bit real mode. A new assembler routine is created that takes the AP from 64-bit long mode to 16-bit real mode. This is located under 1MB in memory and transitions from 64-bit long mode to 32-bit compatibility mode to 16-bit protected mode and finally 16-bit real mode. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Reviewed-by: Eric Dong 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 | 336 +++++++++++++++++- UefiCpuPkg/Library/MpInitLib/PeiMpLib.c | 19 + UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmFuncsArch.c | 2 +- UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc | 2 +- .../Library/MpInitLib/Ia32/MpFuncs.nasm | 15 + UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc | 4 +- UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm | 239 +++++++++++++ 11 files changed, 738 insertions(+), 15 deletions(-) diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/DxeMpInitLib.inf index 583276595619..1771575c69c1 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf @@ -52,6 +52,7 @@ [LibraryClasses] DebugAgentLib SynchronizationLib PcdLib + VmgExitLib =20 [Protocols] gEfiTimerArchProtocolGuid ## SOMETIMES_CONSUMES @@ -72,4 +73,6 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate ## = SOMETIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApStatusCheckIntervalInMicroSeconds ## = CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled ## = CONSUMES + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase ## = SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ## = CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase ## = CONSUMES diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf b/UefiCpuPkg/Lib= rary/MpInitLib/PeiMpInitLib.inf index 4b3d39fbf36c..34abf25d43cd 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf @@ -51,6 +51,7 @@ [LibraryClasses] SynchronizationLib PeiServicesLib PcdLib + VmgExitLib =20 [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber ## CONS= UMES @@ -62,6 +63,8 @@ [Pcd] gUefiCpuPkgTokenSpaceGuid.PcdCpuApLoopMode ## CONS= UMES gUefiCpuPkgTokenSpaceGuid.PcdCpuApTargetCstate ## SOME= TIMES_CONSUMES gUefiCpuPkgTokenSpaceGuid.PcdSevEsIsEnabled ## CONS= UMES + gUefiCpuPkgTokenSpaceGuid.PcdSevEsWorkAreaBase ## SOME= TIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdGhcbBase ## CONS= UMES =20 [Ppis] gEdkiiPeiShadowMicrocodePpiGuid ## SOMETIMES_CONSUMES diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.h b/UefiCpuPkg/Library/MpIn= itLib/MpLib.h index 5b46c295b6b2..b1a9d99cb3eb 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -173,6 +173,11 @@ typedef struct { UINT8 *RelocateApLoopFuncAddress; UINTN RelocateApLoopFuncSize; UINTN ModeTransitionOffset; + UINTN SwitchToRealSize; + UINTN SwitchToRealOffset; + UINTN SwitchToRealNoNxOffset; + UINTN SwitchToRealPM16ModeOffset; + UINTN SwitchToRealPM16ModeSize; } MP_ASSEMBLY_ADDRESS_MAP; =20 typedef struct _CPU_MP_DATA CPU_MP_DATA; @@ -211,6 +216,8 @@ typedef struct { // Enable5LevelPaging indicates whether 5-level paging is enabled in lon= g mode. // BOOLEAN Enable5LevelPaging; + BOOLEAN SevEsIsEnabled; + UINTN GhcbBase; } MP_CPU_EXCHANGE_INFO; =20 #pragma pack() @@ -257,6 +264,7 @@ struct _CPU_MP_DATA { UINT8 ApLoopMode; UINT8 ApTargetCState; UINT16 PmCodeSegment; + UINT16 Pm16CodeSegment; CPU_AP_DATA *CpuData; volatile MP_CPU_EXCHANGE_INFO *MpCpuExchangeInfo; =20 @@ -278,8 +286,47 @@ struct _CPU_MP_DATA { BOOLEAN WakeUpByInitSipiSipi; =20 BOOLEAN SevEsIsEnabled; + UINTN SevEsAPBuffer; + UINTN SevEsAPResetStackStart; + CPU_MP_DATA *NewCpuMpData; + + UINT64 GhcbBase; }; =20 +#define AP_RESET_STACK_SIZE 64 + +#pragma pack(1) + +typedef struct { + UINT8 InsnBuffer[8]; + UINT16 Rip; + UINT16 Segment; +} SEV_ES_AP_JMP_FAR; + +#pragma pack() + +/** + Assembly code to move an AP from long mode to real mode. + + Move an AP from long mode to real mode in preparation to invoking + the reset vector. This is used for SEV-ES guests where a hypervisor + is not allowed to set the CS and RIP to point to the reset vector. + + @param[in] BufferStart The reset vector target. + @param[in] Code16 16-bit protected mode code segment value. + @param[in] Code32 32-bit protected mode code segment value. + @param[in] StackStart The start of a stack to be used for transitioni= ng + from long mode to real mode. +**/ +typedef +VOID +(EFIAPI AP_RESET) ( + IN UINTN BufferStart, + IN UINT16 Code16, + IN UINT16 Code32, + IN UINTN StackStart + ); + extern EFI_GUID mCpuInitMpLibHobGuid; =20 /** @@ -385,6 +432,19 @@ GetModeTransitionBuffer ( IN UINTN BufferSize ); =20 +/** + Return the address of the SEV-ES AP jump table. + + This buffer is required in order for an SEV-ES guest to transition from + UEFI into an OS. + + @return Return SEV-ES AP jump table buffer +**/ +UINTN +GetSevEsAPMemory ( + VOID + ); + /** This function will be called by BSP to wakeup AP. =20 diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/M= pInitLib/DxeMpLib.c index 8ccddf8e9f9c..9115ff9e3e30 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c @@ -12,6 +12,8 @@ #include #include #include +#include +#include =20 #include =20 @@ -144,6 +146,39 @@ GetModeTransitionBuffer ( return (UINTN)StartAddress; } =20 +/** + Return the address of the SEV-ES AP jump table. + + This buffer is required in order for an SEV-ES guest to transition from + UEFI into an OS. + + @return Return SEV-ES AP jump table buffer +**/ +UINTN +GetSevEsAPMemory ( + VOID + ) +{ + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS StartAddress; + + // + // Allocate 1 page for AP jump table page + // + StartAddress =3D BASE_4GB - 1; + Status =3D gBS->AllocatePages ( + AllocateMaxAddress, + EfiReservedMemoryType, + 1, + &StartAddress + ); + ASSERT_EFI_ERROR (Status); + + DEBUG ((DEBUG_INFO, "Dxe: SevEsAPMemory =3D %lx\n", (UINTN) StartAddress= )); + + return (UINTN) StartAddress; +} + /** Checks APs status and updates APs status if needed. =20 @@ -218,6 +253,38 @@ CheckApsStatus ( } } =20 +/** + Get Protected mode code segment with 16-bit default addressing + from current GDT table. + + @return Protected mode 16-bit code segment value. +**/ +UINT16 +GetProtectedMode16CS ( + VOID + ) +{ + IA32_DESCRIPTOR GdtrDesc; + IA32_SEGMENT_DESCRIPTOR *GdtEntry; + UINTN GdtEntryCount; + UINT16 Index; + + Index =3D (UINT16) -1; + AsmReadGdtr (&GdtrDesc); + GdtEntryCount =3D (GdtrDesc.Limit + 1) / sizeof (IA32_SEGMENT_DESCRIPTOR= ); + GdtEntry =3D (IA32_SEGMENT_DESCRIPTOR *) GdtrDesc.Base; + for (Index =3D 0; Index < GdtEntryCount; Index++) { + if (GdtEntry->Bits.L =3D=3D 0) { + if (GdtEntry->Bits.Type > 8 && GdtEntry->Bits.DB =3D=3D 0) { + break; + } + } + GdtEntry++; + } + ASSERT (Index !=3D GdtEntryCount); + return Index * 8; +} + /** Get Protected mode code segment from current GDT table. =20 @@ -238,7 +305,7 @@ GetProtectedModeCS ( GdtEntry =3D (IA32_SEGMENT_DESCRIPTOR *) GdtrDesc.Base; for (Index =3D 0; Index < GdtEntryCount; Index++) { if (GdtEntry->Bits.L =3D=3D 0) { - if (GdtEntry->Bits.Type > 8 && GdtEntry->Bits.L =3D=3D 0) { + if (GdtEntry->Bits.Type > 8 && GdtEntry->Bits.DB =3D=3D 1) { break; } } @@ -300,6 +367,7 @@ MpInitChangeApLoopCallback ( =20 CpuMpData =3D GetCpuMpData (); CpuMpData->PmCodeSegment =3D GetProtectedModeCS (); + CpuMpData->Pm16CodeSegment =3D GetProtectedMode16CS (); CpuMpData->ApLoopMode =3D PcdGet8 (PcdCpuApLoopMode); mNumberToFinish =3D CpuMpData->CpuCount - 1; WakeUpAP (CpuMpData, TRUE, 0, RelocateApLoop, NULL, TRUE); diff --git a/UefiCpuPkg/Library/MpInitLib/MpLib.c b/UefiCpuPkg/Library/MpIn= itLib/MpLib.c index 2a3fbeef35f7..90416c81b616 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.c @@ -9,6 +9,9 @@ **/ =20 #include "MpLib.h" +#include +#include +#include =20 EFI_GUID mCpuInitMpLibHobGuid =3D CPU_INIT_MP_LIB_HOB_GUID; =20 @@ -291,6 +294,14 @@ GetApLoopMode ( // ApLoopMode =3D ApInHltLoop; } + + if (PcdGetBool (PcdSevEsIsEnabled)) { + // + // For SEV-ES, force AP in Hlt-loop mode in order to use the GHCB + // protocol for starting APs + // + ApLoopMode =3D ApInHltLoop; + } } =20 if (ApLoopMode !=3D ApInMwaitLoop) { @@ -587,6 +598,112 @@ InitializeApData ( SetApState (&CpuMpData->CpuData[ProcessorNumber], CpuStateIdle); } =20 +/** + Get Protected mode code segment with 16-bit default addressing + from current GDT table. + + @return Protected mode 16-bit code segment value. +**/ +STATIC +UINT16 +GetProtectedMode16CS ( + VOID + ) +{ + IA32_DESCRIPTOR GdtrDesc; + IA32_SEGMENT_DESCRIPTOR *GdtEntry; + UINTN GdtEntryCount; + UINT16 Index; + + Index =3D (UINT16) -1; + AsmReadGdtr (&GdtrDesc); + GdtEntryCount =3D (GdtrDesc.Limit + 1) / sizeof (IA32_SEGMENT_DESCRIPTOR= ); + GdtEntry =3D (IA32_SEGMENT_DESCRIPTOR *) GdtrDesc.Base; + for (Index =3D 0; Index < GdtEntryCount; Index++) { + if (GdtEntry->Bits.L =3D=3D 0 && + GdtEntry->Bits.DB =3D=3D 0 && + GdtEntry->Bits.Type > 8) { + break; + } + GdtEntry++; + } + ASSERT (Index !=3D GdtEntryCount); + return Index * 8; +} + +/** + Get Protected mode code segment with 32-bit default addressing + from current GDT table. + + @return Protected mode 32-bit code segment value. +**/ +STATIC +UINT16 +GetProtectedMode32CS ( + VOID + ) +{ + IA32_DESCRIPTOR GdtrDesc; + IA32_SEGMENT_DESCRIPTOR *GdtEntry; + UINTN GdtEntryCount; + UINT16 Index; + + Index =3D (UINT16) -1; + AsmReadGdtr (&GdtrDesc); + GdtEntryCount =3D (GdtrDesc.Limit + 1) / sizeof (IA32_SEGMENT_DESCRIPTOR= ); + GdtEntry =3D (IA32_SEGMENT_DESCRIPTOR *) GdtrDesc.Base; + for (Index =3D 0; Index < GdtEntryCount; Index++) { + if (GdtEntry->Bits.L =3D=3D 0 && + GdtEntry->Bits.DB =3D=3D 1 && + GdtEntry->Bits.Type > 8) { + break; + } + GdtEntry++; + } + ASSERT (Index !=3D GdtEntryCount); + return Index * 8; +} + +/** + Reset an AP when in SEV-ES mode. + + If successful, this function never returns. + + @param[in] Ghcb Pointer to the GHCB + @param[in] CpuMpData Pointer to CPU MP Data + +**/ +STATIC +VOID +MpInitLibSevEsAPReset ( + IN GHCB *Ghcb, + IN CPU_MP_DATA *CpuMpData + ) +{ + UINT16 Code16, Code32; + AP_RESET *APResetFn; + UINTN BufferStart; + UINTN StackStart; + + Code16 =3D GetProtectedMode16CS (); + Code32 =3D GetProtectedMode32CS (); + + if (CpuMpData->WakeupBufferHigh !=3D 0) { + APResetFn =3D (AP_RESET *) (CpuMpData->WakeupBufferHigh + CpuMpData->A= ddressMap.SwitchToRealNoNxOffset); + } else { + APResetFn =3D (AP_RESET *) (CpuMpData->MpCpuExchangeInfo->BufferStart = + CpuMpData->AddressMap.SwitchToRealOffset); + } + + BufferStart =3D CpuMpData->MpCpuExchangeInfo->BufferStart; + StackStart =3D CpuMpData->SevEsAPResetStackStart - + (AP_RESET_STACK_SIZE * GetApicId ()); + + // + // This call never returns. + // + APResetFn (BufferStart, Code16, Code32, StackStart); +} + /** This function will be called from AP reset code if BSP uses WakeUpAP. =20 @@ -648,7 +765,14 @@ ApWakeupFunction ( InitializeApData (CpuMpData, ProcessorNumber, BistData, ApTopOfStack= ); ApStartupSignalBuffer =3D CpuMpData->CpuData[ProcessorNumber].Startu= pApSignal; =20 - InterlockedDecrement ((UINT32 *) &CpuMpData->MpCpuExchangeInfo->NumA= psExecuting); + // + // Delay decrementing the APs executing count when SEV-ES is enabled + // to allow the APs to issue an AP_RESET_HOLD before the BSP possibly + // performs another INIT-SIPI-SIPI sequence. + // + if (!CpuMpData->SevEsIsEnabled) { + InterlockedDecrement ((UINT32 *) &CpuMpData->MpCpuExchangeInfo->Nu= mApsExecuting); + } } else { // // Execute AP function if AP is ready @@ -755,7 +879,52 @@ ApWakeupFunction ( // while (TRUE) { DisableInterrupts (); - CpuSleep (); + if (CpuMpData->SevEsIsEnabled) { + MSR_SEV_ES_GHCB_REGISTER Msr; + GHCB *Ghcb; + UINT64 Status; + BOOLEAN DoDecrement; + + if (CpuMpData->InitFlag =3D=3D ApInitConfig) { + DoDecrement =3D TRUE; + } + + while (TRUE) { + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + Ghcb =3D Msr.Ghcb; + + VmgInit (Ghcb); + + if (DoDecrement) { + DoDecrement =3D FALSE; + + // + // Perform the delayed decrement just before issuing the fir= st + // VMGEXIT with AP_RESET_HOLD. + // + InterlockedDecrement ((UINT32 *) &CpuMpData->MpCpuExchangeIn= fo->NumApsExecuting); + } + + Status =3D VmgExit (Ghcb, SVM_EXIT_AP_RESET_HOLD, 0, 0); + if ((Status =3D=3D 0) && (Ghcb->SaveArea.SwExitInfo2 !=3D 0)) { + VmgDone (Ghcb); + break; + } + + VmgDone (Ghcb); + } + + // + // Awakened in a new phase? Use the new CpuMpData + // + if (CpuMpData->NewCpuMpData !=3D NULL) { + CpuMpData =3D CpuMpData->NewCpuMpData; + } + + MpInitLibSevEsAPReset (Ghcb, CpuMpData); + } else { + CpuSleep (); + } CpuPause (); } } @@ -868,6 +1037,9 @@ FillExchangeInfoData ( ExchangeInfo->Enable5LevelPaging =3D (BOOLEAN) (Cr4.Bits.LA57 =3D=3D 1); DEBUG ((DEBUG_INFO, "%a: 5-Level Paging =3D %d\n", gEfiCallerBaseName, E= xchangeInfo->Enable5LevelPaging)); =20 + ExchangeInfo->SevEsIsEnabled =3D CpuMpData->SevEsIsEnabled; + ExchangeInfo->GhcbBase =3D (UINTN) CpuMpData->GhcbBase; + // // Get the BSP's data of GDT and IDT // @@ -894,8 +1066,9 @@ FillExchangeInfoData ( // EfiBootServicesCode to avoid page fault if NX memory protection is en= abled. // if (CpuMpData->WakeupBufferHigh !=3D 0) { - Size =3D CpuMpData->AddressMap.RendezvousFunnelSize - - CpuMpData->AddressMap.ModeTransitionOffset; + Size =3D CpuMpData->AddressMap.RendezvousFunnelSize + + CpuMpData->AddressMap.SwitchToRealSize - + CpuMpData->AddressMap.ModeTransitionOffset; CopyMem ( (VOID *)CpuMpData->WakeupBufferHigh, CpuMpData->AddressMap.RendezvousFunnelAddress + @@ -948,7 +1121,8 @@ BackupAndPrepareWakeupBuffer( CopyMem ( (VOID *) CpuMpData->WakeupBuffer, (VOID *) CpuMpData->AddressMap.RendezvousFunnelAddress, - CpuMpData->AddressMap.RendezvousFunnelSize + CpuMpData->AddressMap.RendezvousFunnelSize + + CpuMpData->AddressMap.SwitchToRealSize ); } =20 @@ -969,6 +1143,44 @@ RestoreWakeupBuffer( ); } =20 +/** + Calculate the size of the reset stack. + + @return Total amount of memory required for stacks +**/ +STATIC +UINTN +GetApResetStackSize ( + VOID + ) +{ + return AP_RESET_STACK_SIZE * PcdGet32(PcdCpuMaxLogicalProcessorNumber); +} + +/** + Calculate the size of the reset vector. + + @param[in] AddressMap The pointer to Address Map structure. + + @return Total amount of memory required for the AP reset= area +**/ +STATIC +UINTN +GetApResetVectorSize ( + IN MP_ASSEMBLY_ADDRESS_MAP *AddressMap + ) +{ + UINTN Size; + + Size =3D ALIGN_VALUE (AddressMap->RendezvousFunnelSize + + AddressMap->SwitchToRealSize + + sizeof (MP_CPU_EXCHANGE_INFO), + CPU_STACK_ALIGNMENT); + Size +=3D GetApResetStackSize (); + + return Size; +} + /** Allocate reset vector buffer. =20 @@ -982,16 +1194,22 @@ AllocateResetVector ( UINTN ApResetVectorSize; =20 if (CpuMpData->WakeupBuffer =3D=3D (UINTN) -1) { - ApResetVectorSize =3D CpuMpData->AddressMap.RendezvousFunnelSize + - sizeof (MP_CPU_EXCHANGE_INFO); + ApResetVectorSize =3D GetApResetVectorSize (&CpuMpData->AddressMap); =20 CpuMpData->WakeupBuffer =3D GetWakeupBuffer (ApResetVectorSize); CpuMpData->MpCpuExchangeInfo =3D (MP_CPU_EXCHANGE_INFO *) (UINTN) - (CpuMpData->WakeupBuffer + CpuMpData->AddressMap.Rende= zvousFunnelSize); + (CpuMpData->WakeupBuffer + + CpuMpData->AddressMap.RendezvousFunnelSize + + CpuMpData->AddressMap.SwitchToRealSize); CpuMpData->WakeupBufferHigh =3D GetModeTransitionBuffer ( - CpuMpData->AddressMap.RendezvousFunnel= Size - + CpuMpData->AddressMap.RendezvousFunnel= Size + + CpuMpData->AddressMap.SwitchToRealSize= - CpuMpData->AddressMap.ModeTransitionOf= fset ); + // + // The reset stack starts at the end of the buffer. + // + CpuMpData->SevEsAPResetStackStart =3D CpuMpData->WakeupBuffer + ApRese= tVectorSize; } BackupAndPrepareWakeupBuffer (CpuMpData); } @@ -1006,7 +1224,80 @@ FreeResetVector ( IN CPU_MP_DATA *CpuMpData ) { - RestoreWakeupBuffer (CpuMpData); + // + // If SEV-ES is enabled, the reset area is needed for AP parking and + // and AP startup in the OS, so the reset area is reserved. Do not + // perform the restore as this will overwrite memory which has data + // needed by SEV-ES. + // + if (!CpuMpData->SevEsIsEnabled) { + RestoreWakeupBuffer (CpuMpData); + } +} + +/** + Allocate the SEV-ES AP jump table buffer. + + @param[in, out] CpuMpData The pointer to CPU MP Data structure. +**/ +VOID +AllocateSevEsAPMemory ( + IN OUT CPU_MP_DATA *CpuMpData + ) +{ + if (CpuMpData->SevEsAPBuffer =3D=3D (UINTN) -1) { + CpuMpData->SevEsAPBuffer =3D + CpuMpData->SevEsIsEnabled ? GetSevEsAPMemory () : 0; + } +} + +/** + Program the SEV-ES AP jump table buffer. + + @param[in] SipiVector The SIPI vector used for the AP Reset +**/ +VOID +SetSevEsJumpTable ( + IN UINTN SipiVector + ) +{ + SEV_ES_AP_JMP_FAR *JmpFar; + UINT32 Offset, InsnByte; + UINT8 LoNib, HiNib; + + JmpFar =3D (SEV_ES_AP_JMP_FAR *) FixedPcdGet32 (PcdSevEsWorkAreaBase); + ASSERT (JmpFar !=3D NULL); + + // + // Obtain the address of the Segment/Rip location in the workarea. + // This will be set to a value derived from the SIPI vector and will + // be the memory address used for the far jump below. + // + Offset =3D FixedPcdGet32 (PcdSevEsWorkAreaBase); + Offset +=3D sizeof (JmpFar->InsnBuffer); + LoNib =3D (UINT8) Offset; + HiNib =3D (UINT8) (Offset >> 8); + + // + // Program the workarea (which is the initial AP boot address) with + // far jump to the SIPI vector (where XX and YY represent the + // address of where the SIPI vector is stored. + // + // JMP FAR [CS:XXYY] =3D> 2E FF 2E YY XX + // + InsnByte =3D 0; + JmpFar->InsnBuffer[InsnByte++] =3D 0x2E; // CS override prefix + JmpFar->InsnBuffer[InsnByte++] =3D 0xFF; // JMP (FAR) + JmpFar->InsnBuffer[InsnByte++] =3D 0x2E; // ModRM (JMP memory location) + JmpFar->InsnBuffer[InsnByte++] =3D LoNib; // YY offset ... + JmpFar->InsnBuffer[InsnByte++] =3D HiNib; // XX offset ... + + // + // Program the Segment/Rip based on the SIPI vector (always at least + // 16-byte aligned, so Rip is set to 0). + // + JmpFar->Rip =3D 0; + JmpFar->Segment =3D (UINT16) (SipiVector >> 4); } =20 /** @@ -1043,6 +1334,7 @@ WakeUpAP ( CpuMpData->InitFlag !=3D ApInitDone) { ResetVectorRequired =3D TRUE; AllocateResetVector (CpuMpData); + AllocateSevEsAPMemory (CpuMpData); FillExchangeInfoData (CpuMpData); SaveLocalApicTimerSetting (CpuMpData); } @@ -1079,6 +1371,15 @@ WakeUpAP ( } } if (ResetVectorRequired) { + // + // For SEV-ES, the initial AP boot address will be defined by + // PcdSevEsWorkAreaBase. The Segment/Rip must be the jump address + // from the original INIT-SIPI-SIPI. + // + if (CpuMpData->SevEsIsEnabled) { + SetSevEsJumpTable (ExchangeInfo->BufferStart); + } + // // Wakeup all APs // @@ -1170,6 +1471,16 @@ WakeUpAP ( *(UINT32 *) CpuData->StartupApSignal =3D WAKEUP_AP_SIGNAL; if (ResetVectorRequired) { CpuInfoInHob =3D (CPU_INFO_IN_HOB *) (UINTN) CpuMpData->CpuInfoInHob; + + // + // For SEV-ES, the initial AP boot address will be defined by + // PcdSevEsWorkAreaBase. The Segment/Rip must be the jump address + // from the original INIT-SIPI-SIPI. + // + if (CpuMpData->SevEsIsEnabled) { + SetSevEsJumpTable (ExchangeInfo->BufferStart); + } + SendInitSipiSipi ( CpuInfoInHob[ProcessorNumber].ApicId, (UINT32) ExchangeInfo->BufferStart @@ -1646,7 +1957,7 @@ MpInitLibInitialize ( ASSERT (MaxLogicalProcessorNumber !=3D 0); =20 AsmGetAddressMap (&AddressMap); - ApResetVectorSize =3D AddressMap.RendezvousFunnelSize + sizeof (MP_CPU_E= XCHANGE_INFO); + ApResetVectorSize =3D GetApResetVectorSize (&AddressMap); ApStackSize =3D PcdGet32(PcdCpuApStackSize); ApLoopMode =3D GetApLoopMode (&MonitorFilterSize); =20 @@ -1705,6 +2016,8 @@ MpInitLibInitialize ( CpuMpData->CpuInfoInHob =3D (UINT64) (UINTN) (CpuMpData->CpuData + M= axLogicalProcessorNumber); InitializeSpinLock(&CpuMpData->MpLock); CpuMpData->SevEsIsEnabled =3D PcdGetBool (PcdSevEsIsEnabled); + CpuMpData->SevEsAPBuffer =3D (UINTN) -1; + CpuMpData->GhcbBase =3D PcdGet64 (PcdGhcbBase); =20 // // Make sure no memory usage outside of the allocated buffer. @@ -1763,6 +2076,7 @@ MpInitLibInitialize ( // APs have been wakeup before, just get the CPU Information // from HOB // + OldCpuMpData->NewCpuMpData =3D CpuMpData; CpuMpData->CpuCount =3D OldCpuMpData->CpuCount; CpuMpData->BspNumber =3D OldCpuMpData->BspNumber; CpuMpData->CpuInfoInHob =3D OldCpuMpData->CpuInfoInHob; diff --git a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c b/UefiCpuPkg/Library/M= pInitLib/PeiMpLib.c index a548fed23fa7..3989bd6a7a9f 100644 --- a/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/PeiMpLib.c @@ -280,6 +280,25 @@ GetModeTransitionBuffer ( return 0; } =20 +/** + Return the address of the SEV-ES AP jump table. + + This buffer is required in order for an SEV-ES guest to transition from + UEFI into an OS. + + @return Return SEV-ES AP jump table buffer +**/ +UINTN +GetSevEsAPMemory ( + VOID + ) +{ + // + // PEI phase doesn't need to do such transition. So simply return 0. + // + return 0; +} + /** Checks APs status and updates APs status if needed. =20 diff --git a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmFuncsArch.c b/UefiCpuPkg/PiSm= mCpuDxeSmm/X64/SmmFuncsArch.c index 6298571e29b2..28f8e8e133e5 100644 --- a/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmFuncsArch.c +++ b/UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmFuncsArch.c @@ -121,7 +121,7 @@ GetProtectedModeCS ( GdtEntry =3D (IA32_SEGMENT_DESCRIPTOR *) GdtrDesc.Base; for (Index =3D 0; Index < GdtEntryCount; Index++) { if (GdtEntry->Bits.L =3D=3D 0) { - if (GdtEntry->Bits.Type > 8 && GdtEntry->Bits.L =3D=3D 0) { + if (GdtEntry->Bits.Type > 8 && GdtEntry->Bits.DB =3D=3D 1) { break; } } diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc b/UefiCpuPkg/Libra= ry/MpInitLib/Ia32/MpEqu.inc index efb1bc2bf7cb..4f5a7c859a56 100644 --- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc +++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpEqu.inc @@ -19,7 +19,7 @@ CPU_SWITCH_STATE_IDLE equ 0 CPU_SWITCH_STATE_STORED equ 1 CPU_SWITCH_STATE_LOADED equ 2 =20 -LockLocation equ (RendezvousFunnelProcEnd - Rendez= vousFunnelProcStart) +LockLocation equ (SwitchToRealProcEnd - Rendezvous= FunnelProcStart) StackStartAddressLocation equ LockLocation + 04h StackSizeLocation equ LockLocation + 08h ApProcedureLocation equ LockLocation + 0Ch diff --git a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm b/UefiCpuPkg/Li= brary/MpInitLib/Ia32/MpFuncs.nasm index b74046b76af3..309d53bf3b37 100644 --- a/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm +++ b/UefiCpuPkg/Library/MpInitLib/Ia32/MpFuncs.nasm @@ -215,6 +215,16 @@ CProcedureInvoke: jmp $ ; Never reach here RendezvousFunnelProcEnd: =20 +;-------------------------------------------------------------------------= ------------ +;SwitchToRealProc procedure follows. +;NOT USED IN 32 BIT MODE. +;-------------------------------------------------------------------------= ------------ +global ASM_PFX(SwitchToRealProc) +ASM_PFX(SwitchToRealProc): +SwitchToRealProcStart: + jmp $ ; Never reach here +SwitchToRealProcEnd: + ;-------------------------------------------------------------------------= ------------ ; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfAp= Stack, CountTofinish); ;-------------------------------------------------------------------------= ------------ @@ -263,6 +273,11 @@ ASM_PFX(AsmGetAddressMap): mov dword [ebx + 0Ch], AsmRelocateApLoopStart mov dword [ebx + 10h], AsmRelocateApLoopEnd - AsmRelocateApLoop= Start mov dword [ebx + 14h], Flat32Start - RendezvousFunnelProcStart + mov dword [ebx + 18h], SwitchToRealProcEnd - SwitchToRealProcSt= art ; SwitchToRealSize + mov dword [ebx + 1Ch], SwitchToRealProcStart - RendezvousFunnel= ProcStart ; SwitchToRealOffset + mov dword [ebx + 20h], SwitchToRealProcStart - Flat32Start = ; SwitchToRealNoNxOffset + mov dword [ebx + 24h], 0 = ; SwitchToRealPM16ModeOffset + mov dword [ebx + 28h], 0 = ; SwitchToRealPM16ModeSize =20 popad ret diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc b/UefiCpuPkg/Librar= y/MpInitLib/X64/MpEqu.inc index 58ef369342a7..c92daaaffd6b 100644 --- a/UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc +++ b/UefiCpuPkg/Library/MpInitLib/X64/MpEqu.inc @@ -19,7 +19,7 @@ CPU_SWITCH_STATE_IDLE equ 0 CPU_SWITCH_STATE_STORED equ 1 CPU_SWITCH_STATE_LOADED equ 2 =20 -LockLocation equ (RendezvousFunnelProcEnd - Rendez= vousFunnelProcStart) +LockLocation equ (SwitchToRealProcEnd - Rendezvous= FunnelProcStart) StackStartAddressLocation equ LockLocation + 08h StackSizeLocation equ LockLocation + 10h ApProcedureLocation equ LockLocation + 18h @@ -41,3 +41,5 @@ ModeTransitionSegmentLocation equ LockLocation + 9= 8h ModeHighMemoryLocation equ LockLocation + 9Ah ModeHighSegmentLocation equ LockLocation + 9Eh Enable5LevelPagingLocation equ LockLocation + 0A0h +SevEsIsEnabledLocation equ LockLocation + 0A1h +GhcbBaseLocation equ LockLocation + 0A2h diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm b/UefiCpuPkg/Lib= rary/MpInitLib/X64/MpFuncs.nasm index 87f2523e856f..6956b408d004 100644 --- a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm +++ b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm @@ -184,9 +184,97 @@ Releaselock: add edi, StackStartAddressLocation add rax, qword [edi] mov rsp, rax + + lea edi, [esi + SevEsIsEnabledLocation] + cmp byte [edi], 1 ; SevEsIsEnabled + jne CProcedureInvoke + + ; + ; program GHCB + ; Each page after the GHCB is a per-CPU page, so the calculation pro= grams + ; a GHCB to be every 8KB. + ; + mov eax, SIZE_4KB + shl eax, 1 ; EAX =3D SIZE_4K * 2 + mov ecx, ebx + mul ecx ; EAX =3D SIZE_4K * 2 * C= puNumber + mov edi, esi + add edi, GhcbBaseLocation + add rax, qword [edi] + mov rdx, rax + shr rdx, 32 + mov rcx, 0xc0010130 + wrmsr jmp CProcedureInvoke =20 GetApicId: + lea edi, [esi + SevEsIsEnabledLocation] + cmp byte [edi], 1 ; SevEsIsEnabled + jne DoCpuid + + ; + ; Since we don't have a stack yet, we can't take a #VC + ; exception. Use the GHCB protocol to perform the CPUID + ; calls. + ; + mov rcx, 0xc0010130 + rdmsr + shl rdx, 32 + or rax, rdx + mov rdi, rax ; RDI now holds the original GHCB GPA + + mov rdx, 0 ; CPUID function 0 + mov rax, 0 ; RAX register requested + or rax, 4 + wrmsr + rep vmmcall + rdmsr + cmp edx, 0bh + jb NoX2ApicSevEs ; CPUID level below CPUID_EXTENDED_TOP= OLOGY + + mov rdx, 0bh ; CPUID function 0x0b + mov rax, 040000000h ; RBX register requested + or rax, 4 + wrmsr + rep vmmcall + rdmsr + test edx, 0ffffh + jz NoX2ApicSevEs ; CPUID.0BH:EBX[15:0] is zero + + mov rdx, 0bh ; CPUID function 0x0b + mov rax, 0c0000000h ; RDX register requested + or rax, 4 + wrmsr + rep vmmcall + rdmsr + + ; Processor is x2APIC capable; 32-bit x2APIC ID is now in EDX + jmp RestoreGhcb + +NoX2ApicSevEs: + ; Processor is not x2APIC capable, so get 8-bit APIC ID + mov rdx, 1 ; CPUID function 1 + mov rax, 040000000h ; RBX register requested + or rax, 4 + wrmsr + rep vmmcall + rdmsr + shr edx, 24 + +RestoreGhcb: + mov rbx, rdx ; Save x2APIC/APIC ID + + mov rdx, rdi ; RDI holds the saved GHCB GPA + shr rdx, 32 + mov eax, edi + wrmsr + + mov rdx, rbx + + ; x2APIC ID or APIC ID is in EDX + jmp GetProcessorNumber + +DoCpuid: mov eax, 0 cpuid cmp eax, 0bh @@ -253,12 +341,158 @@ CProcedureInvoke: =20 RendezvousFunnelProcEnd: =20 +;-------------------------------------------------------------------------= ------------ +;SwitchToRealProc procedure follows. +;ALSO THIS PROCEDURE IS EXECUTED BY APs TRANSITIONING TO 16 BIT MODE. HENC= E THIS PROC +;IS IN MACHINE CODE. +; SwitchToRealProc (UINTN BufferStart, UINT16 Code16, UINT16 Code32, UINT= N StackStart) +; rcx - Buffer Start +; rdx - Code16 Selector Offset +; r8 - Code32 Selector Offset +; r9 - Stack Start +;-------------------------------------------------------------------------= ------------ +global ASM_PFX(SwitchToRealProc) +ASM_PFX(SwitchToRealProc): +SwitchToRealProcStart: +BITS 64 + cli + + ; + ; Get RDX reset value before changing stacks since the + ; new stack won't be able to accomodate a #VC exception. + ; + push rax + push rbx + push rcx + push rdx + + mov rax, 1 + cpuid + mov rsi, rax ; Save off the reset value for = RDX + + pop rdx + pop rcx + pop rbx + pop rax + + ; + ; Establish stack below 1MB + ; + mov rsp, r9 + + ; + ; Push ultimate Reset Vector onto the stack + ; + mov rax, rcx + shr rax, 4 + push word 0x0002 ; RFLAGS + push ax ; CS + push word 0x0000 ; RIP + push word 0x0000 ; For alignment, will be discar= ded + + ; + ; Get address of "16-bit operand size" label + ; + lea rbx, [PM16Mode] + + ; + ; Push addresses used to change to compatibility mode + ; + lea rax, [CompatMode] + push r8 + push rax + + ; + ; Clear R8 - R15, for reset, before going into 32-bit mode + ; + xor r8, r8 + xor r9, r9 + xor r10, r10 + xor r11, r11 + xor r12, r12 + xor r13, r13 + xor r14, r14 + xor r15, r15 + + ; + ; Far return into 32-bit mode + ; +o64 retf + +BITS 32 +CompatMode: + ; + ; Set up stack to prepare for exiting protected mode + ; + push edx ; Code16 CS + push ebx ; PM16Mode label address + + ; + ; Disable paging + ; + mov eax, cr0 ; Read CR0 + btr eax, 31 ; Set PG=3D0 + mov cr0, eax ; Write CR0 + + ; + ; Disable long mode + ; + mov ecx, 0c0000080h ; EFER MSR number + rdmsr ; Read EFER + btr eax, 8 ; Set LME=3D0 + wrmsr ; Write EFER + + ; + ; Disable PAE + ; + mov eax, cr4 ; Read CR4 + btr eax, 5 ; Set PAE=3D0 + mov cr4, eax ; Write CR4 + + mov edx, esi ; Restore RDX reset value + + ; + ; Switch to 16-bit operand size + ; + retf + +BITS 16 + ; + ; At entry to this label + ; - RDX will have its reset value + ; - On the top of the stack + ; - Alignment data (two bytes) to be discarded + ; - IP for Real Mode (two bytes) + ; - CS for Real Mode (two bytes) + ; +PM16Mode: + mov eax, cr0 ; Read CR0 + btr eax, 0 ; Set PE=3D0 + mov cr0, eax ; Write CR0 + + pop ax ; Discard alignment data + + ; + ; Clear registers (except RDX and RSP) before going into 16-bit mode + ; + xor eax, eax + xor ebx, ebx + xor ecx, ecx + xor esi, esi + xor edi, edi + xor ebp, ebp + + iret + +SwitchToRealProcEnd: + ;-------------------------------------------------------------------------= ------------ ; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfAp= Stack, CountTofinish); ;-------------------------------------------------------------------------= ------------ global ASM_PFX(AsmRelocateApLoop) ASM_PFX(AsmRelocateApLoop): AsmRelocateApLoopStart: +BITS 64 cli ; Disable interrupt before switching to 3= 2-bit mode mov rax, [rsp + 40] ; CountTofinish lock dec dword [rax] ; (*CountTofinish)-- @@ -324,6 +558,11 @@ ASM_PFX(AsmGetAddressMap): mov qword [rcx + 18h], rax mov qword [rcx + 20h], AsmRelocateApLoopEnd - AsmRelocateApLoop= Start mov qword [rcx + 28h], Flat32Start - RendezvousFunnelProcStart + mov qword [rcx + 30h], SwitchToRealProcEnd - SwitchToRealProcSt= art ; SwitchToRealSize + mov qword [rcx + 38h], SwitchToRealProcStart - RendezvousFunnel= ProcStart ; SwitchToRealOffset + mov qword [rcx + 40h], SwitchToRealProcStart - Flat32Start = ; SwitchToRealNoNxOffset + mov qword [rcx + 48h], PM16Mode - RendezvousFunnelProcStart = ; SwitchToRealPM16ModeOffset + mov qword [rcx + 50h], SwitchToRealProcEnd - PM16Mode = ; SwitchToRealPM16ModeSize ret =20 ;-------------------------------------------------------------------------= ------------ --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63357): https://edk2.groups.io/g/devel/message/63357 Mute This Topic: https://groups.io/mt/75829478/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 Fri Apr 26 07:16:41 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+63358+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+63358+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 1595875445413840.2896243511361; Mon, 27 Jul 2020 11:44:05 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id vh4FYY1788612xnXuSTMtD1P; Mon, 27 Jul 2020 11:44:05 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.79]) by mx.groups.io with SMTP id smtpd.web10.62902.1595875444492914188 for ; Mon, 27 Jul 2020 11:44:04 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A+AZsvITNYdibkLapVICuPCPAFCiOoqfXpvAZ3fXh/WU0pA1pA0WGUigBfydE4MT53Lrh561PtzLwFK4UEyPDROeLAShTQuX4Mw0RhGjxoPhN95aWKRJ3GqJ83FImcVVqf7lFKiDDTiTe92Gav3YEPc2eom3pkTex6HppjdMjD9YyMuanoWLzxSrWZ3MixFW7/ye4gE0SmiLEk/6r67O/pRIjfLHkc3KND+khKh+zb5/tYzt/95KdHiSjPTfv/VQjv2Lu2rp9qCXszG1O6iK2cHlxKXemyU10cWYcjTPsA+lqmjJeH0/74VDKoCCd77WuoPT0hUFbvbeHNNtcPgVsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Cly63GpVgtcX7Qni9pbo9m94/AhxXLuSc1r4QOxC/u8=; b=WSCxNM2JLS/ot0Fo9ASNbyJPedXlaR0+XAw++ONGBg29+tHPe8lk3Zh0Mq5ormqHo6OaKWkTCpIAoHubYn82mNv1LkKmPXG/lceywHCAH0M6mHe5KFxEn3b96XZVgnwf6Yp1znqUn5aNNtt7SRXus2sjc0hCEJuoIb7RI0nAlxbssauZYcWW4eS06MvodfwCxrP7kJvg0coxY/wKpoO7wbM5pop6sDYH1eeLyQLspkdttYhAlPD+nfpC6sIp79tAEe2+Cs6CofgjXeqgxmZWsU1z4OBdxUfWYrzW8nzTVdsbX3p6uBVb3jkE14nmRMIjXs2zTkSLZMmWopeOZGFPiQ== 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 DM5PR12MB1257.namprd12.prod.outlook.com (2603:10b6:3:74::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.24; Mon, 27 Jul 2020 18:44:03 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 18:44:03 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v12 43/46] OvmfPkg: Use the SEV-ES work area for the SEV-ES AP reset vector Date: Mon, 27 Jul 2020 13:43:28 -0500 Message-ID: <66c37d51131b034a9006bfecfc4f1b37f9213c27.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM5PR13CA0055.namprd13.prod.outlook.com (2603:10b6:3:117::17) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR13CA0055.namprd13.prod.outlook.com (2603:10b6:3:117::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.9 via Frontend Transport; Mon, 27 Jul 2020 18:44: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: dc87b205-9cfa-41ac-07a1-08d8325d0899 X-MS-TrafficTypeDiagnostic: DM5PR12MB1257: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: ZOdEpKVcabvmR5+3ByX4+6GYGProlvOp/FmbWtNHI9EhwLp0zaZ8cFccE3ZyZw5MmWAFDIuZtFhOs4cTTSjEUmU9SOojzp9n1e0uQgqd+B9vh+WP75XiD/mk1DBEAnIvHv0jp9vtbtkhgr4oAX1iEYn5XhUl3qTrMers3PRMq8Xg3aHDe0j+TF3nericOn6sdJEdYdmhYNFRddqKxcILT8UY7JH2jxuLo/gjwRAQ8luNgyLAC5bkZAkJNp+dxNzYlUXbzreNR85SIaNIB/367WAzjLojPkC3a6ce9Zm/soDJWRyqZ6sgSbH1doQzNOuMr0VLvqxBv9WEJ4ACrZYMrTIgJDrz9nCk0guO2SMDoFGhTRrcj+RktMMWC6zNU+gMAg7Vzr3JXCozNeKIJy8AWFHwTEr/cjG55P6hl8CgYRWmWzvvp1IQjHiQ1bLPtArLBiwFxeLJZVwK1Q9Cy421Og== X-MS-Exchange-AntiSpam-MessageData: hhVkIqHARb6+MPRNv8CbgbIgsBv3uRCmx5vhdT8/uEWIlfVbjkX5ySUQNEqIEa1adOmBjMhQ7fe7f/F5+HLH/MAlY7kRoQFREJY4NBF9HzHe5ZYMOMXRLfmzgTMqzpAm2xyVeYo19Zy0ZetgEoV4wivelHbS4AYDGpg7altoQFjwdQpigsgwFaAbe9aW8FybWFWq0mCiT1lZKsx/OYRLMf6+6xrTveFrmA5Yb/7VtLPMc4nlAZmdFS4imbrJ7METzeoFqwbMewjYEskk9T5Xg4cmHDO0z/uz9mFV3owMdd7rdLljxnh9hHqZAR/izgDuuN6qpsW1BcjavCtUEdxJG4O4DFOdP2ij1BIqEmF3tTLDjo4HKfF0BYLVjztJzYk49K3QjofklukyQ3ILieTJst5VIaNDBe8iZktZL/GGui3Ff9h3ik37MPDBgrkhqxEhHv+TmhNyGEH1HT8Kvgy9uOeHHuvudE9dZFoesTAQsao= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: dc87b205-9cfa-41ac-07a1-08d8325d0899 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 18:44:03.2428 (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: 1dvcPyTSKF9taE3ncsARQHWe7h02LmSjhYkAvY4CAjsHTnFMbaxshUCbh0VLglLGSeDtudxTz0WcPWMOyjy6+w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1257 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: M7RteXk7ApktHzNMqYAHem56x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595875445; bh=Gagf0eRGit/hkROS66hMrbMGlJlh7asr0NwwYBiNcSc=; h=Content-Type:Date:From:Reply-To:Subject:To; b=R4muDfLCDrFiuiqg0XR0cwivIXhG/9YCPK4OyiqWFSuVhvR63cR8D5+Vmtug85tkVFw gI1Nhh5CRO6KJPszpKMC0xUvYBzjdvrv8O5V7jypwxUza8LAok62Hyr/VdVYXXm+NvGoO mCeyVk/Gx4jXGZ3v0/UMimXiOsQZuouenY8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 A hypervisor is not allowed to update an SEV-ES guest's register state, so when booting an SEV-ES guest AP, the hypervisor is not allowed to set the RIP to the guest requested value. Instead an SEV-ES AP must be re-directed from within the guest to the actual requested staring location as specified in the INIT-SIPI-SIPI sequence. Use the SEV-ES work area for the reset vector code that contains support to jump to the desired RIP location after having been started. This is required for only the very first AP reset. This new OVMF source file, ResetVectorVtf0.asm, is used in place of the original file through the use of the include path order set in OvmfPkg/ResetVector/ResetVector.inf under "[BuildOptions]". Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm | 100 +++++++++++++++++++ OvmfPkg/ResetVector/ResetVector.nasmb | 1 + 2 files changed, 101 insertions(+) create mode 100644 OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm diff --git a/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm b/OvmfPkg/ResetVe= ctor/Ia16/ResetVectorVtf0.asm new file mode 100644 index 000000000000..980e0138e7fe --- /dev/null +++ b/OvmfPkg/ResetVector/Ia16/ResetVectorVtf0.asm @@ -0,0 +1,100 @@ +;-------------------------------------------------------------------------= ----- +; @file +; First code executed by processor after resetting. +; Derived from UefiCpuPkg/ResetVector/Vtf0/Ia16/ResetVectorVtf0.asm +; +; Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.
+; SPDX-License-Identifier: BSD-2-Clause-Patent +; +;-------------------------------------------------------------------------= ----- + +BITS 16 + +ALIGN 16 + +; +; Pad the image size to 4k when page tables are in VTF0 +; +; If the VTF0 image has page tables built in, then we need to make +; sure the end of VTF0 is 4k above where the page tables end. +; +; This is required so the page tables will be 4k aligned when VTF0 is +; located just below 0x100000000 (4GB) in the firmware device. +; +%ifdef ALIGN_TOP_TO_4K_FOR_PAGING + TIMES (0x1000 - ($ - EndOfPageTables) - 0x20) DB 0 +%endif + +; +; SEV-ES Processor Reset support +; +; sevEsResetBlock: +; For the initial boot of an AP under SEV-ES, the "reset" RIP must be +; programmed to the RAM area defined by SEV_ES_AP_RESET_IP. A known offs= et +; and GUID will be used to locate this block in the firmware and extract +; the build time RIP value. The GUID must always be 48 bytes from the +; end of the firmware. +; +; 0xffffffca (-0x36) - IP value +; 0xffffffcc (-0x34) - CS segment base [31:16] +; 0xffffffce (-0x32) - Size of the SEV-ES reset block +; 0xffffffd0 (-0x30) - SEV-ES reset block GUID +; (00f771de-1a7e-4fcb-890e-68c77e2fb44e) +; +; A hypervisor reads the CS segement base and IP value. The CS segment b= ase +; value represents the high order 16-bits of the CS segment base, so the +; hypervisor must left shift the value of the CS segement base by 16 bit= s to +; form the full CS segment base for the CS segment register. It would th= en +; program the EIP register with the IP value as read. +; + +TIMES (32 - (sevEsResetBlockEnd - sevEsResetBlockStart)) DB 0 + +sevEsResetBlockStart: + DD SEV_ES_AP_RESET_IP + DW sevEsResetBlockEnd - sevEsResetBlockStart + DB 0xDE, 0x71, 0xF7, 0x00, 0x7E, 0x1A, 0xCB, 0x4F + DB 0x89, 0x0E, 0x68, 0xC7, 0x7E, 0x2F, 0xB4, 0x4E +sevEsResetBlockEnd: + +ALIGN 16 + +applicationProcessorEntryPoint: +; +; Application Processors entry point +; +; GenFv generates code aligned on a 4k boundary which will jump to this +; location. (0xffffffe0) This allows the Local APIC Startup IPI to be +; used to wake up the application processors. +; + jmp EarlyApInitReal16 + +ALIGN 8 + + DD 0 + +; +; The VTF signature +; +; VTF-0 means that the VTF (Volume Top File) code does not require +; any fixups. +; +vtfSignature: + DB 'V', 'T', 'F', 0 + +ALIGN 16 + +resetVector: +; +; Reset Vector +; +; This is where the processor will begin execution +; + nop + nop + jmp EarlyBspInitReal16 + +ALIGN 16 + +fourGigabytes: + diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb b/OvmfPkg/ResetVector/Re= setVector.nasmb index 762661115d50..4913b379a993 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -82,5 +82,6 @@ =20 %include "Main.asm" =20 + %define SEV_ES_AP_RESET_IP FixedPcdGet32 (PcdSevEsWorkAreaBase) %include "Ia16/ResetVectorVtf0.asm" =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63358): https://edk2.groups.io/g/devel/message/63358 Mute This Topic: https://groups.io/mt/75829481/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 Fri Apr 26 07:16:41 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+63359+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+63359+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 1595875452699362.9074960511483; Mon, 27 Jul 2020 11:44:12 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id BI9bYY1788612xJ9bNRfbybH; Mon, 27 Jul 2020 11:44:12 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.52]) by mx.groups.io with SMTP id smtpd.web10.62906.1595875451711785417 for ; Mon, 27 Jul 2020 11:44:11 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VL98dDj+HHZqgQxqEEmjA89KBbPg/WsOqc23Si6gSUjnYf+R5ECSQfUz4JD72oyA1GBtt3pdvRRRr7aJ0XtaL2bEK7nrgJrM5Q4Jxu5Po2HSwYjftxBZEzJPPYwU1e5JmnnAG7Eba9KtgUmz80R55OzFHKJGiMBfVUWDsQLYA1ll/O6uejAjaLrvNHazNSlzGQfRU8MLBHk8h9NxGMyf6YjukwBYgeL6RfnbygBtm+oJOoBHpKYsZFz/H2Gn5TlpZgb0gLIHY1JFpPNb+7eGjf8lk+0GBYk8MHwJZaqFGWo/nYQ1gz3e4FgxNUwzWpCR6a7d3+9UbDaIflXoLg9lKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cYWmh/fcAwIXIlWubzjDdUIKKdxtd9nRLkFVJO7hvKY=; b=Xf4oNAPbLoMJ2lPHFmQGax8J9EHJ8w6IMVezbnil4euDRrMxZdB9zN/zFyn3GaeDNjD14AydZ8vpTS/qHMpjhrdzrDr/5aOpjOaOiyl+v+celOItTl1TvZ4pEFQQB6kysGNIq09bQL6x+eQMhGJwyFzvCaMPWLHI817ch3xaKvU44BgG6oMQv4jul6TjkKTgowLRAnYqH7Fhfv2KP56yng7dIUZ1T4eX/fZhAB9aEZly2XO890NbDwA3b3PJDXR1yNkqFaUDHIEvjQf9ap08C0O3nx28a7uIMacfUSgfvaxOAsxSYB1CijNPfsWGiVNCi22oGU7uFHb4mztFgY22xg== 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 DM5PR12MB1257.namprd12.prod.outlook.com (2603:10b6:3:74::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.24; Mon, 27 Jul 2020 18:44:10 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 18:44:10 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v12 44/46] OvmfPkg: Move the GHCB allocations into reserved memory Date: Mon, 27 Jul 2020 13:43:29 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR19CA0040.namprd19.prod.outlook.com (2603:10b6:3:9a::26) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM5PR19CA0040.namprd19.prod.outlook.com (2603:10b6:3:9a::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.21 via Frontend Transport; Mon, 27 Jul 2020 18:44:10 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 2391125b-2e89-4396-ecc7-08d8325d0d0e X-MS-TrafficTypeDiagnostic: DM5PR12MB1257: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3044; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: PK7TrnF0yEPrn9WArKEnxjTH18IrJTOurZ1Xmz5ABJjchxHrjqoL7XwYmbPLskIFuF7OrhK8QhGPqG0bqSZ18bvJADNZjd81B+UPbHtosDRsJT5Mutez17FJSj7cMea7M4qIq2DRSDtMWGnu/XPpFqkl8XBygW+yZOvOofuBFZ30bMv5z2MqCI6EMXzJ/v6FknDfydyHugVeXKBn7uIFg332I10KbZE5AdtkYGlMYtHgUaz3NLZT96pr3rR8ZivbnqI1UFnCZyHxQ4jP2XVqpbmY48G8Sg9sNuTXBoFwMK2PvMOkLFUf0QxvdAsp/gJ1Z+eY6k/4Ve+WmdTFBACshJ/7Y6fpqXLj/HfmUBF1pzCHycQVkwe4IuaJ6O8K8oA/tOakcFPkjaKoIYs7kqCekXvFY6bWbL4ZqMCxyv48sf35KEpKyPFhhO0OOLXQ7mF59UgKO3wQLz9hgL9B3uP3WA== X-MS-Exchange-AntiSpam-MessageData: QEwGWGqdPmyuQKcEjRMQt+w3WTshq8E9SLweusbGw+/JfdkYZ+HaEvHUbAqGGCfU55a7RLsf6RnBBZb3MK1EZqe1SB2s9uvsiJaFT1Cp7BCWO4yiBmosXfvfB9oodTRJD+AqxpFLub0qGrk68Q5jpQclQZwofPtlXCS96kHYmMafu+Ol+DLRWnY+V8fKOzexx77qnESSBRofmmkfQMEbIgpTC4IKVuFAuiM+UlM9gL1ofN2k9zzBzweFpXhsE2+WGf8MDJJ90ct4wRNsNfFLfB3vyeTC+rpeXZkrtGP0qmZaXpVCxgFV1kqpBWUk5rnqk8LMIxVt9Tlt10HULLpEjpBeA8svB8CY3rON3X7nukFf2q0YPqtTdHpGwzhkR5KLCz/tSQKwqSVfbQEj1vvwwMSaG+zzBVMOifTdiRNrizdzOPphB79BpBujkbFVVsivb4i0oYsNtZvBOY6l+jjd7tlXh7M35x8kon0tmp+YiGs= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2391125b-2e89-4396-ecc7-08d8325d0d0e X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 18:44:10.7453 (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: xJMeNXR1YxqWzeV++M8le4CNxyrS6U/eGlrnTSCEVig4q5453449EHYK5nxM3wIxlo6rNcD6jw1/ghf8qtTlvQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1257 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: HlfYYT3U7jUzmmotu5fVUYQcx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595875452; bh=/8XgfXd6EqFEQ1OLKgVvCaxeOhfI7PXiG0O1ZdAxoLI=; h=Content-Type:Date:From:Reply-To:Subject:To; b=OCMl8a/k+S32Yz0BcpPCracEKVXNyOq1oKSSt6+WizzFdZTTtLqUU6eQRFDI8v3JeoQ 7TJdDZKTu6CSwvjftozc/UQlZ0baE2gFxGXfC8gLst3c07SB769VvMjBEVmUNuGYLOTfR KAvVHRtpnw+R2hOXnrAsLbGUrI8Hbqn8LJU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 After having transitioned from UEFI to the OS, the OS will need to boot the APs. For an SEV-ES guest, the APs will have been parked by UEFI using GHCB pages allocated by UEFI. The hypervisor will write to the GHCB SW_EXITINFO2 field of the GHCB when the AP is booted. As a result, the GHCB pages must be marked reserved so that the OS does not attempt to use them and experience memory corruption because of the hypervisor write. Change the GHCB allocation from the default boot services memory to reserved memory. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/PlatformPei/AmdSev.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/PlatformPei/AmdSev.c b/OvmfPkg/PlatformPei/AmdSev.c index a2b38c591236..4a515a484720 100644 --- a/OvmfPkg/PlatformPei/AmdSev.c +++ b/OvmfPkg/PlatformPei/AmdSev.c @@ -51,9 +51,11 @@ AmdSevEsInitialize ( =20 // // Allocate GHCB and per-CPU variable pages. + // Since the pages must survive across the UEFI to OS transition + // make them reserved. // GhcbPageCount =3D mMaxCpuCount * 2; - GhcbBase =3D AllocatePages (GhcbPageCount); + GhcbBase =3D AllocateReservedPages (GhcbPageCount); ASSERT (GhcbBase !=3D NULL); =20 GhcbBasePa =3D (PHYSICAL_ADDRESS)(UINTN) GhcbBase; --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63359): https://edk2.groups.io/g/devel/message/63359 Mute This Topic: https://groups.io/mt/75829487/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 Fri Apr 26 07:16:41 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+63360+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+63360+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 1595875460518570.829626791102; Mon, 27 Jul 2020 11:44:20 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id aWVLYY1788612xdUn2VSAOIJ; Mon, 27 Jul 2020 11:44:19 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.41]) by mx.groups.io with SMTP id smtpd.web11.62699.1595875459352844781 for ; Mon, 27 Jul 2020 11:44:19 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IG2gZYCuO/ooI8plyPf++tblKrc1e/sgLDofZDqnaI7+ixBgM6TnerLVjImQgxucqppOPt1Bgv9BTqggnhitKUQl7eGripAGhcU7OZHXpGBjTHNtOOiaXVl/2oP6KOyGJf94b3kvW8g22JycsG9yHQ9eDsWkEH63rSnUwO1Ncz0c+OefgkhX3hi9WSdQv1Sh5VJXT49yYDQ1R8Gp7Ngwx1N0kwJk47UKzenH6A/YlNHSRnDSFo1NmdWV75mnzcQilMBcRdLuFTlYgvitLuOmT5StUNhoTpWojt8SKBkuRH+aMkH5ZRdZxsM3wooDpvc7roH0qGhwObKUKoj++CscWg== 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=NB9l/B18lE6yAUYEdm6Gf7eEH/WJWN/404HvIJKlhK4=; b=MypgQV+7s4tKsPjkxOP92zr/g2iuLhL2gcc6Wu+qfgQhCZgbsp1cICQ0YKPUbaOgNEw4lAeAUyU2slY335vnQAjCUzlsd8xtqc+p5mgIl67dRpc5sLjmdU8Nvl/2M8G2M4F2HVfanI8S29sY34GUM1wEPEtTVgSQsROfq6o1u3YpyqXhFMS77AQVutmDOOj7g9j/LcVExBe1vSk5RTZpdRxgtWp2n//aPs4y+39+dOq/URu0XBZvj0MoHEDfDEK00COgmDtfgKk3PgOj9KmMnYjAhYTOi+I7Ux7uKwpbEiOS2jCWpy8kp3o8AzMlaxHhb6TSnbl8h3Y+gRBU2rypog== 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 DM5PR12MB1257.namprd12.prod.outlook.com (2603:10b6:3:74::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.24; Mon, 27 Jul 2020 18:44:18 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 18:44:18 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v12 45/46] UefiCpuPkg/MpInitLib: Prepare SEV-ES guest APs for OS use Date: Mon, 27 Jul 2020 13:43:30 -0500 Message-ID: <8c93a934b505c89fd2d29ccdee1a50b425c7db85.1595863587.git.thomas.lendacky@amd.com> In-Reply-To: References: X-ClientProxiedBy: DM6PR13CA0049.namprd13.prod.outlook.com (2603:10b6:5:134::26) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Received: from tlendack-t1.amd.com (165.204.77.1) by DM6PR13CA0049.namprd13.prod.outlook.com (2603:10b6:5:134::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.10 via Frontend Transport; Mon, 27 Jul 2020 18:44:17 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 75fa6624-5743-4c85-88e3-08d8325d1179 X-MS-TrafficTypeDiagnostic: DM5PR12MB1257: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: xEnsBgl6zLWxQtKGoArXwI/bniwa+U1W++sRp10fGwsplYyOAct+9bTXwsXtFk12h3sJdcVEw9WeP8PNRrghOOj/dO3WtaOH0EHFRG5izdgyTX9FyTUkoNQ4ORHwU7uVd2iFvOq8N5XD6M6YdbLuvwZG/bQCsTEQkGZDGoVuzntXNUgcB1BEXYV7NigsH0RW/O4Fl4MiXvdkW47Afloy5J7zRZwpI6sHboWkjSRQmpNi/pUXDiCis8djFkuV8Ak3K7H6am+PjCgrPPxg9TjiiiFSaUyC5LUN6TZse8/mIydhl6Hbq1uQjYLj23rnrH1wQQKiNiBC5FW5ngdiezrHhW3Th5lATshAK4ARIzIdDJIICr4NiXtxmrSGpUGPKYwMgNIdueA8BLnRJ6TpIjZlo686vumqBkXICbwp8aor3dueyeX58AmQ4RxI2+7k+mEsFoqJF7gMPo5Gfeq8V5U0Ag== X-MS-Exchange-AntiSpam-MessageData: M4SW57awj2Dwdkuy+YzWz0aqyg1nRV/ar8yAznYLHxtqn+lsqBwqWfJiNWmCdqupFpcstuc0fx/PSq2Qb81TrpZpgUd0YPUeLipaKbxA9Ij1wGtHRed5aEOin2b4jjLl0EBe15sL5Z008COgVGYi4Cn0Tk7q+nk0tiQMzxaJUmA8B0+lkyHJlJ+Zo3f5tpjYnZcHkejbOrSNwADIbLdLepQYcRvv94BLsR4Ra6HH8KxqZryTgTKoV+PEpmoEYhDYyGN6sbXWxZGiNqN18TnUQbwJcxsqCTyGYtpe/2ci00hgNG2zVsZKPhcF/c7LvvwP+2JHpSGHnHspxrzsA8VvhkTkrw7ht1v7lwjwCUrUvTXVvWHSUiFuLykaIR+0ZvkaJ6k5M/Y0s1Y4Cs81RWBcG/BtzQgKWjdn/bBvp0EQ05rRk+JJW3ynYcEEhFp4Ie13LWd2gqO4uEnEV6m1FHUMeWPvBAYXLnf9DtaUwiAVAxE= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 75fa6624-5743-4c85-88e3-08d8325d1179 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 18:44:18.1888 (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: Xqxmjd/DT6dNMJOM2BXjogauWxjwDXAvTH0wKsCPRe2bhmEdcscpX+imhHU5U9BDbAWFi9IocIPpchOdkBzFQA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1257 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: XRWrjEMskkGPX82D3HKkMiRcx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595875459; bh=r0EuAxfcJSCBIn/LF9Givie0Vim7fo82jziS6yWVVUs=; h=Content-Type:Date:From:Reply-To:Subject:To; b=T9MqiZFPFdUlZrIKmL0eQp1Nib0p93xt5+6fJkeZnxYnX7EOABytGZAbbfmdn7HWDvB UWcAJOEI1rj9/BXIfQWb30Ei4vTlqMAKVUD5+syvHYyYPdWkLFtfSr12+eRcSrz4PRezX JmQS/ZUkZ2BWhlKFKnyxri1AuoNCRQ7k8sg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Before UEFI transfers control to the OS, it must park the AP. This is done using the AsmRelocateApLoop function to transition into 32-bit non-paging mode. For an SEV-ES guest, a few additional things must be done: - AsmRelocateApLoop must be updated to support SEV-ES. This means performing a VMGEXIT AP Reset Hold instead of an MWAIT or HLT loop. - Since the AP must transition to real mode, a small routine is copied to the WakeupBuffer area. Since the WakeupBuffer will be used by the AP during OS booting, it must be placed in reserved memory. Additionally, the AP stack must be located where it can be accessed in real mode. - Once the AP is in real mode it will transfer control to the destination specified by the OS in the SEV-ES AP Jump Table. The SEV-ES AP Jump Table address is saved by the hypervisor for the OS using the GHCB VMGEXIT AP Jump Table exit code. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Reviewed-by: Eric Dong 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 b1a9d99cb3eb..267aa5201c50 100644 --- a/UefiCpuPkg/Library/MpInitLib/MpLib.h +++ b/UefiCpuPkg/Library/MpInitLib/MpLib.h @@ -293,7 +293,8 @@ struct _CPU_MP_DATA { UINT64 GhcbBase; }; =20 -#define AP_RESET_STACK_SIZE 64 +#define AP_SAFE_STACK_SIZE 128 +#define AP_RESET_STACK_SIZE AP_SAFE_STACK_SIZE =20 #pragma pack(1) =20 @@ -349,8 +350,11 @@ VOID IN BOOLEAN MwaitSupport, IN UINTN ApTargetCState, IN UINTN PmCodeSegment, + IN UINTN Pm16CodeSegment, IN UINTN TopOfApStack, - IN UINTN NumberToFinish + IN UINTN NumberToFinish, + IN UINTN SevEsAPJumpTable, + IN UINTN WakeupBuffer ); =20 /** diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c b/UefiCpuPkg/Library/M= pInitLib/DxeMpLib.c index 9115ff9e3e30..7165bcf3124a 100644 --- a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c +++ b/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include =20 @@ -85,6 +86,13 @@ GetWakeupBuffer ( { EFI_STATUS Status; EFI_PHYSICAL_ADDRESS StartAddress; + EFI_MEMORY_TYPE MemoryType; + + if (PcdGetBool (PcdSevEsIsEnabled)) { + MemoryType =3D EfiReservedMemoryType; + } else { + MemoryType =3D EfiBootServicesData; + } =20 // // Try to allocate buffer below 1M for waking vector. @@ -97,7 +105,7 @@ GetWakeupBuffer ( StartAddress =3D 0x88000; Status =3D gBS->AllocatePages ( AllocateMaxAddress, - EfiBootServicesData, + MemoryType, EFI_SIZE_TO_PAGES (WakeupBufferSize), &StartAddress ); @@ -159,8 +167,10 @@ GetSevEsAPMemory ( VOID ) { - EFI_STATUS Status; - EFI_PHYSICAL_ADDRESS StartAddress; + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS StartAddress; + MSR_SEV_ES_GHCB_REGISTER Msr; + GHCB *Ghcb; =20 // // Allocate 1 page for AP jump table page @@ -176,6 +186,16 @@ GetSevEsAPMemory ( =20 DEBUG ((DEBUG_INFO, "Dxe: SevEsAPMemory =3D %lx\n", (UINTN) StartAddress= )); =20 + // + // Save the SevEsAPMemory as the AP jump table. + // + Msr.GhcbPhysicalAddress =3D AsmReadMsr64 (MSR_SEV_ES_GHCB); + Ghcb =3D Msr.Ghcb; + + VmgInit (Ghcb); + VmgExit (Ghcb, SVM_EXIT_AP_JUMP_TABLE, 0, (UINT64) (UINTN) StartAddress); + VmgDone (Ghcb); + return (UINTN) StartAddress; } =20 @@ -330,17 +350,26 @@ RelocateApLoop ( BOOLEAN MwaitSupport; ASM_RELOCATE_AP_LOOP AsmRelocateApLoopFunc; UINTN ProcessorNumber; + UINTN StackStart; =20 MpInitLibWhoAmI (&ProcessorNumber); CpuMpData =3D GetCpuMpData (); MwaitSupport =3D IsMwaitSupport (); + if (CpuMpData->SevEsIsEnabled) { + StackStart =3D CpuMpData->SevEsAPResetStackStart; + } else { + StackStart =3D mReservedTopOfApStack; + } AsmRelocateApLoopFunc =3D (ASM_RELOCATE_AP_LOOP) (UINTN) mReservedApLoop= Func; AsmRelocateApLoopFunc ( MwaitSupport, CpuMpData->ApTargetCState, CpuMpData->PmCodeSegment, - mReservedTopOfApStack - ProcessorNumber * AP_SAFE_STACK_SIZE, - (UINTN) &mNumberToFinish + CpuMpData->Pm16CodeSegment, + StackStart - ProcessorNumber * AP_SAFE_STACK_SIZE, + (UINTN) &mNumberToFinish, + CpuMpData->SevEsAPBuffer, + CpuMpData->WakeupBuffer ); // // It should never reach here @@ -374,6 +403,21 @@ MpInitChangeApLoopCallback ( while (mNumberToFinish > 0) { CpuPause (); } + + if (CpuMpData->SevEsIsEnabled && (CpuMpData->WakeupBuffer !=3D (UINTN) -= 1)) { + // + // There are APs present. Re-use reserved memory area below 1MB from + // WakeupBuffer as the area to be used for transitioning to 16-bit mode + // in support of booting of the AP by an OS. + // + CopyMem ( + (VOID *) CpuMpData->WakeupBuffer, + (VOID *) (CpuMpData->AddressMap.RendezvousFunnelAddress + + CpuMpData->AddressMap.SwitchToRealPM16ModeOffset), + CpuMpData->AddressMap.SwitchToRealPM16ModeSize + ); + } + DEBUG ((DEBUG_INFO, "%a() done!\n", __FUNCTION__)); } =20 diff --git a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm b/UefiCpuPkg/Lib= rary/MpInitLib/X64/MpFuncs.nasm index 6956b408d004..3b8ec477b8b3 100644 --- a/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm +++ b/UefiCpuPkg/Library/MpInitLib/X64/MpFuncs.nasm @@ -465,6 +465,10 @@ BITS 16 ; - IP for Real Mode (two bytes) ; - CS for Real Mode (two bytes) ; + ; This label is also used with AsmRelocateApLoop. During MP finalizati= on, + ; the code from PM16Mode to SwitchToRealProcEnd is copied to the start= of + ; the WakeupBuffer, allowing a parked AP to be booted by an OS. + ; PM16Mode: mov eax, cr0 ; Read CR0 btr eax, 0 ; Set PE=3D0 @@ -487,32 +491,95 @@ PM16Mode: SwitchToRealProcEnd: =20 ;-------------------------------------------------------------------------= ------------ -; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, TopOfAp= Stack, CountTofinish); +; AsmRelocateApLoop (MwaitSupport, ApTargetCState, PmCodeSegment, Pm16Cod= eSegment, TopOfApStack, CountTofinish, SevEsAPJumpTable, WakeupBuffer); ;-------------------------------------------------------------------------= ------------ global ASM_PFX(AsmRelocateApLoop) ASM_PFX(AsmRelocateApLoop): AsmRelocateApLoopStart: BITS 64 + cmp qword [rsp + 56], 0 + je NoSevEs + + ; + ; Perform some SEV-ES related setup before leaving 64-bit mode + ; + push rcx + push rdx + + ; + ; Get the RDX reset value using CPUID + ; + mov rax, 1 + cpuid + mov rsi, rax ; Save off the reset value for RDX + + ; + ; Prepare the GHCB for the AP_HLT_LOOP VMGEXIT call + ; - Must be done while in 64-bit long mode so that writes to + ; the GHCB memory will be unencrypted. + ; - No NAE events can be generated once this is set otherwise + ; the AP_RESET_HOLD SW_EXITCODE will be overwritten. + ; + mov rcx, 0xc0010130 + rdmsr ; Retrieve current GHCB address + shl rdx, 32 + or rdx, rax + + mov rdi, rdx + xor rax, rax + mov rcx, 0x800 + shr rcx, 3 + rep stosq ; Clear the GHCB + + mov rax, 0x80000004 ; VMGEXIT AP_RESET_HOLD + mov [rdx + 0x390], rax + + pop rdx + pop rcx + +NoSevEs: cli ; Disable interrupt before switching to 3= 2-bit mode - mov rax, [rsp + 40] ; CountTofinish + mov rax, [rsp + 48] ; CountTofinish lock dec dword [rax] ; (*CountTofinish)-- - mov rsp, r9 - push rcx - push rdx =20 - lea rsi, [PmEntry] ; rsi <- The start address of transition = code + mov rax, [rsp + 56] ; SevEsAPJumpTable + mov rbx, [rsp + 64] ; WakeupBuffer + mov rsp, [rsp + 40] ; TopOfApStack + + push rax ; Save SevEsAPJumpTable + push rbx ; Save WakeupBuffer + push r9 ; Save Pm16CodeSegment + push rcx ; Save MwaitSupport + push rdx ; Save ApTargetCState + + lea rax, [PmEntry] ; rax <- The start address of transition = code =20 push r8 - push rsi - DB 0x48 - retf + push rax + + ; + ; Clear R8 - R15, for reset, before going into 32-bit mode + ; + xor r8, r8 + xor r9, r9 + xor r10, r10 + xor r11, r11 + xor r12, r12 + xor r13, r13 + xor r14, r14 + xor r15, r15 + + ; + ; Far return into 32-bit mode + ; +o64 retf + BITS 32 PmEntry: mov eax, cr0 btr eax, 31 ; Clear CR0.PG mov cr0, eax ; Disable paging and caches =20 - mov ebx, edx ; Save EntryPoint to rbx, for rdmsr will = overwrite rdx mov ecx, 0xc0000080 rdmsr and ah, ~ 1 ; Clear LME @@ -525,6 +592,8 @@ PmEntry: add esp, 4 pop ecx, add esp, 4 + +MwaitCheck: cmp cl, 1 ; Check mwait-monitor support jnz HltLoop mov ebx, edx ; Save C-State to ebx @@ -538,10 +607,50 @@ MwaitLoop: shl eax, 4 mwait jmp MwaitLoop + HltLoop: + pop edx ; PM16CodeSegment + add esp, 4 + pop ebx ; WakeupBuffer + add esp, 4 + pop eax ; SevEsAPJumpTable + add esp, 4 + cmp eax, 0 ; Check for SEV-ES + je DoHlt + + cli + ; + ; SEV-ES is enabled, use VMGEXIT (GHCB information already + ; set by caller) + ; +BITS 64 + rep vmmcall +BITS 32 + + ; + ; Back from VMGEXIT AP_HLT_LOOP + ; Push the FLAGS/CS/IP values to use + ; + push word 0x0002 ; EFLAGS + xor ecx, ecx + mov cx, [eax + 2] ; CS + push cx + mov cx, [eax] ; IP + push cx + push word 0x0000 ; For alignment, will be discarded + + push edx + push ebx + + mov edx, esi ; Restore RDX reset value + + retf + +DoHlt: cli hlt - jmp HltLoop + jmp DoHlt + BITS 64 AsmRelocateApLoopEnd: =20 --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63360): https://edk2.groups.io/g/devel/message/63360 Mute This Topic: https://groups.io/mt/75829490/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 Fri Apr 26 07:16:41 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+63361+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+63361+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 1595875467603627.8171822205898; Mon, 27 Jul 2020 11:44:27 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id m4keYY1788612xoOszISHXha; Mon, 27 Jul 2020 11:44:27 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.56]) by mx.groups.io with SMTP id smtpd.web12.62789.1595875466690099606 for ; Mon, 27 Jul 2020 11:44:26 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XNSfs2cM1Jo/XdQ03rGbCP5XOfHhQ/pCraxQ1NI01UYpVE3atwO3DJob8cPeE0aUqGB8XxgQryH7USdu0MEQnAgOUsitEdHxSNxm2v9obwjFFaxtExUuHsZCqmQGxRa+rkPYBfMjt0j0RiVFx+4YpmkNqP6ughImY/X2YkR67MAWE417Pn0tOTzQck57329515haVj6OdBFStS73KioVXvrfDaC9w0NFLI9EEObDM9iE3N4NvN9B1PwXbuvSjoLCjMHDRmgXnPweIdu8sJGEw+2R6FSqim2VQeR3c1iJlGRkdHH52y9N6cq++JQNvLbttbvl9aarJVoK2nEA+B3ngQ== 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=XCnaAzxMkOBWc2lJckBTpLScRWzaGsdTjPPPS/httsc=; b=HRe5G2DxMsa/cOy01QZ5B9Q3yD6MAjonPyzd8ST0TEJDlkDfFHbGMk0OUgFU2RpGCM3ByV0JQSYxfEq1HlzG05HE/rfkpf7O3mSU2EyDNsaqJhA8HhJaghPbLVBERVhAKDjbVzYQuFAE858huTNANapvuzTT7PcRHnEA/pmcJtIw3+qV1tRa54fXZBYd9AFfLJfGZAuJiD7SWL3sQ7jpe13//ZtphTa+Wit40bKFqq70sYWAbX+T4LqFseNAaAFL1KV2IDxOuvkGDJIMUfe48crN01W/HgepbkdZchkLkcyrzHn7dqBkiqNATyb21rJR0isYYhhazERtPXWrBYW1jg== 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 DM5PR12MB1257.namprd12.prod.outlook.com (2603:10b6:3:74::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.24; Mon, 27 Jul 2020 18:44:25 +0000 X-Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 18:44:25 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [edk2-devel] [PATCH v12 46/46] Maintainers.txt: Add reviewers for the OvmfPkg SEV-related files Date: Mon, 27 Jul 2020 13:43:31 -0500 Message-ID: In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0070.namprd04.prod.outlook.com (2603:10b6:3:ef::32) 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 DM5PR04CA0070.namprd04.prod.outlook.com (2603:10b6:3:ef::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.20 via Frontend Transport; Mon, 27 Jul 2020 18:44:25 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: d5831ad1-3b03-42ff-12bf-08d8325d15fe X-MS-TrafficTypeDiagnostic: DM5PR12MB1257: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2449; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Message-Info: DqxMAAJC0ELsBOJflAJkNE9tqvVMa98kfN6PpdCDrR5fl0r3D/NTjXDd35AwHCadqf+lKPzkWRD2+bn00C5FSez3+d+drvFylsttwOc2b3FrZ6/fHq7majxTXuj72R+5KfyOa7MunsPjHX3YJmf0YqqQvK3wHJslibfGGxx905pHqab3k4BuwXu74+ZnZ4RfW8upvQV67ku1QmqZtTP/Y4w/OdkggkGCvRK2oeDZzvmh3n4F9o1ug8XLG4Ry7bC2zmA2ta9vF4xaVEAbH35ulwnYyk6fwvq5qWtXtBVgqe/Cm09QA3DwjR1c9j/rrHtqVIWs797NzQFHR2VA+hCx/XOR+zmYQWQ6XcGgvX0A3hhOco3zBDww0ybxPwR4S5ec X-MS-Exchange-AntiSpam-MessageData: XXyqJ7W9QNmROsYrFw2Ci7e971vC4/Vox8t0g2sgDhT//IU3xakSGuNXFkKMDkvQppfScA12VeA7HVJgV/4obcgCz7sKUme864Bgbxut3wZsrlOmSd7fpGcl6OlrHIxF7w5jdTEtLpAknTHP86T3RKJWGtF/l5mAI1rkBWiUo5GzEpn1qYH6TyjIlDWV9U1XIpbB3DLbgU+ugzg6I+Hp5VWL6A7k4h5wzSixa7p+97EU+QazDdWWDjcmpvtjOdN9AnIvKqv7ERZqid6v3AqACDwmpkwOfHXBtXeXrPDjeFEi2su5dljFeePoUsmcnIDdGsmhrNizXIKVBLmmjhL89JUTJJQXVS1iF0FzYdgcMWO6gpsOMfBcP5HXdBr5PR3XbRd2k3J/SBaLgzfTtA2wq9Y+wKU0lW0/d7C+X7rlSU7PGL+K3eYIJch+tP8OML7VbYns9T7bfjKYshbDa85Q4mJ+sQgZvoxxOpocE6bB/0o= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: d5831ad1-3b03-42ff-12bf-08d8325d15fe X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 18:44:25.6944 (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: zj0/eF7uYb51E8eUGmqEk4JSTCG5m5DW6aNvztsADK7aTP3BLluYiduW68YghI5J1MenuJs7snj9+bjgWLWW9A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1257 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: ozHtzqRxThpAcLwagiwMCW7Ex1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595875467; bh=hJn+v3PL7PPmaCsgP0YLK50SuKF4A5RXkkkKesgHECs=; h=Content-Type:Date:From:Reply-To:Subject:To; b=YUhQ8DP8cDHPmBOMKysT172Le9NdXyQqZ/UYfatGqNctjbA9hawZ3L+ivBGVnEnZRjQ t5/iIAWxU9L48riioclah8YFMPmsR9MM2JZKLybbNowBzz9CapYUE8kDZbcDajcvCR+DY YILzU9Q2wyRIqOfzbWHplsptuuf80rldME8= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Tom Lendacky Register reviewers for the SEV-related files in OvmfPkg. Cc: Andrew Fish Cc: Laszlo Ersek Cc: Leif Lindholm Cc: Michael D Kinney Cc: Brijesh Singh Acked-by: Brijesh Singh Reviewed-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- Maintainers.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Maintainers.txt b/Maintainers.txt index 5504bb3d17cc..dc7ac7a5daf6 100644 --- a/Maintainers.txt +++ b/Maintainers.txt @@ -412,6 +412,16 @@ F: OvmfPkg/PvScsiDxe/ R: Liran Alon R: Nikita Leshenko =20 +OvmfPkg: SEV-related modules +F: OvmfPkg/AmdSevDxe/ +F: OvmfPkg/Include/Library/MemEncryptSevLib.h +F: OvmfPkg/IoMmuDxe/AmdSevIoMmu.* +F: OvmfPkg/Library/BaseMemEncryptSevLib/ +F: OvmfPkg/Library/VmgExitLib/ +F: OvmfPkg/PlatformPei/AmdSev.c +R: Tom Lendacky +R: Brijesh Singh + OvmfPkg: TCG- and TPM2-related modules F: OvmfPkg/Include/IndustryStandard/QemuTpm.h F: OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c --=20 2.27.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#63361): https://edk2.groups.io/g/devel/message/63361 Mute This Topic: https://groups.io/mt/75829491/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-