From: James Hogan <james.hogan@imgtec.com>
To: Mario Smarduch <m.smarduch@samsung.com>
Cc: <kvmarm@lists.cs.columbia.edu>, <christoffer.dall@linaro.org>,
<pbonzini@redhat.com>, <agraf@suse.de>, <catalin.marinas@arm.com>,
<cornelia.huck@de.ibm.com>, <borntraeger@de.ibm.com>,
<marc.zyngier@arm.com>, <xiaoguangrong@linux.vnet.ibm.com>,
<kvm@vger.kernel.org>, <kvm-ppc@vger.kernel.org>,
<kvm-ia64@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>, <steve.capper@arm.com>,
<peter.maydell@linaro.org>
Subject: Re: [PATCH v12 2/6] KVM: Add generic support for dirty page logging
Date: Sat, 1 Nov 2014 10:12:08 +0000 [thread overview]
Message-ID: <20141101101208.GE12801@jhogan-linux.le.imgtec.org> (raw)
In-Reply-To: <1414017251-5772-3-git-send-email-m.smarduch@samsung.com>
Hi Mario,
On Wed, Oct 22, 2014 at 03:34:07PM -0700, Mario Smarduch wrote:
> +/**
> + * kvm_vm_ioctl_get_dirty_log - get and clear the log of dirty pages in a slot
> + * @kvm: kvm instance
> + * @log: slot id and address to which we copy the log
> + *
> + * We need to keep it in mind that VCPU threads can write to the bitmap
> + * concurrently. So, to avoid losing data, we keep the following order for
> + * each bit:
> + *
> + * 1. Take a snapshot of the bit and clear it if needed.
> + * 2. Write protect the corresponding page.
> + * 3. Flush TLB's if needed.
> + * 4. Copy the snapshot to the userspace.
> + *
> + * Between 2 and 3, the guest may write to the page using the remaining TLB
> + * entry. This is not a problem because the page will be reported dirty at
> + * step 4 using the snapshot taken before and step 3 ensures that successive
> + * writes will be logged for the next call.
> + */
> +int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log)
> +{
> + int r;
> + struct kvm_memory_slot *memslot;
> + unsigned long n, i;
> + unsigned long *dirty_bitmap;
> + unsigned long *dirty_bitmap_buffer;
> + bool is_dirty = false;
> +
> + mutex_lock(&kvm->slots_lock);
> +
> + r = -EINVAL;
> + if (log->slot >= KVM_USER_MEM_SLOTS)
> + goto out;
> +
> + memslot = id_to_memslot(kvm->memslots, log->slot);
> +
> + dirty_bitmap = memslot->dirty_bitmap;
> + r = -ENOENT;
> + if (!dirty_bitmap)
> + goto out;
> +
> + n = kvm_dirty_bitmap_bytes(memslot);
> +
> + dirty_bitmap_buffer = dirty_bitmap + n / sizeof(long);
> + memset(dirty_bitmap_buffer, 0, n);
> +
> + spin_lock(&kvm->mmu_lock);
> +
> + for (i = 0; i < n / sizeof(long); i++) {
> + unsigned long mask;
> + gfn_t offset;
> +
> + if (!dirty_bitmap[i])
> + continue;
> +
> + is_dirty = true;
> +
> + mask = xchg(&dirty_bitmap[i], 0);
> + dirty_bitmap_buffer[i] = mask;
> +
> + offset = i * BITS_PER_LONG;
> + kvm_mmu_write_protect_pt_masked(kvm, memslot, offset, mask);
> + }
> +
> + spin_unlock(&kvm->mmu_lock);
> +
> + /* See the comments in kvm_mmu_slot_remove_write_access(). */
> + lockdep_assert_held(&kvm->slots_lock);
> +
> + /*
> + * All the TLBs can be flushed out of mmu lock, see the comments in
> + * kvm_mmu_slot_remove_write_access().
> + */
> + if (is_dirty)
> + kvm_flush_remote_tlbs(kvm);
> +
> + r = -EFAULT;
> + if (copy_to_user(log->dirty_bitmap, dirty_bitmap_buffer, n))
> + goto out;
AFAICT all of the arch implementations of kvm_vm_ioctl_get_dirty_log()
except x86 and ppc hv (i.e. ia60, mips, ppc pv, s390) already make use
of the existing generic function kvm_get_dirty_log() to help implement
their kvm_vm_ioctl_get_dirty_log functions, which all look pretty
similar now except for TLB flushing.
Would they not be a better base for a generic
kvm_vm_ioctl_get_dirty_log()?
It feels a bit wrong to add a generic higher level function which
doesn't make use of the existing generic lower level abstraction.
(Appologies if this has already been brought up in previous versions of
the patchset, I haven't been tracking them).
Cheers
James
> +
> + r = 0;
> +out:
> + mutex_unlock(&kvm->slots_lock);
> + return r;
> +}
next prev parent reply other threads:[~2014-11-01 10:12 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-22 22:34 [PATCH v12 0/6] arm/KVM: dirty page logging support for ARMv7 (3.17.0-rc1) Mario Smarduch
2014-10-22 22:34 ` [PATCH v12 1/6] KVM: Add architecture-defined TLB flush support Mario Smarduch
2014-10-30 12:06 ` Cornelia Huck
2014-11-05 16:10 ` Paolo Bonzini
2014-10-22 22:34 ` [PATCH v12 2/6] KVM: Add generic support for dirty page logging Mario Smarduch
2014-10-30 12:14 ` Cornelia Huck
2014-10-30 19:19 ` Mario Smarduch
2014-11-03 3:01 ` Takuya Yoshikawa
2014-11-03 19:34 ` Mario Smarduch
2014-11-01 10:12 ` James Hogan [this message]
2014-11-03 18:44 ` Mario Smarduch
2014-11-05 16:09 ` Paolo Bonzini
2014-11-05 23:05 ` Mario Smarduch
2014-11-06 10:14 ` Paolo Bonzini
2014-11-06 18:07 ` Mario Smarduch
2014-10-22 22:34 ` [PATCH v12 3/6] arm: KVM: Add ARMv7 API to flush TLBs Mario Smarduch
2014-10-22 22:34 ` [PATCH v12 4/6] arm: KVM: Add initial dirty page locking infrastructure Mario Smarduch
2014-10-27 23:26 ` [PATCH v12 0/6] arm/KVM: dirty page logging support for ARMv7 (3.17.0-rc1) Wanpeng Li
2014-10-28 0:28 ` Mario Smarduch
2014-10-28 1:24 ` Wanpeng Li
2014-10-28 16:15 ` Mario Smarduch
2014-10-28 16:29 ` [PATCH v12 0/6] 2nd-request for review comments: " Mario Smarduch
2014-10-30 12:11 ` [PATCH v12 0/6] " Christian Borntraeger
2014-10-30 19:27 ` Mario Smarduch
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=20141101101208.GE12801@jhogan-linux.le.imgtec.org \
--to=james.hogan@imgtec.com \
--cc=agraf@suse.de \
--cc=borntraeger@de.ibm.com \
--cc=catalin.marinas@arm.com \
--cc=christoffer.dall@linaro.org \
--cc=cornelia.huck@de.ibm.com \
--cc=kvm-ia64@vger.kernel.org \
--cc=kvm-ppc@vger.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=m.smarduch@samsung.com \
--cc=marc.zyngier@arm.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=steve.capper@arm.com \
--cc=xiaoguangrong@linux.vnet.ibm.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