public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: Paul Mackerras <paulus@samba.org>
Cc: kvm-ppc@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH 4/7] KVM: PPC: Book3S HV: Fix dirty map for hugepages
Date: Sun, 25 May 2014 12:00:48 +0200	[thread overview]
Message-ID: <5381BF50.5060701@suse.de> (raw)
In-Reply-To: <1400919721-14264-5-git-send-email-paulus@samba.org>


On 24.05.14 10:21, Paul Mackerras wrote:
> From: Alexey Kardashevskiy <aik@ozlabs.ru>
>
> The dirty map that we construct for the KVM_GET_DIRTY_LOG ioctl has
> one bit per system page (4K/64K).  Currently, we only set one bit in
> the map for each HPT entry with the Change bit set, even if the HPT is
> for a large page (e.g., 16MB).  Userspace then considers only the
> first system page dirty, though in fact the guest may have modified
> anywhere in the large page.
>
> To fix this, we make kvm_test_clear_dirty() return the actual number
> of pages that are dirty.  In kvmppc_hv_get_dirty_log() we then set
> that many bits in the dirty map.
>
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> Signed-off-by: Paul Mackerras <paulus@samba.org>
> ---
>   arch/powerpc/kvm/book3s_64_mmu_hv.c | 14 ++++++++++----
>   1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
> index f32896f..d605dc24 100644
> --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
> +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
> @@ -1053,6 +1053,7 @@ static int kvm_test_clear_dirty(struct kvm *kvm, unsigned long *rmapp)
>   {
>   	struct revmap_entry *rev = kvm->arch.revmap;
>   	unsigned long head, i, j;
> +	unsigned long n;
>   	unsigned long *hptep;
>   	int ret = 0;
>   
> @@ -1095,7 +1096,10 @@ static int kvm_test_clear_dirty(struct kvm *kvm, unsigned long *rmapp)
>   				rev[i].guest_rpte |= HPTE_R_C;
>   				note_hpte_modification(kvm, &rev[i]);
>   			}
> -			ret = 1;
> +			n = hpte_page_size(hptep[0], hptep[1]);
> +			n = (n + PAGE_SIZE - 1) >> PAGE_SHIFT;
> +			if (n > ret)
> +				ret = n;

Please document in the function header that the return value is the 
number of pages that are dirty. Alternatively rename the function.

>   		}
>   		hptep[0] &= ~HPTE_V_HVLOCK;
>   	} while ((i = j) != head);
> @@ -1125,15 +1129,17 @@ static void harvest_vpa_dirty(struct kvmppc_vpa *vpa,
>   long kvmppc_hv_get_dirty_log(struct kvm *kvm, struct kvm_memory_slot *memslot,
>   			     unsigned long *map)
>   {
> -	unsigned long i;
> +	unsigned long i, j;
>   	unsigned long *rmapp;
>   	struct kvm_vcpu *vcpu;
>   
>   	preempt_disable();
>   	rmapp = memslot->arch.rmap;
>   	for (i = 0; i < memslot->npages; ++i) {
> -		if (kvm_test_clear_dirty(kvm, rmapp) && map)
> -			__set_bit_le(i, map);
> +		int ret = kvm_test_clear_dirty(kvm, rmapp);

Please give this one a better name. npages maybe?

> +		if (ret && map)
> +			for (j = i - (i % ret); ret; ++j, --ret)

Why do we go down from the index?


Alex

> +				__set_bit_le(j, map);
>   		++rmapp;
>   	}
>   

  reply	other threads:[~2014-05-25 10:00 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-24  8:21 [PATCH 0/7] Bug fixes for HV KVM Paul Mackerras
2014-05-24  8:21 ` [PATCH 1/7] KVM: PPC: Book3S: Add ONE_REG register names that were missed Paul Mackerras
2014-05-24  8:21 ` [PATCH 2/7] KVM: PPC: Book3S: Move KVM_REG_PPC_WORT to an unused register number Paul Mackerras
2014-05-24  8:21 ` [PATCH 3/7] KVM: PPC: Book3S HV: Fix check for running inside guest in global_invalidates() Paul Mackerras
2014-05-24  8:21 ` [PATCH 4/7] KVM: PPC: Book3S HV: Fix dirty map for hugepages Paul Mackerras
2014-05-25 10:00   ` Alexander Graf [this message]
2014-05-26  3:30     ` Paul Mackerras
2014-05-24  8:21 ` [PATCH 5/7] KVM: PPC: Book3S HV: Make sure we don't miss dirty pages Paul Mackerras
2014-05-24  8:22 ` [PATCH 6/7] KVM: PPC: Book3S HV: Work around POWER8 performance monitor bugs Paul Mackerras
2014-05-25 10:07   ` Alexander Graf
2014-05-24  8:22 ` [PATCH 7/7] KVM: PPC: Book3S HV: Fix machine check delivery to guest Paul Mackerras

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=5381BF50.5060701@suse.de \
    --to=agraf@suse.de \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=paulus@samba.org \
    /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