public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "wenyi,xie" <xiewenyi2@huawei.com>
To: <devel@edk2.groups.io>, <jian.j.wang@intel.com>,
	<gaoliming@byosoft.com.cn>, <hao.a.wu@intel.com>,
	<ray.ni@intel.com>
Cc: <songdongkuang@huawei.com>, <xiewenyi2@huawei.com>,
	<kejiayi1@huawei.com>
Subject: [PATCH EDK2 v1 1/1] MdeModulePkg/PciBucDxe:Fix issue when initial SR-IVO
Date: Fri, 14 Jan 2022 17:31:25 +0800	[thread overview]
Message-ID: <20220114093125.69742-2-xiewenyi2@huawei.com> (raw)
In-Reply-To: <20220114093125.69742-1-xiewenyi2@huawei.com>

Reference:https://bugzilla.tianocore.org/show_bug.cgi?id=3804

When calculating SR-IOV reserve bus in function CreatePciIoDevice(),
there are two points may have problem.
LastVF = PFRid + FirstVFOffset + (PciIoDevice->InitialVFs - 1) * VFStride;
PciIoDevice->ReservedBusNum =
(UINT16)(EFI_PCI_BUS_OF_RID (LastVF) - Bus + 1);

The first is that if the value of PciIoDevice->InitialVFs is 0, it will
cause overflow, it's better to check InitialVFs before used.
The second is that if number of bus is not enough for all PF and still
allocate bus for VF, it will lead to PCI enumerating failure.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Wenyi Xie <xiewenyi2@huawei.com>
---
 MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c
index 9251388bc268..a4d1db534276 100644
--- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c
+++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c
@@ -2402,12 +2402,12 @@ CreatePciIoDevice (
       // Calculate LastVF
       //
       PFRid  = EFI_PCI_RID (Bus, Device, Func);
-      LastVF = PFRid + FirstVFOffset + (PciIoDevice->InitialVFs - 1) * VFStride;
+      LastVF = PFRid + FirstVFOffset + (PciIoDevice->InitialVFs == 0 ? 0 : PciIoDevice->InitialVFs - 1) * VFStride;
 
       //
       // Calculate ReservedBusNum for this PF
       //
-      PciIoDevice->ReservedBusNum = (UINT16)(EFI_PCI_BUS_OF_RID (LastVF) - Bus + 1);
+      PciIoDevice->ReservedBusNum = (UINT16)(EFI_PCI_BUS_OF_RID (LastVF) - Bus);
 
       DEBUG ((
         DEBUG_INFO,
-- 
2.20.1.windows.1


      reply	other threads:[~2022-01-14  9:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-14  9:31 [PATCH EDK2 v1 0/1] MdeModulePkg/PciBucDxe:Fix issue when initial SR-IVO wenyi,xie
2022-01-14  9:31 ` wenyi,xie [this message]

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=20220114093125.69742-2-xiewenyi2@huawei.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