From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.87]) by mx.groups.io with SMTP id smtpd.web10.924.1589925116921850878 for ; Tue, 19 May 2020 14:51:57 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=SOkbQDjc; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.223.87, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oaIGVev5hgPLdn2nAAao1RS4nKU3ckeV+huI9VsphKwgHW3RPOWciMGD5UyYZ+CV4geMAIMOrDOxq/Ad1KSyCjcFnnQ/XycfldB8SxQSnhNB6Ay4xhiclXrk7EBtkjf+aen5EyrvqmyBtUV4ICD8ucMxBP29LpGeDFz8OpFvKiXJTKWejey3sfmrfO2KwAbUjjz5RY5oIqNvOjBcXqDVVwrNEgyW6rfWQC9GhbAefXmGm04A9C1zhE95mWin0c40FNSRhLB7HiLlCf211Smdb8P+IyURLGV1RrftT2aoTO6KpMNDA0N1GLTOQBN9LeCWawVCEDf6aCaWOn+WR2u94w== 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=ItdpWsxoiGnM4ukmjeGzml4BDQQ3BYGPCMEVZVYeMVQ=; b=BkAVyuJqRdTeDuByfmr2Fp2poq6cMMqukmI6afSV1GcFukW3rTJ4GeLosRBY8vfyPiup27V8p/9DdRGX0zhExTn5FJT+jXVvaG+ejEAa1PepNZUnccfeB4eevTLxGcJUihmlCDH4g8UkYZ7xRTfmbDTOuFNvinvmcn5Y1e23MQ2YIlD91j/NaL0ed1DRT99N/krvE+rpq7evnfbu0ufXU6LvRsXjROLW5oqkKDG64EqULG3R+yW7wc8D47rm+51hWmbhqBLSDEGOCCKViQ45syiK2p+sqdI4gDhyls8nEp3vR/E0F3HIFC/lWhUOf8NDMzdA+Q43U2RqKC3l1s7Yjw== 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=ItdpWsxoiGnM4ukmjeGzml4BDQQ3BYGPCMEVZVYeMVQ=; b=SOkbQDjcdKl5Kbb1lEfBmujrArdXoDCn0P1Rz57H021R1YbtmxooanKsiM/JKXejloj/XR6AuOcheO5MItDznSXRniaU1YwJHAFLso6Ilv7HMn9FxYicDvOpGvzKkAioyuBgPUYt6wY/ImR4qaVB5zbyBiADkYoyHPgHxFNkVHg= 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 DM5PR12MB2504.namprd12.prod.outlook.com (2603:10b6:4:b5::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.20; Tue, 19 May 2020 21:51:54 +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.3000.034; Tue, 19 May 2020 21:51:53 +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 , Ard Biesheuvel Subject: [PATCH v8 24/46] OvmfPkg/VmgExitLib: Add support for MONITOR/MONITORX NAE events Date: Tue, 19 May 2020 16:50:52 -0500 Message-Id: <9d7a3e2445c91d65b508049a96f4461594fe4ba4.1589925074.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) 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 DM6PR11CA0048.namprd11.prod.outlook.com (2603:10b6:5:14c::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3000.25 via Frontend Transport; Tue, 19 May 2020 21:51:53 +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: ac5529a3-f07d-471a-0140-08d7fc3ed7ec X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-Forefront-PRVS: 040866B734 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nFTonOia+ZIpITGX6lfrlvj2EWsSsVApxIJcO2whzL4QI6zt9YW6VWi4JjZ1qFtbjqPU8GyBETFz2J9dZDe6MduE91pQH+jBD+sjaZxueTFAsBbU2Z7M5FNCvvp7wSOJRNgPgDFABxxnHPTWrEmL7eL2SfDa8tHeQU0pdpKhW94TiRpgyiKSAQch0JM1HUgPeU2DmaTHD07RF5Lg/3uToZPuu+yJnqR6I3TfQ5W0dQ8nJZolVxl+QMnhh1P4VaWACJBcor0hjDHlj9wIUY8pkui2NU258WYcRc5Hyk7dYk+1gu0j+UqVUVAvw+lzJXzOYHQXp1cTT8hj+X9c5TBAMwUnSlzBpuNnZLZYNxObmpataCjpx+pcm7zF4rJjdrpkW5WaftD78HuXaPvv8YqBH/Fgcnf4vn2I6RHow4FzYFRYYDfQCxafGKTL4m1b1eQBz/xFtX2jWDI0FJKyrI/wQZumLmd/LTarSCHgBP6ynNLy86RrXJil5j29ySkwxq5t5uFhaXDec1xwvQSfTqk0mNZRId/X+Pn+Z+rh4I1tO0m5DlrGsEWTroVUfKdpaFi/JfAjKfybfjnk05eCz592zw== 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)(376002)(39860400002)(136003)(346002)(396003)(366004)(316002)(86362001)(2906002)(54906003)(7696005)(52116002)(2616005)(956004)(66946007)(66476007)(19627235002)(66556008)(36756003)(26005)(16526019)(186003)(4326008)(8676002)(5660300002)(966005)(6486002)(8936002)(6916009)(478600001)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: uFDm5Ktb1uLOruEb6CQEmsfcmZ+zwKQNteXLCafcV5iMQP4GcjVjpI72tdvYJiea382eMu/Hn50vYA8+o4ukiBONxNBahZ9qSu9dx4sLoSlLRVTnSxMqdE3K7qhxcnx1Ml21TPHRf1P5tYhbL/+sAd29xyfO0/XkUaejmahcKcV1xO4shPlWB+u1M4UKGMDcaqzdIx2Tm/5YEFd8pzsBCq9zacL7RV97gyBm50drs2ppvMH2yNWd75NaZ69UFlf5h1L2fYkU38z90OtxR+OfMho7GwkDu+D7B2CpxiH1V7u7ZYT03f2U4lv+TVF9vMifXgWadhU8MBztPu6hNgwBCp7ffJ+JZJ5KOD/cUpX1EAunf6k9kCH+93uu4Ol+HPelGGqveNe9K3gox4g2bO5jYuNRUgy9iWK/ZHcSyJ6pe8Fx3dx/MBcDTtpGIZBWws52prMQKkmHHxWU0ASExvCZEv4HtSf7J8kX0ZgJf8SnHOQ= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: ac5529a3-f07d-471a-0140-08d7fc3ed7ec X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:53.8543 (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: JfN+oZ5hIy++bYeqFxIOA0hBm4Tx/olv53oeeIAqK55z3qPbBzwXPcqTifL7JlC1wPkvPMjYdqy9u0BAFr2+OA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Signed-off-by: Tom Lendacky --- .../Library/VmgExitLib/X64/VmgExitVcHandler.c | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c index 716f21a9ee0e..9b7639069276 100644 --- a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c @@ -843,6 +843,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, SVM_EXIT_MONITOR, 0, 0); + if (Status) { + return Status; + } + + return 0; +} + /** Handle a WBINVD event. @@ -1494,6 +1535,10 @@ VmgExitHandleVc ( NaeExit = WbinvdExit; break; + case SVM_EXIT_MONITOR: + NaeExit = MonitorExit; + break; + case SVM_EXIT_NPF: NaeExit = MmioExit; break; -- 2.17.1