All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] KVM: MMU: fix kvm_is_mmio_pfn()
@ 2017-10-31 11:48 Haozhong Zhang
  2017-10-31 11:48 ` [PATCH v2 1/2] x86/mm: expose lookup_memtype() Haozhong Zhang
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Haozhong Zhang @ 2017-10-31 11:48 UTC (permalink / raw)
  To: kvm, x86
  Cc: linux-kernel, Paolo Bonzini, rkrcmar, Xiao Guangrong,
	Dan Williams, ivan.d.cuevas.escareno, karthik.kumar,
	Haozhong Zhang, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	Borislav Petkov, Mikulas Patocka, Tom Lendacky

[I just copy the commit message from patch 2]

Some reserved pages, such as those from NVDIMM DAX devices, are
not for MMIO, and can be mapped with cached memory type for better
performance. However, the above check misconceives those pages as
MMIO.  Because KVM maps MMIO pages with UC memory type, the
performance of guest accesses to those pages would be harmed.
Therefore, we check the host memory type by lookup_memtype() in
addition and only treat UC/UC- pages as MMIO.

Changes in v2:
 * Switch to lookup_memtype() to get host memory type.
 * Rewrite the comment in KVM MMU patch.
 * Remove v1 patch 2, which is not necessary in v2.

Haozhong Zhang (2):
  x86/mm: expose lookup_memtype()
  KVM: MMU: consider host cache mode in MMIO page check

 arch/x86/include/asm/pat.h |  2 ++
 arch/x86/kvm/mmu.c         | 30 +++++++++++++++++++++++++++---
 arch/x86/mm/pat.c          |  3 ++-
 3 files changed, 31 insertions(+), 4 deletions(-)

-- 
2.14.1

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

* [PATCH v2 1/2] x86/mm: expose lookup_memtype()
  2017-10-31 11:48 [PATCH v2 0/2] KVM: MMU: fix kvm_is_mmio_pfn() Haozhong Zhang
@ 2017-10-31 11:48 ` Haozhong Zhang
  2017-10-31 11:48 ` [PATCH v2 2/2] KVM: MMU: consider host cache mode in MMIO page check Haozhong Zhang
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: Haozhong Zhang @ 2017-10-31 11:48 UTC (permalink / raw)
  To: kvm, x86
  Cc: linux-kernel, Paolo Bonzini, rkrcmar, Xiao Guangrong,
	Dan Williams, ivan.d.cuevas.escareno, karthik.kumar,
	Haozhong Zhang

KVM MMU will use it to get the cache mode of the host page.

Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
---
 arch/x86/include/asm/pat.h | 2 ++
 arch/x86/mm/pat.c          | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/pat.h b/arch/x86/include/asm/pat.h
index fffb2794dd89..990d955972b8 100644
--- a/arch/x86/include/asm/pat.h
+++ b/arch/x86/include/asm/pat.h
@@ -21,4 +21,6 @@ int io_reserve_memtype(resource_size_t start, resource_size_t end,
 
 void io_free_memtype(resource_size_t start, resource_size_t end);
 
+enum page_cache_mode lookup_memtype(u64 paddr);
+
 #endif /* _ASM_X86_PAT_H */
diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
index fe7d57a8fb60..e85987aaf5d5 100644
--- a/arch/x86/mm/pat.c
+++ b/arch/x86/mm/pat.c
@@ -650,7 +650,7 @@ int free_memtype(u64 start, u64 end)
  * Returns _PAGE_CACHE_MODE_WB, _PAGE_CACHE_MODE_WC, _PAGE_CACHE_MODE_UC_MINUS
  * or _PAGE_CACHE_MODE_WT.
  */
-static enum page_cache_mode lookup_memtype(u64 paddr)
+enum page_cache_mode lookup_memtype(u64 paddr)
 {
 	enum page_cache_mode rettype = _PAGE_CACHE_MODE_WB;
 	struct memtype *entry;
@@ -676,6 +676,7 @@ static enum page_cache_mode lookup_memtype(u64 paddr)
 	spin_unlock(&memtype_lock);
 	return rettype;
 }
+EXPORT_SYMBOL_GPL(lookup_memtype);
 
 /**
  * io_reserve_memtype - Request a memory type mapping for a region of memory
-- 
2.14.1

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

* [PATCH v2 2/2] KVM: MMU: consider host cache mode in MMIO page check
  2017-10-31 11:48 [PATCH v2 0/2] KVM: MMU: fix kvm_is_mmio_pfn() Haozhong Zhang
  2017-10-31 11:48 ` [PATCH v2 1/2] x86/mm: expose lookup_memtype() Haozhong Zhang
