From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.51]) by mx.groups.io with SMTP id smtpd.web10.84.1681327543426740378 for ; Wed, 12 Apr 2023 12:25:43 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=zFieFcBJ; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.220.51, mailfrom: thomas.lendacky@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HVdCr16zI9myaOwrAwClsu7Q+HMMXCM2NjBVJBFr0mhNIPVlz+wkxlx1SN1/dv3QcuIWdmEjk8wosY6xkmJts308Ag/+2C4xrvPKTlnGTdKBN6aYvuYmI/+lQVz4nxji4iNnPCWQUzLzwSIltSQlLByduYsbhrdteEf56AixKn1fJEwCk+ispOkPVqUeONswZgNg+gOxVwpuYr0/ttDu5kT7wiGyk/rWk2ktIueQuYQD0EM5UWXOhhH2yukINpbb9Co/GpOIqc6Y2w6NPkqukMLflqWxGQPUt5Gr3jjSpTV6dOFaaxTm5V3wCpmVD1L6K2bptDl+9Y+DAlRYni1oxg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GIWCTIDnH3XC+AsitVSIvRutYYkUXgH9iQvRVUPA7WY=; b=PZi9d2VMJn5Ryd9Xsm/HTOdUZDDnA1ERQ9q6WhGjLaSy2L9wCBfunSfixqDs4axgz1tCIMaazg6DqLNh2721tQ+0M3I9N7bytryp2WIM//GoNjHuiOQ/2ca3rmx87fgcoHv4cc1ynGvqgOG6ImaP2rC8zq2loP+/itulibwsHwwIYYbWm/y6xaJ451+mc6Ur6IP1913nAUeE4DAhFbsN5pVtCrlMMlmroMH7bU53JSl2lKFoTGJFyD5B/9oCIx2rCFozecqHPBm7GKWEIjKs/l5yLV8LYj4UxGqRZ+8aB4bqWy0zRQdIQ3Dk9a6s2hz6TlyzeIxh34RIR/ZYcqvoBw== 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=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GIWCTIDnH3XC+AsitVSIvRutYYkUXgH9iQvRVUPA7WY=; b=zFieFcBJtADl4ZWuuk7FNJa6XV7zSLzdWjRbUSMzZasy6ZOkj/Kmx+7pw8BEN33Z6zz1cS2JByPHKWJD0sgAgAr95nebQ8SKMqBQ4N8xPutjWRNDc1puUusHp3RjMoMHzIQJdgjsh4tI4T+gZVzVvfH43x3Z7DTxIs9WyB17FXE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) by DS7PR12MB8291.namprd12.prod.outlook.com (2603:10b6:8:e2::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.31; Wed, 12 Apr 2023 19:25:41 +0000 Received: from DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::ea32:baf8:cc85:9648]) by DM4PR12MB5229.namprd12.prod.outlook.com ([fe80::ea32:baf8:cc85:9648%6]) with mapi id 15.20.6298.030; Wed, 12 Apr 2023 19:25:41 +0000 Message-ID: <2301e275-1f69-e5c0-997d-d967264aa590@amd.com> Date: Wed, 12 Apr 2023 14:25:38 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [edk2-devel] [Patch V2 0/8] Use CpuPageTableLib to create and update smm page table To: devel@edk2.groups.io, dun.tan@intel.com References: <1755241E6695EAE7.1885@groups.io> From: "Lendacky, Thomas" In-Reply-To: X-ClientProxiedBy: MN2PR14CA0029.namprd14.prod.outlook.com (2603:10b6:208:23e::34) To DM4PR12MB5229.namprd12.prod.outlook.com (2603:10b6:5:398::12) Return-Path: Thomas.Lendacky@amd.com MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR12MB5229:EE_|DS7PR12MB8291:EE_ X-MS-Office365-Filtering-Correlation-Id: 0f5dcbbb-9fde-4758-a9fb-08db3b8bb422 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kBmayzRtUNofBgSbMMl0SgWCvCkpAiKGStCP+2NhbAVeqK4uW9VxO8/g/S2wXfzOMm9i8D0j8ZaBG2rlS6PZD7CQchqa7HnORzjzrZ8FteCgI+yI1blYVEFHJ6CJjAyiEQ28zXEfy4dmxyxgRDtWVlxcDV8pDQhBnH8qPb7IveDbr4e/Nx4fNl4j19EHWF80twQw9ksozZ6BtfqMvFFjPJam9jSgRK1ryr7D14rfiqPOCRP9YQQouVY7GcPQHHceS99L64Ag9Osj9JsLSnxSRhxTlgzmp9b4rFuGTwrrtKwmo07Gfs6znN9OIXdAMFCpGl+EMvKMFqN6VkAkdZY1rEOky4R1kKq0TehRSNoCeM8rTA3ZOPBXqc/JxN0IgtcaobOi7BWN/cb3j2V3Av+RktXSgg9vU3kkct1ONa/SIumt2Igebb9SlrWGA70sGFsU260Aw9xwb5Dwqeg27TDC2JEa8RHgaYPmIdxc15j97nIOH9t7OSbRGi2dd/rSjQ/FGRHF1SC/dintmPJNv1iTaRtRyVsR3O4KUEQPXYEJVd9pEkwoUNldvfxRd3sjyQTf3dIbauqG+BhuehZEWYaIJ2JDoDYdfduncY9GVP1CDpNkzjo2+egGgj41U9mjV3RF X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR12MB5229.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(366004)(376002)(396003)(136003)(346002)(39860400002)(451199021)(2906002)(41300700001)(8676002)(66556008)(66476007)(8936002)(15650500001)(31686004)(5660300002)(66899021)(19627235002)(66946007)(83380400001)(478600001)(316002)(966005)(6486002)(53546011)(26005)(2616005)(6666004)(6512007)(36756003)(6506007)(38100700002)(186003)(31696002)(86362001)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?Q0VJaXFibjV6SWdVSUJ3cjQwMGpnNGJZNTVVdFc3K1lVSDNmOHhnbnFlUzVE?= =?utf-8?B?NW9tUXpQMTcyR1JMR0JqZy9KRHpYeW8zK2kyTXExeS8zeGROMXlQSU5BN1Nj?= =?utf-8?B?Wm9tNUtRN0t1NVI1QjFPMjVJcUkwdndCdDhvKzJMdUtUUHBvd1NWd0ppR0dX?= =?utf-8?B?U0JjczFiYjJkZ05JRlJuL0MzRVF3NEtrZmhERm04ZHdBbzF5N0M0SmdrSzdO?= =?utf-8?B?V0U3a0ZJalNzZzhFK2Jta05oaHpFS2h4Q3VSNzNJYlVVUW1lQWJaSHo1aVE0?= =?utf-8?B?eDd0Yk10ck9OTUwvUkNZUjdhcTVLQS9oN0hKVnI5Wm1mUlhzVUloYWVLQ3Fk?= =?utf-8?B?MVJDdC9KYW1WVEFTMDlrZGQ1Vy9tQlhEUi9MUXd4TEJ2REluRVc5UW1tcFBk?= =?utf-8?B?clRJdkJLUzV0K2FKSi8zYzJQa0lVUnVuL0g3aFVyc2VXbnluS0ZHcG1lckdM?= =?utf-8?B?WnVneGNpeGtNa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x?= =?utf-8?B?Tkd5a0JtakNXOGFZVmhXQ1RFNE54VlFNSmRWS3M5U3diUCtOTllibFY0ZkM3?= =?utf-8?B?TmVKNHVPeERjZ0ZBL1BLNHhucDA4TDdhOFY3c3U1WlF4RGhmeXRHbXc3MGtS?= =?utf-8?B?SkNCeVRKM09EK2hBZVdxRXVRN0VaeEdhdGdnTmRqZldDWllvOS8rWVRzMXcw?= =?utf-8?B?ZlNPWVdiektUOFVEV0FUaVg5bkYvbmZvaVVpQ0l4bjFDTzJYeTlud0dETmtO?= =?utf-8?B?RmJEdGFlcHBqajVJNE9PTkJvOW9QZmM3VDR3RnQvMW9XTHM5SDNOS1NZNXVq?= =?utf-8?B?RitaRnJvdGhMemt4Ny9iL3NvbFZEemFic2NPZzFiZzcvaU5ST2VzYTRNaXQ3?= =?utf-8?B?U3IzRlZ0Y2VXZEgwSlZnTjRUekREOGhPOHM1bEp0SzdVblBuakZWdlN0SFN2?= =?utf-8?B?bTBmQjJhYi9oaGZZYldoQTFrUlk3dUtOOW50bDVqWFFkM3JrM2VrckhKcUcy?= =?utf-8?B?ZTlUM3g5OUVaNDliaFNuTWhpeGlpRy8vU0ErdSt2SVZIbit2MWRSemx3Nmli?= =?utf-8?B?N3ZaRnUzcmpLakVJSFU0b3FITW0rM21aN2wxdFM4SGw3a0pYbElySkc2aEl1?= =?utf-8?B?SjU5UVBLdE1GNG84cSs1ellrMEtwZW0wYjVrcTRSWllBR1QvalYxRXBUb0lQ?= =?utf-8?B?VlVrYm83aVdOWGVZWkhybUVDRER6RXBUZjd0M05FeUt1T29lbGlRVnRWdlVE?= =?utf-8?Q?mekFzoebilBR5cdMrvQ5mAsdL?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0f5dcbbb-9fde-4758-a9fb-08db3b8bb422 X-MS-Exchange-CrossTenant-AuthSource: DM4PR12MB5229.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2023 19:25:41.3382 (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: XGb8bH7nYHD9srPuJStnjFl5aSq2yDUQRYNse/3EwsvUg49pmjqVbIwNqDxRb5nC+qZ7EfEvCTvLcsVQuJ+9TQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB8291 Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 4/12/23 05:17, duntan via groups.io wrote: > Hi Tom, > > This patch set is to change PiSmmCpuDxeSmm code to use CpuPageTableLib to create and update SMM page table. The Pcd PcdPteMemoryEncryptionAddressOrMask is also used in PiSmmCpuDxeSmm code and the whole range covered by page table is mapped encrypted, which is different from the situation in DxeIpl module. > So could you also help do a test to make sure the AMD SEV feature still works good in SMM with this patch set? > Here is the code branch in my fork repo: https://github.com/td36/edk2/commits/SmmPageTable_V2 Hi Dun, I tested at the final commit of the branch and encountered a #GP with an SEV guest. It looks like the CpuPageTableLibrary doesn't take the encryption bit into account. For example: Line 436 of UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c PagingEntry = (IA32_PAGING_ENTRY *)(UINTN)IA32_PNLE_PAGE_TABLE_BASE_ADDRESS (&ParentPagingEntry->Pnle); This will get an address with the encryption bit set and then try to reference it. When I clear the encryption bit, the code proceeds a bit further, but then encounters a #GP in a different location. So it appears that the CpuPageTableLibrary doesn't deal with the encryption bit properly. Also, going through a build/test of each individual patch had mixed results. - With the second patch in the series applied, I get a build error: /root/kernels/ovmf-dun-build-X64/OvmfPkg/OvmfPkgX64.dsc(...): error 4000: Instance of library class [CpuPageTableLib] is not found in [/root/kernels/ovmf-dun-build-X64/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf] [X64] consumed by module [/root/kernels/ovmf-dun-build-X64/UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf] that isn't resolved until the final patch. Thanks, Tom > > Thanks, > Dun > > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of duntan > Sent: Wednesday, April 12, 2023 4:54 PM > To: devel@edk2.groups.io > Subject: [edk2-devel] [Patch V2 0/8] Use CpuPageTableLib to create and update smm page table > > In V2 patch set: > 1.In 'Refinement to code about updating smm page table', use QuickSort() in BaseLib instead or PerformQuickSort() in BaseSortLib. > 2.Remove the patch to add BaseSortLib in DSC file. > 3.Add a new patch to add CpuPageTableLib in UefiCpuPkg.dsc. > 4.Add a temp patch to add CpuPageTableLib in OvmfPkg dsc files for test(A previous patch I sent before '[Patch V2 4/8] OvmfPkg: Add CpuPageTableLib required by DxeIpl in DSC file' contains all the changes in this patch) > > Dun Tan (8): > OvmfPkg: Add CpuPageTableLib required by PiSmmCpuDxe > UefiPayloadPkg: Add CpuPageTableLib required by PiSmmCpuDxe > UefiCpuPkg: Use CpuPageTableLib to convert SMM paging attribute. > UefiCpuPkg/PiSmmCpuDxeSmm: Avoid setting non-present range to RO/NX > UefiCpuPkg: Extern mSmmShadowStackSize in PiSmmCpuDxeSmm.h > UefiCpuPkg: Refinement to current smm page table generation code > UefiCpuPkg: Refinement to code about updating smm page table > UefiCpuPkg/PiSmmCpuDxeSmm: Remove unnecessary function > > OvmfPkg/CloudHv/CloudHvX64.dsc | 2 +- > OvmfPkg/OvmfPkgIa32.dsc | 3 ++- > OvmfPkg/OvmfPkgIa32X64.dsc | 2 +- > OvmfPkg/OvmfPkgX64.dsc | 2 +- > UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/PageTbl.c | 5 +++-- > UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmFuncsArch.c | 3 +-- > UefiCpuPkg/PiSmmCpuDxeSmm/Ia32/SmmProfileArch.c | 2 +- > UefiCpuPkg/PiSmmCpuDxeSmm/MpService.c | 132 ------------------------------------------------------------------------------------------------------------------------------------ > UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.c | 8 ++++++-- > UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.h | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------- > UefiCpuPkg/PiSmmCpuDxeSmm/PiSmmCpuDxeSmm.inf | 1 + > UefiCpuPkg/PiSmmCpuDxeSmm/SmmCpuMemoryManagement.c | 629 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- > UefiCpuPkg/PiSmmCpuDxeSmm/SmmProfile.c | 348 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- > UefiCpuPkg/PiSmmCpuDxeSmm/X64/PageTbl.c | 229 ++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- > UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmFuncsArch.c | 3 +-- > UefiCpuPkg/PiSmmCpuDxeSmm/X64/SmmProfileArch.c | 19 ++----------------- > UefiPayloadPkg/UefiPayloadPkg.dsc | 2 +- > 17 files changed, 510 insertions(+), 977 deletions(-) >