From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.81]) by mx.groups.io with SMTP id smtpd.web10.9728.1602346048983524589 for ; Sat, 10 Oct 2020 09:07:29 -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=NSBchXhy; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.244.81, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MvmfkIvVR78dgh4gYLhgGFSbceOSxurNjgKV2X93FuZP5mXuQeFrJ6g0QAKQC4GlpQ9okDLAoZpdURq4TMLGaMDWnAdwBLeEXH53ycJhXZ4oKei6AlBWUXZ7eeas66V+uX2x8jGx/aX4PyFn8D9xMnIQghoHKzRRdijiqwGZXUbzTpY/PVM/SSlOrA7XUEHYxljMAF9gXS13mM900YLl7+dk78gtnP/D9WVoiLusLwWWhRRJ1KPhhaKGkttSZqs1CGw8jJOCPrtKdiLTyg2pIPXu0zx1KoZkuc5qFHZ7C0Z/f9DjIxvye0JzRy9dpeqGXLfp8a3vnF3uNjM4ybaDKA== 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=ipkFKQlJ+B95zh2YjPoN74zzBKiElWg+C30hrjvz2Fc=; b=c42kzQ3b6SwEpEc6DX9mj9REWrKWCuWNSu/X4i0z/Oxkz7KtKK99u5RgLGwPm9U1sAQLv7KnnJNJFCTxIkdlkbssZdmX+T8x91N+tRLD8lOsbHi/z0OJZcBkrFakwtvJDDbQM1CxyoJuTgQ8HaQqqfr7miHTTRDA+8I1QyFZaKoI9qutijXOVIzM+k0uyk2mB1UZNJJmTypoD6mS3EMYsnBcRjerblAdSszqAgZdoWnnzAwFjHI/geIA4FIw4TfnLWthFgtTuWBUcpKo7HREClUvsnYzGcsx9xeHDyxyiMj3GrIdrrv50sW2/aYM02Qn1sm81hVlWdNycMlBDS0oCQ== 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=ipkFKQlJ+B95zh2YjPoN74zzBKiElWg+C30hrjvz2Fc=; b=NSBchXhyLCHSI7C3XBzpkCTGfNWy0aFzYGga92QKC5DD+YC8X3kX4xaua8GOUjDoIZmNnxvAQ5DFBAXCpL2Bnt6VA4F7J/b9bIqemB96d30RR0kshr9rUiwjxpDy0D9dz1J9+o9U8t5LXBMrMmBb/C6d+/MvJuKoKxqzgZJaDMU= 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 DM5PR1201MB0122.namprd12.prod.outlook.com (2603:10b6:4:57::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3455.28; Sat, 10 Oct 2020 16:07:27 +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.026; Sat, 10 Oct 2020 16:07:27 +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 1/9] OvmfPkg/VmgExitLib: Update ValidBitmap settings Date: Sat, 10 Oct 2020 11:06:59 -0500 Message-ID: <2f5fbbbe7183109a3ec28f17f0810032476ddbc3.1602346027.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: SN4PR0501CA0135.namprd05.prod.outlook.com (2603:10b6:803:2c::13) 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 SN4PR0501CA0135.namprd05.prod.outlook.com (2603:10b6:803:2c::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3477.13 via Frontend Transport; Sat, 10 Oct 2020 16:07:26 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 00c087c4-c746-4e7c-abe3-08d86d369512 X-MS-TrafficTypeDiagnostic: DM5PR1201MB0122: 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: 3qAHTeB1I+U1V2ZQV4KzD7y+AIQQquc7U1Np1SInfRCzDNys1HPt3yMvOEVBZVOiOr/hyBH76h9hP5z6YWCpWkvkPbIPPVNmdI5/AfIAHdgzT5JMF/4GhYHbdmN4Xl8f/1GqCpvj7IuKLU/C6ECesmEOJ2W+w3FPcBu2jSVazaBs0NrbBhgbne8PeRGyzowOXywQhd/URBCfaVaZqEAZ9Lwi6CzvD4dHpeBgtDPcgCI32olkAqtxdId1AMQDcrnMsS1IBVLUWuvulVLCP1SrQf2Lj+AzqNsYTW47agQXdHm9+Bk3Pj63WeD168GvVToUSP+uOWIh0URxlE2g3js0Bg== 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)(136003)(39860400002)(396003)(346002)(366004)(376002)(478600001)(4326008)(6916009)(2616005)(956004)(86362001)(26005)(54906003)(66476007)(316002)(8676002)(66946007)(6666004)(66556008)(52116002)(5660300002)(2906002)(83380400001)(36756003)(6486002)(7696005)(16526019)(186003)(8936002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: j75PleTdQ6aI4isSFEaKqC3ElvxBkz5L8xF/Yd2OgM0vATRh/A8xqgUzWks3yv6ew1K3W12OT0b9vXE5+E2enjC7ntT/036PdXOvklvgevsYGhY3Buyb8DcCBqzyDbp7gjmAKeH89yYB/1lTQ+RSdikdWB1dAIEJXgiFauFlMR6lymKRhPXQWFlc20sT+aLYayh1FGM8g4hFXqIpOq2wlpxfX1HSSgBUh3CHrk71esqeP4zKjxsUVA0tif7rj7o/eZtO3T1KBVz0uGJrF4Hjo9JnJv6eV2qaHsDsV8VVgxo7c73Yc45QpLMHb+VPsP6MCbbm4jT/PDZIiIJais9YRR2KiiwCd6OFTE0i6GN04on40gc3UkI+W32SxnwmBXfUHyc/x1Ca8XOgGx/OE/dne9VOoALEE+t1C24sld8obOWB/fOJNQmsMeyAhplnawsOyjdj8YuKMO/8xm+FaWOuGpzPtwaqsm6GET3LV47vbEkVGn+VOVbB15OhcoeeloKqYTWQacD9fTduKRtUU7XnVVLr6xCbi7Yjx49oIiXvBIXM7zmXi0aw+oYKBqF6ye28D3qc9N7poHb/nUGm0EW8Q3QfZM34iNqTz7rbrGdwmNEz9civEXgG4GMfmzF5Cbu9PGSQN/P8PypYlI5rsF5MQw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 00c087c4-c746-4e7c-abe3-08d86d369512 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Oct 2020 16:07:27.2484 (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: RH9JnT7Rm6h0gtz3+mdZSEBNTNaIm9jPPZeOmkyq0YHPGJb98Rq5iehtsKW5u5yjPkXUUbux552PrRFs+IWEjA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR1201MB0122 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable From: Tom Lendacky 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 redefing 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 | 48 ++++++++------------ OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 4 +- 2 files changed, 20 insertions(+), 32 deletions(-) diff --git a/MdePkg/Include/Register/Amd/Ghcb.h b/MdePkg/Include/Register/A= md/Ghcb.h index 54a80da0f6d7..33c7e8939a28 100644 --- a/MdePkg/Include/Register/Amd/Ghcb.h +++ b/MdePkg/Include/Register/Amd/Ghcb.h @@ -82,50 +82,25 @@ #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 Reserved2[300]; UINT64 Rax; - UINT8 Reserved4[264]; + UINT8 Reserved3[264]; UINT64 Rcx; UINT64 Rdx; UINT64 Rbx; - UINT8 Reserved5[112]; + UINT8 Reserved4[112]; UINT64 SwExitCode; UINT64 SwExitInfo1; UINT64 SwExitInfo2; UINT64 SwScratch; - UINT8 Reserved6[56]; + UINT8 Reserved5[56]; UINT64 XCr0; UINT8 ValidBitmap[16]; UINT64 X87StateGpa; - UINT8 Reserved7[1016]; + UINT8 Reserved6[1016]; } GHCB_SAVE_AREA; =20 typedef PACKED struct { @@ -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