public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Wasim Khan" <wasim.khan@nxp.com>
To: "Ni, Ray" <ray.ni@intel.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: "ard.biesheuvel@linaro.org" <ard.biesheuvel@linaro.org>,
	Varun Sethi <V.Sethi@nxp.com>, "Wu, Hao A" <hao.a.wu@intel.com>
Subject: Re: [PATCH] MdeModulePkg/PciHostBridge: Update Mem and PMem Limit Checks
Date: Thu, 23 Apr 2020 13:52:08 +0000	[thread overview]
Message-ID: <VE1PR04MB6702AC23B499FAE029AB5F6C90D30@VE1PR04MB6702.eurprd04.prod.outlook.com> (raw)
In-Reply-To: <734D49CCEBEEF84792F5B80ED585239D5C50A98E@SHSMSX104.ccr.corp.intel.com>



> -----Original Message-----
> From: Ni, Ray <ray.ni@intel.com>
> Sent: Thursday, April 23, 2020 5:07 PM
> To: Wasim Khan <wasim.khan@nxp.com>; devel@edk2.groups.io
> Cc: ard.biesheuvel@linaro.org; Varun Sethi <V.Sethi@nxp.com>; Wu, Hao A
> <hao.a.wu@intel.com>
> Subject: RE: [PATCH] MdeModulePkg/PciHostBridge: Update Mem and PMem
> Limit Checks
> 
> Thanks for fixing the check.
> 
> PCI_ROOT_BRIDGE_APERTURE.Base/Limit are device address while the memory
> space in GCD belongs to host domain.
> So, host address for Mem/Pmem should be below 4GB while device address can
> across 4GB.
> 


Hi Ray,
Thank you for the review. 
There are cases when we don't have PCIe host address below 4GB, and the PCIe HOST Address space is only available above 4GB. 
For Example, Mem: 40000000 - FFFFFFFF Translation=FFFFFF6000000000 will result in HOST Address = 0xA0FFFFFFFF . This is a valid use case, but below check will report ASSERT for this HOST ADDRESS. 


> Can you enhance the check as below?
>   ASSERT (TO_HOST_ADDRESS (Bridge->Mem.Limit, Bridge->Mem.Translation) <
> SIZE_4GB);
>   if (TO_HOST_ADDRESS (Bridge->Mem.Limit, Bridge->Mem.Translation) >=
> SIZE_4GB) {
>     return NULL;
>   }
> 
> It will look more precise and can detect invalid Mem/Pmem resource.
> 
> > -----Original Message-----
> > From: Wasim Khan <wasim.khan@nxp.com>
> > Sent: Thursday, April 23, 2020 6:44 PM
> > To: devel@edk2.groups.io
> > Cc: ard.biesheuvel@linaro.org; v.sethi@nxp.com; Wu, Hao A
> > <hao.a.wu@intel.com>; Ni, Ray <ray.ni@intel.com>; Wasim Khan
> > <wasim.khan@nxp.com>
> > Subject: [PATCH] MdeModulePkg/PciHostBridge: Update Mem and PMem
> Limit
> > Checks
> >
> > 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 <wasim.khan@nxp.com>
> > ---
> >  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


  reply	other threads:[~2020-04-23 13:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-23 10:43 [PATCH] MdeModulePkg/PciHostBridge: Update Mem and PMem Limit Checks Wasim Khan
2020-04-23 11:36 ` Ni, Ray
2020-04-23 13:52   ` Wasim Khan [this message]
2020-04-23 14:28     ` [edk2-devel] " Ni, Ray
2020-04-23 14:53       ` Wasim Khan
2020-04-23 15:17         ` Ni, Ray
2020-04-23 16:04           ` Wasim Khan
2020-04-23 18:56 ` Ard Biesheuvel
2020-04-24  4:35   ` Wasim Khan
2020-04-24  6:07     ` [edk2-devel] " Ard Biesheuvel
2020-04-24  7:32       ` Wasim Khan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=VE1PR04MB6702AC23B499FAE029AB5F6C90D30@VE1PR04MB6702.eurprd04.prod.outlook.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox