From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (NAM10-DM6-obe.outbound.protection.outlook.com [40.107.93.69]) by mx.groups.io with SMTP id smtpd.web11.21098.1594737122996080576 for ; Tue, 14 Jul 2020 07:32:03 -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=ZOMDtkb4; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.93.69, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Sa7DIyNlfiPRDX8hm07nuXP90QqoXazKEMueMRZAWAA6cEg1Ng48hhsC+GThGw8DKWZWZYPbjOgXmjYM48YHCj8yQBCKNn/6HN7esvqLSCperUSH2RiUQ2la9gjQ/ut9El+oucRroByNF64eEab1OuUfT/cgvSIIAGaTnpQb+t1OxLAefN1TBfKgNEAstvaV4UBCT+ld4m0RzmrH/jb8291aTAOqPGMAsT98o3cxZmChAZSvLs3r2PF7+0hZcfhEHNPiG22EqWZKtrBhpWcJQn1URerOOfTcxedsYhxzliOI19NZnIk4IT90fFDYb+sm2kNT0plhKyt7rlcqvW0aNw== 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=eBmR9KB6lqv/SoSydfYkNABhlv1MkFrfLyI/DHC1ZtMTiXkIAa4ScuL15968WYT6he8ma4A2/z+mAeQ1XbpGyy4BEPjDANbhDhdWjtZpzrg4E2WUjz9sjis80UnzGVMP7/KZynUtWJUDTL6yIYhRZcC2z73DMWY1sORt8EkzVNcLLezywMFrgxccAVGz3wmWPYbkQNl7k3S/T4NP6ux8ybFavKiYz4R4wJZ+8ENNwDgV4tGfJHVrA21PTtQ/dWkin6jUM2/3ZZBNLP38dMfQ8fzi5rZrFUTCxeeRn/JvLhC/gYq0dU5bV/d/y7UgxOd9ztVZSTvIl+SaWtVLIveXFA== 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=ZOMDtkb4EK4WDH1Mgy4FyyKYuLT03cw84KcndLvOBY6sTesvLNBENPbgw3ibgaN0kL6OVcdzo/mXRFXFIi4/G4F6klGjNyGUbq9EX7NOygQTHsLaRwCQpu84EcGq54eXZdC/7NAsKG7hZVukZR6K6gWMIbNb6y2MhK7yOOvPynM= 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 DM6PR12MB3177.namprd12.prod.outlook.com (2603:10b6:5:187::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.22; Tue, 14 Jul 2020 14:32:00 +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.3174.026; Tue, 14 Jul 2020 14:32:00 +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 v10 16/46] OvmfPkg/VmgExitLib: Add support for MSR_PROT NAE events Date: Tue, 14 Jul 2020 09:27:47 -0500 Message-ID: <3daa8d5e420de73e5d63a71d79910523abcf0f5b.1594736896.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: SN6PR2101CA0027.namprd21.prod.outlook.com (2603:10b6:805:106::37) 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 SN6PR2101CA0027.namprd21.prod.outlook.com (2603:10b6:805:106::37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.7 via Frontend Transport; Tue, 14 Jul 2020 14:31:59 +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: 25260f7f-2253-40a0-d120-08d82802ab80 X-MS-TrafficTypeDiagnostic: DM6PR12MB3177: 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: iR7tDdObiE/ZBLX83PBYfkkfqBGqFBmANEO0XuIdM2gjrwvvbGDjk9bhu7mVd/6xRVirzGJ1qkegAtdM4eJOfcotHDrHcoHwqY+OG1s8ojHYC42jwbtzHwmGpgpgDBWvTgE8WONHuByadPRILLpfONGHYyWKA8GPQ/HIBVdFtaaideUVziV31FM1AEmPSu6XZLdiSQGZPbZLcM+8FzCa8rEpTOqDmmoU8nWPSFu8gcDDhQrYs3f29OezqzhvMASGw4j9x6dpYaAupAhGkpC+qH0/14gZQA2JIRNdnvR7d1ZQXPBGdKDeakH9QN6P1vY1VW87HHlB+P1Jds+7lHTfa0VLlWaR+SdlCm5z1p/VU4l5uAiJWc0tbDUeDelH9M+FkwdTpv4f2KanLIoVrsIsteB78gqzqBDx816rAqUQqVrOPnFnHghXrcb85B1irsBuLdnXjbzhIXi90thmMBJD3Q== 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)(396003)(39860400002)(136003)(346002)(366004)(376002)(86362001)(478600001)(8676002)(54906003)(6916009)(2906002)(8936002)(956004)(6486002)(2616005)(52116002)(966005)(7696005)(66946007)(4326008)(6666004)(66476007)(186003)(66556008)(16526019)(26005)(83380400001)(5660300002)(316002)(36756003)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 7PCWe/C5xV//qZi6qXJzWveYZsiLM8mGWfaGGVqAQimmJnGgfcjw4Nbp+zziuagv8r60sDyiRKBq2m5EvJyG20LBeuLgHmn7fqiOvmuVjePTjs55g4bvB74q4MqdGpo5NZnWsCrqix4DGA7xfsGCLDgydJZfh58Bz/KXufBOUD+E0vRhZuVYZ5pQrahhoTD4tZRELqmg2tWRlWM+kMtvi3noDOCRmLFV1/LJ9JN/A8DSvMD7gaCdb2JrKK61kxqrXtIR7NYWUagYA8W1+0BelxR13zCaW0u1HFzwSsbHjM2/kHmJgad+F8R7XIbohYAP8RNEQuen73vL0pKqBCuG4OLVQV36g0pHUGdI9WAl/ewzfAu4N/uOOEOyu+Or0y7mMixi8iztHKeEDTryBpvttIvj6T39c79vUgXFoXI2zHRNL6RvUKHvyXK4LsiBLpTnrgTGDtjrRKF7DPK7E98j81Hy9sHfrYeEmxsuK3Ihc+Y= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 25260f7f-2253-40a0-d120-08d82802ab80 X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Jul 2020 14:32:00.7995 (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: UYJ+RpNoAMvWN25Uz1/V3e9GIAf076rwipZOgf1MruUccEU3JqIF0oDmFwqmsEXfA8A8C6h2gCDFVlKzVNSpdg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3177 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