From nobody Sun Dec 22 06:02:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+104836+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+104836+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1684115133; cv=none; d=zohomail.com; s=zohoarc; b=DctvPhuA2kAzMSXSq2bZNCcYEMWsERx0Z7TxQ/b+YWgtVF2zAYMzG7SlFzt4gFFh7wKVHlua3BOokfSNKwl1f3QwTt5Z2ScOnxhDk47Xq68xb9zig/e+6JsA+kLxM6uMnjvsTGQnDM96Jum/ADuaUrFiNrqwnigyHQ/JqhAymdY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1684115133; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=MU9M+VUhWvs+80aU0ClQ7WFK6gdsXorxksXqpVvar74=; b=FwoiIt/KBcZ7O4xUNW+bP9hV1fJrquZCElauUKK6ooWTZsaBrUsy/v9kMT8uq/qUn4os8J9DPksEPITf4NkMK5nAS8QR8FOxEQcX9DI4KJSjyT0YvE2JM2/N5G9W47474z/VE/f/L2Ua/bVvo7OSDdnie01fPsEwLndq63EvY4I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+104836+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1684115133041722.0607737382882; Sun, 14 May 2023 18:45:33 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id rF80YY1788612xCPPEOH2bUL; Sun, 14 May 2023 18:45:32 -0700 X-Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web11.79068.1684114925302985385 for ; Sun, 14 May 2023 18:42:15 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10710"; a="331457262" X-IronPort-AV: E=Sophos;i="5.99,275,1677571200"; d="scan'208";a="331457262" X-Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 May 2023 18:42:14 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10710"; a="824987154" X-IronPort-AV: E=Sophos;i="5.99,275,1677571200"; d="scan'208";a="824987154" X-Received: from shwdesfp01.ccr.corp.intel.com ([10.239.158.151]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 May 2023 18:42:12 -0700 From: "Zhiguang Liu" To: devel@edk2.groups.io Cc: Zhiguang Liu , Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann , Debkumar De , Catharine West Subject: [edk2-devel] [PATCH v6 5/5] UefiCpuPkg/ResetVector: Support 5 level page table in ResetVector Date: Mon, 15 May 2023 09:41:38 +0800 Message-Id: <20230515014138.1321-6-zhiguang.liu@intel.com> In-Reply-To: <20230515014138.1321-1-zhiguang.liu@intel.com> References: <20230515014138.1321-1-zhiguang.liu@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,zhiguang.liu@intel.com X-Gm-Message-State: COm2MH7jTB0aXcSunaJPCMwxx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1684115132; bh=r3yejXcs/LqdXz26kDhOXswnCcRNH3drt187IRoAQaw=; h=Cc:Date:From:Reply-To:Subject:To; b=qO6QW3hlHu+ACgHDYqZayLW/bwivyrHtL8AWoDKFZSH26ztcEWIdmFrrlkum5u8prh8 XbCR+/mkskiA6AV5DSdUMGyPuC1y5V3xsVoLiHHEc5YCFx9PN3/arPLhuzaRTg/0/QqN4 Vd2yk8S1RnDyok5Xx1M4r0sLGNUjJiKFq94= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1684115133623100007 Content-Type: text/plain; charset="utf-8" Add a macro USE_5_LEVEL_PAGE_TABLE to determine whether to create 5 level page table. If macro USE_5_LEVEL_PAGE_TABLE is defined, PML5Table is created at (4G-12K), while PML4Table is at (4G-16K). In runtime check, if 5level paging is supported, use PML5Table, otherwise, use PML4Table. If macro USE_5_LEVEL_PAGE_TABLE is not defined, to save space, 5level paging is not created, and 4level paging is at (4G-12K) and be used. V6: In previous version, I merge code from Ia32\PageTables64.asm into Ia32\Flat32ToFlat64.asm to reduce files. However, reset vector from OvmfPkg\Bhyve\ResetVector needs the code from Flat32ToFlat64.asm, and needs its OneTimeCall SetCr3ForPageTables64. To be compatible, in this version, I keep the file PageTables64.asm, and implement 5level paging logic there. Cc: Eric Dong Cc: Ray Ni Cc: Rahul Kumar Cc: Gerd Hoffmann Cc: Debkumar De Cc: Catharine West Signed-off-by: Zhiguang Liu --- .../ResetVector/Vtf0/Ia32/PageTables64.asm | 20 +++++++++++++++++++ .../ResetVector/Vtf0/X64/PageTables.asm | 9 +++++++++ 2 files changed, 29 insertions(+) diff --git a/UefiCpuPkg/ResetVector/Vtf0/Ia32/PageTables64.asm b/UefiCpuPkg= /ResetVector/Vtf0/Ia32/PageTables64.asm index f188da20ba..165cebcfaa 100644 --- a/UefiCpuPkg/ResetVector/Vtf0/Ia32/PageTables64.asm +++ b/UefiCpuPkg/ResetVector/Vtf0/Ia32/PageTables64.asm @@ -17,8 +17,28 @@ SetCr3ForPageTables64: ; ; These pages are built into the ROM image in X64/PageTables.asm ; +%ifdef USE_5_LEVEL_PAGE_TABLE + mov eax, 0 + cpuid + cmp eax, 07h ; check if basic CPUID leaf contai= ns leaf 07 + jb NotSupport5LevelPaging ; 5level paging not support, downg= rade to 4level paging + mov eax, 07h ; check cpuid leaf 7, subleaf 0 + mov ecx, 0 + cpuid + bt ecx, 16 ; [Bits 16] Supports 5-level pagin= g if 1. + jnc NotSupport5LevelPaging ; 5level paging not support, downg= rade to 4level paging + mov eax, ADDR_OF(Pml5) + mov cr3, eax + mov eax, cr4 + bts eax, 12 ; Set LA57=3D1. + mov cr4, eax + jmp SetCr3Done +NotSupport5LevelPaging: +%endif + mov eax, ADDR_OF(Pml4) mov cr3, eax +SetCr3Done: =20 OneTimeCallRet SetCr3ForPageTables64 =20 diff --git a/UefiCpuPkg/ResetVector/Vtf0/X64/PageTables.asm b/UefiCpuPkg/Re= setVector/Vtf0/X64/PageTables.asm index d66fb62c34..7960b141be 100644 --- a/UefiCpuPkg/ResetVector/Vtf0/X64/PageTables.asm +++ b/UefiCpuPkg/ResetVector/Vtf0/X64/PageTables.asm @@ -81,4 +81,13 @@ Pml4: ; DQ PAGE_NLE(Pdp) TIMES 0x1000 - ($ - Pml4) DB 0 + +%ifdef USE_5_LEVEL_PAGE_TABLE +Pml5: + ; + ; Pml5 table (only first entry is present, pointing to Pml4) + ; + DQ PAGE_NLE(Pml4) + TIMES 0x1000 - ($ - Pml5) DB 0 +%endif EndOfPageTables: --=20 2.31.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#104836): https://edk2.groups.io/g/devel/message/104836 Mute This Topic: https://groups.io/mt/98894736/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-