From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.63]) by mx.groups.io with SMTP id smtpd.web11.9832.1597325158494345955 for ; Thu, 13 Aug 2020 06:25:58 -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=n4Q+qCg8; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.92.63, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=axTU9uC+P71dvOKRZcLZuMledNv8hiU79AsiGNDV4pLtxYoEbY/0IO4l1cIUNr9I7oWSa/TsoQ5WQURZRESnXRnHQ7BJL2Ot9Q4Q9e1e4Olame7umiv/tXh/D8/AQD3dpTSCal1NgvKuTe7iDmMsFTrGXyaAaLadCdQxhrcoijs4hcehfwar6gIFgIkUX1w1dui9UhC5t8yx+EvHa6QLqsvWDGqEBN2DVrI4Ye6UGhabOlNNJv40kGQcOCef3LTwtv2AbU1JNrFuiqW+4wNflozMoiAjI6YOwLH0UvM70hjd2Y3HXwn1RPDIQM0EJuHM/m3EPUuZZp/A2cqZ6vpEOw== 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=WwPoHenNP7rvqZUFCgHcZryvUQELIkWR2uUul3kCMqM=; b=gwkcTjPrQOHkdSYOgqe0VmGTbkWr+WfLWpXu/jc+ReVFTaZob6CgSyomnG7qW6b6F2J80cEMJSDqTHCZoN85I9r96vZS7LIl8ryiNLCc31kD9SOdqq2XoO+CSZpm9NtiuklyrLCNC7RW/NXTeb7xubdJBdHdz5ZCeLoBNbS0jOwCedQhgtWWzWzLA6NEljHBFXQuYc1M6nCpdv2nBl0euFVZXFn3Hcp9wuS55jY2RkuO97ZlT3S3g7FmDzcraKqAlXiy+5mNqT4qcNwoFjRO1yAjt2iJK8N7Ml6RjXTAet10gzzOHgBZO3o5PoYE2dDyCG8J6f9/dYsL32E6G6lAAg== 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=WwPoHenNP7rvqZUFCgHcZryvUQELIkWR2uUul3kCMqM=; b=n4Q+qCg8tS0dVP5QTyZ9umZeYom0OoxTEfefm/+01JUEEHyPDlF1BSlhtwshY/WRwIo9aGNbAiKjED6py4kGOcnE638q0GTtj9YTfO5sIAUZMGEocfZrGI81QSgvyq8Q+qu+IKpQJ7G2asHtLyi77rQfEp4VBlxWB/OjSuLP9zM= 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 DM6PR12MB4220.namprd12.prod.outlook.com (2603:10b6:5:21d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3283.15; Thu, 13 Aug 2020 13:25:50 +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.3261.025; Thu, 13 Aug 2020 13:25:50 +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 v15 16/46] OvmfPkg/VmgExitLib: Add support for MSR_PROT NAE events Date: Thu, 13 Aug 2020 08:23:03 -0500 Message-ID: <93aa72fbbbc81e31310e8257079002303bbc36e6.1597325013.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: X-ClientProxiedBy: DM5PR04CA0060.namprd04.prod.outlook.com (2603:10b6:3:ef::22) 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 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.3283.15 via Frontend Transport; Thu, 13 Aug 2020 13:25:49 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 1d0e98e9-a96a-4632-3c05-08d83f8c6585 X-MS-TrafficTypeDiagnostic: DM6PR12MB4220: 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: Dc/UgRghtlrDR1oemO4nFDd8FPbGbEE8k3hzUqfkc7H+Yr3nuiVLspV0U1HEYJeh5KnChuQXuise2aDXeFxAF4XUXR8lU6D1t9iSSHM/jsUl9a5Uf45vOEvXE2kLCdjPO88GGQzG9NBVTfKwA08bAUcFXECpZrQ6R81Do6IygcHfXOHOHtfmXz0uyc6O2xr/aWezJio3SaR4Lyx+2VB2wX0w1CDSIMf/BLZ6MIRY/hloR0hGqHSKXFnWAA6/GiXDD1oLJxGDg4h+yZ60JOxDzDdoQdkJM2CNlpPoDkA0u5BLwm9OxsBA1FxM1lojsPetR2A17R8H4ztDT7nmKPXDSRh8HxyIR+vwj96QqgCbwpacIDRsQ0IKjGnz0T9P5BApi/rg7XHI8yZmKjFqrUFO/K75W69dKO01rt5VZCBgrrv/a4Tp8zrO7ZN7HGpAA26gYxE81yXpEzKJ8PF934M+xQ== 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;SFS:(4636009)(366004)(136003)(396003)(346002)(39860400002)(376002)(2906002)(956004)(36756003)(66556008)(54906003)(86362001)(966005)(2616005)(6666004)(6916009)(478600001)(8676002)(66476007)(316002)(83380400001)(52116002)(6486002)(7696005)(8936002)(66946007)(5660300002)(186003)(4326008)(16526019)(26005)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 1FhowqTbo+fyb4snLmC3Cngjof0/1wwvcRluSpEpUAycNb5CNf5/rqT3JyCH6QkXTLuqn7jIAppuSzF9e9rEe7VMP4nlLEWVFlqoBLGzqn1P4uqGK7O08vl5dQltwW448UAzXcn6CSUdbxKGL1s6R8GXj6VOGfr4PIj8p0O7ePp2k1oNjLqIYbBymaVJYcWE0Hta3l1j9FXIsVUnRaardwAMA05d1V8FZeQCXazY5R/jkKCWMMw/CffeSutXnKbQz4cL0/CdUJiYCl0VB1A/szXsk8FgNBkOdW9YX4RnPHyp+Ks+PxaburjC7i03cDJWZz9MvyGTki97jK8ZutvaZAY5X58nS0XrzxiFgHLt/XjutSCdds3+AmNZ9cJADmCqTu56909eHM9ubYnfJ66H0sb+Px2xqpA1QRVhKryHO13n2K4j41mihYRJ/I9mdH37d2m0dUBTu9vB2RMCw8fDoa9YjijQf0dJjd03OPGKBCEf4osBPNmflp/I5VrzVsqDRPjEqJ49rmTNXx+T8II9Agta+OZBt8bC7AlBik2A0zrIJcJ79muX8jX3JXisReVxLtOXnKFLerFRYQw6LrHqCSnz7oimXO6zjazqjnx2rBzBdhXitBDbXtMcE9SIzauMw1vSQ5P7vDgp2Gjw3LXcQA== X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1d0e98e9-a96a-4632-3c05-08d83f8c6585 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Aug 2020 13:25:50.6116 (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: FxNaedVyRjaeMM9t+lP9/7ua8+UDmuIc36/5+2Q8p1gxYS2mHiyjDBkaYu0vGwjpcLyOenwko94e9AN9xQRuIQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4220 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 476e94ce5fb7..f6cfd7fa2993 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.28.0