From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.45]) by mx.groups.io with SMTP id smtpd.web11.961.1589925110091328852 for ; Tue, 19 May 2020 14:51:50 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=CNvRXWEZ; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.220.45, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V3yeYrQaLItfrOZDAfkFyFiCX4ogMQB2glvJxgR81fPPOhTki+76Tj5Z2QaMwqA4wZMOJfxR55DaKYkWpOSF6sap5CL0t5uKT07j4BCbMzp+dcfreL4fedySVI2v4tgH6TvwF9lQaO4xqd8EboIJSmajrnVcDdSRfd/AZYEULbIOPl7PqEacf/AiVAoa9DZUxDumJA0B1fUenD39nj1B9RFzwFUBapke/SuuxRhaDZxvX1ZJxWICeJ3UHC6B33+QoDnR/oBx+cf2A33JAA/hmzi59uDBvfKohYICsbyyfe/RtRJmrAF21JQ7RydZE6ccrs4QIZzmIaqjmafswDswTw== 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=bI10WG+KAAk+daGwfE/hqSTcIf9P06YRdZ0Ctm0S3xE=; b=VgmG7/XzFiaM8hRK9CnAidGm+F1CqT4teQon3S0MBRC+GxOUuFugwVcMIV9RyBzzYz/giuwcITtREx810P9+voFTWX2BDjmEyZrvhxuWdY2PdPD0drma8+G93qnBo4l+FK8LYK//fJmXDary84DVObG8dS/cmZAkyUxH64dB1Z6JiTMgNMZDITbKalMmuw8sGn1JqQGLsHaB5ctXk+sqiOuf88qevMloQm9lGIVsOXtrX+tjrBgWdlyDk6dmVmu9P/uEepU2AWoiScPGl7P4fNBehit4Mg+ch9QlH8hRh3e3+hnQqgiYlb2Szyx1C6qlHy5LRTUO+AhB6FxlFUJxnA== 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=bI10WG+KAAk+daGwfE/hqSTcIf9P06YRdZ0Ctm0S3xE=; b=CNvRXWEZMJs40PxD92AeRquYjf5mxm1ghqthG6NKdJTsYr1krreoeG2dEz2uDGm5gE8sz3bofzRTQLJs+98rQBUPMoqPlMS3Nl+6neX7SKulyL9Jr0/wpW6tuaw9M+YwtUq1XOZ/tw/iKksuEeyEynPInw4XBW68NgD+7vaL1Ns= 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:49 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3000.034; Tue, 19 May 2020 21:51:48 +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 , Ard Biesheuvel Subject: [PATCH v8 19/46] OvmfPkg/VmgExitLib: Add support for RDTSC NAE events Date: Tue, 19 May 2020 16:50:47 -0500 Message-Id: <675998211a44fb140d5847db486c8a644e0ec003.1589925074.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) 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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51:47 +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: 21d614e3-3896-43d1-d920-08d7fc3ed4cf X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-Forefront-PRVS: 040866B734 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8R9/wd69GL2PXD8l5mfIhqbnj6NEXg6Pc8eITC2DlldMsrtRzkmSOU0fiJrHH8a+HROaq035afVp3Pgd0GuWwFwHVKvBd+t2rYknowBHP+/b4XiyCfRFp6iH2xLw9xv/2R9EhKqpoBXVnF9O0GBhxrjm7McVVkgn7I/aD/VIGpIGaBazeVuESKeJJXTeNYtma8iz8NA04Yk+NuLu6rJScQjxuSzzB7mzT5p4GVjrJ8SpxLzoYR5LUGriq/qLnqXtAThfQDZT/IQLL99M1/dF/e7mzBhOtYE2p6n/VqguN2OOsL2nyDKGxJuYKEveilYl5eXaHknXL/glW+yZbdu+7w0ADBmMR6SJVwWluRb4TkDuNt0YA6eC5vGSCf/JV40Q9o5bBWduvak40PNgEqdV4PaZzW878mrhOvYF2zaEPq+uahEFQGUNWY28Y67uFfh1loY5yzv7sECDYT0hldNkQv0TT90I22JlLuudkwTXtNx9JhkPQ6zLQDZKiuprk0fQ00ZYGCQ17XyYcogLwJxHdBHSyYqyiy5sDKNjdpbUKkbWHJFE1NGm+PWJYpZz1i2egbnsegEtYPfyD0yeGqNpiA== 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;SFTY:;SFS:(4636009)(376002)(39860400002)(136003)(346002)(396003)(366004)(316002)(86362001)(2906002)(54906003)(7696005)(52116002)(2616005)(956004)(66946007)(66476007)(19627235002)(66556008)(36756003)(26005)(16526019)(186003)(4326008)(8676002)(5660300002)(966005)(6486002)(8936002)(6916009)(478600001)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: nbxH8nHcClv7DlI3Qt87mIlqwbQ83haOc6DTMStWpzlu4ofgK58d1wVBZ6ipb7UM9giDFveCb13ZD9cbxQN+RnK5jXrn8jlWJzArP46k2AIGhrXGQak4Fy8RdwQO12aazO6KtkiWwpvIAx1Iizv4+e0bmZ1WxihS2L/LzJfgR9/0Wu3VkvphAQ96n/uBgu5WVK8l5aqvU5OQKAQnz3pOS3WR+mzIcdYMOEjvIrf6Ry0w1GrS0/QGBHkI5YSXPhTIyzgESt9+IWIAcugSx9Yh08w9WihLU5w4uNzb5vJxFxTIZGxtWejB5i/kd+dX+rj6LTU5eOBdB+tqdbw6/WGmdx9i/TCngbWgzAXd7IFYxGOYqktNEgaKW0GZUIe8bItZWc95tBQnioruSEb+bMnTCIYWs4QVmQoYHp6baCT/PhI3DFavJxFhT8xU03Id24c3VI9eOq2buZ3D1kKof6RE4q+iHJRb0h9fG/stKeNbix4= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 21d614e3-3896-43d1-d920-08d7fc3ed4cf X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:48.7956 (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: B2N5+CIMFoMHZH7RgF8Df1XEnOQ/fN62TKAYsIPVed4I+qOuQG99KIkyoFB+dCPs8sK0zlJCocX9Q37DT3hjdg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Signed-off-by: Tom Lendacky --- .../Library/VmgExitLib/X64/VmgExitVcHandler.c | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c index 0cf26c052b32..3d2a9c6f9bc9 100644 --- a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c @@ -1214,6 +1214,45 @@ CpuidExit ( return 0; } +/** + Handle a RDTSC event. + + Use the VMGEXIT instruction to handle a RDTSC event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communication + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @retval Others New exception value to propagate + +**/ +STATIC +UINT64 +RdtscExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + Status = VmgExit (Ghcb, SVM_EXIT_RDTSC, 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; +} + /** Handle a #VC exception. @@ -1258,6 +1297,10 @@ VmgExitHandleVc ( ExitCode = Regs->ExceptionData; switch (ExitCode) { + case SVM_EXIT_RDTSC: + NaeExit = RdtscExit; + break; + case SVM_EXIT_CPUID: NaeExit = CpuidExit; break; -- 2.17.1