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.web10.1665.1580857343101360274 for ; Tue, 04 Feb 2020 15:02:23 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=NCRHtKU3; 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=c9xJ8kUjkEm5F3JZyPlM/6JQKGKldSHUc7yFY6l/cxtPmShH+ZJG2emtJLOac5aSm2pcR9sk1f9Uw7heSEN2olJtxTDFHYfDKqR8NZBJsSvffly/4TN4h0y1OY6TbRMQ+0G3vGo3dFqAYEHg1mE6BlzxXkgzPbPOc6XVFyYDz//+lPsbh6Jc9rqD2nOLael5YmWQOINHqWZbZv1lgXtngH34L2Sf45srxemLTE/dhwlAtGJzqJdzW4mr6RwwArwbDoo2+0m6oOSpvA2qqC/j6++g4jSgOEjEweyME7h9VrC40jBib05glJixukCU0cBDtGKSyAcu/ueJLlEsvZwFkw== 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=ySpnu2LSCPI7ZfnWXEQjmZYar7FHl13GfJrz7a9c9jY=; b=Os75xdRO7j9O1uV3LBL+RDxbLc0dSZRixsf/zI4p1WmA6RLcCBBhmb8Dx10yC7k9XqDyafE7wNvRAi32BYlHfRf16mOaGVE/hsEoKj75Rc9p56LUDrT4OZFWTicCzyKsOiit0ObeyaTX9lnl3Co1IlVcNgRJqsDDmjH9VMKk1YiHOsfCknq9jUKo+WTcCHi/K3VmfvkCEb6Mb5SsbIuW3PGWeFZ71DNel1WKCD0ENyuSm/Vw9+Iwp6b4FYY/DrShK2sLvwn5J3bJ/xQpZ19E0LOVrDkJMuVhU74Zmn38hpWD3HiaRjLb+d5tQj7GEx3BLI0oHriwYjHrqCBAgpYSJA== 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=ySpnu2LSCPI7ZfnWXEQjmZYar7FHl13GfJrz7a9c9jY=; b=NCRHtKU3VQkIg2q38yMhnFmDyQQwH+ydSZES8D5a04lDtX8/Zakmb+r+agMiv1O4J5mWPdeE6obP0jPUPjjHTwNCmZ5NBk03keRtfjz2VU2E6Gss0QxH3KiPaoXXrjA5/0IHwGTd8z2nmgOeBA/VGW78eGTmpfYxteo2GDT+Dvs= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; Received: from DM6PR12MB3163.namprd12.prod.outlook.com (20.179.71.154) by DM6PR12MB3930.namprd12.prod.outlook.com (10.255.174.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2686.29; Tue, 4 Feb 2020 23:02:21 +0000 Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::a0cd:463:f444:c270]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::a0cd:463:f444:c270%7]) with mapi id 15.20.2707.020; Tue, 4 Feb 2020 23:02:21 +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 v4 19/40] UefiCpuPkg/CpuExceptionHandler: Add support for RDTSCP NAE events Date: Tue, 4 Feb 2020 17:01:23 -0600 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR16CA0062.namprd16.prod.outlook.com (2603:10b6:805:ca::39) To DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) Return-Path: thomas.lendacky@amd.com MIME-Version: 1.0 Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR16CA0062.namprd16.prod.outlook.com (2603:10b6:805:ca::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2686.32 via Frontend Transport; Tue, 4 Feb 2020 23:02:20 +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: a2fe2d99-76c0-4e88-97cb-08d7a9c64a63 X-MS-TrafficTypeDiagnostic: DM6PR12MB3930:|DM6PR12MB3930: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2000; X-Forefront-PRVS: 03030B9493 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(39860400002)(366004)(376002)(136003)(396003)(346002)(199004)(189003)(4326008)(478600001)(6916009)(81156014)(2616005)(956004)(81166006)(8676002)(966005)(316002)(54906003)(19627235002)(2906002)(6486002)(66476007)(66556008)(52116002)(7696005)(186003)(26005)(16526019)(5660300002)(86362001)(36756003)(66946007)(8936002);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR12MB3930;H:DM6PR12MB3163.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; 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: xalJOw26VMX9PhJQHuM11XPDBwZuySXAK0jn/jNTr0M2PcIlItvxwjUZyotwc2LiYu3SlPAP1XVHPM9iPzBE6+KIJExOI5/+rFa2nFCYnasffGg0zhXGHIp2ewKpiW0azHVg2QSOkDgWu8lTLS2uphGHEYPUOH2231J4AodfNRWPgxssQaJNr8Akwh790LT0Fc4TivgJue42aj8RQ1tpaqIgF1k9wgN2pbD6B5p9RNmvXR//zeQZJ3TykHWcTrbS7o5PVxs8g9BNrmB/rXvD1GQpuGdDnMRkVaPjsqms4oeMLBKP4cTD8ahePPudCM5LC38hxg4JCHJlW+SiemBvhaDTT4uKhAQFOFmzXEQJ5qOO6hXb4AOAW01ua2tBO63NULQmeq8bjKK96J8uk8ueSVz6sRLymJdj+drTVThz7E8w4bdKgr/sZoTlqAnqdWjwPTMBiyhi72pEsE2kDcjnoh+z1g2g71z3dt6SGsEvPw0/wKeBn8DLOi9gT9tIHiIXmFyjSLHcp/2ewMYhAamdug== X-MS-Exchange-AntiSpam-MessageData: cwjaCSUtWrOoRQ/BJELN4SKLydna44k70cg0Ermete8XR4mlixJL3yKcVv+t17kKYXZdShyV0WcZkSdbxrYanPv5bqXxBGIDjDuphKqwVx7OPA6nVcTkeQkSGNxpjpT2gzqj54yBav38KG5Tc633nw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a2fe2d99-76c0-4e88-97cb-08d7a9c64a63 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2020 23:02:21.4982 (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: yuXGTpKHavZzgrG4/wvUCFSGu47DpGDbNVbyf3YlG0klXKq7Oe4Shcxdka7Wya4evWQFq6QfJpyIXI1z88CK3w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3930 Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198 Under SEV-ES, a RDTSCP intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Signed-off-by: Tom Lendacky --- .../X64/AMDSevVcCommon.c | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c index 734c2bbeb989..f18fbe97e147 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c @@ -609,6 +609,35 @@ WbinvdExit ( return 0; } +STATIC +UINT64 +RdtscpExit ( + GHCB *Ghcb, + EFI_SYSTEM_CONTEXT_X64 *Regs, + SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + DecodeModRm (Regs, InstructionData); + + Status = VmgExit (Ghcb, SvmExitRdtscp, 0, 0); + if (Status) { + return Status; + } + + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRcx) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax = Ghcb->SaveArea.Rax; + Regs->Rcx = Ghcb->SaveArea.Rcx; + Regs->Rdx = Ghcb->SaveArea.Rdx; + + return 0; +} + STATIC UINT64 VmmCallExit ( @@ -1039,6 +1068,10 @@ DoVcCommon ( NaeExit = VmmCallExit; break; + case SvmExitRdtscp: + NaeExit = RdtscpExit; + break; + case SvmExitWbinvd: NaeExit = WbinvdExit; break; -- 2.17.1