mbox series

[v3,00/11] iommu: Prepare to deliver page faults to user space

Message ID 20230817234047.195194-1-baolu.lu@linux.intel.com (mailing list archive)
Headers show
Series iommu: Prepare to deliver page faults to user space | expand

Message

Baolu Lu Aug. 17, 2023, 11:40 p.m. UTC
When a user-managed page table is attached to an IOMMU, it is necessary
to deliver IO page faults to user space so that they can be handled
appropriately. One use case for this is nested translation, which is
currently being discussed in the mailing list.

I have posted a RFC series [1] that describes the implementation of
delivering page faults to user space through IOMMUFD. This series has
received several comments on the IOMMU refactoring, which I am trying to
address in this series.

The major refactoring includes:

- [PATCH 01 ~ 04] Move include/uapi/linux/iommu.h to
  include/linux/iommu.h. Remove the unrecoverable fault data definition.
- [PATCH 05 ~ 06] Remove iommu_[un]register_device_fault_handler().
- [PATCH 07 ~ 11] Separate SVA and IOPF. Make IOPF a generic page fault
  handling framework. 

This is also available at github [2]. I would appreciate your feedback
on this series.

[1] https://lore.kernel.org/linux-iommu/20230530053724.232765-1-baolu.lu@linux.intel.com/
[2] https://github.com/LuBaolu/intel-iommu/commits/preparatory-io-pgfault-delivery-v3

Change log:
v3:
 - Convert the fault data structures from uAPI to kAPI.
 - Merge iopf_device_param into iommu_fault_param.
 - Add debugging on domain lifetime for iopf.
 - Remove patch "iommu: Change the return value of dev_iommu_get()".
 - Remove patch "iommu: Add helper to set iopf handler for domain".
 - Misc code refactoring and refining.

v2: https://lore.kernel.org/linux-iommu/20230727054837.147050-1-baolu.lu@linux.intel.com/
 - Remove unrecoverable fault data definition as suggested by Kevin.
 - Drop the per-device fault cookie code considering that doesn't make
   much sense for SVA.
 - Make the IOMMU page fault handling framework generic. So that it can
   avaible for use cases other than SVA.

v1: https://lore.kernel.org/linux-iommu/20230711010642.19707-1-baolu.lu@linux.intel.com/

Lu Baolu (11):
  iommu: Move iommu fault data to linux/iommu.h
  iommu/arm-smmu-v3: Remove unrecoverable faults reporting
  iommu: Remove unrecoverable fault data
  iommu: Cleanup iopf data structure definitions
  iommu: Merge iopf_device_param into iommu_fault_param
  iommu: Remove iommu_[un]register_device_fault_handler()
  iommu: Prepare for separating SVA and IOPF
  iommu: Move iopf_handler() to iommu-sva.c
  iommu: Make iommu_queue_iopf() more generic
  iommu: Add debugging on domain lifetime for iopf
  iommu: Separate SVA and IOPF in Makefile and Kconfig

 include/linux/iommu.h                         | 202 ++++++++++++++---
 drivers/iommu/iommu-sva.h                     |  71 ------
 include/uapi/linux/iommu.h                    | 161 --------------
 .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c   |  14 +-
 drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c   |  47 ++--
 drivers/iommu/intel/iommu.c                   |  25 +--
 drivers/iommu/intel/svm.c                     |   1 -
 drivers/iommu/io-pgfault.c                    | 208 ++++++++----------
 drivers/iommu/iommu-sva.c                     |  49 ++++-
 drivers/iommu/iommu.c                         | 132 +++--------
 MAINTAINERS                                   |   1 -
 drivers/iommu/Kconfig                         |   4 +
 drivers/iommu/Makefile                        |   3 +-
 drivers/iommu/intel/Kconfig                   |   1 +
 14 files changed, 362 insertions(+), 557 deletions(-)
 delete mode 100644 drivers/iommu/iommu-sva.h
 delete mode 100644 include/uapi/linux/iommu.h

Comments

Jason Gunthorpe Aug. 21, 2023, 6:31 p.m. UTC | #1
On Fri, Aug 18, 2023 at 07:40:36AM +0800, Lu Baolu wrote:
> When a user-managed page table is attached to an IOMMU, it is necessary
> to deliver IO page faults to user space so that they can be handled
> appropriately. One use case for this is nested translation, which is
> currently being discussed in the mailing list.
> 
> I have posted a RFC series [1] that describes the implementation of
> delivering page faults to user space through IOMMUFD. This series has
> received several comments on the IOMMU refactoring, which I am trying to
> address in this series.

Looking at this after all the patches are applied..

iommu_report_device_fault() and iommu_queue_iopf() should be put in
the same file.

iommu_queue_iopf() seems misnamed since it isn't queuing anything. It
is delivering the fault to the domain.

It is weird that iommu_sva_domain_alloc is not in the sva file

iopf_queue_work() wrappers a work queue, but it should trampoline
through another function before invoking the driver's callback and not
invoke it with a weird work_struct - decode the group and get back the
domain. Every single handler will require the group and domain.

Same for domain->iopf_handler, the domain should be an argument if we
are invoking the function on a domain.

Perhaps group->domain is a simple answer.

Jason
Baolu Lu Aug. 23, 2023, 1:24 a.m. UTC | #2
On 2023/8/22 2:31, Jason Gunthorpe wrote:
> On Fri, Aug 18, 2023 at 07:40:36AM +0800, Lu Baolu wrote:
>> When a user-managed page table is attached to an IOMMU, it is necessary
>> to deliver IO page faults to user space so that they can be handled
>> appropriately. One use case for this is nested translation, which is
>> currently being discussed in the mailing list.
>>
>> I have posted a RFC series [1] that describes the implementation of
>> delivering page faults to user space through IOMMUFD. This series has
>> received several comments on the IOMMU refactoring, which I am trying to
>> address in this series.
> 
> Looking at this after all the patches are applied..

Thank you very much for reviewing my patches.

> 
> iommu_report_device_fault() and iommu_queue_iopf() should be put in
> the same file.

Yes. I will move both into io-pgfault.c. After that, iommu_queue_iopf()
becomes static.

> 
> iommu_queue_iopf() seems misnamed since it isn't queuing anything. It
> is delivering the fault to the domain.

Yeah, perhaps we can rename it to iommu_handle_iopf().

/**
  * iommu_handle_iopf - IO Page Fault handler
  * @fault: fault event
  * @dev: struct device.

> 
> It is weird that iommu_sva_domain_alloc is not in the sva file

Agreed. I will move it to iommu-sva.c.

> iopf_queue_work() wrappers a work queue, but it should trampoline
> through another function before invoking the driver's callback and not
> invoke it with a weird work_struct - decode the group and get back the
> domain. Every single handler will require the group and domain.

The work queue wrapper is duplicate. I will remove it and let the driver
to call queue_work() directly.

> 
> Same for domain->iopf_handler, the domain should be an argument if we
> are invoking the function on a domain.
> 
> Perhaps group->domain is a simple answer.

Yes. I will add domain in fault group and make it part of the parameters
of the callback.

Best regards,
baolu