1. 05 11月, 2019 7 次提交
  2. 01 10月, 2019 3 次提交
  3. 30 7月, 2019 5 次提交
  4. 24 7月, 2019 2 次提交
    • W
      iommu/io-pgtable: Rename iommu_gather_ops to iommu_flush_ops · 298f7889
      Will Deacon 提交于
      In preparation for TLB flush gathering in the IOMMU API, rename the
      iommu_gather_ops structure in io-pgtable to iommu_flush_ops, which
      better describes its purpose and avoids the potential for confusion
      between different levels of the API.
      
      $ find linux/ -type f -name '*.[ch]' | xargs sed -i 's/gather_ops/flush_ops/g'
      Signed-off-by: NWill Deacon <will@kernel.org>
      298f7889
    • W
      iommu/io-pgtable-arm: Remove redundant call to io_pgtable_tlb_sync() · f71da467
      Will Deacon 提交于
      Commit b6b65ca2 ("iommu/io-pgtable-arm: Add support for non-strict
      mode") added an unconditional call to io_pgtable_tlb_sync() immediately
      after the case where we replace a block entry with a table entry during
      an unmap() call. This is redundant, since the IOMMU API will call
      iommu_tlb_sync() on this path and the patch in question mentions this:
      
       | To save having to reason about it too much, make sure the invalidation
       | in arm_lpae_split_blk_unmap() just performs its own unconditional sync
       | to minimise the window in which we're technically violating the break-
       | before-make requirement on a live mapping. This might work out redundant
       | with an outer-level sync for strict unmaps, but we'll never be splitting
       | blocks on a DMA fastpath anyway.
      
      However, this sync gets in the way of deferred TLB invalidation for leaf
      entries and is at best a questionable, unproven hack. Remove it.
      Signed-off-by: NWill Deacon <will@kernel.org>
      f71da467
  5. 25 6月, 2019 2 次提交
  6. 19 6月, 2019 2 次提交
    • T
      treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 234 · caab277b
      Thomas Gleixner 提交于
      Based on 1 normalized pattern(s):
      
        this program is free software you can redistribute it and or modify
        it under the terms of the gnu general public license version 2 as
        published by the free software foundation this program is
        distributed in the hope that it will be useful but without any
        warranty without even the implied warranty of merchantability or
        fitness for a particular purpose see the gnu general public license
        for more details you should have received a copy of the gnu general
        public license along with this program if not see http www gnu org
        licenses
      
      extracted by the scancode license scanner the SPDX license identifier
      
        GPL-2.0-only
      
      has been chosen to replace the boilerplate/reference in 503 file(s).
      Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
      Reviewed-by: NAlexios Zavras <alexios.zavras@intel.com>
      Reviewed-by: NAllison Randal <allison@lohutok.net>
      Reviewed-by: NEnrico Weigelt <info@metux.net>
      Cc: linux-spdx@vger.kernel.org
      Link: https://lkml.kernel.org/r/20190602204653.811534538@linutronix.deSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      caab277b
    • V
      iommu/io-pgtable-arm: Add support to use system cache · 90ec7a76
      Vivek Gautam 提交于
      Few Qualcomm platforms such as, sdm845 have an additional outer
      cache called as System cache, aka. Last level cache (LLC) that
      allows non-coherent devices to upgrade to using caching.
      This cache sits right before the DDR, and is tightly coupled
      with the memory controller. The clients using this cache request
      their slices from this system cache, make it active, and can then
      start using it.
      
      There is a fundamental assumption that non-coherent devices can't
      access caches. This change adds an exception where they *can* use
      some level of cache despite still being non-coherent overall.
      The coherent devices that use cacheable memory, and CPU make use of
      this system cache by default.
      
      Looking at memory types, we have following -
      a) Normal uncached :- MAIR 0x44, inner non-cacheable,
                            outer non-cacheable;
      b) Normal cached :-   MAIR 0xff, inner read write-back non-transient,
                            outer read write-back non-transient;
                            attribute setting for coherenet I/O devices.
      and, for non-coherent i/o devices that can allocate in system cache
      another type gets added -
      c) Normal sys-cached :- MAIR 0xf4, inner non-cacheable,
                              outer read write-back non-transient
      
      Coherent I/O devices use system cache by marking the memory as
      normal cached.
      Non-coherent I/O devices should mark the memory as normal
      sys-cached in page tables to use system cache.
      Acked-by: NRobin Murphy <robin.murphy@arm.com>
      Signed-off-by: NVivek Gautam <vivek.gautam@codeaurora.org>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      90ec7a76
  7. 13 4月, 2019 1 次提交
  8. 11 2月, 2019 1 次提交
    • R
      iommu: Allow io-pgtable to be used outside of drivers/iommu/ · b77cf11f
      Rob Herring 提交于
      Move io-pgtable.h to include/linux/ and export alloc_io_pgtable_ops
      and free_io_pgtable_ops. This enables drivers outside drivers/iommu/ to
      use the page table library. Specifically, some ARM Mali GPUs use the
      ARM page table formats.
      
      Cc: Will Deacon <will.deacon@arm.com>
      Cc: Robin Murphy <robin.murphy@arm.com>
      Cc: Joerg Roedel <joro@8bytes.org>
      Cc: Matthias Brugger <matthias.bgg@gmail.com>
      Cc: Rob Clark <robdclark@gmail.com>
      Cc: linux-arm-kernel@lists.infradead.org
      Cc: iommu@lists.linux-foundation.org
      Cc: linux-mediatek@lists.infradead.org
      Cc: linux-arm-msm@vger.kernel.org
      Signed-off-by: NRob Herring <robh@kernel.org>
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      b77cf11f
  9. 01 10月, 2018 2 次提交
    • Z
      iommu/io-pgtable-arm: Add support for non-strict mode · b6b65ca2
      Zhen Lei 提交于
      Non-strict mode is simply a case of skipping 'regular' leaf TLBIs, since
      the sync is already factored out into ops->iotlb_sync at the core API
      level. Non-leaf invalidations where we change the page table structure
      itself still have to be issued synchronously in order to maintain walk
      caches correctly.
      
      To save having to reason about it too much, make sure the invalidation
      in arm_lpae_split_blk_unmap() just performs its own unconditional sync
      to minimise the window in which we're technically violating the break-
      before-make requirement on a live mapping. This might work out redundant
      with an outer-level sync for strict unmaps, but we'll never be splitting
      blocks on a DMA fastpath anyway.
      Signed-off-by: NZhen Lei <thunder.leizhen@huawei.com>
      [rm: tweak comment, commit message, split_blk_unmap logic and barriers]
      Signed-off-by: NRobin Murphy <robin.murphy@arm.com>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      b6b65ca2
    • R
      iommu/io-pgtable-arm: Fix race handling in split_blk_unmap() · 85c7a0f1
      Robin Murphy 提交于
      In removing the pagetable-wide lock, we gained the possibility of the
      vanishingly unlikely case where we have a race between two concurrent
      unmappers splitting the same block entry. The logic to handle this is
      fairly straightforward - whoever loses the race frees their partial
      next-level table and instead dereferences the winner's newly-installed
      entry in order to fall back to a regular unmap, which intentionally
      echoes the pre-existing case of recursively splitting a 1GB block down
      to 4KB pages by installing a full table of 2MB blocks first.
      
      Unfortunately, the chump who implemented that logic failed to update the
      condition check for that fallback, meaning that if said race occurs at
      the last level (where the loser's unmap_idx is valid) then the unmap
      won't actually happen. Fix that to properly account for both the race
      and recursive cases.
      
      Fixes: 2c3d273e ("iommu/io-pgtable-arm: Support lockless operation")
      Signed-off-by: NRobin Murphy <robin.murphy@arm.com>
      [will: re-jig control flow to avoid duplicate cmpxchg test]
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      85c7a0f1
  10. 26 7月, 2018 1 次提交
  11. 29 5月, 2018 1 次提交
    • R
      iommu/io-pgtable-arm: Make allocations NUMA-aware · 4b123757
      Robin Murphy 提交于
      We would generally expect pagetables to be read by the IOMMU more than
      written by the CPU, so in NUMA systems it makes sense to locate them
      close to the former and avoid cross-node pagetable walks if at all
      possible. As it turns out, we already have a handle on the IOMMU device
      for the sake of coherency management, so it's trivial to grab the
      appropriate NUMA node when allocating new pagetable pages.
      
      Note that we drop the semantics of alloc_pages_exact(), but that's fine
      since they have never been necessary: the only time we're allocating
      more than one page is for stage 2 top-level concatenation, but since
      that is based on the number of IPA bits, the size is always some exact
      power of two anyway.
      Acked-by: NWill Deacon <will.deacon@arm.com>
      Signed-off-by: NRobin Murphy <robin.murphy@arm.com>
      Signed-off-by: NJoerg Roedel <jroedel@suse.de>
      4b123757
  12. 03 5月, 2018 1 次提交
  13. 29 3月, 2018 1 次提交
  14. 27 3月, 2018 1 次提交
  15. 14 2月, 2018 1 次提交
  16. 02 10月, 2017 1 次提交
  17. 20 7月, 2017 1 次提交
  18. 24 6月, 2017 4 次提交
    • W
      iommu/io-pgtable-arm: Use dma_wmb() instead of wmb() when publishing table · 77f34458
      Will Deacon 提交于
      When writing a new table entry, we must ensure that the contents of the
      table is made visible to the SMMU page table walker before the updated
      table entry itself.
      
      This is currently achieved using wmb(), which expands to an expensive and
      unnecessary DSB instruction. Ideally, we'd just use cmpxchg64_release when
      writing the table entry, but this doesn't have memory ordering semantics
      on !SMP systems.
      
      Instead, use dma_wmb(), which emits DMB OSHST. Strictly speaking, this
      does more than we require (since it targets the outer-shareable domain),
      but it's likely to be significantly faster than the DSB approach.
      Reported-by: NLinu Cherian <linu.cherian@cavium.com>
      Suggested-by: NRobin Murphy <robin.murphy@arm.com>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      77f34458
    • R
      iommu/io-pgtable-arm: Support lockless operation · 2c3d273e
      Robin Murphy 提交于
      For parallel I/O with multiple concurrent threads servicing the same
      device (or devices, if several share a domain), serialising page table
      updates becomes a massive bottleneck. On reflection, though, we don't
      strictly need to do that - for valid IOMMU API usage, there are in fact
      only two races that we need to guard against: multiple map requests for
      different blocks within the same region, when the intermediate-level
      table for that region does not yet exist; and multiple unmaps of
      different parts of the same block entry. Both of those are fairly easily
      solved by using a cmpxchg to install the new table, such that if we then
      find that someone else's table got there first, we can simply free ours
      and continue.
      
      Make the requisite changes such that we can withstand being called
      without the caller maintaining a lock. In theory, this opens up a few
      corners in which wildly misbehaving callers making nonsensical
      overlapping requests might lead to crashes instead of just unpredictable
      results, but correct code really does not deserve to pay a significant
      performance cost for the sake of masking bugs in theoretical broken code.
      Signed-off-by: NRobin Murphy <robin.murphy@arm.com>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      2c3d273e
    • R
      iommu/io-pgtable: Introduce explicit coherency · 81b3c252
      Robin Murphy 提交于
      Once we remove the serialising spinlock, a potential race opens up for
      non-coherent IOMMUs whereby a caller of .map() can be sure that cache
      maintenance has been performed on their new PTE, but will have no
      guarantee that such maintenance for table entries above it has actually
      completed (e.g. if another CPU took an interrupt immediately after
      writing the table entry, but before initiating the DMA sync).
      
      Handling this race safely will add some potentially non-trivial overhead
      to installing a table entry, which we would much rather avoid on
      coherent systems where it will be unnecessary, and where we are stirivng
      to minimise latency by removing the locking in the first place.
      
      To that end, let's introduce an explicit notion of cache-coherency to
      io-pgtable, such that we will be able to avoid penalising IOMMUs which
      know enough to know when they are coherent.
      Signed-off-by: NRobin Murphy <robin.murphy@arm.com>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      81b3c252
    • R
      iommu/io-pgtable-arm: Improve split_blk_unmap · fb3a9579
      Robin Murphy 提交于
      The current split_blk_unmap implementation suffers from some inscrutable
      pointer trickery for creating the tables to replace the block entry, but
      more than that it also suffers from hideous inefficiency. For example,
      the most pathological case of unmapping a level 3 page from a level 1
      block will allocate 513 lower-level tables to remap the entire block at
      page granularity, when only 2 are actually needed (the rest can be
      covered by level 2 block entries).
      
      Also, we would like to be able to relax the spinlock requirement in
      future, for which the roll-back-and-try-again logic for race resolution
      would be pretty hideous under the current paradigm.
      
      Both issues can be resolved most neatly by turning things sideways:
      instead of repeatedly recursing into __arm_lpae_map() map to build up an
      entire new sub-table depth-first, we can directly replace the block
      entry with a next-level table of block/page entries, then repeat by
      unmapping at the next level if necessary. With a little refactoring of
      some helper functions, the code ends up not much bigger than before, but
      considerably easier to follow and to adapt in future.
      Signed-off-by: NRobin Murphy <robin.murphy@arm.com>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      fb3a9579
  19. 06 4月, 2017 1 次提交
    • R
      iommu/io-pgtable-arm: Avoid shift overflow in block size · 022f4e4f
      Robin Murphy 提交于
      The recursive nature of __arm_lpae_{map,unmap}() means that
      ARM_LPAE_BLOCK_SIZE() is evaluated for every level, including those
      where block mappings aren't possible. This in itself is harmless enough,
      as we will only ever be called with valid sizes from the pgsize_bitmap,
      and thus always recurse down past any imaginary block sizes. The only
      problem is that most of those imaginary sizes overflow the type used for
      the calculation, and thus trigger warnings under UBsan:
      
      [   63.020939] ================================================================================
      [   63.021284] UBSAN: Undefined behaviour in drivers/iommu/io-pgtable-arm.c:312:22
      [   63.021602] shift exponent 39 is too large for 32-bit type 'int'
      [   63.021909] CPU: 0 PID: 1119 Comm: lkvm Not tainted 4.7.0-rc3+ #819
      [   63.022163] Hardware name: FVP Base (DT)
      [   63.022345] Call trace:
      [   63.022629] [<ffffff900808f258>] dump_backtrace+0x0/0x3a8
      [   63.022975] [<ffffff900808f614>] show_stack+0x14/0x20
      [   63.023294] [<ffffff90086bc9dc>] dump_stack+0x104/0x148
      [   63.023609] [<ffffff9008713ce8>] ubsan_epilogue+0x18/0x68
      [   63.023956] [<ffffff9008714410>] __ubsan_handle_shift_out_of_bounds+0x18c/0x1bc
      [   63.024365] [<ffffff900890fcb0>] __arm_lpae_map+0x720/0xae0
      [   63.024732] [<ffffff9008910170>] arm_lpae_map+0x100/0x190
      [   63.025049] [<ffffff90089183d8>] arm_smmu_map+0x78/0xc8
      [   63.025390] [<ffffff9008906c18>] iommu_map+0x130/0x230
      [   63.025763] [<ffffff9008bf7564>] vfio_iommu_type1_attach_group+0x4bc/0xa00
      [   63.026156] [<ffffff9008bf3c78>] vfio_fops_unl_ioctl+0x320/0x580
      [   63.026515] [<ffffff9008377420>] do_vfs_ioctl+0x140/0xd28
      [   63.026858] [<ffffff9008378094>] SyS_ioctl+0x8c/0xa0
      [   63.027179] [<ffffff9008086e70>] el0_svc_naked+0x24/0x28
      [   63.027412] ================================================================================
      
      Perform the shift in a 64-bit type to prevent the theoretical overflow
      and keep the peace. As it turns out, this generates identical code for
      32-bit ARM, and marginally shorter AArch64 code, so it's good all round.
      Signed-off-by: NRobin Murphy <robin.murphy@arm.com>
      Signed-off-by: NWill Deacon <will.deacon@arm.com>
      022f4e4f
  20. 11 3月, 2017 1 次提交
  21. 19 1月, 2017 1 次提交