From mboxrd@z Thu Jan 1 00:00:00 1970 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.web11.19474.1602864579211732725 for ; Fri, 16 Oct 2020 09:09:39 -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=qyU6t5b1; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.92.52, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cyxfTJybBO8otysv1umHgdIvksg4W2ke2MQXVT+sVp0hZaQcwhp8cxAcN8prOCVudyxUQzkNewY3W2NGNxF68exmgXltleBKwLW6SLEXpb6mjWG6FdtWKmEffgPUzz0fFD9wN9QGT4u0OERoG10rfRcVwKDcqoIB9lJAawJDuxO/ORh4ORI0SWx8+YDTrsjz03QhMZ85OojIs3myexoEq9ERC+VDdKW6ylxAJGFuH9m05ydTbO02qkVoe7UNO0T7cKMOPJtAKXJcaZGW6okMTQlXHoUEV+qLcjGZPybo6gppZigrOoeNCIwXZucCX2GydCt2FvwBwOmmOPtVstKNKA== 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=sPBu2j/UkldiGs8kh+Ynl4l3J/PuGDvdzsB7ukshROs=; b=ixFKqspSvq1PYtNbWAj+BDBUSi2AAUsm4yZvZ8FwpsnyicY16dp8SJgabgborxlJwmqjoDUQkd8HrUKhj6wd8Mu7vs8ZkCTqW6eFElCKrhMfbAKb9E3Ds9HF6QhywrbqxpSRV28EBSepQPx+4Lm4QKZrVb91xm+fnWiUTjiqlvWguzAdpNba40PBg5lCjjJMHlSmZ4d2wi4m2Jw5F6dyLs0gNDCsb+u5repU2l7GEU6XSKzHCAm7l1bDDqEespMiAG4enlXZxjAlqVlwnYHThyl2YDDPIYAH29EDs8JxLTidd+ejrg1IhlbMU7d2xxSg+Nx28W3hZ6c/otbZD9C8rA== 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=sPBu2j/UkldiGs8kh+Ynl4l3J/PuGDvdzsB7ukshROs=; b=qyU6t5b1qhIgZX8O0oGArbWgwsGA/Q17ER7SYzdFmMDGxV5KGLoITUwRGKm8sYpGdHjw0l7BNmCglvYEc2mCPLj5aT/fNuAM181lMViVidjSbPf1vDniMqu3h/Zrw+45NQZeKQtItxUsybHp7Ku0hJVdWc8iFZwlIIPJs5E9zgg= 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 DM6PR12MB4926.namprd12.prod.outlook.com (2603:10b6:5:1bb::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.20; Fri, 16 Oct 2020 16:09:37 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4d88:9239:2419:7348]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4d88:9239:2419:7348%2]) with mapi id 15.20.3455.030; Fri, 16 Oct 2020 16:09:37 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Michael D Kinney , Liming Gao , Zhiguang Liu , Jordan Justen , Laszlo Ersek , Ard Biesheuvel Subject: [PATCH v2 01/11] MdePkg, OvmfPkg: Clean up GHCB field offsets and save area Date: Fri, 16 Oct 2020 11:09:07 -0500 Message-ID: <523f270e4e6f7a62cdbebc541b442bd766e7ab3a.1602864557.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: DM6PR21CA0016.namprd21.prod.outlook.com (2603:10b6:5:174::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 DM6PR21CA0016.namprd21.prod.outlook.com (2603:10b6:5:174::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3499.3 via Frontend Transport; Fri, 16 Oct 2020 16:09:37 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9350dbe1-9016-46a1-da03-08d871ede161 X-MS-TrafficTypeDiagnostic: DM6PR12MB4926: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4XJYUF615uZcIjpqDWmKodT2ftnWd6ALGjT8jYdFOszKIu5FYyuTCGJV5IDCgUZECW5DbCMPQe3U0K/7o7B99bGjtm8P7xuWjrh/qJmiYxuCbwcuKYQBBFnDFOl/ylA7qYmua13io/sWBphWTTKs3lRQ1utQ+eNh8HDnIjA6UVgWPGw5OKeEzegfuESlNFAGO7jZ/KQN94kSNfnhtgi3uEjuA3Ur2i6EqfaCt3UthYF1hDibYT898vj1+Uh+J8H8J6I6qt52MBW3ZGN5O1jVAJWUjXbg+WUiioHxVYZkfUaHjBu4QQ4vFor5nnWhGfLdc/WzMACyurIeDTHbeQwNbmLcP2Mno6r2jXn6ZpcTfuyEdfJgrpsDDaZXY2JjvdWBNNmM5+xUx165iTM1Q7GhES9rI+64oqmbqrED3QnNNjed9fVP39l9zFh3Zgok2+rx0CbMO+pywsS+t5dD6CfR0Q== 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)(136003)(396003)(376002)(366004)(346002)(7696005)(52116002)(83380400001)(66556008)(66476007)(86362001)(66946007)(36756003)(4326008)(2906002)(316002)(6666004)(54906003)(6486002)(34490700002)(5660300002)(6916009)(26005)(956004)(2616005)(16526019)(478600001)(8936002)(966005)(8676002)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: mVRT7x2xb8Mt92CIxoz4YPMgZw15o4dn5KWixGQ2W6fovolfUbLlLkKQpTc1JL/w0Oh4uygCEPfwelT/4TxAYkLpjtrzodwxBPpPmXhcEWhOH9O1YJh5Oa5SPPWBYqrCqZjEKVHsgdLTbrGongwI+E22w3F6oCLtlmuo8uQdBPD0M16n9YlTWu6jb35wiaTts+n6suA0e/ICln86Np04BvG+tZV0bEbRvSrhc7CMN1Iv4Zy1uqHHo7pgCy6X2ygDvIoAMbuhapOIhzCFpoW7e1ZIZsZASU83gUeGR+EidNaxeLBzxViuSaLtUMIcbwBABYYRZ05ry1F86d2OhE/kmtJFLNy0x1cR26W0sBex7FTVIFt3iGARIfEJ8l0k1ngz3iiETeWzouyq7KGbSulnYczL5TAKJnpzwQ9qf8shsVCnWGs7oIC3D7Vyp9nIBRV21Crq3o34mzCM4lX1+sBLp7JktTOS3tanVlekkbjENsG85r/bA27oClt6VZGBySmUrcgQky9gbTXoR/iOS/12pHG42OTgLL5IcLxvjZrryj5ZlDcQ/f16pJfa7uptNx2p/PYv8GNxWD2xOmsOZPxt8poObLPkYhBoLpbVGjt5gEMxZTw9fkUbXJFmserEFnT6ovMqFfU4QsKQ/XkGu5PpPg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9350dbe1-9016-46a1-da03-08d871ede161 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2020 16:09:37.7748 (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: 3MYKJouyzIgI//B06R5MExYIH/vFNPMpAE2uLLjdj7xYDXwUIqE7sp9s5gbJfcY1XQHnRoHHWRFGPdx+61p0Aw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4926 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. Rename GHCB_REGISTER to GHCB_QWORD_OFFSET to more appropriately describe the enum. While redefining the values, only include (and add) fields that are used per the GHCB specification. 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 Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Cc: Tom Lendacky Cc: Brijesh Singh Signed-off-by: Tom Lendacky --- MdePkg/Include/Register/Amd/Ghcb.h | 40 +++++++------------- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 4 +- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/MdePkg/Include/Register/Amd/Ghcb.h b/MdePkg/Include/Register/A= md/Ghcb.h index 54a80da0f6d7..93fb6e3cb0fc 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,19 @@ typedef PACKED struct { UINT32 GhcbUsage; } GHCB; =20 +typedef enum { + GhcbCpl =3D OFFSET_OF (GHCB, SaveArea.Cpl) / sizeof (UINT64), + GhcbRax =3D OFFSET_OF (GHCB, SaveArea.Rax) / sizeof (UINT64), + GhcbRbx =3D OFFSET_OF (GHCB, SaveArea.Rbx) / sizeof (UINT64), + GhcbRcx =3D OFFSET_OF (GHCB, SaveArea.Rcx) / sizeof (UINT64), + GhcbRdx =3D OFFSET_OF (GHCB, SaveArea.Rdx) / sizeof (UINT64), + GhcbXCr0 =3D OFFSET_OF (GHCB, SaveArea.XCr0) / sizeof (UINT64), + GhcbSwExitCode =3D OFFSET_OF (GHCB, SaveArea.SwExitCode) / sizeof (UIN= T64), + GhcbSwExitInfo1 =3D OFFSET_OF (GHCB, SaveArea.SwExitInfo1) / sizeof (UI= NT64), + GhcbSwExitInfo2 =3D OFFSET_OF (GHCB, SaveArea.SwExitInfo2) / sizeof (UI= NT64), + GhcbSwScratch =3D OFFSET_OF (GHCB, SaveArea.SwScratch) / sizeof (UINT= 64), +} GHCB_QWORD_OFFSET; + typedef union { struct { UINT32 Lower32Bits; diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index 8e42b305e83c..c5484a3f478c 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -153,7 +153,7 @@ STATIC BOOLEAN GhcbIsRegValid ( IN GHCB *Ghcb, - IN GHCB_REGISTER Reg + IN GHCB_QWORD_OFFSET Reg ) { UINT32 RegIndex; @@ -179,7 +179,7 @@ STATIC VOID GhcbSetRegValid ( IN OUT GHCB *Ghcb, - IN GHCB_REGISTER Reg + IN GHCB_QWORD_OFFSET Reg ) { UINT32 RegIndex; --=20 2.28.0