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

Configure Feed

Select the types of activity you want to include in your feed.

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

Pull virtio updates from Michael Tsirkin:
"A small pull request this time around, mostly because the vduse
network got postponed to next relase so we can be sure we got the
security store right"

* tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost:
virtio_ring: fix avail_wrap_counter in virtqueue_add_packed
virtio_vdpa: build affinity masks conditionally
virtio_net: merge dma operations when filling mergeable buffers
virtio_ring: introduce dma sync api for virtqueue
virtio_ring: introduce dma map api for virtqueue
virtio_ring: introduce virtqueue_reset()
virtio_ring: separate the logic of reset/enable from virtqueue_resize
virtio_ring: correct the expression of the description of virtqueue_resize()
virtio_ring: skip unmap for premapped
virtio_ring: introduce virtqueue_dma_dev()
virtio_ring: support add premapped buf
virtio_ring: introduce virtqueue_set_dma_premapped()
virtio_ring: put mapping error check in vring_map_one_sg
virtio_ring: check use_dma_api before unmap desc for indirect
vdpa_sim: offer VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK
vdpa: add get_backend_features vdpa operation
vdpa: accept VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK backend feature
vdpa: add VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK flag
vdpa/mlx5: Remove unused function declarations

+625 -90
+203 -27
drivers/net/virtio_net.c
··· 132 132 u32 max_usecs; 133 133 }; 134 134 135 + /* The dma information of pages allocated at a time. */ 136 + struct virtnet_rq_dma { 137 + dma_addr_t addr; 138 + u32 ref; 139 + u16 len; 140 + u16 need_sync; 141 + }; 142 + 135 143 /* Internal representation of a send virtqueue */ 136 144 struct send_queue { 137 145 /* Virtqueue associated with this send _queue */ ··· 193 185 char name[16]; 194 186 195 187 struct xdp_rxq_info xdp_rxq; 188 + 189 + /* Record the last dma info to free after new pages is allocated. */ 190 + struct virtnet_rq_dma *last_dma; 191 + 192 + /* Do dma by self */ 193 + bool do_dma; 196 194 }; 197 195 198 196 /* This structure can contain rss message with maximum settings for indirection table and keysize ··· 594 580 return skb; 595 581 } 596 582 583 + static void virtnet_rq_unmap(struct receive_queue *rq, void *buf, u32 len) 584 + { 585 + struct page *page = virt_to_head_page(buf); 586 + struct virtnet_rq_dma *dma; 587 + void *head; 588 + int offset; 589 + 590 + head = page_address(page); 591 + 592 + dma = head; 593 + 594 + --dma->ref; 595 + 596 + if (dma->ref) { 597 + if (dma->need_sync && len) { 598 + offset = buf - (head + sizeof(*dma)); 599 + 600 + virtqueue_dma_sync_single_range_for_cpu(rq->vq, dma->addr, offset, 601 + len, DMA_FROM_DEVICE); 602 + } 603 + 604 + return; 605 + } 606 + 607 + virtqueue_dma_unmap_single_attrs(rq->vq, dma->addr, dma->len, 608 + DMA_FROM_DEVICE, DMA_ATTR_SKIP_CPU_SYNC); 609 + put_page(page); 610 + } 611 + 612 + static void *virtnet_rq_get_buf(struct receive_queue *rq, u32 *len, void **ctx) 613 + { 614 + void *buf; 615 + 616 + buf = virtqueue_get_buf_ctx(rq->vq, len, ctx); 617 + if (buf && rq->do_dma) 618 + virtnet_rq_unmap(rq, buf, *len); 619 + 620 + return buf; 621 + } 622 + 623 + static void *virtnet_rq_detach_unused_buf(struct receive_queue *rq) 624 + { 625 + void *buf; 626 + 627 + buf = virtqueue_detach_unused_buf(rq->vq); 628 + if (buf && rq->do_dma) 629 + virtnet_rq_unmap(rq, buf, 0); 630 + 631 + return buf; 632 + } 633 + 634 + static void virtnet_rq_init_one_sg(struct receive_queue *rq, void *buf, u32 len) 635 + { 636 + struct virtnet_rq_dma *dma; 637 + dma_addr_t addr; 638 + u32 offset; 639 + void *head; 640 + 641 + if (!rq->do_dma) { 642 + sg_init_one(rq->sg, buf, len); 643 + return; 644 + } 645 + 646 + head = page_address(rq->alloc_frag.page); 647 + 648 + offset = buf - head; 649 + 650 + dma = head; 651 + 652 + addr = dma->addr - sizeof(*dma) + offset; 653 + 654 + sg_init_table(rq->sg, 1); 655 + rq->sg[0].dma_address = addr; 656 + rq->sg[0].length = len; 657 + } 658 + 659 + static void *virtnet_rq_alloc(struct receive_queue *rq, u32 size, gfp_t gfp) 660 + { 661 + struct page_frag *alloc_frag = &rq->alloc_frag; 662 + struct virtnet_rq_dma *dma; 663 + void *buf, *head; 664 + dma_addr_t addr; 665 + 666 + if (unlikely(!skb_page_frag_refill(size, alloc_frag, gfp))) 667 + return NULL; 668 + 669 + head = page_address(alloc_frag->page); 670 + 671 + if (rq->do_dma) { 672 + dma = head; 673 + 674 + /* new pages */ 675 + if (!alloc_frag->offset) { 676 + if (rq->last_dma) { 677 + /* Now, the new page is allocated, the last dma 678 + * will not be used. So the dma can be unmapped 679 + * if the ref is 0. 680 + */ 681 + virtnet_rq_unmap(rq, rq->last_dma, 0); 682 + rq->last_dma = NULL; 683 + } 684 + 685 + dma->len = alloc_frag->size - sizeof(*dma); 686 + 687 + addr = virtqueue_dma_map_single_attrs(rq->vq, dma + 1, 688 + dma->len, DMA_FROM_DEVICE, 0); 689 + if (virtqueue_dma_mapping_error(rq->vq, addr)) 690 + return NULL; 691 + 692 + dma->addr = addr; 693 + dma->need_sync = virtqueue_dma_need_sync(rq->vq, addr); 694 + 695 + /* Add a reference to dma to prevent the entire dma from 696 + * being released during error handling. This reference 697 + * will be freed after the pages are no longer used. 698 + */ 699 + get_page(alloc_frag->page); 700 + dma->ref = 1; 701 + alloc_frag->offset = sizeof(*dma); 702 + 703 + rq->last_dma = dma; 704 + } 705 + 706 + ++dma->ref; 707 + } 708 + 709 + buf = head + alloc_frag->offset; 710 + 711 + get_page(alloc_frag->page); 712 + alloc_frag->offset += size; 713 + 714 + return buf; 715 + } 716 + 717 + static void virtnet_rq_set_premapped(struct virtnet_info *vi) 718 + { 719 + int i; 720 + 721 + /* disable for big mode */ 722 + if (!vi->mergeable_rx_bufs && vi->big_packets) 723 + return; 724 + 725 + for (i = 0; i < vi->max_queue_pairs; i++) { 726 + if (virtqueue_set_dma_premapped(vi->rq[i].vq)) 727 + continue; 728 + 729 + vi->rq[i].do_dma = true; 730 + } 731 + } 732 + 597 733 static void free_old_xmit_skbs(struct send_queue *sq, bool in_napi) 598 734 { 599 735 unsigned int len; ··· 1099 935 void *buf; 1100 936 int off; 1101 937 1102 - buf = virtqueue_get_buf(rq->vq, &buflen); 938 + buf = virtnet_rq_get_buf(rq, &buflen, NULL); 1103 939 if (unlikely(!buf)) 1104 940 goto err_buf; 1105 941 ··· 1319 1155 int len; 1320 1156 1321 1157 while (num_buf-- > 1) { 1322 - buf = virtqueue_get_buf(rq->vq, &len); 1158 + buf = virtnet_rq_get_buf(rq, &len, NULL); 1323 1159 if (unlikely(!buf)) { 1324 1160 pr_debug("%s: rx error: %d buffers missing\n", 1325 1161 dev->name, num_buf); ··· 1427 1263 return -EINVAL; 1428 1264 1429 1265 while (--*num_buf > 0) { 1430 - buf = virtqueue_get_buf_ctx(rq->vq, &len, &ctx); 1266 + buf = virtnet_rq_get_buf(rq, &len, &ctx); 1431 1267 if (unlikely(!buf)) { 1432 1268 pr_debug("%s: rx error: %d buffers out of %d missing\n", 1433 1269 dev->name, *num_buf, ··· 1656 1492 while (--num_buf) { 1657 1493 int num_skb_frags; 1658 1494 1659 - buf = virtqueue_get_buf_ctx(rq->vq, &len, &ctx); 1495 + buf = virtnet_rq_get_buf(rq, &len, &ctx); 1660 1496 if (unlikely(!buf)) { 1661 1497 pr_debug("%s: rx error: %d buffers out of %d missing\n", 1662 1498 dev->name, num_buf, ··· 1815 1651 static int add_recvbuf_small(struct virtnet_info *vi, struct receive_queue *rq, 1816 1652 gfp_t gfp) 1817 1653 { 1818 - struct page_frag *alloc_frag = &rq->alloc_frag; 1819 1654 char *buf; 1820 1655 unsigned int xdp_headroom = virtnet_get_headroom(vi); 1821 1656 void *ctx = (void *)(unsigned long)xdp_headroom; ··· 1823 1660 1824 1661 len = SKB_DATA_ALIGN(len) + 1825 1662 SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); 1826 - if (unlikely(!skb_page_frag_refill(len, alloc_frag, gfp))) 1663 + 1664 + buf = virtnet_rq_alloc(rq, len, gfp); 1665 + if (unlikely(!buf)) 1827 1666 return -ENOMEM; 1828 1667 1829 - buf = (char *)page_address(alloc_frag->page) + alloc_frag->offset; 1830 - get_page(alloc_frag->page); 1831 - alloc_frag->offset += len; 1832 - sg_init_one(rq->sg, buf + VIRTNET_RX_PAD + xdp_headroom, 1833 - vi->hdr_len + GOOD_PACKET_LEN); 1668 + virtnet_rq_init_one_sg(rq, buf + VIRTNET_RX_PAD + xdp_headroom, 1669 + vi->hdr_len + GOOD_PACKET_LEN); 1670 + 1834 1671 err = virtqueue_add_inbuf_ctx(rq->vq, rq->sg, 1, buf, ctx, gfp); 1835 - if (err < 0) 1672 + if (err < 0) { 1673 + if (rq->do_dma) 1674 + virtnet_rq_unmap(rq, buf, 0); 1836 1675 put_page(virt_to_head_page(buf)); 1676 + } 1677 + 1837 1678 return err; 1838 1679 } 1839 1680 ··· 1914 1747 unsigned int headroom = virtnet_get_headroom(vi); 1915 1748 unsigned int tailroom = headroom ? sizeof(struct skb_shared_info) : 0; 1916 1749 unsigned int room = SKB_DATA_ALIGN(headroom + tailroom); 1917 - char *buf; 1918 - void *ctx; 1919 - int err; 1920 1750 unsigned int len, hole; 1751 + void *ctx; 1752 + char *buf; 1753 + int err; 1921 1754 1922 1755 /* Extra tailroom is needed to satisfy XDP's assumption. This 1923 1756 * means rx frags coalescing won't work, but consider we've 1924 1757 * disabled GSO for XDP, it won't be a big issue. 1925 1758 */ 1926 1759 len = get_mergeable_buf_len(rq, &rq->mrg_avg_pkt_len, room); 1927 - if (unlikely(!skb_page_frag_refill(len + room, alloc_frag, gfp))) 1760 + 1761 + buf = virtnet_rq_alloc(rq, len + room, gfp); 1762 + if (unlikely(!buf)) 1928 1763 return -ENOMEM; 1929 1764 1930 - buf = (char *)page_address(alloc_frag->page) + alloc_frag->offset; 1931 1765 buf += headroom; /* advance address leaving hole at front of pkt */ 1932 - get_page(alloc_frag->page); 1933 - alloc_frag->offset += len + room; 1934 1766 hole = alloc_frag->size - alloc_frag->offset; 1935 1767 if (hole < len + room) { 1936 1768 /* To avoid internal fragmentation, if there is very likely not ··· 1943 1777 alloc_frag->offset += hole; 1944 1778 } 1945 1779 1946 - sg_init_one(rq->sg, buf, len); 1780 + virtnet_rq_init_one_sg(rq, buf, len); 1781 + 1947 1782 ctx = mergeable_len_to_ctx(len + room, headroom); 1948 1783 err = virtqueue_add_inbuf_ctx(rq->vq, rq->sg, 1, buf, ctx, gfp); 1949 - if (err < 0) 1784 + if (err < 0) { 1785 + if (rq->do_dma) 1786 + virtnet_rq_unmap(rq, buf, 0); 1950 1787 put_page(virt_to_head_page(buf)); 1788 + } 1951 1789 1952 1790 return err; 1953 1791 } ··· 2072 1902 void *ctx; 2073 1903 2074 1904 while (stats.packets < budget && 2075 - (buf = virtqueue_get_buf_ctx(rq->vq, &len, &ctx))) { 1905 + (buf = virtnet_rq_get_buf(rq, &len, &ctx))) { 2076 1906 receive_buf(vi, rq, buf, len, ctx, xdp_xmit, &stats); 2077 1907 stats.packets++; 2078 1908 } 2079 1909 } else { 2080 1910 while (stats.packets < budget && 2081 - (buf = virtqueue_get_buf(rq->vq, &len)) != NULL) { 1911 + (buf = virtnet_rq_get_buf(rq, &len, NULL)) != NULL) { 2082 1912 receive_buf(vi, rq, buf, len, NULL, xdp_xmit, &stats); 2083 1913 stats.packets++; 2084 1914 } ··· 3978 3808 { 3979 3809 int i; 3980 3810 for (i = 0; i < vi->max_queue_pairs; i++) 3981 - if (vi->rq[i].alloc_frag.page) 3811 + if (vi->rq[i].alloc_frag.page) { 3812 + if (vi->rq[i].do_dma && vi->rq[i].last_dma) 3813 + virtnet_rq_unmap(&vi->rq[i], vi->rq[i].last_dma, 0); 3982 3814 put_page(vi->rq[i].alloc_frag.page); 3815 + } 3983 3816 } 3984 3817 3985 3818 static void virtnet_sq_free_unused_buf(struct virtqueue *vq, void *buf) ··· 4019 3846 } 4020 3847 4021 3848 for (i = 0; i < vi->max_queue_pairs; i++) { 4022 - struct virtqueue *vq = vi->rq[i].vq; 4023 - while ((buf = virtqueue_detach_unused_buf(vq)) != NULL) 4024 - virtnet_rq_free_unused_buf(vq, buf); 3849 + struct receive_queue *rq = &vi->rq[i]; 3850 + 3851 + while ((buf = virtnet_rq_detach_unused_buf(rq)) != NULL) 3852 + virtnet_rq_free_unused_buf(rq->vq, buf); 4025 3853 cond_resched(); 4026 3854 } 4027 3855 } ··· 4195 4021 ret = virtnet_find_vqs(vi); 4196 4022 if (ret) 4197 4023 goto err_free; 4024 + 4025 + virtnet_rq_set_premapped(vi); 4198 4026 4199 4027 cpus_read_lock(); 4200 4028 virtnet_set_affinity(vi);
-3
drivers/vdpa/mlx5/core/mlx5_vdpa.h
··· 100 100 bool suspended; 101 101 }; 102 102 103 - int mlx5_vdpa_alloc_pd(struct mlx5_vdpa_dev *dev, u32 *pdn, u16 uid); 104 - int mlx5_vdpa_dealloc_pd(struct mlx5_vdpa_dev *dev, u32 pdn, u16 uid); 105 - int mlx5_vdpa_get_null_mkey(struct mlx5_vdpa_dev *dev, u32 *null_mkey); 106 103 int mlx5_vdpa_create_tis(struct mlx5_vdpa_dev *mvdev, void *in, u32 *tisn); 107 104 void mlx5_vdpa_destroy_tis(struct mlx5_vdpa_dev *mvdev, u32 tisn); 108 105 int mlx5_vdpa_create_rqt(struct mlx5_vdpa_dev *mvdev, void *in, int inlen, u32 *rqtn);
+8
drivers/vdpa/vdpa_sim/vdpa_sim.c
··· 18 18 #include <linux/vdpa.h> 19 19 #include <linux/vhost_iotlb.h> 20 20 #include <uapi/linux/vdpa.h> 21 + #include <uapi/linux/vhost_types.h> 21 22 22 23 #include "vdpa_sim.h" 23 24 ··· 411 410 return vdpasim->dev_attr.supported_features; 412 411 } 413 412 413 + static u64 vdpasim_get_backend_features(const struct vdpa_device *vdpa) 414 + { 415 + return BIT_ULL(VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK); 416 + } 417 + 414 418 static int vdpasim_set_driver_features(struct vdpa_device *vdpa, u64 features) 415 419 { 416 420 struct vdpasim *vdpasim = vdpa_to_sim(vdpa); ··· 739 733 .get_vq_align = vdpasim_get_vq_align, 740 734 .get_vq_group = vdpasim_get_vq_group, 741 735 .get_device_features = vdpasim_get_device_features, 736 + .get_backend_features = vdpasim_get_backend_features, 742 737 .set_driver_features = vdpasim_set_driver_features, 743 738 .get_driver_features = vdpasim_get_driver_features, 744 739 .set_config_cb = vdpasim_set_config_cb, ··· 777 770 .get_vq_align = vdpasim_get_vq_align, 778 771 .get_vq_group = vdpasim_get_vq_group, 779 772 .get_device_features = vdpasim_get_device_features, 773 + .get_backend_features = vdpasim_get_backend_features, 780 774 .set_driver_features = vdpasim_set_driver_features, 781 775 .get_driver_features = vdpasim_get_driver_features, 782 776 .set_config_cb = vdpasim_set_config_cb,
+14 -1
drivers/vhost/vdpa.c
··· 403 403 return 0; 404 404 } 405 405 406 + static u64 vhost_vdpa_get_backend_features(const struct vhost_vdpa *v) 407 + { 408 + struct vdpa_device *vdpa = v->vdpa; 409 + const struct vdpa_config_ops *ops = vdpa->config; 410 + 411 + if (!ops->get_backend_features) 412 + return 0; 413 + else 414 + return ops->get_backend_features(vdpa); 415 + } 416 + 406 417 static long vhost_vdpa_set_features(struct vhost_vdpa *v, u64 __user *featurep) 407 418 { 408 419 struct vdpa_device *vdpa = v->vdpa; ··· 691 680 return -EFAULT; 692 681 if (features & ~(VHOST_VDPA_BACKEND_FEATURES | 693 682 BIT_ULL(VHOST_BACKEND_F_SUSPEND) | 694 - BIT_ULL(VHOST_BACKEND_F_RESUME))) 683 + BIT_ULL(VHOST_BACKEND_F_RESUME) | 684 + BIT_ULL(VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK))) 695 685 return -EOPNOTSUPP; 696 686 if ((features & BIT_ULL(VHOST_BACKEND_F_SUSPEND)) && 697 687 !vhost_vdpa_can_suspend(v)) ··· 753 741 features |= BIT_ULL(VHOST_BACKEND_F_SUSPEND); 754 742 if (vhost_vdpa_can_resume(v)) 755 743 features |= BIT_ULL(VHOST_BACKEND_F_RESUME); 744 + features |= vhost_vdpa_get_backend_features(v); 756 745 if (copy_to_user(featurep, &features, sizeof(features))) 757 746 r = -EFAULT; 758 747 break;
+359 -53
drivers/virtio/virtio_ring.c
··· 172 172 /* Host publishes avail event idx */ 173 173 bool event; 174 174 175 + /* Do DMA mapping by driver */ 176 + bool premapped; 177 + 178 + /* Do unmap or not for desc. Just when premapped is False and 179 + * use_dma_api is true, this is true. 180 + */ 181 + bool do_unmap; 182 + 175 183 /* Head of free buffer list. */ 176 184 unsigned int free_head; 177 185 /* Number we've added since last sync. */ ··· 363 355 } 364 356 365 357 /* Map one sg entry. */ 366 - static dma_addr_t vring_map_one_sg(const struct vring_virtqueue *vq, 367 - struct scatterlist *sg, 368 - enum dma_data_direction direction) 358 + static int vring_map_one_sg(const struct vring_virtqueue *vq, struct scatterlist *sg, 359 + enum dma_data_direction direction, dma_addr_t *addr) 369 360 { 361 + if (vq->premapped) { 362 + *addr = sg_dma_address(sg); 363 + return 0; 364 + } 365 + 370 366 if (!vq->use_dma_api) { 371 367 /* 372 368 * If DMA is not used, KMSAN doesn't know that the scatterlist ··· 378 366 * depending on the direction. 379 367 */ 380 368 kmsan_handle_dma(sg_page(sg), sg->offset, sg->length, direction); 381 - return (dma_addr_t)sg_phys(sg); 369 + *addr = (dma_addr_t)sg_phys(sg); 370 + return 0; 382 371 } 383 372 384 373 /* ··· 387 374 * the way it expects (we don't guarantee that the scatterlist 388 375 * will exist for the lifetime of the mapping). 389 376 */ 390 - return dma_map_page(vring_dma_dev(vq), 377 + *addr = dma_map_page(vring_dma_dev(vq), 391 378 sg_page(sg), sg->offset, sg->length, 392 379 direction); 380 + 381 + if (dma_mapping_error(vring_dma_dev(vq), *addr)) 382 + return -ENOMEM; 383 + 384 + return 0; 393 385 } 394 386 395 387 static dma_addr_t vring_map_single(const struct vring_virtqueue *vq, ··· 445 427 { 446 428 u16 flags; 447 429 448 - if (!vq->use_dma_api) 430 + if (!vq->do_unmap) 449 431 return; 450 432 451 433 flags = virtio16_to_cpu(vq->vq.vdev, desc->flags); ··· 463 445 struct vring_desc_extra *extra = vq->split.desc_extra; 464 446 u16 flags; 465 447 466 - if (!vq->use_dma_api) 467 - goto out; 468 - 469 448 flags = extra[i].flags; 470 449 471 450 if (flags & VRING_DESC_F_INDIRECT) { 451 + if (!vq->use_dma_api) 452 + goto out; 453 + 472 454 dma_unmap_single(vring_dma_dev(vq), 473 455 extra[i].addr, 474 456 extra[i].len, 475 457 (flags & VRING_DESC_F_WRITE) ? 476 458 DMA_FROM_DEVICE : DMA_TO_DEVICE); 477 459 } else { 460 + if (!vq->do_unmap) 461 + goto out; 462 + 478 463 dma_unmap_page(vring_dma_dev(vq), 479 464 extra[i].addr, 480 465 extra[i].len, ··· 609 588 610 589 for (n = 0; n < out_sgs; n++) { 611 590 for (sg = sgs[n]; sg; sg = sg_next(sg)) { 612 - dma_addr_t addr = vring_map_one_sg(vq, sg, DMA_TO_DEVICE); 613 - if (vring_mapping_error(vq, addr)) 591 + dma_addr_t addr; 592 + 593 + if (vring_map_one_sg(vq, sg, DMA_TO_DEVICE, &addr)) 614 594 goto unmap_release; 615 595 616 596 prev = i; ··· 625 603 } 626 604 for (; n < (out_sgs + in_sgs); n++) { 627 605 for (sg = sgs[n]; sg; sg = sg_next(sg)) { 628 - dma_addr_t addr = vring_map_one_sg(vq, sg, DMA_FROM_DEVICE); 629 - if (vring_mapping_error(vq, addr)) 606 + dma_addr_t addr; 607 + 608 + if (vring_map_one_sg(vq, sg, DMA_FROM_DEVICE, &addr)) 630 609 goto unmap_release; 631 610 632 611 prev = i; ··· 643 620 } 644 621 /* Last one doesn't continue. */ 645 622 desc[prev].flags &= cpu_to_virtio16(_vq->vdev, ~VRING_DESC_F_NEXT); 646 - if (!indirect && vq->use_dma_api) 623 + if (!indirect && vq->do_unmap) 647 624 vq->split.desc_extra[prev & (vq->split.vring.num - 1)].flags &= 648 625 ~VRING_DESC_F_NEXT; 649 626 ··· 652 629 dma_addr_t addr = vring_map_single( 653 630 vq, desc, total_sg * sizeof(struct vring_desc), 654 631 DMA_TO_DEVICE); 655 - if (vring_mapping_error(vq, addr)) 632 + if (vring_mapping_error(vq, addr)) { 633 + if (vq->premapped) 634 + goto free_indirect; 635 + 656 636 goto unmap_release; 637 + } 657 638 658 639 virtqueue_add_desc_split(_vq, vq->split.vring.desc, 659 640 head, addr, ··· 723 696 i = vring_unmap_one_split(vq, i); 724 697 } 725 698 699 + free_indirect: 726 700 if (indirect) 727 701 kfree(desc); 728 702 ··· 802 774 VRING_DESC_F_INDIRECT)); 803 775 BUG_ON(len == 0 || len % sizeof(struct vring_desc)); 804 776 805 - for (j = 0; j < len / sizeof(struct vring_desc); j++) 806 - vring_unmap_one_split_indirect(vq, &indir_desc[j]); 777 + if (vq->do_unmap) { 778 + for (j = 0; j < len / sizeof(struct vring_desc); j++) 779 + vring_unmap_one_split_indirect(vq, &indir_desc[j]); 780 + } 807 781 808 782 kfree(indir_desc); 809 783 vq->split.desc_state[head].indir_desc = NULL; ··· 1225 1195 { 1226 1196 u16 flags; 1227 1197 1228 - if (!vq->use_dma_api) 1229 - return; 1230 - 1231 1198 flags = extra->flags; 1232 1199 1233 1200 if (flags & VRING_DESC_F_INDIRECT) { 1201 + if (!vq->use_dma_api) 1202 + return; 1203 + 1234 1204 dma_unmap_single(vring_dma_dev(vq), 1235 1205 extra->addr, extra->len, 1236 1206 (flags & VRING_DESC_F_WRITE) ? 1237 1207 DMA_FROM_DEVICE : DMA_TO_DEVICE); 1238 1208 } else { 1209 + if (!vq->do_unmap) 1210 + return; 1211 + 1239 1212 dma_unmap_page(vring_dma_dev(vq), 1240 1213 extra->addr, extra->len, 1241 1214 (flags & VRING_DESC_F_WRITE) ? ··· 1251 1218 { 1252 1219 u16 flags; 1253 1220 1254 - if (!vq->use_dma_api) 1221 + if (!vq->do_unmap) 1255 1222 return; 1256 1223 1257 1224 flags = le16_to_cpu(desc->flags); ··· 1312 1279 1313 1280 for (n = 0; n < out_sgs + in_sgs; n++) { 1314 1281 for (sg = sgs[n]; sg; sg = sg_next(sg)) { 1315 - addr = vring_map_one_sg(vq, sg, n < out_sgs ? 1316 - DMA_TO_DEVICE : DMA_FROM_DEVICE); 1317 - if (vring_mapping_error(vq, addr)) 1282 + if (vring_map_one_sg(vq, sg, n < out_sgs ? 1283 + DMA_TO_DEVICE : DMA_FROM_DEVICE, &addr)) 1318 1284 goto unmap_release; 1319 1285 1320 1286 desc[i].flags = cpu_to_le16(n < out_sgs ? ··· 1328 1296 addr = vring_map_single(vq, desc, 1329 1297 total_sg * sizeof(struct vring_packed_desc), 1330 1298 DMA_TO_DEVICE); 1331 - if (vring_mapping_error(vq, addr)) 1299 + if (vring_mapping_error(vq, addr)) { 1300 + if (vq->premapped) 1301 + goto free_desc; 1302 + 1332 1303 goto unmap_release; 1304 + } 1333 1305 1334 1306 vq->packed.vring.desc[head].addr = cpu_to_le64(addr); 1335 1307 vq->packed.vring.desc[head].len = cpu_to_le32(total_sg * 1336 1308 sizeof(struct vring_packed_desc)); 1337 1309 vq->packed.vring.desc[head].id = cpu_to_le16(id); 1338 1310 1339 - if (vq->use_dma_api) { 1311 + if (vq->do_unmap) { 1340 1312 vq->packed.desc_extra[id].addr = addr; 1341 1313 vq->packed.desc_extra[id].len = total_sg * 1342 1314 sizeof(struct vring_packed_desc); ··· 1391 1355 for (i = 0; i < err_idx; i++) 1392 1356 vring_unmap_desc_packed(vq, &desc[i]); 1393 1357 1358 + free_desc: 1394 1359 kfree(desc); 1395 1360 1396 1361 END_USE(vq); ··· 1463 1426 c = 0; 1464 1427 for (n = 0; n < out_sgs + in_sgs; n++) { 1465 1428 for (sg = sgs[n]; sg; sg = sg_next(sg)) { 1466 - dma_addr_t addr = vring_map_one_sg(vq, sg, n < out_sgs ? 1467 - DMA_TO_DEVICE : DMA_FROM_DEVICE); 1468 - if (vring_mapping_error(vq, addr)) 1429 + dma_addr_t addr; 1430 + 1431 + if (vring_map_one_sg(vq, sg, n < out_sgs ? 1432 + DMA_TO_DEVICE : DMA_FROM_DEVICE, &addr)) 1469 1433 goto unmap_release; 1470 1434 1471 1435 flags = cpu_to_le16(vq->packed.avail_used_flags | ··· 1481 1443 desc[i].len = cpu_to_le32(sg->length); 1482 1444 desc[i].id = cpu_to_le16(id); 1483 1445 1484 - if (unlikely(vq->use_dma_api)) { 1446 + if (unlikely(vq->do_unmap)) { 1485 1447 vq->packed.desc_extra[curr].addr = addr; 1486 1448 vq->packed.desc_extra[curr].len = sg->length; 1487 1449 vq->packed.desc_extra[curr].flags = ··· 1499 1461 } 1500 1462 } 1501 1463 1502 - if (i < head) 1464 + if (i <= head) 1503 1465 vq->packed.avail_wrap_counter ^= 1; 1504 1466 1505 1467 /* We're using some buffers from the free list. */ ··· 1615 1577 vq->free_head = id; 1616 1578 vq->vq.num_free += state->num; 1617 1579 1618 - if (unlikely(vq->use_dma_api)) { 1580 + if (unlikely(vq->do_unmap)) { 1619 1581 curr = id; 1620 1582 for (i = 0; i < state->num; i++) { 1621 1583 vring_unmap_extra_packed(vq, ··· 1632 1594 if (!desc) 1633 1595 return; 1634 1596 1635 - if (vq->use_dma_api) { 1597 + if (vq->do_unmap) { 1636 1598 len = vq->packed.desc_extra[id].len; 1637 1599 for (i = 0; i < len / sizeof(struct vring_packed_desc); 1638 1600 i++) ··· 2090 2052 vq->packed_ring = true; 2091 2053 vq->dma_dev = dma_dev; 2092 2054 vq->use_dma_api = vring_use_dma_api(vdev); 2055 + vq->premapped = false; 2056 + vq->do_unmap = vq->use_dma_api; 2093 2057 2094 2058 vq->indirect = virtio_has_feature(vdev, VIRTIO_RING_F_INDIRECT_DESC) && 2095 2059 !context; ··· 2152 2112 return -ENOMEM; 2153 2113 } 2154 2114 2115 + static int virtqueue_disable_and_recycle(struct virtqueue *_vq, 2116 + void (*recycle)(struct virtqueue *vq, void *buf)) 2117 + { 2118 + struct vring_virtqueue *vq = to_vvq(_vq); 2119 + struct virtio_device *vdev = vq->vq.vdev; 2120 + void *buf; 2121 + int err; 2122 + 2123 + if (!vq->we_own_ring) 2124 + return -EPERM; 2125 + 2126 + if (!vdev->config->disable_vq_and_reset) 2127 + return -ENOENT; 2128 + 2129 + if (!vdev->config->enable_vq_after_reset) 2130 + return -ENOENT; 2131 + 2132 + err = vdev->config->disable_vq_and_reset(_vq); 2133 + if (err) 2134 + return err; 2135 + 2136 + while ((buf = virtqueue_detach_unused_buf(_vq)) != NULL) 2137 + recycle(_vq, buf); 2138 + 2139 + return 0; 2140 + } 2141 + 2142 + static int virtqueue_enable_after_reset(struct virtqueue *_vq) 2143 + { 2144 + struct vring_virtqueue *vq = to_vvq(_vq); 2145 + struct virtio_device *vdev = vq->vq.vdev; 2146 + 2147 + if (vdev->config->enable_vq_after_reset(_vq)) 2148 + return -EBUSY; 2149 + 2150 + return 0; 2151 + } 2155 2152 2156 2153 /* 2157 2154 * Generic functions and exported symbols. ··· 2313 2236 return virtqueue_add(vq, &sg, num, 0, 1, data, ctx, gfp); 2314 2237 } 2315 2238 EXPORT_SYMBOL_GPL(virtqueue_add_inbuf_ctx); 2239 + 2240 + /** 2241 + * virtqueue_dma_dev - get the dma dev 2242 + * @_vq: the struct virtqueue we're talking about. 2243 + * 2244 + * Returns the dma dev. That can been used for dma api. 2245 + */ 2246 + struct device *virtqueue_dma_dev(struct virtqueue *_vq) 2247 + { 2248 + struct vring_virtqueue *vq = to_vvq(_vq); 2249 + 2250 + if (vq->use_dma_api) 2251 + return vring_dma_dev(vq); 2252 + else 2253 + return NULL; 2254 + } 2255 + EXPORT_SYMBOL_GPL(virtqueue_dma_dev); 2316 2256 2317 2257 /** 2318 2258 * virtqueue_kick_prepare - first half of split virtqueue_kick call. ··· 2635 2541 #endif 2636 2542 vq->dma_dev = dma_dev; 2637 2543 vq->use_dma_api = vring_use_dma_api(vdev); 2544 + vq->premapped = false; 2545 + vq->do_unmap = vq->use_dma_api; 2638 2546 2639 2547 vq->indirect = virtio_has_feature(vdev, VIRTIO_RING_F_INDIRECT_DESC) && 2640 2548 !context; ··· 2715 2619 * virtqueue_resize - resize the vring of vq 2716 2620 * @_vq: the struct virtqueue we're talking about. 2717 2621 * @num: new ring num 2718 - * @recycle: callback for recycle the useless buffer 2622 + * @recycle: callback to recycle unused buffers 2719 2623 * 2720 2624 * When it is really necessary to create a new vring, it will set the current vq 2721 2625 * into the reset state. Then call the passed callback to recycle the buffer ··· 2739 2643 void (*recycle)(struct virtqueue *vq, void *buf)) 2740 2644 { 2741 2645 struct vring_virtqueue *vq = to_vvq(_vq); 2742 - struct virtio_device *vdev = vq->vq.vdev; 2743 - void *buf; 2744 2646 int err; 2745 - 2746 - if (!vq->we_own_ring) 2747 - return -EPERM; 2748 2647 2749 2648 if (num > vq->vq.num_max) 2750 2649 return -E2BIG; ··· 2750 2659 if ((vq->packed_ring ? vq->packed.vring.num : vq->split.vring.num) == num) 2751 2660 return 0; 2752 2661 2753 - if (!vdev->config->disable_vq_and_reset) 2754 - return -ENOENT; 2755 - 2756 - if (!vdev->config->enable_vq_after_reset) 2757 - return -ENOENT; 2758 - 2759 - err = vdev->config->disable_vq_and_reset(_vq); 2662 + err = virtqueue_disable_and_recycle(_vq, recycle); 2760 2663 if (err) 2761 2664 return err; 2762 - 2763 - while ((buf = virtqueue_detach_unused_buf(_vq)) != NULL) 2764 - recycle(_vq, buf); 2765 2665 2766 2666 if (vq->packed_ring) 2767 2667 err = virtqueue_resize_packed(_vq, num); 2768 2668 else 2769 2669 err = virtqueue_resize_split(_vq, num); 2770 2670 2771 - if (vdev->config->enable_vq_after_reset(_vq)) 2772 - return -EBUSY; 2773 - 2774 - return err; 2671 + return virtqueue_enable_after_reset(_vq); 2775 2672 } 2776 2673 EXPORT_SYMBOL_GPL(virtqueue_resize); 2674 + 2675 + /** 2676 + * virtqueue_set_dma_premapped - set the vring premapped mode 2677 + * @_vq: the struct virtqueue we're talking about. 2678 + * 2679 + * Enable the premapped mode of the vq. 2680 + * 2681 + * The vring in premapped mode does not do dma internally, so the driver must 2682 + * do dma mapping in advance. The driver must pass the dma_address through 2683 + * dma_address of scatterlist. When the driver got a used buffer from 2684 + * the vring, it has to unmap the dma address. 2685 + * 2686 + * This function must be called immediately after creating the vq, or after vq 2687 + * reset, and before adding any buffers to it. 2688 + * 2689 + * Caller must ensure we don't call this with other virtqueue operations 2690 + * at the same time (except where noted). 2691 + * 2692 + * Returns zero or a negative error. 2693 + * 0: success. 2694 + * -EINVAL: vring does not use the dma api, so we can not enable premapped mode. 2695 + */ 2696 + int virtqueue_set_dma_premapped(struct virtqueue *_vq) 2697 + { 2698 + struct vring_virtqueue *vq = to_vvq(_vq); 2699 + u32 num; 2700 + 2701 + START_USE(vq); 2702 + 2703 + num = vq->packed_ring ? vq->packed.vring.num : vq->split.vring.num; 2704 + 2705 + if (num != vq->vq.num_free) { 2706 + END_USE(vq); 2707 + return -EINVAL; 2708 + } 2709 + 2710 + if (!vq->use_dma_api) { 2711 + END_USE(vq); 2712 + return -EINVAL; 2713 + } 2714 + 2715 + vq->premapped = true; 2716 + vq->do_unmap = false; 2717 + 2718 + END_USE(vq); 2719 + 2720 + return 0; 2721 + } 2722 + EXPORT_SYMBOL_GPL(virtqueue_set_dma_premapped); 2723 + 2724 + /** 2725 + * virtqueue_reset - detach and recycle all unused buffers 2726 + * @_vq: the struct virtqueue we're talking about. 2727 + * @recycle: callback to recycle unused buffers 2728 + * 2729 + * Caller must ensure we don't call this with other virtqueue operations 2730 + * at the same time (except where noted). 2731 + * 2732 + * Returns zero or a negative error. 2733 + * 0: success. 2734 + * -EBUSY: Failed to sync with device, vq may not work properly 2735 + * -ENOENT: Transport or device not supported 2736 + * -EPERM: Operation not permitted 2737 + */ 2738 + int virtqueue_reset(struct virtqueue *_vq, 2739 + void (*recycle)(struct virtqueue *vq, void *buf)) 2740 + { 2741 + struct vring_virtqueue *vq = to_vvq(_vq); 2742 + int err; 2743 + 2744 + err = virtqueue_disable_and_recycle(_vq, recycle); 2745 + if (err) 2746 + return err; 2747 + 2748 + if (vq->packed_ring) 2749 + virtqueue_reinit_packed(vq); 2750 + else 2751 + virtqueue_reinit_split(vq); 2752 + 2753 + return virtqueue_enable_after_reset(_vq); 2754 + } 2755 + EXPORT_SYMBOL_GPL(virtqueue_reset); 2777 2756 2778 2757 /* Only available for split ring */ 2779 2758 struct virtqueue *vring_new_virtqueue(unsigned int index, ··· 3105 2944 return &to_vvq(vq)->split.vring; 3106 2945 } 3107 2946 EXPORT_SYMBOL_GPL(virtqueue_get_vring); 2947 + 2948 + /** 2949 + * virtqueue_dma_map_single_attrs - map DMA for _vq 2950 + * @_vq: the struct virtqueue we're talking about. 2951 + * @ptr: the pointer of the buffer to do dma 2952 + * @size: the size of the buffer to do dma 2953 + * @dir: DMA direction 2954 + * @attrs: DMA Attrs 2955 + * 2956 + * The caller calls this to do dma mapping in advance. The DMA address can be 2957 + * passed to this _vq when it is in pre-mapped mode. 2958 + * 2959 + * return DMA address. Caller should check that by virtqueue_dma_mapping_error(). 2960 + */ 2961 + dma_addr_t virtqueue_dma_map_single_attrs(struct virtqueue *_vq, void *ptr, 2962 + size_t size, 2963 + enum dma_data_direction dir, 2964 + unsigned long attrs) 2965 + { 2966 + struct vring_virtqueue *vq = to_vvq(_vq); 2967 + 2968 + if (!vq->use_dma_api) 2969 + return (dma_addr_t)virt_to_phys(ptr); 2970 + 2971 + return dma_map_single_attrs(vring_dma_dev(vq), ptr, size, dir, attrs); 2972 + } 2973 + EXPORT_SYMBOL_GPL(virtqueue_dma_map_single_attrs); 2974 + 2975 + /** 2976 + * virtqueue_dma_unmap_single_attrs - unmap DMA for _vq 2977 + * @_vq: the struct virtqueue we're talking about. 2978 + * @addr: the dma address to unmap 2979 + * @size: the size of the buffer 2980 + * @dir: DMA direction 2981 + * @attrs: DMA Attrs 2982 + * 2983 + * Unmap the address that is mapped by the virtqueue_dma_map_* APIs. 2984 + * 2985 + */ 2986 + void virtqueue_dma_unmap_single_attrs(struct virtqueue *_vq, dma_addr_t addr, 2987 + size_t size, enum dma_data_direction dir, 2988 + unsigned long attrs) 2989 + { 2990 + struct vring_virtqueue *vq = to_vvq(_vq); 2991 + 2992 + if (!vq->use_dma_api) 2993 + return; 2994 + 2995 + dma_unmap_single_attrs(vring_dma_dev(vq), addr, size, dir, attrs); 2996 + } 2997 + EXPORT_SYMBOL_GPL(virtqueue_dma_unmap_single_attrs); 2998 + 2999 + /** 3000 + * virtqueue_dma_mapping_error - check dma address 3001 + * @_vq: the struct virtqueue we're talking about. 3002 + * @addr: DMA address 3003 + * 3004 + * Returns 0 means dma valid. Other means invalid dma address. 3005 + */ 3006 + int virtqueue_dma_mapping_error(struct virtqueue *_vq, dma_addr_t addr) 3007 + { 3008 + struct vring_virtqueue *vq = to_vvq(_vq); 3009 + 3010 + if (!vq->use_dma_api) 3011 + return 0; 3012 + 3013 + return dma_mapping_error(vring_dma_dev(vq), addr); 3014 + } 3015 + EXPORT_SYMBOL_GPL(virtqueue_dma_mapping_error); 3016 + 3017 + /** 3018 + * virtqueue_dma_need_sync - check a dma address needs sync 3019 + * @_vq: the struct virtqueue we're talking about. 3020 + * @addr: DMA address 3021 + * 3022 + * Check if the dma address mapped by the virtqueue_dma_map_* APIs needs to be 3023 + * synchronized 3024 + * 3025 + * return bool 3026 + */ 3027 + bool virtqueue_dma_need_sync(struct virtqueue *_vq, dma_addr_t addr) 3028 + { 3029 + struct vring_virtqueue *vq = to_vvq(_vq); 3030 + 3031 + if (!vq->use_dma_api) 3032 + return false; 3033 + 3034 + return dma_need_sync(vring_dma_dev(vq), addr); 3035 + } 3036 + EXPORT_SYMBOL_GPL(virtqueue_dma_need_sync); 3037 + 3038 + /** 3039 + * virtqueue_dma_sync_single_range_for_cpu - dma sync for cpu 3040 + * @_vq: the struct virtqueue we're talking about. 3041 + * @addr: DMA address 3042 + * @offset: DMA address offset 3043 + * @size: buf size for sync 3044 + * @dir: DMA direction 3045 + * 3046 + * Before calling this function, use virtqueue_dma_need_sync() to confirm that 3047 + * the DMA address really needs to be synchronized 3048 + * 3049 + */ 3050 + void virtqueue_dma_sync_single_range_for_cpu(struct virtqueue *_vq, 3051 + dma_addr_t addr, 3052 + unsigned long offset, size_t size, 3053 + enum dma_data_direction dir) 3054 + { 3055 + struct vring_virtqueue *vq = to_vvq(_vq); 3056 + struct device *dev = vring_dma_dev(vq); 3057 + 3058 + if (!vq->use_dma_api) 3059 + return; 3060 + 3061 + dma_sync_single_range_for_cpu(dev, addr, offset, size, 3062 + DMA_BIDIRECTIONAL); 3063 + } 3064 + EXPORT_SYMBOL_GPL(virtqueue_dma_sync_single_range_for_cpu); 3065 + 3066 + /** 3067 + * virtqueue_dma_sync_single_range_for_device - dma sync for device 3068 + * @_vq: the struct virtqueue we're talking about. 3069 + * @addr: DMA address 3070 + * @offset: DMA address offset 3071 + * @size: buf size for sync 3072 + * @dir: DMA direction 3073 + * 3074 + * Before calling this function, use virtqueue_dma_need_sync() to confirm that 3075 + * the DMA address really needs to be synchronized 3076 + */ 3077 + void virtqueue_dma_sync_single_range_for_device(struct virtqueue *_vq, 3078 + dma_addr_t addr, 3079 + unsigned long offset, size_t size, 3080 + enum dma_data_direction dir) 3081 + { 3082 + struct vring_virtqueue *vq = to_vvq(_vq); 3083 + struct device *dev = vring_dma_dev(vq); 3084 + 3085 + if (!vq->use_dma_api) 3086 + return; 3087 + 3088 + dma_sync_single_range_for_device(dev, addr, offset, size, 3089 + DMA_BIDIRECTIONAL); 3090 + } 3091 + EXPORT_SYMBOL_GPL(virtqueue_dma_sync_single_range_for_device); 3108 3092 3109 3093 MODULE_LICENSE("GPL");
+11 -6
drivers/virtio/virtio_vdpa.c
··· 366 366 struct irq_affinity default_affd = { 0 }; 367 367 struct cpumask *masks; 368 368 struct vdpa_callback cb; 369 + bool has_affinity = desc && ops->set_vq_affinity; 369 370 int i, err, queue_idx = 0; 370 371 371 - masks = create_affinity_masks(nvqs, desc ? desc : &default_affd); 372 - if (!masks) 373 - return -ENOMEM; 372 + if (has_affinity) { 373 + masks = create_affinity_masks(nvqs, desc ? desc : &default_affd); 374 + if (!masks) 375 + return -ENOMEM; 376 + } 374 377 375 378 for (i = 0; i < nvqs; ++i) { 376 379 if (!names[i]) { ··· 389 386 goto err_setup_vq; 390 387 } 391 388 392 - if (ops->set_vq_affinity) 389 + if (has_affinity) 393 390 ops->set_vq_affinity(vdpa, i, &masks[i]); 394 391 } 395 392 396 393 cb.callback = virtio_vdpa_config_cb; 397 394 cb.private = vd_dev; 398 395 ops->set_config_cb(vdpa, &cb); 399 - kfree(masks); 396 + if (has_affinity) 397 + kfree(masks); 400 398 401 399 return 0; 402 400 403 401 err_setup_vq: 404 402 virtio_vdpa_del_vqs(vdev); 405 - kfree(masks); 403 + if (has_affinity) 404 + kfree(masks); 406 405 return err; 407 406 } 408 407
+4
include/linux/vdpa.h
··· 208 208 * @vdev: vdpa device 209 209 * Returns the virtio features support by the 210 210 * device 211 + * @get_backend_features: Get parent-specific backend features (optional) 212 + * Returns the vdpa features supported by the 213 + * device. 211 214 * @set_driver_features: Set virtio features supported by the driver 212 215 * @vdev: vdpa device 213 216 * @features: feature support by the driver ··· 361 358 u32 (*get_vq_align)(struct vdpa_device *vdev); 362 359 u32 (*get_vq_group)(struct vdpa_device *vdev, u16 idx); 363 360 u64 (*get_device_features)(struct vdpa_device *vdev); 361 + u64 (*get_backend_features)(const struct vdpa_device *vdev); 364 362 int (*set_driver_features)(struct vdpa_device *vdev, u64 features); 365 363 u64 (*get_driver_features)(struct vdpa_device *vdev); 366 364 void (*set_config_cb)(struct vdpa_device *vdev,
+22
include/linux/virtio.h
··· 9 9 #include <linux/device.h> 10 10 #include <linux/mod_devicetable.h> 11 11 #include <linux/gfp.h> 12 + #include <linux/dma-mapping.h> 12 13 13 14 /** 14 15 * struct virtqueue - a queue to register buffers for sending or receiving. ··· 62 61 void *data, 63 62 gfp_t gfp); 64 63 64 + struct device *virtqueue_dma_dev(struct virtqueue *vq); 65 + 65 66 bool virtqueue_kick(struct virtqueue *vq); 66 67 67 68 bool virtqueue_kick_prepare(struct virtqueue *vq); ··· 80 77 bool virtqueue_enable_cb(struct virtqueue *vq); 81 78 82 79 unsigned virtqueue_enable_cb_prepare(struct virtqueue *vq); 80 + 81 + int virtqueue_set_dma_premapped(struct virtqueue *_vq); 83 82 84 83 bool virtqueue_poll(struct virtqueue *vq, unsigned); 85 84 ··· 100 95 101 96 int virtqueue_resize(struct virtqueue *vq, u32 num, 102 97 void (*recycle)(struct virtqueue *vq, void *buf)); 98 + int virtqueue_reset(struct virtqueue *vq, 99 + void (*recycle)(struct virtqueue *vq, void *buf)); 103 100 104 101 /** 105 102 * struct virtio_device - representation of a device using virtio ··· 213 206 #define module_virtio_driver(__virtio_driver) \ 214 207 module_driver(__virtio_driver, register_virtio_driver, \ 215 208 unregister_virtio_driver) 209 + 210 + dma_addr_t virtqueue_dma_map_single_attrs(struct virtqueue *_vq, void *ptr, size_t size, 211 + enum dma_data_direction dir, unsigned long attrs); 212 + void virtqueue_dma_unmap_single_attrs(struct virtqueue *_vq, dma_addr_t addr, 213 + size_t size, enum dma_data_direction dir, 214 + unsigned long attrs); 215 + int virtqueue_dma_mapping_error(struct virtqueue *_vq, dma_addr_t addr); 216 + 217 + bool virtqueue_dma_need_sync(struct virtqueue *_vq, dma_addr_t addr); 218 + void virtqueue_dma_sync_single_range_for_cpu(struct virtqueue *_vq, dma_addr_t addr, 219 + unsigned long offset, size_t size, 220 + enum dma_data_direction dir); 221 + void virtqueue_dma_sync_single_range_for_device(struct virtqueue *_vq, dma_addr_t addr, 222 + unsigned long offset, size_t size, 223 + enum dma_data_direction dir); 216 224 #endif /* _LINUX_VIRTIO_H */
+4
include/uapi/linux/vhost_types.h
··· 181 181 #define VHOST_BACKEND_F_SUSPEND 0x4 182 182 /* Device can be resumed */ 183 183 #define VHOST_BACKEND_F_RESUME 0x5 184 + /* Device supports the driver enabling virtqueues both before and after 185 + * DRIVER_OK 186 + */ 187 + #define VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK 0x6 184 188 185 189 #endif