Skip to content

Commit 24b5d26

Browse files
LuBaolujoergroedel
authored andcommitted
iommu: Prepare for separating SVA and IOPF
Move iopf_group data structure to iommu.h to make it a minimal set of faults that a domain's page fault handler should handle. Add a new function, iopf_free_group(), to free a fault group after all faults in the group are handled. This function will be made global so that it can be called from other files, such as iommu-sva.c. Move iopf_queue data structure to iommu.h to allow the workqueue to be scheduled out of this file. This will simplify the sequential patches. Signed-off-by: Lu Baolu <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Reviewed-by: Yi Liu <[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 3f02a9d commit 24b5d26

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

drivers/iommu/io-pgfault.c

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,17 @@
1313

1414
#include "iommu-sva.h"
1515

16-
/**
17-
* struct iopf_queue - IO Page Fault queue
18-
* @wq: the fault workqueue
19-
* @devices: devices attached to this queue
20-
* @lock: protects the device list
21-
*/
22-
struct iopf_queue {
23-
struct workqueue_struct *wq;
24-
struct list_head devices;
25-
struct mutex lock;
26-
};
27-
28-
struct iopf_group {
29-
struct iopf_fault last_fault;
30-
struct list_head faults;
31-
struct work_struct work;
32-
struct device *dev;
33-
};
16+
static void iopf_free_group(struct iopf_group *group)
17+
{
18+
struct iopf_fault *iopf, *next;
19+
20+
list_for_each_entry_safe(iopf, next, &group->faults, list) {
21+
if (!(iopf->fault.prm.flags & IOMMU_FAULT_PAGE_REQUEST_LAST_PAGE))
22+
kfree(iopf);
23+
}
24+
25+
kfree(group);
26+
}
3427

3528
static int iopf_complete_group(struct device *dev, struct iopf_fault *iopf,
3629
enum iommu_page_response_code status)
@@ -50,9 +43,9 @@ static int iopf_complete_group(struct device *dev, struct iopf_fault *iopf,
5043

5144
static void iopf_handler(struct work_struct *work)
5245
{
46+
struct iopf_fault *iopf;
5347
struct iopf_group *group;
5448
struct iommu_domain *domain;
55-
struct iopf_fault *iopf, *next;
5649
enum iommu_page_response_code status = IOMMU_PAGE_RESP_SUCCESS;
5750

5851
group = container_of(work, struct iopf_group, work);
@@ -61,22 +54,18 @@ static void iopf_handler(struct work_struct *work)
6154
if (!domain || !domain->iopf_handler)
6255
status = IOMMU_PAGE_RESP_INVALID;
6356

64-
list_for_each_entry_safe(iopf, next, &group->faults, list) {
57+
list_for_each_entry(iopf, &group->faults, list) {
6558
/*
6659
* For the moment, errors are sticky: don't handle subsequent
6760
* faults in the group if there is an error.
6861
*/
6962
if (status == IOMMU_PAGE_RESP_SUCCESS)
7063
status = domain->iopf_handler(&iopf->fault,
7164
domain->fault_data);
72-
73-
if (!(iopf->fault.prm.flags &
74-
IOMMU_FAULT_PAGE_REQUEST_LAST_PAGE))
75-
kfree(iopf);
7665
}
7766

7867
iopf_complete_group(group->dev, &group->last_fault, status);
79-
kfree(group);
68+
iopf_free_group(group);
8069
}
8170

8271
/**

include/linux/iommu.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ struct iommu_dirty_ops;
4141
struct notifier_block;
4242
struct iommu_sva;
4343
struct iommu_dma_cookie;
44-
struct iopf_queue;
4544

4645
#define IOMMU_FAULT_PERM_READ (1 << 0) /* read */
4746
#define IOMMU_FAULT_PERM_WRITE (1 << 1) /* write */
@@ -126,6 +125,25 @@ struct iopf_fault {
126125
struct list_head list;
127126
};
128127

128+
struct iopf_group {
129+
struct iopf_fault last_fault;
130+
struct list_head faults;
131+
struct work_struct work;
132+
struct device *dev;
133+
};
134+
135+
/**
136+
* struct iopf_queue - IO Page Fault queue
137+
* @wq: the fault workqueue
138+
* @devices: devices attached to this queue
139+
* @lock: protects the device list
140+
*/
141+
struct iopf_queue {
142+
struct workqueue_struct *wq;
143+
struct list_head devices;
144+
struct mutex lock;
145+
};
146+
129147
/* iommu fault flags */
130148
#define IOMMU_FAULT_READ 0x0
131149
#define IOMMU_FAULT_WRITE 0x1

0 commit comments

Comments
 (0)