From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.60]) by mx.groups.io with SMTP id smtpd.web11.4250.1596829347827318178 for ; Fri, 07 Aug 2020 12:42:27 -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=Zd6zUtyH; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.94.60, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Oil223olcoPXFf3bEWEzf1qM26CZvSJev5ehUfMEYOHzWfPkrfAg4Cn2AmEJ9ZY+ysjhRgodtXy1/s1otqxGCkSdRFdHoTrB/bHGWeC9DvpN/2jLcGNhWN2guASNHa0A6QVNjiXPf8l1pZnmMY/AV9MeDPHWc2g4See8gUm+PIoKnh/xKndjeqnmwzmxziFa7E044/0aDQLo5HS3RyBeBoOgKbEtpNOc/CDXPsBE3eJOiqY08dPl+U/J1ZEDGHgDgmXO/vWNMp8RR5t8rJbjTm43VVde6UicjzYc20JvkaOxCBP/ONFNjIA8RLgTjLpG41Ld2/s2qFvQqyCff/YGBA== 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=Cwy8ZPrcwpqMgBUqXKJ9IPvcZyHcW8VLL2/Hb4z2qC9/M1MwCXcHSNAVPyTTRbqyPtft3IjFaSyVtjEGt+1rww6vNWI9tEFxxR0kMrH3kZOgmlYzBnmXyygGKbBLNvwLB3PZM/kaVfrrEzh0f5PdN+sCShO1J8782zJNOluKZ01CXWRN4gdtohbTJDd6GEOwwmEM2kj9ey/1FR9W44ynekrmUx/dFJ+4ZTSIKfU8PgKbEjtensUlLyo8miHp0yyCqzs1pTjCwleyGnxgCneWC9W0xSTb5zVjst6miY31NffA+xoE9uYyMNLw3LgS7OSRVMsCXUzL8yhcn9N594IK0g== 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=Zd6zUtyHWhN3jHO5BTU8g7SBo9NnwBECitXXM7nRp7SKcpRf0uRfxj5Efou7Zna7CDFmZOQ42/HVELXf1qjeFIA3AYA/94AwhSw8kXYlitWe4C45yJcXjQeAhzqT9myVRnt/sRSYkchVV2V6124O1a70tpbAI1r0DokdQ+C9ev4= 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 CY4PR12MB1798.namprd12.prod.outlook.com (2603:10b6:903:11a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.19; Fri, 7 Aug 2020 19:42: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.3239.024; Fri, 7 Aug 2020 19:42: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 v14 20/46] OvmfPkg/VmgExitLib: Add support for RDPMC NAE events Date: Fri, 7 Aug 2020 14:39:05 -0500 Message-ID: <69cb6f8349d4a4dafa791b73d5b24c43c15507b3.1596829170.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: DM5PR07CA0090.namprd07.prod.outlook.com (2603:10b6:4:ae::19) 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 DM5PR07CA0090.namprd07.prod.outlook.com (2603:10b6:4:ae::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3261.15 via Frontend Transport; Fri, 7 Aug 2020 19:42: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: 10ce0a97-f71e-4b33-f0e0-08d83b0a0311 X-MS-TrafficTypeDiagnostic: CY4PR12MB1798: 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: oBS/kuzFTnYvaAD4aGvJ8Fh9Fb330M9WoAIfcQCqoYH+cyjsNcQBhNERUnAf8NNWmhYsUXCOmtiK47f2wIcqwJ1OYLgo3HQJ6j7vVjlA+8oJIG23XbxG9qu7dIjbfwbPD29WqQODm3Qf3C5DPnr2Wv+81xmK4v9h3Yrzf1CZhuMhza+n84j9mRbM2H2ihwnsYZ5quYCqYivNfQ/YKBcp7vwAJjBxp6+0E2IipEDpjWU/0i/IuE6f9wNzqZtLJNW7npNylBCWfww5EoY74aBtnHryrNVIoI/WdO4Y/CeUgRJQggAOq1x08byFz18rnYyr5UoaJMOJNmWnX1Pws62wMwA+2dpfosIyYlub9Hp/16Pdwhn2wPHoiLG/uwYKk9Ffxrw2UQxIPs5vhlYP+QWcpvCSOm6WyaBnmmZVLBU7s3wC7CTrnstqDawsefPmJw8SNGFeULRlBNbhX+yv74R6Hw== 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)(376002)(136003)(366004)(39860400002)(346002)(396003)(4326008)(66946007)(6486002)(2906002)(66556008)(66476007)(5660300002)(966005)(478600001)(8676002)(7696005)(26005)(8936002)(16526019)(186003)(86362001)(956004)(6916009)(36756003)(2616005)(6666004)(52116002)(316002)(54906003)(83380400001)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: ni7lZ8bAT15AfyRsvHHGsbU/Fntkc4ReBBKnjmAnJgBZHh7SkDbyJRT5h2tn/PAwLphf+zBh3jcB3iBX5LYGvWYHhH89oYj1hcfXkjhB1Tln//9PByeiaAZ3mVrMXAYn6rI50T8ARgs82kgxRLUqKHO+8BcMqb3qiRWZmRKD9J/L7EDqWejf6+u5HckPtPL48IYjR8l2Y4iMYkofjEV7WBSIiwrt0bSu/hw9mO+AYv0RfZXhJQ3JGCSTJMwkzEQWEVWT0MzxlXLmYJdfo+J24ff7vajYqCO58LPo6X9Q6YiAYflUDyiyYXpEbfVOCqVOq/AcicOedhyXLlALZR8dA848gsVrMNwVHbzZnB/aB0ZodLzRYQu9n7Jw8U+RHU1CSd6wSCmzfUCRBZYcbAkNfyftdobtdgmpfP9erp6jug2h2wcb9Bn2IvCzdVWDQA+Nmxd1cwci7I2X4hx6yOKs7FZIZqtHI5qU6/ovBkysCi8QYS0psxngEEC9KgUULBqxNwT0B2RLA9G12SCyfi9dx8nqvhgzJ99NffzrKjuhes1VLjP8NCNtHnvOp5/uJ+GXbh3Fv2PqglQSth+fazJMFwOX+L6TIfHXXIXUmkMdl0pNPT7sjxv1AuhOBSm9RAY1phpPOtr2ZN70PzA9NC36UA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 10ce0a97-f71e-4b33-f0e0-08d83b0a0311 X-MS-Exchange-CrossTenant-AuthSource: CY4PR12MB1352.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2020 19:42:26.2483 (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: aM/+xYU9Z7SORrSGszUvxUp1pIbSW/AL0yxgIUpQYNGbTXW8XdFUF7+6o9PaFKNUUNVXvtBHOaJQ3j3HdB6mxQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1798 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