[PATCH v4 11/11] iommu/vt-d: Convert global spinlock into per domain lock

2022-07-05 Thread Lu Baolu
tracking lists are never accessed in any interrupt context, there is no need to disable interrupts while spinning. Replace irqsave variant with spinlock calls. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian --- drivers/iommu/intel/iommu.h | 1 + drivers/iommu/intel/iommu.c | 42

[PATCH v4 10/11] iommu/vt-d: Use device_domain_lock accurately

2022-07-05 Thread Lu Baolu
The device_domain_lock is used to protect the device tracking list of a domain. Remove unnecessary spin_lock/unlock()'s and move the necessary ones around the list access. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian --- drivers/iommu/intel/iommu.c | 57

[PATCH v4 09/11] iommu/vt-d: Fold __dmar_remove_one_dev_info() into its caller

2022-07-05 Thread Lu Baolu
Fold __dmar_remove_one_dev_info() into dmar_remove_one_dev_info() which is its only caller. Make the spin lock critical range only cover the device list change code and remove some unnecessary checks. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian --- drivers/iommu/intel/iommu.c | 31

[PATCH v4 07/11] iommu/vt-d: Acquiring lock in pasid manipulation helpers

2022-07-05 Thread Lu Baolu
The iommu->lock is used to protect the per-IOMMU pasid directory table and pasid table. Move the spinlock acquisition/release into the helpers to make the code self-contained. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian --- drivers/iommu/intel/iommu.c | 2 - drivers/iommu/intel/pasi

[PATCH v4 08/11] iommu/vt-d: Check device list of domain in domain free path

2022-07-05 Thread Lu Baolu
When the IOMMU domain is about to be freed, it should not be set on any device. Instead of silently dealing with some bug cases, it's better to trigger a warning to report and fix any potential bugs at the first time. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe Reviewed-by: Kevin Tian

[PATCH v4 05/11] iommu/vt-d: Replace spin_lock_irqsave() with spin_lock()

2022-07-05 Thread Lu Baolu
ens on the device_domain_lock side, which protects the device domain attachment information. This replaces spin_lock/unlock_irqsave/irqrestore() calls with the normal spin_lock/unlock(). Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian --- drivers/iommu/intel/debugfs.c | 6 ++-- drivers/iommu/intel/iommu.c |

[PATCH v4 06/11] iommu/vt-d: Acquiring lock in domain ID allocation helpers

2022-07-05 Thread Lu Baolu
The iommu->lock is used to protect the per-IOMMU domain ID resource. Moving the lock into the ID alloc/free helpers makes the code more compact. At the same time, the device_domain_lock is irrelevant to the domain ID resource, remove its assertion as well. Signed-off-by: Lu Baolu Revie

[PATCH v4 04/11] iommu/vt-d: Unnecessary spinlock for root table alloc and free

2022-07-05 Thread Lu Baolu
The IOMMU root table is allocated and freed in the IOMMU initialization code in static boot or hot-remove paths. There's no need for a spinlock. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian --- drivers/iommu/intel/iommu.c | 18 +- 1 file changed, 5 insertions(+), 13

[PATCH v4 02/11] iommu/vt-d: Remove clearing translation data in disable_dmar_iommu()

2022-07-05 Thread Lu Baolu
to repeat it in IOMMU hot-remove path either. This removes the unnecessary code and only leaves a check. Signed-off-by: Lu Baolu --- drivers/iommu/intel/pasid.h | 1 + drivers/iommu/intel/iommu.c | 21 +++-- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/drivers

[PATCH v4 03/11] iommu/vt-d: Use pci_get_domain_bus_and_slot() in pgtable_walk()

2022-07-05 Thread Lu Baolu
Use pci_get_domain_bus_and_slot() instead of searching the global list to retrieve the pci device pointer. This also removes the global device_domain_list as there isn't any consumer anymore. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe Reviewed-by: Kevin Tian --- drivers/iommu/intel

[PATCH v4 00/11] iommu/vt-d: Optimize the use of locks

2022-07-05 Thread Lu Baolu
several comments received during v1 review. v1: - https://lore.kernel.org/linux-iommu/20220527063019.3112905-1-baolu...@linux.intel.com/ - Initial post. Lu Baolu (11): iommu/vt-d: debugfs: Remove device_domain_lock usage iommu/vt-d: Remove clearing translation data in disable_dmar_iommu

[PATCH v4 01/11] iommu/vt-d: debugfs: Remove device_domain_lock usage

2022-07-05 Thread Lu Baolu
of iommu.c by replacing it with the group mutex lock. Using the group mutex lock is cleaner and more compatible to following cleanups. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian --- drivers/iommu/intel/iommu.h | 1 - drivers/iommu/intel/debugfs.c | 43 +-- drivers

