[PATCH v5 12/12] iommu: Rename iommu-sva-lib.{c,h}

2022-05-01 Thread Lu Baolu
Rename iommu-sva-lib.c[h] to iommu-sva.c[h] as it contains all code for SVA implementation in iommu core. Signed-off-by: Lu Baolu --- drivers/iommu/{iommu-sva-lib.h => iommu-sva.h} | 0 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 2 +- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2

[PATCH v5 11/12] iommu: Per-domain I/O page fault handling

2022-05-01 Thread Lu Baolu
Tweak the I/O page fault handling framework to route the page faults to the domain and call the page fault handler retrieved from the domain. This makes the I/O page fault handling framework possible to serve more usage scenarios as long as they have an IOMMU domain and install a page fault

[PATCH v5 10/12] iommu: Prepare IOMMU domain for IOPF

2022-05-01 Thread Lu Baolu
This adds some mechanisms around the iommu_domain so that the I/O page fault handling framework could route a page fault to the domain and call the fault handler from it. Add pointers to the page fault handler and its private data in struct iommu_domain. The fault handler will be called with the

[PATCH v5 09/12] iommu: Remove SVA related callbacks from iommu ops

2022-05-01 Thread Lu Baolu
These ops'es have been replaced with the dev_attach/detach_pasid domain ops'es. There's no need for them anymore. Remove them to avoid dead code. Signed-off-by: Lu Baolu --- include/linux/intel-iommu.h | 4 -- include/linux/iommu.h | 8 ---

[PATCH v5 08/12] iommu/sva: Use attach/detach_pasid_dev in SVA interfaces

2022-05-01 Thread Lu Baolu
The existing iommu SVA interfaces are implemented by calling the SVA specific iommu ops provided by the IOMMU drivers. There's no need for any SVA specific ops in iommu_ops vector anymore as we can achieve this through the generic attach/detach_dev_pasid domain ops. This refactors the IOMMU SVA

[PATCH v5 07/12] arm-smmu-v3/sva: Add SVA domain support

2022-05-01 Thread Lu Baolu
Add support for SVA domain allocation and provide an SVA-specific iommu_domain_ops. Signed-off-by: Lu Baolu --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 14 +++ .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 42 +++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 21

[PATCH v5 05/12] iommu/vt-d: Remove SVM_FLAG_SUPERVISOR_MODE support

2022-05-01 Thread Lu Baolu
The current kernel DMA with PASID support is based on the SVA with a flag SVM_FLAG_SUPERVISOR_MODE. The IOMMU driver binds the kernel memory address space to a PASID of the device. The device driver programs the device with kernel virtual address (KVA) for DMA access. There have been security and

[PATCH v5 06/12] iommu/vt-d: Add SVA domain support

2022-05-01 Thread Lu Baolu
Add support for SVA domain allocation and provide an SVA-specific iommu_domain_ops. Signed-off-by: Lu Baolu --- include/linux/intel-iommu.h | 1 + drivers/iommu/intel/iommu.c | 10 ++ drivers/iommu/intel/svm.c | 37 + 3 files changed, 48

[PATCH v5 04/12] iommu/sva: Basic data structures for SVA

2022-05-01 Thread Lu Baolu
Use below data structures for SVA implementation in the IOMMU core: - struct iommu_sva_ioas Represent the I/O address space shared with an application CPU address space. This structure has a 1:1 relationship with an mm_struct. It grabs a "mm->mm_count" refcount during creation and drop it

[PATCH v5 03/12] iommu: Add attach/detach_dev_pasid domain ops

2022-05-01 Thread Lu Baolu
Attaching an IOMMU domain to a PASID of a device is a generic operation for modern IOMMU drivers which support PASID-granular DMA address translation. Currently visible usage scenarios include (but not limited): - SVA (Shared Virtual Address) - kernel DMA with PASID - hardware-assist mediated

[PATCH v5 01/12] dmaengine: idxd: Separate user and kernel pasid enabling

