From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (NAM02-CY1-obe.outbound.protection.outlook.com [40.107.76.74]) by mx.groups.io with SMTP id smtpd.web11.4815.1594756238311396655 for ; Tue, 14 Jul 2020 12:50:38 -0700 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=gBdLc8kJ; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.76.74, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NPWmR9Wx0dVKtp8DTHkzEU1g8+sHqmyiaZCSsbIUe8PiPmMb7A18cvOFuBY10x7o1qnqLCs2n2aRHhIzufoiYMT+fT9soTeg9FN3gdKIg46gGmdhi93MlJqfrTRmmvKLaA5u3MTkPvlwzsvhJsQAjthEPNz1g9qqoezYgIs7XS8anRbIfUbdmRgysfeU+dgSH9suBK17RT0/U0ynU25O4/JFo+7u20ZCDSS6BjiIbaKTE2R+rBlNcrUrlj9NQenaZ/qXsaYv/L0NjWm+YqH4AF8NjipFGxSsyVMH0Vc1pHbXaYlwBXvA8lfXAzu56xZeUO+HqqeNkcMVr6iZPGZHrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=y42cNfhmfyz07xseYeQYH9zbpfMlzMLWf83yCfosPcg=; b=lUqTI5+FhCwVw2iUGnDswEttI8wl+nurDaUs2AthUul1zRieGm6KEO3Y+bFjkvHKpa7UtCvzXgzYmtaP8J2u56CYyDau6+5ygvdCeEiB/WyRuzgVfWpOaX3wjBCjl53+zbeFpxdex8KqQeROKHn45yiAlbRx2ZCLe74UZ2NOCf5MFWFIl6JEXSlHgn5Zr/EwtKsVg08z8ZpEv5NJfFHkHgvlQkiAGXDgOOUupsqbdXwkhcFK0QN/Oq0SY3/tAUe3ecVut50m9EgchQvIztmirvB4o3xoMNSGjSCav/oKeiSaW1WvSMoJkLCZSbI24qwNYd6sDmQiPVuN8wYBWo8Hag== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none 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=gBdLc8kJ0YDyRc118lvmPJSwRTWQKth1al+nUI1Hmjp0OwPONAoSN1vo07IOXppiBmH2/rZpvA/XxqCu0NUi9Hl5HD4sYQ4a+QsouPWi3Bhn8FKxTyVAscAdpb7ZW0lWvf5E/ErrW1a9OmjHktgntfReyHStVvIxPcUwO/gEB+c= 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 DM5PR12MB1834.namprd12.prod.outlook.com (2603:10b6:3:10a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 19:50:37 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3174.026; Tue, 14 Jul 2020 19:50:37 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io Subject: [PATCH v10 40/46] UefiCpuPkg: Add a 16-bit protected mode code segment descriptor Date: Tue, 14 Jul 2020 14:50:20 -0500 Message-ID: <3eb2b59947bbe3875e68638a7f64d1bcf917ef3d.1594736896.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0016.namprd21.prod.outlook.com (2603:10b6:805:106::26) To DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) 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 SN6PR2101CA0016.namprd21.prod.outlook.com (2603:10b6:805:106::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.7 via Frontend Transport; Tue, 14 Jul 2020 19:50:36 +0000 X-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: a3074498-0161-4a94-70f0-08d8282f2d9a X-MS-TrafficTypeDiagnostic: DM5PR12MB1834: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VBgYDaWto3NojdGFfijpspjv2FgkhZdEscGp/aN4AY6aomr1KMnaf2Z1+mntgo1L2CJiBQEiVag6gqIhaCFhNWHLtlWOieOevCTdySfEfJDQln9hzZ8FHPGnUFB3boTpdO3qLpuEptVnAG2h4245XnVXxsQ50ydp8hULe1Z0SuEjoPUtL06bkp07tPqIBGFeLyB48rsLzJwBz730viCQKFCgMFFObUFPe8Gmxlsd4oP8x2t8lxrom918c/jgyGpJ/0lSYrfkI6b0C2SNqkBtRczheTxNQ2VqvX8AKYT45VWwh6Qk0NBiRQlPgQl7S0+tElGsKXEZgXrC/zv27S0stD26bVoPy/SmKgCQl4DU9k67e7+UcBXwXXWhB3/0WRMGzWDZIxqSYVXJn+9za9lkhM67GpIXURgDnktIREXbMvpw3sw/snjhxIGHuuBgVgwp/w/rg3YiTpYpWofHKxhseA== 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)(346002)(136003)(396003)(376002)(39860400002)(366004)(478600001)(7696005)(8936002)(52116002)(2906002)(83380400001)(956004)(6666004)(36756003)(316002)(6486002)(26005)(66946007)(186003)(966005)(8676002)(16526019)(5660300002)(66476007)(6916009)(2616005)(66556008)(86362001)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: YWP3hawbNuwBLcsXBxDBwZxcpdtJepPdIXx1vPPPzXVMFSr/hcVpDzAhCW7Ow9zZ+OV/25IO6L9AvgkadwMEout7jGRYbpUwDqsgGUMEK9jlciudkEtWyxQtcOyJPl/Dc46bL4HrNdxVj6sjZfyXzg/jLJQxGw/6cUZ8hcUuisR4kMmAH6d6wG9AOJ/eOknqTjuy+HXiXMcSXCEnLqopXTHCq99/Sz4BOchwd93FqTQThKF4kuzTDdmxAhYo7CC4elPCGxmtPFdw1MLCPqz1c/2fbxQfFLZT2hJM+J6pONYCufxS05QXwIMRTBu+9AVZU/BATaFAEKfHQRxYoP8z53Eallopby7ZAS8vaFeaLnmhxkpgd8tmQ7C9no7cH5rPRySiW1LnRmcZrJmvHdnJCzHOpP2P2T0KYf6R8EXbo1xwF96PkEYwmQ9ZIeOd63BgBNbiZ1ziezGtsMW+rEph+VAzge7tbhovk6dBpr9CEK0= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a3074498-0161-4a94-70f0-08d8282f2d9a X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 19:50:36.8854 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 1WYipZwCckiNLQwJl8dVoVEB0/vIblm/5tru3M8gHT8Zp44p677KTROrgsLbdRtSDLQj9VA2OMi/uaQs9yKp3g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1834 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