From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mx.groups.io with SMTP id smtpd.web08.5270.1642152696352512983 for ; Fri, 14 Jan 2022 01:31:38 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: huawei.com, ip: 45.249.212.189, mailfrom: xiewenyi2@huawei.com) Received: from kwepemi500003.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4JZwwG5jP1z8wN9; Fri, 14 Jan 2022 17:28:46 +0800 (CST) Received: from kwepemm600004.china.huawei.com (7.193.23.242) by kwepemi500003.china.huawei.com (7.221.188.51) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Fri, 14 Jan 2022 17:31:31 +0800 Received: from kwephisprg16640.huawei.com (10.247.83.252) by kwepemm600004.china.huawei.com (7.193.23.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Fri, 14 Jan 2022 17:31:30 +0800 From: "wenyi,xie" To: , , , , CC: , , Subject: [PATCH EDK2 v1 1/1] MdeModulePkg/PciBucDxe:Fix issue when initial SR-IVO Date: Fri, 14 Jan 2022 17:31:25 +0800 Message-ID: <20220114093125.69742-2-xiewenyi2@huawei.com> X-Mailer: git-send-email 2.18.0.huawei.25 In-Reply-To: <20220114093125.69742-1-xiewenyi2@huawei.com> References: <20220114093125.69742-1-xiewenyi2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.247.83.252] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600004.china.huawei.com (7.193.23.242) X-CFilter-Loop: Reflected Content-Type: text/plain 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 Cc: Liming Gao Cc: Hao A Wu Cc: Ray Ni Signed-off-by: Wenyi Xie --- 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