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.57]) by mx.groups.io with SMTP id smtpd.web11.21122.1594737170371274409 for ; Tue, 14 Jul 2020 07:32:50 -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=WWpdkNA8; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.93.57, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Vrdp5aowtOLu9vhE8pBl8c+DRz3s7UjLP+bhGvNxGSYtPrrb8aZlRJV5OYRl14r6LLPJewp0092i1hdYjmFqAHjJXb/4TzQ2hku0uG/yev4qwzYbIomeonEh1sdbmGF+Peq4YA42w09wo68BCO1jUceyrl2bckg99kOz3Vx0j54DXS+0iUAPONoToopr7IdrUgZoUwgTZQhvvLb/VU5LjA1bgEIt2Ims0bbMtZRJCnXg4hwu3Fb8TyaoIukr7RnVM8pF8OO3vlDCI7i87vehhW+2HUCxAI/FAyvJ+OGxg3Es9uuyJQmLu3Dpy5hRQMTC1gOySJSrIvrKKyku3pLDcw== 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=YDrRg1u/JTywx9134oK2vE9+CS2u6YIvUYIy+ZNn2o8qvCUvdYe6vF+SRSpo+aOxsWWPCs2m/8rm/kMDrlN8fYm7V+YXcpwYud+H/3y4xbJnCDLxlj0pwaoscHk70wMeE2y2j9dNwpiCPoJsqecaYHNdGNYQH3BDBBsOo/2MVPUI0T0MYA4VrqVNia5z+A4bVwoOk2Mx4+4PxRK3e0lnvj0K2ClYM7d0kS5wUvpfrAtR/tPWzw1HD1Ie+axNCHyho2jQTQbaiSe7R+69HYS2+VxlfhEMrLbRbfQiIQrcdpEsJDhlmdrDT7HqjMGUhebF7RyaDYJxizTiLGGihfqUYQ== 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=WWpdkNA869wY/f5w8V1E28OT3Kw/XCsRM7Ko6vbY57NqtJp2rLsCMYmbPCrqfFDW1kLl+J7FRyg105WmpAjD5QNVTFszkgZNJnunBrIC3l9JrD1+qdioRmTAiuQfXcOKUCipZ6prn4KTvf/ADkz+ErsSEM7QxnBvCzrN6xfQLKQ= 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 DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:32:49 +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.3174.026; Tue, 14 Jul 2020 14:32:49 +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 v10 20/46] OvmfPkg/VmgExitLib: Add support for RDPMC NAE events Date: Tue, 14 Jul 2020 09:27:51 -0500 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: DM5PR15CA0057.namprd15.prod.outlook.com (2603:10b6:3:ae::19) 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 DM5PR15CA0057.namprd15.prod.outlook.com (2603:10b6:3:ae::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22 via Frontend Transport; Tue, 14 Jul 2020 14:32:48 +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: be0414c9-435d-4835-2c4e-08d82802c82f X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: 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: SKqPM/tuRtTNFtZ0UiFFMDtyVoF/ElVHbqEo+ZAP9Aun4q2MB7wAkPMxBBqi2/Hy2DcM+xV8jU9A9A8Fb/fldHhatctt5Ia/DCwODoCLRdXO6HaZlCpkN67NFdnH9jQCoD3+W3ViM4yoQDlNgTVipB8StojI9kNQCEuwqtF57qe0qLmewJDvcN5/KTAcktSo1O4aaSzPhi8h5pI+PArW4ij9YK21XLEEMFknk3Uz73sOHlh+6pMvmWSZMzLrUoTSkN6KMAzkZ/jaKS7TXKiZ5PaV+S6nlgCRfumQdOuE+PG7T+rvhFIoNaoCRtymcLCcJKwsDA3WZamikai+MO7GLT2s7Ym5dRGQPGMhD9Q/87hB5oYF6++7SgVov3oe1lpx4qty4Mqz9aieqrmfL4xvOAUkOikE9eOaZjtZvdPNA2V++o8jQY1G8hN/TtzAMp3S1nYUsQNxx1RkmTHq7TXfoQ== 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)(396003)(39860400002)(136003)(346002)(366004)(376002)(86362001)(478600001)(8676002)(54906003)(6916009)(2906002)(8936002)(956004)(6486002)(2616005)(52116002)(966005)(7696005)(66946007)(4326008)(6666004)(66476007)(186003)(66556008)(16526019)(26005)(83380400001)(5660300002)(316002)(36756003)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: KAziSrDzfuPQrQvedYoJkDjx7eDM/QfTwm5cjqcDjwsrHyy4yS3esh7sZ9jZ3xQ7ThaNCyRZSvhUcvYIcQc9XABhL9kioWVoXwokTau0AIZjIAGI7pI3RMzVbOjFVXA4fY9PzZ1E+Bn7tevHfak6ztg1FVrhsT2ZglxBL/sDuvSZOkMGLiXdh75o2qOBovHMkMOovKT6GPh+X2/mZO8JeNY9P1s4S2ZE6b2iCvQPJ/MamU/oiL6Xd7EzmZMPgvll576ALP+bRxR0WWJLOppfo7x+sH5EFRU6b89WyCe6hfy3oAEgkpkSErzeCcxb6nsbs9X3Fz/JjrEMtPVPYCASf5MEuGxwqbZkJDEUZME3LEZtAbPMLoYeC/i3IDfxjwK52eqDAECEsy2MFVJD7US/SGCfiBRz7GrYNIwjgEP0/gHSoCtu3pnf3TFz5Q6JaAQjPhTc+e0PBDNg3ndQOHIowvXrQJ4DIQRemm9drO1qQys= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: be0414c9-435d-4835-2c4e-08d82802c82f X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:32:49.0773 (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: RBZJ2ej5NevAOC9GKUu0stSiOWqKqkkSOEgZ7seKj3M+xWTcJe+4eQMj545wx78ZnjFpmNVYq8N608+MBYWcuw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 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