1. 29 9月, 2021 1 次提交
    • H
      IOMMU: SMMUv2: Bypass SMMU in default for some SoCs · 4f9fce3a
      Hanjun Guo 提交于
      hulk inclusion
      category: feature
      bugzilla: https://gitee.com/openeuler/kernel/issues/I41AUQ
      CVE: NA
      
      -------------------------------------
      
      Support SMMU default bypass for some CPU SoCs which the SMMU is not
      functional well in address translation mode.
      
      We already have the .def_domain_type hook for iommu_ops in iommu driver,
      so we add the CPU SoC SMMU bypass code in the .def_domain_type hook in
      smmuv2 driver, and return IOMMU_DOMAIN_IDENTITY for such SoCs.
      
      After we add the hook, we set all the devices for such SoCs in pass
      through mode, no matter adding iommu.passthrough=off/on or not in the
      boot cmdline.
      
      While we at it, update the config SMMU_BYPASS_DEV to specify the
      useage.
      Signed-off-by: NHanjun Guo <guohanjun@huawei.com>
      Cc: Guo Hui <guohui@uniontech.com>
      Cc: Cheng Jian <cj.chengjian@huawei.com>
      Cc: Zhen Lei <thunder.leizhen@huawei.com>
      Cc: Xiuqi Xie <xiexiuqi@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      4f9fce3a
  2. 31 8月, 2021 1 次提交
  3. 03 6月, 2021 3 次提交
    • J
      iommu/arm-smmu-v3: Support auxiliary domains · 7ca84842
      Jean-Philippe Brucker 提交于
      maillist inclusion
      category: feature
      bugzilla: 51855
      CVE: NA
      
      Reference: https://jpbrucker.net/git/linux/commit/?h=sva/2021-03-01&id=4411467daeff90c7c371cef6369e4bf8561fb00e
      
      ---------------------------------------------
      
      In commit a3a19592 ("iommu: Add APIs for multiple domains per
      device"), the IOMMU API gained the concept of auxiliary domains (AUXD),
      which allows to control the PASID-tagged address spaces of a device. With
      AUXD the PASID address space are not shared with the CPU, but are instead
      modified with iommu_map() and iommu_unmap() calls on auxiliary domains.
      
      Add auxiliary domain support to the SMMUv3 driver. Device drivers allocate
      an unmanaged IOMMU domain with iommu_domain_alloc(), and attach it to the
      device with iommu_aux_attach_domain().
      
      The AUXD API is fairly permissive, and allows to attach an IOMMU domain in
      both normal and auxiliary mode at the same time - one device can be
      attached to the domain normally, and another device can be attached
      through one of its PASIDs. To avoid excessive complexity in the SMMU
      implementation we pose some restrictions on supported AUXD usage:
      
      * A domain is either in auxiliary mode or normal mode. And that state is
        sticky. Once detached the domain has to be re-attached in the same mode.
      
      * An auxiliary domain can have a single parent domain. Two devices can be
        attached to the same auxiliary domain only if they are attached to the
        same parent domain.
      
      In practice these shouldn't be problematic, since we have the same kind of
      restriction on normal domains and users have been able to cope so far: at
      the moment a domain cannot be attached to two devices behind different
      SMMUs. When VFIO puts two such devices in the same container, it simply
      falls back to allocating two separate IOMMU domains.
      
      Be careful with mixing ATS and PASID. PCIe does not provide a way to only
      invalidate non-PASID ATC entries, without also invalidating all
      PASID-tagged ATC entries in the same address range! Try to avoid using
      PASID and non-PASID contexts at the same time.
      
      FIXME: if a device is removed from the domain while we drop an auxiliary
      domain, there may be a problem. We remove the ctx desc, invalidate CD
      cache for all devices, then invaliate the ATC for all devices. But we
      drop the devices lock between the two invalidations so if a device is
      removed we might miss the ATC inval?
      Signed-off-by: NJean-Philippe Brucker <jean-philippe@linaro.org>
      Signed-off-by: NLijun Fang <fanglijun3@huawei.com>
      Reviewed-by: NWeilong Chen <chenweilong@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      7ca84842
    • J
      iommu/arm-smmu-v3: Implement iommu_sva_bind/unbind() · fafdba2c
      Jean-Philippe Brucker 提交于
      mainline inclusion
      from mainline-5.11-rc1
      commit 32784a95
      category: feature
      bugzilla: 51855
      CVE: NA
      
      ---------------------------------------------
      
      The sva_bind() function allows devices to access process address spaces
      using a PASID (aka SSID).
      
      (1) bind() allocates or gets an existing MMU notifier tied to the
          (domain, mm) pair. Each mm gets one PASID.
      
      (2) Any change to the address space calls invalidate_range() which sends
          ATC invalidations (in a subsequent patch).
      
      (3) When the process address space dies, the release() notifier disables
          the CD to allow reclaiming the page tables. Since release() has to
          be light we do not instruct device drivers to stop DMA here, we just
          ignore incoming page faults from this point onwards.
      
          To avoid any event 0x0a print (C_BAD_CD) we disable translation
          without clearing CD.V. PCIe Translation Requests and Page Requests
          are silently denied. Don't clear the R bit because the S bit can't
          be cleared when STALL_MODEL==0b10 (forced), and clearing R without
          clearing S is useless. Faulting transactions will stall and will be
          aborted by the IOPF handler.
      
      (4) After stopping DMA, the device driver releases the bond by calling
          unbind(). We release the MMU notifier, free the PASID and the bond.
      
      Three structures keep track of bonds:
      * arm_smmu_bond: one per {device, mm} pair, the handle returned to the
        device driver for a bind() request.
      * arm_smmu_mmu_notifier: one per {domain, mm} pair, deals with ATS/TLB
        invalidations and clearing the context descriptor on mm exit.
      * arm_smmu_ctx_desc: one per mm, holds the pinned ASID and pgd.
      Signed-off-by: NJean-Philippe Brucker <jean-philippe@linaro.org>
      Link: https://lore.kernel.org/r/20201106155048.997886-4-jean-philippe@linaro.orgSigned-off-by: NWill Deacon <will@kernel.org>
      Signed-off-by: NLijun Fang <fanglijun3@huawei.com>
      Reviewed-by: NWeilong Chen <chenweilong@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      fafdba2c
    • J
      iommu/sva: Add PASID helpers · a00ec499
      Jean-Philippe Brucker 提交于
      mainline inclusion
      from mainline-5.11-rc1
      commit cfc78dfd
      category: feature
      bugzilla: 51855
      CVE: NA
      
      ---------------------------------------------
      
      Let IOMMU drivers allocate a single PASID per mm. Store the mm in the
      IOASID set to allow refcounting and searching mm by PASID, when handling
      an I/O page fault.
      Signed-off-by: NJean-Philippe Brucker <jean-philippe@linaro.org>
      Reviewed-by: NLu Baolu <baolu.lu@linux.intel.com>
      Link: https://lore.kernel.org/r/20201106155048.997886-3-jean-philippe@linaro.orgSigned-off-by: NWill Deacon <will@kernel.org>
      Signed-off-by: NLijun Fang <fanglijun3@huawei.com>
      Reviewed-by: NWeilong Chen <chenweilong@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      a00ec499
  4. 29 9月, 2020 1 次提交
  5. 18 9月, 2020 1 次提交
  6. 29 7月, 2020 2 次提交
  7. 19 7月, 2020 1 次提交
  8. 10 7月, 2020 2 次提交
  9. 30 6月, 2020 1 次提交
  10. 23 6月, 2020 1 次提交
  11. 14 6月, 2020 1 次提交
    • M
      treewide: replace '---help---' in Kconfig files with 'help' · a7f7f624
      Masahiro Yamada 提交于
      Since commit 84af7a61 ("checkpatch: kconfig: prefer 'help' over
      '---help---'"), the number of '---help---' has been gradually
      decreasing, but there are still more than 2400 instances.
      
      This commit finishes the conversion. While I touched the lines,
      I also fixed the indentation.
      
      There are a variety of indentation styles found.
      
        a) 4 spaces + '---help---'
        b) 7 spaces + '---help---'
        c) 8 spaces + '---help---'
        d) 1 space + 1 tab + '---help---'
        e) 1 tab + '---help---'    (correct indentation)
        f) 1 tab + 1 space + '---help---'
        g) 1 tab + 2 spaces + '---help---'
      
      In order to convert all of them to 1 tab + 'help', I ran the
      following commend:
      
        $ find . -name 'Kconfig*' | xargs sed -i 's/^[[:space:]]*---help---/\thelp/'
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      a7f7f624
  12. 14 5月, 2020 1 次提交
  13. 29 4月, 2020 2 次提交
    • K
      iommu: spapr_tce: Disable compile testing to fix build on book3s_32 config · 9dd124b6
      Krzysztof Kozlowski 提交于
      Although SPAPR_TCE_IOMMU itself can be compile tested on certain PowerPC
      configurations, its presence makes arch/powerpc/kvm/Makefile to select
      modules which do not build in such configuration.
      
      The arch/powerpc/kvm/ modules use kvm_arch.spapr_tce_tables which exists
      only with CONFIG_PPC_BOOK3S_64.  However these modules are selected when
      COMPILE_TEST and SPAPR_TCE_IOMMU are chosen leading to build failures:
      
          In file included from arch/powerpc/include/asm/book3s/64/mmu-hash.h:20:0,
                           from arch/powerpc/kvm/book3s_64_vio_hv.c:22:
          arch/powerpc/include/asm/book3s/64/pgtable.h:17:0: error: "_PAGE_EXEC" redefined [-Werror]
           #define _PAGE_EXEC  0x00001 /* execute permission */
      
          In file included from arch/powerpc/include/asm/book3s/32/pgtable.h:8:0,
                           from arch/powerpc/include/asm/book3s/pgtable.h:8,
                           from arch/powerpc/include/asm/pgtable.h:18,
                           from include/linux/mm.h:95,
                           from arch/powerpc/include/asm/io.h:29,
                           from include/linux/io.h:13,
                           from include/linux/irq.h:20,
                           from arch/powerpc/include/asm/hardirq.h:6,
                           from include/linux/hardirq.h:9,
                           from include/linux/kvm_host.h:7,
                           from arch/powerpc/kvm/book3s_64_vio_hv.c:12:
          arch/powerpc/include/asm/book3s/32/hash.h:29:0: note: this is the location of the previous definition
           #define _PAGE_EXEC 0x200 /* software: exec allowed */
      
      Fixes: e93a1695 ("iommu: Enable compile testing for some of drivers")
      Reported-by: NGeert Uytterhoeven <geert@linux-m68k.org>
      Signed-off-by: NKrzysztof Kozlowski <krzk@kernel.org>
      Link: https://lore.kernel.org/r/20200414142630.21153-1-krzk@kernel.orgSigned-off-by: NJoerg Roedel <jroedel@suse.de>
      9dd124b6
    • 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
  14. 27 3月, 2020 1 次提交
  15. 04 3月, 2020 1 次提交
  16. 28 2月, 2020 1 次提交
  17. 07 1月, 2020 2 次提交
  18. 23 12月, 2019 3 次提交
  19. 22 11月, 2019 1 次提交
  20. 16 10月, 2019 1 次提交
  21. 15 10月, 2019 2 次提交
  22. 11 9月, 2019 1 次提交
  23. 17 8月, 2019 1 次提交
  24. 07 6月, 2019 1 次提交
  25. 27 5月, 2019 2 次提交
  26. 21 5月, 2019 1 次提交
  27. 03 5月, 2019 1 次提交
    • J
      iommu/dma-iommu: Split iommu_dma_map_msi_msg() in two parts · ece6e6f0
      Julien Grall 提交于
      On RT, iommu_dma_map_msi_msg() may be called from non-preemptible
      context. This will lead to a splat with CONFIG_DEBUG_ATOMIC_SLEEP as
      the function is using spin_lock (they can sleep on RT).
      
      iommu_dma_map_msi_msg() is used to map the MSI page in the IOMMU PT
      and update the MSI message with the IOVA.
      
      Only the part to lookup for the MSI page requires to be called in
      preemptible context. As the MSI page cannot change over the lifecycle
      of the MSI interrupt, the lookup can be cached and re-used later on.
      
      iomma_dma_map_msi_msg() is now split in two functions:
          - iommu_dma_prepare_msi(): This function will prepare the mapping
          in the IOMMU and store the cookie in the structure msi_desc. This
          function should be called in preemptible context.
          - iommu_dma_compose_msi_msg(): This function will update the MSI
          message with the IOVA when the device is behind an IOMMU.
      Signed-off-by: NJulien Grall <julien.grall@arm.com>
      Reviewed-by: NRobin Murphy <robin.murphy@arm.com>
      Reviewed-by: NEric Auger <eric.auger@redhat.com>
      Acked-by: NJoerg Roedel <jroedel@suse.de>
      Signed-off-by: NMarc Zyngier <marc.zyngier@arm.com>
      ece6e6f0
  28. 05 4月, 2019 1 次提交
    • D
      iommu/arm-smmu: Break insecure users by disabling bypass by default · 954a03be
      Douglas Anderson 提交于
      If you're bisecting why your peripherals stopped working, it's
      probably this CL.  Specifically if you see this in your dmesg:
        Unexpected global fault, this could be serious
      ...then it's almost certainly this CL.
      
      Running your IOMMU-enabled peripherals with the IOMMU in bypass mode
      is insecure and effectively disables the protection they provide.
      There are few reasons to allow unmatched stream bypass, and even fewer
      good ones.
      
      This patch starts the transition over to make it much harder to run
      your system insecurely.  Expected steps:
      
      1. By default disable bypass (so anyone insecure will notice) but make
         it easy for someone to re-enable bypass with just a KConfig change.
         That's this patch.
      
      2. After people have had a little time to come to grips with the fact
         that they need to set their IOMMUs properly and have had time to
         dig into how to do this, the KConfig will be eliminated and bypass
         will simply be disabled.  Folks who are truly upset and still
         haven't fixed their system can either figure out how to add
         'arm-smmu.disable_bypass=n' to their command line or revert the
         patch in their own private kernel.  Of course these folks will be
         less secure.
      Suggested-by: NRobin Murphy <robin.murphy@arm.com>
      Reviewed-by: NMarc Gonzalez <marc.w.gonzalez@free.fr>
      Tested-by: NMarc Gonzalez <marc.w.gonzalez@free.fr>
      Signed-off-by: NDouglas Anderson <dianders@chromium.org>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      954a03be
  29. 28 2月, 2019 1 次提交
    • L
      iommu/hyper-v: Add Hyper-V stub IOMMU driver · 29217a47
      Lan Tianyu 提交于
      On the bare metal, enabling X2APIC mode requires interrupt remapping
      function which helps to deliver irq to cpu with 32-bit APIC ID.
      Hyper-V doesn't provide interrupt remapping function so far and Hyper-V
      MSI protocol already supports to deliver interrupt to the CPU whose
      virtual processor index is more than 255. IO-APIC interrupt still has
      8-bit APIC ID limitation.
      
      This patch is to add Hyper-V stub IOMMU driver in order to enable
      X2APIC mode successfully in Hyper-V Linux guest. The driver returns X2APIC
      interrupt remapping capability when X2APIC mode is available. Otherwise,
      it creates a Hyper-V irq domain to limit IO-APIC interrupts' affinity
      and make sure cpus assigned with IO-APIC interrupt have 8-bit APIC ID.
      
      Define 24 IO-APIC remapping entries because Hyper-V only expose one
      single IO-APIC and one IO-APIC has 24 pins according IO-APIC spec(
      https://pdos.csail.mit.edu/6.828/2016/readings/ia32/ioapic.pdf).
      Reviewed-by: NMichael Kelley <mikelley@microsoft.com>
      Signed-off-by: NLan Tianyu <Tianyu.Lan@microsoft.com>
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      29217a47
  30. 16 1月, 2019 1 次提交