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