1. 18 2月, 2016 5 次提交
    • W
      iommu/arm-smmu: Treat IOMMU_DOMAIN_DMA as bypass for now · cbf8277e
      Will Deacon 提交于
      Until all upstream devices have their DMA ops swizzled to point at the
      SMMU, we need to treat the IOMMU_DOMAIN_DMA domain as bypass to avoid
      putting devices into an empty address space when detaching from VFIO.
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      cbf8277e
    • W
      iommu/arm-smmu: Don't fail device attach if already attached to a domain · bc7f2ce0
      Will Deacon 提交于
      The ARM SMMU attach_dev implementations returns -EEXIST if the device
      being attached is already attached to a domain. This doesn't play nicely
      with the default domain, resulting in splats such as:
      
        WARNING: at drivers/iommu/iommu.c:1257
        Modules linked in:
      
        CPU: 3 PID: 1939 Comm: virtio-net-tx Tainted: G S              4.5.0-rc4+ #1
        Hardware name: FVP Base (DT)
        task: ffffffc87a9d0000 ti: ffffffc07a278000 task.ti: ffffffc07a278000
        PC is at __iommu_detach_group+0x68/0xe8
        LR is at __iommu_detach_group+0x48/0xe8
      
      This patch fixes the problem by forcefully detaching the device from
      its old domain, if present, when attaching to a new one. The unused
      ->detach_dev callback is also removed the iommu_ops structures.
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      bc7f2ce0
    • R
      iommu/arm-smmu: Allow disabling unmatched stream bypass · 25a1c96c
      Robin Murphy 提交于
      Borrow the disable_bypass parameter from the SMMUv3 driver as a handy
      debugging/security feature so that unmatched stream IDs (i.e. devices
      not attached to an IOMMU domain) may be configured to fault.
      
      Rather than introduce unsightly inconsistency, or repeat the existing
      unnecessary use of module_param_named(), fix that as well in passing.
      Signed-off-by: NRobin Murphy <robin.murphy@arm.com>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      25a1c96c
    • R
      iommu/arm-smmu: Support DMA-API domains · 9adb9594
      Robin Murphy 提交于
      With DMA mapping ops provided by the iommu-dma code, only a minimal
      contribution from the IOMMU driver is needed to create a suitable
      DMA-API domain for them to use. Implement this for the ARM SMMUs.
      Signed-off-by: NRobin Murphy <robin.murphy@arm.com>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      9adb9594
    • R
      iommu/arm-smmu: Treat all device transactions as unprivileged · d346180e
      Robin Murphy 提交于
      The IOMMU API has no concept of privilege so assumes all devices and
      mappings are equal, and indeed most non-CPU master devices on an AMBA
      interconnect make little use of the attribute bits on the bus thus by
      default perform unprivileged data accesses.
      
      Some devices, however, believe themselves more equal than others, such
      as programmable DMA controllers whose 'master' thread issues bus
      transactions marked as privileged instruction fetches, while the data
      accesses of its channel threads (under the control of Linux, at least)
      are marked as unprivileged. This poses a problem for implementing the
      DMA API on an IOMMU conforming to ARM VMSAv8, under which a page that is
      unprivileged-writeable is also implicitly privileged-execute-never.
      Given that, there is no one set of attributes with which iommu_map() can
      implement, say, dma_alloc_coherent() that will allow every possible type
      of access without something running into unexecepted permission faults.
      
      Fortunately the SMMU architecture provides a means to mitigate such
      issues by overriding the incoming attributes of a transaction; make use
      of that to strip the privileged/unprivileged status off incoming
      transactions, leaving just the instruction/data dichotomy which the
      IOMMU API does at least understand; Four states good, two states better.
      Signed-off-by: NRobin Murphy <robin.murphy@arm.com>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      d346180e
  2. 17 12月, 2015 4 次提交
    • R
      iommu/arm-smmu: Invalidate TLBs properly · 75df1386
      Robin Murphy 提交于
      When invalidating an IOVA range potentially spanning multiple pages,
      such as when removing an entire intermediate-level table, we currently
      only issue an invalidation for the first IOVA of that range. Since the
      architecture specifies that address-based TLB maintenance operations
      target a single entry, an SMMU could feasibly retain live entries for
      subsequent pages within that unmapped range, which is not good.
      
      Make sure we hit every possible entry by iterating over the whole range
      at the granularity provided by the pagetable implementation.
      Signed-off-by: NRobin Murphy <robin.murphy@arm.com>
      [will: added missing semicolons...]
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      75df1386
    • R
      iommu/io-pgtable: Indicate granule for TLB maintenance · 06c610e8
      Robin Murphy 提交于
      IOMMU hardware with range-based TLB maintenance commands can work
      happily with the iova and size arguments passed via the tlb_add_flush
      callback, but for IOMMUs which require separate commands per entry in
      the range, it is not straightforward to infer the necessary granularity
      when it comes to issuing the actual commands.
      
      Add an additional argument indicating the granularity for the benefit
      of drivers needing to know, and update the ARM LPAE code appropriately
      (for non-leaf invalidations we currently just assume the worst-case
      page granularity rather than walking the table to check).
      Signed-off-by: NRobin Murphy <robin.murphy@arm.com>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      06c610e8
    • P
      iommu/arm-smmu: Correct group reference count · 9a4a9d8c
      Peng Fan 提交于
      The basic flow for add a device:
       arm_smmu_add_device
              |->iommu_group_get_for_dev
                  |->iommu_group_get
                           return group;  (1)
                  |->ops->device_group : Init/increase reference count to/by 1.
                  |->iommu_group_add_device : Increase reference count by 1.
      		     return group   (2)
              |->return 0;
      
      Since we are adding one device, the flow is (2) and the group reference
      count will be increased by 2. So, we need to add iommu_group_put at the
      end of arm_smmu_add_device to decrease the count by 1.
      
      Also take the failure path into consideration when fail to add a device.
      Signed-off-by: NPeng Fan <van.freenix@gmail.com>
      Cc: Will Deacon <will.deacon@arm.com>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      9a4a9d8c
    • M
      iommu/arm-smmu: Delete an unnecessary check before free_io_pgtable_ops() · 44830b0c
      Markus Elfring 提交于
      The free_io_pgtable_ops() function tests whether its argument is NULL
      and then returns immediately. Thus the test around the call is not needed.
      
      This issue was detected by using the Coccinelle software.
      Signed-off-by: NMarkus Elfring <elfring@users.sourceforge.net>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      44830b0c
  3. 22 10月, 2015 1 次提交
  4. 15 10月, 2015 1 次提交
  5. 14 10月, 2015 2 次提交
  6. 06 8月, 2015 2 次提交
  7. 31 7月, 2015 1 次提交
    • R
      iommu/arm-smmu: Sort out coherency · bae2c2d4
      Robin Murphy 提交于
      Currently, we detect whether the SMMU has coherent page table walk
      capability from the IDR0.CTTW field, and base our cache maintenance
      decisions on that. In preparation for fixing the bogus DMA API usage,
      however, we need to ensure that the DMA API agrees about this, which
      necessitates deferring to the dma-coherent property in the device tree
      for the final say.
      
      As an added bonus, since systems exist where an external CTTW signal
      has been tied off incorrectly at integration, allowing DT to override
      it offers a neat workaround for coherency issues with such SMMUs.
      Signed-off-by: NRobin Murphy <robin.murphy@arm.com>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      bae2c2d4
  8. 30 6月, 2015 1 次提交
  9. 29 5月, 2015 2 次提交
  10. 12 5月, 2015 1 次提交
    • W
      iommu/arm-smmu: Fix sign-extension of upstream bus addresses at stage 1 · 5dc5616e
      Will Deacon 提交于
      Stage 1 translation is controlled by two sets of page tables (TTBR0 and
      TTBR1) which grow up and down from zero respectively in the ARMv8
      translation regime. For the SMMU, we only care about TTBR0 and, in the
      case of a 48-bit virtual space, we expect to map virtual addresses 0x0
      through to 0xffff_ffff_ffff.
      
      Given that some masters may be incapable of emitting virtual addresses
      targetting TTBR1 (e.g. because they sit on a 48-bit bus), the SMMU
      architecture allows bit 47 to be sign-extended, halving the virtual
      range of TTBR0 but allowing TTBR1 to be used. This is controlled by the
      SEP field in TTBCR2.
      
      The SMMU driver incorrectly enables this sign-extension feature, which
      causes problems when userspace addresses are programmed into a master
      device with the SMMU expecting to map the incoming transactions via
      TTBR0; if the top bit of address is set, we will instead get a
      translation fault since TTBR1 walks are disabled in the TTBCR.
      
      This patch fixes the issue by disabling sign-extension of a fixed
      virtual address bit and instead basing the behaviour on the upstream bus
      size: the incoming address is zero extended unless the upstream bus is
      only 49 bits wide, in which case bit 48 is used as the sign bit and is
      replicated to the upper bits.
      
      Cc: <stable@vger.kernel.org> # v4.0+
      Reported-by: NVarun Sethi <varun.sethi@freescale.com>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      5dc5616e
  11. 31 3月, 2015 1 次提交
  12. 27 3月, 2015 3 次提交
  13. 23 3月, 2015 1 次提交
  14. 04 2月, 2015 1 次提交
  15. 20 1月, 2015 1 次提交
    • M
      iommu/arm-smmu: add support for iova_to_phys through ATS1PR · 859a732e
      Mitchel Humpherys 提交于
      Currently, we provide the iommu_ops.iova_to_phys service by doing a
      table walk in software to translate IO virtual addresses to physical
      addresses. On SMMUs that support it, it can be useful to ask the SMMU
      itself to do the translation. This can be used to warm the TLBs for an
      SMMU. It can also be useful for testing and hardware validation.
      
      Since the address translation registers are optional on SMMUv2, only
      enable hardware translations when using SMMUv1 or when SMMU_IDR0.S1TS=1
      and SMMU_IDR0.ATOSNS=0, as described in the ARM SMMU v1-v2 spec.
      Signed-off-by: NMitchel Humpherys <mitchelh@codeaurora.org>
      [will: reworked on top of generic iopgtbl changes]
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      859a732e
  16. 19 1月, 2015 2 次提交
  17. 14 11月, 2014 4 次提交
  18. 04 11月, 2014 1 次提交
    • O
      iommu: Add iommu_map_sg() function · 315786eb
      Olav Haugan 提交于
      Mapping and unmapping are more often than not in the critical path.
      map_sg allows IOMMU driver implementations to optimize the process
      of mapping buffers into the IOMMU page tables.
      
      Instead of mapping a buffer one page at a time and requiring potentially
      expensive TLB operations for each page, this function allows the driver
      to map all pages in one go and defer TLB maintenance until after all
      pages have been mapped.
      
      Additionally, the mapping operation would be faster in general since
      clients does not have to keep calling map API over and over again for
      each physically contiguous chunk of memory that needs to be mapped to a
      virtually contiguous region.
      Signed-off-by: NOlav Haugan <ohaugan@codeaurora.org>
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      315786eb
  19. 20 10月, 2014 1 次提交
  20. 25 9月, 2014 2 次提交
  21. 22 9月, 2014 1 次提交
  22. 17 9月, 2014 2 次提交