From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web09.1692.1580857338005546073 for ; Tue, 04 Feb 2020 15:02:19 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=JiuvRKaj; spf=none, err=SPF record not found (domain: amd.com, ip: , mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ctMRCGLPHu5mye/gvn0fKhiRCblUs56cOshr3rdIh72Pa2V4uZsK00Rl012Heg2G6qQjO17kFm+E0AH/VF8eRK9SWehHHAsayEA3ZYJZPAgsEeuqc86ZrH76K4OOOxcYMk5rf/d7NXIbszuzHqGDekuDsusl1IW+KMmmDUhil3+56NoLEWL9tVMwL7zCEyftLBqqzgV0SSU9uzk0IUcVQXOBgZVQKhc84FqiBIXEWzFd6bGhFIRehyNcQmFF3JaTMsSP2tcvQzp4LbJ4/TMMhrQrbVdk16ZIZxVSBuIUVfgxRvkvBw/VRE3oF8Dz3b8WSKGeFI9DMNUldxVDHbPy+Q== 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=UuUZ7rYIwEsLaCBbk3MGDWyM7vEMwCEx/yOnta6eUnY=; b=lCPByt/we31o9jJjDkLY3Dxl5DYu1HAPiROeFulCUnMji+Qlz+kO8g3gRY/xwLViZIQXlgGh2zlM6C7Atx088KV5QnM8FRXuh60hmsk3Egz/72ftFZNlW5RvrnXdGuBUBIzoAZa6YqJitv3ymBzq//uaDlAxm005C3elIzjSo4W6N+Qs6U6O1P6TXy3wdQmLws7aX11vEGpxuEs5M8nPCYqZHNZNuuvdHl88zJtugZ/ifH9qdrPezE9Tes+vDg93bTRWtHkzgViTZWWCptcKtxKgHphjU0sNLt+Rm3SsNx1+tnPT75zmooJzxZgoGwBjpGnUOLrWoSE6UJK4mlzKiw== 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=UuUZ7rYIwEsLaCBbk3MGDWyM7vEMwCEx/yOnta6eUnY=; b=JiuvRKaji95bd4hlopGwiUwHdG/AhJtpTUHUt5h+Xg3HnVgF0dGSzcWRNkxZTsOerpmp1tDZ6cXkBjlwMZ6B5gWm9LOk2F0IGVmrKmc8jKbp1Unoy0fOpiyVNvCZvou8oE4JecUoqRkwRWFr1oc6+zpSRiGfKpmgrZgVC6ziQLc= 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 DM6PR12MB3930.namprd12.prod.outlook.com (10.255.174.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2686.29; Tue, 4 Feb 2020 23:02:18 +0000 Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::a0cd:463:f444:c270]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::a0cd:463:f444:c270%7]) with mapi id 15.20.2707.020; Tue, 4 Feb 2020 23:02:18 +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: [PATCH v4 16/40] UefiCpuPkg/CpuExceptionHandler: Add support for RDPMC NAE events Date: Tue, 4 Feb 2020 17:01:20 -0600 Message-Id: <120361d3390b049782aab490b38776080736abdc.1580857303.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: SN6PR16CA0062.namprd16.prod.outlook.com (2603:10b6:805:ca::39) To DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) Return-Path: thomas.lendacky@amd.com MIME-Version: 1.0 Received: from tlendack-t1.amd.com (165.204.77.1) by SN6PR16CA0062.namprd16.prod.outlook.com (2603:10b6:805:ca::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2686.32 via Frontend Transport; Tue, 4 Feb 2020 23:02:17 +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: fefb3801-9140-4ba1-77fc-08d7a9c6484c X-MS-TrafficTypeDiagnostic: DM6PR12MB3930:|DM6PR12MB3930: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2000; X-Forefront-PRVS: 03030B9493 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(39860400002)(366004)(376002)(136003)(396003)(346002)(199004)(189003)(4326008)(478600001)(6916009)(81156014)(2616005)(956004)(81166006)(8676002)(6666004)(966005)(316002)(54906003)(19627235002)(2906002)(6486002)(66476007)(66556008)(52116002)(7696005)(186003)(26005)(16526019)(5660300002)(86362001)(36756003)(66946007)(8936002);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR12MB3930;H:DM6PR12MB3163.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX: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: hdW2zxafXJnpZOmt5buveYzrH+WIT6YkM99K2nKNA2Ej0qIqgXFIjfdNjh7YSJLXyfaqZ1dc0uMupCGTw0GnYx97BbZvFBNplY8jZ9e+Y1AQ957R6Bxk2hpCOWcs9Eo9RNIRowonPEqI9jUxD12OkdJyX60AgUCYKMgot1lNlCgw9U2LzT01ozYZcmQbH6qr+h9Rui5HhpbFYNEd46Wn7MxGvD3OEl8nwCEbfMZtJqxFOl6/sYQ6eJyU03LpZ0/fxlq2y+n4BAwv0p9Is8rDhwXa4tfrOPdtQReAmnx1EM3aeT3g4VAxl7TvlJ+5Zq+bymQEDx7+LMzci/wXDpsVXd99p1bzLYU648uJ8YM+ACfd/sxFXNvwH4k+Ty8n7ua2OmDEqQJ6H3GSCeFa3urc/GokG5MElfkcFbds4FIC7eYyDZvCiVTlGhL3+vrR/JKI4+xJ1D+Ct7sOeyx4hMJtGzVSlVvHQBM5Q/QQgtovl1X68tLLwVWBUp50IZByrCfCEKoYd8zxmziTha2mGB/agg== X-MS-Exchange-AntiSpam-MessageData: 5ydlqTCdW7ovNK9YCn7LVnyu8XuckZWnnK9WE7UujLzvypiJQYmnXviimUi8pj6w869s5WUxK1jniQL1e3xvM32ruqti3kdunlP/Eo+cgWxzbPYXj7emVSVIxBF/ozeB8RBn92MuuqbzAEyxYGJOWQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: fefb3801-9140-4ba1-77fc-08d7a9c6484c X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Feb 2020 23:02:18.0212 (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: IHGVVDC5RW1AScLSmYoI4JMm+dycpC0lfgUOFr783kWQJWf6Ra658PSyEBXCB/GIlkUCccBhKR47FzzrYeBqTw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3930 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: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Signed-off-by: Tom Lendacky --- .../X64/AMDSevVcCommon.c | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c index 552fe2e1a343..c2bc213e602c 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c @@ -894,6 +894,34 @@ CpuidExit ( return 0; } +STATIC +UINT64 +RdpmcExit ( + GHCB *Ghcb, + EFI_SYSTEM_CONTEXT_X64 *Regs, + SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + Ghcb->SaveArea.Rcx = Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + + Status = VmgExit (Ghcb, SvmExitRdpmc, 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; +} + STATIC UINT64 RdtscExit ( @@ -939,6 +967,10 @@ DoVcCommon ( NaeExit = RdtscExit; break; + case SvmExitRdpmc: + NaeExit = RdpmcExit; + break; + case SvmExitCpuid: NaeExit = CpuidExit; break; -- 2.17.1