|
29 | 29 | #include <linux/nospec.h> |
30 | 30 | #include <linux/sched/mm.h> |
31 | 31 | #include <linux/iommufd.h> |
| 32 | +#ifdef CONFIG_VFIO_PCI_DMABUF |
32 | 33 | #include <linux/pci-p2pdma.h> |
| 34 | +#endif |
33 | 35 | #if IS_ENABLED(CONFIG_EEH) |
34 | 36 | #include <asm/eeh.h> |
35 | 37 | #endif |
@@ -288,6 +290,8 @@ static int vfio_pci_runtime_pm_entry(struct vfio_pci_core_device *vdev, |
288 | 290 | * semaphore. |
289 | 291 | */ |
290 | 292 | vfio_pci_zap_and_down_write_memory_lock(vdev); |
| 293 | + vfio_pci_dma_buf_move(vdev, true); |
| 294 | + |
291 | 295 | if (vdev->pm_runtime_engaged) { |
292 | 296 | up_write(&vdev->memory_lock); |
293 | 297 | return -EINVAL; |
@@ -371,6 +375,8 @@ static void vfio_pci_runtime_pm_exit(struct vfio_pci_core_device *vdev) |
371 | 375 | */ |
372 | 376 | down_write(&vdev->memory_lock); |
373 | 377 | __vfio_pci_runtime_pm_exit(vdev); |
| 378 | + if (__vfio_pci_memory_enabled(vdev)) |
| 379 | + vfio_pci_dma_buf_move(vdev, false); |
374 | 380 | up_write(&vdev->memory_lock); |
375 | 381 | } |
376 | 382 |
|
@@ -691,6 +697,8 @@ void vfio_pci_core_close_device(struct vfio_device *core_vdev) |
691 | 697 | #endif |
692 | 698 | vfio_pci_core_disable(vdev); |
693 | 699 |
|
| 700 | + vfio_pci_dma_buf_cleanup(vdev); |
| 701 | + |
694 | 702 | mutex_lock(&vdev->igate); |
695 | 703 | if (vdev->err_trigger) { |
696 | 704 | eventfd_ctx_put(vdev->err_trigger); |
@@ -1223,7 +1231,10 @@ static int vfio_pci_ioctl_reset(struct vfio_pci_core_device *vdev, |
1223 | 1231 | */ |
1224 | 1232 | vfio_pci_set_power_state(vdev, PCI_D0); |
1225 | 1233 |
|
| 1234 | + vfio_pci_dma_buf_move(vdev, true); |
1226 | 1235 | ret = pci_try_reset_function(vdev->pdev); |
| 1236 | + if (__vfio_pci_memory_enabled(vdev)) |
| 1237 | + vfio_pci_dma_buf_move(vdev, false); |
1227 | 1238 | up_write(&vdev->memory_lock); |
1228 | 1239 |
|
1229 | 1240 | return ret; |
@@ -1512,6 +1523,8 @@ int vfio_pci_core_ioctl_feature(struct vfio_device *device, u32 flags, |
1512 | 1523 | return vfio_pci_core_pm_exit(vdev, flags, arg, argsz); |
1513 | 1524 | case VFIO_DEVICE_FEATURE_PCI_VF_TOKEN: |
1514 | 1525 | return vfio_pci_core_feature_token(vdev, flags, arg, argsz); |
| 1526 | + case VFIO_DEVICE_FEATURE_DMA_BUF: |
| 1527 | + return vfio_pci_core_feature_dma_buf(vdev, flags, arg, argsz); |
1515 | 1528 | default: |
1516 | 1529 | return -ENOTTY; |
1517 | 1530 | } |
@@ -2088,9 +2101,13 @@ int vfio_pci_core_init_dev(struct vfio_device *core_vdev) |
2088 | 2101 | INIT_LIST_HEAD(&vdev->dummy_resources_list); |
2089 | 2102 | INIT_LIST_HEAD(&vdev->ioeventfds_list); |
2090 | 2103 | INIT_LIST_HEAD(&vdev->sriov_pfs_item); |
| 2104 | +#ifdef CONFIG_VFIO_PCI_DMABUF |
2091 | 2105 | vdev->provider = pci_p2pdma_enable(vdev->pdev); |
2092 | 2106 | if (IS_ERR(vdev->provider)) |
2093 | 2107 | return PTR_ERR(vdev->provider); |
| 2108 | + |
| 2109 | + INIT_LIST_HEAD(&vdev->dmabufs); |
| 2110 | +#endif |
2094 | 2111 | init_rwsem(&vdev->memory_lock); |
2095 | 2112 | xa_init(&vdev->ctx); |
2096 | 2113 |
|
@@ -2473,11 +2490,17 @@ static int vfio_pci_dev_set_hot_reset(struct vfio_device_set *dev_set, |
2473 | 2490 | * cause the PCI config space reset without restoring the original |
2474 | 2491 | * state (saved locally in 'vdev->pm_save'). |
2475 | 2492 | */ |
2476 | | - list_for_each_entry(vdev, &dev_set->device_list, vdev.dev_set_list) |
| 2493 | + list_for_each_entry(vdev, &dev_set->device_list, vdev.dev_set_list) { |
| 2494 | + vfio_pci_dma_buf_move(vdev, true); |
2477 | 2495 | vfio_pci_set_power_state(vdev, PCI_D0); |
| 2496 | + } |
2478 | 2497 |
|
2479 | 2498 | ret = pci_reset_bus(pdev); |
2480 | 2499 |
|
| 2500 | + list_for_each_entry(vdev, &dev_set->device_list, vdev.dev_set_list) |
| 2501 | + if (__vfio_pci_memory_enabled(vdev)) |
| 2502 | + vfio_pci_dma_buf_move(vdev, false); |
| 2503 | + |
2481 | 2504 | vdev = list_last_entry(&dev_set->device_list, |
2482 | 2505 | struct vfio_pci_core_device, vdev.dev_set_list); |
2483 | 2506 |
|
|
0 commit comments