Skip to content

Commit be2a243

Browse files
LuBaolujoergroedel
authored andcommitted
iommufd: Remove unnecessary IOMMU_DEV_FEAT_IOPF
The iopf enablement has been moved to the iommu drivers. It is unnecessary for iommufd to handle iopf enablement. Remove the iopf enablement logic to avoid duplication. Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Tested-by: Zhangfei Gao <zhangfei.gao@linaro.org> Link: https://lore.kernel.org/r/20250418080130.1844424-8-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent ec027bf commit be2a243

File tree

3 files changed

+30
-83
lines changed

3 files changed

+30
-83
lines changed

drivers/iommu/iommufd/device.c

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ struct iommufd_device *iommufd_device_bind(struct iommufd_ctx *ictx,
221221
refcount_inc(&idev->obj.users);
222222
/* igroup refcount moves into iommufd_device */
223223
idev->igroup = igroup;
224-
mutex_init(&idev->iopf_lock);
225224

226225
/*
227226
* If the caller fails after this success it must call
@@ -425,13 +424,35 @@ static int iommufd_hwpt_pasid_compat(struct iommufd_hw_pagetable *hwpt,
425424
return 0;
426425
}
427426

427+
static bool iommufd_hwpt_compatible_device(struct iommufd_hw_pagetable *hwpt,
428+
struct iommufd_device *idev)
429+
{
430+
struct pci_dev *pdev;
431+
432+
if (!hwpt->fault || !dev_is_pci(idev->dev))
433+
return true;
434+
435+
/*
436+
* Once we turn on PCI/PRI support for VF, the response failure code
437+
* should not be forwarded to the hardware due to PRI being a shared
438+
* resource between PF and VFs. There is no coordination for this
439+
* shared capability. This waits for a vPRI reset to recover.
440+
*/
441+
pdev = to_pci_dev(idev->dev);
442+
443+
return (!pdev->is_virtfn || !pci_pri_supported(pdev));
444+
}
445+
428446
static int iommufd_hwpt_attach_device(struct iommufd_hw_pagetable *hwpt,
429447
struct iommufd_device *idev,
430448
ioasid_t pasid)
431449
{
432450
struct iommufd_attach_handle *handle;
433451
int rc;
434452

453+
if (!iommufd_hwpt_compatible_device(hwpt, idev))
454+
return -EINVAL;
455+
435456
rc = iommufd_hwpt_pasid_compat(hwpt, idev, pasid);
436457
if (rc)
437458
return rc;
@@ -440,12 +461,6 @@ static int iommufd_hwpt_attach_device(struct iommufd_hw_pagetable *hwpt,
440461
if (!handle)
441462
return -ENOMEM;
442463

443-
if (hwpt->fault) {
444-
rc = iommufd_fault_iopf_enable(idev);
445-
if (rc)
446-
goto out_free_handle;
447-
}
448-
449464
handle->idev = idev;
450465
if (pasid == IOMMU_NO_PASID)
451466
rc = iommu_attach_group_handle(hwpt->domain, idev->igroup->group,
@@ -454,13 +469,10 @@ static int iommufd_hwpt_attach_device(struct iommufd_hw_pagetable *hwpt,
454469
rc = iommu_attach_device_pasid(hwpt->domain, idev->dev, pasid,
455470
&handle->handle);
456471
if (rc)
457-
goto out_disable_iopf;
472+
goto out_free_handle;
458473

459474
return 0;
460475

461-
out_disable_iopf:
462-
if (hwpt->fault)
463-
iommufd_fault_iopf_disable(idev);
464476
out_free_handle:
465477
kfree(handle);
466478
return rc;
@@ -492,10 +504,7 @@ static void iommufd_hwpt_detach_device(struct iommufd_hw_pagetable *hwpt,
492504
else
493505
iommu_detach_device_pasid(hwpt->domain, idev->dev, pasid);
494506

495-
if (hwpt->fault) {
496-
iommufd_auto_response_faults(hwpt, handle);
497-
iommufd_fault_iopf_disable(idev);
498-
}
507+
iommufd_auto_response_faults(hwpt, handle);
499508
kfree(handle);
500509
}
501510

@@ -507,6 +516,9 @@ static int iommufd_hwpt_replace_device(struct iommufd_device *idev,
507516
struct iommufd_attach_handle *handle, *old_handle;
508517
int rc;
509518

519+
if (!iommufd_hwpt_compatible_device(hwpt, idev))
520+
return -EINVAL;
521+
510522
rc = iommufd_hwpt_pasid_compat(hwpt, idev, pasid);
511523
if (rc)
512524
return rc;
@@ -517,12 +529,6 @@ static int iommufd_hwpt_replace_device(struct iommufd_device *idev,
517529
if (!handle)
518530
return -ENOMEM;
519531

520-
if (hwpt->fault && !old->fault) {
521-
rc = iommufd_fault_iopf_enable(idev);
522-
if (rc)
523-
goto out_free_handle;
524-
}
525-
526532
handle->idev = idev;
527533
if (pasid == IOMMU_NO_PASID)
528534
rc = iommu_replace_group_handle(idev->igroup->group,
@@ -531,20 +537,13 @@ static int iommufd_hwpt_replace_device(struct iommufd_device *idev,
531537
rc = iommu_replace_device_pasid(hwpt->domain, idev->dev,
532538
pasid, &handle->handle);
533539
if (rc)
534-
goto out_disable_iopf;
540+
goto out_free_handle;
535541

536-
if (old->fault) {
537-
iommufd_auto_response_faults(hwpt, old_handle);
538-
if (!hwpt->fault)
539-
iommufd_fault_iopf_disable(idev);
540-
}
542+
iommufd_auto_response_faults(hwpt, old_handle);
541543
kfree(old_handle);
542544

543545
return 0;
544546

545-
out_disable_iopf:
546-
if (hwpt->fault && !old->fault)
547-
iommufd_fault_iopf_disable(idev);
548547
out_free_handle:
549548
kfree(handle);
550549
return rc;

drivers/iommu/iommufd/eventq.c

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,59 +9,13 @@
99
#include <linux/iommufd.h>
1010
#include <linux/module.h>
1111
#include <linux/mutex.h>
12-
#include <linux/pci.h>
13-
#include <linux/pci-ats.h>
1412
#include <linux/poll.h>
1513
#include <uapi/linux/iommufd.h>
1614

1715
#include "../iommu-priv.h"
1816
#include "iommufd_private.h"
1917

2018
/* IOMMUFD_OBJ_FAULT Functions */
21-
22-
int iommufd_fault_iopf_enable(struct iommufd_device *idev)
23-
{
24-
struct device *dev = idev->dev;
25-
int ret;
26-
27-
/*
28-
* Once we turn on PCI/PRI support for VF, the response failure code
29-
* should not be forwarded to the hardware due to PRI being a shared
30-
* resource between PF and VFs. There is no coordination for this
31-
* shared capability. This waits for a vPRI reset to recover.
32-
*/
33-
if (dev_is_pci(dev)) {
34-
struct pci_dev *pdev = to_pci_dev(dev);
35-
36-
if (pdev->is_virtfn && pci_pri_supported(pdev))
37-
return -EINVAL;
38-
}
39-
40-
mutex_lock(&idev->iopf_lock);
41-
/* Device iopf has already been on. */
42-
if (++idev->iopf_enabled > 1) {
43-
mutex_unlock(&idev->iopf_lock);
44-
return 0;
45-
}
46-
47-
ret = iommu_dev_enable_feature(dev, IOMMU_DEV_FEAT_IOPF);
48-
if (ret)
49-
--idev->iopf_enabled;
50-
mutex_unlock(&idev->iopf_lock);
51-
52-
return ret;
53-
}
54-
55-
void iommufd_fault_iopf_disable(struct iommufd_device *idev)
56-
{
57-
mutex_lock(&idev->iopf_lock);
58-
if (!WARN_ON(idev->iopf_enabled == 0)) {
59-
if (--idev->iopf_enabled == 0)
60-
iommu_dev_disable_feature(idev->dev, IOMMU_DEV_FEAT_IOPF);
61-
}
62-
mutex_unlock(&idev->iopf_lock);
63-
}
64-
6519
void iommufd_auto_response_faults(struct iommufd_hw_pagetable *hwpt,
6620
struct iommufd_attach_handle *handle)
6721
{
@@ -70,7 +24,7 @@ void iommufd_auto_response_faults(struct iommufd_hw_pagetable *hwpt,
7024
struct list_head free_list;
7125
unsigned long index;
7226

73-
if (!fault)
27+
if (!fault || !handle)
7428
return;
7529
INIT_LIST_HEAD(&free_list);
7630

drivers/iommu/iommufd/iommufd_private.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,9 +425,6 @@ struct iommufd_device {
425425
/* always the physical device */
426426
struct device *dev;
427427
bool enforce_cache_coherency;
428-
/* protect iopf_enabled counter */
429-
struct mutex iopf_lock;
430-
unsigned int iopf_enabled;
431428
};
432429

433430
static inline struct iommufd_device *
@@ -506,9 +503,6 @@ iommufd_get_fault(struct iommufd_ucmd *ucmd, u32 id)
506503
int iommufd_fault_alloc(struct iommufd_ucmd *ucmd);
507504
void iommufd_fault_destroy(struct iommufd_object *obj);
508505
int iommufd_fault_iopf_handler(struct iopf_group *group);
509-
510-
int iommufd_fault_iopf_enable(struct iommufd_device *idev);
511-
void iommufd_fault_iopf_disable(struct iommufd_device *idev);
512506
void iommufd_auto_response_faults(struct iommufd_hw_pagetable *hwpt,
513507
struct iommufd_attach_handle *handle);
514508

0 commit comments

Comments
 (0)