Skip to content

Commit f41e27b

Browse files
emuslngregkh
authored andcommitted
pds_core: specify auxiliary_device to be created
[ Upstream commit b699bdc ] In preparation for adding a new auxiliary_device for the PF, make the vif type an argument to pdsc_auxbus_dev_add(). Pass in the address of the padev pointer so that the caller can specify where to save it and keep the mutex usage within the function. Link: https://patch.msgid.link/r/[email protected] Reviewed-by: Leon Romanovsky <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Reviewed-by: Dave Jiang <[email protected]> Signed-off-by: Shannon Nelson <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Stable-dep-of: dfd7601 ("pds_core: remove write-after-free of client_id") Signed-off-by: Sasha Levin <[email protected]>
1 parent 1d69ab8 commit f41e27b

File tree

4 files changed

+33
-27
lines changed

4 files changed

+33
-27
lines changed

drivers/net/ethernet/amd/pds_core/auxbus.c

+18-19
Original file line numberDiff line numberDiff line change
@@ -172,29 +172,32 @@ static struct pds_auxiliary_dev *pdsc_auxbus_dev_register(struct pdsc *cf,
172172
return padev;
173173
}
174174

175-
void pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf)
175+
void pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf,
176+
struct pds_auxiliary_dev **pd_ptr)
176177
{
177178
struct pds_auxiliary_dev *padev;
178179

180+
if (!*pd_ptr)
181+
return;
182+
179183
mutex_lock(&pf->config_lock);
180184

181-
padev = pf->vfs[cf->vf_id].padev;
182-
if (padev) {
183-
pds_client_unregister(pf, padev->client_id);
184-
auxiliary_device_delete(&padev->aux_dev);
185-
auxiliary_device_uninit(&padev->aux_dev);
186-
padev->client_id = 0;
187-
}
188-
pf->vfs[cf->vf_id].padev = NULL;
185+
padev = *pd_ptr;
186+
pds_client_unregister(pf, padev->client_id);
187+
auxiliary_device_delete(&padev->aux_dev);
188+
auxiliary_device_uninit(&padev->aux_dev);
189+
padev->client_id = 0;
190+
*pd_ptr = NULL;
189191

190192
mutex_unlock(&pf->config_lock);
191193
}
192194

193-
int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf)
195+
int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf,
196+
enum pds_core_vif_types vt,
197+
struct pds_auxiliary_dev **pd_ptr)
194198
{
195199
struct pds_auxiliary_dev *padev;
196200
char devname[PDS_DEVNAME_LEN];
197-
enum pds_core_vif_types vt;
198201
unsigned long mask;
199202
u16 vt_support;
200203
int client_id;
@@ -203,6 +206,9 @@ int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf)
203206
if (!cf)
204207
return -ENODEV;
205208

209+
if (vt >= PDS_DEV_TYPE_MAX)
210+
return -EINVAL;
211+
206212
mutex_lock(&pf->config_lock);
207213

208214
mask = BIT_ULL(PDSC_S_FW_DEAD) |
@@ -214,17 +220,10 @@ int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf)
214220
goto out_unlock;
215221
}
216222

217-
/* We only support vDPA so far, so it is the only one to
218-
* be verified that it is available in the Core device and
219-
* enabled in the devlink param. In the future this might
220-
* become a loop for several VIF types.
221-
*/
222-
223223
/* Verify that the type is supported and enabled. It is not
224224
* an error if there is no auxbus device support for this
225225
* VF, it just means something else needs to happen with it.
226226
*/
227-
vt = PDS_DEV_TYPE_VDPA;
228227
vt_support = !!le16_to_cpu(pf->dev_ident.vif_types[vt]);
229228
if (!(vt_support &&
230229
pf->viftype_status[vt].supported &&
@@ -250,7 +249,7 @@ int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf)
250249
err = PTR_ERR(padev);
251250
goto out_unlock;
252251
}
253-
pf->vfs[cf->vf_id].padev = padev;
252+
*pd_ptr = padev;
254253

