From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (NAM11-DM6-obe.outbound.protection.outlook.com [40.107.223.67]) by mx.groups.io with SMTP id smtpd.web11.10146.1594213635813465663 for ; Wed, 08 Jul 2020 06:07:16 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector2-amdcloud-onmicrosoft-com header.b=XqDq5WfQ; spf=none, err=SPF record not found (domain: amd.com, ip: 40.107.223.67, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fvQL3W/9MZL4if/GmPdVQPFTz4nnzFGE/jIUBGMEAzMEs79vW9lXj7p/r37kDP6K3ZgBojY0K+9RR32ISgBIcGBqsn0Bh0cNAnXBU5DZf5Vfg5thxBnarudoLzZOyOEtfPPg5Ymo5AOvzR8v3AaMUu3TXDwSVBUPATODTcB9AKeZmb3Q6jJVWYCrVGxRWeyHTlwn2JkjtY6Okk/fxdLeV1VjbuSQrX7U827U63vk+6sUCd/UHbGGIUR9fiAbJZH2aAI0R5a2gsualEFpocK56dax/abrE1u6RSiiJ18iKcDSnRlB8yX17PF0xU+Kl3QTGFblMSvSCv8JhOGmcqo3pw== 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=RiWvtxJ2FMj3dxAxq/v2SMYkVHiwvCZuzSU4LaQh8Yo=; b=bEgPkxd+Pj/NPIx7XfvL3x2g/BcJL0ZfONQPwWyeqWDfhDWbpcyaSncjCBPT5dtahXF8PFf5txUQHBjainyUFumc3T0e9Owu0+7/C3+lZEpbkzX5gTMY2yPeXUoIun4Wnac+qX67Mwa4eBAhGSPip7Gj8XV4mVw3Zhq1TcmNQLoPDVPNDwMHUvKSIhOo64um/5nS1aFcyhhROmUCaCFa0TEJF9hatdmlVWlslLd+bjmwdsPIQl1ozkGwqoJ++03nu9T93CkVxUqenqox5pC4F3q4LCGCjM3NK8WKYwH+4oQs4Uby3j9MTqM8/2l7YH1v1FdMbCB4LWpxxoGHfThJ+A== 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=RiWvtxJ2FMj3dxAxq/v2SMYkVHiwvCZuzSU4LaQh8Yo=; b=XqDq5WfQjAD8ra1Pgin/Y99kMlcMoP3HRhGdSEeH3oAh6Zcx+zvXlnjrEFTkZVTvvVOvV26tKVO12enIxdKudVG4iMpV1S3LeycU5fxwSUQ/vuVYgHoxswzfRaVcKW3PvGb4j/az+gEAhdG4CocXwXn3/mURt1fiaur91sU3CeY= Authentication-Results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=amd.com; Received: from DM5PR12MB1355.namprd12.prod.outlook.com (2603:10b6:3:6e::7) by DM6PR12MB3372.namprd12.prod.outlook.com (2603:10b6:5:11b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3153.28; Wed, 8 Jul 2020 13:07:14 +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.021; Wed, 8 Jul 2020 13:07:14 +0000 Subject: Re: [edk2-devel] [PATCH v9 08/46] UefiCpuPkg: Implement library support for VMGEXIT From: "Lendacky, Thomas" To: Laszlo Ersek , "Dong, Eric" , "devel@edk2.groups.io" Cc: Brijesh Singh , Ard Biesheuvel , "Justen, Jordan L" , "Gao, Liming" , "Kinney, Michael D" , "Ni, Ray" References: <79f21141-07c6-d63f-7680-1ef08c53ecec@amd.com> <2d5f88ec-b3c4-8beb-dd60-68640f96b0da@amd.com> <9235cfe8-d9dc-4995-afee-681e96889f88@redhat.com> <4742c21f-19b6-b4c2-ea8c-fc15fbb8170b@amd.com> Message-ID: Date: Wed, 8 Jul 2020 08:07:12 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 In-Reply-To: X-ClientProxiedBy: DM5PR19CA0062.namprd19.prod.outlook.com (2603:10b6:3:116::24) 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 [10.236.30.118] (165.204.77.1) by DM5PR19CA0062.namprd19.prod.outlook.com (2603:10b6:3:116::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3174.21 via Frontend Transport; Wed, 8 Jul 2020 13:07:13 +0000 X-Originating-IP: [165.204.77.1] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 0280b31f-9878-449d-e75a-08d8233fd4fd X-MS-TrafficTypeDiagnostic: DM6PR12MB3372: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-Forefront-PRVS: 04583CED1A X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZI/d2r0Oq1u7BO8mpoRw8fG4Kld0fePje/ZlsEYvH5r489P8O9AlISfrH6zaBVn3JyYq8H2axn59YQUkByPNx+l+0nEyhb+Ugt7mtRrDniMeQ7KwwGpGBiCN+ABoJs5idxRxFz9aQ8xPkb8SHKosCvsb/QPxIdzUTwuU7VaJLD644bZqRPeEXwcyqpEauwaPjOnSBVyiTCPFjXE7nHJHJm/t5kzYrfOX87Q3h394GFw/x9ruhZEMtIMK5hg+BBY10GNM3jscnKFtDns65x1QBEX+Os6vhJ5xBstpc3OKNak495W+ookvHpZa3lZ2pWjawP9E87H9UIIP9itU3w0CoD06JZF5HpDYOEgHIh4mtLWgw4p2jIkCyA9Ou7JOG9FWUrGP8d7shmWm54QyUWt2rIMM6EVmdfk4FeDa+3iy/Ws/bFkvWhawzqgUqSoFA6z1 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)(366004)(396003)(136003)(376002)(39850400004)(346002)(45080400002)(6486002)(316002)(66476007)(66946007)(66556008)(83380400001)(478600001)(31686004)(5660300002)(966005)(54906003)(86362001)(53546011)(2906002)(19627235002)(8676002)(16576012)(52116002)(16526019)(2616005)(186003)(36756003)(110136005)(8936002)(31696002)(4326008)(956004)(26005)(43740500002)(460985005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: CYCnDWwNVKvOpRq8NcyeIHQfNTuB/qXqzIuT2Hvs7yIeTCHZYgMeewKlI5p/tKvQ4rVmhXtgDcnZh8AxNB33DCfKOk13xp1rhP5L2zTglwxKQXTbbvJhaZXlMbCA2Olaa+7ykHWW+U9o/FvlkpUD8zsMj/4WKci2wtZO4A697H088UsyW6CqwnG/3cRQcE41tcS4ndN9LnUytfterU5Tu9o3llnRiT/O7kdCdrK29qBbMlng+huTalTHqrZe/LF2xYIXgAm2gZdCZiwYrIC3ylpcNJOQdVx59GqE/c8UisM2Ji6mlfe/2m6STWiUheSucgirxqfZMQ8DaVmYN5eERYzb1fvg7uGYOkLigk6isPxahfIURMygf/4z1I0l/e4tnNmQg4zQb8SLcYZiRjrDp3tUl3Nr/9YcNzh/KjX33C5oo4ljmuDHlKrj9dBmv3AkI2NbV2r1bPOCPDB8Q5msaL4uOvYWBaQO/tNdIMIAQ9s= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0280b31f-9878-449d-e75a-08d8233fd4fd X-MS-Exchange-CrossTenant-AuthSource: DM5PR12MB1355.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jul 2020 13:07:13.9025 (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: v42esYZeCeWvTpOCNFpLtSrOvvhLvh2gyYtImBoniv5w21ZlKfOIrMi8XnuYaL4zo19ppDvwxmmEuhDPmNouvg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3372 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 7/7/20 12:11 PM, Tom Lendacky wrote: > On 7/7/20 10:50 AM, Tom Lendacky wrote: >> On 7/7/20 10:36 AM, Laszlo Ersek wrote: >>> On 07/06/20 22:03, Tom Lendacky wrote: >>>> On 7/2/20 2:04 AM, Dong, Eric wrote: >>>>> Hi Tom, >>>> >>>> Hi Eric, >>>> >>>>> >>>>> We have root cause this Mac file format issue. The patch mail from your side include extra two "=0D=0D" , and our test tool convert them to "\r\r". This is Mac file line ending format. So this issue been reported. We have updated our tool to handle this special case. >>>> >>>> Good to know, thanks! >>>> >>>>> >>>>> With that change, now I met below error when use VS2015 tool chain. Can you help to fix it? >>>>> >>>>> Building ... g:\edk2-open-source\edk2\MdePkg\Library\PeiCoreEntryPoint\PeiCoreEntryPoint.inf [X64] >>>>> PeCoffLoaderEx.c >>>>> g:\edk2-open-source\edk2\OvmfPkg\Library\VmgExitLib\VmgExitVcHandler.c(386): warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?) >>>>> NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Vc\bin\x86_amd64\cl.exe"' : return code '0x2' >>> >>> This is for the line >>> >>> Displacement *= (1 << Ext->Sib.Scale); >>> >>> from >>> >>> [edk2-devel] [PATCH v9 17/46] >>> OvmfPkg/VmgExitLib: Add support for NPF NAE events (MMIO) >>> >>>> >>>> Yup, looks like that needs to be a "1ULL <<" instead of "1 <<". >>>> I have verified that fixes the issue. >>> >>> I disagree. >>> >>> At that point, Displacement is of type INT64, and it may well be a >>> negative value. We definitely want to multiply it by a signed int >>> (values 1, 2, 4, 8). >>> >>> I commented on this before. Please see: >>> >>> (i) my comment block (10) here -- especially comment (10c): >>> >>> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fedk2.groups.io%2Fg%2Fdevel%2Fmessage%2F60144&data=02%7C01%7Cthomas.lendacky%40amd.com%7Cec0cb2ad96694b66d8ff08d8228b7c8e%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637297329772337705&sdata=g%2BGooY1Sv0G7ydr11Jh%2BTXxo4Wy6ZWcT5Mq9VmWddi8%3D&reserved=0 >>> >>> (alternative link: >>> ) >>> >>> (ii) and my comment here: >>> >>> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fedk2.groups.io%2Fg%2Fdevel%2Fmessage%2F60146&data=02%7C01%7Cthomas.lendacky%40amd.com%7Cec0cb2ad96694b66d8ff08d8228b7c8e%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637297329772337705&sdata=iNIBJCIlfEEsY37cdwUbH27tx5HvXVs3PZiOQfaGeLQ%3D&reserved=0 >>> >>> (alternative link: >>> ). >>> >>> >>> The compiler warning is well-meaning, but unnecessary. A 64-bit shift is >>> *NOT* intended. We want to end up with one of the signed int (aka INT32) >>> values 1, 2, 4 or 8. And then multiply the INT64 Displacement with that >>> value. For the multiplication, the INT32 value 1, 2, 4 or 8 will be >>> implicitly converted to INT64. That's entirely intentional. >>> >>> If we want to suppress the warning, while keeping the logic intact, we >>> should employ an explicit cast: >>> >>> Displacement *= (INT64)(1 << Ext->Sib.Scale); >> >> Ok, that makes sense. I'll use the explicit cast. >> >>> >>>> >>>> One thing I noticed is that the 32-bit builds >>>> (PlatformCI_OvmfPkg_Windows_VS2019_PR, Platform_CI OVMF_IA32_NOOPT and >>>> Platform_CI OVMF_IA32X64_NOOPT) encounter an error: >>>> >>>> ERROR - Linker #2001 from SecMain.lib(SecMain.obj) : unresolved external symbol __allshl >>>> ERROR - Linker #1120 from d:\a\1\s\Build\Ovmf3264\NOOPT_VS2019\IA32\OvmfPkg\Sec\SecMain\DEBUG\SecMain.dll : fatal 1 unresolved externals >>>> ERROR - Compiler #1077 from NMAKE : fatal '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.26.28801\bin\Hostx86\x86\link.exe"' : return code '0x460' >>>> >>>> Any idea what is causing this error? >>> >>> A left-shift operator (<<) applied to a 64-bit operand is somehow >>> finding its way into the 32-bit SEC build. >>> >>> That is indeed wrong (for such cases, we're supposed to use LShiftU64() >>> from BaseLib). >>> >>> What I don't understand however is that all of the "<<" operator uses, >>> on 64-bit operands, should already be limited to code that is *only* >>> built for X64! >>> >>> For example, with this series applied, SecMain in OVMF consumes >>> "UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib.inf". >>> And the latter consumes VmgExitLib. >>> >>> But VmgExitLib is resolved to >>> "UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf", in the IA32 and >>> IA32X64 DSC files. This Null instance contains no left-shifts. >>> >>> Therefore any << operators, applied to 64-bit operands, present in >>> "OvmfPkg/Library/VmgExitLib", should never be compiled for IA32 and IA32X64. >>> >>> So I don't know where the problematic "<<" comes from. It does not come >>> from VmgExitLib, as far as I can tell. >> >> Yes, I don't think it's coming from VmgExitLib, either. >> >> I wonder if it somehow might be coming from the MSR_SEV_ES_GHCB_REGISTER >> struct and the bit fields that are used within it? That code, while not >> executed in non-X64 builds because SEV-ES is not active, is still built >> and maybe the bit fields result in implicit shifts occurring, specifically >> in SevEsProtocolFailure()? >> >> I'll experiment with some things and see if that is the issue. > > I commented out the setting of the GhcbTerminate fields in the > SevEsProtocolFailure() routine of OvmfPkg/Sec/SecMain.c and the error > disappeared. I'll see if changing from using UINT64 to multiple UINT32 > entries fixes the problem, but I wouldn't think that the bit fields > would/should cause an issue here with 32-bit builds. Changing the bit fields from UINT64 to UINT32 fixed the error and SEV-ES support continues to function properly. Since the architecture is little endian, there was no need to pad out to the full UINT64 size for the structs (the union takes care of that in general). The change looks like this: diff --git a/MdePkg/Include/Register/Amd/Fam17Msr.h b/MdePkg/Include/Register/Amd/Fam17Msr.h index 466a3143599c..3cbe593868d4 100644 --- a/MdePkg/Include/Register/Amd/Fam17Msr.h +++ b/MdePkg/Include/Register/Amd/Fam17Msr.h @@ -28,7 +28,7 @@ **/ typedef union { struct { - UINT64 Function:12; + UINT32 Function:12; } GhcbInfo; struct { @@ -39,9 +39,9 @@ typedef union { } GhcbProtocol; struct { - UINT64 Function:12; - UINT64 ReasonCodeSet:4; - UINT64 ReasonCode:8; + UINT32 Function:12; + UINT32 ReasonCodeSet:4; + UINT32 ReasonCode:8; } GhcbTerminate; VOID *Ghcb; Unless there are any concerns, I'll incorporate this change. Thanks, Tom > > Thanks, > Tom > >> >> Thanks, >> Tom >> >>> >>> Thanks, >>> Laszlo >>>