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: Re: KVM: x86: move vapic page handling out of fast path
Date: Mon, 23 Jun 2008 11:47:46 -0300	[thread overview]
Message-ID: <20080623144746.GA30027@dmt.cnet> (raw)
In-Reply-To: <485F0A8E.3030605@qumranet.com>

On Mon, Jun 23, 2008 at 05:29:34AM +0300, Avi Kivity wrote:
> The page can't be swapped out since its reference count is elevated  
> indefinitely.

AFAICT the page can be swapped out when the guest has exited to
userspace and the only reference is the qemu userspace mapping.

>> So, what do you have against this patch ?
>>   
>
> We need to move away from reference counts, they make kvm brittle.  The  
> patch improves the current state of things (since pages are pinned  
> indefinitely anyway now) but takes the wrong direction for the future.
>
> Note that kvmclock has the same issue, so we might as well share the  
> solution:
>
> struct kvm_fast_guest_page {
>     gfn_t gfn;
>     struct page *page;
>     spinlock_t lock;
>     struct list_head link;
> }
>
> The mmu notifier callbacks can scan this list and null any pages that  
> match the gfn being cleared, but in the normal cast, ->page can be  
> accessed directly.

OK, can you please apply this at least:

KVM: move slots_lock acquision down to vapic_exit

There is no need to grab slots_lock if the vapic_page will not
be touched.

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


diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 26b051b..29e8983 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2759,8 +2759,10 @@ static void vapic_exit(struct kvm_vcpu *vcpu)
 	if (!apic || !apic->vapic_addr)
 		return;
 
+	down_read(&vcpu->kvm->slots_lock);
 	kvm_release_page_dirty(apic->vapic_page);
 	mark_page_dirty(vcpu->kvm, apic->vapic_addr >> PAGE_SHIFT);
+	up_read(&vcpu->kvm->slots_lock);
 }
 
 static int __vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
@@ -2916,9 +2918,7 @@ 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-10-18 10:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-19 17:43 KVM: x86: move vapic page handling out of fast path Marcelo Tosatti
2008-06-22  5:00 ` Avi Kivity
2008-06-22 17:05   ` Marcelo Tosatti
2008-06-23  2:29     ` Avi Kivity
2008-06-23 14:47       ` Marcelo Tosatti [this message]
  -- 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=20080623144746.GA30027@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