From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=m9g0mZXa; spf=none, err=SPF record not found (domain: amd.com, ip: , mailfrom: thomas.lendacky@amd.com) Received: from NAM01-BN3-obe.outbound.protection.outlook.com (NAM01-BN3-obe.outbound.protection.outlook.com []) by groups.io with SMTP; Mon, 19 Aug 2019 14:36:07 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WYDUQDE6yYE1jExFpp/JPqbb1X6Rtq6ai4hK1sOXSdHNLLwLSCNkovsk+AUrKU4Im7G7zYzzbpQTQXV8xUtQ+kXAIZ6+QZNeV0WiCFmDunonRKEwFd2NWNPHyx9uHkPO9827vcRXID7/ylDqMuNCHBc4x4jhUZZkE/US1BwF66/hlHDV5ogE3sOfUGW+bmRD0mgwSLLGoiFcU95hZXZPn8Alhz3y3xfuKMCpak8pcpZVCPxqgGp8m355i6T2mjTWCDjoMI8b6GqmMvtjclGXTJJs5yFf1Dbim4He6bBa0nzN9pBRRtiznDGRSCATfOKm7W33WauyKpj6qhA8AK1iKA== 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=l8PPfUWthEPTqDD9fJLNCDnNJ5hDPkRTr6hAUOo7EyM=; b=MiQ8psTwTAhOYT8yfsWlmspSd7mAREzDFncSwA4jMq3MhUJIWuTF7SVMqV+GPeTbrgDAnFGqyQGrR4XnelQzGRhWiYk3zTFPZ84tGmhygbIDuVGpvCBWmcRsDF1AtDI4KrVSDyLdfpV1yASQeiQIetSe6sL9cg5kTd6xKeUG5K8wDKS5boDnrCkm6GdH/1pfu8o7y/n6kDmoP6Uc/WsrF1LXjPUcO5K0VC/FnRByG1EnCQNCVdJzMQjMOnNbGYcgqtgajGLPoTkbNBTEaMX8Bda7qrDz3s+ieJbap8T1ITDdHAhKOBJUJHWwn7glEHIAy8n3uyOcMg3PPJJIM1yMkg== 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=l8PPfUWthEPTqDD9fJLNCDnNJ5hDPkRTr6hAUOo7EyM=; b=m9g0mZXaEsczzRZ+RzleJ2/FMIGfu53aPnjiUN21W698LeYM8Yk7xwE/Fu+2ZIa53lEt2Tmj9tr5KKbdGhnKFL1KFOugDN/Z7SZGqkjnL10tnz8wLsiIM4mg2zmzSs/q7m0kUKkacFA3sJhwzbK6IVIGTlhCza5WzYsDlkRO04U= Received: from BYAPR12MB3158.namprd12.prod.outlook.com (20.179.92.19) by BYAPR12MB2965.namprd12.prod.outlook.com (20.178.52.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2178.18; Mon, 19 Aug 2019 21:36:06 +0000 Received: from BYAPR12MB3158.namprd12.prod.outlook.com ([fe80::39b9:76bd:a491:1f27]) by BYAPR12MB3158.namprd12.prod.outlook.com ([fe80::39b9:76bd:a491:1f27%6]) with mapi id 15.20.2157.022; Mon, 19 Aug 2019 21:36:06 +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 , "Singh, Brijesh" Subject: [RFC PATCH 14/28] UefiCpuPkg/CpuExceptionHandler: Add support for MSR_PROT NAE events Thread-Topic: [RFC PATCH 14/28] UefiCpuPkg/CpuExceptionHandler: Add support for MSR_PROT NAE events Thread-Index: AQHVVtYbEJO7Or2++E2fcfgP9XzNPQ== Date: Mon, 19 Aug 2019 21:36:05 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.17.1 x-clientproxiedby: SN2PR01CA0031.prod.exchangelabs.com (2603:10b6:804:2::41) To BYAPR12MB3158.namprd12.prod.outlook.com (2603:10b6:a03:132::19) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [165.204.77.1] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 233f992d-41de-42a3-7553-08d724ed3daa x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(4618075)(2017052603328)(7193020);SRVR:BYAPR12MB2965; x-ms-traffictypediagnostic: BYAPR12MB2965: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6790; x-forefront-prvs: 0134AD334F x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(4636009)(346002)(366004)(376002)(396003)(136003)(39860400002)(189003)(199004)(50226002)(53936002)(316002)(5660300002)(2351001)(52116002)(76176011)(36756003)(6436002)(71200400001)(19627235002)(6512007)(7736002)(256004)(86362001)(14454004)(478600001)(305945005)(2906002)(71190400001)(2501003)(64756008)(186003)(118296001)(4326008)(26005)(6486002)(99286004)(1730700003)(386003)(6506007)(66066001)(66476007)(66556008)(8676002)(102836004)(81166006)(25786009)(66446008)(6916009)(54906003)(3846002)(6116002)(486006)(5640700003)(476003)(2616005)(11346002)(446003)(81156014)(66946007)(8936002);DIR:OUT;SFP:1101;SCL:1;SRVR:BYAPR12MB2965;H:BYAPR12MB3158.namprd12.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: amd.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: aTzD8ODIoXvBn0DHJBYTjL67bEUgwUK6qOAL7U6sh7waK/F/MKxMhzpmdMrjCeZakf8RkxpmSCwiXACOj7uhnoA1b1yfljYuVq+CmgbIj1OqSZ29vl389MI0XIODhTA6r3AeQr+9jt9aEvWC+CXuyQE+w9tYfUb25bSbovHutBjF22HYBiHgD92NOc0rzMH//paiaxxosqQtu+GzCCvaHUTjxvM94Zbz8nMTCC6g/DFk2kFA5l9FhB5BqFd6bLVrYlDKoUYTDzps2WTQXvsHwzED49Cbbuq3m0HHlpkTxftor/ReCWDyvzp2XKHBkVYiJIUvWMxK0yWTtlYeJRexwk/nRJGz4HOuFQM277MAKmXO8DdfZ7zmu8VZ/7qLpRihsOmknrsNMcNrusdY0UWa1FSYyNupEGlOPRVLe/r0gHI= MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 233f992d-41de-42a3-7553-08d724ed3daa X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Aug 2019 21:36:05.9173 (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: h3VrAIGHD/LeHGV0ixUxk/7HfD4F/dtCsR4d5HyNGbvHu7c3KBRV//qRwTs7Gv1qbFqes2H7Xy3m9DK1wbFMcw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB2965 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-ID: <6D8112E1B147444696294A3AC6B59E7F@namprd12.prod.outlook.com> Content-Transfer-Encoding: quoted-printable From: Tom Lendacky 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. Signed-off-by: Tom Lendacky --- .../X64/AMDSevVcCommon.c | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c= b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c index 66cd0f9eb196..2b25919ea496 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c @@ -251,6 +251,54 @@ UnsupportedExit ( return Status; } =20 +STATIC +UINTN +MsrExit ( + GHCB *Ghcb, + EFI_SYSTEM_CONTEXT_X64 *Regs, + SEV_ES_INSTRUCTION_DATA *InstructionData + ) +{ + UINT64 ExitInfo1; + UINTN 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); + /* Fallthrough */ + case 0x32: // RDMSR + Ghcb->SaveArea.Rcx =3D Regs->Rcx; + GhcbSetRegValid (Ghcb, GhcbRcx); + break; + default: + VmgExit (Ghcb, SvmExitUnsupported, SvmExitMsr, 0); + ASSERT (0); + } + + Status =3D VmgExit (Ghcb, SvmExitMsr, ExitInfo1, 0); + if (Status) { + return Status; + } + + if (!ExitInfo1) { + if (!GhcbIsRegValid (Ghcb, GhcbRax) || + !GhcbIsRegValid (Ghcb, GhcbRdx)) { + VmgExit (Ghcb, SvmExitUnsupported, SvmExitMsr, 0); + ASSERT (0); + } + Regs->Rax =3D Ghcb->SaveArea.Rax; + Regs->Rdx =3D 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) @@ -538,6 +586,10 @@ DoVcCommon ( NaeExit =3D IoioExit; break; =20 + case SvmExitMsr: + NaeExit =3D MsrExit; + break; + default: NaeExit =3D UnsupportedExit; } --=20 2.17.1