[PATCH v5 5/5] vfio/iommu_type1: Simplify group attachment

2022-07-01 Thread Nicolin Chen via iommu
Un-inline the domain specific logic from the attach/detach_group ops into two paired functions vfio_iommu_alloc_attach_domain() and vfio_iommu_detach_destroy_domain() that strictly deal with creating and destroying struct vfio_domains. Add the logic to check for EMEDIUMTYPE return code of iommu_at

[PATCH v5 4/5] vfio/iommu_type1: Clean up update_dirty_scope in detach_group()

2022-07-01 Thread Nicolin Chen via iommu
All devices in emulated_iommu_groups have pinned_page_dirty_scope set, so the update_dirty_scope in the first list_for_each_entry is always false. Clean it up, and move the "if update_dirty_scope" part from the detach_group_done routine to the domain_list part. Suggested-by: Jason Gunthorpe Revie

[PATCH v5 3/5] vfio/iommu_type1: Remove the domain->ops comparison

2022-07-01 Thread Nicolin Chen via iommu
The domain->ops validation was added, as a precaution, for mixed-driver systems. Per Robin's remarks, * While bus_set_iommu() still exists, the core code prevents multiple drivers from registering, so we can't really run into a situation of having a mixed-driver system: https://lore.kernel.o

[PATCH v5 2/5] vfio/iommu_type1: Prefer to reuse domains vs match enforced cache coherency

2022-07-01 Thread Nicolin Chen via iommu
From: Jason Gunthorpe The KVM mechanism for controlling wbinvd is based on OR of the coherency property of all devices attached to a guest, no matter whether those devices are attached to a single domain or multiple domains. On the other hand, the benefit to using separate domains was that those

[PATCH v5 1/5] iommu: Return -EMEDIUMTYPE for incompatible domain and device/group

2022-07-01 Thread Nicolin Chen via iommu
Cases like VFIO wish to attach a device to an existing domain that was not allocated specifically from the device. This raises a condition where the IOMMU driver can fail the domain attach because the domain and device are incompatible with each other. This is a soft failure that can be resolved b

[PATCH v5 0/5] cover-letter: Simplify vfio_iommu_type1 attach/detach routine

2022-07-01 Thread Nicolin Chen via iommu
This is a preparatory series for IOMMUFD v2 patches. It enforces error code -EMEDIUMTYPE in iommu_attach_device() and iommu_attach_group() when an IOMMU domain and a device/group are incompatible. It also drops the useless domain->ops check since it won't fail in current environment. These allow V

Re: [PATCH v4 1/5] iommu: Return -EMEDIUMTYPE for incompatible domain and device/group

2022-07-01 Thread Nicolin Chen via iommu
On Fri, Jul 01, 2022 at 07:17:38PM +0100, Robin Murphy wrote: > External email: Use caution opening links or attachments > > > On 01/07/2022 5:43 pm, Nicolin Chen wrote: > > On Fri, Jul 01, 2022 at 11:21:48AM +0100, Robin Murphy wrote: > > > > > > diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu

Re: [PATCH v4 1/5] iommu: Return -EMEDIUMTYPE for incompatible domain and device/group

2022-07-01 Thread Nicolin Chen via iommu
On Fri, Jul 01, 2022 at 11:21:48AM +0100, Robin Murphy wrote: > > diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.c > > b/drivers/iommu/arm/arm-smmu/arm-smmu.c > > index 2ed3594f384e..072cac5ab5a4 100644 > > --- a/drivers/iommu/arm/arm-smmu/arm-smmu.c > > +++ b/drivers/iommu/arm/arm-smmu/arm-smm

[PATCH v4 4/5] vfio/iommu_type1: Clean up update_dirty_scope in detach_group()

2022-06-30 Thread Nicolin Chen via iommu
All devices in emulated_iommu_groups have pinned_page_dirty_scope set, so the update_dirty_scope in the first list_for_each_entry is always false. Clean it up, and move the "if update_dirty_scope" part from the detach_group_done routine to the domain_list part. Suggested-by: Jason Gunthorpe Revie

[PATCH v4 5/5] vfio/iommu_type1: Simplify group attachment

2022-06-30 Thread Nicolin Chen via iommu
Un-inline the domain specific logic from the attach/detach_group ops into two paired functions vfio_iommu_alloc_attach_domain() and vfio_iommu_detach_destroy_domain() that strictly deal with creating and destroying struct vfio_domains. Add the logic to check for EMEDIUMTYPE return code of iommu_at

[PATCH v4 2/5] vfio/iommu_type1: Prefer to reuse domains vs match enforced cache coherency

2022-06-30 Thread Nicolin Chen via iommu
From: Jason Gunthorpe The KVM mechanism for controlling wbinvd is based on OR of the coherency property of all devices attached to a guest, no matter whether those devices are attached to a single domain or multiple domains. On the other hand, the benefit to using separate domains was that those

[PATCH v4 3/5] vfio/iommu_type1: Remove the domain->ops comparison

2022-06-30 Thread Nicolin Chen via iommu
The domain->ops validation was added, as a precaution, for mixed-driver systems. Per Robin's remarks, * While bus_set_iommu() still exists, the core code prevents multiple drivers from registering, so we can't really run into a situation of having a mixed-driver system: https://lore.kernel.o

[PATCH v4 1/5] iommu: Return -EMEDIUMTYPE for incompatible domain and device/group

2022-06-30 Thread Nicolin Chen via iommu
Cases like VFIO wish to attach a device to an existing domain that was not allocated specifically from the device. This raises a condition where the IOMMU driver can fail the domain attach because the domain and device are incompatible with each other. This is a soft failure that can be resolved b

[PATCH v4 0/5] Simplify vfio_iommu_type1 attach/detach routine

