Re: [PATCH v2 06/19] iommufd/viommu: Add IOMMU_VIOMMU_SET/UNSET_VDEV_ID ioctl

2025-05-06 Thread Nicolin Chen
On Tue, May 06, 2025 at 09:58:47AM -0300, Jason Gunthorpe wrote: > On Mon, May 05, 2025 at 07:53:44PM -0700, Nicolin Chen wrote: > > On Mon, May 05, 2025 at 02:08:07PM -0300, Jason Gunthorpe wrote: > > > On Wed, Apr 30, 2025 at 12:58:47AM -0700, Nicolin Chen wrote: > >

Re: [PATCH v2 06/19] iommufd/viommu: Add IOMMU_VIOMMU_SET/UNSET_VDEV_ID ioctl

2025-05-05 Thread Nicolin Chen
On Mon, May 05, 2025 at 02:08:07PM -0300, Jason Gunthorpe wrote: > On Wed, Apr 30, 2025 at 12:58:47AM -0700, Nicolin Chen wrote: > > > > ... and I just hit a problem with it - this is basically guest BDFn > > > and it works as long as I'm hotplugging the TEE-IO VF

Re: [PATCH v2 06/19] iommufd/viommu: Add IOMMU_VIOMMU_SET/UNSET_VDEV_ID ioctl

2025-04-30 Thread Nicolin Chen
On Wed, Apr 30, 2025 at 05:54:53PM +1000, Alexey Kardashevskiy wrote: > On 4/10/24 21:41, Jason Gunthorpe wrote: > > On Fri, Oct 04, 2024 at 02:32:28PM +1000, Alexey Kardashevskiy wrote: > > > > > > + __u32 __reserved; > > > > + __aligned_u64 vdev_id; > > I believe this ended up being

Re: [PATCH v2 3/7] iommu: Make iommu_dma_prepare_msi() into a generic operation

2025-02-27 Thread Nicolin Chen
On Thu, Feb 27, 2025 at 11:32:42AM -0400, Jason Gunthorpe wrote: > On Thu, Feb 27, 2025 at 11:21:28AM +, Robin Murphy wrote: > > All I'm saying is to hide the callback detail in the IOMMUFD code because > > being IOMMUFD modular is unique to IOMMUFD and not the rest of the core > > code's probl

Re: [PATCH v2 7/7] iommu: Turn iova_cookie to dma-iommu private pointer

2025-02-26 Thread Nicolin Chen
On Wed, Feb 26, 2025 at 01:36:10PM -0400, Jason Gunthorpe wrote: > On Tue, Feb 25, 2025 at 06:25:27PM -0800, Nicolin Chen wrote: > > On Fri, Feb 21, 2025 at 10:39:59AM -0400, Jason Gunthorpe wrote: > > > diff --git a/include/linux/iommu.h b/include/linux/iommu.h > >

Re: [PATCH v2 7/7] iommu: Turn iova_cookie to dma-iommu private pointer

2025-02-25 Thread Nicolin Chen
On Fri, Feb 21, 2025 at 10:39:59AM -0400, Jason Gunthorpe wrote: > diff --git a/include/linux/iommu.h b/include/linux/iommu.h > index 99dd72998cb7f7..082274e8ba6a3d 100644 > --- a/include/linux/iommu.h > +++ b/include/linux/iommu.h > @@ -1534,12 +1534,16 @@ void iommu_debugfs_setup(void); > static

[PATCH v2 1/7] genirq/msi: Store the IOMMU IOVA directly in msi_desc instead of iommu_cookie

2025-02-19 Thread Nicolin Chen
Gunthorpe Signed-off-by: Nicolin Chen --- include/linux/msi.h | 33 - drivers/iommu/dma-iommu.c | 28 +--- 2 files changed, 25 insertions(+), 36 deletions(-) diff --git a/include/linux/msi.h b/include/linux/msi.h index b10093c4d00e..fc

[PATCH v2 2/7] genirq/msi: Refactor iommu_dma_compose_msi_msg()

2025-02-19 Thread Nicolin Chen
patch, which allows multiple implementation options for iommu_dma_prepare_msi(). So, it does not make sense to have the iommu_dma_compose_msi_msg() in dma-iommu.c as it no longer provides the only iommu_dma_prepare_msi() implementation. Signed-off-by: Jason Gunthorpe Signed-off-by: Nicolin Chen

[PATCH v2 7/7] iommu: Turn iova_cookie to dma-iommu private pointer

2025-02-19 Thread Nicolin Chen
to use dma-iommu.c for sw_msi and still need iova_cookie. Suggested-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- include/linux/iommu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index e93d2e918599..99dd72998cb7 10

[PATCH v2 5/7] iommu: Turn fault_data to iommufd private pointer

2025-02-19 Thread Nicolin Chen
comments for readability. Signed-off-by: Nicolin Chen --- include/linux/iommu.h| 6 -- drivers/iommu/iommufd/fault.c| 2 +- drivers/iommu/iommufd/hw_pagetable.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/linux/iommu.h b/include/linux/

[PATCH v2 4/7] irqchip: Have CONFIG_IRQ_MSI_IOMMU be selected by irqchips that need it

2025-02-19 Thread Nicolin Chen
ff-by: Nicolin Chen --- drivers/iommu/Kconfig | 1 - drivers/irqchip/Kconfig | 4 kernel/irq/Kconfig | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/Kconfig b/drivers/iommu/Kconfig index ec1b5e32b972..5124e7431fe3 100644 --- a/drivers/iommu/Kconfig +++ b/dr

[PATCH v2 0/7] iommu: Add MSI mapping support with nested SMMU (Part-1 core)

2025-02-19 Thread Nicolin Chen
! Nicolin Jason Gunthorpe (5): genirq/msi: Store the IOMMU IOVA directly in msi_desc instead of iommu_cookie genirq/msi: Refactor iommu_dma_compose_msi_msg() iommu: Make iommu_dma_prepare_msi() into a generic operation irqchip: Have CONFIG_IRQ_MSI_IOMMU be selected by irqchips that need

