Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

Pull virtio updates from Michael Tsirkin:
"A small number of improvements all over the place:

- shutdown has been reworked to reset devices

- virtio fs is now allowed in vduse

- vhost-scsi memory use has been reduced

- cleanups, fixes all over the place

A couple more fixes are being tested and will be merged after rc1"

* tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost:
vhost-scsi: Reduce response iov mem use
vhost-scsi: Allocate iov_iter used for unaligned copies when needed
vhost-scsi: Stop duplicating se_cmd fields
vhost-scsi: Dynamically allocate scatterlists
vhost-scsi: Return queue full for page alloc failures during copy
vhost-scsi: Add better resource allocation failure handling
vhost-scsi: Allocate T10 PI structs only when enabled
vhost-scsi: Reduce mem use by moving upages to per queue
vduse: add virtio_fs to allowed dev id
sound/virtio: Fix cancel_sync warnings on uninitialized work_structs
vdpa/mlx5: Fix oversized null mkey longer than 32bit
vdpa/mlx5: Fix mlx5_vdpa_get_config() endianness on big-endian machines
vhost-scsi: Fix handling of multiple calls to vhost_scsi_set_endpoint
tools: virtio/linux/module.h add MODULE_DESCRIPTION() define.
tools: virtio/linux/compiler.h: Add data_race() define.
tools/virtio: Add DMA_MAPPING_ERROR and sg_dma_len api define for virtio test
virtio: break and reset virtio devices on device_shutdown()

