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.41]) by mx.groups.io with SMTP id smtpd.web12.486.1587577361985959466 for ; Wed, 22 Apr 2020 10:42:42 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=sfr2tI+l; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.76.41, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RI/xfpLPVsWjXdZbJMTIWaeMJvr9CsyuteNkpIBYUcY4IhB5LgAbbbA4P5nJYQidngZsUkXUslrhnKAUcXRp3prsT7qB9qv19TTOYDPxEEvHskaejsPfOs+klTrs1J4wvdqG5PDYNCeTQoIMTwTK3ovhbCNr9DUhjiYKlfjqFYibwSoUEX2fqBUk/bYR2nQnVD5wdHIeYS+NPmUvK+oCWyf8JmU5jUo69EeirQ4+qTN1PeMp8bINc7qnqRawdLtymET4JiQHXdx/hzsR0gWoZ2LKtfLLvPRbci6LIBHEwaobLjPYLaFIvGbPqePryFbjCFW9bF0bM+Ht4fFFcVZqCQ== 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=d3TXy9LpMjXQdUNSU2Jw9Xr58PDR5qVimhnVzzDTlew=; b=JLaUC4xOpxMv5LeOgtGZC+8WDNLxQfjJ3abYiFpAb+iUMV2aukzOLFwKWYO4e1yMCvopW+yigZlmM9zjCzfic1nHCLOhZGOWeiNN1kQFGcSpNqtH1uW9HLwFmp5804+ciGpKtQu7qBRiJjcCZsXtMaf3CGzrn6HUbzIEeAQ6fy8mI4/9RI/vpIhsTxiuqmO0Xk2wIdZ1RGj3WuqMeX+umS43+K7bFSO/qoMIgLEadJidg4LSuPxc0+IAByytlhlQSGo6oyDC4fY5hkfaEa7oYdT6EKWajc5Zw/FI/2vW+Tt8Pkf0nFXtX8Lvul7ISxzI4B4WkWe8ELY1PFPxUSaJCg== 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=d3TXy9LpMjXQdUNSU2Jw9Xr58PDR5qVimhnVzzDTlew=; b=sfr2tI+lYhu+FmGMRed+5MZ1N998IxW9O5PrGjEnFbksJICcnZW+X7eCNGSodk+wIbYkhzqxFnyOE2SQ6Zu61jvHxVISiBBcs9SWrK6UCm4q0zsl/kXJxL99NL3LVByR8Atak/ZZ7ft27HEhxWKIXbvh9ZPAbPUEKTNqEwQWbkU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; Received: from DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) by DM6PR12MB3449.namprd12.prod.outlook.com (2603:10b6:5:3b::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2921.25; Wed, 22 Apr 2020 17:42:40 +0000 Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::9ae:cb95:c925:d5bf]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::9ae:cb95:c925:d5bf%4]) with mapi id 15.20.2921.030; Wed, 22 Apr 2020 17:42:40 +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 v7 23/43] UefiCpuPkg/CpuExceptionHandler: Add support for MONITOR/MONITORX NAE events Date: Wed, 22 Apr 2020 12:41:38 -0500 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0060.namprd04.prod.outlook.com (2603:10b6:3:ef::22) To DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:15e::26) 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 DM5PR04CA0060.namprd04.prod.outlook.com (2603:10b6:3:ef::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13 via Frontend Transport; Wed, 22 Apr 2020 17:42:39 +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: 83d6252d-4b75-45b9-83b3-08d7e6e48da2 X-MS-TrafficTypeDiagnostic: DM6PR12MB3449:|DM6PR12MB3449: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-Forefront-PRVS: 03818C953D X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB3163.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(10009020)(4636009)(136003)(346002)(376002)(39860400002)(366004)(396003)(66556008)(16526019)(66476007)(186003)(5660300002)(4326008)(86362001)(54906003)(8936002)(81156014)(966005)(6486002)(66946007)(316002)(19627235002)(52116002)(7696005)(956004)(36756003)(6916009)(2906002)(2616005)(8676002)(478600001)(26005)(136400200001);DIR:OUT;SFP:1101; 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: gEBDqcSo1BiUb8xDmf1rGnKQf1EIm9EZmkQ1kn/u5mV7IZ30s/G6AEp5NQAPcNM2JXvdAogrBQLFqdMmKp2jfHJ5e/cEtvsRMJGhmCuPf3h85+tKe8b+wj3MZtt5F/2X0f7+rdM1bIVA3mtk05xl073HMvr5tL9OvZdFf0bMFS/p/M146/gE2jKpoRa95dEHi0Cc4xekPaIWYXGLy1uNfLS58Fsj9zQ8Fkyfz2z7OYDWP0UwBmKYhMz3g44LIaq+HEjZOQxD9/jDry3gd9jHTTY/S/HYrcFc2Z6zy6gyNAjbxI2Y56A0+Tongkjv2+0DBjCBK8+ec9ligas36eSH5pSWghH8WB+lQ8oCXDv4tQjN9v2JfZngywMTF6eCWtiroxv10E1fJEsa4gzcgED+ExTRq1Q3z5mLINCdANEvmItAIvPPRnkv64amwyYve3l69TkRX8IXWHFXj954KbQYmyppzY9zWQYmz/MEACOnETQC8bkcAdzkkiEIDXAUfG678xLgjEyVBuULnfy9dmZB31IwFwN6BdgyClNzYRAeCNRil2gAEJavWuJUdvYAYmV80gmYFX8QG28bY+3nuxkG7w== X-MS-Exchange-AntiSpam-MessageData: MA0c/oyyJ5QKRK2N2NBxwxC9krL42BzLIFhTxMbXdzskAckypPT3b8W/jnTaFcqKikpo20sJibIcgNaNrG5C/O6vfxPbyFn55HWZS3EKWxtQPXxwdxFeu4Gsabc/Ek8HF7k1sGgPGuxdQPcsIa5xyw== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 83d6252d-4b75-45b9-83b3-08d7e6e48da2 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2020 17:42:40.1153 (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: gpX6dSYbmcdeCIs1bE0PNeZ/ROqsTDXj6GaPM+EIxvlJ+U5JqrHqle72IW2A9p/tTZWFxpOVbCJKQS18J6fZTQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3449 Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198 Under SEV-ES, a MONITOR/MONITORX 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/ArchAMDSevVcHandler.c | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c index 75272c47ba35..890451ff97a2 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c @@ -836,6 +836,47 @@ MmioExit ( return Status; } +/** + Handle a MONITOR event. + + Use the VMGEXIT instruction to handle a MONITOR event. + + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communication + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @retval Others New exception value to propagate + +**/ +STATIC +UINT64 +MonitorExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 Status; + + DecodeModRm (Regs, InstructionData); + + Ghcb->SaveArea.Rax = Regs->Rax; // Identity mapped, so VA = PA + GhcbSetRegValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Rcx = Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + Ghcb->SaveArea.Rdx = Regs->Rdx; + GhcbSetRegValid (Ghcb, GhcbRdx); + + Status = VmgExit (Ghcb, SvmExitMonitor, 0, 0); + if (Status) { + return Status; + } + + return 0; +} + /** Handle a WBINVD event. @@ -1473,6 +1514,10 @@ DoVcCommon ( NaeExit = WbinvdExit; break; + case SvmExitMonitor: + NaeExit = MonitorExit; + break; + case SvmExitNpf: NaeExit = MmioExit; break; -- 2.17.1