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.web10.921.1589925107171473827 for ; Tue, 19 May 2020 14:51:47 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=0AEsiL0i; 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=g6+hYi3rpdedipYl75FbVani7EDrMpniAeq65BqoMLi627fBNPy4Qzkesl2oqznfGsE6y/F1EK//cbpOGLV3q/pfrDwphH5PpkHXx11+B2sB4XyEWdv2xmNGoS2v6RshClUBYJMXhGRGjmSUw5xXgoXLToXdDsm8hE1OgK10tuHj143y4eO2hWRXsv5i3HmsewkpOvQrmMsjZctKYBsMz67d8X7m9j5JS/4Fn5+tFJKWK8jm0aDWjnqN5vQgW4Umz2GVzXSmR6+jNrY3JUvYcAXWHcWHKLF6mZ2XcFhgcnyes6s5DdmitmYXXmtT74kuaQfe5pS6sAk9ZBQ2wRRh2w== 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=HhbV/jlpH4VFF+4g3Z4YBGMDxneVSeIv9RfgxMMNmIU=; b=gsJovfvCBtS8aOKHx4vXWnDzawAK5QcKtgAXq1CH2q7/6K3cPejT6xGbpE6vw61Sa3Xz2g/tSwflUdPqvMwCkKSeWVVDJko89x3UKlrVZOj4N272FzMj0QAshXPYC0JnPz17n43sYxq9vAtR9Cy4Fi/8/7265WPastqeIs3lsarG2tpL7MnYcqeRPHCtxcNVrvaed7mhhnVDj5x2VF0NK8dWe8Wus2+mBhuKtcJRybBcsdwQMR0NW7cEfQQJIE5lzNQ9asu8WfQRSGDc9lY4LJ6KcBWuFPoAYFbOKVPZK8NIknnuNtyUZLYmCMVCY4FW05ZongqyY/FfDiFpKJ0kdA== 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=HhbV/jlpH4VFF+4g3Z4YBGMDxneVSeIv9RfgxMMNmIU=; b=0AEsiL0is1uBA40MU4sjFoY4X5wnz0Pe5KqzsXNK08q4qw/9E07IEohVs+dTsG1f6HaXV/yeX9qijjKmr52XsKQigkIQhKkcTETKHoJNtGTKGWPZvNWXTnGOcUna06BUmMRQxHTVZWugaYBy3CKyKiX/RcBxQ19rgomoNsUGEjE= 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:46 +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:45 +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 16/46] OvmfPkg/VmgExitLib: Add support for MSR_PROT NAE events Date: Tue, 19 May 2020 16:50:44 -0500 Message-Id: <0c535885cd63be2633ae1f421014f5d2598fe0cc.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:44 +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: bbaa557e-1f10-4e63-49b0-08d7fc3ed2fd X-MS-TrafficTypeDiagnostic: DM5PR12MB2504: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-Forefront-PRVS: 040866B734 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 47dhoHoxJlO9jKddkZJTnSTqL2Du5Gbg81AZ990BjhnC1srMkljE+MYGyjtPZHwcTXloltbaNIvk95UguclGCcsPqmdBgIx6EITYbWqws2nqONCPO+C1vo1/OVDTKrSDb4WoUzV6tp+C6+XvAocguvu1PScI745FeS4GZvfN4O2hL4urjx1bW+VGd7ZBHFYlIYoDM86PYWSUcQK6Z8XMHqqVz3cwRnAGI+4+sBOKgYLmd4Rfs9m8vYHFJfZnYWNO+GFIawJl1BFvS0wRMXQmnK+pS30D73sbZjKSEZ/FRTDvZCpS7ZeOTItZVTNUtOtDEMYSKKJCDtWi7ncdpGlWknyqNQ9NtH8sfi+GVHn5gkNnQjztHN0o9zCyDNLglDrEEEQpI5hh4g6O/VvTvRDx6pSgYG58pE0tAHBg9TznOt3kiNVp0q9/1lMxtt8y2sEcRJNVKV+VHUHUaBnOG7mLqQ07xXPUHbnPnYENUVsvGQq6ipfJzP1X6oJg4djFJx6zA2nx3Iv6y7ALdwfjSJGcmfMqKybZ/DM2NSuD7EedWD3ho6XLqnFfOl3rPns+xniyr4ki3MIe0JxIsoVSV9wtog== 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: DKtBNCfKbrITaaVlUs/0YKWz4yiKfzuVi1GVogu9V5uoc2EhGZfkpU0YkuX1iqadHKGQ1Pr2p/Llv93wEV/OoqQi6qtn9k+3rkzH19vISYNMelaM5fdT0+FiuVXwa37awkMuymvqyOzxEad8UZM+iY3Y/kMEfmcPD7LvGKtqK2wGJAWtg+Lm/GG6/0c4PzQWF+moCEJs7hBCv2sVMltzIQ4DugECKfcZXnzmBJdOwSNOzUtRnD9VsZsMImJPUgYJHSzqczW77HKp2P4lnrvRo7WKXBOFA4hDNrsmuVONeayo+ztEwB016iBY5uUmbFt6aPm/odxua34vBScQgn3pYTwltfekt1E7W0b4vVJdlIkdqOMkw/vxfNSPPi4g9gnRLMWwRbQlg5ylrYm+60VxnSEjABCv3TnXv9sy6YAHxRGvzib/uNWr4ehW73RfErgdP6WgnC/eSa+FPqbBwvDdh6aKqfdAFp+OOpkeHwhzZII= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: bbaa557e-1f10-4e63-49b0-08d7fc3ed2fd X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2020 21:51:45.6150 (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: VpA0/54OB120/bn092WI0++jpC2Q66yovEFGSqX0K/+rCT1IG8BMAv26UR2urAWnhHvn7gwvUKdETjbWXA4e7A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2504 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: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Signed-off-by: Tom Lendacky --- .../Library/VmgExitLib/X64/VmgExitVcHandler.c | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c index 2f62795edf61..1c6b472a47c4 100644 --- a/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/X64/VmgExitVcHandler.c @@ -411,6 +411,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, SVM_EXIT_MSR, 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) @@ -743,6 +802,10 @@ VmgExitHandleVc ( NaeExit = IoioExit; break; + case SVM_EXIT_MSR: + NaeExit = MsrExit; + break; + default: NaeExit = UnsupportedExit; } -- 2.17.1