• S
    iommu: Add support to change default domain of an iommu group · 08a27c1c
    Sai Praneeth Prakhya 提交于
    Presently, the default domain of an iommu group is allocated during boot
    time and it cannot be changed later. So, the device would typically be
    either in identity (also known as pass_through) mode or the device would be
    in DMA mode as long as the machine is up and running. There is no way to
    change the default domain type dynamically i.e. after booting, a device
    cannot switch between identity mode and DMA mode.
    
    But, assume a use case wherein the user trusts the device and believes that
    the OS is secure enough and hence wants *only* this device to bypass IOMMU
    (so that it could be high performing) whereas all the other devices to go
    through IOMMU (so that the system is protected). Presently, this use case
    is not supported. It will be helpful if there is some way to change the
    default domain of an iommu group dynamically. Hence, add such support.
    
    A privileged user could request the kernel to change the default domain
    type of a iommu group by writing to
    "/sys/kernel/iommu_groups/<grp_id>/type" file. Presently, only three values
    are supported
    1. identity: all the DMA transactions from the device in this group are
                 *not* translated by the iommu
    2. DMA: all the DMA transactions from the device in this group are
            translated by the iommu
    3. auto: change to the type the device was booted with
    
    Note:
    1. Default domain of an iommu group with two or more devices cannot be
       changed.
    2. The device in the iommu group shouldn't be bound to any driver.
    3. The device shouldn't be assigned to user for direct access.
    4. The change request will fail if any device in the group has a mandatory
       default domain type and the requested one conflicts with that.
    
    Please see "Documentation/ABI/testing/sysfs-kernel-iommu_groups" for more
    information.
    Signed-off-by: NSai Praneeth Prakhya <sai.praneeth.prakhya@intel.com>
    Signed-off-by: NLu Baolu <baolu.lu@linux.intel.com>
    Cc: Christoph Hellwig <hch@lst.de>
    Cc: Joerg Roedel <joro@8bytes.org>
    Cc: Ashok Raj <ashok.raj@intel.com>
    Cc: Will Deacon <will.deacon@arm.com>
    Cc: Sohil Mehta <sohil.mehta@intel.com>
    Cc: Robin Murphy <robin.murphy@arm.com>
    Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
    Link: https://lore.kernel.org/r/20201124130604.2912899-3-baolu.lu@linux.intel.comSigned-off-by: NWill Deacon <will@kernel.org>
    08a27c1c
iommu.c 81.2 KB