From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.57]) by mx.groups.io with SMTP id smtpd.web11.13894.1597335903506943915 for ; Thu, 13 Aug 2020 09:25:03 -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=vFs9E6tp; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.236.57, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f+rA3b/vEHoMlzqWDXJBqCgq9oqazhBAtRLA7agHhlo+SjOew1EMOSEHuiep1Vc5nNICmJe/PlKdEY355OoAyFronKCaftFphgEGotk+HF/aTUgerREPnKjbIv9UmLvV3PNSaGe8JgwpafbUdREeFrHinPtNrzdv890t7FH9LmizCDEoDqIQSPA8zra1GUq+Q2sZg4yqdwuPa/ZGDvFG6QW8AGUz9rLTJ7WpJom0vLtpNu/IoZfoKU4uxLDwyZsYd/DUW/7nIvp9X7UIVkSSL92cZmr1IyfamagVBxhTnlGso/xPv3t/ZWF1aSI7YIf3D7EKAXfCQ2/Jv265y5R2+g== 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=YkA2tvsVS/w0UnozBUn3AVnburoOj9wJmhvA0QdC9vo=; b=ZcOmMg/s+9ozzsE2edP4EkucSs5DEWFOkRydWNFDPMDEH5tsqLE7qWP7sSGTHl0aWjkqg3OYad6472eKKobFUNhN6NAr4fUSRZ8/jKDAVbazq6VJbcB9X1cwQFbF877WSd0uTlIV/IFJKgKIn2XNtEkASCwarl+akPB1sZN9uYZf8nEauKSxRa24uq7rEcBPZcLCr1LoBoccHnWShm++h87/YtoSriu2etPMCle0tNVgcY6jWTMm4wXKJi6TQxZIZ7Vb+/4tf/nbK1iY053dPlq3kSHFSOn5YJr9sqtFAmnexVohjN1C1fsTkZtzo1L4bF1U7g81FtIrp4HJxskl8g== 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=YkA2tvsVS/w0UnozBUn3AVnburoOj9wJmhvA0QdC9vo=; b=vFs9E6tpINC7zk3WEH5z91xOdIw3rRtbWezFF+xcvD5kmQ8lrIvLVoITNTSnArt5y+cXAZXexq8/0bL7G2Mxa5hqQ+ERKttlQ1UcMLjI2tsOIkGzPfkdQbagONcM1qi5Ve4mDMopMOylqxXmuDdEikqm/Ncz3cyS/0ZpMPYt/gM= 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 DM6PR12MB4297.namprd12.prod.outlook.com (2603:10b6:5:211::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.16; Thu, 13 Aug 2020 16:24:55 +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.3261.025; Thu, 13 Aug 2020 16:24:55 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [PATCH v15 40/46] UefiCpuPkg: Add a 16-bit protected mode code segment descriptor Date: Thu, 13 Aug 2020 11:24:39 -0500 Message-ID: <679dabb843cd65e5f5d058e3102b45091f02e4b0.1597325013.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0031.namprd04.prod.outlook.com (2603:10b6:3:12b::17) 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 DM5PR04CA0031.namprd04.prod.outlook.com (2603:10b6:3:12b::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.16 via Frontend Transport; Thu, 13 Aug 2020 16:24:55 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 7331014a-7c3b-462d-2be3-08d83fa569e3 X-MS-TrafficTypeDiagnostic: DM6PR12MB4297: 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: sqSsnRuM4pn5O5CXKVZWUY2Ikbb8Mw57eEQksovj5XUZXhnORbj+vPZlo8Jy2K/g2NGyL+x0BpyvqlBqICbjj0KV1KMizYV2L/fPb8wCf2JIWqEkrFNgDYdvz2k5DJtXk5YPBEHHml+aoqUD+hGbk/WLI92iNRijoeCK3E7U87mBn99tpB+PQamXxxKQkhxdYZZr2rcG7MMqrBd0Yx16iretlqJEIQL8RnPGg4BcY1uahYmOmjMebdl6TlZOvuy6/NNAQMLkkIj6OrzlAn4XOCpk7jVV27GVFVhhnm0Ajyvwr1/o7j640g8U53w1O8siAKTLBMSkBUX3OvM+5uPfa0XoeVjXKWdWAwfVWQc4KdY8JwNddTI0Z53UueZozF4zuV11wdfPZ6Rq5iUYnoA/GXzppFp1a9DvjKCLDySy5whvXhssoXqK8p90Ik6cQ27xaBjgjHBHSMYvDMtthZ46nA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM5PR12MB1355.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(39860400002)(366004)(136003)(376002)(396003)(346002)(6486002)(478600001)(6666004)(16526019)(26005)(86362001)(36756003)(186003)(966005)(52116002)(83380400001)(7696005)(956004)(2616005)(316002)(6916009)(66946007)(66556008)(8676002)(5660300002)(8936002)(66476007)(2906002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: UPLH4vkI8s6xE+aQsaV6iWSmJ4R+UnaojG9MyFQH6MJsV5ctS4zHFrKJQPEm2R4O2bNX00ulevvH7In5TvaA6iI81pOPFt41zTgG6ZNQjlYZNENwpISC3lTcVvdPrSE3XGrH0t1EgsEOXugxz3C/z03H7S3tEDImfMSxHCIYKon1n4mswlLh41h0ru0ktZgdLQ5VhG8+V8HGLltDXb15PSTqDaIeyRV79o90yVjyUXMkB+ODVNhyGsabmnVNKHy5CPlu3V2q4RQxmf5Dd/D7D2l3AvJdPIiKUscOdLE5LBD31fZ9bx4pllwgacoN7dGFoxA5ITOHp98wpuPMObfF2iBZAltBp1R/ITyUBtwPB2iKzD4mG7K2HDfnN/Q3uWgi3OfDxzwDANOMwWOnxy5Pbczp0FAiHJaJNW5kGtlze/VB22DBTz0YfXSuPTZGq7QMkVhxrHQz7BD/lbsgELQUNgxKdQA8jUpH/3L+G8XeSrWd1nrdIOY4L+C+fs7Zcg1gN2nViAhMGGhe1UWIgy7nNDFBfubLbYyrarA0+qfk1n1W+dbEQhHKF1T2AOqIDuojNuBIRYihhuDBMRb7SXKZK4xM9MRCwOQCW4R5oCirQ4IvFu1jrHAFKloFfpuX9kpavjxT1tyG2uY5PEXEmDLoHQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7331014a-7c3b-462d-2be3-08d83fa569e3 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Aug 2020 16:24:55.3333 (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: 2ZZJNRGRZQxWG1pZ4ryQeDRrKOMAuLvXIV9NeF6jrCUA9ROmqfjZ9Q8byAP8sFgAwBHvp2wJJFRKmzbkj1NQ3g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4297 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.28.0