From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.120]) by mx.groups.io with SMTP id smtpd.web12.2156.1587718311381429004 for ; Fri, 24 Apr 2020 01:51:51 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BWSXo4Wr; spf=pass (domain: redhat.com, ip: 205.139.110.120, mailfrom: philmd@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587718310; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AGgq0KJcvB6QL+m0tXFUFAScn6E4PEibHXPHMFGImvY=; b=BWSXo4WrVonnSupWWHOGjEYfEO9GrdLgBn4j8BAU2o5j14uYTm89CCXLXAQ7TDGu0FPGtF jFNfbpdGQWOXxb/dlW0uFcD0vXKV7zY5L3QDBe5gHA9b8oNrqX+/NHrGtU3IRoBVhYDJHt Mxezs+kiUEvaFDDTt1fiFOpvrn3uxyU= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-456-dxqnQubCPZaZa-OKjOKSng-1; Fri, 24 Apr 2020 04:51:43 -0400 X-MC-Unique: dxqnQubCPZaZa-OKjOKSng-1 Received: by mail-ej1-f71.google.com with SMTP id gj7so4494253ejb.9 for ; Fri, 24 Apr 2020 01:51:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=WSSZpbrPlLVeTV8EoCyWItscAcSJPx9VBu+CBDnuzgU=; b=q5Egf4X6c85KUFxF9o4SmredeBBBQzDWVF2rHDP6x6JHbDK1VoBE6Q06L9qzOQazRP Xx3xEvNjaL+3RvyNwaqq9w7yw+sq22jXyLzsfmpYDoCvF73+WqgRh2CI3WXXC5rhFZVk h5TqpqUHgSjX5Ra6Ij0iCvhBN3nV3vPJhVwSv6E9uBr+eBYS7LHBdNt+GK+RK7uz92C6 YjsyiF07oE54X61eydCzAt0s/KewEdzly72N4BEySpBxuWHSwBuYn69lQip+LJPY8Tqy g1vJ8q6tiIxa2xSAe7mVC4TjT4oXSw6FhMXPDFAZupjAiyRSytEO5nppLOwQaTiAcpdf hYtw== X-Gm-Message-State: AGi0PuazjtoR2d+HW2RtjHrUZwD+4FDiM0sAc0qIY1jOxJPv9UaCpZr7 6X87Oy1bjm4TlCP34Ic8guvCHjRgxzn9sUMAumA5D70oR0lftOLKOdThk2G2GCXliGkMm61/RzR thorAMfD7X5hpaw== X-Received: by 2002:a05:6402:1d23:: with SMTP id dh3mr6185354edb.349.1587718301746; Fri, 24 Apr 2020 01:51:41 -0700 (PDT) X-Google-Smtp-Source: APiQypIBjQ4TABB/8o3CGKF3gBupiVhEilJhkiy58wcPYIzKmafkZaBVRAv5roioffEzjGNE7mMojQ== X-Received: by 2002:a05:6402:1d23:: with SMTP id dh3mr6185344edb.349.1587718301473; Fri, 24 Apr 2020 01:51:41 -0700 (PDT) Return-Path: Received: from [192.168.1.39] (116.red-83-42-57.dynamicip.rima-tde.net. [83.42.57.116]) by smtp.gmail.com with ESMTPSA id gq21sm680447ejb.90.2020.04.24.01.51.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Apr 2020 01:51:40 -0700 (PDT) Subject: Re: [PATCH 2/7] OvmfPkg/PlatformPei: parse "X-PciMmio64Mb" with QemuFwCfgSimpleParserLib To: Laszlo Ersek , edk2-devel-groups-io Cc: Ard Biesheuvel , Jordan Justen , Per Sundstrom References: <20200424075353.8489-1-lersek@redhat.com> <20200424075353.8489-3-lersek@redhat.com> From: =?UTF-8?B?UGhpbGlwcGUgTWF0aGlldS1EYXVkw6k=?= Message-ID: <8d48eb9f-3715-fd8e-37c4-fe6ab141461a@redhat.com> Date: Fri, 24 Apr 2020 10:51:39 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200424075353.8489-3-lersek@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable On 4/24/20 9:53 AM, Laszlo Ersek wrote: > Replace the >=20 > - QemuFwCfgFindFile(), > - QemuFwCfgSelectItem(), > - QemuFwCfgReadBytes(), > - AsciiStrDecimalToUint64() >=20 > sequence in the GetFirstNonAddress() function with a call to > QemuFwCfgSimpleParserLib. >=20 > This change is compatible with valid strings accepted previously. >=20 > Cc: Ard Biesheuvel > Cc: Jordan Justen > Cc: Per Sundstrom > Cc: Philippe Mathieu-Daud=C3=A9 > Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2681 > Signed-off-by: Laszlo Ersek > --- > OvmfPkg/PlatformPei/PlatformPei.inf | 1 + > OvmfPkg/PlatformPei/MemDetect.c | 36 ++++++++++++-------- > 2 files changed, 22 insertions(+), 15 deletions(-) >=20 > diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Pl= atformPei.inf > index 19f2424981bc..e72ef7963d97 100644 > --- a/OvmfPkg/PlatformPei/PlatformPei.inf > +++ b/OvmfPkg/PlatformPei/PlatformPei.inf > @@ -60,6 +60,7 @@ [LibraryClasses] > PeimEntryPoint > QemuFwCfgLib > QemuFwCfgS3Lib > + QemuFwCfgSimpleParserLib > MtrrLib > MemEncryptSevLib > PcdLib > diff --git a/OvmfPkg/PlatformPei/MemDetect.c b/OvmfPkg/PlatformPei/MemDet= ect.c > index 47dc9c543719..f32df937f9ba 100644 > --- a/OvmfPkg/PlatformPei/MemDetect.c > +++ b/OvmfPkg/PlatformPei/MemDetect.c > @@ -33,6 +33,7 @@ Module Name: > #include > #include > #include > +#include > =20 > #include "Platform.h" > #include "Cmos.h" > @@ -336,7 +337,7 @@ GetFirstNonAddress ( > { > UINT64 FirstNonAddress; > UINT64 Pci64Base, Pci64Size; > - CHAR8 MbString[7 + 1]; Replaced by UINT64_STRING_MAX_SIZE + CRLF_LENGTH, way safer. > + UINT32 FwCfgPciMmio64Mb; > EFI_STATUS Status; > FIRMWARE_CONFIG_ITEM FwCfgItem; > UINTN FwCfgSize; > @@ -379,25 +380,30 @@ GetFirstNonAddress ( > =20 > // > // See if the user specified the number of megabytes for the 64-bit P= CI 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 mig= ht go > // away at any time. > // > - Status =3D QemuFwCfgFindFile ("opt/ovmf/X-PciMmio64Mb", &FwCfgItem, > - &FwCfgSize); > - if (!EFI_ERROR (Status)) { > - if (FwCfgSize >=3D sizeof MbString) { > - DEBUG ((EFI_D_WARN, > - "%a: ignoring malformed 64-bit PCI host aperture size from fw_cf= g\n", > - __FUNCTION__)); > - } else { > - QemuFwCfgSelectItem (FwCfgItem); > - QemuFwCfgReadBytes (FwCfgSize, MbString); Up to here is QemuFwCfgGetAsString(), OK. > - MbString[FwCfgSize] =3D '\0'; StripNewline(), OK. > - Pci64Size =3D LShiftU64 (AsciiStrDecimalToUint64 (MbString), 20); > + Status =3D QemuFwCfgParseUint32 ("opt/ovmf/X-PciMmio64Mb", FALSE, ParseAsHex=3DFalse, so we use AsciiStrDecimalToUint64S(), OK. > + &FwCfgPciMmio64Mb); > + switch (Status) { > + case EFI_UNSUPPORTED: > + case EFI_NOT_FOUND: > + break; > + case EFI_SUCCESS: > + if (FwCfgPciMmio64Mb <=3D 0x1000000) { > + Pci64Size =3D LShiftU64 (FwCfgPciMmio64Mb, 20); 16TB, OK. > + break; > } > + // > + // fall through > + // > + default: > + DEBUG ((DEBUG_WARN, > + "%a: ignoring malformed 64-bit PCI host aperture size from fw_cfg\= n", > + __FUNCTION__)); > + break; > } > =20 > if (Pci64Size =3D=3D 0) { >=20 The new API is very clean! Reviewed-by: Philippe Mathieu-Daude