Skip to content

Commit 3cddb79

Browse files
niklas88hcahca
authored andcommitted
s390/pci: fix zpci_bus_link_virtfn()
We were missing the pci_dev_put() for candidate PFs. Furhtermore in discussion with upstream it turns out that somewhat counterintuitively some common code, in particular the vfio-pci driver, assumes that pdev->is_virtfn always implies that pdev->physfn is set, i.e. that VFs are always linked. While POWER does seem to set pdev->is_virtfn even for unlinked functions (see comments in arch/powerpc/kernel/eeh.c:eeh_debugfs_break_device()) for now just be safe and only set pdev->is_virtfn on linking. Also make sure that we only search for parent PFs if the zbus is multifunction and we thus know the devfn values supplied by firmware come from the RID. Fixes: e5794cf ("s390/pci: create links between PFs and VFs") Cc: <[email protected]> # 5.8 Reviewed-by: Pierre Morel <[email protected]> Signed-off-by: Niklas Schnelle <[email protected]> Signed-off-by: Heiko Carstens <[email protected]>
1 parent fd78c59 commit 3cddb79

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

arch/s390/pci/pci_bus.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,14 @@ static int zpci_bus_link_virtfn(struct pci_dev *pdev,
132132
{
133133
int rc;
134134

135-
virtfn->physfn = pci_dev_get(pdev);
136135
rc = pci_iov_sysfs_link(pdev, virtfn, vfid);
137-
if (rc) {
138-
pci_dev_put(pdev);
139-
virtfn->physfn = NULL;
136+
if (rc)
140137
return rc;
141-
}
138+
139+
virtfn->is_virtfn = 1;
140+
virtfn->multifunction = 0;
141+
virtfn->physfn = pci_dev_get(pdev);
142+
142143
return 0;
143144
}
144145

@@ -151,9 +152,9 @@ static int zpci_bus_setup_virtfn(struct zpci_bus *zbus,
151152
int vfid = vfn - 1; /* Linux' vfid's start at 0 vfn at 1*/
152153
int rc = 0;
153154

154-
virtfn->is_virtfn = 1;
155-
virtfn->multifunction = 0;
156-
WARN_ON(vfid < 0);
155+
if (!zbus->multifunction)
156+
return 0;
157+
157158
/* If the parent PF for the given VF is also configured in the
158159
* instance, it must be on the same zbus.
159160
* We can then identify the parent PF by checking what
@@ -165,11 +166,17 @@ static int zpci_bus_setup_virtfn(struct zpci_bus *zbus,
165166
zdev = zbus->function[i];
166167
if (zdev && zdev->is_physfn) {
167168
pdev = pci_get_slot(zbus->bus, zdev->devfn);
169+
if (!pdev)
170+
continue;
168171
cand_devfn = pci_iov_virtfn_devfn(pdev, vfid);
169172
if (cand_devfn == virtfn->devfn) {
170173
rc = zpci_bus_link_virtfn(pdev, virtfn, vfid);
174+
/* balance pci_get_slot() */
175+
pci_dev_put(pdev);
171176
break;
172177
}
178+
/* balance pci_get_slot() */
179+
pci_dev_put(pdev);
173180
}
174181
}
175182
return rc;
@@ -178,8 +185,6 @@ static int zpci_bus_setup_virtfn(struct zpci_bus *zbus,
178185
static inline int zpci_bus_setup_virtfn(struct zpci_bus *zbus,
179186
struct pci_dev *virtfn, int vfn)
180187
{
181-
virtfn->is_virtfn = 1;
182-
virtfn->multifunction = 0;
183188
return 0;
184189
}
185190
#endif

0 commit comments

Comments
 (0)