@ 2017-10-31 11:48 ` Haozhong Zhang
  2017-11-02  7:56   ` Xiao Guangrong
  2017-11-02  6:48 ` [PATCH v2 0/2] KVM: MMU: fix kvm_is_mmio_pfn() Haozhong Zhang
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Haozhong Zhang @ 2017-10-31 11:48 UTC (permalink / raw)
  To: kvm, x86
  Cc: linux-kernel, Paolo Bonzini, rkrcmar, Xiao Guangrong,
	Dan Williams, ivan.d.cuevas.escareno, karthik.kumar,
	Haozhong Zhang

Some reserved pages, such as those from NVDIMM DAX devices, are
not for MMIO, and can be mapped with cached memory type for better
performance. However, the above check misconceives those pages as
MMIO.  Because KVM maps MMIO pages with UC memory type, the
performance of guest accesses to those pages would be harmed.
Therefore, we check the host memory type by lookup_memtype() in
addition and only treat UC/UC- pages as MMIO.

Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
Reported-by: Cuevas Escareno, Ivan D <ivan.d.cuevas.escareno@intel.com>
Reported-by: Kumar, Karthik <karthik.kumar@intel.com>
---
 arch/x86/kvm/mmu.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 0b481cc9c725..206828d18857 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -2707,10 +2707,34 @@ static bool mmu_need_write_protect(struct kvm_vcpu *vcpu, gfn_t gfn,
 
 static bool kvm_is_mmio_pfn(kvm_pfn_t pfn)
 {
-	if (pfn_valid(pfn))
-		return !is_zero_pfn(pfn) && PageReserved(pfn_to_page(pfn));
+	bool is_mmio = true;
 
-	return true;
+	if (pfn_valid(pfn)) {
+		is_mmio = !is_zero_pfn(pfn) && PageReserved(pfn_to_page(pfn));
+
+		/*
+		 * Some reserved pages, such as those from NVDIMM DAX
+		 * devices, are not for MMIO, and can be mapped with
+		 * cached memory type for better performance. However,
+		 * the above check misconceives those pages as MMIO.
+		 * Because KVM maps MMIO pages with UC memory type,
+		 * the performance of guest accesses to those pages
+		 * would be harmed. Therefore, we check the host
+		 * memory type by lookup_memtype() in addition and
+		 * only treat UC/UC- pages as MMIO.
+		 *
+		 * lookup_memtype() works only when PAT is enabled, so
+		 * add pat_enabled() check here.
+		 */
+		if (is_mmio && pat_enabled()) {
+			enum page_cache_mode cm = lookup_memtype(PFN_PHYS(pfn));
+
+			is_mmio = (cm == _PAGE_CACHE_MODE_UC ||
+				   cm == _PAGE_CACHE_MODE_UC_MINUS);
+		}
+	}
+
+	return is_mmio;
 }
 
 static int set_spte(struct kvm_vcpu *vcpu, u64 *sptep,
-- 
2.14.1

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

* Re: [PATCH v2 0/2] KVM: MMU: fix kvm_is_mmio_pfn()
  2017-10-31 11:48 [PATCH v2 0/2] KVM: MMU: fix kvm_is_mmio_pfn() Haozhong Zhang
  2017-10-31 11:48 ` [PATCH v2 1/2] x86/mm: expose lookup_memtype() Haozhong Zhang
  2017-10-31 11:48 ` [PATCH v2 2/2] KVM: MMU: consider host cache mode in MMIO page check Haozhong Zhang
@ 2017-11-02  6:48 ` Haozhong Zhang
  2017-11-02 17:37 ` Konrad Rzeszutek Wilk
  2017-11-03 14:15 ` Mikulas Patocka
  4 siblings, 0 replies; 11+ messages in thread
From: Haozhong Zhang @ 2017-11-02  6:48 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: linux-kernel, rkrcmar, Xiao Guangrong, Dan Williams,
	ivan.d.cuevas.escareno, karthik.kumar, Thomas Gleixner,
	Ingo Molnar, H. Peter Anvin, Borislav Petkov, Mikulas Patocka,
	Tom Lendacky, kvm, x86

