Lines Matching +full:iommu +full:- +full:secure +full:- +full:id

1 // SPDX-License-Identifier: GPL-2.0-only
6 /* Driver should use a per-structure helper in include/linux/iommufd.h */
12 return -EINVAL; in _iommufd_object_depend()
14 if (obj_dependent->type != obj_depended->type) in _iommufd_object_depend()
15 return -EINVAL; in _iommufd_object_depend()
17 refcount_inc(&obj_depended->users); in _iommufd_object_depend()
22 /* Driver should use a per-structure helper in include/linux/iommufd.h */
27 obj_dependent->type != obj_depended->type)) in _iommufd_object_undepend()
30 refcount_dec(&obj_depended->users); in _iommufd_object_undepend()
37 * Driver should use a per-structure helper in include/linux/iommufd.h
48 return -EINVAL; in _iommufd_alloc_mmap()
50 return -EINVAL; in _iommufd_alloc_mmap()
54 return -ENOMEM; in _iommufd_alloc_mmap()
55 immap->owner = owner; in _iommufd_alloc_mmap()
56 immap->length = length; in _iommufd_alloc_mmap()
57 immap->mmio_addr = mmio_addr; in _iommufd_alloc_mmap()
60 rc = mtree_alloc_range(&ictx->mt_mmap, &startp, immap, immap->length, in _iommufd_alloc_mmap()
67 /* mmap() syscall will right-shift the offset in vma->vm_pgoff too */ in _iommufd_alloc_mmap()
68 immap->vm_pgoff = startp >> PAGE_SHIFT; in _iommufd_alloc_mmap()
74 /* Driver should use a per-structure helper in include/linux/iommufd.h */
80 immap = mtree_erase(&ictx->mt_mmap, offset); in _iommufd_destroy_mmap()
81 WARN_ON_ONCE(!immap || immap->owner != owner); in _iommufd_destroy_mmap()
88 return vdev->idev->dev; in iommufd_vdevice_to_device()
92 /* Caller should xa_lock(&viommu->vdevs) to protect the return value */
98 lockdep_assert_held(&viommu->vdevs.xa_lock); in iommufd_viommu_find_dev()
100 vdev = xa_load(&viommu->vdevs, vdev_id); in iommufd_viommu_find_dev()
105 /* Return -ENOENT if device is not associated to the vIOMMU */
111 int rc = -ENOENT; in iommufd_viommu_get_vdev_id()
114 return -EINVAL; in iommufd_viommu_get_vdev_id()
116 xa_lock(&viommu->vdevs); in iommufd_viommu_get_vdev_id()
117 xa_for_each(&viommu->vdevs, index, vdev) { in iommufd_viommu_get_vdev_id()
119 *vdev_id = vdev->virt_id; in iommufd_viommu_get_vdev_id()
124 xa_unlock(&viommu->vdevs); in iommufd_viommu_get_vdev_id()
142 return -EINVAL; in iommufd_viommu_report_event()
144 down_read(&viommu->veventqs_rwsem); in iommufd_viommu_report_event()
148 rc = -EOPNOTSUPP; in iommufd_viommu_report_event()
152 spin_lock(&veventq->common.lock); in iommufd_viommu_report_event()
153 if (veventq->num_events == veventq->depth) { in iommufd_viommu_report_event()
154 vevent = &veventq->lost_events_header; in iommufd_viommu_report_event()
160 rc = -ENOMEM; in iommufd_viommu_report_event()
161 vevent = &veventq->lost_events_header; in iommufd_viommu_report_event()
164 vevent->data_len = data_len; in iommufd_viommu_report_event()
165 memcpy(vevent->event_data, event_data, data_len); in iommufd_viommu_report_event()
166 veventq->num_events++; in iommufd_viommu_report_event()
170 spin_unlock(&veventq->common.lock); in iommufd_viommu_report_event()
172 up_read(&viommu->veventqs_rwsem); in iommufd_viommu_report_event()
191 lockdep_assert_held(&ictx->sw_msi_lock); in iommufd_sw_msi_get_map()
193 list_for_each_entry(cur, &ictx->sw_msi_list, sw_msi_item) { in iommufd_sw_msi_get_map()
194 if (cur->sw_msi_start != sw_msi_start) in iommufd_sw_msi_get_map()
196 max_pgoff = max(max_pgoff, cur->pgoff + 1); in iommufd_sw_msi_get_map()
197 if (cur->msi_addr == msi_addr) in iommufd_sw_msi_get_map()
201 if (ictx->sw_msi_id >= in iommufd_sw_msi_get_map()
203 return ERR_PTR(-EOVERFLOW); in iommufd_sw_msi_get_map()
207 return ERR_PTR(-ENOMEM); in iommufd_sw_msi_get_map()
209 cur->sw_msi_start = sw_msi_start; in iommufd_sw_msi_get_map()
210 cur->msi_addr = msi_addr; in iommufd_sw_msi_get_map()
211 cur->pgoff = max_pgoff; in iommufd_sw_msi_get_map()
212 cur->id = ictx->sw_msi_id++; in iommufd_sw_msi_get_map()
213 list_add_tail(&cur->sw_msi_item, &ictx->sw_msi_list); in iommufd_sw_msi_get_map()
223 lockdep_assert_held(&ictx->sw_msi_lock); in iommufd_sw_msi_install()
225 iova = msi_map->sw_msi_start + msi_map->pgoff * PAGE_SIZE; in iommufd_sw_msi_install()
226 if (!test_bit(msi_map->id, hwpt_paging->present_sw_msi.bitmap)) { in iommufd_sw_msi_install()
229 rc = iommu_map(hwpt_paging->common.domain, iova, in iommufd_sw_msi_install()
230 msi_map->msi_addr, PAGE_SIZE, in iommufd_sw_msi_install()
235 __set_bit(msi_map->id, hwpt_paging->present_sw_msi.bitmap); in iommufd_sw_msi_install()
243 * IOMMU. msi_addr is the physical address of the MSI page. iommufd will
260 * It is safe to call iommu_attach_handle_get() here because the iommu in iommufd_sw_msi()
267 iommu_attach_handle_get(dev->iommu_group, IOMMU_NO_PASID, 0); in iommufd_sw_msi()
270 hwpt_paging = find_hwpt_paging(domain->iommufd_hwpt); in iommufd_sw_msi()
274 if (handle->idev->igroup->sw_msi_start == PHYS_ADDR_MAX) in iommufd_sw_msi()
277 ictx = handle->idev->ictx; in iommufd_sw_msi()
278 guard(mutex)(&ictx->sw_msi_lock); in iommufd_sw_msi()
282 * that is secure to map at PAGE_SIZE. in iommufd_sw_msi()
284 msi_map = iommufd_sw_msi_get_map(handle->idev->ictx, in iommufd_sw_msi()
286 handle->idev->igroup->sw_msi_start); in iommufd_sw_msi()
293 __set_bit(msi_map->id, handle->idev->igroup->required_sw_msi.bitmap); in iommufd_sw_msi()
295 iova = msi_map->sw_msi_start + msi_map->pgoff * PAGE_SIZE; in iommufd_sw_msi()