+439 -217
+5 -2
drivers/vdpa/mlx5/core/mr.c
··· 190 190 klm->bcount = cpu_to_be32(klm_bcount(dmr->end - dmr->start)); 191 191 preve = dmr->end; 192 192 } else { 193 + u64 bcount = min_t(u64, dmr->start - preve, MAX_KLM_SIZE); 194 + 193 195 klm->key = cpu_to_be32(mvdev->res.null_mkey); 194 - klm->bcount = cpu_to_be32(klm_bcount(dmr->start - preve)); 195 - preve = dmr->start; 196 + klm->bcount = cpu_to_be32(klm_bcount(bcount)); 197 + preve += bcount; 198 + 196 199 goto again; 197 200 } 198 201 }
+3
drivers/vdpa/mlx5/net/mlx5_vnet.c
··· 3884 3884 ndev->mvdev.max_vqs = max_vqs; 3885 3885 mvdev = &ndev->mvdev; 3886 3886 mvdev->mdev = mdev; 3887 + /* cpu_to_mlx5vdpa16() below depends on this flag */ 3888 + mvdev->actual_features = 3889 + (device_features & BIT_ULL(VIRTIO_F_VERSION_1)); 3887 3890 3888 3891 ndev->vqs = kcalloc(max_vqs, sizeof(*ndev->vqs), GFP_KERNEL); 3889 3892 ndev->event_cbs = kcalloc(max_vqs + 1, sizeof(*ndev->event_cbs), GFP_KERNEL);
+1
drivers/vdpa/vdpa_user/vduse_dev.c
··· 144 144 static u32 allowed_device_id[] = { 145 145 VIRTIO_ID_BLOCK, 146 146 VIRTIO_ID_NET, 147 + VIRTIO_ID_FS, 147 148 }; 148 149 149 150 static inline struct vduse_dev *vdpa_to_vduse(struct vdpa_device *vdpa)
+1
drivers/vhost/Kconfig
··· 47 47 tristate "VHOST_SCSI TCM fabric driver" 48 48 depends on TARGET_CORE && EVENTFD 49 49 select VHOST 50 + select SG_POOL 50 51 default n 51 52 help 52 53 Say M here to enable the vhost_scsi TCM fabric module
+340 -209
drivers/vhost/scsi.c
··· 45 45 #define VHOST_SCSI_PREALLOC_SGLS 2048 46 46 #define VHOST_SCSI_PREALLOC_UPAGES 2048 47 47 #define VHOST_SCSI_PREALLOC_PROT_SGLS 2048 48 + /* 49 + * For the legacy descriptor case we allocate an iov per byte in the 50 + * virtio_scsi_cmd_resp struct. 51 + */ 52 + #define VHOST_SCSI_MAX_RESP_IOVS sizeof(struct virtio_scsi_cmd_resp) 53 + 54 + static unsigned int vhost_scsi_inline_sg_cnt = VHOST_SCSI_PREALLOC_SGLS; 55 + 56 + #ifdef CONFIG_ARCH_NO_SG_CHAIN 57 + static int vhost_scsi_set_inline_sg_cnt(const char *buf, 58 + const struct kernel_param *kp) 59 + { 60 + pr_err("Setting inline_sg_cnt is not supported.\n"); 61 + return -EOPNOTSUPP; 62 + } 63 + #else 64 + static int vhost_scsi_set_inline_sg_cnt(const char *buf, 65 + const struct kernel_param *kp) 66 + { 67 + unsigned int cnt; 68 + int ret; 69 + 70 + ret = kstrtouint(buf, 10, &cnt); 71 + if (ret) 72 + return ret; 73 + 74 + if (ret > VHOST_SCSI_PREALLOC_SGLS) { 75 + pr_err("Max inline_sg_cnt is %u\n", VHOST_SCSI_PREALLOC_SGLS); 76 + return -EINVAL; 77 + } 78 + 79 + vhost_scsi_inline_sg_cnt = cnt; 80 + return 0; 81 + } 82 + #endif 83 + 84 + static int vhost_scsi_get_inline_sg_cnt(char *buf, 85 + const struct kernel_param *kp) 86 + { 87 + return sprintf(buf, "%u\n", vhost_scsi_inline_sg_cnt); 88 + } 89 + 90 + static const struct kernel_param_ops vhost_scsi_inline_sg_cnt_op = { 91 + .get = vhost_scsi_get_inline_sg_cnt, 92 + .set = vhost_scsi_set_inline_sg_cnt, 93 + }; 94 + 95 + module_param_cb(inline_sg_cnt, &vhost_scsi_inline_sg_cnt_op, NULL, 0644); 96 + MODULE_PARM_DESC(inline_sg_cnt, "Set the number of scatterlist entries to pre-allocate. The default is 2048."); 48 97 49 98 /* Max number of requests before requeueing the job. 50 99 * Using this limit prevents one virtqueue from starving others with ··· 111 62 struct vhost_scsi_cmd { 112 63 /* Descriptor from vhost_get_vq_desc() for virt_queue segment */ 113 64 int tvc_vq_desc; 114 - /* virtio-scsi initiator task attribute */ 115 - int tvc_task_attr; 116 - /* virtio-scsi response incoming iovecs */ 117 - int tvc_in_iovs; 118 - /* virtio-scsi initiator data direction */ 119 - enum dma_data_direction tvc_data_direction; 120 - /* Expected data transfer length from virtio-scsi header */ 121 - u32 tvc_exp_data_len; 122 - /* The Tag from include/linux/virtio_scsi.h:struct virtio_scsi_cmd_req */ 123 - u64 tvc_tag; 124 65 /* The number of scatterlists associated with this cmd */ 125 66 u32 tvc_sgl_count; 126 67 u32 tvc_prot_sgl_count; 127 - /* Saved unpacked SCSI LUN for vhost_scsi_target_queue_cmd() */ 128 - u32 tvc_lun; 129 68 u32 copied_iov:1; 130 - const void *saved_iter_addr; 131 - struct iov_iter saved_iter; 132 - /* Pointer to the SGL formatted memory from virtio-scsi */ 133 - struct scatterlist *tvc_sgl; 134 - struct scatterlist *tvc_prot_sgl; 135 - struct page **tvc_upages; 136 - /* Pointer to response header iovec */ 137 - struct iovec *tvc_resp_iov; 138 - /* Pointer to vhost_scsi for our device */ 139 - struct vhost_scsi *tvc_vhost; 69 + const void *read_iov; 70 + struct iov_iter *read_iter; 71 + struct scatterlist *sgl; 72 + struct sg_table table; 73 + struct scatterlist *prot_sgl; 74 + struct sg_table prot_table; 75 + /* Fast path response header iovec used when only one vec is needed */ 76 + struct iovec tvc_resp_iov; 77 + /* Number of iovs for response */ 78 + unsigned int tvc_resp_iovs_cnt; 79 + /* Pointer to response header iovecs if more than one is needed */ 80 + struct iovec *tvc_resp_iovs; 140 81 /* Pointer to vhost_virtqueue for the cmd */ 141 82 struct vhost_virtqueue *tvc_vq; 142 - /* Pointer to vhost nexus memory */ 143 - struct vhost_scsi_nexus *tvc_nexus; 144 83 /* The TCM I/O descriptor that is accessed via container_of() */ 145 84 struct se_cmd tvc_se_cmd; 146 - /* Copy of the incoming SCSI command descriptor block (CDB) */ 147 - unsigned char tvc_cdb[VHOST_SCSI_MAX_CDB_SIZE]; 148 85 /* Sense buffer that will be mapped into outgoing status */ 149 86 unsigned char tvc_sense_buf[TRANSPORT_SENSE_BUFFER]; 150 87 /* Completed commands list, serviced from vhost worker thread */ ··· 222 187 struct vhost_scsi_cmd *scsi_cmds; 223 188 struct sbitmap scsi_tags; 224 189 int max_cmds; 190 + struct page **upages; 225 191 226 192 struct vhost_work completion_work; 227 193 struct llist_head completion_list; ··· 242 206 243 207 bool vs_events_missed; /* any missed events, protected by vq->mutex */ 244 208 int vs_events_nr; /* num of pending events, protected by vq->mutex */ 209 + 210 + unsigned int inline_sg_cnt; 245 211 }; 246 212 247 213 struct vhost_scsi_tmf { ··· 368 330 struct vhost_scsi_cmd, tvc_se_cmd); 369 331 struct vhost_scsi_virtqueue *svq = container_of(tv_cmd->tvc_vq, 370 332 struct vhost_scsi_virtqueue, vq); 333 + struct vhost_scsi *vs = svq->vs; 371 334 struct vhost_scsi_inflight *inflight = tv_cmd->inflight; 335 + struct scatterlist *sg; 336 + struct page *page; 372 337 int i; 373 338 374 339 if (tv_cmd->tvc_sgl_count) { 375 - for (i = 0; i < tv_cmd->tvc_sgl_count; i++) { 340 + for_each_sgtable_sg(&tv_cmd->table, sg, i) { 341 + page = sg_page(sg); 342 + if (!page) 343 + continue; 344 + 376 345 if (tv_cmd->copied_iov) 377 - __free_page(sg_page(&tv_cmd->tvc_sgl[i])); 346 + __free_page(page); 378 347 else 379 - put_page(sg_page(&tv_cmd->tvc_sgl[i])); 348 + put_page(page); 380 349 } 381 - kfree(tv_cmd->saved_iter_addr); 350 + kfree(tv_cmd->read_iter); 351 + kfree(tv_cmd->read_iov); 352 + sg_free_table_chained(&tv_cmd->table, vs->inline_sg_cnt); 382 353 } 383 354 if (tv_cmd->tvc_prot_sgl_count) { 384 - for (i = 0; i < tv_cmd->tvc_prot_sgl_count; i++) 385 - put_page(sg_page(&tv_cmd->tvc_prot_sgl[i])); 355 + for_each_sgtable_sg(&tv_cmd->prot_table, sg, i) { 356 + page = sg_page(sg); 357 + if (page) 358 + put_page(page); 359 + } 360 + sg_free_table_chained(&tv_cmd->prot_table, vs->inline_sg_cnt); 386 361 } 387 362 363 + if (tv_cmd->tvc_resp_iovs != &tv_cmd->tvc_resp_iov) 364 + kfree(tv_cmd->tvc_resp_iovs); 388 365 sbitmap_clear_bit(&svq->scsi_tags, se_cmd->map_tag); 389 366 vhost_scsi_put_inflight(inflight); 390 367 } ··· 586 533 587 534 static int vhost_scsi_copy_sgl_to_iov(struct vhost_scsi_cmd *cmd) 588 535 { 589 - struct iov_iter *iter = &cmd->saved_iter; 590 - struct scatterlist *sg = cmd->tvc_sgl; 536 + struct iov_iter *iter = cmd->read_iter; 537 + struct scatterlist *sg; 591 538 struct page *page; 592 539 size_t len; 593 540 int i; 594 541 595 - for (i = 0; i < cmd->tvc_sgl_count; i++) { 596 - page = sg_page(&sg[i]); 597 - len = sg[i].length; 542 + for_each_sgtable_sg(&cmd->table, sg, i) { 543 + page = sg_page(sg); 544 + if (!page) 545 + continue; 546 + 547 + len = sg->length; 598 548 599 549 if (copy_page_to_iter(page, 0, len, iter) != len) { 600 550 pr_err("Could not copy data while handling misaligned cmd. Error %zu\n", ··· 634 578 cmd, se_cmd->residual_count, se_cmd->scsi_status); 635 579 memset(&v_rsp, 0, sizeof(v_rsp)); 636 580 637 - if (cmd->saved_iter_addr && vhost_scsi_copy_sgl_to_iov(cmd)) { 581 + if (cmd->read_iter && vhost_scsi_copy_sgl_to_iov(cmd)) { 638 582 v_rsp.response = VIRTIO_SCSI_S_BAD_TARGET; 639 583 } else { 640 584 v_rsp.resid = cpu_to_vhost32(cmd->tvc_vq, ··· 647 591 se_cmd->scsi_sense_length); 648 592 } 649 593 650 - iov_iter_init(&iov_iter, ITER_DEST, cmd->tvc_resp_iov, 651 - cmd->tvc_in_iovs, sizeof(v_rsp)); 594 + iov_iter_init(&iov_iter, ITER_DEST, cmd->tvc_resp_iovs, 595 + cmd->tvc_resp_iovs_cnt, sizeof(v_rsp)); 652 596 ret = copy_to_iter(&v_rsp, sizeof(v_rsp), &iov_iter); 653 597 if (likely(ret == sizeof(v_rsp))) { 654 598 signal = true; ··· 665 609 } 666 610 667 611 static struct vhost_scsi_cmd * 668 - vhost_scsi_get_cmd(struct vhost_virtqueue *vq, struct vhost_scsi_tpg *tpg, 669 - unsigned char *cdb, u64 scsi_tag, u16 lun, u8 task_attr, 670 - u32 exp_data_len, int data_direction) 612 + vhost_scsi_get_cmd(struct vhost_virtqueue *vq, u64 scsi_tag) 671 613 { 672 614 struct vhost_scsi_virtqueue *svq = container_of(vq, 673 615 struct vhost_scsi_virtqueue, vq); 674 616 struct vhost_scsi_cmd *cmd; 675 - struct vhost_scsi_nexus *tv_nexus; 676 - struct scatterlist *sg, *prot_sg; 677 - struct iovec *tvc_resp_iov; 678 - struct page **pages; 617 + struct scatterlist *sgl, *prot_sgl; 679 618 int tag; 680 - 681 - tv_nexus = tpg->tpg_nexus; 682 - if (!tv_nexus) { 683 - pr_err("Unable to locate active struct vhost_scsi_nexus\n"); 684 - return ERR_PTR(-EIO); 685 - } 686 619 687 620 tag = sbitmap_get(&svq->scsi_tags); 688 621 if (tag < 0) { 689 - pr_err("Unable to obtain tag for vhost_scsi_cmd\n"); 622 + pr_warn_once("Guest sent too many cmds. Returning TASK_SET_FULL.\n"); 690 623 return ERR_PTR(-ENOMEM); 691 624 } 692 625 693 626 cmd = &svq->scsi_cmds[tag]; 694 - sg = cmd->tvc_sgl; 695 - prot_sg = cmd->tvc_prot_sgl; 696 - pages = cmd->tvc_upages; 697 - tvc_resp_iov = cmd->tvc_resp_iov; 627 + sgl = cmd->sgl; 628 + prot_sgl = cmd->prot_sgl; 698 629 memset(cmd, 0, sizeof(*cmd)); 699 - cmd->tvc_sgl = sg; 700 - cmd->tvc_prot_sgl = prot_sg; 701 - cmd->tvc_upages = pages; 630 + cmd->sgl = sgl; 631 + cmd->prot_sgl = prot_sgl; 702 632 cmd->tvc_se_cmd.map_tag = tag; 703 - cmd->tvc_tag = scsi_tag; 704 - cmd->tvc_lun = lun; 705 - cmd->tvc_task_attr = task_attr; 706 - cmd->tvc_exp_data_len = exp_data_len; 707 - cmd->tvc_data_direction = data_direction; 708 - cmd->tvc_nexus = tv_nexus; 709 633 cmd->inflight = vhost_scsi_get_inflight(vq); 710 - cmd->tvc_resp_iov = tvc_resp_iov; 711 - 712 - memcpy(cmd->tvc_cdb, cdb, VHOST_SCSI_MAX_CDB_SIZE); 713 634 714 635 return cmd; 636 + } 637 + 638 + static void vhost_scsi_revert_map_iov_to_sgl(struct iov_iter *iter, 639 + struct scatterlist *curr, 640 + struct scatterlist *end) 641 + { 642 + size_t revert_bytes = 0; 643 + struct page *page; 644 + 645 + while (curr != end) { 646 + page = sg_page(curr); 647 + 648 + if (page) { 649 + put_page(page); 650 + revert_bytes += curr->length; 651 + } 652 + /* Clear so we can re-use it for the copy path */ 653 + sg_set_page(curr, NULL, 0, 0); 654 + curr = sg_next(curr); 655 + } 656 + iov_iter_revert(iter, revert_bytes); 715 657 } 716 658 717 659 /* ··· 720 666 static int 721 667 vhost_scsi_map_to_sgl(struct vhost_scsi_cmd *cmd, 722 668 struct iov_iter *iter, 723 - struct scatterlist *sgl, 669 + struct sg_table *sg_table, 670 + struct scatterlist **sgl, 724 671 bool is_prot) 725 672 { 726 - struct page **pages = cmd->tvc_upages; 727 - struct scatterlist *sg = sgl; 728 - ssize_t bytes, mapped_bytes; 729 - size_t offset, mapped_offset; 730 - unsigned int npages = 0; 673 + struct vhost_scsi_virtqueue *svq = container_of(cmd->tvc_vq, 674 + struct vhost_scsi_virtqueue, vq); 675 + struct page **pages = svq->upages; 676 + struct scatterlist *sg = *sgl; 677 + ssize_t bytes; 678 + size_t offset; 679 + unsigned int n, npages = 0; 731 680 732 681 bytes = iov_iter_get_pages2(iter, pages, LONG_MAX, 733 682 VHOST_SCSI_PREALLOC_UPAGES, &offset); ··· 738 681 if (bytes <= 0) 739 682 return bytes < 0 ? bytes : -EFAULT; 740 683 741 - mapped_bytes = bytes; 742 - mapped_offset = offset; 743 - 744 684 while (bytes) { 745 - unsigned n = min_t(unsigned, PAGE_SIZE - offset, bytes); 685 + n = min_t(unsigned int, PAGE_SIZE - offset, bytes); 746 686 /* 747 687 * The block layer requires bios/requests to be a multiple of 748 688 * 512 bytes, but Windows can send us vecs that are misaligned. ··· 760 706 goto revert_iter_get_pages; 761 707 } 762 708 763 - sg_set_page(sg++, pages[npages++], n, offset); 709 + sg_set_page(sg, pages[npages++], n, offset); 710 + sg = sg_next(sg); 764 711 bytes -= n; 765 712 offset = 0; 766 713 } 767 714 715 + *sgl = sg; 768 716 return npages; 769 717 770 718 revert_iter_get_pages: 771 - iov_iter_revert(iter, mapped_bytes); 719 + vhost_scsi_revert_map_iov_to_sgl(iter, *sgl, sg); 772 720 773 - npages = 0; 774 - while (mapped_bytes) { 775 - unsigned int n = min_t(unsigned int, PAGE_SIZE - mapped_offset, 776 - mapped_bytes); 721 + iov_iter_revert(iter, bytes); 722 + while (bytes) { 723 + n = min_t(unsigned int, PAGE_SIZE, bytes); 777 724 778 725 put_page(pages[npages++]); 779 - 780 - mapped_bytes -= n; 781 - mapped_offset = 0; 726 + bytes -= n; 782 727 } 783 728 784 729 return -EINVAL; ··· 805 752 806 753 static int 807 754 vhost_scsi_copy_iov_to_sgl(struct vhost_scsi_cmd *cmd, struct iov_iter *iter, 808 - struct scatterlist *sg, int sg_count) 755 + struct sg_table *sg_table, int sg_count, 756 + int data_dir) 809 757 { 810 758 size_t len = iov_iter_count(iter); 811 759 unsigned int nbytes = 0; 760 + struct scatterlist *sg; 812 761 struct page *page; 813 - int i; 762 + int i, ret; 814 763 815 - if (cmd->tvc_data_direction == DMA_FROM_DEVICE) { 816 - cmd->saved_iter_addr = dup_iter(&cmd->saved_iter, iter, 817 - GFP_KERNEL); 818 - if (!cmd->saved_iter_addr) 764 + if (data_dir == DMA_FROM_DEVICE) { 765 + cmd->read_iter = kzalloc(sizeof(*cmd->read_iter), GFP_KERNEL); 766 + if (!cmd->read_iter) 819 767 return -ENOMEM; 768 + 769 + cmd->read_iov = dup_iter(cmd->read_iter, iter, GFP_KERNEL); 770 + if (!cmd->read_iov) { 771 + ret = -ENOMEM; 772 + goto free_iter; 773 + } 820 774 } 821 775 822 - for (i = 0; i < sg_count; i++) { 776 + for_each_sgtable_sg(sg_table, sg, i) { 823 777 page = alloc_page(GFP_KERNEL); 824 778 if (!page) { 825 - i--; 779 + ret = -ENOMEM; 826 780 goto err; 827 781 } 828 782 829 783 nbytes = min_t(unsigned int, PAGE_SIZE, len); 830 - sg_set_page(&sg[i], page, nbytes, 0); 784 + sg_set_page(sg, page, nbytes, 0); 831 785 832 - if (cmd->tvc_data_direction == DMA_TO_DEVICE && 833 - copy_page_from_iter(page, 0, nbytes, iter) != nbytes) 786 + if (data_dir == DMA_TO_DEVICE && 787 + copy_page_from_iter(page, 0, nbytes, iter) != nbytes) { 788 + ret = -EFAULT; 834 789 goto err; 790 + } 835 791 836 792 len -= nbytes; 837 793 } ··· 852 790 pr_err("Could not read %u bytes while handling misaligned cmd\n", 853 791 nbytes); 854 792 855 - for (; i >= 0; i--) 856 - __free_page(sg_page(&sg[i])); 857 - kfree(cmd->saved_iter_addr); 858 - return -ENOMEM; 793 + for_each_sgtable_sg(sg_table, sg, i) { 794 + page = sg_page(sg); 795 + if (page) 796 + __free_page(page); 797 + } 798 + kfree(cmd->read_iov); 799 + free_iter: 800 + kfree(cmd->read_iter); 801 + return ret; 859 802 } 860 803 861 804 static int 862 805 vhost_scsi_map_iov_to_sgl(struct vhost_scsi_cmd *cmd, struct iov_iter *iter, 863 - struct scatterlist *sg, int sg_count, bool is_prot) 806 + struct sg_table *sg_table, int sg_count, bool is_prot) 864 807 { 865 - struct scatterlist *p = sg; 866 - size_t revert_bytes; 808 + struct scatterlist *sg = sg_table->sgl; 867 809 int ret; 868 810 869 811 while (iov_iter_count(iter)) { 870 - ret = vhost_scsi_map_to_sgl(cmd, iter, sg, is_prot); 812 + ret = vhost_scsi_map_to_sgl(cmd, iter, sg_table, &sg, is_prot); 871 813 if (ret < 0) { 872 - revert_bytes = 0; 873 - 874 - while (p < sg) { 875 - struct page *page = sg_page(p); 876 - 877 - if (page) { 878 - put_page(page); 879 - revert_bytes += p->length; 880 - } 881 - p++; 882 - } 883 - 884 - iov_iter_revert(iter, revert_bytes); 814 + vhost_scsi_revert_map_iov_to_sgl(iter, sg_table->sgl, 815 + sg); 885 816 return ret; 886 817 } 887 - sg += ret; 888 818 } 889 819 890 820 return 0; 891 821 } 892 822 893 823 static int 894 - vhost_scsi_mapal(struct vhost_scsi_cmd *cmd, 824 + vhost_scsi_mapal(struct vhost_scsi *vs, struct vhost_scsi_cmd *cmd, 895 825 size_t prot_bytes, struct iov_iter *prot_iter, 896 - size_t data_bytes, struct iov_iter *data_iter) 826 + size_t data_bytes, struct iov_iter *data_iter, int data_dir) 897 827 { 898 828 int sgl_count, ret; 899 829 900 830 if (prot_bytes) { 901 831 sgl_count = vhost_scsi_calc_sgls(prot_iter, prot_bytes, 902 832 VHOST_SCSI_PREALLOC_PROT_SGLS); 903 - if (sgl_count < 0) 904 - return sgl_count; 833 + cmd->prot_table.sgl = cmd->prot_sgl; 834 + ret = sg_alloc_table_chained(&cmd->prot_table, sgl_count, 835 + cmd->prot_table.sgl, 836 + vs->inline_sg_cnt); 837 + if (ret) 838 + return ret; 905 839 906 - sg_init_table(cmd->tvc_prot_sgl, sgl_count); 907 840 cmd->tvc_prot_sgl_count = sgl_count; 908 841 pr_debug("%s prot_sg %p prot_sgl_count %u\n", __func__, 909 - cmd->tvc_prot_sgl, cmd->tvc_prot_sgl_count); 842 + cmd->prot_table.sgl, cmd->tvc_prot_sgl_count); 910 843 911 844 ret = vhost_scsi_map_iov_to_sgl(cmd, prot_iter, 912 - cmd->tvc_prot_sgl, 845 + &cmd->prot_table, 913 846 cmd->tvc_prot_sgl_count, true); 914 847 if (ret < 0) { 848 + sg_free_table_chained(&cmd->prot_table, 849 + vs->inline_sg_cnt); 915 850 cmd->tvc_prot_sgl_count = 0; 916 851 return ret; 917 852 } ··· 918 859 if (sgl_count < 0) 919 860 return sgl_count; 920 861 921 - sg_init_table(cmd->tvc_sgl, sgl_count); 862 + cmd->table.sgl = cmd->sgl; 863 + ret = sg_alloc_table_chained(&cmd->table, sgl_count, cmd->table.sgl, 864 + vs->inline_sg_cnt); 865 + if (ret) 866 + return ret; 867 + 922 868 cmd->tvc_sgl_count = sgl_count; 923 869 pr_debug("%s data_sg %p data_sgl_count %u\n", __func__, 924 - cmd->tvc_sgl, cmd->tvc_sgl_count); 870 + cmd->table.sgl, cmd->tvc_sgl_count); 925 871 926 - ret = vhost_scsi_map_iov_to_sgl(cmd, data_iter, cmd->tvc_sgl, 872 + ret = vhost_scsi_map_iov_to_sgl(cmd, data_iter, &cmd->table, 927 873 cmd->tvc_sgl_count, false); 928 - if (ret == -EINVAL) { 929 - sg_init_table(cmd->tvc_sgl, cmd->tvc_sgl_count); 930 - ret = vhost_scsi_copy_iov_to_sgl(cmd, data_iter, cmd->tvc_sgl, 931 - cmd->tvc_sgl_count); 932 - } 933 - 874 + if (ret == -EINVAL) 875 + ret = vhost_scsi_copy_iov_to_sgl(cmd, data_iter, &cmd->table, 876 + cmd->tvc_sgl_count, data_dir); 934 877 if (ret < 0) { 878 + sg_free_table_chained(&cmd->table, vs->inline_sg_cnt); 935 879 cmd->tvc_sgl_count = 0; 936 880 return ret; 937 881 } ··· 958 896 return TCM_SIMPLE_TAG; 959 897 } 960 898 961 - static void vhost_scsi_target_queue_cmd(struct vhost_scsi_cmd *cmd) 899 + static void vhost_scsi_target_queue_cmd(struct vhost_scsi_nexus *nexus, 900 + struct vhost_scsi_cmd *cmd, 901 + unsigned char *cdb, u16 lun, 902 + int task_attr, int data_dir, 903 + u32 exp_data_len) 962 904 { 963 905 struct se_cmd *se_cmd = &cmd->tvc_se_cmd; 964 - struct vhost_scsi_nexus *tv_nexus; 965 906 struct scatterlist *sg_ptr, *sg_prot_ptr = NULL; 966 907 967 908 /* FIXME: BIDI operation */ 968 909 if (cmd->tvc_sgl_count) { 969 - sg_ptr = cmd->tvc_sgl; 910 + sg_ptr = cmd->table.sgl; 970 911 971 912 if (cmd->tvc_prot_sgl_count) 972 - sg_prot_ptr = cmd->tvc_prot_sgl; 913 + sg_prot_ptr = cmd->prot_table.sgl; 973 914 else 974 915 se_cmd->prot_pto = true; 975 916 } else { 976 917 sg_ptr = NULL; 977 918 } 978 - tv_nexus = cmd->tvc_nexus; 979 919 980 920 se_cmd->tag = 0; 981 - target_init_cmd(se_cmd, tv_nexus->tvn_se_sess, &cmd->tvc_sense_buf[0], 982 - cmd->tvc_lun, cmd->tvc_exp_data_len, 983 - vhost_scsi_to_tcm_attr(cmd->tvc_task_attr), 984 - cmd->tvc_data_direction, TARGET_SCF_ACK_KREF); 921 + target_init_cmd(se_cmd, nexus->tvn_se_sess, &cmd->tvc_sense_buf[0], 922 + lun, exp_data_len, vhost_scsi_to_tcm_attr(task_attr), 923 + data_dir, TARGET_SCF_ACK_KREF); 985 924 986 - if (target_submit_prep(se_cmd, cmd->tvc_cdb, sg_ptr, 925 + if (target_submit_prep(se_cmd, cdb, sg_ptr, 987 926 cmd->tvc_sgl_count, NULL, 0, sg_prot_ptr, 988 927 cmd->tvc_prot_sgl_count, GFP_KERNEL)) 989 928 return; 990 929 991 930 target_submit(se_cmd); 931 + } 932 + 933 + static void 934 + vhost_scsi_send_status(struct vhost_scsi *vs, struct vhost_virtqueue *vq, 935 + int head, unsigned int out, u8 status) 936 + { 937 + struct virtio_scsi_cmd_resp __user *resp; 938 + struct virtio_scsi_cmd_resp rsp; 939 + int ret; 940 + 941 + memset(&rsp, 0, sizeof(rsp)); 942 + rsp.status = status; 943 + resp = vq->iov[out].iov_base; 944 + ret = __copy_to_user(resp, &rsp, sizeof(rsp)); 945 + if (!ret) 946 + vhost_add_used_and_signal(&vs->dev, vq, head, 0); 947 + else 948 + pr_err("Faulted on virtio_scsi_cmd_resp\n"); 992 949 } 993 950 994 951 static void ··· 1130 1049 return ret; 1131 1050 } 1132 1051 1052 + static int 1053 + vhost_scsi_setup_resp_iovs(struct vhost_scsi_cmd *cmd, struct iovec *in_iovs, 1054 + unsigned int in_iovs_cnt) 1055 + { 1056 + int i, cnt; 1057 + 1058 + if (!in_iovs_cnt) 1059 + return 0; 1060 + /* 1061 + * Initiator's normally just put the virtio_scsi_cmd_resp in the first 1062 + * iov, but just in case they wedged in some data with it we check for 1063 + * greater than or equal to the response struct. 1064 + */ 1065 + if (in_iovs[0].iov_len >= sizeof(struct virtio_scsi_cmd_resp)) { 1066 + cmd->tvc_resp_iovs = &cmd->tvc_resp_iov; 1067 + cmd->tvc_resp_iovs_cnt = 1; 1068 + } else { 1069 + /* 1070 + * Legacy descriptor layouts didn't specify that we must put 1071 + * the entire response in one iov. Worst case we have a 1072 + * iov per byte. 1073 + */ 1074 + cnt = min(VHOST_SCSI_MAX_RESP_IOVS, in_iovs_cnt); 1075 + cmd->tvc_resp_iovs = kcalloc(cnt, sizeof(struct iovec), 1076 + GFP_KERNEL); 1077 + if (!cmd->tvc_resp_iovs) 1078 + return -ENOMEM; 1079 + 1080 + cmd->tvc_resp_iovs_cnt = cnt; 1081 + } 1082 + 1083 + for (i = 0; i < cmd->tvc_resp_iovs_cnt; i++) 1084 + cmd->tvc_resp_iovs[i] = in_iovs[i]; 1085 + 1086 + return 0; 1087 + } 1088 + 1133 1089 static u16 vhost_buf_to_lun(u8 *lun_buf) 1134 1090 { 1135 1091 return ((lun_buf[2] << 8) | lun_buf[3]) & 0x3FFF; ··· 1178 1060 struct vhost_scsi_tpg **vs_tpg, *tpg; 1179 1061 struct virtio_scsi_cmd_req v_req; 1180 1062 struct virtio_scsi_cmd_req_pi v_req_pi; 1063 + struct vhost_scsi_nexus *nexus; 1181 1064 struct vhost_scsi_ctx vc; 1182 1065 struct vhost_scsi_cmd *cmd; 1183 1066 struct iov_iter in_iter, prot_iter, data_iter; 1184 1067 u64 tag; 1185 1068 u32 exp_data_len, data_direction; 1186 - int ret, prot_bytes, i, c = 0; 1069 + int ret, prot_bytes, c = 0; 1187 1070 u16 lun; 1188 1071 u8 task_attr; 1189 1072 bool t10_pi = vhost_has_feature(vq, VIRTIO_SCSI_F_T10_PI); 1190 - void *cdb; 1073 + u8 *cdb; 1191 1074 1192 1075 mutex_lock(&vq->mutex); 1193 1076 /* ··· 1331 1212 scsi_command_size(cdb), VHOST_SCSI_MAX_CDB_SIZE); 1332 1213 goto err; 1333 1214 } 1334 - cmd = vhost_scsi_get_cmd(vq, tpg, cdb, tag, lun, task_attr, 1335 - exp_data_len + prot_bytes, 1336 - data_direction); 1337 - if (IS_ERR(cmd)) { 1338 - vq_err(vq, "vhost_scsi_get_cmd failed %ld\n", 1339 - PTR_ERR(cmd)); 1215 + 1216 + nexus = tpg->tpg_nexus; 1217 + if (!nexus) { 1218 + vq_err(vq, "Unable to locate active struct vhost_scsi_nexus\n"); 1219 + ret = -EIO; 1340 1220 goto err; 1341 1221 } 1342 - cmd->tvc_vhost = vs; 1222 + 1223 + cmd = vhost_scsi_get_cmd(vq, tag); 1224 + if (IS_ERR(cmd)) { 1225 + ret = PTR_ERR(cmd); 1226 + vq_err(vq, "vhost_scsi_get_tag failed %dd\n", ret); 1227 + goto err; 1228 + } 1343 1229 cmd->tvc_vq = vq; 1344 - for (i = 0; i < vc.in ; i++) 1345 - cmd->tvc_resp_iov[i] = vq->iov[vc.out + i]; 1346 - cmd->tvc_in_iovs = vc.in; 1230 + 1231 + ret = vhost_scsi_setup_resp_iovs(cmd, &vq->iov[vc.out], vc.in); 1232 + if (ret) { 1233 + vq_err(vq, "Failed to alloc recv iovs\n"); 1234 + vhost_scsi_release_cmd_res(&cmd->tvc_se_cmd); 1235 + goto err; 1236 + } 1347 1237 1348 1238 pr_debug("vhost_scsi got command opcode: %#02x, lun: %d\n", 1349 - cmd->tvc_cdb[0], cmd->tvc_lun); 1239 + cdb[0], lun); 1350 1240 pr_debug("cmd: %p exp_data_len: %d, prot_bytes: %d data_direction:" 1351 1241 " %d\n", cmd, exp_data_len, prot_bytes, data_direction); 1352 1242 1353 1243 if (data_direction != DMA_NONE) { 1354 - if (unlikely(vhost_scsi_mapal(cmd, prot_bytes, 1355 - &prot_iter, exp_data_len, 1356 - &data_iter))) { 1244 + ret = vhost_scsi_mapal(vs, cmd, prot_bytes, &prot_iter, 1245 + exp_data_len, &data_iter, 1246 + data_direction); 1247 + if (unlikely(ret)) { 1357 1248 vq_err(vq, "Failed to map iov to sgl\n"); 1358 1249 vhost_scsi_release_cmd_res(&cmd->tvc_se_cmd); 1359 1250 goto err; ··· 1375 1246 * vhost_scsi_queue_data_in() and vhost_scsi_queue_status() 1376 1247 */ 1377 1248 cmd->tvc_vq_desc = vc.head; 1378 - vhost_scsi_target_queue_cmd(cmd); 1249 + vhost_scsi_target_queue_cmd(nexus, cmd, cdb, lun, task_attr, 1250 + data_direction, 1251 + exp_data_len + prot_bytes); 1379 1252 ret = 0; 1380 1253 err: 1381 1254 /* ··· 1385 1254 * EINVAL: Invalid response buffer, drop the request 1386 1255 * EIO: Respond with bad target 1387 1256 * EAGAIN: Pending request 1257 + * ENOMEM: Could not allocate resources for request 1388 1258 */ 1389 1259 if (ret == -ENXIO) 1390 1260 break; 1391 1261 else if (ret == -EIO) 1392 1262 vhost_scsi_send_bad_target(vs, vq, vc.head, vc.out); 1263 + else if (ret == -ENOMEM) 1264 + vhost_scsi_send_status(vs, vq, vc.head, vc.out, 1265 + SAM_STAT_TASK_SET_FULL); 1393 1266 } while (likely(!vhost_exceeds_weight(vq, ++c, 0))); 1394 1267 out: 1395 1268 mutex_unlock(&vq->mutex); ··· 1731 1596 for (i = 0; i < svq->max_cmds; i++) { 1732 1597 tv_cmd = &svq->scsi_cmds[i]; 1733 1598 1734 - kfree(tv_cmd->tvc_sgl); 1735 - kfree(tv_cmd->tvc_prot_sgl); 1736 - kfree(tv_cmd->tvc_upages); 1737 - kfree(tv_cmd->tvc_resp_iov); 1599 + kfree(tv_cmd->sgl); 1600 + kfree(tv_cmd->prot_sgl); 1738 1601 } 1739 1602 1740 1603 sbitmap_free(&svq->scsi_tags); 1604 + kfree(svq->upages); 1741 1605 kfree(svq->scsi_cmds); 1742 1606 svq->scsi_cmds = NULL; 1743 1607 } ··· 1745 1611 { 1746 1612 struct vhost_scsi_virtqueue *svq = container_of(vq, 1747 1613 struct vhost_scsi_virtqueue, vq); 1614 + struct vhost_scsi *vs = svq->vs; 1748 1615 struct vhost_scsi_cmd *tv_cmd; 1749 1616 unsigned int i; 1750 1617 ··· 1763 1628 return -ENOMEM; 1764 1629 } 1765 1630 1631 + svq->upages = kcalloc(VHOST_SCSI_PREALLOC_UPAGES, sizeof(struct page *), 1632 + GFP_KERNEL); 1633 + if (!svq->upages) 1634 + goto out; 1635 + 1766 1636 for (i = 0; i < max_cmds; i++) { 1767 1637 tv_cmd = &svq->scsi_cmds[i]; 1768 1638 1769 - tv_cmd->tvc_sgl = kcalloc(VHOST_SCSI_PREALLOC_SGLS, 1770 - sizeof(struct scatterlist), 1771 - GFP_KERNEL); 1772 - if (!tv_cmd->tvc_sgl) { 1773 - pr_err("Unable to allocate tv_cmd->tvc_sgl\n"); 1774 - goto out; 1639 + if (vs->inline_sg_cnt) { 1640 + tv_cmd->sgl = kcalloc(vs->inline_sg_cnt, 1641 + sizeof(struct scatterlist), 1642 + GFP_KERNEL); 1643 + if (!tv_cmd->sgl) { 1644 + pr_err("Unable to allocate tv_cmd->sgl\n"); 1645 + goto out; 1646 + } 1775 1647 } 1776 1648 1777 - tv_cmd->tvc_upages = kcalloc(VHOST_SCSI_PREALLOC_UPAGES, 1778 - sizeof(struct page *), 1779 - GFP_KERNEL); 1780 - if (!tv_cmd->tvc_upages) { 1781 - pr_err("Unable to allocate tv_cmd->tvc_upages\n"); 1782 - goto out; 1783 - } 1784 - 1785 - tv_cmd->tvc_resp_iov = kcalloc(UIO_MAXIOV, 1786 - sizeof(struct iovec), 1787 - GFP_KERNEL); 1788 - if (!tv_cmd->tvc_resp_iov) { 1789 - pr_err("Unable to allocate tv_cmd->tvc_resp_iov\n"); 1790 - goto out; 1791 - } 1792 - 1793 - tv_cmd->tvc_prot_sgl = kcalloc(VHOST_SCSI_PREALLOC_PROT_SGLS, 1794 - sizeof(struct scatterlist), 1795 - GFP_KERNEL); 1796 - if (!tv_cmd->tvc_prot_sgl) { 1797 - pr_err("Unable to allocate tv_cmd->tvc_prot_sgl\n"); 1798 - goto out; 1649 + if (vhost_has_feature(vq, VIRTIO_SCSI_F_T10_PI) && 1650 + vs->inline_sg_cnt) { 1651 + tv_cmd->prot_sgl = kcalloc(vs->inline_sg_cnt, 1652 + sizeof(struct scatterlist), 1653 + GFP_KERNEL); 1654 + if (!tv_cmd->prot_sgl) { 1655 + pr_err("Unable to allocate tv_cmd->prot_sgl\n"); 1656 + goto out; 1657 + } 1799 1658 } 1800 1659 } 1801 1660 return 0; ··· 1828 1699 } 1829 1700 } 1830 1701 1702 + if (vs->vs_tpg) { 1703 + pr_err("vhost-scsi endpoint already set for %s.\n", 1704 + vs->vs_vhost_wwpn); 1705 + ret = -EEXIST; 1706 + goto out; 1707 + } 1708 + 1831 1709 len = sizeof(vs_tpg[0]) * VHOST_SCSI_MAX_TARGET; 1832 1710 vs_tpg = kzalloc(len, GFP_KERNEL); 1833 1711 if (!vs_tpg) { 1834 1712 ret = -ENOMEM; 1835 1713 goto out; 1836 1714 } 1837 - if (vs->vs_tpg) 1838 - memcpy(vs_tpg, vs->vs_tpg, len); 1839 1715 1840 1716 mutex_lock(&vhost_scsi_mutex); 1841 1717 list_for_each_entry(tpg, &vhost_scsi_list, tv_tpg_list) { ··· 1856 1722 tv_tport = tpg->tport; 1857 1723 1858 1724 if (!strcmp(tv_tport->tport_name, t->vhost_wwpn)) { 1859 - if (vs->vs_tpg && vs->vs_tpg[tpg->tport_tpgt]) { 1860 - mutex_unlock(&tpg->tv_tpg_mutex); 1861 - mutex_unlock(&vhost_scsi_mutex); 1862 - ret = -EEXIST; 1863 - goto undepend; 1864 - } 1865 1725 /* 1866 1726 * In order to ensure individual vhost-scsi configfs 1867 1727 * groups cannot be removed while in use by vhost ioctl, ··· 1902 1774 } 1903 1775 ret = 0; 1904 1776 } else { 1905 - ret = -EEXIST; 1777 + ret = -ENODEV; 1778 + goto free_tpg; 1906 1779 } 1907 1780 1908 1781 /* 1909 - * Act as synchronize_rcu to make sure access to 1910 - * old vs->vs_tpg is finished. 1782 + * Act as synchronize_rcu to make sure requests after this point 1783 + * see a fully setup device. 1911 1784 */ 1912 1785 vhost_scsi_flush(vs); 1913 - kfree(vs->vs_tpg); 1914 1786 vs->vs_tpg = vs_tpg; 1915 1787 goto out; 1916 1788 ··· 1930 1802 target_undepend_item(&tpg->se_tpg.tpg_group.cg_item); 1931 1803 } 1932 1804 } 1805 + free_tpg: 1933 1806 kfree(vs_tpg); 1934 1807 out: 1935 1808 mutex_unlock(&vs->dev.mutex); ··· 2033 1904 vhost_scsi_flush(vs); 2034 1905 kfree(vs->vs_tpg); 2035 1906 vs->vs_tpg = NULL; 1907 + memset(vs->vs_vhost_wwpn, 0, sizeof(vs->vs_vhost_wwpn)); 2036 1908 WARN_ON(vs->vs_events_nr); 2037 1909 mutex_unlock(&vs->dev.mutex); 2038 1910 return 0; ··· 2078 1948 vs = kvzalloc(sizeof(*vs), GFP_KERNEL); 2079 1949 if (!vs) 2080 1950 goto err_vs; 1951 + vs->inline_sg_cnt = vhost_scsi_inline_sg_cnt; 2081 1952 2082 1953 if (nvqs > VHOST_SCSI_MAX_IO_VQ) { 2083 1954 pr_err("Invalid max_io_vqs of %d. Using %d.\n", nvqs,
+29
drivers/virtio/virtio.c
··· 395 395 return dev->config->get_vq_affinity(dev, irq_vec); 396 396 } 397 397 398 + static void virtio_dev_shutdown(struct device *_d) 399 + { 400 + struct virtio_device *dev = dev_to_virtio(_d); 401 + struct virtio_driver *drv = drv_to_virtio(dev->dev.driver); 402 + 403 + /* 404 + * Stop accesses to or from the device. 405 + * We only need to do it if there's a driver - no accesses otherwise. 406 + */ 407 + if (!drv) 408 + return; 409 + 410 + /* 411 + * Some devices get wedged if you kick them after they are 412 + * reset. Mark all vqs as broken to make sure we don't. 413 + */ 414 + virtio_break_device(dev); 415 + /* 416 + * Guarantee that any callback will see vq->broken as true. 417 + */ 418 + virtio_synchronize_cbs(dev); 419 + /* 420 + * As IOMMUs are reset on shutdown, this will block device access to memory. 421 + * Some devices get wedged if this happens, so reset to make sure it does not. 422 + */ 423 + dev->config->reset(dev); 424 + } 425 + 398 426 static const struct bus_type virtio_bus = { 399 427 .name = "virtio", 400 428 .match = virtio_dev_match, ··· 431 403 .probe = virtio_dev_probe, 432 404 .remove = virtio_dev_remove, 433 405 .irq_get_affinity = virtio_irq_get_affinity, 406 + .shutdown = virtio_dev_shutdown, 434 407 }; 435 408 436 409 int __register_virtio_driver(struct virtio_driver *driver, struct module *owner)
+15 -6
sound/virtio/virtio_pcm.c
··· 339 339 if (!snd->substreams) 340 340 return -ENOMEM; 341 341 342 + /* 343 + * Initialize critical substream fields early in case we hit an 344 + * error path and end up trying to clean up uninitialized structures 345 + * elsewhere. 346 + */ 347 + for (i = 0; i < snd->nsubstreams; ++i) { 348 + struct virtio_pcm_substream *vss = &snd->substreams[i]; 349 + 350 + vss->snd = snd; 351 + vss->sid = i; 352 + INIT_WORK(&vss->elapsed_period, virtsnd_pcm_period_elapsed); 353 + init_waitqueue_head(&vss->msg_empty); 354 + spin_lock_init(&vss->lock); 355 + } 356 + 342 357 info = kcalloc(snd->nsubstreams, sizeof(*info), GFP_KERNEL); 343 358 if (!info) 344 359 return -ENOMEM; ··· 366 351 for (i = 0; i < snd->nsubstreams; ++i) { 367 352 struct virtio_pcm_substream *vss = &snd->substreams[i]; 368 353 struct virtio_pcm *vpcm; 369 - 370 - vss->snd = snd; 371 - vss->sid = i; 372 - INIT_WORK(&vss->elapsed_period, virtsnd_pcm_period_elapsed); 373 - init_waitqueue_head(&vss->msg_empty); 374 - spin_lock_init(&vss->lock); 375 354 376 355 rc = virtsnd_pcm_build_hw(vss, &info[i]); 377 356 if (rc)
+25
tools/virtio/linux/compiler.h
··· 10 10 #define READ_ONCE(var) (*((volatile typeof(var) *)(&(var)))) 11 11 12 12 #define __aligned(x) __attribute((__aligned__(x))) 13 + 14 + /** 15 + * data_race - mark an expression as containing intentional data races 16 + * 17 + * This data_race() macro is useful for situations in which data races 18 + * should be forgiven. One example is diagnostic code that accesses 19 + * shared variables but is not a part of the core synchronization design. 20 + * For example, if accesses to a given variable are protected by a lock, 21 + * except for diagnostic code, then the accesses under the lock should 22 + * be plain C-language accesses and those in the diagnostic code should 23 + * use data_race(). This way, KCSAN will complain if buggy lockless 24 + * accesses to that variable are introduced, even if the buggy accesses 25 + * are protected by READ_ONCE() or WRITE_ONCE(). 26 + * 27 + * This macro *does not* affect normal code generation, but is a hint 28 + * to tooling that data races here are to be ignored. If the access must 29 + * be atomic *and* KCSAN should ignore the access, use both data_race() 30 + * and READ_ONCE(), for example, data_race(READ_ONCE(x)). 31 + */ 32 + #define data_race(expr) \ 33 + ({ \ 34 + __auto_type __v = (expr); \ 35 + __v; \ 36 + }) 37 + 13 38 #endif
+13
tools/virtio/linux/dma-mapping.h
··· 31 31 #define dma_unmap_page(d, a, s, r) do { (void)(d); (void)(a); (void)(s); (void)(r); } while (0) 32 32 33 33 #define sg_dma_address(sg) (0) 34 + #define sg_dma_len(sg) (0) 34 35 #define dma_need_sync(v, a) (0) 35 36 #define dma_unmap_single_attrs(d, a, s, r, t) do { \ 36 37 (void)(d); (void)(a); (void)(s); (void)(r); (void)(t); \ ··· 43 42 (void)(d); (void)(a); (void)(o); (void)(s); (void)(r); \ 44 43 } while (0) 45 44 #define dma_max_mapping_size(...) SIZE_MAX 45 + 46 + /* 47 + * A dma_addr_t can hold any valid DMA or bus address for the platform. It can 48 + * be given to a device to use as a DMA source or target. It is specific to a 49 + * given device and there may be a translation between the CPU physical address 50 + * space and the bus address space. 51 + * 52 + * DMA_MAPPING_ERROR is the magic error code if a mapping failed. It should not 53 + * be used directly in drivers, but checked for using dma_mapping_error() 54 + * instead. 55 + */ 56 + #define DMA_MAPPING_ERROR (~(dma_addr_t)0) 46 57 47 58 #endif
+7
tools/virtio/linux/module.h
··· 5 5 static __attribute__((unused)) const char *__MODULE_LICENSE_name = \ 6 6 __MODULE_LICENSE_value 7 7 8 + #ifndef MODULE_AUTHOR 9 + #define MODULE_AUTHOR(x) 10 + #endif 11 + 12 + #ifndef MODULE_DESCRIPTION 13 + #define MODULE_DESCRIPTION(x) 14 + #endif