[PATCH] iommu/amd: Remove redundant assignment of err

2021-05-18 Thread Shaokun Zhang
'err' will be initialized and cleanup the redundant initialization. Cc: Joerg Roedel Signed-off-by: Shaokun Zhang --- drivers/iommu/amd/iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index

[PATCH 1/2] iommu/vt-d: Check for allocation failure in aux_detach_device()

2021-05-18 Thread Lu Baolu
From: Dan Carpenter In current kernels small allocations never fail, but checking for allocation failure is the correct thing to do. Fixes: 18abda7a2d55 ("iommu/vt-d: Fix general protection fault in aux_detach_device()") Signed-off-by: Dan Carpenter Acked-by: Lu Baolu Link:

[PATCH 2/2] iommu/vt-d: Use user privilege for RID2PASID translation

2021-05-18 Thread Lu Baolu
When first-level page tables are used for IOVA translation, we use user privilege by setting U/S bit in the page table entry. This is to make it consistent with the second level translation, where the U/S enforcement is not available. Clear the SRE (Supervisor Request Enable) field in the pasid

[PATCH 0/2] [PULL REQUEST] iommu/vt-d: Fixes for v5.13-rc3

2021-05-18 Thread Lu Baolu
Hi Joerg, Two small fixes are queued in this series. It includes: - Use user privilege for RID2PASID translation - Check memory allocation return value Please consider them for v5.13. Best regards, Lu Baolu Dan Carpenter (1): iommu/vt-d: Check for allocation failure in aux_detach_device()

[PATCH 1/2] irqchip/qcom-pdc: Switch to IRQCHIP_PLATFORM_DRIVER and allow as a module

2021-05-18 Thread John Stultz
From: Saravana Kannan This patch revives changes from Saravana Kannan to switch the qcom-pdc driver to use IRQCHIP_PLATFORM_DRIVER helper macros, and allows qcom-pdc driver to be loaded as a permanent module. Earlier attempts at this ran into trouble with loading dependencies, but with

[PATCH 2/2] firmware: QCOM_SCM: Allow qcom_scm driver to be loadable as a permenent module

2021-05-18 Thread John Stultz
Allow the qcom_scm driver to be loadable as a permenent module. This still uses the "depends on QCOM_SCM || !QCOM_SCM" bit to ensure that drivers that call into the qcom_scm driver are also built as modules. While not ideal in some cases its the only safe way I can find to avoid build errors

Re: [RFC PATCH v3 5/8] vfio/type1: VFIO_IOMMU_ENABLE_IOPF

2021-05-18 Thread Alex Williamson
On Fri, 9 Apr 2021 11:44:17 +0800 Shenming Lu wrote: > Since enabling IOPF for devices may lead to a slow ramp up of performance, > we add an ioctl VFIO_IOMMU_ENABLE_IOPF to make it configurable. And the > IOPF enabling of a VFIO device includes setting IOMMU_DEV_FEAT_IOPF and > registering the

Re: [RFC PATCH v3 0/8] Add IOPF support for VFIO passthrough

2021-05-18 Thread Alex Williamson
On Fri, 9 Apr 2021 11:44:12 +0800 Shenming Lu wrote: > Hi, > > Requesting for your comments and suggestions. :-) > > The static pinning and mapping problem in VFIO and possible solutions > have been discussed a lot [1, 2]. One of the solutions is to add I/O > Page Fault support for VFIO

Re: [RFC PATCH v3 6/8] vfio/type1: No need to statically pin and map if IOPF enabled

2021-05-18 Thread Alex Williamson
On Fri, 9 Apr 2021 11:44:18 +0800 Shenming Lu wrote: > If IOPF enabled for the VFIO container, there is no need to statically > pin and map the entire DMA range, we can do it on demand. And unmap > according to the IOPF mapped bitmap when removing vfio_dma. > > Note that we still mark all pages

Re: [RFC PATCH v3 3/8] vfio/type1: Add an MMU notifier to avoid pinning

2021-05-18 Thread Alex Williamson
On Fri, 9 Apr 2021 11:44:15 +0800 Shenming Lu wrote: > To avoid pinning pages when they are mapped in IOMMU page tables, we > add an MMU notifier to tell the addresses which are no longer valid > and try to unmap them. > > Signed-off-by: Shenming Lu > --- > drivers/vfio/vfio_iommu_type1.c |

Re: [RFC PATCH v3 4/8] vfio/type1: Pre-map more pages than requested in the IOPF handling

2021-05-18 Thread Alex Williamson
On Fri, 9 Apr 2021 11:44:16 +0800 Shenming Lu wrote: > To optimize for fewer page fault handlings, we can pre-map more pages > than requested at once. > > Note that IOPF_PREMAP_LEN is just an arbitrary value for now, which we > could try further tuning. I'd prefer that the series introduced

