Re: [PATCH v5 2/2] iommu/mediatek: Allow page table PA up to 35bit

2022-05-19 Thread Yong Wu via iommu
On Mon, 2022-05-16 at 22:16 +0800, yf.w...@mediatek.com wrote: > From: Yunfei Wang > > Add the quirk IO_PGTABLE_QUIRK_ARM_MTK_TTBR_EXT support, so that > allows > page table PA up to 35bit, not only in ZONE_DMA32. Comment why this is needed. e.g. For single normal zone. > > Signed-off-by:

Re: [PATCH] iommu/dma: Add config for PCI SAC address trick

2022-05-19 Thread Christoph Hellwig
On Wed, May 18, 2022 at 06:36:59PM +0100, Robin Murphy wrote: > +config IOMMU_DMA_PCI_SAC_OPT > + bool "Enable 64-bit legacy PCI optimisation by default" > + depends on IOMMU_DMA > + default X86 > + help > + Enable by default an IOMMU optimisation for 64-bit legacy PCI

[PATCH v7 01/10] iommu: Add pasids field in struct iommu_device

2022-05-19 Thread Lu Baolu
Use this field to keep the number of supported PASIDs that an IOMMU hardware is able to support. This is a generic attribute of an IOMMU and lifting it into the per-IOMMU device structure makes it possible to allocate a PASID for device without calls into the IOMMU drivers. Any iommu driver which

[PATCH v7 00/10] iommu: SVA and IOPF refactoring

2022-05-19 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 v7 02/10] iommu: Remove SVM_FLAG_SUPERVISOR_MODE support

2022-05-19 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 v7 06/10] iommu/sva: Refactoring iommu_sva_bind/unbind_device()

2022-05-19 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 v7 07/10] iommu: Remove SVA related callbacks from iommu ops

2022-05-19 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 --- include/linux/intel-iommu.h | 3 -- include/linux/iommu.h

[PATCH v7 03/10] iommu/sva: Add iommu_sva_domain support

2022-05-19 Thread Lu Baolu
The iommu_sva_domain represents a hardware pagetable that the IOMMU hardware could use for SVA translation. This adds some infrastructure to support SVA domain in the iommu common layer. It includes: - Add a new struct iommu_sva_domain and new IOMMU_DOMAIN_SVA domain type. - Add a new domain

[PATCH v7 04/10] iommu/vt-d: Add SVA domain support

2022-05-19 Thread Lu Baolu
Add support for domain ops callbacks for an SVA domain. Signed-off-by: Lu Baolu --- include/linux/intel-iommu.h | 4 drivers/iommu/intel/iommu.c | 4 drivers/iommu/intel/svm.c | 37 - 3 files changed, 40 insertions(+), 5 deletions(-) diff --git

[PATCH v7 09/10] iommu: Per-domain I/O page fault handling

2022-05-19 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 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 +-

[PATCH v7 08/10] iommu: Prepare IOMMU domain for IOPF

2022-05-19 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 v7 05/10] arm-smmu-v3/sva: Add SVA domain support

2022-05-19 Thread Lu Baolu
Add support for domain ops callbacks for an SVA domain. Signed-off-by: Lu Baolu --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 4 ++ .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 46 +++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 6 +++ 3 files changed, 56

Re: [PATCH v5 1/2] iommu/io-pgtable-arm-v7s: Add a quirk to allow pgtable PA up to 35bit

2022-05-19 Thread Miles Chen via iommu
Hi Yunfei, > The calling to kmem_cache_alloc for level 2 pgtable allocation may run > in atomic context, and it fails sometimes when DMA32 zone runs out of > memory. > > Since Mediatek IOMMU hardware support at most 35bit PA in pgtable, > so add a quirk to allow the PA of pgtables support up to

Re: [PATCH v4 1/6] iommu: Add a per domain PASID for DMA API

