From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (NAM02-CY1-obe.outbound.protection.outlook.com [40.107.76.79]) by mx.groups.io with SMTP id smtpd.web10.13520.1574280457902726683 for ; Wed, 20 Nov 2019 12:07:38 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=XgAN4Vx9; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.76.79, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I5CsAVftxtjYrh7O543BM8K+6ZprnVRbSK4CAYb0GCMYGWWej5Nxk8HxHBE+Sdd6D/UfPCUXdSLPWemNUvV4hO/ys+sjCDNiG/375xSCNMx9nBIyB/UAAKRXRPuvUpv/AgJ7VKzkQLQNZG4k5OGONz+K5XIU7AHQ25UmcWsjh9W4U4Lo4EZjZcGA2QoAD8iwNb3snSkYP1en8mQu+KmKLxMn6554r7I2HEOPt/VWkpzy39Y7BVywBLCu+C4o8INAd3kF6q7rSTDGut/jJ+s8Uq9N7AkKHHhPYWP/cApMViysfAaxxl37iRFZX+AJS44KHpba4hNoMsaYbpbFmuGPEg== 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=H4K8WY9JN4bjr3OMt5G/+0P7tFxl0DkR6T1Im7FTGkw=; b=FQVrKavIdxFN7rE7Z54/xj0sDNdigQ4CzWC4nTBiU90WqUELjWVE/RKQzhFua3uGP43ZHQuSqmFkJfDmt58z+zVZ7X2/IGa0voge+Pvl47EIGUFLToHzWKh8zSe6yZ9SzCK/ZH70wqZ5zcdXzoFranpPjFHJJAx8Dp6cy6crVODJJHzzMSI/zeYmDekz+JhuzgXAt1m2PI3H1HWnAOL4iVbJqB1X29QYgviQVw6dTsb5IGCZH/Dvt+qMuPRdbEfvx3NbsuNCA1BvapC/ZpJkDL1as8e1Pj6TXbtu5RDzG72I9OtBW3HYgU0Brb9i4F1dnw53MowJqFa9PGJl0pDRcA== 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=H4K8WY9JN4bjr3OMt5G/+0P7tFxl0DkR6T1Im7FTGkw=; b=XgAN4Vx9SjgoL3hQ0YhtksAfgsne3hhAQQcF3lleERAeoxUK3NKQC4EXTuk5qk83T9Q7ZUhJ4EyPmKAEYrzNRx6YprSJKx4GN/HS+xBvaxFYWsJ276phm9z5/uYKWeXhmTbZlEoKnIyV9407Sa/uw76ohwd5ZOEzXQ6P7UMtF4w= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; Received: from DM6PR12MB3163.namprd12.prod.outlook.com (20.179.71.154) by DM6PR12MB3675.namprd12.prod.outlook.com (10.255.76.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2451.28; Wed, 20 Nov 2019 20:07:36 +0000 Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::dd0c:8e53:4913:8ef4]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::dd0c:8e53:4913:8ef4%5]) with mapi id 15.20.2451.031; Wed, 20 Nov 2019 20:07:36 +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 Subject: [RFC PATCH v3 19/43] UefiCpuPkg/CpuExceptionHandler: Add support for RDTSCP NAE events Date: Wed, 20 Nov 2019 14:06:41 -0600 Message-Id: <1de417001be9576644a926c19f6d33221701a7ac.1574280425.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM3PR12CA0087.namprd12.prod.outlook.com (2603:10b6:0:57::31) To DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) Return-Path: thomas.lendacky@amd.com MIME-Version: 1.0 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: dde64fe4-d7bc-4b61-76ef-08d76df5494b X-MS-TrafficTypeDiagnostic: DM6PR12MB3675: X-MS-Exchange-PUrlCount: 1 X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2000; X-Forefront-PRVS: 02272225C5 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(1496009)(4636009)(376002)(346002)(396003)(39860400002)(366004)(136003)(189003)(199004)(2361001)(50226002)(81156014)(81166006)(8676002)(2906002)(6486002)(99286004)(66476007)(486006)(47776003)(66556008)(25786009)(2616005)(476003)(54906003)(11346002)(118296001)(8936002)(316002)(2351001)(7736002)(305945005)(66066001)(6916009)(86362001)(16586007)(3846002)(6116002)(48376002)(14454004)(478600001)(966005)(5660300002)(66946007)(446003)(76176011)(36756003)(51416003)(6506007)(386003)(50466002)(52116002)(4326008)(6436002)(6666004)(6306002)(6512007)(19627235002)(26005)(186003);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR12MB3675;H:DM6PR12MB3163.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: h3i0O4lDlmrcgL5q2kwivPEQSCaN77gkEU/8ybuAay/UPyAk7/jyABnu/PbhIECZU/bIvWmNYHI7ECiya0YFzeyl0fM/1i093d1na6SxK/aCgFqBNin1vpwISsLaGfq8136AVwu6DORv9eL/PuvL89wW/SrYgs0XnthPgtvLMh26iPM5KMIiGr7cyTxKkUhSuwTFnVaIbjQa4O7NOrlQ0wfhlCwAEeNrd6NnqzcJ6PrkIvWb7XOfgVbu4OjyEkZMdtxs9L8nsvJK3tsrAhVtDBurO143g5Ch055XDOeM1DO6nhrIAS+IR9LBPwcO9igjb0Y1OThU2Dl00+sDikwYT2ejb95dHXwjpQ8Z5rxVXq1AVNF3zuqwmr++C4J+w0s3qjaQ/iVq+OiA1IFDH5lAVVrh0Np3bm7szKY1fK3Nx7t5k6MPvA8Luh08sYec5W9wRNbVE2dcKp8vT2uAMAblHtBOrisGQsSgCNIQqtBp2xw= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: dde64fe4-d7bc-4b61-76ef-08d76df5494b X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Nov 2019 20:07:36.5299 (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: f10i/w4IY3eBy1cZwRTq0S5bF/bYAwL0aqtMDBpc3ftXRs6u44fDtLq6RNsmdHEqK/o6iMyCHt//KP7XtrEbTQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3675 Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198 Under SEV-ES, a RDTSCP intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Signed-off-by: Tom Lendacky --- .../X64/AMDSevVcCommon.c | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c index 8b0192bf0a0e..425b1c533532 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c @@ -603,6 +603,36 @@ WbinvdExit ( return 0; } +STATIC +UINTN +RdtscpExit ( + GHCB *Ghcb, + EFI_SYSTEM_CONTEXT_X64 *Regs, + SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINTN Status; + + DecodeModRm (Regs, InstructionData); + + Status = VmgExit (Ghcb, SvmExitRdtscp, 0, 0); + if (Status) { + return Status; + } + + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRcx) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + VmgExit (Ghcb, SvmExitUnsupported, SvmExitRdtscp, 0); + ASSERT (0); + } + Regs->Rax = Ghcb->SaveArea.Rax; + Regs->Rcx = Ghcb->SaveArea.Rcx; + Regs->Rdx = Ghcb->SaveArea.Rdx; + + return 0; +} + STATIC UINTN VmmCallExit ( @@ -1043,6 +1073,10 @@ DoVcCommon ( NaeExit = VmmCallExit; break; + case SvmExitRdtscp: + NaeExit = RdtscpExit; + break; + case SvmExitWbinvd: NaeExit = WbinvdExit; break; -- 2.17.1