Re: [RFC PATCH v3 8/8] vfio: Add nested IOPF support

2021-05-18 Thread Alex Williamson
On Fri, 9 Apr 2021 11:44:20 +0800 Shenming Lu wrote: > To set up nested mode, drivers such as vfio_pci need to register a > handler to receive stage/level 1 faults from the IOMMU, but since > currently each device can only have one iommu dev fault handler, > and if stage 2 IOPF is already

Re: [RFC PATCH v3 1/8] iommu: Evolve the device fault reporting framework

2021-05-18 Thread Alex Williamson
On Fri, 9 Apr 2021 11:44:13 +0800 Shenming Lu wrote: > This patch follows the discussion here: > > https://lore.kernel.org/linux-acpi/YAaxjmJW+ZMvrhac@myrica/ > > Besides SVA/vSVA, such as VFIO may also enable (2nd level) IOPF to remove > pinning restriction. In order to better support more

Re: [RFC PATCH v3 2/8] vfio/type1: Add a page fault handler

2021-05-18 Thread Alex Williamson
On Fri, 9 Apr 2021 11:44:14 +0800 Shenming Lu wrote: > VFIO manages the DMA mapping itself. To support IOPF (on-demand paging) > for VFIO (IOMMU capable) devices, we add a VFIO page fault handler to > serve the reported page faults from the IOMMU driver. > > Signed-off-by: Shenming Lu > --- >

Re: [RFC PATCH v3 7/8] vfio/type1: Add selective DMA faulting support

2021-05-18 Thread Alex Williamson
On Fri, 9 Apr 2021 11:44:19 +0800 Shenming Lu wrote: > Some devices only allow selective DMA faulting. Similar to the selective > dirty page tracking, the vendor driver can call vfio_pin_pages() to > indicate the non-faultable scope, we add a new struct vfio_range to > record it, then when the

Re: [PATCH 1/1] dma-contiguous: return early for dt case in dma_contiguous_reserve

2021-05-18 Thread Robin Murphy
On 2021-05-18 12:28, Dong Aisheng wrote: dma_contiguous_reserve() aims to support cmdline case for CMA memory reserve. But if users define reserved memory in DT, 'dma_contiguous_default_area' will not be 0, then it's meaningless to continue to run dma_contiguous_reserve(). So we return early if

[PATCH] dma debug: report -EEXIST errors in add_dma_entry

2021-05-18 Thread Hamza Mahfooz
Since, overlapping mappings are not supported by the DMA API we should report an error if active_cacheline_insert returns -EEXIST. Suggested-by: Dan Williams Signed-off-by: Hamza Mahfooz --- kernel/dma/debug.c | 6 ++ 1 file changed, 2 insertions(+), 4 deletions(-) diff --git

[PATCH 1/1] dma-contiguous: return early for dt case in dma_contiguous_reserve

2021-05-18 Thread Dong Aisheng
dma_contiguous_reserve() aims to support cmdline case for CMA memory reserve. But if users define reserved memory in DT, 'dma_contiguous_default_area' will not be 0, then it's meaningless to continue to run dma_contiguous_reserve(). So we return early if detect 'dma_contiguous_default_area' is

Re: [PATCH v3] iommu/iova: put free_iova_mem() outside of spinlock iova_rbtree_lock

2021-05-18 Thread Joerg Roedel
On Tue, May 18, 2021 at 11:08:47AM +0200, Joerg Roedel wrote: > Looks good to me, but I'll wait for Robins opinion before applying. Nevermind, just found the new version which Robin already acked. ___ iommu mailing list iommu@lists.linux-foundation.org

Re: [PATCH v3] iommu/iova: put free_iova_mem() outside of spinlock iova_rbtree_lock

2021-05-18 Thread Robin Murphy
On 2021-05-18 10:08, Joerg Roedel wrote: On Mon, Apr 19, 2021 at 03:13:35PM +0800, chenxiang wrote: From: Xiang Chen It is not necessary to put free_iova_mem() inside of spinlock/unlock iova_rbtree_lock which only leads to more completion for the spinlock. It has a small promote on the

Re: [PATCH v3] iommu/iova: put free_iova_mem() outside of spinlock iova_rbtree_lock

2021-05-18 Thread chenxiang (M)
Hi Joerg, 在 2021/5/18 17:08, Joerg Roedel 写道: On Mon, Apr 19, 2021 at 03:13:35PM +0800, chenxiang wrote: From: Xiang Chen It is not necessary to put free_iova_mem() inside of spinlock/unlock iova_rbtree_lock which only leads to more completion for the spinlock. It has a small promote on the

Re: [PATCH -next] iommu/virtio: Add missing MODULE_DEVICE_TABLE

