From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 78C3EAC1312 for ; Mon, 29 Jan 2024 12:02:13 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=rYGf9GwuNKzfXbvmtEMbJQ0XnqjBwALM36b4oDw1d/E=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding:Content-Type; s=20140610; t=1706529732; v=1; b=UyIJ25aFNkx7RZx1dbjE3S0Ax4ienlEOdAIHVc87Q5LCarIb847mimrNk1ZiH3We1GT+OqU0 0mrMHYciQH05Wv3kMk6IlCW6qWsaD7GPjZbPIfQocFF6OdmErjZYSnGFJHNy/P+S6PdSR1AlRlr jD90hEYv18UWdURGCq2bjlsI= X-Received: by 127.0.0.2 with SMTP id ABppYY7687511xJPWC18fR7A; Mon, 29 Jan 2024 04:02:12 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web10.13149.1706529731484448034 for ; Mon, 29 Jan 2024 04:02:11 -0800 X-Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-448-3iKGbOy6P4OfGpDYN0Yncg-1; Mon, 29 Jan 2024 07:02:05 -0500 X-MC-Unique: 3iKGbOy6P4OfGpDYN0Yncg-1 X-Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AF6463813BC5; Mon, 29 Jan 2024 12:02:04 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.192.180]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7AB3040C9444; Mon, 29 Jan 2024 12:02:04 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 33D4218009E5; Mon, 29 Jan 2024 13:02:01 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Laszlo Ersek , Oliver Steffen , Gerd Hoffmann , Ard Biesheuvel , Michael Roth , Min Xu , Tom Lendacky , Erdem Aktas , Jiewen Yao , Liming Gao Subject: [edk2-devel] [PATCH 2/3] OvmfPkg/ResetVector: add 5-level paging support Date: Mon, 29 Jan 2024 13:02:00 +0100 Message-ID: <20240129120201.344234-3-kraxel@redhat.com> In-Reply-To: <20240129120201.344234-1-kraxel@redhat.com> References: <20240129120201.344234-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk 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,kraxel@redhat.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: DnW1ZPXFGV9FKD2dxvRtP1GGx7686176AA= Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=UyIJ25aF; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=redhat.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io Compile the OVMF ResetVector with 5-level paging support in case PcdUse5LevelPageTable is TRUE. When enabled the ResetVector will check at runtime whenever support for 5-level paging and gigabyte pages is available. In case both features are supported it will run OVMF in 5-level paging mode, otherwise fallback to 4-level paging. Signed-off-by: Gerd Hoffmann --- OvmfPkg/ResetVector/ResetVector.inf | 1 + OvmfPkg/ResetVector/Ia32/PageTables64.asm | 72 +++++++++++++++++++++++ OvmfPkg/ResetVector/ResetVector.nasmb | 1 + 3 files changed, 74 insertions(+) diff --git a/OvmfPkg/ResetVector/ResetVector.inf b/OvmfPkg/ResetVector/ResetVector.inf index a4154ca90c28..65f71b05a02e 100644 --- a/OvmfPkg/ResetVector/ResetVector.inf +++ b/OvmfPkg/ResetVector/ResetVector.inf @@ -64,3 +64,4 @@ [FixedPcd] gUefiOvmfPkgTokenSpaceGuid.PcdQemuHashTableSize gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsBase gUefiOvmfPkgTokenSpaceGuid.PcdOvmfSnpSecretsSize + gEfiMdeModulePkgTokenSpaceGuid.PcdUse5LevelPageTable diff --git a/OvmfPkg/ResetVector/Ia32/PageTables64.asm b/OvmfPkg/ResetVector/Ia32/PageTables64.asm index 317cad430f29..0f88d1c71798 100644 --- a/OvmfPkg/ResetVector/Ia32/PageTables64.asm +++ b/OvmfPkg/ResetVector/Ia32/PageTables64.asm @@ -81,6 +81,78 @@ clearPageTablesMemoryLoop: mov dword[ecx * 4 + PT_ADDR (0) - 4], eax loop clearPageTablesMemoryLoop +%if PG_5_LEVEL + + ; save edx (cpuid changes it) + mov edi, edx + + ; check for cpuid leaf 0x07 + mov eax, 0x00 + cpuid + cmp eax, 0x07 + jb Paging4Lvl + + ; check for la57 (aka 5-level paging) + mov eax, 0x07 + mov ecx, 0x00 + cpuid + bt ecx, 16 + jnc Paging4Lvl + + ; check for cpuid leaf 0x80000001 + mov eax, 0x80000000 + cpuid + cmp eax, 0x80000001 + jb Paging4Lvl + + ; check for 1g pages + mov eax, 0x80000001 + cpuid + bt edx, 26 + jnc Paging4Lvl + + ; + ; use 5-level paging with gigabyte pages + ; + debugShowPostCode 0x51 ; 5-level paging + + ; restore edx + mov edx, edi + + ; level 5 + mov dword[PT_ADDR (0)], PT_ADDR (0x1000) + PAGE_PDP_ATTR + mov dword[PT_ADDR (4)], edx + + ; level 4 + mov dword[PT_ADDR (0x1000)], PT_ADDR (0x2000) + PAGE_PDP_ATTR + mov dword[PT_ADDR (0x1004)], edx + + ; level 3 + mov dword[PT_ADDR (0x2000)], (0 << 30) + PAGE_2M_PDE_ATTR + mov dword[PT_ADDR (0x2004)], edx + mov dword[PT_ADDR (0x2008)], (1 << 30) + PAGE_2M_PDE_ATTR + mov dword[PT_ADDR (0x200c)], edx + mov dword[PT_ADDR (0x2010)], (2 << 30) + PAGE_2M_PDE_ATTR + mov dword[PT_ADDR (0x2014)], edx + mov dword[PT_ADDR (0x2018)], (3 << 30) + PAGE_2M_PDE_ATTR + mov dword[PT_ADDR (0x201c)], edx + + ; set la57 bit in cr4 + mov eax, cr4 + bts eax, 12 + mov cr4, eax + + ; done + jmp SetCr3 + +Paging4Lvl: + debugShowPostCode 0x41 ; 4-level paging + + ; restore edx + mov edx, edi + +%endif + ; ; Top level Page Directory Pointers (1 * 512GB entry) ; diff --git a/OvmfPkg/ResetVector/ResetVector.nasmb b/OvmfPkg/ResetVector/ResetVector.nasmb index 5832aaa8abf7..16b3eee57671 100644 --- a/OvmfPkg/ResetVector/ResetVector.nasmb +++ b/OvmfPkg/ResetVector/ResetVector.nasmb @@ -49,6 +49,7 @@ %define WORK_AREA_GUEST_TYPE (FixedPcdGet32 (PcdOvmfWorkAreaBase)) %define PT_ADDR(Offset) (FixedPcdGet32 (PcdOvmfSecPageTablesBase) + (Offset)) +%define PG_5_LEVEL (FixedPcdGetBool (PcdUse5LevelPageTable)) %define GHCB_PT_ADDR (FixedPcdGet32 (PcdOvmfSecGhcbPageTableBase)) %define GHCB_BASE (FixedPcdGet32 (PcdOvmfSecGhcbBase)) -- 2.43.0 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#114689): https://edk2.groups.io/g/devel/message/114689 Mute This Topic: https://groups.io/mt/104029639/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-