From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.736.1587708482718822544 for ; Thu, 23 Apr 2020 23:08:03 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: ard.biesheuvel@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B79CE31B; Thu, 23 Apr 2020 23:08:01 -0700 (PDT) Received: from [10.37.8.121] (unknown [10.37.8.121]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8B57F3F68F; Thu, 23 Apr 2020 23:08:00 -0700 (PDT) Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/PciHostBridge: Update Mem and PMem Limit Checks To: devel@edk2.groups.io, wasim.khan@nxp.com, Ard Biesheuvel Cc: Varun Sethi , "Wu, Hao A" , "Ni, Ray" References: <1587638612-13056-1-git-send-email-wasim.khan@nxp.com> From: "Ard Biesheuvel" Message-ID: Date: Fri, 24 Apr 2020 08:07:59 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit On 4/24/20 6:35 AM, Wasim Khan via groups.io wrote: > > >> -----Original Message----- >> From: Ard Biesheuvel >> Sent: Friday, April 24, 2020 12:27 AM >> To: Wasim Khan >> Cc: edk2-devel-groups-io ; Varun Sethi >> ; Wu, Hao A ; Ni, Ray >> >> Subject: Re: [PATCH] MdeModulePkg/PciHostBridge: Update Mem and PMem >> Limit Checks >> >> On Thu, 23 Apr 2020 at 12:43, Wasim Khan wrote: >>> >>> With Address Translation Support, it is possible and also correct that >>> Mem and Pmem Limit cross the 4GB boundary. >>> Update the checks so that Mem/PMem Limit should not cross 4GB from the >>> Mem/PMem Base address. >>> >>> Signed-off-by: Wasim Khan >>> --- >>> MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c | 8 ++++---- >>> 1 file changed, 4 insertions(+), 4 deletions(-) >>> >>> diff --git a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c >>> b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c >>> index d304fae..9cf7e98 100644 >>> --- a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c >>> +++ b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c >>> @@ -117,8 +117,8 @@ CreateRootBridge ( >>> // Make sure Mem and MemAbove4G apertures are valid >>> // >>> if (RESOURCE_VALID (&Bridge->Mem)) { >>> - ASSERT (Bridge->Mem.Limit < SIZE_4GB); >>> - if (Bridge->Mem.Limit >= SIZE_4GB) { >>> + ASSERT (Bridge->Mem.Limit < (Bridge->Mem.Base + SIZE_4GB)); >>> + if (Bridge->Mem.Limit >= (Bridge->Mem.Base + SIZE_4GB)) { >>> return NULL; >>> } >>> } >>> @@ -129,8 +129,8 @@ CreateRootBridge ( >>> } >>> } >>> if (RESOURCE_VALID (&Bridge->PMem)) { >>> - ASSERT (Bridge->PMem.Limit < SIZE_4GB); >>> - if (Bridge->PMem.Limit >= SIZE_4GB) { >>> + ASSERT (Bridge->PMem.Limit < (Bridge->PMem.Base + SIZE_4GB)); >>> + if (Bridge->PMem.Limit >= (Bridge->PMem.Base + SIZE_4GB)) { >>> return NULL; >>> } >>> } >>> -- >>> 2.7.4 >>> >> >> This is not the right fix. >> >> The translation offset should be taken into account for these checks > > Thanks for the review Ard. > device address = host address + translation offset. > Mem and Pmem represents "device address" , so that are already taking translation offset into account. > OK, apparently I am missing something. For the MMIO32 window, the limit has to be < 4 GB, since the whole region needs to be 32-bit addressable. Otherwise, how are you going to allocate a 32-bit BAR from the part of the window that is > 4 GB ?