2021-05-18 Thread Joerg Roedel
On Sat, May 08, 2021 at 11:14:51AM +0800, Bixuan Cui wrote: > This patch adds missing MODULE_DEVICE_TABLE definition which generates > correct modalias for automatic loading of this driver when it is built > as an external module. > > Reported-by: Hulk Robot > Signed-off-by: Bixuan Cui > --- >

Re: [PATCH 1/4] iommu/amd: Fix wrong parentheses on page-specific invalidations

2021-05-18 Thread Joerg Roedel
On Sat, May 01, 2021 at 11:59:56PM -0700, Nadav Amit wrote: > From: Nadav Amit > > The logic to determine the mask of page-specific invalidations was > tested in userspace. As the code was copied into the kernel, the > parentheses were mistakenly set in the wrong place, resulting in the > wrong

Re: [PATCH] iommu/amd: Clear DMA ops when switching domain

2021-05-18 Thread Joerg Roedel
On Thu, Apr 22, 2021 at 11:42:19AM +0200, Jean-Philippe Brucker wrote: > Since commit 08a27c1c3ecf ("iommu: Add support to change default domain > of an iommu group") a user can switch a device between IOMMU and direct > DMA through sysfs. This doesn't work for AMD IOMMU at the moment because >

Re: [PATCH v3] iommu/iova: put free_iova_mem() outside of spinlock iova_rbtree_lock

2021-05-18 Thread Joerg Roedel
On Mon, Apr 19, 2021 at 03:13:35PM +0800, chenxiang wrote: > From: Xiang Chen > > It is not necessary to put free_iova_mem() inside of spinlock/unlock > iova_rbtree_lock which only leads to more completion for the spinlock. > It has a small promote on the performance after the change. And also >

Re: [PATCH v4 2/8] iommu/dma: Introduce generic helper to retrieve RMR info

