From: Yulei Zhang <yuleixzhang@xxxxxxxxxxx> Add get/put_dmem_pfn(), each time when vfio module reference/release dmempages. Signed-off-by: Chen Zhuo <sagazchen@xxxxxxxxxxx> Signed-off-by: Yulei Zhang <yuleixzhang@xxxxxxxxxxx> --- drivers/vfio/vfio_iommu_type1.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index c465d1a..4856a89 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -39,6 +39,7 @@ #include <linux/notifier.h> #include <linux/dma-iommu.h> #include <linux/irqdomain.h> +#include <linux/dmem.h> #define DRIVER_VERSION "0.2" #define DRIVER_AUTHOR "Alex Williamson <alex.williamson@xxxxxxxxxx>" @@ -411,7 +412,10 @@ static int put_pfn(unsigned long pfn, int prot) unpin_user_pages_dirty_lock(&page, 1, prot & IOMMU_WRITE); return 1; - } + } else if (is_dmem_pfn(pfn)) + put_dmem_pfn(pfn); + + /* Dmem page is not counted against user. */ return 0; } @@ -477,6 +481,9 @@ static int vaddr_get_pfn(struct mm_struct *mm, unsigned long vaddr, if (!ret && !is_invalid_reserved_pfn(*pfn)) ret = -EFAULT; + + if (!ret && is_dmem_pfn(*pfn)) + get_dmem_pfn(*pfn); } done: mmap_read_unlock(mm); -- 1.8.3.1