nvdimm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH V2 0/4] Fix kvm misconceives NVDIMM pages as reserved mmio
@ 2018-07-10 17:01 Zhang Yi
  2018-07-10 17:01 ` [PATCH V2 1/4] kvm: remove redundant reserved page check Zhang Yi
                   ` (6 more replies)
  0 siblings, 7 replies; 13+ messages in thread
From: Zhang Yi @ 2018-07-10 17:01 UTC (permalink / raw)
  To: kvm, linux-kernel, linux-nvdimm, pbonzini, dan.j.williams, jack,
	hch, yu.c.zhang
  Cc: linux-mm, yi.z.zhang, rkrcmar

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(-)

-- 
2.7.4

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH V2 1/4] kvm: remove redundant reserved page check
  2018-07-10 17:01 [PATCH V2 0/4] Fix kvm misconceives NVDIMM pages as reserved mmio Zhang Yi
@ 2018-07-10 17:01 ` Zhang Yi
  2018-07-10 17:01 ` [PATCH V2 2/4] mm: introduce memory type MEMORY_DEVICE_DEV_DAX Zhang Yi
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 13+ messages in thread
From: Zhang Yi @ 2018-07-10 17:01 UTC (permalink / raw)
  To: kvm, linux-kernel, linux-nvdimm, pbonzini, dan.j.williams, jack,
	hch, yu.c.zhang
  Cc: linux-mm, yi.z.zhang, rkrcmar

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

Signed-off-by: Zhang Yi <yi.z.zhang@linux.intel.com>
Signed-off-by: Zhang Yu <yu.c.zhang@linux.intel.com>
---
 virt/kvm/kvm_main.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index c7b2e92..afb2e6e 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -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);
 
-- 
2.7.4

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH V2 2/4] mm: introduce memory type MEMORY_DEVICE_DEV_DAX
  2018-07-10 17:01 [PATCH V2 0/4] Fix kvm misconceives NVDIMM pages as reserved mmio Zhang Yi
  2018-07-10 17:01 ` [PATCH V2 1/4] kvm: remove redundant reserved page check Zhang Yi
@ 2018-07-10 17:01 ` Zhang Yi
  2018-08-07  9:11   ` Jan Kara
  2018-07-10 17:03 ` [PATCH V2 3/4] mm: add a function to differentiate the pages is from DAX device memory Zhang Yi
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 13+ messages in thread
From: Zhang Yi @ 2018-07-10 17:01 UTC (permalink / raw)
  To: kvm, linux-kernel, linux-nvdimm, pbonzini, dan.j.williams, jack,
	hch, yu.c.zhang
  Cc: linux-mm, yi.z.zhang, rkrcmar

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.

Signed-off-by: Zhang Yi <yi.z.zhang@linux.intel.com>
Signed-off-by: Zhang Yu <yu.c.zhang@linux.intel.com>
---
 drivers/dax/pmem.c       | 1 +
 include/linux/memremap.h | 9 +++++++++
 2 files changed, 10 insertions(+)

