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.81]) by mx.groups.io with SMTP id smtpd.web11.963.1589925111316428485 for ; Tue, 19 May 2020 14:51:51 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=IEkPzdN5; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.223.81, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iicR3W7brPQ68QnaNWwPa+nWCClFx3IM71f2+bk5uVnFnvbz48yIISksJaLdQ1gHPtDufYGd8j0CrM8EpPlHmmWp8I0W9WvKEB8hyJ7yBgtW3ChaYZi1TzHpCuIYnhznR+Muk/2RLUpSblKFWhFYCh9hFEWIxyG0RquyC5zd4lNyGsfXaNYd4XIrGQDwUNTzCXRBLE3TYr0/7Cn7BKabIPv/SQ/CSUEvOsrxTZAGZZOWK+4qM8s9BD54vD1QSFjEmpy73fjfdSOR/mB3ElIwebIhgILpUCv9NKJgvA+EIV6EAUeE6+668na5NTZBBBSLXOtkCft6h7WFUS7j3jEiHw== 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=/WlyPof15v7rTYJGsx9wr/NCRY8pwhrTZqKa/GL9i1w=; b=bm48Hq8p0QFZ+t4u43EC7rAU/8AD9nzY7szcYBH2ZeDI1qAkR5ttZoQAGDCWyhCq537OQLffF+fOnTFgC12HKjekNN8BYRuLO9IJn5CACXVAD5M5zPhMoGy5e7jpMfQVacJ37LYUJTR0Ka0IXLmK+sMhPmdGcM9om3GAuYy+3EcHCNKxgZyNIy7byZERqxC7fgs33LNIQo+4tsXqo1hLfZGFqp2QTED56/gCZeJUUz2uEuQLWMpYxY7NDBVm0iNwTBwmkhwh8tluNDM91R7rTWhyDLrLim633TbABA5aBjRZXSc2qLfH5kIp8dcM1Vi6WekpJXzurQcSb91nHHrDnw== 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=/WlyPof15v7rTYJGsx9wr/NCRY8pwhrTZqKa/GL9i1w=; b=IEkPzdN5ndGNhAevFlRF1FSpgQ6YLO7gSqfGE3mGUNTc2ohzpKILZahOmOJqVDoIKYw8eYVU829+OTcAAivT7JjQinP6dbBz8dIeOhIl0xK3GiSPVdOo5s9jppY4J0zWfehCUi0dp5/jv4P8Q6hcwzS3mA1izjhNUAq/2DWXiMI= 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:50 +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:50 +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 20/46] OvmfPkg/VmgExitLib: Add support for RDPMC NAE events Date: Tue, 19 May 2020 16:50:48 -0500 Message-Id: <3aeaebbc0ec807d8a953be4a74017e5073fa60be.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:49 +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: 7820f88e-ba42-4087-3aba-08d7fc3ed581 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: zCOqDfedimOH8t58tbKCMYzLJHrjzDc5dS3ZUil2ooXhgYSkgNwwApWA5aItN4vJBIKMvPh/qK14p2RApajE3GXrVYI72pO8GlIss0fygCRhhEgRBD2A7B40u3FOftrdj0IU+pzaycvyz2m8ggpNvJebRJoHhg6UfsNpLSZ31XGbhREqKB3GF5JQRXjarVTj53wTSRBOG7LYIwxn1+1yqAL9sD134BKHHGOSLgum1m5yn/ldVffLNqJ9/f9efMoX+9fJ0S241a/Xwci/TDl1G0etsbMfTBprq9sZilDUfJjyS/8I7IABJgH5Pn5A5oxNSd95oFGNHotETG6LTj1TuEzRADTV0g9vYFzuVzXIfrdTIdfCmwdOYI8rNHQVWKtd0n9TBttfgu93L+xQpAZD3xO72Lk0StLO3zi0UICqbfg3svrx3GpnzTmZ4akvVBPVHU0SlYahqa3rl8Zlrup3br5HPa63IE42ihO1xr4wnQbLx1gABnrRbkVUZErHhAUnHWbSkVkwRI4rHrpJBdkkJrPonRvB0naPI7/od6GTVrP8fer0QY2GhnhEmlIsoZ2nNo3brHkfbGP5vGkysBzlWQ== 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: 1t2cT2KBKNyYAlXX0sviqPrwJpyJZPcpZI1ub8LrrgakvqjZXNEnznC2Q1zaSrjsyC6CUZYxfMENvlwLbwhvIM6IoJWUBYHq0gENZVoNCHn38JrxxkjjTR/MO9nifX/qjED6hnQ68GE5sQAQYwmkjEiyIil1NjiIusCdQ6EKwnz7Ol791X/ZZ6Wkno4Mv4AWRDQ+T2mx1NUs4T4a86ViRJStyrWXl8vrQZMbCm+J9zKWUsWXKPkcc8n1AmSn2rn6DvU6f1Kzw+WJjVvjlyNCS8WvBucS/d1Yw1s2c7MG3gy8EVjoJ+j4wlSfZeRYfRM5tI0yfwJvWLlJ/3/0P5lXkymu1zYCV6a8Dosc8YvSw1QnZNte3tlnASZH7x9vXsZMSyuCoWVWkk7FT84GckELvGLU3OoURmt7iIRn2PI6elrnZHYa71HOrz6/TaDRR0IcL91APxyM6KkN0o5TIColucKvibz7ioKvm2C+4ERFTb0= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7820f88e-ba42-4087-3aba-08d7fc3ed581 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:49.9211 (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: Z6o1fQ8n58xhLKFeztQF9YIuu/GOm0dyk8TlwP48/BeRZ5U9iDoAU1aRxbRmaGo6H4rBG7xg2A/WsUHxshlf+w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198 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 Signed-off-by: Tom Lendacky --- .../Library/VmgExitLib/X64/VmgExitVcHandler.c | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c index 3d2a9c6f9bc9..d6b35b3019c3 100644 --- a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c @@ -1214,6 +1214,48 @@ CpuidExit ( return 0; } +/** + Handle a RDPMC event. + + Use the VMGEXIT instruction to handle a RDPMC 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 +RdpmcExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + Ghcb->SaveArea.Rcx = Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + + Status = VmgExit (Ghcb, SVM_EXIT_RDPMC, 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 RDTSC event. @@ -1301,6 +1343,10 @@ VmgExitHandleVc ( NaeExit = RdtscExit; break; + case SVM_EXIT_RDPMC: + NaeExit = RdpmcExit; + break; + case SVM_EXIT_CPUID: NaeExit = CpuidExit; break; -- 2.17.1