iommufd: Allocate attach_handle for any HWPT
cover iommufd: Allocate attach_handle for any HWPT
An attach_handle is a hwpt->fault specific thing, so the fault.c has been holding a set of attach/detach/replace helpers for attach_handle and iopf enabling/disabling.
Now, both the iommufd_msi series [1] and the attach_pasid series [2] want to reuse the attach_handle for non-fault cases. Rework the attach_handle, to prepare for either of the series. It should be merged with either that gets merged first.
[1] https://lore.kernel.org/linux-iommu/[email protected]/
[2] https://lore.kernel.org/linux-iommu/[email protected]/
Patches in this series are from [1] with some fixes addressing the review comments.
Changelog
v1 (since [1])
* Rebase on v6.14-rc1
* Unwrap the fault attach/detach/replace helpers
* Split the attach_handle patch to make it clearer
Thanks
Nicolin
Nicolin Chen (2):
iommufd: Make attach_handle generic than fault specific iommufd/fault: Remove iommufd_fault_domain_attach/detach/replace_dev()
drivers/iommu/iommufd/iommufd_private.h | 41 +------- drivers/iommu/iommufd/device.c | 101 +++++++++++++++++++ drivers/iommu/iommufd/fault.c | 128 +----------------------- 3 files changed, 109 insertions(+), 161 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/2 iommufd: Make attach_handle generic than fault specific
"attach_handle" was added exclusively for the iommufd_fault_iopf_handler() used by IOPF/PRI use cases. Now, both the MSI and PASID series require to reuse the attach_handle for non-fault cases.
Add a set of new attach/detach/replace helpers that does the attach_handle allocation/releasing/replacement in the common path and also handles those fault specific routines such as iopf enabling/disabling and auto response.
This covers both non-fault and fault cases in a clean way, replacing those inline helpers in the header. The following patch will clean up those old helpers in the fault.c file.
--- drivers/iommu/iommufd/iommufd_private.h | 33 +------- drivers/iommu/iommufd/device.c | 101 ++++++++++++++++++++++++ drivers/iommu/iommufd/fault.c | 8 +- 3 files changed, 109 insertions(+), 33 deletions(-)
drivers/iommu/iommufd/iommufd_private.h +4 -29
@@ -504,35 +504,10 @@ int iommufd_fault_domain_replace_dev(struct iommufd_device *idev,struct iommufd_hw_pagetable *hwpt, struct iommufd_hw_pagetable *old); -static inline int iommufd_hwpt_attach_device (struct iommufd_hw_pagetable *hwpt, -struct iommufd_device *idev) -{ -if (hwpt->fault) -return iommufd_fault_domain_attach_dev (hwpt, idev); - -return iommu_attach_group (hwpt->domain, idev->igroup->group); -} - -static inline void iommufd_hwpt_detach_device (struct iommufd_hw_pagetable *hwpt, -struct iommufd_device *idev) -{ -if (hwpt->fault) { -iommufd_fault_domain_detach_dev (hwpt, idev); -return ; - } - -iommu_detach_group (hwpt->domain, idev->igroup->group); -} - -static inline int iommufd_hwpt_replace_device (struct iommufd_device *idev, -struct iommufd_hw_pagetable *hwpt, -struct iommufd_hw_pagetable *old) -{ -if (old->fault || hwpt->fault) -return iommufd_fault_domain_replace_dev (idev, hwpt, old); - -return iommu_group_replace_domain (idev->igroup->group, hwpt->domain); -} +int iommufd_fault_iopf_enable (struct iommufd_device *idev); +void iommufd_fault_iopf_disable (struct iommufd_device *idev); +void iommufd_auto_response_faults (struct iommufd_hw_pagetable *hwpt, +struct iommufd_attach_handle *handle);static inline struct iommufd_viommu *iommufd_get_viommu (struct iommufd_ucmd *ucmd,u32 id)
drivers/iommu/iommufd/device.c +101 -0
107 lines not on this page · raw message
drivers/iommu/iommufd/fault.c +4 -4
@@ -17,7 +17,7 @@#include "../iommu-priv.h" #include "iommufd_private.h" -static int iommufd_fault_iopf_enable (struct iommufd_device *idev) +int iommufd_fault_iopf_enable (struct iommufd_device *idev) {struct device *dev = idev->dev;int ret;
@@ -50,7 +50,7 @@ static int iommufd_fault_iopf_enable(struct iommufd_device *idev)return ret; } -static void iommufd_fault_iopf_disable (struct iommufd_device *idev) +void iommufd_fault_iopf_disable (struct iommufd_device *idev) {mutex_lock (&idev->iopf_lock);if (!WARN_ON (idev->iopf_enabled ==0 )) {
@@ -98,8 +98,8 @@ int iommufd_fault_domain_attach_dev(struct iommufd_hw_pagetable *hwpt,return ret; } -static void iommufd_auto_response_faults (struct iommufd_hw_pagetable *hwpt, -struct iommufd_attach_handle *handle) +void iommufd_auto_response_faults (struct iommufd_hw_pagetable *hwpt, +struct iommufd_attach_handle *handle) {struct iommufd_fault *fault = hwpt->fault;struct iopf_group *group, *next;
Signature · 1 line
2.43.0
Re: [PATCH v1 1/2] iommufd: Make attach_handle generic than fault specific
Quoted 12 lines · Nicolin Chen
"
attach_handle" was added exclusively for theiommufd_fault_iopf_handler()used by IOPF/PRI use cases. Now, both the MSI and PASID series require to reuse theattach_handlefor non-fault cases.Add a set of new attach/detach/replace helpers that does the
attach_handleallocation/releasing/replacement in the common path and also handles those fault specific routines such as iopf enabling/disabling and auto response.This covers both non-fault and fault cases in a clean way, replacing those inline helpers in the header. The following patch will clean up those old helpers in the
fault.cfile.
Quoted 6 lines
Signed-off-by Nicolin Chen <[email protected]>--- drivers/iommu/iommufd/iommufd_private.h | 33 +------- drivers/iommu/iommufd/device.c | 101 ++++++++++++++++++++++++ drivers/iommu/iommufd/fault.c | 8 +- 3 files changed, 109 insertions(+), 33 deletions(-)
Signature · 2 lines
Regards, Yi Liu
Jason Gunthorpe
maintainerRe: [PATCH v1 1/2] iommufd: Make attach_handle generic than fault specific
In reply to Nicolin ChenQuoted 12 lines · Nicolin Chen
"
attach_handle" was added exclusively for theiommufd_fault_iopf_handler()used by IOPF/PRI use cases. Now, both the MSI and PASID series require to reuse theattach_handlefor non-fault cases.Add a set of new attach/detach/replace helpers that does the
attach_handleallocation/releasing/replacement in the common path and also handles those fault specific routines such as iopf enabling/disabling and auto response.This covers both non-fault and fault cases in a clean way, replacing those inline helpers in the header. The following patch will clean up those old helpers in the
fault.cfile.
Quoted 6 lines
Signed-off-by Nicolin Chen <[email protected]>--- drivers/iommu/iommufd/iommufd_private.h | 33 +------- drivers/iommu/iommufd/device.c | 101 ++++++++++++++++++++++++ drivers/iommu/iommufd/fault.c | 8 +- 3 files changed, 109 insertions(+), 33 deletions(-)
I am going to add some lockdeps to this:
drivers/iommu/iommufd/device.c +4 -0
@@ -360,6 +360,8 @@ static int iommufd_hwpt_attach_device(struct iommufd_hw_pagetable *hwpt,struct iommufd_attach_handle *handle;int rc; +lockdep_assert_held (&idev->igroup->lock); + handle =kzalloc (sizeof (*handle),GFP_KERNEL );if (!handle)return -ENOMEM ;
@@ -391,6 +393,8 @@ iommufd_device_get_attach_handle(struct iommufd_device *idev) {struct iommu_attach_handle *handle; +lockdep_assert_held (&idev->igroup->lock); + handle =iommu_attach_handle_get (idev->igroup->group,IOMMU_NO_PASID ,0 );if (IS_ERR (handle))
I think the one in get_attach_handle is important to discourage misuse of that ..
Thanks,
Jason
PATCH 2/2 iommufd/fault: Remove iommufd_fault_domain_attach/detach/replace_dev()
In reply to Nicolin ChenThere are new attach/detach/replace helpers in device.c taking care of both the attach_handle and the fault specific routines for iopf_enable/disable() and auto response.
Clean up these redundant functions in the fault.c file.
--- drivers/iommu/iommufd/iommufd_private.h | 8 -- drivers/iommu/iommufd/fault.c | 120 ------------------------ 2 files changed, 128 deletions(-)
drivers/iommu/iommufd/iommufd_private.h +0 -8
@@ -496,14 +496,6 @@ int iommufd_fault_alloc(struct iommufd_ucmd *ucmd);void iommufd_fault_destroy (struct iommufd_object *obj);int iommufd_fault_iopf_handler (struct iopf_group *group); -int iommufd_fault_domain_attach_dev (struct iommufd_hw_pagetable *hwpt, -struct iommufd_device *idev); -void iommufd_fault_domain_detach_dev (struct iommufd_hw_pagetable *hwpt, -struct iommufd_device *idev); -int iommufd_fault_domain_replace_dev (struct iommufd_device *idev, -struct iommufd_hw_pagetable *hwpt, -struct iommufd_hw_pagetable *old); -int iommufd_fault_iopf_enable (struct iommufd_device *idev);void iommufd_fault_iopf_disable (struct iommufd_device *idev); void iommufd_auto_response_faults(struct iommufd_hw_pagetable *hwpt,
drivers/iommu/iommufd/fault.c +0 -120
132 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v1 2/2] iommufd/fault: Remove iommufd_fault_domain_attach/detach/replace_dev()
Quoted 11 lines · Nicolin Chen
There are new attach/detach/replace helpers in
device.ctaking care of both theattach_handleand the fault specific routines for iopf_enable/disable() and auto response.Clean up these redundant functions in the
fault.cfile.Signed-off-by Nicolin Chen <[email protected]>--- drivers/iommu/iommufd/iommufd_private.h | 8 -- drivers/iommu/iommufd/fault.c | 120 ------------------------ 2 files changed, 128 deletions(-)
Signature · 2 lines
Regards, Yi Liu
Jason Gunthorpe
maintainerQuoted 9 lines · Nicolin Chen
An
attach_handleis ahwpt->faultspecific thing, so thefault.chas been holding a set of attach/detach/replace helpers forattach_handleand iopf enabling/disabling.Now, both the
iommufd_msiseries [1] and theattach_pasidseries [2] want to reuse theattach_handlefor non-fault cases. Rework theattach_handle, to prepare for either of the series. It should be merged with either that gets merged first.
Quoted 5 lines
[1] https://lore.kernel.org/linux-iommu/[email protected]/
[2] https://lore.kernel.org/linux-iommu/[email protected]/Patches in this series are from [1] with some fixes addressing the review comments.
Applied, the other patches can rebase on top of this
Thanks,
Jason