Skip to contentSkip to conversation

Fix kvm misconceives NVDIMM pages as reserved mmio

PATCH Superseded Zhang Yi 4 participants 13 messages Jul 10, 2018 – Aug 8, 2018 1 message not in the archive

Subsystems (6)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Zhang Yi

author
#0 lore raw

v2 cover Fix kvm misconceives NVDIMM pages as reserved mmio

For device specific memory space, when we move these area of pfn to memory zone, we will set the page reserved flag at that time, some of these reserved for device mmio, and some of these are not, such as NVDIMM pmem.

Now, we map these dev_dax or fs_dax pages to kvm for DIMM/NVDIMM backend, since these pages are reserved. the check of kvm_is_reserved_pfn() misconceives those pages as MMIO. Therefor, we introduce 2 page map types, MEMORY_DEVICE_FS_DAX/MEMORY_DEVICE_DEV_DAX, to indentify these pages are from NVDIMM pmem. and let kvm treat these as normal pages.

Without this patch, Many operations will be missed due to this mistreatment to pmem pages. For example, a page may not have chance to be unpinned for KVM guest(in kvm_release_pfn_clean); not able to be marked as dirty/accessed(in kvm_set_pfn_dirty/accessed) etc.

V1:
https://lkml.org/lkml/2018/7/4/91

V2:
*Add documentation for MEMORY_DEVICE_DEV_DAX memory type in comment block *Add is_dax_page() in mm.h to differentiate the pages is from DAX device. *Remove the function kvm_is_nd_pfn().

Zhang Yi (4):
kvm: remove redundant reserved page check
mm: introduce memory type MEMORY_DEVICE_DEV_DAX
mm: add a function to differentiate the pages is from DAX device
memory
kvm: add a check if pfn is from NVDIMM pmem.

 drivers/dax/pmem.c       |  1 +
 include/linux/memremap.h |  9 +++++++++
 include/linux/mm.h       | 12 ++++++++++++
 virt/kvm/kvm_main.c      | 16 ++++++++--------
 4 files changed, 30 insertions(+), 8 deletions(-)
Signature · 6 lines
2.7.4

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
author
#1 lore raw

PATCH v2 1/4 kvm: remove redundant reserved page check

PageReserved() is already checked inside kvm_is_reserved_pfn(), remove it from kvm_set_pfn_dirty().

---
 virt/kvm/kvm_main.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
virt/kvm/kvm_main.c +2 -6
index c7b2e92..afb2e6e 100644
@@ -1673,12 +1673,8 @@ EXPORT_SYMBOL_GPL(kvm_release_pfn_dirty);
 
 void kvm_set_pfn_dirty(kvm_pfn_t pfn)
 {
-	if (!kvm_is_reserved_pfn(pfn)) {
-		struct page *page = pfn_to_page(pfn);
-
-		if (!PageReserved(page))
-			SetPageDirty(page);
-	}
+	if (!kvm_is_reserved_pfn(pfn))
+		SetPageDirty(pfn_to_page(pfn));
 }
 EXPORT_SYMBOL_GPL(kvm_set_pfn_dirty);
 
Signature · 6 lines
2.7.4

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
author
#2 lore raw

PATCH v2 2/4 mm: introduce memory type MEMORY_DEVICE_DEV_DAX

In reply to Zhang Yi

Currently, NVDIMM pages will be marked 'PageReserved'. However, unlike other reserved PFNs, pages on NVDIMM shall still behave like normal ones in many cases, i.e. when used as backend memory of KVM guest. This patch introduces a new memory type, MEMORY_DEVICE_DEV_DAX. And set this flag while dax driver hotplug the device memory.

---
 drivers/dax/pmem.c       | 1 +
 include/linux/memremap.h | 9 +++++++++
 2 files changed, 10 insertions(+)
drivers/dax/pmem.c +1 -0
index fd49b24..fb3f363 100644
@@ -111,6 +111,7 @@ static int dax_pmem_probe(struct device *dev)
 		return rc;
 
 	dax_pmem->pgmap.ref = &dax_pmem->ref;
+	dax_pmem->pgmap.type = MEMORY_DEVICE_DEV_DAX;
 	addr = devm_memremap_pages(dev, &dax_pmem->pgmap);
 	if (IS_ERR(addr))
 		return PTR_ERR(addr);
