From patchwork Mon Jun 8 13:00:09 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 28622 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n58D18so022340 for ; Mon, 8 Jun 2009 13:01:09 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753049AbZFHNAP (ORCPT ); Mon, 8 Jun 2009 09:00:15 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751782AbZFHNAP (ORCPT ); Mon, 8 Jun 2009 09:00:15 -0400 Received: from mx2.redhat.com ([66.187.237.31]:54665 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754683AbZFHNAL (ORCPT ); Mon, 8 Jun 2009 09:00:11 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n58D0ETO006557 for ; Mon, 8 Jun 2009 09:00:14 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n58D0C8A011472; Mon, 8 Jun 2009 09:00:12 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n58D0Ba5022984; Mon, 8 Jun 2009 09:00:12 -0400 Received: from localhost.localdomain (cleopatra.tlv.redhat.com [10.35.255.11]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id F11B7250AC0; Mon, 8 Jun 2009 16:00:10 +0300 (IDT) From: Avi Kivity To: kvm@vger.kernel.org Cc: Marcelo Tosatti Subject: [PATCH 1/2] KVM: Disable large pages on misaligned memory slots Date: Mon, 8 Jun 2009 16:00:09 +0300 Message-Id: <1244466010-24909-2-git-send-email-avi@redhat.com> In-Reply-To: <1244466010-24909-1-git-send-email-avi@redhat.com> References: <1244466010-24909-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org If a slots guest physical address and host virtual address unequal (mod large page size), then we would erronously try to back guest large pages with host large pages. Detect this misalignment and diable large page support for the trouble slot. Signed-off-by: Avi Kivity --- virt/kvm/kvm_main.c | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 9c99307..b9ca73c 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1086,7 +1086,7 @@ int __kvm_set_memory_region(struct kvm *kvm, { int r; gfn_t base_gfn; - unsigned long npages; + unsigned long npages, ugfn; int largepages; unsigned long i; struct kvm_memory_slot *memslot; @@ -1177,6 +1177,14 @@ int __kvm_set_memory_region(struct kvm *kvm, new.lpage_info[0].write_count = 1; if ((base_gfn+npages) % KVM_PAGES_PER_HPAGE) new.lpage_info[largepages-1].write_count = 1; + ugfn = new.userspace_addr >> PAGE_SHIFT; + /* + * If the gfn and userspace address are not aligned wrt each + * other, disable large page support for this slot + */ + if ((base_gfn ^ ugfn) & (KVM_PAGES_PER_HPAGE - 1)) + for (i = 0; i < largepages; ++i) + new.lpage_info[i].write_count = 1; } /* Allocate page dirty bitmap if needed */