On 10/31/17 19:48 +0800, Haozhong Zhang wrote:
> [I just copy the commit message from patch 2]
> 
> Some reserved pages, such as those from NVDIMM DAX devices, are
> not for MMIO, and can be mapped with cached memory type for better
> performance. However, the above check misconceives those pages as
> MMIO.  Because KVM maps MMIO pages with UC memory type, the
> performance of guest accesses to those pages would be harmed.
> Therefore, we check the host memory type by lookup_memtype() in
> addition and only treat UC/UC- pages as MMIO.
> 
> Changes in v2:
>  * Switch to lookup_memtype() to get host memory type.
>  * Rewrite the comment in KVM MMU patch.
>  * Remove v1 patch 2, which is not necessary in v2.
> 
> Haozhong Zhang (2):
>   x86/mm: expose lookup_memtype()
>   KVM: MMU: consider host cache mode in MMIO page check
> 
>  arch/x86/include/asm/pat.h |  2 ++
>  arch/x86/kvm/mmu.c         | 30 +++++++++++++++++++++++++++---
>  arch/x86/mm/pat.c          |  3 ++-
>  3 files changed, 31 insertions(+), 4 deletions(-)
> 
> -- 
> 2.14.1
> 

Hi Paolo,

This patchset fixed a performance drop issue when using NVDIMM on KVM,
so I think it's nice to have in 4.14. Can you help to review it?

Thanks,
Haozhong

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

* Re: [PATCH v2 2/2] KVM: MMU: consider host cache mode in MMIO page check
  2017-10-31 11:48 ` [PATCH v2 2/2] KVM: MMU: consider host cache mode in MMIO page check Haozhong Zhang
@ 2017-11-02  7:56   ` Xiao Guangrong
  2017-11-02  9:20     ` Haozhong Zhang
  0 siblings, 1 reply; 11+ messages in thread
From: Xiao Guangrong @ 2017-11-02  7:56 UTC (permalink / raw)
  To: Haozhong Zhang, kvm, x86
  Cc: linux-kernel, Paolo Bonzini, rkrcmar, Dan Williams,
	ivan.d.cuevas.escareno, karthik.kumar, Ingo Molnar



On 10/31/2017 07:48 PM, Haozhong Zhang wrote:
> Some reserved pages, such as those from NVDIMM DAX devices, are
> not for MMIO, and can be mapped with cached memory type for better
> performance. However, the above check misconceives those pages as
> MMIO.  Because KVM maps MMIO pages with UC memory type, the
> performance of guest accesses to those pages would be harmed.
> Therefore, we check the host memory type by lookup_memtype() in
> addition and only treat UC/UC- pages as MMIO.
> 
> Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
> Reported-by: Cuevas Escareno, Ivan D <ivan.d.cuevas.escareno@intel.com>
> Reported-by: Kumar, Karthik <karthik.kumar@intel.com>
> ---
>   arch/x86/kvm/mmu.c | 30 +++++++++++++++++++++++++++---
>   1 file changed, 27 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
> index 0b481cc9c725..206828d18857 100644
> --- a/arch/x86/kvm/mmu.c
> +++ b/arch/x86/kvm/mmu.c
> @@ -2707,10 +2707,34 @@ static bool mmu_need_write_protect(struct kvm_vcpu *vcpu, gfn_t gfn,
>   
>   static bool kvm_is_mmio_pfn(kvm_pfn_t pfn)
>   {
> -	if (pfn_valid(pfn))
> -		return !is_zero_pfn(pfn) && PageReserved(pfn_to_page(pfn));
> +	bool is_mmio = true;
>   
> -	return true;
> +	if (pfn_valid(pfn)) {
> +		is_mmio = !is_zero_pfn(pfn) && PageReserved(pfn_to_page(pfn));
> +
> +		/*
> +		 * Some reserved pages, such as those from NVDIMM DAX
> +		 * devices, are not for MMIO, and can be mapped with
> +		 * cached memory type for better performance. However,
> +		 * the above check misconceives those pages as MMIO.
> +		 * Because KVM maps MMIO pages with UC memory type,
> +		 * the performance of guest accesses to those pages
> +		 * would be harmed. Therefore, we check the host
> +		 * memory type by lookup_memtype() in addition and
> +		 * only treat UC/UC- pages as MMIO.
> +		 *
> +		 * lookup_memtype() works only when PAT is enabled, so
> +		 * add pat_enabled() check here.
> +		 */
> +		if (is_mmio && pat_enabled()) {
> +			enum page_cache_mode cm = lookup_memtype(PFN_PHYS(pfn));
> +
> +			is_mmio = (cm == _PAGE_CACHE_MODE_UC ||
> +				   cm == _PAGE_CACHE_MODE_UC_MINUS);
> +		}
> +	}

You can move all of these detailed stuffs to pat.c and abstract them by introducing
a function, maybe named pat_pfn_is_uc(). I think this is what Ingo wants.

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

* Re: [PATCH v2 2/2] KVM: MMU: consider host cache mode in MMIO page check
  2017-11-02  7:56   ` Xiao Guangrong
