From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.49]) by mx.groups.io with SMTP id smtpd.web12.662.1583190466300906709 for ; Mon, 02 Mar 2020 15:07:46 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=TIvNeSIB; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.93.49, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kYEb/f/nyPjqnFfYjvjnzkcPYwtWj3gV27V7C2ocxCu49tPuVcU1AcMo2HJ1EvAY+MT69G4uq3MwSne1149Ty4nvcOi3IEWWFdq3z2piix4IvXXPrrOf1Dmk8Fy/MqTnNSJpU+Fchu4DRTSxEBf37ni3xmwHanhfGytUdmP1chEhXAvAjbgGzG596OJirQByzHo71Byk4FYhKKwMJtccQpUfosArusnkN+ArSThfvEV9q5GC4AodmmpU9Dnuk06MICQxGs8A2PX0bc4vqcmtUWnbmbCGdtGIb2Fizo7vUifh69VXRz8FwBRGzgK3kk6wkzIERqOkHPWjPeRj6/PzOA== 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=tvVdmYcoWJu/7TX03oUdp5/JibQfS/KYTwGZV5K527k=; b=H4fiKMZEFaELn4uoaNrZqWrvrcqK5ViLNuoChYtbXFdiBzbBFZWaNUT2jZWN+r8HSGG+svymmg9nKLuhu7wF9KDjV4unpfLfGn/ziqrV+oQLaZD2Gr70RNnOrpvKzMLo1eGyMzpqp/2SUpv+8PQ0C8kVrbhWWNYIE0CSl/V0oCgSDeVxxZjXZiuYwn0tOeiGC7pLjmDOdwB0tB4ZwE2ChpK2nu9/DRuHdNa3ck0eTqvdRHOIHWvSJiTcEro2+9KkKRAoajnMWoTr91PicWAD8PqiZt8otg5Y/5b512Ht0Q9KIvqyY2ECpmunu6Loej+XHW74hltOFnqc2IjEnpdS/w== 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=tvVdmYcoWJu/7TX03oUdp5/JibQfS/KYTwGZV5K527k=; b=TIvNeSIBdifQvf0cjF5bG0V2BoLGadQEihSwFW0+1XhZ04eSMdNIrzorkuLoC6ngfkyteyirFRB+KjHgEgxWR8iOV11Ulw+QXSR7g/eWKLSaOLMg57qVsTlTh74/GVYRTKOJiXQzebYv6rHEvOJpPI6wrweZZgdXClXxZfp26YI= 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 DM6PR12MB4041.namprd12.prod.outlook.com (2603:10b6:5:210::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2772.15; Mon, 2 Mar 2020 23:07:45 +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.2772.019; Mon, 2 Mar 2020 23:07:45 +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 v5 17/42] UefiCpuPkg/CpuExceptionHandler: Add support for RDTSC NAE events Date: Mon, 2 Mar 2020 17:06:48 -0600 Message-Id: <7624fa11bc1774adb70f2528f6cfeda439feeb58.1583190432.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR2001CA0013.namprd20.prod.outlook.com (2603:10b6:4:16::23) 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 DM5PR2001CA0013.namprd20.prod.outlook.com (2603:10b6:4:16::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2772.16 via Frontend Transport; Mon, 2 Mar 2020 23:07:44 +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: a8a1fc8e-e197-40a6-78a3-08d7befe8485 X-MS-TrafficTypeDiagnostic: DM6PR12MB4041:|DM6PR12MB4041: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2000; X-Forefront-PRVS: 033054F29A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(376002)(39860400002)(366004)(346002)(396003)(136003)(199004)(189003)(478600001)(86362001)(5660300002)(81156014)(36756003)(6916009)(316002)(4326008)(54906003)(2906002)(6486002)(8936002)(81166006)(8676002)(966005)(956004)(2616005)(66476007)(66556008)(7696005)(52116002)(19627235002)(66946007)(186003)(26005)(16526019);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR12MB4041;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: nyhgFJdzRY04bwuLqyzqo3iv6c0AoMzP0U1gSadOCmKA+IxvMq/tW7W2ZgNYX5Ujki++edgg7vu46sZOtousMdNIO4b6hNaqqDA1KI/scgnPtl8ayp9GCpLT6ZCTQbeUg2mtg6YcrNCgzAIMBEVMhyIZqunaOUl84eTE+1wP/gOqFuDEBslTuhXE7LUdOJ0iWv1OMGSFvUsEI596YhQaI008eJ6YtMCYXswDsDvUEjK3OrzmbXQ6kve0MN5ZhfIDFlwQ4y9vGb8Jqfrmt0pztC4uJWVnu+bN98WglJ+AHT5b6Hrh5Sktb4mIM+8ocvYoz7PjlJEquWWRRz1WLNaD+E9ylNqNHouVAb/DIKcpai232B7e26Y+nSAJY4rakwcG8eso7SnFu83aZGQJIcp/lyLXzD2Bc9Y5H2BSH7L1YlBOmEEtlNueaYfZEmo7aZ8pJXIDsotX294K4UYPVuDe2oOtxyMczAunS2/2Qt7HgqPITFMFeJ72ZKv4CgKJnNmkqtFUU6SDGobbThCJ1G6QIg== X-MS-Exchange-AntiSpam-MessageData: f679QiY5SqdoNALJ5w9Yt8FDOG92CAw7S1F481eKdskLb+HtYtSm61hgOONHL6BJjtjwslSU5qjkSzPS5mC0gYMyFVEAQlWhKCChWQZ0g7nCr2AJ52hIGl4gV/3XYU8pVUJOEpxaJLdlBQ5aVVNhMQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a8a1fc8e-e197-40a6-78a3-08d7befe8485 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2020 23:07:45.3922 (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: Q7qwbdMC9Aw9RnrbZXQN2D9bAFBgj2t+zMZPs2b2JnowVt89p3UkZ1MqhdedDSQ8NZKXgJkRi7LymPMvMYXCVw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4041 Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198 Under SEV-ES, a RDTSC 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/ArchAMDSevVcHandler.c | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c index 1096403261db..82f42d905068 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c @@ -894,6 +894,31 @@ CpuidExit ( return 0; } +STATIC +UINT64 +RdtscExit ( + GHCB *Ghcb, + EFI_SYSTEM_CONTEXT_X64 *Regs, + SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + Status = VmgExit (Ghcb, SvmExitRdtsc, 0, 0); + if (Status) { + return Status; + } + + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax = Ghcb->SaveArea.Rax; + Regs->Rdx = Ghcb->SaveArea.Rdx; + + return 0; +} + UINTN DoVcCommon ( GHCB *Ghcb, @@ -910,6 +935,10 @@ DoVcCommon ( ExitCode = Regs->ExceptionData; switch (ExitCode) { + case SvmExitRdtsc: + NaeExit = RdtscExit; + break; + case SvmExitCpuid: NaeExit = CpuidExit; break; -- 2.17.1