[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <0e5dd1479a55d8af7adfe44390f8e45186295dce.1607332046.git.yuleixzhang@tencent.com>
Date: Mon, 7 Dec 2020 19:31:29 +0800
From: yulei.kernel@...il.com
To: linux-mm@...ck.org, akpm@...ux-foundation.org,
linux-fsdevel@...r.kernel.org, kvm@...r.kernel.org,
linux-kernel@...r.kernel.org, naoya.horiguchi@....com,
viro@...iv.linux.org.uk, pbonzini@...hat.com
Cc: joao.m.martins@...cle.com, rdunlap@...radead.org,
sean.j.christopherson@...el.com, xiaoguangrong.eric@...il.com,
kernellwp@...il.com, lihaiwei.kernel@...il.com,
Yulei Zhang <yuleixzhang@...cent.com>,
Chen Zhuo <sagazchen@...cent.com>
Subject: [RFC V2 36/37] vfio: support dmempage refcount for vfio
From: Yulei Zhang <yuleixzhang@...cent.com>
Add get/put_dmem_pfn(), each time when vfio module reference/release
dmempages.
Signed-off-by: Chen Zhuo <sagazchen@...cent.com>
Signed-off-by: Yulei Zhang <yuleixzhang@...cent.com>
---
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@...hat.com>"
@@ -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
Powered by blists - more mailing lists