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

Merge branch 'stable/for-linus-4.9' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/swiotlb

Pull swiotlb updates from Konrad Rzeszutek Wilk:

- minor fixes (rate limiting), remove certain functions

- support for DMA_ATTR_SKIP_CPU_SYNC which is an optimization
in the DMA API

* 'stable/for-linus-4.9' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad/swiotlb:
swiotlb: Minor fix-ups for DMA_ATTR_SKIP_CPU_SYNC support
swiotlb: Add support for DMA_ATTR_SKIP_CPU_SYNC
swiotlb-xen: Enforce return of DMA_ERROR_CODE in mapping function
swiotlb: Drop unused functions swiotlb_map_sg and swiotlb_unmap_sg
swiotlb: Rate-limit printing when running out of SW-IOMMU space

+57 -70
-1
arch/arm/xen/mm.c
··· 186 186 EXPORT_SYMBOL(xen_dma_ops); 187 187 188 188 static struct dma_map_ops xen_swiotlb_dma_ops = { 189 - .mapping_error = xen_swiotlb_dma_mapping_error, 190 189 .alloc = xen_swiotlb_alloc_coherent, 191 190 .free = xen_swiotlb_free_coherent, 192 191 .sync_single_for_cpu = xen_swiotlb_sync_single_for_cpu,
-1
arch/x86/xen/pci-swiotlb-xen.c
··· 19 19 int xen_swiotlb __read_mostly; 20 20 21 21 static struct dma_map_ops xen_swiotlb_dma_ops = { 22 - .mapping_error = xen_swiotlb_dma_mapping_error, 23 22 .alloc = xen_swiotlb_alloc_coherent, 24 23 .free = xen_swiotlb_free_coherent, 25 24 .sync_single_for_cpu = xen_swiotlb_sync_single_for_cpu,
+12 -15
drivers/xen/swiotlb-xen.c
··· 405 405 */ 406 406 trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force); 407 407 408 - map = swiotlb_tbl_map_single(dev, start_dma_addr, phys, size, dir); 408 + map = swiotlb_tbl_map_single(dev, start_dma_addr, phys, size, dir, 409 + attrs); 409 410 if (map == SWIOTLB_MAP_ERROR) 410 411 return DMA_ERROR_CODE; 411 412 ··· 417 416 /* 418 417 * Ensure that the address returned is DMA'ble 419 418 */ 420 - if (!dma_capable(dev, dev_addr, size)) { 421 - swiotlb_tbl_unmap_single(dev, map, size, dir); 422 - dev_addr = 0; 423 - } 424 - return dev_addr; 419 + if (dma_capable(dev, dev_addr, size)) 420 + return dev_addr; 421 + 422 + attrs |= DMA_ATTR_SKIP_CPU_SYNC; 423 + swiotlb_tbl_unmap_single(dev, map, size, dir, attrs); 424 + 425 + return DMA_ERROR_CODE; 425 426 } 426 427 EXPORT_SYMBOL_GPL(xen_swiotlb_map_page); 427 428 ··· 447 444 448 445 /* NOTE: We use dev_addr here, not paddr! */ 449 446 if (is_xen_swiotlb_buffer(dev_addr)) { 450 - swiotlb_tbl_unmap_single(hwdev, paddr, size, dir); 447 + swiotlb_tbl_unmap_single(hwdev, paddr, size, dir, attrs); 451 448 return; 452 449 } 453 450 ··· 560 557 start_dma_addr, 561 558 sg_phys(sg), 562 559 sg->length, 563 - dir); 560 + dir, attrs); 564 561 if (map == SWIOTLB_MAP_ERROR) { 565 562 dev_warn(hwdev, "swiotlb buffer is full\n"); 566 563 /* Don't panic here, we expect map_sg users 567 564 to do proper error handling. */ 565 + attrs |= DMA_ATTR_SKIP_CPU_SYNC; 568 566 xen_swiotlb_unmap_sg_attrs(hwdev, sgl, i, dir, 569 567 attrs); 570 568 sg_dma_len(sgl) = 0; ··· 651 647 xen_swiotlb_sync_sg(hwdev, sg, nelems, dir, SYNC_FOR_DEVICE); 652 648 } 653 649 EXPORT_SYMBOL_GPL(xen_swiotlb_sync_sg_for_device); 654 - 655 - int 656 - xen_swiotlb_dma_mapping_error(struct device *hwdev, dma_addr_t dma_addr) 657 - { 658 - return !dma_addr; 659 - } 660 - EXPORT_SYMBOL_GPL(xen_swiotlb_dma_mapping_error); 661 650 662 651 /* 663 652 * Return whether the given device DMA address mask can be supported
+4 -10
include/linux/swiotlb.h
··· 44 44 extern phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, 45 45 dma_addr_t tbl_dma_addr, 46 46 phys_addr_t phys, size_t size, 47 - enum dma_data_direction dir); 47 + enum dma_data_direction dir, 48 + unsigned long attrs); 48 49 49 50 extern void swiotlb_tbl_unmap_single(struct device *hwdev, 50 51 phys_addr_t tlb_addr, 51 - size_t size, enum dma_data_direction dir); 52 + size_t size, enum dma_data_direction dir, 53 + unsigned long attrs); 52 54 53 55 extern void swiotlb_tbl_sync_single(struct device *hwdev, 54 56 phys_addr_t tlb_addr, ··· 73 71 extern void swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr, 74 72 size_t size, enum dma_data_direction dir, 75 73 unsigned long attrs); 76 - 77 - extern int 78 - swiotlb_map_sg(struct device *hwdev, struct scatterlist *sg, int nents, 79 - enum dma_data_direction dir); 80 - 81 - extern void 82 - swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nents, 83 - enum dma_data_direction dir); 84 74 85 75 extern int 86 76 swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, int nelems,
-3
include/xen/swiotlb-xen.h
··· 51 51 int nelems, enum dma_data_direction dir); 52 52 53 53 extern int 54 - xen_swiotlb_dma_mapping_error(struct device *hwdev, dma_addr_t dma_addr); 55 - 56 - extern int 57 54 xen_swiotlb_dma_supported(struct device *hwdev, u64 mask); 58 55 59 56 extern int
+41 -40
lib/swiotlb.c
··· 425 425 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, 426 426 dma_addr_t tbl_dma_addr, 427 427 phys_addr_t orig_addr, size_t size, 428 - enum dma_data_direction dir) 428 + enum dma_data_direction dir, 429 + unsigned long attrs) 429 430 { 430 431 unsigned long flags; 431 432 phys_addr_t tlb_addr; ··· 527 526 */ 528 527 for (i = 0; i < nslots; i++) 529 528 io_tlb_orig_addr[index+i] = orig_addr + (i << IO_TLB_SHIFT); 530 - if (dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL) 529 + if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) && 530 + (dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL)) 531 531 swiotlb_bounce(orig_addr, tlb_addr, size, DMA_TO_DEVICE); 532 532 533 533 return tlb_addr; ··· 541 539 542 540 static phys_addr_t 543 541 map_single(struct device *hwdev, phys_addr_t phys, size_t size, 544 - enum dma_data_direction dir) 542 + enum dma_data_direction dir, unsigned long attrs) 545 543 { 546 544 dma_addr_t start_dma_addr = phys_to_dma(hwdev, io_tlb_start); 547 545 548 - return swiotlb_tbl_map_single(hwdev, start_dma_addr, phys, size, dir); 546 + return swiotlb_tbl_map_single(hwdev, start_dma_addr, phys, size, 547 + dir, attrs); 549 548 } 550 549 551 550 /* 552 551 * dma_addr is the kernel virtual address of the bounce buffer to unmap. 553 552 */ 554 553 void swiotlb_tbl_unmap_single(struct device *hwdev, phys_addr_t tlb_addr, 555 - size_t size, enum dma_data_direction dir) 554 + size_t size, enum dma_data_direction dir, 555 + unsigned long attrs) 556 556 { 557 557 unsigned long flags; 558 558 int i, count, nslots = ALIGN(size, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT; ··· 565 561 * First, sync the memory before unmapping the entry 566 562 */ 567 563 if (orig_addr != INVALID_PHYS_ADDR && 564 + !(attrs & DMA_ATTR_SKIP_CPU_SYNC) && 568 565 ((dir == DMA_FROM_DEVICE) || (dir == DMA_BIDIRECTIONAL))) 569 566 swiotlb_bounce(orig_addr, tlb_addr, size, DMA_FROM_DEVICE); 570 567 ··· 659 654 * GFP_DMA memory; fall back on map_single(), which 660 655 * will grab memory from the lowest available address range. 661 656 */ 662 - phys_addr_t paddr = map_single(hwdev, 0, size, DMA_FROM_DEVICE); 657 + phys_addr_t paddr = map_single(hwdev, 0, size, 658 + DMA_FROM_DEVICE, 0); 663 659 if (paddr == SWIOTLB_MAP_ERROR) 664 660 goto err_warn; 665 661 ··· 673 667 (unsigned long long)dma_mask, 674 668 (unsigned long long)dev_addr); 675 669 676 - /* DMA_TO_DEVICE to avoid memcpy in unmap_single */ 670 + /* 671 + * DMA_TO_DEVICE to avoid memcpy in unmap_single. 672 + * The DMA_ATTR_SKIP_CPU_SYNC is optional. 673 + */ 677 674 swiotlb_tbl_unmap_single(hwdev, paddr, 678 - size, DMA_TO_DEVICE); 675 + size, DMA_TO_DEVICE, 676 + DMA_ATTR_SKIP_CPU_SYNC); 679 677 goto err_warn; 680 678 } 681 679 } ··· 708 698 if (!is_swiotlb_buffer(paddr)) 709 699 free_pages((unsigned long)vaddr, get_order(size)); 710 700 else 711 - /* DMA_TO_DEVICE to avoid memcpy in swiotlb_tbl_unmap_single */ 712 - swiotlb_tbl_unmap_single(hwdev, paddr, size, DMA_TO_DEVICE); 701 + /* 702 + * DMA_TO_DEVICE to avoid memcpy in swiotlb_tbl_unmap_single. 703 + * DMA_ATTR_SKIP_CPU_SYNC is optional. 704 + */ 705 + swiotlb_tbl_unmap_single(hwdev, paddr, size, DMA_TO_DEVICE, 706 + DMA_ATTR_SKIP_CPU_SYNC); 713 707 } 714 708 EXPORT_SYMBOL(swiotlb_free_coherent); 715 709 ··· 728 714 * When the mapping is small enough return a static buffer to limit 729 715 * the damage, or panic when the transfer is too big. 730 716 */ 731 - printk(KERN_ERR "DMA: Out of SW-IOMMU space for %zu bytes at " 732 - "device %s\n", size, dev ? dev_name(dev) : "?"); 717 + dev_err_ratelimited(dev, "DMA: Out of SW-IOMMU space for %zu bytes\n", 718 + size); 733 719 734 720 if (size <= io_tlb_overflow || !do_panic) 735 721 return; ··· 769 755 trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force); 770 756 771 757 /* Oh well, have to allocate and map a bounce buffer. */ 772 - map = map_single(dev, phys, size, dir); 758 + map = map_single(dev, phys, size, dir, attrs); 773 759 if (map == SWIOTLB_MAP_ERROR) { 774 760 swiotlb_full(dev, size, dir, 1); 775 761 return phys_to_dma(dev, io_tlb_overflow_buffer); ··· 778 764 dev_addr = phys_to_dma(dev, map); 779 765 780 766 /* Ensure that the address returned is DMA'ble */ 781 - if (!dma_capable(dev, dev_addr, size)) { 782 - swiotlb_tbl_unmap_single(dev, map, size, dir); 783 - return phys_to_dma(dev, io_tlb_overflow_buffer); 784 - } 767 + if (dma_capable(dev, dev_addr, size)) 768 + return dev_addr; 785 769 786 - return dev_addr; 770 + attrs |= DMA_ATTR_SKIP_CPU_SYNC; 771 + swiotlb_tbl_unmap_single(dev, map, size, dir, attrs); 772 + 773 + return phys_to_dma(dev, io_tlb_overflow_buffer); 787 774 } 788 775 EXPORT_SYMBOL_GPL(swiotlb_map_page); 789 776 ··· 797 782 * whatever the device wrote there. 798 783 */ 799 784 static void unmap_single(struct device *hwdev, dma_addr_t dev_addr, 800 - size_t size, enum dma_data_direction dir) 785 + size_t size, enum dma_data_direction dir, 786 + unsigned long attrs) 801 787 { 802 788 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr); 803 789 804 790 BUG_ON(dir == DMA_NONE); 805 791 806 792 if (is_swiotlb_buffer(paddr)) { 807 - swiotlb_tbl_unmap_single(hwdev, paddr, size, dir); 793 + swiotlb_tbl_unmap_single(hwdev, paddr, size, dir, attrs); 808 794 return; 809 795 } 810 796 ··· 825 809 size_t size, enum dma_data_direction dir, 826 810 unsigned long attrs) 827 811 { 828 - unmap_single(hwdev, dev_addr, size, dir); 812 + unmap_single(hwdev, dev_addr, size, dir, attrs); 829 813 } 830 814 EXPORT_SYMBOL_GPL(swiotlb_unmap_page); 831 815 ··· 907 891 if (swiotlb_force || 908 892 !dma_capable(hwdev, dev_addr, sg->length)) { 909 893 phys_addr_t map = map_single(hwdev, sg_phys(sg), 910 - sg->length, dir); 894 + sg->length, dir, attrs); 911 895 if (map == SWIOTLB_MAP_ERROR) { 912 896 /* Don't panic here, we expect map_sg users 913 897 to do proper error handling. */ 914 898 swiotlb_full(hwdev, sg->length, dir, 0); 899 + attrs |= DMA_ATTR_SKIP_CPU_SYNC; 915 900 swiotlb_unmap_sg_attrs(hwdev, sgl, i, dir, 916 901 attrs); 917 902 sg_dma_len(sgl) = 0; ··· 926 909 return nelems; 927 910 } 928 911 EXPORT_SYMBOL(swiotlb_map_sg_attrs); 929 - 930 - int 931 - swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, 932 - enum dma_data_direction dir) 933 - { 934 - return swiotlb_map_sg_attrs(hwdev, sgl, nelems, dir, 0); 935 - } 936 - EXPORT_SYMBOL(swiotlb_map_sg); 937 912 938 913 /* 939 914 * Unmap a set of streaming mode DMA translations. Again, cpu read rules ··· 942 933 BUG_ON(dir == DMA_NONE); 943 934 944 935 for_each_sg(sgl, sg, nelems, i) 945 - unmap_single(hwdev, sg->dma_address, sg_dma_len(sg), dir); 946 - 936 + unmap_single(hwdev, sg->dma_address, sg_dma_len(sg), dir, 937 + attrs); 947 938 } 948 939 EXPORT_SYMBOL(swiotlb_unmap_sg_attrs); 949 - 950 - void 951 - swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sgl, int nelems, 952 - enum dma_data_direction dir) 953 - { 954 - return swiotlb_unmap_sg_attrs(hwdev, sgl, nelems, dir, 0); 955 - } 956 - EXPORT_SYMBOL(swiotlb_unmap_sg); 957 940 958 941 /* 959 942 * Make physical memory consistent for a set of streaming mode DMA translations