Skip to content

Commit 1ff25d7

Browse files
LuBaolujoergroedel
authored andcommitted
iommu: Remove iommu_[un]register_device_fault_handler()
The individual iommu driver reports the iommu page faults by calling iommu_report_device_fault(), where a pre-registered device fault handler is called to route the fault to another fault handler installed on the corresponding iommu domain. The pre-registered device fault handler is static and won't be dynamic as the fault handler is eventually per iommu domain. Replace calling device fault handler with iommu_queue_iopf(). After this replacement, the registering and unregistering fault handler interfaces are not needed anywhere. Remove the interfaces and the related data structures to avoid dead code. Convert cookie parameter of iommu_queue_iopf() into a device pointer that is really passed. Signed-off-by: Lu Baolu <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Tested-by: Yan Zhao <[email protected]> Tested-by: Longfang Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 15fc60c commit 1ff25d7

File tree

6 files changed

+13
-133
lines changed

6 files changed

+13
-133
lines changed

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,6 @@ bool arm_smmu_master_sva_enabled(struct arm_smmu_master *master)
487487

488488
static int arm_smmu_master_sva_enable_iopf(struct arm_smmu_master *master)
489489
{
490-
int ret;
491490
struct device *dev = master->dev;
492491

493492
/*
@@ -500,16 +499,7 @@ static int arm_smmu_master_sva_enable_iopf(struct arm_smmu_master *master)
500499
if (!master->iopf_enabled)
501500
return -EINVAL;
502501

503-
ret = iopf_queue_add_device(master->smmu->evtq.iopf, dev);
504-
if (ret)
505-
return ret;
506-
507-
ret = iommu_register_device_fault_handler(dev, iommu_queue_iopf, dev);
508-
if (ret) {
509-
iopf_queue_remove_device(master->smmu->evtq.iopf, dev);
510-
return ret;
511-
}
512-
return 0;
502+
return iopf_queue_add_device(master->smmu->evtq.iopf, dev);
513503
}
514504

515505
static void arm_smmu_master_sva_disable_iopf(struct arm_smmu_master *master)
@@ -519,7 +509,6 @@ static void arm_smmu_master_sva_disable_iopf(struct arm_smmu_master *master)
519509
if (!master->iopf_enabled)
520510
return;
521511

522-
iommu_unregister_device_fault_handler(dev);
523512
iopf_queue_remove_device(master->smmu->evtq.iopf, dev);
524513
}
525514

drivers/iommu/intel/iommu.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4427,23 +4427,15 @@ static int intel_iommu_enable_iopf(struct device *dev)
44274427
if (ret)
44284428
return ret;
44294429

4430-
ret = iommu_register_device_fault_handler(dev, iommu_queue_iopf, dev);
4431-
if (ret)
4432-
goto iopf_remove_device;
4433-
44344430
ret = pci_enable_pri(pdev, PRQ_DEPTH);
4435-
if (ret)
4436-
goto iopf_unregister_handler;
4431+
if (ret) {
4432+
iopf_queue_remove_device(iommu->iopf_queue, dev);
4433+
return ret;
4434+
}
4435+
44374436
info->pri_enabled = 1;
44384437

44394438
return 0;
4440-
4441-
iopf_unregister_handler:
4442-
iommu_unregister_device_fault_handler(dev);
4443-
iopf_remove_device:
4444-
iopf_queue_remove_device(iommu->iopf_queue, dev);
4445-
4446-
return ret;
44474439
}
44484440

44494441
static int intel_iommu_disable_iopf(struct device *dev)
@@ -4466,11 +4458,9 @@ static int intel_iommu_disable_iopf(struct device *dev)
44664458
info->pri_enabled = 0;
44674459

44684460
/*
4469-
* With PRI disabled and outstanding PRQs drained, unregistering
4470-
* fault handler and removing device from iopf queue should never
4471-
* fail.
4461+
* With PRI disabled and outstanding PRQs drained, removing device
4462+
* from iopf queue should never fail.
44724463
*/
4473-
WARN_ON(iommu_unregister_device_fault_handler(dev));
44744464
WARN_ON(iopf_queue_remove_device(iommu->iopf_queue, dev));
44754465

44764466
return 0;

drivers/iommu/io-pgfault.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static void iopf_handler(struct work_struct *work)
8787
/**
8888
* iommu_queue_iopf - IO Page Fault handler
8989
* @fault: fault event
90-
* @cookie: struct device, passed to iommu_register_device_fault_handler.
90+
* @dev: struct device.
9191
*
9292
* Add a fault to the device workqueue, to be handled by mm.
9393
*
@@ -124,14 +124,12 @@ static void iopf_handler(struct work_struct *work)
124124
*
125125
* Return: 0 on success and <0 on error.
126126
*/
127-
int iommu_queue_iopf(struct iommu_fault *fault, void *cookie)
127+
int iommu_queue_iopf(struct iommu_fault *fault, struct device *dev)
128128
{
129129
int ret;
130130
struct iopf_group *group;
131131
struct iopf_fault *iopf, *next;
132132
struct iommu_fault_param *iopf_param;
133-
134-
struct device *dev = cookie;
135133
struct dev_iommu *param = dev->iommu;
136134

137135
lockdep_assert_held(&param->lock);

drivers/iommu/iommu-sva.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct iommu_fault;
1313
struct iopf_queue;
1414

1515
#ifdef CONFIG_IOMMU_SVA
16-
int iommu_queue_iopf(struct iommu_fault *fault, void *cookie);
16+
int iommu_queue_iopf(struct iommu_fault *fault, struct device *dev);
1717

1818
int iopf_queue_add_device(struct iopf_queue *queue, struct device *dev);
1919
int iopf_queue_remove_device(struct iopf_queue *queue,
@@ -26,7 +26,7 @@ enum iommu_page_response_code
2626
iommu_sva_handle_iopf(struct iommu_fault *fault, void *data);
2727

2828
#else /* CONFIG_IOMMU_SVA */
29-
static inline int iommu_queue_iopf(struct iommu_fault *fault, void *cookie)
29+
static inline int iommu_queue_iopf(struct iommu_fault *fault, struct device *dev)
3030
{
3131
return -ENODEV;
3232
}

drivers/iommu/iommu.c

Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,76 +1330,6 @@ void iommu_group_put(struct iommu_group *group)
13301330
}
13311331
EXPORT_SYMBOL_GPL(iommu_group_put);
13321332

1333-
/**
1334-
* iommu_register_device_fault_handler() - Register a device fault handler
1335-
* @dev: the device
1336-
* @handler: the fault handler
1337-
* @data: private data passed as argument to the handler
1338-
*
1339-
* When an IOMMU fault event is received, this handler gets called with the
1340-
* fault event and data as argument. The handler should return 0 on success. If
1341-
* the fault is recoverable (IOMMU_FAULT_PAGE_REQ), the consumer should also
1342-
* complete the fault by calling iommu_page_response() with one of the following
1343-
* response code:
1344-
* - IOMMU_PAGE_RESP_SUCCESS: retry the translation
1345-
* - IOMMU_PAGE_RESP_INVALID: terminate the fault
1346-
* - IOMMU_PAGE_RESP_FAILURE: terminate the fault and stop reporting
1347-
* page faults if possible.
1348-
*
1349-
* Return 0 if the fault handler was installed successfully, or an error.
1350-
*/
1351-
int iommu_register_device_fault_handler(struct device *dev,
1352-
iommu_dev_fault_handler_t handler,
1353-
void *data)
1354-
{
1355-
struct dev_iommu *param = dev->iommu;
1356-
int ret = 0;
1357-
1358-
if (!param || !param->fault_param)
1359-
return -EINVAL;
1360-
1361-
mutex_lock(&param->lock);
1362-
/* Only allow one fault handler registered for each device */
1363-
if (param->fault_param->handler) {
1364-
ret = -EBUSY;
1365-
goto done_unlock;
1366-
}
1367-
1368-
param->fault_param->handler = handler;
1369-
param->fault_param->data = data;
1370-
1371-
done_unlock:
1372-
mutex_unlock(&param->lock);
1373-
1374-
return ret;
1375-
}
1376-
EXPORT_SYMBOL_GPL(iommu_register_device_fault_handler);
1377-
1378-
/**
1379-
* iommu_unregister_device_fault_handler() - Unregister the device fault handler
1380-
* @dev: the device
1381-
*
1382-
* Remove the device fault handler installed with
1383-
* iommu_register_device_fault_handler().
1384-
*
1385-
* Return 0 on success, or an error.
1386-
*/
1387-
int iommu_unregister_device_fault_handler(struct device *dev)
1388-
{
1389-
struct dev_iommu *param = dev->iommu;
1390-
1391-
if (!param || !param->fault_param)
1392-
return -EINVAL;
1393-
1394-
mutex_lock(&param->lock);
1395-
param->fault_param->handler = NULL;
1396-
param->fault_param->data = NULL;
1397-
mutex_unlock(&param->lock);
1398-
1399-
return 0;
1400-
}
1401-
EXPORT_SYMBOL_GPL(iommu_unregister_device_fault_handler);
1402-
14031333
/**
14041334
* iommu_report_device_fault() - Report fault event to device driver
14051335
* @dev: the device
@@ -1424,10 +1354,6 @@ int iommu_report_device_fault(struct device *dev, struct iommu_fault_event *evt)
14241354
/* we only report device fault if there is a handler registered */
14251355
mutex_lock(&param->lock);
14261356
fparam = param->fault_param;
1427-
if (!fparam || !fparam->handler) {
1428-
ret = -EINVAL;
1429-
goto done_unlock;
1430-
}
14311357

14321358
if (evt->fault.type == IOMMU_FAULT_PAGE_REQ &&
14331359
(evt->fault.prm.flags & IOMMU_FAULT_PAGE_REQUEST_LAST_PAGE)) {
@@ -1442,7 +1368,7 @@ int iommu_report_device_fault(struct device *dev, struct iommu_fault_event *evt)
14421368
mutex_unlock(&fparam->lock);
14431369
}
14441370

1445-
ret = fparam->handler(&evt->fault, fparam->data);
1371+
ret = iommu_queue_iopf(&evt->fault, dev);
14461372
if (ret && evt_pending) {
14471373
mutex_lock(&fparam->lock);
14481374
list_del(&evt_pending->list);

include/linux/iommu.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ struct iommu_page_response {
128128

129129
typedef int (*iommu_fault_handler_t)(struct iommu_domain *,
130130
struct device *, unsigned long, int, void *);
131-
typedef int (*iommu_dev_fault_handler_t)(struct iommu_fault *, void *);
132131

133132
struct iommu_domain_geometry {
134133
dma_addr_t aperture_start; /* First address that can be mapped */
@@ -671,8 +670,6 @@ struct iommu_fault_event {
671670

672671
/**
673672
* struct iommu_fault_param - per-device IOMMU fault data
674-
* @handler: Callback function to handle IOMMU faults at device level
675-
* @data: handler private data
676673
* @lock: protect pending faults list
677674
* @dev: the device that owns this param
678675
* @queue: IOPF queue
@@ -682,8 +679,6 @@ struct iommu_fault_event {
682679
* @faults: holds the pending faults which need response
683680
*/
684681
struct iommu_fault_param {
685-
iommu_dev_fault_handler_t handler;
686-
void *data;
687682
struct mutex lock;
688683

689684
struct device *dev;
@@ -806,11 +801,6 @@ extern int iommu_group_for_each_dev(struct iommu_group *group, void *data,
806801
extern struct iommu_group *iommu_group_get(struct device *dev);
807802
extern struct iommu_group *iommu_group_ref_get(struct iommu_group *group);
808803
extern void iommu_group_put(struct iommu_group *group);
809-
extern int iommu_register_device_fault_handler(struct device *dev,
810-
iommu_dev_fault_handler_t handler,
811-
void *data);
812-
813-
extern int iommu_unregister_device_fault_handler(struct device *dev);
814804

815805
extern int iommu_report_device_fault(struct device *dev,
816806
struct iommu_fault_event *evt);
@@ -1222,19 +1212,6 @@ static inline void iommu_group_put(struct iommu_group *group)
12221212
{
12231213
}
12241214

1225-
static inline
1226-
int iommu_register_device_fault_handler(struct device *dev,
1227-
iommu_dev_fault_handler_t handler,
1228-
void *data)
1229-
{
1230-
return -ENODEV;
1231-
}
1232-
1233-
static inline int iommu_unregister_device_fault_handler(struct device *dev)
1234-
{
1235-
return 0;
1236-
}
1237-
12381215
static inline
12391216
int iommu_report_device_fault(struct device *dev, struct iommu_fault_event *evt)
12401217
{

0 commit comments

Comments
 (0)