Skip to content

Commit 35ff867

Browse files
pierrecregutbjorn-helgaas
authored andcommitted
PCI/IOV: Serialize sysfs sriov_numvfs reads vs writes
When sriov_numvfs is being updated, we call the driver->sriov_configure() function, which may enable VFs and call probe functions, which may make new devices visible. This all happens before before sriov_numvfs_store() updates sriov->num_VFs, so previously, concurrent sysfs reads of sriov_numvfs returned stale values. Serialize the sysfs read vs the write so the read returns the correct num_VFs value. [bhelgaas: hold device_lock instead of checking mutex_is_locked()] Link: https://bugzilla.kernel.org/show_bug.cgi?id=202991 Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Pierre Crégut <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]>
1 parent 56b4cd4 commit 35ff867

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/pci/iov.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,14 @@ static ssize_t sriov_numvfs_show(struct device *dev,
254254
char *buf)
255255
{
256256
struct pci_dev *pdev = to_pci_dev(dev);
257+
u16 num_vfs;
258+
259+
/* Serialize vs sriov_numvfs_store() so readers see valid num_VFs */
260+
device_lock(&pdev->dev);
261+
num_vfs = pdev->sriov->num_VFs;
262+
device_unlock(&pdev->dev);
257263

258-
return sprintf(buf, "%u\n", pdev->sriov->num_VFs);
264+
return sprintf(buf, "%u\n", num_vfs);
259265
}
260266

261267
/*

0 commit comments

Comments
 (0)