1. 29 4月, 2020 2 次提交
    • G
      iommu/mediatek: Fix MTK_IOMMU dependencies · d1dcb725
      Geert Uytterhoeven 提交于
      If NO_DMA=y (e.g. Sun-3 all{mod,yes}-config):
      
          drivers/iommu/dma-iommu.o: In function `iommu_dma_mmap':
          dma-iommu.c:(.text+0x836): undefined reference to `dma_pgprot'
      
      IOMMU_DMA must not be selected, unless HAS_DMA=y.
      
      Hence fix this by making MTK_IOMMU depend on HAS_DMA.
      While at it, remove the dependency on ARM || ARM64, as that is already
      implied by the dependency on ARCH_MEDIATEK.
      
      Fixes: e93a1695 ("iommu: Enable compile testing for some of drivers")
      Signed-off-by: NGeert Uytterhoeven <geert@linux-m68k.org>
      Link: https://lore.kernel.org/r/20200410143047.19691-1-geert@linux-m68k.orgSigned-off-by: NJoerg Roedel <jroedel@suse.de>
      d1dcb725
    • K
      iommu: Fix the memory leak in dev_iommu_free() · 5375e874
      Kevin Hao 提交于
      In iommu_probe_device(), we would invoke dev_iommu_free() to free the
      dev->iommu after the ->add_device() returns failure. But after commit
      72acd9df ("iommu: Move iommu_fwspec to struct dev_iommu"), we also
      need to free the iommu_fwspec before the dev->iommu is freed. This fixes
      the following memory leak reported by kmemleak:
        unreferenced object 0xffff000bc836c700 (size 128):
          comm "swapper/0", pid 1, jiffies 4294896304 (age 782.120s)
          hex dump (first 32 bytes):
            00 00 00 00 00 00 00 00 d8 cd 9b ff 0b 00 ff ff  ................
            00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
          backtrace:
            [<00000000df34077b>] kmem_cache_alloc_trace+0x244/0x4b0
            [<000000000e560ac0>] iommu_fwspec_init+0x7c/0xb0
            [<0000000075eda275>] of_iommu_xlate+0x80/0xe8
            [<00000000728d6bf9>] of_pci_iommu_init+0xb0/0xb8
            [<00000000d001fe6f>] pci_for_each_dma_alias+0x48/0x190
            [<000000006db6bbce>] of_iommu_configure+0x1ac/0x1d0
            [<00000000634745f8>] of_dma_configure+0xdc/0x220
            [<000000002cbc8ba0>] pci_dma_configure+0x50/0x78
            [<00000000cdf6e193>] really_probe+0x8c/0x340
            [<00000000fddddc46>] driver_probe_device+0x60/0xf8
            [<0000000061bcdb51>] __device_attach_driver+0x8c/0xd0
            [<000000009b9ff58e>] bus_for_each_drv+0x80/0xd0
            [<000000004b9c8aa3>] __device_attach+0xec/0x148
            [<00000000a5c13bf3>] device_attach+0x1c/0x28
            [<000000005071e151>] pci_bus_add_device+0x58/0xd0
            [<000000002d4f87d1>] pci_bus_add_devices+0x40/0x90
      
      Fixes: 72acd9df ("iommu: Move iommu_fwspec to struct dev_iommu")
      Signed-off-by: NKevin Hao <haokexin@gmail.com>
      Link: https://lore.kernel.org/r/20200402143749.40500-1-haokexin@gmail.comSigned-off-by: NJoerg Roedel <jroedel@suse.de>
      5375e874
  2. 27 3月, 2020 15 次提交
  3. 19 3月, 2020 8 次提交
  4. 15 3月, 2020 1 次提交
  5. 14 3月, 2020 3 次提交
    • S
      iommu/amd: Fix IOMMU AVIC not properly update the is_run bit in IRTE · 730ad0ed
      Suravee Suthikulpanit 提交于
      Commit b9c6ff94 ("iommu/amd: Re-factor guest virtual APIC
      (de-)activation code") accidentally left out the ir_data pointer when
      calling modity_irte_ga(), which causes the function amd_iommu_update_ga()
      to return prematurely due to struct amd_ir_data.ref is NULL and
      the "is_run" bit of IRTE does not get updated properly.
      
      This results in bad I/O performance since IOMMU AVIC always generate GA Log
      entry and notify IOMMU driver and KVM when it receives interrupt from the
      PCI pass-through device instead of directly inject interrupt to the vCPU.
      
      Fixes by passing ir_data when calling modify_irte_ga() as done previously.
      
      Fixes: b9c6ff94 ("iommu/amd: Re-factor guest virtual APIC (de-)activation code")
      Signed-off-by: NSuravee Suthikulpanit <suravee.suthikulpanit@amd.com>
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      730ad0ed
    • D
      iommu/vt-d: Ignore devices with out-of-spec domain number · da72a379
      Daniel Drake 提交于
      VMD subdevices are created with a PCI domain ID of 0x10000 or
      higher.
      
      These subdevices are also handled like all other PCI devices by
      dmar_pci_bus_notifier().
      
      However, when dmar_alloc_pci_notify_info() take records of such devices,
      it will truncate the domain ID to a u16 value (in info->seg).
      The device at (e.g.) 10000:00:02.0 is then treated by the DMAR code as if
      it is 0000:00:02.0.
      
      In the unlucky event that a real device also exists at 0000:00:02.0 and
      also has a device-specific entry in the DMAR table,
      dmar_insert_dev_scope() will crash on:
         BUG_ON(i >= devices_cnt);
      
      That's basically a sanity check that only one PCI device matches a
      single DMAR entry; in this case we seem to have two matching devices.
      
      Fix this by ignoring devices that have a domain number higher than
      what can be looked up in the DMAR table.
      
      This problem was carefully diagnosed by Jian-Hong Pan.
      Signed-off-by: NLu Baolu <baolu.lu@linux.intel.com>
      Signed-off-by: NDaniel Drake <drake@endlessm.com>
      Fixes: 59ce0515 ("iommu/vt-d: Update DRHD/RMRR/ATSR device scope caches when PCI hotplug happens")
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      da72a379
    • Z
      iommu/vt-d: Fix the wrong printing in RHSA parsing · b0bb0c22
      Zhenzhong Duan 提交于
      When base address in RHSA structure doesn't match base address in
      each DRHD structure, the base address in last DRHD is printed out.
      
      This doesn't make sense when there are multiple DRHD units, fix it
      by printing the buggy RHSA's base address.
      Signed-off-by: NLu Baolu <baolu.lu@linux.intel.com>
      Signed-off-by: NZhenzhong Duan <zhenzhong.duan@gmail.com>
      Fixes: fd0c8894 ("intel-iommu: Set a more specific taint flag for invalid BIOS DMAR tables")
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      b0bb0c22
  6. 13 3月, 2020 4 次提交
  7. 10 3月, 2020 2 次提交
    • Q
      iommu/vt-d: Silence RCU-list debugging warnings · f5152416
      Qian Cai 提交于
      Similar to the commit 02d715b4 ("iommu/vt-d: Fix RCU list debugging
      warnings"), there are several other places that call
      list_for_each_entry_rcu() outside of an RCU read side critical section
      but with dmar_global_lock held. Silence those false positives as well.
      
       drivers/iommu/intel-iommu.c:4288 RCU-list traversed in non-reader section!!
       1 lock held by swapper/0/1:
        #0: ffffffff935892c8 (dmar_global_lock){+.+.}, at: intel_iommu_init+0x1ad/0xb97
      
       drivers/iommu/dmar.c:366 RCU-list traversed in non-reader section!!
       1 lock held by swapper/0/1:
        #0: ffffffff935892c8 (dmar_global_lock){+.+.}, at: intel_iommu_init+0x125/0xb97
      
       drivers/iommu/intel-iommu.c:5057 RCU-list traversed in non-reader section!!
       1 lock held by swapper/0/1:
        #0: ffffffffa71892c8 (dmar_global_lock){++++}, at: intel_iommu_init+0x61a/0xb13
      Signed-off-by: NQian Cai <cai@lca.pw>
      Acked-by: NLu Baolu <baolu.lu@linux.intel.com>
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      f5152416
    • Q
      iommu/vt-d: Fix RCU-list bugs in intel_iommu_init() · 2d48ea0e
      Qian Cai 提交于
      There are several places traverse RCU-list without holding any lock in
      intel_iommu_init(). Fix them by acquiring dmar_global_lock.
      
       WARNING: suspicious RCU usage
       -----------------------------
       drivers/iommu/intel-iommu.c:5216 RCU-list traversed in non-reader section!!
      
       other info that might help us debug this:
      
       rcu_scheduler_active = 2, debug_locks = 1
       no locks held by swapper/0/1.
      
       Call Trace:
        dump_stack+0xa0/0xea
        lockdep_rcu_suspicious+0x102/0x10b
        intel_iommu_init+0x947/0xb13
        pci_iommu_init+0x26/0x62
        do_one_initcall+0xfe/0x500
        kernel_init_freeable+0x45a/0x4f8
        kernel_init+0x11/0x139
        ret_from_fork+0x3a/0x50
       DMAR: Intel(R) Virtualization Technology for Directed I/O
      
      Fixes: d8190dc6 ("iommu/vt-d: Enable DMA remapping after rmrr mapped")
      Signed-off-by: NQian Cai <cai@lca.pw>
      Acked-by: NLu Baolu <baolu.lu@linux.intel.com>
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      2d48ea0e
  8. 04 3月, 2020 5 次提交
    • M
      iommu/dma: Fix MSI reservation allocation · 65ac74f1
      Marc Zyngier 提交于
      The way cookie_init_hw_msi_region() allocates the iommu_dma_msi_page
      structures doesn't match the way iommu_put_dma_cookie() frees them.
      
      The former performs a single allocation of all the required structures,
      while the latter tries to free them one at a time. It doesn't quite
      work for the main use case (the GICv3 ITS where the range is 64kB)
      when the base granule size is 4kB.
      
      This leads to a nice slab corruption on teardown, which is easily
      observable by simply creating a VF on a SRIOV-capable device, and
      tearing it down immediately (no need to even make use of it).
      Fortunately, this only affects systems where the ITS isn't translated
      by the SMMU, which are both rare and non-standard.
      
      Fix it by allocating iommu_dma_msi_page structures one at a time.
      
      Fixes: 7c1b058c ("iommu/dma: Handle IOMMU API reserved regions")
      Signed-off-by: NMarc Zyngier <maz@kernel.org>
      Reviewed-by: NEric Auger <eric.auger@redhat.com>
      Cc: Robin Murphy <robin.murphy@arm.com>
      Cc: Joerg Roedel <jroedel@suse.de>
      Cc: Will Deacon <will@kernel.org>
      Cc: stable@vger.kernel.org
      Reviewed-by: NRobin Murphy <robin.murphy@arm.com>
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      65ac74f1
    • K
      iommu: Enable compile testing for some of drivers · e93a1695
      Krzysztof Kozlowski 提交于
      Some of the IOMMU drivers can be compile tested to increase build
      coverage.  The OMAP, Rockchip and Exynos drivers use
      device.dev_archdata.iommu field which does not exist on all platforms.
      The sPAPR TCE and ARM SMMU have also restrictions where they can be
      built.
      Signed-off-by: NKrzysztof Kozlowski <krzk@kernel.org>
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      e93a1695
    • K
      iommu/omap: Fix -Woverflow warnings when compiling on 64-bit architectures · d84edddc
      Krzysztof Kozlowski 提交于
      Although the OMAP IOMMU driver supports only ARMv7 (32-bit) platforms,
      it can be compile tested for other architectures, including 64-bit ones.
      In such case the warning appears:
      
             In file included from drivers/iommu/omap-iommu.c:33:0:
             drivers/iommu/omap-iommu.c: In function 'omap_iommu_iova_to_phys':
          >> drivers/iommu/omap-iopgtable.h:44:21: warning: large integer implicitly truncated to unsigned type [-Woverflow]
              #define IOPTE_MASK  (~(IOPTE_SIZE - 1))
                                  ^
          >> drivers/iommu/omap-iommu.c:1641:41: note: in expansion of macro 'IOPTE_MASK'
                 ret = omap_iommu_translate(*pte, da, IOPTE_MASK);
                                                      ^~~~~~~~~~
      
      Fix this by using architecture-depending types in omap_iommu_translate():
      1. Pointer should be cast to unsigned long,
      2. Virtual addresses should be cast to dma_addr_t.
      
      On 32-bit this will be the same as original code (using u32).  On 64-bit
      it should produce meaningful result, although it does not really matter.
      Reported-by: Nkbuild test robot <lkp@intel.com>
      Signed-off-by: NKrzysztof Kozlowski <krzk@kernel.org>
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      d84edddc
    • K
      iommu/omap: Fix printing format for size_t on 64-bit · 6135a891
      Krzysztof Kozlowski 提交于
      Print size_t as %zu or %zx to fix -Wformat warnings when compiling on
      64-bit platform (e.g. with COMPILE_TEST):
      
          drivers/iommu/omap-iommu.c: In function ‘flush_iotlb_page’:
          drivers/iommu/omap-iommu.c:437:47: warning:
              format ‘%x’ expects argument of type ‘unsigned int’,
              but argument 7 has type ‘size_t {aka long unsigned int}’ [-Wformat=]
      Acked-by: NSuman Anna <s-anna@ti.com>
      Signed-off-by: NKrzysztof Kozlowski <krzk@kernel.org>
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      6135a891
    • K
      iommu/omap: Fix pointer cast -Wpointer-to-int-cast warnings on 64 bit · f2ce16c3
      Krzysztof Kozlowski 提交于
      pointers should be casted to unsigned long to avoid
      -Wpointer-to-int-cast warnings when compiling on 64-bit platform (e.g.
      with COMPILE_TEST):
      
          drivers/iommu/omap-iommu.c: In function ‘omap2_iommu_enable’:
          drivers/iommu/omap-iommu.c:170:25: warning:
              cast from pointer to integer of different size [-Wpointer-to-int-cast]
            if (!obj->iopgd || !IS_ALIGNED((u32)obj->iopgd,  SZ_16K))
                                   ^
      Signed-off-by: NKrzysztof Kozlowski <krzk@kernel.org>
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      f2ce16c3