From: Avi Kivity <avi@redhat.com>
To: Joerg Roedel <joerg.roedel@amd.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/7] kvm mmu: implement necessary data structures for second huge page accounting
Date: Sun, 29 Mar 2009 16:37:38 +0300 [thread overview]
Message-ID: <49CF79A2.9020202@redhat.com> (raw)
In-Reply-To: <49CF7716.1000008@redhat.com>
Avi Kivity wrote:
> Joerg Roedel wrote:
>> This patch adds the necessary data structures to take care of write
>> protections in place within a second huge page sized page.
>>
>>
>> +#ifdef KVM_PAGES_PER_LHPAGE
>> + if (npages && !new.hpage_info) {
>> + int hugepages = npages / KVM_PAGES_PER_LHPAGE;
>> + if (npages % KVM_PAGES_PER_LHPAGE)
>> + hugepages++;
>> + if (base_gfn % KVM_PAGES_PER_LHPAGE)
>> + hugepages++;
>>
>
> Consider a slot with base_gfn == 1 and npages == 1. This will have
> hugepages == 2, which is wrong.
>
> I think the right calculation is
>
> ((base_gfn + npages - 1) / N) - (base_gfn / N) + 1
>
> i.e. index of last page, plus one so we can store it.
>
> The small huge page calculation is off as well.
>
I fixed the existing case with
commit 1a967084dbe97a2f4be84139d14e2d958d7ffc46
Author: Avi Kivity <avi@redhat.com>
Date: Sun Mar 29 16:31:25 2009 +0300
KVM: MMU: Fix off-by-one calculating large page count
The large page initialization code concludes there are two large
pages spanned
by a slot covering 1 (small) page starting at gfn 1. This is
incorrect, and
also results in incorrect write_count initialization in some cases
(base = 1,
npages = 513 for example).
Cc: stable@kernel.org
Signed-off-by: Avi Kivity <avi@redhat.com>
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 8aa3b95..3d31557 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1076,6 +1076,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
int r;
gfn_t base_gfn;
unsigned long npages;
+ int largepages;
unsigned long i;
struct kvm_memory_slot *memslot;
struct kvm_memory_slot old, new;
@@ -1151,11 +1152,8 @@ int __kvm_set_memory_region(struct kvm *kvm,
new.userspace_addr = 0;
}
if (npages && !new.lpage_info) {
- int largepages = npages / KVM_PAGES_PER_HPAGE;
- if (npages % KVM_PAGES_PER_HPAGE)
- largepages++;
- if (base_gfn % KVM_PAGES_PER_HPAGE)
- largepages++;
+ largepages = 1 + (base_gfn + npages - 1) /
KVM_PAGES_PER_HPAGE;
+ largepages -= base_gfn / npages;
new.lpage_info = vmalloc(largepages *
sizeof(*new.lpage_info));
--
error compiling committee.c: too many arguments to function
next prev parent reply other threads:[~2009-03-29 13:37 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-27 14:31 [PATCH 0/7] Support for GB pages in KVM Joerg Roedel
2009-03-27 14:31 ` [PATCH 1/7] hugetlb: export vma_kernel_pagesize to modules Joerg Roedel
2009-03-27 14:31 ` [PATCH 2/7] kvm mmu: infrastructure changes for multiple huge page support Joerg Roedel
2009-03-29 11:38 ` Avi Kivity
2009-03-27 14:31 ` [PATCH 3/7] kvm mmu: add page size parameter to rmap_remove Joerg Roedel
2009-03-27 14:31 ` [PATCH 4/7] kvm mmu: implement necessary data structures for second huge page accounting Joerg Roedel
2009-03-29 11:45 ` Avi Kivity
2009-03-29 13:03 ` Joerg Roedel
2009-03-29 13:15 ` Avi Kivity
2009-03-29 13:32 ` Joerg Roedel
2009-03-29 13:26 ` Avi Kivity
2009-03-29 13:37 ` Avi Kivity [this message]
2009-03-27 14:31 ` [PATCH 5/7] kvm mmu: add support for 1GB pages to direct mapping paths Joerg Roedel
2009-03-29 11:49 ` Avi Kivity
2009-03-27 14:31 ` [PATCH 6/7] kvm mmu: enabling 1GB pages by extending backing_size funtion Joerg Roedel
2009-03-29 11:51 ` Avi Kivity
2009-03-27 14:31 ` [PATCH 7/7] kvm x86: report 1GB page support to userspace Joerg Roedel
2009-03-29 11:54 ` Avi Kivity
2009-03-29 12:45 ` Joerg Roedel
2009-03-29 12:49 ` Avi Kivity
2009-03-29 12:54 ` Joerg Roedel
2009-03-29 13:00 ` Avi Kivity
2009-03-28 21:40 ` [PATCH 0/7] Support for GB pages in KVM Marcelo Tosatti
2009-03-28 21:49 ` Joerg Roedel
2009-03-29 12:03 ` Avi Kivity
2009-03-29 12:47 ` Joerg Roedel
2009-03-29 12:01 ` 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=49CF79A2.9020202@redhat.com \
--to=avi@redhat.com \
--cc=joerg.roedel@amd.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mtosatti@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