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=x94g0UpF; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.76.50, mailfrom: thomas.lendacky@amd.com) Received: from NAM02-CY1-obe.outbound.protection.outlook.com (NAM02-CY1-obe.outbound.protection.outlook.com [40.107.76.50]) by groups.io with SMTP; Thu, 19 Sep 2019 12:52:52 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Zi2Tqzox2Tkf/Xff9efcqFf2FFn7yCZubRF6SyboSyTw5aCtWslwFyQEA4hY5dU3USktThtBOEPXqg7mfQO7YMNYAcnR3BMbF0vsCFjnyBJzeBSrYXIMzofv0mEf1A9H2TNdoCeH9++Led5J6h2DUJnQ1tEaIsSrQu/wYALWCjDuK1df3+oW0WhqCqf22/a7WnpEITlmO8bE2eR9ryZ0WovQ8Yf12UopWR7wXXgGW5gSy9Vo5isL/y6DvglSFjczMDWaJgsqifSViR1PlMS4ikgdKg/FzOuayND9JupaD1uIT9b6gbNHMEi9W+XPqjCI17DTJI4um+CeF0JICl4rBQ== 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=0FZE6GbvXuNTQ15XeXAtxjUk7TiNySG6RPQP2bjVSd0=; b=na4OKHgiJ0EOSg7fKjFmk8vi8X/rYf0yOVrlhMhlRhbnrG9t4MtwkFi/pviK3FgSH8KTLVqa2yRu12YosClxtz8mbj5ExqIw8YTajDCIULi3Z5vAX+zxZ3kMh2gRDgvk7Zt2GuGY2ImeMI1U6TudvS+nT0y/5wsKDgGn+C5XsfUo7sGvDzzUFEj/TXZUYrY2p/R1W1JFhbGyw++DVtEeCzY/yFJc+ME7iVO59DVHCmDoAD3BzKtlCMkOuRnnTajWxROxbqh+ZSm29siMaK6Z1njG8XH8ulbY32L/5BK+8l4gwQpUx2MMXCmdASalzvtyumF7E/FMOjeFNBV9Ks3wrQ== 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=0FZE6GbvXuNTQ15XeXAtxjUk7TiNySG6RPQP2bjVSd0=; b=x94g0UpF1XGQGJFtAcJxuNZxGtt2Wl3MnmUpCiV3Mo2RiNAJJPdLfEZVNCHnJEhMgZ3ERh7DoLoO5NWpVcHRWTdyHjuC1mmD9s4gH5Ub+dcgE+H1hdpaMiCYUBHjiRAW7J0iNYKPf0867PVOupe5y8BLH+rYRBbmmJLQwWGGajQ= Received: from DM6PR12MB3163.namprd12.prod.outlook.com (20.179.104.150) by DM6PR12MB3228.namprd12.prod.outlook.com (20.179.105.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2263.13; Thu, 19 Sep 2019 19:52:50 +0000 Received: from DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::400e:f0c3:7ca:2fcc]) by DM6PR12MB3163.namprd12.prod.outlook.com ([fe80::400e:f0c3:7ca:2fcc%6]) with mapi id 15.20.2284.009; Thu, 19 Sep 2019 19:52:50 +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 v2 23/44] UefiCpuPkg/CpuExceptionHandler: Add support for MSR_PROT NAE events Thread-Topic: [RFC PATCH v2 23/44] UefiCpuPkg/CpuExceptionHandler: Add support for MSR_PROT NAE events Thread-Index: AQHVbyPRGRB3SH6iw0G/RYA62qqL5w== Date: Thu, 19 Sep 2019 19:52:50 +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: SN4PR0501CA0146.namprd05.prod.outlook.com (2603:10b6:803:2c::24) To DM6PR12MB3163.namprd12.prod.outlook.com (2603:10b6:5:182::22) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Thomas.Lendacky@amd.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [165.204.78.1] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 3c416291-91f6-4290-04b0-08d73d3af3e6 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600167)(711020)(4605104)(1401327)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7193020);SRVR:DM6PR12MB3228; x-ms-traffictypediagnostic: DM6PR12MB3228: x-ms-exchange-purlcount: 1 x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6790; x-forefront-prvs: 016572D96D x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(4636009)(1496009)(366004)(376002)(396003)(136003)(39860400002)(346002)(189003)(199004)(4326008)(26005)(446003)(25786009)(52116002)(19627235002)(71200400001)(71190400001)(8936002)(81156014)(81166006)(256004)(8676002)(186003)(50226002)(2351001)(2616005)(102836004)(486006)(11346002)(476003)(66066001)(386003)(6506007)(66446008)(14454004)(76176011)(99286004)(6486002)(36756003)(5640700003)(66556008)(118296001)(3846002)(316002)(7736002)(2501003)(1730700003)(6116002)(5660300002)(478600001)(54906003)(6916009)(966005)(6436002)(2906002)(64756008)(305945005)(86362001)(6512007)(6306002)(66476007)(66946007);DIR:OUT;SFP:1101;SCL:1;SRVR:DM6PR12MB3228;H:DM6PR12MB3163.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: h90bW8g+FSgyFNi9o7wGRndNfnEDiDlbOkfZOVgkmTL92zdBjCIRidTnk4/VIEIMHsZHH5NGpJb9hshMQ/Kg0EUkm1hQrv5eDDScEbajAvynSdaH01y9K7NNLlZ6TvQYUVBdPB7e9OkibJL9+qPyKd924D7IQkr827FyYUHgRJhB4kf0fsLOObEhDDL/X0x5GkaGUZSWgIbu/9GPmFJ2Pe2DhoVFs6XKjQYsR27c+XDd4S2c6L4UObeBIS05HhqCyZqE6dB3DWlqFz3Nyv7Gh8BCaMKWQ9R/KMtL32roWu8GdK3Z4YzbhKAvP2COK6qvGUzZY0lRYZS0+Yo5QbYBAvChWRFHSmdXSCKzUYvzr72hPKN8hA9nJ10khqpvyZjrMQ8M8Ibgq5IJ7utf0Ap9spIx6LFlyGjWgVPQDNSgE54= MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3c416291-91f6-4290-04b0-08d73d3af3e6 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Sep 2019 19:52:50.8048 (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: rKhRL+dXiijS4/CbJn/orF7anOHE4HE4B+ylq7uxX5jYH5RwIxhN9akvg8p7S7tKmd8y60U3+qj/aj370mUvRA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3228 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-ID: <03A5C9DB0B9AE74F8046100CE67A4647@namprd12.prod.outlook.com> 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: Eric Dong Cc: Ray Ni Cc: Laszlo Ersek 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 29119ba863d3..748883419752 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/X64/AMDSevVcCommon.c @@ -278,6 +278,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) @@ -546,6 +594,10 @@ DoVcCommon ( NaeExit =3D IoioExit; break; =20 + case SvmExitMsr: + NaeExit =3D MsrExit; + break; + default: NaeExit =3D UnsupportedExit; } --=20 2.17.1