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

Merge tag 'iommu-fixes-v4.2-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu

Pull iommu fixes from Joerg Roedel:
"The fixes include:

- a couple of fixes for the new ARM-SMMUv3 driver to fix issues found
on the first real implementation of that hardware.

- a patch for the Intel VT-d driver to fix a domain-id leak"

* tag 'iommu-fixes-v4.2-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu:
iommu/vt-d: Fix VM domain ID leak
iommu/arm-smmu: Skip the execution of CMD_PREFETCH_CONFIG
iommu/arm-smmu: Enlarge STRTAB_L1_SZ_SHIFT to support larger sidsize
iommu/arm-smmu: Fix the values of ARM64_TCR_{I,O}RGN0_SHIFT
iommu/arm-smmu: Fix LOG2SIZE setting for 2-level stream tables
iommu/arm-smmu: Fix the index calculation of strtab

+55 -17
+3
Documentation/devicetree/bindings/iommu/arm,smmu-v3.txt
··· 35 35 36 36 NOTE: this only applies to the SMMU itself, not 37 37 masters connected upstream of the SMMU. 38 + 39 + - hisilicon,broken-prefetch-cmd 40 + : Avoid sending CMD_PREFETCH_* commands to the SMMU.
+46 -14
drivers/iommu/arm-smmu-v3.c
··· 199 199 * Stream table. 200 200 * 201 201 * Linear: Enough to cover 1 << IDR1.SIDSIZE entries 202 - * 2lvl: 8k L1 entries, 256 lazy entries per table (each table covers a PCI bus) 202 + * 2lvl: 128k L1 entries, 203 + * 256 lazy entries per table (each table covers a PCI bus) 203 204 */ 204 - #define STRTAB_L1_SZ_SHIFT 16 205 + #define STRTAB_L1_SZ_SHIFT 20 205 206 #define STRTAB_SPLIT 8 206 207 207 208 #define STRTAB_L1_DESC_DWORDS 1 ··· 270 269 #define ARM64_TCR_TG0_SHIFT 14 271 270 #define ARM64_TCR_TG0_MASK 0x3UL 272 271 #define CTXDESC_CD_0_TCR_IRGN0_SHIFT 8 273 - #define ARM64_TCR_IRGN0_SHIFT 24 272 + #define ARM64_TCR_IRGN0_SHIFT 8 274 273 #define ARM64_TCR_IRGN0_MASK 0x3UL 275 274 #define CTXDESC_CD_0_TCR_ORGN0_SHIFT 10 276 - #define ARM64_TCR_ORGN0_SHIFT 26 275 + #define ARM64_TCR_ORGN0_SHIFT 10 277 276 #define ARM64_TCR_ORGN0_MASK 0x3UL 278 277 #define CTXDESC_CD_0_TCR_SH0_SHIFT 12 279 278 #define ARM64_TCR_SH0_SHIFT 12 ··· 543 542 #define ARM_SMMU_FEAT_HYP (1 << 12) 544 543 u32 features; 545 544 545 + #define ARM_SMMU_OPT_SKIP_PREFETCH (1 << 0) 546 + u32 options; 547 + 546 548 struct arm_smmu_cmdq cmdq; 547 549 struct arm_smmu_evtq evtq; 548 550 struct arm_smmu_priq priq; ··· 606 602 static DEFINE_SPINLOCK(arm_smmu_devices_lock); 607 603 static LIST_HEAD(arm_smmu_devices); 608 604 605 + struct arm_smmu_option_prop { 606 + u32 opt; 607 + const char *prop; 608 + }; 609 + 610 + static struct arm_smmu_option_prop arm_smmu_options[] = { 611 + { ARM_SMMU_OPT_SKIP_PREFETCH, "hisilicon,broken-prefetch-cmd" }, 612 + { 0, NULL}, 613 + }; 614 + 609 615 static struct arm_smmu_domain *to_smmu_domain(struct iommu_domain *dom) 610 616 { 611 617 return container_of(dom, struct arm_smmu_domain, domain); 618 + } 619 + 620 + static void parse_driver_options(struct arm_smmu_device *smmu) 621 + { 622 + int i = 0; 623 + 624 + do { 625 + if (of_property_read_bool(smmu->dev->of_node, 626 + arm_smmu_options[i].prop)) { 627 + smmu->options |= arm_smmu_options[i].opt; 628 + dev_notice(smmu->dev, "option %s\n", 629 + arm_smmu_options[i].prop); 630 + } 631 + } while (arm_smmu_options[++i].opt); 612 632 } 613 633 614 634 /* Low-level queue manipulation functions */ ··· 1064 1036 arm_smmu_sync_ste_for_sid(smmu, sid); 1065 1037 1066 1038 /* It's likely that we'll want to use the new STE soon */ 1067 - arm_smmu_cmdq_issue_cmd(smmu, &prefetch_cmd); 1039 + if (!(smmu->options & ARM_SMMU_OPT_SKIP_PREFETCH)) 1040 + arm_smmu_cmdq_issue_cmd(smmu, &prefetch_cmd); 1068 1041 } 1069 1042 1070 1043 static void arm_smmu_init_bypass_stes(u64 *strtab, unsigned int nent) ··· 1093 1064 return 0; 1094 1065 1095 1066 size = 1 << (STRTAB_SPLIT + ilog2(STRTAB_STE_DWORDS) + 3); 1096 - strtab = &cfg->strtab[sid >> STRTAB_SPLIT << STRTAB_L1_DESC_DWORDS]; 1067 + strtab = &cfg->strtab[(sid >> STRTAB_SPLIT) * STRTAB_L1_DESC_DWORDS]; 1097 1068 1098 1069 desc->span = STRTAB_SPLIT + 1; 1099 1070 desc->l2ptr = dma_zalloc_coherent(smmu->dev, size, &desc->l2ptr_dma, ··· 2049 2020 { 2050 2021 void *strtab; 2051 2022 u64 reg; 2052 - u32 size; 2023 + u32 size, l1size; 2053 2024 int ret; 2054 2025 struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; 2055 2026 2056 2027 /* Calculate the L1 size, capped to the SIDSIZE */ 2057 2028 size = STRTAB_L1_SZ_SHIFT - (ilog2(STRTAB_L1_DESC_DWORDS) + 3); 2058 2029 size = min(size, smmu->sid_bits - STRTAB_SPLIT); 2059 - if (size + STRTAB_SPLIT < smmu->sid_bits) 2030 + cfg->num_l1_ents = 1 << size; 2031 + 2032 + size += STRTAB_SPLIT; 2033 + if (size < smmu->sid_bits) 2060 2034 dev_warn(smmu->dev, 2061 2035 "2-level strtab only covers %u/%u bits of SID\n", 2062 - size + STRTAB_SPLIT, smmu->sid_bits); 2036 + size, smmu->sid_bits); 2063 2037 2064 - cfg->num_l1_ents = 1 << size; 2065 - size = cfg->num_l1_ents * (STRTAB_L1_DESC_DWORDS << 3); 2066 - strtab = dma_zalloc_coherent(smmu->dev, size, &cfg->strtab_dma, 2038 + l1size = cfg->num_l1_ents * (STRTAB_L1_DESC_DWORDS << 3); 2039 + strtab = dma_zalloc_coherent(smmu->dev, l1size, &cfg->strtab_dma, 2067 2040 GFP_KERNEL); 2068 2041 if (!strtab) { 2069 2042 dev_err(smmu->dev, ··· 2086 2055 ret = arm_smmu_init_l1_strtab(smmu); 2087 2056 if (ret) 2088 2057 dma_free_coherent(smmu->dev, 2089 - cfg->num_l1_ents * 2090 - (STRTAB_L1_DESC_DWORDS << 3), 2058 + l1size, 2091 2059 strtab, 2092 2060 cfg->strtab_dma); 2093 2061 return ret; ··· 2602 2572 irq = platform_get_irq_byname(pdev, "gerror"); 2603 2573 if (irq > 0) 2604 2574 smmu->gerr_irq = irq; 2575 + 2576 + parse_driver_options(smmu); 2605 2577 2606 2578 /* Probe the h/w */ 2607 2579 ret = arm_smmu_device_probe(smmu);
+6 -3
drivers/iommu/intel-iommu.c
··· 1830 1830 1831 1831 static void domain_exit(struct dmar_domain *domain) 1832 1832 { 1833 + struct dmar_drhd_unit *drhd; 1834 + struct intel_iommu *iommu; 1833 1835 struct page *freelist = NULL; 1834 - int i; 1835 1836 1836 1837 /* Domain 0 is reserved, so dont process it */ 1837 1838 if (!domain) ··· 1852 1851 1853 1852 /* clear attached or cached domains */ 1854 1853 rcu_read_lock(); 1855 - for_each_set_bit(i, domain->iommu_bmp, g_num_of_iommus) 1856 - iommu_detach_domain(domain, g_iommus[i]); 1854 + for_each_active_iommu(iommu, drhd) 1855 + if (domain_type_is_vm(domain) || 1856 + test_bit(iommu->seq_id, domain->iommu_bmp)) 1857 + iommu_detach_domain(domain, iommu); 1857 1858 rcu_read_unlock(); 1858 1859 1859 1860 dma_free_pagelist(freelist);