From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.64]) by mx.groups.io with SMTP id smtpd.web12.5620.1595366549074569970 for ; Tue, 21 Jul 2020 14:22:29 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=XYfs5Gb0; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.223.64, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V27nMOVMbkGOjGTqZaTTpu0HkmwWRBUsY1Ziy3UI7BpKs0IVZcq4K+3kLKlZUB0LrULzvIaj1j3I0oFyu2k7lSE3fYP4FCdhOTlqf8rbrjZVS536ZXyqELj8lI8qYSLN6T59PBmXfjnuENGWhUTY//Gd6ELAsjKk90dcvStBxdUXQ9rnK/4QEwyyDOqA7GgoHxkkKWe5IMlENm2lhkUTTus73omsa8A2trdMPxzCjhuECPvoDG2HF0phIU9ndyBeD7lCf3IPs6dutsGnUuW0f7dRCo0l85uSA5mXjxFqLl0XOpc2bsEQjifj2w6h91S++nhXpDe2SUXOmYPRe4XHHA== 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=4O6+S0hN1CMnpBWLQIazWEUnN+r5+tUBAtS8g+NsqAw=; b=GHH4ApU2U11x/7TjVijLtoS+TY12u6H6L/qRK68XIDgPdyHIAYAsHra/STvqtWLUxa2ub2cYnx1AodC92zEDoYZWtgiSPAWTHInLnGMgWSgML0wfdEdMmN3OcJu1cNioOUY6sxD3CT+9eme7num1u/GllUuV+H0g2utjGN2ruMlkMpRmbojBMrGYZUkkVh8qPqpzPOZcT6xiDkdqorjADOwTva394cg9swhCBD8vO+IFZOkoP4RjECh/Z4OBtWUCFuA3hXnuaL4F0Alo6q7ggT6NUnuWsMqrFefT8boDg8Wm/j9o6CbCZDUzN2CEAPjbqpqzzFQ4094bs6uwpHM7JQ== 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=4O6+S0hN1CMnpBWLQIazWEUnN+r5+tUBAtS8g+NsqAw=; b=XYfs5Gb0BpVIWDi7CtEeG+hT418TSaK8v4vGQDvHB/43cxgJybXxmFOkvZ35tACqgaaIMtnPSMiY+fYX4dRPrjn5+a5jG73mhbl9jeFYtawQEHxRbWIqijBYKiljgKWKBc1L4Uk/nCl7r4h7xejmKniCl9tQhzFP41kDfqfsDI0= 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 CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) by CY4PR12MB1606.namprd12.prod.outlook.com (2603:10b6:910:10::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.23; Tue, 21 Jul 2020 21:22:26 +0000 Received: from CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b]) by CY4PR12MB1352.namprd12.prod.outlook.com ([fe80::9181:78bf:bf0:702b%5]) with mapi id 15.20.3216.020; Tue, 21 Jul 2020 21:22:26 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [PATCH v11 20/46] OvmfPkg/VmgExitLib: Add support for RDPMC NAE events Date: Tue, 21 Jul 2020 16:18:57 -0500 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: DM6PR03CA0064.namprd03.prod.outlook.com (2603:10b6:5:100::41) To CY4PR12MB1352.namprd12.prod.outlook.com (2603:10b6:903:3a::13) 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 DM6PR03CA0064.namprd03.prod.outlook.com (2603:10b6:5:100::41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.21 via Frontend Transport; Tue, 21 Jul 2020 21:22:25 +0000 X-Mailer: git-send-email 2.27.0 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 7ada56eb-24e2-47e6-8a2c-08d82dbc2aa1 X-MS-TrafficTypeDiagnostic: CY4PR12MB1606: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5bN0SUC7+BShU0bDiRRnpK8Cx9DzGOdZsUpBiwTV0ZqLJp8mTCffJaEN7RO2qE7MRJd3SDNlVbY1899Z/TUuRjGk98ESP+DC73bcYzcLhJKS5QtOQWbYTv+JUpj96dkUIFE5bV769YdEJISOAvgWX18wFm81seEPIcEIubBgLLFCCOKF7SCfszln6DHjnnRhGTtKscG6Uoh7X7HPERavAkGqGnqAVSozOgKcp4CYtwbsezJA7PHA6vyWC0aM36Lvg/qbUqUpwYfAXDTs8w8hobRtnFvY7NRpt3yM+acBm9/akGXYoZKkXlCu/zhBxErXD5ZxpuP3fZ70/HggkYLoDqvHBlDGFHZNAd8QaVhAOR28xKuq/ZR0in07y40X7HFP9xxt5V1tJnxvESc7ZTIvDGHP9OflWiE6sPbmrX5VhElbvnijppX/mKw9SCEA+K2n0jshGyghzu/0snhGJcrsiw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY4PR12MB1352.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(136003)(39860400002)(346002)(396003)(366004)(376002)(6916009)(54906003)(2616005)(956004)(316002)(6666004)(26005)(4326008)(186003)(66476007)(36756003)(16526019)(66556008)(66946007)(2906002)(6486002)(8676002)(52116002)(83380400001)(966005)(5660300002)(478600001)(86362001)(8936002)(7696005)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: BgQDXRTQGEAaFRv2w0M5jCb65W7qB+bzGR8NFDqG/Ci/5hR9pFP/8N4h3Du7jdRlxE3loBBaXUcVjVLi1dCyZyGmlAves8hvOqEOn0u8uSEPFwZmARfuBDiuWq7ShvYhwRG45uO1eo9MJIIYXceocNsGaM15STU/G2fjR3vO8xmDmO8TFAo6YEBUzyu8OGNyBFoNV92rscNcgDhBlTXbFiWSUscqqRiu7bIFxTZhJWPfBmUhcfoKqUp+AaOrZYfBfTdeeOyDtE8PDA9kb8BBo9VwXNbQAJ3mK9xNoEzX5AQM1ZqDQPjTx+mEza0Vi4iULeEUCJGa6KqOM3UpKvQ0WL23nUtLubaDHqfL6TqrEYmoj51EYjpoptyOcBT5WsPUWc1Wx0eXESPNVO0UL+JANo4FjAIfiNmTUGIEnFLHqamN+7Gk1v0iUeCebDHSZUGGmF98LU+LsFnASHGottHC1WHZmg7KTGEMv/dQUhWfYaQ= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7ada56eb-24e2-47e6-8a2c-08d82dbc2aa1 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Jul 2020 21:22:26.7485 (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: p1kMMWrEP7EBckTPYUc09rGF3C1Ef8inH6bkH/+LE0QvQ9SyRdu4xKH0Rdr6Gi0KRKrC4sHlPkTU3NQqjFYCLA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1606 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a RDPMC 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 Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index 65af57046063..b19bd3ee8906 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -1221,6 +1221,48 @@ CpuidExit ( return 0; } =20 +/** + Handle a RDPMC event. + + Use the VMGEXIT instruction to handle a RDPMC event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return New exception value to propagate + +**/ +STATIC +UINT64 +RdpmcExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + Ghcb->SaveArea.Rcx =3D Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + + Status =3D VmgExit (Ghcb, SVM_EXIT_RDPMC, 0, 0); + if (Status !=3D 0) { + return Status; + } + + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; + Regs->Rdx =3D Ghcb->SaveArea.Rdx; + + return 0; +} + /** Handle a RDTSC event. =20 @@ -1308,6 +1350,10 @@ VmgExitHandleVc ( NaeExit =3D RdtscExit; break; =20 + case SVM_EXIT_RDPMC: + NaeExit =3D RdpmcExit; + break; + case SVM_EXIT_CPUID: NaeExit =3D CpuidExit; break; --=20 2.27.0