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 14:45:44 +0300 [thread overview]
Message-ID: <49CF5F68.1020507@redhat.com> (raw)
In-Reply-To: <1238164319-16092-5-git-send-email-joerg.roedel@amd.com>
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.
>
>
> struct kvm_vcpu_arch {
> diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
> index 9936b45..7d4162d 100644
> --- a/arch/x86/kvm/mmu.c
> +++ b/arch/x86/kvm/mmu.c
> @@ -390,6 +390,15 @@ static int *slot_largepage_idx(gfn_t gfn, struct kvm_memory_slot *slot)
> return &slot->lpage_info[idx].write_count;
> }
>
> +static int *slot_hugepage_idx(gfn_t gfn, struct kvm_memory_slot *slot)
> +{
> + unsigned long idx;
> +
> + idx = (gfn / KVM_PAGES_PER_1G_PAGE) -
> + (slot->base_gfn / KVM_PAGES_PER_1G_PAGE);
> + return &slot->hpage_info[idx].write_count;
> +}
>
A page level argument would remove the need for this duplication, as
well as all the constants.
>
> +static int has_wrprotected_largepage(struct kvm *kvm, gfn_t gfn)
> +{
> + struct kvm_memory_slot *slot;
> + int *hugepage_idx;
> +
> + gfn = unalias_gfn(kvm, gfn);
> + slot = gfn_to_memslot_unaliased(kvm, gfn);
> + if (slot) {
> + hugepage_idx = slot_hugepage_idx(gfn, slot);
>
slot_largepage_idx() here?
I don't think we ever write protect large pages, so why is this needed?
> + return *hugepage_idx;
> + }
> +
> + return 1;
> +}
>
> +
> static enum kvm_page_size host_page_size(struct kvm *kvm, gfn_t gfn)
> {
> struct vm_area_struct *vma;
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index 095ebb6..2f05d48 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -103,7 +103,7 @@ struct kvm_memory_slot {
> struct {
> unsigned long rmap_pde;
> int write_count;
> - } *lpage_info;
> + } *lpage_info, *hpage_info;
>
} * lpage_info[KVM_NR_PAGE_LEVELS];
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 8aa3b95..c4842f4 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -1001,10 +1001,14 @@ static void kvm_free_physmem_slot(struct kvm_memory_slot *free,
> if (!dont || free->lpage_info != dont->lpage_info)
> vfree(free->lpage_info);
>
> + if (!dont || free->hpage_info != dont->hpage_info)
> + vfree(free->hpage_info);
>
loop
> void kvm_free_physmem(struct kvm *kvm)
> @@ -1170,6 +1174,28 @@ int __kvm_set_memory_region(struct kvm *kvm,
> new.lpage_info[largepages-1].write_count = 1;
> }
>
> +#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++;
> +
> + new.hpage_info = vmalloc(hugepages * sizeof(*new.hpage_info));
> +
> + if (!new.hpage_info)
> + goto out_free;
> +
> + memset(new.hpage_info, 0, hugepages * sizeof(*new.hpage_info));
> +
> + if (base_gfn % KVM_PAGES_PER_LHPAGE)
> + new.hpage_info[0].write_count = 1;
> + if ((base_gfn+npages) % KVM_PAGES_PER_LHPAGE)
> + new.hpage_info[hugepages-1].write_count = 1;
> + }
> +#endif
>
Loop, KVM_NR_PAGE_LEVELS defined per arch.
--
error compiling committee.c: too many arguments to function
next prev parent reply other threads:[~2009-03-29 11:45 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 [this message]
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
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=49CF5F68.1020507@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;
as well as URLs for NNTP newsgroup(s).