|
18 | 18 | #include <uapi/linux/iommufd.h> |
19 | 19 | #include <linux/iommufd.h> |
20 | 20 |
|
| 21 | +#include "io_pagetable.h" |
21 | 22 | #include "iommufd_private.h" |
22 | 23 | #include "iommufd_test.h" |
23 | 24 |
|
24 | 25 | struct iommufd_object_ops { |
25 | 26 | void (*destroy)(struct iommufd_object *obj); |
26 | 27 | }; |
27 | 28 | static const struct iommufd_object_ops iommufd_object_ops[]; |
| 29 | +static struct miscdevice vfio_misc_dev; |
28 | 30 |
|
29 | 31 | struct iommufd_object *_iommufd_object_alloc(struct iommufd_ctx *ictx, |
30 | 32 | size_t size, |
@@ -170,6 +172,16 @@ static int iommufd_fops_open(struct inode *inode, struct file *filp) |
170 | 172 | if (!ictx) |
171 | 173 | return -ENOMEM; |
172 | 174 |
|
| 175 | + /* |
| 176 | + * For compatibility with VFIO when /dev/vfio/vfio is opened we default |
| 177 | + * to the same rlimit accounting as vfio uses. |
| 178 | + */ |
| 179 | + if (IS_ENABLED(CONFIG_IOMMUFD_VFIO_CONTAINER) && |
| 180 | + filp->private_data == &vfio_misc_dev) { |
| 181 | + ictx->account_mode = IOPT_PAGES_ACCOUNT_MM; |
| 182 | + pr_info_once("IOMMUFD is providing /dev/vfio/vfio, not VFIO.\n"); |
| 183 | + } |
| 184 | + |
173 | 185 | xa_init_flags(&ictx->objects, XA_FLAGS_ALLOC1 | XA_FLAGS_ACCOUNT); |
174 | 186 | ictx->file = filp; |
175 | 187 | filp->private_data = ictx; |
@@ -400,25 +412,49 @@ static struct miscdevice iommu_misc_dev = { |
400 | 412 | .mode = 0660, |
401 | 413 | }; |
402 | 414 |
|
| 415 | + |
| 416 | +static struct miscdevice vfio_misc_dev = { |
| 417 | + .minor = VFIO_MINOR, |
| 418 | + .name = "vfio", |
| 419 | + .fops = &iommufd_fops, |
| 420 | + .nodename = "vfio/vfio", |
| 421 | + .mode = 0666, |
| 422 | +}; |
| 423 | + |
403 | 424 | static int __init iommufd_init(void) |
404 | 425 | { |
405 | 426 | int ret; |
406 | 427 |
|
407 | 428 | ret = misc_register(&iommu_misc_dev); |
408 | 429 | if (ret) |
409 | 430 | return ret; |
| 431 | + |
| 432 | + if (IS_ENABLED(CONFIG_IOMMUFD_VFIO_CONTAINER)) { |
| 433 | + ret = misc_register(&vfio_misc_dev); |
| 434 | + if (ret) |
| 435 | + goto err_misc; |
| 436 | + } |
410 | 437 | iommufd_test_init(); |
411 | 438 | return 0; |
| 439 | +err_misc: |
| 440 | + misc_deregister(&iommu_misc_dev); |
| 441 | + return ret; |
412 | 442 | } |
413 | 443 |
|
414 | 444 | static void __exit iommufd_exit(void) |
415 | 445 | { |
416 | 446 | iommufd_test_exit(); |
| 447 | + if (IS_ENABLED(CONFIG_IOMMUFD_VFIO_CONTAINER)) |
| 448 | + misc_deregister(&vfio_misc_dev); |
417 | 449 | misc_deregister(&iommu_misc_dev); |
418 | 450 | } |
419 | 451 |
|
420 | 452 | module_init(iommufd_init); |
421 | 453 | module_exit(iommufd_exit); |
422 | 454 |
|
| 455 | +#if IS_ENABLED(CONFIG_IOMMUFD_VFIO_CONTAINER) |
| 456 | +MODULE_ALIAS_MISCDEV(VFIO_MINOR); |
| 457 | +MODULE_ALIAS("devname:vfio/vfio"); |
| 458 | +#endif |
423 | 459 | MODULE_DESCRIPTION("I/O Address Space Management for passthrough devices"); |
424 | 460 | MODULE_LICENSE("GPL"); |
0 commit comments