diff options
author | Pierre Crégut <pierre.cregut@orange.com> | 2019-09-11 09:27:36 +0200 |
---|---|---|
committer | Bjorn Helgaas <bhelgaas@google.com> | 2019-10-15 23:39:12 +0200 |
commit | 35ff867b76576e32f34c698ccd11343f7d616204 (patch) | |
tree | 8475dcbce83eebc0c4761b8565e27f7e721f6be5 /drivers/pci/iov.c | |
parent | PCI: Add DMA alias quirk for Intel VCA NTB (diff) | |
download | linux-35ff867b76576e32f34c698ccd11343f7d616204.tar.xz linux-35ff867b76576e32f34c698ccd11343f7d616204.zip |
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/20190911072736.32091-1-pierre.cregut@orange.com
Signed-off-by: Pierre Crégut <pierre.cregut@orange.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Diffstat (limited to 'drivers/pci/iov.c')
-rw-r--r-- | drivers/pci/iov.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index b3f972e8cfed..1d3de1ea081d 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -254,8 +254,14 @@ static ssize_t sriov_numvfs_show(struct device *dev, char *buf) { struct pci_dev *pdev = to_pci_dev(dev); + u16 num_vfs; + + /* Serialize vs sriov_numvfs_store() so readers see valid num_VFs */ + device_lock(&pdev->dev); + num_vfs = pdev->sriov->num_VFs; + device_unlock(&pdev->dev); - return sprintf(buf, "%u\n", pdev->sriov->num_VFs); + return sprintf(buf, "%u\n", num_vfs); } /* |