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

Merge tag 'iommu-updates-v5.16' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu

Pull iommu updates from Joerg Roedel:

- Intel IOMMU Updates fro Lu Baolu:
- Dump DMAR translation structure when DMA fault occurs
- An optimization in the page table manipulation code
- Use second level for GPA->HPA translation
- Various cleanups

- Arm SMMU Updates from Will
- Minor optimisations to SMMUv3 command creation and submission
- Numerous new compatible string for Qualcomm SMMUv2 implementations

- Fixes for the SWIOTLB based implemenation of dma-iommu code for
untrusted devices

- Add support for r8a779a0 to the Renesas IOMMU driver and DT matching
code for r8a77980

- A couple of cleanups and fixes for the Apple DART IOMMU driver

- Make use of generic report_iommu_fault() interface in the AMD IOMMU
driver

- Various smaller fixes and cleanups

* tag 'iommu-updates-v5.16' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu: (35 commits)
iommu/dma: Fix incorrect error return on iommu deferred attach
iommu/dart: Initialize DART_STREAMS_ENABLE
iommu/dma: Use kvcalloc() instead of kvzalloc()
iommu/tegra-smmu: Use devm_bitmap_zalloc when applicable
iommu/dart: Use kmemdup instead of kzalloc and memcpy
iommu/vt-d: Avoid duplicate removing in __domain_mapping()
iommu/vt-d: Convert the return type of first_pte_in_page to bool
iommu/vt-d: Clean up unused PASID updating functions
iommu/vt-d: Delete dev_has_feat callback
iommu/vt-d: Use second level for GPA->HPA translation
iommu/vt-d: Check FL and SL capability sanity in scalable mode
iommu/vt-d: Remove duplicate identity domain flag
iommu/vt-d: Dump DMAR translation structure when DMA fault occurs
iommu/vt-d: Do not falsely log intel_iommu is unsupported kernel option
iommu/arm-smmu-qcom: Request direct mapping for modem device
iommu: arm-smmu-qcom: Add compatible for QCM2290
dt-bindings: arm-smmu: Add compatible for QCM2290 SoC
iommu/arm-smmu-qcom: Add SM6350 SMMU compatible
dt-bindings: arm-smmu: Add compatible for SM6350 SoC
iommu/arm-smmu-v3: Properly handle the return value of arm_smmu_cmdq_build_cmd()
...