[PATCH v2 6/6] iommu/vt-d: Make DMAR_UNITS_SUPPORTED default 1024

2022-07-01 Thread Lu Baolu
; and the system fails to boot properly. To support up to 64 sockets with 10 DMAR units each (640), make the value of DMAR_UNITS_SUPPORTED default 1024. Signed-off-by: Steve Wahl Link: https://lore.kernel.org/linux-iommu/20220615183650.32075-1-steve.w...@hpe.com/ Signed-off-by: Lu Baolu Reviewe

[PATCH v2 5/6] iommu/vt-d: Remove global g_iommus array

2022-07-01 Thread Lu Baolu
The g_iommus and g_num_of_iommus is not used anywhere. Remove them to avoid dead code. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian --- drivers/iommu/intel/iommu.c | 44 - 1 file changed, 44 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers

[PATCH v2 4/6] iommu/vt-d: Remove unnecessary check in intel_iommu_add()

2022-07-01 Thread Lu Baolu
-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 70408c234f5b..d79c48c5fc8c 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -3463,9 +3463,6 @@ static int

[PATCH v2 3/6] iommu/vt-d: Refactor iommu information of each domain

2022-07-01 Thread Lu Baolu
these static arrays by replacing them with an xarray and consuming memory on demand. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.h | 29 ++--- drivers/iommu/intel/iommu.c | 124 +--- drivers/iommu/intel/pasid.c | 2 +- drivers/iommu/intel/svm.c | 2 +- 4

[PATCH v2 2/6] iommu/vt-d: Use IDA interface to manage iommu sequence id

2022-07-01 Thread Lu Baolu
Switch dmar unit sequence id allocation and release from bitmap to IDA interface. Signed-off-by: Lu Baolu --- drivers/iommu/intel/dmar.c | 35 --- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel

[PATCH v2 1/6] iommu/vt-d: Remove unused domain_get_iommu()

2022-07-01 Thread Lu Baolu
It is not used anywhere. Remove it to avoid dead code. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian --- drivers/iommu/intel/iommu.h | 1 - drivers/iommu/intel/iommu.c | 18 -- 2 files changed, 19 deletions(-) diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel

[PATCH v2 0/6] iommu/vt-d: Reset DMAR_UNITS_SUPPORTED

2022-07-01 Thread Lu Baolu
() with xa_cmpxchg(). - Set domain->nid to NUMA_NO_NODE when domain is detached from an iommu. - Avoid adding a new VTD_FLAG_IOMMU_PROBED flag. Remove the duplicate check directly. v1: - https://lore.kernel.org/lkml/20220625125204.2199437-1-baolu...@linux.intel.com/ - Initial post. Lu Baolu

Re: [PATCH v1 3/6] iommu/vt-d: Refactor iommu information of each domain

