History

PCI/IOV: Introduce pci_iov_sysfs_link() function

Currently pci_iov_add_virtfn() scans the SR-IOV BARs, adds the VF to the bus and also creates the sysfs links between the newly added VF and its parent PF. With pdev->no_vf_scan fencing off the entire pci_iov_add_virtfn() call s390 as the sole pdev->no_vf_scan user thus ends up missing these sysfs links which are required for example by QEMU/libvirt. Instead of duplicating the code refactor pci_iov_add_virtfn() to make sysfs link creation callable separately.

Niklas Schnelle committed 6 years ago

Commit a1ceea61 parent c70d82e2 files · +33 −11Browse files

Unified · Split

2 files
  1. drivers/pci/iov.c +25 −11
  2. include/linux/pci.h +8 −0
drivers/pci/iov.c+25−11
@@ -133,12 +133,35 @@ static void pci_read_vf_config_common(struct pci_dev *virtfn) · 132 unmodified lines
133133 &physfn->sriov->subsystem_device);
134134 }
135135
136+int pci_iov_sysfs_link(struct pci_dev *dev,
137+ struct pci_dev *virtfn, int id)
138+{
139+ char buf[VIRTFN_ID_LEN];
140+ int rc;
141+
142+ sprintf(buf, "virtfn%u", id);
143+ rc = sysfs_create_link(&dev->dev.kobj, &virtfn->dev.kobj, buf);
144+ if (rc)
145+ goto failed;
146+ rc = sysfs_create_link(&virtfn->dev.kobj, &dev->dev.kobj, "physfn");
147+ if (rc)
148+ goto failed1;
149+
150+ kobject_uevent(&virtfn->dev.kobj, KOBJ_CHANGE);
151+
152+ return 0;
153+
154+failed1:
155+ sysfs_remove_link(&dev->dev.kobj, buf);
156+failed:
157+ return rc;
158+}
159+
136160 int pci_iov_add_virtfn(struct pci_dev *dev, int id)
137161 {
138162 int i;
139163 int rc = -ENOMEM;
140164 u64 size;
141− char buf[VIRTFN_ID_LEN];
142165 struct pci_dev *virtfn;
143166 struct resource *res;
144167 struct pci_sriov *iov = dev->sriov;
@@ -182,23 +205,14 @@ int pci_iov_add_virtfn(struct pci_dev *dev, int id) · 37 unmodified lines
182205 }
183206
184207 pci_device_add(virtfn, virtfn->bus);
185−
186− sprintf(buf, "virtfn%u", id);
187− rc = sysfs_create_link(&dev->dev.kobj, &virtfn->dev.kobj, buf);
208+ rc = pci_iov_sysfs_link(dev, virtfn, id);
188209 if (rc)
189210 goto failed1;
190− rc = sysfs_create_link(&virtfn->dev.kobj, &dev->dev.kobj, "physfn");
191− if (rc)
192− goto failed2;
193−
194− kobject_uevent(&virtfn->dev.kobj, KOBJ_CHANGE);
195211
196212 pci_bus_add_device(virtfn);
197213
198214 return 0;
199215
200−failed2:
201− sysfs_remove_link(&dev->dev.kobj, buf);
202216 failed1:
203217 pci_stop_and_remove_bus_device(virtfn);
204218 pci_dev_put(dev);
include/linux/pci.h+8−0
@@ -2048,6 +2048,8 @@ int pci_iov_virtfn_devfn(struct pci_dev *dev, int id); · 2047 unmodified lines
20482048
20492049 int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn);
20502050 void pci_disable_sriov(struct pci_dev *dev);
2051+
2052+int pci_iov_sysfs_link(struct pci_dev *dev, struct pci_dev *virtfn, int id);
20512053 int pci_iov_add_virtfn(struct pci_dev *dev, int id);
20522054 void pci_iov_remove_virtfn(struct pci_dev *dev, int id);
20532055 int pci_num_vf(struct pci_dev *dev);
@@ -2073,6 +2075,12 @@ static inline int pci_iov_virtfn_devfn(struct pci_dev *dev, int id) · 19 unmodified lines
20732075 }
20742076 static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
20752077 { return -ENODEV; }
2078+
2079+static inline int pci_iov_sysfs_link(struct pci_dev *dev,
2080+ struct pci_dev *virtfn, int id)
2081+{
2082+ return -ENODEV;
2083+}
20762084 static inline int pci_iov_add_virtfn(struct pci_dev *dev, int id)
20772085 {
20782086 return -ENOSYS;