From patchwork Fri Dec 26 04:55:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiejun Chen X-Patchwork-Id: 5542181 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 06141BEEA8 for ; Fri, 26 Dec 2014 04:58:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2EBDA2012D for ; Fri, 26 Dec 2014 04:58:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D1F5A20108 for ; Fri, 26 Dec 2014 04:58:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751258AbaLZE6A (ORCPT ); Thu, 25 Dec 2014 23:58:00 -0500 Received: from mga03.intel.com ([134.134.136.65]:40183 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750920AbaLZE57 (ORCPT ); Thu, 25 Dec 2014 23:57:59 -0500 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga103.jf.intel.com with ESMTP; 25 Dec 2014 20:55:16 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.07,646,1413270000"; d="scan'208";a="653308918" Received: from tchen0-linux.bj.intel.com ([10.238.135.72]) by fmsmga002.fm.intel.com with ESMTP; 25 Dec 2014 20:57:57 -0800 From: Tiejun Chen 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 Message-Id: <1419569710-8127-1-git-send-email-tiejun.chen@intel.com> X-Mailer: git-send-email 1.9.1 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Tested-by: Jamie Heilman Reported-by: Andy Lutomirski Signed-off-by: Tiejun Chen --- 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--;