2022-06-30 Thread Lu Baolu
On 6/30/22 4:28 PM, Tian, Kevin wrote: From: Lu Baolu Sent: Saturday, June 25, 2022 8:52 PM +struct iommu_domain_info { + struct intel_iommu *iommu; + unsigned int refcnt; + u16 did; +}; + struct dmar_domain { int nid;/* node id

Re: [PATCH v1 2/6] iommu/vt-d: Use IDA interface to manage iommu sequence id

2022-06-30 Thread Lu Baolu
On 6/30/22 4:21 PM, Tian, Kevin wrote: From: Lu Baolu Sent: Saturday, June 25, 2022 8:52 PM @@ -1062,11 +1040,14 @@ static int alloc_iommu(struct dmar_drhd_unit *drhd) if (!iommu) return -ENOMEM; - if (dmar_alloc_seq_id(iommu) < 0) { + iommu->

[PATCH v3 11/11] iommu/vt-d: Convert global spinlock into per domain lock

2022-06-29 Thread Lu Baolu
tracking lists are never accessed in any interrupt context, there is no need to disable interrupts while spinning. Replace irqsave variant with spinlock calls. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.h | 1 + drivers/iommu/intel/iommu.c | 50 - 2

[PATCH v3 10/11] iommu/vt-d: Use device_domain_lock accurately

2022-06-29 Thread Lu Baolu
The device_domain_lock is used to protect the device tracking list of a domain. Remove unnecessary spin_lock/unlock()'s and move the necessary ones around the list access. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 61 ++--- 1 file changed, 23

[PATCH v3 09/11] iommu/vt-d: Fold __dmar_remove_one_dev_info() into its caller

2022-06-29 Thread Lu Baolu
Fold __dmar_remove_one_dev_info() into dmar_remove_one_dev_info() which is its only caller. Make the spin lock critical range only cover the device list change code and remove some unnecessary checks. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 33

[PATCH v3 08/11] iommu/vt-d: Check device list of domain in domain free path

2022-06-29 Thread Lu Baolu
When the IOMMU domain is about to be freed, it should not be set on any device. Instead of silently dealing with some bug cases, it's better to trigger a warning to report and fix any potential bugs at the first time. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe Reviewed-by: Kevin Tian

[PATCH v3 07/11] iommu/vt-d: Acquiring lock in pasid manipulation helpers

2022-06-29 Thread Lu Baolu
The iommu->lock is used to protect the per-IOMMU pasid directory table and pasid table. Move the spinlock acquisition/release into the helpers to make the code self-contained. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian --- drivers/iommu/intel/iommu.c | 2 - drivers/iommu/intel/pasi

[PATCH v3 06/11] iommu/vt-d: Acquiring lock in domain ID allocation helpers

2022-06-29 Thread Lu Baolu
The iommu->lock is used to protect the per-IOMMU domain ID resource. Moving the lock into the ID alloc/free helpers makes the code more compact. At the same time, the device_domain_lock is irrelevant to the domain ID resource, remove its assertion as well. Signed-off-by: Lu Baolu --- driv

[PATCH v3 05/11] iommu/vt-d: Replace spin_lock_irqsave() with spin_lock()

2022-06-29 Thread Lu Baolu
The iommu->lock is used to protect changes in root/context/pasid tables and domain ID allocation. There's no use case to change these resources in any interrupt context. Therefore, it's unnecessary to disable the interrupts when the spinlock is held. Signed-off-by: Lu Baolu Reviewed-by: Ke

[PATCH v3 04/11] iommu/vt-d: Unnecessary spinlock for root table alloc and free

2022-06-29 Thread Lu Baolu
The IOMMU root table is allocated and freed in the IOMMU initialization code in static boot or hot-remove paths. There's no need for a spinlock. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian --- drivers/iommu/intel/iommu.c | 18 +- 1 file changed, 5 insertions(+), 13

[PATCH v3 02/11] iommu/vt-d: Remove clearing translation data in disable_dmar_iommu()

2022-06-29 Thread Lu Baolu
to repeat it in IOMMU hot-remove path either. This removes the unnecessary code and only leaves a check. Signed-off-by: Lu Baolu --- drivers/iommu/intel/pasid.h | 1 + drivers/iommu/intel/iommu.c | 21 +++-- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/drivers

[PATCH v3 03/11] iommu/vt-d: Use pci_get_domain_bus_and_slot() in pgtable_walk()

2022-06-29 Thread Lu Baolu
Use pci_get_domain_bus_and_slot() instead of searching the global list to retrieve the pci device pointer. This also removes the global device_domain_list as there isn't any consumer anymore. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe Reviewed-by: Kevin Tian --- drivers/iommu/intel

[PATCH v3 01/11] iommu/vt-d: debugfs: Remove device_domain_lock usage

2022-06-29 Thread Lu Baolu
of iommu.c by replacing it with the group mutex lock. Using the group mutex lock is cleaner and more compatible to following cleanups. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.h | 1 - drivers/iommu/intel/debugfs.c | 43 +-- drivers/iommu/intel/iommu.c

[PATCH v3 00/11] iommu/vt-d: Optimize the use of locks

2022-06-29 Thread Lu Baolu
...@linux.intel.com/ - Drop the conversion from spinlock to mutex and make this series cleanup purpose only. - Address several comments received during v1 review. v1: - https://lore.kernel.org/linux-iommu/20220527063019.3112905-1-baolu...@linux.intel.com/ - Initial post. Lu Baolu (11

[PATCH 1/1] iommu/vt-d: Fix RID2PASID setup/teardown failure

2022-06-25 Thread Lu Baolu
reasonable to remove this part of immature code to make the driver feasible and stable. Fixes: ef848b7e5a6a0 ("iommu/vt-d: Setup pasid entry for RID2PASID support") Reported-by: Chenyi Qiang Reported-by: Ethan Zhao Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian Reviewed-by:

[PATCH 0/1] iommu/vt-d: Fixes for v5.19-rc4

2022-06-25 Thread Lu Baolu
Hi Joerg, One fix is queued for v5.19. It aims to fix: - RID2PASID setup/teardown failures for pci alias devices Please consider it for the iommu/fix branch. Best regards, Lu Baolu Lu Baolu (1): iommu/vt-d: Fix RID2PASID setup/teardown failure include/linux/intel-iommu.h | 3 -- drivers

[PATCH v1 6/6] iommu/vt-d: Make DMAR_UNITS_SUPPORTED default 1024

2022-06-25 Thread Lu Baolu
; and the system fails to boot properly. To support up to 64 sockets with 10 DMAR units each (640), make the value of DMAR_UNITS_SUPPORTED default 1024. Signed-off-by: Steve Wahl Signed-off-by: Lu Baolu --- include/linux/dmar.h | 6 +- 1 file changed, 1 insertion(+), 5 deletions(-) diff

[PATCH v1 5/6] iommu/vt-d: Remove global g_iommus array

2022-06-25 Thread Lu Baolu
The g_iommus is not used anywhere. Remove it to avoid dead code. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 42 - 1 file changed, 42 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index f6d7055cffd7

[PATCH v1 4/6] iommu/vt-d: Add VTD_FLAG_IOMMU_PROBED flag

2022-06-25 Thread Lu Baolu
In the IOMMU hot-add path, there's a need to check whether an IOMMU has been probed. Instead of checking the IOMMU pointer in the global list, it's better to allocate a flag bit in iommu->flags for this purpose. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.h | 1 + drivers/iommu/in

[PATCH v1 3/6] iommu/vt-d: Refactor iommu information of each domain

2022-06-25 Thread Lu Baolu
these static arrays by replacing them with an xarray and consuming memory on demand. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.h | 27 +--- drivers/iommu/intel/iommu.c | 123 drivers/iommu/intel/pasid.c | 2 +- drivers/iommu/intel/svm.c | 2 +- 4

[PATCH v1 1/6] iommu/vt-d: Remove unused domain_get_iommu()

2022-06-25 Thread Lu Baolu
It is not used anywhere. Remove it to avoid dead code. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.h | 1 - drivers/iommu/intel/iommu.c | 18 -- 2 files changed, 19 deletions(-) diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index df64d3d9c49a

[PATCH v1 2/6] iommu/vt-d: Use IDA interface to manage iommu sequence id

2022-06-25 Thread Lu Baolu
Switch dmar unit sequence id allocation and release from bitmap to IDA interface. Signed-off-by: Lu Baolu --- drivers/iommu/intel/dmar.c | 33 +++-- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c

[PATCH v1 0/6] iommu/vt-d: Reset DMAR_UNITS_SUPPORTED

2022-06-25 Thread Lu Baolu
regards, baolu Lu Baolu (6): iommu/vt-d: Remove unused domain_get_iommu() iommu/vt-d: Use IDA interface to manage iommu sequence id iommu/vt-d: Refactor iommu information of each domain iommu/vt-d: Add VTD_FLAG_IOMMU_PROBED flag iommu/vt-d: Remove global g_iommus array iommu/vt-d: Make

[PATCH v3 1/1] iommu/vt-d: Fix RID2PASID setup/teardown failure

2022-06-23 Thread Lu Baolu
reasonable to remove this part of immature code to make the driver feasible and stable. Fixes: ef848b7e5a6a0 ("iommu/vt-d: Setup pasid entry for RID2PASID support") Reported-by: Chenyi Qiang Reported-by: Ethan Zhao Cc: sta...@vger.kernel.org Signed-off-by: Lu Baolu --- include/linu

[PATCH v2 1/1] iommu/vt-d: Fix RID2PASID setup failure

2022-06-21 Thread Lu Baolu
nt devices just try to setup the RID2PASID entry with the same domain, which is negligible. This also adds domain validity checks for more confidence anyway. Fixes: ef848b7e5a6a0 ("iommu/vt-d: Setup pasid entry for RID2PASID support") Reported-by: Chenyi Qiang Cc: sta...@vger.kernel.org Sig

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

2022-06-21 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 Reviewed-by: Jean-Philippe Brucker --- drivers/iommu/{iommu-sva-lib.h => iommu-sva.h} | 6 +++--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 2 +- driv

[PATCH v9 10/11] iommu: Per-domain I/O page fault handling

2022-06-21 Thread Lu Baolu
a guarantee that the SVA domain doesn't go away during IOPF handling, because unbind() waits for pending faults with iopf_queue_flush_dev() before freeing the domain. Hence, there's no need to synchronize life cycle of the iommu domains between the unbind() and the interrupt threads. Signed-off-by: Lu

[PATCH v9 09/11] iommu: Prepare IOMMU domain for IOPF

2022-06-21 Thread Lu Baolu
of the per-domain page fault handling model. The I/O page fault handler for SVA is copied to the SVA file with mmget_not_zero() added before mmap_read_lock(). Suggested-by: Jean-Philippe Brucker Signed-off-by: Lu Baolu Reviewed-by: Jean-Philippe Brucker --- include/linux/iommu.h | 3

[PATCH v9 08/11] iommu: Remove SVA related callbacks from iommu ops

2022-06-21 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 Reviewed-by: Jean-Philippe Brucker Reviewed-by: Kevin Tian --- include/linux/intel-iommu.h | 3

[PATCH v9 07/11] iommu/sva: Refactoring iommu_sva_bind/unbind_device()

2022-06-21 Thread Lu Baolu
interfaces implementation by using the set/block_pasid_dev ops and align them with the concept of the SVA iommu domain. Put the new SVA code in the sva related file in order to make it self-contained. Signed-off-by: Lu Baolu --- include/linux/iommu.h | 67 +++ drivers

[PATCH v9 06/11] arm-smmu-v3/sva: Add SVA domain support

2022-06-21 Thread Lu Baolu
Add support for SVA domain allocation and provide an SVA-specific iommu_domain_ops. Signed-off-by: Lu Baolu Reviewed-by: Jean-Philippe Brucker --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 6 ++ .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 69 +++ drivers/iommu/arm

[PATCH v9 05/11] iommu/vt-d: Add SVA domain support

2022-06-21 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 | 5 drivers/iommu/intel/iommu.c | 2 ++ drivers/iommu/intel/svm.c | 49 + 3 files changed, 56 insertions

[PATCH v9 04/11] iommu: Add sva iommu_domain support

2022-06-21 Thread Lu Baolu
in fabric i.e. not affected by hotplug. The iommu_attach/detach_device_pasid() can be used for other purposes, such as kernel DMA with pasid, mediation device, etc. Suggested-by: Jean-Philippe Brucker Suggested-by: Jason Gunthorpe Signed-off-by: Lu Baolu Reviewed-by: Jean-Philippe Brucker

[PATCH v9 03/11] iommu: Remove SVM_FLAG_SUPERVISOR_MODE support

2022-06-21 Thread Lu Baolu
in iommu_sva_bind_device() and all callbacks is not needed anymore. Cleanup them as well. Link: https://lore.kernel.org/linux-iommu/20210511194726.gp1002...@nvidia.com/ Signed-off-by: Jacob Pan Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe Reviewed-by: Jean-Philippe Brucker Reviewed-by: Kevin Tian

[PATCH v9 02/11] iommu: Add max_pasids field in struct dev_iommu

2022-06-21 Thread Lu Baolu
Use this field to save the number of PASIDs that a device is able to consume. It is a generic attribute of a device and lifting it into the per-device dev_iommu struct could help to avoid the boilerplate code in various IOMMU drivers. Signed-off-by: Lu Baolu --- include/linux/iommu.h | 2

[PATCH v9 00/11] iommu: SVA and IOPF refactoring

2022-06-21 Thread Lu Baolu
handler. v1: - https://lore.kernel.org/linux-iommu/20220320064030.2936936-1-baolu...@linux.intel.com/ - Initial post. *** BLURB HERE *** Lu Baolu (11): iommu: Add max_pasids field in struct iommu_device iommu: Add max_pasids field in struct dev_iommu iommu: Remove SVM_FLAG_SUPERVISOR_MO

[PATCH v9 01/11] iommu: Add max_pasids field in struct iommu_device

2022-06-21 Thread Lu Baolu
that supports PASID related features should set this field before enabling them on the devices. In the Intel IOMMU driver, intel_iommu_sm is moved to CONFIG_INTEL_IOMMU enclave so that the pasid_supported() helper could be used in dmar.c without compilation errors. Signed-off-by: Lu Baolu Reviewed

[PATCH 1/1] iommu/vt-d: Fix RID2PASID setup failure

2022-06-20 Thread Lu Baolu
vices just try to setup the RID2PASID entry with the same domain, which is negligible. Fixes: ef848b7e5a6a0 ("iommu/vt-d: Setup pasid entry for RID2PASID support") Reported-by: Chenyi Qiang Cc: sta...@vger.kernel.org Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 2 +

[PATCH 1/1] iommu/vt-d: Add set_dev_pasid callbacks for default domain

2022-06-13 Thread Lu Baolu
-domain list and is used for IOTLB and devTLB invalidation. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.h | 8 +++ drivers/iommu/intel/iommu.c | 118 +++- 2 files changed, 124 insertions(+), 2 deletions(-) --- Note: This is a follow-up of this patch

[PATCH v2 12/12] iommu/vt-d: Convert global spinlock into per domain ones

2022-06-13 Thread Lu Baolu
tracking lists are never accessed in any interrupt context, there is no need to disable interrupts while spinning. Replace irqsave variant with spinlock calls. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.h | 1 + drivers/iommu/intel/iommu.c | 45 +++-- 2

[PATCH v2 11/12] iommu/vt-d: Use device_domain_lock accurately

2022-06-13 Thread Lu Baolu
The device_domain_lock is used to protect the device tracking list of a domain. Remove unnecessary spin_lock/unlock()'s and move the necessary ones around the list access. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 68 +++-- 1 file changed, 27

[PATCH v2 10/12] iommu/vt-d: Fold __dmar_remove_one_dev_info() into its caller

2022-06-13 Thread Lu Baolu
Fold __dmar_remove_one_dev_info() into dmar_remove_one_dev_info() which is its only caller. Make the spin lock critical range only cover the device list change code and remove some unnecessary checks. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 34

[PATCH v2 09/12] iommu/vt-d: Check device list of domain in domain free path

2022-06-13 Thread Lu Baolu
When the IOMMU domain is about to be freed, it should not be set on any device. Instead of silently dealing with some bug cases, it's better to trigger a warning to report and fix any potential bugs at the first time. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe --- drivers/iommu/intel

[PATCH v2 08/12] iommu/vt-d: Replace spin_lock_irqsave() with spin_lock()

2022-06-13 Thread Lu Baolu
The iommu->lock is used to protect changes in root/context/pasid tables and domain ID allocation. There's no use case to change these resources in any interrupt context. Hence there's no need to disable interrupts when helding the spinlock. Signed-off-by: Lu Baolu --- drivers/iommu/in

[PATCH v2 07/12] iommu/vt-d: Acquiring lock in pasid manipulation helpers

2022-06-13 Thread Lu Baolu
olding the lock. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian --- drivers/iommu/intel/iommu.c | 2 - drivers/iommu/intel/pasid.c | 108 +++- drivers/iommu/intel/svm.c | 5 +- 3 files changed, 57 insertions(+), 58 deletions(-) diff --git a/drivers/iommu

[PATCH v2 06/12] iommu/vt-d: Acquiring lock in domain ID allocation helpers

2022-06-13 Thread Lu Baolu
t;lock is never used in interrupt context, there's no need to use the irqsave variant of the spinlock calls. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 25 + 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu

[PATCH v2 05/12] iommu/vt-d: Unnecessary spinlock for root table alloc and free

2022-06-13 Thread Lu Baolu
The IOMMU root table is allocated and freed in the IOMMU initialization code in static boot or hot-remove paths. There's no need for a spinlock. Signed-off-by: Lu Baolu Reviewed-by: Kevin Tian --- drivers/iommu/intel/iommu.c | 18 +- 1 file changed, 5 insertions(+), 13

[PATCH v2 04/12] iommu/vt-d: Use pci_get_domain_bus_and_slot() in pgtable_walk()

2022-06-13 Thread Lu Baolu
Use pci_get_domain_bus_and_slot() instead of searching the global list to retrieve the pci device pointer. This also removes the global device_domain_list as there isn't any consumer anymore. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe Reviewed-by: Kevin Tian --- drivers/iommu/intel

[PATCH v2 03/12] iommu/vt-d: Remove clearing translation data in disable_dmar_iommu()

2022-06-13 Thread Lu Baolu
to repeat it in IOMMU hot-remove path either. This removes the unnecessary code and only leaves a check. Signed-off-by: Lu Baolu --- drivers/iommu/intel/pasid.h | 1 + drivers/iommu/intel/iommu.c | 21 +++-- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/drivers

[PATCH v2 02/12] iommu/vt-d: Remove for_each_device_domain()

2022-06-13 Thread Lu Baolu
The per-device device_domain_info data could be retrieved from the device itself. There's no need to search a global list. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe Reviewed-by: Kevin Tian --- drivers/iommu/intel/iommu.h | 2 -- drivers/iommu/intel/iommu.c | 25

[PATCH v2 01/12] iommu/vt-d: debugfs: Remove device_domain_lock usage

2022-06-13 Thread Lu Baolu
the device tracking lists of each domain. This replaces device_domain_lock with group->mutex to protect page tables from setting a new domain. This also makes device_domain_lock static as it is now only used inside the file. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.h |

[PATCH v2 00/12] iommu/vt-d: Optimize the use of locks

2022-06-13 Thread Lu Baolu
://lore.kernel.org/linux-iommu/20220527063019.3112905-1-baolu...@linux.intel.com/ - Initial post. Lu Baolu (12): iommu/vt-d: debugfs: Remove device_domain_lock usage iommu/vt-d: Remove for_each_device_domain() iommu/vt-d: Remove clearing translation data in disable_dmar_iommu() iommu/vt-d: Use

[RFC PATCHES 2/2] iommu: Replace put_pages_list() with iommu_free_pgtbl_pages()

2022-06-09 Thread Lu Baolu
Therefore, RCU protected page free will take effect if necessary. Signed-off-by: Lu Baolu --- drivers/iommu/amd/io_pgtable.c | 5 ++--- drivers/iommu/dma-iommu.c | 6 -- drivers/iommu/intel/iommu.c| 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers

[RFC PATCHES 1/2] iommu: Add RCU-protected page free support

2022-06-09 Thread Lu Baolu
for scanning within a rcu_read_lock critical region. Considering that scanning the page table is a rare case, this also adds a domain flag and the RCU-protected page free is only used when this flat is set. Signed-off-by: Lu Baolu --- include/linux/iommu.h | 9 + drivers/iommu/iommu.c | 23

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

2022-06-06 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 Reviewed-by: Jean-Philippe Brucker --- drivers/iommu/{iommu-sva-lib.h => iommu-sva.h} | 6 +++--- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 2 +- driv

[PATCH v8 10/11] iommu: Per-domain I/O page fault handling

2022-06-06 Thread Lu Baolu
a guarantee that the SVA domain doesn't go away during IOPF handling, because unbind() waits for pending faults with iopf_queue_flush_dev() before freeing the domain. Hence, there's no need to synchronize life cycle of the iommu domains between the unbind() and the interrupt threads. Signed-off-by: Lu

[PATCH v8 09/11] iommu: Prepare IOMMU domain for IOPF

2022-06-06 Thread Lu Baolu
of the per-domain page fault handling model. The I/O page fault handler for SVA is copied to the SVA file with mmget_not_zero() added before mmap_read_lock(). Suggested-by: Jean-Philippe Brucker Signed-off-by: Lu Baolu Reviewed-by: Jean-Philippe Brucker --- include/linux/iommu.h | 3

[PATCH v8 08/11] iommu: Remove SVA related callbacks from iommu ops

2022-06-06 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 Reviewed-by: Jean-Philippe Brucker Reviewed-by: Kevin Tian --- include/linux/intel-iommu.h | 3

[PATCH v8 07/11] iommu/sva: Refactoring iommu_sva_bind/unbind_device()

2022-06-06 Thread Lu Baolu
interfaces implementation by using the set/block_pasid_dev ops and align them with the concept of the SVA iommu domain. Put the new SVA code in the sva related file in order to make it self-contained. Signed-off-by: Lu Baolu --- include/linux/iommu.h | 67 +++ drivers

[PATCH v8 06/11] arm-smmu-v3/sva: Add SVA domain support

2022-06-06 Thread Lu Baolu
Add support for SVA domain allocation and provide an SVA-specific iommu_domain_ops. Signed-off-by: Lu Baolu Reviewed-by: Jean-Philippe Brucker --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 6 ++ .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 69 +++ drivers/iommu/arm

[PATCH v8 05/11] iommu/vt-d: Add SVA domain support

2022-06-06 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 | 5 drivers/iommu/intel/iommu.c | 2 ++ drivers/iommu/intel/svm.c | 49 + 3 files changed, 56 insertions

[PATCH v8 04/11] iommu: Add sva iommu_domain support

2022-06-06 Thread Lu Baolu
in fabric i.e. not affected by hotplug. The iommu_attach/detach_device_pasid() can be used for other purposes, such as kernel DMA with pasid, mediation device, etc. Suggested-by: Jean-Philippe Brucker Suggested-by: Jason Gunthorpe Signed-off-by: Lu Baolu Reviewed-by: Jean-Philippe Brucker

[PATCH v8 03/11] iommu: Remove SVM_FLAG_SUPERVISOR_MODE support

2022-06-06 Thread Lu Baolu
in iommu_sva_bind_device() and all callbacks is not needed anymore. Cleanup them as well. Link: https://lore.kernel.org/linux-iommu/20210511194726.gp1002...@nvidia.com/ Signed-off-by: Jacob Pan Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe Reviewed-by: Jean-Philippe Brucker Reviewed-by: Kevin Tian

[PATCH v8 02/11] iommu: Add max_pasids field in struct dev_iommu

2022-06-06 Thread Lu Baolu
Use this field to save the number of PASIDs that a device is able to consume. It is a generic attribute of a device and lifting it into the per-device dev_iommu struct could help to avoid the boilerplate code in various IOMMU drivers. Signed-off-by: Lu Baolu --- include/linux/iommu.h | 2

[PATCH v8 00/11] iommu: SVA and IOPF refactoring

2022-06-06 Thread Lu Baolu
rop the patch "iommu: Handle IO page faults directly". - Add mmget_not_zero(mm) in SVA page fault handler. v1: - https://lore.kernel.org/linux-iommu/20220320064030.2936936-1-baolu...@linux.intel.com/ - Initial post. Lu Baolu (11): iommu: Add max_pasids field in struct iommu_device

[PATCH v8 01/11] iommu: Add max_pasids field in struct iommu_device

2022-06-06 Thread Lu Baolu
supports PASID related features should set this field before enabling them on the devices. Signed-off-by: Lu Baolu Reviewed-by: Jean-Philippe Brucker --- include/linux/intel-iommu.h | 3 ++- include/linux/iommu.h | 2 ++ drivers/iommu/arm/arm-smmu-v3/arm

[PATCH 12/12] iommu/vt-d: Convert device_domain_lock into per-domain mutex

2022-05-27 Thread Lu Baolu
-by: Lu Baolu --- drivers/iommu/intel/iommu.h | 1 + drivers/iommu/intel/iommu.c | 45 +++-- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index 6724703d573b..9e572ddffc08 100644

[PATCH 11/12] iommu/vt-d: Use device_domain_lock accurately

2022-05-27 Thread Lu Baolu
The device_domain_lock is used to protect the device tracking list of a domain. Remove unnecessary spin_lock/unlock()'s and move the necessary ones around the list access. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 68 +++-- 1 file changed, 27

[PATCH 10/12] iommu/vt-d: Fold __dmar_remove_one_dev_info() into its caller

2022-05-27 Thread Lu Baolu
Fold __dmar_remove_one_dev_info() into dmar_remove_one_dev_info() which is its only caller. Make the spin lock critical range only cover the device list change code and remove some unnecessary checks. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 34

[PATCH 09/12] iommu/vt-d: Check device list of domain in domain free path

2022-05-27 Thread Lu Baolu
When the IOMMU domain is about to be freed, it should not be set on any device. Instead of silently dealing with some bug cases, it's better to trigger a warning to report and fix any potential bugs at the first time. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 17

[PATCH 08/12] iommu/vt-d: Replace spin_lock_irqsave() with spin_lock()

2022-05-27 Thread Lu Baolu
The iommu->lock is used to protect changes in root/context/pasid tables and domain ID allocation. There's no use case to change these resources in any interrupt context. Hence there's no need to disable interrupts when helding the spinlock. Signed-off-by: Lu Baolu --- drivers/iommu/in

[PATCH 07/12] iommu/vt-d: Acquiring lock in pasid manipulation helpers

2022-05-27 Thread Lu Baolu
The iommu->lock is used to protect the per-IOMMU pasid directory table and pasid table. Move the spinlock acquisition/release into the helpers to make the code self-contained. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 2 - drivers/iommu/intel/pasid.c |

[PATCH 06/12] iommu/vt-d: Acquiring lock in domain ID allocation helpers

2022-05-27 Thread Lu Baolu
The iommu->lock is used to protect the per-IOMMU domain ID resource. Move the spinlock acquisition/release into the helpers where domain IDs are allocated and freed. The device_domain_lock is irrelevant to domain ID resources, remove its assertion as well. Signed-off-by: Lu Baolu --- driv

[PATCH 04/12] iommu/vt-d: Use pci_get_domain_bus_and_slot() in pgtable_walk()

2022-05-27 Thread Lu Baolu
Use pci_get_domain_bus_and_slot() instead of searching the global list to retrieve the pci device pointer. This removes device_domain_list global list as there are no consumers anymore. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.h | 1 - drivers/iommu/intel/iommu.c | 33

[PATCH 05/12] iommu/vt-d: Unncessary spinlock for root table alloc and free

2022-05-27 Thread Lu Baolu
The IOMMU root table is allocated and freed in the IOMMU initialization code in static boot or hot-plug paths. There's no need for a spinlock. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 18 +- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/drivers

[PATCH 03/12] iommu/vt-d: Remove clearing translation data in disable_dmar_iommu()

2022-05-27 Thread Lu Baolu
to repeat it in IOMMU hot-remove path either. So, let's remove this unnecessary code. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 15 --- 1 file changed, 15 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 6549b09d7f32..25d4c5200526

[PATCH 02/12] iommu/vt-d: Remove for_each_device_domain()

2022-05-27 Thread Lu Baolu
The per-device device_domain_info data could be retrieved from the device itself. There's no need to search a global list. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.h | 2 -- drivers/iommu/intel/iommu.c | 25 - drivers/iommu/intel/pasid.c | 37

[PATCH 01/12] iommu/vt-d: Use iommu_get_domain_for_dev() in debugfs

2022-05-27 Thread Lu Baolu
Retrieve the attached domain for a device through the generic interface exposed by the iommu core. This also makes device_domain_lock static. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.h | 1 - drivers/iommu/intel/debugfs.c | 20 drivers/iommu/intel/iommu.c

[PATCH 00/12] iommu/vt-d: Optimize the use of locks

2022-05-27 Thread Lu Baolu
and suggestions are very appreciated. Best regards, baolu Lu Baolu (12): iommu/vt-d: Use iommu_get_domain_for_dev() in debugfs iommu/vt-d: Remove for_each_device_domain() iommu/vt-d: Remove clearing translation data in disable_dmar_iommu() iommu/vt-d: Use pci_get_domain_bus_and_slot

[PATCH 1/1] iommu/vt-d: Remove unused iovad from dmar_domain

2022-05-26 Thread Lu Baolu
Not used anywhere. Cleanup it to avoid dead code. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.h | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/iommu/intel/iommu.h b/drivers/iommu/intel/iommu.h index 0f9df5a19ef7..a22adfbdf870 100644 --- a/drivers/iommu/intel/iommu.h +++ b

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

2022-05-19 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 Reviewed-by: Jean-Philippe Brucker --- drivers/iommu/{iommu-sva-lib.h => iommu-sva.h} | 0 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 2 +- drivers/io

  1   2   3   4   5   6   7   8   9   10   >