[PATCH v2 6/7] iommufd: Implement sw_msi support natively

2025-02-19 Thread Nicolin Chen
mapping directly and use a global per-fd table to associate assigned IOVA to the MSI pages. This allows the MSI pages to be loaded into a domain before it is attached ensuring that MSI is not disrupted. Signed-off-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd

[PATCH v2 3/7] iommu: Make iommu_dma_prepare_msi() into a generic operation

2025-02-19 Thread Nicolin Chen
rtion for the group mutex as documentation. For the dmau_iommu.c each iommu_domain is unique to a group. Signed-off-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- include/linux/iommu.h | 44 ++- drivers/iommu/dma-iommu.c

Re: [PATCH v1 00/13] iommu: Add MSI mapping support with nested SMMU

2025-02-19 Thread Nicolin Chen
On Wed, Feb 19, 2025 at 09:37:23AM -0400, Jason Gunthorpe wrote: > On Sat, Feb 08, 2025 at 01:02:33AM -0800, Nicolin Chen wrote: > > iommu: Turn iova_cookie to dma-iommu private pointer > > I suggest you respin this with the updates and stop here at this > patch, it is enou

Re: [PATCH v1 01/13] genirq/msi: Store the IOMMU IOVA directly in msi_desc instead of iommu_cookie

2025-02-13 Thread Nicolin Chen
On Thu, Feb 13, 2025 at 09:57:52AM -0400, Jason Gunthorpe wrote: > Nicolin - lets change the patch structure a little bit can you adjust > this patch to leave iommu_dma_compose_msi_msg() in dma-iommu.c and the > next patch will be all about renaming and moving it to the MSI core > code instead? Eas

Re: [PATCH v1 01/13] genirq/msi: Store the IOMMU IOVA directly in msi_desc instead of iommu_cookie