2022-06-30 Thread Nicolin Chen via iommu
This is a preparatory series for IOMMUFD v2 patches. It enforces error code -EMEDIUMTYPE in iommu_attach_device() and iommu_attach_group() when an IOMMU domain and a device/group are incompatible. It also drops the useless domain->ops check since it won't fail in current environment. These allow V

Re: [PATCH v3 1/5] iommu: Return -EMEDIUMTYPE for incompatible domain and device/group

2022-06-30 Thread Nicolin Chen via iommu
On Thu, Jun 30, 2022 at 09:21:42AM +0100, Robin Murphy wrote: > External email: Use caution opening links or attachments > > > On 2022-06-29 20:47, Nicolin Chen wrote: > > On Fri, Jun 24, 2022 at 03:19:43PM -0300, Jason Gunthorpe wrote: > > > On Fri, Jun 24, 2022 at 06:35:49PM +0800, Yong Wu wrot

Re: [PATCH v3 1/5] iommu: Return -EMEDIUMTYPE for incompatible domain and device/group

2022-06-30 Thread Nicolin Chen via iommu
On Thu, Jun 30, 2022 at 05:33:16PM +0800, Yong Wu wrote: > External email: Use caution opening links or attachments > > > On Wed, 2022-06-29 at 12:47 -0700, Nicolin Chen wrote: > > On Fri, Jun 24, 2022 at 03:19:43PM -0300, Jason Gunthorpe wrote: > > > On Fri, Jun 24, 2022 at 06:35:49PM +0800, Yon

Re: [PATCH v3 1/5] iommu: Return -EMEDIUMTYPE for incompatible domain and device/group

2022-06-29 Thread Nicolin Chen via iommu
On Fri, Jun 24, 2022 at 03:19:43PM -0300, Jason Gunthorpe wrote: > On Fri, Jun 24, 2022 at 06:35:49PM +0800, Yong Wu wrote: > > > > > It's not used in VFIO context. "return 0" just satisfy the iommu > > > > framework to go ahead. and yes, here we only allow the shared > > > > "mapping-domain" (All

Re: [PATCH v3 1/5] iommu: Return -EMEDIUMTYPE for incompatible domain and device/group

2022-06-23 Thread Nicolin Chen via iommu
On Fri, Jun 24, 2022 at 01:38:58PM +0800, Yong Wu wrote: > > > > diff --git a/drivers/iommu/mtk_iommu_v1.c > > > > b/drivers/iommu/mtk_iommu_v1.c > > > > index e1cb51b9866c..5386d889429d 100644 > > > > --- a/drivers/iommu/mtk_iommu_v1.c > > > > +++ b/drivers/iommu/mtk_iommu_v1.c > > > > @@ -304,7

Re: [PATCH v3 1/5] iommu: Return -EMEDIUMTYPE for incompatible domain and device/group

2022-06-23 Thread Nicolin Chen via iommu
On Fri, Jun 24, 2022 at 09:35:49AM +0800, Baolu Lu wrote: > External email: Use caution opening links or attachments > > > On 2022/6/24 04:00, Nicolin Chen wrote: > > diff --git a/drivers/iommu/mtk_iommu_v1.c b/drivers/iommu/mtk_iommu_v1.c > > index e1cb51b9866c..5386d889429d 100644 > > --- a/dri

[PATCH v3 3/5] vfio/iommu_type1: Remove the domain->ops comparison

2022-06-23 Thread Nicolin Chen via iommu
The domain->ops validation was added, as a precaution, for mixed-driver systems. Per Robin's remarks, * While bus_set_iommu() still exists, the core code prevents multiple drivers from registering, so we can't really run into a situation of having a mixed-driver system: https://lore.kernel.o

[PATCH v3 4/5] vfio/iommu_type1: Clean up update_dirty_scope in detach_group()

2022-06-23 Thread Nicolin Chen via iommu
All devices in emulated_iommu_groups have pinned_page_dirty_scope set, so the update_dirty_scope in the first list_for_each_entry is always false. Clean it up, and move the "if update_dirty_scope" part from the detach_group_done routine to the domain_list part. Suggested-by: Jason Gunthorpe Revie

[PATCH v3 5/5] vfio/iommu_type1: Simplify group attachment

2022-06-23 Thread Nicolin Chen via iommu
Un-inline the domain specific logic from the attach/detach_group ops into two paired functions vfio_iommu_alloc_attach_domain() and vfio_iommu_detach_destroy_domain() that strictly deal with creating and destroying struct vfio_domains. Add the logic to check for EMEDIUMTYPE return code of iommu_at

[PATCH v3 2/5] vfio/iommu_type1: Prefer to reuse domains vs match enforced cache coherency

2022-06-23 Thread Nicolin Chen via iommu
From: Jason Gunthorpe The KVM mechanism for controlling wbinvd is based on OR of the coherency property of all devices attached to a guest, no matter whether those devices are attached to a single domain or multiple domains. On the other hand, the benefit to using separate domains was that those

[PATCH v3 1/5] iommu: Return -EMEDIUMTYPE for incompatible domain and device/group

2022-06-23 Thread Nicolin Chen via iommu
Cases like VFIO wish to attach a device to an existing domain that was not allocated specifically from the device. This raises a condition where the IOMMU driver can fail the domain attach because the domain and device are incompatible with each other. This is a soft failure that can be resolved b

[PATCH v3 0/5] Simplify vfio_iommu_type1 attach/detach routine

2022-06-23 Thread Nicolin Chen via iommu
This is a preparatory series for IOMMUFD v2 patches. It enforces error code -EMEDIUMTYPE in iommu_attach_device() and iommu_attach_group() when an IOMMU domain and a device/group are incompatible. It also drops the useless domain->ops check since it won't fail in current environment. These allow V

Re: [PATCH v2 3/5] vfio/iommu_type1: Remove the domain->ops comparison