@ 2017-11-02  9:20     ` Haozhong Zhang
  0 siblings, 0 replies; 11+ messages in thread
From: Haozhong Zhang @ 2017-11-02  9:20 UTC (permalink / raw)
  To: Xiao Guangrong
  Cc: kvm, x86, linux-kernel, Paolo Bonzini, rkrcmar, Dan Williams,
	ivan.d.cuevas.escareno, karthik.kumar, Ingo Molnar

On 11/02/17 15:56 +0800, Xiao Guangrong wrote:
> 
> 
> On 10/31/2017 07:48 PM, Haozhong Zhang wrote:
> > Some reserved pages, such as those from NVDIMM DAX devices, are
> > not for MMIO, and can be mapped with cached memory type for better
> > performance. However, the above check misconceives those pages as
> > MMIO.  Because KVM maps MMIO pages with UC memory type, the
> > performance of guest accesses to those pages would be harmed.
> > Therefore, we check the host memory type by lookup_memtype() in
> > addition and only treat UC/UC- pages as MMIO.
> > 
> > Signed-off-by: Haozhong Zhang <haozhong.zhang@intel.com>
> > Reported-by: Cuevas Escareno, Ivan D <ivan.d.cuevas.escareno@intel.com>
> > Reported-by: Kumar, Karthik <karthik.kumar@intel.com>
> > ---
> >   arch/x86/kvm/mmu.c | 30 +++++++++++++++++++++++++++---
> >   1 file changed, 27 insertions(+), 3 deletions(-)
> > 
> > diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
> > index 0b481cc9c725..206828d18857 100644
> > --- a/arch/x86/kvm/mmu.c
> > +++ b/arch/x86/kvm/mmu.c
> > @@ -2707,10 +2707,34 @@ static bool mmu_need_write_protect(struct kvm_vcpu *vcpu, gfn_t gfn,
> >   static bool kvm_is_mmio_pfn(kvm_pfn_t pfn)
> >   {
> > -	if (pfn_valid(pfn))
> > -		return !is_zero_pfn(pfn) && PageReserved(pfn_to_page(pfn));
> > +	bool is_mmio = true;
> > -	return true;
> > +	if (pfn_valid(pfn)) {
> > +		is_mmio = !is_zero_pfn(pfn) && PageReserved(pfn_to_page(pfn));
> > +
> > +		/*
> > +		 * Some reserved pages, such as those from NVDIMM DAX
> > +		 * devices, are not for MMIO, and can be mapped with
> > +		 * cached memory type for better performance. However,
> > +		 * the above check misconceives those pages as MMIO.
> > +		 * Because KVM maps MMIO pages with UC memory type,
> > +		 * the performance of guest accesses to those pages
> > +		 * would be harmed. Therefore, we check the host
> > +		 * memory type by lookup_memtype() in addition and
> > +		 * only treat UC/UC- pages as MMIO.
> > +		 *
> > +		 * lookup_memtype() works only when PAT is enabled, so
> > +		 * add pat_enabled() check here.
> > +		 */
> > +		if (is_mmio && pat_enabled()) {
> > +			enum page_cache_mode cm = lookup_memtype(PFN_PHYS(pfn));
> > +
> > +			is_mmio = (cm == _PAGE_CACHE_MODE_UC ||
> > +				   cm == _PAGE_CACHE_MODE_UC_MINUS);
> > +		}
> > +	}
> 
> You can move all of these detailed stuffs to pat.c and abstract them by introducing
> a function, maybe named pat_pfn_is_uc(). I think this is what Ingo wants.
> 

OK, I'll move the cache mode check to a function in pat.c.

Let me wait for Paolo and others' comments. If no additional comments,
I'll send another version ASAP.

Thanks,
Haozhong

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

* Re: [PATCH v2 0/2] KVM: MMU: fix kvm_is_mmio_pfn()
  2017-10-31 11:48 [PATCH v2 0/2] KVM: MMU: fix kvm_is_mmio_pfn() Haozhong Zhang
                   ` (2 preceding siblings ...)
  2017-11-02  6:48 ` [PATCH v2 0/2] KVM: MMU: fix kvm_is_mmio_pfn() Haozhong Zhang
@ 2017-11-02 17:37 ` Konrad Rzeszutek Wilk
  2017-11-03  0:26   ` Haozhong Zhang
  2017-11-03 14:15 ` Mikulas Patocka
  4 siblings, 1 reply; 11+ messages in thread
