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

Pull virtio updates from Michael Tsirkin:
"vhost,virtio,vdpa: features, fixes, cleanups.

vdpa/mlx5:
- VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK
- new maintainer

vdpa:
- support for vq descriptor mappings
- decouple reset of iotlb mapping from device reset

and fixes, cleanups all over the place"

* tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: (34 commits)
vdpa_sim: implement .reset_map support
vdpa/mlx5: implement .reset_map driver op
vhost-vdpa: clean iotlb map during reset for older userspace
vdpa: introduce .compat_reset operation callback
vhost-vdpa: introduce IOTLB_PERSIST backend feature bit
vhost-vdpa: reset vendor specific mapping to initial state in .release
vdpa: introduce .reset_map operation callback
virtio_pci: add check for common cfg size
virtio-blk: fix implicit overflow on virtio_max_dma_size
virtio_pci: add build offset check for the new common cfg items
virtio: add definition of VIRTIO_F_NOTIF_CONFIG_DATA feature bit
vduse: make vduse_class constant
vhost-scsi: Spelling s/preceeding/preceding/g
virtio: kdoc for struct virtio_pci_modern_device
vdpa: Update sysfs ABI documentation
MAINTAINERS: Add myself as mlx5_vdpa driver
virtio-balloon: correct the comment of virtballoon_migratepage()
mlx5_vdpa: offer VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK
vdpa/mlx5: Update cvq iotlb mapping on ASID change
vdpa/mlx5: Make iotlb helper functions more generic
...