2022-06-23 Thread Nicolin Chen via iommu
On Thu, Jun 23, 2022 at 03:50:22AM +, Tian, Kevin wrote: > External email: Use caution opening links or attachments > > > > From: Robin Murphy > > Sent: Wednesday, June 22, 2022 3:55 PM > > > > On 2022-06-16 23:23, Nicolin Chen wrote: > > > On Thu, Jun 16, 2022 at 06:40:14AM +, Tian, Kev

Re: [PATCH v2 2/5] vfio/iommu_type1: Prefer to reuse domains vs match enforced cache coherency

2022-06-21 Thread Nicolin Chen via iommu
On Tue, Jun 21, 2022 at 04:46:02PM -0600, Alex Williamson wrote: > External email: Use caution opening links or attachments > > > On Wed, 15 Jun 2022 17:03:01 -0700 > Nicolin Chen wrote: > > > From: Jason Gunthorpe > > > > The KVM mechanism for controlling wbinvd is based on OR of the coherenc

Re: [PATCH v2 5/5] vfio/iommu_type1: Simplify group attachment

2022-06-21 Thread Nicolin Chen via iommu
On Mon, Jun 20, 2022 at 11:11:01AM +0100, Robin Murphy wrote: > External email: Use caution opening links or attachments > > > On 2022-06-17 03:53, Tian, Kevin wrote: > > > From: Nicolin Chen > > > Sent: Friday, June 17, 2022 6:41 AM > > > > > > > ... > > > > > - if (resv_msi) { > > > > > +

Re: [PATCH v2 5/5] vfio/iommu_type1: Simplify group attachment

2022-06-21 Thread Nicolin Chen via iommu
On Mon, Jun 20, 2022 at 01:03:17AM -0300, Jason Gunthorpe wrote: > On Fri, Jun 17, 2022 at 04:07:20PM -0700, Nicolin Chen wrote: > > > > > > > + vfio_iommu_aper_expand(iommu, &iova_copy); > > > > > > > > > > but now it's done for every group detach. The aperture is decided > > > > > by domain

Re: [PATCH v2 5/5] vfio/iommu_type1: Simplify group attachment

2022-06-17 Thread Nicolin Chen via iommu
On Fri, Jun 17, 2022 at 02:53:13AM +, Tian, Kevin wrote: > > > ... > > > > - if (resv_msi) { > > > > + if (resv_msi && !domain->msi_cookie) { > > > > ret = iommu_get_msi_cookie(domain->domain, > > > > resv_msi_base); > > > > if (ret && ret != -ENODEV) > > > >

Re: [PATCH v2 5/5] vfio/iommu_type1: Simplify group attachment

2022-06-16 Thread Nicolin Chen via iommu
On Thu, Jun 16, 2022 at 07:08:10AM +, Tian, Kevin wrote: > ... > > +static struct vfio_domain * > > +vfio_iommu_alloc_attach_domain(struct bus_type *bus, struct vfio_iommu > > *iommu, > > +struct vfio_iommu_group *group) > > +{ > > + struct iommu_domain *new_doma

Re: [PATCH v2 4/5] vfio/iommu_type1: Clean up update_dirty_scope in detach_group()

2022-06-16 Thread Nicolin Chen via iommu
On Thu, Jun 16, 2022 at 06:45:09AM +, Tian, Kevin wrote: > > +out_unlock: > > mutex_unlock(&iommu->lock); > > } > > > > I'd just replace the goto with a direct unlock and then return there. > the readability is slightly better. OK. Will do that. ___

Re: [PATCH v2 3/5] vfio/iommu_type1: Remove the domain->ops comparison

2022-06-16 Thread Nicolin Chen via iommu
On Thu, Jun 16, 2022 at 06:40:14AM +, Tian, Kevin wrote: > > The domain->ops validation was added, as a precaution, for mixed-driver > > systems. However, at this moment only one iommu driver is possible. So > > remove it. > > It's true on a physical platform. But I'm not sure whether a virtu

Re: [PATCH v2 1/5] iommu: Return -EMEDIUMTYPE for incompatible domain and device/group

2022-06-15 Thread Nicolin Chen via iommu
On Thu, Jun 16, 2022 at 10:09:49AM +0800, Baolu Lu wrote: > External email: Use caution opening links or attachments > > > On 2022/6/16 08:03, Nicolin Chen wrote: > > diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c > > index 44016594831d..0dd13330fe12 100644 > > --- a/drive

[PATCH v2 5/5] vfio/iommu_type1: Simplify group attachment

2022-06-15 Thread Nicolin Chen via iommu
Un-inline the domain specific logic from the attach/detach_group ops into two paired functions vfio_iommu_alloc_attach_domain() and vfio_iommu_detach_destroy_domain() that strictly deal with creating and destroying struct vfio_domains. Add the logic to check for EMEDIUMTYPE return code of iommu_at

[PATCH v2 3/5] vfio/iommu_type1: Remove the domain->ops comparison

2022-06-15 Thread Nicolin Chen via iommu
The domain->ops validation was added, as a precaution, for mixed-driver systems. However, at this moment only one iommu driver is possible. So remove it. Per discussion with Robin, in future when many can be permitted we will rely on the IOMMU core code to check the domain->ops: https://lore.kerne

[PATCH v2 4/5] vfio/iommu_type1: Clean up update_dirty_scope in detach_group()

2022-06-15 Thread Nicolin Chen via iommu
All devices in emulated_iommu_groups have pinned_page_dirty_scope set, so the update_dirty_scope in the first list_for_each_entry is always false. Clean it up, and move the "if update_dirty_scope" part from the detach_group_done routine to the domain_list part. Rename the "detach_group_done" goto

[PATCH v2 1/5] iommu: Return -EMEDIUMTYPE for incompatible domain and device/group

2022-06-15 Thread Nicolin Chen via iommu
Cases like VFIO wish to attach a device to an existing domain that was not allocated specifically from the device. This raises a condition where the IOMMU driver can fail the domain attach because the domain and device are incompatible with each other. This is a soft failure that can be resolved b

[PATCH v2 2/5] vfio/iommu_type1: Prefer to reuse domains vs match enforced cache coherency

2022-06-15 Thread Nicolin Chen via iommu
From: Jason Gunthorpe The KVM mechanism for controlling wbinvd is based on OR of the coherency property of all devices attached to a guest, no matter those devices are attached to a single domain or multiple domains. So, there is no value in trying to push a device that could do enforced cache c

[PATCH v2 0/5] Simplify vfio_iommu_type1 attach/detach routine

2022-06-15 Thread Nicolin Chen via iommu
This is a preparatory series for IOMMUFD v2 patches. It enforces error code -EMEDIUMTYPE in iommu_attach_device() and iommu_attach_group() when an IOMMU domain and a device/group are incompatible. It also drops the useless domain->ops check since it won't fail in current environment. These allow V

Re: [PATCH 3/5] vfio/iommu_type1: Prefer to reuse domains vs match enforced cache coherency

2022-06-15 Thread Nicolin Chen via iommu
On Wed, Jun 15, 2022 at 07:35:00AM +, Tian, Kevin wrote: > External email: Use caution opening links or attachments > > > > From: Nicolin Chen > > Sent: Wednesday, June 15, 2022 4:45 AM > > > > Hi Kevin, > > > > On Wed, Jun 08, 2022 at 11:48:27PM +, Tian, Kevin wrote: > > > > > > The KVM

Re: [PATCH 3/5] vfio/iommu_type1: Prefer to reuse domains vs match enforced cache coherency

2022-06-14 Thread Nicolin Chen via iommu
Hi Kevin, On Wed, Jun 08, 2022 at 11:48:27PM +, Tian, Kevin wrote: > > > > The KVM mechanism for controlling wbinvd is only triggered during > > > > kvm_vfio_group_add(), meaning it is a one-shot test done once the > > devices > > > > are setup. > > > > > > It's not one-shot. kvm_vfio_update_c

Re: [PATCH 4/5] vfio/iommu_type1: Clean up update_dirty_scope in detach_group()

2022-06-08 Thread Nicolin Chen via iommu
On Wed, Jun 08, 2022 at 08:35:47AM +, Tian, Kevin wrote: > > @@ -2519,7 +2515,17 @@ static void vfio_iommu_type1_detach_group(void > > *iommu_data, > > kfree(domain); > > vfio_iommu_aper_expand(iommu, &iova_copy); > > vfio_updat

Re: [PATCH 1/5] iommu: Return -EMEDIUMTYPE for incompatible domain and device/group

2022-06-08 Thread Nicolin Chen via iommu
Hi Kevin, On Wed, Jun 08, 2022 at 07:49:10AM +, Tian, Kevin wrote: > External email: Use caution opening links or attachments > > > > From: Nicolin Chen > > Sent: Monday, June 6, 2022 2:19 PM > > > > Cases like VFIO wish to attach a device to an existing domain that was > > not allocated spe

Re: [PATCH 1/5] iommu: Return -EMEDIUMTYPE for incompatible domain and device/group

2022-06-06 Thread Nicolin Chen via iommu
On Tue, Jun 07, 2022 at 11:23:27AM +0800, Baolu Lu wrote: > External email: Use caution opening links or attachments > > > On 2022/6/6 14:19, Nicolin Chen wrote: > > +/** > > + * iommu_attach_group - Attach an IOMMU group to an IOMMU domain > > + * @domain: IOMMU domain to attach > > + * @dev: IO

Re: [PATCH 2/5] iommu: Ensure device has the same iommu_ops as the domain

2022-06-06 Thread Nicolin Chen via iommu
On Mon, Jun 06, 2022 at 06:50:33PM +0100, Robin Murphy wrote: > External email: Use caution opening links or attachments > > > On 2022-06-06 17:51, Nicolin Chen wrote: > > Hi Robin, > > > > On Mon, Jun 06, 2022 at 03:33:42PM +0100, Robin Murphy wrote: > > > On 2022-06-06 07:19, Nicolin Chen wrot

Re: [PATCH 2/5] iommu: Ensure device has the same iommu_ops as the domain

2022-06-06 Thread Nicolin Chen via iommu
Hi Robin, On Mon, Jun 06, 2022 at 03:33:42PM +0100, Robin Murphy wrote: > On 2022-06-06 07:19, Nicolin Chen wrote: > > The core code should not call an iommu driver op with a struct device > > parameter unless it knows that the dev_iommu_priv_get() for that struct > > device was setup by the same

[PATCH 4/5] vfio/iommu_type1: Clean up update_dirty_scope in detach_group()

2022-06-05 Thread Nicolin Chen via iommu
All devices in emulated_iommu_groups have pinned_page_dirty_scope set, so the update_dirty_scope in the first list_for_each_entry is always false. Clean it up, and move the "if update_dirty_scope" part from the detach_group_done routine to the domain_list part. Rename the "detach_group_done" goto

[PATCH 5/5] vfio/iommu_type1: Simplify group attachment

2022-06-05 Thread Nicolin Chen via iommu
Un-inline the domain specific logic from the attach/detach_group ops into two paired functions vfio_iommu_alloc_attach_domain() and vfio_iommu_detach_destroy_domain() that strictly deal with creating and destroying struct vfio_domains. Add the logic to check for EMEDIUMTYPE return code of iommu_at

[PATCH 3/5] vfio/iommu_type1: Prefer to reuse domains vs match enforced cache coherency

2022-06-05 Thread Nicolin Chen via iommu
From: Jason Gunthorpe The KVM mechanism for controlling wbinvd is only triggered during kvm_vfio_group_add(), meaning it is a one-shot test done once the devices are setup. So, there is no value in trying to push a device that could do enforced cache coherency to a dedicated domain vs re-using a

[PATCH 2/5] iommu: Ensure device has the same iommu_ops as the domain

2022-06-05 Thread Nicolin Chen via iommu
The core code should not call an iommu driver op with a struct device parameter unless it knows that the dev_iommu_priv_get() for that struct device was setup by the same driver. Otherwise in a mixed driver system the iommu_priv could be casted to the wrong type. Store the iommu_ops pointer in the

[PATCH 1/5] iommu: Return -EMEDIUMTYPE for incompatible domain and device/group

2022-06-05 Thread Nicolin Chen via iommu
Cases like VFIO wish to attach a device to an existing domain that was not allocated specifically from the device. This raises a condition where the IOMMU driver can fail the domain attach because the domain and device are incompatible with each other. This is a soft failure that can be resolved b

[PATCH 0/5] Simplify vfio_iommu_type1 attach/detach routine

2022-06-05 Thread Nicolin Chen via iommu
This is a preparatory series for IOMMUFD v2 patches. It enforces error code -EMEDIUMTYPE in iommu_attach_device() and iommu_attach_group() when an IOMMU domain and a device/group are incompatible. It also moves the domain->ops check into __iommu_attach_device(). These allow VFIO iommu code to simpl

Re: [PATCH] iommu/vt-d: Try info->iommu in device_to_iommu()

2022-05-13 Thread Nicolin Chen via iommu
On Fri, May 13, 2022 at 08:50:32AM -0300, Jason Gunthorpe wrote: > > Perhaps, we can make device_to_iommu() only for probe_device() where the > > per-device info data is not initialized yet. After probe_device(), iommu > > and sid are retrieved through other helpers by looking up the device > > in

Re: [PATCH] iommu/vt-d: Try info->iommu in device_to_iommu()

2022-05-12 Thread Nicolin Chen via iommu
On Fri, May 13, 2022 at 11:32:11AM +0800, Baolu Lu wrote: > External email: Use caution opening links or attachments > > > On 2022/5/13 08:32, Nicolin Chen wrote: > > Local boot test and VFIO sanity test show that info->iommu can be > > used in device_to_iommu() as a fast path. So this patch adds

[PATCH] iommu/vt-d: Try info->iommu in device_to_iommu()

2022-05-12 Thread Nicolin Chen via iommu
Local boot test and VFIO sanity test show that info->iommu can be used in device_to_iommu() as a fast path. So this patch adds it. Signed-off-by: Nicolin Chen --- drivers/iommu/intel/iommu.c | 5 + 1 file changed, 5 insertions(+) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/inte

Re: [PATCH] vfio: Remove VFIO_TYPE1_NESTING_IOMMU

2022-05-10 Thread Nicolin Chen via iommu
On Tue, May 10, 2022 at 01:55:24PM -0300, Jason Gunthorpe wrote: > This control causes the ARM SMMU drivers to choose a stage 2 > implementation for the IO pagetable (vs the stage 1 usual default), > however this choice has no visible impact to the VFIO user. Further qemu > never implemented this a

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

2022-05-04 Thread Nicolin Chen via iommu
On Tue, May 03, 2022 at 09:11:02PM -0300, Jason Gunthorpe wrote: > This is based on Robins draft here: > > https://lore.kernel.org/linux-iommu/18831161-473f-e04f-4a81-1c7062ad1...@arm.com/ > > With some rework. I re-organized the call chains instead of introducing > iommu_group_user_attached(),

Re: [PATCH] iommu/arm-smmu-v3: Fix size calculation in arm_smmu_mm_invalidate_range()

2022-04-19 Thread Nicolin Chen via iommu
On Tue, Apr 19, 2022 at 08:10:34PM -0300, Jason Gunthorpe wrote: > > - size_t size = end - start + 1; > > + size_t size; > > + > > + /* > > + * The mm_types defines vm_end as the first byte after the end > > address, > > + * different from IOMMU subsystem using the last addr

[PATCH] iommu/arm-smmu-v3: Fix size calculation in arm_smmu_mm_invalidate_range()

2022-04-19 Thread Nicolin Chen via iommu
The arm_smmu_mm_invalidate_range function is designed to be called by mm core for Shared Virtual Addressing purpose between IOMMU and CPU MMU. However, the ways of two subsystems defining their "end" addresses are slightly different. IOMMU defines its "end" address using the last address of an addr

Re: [PATCH] iommu/arm-smmu-v3: Align size in __arm_smmu_tlb_inv_range

2022-04-19 Thread Nicolin Chen via iommu
On Tue, Apr 19, 2022 at 05:02:33PM -0300, Jason Gunthorpe wrote: > > diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c > > b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c > > index d816759a6bcf..e280568bb513 100644 > > +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c > > @@ -183

Re: [PATCH] iommu/arm-smmu-v3: Align size in __arm_smmu_tlb_inv_range

2022-04-15 Thread Nicolin Chen via iommu
On Thu, Apr 14, 2022 at 11:32:38AM +0100, Robin Murphy wrote: > > By looking at the call trace within arm_smmu_* functions: > >__arm_smmu_tlb_inv_range > >arm_smmu_tlb_inv_range_asid > >arm_smmu_mm_invalidate_range > >{from mm_notifier_* functions} > > > > There's no address alignm

Re: [PATCH] iommu/arm-smmu-v3: Align size in __arm_smmu_tlb_inv_range

2022-04-14 Thread Nicolin Chen via iommu
On Thu, Apr 14, 2022 at 11:32:38AM +0100, Robin Murphy wrote: > External email: Use caution opening links or attachments > > > On 2022-04-13 21:19, Nicolin Chen wrote: > > Hi Robin, > > > > On Wed, Apr 13, 2022 at 02:40:31PM +0100, Robin Murphy wrote: > > > On 2022-04-13 05:17, Nicolin Chen wrot

Re: [PATCH] iommu/arm-smmu-v3: Align size in __arm_smmu_tlb_inv_range

2022-04-13 Thread Nicolin Chen via iommu
Hi Robin, On Wed, Apr 13, 2022 at 02:40:31PM +0100, Robin Murphy wrote: > On 2022-04-13 05:17, Nicolin Chen wrote: > > To calculate num_pages, the size should be aligned with > > "page size", determined by the tg value. Otherwise, its > > following "while (iova < end)" might become an infinite > >

[PATCH] iommu/arm-smmu-v3: Align size in __arm_smmu_tlb_inv_range

2022-04-12 Thread Nicolin Chen via iommu
To calculate num_pages, the size should be aligned with "page size", determined by the tg value. Otherwise, its following "while (iova < end)" might become an infinite loop if unaligned size is slightly greater than 1 << tg. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-

Re: [PATCH v3 5/5] iommu/nvidia-grace-cmdqv: Limit CMDs for guest owned VINTF

2021-12-27 Thread Nicolin Chen via iommu
On Fri, Dec 24, 2021 at 12:13:57PM +, Robin Murphy wrote: > > > > > > @@ -176,6 +177,24 @@ struct arm_smmu_cmdq > > > > > > *nvidia_grace_cmdqv_get_cmdq(struct arm_smmu_device *smmu) > > > > > > if (!FIELD_GET(VINTF_STATUS, vintf0->status)) > > > > > > return &smmu->cm

Re: [PATCH v3 5/5] iommu/nvidia-grace-cmdqv: Limit CMDs for guest owned VINTF

2021-12-24 Thread Nicolin Chen via iommu
pening links or attachments > > > > > > > > > On 2021-11-19 07:19, Nicolin Chen via iommu wrote: > > > > When VCMDQs are assigned to a VINTF that is owned by a guest, not > > > > hypervisor (HYP_OWN bit is unset), only TLB invalidation comm

Re: [PATCH v3 5/5] iommu/nvidia-grace-cmdqv: Limit CMDs for guest owned VINTF

2021-12-22 Thread Nicolin Chen via iommu
On Wed, Dec 22, 2021 at 12:32:29PM +, Robin Murphy wrote: > External email: Use caution opening links or attachments > > > On 2021-11-19 07:19, Nicolin Chen via iommu wrote: > > When VCMDQs are assigned to a VINTF that is owned by a guest, not > > hypervisor (HYP_OWN

Re: [PATCH v3 4/5] iommu/arm-smmu-v3: Add host support for NVIDIA Grace CMDQ-V

2021-12-21 Thread Nicolin Chen via iommu
On Tue, Dec 21, 2021 at 06:55:20PM +, Robin Murphy wrote: > External email: Use caution opening links or attachments > > > On 2021-12-20 19:27, Nicolin Chen wrote: > > Hi Robin, > > > > Thank you for the reply! > > > > On Mon, Dec 20, 2021 at 06:42:26PM +, Robin Murphy wrote: > > > On 2

Re: [PATCH v3 4/5] iommu/arm-smmu-v3: Add host support for NVIDIA Grace CMDQ-V

2021-12-20 Thread Nicolin Chen via iommu
Hi Robin, Thank you for the reply! On Mon, Dec 20, 2021 at 06:42:26PM +, Robin Murphy wrote: > On 2021-11-19 07:19, Nicolin Chen wrote: > > From: Nate Watterson > > > > NVIDIA's Grace Soc has a CMDQ-Virtualization (CMDQV) hardware, > > which extends the standard ARM SMMU v3 IP to support mu

Re: [PATCH v8 6/6] iommu/tegra-smmu: Add pagetable mappings to debugfs

2021-12-09 Thread Nicolin Chen via iommu
On Thu, Dec 09, 2021 at 10:58:15PM +0300, Dmitry Osipenko wrote: > External email: Use caution opening links or attachments > > > 09.12.2021 22:51, Nicolin Chen пишет: > > On Thu, Dec 09, 2021 at 10:40:42PM +0300, Dmitry Osipenko wrote: > >> External email: Use caution opening links or attachment

Re: [PATCH v8 6/6] iommu/tegra-smmu: Add pagetable mappings to debugfs

2021-12-09 Thread Nicolin Chen via iommu
On Thu, Dec 09, 2021 at 10:58:32PM +0300, Dmitry Osipenko wrote: > External email: Use caution opening links or attachments > > > 09.12.2021 22:54, Nicolin Chen пишет: > > On Thu, Dec 09, 2021 at 10:44:25PM +0300, Dmitry Osipenko wrote: > >> External email: Use caution opening links or attachment

Re: [PATCH v8 6/6] iommu/tegra-smmu: Add pagetable mappings to debugfs

2021-12-09 Thread Nicolin Chen via iommu
On Thu, Dec 09, 2021 at 10:44:25PM +0300, Dmitry Osipenko wrote: > External email: Use caution opening links or attachments > > > 09.12.2021 22:24, Nicolin Chen пишет: > > On Thu, Dec 09, 2021 at 05:49:09PM +0300, Dmitry Osipenko wrote: > >> External email: Use caution opening links or attachment

Re: [PATCH v8 6/6] iommu/tegra-smmu: Add pagetable mappings to debugfs

2021-12-09 Thread Nicolin Chen via iommu
On Thu, Dec 09, 2021 at 10:40:42PM +0300, Dmitry Osipenko wrote: > External email: Use caution opening links or attachments > > > 09.12.2021 22:32, Nicolin Chen пишет: > > On Thu, Dec 09, 2021 at 05:47:18PM +0300, Dmitry Osipenko wrote: > >> External email: Use caution opening links or attachment

Re: [PATCH v8 6/6] iommu/tegra-smmu: Add pagetable mappings to debugfs

2021-12-09 Thread Nicolin Chen via iommu
On Thu, Dec 09, 2021 at 05:47:18PM +0300, Dmitry Osipenko wrote: > External email: Use caution opening links or attachments > > > 09.12.2021 10:38, Nicolin Chen пишет: > > @@ -545,6 +719,15 @@ static void tegra_smmu_detach_as(struct tegra_smmu > > *smmu, > > if (group->swgrp != swg

Re: [PATCH v8 6/6] iommu/tegra-smmu: Add pagetable mappings to debugfs

2021-12-09 Thread Nicolin Chen via iommu
On Thu, Dec 09, 2021 at 05:49:09PM +0300, Dmitry Osipenko wrote: > External email: Use caution opening links or attachments > > > 09.12.2021 10:38, Nicolin Chen пишет: > > +static unsigned long pd_pt_index_iova(unsigned int pd_index, unsigned int > > pt_index) > > +{ > > + return (pd_index &

[PATCH v8 6/6] iommu/tegra-smmu: Add pagetable mappings to debugfs

2021-12-08 Thread Nicolin Chen via iommu
This patch dumps all active mapping entries from pagetable to a debugfs directory named "mappings". Part of this patch for listing all swgroup names in a group_soc is provided by Dmitry Osipenko Attaching an example: [SWGROUP: xusb_host] [as: (id: 5), (attr: R|W|-), (pd_dma: 0x80005000)

[PATCH v8 4/6] iommu/tegra-smmu: Use swgrp pointer instead of swgroup id

2021-12-08 Thread Nicolin Chen via iommu
This patch changes in struct tegra_smmu_group to use swgrp pointer instead of swgroup, as a preparational change for the "mappings" debugfs feature. Acked-by: Thierry Reding Signed-off-by: Nicolin Chen --- drivers/iommu/tegra-smmu.c | 12 1 file changed, 8 insertions(+), 4 deletion

[PATCH v8 2/6] iommu/tegra-smmu: Rename tegra_smmu_find_group to tegra_smmu_find_group_soc

2021-12-08 Thread Nicolin Chen via iommu
The existing function tegra_smmu_find_group really finds group->soc pointer, so naming it "find_group" might not be clear by looking at it alone. This patch renames it to tegra_smmu_group_soc in order to disambiguate the use of "group" in this driver. Signed-off-by: Nicolin Chen --- drivers/iomm

[PATCH v8 3/6] iommu/tegra-smmu: Rename struct tegra_smmu_swgroup *group to *swgrp

2021-12-08 Thread Nicolin Chen via iommu
There are both tegra_smmu_swgroup and tegra_smmu_group structs using "group" for their pointer instances. This gets confusing to read the driver sometimes. So this patch renames "group" of struct tegra_smmu_swgroup to "swgrp" as a cleanup. Also renames its "find" function. Note that we already ha

[PATCH v8 5/6] iommu/tegra-smmu: Attach as pointer to tegra_smmu_group

2021-12-08 Thread Nicolin Chen via iommu
This could ease driver to access corresponding as pointer when having tegra_smmu_group pointer only, which can help new mappings debugfs nodes. Also moving tegra_smmu_find_group_soc() upward, for using it in new tegra_smmu_attach_as(); and it's better to have all tegra_smmu_find_* functions togeth

[PATCH v8 0/6] iommu/tegra-smmu: Add pagetable mappings to debugfs

2021-12-08 Thread Nicolin Chen via iommu
This series of patches adds a new mappings node to debugfs for tegra-smmu driver. The first five patches are all preparational changes for PATCH-6, based on Thierry's review feedback against v5. Changelog v8: * No changes for PATCH 1-4 * PATCH-5: * * bypassed "group->as == as" to fix KMSG bug r

[PATCH v8 1/6] iommu/tegra-smmu: Rename struct iommu_group *group to *grp

2021-12-08 Thread Nicolin Chen via iommu
There are a few structs using "group" for their pointer instances. This gets confusing sometimes. The instance of struct iommu_group is used in local function with an alias "grp", which can separate it from others. So this patch simply renames "group" to "grp" as a cleanup. Acked-by: Thierry Redi

Re: [PATCH v7 6/6] iommu/tegra-smmu: Add pagetable mappings to debugfs

2021-12-08 Thread Nicolin Chen via iommu
On Wed, Dec 08, 2021 at 07:09:37PM +0300, Dmitry Osipenko wrote: > External email: Use caution opening links or attachments > > > 08.12.2021 11:47, Nicolin Chen пишет: > > static void tegra_smmu_attach_as(struct tegra_smmu *smmu, > >struct tegra_smmu_as *as, > >

[PATCH v7 0/6] iommu/tegra-smmu: Add pagetable mappings to debugfs

2021-12-08 Thread Nicolin Chen via iommu
This series of patches adds a new mappings node to debugfs for tegra-smmu driver. The first five patches are all preparational changes for PATCH-6, based on Thierry's review feedback against v5. Changelog v7: * Added "Acked-by" from Thierry to PATCH1,4,5 * No other changes for PATCH1,3,4,5 * PA

[PATCH v7 1/6] iommu/tegra-smmu: Rename struct iommu_group *group to *grp

2021-12-08 Thread Nicolin Chen via iommu
There are a few structs using "group" for their pointer instances. This gets confusing sometimes. The instance of struct iommu_group is used in local function with an alias "grp", which can separate it from others. So this patch simply renames "group" to "grp" as a cleanup. Acked-by: Thierry Redi

[PATCH v7 6/6] iommu/tegra-smmu: Add pagetable mappings to debugfs

2021-12-08 Thread Nicolin Chen via iommu
This patch dumps all active mapping entries from pagetable to a debugfs directory named "mappings". Attaching an example: [SWGROUP: xusb_host] [as: (id: 5), (attr: R|W|-), (pd_dma: 0x80005000)] { [index: 1023] 0xf0080040 (count: 52) { PTE RANGE | ATTR

[PATCH v7 3/6] iommu/tegra-smmu: Rename struct tegra_smmu_swgroup *group to *swgrp

2021-12-08 Thread Nicolin Chen via iommu
There are both tegra_smmu_swgroup and tegra_smmu_group structs using "group" for their pointer instances. This gets confusing to read the driver sometimes. So this patch renames "group" of struct tegra_smmu_swgroup to "swgrp" as a cleanup. Also renames its "find" function. Note that we already ha

[PATCH v7 4/6] iommu/tegra-smmu: Use swgrp pointer instead of swgroup id

2021-12-08 Thread Nicolin Chen via iommu
This patch changes in struct tegra_smmu_group to use swgrp pointer instead of swgroup, as a preparational change for the "mappings" debugfs feature. Acked-by: Thierry Reding Signed-off-by: Nicolin Chen --- drivers/iommu/tegra-smmu.c | 12 1 file changed, 8 insertions(+), 4 deletion

[PATCH v7 2/6] iommu/tegra-smmu: Rename tegra_smmu_find_group to tegra_smmu_find_group_soc

2021-12-08 Thread Nicolin Chen via iommu
The existing function tegra_smmu_find_group really finds group->soc pointer, so naming it "find_group" might not be clear by looking at it alone. This patch renames it to tegra_smmu_group_soc in order to disambiguate the use of "group" in this driver. Signed-off-by: Nicolin Chen --- drivers/iomm

[PATCH v7 5/6] iommu/tegra-smmu: Attach as pointer to tegra_smmu_group

2021-12-08 Thread Nicolin Chen via iommu
This could ease driver to access corresponding as pointer when having tegra_smmu_group pointer only, which can help new mappings debugfs nodes. Also moving tegra_smmu_find_group_soc() upward, for using it in new tegra_smmu_attach_as(); and it's better to have all tegra_smmu_find_* functions togeth

[PATCH v3 4/5] iommu/arm-smmu-v3: Add host support for NVIDIA Grace CMDQ-V

2021-11-18 Thread Nicolin Chen via iommu
From: Nate Watterson NVIDIA's Grace Soc has a CMDQ-Virtualization (CMDQV) hardware, which extends the standard ARM SMMU v3 IP to support multiple VCMDQs with virtualization capabilities. In-kernel of host OS, they're used to reduce contention on a single queue. In terms of command queue, they are

[PATCH v3 2/5] iommu/arm-smmu-v3: Make arm_smmu_cmdq_init reusable

2021-11-18 Thread Nicolin Chen via iommu
The CMDQV extension in NVIDIA Grace SoC resues the arm_smmu_cmdq structure while the queue location isn't same as smmu->cmdq. So, this patch adds a cmdq argument to arm_smmu_cmdq_init() function and shares its define in the header for CMDQV driver to use. Signed-off-by: Nicolin Chen --- drivers/

[PATCH v3 5/5] iommu/nvidia-grace-cmdqv: Limit CMDs for guest owned VINTF

2021-11-18 Thread Nicolin Chen via iommu
When VCMDQs are assigned to a VINTF that is owned by a guest, not hypervisor (HYP_OWN bit is unset), only TLB invalidation commands are supported. This requires get_cmd() function to scan the input cmd before selecting cmdq between smmu->cmdq and vintf->vcmdq, so unsupported commands can still go t

[PATCH v3 3/5] iommu/arm-smmu-v3: Pass cmdq pointer in arm_smmu_cmdq_issue_cmdlist()

2021-11-18 Thread Nicolin Chen via iommu
The driver currently calls arm_smmu_get_cmdq() helper internally in different places, though they are all actually called from the same source -- arm_smmu_cmdq_issue_cmdlist() function. This patch changes this to pass the cmdq pointer to these functions instead of calling arm_smmu_get_cmdq() every

[PATCH v3 1/5] iommu/arm-smmu-v3: Add CS_NONE quirk

2021-11-18 Thread Nicolin Chen via iommu
The CMDQV extension in NVIDIA Grace SoC only supports CS_NONE in the CS field of CMD_SYNC. So this patch adds a quirk flag to accommodate that. Signed-off-by: Nicolin Chen --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 7 ++- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 4 2 files c

[PATCH v3 0/5] iommu/arm-smmu-v3: Add NVIDIA Grace CMDQ-V Support

2021-11-18 Thread Nicolin Chen via iommu
From: Nicolin Chen NVIDIA's Grace SoC has a CMDQ-Virtualization (CMDQV) hardware that extends standard ARM SMMUv3 to support multiple command queues with virtualization capabilities. Though this is similar to the ECMDQ in SMMUv3.3, CMDQV provides additional V-Interfaces that allow VMs to have the

Re: [RFC][PATCH v2 00/13] iommu/arm-smmu-v3: Add NVIDIA implementation

2021-09-16 Thread Nicolin Chen via iommu
Hi Kevin, On Thu, Sep 02, 2021 at 10:27:06PM +, Tian, Kevin wrote: > > Indeed, this looks like a flavour of the accelerated invalidation > > stuff we've talked about already. > > > > I would see it probably exposed as some HW specific IOCTL on the iommu > > fd to get access to the accelerated

[RFC][PATCH v2 12/13] iommu/arm-smmu-v3: Add support for NVIDIA CMDQ-Virtualization hw

2021-08-30 Thread Nicolin Chen via iommu
From: Nate Watterson NVIDIA's Grace SoC has a CMDQ-Virtualization (CMDQV) hardware, which adds multiple VCMDQ interfaces (VINTFs) to supplement the architected SMMU_CMDQ in an effort to reduce contention. To make use of these supplemental CMDQs in arm-smmu-v3 driver, this patch borrows the "impl

[RFC][PATCH v2 10/13] iommu/arm-smmu-v3: Pass cmdq pointer in arm_smmu_cmdq_issue_cmdlist()

2021-08-30 Thread Nicolin Chen via iommu
The driver currently calls arm_smmu_get_cmdq() helper internally in different places, though they are all actually called from the same source -- arm_smmu_cmdq_issue_cmdlist() function. This patch changes this to pass the cmdq pointer to these functions instead of calling arm_smmu_get_cmdq() every

  1   2   >