OSDN Git Service

vfio/pci: Use kernel VPD access functions
authorAlex Williamson <alex.williamson@redhat.com>
Tue, 27 Oct 2015 20:53:05 +0000 (14:53 -0600)
committerAlex Williamson <alex.williamson@redhat.com>
Tue, 27 Oct 2015 20:53:05 +0000 (14:53 -0600)
commit4e1a635552d3df7bb743de8c2be156293c53839e
treeca4997c28062babbe93bea6915580711539191dc
parent5f096b14d421ba23249b752e41989ecfaa6ae226
vfio/pci: Use kernel VPD access functions

The PCI VPD capability operates on a set of window registers in PCI
config space.  Writing to the address register triggers either a read
or write, depending on the setting of the PCI_VPD_ADDR_F bit within
the address register.  The data register provides either the source
for writes or the target for reads.

This model is susceptible to being broken by concurrent access, for
which the kernel has adopted a set of access functions to serialize
these registers.  Additionally, commits like 932c435caba8 ("PCI: Add
dev_flags bit to access VPD through function 0") and 7aa6ca4d39ed
("PCI: Add VPD function 0 quirk for Intel Ethernet devices") indicate
that VPD registers can be shared between functions on multifunction
devices creating dependencies between otherwise independent devices.

Fortunately it's quite easy to emulate the VPD registers, simply
storing copies of the address and data registers in memory and
triggering a VPD read or write on writes to the address register.
This allows vfio users to avoid seeing spurious register changes from
accesses on other devices and enables the use of shared quirks in the
host kernel.  We can theoretically still race with access through
sysfs, but the window of opportunity is much smaller.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Acked-by: Mark Rustad <mark.d.rustad@intel.com>
drivers/vfio/pci/vfio_pci_config.c