From: Konrad Rzeszutek Wilk @ 2017-11-02 17:37 UTC (permalink / raw)
  To: Haozhong Zhang, Olif Chapman
  Cc: kvm, x86, linux-kernel, Paolo Bonzini, rkrcmar, Xiao Guangrong,
	Dan Williams, ivan.d.cuevas.escareno, karthik.kumar,
	Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Borislav Petkov,
	Mikulas Patocka, Tom Lendacky

On Tue, Oct 31, 2017 at 07:48:38PM +0800, Haozhong Zhang wrote:
> [I just copy the commit message from patch 2]
> 
> Some reserved pages, such as those from NVDIMM DAX devices, are
> not for MMIO, and can be mapped with cached memory type for better
> performance. However, the above check misconceives those pages as
> MMIO.  Because KVM maps MMIO pages with UC memory type, the
> performance of guest accesses to those pages would be harmed.
> Therefore, we check the host memory type by lookup_memtype() in
> addition and only treat UC/UC- pages as MMIO.

Is there a specific workload you used to detect this?

Thanks!
> 
> Changes in v2:
>  * Switch to lookup_memtype() to get host memory type.
>  * Rewrite the comment in KVM MMU patch.
>  * Remove v1 patch 2, which is not necessary in v2.
> 
> Haozhong Zhang (2):
>   x86/mm: expose lookup_memtype()
>   KVM: MMU: consider host cache mode in MMIO page check
> 
>  arch/x86/include/asm/pat.h |  2 ++
>  arch/x86/kvm/mmu.c         | 30 +++++++++++++++++++++++++++---
>  arch/x86/mm/pat.c          |  3 ++-
>  3 files changed, 31 insertions(+), 4 deletions(-)
> 
> -- 
> 2.14.1
> 

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

* Re: [PATCH v2 0/2] KVM: MMU: fix kvm_is_mmio_pfn()
  2017-11-02 17:37 ` Konrad Rzeszutek Wilk
@ 2017-11-03  0:26   ` Haozhong Zhang
  0 siblings, 0 replies; 11+ messages in thread
From: Haozhong Zhang @ 2017-11-03  0:26 UTC (permalink / raw)
  To: Konrad Rzeszutek Wilk
  Cc: Olif Chapman, kvm, x86, linux-kernel, Paolo Bonzini, rkrcmar,
	Xiao Guangrong, Dan Williams, ivan.d.cuevas.escareno,
	karthik.kumar, Thomas Gleixner, Ingo Molnar, H. Peter Anvin,
	Borislav Petkov, Mikulas Patocka, Tom Lendacky

On 11/02/17 13:37 -0400, Konrad Rzeszutek Wilk wrote:
> On Tue, Oct 31, 2017 at 07:48:38PM +0800, Haozhong Zhang wrote:
> > [I just copy the commit message from patch 2]
> > 
> > Some reserved pages, such as those from NVDIMM DAX devices, are
> > not for MMIO, and can be mapped with cached memory type for better
> > performance. However, the above check misconceives those pages as
> > MMIO.  Because KVM maps MMIO pages with UC memory type, the
> > performance of guest accesses to those pages would be harmed.
> > Therefore, we check the host memory type by lookup_memtype() in
> > addition and only treat UC/UC- pages as MMIO.
> 
> Is there a specific workload you used to detect this?
>