2022-05-01 Thread Lu Baolu
From: Dave Jiang The idxd driver always gated the pasid enabling under a single knob and this assumption is incorrect. The pasid used for kernel operation can be independently toggled and has no dependency on the user pasid (and vice versa). Split the two so they are independent "enabled" flags.

[PATCH v5 02/12] iommu: Add pasid_bits field in struct dev_iommu

2022-05-01 Thread Lu Baolu
Use this field to save the pasid/ssid bits that a device is able to support with its IOMMU hardware. It is a generic attribute of a device and lifting it into the per-device dev_iommu struct makes it possible to allocate a PASID for device without calls into the IOMMU drivers. Any iommu driver

[PATCH v5 00/12] iommu: SVA and IOPF refactoring

2022-05-01 Thread Lu Baolu
Hi folks, The former part of this series refactors the IOMMU SVA code by assigning an SVA type of iommu_domain to a shared virtual address and replacing sva_bind/unbind iommu ops with attach/detach_dev_pasid domain ops. The latter part changes the existing I/O page fault handling framework from

[PATCH v2] iommu: fix an incorrect NULL check on list iterator

2022-05-01 Thread Xiaomeng Tong
The bug is here: if (!iommu || iommu->dev->of_node != spec->np) { The list iterator value 'iommu' will *always* be set and non-NULL by list_for_each_entry(), so it is incorrect to assume that the iterator value will be NULL if the list is empty or no element is found (in fact, it will

[PATCH v2] iommu: fix an incorrect NULL check on list iterator

2022-05-01 Thread Xiaomeng Tong
The bug is here: if (!iommu || iommu->dev->of_node != spec->np) { The list iterator value 'iommu' will *always* be set and non-NULL by list_for_each_entry(), so it is incorrect to assume that the iterator value will be NULL if the list is empty or no element is found (in fact, it will

[PATCH 5/5] iommu/vt-d: Remove hard coding PGSNP bit in PASID entries

2022-05-01 Thread Lu Baolu
As enforce_cache_coherency has been introduced into the iommu_domain_ops, the kernel component which owns the iommu domain is able to opt-in its requirement for force snooping support. The iommu driver has no need to hard code the page snoop control bit in the PASID table entries anymore.

[PATCH 4/5] iommu/vt-d: Remove domain_update_iommu_snooping()

2022-05-01 Thread Lu Baolu
The IOMMU force snooping capability is not required to be consistent among all the IOMMUs anymore. Remove force snooping capability check in the IOMMU hot-add path and domain_update_iommu_snooping() becomes a dead code now. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 34

[PATCH 3/5] iommu/vt-d: Check domain force_snooping against attached devices

2022-05-01 Thread Lu Baolu
As domain->force_snooping only impacts the devices attached with the domain, there's no need to check against all IOMMU units. At the same time, for a brand new domain (hasn't been attached to any device), the force_snooping field could be set, but the attach_dev callback will return failure if it

[PATCH 1/5] iommu/vt-d: Block force-snoop domain attaching if no SC support

2022-05-01 Thread Lu Baolu
In the attach_dev callback of the default domain ops, if the domain has been set force_snooping, but the iommu hardware of the device does not support SC(Snoop Control) capability, the callback should block it and return a corresponding error code. Signed-off-by: Lu Baolu ---

[PATCH 2/5] iommu/vt-d: Set SNP bit only in second-level page table entries

2022-05-01 Thread Lu Baolu
The SNP bit is only valid for second-level PTEs. Setting this bit in the first-level PTEs has no functional impact because the Intel IOMMU always ignores the same bit in first-level PTEs. Anyway, let's check the page table type before setting SNP bit in PTEs to make the code more readable.

[PATCH 0/5] iommu/vt-d: Force snooping improvement

2022-05-01 Thread Lu Baolu
Hi folks, Previously, the IOMMU capability of enforcing cache coherency is queried through iommu_capable(IOMMU_CAP_CACHE_COHERENCY). This is a global capability, hence the IOMMU driver reports support for this capability only when all IOMMUs in the system has this support. Commit 6043257b1de06