From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=CbSr1A7B; spf=none, err=SPF record not found (domain: amd.com, ip: , mailfrom: thomas.lendacky@amd.com) Received: from NAM03-BY2-obe.outbound.protection.outlook.com (NAM03-BY2-obe.outbound.protection.outlook.com []) by groups.io with SMTP; Thu, 19 Sep 2019 12:52:45 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ceWlAHV1p9OqF3fzyiwJrAlXmgW0ltnfcS3aTSiK10OkZ/u0VxYtFg5sLNmdBIL6VPOwpk9WrxGkWXmRtlA44DxiFOguda81KBP+i00c99hKHCyAWEFbaSi0MInmv3pOAcHHx6H/WOlrEl3LgxV4eqBx5kLtWBsta2vIbKQRa2Kalja+YIW1wnNjs8T3Y645tukBWQPCBk7tr6Q+ZgNFG1ikhg3qgOIzeAum6cqikTn89MbZXmBFgkAs4zIDzgRnwVE/66VONEAmCPyplPjljypej0pwrozz/SZMjqdczCdTXpxfvw44uRdEQrIXKJfjSGQ5FNbFwYlfBVsDYYMzaA== 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=LGKxBDmFb/OiHHE/v0t1pJALsw007JXDmG5C8e9ICMc=; b=MbUaLVHgumiLbc3fpzgT5aTpp74ipIA5utKKN3EF+/rCQIxesnLCdXAhFS429UFczWez1A+N284wjmFEw6jkb6kExLzx2+oqj6Wu0F33gDDFVAbJtZwhiv+PZuS3U4AAjw0Y0c1aMF7O9cJ38q5hOe1EzBAtsaa2l0oWc1hy360Avq1AzXcbf2sKPtQHaNWDhrB6H1gSnQpzV/3VJUkMqNQIjxHZZXUCr+5sBcUtTWLdeX5c83xdCrng0GbgqZ0mIQr9n0lYEXK19w/zWcKS4ilFRohGF1jv8CWYaLSKOsgvgwi6YToyvMOtPVokGhZVCRXYL5VT0TXQ4+wIlSvONA== 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=LGKxBDmFb/OiHHE/v0t1pJALsw007JXDmG5C8e9ICMc=; b=CbSr1A7BPAx6jqJzCBN5IT4058JXmyv4QgRFywIqxA/8B/W8cgolQ0lK+/vufj/zcbOJ1NMIGaf2otqSLVuuC4oTj7yYYydTzXz3oAuitFp1r1wae+ZIrOBBL7V1E3qpf1blBFrVzhfWz+HA4yyO6VhyQqDIhOJ2LY/9NcBVSWo= Received: from DM6PR12MB3163.namprd12.prod.outlook.com (20.179.104.150) by DM6PR12MB3228.namprd12.prod.outlook.com (20.179.105.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2263.13; Thu, 19 Sep 2019 19:52:44 +0000 Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::400e:f0c3:7ca:2fcc]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::400e:f0c3:7ca:2fcc%6]) with mapi id 15.20.2284.009; Thu, 19 Sep 2019 19:52:44 +0000 From: "Lendacky, Thomas" To: "devel@edk2.groups.io" CC: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Michael D Kinney , Liming Gao , Eric Dong , Ray Ni , "Singh, Brijesh" Subject: [RFC PATCH v2 17/44] UefiCpuPkg/CpuExceptionHandler: Add #VC exception handling for Sec phase Thread-Topic: [RFC PATCH v2 17/44] UefiCpuPkg/CpuExceptionHandler: Add #VC exception handling for Sec phase Thread-Index: AQHVbyPNOeGdUWdiR0e9W+asMAMu7g== Date: Thu, 19 Sep 2019 19:52:44 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.17.1 x-clientproxiedby: SN4PR0501CA0146.namprd05.prod.outlook.com (2603:10b6:803:2c::24) To DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:182::22) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [165.204.78.1] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 6a6c03b3-49a7-4672-f3c5-08d73d3aefb3 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600167)(711020)(4605104)(1401327)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7193020);SRVR:DM6PR12MB3228; x-ms-traffictypediagnostic: DM6PR12MB3228: x-ms-exchange-purlcount: 1 x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8273; x-forefront-prvs: 016572D96D x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(4636009)(1496009)(366004)(376002)(396003)(136003)(39860400002)(346002)(189003)(199004)(4326008)(26005)(446003)(25786009)(52116002)(14444005)(71200400001)(71190400001)(8936002)(81156014)(81166006)(256004)(8676002)(186003)(50226002)(2351001)(2616005)(102836004)(486006)(11346002)(476003)(66066001)(386003)(6506007)(66446008)(14454004)(76176011)(99286004)(6486002)(36756003)(5640700003)(66556008)(118296001)(3846002)(316002)(7736002)(2501003)(1730700003)(6116002)(5660300002)(478600001)(54906003)(6916009)(966005)(6436002)(2906002)(64756008)(305945005)(86362001)(6512007)(6306002)(66476007)(66946007);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR12MB3228;H:DM6PR12MB3163.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 3EBsvl04oDOHdBHwqu+98HeZBfOeV0Ndyxs5tdwgBvvQnz1N8Yfyuee1Yb4rL/clk0FuP4BUsYOthCmeCvtYMpTaxXD4MGXeRDNfhAXGsU1nsNaLO5iGY0aDBT9h62oeDGTvwM022gSvi07N4ka1EvJnco8kcdzOKvMnt3kI7mI3ju+E9WqU/SpcRgwHM3nZHbyhdih3ZJettxkh7PHcwIoytfs/p9aJ2voMDex3/0nDMPF7woB6cLCbOiKtWJRSwIKwaFfBfCpVzB5w7sstwfJhhTt4ElpeX7ppbfTxgT5bHMrT5oXwfjt+e5WaAV1FX5XBScY3qaSxNJh5OtviwFICcU3M+dD3uZ0gSdTjp6I2QBnT3cViHEap5HgMyFF68TuSTx/I/bzbgcqcTVx9TwgM46q/vr0BSbfCNgXHeuI= MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6a6c03b3-49a7-4672-f3c5-08d73d3aefb3 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Sep 2019 19:52:44.0666 (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: y0WkdmMH3CCSZgIM4K3Kcm/gXN6fyuIznAxIq+Z+hjYSoM5ggwLMvm5qWFhXHjUgccJE2/akrPDZMv0KBCvvww== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3228 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-ID: Content-Transfer-Encoding: quoted-printable From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 An SEV-ES guest will generate a #VC exception when it encounters a non-automatic exit (NAE) event. It is expected that the #VC exception handler will communicate with the hypervisor using the GHCB to handle the NAE event. NAE events can occur during the Sec phase, so initialize exception handling early in the OVMF Sec support. Add to the basic #VC exception handler to set the GHCB MSR to a pre-allocated GHCB and call a common #VC handler. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Signed-off-by: Tom Lendacky --- OvmfPkg/Sec/SecMain.inf | 1 + OvmfPkg/Sec/SecMain.c | 29 ++++++++++++++++------------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/OvmfPkg/Sec/SecMain.inf b/OvmfPkg/Sec/SecMain.inf index 63ba4cb555fb..7f53845f5436 100644 --- a/OvmfPkg/Sec/SecMain.inf +++ b/OvmfPkg/Sec/SecMain.inf @@ -50,6 +50,7 @@ [LibraryClasses] PeCoffExtraActionLib ExtractGuidedSectionLib LocalApicLib + CpuExceptionHandlerLib =20 [Ppis] gEfiTemporaryRamSupportPpiGuid # PPI ALWAYS_PRODUCED diff --git a/OvmfPkg/Sec/SecMain.c b/OvmfPkg/Sec/SecMain.c index 3914355cd17b..7f1dfb2e57c1 100644 --- a/OvmfPkg/Sec/SecMain.c +++ b/OvmfPkg/Sec/SecMain.c @@ -24,6 +24,7 @@ #include #include #include +#include =20 #include =20 @@ -737,6 +738,21 @@ SecCoreStartupWithStack ( Table[Index] =3D 0; } =20 + // + // Initialize IDT + // + IdtTableInStack.PeiService =3D NULL; + for (Index =3D 0; Index < SEC_IDT_ENTRY_COUNT; Index ++) { + CopyMem (&IdtTableInStack.IdtTable[Index], &mIdtEntryTemplate, sizeof = (mIdtEntryTemplate)); + } + + IdtDescriptor.Base =3D (UINTN)&IdtTableInStack.IdtTable; + IdtDescriptor.Limit =3D (UINT16)(sizeof (IdtTableInStack.IdtTable) - 1); + + AsmWriteIdtr (&IdtDescriptor); + + InitializeCpuExceptionHandlers (NULL); + ProcessLibraryConstructorList (NULL, NULL); =20 DEBUG ((EFI_D_INFO, @@ -751,19 +767,6 @@ SecCoreStartupWithStack ( // InitializeFloatingPointUnits (); =20 - // - // Initialize IDT - // =20 - IdtTableInStack.PeiService =3D NULL; - for (Index =3D 0; Index < SEC_IDT_ENTRY_COUNT; Index ++) { - CopyMem (&IdtTableInStack.IdtTable[Index], &mIdtEntryTemplate, sizeof = (mIdtEntryTemplate)); - } - - IdtDescriptor.Base =3D (UINTN)&IdtTableInStack.IdtTable; - IdtDescriptor.Limit =3D (UINT16)(sizeof (IdtTableInStack.IdtTable) - 1); - - AsmWriteIdtr (&IdtDescriptor); - #if defined (MDE_CPU_X64) // // ASSERT that the Page Tables were set by the reset vector code to --=20 2.17.1