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

1 // SPDX-License-Identifier: GPL-2.0-only
15 return ERR_PTR(-ENOMEM); in _iommufd_object_alloc()
16 obj->type = type; in _iommufd_object_alloc()
18 refcount_set(&obj->shortterm_users, 1); in _iommufd_object_alloc()
19 refcount_set(&obj->users, 1); in _iommufd_object_alloc()
22 * Reserve an ID in the xarray but do not publish the pointer yet since in _iommufd_object_alloc()
28 rc = xa_alloc(&ictx->objects, &obj->id, XA_ZERO_ENTRY, xa_limit_31b, in _iommufd_object_alloc()
39 /* Caller should xa_lock(&viommu->vdevs) to protect the return value */
45 lockdep_assert_held(&viommu->vdevs.xa_lock); in iommufd_viommu_find_dev()
47 vdev = xa_load(&viommu->vdevs, vdev_id); in iommufd_viommu_find_dev()
48 return vdev ? vdev->dev : NULL; in iommufd_viommu_find_dev()
52 /* Return -ENOENT if device is not associated to the vIOMMU */
58 int rc = -ENOENT; in iommufd_viommu_get_vdev_id()
61 return -EINVAL; in iommufd_viommu_get_vdev_id()
63 xa_lock(&viommu->vdevs); in iommufd_viommu_get_vdev_id()
64 xa_for_each(&viommu->vdevs, index, vdev) { in iommufd_viommu_get_vdev_id()
65 if (vdev->dev == dev) { in iommufd_viommu_get_vdev_id()
66 *vdev_id = vdev->id; in iommufd_viommu_get_vdev_id()
71 xa_unlock(&viommu->vdevs); in iommufd_viommu_get_vdev_id()
89 return -EINVAL; in iommufd_viommu_report_event()
91 down_read(&viommu->veventqs_rwsem); in iommufd_viommu_report_event()
95 rc = -EOPNOTSUPP; in iommufd_viommu_report_event()
99 spin_lock(&veventq->common.lock); in iommufd_viommu_report_event()
100 if (veventq->num_events == veventq->depth) { in iommufd_viommu_report_event()
101 vevent = &veventq->lost_events_header; in iommufd_viommu_report_event()
107 rc = -ENOMEM; in iommufd_viommu_report_event()
108 vevent = &veventq->lost_events_header; in iommufd_viommu_report_event()
111 memcpy(vevent->event_data, event_data, data_len); in iommufd_viommu_report_event()
112 vevent->data_len = data_len; in iommufd_viommu_report_event()
113 veventq->num_events++; in iommufd_viommu_report_event()
117 spin_unlock(&veventq->common.lock); in iommufd_viommu_report_event()
119 up_read(&viommu->veventqs_rwsem); in iommufd_viommu_report_event()
138 lockdep_assert_held(&ictx->sw_msi_lock); in iommufd_sw_msi_get_map()
140 list_for_each_entry(cur, &ictx->sw_msi_list, sw_msi_item) { in iommufd_sw_msi_get_map()
141 if (cur->sw_msi_start != sw_msi_start) in iommufd_sw_msi_get_map()
143 max_pgoff = max(max_pgoff, cur->pgoff + 1); in iommufd_sw_msi_get_map()
144 if (cur->msi_addr == msi_addr) in iommufd_sw_msi_get_map()
148 if (ictx->sw_msi_id >= in iommufd_sw_msi_get_map()
150 return ERR_PTR(-EOVERFLOW); in iommufd_sw_msi_get_map()
154 return ERR_PTR(-ENOMEM); in iommufd_sw_msi_get_map()
156 cur->sw_msi_start = sw_msi_start; in iommufd_sw_msi_get_map()
157 cur->msi_addr = msi_addr; in iommufd_sw_msi_get_map()
158 cur->pgoff = max_pgoff; in iommufd_sw_msi_get_map()
159 cur->id = ictx->sw_msi_id++; in iommufd_sw_msi_get_map()
160 list_add_tail(&cur->sw_msi_item, &ictx->sw_msi_list); in iommufd_sw_msi_get_map()
170 lockdep_assert_held(&ictx->sw_msi_lock); in iommufd_sw_msi_install()
172 iova = msi_map->sw_msi_start + msi_map->pgoff * PAGE_SIZE; in iommufd_sw_msi_install()
173 if (!test_bit(msi_map->id, hwpt_paging->present_sw_msi.bitmap)) { in iommufd_sw_msi_install()
176 rc = iommu_map(hwpt_paging->common.domain, iova, in iommufd_sw_msi_install()
177 msi_map->msi_addr, PAGE_SIZE, in iommufd_sw_msi_install()
182 __set_bit(msi_map->id, hwpt_paging->present_sw_msi.bitmap); in iommufd_sw_msi_install()
190 * IOMMU. msi_addr is the physical address of the MSI page. iommufd will
207 * It is safe to call iommu_attach_handle_get() here because the iommu in iommufd_sw_msi()
214 iommu_attach_handle_get(dev->iommu_group, IOMMU_NO_PASID, 0); in iommufd_sw_msi()
217 hwpt_paging = find_hwpt_paging(domain->iommufd_hwpt); in iommufd_sw_msi()
221 if (handle->idev->igroup->sw_msi_start == PHYS_ADDR_MAX) in iommufd_sw_msi()
224 ictx = handle->idev->ictx; in iommufd_sw_msi()
225 guard(mutex)(&ictx->sw_msi_lock); in iommufd_sw_msi()
229 * that is secure to map at PAGE_SIZE. in iommufd_sw_msi()
231 msi_map = iommufd_sw_msi_get_map(handle->idev->ictx, in iommufd_sw_msi()
233 handle->idev->igroup->sw_msi_start); in iommufd_sw_msi()
240 __set_bit(msi_map->id, handle->idev->igroup->required_sw_msi.bitmap); in iommufd_sw_msi()
242 iova = msi_map->sw_msi_start + msi_map->pgoff * PAGE_SIZE; in iommufd_sw_msi()