• J
    iommu/sva: Manage process address spaces · 59e55d73
    Jean-Philippe Brucker 提交于
    hulk inclusion
    category: feature
    bugzilla: 14369
    CVE: NA
    -------------------
    
    Allocate IOMMU mm structures and binding them to devices. Four operations
    are added to IOMMU drivers:
    
    * mm_alloc(): to create an io_mm structure and perform architecture-
      specific operations required to grab the process (for instance on ARM,
      pin down the CPU ASID so that the process doesn't get assigned a new
      ASID on rollover).
    
      There is a single valid io_mm structure per Linux mm. Future extensions
      may also use io_mm for kernel-managed address spaces, populated with
      map()/unmap() calls instead of bound to process address spaces. This
      patch focuses on "shared" io_mm.
    
    * mm_attach(): attach an mm to a device. The IOMMU driver checks that the
      device is capable of sharing an address space, and writes the PASID
      table entry to install the pgd.
    
      Some IOMMU drivers will have a single PASID table per domain, for
      convenience. Other can implement it differently but to help these
      drivers, mm_attach and mm_detach take 'attach_domain' and
      'detach_domain' parameters, that tell whether they need to set and clear
      the PASID entry or only send the required TLB invalidations.
    
    * mm_detach(): detach an mm from a device. The IOMMU driver removes the
      PASID table entry and invalidates the IOTLBs.
    
    * mm_free(): free a structure allocated by mm_alloc(), and let arch
      release the process.
    
    mm_attach and mm_detach operations are serialized with a spinlock. When
    trying to optimize this code, we should at least prevent concurrent
    attach()/detach() on the same domain (so multi-level PASID table code can
    allocate tables lazily). mm_alloc() can sleep, but mm_free must not
    (because we'll have to call it from call_srcu later on).
    
    At the moment we use an IDR for allocating PASIDs and retrieving contexts.
    We also use a single spinlock. These can be refined and optimized later (a
    custom allocator will be needed for top-down PASID allocation).
    
    Keeping track of address spaces requires the use of MMU notifiers.
    Handling process exit with regard to unbind() is tricky, so it is left for
    another patch and we explicitly fail mm_alloc() for the moment.
    Signed-off-by: NJean-Philippe Brucker <jean-philippe.brucker@arm.com>
    Signed-off-by: NFang Lijun <fanglijun3@huawei.com>
    Reviewed-by: NHanjun Guo <guohanjun@huawei.com>
    Reviewed-by: NZhen Lei <thunder.leizhen@huawei.com>
    Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
    59e55d73
iommu.c 61.6 KB