public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <marcelo@kvack.org>
To: Avi Kivity <avi@qumranet.com>
Cc: Marcelo Tosatti <marcelo@kvack.org>,
	kvm-devel@lists.sourceforge.net,
	Andrea Arcangeli <andrea@qumranet.com>
Subject: Re: [PATCH] QEMU support for virtio balloon driver
Date: Sat, 8 Mar 2008 16:27:13 -0300	[thread overview]
Message-ID: <20080308192713.GA19321@dmt> (raw)
In-Reply-To: <479B8040.1000901@qumranet.com>

On Sat, Jan 26, 2008 at 08:47:28PM +0200, Avi Kivity wrote:
> Anthony Liguori wrote:
> >Do others expect KVM to just cope with the virtual mapping being changed 
> >out from underneath of it?
> >  
> 
> kvm should cope with both malicious guests and malicious (or buggy) host 
> userspace.  It's difficuly to analyze, but mmu notifiers might be 
> necessary for the latter.

The reason for the host crash with madvise is that the rmap code relies
on the guest process virtual mappings from not disappearing while there
are active shadow mappings.

How to proceed now? Do we want to efficiently support ballooning without
mmu notifiers? If so, an ioctl to zap the mmu is necessary as discussed
before.


diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index f0cdfba..4c93b79 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -1009,6 +1009,21 @@ struct page *gva_to_page(struct kvm_vcpu *vcpu, gva_t gva)
 	return page;
 }
 
+static int was_spte_rmapped(struct kvm *kvm, u64 *spte, struct page *page)
+{
+	int ret = 0;
+	unsigned long host_pfn = (*spte & PT64_BASE_ADDR_MASK) >> PAGE_SHIFT;
+
+	if (is_rmap_pte(*spte)) {
+		if (host_pfn != page_to_pfn(page))
+			rmap_remove(kvm, spte);
+		else
+			ret = 1;
+	}
+
+	return ret;
+}
+
 static void mmu_set_spte(struct kvm_vcpu *vcpu, u64 *shadow_pte,
 			 unsigned pt_access, unsigned pte_access,
 			 int user_fault, int write_fault, int dirty,
@@ -1016,7 +1031,7 @@ static void mmu_set_spte(struct kvm_vcpu *vcpu, u64 *shadow_pte,
 			 struct page *page)
 {
 	u64 spte;
-	int was_rmapped = is_rmap_pte(*shadow_pte);
+	int was_rmapped = was_spte_rmapped(vcpu->kvm, shadow_pte, page);
 	int was_writeble = is_writeble_pte(*shadow_pte);
 
 	/*



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

  reply	other threads:[~2008-03-08 19:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-24 21:23 [PATCH] QEMU support for virtio balloon driver Anthony Liguori
     [not found] ` <1201209786831-git-send-email-aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-01-24 22:29   ` Anthony Liguori
     [not found]     ` <4799115F.8010506-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-01-25 16:08       ` Marcelo Tosatti
2008-01-25 17:02         ` Anthony Liguori
     [not found]           ` <479A162C.1060209-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-01-26 18:47             ` Avi Kivity
2008-03-08 19:27               ` Marcelo Tosatti [this message]
2008-03-08 20:51                 ` Marcelo Tosatti
2008-03-09  2:46                   ` Anthony Liguori
2008-01-26  3:35         ` Rusty Russell
2008-01-25 23:08       ` Dor Laor
     [not found]         ` <1201302492.2944.8.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2008-01-26  0:10           ` Anthony Liguori
     [not found]             ` <479A7A5C.6030005-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-01-26 18:35               ` Avi Kivity
  -- strict thread matches above, loose matches on Subject: below --
2008-02-25 19:47 Anthony Liguori
2008-02-25 23:45 ` Dor Laor

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=20080308192713.GA19321@dmt \
    --to=marcelo@kvack.org \
    --cc=andrea@qumranet.com \
    --cc=avi@qumranet.com \
    --cc=kvm-devel@lists.sourceforge.net \
    /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