+545 -185
+2 -2
Documentation/ABI/testing/sysfs-bus-vdpa
··· 1 - What: /sys/bus/vdpa/driver_autoprobe 1 + What: /sys/bus/vdpa/drivers_autoprobe 2 2 Date: March 2020 3 3 Contact: virtualization@lists.linux-foundation.org 4 4 Description: ··· 17 17 Writing a device name to this file will cause the kernel binds 18 18 devices to a compatible driver. 19 19 20 - This can be useful when /sys/bus/vdpa/driver_autoprobe is 20 + This can be useful when /sys/bus/vdpa/drivers_autoprobe is 21 21 disabled. 22 22 23 23 What: /sys/bus/vdpa/drivers/.../bind
+6
MAINTAINERS
··· 13790 13790 F: include/linux/mlx5/ 13791 13791 F: include/uapi/rdma/mlx5-abi.h 13792 13792 13793 + MELLANOX MLX5 VDPA DRIVER 13794 + M: Dragos Tatulea <dtatulea@nvidia.com> 13795 + L: virtualization@lists.linux-foundation.org 13796 + S: Supported 13797 + F: drivers/vdpa/mlx5/ 13798 + 13793 13799 MELLANOX MLXCPLD I2C AND MUX DRIVER 13794 13800 M: Vadim Pasternak <vadimp@nvidia.com> 13795 13801 M: Michael Shych <michaelsh@nvidia.com>
+3 -1
drivers/block/virtio_blk.c
··· 1311 1311 u16 min_io_size; 1312 1312 u8 physical_block_exp, alignment_offset; 1313 1313 unsigned int queue_depth; 1314 + size_t max_dma_size; 1314 1315 1315 1316 if (!vdev->config->get) { 1316 1317 dev_err(&vdev->dev, "%s failure: config access disabled\n", ··· 1410 1409 /* No real sector limit. */ 1411 1410 blk_queue_max_hw_sectors(q, UINT_MAX); 1412 1411 1413 - max_size = virtio_max_dma_size(vdev); 1412 + max_dma_size = virtio_max_dma_size(vdev); 1413 + max_size = max_dma_size > U32_MAX ? U32_MAX : max_dma_size; 1414 1414 1415 1415 /* Host can optionally specify maximum segment size and number of 1416 1416 * segments. */
+20 -12
drivers/vdpa/mlx5/core/mlx5_vdpa.h
··· 31 31 struct list_head head; 32 32 unsigned long num_directs; 33 33 unsigned long num_klms; 34 - /* state of dvq mr */ 35 - bool initialized; 36 34 37 - /* serialize mkey creation and destruction */ 38 - struct mutex mkey_mtx; 35 + struct vhost_iotlb *iotlb; 36 + 39 37 bool user_mr; 40 38 }; 41 39 ··· 72 74 enum { 73 75 MLX5_VDPA_DATAVQ_GROUP, 74 76 MLX5_VDPA_CVQ_GROUP, 77 + MLX5_VDPA_DATAVQ_DESC_GROUP, 75 78 MLX5_VDPA_NUMVQ_GROUPS 76 79 }; 77 80 78 81 enum { 79 - MLX5_VDPA_NUM_AS = MLX5_VDPA_NUMVQ_GROUPS 82 + MLX5_VDPA_NUM_AS = 2 80 83 }; 81 84 82 85 struct mlx5_vdpa_dev { ··· 92 93 u16 max_idx; 93 94 u32 generation; 94 95 95 - struct mlx5_vdpa_mr mr; 96 + struct mlx5_vdpa_mr *mr[MLX5_VDPA_NUM_AS]; 97 + /* serialize mr access */ 98 + struct mutex mr_mtx; 96 99 struct mlx5_control_vq cvq; 97 100 struct workqueue_struct *wq; 98 101 unsigned int group2asid[MLX5_VDPA_NUMVQ_GROUPS]; ··· 115 114 int mlx5_vdpa_create_mkey(struct mlx5_vdpa_dev *mvdev, u32 *mkey, u32 *in, 116 115 int inlen); 117 116 int mlx5_vdpa_destroy_mkey(struct mlx5_vdpa_dev *mvdev, u32 mkey); 118 - int mlx5_vdpa_handle_set_map(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); 122 - void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev); 123 - void mlx5_vdpa_destroy_mr_asid(struct mlx5_vdpa_dev *mvdev, unsigned int asid); 117 + struct mlx5_vdpa_mr *mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, 118 + struct vhost_iotlb *iotlb); 119 + void mlx5_vdpa_destroy_mr_resources(struct mlx5_vdpa_dev *mvdev); 120 + void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev, 121 + struct mlx5_vdpa_mr *mr); 122 + void mlx5_vdpa_update_mr(struct mlx5_vdpa_dev *mvdev, 123 + struct mlx5_vdpa_mr *mr, 124 + unsigned int asid); 125 + int mlx5_vdpa_update_cvq_iotlb(struct mlx5_vdpa_dev *mvdev, 126 + struct vhost_iotlb *iotlb, 127 + unsigned int asid); 128 + int mlx5_vdpa_create_dma_mr(struct mlx5_vdpa_dev *mvdev); 129 + int mlx5_vdpa_reset_mr(struct mlx5_vdpa_dev *mvdev, unsigned int asid); 124 130 125 131 #define mlx5_vdpa_warn(__dev, format, ...) \ 126 132 dev_warn((__dev)->mdev->device, "%s:%d:(pid %d) warning: " format, __func__, __LINE__, \
+127 -84
drivers/vdpa/mlx5/core/mr.c
··· 301 301 sg_free_table(&mr->sg_head); 302 302 } 303 303 304 - static int add_direct_chain(struct mlx5_vdpa_dev *mvdev, u64 start, u64 size, u8 perm, 304 + static int add_direct_chain(struct mlx5_vdpa_dev *mvdev, 305 + struct mlx5_vdpa_mr *mr, 306 + u64 start, 307 + u64 size, 308 + u8 perm, 305 309 struct vhost_iotlb *iotlb) 306 310 { 307 - struct mlx5_vdpa_mr *mr = &mvdev->mr; 308 311 struct mlx5_vdpa_direct_mr *dmr; 309 312 struct mlx5_vdpa_direct_mr *n; 310 313 LIST_HEAD(tmp); ··· 357 354 * indirect memory key that provides access to the enitre address space given 358 355 * by iotlb. 359 356 */ 360 - static int create_user_mr(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb) 357 + static int create_user_mr(struct mlx5_vdpa_dev *mvdev, 358 + struct mlx5_vdpa_mr *mr, 359 + struct vhost_iotlb *iotlb) 361 360 { 362 - struct mlx5_vdpa_mr *mr = &mvdev->mr; 363 361 struct mlx5_vdpa_direct_mr *dmr; 364 362 struct mlx5_vdpa_direct_mr *n; 365 363 struct vhost_iotlb_map *map; ··· 388 384 LOG_MAX_KLM_SIZE); 389 385 mr->num_klms += nnuls; 390 386 } 391 - err = add_direct_chain(mvdev, ps, pe - ps, pperm, iotlb); 387 + err = add_direct_chain(mvdev, mr, ps, pe - ps, pperm, iotlb); 392 388 if (err) 393 389 goto err_chain; 394 390 } ··· 397 393 pperm = map->perm; 398 394 } 399 395 } 400 - err = add_direct_chain(mvdev, ps, pe - ps, pperm, iotlb); 396 + err = add_direct_chain(mvdev, mr, ps, pe - ps, pperm, iotlb); 401 397 if (err) 402 398 goto err_chain; 403 399 ··· 454 450 mlx5_vdpa_destroy_mkey(mvdev, mr->mkey); 455 451 } 456 452 457 - static int dup_iotlb(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *src) 453 + static int dup_iotlb(struct vhost_iotlb *dst, struct vhost_iotlb *src) 458 454 { 459 455 struct vhost_iotlb_map *map; 460 456 u64 start = 0, last = ULLONG_MAX; 461 457 int err; 462 458 459 + if (dst == src) 460 + return -EINVAL; 461 + 463 462 if (!src) { 464 - err = vhost_iotlb_add_range(mvdev->cvq.iotlb, start, last, start, VHOST_ACCESS_RW); 463 + err = vhost_iotlb_add_range(dst, start, last, start, VHOST_ACCESS_RW); 465 464 return err; 466 465 } 467 466 468 467 for (map = vhost_iotlb_itree_first(src, start, last); map; 469 468 map = vhost_iotlb_itree_next(map, start, last)) { 470 - err = vhost_iotlb_add_range(mvdev->cvq.iotlb, map->start, map->last, 469 + err = vhost_iotlb_add_range(dst, map->start, map->last, 471 470 map->addr, map->perm); 472 471 if (err) 473 472 return err; ··· 478 471 return 0; 479 472 } 480 473 481 - static void prune_iotlb(struct mlx5_vdpa_dev *mvdev) 474 + static void prune_iotlb(struct vhost_iotlb *iotlb) 482 475 { 483 - vhost_iotlb_del_range(mvdev->cvq.iotlb, 0, ULLONG_MAX); 476 + vhost_iotlb_del_range(iotlb, 0, ULLONG_MAX); 484 477 } 485 478 486 479 static void destroy_user_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr) ··· 496 489 } 497 490 } 498 491 499 - static void _mlx5_vdpa_destroy_cvq_mr(struct mlx5_vdpa_dev *mvdev, unsigned int asid) 492 + static void _mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev, struct mlx5_vdpa_mr *mr) 500 493 { 501 - if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] != asid) 502 - return; 503 - 504 - prune_iotlb(mvdev); 505 - } 506 - 507 - static void _mlx5_vdpa_destroy_dvq_mr(struct mlx5_vdpa_dev *mvdev, unsigned int asid) 508 - { 509 - struct mlx5_vdpa_mr *mr = &mvdev->mr; 510 - 511 - if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] != asid) 512 - return; 513 - 514 - if (!mr->initialized) 515 - return; 516 - 517 494 if (mr->user_mr) 518 495 destroy_user_mr(mvdev, mr); 519 496 else 520 497 destroy_dma_mr(mvdev, mr); 521 498 522 - mr->initialized = false; 499 + vhost_iotlb_free(mr->iotlb); 523 500 } 524 501 525 - void mlx5_vdpa_destroy_mr_asid(struct mlx5_vdpa_dev *mvdev, unsigned int asid) 502 + void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev, 503 + struct mlx5_vdpa_mr *mr) 526 504 { 527 - struct mlx5_vdpa_mr *mr = &mvdev->mr; 505 + if (!mr) 506 + return; 528 507 529 - mutex_lock(&mr->mkey_mtx); 508 + mutex_lock(&mvdev->mr_mtx); 530 509 531 - _mlx5_vdpa_destroy_dvq_mr(mvdev, asid); 532 - _mlx5_vdpa_destroy_cvq_mr(mvdev, asid); 510 + _mlx5_vdpa_destroy_mr(mvdev, mr); 533 511 534 - mutex_unlock(&mr->mkey_mtx); 512 + for (int i = 0; i < MLX5_VDPA_NUM_AS; i++) { 513 + if (mvdev->mr[i] == mr) 514 + mvdev->mr[i] = NULL; 515 + } 516 + 517 + mutex_unlock(&mvdev->mr_mtx); 518 + 519 + kfree(mr); 535 520 } 536 521 537 - void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev) 522 + void mlx5_vdpa_update_mr(struct mlx5_vdpa_dev *mvdev, 523 + struct mlx5_vdpa_mr *new_mr, 524 + unsigned int asid) 538 525 { 539 - mlx5_vdpa_destroy_mr_asid(mvdev, mvdev->group2asid[MLX5_VDPA_CVQ_GROUP]); 540 - mlx5_vdpa_destroy_mr_asid(mvdev, mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP]); 526 + struct mlx5_vdpa_mr *old_mr = mvdev->mr[asid]; 527 + 528 + mutex_lock(&mvdev->mr_mtx); 529 + 530 + mvdev->mr[asid] = new_mr; 531 + if (old_mr) { 532 + _mlx5_vdpa_destroy_mr(mvdev, old_mr); 533 + kfree(old_mr); 534 + } 535 + 536 + mutex_unlock(&mvdev->mr_mtx); 537 + 541 538 } 542 539 543 - static int _mlx5_vdpa_create_cvq_mr(struct mlx5_vdpa_dev *mvdev, 544 - struct vhost_iotlb *iotlb, 545 - unsigned int asid) 540 + void mlx5_vdpa_destroy_mr_resources(struct mlx5_vdpa_dev *mvdev) 546 541 { 547 - if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] != asid) 548 - return 0; 542 + for (int i = 0; i < MLX5_VDPA_NUM_AS; i++) 543 + mlx5_vdpa_destroy_mr(mvdev, mvdev->mr[i]); 549 544 550 - return dup_iotlb(mvdev, iotlb); 545 + prune_iotlb(mvdev->cvq.iotlb); 551 546 } 552 547 553 - static int _mlx5_vdpa_create_dvq_mr(struct mlx5_vdpa_dev *mvdev, 554 - struct vhost_iotlb *iotlb, 555 - unsigned int asid) 548 + static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, 549 + struct mlx5_vdpa_mr *mr, 550 + struct vhost_iotlb *iotlb) 556 551 { 557 - struct mlx5_vdpa_mr *mr = &mvdev->mr; 558 552 int err; 559 553 560 - if (mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP] != asid) 561 - return 0; 562 - 563 - if (mr->initialized) 564 - return 0; 565 - 566 554 if (iotlb) 567 - err = create_user_mr(mvdev, iotlb); 555 + err = create_user_mr(mvdev, mr, iotlb); 568 556 else 569 557 err = create_dma_mr(mvdev, mr); 570 558 571 559 if (err) 572 560 return err; 573 561 574 - mr->initialized = true; 562 + mr->iotlb = vhost_iotlb_alloc(0, 0); 563 + if (!mr->iotlb) { 564 + err = -ENOMEM; 565 + goto err_mr; 566 + } 567 + 568 + err = dup_iotlb(mr->iotlb, iotlb); 569 + if (err) 570 + goto err_iotlb; 575 571 576 572 return 0; 573 + 574 + err_iotlb: 575 + vhost_iotlb_free(mr->iotlb); 576 + 577 + err_mr: 578 + if (iotlb) 579 + destroy_user_mr(mvdev, mr); 580 + else 581 + destroy_dma_mr(mvdev, mr); 582 + 583 + return err; 577 584 } 578 585 579 - static int _mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, 580 - struct vhost_iotlb *iotlb, unsigned int asid) 586 + struct mlx5_vdpa_mr *mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, 587 + struct vhost_iotlb *iotlb) 581 588 { 589 + struct mlx5_vdpa_mr *mr; 582 590 int err; 583 591 584 - err = _mlx5_vdpa_create_dvq_mr(mvdev, iotlb, asid); 585 - if (err) 586 - return err; 592 + mr = kzalloc(sizeof(*mr), GFP_KERNEL); 593 + if (!mr) 594 + return ERR_PTR(-ENOMEM); 587 595 588 - err = _mlx5_vdpa_create_cvq_mr(mvdev, iotlb, asid); 596 + mutex_lock(&mvdev->mr_mtx); 597 + err = _mlx5_vdpa_create_mr(mvdev, mr, iotlb); 598 + mutex_unlock(&mvdev->mr_mtx); 599 + 589 600 if (err) 590 601 goto out_err; 591 602 592 - return 0; 603 + return mr; 593 604 594 605 out_err: 595 - _mlx5_vdpa_destroy_dvq_mr(mvdev, asid); 596 - 597 - return err; 606 + kfree(mr); 607 + return ERR_PTR(err); 598 608 } 599 609 600 - int mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb, 601 - unsigned int asid) 610 + int mlx5_vdpa_update_cvq_iotlb(struct mlx5_vdpa_dev *mvdev, 611 + struct vhost_iotlb *iotlb, 612 + unsigned int asid) 602 613 { 603 614 int err; 604 615 605 - mutex_lock(&mvdev->mr.mkey_mtx); 606 - err = _mlx5_vdpa_create_mr(mvdev, iotlb, asid); 607 - mutex_unlock(&mvdev->mr.mkey_mtx); 616 + if (mvdev->group2asid[MLX5_VDPA_CVQ_GROUP] != asid) 617 + return 0; 618 + 619 + spin_lock(&mvdev->cvq.iommu_lock); 620 + 621 + prune_iotlb(mvdev->cvq.iotlb); 622 + err = dup_iotlb(mvdev->cvq.iotlb, iotlb); 623 + 624 + spin_unlock(&mvdev->cvq.iommu_lock); 625 + 608 626 return err; 609 627 } 610 628 611 - int mlx5_vdpa_handle_set_map(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb, 612 - bool *change_map, unsigned int asid) 629 + int mlx5_vdpa_create_dma_mr(struct mlx5_vdpa_dev *mvdev) 613 630 { 614 - struct mlx5_vdpa_mr *mr = &mvdev->mr; 615 - int err = 0; 631 + struct mlx5_vdpa_mr *mr; 616 632 617 - *change_map = false; 618 - mutex_lock(&mr->mkey_mtx); 619 - if (mr->initialized) { 620 - mlx5_vdpa_info(mvdev, "memory map update\n"); 621 - *change_map = true; 633 + mr = mlx5_vdpa_create_mr(mvdev, NULL); 634 + if (IS_ERR(mr)) 635 + return PTR_ERR(mr); 636 + 637 + mlx5_vdpa_update_mr(mvdev, mr, 0); 638 + 639 + return mlx5_vdpa_update_cvq_iotlb(mvdev, NULL, 0); 640 + } 641 + 642 + int mlx5_vdpa_reset_mr(struct mlx5_vdpa_dev *mvdev, unsigned int asid) 643 + { 644 + if (asid >= MLX5_VDPA_NUM_AS) 645 + return -EINVAL; 646 + 647 + mlx5_vdpa_destroy_mr(mvdev, mvdev->mr[asid]); 648 + 649 + if (asid == 0 && MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) { 650 + if (mlx5_vdpa_create_dma_mr(mvdev)) 651 + mlx5_vdpa_warn(mvdev, "create DMA MR failed\n"); 652 + } else { 653 + mlx5_vdpa_update_cvq_iotlb(mvdev, NULL, asid); 622 654 } 623 - if (!*change_map) 624 - err = _mlx5_vdpa_create_mr(mvdev, iotlb, asid); 625 - mutex_unlock(&mr->mkey_mtx); 626 655 627 - return err; 656 + return 0; 628 657 }
+3 -3
drivers/vdpa/mlx5/core/resources.c
··· 256 256 mlx5_vdpa_warn(mvdev, "resources already allocated\n"); 257 257 return -EINVAL; 258 258 } 259 - mutex_init(&mvdev->mr.mkey_mtx); 259 + mutex_init(&mvdev->mr_mtx); 260 260 res->uar = mlx5_get_uars_page(mdev); 261 261 if (IS_ERR(res->uar)) { 262 262 err = PTR_ERR(res->uar); ··· 301 301 err_uctx: 302 302 mlx5_put_uars_page(mdev, res->uar); 303 303 err_uars: 304 - mutex_destroy(&mvdev->mr.mkey_mtx); 304 + mutex_destroy(&mvdev->mr_mtx); 305 305 return err; 306 306 } 307 307 ··· 318 318 dealloc_pd(mvdev, res->pdn, res->uid); 319 319 destroy_uctx(mvdev, res->uid); 320 320 mlx5_put_uars_page(mvdev->mdev, res->uar); 321 - mutex_destroy(&mvdev->mr.mkey_mtx); 321 + mutex_destroy(&mvdev->mr_mtx); 322 322 res->valid = false; 323 323 }
+106 -31
drivers/vdpa/mlx5/net/mlx5_vnet.c
··· 7 7 #include <uapi/linux/virtio_net.h> 8 8 #include <uapi/linux/virtio_ids.h> 9 9 #include <uapi/linux/vdpa.h> 10 + #include <uapi/linux/vhost_types.h> 10 11 #include <linux/virtio_config.h> 11 12 #include <linux/auxiliary_bus.h> 12 13 #include <linux/mlx5/cq.h> ··· 862 861 { 863 862 int inlen = MLX5_ST_SZ_BYTES(create_virtio_net_q_in); 864 863 u32 out[MLX5_ST_SZ_DW(create_virtio_net_q_out)] = {}; 864 + struct mlx5_vdpa_dev *mvdev = &ndev->mvdev; 865 + struct mlx5_vdpa_mr *vq_mr; 866 + struct mlx5_vdpa_mr *vq_desc_mr; 865 867 void *obj_context; 866 868 u16 mlx_features; 867 869 void *cmd_hdr; ··· 917 913 MLX5_SET64(virtio_q, vq_ctx, desc_addr, mvq->desc_addr); 918 914 MLX5_SET64(virtio_q, vq_ctx, used_addr, mvq->device_addr); 919 915 MLX5_SET64(virtio_q, vq_ctx, available_addr, mvq->driver_addr); 920 - MLX5_SET(virtio_q, vq_ctx, virtio_q_mkey, ndev->mvdev.mr.mkey); 916 + vq_mr = mvdev->mr[mvdev->group2asid[MLX5_VDPA_DATAVQ_GROUP]]; 917 + if (vq_mr) 918 + MLX5_SET(virtio_q, vq_ctx, virtio_q_mkey, vq_mr->mkey); 919 + 920 + vq_desc_mr = mvdev->mr[mvdev->group2asid[MLX5_VDPA_DATAVQ_DESC_GROUP]]; 921 + if (vq_desc_mr && MLX5_CAP_DEV_VDPA_EMULATION(mvdev->mdev, desc_group_mkey_supported)) 922 + MLX5_SET(virtio_q, vq_ctx, desc_group_mkey, vq_desc_mr->mkey); 923 + 921 924 MLX5_SET(virtio_q, vq_ctx, umem_1_id, mvq->umem1.id); 922 925 MLX5_SET(virtio_q, vq_ctx, umem_1_size, mvq->umem1.size); 923 926 MLX5_SET(virtio_q, vq_ctx, umem_2_id, mvq->umem2.id); ··· 2312 2301 return MLX5_VDPA_DATAVQ_GROUP; 2313 2302 } 2314 2303 2304 + static u32 mlx5_vdpa_get_vq_desc_group(struct vdpa_device *vdev, u16 idx) 2305 + { 2306 + struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); 2307 + 2308 + if (is_ctrl_vq_idx(mvdev, idx)) 2309 + return MLX5_VDPA_CVQ_GROUP; 2310 + 2311 + return MLX5_VDPA_DATAVQ_DESC_GROUP; 2312 + } 2313 + 2315 2314 static u64 mlx_to_vritio_features(u16 dev_features) 2316 2315 { 2317 2316 u64 result = 0; ··· 2560 2539 flush_workqueue(ndev->mvdev.wq); 2561 2540 } 2562 2541 2542 + static u64 mlx5_vdpa_get_backend_features(const struct vdpa_device *vdpa) 2543 + { 2544 + return BIT_ULL(VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK); 2545 + } 2546 + 2563 2547 static int mlx5_vdpa_set_driver_features(struct vdpa_device *vdev, u64 features) 2564 2548 { 2565 2549 struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); ··· 2699 2673 } 2700 2674 2701 2675 static int mlx5_vdpa_change_map(struct mlx5_vdpa_dev *mvdev, 2702 - struct vhost_iotlb *iotlb, unsigned int asid) 2676 + struct mlx5_vdpa_mr *new_mr, 2677 + unsigned int asid) 2703 2678 { 2704 2679 struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev); 2705 2680 int err; ··· 2708 2681 suspend_vqs(ndev); 2709 2682 err = save_channels_info(ndev); 2710 2683 if (err) 2711 - goto err_mr; 2684 + return err; 2712 2685 2713 2686 teardown_driver(ndev); 2714 - mlx5_vdpa_destroy_mr_asid(mvdev, asid); 2715 - err = mlx5_vdpa_create_mr(mvdev, iotlb, asid); 2716 - if (err) 2717 - goto err_mr; 2687 + 2688 + mlx5_vdpa_update_mr(mvdev, new_mr, asid); 2718 2689 2719 2690 if (!(mvdev->status & VIRTIO_CONFIG_S_DRIVER_OK) || mvdev->suspended) 2720 - goto err_mr; 2691 + return 0; 2721 2692 2722 2693 restore_channels_info(ndev); 2723 2694 err = setup_driver(mvdev); 2724 2695 if (err) 2725 - goto err_setup; 2696 + return err; 2726 2697 2727 2698 return 0; 2728 - 2729 - err_setup: 2730 - mlx5_vdpa_destroy_mr_asid(mvdev, asid); 2731 - err_mr: 2732 - return err; 2733 2699 } 2734 2700 2735 2701 /* reslock must be held for this function */ ··· 2861 2841 err_driver: 2862 2842 unregister_link_notifier(ndev); 2863 2843 err_setup: 2864 - mlx5_vdpa_destroy_mr(&ndev->mvdev); 2844 + mlx5_vdpa_destroy_mr_resources(&ndev->mvdev); 2865 2845 ndev->mvdev.status |= VIRTIO_CONFIG_S_FAILED; 2866 2846 err_clear: 2867 2847 up_write(&ndev->reslock); ··· 2876 2856 mvdev->group2asid[i] = 0; 2877 2857 } 2878 2858 2879 - static int mlx5_vdpa_reset(struct vdpa_device *vdev) 2859 + static int mlx5_vdpa_compat_reset(struct vdpa_device *vdev, u32 flags) 2880 2860 { 2881 2861 struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); 2882 2862 struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev); ··· 2888 2868 unregister_link_notifier(ndev); 2889 2869 teardown_driver(ndev); 2890 2870 clear_vqs_ready(ndev); 2891 - mlx5_vdpa_destroy_mr(&ndev->mvdev); 2871 + if (flags & VDPA_RESET_F_CLEAN_MAP) 2872 + mlx5_vdpa_destroy_mr_resources(&ndev->mvdev); 2892 2873 ndev->mvdev.status = 0; 2893 2874 ndev->mvdev.suspended = false; 2894 2875 ndev->cur_num_vqs = 0; ··· 2900 2879 init_group_to_asid_map(mvdev); 2901 2880 ++mvdev->generation; 2902 2881 2903 - if (MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) { 2904 - if (mlx5_vdpa_create_mr(mvdev, NULL, 0)) 2882 + if ((flags & VDPA_RESET_F_CLEAN_MAP) && 2883 + MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) { 2884 + if (mlx5_vdpa_create_dma_mr(mvdev)) 2905 2885 mlx5_vdpa_warn(mvdev, "create MR failed\n"); 2906 2886 } 2907 2887 up_write(&ndev->reslock); 2908 2888 2909 2889 return 0; 2890 + } 2891 + 2892 + static int mlx5_vdpa_reset(struct vdpa_device *vdev) 2893 + { 2894 + return mlx5_vdpa_compat_reset(vdev, 0); 2910 2895 } 2911 2896 2912 2897 static size_t mlx5_vdpa_get_config_size(struct vdpa_device *vdev) ··· 2946 2919 static int set_map_data(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb, 2947 2920 unsigned int asid) 2948 2921 { 2949 - bool change_map; 2922 + struct mlx5_vdpa_mr *new_mr; 2950 2923 int err; 2951 2924 2952 - err = mlx5_vdpa_handle_set_map(mvdev, iotlb, &change_map, asid); 2953 - if (err) { 2954 - mlx5_vdpa_warn(mvdev, "set map failed(%d)\n", err); 2955 - return err; 2925 + if (asid >= MLX5_VDPA_NUM_AS) 2926 + return -EINVAL; 2927 + 2928 + if (vhost_iotlb_itree_first(iotlb, 0, U64_MAX)) { 2929 + new_mr = mlx5_vdpa_create_mr(mvdev, iotlb); 2930 + if (IS_ERR(new_mr)) { 2931 + err = PTR_ERR(new_mr); 2932 + mlx5_vdpa_warn(mvdev, "create map failed(%d)\n", err); 2933 + return err; 2934 + } 2935 + } else { 2936 + /* Empty iotlbs don't have an mr but will clear the previous mr. */ 2937 + new_mr = NULL; 2956 2938 } 2957 2939 2958 - if (change_map) 2959 - err = mlx5_vdpa_change_map(mvdev, iotlb, asid); 2940 + if (!mvdev->mr[asid]) { 2941 + mlx5_vdpa_update_mr(mvdev, new_mr, asid); 2942 + } else { 2943 + err = mlx5_vdpa_change_map(mvdev, new_mr, asid); 2944 + if (err) { 2945 + mlx5_vdpa_warn(mvdev, "change map failed(%d)\n", err); 2946 + goto out_err; 2947 + } 2948 + } 2960 2949 2950 + return mlx5_vdpa_update_cvq_iotlb(mvdev, iotlb, asid); 2951 + 2952 + out_err: 2953 + mlx5_vdpa_destroy_mr(mvdev, new_mr); 2961 2954 return err; 2962 2955 } 2963 2956 ··· 2990 2943 2991 2944 down_write(&ndev->reslock); 2992 2945 err = set_map_data(mvdev, iotlb, asid); 2946 + up_write(&ndev->reslock); 2947 + return err; 2948 + } 2949 + 2950 + static int mlx5_vdpa_reset_map(struct vdpa_device *vdev, unsigned int asid) 2951 + { 2952 + struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); 2953 + struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev); 2954 + int err; 2955 + 2956 + down_write(&ndev->reslock); 2957 + err = mlx5_vdpa_reset_mr(mvdev, asid); 2993 2958 up_write(&ndev->reslock); 2994 2959 return err; 2995 2960 } ··· 3044 2985 ndev = to_mlx5_vdpa_ndev(mvdev); 3045 2986 3046 2987 free_resources(ndev); 3047 - mlx5_vdpa_destroy_mr(mvdev); 2988 + mlx5_vdpa_destroy_mr_resources(mvdev); 3048 2989 if (!is_zero_ether_addr(ndev->config.mac)) { 3049 2990 pfmdev = pci_get_drvdata(pci_physfn(mvdev->mdev->pdev)); 3050 2991 mlx5_mpfs_del_mac(pfmdev, ndev->config.mac); ··· 3228 3169 unsigned int asid) 3229 3170 { 3230 3171 struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); 3172 + int err = 0; 3231 3173 3232 3174 if (group >= MLX5_VDPA_NUMVQ_GROUPS) 3233 3175 return -EINVAL; 3234 3176 3235 3177 mvdev->group2asid[group] = asid; 3236 - return 0; 3178 + 3179 + mutex_lock(&mvdev->mr_mtx); 3180 + if (group == MLX5_VDPA_CVQ_GROUP && mvdev->mr[asid]) 3181 + err = mlx5_vdpa_update_cvq_iotlb(mvdev, mvdev->mr[asid]->iotlb, asid); 3182 + mutex_unlock(&mvdev->mr_mtx); 3183 + 3184 + return err; 3237 3185 } 3238 3186 3239 3187 static const struct vdpa_config_ops mlx5_vdpa_ops = { ··· 3257 3191 .get_vq_irq = mlx5_get_vq_irq, 3258 3192 .get_vq_align = mlx5_vdpa_get_vq_align, 3259 3193 .get_vq_group = mlx5_vdpa_get_vq_group, 3194 + .get_vq_desc_group = mlx5_vdpa_get_vq_desc_group, /* Op disabled if not supported. */ 3260 3195 .get_device_features = mlx5_vdpa_get_device_features, 3196 + .get_backend_features = mlx5_vdpa_get_backend_features, 3261 3197 .set_driver_features = mlx5_vdpa_set_driver_features, 3262 3198 .get_driver_features = mlx5_vdpa_get_driver_features, 3263 3199 .set_config_cb = mlx5_vdpa_set_config_cb, ··· 3269 3201 .get_status = mlx5_vdpa_get_status, 3270 3202 .set_status = mlx5_vdpa_set_status, 3271 3203 .reset = mlx5_vdpa_reset, 3204 + .compat_reset = mlx5_vdpa_compat_reset, 3272 3205 .get_config_size = mlx5_vdpa_get_config_size, 3273 3206 .get_config = mlx5_vdpa_get_config, 3274 3207 .set_config = mlx5_vdpa_set_config, 3275 3208 .get_generation = mlx5_vdpa_get_generation, 3276 3209 .set_map = mlx5_vdpa_set_map, 3210 + .reset_map = mlx5_vdpa_reset_map, 3277 3211 .set_group_asid = mlx5_set_group_asid, 3278 3212 .get_vq_dma_dev = mlx5_get_vq_dma_dev, 3279 3213 .free = mlx5_vdpa_free, ··· 3359 3289 struct vdpa_mgmt_dev mgtdev; 3360 3290 struct mlx5_adev *madev; 3361 3291 struct mlx5_vdpa_net *ndev; 3292 + struct vdpa_config_ops vdpa_ops; 3362 3293 }; 3363 3294 3364 3295 static int config_func_mtu(struct mlx5_core_dev *mdev, u16 mtu) ··· 3473 3402 max_vqs = 2; 3474 3403 } 3475 3404 3476 - ndev = vdpa_alloc_device(struct mlx5_vdpa_net, mvdev.vdev, mdev->device, &mlx5_vdpa_ops, 3405 + ndev = vdpa_alloc_device(struct mlx5_vdpa_net, mvdev.vdev, mdev->device, &mgtdev->vdpa_ops, 3477 3406 MLX5_VDPA_NUMVQ_GROUPS, MLX5_VDPA_NUM_AS, name, false); 3478 3407 if (IS_ERR(ndev)) 3479 3408 return PTR_ERR(ndev); ··· 3556 3485 goto err_mpfs; 3557 3486 3558 3487 if (MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) { 3559 - err = mlx5_vdpa_create_mr(mvdev, NULL, 0); 3488 + err = mlx5_vdpa_create_dma_mr(mvdev); 3560 3489 if (err) 3561 3490 goto err_res; 3562 3491 } ··· 3586 3515 err_res2: 3587 3516 free_resources(ndev); 3588 3517 err_mr: 3589 - mlx5_vdpa_destroy_mr(mvdev); 3518 + mlx5_vdpa_destroy_mr_resources(mvdev); 3590 3519 err_res: 3591 3520 mlx5_vdpa_free_resources(&ndev->mvdev); 3592 3521 err_mpfs: ··· 3646 3575 MLX5_CAP_DEV_VDPA_EMULATION(mdev, max_num_virtio_queues) + 1; 3647 3576 mgtdev->mgtdev.supported_features = get_supported_features(mdev); 3648 3577 mgtdev->madev = madev; 3578 + mgtdev->vdpa_ops = mlx5_vdpa_ops; 3579 + 3580 + if (!MLX5_CAP_DEV_VDPA_EMULATION(mdev, desc_group_mkey_supported)) 3581 + mgtdev->vdpa_ops.get_vq_desc_group = NULL; 3649 3582 3650 3583 err = vdpa_mgmtdev_register(&mgtdev->mgtdev); 3651 3584 if (err)
+43 -9
drivers/vdpa/vdpa_sim/vdpa_sim.c
··· 139 139 vq->vring.notify = NULL; 140 140 } 141 141 142 - static void vdpasim_do_reset(struct vdpasim *vdpasim) 142 + static void vdpasim_do_reset(struct vdpasim *vdpasim, u32 flags) 143 143 { 144 144 int i; 145 145 ··· 151 151 &vdpasim->iommu_lock); 152 152 } 153 153 154 - for (i = 0; i < vdpasim->dev_attr.nas; i++) { 155 - vhost_iotlb_reset(&vdpasim->iommu[i]); 156 - vhost_iotlb_add_range(&vdpasim->iommu[i], 0, ULONG_MAX, 157 - 0, VHOST_MAP_RW); 158 - vdpasim->iommu_pt[i] = true; 154 + if (flags & VDPA_RESET_F_CLEAN_MAP) { 155 + for (i = 0; i < vdpasim->dev_attr.nas; i++) { 156 + vhost_iotlb_reset(&vdpasim->iommu[i]); 157 + vhost_iotlb_add_range(&vdpasim->iommu[i], 0, ULONG_MAX, 158 + 0, VHOST_MAP_RW); 159 + vdpasim->iommu_pt[i] = true; 160 + } 159 161 } 160 162 161 163 vdpasim->running = true; ··· 261 259 if (!vdpasim->iommu_pt) 262 260 goto err_iommu; 263 261 264 - for (i = 0; i < vdpasim->dev_attr.nas; i++) 262 + for (i = 0; i < vdpasim->dev_attr.nas; i++) { 265 263 vhost_iotlb_init(&vdpasim->iommu[i], max_iotlb_entries, 0); 264 + vhost_iotlb_add_range(&vdpasim->iommu[i], 0, ULONG_MAX, 0, 265 + VHOST_MAP_RW); 266 + vdpasim->iommu_pt[i] = true; 267 + } 266 268 267 269 for (i = 0; i < dev_attr->nvqs; i++) 268 270 vringh_set_iotlb(&vdpasim->vqs[i].vring, &vdpasim->iommu[0], ··· 486 480 mutex_unlock(&vdpasim->mutex); 487 481 } 488 482 489 - static int vdpasim_reset(struct vdpa_device *vdpa) 483 + static int vdpasim_compat_reset(struct vdpa_device *vdpa, u32 flags) 490 484 { 491 485 struct vdpasim *vdpasim = vdpa_to_sim(vdpa); 492 486 493 487 mutex_lock(&vdpasim->mutex); 494 488 vdpasim->status = 0; 495 - vdpasim_do_reset(vdpasim); 489 + vdpasim_do_reset(vdpasim, flags); 496 490 mutex_unlock(&vdpasim->mutex); 497 491 498 492 return 0; 493 + } 494 + 495 + static int vdpasim_reset(struct vdpa_device *vdpa) 496 + { 497 + return vdpasim_compat_reset(vdpa, 0); 499 498 } 500 499 501 500 static int vdpasim_suspend(struct vdpa_device *vdpa) ··· 648 637 return ret; 649 638 } 650 639 640 + static int vdpasim_reset_map(struct vdpa_device *vdpa, unsigned int asid) 641 + { 642 + struct vdpasim *vdpasim = vdpa_to_sim(vdpa); 643 + 644 + if (asid >= vdpasim->dev_attr.nas) 645 + return -EINVAL; 646 + 647 + spin_lock(&vdpasim->iommu_lock); 648 + if (vdpasim->iommu_pt[asid]) 649 + goto out; 650 + vhost_iotlb_reset(&vdpasim->iommu[asid]); 651 + vhost_iotlb_add_range(&vdpasim->iommu[asid], 0, ULONG_MAX, 652 + 0, VHOST_MAP_RW); 653 + vdpasim->iommu_pt[asid] = true; 654 + out: 655 + spin_unlock(&vdpasim->iommu_lock); 656 + return 0; 657 + } 658 + 651 659 static int vdpasim_bind_mm(struct vdpa_device *vdpa, struct mm_struct *mm) 652 660 { 653 661 struct vdpasim *vdpasim = vdpa_to_sim(vdpa); ··· 779 749 .get_status = vdpasim_get_status, 780 750 .set_status = vdpasim_set_status, 781 751 .reset = vdpasim_reset, 752 + .compat_reset = vdpasim_compat_reset, 782 753 .suspend = vdpasim_suspend, 783 754 .resume = vdpasim_resume, 784 755 .get_config_size = vdpasim_get_config_size, ··· 790 759 .set_group_asid = vdpasim_set_group_asid, 791 760 .dma_map = vdpasim_dma_map, 792 761 .dma_unmap = vdpasim_dma_unmap, 762 + .reset_map = vdpasim_reset_map, 793 763 .bind_mm = vdpasim_bind_mm, 794 764 .unbind_mm = vdpasim_unbind_mm, 795 765 .free = vdpasim_free, ··· 819 787 .get_status = vdpasim_get_status, 820 788 .set_status = vdpasim_set_status, 821 789 .reset = vdpasim_reset, 790 + .compat_reset = vdpasim_compat_reset, 822 791 .suspend = vdpasim_suspend, 823 792 .resume = vdpasim_resume, 824 793 .get_config_size = vdpasim_get_config_size, ··· 829 796 .get_iova_range = vdpasim_get_iova_range, 830 797 .set_group_asid = vdpasim_set_group_asid, 831 798 .set_map = vdpasim_set_map, 799 + .reset_map = vdpasim_reset_map, 832 800 .bind_mm = vdpasim_bind_mm, 833 801 .unbind_mm = vdpasim_unbind_mm, 834 802 .free = vdpasim_free,
+21 -19
drivers/vdpa/vdpa_user/vduse_dev.c
··· 134 134 static DEFINE_IDR(vduse_idr); 135 135 136 136 static dev_t vduse_major; 137 - static struct class *vduse_class; 138 137 static struct cdev vduse_ctrl_cdev; 139 138 static struct cdev vduse_cdev; 140 139 static struct workqueue_struct *vduse_irq_wq; ··· 1527 1528 .default_groups = vq_groups, 1528 1529 }; 1529 1530 1531 + static char *vduse_devnode(const struct device *dev, umode_t *mode) 1532 + { 1533 + return kasprintf(GFP_KERNEL, "vduse/%s", dev_name(dev)); 1534 + } 1535 + 1536 + static const struct class vduse_class = { 1537 + .name = "vduse", 1538 + .devnode = vduse_devnode, 1539 + }; 1540 + 1530 1541 static void vduse_dev_deinit_vqs(struct vduse_dev *dev) 1531 1542 { 1532 1543 int i; ··· 1647 1638 mutex_unlock(&dev->lock); 1648 1639 1649 1640 vduse_dev_reset(dev); 1650 - device_destroy(vduse_class, MKDEV(MAJOR(vduse_major), dev->minor)); 1641 + device_destroy(&vduse_class, MKDEV(MAJOR(vduse_major), dev->minor)); 1651 1642 idr_remove(&vduse_idr, dev->minor); 1652 1643 kvfree(dev->config); 1653 1644 vduse_dev_deinit_vqs(dev); ··· 1814 1805 1815 1806 dev->minor = ret; 1816 1807 dev->msg_timeout = VDUSE_MSG_DEFAULT_TIMEOUT; 1817 - dev->dev = device_create_with_groups(vduse_class, NULL, 1808 + dev->dev = device_create_with_groups(&vduse_class, NULL, 1818 1809 MKDEV(MAJOR(vduse_major), dev->minor), 1819 1810 dev, vduse_dev_groups, "%s", config->name); 1820 1811 if (IS_ERR(dev->dev)) { ··· 1830 1821 1831 1822 return 0; 1832 1823 err_vqs: 1833 - device_destroy(vduse_class, MKDEV(MAJOR(vduse_major), dev->minor)); 1824 + device_destroy(&vduse_class, MKDEV(MAJOR(vduse_major), dev->minor)); 1834 1825 err_dev: 1835 1826 idr_remove(&vduse_idr, dev->minor); 1836 1827 err_idr: ··· 1942 1933 .compat_ioctl = compat_ptr_ioctl, 1943 1934 .llseek = noop_llseek, 1944 1935 }; 1945 - 1946 - static char *vduse_devnode(const struct device *dev, umode_t *mode) 1947 - { 1948 - return kasprintf(GFP_KERNEL, "vduse/%s", dev_name(dev)); 1949 - } 1950 1936 1951 1937 struct vduse_mgmt_dev { 1952 1938 struct vdpa_mgmt_dev mgmt_dev; ··· 2086 2082 int ret; 2087 2083 struct device *dev; 2088 2084 2089 - vduse_class = class_create("vduse"); 2090 - if (IS_ERR(vduse_class)) 2091 - return PTR_ERR(vduse_class); 2092 - 2093 - vduse_class->devnode = vduse_devnode; 2085 + ret = class_register(&vduse_class); 2086 + if (ret) 2087 + return ret; 2094 2088 2095 2089 ret = alloc_chrdev_region(&vduse_major, 0, VDUSE_DEV_MAX, "vduse"); 2096 2090 if (ret) ··· 2101 2099 if (ret) 2102 2100 goto err_ctrl_cdev; 2103 2101 2104 - dev = device_create(vduse_class, NULL, vduse_major, NULL, "control"); 2102 + dev = device_create(&vduse_class, NULL, vduse_major, NULL, "control"); 2105 2103 if (IS_ERR(dev)) { 2106 2104 ret = PTR_ERR(dev); 2107 2105 goto err_device; ··· 2143 2141 err_wq: 2144 2142 cdev_del(&vduse_cdev); 2145 2143 err_cdev: 2146 - device_destroy(vduse_class, vduse_major); 2144 + device_destroy(&vduse_class, vduse_major); 2147 2145 err_device: 2148 2146 cdev_del(&vduse_ctrl_cdev); 2149 2147 err_ctrl_cdev: 2150 2148 unregister_chrdev_region(vduse_major, VDUSE_DEV_MAX); 2151 2149 err_chardev_region: 2152 - class_destroy(vduse_class); 2150 + class_unregister(&vduse_class); 2153 2151 return ret; 2154 2152 } 2155 2153 module_init(vduse_init); ··· 2161 2159 destroy_workqueue(vduse_irq_bound_wq); 2162 2160 destroy_workqueue(vduse_irq_wq); 2163 2161 cdev_del(&vduse_cdev); 2164 - device_destroy(vduse_class, vduse_major); 2162 + device_destroy(&vduse_class, vduse_major); 2165 2163 cdev_del(&vduse_ctrl_cdev); 2166 2164 unregister_chrdev_region(vduse_major, VDUSE_DEV_MAX); 2167 - class_destroy(vduse_class); 2165 + class_unregister(&vduse_class); 2168 2166 } 2169 2167 module_exit(vduse_exit); 2170 2168
+1 -1
drivers/vhost/scsi.c
··· 1158 1158 /* 1159 1159 * Set prot_iter to data_iter and truncate it to 1160 1160 * prot_bytes, and advance data_iter past any 1161 - * preceeding prot_bytes that may be present. 1161 + * preceding prot_bytes that may be present. 1162 1162 * 1163 1163 * Also fix up the exp_data_len to reflect only the 1164 1164 * actual data payload length.
+75 -4
drivers/vhost/vdpa.c
··· 131 131 return vhost_vdpa_alloc_as(v, asid); 132 132 } 133 133 134 + static void vhost_vdpa_reset_map(struct vhost_vdpa *v, u32 asid) 135 + { 136 + struct vdpa_device *vdpa = v->vdpa; 137 + const struct vdpa_config_ops *ops = vdpa->config; 138 + 139 + if (ops->reset_map) 140 + ops->reset_map(vdpa, asid); 141 + } 142 + 134 143 static int vhost_vdpa_remove_as(struct vhost_vdpa *v, u32 asid) 135 144 { 136 145 struct vhost_vdpa_as *as = asid_to_as(v, asid); ··· 149 140 150 141 hlist_del(&as->hash_link); 151 142 vhost_vdpa_iotlb_unmap(v, &as->iotlb, 0ULL, 0ULL - 1, asid); 143 + /* 144 + * Devices with vendor specific IOMMU may need to restore 145 + * iotlb to the initial or default state, which cannot be 146 + * cleaned up in the all range unmap call above. Give them 147 + * a chance to clean up or reset the map to the desired 148 + * state. 149 + */ 150 + vhost_vdpa_reset_map(v, asid); 152 151 kfree(as); 153 152 154 153 return 0; ··· 227 210 irq_bypass_unregister_producer(&vq->call_ctx.producer); 228 211 } 229 212 230 - static int vhost_vdpa_reset(struct vhost_vdpa *v) 213 + static int _compat_vdpa_reset(struct vhost_vdpa *v) 231 214 { 232 215 struct vdpa_device *vdpa = v->vdpa; 216 + u32 flags = 0; 233 217 218 + if (v->vdev.vqs) { 219 + flags |= !vhost_backend_has_feature(v->vdev.vqs[0], 220 + VHOST_BACKEND_F_IOTLB_PERSIST) ? 221 + VDPA_RESET_F_CLEAN_MAP : 0; 222 + } 223 + 224 + return vdpa_reset(vdpa, flags); 225 + } 226 + 227 + static int vhost_vdpa_reset(struct vhost_vdpa *v) 228 + { 234 229 v->in_batch = 0; 235 - 236 - return vdpa_reset(vdpa); 230 + return _compat_vdpa_reset(v); 237 231 } 238 232 239 233 static long vhost_vdpa_bind_mm(struct vhost_vdpa *v) ··· 323 295 vhost_vdpa_unsetup_vq_irq(v, i); 324 296 325 297 if (status == 0) { 326 - ret = vdpa_reset(vdpa); 298 + ret = _compat_vdpa_reset(v); 327 299 if (ret) 328 300 return ret; 329 301 } else ··· 417 389 return ops->resume; 418 390 } 419 391 392 + static bool vhost_vdpa_has_desc_group(const struct vhost_vdpa *v) 393 + { 394 + struct vdpa_device *vdpa = v->vdpa; 395 + const struct vdpa_config_ops *ops = vdpa->config; 396 + 397 + return ops->get_vq_desc_group; 398 + } 399 + 420 400 static long vhost_vdpa_get_features(struct vhost_vdpa *v, u64 __user *featurep) 421 401 { 422 402 struct vdpa_device *vdpa = v->vdpa; ··· 448 412 return 0; 449 413 else 450 414 return ops->get_backend_features(vdpa); 415 + } 416 + 417 + static bool vhost_vdpa_has_persistent_map(const struct vhost_vdpa *v) 418 + { 419 + struct vdpa_device *vdpa = v->vdpa; 420 + const struct vdpa_config_ops *ops = vdpa->config; 421 + 422 + return (!ops->set_map && !ops->dma_map) || ops->reset_map || 423 + vhost_vdpa_get_backend_features(v) & BIT_ULL(VHOST_BACKEND_F_IOTLB_PERSIST); 451 424 } 452 425 453 426 static long vhost_vdpa_set_features(struct vhost_vdpa *v, u64 __user *featurep) ··· 650 605 else if (copy_to_user(argp, &s, sizeof(s))) 651 606 return -EFAULT; 652 607 return 0; 608 + case VHOST_VDPA_GET_VRING_DESC_GROUP: 609 + if (!vhost_vdpa_has_desc_group(v)) 610 + return -EOPNOTSUPP; 611 + s.index = idx; 612 + s.num = ops->get_vq_desc_group(vdpa, idx); 613 + if (s.num >= vdpa->ngroups) 614 + return -EIO; 615 + else if (copy_to_user(argp, &s, sizeof(s))) 616 + return -EFAULT; 617 + return 0; 653 618 case VHOST_VDPA_SET_GROUP_ASID: 654 619 if (copy_from_user(&s, argp, sizeof(s))) 655 620 return -EFAULT; ··· 745 690 if (copy_from_user(&features, featurep, sizeof(features))) 746 691 return -EFAULT; 747 692 if (features & ~(VHOST_VDPA_BACKEND_FEATURES | 693 + BIT_ULL(VHOST_BACKEND_F_DESC_ASID) | 694 + BIT_ULL(VHOST_BACKEND_F_IOTLB_PERSIST) | 748 695 BIT_ULL(VHOST_BACKEND_F_SUSPEND) | 749 696 BIT_ULL(VHOST_BACKEND_F_RESUME) | 750 697 BIT_ULL(VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK))) ··· 756 699 return -EOPNOTSUPP; 757 700 if ((features & BIT_ULL(VHOST_BACKEND_F_RESUME)) && 758 701 !vhost_vdpa_can_resume(v)) 702 + return -EOPNOTSUPP; 703 + if ((features & BIT_ULL(VHOST_BACKEND_F_DESC_ASID)) && 704 + !(features & BIT_ULL(VHOST_BACKEND_F_IOTLB_ASID))) 705 + return -EINVAL; 706 + if ((features & BIT_ULL(VHOST_BACKEND_F_DESC_ASID)) && 707 + !vhost_vdpa_has_desc_group(v)) 708 + return -EOPNOTSUPP; 709 + if ((features & BIT_ULL(VHOST_BACKEND_F_IOTLB_PERSIST)) && 710 + !vhost_vdpa_has_persistent_map(v)) 759 711 return -EOPNOTSUPP; 760 712 vhost_set_backend_features(&v->vdev, features); 761 713 return 0; ··· 819 753 features |= BIT_ULL(VHOST_BACKEND_F_SUSPEND); 820 754 if (vhost_vdpa_can_resume(v)) 821 755 features |= BIT_ULL(VHOST_BACKEND_F_RESUME); 756 + if (vhost_vdpa_has_desc_group(v)) 757 + features |= BIT_ULL(VHOST_BACKEND_F_DESC_ASID); 758 + if (vhost_vdpa_has_persistent_map(v)) 759 + features |= BIT_ULL(VHOST_BACKEND_F_IOTLB_PERSIST); 822 760 features |= vhost_vdpa_get_backend_features(v); 823 761 if (copy_to_user(featurep, &features, sizeof(features))) 824 762 r = -EFAULT; ··· 1355 1285 vhost_vdpa_free_domain(v); 1356 1286 vhost_dev_cleanup(&v->vdev); 1357 1287 kfree(v->vdev.vqs); 1288 + v->vdev.vqs = NULL; 1358 1289 } 1359 1290 1360 1291 static int vhost_vdpa_open(struct inode *inode, struct file *filep)
+1 -1
drivers/virtio/virtio_balloon.c
··· 745 745 * 2) update the host about the old page removed from vb->pages list; 746 746 * 747 747 * This function preforms the balloon page migration task. 748 - * Called through balloon_mapping->a_ops->migratepage 748 + * Called through movable_operations->migrate_page 749 749 */ 750 750 static int virtballoon_migratepage(struct balloon_dev_info *vb_dev_info, 751 751 struct page *newpage, struct page *page, enum migrate_mode mode)
+36
drivers/virtio/virtio_pci_modern.c
··· 39 39 __virtio_set_bit(vdev, VIRTIO_F_RING_RESET); 40 40 } 41 41 42 + static int __vp_check_common_size_one_feature(struct virtio_device *vdev, u32 fbit, 43 + u32 offset, const char *fname) 44 + { 45 + struct virtio_pci_device *vp_dev = to_vp_device(vdev); 46 + 47 + if (!__virtio_test_bit(vdev, fbit)) 48 + return 0; 49 + 50 + if (likely(vp_dev->mdev.common_len >= offset)) 51 + return 0; 52 + 53 + dev_err(&vdev->dev, 54 + "virtio: common cfg size(%zu) does not match the feature %s\n", 55 + vp_dev->mdev.common_len, fname); 56 + 57 + return -EINVAL; 58 + } 59 + 60 + #define vp_check_common_size_one_feature(vdev, fbit, field) \ 61 + __vp_check_common_size_one_feature(vdev, fbit, \ 62 + offsetofend(struct virtio_pci_modern_common_cfg, field), #fbit) 63 + 64 + static int vp_check_common_size(struct virtio_device *vdev) 65 + { 66 + if (vp_check_common_size_one_feature(vdev, VIRTIO_F_NOTIF_CONFIG_DATA, queue_notify_data)) 67 + return -EINVAL; 68 + 69 + if (vp_check_common_size_one_feature(vdev, VIRTIO_F_RING_RESET, queue_reset)) 70 + return -EINVAL; 71 + 72 + return 0; 73 + } 74 + 42 75 /* virtio config->finalize_features() implementation */ 43 76 static int vp_finalize_features(struct virtio_device *vdev) 44 77 { ··· 89 56 "but does not have VIRTIO_F_VERSION_1\n"); 90 57 return -EINVAL; 91 58 } 59 + 60 + if (vp_check_common_size(vdev)) 61 + return -EINVAL; 92 62 93 63 vp_modern_set_features(&vp_dev->mdev, vdev->features); 94 64
+5 -1
drivers/virtio/virtio_pci_modern_dev.c
··· 203 203 offsetof(struct virtio_pci_common_cfg, queue_used_lo)); 204 204 BUILD_BUG_ON(VIRTIO_PCI_COMMON_Q_USEDHI != 205 205 offsetof(struct virtio_pci_common_cfg, queue_used_hi)); 206 + BUILD_BUG_ON(VIRTIO_PCI_COMMON_Q_NDATA != 207 + offsetof(struct virtio_pci_modern_common_cfg, queue_notify_data)); 208 + BUILD_BUG_ON(VIRTIO_PCI_COMMON_Q_RESET != 209 + offsetof(struct virtio_pci_modern_common_cfg, queue_reset)); 206 210 } 207 211 208 212 /* ··· 296 292 mdev->common = vp_modern_map_capability(mdev, common, 297 293 sizeof(struct virtio_pci_common_cfg), 4, 298 294 0, sizeof(struct virtio_pci_modern_common_cfg), 299 - NULL, NULL); 295 + &mdev->common_len, NULL); 300 296 if (!mdev->common) 301 297 goto err_map_common; 302 298 mdev->isr = vp_modern_map_capability(mdev, isr, sizeof(u8), 1,
+1 -1
drivers/virtio/virtio_vdpa.c
··· 100 100 { 101 101 struct vdpa_device *vdpa = vd_get_vdpa(vdev); 102 102 103 - vdpa_reset(vdpa); 103 + vdpa_reset(vdpa, 0); 104 104 } 105 105 106 106 static bool virtio_vdpa_notify(struct virtqueue *vq)
+7 -1
include/linux/mlx5/mlx5_ifc.h
··· 1232 1232 u8 max_emulated_devices[0x8]; 1233 1233 u8 max_num_virtio_queues[0x18]; 1234 1234 1235 - u8 reserved_at_a0[0x60]; 1235 + u8 reserved_at_a0[0x20]; 1236 + 1237 + u8 reserved_at_c0[0x13]; 1238 + u8 desc_group_mkey_supported[0x1]; 1239 + u8 reserved_at_d4[0xc]; 1240 + 1241 + u8 reserved_at_e0[0x20]; 1236 1242 1237 1243 u8 umem_1_buffer_param_a[0x20]; 1238 1244
+6 -1
include/linux/mlx5/mlx5_ifc_vdpa.h
··· 74 74 u8 reserved_at_320[0x8]; 75 75 u8 pd[0x18]; 76 76 77 - u8 reserved_at_340[0xc0]; 77 + u8 reserved_at_340[0x20]; 78 + 79 + u8 desc_group_mkey[0x20]; 80 + 81 + u8 reserved_at_380[0x80]; 78 82 }; 79 83 80 84 struct mlx5_ifc_virtio_net_q_object_bits { ··· 145 141 MLX5_VIRTQ_MODIFY_MASK_STATE = (u64)1 << 0, 146 142 MLX5_VIRTQ_MODIFY_MASK_DIRTY_BITMAP_PARAMS = (u64)1 << 3, 147 143 MLX5_VIRTQ_MODIFY_MASK_DIRTY_BITMAP_DUMP_ENABLE = (u64)1 << 4, 144 + MLX5_VIRTQ_MODIFY_MASK_DESC_GROUP_MKEY = (u64)1 << 14, 148 145 }; 149 146 150 147 enum {
+39 -2
include/linux/vdpa.h
··· 204 204 * @vdev: vdpa device 205 205 * @idx: virtqueue index 206 206 * Returns u32: group id for this virtqueue 207 + * @get_vq_desc_group: Get the group id for the descriptor table of 208 + * a specific virtqueue (optional) 209 + * @vdev: vdpa device 210 + * @idx: virtqueue index 211 + * Returns u32: group id for the descriptor table 212 + * portion of this virtqueue. Could be different 213 + * than the one from @get_vq_group, in which case 214 + * the access to the descriptor table can be 215 + * confined to a separate asid, isolating from 216 + * the virtqueue's buffer address access. 207 217 * @get_device_features: Get virtio features supported by the device 208 218 * @vdev: vdpa device 209 219 * Returns the virtio features support by the ··· 251 241 * @status: virtio device status 252 242 * @reset: Reset device 253 243 * @vdev: vdpa device 244 + * Returns integer: success (0) or error (< 0) 245 + * @compat_reset: Reset device with compatibility quirks to 246 + * accommodate older userspace. Only needed by 247 + * parent driver which used to have bogus reset 248 + * behaviour, and has to maintain such behaviour 249 + * for compatibility with older userspace. 250 + * Historically compliant driver only has to 251 + * implement .reset, Historically non-compliant 252 + * driver should implement both. 253 + * @vdev: vdpa device 254 + * @flags: compatibility quirks for reset 254 255 * Returns integer: success (0) or error (< 0) 255 256 * @suspend: Suspend the device (optional) 256 257 * @vdev: vdpa device ··· 338 317 * @iova: iova to be unmapped 339 318 * @size: size of the area 340 319 * Returns integer: success (0) or error (< 0) 320 + * @reset_map: Reset device memory mapping to the default 321 + * state (optional) 322 + * Needed for devices that are using device 323 + * specific DMA translation and prefer mapping 324 + * to be decoupled from the virtio life cycle, 325 + * i.e. device .reset op does not reset mapping 326 + * @vdev: vdpa device 327 + * @asid: address space identifier 328 + * Returns integer: success (0) or error (< 0) 341 329 * @get_vq_dma_dev: Get the dma device for a specific 342 330 * virtqueue (optional) 343 331 * @vdev: vdpa device ··· 390 360 /* Device ops */ 391 361 u32 (*get_vq_align)(struct vdpa_device *vdev); 392 362 u32 (*get_vq_group)(struct vdpa_device *vdev, u16 idx); 363 + u32 (*get_vq_desc_group)(struct vdpa_device *vdev, u16 idx); 393 364 u64 (*get_device_features)(struct vdpa_device *vdev); 394 365 u64 (*get_backend_features)(const struct vdpa_device *vdev); 395 366 int (*set_driver_features)(struct vdpa_device *vdev, u64 features); ··· 404 373 u8 (*get_status)(struct vdpa_device *vdev); 405 374 void (*set_status)(struct vdpa_device *vdev, u8 status); 406 375 int (*reset)(struct vdpa_device *vdev); 376 + int (*compat_reset)(struct vdpa_device *vdev, u32 flags); 377 + #define VDPA_RESET_F_CLEAN_MAP 1 407 378 int (*suspend)(struct vdpa_device *vdev); 408 379 int (*resume)(struct vdpa_device *vdev); 409 380 size_t (*get_config_size)(struct vdpa_device *vdev); ··· 427 394 u64 iova, u64 size, u64 pa, u32 perm, void *opaque); 428 395 int (*dma_unmap)(struct vdpa_device *vdev, unsigned int asid, 429 396 u64 iova, u64 size); 397 + int (*reset_map)(struct vdpa_device *vdev, unsigned int asid); 430 398 int (*set_group_asid)(struct vdpa_device *vdev, unsigned int group, 431 399 unsigned int asid); 432 400 struct device *(*get_vq_dma_dev)(struct vdpa_device *vdev, u16 idx); ··· 519 485 return vdev->dma_dev; 520 486 } 521 487 522 - static inline int vdpa_reset(struct vdpa_device *vdev) 488 + static inline int vdpa_reset(struct vdpa_device *vdev, u32 flags) 523 489 { 524 490 const struct vdpa_config_ops *ops = vdev->config; 525 491 int ret; 526 492 527 493 down_write(&vdev->cf_lock); 528 494 vdev->features_valid = false; 529 - ret = ops->reset(vdev); 495 + if (ops->compat_reset && flags) 496 + ret = ops->compat_reset(vdev, flags); 497 + else 498 + ret = ops->reset(vdev); 530 499 up_write(&vdev->cf_lock); 531 500 return ret; 532 501 }
+23 -12
include/linux/virtio_pci_modern.h
··· 12 12 __le16 queue_reset; /* read-write */ 13 13 }; 14 14 15 + /** 16 + * struct virtio_pci_modern_device - info for modern PCI virtio 17 + * @pci_dev: Ptr to the PCI device struct 18 + * @common: Position of the common capability in the PCI config 19 + * @device: Device-specific data (non-legacy mode) 20 + * @notify_base: Base of vq notifications (non-legacy mode) 21 + * @notify_pa: Physical base of vq notifications 22 + * @isr: Where to read and clear interrupt 23 + * @notify_len: So we can sanity-check accesses 24 + * @device_len: So we can sanity-check accesses 25 + * @notify_map_cap: Capability for when we need to map notifications per-vq 26 + * @notify_offset_multiplier: Multiply queue_notify_off by this value 27 + * (non-legacy mode). 28 + * @modern_bars: Bitmask of BARs 29 + * @id: Device and vendor id 30 + * @device_id_check: Callback defined before vp_modern_probe() to be used to 31 + * verify the PCI device is a vendor's expected device rather 32 + * than the standard virtio PCI device 33 + * Returns the found device id or ERRNO 34 + * @dma_mask: Optional mask instead of the traditional DMA_BIT_MASK(64), 35 + * for vendor devices with DMA space address limitations 36 + */ 15 37 struct virtio_pci_modern_device { 16 38 struct pci_dev *pci_dev; 17 39 18 40 struct virtio_pci_common_cfg __iomem *common; 19 - /* Device-specific data (non-legacy mode) */ 20 41 void __iomem *device; 21 - /* Base of vq notifications (non-legacy mode). */ 22 42 void __iomem *notify_base; 23 - /* Physical base of vq notifications */ 24 43 resource_size_t notify_pa; 25 - /* Where to read and clear interrupt */ 26 44 u8 __iomem *isr; 27 45 28 - /* So we can sanity-check accesses. */ 29 46 size_t notify_len; 30 47 size_t device_len; 48 + size_t common_len; 31 49 32 - /* Capability for when we need to map notifications per-vq. */ 33 50 int notify_map_cap; 34 51 35 - /* Multiply queue_notify_off by this value. (non-legacy mode). */ 36 52 u32 notify_offset_multiplier; 37 - 38 53 int modern_bars; 39 - 40 54 struct virtio_device_id id; 41 55 42 - /* optional check for vendor virtio device, returns dev_id or -ERRNO */ 43 56 int (*device_id_check)(struct pci_dev *pdev); 44 - 45 - /* optional mask for devices with limited DMA space */ 46 57 u64 dma_mask; 47 58 }; 48 59
+8
include/uapi/linux/vhost.h
··· 219 219 */ 220 220 #define VHOST_VDPA_RESUME _IO(VHOST_VIRTIO, 0x7E) 221 221 222 + /* Get the group for the descriptor table including driver & device areas 223 + * of a virtqueue: read index, write group in num. 224 + * The virtqueue index is stored in the index field of vhost_vring_state. 225 + * The group ID of the descriptor table for this specific virtqueue 226 + * is returned via num field of vhost_vring_state. 227 + */ 228 + #define VHOST_VDPA_GET_VRING_DESC_GROUP _IOWR(VHOST_VIRTIO, 0x7F, \ 229 + struct vhost_vring_state) 222 230 #endif
+7
include/uapi/linux/vhost_types.h
··· 185 185 * DRIVER_OK 186 186 */ 187 187 #define VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK 0x6 188 + /* Device may expose the virtqueue's descriptor area, driver area and 189 + * device area to a different group for ASID binding than where its 190 + * buffers may reside. Requires VHOST_BACKEND_F_IOTLB_ASID. 191 + */ 192 + #define VHOST_BACKEND_F_DESC_ASID 0x7 193 + /* IOTLB don't flush memory mapping across device reset */ 194 + #define VHOST_BACKEND_F_IOTLB_PERSIST 0x8 188 195 189 196 #endif
+5
include/uapi/linux/virtio_config.h
··· 105 105 */ 106 106 #define VIRTIO_F_NOTIFICATION_DATA 38 107 107 108 + /* This feature indicates that the driver uses the data provided by the device 109 + * as a virtqueue identifier in available buffer notifications. 110 + */ 111 + #define VIRTIO_F_NOTIF_CONFIG_DATA 39 112 + 108 113 /* 109 114 * This feature indicates that the driver can reset a queue individually. 110 115 */