From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.82]) by mx.groups.io with SMTP id smtpd.web11.4354.1596141727092546180 for ; Thu, 30 Jul 2020 13:42:07 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=U40pXBSz; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.220.82, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kl7Umsi96mC3XfZbb8OPevW5cYqGOd3EPTN7Hf9B7jQkVBDXkn+04WKLj+76rvLbrnZr9AuaxW5AHlU6liHjEzAMQ30NNRBAxpqC4nbGCsh/GCM6IPc06F1vRAY6vUfKIlhiNM3+oWICWT28gWf1JBoR8ataw/082BpO+7U9qzMX+FySLGq5WiVL765qh7PIoQOf3TrYWLmnHAQZ4L6zz4+eGcVlsSARoN2I4CV0y5gNMEBTmuWNRk1FDufENZYmn189CEK82pmHb1Qf/GD9dYljbTKVsFY8n/al9ZEm786kpVg+RyyCtzIVMTVQpZ/wttHbXPd39ldgZevDyMI+RQ== 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=MKH1TankgAgP90y8WmoJANbcpcWQv7Zm9DIFTDyiP6a8FQFPcEdZN3lPzBYH59LUKSaqUbESavmHU/qHhwzDT/e9rGuVTHaNk8getCRwaOqK9Jzat6Ny0d8VrCc3qljx1SHhzwCU/ZaMpEaBO9QHRbFAk3hOs5sEzBhF5DiHD/IFa3uhmgIZllS1shEsYg8Ixk92INeyK4iPBbFDGTLJk18B357LbSWdtLXaY87aFd54HtHq/0bM9K4F7BOgAdRDFiKmncreYejmlcePsF0gmczw2g+ZvCDXGjvgojy1AmRGGb7boQsHt8b0dP2XA4uxTypDom8jawOF8L83nCqT2A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector2-amdcloud-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=y42cNfhmfyz07xseYeQYH9zbpfMlzMLWf83yCfosPcg=; b=U40pXBSz+pwih+Z7SZW+YbJaEtQC524Tfoom/7qLUCdSqG4JO0rfD0dHmSTpZrkz/GZA6oE9eX42kUj7DEDKLx7riQHC55u/NuHRsnAacpBnUaOIy+iOsWpXrVWOtcSv6ok18RFv31cGPpPSFmNhBrppnF0NiX5PqtXjOr/wYGU= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3868.namprd12.prod.outlook.com (2603:10b6:5:1c8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 20:42:05 +0000 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.3239.020; Thu, 30 Jul 2020 20:42:05 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [PATCH v13 40/46] UefiCpuPkg: Add a 16-bit protected mode code segment descriptor Date: Thu, 30 Jul 2020 15:41:49 -0500 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: DM6PR06CA0001.namprd06.prod.outlook.com (2603:10b6:5:120::14) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) Return-Path: thomas.lendacky@amd.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from tlendack-t1.amd.com (165.204.77.1) by DM6PR06CA0001.namprd06.prod.outlook.com (2603:10b6:5:120::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16 via Frontend Transport; Thu, 30 Jul 2020 20:42:05 +0000 X-Mailer: git-send-email 2.27.0 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 30afda86-c386-4143-c51a-08d834c90525 X-MS-TrafficTypeDiagnostic: DM6PR12MB3868: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nvGN3vkAqVq5ZOKYtSgp6yTsvEb7QWoen++4bH08xSATeWjAXSqQxiyqVT+TtYubqqhh8w3cC3pGRV7MEe80dvc9Yskxng89NUHNVwImezaYDBaA0Nw4Omd5NAPKRq4MY2BYfjpXglYhP/eQvhAiUvLTIDaz+l7XiaxwmixtTqvEPJvLrWOO8nxbmZXQI80cToKF9rPAQVv5LiOmU13ae9FnHkqrEEXamHXRe2lvTx6SVILfRIVFpO2dX2KdYciSPvsxQK5GbeJAUggqfdKGdZzD1kpQrNqp6im9A0r1/Y3Hb4LF8Ggur1FWt0EpUaYFG7afX2flzIHV5jRG23fdPBv1aAJLK2lwNCGkB03AM0X9xG7Hu6uwphDrgIq+NcJjtkfFR2dToJHLGmU1AQRVnSVCJsKB++OzfPSMixhw0KSzoeYO7j4ffJBgL3XU0yyL4Eh/rwfoCoo/9INrZ6p/gw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1355.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(376002)(396003)(346002)(39860400002)(136003)(366004)(2906002)(5660300002)(52116002)(7696005)(2616005)(956004)(478600001)(66476007)(66556008)(316002)(16526019)(83380400001)(6666004)(6486002)(36756003)(8936002)(86362001)(66946007)(6916009)(26005)(966005)(186003)(8676002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: gM/WnRubzVwnYNXW4k76tLwj50Z6jQWFXrK35moRG13YtulLkw+oSAP9ZqNKmk9h9/5hGxVDsJbEfd1a4h8pEYP8La5MOCcbCOf7X7DbwAVEE05z3AoKoKgxTXjaCGrr3EAMQazV/1cMpd1r8s68nnDnPilsbbMShfJaMryW4nJvL+l4SHziLddUbMthgi0mukL2cYWR/9+i6KvUaF6Eg1a4qNsjq4uxjk52/fHZX5yySqWbOZtgF3bS/u/4Xs+ro1JQhHndYzliUladrk1V2hJXD/Dl/PBDeXDf7kEmQ1kmmoeytoTiN/FBFUMHBRGZzPA960v2fifT7IzLQFN19QPngc8qLuzdaJe+v5NoX0IlwqePbYLKQVv2QOPyeFM5hb+pJgkt97UiK4TlrB4rBfNTLFlhhhO0X9VoPzlyOe4uNpp3b9xSvrj76GrtdNqHLIwP3G00ovdFfLpjISwSWWbxwDJsVeOVqh5A0E8c52t4G1twWYDbyrCvcfvUNS16bNf6b3Qg95ChskvJ4GXxhxpZc0/JZBhCNWxl3oFglsc5XBUlt70YidIkMA5uTARvqxCsnU3VI9p+EkrRVoQ0a4tK3Z0CS3VJEagSBZsZG8YBRno6aI53/tRhKEj9h/0oS+QJ/krDXvP6rTbncQzc2w== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 30afda86-c386-4143-c51a-08d834c90525 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 20:42:05.4486 (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: Qd111NCtUXqfh4Tbv3dVTNh7Cyq/v5k3xfOTzx6ljh+wRLm9fbYyHODnYuWXoj8b224LjVQkwGaPWuQdcnSfZQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3868 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable 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