public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Tiejun Chen <tiejun.chen@intel.com>
To: pbonzini@redhat.com, imammedo@redhat.com
Cc: luto@amacapital.net, jamie@audible.transient.net, kvm@vger.kernel.org
Subject: [PATCH] kvm: fix to update memslots properly
Date: Fri, 26 Dec 2014 12:55:10 +0800	[thread overview]
Message-ID: <1419569710-8127-1-git-send-email-tiejun.chen@intel.com> (raw)

After commit, 0e60b0799fed, "kvm: change memslot sorting rule from size to
GFN" is introduced, we're missing but need to consider such a case,
(!new->base_gfn && !mslots[i - 1].base_gfn && !mslots[i - 1].npages), then
re-sort kvm_memslots wrong in next case to issue the following,

KVM internal error. Suberror: 1
emulation failure
EAX=000dee58 EBX=00000000 ECX=00000000 EDX=00000cfd
ESI=00000059 EDI=00000000 EBP=00000000 ESP=00006fc4
EIP=000f17f4 EFL=00010012 [----A--] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
CS =0008 00000000 ffffffff 00c09b00 DPL=0 CS32 [-RA]
SS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
DS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
FS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
GS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT=     000f6c58 00000037
IDT=     000f6c96 00000000
CR0=60000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000
DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
EFER=0000000000000000
Code=e8 75 fc ff ff 89 f2 a8 10 89 d8 75 0a b9 74 17 ff ff ff d1 <5b>
5e c3 5b 5e e9 76 ff ff ff 57 56 53 8b 35 38 65 0f 00 85 f6 0f 88 be
00 00 00 0f b7 f6

And we also should set flag as 0 in case of (new->npages == 0) &&
(new->base_gfn == 0).

Reported-by: Jamie Heilman <jamie@audible.transient.net>
Tested-by: Jamie Heilman <jamie@audible.transient.net>
Reported-by: Andy Lutomirski <luto@amacapital.net>
Signed-off-by: Tiejun Chen <tiejun.chen@intel.com>
---

I test this both in Andy' case and Jamie's case.

 virt/kvm/kvm_main.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index f528343..6e52f3f 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -672,6 +672,7 @@ static void update_memslots(struct kvm_memslots *slots,
 	WARN_ON(mslots[i].id != id);
 	if (!new->npages) {
 		new->base_gfn = 0;
+		new->flags = 0;
 		if (mslots[i].npages)
 			slots->used_slots--;
 	} else {
@@ -688,7 +689,9 @@ static void update_memslots(struct kvm_memslots *slots,
 		i++;
 	}
 	while (i > 0 &&
-	       new->base_gfn > mslots[i - 1].base_gfn) {
+	       ((new->base_gfn > mslots[i - 1].base_gfn) ||
+	        (!new->base_gfn &&
+	         !mslots[i - 1].base_gfn && !mslots[i - 1].npages))) {
 		mslots[i] = mslots[i - 1];
 		slots->id_to_index[mslots[i].id] = i;
 		i--;
-- 
1.9.1


             reply	other threads:[~2014-12-26  4:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-26  4:55 Tiejun Chen [this message]
2014-12-27 20:41 ` [PATCH] kvm: fix to update memslots properly Paolo Bonzini
2014-12-27 22:52   ` Jamie Heilman
2014-12-29  1:06   ` Chen, Tiejun
2015-03-09 20:54   ` Marcelo Tosatti
2015-03-10  6:17     ` Chen, Tiejun
2015-03-10 11:59       ` Paolo Bonzini

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=1419569710-8127-1-git-send-email-tiejun.chen@intel.com \
    --to=tiejun.chen@intel.com \
    --cc=imammedo@redhat.com \
    --cc=jamie@audible.transient.net \
    --cc=kvm@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=pbonzini@redhat.com \
    /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