History

Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost

Pull virtio updates from Michael Tsirkin: "Mostly fixes all over the place, a couple of cleanups" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: (32 commits) virtio_blk: Fix signedness bug in virtblk_prep_rq() vdpa_sim_net: should not drop the multicast/broadcast packet vdpasim: fix memory leak when freeing IOTLBs vdpa: conditionally fill max max queue pair for stats vdpa/vp_vdpa: fix kfree a wrong pointer in vp_vdpa_remove vduse: Validate vq_num in vduse_validate_config() tools/virtio: remove smp_read_barrier_depends() tools/virtio: remove stray characters vhost_vdpa: fix the crash in unmap a large memory virtio: Implementing attribute show with sysfs_emit virtio-crypto: fix memory leak in virtio_crypto_alg_skcipher_close_session() tools/virtio: Variable type completion vdpa_sim: fix vringh initialization in vdpasim_queue_ready() virtio_blk: use UINT_MAX instead of -1U vhost-vdpa: fix an iotlb memory leak vhost: fix range used in translate_desc() vringh: fix range used in iotlb_translate() vhost/vsock: Fix error handling in vhost_vsock_init() vdpa_sim: fix possible memory leak in vdpasim_net_init() and vdpasim_blk_init() tools: Delete the unneeded semicolon after curly braces ...

Linus Torvalds committed 3 years ago

Commit 41c03ba2 parents 512dee0 a26116c23 files · +173 −163Browse files

Unified · Split

23 files
  1. drivers/block/virtio_blk.c +20 −15
  2. drivers/crypto/virtio/virtio_crypto_skcipher_algs.c +2 −1
  3. drivers/vdpa/mlx5/core/mlx5_vdpa.h +3 −2
  4. drivers/vdpa/mlx5/core/mr.c +26 −20
  5. drivers/vdpa/mlx5/net/mlx5_vnet.c +23 −55
  6. drivers/vdpa/vdpa.c +5 −6
  7. drivers/vdpa/vdpa_sim/vdpa_sim.c +4 −3
  8. drivers/vdpa/vdpa_sim/vdpa_sim_blk.c +3 −1
  9. drivers/vdpa/vdpa_sim/vdpa_sim_net.c +6 −1
  10. drivers/vdpa/vdpa_user/vduse_dev.c +3 −0
  11. drivers/vdpa/virtio_pci/vp_vdpa.c +1 −1
  12. drivers/vhost/vdpa.c +31 −21
  13. drivers/vhost/vhost.c +2 −2
  14. drivers/vhost/vringh.c +2 −3
  15. drivers/vhost/vsock.c +8 −1
  16. drivers/virtio/virtio.c +6 −6
  17. drivers/virtio/virtio_pci_modern.c +2 −2
  18. drivers/virtio/virtio_ring.c +1 −1
  19. include/uapi/linux/vdpa.h +1 −3
  20. tools/virtio/ringtest/main.h +20 −17
  21. tools/virtio/virtio-trace/trace-agent-ctl.c +1 −1
  22. tools/virtio/virtio_test.c +1 −1
  23. tools/virtio/vringh_test.c +2 −0
