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.84]) by mx.groups.io with SMTP id smtpd.web11.476.1587577352717121981 for ; Wed, 22 Apr 2020 10:42:32 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=bQc1H39g; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.76.84, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TfV88DWWIGD22mumAPLki9TOEzpRIZllWRWUrhnEHxSuRTyxjdSwEq3x4ylMO7M5ckBRkc0hmtS6ZUGAVjfCH6SepEr9YCajQMHkdB5NTcVMnW/EVP5QeL1X8JJBTryq+WhMobwVnqm+EvsTb75j7ABvjDNvgOka8pVMkye0SNAoMBtf9CCSyYUMCWk/n3o0HQRhki13cOlgzxg34QSWpkU4gs1IXAJjjxse6e/qwYTUYv6qLUvyy01EvNqY+FtjE5Mean+f9L7LiQ9Vqs765PqYUTk2crKquiJIMjGopko72nMAbq3H9j96C5Vtc0c1kjSdSBlN8vx8hoL90fVxAg== 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=fNCm7NBt4GIOdcBOAD74dTnEknJ7WiQLapwMeT+LgPw=; b=ocdlyalIowJD8rNegWaWSx7j7iay2uXPM4ThA0oui03R5DemOIwBhz1HTIBuH5LmlEKAY0vr/TxIz2/22IsSsZtP+8hDXxDZ5rfqEPeZQQWt7zgREgOTSJLOxyBRsxx8Dgb6K3bJJAyTRggAGyIfRgQ4JpDbiM1sCgiiB5rNALx1Kiby63GYHLtbcaJe/J24VdL0Fk7dKoaX01lejpc89Cn2Fgh/4bRS53k2sqBym7m7ZZR0zj/NQTv8eri198wfgH5is9YtXNicBTxC/oFQiyIxt0W8qeWz20DYgBOZrrBSifX6A/0alXL7zV9DfMVSggozVMCbNv8t7mldxVfSJA== 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=fNCm7NBt4GIOdcBOAD74dTnEknJ7WiQLapwMeT+LgPw=; b=bQc1H39g1FqM2NqAu3/9SuvffBHkoGMdAnNpGnhsqcQtgLFuJVgkdMKCGaWEB6vMyH8xpjyW20dohSPuxYBUbDuR9zSa3bCVbZqokuYpOAcyi63wVFSsMUWNiMqgH+jWeL+pGYUBfPSHh6m88zuxpHh/t0raBZSCOrPq0dknxIs= 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:31 +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:30 +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 15/43] UefiCpuPkg/CpuExceptionHandler: Add support for MSR_PROT NAE events Date: Wed, 22 Apr 2020 12:41:30 -0500 Message-Id: <8fc5e2b1a4c2b128bbf4b60c4e465515d6fe3e21.1587577317.git.thomas.lendacky@amd.com> 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:30 +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: f741e954-7644-4bb9-2e0d-08d7e6e487ff X-MS-TrafficTypeDiagnostic: DM6PR12MB3449:|DM6PR12MB3449: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; 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: chzx2s2/s2597LP7+glubAvSHP/ijW/fHooB8nyl+cQ3UB0BwGZRvYhKN+vIsjxA8CzhztJtZ2OY5CQF1lG5zhz5ck1ENVOJSWQVIMDFFE23LmiJFbLVxtuxR43MYjmWeyPs186EdetHFV4OqGCjRliC2LE3KR4JK81ayAx+yF1JsjPUz1gRvlbqz3wS5R99HcqUFMKjRfpPdXANjXTGORPp1uF8FCwA8vfpPl5iYHl8xmX78zLyFF0qrJ/rHBxfR6nIexvz3KLLDs1N69Osij/1KxrTcBcBkO0RXo8ihya1GqwgAviIehGFSbKTe0jcg8HHEnYZhJYCcLA/wCTIlBz3SHIIF8YyRx/tjJOlkxmNUG33ntroF9luuInTKxAlYoJI7hPNkiopSqWGazqZXX/a6cI2FAVSEi3W1VRgZtJ8E3FyxGJ2eZB/s/bPYRTn4wTNr539dKl90UhgQXC6Xb7X+h2BVBRXKgPm/NBS8zOPKZa33jXYRUW0lDblWUsP1L+jnuCty4ZKc0Cj9sOVBBxvDK5/tQQuC7HEbsjmShZuFowfovyC2LSHVKZ3GvVlIxBMYH8U6+RjPp1t8umntQ== X-MS-Exchange-AntiSpam-MessageData: IKnQhl9oivaf//qtblM/mYvBjYBc3wVvc7tNk1NVeFZNfPUNqpC8hZaTwswa6NNvuvgodVKKS5aEogobun/CStZHYN4edNjty4yB0qV6PHEsh0StQMyTecz/5gC89qDDkgoTkSqfVOPty3KrfXRjtA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: f741e954-7644-4bb9-2e0d-08d7e6e487ff X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Apr 2020 17:42:30.6933 (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: H52orDLGoywVVCyfTZLlhvns/9zhQAyl7s5rbQ2eFrRyNHZCF4hsM14bEBd0f7QkkfwH3zGxqIk0hoFkJhNDbQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3449 Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2198 Under SEV-ES, a MSR_PROT intercept generates a #VC exception. VMGEXIT must be used to allow the hypervisor to handle this intercept. Add support to construct the required GHCB values to support an MSR_PROT NAE event. Parse the instruction that generated the #VC exception to determine whether it is RDMSR or WRMSR, setting the required register register values in the GHCB and creating the proper SW_EXIT_INFO1 value in the GHCB. Cc: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek Signed-off-by: Tom Lendacky --- .../X64/ArchAMDSevVcHandler.c | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c index 4324de152b82..8eae3633a31b 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/ArchAMDSevVcHandler.c @@ -404,6 +404,65 @@ UnsupportedExit ( return Status; } +/** + Handle an MSR event. + + Use the VMGEXIT instruction to handle either a RDMSR or WRMSR 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 +MsrExit ( + IN OUT GHCB *Ghcb, + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs, + IN SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 ExitInfo1, Status; + + ExitInfo1 = 0; + + switch (*(InstructionData->OpCodes + 1)) { + case 0x30: // WRMSR + ExitInfo1 = 1; + Ghcb->SaveArea.Rax = Regs->Rax; + GhcbSetRegValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Rdx = Regs->Rdx; + GhcbSetRegValid (Ghcb, GhcbRdx); + /* Fallthrough */ + case 0x32: // RDMSR + Ghcb->SaveArea.Rcx = Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + break; + default: + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + + Status = VmgExit (Ghcb, SvmExitMsr, ExitInfo1, 0); + if (Status) { + return Status; + } + + if (!ExitInfo1) { + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax = Ghcb->SaveArea.Rax; + Regs->Rdx = Ghcb->SaveArea.Rdx; + } + + return 0; +} + #define IOIO_TYPE_STR (1 << 2) #define IOIO_TYPE_IN 1 #define IOIO_TYPE_INS (IOIO_TYPE_IN | IOIO_TYPE_STR) @@ -722,6 +781,10 @@ DoVcCommon ( NaeExit = IoioExit; break; + case SvmExitMsr: + NaeExit = MsrExit; + break; + default: NaeExit = UnsupportedExit; } -- 2.17.1