Creating files on NVDIMM in VM is must slower than the same operation
on the baremetal. As the wrong EPT memory type (UC vs. WB) is used,
every guest access to NVDIMM would be slower than baremetal.

Haozhong

> Thanks!
> > 
> > Changes in v2:
> >  * Switch to lookup_memtype() to get host memory type.
> >  * Rewrite the comment in KVM MMU patch.
> >  * Remove v1 patch 2, which is not necessary in v2.
> > 
> > Haozhong Zhang (2):
> >   x86/mm: expose lookup_memtype()
> >   KVM: MMU: consider host cache mode in MMIO page check
> > 
> >  arch/x86/include/asm/pat.h |  2 ++
> >  arch/x86/kvm/mmu.c         | 30 +++++++++++++++++++++++++++---
> >  arch/x86/mm/pat.c          |  3 ++-
> >  3 files changed, 31 insertions(+), 4 deletions(-)
> > 
> > -- 
> > 2.14.1
> > 

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

* Re: [PATCH v2 0/2] KVM: MMU: fix kvm_is_mmio_pfn()
  2017-10-31 11:48 [PATCH v2 0/2] KVM: MMU: fix kvm_is_mmio_pfn() Haozhong Zhang
                   ` (3 preceding siblings ...)
  2017-11-02 17:37 ` Konrad Rzeszutek Wilk
@ 2017-11-03 14:15 ` Mikulas Patocka
  2017-11-08  1:30   ` Haozhong Zhang
  4 siblings, 1 reply; 11+ messages in thread
From: Mikulas Patocka @ 2017-11-03 14:15 UTC (permalink / raw)
  To: Haozhong Zhang
  Cc: kvm, x86, linux-kernel, Paolo Bonzini, rkrcmar, Xiao Guangrong,
	Dan Williams, ivan.d.cuevas.escareno, karthik.kumar,
	Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Borislav Petkov,
	Tom Lendacky



On Tue, 31 Oct 2017, Haozhong Zhang wrote:

> [I just copy the commit message from patch 2]
> 
> Some reserved pages, such as those from NVDIMM DAX devices, are
> not for MMIO, and can be mapped with cached memory type for better
> performance. However, the above check misconceives those pages as

Note that cached memory type on persistent memory has horrible 
performance. The clwb instruction on Broadwell is very slow - when you 
write to persistent memory and use clwb to flush cache, the performance is 
about 350MB/s.

Using write-combining memory type for persistent memory is much faster, it 
can sustain performance of one 8-byte write per tick.

Mikulas

> MMIO.  Because KVM maps MMIO pages with UC memory type, the
> performance of guest accesses to those pages would be harmed.
> Therefore, we check the host memory type by lookup_memtype() in
> addition and only treat UC/UC- pages as MMIO.
> 
> Changes in v2:
>  * Switch to lookup_memtype() to get host memory type.
>  * Rewrite the comment in KVM MMU patch.
>  * Remove v1 patch 2, which is not necessary in v2.
> 
> Haozhong Zhang (2):
>   x86/mm: expose lookup_memtype()
>   KVM: MMU: consider host cache mode in MMIO page check
> 
>  arch/x86/include/asm/pat.h |  2 ++
>  arch/x86/kvm/mmu.c         | 30 +++++++++++++++++++++++++++---
>  arch/x86/mm/pat.c          |  3 ++-
>  3 files changed, 31 insertions(+), 4 deletions(-)
> 
> -- 
> 2.14.1
> 

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

