From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.89]) by mx.groups.io with SMTP id smtpd.web12.10853.1591363693067214833 for ; Fri, 05 Jun 2020 06:28:13 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=e7y//sgF; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.243.89, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=huwwfx0j7gq7Qbzi23EkChnNrLWZsLvwABz9KL42iyxULM2FNJOd+auaWqR6RFx3uQPKpuN1rfVyqEXjP9r2wen0zw+mE/brnnWPmzBrBBmYe9SQHdCw+vEnVZWScrtTK+YepzCr++ml75ulq3JQf2HPu2pb+iXHudL/AxiKYk2dWGiPWDJVDVpkO65SpKGwWP8FMSs37mrygULVQOaJ0nJBbujpncFyWYaqyPeTM1mjDPut52njMXXvxb1rV/04pg7BnGrzt6sIAIuOkVBkGj1YCiBkHT4Y2aALeGsecxacPE7pFvvcXXhv9EQ/3xiV8S4uMwityhfQCuF31dh5HQ== 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=jOkS6c1zFaPDJ6Gi0BcSF+mx+mmU1+fc9VAJ96eBuYs=; b=gC9rU23nVv4G749M29wue+1pDKj7iog3KaNSjC1PXZdzSMTmW4V2+d4EVP/zulNXQ909NYZTVd3Sqh3v5/Cgzl/1yIrBuDAXMlsNcc6C6SuBxXwy7FiqDYCMA/7VQHivN50s1Y+5Z8LbaHIBfFpxH0LX4PXPcn5hV/5uCbVTObUapZo7NpO6qfqleIH720Ge98W9WZuLQI6mCADhq4UBjWYa9amP8ryGnI+B3Sm7mNUVqkU+sAGn0inBeHzWTqAr6Jdv5K5vOem0afZjrJHh9WPd6B3hCQOsh+EivIeY/WVou/4v2KHAsLS7QkIYMtWdhRjcEJ614ZTDU4AIVjRPNA== 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=jOkS6c1zFaPDJ6Gi0BcSF+mx+mmU1+fc9VAJ96eBuYs=; b=e7y//sgF6Sxz6gOjU1/ecZDn6JS6itMrO63E6pxni9qP0dNKxPeOvG3bxrf5Q13bCzE6ozvRLDW3eST7Q1QE/LZl1kZYHUfIg3mzDiF8FdoMsOG37/dkT8+9XgdliAy/ZHyPoUvWbUns6FI/R0Lu45hqwI9Oa9yIh9YmJBX3JmE= 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 DM5PR12MB1354.namprd12.prod.outlook.com (2603:10b6:3:7a::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.20; Fri, 5 Jun 2020 13:28:11 +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.3066.019; Fri, 5 Jun 2020 13:28:11 +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 v9 23/46] OvmfPkg/VmgExitLib: Add support for RDTSCP NAE events Date: Fri, 5 Jun 2020 08:27:14 -0500 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: DM5PR19CA0060.namprd19.prod.outlook.com (2603:10b6:3:116::22) 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 DM5PR19CA0060.namprd19.prod.outlook.com (2603:10b6:3:116::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.18 via Frontend Transport; Fri, 5 Jun 2020 13:28:11 +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: be8fe9d4-072f-4ec0-124c-08d809544b17 X-MS-TrafficTypeDiagnostic: DM5PR12MB1354: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-Forefront-PRVS: 0425A67DEF X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: V45WCvV/4mBfOOxIW3qvqfcMSokW8XGbGKHJR87P095FrpQNzSI6GCEuA7gHAniKTmd+f3Am0ab7FdsFrf2p/GJ8M7uGQqCBDTpO9eTiuOT4oiwgb5Pe5/u0pbZPblnav7JrskIc+/3ifmD775+iqwDVpHbGa2X4egfu7qnDpGkKU/A3D4USDGgkm3RJMC2mOJmQzUbWmky0Bni1UmqlTTipYqyhkSPM6uB+qgmIJvZKXtqZQZxdbKBNduL9SzAVazFyXLhTdG6wUFTzl22JyW5iwHe4ZigId5alW+NKo5zYrJX1ue1cFNXFA/YJr9ZcULG8gDfSpZVIiIZsEFVGqug35sJf1Fac+0g6UoTJf4j9Ba8dTFVg4GupgWQ7VNF8X9JXzMhmH6AGSv969XiM4zVwGKZK+gx2KY4w6ETcw15YBRFEOea0ouBJI7SBn+37kVUy29aN7txQoJuwQRAsGQ== 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)(346002)(39860400002)(376002)(366004)(396003)(136003)(52116002)(83380400001)(26005)(316002)(7696005)(54906003)(6486002)(478600001)(956004)(16526019)(86362001)(4326008)(36756003)(2616005)(966005)(6916009)(2906002)(8936002)(5660300002)(8676002)(66476007)(66946007)(66556008)(186003)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: GwiqkVKbx2Z1jbO++pS2ahTkIRhqE16UPEob2CgQLEpmofPBC1qO3si0TEuXEUPKTrs6gOcb9NRMvAp18QI6mxFvvW62H3plL6GMHyjcLsI5Xzo0aWBdZHHc4RLtEQLVaCkrNtJUwFXdDLCiU7SH6+FF4XEbLZxc7JYjbUq01mqed4QRWrk4UMuO6gEAqI1Gs77ydRkfvQQnLxkatiI7zsWJUO0KU3ywoEgccvY+Sql385UkMpFrLT8tXPRqzBg62QvMEynxQbyiH/ghRbye3ja0J69ABPdRDRlIZiyyf7u1lPGDTD2dAh/56IHTrM42FyQ4nlmnW/oteiLWfoQMbThEj/xQTB79AcOLXdzSke73fnmOo9wk+eAi1vdbCckV9uHThXbL/4PcZrSvHXjQHokbNYmWSQw+KRNaIQUZ8W37seGIC3L6VxzBo3NHKhG4h8bcX+SiS8QMzJqWSJ3FPj/MTlymmDZ/d/5In4bRh0M= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: be8fe9d4-072f-4ec0-124c-08d809544b17 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jun 2020 13:28:11.6640 (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: 6yrO2lRl6/USs/8HK7blZuZ7x9U/7zZglZZJx3QDSEqHR0mUWg5fzVq126vtWjx0pfmX6An0bCSUgJSOjdpdYQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1354 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a RDTSCP 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 | 47 ++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index b77821d2f989..8c2b34c4a83b 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -879,6 +879,49 @@ WbinvdExit ( return VmgExit (Ghcb, SVM_EXIT_WBINVD, 0, 0);=0D }=0D =0D +/**=0D + Handle a RDTSCP event.=0D +=0D + Use the VMGEXIT instruction to handle a RDTSCP event.=0D +=0D + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation=0D + Block=0D + @param[in, out] Regs x64 processor context=0D + @param[in] InstructionData Instruction parsing context=0D +=0D + @return 0 Event handled successfully=0D + @return Others New exception value to propagate=0D +=0D +**/=0D +STATIC=0D +UINT64=0D +RdtscpExit (=0D + IN OUT GHCB *Ghcb,=0D + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs,=0D + IN SEV_ES_INSTRUCTION_DATA *InstructionData=0D + )=0D +{=0D + UINT64 Status;=0D +=0D + DecodeModRm (Regs, InstructionData);=0D +=0D + Status =3D VmgExit (Ghcb, SVM_EXIT_RDTSCP, 0, 0);=0D + if (Status !=3D 0) {=0D + return Status;=0D + }=0D +=0D + if (!GhcbIsRegValid (Ghcb, GhcbRax) ||=0D + !GhcbIsRegValid (Ghcb, GhcbRcx) ||=0D + !GhcbIsRegValid (Ghcb, GhcbRdx)) {=0D + return UnsupportedExit (Ghcb, Regs, InstructionData);=0D + }=0D + Regs->Rax =3D Ghcb->SaveArea.Rax;=0D + Regs->Rcx =3D Ghcb->SaveArea.Rcx;=0D + Regs->Rdx =3D Ghcb->SaveArea.Rdx;=0D +=0D + return 0;=0D +}=0D +=0D /**=0D Handle a VMMCALL event.=0D =0D @@ -1441,6 +1484,10 @@ VmgExitHandleVc ( NaeExit =3D VmmCallExit;=0D break;=0D =0D + case SVM_EXIT_RDTSCP:=0D + NaeExit =3D RdtscpExit;=0D + break;=0D +=0D case SVM_EXIT_WBINVD:=0D NaeExit =3D WbinvdExit;=0D break;=0D --=20 2.27.0