Lines Matching +full:elm +full:- +full:id

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2021-2022, NVIDIA CORPORATION & AFFILIATES
17 rc = iopt_unmap_all(&ioas->iopt, NULL); in iommufd_ioas_destroy()
18 WARN_ON(rc && rc != -ENOENT); in iommufd_ioas_destroy()
19 iopt_destroy_table(&ioas->iopt); in iommufd_ioas_destroy()
20 mutex_destroy(&ioas->mutex); in iommufd_ioas_destroy()
31 iopt_init_table(&ioas->iopt); in iommufd_ioas_alloc()
32 INIT_LIST_HEAD(&ioas->hwpt_list); in iommufd_ioas_alloc()
33 mutex_init(&ioas->mutex); in iommufd_ioas_alloc()
39 struct iommu_ioas_alloc *cmd = ucmd->cmd; in iommufd_ioas_alloc_ioctl()
43 if (cmd->flags) in iommufd_ioas_alloc_ioctl()
44 return -EOPNOTSUPP; in iommufd_ioas_alloc_ioctl()
46 ioas = iommufd_ioas_alloc(ucmd->ictx); in iommufd_ioas_alloc_ioctl()
50 cmd->out_ioas_id = ioas->obj.id; in iommufd_ioas_alloc_ioctl()
54 iommufd_object_finalize(ucmd->ictx, &ioas->obj); in iommufd_ioas_alloc_ioctl()
58 iommufd_object_abort_and_destroy(ucmd->ictx, &ioas->obj); in iommufd_ioas_alloc_ioctl()
65 struct iommu_ioas_iova_ranges *cmd = ucmd->cmd; in iommufd_ioas_iova_ranges()
71 if (cmd->__reserved) in iommufd_ioas_iova_ranges()
72 return -EOPNOTSUPP; in iommufd_ioas_iova_ranges()
74 ioas = iommufd_get_ioas(ucmd->ictx, cmd->ioas_id); in iommufd_ioas_iova_ranges()
78 down_read(&ioas->iopt.iova_rwsem); in iommufd_ioas_iova_ranges()
79 max_iovas = cmd->num_iovas; in iommufd_ioas_iova_ranges()
80 ranges = u64_to_user_ptr(cmd->allowed_iovas); in iommufd_ioas_iova_ranges()
81 cmd->num_iovas = 0; in iommufd_ioas_iova_ranges()
82 cmd->out_iova_alignment = ioas->iopt.iova_alignment; in iommufd_ioas_iova_ranges()
83 interval_tree_for_each_span(&span, &ioas->iopt.reserved_itree, 0, in iommufd_ioas_iova_ranges()
87 if (cmd->num_iovas < max_iovas) { in iommufd_ioas_iova_ranges()
88 struct iommu_iova_range elm = { in iommufd_ioas_iova_ranges() local
93 if (copy_to_user(&ranges[cmd->num_iovas], &elm, in iommufd_ioas_iova_ranges()
94 sizeof(elm))) { in iommufd_ioas_iova_ranges()
95 rc = -EFAULT; in iommufd_ioas_iova_ranges()
99 cmd->num_iovas++; in iommufd_ioas_iova_ranges()
104 if (cmd->num_iovas > max_iovas) in iommufd_ioas_iova_ranges()
105 rc = -EMSGSIZE; in iommufd_ioas_iova_ranges()
107 up_read(&ioas->iopt.iova_rwsem); in iommufd_ioas_iova_ranges()
108 iommufd_put_object(ucmd->ictx, &ioas->obj); in iommufd_ioas_iova_ranges()
123 return -EFAULT; in iommufd_ioas_load_iovas()
126 return -EINVAL; in iommufd_ioas_load_iovas()
129 return -EINVAL; in iommufd_ioas_load_iovas()
133 return -ENOMEM; in iommufd_ioas_load_iovas()
134 allowed->node.start = range.start; in iommufd_ioas_load_iovas()
135 allowed->node.last = range.last; in iommufd_ioas_load_iovas()
137 interval_tree_insert(&allowed->node, itree); in iommufd_ioas_load_iovas()
144 struct iommu_ioas_allow_iovas *cmd = ucmd->cmd; in iommufd_ioas_allow_iovas()
151 if (cmd->__reserved) in iommufd_ioas_allow_iovas()
152 return -EOPNOTSUPP; in iommufd_ioas_allow_iovas()
154 ioas = iommufd_get_ioas(ucmd->ictx, cmd->ioas_id); in iommufd_ioas_allow_iovas()
157 iopt = &ioas->iopt; in iommufd_ioas_allow_iovas()
160 u64_to_user_ptr(cmd->allowed_iovas), in iommufd_ioas_allow_iovas()
161 cmd->num_iovas); in iommufd_ioas_allow_iovas()
178 iommufd_put_object(ucmd->ictx, &ioas->obj); in iommufd_ioas_allow_iovas()
202 struct iommu_ioas_map *cmd = ucmd->cmd; in iommufd_ioas_map()
203 unsigned long iova = cmd->iova; in iommufd_ioas_map()
208 if ((cmd->flags & in iommufd_ioas_map()
211 cmd->__reserved) in iommufd_ioas_map()
212 return -EOPNOTSUPP; in iommufd_ioas_map()
213 if (cmd->iova >= ULONG_MAX || cmd->length >= ULONG_MAX) in iommufd_ioas_map()
214 return -EOVERFLOW; in iommufd_ioas_map()
216 if (!(cmd->flags & in iommufd_ioas_map()
218 return -EINVAL; in iommufd_ioas_map()
220 ioas = iommufd_get_ioas(ucmd->ictx, cmd->ioas_id); in iommufd_ioas_map()
224 if (!(cmd->flags & IOMMU_IOAS_MAP_FIXED_IOVA)) in iommufd_ioas_map()
226 rc = iopt_map_user_pages(ucmd->ictx, &ioas->iopt, &iova, in iommufd_ioas_map()
227 u64_to_user_ptr(cmd->user_va), cmd->length, in iommufd_ioas_map()
228 conv_iommu_prot(cmd->flags), flags); in iommufd_ioas_map()
232 cmd->iova = iova; in iommufd_ioas_map()
235 iommufd_put_object(ucmd->ictx, &ioas->obj); in iommufd_ioas_map()
241 struct iommu_ioas_copy *cmd = ucmd->cmd; in iommufd_ioas_copy()
249 iommufd_test_syz_conv_iova_id(ucmd, cmd->src_ioas_id, &cmd->src_iova, in iommufd_ioas_copy()
250 &cmd->flags); in iommufd_ioas_copy()
252 if ((cmd->flags & in iommufd_ioas_copy()
255 return -EOPNOTSUPP; in iommufd_ioas_copy()
256 if (cmd->length >= ULONG_MAX || cmd->src_iova >= ULONG_MAX || in iommufd_ioas_copy()
257 cmd->dst_iova >= ULONG_MAX) in iommufd_ioas_copy()
258 return -EOVERFLOW; in iommufd_ioas_copy()
260 if (!(cmd->flags & in iommufd_ioas_copy()
262 return -EINVAL; in iommufd_ioas_copy()
264 src_ioas = iommufd_get_ioas(ucmd->ictx, cmd->src_ioas_id); in iommufd_ioas_copy()
267 rc = iopt_get_pages(&src_ioas->iopt, cmd->src_iova, cmd->length, in iommufd_ioas_copy()
269 iommufd_put_object(ucmd->ictx, &src_ioas->obj); in iommufd_ioas_copy()
273 dst_ioas = iommufd_get_ioas(ucmd->ictx, cmd->dst_ioas_id); in iommufd_ioas_copy()
279 if (!(cmd->flags & IOMMU_IOAS_MAP_FIXED_IOVA)) in iommufd_ioas_copy()
281 iova = cmd->dst_iova; in iommufd_ioas_copy()
282 rc = iopt_map_pages(&dst_ioas->iopt, &pages_list, cmd->length, &iova, in iommufd_ioas_copy()
283 conv_iommu_prot(cmd->flags), flags); in iommufd_ioas_copy()
287 cmd->dst_iova = iova; in iommufd_ioas_copy()
290 iommufd_put_object(ucmd->ictx, &dst_ioas->obj); in iommufd_ioas_copy()
298 struct iommu_ioas_unmap *cmd = ucmd->cmd; in iommufd_ioas_unmap()
303 ioas = iommufd_get_ioas(ucmd->ictx, cmd->ioas_id); in iommufd_ioas_unmap()
307 if (cmd->iova == 0 && cmd->length == U64_MAX) { in iommufd_ioas_unmap()
308 rc = iopt_unmap_all(&ioas->iopt, &unmapped); in iommufd_ioas_unmap()
312 if (cmd->iova >= ULONG_MAX || cmd->length >= ULONG_MAX) { in iommufd_ioas_unmap()
313 rc = -EOVERFLOW; in iommufd_ioas_unmap()
316 rc = iopt_unmap_iova(&ioas->iopt, cmd->iova, cmd->length, in iommufd_ioas_unmap()
322 cmd->length = unmapped; in iommufd_ioas_unmap()
326 iommufd_put_object(ucmd->ictx, &ioas->obj); in iommufd_ioas_unmap()
333 if (cmd->object_id) in iommufd_option_rlimit_mode()
334 return -EOPNOTSUPP; in iommufd_option_rlimit_mode()
336 if (cmd->op == IOMMU_OPTION_OP_GET) { in iommufd_option_rlimit_mode()
337 cmd->val64 = ictx->account_mode == IOPT_PAGES_ACCOUNT_MM; in iommufd_option_rlimit_mode()
340 if (cmd->op == IOMMU_OPTION_OP_SET) { in iommufd_option_rlimit_mode()
344 return -EPERM; in iommufd_option_rlimit_mode()
346 xa_lock(&ictx->objects); in iommufd_option_rlimit_mode()
347 if (!xa_empty(&ictx->objects)) { in iommufd_option_rlimit_mode()
348 rc = -EBUSY; in iommufd_option_rlimit_mode()
350 if (cmd->val64 == 0) in iommufd_option_rlimit_mode()
351 ictx->account_mode = IOPT_PAGES_ACCOUNT_USER; in iommufd_option_rlimit_mode()
352 else if (cmd->val64 == 1) in iommufd_option_rlimit_mode()
353 ictx->account_mode = IOPT_PAGES_ACCOUNT_MM; in iommufd_option_rlimit_mode()
355 rc = -EINVAL; in iommufd_option_rlimit_mode()
357 xa_unlock(&ictx->objects); in iommufd_option_rlimit_mode()
361 return -EOPNOTSUPP; in iommufd_option_rlimit_mode()
367 if (cmd->op == IOMMU_OPTION_OP_GET) { in iommufd_ioas_option_huge_pages()
368 cmd->val64 = !ioas->iopt.disable_large_pages; in iommufd_ioas_option_huge_pages()
371 if (cmd->op == IOMMU_OPTION_OP_SET) { in iommufd_ioas_option_huge_pages()
372 if (cmd->val64 == 0) in iommufd_ioas_option_huge_pages()
373 return iopt_disable_large_pages(&ioas->iopt); in iommufd_ioas_option_huge_pages()
374 if (cmd->val64 == 1) { in iommufd_ioas_option_huge_pages()
375 iopt_enable_large_pages(&ioas->iopt); in iommufd_ioas_option_huge_pages()
378 return -EINVAL; in iommufd_ioas_option_huge_pages()
380 return -EOPNOTSUPP; in iommufd_ioas_option_huge_pages()
385 struct iommu_option *cmd = ucmd->cmd; in iommufd_ioas_option()
389 if (cmd->__reserved) in iommufd_ioas_option()
390 return -EOPNOTSUPP; in iommufd_ioas_option()
392 ioas = iommufd_get_ioas(ucmd->ictx, cmd->object_id); in iommufd_ioas_option()
396 switch (cmd->option_id) { in iommufd_ioas_option()
401 rc = -EOPNOTSUPP; in iommufd_ioas_option()
404 iommufd_put_object(ucmd->ictx, &ioas->obj); in iommufd_ioas_option()