diff --git a/drivers/dax/pmem.c b/drivers/dax/pmem.c
index fd49b24..fb3f363 100644
--- a/drivers/dax/pmem.c
+++ b/drivers/dax/pmem.c
@@ -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);
diff --git a/include/linux/memremap.h b/include/linux/memremap.h
index 5ebfff6..a36bce8 100644
--- a/include/linux/memremap.h
+++ b/include/linux/memremap.h
@@ -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,
 };
 
 /*
-- 
2.7.4

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH V2 3/4] mm: add a function to differentiate the pages is from DAX device memory
  2018-07-10 17:01 [PATCH V2 0/4] Fix kvm misconceives NVDIMM pages as reserved mmio Zhang Yi
  2018-07-10 17:01 ` [PATCH V2 1/4] kvm: remove redundant reserved page check Zhang Yi
  2018-07-10 17:01 ` [PATCH V2 2/4] mm: introduce memory type MEMORY_DEVICE_DEV_DAX Zhang Yi
@ 2018-07-10 17:03 ` Zhang Yi
  2018-08-07  9:13   ` Jan Kara
       [not found] ` <cover.1531241281.git.yi.z.zhang-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 13+ messages in thread
From: Zhang Yi @ 2018-07-10 17:03 UTC (permalink / raw)
  To: kvm, linux-kernel, linux-nvdimm, pbonzini, dan.j.williams, jack,
	hch, yu.c.zhang
  Cc: linux-mm, yi.z.zhang, rkrcmar

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.

Signed-off-by: Zhang Yi <yi.z.zhang@linux.intel.com>
Signed-off-by: Zhang Yu <yu.c.zhang@linux.intel.com>
---
 include/linux/mm.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 6e19265..9f0f690 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -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)
-- 
2.7.4

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH V2 3/4] mm: add a function to differentiate the pages is from DAX device memory
       [not found] ` <cover.1531241281.git.yi.z.zhang-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
@ 2018-07-10 17:03   ` Zhang Yi
  0 siblings, 0 replies; 13+ messages in thread
From: Zhang Yi @ 2018-07-10 17:03 UTC (permalink / raw)
  To: kvm-u79uwXL29TY76Z2rM5mHXA, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-nvdimm-hn68Rpc1hR1g9hUCZPvPmw,
	pbonzini-H+wXaHxf7aLQT0dZR+AlfA,
	dan.j.williams-ral2JQCrhuEAvxtiuMwx3w, jack-AlSwsSmVLrQ,
	hch-jcswGhMUV9g, yu.c.zhang-ral2JQCrhuEAvxtiuMwx3w
  Cc: linux-mm-Bw31MaZKKs3YtjvyW6yDsg,
	yi.z.zhang-ral2JQCrhuEAvxtiuMwx3w,
	rkrcmar-H+wXaHxf7aLQT0dZR+AlfA

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.

Signed-off-by: Zhang Yi <yi.z.zhang-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Signed-off-by: Zhang Yu <yu.c.zhang-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
 include/linux/mm.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index 6e19265..9f0f690 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -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)
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH V2 4/4] kvm: add a check if pfn is from NVDIMM pmem.
  2018-07-10 17:01 [PATCH V2 0/4] Fix kvm misconceives NVDIMM pages as reserved mmio Zhang Yi
                   ` (3 preceding siblings ...)
       [not found] ` <cover.1531241281.git.yi.z.zhang-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
@ 2018-07-10 17:04 ` Zhang Yi
  2018-07-13 14:29 ` [PATCH V2 0/4] Fix kvm misconceives NVDIMM pages as reserved mmio Zhang,Yi
  2018-07-20 14:11 ` Zhang,Yi
  6 siblings, 0 replies; 13+ messages in thread
From: Zhang Yi @ 2018-07-10 17:04 UTC (permalink / raw)
  To: kvm, linux-kernel, linux-nvdimm, pbonzini, dan.j.williams, jack,
	hch, yu.c.zhang
  Cc: linux-mm, yi.z.zhang, rkrcmar

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

Signed-off-by: Zhang Yi <yi.z.zhang@linux.intel.com>
---
 virt/kvm/kvm_main.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index afb2e6e..77e6ba8 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -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;
 }
-- 
2.7.4

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH V2 0/4] Fix kvm misconceives NVDIMM pages as reserved mmio
  2018-07-10 17:01 [PATCH V2 0/4] Fix kvm misconceives NVDIMM pages as reserved mmio Zhang Yi
                   ` (4 preceding siblings ...)
  2018-07-10 17:04 ` [PATCH V2 4/4] kvm: add a check if pfn is from NVDIMM pmem Zhang Yi
@ 2018-07-13 14:29 ` Zhang,Yi
  2018-07-20 14:11 ` Zhang,Yi
  6 siblings, 0 replies; 13+ messages in thread
From: Zhang,Yi @ 2018-07-13 14:29 UTC (permalink / raw)
  To: kvm, linux-kernel, linux-nvdimm, pbonzini, dan.j.williams, jack,
	hch, yu.c.zhang
  Cc: linux-mm, yi.z.zhang, rkrcmar

Ping for further review, comments.

Thanks All

Regards
Yi.

On 2018年07月11日 01:01, Zhang Yi wrote:
> 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(-)
>

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH V2 0/4] Fix kvm misconceives NVDIMM pages as reserved mmio
  2018-07-20 14:11 ` Zhang,Yi
@ 2018-07-20  8:32   ` Paolo Bonzini
  2018-07-20 16:24     ` Zhang,Yi
  0 siblings, 1 reply; 13+ messages in thread
From: Paolo Bonzini @ 2018-07-20  8:32 UTC (permalink / raw)
  To: Zhang,Yi, kvm, linux-kernel, linux-nvdimm, dan.j.williams, jack,
	hch, yu.c.zhang, dave.jiang
  Cc: linux-mm, rkrcmar, yi.z.zhang

On 20/07/2018 16:11, Zhang,Yi wrote:
> Added Jiang,Dave,
> 
> Ping for further review, comments.

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

Paolo

> 
> Thanks All
> 
> Regards
> Yi.
> 
> 
> On 2018年07月11日 01:01, Zhang Yi wrote:
>> 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(-)
>>
> 
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH V2 0/4] Fix kvm misconceives NVDIMM pages as reserved mmio
  2018-07-10 17:01 [PATCH V2 0/4] Fix kvm misconceives NVDIMM pages as reserved mmio Zhang Yi
                   ` (5 preceding siblings ...)
  2018-07-13 14:29 ` [PATCH V2 0/4] Fix kvm misconceives NVDIMM pages as reserved mmio Zhang,Yi
@ 2018-07-20 14:11 ` Zhang,Yi
  2018-07-20  8:32   ` Paolo Bonzini
  6 siblings, 1 reply; 13+ messages in thread
From: Zhang,Yi @ 2018-07-20 14:11 UTC (permalink / raw)
  To: kvm, linux-kernel, linux-nvdimm, pbonzini, dan.j.williams, jack,
	hch, yu.c.zhang, dave.jiang
  Cc: linux-mm, yi.z.zhang, rkrcmar

Added Jiang,Dave,

Ping for further review, comments.

Thanks All

Regards
Yi.


On 2018年07月11日 01:01, Zhang Yi wrote:
> 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(-)
>

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH V2 0/4] Fix kvm misconceives NVDIMM pages as reserved mmio
  2018-07-20  8:32   ` Paolo Bonzini
@ 2018-07-20 16:24     ` Zhang,Yi
  0 siblings, 0 replies; 13+ messages in thread
From: Zhang,Yi @ 2018-07-20 16:24 UTC (permalink / raw)
  To: Paolo Bonzini, kvm, linux-kernel, linux-nvdimm, dan.j.williams,
	jack, hch, yu.c.zhang, dave.jiang
  Cc: linux-mm, rkrcmar, yi.z.zhang

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

Thank you, Paolo.

Regards
Yi

On 2018年07月20日 16:32, Paolo Bonzini wrote:
> On 20/07/2018 16:11, Zhang,Yi wrote:
>> Added Jiang,Dave,
>>
>> Ping for further review, comments.
> I need an Acked-by from the MM people to merge this.  Jan, Dan?
>
> Paolo
>
>> Thanks All
>>
>> Regards
>> Yi.
>>
>>
>> On 2018年07月11日 01:01, Zhang Yi wrote:
>>> 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(-)
>>>
>>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH V2 2/4] mm: introduce memory type MEMORY_DEVICE_DEV_DAX
  2018-07-10 17:01 ` [PATCH V2 2/4] mm: introduce memory type MEMORY_DEVICE_DEV_DAX Zhang Yi
@ 2018-08-07  9:11   ` Jan Kara
  2018-08-08  9:22     ` Zhang,Yi
  0 siblings, 1 reply; 13+ messages in thread
From: Jan Kara @ 2018-08-07  9:11 UTC (permalink / raw)
  To: Zhang Yi
  Cc: jack, yu.c.zhang, kvm, linux-nvdimm, rkrcmar, linux-kernel,
	linux-mm, pbonzini, hch, yi.z.zhang

On Wed 11-07-18 01:01:59, Zhang Yi wrote:
> 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.
> 
> Signed-off-by: Zhang Yi <yi.z.zhang@linux.intel.com>
> Signed-off-by: Zhang Yu <yu.c.zhang@linux.intel.com>
> ---
>  drivers/dax/pmem.c       | 1 +
>  include/linux/memremap.h | 9 +++++++++
>  2 files changed, 10 insertions(+)
> 
> diff --git a/drivers/dax/pmem.c b/drivers/dax/pmem.c
> index fd49b24..fb3f363 100644
> --- a/drivers/dax/pmem.c
> +++ b/drivers/dax/pmem.c
> @@ -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);
> diff --git a/include/linux/memremap.h b/include/linux/memremap.h
> index 5ebfff6..a36bce8 100644
> --- a/include/linux/memremap.h
> +++ b/include/linux/memremap.h
> @@ -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.

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

>   */
>  enum memory_type {
>  	MEMORY_DEVICE_PRIVATE = 1,
>  	MEMORY_DEVICE_PUBLIC,
>  	MEMORY_DEVICE_FS_DAX,
> +	MEMORY_DEVICE_DEV_DAX,
>  };
>  
>  /*
> -- 
> 2.7.4
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH V2 3/4] mm: add a function to differentiate the pages is from DAX device memory
  2018-07-10 17:03 ` [PATCH V2 3/4] mm: add a function to differentiate the pages is from DAX device memory Zhang Yi
@ 2018-08-07  9:13   ` Jan Kara
  0 siblings, 0 replies; 13+ messages in thread
From: Jan Kara @ 2018-08-07  9:13 UTC (permalink / raw)
  To: Zhang Yi
  Cc: jack, yu.c.zhang, kvm, linux-nvdimm, rkrcmar, linux-kernel,
	linux-mm, pbonzini, hch, yi.z.zhang

On Wed 11-07-18 01:03:51, Zhang Yi wrote:
> 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.
> 
> Signed-off-by: Zhang Yi <yi.z.zhang@linux.intel.com>
> Signed-off-by: Zhang Yu <yu.c.zhang@linux.intel.com>

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:

Acked-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  include/linux/mm.h | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index 6e19265..9f0f690 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -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)
> -- 
> 2.7.4
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH V2 2/4] mm: introduce memory type MEMORY_DEVICE_DEV_DAX
  2018-08-07  9:11   ` Jan Kara
@ 2018-08-08  9:22     ` Zhang,Yi
  0 siblings, 0 replies; 13+ messages in thread
From: Zhang,Yi @ 2018-08-08  9:22 UTC (permalink / raw)
  To: Jan Kara
  Cc: yu.c.zhang, kvm, linux-nvdimm, rkrcmar, linux-kernel, linux-mm,
	pbonzini, hch, yi.z.zhang



On 2018年08月07日 17:11, Jan Kara wrote:
> On Wed 11-07-18 01:01:59, Zhang Yi wrote:
>> 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.
>>
>> Signed-off-by: Zhang Yi <yi.z.zhang@linux.intel.com>
>> Signed-off-by: Zhang Yu <yu.c.zhang@linux.intel.com>
>> ---
>>  drivers/dax/pmem.c       | 1 +
>>  include/linux/memremap.h | 9 +++++++++
>>  2 files changed, 10 insertions(+)
>>
>> diff --git a/drivers/dax/pmem.c b/drivers/dax/pmem.c
>> index fd49b24..fb3f363 100644
>> --- a/drivers/dax/pmem.c
>> +++ b/drivers/dax/pmem.c
>> @@ -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);
>> diff --git a/include/linux/memremap.h b/include/linux/memremap.h
>> index 5ebfff6..a36bce8 100644
>> --- a/include/linux/memremap.h
>> +++ b/include/linux/memremap.h
>> @@ -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.
> 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
Yes, agree, thanks for your kindly review. Jan.
>
>>   */
>>  enum memory_type {
>>  	MEMORY_DEVICE_PRIVATE = 1,
>>  	MEMORY_DEVICE_PUBLIC,
>>  	MEMORY_DEVICE_FS_DAX,
>> +	MEMORY_DEVICE_DEV_DAX,
>>  };
>>  
>>  /*
>> -- 
>> 2.7.4
>>

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2018-08-08  1:38 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-10 17:01 [PATCH V2 0/4] Fix kvm misconceives NVDIMM pages as reserved mmio Zhang Yi
2018-07-10 17:01 ` [PATCH V2 1/4] kvm: remove redundant reserved page check Zhang Yi
2018-07-10 17:01 ` [PATCH V2 2/4] mm: introduce memory type MEMORY_DEVICE_DEV_DAX Zhang Yi
2018-08-07  9:11   ` Jan Kara
2018-08-08  9:22     ` Zhang,Yi
2018-07-10 17:03 ` [PATCH V2 3/4] mm: add a function to differentiate the pages is from DAX device memory Zhang Yi
2018-08-07  9:13   ` Jan Kara
     [not found] ` <cover.1531241281.git.yi.z.zhang-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2018-07-10 17:03   ` Zhang Yi
2018-07-10 17:04 ` [PATCH V2 4/4] kvm: add a check if pfn is from NVDIMM pmem Zhang Yi
2018-07-13 14:29 ` [PATCH V2 0/4] Fix kvm misconceives NVDIMM pages as reserved mmio Zhang,Yi
2018-07-20 14:11 ` Zhang,Yi
2018-07-20  8:32   ` Paolo Bonzini
2018-07-20 16:24     ` Zhang,Yi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).