diff mbox

[3/3] KVM: move postcommit flush to x86, as mmio sptes are x86 specific

Message ID 20120824185634.625676530@amt.cnet (mailing list archive)
State New, archived
Headers show

Commit Message

Marcelo Tosatti Aug. 24, 2012, 6:54 p.m. UTC
Other arches do not need this.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>



--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Xiao Guangrong Aug. 27, 2012, 8:04 a.m. UTC | #1
On 08/25/2012 02:54 AM, Marcelo Tosatti wrote:
> Other arches do not need this.
> 
> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
> 
> Index: kvm/arch/x86/kvm/x86.c
> ===================================================================
> --- kvm.orig/arch/x86/kvm/x86.c
> +++ kvm/arch/x86/kvm/x86.c
> @@ -6455,6 +6455,14 @@ void kvm_arch_commit_memory_region(struc
>  		kvm_mmu_change_mmu_pages(kvm, nr_mmu_pages);
>  	kvm_mmu_slot_remove_write_access(kvm, mem->slot);
>  	spin_unlock(&kvm->mmu_lock);
> +	/*
> +	 * If the new memory slot is created, we need to clear all
> +	 * mmio sptes.
> +	 */
> +	if (old.npages == 0 && npages) {
> +		kvm_mmu_zap_all(kvm);
> +		kvm_reload_remote_mmus(kvm);
> +	}

Can not use kvm_arch_flush_shadow_all()?

Others are fine to me.

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Takuya Yoshikawa Aug. 27, 2012, 2:41 p.m. UTC | #2
On Fri, 24 Aug 2012 15:54:59 -0300
Marcelo Tosatti <mtosatti@redhat.com> wrote:

> Other arches do not need this.
> 
> Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
> 
> Index: kvm/arch/x86/kvm/x86.c
> ===================================================================
> --- kvm.orig/arch/x86/kvm/x86.c
> +++ kvm/arch/x86/kvm/x86.c
> @@ -6455,6 +6455,14 @@ void kvm_arch_commit_memory_region(struc
>  		kvm_mmu_change_mmu_pages(kvm, nr_mmu_pages);
>  	kvm_mmu_slot_remove_write_access(kvm, mem->slot);
>  	spin_unlock(&kvm->mmu_lock);
> +	/*
> +	 * If the new memory slot is created, we need to clear all
> +	 * mmio sptes.
> +	 */
> +	if (old.npages == 0 && npages) {
> +		kvm_mmu_zap_all(kvm);
> +		kvm_reload_remote_mmus(kvm);
> +	}
>  }

Any explanation why (old.base_gfn != new.base_gfn) case can be
omitted?

Takuya

>  
>  void kvm_arch_flush_shadow_all(struct kvm *kvm)
> Index: kvm/virt/kvm/kvm_main.c
> ===================================================================
> --- kvm.orig/virt/kvm/kvm_main.c
> +++ kvm/virt/kvm/kvm_main.c
> @@ -849,13 +849,6 @@ int __kvm_set_memory_region(struct kvm *
>  
>  	kvm_arch_commit_memory_region(kvm, mem, old, user_alloc);
>  
> -	/*
> -	 * If the new memory slot is created, we need to clear all
> -	 * mmio sptes.
> -	 */
> -	if (npages && old.base_gfn != mem->guest_phys_addr >> PAGE_SHIFT)
> -		kvm_arch_flush_shadow_all(kvm);
> -
>  	kvm_free_physmem_slot(&old, &new);
>  	kfree(old_memslots);
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Marcelo Tosatti Aug. 27, 2012, 7:06 p.m. UTC | #3
On Mon, Aug 27, 2012 at 11:41:08PM +0900, Takuya Yoshikawa wrote:
> On Fri, 24 Aug 2012 15:54:59 -0300
> Marcelo Tosatti <mtosatti@redhat.com> wrote:
> 
> > Other arches do not need this.
> > 
> > Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
> > 
> > Index: kvm/arch/x86/kvm/x86.c
> > ===================================================================
> > --- kvm.orig/arch/x86/kvm/x86.c
> > +++ kvm/arch/x86/kvm/x86.c
> > @@ -6455,6 +6455,14 @@ void kvm_arch_commit_memory_region(struc
> >  		kvm_mmu_change_mmu_pages(kvm, nr_mmu_pages);
> >  	kvm_mmu_slot_remove_write_access(kvm, mem->slot);
> >  	spin_unlock(&kvm->mmu_lock);
> > +	/*
> > +	 * If the new memory slot is created, we need to clear all
> > +	 * mmio sptes.
> > +	 */
> > +	if (old.npages == 0 && npages) {
> > +		kvm_mmu_zap_all(kvm);
> > +		kvm_reload_remote_mmus(kvm);
> > +	}
> >  }
> 
> Any explanation why (old.base_gfn != new.base_gfn) case can be
> omitted?

(old.base_gfn != new.base_gfn) check covers the cases

1. old.base_gfn = 0, new.base_gfn = !0 (slot creation)

and

x != 0, y != 0, x != y.
2. old.base_gfn = x, new.base_gfn = y (gpa base change)

Patch 2 covers case 2, so its only necessary to cover case
1 here.

Makes sense?

> Takuya
> 
> >  
> >  void kvm_arch_flush_shadow_all(struct kvm *kvm)
> > Index: kvm/virt/kvm/kvm_main.c
> > ===================================================================
> > --- kvm.orig/virt/kvm/kvm_main.c
> > +++ kvm/virt/kvm/kvm_main.c
> > @@ -849,13 +849,6 @@ int __kvm_set_memory_region(struct kvm *
> >  
> >  	kvm_arch_commit_memory_region(kvm, mem, old, user_alloc);
> >  
> > -	/*
> > -	 * If the new memory slot is created, we need to clear all
> > -	 * mmio sptes.
> > -	 */
> > -	if (npages && old.base_gfn != mem->guest_phys_addr >> PAGE_SHIFT)
> > -		kvm_arch_flush_shadow_all(kvm);
> > -
> >  	kvm_free_physmem_slot(&old, &new);
> >  	kfree(old_memslots);
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Takuya Yoshikawa Aug. 28, 2012, 12:30 a.m. UTC | #4
On Mon, 27 Aug 2012 16:06:01 -0300
Marcelo Tosatti <mtosatti@redhat.com> wrote:

> > Any explanation why (old.base_gfn != new.base_gfn) case can be
> > omitted?
> 
> (old.base_gfn != new.base_gfn) check covers the cases
> 
> 1. old.base_gfn = 0, new.base_gfn = !0 (slot creation)
> 
> and
> 
> x != 0, y != 0, x != y.
> 2. old.base_gfn = x, new.base_gfn = y (gpa base change)
> 
> Patch 2 covers case 2, so its only necessary to cover case
> 1 here.
> 
> Makes sense?

Yes.

But didn't you change the flush in the if block modified by patch 2
to kvm_arch_flush_shadow_memslot()?

Although current implementation flushes everything, this may trigger
problem when we change it.

	Takuya
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Marcelo Tosatti Aug. 28, 2012, 8:41 p.m. UTC | #5
On Tue, Aug 28, 2012 at 09:30:24AM +0900, Takuya Yoshikawa wrote:
> On Mon, 27 Aug 2012 16:06:01 -0300
> Marcelo Tosatti <mtosatti@redhat.com> wrote:
> 
> > > Any explanation why (old.base_gfn != new.base_gfn) case can be
> > > omitted?
> > 
> > (old.base_gfn != new.base_gfn) check covers the cases
> > 
> > 1. old.base_gfn = 0, new.base_gfn = !0 (slot creation)
> > 
> > and
> > 
> > x != 0, y != 0, x != y.
> > 2. old.base_gfn = x, new.base_gfn = y (gpa base change)
> > 
> > Patch 2 covers case 2, so its only necessary to cover case
> > 1 here.
> > 
> > Makes sense?
> 
> Yes.
> 
> But didn't you change the flush in the if block modified by patch 2
> to kvm_arch_flush_shadow_memslot()?
> 
> Although current implementation flushes everything, this may trigger
> problem when we change it.
> 
> 	Takuya

Yay, thanks.

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Marcelo Tosatti Aug. 28, 2012, 8:45 p.m. UTC | #6
On Mon, Aug 27, 2012 at 04:04:44PM +0800, Xiao Guangrong wrote:
> On 08/25/2012 02:54 AM, Marcelo Tosatti wrote:
> > Other arches do not need this.
> > 
> > Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
> > 
> > Index: kvm/arch/x86/kvm/x86.c
> > ===================================================================
> > --- kvm.orig/arch/x86/kvm/x86.c
> > +++ kvm/arch/x86/kvm/x86.c
> > @@ -6455,6 +6455,14 @@ void kvm_arch_commit_memory_region(struc
> >  		kvm_mmu_change_mmu_pages(kvm, nr_mmu_pages);
> >  	kvm_mmu_slot_remove_write_access(kvm, mem->slot);
> >  	spin_unlock(&kvm->mmu_lock);
> > +	/*
> > +	 * If the new memory slot is created, we need to clear all
> > +	 * mmio sptes.
> > +	 */
> > +	if (old.npages == 0 && npages) {
> > +		kvm_mmu_zap_all(kvm);
> > +		kvm_reload_remote_mmus(kvm);
> > +	}
> 
> Can not use kvm_arch_flush_shadow_all()?

Better reduce it to necessary cases only.

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

Index: kvm/arch/x86/kvm/x86.c
===================================================================
--- kvm.orig/arch/x86/kvm/x86.c
+++ kvm/arch/x86/kvm/x86.c
@@ -6455,6 +6455,14 @@  void kvm_arch_commit_memory_region(struc
 		kvm_mmu_change_mmu_pages(kvm, nr_mmu_pages);
 	kvm_mmu_slot_remove_write_access(kvm, mem->slot);
 	spin_unlock(&kvm->mmu_lock);
+	/*
+	 * If the new memory slot is created, we need to clear all
+	 * mmio sptes.
+	 */
+	if (old.npages == 0 && npages) {
+		kvm_mmu_zap_all(kvm);
+		kvm_reload_remote_mmus(kvm);
+	}
 }
 
 void kvm_arch_flush_shadow_all(struct kvm *kvm)
Index: kvm/virt/kvm/kvm_main.c
===================================================================
--- kvm.orig/virt/kvm/kvm_main.c
+++ kvm/virt/kvm/kvm_main.c
@@ -849,13 +849,6 @@  int __kvm_set_memory_region(struct kvm *
 
 	kvm_arch_commit_memory_region(kvm, mem, old, user_alloc);
 
-	/*
-	 * If the new memory slot is created, we need to clear all
-	 * mmio sptes.
-	 */
-	if (npages && old.base_gfn != mem->guest_phys_addr >> PAGE_SHIFT)
-		kvm_arch_flush_shadow_all(kvm);
-
 	kvm_free_physmem_slot(&old, &new);
 	kfree(old_memslots);