Skip to content

Commit 99cb233

Browse files
Benjamin Lijbarnes993
authored andcommitted
PCI: Limit VPD read/write lengths for Broadcom 5706, 5708, 5709 rev.
For Broadcom 5706, 5708, 5709 rev. A nics, any read beyond the VPD end tag will hang the device. This problem was initially observed when a vpd entry was created in sysfs ('/sys/bus/pci/devices/<id>/vpd'). A read to this sysfs entry will dump 32k of data. Reading a full 32k will cause an access beyond the VPD end tag causing the device to hang. Once the device is hung, the bnx2 driver will not be able to reset the device. We believe that it is legal to read beyond the end tag and therefore the solution is to limit the read/write length. A majority of this patch is from Matthew Wilcox who gave code for reworking the PCI vpd size information. A PCI quirk added for the Broadcom NIC's to limit the read/write's. Signed-off-by: Benjamin Li <benli@broadcom.com> Signed-off-by: Matthew Wilcox <willy@linux.intel.com> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
1 parent a94c248 commit 99cb233

4 files changed

Lines changed: 48 additions & 12 deletions

File tree

‎drivers/pci/access.c‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,7 @@ static int pci_vpd_pci22_read(struct pci_dev *dev, int pos, int size,
178178
int ret;
179179
int begin, end, i;
180180

181-
if (pos < 0 || pos > PCI_VPD_PCI22_SIZE ||
182-
size > PCI_VPD_PCI22_SIZE - pos)
181+
if (pos < 0 || pos > vpd->base.len || size > vpd->base.len - pos)
183182
return -EINVAL;
184183
if (size == 0)
185184
return 0;
@@ -223,8 +222,8 @@ static int pci_vpd_pci22_write(struct pci_dev *dev, int pos, int size,
223222
u32 val;
224223
int ret;
225224

226-
if (pos < 0 || pos > PCI_VPD_PCI22_SIZE || pos & 3 ||
227-
size > PCI_VPD_PCI22_SIZE - pos || size < 4)
225+
if (pos < 0 || pos > vpd->base.len || pos & 3 ||
226+
size > vpd->base.len - pos || size < 4)
228227
return -EINVAL;
229228

230229
val = (u8) *buf++;
@@ -255,11 +254,6 @@ static int pci_vpd_pci22_write(struct pci_dev *dev, int pos, int size,
255254
return 4;
256255
}
257256

258-
static int pci_vpd_pci22_get_size(struct pci_dev *dev)
259-
{
260-
return PCI_VPD_PCI22_SIZE;
261-
}
262-
263257
static void pci_vpd_pci22_release(struct pci_dev *dev)
264258
{
265259
kfree(container_of(dev->vpd, struct pci_vpd_pci22, base));
@@ -268,7 +262,6 @@ static void pci_vpd_pci22_release(struct pci_dev *dev)
268262
static struct pci_vpd_ops pci_vpd_pci22_ops = {
269263
.read = pci_vpd_pci22_read,
270264
.write = pci_vpd_pci22_write,
271-
.get_size = pci_vpd_pci22_get_size,
272265
.release = pci_vpd_pci22_release,
273266
};
274267

@@ -284,6 +277,7 @@ int pci_vpd_pci22_init(struct pci_dev *dev)
284277
if (!vpd)
285278
return -ENOMEM;
286279

280+
vpd->base.len = PCI_VPD_PCI22_SIZE;
287281
vpd->base.ops = &pci_vpd_pci22_ops;
288282
spin_lock_init(&vpd->lock);
289283
vpd->cap = cap;

‎drivers/pci/pci-sysfs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
736736
attr = kzalloc(sizeof(*attr), GFP_ATOMIC);
737737
if (attr) {
738738
pdev->vpd->attr = attr;
739-
attr->size = pdev->vpd->ops->get_size(pdev);
739+
attr->size = pdev->vpd->len;
740740
attr->attr.name = "vpd";
741741
attr->attr.mode = S_IRUSR | S_IWUSR;
742742
attr->read = pci_read_vpd;

‎drivers/pci/pci.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ extern int pci_user_write_config_dword(struct pci_dev *dev, int where, u32 val);
2121
struct pci_vpd_ops {
2222
int (*read)(struct pci_dev *dev, int pos, int size, char *buf);
2323
int (*write)(struct pci_dev *dev, int pos, int size, const char *buf);
24-
int (*get_size)(struct pci_dev *dev);
2524
void (*release)(struct pci_dev *dev);
2625
};
2726

2827
struct pci_vpd {
28+
unsigned int len;
2929
struct pci_vpd_ops *ops;
3030
struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
3131
};

‎drivers/pci/quirks.c‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,48 @@ static void __devinit quirk_via_cx700_pci_parking_caching(struct pci_dev *dev)
16701670
}
16711671
DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_VIA, 0x324e, quirk_via_cx700_pci_parking_caching);
16721672

1673+
/*
1674+
* For Broadcom 5706, 5708, 5709 rev. A nics, any read beyond the
1675+
* VPD end tag will hang the device. This problem was initially
1676+
* observed when a vpd entry was created in sysfs
1677+
* ('/sys/bus/pci/devices/<id>/vpd'). A read to this sysfs entry
1678+
* will dump 32k of data. Reading a full 32k will cause an access
1679+
* beyond the VPD end tag causing the device to hang. Once the device
1680+
* is hung, the bnx2 driver will not be able to reset the device.
1681+
* We believe that it is legal to read beyond the end tag and
1682+
* therefore the solution is to limit the read/write length.
1683+
*/
1684+
static void __devinit quirk_brcm_570x_limit_vpd(struct pci_dev *dev)
1685+
{
1686+
/* Only disable the VPD capability for 5706, 5708, and 5709 rev. A */
1687+
if ((dev->device == PCI_DEVICE_ID_NX2_5706) ||
1688+
(dev->device == PCI_DEVICE_ID_NX2_5708) ||
1689+
((dev->device == PCI_DEVICE_ID_NX2_5709) &&
1690+
(dev->revision & 0xf0) == 0x0)) {
1691+
if (dev->vpd)
1692+
dev->vpd->len = 0x80;
1693+
}
1694+
}
1695+
1696+
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_BROADCOM,
1697+
PCI_DEVICE_ID_NX2_5706,
1698+
quirk_brcm_570x_limit_vpd);
1699+
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_BROADCOM,
1700+
PCI_DEVICE_ID_NX2_5706S,
1701+
quirk_brcm_570x_limit_vpd);
1702+
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_BROADCOM,
1703+
PCI_DEVICE_ID_NX2_5708,
1704+
quirk_brcm_570x_limit_vpd);
1705+
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_BROADCOM,
1706+
PCI_DEVICE_ID_NX2_5708S,
1707+
quirk_brcm_570x_limit_vpd);
1708+
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_BROADCOM,
1709+
PCI_DEVICE_ID_NX2_5709,
1710+
quirk_brcm_570x_limit_vpd);
1711+
DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_BROADCOM,
1712+
PCI_DEVICE_ID_NX2_5709S,
1713+
quirk_brcm_570x_limit_vpd);
1714+
16731715
#ifdef CONFIG_PCI_MSI
16741716
/* Some chipsets do not support MSI. We cannot easily rely on setting
16751717
* PCI_BUS_FLAGS_NO_MSI in its bus flags because there are actually

0 commit comments

Comments
 (0)