Re: [PATCH v3 09/16] iommu: Introduce guest PASID bind function

2019-05-20 Thread Jacob Pan
On Thu, 16 May 2019 09:14:29 -0700 Jacob Pan wrote: > On Thu, 16 May 2019 15:14:40 +0100 > Jean-Philippe Brucker wrote: > > > Hi Jacob, > > > > On 03/05/2019 23:32, Jacob Pan wrote: > > > +/** > > > + * struct gpasid_bind_data - Information about device and guest > > > PASID binding > > > +

Re: [PATCH v2 4/4] vfio: vfio_iommu_type1: implement VFIO_IOMMU_INFO_CAPABILITIES

2019-05-20 Thread Pierre Morel
On 20/05/2019 16:27, Cornelia Huck wrote: On Mon, 20 May 2019 13:19:23 +0200 Pierre Morel wrote: On 17/05/2019 20:04, Pierre Morel wrote: On 17/05/2019 18:41, Alex Williamson wrote: On Fri, 17 May 2019 18:16:50 +0200 Pierre Morel wrote: We implement the capability interface for

Re: [PATCH] iommu/vt-d: Fix bind svm with multiple devices

2019-05-20 Thread Jacob Pan
Hi Joerg & David, Any feedback on this one? Thanks. On Wed, 8 May 2019 12:22:46 -0700 Jacob Pan wrote: > If multiple devices try to bind to the same mm/PASID, we need to > set up first level PASID entries for all the devices. The current > code does not consider this case which results in

[PATCH 1/1] iommu/vt-d: Remove unnecessary rcu_read_locks

2019-05-20 Thread Lukasz Odzioba
We use RCU's for rarely updated lists like iommus, rmrr, atsr units. I'm not sure why domain_remove_dev_info() in domain_exit() was surrounded by rcu_read_lock. Lock was present before refactoring in d160aca527, but it was related to rcu list, not domain_remove_dev_info function.

Re: [PATCH v2 4/4] vfio: vfio_iommu_type1: implement VFIO_IOMMU_INFO_CAPABILITIES

2019-05-20 Thread Cornelia Huck
On Mon, 20 May 2019 13:19:23 +0200 Pierre Morel wrote: > On 17/05/2019 20:04, Pierre Morel wrote: > > On 17/05/2019 18:41, Alex Williamson wrote: > >> On Fri, 17 May 2019 18:16:50 +0200 > >> Pierre Morel wrote: > >> > >>> We implement the capability interface for VFIO_IOMMU_GET_INFO. > >>>

[PATCH v7 1/1] iommu: enhance IOMMU dma mode build options

2019-05-20 Thread Zhen Lei
First, add build option IOMMU_DEFAULT_{LAZY|STRICT}, so that we have the opportunity to set {lazy|strict} mode as default at build time. Then put the three config options in an choice, make people can only choose one of the three at a time. The default IOMMU dma modes on each ARCHs have no

[PATCH v7 0/1] iommu: enhance IOMMU dma mode build options

2019-05-20 Thread Zhen Lei
v6 --> v7: 1. Fix some text editing errors v5 --> v6: 1. give up adding boot option iommu.dma_mode v4 --> v5: As Hanjun and Thomas Gleixner's suggestion: 1. Keep the old ARCH specific boot options no change. 2. Keep build option CONFIG_IOMMU_DEFAULT_PASSTHROUGH no change. v4: As Robin Murphy's

Re: [RFC PATCH] virtio_ring: Use DMA API if guest memory is encrypted

2019-05-20 Thread Michael S. Tsirkin
On Wed, Apr 17, 2019 at 06:42:00PM -0300, Thiago Jung Bauermann wrote: > I rephrased it in terms of address translation. What do you think of > this version? The flag name is slightly different too: > > > VIRTIO_F_ACCESS_PLATFORM_NO_TRANSLATION This feature has the same > meaning as

Re: [RFC PATCH] virtio_ring: Use DMA API if guest memory is encrypted

2019-05-20 Thread Michael S. Tsirkin
On Fri, Apr 26, 2019 at 08:56:43PM -0300, Thiago Jung Bauermann wrote: > > Michael S. Tsirkin writes: > > > On Wed, Apr 24, 2019 at 10:01:56PM -0300, Thiago Jung Bauermann wrote: > >> > >> Michael S. Tsirkin writes: > >> > >> > On Wed, Apr 17, 2019 at 06:42:00PM -0300, Thiago Jung Bauermann

Re: [PATCH v3 6/7] iommu: Introduce IOMMU_RESV_DIRECT_RELAXABLE reserved memory regions

2019-05-20 Thread Auger Eric
Hi Robin, On 5/16/19 7:53 PM, Robin Murphy wrote: > On 16/05/2019 14:23, Auger Eric wrote: >> Hi Robin, >> On 5/16/19 2:46 PM, Robin Murphy wrote: >>> On 16/05/2019 11:08, Eric Auger wrote: Introduce a new type for reserved region. This corresponds to directly mapped regions which are

Re: [PATCH v2 4/4] vfio: vfio_iommu_type1: implement VFIO_IOMMU_INFO_CAPABILITIES

2019-05-20 Thread Pierre Morel
On 17/05/2019 20:04, Pierre Morel wrote: On 17/05/2019 18:41, Alex Williamson wrote: On Fri, 17 May 2019 18:16:50 +0200 Pierre Morel wrote: We implement the capability interface for VFIO_IOMMU_GET_INFO. When calling the ioctl, the user must specify VFIO_IOMMU_INFO_CAPABILITIES to retrieve

[PATCH 09/24] iommu/dma: Factor out remapped pages lookup

2019-05-20 Thread Christoph Hellwig
From: Robin Murphy Since we duplicate the find_vm_area() logic a few times in places where we only care aboute the pages, factor out a helper to abstract it. Signed-off-by: Robin Murphy [hch: don't warn when not finding a region, as we'll rely on that later] Signed-off-by: Christoph Hellwig

[PATCH 22/24] iommu/dma: Switch copyright boilerplace to SPDX

2019-05-20 Thread Christoph Hellwig
Signed-off-by: Christoph Hellwig Acked-by: Robin Murphy --- drivers/iommu/dma-iommu.c | 13 + include/linux/dma-iommu.h | 13 + 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index

[PATCH 23/24] arm64: switch copyright boilerplace to SPDX in dma-mapping.c

2019-05-20 Thread Christoph Hellwig
Signed-off-by: Christoph Hellwig Acked-by: Robin Murphy Reviewed-by: Mukesh Ojha Acked-by: Catalin Marinas --- arch/arm64/mm/dma-mapping.c | 15 +-- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c index

[PATCH 24/24] arm64: trim includes in dma-mapping.c

2019-05-20 Thread Christoph Hellwig
With most of the previous functionality now elsewhere a lot of the headers included in this file are not needed. Signed-off-by: Christoph Hellwig Acked-by: Catalin Marinas --- arch/arm64/mm/dma-mapping.c | 10 -- 1 file changed, 10 deletions(-) diff --git a/arch/arm64/mm/dma-mapping.c

[PATCH 19/24] iommu/dma: Refactor iommu_dma_get_sgtable

2019-05-20 Thread Christoph Hellwig
Inline __iommu_dma_get_sgtable_page into the main function, and use the fact that __iommu_dma_get_pages return NULL for remapped contigous allocations to simplify the code flow a bit. Signed-off-by: Christoph Hellwig Reviewed-by: Robin Murphy --- drivers/iommu/dma-iommu.c | 45

[PATCH 21/24] iommu/dma: Don't depend on CONFIG_DMA_DIRECT_REMAP

2019-05-20 Thread Christoph Hellwig
For entirely dma coherent architectures there is no requirement to ever remap dma coherent allocation. Move all the remap and pool code under IS_ENABLED() checks and drop the Kconfig dependency. Signed-off-by: Christoph Hellwig Reviewed-by: Robin Murphy --- drivers/iommu/Kconfig | 1 -

[PATCH 07/24] iommu/dma: Move domain lookup into __iommu_dma_{map, unmap}

2019-05-20 Thread Christoph Hellwig
From: Robin Murphy Most of the callers don't care, and the couple that do already have the domain to hand for other reasons are in slow paths where the (trivial) overhead of a repeated lookup will be utterly immaterial. Signed-off-by: Robin Murphy [hch: dropped the hunk touching

[PATCH 20/24] iommu/dma: Refactor iommu_dma_mmap

2019-05-20 Thread Christoph Hellwig
Inline __iommu_dma_mmap_pfn into the main function, and use the fact that __iommu_dma_get_pages return NULL for remapped contigous allocations to simplify the code flow a bit. Signed-off-by: Christoph Hellwig Reviewed-by: Robin Murphy --- drivers/iommu/dma-iommu.c | 46

[PATCH 18/24] iommu/dma: Refactor iommu_dma_alloc, part 2

2019-05-20 Thread Christoph Hellwig
All the logic in iommu_dma_alloc that deals with page allocation from the CMA or page allocators can be split into a self-contained helper, and we can than map the result of that or the atomic pool allocation with the iommu later. This also allows reusing __iommu_dma_free to tear down the

[PATCH 06/24] iommu/dma: Move __iommu_dma_map

2019-05-20 Thread Christoph Hellwig
Moving this function up to its unmap counterpart helps to keep related code together for the following changes. Signed-off-by: Christoph Hellwig Reviewed-by: Robin Murphy --- drivers/iommu/dma-iommu.c | 46 +++ 1 file changed, 23 insertions(+), 23

[PATCH 17/24] iommu/dma: Cleanup variable naming in iommu_dma_alloc

2019-05-20 Thread Christoph Hellwig
From: Robin Murphy Most importantly clear up the size / iosize confusion. Also rename addr to cpu_addr to match the surrounding code and make the intention a little more clear. Signed-off-by: Robin Murphy [hch: split from a larger patch] Signed-off-by: Christoph Hellwig ---

[PATCH 16/24] iommu/dma: Split iommu_dma_free

2019-05-20 Thread Christoph Hellwig
From: Robin Murphy Most of it can double up to serve the failure cleanup path for iommu_dma_alloc(). Signed-off-by: Robin Murphy --- drivers/iommu/dma-iommu.c | 12 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c

[PATCH 13/24] iommu/dma: Refactor iommu_dma_alloc

2019-05-20 Thread Christoph Hellwig
From: Robin Murphy Shuffle around the self-contained atomic and non-contiguous cases to return early and get out of the way of the CMA case that we're about to work on next. Signed-off-by: Robin Murphy [hch: slight changes to the code flow] Signed-off-by: Christoph Hellwig ---

[PATCH 08/24] iommu/dma: Squash __iommu_dma_{map,unmap}_page helpers

2019-05-20 Thread Christoph Hellwig
From: Robin Murphy The remaining internal callsites don't care about having prototypes compatible with the relevant dma_map_ops callbacks, so the extra level of indirection just wastes space and complictaes things. Signed-off-by: Robin Murphy Signed-off-by: Christoph Hellwig ---

[PATCH 05/24] iommu/dma: move the arm64 wrappers to common code

2019-05-20 Thread Christoph Hellwig
There is nothing really arm64 specific in the iommu_dma_ops implementation, so move it to dma-iommu.c and keep a lot of symbols self-contained. Note the implementation does depend on the DMA_DIRECT_REMAP infrastructure for now, so we'll have to make the DMA_IOMMU support depend on it, but this

[PATCH 15/24] iommu/dma: Merge the CMA and alloc_pages allocation paths

2019-05-20 Thread Christoph Hellwig
Instead of having a separate code path for the non-blocking alloc_pages and CMA allocations paths merge them into one. There is a slight behavior change here in that we try the page allocator if CMA fails. This matches what dma-direct and other iommu drivers do and will be needed to use the

[PATCH 10/24] iommu/dma: Refactor the page array remapping allocator

2019-05-20 Thread Christoph Hellwig
Move the call to dma_common_pages_remap into __iommu_dma_alloc and rename it to iommu_dma_alloc_remap. This creates a self-contained helper for remapped pages allocation and mapping. Signed-off-by: Christoph Hellwig Reviewed-by: Robin Murphy --- drivers/iommu/dma-iommu.c | 54

[PATCH 14/24] iommu/dma: Don't remap CMA unnecessarily

2019-05-20 Thread Christoph Hellwig
From: Robin Murphy Always remapping CMA allocations was largely a bodge to keep the freeing logic manageable when it was split between here and an arch wrapper. Now that it's all together and streamlined, we can relax that limitation. Signed-off-by: Robin Murphy Signed-off-by: Christoph

[PATCH 12/24] iommu/dma: Refactor iommu_dma_free

2019-05-20 Thread Christoph Hellwig
From: Robin Murphy The freeing logic was made particularly horrible by part of it being opaque to the arch wrapper, which led to a lot of convoluted repetition to ensure each path did everything in the right order. Now that it's all private, we can pick apart and consolidate the

[PATCH 11/24] iommu/dma: Remove __iommu_dma_free

2019-05-20 Thread Christoph Hellwig
We only have a single caller of this function left, so open code it there. Signed-off-by: Christoph Hellwig Reviewed-by: Robin Murphy --- drivers/iommu/dma-iommu.c | 21 ++--- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/drivers/iommu/dma-iommu.c

[PATCH 04/24] iommu/dma: Use for_each_sg in iommu_dma_alloc

2019-05-20 Thread Christoph Hellwig
arch_dma_prep_coherent can handle physically contiguous ranges larger than PAGE_SIZE just fine, which means we don't need a page-based iterator. Signed-off-by: Christoph Hellwig Reviewed-by: Robin Murphy --- drivers/iommu/dma-iommu.c | 14 +- 1 file changed, 5 insertions(+), 9

[PATCH 01/24] arm64/iommu: handle non-remapped addresses in ->mmap and ->get_sgtable

2019-05-20 Thread Christoph Hellwig
DMA allocations that can't sleep may return non-remapped addresses, but we do not properly handle them in the mmap and get_sgtable methods. Resolve non-vmalloc addresses using virt_to_page to handle this corner case. Signed-off-by: Christoph Hellwig Reviewed-by: Robin Murphy Acked-by: Catalin

implement generic dma_map_ops for IOMMUs v5

2019-05-20 Thread Christoph Hellwig
Hi Robin and Joerg, I think we are finally ready for the generic dma-iommu series. I have various DMA API changes pending, and Tom has patches ready to convert the AMD and Intel iommu drivers over to it. I'd love to have this in a stable branch shared between the dma-mapping and iommu trees the

[PATCH 03/24] iommu/dma: Remove the flush_page callback

2019-05-20 Thread Christoph Hellwig
We now have a arch_dma_prep_coherent architecture hook that is used for the generic DMA remap allocator, and we should use the same interface for the dma-iommu code. Signed-off-by: Christoph Hellwig Reviewed-by: Robin Murphy Acked-by: Catalin Marinas --- arch/arm64/mm/dma-mapping.c | 8