Re: [PATCH v2] iommu/vt-d: calculate mask for non-aligned flushes

2022-03-28 Thread Lu Baolu
Hi David, On 2022/3/22 14:35, David Stevens wrote: From: David Stevens Calculate the appropriate mask for non-size-aligned page selective invalidation. Since psi uses the mask value to mask out the lower order bits of the target address, properly flushing the iotlb requires using a mask value

Re: [PATCH RFC 10/11] iommu: Make IOPF handling framework generic

2022-03-21 Thread Lu Baolu
On 2022/3/21 20:50, Jason Gunthorpe wrote: On Sun, Mar 20, 2022 at 02:40:29PM +0800, Lu Baolu wrote: +static enum iommu_page_response_code +iommu_sva_handle_iopf(struct iommu_fault *fault, void *data) +{ + vm_fault_t ret; + struct mm_struct *mm; + struct vm_area_struct *vma

Re: [PATCH RFC 10/11] iommu: Make IOPF handling framework generic

2022-03-21 Thread Lu Baolu
On 2022/3/21 19:39, Jean-Philippe Brucker wrote: On Sun, Mar 20, 2022 at 02:40:29PM +0800, Lu Baolu wrote: The existing IOPF handling framework only handles the I/O page faults for SVA. Ginven that we are able to link iommu domain with each I/O page fault, we can now make the I/O page fault

Re: [PATCH RFC 10/11] iommu: Make IOPF handling framework generic

2022-03-21 Thread Lu Baolu
On 2022/3/21 20:43, Jason Gunthorpe wrote: On Mon, Mar 21, 2022 at 11:42:16AM +, Jean-Philippe Brucker wrote: I tend to disagree with that last part. The fault is caused by a specific device accessing shared page tables. We should keep that device information throughout the fault handling,

Re: [PATCH RFC 09/11] iommu: Add iommu_get_domain_for_dev_pasid()

2022-03-21 Thread Lu Baolu
On 2022/3/21 20:40, Jason Gunthorpe wrote: On Sun, Mar 20, 2022 at 02:40:28PM +0800, Lu Baolu wrote: @@ -3098,7 +3101,16 @@ int iommu_attach_device_pasid(struct iommu_domain *domain, if (iommu_group_device_count(group) != 1) goto out_unlock; + xa_lock(>pasid_ar

Re: [PATCH RFC 06/11] iommu/sva: Use attach/detach_pasid_dev in SVA interfaces

2022-03-21 Thread Lu Baolu
On 2022/3/21 20:05, Jason Gunthorpe wrote: On Sun, Mar 20, 2022 at 02:40:25PM +0800, Lu Baolu wrote: +/** + * iommu_sva_bind_device() - Bind a process address space to a device + * @dev: the device + * @mm: the mm to bind, caller must hold a reference to it + * @drvdata: opaque data pointer

Re: [PATCH RFC 06/11] iommu/sva: Use attach/detach_pasid_dev in SVA interfaces

2022-03-21 Thread Lu Baolu
On 2022/3/21 19:33, Jean-Philippe Brucker wrote: On Sun, Mar 20, 2022 at 02:40:25PM +0800, Lu Baolu wrote: diff --git a/drivers/iommu/iommu-sva-lib.c b/drivers/iommu/iommu-sva-lib.c index 106506143896..47cf98e661ff 100644 --- a/drivers/iommu/iommu-sva-lib.c +++ b/drivers/iommu/iommu-sva-lib.c

Re: [PATCH RFC 04/11] iommu/vt-d: Add SVA domain support

2022-03-21 Thread Lu Baolu
On 2022/3/21 19:56, Jason Gunthorpe wrote: On Sun, Mar 20, 2022 at 02:40:23PM +0800, Lu Baolu wrote: Add support for SVA domain allocation and provide an SVA-specific iommu_domain_ops. Signed-off-by: Lu Baolu include/linux/intel-iommu.h | 1 + drivers/iommu/intel/iommu.c | 12

Re: [PATCH RFC 02/11] iommu: Add iommu_domain type for SVA

2022-03-21 Thread Lu Baolu
On 2022/3/21 19:47, Jason Gunthorpe wrote: On Sun, Mar 20, 2022 at 02:40:21PM +0800, Lu Baolu wrote: Add a new iommu domain type IOMMU_DOMAIN_SVA to represent an I/O page table which is shared from CPU host VA. Add a sva_cookie field in the iommu_domain structure to save the mm_struct which

Re: [PATCH RFC 01/11] iommu: Add pasid_bits field in struct dev_iommu

2022-03-21 Thread Lu Baolu
On 2022/3/22 8:26, Tian, Kevin wrote: From: Lu Baolu Sent: Monday, March 21, 2022 6:22 PM - if (features >= 0) + if (features >= 0) { info->pasid_supported = fea

Re: [PATCH RFC 01/11] iommu: Add pasid_bits field in struct dev_iommu

2022-03-21 Thread Lu Baolu
On 2022/3/21 19:22, Jean-Philippe Brucker wrote: Hi Baolu, On Sun, Mar 20, 2022 at 02:40:20PM +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 627a3ed5ee8f..8e262210b5ad 100644 --- a/drivers/iommu/arm/arm-smmu

Re: [PATCH RFC 06/11] iommu/sva: Use attach/detach_pasid_dev in SVA interfaces

2022-03-21 Thread Lu Baolu
On 2022/3/21 16:04, Tian, Kevin wrote: From: Lu Baolu Sent: Sunday, March 20, 2022 2:40 PM +struct iommu_sva * +iommu_sva_bind_device(struct device *dev, struct mm_struct *mm, void *drvdata) +{ + int ret = -EINVAL; + struct iommu_sva *handle; + struct iommu_domain *domain

Re: [PATCH RFC 04/11] iommu/vt-d: Add SVA domain support

2022-03-21 Thread Lu Baolu
On 2022/3/21 15:45, Tian, Kevin wrote: From: Lu Baolu Sent: Sunday, March 20, 2022 2:40 PM Add support for SVA domain allocation and provide an SVA-specific iommu_domain_ops. Signed-off-by: Lu Baolu --- include/linux/intel-iommu.h | 1 + drivers/iommu/intel/iommu.c | 12

Re: [PATCH RFC 03/11] iommu: Add attach/detach_dev_pasid domain ops

2022-03-21 Thread Lu Baolu
On 2022/3/21 15:13, Tian, Kevin wrote: From: Lu Baolu Sent: Sunday, March 20, 2022 2:40 PM Attaching an IOMMU domain to a PASID of a device is a generic operation for modern IOMMU drivers which support PASID-granular DMA address translation. Currently visible usage scenarios include

Re: [PATCH RFC 02/11] iommu: Add iommu_domain type for SVA

2022-03-21 Thread Lu Baolu
On 2022/3/21 15:06, Tian, Kevin wrote: From: Lu Baolu Sent: Sunday, March 20, 2022 2:40 PM Add a new iommu domain type IOMMU_DOMAIN_SVA to represent an I/O page table which is shared from CPU host VA. Add a sva_cookie field in the iommu_domain structure to save the mm_struct which represent

Re: [PATCH RFC 01/11] iommu: Add pasid_bits field in struct dev_iommu

2022-03-21 Thread Lu Baolu
On 2022/3/21 15:01, Tian, Kevin wrote: From: Lu Baolu Sent: Sunday, March 20, 2022 2:40 PM Use this field to save the pasid/ssid bits that a device is able to support with its IOMMU hardware. It is a generic attribute of a device and lifting it into the per-device dev_iommu struct makes

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

2022-03-20 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 --- drivers/iommu/{iommu-sva-lib.h => iommu-sva.h} | 0 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 2 +- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c

[PATCH RFC 10/11] iommu: Make IOPF handling framework generic

2022-03-20 Thread Lu Baolu
The existing IOPF handling framework only handles the I/O page faults for SVA. Ginven that we are able to link iommu domain with each I/O page fault, we can now make the I/O page fault handling framework more general for more types of page faults. Signed-off-by: Lu Baolu --- include/linux

[PATCH RFC 09/11] iommu: Add iommu_get_domain_for_dev_pasid()

2022-03-20 Thread Lu Baolu
. Signed-off-by: Lu Baolu --- include/linux/iommu.h | 8 drivers/iommu/iommu.c | 31 +++ 2 files changed, 39 insertions(+) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 47c9aa5aa9c8..803e7b07605e 100644 --- a/include/linux/iommu.h +++ b

[PATCH RFC 08/11] iommu: Handle IO page faults directly

2022-03-20 Thread Lu Baolu
Directly call the IO page fault handler in iommu_report_device_fault() unless the device driver registered its own page fault handler. There is no need to explicitly register the fault handler in IOMMU drivers. Signed-off-by: Lu Baolu --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 13

[PATCH RFC 07/11] iommu: Remove SVA related callbacks from iommu ops

2022-03-20 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 --- include/linux/intel-iommu.h | 4 -- include/linux/iommu.h | 8 --- drivers

[PATCH RFC 06/11] iommu/sva: Use attach/detach_pasid_dev in SVA interfaces

2022-03-20 Thread Lu Baolu
interfaces implementation by using the attach/detach_pasid_dev ops and align them with the concept of the 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 | 46 +--- drivers/iommu

[PATCH RFC 05/11] arm-smmu-v3/sva: Add SVA domain support

2022-03-20 Thread Lu Baolu
Add support for SVA domain allocation and provide an SVA-specific iommu_domain_ops. Signed-off-by: Lu Baolu --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 14 ++ .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 45 +++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 13

[PATCH RFC 04/11] iommu/vt-d: Add SVA domain support

2022-03-20 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 | 1 + drivers/iommu/intel/iommu.c | 12 drivers/iommu/intel/svm.c | 34 ++ 3 files changed, 47 insertions

[PATCH RFC 03/11] iommu: Add attach/detach_dev_pasid domain ops

2022-03-20 Thread Lu Baolu
of common domain ops for this purpose and implements a couple of wrapper helpers for in-kernel usage. Signed-off-by: Lu Baolu --- include/linux/iommu.h | 22 ++ drivers/iommu/iommu.c | 41 + 2 files changed, 63 insertions(+) diff --git

[PATCH RFC 02/11] iommu: Add iommu_domain type for SVA

2022-03-20 Thread Lu Baolu
Add a new iommu domain type IOMMU_DOMAIN_SVA to represent an I/O page table which is shared from CPU host VA. Add a sva_cookie field in the iommu_domain structure to save the mm_struct which represent the CPU memory page table. Signed-off-by: Lu Baolu --- include/linux/iommu.h | 6 ++ 1

[PATCH RFC 01/11] iommu: Add pasid_bits field in struct dev_iommu

2022-03-20 Thread Lu Baolu
which suports PASID related features should set this field before features are enabled on the devices. Signed-off-by: Lu Baolu --- include/linux/iommu.h | 1 + drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 1 + drivers/iommu/intel/iommu.c | 5 - 3 files

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

2022-03-20 Thread Lu Baolu
, baolu Lu Baolu (11): iommu: Add pasid_bits field in struct dev_iommu iommu: Add iommu_domain type for SVA iommu: Add attach/detach_dev_pasid domain ops iommu/vt-d: Add SVA domain support arm-smmu-v3/sva: Add SVA domain support iommu/sva: Use attach/detach_pasid_dev in SVA interfaces

Re: [PATCH v2 5/8] iommu: Add PASID support for DMA mapping API users

2022-03-18 Thread Lu Baolu
On 2022/3/15 13:07, Jacob Pan wrote: DMA mapping API is the de facto standard for in-kernel DMA. It operates on a per device/RID basis which is not PASID-aware. Some modern devices such as Intel Data Streaming Accelerator, PASID is required for certain work submissions. To allow such devices

Re: [PATCH v2 2/8] iommu: Add attach/detach_dev_pasid domain ops

2022-03-18 Thread Lu Baolu
On 2022/3/15 19:49, Tian, Kevin wrote: From: Jean-Philippe Brucker Sent: Tuesday, March 15, 2022 7:27 PM On Mon, Mar 14, 2022 at 10:07:06PM -0700, Jacob Pan wrote: From: Lu Baolu An IOMMU domain represents an address space which can be attached by devices that perform DMA within a domain

Re: [PATCH v2 2/8] iommu: Add attach/detach_dev_pasid domain ops

2022-03-18 Thread Lu Baolu
On 2022/3/15 13:07, Jacob Pan wrote: From: Lu Baolu An IOMMU domain represents an address space which can be attached by devices that perform DMA within a domain. However, for platforms with PASID capability the domain attachment needs be handled at device+PASID level. There can be multiple

Re: [PATCH 1/2] agp/intel: Use per device iommu check

2022-03-07 Thread Lu Baolu
On 2022/2/11 11:05, Lu Baolu wrote: The IOMMU subsystem has already provided an interface to query whether the IOMMU hardware is enabled for a specific device. This changes the check from Intel specific intel_iommu_gfx_mapped (globally exported by the Intel IOMMU driver) to probing the presence

[PATCH v8 11/11] iommu: Remove iommu group changes notifier

2022-03-07 Thread Lu Baolu
The iommu group changes notifer is not referenced in the tree. Remove it to avoid dead code. Suggested-by: Christoph Hellwig Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe --- include/linux/iommu.h | 23 - drivers/iommu/iommu.c | 75

[PATCH v8 10/11] vfio: Remove iommu group notifier

2022-03-07 Thread Lu Baolu
-by: Lu Baolu Reviewed-by: Jason Gunthorpe Acked-by: Alex Williamson --- drivers/vfio/vfio.c | 147 1 file changed, 147 deletions(-) diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index e0df2bc692b2..dd3fac0d6bc9 100644 --- a/drivers/vfio/vfio.c

[PATCH v8 09/11] vfio: Delete the unbound_list

2022-03-07 Thread Lu Baolu
_group_dev() returns, so simply delete the unbound_list entirely. Reviewed-by: Chaitanya Kulkarni Signed-off-by: Jason Gunthorpe Signed-off-by: Lu Baolu Acked-by: Alex Williamson --- drivers/vfio/vfio.c | 74 ++--- 1 file changed, 2 insertions(+), 72 dele

[PATCH v8 08/11] vfio: Remove use of vfio_group_viable()

2022-03-07 Thread Lu Baolu
The only remaining reference is in GROUP_GET_STATUS, which could be called at any time when group fd is valid. Here we just replace the vfio_group_viable() by directly calling IOMMU core to get viability status. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe Acked-by: Alex Williamson --- dri

[PATCH v8 07/11] vfio: Set DMA ownership for VFIO devices

2022-03-07 Thread Lu Baolu
like what we have done in the pcieport driver. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe Acked-by: Alex Williamson --- drivers/vfio/fsl-mc/vfio_fsl_mc.c | 1 + drivers/vfio/pci/vfio_pci.c | 1 + drivers/vfio/platform/vfio_amba.c | 1 + drivers/vfio/platform

[PATCH v8 06/11] PCI: portdrv: Set driver_managed_dma

2022-03-07 Thread Lu Baolu
you can't find ioremap() or similar calls. It's tolerant to userspace possibly also touching the same MMIO registers via P2P DMA access. Suggested-by: Jason Gunthorpe Suggested-by: Kevin Tian Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe Acked-by: Bjorn Helgaas --- driver

[PATCH v8 05/11] PCI: pci_stub: Set driver_managed_dma

2022-03-07 Thread Lu Baolu
by the admin to block driver binding after applying the DMA ownership to VFIO. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe Acked-by: Bjorn Helgaas --- drivers/pci/pci-stub.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/pci/pci-stub.c b/drivers/pci/pci-stub.c index e408099fea52

[PATCH v8 04/11] bus: platform, amba, fsl-mc, PCI: Add device DMA ownership management

2022-03-07 Thread Lu Baolu
-off-by: Lu Baolu Reviewed-by: Greg Kroah-Hartman Reviewed-by: Jason Gunthorpe --- include/linux/amba/bus.h| 8 include/linux/fsl/mc.h | 8 include/linux/pci.h | 8 include/linux/platform_device.h | 8 drivers/amba/bus.c

[PATCH v8 03/11] amba: Stop sharing platform_dma_configure()

2022-03-07 Thread Lu Baolu
Stop sharing platform_dma_configure() helper as they are about to have their own bus dma_configure callbacks. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe --- include/linux/platform_device.h | 2 -- drivers/amba/bus.c | 19 ++- drivers/base/platform.c

[PATCH v8 02/11] driver core: Add dma_cleanup callback in bus_type

2022-03-07 Thread Lu Baolu
with lockdown=integrity, can force the kernel to BUG. With this change, the bus driver could check and set the DMA ownership in driver binding process and fail on ownership conflicts. The DMA ownership should be released during driver unbinding. Signed-off-by: Lu Baolu Reviewed-by: Greg Kroah-Hartman

[PATCH v8 01/11] iommu: Add DMA ownership management interfaces

2022-03-07 Thread Lu Baolu
iommu_group *group); The device userspace assignment must be disallowed if the DMA owner claiming interface returns failure. Signed-off-by: Jason Gunthorpe Signed-off-by: Kevin Tian Signed-off-by: Lu Baolu --- include/linux/iommu.h | 31 + drivers/iommu/iommu.c | 153

[PATCH v8 00/11] Fix BUG_ON in vfio_iommu_group_notifier()

2022-03-07 Thread Lu Baolu
ers. This is based on next branch of linux-iommu tree: https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git and also available on github: https://github.com/LuBaolu/intel-iommu/commits/iommu-dma-ownership-v8 Best regards, baolu Jason Gunthorpe (1): vfio: Delete the unbound_list

Re: [PATCH v7 01/11] iommu: Add DMA ownership management interfaces

2022-03-07 Thread Lu Baolu
On 2022/3/7 20:42, Eric Auger wrote: Hi Lu, On 3/7/22 4:27 AM, Lu Baolu wrote: Hi Robin, On 3/4/22 10:10 PM, Robin Murphy wrote: On 2022-03-04 13:55, Eric Auger wrote: Hi Robin, On 3/4/22 1:22 PM, Robin Murphy wrote: On 2022-03-04 10:43, Lu Baolu wrote: Hi Eric, On 2022/3/4 18:34, Eric

Re: [PATCH v7 01/11] iommu: Add DMA ownership management interfaces

2022-03-06 Thread Lu Baolu
Hi Robin, On 3/4/22 10:10 PM, Robin Murphy wrote: On 2022-03-04 13:55, Eric Auger wrote: Hi Robin, On 3/4/22 1:22 PM, Robin Murphy wrote: On 2022-03-04 10:43, Lu Baolu wrote: Hi Eric, On 2022/3/4 18:34, Eric Auger wrote: I hit a WARN_ON() when unbinding an e1000e driver just after boot

Re: [PATCH v7 01/11] iommu: Add DMA ownership management interfaces

2022-03-04 Thread Lu Baolu
Hi Eric, On 2022/3/4 18:34, Eric Auger wrote: I hit a WARN_ON() when unbinding an e1000e driver just after boot: sudo modprobe -v vfio-pci echo vfio-pci | sudo tee -a /sys/bus/pci/devices/0004:01:00.0/driver_override vfio-pci echo 0004:01:00.0 | sudo tee -a  /sys/bus/pci/drivers/e1000e/unbind

Re: [PATCH 00/12] [PULL REQUEST] Intel IOMMU updates for Linux v5.18

2022-03-04 Thread Lu Baolu
Hi Joerg, On 2022/3/4 17:37, Joerg Roedel wrote: Hi Baolu, On Tue, Mar 01, 2022 at 10:01:47AM +0800, Lu Baolu wrote: This includes patches queued for v5.18. It includes: - [PATCH 1 ~ 11] Various cleanups, no intentional functional changes. - [PATCH 12] Enable ATS in SoC-integrated

Re: [PATCH v7 06/11] PCI: portdrv: Set driver_managed_dma

2022-02-28 Thread Lu Baolu
Hi Bjorn, On 3/1/22 3:56 AM, Bjorn Helgaas wrote: On Mon, Feb 28, 2022 at 08:50:51AM +0800, Lu Baolu wrote: If a switch lacks ACS P2P Request Redirect, a device below the switch can bypass the IOMMU and DMA directly to other devices below the switch, so all the downstream devices must

[PATCH 12/12] iommu/vt-d: Enable ATS for the devices in SATC table

2022-02-28 Thread Lu Baolu
as it becomes dead code now. Signed-off-by: Yian Chen Link: https://lore.kernel.org/r/20220222185416.1722611-1-yian.c...@intel.com Signed-off-by: Lu Baolu --- include/linux/intel-iommu.h | 1 - drivers/iommu/intel/iommu.c | 40 +++-- 2 files changed, 38 insertions(+), 3

[PATCH 11/12] iommu/vt-d: Remove unused function intel_svm_capable()

2022-02-28 Thread Lu Baolu
From: YueHaibing This is unused since commit 4048377414162 ("iommu/vt-d: Use iommu_sva_alloc(free)_pasid() helpers"). Signed-off-by: YueHaibing Link: https://lore.kernel.org/r/20220216113851.25004-1-yuehaib...@huawei.com Signed-off-by: Lu Baolu --- drivers/iommu/intel/svm.c | 5 ---

[PATCH 10/12] iommu/vt-d: Add missing "__init" for rmrr_sanity_check()

2022-02-28 Thread Lu Baolu
Bonelli Link: https://lore.kernel.org/r/20220210023141.9208-1-ma...@mebeim.net Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index f5b15bc20426..19562891d6ef 100644 --- a

[PATCH 09/12] iommu/vt-d: Move intel_iommu_ops to header file

2022-02-28 Thread Lu Baolu
://lore.kernel.org/r/20220207141240.8253-1-andriy.shevche...@linux.intel.com Signed-off-by: Lu Baolu --- include/linux/intel-iommu.h | 2 ++ drivers/iommu/intel/dmar.c | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h index

[PATCH 08/12] iommu/vt-d: Fix indentation of goto labels

2022-02-28 Thread Lu Baolu
Remove blanks before goto labels. Signed-off-by: Lu Baolu Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Link: https://lore.kernel.org/r/20220214025704.3184654-1-baolu...@linux.intel.com --- drivers/iommu/intel/iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions

[PATCH 07/12] iommu/vt-d: Remove unnecessary prototypes

2022-02-28 Thread Lu Baolu
Some prototypes in iommu.c are unnecessary. Delete them. Signed-off-by: Lu Baolu Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Link: https://lore.kernel.org/r/20220214025704.3184654-1-baolu...@linux.intel.com --- drivers/iommu/intel/iommu.c | 5 - 1 file changed, 5

[PATCH 06/12] iommu/vt-d: Remove unnecessary includes

2022-02-28 Thread Lu Baolu
Remove unnecessary include files and sort the remaining alphabetically. Signed-off-by: Lu Baolu Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Link: https://lore.kernel.org/r/20220214025704.3184654-1-baolu...@linux.intel.com --- drivers/iommu/intel/iommu.c | 34

[PATCH 05/12] iommu/vt-d: Remove DEFER_DEVICE_DOMAIN_INFO

2022-02-28 Thread Lu Baolu
for getting the private data and domain are also cleaned. Signed-off-by: Lu Baolu Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Link: https://lore.kernel.org/r/20220214025704.3184654-1-baolu...@linux.intel.com --- include/linux/intel-iommu.h | 2 - drivers/iommu/intel/debugfs.c | 3

[PATCH 04/12] iommu/vt-d: Remove domain and devinfo mempool

2022-02-28 Thread Lu Baolu
The domain and devinfo memory blocks are only allocated during device probe and released during remove. There's no hot-path context, hence no need for memory pools. Signed-off-by: Lu Baolu Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Link: https://lore.kernel.org/r

[PATCH 03/12] iommu/vt-d: Remove iova_cache_get/put()

2022-02-28 Thread Lu Baolu
These have been done in drivers/iommu/dma-iommu.c. Remove this duplicate code. Signed-off-by: Lu Baolu Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Link: https://lore.kernel.org/r/20220214025704.3184654-1-baolu...@linux.intel.com --- drivers/iommu/intel/iommu.c | 5 - 1

[PATCH 02/12] iommu/vt-d: Remove finding domain in dmar_insert_one_dev_info()

2022-02-28 Thread Lu Baolu
The Intel IOMMU driver has already converted to use default domain framework in iommu core. There's no need to find a domain for the device in the domain attaching path. Cleanup that code. Signed-off-by: Lu Baolu Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Link: https

[PATCH 01/12] iommu/vt-d: Remove intel_iommu::domains

2022-02-28 Thread Lu Baolu
The "domains" field of the intel_iommu structure keeps the mapping of domain_id to dmar_domain. This information is not used anywhere. Remove and cleanup it to avoid unnecessary memory consumption. Signed-off-by: Lu Baolu Reviewed-by: Christoph Hellwig Reviewed-by: Jason Gunthorpe Li

[PATCH 00/12] [PULL REQUEST] Intel IOMMU updates for Linux v5.18

2022-02-28 Thread Lu Baolu
(1): iommu/vt-d: Move intel_iommu_ops to header file Lu Baolu (8): iommu/vt-d: Remove intel_iommu::domains iommu/vt-d: Remove finding domain in dmar_insert_one_dev_info() iommu/vt-d: Remove iova_cache_get/put() iommu/vt-d: Remove domain and devinfo mempool iommu/vt-d: Remove

Re: [PATCH v6 00/11] Fix BUG_ON in vfio_iommu_group_notifier()

2022-02-27 Thread Lu Baolu
On 2/18/22 8:55 AM, Lu Baolu wrote: v6: - Refine comments and commit mesages. - Rename iommu_group_set_dma_owner() to iommu_group_claim_dma_owner(). - Rename iommu_device_use/unuse_kernel_dma() to iommu_device_use/unuse_default_domain(). - Remove unnecessary EXPORT_SYMBOL_GPL

[PATCH v7 11/11] iommu: Remove iommu group changes notifier

2022-02-27 Thread Lu Baolu
The iommu group changes notifer is not referenced in the tree. Remove it to avoid dead code. Suggested-by: Christoph Hellwig Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe --- include/linux/iommu.h | 23 - drivers/iommu/iommu.c | 75

[PATCH v7 10/11] vfio: Remove iommu group notifier

2022-02-27 Thread Lu Baolu
-by: Lu Baolu Reviewed-by: Jason Gunthorpe --- drivers/vfio/vfio.c | 147 1 file changed, 147 deletions(-) diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c index e0df2bc692b2..dd3fac0d6bc9 100644 --- a/drivers/vfio/vfio.c +++ b/drivers/vfio/vfio.c

[PATCH v7 09/11] vfio: Delete the unbound_list

2022-02-27 Thread Lu Baolu
_group_dev() returns, so simply delete the unbound_list entirely. Reviewed-by: Chaitanya Kulkarni Signed-off-by: Jason Gunthorpe Signed-off-by: Lu Baolu --- drivers/vfio/vfio.c | 74 ++--- 1 file changed, 2 insertions(+), 72 deletions(-) diff --git a/d

[PATCH v7 08/11] vfio: Remove use of vfio_group_viable()

2022-02-27 Thread Lu Baolu
The only remaining reference is in GROUP_GET_STATUS, which could be called at any time when group fd is valid. Here we just replace the vfio_group_viable() by directly calling IOMMU core to get viability status. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe --- drivers/vfio/vf

[PATCH v7 07/11] vfio: Set DMA ownership for VFIO devices

2022-02-27 Thread Lu Baolu
like what we have done in the pcieport driver. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe --- drivers/vfio/fsl-mc/vfio_fsl_mc.c | 1 + drivers/vfio/pci/vfio_pci.c | 1 + drivers/vfio/platform/vfio_amba.c | 1 + drivers/vfio/platform/vfio_platform.c | 1 + drivers

[PATCH v7 06/11] PCI: portdrv: Set driver_managed_dma

2022-02-27 Thread Lu Baolu
-by: Jason Gunthorpe Suggested-by: Kevin Tian Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe --- drivers/pci/pcie/portdrv_pci.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c index 35eca6277a96..6b2adb678c21 100644

[PATCH v7 05/11] PCI: pci_stub: Set driver_managed_dma

2022-02-27 Thread Lu Baolu
by the admin to block driver binding after applying the DMA ownership to VFIO. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe --- drivers/pci/pci-stub.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/pci/pci-stub.c b/drivers/pci/pci-stub.c index e408099fea52..d1f4c1ce7bd1 100644

[PATCH v7 04/11] bus: platform, amba, fsl-mc, PCI: Add device DMA ownership management

2022-02-27 Thread Lu Baolu
be solved. Cc: Greg Kroah-Hartman Cc: Bjorn Helgaas Cc: Stuart Yoder Cc: Laurentiu Tudor Signed-off-by: Lu Baolu Reviewed-by: Greg Kroah-Hartman Reviewed-by: Jason Gunthorpe --- include/linux/amba/bus.h| 8 include/linux/fsl/mc.h | 8 include/linux

[PATCH v7 03/11] amba: Stop sharing platform_dma_configure()

2022-02-27 Thread Lu Baolu
Stop sharing platform_dma_configure() helper as they are about to have their own bus dma_configure callbacks. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe --- include/linux/platform_device.h | 2 -- drivers/amba/bus.c | 19 ++- drivers/base/platform.c

[PATCH v7 02/11] driver core: Add dma_cleanup callback in bus_type

2022-02-27 Thread Lu Baolu
with lockdown=integrity, can force the kernel to BUG. With this change, the bus driver could check and set the DMA ownership in driver binding process and fail on ownership conflicts. The DMA ownership should be released during driver unbinding. Signed-off-by: Lu Baolu Reviewed-by: Greg Kroah-Hartman

[PATCH v7 01/11] iommu: Add DMA ownership management interfaces

2022-02-27 Thread Lu Baolu
iommu_group *group); The device userspace assignment must be disallowed if the DMA owner claiming interface returns failure. Signed-off-by: Jason Gunthorpe Signed-off-by: Kevin Tian Signed-off-by: Lu Baolu --- include/linux/iommu.h | 31 + drivers/iommu/iommu.c | 153

[PATCH v7 00/11] Fix BUG_ON in vfio_iommu_group_notifier()

2022-02-27 Thread Lu Baolu
bridge drivers. - Comments refinement. This is based on next branch of linux-iommu tree: https://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu.git and also available on github: https://github.com/LuBaolu/intel-iommu/commits/iommu-dma-ownership-v7 Best regards, baolu Jason Gunthorpe (1):

Re: [PATCH] iommu/vt-d: Add RPLS to quirk list to skip TE disabling

2022-02-24 Thread Lu Baolu
On 2/24/22 9:39 PM, Vivi, Rodrigo wrote: On Thu, 2022-02-24 at 13:42 +0800, Lu Baolu wrote: On 2/23/22 2:29 PM, Tejas Upadhyay wrote: The VT-d spec requires (10.4.4 Global Command Register, TE field) that: Hardware implementations supporting DMA draining must drain any in-flight DMA read

Re: [PATCH v2 08/11] iommu/vt-d: Fix indentation of goto labels

2022-02-24 Thread Lu Baolu
On 2/24/22 9:08 PM, Jason Gunthorpe wrote: On Mon, Feb 14, 2022 at 10:57:01AM +0800, Lu Baolu wrote: Remove blanks before goto labels. Signed-off-by: Lu Baolu drivers/iommu/intel/iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) It would be better to rework this function

Re: [PATCH v2 06/11] iommu/vt-d: Remove unnecessary includes

2022-02-24 Thread Lu Baolu
On 2/24/22 9:05 PM, Jason Gunthorpe wrote: On Mon, Feb 14, 2022 at 10:56:59AM +0800, Lu Baolu wrote: Remove unnecessary include files and sort the remaining alphabetically. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 34 +++--- 1 file changed, 7

Re: [PATCH v2 05/11] iommu/vt-d: Remove DEFER_DEVICE_DOMAIN_INFO

2022-02-24 Thread Lu Baolu
On 2/24/22 9:04 PM, Jason Gunthorpe wrote: On Mon, Feb 14, 2022 at 10:56:58AM +0800, Lu Baolu wrote: diff --git a/drivers/iommu/intel/debugfs.c b/drivers/iommu/intel/debugfs.c index db7a0ca73626..ed796eea4581 100644 --- a/drivers/iommu/intel/debugfs.c +++ b/drivers/iommu/intel/debugfs.c

Re: [PATCH v2 09/11] iommu/vt-d: Remove commented code

2022-02-24 Thread Lu Baolu
On 2/24/22 9:09 PM, Jason Gunthorpe wrote: On Mon, Feb 14, 2022 at 10:57:02AM +0800, Lu Baolu wrote: This removes unnecessary commented code. Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 10 +- 1 file changed, 1 insertion(+), 9 deletions(-) Assuming you don't want

Re: [PATCH] iommu/vt-d: Add RPLS to quirk list to skip TE disabling

2022-02-23 Thread Lu Baolu
On 2/23/22 2:29 PM, Tejas Upadhyay wrote: The VT-d spec requires (10.4.4 Global Command Register, TE field) that: Hardware implementations supporting DMA draining must drain any in-flight DMA read/write requests queued within the Root-Complex before completing the translation enable command and

Re: [PATCH v6 01/11] iommu: Add dma ownership management interfaces

2022-02-23 Thread Lu Baolu
On 2/24/22 1:16 PM, Lu Baolu wrote: Hi Robin and Jason, On 2/24/22 2:02 AM, Jason Gunthorpe wrote: On Wed, Feb 23, 2022 at 06:00:06PM +, Robin Murphy wrote: ...and equivalently just set owner_cnt directly to 0 here. I don't see a realistic use-case for any driver to claim the same group

Re: [PATCH v6 01/11] iommu: Add dma ownership management interfaces

2022-02-23 Thread Lu Baolu
On 2/24/22 2:00 AM, Robin Murphy wrote: On 2022-02-18 00:55, Lu Baolu wrote: [...] +/** + * iommu_group_claim_dma_owner() - Set DMA ownership of a group + * @group: The group. + * @owner: Caller specified pointer. Used for exclusive ownership. + * + * This is to support backward compatibility

Re: [PATCH v6 01/11] iommu: Add dma ownership management interfaces

2022-02-23 Thread Lu Baolu
Hi Robin and Jason, On 2/24/22 2:02 AM, Jason Gunthorpe wrote: On Wed, Feb 23, 2022 at 06:00:06PM +, Robin Murphy wrote: ...and equivalently just set owner_cnt directly to 0 here. I don't see a realistic use-case for any driver to claim the same group more than once, and allowing it in

Re: [PATCH v6 10/11] vfio: Remove iommu group notifier

2022-02-23 Thread Lu Baolu
Hi Alex, On 2/24/22 5:53 AM, Alex Williamson wrote: On Fri, 18 Feb 2022 08:55:20 +0800 Lu Baolu wrote: The iommu core and driver core have been enhanced to avoid unsafe driver binding to a live group after iommu_group_set_dma_owner(PRIVATE_USER) has been called. There's no need to register

Re: [PATCH v6 02/11] driver core: Add dma_cleanup callback in bus_type

2022-02-22 Thread Lu Baolu
On 2/23/22 7:53 AM, Jason Gunthorpe wrote: To spell it out, the scheme I'm proposing looks like this: Well, I already got this, it is what is in driver_or_DMA_API_token() that matters I think you are suggesting to do something like: if (!READ_ONCE(dev->driver) || ???) return

Re: [PATCH v6 02/11] driver core: Add dma_cleanup callback in bus_type

2022-02-21 Thread Lu Baolu
On 2/22/22 7:48 AM, Jason Gunthorpe wrote: since we should only care about ownership at probe, hotplug, and other places well outside critical fast-paths, I'm not sure we really need to keep track of that anyway - it can always be recalculated by walking the group->devices list, It has to be

[PATCH 1/1] iommu/vt-d: Fix double list_add when enabling VMD in scalable mode

2022-02-20 Thread Lu Baolu
mu/vt-d: Fix clearing real DMA device's scalable-mode context entries") Cc: sta...@vger.kernel.org # v5.14+ Signed-off-by: Adrian Huang Link: https://lore.kernel.org/r/20220216091307.703-1-adrianhuang0...@gmail.com Signed-off-by: Lu Baolu --- drivers/iommu/intel/iommu.c | 2 +- 1 file changed

[PATCH 0/1] iommu/vt-d: Fixes for v5.17-rc6

2022-02-20 Thread Lu Baolu
Hi Joerg, One fix is queued for v5.17. It aims to fix: - Kernel BUG() when VMD is enabled in scalable mode. Please consider it for the iommu/fix branch. Best regards, Lu Baolu Adrian Huang (1): iommu/vt-d: Fix double list_add when enabling VMD in scalable mode drivers/iommu/intel

Re: [PATCH v6 01/11] iommu: Add dma ownership management interfaces

2022-02-20 Thread Lu Baolu
On 2/19/22 3:31 PM, Christoph Hellwig wrote: The overall API and patch looks fine, but: + * iommu_group_dma_owner_claimed() - Query group dma ownership status + * @group: The group. + * + * This provides status query on a given group. It is racey and only for + * non-binding status reporting.

Re: [PATCH v6 00/11] Fix BUG_ON in vfio_iommu_group_notifier()

2022-02-20 Thread Lu Baolu
On 2/18/22 11:51 PM, Jason Gunthorpe wrote: On Fri, Feb 18, 2022 at 08:55:10AM +0800, Lu Baolu wrote: Hi folks, The iommu group is the minimal isolation boundary for DMA. Devices in a group can access each other's MMIO registers via peer to peer DMA and also need share the same I/O address

Re: [PATCH v2 1/1] iommu/vt-d: Fix list_add double add when enabling VMD and scalable mode

2022-02-20 Thread Lu Baolu
On 2/18/22 4:21 PM, Huang Adrian wrote: Another thing I am still concerned is about the context entry setup. What does the context entries look like for both VMD and subdevices after domain_context_mapping() being called? pasid_table in struct device_domain_info is NULL because the field

Re: [PATCH] iommu/vt-d: Enable ATS for the devices in SATC table

2022-02-17 Thread Lu Baolu
Hi Yian, On 2/17/22 3:36 AM, Yian Chen wrote: Starting from Intel VT-d v3.2, Intel platform BIOS can provide additional SATC table structure. SATC table includes a list of SoC integrated devices that support ATC (Address translation cache). Enabling ATC (via ATS capability) can be a functional

Re: [PATCH v2 1/1] iommu/vt-d: Fix list_add double add when enabling VMD and scalable mode

2022-02-17 Thread Lu Baolu
On 2/16/22 5:13 PM, Adrian Huang wrote: pci_real_dma_dev() in pci_for_each_dma_alias() gets the real dma device which is the VMD device :59:00.5. However, pte of the VMD device :59:00.5 has been configured during this message "pci :59:00.5: Adding to iommu group 42". So, the status

Re: [PATCH v5 00/14] Fix BUG_ON in vfio_iommu_group_notifier()

2022-02-17 Thread Lu Baolu
On 1/4/22 9:56 AM, Lu Baolu wrote: Hi folks, The iommu group is the minimal isolation boundary for DMA. Devices in a group can access each other's MMIO registers via peer to peer DMA and also need share the same I/O address space. Once the I/O address space is assigned to user control

[PATCH v6 01/11] iommu: Add dma ownership management interfaces

2022-02-17 Thread Lu Baolu
iommu_group *group); The device userspace assignment must be disallowed if the DMA owner claiming interface returns failure. Signed-off-by: Jason Gunthorpe Signed-off-by: Kevin Tian Signed-off-by: Lu Baolu --- include/linux/iommu.h | 31 + drivers/iommu/iommu.c | 158

[PATCH v6 08/11] vfio: Remove use of vfio_group_viable()

2022-02-17 Thread Lu Baolu
The only remaining reference is in GROUP_GET_STATUS, which could be called at any time when group fd is valid. Here we just replace the vfio_group_viable() by directly calling IOMMU core to get viability status. Signed-off-by: Lu Baolu --- drivers/vfio/vfio.c | 18 ++ 1 file c

[PATCH v6 03/11] amba: Stop sharing platform_dma_configure()

2022-02-17 Thread Lu Baolu
Stop sharing platform_dma_configure() helper as they are about to have their own bus dma_configure callbacks. Signed-off-by: Lu Baolu --- include/linux/platform_device.h | 2 -- drivers/amba/bus.c | 19 ++- drivers/base/platform.c | 3 +-- 3 files changed

[PATCH v6 11/11] iommu: Remove iommu group changes notifier

2022-02-17 Thread Lu Baolu
The iommu group changes notifer is not referenced in the tree. Remove it to avoid dead code. Suggested-by: Christoph Hellwig Signed-off-by: Lu Baolu --- include/linux/iommu.h | 23 - drivers/iommu/iommu.c | 75 --- 2 files changed, 98

[PATCH v6 10/11] vfio: Remove iommu group notifier

2022-02-17 Thread Lu Baolu
same MMIO registers via P2P DMA attacks? Conservatively if the driver maps an MMIO region at all, we can say that it fails the test. Signed-off-by: Lu Baolu --- drivers/vfio/vfio.c | 147 1 file changed, 147 deletions(-) diff --git a/drivers/vfi

<    1   2   3   4   5   6   7   8   9   10   >