From nobody Sat Nov 23 21:33:13 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+94699+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+94699+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1664891254; cv=none; d=zohomail.com; s=zohoarc; b=ABKLOCJr6xOhuL/csKhj/mOfMlJxLHcizIr82wfVVe7gpRminD6cbYLd6/B1D1l5oQw/ebd/hV0IRx10kiJ9WveExQrWgCK5kHsDRPGyoQ3b5h0CJcxiv6Un9N6MO96tG9y0SHXp2I/dciPVLqmerjvaGbXBYfmnEuv7xxWYhm0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664891254; 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=WYMiETpbeUpL1XoiFD/KZG80hRZiMMM2Rv0ey9OIQHQ=; b=lYJHLOwIWsNi/xKVUOUylSxGxDxdaPi/aKCJdFaEdH7m7YajYALOMc9WudLCDf2iMwJ2ey4/T2QSZr/b31sa7jMe6XLg33yZvcyAhjj4CdHyi0aCMh4UioVnFz1LApN+TwfGHuSZ8PMC4xIxRmmIzJOiEH1COfpdI5OqrainLMY= 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+94699+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 1664891254383934.7830516930763; Tue, 4 Oct 2022 06:47:34 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 8NHBYY1788612xJgxtvl1afx; Tue, 04 Oct 2022 06:47:34 -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.web08.10763.1664891252533102044 for ; Tue, 04 Oct 2022 06:47:33 -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-473-oHL16OmkNg-6Ey38EYLisg-1; Tue, 04 Oct 2022 09:47:30 -0400 X-MC-Unique: oHL16OmkNg-6Ey38EYLisg-1 X-Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DD7B8101A52A; Tue, 4 Oct 2022 13:47:29 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.193.173]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7B746477F55; Tue, 4 Oct 2022 13:47:29 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 10BBB1800848; Tue, 4 Oct 2022 15:47:28 +0200 (CEST) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Jordan Justen , Gerd Hoffmann , Pawel Polawski , Jiewen Yao , Oliver Steffen , Ard Biesheuvel Subject: [edk2-devel] [PATCH v2 1/4] OvmfPkg/PlatformInitLib: qemu cpuid physbits detection Date: Tue, 4 Oct 2022 15:47:25 +0200 Message-Id: <20221004134728.55499-2-kraxel@redhat.com> In-Reply-To: <20221004134728.55499-1-kraxel@redhat.com> References: <20221004134728.55499-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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: yHoYsIryOIXKDvN7kuBCmX2Px1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1664891254; bh=brE8We+E243brlk9FoaAlIBJYBURl/yZTXgsXxMrbQA=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=wpy7PcDQmiLlok4oWHRrfCmmChaxlVmqg+ABiEsNUPJPQITaV0uiTU4c/ANbkUdX+ua 6FYLVre/09FyPTCfABRfgUVyuFtarBDVRE90kmj7mwjt5QrSbhVWlYtNvrKdYKs+wCibH I04q15dbneA2Lz2dO3tqPKu5ViNBPzQL5Vk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1664891254807100003 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 (#94699): https://edk2.groups.io/g/devel/message/94699 Mute This Topic: https://groups.io/mt/94113625/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 Sat Nov 23 21:33:13 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+94702+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+94702+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1664891258; cv=none; d=zohomail.com; s=zohoarc; b=DzAm6tOF9JjpIIRk0AZlDduJF+xKJOAL4YugScLbLOJVGpBSAW19LD8RMRvGVPK8Tu0dKYNx6ImNLPQEUxpwutsNJ1yqRAQwzRTVo+p3wuTMkEtYHVYMO6KYAilyAWsld9MbPYC+NKksMsmLdTE9yFvLXRsRClokihhPpYvDlwE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664891258; 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=ROFLo1EAFQYl+FJtbl9YLul+roHBN52xx6DEkX5J/JQ=; b=oAgXdyxAZiw2mho80raxEZWfglU6HDCe7E9NZfo3B785L6b2GazCdlBkS0p1KHYiJbzwZRnXkRGPWt9Tbdb+xIgKfO0TbxoI5HUILaf1fB9cYK3Aou/tuUXkU+4b6xTbot1uvOnHRTDlSDBDuILZjpIjoF3ukLO4InEbMmO+VeE= 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+94702+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 1664891258901956.6175948252154; Tue, 4 Oct 2022 06:47:38 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id WEkUYY1788612xYkfoWFwHnW; Tue, 04 Oct 2022 06:47:38 -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.10933.1664891256994032203 for ; Tue, 04 Oct 2022 06:47:38 -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-19-ngQZbtmsPHunCoxnZ7SjYg-1; Tue, 04 Oct 2022 09:47:31 -0400 X-MC-Unique: ngQZbtmsPHunCoxnZ7SjYg-1 X-Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 26219101E153; Tue, 4 Oct 2022 13:47:31 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.193.173]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E8DE0477F5D; Tue, 4 Oct 2022 13:47:30 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 15A88180084D; Tue, 4 Oct 2022 15:47:28 +0200 (CEST) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Jordan Justen , Gerd Hoffmann , Pawel Polawski , Jiewen Yao , Oliver Steffen , Ard Biesheuvel Subject: [edk2-devel] [PATCH v2 2/4] OvmfPkg/PlatformInitLib: detect physical address space Date: Tue, 4 Oct 2022 15:47:26 +0200 Message-Id: <20221004134728.55499-3-kraxel@redhat.com> In-Reply-To: <20221004134728.55499-1-kraxel@redhat.com> References: <20221004134728.55499-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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: SjtbRuNV8VJWj344FObeXqSRx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1664891258; bh=rL5uPKF+TNoeR/1J/fX0psR1hQcPdrTBM4nREBu+yVY=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=v2jI3pNEljcI44sqXUeWtM18wmaWlGOolAvBirqs5YTOu/OrRIYrLMxYyCwOmZ2OGQb HINnd7Sfgb1tcQ3YS4l0NfrRA5BlA8OcqzSdTvP+ILoxKFpCjkAnxJ7Piz96WdO+Ynnot Kx42uQMKL7y1XarUDrR4puXQDWb4PUDCnR0= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1664891260892100002 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 (#94702): https://edk2.groups.io/g/devel/message/94702 Mute This Topic: https://groups.io/mt/94113631/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 Sat Nov 23 21:33:13 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+94700+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+94700+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1664891255; cv=none; d=zohomail.com; s=zohoarc; b=El1dds0irqO3EERMM61xCn0pIXjjOL1l2fbj3GPtaEyh5fxkSc+aO5MYkrBKK5a7tDcUigmaDAxl7+aKw6eV6E1isstd/vFvaXCGIAs/uQhPZenRaHi2gpXFNh7gByuc2RNym2VyFsk+xwXKXxBv9XC12bjhldGrQV/f0x4f94g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664891255; 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=7B96VxKlocAiiw4rbAT4EverdfLQPgO0XFJta2fW1mk=; b=CIjrA5IdcHCKJgIF+tdl6xy8qyHeD9OM3leg9ZWIqCMrjKy4DyZIPO/IsbyKreyBkvZOgA8t/ncF4jy4IE6Jm4QSj+mnu8rlsRI0tjEY6+YUgUQT4qycERwOjaKv8goTIkpqGoRFsKHggUot1dI8eKoAbMDPGze/KuhebNYcFUs= 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+94700+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 1664891255233673.7527948300868; Tue, 4 Oct 2022 06:47:35 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Gtw8YY1788612x0BVJqXFsNF; Tue, 04 Oct 2022 06:47:34 -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.web11.10736.1664891253770303024 for ; Tue, 04 Oct 2022 06:47:34 -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-48-_I02o2eYMXOi5otL374vvA-1; Tue, 04 Oct 2022 09:47:31 -0400 X-MC-Unique: _I02o2eYMXOi5otL374vvA-1 X-Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4365B382C966; Tue, 4 Oct 2022 13:47:31 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.193.173]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 104F5C15BA4; Tue, 4 Oct 2022 13:47:31 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 1A93518017F9; Tue, 4 Oct 2022 15:47:28 +0200 (CEST) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Jordan Justen , Gerd Hoffmann , Pawel Polawski , Jiewen Yao , Oliver Steffen , Ard Biesheuvel Subject: [edk2-devel] [PATCH v2 3/4] OvmfPkg/PlatformInitLib: dynamic mmio window size Date: Tue, 4 Oct 2022 15:47:27 +0200 Message-Id: <20221004134728.55499-4-kraxel@redhat.com> In-Reply-To: <20221004134728.55499-1-kraxel@redhat.com> References: <20221004134728.55499-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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: pbD0fVZID1y9VLUMHNvjYfgzx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1664891254; bh=1z06z5MRqB75FxHeJ9wGBYx9It3sK1bVfRPHzZUb0Jg=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=YV4UfCrh95inAJ7A8+0gLS1ZiOxy3yX2vn+FXWGZ/Sqa7VLoDcs4UHjiMRK8uRf/B5a d80q8wJ9ePQkiAwe5fwfldTg5P4xh5ZR0ar7+RaIFGD6N8t91aOdHCC282kj/KqxzLT+Y O13njK0fJzQPfQmQxu6fJ3beuxnk865hGHM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1664891256785100008 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 (#94700): https://edk2.groups.io/g/devel/message/94700 Mute This Topic: https://groups.io/mt/94113626/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 Sat Nov 23 21:33:13 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+94701+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+94701+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1664891258; cv=none; d=zohomail.com; s=zohoarc; b=LkBBvQCUr9kL6wRjfOpl8HaNpj5lPQ9V1FWk4oOg2//24tyXIqTYwQ6oZP/fQvNLLznVwZ5Pt3BRAIvzm3f+PSHy5YuSBR1XZAdmYyeFvskTei02gvuCQqBw6bZ1r5SsnSYaV1uuM6jLilLkVPoTEFQvjNFE1BddEpGQW1gBh5c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664891258; 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=z8Y2fM10bLp25kVTGAtiQ/1nDsx0/UGMOtzwBPN5ijE=; b=JIulTfk9vEvrQtgCKkGNb5f5ApeUWcqDMPEwkRA2iFgWKE1PutuL6OEut/q0C1bSFcVa3RiuSXKpNj+zHQbCaYyHgm6sRtryNplfw4fDMFdAH3PKNsMhqyaPw6k9XDEw41rcctPQr1GZz4g+vfxRbBbB7/B1jda0PY52JrLwWo4= 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+94701+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 1664891258916753.8411952559854; Tue, 4 Oct 2022 06:47:38 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id PD5aYY1788612xAtLzXpP4Wd; Tue, 04 Oct 2022 06:47:37 -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.10831.1664891256726628098 for ; Tue, 04 Oct 2022 06:47:36 -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-606-flDFvIPJMw6AP8y2ihmamA-1; Tue, 04 Oct 2022 09:47:33 -0400 X-MC-Unique: flDFvIPJMw6AP8y2ihmamA-1 X-Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A79E38027FE; Tue, 4 Oct 2022 13:47:32 +0000 (UTC) X-Received: from sirius.home.kraxel.org (unknown [10.39.193.173]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 52ADD40EFB00; Tue, 4 Oct 2022 13:47:32 +0000 (UTC) X-Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 203C41801F26; Tue, 4 Oct 2022 15:47:28 +0200 (CEST) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Jordan Justen , Gerd Hoffmann , Pawel Polawski , Jiewen Yao , Oliver Steffen , Ard Biesheuvel , Laszlo Ersek Subject: [edk2-devel] [PATCH v2 4/4] OvmfPkg/PciHotPlugInitDxe: reserve more mmio space Date: Tue, 4 Oct 2022 15:47:28 +0200 Message-Id: <20221004134728.55499-5-kraxel@redhat.com> In-Reply-To: <20221004134728.55499-1-kraxel@redhat.com> References: <20221004134728.55499-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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: OJlQ0d9oGQC1AvMokqbGnW3Mx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1664891257; bh=Ct9JPArTFYcjm7YetTweYXc6cezb3HjpSjtOEDF/hWU=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=i4EQUwHanTFpdgC7llwhNAxD73EsHDaYzQQQDDvYnRITNnuOhtzMnvzsgTQ0XfCT8HT gZq4XQEzIQDEmyhIRopE3xAGIe8xV/oX2XRFQ1IZl94RPWnfFNRbTvIQofFkAiNiwUdpO n8w0p5+87Yd9zWoEvgQLOieEJgPGT6tRPZ4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1664891260901100004 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. Cc: Laszlo Ersek Signed-off-by: Gerd Hoffmann Reviewed-by: Laszlo Ersek --- OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf | 1 + OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.c | 21 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) 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..3f9c84cf2b54 100644 --- a/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.c +++ b/OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.c @@ -556,6 +556,7 @@ GetResourcePadding ( EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS *Address; BOOLEAN DefaultIo; BOOLEAN DefaultMmio; + BOOLEAN DefaultPrefMmio; RESOURCE_PADDING ReservationRequest; EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *FirstResource; EFI_STATUS ReservationHintStatus; @@ -588,8 +589,9 @@ GetResourcePadding ( return EFI_INVALID_PARAMETER; } =20 - DefaultIo =3D TRUE; - DefaultMmio =3D TRUE; + DefaultIo =3D TRUE; + DefaultMmio =3D TRUE; + DefaultPrefMmio =3D TRUE; =20 // // Init ReservationRequest, and point FirstResource one past the last @@ -722,6 +724,7 @@ GetResourcePadding ( HighBit =3D HighBitSetRoundUp32 (ReservationHint.Prefetchable32BitMm= io); if (HighBit !=3D -1) { SetMmioPadding (--FirstResource, TRUE, TRUE, (UINTN)HighBit); + DefaultPrefMmio =3D FALSE; } } else if ((ReservationHint.Prefetchable64BitMmio > 0) && (ReservationHint.Prefetchable64BitMmio < MAX_UINT64)) @@ -729,6 +732,7 @@ GetResourcePadding ( HighBit =3D HighBitSetRoundUp64 (ReservationHint.Prefetchable64BitMm= io); if (HighBit !=3D -1) { SetMmioPadding (--FirstResource, TRUE, FALSE, (UINTN)HighBit); + DefaultPrefMmio =3D FALSE; } } } @@ -752,6 +756,19 @@ GetResourcePadding ( ); } =20 + if (DefaultPrefMmio) { + UINT64 Pci64Size =3D PcdGet64 (PcdPciMmio64Size); + + if (Pci64Size > SIZE_32GB) { + SetMmioPadding ( + --FirstResource, + TRUE, + FALSE, + (UINTN)HighBitSetRoundUp64 (RShiftU64 (Pci64Size, 8)) + ); + } + } + // // Output a copy of ReservationRequest from the lowest-address populated // entry until the end of the structure (including --=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 (#94701): https://edk2.groups.io/g/devel/message/94701 Mute This Topic: https://groups.io/mt/94113630/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-