From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.132.183.28; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B141B21196221 for ; Wed, 28 Nov 2018 14:54:31 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0707E3086258; Wed, 28 Nov 2018 22:54:31 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-170.rdu2.redhat.com [10.10.120.170]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8EB1D600C6; Wed, 28 Nov 2018 22:54:25 +0000 (UTC) To: Ard Biesheuvel , edk2-devel@lists.01.org Cc: Eric Auger , Andrew Jones , Philippe Mathieu-Daude References: <20181128191646.31526-1-ard.biesheuvel@linaro.org> <20181128191646.31526-2-ard.biesheuvel@linaro.org> From: Laszlo Ersek Message-ID: <7c047366-2b63-08fc-079e-98705c7efa6b@redhat.com> Date: Wed, 28 Nov 2018 23:54:24 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20181128191646.31526-2-ard.biesheuvel@linaro.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 28 Nov 2018 22:54:31 +0000 (UTC) Subject: Re: [RFC PATCH 1/2] ArmVirtPkg/NorFlashQemuLib: disregard our primary FV X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Nov 2018 22:54:31 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 11/28/18 20:16, Ard Biesheuvel wrote: > The primary FV contains the firmware boot image, which is not > runtime updatable in our case. So exposing it to the NOR flash > driver is undesirable, since it may attempt to modify the NOR > flash contents. With you so far. > It is also rather pointless, since we don't > keep anything there that we don't already expose via the FVB > protocol instances that DXE core creates for us based on the > FV HOBs I don't follow -- the DXE core does rely on the FV HOBs that we create for it, but I don't remember the DXE core creating FVB protocol instances. An FVB ("firmware volume block") protocol instance is usually created by a flash driver. What am I missing? Do you mean handles with MemoryMapped(...)/FvFile(...) and Fv(...)/FvFile(...) device paths on them? That point into firmware volumes (that have been supposedly decompressed from flash to RAM)? > (and so there is nothing the partition or file system > drivers could potentially attach to via the block I/O and disk > I/O protocol instances that the NOR flash driver creates) Ugh, NorFlashDxe creates BlockIo and DiskIo interfaces itself??? Let's see... /* Although DiskIoDxe will automatically install the DiskIO protocol whenever we install the BlockIO protocol, its implementation is sub-optimal as it reads and writes entire blocks using the BlockIO protocol. In fact we can access NOR flash with a finer granularity than that, so we can improve performance by directly producing the DiskIO protocol. */ Umm... this flash driver does a lot more than I thought it did... or should. :) Anyway I think it should suffice to say in the commit message that we don't want to expose the first flash device as an FVB protocol instance, because (a) it's read-only, and (b) in the DXE phase, we don't use anything from that flash device. It contains: - the reset vector, - the SEC module, - (for ArmVirtQemu) the non-compressed PEI core, and PEIMs, - and a compressed bunch of DXE modules (incl. the DXE core) which are decompressed to RAM anyway. > So let's disregard the NOR flash block that covers the primary > FV. OK. > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ard Biesheuvel > --- > ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf | 5 +++++ > ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c | 13 +++++++++++-- > 2 files changed, 16 insertions(+), 2 deletions(-) > > diff --git a/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf b/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf > index d86ff36dbd58..c5752a243e6b 100644 > --- a/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf > +++ b/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf > @@ -28,6 +28,7 @@ [Sources.common] > [Packages] > MdePkg/MdePkg.dec > ArmPlatformPkg/ArmPlatformPkg.dec > + ArmPkg/ArmPkg.dec > ArmVirtPkg/ArmVirtPkg.dec > > [LibraryClasses] > @@ -40,3 +41,7 @@ [Protocols] > > [Depex] > gFdtClientProtocolGuid > + > +[Pcd] > + gArmTokenSpaceGuid.PcdFvBaseAddress > + gArmTokenSpaceGuid.PcdFvSize > diff --git a/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c b/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c > index 2678f57eaaad..72b47bdb5a78 100644 > --- a/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c > +++ b/ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c > @@ -75,13 +75,22 @@ NorFlashPlatformGetDevices ( > Size = SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[2])); > Reg += 4; > > + PropSize -= 4 * sizeof (UINT32); > + > + // > + // Disregard any flash devices that overlap with the primary FV. > + // The firmware is not updatable from inside the guest anyway. > + // > + if ((PcdGet64 (PcdFvBaseAddress) + PcdGet32 (PcdFvSize) >= Base) && > + (Base + Size) >= PcdGet64 (PcdFvBaseAddress)) { > + continue; > + } > + The overlap condition is expressed correctly, in general, I think; however, both subconditions are off-by-one each. In each, we compare an exclusive limit (one's end) with an inclusive limit (the other's base). And, when exclusive equals inclusive, there is no overlap; they are directly adjacent only. I'd drop the equal signs. > mNorFlashDevices[Num].DeviceBaseAddress = (UINTN)Base; > mNorFlashDevices[Num].RegionBaseAddress = (UINTN)Base; > mNorFlashDevices[Num].Size = (UINTN)Size; > mNorFlashDevices[Num].BlockSize = QEMU_NOR_BLOCK_SIZE; > Num++; > - > - PropSize -= 4 * sizeof (UINT32); > } > } > > Thanks Laszlo