Skip to content

Commit 0ccd733

Browse files
committed
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull virtio fixes from Michael Tsirkin: "Several small bugfixes all over the place" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: vdpa/mlx5: Fix error path during device add vp_vdpa: fix id_table array not null terminated error virtio_pci: Fix admin vq cleanup by using correct info pointer vDPA/ifcvf: Fix pci_read_config_byte() return code handling Fix typo in vringh_test.c vdpa: solidrun: Fix UB bug with devres vsock/virtio: Initialization of the dangling pointer occurring in vsk->trans
2 parents 2d5404c + 83e445e commit 0ccd733

File tree

9 files changed

+45
-42
lines changed

9 files changed

+45
-42
lines changed

drivers/vdpa/ifcvf/ifcvf_base.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ int ifcvf_init_hw(struct ifcvf_hw *hw, struct pci_dev *pdev)
108108
u32 i;
109109

110110
ret = pci_read_config_byte(pdev, PCI_CAPABILITY_LIST, &pos);
111-
if (ret < 0) {
111+
if (ret) {
112112
IFCVF_ERR(pdev, "Failed to read PCI capability list\n");
113113
return -EIO;
114114
}

drivers/vdpa/mlx5/net/mlx5_vnet.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3963,28 +3963,28 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
39633963
mvdev->vdev.dma_dev = &mdev->pdev->dev;
39643964
err = mlx5_vdpa_alloc_resources(&ndev->mvdev);
39653965
if (err)
3966-
goto err_mpfs;
3966+
goto err_alloc;
39673967

39683968
err = mlx5_vdpa_init_mr_resources(mvdev);
39693969
if (err)
3970-
goto err_res;
3970+
goto err_alloc;
39713971

39723972
if (MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) {
39733973
err = mlx5_vdpa_create_dma_mr(mvdev);
39743974
if (err)
3975-
goto err_mr_res;
3975+
goto err_alloc;
39763976
}
39773977

39783978
err = alloc_fixed_resources(ndev);
39793979
if (err)
3980-
goto err_mr;
3980+
goto err_alloc;
39813981

39823982
ndev->cvq_ent.mvdev = mvdev;
39833983
INIT_WORK(&ndev->cvq_ent.work, mlx5_cvq_kick_handler);
39843984
mvdev->wq = create_singlethread_workqueue("mlx5_vdpa_wq");
39853985
if (!mvdev->wq) {
39863986
err = -ENOMEM;
3987-
goto err_res2;
3987+
goto err_alloc;
39883988
}
39893989

39903990
mvdev->vdev.mdev = &mgtdev->mgtdev;
@@ -4010,17 +4010,6 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
40104010
_vdpa_unregister_device(&mvdev->vdev);
40114011
err_reg:
40124012
destroy_workqueue(mvdev->wq);
4013-
err_res2:
4014-
free_fixed_resources(ndev);
4015-
err_mr:
4016-
mlx5_vdpa_clean_mrs(mvdev);
4017-
err_mr_res:
4018-
mlx5_vdpa_destroy_mr_resources(mvdev);
4019-
err_res:
4020-
mlx5_vdpa_free_resources(&ndev->mvdev);
4021-
err_mpfs:
4022-
if (!is_zero_ether_addr(config->mac))
4023-
mlx5_mpfs_del_mac(pfmdev, config->mac);
40244013
err_alloc:
40254014
put_device(&mvdev->vdev.dev);
40264015
return err;

drivers/vdpa/solidrun/snet_main.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ static const struct vdpa_config_ops snet_config_ops = {
555555

556556
static int psnet_open_pf_bar(struct pci_dev *pdev, struct psnet *psnet)
557557
{
558-
char name[50];
558+
char *name;
559559
int ret, i, mask = 0;
560560
/* We don't know which BAR will be used to communicate..
561561
* We will map every bar with len > 0.
@@ -573,7 +573,10 @@ static int psnet_open_pf_bar(struct pci_dev *pdev, struct psnet *psnet)
573573
return -ENODEV;
574574
}
575575

576-
snprintf(name, sizeof(name), "psnet[%s]-bars", pci_name(pdev));
576+
name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "psnet[%s]-bars", pci_name(pdev));
577+
if (!name)
578+
return -ENOMEM;
579+
577580
ret = pcim_iomap_regions(pdev, mask, name);
578581
if (ret) {
579582
SNET_ERR(pdev, "Failed to request and map PCI BARs\n");
@@ -590,10 +593,13 @@ static int psnet_open_pf_bar(struct pci_dev *pdev, struct psnet *psnet)
590593

591594
static int snet_open_vf_bar(struct pci_dev *pdev, struct snet *snet)
592595
{
593-
char name[50];
596+
char *name;
594597
int ret;
595598

596-
snprintf(name, sizeof(name), "snet[%s]-bar", pci_name(pdev));
599+
name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "snet[%s]-bars", pci_name(pdev));
600+
if (!name)
601+
return -ENOMEM;
602+
597603
/* Request and map BAR */
598604
ret = pcim_iomap_regions(pdev, BIT(snet->psnet->cfg.vf_bar), name);
599605
if (ret) {

drivers/vdpa/virtio_pci/vp_vdpa.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,11 @@ static int vp_vdpa_probe(struct pci_dev *pdev, const struct pci_device_id *id)
612612
goto mdev_err;
613613
}
614614

615-
mdev_id = kzalloc(sizeof(struct virtio_device_id), GFP_KERNEL);
615+
/*
616+
* id_table should be a null terminated array, so allocate one additional
617+
* entry here, see vdpa_mgmtdev_get_classes().
618+
*/
619+
mdev_id = kcalloc(2, sizeof(struct virtio_device_id), GFP_KERNEL);
616620
if (!mdev_id) {
617621
err = -ENOMEM;
618622
goto mdev_id_err;
@@ -632,8 +636,8 @@ static int vp_vdpa_probe(struct pci_dev *pdev, const struct pci_device_id *id)
632636
goto probe_err;
633637
}
634638

635-
mdev_id->device = mdev->id.device;
636-
mdev_id->vendor = mdev->id.vendor;
639+
mdev_id[0].device = mdev->id.device;
640+
mdev_id[0].vendor = mdev->id.vendor;
637641
mgtdev->id_table = mdev_id;
638642
mgtdev->max_supported_vqs = vp_modern_get_num_queues(mdev);
639643
mgtdev->supported_features = vp_modern_get_features(mdev);

drivers/virtio/virtio_pci_common.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ MODULE_PARM_DESC(force_legacy,
2424
"Force legacy mode for transitional virtio 1 devices");
2525
#endif
2626

27+
bool vp_is_avq(struct virtio_device *vdev, unsigned int index)
28+
{
29+
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
30+
31+
if (!virtio_has_feature(vdev, VIRTIO_F_ADMIN_VQ))
32+
return false;
33+
34+
return index == vp_dev->admin_vq.vq_index;
35+
}
36+
2737
/* wait for pending irq handlers */
2838
void vp_synchronize_vectors(struct virtio_device *vdev)
2939
{
@@ -234,10 +244,9 @@ static struct virtqueue *vp_setup_vq(struct virtio_device *vdev, unsigned int in
234244
return vq;
235245
}
236246

237-
static void vp_del_vq(struct virtqueue *vq)
247+
static void vp_del_vq(struct virtqueue *vq, struct virtio_pci_vq_info *info)
238248
{
239249
struct virtio_pci_device *vp_dev = to_vp_device(vq->vdev);
240-
struct virtio_pci_vq_info *info = vp_dev->vqs[vq->index];
241250
unsigned long flags;
242251

243252
/*
@@ -258,13 +267,16 @@ static void vp_del_vq(struct virtqueue *vq)
258267
void vp_del_vqs(struct virtio_device *vdev)
259268
{
260269
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
270+
struct virtio_pci_vq_info *info;
261271
struct virtqueue *vq, *n;
262272
int i;
263273

264274
list_for_each_entry_safe(vq, n, &vdev->vqs, list) {
265-
if (vp_dev->per_vq_vectors) {
266-
int v = vp_dev->vqs[vq->index]->msix_vector;
275+
info = vp_is_avq(vdev, vq->index) ? vp_dev->admin_vq.info :
276+
vp_dev->vqs[vq->index];
267277

278+
if (vp_dev->per_vq_vectors) {
279+
int v = info->msix_vector;
268280
if (v != VIRTIO_MSI_NO_VECTOR &&
269281
!vp_is_slow_path_vector(v)) {
270282
int irq = pci_irq_vector(vp_dev->pci_dev, v);
@@ -273,7 +285,7 @@ void vp_del_vqs(struct virtio_device *vdev)
273285
free_irq(irq, vq);
274286
}
275287
}
276-
vp_del_vq(vq);
288+
vp_del_vq(vq, info);
277289
}
278290
vp_dev->per_vq_vectors = false;
279291

@@ -354,7 +366,7 @@ vp_find_one_vq_msix(struct virtio_device *vdev, int queue_idx,
354366
vring_interrupt, 0,
355367
vp_dev->msix_names[msix_vec], vq);
356368
if (err) {
357-
vp_del_vq(vq);
369+
vp_del_vq(vq, *p_info);
358370
return ERR_PTR(err);
359371
}
360372

drivers/virtio/virtio_pci_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ struct virtio_device *virtio_pci_vf_get_pf_dev(struct pci_dev *pdev);
178178
#define VIRTIO_ADMIN_CMD_BITMAP 0
179179
#endif
180180

181+
bool vp_is_avq(struct virtio_device *vdev, unsigned int index);
181182
void vp_modern_avq_done(struct virtqueue *vq);
182183
int vp_modern_admin_cmd_exec(struct virtio_device *vdev,
183184
struct virtio_admin_cmd *cmd);

drivers/virtio/virtio_pci_modern.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,6 @@ static int vp_avq_index(struct virtio_device *vdev, u16 *index, u16 *num)
4343
return 0;
4444
}
4545

46-
static bool vp_is_avq(struct virtio_device *vdev, unsigned int index)
47-
{
48-
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
49-
50-
if (!virtio_has_feature(vdev, VIRTIO_F_ADMIN_VQ))
51-
return false;
52-
53-
return index == vp_dev->admin_vq.vq_index;
54-
}
55-
5646
void vp_modern_avq_done(struct virtqueue *vq)
5747
{
5848
struct virtio_pci_device *vp_dev = to_vp_device(vq->vdev);
@@ -245,7 +235,7 @@ static void vp_modern_avq_cleanup(struct virtio_device *vdev)
245235
if (!virtio_has_feature(vdev, VIRTIO_F_ADMIN_VQ))
246236
return;
247237

248-
vq = vp_dev->vqs[vp_dev->admin_vq.vq_index]->vq;
238+
vq = vp_dev->admin_vq.info->vq;
249239
if (!vq)
250240
return;
251241

net/vmw_vsock/virtio_transport_common.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,7 @@ void virtio_transport_destruct(struct vsock_sock *vsk)
11091109
struct virtio_vsock_sock *vvs = vsk->trans;
11101110

11111111
kfree(vvs);
1112+
vsk->trans = NULL;
11121113
}
11131114
EXPORT_SYMBOL_GPL(virtio_transport_destruct);
11141115

tools/virtio/vringh_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ int main(int argc, char *argv[])
519519
errx(1, "virtqueue_add_sgs: %i", err);
520520
__kmalloc_fake = NULL;
521521

522-
/* Host retreives it. */
522+
/* Host retrieves it. */
523523
vringh_iov_init(&riov, host_riov, ARRAY_SIZE(host_riov));
524524
vringh_iov_init(&wiov, host_wiov, ARRAY_SIZE(host_wiov));
525525

0 commit comments

Comments
 (0)