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

Merge branch 'core' into x86/vt-d

+412 -1761
+1 -1
drivers/gpu/drm/nouveau/nvkm/engine/device/tegra.c
··· 133 133 * or equal to the system's PAGE_SIZE, with a preference if 134 134 * both are equal. 135 135 */ 136 - pgsize_bitmap = tdev->iommu.domain->ops->pgsize_bitmap; 136 + pgsize_bitmap = tdev->iommu.domain->pgsize_bitmap; 137 137 if (pgsize_bitmap & PAGE_SIZE) { 138 138 tdev->iommu.pgshift = PAGE_SHIFT; 139 139 } else {
+1 -2
drivers/iommu/amd/amd_iommu.h
··· 116 116 117 117 118 118 extern bool translation_pre_enabled(struct amd_iommu *iommu); 119 - extern bool amd_iommu_is_attach_deferred(struct iommu_domain *domain, 120 - struct device *dev); 119 + extern bool amd_iommu_is_attach_deferred(struct device *dev); 121 120 extern int __init add_special_device(u8 type, u8 id, u16 *devid, 122 121 bool cmd_line); 123 122
+12 -11
drivers/iommu/amd/iommu.c
··· 2215 2215 list_add_tail(&region->list, head); 2216 2216 } 2217 2217 2218 - bool amd_iommu_is_attach_deferred(struct iommu_domain *domain, 2219 - struct device *dev) 2218 + bool amd_iommu_is_attach_deferred(struct device *dev) 2220 2219 { 2221 2220 struct iommu_dev_data *dev_data = dev_iommu_priv_get(dev); 2222 2221 ··· 2268 2269 const struct iommu_ops amd_iommu_ops = { 2269 2270 .capable = amd_iommu_capable, 2270 2271 .domain_alloc = amd_iommu_domain_alloc, 2271 - .domain_free = amd_iommu_domain_free, 2272 - .attach_dev = amd_iommu_attach_device, 2273 - .detach_dev = amd_iommu_detach_device, 2274 - .map = amd_iommu_map, 2275 - .iotlb_sync_map = amd_iommu_iotlb_sync_map, 2276 - .unmap = amd_iommu_unmap, 2277 - .iova_to_phys = amd_iommu_iova_to_phys, 2278 2272 .probe_device = amd_iommu_probe_device, 2279 2273 .release_device = amd_iommu_release_device, 2280 2274 .probe_finalize = amd_iommu_probe_finalize, ··· 2276 2284 .put_resv_regions = generic_iommu_put_resv_regions, 2277 2285 .is_attach_deferred = amd_iommu_is_attach_deferred, 2278 2286 .pgsize_bitmap = AMD_IOMMU_PGSIZES, 2279 - .flush_iotlb_all = amd_iommu_flush_iotlb_all, 2280 - .iotlb_sync = amd_iommu_iotlb_sync, 2281 2287 .def_domain_type = amd_iommu_def_domain_type, 2288 + .default_domain_ops = &(const struct iommu_domain_ops) { 2289 + .attach_dev = amd_iommu_attach_device, 2290 + .detach_dev = amd_iommu_detach_device, 2291 + .map = amd_iommu_map, 2292 + .unmap = amd_iommu_unmap, 2293 + .iotlb_sync_map = amd_iommu_iotlb_sync_map, 2294 + .iova_to_phys = amd_iommu_iova_to_phys, 2295 + .flush_iotlb_all = amd_iommu_flush_iotlb_all, 2296 + .iotlb_sync = amd_iommu_iotlb_sync, 2297 + .free = amd_iommu_domain_free, 2298 + } 2282 2299 }; 2283 2300 2284 2301 /*****************************************************************************
+1 -1
drivers/iommu/amd/iommu_v2.c
··· 537 537 ret = NOTIFY_DONE; 538 538 539 539 /* In kdump kernel pci dev is not initialized yet -> send INVALID */ 540 - if (amd_iommu_is_attach_deferred(NULL, &pdev->dev)) { 540 + if (amd_iommu_is_attach_deferred(&pdev->dev)) { 541 541 amd_iommu_complete_ppr(pdev, iommu_fault->pasid, 542 542 PPR_INVALID, tag); 543 543 goto out;
+11 -9
drivers/iommu/apple-dart.c
··· 765 765 766 766 static const struct iommu_ops apple_dart_iommu_ops = { 767 767 .domain_alloc = apple_dart_domain_alloc, 768 - .domain_free = apple_dart_domain_free, 769 - .attach_dev = apple_dart_attach_dev, 770 - .detach_dev = apple_dart_detach_dev, 771 - .map_pages = apple_dart_map_pages, 772 - .unmap_pages = apple_dart_unmap_pages, 773 - .flush_iotlb_all = apple_dart_flush_iotlb_all, 774 - .iotlb_sync = apple_dart_iotlb_sync, 775 - .iotlb_sync_map = apple_dart_iotlb_sync_map, 776 - .iova_to_phys = apple_dart_iova_to_phys, 777 768 .probe_device = apple_dart_probe_device, 778 769 .release_device = apple_dart_release_device, 779 770 .device_group = apple_dart_device_group, ··· 773 782 .get_resv_regions = apple_dart_get_resv_regions, 774 783 .put_resv_regions = generic_iommu_put_resv_regions, 775 784 .pgsize_bitmap = -1UL, /* Restricted during dart probe */ 785 + .default_domain_ops = &(const struct iommu_domain_ops) { 786 + .attach_dev = apple_dart_attach_dev, 787 + .detach_dev = apple_dart_detach_dev, 788 + .map_pages = apple_dart_map_pages, 789 + .unmap_pages = apple_dart_unmap_pages, 790 + .flush_iotlb_all = apple_dart_flush_iotlb_all, 791 + .iotlb_sync = apple_dart_iotlb_sync, 792 + .iotlb_sync_map = apple_dart_iotlb_sync_map, 793 + .iova_to_phys = apple_dart_iova_to_phys, 794 + .free = apple_dart_domain_free, 795 + } 776 796 }; 777 797 778 798 static irqreturn_t apple_dart_irq(int irq, void *dev)
+10 -8
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
··· 2841 2841 static struct iommu_ops arm_smmu_ops = { 2842 2842 .capable = arm_smmu_capable, 2843 2843 .domain_alloc = arm_smmu_domain_alloc, 2844 - .domain_free = arm_smmu_domain_free, 2845 - .attach_dev = arm_smmu_attach_dev, 2846 - .map_pages = arm_smmu_map_pages, 2847 - .unmap_pages = arm_smmu_unmap_pages, 2848 - .flush_iotlb_all = arm_smmu_flush_iotlb_all, 2849 - .iotlb_sync = arm_smmu_iotlb_sync, 2850 - .iova_to_phys = arm_smmu_iova_to_phys, 2851 2844 .probe_device = arm_smmu_probe_device, 2852 2845 .release_device = arm_smmu_release_device, 2853 2846 .device_group = arm_smmu_device_group, 2854 - .enable_nesting = arm_smmu_enable_nesting, 2855 2847 .of_xlate = arm_smmu_of_xlate, 2856 2848 .get_resv_regions = arm_smmu_get_resv_regions, 2857 2849 .put_resv_regions = generic_iommu_put_resv_regions, ··· 2857 2865 .page_response = arm_smmu_page_response, 2858 2866 .pgsize_bitmap = -1UL, /* Restricted during device attach */ 2859 2867 .owner = THIS_MODULE, 2868 + .default_domain_ops = &(const struct iommu_domain_ops) { 2869 + .attach_dev = arm_smmu_attach_dev, 2870 + .map_pages = arm_smmu_map_pages, 2871 + .unmap_pages = arm_smmu_unmap_pages, 2872 + .flush_iotlb_all = arm_smmu_flush_iotlb_all, 2873 + .iotlb_sync = arm_smmu_iotlb_sync, 2874 + .iova_to_phys = arm_smmu_iova_to_phys, 2875 + .enable_nesting = arm_smmu_enable_nesting, 2876 + .free = arm_smmu_domain_free, 2877 + } 2860 2878 }; 2861 2879 2862 2880 /* Probing and initialisation functions */
+11 -9
drivers/iommu/arm/arm-smmu/arm-smmu.c
··· 1583 1583 static struct iommu_ops arm_smmu_ops = { 1584 1584 .capable = arm_smmu_capable, 1585 1585 .domain_alloc = arm_smmu_domain_alloc, 1586 - .domain_free = arm_smmu_domain_free, 1587 - .attach_dev = arm_smmu_attach_dev, 1588 - .map_pages = arm_smmu_map_pages, 1589 - .unmap_pages = arm_smmu_unmap_pages, 1590 - .flush_iotlb_all = arm_smmu_flush_iotlb_all, 1591 - .iotlb_sync = arm_smmu_iotlb_sync, 1592 - .iova_to_phys = arm_smmu_iova_to_phys, 1593 1586 .probe_device = arm_smmu_probe_device, 1594 1587 .release_device = arm_smmu_release_device, 1595 1588 .probe_finalize = arm_smmu_probe_finalize, 1596 1589 .device_group = arm_smmu_device_group, 1597 - .enable_nesting = arm_smmu_enable_nesting, 1598 - .set_pgtable_quirks = arm_smmu_set_pgtable_quirks, 1599 1590 .of_xlate = arm_smmu_of_xlate, 1600 1591 .get_resv_regions = arm_smmu_get_resv_regions, 1601 1592 .put_resv_regions = generic_iommu_put_resv_regions, 1602 1593 .def_domain_type = arm_smmu_def_domain_type, 1603 1594 .pgsize_bitmap = -1UL, /* Restricted during device attach */ 1604 1595 .owner = THIS_MODULE, 1596 + .default_domain_ops = &(const struct iommu_domain_ops) { 1597 + .attach_dev = arm_smmu_attach_dev, 1598 + .map_pages = arm_smmu_map_pages, 1599 + .unmap_pages = arm_smmu_unmap_pages, 1600 + .flush_iotlb_all = arm_smmu_flush_iotlb_all, 1601 + .iotlb_sync = arm_smmu_iotlb_sync, 1602 + .iova_to_phys = arm_smmu_iova_to_phys, 1603 + .enable_nesting = arm_smmu_enable_nesting, 1604 + .set_pgtable_quirks = arm_smmu_set_pgtable_quirks, 1605 + .free = arm_smmu_domain_free, 1606 + } 1605 1607 }; 1606 1608 1607 1609 static void arm_smmu_device_reset(struct arm_smmu_device *smmu)
+10 -8
drivers/iommu/arm/arm-smmu/qcom_iommu.c
··· 590 590 static const struct iommu_ops qcom_iommu_ops = { 591 591 .capable = qcom_iommu_capable, 592 592 .domain_alloc = qcom_iommu_domain_alloc, 593 - .domain_free = qcom_iommu_domain_free, 594 - .attach_dev = qcom_iommu_attach_dev, 595 - .detach_dev = qcom_iommu_detach_dev, 596 - .map = qcom_iommu_map, 597 - .unmap = qcom_iommu_unmap, 598 - .flush_iotlb_all = qcom_iommu_flush_iotlb_all, 599 - .iotlb_sync = qcom_iommu_iotlb_sync, 600 - .iova_to_phys = qcom_iommu_iova_to_phys, 601 593 .probe_device = qcom_iommu_probe_device, 602 594 .release_device = qcom_iommu_release_device, 603 595 .device_group = generic_device_group, 604 596 .of_xlate = qcom_iommu_of_xlate, 605 597 .pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M, 598 + .default_domain_ops = &(const struct iommu_domain_ops) { 599 + .attach_dev = qcom_iommu_attach_dev, 600 + .detach_dev = qcom_iommu_detach_dev, 601 + .map = qcom_iommu_map, 602 + .unmap = qcom_iommu_unmap, 603 + .flush_iotlb_all = qcom_iommu_flush_iotlb_all, 604 + .iotlb_sync = qcom_iommu_iotlb_sync, 605 + .iova_to_phys = qcom_iommu_iova_to_phys, 606 + .free = qcom_iommu_domain_free, 607 + } 606 608 }; 607 609 608 610 static int qcom_iommu_sec_ptbl_init(struct device *dev)
+4
drivers/iommu/dma-iommu.c
··· 525 525 struct iommu_dma_cookie *cookie = domain->iova_cookie; 526 526 unsigned long order, base_pfn; 527 527 struct iova_domain *iovad; 528 + int ret; 528 529 529 530 if (!cookie || cookie->type != IOMMU_DMA_IOVA_COOKIE) 530 531 return -EINVAL; ··· 560 559 } 561 560 562 561 init_iova_domain(iovad, 1UL << order, base_pfn); 562 + ret = iova_domain_init_rcaches(iovad); 563 + if (ret) 564 + return ret; 563 565 564 566 /* If the FQ fails we can simply fall back to strict mode */ 565 567 if (domain->type == IOMMU_DOMAIN_DMA_FQ && iommu_dma_init_fq(domain))
+8 -6
drivers/iommu/exynos-iommu.c
··· 1309 1309 1310 1310 static const struct iommu_ops exynos_iommu_ops = { 1311 1311 .domain_alloc = exynos_iommu_domain_alloc, 1312 - .domain_free = exynos_iommu_domain_free, 1313 - .attach_dev = exynos_iommu_attach_device, 1314 - .detach_dev = exynos_iommu_detach_device, 1315 - .map = exynos_iommu_map, 1316 - .unmap = exynos_iommu_unmap, 1317 - .iova_to_phys = exynos_iommu_iova_to_phys, 1318 1312 .device_group = generic_device_group, 1319 1313 .probe_device = exynos_iommu_probe_device, 1320 1314 .release_device = exynos_iommu_release_device, 1321 1315 .pgsize_bitmap = SECT_SIZE | LPAGE_SIZE | SPAGE_SIZE, 1322 1316 .of_xlate = exynos_iommu_of_xlate, 1317 + .default_domain_ops = &(const struct iommu_domain_ops) { 1318 + .attach_dev = exynos_iommu_attach_device, 1319 + .detach_dev = exynos_iommu_detach_device, 1320 + .map = exynos_iommu_map, 1321 + .unmap = exynos_iommu_unmap, 1322 + .iova_to_phys = exynos_iommu_iova_to_phys, 1323 + .free = exynos_iommu_domain_free, 1324 + } 1323 1325 }; 1324 1326 1325 1327 static int __init exynos_iommu_init(void)
+6 -4
drivers/iommu/fsl_pamu_domain.c
··· 453 453 static const struct iommu_ops fsl_pamu_ops = { 454 454 .capable = fsl_pamu_capable, 455 455 .domain_alloc = fsl_pamu_domain_alloc, 456 - .domain_free = fsl_pamu_domain_free, 457 - .attach_dev = fsl_pamu_attach_device, 458 - .detach_dev = fsl_pamu_detach_device, 459 - .iova_to_phys = fsl_pamu_iova_to_phys, 460 456 .probe_device = fsl_pamu_probe_device, 461 457 .release_device = fsl_pamu_release_device, 462 458 .device_group = fsl_pamu_device_group, 459 + .default_domain_ops = &(const struct iommu_domain_ops) { 460 + .attach_dev = fsl_pamu_attach_device, 461 + .detach_dev = fsl_pamu_detach_device, 462 + .iova_to_phys = fsl_pamu_iova_to_phys, 463 + .free = fsl_pamu_domain_free, 464 + } 463 465 }; 464 466 465 467 int __init pamu_domain_init(void)
+1 -2
drivers/iommu/intel/debugfs.c
··· 351 351 if (!domain) 352 352 return 0; 353 353 354 - seq_printf(m, "Device %s with pasid %d @0x%llx\n", 355 - dev_name(dev), domain->default_pasid, 354 + seq_printf(m, "Device %s @0x%llx\n", dev_name(dev), 356 355 (u64)virt_to_phys(domain->pgd)); 357 356 seq_puts(m, "IOVA_PFN\t\tPML5E\t\t\tPML4E\t\t\tPDPE\t\t\tPDE\t\t\tPTE\n"); 358 357
+14 -526
drivers/iommu/intel/iommu.c
··· 1573 1573 break; 1574 1574 } 1575 1575 1576 - if (!has_iotlb_device) { 1577 - struct subdev_domain_info *sinfo; 1578 - 1579 - list_for_each_entry(sinfo, &domain->subdevices, link_domain) { 1580 - info = get_domain_info(sinfo->pdev); 1581 - if (info && info->ats_enabled) { 1582 - has_iotlb_device = true; 1583 - break; 1584 - } 1585 - } 1586 - } 1587 - 1588 1576 domain->has_iotlb_device = has_iotlb_device; 1589 1577 } 1590 1578 ··· 1670 1682 { 1671 1683 unsigned long flags; 1672 1684 struct device_domain_info *info; 1673 - struct subdev_domain_info *sinfo; 1674 1685 1675 1686 if (!domain->has_iotlb_device) 1676 1687 return; ··· 1678 1691 list_for_each_entry(info, &domain->devices, link) 1679 1692 __iommu_flush_dev_iotlb(info, addr, mask); 1680 1693 1681 - list_for_each_entry(sinfo, &domain->subdevices, link_domain) { 1682 - info = get_domain_info(sinfo->pdev); 1683 - __iommu_flush_dev_iotlb(info, addr, mask); 1684 - } 1685 1694 spin_unlock_irqrestore(&device_domain_lock, flags); 1686 - } 1687 - 1688 - static void domain_flush_piotlb(struct intel_iommu *iommu, 1689 - struct dmar_domain *domain, 1690 - u64 addr, unsigned long npages, bool ih) 1691 - { 1692 - u16 did = domain->iommu_did[iommu->seq_id]; 1693 - 1694 - if (domain->default_pasid) 1695 - qi_flush_piotlb(iommu, did, domain->default_pasid, 1696 - addr, npages, ih); 1697 - 1698 - if (!list_empty(&domain->devices)) 1699 - qi_flush_piotlb(iommu, did, PASID_RID2PASID, addr, npages, ih); 1700 1695 } 1701 1696 1702 1697 static void iommu_flush_iotlb_psi(struct intel_iommu *iommu, ··· 1696 1727 ih = 1 << 6; 1697 1728 1698 1729 if (domain_use_first_level(domain)) { 1699 - domain_flush_piotlb(iommu, domain, addr, pages, ih); 1730 + qi_flush_piotlb(iommu, did, PASID_RID2PASID, addr, pages, ih); 1700 1731 } else { 1701 1732 /* 1702 1733 * Fallback to domain selective flush if no PSI support or ··· 1745 1776 u16 did = dmar_domain->iommu_did[iommu->seq_id]; 1746 1777 1747 1778 if (domain_use_first_level(dmar_domain)) 1748 - domain_flush_piotlb(iommu, dmar_domain, 0, -1, 0); 1779 + qi_flush_piotlb(iommu, did, PASID_RID2PASID, 0, -1, 0); 1749 1780 else 1750 1781 iommu->flush.flush_iotlb(iommu, did, 0, 0, 1751 1782 DMA_TLB_DSI_FLUSH); ··· 1952 1983 domain->flags |= DOMAIN_FLAG_USE_FIRST_LEVEL; 1953 1984 domain->has_iotlb_device = false; 1954 1985 INIT_LIST_HEAD(&domain->devices); 1955 - INIT_LIST_HEAD(&domain->subdevices); 1956 1986 1957 1987 return domain; 1958 1988 } ··· 2644 2676 info->domain = domain; 2645 2677 info->iommu = iommu; 2646 2678 info->pasid_table = NULL; 2647 - info->auxd_enabled = 0; 2648 - INIT_LIST_HEAD(&info->subdevices); 2649 2679 2650 2680 if (dev && dev_is_pci(dev)) { 2651 2681 struct pci_dev *pdev = to_pci_dev(info->dev); ··· 4603 4637 domain_exit(to_dmar_domain(domain)); 4604 4638 } 4605 4639 4606 - /* 4607 - * Check whether a @domain could be attached to the @dev through the 4608 - * aux-domain attach/detach APIs. 4609 - */ 4610 - static inline bool 4611 - is_aux_domain(struct device *dev, struct iommu_domain *domain) 4612 - { 4613 - struct device_domain_info *info = get_domain_info(dev); 4614 - 4615 - return info && info->auxd_enabled && 4616 - domain->type == IOMMU_DOMAIN_UNMANAGED; 4617 - } 4618 - 4619 - static inline struct subdev_domain_info * 4620 - lookup_subdev_info(struct dmar_domain *domain, struct device *dev) 4621 - { 4622 - struct subdev_domain_info *sinfo; 4623 - 4624 - if (!list_empty(&domain->subdevices)) { 4625 - list_for_each_entry(sinfo, &domain->subdevices, link_domain) { 4626 - if (sinfo->pdev == dev) 4627 - return sinfo; 4628 - } 4629 - } 4630 - 4631 - return NULL; 4632 - } 4633 - 4634 - static int auxiliary_link_device(struct dmar_domain *domain, 4635 - struct device *dev) 4636 - { 4637 - struct device_domain_info *info = get_domain_info(dev); 4638 - struct subdev_domain_info *sinfo = lookup_subdev_info(domain, dev); 4639 - 4640 - assert_spin_locked(&device_domain_lock); 4641 - if (WARN_ON(!info)) 4642 - return -EINVAL; 4643 - 4644 - if (!sinfo) { 4645 - sinfo = kzalloc(sizeof(*sinfo), GFP_ATOMIC); 4646 - if (!sinfo) 4647 - return -ENOMEM; 4648 - sinfo->domain = domain; 4649 - sinfo->pdev = dev; 4650 - list_add(&sinfo->link_phys, &info->subdevices); 4651 - list_add(&sinfo->link_domain, &domain->subdevices); 4652 - } 4653 - 4654 - return ++sinfo->users; 4655 - } 4656 - 4657 - static int auxiliary_unlink_device(struct dmar_domain *domain, 4658 - struct device *dev) 4659 - { 4660 - struct device_domain_info *info = get_domain_info(dev); 4661 - struct subdev_domain_info *sinfo = lookup_subdev_info(domain, dev); 4662 - int ret; 4663 - 4664 - assert_spin_locked(&device_domain_lock); 4665 - if (WARN_ON(!info || !sinfo || sinfo->users <= 0)) 4666 - return -EINVAL; 4667 - 4668 - ret = --sinfo->users; 4669 - if (!ret) { 4670 - list_del(&sinfo->link_phys); 4671 - list_del(&sinfo->link_domain); 4672 - kfree(sinfo); 4673 - } 4674 - 4675 - return ret; 4676 - } 4677 - 4678 - static int aux_domain_add_dev(struct dmar_domain *domain, 4679 - struct device *dev) 4680 - { 4681 - int ret; 4682 - unsigned long flags; 4683 - struct intel_iommu *iommu; 4684 - 4685 - iommu = device_to_iommu(dev, NULL, NULL); 4686 - if (!iommu) 4687 - return -ENODEV; 4688 - 4689 - if (domain->default_pasid <= 0) { 4690 - u32 pasid; 4691 - 4692 - /* No private data needed for the default pasid */ 4693 - pasid = ioasid_alloc(NULL, PASID_MIN, 4694 - pci_max_pasids(to_pci_dev(dev)) - 1, 4695 - NULL); 4696 - if (pasid == INVALID_IOASID) { 4697 - pr_err("Can't allocate default pasid\n"); 4698 - return -ENODEV; 4699 - } 4700 - domain->default_pasid = pasid; 4701 - } 4702 - 4703 - spin_lock_irqsave(&device_domain_lock, flags); 4704 - ret = auxiliary_link_device(domain, dev); 4705 - if (ret <= 0) 4706 - goto link_failed; 4707 - 4708 - /* 4709 - * Subdevices from the same physical device can be attached to the 4710 - * same domain. For such cases, only the first subdevice attachment 4711 - * needs to go through the full steps in this function. So if ret > 4712 - * 1, just goto out. 4713 - */ 4714 - if (ret > 1) 4715 - goto out; 4716 - 4717 - /* 4718 - * iommu->lock must be held to attach domain to iommu and setup the 4719 - * pasid entry for second level translation. 4720 - */ 4721 - spin_lock(&iommu->lock); 4722 - ret = domain_attach_iommu(domain, iommu); 4723 - if (ret) 4724 - goto attach_failed; 4725 - 4726 - /* Setup the PASID entry for mediated devices: */ 4727 - if (domain_use_first_level(domain)) 4728 - ret = domain_setup_first_level(iommu, domain, dev, 4729 - domain->default_pasid); 4730 - else 4731 - ret = intel_pasid_setup_second_level(iommu, domain, dev, 4732 - domain->default_pasid); 4733 - if (ret) 4734 - goto table_failed; 4735 - 4736 - spin_unlock(&iommu->lock); 4737 - out: 4738 - spin_unlock_irqrestore(&device_domain_lock, flags); 4739 - 4740 - return 0; 4741 - 4742 - table_failed: 4743 - domain_detach_iommu(domain, iommu); 4744 - attach_failed: 4745 - spin_unlock(&iommu->lock); 4746 - auxiliary_unlink_device(domain, dev); 4747 - link_failed: 4748 - spin_unlock_irqrestore(&device_domain_lock, flags); 4749 - if (list_empty(&domain->subdevices) && domain->default_pasid > 0) 4750 - ioasid_put(domain->default_pasid); 4751 - 4752 - return ret; 4753 - } 4754 - 4755 - static void aux_domain_remove_dev(struct dmar_domain *domain, 4756 - struct device *dev) 4757 - { 4758 - struct device_domain_info *info; 4759 - struct intel_iommu *iommu; 4760 - unsigned long flags; 4761 - 4762 - if (!is_aux_domain(dev, &domain->domain)) 4763 - return; 4764 - 4765 - spin_lock_irqsave(&device_domain_lock, flags); 4766 - info = get_domain_info(dev); 4767 - iommu = info->iommu; 4768 - 4769 - if (!auxiliary_unlink_device(domain, dev)) { 4770 - spin_lock(&iommu->lock); 4771 - intel_pasid_tear_down_entry(iommu, dev, 4772 - domain->default_pasid, false); 4773 - domain_detach_iommu(domain, iommu); 4774 - spin_unlock(&iommu->lock); 4775 - } 4776 - 4777 - spin_unlock_irqrestore(&device_domain_lock, flags); 4778 - 4779 - if (list_empty(&domain->subdevices) && domain->default_pasid > 0) 4780 - ioasid_put(domain->default_pasid); 4781 - } 4782 - 4783 4640 static int prepare_domain_attach_device(struct iommu_domain *domain, 4784 4641 struct device *dev) 4785 4642 { ··· 4613 4824 iommu = device_to_iommu(dev, NULL, NULL); 4614 4825 if (!iommu) 4615 4826 return -ENODEV; 4616 - 4617 - if ((dmar_domain->flags & DOMAIN_FLAG_NESTING_MODE) && 4618 - !ecap_nest(iommu->ecap)) { 4619 - dev_err(dev, "%s: iommu not support nested translation\n", 4620 - iommu->name); 4621 - return -EINVAL; 4622 - } 4623 4827 4624 4828 /* check if this iommu agaw is sufficient for max mapped address */ 4625 4829 addr_width = agaw_to_width(iommu->agaw); ··· 4655 4873 return -EPERM; 4656 4874 } 4657 4875 4658 - if (is_aux_domain(dev, domain)) 4659 - return -EPERM; 4660 - 4661 4876 /* normally dev is not mapped */ 4662 4877 if (unlikely(domain_context_mapped(dev))) { 4663 4878 struct dmar_domain *old_domain; ··· 4671 4892 return domain_add_dev_info(to_dmar_domain(domain), dev); 4672 4893 } 4673 4894 4674 - static int intel_iommu_aux_attach_device(struct iommu_domain *domain, 4675 - struct device *dev) 4676 - { 4677 - int ret; 4678 - 4679 - if (!is_aux_domain(dev, domain)) 4680 - return -EPERM; 4681 - 4682 - ret = prepare_domain_attach_device(domain, dev); 4683 - if (ret) 4684 - return ret; 4685 - 4686 - return aux_domain_add_dev(to_dmar_domain(domain), dev); 4687 - } 4688 - 4689 4895 static void intel_iommu_detach_device(struct iommu_domain *domain, 4690 4896 struct device *dev) 4691 4897 { 4692 4898 dmar_remove_one_dev_info(dev); 4693 4899 } 4694 - 4695 - static void intel_iommu_aux_detach_device(struct iommu_domain *domain, 4696 - struct device *dev) 4697 - { 4698 - aux_domain_remove_dev(to_dmar_domain(domain), dev); 4699 - } 4700 - 4701 - #ifdef CONFIG_INTEL_IOMMU_SVM 4702 - /* 4703 - * 2D array for converting and sanitizing IOMMU generic TLB granularity to 4704 - * VT-d granularity. Invalidation is typically included in the unmap operation 4705 - * as a result of DMA or VFIO unmap. However, for assigned devices guest 4706 - * owns the first level page tables. Invalidations of translation caches in the 4707 - * guest are trapped and passed down to the host. 4708 - * 4709 - * vIOMMU in the guest will only expose first level page tables, therefore 4710 - * we do not support IOTLB granularity for request without PASID (second level). 4711 - * 4712 - * For example, to find the VT-d granularity encoding for IOTLB 4713 - * type and page selective granularity within PASID: 4714 - * X: indexed by iommu cache type 4715 - * Y: indexed by enum iommu_inv_granularity 4716 - * [IOMMU_CACHE_INV_TYPE_IOTLB][IOMMU_INV_GRANU_ADDR] 4717 - */ 4718 - 4719 - static const int 4720 - inv_type_granu_table[IOMMU_CACHE_INV_TYPE_NR][IOMMU_INV_GRANU_NR] = { 4721 - /* 4722 - * PASID based IOTLB invalidation: PASID selective (per PASID), 4723 - * page selective (address granularity) 4724 - */ 4725 - {-EINVAL, QI_GRAN_NONG_PASID, QI_GRAN_PSI_PASID}, 4726 - /* PASID based dev TLBs */ 4727 - {-EINVAL, -EINVAL, QI_DEV_IOTLB_GRAN_PASID_SEL}, 4728 - /* PASID cache */ 4729 - {-EINVAL, -EINVAL, -EINVAL} 4730 - }; 4731 - 4732 - static inline int to_vtd_granularity(int type, int granu) 4733 - { 4734 - return inv_type_granu_table[type][granu]; 4735 - } 4736 - 4737 - static inline u64 to_vtd_size(u64 granu_size, u64 nr_granules) 4738 - { 4739 - u64 nr_pages = (granu_size * nr_granules) >> VTD_PAGE_SHIFT; 4740 - 4741 - /* VT-d size is encoded as 2^size of 4K pages, 0 for 4k, 9 for 2MB, etc. 4742 - * IOMMU cache invalidate API passes granu_size in bytes, and number of 4743 - * granu size in contiguous memory. 4744 - */ 4745 - return order_base_2(nr_pages); 4746 - } 4747 - 4748 - static int 4749 - intel_iommu_sva_invalidate(struct iommu_domain *domain, struct device *dev, 4750 - struct iommu_cache_invalidate_info *inv_info) 4751 - { 4752 - struct dmar_domain *dmar_domain = to_dmar_domain(domain); 4753 - struct device_domain_info *info; 4754 - struct intel_iommu *iommu; 4755 - unsigned long flags; 4756 - int cache_type; 4757 - u8 bus, devfn; 4758 - u16 did, sid; 4759 - int ret = 0; 4760 - u64 size = 0; 4761 - 4762 - if (!inv_info || !dmar_domain) 4763 - return -EINVAL; 4764 - 4765 - if (!dev || !dev_is_pci(dev)) 4766 - return -ENODEV; 4767 - 4768 - iommu = device_to_iommu(dev, &bus, &devfn); 4769 - if (!iommu) 4770 - return -ENODEV; 4771 - 4772 - if (!(dmar_domain->flags & DOMAIN_FLAG_NESTING_MODE)) 4773 - return -EINVAL; 4774 - 4775 - spin_lock_irqsave(&device_domain_lock, flags); 4776 - spin_lock(&iommu->lock); 4777 - info = get_domain_info(dev); 4778 - if (!info) { 4779 - ret = -EINVAL; 4780 - goto out_unlock; 4781 - } 4782 - did = dmar_domain->iommu_did[iommu->seq_id]; 4783 - sid = PCI_DEVID(bus, devfn); 4784 - 4785 - /* Size is only valid in address selective invalidation */ 4786 - if (inv_info->granularity == IOMMU_INV_GRANU_ADDR) 4787 - size = to_vtd_size(inv_info->granu.addr_info.granule_size, 4788 - inv_info->granu.addr_info.nb_granules); 4789 - 4790 - for_each_set_bit(cache_type, 4791 - (unsigned long *)&inv_info->cache, 4792 - IOMMU_CACHE_INV_TYPE_NR) { 4793 - int granu = 0; 4794 - u64 pasid = 0; 4795 - u64 addr = 0; 4796 - 4797 - granu = to_vtd_granularity(cache_type, inv_info->granularity); 4798 - if (granu == -EINVAL) { 4799 - pr_err_ratelimited("Invalid cache type and granu combination %d/%d\n", 4800 - cache_type, inv_info->granularity); 4801 - break; 4802 - } 4803 - 4804 - /* 4805 - * PASID is stored in different locations based on the 4806 - * granularity. 4807 - */ 4808 - if (inv_info->granularity == IOMMU_INV_GRANU_PASID && 4809 - (inv_info->granu.pasid_info.flags & IOMMU_INV_PASID_FLAGS_PASID)) 4810 - pasid = inv_info->granu.pasid_info.pasid; 4811 - else if (inv_info->granularity == IOMMU_INV_GRANU_ADDR && 4812 - (inv_info->granu.addr_info.flags & IOMMU_INV_ADDR_FLAGS_PASID)) 4813 - pasid = inv_info->granu.addr_info.pasid; 4814 - 4815 - switch (BIT(cache_type)) { 4816 - case IOMMU_CACHE_INV_TYPE_IOTLB: 4817 - /* HW will ignore LSB bits based on address mask */ 4818 - if (inv_info->granularity == IOMMU_INV_GRANU_ADDR && 4819 - size && 4820 - (inv_info->granu.addr_info.addr & ((BIT(VTD_PAGE_SHIFT + size)) - 1))) { 4821 - pr_err_ratelimited("User address not aligned, 0x%llx, size order %llu\n", 4822 - inv_info->granu.addr_info.addr, size); 4823 - } 4824 - 4825 - /* 4826 - * If granu is PASID-selective, address is ignored. 4827 - * We use npages = -1 to indicate that. 4828 - */ 4829 - qi_flush_piotlb(iommu, did, pasid, 4830 - mm_to_dma_pfn(inv_info->granu.addr_info.addr), 4831 - (granu == QI_GRAN_NONG_PASID) ? -1 : 1 << size, 4832 - inv_info->granu.addr_info.flags & IOMMU_INV_ADDR_FLAGS_LEAF); 4833 - 4834 - if (!info->ats_enabled) 4835 - break; 4836 - /* 4837 - * Always flush device IOTLB if ATS is enabled. vIOMMU 4838 - * in the guest may assume IOTLB flush is inclusive, 4839 - * which is more efficient. 4840 - */ 4841 - fallthrough; 4842 - case IOMMU_CACHE_INV_TYPE_DEV_IOTLB: 4843 - /* 4844 - * PASID based device TLB invalidation does not support 4845 - * IOMMU_INV_GRANU_PASID granularity but only supports 4846 - * IOMMU_INV_GRANU_ADDR. 4847 - * The equivalent of that is we set the size to be the 4848 - * entire range of 64 bit. User only provides PASID info 4849 - * without address info. So we set addr to 0. 4850 - */ 4851 - if (inv_info->granularity == IOMMU_INV_GRANU_PASID) { 4852 - size = 64 - VTD_PAGE_SHIFT; 4853 - addr = 0; 4854 - } else if (inv_info->granularity == IOMMU_INV_GRANU_ADDR) { 4855 - addr = inv_info->granu.addr_info.addr; 4856 - } 4857 - 4858 - if (info->ats_enabled) 4859 - qi_flush_dev_iotlb_pasid(iommu, sid, 4860 - info->pfsid, pasid, 4861 - info->ats_qdep, addr, 4862 - size); 4863 - else 4864 - pr_warn_ratelimited("Passdown device IOTLB flush w/o ATS!\n"); 4865 - break; 4866 - default: 4867 - dev_err_ratelimited(dev, "Unsupported IOMMU invalidation type %d\n", 4868 - cache_type); 4869 - ret = -EINVAL; 4870 - } 4871 - } 4872 - out_unlock: 4873 - spin_unlock(&iommu->lock); 4874 - spin_unlock_irqrestore(&device_domain_lock, flags); 4875 - 4876 - return ret; 4877 - } 4878 - #endif 4879 4900 4880 4901 static int intel_iommu_map(struct iommu_domain *domain, 4881 4902 unsigned long iova, phys_addr_t hpa, ··· 4970 5391 return generic_device_group(dev); 4971 5392 } 4972 5393 4973 - static int intel_iommu_enable_auxd(struct device *dev) 4974 - { 4975 - struct device_domain_info *info; 4976 - struct intel_iommu *iommu; 4977 - unsigned long flags; 4978 - int ret; 4979 - 4980 - iommu = device_to_iommu(dev, NULL, NULL); 4981 - if (!iommu || dmar_disabled) 4982 - return -EINVAL; 4983 - 4984 - if (!sm_supported(iommu) || !pasid_supported(iommu)) 4985 - return -EINVAL; 4986 - 4987 - ret = intel_iommu_enable_pasid(iommu, dev); 4988 - if (ret) 4989 - return -ENODEV; 4990 - 4991 - spin_lock_irqsave(&device_domain_lock, flags); 4992 - info = get_domain_info(dev); 4993 - info->auxd_enabled = 1; 4994 - spin_unlock_irqrestore(&device_domain_lock, flags); 4995 - 4996 - return 0; 4997 - } 4998 - 4999 - static int intel_iommu_disable_auxd(struct device *dev) 5000 - { 5001 - struct device_domain_info *info; 5002 - unsigned long flags; 5003 - 5004 - spin_lock_irqsave(&device_domain_lock, flags); 5005 - info = get_domain_info(dev); 5006 - if (!WARN_ON(!info)) 5007 - info->auxd_enabled = 0; 5008 - spin_unlock_irqrestore(&device_domain_lock, flags); 5009 - 5010 - return 0; 5011 - } 5012 - 5013 5394 static int intel_iommu_enable_sva(struct device *dev) 5014 5395 { 5015 5396 struct device_domain_info *info = get_domain_info(dev); ··· 5026 5487 intel_iommu_dev_enable_feat(struct device *dev, enum iommu_dev_features feat) 5027 5488 { 5028 5489 switch (feat) { 5029 - case IOMMU_DEV_FEAT_AUX: 5030 - return intel_iommu_enable_auxd(dev); 5031 - 5032 5490 case IOMMU_DEV_FEAT_IOPF: 5033 5491 return intel_iommu_enable_iopf(dev); 5034 5492 ··· 5041 5505 intel_iommu_dev_disable_feat(struct device *dev, enum iommu_dev_features feat) 5042 5506 { 5043 5507 switch (feat) { 5044 - case IOMMU_DEV_FEAT_AUX: 5045 - return intel_iommu_disable_auxd(dev); 5046 - 5047 5508 case IOMMU_DEV_FEAT_IOPF: 5048 5509 return 0; 5049 5510 ··· 5052 5519 } 5053 5520 } 5054 5521 5055 - static bool 5056 - intel_iommu_dev_feat_enabled(struct device *dev, enum iommu_dev_features feat) 5057 - { 5058 - struct device_domain_info *info = get_domain_info(dev); 5059 - 5060 - if (feat == IOMMU_DEV_FEAT_AUX) 5061 - return scalable_mode_support() && info && info->auxd_enabled; 5062 - 5063 - return false; 5064 - } 5065 - 5066 - static int 5067 - intel_iommu_aux_get_pasid(struct iommu_domain *domain, struct device *dev) 5068 - { 5069 - struct dmar_domain *dmar_domain = to_dmar_domain(domain); 5070 - 5071 - return dmar_domain->default_pasid > 0 ? 5072 - dmar_domain->default_pasid : -EINVAL; 5073 - } 5074 - 5075 - static bool intel_iommu_is_attach_deferred(struct iommu_domain *domain, 5076 - struct device *dev) 5522 + static bool intel_iommu_is_attach_deferred(struct device *dev) 5077 5523 { 5078 5524 return attach_deferred(dev); 5079 - } 5080 - 5081 - static int 5082 - intel_iommu_enable_nesting(struct iommu_domain *domain) 5083 - { 5084 - struct dmar_domain *dmar_domain = to_dmar_domain(domain); 5085 - unsigned long flags; 5086 - int ret = -ENODEV; 5087 - 5088 - spin_lock_irqsave(&device_domain_lock, flags); 5089 - if (list_empty(&dmar_domain->devices)) { 5090 - dmar_domain->flags |= DOMAIN_FLAG_NESTING_MODE; 5091 - dmar_domain->flags &= ~DOMAIN_FLAG_USE_FIRST_LEVEL; 5092 - ret = 0; 5093 - } 5094 - spin_unlock_irqrestore(&device_domain_lock, flags); 5095 - 5096 - return ret; 5097 5525 } 5098 5526 5099 5527 /* ··· 5092 5598 const struct iommu_ops intel_iommu_ops = { 5093 5599 .capable = intel_iommu_capable, 5094 5600 .domain_alloc = intel_iommu_domain_alloc, 5095 - .domain_free = intel_iommu_domain_free, 5096 - .enable_nesting = intel_iommu_enable_nesting, 5097 - .attach_dev = intel_iommu_attach_device, 5098 - .detach_dev = intel_iommu_detach_device, 5099 - .aux_attach_dev = intel_iommu_aux_attach_device, 5100 - .aux_detach_dev = intel_iommu_aux_detach_device, 5101 - .aux_get_pasid = intel_iommu_aux_get_pasid, 5102 - .map_pages = intel_iommu_map_pages, 5103 - .unmap_pages = intel_iommu_unmap_pages, 5104 - .iotlb_sync_map = intel_iommu_iotlb_sync_map, 5105 - .flush_iotlb_all = intel_flush_iotlb_all, 5106 - .iotlb_sync = intel_iommu_tlb_sync, 5107 - .iova_to_phys = intel_iommu_iova_to_phys, 5108 5601 .probe_device = intel_iommu_probe_device, 5109 5602 .probe_finalize = intel_iommu_probe_finalize, 5110 5603 .release_device = intel_iommu_release_device, 5111 5604 .get_resv_regions = intel_iommu_get_resv_regions, 5112 5605 .put_resv_regions = generic_iommu_put_resv_regions, 5113 5606 .device_group = intel_iommu_device_group, 5114 - .dev_feat_enabled = intel_iommu_dev_feat_enabled, 5115 5607 .dev_enable_feat = intel_iommu_dev_enable_feat, 5116 5608 .dev_disable_feat = intel_iommu_dev_disable_feat, 5117 5609 .is_attach_deferred = intel_iommu_is_attach_deferred, 5118 5610 .def_domain_type = device_def_domain_type, 5119 5611 .pgsize_bitmap = SZ_4K, 5120 5612 #ifdef CONFIG_INTEL_IOMMU_SVM 5121 - .cache_invalidate = intel_iommu_sva_invalidate, 5122 - .sva_bind_gpasid = intel_svm_bind_gpasid, 5123 - .sva_unbind_gpasid = intel_svm_unbind_gpasid, 5124 5613 .sva_bind = intel_svm_bind, 5125 5614 .sva_unbind = intel_svm_unbind, 5126 5615 .sva_get_pasid = intel_svm_get_pasid, 5127 5616 .page_response = intel_svm_page_response, 5128 5617 #endif 5618 + .default_domain_ops = &(const struct iommu_domain_ops) { 5619 + .attach_dev = intel_iommu_attach_device, 5620 + .detach_dev = intel_iommu_detach_device, 5621 + .map_pages = intel_iommu_map_pages, 5622 + .unmap_pages = intel_iommu_unmap_pages, 5623 + .iotlb_sync_map = intel_iommu_iotlb_sync_map, 5624 + .flush_iotlb_all = intel_flush_iotlb_all, 5625 + .iotlb_sync = intel_iommu_tlb_sync, 5626 + .iova_to_phys = intel_iommu_iova_to_phys, 5627 + .free = intel_iommu_domain_free, 5628 + } 5129 5629 }; 5130 5630 5131 5631 static void quirk_iommu_igfx(struct pci_dev *dev)
-161
drivers/iommu/intel/pasid.c
··· 762 762 763 763 return 0; 764 764 } 765 - 766 - static int 767 - intel_pasid_setup_bind_data(struct intel_iommu *iommu, struct pasid_entry *pte, 768 - struct iommu_gpasid_bind_data_vtd *pasid_data) 769 - { 770 - /* 771 - * Not all guest PASID table entry fields are passed down during bind, 772 - * here we only set up the ones that are dependent on guest settings. 773 - * Execution related bits such as NXE, SMEP are not supported. 774 - * Other fields, such as snoop related, are set based on host needs 775 - * regardless of guest settings. 776 - */ 777 - if (pasid_data->flags & IOMMU_SVA_VTD_GPASID_SRE) { 778 - if (!ecap_srs(iommu->ecap)) { 779 - pr_err_ratelimited("No supervisor request support on %s\n", 780 - iommu->name); 781 - return -EINVAL; 782 - } 783 - pasid_set_sre(pte); 784 - /* Enable write protect WP if guest requested */ 785 - if (pasid_data->flags & IOMMU_SVA_VTD_GPASID_WPE) 786 - pasid_set_wpe(pte); 787 - } 788 - 789 - if (pasid_data->flags & IOMMU_SVA_VTD_GPASID_EAFE) { 790 - if (!ecap_eafs(iommu->ecap)) { 791 - pr_err_ratelimited("No extended access flag support on %s\n", 792 - iommu->name); 793 - return -EINVAL; 794 - } 795 - pasid_set_eafe(pte); 796 - } 797 - 798 - /* 799 - * Memory type is only applicable to devices inside processor coherent 800 - * domain. Will add MTS support once coherent devices are available. 801 - */ 802 - if (pasid_data->flags & IOMMU_SVA_VTD_GPASID_MTS_MASK) { 803 - pr_warn_ratelimited("No memory type support %s\n", 804 - iommu->name); 805 - return -EINVAL; 806 - } 807 - 808 - return 0; 809 - } 810 - 811 - /** 812 - * intel_pasid_setup_nested() - Set up PASID entry for nested translation. 813 - * This could be used for guest shared virtual address. In this case, the 814 - * first level page tables are used for GVA-GPA translation in the guest, 815 - * second level page tables are used for GPA-HPA translation. 816 - * 817 - * @iommu: IOMMU which the device belong to 818 - * @dev: Device to be set up for translation 819 - * @gpgd: FLPTPTR: First Level Page translation pointer in GPA 820 - * @pasid: PASID to be programmed in the device PASID table 821 - * @pasid_data: Additional PASID info from the guest bind request 822 - * @domain: Domain info for setting up second level page tables 823 - * @addr_width: Address width of the first level (guest) 824 - */ 825 - int intel_pasid_setup_nested(struct intel_iommu *iommu, struct device *dev, 826 - pgd_t *gpgd, u32 pasid, 827 - struct iommu_gpasid_bind_data_vtd *pasid_data, 828 - struct dmar_domain *domain, int addr_width) 829 - { 830 - struct pasid_entry *pte; 831 - struct dma_pte *pgd; 832 - int ret = 0; 833 - u64 pgd_val; 834 - int agaw; 835 - u16 did; 836 - 837 - if (!ecap_nest(iommu->ecap)) { 838 - pr_err_ratelimited("IOMMU: %s: No nested translation support\n", 839 - iommu->name); 840 - return -EINVAL; 841 - } 842 - 843 - if (!(domain->flags & DOMAIN_FLAG_NESTING_MODE)) { 844 - pr_err_ratelimited("Domain is not in nesting mode, %x\n", 845 - domain->flags); 846 - return -EINVAL; 847 - } 848 - 849 - pte = intel_pasid_get_entry(dev, pasid); 850 - if (WARN_ON(!pte)) 851 - return -EINVAL; 852 - 853 - /* 854 - * Caller must ensure PASID entry is not in use, i.e. not bind the 855 - * same PASID to the same device twice. 856 - */ 857 - if (pasid_pte_is_present(pte)) 858 - return -EBUSY; 859 - 860 - pasid_clear_entry(pte); 861 - 862 - /* Sanity checking performed by caller to make sure address 863 - * width matching in two dimensions: 864 - * 1. CPU vs. IOMMU 865 - * 2. Guest vs. Host. 866 - */ 867 - switch (addr_width) { 868 - #ifdef CONFIG_X86 869 - case ADDR_WIDTH_5LEVEL: 870 - if (!cpu_feature_enabled(X86_FEATURE_LA57) || 871 - !cap_5lp_support(iommu->cap)) { 872 - dev_err_ratelimited(dev, 873 - "5-level paging not supported\n"); 874 - return -EINVAL; 875 - } 876 - 877 - pasid_set_flpm(pte, 1); 878 - break; 879 - #endif 880 - case ADDR_WIDTH_4LEVEL: 881 - pasid_set_flpm(pte, 0); 882 - break; 883 - default: 884 - dev_err_ratelimited(dev, "Invalid guest address width %d\n", 885 - addr_width); 886 - return -EINVAL; 887 - } 888 - 889 - /* First level PGD is in GPA, must be supported by the second level */ 890 - if ((uintptr_t)gpgd > domain->max_addr) { 891 - dev_err_ratelimited(dev, 892 - "Guest PGD %lx not supported, max %llx\n", 893 - (uintptr_t)gpgd, domain->max_addr); 894 - return -EINVAL; 895 - } 896 - pasid_set_flptr(pte, (uintptr_t)gpgd); 897 - 898 - ret = intel_pasid_setup_bind_data(iommu, pte, pasid_data); 899 - if (ret) 900 - return ret; 901 - 902 - /* Setup the second level based on the given domain */ 903 - pgd = domain->pgd; 904 - 905 - agaw = iommu_skip_agaw(domain, iommu, &pgd); 906 - if (agaw < 0) { 907 - dev_err_ratelimited(dev, "Invalid domain page table\n"); 908 - return -EINVAL; 909 - } 910 - pgd_val = virt_to_phys(pgd); 911 - pasid_set_slptr(pte, pgd_val); 912 - pasid_set_fault_enable(pte); 913 - 914 - did = domain->iommu_did[iommu->seq_id]; 915 - pasid_set_domain_id(pte, did); 916 - 917 - pasid_set_address_width(pte, agaw); 918 - pasid_set_page_snoop(pte, !!ecap_smpwc(iommu->ecap)); 919 - 920 - pasid_set_translation_type(pte, PASID_ENTRY_PGTT_NESTED); 921 - pasid_set_present(pte); 922 - pasid_flush_caches(iommu, pte, pasid, did); 923 - 924 - return ret; 925 - }
-4
drivers/iommu/intel/pasid.h
··· 118 118 int intel_pasid_setup_pass_through(struct intel_iommu *iommu, 119 119 struct dmar_domain *domain, 120 120 struct device *dev, u32 pasid); 121 - int intel_pasid_setup_nested(struct intel_iommu *iommu, 122 - struct device *dev, pgd_t *pgd, u32 pasid, 123 - struct iommu_gpasid_bind_data_vtd *pasid_data, 124 - struct dmar_domain *domain, int addr_width); 125 121 void intel_pasid_tear_down_entry(struct intel_iommu *iommu, 126 122 struct device *dev, u32 pasid, 127 123 bool fault_ignore);
-209
drivers/iommu/intel/svm.c
··· 318 318 return 0; 319 319 } 320 320 321 - int intel_svm_bind_gpasid(struct iommu_domain *domain, struct device *dev, 322 - struct iommu_gpasid_bind_data *data) 323 - { 324 - struct intel_iommu *iommu = device_to_iommu(dev, NULL, NULL); 325 - struct intel_svm_dev *sdev = NULL; 326 - struct dmar_domain *dmar_domain; 327 - struct device_domain_info *info; 328 - struct intel_svm *svm = NULL; 329 - unsigned long iflags; 330 - int ret = 0; 331 - 332 - if (WARN_ON(!iommu) || !data) 333 - return -EINVAL; 334 - 335 - if (data->format != IOMMU_PASID_FORMAT_INTEL_VTD) 336 - return -EINVAL; 337 - 338 - /* IOMMU core ensures argsz is more than the start of the union */ 339 - if (data->argsz < offsetofend(struct iommu_gpasid_bind_data, vendor.vtd)) 340 - return -EINVAL; 341 - 342 - /* Make sure no undefined flags are used in vendor data */ 343 - if (data->vendor.vtd.flags & ~(IOMMU_SVA_VTD_GPASID_LAST - 1)) 344 - return -EINVAL; 345 - 346 - if (!dev_is_pci(dev)) 347 - return -ENOTSUPP; 348 - 349 - /* VT-d supports devices with full 20 bit PASIDs only */ 350 - if (pci_max_pasids(to_pci_dev(dev)) != PASID_MAX) 351 - return -EINVAL; 352 - 353 - /* 354 - * We only check host PASID range, we have no knowledge to check 355 - * guest PASID range. 356 - */ 357 - if (data->hpasid <= 0 || data->hpasid >= PASID_MAX) 358 - return -EINVAL; 359 - 360 - info = get_domain_info(dev); 361 - if (!info) 362 - return -EINVAL; 363 - 364 - dmar_domain = to_dmar_domain(domain); 365 - 366 - mutex_lock(&pasid_mutex); 367 - ret = pasid_to_svm_sdev(dev, data->hpasid, &svm, &sdev); 368 - if (ret) 369 - goto out; 370 - 371 - if (sdev) { 372 - /* 373 - * Do not allow multiple bindings of the same device-PASID since 374 - * there is only one SL page tables per PASID. We may revisit 375 - * once sharing PGD across domains are supported. 376 - */ 377 - dev_warn_ratelimited(dev, "Already bound with PASID %u\n", 378 - svm->pasid); 379 - ret = -EBUSY; 380 - goto out; 381 - } 382 - 383 - if (!svm) { 384 - /* We come here when PASID has never been bond to a device. */ 385 - svm = kzalloc(sizeof(*svm), GFP_KERNEL); 386 - if (!svm) { 387 - ret = -ENOMEM; 388 - goto out; 389 - } 390 - /* REVISIT: upper layer/VFIO can track host process that bind 391 - * the PASID. ioasid_set = mm might be sufficient for vfio to 392 - * check pasid VMM ownership. We can drop the following line 393 - * once VFIO and IOASID set check is in place. 394 - */ 395 - svm->mm = get_task_mm(current); 396 - svm->pasid = data->hpasid; 397 - if (data->flags & IOMMU_SVA_GPASID_VAL) { 398 - svm->gpasid = data->gpasid; 399 - svm->flags |= SVM_FLAG_GUEST_PASID; 400 - } 401 - pasid_private_add(data->hpasid, svm); 402 - INIT_LIST_HEAD_RCU(&svm->devs); 403 - mmput(svm->mm); 404 - } 405 - sdev = kzalloc(sizeof(*sdev), GFP_KERNEL); 406 - if (!sdev) { 407 - ret = -ENOMEM; 408 - goto out; 409 - } 410 - sdev->dev = dev; 411 - sdev->sid = PCI_DEVID(info->bus, info->devfn); 412 - sdev->iommu = iommu; 413 - 414 - /* Only count users if device has aux domains */ 415 - if (iommu_dev_feature_enabled(dev, IOMMU_DEV_FEAT_AUX)) 416 - sdev->users = 1; 417 - 418 - /* Set up device context entry for PASID if not enabled already */ 419 - ret = intel_iommu_enable_pasid(iommu, sdev->dev); 420 - if (ret) { 421 - dev_err_ratelimited(dev, "Failed to enable PASID capability\n"); 422 - kfree(sdev); 423 - goto out; 424 - } 425 - 426 - /* 427 - * PASID table is per device for better security. Therefore, for 428 - * each bind of a new device even with an existing PASID, we need to 429 - * call the nested mode setup function here. 430 - */ 431 - spin_lock_irqsave(&iommu->lock, iflags); 432 - ret = intel_pasid_setup_nested(iommu, dev, 433 - (pgd_t *)(uintptr_t)data->gpgd, 434 - data->hpasid, &data->vendor.vtd, dmar_domain, 435 - data->addr_width); 436 - spin_unlock_irqrestore(&iommu->lock, iflags); 437 - if (ret) { 438 - dev_err_ratelimited(dev, "Failed to set up PASID %llu in nested mode, Err %d\n", 439 - data->hpasid, ret); 440 - /* 441 - * PASID entry should be in cleared state if nested mode 442 - * set up failed. So we only need to clear IOASID tracking 443 - * data such that free call will succeed. 444 - */ 445 - kfree(sdev); 446 - goto out; 447 - } 448 - 449 - svm->flags |= SVM_FLAG_GUEST_MODE; 450 - 451 - init_rcu_head(&sdev->rcu); 452 - list_add_rcu(&sdev->list, &svm->devs); 453 - out: 454 - if (!IS_ERR_OR_NULL(svm) && list_empty(&svm->devs)) { 455 - pasid_private_remove(data->hpasid); 456 - kfree(svm); 457 - } 458 - 459 - mutex_unlock(&pasid_mutex); 460 - return ret; 461 - } 462 - 463 - int intel_svm_unbind_gpasid(struct device *dev, u32 pasid) 464 - { 465 - struct intel_iommu *iommu = device_to_iommu(dev, NULL, NULL); 466 - struct intel_svm_dev *sdev; 467 - struct intel_svm *svm; 468 - int ret; 469 - 470 - if (WARN_ON(!iommu)) 471 - return -EINVAL; 472 - 473 - mutex_lock(&pasid_mutex); 474 - ret = pasid_to_svm_sdev(dev, pasid, &svm, &sdev); 475 - if (ret) 476 - goto out; 477 - 478 - if (sdev) { 479 - if (iommu_dev_feature_enabled(dev, IOMMU_DEV_FEAT_AUX)) 480 - sdev->users--; 481 - if (!sdev->users) { 482 - list_del_rcu(&sdev->list); 483 - intel_pasid_tear_down_entry(iommu, dev, 484 - svm->pasid, false); 485 - intel_svm_drain_prq(dev, svm->pasid); 486 - kfree_rcu(sdev, rcu); 487 - 488 - if (list_empty(&svm->devs)) { 489 - /* 490 - * We do not free the IOASID here in that 491 - * IOMMU driver did not allocate it. 492 - * Unlike native SVM, IOASID for guest use was 493 - * allocated prior to the bind call. 494 - * In any case, if the free call comes before 495 - * the unbind, IOMMU driver will get notified 496 - * and perform cleanup. 497 - */ 498 - pasid_private_remove(pasid); 499 - kfree(svm); 500 - } 501 - } 502 - } 503 - out: 504 - mutex_unlock(&pasid_mutex); 505 - return ret; 506 - } 507 - 508 321 static int intel_svm_alloc_pasid(struct device *dev, struct mm_struct *mm, 509 322 unsigned int flags) 510 323 { ··· 936 1123 if (ret || !sdev) { 937 1124 ret = -ENODEV; 938 1125 goto out; 939 - } 940 - 941 - /* 942 - * For responses from userspace, need to make sure that the 943 - * pasid has been bound to its mm. 944 - */ 945 - if (svm->flags & SVM_FLAG_GUEST_MODE) { 946 - struct mm_struct *mm; 947 - 948 - mm = get_task_mm(current); 949 - if (!mm) { 950 - ret = -EINVAL; 951 - goto out; 952 - } 953 - 954 - if (mm != svm->mm) { 955 - ret = -ENODEV; 956 - mmput(mm); 957 - goto out; 958 - } 959 - 960 - mmput(mm); 961 1126 } 962 1127 963 1128 /*
+39 -300
drivers/iommu/iommu.c
··· 323 323 324 324 void iommu_release_device(struct device *dev) 325 325 { 326 - const struct iommu_ops *ops = dev->bus->iommu_ops; 326 + const struct iommu_ops *ops; 327 327 328 328 if (!dev->iommu) 329 329 return; 330 330 331 331 iommu_device_unlink(dev->iommu->iommu_dev, dev); 332 332 333 + ops = dev_iommu_ops(dev); 333 334 ops->release_device(dev); 334 335 335 336 iommu_group_remove_device(dev); ··· 791 790 dma_addr_t start, end, addr; 792 791 size_t map_size = 0; 793 792 794 - if (domain->ops->apply_resv_region) 795 - domain->ops->apply_resv_region(dev, domain, entry); 796 - 797 793 start = ALIGN(entry->start, pg_size); 798 794 end = ALIGN(entry->start + entry->length, pg_size); 799 795 ··· 831 833 return ret; 832 834 } 833 835 834 - static bool iommu_is_attach_deferred(struct iommu_domain *domain, 835 - struct device *dev) 836 + static bool iommu_is_attach_deferred(struct device *dev) 836 837 { 837 - if (domain->ops->is_attach_deferred) 838 - return domain->ops->is_attach_deferred(domain, dev); 838 + const struct iommu_ops *ops = dev_iommu_ops(dev); 839 + 840 + if (ops->is_attach_deferred) 841 + return ops->is_attach_deferred(dev); 839 842 840 843 return false; 841 844 } ··· 893 894 894 895 mutex_lock(&group->mutex); 895 896 list_add_tail(&device->list, &group->devices); 896 - if (group->domain && !iommu_is_attach_deferred(group->domain, dev)) 897 + if (group->domain && !iommu_is_attach_deferred(dev)) 897 898 ret = __iommu_attach_device(group->domain, dev); 898 899 mutex_unlock(&group->mutex); 899 900 if (ret) ··· 1254 1255 struct iommu_fault_event *evt; 1255 1256 struct iommu_fault_page_request *prm; 1256 1257 struct dev_iommu *param = dev->iommu; 1258 + const struct iommu_ops *ops = dev_iommu_ops(dev); 1257 1259 bool has_pasid = msg->flags & IOMMU_PAGE_RESP_PASID_VALID; 1258 - struct iommu_domain *domain = iommu_get_domain_for_dev(dev); 1259 1260 1260 - if (!domain || !domain->ops->page_response) 1261 + if (!ops->page_response) 1261 1262 return -ENODEV; 1262 1263 1263 1264 if (!param || !param->fault_param) ··· 1298 1299 msg->pasid = 0; 1299 1300 } 1300 1301 1301 - ret = domain->ops->page_response(dev, evt, msg); 1302 + ret = ops->page_response(dev, evt, msg); 1302 1303 list_del(&evt->list); 1303 1304 kfree(evt); 1304 1305 break; ··· 1523 1524 1524 1525 static int iommu_get_def_domain_type(struct device *dev) 1525 1526 { 1526 - const struct iommu_ops *ops = dev->bus->iommu_ops; 1527 + const struct iommu_ops *ops = dev_iommu_ops(dev); 1527 1528 1528 1529 if (dev_is_pci(dev) && to_pci_dev(dev)->untrusted) 1529 1530 return IOMMU_DOMAIN_DMA; ··· 1582 1583 */ 1583 1584 static struct iommu_group *iommu_group_get_for_dev(struct device *dev) 1584 1585 { 1585 - const struct iommu_ops *ops = dev->bus->iommu_ops; 1586 + const struct iommu_ops *ops = dev_iommu_ops(dev); 1586 1587 struct iommu_group *group; 1587 1588 int ret; 1588 1589 1589 1590 group = iommu_group_get(dev); 1590 1591 if (group) 1591 1592 return group; 1592 - 1593 - if (!ops) 1594 - return ERR_PTR(-EINVAL); 1595 1593 1596 1594 group = ops->device_group(dev); 1597 1595 if (WARN_ON_ONCE(group == NULL)) ··· 1744 1748 struct iommu_domain *domain = data; 1745 1749 int ret = 0; 1746 1750 1747 - if (!iommu_is_attach_deferred(domain, dev)) 1751 + if (!iommu_is_attach_deferred(dev)) 1748 1752 ret = __iommu_attach_device(domain, dev); 1749 1753 1750 1754 return ret; ··· 1758 1762 1759 1763 static int iommu_group_do_probe_finalize(struct device *dev, void *data) 1760 1764 { 1761 - struct iommu_domain *domain = data; 1765 + const struct iommu_ops *ops = dev_iommu_ops(dev); 1762 1766 1763 - if (domain->ops->probe_finalize) 1764 - domain->ops->probe_finalize(dev); 1767 + if (ops->probe_finalize) 1768 + ops->probe_finalize(dev); 1765 1769 1766 1770 return 0; 1767 1771 } ··· 1950 1954 if (!domain) 1951 1955 return NULL; 1952 1956 1953 - domain->ops = bus->iommu_ops; 1954 1957 domain->type = type; 1955 1958 /* Assume all sizes by default; the driver may override this later */ 1956 - domain->pgsize_bitmap = bus->iommu_ops->pgsize_bitmap; 1959 + domain->pgsize_bitmap = bus->iommu_ops->pgsize_bitmap; 1960 + if (!domain->ops) 1961 + domain->ops = bus->iommu_ops->default_domain_ops; 1957 1962 1958 1963 if (iommu_is_dma_domain(domain) && iommu_get_dma_cookie(domain)) { 1959 1964 iommu_domain_free(domain); ··· 1972 1975 void iommu_domain_free(struct iommu_domain *domain) 1973 1976 { 1974 1977 iommu_put_dma_cookie(domain); 1975 - domain->ops->domain_free(domain); 1978 + domain->ops->free(domain); 1976 1979 } 1977 1980 EXPORT_SYMBOL_GPL(iommu_domain_free); 1978 1981 ··· 2020 2023 2021 2024 int iommu_deferred_attach(struct device *dev, struct iommu_domain *domain) 2022 2025 { 2023 - const struct iommu_ops *ops = domain->ops; 2024 - 2025 - if (ops->is_attach_deferred && ops->is_attach_deferred(domain, dev)) 2026 + if (iommu_is_attach_deferred(dev)) 2026 2027 return __iommu_attach_device(domain, dev); 2027 2028 2028 2029 return 0; 2029 2030 } 2030 2031 2031 - /* 2032 - * Check flags and other user provided data for valid combinations. We also 2033 - * make sure no reserved fields or unused flags are set. This is to ensure 2034 - * not breaking userspace in the future when these fields or flags are used. 2035 - */ 2036 - static int iommu_check_cache_invl_data(struct iommu_cache_invalidate_info *info) 2037 - { 2038 - u32 mask; 2039 - int i; 2040 - 2041 - if (info->version != IOMMU_CACHE_INVALIDATE_INFO_VERSION_1) 2042 - return -EINVAL; 2043 - 2044 - mask = (1 << IOMMU_CACHE_INV_TYPE_NR) - 1; 2045 - if (info->cache & ~mask) 2046 - return -EINVAL; 2047 - 2048 - if (info->granularity >= IOMMU_INV_GRANU_NR) 2049 - return -EINVAL; 2050 - 2051 - switch (info->granularity) { 2052 - case IOMMU_INV_GRANU_ADDR: 2053 - if (info->cache & IOMMU_CACHE_INV_TYPE_PASID) 2054 - return -EINVAL; 2055 - 2056 - mask = IOMMU_INV_ADDR_FLAGS_PASID | 2057 - IOMMU_INV_ADDR_FLAGS_ARCHID | 2058 - IOMMU_INV_ADDR_FLAGS_LEAF; 2059 - 2060 - if (info->granu.addr_info.flags & ~mask) 2061 - return -EINVAL; 2062 - break; 2063 - case IOMMU_INV_GRANU_PASID: 2064 - mask = IOMMU_INV_PASID_FLAGS_PASID | 2065 - IOMMU_INV_PASID_FLAGS_ARCHID; 2066 - if (info->granu.pasid_info.flags & ~mask) 2067 - return -EINVAL; 2068 - 2069 - break; 2070 - case IOMMU_INV_GRANU_DOMAIN: 2071 - if (info->cache & IOMMU_CACHE_INV_TYPE_DEV_IOTLB) 2072 - return -EINVAL; 2073 - break; 2074 - default: 2075 - return -EINVAL; 2076 - } 2077 - 2078 - /* Check reserved padding fields */ 2079 - for (i = 0; i < sizeof(info->padding); i++) { 2080 - if (info->padding[i]) 2081 - return -EINVAL; 2082 - } 2083 - 2084 - return 0; 2085 - } 2086 - 2087 - int iommu_uapi_cache_invalidate(struct iommu_domain *domain, struct device *dev, 2088 - void __user *uinfo) 2089 - { 2090 - struct iommu_cache_invalidate_info inv_info = { 0 }; 2091 - u32 minsz; 2092 - int ret; 2093 - 2094 - if (unlikely(!domain->ops->cache_invalidate)) 2095 - return -ENODEV; 2096 - 2097 - /* 2098 - * No new spaces can be added before the variable sized union, the 2099 - * minimum size is the offset to the union. 2100 - */ 2101 - minsz = offsetof(struct iommu_cache_invalidate_info, granu); 2102 - 2103 - /* Copy minsz from user to get flags and argsz */ 2104 - if (copy_from_user(&inv_info, uinfo, minsz)) 2105 - return -EFAULT; 2106 - 2107 - /* Fields before the variable size union are mandatory */ 2108 - if (inv_info.argsz < minsz) 2109 - return -EINVAL; 2110 - 2111 - /* PASID and address granu require additional info beyond minsz */ 2112 - if (inv_info.granularity == IOMMU_INV_GRANU_PASID && 2113 - inv_info.argsz < offsetofend(struct iommu_cache_invalidate_info, granu.pasid_info)) 2114 - return -EINVAL; 2115 - 2116 - if (inv_info.granularity == IOMMU_INV_GRANU_ADDR && 2117 - inv_info.argsz < offsetofend(struct iommu_cache_invalidate_info, granu.addr_info)) 2118 - return -EINVAL; 2119 - 2120 - /* 2121 - * User might be using a newer UAPI header which has a larger data 2122 - * size, we shall support the existing flags within the current 2123 - * size. Copy the remaining user data _after_ minsz but not more 2124 - * than the current kernel supported size. 2125 - */ 2126 - if (copy_from_user((void *)&inv_info + minsz, uinfo + minsz, 2127 - min_t(u32, inv_info.argsz, sizeof(inv_info)) - minsz)) 2128 - return -EFAULT; 2129 - 2130 - /* Now the argsz is validated, check the content */ 2131 - ret = iommu_check_cache_invl_data(&inv_info); 2132 - if (ret) 2133 - return ret; 2134 - 2135 - return domain->ops->cache_invalidate(domain, dev, &inv_info); 2136 - } 2137 - EXPORT_SYMBOL_GPL(iommu_uapi_cache_invalidate); 2138 - 2139 - static int iommu_check_bind_data(struct iommu_gpasid_bind_data *data) 2140 - { 2141 - u64 mask; 2142 - int i; 2143 - 2144 - if (data->version != IOMMU_GPASID_BIND_VERSION_1) 2145 - return -EINVAL; 2146 - 2147 - /* Check the range of supported formats */ 2148 - if (data->format >= IOMMU_PASID_FORMAT_LAST) 2149 - return -EINVAL; 2150 - 2151 - /* Check all flags */ 2152 - mask = IOMMU_SVA_GPASID_VAL; 2153 - if (data->flags & ~mask) 2154 - return -EINVAL; 2155 - 2156 - /* Check reserved padding fields */ 2157 - for (i = 0; i < sizeof(data->padding); i++) { 2158 - if (data->padding[i]) 2159 - return -EINVAL; 2160 - } 2161 - 2162 - return 0; 2163 - } 2164 - 2165 - static int iommu_sva_prepare_bind_data(void __user *udata, 2166 - struct iommu_gpasid_bind_data *data) 2167 - { 2168 - u32 minsz; 2169 - 2170 - /* 2171 - * No new spaces can be added before the variable sized union, the 2172 - * minimum size is the offset to the union. 2173 - */ 2174 - minsz = offsetof(struct iommu_gpasid_bind_data, vendor); 2175 - 2176 - /* Copy minsz from user to get flags and argsz */ 2177 - if (copy_from_user(data, udata, minsz)) 2178 - return -EFAULT; 2179 - 2180 - /* Fields before the variable size union are mandatory */ 2181 - if (data->argsz < minsz) 2182 - return -EINVAL; 2183 - /* 2184 - * User might be using a newer UAPI header, we shall let IOMMU vendor 2185 - * driver decide on what size it needs. Since the guest PASID bind data 2186 - * can be vendor specific, larger argsz could be the result of extension 2187 - * for one vendor but it should not affect another vendor. 2188 - * Copy the remaining user data _after_ minsz 2189 - */ 2190 - if (copy_from_user((void *)data + minsz, udata + minsz, 2191 - min_t(u32, data->argsz, sizeof(*data)) - minsz)) 2192 - return -EFAULT; 2193 - 2194 - return iommu_check_bind_data(data); 2195 - } 2196 - 2197 - int iommu_uapi_sva_bind_gpasid(struct iommu_domain *domain, struct device *dev, 2198 - void __user *udata) 2199 - { 2200 - struct iommu_gpasid_bind_data data = { 0 }; 2201 - int ret; 2202 - 2203 - if (unlikely(!domain->ops->sva_bind_gpasid)) 2204 - return -ENODEV; 2205 - 2206 - ret = iommu_sva_prepare_bind_data(udata, &data); 2207 - if (ret) 2208 - return ret; 2209 - 2210 - return domain->ops->sva_bind_gpasid(domain, dev, &data); 2211 - } 2212 - EXPORT_SYMBOL_GPL(iommu_uapi_sva_bind_gpasid); 2213 - 2214 - int iommu_sva_unbind_gpasid(struct iommu_domain *domain, struct device *dev, 2215 - ioasid_t pasid) 2216 - { 2217 - if (unlikely(!domain->ops->sva_unbind_gpasid)) 2218 - return -ENODEV; 2219 - 2220 - return domain->ops->sva_unbind_gpasid(dev, pasid); 2221 - } 2222 - EXPORT_SYMBOL_GPL(iommu_sva_unbind_gpasid); 2223 - 2224 - int iommu_uapi_sva_unbind_gpasid(struct iommu_domain *domain, struct device *dev, 2225 - void __user *udata) 2226 - { 2227 - struct iommu_gpasid_bind_data data = { 0 }; 2228 - int ret; 2229 - 2230 - if (unlikely(!domain->ops->sva_bind_gpasid)) 2231 - return -ENODEV; 2232 - 2233 - ret = iommu_sva_prepare_bind_data(udata, &data); 2234 - if (ret) 2235 - return ret; 2236 - 2237 - return iommu_sva_unbind_gpasid(domain, dev, data.hpasid); 2238 - } 2239 - EXPORT_SYMBOL_GPL(iommu_uapi_sva_unbind_gpasid); 2240 - 2241 2032 static void __iommu_detach_device(struct iommu_domain *domain, 2242 2033 struct device *dev) 2243 2034 { 2244 - if (iommu_is_attach_deferred(domain, dev)) 2035 + if (iommu_is_attach_deferred(dev)) 2245 2036 return; 2246 2037 2247 2038 if (unlikely(domain->ops->detach_dev == NULL)) ··· 2243 2458 phys_addr_t paddr, size_t size, int prot, 2244 2459 gfp_t gfp, size_t *mapped) 2245 2460 { 2246 - const struct iommu_ops *ops = domain->ops; 2461 + const struct iommu_domain_ops *ops = domain->ops; 2247 2462 size_t pgsize, count; 2248 2463 int ret; 2249 2464 ··· 2266 2481 static int __iommu_map(struct iommu_domain *domain, unsigned long iova, 2267 2482 phys_addr_t paddr, size_t size, int prot, gfp_t gfp) 2268 2483 { 2269 - const struct iommu_ops *ops = domain->ops; 2484 + const struct iommu_domain_ops *ops = domain->ops; 2270 2485 unsigned long orig_iova = iova; 2271 2486 unsigned int min_pagesz; 2272 2487 size_t orig_size = size; ··· 2326 2541 static int _iommu_map(struct iommu_domain *domain, unsigned long iova, 2327 2542 phys_addr_t paddr, size_t size, int prot, gfp_t gfp) 2328 2543 { 2329 - const struct iommu_ops *ops = domain->ops; 2544 + const struct iommu_domain_ops *ops = domain->ops; 2330 2545 int ret; 2331 2546 2332 2547 ret = __iommu_map(domain, iova, paddr, size, prot, gfp); ··· 2355 2570 unsigned long iova, size_t size, 2356 2571 struct iommu_iotlb_gather *iotlb_gather) 2357 2572 { 2358 - const struct iommu_ops *ops = domain->ops; 2573 + const struct iommu_domain_ops *ops = domain->ops; 2359 2574 size_t pgsize, count; 2360 2575 2361 2576 pgsize = iommu_pgsize(domain, iova, iova, size, &count); ··· 2368 2583 unsigned long iova, size_t size, 2369 2584 struct iommu_iotlb_gather *iotlb_gather) 2370 2585 { 2371 - const struct iommu_ops *ops = domain->ops; 2586 + const struct iommu_domain_ops *ops = domain->ops; 2372 2587 size_t unmapped_page, unmapped = 0; 2373 2588 unsigned long orig_iova = iova; 2374 2589 unsigned int min_pagesz; ··· 2444 2659 struct scatterlist *sg, unsigned int nents, int prot, 2445 2660 gfp_t gfp) 2446 2661 { 2447 - const struct iommu_ops *ops = domain->ops; 2662 + const struct iommu_domain_ops *ops = domain->ops; 2448 2663 size_t len = 0, mapped = 0; 2449 2664 phys_addr_t start; 2450 2665 unsigned int i = 0; ··· 2577 2792 2578 2793 void iommu_get_resv_regions(struct device *dev, struct list_head *list) 2579 2794 { 2580 - const struct iommu_ops *ops = dev->bus->iommu_ops; 2795 + const struct iommu_ops *ops = dev_iommu_ops(dev); 2581 2796 2582 - if (ops && ops->get_resv_regions) 2797 + if (ops->get_resv_regions) 2583 2798 ops->get_resv_regions(dev, list); 2584 2799 } 2585 2800 2586 2801 void iommu_put_resv_regions(struct device *dev, struct list_head *list) 2587 2802 { 2588 - const struct iommu_ops *ops = dev->bus->iommu_ops; 2803 + const struct iommu_ops *ops = dev_iommu_ops(dev); 2589 2804 2590 - if (ops && ops->put_resv_regions) 2805 + if (ops->put_resv_regions) 2591 2806 ops->put_resv_regions(dev, list); 2592 2807 } 2593 2808 ··· 2744 2959 2745 2960 /* 2746 2961 * The device drivers should do the necessary cleanups before calling this. 2747 - * For example, before disabling the aux-domain feature, the device driver 2748 - * should detach all aux-domains. Otherwise, this will return -EBUSY. 2749 2962 */ 2750 2963 int iommu_dev_disable_feature(struct device *dev, enum iommu_dev_features feat) 2751 2964 { ··· 2771 2988 } 2772 2989 EXPORT_SYMBOL_GPL(iommu_dev_feature_enabled); 2773 2990 2774 - /* 2775 - * Aux-domain specific attach/detach. 2776 - * 2777 - * Only works if iommu_dev_feature_enabled(dev, IOMMU_DEV_FEAT_AUX) returns 2778 - * true. Also, as long as domains are attached to a device through this 2779 - * interface, any tries to call iommu_attach_device() should fail 2780 - * (iommu_detach_device() can't fail, so we fail when trying to re-attach). 2781 - * This should make us safe against a device being attached to a guest as a 2782 - * whole while there are still pasid users on it (aux and sva). 2783 - */ 2784 - int iommu_aux_attach_device(struct iommu_domain *domain, struct device *dev) 2785 - { 2786 - int ret = -ENODEV; 2787 - 2788 - if (domain->ops->aux_attach_dev) 2789 - ret = domain->ops->aux_attach_dev(domain, dev); 2790 - 2791 - if (!ret) 2792 - trace_attach_device_to_domain(dev); 2793 - 2794 - return ret; 2795 - } 2796 - EXPORT_SYMBOL_GPL(iommu_aux_attach_device); 2797 - 2798 - void iommu_aux_detach_device(struct iommu_domain *domain, struct device *dev) 2799 - { 2800 - if (domain->ops->aux_detach_dev) { 2801 - domain->ops->aux_detach_dev(domain, dev); 2802 - trace_detach_device_from_domain(dev); 2803 - } 2804 - } 2805 - EXPORT_SYMBOL_GPL(iommu_aux_detach_device); 2806 - 2807 - int iommu_aux_get_pasid(struct iommu_domain *domain, struct device *dev) 2808 - { 2809 - int ret = -ENODEV; 2810 - 2811 - if (domain->ops->aux_get_pasid) 2812 - ret = domain->ops->aux_get_pasid(domain, dev); 2813 - 2814 - return ret; 2815 - } 2816 - EXPORT_SYMBOL_GPL(iommu_aux_get_pasid); 2817 - 2818 2991 /** 2819 2992 * iommu_sva_bind_device() - Bind a process address space to a device 2820 2993 * @dev: the device ··· 2792 3053 { 2793 3054 struct iommu_group *group; 2794 3055 struct iommu_sva *handle = ERR_PTR(-EINVAL); 2795 - const struct iommu_ops *ops = dev->bus->iommu_ops; 3056 + const struct iommu_ops *ops = dev_iommu_ops(dev); 2796 3057 2797 - if (!ops || !ops->sva_bind) 3058 + if (!ops->sva_bind) 2798 3059 return ERR_PTR(-ENODEV); 2799 3060 2800 3061 group = iommu_group_get(dev); ··· 2835 3096 { 2836 3097 struct iommu_group *group; 2837 3098 struct device *dev = handle->dev; 2838 - const struct iommu_ops *ops = dev->bus->iommu_ops; 3099 + const struct iommu_ops *ops = dev_iommu_ops(dev); 2839 3100 2840 - if (!ops || !ops->sva_unbind) 3101 + if (!ops->sva_unbind) 2841 3102 return; 2842 3103 2843 3104 group = iommu_group_get(dev); ··· 2854 3115 2855 3116 u32 iommu_sva_get_pasid(struct iommu_sva *handle) 2856 3117 { 2857 - const struct iommu_ops *ops = handle->dev->bus->iommu_ops; 3118 + const struct iommu_ops *ops = dev_iommu_ops(handle->dev); 2858 3119 2859 - if (!ops || !ops->sva_get_pasid) 3120 + if (!ops->sva_get_pasid) 2860 3121 return IOMMU_PASID_INVALID; 2861 3122 2862 3123 return ops->sva_get_pasid(handle);
+62 -16
drivers/iommu/iova.c
··· 15 15 /* The anchor node sits above the top of the usable address space */ 16 16 #define IOVA_ANCHOR ~0UL 17 17 18 + #define IOVA_RANGE_CACHE_MAX_SIZE 6 /* log of max cached IOVA range size (in pages) */ 19 + 18 20 static bool iova_rcache_insert(struct iova_domain *iovad, 19 21 unsigned long pfn, 20 22 unsigned long size); 21 23 static unsigned long iova_rcache_get(struct iova_domain *iovad, 22 24 unsigned long size, 23 25 unsigned long limit_pfn); 24 - static void init_iova_rcaches(struct iova_domain *iovad); 25 26 static void free_cpu_cached_iovas(unsigned int cpu, struct iova_domain *iovad); 26 27 static void free_iova_rcaches(struct iova_domain *iovad); 27 28 ··· 65 64 iovad->anchor.pfn_lo = iovad->anchor.pfn_hi = IOVA_ANCHOR; 66 65 rb_link_node(&iovad->anchor.node, NULL, &iovad->rbroot.rb_node); 67 66 rb_insert_color(&iovad->anchor.node, &iovad->rbroot); 68 - cpuhp_state_add_instance_nocalls(CPUHP_IOMMU_IOVA_DEAD, &iovad->cpuhp_dead); 69 - init_iova_rcaches(iovad); 70 67 } 71 68 EXPORT_SYMBOL_GPL(init_iova_domain); 72 69 ··· 94 95 cached_iova = to_iova(iovad->cached32_node); 95 96 if (free == cached_iova || 96 97 (free->pfn_hi < iovad->dma_32bit_pfn && 97 - free->pfn_lo >= cached_iova->pfn_lo)) { 98 + free->pfn_lo >= cached_iova->pfn_lo)) 98 99 iovad->cached32_node = rb_next(&free->node); 100 + 101 + if (free->pfn_lo < iovad->dma_32bit_pfn) 99 102 iovad->max32_alloc_size = iovad->dma_32bit_pfn; 100 - } 101 103 102 104 cached_iova = to_iova(iovad->cached_node); 103 105 if (free->pfn_lo >= cached_iova->pfn_lo) ··· 488 488 } 489 489 EXPORT_SYMBOL_GPL(free_iova_fast); 490 490 491 + static void iova_domain_free_rcaches(struct iova_domain *iovad) 492 + { 493 + cpuhp_state_remove_instance_nocalls(CPUHP_IOMMU_IOVA_DEAD, 494 + &iovad->cpuhp_dead); 495 + free_iova_rcaches(iovad); 496 + } 497 + 491 498 /** 492 499 * put_iova_domain - destroys the iova domain 493 500 * @iovad: - iova domain in question. ··· 504 497 { 505 498 struct iova *iova, *tmp; 506 499 507 - cpuhp_state_remove_instance_nocalls(CPUHP_IOMMU_IOVA_DEAD, 508 - &iovad->cpuhp_dead); 509 - free_iova_rcaches(iovad); 500 + if (iovad->rcaches) 501 + iova_domain_free_rcaches(iovad); 502 + 510 503 rbtree_postorder_for_each_entry_safe(iova, tmp, &iovad->rbroot, node) 511 504 free_iova_mem(iova); 512 505 } ··· 615 608 */ 616 609 617 610 #define IOVA_MAG_SIZE 128 611 + #define MAX_GLOBAL_MAGS 32 /* magazines per bin */ 618 612 619 613 struct iova_magazine { 620 614 unsigned long size; ··· 626 618 spinlock_t lock; 627 619 struct iova_magazine *loaded; 628 620 struct iova_magazine *prev; 621 + }; 622 + 623 + struct iova_rcache { 624 + spinlock_t lock; 625 + unsigned long depot_size; 626 + struct iova_magazine *depot[MAX_GLOBAL_MAGS]; 627 + struct iova_cpu_rcache __percpu *cpu_rcaches; 629 628 }; 630 629 631 630 static struct iova_magazine *iova_magazine_alloc(gfp_t flags) ··· 708 693 mag->pfns[mag->size++] = pfn; 709 694 } 710 695 711 - static void init_iova_rcaches(struct iova_domain *iovad) 696 + int iova_domain_init_rcaches(struct iova_domain *iovad) 712 697 { 713 - struct iova_cpu_rcache *cpu_rcache; 714 - struct iova_rcache *rcache; 715 698 unsigned int cpu; 716 - int i; 699 + int i, ret; 700 + 701 + iovad->rcaches = kcalloc(IOVA_RANGE_CACHE_MAX_SIZE, 702 + sizeof(struct iova_rcache), 703 + GFP_KERNEL); 704 + if (!iovad->rcaches) 705 + return -ENOMEM; 717 706 718 707 for (i = 0; i < IOVA_RANGE_CACHE_MAX_SIZE; ++i) { 708 + struct iova_cpu_rcache *cpu_rcache; 709 + struct iova_rcache *rcache; 710 + 719 711 rcache = &iovad->rcaches[i]; 720 712 spin_lock_init(&rcache->lock); 721 713 rcache->depot_size = 0; 722 - rcache->cpu_rcaches = __alloc_percpu(sizeof(*cpu_rcache), cache_line_size()); 723 - if (WARN_ON(!rcache->cpu_rcaches)) 724 - continue; 714 + rcache->cpu_rcaches = __alloc_percpu(sizeof(*cpu_rcache), 715 + cache_line_size()); 716 + if (!rcache->cpu_rcaches) { 717 + ret = -ENOMEM; 718 + goto out_err; 719 + } 725 720 for_each_possible_cpu(cpu) { 726 721 cpu_rcache = per_cpu_ptr(rcache->cpu_rcaches, cpu); 722 + 727 723 spin_lock_init(&cpu_rcache->lock); 728 724 cpu_rcache->loaded = iova_magazine_alloc(GFP_KERNEL); 729 725 cpu_rcache->prev = iova_magazine_alloc(GFP_KERNEL); 726 + if (!cpu_rcache->loaded || !cpu_rcache->prev) { 727 + ret = -ENOMEM; 728 + goto out_err; 729 + } 730 730 } 731 731 } 732 + 733 + ret = cpuhp_state_add_instance_nocalls(CPUHP_IOMMU_IOVA_DEAD, 734 + &iovad->cpuhp_dead); 735 + if (ret) 736 + goto out_err; 737 + return 0; 738 + 739 + out_err: 740 + free_iova_rcaches(iovad); 741 + return ret; 732 742 } 743 + EXPORT_SYMBOL_GPL(iova_domain_init_rcaches); 733 744 734 745 /* 735 746 * Try inserting IOVA range starting with 'iova_pfn' into 'rcache', and ··· 872 831 { 873 832 unsigned int log_size = order_base_2(size); 874 833 875 - if (log_size >= IOVA_RANGE_CACHE_MAX_SIZE) 834 + if (log_size >= IOVA_RANGE_CACHE_MAX_SIZE || !iovad->rcaches) 876 835 return 0; 877 836 878 837 return __iova_rcache_get(&iovad->rcaches[log_size], limit_pfn - size); ··· 890 849 891 850 for (i = 0; i < IOVA_RANGE_CACHE_MAX_SIZE; ++i) { 892 851 rcache = &iovad->rcaches[i]; 852 + if (!rcache->cpu_rcaches) 853 + break; 893 854 for_each_possible_cpu(cpu) { 894 855 cpu_rcache = per_cpu_ptr(rcache->cpu_rcaches, cpu); 895 856 iova_magazine_free(cpu_rcache->loaded); ··· 901 858 for (j = 0; j < rcache->depot_size; ++j) 902 859 iova_magazine_free(rcache->depot[j]); 903 860 } 861 + 862 + kfree(iovad->rcaches); 863 + iovad->rcaches = NULL; 904 864 } 905 865 906 866 /*
+10 -8
drivers/iommu/ipmmu-vmsa.c
··· 868 868 869 869 static const struct iommu_ops ipmmu_ops = { 870 870 .domain_alloc = ipmmu_domain_alloc, 871 - .domain_free = ipmmu_domain_free, 872 - .attach_dev = ipmmu_attach_device, 873 - .detach_dev = ipmmu_detach_device, 874 - .map = ipmmu_map, 875 - .unmap = ipmmu_unmap, 876 - .flush_iotlb_all = ipmmu_flush_iotlb_all, 877 - .iotlb_sync = ipmmu_iotlb_sync, 878 - .iova_to_phys = ipmmu_iova_to_phys, 879 871 .probe_device = ipmmu_probe_device, 880 872 .release_device = ipmmu_release_device, 881 873 .probe_finalize = ipmmu_probe_finalize, ··· 875 883 ? generic_device_group : ipmmu_find_group, 876 884 .pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K, 877 885 .of_xlate = ipmmu_of_xlate, 886 + .default_domain_ops = &(const struct iommu_domain_ops) { 887 + .attach_dev = ipmmu_attach_device, 888 + .detach_dev = ipmmu_detach_device, 889 + .map = ipmmu_map, 890 + .unmap = ipmmu_unmap, 891 + .flush_iotlb_all = ipmmu_flush_iotlb_all, 892 + .iotlb_sync = ipmmu_iotlb_sync, 893 + .iova_to_phys = ipmmu_iova_to_phys, 894 + .free = ipmmu_domain_free, 895 + } 878 896 }; 879 897 880 898 /* -----------------------------------------------------------------------------
+16 -20
drivers/iommu/msm_iommu.c
··· 558 558 return ret; 559 559 } 560 560 561 - static bool msm_iommu_capable(enum iommu_cap cap) 562 - { 563 - return false; 564 - } 565 - 566 561 static void print_ctx_regs(void __iomem *base, int ctx) 567 562 { 568 563 unsigned int fsr = GET_FSR(base, ctx); ··· 667 672 } 668 673 669 674 static struct iommu_ops msm_iommu_ops = { 670 - .capable = msm_iommu_capable, 671 675 .domain_alloc = msm_iommu_domain_alloc, 672 - .domain_free = msm_iommu_domain_free, 673 - .attach_dev = msm_iommu_attach_dev, 674 - .detach_dev = msm_iommu_detach_dev, 675 - .map = msm_iommu_map, 676 - .unmap = msm_iommu_unmap, 677 - /* 678 - * Nothing is needed here, the barrier to guarantee 679 - * completion of the tlb sync operation is implicitly 680 - * taken care when the iommu client does a writel before 681 - * kick starting the other master. 682 - */ 683 - .iotlb_sync = NULL, 684 - .iotlb_sync_map = msm_iommu_sync_map, 685 - .iova_to_phys = msm_iommu_iova_to_phys, 686 676 .probe_device = msm_iommu_probe_device, 687 677 .release_device = msm_iommu_release_device, 688 678 .device_group = generic_device_group, 689 679 .pgsize_bitmap = MSM_IOMMU_PGSIZES, 690 680 .of_xlate = qcom_iommu_of_xlate, 681 + .default_domain_ops = &(const struct iommu_domain_ops) { 682 + .attach_dev = msm_iommu_attach_dev, 683 + .detach_dev = msm_iommu_detach_dev, 684 + .map = msm_iommu_map, 685 + .unmap = msm_iommu_unmap, 686 + /* 687 + * Nothing is needed here, the barrier to guarantee 688 + * completion of the tlb sync operation is implicitly 689 + * taken care when the iommu client does a writel before 690 + * kick starting the other master. 691 + */ 692 + .iotlb_sync = NULL, 693 + .iotlb_sync_map = msm_iommu_sync_map, 694 + .iova_to_phys = msm_iommu_iova_to_phys, 695 + .free = msm_iommu_domain_free, 696 + } 691 697 }; 692 698 693 699 static int msm_iommu_probe(struct platform_device *pdev)
+11 -9
drivers/iommu/mtk_iommu.c
··· 658 658 659 659 static const struct iommu_ops mtk_iommu_ops = { 660 660 .domain_alloc = mtk_iommu_domain_alloc, 661 - .domain_free = mtk_iommu_domain_free, 662 - .attach_dev = mtk_iommu_attach_device, 663 - .detach_dev = mtk_iommu_detach_device, 664 - .map = mtk_iommu_map, 665 - .unmap = mtk_iommu_unmap, 666 - .flush_iotlb_all = mtk_iommu_flush_iotlb_all, 667 - .iotlb_sync = mtk_iommu_iotlb_sync, 668 - .iotlb_sync_map = mtk_iommu_sync_map, 669 - .iova_to_phys = mtk_iommu_iova_to_phys, 670 661 .probe_device = mtk_iommu_probe_device, 671 662 .release_device = mtk_iommu_release_device, 672 663 .device_group = mtk_iommu_device_group, ··· 666 675 .put_resv_regions = generic_iommu_put_resv_regions, 667 676 .pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M, 668 677 .owner = THIS_MODULE, 678 + .default_domain_ops = &(const struct iommu_domain_ops) { 679 + .attach_dev = mtk_iommu_attach_device, 680 + .detach_dev = mtk_iommu_detach_device, 681 + .map = mtk_iommu_map, 682 + .unmap = mtk_iommu_unmap, 683 + .flush_iotlb_all = mtk_iommu_flush_iotlb_all, 684 + .iotlb_sync = mtk_iommu_iotlb_sync, 685 + .iotlb_sync_map = mtk_iommu_sync_map, 686 + .iova_to_phys = mtk_iommu_iova_to_phys, 687 + .free = mtk_iommu_domain_free, 688 + } 669 689 }; 670 690 671 691 static int mtk_iommu_hw_init(const struct mtk_iommu_data *data)
+8 -6
drivers/iommu/mtk_iommu_v1.c
··· 514 514 515 515 static const struct iommu_ops mtk_iommu_ops = { 516 516 .domain_alloc = mtk_iommu_domain_alloc, 517 - .domain_free = mtk_iommu_domain_free, 518 - .attach_dev = mtk_iommu_attach_device, 519 - .detach_dev = mtk_iommu_detach_device, 520 - .map = mtk_iommu_map, 521 - .unmap = mtk_iommu_unmap, 522 - .iova_to_phys = mtk_iommu_iova_to_phys, 523 517 .probe_device = mtk_iommu_probe_device, 524 518 .probe_finalize = mtk_iommu_probe_finalize, 525 519 .release_device = mtk_iommu_release_device, ··· 521 527 .device_group = generic_device_group, 522 528 .pgsize_bitmap = ~0UL << MT2701_IOMMU_PAGE_SHIFT, 523 529 .owner = THIS_MODULE, 530 + .default_domain_ops = &(const struct iommu_domain_ops) { 531 + .attach_dev = mtk_iommu_attach_device, 532 + .detach_dev = mtk_iommu_detach_device, 533 + .map = mtk_iommu_map, 534 + .unmap = mtk_iommu_unmap, 535 + .iova_to_phys = mtk_iommu_iova_to_phys, 536 + .free = mtk_iommu_domain_free, 537 + } 524 538 }; 525 539 526 540 static const struct of_device_id mtk_iommu_of_ids[] = {
+8 -6
drivers/iommu/omap-iommu.c
··· 1734 1734 1735 1735 static const struct iommu_ops omap_iommu_ops = { 1736 1736 .domain_alloc = omap_iommu_domain_alloc, 1737 - .domain_free = omap_iommu_domain_free, 1738 - .attach_dev = omap_iommu_attach_dev, 1739 - .detach_dev = omap_iommu_detach_dev, 1740 - .map = omap_iommu_map, 1741 - .unmap = omap_iommu_unmap, 1742 - .iova_to_phys = omap_iommu_iova_to_phys, 1743 1737 .probe_device = omap_iommu_probe_device, 1744 1738 .release_device = omap_iommu_release_device, 1745 1739 .device_group = omap_iommu_device_group, 1746 1740 .pgsize_bitmap = OMAP_IOMMU_PGSIZES, 1741 + .default_domain_ops = &(const struct iommu_domain_ops) { 1742 + .attach_dev = omap_iommu_attach_dev, 1743 + .detach_dev = omap_iommu_detach_dev, 1744 + .map = omap_iommu_map, 1745 + .unmap = omap_iommu_unmap, 1746 + .iova_to_phys = omap_iommu_iova_to_phys, 1747 + .free = omap_iommu_domain_free, 1748 + } 1747 1749 }; 1748 1750 1749 1751 static int __init omap_iommu_init(void)
+8 -6
drivers/iommu/rockchip-iommu.c
··· 1187 1187 1188 1188 static const struct iommu_ops rk_iommu_ops = { 1189 1189 .domain_alloc = rk_iommu_domain_alloc, 1190 - .domain_free = rk_iommu_domain_free, 1191 - .attach_dev = rk_iommu_attach_device, 1192 - .detach_dev = rk_iommu_detach_device, 1193 - .map = rk_iommu_map, 1194 - .unmap = rk_iommu_unmap, 1195 1190 .probe_device = rk_iommu_probe_device, 1196 1191 .release_device = rk_iommu_release_device, 1197 - .iova_to_phys = rk_iommu_iova_to_phys, 1198 1192 .device_group = rk_iommu_device_group, 1199 1193 .pgsize_bitmap = RK_IOMMU_PGSIZE_BITMAP, 1200 1194 .of_xlate = rk_iommu_of_xlate, 1195 + .default_domain_ops = &(const struct iommu_domain_ops) { 1196 + .attach_dev = rk_iommu_attach_device, 1197 + .detach_dev = rk_iommu_detach_device, 1198 + .map = rk_iommu_map, 1199 + .unmap = rk_iommu_unmap, 1200 + .iova_to_phys = rk_iommu_iova_to_phys, 1201 + .free = rk_iommu_domain_free, 1202 + } 1201 1203 }; 1202 1204 1203 1205 static int rk_iommu_probe(struct platform_device *pdev)
+8 -6
drivers/iommu/s390-iommu.c
··· 363 363 static const struct iommu_ops s390_iommu_ops = { 364 364 .capable = s390_iommu_capable, 365 365 .domain_alloc = s390_domain_alloc, 366 - .domain_free = s390_domain_free, 367 - .attach_dev = s390_iommu_attach_device, 368 - .detach_dev = s390_iommu_detach_device, 369 - .map = s390_iommu_map, 370 - .unmap = s390_iommu_unmap, 371 - .iova_to_phys = s390_iommu_iova_to_phys, 372 366 .probe_device = s390_iommu_probe_device, 373 367 .release_device = s390_iommu_release_device, 374 368 .device_group = generic_device_group, 375 369 .pgsize_bitmap = S390_IOMMU_PGSIZES, 370 + .default_domain_ops = &(const struct iommu_domain_ops) { 371 + .attach_dev = s390_iommu_attach_device, 372 + .detach_dev = s390_iommu_detach_device, 373 + .map = s390_iommu_map, 374 + .unmap = s390_iommu_unmap, 375 + .iova_to_phys = s390_iommu_iova_to_phys, 376 + .free = s390_domain_free, 377 + } 376 378 }; 377 379 378 380 static int __init s390_iommu_init(void)
+10 -8
drivers/iommu/sprd-iommu.c
··· 416 416 417 417 static const struct iommu_ops sprd_iommu_ops = { 418 418 .domain_alloc = sprd_iommu_domain_alloc, 419 - .domain_free = sprd_iommu_domain_free, 420 - .attach_dev = sprd_iommu_attach_device, 421 - .detach_dev = sprd_iommu_detach_device, 422 - .map = sprd_iommu_map, 423 - .unmap = sprd_iommu_unmap, 424 - .iotlb_sync_map = sprd_iommu_sync_map, 425 - .iotlb_sync = sprd_iommu_sync, 426 - .iova_to_phys = sprd_iommu_iova_to_phys, 427 419 .probe_device = sprd_iommu_probe_device, 428 420 .release_device = sprd_iommu_release_device, 429 421 .device_group = sprd_iommu_device_group, 430 422 .of_xlate = sprd_iommu_of_xlate, 431 423 .pgsize_bitmap = ~0UL << SPRD_IOMMU_PAGE_SHIFT, 432 424 .owner = THIS_MODULE, 425 + .default_domain_ops = &(const struct iommu_domain_ops) { 426 + .attach_dev = sprd_iommu_attach_device, 427 + .detach_dev = sprd_iommu_detach_device, 428 + .map = sprd_iommu_map, 429 + .unmap = sprd_iommu_unmap, 430 + .iotlb_sync_map = sprd_iommu_sync_map, 431 + .iotlb_sync = sprd_iommu_sync, 432 + .iova_to_phys = sprd_iommu_iova_to_phys, 433 + .free = sprd_iommu_domain_free, 434 + } 433 435 }; 434 436 435 437 static const struct of_device_id sprd_iommu_of_match[] = {
+10 -8
drivers/iommu/sun50i-iommu.c
··· 760 760 761 761 static const struct iommu_ops sun50i_iommu_ops = { 762 762 .pgsize_bitmap = SZ_4K, 763 - .attach_dev = sun50i_iommu_attach_device, 764 - .detach_dev = sun50i_iommu_detach_device, 765 763 .device_group = sun50i_iommu_device_group, 766 764 .domain_alloc = sun50i_iommu_domain_alloc, 767 - .domain_free = sun50i_iommu_domain_free, 768 - .flush_iotlb_all = sun50i_iommu_flush_iotlb_all, 769 - .iotlb_sync = sun50i_iommu_iotlb_sync, 770 - .iova_to_phys = sun50i_iommu_iova_to_phys, 771 - .map = sun50i_iommu_map, 772 765 .of_xlate = sun50i_iommu_of_xlate, 773 766 .probe_device = sun50i_iommu_probe_device, 774 767 .release_device = sun50i_iommu_release_device, 775 - .unmap = sun50i_iommu_unmap, 768 + .default_domain_ops = &(const struct iommu_domain_ops) { 769 + .attach_dev = sun50i_iommu_attach_device, 770 + .detach_dev = sun50i_iommu_detach_device, 771 + .flush_iotlb_all = sun50i_iommu_flush_iotlb_all, 772 + .iotlb_sync = sun50i_iommu_iotlb_sync, 773 + .iova_to_phys = sun50i_iommu_iova_to_phys, 774 + .map = sun50i_iommu_map, 775 + .unmap = sun50i_iommu_unmap, 776 + .free = sun50i_iommu_domain_free, 777 + } 776 778 }; 777 779 778 780 static void sun50i_iommu_report_fault(struct sun50i_iommu *iommu,
+10 -14
drivers/iommu/tegra-gart.c
··· 238 238 return pte & GART_PAGE_MASK; 239 239 } 240 240 241 - static bool gart_iommu_capable(enum iommu_cap cap) 242 - { 243 - return false; 244 - } 245 - 246 241 static struct iommu_device *gart_iommu_probe_device(struct device *dev) 247 242 { 248 243 if (!dev_iommu_fwspec_get(dev)) ··· 271 276 } 272 277 273 278 static const struct iommu_ops gart_iommu_ops = { 274 - .capable = gart_iommu_capable, 275 279 .domain_alloc = gart_iommu_domain_alloc, 276 - .domain_free = gart_iommu_domain_free, 277 - .attach_dev = gart_iommu_attach_dev, 278 - .detach_dev = gart_iommu_detach_dev, 279 280 .probe_device = gart_iommu_probe_device, 280 281 .release_device = gart_iommu_release_device, 281 282 .device_group = generic_device_group, 282 - .map = gart_iommu_map, 283 - .unmap = gart_iommu_unmap, 284 - .iova_to_phys = gart_iommu_iova_to_phys, 285 283 .pgsize_bitmap = GART_IOMMU_PGSIZES, 286 284 .of_xlate = gart_iommu_of_xlate, 287 - .iotlb_sync_map = gart_iommu_sync_map, 288 - .iotlb_sync = gart_iommu_sync, 285 + .default_domain_ops = &(const struct iommu_domain_ops) { 286 + .attach_dev = gart_iommu_attach_dev, 287 + .detach_dev = gart_iommu_detach_dev, 288 + .map = gart_iommu_map, 289 + .unmap = gart_iommu_unmap, 290 + .iova_to_phys = gart_iommu_iova_to_phys, 291 + .iotlb_sync_map = gart_iommu_sync_map, 292 + .iotlb_sync = gart_iommu_sync, 293 + .free = gart_iommu_domain_free, 294 + } 289 295 }; 290 296 291 297 int tegra_gart_suspend(struct gart_device *gart)
+8 -12
drivers/iommu/tegra-smmu.c
··· 272 272 clear_bit(id, smmu->asids); 273 273 } 274 274 275 - static bool tegra_smmu_capable(enum iommu_cap cap) 276 - { 277 - return false; 278 - } 279 - 280 275 static struct iommu_domain *tegra_smmu_domain_alloc(unsigned type) 281 276 { 282 277 struct tegra_smmu_as *as; ··· 962 967 } 963 968 964 969 static const struct iommu_ops tegra_smmu_ops = { 965 - .capable = tegra_smmu_capable, 966 970 .domain_alloc = tegra_smmu_domain_alloc, 967 - .domain_free = tegra_smmu_domain_free, 968 - .attach_dev = tegra_smmu_attach_dev, 969 - .detach_dev = tegra_smmu_detach_dev, 970 971 .probe_device = tegra_smmu_probe_device, 971 972 .release_device = tegra_smmu_release_device, 972 973 .device_group = tegra_smmu_device_group, 973 - .map = tegra_smmu_map, 974 - .unmap = tegra_smmu_unmap, 975 - .iova_to_phys = tegra_smmu_iova_to_phys, 976 974 .of_xlate = tegra_smmu_of_xlate, 977 975 .pgsize_bitmap = SZ_4K, 976 + .default_domain_ops = &(const struct iommu_domain_ops) { 977 + .attach_dev = tegra_smmu_attach_dev, 978 + .detach_dev = tegra_smmu_detach_dev, 979 + .map = tegra_smmu_map, 980 + .unmap = tegra_smmu_unmap, 981 + .iova_to_phys = tegra_smmu_iova_to_phys, 982 + .free = tegra_smmu_domain_free, 983 + } 978 984 }; 979 985 980 986 static void tegra_smmu_ahb_enable(void)
+8 -6
drivers/iommu/virtio-iommu.c
··· 1008 1008 1009 1009 static struct iommu_ops viommu_ops = { 1010 1010 .domain_alloc = viommu_domain_alloc, 1011 - .domain_free = viommu_domain_free, 1012 - .attach_dev = viommu_attach_dev, 1013 - .map = viommu_map, 1014 - .unmap = viommu_unmap, 1015 - .iova_to_phys = viommu_iova_to_phys, 1016 - .iotlb_sync = viommu_iotlb_sync, 1017 1011 .probe_device = viommu_probe_device, 1018 1012 .probe_finalize = viommu_probe_finalize, 1019 1013 .release_device = viommu_release_device, ··· 1016 1022 .put_resv_regions = generic_iommu_put_resv_regions, 1017 1023 .of_xlate = viommu_of_xlate, 1018 1024 .owner = THIS_MODULE, 1025 + .default_domain_ops = &(const struct iommu_domain_ops) { 1026 + .attach_dev = viommu_attach_dev, 1027 + .map = viommu_map, 1028 + .unmap = viommu_unmap, 1029 + .iova_to_phys = viommu_iova_to_phys, 1030 + .iotlb_sync = viommu_iotlb_sync, 1031 + .free = viommu_domain_free, 1032 + } 1019 1033 }; 1020 1034 1021 1035 static int viommu_init_vqs(struct viommu_dev *viommu)
+11
drivers/vdpa/vdpa_user/iova_domain.c
··· 480 480 struct file *file; 481 481 struct vduse_bounce_map *map; 482 482 unsigned long pfn, bounce_pfns; 483 + int ret; 483 484 484 485 bounce_pfns = PAGE_ALIGN(bounce_size) >> PAGE_SHIFT; 485 486 if (iova_limit <= bounce_size) ··· 514 513 spin_lock_init(&domain->iotlb_lock); 515 514 init_iova_domain(&domain->stream_iovad, 516 515 PAGE_SIZE, IOVA_START_PFN); 516 + ret = iova_domain_init_rcaches(&domain->stream_iovad); 517 + if (ret) 518 + goto err_iovad_stream; 517 519 init_iova_domain(&domain->consistent_iovad, 518 520 PAGE_SIZE, bounce_pfns); 521 + ret = iova_domain_init_rcaches(&domain->consistent_iovad); 522 + if (ret) 523 + goto err_iovad_consistent; 519 524 520 525 return domain; 526 + err_iovad_consistent: 527 + put_iova_domain(&domain->stream_iovad); 528 + err_iovad_stream: 529 + fput(file); 521 530 err_file: 522 531 vfree(domain->bounce_maps); 523 532 err_map:
-27
include/linux/intel-iommu.h
··· 525 525 */ 526 526 #define DOMAIN_FLAG_USE_FIRST_LEVEL BIT(1) 527 527 528 - /* 529 - * Domain represents a virtual machine which demands iommu nested 530 - * translation mode support. 531 - */ 532 - #define DOMAIN_FLAG_NESTING_MODE BIT(2) 533 - 534 528 struct dmar_domain { 535 529 int nid; /* node id */ 536 530 ··· 542 548 u8 iommu_snooping: 1; /* indicate snooping control feature */ 543 549 544 550 struct list_head devices; /* all devices' list */ 545 - struct list_head subdevices; /* all subdevices' list */ 546 551 struct iova_domain iovad; /* iova's that belong to this domain */ 547 552 548 553 struct dma_pte *pgd; /* virtual address */ ··· 555 562 0 == 4KiB (no superpages), 1 == 2MiB, 556 563 2 == 1GiB, 3 == 512GiB, 4 == 1TiB */ 557 564 u64 max_addr; /* maximum mapped address */ 558 - 559 - u32 default_pasid; /* 560 - * The default pasid used for non-SVM 561 - * traffic on mediated devices. 562 - */ 563 565 564 566 struct iommu_domain domain; /* generic domain data structure for 565 567 iommu core */ ··· 608 620 void *perf_statistic; 609 621 }; 610 622 611 - /* Per subdevice private data */ 612 - struct subdev_domain_info { 613 - struct list_head link_phys; /* link to phys device siblings */ 614 - struct list_head link_domain; /* link to domain siblings */ 615 - struct device *pdev; /* physical device derived from */ 616 - struct dmar_domain *domain; /* aux-domain */ 617 - int users; /* user count */ 618 - }; 619 - 620 623 /* PCI domain-device relationship */ 621 624 struct device_domain_info { 622 625 struct list_head link; /* link to domain siblings */ 623 626 struct list_head global; /* link to global list */ 624 627 struct list_head table; /* link to pasid table */ 625 - struct list_head subdevices; /* subdevices sibling */ 626 628 u32 segment; /* PCI segment number */ 627 629 u8 bus; /* PCI bus number */ 628 630 u8 devfn; /* PCI devfn number */ ··· 623 645 u8 pri_enabled:1; 624 646 u8 ats_supported:1; 625 647 u8 ats_enabled:1; 626 - u8 auxd_enabled:1; /* Multiple domains per device */ 627 648 u8 ats_qdep; 628 649 struct device *dev; /* it's NULL for PCIe-to-PCI bridge */ 629 650 struct intel_iommu *iommu; /* IOMMU used by this device */ ··· 742 765 extern void intel_svm_check(struct intel_iommu *iommu); 743 766 extern int intel_svm_enable_prq(struct intel_iommu *iommu); 744 767 extern int intel_svm_finish_prq(struct intel_iommu *iommu); 745 - int intel_svm_bind_gpasid(struct iommu_domain *domain, struct device *dev, 746 - struct iommu_gpasid_bind_data *data); 747 - int intel_svm_unbind_gpasid(struct device *dev, u32 pasid); 748 768 struct iommu_sva *intel_svm_bind(struct device *dev, struct mm_struct *mm, 749 769 void *drvdata); 750 770 void intel_svm_unbind(struct iommu_sva *handle); ··· 769 795 770 796 unsigned int flags; 771 797 u32 pasid; 772 - int gpasid; /* In case that guest PASID is different from host PASID */ 773 798 struct list_head devs; 774 799 }; 775 800 #else
-12
include/linux/intel-svm.h
··· 25 25 * do such IOTLB flushes automatically. 26 26 */ 27 27 #define SVM_FLAG_SUPERVISOR_MODE BIT(0) 28 - /* 29 - * The SVM_FLAG_GUEST_MODE flag is used when a PASID bind is for guest 30 - * processes. Compared to the host bind, the primary differences are: 31 - * 1. mm life cycle management 32 - * 2. fault reporting 33 - */ 34 - #define SVM_FLAG_GUEST_MODE BIT(1) 35 - /* 36 - * The SVM_FLAG_GUEST_PASID flag is used when a guest has its own PASID space, 37 - * which requires guest and host PASID translation at both directions. 38 - */ 39 - #define SVM_FLAG_GUEST_PASID BIT(2) 40 28 41 29 #endif /* __INTEL_SVM_H__ */
+92 -143
include/linux/iommu.h
··· 37 37 struct bus_type; 38 38 struct device; 39 39 struct iommu_domain; 40 + struct iommu_domain_ops; 40 41 struct notifier_block; 41 42 struct iommu_sva; 42 43 struct iommu_fault_event; ··· 89 88 90 89 struct iommu_domain { 91 90 unsigned type; 92 - const struct iommu_ops *ops; 91 + const struct iommu_domain_ops *ops; 93 92 unsigned long pgsize_bitmap; /* Bitmap of page sizes in use */ 94 93 iommu_fault_handler_t handler; 95 94 void *handler_token; ··· 145 144 146 145 /** 147 146 * enum iommu_dev_features - Per device IOMMU features 148 - * @IOMMU_DEV_FEAT_AUX: Auxiliary domain feature 149 147 * @IOMMU_DEV_FEAT_SVA: Shared Virtual Addresses 150 148 * @IOMMU_DEV_FEAT_IOPF: I/O Page Faults such as PRI or Stall. Generally 151 149 * enabling %IOMMU_DEV_FEAT_SVA requires ··· 157 157 * iommu_dev_has_feature(), and enable it using iommu_dev_enable_feature(). 158 158 */ 159 159 enum iommu_dev_features { 160 - IOMMU_DEV_FEAT_AUX, 161 160 IOMMU_DEV_FEAT_SVA, 162 161 IOMMU_DEV_FEAT_IOPF, 163 162 }; ··· 193 194 * struct iommu_ops - iommu ops and capabilities 194 195 * @capable: check capability 195 196 * @domain_alloc: allocate iommu domain 196 - * @domain_free: free iommu domain 197 - * @attach_dev: attach device to an iommu domain 198 - * @detach_dev: detach device from an iommu domain 197 + * @probe_device: Add device to iommu driver handling 198 + * @release_device: Remove device from iommu driver handling 199 + * @probe_finalize: Do final setup work after the device is added to an IOMMU 200 + * group and attached to the groups domain 201 + * @device_group: find iommu group for a particular device 202 + * @get_resv_regions: Request list of reserved regions for a device 203 + * @put_resv_regions: Free list of reserved regions for a device 204 + * @of_xlate: add OF master IDs to iommu grouping 205 + * @is_attach_deferred: Check if domain attach should be deferred from iommu 206 + * driver init to device driver init (default no) 207 + * @dev_has/enable/disable_feat: per device entries to check/enable/disable 208 + * iommu specific features. 209 + * @dev_feat_enabled: check enabled feature 210 + * @sva_bind: Bind process address space to device 211 + * @sva_unbind: Unbind process address space from device 212 + * @sva_get_pasid: Get PASID associated to a SVA handle 213 + * @page_response: handle page request response 214 + * @def_domain_type: device default domain type, return value: 215 + * - IOMMU_DOMAIN_IDENTITY: must use an identity domain 216 + * - IOMMU_DOMAIN_DMA: must use a dma domain 217 + * - 0: use the default setting 218 + * @default_domain_ops: the default ops for domains 219 + * @pgsize_bitmap: bitmap of all possible supported page sizes 220 + * @owner: Driver module providing these ops 221 + */ 222 + struct iommu_ops { 223 + bool (*capable)(enum iommu_cap); 224 + 225 + /* Domain allocation and freeing by the iommu driver */ 226 + struct iommu_domain *(*domain_alloc)(unsigned iommu_domain_type); 227 + 228 + struct iommu_device *(*probe_device)(struct device *dev); 229 + void (*release_device)(struct device *dev); 230 + void (*probe_finalize)(struct device *dev); 231 + struct iommu_group *(*device_group)(struct device *dev); 232 + 233 + /* Request/Free a list of reserved regions for a device */ 234 + void (*get_resv_regions)(struct device *dev, struct list_head *list); 235 + void (*put_resv_regions)(struct device *dev, struct list_head *list); 236 + 237 + int (*of_xlate)(struct device *dev, struct of_phandle_args *args); 238 + bool (*is_attach_deferred)(struct device *dev); 239 + 240 + /* Per device IOMMU features */ 241 + bool (*dev_has_feat)(struct device *dev, enum iommu_dev_features f); 242 + bool (*dev_feat_enabled)(struct device *dev, enum iommu_dev_features f); 243 + int (*dev_enable_feat)(struct device *dev, enum iommu_dev_features f); 244 + int (*dev_disable_feat)(struct device *dev, enum iommu_dev_features f); 245 + 246 + struct iommu_sva *(*sva_bind)(struct device *dev, struct mm_struct *mm, 247 + void *drvdata); 248 + void (*sva_unbind)(struct iommu_sva *handle); 249 + u32 (*sva_get_pasid)(struct iommu_sva *handle); 250 + 251 + int (*page_response)(struct device *dev, 252 + struct iommu_fault_event *evt, 253 + struct iommu_page_response *msg); 254 + 255 + int (*def_domain_type)(struct device *dev); 256 + 257 + const struct iommu_domain_ops *default_domain_ops; 258 + unsigned long pgsize_bitmap; 259 + struct module *owner; 260 + }; 261 + 262 + /** 263 + * struct iommu_domain_ops - domain specific operations 264 + * @attach_dev: attach an iommu domain to a device 265 + * @detach_dev: detach an iommu domain from a device 199 266 * @map: map a physically contiguous memory region to an iommu domain 200 267 * @map_pages: map a physically contiguous set of pages of the same size to 201 268 * an iommu domain. ··· 272 207 * @iotlb_sync: Flush all queued ranges from the hardware TLBs and empty flush 273 208 * queue 274 209 * @iova_to_phys: translate iova to physical address 275 - * @probe_device: Add device to iommu driver handling 276 - * @release_device: Remove device from iommu driver handling 277 - * @probe_finalize: Do final setup work after the device is added to an IOMMU 278 - * group and attached to the groups domain 279 - * @device_group: find iommu group for a particular device 280 210 * @enable_nesting: Enable nesting 281 211 * @set_pgtable_quirks: Set io page table quirks (IO_PGTABLE_QUIRK_*) 282 - * @get_resv_regions: Request list of reserved regions for a device 283 - * @put_resv_regions: Free list of reserved regions for a device 284 - * @apply_resv_region: Temporary helper call-back for iova reserved ranges 285 - * @of_xlate: add OF master IDs to iommu grouping 286 - * @is_attach_deferred: Check if domain attach should be deferred from iommu 287 - * driver init to device driver init (default no) 288 - * @dev_has/enable/disable_feat: per device entries to check/enable/disable 289 - * iommu specific features. 290 - * @dev_feat_enabled: check enabled feature 291 - * @aux_attach/detach_dev: aux-domain specific attach/detach entries. 292 - * @aux_get_pasid: get the pasid given an aux-domain 293 - * @sva_bind: Bind process address space to device 294 - * @sva_unbind: Unbind process address space from device 295 - * @sva_get_pasid: Get PASID associated to a SVA handle 296 - * @page_response: handle page request response 297 - * @cache_invalidate: invalidate translation caches 298 - * @sva_bind_gpasid: bind guest pasid and mm 299 - * @sva_unbind_gpasid: unbind guest pasid and mm 300 - * @def_domain_type: device default domain type, return value: 301 - * - IOMMU_DOMAIN_IDENTITY: must use an identity domain 302 - * - IOMMU_DOMAIN_DMA: must use a dma domain 303 - * - 0: use the default setting 304 - * @pgsize_bitmap: bitmap of all possible supported page sizes 305 - * @owner: Driver module providing these ops 212 + * @free: Release the domain after use. 306 213 */ 307 - struct iommu_ops { 308 - bool (*capable)(enum iommu_cap); 309 - 310 - /* Domain allocation and freeing by the iommu driver */ 311 - struct iommu_domain *(*domain_alloc)(unsigned iommu_domain_type); 312 - void (*domain_free)(struct iommu_domain *); 313 - 214 + struct iommu_domain_ops { 314 215 int (*attach_dev)(struct iommu_domain *domain, struct device *dev); 315 216 void (*detach_dev)(struct iommu_domain *domain, struct device *dev); 217 + 316 218 int (*map)(struct iommu_domain *domain, unsigned long iova, 317 219 phys_addr_t paddr, size_t size, int prot, gfp_t gfp); 318 220 int (*map_pages)(struct iommu_domain *domain, unsigned long iova, 319 221 phys_addr_t paddr, size_t pgsize, size_t pgcount, 320 222 int prot, gfp_t gfp, size_t *mapped); 321 223 size_t (*unmap)(struct iommu_domain *domain, unsigned long iova, 322 - size_t size, struct iommu_iotlb_gather *iotlb_gather); 224 + size_t size, struct iommu_iotlb_gather *iotlb_gather); 323 225 size_t (*unmap_pages)(struct iommu_domain *domain, unsigned long iova, 324 226 size_t pgsize, size_t pgcount, 325 227 struct iommu_iotlb_gather *iotlb_gather); 228 + 326 229 void (*flush_iotlb_all)(struct iommu_domain *domain); 327 230 void (*iotlb_sync_map)(struct iommu_domain *domain, unsigned long iova, 328 231 size_t size); 329 232 void (*iotlb_sync)(struct iommu_domain *domain, 330 233 struct iommu_iotlb_gather *iotlb_gather); 331 - phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, dma_addr_t iova); 332 - struct iommu_device *(*probe_device)(struct device *dev); 333 - void (*release_device)(struct device *dev); 334 - void (*probe_finalize)(struct device *dev); 335 - struct iommu_group *(*device_group)(struct device *dev); 234 + 235 + phys_addr_t (*iova_to_phys)(struct iommu_domain *domain, 236 + dma_addr_t iova); 237 + 336 238 int (*enable_nesting)(struct iommu_domain *domain); 337 239 int (*set_pgtable_quirks)(struct iommu_domain *domain, 338 240 unsigned long quirks); 339 241 340 - /* Request/Free a list of reserved regions for a device */ 341 - void (*get_resv_regions)(struct device *dev, struct list_head *list); 342 - void (*put_resv_regions)(struct device *dev, struct list_head *list); 343 - void (*apply_resv_region)(struct device *dev, 344 - struct iommu_domain *domain, 345 - struct iommu_resv_region *region); 346 - 347 - int (*of_xlate)(struct device *dev, struct of_phandle_args *args); 348 - bool (*is_attach_deferred)(struct iommu_domain *domain, struct device *dev); 349 - 350 - /* Per device IOMMU features */ 351 - bool (*dev_has_feat)(struct device *dev, enum iommu_dev_features f); 352 - bool (*dev_feat_enabled)(struct device *dev, enum iommu_dev_features f); 353 - int (*dev_enable_feat)(struct device *dev, enum iommu_dev_features f); 354 - int (*dev_disable_feat)(struct device *dev, enum iommu_dev_features f); 355 - 356 - /* Aux-domain specific attach/detach entries */ 357 - int (*aux_attach_dev)(struct iommu_domain *domain, struct device *dev); 358 - void (*aux_detach_dev)(struct iommu_domain *domain, struct device *dev); 359 - int (*aux_get_pasid)(struct iommu_domain *domain, struct device *dev); 360 - 361 - struct iommu_sva *(*sva_bind)(struct device *dev, struct mm_struct *mm, 362 - void *drvdata); 363 - void (*sva_unbind)(struct iommu_sva *handle); 364 - u32 (*sva_get_pasid)(struct iommu_sva *handle); 365 - 366 - int (*page_response)(struct device *dev, 367 - struct iommu_fault_event *evt, 368 - struct iommu_page_response *msg); 369 - int (*cache_invalidate)(struct iommu_domain *domain, struct device *dev, 370 - struct iommu_cache_invalidate_info *inv_info); 371 - int (*sva_bind_gpasid)(struct iommu_domain *domain, 372 - struct device *dev, struct iommu_gpasid_bind_data *data); 373 - 374 - int (*sva_unbind_gpasid)(struct device *dev, u32 pasid); 375 - 376 - int (*def_domain_type)(struct device *dev); 377 - 378 - unsigned long pgsize_bitmap; 379 - struct module *owner; 242 + void (*free)(struct iommu_domain *domain); 380 243 }; 381 244 382 245 /** ··· 396 403 }; 397 404 } 398 405 406 + static inline const struct iommu_ops *dev_iommu_ops(struct device *dev) 407 + { 408 + /* 409 + * Assume that valid ops must be installed if iommu_probe_device() 410 + * has succeeded. The device ops are essentially for internal use 411 + * within the IOMMU subsystem itself, so we should be able to trust 412 + * ourselves not to misuse the helper. 413 + */ 414 + return dev->iommu->iommu_dev->ops; 415 + } 416 + 399 417 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */ 400 418 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */ 401 419 #define IOMMU_GROUP_NOTIFY_BIND_DRIVER 3 /* Pre Driver bind */ ··· 425 421 struct device *dev); 426 422 extern void iommu_detach_device(struct iommu_domain *domain, 427 423 struct device *dev); 428 - extern int iommu_uapi_cache_invalidate(struct iommu_domain *domain, 429 - struct device *dev, 430 - void __user *uinfo); 431 - 432 - extern int iommu_uapi_sva_bind_gpasid(struct iommu_domain *domain, 433 - struct device *dev, void __user *udata); 434 - extern int iommu_uapi_sva_unbind_gpasid(struct iommu_domain *domain, 435 - struct device *dev, void __user *udata); 436 424 extern int iommu_sva_unbind_gpasid(struct iommu_domain *domain, 437 425 struct device *dev, ioasid_t pasid); 438 426 extern struct iommu_domain *iommu_get_domain_for_dev(struct device *dev); ··· 668 672 int iommu_dev_enable_feature(struct device *dev, enum iommu_dev_features f); 669 673 int iommu_dev_disable_feature(struct device *dev, enum iommu_dev_features f); 670 674 bool iommu_dev_feature_enabled(struct device *dev, enum iommu_dev_features f); 671 - int iommu_aux_attach_device(struct iommu_domain *domain, struct device *dev); 672 - void iommu_aux_detach_device(struct iommu_domain *domain, struct device *dev); 673 - int iommu_aux_get_pasid(struct iommu_domain *domain, struct device *dev); 674 675 675 676 struct iommu_sva *iommu_sva_bind_device(struct device *dev, 676 677 struct mm_struct *mm, ··· 1012 1019 return -ENODEV; 1013 1020 } 1014 1021 1015 - static inline int 1016 - iommu_aux_attach_device(struct iommu_domain *domain, struct device *dev) 1017 - { 1018 - return -ENODEV; 1019 - } 1020 - 1021 - static inline void 1022 - iommu_aux_detach_device(struct iommu_domain *domain, struct device *dev) 1023 - { 1024 - } 1025 - 1026 - static inline int 1027 - iommu_aux_get_pasid(struct iommu_domain *domain, struct device *dev) 1028 - { 1029 - return -ENODEV; 1030 - } 1031 - 1032 1022 static inline struct iommu_sva * 1033 1023 iommu_sva_bind_device(struct device *dev, struct mm_struct *mm, void *drvdata) 1034 1024 { ··· 1025 1049 static inline u32 iommu_sva_get_pasid(struct iommu_sva *handle) 1026 1050 { 1027 1051 return IOMMU_PASID_INVALID; 1028 - } 1029 - 1030 - static inline int 1031 - iommu_uapi_cache_invalidate(struct iommu_domain *domain, 1032 - struct device *dev, 1033 - struct iommu_cache_invalidate_info *inv_info) 1034 - { 1035 - return -ENODEV; 1036 - } 1037 - 1038 - static inline int iommu_uapi_sva_bind_gpasid(struct iommu_domain *domain, 1039 - struct device *dev, void __user *udata) 1040 - { 1041 - return -ENODEV; 1042 - } 1043 - 1044 - static inline int iommu_uapi_sva_unbind_gpasid(struct iommu_domain *domain, 1045 - struct device *dev, void __user *udata) 1046 - { 1047 - return -ENODEV; 1048 - } 1049 - 1050 - static inline int iommu_sva_unbind_gpasid(struct iommu_domain *domain, 1051 - struct device *dev, 1052 - ioasid_t pasid) 1053 - { 1054 - return -ENODEV; 1055 1052 } 1056 1053 1057 1054 static inline struct iommu_fwspec *dev_iommu_fwspec_get(struct device *dev)
+3 -12
include/linux/iova.h
··· 21 21 unsigned long pfn_lo; /* Lowest allocated pfn */ 22 22 }; 23 23 24 - struct iova_magazine; 25 - struct iova_cpu_rcache; 26 24 27 - #define IOVA_RANGE_CACHE_MAX_SIZE 6 /* log of max cached IOVA range size (in pages) */ 28 - #define MAX_GLOBAL_MAGS 32 /* magazines per bin */ 29 - 30 - struct iova_rcache { 31 - spinlock_t lock; 32 - unsigned long depot_size; 33 - struct iova_magazine *depot[MAX_GLOBAL_MAGS]; 34 - struct iova_cpu_rcache __percpu *cpu_rcaches; 35 - }; 25 + struct iova_rcache; 36 26 37 27 /* holds all the iova translations for a domain */ 38 28 struct iova_domain { ··· 36 46 unsigned long max32_alloc_size; /* Size of last failed allocation */ 37 47 struct iova anchor; /* rbtree lookup anchor */ 38 48 39 - struct iova_rcache rcaches[IOVA_RANGE_CACHE_MAX_SIZE]; /* IOVA range caches */ 49 + struct iova_rcache *rcaches; 40 50 struct hlist_node cpuhp_dead; 41 51 }; 42 52 ··· 92 102 unsigned long pfn_hi); 93 103 void init_iova_domain(struct iova_domain *iovad, unsigned long granule, 94 104 unsigned long start_pfn); 105 + int iova_domain_init_rcaches(struct iova_domain *iovad); 95 106 struct iova *find_iova(struct iova_domain *iovad, unsigned long pfn); 96 107 void put_iova_domain(struct iova_domain *iovad); 97 108 #else
-181
include/uapi/linux/iommu.h
··· 158 158 __u32 code; 159 159 }; 160 160 161 - /* defines the granularity of the invalidation */ 162 - enum iommu_inv_granularity { 163 - IOMMU_INV_GRANU_DOMAIN, /* domain-selective invalidation */ 164 - IOMMU_INV_GRANU_PASID, /* PASID-selective invalidation */ 165 - IOMMU_INV_GRANU_ADDR, /* page-selective invalidation */ 166 - IOMMU_INV_GRANU_NR, /* number of invalidation granularities */ 167 - }; 168 - 169 - /** 170 - * struct iommu_inv_addr_info - Address Selective Invalidation Structure 171 - * 172 - * @flags: indicates the granularity of the address-selective invalidation 173 - * - If the PASID bit is set, the @pasid field is populated and the invalidation 174 - * relates to cache entries tagged with this PASID and matching the address 175 - * range. 176 - * - If ARCHID bit is set, @archid is populated and the invalidation relates 177 - * to cache entries tagged with this architecture specific ID and matching 178 - * the address range. 179 - * - Both PASID and ARCHID can be set as they may tag different caches. 180 - * - If neither PASID or ARCHID is set, global addr invalidation applies. 181 - * - The LEAF flag indicates whether only the leaf PTE caching needs to be 182 - * invalidated and other paging structure caches can be preserved. 183 - * @pasid: process address space ID 184 - * @archid: architecture-specific ID 185 - * @addr: first stage/level input address 186 - * @granule_size: page/block size of the mapping in bytes 187 - * @nb_granules: number of contiguous granules to be invalidated 188 - */ 189 - struct iommu_inv_addr_info { 190 - #define IOMMU_INV_ADDR_FLAGS_PASID (1 << 0) 191 - #define IOMMU_INV_ADDR_FLAGS_ARCHID (1 << 1) 192 - #define IOMMU_INV_ADDR_FLAGS_LEAF (1 << 2) 193 - __u32 flags; 194 - __u32 archid; 195 - __u64 pasid; 196 - __u64 addr; 197 - __u64 granule_size; 198 - __u64 nb_granules; 199 - }; 200 - 201 - /** 202 - * struct iommu_inv_pasid_info - PASID Selective Invalidation Structure 203 - * 204 - * @flags: indicates the granularity of the PASID-selective invalidation 205 - * - If the PASID bit is set, the @pasid field is populated and the invalidation 206 - * relates to cache entries tagged with this PASID and matching the address 207 - * range. 208 - * - If the ARCHID bit is set, the @archid is populated and the invalidation 209 - * relates to cache entries tagged with this architecture specific ID and 210 - * matching the address range. 211 - * - Both PASID and ARCHID can be set as they may tag different caches. 212 - * - At least one of PASID or ARCHID must be set. 213 - * @pasid: process address space ID 214 - * @archid: architecture-specific ID 215 - */ 216 - struct iommu_inv_pasid_info { 217 - #define IOMMU_INV_PASID_FLAGS_PASID (1 << 0) 218 - #define IOMMU_INV_PASID_FLAGS_ARCHID (1 << 1) 219 - __u32 flags; 220 - __u32 archid; 221 - __u64 pasid; 222 - }; 223 - 224 - /** 225 - * struct iommu_cache_invalidate_info - First level/stage invalidation 226 - * information 227 - * @argsz: User filled size of this data 228 - * @version: API version of this structure 229 - * @cache: bitfield that allows to select which caches to invalidate 230 - * @granularity: defines the lowest granularity used for the invalidation: 231 - * domain > PASID > addr 232 - * @padding: reserved for future use (should be zero) 233 - * @pasid_info: invalidation data when @granularity is %IOMMU_INV_GRANU_PASID 234 - * @addr_info: invalidation data when @granularity is %IOMMU_INV_GRANU_ADDR 235 - * 236 - * Not all the combinations of cache/granularity are valid: 237 - * 238 - * +--------------+---------------+---------------+---------------+ 239 - * | type / | DEV_IOTLB | IOTLB | PASID | 240 - * | granularity | | | cache | 241 - * +==============+===============+===============+===============+ 242 - * | DOMAIN | N/A | Y | Y | 243 - * +--------------+---------------+---------------+---------------+ 244 - * | PASID | Y | Y | Y | 245 - * +--------------+---------------+---------------+---------------+ 246 - * | ADDR | Y | Y | N/A | 247 - * +--------------+---------------+---------------+---------------+ 248 - * 249 - * Invalidations by %IOMMU_INV_GRANU_DOMAIN don't take any argument other than 250 - * @version and @cache. 251 - * 252 - * If multiple cache types are invalidated simultaneously, they all 253 - * must support the used granularity. 254 - */ 255 - struct iommu_cache_invalidate_info { 256 - __u32 argsz; 257 - #define IOMMU_CACHE_INVALIDATE_INFO_VERSION_1 1 258 - __u32 version; 259 - /* IOMMU paging structure cache */ 260 - #define IOMMU_CACHE_INV_TYPE_IOTLB (1 << 0) /* IOMMU IOTLB */ 261 - #define IOMMU_CACHE_INV_TYPE_DEV_IOTLB (1 << 1) /* Device IOTLB */ 262 - #define IOMMU_CACHE_INV_TYPE_PASID (1 << 2) /* PASID cache */ 263 - #define IOMMU_CACHE_INV_TYPE_NR (3) 264 - __u8 cache; 265 - __u8 granularity; 266 - __u8 padding[6]; 267 - union { 268 - struct iommu_inv_pasid_info pasid_info; 269 - struct iommu_inv_addr_info addr_info; 270 - } granu; 271 - }; 272 - 273 - /** 274 - * struct iommu_gpasid_bind_data_vtd - Intel VT-d specific data on device and guest 275 - * SVA binding. 276 - * 277 - * @flags: VT-d PASID table entry attributes 278 - * @pat: Page attribute table data to compute effective memory type 279 - * @emt: Extended memory type 280 - * 281 - * Only guest vIOMMU selectable and effective options are passed down to 282 - * the host IOMMU. 283 - */ 284 - struct iommu_gpasid_bind_data_vtd { 285 - #define IOMMU_SVA_VTD_GPASID_SRE (1 << 0) /* supervisor request */ 286 - #define IOMMU_SVA_VTD_GPASID_EAFE (1 << 1) /* extended access enable */ 287 - #define IOMMU_SVA_VTD_GPASID_PCD (1 << 2) /* page-level cache disable */ 288 - #define IOMMU_SVA_VTD_GPASID_PWT (1 << 3) /* page-level write through */ 289 - #define IOMMU_SVA_VTD_GPASID_EMTE (1 << 4) /* extended mem type enable */ 290 - #define IOMMU_SVA_VTD_GPASID_CD (1 << 5) /* PASID-level cache disable */ 291 - #define IOMMU_SVA_VTD_GPASID_WPE (1 << 6) /* Write protect enable */ 292 - #define IOMMU_SVA_VTD_GPASID_LAST (1 << 7) 293 - __u64 flags; 294 - __u32 pat; 295 - __u32 emt; 296 - }; 297 - 298 - #define IOMMU_SVA_VTD_GPASID_MTS_MASK (IOMMU_SVA_VTD_GPASID_CD | \ 299 - IOMMU_SVA_VTD_GPASID_EMTE | \ 300 - IOMMU_SVA_VTD_GPASID_PCD | \ 301 - IOMMU_SVA_VTD_GPASID_PWT) 302 - 303 - /** 304 - * struct iommu_gpasid_bind_data - Information about device and guest PASID binding 305 - * @argsz: User filled size of this data 306 - * @version: Version of this data structure 307 - * @format: PASID table entry format 308 - * @flags: Additional information on guest bind request 309 - * @gpgd: Guest page directory base of the guest mm to bind 310 - * @hpasid: Process address space ID used for the guest mm in host IOMMU 311 - * @gpasid: Process address space ID used for the guest mm in guest IOMMU 312 - * @addr_width: Guest virtual address width 313 - * @padding: Reserved for future use (should be zero) 314 - * @vtd: Intel VT-d specific data 315 - * 316 - * Guest to host PASID mapping can be an identity or non-identity, where guest 317 - * has its own PASID space. For non-identify mapping, guest to host PASID lookup 318 - * is needed when VM programs guest PASID into an assigned device. VMM may 319 - * trap such PASID programming then request host IOMMU driver to convert guest 320 - * PASID to host PASID based on this bind data. 321 - */ 322 - struct iommu_gpasid_bind_data { 323 - __u32 argsz; 324 - #define IOMMU_GPASID_BIND_VERSION_1 1 325 - __u32 version; 326 - #define IOMMU_PASID_FORMAT_INTEL_VTD 1 327 - #define IOMMU_PASID_FORMAT_LAST 2 328 - __u32 format; 329 - __u32 addr_width; 330 - #define IOMMU_SVA_GPASID_VAL (1 << 0) /* guest PASID valid */ 331 - __u64 flags; 332 - __u64 gpgd; 333 - __u64 hpasid; 334 - __u64 gpasid; 335 - __u8 padding[8]; 336 - /* Vendor specific data */ 337 - union { 338 - struct iommu_gpasid_bind_data_vtd vtd; 339 - } vendor; 340 - }; 341 - 342 161 #endif /* _UAPI_IOMMU_H */