From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com []) by mx.groups.io with SMTP id smtpd.web11.694.1583190475799820802 for ; Mon, 02 Mar 2020 15:07:56 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=FukgY0k9; 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=gteTqtrlqr5koWpfbpnTBL5cW7sOorL8MbsXi062ybNK/zFmkgCr6EQ2yMCLb41Hno6KA/qpAupa4oc8ktb8NBB0A0Ot0f9gN5jUNAbo90Mf8I36ctSBi0xtdIT8X4GSzeFwBc05YrPSeoum+X4HIhAF20iZleF5sHfVB3pgeBE0eoD/DsR24mGn8+iXF245GEG32/SCG1Tl4skLVYX0h03I0oJLHermZ1hVEkPYW9xzRCEyaCIaXOHUBaPWbqYY33rEpTdFEIRqZl3yFeYl1pUhOWGibUoia80f+sU937RKzOZhVX138LLz7cFn3VCIxeZHXvyto/cS+ZzHEi0vsw== 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=Bxg/5svd+UDZU1TBirIDxMoeMq65CvHH0E23H4CY5eA=; b=bU22DMlNTsVDB6mveKWXiZW4bluOaOAfCa34RoyWFmqHOf08UcElCTmQjLZFTnAQqj5Exx58/KqRU7nNRCkod8dx11ymRow9yyKJlsXIRko0w0bNykHcl8BqBXG7F+KejcdCKM6XpFuWlYxmqZn6qhE73xTCrdUuqP8LVcsfiWf9l7rXOEbjJy+8UBqnUtB2SFbhnFNxZEChFtpmMmUJmMCF7GICqF15Vcld9FOHcxCP+iQwZ1ETHjgVNhACq/8FW6fU/A51JZdGMMUuvS4WnYmxecDmHNJTHfg+h2pb1NlrtK2BG1HYRLjB5v8+i6uRvCMnF3TvyQ3R7bmAXUyOiA== 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=Bxg/5svd+UDZU1TBirIDxMoeMq65CvHH0E23H4CY5eA=; b=FukgY0k9NXUJR9pSRXtN4e0YfHMBWqiBCeLnDys1iVUx4PeYzDCazJFmE2weIWl6pL/zMR1wC6kExCPQhEBlcMe39Ce7nQjLH7ZmGLazwdBPtKtdSLonYGZZjytYuivH+TuB2EangkHZbRBUQlBLj6v/iKMLVVMskdkM87cEMiQ= 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 DM6PR12MB4201.namprd12.prod.outlook.com (2603:10b6:5:216::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2772.18; Mon, 2 Mar 2020 23:07:50 +0000 Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::f0f9:a88f:f840:2733]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::f0f9:a88f:f840:2733%7]) with mapi id 15.20.2772.019; Mon, 2 Mar 2020 23:07:49 +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 v5 22/42] UefiCpuPkg/CpuExceptionHandler: Add support for MONITOR/MONITORX NAE events Date: Mon, 2 Mar 2020 17:06:53 -0600 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-ClientProxiedBy: DM5PR2001CA0013.namprd20.prod.outlook.com (2603:10b6:4:16::23) 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 DM5PR2001CA0013.namprd20.prod.outlook.com (2603:10b6:4:16::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2772.16 via Frontend Transport; Mon, 2 Mar 2020 23:07:49 +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: 5102b729-632b-4136-b94c-08d7befe8733 X-MS-TrafficTypeDiagnostic: DM6PR12MB4201:|DM6PR12MB4201: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2000; X-Forefront-PRVS: 033054F29A X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(376002)(366004)(136003)(346002)(396003)(39860400002)(199004)(189003)(66946007)(8936002)(54906003)(316002)(81156014)(81166006)(19627235002)(6486002)(6916009)(6666004)(66556008)(8676002)(4326008)(66476007)(52116002)(7696005)(2616005)(5660300002)(2906002)(36756003)(186003)(966005)(86362001)(478600001)(16526019)(26005)(956004);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR12MB4201;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: h7ehMiuOk1x20yvZ3738UletQW0VjfKFxFQKFMjUk0kF3z3UNglIOgokCAPigc9Un2g/T2G6x3Bhid4LVmF2dSJlGSW+HSEuY81J+NPM3T/L4liYs2yssb/WkCNyDY6JjcYlI+msMt8JNCt4rQPvahOnI4xv2fbEp65bN+KZBKwIP6f+S06R2mpbA3gR7sU1+zPIdaNKvBULBacx9ygFHXUH9+jZ1lH5BAvB/YlU1GUpO0evvD33oxrZxxQjuHKCjPooJKrumXeBuaoRdjqAk9BLROSpu7eSMc2mnmr6hM8KYmMzIJE1vid/gmqPNA1tbXouyp59FWG8Sw3XbsHR+UvuFHsLrdqEYVkmKCo+xLXu8NyXWgvhzpin8exmg6QajR0zYHm71hoAH7oPuhvwIT/X7UpCy5lBXfP55pU/nCZmtlW+ELO6KybGcYSL2e7LpbSJsyU9NgwrZ1NjCqoBeHNbVdHw1z0P9gIqJLvENHzMt1kZaazTJLaUIk1uVSLNucYz+Gk5h5IGO9iszcR79g== X-MS-Exchange-AntiSpam-MessageData: yyVsG833H7FlKoulZ7hGatZaKmn7c8DdQeR0jD2WfLf2Ps6aIPY0GoVBF3ux3zC7icWrxQkXEFu7IIFsXZMo2603mcZTS22CzsgcqUDaRPStD1Fk7VJSK9Vqoaw9aKxfn6B3TYLqF05kGR2HB5mgOg== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5102b729-632b-4136-b94c-08d7befe8733 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Mar 2020 23:07:49.9017 (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: 7QMzfCTjAqb3+TdB9GRLGC8pGaXGppcSgn0L9yfNdF4MsZ/QfrYLvEr2GHP4qunyte8MkxrxYaVzgSYHAIVACg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4201 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 | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c index 0a27ade69310..784229c5ca8d 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c @@ -591,6 +591,33 @@ MmioExit ( return Status; } +STATIC +UINT64 +MonitorExit ( + GHCB *Ghcb, + EFI_SYSTEM_CONTEXT_X64 *Regs, + 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; +} + STATIC UINT64 WbinvdExit ( @@ -1076,6 +1103,10 @@ DoVcCommon ( NaeExit = WbinvdExit; break; + case SvmExitMonitor: + NaeExit = MonitorExit; + break; + case SvmExitNpf: NaeExit = MmioExit; break; -- 2.17.1