From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.77]) by mx.groups.io with SMTP id smtpd.web10.1749.1596134809851432430 for ; Thu, 30 Jul 2020 11:46:50 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=RAweqGIK; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.94.77, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dD8IPg6cHgSNsRYHdIJbwVCVLZN41diFBoC1owXW0ICfxxzCEiLQUV5xX5JQ7jpMKWypJsRn0euZrW++iCZkqL2IvatJLiHlkinFPRHSfkucfdt8g4/rQ2I6obTF6NlYDy36g6ztWK/6fWvqU0I78aap4adIc2X1g04EvDxhggBYrsdjQzAUPEX9AnH/U+lPA8F1XlqRfUnZ55/uvgKhPeYxjx2pF5UnXlhGVEzZjjC/hOdNlUxrSFv+r/Q9SXHLOSS0TIvgBAv6y++HnBhW0blX3uTRJtImJxUQ2/iU51eTucGvlm4EcVs4saYg+4mP/5o637loj/9W+VZ9hf86Lg== 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=z7KM/QY3QdiNzO0sLsMAJB/dGUXDqeKlzSZHqwBk/3M=; b=nT0TdGvH8HrS6NkFdhJnxRkwWRRu4v2o52uGHbRolBN9nniReWSixR0qWffXkQAKmk7PfHVIaqwRpIkJrnQaOiTdpzhwp65D0+aYIM/aLh26syigEJ4pO58/phNFMHhCVoBiJ/xrQd7FN6Ys+XcmiDH8rvJUWwMyoEMQyuzVL77SD0JWirLrln4bavHjEYyWJGDAoP8DUvh+cApULVX2J7IBoOj50macIA24z6CdS2SMHLTbqpDfrdBtIZ5gD7T8V5I4PSarwfRsqJ9/A/o0Mxw6jVZ77jBxNNFOrA09Dx0LDHpcs4plhWenmh9DNTEzrFGqD84TSTfYnM1hjtgRzw== 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=z7KM/QY3QdiNzO0sLsMAJB/dGUXDqeKlzSZHqwBk/3M=; b=RAweqGIKpPLj2EVoNOq3jCXWJXB45CXGKPFr0pO9ZVBFwocM0FR+4nU6K8e+HZs4YvXEiAUQqShtGtQSuiNY9W863XsZgr6UMa/shtU892JD6qjcSghNruRmgEIbqiOFmbo2PhAjk2rn9ho4Ep4Vz6Z6zeDF0zF6DQkRwuf3N3M= 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 DM6PR12MB4092.namprd12.prod.outlook.com (2603:10b6:5:214::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.16; Thu, 30 Jul 2020 18:46:48 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::25ec:e6ba:197c:4eb0%8]) with mapi id 15.20.3239.020; Thu, 30 Jul 2020 18:46:48 +0000 From: "Lendacky, Thomas" To: devel@edk2.groups.io CC: Brijesh Singh , Ard Biesheuvel , Eric Dong , Jordan Justen , Laszlo Ersek , Liming Gao , Michael D Kinney , Ray Ni Subject: [PATCH v13 16/46] OvmfPkg/VmgExitLib: Add support for MSR_PROT NAE events Date: Thu, 30 Jul 2020 13:43:28 -0500 Message-ID: <6846dc1bfc31309a65930d153f8e0ffbc49f45c4.1596134638.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: DM6PR02CA0121.namprd02.prod.outlook.com (2603:10b6:5:1b4::23) 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 DM6PR02CA0121.namprd02.prod.outlook.com (2603:10b6:5:1b4::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3239.18 via Frontend Transport; Thu, 30 Jul 2020 18:46:47 +0000 X-Mailer: git-send-email 2.27.0 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 13c8a13f-2696-45ff-797c-08d834b8ea62 X-MS-TrafficTypeDiagnostic: DM6PR12MB4092: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PHxpuA+BX0Fc4VdJ/bdJLGnHb5rE8XYAQBJ+cK19xRiVw8dCtl0DPcc2YPmQ6Tkleu73ttGLjC3dTV0ZjkXRa6/C1UxTNut4iA63UiHAM/STlK+bphJ0LNC4o3kyHMk0k3ugCFZHbNY9zeHi3w10ENIPqYN/8j4T714K/XJdJLx8RaUso0Le0g6AOKWJH0FplCMDXwTKax7+cA8+0fyGSU7lLLgmgWXZdjsegLeQVIxvhFIFAJF/3QfEXCWJ60BXrWHdkzxQcsnRPzctPxCKItVfKnxpfdwbZetvp2H92YPBWrhc0DOTo345pB80G1dV9kRPjL6Vo2u+jtDrcNz3vS+ywAkAdHWs51N3XnAQmhInzR/69pivEeqFZ030WNNpMR2OE25sQZwWN9g1BYYIM0PTAvQ5GFc3a5BpbZ2aRjA20E8ydhx3zlmAI6MtYipMGmFjS7ZjEjbZKG43kCPhgw== 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)(366004)(346002)(39860400002)(376002)(396003)(136003)(6486002)(52116002)(7696005)(26005)(5660300002)(186003)(16526019)(54906003)(66556008)(4326008)(66476007)(66946007)(316002)(6666004)(86362001)(2906002)(2616005)(6916009)(36756003)(966005)(8676002)(83380400001)(478600001)(956004)(8936002)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: yQu3Qq/yuHcx8tG5flU6s00+quHpyrEoEN84mVwSUYbEvFC75BcvQ4RKlUHvKQnlrHhglz2WRHyLGEQIVQ68NOXzz6HXJXBW2TxsUd6844wKaAk+U7GwC5ruWyq1c7uSFOi0uXjoMmYYxJQTf4O3gFSeyaljc2MfnQKjr3YJw25b4wf12aOppBhVrwIftG1qE8YMbJyhchYXtqupJ5K1a7Ck9G+jUa4KR5iRmAHcA09vU+UOpisjQ0ITFtNqLovR3M1y8omj//Cnli1YS/Oc3eAmFt32cTPj3jhbpnaTLk7zU74Rvv8O4Zhu1EG2N8AXhJzsCpQ4fzR1bS5nKzbJHzJBZ2EqwXIeACd2PiEgdGxgNJU7dD6lLrc6p1xCH/A8iB8ht2+ZJJnTWm75sjHuv+yKYiXuy0rKmD7qquxkAWsKFgqYmr8K1DwdzPevbcpDknjO5fXIsznpssfpwYAo2qr2B6VrqRdwKFQzv3R1K0BXfm6i89WRB5HSkBXNA4hsj90fbURtB2tZhoRiihGs9uo2nXny5H30xtK7pXOoKMVryFWCmTrtCFthmASy6Mo0GfUw5sW0vnPcMRJJgeg/P8vvLHjXHvySCeRx27J2euY7lC2mra+MYa+ieIpElc1jkxuBiGL/CnahCe5VxyQyCQ== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 13c8a13f-2696-45ff-797c-08d834b8ea62 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2020 18:46:48.7492 (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: 3g3fkJ0SBqzQaIo+sOJF7JgLx/8zneKAcpJ5cOVnHYpxhmcVWsPV4WQLyoEjjzoGaU/UwFMPsyGdTApTgsMAnA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4092 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable From: Tom Lendacky BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 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 Acked-by: Laszlo Ersek Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index 1c9c272a250e..dbedd4e9f95d 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -374,6 +374,67 @@ UnsupportedExit ( return Status; } =20 +/** + 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 Communi= cation + Block + @param[in, out] Regs x64 processor context + @param[in] InstructionData Instruction parsing context + + @retval 0 Event handled successfully + @return 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 =3D 0; + + switch (*(InstructionData->OpCodes + 1)) { + case 0x30: // WRMSR + ExitInfo1 =3D 1; + Ghcb->SaveArea.Rax =3D Regs->Rax; + GhcbSetRegValid (Ghcb, GhcbRax); + Ghcb->SaveArea.Rdx =3D Regs->Rdx; + GhcbSetRegValid (Ghcb, GhcbRdx); + // + // fall through + // + case 0x32: // RDMSR + Ghcb->SaveArea.Rcx =3D Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + break; + default: + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + + Status =3D VmgExit (Ghcb, SVM_EXIT_MSR, ExitInfo1, 0); + if (Status !=3D 0) { + return Status; + } + + if (ExitInfo1 =3D=3D 0) { + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + return UnsupportedExit (Ghcb, Regs, InstructionData); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; + Regs->Rdx =3D Ghcb->SaveArea.Rdx; + } + + return 0; +} + /** Build the IOIO event information. =20 @@ -705,6 +766,10 @@ VmgExitHandleVc ( NaeExit =3D IoioExit; break; =20 + case SVM_EXIT_MSR: + NaeExit =3D MsrExit; + break; + default: NaeExit =3D UnsupportedExit; } --=20 2.27.0