Re: [PATCH 4/6] iommu/qcom: Add support for AArch64 IOMMU pagetables

2022-05-27 Thread kernel test robot
Hi Konrad, Thank you for the patch! Perhaps something to improve: [auto build test WARNING on joro-iommu/next] [also build test WARNING on v5.18 next-20220527] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base

Re: [PATCH v6 20/21] PCI/P2PDMA: Introduce pci_mmap_p2pmem()

2022-05-27 Thread Logan Gunthorpe
On 2022-05-27 13:03, Jason Gunthorpe wrote: > On Fri, May 27, 2022 at 09:35:07AM -0600, Logan Gunthorpe wrote: >> >> >> On 2022-05-27 06:55, Jason Gunthorpe wrote: >>> On Thu, Apr 07, 2022 at 09:47:16AM -0600, Logan Gunthorpe wrote: +static void pci_p2pdma_unmap_mappings(void *data)

[PATCH 1/6] iommu/qcom: Use the asid read from device-tree if specified

2022-05-27 Thread Konrad Dybcio
From: AngeloGioacchino Del Regno As specified in this driver, the context banks are 0x1000 apart. Problem is that sometimes the context number (our asid) does not match this logic and we end up using the wrong one: this starts being a problem in the case that we need to send TZ commands to do

[PATCH 0/6] Fix and extend Qualcomm IOMMU support

2022-05-27 Thread Konrad Dybcio
Due to Qualcomm's software solutions, genius or otherwise, the IOMMUs on pre-msm8998-and-sdm630 SoCs are flawed beyond reason, and conviniently it is all due to an (almost in all cases) irreplaceable hypervisor and TZ stack. As end users and developers, we have no choice but to adapt to that and

[PATCH 3/6] iommu/qcom: Properly reset the IOMMU context

2022-05-27 Thread Konrad Dybcio
From: AngeloGioacchino Del Regno To avoid context faults reset the context entirely on detach and to ensure a fresh clean start also do a complete reset before programming the context for domain initialization. Signed-off-by: AngeloGioacchino Del Regno Signed-off-by: Marijn Suijten

[PATCH 2/6] iommu/qcom: Write TCR before TTBRs to fix ASID access behavior

2022-05-27 Thread Konrad Dybcio
From: AngeloGioacchino Del Regno As also stated in the arm-smmu driver, we must write the TCR before writing the TTBRs, since the TCR determines the access behavior of some fields. Signed-off-by: AngeloGioacchino Del Regno Signed-off-by: Marijn Suijten Signed-off-by: Konrad Dybcio ---

[PATCH 4/6] iommu/qcom: Add support for AArch64 IOMMU pagetables

2022-05-27 Thread Konrad Dybcio
From: AngeloGioacchino Del Regno Some IOMMUs associated with some TZ firmwares may support switching to the AArch64 pagetable format by sending a "set pagetable format" scm command indicating the IOMMU secure ID and the context number to switch. Add a DT property "qcom,use-aarch64-pagetables"

[PATCH 6/6] iommu/qcom: Add support for QCIOMMUv2 and QCIOMMU-500 secured contexts

2022-05-27 Thread Konrad Dybcio
From: AngeloGioacchino Del Regno This IOMMU is yet another Qualcomm variant of known IOMMUs, found in Family-B SoCs, such as MSM8956, MSM8976, MSM8953, MSM8917 and others, and that firmware perfectly adheres to this driver logic. This time, though, the catch is that the secure contexts are also

[PATCH 5/6] iommu/qcom: Index contexts by asid number to allow asid 0

2022-05-27 Thread Konrad Dybcio
From: AngeloGioacchino Del Regno This driver was indexing the contexts by asid-1, which is probably done under the assumption that the first ASID is always 1. Unfortunately this is not entirely true: at least in the MSM8956 and MSM8976 GPU IOMMU, the gpu_user context's ASID number is zero. To

Re: [PATCH v6 20/21] PCI/P2PDMA: Introduce pci_mmap_p2pmem()

