From nobody Thu May 16 02:38:27 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+94520+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+94520+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1664460451; cv=none; d=zohomail.com; s=zohoarc; b=fM75CnLXGgPoUzao4jULBxvXv6k6sYt+Kkm83Mb6VqwQ+Ti2jYIXLFjIPskf6Iv16asCqJ+UC1EvYCbLSdlzlplt7rO7nao5Yab6oPgKQ9oNqKPyJMcApd2i1EY4zs0GELwioUyXM3yfeypnmvYH35Ngj3un5WsJSwM8Q1uS0zo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664460451; h=Content-Type: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=ISBBYWooVW2uv5EOtL8lruMG6cMCB2d5r52MtDKeFoQ=; b=NHNB62OU3UeiN9o9i+cp+QFRmbV8rQyAO+2N97asECbiGGX+xG6Uhmm001oH4JlazEceL6JziupukxS9MfHjj8c079M6rLJMSMny811mEAI5qLyhFcw1GTw6LQcFuoKFWhpUnN38XmMw3jwBgNf2+j9eme9pmLAMg0OuZ1Hwl3s= 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+94520+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 1664460451754570.5616633432585; Thu, 29 Sep 2022 07:07:31 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id AqI0YY1788612x9MiBQmTWs5; Thu, 29 Sep 2022 07:07:30 -0700 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.web08.10988.1664460448267482812 for ; Thu, 29 Sep 2022 07:07:28 -0700 X-Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-488-bAYdj8wtPZSHf-EmCk_NvQ-1; Thu, 29 Sep 2022 10:07:23 -0400 X-MC-Unique: bAYdj8wtPZSHf-EmCk_NvQ-1 X-Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0AF6C1C068D1; Thu, 29 Sep 2022 14:07:23 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.194.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 89071145B98C; Thu, 29 Sep 2022 14:07:22 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id DFC0F18009B7; Thu, 29 Sep 2022 16:07:20 +0200 (CEST) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Gerd Hoffmann , Oliver Steffen , Ard Biesheuvel , Jiewen Yao , Pawel Polawski , Jordan Justen Subject: [edk2-devel] [PATCH 1/4] OvmfPkg/PlatformInitLib: qemu cpuid physbits detection Date: Thu, 29 Sep 2022 16:07:17 +0200 Message-Id: <20220929140720.1501464-2-kraxel@redhat.com> In-Reply-To: <20220929140720.1501464-1-kraxel@redhat.com> References: <20220929140720.1501464-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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,kraxel@redhat.com X-Gm-Message-State: 6tabiJ0bEb86ep8T1bEDyDtNx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1664460450; bh=BC4PuiOb5PUKrZLngyfvOgwHIwPePGb7dVqMD3nl2CE=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=J2tD/PXqQXSh/svIBE2f/AoXP551d7ioY2E8yFMq+Gby4Z2DHVg9vKQnCr2Bpdh7/Ll g9Pw1FCj6q268SjcvmkSzXIZIDfIE5DU+Fp6t8fhruCDjKQXQtunJ3gdCYpHWvkCyvpvm qICbO4WL05ZqL3j0IDMoOkxIXd5sYtyyk/o= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1664460453827100016 Content-Type: text/plain; charset="utf-8"; x-default="true" Add some qemu specific quirks to PlatformAddressWidthFromCpuid() to figure whenever the PhysBits value returned by CPUID is something real we can work with or not. See the source code comment for details on the logic. Also apply some limits to the address space we are going to use: * Place a hard cap at 47 PhysBits (128 TB) to avoid using addresses which require 5-level paging support. * Cap at 40 PhysBits (1 TB) in case the CPU has no support for gigabyte pages, to avoid excessive amounts of pages being used for page tables. Signed-off-by: Gerd Hoffmann --- OvmfPkg/Library/PlatformInitLib/MemDetect.c | 102 ++++++++++++++++---- 1 file changed, 84 insertions(+), 18 deletions(-) diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/= PlatformInitLib/MemDetect.c index d1a4f4b20791..143a01ceb01e 100644 --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c @@ -503,39 +503,105 @@ PlatformGetFirstNonAddress ( } =20 /* - * Use CPUID to figure physical address width. Does *not* work - * reliable on qemu. For historical reasons qemu returns phys-bits=3D40 - * even in case the host machine supports less than that. - * - * qemu has a cpu property (host-phys-bits=3D{on,off}) to change that - * and make sure guest phys-bits are not larger than host phys-bits., - * but it is off by default. Exception: microvm machine type - * hard-wires that property to on. + * Use CPUID to figure physical address width. + * + * Does *not* work reliable on qemu. For historical reasons qemu + * returns phys-bits=3D40 by default even in case the host machine + * supports less than that. + * + * So we apply the following rules (which can be enabled/disabled + * using the QemuQuirk parameter) to figure whenever we can work with + * the returned physical address width or not: + * + * (1) If it is 41 or higher consider it valid. + * (2) If it is 40 or lower consider it valid in case it matches a + * known-good value for the CPU vendor, which is: + * -> 36 or 39 for Intel + * -> 40 for AMD + * (3) Otherwise consider it invalid. + * + * Recommendation: Run qemu with host-phys-bits=3Don. That will make + * sure guest phys-bits is not larger than host phys-bits. Some + * distro builds do that by default. */ VOID EFIAPI PlatformAddressWidthFromCpuid ( - IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob + IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob, + IN BOOLEAN QemuQuirk ) { - UINT32 RegEax; + UINT32 RegEax, RegEbx, RegEcx, RegEdx, Max; + UINT8 PhysBits; + CHAR8 Signature[13] =3D { 0 }; + BOOLEAN Valid =3D FALSE; + BOOLEAN Page1GSupport =3D FALSE; =20 - AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL); - if (RegEax >=3D 0x80000008) { + AsmCpuid (0x80000000, &RegEax, &RegEbx, &RegEcx, &RegEdx); + *(UINT32 *)(Signature + 0) =3D RegEbx; + *(UINT32 *)(Signature + 4) =3D RegEdx; + *(UINT32 *)(Signature + 8) =3D RegEcx; + Max =3D RegEax; + + if (Max >=3D 0x80000001) { + AsmCpuid (0x80000001, NULL, NULL, NULL, &RegEdx); + if ((RegEdx & BIT26) !=3D 0) { + Page1GSupport =3D TRUE; + } + } + + if (Max >=3D 0x80000008) { AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL); - PlatformInfoHob->PhysMemAddressWidth =3D (UINT8)RegEax; + PhysBits =3D (UINT8)RegEax; } else { - PlatformInfoHob->PhysMemAddressWidth =3D 36; + PhysBits =3D 36; } =20 - PlatformInfoHob->FirstNonAddress =3D LShiftU64 (1, PlatformInfoHob->Phys= MemAddressWidth); + if (!QemuQuirk) { + Valid =3D TRUE; + } else if (PhysBits >=3D 41) { + Valid =3D TRUE; + } else if (AsciiStrCmp (Signature, "GenuineIntel") =3D=3D 0) { + if ((PhysBits =3D=3D 36) || (PhysBits =3D=3D 39)) { + Valid =3D TRUE; + } + } else if (AsciiStrCmp (Signature, "AuthenticAMD") =3D=3D 0) { + if (PhysBits =3D=3D 40) { + Valid =3D TRUE; + } + } =20 DEBUG (( DEBUG_INFO, - "%a: cpuid: phys-bits is %d\n", + "%a: Signature: '%a', PhysBits: %d, QemuQuirk: %a, Valid: %a\n", __FUNCTION__, - PlatformInfoHob->PhysMemAddressWidth + Signature, + PhysBits, + QemuQuirk ? "On" : "Off", + Valid ? "Yes" : "No" )); + + if (Valid) { + if (PhysBits > 47) { + /* + * Avoid 5-level paging altogether for now, which limits + * PhysBits to 48. Also avoid using address bit 48, due to sign + * extension we can't identity-map these addresses (and lots of + * places in edk2 assume we have everything identity-mapped). + * So the actual limit is 47. + */ + DEBUG ((DEBUG_INFO, "%a: limit PhysBits to 47 (avoid 5-level paging)= \n", __func__)); + PhysBits =3D 47; + } + + if (!Page1GSupport && (PhysBits > 40)) { + DEBUG ((DEBUG_INFO, "%a: limit PhysBits to 40 (no 1G pages available= )\n", __func__)); + PhysBits =3D 40; + } + + PlatformInfoHob->PhysMemAddressWidth =3D PhysBits; + PlatformInfoHob->FirstNonAddress =3D LShiftU64 (1, PlatformInfoHob= ->PhysMemAddressWidth); + } } =20 /** @@ -672,7 +738,7 @@ PlatformAddressWidthInitialization ( EFI_STATUS Status; =20 if (PlatformInfoHob->HostBridgeDevId =3D=3D 0xffff /* microvm */) { - PlatformAddressWidthFromCpuid (PlatformInfoHob); + PlatformAddressWidthFromCpuid (PlatformInfoHob, FALSE); return; } =20 --=20 2.37.3 -=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 (#94520): https://edk2.groups.io/g/devel/message/94520 Mute This Topic: https://groups.io/mt/93994877/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- From nobody Thu May 16 02:38:27 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+94517+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+94517+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1664460448; cv=none; d=zohomail.com; s=zohoarc; b=AqzYZ17QP/EKZsKlh05yUHYfiH1Zk5y1dTED13T96d2uTMSPIQ3WV+Z3GratXg/j4Qw822fRw0jtR3g266YtX4aITuf6nCui2+C59fvDNb7zRgl2JymnTKa4snzgXmtZipvO2DTGzVr+IlfJlYg0dj4yMqwpnLQuJL8ltc3HmTE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664460448; h=Content-Type: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=xApoZ2HPVWoXHKqVZTP3KCKl6aCSAdUcj2C6rKFBjTo=; b=EvGBUuBWCg2eXkIu6DMeB3oAoUZSuOUX9/b6dVjgHae6huDgK9Swn48LbUHfp6qEDE4/AqDdWLoR/xIcKWp7kER1k8+5fXYD9tTS/5OUkomq6JgnZjw6I9ifNzsxfvct/sciiPILX2wbZEZXA7uUkEdeu/RlbNgWsJMGurpsF2E= 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+94517+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 166446044823073.95830215408375; Thu, 29 Sep 2022 07:07:28 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id ur7XYY1788612xueoM5Dkmpy; Thu, 29 Sep 2022 07:07:27 -0700 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.web12.10694.1664460446900602140 for ; Thu, 29 Sep 2022 07:07:27 -0700 X-Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-240-SbUTwEuKMZeJFhCD4MLRqg-1; Thu, 29 Sep 2022 10:07:24 -0400 X-MC-Unique: SbUTwEuKMZeJFhCD4MLRqg-1 X-Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 81885185A7AF; Thu, 29 Sep 2022 14:07:24 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.194.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3F9FB40C6EC2; Thu, 29 Sep 2022 14:07:24 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id E538C18009B8; Thu, 29 Sep 2022 16:07:20 +0200 (CEST) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Gerd Hoffmann , Oliver Steffen , Ard Biesheuvel , Jiewen Yao , Pawel Polawski , Jordan Justen Subject: [edk2-devel] [PATCH 2/4] OvmfPkg/PlatformInitLib: detect physical address space Date: Thu, 29 Sep 2022 16:07:18 +0200 Message-Id: <20220929140720.1501464-3-kraxel@redhat.com> In-Reply-To: <20220929140720.1501464-1-kraxel@redhat.com> References: <20220929140720.1501464-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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,kraxel@redhat.com X-Gm-Message-State: gz1LeiOPyQBdUJ5jpgyWjAHGx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1664460447; bh=E55lAH5DmMUDEOWfX7mwmve9XGVCU5bOsT85Usx5o9A=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=BofaGtwjrQ0XR2m14e2EzdUdKhJav5aWpdqqmDOQLsFkX5FWb23VeIyIFYcksBnGv1h el4kuCeLZyE9BMSjweTjxPgebytJapPjplTdkl2G7w8MT1VamYy/uxMur2n0lz/kyxYaP zp+NtW492m17yUYkVz8F/MMd4cu5tDyae9A= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1664460449892100003 Content-Type: text/plain; charset="utf-8"; x-default="true" Try detect physical address space, when successful use it. Otherwise go continue using the current guesswork code path. Signed-off-by: Gerd Hoffmann --- OvmfPkg/Library/PlatformInitLib/MemDetect.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/= PlatformInitLib/MemDetect.c index 143a01ceb01e..16ecbfadc30c 100644 --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c @@ -761,6 +761,19 @@ PlatformAddressWidthInitialization ( FirstNonAddress =3D PlatformGetFirstNonAddress (PlatformInfoHob); } =20 + PlatformAddressWidthFromCpuid (PlatformInfoHob, TRUE); + if (PlatformInfoHob->PhysMemAddressWidth !=3D 0) { + // physical address width is known + PlatformInfoHob->FirstNonAddress =3D FirstNonAddress; + return; + } + + // + // physical address width is NOT known + // -> do some guess work, mostly based on installed memory + // -> try be conservstibe to stay below the guaranteed minimum of + // 36 phys bits (aka 64 GB). + // PhysMemAddressWidth =3D (UINT8)HighBitSet64 (FirstNonAddress); =20 // --=20 2.37.3 -=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 (#94517): https://edk2.groups.io/g/devel/message/94517 Mute This Topic: https://groups.io/mt/93994874/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- From nobody Thu May 16 02:38:27 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+94518+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+94518+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1664460450; cv=none; d=zohomail.com; s=zohoarc; b=mjCJK/dfqZDr10q0jGRC5lvV4OTTPKQ5PluwhWZobULmS/kV22f3CEu/1nOzcvGraOwZow/sIKaL27twa8TuznPR0Mi+3kv+HxneHQ2l+bten3HeNYWS3GIwnsm+95f1plEkKAIqO4eiyEDJBb8vmKEUtN0Zd40HpDw/nOnLmqE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664460450; h=Content-Type: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=laaEE4IbYpW+d9o/gdJwWC+BPtnxVppVYcTfvV7yDuQ=; b=T/FHLNhG7blQW12AHxCV+AJC0sFn4f7gz9OUVKqQ4VTn9/RY8RHshf2AJVZuaXWI/bDPz+PjtSSs67mzttJz33M/QRHggqfbIoCwPzk9U0152jj3HRl9C2NZUCb0quG0JHrCY4/COLdZipW8COwt/5o5WJZJxV5mXY5AbZNyLOE= 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+94518+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 1664460450399398.2420902692687; Thu, 29 Sep 2022 07:07:30 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id lKRKYY1788612xxLSzBWXqxA; Thu, 29 Sep 2022 07:07:28 -0700 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.10486.1664460447514123950 for ; Thu, 29 Sep 2022 07:07:27 -0700 X-Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-92-9IjLvIG_PK6M82dBV-bzfA-1; Thu, 29 Sep 2022 10:07:25 -0400 X-MC-Unique: 9IjLvIG_PK6M82dBV-bzfA-1 X-Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BF8DE2932490; Thu, 29 Sep 2022 14:07:24 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.194.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7DF15207B317; Thu, 29 Sep 2022 14:07:24 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id E8D9918009BA; Thu, 29 Sep 2022 16:07:20 +0200 (CEST) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Gerd Hoffmann , Oliver Steffen , Ard Biesheuvel , Jiewen Yao , Pawel Polawski , Jordan Justen Subject: [edk2-devel] [PATCH 3/4] OvmfPkg/PlatformInitLib: dynamic mmio window size Date: Thu, 29 Sep 2022 16:07:19 +0200 Message-Id: <20220929140720.1501464-4-kraxel@redhat.com> In-Reply-To: <20220929140720.1501464-1-kraxel@redhat.com> References: <20220929140720.1501464-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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,kraxel@redhat.com X-Gm-Message-State: USz53cQYcfLakDjKFQ0Vuu8Jx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1664460448; bh=jeFof9kLbKugMQcOERKg0eXg09nr73UOARwj9cCtoAo=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=HAcv/kqLYgIrZl/sN0JhcgywdhIbUpQDeZ1uzOWhf5evRPLdrIttYW6qqei8E+L0yv6 BqSoK8z58ig3FFnROqVJ9enCqFnnjPYgq2D1ZGCdBbu2dI7zlkfo1SlzTan7iRGPrfwQG 8PIR60rs6dXW1Rj65NSK/vrrxJCMrRACl+U= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1664460451805100009 Content-Type: text/plain; charset="utf-8"; x-default="true" In case we have a reliable PhysMemAddressWidth use that to dynamically size the 64bit address window. Allocate 1/8 of the physical address space and place the window at the upper end of the address space. Signed-off-by: Gerd Hoffmann --- OvmfPkg/Library/PlatformInitLib/MemDetect.c | 28 +++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/OvmfPkg/Library/PlatformInitLib/MemDetect.c b/OvmfPkg/Library/= PlatformInitLib/MemDetect.c index 16ecbfadc30c..ae217d0242ed 100644 --- a/OvmfPkg/Library/PlatformInitLib/MemDetect.c +++ b/OvmfPkg/Library/PlatformInitLib/MemDetect.c @@ -604,6 +604,33 @@ PlatformAddressWidthFromCpuid ( } } =20 +VOID +EFIAPI +PlatformDynamicMmioWindow ( + IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob + ) +{ + UINT64 AddrSpace, MmioSpace; + + AddrSpace =3D LShiftU64 (1, PlatformInfoHob->PhysMemAddressWidth); + MmioSpace =3D LShiftU64 (1, PlatformInfoHob->PhysMemAddressWidth - 3); + + if ((PlatformInfoHob->PcdPciMmio64Size < MmioSpace) && + (PlatformInfoHob->PcdPciMmio64Base + MmioSpace < AddrSpace)) + { + DEBUG ((DEBUG_INFO, "%a: using dynamic mmio window\n", __func__)); + DEBUG ((DEBUG_INFO, "%a: Addr Space 0x%Lx (%Ld GB)\n", __func__, Add= rSpace, RShiftU64 (AddrSpace, 30))); + DEBUG ((DEBUG_INFO, "%a: MMIO Space 0x%Lx (%Ld GB)\n", __func__, Mmi= oSpace, RShiftU64 (MmioSpace, 30))); + PlatformInfoHob->PcdPciMmio64Size =3D MmioSpace; + PlatformInfoHob->PcdPciMmio64Base =3D AddrSpace - MmioSpace; + } else { + DEBUG ((DEBUG_INFO, "%a: using classic mmio window\n", __func__)); + } + + DEBUG ((DEBUG_INFO, "%a: Pci64 Base 0x%Lx\n", __func__, PlatformInfoHo= b->PcdPciMmio64Base)); + DEBUG ((DEBUG_INFO, "%a: Pci64 Size 0x%Lx\n", __func__, PlatformInfoHo= b->PcdPciMmio64Size)); +} + /** Iterate over the PCI host bridges resources information optionally provi= ded in fw-cfg and find the highest address contained in the PCI MMIO windows= . If @@ -765,6 +792,7 @@ PlatformAddressWidthInitialization ( if (PlatformInfoHob->PhysMemAddressWidth !=3D 0) { // physical address width is known PlatformInfoHob->FirstNonAddress =3D FirstNonAddress; + PlatformDynamicMmioWindow (PlatformInfoHob); return; } =20 --=20 2.37.3 -=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 (#94518): https://edk2.groups.io/g/devel/message/94518 Mute This Topic: https://groups.io/mt/93994875/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- From nobody Thu May 16 02:38:27 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+94521+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+94521+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1664460452; cv=none; d=zohomail.com; s=zohoarc; b=CFtZOU8+4hxapkVbC38x8qSWMltgzvTaD+nTD+xc9nufwTsjk0iep4+DGvEBE7MtCdsVSMQrvlJB91Yl4KB6g+ZqcSyoLTwPSHPCEJYK8Fg9vQEcdRTBmofGbUruix50bZzp0xSNO3FM897eWr1/xiSzLBTYx9mkSkCEGG7uH+o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664460452; h=Content-Type: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=pVyl07ucOvxnUlKuGOVrb6dD+7+nYGa5x//r0LNDhE8=; b=kz8MEEfBOnQ3KJTPSE0tp+tDF6pr9fTybbE/DXR5wzSnWqL7qTNSKoOUQdye+t1cwjapH5aXtbUth9Fk9Q61U681xOu9YwLCE2Uxl9YR6IVDKQpCQRF+g6wpPHWFGUtg66heP5Gp9A6f11sYFyC8U8sxWUm7/i6omJJN0+HsaXY= 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+94521+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 1664460452550776.1210423830307; Thu, 29 Sep 2022 07:07:32 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id myVIYY1788612xFBqfh3HDK9; Thu, 29 Sep 2022 07:07:32 -0700 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.groups.io with SMTP id smtpd.web09.10849.1664460451392678862 for ; Thu, 29 Sep 2022 07:07:31 -0700 X-Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-501-iFWrmmFoNsaCcZsGYrKIkQ-1; Thu, 29 Sep 2022 10:07:26 -0400 X-MC-Unique: iFWrmmFoNsaCcZsGYrKIkQ-1 X-Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 316B7862FDF; Thu, 29 Sep 2022 14:07:26 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.194.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E942214588BE; Thu, 29 Sep 2022 14:07:25 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id EC8A618009BB; Thu, 29 Sep 2022 16:07:20 +0200 (CEST) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Gerd Hoffmann , Oliver Steffen , Ard Biesheuvel , Jiewen Yao , Pawel Polawski , Jordan Justen Subject: [edk2-devel] [PATCH 4/4] OvmfPkg/PciHotPlugInitDxe: reserve more mmio space Date: Thu, 29 Sep 2022 16:07:20 +0200 Message-Id: <20220929140720.1501464-5-kraxel@redhat.com> In-Reply-To: <20220929140720.1501464-1-kraxel@redhat.com> References: <20220929140720.1501464-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com 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,kraxel@redhat.com X-Gm-Message-State: ua1MEKGacYnaIGRoxSn4nWA0x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1664460452; bh=V7X0ntjcAX8qy4k3xCOoToYC8OC0zb6HCxpX+bRxUoY=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=PXewhPHXSqWVkpCjhXu2Z7BjgrhFvY+WR4JMsc5HGCjBBudd3vfkq1F+qqr0h5h0bkj eZPdofVV1gaNjeyghl9U6IQ0AKBHkj+bfyi7eteXdKOASQ3Wds1ur1ok6Uj13hKknU3l2 O66eacQfn5jvKWr7vQGJgXoNbxLY3nSM3dk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1664460453876100017 Content-Type: text/plain; charset="utf-8"; x-default="true" In case the 64-bit pci mmio window is larger than the default size of 32G be generous and hand out larger chunks of address space for prefetchable mmio bridge windows. Signed-off-by: Gerd Hoffmann --- OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf | 1 + OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf b/OvmfPkg/PciHotP= lugInitDxe/PciHotPlugInit.inf index 78b95faa7a7a..f56b1de6fd92 100644 --- a/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf +++ b/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf @@ -40,6 +40,7 @@ [Protocols] =20 [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId ## CONSUMES + gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Size ## CONSUMES =20 [Depex] TRUE diff --git a/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.c b/OvmfPkg/PciHotPlu= gInitDxe/PciHotPlugInit.c index c122855b735d..08ea5b57bc18 100644 --- a/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.c +++ b/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.c @@ -744,12 +744,25 @@ GetResourcePadding ( // // Request defaults. // + UINT64 Pci64Size =3D PcdGet64 (PcdPciMmio64Size); + + // non-prefetchable SetMmioPadding ( --FirstResource, FALSE, TRUE, (UINTN)HighBitSetRoundUp32 (SIZE_2MB) ); + + // prefetchable + if (Pci64Size > SIZE_32GB) { + SetMmioPadding ( + --FirstResource, + TRUE, + FALSE, + (UINTN)HighBitSetRoundUp64 (RShiftU64 (Pci64Size, 8)) + ); + } } =20 // --=20 2.37.3 -=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 (#94521): https://edk2.groups.io/g/devel/message/94521 Mute This Topic: https://groups.io/mt/93994880/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-