From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.66]) by mx.groups.io with SMTP id smtpd.web10.10763.1591363687747704445 for ; Fri, 05 Jun 2020 06:28:07 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=aGFOPS2l; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.243.66, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K4i0IOxicCDGF81SGwt1n0ilCr3MJ+W6MWKkr6YN05RQOqtxP38zLDv/WcDcpwVN5R+pd+u4dr0lWP5cM4Z9iT8tQ+kMezUd1tJ0wEXsjPsXxZlMQ8d5JI1RNOUd8B2Xn96oC5xtiXxxBD4GGPWxmYEReuaHuCWsym3vlU0yCv9kZHAaNx9YgzBl6jPxj2kKnXoGo0R4Qjql7wMMfF40cTjL9IhO9ce8PQzog2iYrH8tLfYxmmwT2hJTV2HptOLyoRwOUK/hi/bY5R2LcWMn/fRp/FkHiCoTFEmS76QuuBsAqx0fHHInKmXND1TlvSi/oSacwIkE9AXb7vNFLm6cyA== 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=y8MXdKoHZ001yRfb9SYbkzZGA1UfJhJtdxfq8P4MA7I=; b=DjcuYzHbKa8ClmzL2wVeNMj7g0Ij50VzQUmWxklJK707WorCkICbPzDSAjl7ffIWj6Oe8HBKoXGmVATC/ska7eIPS/Kmq7ajgXs1zILkQt2g3npkrXzO3SlzoE5xg3lwc2o92hRxl2pbz7SZnm9KkmYvHTwuYD0znHwbfAEd3V0kPnvblXfHUMm9AnyfuWbfHDHAe+jEjEQNCNRiWdXWkAXgqIRfnylcvDVOUy5TCavMbfo17ONaA41jC6SAMh9QuroIeJjSL2uKV5pRevYhJpNF0gHohx/52SrTmaGXKAjYljddU8T7dpmLJWPvA8O9wWghv7aTGwLMZwBHkg3gvw== 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=y8MXdKoHZ001yRfb9SYbkzZGA1UfJhJtdxfq8P4MA7I=; b=aGFOPS2lJs7AQnAPh/9f+GZfQ06DI3ve6iIkP5EEf9LCkozo7gsIA+iz8jMdI/NHzlsIwBmxzilgSn2ymBDRxjhRUosF7+Akfz3ldL0FLEIEc46rwRS2vi8eKGJg1EbWhvIlZDzqmzvuPmeuE28m+oYmDy4JNwfcS7F/PYBDifA= 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 DM5PR12MB1354.namprd12.prod.outlook.com (2603:10b6:3:7a::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.20; Fri, 5 Jun 2020 13:28:06 +0000 Received: from DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1]) by DM5PR12MB1355.namprd12.prod.outlook.com ([fe80::4ce1:9947:9681:c8b1%10]) with mapi id 15.20.3066.019; Fri, 5 Jun 2020 13:28:06 +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 v9 17/46] OvmfPkg/VmgExitLib: Add support for NPF NAE events (MMIO) Date: Fri, 5 Jun 2020 08:27:08 -0500 Message-Id: <2eeee73d6f93964ed098f367850267b092100bde.1591363657.git.thomas.lendacky@amd.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-ClientProxiedBy: DM5PR19CA0060.namprd19.prod.outlook.com (2603:10b6:3:116::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 DM5PR19CA0060.namprd19.prod.outlook.com (2603:10b6:3:116::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.18 via Frontend Transport; Fri, 5 Jun 2020 13:28:05 +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: 55823cc7-d742-4f80-0eed-08d8095447b5 X-MS-TrafficTypeDiagnostic: DM5PR12MB1354: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-Forefront-PRVS: 0425A67DEF X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: b5MoRcwAIW0Klr8BOOi5WIqh8ncDI8/H1SdRFQenUtU7+cn66MSvZavNo2VWJI1xnbq6lnc5DszvUvqBrSEQBosof4i/Wl+0/bkkQPcjBhG0pFtNVBpw84ouTSSvP51B5yNmrD9OHx2XFcdqHqplpZ98tP1mfLAnDvuvPed4ulRL34FLiOl6nWAJrQWVIfIcuvkorKYplyjAjl0OMtuGQmHpYhbflZMNRrpeTc8rPrVypBQUwyMz6GFa/1scW0amOuNWRGGjUh5afecto3Q036dicojSWciv6i2hGHW+BHCA/RseiFBGS+Fe61AG5jk7Y1xwZjcmQXKo5feRiJD/SsLjT8rLN8omHQkF60xKwVwpDli5MCssqqkrx1PZHrOkQS0iy6P0v1p/otNt2B8DUaNC+l9W5K77NsmYcXG8q0tDmeJt67HnWoMOV4DAPAt7LDDpbcl05bX8XxjXpMZewA== 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)(346002)(39860400002)(376002)(366004)(396003)(136003)(30864003)(52116002)(83380400001)(26005)(316002)(7696005)(54906003)(6486002)(478600001)(956004)(16526019)(86362001)(4326008)(36756003)(2616005)(966005)(6916009)(2906002)(8936002)(5660300002)(8676002)(66476007)(66946007)(66556008)(186003)(136400200001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: gyJDhtyCONW6HBgT3TbZP9bvvli8dwrLj/3v6/nrIQWhMeg/Je+urMsNwd4xehTR1nweLjKFU2nsvifJWr8SNtqRLwwVm4YQqU/7EjeHbE1HfHdr6YMcuzqvJuwba5/aKg9Mpzyw2o7fTQcqdk+hQNur6n4f1f1wPGTg/yXGVm3sfUf5dncOUWzNHPEFd46F0g+zKDWwIhrKHnhJ/FlQGpoU7JDRF7rKsf0Va/oSby7Tfmb5biXQ2rzyW0nFYHNLBnrQq+H8vvCZn1K/abdr1gBEUox7YsXWMJVdvtXqb9XSasB3Y4po6WQupe1fF1dFHB+drY9W5ZqdH22K0MOKxjVGOXbmjxiOgWUUVOyxeTbqljyufUZVThxFnxlGxYN8qQo/FsYCyMViHoxF/92ba97joZ6sptqQnn/tavHvok+xtyw4kmqaGGybyIPyu9SmZP1mmuYRkaGJpJfjNbYSjZYJdGSp8zplWvTJdPIlll0= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 55823cc7-d742-4f80-0eed-08d8095447b5 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jun 2020 13:28:06.0405 (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: pBjLkW44oNzKVWUVm+Zq9ZBSVY965JreqbI+6PWPliod/pcRRPoeUsGTK2fzaQ7dSR0BOTTlVJJAONBSs5imtQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB1354 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2198 Under SEV-ES, a NPF intercept for an NPT entry with a reserved bit set generates a #VC exception. This condition is assumed to be an MMIO access. VMGEXIT must be used to allow the hypervisor to handle this intercept. Add support to construct the required GHCB values to support a NPF NAE event for MMIO. Parse the instruction that generated the #VC exception, setting the required register values in the GHCB and creating the proper SW_EXIT_INFO1, SW_EXITINFO2 and SW_SCRATCH values in the GHCB. Cc: Jordan Justen Cc: Laszlo Ersek Cc: Ard Biesheuvel Signed-off-by: Tom Lendacky --- OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c | 484 ++++++++++++++++++++ 1 file changed, 484 insertions(+) diff --git a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c b/OvmfPkg/Librar= y/VmgExitLib/VmgExitVcHandler.c index 009eb48cd468..c2646d45506a 100644 --- a/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c +++ b/OvmfPkg/Library/VmgExitLib/VmgExitVcHandler.c @@ -183,6 +183,279 @@ GhcbSetRegValid ( Ghcb->SaveArea.ValidBitmap[RegIndex] |=3D (1 << RegBit);=0D }=0D =0D +/**=0D + Return a pointer to the contents of the specified register.=0D +=0D + Based upon the input register, return a pointer to the registers content= s=0D + in the x86 processor context.=0D +=0D + @param[in] Regs x64 processor context=0D + @param[in] Register Register to obtain pointer for=0D +=0D + @return Pointer to the contents of the requested register=0D +=0D +**/=0D +STATIC=0D +UINT64 *=0D +GetRegisterPointer (=0D + IN EFI_SYSTEM_CONTEXT_X64 *Regs,=0D + IN UINT8 Register=0D + )=0D +{=0D + UINT64 *Reg;=0D +=0D + switch (Register) {=0D + case 0:=0D + Reg =3D &Regs->Rax;=0D + break;=0D + case 1:=0D + Reg =3D &Regs->Rcx;=0D + break;=0D + case 2:=0D + Reg =3D &Regs->Rdx;=0D + break;=0D + case 3:=0D + Reg =3D &Regs->Rbx;=0D + break;=0D + case 4:=0D + Reg =3D &Regs->Rsp;=0D + break;=0D + case 5:=0D + Reg =3D &Regs->Rbp;=0D + break;=0D + case 6:=0D + Reg =3D &Regs->Rsi;=0D + break;=0D + case 7:=0D + Reg =3D &Regs->Rdi;=0D + break;=0D + case 8:=0D + Reg =3D &Regs->R8;=0D + break;=0D + case 9:=0D + Reg =3D &Regs->R9;=0D + break;=0D + case 10:=0D + Reg =3D &Regs->R10;=0D + break;=0D + case 11:=0D + Reg =3D &Regs->R11;=0D + break;=0D + case 12:=0D + Reg =3D &Regs->R12;=0D + break;=0D + case 13:=0D + Reg =3D &Regs->R13;=0D + break;=0D + case 14:=0D + Reg =3D &Regs->R14;=0D + break;=0D + case 15:=0D + Reg =3D &Regs->R15;=0D + break;=0D + default:=0D + Reg =3D NULL;=0D + }=0D + ASSERT (Reg !=3D NULL);=0D +=0D + return Reg;=0D +}=0D +=0D +/**=0D + Update the instruction parsing context for displacement bytes.=0D +=0D + @param[in, out] InstructionData Instruction parsing context=0D + @param[in] Size The instruction displacement size=0D +=0D +**/=0D +STATIC=0D +VOID=0D +UpdateForDisplacement (=0D + IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData,=0D + IN UINTN Size=0D + )=0D +{=0D + InstructionData->DisplacementSize =3D Size;=0D + InstructionData->Immediate +=3D Size;=0D + InstructionData->End +=3D Size;=0D +}=0D +=0D +/**=0D + Determine if an instruction address if RIP relative.=0D +=0D + Examine the instruction parsing context to determine if the address offs= et=0D + is relative to the instruction pointer.=0D +=0D + @param[in] InstructionData Instruction parsing context=0D +=0D + @retval TRUE Instruction addressing is RIP relative=0D + @retval FALSE Instruction addressing is not RIP relative=0D +=0D +**/=0D +STATIC=0D +BOOLEAN=0D +IsRipRelative (=0D + IN SEV_ES_INSTRUCTION_DATA *InstructionData=0D + )=0D +{=0D + SEV_ES_INSTRUCTION_OPCODE_EXT *Ext;=0D +=0D + Ext =3D &InstructionData->Ext;=0D +=0D + return ((InstructionData->Mode =3D=3D LongMode64Bit) &&=0D + (Ext->ModRm.Mod =3D=3D 0) &&=0D + (Ext->ModRm.Rm =3D=3D 5) &&=0D + (InstructionData->SibPresent =3D=3D FALSE));=0D +}=0D +=0D +/**=0D + Return the effective address of a memory operand.=0D +=0D + Examine the instruction parsing context to obtain the effective memory=0D + address of a memory operand.=0D +=0D + @param[in] Regs x64 processor context=0D + @param[in] InstructionData Instruction parsing context=0D +=0D + @return The memory operand effective address=0D +=0D +**/=0D +STATIC=0D +UINT64=0D +GetEffectiveMemoryAddress (=0D + IN EFI_SYSTEM_CONTEXT_X64 *Regs,=0D + IN SEV_ES_INSTRUCTION_DATA *InstructionData=0D + )=0D +{=0D + SEV_ES_INSTRUCTION_OPCODE_EXT *Ext;=0D + UINT64 EffectiveAddress;=0D +=0D + Ext =3D &InstructionData->Ext;=0D + EffectiveAddress =3D 0;=0D +=0D + if (IsRipRelative (InstructionData)) {=0D + //=0D + // RIP-relative displacement is a 32-bit signed value=0D + //=0D + INT32 RipRelative;=0D +=0D + RipRelative =3D *(INT32 *) InstructionData->Displacement;=0D +=0D + UpdateForDisplacement (InstructionData, 4);=0D +=0D + //=0D + // Negative displacement is handled by standard UINT64 wrap-around.=0D + //=0D + return Regs->Rip + (UINT64) RipRelative;=0D + }=0D +=0D + switch (Ext->ModRm.Mod) {=0D + case 1:=0D + UpdateForDisplacement (InstructionData, 1);=0D + EffectiveAddress +=3D (UINT64) (*(INT8 *) (InstructionData->Displaceme= nt));=0D + break;=0D + case 2:=0D + switch (InstructionData->AddrSize) {=0D + case Size16Bits:=0D + UpdateForDisplacement (InstructionData, 2);=0D + EffectiveAddress +=3D (UINT64) (*(INT16 *) (InstructionData->Displac= ement));=0D + break;=0D + default:=0D + UpdateForDisplacement (InstructionData, 4);=0D + EffectiveAddress +=3D (UINT64) (*(INT32 *) (InstructionData->Displac= ement));=0D + break;=0D + }=0D + break;=0D + }=0D +=0D + if (InstructionData->SibPresent) {=0D + INT64 Displacement;=0D +=0D + if (Ext->Sib.Index !=3D 4) {=0D + CopyMem (&Displacement,=0D + GetRegisterPointer (Regs, Ext->Sib.Index),=0D + sizeof (Displacement));=0D + Displacement *=3D (1 << Ext->Sib.Scale);=0D +=0D + //=0D + // Negative displacement is handled by standard UINT64 wrap-around.= =0D + //=0D + EffectiveAddress +=3D (UINT64) Displacement;=0D + }=0D +=0D + if ((Ext->Sib.Base !=3D 5) || Ext->ModRm.Mod) {=0D + EffectiveAddress +=3D *GetRegisterPointer (Regs, Ext->Sib.Base);=0D + } else {=0D + UpdateForDisplacement (InstructionData, 4);=0D + EffectiveAddress +=3D (UINT64) (*(INT32 *) (InstructionData->Displac= ement));=0D + }=0D + } else {=0D + EffectiveAddress +=3D *GetRegisterPointer (Regs, Ext->ModRm.Rm);=0D + }=0D +=0D + return EffectiveAddress;=0D +}=0D +=0D +/**=0D + Decode a ModRM byte.=0D +=0D + Examine the instruction parsing context to decode a ModRM byte and the S= IB=0D + byte, if present.=0D +=0D + @param[in] Regs x64 processor context=0D + @param[in, out] InstructionData Instruction parsing context=0D +=0D +**/=0D +STATIC=0D +VOID=0D +DecodeModRm (=0D + IN EFI_SYSTEM_CONTEXT_X64 *Regs,=0D + IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData=0D + )=0D +{=0D + SEV_ES_INSTRUCTION_OPCODE_EXT *Ext;=0D + INSTRUCTION_REX_PREFIX *RexPrefix;=0D + INSTRUCTION_MODRM *ModRm;=0D + INSTRUCTION_SIB *Sib;=0D +=0D + RexPrefix =3D &InstructionData->RexPrefix;=0D + Ext =3D &InstructionData->Ext;=0D + ModRm =3D &InstructionData->ModRm;=0D + Sib =3D &InstructionData->Sib;=0D +=0D + InstructionData->ModRmPresent =3D TRUE;=0D + ModRm->Uint8 =3D *(InstructionData->End);=0D +=0D + InstructionData->Displacement++;=0D + InstructionData->Immediate++;=0D + InstructionData->End++;=0D +=0D + Ext->ModRm.Mod =3D ModRm->Bits.Mod;=0D + Ext->ModRm.Reg =3D (RexPrefix->Bits.BitR << 3) | ModRm->Bits.Reg;=0D + Ext->ModRm.Rm =3D (RexPrefix->Bits.BitB << 3) | ModRm->Bits.Rm;=0D +=0D + Ext->RegData =3D *GetRegisterPointer (Regs, Ext->ModRm.Reg);=0D +=0D + if (Ext->ModRm.Mod =3D=3D 3) {=0D + Ext->RmData =3D *GetRegisterPointer (Regs, Ext->ModRm.Rm);=0D + } else {=0D + if (ModRm->Bits.Rm =3D=3D 4) {=0D + InstructionData->SibPresent =3D TRUE;=0D + Sib->Uint8 =3D *(InstructionData->End);=0D +=0D + InstructionData->Displacement++;=0D + InstructionData->Immediate++;=0D + InstructionData->End++;=0D +=0D + Ext->Sib.Scale =3D Sib->Bits.Scale;=0D + Ext->Sib.Index =3D (RexPrefix->Bits.BitX << 3) | Sib->Bits.Index;=0D + Ext->Sib.Base =3D (RexPrefix->Bits.BitB << 3) | Sib->Bits.Base;=0D + }=0D +=0D + Ext->RmData =3D GetEffectiveMemoryAddress (Regs, InstructionData);=0D + }=0D +}=0D +=0D /**=0D Decode instruction prefixes.=0D =0D @@ -374,6 +647,213 @@ UnsupportedExit ( return Status;=0D }=0D =0D +/**=0D + Handle an MMIO event.=0D +=0D + Use the VMGEXIT instruction to handle either an MMIO read or an MMIO wri= te.=0D +=0D + @param[in, out] Ghcb Pointer to the Guest-Hypervisor Communi= cation=0D + Block=0D + @param[in, out] Regs x64 processor context=0D + @param[in, out] InstructionData Instruction parsing context=0D +=0D + @return 0 Event handled successfully=0D + @return Others New exception value to propagate=0D +=0D +**/=0D +STATIC=0D +UINT64=0D +MmioExit (=0D + IN OUT GHCB *Ghcb,=0D + IN OUT EFI_SYSTEM_CONTEXT_X64 *Regs,=0D + IN OUT SEV_ES_INSTRUCTION_DATA *InstructionData=0D + )=0D +{=0D + UINT64 ExitInfo1, ExitInfo2, Status;=0D + UINTN Bytes;=0D + UINT64 *Register;=0D + UINT8 OpCode, SignByte;=0D +=0D + Bytes =3D 0;=0D +=0D + OpCode =3D *(InstructionData->OpCodes);=0D + if (OpCode =3D=3D TWO_BYTE_OPCODE_ESCAPE) {=0D + OpCode =3D *(InstructionData->OpCodes + 1);=0D + }=0D +=0D + switch (OpCode) {=0D + //=0D + // MMIO write (MOV reg/memX, regX)=0D + //=0D + case 0x88:=0D + Bytes =3D 1;=0D + //=0D + // fall through=0D + //=0D + case 0x89:=0D + DecodeModRm (Regs, InstructionData);=0D + Bytes =3D ((Bytes !=3D 0) ? Bytes :=0D + (InstructionData->DataSize =3D=3D Size16Bits) ? 2 :=0D + (InstructionData->DataSize =3D=3D Size32Bits) ? 4 :=0D + (InstructionData->DataSize =3D=3D Size64Bits) ? 8 :=0D + 0);=0D +=0D + if (InstructionData->Ext.ModRm.Mod =3D=3D 3) {=0D + //=0D + // NPF on two register operands???=0D + //=0D + return UnsupportedExit (Ghcb, Regs, InstructionData);=0D + }=0D +=0D + ExitInfo1 =3D InstructionData->Ext.RmData;=0D + ExitInfo2 =3D Bytes;=0D + CopyMem (Ghcb->SharedBuffer, &InstructionData->Ext.RegData, Bytes);=0D +=0D + Ghcb->SaveArea.SwScratch =3D (UINT64) Ghcb->SharedBuffer;=0D + Status =3D VmgExit (Ghcb, SVM_EXIT_MMIO_WRITE, ExitInfo1, ExitInfo2);= =0D + if (Status !=3D 0) {=0D + return Status;=0D + }=0D + break;=0D +=0D + //=0D + // MMIO write (MOV reg/memX, immX)=0D + //=0D + case 0xC6:=0D + Bytes =3D 1;=0D + //=0D + // fall through=0D + //=0D + case 0xC7:=0D + DecodeModRm (Regs, InstructionData);=0D + Bytes =3D ((Bytes !=3D 0) ? Bytes :=0D + (InstructionData->DataSize =3D=3D Size16Bits) ? 2 :=0D + (InstructionData->DataSize =3D=3D Size32Bits) ? 4 :=0D + 0);=0D +=0D + InstructionData->ImmediateSize =3D Bytes;=0D + InstructionData->End +=3D Bytes;=0D +=0D + ExitInfo1 =3D InstructionData->Ext.RmData;=0D + ExitInfo2 =3D Bytes;=0D + CopyMem (Ghcb->SharedBuffer, InstructionData->Immediate, Bytes);=0D +=0D + Ghcb->SaveArea.SwScratch =3D (UINT64) Ghcb->SharedBuffer;=0D + Status =3D VmgExit (Ghcb, SVM_EXIT_MMIO_WRITE, ExitInfo1, ExitInfo2);= =0D + if (Status !=3D 0) {=0D + return Status;=0D + }=0D + break;=0D +=0D + //=0D + // MMIO read (MOV regX, reg/memX)=0D + //=0D + case 0x8A:=0D + Bytes =3D 1;=0D + //=0D + // fall through=0D + //=0D + case 0x8B:=0D + DecodeModRm (Regs, InstructionData);=0D + Bytes =3D ((Bytes !=3D 0) ? Bytes :=0D + (InstructionData->DataSize =3D=3D Size16Bits) ? 2 :=0D + (InstructionData->DataSize =3D=3D Size32Bits) ? 4 :=0D + (InstructionData->DataSize =3D=3D Size64Bits) ? 8 :=0D + 0);=0D + if (InstructionData->Ext.ModRm.Mod =3D=3D 3) {=0D + //=0D + // NPF on two register operands???=0D + //=0D + return UnsupportedExit (Ghcb, Regs, InstructionData);=0D + }=0D +=0D + ExitInfo1 =3D InstructionData->Ext.RmData;=0D + ExitInfo2 =3D Bytes;=0D +=0D + Ghcb->SaveArea.SwScratch =3D (UINT64) Ghcb->SharedBuffer;=0D + Status =3D VmgExit (Ghcb, SVM_EXIT_MMIO_READ, ExitInfo1, ExitInfo2);=0D + if (Status !=3D 0) {=0D + return Status;=0D + }=0D +=0D + Register =3D GetRegisterPointer (Regs, InstructionData->Ext.ModRm.Reg)= ;=0D + if (Bytes =3D=3D 4) {=0D + //=0D + // Zero-extend for 32-bit operation=0D + //=0D + *Register =3D 0;=0D + }=0D + CopyMem (Register, Ghcb->SharedBuffer, Bytes);=0D + break;=0D +=0D + //=0D + // MMIO read w/ zero-extension ((MOVZX regX, reg/memX)=0D + //=0D + case 0xB6:=0D + Bytes =3D 1;=0D + //=0D + // fall through=0D + //=0D + case 0xB7:=0D + Bytes =3D (Bytes !=3D 0) ? Bytes : 2;=0D +=0D + ExitInfo1 =3D InstructionData->Ext.RmData;=0D + ExitInfo2 =3D Bytes;=0D +=0D + Ghcb->SaveArea.SwScratch =3D (UINT64) Ghcb->SharedBuffer;=0D + Status =3D VmgExit (Ghcb, SVM_EXIT_MMIO_READ, ExitInfo1, ExitInfo2);=0D + if (Status !=3D 0) {=0D + return Status;=0D + }=0D +=0D + Register =3D GetRegisterPointer (Regs, InstructionData->Ext.ModRm.Reg)= ;=0D + SetMem (Register, InstructionData->DataSize, 0);=0D + CopyMem (Register, Ghcb->SharedBuffer, Bytes);=0D + break;=0D +=0D + //=0D + // MMIO read w/ sign-extension (MOVSX regX, reg/memX)=0D + //=0D + case 0xBE:=0D + Bytes =3D 1;=0D + //=0D + // fall through=0D + //=0D + case 0xBF:=0D + Bytes =3D (Bytes !=3D 0) ? Bytes : 2;=0D +=0D + ExitInfo1 =3D InstructionData->Ext.RmData;=0D + ExitInfo2 =3D Bytes;=0D +=0D + Ghcb->SaveArea.SwScratch =3D (UINT64) Ghcb->SharedBuffer;=0D + Status =3D VmgExit (Ghcb, SVM_EXIT_MMIO_READ, ExitInfo1, ExitInfo2);=0D + if (Status !=3D 0) {=0D + return Status;=0D + }=0D +=0D + if (Bytes =3D=3D 1) {=0D + UINT8 *Data =3D (UINT8 *) Ghcb->SharedBuffer;=0D +=0D + SignByte =3D ((*Data & BIT7) !=3D 0) ? 0xFF : 0x00;=0D + } else {=0D + UINT16 *Data =3D (UINT16 *) Ghcb->SharedBuffer;=0D +=0D + SignByte =3D ((*Data & BIT15) !=3D 0) ? 0xFF : 0x00;=0D + }=0D +=0D + Register =3D GetRegisterPointer (Regs, InstructionData->Ext.ModRm.Reg)= ;=0D + SetMem (Register, InstructionData->DataSize, SignByte);=0D + CopyMem (Register, Ghcb->SharedBuffer, Bytes);=0D + break;=0D +=0D + default:=0D + Status =3D GP_EXCEPTION;=0D + ASSERT (FALSE);=0D + }=0D +=0D + return Status;=0D +}=0D +=0D /**=0D Handle an MSR event.=0D =0D @@ -770,6 +1250,10 @@ VmgExitHandleVc ( NaeExit =3D MsrExit;=0D break;=0D =0D + case SVM_EXIT_NPF:=0D + NaeExit =3D MmioExit;=0D + break;=0D +=0D default:=0D NaeExit =3D UnsupportedExit;=0D }=0D --=20 2.27.0