From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.58]) by mx.groups.io with SMTP id smtpd.web12.1289.1585071683796660650 for ; Tue, 24 Mar 2020 10:41:23 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=UI+qbGa6; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.243.58, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hBscevVUkK11jpEwm1CN6dgrGdGIE3c2BVEagJ1mWAO+dihgsGRvt6KydWKnce5a2LJUx6Mu+2O2OgfoHGhm/topsPOT+JDk/cML5LbiDHegad2jB0twkzHnJyyluVlYQUbVP2sSDZdLSHMjT5ifKxXZaVsFW/jaXZWSC6QwbPi9+jecSjKd3hUnvDe+ZVeCKNOsTKu9nma7xBgP+KsgeZcJjlqQojSYVv5voKM+ALHOlmj1GGbMpY/ozVZ7WI39I62HdLWMx/vMi33nc7uDLj5ZyPp4COeTqCNfvt4SCnmX6uRTZVF23kguuI26L0Pj42r+t4dYgLIPep1hYXiYjA== 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=y06eqEKuZOmUDDmQz/38mXsQaiyZ7su0A7sW+kGFyqk=; b=YwyFg+ILBYChA1mQDTL7AvwO/XnL9Sd70dwBiVURTfZ/l41KZnWje2xDHRMQBAWEh1IOkPRqm81Jeqz8FI+e6NRJzOa0pLQBiT2McgdAulgOKsDhdRP2CeAbVatVZWEIFg/I84jE2ft+krk1ccJlMcYhQbxpm+/uGfwkLcHEAvH15u69i0rmnqL/m6n/BKQaM+f+0Z45t9+Ti6mjgZ3N2yOHtiP2rZUzoT4cCZSd1hCvB+Ei9Bcw00TXA3DQEpwYsTPoulV5GitdVE0tajhWjuYweKQAlLwZhZfJ9y1Z09UjnVY4Cbc1ZbR8PqrrUxw+1HKNkccegxFiIK2v3v4mxA== 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=y06eqEKuZOmUDDmQz/38mXsQaiyZ7su0A7sW+kGFyqk=; b=UI+qbGa6NFa1E5CQDvXrrWfR8sarQsLil8BavANqrFT3nakMGdYlUBNZ52dCmIFulTuGSBhO77bK12zwxfudBv397yBJlIRW8G3RlgZAipEFW/cNs3d59Tr4DIjnd0h3zarAUJIqVGbvK6yBXzzxi6XKJgpkLJMGTds87D4taOo= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; Received: from DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) by DM6PR12MB3915.namprd12.prod.outlook.com (2603:10b6:5:1c4::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2835.22; Tue, 24 Mar 2020 17:41:22 +0000 Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::f0f9:a88f:f840:2733]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::f0f9:a88f:f840:2733%7]) with mapi id 15.20.2835.023; Tue, 24 Mar 2020 17:41:22 +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 , Brijesh Singh Subject: [PATCH v6 13/42] UefiCpuPkg/CpuExceptionHandler: Add support for CPUID NAE events Date: Tue, 24 Mar 2020 12:40:27 -0500 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR06CA0025.namprd06.prod.outlook.com (2603:10b6:3:5d::11) To DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) 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 DM5PR06CA0025.namprd06.prod.outlook.com (2603:10b6:3:5d::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2835.19 via Frontend Transport; Tue, 24 Mar 2020 17:41:21 +0000 X-Mailer: git-send-email 2.17.1 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 269ef853-d702-4e19-c6d1-08d7d01a9147 X-MS-TrafficTypeDiagnostic: DM6PR12MB3915:|DM6PR12MB3915: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-Forefront-PRVS: 03524FBD26 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(376002)(366004)(346002)(136003)(396003)(39860400002)(8676002)(8936002)(186003)(316002)(54906003)(16526019)(956004)(66476007)(36756003)(6486002)(19627235002)(66946007)(6916009)(66556008)(2616005)(26005)(4326008)(966005)(81156014)(478600001)(81166006)(5660300002)(2906002)(7696005)(52116002)(86362001)(136400200001);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR12MB3915;H:DM6PR12MB3163.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DbK1yxBH1hkyKbgSFtAO7HI3RdrM/joJIOVKn/q9b1CSgeAD7JOGeld1NgvfRjonJBUyKMtkdNCX76QXmLFQ6X/7/7vouw0qi6gE4TxuyblJj9QXjupX/IH59N3vBWydtQ/b5pDzwP1wgbyFpambmjf1BgEulS/L7dIqydhH23W7nv4jXggjLb4jtzpz2i5pGuG8OWKevNrFWMF063B22tOIE29Qw4jUH/EToEAM9SpWOm36rC+CaqHTCalPa9yP4x2rvFpOWRcELsQwb3CAV91/TNsnO9FTgGz6BC3Ez6yIsTPvSbRFg1tBt9eRu/RE8raA3hBYCPqcg5YwjaX86gSGqm3drQrVnnc64ls12xUg9LCg1d/n4e9MWEBLgincnsWok962LAbB7SGdtxLYPpOjEd4aqT2MModlkG78rh4l3htnQZFMk0G1MWTCMXjr0fUiGbN0pabNNiKdk2m/AblaelYYh41S+fdLRRINKM59rYkJt4tjVfKXVwJ9W4qJPZFWPIZldb76BiGP2Cm3/MWnBlMhutby9eV2OAmCYFz0EV3/mLkB2omLG+2jRWrFsNxE2rIjCsZ1FXNp021BUQ== X-MS-Exchange-AntiSpam-MessageData: Iwe3wdd8B2pKhiaW7AjEITCaqL78Ox6uYB2vlJ7/v4ORNTXzlHslxXTnQF78sMeWeEqbL+DDkd6RspaQWY85TaIczAbMV2KM33bXahwhx6cKHG+ynSJXU0+rMLzldDXZlIgnKhDbg8d/4qxAs60hXQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 269ef853-d702-4e19-c6d1-08d7d01a9147 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Mar 2020 17:41:22.3590 (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: PjiVj2maMDPDObKA2frLVSlTqjxv27EwzFRN73ou1NuvG5s6F+CkXaN3R+Ulhcqe9WWZmahogtZ+JyKYiE/9uw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3915 Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198 Under SEV-ES, a CPUID intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Add support to construct the required GHCB values to support a CPUID NAE event. Additionally, CPUID 0x0000_000d requires XCR0 to be supplied in the GHCB, so add support to issue the XGETBV instruction. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Signed-off-by: Tom Lendacky --- .../X64/ArchAMDSevVcHandler.c | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c index 24f746f994ca..d57444b50719 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c @@ -11,6 +11,8 @@ #include #include "AMDSevVcCommon.h" +#define CR4_OSXSAVE (1 << 18) + typedef enum { LongMode64Bit = 0, LongModeCompat32Bit, @@ -494,6 +496,44 @@ IoioExit ( return 0; } +STATIC +UINT64 +CpuidExit ( + GHCB *Ghcb, + EFI_SYSTEM_CONTEXT_X64 *Regs, + SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + Ghcb->SaveArea.Rax = Regs->Rax; + GhcbSetRegValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Rcx = Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + if (Regs->Rax == 0x0000000d) { + Ghcb->SaveArea.XCr0 = (AsmReadCr4 () & CR4_OSXSAVE) ? AsmXGetBv (0) : 1; + GhcbSetRegValid (Ghcb, GhcbXCr0); + } + + Status = VmgExit (Ghcb, SvmExitCpuid, 0, 0); + if (Status) { + return Status; + } + + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRbx) || + !GhcbIsRegValid (Ghcb, GhcbRcx) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax = Ghcb->SaveArea.Rax; + Regs->Rbx = Ghcb->SaveArea.Rbx; + Regs->Rcx = Ghcb->SaveArea.Rcx; + Regs->Rdx = Ghcb->SaveArea.Rdx; + + return 0; +} + UINTN DoVcCommon ( GHCB *Ghcb, @@ -510,6 +550,10 @@ DoVcCommon ( ExitCode = Regs->ExceptionData; switch (ExitCode) { + case SvmExitCpuid: + NaeExit = CpuidExit; + break; + case SvmExitIoioProt: NaeExit = IoioExit; break; -- 2.17.1