2021-05-18 Thread Joerg Roedel
On Thu, May 13, 2021 at 02:45:44PM +0100, Shameer Kolothum wrote: > +/** > + * struct iommu_rmr - Reserved Memory Region details per IOMMU > + * @list: Linked list pointers to hold RMR region info > + * @base_address: base address of Reserved Memory Region > + * @length: length of memory region >

Re: [PATCH v6 00/15] Restricted DMA

2021-05-18 Thread Claire Chang
v7: https://lore.kernel.org/patchwork/cover/1431031/ On Mon, May 10, 2021 at 5:50 PM Claire Chang wrote: > > From: Claire Chang > > This series implements mitigations for lack of DMA access control on > systems without an IOMMU, which could result in the DMA accessing the > system memory at

Re: [PATCH v7 04/15] swiotlb: Add restricted DMA pool initialization

2021-05-18 Thread Claire Chang
I didn't move this to a separate file because I feel it might be confusing for swiotlb_alloc/free (and need more functions to be non-static). Maybe instead of moving to a separate file, we can try to come up with a better naming? ___ iommu mailing list

Re: [PATCH v7 05/15] swiotlb: Add a new get_io_tlb_mem getter

2021-05-18 Thread Claire Chang
Still keep this function because directly using dev->dma_io_tlb_mem will cause issues for memory allocation for existing devices. The pool can't support atomic coherent allocation so we need to distinguish the per device pool and the default pool in swiotlb_alloc.

[PATCH v7 15/15] of: Add plumbing for restricted DMA pool

2021-05-18 Thread Claire Chang
If a device is not behind an IOMMU, we look up the device node and set up the restricted DMA when the restricted-dma-pool is presented. Signed-off-by: Claire Chang --- drivers/of/address.c| 25 + drivers/of/device.c | 3 +++ drivers/of/of_private.h | 5 + 3

[PATCH v7 14/15] dt-bindings: of: Add restricted DMA pool

2021-05-18 Thread Claire Chang
Introduce the new compatible string, restricted-dma-pool, for restricted DMA. One can specify the address and length of the restricted DMA memory region by restricted-dma-pool in the reserved-memory node. Signed-off-by: Claire Chang --- .../reserved-memory/reserved-memory.txt | 27

[PATCH v7 13/15] dma-direct: Allocate memory from restricted DMA pool if available

2021-05-18 Thread Claire Chang
The restricted DMA pool is preferred if available. The restricted DMA pools provide a basic level of protection against the DMA overwriting buffer contents at unexpected times. However, to protect against general data leakage and system memory corruption, the system needs to provide a way to lock

[PATCH v7 12/15] swiotlb: Add restricted DMA alloc/free support.

2021-05-18 Thread Claire Chang
Add the functions, swiotlb_{alloc,free} to support the memory allocation from restricted DMA pool. Signed-off-by: Claire Chang --- include/linux/swiotlb.h | 4 kernel/dma/swiotlb.c| 35 +-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git

[PATCH v7 11/15] dma-direct: Add a new wrapper __dma_direct_free_pages()

2021-05-18 Thread Claire Chang
Add a new wrapper __dma_direct_free_pages() that will be useful later for swiotlb_free(). Signed-off-by: Claire Chang --- kernel/dma/direct.c | 14 ++ 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index

[PATCH v7 10/15] swiotlb: Refactor swiotlb_tbl_unmap_single

2021-05-18 Thread Claire Chang
Add a new function, release_slots, to make the code reusable for supporting different bounce buffer pools, e.g. restricted DMA pool. Signed-off-by: Claire Chang --- kernel/dma/swiotlb.c | 35 --- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git

[PATCH v7 09/15] swiotlb: Move alloc_size to find_slots

2021-05-18 Thread Claire Chang
Move the maintenance of alloc_size to find_slots for better code reusability later. Signed-off-by: Claire Chang --- kernel/dma/swiotlb.c | 10 +- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 95f482c4408c..2ec6711071de

[PATCH v7 08/15] swiotlb: Bounce data from/to restricted DMA pool if available

2021-05-18 Thread Claire Chang
Regardless of swiotlb setting, the restricted DMA pool is preferred if available. The restricted DMA pools provide a basic level of protection against the DMA overwriting buffer contents at unexpected times. However, to protect against general data leakage and system memory corruption, the system

[PATCH v7 07/15] swiotlb: Update is_swiotlb_active to add a struct device argument

2021-05-18 Thread Claire Chang
Update is_swiotlb_active to add a struct device argument. This will be useful later to allow for restricted DMA pool. Signed-off-by: Claire Chang --- drivers/gpu/drm/i915/gem/i915_gem_internal.c | 2 +- drivers/gpu/drm/nouveau/nouveau_ttm.c| 2 +- drivers/pci/xen-pcifront.c

[PATCH v7 05/15] swiotlb: Add a new get_io_tlb_mem getter

2021-05-18 Thread Claire Chang
Add a new getter, get_io_tlb_mem, to help select the io_tlb_mem struct. The restricted DMA pool is preferred if available. Signed-off-by: Claire Chang --- include/linux/swiotlb.h | 11 +++ 1 file changed, 11 insertions(+) diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h

[PATCH v7 06/15] swiotlb: Update is_swiotlb_buffer to add a struct device argument

2021-05-18 Thread Claire Chang
Update is_swiotlb_buffer to add a struct device argument. This will be useful later to allow for restricted DMA pool. Signed-off-by: Claire Chang --- drivers/iommu/dma-iommu.c | 12 ++-- drivers/xen/swiotlb-xen.c | 2 +- include/linux/swiotlb.h | 6 +++--- kernel/dma/direct.c

[PATCH v7 04/15] swiotlb: Add restricted DMA pool initialization

2021-05-18 Thread Claire Chang
Add the initialization function to create restricted DMA pools from matching reserved-memory nodes. Signed-off-by: Claire Chang --- include/linux/device.h | 4 +++ include/linux/swiotlb.h | 3 +- kernel/dma/swiotlb.c| 76 + 3 files changed, 82

[PATCH v7 03/15] swiotlb: Add DMA_RESTRICTED_POOL

2021-05-18 Thread Claire Chang
Add a new kconfig symbol, DMA_RESTRICTED_POOL, for restricted DMA pool. Signed-off-by: Claire Chang --- kernel/dma/Kconfig | 14 ++ 1 file changed, 14 insertions(+) diff --git a/kernel/dma/Kconfig b/kernel/dma/Kconfig index 77b405508743..3e961dc39634 100644 --- a/kernel/dma/Kconfig

[PATCH v7 02/15] swiotlb: Refactor swiotlb_create_debugfs

2021-05-18 Thread Claire Chang
Split the debugfs creation to make the code reusable for supporting different bounce buffer pools, e.g. restricted DMA pool. Signed-off-by: Claire Chang --- kernel/dma/swiotlb.c | 25 +++-- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/kernel/dma/swiotlb.c

[PATCH v7 01/15] swiotlb: Refactor swiotlb init functions

2021-05-18 Thread Claire Chang
Add a new function, swiotlb_init_io_tlb_mem, for the io_tlb_mem struct initialization to make the code reusable. Note that we now also call set_memory_decrypted in swiotlb_init_with_tbl. Signed-off-by: Claire Chang --- kernel/dma/swiotlb.c | 51 ++-- 1

[PATCH v7 00/15] Restricted DMA

2021-05-18 Thread Claire Chang
This series implements mitigations for lack of DMA access control on systems without an IOMMU, which could result in the DMA accessing the system memory at unexpected times and/or unexpected addresses, possibly leading to data leakage or corruption. For example, we plan to use the PCI-e bus for