From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (NAM11-BN8-obe.outbound.protection.outlook.com [40.107.236.72]) by mx.groups.io with SMTP id smtpd.web11.21114.1594737158438570483 for ; Tue, 14 Jul 2020 07:32:38 -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=zLUAvDkS; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.236.72, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mGZS0gk0L7kQ/z3Eo5YfLiAYbIQUQKoWS6P3nB6f88bb11gg5J5R/yNpwNl09hTm5qwm7Ak1/KLvFtiPztR0HiIpj1goSM2rh+X30dgjQPjVswf08FbdOZ1ZWKIez9sj6oHcN0BNsuBHWvGJmv2vaT3k5ZteY07QvSqv+Q4bCKLAOGdTuW23Hp7rNjHacz2X2BTpvp6QR1+Li2HfcmK4SnCGeXAOqtG+zQj0Q1b4+U7HW1/LF3+WjlY1c8Z0GiHk0KURrSh7HpWi16ktU1bS5GkwbkppWtCxRRB/ltnrGx8ssHzljesT7CuVwDJnt1HsbjbrNl6EBJKp2+XojGMcig== 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=d00K2p9wGq3eOi/6hoKeg0U80JcDhc9VJVDfMfmKMog=; b=AyfSvExDBut3kwLvFUjhgUfL0CeFVsTH89f/XvmpZnGH6bQ1cxXoNkNa/wdsVbRZ7poNqQkveI45jUXDjLFDmsY3+hFykwCoyayV3E2rqSn5YYtqStJEEQgkT9U2wiTPuqSmne7ZQkcEjEy6IwDoHgC3YOiwA11WqoNB5sdsI3aNpmsk9OK3oQ/cL8zhuSMBRVN6OnkkcAma5m6ImM2vtxXmcnMT6Tar1/4zgPXJCBSzGc8x6g5YcfO3Xd6dWeOBdY64jIcpVteeoMwg/X/16YN3PHJ/PAAFY3M20P+nEtdeRRtfnTqG0nR8vmi/l17fvrMShtf3jA40jfb16R9YNQ== 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=d00K2p9wGq3eOi/6hoKeg0U80JcDhc9VJVDfMfmKMog=; b=zLUAvDkSNIZpBvSVtgZ+rUB4DjEHxZSh7E4mjsOfbgmjd/+K0oL1VgRMMYdkRoRiuWI9tVm1mlz+ZrjPKmaELKXdn5wAQAtjSiooPb8tr5sfDl/D3lAIZGxSqpRpF5qLQRFynU6QVaV76zZm5li9FhcxIHseMgOdPMbRnA+BAqk= 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:37 +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:37 +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 19/46] OvmfPkg/VmgExitLib: Add support for RDTSC NAE events Date: Tue, 14 Jul 2020 09:27:50 -0500 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: DM5PR07CA0104.namprd07.prod.outlook.com (2603:10b6:4:ae::33) 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 DM5PR07CA0104.namprd07.prod.outlook.com (2603:10b6:4:ae::33) 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:36 +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: 558cd2f9-3554-45c4-afff-08d82802c0f7 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: LnQyDhjiz2KLzJxja7cCO201qdfGS7VOdjdFAyNoHnMW9gwGixMEMAd5g9aeHtzMzDyQbKze2l1q6FEvHwqypKiXp/mfJ8Fvsf1OiHdi1rS4vOB7H7myup6A33SIxOaq0vYXXWLMDOGsem7w5KhLmHuWd6reeFt59d2SUzlZNpoS1wVfyOciiZ62DIcIxUOMwn/BV2n0+UmQyVowt8140xpjcq3hTNYyErjegks3VZfjcUnjxwuiI3cJCW2cipQ3JDXRkcUnvH2mx47hjrgBQOhtlbp1SclMbxkF7QsrxAJjHEigZXpSHI8TFXh2BLDNgZEgV4scB+auWJahLn+BNu58Rurfm6PJMMe6u1iiblokPJ7rg+qId9FZiYlqn5TogPEAgm+BdBEx4d8mMd7gjVqZvUaUD+Ybr2bLLv5gGaDFgNJWtUoofvSLMJt62H5pvW4OAdhAXUkIHK1/s36zdA== 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: OdoAt7XnhRCSydP0Ij+UUF/I8glntMjZrpNzqA3e3f9VTVfEoFEyXvMf2j6R57zYhINtcWdqDY7fztA1G4BkmX+ZwXUH22/B2E9L0jzRy7/Tpluliz/wyXvntTeCJsDJPkiMFQPA2PKAW3sZe4ca9TWG0kSDXxRRzpBXb09rYdXZEmoMAMgl/JbTWKFBVl/wZTnH+x9IAyL1UWFz5cXxpk8Y4py4C2Oh9mYLjs5JebrK4KsaOBjEwe7gNDJ9+7jCgyqz2P/kI0gZPZW854JLxpYfIbrGWS4Ln1WpWqag8fcZMG4QVnqRXrZ6C4BlZCUqhLNJbJdzHVxaYWTlUp0sPMeHpA29N+6s+SMElHw18JkelkL+lDxmzdDai7uMLevq+oUX+M2qK3Zj9P7j04Wk8PhFTRMckx7d/05tZP72241oS6MgGInaBJmdHtgfLBJWbOfh8KjX/ogbd4oATto8G1iIYsC6gRPNaSwvZvk4njo= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 558cd2f9-3554-45c4-afff-08d82802c0f7 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:36.9007 (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: PNFFMt/c+/vzYFNhzYNmo2hkJLRXutw7FOHl5SMyBinl214nent8sdOVxM5q9n6UGfZtk5FFsUWwTfKcxR8C7g== 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 RDTSC 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 | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index bf07f960e380..65af57046063 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -1221,6 +1221,45 @@ CpuidExit ( return 0; } =20 +/** + Handle a RDTSC event. + + Use the VMGEXIT instruction to handle a RDTSC 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 +RdtscExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + Status =3D VmgExit (Ghcb, SVM_EXIT_RDTSC, 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 #VC exception. =20 @@ -1265,6 +1304,10 @@ VmgExitHandleVc ( =20 ExitCode =3D Regs->ExceptionData; switch (ExitCode) { + case SVM_EXIT_RDTSC: + NaeExit =3D RdtscExit; + break; + case SVM_EXIT_CPUID: NaeExit =3D CpuidExit; break; --=20 2.27.0