2022-05-27 Thread Jason Gunthorpe
On Fri, May 27, 2022 at 09:35:07AM -0600, Logan Gunthorpe wrote: > > > On 2022-05-27 06:55, Jason Gunthorpe wrote: > > On Thu, Apr 07, 2022 at 09:47:16AM -0600, Logan Gunthorpe wrote: > >> +static void pci_p2pdma_unmap_mappings(void *data) > >> +{ > >> + struct pci_dev *pdev = data; > >> +

Re: [PATCH v6 20/21] PCI/P2PDMA: Introduce pci_mmap_p2pmem()

2022-05-27 Thread Logan Gunthorpe
On 2022-05-27 06:55, Jason Gunthorpe wrote: > On Thu, Apr 07, 2022 at 09:47:16AM -0600, Logan Gunthorpe wrote: >> +static void pci_p2pdma_unmap_mappings(void *data) >> +{ >> +struct pci_dev *pdev = data; >> +struct pci_p2pdma *p2pdma = rcu_dereference_protected(pdev->p2pdma, 1); >> + >>

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

2022-05-27 Thread Jason Gunthorpe via iommu
On Fri, May 27, 2022 at 02:30:16PM +0800, Lu Baolu wrote: > 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. > >

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

2022-05-27 Thread Jason Gunthorpe via iommu
On Fri, May 27, 2022 at 02:30:11PM +0800, Lu Baolu wrote: > 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 > --- >

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

2022-05-27 Thread Jason Gunthorpe via iommu
On Fri, May 27, 2022 at 02:30:10PM +0800, Lu Baolu wrote: > The disable_dmar_iommu() is called when IOMMU initialzation fails or > the IOMMU is hot-removed from the system. In both cases, there is no > need to clear the IOMMU translation data structures for devices. > > On the initialization

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

2022-05-27 Thread Jason Gunthorpe via iommu
On Fri, May 27, 2022 at 02:30:09PM +0800, Lu Baolu wrote: > 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

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

2022-05-27 Thread Jason Gunthorpe via iommu
On Fri, May 27, 2022 at 02:30:08PM +0800, Lu Baolu wrote: > 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 - >

Re: [PATCH] drivers: iommu: Directly use ida_alloc()/free()

2022-05-27 Thread Jason Gunthorpe via iommu
On Fri, May 27, 2022 at 07:03:07AM +, keliu wrote: > Use ida_alloc()/ida_free() instead of deprecated > ida_simple_get()/ida_simple_remove() . > > Signed-off-by: keliu > --- > drivers/iommu/iommu.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) Reviewed-by: Jason Gunthorpe

Re: [PATCH v6 20/21] PCI/P2PDMA: Introduce pci_mmap_p2pmem()

2022-05-27 Thread Jason Gunthorpe
On Thu, Apr 07, 2022 at 09:47:16AM -0600, Logan Gunthorpe wrote: > +static void pci_p2pdma_unmap_mappings(void *data) > +{ > + struct pci_dev *pdev = data; > + struct pci_p2pdma *p2pdma = rcu_dereference_protected(pdev->p2pdma, 1); > + > + /* Ensure no new pages can be allocated in

Re: [RFC PATCH V3 2/2] net: netvsc: Allocate per-device swiotlb bounce buffer for netvsc

2022-05-27 Thread Tianyu Lan
On 5/27/2022 2:43 AM, Dexuan Cui wrote: From: Tianyu Lan Sent: Thursday, May 26, 2022 5:01 AM ... @@ -119,6 +124,10 @@ static void netvsc_subchan_work(struct work_struct *w) nvdev->max_chn = 1; nvdev->num_chn = 1; } + +

[PATCH] drivers: iommu: Directly use ida_alloc()/free()

2022-05-27 Thread keliu via iommu
Use ida_alloc()/ida_free() instead of deprecated ida_simple_get()/ida_simple_remove() . Signed-off-by: keliu --- drivers/iommu/iommu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 857d4c2fd1a2..8d56146a0b44 100644

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

2022-05-27 Thread Lu Baolu
Using a global device_domain_lock spinlock to protect per-domain device tracking lists is an inefficient way, especially considering this lock is also needed in the hot paths. On the other hand, in the iommu_unmap() path, the driver needs to iterate over the device tracking list and flush the

[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 ---

[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 | 106

[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 ---

[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

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

2022-05-27 Thread Lu Baolu
The disable_dmar_iommu() is called when IOMMU initialzation fails or the IOMMU is hot-removed from the system. In both cases, there is no need to clear the IOMMU translation data structures for devices. On the initialization path, the device probing only happens after the IOMMU is initialized

[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
Hi folks, This series tries to optimize the uses of two locks in the Intel IOMMU driver: - The intel_iommu::lock is used to protect the IOMMU resources shared by devices. They include the IOMMU root and context tables, the pasid tables and the domain IDs. - The global device_domain_lock is