255254
out_unlock:
256255
mutex_unlock(&pf->config_lock);

drivers/net/ethernet/amd/pds_core/core.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,11 @@ void pdsc_health_thread(struct work_struct *work);
303303
int pdsc_register_notify(struct notifier_block *nb);
304304
void pdsc_unregister_notify(struct notifier_block *nb);
305305
void pdsc_notify(unsigned long event, void *data);
306-
int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf);
307-
void pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf);
306+
int pdsc_auxbus_dev_add(struct pdsc *cf, struct pdsc *pf,
307+
enum pds_core_vif_types vt,
308+
struct pds_auxiliary_dev **pd_ptr);
309+
void pdsc_auxbus_dev_del(struct pdsc *cf, struct pdsc *pf,
310+
struct pds_auxiliary_dev **pd_ptr);
308311

309312
void pdsc_process_adminq(struct pdsc_qcq *qcq);
310313
void pdsc_work_thread(struct work_struct *work);

drivers/net/ethernet/amd/pds_core/devlink.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ int pdsc_dl_enable_set(struct devlink *dl, u32 id,
5757
struct pdsc *vf = pdsc->vfs[vf_id].vf;
5858

5959
if (ctx->val.vbool)
60-
err = pdsc_auxbus_dev_add(vf, pdsc);
60+
err = pdsc_auxbus_dev_add(vf, pdsc, vt_entry->vif_id,
61+
&pdsc->vfs[vf_id].padev);
6162
else
62-
pdsc_auxbus_dev_del(vf, pdsc);
63+
pdsc_auxbus_dev_del(vf, pdsc, &pdsc->vfs[vf_id].padev);
6364
}
6465

6566
return err;

drivers/net/ethernet/amd/pds_core/main.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ static int pdsc_init_vf(struct pdsc *vf)
190190
devl_unlock(dl);
191191

192192
pf->vfs[vf->vf_id].vf = vf;
193-
err = pdsc_auxbus_dev_add(vf, pf);
193+
err = pdsc_auxbus_dev_add(vf, pf, PDS_DEV_TYPE_VDPA,
194+
&pf->vfs[vf->vf_id].padev);
194195
if (err) {
195196
devl_lock(dl);
196197
devl_unregister(dl);
@@ -417,7 +418,7 @@ static void pdsc_remove(struct pci_dev *pdev)
417418

418419
pf = pdsc_get_pf_struct(pdsc->pdev);
419420
if (!IS_ERR(pf)) {
420-
pdsc_auxbus_dev_del(pdsc, pf);
421+
pdsc_auxbus_dev_del(pdsc, pf, &pf->vfs[pdsc->vf_id].padev);
421422
pf->vfs[pdsc->vf_id].vf = NULL;
422423
}
423424
} else {
@@ -482,7 +483,8 @@ static void pdsc_reset_prepare(struct pci_dev *pdev)
482483

483484
pf = pdsc_get_pf_struct(pdsc->pdev);
484485
if (!IS_ERR(pf))
485-
pdsc_auxbus_dev_del(pdsc, pf);
486+
pdsc_auxbus_dev_del(pdsc, pf,
487+
&pf->vfs[pdsc->vf_id].padev);
486488
}
487489

488490
pdsc_unmap_bars(pdsc);
@@ -527,7 +529,8 @@ static void pdsc_reset_done(struct pci_dev *pdev)
527529

528530
pf = pdsc_get_pf_struct(pdsc->pdev);
529531
if (!IS_ERR(pf))
530-
pdsc_auxbus_dev_add(pdsc, pf);
532+
pdsc_auxbus_dev_add(pdsc, pf, PDS_DEV_TYPE_VDPA,
533+
&pf->vfs[pdsc->vf_id].padev);
531534
}
532535
}
533536

0 commit comments

Comments
 (0)