* Re: [PATCH v2 0/2] KVM: MMU: fix kvm_is_mmio_pfn()
  2017-11-03 14:15 ` Mikulas Patocka
@ 2017-11-08  1:30   ` Haozhong Zhang
  2017-11-08 12:24     ` Mikulas Patocka
  0 siblings, 1 reply; 11+ messages in thread
From: Haozhong Zhang @ 2017-11-08  1:30 UTC (permalink / raw)
  To: Mikulas Patocka
  Cc: kvm, x86, linux-kernel, Paolo Bonzini, rkrcmar, Xiao Guangrong,
	Dan Williams, ivan.d.cuevas.escareno, karthik.kumar,
	Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Borislav Petkov,
	Tom Lendacky

On 11/03/17 10:15 -0400, Mikulas Patocka wrote:
> 
> 
> On Tue, 31 Oct 2017, Haozhong Zhang wrote:
> 
> > [I just copy the commit message from patch 2]
> > 
> > Some reserved pages, such as those from NVDIMM DAX devices, are
> > not for MMIO, and can be mapped with cached memory type for better
> > performance. However, the above check misconceives those pages as
> 
> Note that cached memory type on persistent memory has horrible 
> performance. The clwb instruction on Broadwell is very slow - when you 
> write to persistent memory and use clwb to flush cache, the performance is 
> about 350MB/s.

Wasn't clwb first introduced on Skylake?

Haozhong

> 
> Using write-combining memory type for persistent memory is much faster, it 
> can sustain performance of one 8-byte write per tick.
> 
> Mikulas
> 
> > MMIO.  Because KVM maps MMIO pages with UC memory type, the
> > performance of guest accesses to those pages would be harmed.
> > Therefore, we check the host memory type by lookup_memtype() in
> > addition and only treat UC/UC- pages as MMIO.
> > 
> > Changes in v2:
> >  * Switch to lookup_memtype() to get host memory type.
> >  * Rewrite the comment in KVM MMU patch.
> >  * Remove v1 patch 2, which is not necessary in v2.
> > 
> > Haozhong Zhang (2):
> >   x86/mm: expose lookup_memtype()
> >   KVM: MMU: consider host cache mode in MMIO page check
> > 
> >  arch/x86/include/asm/pat.h |  2 ++
> >  arch/x86/kvm/mmu.c         | 30 +++++++++++++++++++++++++++---
> >  arch/x86/mm/pat.c          |  3 ++-
> >  3 files changed, 31 insertions(+), 4 deletions(-)
> > 
> > -- 
> > 2.14.1
> > 

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

* Re: [PATCH v2 0/2] KVM: MMU: fix kvm_is_mmio_pfn()
  2017-11-08  1:30   ` Haozhong Zhang
@ 2017-11-08 12:24     ` Mikulas Patocka
  0 siblings, 0 replies; 11+ messages in thread
From: Mikulas Patocka @ 2017-11-08 12:24 UTC (permalink / raw)
  To: Haozhong Zhang
  Cc: kvm, x86, linux-kernel, Paolo Bonzini, rkrcmar, Xiao Guangrong,
	Dan Williams, ivan.d.cuevas.escareno, karthik.kumar,
	Thomas Gleixner, Ingo Molnar, H. Peter Anvin, Borislav Petkov,
	Tom Lendacky



On Wed, 8 Nov 2017, Haozhong Zhang wrote:

> On 11/03/17 10:15 -0400, Mikulas Patocka wrote:
> > 
> > 
> > On Tue, 31 Oct 2017, Haozhong Zhang wrote:
> > 
> > > [I just copy the commit message from patch 2]
> > > 
> > > Some reserved pages, such as those from NVDIMM DAX devices, are
> > > not for MMIO, and can be mapped with cached memory type for better
> > > performance. However, the above check misconceives those pages as
> > 
> > Note that cached memory type on persistent memory has horrible 
> > performance. The clwb instruction on Broadwell is very slow - when you 
> > write to persistent memory and use clwb to flush cache, the performance is 
> > about 350MB/s.
> 
> Wasn't clwb first introduced on Skylake?
> 
> Haozhong

You're right - the clwb() function uses clflushopt on Broadwell - that's 
what I meant is slow.

Mikulas

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

end of thread, other threads:[~2017-11-08 12:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-31 11:48 [PATCH v2 0/2] KVM: MMU: fix kvm_is_mmio_pfn() Haozhong Zhang
2017-10-31 11:48 ` [PATCH v2 1/2] x86/mm: expose lookup_memtype() Haozhong Zhang
2017-10-31 11:48 ` [PATCH v2 2/2] KVM: MMU: consider host cache mode in MMIO page check Haozhong Zhang
2017-11-02  7:56   ` Xiao Guangrong
2017-11-02  9:20     ` Haozhong Zhang
2017-11-02  6:48 ` [PATCH v2 0/2] KVM: MMU: fix kvm_is_mmio_pfn() Haozhong Zhang
2017-11-02 17:37 ` Konrad Rzeszutek Wilk
2017-11-03  0:26   ` Haozhong Zhang
2017-11-03 14:15 ` Mikulas Patocka
2017-11-08  1:30   ` Haozhong Zhang
2017-11-08 12:24     ` Mikulas Patocka

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.