2025-02-13 Thread Nicolin Chen
On Thu, Feb 13, 2025 at 12:28:49PM -0800, Jacob Pan wrote: > Hi Nicolin, > > On Sat, 8 Feb 2025 01:02:34 -0800 > Nicolin Chen wrote: > > > -static inline void msi_desc_set_iommu_cookie(struct msi_desc *desc, > > -c

Re: [PATCH v1 06/13] iommufd: Implement sw_msi support natively

2025-02-11 Thread Nicolin Chen
On Tue, Feb 11, 2025 at 02:16:20PM -0400, Jason Gunthorpe wrote: > On Sat, Feb 08, 2025 at 01:02:39AM -0800, Nicolin Chen wrote: > > > +static struct iommufd_attach_handle * > > +iommu_group_get_iommufd_handle(struct iommu_group *group) > > +{ > > + stru

Re: [PATCH v1 08/13] iommufd/device: Move sw_msi_start from igroup to idev

2025-02-10 Thread Nicolin Chen
On Sun, Feb 09, 2025 at 02:41:52PM -0400, Jason Gunthorpe wrote: > On Sat, Feb 08, 2025 at 01:02:41AM -0800, Nicolin Chen wrote: > > @@ -433,8 +433,8 @@ static int iommufd_group_setup_msi(struct iommufd_group > > *igroup, > > list_for_each_entry(cur, &ictx-

[PATCH v1 13/13] iommufd/selftest: Add coverage for IOMMU_OPTION_SW_MSI_START/SIZE

2025-02-08 Thread Nicolin Chen
Also add fail_nth coverage too. Signed-off-by: Nicolin Chen --- tools/testing/selftests/iommu/iommufd.c | 97 +++ .../selftests/iommu/iommufd_fail_nth.c| 21 2 files changed, 118 insertions(+) diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools

[PATCH v1 09/13] iommufd: Pass in idev to iopt_table_enforce_dev_resv_regions

2025-02-08 Thread Nicolin Chen
The iopt_table_enforce_dev_resv_regions needs to access the sw_msi_start and sw_msi_size stored in the idev, set by user space. So, pass in idev pointer instead. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_private.h | 2 +- drivers/iommu/iommufd/device.c | 5

[PATCH v1 12/13] iommufd/selftest: Add a testing reserved region

2025-02-08 Thread Nicolin Chen
The new IOMMU_OPTION_SW_MSI_START/SIZE must not overlap with any existing device reserved region, so add a testing region [0x8000, 0x8fff], on top of the normal IOVA aperture for selftest program to run an overlap test. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd

[PATCH v1 11/13] iommufd/selftest: Add MOCK_FLAGS_DEVICE_NO_ATTACH

2025-02-08 Thread Nicolin Chen
Add a new MOCK_FLAGS_DEVICE_NO_ATTACH flag to allow the mock_domain cmd to bypass the attach step, as IOMMU_OPTION_SW_MSI_START/SIZE only allow users to set prior to an IOAS/HWPT attachment. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_test.h | 1 + drivers/iommu/iommufd

[PATCH v1 10/13] iommufd: Add IOMMU_OPTION_SW_MSI_START/SIZE ioctls

2025-02-08 Thread Nicolin Chen
must set the values before attaching the device to any HWPT/IOAS to have an effect. Suggested-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_private.h | 2 + include/uapi/linux/iommufd.h| 20 - drivers/iommu/iommufd/io_pagetable.c| 15

[PATCH v1 06/13] iommufd: Implement sw_msi support natively

2025-02-08 Thread Nicolin Chen
mapping directly and use a global per-fd table to associate assigned iova to the MSI pages. This allows the MSI pages to be loaded into a domain before it is attached ensuring that MSI is not disrupted. Signed-off-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd

[PATCH v1 05/13] iommu: Turn fault_data to iommufd private pointer

2025-02-08 Thread Nicolin Chen
comments for readability. Signed-off-by: Nicolin Chen --- include/linux/iommu.h| 6 -- drivers/iommu/iommufd/fault.c| 2 +- drivers/iommu/iommufd/hw_pagetable.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/linux/iommu.h b/include/linux/

[PATCH v1 03/13] iommu: Make iommu_dma_prepare_msi() into a generic operation

2025-02-08 Thread Nicolin Chen
ff-by: Nicolin Chen --- include/linux/iommu.h | 44 ++- drivers/iommu/dma-iommu.c | 33 + drivers/iommu/iommu.c | 29 ++ 3 files changed, 73 insertions(+), 33 deletions(-) diff --git a/include/linux/iomm

[PATCH v1 08/13] iommufd/device: Move sw_msi_start from igroup to idev

2025-02-08 Thread Nicolin Chen
The sw_msi_start was set from the per-device reserved region, so storing it in the iommufd_device structure makes sense too. This will also ease a following patch adding a SET_OPTION uAPI to set per-idev sw_msi args. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_private.h | 2

[PATCH v1 07/13] iommu: Turn iova_cookie to dma-iommu private pointer

2025-02-08 Thread Nicolin Chen
to use dma-iommu.c for sw_msi and still need iova_cookie. Signed-off-by: Nicolin Chen --- include/linux/iommu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index e93d2e918599..99dd72998cb7 100644 --- a/include/linux/iommu.h +++

[PATCH v1 04/13] irqchip: Have CONFIG_IRQ_MSI_IOMMU be selected by the irqchips that need it

2025-02-08 Thread Nicolin Chen
be compiled into the kernel. If IRQ_MSI_IOMMU is selected with no IOMMU side implementation then prepare/compose will be NOP stubs. If IRQ_MSI_IOMMU is not selected by an irqchip then the related code on the iommu side is compiled out. Signed-off-by: Jason Gunthorpe Signed-off-by: Nicolin Chen

[PATCH v1 02/13] genirq/msi: Rename iommu_dma_compose_msi_msg() to msi_msg_set_addr()

2025-02-08 Thread Nicolin Chen
. Signed-off-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- include/linux/msi.h | 18 -- drivers/irqchip/irq-gic-v2m.c | 5 + drivers/irqchip/irq-gic-v3-its.c | 13 +++-- drivers/irqchip/irq-gic-v3-mbi.c | 12 drivers/irqchip/irq

[PATCH v1 01/13] genirq/msi: Store the IOMMU IOVA directly in msi_desc instead of iommu_cookie

2025-02-08 Thread Nicolin Chen
son Gunthorpe Signed-off-by: Nicolin Chen --- include/linux/iommu.h | 6 - include/linux/msi.h | 49 +-- drivers/iommu/dma-iommu.c | 30 3 files changed, 36 insertions(+), 49 deletions(-) diff --git a/include/linux/iomm

[PATCH v1 00/13] iommu: Add MSI mapping support with nested SMMU

2025-02-08 Thread Nicolin Chen
Rename iommu_dma_compose_msi_msg() to msi_msg_set_addr() iommu: Make iommu_dma_prepare_msi() into a generic operation irqchip: Have CONFIG_IRQ_MSI_IOMMU be selected by the irqchips that need it iommufd: Implement sw_msi support natively Nicolin Chen (8): iommu: Turn fault_data to iommufd

Re: [PATCH RFCv2 09/13] iommufd: Add IOMMU_OPTION_SW_MSI_START/SIZE ioctls

2025-02-07 Thread Nicolin Chen
On Fri, Feb 07, 2025 at 11:28:01AM -0400, Jason Gunthorpe wrote: > On Fri, Feb 07, 2025 at 10:30:20AM -0400, Jason Gunthorpe wrote: > > On Thu, Feb 06, 2025 at 08:26:05PM -0800, Nicolin Chen wrote: > > > Yea, I found iopt_reserve_iova() is actually missed entirely... > > &g

Re: [PATCH RFCv2 09/13] iommufd: Add IOMMU_OPTION_SW_MSI_START/SIZE ioctls

2025-02-06 Thread Nicolin Chen
On Wed, Jan 29, 2025 at 10:58:00AM -0400, Jason Gunthorpe wrote: > On Wed, Jan 29, 2025 at 02:44:12PM +0100, Eric Auger wrote: > > On 1/11/25 4:32 AM, Nicolin Chen wrote: > > > For systems that require MSI pages to be mapped into the IOMMU translation > > > t

Re: [PATCH RFCv2 00/13] iommu: Add MSI mapping support with nested SMMU

2025-02-05 Thread Nicolin Chen
On Wed, Feb 05, 2025 at 02:49:04PM -0800, Jacob Pan wrote: > > There have been two approaches to solve this problem: > > 1. Create an identity mapping in the stage-1. VMM could insert a few > > RMRs (Reserved Memory Regions) in guest's IORT. Then the guest kernel > > would fetch these RMR entries f

Re: [PATCH RFCv2 09/13] iommufd: Add IOMMU_OPTION_SW_MSI_START/SIZE ioctls

2025-02-03 Thread Nicolin Chen
On Thu, Jan 23, 2025 at 10:07:13AM +, Tian, Kevin wrote: > > From: Nicolin Chen > > Sent: Saturday, January 11, 2025 11:32 AM > > > > @@ -294,7 +294,9 @@ struct iommu_ioas_unmap { > > > > /** > > * enum iommufd_op

Re: [PATCH RFCv2 06/13] iommufd: Make attach_handle generic

2025-02-03 Thread Nicolin Chen
On Wed, Jan 29, 2025 at 02:14:47PM +0100, Eric Auger wrote: > > @@ -352,6 +352,111 @@ iommufd_device_attach_reserved_iova(struct > > iommufd_device *idev, > > return 0; > > } > > > > +/* The device attach/detach/replace helpers for attach_handle */ > > + > > +static int iommufd_hwpt_attach_

Re: [PATCH RFCv2 05/13] iommu: Turn fault_data to iommufd private pointer

2025-02-03 Thread Nicolin Chen
Hi Eric, On Wed, Jan 29, 2025 at 01:40:54PM +0100, Eric Auger wrote: > On 1/11/25 4:32 AM, Nicolin Chen wrote: > > A "fault_data" was added exclusively for the iommufd_fault_iopf_handler() > > used by IOPF/PRI use cases, along with the attach_handle. Now, the iomm

Re: [PATCH RFCv2 06/13] iommufd: Make attach_handle generic

2025-01-19 Thread Nicolin Chen
On Sun, Jan 19, 2025 at 06:40:57PM +0800, Yi Liu wrote: > On 2025/1/19 04:32, Nicolin Chen wrote: > > On Sat, Jan 18, 2025 at 04:23:22PM +0800, Yi Liu wrote: > > > On 2025/1/11 11:32, Nicolin Chen wrote: > > > > +static int iommufd_hwpt_attach_device(struct iommu

Re: [PATCH RFCv2 06/13] iommufd: Make attach_handle generic

2025-01-18 Thread Nicolin Chen
On Sat, Jan 18, 2025 at 04:23:22PM +0800, Yi Liu wrote: > On 2025/1/11 11:32, Nicolin Chen wrote: > > "attach_handle" was added exclusively for the iommufd_fault_iopf_handler() > > used by IOPF/PRI use cases, along with the "fault_data". Now, the iommufd > &

[PATCH RFCv2 02/13] genirq/msi: Rename iommu_dma_compose_msi_msg() to msi_msg_set_msi_addr()

2025-01-10 Thread Nicolin Chen
. Signed-off-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- include/linux/msi.h | 18 -- drivers/irqchip/irq-gic-v2m.c | 5 + drivers/irqchip/irq-gic-v3-its.c | 13 +++-- drivers/irqchip/irq-gic-v3-mbi.c | 12 drivers/irqchip/irq

[PATCH RFCv2 03/13] iommu: Make iommu_dma_prepare_msi() into a generic operation

2025-01-10 Thread Nicolin Chen
ckdep assertion for the group mutex as documentation. For the dma_iommu.c each iommu_domain unique to a group. Signed-off-by: Jason Gunthorpe [nicolinc: move iommu_domain_set_sw_msi() from iommu_dma_init_domain() to iommu_dma_init_domain(); add in iommu_put_dma_cookie() an sw_msi test] Signed-off-by: Ni

[PATCH RFCv2 13/13] vfio/pci: Allow preset MSI IOVAs via VFIO_IRQ_SET_ACTION_PREPARE

2025-01-10 Thread Nicolin Chen
ss, in order to work with the IOMMU on ARM64. Signed-off-by: Nicolin Chen --- include/uapi/linux/vfio.h | 8 -- drivers/vfio/pci/vfio_pci_intrs.c | 46 +++ drivers/vfio/vfio_main.c | 3 ++ 3 files changed, 55 insertions(+), 2 deletions(-) diff -

[PATCH RFCv2 12/13] vfio-iommufd: Provide another layer of msi_iova helpers

2025-01-10 Thread Nicolin Chen
As the bridge between iommufd core and vfio core, add a set of msi_iova helpers to call the new msi_iova helpers from the iommufd_device level. The next patch will use this bridging helpers in vfio-pci code. Signed-off-by: Nicolin Chen --- include/linux/vfio.h | 25

[PATCH RFCv2 11/13] iommufd/device: Allow setting IOVAs for MSI(x) vectors

2025-01-10 Thread Nicolin Chen
vide a set of helpers to allocate/set/unset the resizable array. The next patch will call them from the vfio code. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_private.h | 2 ++ include/linux/iommufd.h | 6 drivers/iommu/iommufd/device.c

[PATCH RFCv2 10/13] iommufd/selftes: Add coverage for IOMMU_OPTION_SW_MSI_START/SIZE

2025-01-10 Thread Nicolin Chen
Also add fail_nth coverage too. Signed-off-by: Nicolin Chen --- tools/testing/selftests/iommu/iommufd.c | 53 +++ .../selftests/iommu/iommufd_fail_nth.c| 14 + 2 files changed, 67 insertions(+) diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools

[PATCH RFCv2 09/13] iommufd: Add IOMMU_OPTION_SW_MSI_START/SIZE ioctls

2025-01-10 Thread Nicolin Chen
directly replace the IOMMU_RESV_SW_MSI values. The VMM must set the values before creating any hwpt's to have any effect. Suggested-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_private.h | 4 +++ include/uapi/linux/iommufd.h

[PATCH RFCv2 07/13] iommufd: Implement sw_msi support natively

2025-01-10 Thread Nicolin Chen
: Nicolin Chen --- drivers/iommu/iommufd/iommufd_private.h | 23 +++- drivers/iommu/iommufd/device.c | 158 drivers/iommu/iommufd/hw_pagetable.c| 3 + drivers/iommu/iommufd/main.c| 9 ++ 4 files changed, 170 insertions(+), 23 deletions(-) diff

[PATCH RFCv2 08/13] iommu: Turn iova_cookie to dma-iommu private pointer

2025-01-10 Thread Nicolin Chen
Now, iommufd has its own iommufd_sw_msi using iommufd_hwpt, the iommufd owned domain's private pointer. Similarly, iova_cookie can be seen as a dma-iommu owned domain's private pointer. So, move iova_cookie into the union. Signed-off-by: Nicolin Chen --- include/linux/iommu.h | 2

[PATCH RFCv2 06/13] iommufd: Make attach_handle generic

2025-01-10 Thread Nicolin Chen
the fault.c file to make it generic for all cases. Simplify the remaining fault specific routine to attach/detach. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_private.h | 40 +--- drivers/iommu/iommufd/device.c | 105 + drivers/iommu/iommufd/fau

[PATCH RFCv2 05/13] iommu: Turn fault_data to iommufd private pointer

2025-01-10 Thread Nicolin Chen
comments for readability. Signed-off-by: Nicolin Chen --- include/linux/iommu.h| 6 -- drivers/iommu/iommufd/fault.c| 2 +- drivers/iommu/iommufd/hw_pagetable.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/linux/iommu.h b/include/linux/

[PATCH RFCv2 04/13] irqchip: Have CONFIG_IRQ_MSI_IOMMU be selected by the irqchips that need it

2025-01-10 Thread Nicolin Chen
be compiled into the kernel. If IRQ_MSI_IOMMU is selected with no IOMMU side implementation then prepare/compose will be NOP stubs. If IRQ_MSI_IOMMU is not selected by an irqchip then the related code on the iommu side is compiled out. Signed-off-by: Jason Gunthorpe Signed-off-by: Nicolin Chen

[PATCH RFCv2 01/13] genirq/msi: Store the IOMMU IOVA directly in msi_desc instead of iommu_cookie

2025-01-10 Thread Nicolin Chen
horpe Signed-off-by: Nicolin Chen --- include/linux/iommu.h | 6 -- include/linux/msi.h | 45 +++ drivers/iommu/dma-iommu.c | 30 +- 3 files changed, 32 insertions(+), 49 deletions(-) diff --git a/include/linux/iommu.h b/

[PATCH RFCv2 00/13] iommu: Add MSI mapping support with nested SMMU

2025-01-10 Thread Nicolin Chen
orpe (5): genirq/msi: Store the IOMMU IOVA directly in msi_desc instead of iommu_cookie genirq/msi: Rename iommu_dma_compose_msi_msg() to msi_msg_set_msi_addr() iommu: Make iommu_dma_prepare_msi() into a generic operation irqchip: Have CONFIG_IRQ_MSI_IOMMU be selected by the irqchips t

[PATCH v1 2/2] iommufd/selftest: Cover IOMMU_FAULT_QUEUE_ALLOC in iommufd_fail_nth

2024-12-03 Thread Nicolin Chen
This was missing in the series introducing the fault object. Thus, add it. Signed-off-by: Nicolin Chen --- tools/testing/selftests/iommu/iommufd_fail_nth.c | 14 ++ 1 file changed, 14 insertions(+) diff --git a/tools/testing/selftests/iommu/iommufd_fail_nth.c b/tools/testing

[PATCH v1 0/2] iommufd: Fix a small bug in fault.c

2024-12-03 Thread Nicolin Chen
There are a few patches in vIRQ series that rework the fault.c file. So, we should fix this before that bigger series touches the same code. And add missing coverage for IOMMU_FAULT_QUEUE_ALLOC in iommufd_fail_nth. Thanks! Nicolin Nicolin Chen (2): iommufd/fault: Fix out_fput in

[PATCH v1 1/2] iommufd/fault: Fix out_fput in iommufd_fault_alloc()

2024-12-03 Thread Nicolin Chen
ef_put+0x100/0x138 (L) __fput_sync+0x4c/0xd0 Drop those two lines to fix the warnings above. Fixes: 07838f7fd529 ("iommufd: Add iommufd fault object") Cc: sta...@vger.kernel.org Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/fault.c | 2 -- 1 file changed, 2 deletions(

Re: [PATCH v5 12/13] Documentation: userspace-api: iommufd: Update vIOMMU

2024-10-29 Thread Nicolin Chen
On Fri, Oct 25, 2024 at 04:49:52PM -0700, Nicolin Chen wrote: > With the introduction of the new object and its infrastructure, update the > doc to reflect that and add a new graph. > > Reviewed-by: Jason Gunthorpe > Reviewed-by: Kevin Tian > Signed-off-by: Nicolin Chen >

Re: [PATCH v5 06/13] iommu: Add iommu_copy_struct_from_full_user_array helper

2024-10-29 Thread Nicolin Chen
On Tue, Oct 29, 2024 at 08:24:52AM +, Tian, Kevin wrote: > > From: Nicolin Chen > > Sent: Saturday, October 26, 2024 7:51 AM > > > > From: Jason Gunthorpe > > > > The iommu_copy_struct_from_user_array helper can be used to copy a > > single >

Re: [PATCH v5 03/13] iommufd: Add iommufd_verify_unfinalized_object

2024-10-29 Thread Nicolin Chen
On Tue, Oct 29, 2024 at 03:55:58PM -0300, Jason Gunthorpe wrote: > On Tue, Oct 29, 2024 at 09:18:05AM -0700, Nicolin Chen wrote: > > I think we'd need the same change in iommufd_object_abort() too. > > Makes sense I found xa_cmpxchg() does xas_result to its returnin

Re: [PATCH v5 05/13] iommufd: Allow hwpt_id to carry viommu_id for IOMMU_HWPT_INVALIDATE

2024-10-29 Thread Nicolin Chen
On Tue, Oct 29, 2024 at 04:09:41PM -0300, Jason Gunthorpe wrote: > On Fri, Oct 25, 2024 at 04:50:34PM -0700, Nicolin Chen wrote: > > @@ -497,17 +497,35 @@ int iommufd_hwpt_invalidate(struct iommufd_ucmd *ucmd) > > goto out; > > } > > > > - hw

Re: [PATCH v5 01/13] iommufd/viommu: Add IOMMUFD_OBJ_VDEVICE and IOMMU_VDEVICE_ALLOC ioctl

2024-10-29 Thread Nicolin Chen
On Tue, Oct 29, 2024 at 03:48:01PM -0300, Jason Gunthorpe wrote: > On Tue, Oct 29, 2024 at 10:29:56AM -0700, Nicolin Chen wrote: > > On Tue, Oct 29, 2024 at 12:58:24PM -0300, Jason Gunthorpe wrote: > > > On Fri, Oct 25, 2024 at 04:50:30PM -0700, Nicolin Chen wrote: > >

Re: [PATCH v5 03/13] iommufd: Add iommufd_verify_unfinalized_object

2024-10-29 Thread Nicolin Chen
On Tue, Oct 29, 2024 at 03:55:58PM -0300, Jason Gunthorpe wrote: > On Tue, Oct 29, 2024 at 09:18:05AM -0700, Nicolin Chen wrote: > > On Tue, Oct 29, 2024 at 11:49:07AM -0300, Jason Gunthorpe wrote: > > > On Fri, Oct 25, 2024 at 04:49:43PM -0700, Nicolin Chen wrote: > &g

Re: [PATCH v5 01/13] iommufd/viommu: Add IOMMUFD_OBJ_VDEVICE and IOMMU_VDEVICE_ALLOC ioctl

2024-10-29 Thread Nicolin Chen
On Tue, Oct 29, 2024 at 12:58:24PM -0300, Jason Gunthorpe wrote: > On Fri, Oct 25, 2024 at 04:50:30PM -0700, Nicolin Chen wrote: > > diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c > > index 5fd3dd420290..e50113305a9c 100644 > > --- a/drivers/i

Re: [PATCH v5 03/13] iommufd: Add iommufd_verify_unfinalized_object

2024-10-29 Thread Nicolin Chen
On Tue, Oct 29, 2024 at 11:49:07AM -0300, Jason Gunthorpe wrote: > On Fri, Oct 25, 2024 at 04:49:43PM -0700, Nicolin Chen wrote: > > To support driver-allocated vIOMMU objects, it's suggested to call the > > allocator helper in IOMMU dirvers. However, there is no guarantee t

Re: [PATCH v5 06/13] iommufd: Allow pt_id to carry viommu_id for IOMMU_HWPT_ALLOC

2024-10-29 Thread Nicolin Chen
On Tue, Oct 29, 2024 at 12:27:46PM -0300, Jason Gunthorpe wrote: > On Mon, Oct 28, 2024 at 07:52:10AM -0700, Nicolin Chen wrote: > > On Mon, Oct 28, 2024 at 10:03:09AM -0300, Jason Gunthorpe wrote: > > In iommufd_hwpt_paging_alloc(), we reject IOMMU_HWPT_FAULT_ID_VALID: &g

Re: [PATCH v5 04/13] iommufd/viommu: Add IOMMU_VIOMMU_ALLOC ioctl

2024-10-29 Thread Nicolin Chen
On Tue, Oct 29, 2024 at 12:59:35PM -0300, Jason Gunthorpe wrote: > On Tue, Oct 29, 2024 at 08:46:40AM -0700, Nicolin Chen wrote: > > On Tue, Oct 29, 2024 at 12:36:24PM -0300, Jason Gunthorpe wrote: > > > On Tue, Oct 29, 2024 at 11:54:36AM -0300, Jason Gunthorpe wrote: > >

Re: [PATCH v5 09/13] iommufd/selftest: Add refcount to mock_iommu_device

2024-10-29 Thread Nicolin Chen
On Tue, Oct 29, 2024 at 12:34:38PM -0300, Jason Gunthorpe wrote: > On Fri, Oct 25, 2024 at 04:49:49PM -0700, Nicolin Chen wrote: > > For an iommu_dev that can unplug (so far only this selftest does so), the > > viommu->iommu_dev pointer has no guarantee of its life cycle afte

Re: [PATCH v5 04/13] iommufd/viommu: Add IOMMU_VIOMMU_ALLOC ioctl

2024-10-29 Thread Nicolin Chen
On Tue, Oct 29, 2024 at 12:36:24PM -0300, Jason Gunthorpe wrote: > On Tue, Oct 29, 2024 at 11:54:36AM -0300, Jason Gunthorpe wrote: > > On Fri, Oct 25, 2024 at 04:49:44PM -0700, Nicolin Chen wrote: > > > +void iommufd_viommu_destroy(struct iommufd_object *obj) >

Re: [PATCH v5 04/13] iommufd/viommu: Add IOMMU_VIOMMU_ALLOC ioctl

2024-10-29 Thread Nicolin Chen
On Tue, Oct 29, 2024 at 11:54:36AM -0300, Jason Gunthorpe wrote: > On Fri, Oct 25, 2024 at 04:49:44PM -0700, Nicolin Chen wrote: > > +void iommufd_viommu_destroy(struct iommufd_object *obj) > > +{ > > + struct iommufd_viommu *viommu = > > + container_of(obj,

Re: [PATCH v5 06/13] iommufd: Allow pt_id to carry viommu_id for IOMMU_HWPT_ALLOC

2024-10-28 Thread Nicolin Chen
On Mon, Oct 28, 2024 at 07:52:10AM -0700, Nicolin Chen wrote: > On Mon, Oct 28, 2024 at 10:03:09AM -0300, Jason Gunthorpe wrote: > > On Mon, Oct 28, 2024 at 11:24:10AM +0800, Zhangfei Gao wrote: > > > > > > +/** > > > > + * iommufd_viommu_alloc_hwpt_ne

Re: [PATCH v5 01/13] iommufd/viommu: Add IOMMUFD_OBJ_VDEVICE and IOMMU_VDEVICE_ALLOC ioctl

2024-10-28 Thread Nicolin Chen
On Mon, Oct 28, 2024 at 03:11:32AM +, Tian, Kevin wrote: > > From: Nicolin Chen > > Sent: Saturday, October 26, 2024 7:51 AM > > > > + > > +/** > > + * struct iommu_vdevice_alloc - ioctl(IOMMU_VDEVICE_ALLOC) > > + * @size: sizeof(struct iommu_vdevi

Re: [PATCH v5 06/13] iommufd: Allow pt_id to carry viommu_id for IOMMU_HWPT_ALLOC

2024-10-28 Thread Nicolin Chen
On Mon, Oct 28, 2024 at 10:53:38PM +0800, Zhangfei Gao wrote: > On Mon, 28 Oct 2024 at 11:24, Zhangfei Gao wrote: > > > By the way, has qemu changed compared with v3? > > I still got a hardware error in this version, in check > > Found iommufd_viommu_p2-v5 misses some patches, > Simply tested ok

Re: [PATCH v5 06/13] iommufd: Allow pt_id to carry viommu_id for IOMMU_HWPT_ALLOC

2024-10-28 Thread Nicolin Chen
On Mon, Oct 28, 2024 at 10:03:09AM -0300, Jason Gunthorpe wrote: > On Mon, Oct 28, 2024 at 11:24:10AM +0800, Zhangfei Gao wrote: > > > > +/** > > > + * iommufd_viommu_alloc_hwpt_nested() - Get a hwpt_nested for a vIOMMU > > > + * @viommu: vIOMMU ojbect to associate the hwpt_nested/domain with > >

Re: [PATCH v5 07/13] iommufd/viommu: Add iommufd_viommu_find_dev helper

2024-10-27 Thread Nicolin Chen
On Sun, Oct 27, 2024 at 11:02:31PM +0800, Zhangfei Gao wrote: > On Sat, 26 Oct 2024 at 07:51, Nicolin Chen wrote: > > +/* Caller should xa_lock(&viommu->vdevs) to protect the return value */ > > +struct device *iommufd_viommu_find_dev(struct

[PATCH v5 08/13] iommufd/selftest: Add mock_viommu_cache_invalidate

2024-10-25 Thread Nicolin Chen
Similar to the coverage of cache_invalidate_user for iotlb invalidation, add a device cache and a viommu_cache_invalidate function to test it out. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_test.h | 25 + drivers/iommu/iommufd/selftest.c | 76

[PATCH v5 09/13] iommufd/selftest: Add refcount to mock_iommu_device

2024-10-25 Thread Nicolin Chen
refcount is unbalanced. The refcount inc/dec will be added in the following patch. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/selftest.c | 32 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/i

[PATCH v5 02/13] iommufd/selftest: Add IOMMU_VDEVICE_ALLOC test coverage

2024-10-25 Thread Nicolin Chen
Add a vdevice_alloc op to the viommu mock_viommu_ops for the coverage of IOMMU_VIOMMU_TYPE_SELFTEST allocations. Then, add a vdevice_alloc TEST_F to cover the IOMMU_VDEVICE_ALLOC ioctl. Signed-off-by: Nicolin Chen --- tools/testing/selftests/iommu/iommufd_utils.h | 27 +++ tools

[PATCH v5 05/13] iommufd: Add alloc_domain_nested op to iommufd_viommu_ops

2024-10-25 Thread Nicolin Chen
Allow IOMMU driver to use a vIOMMU object that holds a nesting parent hwpt/domain to allocate a nested domain. Suggested-by: Jason Gunthorpe Reviewed-by: Kevin Tian Signed-off-by: Nicolin Chen --- include/linux/iommufd.h | 9 + 1 file changed, 9 insertions(+) diff --git a/include

[PATCH v5 01/13] iommufd/viommu: Add IOMMUFD_OBJ_VDEVICE and IOMMU_VDEVICE_ALLOC ioctl

2024-10-25 Thread Nicolin Chen
re both as the ioctl inputs and take refcounts in the ioctl handler. Then, let the idev structure hold the allocated vdev pointer with a proper locking protection. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_private.h | 20 + include/linux/iommufd.h | 3

[PATCH v5 07/13] iommufd/viommu: Add iommufd_viommu_find_dev helper

2024-10-25 Thread Nicolin Chen
This avoids a bigger trouble of exposing struct iommufd_device and struct iommufd_vdevice in the public header. Signed-off-by: Nicolin Chen --- include/linux/iommufd.h| 8 drivers/iommu/iommufd/driver.c | 13 + 2 files changed, 21 insertions(+) diff --git a

[PATCH v5 04/13] iommufd/viommu: Add IOMMU_VIOMMU_ALLOC ioctl

2024-10-25 Thread Nicolin Chen
Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/Makefile | 3 +- drivers/iommu/iommufd/iommufd_private.h | 3 + include/uapi/linux/iommufd.h| 40 +++ drivers/iommu/iommufd/main.c| 6 ++ drivers/iommu/iommufd/viommu.c | 89

[PATCH v5 07/13] iommufd/selftest: Add container_of helpers

2024-10-25 Thread Nicolin Chen
Use these inline helpers to shorten those container_of lines. Note that one of them goes back and forth between iommu_domain and mock_iommu_domain, which isn't necessary. So drop its container_of. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/selftest.c

[PATCH v5 12/13] iommu/arm-smmu-v3: Add arm_vsmmu_cache_invalidate

2024-10-25 Thread Nicolin Chen
Scan those commands against the permitted command list and fix their VMID/SID fields. Co-developed-by: Eric Auger Signed-off-by: Eric Auger Co-developed-by: Jason Gunthorpe Signed-off-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 5 + in

[PATCH v5 13/13] iommu/arm-smmu-v3: Allow ATS for IOMMU_DOMAIN_NESTED

2024-10-25 Thread Nicolin Chen
From: Jason Gunthorpe Now, ATC invalidation can be done with the vIOMMU invalidation op. A guest owned IOMMU_DOMAIN_NESTED can do an ATS too. Allow it to pass in the EATS field via the vSTE words. Signed-off-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3

[PATCH v5 11/13] Documentation: userspace-api: iommufd: Update vDEVICE

2024-10-25 Thread Nicolin Chen
With the introduction of the new object and its infrastructure, update the doc and the vIOMMU graph to reflect that. Reviewed-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- Documentation/userspace-api/iommufd.rst | 41 +++-- 1 file changed, 32 insertions(+), 9

[PATCH v5 10/13] iommufd/selftest: Add vIOMMU coverage for IOMMU_HWPT_INVALIDATE ioctl

2024-10-25 Thread Nicolin Chen
Add a viommu_cache test function to cover vIOMMU invalidations using the updated IOMMU_HWPT_INVALIDATE ioctl, which now allows passing in a vIOMMU via its hwpt_id field. Signed-off-by: Nicolin Chen --- tools/testing/selftests/iommu/iommufd_utils.h | 32 tools/testing/selftests/iommu

[PATCH v5 09/13] iommufd/selftest: Add IOMMU_TEST_OP_DEV_CHECK_CACHE test command

2024-10-25 Thread Nicolin Chen
Similar to IOMMU_TEST_OP_MD_CHECK_IOTLB verifying a mock_domain's iotlb, IOMMU_TEST_OP_DEV_CHECK_CACHE will be used to verify a mock_dev's cache. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_test.h | 5 tools/testing/selftests/iommu/iommufd_ut

[PATCH v5 06/13] iommu: Add iommu_copy_struct_from_full_user_array helper

2024-10-25 Thread Nicolin Chen
iommu_copy_struct_from_user_array kdoc accordingly. Signed-off-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- include/linux/iommu.h | 48 ++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 14f24b5cd16f

[PATCH v5 05/13] iommufd: Allow hwpt_id to carry viommu_id for IOMMU_HWPT_INVALIDATE

2024-10-25 Thread Nicolin Chen
viommu_id, and reuse the IOMMU_HWPT_INVALIDATE uAPI for vIOMMU invalidations. Drivers can define different structures for vIOMMU invalidations v.s. HWPT ones. Update the uAPI, kdoc, and selftest case accordingly. Reviewed-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- include/uapi/linux

[PATCH v5 03/13] iommu/viommu: Add cache_invalidate to iommufd_viommu_ops

2024-10-25 Thread Nicolin Chen
This per-vIOMMU cache_invalidate op is like the cache_invalidate_user op in struct iommu_domain_ops, but wider, supporting device cache (e.g. PCI ATC invaldiations). Reviewed-by: Jason Gunthorpe Signed-off-by: Nicolin Chen --- include/linux/iommufd.h | 10 ++ 1 file changed, 10

[PATCH v5 04/13] iommufd/hw_pagetable: Enforce invalidation op on vIOMMU-based hwpt_nested

2024-10-25 Thread Nicolin Chen
A vIOMMU-based hwpt_nested requires a cache invalidation op too, either using the one in iommu_domain_ops or the one in viommu_ops. Enforce that upon the allocated hwpt_nested. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/hw_pagetable.c | 4 +++- 1 file changed, 3 insertions(+), 1

[PATCH v5 00/13] iommufd: Add vIOMMU infrastructure (Part-2: vDEVICE)

2024-10-25 Thread Nicolin Chen
t/unset_vdev_id handlers for proper lockings v1 https://lore.kernel.org/all/cover.1723061377.git.nicol...@nvidia.com/ Thanks! Nicolin Jason Gunthorpe (2): iommu: Add iommu_copy_struct_from_full_user_array helper iommu/arm-smmu-v3: Allow ATS for IOMMU_DOMAIN_NESTED Nicolin Chen (11): iommufd/v

[PATCH v5 03/13] iommufd: Add iommufd_verify_unfinalized_object

2024-10-25 Thread Nicolin Chen
ictx. Reviewed-by: Kevin Tian Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_private.h | 3 +++ drivers/iommu/iommufd/main.c| 20 2 files changed, 23 insertions(+) diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/io

[PATCH v5 13/13] iommu/arm-smmu-v3: Add IOMMU_VIOMMU_TYPE_ARM_SMMUV3 support

2024-10-25 Thread Nicolin Chen
int in creating a vIOMMU (vsmmu) from the beginning if it would not support a nested_domain. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 26 +++--- include/uapi/linux/iommufd.h | 2 + .../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c

[PATCH v5 11/13] iommufd/selftest: Add IOMMU_VIOMMU_ALLOC test coverage

2024-10-25 Thread Nicolin Chen
Add a new iommufd_viommu FIXTURE and setup it up with a vIOMMU object. Any new vIOMMU feature will be added as a TEST_F under that. Signed-off-by: Nicolin Chen --- tools/testing/selftests/iommu/iommufd_utils.h | 28 ++ tools/testing/selftests/iommu/iommufd.c | 87

[PATCH v5 12/13] Documentation: userspace-api: iommufd: Update vIOMMU

2024-10-25 Thread Nicolin Chen
With the introduction of the new object and its infrastructure, update the doc to reflect that and add a new graph. Reviewed-by: Jason Gunthorpe Reviewed-by: Kevin Tian Signed-off-by: Nicolin Chen --- Documentation/userspace-api/iommufd.rst | 69 - 1 file changed, 68

[PATCH v5 10/13] iommufd/selftest: Add IOMMU_VIOMMU_TYPE_SELFTEST

2024-10-25 Thread Nicolin Chen
Implement the viommu alloc/free functions to increase/reduce refcount of its dependent mock iommu device. User space can verify this loop via the IOMMU_VIOMMU_TYPE_SELFTEST. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_test.h | 2 + drivers/iommu/iommufd/selftest.c | 64

[PATCH v5 06/13] iommufd: Allow pt_id to carry viommu_id for IOMMU_HWPT_ALLOC

2024-10-25 Thread Nicolin Chen
object. Since a vIOMMU object holds the parent hwpt's refcount already, increase the refcount of the vIOMMU only. Signed-off-by: Nicolin Chen --- drivers/iommu/iommufd/iommufd_private.h | 1 + include/uapi/linux/iommufd.h| 14 ++--- drivers/iommu/iommufd/hw_pagetable.c

  1   2   3   4   5   6   7   8   9   10   >