drivers/block/virtio_blk.c+20−15
@@ -315,22 +315,35 @@ static void virtio_commit_rqs(struct blk_mq_hw_ctx *hctx) · 314 unmodified lines
315315 virtqueue_notify(vq->vq);
316316 }
317317
318+static blk_status_t virtblk_fail_to_queue(struct request *req, int rc)
319+{
320+ virtblk_cleanup_cmd(req);
321+ switch (rc) {
322+ case -ENOSPC:
323+ return BLK_STS_DEV_RESOURCE;
324+ case -ENOMEM:
325+ return BLK_STS_RESOURCE;
326+ default:
327+ return BLK_STS_IOERR;
328+ }
329+}
330+
318331 static blk_status_t virtblk_prep_rq(struct blk_mq_hw_ctx *hctx,
319332 struct virtio_blk *vblk,
320333 struct request *req,
321334 struct virtblk_req *vbr)
322335 {
323336 blk_status_t status;
337+ int num;
324338
325339 status = virtblk_setup_cmd(vblk->vdev, req, vbr);
326340 if (unlikely(status))
327341 return status;
328342
329− vbr->sg_table.nents = virtblk_map_data(hctx, req, vbr);
330− if (unlikely(vbr->sg_table.nents < 0)) {
331− virtblk_cleanup_cmd(req);
332− return BLK_STS_RESOURCE;
333− }
343+ num = virtblk_map_data(hctx, req, vbr);
344+ if (unlikely(num < 0))
345+ return virtblk_fail_to_queue(req, -ENOMEM);
346+ vbr->sg_table.nents = num;
334347
335348 blk_mq_start_request(req);
336349
@@ -364,15 +377,7 @@ static blk_status_t virtio_queue_rq(struct blk_mq_hw_ctx *hctx, · 27 unmodified lines
364377 blk_mq_stop_hw_queue(hctx);
365378 spin_unlock_irqrestore(&vblk->vqs[qid].lock, flags);
366379 virtblk_unmap_data(req, vbr);
367− virtblk_cleanup_cmd(req);
368− switch (err) {
369− case -ENOSPC:
370− return BLK_STS_DEV_RESOURCE;
371− case -ENOMEM:
372− return BLK_STS_RESOURCE;
373− default:
374− return BLK_STS_IOERR;
375− }
380+ return virtblk_fail_to_queue(req, err);
376381 }
377382
378383 if (bd->last && virtqueue_kick_prepare(vblk->vqs[qid].vq))
@@ -991,7 +996,7 @@ static int virtblk_probe(struct virtio_device *vdev) · 612 unmodified lines
991996 blk_queue_max_segments(q, sg_elems);
992997
993998 /* No real sector limit. */
994− blk_queue_max_hw_sectors(q, -1U);
999+ blk_queue_max_hw_sectors(q, UINT_MAX);
9951000
9961001 max_size = virtio_max_dma_size(vdev);
9971002
drivers/crypto/virtio/virtio_crypto_skcipher_algs.c+2−1
@@ -239,7 +239,8 @@ static int virtio_crypto_alg_skcipher_close_session( · 238 unmodified lines
239239 pr_err("virtio_crypto: Close session failed status: %u, session_id: 0x%llx\n",
240240 ctrl_status->status, destroy_session->session_id);
241241
242− return -EINVAL;
242+ err = -EINVAL;
243+ goto out;
243244 }
244245
245246 err = 0;
drivers/vdpa/mlx5/core/mlx5_vdpa.h+3−2
@@ -116,8 +116,9 @@ int mlx5_vdpa_create_mkey(struct mlx5_vdpa_dev *mvdev, u32 *mkey, u32 *in, · 115 unmodified lines
116116 int inlen);
117117 int mlx5_vdpa_destroy_mkey(struct mlx5_vdpa_dev *mvdev, u32 mkey);
118118 int mlx5_vdpa_handle_set_map(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb,
119− bool *change_map);
120−int mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb);
119+ bool *change_map, unsigned int asid);
120+int mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb,
121+ unsigned int asid);
121122 void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev);
122123
123124 #define mlx5_vdpa_warn(__dev, format, ...) \
drivers/vdpa/mlx5/core/mr.c+26−20
@@ -311,7 +311,6 @@ static int add_direct_chain(struct mlx5_vdpa_dev *mvdev, u64 start, u64 size, u8 · 310 unmodified lines
311311 u64 st;
312312 u64 sz;
313313 int err;
314− int i = 0;
315314
316315 st = start;
317316 while (size) {
@@ -336,7 +335,6 @@ static int add_direct_chain(struct mlx5_vdpa_dev *mvdev, u64 start, u64 size, u8 · 18 unmodified lines
336335 mr->num_directs++;
337336 mr->num_klms++;
338337 st += sz;
339− i++;
340338 }
341339 list_splice_tail(&tmp, &mr->head);
342340 return 0;
@@ -511,7 +509,8 @@ out: · 168 unmodified lines
511509 mutex_unlock(&mr->mkey_mtx);
512510 }
513511
514−static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb)
512+static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev,
513+ struct vhost_iotlb *iotlb, unsigned int asid)
515514 {
516515 struct mlx5_vdpa_mr *mr = &mvdev->mr;
517516 int err;
@@ -519,42 +518,49 @@ static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb · 1 unmodified line
519518 if (mr->initialized)
520519 return 0;
521520
522− if (iotlb)
523− err = create_user_mr(mvdev, iotlb);
524− else
525− err = create_dma_mr(mvdev, mr);
521+ if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] == asid) {
522+ if (iotlb)
523+ err = create_user_mr(mvdev, iotlb);
524+ else
525+ err = create_dma_mr(mvdev, mr);
526526
527− if (err)
528− return err;
527+ if (err)
528+ return err;
529+ }
529530
530− err = dup_iotlb(mvdev, iotlb);
531− if (err)
532− goto out_err;
531+ if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] == asid) {
532+ err = dup_iotlb(mvdev, iotlb);
533+ if (err)
534+ goto out_err;
535+ }
533536
534537 mr->initialized = true;
535538 return 0;
536539
537540 out_err:
538− if (iotlb)
539− destroy_user_mr(mvdev, mr);
540− else
541− destroy_dma_mr(mvdev, mr);
541+ if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] == asid) {
542+ if (iotlb)
543+ destroy_user_mr(mvdev, mr);
544+ else
545+ destroy_dma_mr(mvdev, mr);
546+ }
542547
543548 return err;
544549 }
545550
546−int mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb)
551+int mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb,
552+ unsigned int asid)
547553 {
548554 int err;
549555
550556 mutex_lock(&mvdev->mr.mkey_mtx);
551− err = _mlx5_vdpa_create_mr(mvdev, iotlb);
557+ err = _mlx5_vdpa_create_mr(mvdev, iotlb, asid);
552558 mutex_unlock(&mvdev->mr.mkey_mtx);
553559 return err;
554560 }
555561
556562 int mlx5_vdpa_handle_set_map(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb,
557− bool *change_map)
563+ bool *change_map, unsigned int asid)
558564 {
559565 struct mlx5_vdpa_mr *mr = &mvdev->mr;
560566 int err = 0;
@@ -566,7 +572,7 @@ int mlx5_vdpa_handle_set_map(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *io · 5 unmodified lines
566572 *change_map = true;
567573 }
568574 if (!*change_map)
569− err = _mlx5_vdpa_create_mr(mvdev, iotlb);
575+ err = _mlx5_vdpa_create_mr(mvdev, iotlb, asid);
570576 mutex_unlock(&mr->mkey_mtx);
571577
572578 return err;
drivers/vdpa/mlx5/net/mlx5_vnet.c+23−55
@@ -1468,11 +1468,13 @@ static int mlx5_vdpa_add_mac_vlan_rules(struct mlx5_vdpa_net *ndev, u8 *mac, · 1467 unmodified lines
14681468 dmac_v = MLX5_ADDR_OF(fte_match_param, headers_v, outer_headers.dmac_47_16);
14691469 eth_broadcast_addr(dmac_c);
14701470 ether_addr_copy(dmac_v, mac);
1471− MLX5_SET(fte_match_set_lyr_2_4, headers_c, cvlan_tag, 1);
1471+ if (ndev->mvdev.actual_features & BIT_ULL(VIRTIO_NET_F_CTRL_VLAN)) {
1472+ MLX5_SET(fte_match_set_lyr_2_4, headers_c, cvlan_tag, 1);
1473+ MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, headers_c, first_vid);
1474+ }
14721475 if (tagged) {
14731476 MLX5_SET(fte_match_set_lyr_2_4, headers_v, cvlan_tag, 1);
1474− MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, headers_c, first_vid);
1475− MLX5_SET(fte_match_set_lyr_2_4, headers_c, first_vid, vid);
1477+ MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_vid, vid);
14761478 }
14771479 flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
14781480 dest.type = MLX5_FLOW_DESTINATION_TYPE_TIR;
@@ -1684,7 +1686,7 @@ static virtio_net_ctrl_ack handle_ctrl_mac(struct mlx5_vdpa_dev *mvdev, u8 cmd) · 205 unmodified lines
16841686
16851687 /* Need recreate the flow table entry, so that the packet could forward back
16861688 */
1687− mac_vlan_del(ndev, ndev->config.mac, 0, false);
1689+ mac_vlan_del(ndev, mac_back, 0, false);
16881690
16891691 if (mac_vlan_add(ndev, ndev->config.mac, 0, false)) {
16901692 mlx5_vdpa_warn(mvdev, "failed to insert forward rules, try to restore\n");
@@ -1821,6 +1823,9 @@ static virtio_net_ctrl_ack handle_ctrl_vlan(struct mlx5_vdpa_dev *mvdev, u8 cmd) · 130 unmodified lines
18211823 size_t read;
18221824 u16 id;
18231825
1826+ if (!(ndev->mvdev.actual_features & BIT_ULL(VIRTIO_NET_F_CTRL_VLAN)))
1827+ return status;
1828+
18241829 switch (cmd) {
18251830 case VIRTIO_NET_CTRL_VLAN_ADD:
18261831 read = vringh_iov_pull_iotlb(&cvq->vring, &cvq->riov, &vlan, sizeof(vlan));
@@ -2389,7 +2394,8 @@ static void restore_channels_info(struct mlx5_vdpa_net *ndev) · 562 unmodified lines
23892394 }
23902395 }
23912396
2392−static int mlx5_vdpa_change_map(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb)
2397+static int mlx5_vdpa_change_map(struct mlx5_vdpa_dev *mvdev,
2398+ struct vhost_iotlb *iotlb, unsigned int asid)
23932399 {
23942400 struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
23952401 int err;
@@ -2401,7 +2407,7 @@ static int mlx5_vdpa_change_map(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb · 5 unmodified lines
24012407
24022408 teardown_driver(ndev);
24032409 mlx5_vdpa_destroy_mr(mvdev);
2404− err = mlx5_vdpa_create_mr(mvdev, iotlb);
2410+ err = mlx5_vdpa_create_mr(mvdev, iotlb, asid);
24052411 if (err)
24062412 goto err_mr;
24072413
@@ -2582,7 +2588,7 @@ static int mlx5_vdpa_reset(struct vdpa_device *vdev) · 174 unmodified lines
25822588 ++mvdev->generation;
25832589
25842590 if (MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) {
2585− if (mlx5_vdpa_create_mr(mvdev, NULL))
2591+ if (mlx5_vdpa_create_mr(mvdev, NULL, 0))
25862592 mlx5_vdpa_warn(mvdev, "create MR failed\n");
25872593 }
25882594 up_write(&ndev->reslock);
@@ -2618,41 +2624,20 @@ static u32 mlx5_vdpa_get_generation(struct vdpa_device *vdev) · 29 unmodified lines
26182624 return mvdev->generation;
26192625 }
26202626
2621−static int set_map_control(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb)
2622−{
2623− u64 start = 0ULL, last = 0ULL - 1;
2624− struct vhost_iotlb_map *map;
2625− int err = 0;
2626−
2627− spin_lock(&mvdev->cvq.iommu_lock);
2628− vhost_iotlb_reset(mvdev->cvq.iotlb);
2629−
2630− for (map = vhost_iotlb_itree_first(iotlb, start, last); map;
2631− map = vhost_iotlb_itree_next(map, start, last)) {
2632− err = vhost_iotlb_add_range(mvdev->cvq.iotlb, map->start,
2633− map->last, map->addr, map->perm);
2634− if (err)
2635− goto out;
2636− }
2637−
2638−out:
2639− spin_unlock(&mvdev->cvq.iommu_lock);
2640− return err;
2641−}
2642−
2643−static int set_map_data(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb)
2627+static int set_map_data(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb,
2628+ unsigned int asid)
26442629 {
26452630 bool change_map;
26462631 int err;
26472632
2648− err = mlx5_vdpa_handle_set_map(mvdev, iotlb, &change_map);
2633+ err = mlx5_vdpa_handle_set_map(mvdev, iotlb, &change_map, asid);
26492634 if (err) {
26502635 mlx5_vdpa_warn(mvdev, "set map failed(%d)\n", err);
26512636 return err;
26522637 }
26532638
26542639 if (change_map)
2655− err = mlx5_vdpa_change_map(mvdev, iotlb);
2640+ err = mlx5_vdpa_change_map(mvdev, iotlb, asid);
26562641
26572642 return err;
26582643 }
@@ -2665,16 +2650,7 @@ static int mlx5_vdpa_set_map(struct vdpa_device *vdev, unsigned int asid, · 6 unmodified lines
26652650 int err = -EINVAL;
26662651
26672652 down_write(&ndev->reslock);
2668− if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] == asid) {
2669− err = set_map_data(mvdev, iotlb);
2670− if (err)
2671− goto out;
2672− }
2673−
2674− if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] == asid)
2675− err = set_map_control(mvdev, iotlb);
2676−
2677−out:
2653+ err = set_map_data(mvdev, iotlb, asid);
26782654 up_write(&ndev->reslock);
26792655 return err;
26802656 }
@@ -2840,8 +2816,8 @@ static int mlx5_vdpa_suspend(struct vdpa_device *vdev) · 159 unmodified lines
28402816 int i;
28412817
28422818 down_write(&ndev->reslock);
2843− mlx5_notifier_unregister(mvdev->mdev, &ndev->nb);
28442819 ndev->nb_registered = false;
2820+ mlx5_notifier_unregister(mvdev->mdev, &ndev->nb);
28452821 flush_workqueue(ndev->mvdev.wq);
28462822 for (i = 0; i < ndev->cur_num_vqs; i++) {
28472823 mvq = &ndev->vqs[i];
@@ -3019,7 +2995,7 @@ static void update_carrier(struct work_struct *work) · 171 unmodified lines
30192995 else
30202996 ndev->config.status &= cpu_to_mlx5vdpa16(mvdev, ~VIRTIO_NET_S_LINK_UP);
30212997
3022− if (ndev->config_cb.callback)
2998+ if (ndev->nb_registered && ndev->config_cb.callback)
30232999 ndev->config_cb.callback(ndev->config_cb.private);
30243000
30253001 kfree(wqent);
@@ -3036,21 +3012,13 @@ static int event_handler(struct notifier_block *nb, unsigned long event, void *p · 10 unmodified lines
30363012 switch (eqe->sub_type) {
30373013 case MLX5_PORT_CHANGE_SUBTYPE_DOWN:
30383014 case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE:
3039− down_read(&ndev->reslock);
3040− if (!ndev->nb_registered) {
3041− up_read(&ndev->reslock);
3042− return NOTIFY_DONE;
3043− }
30443015 wqent = kzalloc(sizeof(*wqent), GFP_ATOMIC);
3045− if (!wqent) {
3046− up_read(&ndev->reslock);
3016+ if (!wqent)
30473017 return NOTIFY_DONE;
3048− }
30493018
30503019 wqent->mvdev = &ndev->mvdev;
30513020 INIT_WORK(&wqent->work, update_carrier);
30523021 queue_work(ndev->mvdev.wq, &wqent->work);
3053− up_read(&ndev->reslock);
30543022 ret = NOTIFY_OK;
30553023 break;
30563024 default:
@@ -3185,7 +3153,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name, · 128 unmodified lines
31853153 goto err_mpfs;
31863154
31873155 if (MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) {
3188− err = mlx5_vdpa_create_mr(mvdev, NULL);
3156+ err = mlx5_vdpa_create_mr(mvdev, NULL, 0);
31893157 if (err)
31903158 goto err_res;
31913159 }
@@ -3237,8 +3205,8 @@ static void mlx5_vdpa_dev_del(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device * · 45 unmodified lines
32373205 struct workqueue_struct *wq;
32383206
32393207 if (ndev->nb_registered) {
3240− mlx5_notifier_unregister(mvdev->mdev, &ndev->nb);
32413208 ndev->nb_registered = false;
3209+ mlx5_notifier_unregister(mvdev->mdev, &ndev->nb);
32423210 }
32433211 wq = mvdev->wq;
32443212 mvdev->wq = NULL;
drivers/vdpa/vdpa.c+5−6
@@ -855,7 +855,7 @@ static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *ms · 854 unmodified lines
855855
856856 features_device = vdev->config->get_device_features(vdev);
857857
858− if (nla_put_u64_64bit(msg, VDPA_ATTR_VDPA_DEV_SUPPORTED_FEATURES, features_device,
858+ if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_FEATURES, features_device,
859859 VDPA_ATTR_PAD))
860860 return -EMSGSIZE;
861861
@@ -935,7 +935,6 @@ static int vdpa_fill_stats_rec(struct vdpa_device *vdev, struct sk_buff *msg, · 73 unmodified lines
935935 {
936936 struct virtio_net_config config = {};
937937 u64 features;
938− u16 max_vqp;
939938 u8 status;
940939 int err;
941940
@@ -946,15 +945,15 @@ static int vdpa_fill_stats_rec(struct vdpa_device *vdev, struct sk_buff *msg, · 4 unmodified lines
946945 }
947946 vdpa_get_config_unlocked(vdev, 0, &config, sizeof(config));
948947
949− max_vqp = __virtio16_to_cpu(true, config.max_virtqueue_pairs);
950− if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MAX_VQP, max_vqp))
951− return -EMSGSIZE;
952−
953948 features = vdev->config->get_driver_features(vdev);
954949 if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_NEGOTIATED_FEATURES,
955950 features, VDPA_ATTR_PAD))
956951 return -EMSGSIZE;
957952
953+ err = vdpa_dev_net_mq_config_fill(msg, features, &config);
954+ if (err)
955+ return err;
956+
958957 if (nla_put_u32(msg, VDPA_ATTR_DEV_QUEUE_INDEX, index))
959958 return -EMSGSIZE;
960959
drivers/vdpa/vdpa_sim/vdpa_sim.c+4−3
@@ -67,8 +67,7 @@ static void vdpasim_queue_ready(struct vdpasim *vdpasim, unsigned int idx) · 66 unmodified lines
6767 {
6868 struct vdpasim_virtqueue *vq = &vdpasim->vqs[idx];
6969
70− vringh_init_iotlb(&vq->vring, vdpasim->dev_attr.supported_features,
71− VDPASIM_QUEUE_MAX, false,
70+ vringh_init_iotlb(&vq->vring, vdpasim->features, vq->num, false,
7271 (struct vring_desc *)(uintptr_t)vq->desc_addr,
7372 (struct vring_avail *)
7473 (uintptr_t)vq->driver_addr,
@@ -690,7 +689,9 @@ static void vdpasim_free(struct vdpa_device *vdpa) · 615 unmodified lines
690689 }
691690
692691 kvfree(vdpasim->buffer);
693− vhost_iotlb_free(vdpasim->iommu);
692+ for (i = 0; i < vdpasim->dev_attr.nas; i++)
693+ vhost_iotlb_reset(&vdpasim->iommu[i]);
694+ kfree(vdpasim->iommu);
694695 kfree(vdpasim->vqs);
695696 kfree(vdpasim->config);
696697 }
drivers/vdpa/vdpa_sim/vdpa_sim_blk.c+3−1
@@ -427,8 +427,10 @@ static int __init vdpasim_blk_init(void) · 426 unmodified lines
427427 int ret;
428428
429429 ret = device_register(&vdpasim_blk_mgmtdev);
430− if (ret)
430+ if (ret) {
431+ put_device(&vdpasim_blk_mgmtdev);
431432 return ret;
433+ }
432434
433435 ret = vdpa_mgmtdev_register(&mgmt_dev);
434436 if (ret)
drivers/vdpa/vdpa_sim/vdpa_sim_net.c+6−1
@@ -62,6 +62,9 @@ static bool receive_filter(struct vdpasim *vdpasim, size_t len) · 61 unmodified lines
6262 if (len < ETH_ALEN + hdr_len)
6363 return false;
6464
65+ if (is_broadcast_ether_addr(vdpasim->buffer + hdr_len) ||
66+ is_multicast_ether_addr(vdpasim->buffer + hdr_len))
67+ return true;
6568 if (!strncmp(vdpasim->buffer + hdr_len, vio_config->mac, ETH_ALEN))
6669 return true;
6770
@@ -305,8 +308,10 @@ static int __init vdpasim_net_init(void) · 237 unmodified lines
305308 int ret;
306309
307310 ret = device_register(&vdpasim_net_mgmtdev);
308− if (ret)
311+ if (ret) {
312+ put_device(&vdpasim_net_mgmtdev);
309313 return ret;
314+ }
310315
311316 ret = vdpa_mgmtdev_register(&mgmt_dev);
312317 if (ret)
drivers/vdpa/vdpa_user/vduse_dev.c+3−0
@@ -1440,6 +1440,9 @@ static bool vduse_validate_config(struct vduse_dev_config *config) · 1439 unmodified lines
14401440 if (config->config_size > PAGE_SIZE)
14411441 return false;
14421442
1443+ if (config->vq_num > 0xffff)
1444+ return false;
1445+
14431446 if (!device_is_allowed(config->device_id))
14441447 return false;
14451448
drivers/vdpa/virtio_pci/vp_vdpa.c+1−1
@@ -647,7 +647,7 @@ static void vp_vdpa_remove(struct pci_dev *pdev) · 646 unmodified lines
647647 mdev = vp_vdpa_mgtdev->mdev;
648648 vp_modern_remove(mdev);
649649 vdpa_mgmtdev_unregister(&vp_vdpa_mgtdev->mgtdev);
650− kfree(&vp_vdpa_mgtdev->mgtdev.id_table);
650+ kfree(vp_vdpa_mgtdev->mgtdev.id_table);
651651 kfree(mdev);
652652 kfree(vp_vdpa_mgtdev);
653653 }
drivers/vhost/vdpa.c+31−21
@@ -65,6 +65,10 @@ static DEFINE_IDA(vhost_vdpa_ida); · 64 unmodified lines
6565
6666 static dev_t vhost_vdpa_major;
6767
68+static void vhost_vdpa_iotlb_unmap(struct vhost_vdpa *v,
69+ struct vhost_iotlb *iotlb, u64 start,
70+ u64 last, u32 asid);
71+
6872 static inline u32 iotlb_to_asid(struct vhost_iotlb *iotlb)
6973 {
7074 struct vhost_vdpa_as *as = container_of(iotlb, struct
@@ -135,7 +139,7 @@ static int vhost_vdpa_remove_as(struct vhost_vdpa *v, u32 asid) · 64 unmodified lines
135139 return -EINVAL;
136140
137141 hlist_del(&as->hash_link);
138− vhost_iotlb_reset(&as->iotlb);
142+ vhost_vdpa_iotlb_unmap(v, &as->iotlb, 0ULL, 0ULL - 1, asid);
139143 kfree(as);
140144
141145 return 0;
@@ -683,10 +687,20 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep, · 541 unmodified lines
683687 mutex_unlock(&d->mutex);
684688 return r;
685689 }
690+static void vhost_vdpa_general_unmap(struct vhost_vdpa *v,
691+ struct vhost_iotlb_map *map, u32 asid)
692+{
693+ struct vdpa_device *vdpa = v->vdpa;
694+ const struct vdpa_config_ops *ops = vdpa->config;
695+ if (ops->dma_map) {
696+ ops->dma_unmap(vdpa, asid, map->start, map->size);
697+ } else if (ops->set_map == NULL) {
698+ iommu_unmap(v->domain, map->start, map->size);
699+ }
700+}
686701
687−static void vhost_vdpa_pa_unmap(struct vhost_vdpa *v,
688− struct vhost_iotlb *iotlb,
689− u64 start, u64 last)
702+static void vhost_vdpa_pa_unmap(struct vhost_vdpa *v, struct vhost_iotlb *iotlb,
703+ u64 start, u64 last, u32 asid)
690704 {
691705 struct vhost_dev *dev = &v->vdev;
692706 struct vhost_iotlb_map *map;
@@ -703,13 +717,13 @@ static void vhost_vdpa_pa_unmap(struct vhost_vdpa *v, · 10 unmodified lines
703717 unpin_user_page(page);
704718 }
705719 atomic64_sub(PFN_DOWN(map->size), &dev->mm->pinned_vm);
720+ vhost_vdpa_general_unmap(v, map, asid);
706721 vhost_iotlb_map_free(iotlb, map);
707722 }
708723 }
709724
710−static void vhost_vdpa_va_unmap(struct vhost_vdpa *v,
711− struct vhost_iotlb *iotlb,
712− u64 start, u64 last)
725+static void vhost_vdpa_va_unmap(struct vhost_vdpa *v, struct vhost_iotlb *iotlb,
726+ u64 start, u64 last, u32 asid)
713727 {
714728 struct vhost_iotlb_map *map;
715729 struct vdpa_map_file *map_file;
@@ -718,20 +732,21 @@ static void vhost_vdpa_va_unmap(struct vhost_vdpa *v, · 2 unmodified lines
718732 map_file = (struct vdpa_map_file *)map->opaque;
719733 fput(map_file->file);
720734 kfree(map_file);
735+ vhost_vdpa_general_unmap(v, map, asid);
721736 vhost_iotlb_map_free(iotlb, map);
722737 }
723738 }
724739
725740 static void vhost_vdpa_iotlb_unmap(struct vhost_vdpa *v,
726− struct vhost_iotlb *iotlb,
727− u64 start, u64 last)
741+ struct vhost_iotlb *iotlb, u64 start,
742+ u64 last, u32 asid)
728743 {
729744 struct vdpa_device *vdpa = v->vdpa;
730745
731746 if (vdpa->use_va)
732− return vhost_vdpa_va_unmap(v, iotlb, start, last);
747+ return vhost_vdpa_va_unmap(v, iotlb, start, last, asid);
733748
734− return vhost_vdpa_pa_unmap(v, iotlb, start, last);
749+ return vhost_vdpa_pa_unmap(v, iotlb, start, last, asid);
735750 }
736751
737752 static int perm_to_iommu_flags(u32 perm)
@@ -798,17 +813,12 @@ static void vhost_vdpa_unmap(struct vhost_vdpa *v, · 60 unmodified lines
798813 const struct vdpa_config_ops *ops = vdpa->config;
799814 u32 asid = iotlb_to_asid(iotlb);
800815
801− vhost_vdpa_iotlb_unmap(v, iotlb, iova, iova + size - 1);
816+ vhost_vdpa_iotlb_unmap(v, iotlb, iova, iova + size - 1, asid);
802817
803− if (ops->dma_map) {
804− ops->dma_unmap(vdpa, asid, iova, size);
805− } else if (ops->set_map) {
818+ if (ops->set_map) {
806819 if (!v->in_batch)
807820 ops->set_map(vdpa, asid, iotlb);
808− } else {
809− iommu_unmap(v->domain, iova, size);
810821 }
811−
812822 /* If we are in the middle of batch processing, delay the free
813823 * of AS until BATCH_END.
814824 */
@@ -1162,14 +1172,14 @@ static void vhost_vdpa_cleanup(struct vhost_vdpa *v) · 347 unmodified lines
11621172 struct vhost_vdpa_as *as;
11631173 u32 asid;
11641174
1165− vhost_dev_cleanup(&v->vdev);
1166− kfree(v->vdev.vqs);
1167−
11681175 for (asid = 0; asid < v->vdpa->nas; asid++) {
11691176 as = asid_to_as(v, asid);
11701177 if (as)
11711178 vhost_vdpa_remove_as(v, asid);
11721179 }
1180+
1181+ vhost_dev_cleanup(&v->vdev);
1182+ kfree(v->vdev.vqs);
11731183 }
11741184
11751185 static int vhost_vdpa_open(struct inode *inode, struct file *filep)
drivers/vhost/vhost.c+2−2
@@ -2053,7 +2053,7 @@ static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len, · 2052 unmodified lines
20532053 struct vhost_dev *dev = vq->dev;
20542054 struct vhost_iotlb *umem = dev->iotlb ? dev->iotlb : dev->umem;
20552055 struct iovec *_iov;
2056− u64 s = 0;
2056+ u64 s = 0, last = addr + len - 1;
20572057 int ret = 0;
20582058
20592059 while ((u64)len > s) {
@@ -2063,7 +2063,7 @@ static int translate_desc(struct vhost_virtqueue *vq, u64 addr, u32 len, · 3 unmodified lines
20632063 break;
20642064 }
20652065
2066− map = vhost_iotlb_itree_first(umem, addr, addr + len - 1);
2066+ map = vhost_iotlb_itree_first(umem, addr, last);
20672067 if (map == NULL || map->start > addr) {
20682068 if (umem != dev->iotlb) {
20692069 ret = -EFAULT;
drivers/vhost/vringh.c+2−3
@@ -1102,7 +1102,7 @@ static int iotlb_translate(const struct vringh *vrh, · 1101 unmodified lines
11021102 struct vhost_iotlb_map *map;
11031103 struct vhost_iotlb *iotlb = vrh->iotlb;
11041104 int ret = 0;
1105− u64 s = 0;
1105+ u64 s = 0, last = addr + len - 1;
11061106
11071107 spin_lock(vrh->iotlb_lock);
11081108
@@ -1114,8 +1114,7 @@ static int iotlb_translate(const struct vringh *vrh, · 5 unmodified lines
11141114 break;
11151115 }
11161116
1117− map = vhost_iotlb_itree_first(iotlb, addr,
1118− addr + len - 1);
1117+ map = vhost_iotlb_itree_first(iotlb, addr, last);
11191118 if (!map || map->start > addr) {
11201119 ret = -EINVAL;
11211120 break;
drivers/vhost/vsock.c+8−1
@@ -959,7 +959,14 @@ static int __init vhost_vsock_init(void) · 958 unmodified lines
959959 VSOCK_TRANSPORT_F_H2G);
960960 if (ret < 0)
961961 return ret;
962− return misc_register(&vhost_vsock_misc);
962+
963+ ret = misc_register(&vhost_vsock_misc);
964+ if (ret) {
965+ vsock_core_unregister(&vhost_transport.transport);
966+ return ret;
967+ }
968+
969+ return 0;
963970 };
964971
965972 static void __exit vhost_vsock_exit(void)
drivers/virtio/virtio.c+6−6
@@ -15,7 +15,7 @@ static ssize_t device_show(struct device *_d, · 14 unmodified lines
1515 struct device_attribute *attr, char *buf)
1616 {
1717 struct virtio_device *dev = dev_to_virtio(_d);
18− return sprintf(buf, "0x%04x\n", dev->id.device);
18+ return sysfs_emit(buf, "0x%04x\n", dev->id.device);
1919 }
2020 static DEVICE_ATTR_RO(device);
2121
@@ -23,7 +23,7 @@ static ssize_t vendor_show(struct device *_d, · 1 unmodified line
2323 struct device_attribute *attr, char *buf)
2424 {
2525 struct virtio_device *dev = dev_to_virtio(_d);
26− return sprintf(buf, "0x%04x\n", dev->id.vendor);
26+ return sysfs_emit(buf, "0x%04x\n", dev->id.vendor);
2727 }
2828 static DEVICE_ATTR_RO(vendor);
2929
@@ -31,7 +31,7 @@ static ssize_t status_show(struct device *_d, · 1 unmodified line
3131 struct device_attribute *attr, char *buf)
3232 {
3333 struct virtio_device *dev = dev_to_virtio(_d);
34− return sprintf(buf, "0x%08x\n", dev->config->get_status(dev));
34+ return sysfs_emit(buf, "0x%08x\n", dev->config->get_status(dev));
3535 }
3636 static DEVICE_ATTR_RO(status);
3737
@@ -39,7 +39,7 @@ static ssize_t modalias_show(struct device *_d, · 1 unmodified line
3939 struct device_attribute *attr, char *buf)
4040 {
4141 struct virtio_device *dev = dev_to_virtio(_d);
42− return sprintf(buf, "virtio:d%08Xv%08X\n",
42+ return sysfs_emit(buf, "virtio:d%08Xv%08X\n",
4343 dev->id.device, dev->id.vendor);
4444 }
4545 static DEVICE_ATTR_RO(modalias);
@@ -54,9 +54,9 @@ static ssize_t features_show(struct device *_d, · 8 unmodified lines
5454 /* We actually represent this as a bitstring, as it could be
5555 * arbitrary length in future. */
5656 for (i = 0; i < sizeof(dev->features)*8; i++)
57− len += sprintf(buf+len, "%c",
57+ len += sysfs_emit_at(buf, len, "%c",
5858 __virtio_test_bit(dev, i) ? '1' : '0');
59− len += sprintf(buf+len, "\n");
59+ len += sysfs_emit_at(buf, len, "\n");
6060 return len;
6161 }
6262 static DEVICE_ATTR_RO(features);
drivers/virtio/virtio_pci_modern.c+2−2
@@ -303,14 +303,14 @@ static struct virtqueue *setup_vq(struct virtio_pci_device *vp_dev, · 302 unmodified lines
303303 int err;
304304
305305 if (index >= vp_modern_get_num_queues(mdev))
306− return ERR_PTR(-ENOENT);
306+ return ERR_PTR(-EINVAL);
307307
308308 /* Check if queue is either not available or already active. */
309309 num = vp_modern_get_queue_size(mdev, index);
310310 if (!num || vp_modern_get_queue_enable(mdev, index))
311311 return ERR_PTR(-ENOENT);
312312
313− if (num & (num - 1)) {
313+ if (!is_power_of_2(num)) {
314314 dev_warn(&vp_dev->pci_dev->dev, "bad queue size %u", num);
315315 return ERR_PTR(-EINVAL);
316316 }
drivers/virtio/virtio_ring.c+1−1
@@ -1052,7 +1052,7 @@ static int vring_alloc_queue_split(struct vring_virtqueue_split *vring_split, · 1051 unmodified lines
10521052 dma_addr_t dma_addr;
10531053
10541054 /* We assume num is a power of 2. */
1055− if (num & (num - 1)) {
1055+ if (!is_power_of_2(num)) {
10561056 dev_warn(&vdev->dev, "Bad virtqueue length %u\n", num);
10571057 return -EINVAL;
10581058 }
include/uapi/linux/vdpa.h+1−3
@@ -53,11 +53,9 @@ enum vdpa_attr { · 52 unmodified lines
5353 VDPA_ATTR_DEV_VENDOR_ATTR_NAME, /* string */
5454 VDPA_ATTR_DEV_VENDOR_ATTR_VALUE, /* u64 */
5555
56+ /* virtio features that are provisioned to the vDPA device */
5657 VDPA_ATTR_DEV_FEATURES, /* u64 */
5758
58− /* virtio features that are supported by the vDPA device */
59− VDPA_ATTR_VDPA_DEV_SUPPORTED_FEATURES, /* u64 */
60−
6159 /* new attributes must be added above here */
6260 VDPA_ATTR_MAX,
6361 };
tools/virtio/ringtest/main.h+20−17
@@ -140,25 +140,19 @@ static inline void busy_wait(void) · 139 unmodified lines
140140 #define smp_wmb() smp_release()
141141 #endif
142142
143−#ifdef __alpha__
144−#define smp_read_barrier_depends() smp_acquire()
145−#else
146−#define smp_read_barrier_depends() do {} while(0)
147−#endif
148−
149143 static __always_inline
150144 void __read_once_size(const volatile void *p, void *res, int size)
151145 {
152− switch (size) { \
153− case 1: *(unsigned char *)res = *(volatile unsigned char *)p; break; \
154− case 2: *(unsigned short *)res = *(volatile unsigned short *)p; break; \
155− case 4: *(unsigned int *)res = *(volatile unsigned int *)p; break; \
156− case 8: *(unsigned long long *)res = *(volatile unsigned long long *)p; break; \
157− default: \
158− barrier(); \
159− __builtin_memcpy((void *)res, (const void *)p, size); \
160− barrier(); \
161− } \
146+ switch (size) {
147+ case 1: *(unsigned char *)res = *(volatile unsigned char *)p; break;
148+ case 2: *(unsigned short *)res = *(volatile unsigned short *)p; break;
149+ case 4: *(unsigned int *)res = *(volatile unsigned int *)p; break;
150+ case 8: *(unsigned long long *)res = *(volatile unsigned long long *)p; break;
151+ default:
152+ barrier();
153+ __builtin_memcpy((void *)res, (const void *)p, size);
154+ barrier();
155+ }
162156 }
163157
164158 static __always_inline void __write_once_size(volatile void *p, void *res, int size)
@@ -175,13 +169,22 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s · 10 unmodified lines
175169 }
176170 }
177171
172+#ifdef __alpha__
178173 #define READ_ONCE(x) \
179174 ({ \
180175 union { typeof(x) __val; char __c[1]; } __u; \
181176 __read_once_size(&(x), __u.__c, sizeof(x)); \
182− smp_read_barrier_depends(); /* Enforce dependency ordering from x */ \
177+ smp_mb(); /* Enforce dependency ordering from x */ \
178+ __u.__val; \
179+})
180+#else
181+#define READ_ONCE(x) \
182+({ \
183+ union { typeof(x) __val; char __c[1]; } __u; \
184+ __read_once_size(&(x), __u.__c, sizeof(x)); \
183185 __u.__val; \
184186 })
187+#endif
185188
186189 #define WRITE_ONCE(x, val) \
187190 ({ \
tools/virtio/virtio-trace/trace-agent-ctl.c+1−1
@@ -75,7 +75,7 @@ static int wait_order(int ctl_fd) · 74 unmodified lines
7575
7676 if (ret)
7777 break;
78− };
78+ }
7979
8080 return ret;
8181
tools/virtio/virtio_test.c+1−1
@@ -173,7 +173,7 @@ static void run_test(struct vdev_info *dev, struct vq_info *vq, · 172 unmodified lines
173173 long started = 0, completed = 0, next_reset = reset_n;
174174 long completed_before, started_before;
175175 int r, test = 1;
176− unsigned len;
176+ unsigned int len;
177177 long long spurious = 0;
178178 const bool random_batch = batch == RANDOM_BATCH;
179179
tools/virtio/vringh_test.c+2−0
@@ -308,6 +308,7 @@ static int parallel_test(u64 features, · 307 unmodified lines
308308
309309 gvdev.vdev.features = features;
310310 INIT_LIST_HEAD(&gvdev.vdev.vqs);
311+ spin_lock_init(&gvdev.vdev.vqs_list_lock);
311312 gvdev.to_host_fd = to_host[1];
312313 gvdev.notifies = 0;
313314
@@ -455,6 +456,7 @@ int main(int argc, char *argv[]) · 141 unmodified lines
455456 getrange = getrange_iov;
456457 vdev.features = 0;
457458 INIT_LIST_HEAD(&vdev.vqs);
459+ spin_lock_init(&vdev.vqs_list_lock);
458460
459461 while (argv[1]) {
460462 if (strcmp(argv[1], "--indirect") == 0)