+367 -243
+2
Documentation/devicetree/bindings/iommu/arm,smmu.yaml
··· 33 33 - description: Qcom SoCs implementing "arm,mmu-500" 34 34 items: 35 35 - enum: 36 + - qcom,qcm2290-smmu-500 36 37 - qcom,sc7180-smmu-500 37 38 - qcom,sc7280-smmu-500 38 39 - qcom,sc8180x-smmu-500 39 40 - qcom,sdm845-smmu-500 41 + - qcom,sm6350-smmu-500 40 42 - qcom,sm8150-smmu-500 41 43 - qcom,sm8250-smmu-500 42 44 - qcom,sm8350-smmu-500
+1
Documentation/devicetree/bindings/iommu/renesas,ipmmu-vmsa.yaml
··· 43 43 - renesas,ipmmu-r8a77980 # R-Car V3H 44 44 - renesas,ipmmu-r8a77990 # R-Car E3 45 45 - renesas,ipmmu-r8a77995 # R-Car D3 46 + - renesas,ipmmu-r8a779a0 # R-Car V3U 46 47 47 48 reg: 48 49 maxItems: 1
-2
arch/x86/include/asm/fpu/api.h
··· 108 108 */ 109 109 #define PASID_DISABLED 0 110 110 111 - static inline void update_pasid(void) { } 112 - 113 111 /* Trap handling */ 114 112 extern int fpu__exception_code(struct fpu *fpu, int trap_nr); 115 113 extern void fpu_sync_fpstate(struct fpu *fpu);
+2
drivers/iommu/amd/amd_iommu_types.h
··· 138 138 #define EVENT_DOMID_MASK_HI 0xf0000 139 139 #define EVENT_FLAGS_MASK 0xfff 140 140 #define EVENT_FLAGS_SHIFT 0x10 141 + #define EVENT_FLAG_RW 0x020 142 + #define EVENT_FLAG_I 0x008 141 143 142 144 /* feature control bits */ 143 145 #define CONTROL_IOMMU_EN 0x00ULL
+21
drivers/iommu/amd/iommu.c
··· 474 474 pci_dev_put(pdev); 475 475 } 476 476 477 + #define IS_IOMMU_MEM_TRANSACTION(flags) \ 478 + (((flags) & EVENT_FLAG_I) == 0) 479 + 480 + #define IS_WRITE_REQUEST(flags) \ 481 + ((flags) & EVENT_FLAG_RW) 482 + 477 483 static void amd_iommu_report_page_fault(u16 devid, u16 domain_id, 478 484 u64 address, int flags) 479 485 { ··· 492 486 dev_data = dev_iommu_priv_get(&pdev->dev); 493 487 494 488 if (dev_data) { 489 + /* 490 + * If this is a DMA fault (for which the I(nterrupt) 491 + * bit will be unset), allow report_iommu_fault() to 492 + * prevent logging it. 493 + */ 494 + if (IS_IOMMU_MEM_TRANSACTION(flags)) { 495 + if (!report_iommu_fault(&dev_data->domain->domain, 496 + &pdev->dev, address, 497 + IS_WRITE_REQUEST(flags) ? 498 + IOMMU_FAULT_WRITE : 499 + IOMMU_FAULT_READ)) 500 + goto out; 501 + } 502 + 495 503 if (__ratelimit(&dev_data->rs)) { 496 504 pci_err(pdev, "Event logged [IO_PAGE_FAULT domain=0x%04x address=0x%llx flags=0x%04x]\n", 497 505 domain_id, address, flags); ··· 516 496 domain_id, address, flags); 517 497 } 518 498 499 + out: 519 500 if (pdev) 520 501 pci_dev_put(pdev); 521 502 }
+6 -4
drivers/iommu/apple-dart.c
··· 15 15 #include <linux/bitfield.h> 16 16 #include <linux/clk.h> 17 17 #include <linux/dev_printk.h> 18 - #include <linux/dma-iommu.h> 19 18 #include <linux/dma-mapping.h> 20 19 #include <linux/err.h> 21 20 #include <linux/interrupt.h> ··· 68 69 69 70 #define DART_ERROR_ADDR_HI 0x54 70 71 #define DART_ERROR_ADDR_LO 0x50 72 + 73 + #define DART_STREAMS_ENABLE 0xfc 71 74 72 75 #define DART_TCR(sid) (0x100 + 4 * (sid)) 73 76 #define DART_TCR_TRANSLATE_ENABLE BIT(7) ··· 301 300 stream_map.sidmap = DART_STREAM_ALL; 302 301 apple_dart_hw_disable_dma(&stream_map); 303 302 apple_dart_hw_clear_all_ttbrs(&stream_map); 303 + 304 + /* enable all streams globally since TCR is used to control isolation */ 305 + writel(DART_STREAM_ALL, dart->regs + DART_STREAMS_ENABLE); 304 306 305 307 /* clear any pending errors before the interrupt is unmasked */ 306 308 writel(readl(dart->regs + DART_ERROR), dart->regs + DART_ERROR); ··· 582 578 if (!dart_domain) 583 579 return NULL; 584 580 585 - iommu_get_dma_cookie(&dart_domain->domain); 586 581 mutex_init(&dart_domain->init_lock); 587 582 588 583 /* no need to allocate pgtbl_ops or do any other finalization steps */ ··· 705 702 if (!group) 706 703 goto out; 707 704 708 - group_master_cfg = kzalloc(sizeof(*group_master_cfg), GFP_KERNEL); 705 + group_master_cfg = kmemdup(cfg, sizeof(*group_master_cfg), GFP_KERNEL); 709 706 if (!group_master_cfg) { 710 707 iommu_group_put(group); 711 708 goto out; 712 709 } 713 710 714 - memcpy(group_master_cfg, cfg, sizeof(*group_master_cfg)); 715 711 iommu_group_set_iommudata(group, group_master_cfg, 716 712 apple_dart_release_group); 717 713
+14 -7
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
··· 409 409 dev_err(smmu->dev, "\t0x%016llx\n", (unsigned long long)cmd[i]); 410 410 411 411 /* Convert the erroneous command into a CMD_SYNC */ 412 - if (arm_smmu_cmdq_build_cmd(cmd, &cmd_sync)) { 413 - dev_err(smmu->dev, "failed to convert to CMD_SYNC\n"); 414 - return; 415 - } 412 + arm_smmu_cmdq_build_cmd(cmd, &cmd_sync); 416 413 417 414 queue_write(Q_ENT(q, cons), cmd, q->ent_dwords); 418 415 } ··· 857 860 { 858 861 u64 cmd[CMDQ_ENT_DWORDS]; 859 862 860 - if (arm_smmu_cmdq_build_cmd(cmd, ent)) { 863 + if (unlikely(arm_smmu_cmdq_build_cmd(cmd, ent))) { 861 864 dev_warn(smmu->dev, "ignoring unknown CMDQ opcode 0x%x\n", 862 865 ent->opcode); 863 866 return -EINVAL; ··· 882 885 struct arm_smmu_cmdq_batch *cmds, 883 886 struct arm_smmu_cmdq_ent *cmd) 884 887 { 888 + int index; 889 + 885 890 if (cmds->num == CMDQ_BATCH_ENTRIES) { 886 891 arm_smmu_cmdq_issue_cmdlist(smmu, cmds->cmds, cmds->num, false); 887 892 cmds->num = 0; 888 893 } 889 - arm_smmu_cmdq_build_cmd(&cmds->cmds[cmds->num * CMDQ_ENT_DWORDS], cmd); 894 + 895 + index = cmds->num * CMDQ_ENT_DWORDS; 896 + if (unlikely(arm_smmu_cmdq_build_cmd(&cmds->cmds[index], cmd))) { 897 + dev_warn(smmu->dev, "ignoring unknown CMDQ opcode 0x%x\n", 898 + cmd->opcode); 899 + return; 900 + } 901 + 890 902 cmds->num++; 891 903 } 892 904 ··· 1770 1764 { 1771 1765 int i; 1772 1766 struct arm_smmu_cmdq_ent cmd; 1773 - struct arm_smmu_cmdq_batch cmds = {}; 1767 + struct arm_smmu_cmdq_batch cmds; 1774 1768 1775 1769 arm_smmu_atc_inv_to_cmd(0, 0, 0, &cmd); 1776 1770 1771 + cmds.num = 0; 1777 1772 for (i = 0; i < master->num_streams; i++) { 1778 1773 cmd.atc.sid = master->streams[i].id; 1779 1774 arm_smmu_cmdq_batch_add(master->smmu, &cmds, &cmd);
+3
drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c
··· 231 231 { .compatible = "qcom,sc7180-mdss" }, 232 232 { .compatible = "qcom,sc7180-mss-pil" }, 233 233 { .compatible = "qcom,sc7280-mdss" }, 234 + { .compatible = "qcom,sc7280-mss-pil" }, 234 235 { .compatible = "qcom,sc8180x-mdss" }, 235 236 { .compatible = "qcom,sdm845-mdss" }, 236 237 { .compatible = "qcom,sdm845-mss-pil" }, ··· 404 403 405 404 static const struct of_device_id __maybe_unused qcom_smmu_impl_of_match[] = { 406 405 { .compatible = "qcom,msm8998-smmu-v2" }, 406 + { .compatible = "qcom,qcm2290-smmu-500" }, 407 407 { .compatible = "qcom,sc7180-smmu-500" }, 408 408 { .compatible = "qcom,sc7280-smmu-500" }, 409 409 { .compatible = "qcom,sc8180x-smmu-500" }, 410 410 { .compatible = "qcom,sdm630-smmu-v2" }, 411 411 { .compatible = "qcom,sdm845-smmu-500" }, 412 412 { .compatible = "qcom,sm6125-smmu-500" }, 413 + { .compatible = "qcom,sm6350-smmu-500" }, 413 414 { .compatible = "qcom,sm8150-smmu-500" }, 414 415 { .compatible = "qcom,sm8250-smmu-500" }, 415 416 { .compatible = "qcom,sm8350-smmu-500" },
+86 -114
drivers/iommu/dma-iommu.c
··· 98 98 /** 99 99 * iommu_get_dma_cookie - Acquire DMA-API resources for a domain 100 100 * @domain: IOMMU domain to prepare for DMA-API usage 101 - * 102 - * IOMMU drivers should normally call this from their domain_alloc 103 - * callback when domain->type == IOMMU_DOMAIN_DMA. 104 101 */ 105 102 int iommu_get_dma_cookie(struct iommu_domain *domain) 106 103 { ··· 110 113 111 114 return 0; 112 115 } 113 - EXPORT_SYMBOL(iommu_get_dma_cookie); 114 116 115 117 /** 116 118 * iommu_get_msi_cookie - Acquire just MSI remapping resources ··· 147 151 * iommu_put_dma_cookie - Release a domain's DMA mapping resources 148 152 * @domain: IOMMU domain previously prepared by iommu_get_dma_cookie() or 149 153 * iommu_get_msi_cookie() 150 - * 151 - * IOMMU drivers should normally call this from their domain_free callback. 152 154 */ 153 155 void iommu_put_dma_cookie(struct iommu_domain *domain) 154 156 { ··· 166 172 kfree(cookie); 167 173 domain->iova_cookie = NULL; 168 174 } 169 - EXPORT_SYMBOL(iommu_put_dma_cookie); 170 175 171 176 /** 172 177 * iommu_dma_get_resv_regions - Reserved region driver helper ··· 308 315 static bool dev_is_untrusted(struct device *dev) 309 316 { 310 317 return dev_is_pci(dev) && to_pci_dev(dev)->untrusted; 318 + } 319 + 320 + static bool dev_use_swiotlb(struct device *dev) 321 + { 322 + return IS_ENABLED(CONFIG_SWIOTLB) && dev_is_untrusted(dev); 311 323 } 312 324 313 325 /* sysfs updates are serialised by the mutex of the group owning @domain */ ··· 508 510 iommu_dma_free_iova(cookie, dma_addr, size, &iotlb_gather); 509 511 } 510 512 511 - static void __iommu_dma_unmap_swiotlb(struct device *dev, dma_addr_t dma_addr, 512 - size_t size, enum dma_data_direction dir, 513 - unsigned long attrs) 514 - { 515 - struct iommu_domain *domain = iommu_get_dma_domain(dev); 516 - phys_addr_t phys; 517 - 518 - phys = iommu_iova_to_phys(domain, dma_addr); 519 - if (WARN_ON(!phys)) 520 - return; 521 - 522 - __iommu_dma_unmap(dev, dma_addr, size); 523 - 524 - if (unlikely(is_swiotlb_buffer(dev, phys))) 525 - swiotlb_tbl_unmap_single(dev, phys, size, dir, attrs); 526 - } 527 - 528 513 static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys, 529 514 size_t size, int prot, u64 dma_mask) 530 515 { ··· 534 553 return iova + iova_off; 535 554 } 536 555 537 - static dma_addr_t __iommu_dma_map_swiotlb(struct device *dev, phys_addr_t phys, 538 - size_t org_size, dma_addr_t dma_mask, bool coherent, 539 - enum dma_data_direction dir, unsigned long attrs) 540 - { 541 - int prot = dma_info_to_prot(dir, coherent, attrs); 542 - struct iommu_domain *domain = iommu_get_dma_domain(dev); 543 - struct iommu_dma_cookie *cookie = domain->iova_cookie; 544 - struct iova_domain *iovad = &cookie->iovad; 545 - size_t aligned_size = org_size; 546 - void *padding_start; 547 - size_t padding_size; 548 - dma_addr_t iova; 549 - 550 - /* 551 - * If both the physical buffer start address and size are 552 - * page aligned, we don't need to use a bounce page. 553 - */ 554 - if (IS_ENABLED(CONFIG_SWIOTLB) && dev_is_untrusted(dev) && 555 - iova_offset(iovad, phys | org_size)) { 556 - aligned_size = iova_align(iovad, org_size); 557 - phys = swiotlb_tbl_map_single(dev, phys, org_size, 558 - aligned_size, dir, attrs); 559 - 560 - if (phys == DMA_MAPPING_ERROR) 561 - return DMA_MAPPING_ERROR; 562 - 563 - /* Cleanup the padding area. */ 564 - padding_start = phys_to_virt(phys); 565 - padding_size = aligned_size; 566 - 567 - if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) && 568 - (dir == DMA_TO_DEVICE || 569 - dir == DMA_BIDIRECTIONAL)) { 570 - padding_start += org_size; 571 - padding_size -= org_size; 572 - } 573 - 574 - memset(padding_start, 0, padding_size); 575 - } 576 - 577 - iova = __iommu_dma_map(dev, phys, aligned_size, prot, dma_mask); 578 - if (iova == DMA_MAPPING_ERROR && is_swiotlb_buffer(dev, phys)) 579 - swiotlb_tbl_unmap_single(dev, phys, org_size, dir, attrs); 580 - return iova; 581 - } 582 - 583 556 static void __iommu_dma_free_pages(struct page **pages, int count) 584 557 { 585 558 while (count--) ··· 551 616 if (!order_mask) 552 617 return NULL; 553 618 554 - pages = kvzalloc(count * sizeof(*pages), GFP_KERNEL); 619 + pages = kvcalloc(count, sizeof(*pages), GFP_KERNEL); 555 620 if (!pages) 556 621 return NULL; 557 622 ··· 729 794 { 730 795 phys_addr_t phys; 731 796 732 - if (dev_is_dma_coherent(dev) && !dev_is_untrusted(dev)) 797 + if (dev_is_dma_coherent(dev) && !dev_use_swiotlb(dev)) 733 798 return; 734 799 735 800 phys = iommu_iova_to_phys(iommu_get_dma_domain(dev), dma_handle); ··· 745 810 { 746 811 phys_addr_t phys; 747 812 748 - if (dev_is_dma_coherent(dev) && !dev_is_untrusted(dev)) 813 + if (dev_is_dma_coherent(dev) && !dev_use_swiotlb(dev)) 749 814 return; 750 815 751 816 phys = iommu_iova_to_phys(iommu_get_dma_domain(dev), dma_handle); ··· 763 828 struct scatterlist *sg; 764 829 int i; 765 830 766 - if (dev_is_dma_coherent(dev) && !dev_is_untrusted(dev)) 767 - return; 768 - 769 - for_each_sg(sgl, sg, nelems, i) { 770 - if (!dev_is_dma_coherent(dev)) 831 + if (dev_use_swiotlb(dev)) 832 + for_each_sg(sgl, sg, nelems, i) 833 + iommu_dma_sync_single_for_cpu(dev, sg_dma_address(sg), 834 + sg->length, dir); 835 + else if (!dev_is_dma_coherent(dev)) 836 + for_each_sg(sgl, sg, nelems, i) 771 837 arch_sync_dma_for_cpu(sg_phys(sg), sg->length, dir); 772 - 773 - if (is_swiotlb_buffer(dev, sg_phys(sg))) 774 - swiotlb_sync_single_for_cpu(dev, sg_phys(sg), 775 - sg->length, dir); 776 - } 777 838 } 778 839 779 840 static void iommu_dma_sync_sg_for_device(struct device *dev, ··· 779 848 struct scatterlist *sg; 780 849 int i; 781 850 782 - if (dev_is_dma_coherent(dev) && !dev_is_untrusted(dev)) 783 - return; 784 - 785 - for_each_sg(sgl, sg, nelems, i) { 786 - if (is_swiotlb_buffer(dev, sg_phys(sg))) 787 - swiotlb_sync_single_for_device(dev, sg_phys(sg), 788 - sg->length, dir); 789 - 790 - if (!dev_is_dma_coherent(dev)) 851 + if (dev_use_swiotlb(dev)) 852 + for_each_sg(sgl, sg, nelems, i) 853 + iommu_dma_sync_single_for_device(dev, 854 + sg_dma_address(sg), 855 + sg->length, dir); 856 + else if (!dev_is_dma_coherent(dev)) 857 + for_each_sg(sgl, sg, nelems, i) 791 858 arch_sync_dma_for_device(sg_phys(sg), sg->length, dir); 792 - } 793 859 } 794 860 795 861 static dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page, ··· 795 867 { 796 868 phys_addr_t phys = page_to_phys(page) + offset; 797 869 bool coherent = dev_is_dma_coherent(dev); 798 - dma_addr_t dma_handle; 870 + int prot = dma_info_to_prot(dir, coherent, attrs); 871 + struct iommu_domain *domain = iommu_get_dma_domain(dev); 872 + struct iommu_dma_cookie *cookie = domain->iova_cookie; 873 + struct iova_domain *iovad = &cookie->iovad; 874 + dma_addr_t iova, dma_mask = dma_get_mask(dev); 799 875 800 - dma_handle = __iommu_dma_map_swiotlb(dev, phys, size, dma_get_mask(dev), 801 - coherent, dir, attrs); 802 - if (!coherent && !(attrs & DMA_ATTR_SKIP_CPU_SYNC) && 803 - dma_handle != DMA_MAPPING_ERROR) 876 + /* 877 + * If both the physical buffer start address and size are 878 + * page aligned, we don't need to use a bounce page. 879 + */ 880 + if (dev_use_swiotlb(dev) && iova_offset(iovad, phys | size)) { 881 + void *padding_start; 882 + size_t padding_size, aligned_size; 883 + 884 + aligned_size = iova_align(iovad, size); 885 + phys = swiotlb_tbl_map_single(dev, phys, size, aligned_size, 886 + iova_mask(iovad), dir, attrs); 887 + 888 + if (phys == DMA_MAPPING_ERROR) 889 + return DMA_MAPPING_ERROR; 890 + 891 + /* Cleanup the padding area. */ 892 + padding_start = phys_to_virt(phys); 893 + padding_size = aligned_size; 894 + 895 + if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) && 896 + (dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL)) { 897 + padding_start += size; 898 + padding_size -= size; 899 + } 900 + 901 + memset(padding_start, 0, padding_size); 902 + } 903 + 904 + if (!coherent && !(attrs & DMA_ATTR_SKIP_CPU_SYNC)) 804 905 arch_sync_dma_for_device(phys, size, dir); 805 - return dma_handle; 906 + 907 + iova = __iommu_dma_map(dev, phys, size, prot, dma_mask); 908 + if (iova == DMA_MAPPING_ERROR && is_swiotlb_buffer(dev, phys)) 909 + swiotlb_tbl_unmap_single(dev, phys, size, dir, attrs); 910 + return iova; 806 911 } 807 912 808 913 static void iommu_dma_unmap_page(struct device *dev, dma_addr_t dma_handle, 809 914 size_t size, enum dma_data_direction dir, unsigned long attrs) 810 915 { 811 - if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC)) 812 - iommu_dma_sync_single_for_cpu(dev, dma_handle, size, dir); 813 - __iommu_dma_unmap_swiotlb(dev, dma_handle, size, dir, attrs); 916 + struct iommu_domain *domain = iommu_get_dma_domain(dev); 917 + phys_addr_t phys; 918 + 919 + phys = iommu_iova_to_phys(domain, dma_handle); 920 + if (WARN_ON(!phys)) 921 + return; 922 + 923 + if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC) && !dev_is_dma_coherent(dev)) 924 + arch_sync_dma_for_cpu(phys, size, dir); 925 + 926 + __iommu_dma_unmap(dev, dma_handle, size); 927 + 928 + if (unlikely(is_swiotlb_buffer(dev, phys))) 929 + swiotlb_tbl_unmap_single(dev, phys, size, dir, attrs); 814 930 } 815 931 816 932 /* ··· 939 967 int i; 940 968 941 969 for_each_sg(sg, s, nents, i) 942 - __iommu_dma_unmap_swiotlb(dev, sg_dma_address(s), 970 + iommu_dma_unmap_page(dev, sg_dma_address(s), 943 971 sg_dma_len(s), dir, attrs); 944 972 } 945 973 ··· 950 978 int i; 951 979 952 980 for_each_sg(sg, s, nents, i) { 953 - sg_dma_address(s) = __iommu_dma_map_swiotlb(dev, sg_phys(s), 954 - s->length, dma_get_mask(dev), 955 - dev_is_dma_coherent(dev), dir, attrs); 981 + sg_dma_address(s) = iommu_dma_map_page(dev, sg_page(s), 982 + s->offset, s->length, dir, attrs); 956 983 if (sg_dma_address(s) == DMA_MAPPING_ERROR) 957 984 goto out_unmap; 958 985 sg_dma_len(s) = s->length; ··· 987 1016 988 1017 if (static_branch_unlikely(&iommu_deferred_attach_enabled)) { 989 1018 ret = iommu_deferred_attach(dev, domain); 990 - goto out; 1019 + if (ret) 1020 + goto out; 991 1021 } 1022 + 1023 + if (dev_use_swiotlb(dev)) 1024 + return iommu_dma_map_sg_swiotlb(dev, sg, nents, dir, attrs); 992 1025 993 1026 if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC)) 994 1027 iommu_dma_sync_sg_for_device(dev, sg, nents, dir); 995 - 996 - if (dev_is_untrusted(dev)) 997 - return iommu_dma_map_sg_swiotlb(dev, sg, nents, dir, attrs); 998 1028 999 1029 /* 1000 1030 * Work out how much IOVA space we need, and align the segments to ··· 1069 1097 struct scatterlist *tmp; 1070 1098 int i; 1071 1099 1072 - if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC)) 1073 - iommu_dma_sync_sg_for_cpu(dev, sg, nents, dir); 1074 - 1075 - if (dev_is_untrusted(dev)) { 1100 + if (dev_use_swiotlb(dev)) { 1076 1101 iommu_dma_unmap_sg_swiotlb(dev, sg, nents, dir, attrs); 1077 1102 return; 1078 1103 } 1104 + 1105 + if (!(attrs & DMA_ATTR_SKIP_CPU_SYNC)) 1106 + iommu_dma_sync_sg_for_cpu(dev, sg, nents, dir); 1079 1107 1080 1108 /* 1081 1109 * The scatterlist segments are mapped into a single
+4
drivers/iommu/intel/Kconfig
··· 6 6 config DMAR_PERF 7 7 bool 8 8 9 + config DMAR_DEBUG 10 + bool 11 + 9 12 config INTEL_IOMMU 10 13 bool "Support for Intel IOMMU using DMA Remapping Devices" 11 14 depends on PCI_MSI && ACPI && (X86 || IA64) ··· 34 31 bool "Export Intel IOMMU internals in Debugfs" 35 32 depends on IOMMU_DEBUGFS 36 33 select DMAR_PERF 34 + select DMAR_DEBUG 37 35 help 38 36 !!!WARNING!!! 39 37
+13
drivers/iommu/intel/cap_audit.c
··· 163 163 check_irq_capabilities(iommu, i); 164 164 } 165 165 166 + /* 167 + * If the system is sane to support scalable mode, either SL or FL 168 + * should be sane. 169 + */ 170 + if (intel_cap_smts_sanity() && 171 + !intel_cap_flts_sanity() && !intel_cap_slts_sanity()) 172 + return -EOPNOTSUPP; 173 + 166 174 out: 167 175 rcu_read_unlock(); 168 176 return 0; ··· 210 202 bool intel_cap_flts_sanity(void) 211 203 { 212 204 return ecap_flts(intel_iommu_ecap_sanity); 205 + } 206 + 207 + bool intel_cap_slts_sanity(void) 208 + { 209 + return ecap_slts(intel_iommu_ecap_sanity); 213 210 }
+1
drivers/iommu/intel/cap_audit.h
··· 111 111 bool intel_cap_pasid_sanity(void); 112 112 bool intel_cap_nest_sanity(void); 113 113 bool intel_cap_flts_sanity(void); 114 + bool intel_cap_slts_sanity(void); 114 115 115 116 static inline bool scalable_mode_support(void) 116 117 {
+8 -2
drivers/iommu/intel/dmar.c
··· 1941 1941 1942 1942 reason = dmar_get_fault_reason(fault_reason, &fault_type); 1943 1943 1944 - if (fault_type == INTR_REMAP) 1944 + if (fault_type == INTR_REMAP) { 1945 1945 pr_err("[INTR-REMAP] Request device [%02x:%02x.%d] fault index 0x%llx [fault reason 0x%02x] %s\n", 1946 1946 source_id >> 8, PCI_SLOT(source_id & 0xFF), 1947 1947 PCI_FUNC(source_id & 0xFF), addr >> 48, 1948 1948 fault_reason, reason); 1949 - else if (pasid == INVALID_IOASID) 1949 + 1950 + return 0; 1951 + } 1952 + 1953 + if (pasid == INVALID_IOASID) 1950 1954 pr_err("[%s NO_PASID] Request device [%02x:%02x.%d] fault addr 0x%llx [fault reason 0x%02x] %s\n", 1951 1955 type ? "DMA Read" : "DMA Write", 1952 1956 source_id >> 8, PCI_SLOT(source_id & 0xFF), ··· 1962 1958 source_id >> 8, PCI_SLOT(source_id & 0xFF), 1963 1959 PCI_FUNC(source_id & 0xFF), addr, 1964 1960 fault_reason, reason); 1961 + 1962 + dmar_fault_dump_ptes(iommu, source_id, addr, pasid); 1965 1963 1966 1964 return 0; 1967 1965 }
+145 -68
drivers/iommu/intel/iommu.c
··· 156 156 157 157 static void __init check_tylersburg_isoch(void); 158 158 static int rwbf_quirk; 159 + static inline struct device_domain_info * 160 + dmar_search_domain_by_dev_info(int segment, int bus, int devfn); 159 161 160 162 /* 161 163 * set to 1 to panic kernel if can't successfully enable VT-d ··· 414 412 { 415 413 if (!str) 416 414 return -EINVAL; 415 + 417 416 while (*str) { 418 417 if (!strncmp(str, "on", 2)) { 419 418 dmar_disabled = 0; ··· 444 441 } else if (!strncmp(str, "tboot_noforce", 13)) { 445 442 pr_info("Intel-IOMMU: not forcing on after tboot. This could expose security risk for tboot\n"); 446 443 intel_iommu_tboot_noforce = 1; 444 + } else { 445 + pr_notice("Unknown option - '%s'\n", str); 447 446 } 448 447 449 448 str += strcspn(str, ","); 450 449 while (*str == ',') 451 450 str++; 452 451 } 453 - return 0; 452 + 453 + return 1; 454 454 } 455 455 __setup("intel_iommu=", intel_iommu_setup); 456 456 ··· 528 522 529 523 static inline int domain_type_is_si(struct dmar_domain *domain) 530 524 { 531 - return domain->flags & DOMAIN_FLAG_STATIC_IDENTITY; 525 + return domain->domain.type == IOMMU_DOMAIN_IDENTITY; 532 526 } 533 527 534 528 static inline bool domain_use_first_level(struct dmar_domain *domain) ··· 997 991 out: 998 992 spin_unlock_irqrestore(&iommu->lock, flags); 999 993 } 994 + 995 + #ifdef CONFIG_DMAR_DEBUG 996 + static void pgtable_walk(struct intel_iommu *iommu, unsigned long pfn, u8 bus, u8 devfn) 997 + { 998 + struct device_domain_info *info; 999 + struct dma_pte *parent, *pte; 1000 + struct dmar_domain *domain; 1001 + int offset, level; 1002 + 1003 + info = dmar_search_domain_by_dev_info(iommu->segment, bus, devfn); 1004 + if (!info || !info->domain) { 1005 + pr_info("device [%02x:%02x.%d] not probed\n", 1006 + bus, PCI_SLOT(devfn), PCI_FUNC(devfn)); 1007 + return; 1008 + } 1009 + 1010 + domain = info->domain; 1011 + level = agaw_to_level(domain->agaw); 1012 + parent = domain->pgd; 1013 + if (!parent) { 1014 + pr_info("no page table setup\n"); 1015 + return; 1016 + } 1017 + 1018 + while (1) { 1019 + offset = pfn_level_offset(pfn, level); 1020 + pte = &parent[offset]; 1021 + if (!pte || (dma_pte_superpage(pte) || !dma_pte_present(pte))) { 1022 + pr_info("PTE not present at level %d\n", level); 1023 + break; 1024 + } 1025 + 1026 + pr_info("pte level: %d, pte value: 0x%016llx\n", level, pte->val); 1027 + 1028 + if (level == 1) 1029 + break; 1030 + 1031 + parent = phys_to_virt(dma_pte_addr(pte)); 1032 + level--; 1033 + } 1034 + } 1035 + 1036 + void dmar_fault_dump_ptes(struct intel_iommu *iommu, u16 source_id, 1037 + unsigned long long addr, u32 pasid) 1038 + { 1039 + struct pasid_dir_entry *dir, *pde; 1040 + struct pasid_entry *entries, *pte; 1041 + struct context_entry *ctx_entry; 1042 + struct root_entry *rt_entry; 1043 + u8 devfn = source_id & 0xff; 1044 + u8 bus = source_id >> 8; 1045 + int i, dir_index, index; 1046 + 1047 + pr_info("Dump %s table entries for IOVA 0x%llx\n", iommu->name, addr); 1048 + 1049 + /* root entry dump */ 1050 + rt_entry = &iommu->root_entry[bus]; 1051 + if (!rt_entry) { 1052 + pr_info("root table entry is not present\n"); 1053 + return; 1054 + } 1055 + 1056 + if (sm_supported(iommu)) 1057 + pr_info("scalable mode root entry: hi 0x%016llx, low 0x%016llx\n", 1058 + rt_entry->hi, rt_entry->lo); 1059 + else 1060 + pr_info("root entry: 0x%016llx", rt_entry->lo); 1061 + 1062 + /* context entry dump */ 1063 + ctx_entry = iommu_context_addr(iommu, bus, devfn, 0); 1064 + if (!ctx_entry) { 1065 + pr_info("context table entry is not present\n"); 1066 + return; 1067 + } 1068 + 1069 + pr_info("context entry: hi 0x%016llx, low 0x%016llx\n", 1070 + ctx_entry->hi, ctx_entry->lo); 1071 + 1072 + /* legacy mode does not require PASID entries */ 1073 + if (!sm_supported(iommu)) 1074 + goto pgtable_walk; 1075 + 1076 + /* get the pointer to pasid directory entry */ 1077 + dir = phys_to_virt(ctx_entry->lo & VTD_PAGE_MASK); 1078 + if (!dir) { 1079 + pr_info("pasid directory entry is not present\n"); 1080 + return; 1081 + } 1082 + /* For request-without-pasid, get the pasid from context entry */ 1083 + if (intel_iommu_sm && pasid == INVALID_IOASID) 1084 + pasid = PASID_RID2PASID; 1085 + 1086 + dir_index = pasid >> PASID_PDE_SHIFT; 1087 + pde = &dir[dir_index]; 1088 + pr_info("pasid dir entry: 0x%016llx\n", pde->val); 1089 + 1090 + /* get the pointer to the pasid table entry */ 1091 + entries = get_pasid_table_from_pde(pde); 1092 + if (!entries) { 1093 + pr_info("pasid table entry is not present\n"); 1094 + return; 1095 + } 1096 + index = pasid & PASID_PTE_MASK; 1097 + pte = &entries[index]; 1098 + for (i = 0; i < ARRAY_SIZE(pte->val); i++) 1099 + pr_info("pasid table entry[%d]: 0x%016llx\n", i, pte->val[i]); 1100 + 1101 + pgtable_walk: 1102 + pgtable_walk(iommu, addr >> VTD_PAGE_SHIFT, bus, devfn); 1103 + } 1104 + #endif 1000 1105 1001 1106 static struct dma_pte *pfn_to_dma_pte(struct dmar_domain *domain, 1002 1107 unsigned long pfn, int *target_level) ··· 1991 1874 * Check and return whether first level is used by default for 1992 1875 * DMA translation. 1993 1876 */ 1994 - static bool first_level_by_default(void) 1877 + static bool first_level_by_default(unsigned int type) 1995 1878 { 1996 - return scalable_mode_support() && intel_cap_flts_sanity(); 1879 + /* Only SL is available in legacy mode */ 1880 + if (!scalable_mode_support()) 1881 + return false; 1882 + 1883 + /* Only level (either FL or SL) is available, just use it */ 1884 + if (intel_cap_flts_sanity() ^ intel_cap_slts_sanity()) 1885 + return intel_cap_flts_sanity(); 1886 + 1887 + /* Both levels are available, decide it based on domain type */ 1888 + return type != IOMMU_DOMAIN_UNMANAGED; 1997 1889 } 1998 1890 1999 - static struct dmar_domain *alloc_domain(int flags) 1891 + static struct dmar_domain *alloc_domain(unsigned int type) 2000 1892 { 2001 1893 struct dmar_domain *domain; 2002 1894 ··· 2015 1889 2016 1890 memset(domain, 0, sizeof(*domain)); 2017 1891 domain->nid = NUMA_NO_NODE; 2018 - domain->flags = flags; 2019 - if (first_level_by_default()) 1892 + if (first_level_by_default(type)) 2020 1893 domain->flags |= DOMAIN_FLAG_USE_FIRST_LEVEL; 2021 1894 domain->has_iotlb_device = false; 2022 1895 INIT_LIST_HEAD(&domain->devices); ··· 2479 2354 return -ENOMEM; 2480 2355 first_pte = pte; 2481 2356 2357 + lvl_pages = lvl_to_nr_pages(largepage_lvl); 2358 + 2482 2359 /* It is large page*/ 2483 2360 if (largepage_lvl > 1) { 2484 2361 unsigned long end_pfn; 2362 + unsigned long pages_to_remove; 2485 2363 2486 2364 pteval |= DMA_PTE_LARGE_PAGE; 2487 - end_pfn = ((iov_pfn + nr_pages) & level_mask(largepage_lvl)) - 1; 2365 + pages_to_remove = min_t(unsigned long, nr_pages, 2366 + nr_pte_to_next_page(pte) * lvl_pages); 2367 + end_pfn = iov_pfn + pages_to_remove - 1; 2488 2368 switch_to_super_page(domain, iov_pfn, end_pfn, largepage_lvl); 2489 2369 } else { 2490 2370 pteval &= ~(uint64_t)DMA_PTE_LARGE_PAGE; ··· 2510 2380 } 2511 2381 WARN_ON(1); 2512 2382 } 2513 - 2514 - lvl_pages = lvl_to_nr_pages(largepage_lvl); 2515 - 2516 - BUG_ON(nr_pages < lvl_pages); 2517 2383 2518 2384 nr_pages -= lvl_pages; 2519 2385 iov_pfn += lvl_pages; ··· 2834 2708 struct device *dev; 2835 2709 int i, nid, ret; 2836 2710 2837 - si_domain = alloc_domain(DOMAIN_FLAG_STATIC_IDENTITY); 2711 + si_domain = alloc_domain(IOMMU_DOMAIN_IDENTITY); 2838 2712 if (!si_domain) 2839 2713 return -EFAULT; 2840 2714 ··· 4643 4517 case IOMMU_DOMAIN_DMA: 4644 4518 case IOMMU_DOMAIN_DMA_FQ: 4645 4519 case IOMMU_DOMAIN_UNMANAGED: 4646 - dmar_domain = alloc_domain(0); 4520 + dmar_domain = alloc_domain(type); 4647 4521 if (!dmar_domain) { 4648 4522 pr_err("Can't allocate dmar_domain\n"); 4649 4523 return NULL; ··· 5512 5386 return ret; 5513 5387 } 5514 5388 5515 - /* 5516 - * A PCI express designated vendor specific extended capability is defined 5517 - * in the section 3.7 of Intel scalable I/O virtualization technical spec 5518 - * for system software and tools to detect endpoint devices supporting the 5519 - * Intel scalable IO virtualization without host driver dependency. 5520 - * 5521 - * Returns the address of the matching extended capability structure within 5522 - * the device's PCI configuration space or 0 if the device does not support 5523 - * it. 5524 - */ 5525 - static int siov_find_pci_dvsec(struct pci_dev *pdev) 5526 - { 5527 - int pos; 5528 - u16 vendor, id; 5529 - 5530 - pos = pci_find_next_ext_capability(pdev, 0, 0x23); 5531 - while (pos) { 5532 - pci_read_config_word(pdev, pos + 4, &vendor); 5533 - pci_read_config_word(pdev, pos + 8, &id); 5534 - if (vendor == PCI_VENDOR_ID_INTEL && id == 5) 5535 - return pos; 5536 - 5537 - pos = pci_find_next_ext_capability(pdev, pos, 0x23); 5538 - } 5539 - 5540 - return 0; 5541 - } 5542 - 5543 - static bool 5544 - intel_iommu_dev_has_feat(struct device *dev, enum iommu_dev_features feat) 5389 + static int intel_iommu_enable_iopf(struct device *dev) 5545 5390 { 5546 5391 struct device_domain_info *info = get_domain_info(dev); 5547 5392 5548 - if (feat == IOMMU_DEV_FEAT_AUX) { 5549 - int ret; 5393 + if (info && info->pri_supported) 5394 + return 0; 5550 5395 5551 - if (!dev_is_pci(dev) || dmar_disabled || 5552 - !scalable_mode_support() || !pasid_mode_support()) 5553 - return false; 5554 - 5555 - ret = pci_pasid_features(to_pci_dev(dev)); 5556 - if (ret < 0) 5557 - return false; 5558 - 5559 - return !!siov_find_pci_dvsec(to_pci_dev(dev)); 5560 - } 5561 - 5562 - if (feat == IOMMU_DEV_FEAT_IOPF) 5563 - return info && info->pri_supported; 5564 - 5565 - if (feat == IOMMU_DEV_FEAT_SVA) 5566 - return info && (info->iommu->flags & VTD_FLAG_SVM_CAPABLE) && 5567 - info->pasid_supported && info->pri_supported && 5568 - info->ats_supported; 5569 - 5570 - return false; 5396 + return -ENODEV; 5571 5397 } 5572 5398 5573 5399 static int ··· 5530 5452 return intel_iommu_enable_auxd(dev); 5531 5453 5532 5454 case IOMMU_DEV_FEAT_IOPF: 5533 - return intel_iommu_dev_has_feat(dev, feat) ? 0 : -ENODEV; 5455 + return intel_iommu_enable_iopf(dev); 5534 5456 5535 5457 case IOMMU_DEV_FEAT_SVA: 5536 5458 return intel_iommu_enable_sva(dev); ··· 5656 5578 .get_resv_regions = intel_iommu_get_resv_regions, 5657 5579 .put_resv_regions = generic_iommu_put_resv_regions, 5658 5580 .device_group = intel_iommu_device_group, 5659 - .dev_has_feat = intel_iommu_dev_has_feat, 5660 5581 .dev_feat_enabled = intel_iommu_dev_feat_enabled, 5661 5582 .dev_enable_feat = intel_iommu_dev_enable_feat, 5662 5583 .dev_disable_feat = intel_iommu_dev_disable_feat,
+1 -23
drivers/iommu/intel/svm.c
··· 505 505 return ret; 506 506 } 507 507 508 - static void _load_pasid(void *unused) 509 - { 510 - update_pasid(); 511 - } 512 - 513 - static void load_pasid(struct mm_struct *mm, u32 pasid) 514 - { 515 - mutex_lock(&mm->context.lock); 516 - 517 - /* Update PASID MSR on all CPUs running the mm's tasks. */ 518 - on_each_cpu_mask(mm_cpumask(mm), _load_pasid, NULL, true); 519 - 520 - mutex_unlock(&mm->context.lock); 521 - } 522 - 523 508 static int intel_svm_alloc_pasid(struct device *dev, struct mm_struct *mm, 524 509 unsigned int flags) 525 510 { ··· 599 614 if (ret) 600 615 goto free_sdev; 601 616 602 - /* The newly allocated pasid is loaded to the mm. */ 603 - if (!(flags & SVM_FLAG_SUPERVISOR_MODE) && list_empty(&svm->devs)) 604 - load_pasid(mm, svm->pasid); 605 - 606 617 list_add_rcu(&sdev->list, &svm->devs); 607 618 success: 608 619 return &sdev->sva; ··· 651 670 kfree_rcu(sdev, rcu); 652 671 653 672 if (list_empty(&svm->devs)) { 654 - if (svm->notifier.ops) { 673 + if (svm->notifier.ops) 655 674 mmu_notifier_unregister(&svm->notifier, mm); 656 - /* Clear mm's pasid. */ 657 - load_pasid(mm, PASID_DISABLED); 658 - } 659 675 pasid_private_remove(svm->pasid); 660 676 /* We mandate that no page faults may be outstanding 661 677 * for the PASID when intel_svm_unbind_mm() is called.
+1 -2
drivers/iommu/iommu.c
··· 1954 1954 /* Assume all sizes by default; the driver may override this later */ 1955 1955 domain->pgsize_bitmap = bus->iommu_ops->pgsize_bitmap; 1956 1956 1957 - /* Temporarily avoid -EEXIST while drivers still get their own cookies */ 1958 - if (iommu_is_dma_domain(domain) && !domain->iova_cookie && iommu_get_dma_cookie(domain)) { 1957 + if (iommu_is_dma_domain(domain) && iommu_get_dma_cookie(domain)) { 1959 1958 iommu_domain_free(domain); 1960 1959 domain = NULL; 1961 1960 }
+28 -4
drivers/iommu/ipmmu-vmsa.c
··· 33 33 #define arm_iommu_detach_device(...) do {} while (0) 34 34 #endif 35 35 36 - #define IPMMU_CTX_MAX 8U 36 + #define IPMMU_CTX_MAX 16U 37 37 #define IPMMU_CTX_INVALID -1 38 38 39 - #define IPMMU_UTLB_MAX 48U 39 + #define IPMMU_UTLB_MAX 64U 40 40 41 41 struct ipmmu_features { 42 42 bool use_ns_alias_offset; ··· 189 189 static unsigned int ipmmu_ctx_reg(struct ipmmu_vmsa_device *mmu, 190 190 unsigned int context_id, unsigned int reg) 191 191 { 192 - return mmu->features->ctx_offset_base + 193 - context_id * mmu->features->ctx_offset_stride + reg; 192 + unsigned int base = mmu->features->ctx_offset_base; 193 + 194 + if (context_id > 7) 195 + base += 0x800 - 8 * 0x40; 196 + 197 + return base + context_id * mmu->features->ctx_offset_stride + reg; 194 198 } 195 199 196 200 static u32 ipmmu_ctx_read(struct ipmmu_vmsa_device *mmu, ··· 926 922 .utlb_offset_base = 0, 927 923 }; 928 924 925 + static const struct ipmmu_features ipmmu_features_r8a779a0 = { 926 + .use_ns_alias_offset = false, 927 + .has_cache_leaf_nodes = true, 928 + .number_of_contexts = 16, 929 + .num_utlbs = 64, 930 + .setup_imbuscr = false, 931 + .twobit_imttbcr_sl0 = true, 932 + .reserved_context = true, 933 + .cache_snoop = false, 934 + .ctx_offset_base = 0x10000, 935 + .ctx_offset_stride = 0x1040, 936 + .utlb_offset_base = 0x3000, 937 + }; 938 + 929 939 static const struct of_device_id ipmmu_of_ids[] = { 930 940 { 931 941 .compatible = "renesas,ipmmu-vmsa", ··· 972 954 .compatible = "renesas,ipmmu-r8a77970", 973 955 .data = &ipmmu_features_rcar_gen3, 974 956 }, { 957 + .compatible = "renesas,ipmmu-r8a77980", 958 + .data = &ipmmu_features_rcar_gen3, 959 + }, { 975 960 .compatible = "renesas,ipmmu-r8a77990", 976 961 .data = &ipmmu_features_rcar_gen3, 977 962 }, { 978 963 .compatible = "renesas,ipmmu-r8a77995", 979 964 .data = &ipmmu_features_rcar_gen3, 965 + }, { 966 + .compatible = "renesas,ipmmu-r8a779a0", 967 + .data = &ipmmu_features_r8a779a0, 980 968 }, { 981 969 /* Terminator */ 982 970 },
+3 -1
drivers/iommu/mtk_iommu.c
··· 550 550 phys_addr_t pa; 551 551 552 552 pa = dom->iop->iova_to_phys(dom->iop, iova); 553 - if (dom->data->enable_4GB && pa >= MTK_IOMMU_4GB_MODE_REMAP_BASE) 553 + if (IS_ENABLED(CONFIG_PHYS_ADDR_T_64BIT) && 554 + dom->data->enable_4GB && 555 + pa >= MTK_IOMMU_4GB_MODE_REMAP_BASE) 554 556 pa &= ~BIT_ULL(32); 555 557 556 558 return pa;
+1 -4
drivers/iommu/tegra-smmu.c
··· 1079 1079 struct tegra_mc *mc) 1080 1080 { 1081 1081 struct tegra_smmu *smmu; 1082 - size_t size; 1083 1082 u32 value; 1084 1083 int err; 1085 1084 ··· 1096 1097 */ 1097 1098 mc->smmu = smmu; 1098 1099 1099 - size = BITS_TO_LONGS(soc->num_asids) * sizeof(long); 1100 - 1101 - smmu->asids = devm_kzalloc(dev, size, GFP_KERNEL); 1100 + smmu->asids = devm_bitmap_zalloc(dev, soc->num_asids, GFP_KERNEL); 1102 1101 if (!smmu->asids) 1103 1102 return ERR_PTR(-ENOMEM); 1104 1103
+1 -1
drivers/xen/swiotlb-xen.c
··· 380 380 */ 381 381 trace_swiotlb_bounced(dev, dev_addr, size, swiotlb_force); 382 382 383 - map = swiotlb_tbl_map_single(dev, phys, size, size, dir, attrs); 383 + map = swiotlb_tbl_map_single(dev, phys, size, size, 0, dir, attrs); 384 384 if (map == (phys_addr_t)DMA_MAPPING_ERROR) 385 385 return DMA_MAPPING_ERROR; 386 386
+8
include/linux/dmar.h
··· 131 131 return 0; 132 132 } 133 133 134 + #ifdef CONFIG_DMAR_DEBUG 135 + void dmar_fault_dump_ptes(struct intel_iommu *iommu, u16 source_id, 136 + unsigned long long addr, u32 pasid); 137 + #else 138 + static inline void dmar_fault_dump_ptes(struct intel_iommu *iommu, u16 source_id, 139 + unsigned long long addr, u32 pasid) {} 140 + #endif 141 + 134 142 #ifdef CONFIG_INTEL_IOMMU 135 143 extern int iommu_detected, no_iommu; 136 144 extern int intel_iommu_init(void);
+8 -5
include/linux/intel-iommu.h
··· 517 517 u64 hi; 518 518 }; 519 519 520 - /* si_domain contains mulitple devices */ 521 - #define DOMAIN_FLAG_STATIC_IDENTITY BIT(0) 522 - 523 520 /* 524 521 * When VT-d works in the scalable mode, it allows DMA translation to 525 522 * happen through either first level or second level page table. This ··· 705 708 return (pte->val & DMA_PTE_LARGE_PAGE); 706 709 } 707 710 708 - static inline int first_pte_in_page(struct dma_pte *pte) 711 + static inline bool first_pte_in_page(struct dma_pte *pte) 709 712 { 710 - return !((unsigned long)pte & ~VTD_PAGE_MASK); 713 + return IS_ALIGNED((unsigned long)pte, VTD_PAGE_SIZE); 714 + } 715 + 716 + static inline int nr_pte_to_next_page(struct dma_pte *pte) 717 + { 718 + return first_pte_in_page(pte) ? BIT_ULL(VTD_STRIDE_SHIFT) : 719 + (struct dma_pte *)ALIGN((unsigned long)pte, VTD_PAGE_SIZE) - pte; 711 720 } 712 721 713 722 extern struct dmar_drhd_unit * dmar_find_matched_drhd_unit(struct pci_dev *dev);
+2 -1
include/linux/swiotlb.h
··· 45 45 46 46 phys_addr_t swiotlb_tbl_map_single(struct device *hwdev, phys_addr_t phys, 47 47 size_t mapping_size, size_t alloc_size, 48 - enum dma_data_direction dir, unsigned long attrs); 48 + unsigned int alloc_aligned_mask, enum dma_data_direction dir, 49 + unsigned long attrs); 49 50 50 51 extern void swiotlb_tbl_unmap_single(struct device *hwdev, 51 52 phys_addr_t tlb_addr,
+8 -5
kernel/dma/swiotlb.c
··· 459 459 * allocate a buffer from that IO TLB pool. 460 460 */ 461 461 static int swiotlb_find_slots(struct device *dev, phys_addr_t orig_addr, 462 - size_t alloc_size) 462 + size_t alloc_size, unsigned int alloc_align_mask) 463 463 { 464 464 struct io_tlb_mem *mem = dev->dma_io_tlb_mem; 465 465 unsigned long boundary_mask = dma_get_seg_boundary(dev); ··· 483 483 stride = (iotlb_align_mask >> IO_TLB_SHIFT) + 1; 484 484 if (alloc_size >= PAGE_SIZE) 485 485 stride = max(stride, stride << (PAGE_SHIFT - IO_TLB_SHIFT)); 486 + stride = max(stride, (alloc_align_mask >> IO_TLB_SHIFT) + 1); 486 487 487 488 spin_lock_irqsave(&mem->lock, flags); 488 489 if (unlikely(nslots > mem->nslabs - mem->used)) ··· 542 541 543 542 phys_addr_t swiotlb_tbl_map_single(struct device *dev, phys_addr_t orig_addr, 544 543 size_t mapping_size, size_t alloc_size, 545 - enum dma_data_direction dir, unsigned long attrs) 544 + unsigned int alloc_align_mask, enum dma_data_direction dir, 545 + unsigned long attrs) 546 546 { 547 547 struct io_tlb_mem *mem = dev->dma_io_tlb_mem; 548 548 unsigned int offset = swiotlb_align_offset(dev, orig_addr); ··· 563 561 return (phys_addr_t)DMA_MAPPING_ERROR; 564 562 } 565 563 566 - index = swiotlb_find_slots(dev, orig_addr, alloc_size + offset); 564 + index = swiotlb_find_slots(dev, orig_addr, 565 + alloc_size + offset, alloc_align_mask); 567 566 if (index == -1) { 568 567 if (!(attrs & DMA_ATTR_NO_WARN)) 569 568 dev_warn_ratelimited(dev, ··· 678 675 trace_swiotlb_bounced(dev, phys_to_dma(dev, paddr), size, 679 676 swiotlb_force); 680 677 681 - swiotlb_addr = swiotlb_tbl_map_single(dev, paddr, size, size, dir, 678 + swiotlb_addr = swiotlb_tbl_map_single(dev, paddr, size, size, 0, dir, 682 679 attrs); 683 680 if (swiotlb_addr == (phys_addr_t)DMA_MAPPING_ERROR) 684 681 return DMA_MAPPING_ERROR; ··· 762 759 if (!mem) 763 760 return NULL; 764 761 765 - index = swiotlb_find_slots(dev, 0, size); 762 + index = swiotlb_find_slots(dev, 0, size, 0); 766 763 if (index == -1) 767 764 return NULL; 768 765