From 98800cce65c4eab75a1d0d387990982640e0300e Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Fri, 24 Apr 2020 09:53:48 +0200 Subject: OvmfPkg/PlatformPei: parse "X-PciMmio64Mb" with QemuFwCfgSimpleParserLib MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the - QemuFwCfgFindFile(), - QemuFwCfgSelectItem(), - QemuFwCfgReadBytes(), - AsciiStrDecimalToUint64() sequence in the GetFirstNonAddress() function with a call to QemuFwCfgSimpleParserLib. This change is compatible with valid strings accepted previously. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Per Sundstrom Cc: Philippe Mathieu-Daudé Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2681 Signed-off-by: Laszlo Ersek Message-Id: <20200424075353.8489-3-lersek@redhat.com> Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Ard Biesheuvel --- OvmfPkg/PlatformPei/MemDetect.c | 36 +++++++++++++++++++++--------------- OvmfPkg/PlatformPei/PlatformPei.inf | 1 + 2 files changed, 22 insertions(+), 15 deletions(-) (limited to 'OvmfPkg/PlatformPei') diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDetect.c index 47dc9c5437..f32df937f9 100644 --- a/OvmfPkg/PlatformPei/MemDetect.c +++ b/OvmfPkg/PlatformPei/MemDetect.c @@ -33,6 +33,7 @@ Module Name: #include #include #include +#include #include "Platform.h" #include "Cmos.h" @@ -336,7 +337,7 @@ GetFirstNonAddress ( { UINT64 FirstNonAddress; UINT64 Pci64Base, Pci64Size; - CHAR8 MbString[7 + 1]; + UINT32 FwCfgPciMmio64Mb; EFI_STATUS Status; FIRMWARE_CONFIG_ITEM FwCfgItem; UINTN FwCfgSize; @@ -379,25 +380,30 @@ GetFirstNonAddress ( // // See if the user specified the number of megabytes for the 64-bit PCI host - // aperture. The number of non-NUL characters in MbString allows for - // 9,999,999 MB, which is approximately 10 TB. + // aperture. Accept an aperture size up to 16TB. // // As signaled by the "X-" prefix, this knob is experimental, and might go // away at any time. // - Status = QemuFwCfgFindFile ("opt/ovmf/X-PciMmio64Mb", &FwCfgItem, - &FwCfgSize); - if (!EFI_ERROR (Status)) { - if (FwCfgSize >= sizeof MbString) { - DEBUG ((EFI_D_WARN, - "%a: ignoring malformed 64-bit PCI host aperture size from fw_cfg\n", - __FUNCTION__)); - } else { - QemuFwCfgSelectItem (FwCfgItem); - QemuFwCfgReadBytes (FwCfgSize, MbString); - MbString[FwCfgSize] = '\0'; - Pci64Size = LShiftU64 (AsciiStrDecimalToUint64 (MbString), 20); + Status = QemuFwCfgParseUint32 ("opt/ovmf/X-PciMmio64Mb", FALSE, + &FwCfgPciMmio64Mb); + switch (Status) { + case EFI_UNSUPPORTED: + case EFI_NOT_FOUND: + break; + case EFI_SUCCESS: + if (FwCfgPciMmio64Mb <= 0x1000000) { + Pci64Size = LShiftU64 (FwCfgPciMmio64Mb, 20); + break; } + // + // fall through + // + default: + DEBUG ((DEBUG_WARN, + "%a: ignoring malformed 64-bit PCI host aperture size from fw_cfg\n", + __FUNCTION__)); + break; } if (Pci64Size == 0) { diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/PlatformPei.inf index 19f2424981..e72ef7963d 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -60,6 +60,7 @@ PeimEntryPoint QemuFwCfgLib QemuFwCfgS3Lib + QemuFwCfgSimpleParserLib MtrrLib MemEncryptSevLib PcdLib -- cgit v1.2.3