2022-05-19 Thread Baolu Lu
On 2022/5/19 02:21, Jacob Pan wrote: DMA requests tagged with PASID can target individual IOMMU domains. Introduce a domain-wide PASID for DMA API, it will be used on the same mapping as legacy DMA without PASID. Let it be IOVA or PA in case of identity domain. Signed-off-by: Jacob Pan ---

Re: [PATCH RFC 10/12] iommufd: Add kAPI toward external drivers

2022-05-19 Thread Yi Liu
Hi Jason, On 2022/3/19 01:27, Jason Gunthorpe wrote: +/** + * iommufd_device_attach - Connect a device to an iommu_domain + * @idev: device to attach + * @pt_id: Input a IOMMUFD_OBJ_IOAS, or IOMMUFD_OBJ_HW_PAGETABLE + * Output the IOMMUFD_OBJ_HW_PAGETABLE ID + * @flags: Optional flags

Re: [PATCH v3] iommu: iommu_group_claim_dma_owner() must always assign a domain

2022-05-19 Thread Joerg Roedel
On Wed, May 18, 2022 at 04:14:46PM -0300, Jason Gunthorpe wrote: > Fixes: 0286300e6045 ("iommu: iommu_group_claim_dma_owner() must always assign > a domain") > Reported-by: Eric Farman > Signed-off-by: Jason Gunthorpe > --- > drivers/vfio/vfio.c | 15 ++- > 1 file changed, 10

Re: [PATCH v4 2/6] iommu: Add a helper to do PASID lookup from domain

2022-05-19 Thread Christoph Hellwig
On Wed, May 18, 2022 at 11:21:16AM -0700, Jacob Pan wrote: > +ioasid_t iommu_get_pasid_from_domain(struct device *dev, struct iommu_domain > *domain) Overly long line here. ___ iommu mailing list iommu@lists.linux-foundation.org

Re: [PATCH v7 01/10] iommu: Add pasids field in struct iommu_device

2022-05-19 Thread Jean-Philippe Brucker
Hi Baolu, On Thu, May 19, 2022 at 03:20:38PM +0800, Lu Baolu wrote: > diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > index 88817a3376ef..6e2cd082c670 100644 > --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c > +++

Re: [PATCH RFC 10/12] iommufd: Add kAPI toward external drivers

2022-05-19 Thread Jason Gunthorpe via iommu
On Thu, May 19, 2022 at 05:45:06PM +0800, Yi Liu wrote: > Hi Jason, > > On 2022/3/19 01:27, Jason Gunthorpe wrote: > > > +/** > > + * iommufd_device_attach - Connect a device to an iommu_domain > > + * @idev: device to attach > > + * @pt_id: Input a IOMMUFD_OBJ_IOAS, or IOMMUFD_OBJ_HW_PAGETABLE

Re: [syzbot] WARNING in __dma_map_sg_attrs

2022-05-19 Thread Dmitry Vyukov via iommu
On Tue, 8 Feb 2022 at 13:26, Daniel Vetter wrote: > > On Sat, Feb 05, 2022 at 12:18:23PM -0800, syzbot wrote: > > syzbot has found a reproducer for the following issue on: > > > > HEAD commit:0457e5153e0e Merge tag 'for-linus' of git://git.kernel.org.. > > git tree: upstream > > console

Re: [PATCH v7 01/10] iommu: Add pasids field in struct iommu_device

2022-05-19 Thread Baolu Lu
Hi Jean, On 2022/5/19 18:37, Jean-Philippe Brucker wrote: On Thu, May 19, 2022 at 03:20:38PM +0800, Lu Baolu wrote: diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 88817a3376ef..6e2cd082c670 100644 ---

Re: [PATCH] iommu/dma: Add config for PCI SAC address trick

2022-05-19 Thread John Garry via iommu
On 18/05/2022 18:36, Robin Murphy wrote: For devices stuck behind a conventional PCI bus, saving extra cycles at 33MHz is probably fairly significant. However since native PCI Express is now the norm for high-performance devices, the optimisation to always prefer 32-bit addresses for the sake of

Re: [PATCH v7 02/10] iommu: Remove SVM_FLAG_SUPERVISOR_MODE support

2022-05-19 Thread Jean-Philippe Brucker
On Thu, May 19, 2022 at 03:20:39PM +0800, Lu Baolu wrote: > 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

Re: [PATCH v7 03/10] iommu/sva: Add iommu_sva_domain support

2022-05-19 Thread Jean-Philippe Brucker
On Thu, May 19, 2022 at 03:20:40PM +0800, Lu Baolu wrote: > The iommu_sva_domain represents a hardware pagetable that the IOMMU > hardware could use for SVA translation. This adds some infrastructure > to support SVA domain in the iommu common layer. It includes: > > - Add a new struct

Re: [PATCH v7 05/10] arm-smmu-v3/sva: Add SVA domain support

2022-05-19 Thread Jean-Philippe Brucker
On Thu, May 19, 2022 at 03:20:42PM +0800, Lu Baolu wrote: > Add support for domain ops callbacks for an SVA domain. > > Signed-off-by: Lu Baolu Reviewed-by: Jean-Philippe Brucker (I'll try to take some time next cycle to clean up the driver following this change) > --- >

Re: [PATCH v7 08/10] iommu: Prepare IOMMU domain for IOPF

2022-05-19 Thread Jean-Philippe Brucker
On Thu, May 19, 2022 at 03:20:45PM +0800, Lu Baolu wrote: > 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

Re: [PATCH v3] iommu: iommu_group_claim_dma_owner() must always assign a domain

2022-05-19 Thread Alex Williamson
On Thu, 19 May 2022 09:32:05 +0200 Joerg Roedel wrote: > On Wed, May 18, 2022 at 04:14:46PM -0300, Jason Gunthorpe wrote: > > Fixes: 0286300e6045 ("iommu: iommu_group_claim_dma_owner() must always > > assign a domain") > > Reported-by: Eric Farman > > Signed-off-by: Jason Gunthorpe > > --- >

Re: [PATCH v7 06/10] iommu/sva: Refactoring iommu_sva_bind/unbind_device()

2022-05-19 Thread Jean-Philippe Brucker
On Thu, May 19, 2022 at 03:20:43PM +0800, Lu Baolu wrote: > 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

[PATCH] vfio: Do not manipulate iommu dma_owner for fake iommu groups

2022-05-19 Thread Jason Gunthorpe via iommu
Since asserting dma ownership now causes the group to have its DMA blocked the iommu layer requires a working iommu. This means the dma_owner APIs cannot be used on the fake groups that VFIO creates. Test for this and avoid calling them. Otherwise asserting dma ownership will fail for VFIO mdev

Re: [PATCH v3] iommu: iommu_group_claim_dma_owner() must always assign a domain

2022-05-19 Thread Jason Gunthorpe via iommu
On Thu, May 19, 2022 at 10:51:47AM -0600, Alex Williamson wrote: > On Thu, 19 May 2022 09:32:05 +0200 > Joerg Roedel wrote: > > > On Wed, May 18, 2022 at 04:14:46PM -0300, Jason Gunthorpe wrote: > > > Fixes: 0286300e6045 ("iommu: iommu_group_claim_dma_owner() must always > > > assign a domain")

[PATCH] iommu/s390: tolerate repeat attach_dev calls

2022-05-19 Thread Matthew Rosato
Since commit 0286300e6045 ("iommu: iommu_group_claim_dma_owner() must always assign a domain") s390-iommu will get called to allocate multiple unmanaged iommu domains for a vfio-pci device -- however the current s390-iommu logic tolerates only one. Recognize that multiple domains can be allocated

Re: [PATCH v4 2/6] iommu: Add a helper to do PASID lookup from domain

2022-05-19 Thread Baolu Lu
On 2022/5/19 02:21, Jacob Pan wrote: IOMMU group maintains a PASID array which stores the associated IOMMU domains. This patch introduces a helper function to do domain to PASID look up. It will be used by TLB flush and device-PASID attach verification. Do you really need this? The IOMMU

Re: [PATCH] iommu/s390: tolerate repeat attach_dev calls

2022-05-19 Thread Matthew Rosato
On 5/19/22 2:29 PM, Matthew Rosato wrote: Since commit 0286300e6045 ("iommu: iommu_group_claim_dma_owner() must always assign a domain") s390-iommu will get called to allocate multiple unmanaged iommu domains for a vfio-pci device -- however the current s390-iommu logic tolerates only one.

Re: [PATCH v4 2/6] iommu: Add a helper to do PASID lookup from domain

2022-05-19 Thread Jacob Pan
Hi Baolu, On Thu, 19 May 2022 14:41:06 +0800, Baolu Lu wrote: > > IOMMU group maintains a PASID array which stores the associated IOMMU > > domains. This patch introduces a helper function to do domain to PASID > > look up. It will be used by TLB flush and device-PASID attach > > verification.

Re: [PATCH] iommu/s390: tolerate repeat attach_dev calls

2022-05-19 Thread Jason Gunthorpe via iommu
On Thu, May 19, 2022 at 02:29:29PM -0400, Matthew Rosato wrote: > Since commit 0286300e6045 ("iommu: iommu_group_claim_dma_owner() must > always assign a domain") s390-iommu will get called to allocate multiple > unmanaged iommu domains for a vfio-pci device -- however the current > s390-iommu

Re: [PATCH v6 20/29] init/main: Delay initialization of the lockup detector after smp_init()

2022-05-19 Thread Nicholas Piggin
Excerpts from Ricardo Neri's message of May 14, 2022 9:16 am: > On Tue, May 10, 2022 at 08:38:22PM +1000, Nicholas Piggin wrote: >> Excerpts from Ricardo Neri's message of May 6, 2022 9:59 am: >> > Certain implementations of the hardlockup detector require support for >> > Inter-Processor

Re: [PATCH v7 03/10] iommu/sva: Add iommu_sva_domain support

2022-05-19 Thread Baolu Lu
On 2022/5/20 00:33, Jean-Philippe Brucker wrote: diff --git a/drivers/iommu/iommu-sva-lib.h b/drivers/iommu/iommu-sva-lib.h index 8909ea1094e3..1be21e6b93ec 100644 --- a/drivers/iommu/iommu-sva-lib.h +++ b/drivers/iommu/iommu-sva-lib.h @@ -7,6 +7,7 @@ #include #include +#include

Re: [PATCH] vfio: Do not manipulate iommu dma_owner for fake iommu groups

2022-05-19 Thread Christoph Hellwig
On Thu, May 19, 2022 at 02:03:48PM -0300, Jason Gunthorpe via iommu wrote: > Since asserting dma ownership now causes the group to have its DMA blocked > the iommu layer requires a working iommu. This means the dma_owner APIs > cannot be used on the fake groups that VFIO creates. Test for this and

Re: [PATCH v3 1/4] iommu/vt-d: Implement domain ops for attach_dev_pasid

2022-05-19 Thread Jacob Pan
Hi Jason, On Wed, 18 May 2022 15:52:05 -0300, Jason Gunthorpe wrote: > On Wed, May 18, 2022 at 11:42:04AM -0700, Jacob Pan wrote: > > > > Yes.. It seems inefficient to iterate over that xarray multiple times > > > on the flush hot path, but maybe there is little choice. Try to use > > > use

RE: [PATCH] vfio: Do not manipulate iommu dma_owner for fake iommu groups

2022-05-19 Thread Tian, Kevin
> From: Jason Gunthorpe > Sent: Friday, May 20, 2022 1:04 AM > > Since asserting dma ownership now causes the group to have its DMA > blocked > the iommu layer requires a working iommu. This means the dma_owner APIs > cannot be used on the fake groups that VFIO creates. Test for this and > avoid