From nobody Sun Feb 8 11:22:02 2026 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+86055+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+86055+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1643121288; cv=none; d=zohomail.com; s=zohoarc; b=WHq0iuNbH7xL4h4zOmu22jT/eiJaKuLFPEfSEtALy9EWA4y0LNkMTSQGskFXCEGaQWqO864CDKgBuC3kXEKJkPZk7mipl9/JoiTxw8qteeRvXD+Ag3xzjg1M2Em1LEyl8dl9CzSSazAg8YDge5gl3ojr0UEYm4M6iN3T/eNN5dY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1643121288; h=Content-Type: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=POWztCt9A6zydBHDRoO9FStLD5NS9VVkxf69io3JGzM=; b=TYGwWyLEPScq2i4RBl5dcOZ4hXePO0eSqsaSc+KuDB22wxmyVu+NVR8OovP8Hea5prTV+VIpfRC6Gv2CdF+vvDKXNbjF4GSLhWebQCS0jxH5wn970snAOcWOqsaikF2GlqBYCoqlaRmORvdTd9AFjcGhX7qFHlG8HPYy2WRnruw= 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+86055+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 164312128881789.11449327772971; Tue, 25 Jan 2022 06:34:48 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id XaX5YY1788612xm4oefaIH2F; Tue, 25 Jan 2022 06:34:48 -0800 X-Received: from smtp-fw-9103.amazon.com (smtp-fw-9103.amazon.com [207.171.188.200]) by mx.groups.io with SMTP id smtpd.web11.7699.1643121287564294670 for ; Tue, 25 Jan 2022 06:34:47 -0800 X-IronPort-AV: E=Sophos;i="5.88,315,1635206400"; d="scan'208";a="987181371" X-Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-iad-1d-b48bc93b.us-east-1.amazon.com) ([10.25.36.210]) by smtp-border-fw-9103.sea19.amazon.com with ESMTP; 25 Jan 2022 14:34:32 +0000 X-Received: from EX13D49EUC003.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1d-b48bc93b.us-east-1.amazon.com (Postfix) with ESMTPS id AF1DAC099C; Tue, 25 Jan 2022 14:34:31 +0000 (UTC) X-Received: from ub4014a598e6c52.ant.amazon.com (10.43.160.207) by EX13D49EUC003.ant.amazon.com (10.43.164.91) with Microsoft SMTP Server (TLS) id 15.0.1497.28; Tue, 25 Jan 2022 14:34:27 +0000 From: "Ojeda Leon, Nicolas via groups.io" To: CC: , Nicolas Ojeda Leon , Alexander Graf , Gerd Hoffmann Subject: [edk2-devel] [PATCH v3 4/8] Ovmf/PlatformPei: Use host-provided GPA end if available Date: Tue, 25 Jan 2022 15:30:11 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.43.160.207] X-ClientProxiedBy: EX13D46UWB004.ant.amazon.com (10.43.161.204) To EX13D49EUC003.ant.amazon.com (10.43.164.91) 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,ncoleon@amazon.com X-Gm-Message-State: RQWLW4uOpdJkWBXavgoL2bHrx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1643121288; bh=VHMFMJ6vNmwbB/y545Svm67OGEeTmYhA38QB6jJ5i2U=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=ZgRLuEsLInoO4cUYgRAGzU3z4ResBQLwZ65dx2rVr9Qb48N9zxx0d33lV9K5HmJMZYz TLBhleenVX01Na9MKTF2Qu1TuvHUde4ZhPjQg3Qm3fUmY9n5kzwAKXRU9SXEMwm6g9uzt vUsIXfO/rsy09JWsbM0IyIN6NNR+8hL7w3Q= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1643121291642100003 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Read the "hardware-info" item from fw-cfg to extract specifications of PCI host bridges and analyze the 64-bit apertures of them to find out the highest 64-bit MMIO address required which determines the address space required by the guest, and, consequently, the FirstNonAddress used to calculate size of physical addresses. Using the static PeiHardwareInfoLib, read the fw-cfg file of hardware information to extract, one by one, all the host bridges. Find the last 64-bit MMIO address of each host bridge, using the HardwareInfoPciHostBridgeLib API, and compare it to an accumulate value to discover the highest address used, which corresponds to the highest value that must be included in the guest's physical address space. Given that platforms with multiple host bridges may provide the PCI apertures' addresses, the memory detection logic must take into account that, if the host provided the MMIO windows that can and must be used, the guest needs to take those values. Therefore, if the MMIO windows are found in the host-provided fw-cfg file, skip all the logic calculating the physical address size and just use the value provided. Since each PCI host bridge corresponds to an element in the information provided by the host, each of these must be analyzed looking for the highest address used. Cc: Alexander Graf Cc: Gerd Hoffmann Signed-off-by: Nicolas Ojeda Leon Acked-by: Gerd Hoffmann --- OvmfPkg/PlatformPei/MemDetect.c | 146 ++++++++++++++++++++++++++-- OvmfPkg/PlatformPei/PlatformPei.inf | 1 + 2 files changed, 141 insertions(+), 6 deletions(-) diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetec= t.c index 1bcb5a08bc..26f6df7e7e 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -36,6 +36,7 @@ Module Name: #include #include #include +#include =20 #include "Platform.h" #include "Cmos.h" @@ -369,6 +370,126 @@ GetSystemMemorySizeAbove4gb ( return LShiftU64 (Size, 16); } =20 +/** + 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 + the information is found, return the exclusive end; one past the last us= able + address. + + @param[out] PciMmioAddressEnd Pointer to one-after End Address updated w= ith + information extracted from host-provided d= ata + or zero if no information available or an + error happened + + @retval EFI_SUCCESS PCI information was read and the output + parameter updated with the last valid + address in the 64-bit MMIO range. + @retval EFI_INVALID_PARAMETER Pointer parameter is invalid + @retval EFI_INCOMPATIBLE_VERSION Hardware information found in fw-cfg + has an incompatible format + @retval EFI_UNSUPPORTED Fw-cfg is not supported, thus host + provided information, if any, cannot be + read + @retval EFI_NOT_FOUND No PCI host bridge information provided + by the host. +**/ +STATIC +EFI_STATUS +ScanHostProvided64BitPciMmioEnd ( + OUT UINT64 *PciMmioAddressEnd + ) +{ + EFI_STATUS Status; + HOST_BRIDGE_INFO HostBridge; + FIRMWARE_CONFIG_ITEM FwCfgItem; + UINTN FwCfgSize; + UINTN FwCfgReadIndex; + UINTN ReadDataSize; + UINT64 Above4GMmioEnd; + + if (PciMmioAddressEnd =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + *PciMmioAddressEnd =3D 0; + Above4GMmioEnd =3D 0; + + Status =3D QemuFwCfgFindFile ("etc/hardware-info", &FwCfgItem, &FwCfgSiz= e); + if (EFI_ERROR (Status)) { + return Status; + } + + QemuFwCfgSelectItem (FwCfgItem); + + FwCfgReadIndex =3D 0; + while (FwCfgReadIndex < FwCfgSize) { + Status =3D QemuFwCfgReadNextHardwareInfoByType ( + HardwareInfoTypeHostBridge, + sizeof (HostBridge), + FwCfgSize, + &HostBridge, + &ReadDataSize, + &FwCfgReadIndex + ); + + if (Status !=3D EFI_SUCCESS) { + // + // No more data available to read in the file, break + // loop and finish process + // + break; + } + + Status =3D HardwareInfoPciHostBridgeLastMmioAddress ( + &HostBridge, + ReadDataSize, + TRUE, + &Above4GMmioEnd + ); + + if (Status !=3D EFI_SUCCESS) { + // + // Error parsing MMIO apertures and extracting last MMIO + // address, reset PciMmioAddressEnd as if no information was + // found, to avoid moving forward with incomplete data, and + // bail out + // + DEBUG (( + DEBUG_ERROR, + "%a: ignoring malformed hardware information from fw_cfg\n", + __FUNCTION__ + )); + *PciMmioAddressEnd =3D 0; + return Status; + } + + if (Above4GMmioEnd > *PciMmioAddressEnd) { + *PciMmioAddressEnd =3D Above4GMmioEnd; + } + } + + if (*PciMmioAddressEnd > 0) { + // + // Host-provided PCI information was found and a MMIO window end + // derived from it. + // Increase the End address by one to have the output pointing to + // one after the address in use (exclusive end). + // + *PciMmioAddressEnd +=3D 1; + + DEBUG (( + DEBUG_INFO, + "%a: Pci64End=3D0x%Lx\n", + __FUNCTION__, + *PciMmioAddressEnd + )); + + return EFI_SUCCESS; + } + + return EFI_NOT_FOUND; +} + /** Return the highest address that DXE could possibly use, plus one. **/ @@ -550,15 +671,28 @@ AddressWidthInitialization ( VOID ) { - UINT64 FirstNonAddress; + UINT64 FirstNonAddress; + EFI_STATUS Status; =20 // - // As guest-physical memory size grows, the permanent PEI RAM requiremen= ts - // are dominated by the identity-mapping page tables built by the DXE IP= L. - // The DXL IPL keys off of the physical address bits advertized in the C= PU - // HOB. To conserve memory, we calculate the minimum address width here. + // First scan host-provided hardware information to assess if the address + // space is already known. If so, guest must use those values. // - FirstNonAddress =3D GetFirstNonAddress (); + Status =3D ScanHostProvided64BitPciMmioEnd (&FirstNonAddress); + + if (EFI_ERROR (Status)) { + // + // If the host did not provide valid hardware information leading to a + // hard-defined 64-bit MMIO end, fold back to calculating the minimum = range + // needed. + // As guest-physical memory size grows, the permanent PEI RAM requirem= ents + // are dominated by the identity-mapping page tables built by the DXE = IPL. + // The DXL IPL keys off of the physical address bits advertized in the= CPU + // HOB. To conserve memory, we calculate the minimum address width her= e. + // + FirstNonAddress =3D GetFirstNonAddress (); + } + mPhysMemAddressWidth =3D (UINT8)HighBitSet64 (FirstNonAddress); =20 // diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index 8ef404168c..e840f960d3 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -64,6 +64,7 @@ MemEncryptSevLib PcdLib VmgExitLib + PeiHardwareInfoLib =20 [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvBase --=20 2.17.1 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879 -=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 (#86055): https://edk2.groups.io/g/devel/message/86055 Mute This Topic: https://groups.io/mt/88672492/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-