@@ -60,44 +60,6 @@ void iommufd_fault_iopf_disable(struct iommufd_device *idev)
6060 mutex_unlock (& idev -> iopf_lock );
6161}
6262
63- static int __fault_domain_attach_dev (struct iommufd_hw_pagetable * hwpt ,
64- struct iommufd_device * idev )
65- {
66- struct iommufd_attach_handle * handle ;
67- int ret ;
68-
69- handle = kzalloc (sizeof (* handle ), GFP_KERNEL );
70- if (!handle )
71- return - ENOMEM ;
72-
73- handle -> idev = idev ;
74- ret = iommu_attach_group_handle (hwpt -> domain , idev -> igroup -> group ,
75- & handle -> handle );
76- if (ret )
77- kfree (handle );
78-
79- return ret ;
80- }
81-
82- int iommufd_fault_domain_attach_dev (struct iommufd_hw_pagetable * hwpt ,
83- struct iommufd_device * idev )
84- {
85- int ret ;
86-
87- if (!hwpt -> fault )
88- return - EINVAL ;
89-
90- ret = iommufd_fault_iopf_enable (idev );
91- if (ret )
92- return ret ;
93-
94- ret = __fault_domain_attach_dev (hwpt , idev );
95- if (ret )
96- iommufd_fault_iopf_disable (idev );
97-
98- return ret ;
99- }
100-
10163void iommufd_auto_response_faults (struct iommufd_hw_pagetable * hwpt ,
10264 struct iommufd_attach_handle * handle )
10365{
@@ -135,88 +97,6 @@ void iommufd_auto_response_faults(struct iommufd_hw_pagetable *hwpt,
13597 mutex_unlock (& fault -> mutex );
13698}
13799
138- static struct iommufd_attach_handle *
139- iommufd_device_get_attach_handle (struct iommufd_device * idev )
140- {
141- struct iommu_attach_handle * handle ;
142-
143- handle = iommu_attach_handle_get (idev -> igroup -> group , IOMMU_NO_PASID , 0 );
144- if (IS_ERR (handle ))
145- return NULL ;
146-
147- return to_iommufd_handle (handle );
148- }
149-
150- void iommufd_fault_domain_detach_dev (struct iommufd_hw_pagetable * hwpt ,
151- struct iommufd_device * idev )
152- {
153- struct iommufd_attach_handle * handle ;
154-
155- handle = iommufd_device_get_attach_handle (idev );
156- iommu_detach_group_handle (hwpt -> domain , idev -> igroup -> group );
157- iommufd_auto_response_faults (hwpt , handle );
158- iommufd_fault_iopf_disable (idev );
159- kfree (handle );
160- }
161-
162- static int __fault_domain_replace_dev (struct iommufd_device * idev ,
163- struct iommufd_hw_pagetable * hwpt ,
164- struct iommufd_hw_pagetable * old )
165- {
166- struct iommufd_attach_handle * handle , * curr = NULL ;
167- int ret ;
168-
169- if (old -> fault )
170- curr = iommufd_device_get_attach_handle (idev );
171-
172- if (hwpt -> fault ) {
173- handle = kzalloc (sizeof (* handle ), GFP_KERNEL );
174- if (!handle )
175- return - ENOMEM ;
176-
177- handle -> idev = idev ;
178- ret = iommu_replace_group_handle (idev -> igroup -> group ,
179- hwpt -> domain , & handle -> handle );
180- } else {
181- ret = iommu_replace_group_handle (idev -> igroup -> group ,
182- hwpt -> domain , NULL );
183- }
184-
185- if (!ret && curr ) {
186- iommufd_auto_response_faults (old , curr );
187- kfree (curr );
188- }
189-
190- return ret ;
191- }
192-
193- int iommufd_fault_domain_replace_dev (struct iommufd_device * idev ,
194- struct iommufd_hw_pagetable * hwpt ,
195- struct iommufd_hw_pagetable * old )
196- {
197- bool iopf_off = !hwpt -> fault && old -> fault ;
198- bool iopf_on = hwpt -> fault && !old -> fault ;
199- int ret ;
200-
201- if (iopf_on ) {
202- ret = iommufd_fault_iopf_enable (idev );
203- if (ret )
204- return ret ;
205- }
206-
207- ret = __fault_domain_replace_dev (idev , hwpt , old );
208- if (ret ) {
209- if (iopf_on )
210- iommufd_fault_iopf_disable (idev );
211- return ret ;
212- }
213-
214- if (iopf_off )
215- iommufd_fault_iopf_disable (idev );
216-
217- return 0 ;
218- }
219-
220100void iommufd_fault_destroy (struct iommufd_object * obj )
221101{
222102 struct iommufd_fault * fault = container_of (obj , struct iommufd_fault , obj );
0 commit comments