public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Avi Kivity <avi@qumranet.com>
Cc: kvm-devel <kvm@vger.kernel.org>
Subject: KVM: x86: move vapic page handling out of fast path
Date: Thu, 19 Jun 2008 14:43:47 -0300	[thread overview]
Message-ID: <20080619174347.GA9236@dmt.cnet> (raw)


I fail to see the point of handling the vapic page grab and ref
counting in __vcpu_run's heavyweight enter/exit path.

So move it to kvm_lapic_set_vapic_addr / kvm_free_lapic time.

Other than the obvious improvement for non-Flexpriority case, this      
kills a down_read/up_read pair in heavy exits and reduces code size.    

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


Index: kvm/arch/x86/kvm/lapic.c
===================================================================
--- kvm.orig/arch/x86/kvm/lapic.c
+++ kvm/arch/x86/kvm/lapic.c
@@ -800,6 +800,34 @@ static int apic_mmio_range(struct kvm_io
 	return ret;
 }
 
+static void vapic_get_page(struct kvm_vcpu *vcpu)
+{
+	struct kvm_lapic *apic = vcpu->arch.apic;
+	struct page *page;
+
+	if (!apic || !apic->vapic_addr)
+		return;
+
+	down_read(&vcpu->kvm->slots_lock);
+	down_read(&current->mm->mmap_sem);
+	page = gfn_to_page(vcpu->kvm, apic->vapic_addr >> PAGE_SHIFT);
+	up_read(&current->mm->mmap_sem);
+	up_read(&vcpu->kvm->slots_lock);
+
+	vcpu->arch.apic->vapic_page = page;
+}
+
+static void vapic_put_page(struct kvm_vcpu *vcpu)
+{
+	struct kvm_lapic *apic = vcpu->arch.apic;
+
+	if (!irqchip_in_kernel(vcpu->kvm) || !apic || !apic->vapic_addr)
+		return;
+
+	kvm_release_page_dirty(apic->vapic_page);
+	mark_page_dirty(vcpu->kvm, apic->vapic_addr >> PAGE_SHIFT);
+}
+
 void kvm_free_lapic(struct kvm_vcpu *vcpu)
 {
 	if (!vcpu->arch.apic)
@@ -810,6 +838,9 @@ void kvm_free_lapic(struct kvm_vcpu *vcp
 	if (vcpu->arch.apic->regs_page)
 		__free_page(vcpu->arch.apic->regs_page);
 
+	if (vcpu->arch.apic->vapic_page)
+		vapic_put_page(vcpu);
+
 	kfree(vcpu->arch.apic);
 }
 
@@ -1172,5 +1203,9 @@ void kvm_lapic_set_vapic_addr(struct kvm
 	if (!irqchip_in_kernel(vcpu->kvm))
 		return;
 
+	if (vcpu->arch.apic->vapic_page)
+		vapic_put_page(vcpu);
+
 	vcpu->arch.apic->vapic_addr = vapic_addr;
+	vapic_get_page(vcpu);
 }
Index: kvm/arch/x86/kvm/x86.c
===================================================================
--- kvm.orig/arch/x86/kvm/x86.c
+++ kvm/arch/x86/kvm/x86.c
@@ -2737,32 +2737,6 @@ static void post_kvm_run_save(struct kvm
 					 vcpu->arch.irq_summary == 0);
 }
 
-static void vapic_enter(struct kvm_vcpu *vcpu)
-{
-	struct kvm_lapic *apic = vcpu->arch.apic;
-	struct page *page;
-
-	if (!apic || !apic->vapic_addr)
-		return;
-
-	down_read(&current->mm->mmap_sem);
-	page = gfn_to_page(vcpu->kvm, apic->vapic_addr >> PAGE_SHIFT);
-	up_read(&current->mm->mmap_sem);
-
-	vcpu->arch.apic->vapic_page = page;
-}
-
-static void vapic_exit(struct kvm_vcpu *vcpu)
-{
-	struct kvm_lapic *apic = vcpu->arch.apic;
-
-	if (!apic || !apic->vapic_addr)
-		return;
-
-	kvm_release_page_dirty(apic->vapic_page);
-	mark_page_dirty(vcpu->kvm, apic->vapic_addr >> PAGE_SHIFT);
-}
-
 static int __vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
 {
 	int r;
@@ -2778,7 +2752,6 @@ static int __vcpu_run(struct kvm_vcpu *v
 	}
 
 	down_read(&vcpu->kvm->slots_lock);
-	vapic_enter(vcpu);
 
 preempted:
 	if (vcpu->guest_debug.enabled)
@@ -2916,10 +2889,6 @@ out:
 
 	post_kvm_run_save(vcpu, kvm_run);
 
-	down_read(&vcpu->kvm->slots_lock);
-	vapic_exit(vcpu);
-	up_read(&vcpu->kvm->slots_lock);
-
 	return r;
 }
 

             reply	other threads:[~2008-06-19 17:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-19 17:43 Marcelo Tosatti [this message]
2008-06-22  5:00 ` KVM: x86: move vapic page handling out of fast path Avi Kivity
2008-06-22 17:05   ` Marcelo Tosatti
2008-06-23  2:29     ` Avi Kivity
2008-06-23 14:47       ` Marcelo Tosatti
  -- strict thread matches above, loose matches on Subject: below --
2008-06-23 15:04 Marcelo Tosatti
2008-06-29 11:53 ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080619174347.GA9236@dmt.cnet \
    --to=mtosatti@redhat.com \
    --cc=avi@qumranet.com \
    --cc=kvm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox