From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM04-SN1-obe.outbound.protection.outlook.com (NAM04-SN1-obe.outbound.protection.outlook.com [40.107.70.60]) by mx.groups.io with SMTP id smtpd.web10.58351.1595863759715864288 for ; Mon, 27 Jul 2020 08:29:19 -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=xVO3C5rv; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.70.60, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=D8tWU5OeWzvHoySFeZPMizmPi8vxUl9R8AuE0l2NxeocoXgOe5so9HxjXF4p7wGp0P03th1EY/nBZS789YOcfcGqx36qss3Zj4nACO+UQf+948rOreUTdCmJSwTp240mb1lmt02M138ePnG1DDYFGwN4ppw3Nr4N4bZMpejN+kIin6AmTIwN2H6U3APj4jWy1m6HfsMlPY6z9FIhT11DGvD8+eWFGBA6LwkTMD9WGtY+3P27tIHUn/lgq2j2bbI5f0fwfiqmOvj0zqUuBKIPUWHofic9WJ1sDOtFMnOT6uCgmNJkhkA36El0W/IylVhQVz9I+CCR4zirFn4V5ay1Nw== 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=FMlZ9tRZDTCBpYA5Jor+nAhYkmSbmabTGD6T6gfkJ85cvPQwwPOqsrUm1XM5W2V84yT7PZPMuh16Z6TDMTLbIjTAc87jV0SBIYkHKeycC9cnQVsLHjVvtMAkRJq3ERI5XglmeflE8NeVKSsjxu42sQ/R7csFaEB7y+XkKV5Eh/g/eL8A5IAiHcmeAJAMZdokB8dOf0lNQ5xYvBk5r5Wr4sR525NgRf5eKEtEKQPK7uexxiE6C3kWdCm9ZFq7/y74QXcc5701qRxpjthjixQC2nAzR/trR4RiZlKjdbg76hrrHBjFlxYWMg56GIpAGz7R/L3a8d5wYHa0Cii10EfXgw== 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=xVO3C5rvQq++6ugH6/F9kz1TaVAdlrgZI2cyZct2f1ewZKgxdNRyGs3+t6/Mlkq2jR2rxbLhWsQInO0dqjnbTSat3/jlAR1G/Cm0tfm3zyYzw66Q23sppNVwBQSDNhR2Yn3r2QJVLrY5y2fJyTz9xWDnEGmUAHLGoC73Npc9P1M= 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 DM5PR12MB1163.namprd12.prod.outlook.com (2603:10b6:3:7a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.25; Mon, 27 Jul 2020 15:29:18 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3216.031; Mon, 27 Jul 2020 15:29:18 +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 v12 20/46] OvmfPkg/VmgExitLib: Add support for RDPMC NAE events Date: Mon, 27 Jul 2020 10:26:01 -0500 Message-ID: <04cde18ab64041e4da9099c975c09ee1b87f7908.1595863587.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: DM6PR13CA0002.namprd13.prod.outlook.com (2603:10b6:5:bc::15) 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 DM6PR13CA0002.namprd13.prod.outlook.com (2603:10b6:5:bc::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.9 via Frontend Transport; Mon, 27 Jul 2020 15:29:17 +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: a69048e7-bc02-416c-04fa-08d83241d3ef X-MS-TrafficTypeDiagnostic: DM5PR12MB1163: 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: qtr5JsU9+epAK0o5svYmBBR0qPe41saHbFYXVU6sWbXHxzEMm8/tXS4t0R+VI6P+CiM1VZEc8xZjzMOtAD8CVAA6EUIuEqBIL/mdt/IocJ2mp/02GOC1ws/G6G59qnNhkhleHqHdGve/o5Tt5cWQ6DQeV9g8ngc0Os6k1HVPTeJOUliUcB4HYKkmVfiiRSJAXdO07IJOqAOyv2cfJiJe1pLwnSqBsIXXt4o75Ymw2gdQXY7rbxKMcpg8TAGc2m5tzzTDFDlqtafQYz7QGM5FZViN4rxTUhXrU91FVLx42kkE2fGYZcv9OkMd2UBIoZo7xSjN5XUcCZ4wHsvuPUCy9POas4K/fs1F6TXjhFLLtZJCD1vwjdbYVHCF0+rzKXQSrN62Ktk7G0zkhceQTaLXmTm/o/Qz8hoE+x/GFWgT9yOhdJWsn/MAdU0mNzxUbGlGgJ+NSsL+Fw9fgb9TAq1zCw== 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)(346002)(396003)(136003)(366004)(26005)(7696005)(16526019)(52116002)(186003)(66946007)(2616005)(66556008)(316002)(36756003)(956004)(966005)(5660300002)(66476007)(54906003)(6666004)(478600001)(2906002)(4326008)(6486002)(8676002)(8936002)(6916009)(83380400001)(86362001)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 3UKK1xW2U0LeemejFwMI/rFuRANZTWW+mbt4a7iHZTw8+dKv0eyo5yTuQvfF1lU4Y4pWYnhKtFaHZpwAiXkMpvufuBqFJvKwi8i0CvGc2pXjnkdQTRz/RZ8337WJCmqxh9EFPFxOWMNRZWNPhIAz9ZcVV/baQducsOCk4LrwCORK42SfKZOCw9cmZx7yWtWBHxu7HhQDo9pmrOngTMvoH+MheEy6anlTFkCli5VoMCzUOfW9nE0paCpw3BkD/8nukCZx7AMdbmLTrwmhEa9XUEPeBah7vlmQrg4JN+W9JNZDkhR1D3yQPh9vK0mYOkSKzm1yDS9yXlh4o7B0Pl7lC08H1Jseup5NkOGBL2/QVhsru4y0+6+aDJ6gyfEAsqErbiKp+Ltn9eNDOCQP9yWMLiNU3UBa6pqogJZjC7/DkyUAXnsMI/1UnBkI76Gh9avCW0Uy2Pc7TnaxwtVxAOZN0XwC7gWWqkb4Nr9Fks+6TN8= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a69048e7-bc02-416c-04fa-08d83241d3ef X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jul 2020 15:29:18.4214 (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: WfT9LqjsYKfLu1Ul/RQ+vDdnFLhM6gGYSl7eXTK5BfWx/FUkBIc+CQfMlWt+uhcG7+Rir/XBxK6ctZ0/z5HE4A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1163 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