From: Laszlo Ersek <lersek@redhat.com>
To: Ruiyu Ni <ruiyu.ni@intel.com>, edk2-devel@lists.01.org
Cc: Garrett <Garrett.Kirkendall@amd.com>,
Star Zeng <star.zeng@intel.com>,
Kirkendall@ml01.01.org
Subject: Re: [PATCH 2/3] MdeModulePkg/PciHostBridge: Fix a bug that prevents PMEM access
Date: Fri, 21 Sep 2018 13:06:12 +0200 [thread overview]
Message-ID: <95b75c62-43e6-e92e-3de8-04e3fdd9cd7b@redhat.com> (raw)
In-Reply-To: <20180921072539.268068-3-ruiyu.ni@intel.com>
On 09/21/18 09:25, Ruiyu Ni wrote:
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1196
>
> RootBridgeIoCheckParameter() verifies that the requested MMIO access
> can fit in any of the MEM/PMEM 32/64 ranges. But today's logic
> somehow only checks the requested access against MEM 32/64 ranges.
>
> It should also check the requested access against PMEM 32/64 ranges.
>
> The patch fixes this issue.
>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
> Cc: Star Zeng <star.zeng@intel.com>
> Cc: Kirkendall, Garrett <Garrett.Kirkendall@amd.com>
> ---
> MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c | 14 ++++++++++----
> 1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c
> index 0b6b56f846..f6234b5d11 100644
> --- a/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c
> +++ b/MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciRootBridgeIo.c
> @@ -411,12 +411,18 @@ RootBridgeIoCheckParameter (
> // By comparing the Address against Limit we know which range to be used
> // for checking
> //
> - if (Address + Length <= RootBridge->Mem.Limit + 1) {
> - Base = RootBridge->Mem.Base;
> + if ((Address >= RootBridge->Mem.Base) && (Address + Length <= RootBridge->Mem.Limit + 1)) {
> + Base = RootBridge->Mem.Base;
> Limit = RootBridge->Mem.Limit;
> - } else {
> - Base = RootBridge->MemAbove4G.Base;
> + } else if ((Address >= RootBridge->PMem.Base) && (Address + Length <= RootBridge->PMem.Limit + 1)) {
> + Base = RootBridge->PMem.Base;
> + Limit = RootBridge->PMem.Limit;
> + } else if ((Address >= RootBridge->MemAbove4G.Base) && (Address + Length <= RootBridge->MemAbove4G.Limit + 1)) {
> + Base = RootBridge->MemAbove4G.Base;
> Limit = RootBridge->MemAbove4G.Limit;
> + } else {
> + Base = RootBridge->PMemAbove4G.Base;
> + Limit = RootBridge->PMemAbove4G.Limit;
> }
> } else {
> PciRbAddr = (EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS*) &Address;
>
The interesting thing about this patch is that, if any one of the first
three branches is taken, then the final checks will automatically pass.
That's because, on the first three branches, we select the base & the
limit *because* the access falls between them. Therefore, in the end,
when we check whether the access falls between base and end, they
miraculously happen to do so. :)
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Thanks
Laszlo
next prev parent reply other threads:[~2018-09-21 11:06 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-21 7:25 [PATCH 0/3] Fix a bug that prevents PMEM access Ruiyu Ni
2018-09-21 7:25 ` [PATCH 1/3] MdeModulePkg/PciHostBridge: Enhance boundary check in Io/Mem.Read/Write Ruiyu Ni
2018-09-21 10:53 ` Laszlo Ersek
2018-09-24 13:18 ` Kirkendall, Garrett
2018-09-25 2:14 ` Zeng, Star
2018-09-25 2:43 ` Ni, Ruiyu
2018-09-25 3:02 ` Zeng, Star
2018-09-21 7:25 ` [PATCH 2/3] MdeModulePkg/PciHostBridge: Fix a bug that prevents PMEM access Ruiyu Ni
2018-09-21 11:06 ` Laszlo Ersek [this message]
2018-09-25 2:11 ` Ni, Ruiyu
2018-09-24 13:19 ` Kirkendall, Garrett
2018-09-25 2:15 ` Zeng, Star
2018-09-21 7:25 ` [PATCH 3/3] MdeModulePkg/PciHostBridge: Add RESOURCE_VALID() to simplify code Ruiyu Ni
2018-09-21 11:12 ` Laszlo Ersek
2018-09-25 2:25 ` Ni, Ruiyu
2018-09-25 2:35 ` Zeng, Star
2018-09-25 2:47 ` Ni, Ruiyu
2018-09-25 3:13 ` Zeng, Star
2018-09-25 5:03 ` Ni, Ruiyu
2018-09-24 13:20 ` Kirkendall, Garrett
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=95b75c62-43e6-e92e-3de8-04e3fdd9cd7b@redhat.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