From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.40]) by mx.groups.io with SMTP id smtpd.web09.594.1604685217820358420 for ; Fri, 06 Nov 2020 09:53:37 -0800 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=iIxGy7HF; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.223.40, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LyqaiY7PmRCamNGwtKiDVdEetmSJIeuLOQMST+xX0BZEjVeEUR0rU8JuC5b4yf13a++NB+Umj5Le9KSGE+jj5QtKwaUWKPCRLcRhoRxw6mIyQY6qjSpDoK87j76fdRAJ5g8jXx+iAdCrdVwdG0I3DxaGbn2R0G/mc2B1Lt2UKbxTgCmdT7oY3nAy/7c1YNqF1mIpazfyXgPez4O4XzmLykAbJpp1ezzl64jYB/1Av5pDm9YelJYpSISLaHnacI90QQ4px75ov84zNzwIVBxdG3yvBXfwfEqhGybluDE1A44reN8w+KWnBogL526l6/WbpVhblGS0bRudYryoVAOZUw== 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=HSU0BeNz5Uy2U6qh/94mo5BRx4jSLfUI6SXNArQNmPc=; b=Qj/P1tqsJoO9Jeg31MSmWIbbyZd69f1Wfmu9uwuAvwcTfu/fpBMvzmp4ApMNjAjcJs4e6zBTv7F7se57Tin+hGSjUvl2dz9zllEb/r01TlBv0V+X4UAxrZvvCoEBxPjjosnc2OMzVAN4CVBFqqBU4sdqvMe2KZC8zR2XkoI0kQgYPmZ+3j0BAvSrjW1qNGE6x+grwD3H8G33yW/q7wCF8fJPxR7/9PfdKpApArsfGs+kWOcv44HeGLsu680mA1+VxGr8R0OJ6EimvyCQjHho/GwtIl019RYs4QPFTmZVDXIpajwdQY4LH1XBRYLtGPfrrlQqLvxP/BksJdlzsrzRFA== 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=HSU0BeNz5Uy2U6qh/94mo5BRx4jSLfUI6SXNArQNmPc=; b=iIxGy7HFNq7I84elSucD5btjrxDlM8QRhWIrT9D/C4j3uYDCM+4jkWYIOeT+GanYg9NOIavp5HyhFK/92sxYO+3w0zFxCSoNYSWRrzwenqXu84O7vmig6plMzUJ2ssjsTl+mOkVwKTCEcLnSZrINMDa6T1M+a15v/xa/f8ridmo= 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 DM6PR12MB4385.namprd12.prod.outlook.com (2603:10b6:5:2a6::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3541.21; Fri, 6 Nov 2020 17:53:36 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::e442:c052:8a2c:5fba]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::e442:c052:8a2c:5fba%6]) with mapi id 15.20.3499.032; Fri, 6 Nov 2020 17:53:36 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Michael D Kinney , Liming Gao , Zhiguang Liu Subject: [PATCH v4 01/11] MdePkg: Clean up GHCB field offsets and save area Date: Fri, 6 Nov 2020 11:53:03 -0600 Message-ID: <5e9245c7600b9b2d55dd7586b8df28b91b75b72b.1604685192.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: DM6PR05CA0063.namprd05.prod.outlook.com (2603:10b6:5:335::32) 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 DM6PR05CA0063.namprd05.prod.outlook.com (2603:10b6:5:335::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3541.10 via Frontend Transport; Fri, 6 Nov 2020 17:53:36 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: ec90147c-27c7-4417-93ae-08d8827ce29c X-MS-TrafficTypeDiagnostic: DM6PR12MB4385: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3968; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: A3oz3xnsUhH0aeTlslBYX0SWdWLCMKNXaFzMWXTH/26oTsD9u4Tbk1vv8xaiE+UG2rtmOV+I0/ePYEubr5+J8GnQCAw3LJkWKwApE4u6YPkaeWfocM/JnrdY2faXOpRmWVMiz07ZtyueP4wXIzI8oH/96FpSJxiVNue3KxgE+VhmfL4YN3IEPKfLa4sKS5kxkalwostlOU5V5+yMTrve12uxUnfr48g4XozLgOpdnpu7LIU8fzBkqjVPkANBA7etg2ovZyDtHQkpZnQz+9SmwQypCmuZ1yHE2epfKrTrD3/B9H8YmX8RGGYG0sumyZ3PkFfRTbrHyEtuj3yxJJ8gJMNDIWmG6DnEFqt+HHmEMiBF0lTIubdCi4byuP058p3tfK15OtaEokbZjL+opnoz7g== 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)(366004)(376002)(136003)(346002)(396003)(39860400002)(316002)(966005)(86362001)(83380400001)(52116002)(7696005)(66946007)(5660300002)(6916009)(6666004)(8936002)(36756003)(8676002)(478600001)(66476007)(16526019)(26005)(2906002)(186003)(66556008)(6486002)(4326008)(54906003)(956004)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: yyMQbwlfDQWXc1XSPrVNBwTZ1tioeoasKHJsj1t1wVW2I3y3xi2tgktmc96GMzM83fzVGRSJxZcSaRxzJFDBBqijojVTAdwxehBxr9qSIrKjZvawEJ4jfRFeOlyh0UTE9K/QTEsJyd+y/qzigozgU2QnpBklFPte1zvjTHFopUMen6gkWwVJy2NIg89N9/3KJSG59Dm8T7R3dHM/ksO4AV8zbG7el0Lav2iaHPSJiQY18z039iZdWgkw6PhbTFmGoiLZcm1VnTfzhxiSzCuKOCRa9SnkilzagUkcwwKn/o9B9MmZkf8cNgEDQQaa2y9dJrJhJXGtUEzz1qlbW1ypzCAGCcA6O4shT65BNMQJa/TWQIMXwtK/lpeP0jaHBqeeNh8InF25AoDwLEqzdhuYp8ZzCS5oDbGeT/Hq+mkEWS+3paWVF6Tpx0gFWzOBc10Jyr1MH4WEW1xyoPNWlNx3XyLWyIbXyqqeCgp6OyiKPBgWN66ozxe84rUx1YuyxyJv4Zkk2k7vZtjuK5JQh17IQSz8GchxP7qovlMararTRI781RZXt5CJ/Zhz6imBgu6B7TGg0wHq8xAt8hecwOunMl15ozmS8A8Fs48OUY/3Y6Lxdm6mxCrVgxZrmFnfTuL/9z7byZBHkiXQ6az6B4Ux7w== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ec90147c-27c7-4417-93ae-08d8827ce29c X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Nov 2020 17:53:36.5021 (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: 3QjI2kPmGlJZmfXwF62KNDCZtyMWMn/FhJq++YqlGXGkHMVMNObLbf4rIJvV6y47tHIiORRoMp+z9UySf0NPCw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4385 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3008 Use OFFSET_OF () and sizeof () to calculate the GHCB register field offsets instead of hardcoding the values in the GHCB_REGISTER enum. Define only fields that are used per the GHCB specification, which will result in removing some fields and adding others. Also, remove the DR7 field from the GHCB_SAVE_AREA structure since it is not used/defined in the GHCB specification and then rename the reserved fields as appropriate. Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: Tom Lendacky --- MdePkg/Include/Register/Amd/Ghcb.h | 43 ++++++++------------ 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/MdePkg/Include/Register/Amd/Ghcb.h b/MdePkg/Include/Register/A= md/Ghcb.h index 54a80da0f6d7..ccdb662af7a7 100644 --- a/MdePkg/Include/Register/Amd/Ghcb.h +++ b/MdePkg/Include/Register/Amd/Ghcb.h @@ -82,35 +82,10 @@ #define IOIO_SEG_DS (BIT11 | BIT10) =20 =20 -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]; + UINT8 Reserved8[300]; UINT64 Rax; UINT8 Reserved4[264]; UINT64 Rcx; @@ -136,6 +111,22 @@ typedef PACKED struct { UINT32 GhcbUsage; } GHCB; =20 +#define GHCB_SAVE_AREA_QWORD_OFFSET(RegisterField) \ + (OFFSET_OF (GHCB, SaveArea.RegisterField) / sizeof (UINT64)) + +typedef enum { + GhcbCpl =3D GHCB_SAVE_AREA_QWORD_OFFSET (Cpl), + GhcbRax =3D GHCB_SAVE_AREA_QWORD_OFFSET (Rax), + GhcbRbx =3D GHCB_SAVE_AREA_QWORD_OFFSET (Rbx), + GhcbRcx =3D GHCB_SAVE_AREA_QWORD_OFFSET (Rcx), + GhcbRdx =3D GHCB_SAVE_AREA_QWORD_OFFSET (Rdx), + GhcbXCr0 =3D GHCB_SAVE_AREA_QWORD_OFFSET (XCr0), + GhcbSwExitCode =3D GHCB_SAVE_AREA_QWORD_OFFSET (SwExitCode), + GhcbSwExitInfo1 =3D GHCB_SAVE_AREA_QWORD_OFFSET (SwExitInfo1), + GhcbSwExitInfo2 =3D GHCB_SAVE_AREA_QWORD_OFFSET (SwExitInfo2), + GhcbSwScratch =3D GHCB_SAVE_AREA_QWORD_OFFSET (SwScratch), +} GHCB_REGISTER; + typedef union { struct { UINT32 Lower32Bits; --=20 2.28.0