Re: [PATCH v7 07/10] iommufd: Fault-capable hwpt attach/detach/replace

2024-07-10 Thread Baolu Lu
On 2024/7/10 1:36, Jason Gunthorpe wrote: On Mon, Jul 01, 2024 at 01:55:12PM +0800, Baolu Lu wrote: On 2024/6/29 5:17, Jason Gunthorpe wrote: On Sun, Jun 16, 2024 at 02:11:52PM +0800, Lu Baolu wrote: +static int iommufd_fault_iopf_enable(struct iommufd_device *idev) +{ + struct device

Re: [PATCH v8 06/10] iommufd: Add iommufd fault object

2024-07-04 Thread Baolu Lu
On 2024/7/4 14:37, Tian, Kevin wrote: From: Nicolin Chen Sent: Thursday, July 4, 2024 1:36 PM On Thu, Jul 04, 2024 at 10:59:45AM +0800, Baolu Lu wrote: On Tue, Jul 02, 2024 at 02:34:40PM +0800, Lu Baolu wrote: +enum iommu_fault_type { + IOMMU_FAULT_TYPE_HWPT_IOPF

Re: [PATCH v8 06/10] iommufd: Add iommufd fault object

2024-07-03 Thread Baolu Lu
On 7/4/24 7:06 AM, Nicolin Chen wrote: Hi Baolu, Hi Nicolin, On Tue, Jul 02, 2024 at 02:34:40PM +0800, Lu Baolu wrote: An iommufd fault object provides an interface for delivering I/O page faults to user space. These objects are created and destroyed by user space, and they can be associate

Re: [PATCH v7 00/10] IOMMUFD: Deliver IO page faults to user space

2024-07-01 Thread Baolu Lu
On 2024/6/29 6:14, Jason Gunthorpe wrote: On Sun, Jun 16, 2024 at 02:11:45PM +0800, Lu Baolu wrote: Lu Baolu (10): iommu: Introduce domain attachment handle iommu: Remove sva handle list iommu: Add attach handle to struct iopf_group iommu: Extend domain attach group with handle supp

Re: [PATCH v7 07/10] iommufd: Fault-capable hwpt attach/detach/replace

2024-06-30 Thread Baolu Lu
On 2024/6/29 5:17, Jason Gunthorpe wrote: On Sun, Jun 16, 2024 at 02:11:52PM +0800, Lu Baolu wrote: +static int iommufd_fault_iopf_enable(struct iommufd_device *idev) +{ + struct device *dev = idev->dev; + int ret; + + /* +* Once we turn on PCI/PRI support for VF, the r

Re: [PATCH v7 08/10] iommufd: Associate fault object with iommufd_hw_pgtable

2024-06-30 Thread Baolu Lu
On 2024/6/29 6:13, Jason Gunthorpe wrote: On Sun, Jun 16, 2024 at 02:11:53PM +0800, Lu Baolu wrote: @@ -308,13 +315,29 @@ int iommufd_hwpt_alloc(struct iommufd_ucmd *ucmd) goto out_put_pt; } + if (cmd->flags & IOMMU_HWPT_FAULT_ID_VALID) { + struct iommu

Re: [PATCH v7 04/10] iommu: Extend domain attach group with handle support

2024-06-28 Thread Baolu Lu
On 2024/6/29 5:06, Jason Gunthorpe wrote: On Sun, Jun 16, 2024 at 02:11:49PM +0800, Lu Baolu wrote: +int iommu_replace_group_handle(struct iommu_group *group, + struct iommu_domain *new_domain, + struct iommu_attach_handle *handle) +{ +

Re: [PATCH v7 03/10] iommu: Add attach handle to struct iopf_group

2024-06-17 Thread Baolu Lu
On 6/17/24 3:41 PM, Tian, Kevin wrote: From: Lu Baolu Sent: Sunday, June 16, 2024 2:12 PM Add a new IOMMU capability flag, IOMMU_CAP_USER_IOASID_TABLE, which indicates if the IOMMU driver supports user-managed PASID tables. In the iopf deliver path, if no attach handle found for the iopf PASID,

Re: [PATCH v6 03/10] iommu: Add attach handle to struct iopf_group

2024-06-13 Thread Baolu Lu
On 6/13/24 7:49 PM, Jason Gunthorpe wrote: On Thu, Jun 13, 2024 at 12:23:17PM +0800, Baolu Lu wrote: struct iommu_ops { bool (*capable)(struct device *dev, enum iommu_cap); @@ -600,6 +598,7 @@ struct iommu_ops { struct iommu_domain *blocked_domain; struct

Re: [PATCH v6 00/10] IOMMUFD: Deliver IO page faults to user space

2024-06-12 Thread Baolu Lu
On 6/12/24 9:54 PM, Jason Gunthorpe wrote: On Mon, May 27, 2024 at 12:05:07PM +0800, Lu Baolu wrote: This series implements the functionality of delivering IO page faults to user space through the IOMMUFD framework. One feasible use case is the nested translation. Nested translation is a hardwar

Re: [PATCH v6 06/10] iommufd: Add iommufd fault object

2024-06-12 Thread Baolu Lu
On 6/12/24 9:25 PM, Jason Gunthorpe wrote: On Sat, Jun 08, 2024 at 05:58:34PM +0800, Baolu Lu wrote: +static int iommufd_fault_fops_release(struct inode *inode, struct file *filep) +{ + struct iommufd_fault *fault = filep->private_data; + + iommufd_ctx_put(fault-&g

Re: [PATCH v6 05/10] iommufd: Add fault and response message definitions

2024-06-12 Thread Baolu Lu
On 6/12/24 9:52 PM, Jason Gunthorpe wrote: On Mon, May 27, 2024 at 12:05:12PM +0800, Lu Baolu wrote: +/** + * struct iommu_hwpt_pgfault - iommu page fault data + * @size: sizeof(struct iommu_hwpt_pgfault) + * @flags: Combination of enum iommu_hwpt_pgfault_flags + * @dev_id: id of the originated

Re: [PATCH v6 05/10] iommufd: Add fault and response message definitions

2024-06-12 Thread Baolu Lu
On 6/12/24 9:50 PM, Jason Gunthorpe wrote: On Wed, Jun 12, 2024 at 10:19:46AM -0300, Jason Gunthorpe wrote: I prefer not to mess the definition of user API data and the kernel driver implementation. The kernel driver may change in the future, but the user API will remain stable for a long time.

Re: [PATCH v6 05/10] iommufd: Add fault and response message definitions

2024-06-12 Thread Baolu Lu
On 6/12/24 9:19 PM, Jason Gunthorpe wrote: On Fri, Jun 07, 2024 at 09:38:38AM +, Tian, Kevin wrote: From: Baolu Lu Sent: Thursday, June 6, 2024 2:28 PM On 6/5/24 4:28 PM, Tian, Kevin wrote: From: Lu Baolu Sent: Monday, May 27, 2024 12:05 PM + +/** + * struct iommu_hwpt_page_response

Re: [PATCH v6 04/10] iommu: Extend domain attach group with handle support

2024-06-12 Thread Baolu Lu
On 6/12/24 9:41 PM, Jason Gunthorpe wrote: On Mon, May 27, 2024 at 12:05:11PM +0800, Lu Baolu wrote: Unlike the SVA case where each PASID of a device has an SVA domain attached to it, the I/O page faults are handled by the fault handler of the SVA domain. The I/O page faults for a user page tabl

Re: [PATCH v6 03/10] iommu: Add attach handle to struct iopf_group

2024-06-12 Thread Baolu Lu
On 6/12/24 9:37 PM, Jason Gunthorpe wrote: On Mon, May 27, 2024 at 12:05:10PM +0800, Lu Baolu wrote: @@ -206,20 +182,49 @@ void iommu_report_device_fault(struct device *dev, struct iopf_fault *evt) if (group == &abort_group) goto err_abort; - group->domain = get_domai

Re: [PATCH v6 02/10] iommu: Remove sva handle list

2024-06-12 Thread Baolu Lu
On 6/12/24 9:05 PM, Jason Gunthorpe wrote: On Fri, Jun 07, 2024 at 09:35:23AM +, Tian, Kevin wrote: From: Baolu Lu Sent: Thursday, June 6, 2024 2:07 PM On 6/5/24 4:15 PM, Tian, Kevin wrote: From: Lu Baolu Sent: Monday, May 27, 2024 12:05 PM - list_for_each_entry(handle, &am

Re: [PATCH v6 01/10] iommu: Introduce domain attachment handle

2024-06-12 Thread Baolu Lu
On 6/12/24 9:10 PM, Jason Gunthorpe wrote: On Thu, Jun 06, 2024 at 01:33:29PM +0800, Baolu Lu wrote: But if certain path (other than iopf) in the iommu core needs to know the exact domain pointer then this change breaks it. The iommu core should not fetch the domain pointer in paths other

Re: [PATCH v6 07/10] iommufd: Fault-capable hwpt attach/detach/replace

2024-06-09 Thread Baolu Lu
On 6/7/24 5:30 PM, Tian, Kevin wrote: From: Lu Baolu Sent: Monday, May 27, 2024 12:05 PM Add iopf-capable hw page table attach/detach/replace helpers. The pointer to iommufd_device is stored in the domain attachment handle, so that it can be echo'ed back in the iopf_group. this message needs

Re: [PATCH v6 06/10] iommufd: Add iommufd fault object

2024-06-08 Thread Baolu Lu
On 6/7/24 5:17 PM, Tian, Kevin wrote: From: Lu Baolu Sent: Monday, May 27, 2024 12:05 PM +static ssize_t iommufd_fault_fops_read(struct file *filep, char __user *buf, + size_t count, loff_t *ppos) +{ + size_t fault_size = sizeof(struct iommu_hwpt_pgfau

Re: [PATCH v6 05/10] iommufd: Add fault and response message definitions

2024-06-05 Thread Baolu Lu
On 6/5/24 4:28 PM, Tian, Kevin wrote: From: Lu Baolu Sent: Monday, May 27, 2024 12:05 PM + +/** + * struct iommu_hwpt_page_response - IOMMU page fault response + * @size: sizeof(struct iommu_hwpt_page_response) + * @flags: Must be set to 0 + * @dev_id: device ID of target device for the respons

Re: [PATCH v6 03/10] iommu: Add attach handle to struct iopf_group

2024-06-05 Thread Baolu Lu
On 6/5/24 4:23 PM, Tian, Kevin wrote: From: Lu Baolu Sent: Monday, May 27, 2024 12:05 PM @@ -249,6 +249,12 @@ enum iommu_cap { */ IOMMU_CAP_DEFERRED_FLUSH, IOMMU_CAP_DIRTY_TRACKING, /* IOMMU supports dirty tracking */ + /* +* IOMMU driver supports us

Re: [PATCH v6 02/10] iommu: Remove sva handle list

2024-06-05 Thread Baolu Lu
On 6/5/24 4:15 PM, Tian, Kevin wrote: From: Lu Baolu Sent: Monday, May 27, 2024 12:05 PM @@ -69,11 +68,16 @@ static struct iommu_mm_data *iommu_alloc_mm_data(struct mm_struct *mm, struct de */ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm) { + str

Re: [PATCH v6 01/10] iommu: Introduce domain attachment handle

2024-06-05 Thread Baolu Lu
On 6/5/24 4:02 PM, Tian, Kevin wrote: From: Lu Baolu Sent: Monday, May 27, 2024 12:05 PM @@ -99,7 +99,9 @@ struct iommu_sva *iommu_sva_bind_device(struct device *dev, struct mm_struct *mm /* Search for an existing domain. */ list_for_each_entry(domain, &mm->iommu_mm->sva_domain

Re: [PATCH v5 7/9] iommufd: Associate fault object with iommufd_hw_pgtable

2024-05-26 Thread Baolu Lu
On 5/27/24 9:33 AM, Tian, Kevin wrote: From: Jason Gunthorpe Sent: Friday, May 24, 2024 10:25 PM On Mon, May 20, 2024 at 03:39:54AM +, Tian, Kevin wrote: From: Baolu Lu Sent: Monday, May 20, 2024 10:19 AM On 5/15/24 4:50 PM, Tian, Kevin wrote: From: Lu Baolu Sent: Tuesday, April 30

Re: [PATCH v5 7/9] iommufd: Associate fault object with iommufd_hw_pgtable

2024-05-19 Thread Baolu Lu
On 5/20/24 11:39 AM, Tian, Kevin wrote: From: Baolu Lu Sent: Monday, May 20, 2024 10:19 AM On 5/15/24 4:50 PM, Tian, Kevin wrote: From: Lu Baolu Sent: Tuesday, April 30, 2024 10:57 PM @@ -308,6 +314,19 @@ int iommufd_hwpt_alloc(struct iommufd_ucmd *ucmd) goto out_put_pt

Re: [PATCH v5 6/9] iommufd: Fault-capable hwpt attach/detach/replace

2024-05-19 Thread Baolu Lu
On 5/20/24 11:35 AM, Tian, Kevin wrote: From: Baolu Lu Sent: Monday, May 20, 2024 10:10 AM On 5/15/24 4:43 PM, Tian, Kevin wrote: From: Lu Baolu Sent: Tuesday, April 30, 2024 10:57 PM + +int iommufd_fault_domain_replace_dev(struct iommufd_device *idev

Re: [PATCH v5 4/9] iommufd: Add fault and response message definitions

2024-05-19 Thread Baolu Lu
On 5/20/24 11:24 AM, Tian, Kevin wrote: From: Baolu Lu Sent: Sunday, May 19, 2024 10:38 PM On 2024/5/15 15:43, Tian, Kevin wrote: From: Lu Baolu Sent: Tuesday, April 30, 2024 10:57 PM iommu_hwpt_pgfaults represent fault messages that the userspace can retrieve. Multiple iommu_hwpt_pgfaults

Re: [PATCH v5 5/9] iommufd: Add iommufd fault object

2024-05-19 Thread Baolu Lu
On 5/20/24 11:26 AM, Tian, Kevin wrote: From: Baolu Lu Sent: Monday, May 20, 2024 8:41 AM On 5/15/24 3:57 PM, Tian, Kevin wrote: From: Baolu Lu Sent: Wednesday, May 8, 2024 6:05 PM On 2024/5/8 8:11, Jason Gunthorpe wrote: On Tue, Apr 30, 2024 at 10:57:06PM +0800, Lu Baolu wrote: diff

Re: [PATCH v5 7/9] iommufd: Associate fault object with iommufd_hw_pgtable

2024-05-19 Thread Baolu Lu
On 5/15/24 4:50 PM, Tian, Kevin wrote: From: Lu Baolu Sent: Tuesday, April 30, 2024 10:57 PM @@ -227,7 +233,7 @@ iommufd_hwpt_nested_alloc(struct iommufd_ctx *ictx, refcount_inc(&parent->common.obj.users); hwpt_nested->parent = parent; - hwpt->domain = ops->domain_alloc_u

Re: [PATCH v5 6/9] iommufd: Fault-capable hwpt attach/detach/replace

2024-05-19 Thread Baolu Lu
On 5/15/24 4:43 PM, Tian, Kevin wrote: From: Lu Baolu Sent: Tuesday, April 30, 2024 10:57 PM + +int iommufd_fault_domain_replace_dev(struct iommufd_device *idev, +struct iommufd_hw_pagetable *hwpt, +struct iommufd_hw_pagetab

Re: [PATCH v5 5/9] iommufd: Add iommufd fault object

2024-05-19 Thread Baolu Lu
On 5/15/24 4:37 PM, Tian, Kevin wrote: + iopf_free_group(group); + done += response_size; + + iommufd_put_object(fault->ictx, &idev->obj); get/put is unpaired: if (!idev || idev->obj.id != response.dev_id) idev =

Re: [PATCH v5 5/9] iommufd: Add iommufd fault object

2024-05-19 Thread Baolu Lu
On 5/15/24 4:37 PM, Tian, Kevin wrote: + + iopf_group_response(group, response.code); PCIe spec states that a response failure disables the PRI interface. For SR-IOV it'd be dangerous allowing user to trigger such code to VF to close the entire shared PRI interface. Just another e

Re: [PATCH v5 5/9] iommufd: Add iommufd fault object

2024-05-19 Thread Baolu Lu
On 5/15/24 4:37 PM, Tian, Kevin wrote: +static ssize_t iommufd_fault_fops_write(struct file *filep, const char __user *buf, + size_t count, loff_t *ppos) +{ + size_t response_size = sizeof(struct iommu_hwpt_page_response); + struct iommufd_fault *

Re: [PATCH v5 5/9] iommufd: Add iommufd fault object

2024-05-19 Thread Baolu Lu
On 5/15/24 4:37 PM, Tian, Kevin wrote: @@ -395,6 +396,8 @@ struct iommufd_device { /* always the physical device */ struct device *dev; bool enforce_cache_coherency; + /* outstanding faults awaiting response indexed by fault group id */ + struct xarray faults;

Re: [PATCH v5 5/9] iommufd: Add iommufd fault object

2024-05-19 Thread Baolu Lu
On 5/15/24 3:57 PM, Tian, Kevin wrote: From: Baolu Lu Sent: Wednesday, May 8, 2024 6:05 PM On 2024/5/8 8:11, Jason Gunthorpe wrote: On Tue, Apr 30, 2024 at 10:57:06PM +0800, Lu Baolu wrote: diff --git a/drivers/iommu/iommu-priv.h b/drivers/iommu/iommu-priv.h index ae65e0b85d69..1a0450a83bd0

Re: [PATCH v5 4/9] iommufd: Add fault and response message definitions

2024-05-19 Thread Baolu Lu
On 2024/5/15 15:43, Tian, Kevin wrote: From: Lu Baolu Sent: Tuesday, April 30, 2024 10:57 PM iommu_hwpt_pgfaults represent fault messages that the userspace can retrieve. Multiple iommu_hwpt_pgfaults might be put in an iopf group, with the IOMMU_PGFAULT_FLAGS_LAST_PAGE flag set only for the las

Re: [PATCH v5 3/9] iommu: Add attachment handle to struct iopf_group

2024-05-19 Thread Baolu Lu
On 2024/5/15 15:31, Tian, Kevin wrote: From: Lu Baolu Sent: Tuesday, April 30, 2024 10:57 PM Previously, the domain that a page fault targets is stored in an iopf_group, which represents a minimal set of page faults. With the introduction of attachment handle, replace the domain with the handle

Re: [PATCH v5 2/9] iommu: Replace sva_iommu with iommu_attach_handle

2024-05-19 Thread Baolu Lu
On 5/15/24 3:21 PM, Tian, Kevin wrote: From: Lu Baolu Sent: Tuesday, April 30, 2024 10:57 PM #else -static inline struct iommu_sva * +static inline struct iommu_attach_handle * iommu_sva_bind_device(struct device *dev, struct mm_struct *mm) { - return NULL; + return ERR_PTR(-E

Re: [PATCH v5 1/9] iommu: Introduce domain attachment handle

2024-05-19 Thread Baolu Lu
On 5/15/24 3:17 PM, Tian, Kevin wrote: From: Lu Baolu Sent: Tuesday, April 30, 2024 10:57 PM +/* Add an attach handle to the group's pasid array. */ +static struct iommu_attach_handle * +iommu_attach_handle_set(struct iommu_domain *domain, + struct iommu_group *group, ioas

Re: [PATCH v5 3/9] iommu: Add attachment handle to struct iopf_group

2024-05-10 Thread Baolu Lu
On 2024/5/10 21:38, Jason Gunthorpe wrote: On Fri, May 10, 2024 at 11:14:20AM +0800, Baolu Lu wrote: On 5/8/24 8:04 AM, Jason Gunthorpe wrote: On Tue, Apr 30, 2024 at 10:57:04PM +0800, Lu Baolu wrote: @@ -206,8 +197,11 @@ void iommu_report_device_fault(struct device *dev, struct iopf_fault

Re: [PATCH v5 5/9] iommufd: Add iommufd fault object

2024-05-10 Thread Baolu Lu
On 2024/5/8 8:22, Jason Gunthorpe wrote: On Tue, Apr 30, 2024 at 10:57:06PM +0800, Lu Baolu wrote: +static ssize_t iommufd_fault_fops_read(struct file *filep, char __user *buf, + size_t count, loff_t *ppos) +{ + size_t fault_size = sizeof(struct iommu_h

Re: [PATCH v5 7/9] iommufd: Associate fault object with iommufd_hw_pgtable

2024-05-09 Thread Baolu Lu
On 5/8/24 8:25 AM, Jason Gunthorpe wrote: On Tue, Apr 30, 2024 at 10:57:08PM +0800, Lu Baolu wrote: /** @@ -412,6 +415,9 @@ enum iommu_hwpt_data_type { * @data_type: One of enum iommu_hwpt_data_type * @data_len: Length of the type specific data * @data_uptr: User pointer to the type s

Re: [PATCH v5 6/9] iommufd: Fault-capable hwpt attach/detach/replace

2024-05-09 Thread Baolu Lu
On 5/8/24 8:18 AM, Jason Gunthorpe wrote: On Tue, Apr 30, 2024 at 10:57:07PM +0800, Lu Baolu wrote: diff --git a/drivers/iommu/iommufd/fault.c b/drivers/iommu/iommufd/fault.c index 13125c0feecb..6357229bf3b4 100644 --- a/drivers/iommu/iommufd/fault.c +++ b/drivers/iommu/iommufd/fault.c @@ -15,6

Re: [PATCH v5 3/9] iommu: Add attachment handle to struct iopf_group

2024-05-09 Thread Baolu Lu
On 5/8/24 8:04 AM, Jason Gunthorpe wrote: On Tue, Apr 30, 2024 at 10:57:04PM +0800, Lu Baolu wrote: @@ -206,8 +197,11 @@ void iommu_report_device_fault(struct device *dev, struct iopf_fault *evt) if (group == &abort_group) goto err_abort; - group->domain = get_domain_

Re: [PATCH v5 5/9] iommufd: Add iommufd fault object

2024-05-08 Thread Baolu Lu
On 2024/5/8 8:11, Jason Gunthorpe wrote: On Tue, Apr 30, 2024 at 10:57:06PM +0800, Lu Baolu wrote: diff --git a/drivers/iommu/iommu-priv.h b/drivers/iommu/iommu-priv.h index ae65e0b85d69..1a0450a83bd0 100644 --- a/drivers/iommu/iommu-priv.h +++ b/drivers/iommu/iommu-priv.h @@ -36,6 +36,10 @@ str

Re: [PATCH v4 2/9] iommu: Replace sva_iommu with iommu_attach_handle

2024-04-28 Thread Baolu Lu
On 4/29/24 10:39 AM, Tian, Kevin wrote: From: Baolu Lu Sent: Sunday, April 28, 2024 6:22 PM On 2024/4/10 7:48, Jason Gunthorpe wrote: On Tue, Apr 09, 2024 at 10:11:28AM +0800, Baolu Lu wrote: On 4/8/24 10:19 PM, Jason Gunthorpe wrote: On Sat, Apr 06, 2024 at 02:09:34PM +0800, Baolu Lu wrote

Re: [PATCH v4 2/9] iommu: Replace sva_iommu with iommu_attach_handle

2024-04-28 Thread Baolu Lu
On 2024/4/10 7:48, Jason Gunthorpe wrote: On Tue, Apr 09, 2024 at 10:11:28AM +0800, Baolu Lu wrote: On 4/8/24 10:19 PM, Jason Gunthorpe wrote: On Sat, Apr 06, 2024 at 02:09:34PM +0800, Baolu Lu wrote: On 4/3/24 7:59 PM, Jason Gunthorpe wrote: On Wed, Apr 03, 2024 at 09:15:12AM +0800, Lu

Re: [PATCH v4 2/9] iommu: Replace sva_iommu with iommu_attach_handle

2024-04-09 Thread Baolu Lu
On 4/10/24 7:48 AM, Jason Gunthorpe wrote: On Tue, Apr 09, 2024 at 10:11:28AM +0800, Baolu Lu wrote: On 4/8/24 10:19 PM, Jason Gunthorpe wrote: On Sat, Apr 06, 2024 at 02:09:34PM +0800, Baolu Lu wrote: On 4/3/24 7:59 PM, Jason Gunthorpe wrote: On Wed, Apr 03, 2024 at 09:15:12AM +0800, Lu

Re: [PATCH v4 2/9] iommu: Replace sva_iommu with iommu_attach_handle

2024-04-08 Thread Baolu Lu
On 4/8/24 10:19 PM, Jason Gunthorpe wrote: On Sat, Apr 06, 2024 at 02:09:34PM +0800, Baolu Lu wrote: On 4/3/24 7:59 PM, Jason Gunthorpe wrote: On Wed, Apr 03, 2024 at 09:15:12AM +0800, Lu Baolu wrote: + /* A bond already exists, just take a reference`. */ + handle

Re: [PATCH v4 1/9] iommu: Introduce domain attachment handle

2024-04-08 Thread Baolu Lu
On 4/8/24 10:05 PM, Jason Gunthorpe wrote: void iommufd_fault_domain_detach_dev(struct iommufd_hw_pagetable *hwpt, struct iommufd_device *idev) { + struct iommufd_fault *fault = hwpt->fault; + struct iommu_attach_handle *handle; + if (W

Re: [PATCH v4 1/9] iommu: Introduce domain attachment handle

2024-04-08 Thread Baolu Lu
On 4/8/24 10:05 PM, Jason Gunthorpe wrote: On Sat, Apr 06, 2024 at 12:34:14PM +0800, Baolu Lu wrote: On 4/3/24 7:58 PM, Jason Gunthorpe wrote: On Wed, Apr 03, 2024 at 09:15:11AM +0800, Lu Baolu wrote: Currently, when attaching a domain to a device or its PASID, domain is stored within the

Re: [PATCH v4 2/9] iommu: Replace sva_iommu with iommu_attach_handle

2024-04-05 Thread Baolu Lu
On 4/3/24 7:59 PM, Jason Gunthorpe wrote: - iommu_detach_device_pasid(domain, dev, iommu_mm->pasid); - if (--domain->users == 0) { - list_del(&domain->next); - iommu_domain_free(domain); + iommu_attach_handle_put(handle); + if (refcount_read(&ha

Re: [PATCH v4 2/9] iommu: Replace sva_iommu with iommu_attach_handle

2024-04-05 Thread Baolu Lu
On 4/3/24 7:59 PM, Jason Gunthorpe wrote: On Wed, Apr 03, 2024 at 09:15:12AM +0800, Lu Baolu wrote: + /* A bond already exists, just take a reference`. */ + handle = iommu_attach_handle_get(group, iommu_mm->pasid); + if (handle) { + mutex_unlock(&iommu_sva_lock);

Re: [PATCH v4 1/9] iommu: Introduce domain attachment handle

2024-04-05 Thread Baolu Lu
On 4/3/24 7:58 PM, Jason Gunthorpe wrote: On Wed, Apr 03, 2024 at 09:15:11AM +0800, Lu Baolu wrote: Currently, when attaching a domain to a device or its PASID, domain is stored within the iommu group. It could be retrieved for use during the window between attachment and detachment. With new f

Re: [PATCH v3 4/8] iommufd: Add iommufd fault object

2024-03-25 Thread Baolu Lu
On 3/23/24 1:22 AM, Jason Gunthorpe wrote: On Wed, Mar 20, 2024 at 04:18:05PM +, Shameerali Kolothum Thodi wrote: What I have noticed is that, -read interface works fine and I can receive struct tiommu_hwpt_pgfault data. -But once Guest handles the page faults and returns the page response,

Re: [PATCH v3 4/8] iommufd: Add iommufd fault object

2024-03-25 Thread Baolu Lu
On 3/25/24 11:26 AM, Baolu Lu wrote: On 3/23/24 1:22 AM, Jason Gunthorpe wrote: On Wed, Mar 20, 2024 at 04:18:05PM +, Shameerali Kolothum Thodi wrote: What I have noticed is that, -read interface works fine and I can receive struct tiommu_hwpt_pgfault data. -But once Guest handles the

Re: [PATCH v3 4/8] iommufd: Add iommufd fault object

2024-03-25 Thread Baolu Lu
On 2024/3/23 1:09, Jason Gunthorpe wrote: On Fri, Mar 15, 2024 at 09:46:06AM +0800, Baolu Lu wrote: On 3/9/24 2:03 AM, Jason Gunthorpe wrote: On Mon, Jan 22, 2024 at 03:38:59PM +0800, Lu Baolu wrote: --- /dev/null +++ b/drivers/iommu/iommufd/fault.c @@ -0,0 +1,255 @@ +// SPDX-License

Re: [PATCH v3 5/8] iommufd: Associate fault object with iommufd_hw_pgtable

2024-03-25 Thread Baolu Lu
On 2024/3/23 1:06, Jason Gunthorpe wrote: On Fri, Mar 15, 2024 at 09:16:43AM +0800, Baolu Lu wrote: On 3/9/24 3:05 AM, Jason Gunthorpe wrote: On Mon, Jan 22, 2024 at 03:39:00PM +0800, Lu Baolu wrote: @@ -411,6 +414,8 @@ enum iommu_hwpt_data_type { * @__reserved: Must be 0

Re: [PATCH v3 2/8] iommu/sva: Use iopf domain attach/detach interface

2024-03-25 Thread Baolu Lu
On 3/23/24 12:59 AM, Jason Gunthorpe wrote: On Thu, Mar 14, 2024 at 03:41:23PM +0800, Baolu Lu wrote: The whole cookie mechanism aims to address two things: - Extend the domain lifetime until all pending page faults are resolved. Like you answered, I think the flush is a simpler scheme

Re: [PATCH v3 3/8] iommufd: Add fault and response message definitions

2024-03-25 Thread Baolu Lu
On 3/23/24 1:04 AM, Jason Gunthorpe wrote: +struct iommu_hwpt_pgfault { + __u32 size; + __u32 flags; + __u32 dev_id; + __u32 pasid; + __u32 grpid; + __u32 perm; + __u64 addr; +}; Do we need an addr + size here? I've seen a few things where I wonder if th

Re: [PATCH v3 4/8] iommufd: Add iommufd fault object

2024-03-14 Thread Baolu Lu
On 3/9/24 2:03 AM, Jason Gunthorpe wrote: On Mon, Jan 22, 2024 at 03:38:59PM +0800, Lu Baolu wrote: --- /dev/null +++ b/drivers/iommu/iommufd/fault.c @@ -0,0 +1,255 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (C) 2024 Intel Corporation + */ +#define pr_fmt(fmt) "iommufd: " fmt + +

Re: [PATCH v3 5/8] iommufd: Associate fault object with iommufd_hw_pgtable

2024-03-14 Thread Baolu Lu
On 3/9/24 3:05 AM, Jason Gunthorpe wrote: On Mon, Jan 22, 2024 at 03:39:00PM +0800, Lu Baolu wrote: @@ -411,6 +414,8 @@ enum iommu_hwpt_data_type { * @__reserved: Must be 0 * @data_type: One of enum iommu_hwpt_data_type * @data_len: Length of the type specific data + * @fault_id: The I

Re: [PATCH v3 3/8] iommufd: Add fault and response message definitions

2024-03-14 Thread Baolu Lu
On 2024/3/9 1:50, Jason Gunthorpe wrote: On Mon, Jan 22, 2024 at 03:38:58PM +0800, Lu Baolu wrote: +/** + * enum iommu_hwpt_pgfault_flags - flags for struct iommu_hwpt_pgfault + * @IOMMU_PGFAULT_FLAGS_PASID_VALID: The pasid field of the fault data is + * valid.

Re: [PATCH v3 2/8] iommu/sva: Use iopf domain attach/detach interface

2024-03-14 Thread Baolu Lu
On 2024/3/9 1:46, Jason Gunthorpe wrote: On Mon, Jan 22, 2024 at 03:38:57PM +0800, Lu Baolu wrote: @@ -215,7 +202,23 @@ static struct iopf_group *iopf_group_alloc(struct iommu_fault_param *iopf_param, group = abort_group; } + cookie = iopf_pasid_cookie_get(iopf_param-

Re: [PATCH v3 5/8] iommufd: Associate fault object with iommufd_hw_pgtable

2024-03-06 Thread Baolu Lu
On 2024/3/7 0:01, Jason Gunthorpe wrote: On Wed, Mar 06, 2024 at 11:15:50PM +0800, Zhangfei Gao wrote: Double checked, this does not send flags, 0 is OK, Only domain_alloc_user in iommufd_hwpt_paging_alloc requires flags. In my debug, I need this patch, otherwise NULL pointer errors happen sinc

Re: [PATCH v3 1/8] iommu: Add iopf domain attach/detach/replace interface

2024-02-20 Thread Baolu Lu
On 2024/2/21 14:49, Tian, Kevin wrote: +struct iopf_attach_cookie { + struct iommu_domain *domain; + struct device *dev; + unsigned int pasid; + refcount_t users; + + void *private; + void (*release)(struct iopf_attach_cookie *cookie); +}; this cookie has noth

Re: [PATCH v3 6/8] iommufd: IOPF-capable hw page table attach/detach/replace

2024-02-20 Thread Baolu Lu
On 2024/2/20 21:57, Joel Granados wrote: diff --git a/drivers/iommu/iommufd/fault.c b/drivers/iommu/iommufd/fault.c index e752d1c49dde..a4a49f3cd4c2 100644 --- a/drivers/iommu/iommufd/fault.c +++ b/drivers/iommu/iommufd/fault.c @@ -267,3 +267,125 @@ int iommufd_fault_iopf_handler(struct iopf_grou

Re: [PATCH v3 5/8] iommufd: Associate fault object with iommufd_hw_pgtable

2024-02-20 Thread Baolu Lu
On 2024/2/7 16:14, Tian, Kevin wrote: From: Lu Baolu Sent: Monday, January 22, 2024 3:39 PM + +int iommufd_fault_iopf_handler(struct iopf_group *group) +{ + struct iommufd_hw_pagetable *hwpt = group->cookie->domain- fault_data; + struct iommufd_fault *fault = hwpt->fault; + why

Re: [PATCH v3 1/8] iommu: Add iopf domain attach/detach/replace interface

2024-02-20 Thread Baolu Lu
On 2024/2/7 16:11, Tian, Kevin wrote: From: Lu Baolu Sent: Monday, January 22, 2024 3:39 PM There is a slight difference between iopf domains and non-iopf domains. In the latter, references to domains occur between attach and detach; While in the former, due to the existence of asynchronous iop

Re: [PATCH RFC 17/17] iommu: Mark dev_iommu_priv_set() with a lockdep

2023-11-08 Thread Baolu Lu
On 2023/11/4 0:45, Jason Gunthorpe wrote: A perfect driver would only call dev_iommu_priv_set() from its probe callback. We've made it functionally correct to call it from the of_xlate by adding a lock around that call. lockdep assert that iommu_probe_device_lock is held to discourage misuse. E

Re: [PATCH RFC 01/17] iommu: Remove struct iommu_ops *iommu from arch_setup_dma_ops()

2023-11-08 Thread Baolu Lu
On 2023/11/4 0:44, Jason Gunthorpe wrote: This is not being used to pass ops, it is just a way to tell if an iommu driver was probed. These days this can be detected directly via device_iommu_mapped(). Call device_iommu_mapped() in the two places that need to check it and remove the iommu paramet