include/linux/memremap.h +9 -0
index 5ebfff6..a36bce8 100644
@@ -53,11 +53,20 @@ struct vmem_altmap {
  * wakeup event whenever a page is unpinned and becomes idle. This
  * wakeup is used to coordinate physical address space management (ex:
  * fs truncate/hole punch) vs pinned pages (ex: device dma).
+ *
+ * MEMORY_DEVICE_DEV_DAX:
+ * DAX driver hotplug the device memory and move it to memory zone, these
+ * pages will be marked reserved flag. However, some other kernel componet
+ * will misconceive these pages are reserved mmio (ex: we map these dev_dax
+ * or fs_dax pages to kvm for DIMM/NVDIMM backend). Together with the type
+ * MEMORY_DEVICE_FS_DAX, we can differentiate the pages on NVDIMM with the
+ * normal reserved pages.
  */
 enum memory_type {
 	MEMORY_DEVICE_PRIVATE = 1,
 	MEMORY_DEVICE_PUBLIC,
 	MEMORY_DEVICE_FS_DAX,
+	MEMORY_DEVICE_DEV_DAX,
 };
 
 /*
Signature · 6 lines
2.7.4

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
#3 lore raw

Re: [PATCH V2 2/4] mm: introduce memory type MEMORY_DEVICE_DEV_DAX

Quoted 31 lines · Zhang Yi

Currently, NVDIMM pages will be marked 'PageReserved'. However, unlike other reserved PFNs, pages on NVDIMM shall still behave like normal ones in many cases, i.e. when used as backend memory of KVM guest. This patch introduces a new memory type, MEMORY_DEVICE_DEV_DAX. And set this flag while dax driver hotplug the device memory.

---
 drivers/dax/pmem.c       | 1 +
 include/linux/memremap.h | 9 +++++++++
 2 files changed, 10 insertions(+)
drivers/dax/pmem.c +1 -0
index fd49b24..fb3f363 100644
@@ -111,6 +111,7 @@ static int dax_pmem_probe(struct device *dev)
 		return rc;
 
 	dax_pmem->pgmap.ref = &dax_pmem->ref;
+	dax_pmem->pgmap.type = MEMORY_DEVICE_DEV_DAX;
 	addr = devm_memremap_pages(dev, &dax_pmem->pgmap);
 	if (IS_ERR(addr))
 		return PTR_ERR(addr);
include/linux/memremap.h +0 -0
index 5ebfff6..a36bce8 100644
@@ -53,11 +53,20 @@ struct vmem_altmap {
  * wakeup event whenever a page is unpinned and becomes idle. This

include/linux/memremap.h struct vmem_altmap { · line 63

Quoted 10 lines
include/linux/memremap.h +8 -0
  * wakeup is used to coordinate physical address space management (ex:
  * fs truncate/hole punch) vs pinned pages (ex: device dma).
+ *
+ * MEMORY_DEVICE_DEV_DAX:
+ * DAX driver hotplug the device memory and move it to memory zone, these
+ * pages will be marked reserved flag. However, some other kernel componet
+ * will misconceive these pages are reserved mmio (ex: we map these dev_dax
+ * or fs_dax pages to kvm for DIMM/NVDIMM backend). Together with the type
+ * MEMORY_DEVICE_FS_DAX, we can differentiate the pages on NVDIMM with the
+ * normal reserved pages.

So I believe the description should be in terms of what kind of memory is the MEMORY_DEVICE_DEV_DAX type, not how users use this type. See comments for other memory types...

Honza

Quoted 12 lines
include/linux/memremap.h +1 -0
  */
 enum memory_type {
 	MEMORY_DEVICE_PRIVATE = 1,
 	MEMORY_DEVICE_PUBLIC,
 	MEMORY_DEVICE_FS_DAX,
+	MEMORY_DEVICE_DEV_DAX,
 };
 
 /*
Signature · 1 line
2.7.4
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
author
#4 lore raw

Re: [PATCH V2 2/4] mm: introduce memory type MEMORY_DEVICE_DEV_DAX

Quoted 46 lines · Jan Kara
Quoted 31 lines · Zhang Yi

Currently, NVDIMM pages will be marked 'PageReserved'. However, unlike other reserved PFNs, pages on NVDIMM shall still behave like normal ones in many cases, i.e. when used as backend memory of KVM guest. This patch introduces a new memory type, MEMORY_DEVICE_DEV_DAX. And set this flag while dax driver hotplug the device memory.

---
 drivers/dax/pmem.c       | 1 +
 include/linux/memremap.h | 9 +++++++++
 2 files changed, 10 insertions(+)
drivers/dax/pmem.c +1 -0
index fd49b24..fb3f363 100644
@@ -111,6 +111,7 @@ static int dax_pmem_probe(struct device *dev)
 		return rc;
 
 	dax_pmem->pgmap.ref = &dax_pmem->ref;
+	dax_pmem->pgmap.type = MEMORY_DEVICE_DEV_DAX;
 	addr = devm_memremap_pages(dev, &dax_pmem->pgmap);
 	if (IS_ERR(addr))
 		return PTR_ERR(addr);
include/linux/memremap.h +0 -0
index 5ebfff6..a36bce8 100644
@@ -53,11 +53,20 @@ struct vmem_altmap {
  * wakeup event whenever a page is unpinned and becomes idle. This

include/linux/memremap.h struct vmem_altmap { · line 63

Quoted 10 lines
include/linux/memremap.h +8 -0
  * wakeup is used to coordinate physical address space management (ex:
  * fs truncate/hole punch) vs pinned pages (ex: device dma).
+ *
+ * MEMORY_DEVICE_DEV_DAX:
+ * DAX driver hotplug the device memory and move it to memory zone, these
+ * pages will be marked reserved flag. However, some other kernel componet
+ * will misconceive these pages are reserved mmio (ex: we map these dev_dax
+ * or fs_dax pages to kvm for DIMM/NVDIMM backend). Together with the type
+ * MEMORY_DEVICE_FS_DAX, we can differentiate the pages on NVDIMM with the
+ * normal reserved pages.

So I believe the description should be in terms of what kind of memory is the MEMORY_DEVICE_DEV_DAX type, not how users use this type. See comments for other memory types...

Quoted 1 line

Honza

Yes, agree, thanks for your kindly review. Jan.

Quoted 9 lines
Quoted 9 lines
include/linux/memremap.h +1 -0
  */
 enum memory_type {
 	MEMORY_DEVICE_PRIVATE = 1,
 	MEMORY_DEVICE_PUBLIC,
 	MEMORY_DEVICE_FS_DAX,
+	MEMORY_DEVICE_DEV_DAX,
 };
 
Quoted 4 lines
Quoted 4 lines
include/linux/memremap.h +0 -0
 /*
Signature · 1 line
2.7.4

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

author
#5 lore raw

PATCH v2 3/4 mm: add a function to differentiate the pages is from DAX device memory

In reply to Zhang Yi

DAX driver hotplug the device memory and move it to memory zone, these pages will be marked reserved flag, however, some other kernel componet will misconceive these pages are reserved mmio (ex: we map these dev_dax or fs_dax pages to kvm for DIMM/NVDIMM backend). Together with the type MEMORY_DEVICE_FS_DAX, we can use is_dax_page() to differentiate the pages is DAX device memory or not.

---
 include/linux/mm.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
include/linux/mm.h +12 -0
index 6e19265..9f0f690 100644
@@ -856,6 +856,13 @@ static inline bool is_device_public_page(const struct page *page)
 		page->pgmap->type == MEMORY_DEVICE_PUBLIC;
 }
 
+static inline bool is_dax_page(const struct page *page)
+{
+	return is_zone_device_page(page) &&
+		(page->pgmap->type == MEMORY_DEVICE_FS_DAX ||
+		page->pgmap->type == MEMORY_DEVICE_DEV_DAX);
+}
+
 #else /* CONFIG_DEV_PAGEMAP_OPS */
 static inline void dev_pagemap_get_ops(void)
 {
@@ -879,6 +886,11 @@ static inline bool is_device_public_page(const struct page *page)
 {
 	return false;
 }
+
+static inline bool is_dax_page(const struct page *page)
+{
+	return false;
+}
 #endif /* CONFIG_DEV_PAGEMAP_OPS */
 
 static inline void get_page(struct page *page)
Signature · 1 line
2.7.4
Acked-by on v2 3/4
#6 lore raw

Re: [PATCH V2 3/4] mm: add a function to differentiate the pages is from DAX device memory

Quoted 9 lines · Zhang Yi

DAX driver hotplug the device memory and move it to memory zone, these pages will be marked reserved flag, however, some other kernel componet will misconceive these pages are reserved mmio (ex: we map these dev_dax or fs_dax pages to kvm for DIMM/NVDIMM backend). Together with the type MEMORY_DEVICE_FS_DAX, we can use is_dax_page() to differentiate the pages is DAX device memory or not.

The patch looks OK to me but I don't really feel too confident about this part of the kernel... But feel free to add my:

Honza

Quoted 37 lines
---
 include/linux/mm.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
include/linux/mm.h +12 -0
index 6e19265..9f0f690 100644
@@ -856,6 +856,13 @@ static inline bool is_device_public_page(const struct page *page)
 		page->pgmap->type == MEMORY_DEVICE_PUBLIC;
 }
 
+static inline bool is_dax_page(const struct page *page)
+{
+	return is_zone_device_page(page) &&
+		(page->pgmap->type == MEMORY_DEVICE_FS_DAX ||
+		page->pgmap->type == MEMORY_DEVICE_DEV_DAX);
+}
+
 #else /* CONFIG_DEV_PAGEMAP_OPS */
 static inline void dev_pagemap_get_ops(void)
 {
@@ -879,6 +886,11 @@ static inline bool is_device_public_page(const struct page *page)
 {
 	return false;
 }
+
+static inline bool is_dax_page(const struct page *page)
+{
+	return false;
+}
 #endif /* CONFIG_DEV_PAGEMAP_OPS */
 
 static inline void get_page(struct page *page)
Signature · 1 line
2.7.4
Signature · 2 lines
Jan Kara <jack-IBi9RG/[email protected]>
SUSE Labs, CR
author
#7 lore raw

PATCH v2 4/4 kvm: add a check if pfn is from NVDIMM pmem.

In reply to Zhang Yi

For device specific memory space, when we move these area of pfn to memory zone, we will set the page reserved flag at that time, some of these reserved for device mmio, and some of these are not, such as NVDIMM pmem.

Now, we map these dev_dax or fs_dax pages to kvm for DIMM/NVDIMM backend, since these pages are reserved. the check of kvm_is_reserved_pfn() misconceives those pages as MMIO. Therefor, we introduce 2 page map types, MEMORY_DEVICE_FS_DAX/MEMORY_DEVICE_DEV_DAX, to indentify these pages are from NVDIMM pmem. and let kvm treat these as normal pages.

Without this patch, Many operations will be missed due to this mistreatment to pmem pages. For example, a page may not have chance to be unpinned for KVM guest(in kvm_release_pfn_clean); not able to be marked as dirty/accessed(in kvm_set_pfn_dirty/accessed) etc

---
 virt/kvm/kvm_main.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
virt/kvm/kvm_main.c +6 -2
index afb2e6e..77e6ba8 100644
@@ -142,8 +142,12 @@ __weak void kvm_arch_mmu_notifier_invalidate_range(struct kvm *kvm,
 
 bool kvm_is_reserved_pfn(kvm_pfn_t pfn)
 {
-	if (pfn_valid(pfn))
-		return PageReserved(pfn_to_page(pfn));
+	struct page *page;
+
+	if (pfn_valid(pfn)) {
+		page = pfn_to_page(pfn);
+		return PageReserved(page) && !is_dax_page(page);
+	}
 
 	return true;
 }
Signature · 6 lines
2.7.4

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

A message that is not in the archive (sent off-list or not yet received): cover.1531241281.git.yi.z.zhang-VuQAYsv1563Yd54FQh9/[email protected]

#9 lore raw

PATCH v2 3/4 mm: add a function to differentiate the pages is from DAX device memory

DAX driver hotplug the device memory and move it to memory zone, these pages will be marked reserved flag, however, some other kernel componet will misconceive these pages are reserved mmio (ex: we map these dev_dax or fs_dax pages to kvm for DIMM/NVDIMM backend). Together with the type MEMORY_DEVICE_FS_DAX, we can use is_dax_page() to differentiate the pages is DAX device memory or not.

---
 include/linux/mm.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)
include/linux/mm.h +12 -0
index 6e19265..9f0f690 100644
@@ -856,6 +856,13 @@ static inline bool is_device_public_page(const struct page *page)
 		page->pgmap->type == MEMORY_DEVICE_PUBLIC;
 }
 
+static inline bool is_dax_page(const struct page *page)
+{
+	return is_zone_device_page(page) &&
+		(page->pgmap->type == MEMORY_DEVICE_FS_DAX ||
+		page->pgmap->type == MEMORY_DEVICE_DEV_DAX);
+}
+
 #else /* CONFIG_DEV_PAGEMAP_OPS */
 static inline void dev_pagemap_get_ops(void)
 {
@@ -879,6 +886,11 @@ static inline bool is_device_public_page(const struct page *page)
 {
 	return false;
 }
+
+static inline bool is_dax_page(const struct page *page)
+{
+	return false;
+}
 #endif /* CONFIG_DEV_PAGEMAP_OPS */
 
 static inline void get_page(struct page *page)
Signature · 1 line
2.7.4
author
#10 lore raw
In reply to Zhang Yi

Ping for further review, comments.

Thanks All

Regards
Yi.

Quoted 32 lines · Zhang Yi

For device specific memory space, when we move these area of pfn to memory zone, we will set the page reserved flag at that time, some of these reserved for device mmio, and some of these are not, such as NVDIMM pmem.

Now, we map these dev_dax or fs_dax pages to kvm for DIMM/NVDIMM backend, since these pages are reserved. the check of kvm_is_reserved_pfn() misconceives those pages as MMIO. Therefor, we introduce 2 page map types, MEMORY_DEVICE_FS_DAX/MEMORY_DEVICE_DEV_DAX, to indentify these pages are from NVDIMM pmem. and let kvm treat these as normal pages.

Without this patch, Many operations will be missed due to this mistreatment to pmem pages. For example, a page may not have chance to be unpinned for KVM guest(in kvm_release_pfn_clean); not able to be marked as dirty/accessed(in kvm_set_pfn_dirty/accessed) etc.

V1:
https://lkml.org/lkml/2018/7/4/91

V2:
*Add documentation for MEMORY_DEVICE_DEV_DAX memory type in comment block *Add is_dax_page() in mm.h to differentiate the pages is from DAX device. *Remove the function kvm_is_nd_pfn().

Zhang Yi (4):
kvm: remove redundant reserved page check
mm: introduce memory type MEMORY_DEVICE_DEV_DAX
mm: add a function to differentiate the pages is from DAX device
memory
kvm: add a check if pfn is from NVDIMM pmem.

Quoted 6 lines
 drivers/dax/pmem.c       |  1 +
 include/linux/memremap.h |  9 +++++++++
 include/linux/mm.h       | 12 ++++++++++++
 virt/kvm/kvm_main.c      | 16 ++++++++--------
 4 files changed, 30 insertions(+), 8 deletions(-)

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

author
#11 lore raw
In reply to Zhang Yi

Added Jiang,Dave,

Ping for further review, comments.

Thanks All

Regards
Yi.

Quoted 32 lines · Zhang Yi

For device specific memory space, when we move these area of pfn to memory zone, we will set the page reserved flag at that time, some of these reserved for device mmio, and some of these are not, such as NVDIMM pmem.

Now, we map these dev_dax or fs_dax pages to kvm for DIMM/NVDIMM backend, since these pages are reserved. the check of kvm_is_reserved_pfn() misconceives those pages as MMIO. Therefor, we introduce 2 page map types, MEMORY_DEVICE_FS_DAX/MEMORY_DEVICE_DEV_DAX, to indentify these pages are from NVDIMM pmem. and let kvm treat these as normal pages.

Without this patch, Many operations will be missed due to this mistreatment to pmem pages. For example, a page may not have chance to be unpinned for KVM guest(in kvm_release_pfn_clean); not able to be marked as dirty/accessed(in kvm_set_pfn_dirty/accessed) etc.

V1:
https://lkml.org/lkml/2018/7/4/91

V2:
*Add documentation for MEMORY_DEVICE_DEV_DAX memory type in comment block *Add is_dax_page() in mm.h to differentiate the pages is from DAX device. *Remove the function kvm_is_nd_pfn().

Zhang Yi (4):
kvm: remove redundant reserved page check
mm: introduce memory type MEMORY_DEVICE_DEV_DAX
mm: add a function to differentiate the pages is from DAX device
memory
kvm: add a check if pfn is from NVDIMM pmem.

Quoted 6 lines
 drivers/dax/pmem.c       |  1 +
 include/linux/memremap.h |  9 +++++++++
 include/linux/mm.h       | 12 ++++++++++++
 virt/kvm/kvm_main.c      | 16 ++++++++--------
 4 files changed, 30 insertions(+), 8 deletions(-)

_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm

maintainer
#12 lore raw
Quoted 3 lines · Zhang,Yi

Added Jiang,Dave,

Ping for further review, comments.

I need an Acked-by from the MM people to merge this. Jan, Dan?

Paolo

Quoted 48 lines

Thanks All

Regards
Yi.

Quoted 38 lines · Zhang Yi

For device specific memory space, when we move these area of pfn to memory zone, we will set the page reserved flag at that time, some of these reserved for device mmio, and some of these are not, such as NVDIMM pmem.

Now, we map these dev_dax or fs_dax pages to kvm for DIMM/NVDIMM backend, since these pages are reserved. the check of kvm_is_reserved_pfn() misconceives those pages as MMIO. Therefor, we introduce 2 page map types, MEMORY_DEVICE_FS_DAX/MEMORY_DEVICE_DEV_DAX, to indentify these pages are from NVDIMM pmem. and let kvm treat these as normal pages.

Without this patch, Many operations will be missed due to this mistreatment to pmem pages. For example, a page may not have chance to be unpinned for KVM guest(in kvm_release_pfn_clean); not able to be marked as dirty/accessed(in kvm_set_pfn_dirty/accessed) etc.

V1:
https://lkml.org/lkml/2018/7/4/91

V2:
*Add documentation for MEMORY_DEVICE_DEV_DAX memory type in comment block *Add is_dax_page() in mm.h to differentiate the pages is from DAX device. *Remove the function kvm_is_nd_pfn().

Zhang Yi (4):
kvm: remove redundant reserved page check
mm: introduce memory type MEMORY_DEVICE_DEV_DAX
mm: add a function to differentiate the pages is from DAX device
memory
kvm: add a check if pfn is from NVDIMM pmem.

 drivers/dax/pmem.c       |  1 +
 include/linux/memremap.h |  9 +++++++++
 include/linux/mm.h       | 12 ++++++++++++
 virt/kvm/kvm_main.c      | 16 ++++++++--------
 4 files changed, 30 insertions(+), 8 deletions(-)
author
#13 lore raw

Thanks Paolo, let's wait Jan&Dan 's comments.

Thank you, Paolo.

Regards
Yi

Quoted 54 lines · Paolo Bonzini
Quoted 3 lines · Zhang,Yi

Added Jiang,Dave,

Ping for further review, comments.

I need an Acked-by from the MM people to merge this. Jan, Dan?

Paolo

Quoted 46 lines

Thanks All

Regards
Yi.

Quoted 38 lines · Zhang Yi

For device specific memory space, when we move these area of pfn to memory zone, we will set the page reserved flag at that time, some of these reserved for device mmio, and some of these are not, such as NVDIMM pmem.

Now, we map these dev_dax or fs_dax pages to kvm for DIMM/NVDIMM backend, since these pages are reserved. the check of kvm_is_reserved_pfn() misconceives those pages as MMIO. Therefor, we introduce 2 page map types, MEMORY_DEVICE_FS_DAX/MEMORY_DEVICE_DEV_DAX, to indentify these pages are from NVDIMM pmem. and let kvm treat these as normal pages.

Without this patch, Many operations will be missed due to this mistreatment to pmem pages. For example, a page may not have chance to be unpinned for KVM guest(in kvm_release_pfn_clean); not able to be marked as dirty/accessed(in kvm_set_pfn_dirty/accessed) etc.

V1:
https://lkml.org/lkml/2018/7/4/91

V2:
*Add documentation for MEMORY_DEVICE_DEV_DAX memory type in comment block *Add is_dax_page() in mm.h to differentiate the pages is from DAX device. *Remove the function kvm_is_nd_pfn().

Zhang Yi (4):
kvm: remove redundant reserved page check
mm: introduce memory type MEMORY_DEVICE_DEV_DAX
mm: add a function to differentiate the pages is from DAX device
memory
kvm: add a check if pfn is from NVDIMM pmem.

 drivers/dax/pmem.c       |  1 +
 include/linux/memremap.h |  9 +++++++++
 include/linux/mm.h       | 12 ++++++++++++
 virt/kvm/kvm_main.c      | 16 ++++++++--------
 4 files changed, 30 insertions(+), 8 deletions(-)