arm: dirty page logging support for ARMv7
Subsystems (12)
v11 cover arm: dirty page logging support for ARMv7
This patch adds support for ARMv7 dirty page logging. Some functions of dirty page logging have been split to generic and arch specific implementations, details below. Dirty page logging is one of serveral features required for live migration, live migration has been tested for ARMv7.
Testing:
- QEMU machvirt, VExpress - Exynos 5440, FastModels - lmbench + dirty guest memory cycling.
- ARMv8 Foundation Model/kvmtool - Due to slight overlap in 2nd stage handlers did a basic bringup and memory test.
- x86_64 QEMU basic migration on same platform.
See https://github.com/mjsmar/arm-migration-howto for details testing and setup (see README).
The patch affects armv7,armv8, mips, ia64, powerpc, s390, x86_64. Patch series has been compiled for affected architectures:
- x86_64 - defconfig
- ia64 - ia64-linux-gcc4.6.3 - defconfig, ia64 Kconfig defines BROKEN worked around that to make sure new changes don't break build. Eventually build breaks due to other reasons.
- mips - mips64-linux-gcc4.6.3 - malta_kvm_defconfig
- ppc - powerpc64-linux-gcc4.6.3 - pseries_defconfig
- s390 - s390x-linux-gcc4.6.3 - defconfig
- armv8 - aarch64-linux-gnu-gcc4.8.1 - defconfig
ARMv7 Dirty page logging support overivew-
- initially write protects VM RAM memory regions - 2nd stage page tables
- add support to read dirty page log and again write protect the dirty pages
- second stage page table for next pass.
- second stage huge page are dissolved into small page tables to keep track of dirty pages at page granularity. Tracking at huge page granularity limits migration to an almost idle system.
- In the event migration is canceled, normal behavior is resumed huge pages are rebuilt over time.
- Future Work
o Completed ARMv8 additions - need to validate, on hardware juno
o ARMv8 Validation test - with no migration support yet, implement replication of memory DB using dirty page logging in HA environment.
Changes since v10:
- addressed wanghaibin comments
- addressed Christoffers comments
Changes since v9:
- Split patches into generic and architecture specific variants for TLB Flushing and dirty log read (patches 1,2 & 3,4,5,6)
- rebased to 3.16.0-rc1
- Applied Christoffers comments.
Mario Smarduch (6):
KVM: Add architecture-specific TLB flush implementations
KVM: Add generic implementation of kvm_vm_ioctl_get_dirty_log
arm: KVM: Add ARMv7 API to flush TLBs
arm: KVM: Add initial dirty page locking infrastructure
arm: KVM: dirty log read write protect support
arm: KVM: ARMv7 dirty page logging 2nd stage page fault
arch/arm/include/asm/kvm_asm.h | 1 + arch/arm/include/asm/kvm_host.h | 14 +++ arch/arm/include/asm/kvm_mmu.h | 20 ++++ arch/arm/include/asm/pgtable-3level.h | 1 + arch/arm/kvm/Kconfig | 1 + arch/arm/kvm/arm.c | 13 ++- arch/arm/kvm/interrupts.S | 12 ++ arch/arm/kvm/mmu.c | 196 ++++++++++++++++++++++++++++++++- arch/arm64/kvm/Kconfig | 1 + arch/ia64/kvm/Kconfig | 1 + arch/ia64/kvm/kvm-ia64.c | 2 +- arch/mips/kvm/Kconfig | 1 + arch/mips/kvm/mips.c | 2 +- arch/powerpc/kvm/Kconfig | 1 + arch/powerpc/kvm/book3s.c | 2 +- arch/powerpc/kvm/booke.c | 2 +- arch/s390/kvm/Kconfig | 1 + arch/s390/kvm/kvm-s390.c | 2 +- arch/x86/kvm/x86.c | 86 --------------- include/linux/kvm_host.h | 7 ++ virt/kvm/Kconfig | 6 + virt/kvm/kvm_main.c | 95 ++++++++++++++++ 22 files changed, 369 insertions(+), 98 deletions(-)
Signature · 1 line
1.7.9.5
PATCH v11 1/6 KVM: Add architecture-specific TLB flush implementations
Add support to declare architecture specific TLB flush function, for now ARMv7.
--- include/linux/kvm_host.h | 1 + virt/kvm/Kconfig | 3 +++ virt/kvm/kvm_main.c | 4 ++++ 3 files changed, 8 insertions(+)
include/linux/kvm_host.h +1 -0
@@ -592,6 +592,7 @@ void kvm_load_guest_fpu(struct kvm_vcpu *vcpu);void kvm_put_guest_fpu (struct kvm_vcpu *vcpu);void kvm_flush_remote_tlbs (struct kvm *kvm); +void kvm_arch_flush_remote_tlbs (struct kvm *kvm);void kvm_reload_remote_mmus (struct kvm *kvm);void kvm_make_mclock_inprogress_request (struct kvm *kvm);void kvm_make_scan_ioapic_request (struct kvm *kvm);
virt/kvm/Kconfig +3 -0
@@ -34,3 +34,6 @@ config HAVE_KVM_CPU_RELAX_INTERCEPT config KVM_VFIO bool + +config HAVE_KVM_ARCH_TLB_FLUSH_ALL + bool
virt/kvm/kvm_main.c +4 -0
@@ -186,12 +186,16 @@ static bool make_all_cpus_request(struct kvm *kvm, unsigned int req)void kvm_flush_remote_tlbs (struct kvm *kvm) { +#ifdef CONFIG_HAVE_KVM_ARCH_TLB_FLUSH_ALL +kvm_arch_flush_remote_tlbs (kvm); +#else long dirty_count = kvm->tlbs_dirty;smp_mb ();if (make_all_cpus_request (kvm,KVM_REQ_TLB_FLUSH )) ++kvm->stat.remote_tlb_flush;cmpxchg (&kvm->tlbs_dirty, dirty_count,0 ); +#endif }EXPORT_SYMBOL_GPL (kvm_flush_remote_tlbs);
Signature · 1 line
1.7.9.5
Re: [PATCH v11 1/6] KVM: Add architecture-specific TLB flush implementations
Quoted 37 lines · Mario Smarduch
Add support to declare architecture specific TLB flush function, for now ARMv7.
Signed-off-by Mario Smarduch <[email protected]>--- include/linux/kvm_host.h | 1 + virt/kvm/Kconfig | 3 +++ virt/kvm/kvm_main.c | 4 ++++ 3 files changed, 8 insertions(+)include/linux/kvm_host.h +1
-0@@ -592,6 +592,7 @@ void kvm_load_guest_fpu(struct kvm_vcpu *vcpu);void kvm_put_guest_fpu (struct kvm_vcpu *vcpu);void kvm_flush_remote_tlbs (struct kvm *kvm); +void kvm_arch_flush_remote_tlbs (struct kvm *kvm);void kvm_reload_remote_mmus (struct kvm *kvm);void kvm_make_mclock_inprogress_request (struct kvm *kvm);void kvm_make_scan_ioapic_request (struct kvm *kvm);virt/kvm/Kconfig +3
-0@@ -34,3 +34,6 @@ config HAVE_KVM_CPU_RELAX_INTERCEPT config KVM_VFIO bool + +config HAVE_KVM_ARCH_TLB_FLUSH_ALL + boolvirt/kvm/kvm_main.c +0
-0
virt/kvm/kvm_main.c static bool make_all_cpus_request(struct kvm *kvm, unsigned int req) · line 189
Quoted 4 lines
virt/kvm/kvm_main.c +1
-0@@ -186,12 +186,16 @@ static bool make_all_cpus_request(struct kvm *kvm, unsigned int req)void kvm_flush_remote_tlbs (struct kvm *kvm) { +#ifdef CONFIG_HAVE_KVM_ARCH_TLB_FLUSH_ALL
Please make this an #ifndef on the outer definition and just define your own copy of this function inside of arch/arm/kvm :).
Alex
Quoted 13 lines
virt/kvm/kvm_main.c +3
-0+kvm_arch_flush_remote_tlbs (kvm); +#else long dirty_count = kvm->tlbs_dirty;smp_mb ();if (make_all_cpus_request (kvm,KVM_REQ_TLB_FLUSH )) ++kvm->stat.remote_tlb_flush;cmpxchg (&kvm->tlbs_dirty, dirty_count,0 ); +#endif }EXPORT_SYMBOL_GPL (kvm_flush_remote_tlbs);
PATCH v11 2/6 KVM: Add generic implementation of kvm_vm_ioctl_get_dirty_log
In reply to Mario SmarduchAdd support for generic implementation of dirty log read function. For now x86_64 and ARMv7 share generic dirty log read. Other architectures call their architecture specific functions.
--- arch/arm/kvm/Kconfig | 1 + arch/arm/kvm/arm.c | 2 +- arch/arm64/kvm/Kconfig | 1 + arch/ia64/kvm/Kconfig | 1 + arch/ia64/kvm/kvm-ia64.c | 2 +- arch/mips/kvm/Kconfig | 1 + arch/mips/kvm/mips.c | 2 +- arch/powerpc/kvm/Kconfig | 1 + arch/powerpc/kvm/book3s.c | 2 +- arch/powerpc/kvm/booke.c | 2 +- arch/s390/kvm/Kconfig | 1 + arch/s390/kvm/kvm-s390.c | 2 +- arch/x86/kvm/x86.c | 86 ------------------------------------------ include/linux/kvm_host.h | 6 +++ virt/kvm/Kconfig | 3 ++ virt/kvm/kvm_main.c | 91 +++++++++++++++++++++++++++++++++++++++++++++ 16 files changed, 112 insertions(+), 92 deletions(-)
arch/arm/kvm/Kconfig +1 -0
@@ -23,6 +23,7 @@ config KVM select HAVE_KVM_CPU_RELAX_INTERCEPT select KVM_MMIO select KVM_ARM_HOST + select HAVE_KVM_ARCH_DIRTY_LOG depends on ARM_VIRT_EXT && ARM_LPAE && !CPU_BIG_ENDIAN ---help--- Support hosting virtualized guest machines. You will also
arch/arm/kvm/arm.c +1 -1
@@ -774,7 +774,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp, } } -int kvm_vm_ioctl_get_dirty_log (struct kvm *kvm,struct kvm_dirty_log *log) +int kvm_arch_vm_ioctl_get_dirty_log (struct kvm *kvm,struct kvm_dirty_log *log) {return -EINVAL ; }
arch/arm64/kvm/Kconfig +1 -0
@@ -26,6 +26,7 @@ config KVM select KVM_ARM_HOST select KVM_ARM_VGIC select KVM_ARM_TIMER + select HAVE_KVM_ARCH_DIRTY_LOG ---help--- Support hosting virtualized guest machines.
arch/ia64/kvm/Kconfig +1 -0
@@ -28,6 +28,7 @@ config KVM select HAVE_KVM_IRQ_ROUTING select KVM_APIC_ARCHITECTURE select KVM_MMIO + select HAVE_KVM_ARCH_DIRTY_LOG ---help--- Support hosting fully virtualized guest machines using hardware virtualization extensions. You will need a fairly recent
arch/ia64/kvm/kvm-ia64.c +1 -1
@@ -1812,7 +1812,7 @@ static void kvm_ia64_sync_dirty_log(struct kvm *kvm,spin_unlock (&kvm->arch.dirty_log_lock); } -int kvm_vm_ioctl_get_dirty_log (struct kvm *kvm, +int kvm_arch_vm_ioctl_get_dirty_log (struct kvm *kvm,struct kvm_dirty_log *log) {int r;
arch/mips/kvm/Kconfig +1 -0
@@ -20,6 +20,7 @@ config KVM select PREEMPT_NOTIFIERS select ANON_INODES select KVM_MMIO + select HAVE_KVM_ARCH_DIRTY_LOG ---help--- Support for hosting Guest kernels. Currently supported on MIPS32 processors.
arch/mips/kvm/mips.c +1 -1
@@ -791,7 +791,7 @@ out: }/* Get (and clear) the dirty memory log for a memory slot. */ -int kvm_vm_ioctl_get_dirty_log (struct kvm *kvm,struct kvm_dirty_log *log) +int kvm_arch_vm_ioctl_get_dirty_log (struct kvm *kvm,struct kvm_dirty_log *log) {struct kvm_memory_slot *memslot;unsigned long ga, ga_end;
arch/powerpc/kvm/Kconfig +1 -0
@@ -21,6 +21,7 @@ config KVM select PREEMPT_NOTIFIERS select ANON_INODES select HAVE_KVM_EVENTFD + select HAVE_KVM_ARCH_DIRTY_LOG config KVM_BOOK3S_HANDLER bool
arch/powerpc/kvm/book3s.c +1 -1
@@ -815,7 +815,7 @@ int kvmppc_core_check_requests(struct kvm_vcpu *vcpu)return vcpu->kvm->arch.kvm_ops->check_requests (vcpu); } -int kvm_vm_ioctl_get_dirty_log (struct kvm *kvm,struct kvm_dirty_log *log) +int kvm_arch_vm_ioctl_get_dirty_log (struct kvm *kvm,struct kvm_dirty_log *log) {return kvm->arch.kvm_ops->get_dirty_log (kvm, log); }
arch/powerpc/kvm/booke.c +1 -1
@@ -1624,7 +1624,7 @@ int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,return r; } -int kvm_vm_ioctl_get_dirty_log (struct kvm *kvm,struct kvm_dirty_log *log) +int kvm_arch_vm_ioctl_get_dirty_log (struct kvm *kvm,struct kvm_dirty_log *log) {return -ENOTSUPP ; }
arch/s390/kvm/Kconfig +1 -0
@@ -27,6 +27,7 @@ config KVM select KVM_ASYNC_PF_SYNC select HAVE_KVM_IRQCHIP select HAVE_KVM_IRQ_ROUTING + select HAVE_KVM_ARCH_DIRTY_LOG ---help--- Support hosting paravirtualized guest machines using the SIE virtualization capability on the mainframe. This should work
arch/s390/kvm/kvm-s390.c +1 -1
@@ -208,7 +208,7 @@ static void kvm_s390_sync_dirty_log(struct kvm *kvm,/* * Get (and clear) the dirty memory log for a memory slot. */ -int kvm_vm_ioctl_get_dirty_log (struct kvm *kvm, +int kvm_arch_vm_ioctl_get_dirty_log (struct kvm *kvm,struct kvm_dirty_log *log) {int r;
arch/x86/kvm/x86.c +0 -86
92 lines not on this page · raw message
include/linux/kvm_host.h +6 -0
@@ -609,6 +609,12 @@ int kvm_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log, int *is_dirty);int kvm_vm_ioctl_get_dirty_log (struct kvm *kvm,struct kvm_dirty_log *log); +int kvm_arch_vm_ioctl_get_dirty_log (struct kvm *kvm, +struct kvm_dirty_log *log); +void kvm_mmu_write_protect_pt_masked (struct kvm *kvm, +struct kvm_memory_slot *slot, +gfn_t gfn_offset, +unsigned long mask);int kvm_vm_ioctl_irq_line (struct kvm *kvm,struct kvm_irq_level *irq_level,bool line_status);
virt/kvm/Kconfig +3 -0
@@ -37,3 +37,6 @@ config KVM_VFIO config HAVE_KVM_ARCH_TLB_FLUSH_ALL bool + +config HAVE_KVM_ARCH_DIRTY_LOG + bool
virt/kvm/kvm_main.c +91 -0
97 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [PATCH v11 2/6] KVM: Add generic implementation of kvm_vm_ioctl_get_dirty_log
Quoted 6 lines · Mario Smarduch
Add support for generic implementation of dirty log read function. For now
x86_64and ARMv7 share generic dirty log read. Other architectures call their architecture specific functions.Signed-off-by Mario Smarduch <[email protected]>---
This looks reasonable to me,
Other arch kvm-maintainers: will you give this a look and a spin for your ok?
Thanks,
-Christoffer
Re: [PATCH v11 2/6] KVM: Add generic implementation of kvm_vm_ioctl_get_dirty_log
In reply to Mario SmarduchQuoted 5 lines · On Mon, 22 Sep 2014 17:54:46 -0700 Mario Smarduch <[email protected]>…
Add support for generic implementation of dirty log read function. For now
x86_64and ARMv7 share generic dirty log read. Other architectures call their architecture specific functions.Signed-off-by Mario Smarduch <[email protected]>
This (and the previous patch), once fitted on current kvm/next (trivial rejects), seems to work fine on s390 and looks sane to me.
So, for the s390 parts:
Re: [PATCH v11 2/6] KVM: Add generic implementation of kvm_vm_ioctl_get_dirty_log
Quoted 7 lines · Cornelia Huck
Quoted 4 lines · On Mon, 22 Sep 2014 17:54:46 -0700 Mario Smarduch <[email protected]>…
Add support for generic implementation of dirty log read function. For now
x86_64and ARMv7 share generic dirty log read. Other architectures call their architecture specific functions.
Quoted 9 lines
Quoted 1 line
Signed-off-by Mario Smarduch <[email protected]>This (and the previous patch), once fitted on current kvm/next (trivial rejects), seems to work fine on s390 and looks sane to me.
So, for the s390 parts:
Acked-by Cornelia Huck <[email protected]>
Thanks,
Mario
Re: [PATCH v11 2/6] KVM: Add generic implementation of kvm_vm_ioctl_get_dirty_log
In reply to Mario SmarduchQuoted 29 lines · Mario Smarduch
Add support for generic implementation of dirty log read function. For now
x86_64and ARMv7 share generic dirty log read. Other architectures call their architecture specific functions.Signed-off-by Mario Smarduch <[email protected]>--- arch/arm/kvm/Kconfig | 1 + arch/arm/kvm/arm.c | 2 +- arch/arm64/kvm/Kconfig | 1 + arch/ia64/kvm/Kconfig | 1 + arch/ia64/kvm/kvm-ia64.c | 2 +- arch/mips/kvm/Kconfig | 1 + arch/mips/kvm/mips.c | 2 +- arch/powerpc/kvm/Kconfig | 1 + arch/powerpc/kvm/book3s.c | 2 +- arch/powerpc/kvm/booke.c | 2 +- arch/s390/kvm/Kconfig | 1 + arch/s390/kvm/kvm-s390.c | 2 +- arch/x86/kvm/x86.c | 86 ------------------------------------------ include/linux/kvm_host.h | 6 +++ virt/kvm/Kconfig | 3 ++ virt/kvm/kvm_main.c | 91 +++++++++++++++++++++++++++++++++++++++++++++ 16 files changed, 112 insertions(+), 92 deletions(-)arch/arm/kvm/Kconfig +0
-0
arch/arm/kvm/Kconfig config KVM · line 26
Quoted 4 lines
arch/arm/kvm/Kconfig +1
-0@@ -23,6 +23,7 @@ config KVM select HAVE_KVM_CPU_RELAX_INTERCEPT select KVM_MMIO select KVM_ARM_HOST + select HAVE_KVM_ARCH_DIRTY_LOG
I think we're better off treating the "common dirty log" option as the odd case. So instead of adding this option for every arch, just set it on x86 and later on arm. Then you can ...
virt/kvm/kvm_main.c
Quoted 267 lines
arch/arm/kvm/Kconfig +0
-0depends on ARM_VIRT_EXT && ARM_LPAE && !CPU_BIG_ENDIAN ---help--- Support hosting virtualized guest machines. You will alsoarch/arm/kvm/arm.c +1
-1@@ -774,7 +774,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp, } } -int kvm_vm_ioctl_get_dirty_log (struct kvm *kvm,struct kvm_dirty_log *log) +int kvm_arch_vm_ioctl_get_dirty_log (struct kvm *kvm,struct kvm_dirty_log *log) {return -EINVAL ; }arch/arm64/kvm/Kconfig +1
-0@@ -26,6 +26,7 @@ config KVM select KVM_ARM_HOST select KVM_ARM_VGIC select KVM_ARM_TIMER + select HAVE_KVM_ARCH_DIRTY_LOG ---help--- Support hosting virtualized guest machines.arch/ia64/kvm/Kconfig +1
-0@@ -28,6 +28,7 @@ config KVM select HAVE_KVM_IRQ_ROUTING select KVM_APIC_ARCHITECTURE select KVM_MMIO + select HAVE_KVM_ARCH_DIRTY_LOG ---help--- Support hosting fully virtualized guest machines using hardware virtualization extensions. You will need a fairly recentarch/ia64/kvm/kvm-ia64.c +1
-1@@ -1812,7 +1812,7 @@ static void kvm_ia64_sync_dirty_log(struct kvm *kvm,spin_unlock (&kvm->arch.dirty_log_lock); } -int kvm_vm_ioctl_get_dirty_log (struct kvm *kvm, +int kvm_arch_vm_ioctl_get_dirty_log (struct kvm *kvm,struct kvm_dirty_log *log) {int r;arch/mips/kvm/Kconfig +1
-0@@ -20,6 +20,7 @@ config KVM select PREEMPT_NOTIFIERS select ANON_INODES select KVM_MMIO + select HAVE_KVM_ARCH_DIRTY_LOG ---help--- Support for hosting Guest kernels. Currently supported on MIPS32 processors.arch/mips/kvm/mips.c +1
-1@@ -791,7 +791,7 @@ out: }/* Get (and clear) the dirty memory log for a memory slot. */ -int kvm_vm_ioctl_get_dirty_log (struct kvm *kvm,struct kvm_dirty_log *log) +int kvm_arch_vm_ioctl_get_dirty_log (struct kvm *kvm,struct kvm_dirty_log *log) {struct kvm_memory_slot *memslot;unsigned long ga, ga_end;arch/powerpc/kvm/Kconfig +1
-0@@ -21,6 +21,7 @@ config KVM select PREEMPT_NOTIFIERS select ANON_INODES select HAVE_KVM_EVENTFD + select HAVE_KVM_ARCH_DIRTY_LOG config KVM_BOOK3S_HANDLER boolarch/powerpc/kvm/book3s.c +1
-1@@ -815,7 +815,7 @@ int kvmppc_core_check_requests(struct kvm_vcpu *vcpu)return vcpu->kvm->arch.kvm_ops->check_requests (vcpu); } -int kvm_vm_ioctl_get_dirty_log (struct kvm *kvm,struct kvm_dirty_log *log) +int kvm_arch_vm_ioctl_get_dirty_log (struct kvm *kvm,struct kvm_dirty_log *log) {return kvm->arch.kvm_ops->get_dirty_log (kvm, log); }arch/powerpc/kvm/booke.c +1
-1@@ -1624,7 +1624,7 @@ int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,return r; } -int kvm_vm_ioctl_get_dirty_log (struct kvm *kvm,struct kvm_dirty_log *log) +int kvm_arch_vm_ioctl_get_dirty_log (struct kvm *kvm,struct kvm_dirty_log *log) {return -ENOTSUPP ; }arch/s390/kvm/Kconfig +1
-0@@ -27,6 +27,7 @@ config KVM select KVM_ASYNC_PF_SYNC select HAVE_KVM_IRQCHIP select HAVE_KVM_IRQ_ROUTING + select HAVE_KVM_ARCH_DIRTY_LOG ---help--- Support hosting paravirtualized guest machines using the SIE virtualization capability on the mainframe. This should workarch/s390/kvm/kvm-s390.c +1
-1@@ -208,7 +208,7 @@ static void kvm_s390_sync_dirty_log(struct kvm *kvm,/* * Get (and clear) the dirty memory log for a memory slot. */ -int kvm_vm_ioctl_get_dirty_log (struct kvm *kvm, +int kvm_arch_vm_ioctl_get_dirty_log (struct kvm *kvm,struct kvm_dirty_log *log) {int r;arch/x86/kvm/x86.c +0
-86@@ -3577,92 +3577,6 @@ static int kvm_vm_ioctl_reinject(struct kvm *kvm,return 0 ; } -/** -* 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; - - r =0 ; -out: -mutex_unlock (&kvm->slots_lock); -return r; -} -int kvm_vm_ioctl_irq_line (struct kvm *kvm,struct kvm_irq_level *irq_event,bool line_status) {include/linux/kvm_host.h +6
-0@@ -609,6 +609,12 @@ int kvm_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log, int *is_dirty);int kvm_vm_ioctl_get_dirty_log (struct kvm *kvm,struct kvm_dirty_log *log); +int kvm_arch_vm_ioctl_get_dirty_log (struct kvm *kvm, +struct kvm_dirty_log *log); +void kvm_mmu_write_protect_pt_masked (struct kvm *kvm, +struct kvm_memory_slot *slot, +gfn_t gfn_offset, +unsigned long mask);int kvm_vm_ioctl_irq_line (struct kvm *kvm,struct kvm_irq_level *irq_level,bool line_status);virt/kvm/Kconfig +3
-0@@ -37,3 +37,6 @@ config KVM_VFIO config HAVE_KVM_ARCH_TLB_FLUSH_ALL bool + +config HAVE_KVM_ARCH_DIRTY_LOG + boolvirt/kvm/kvm_main.c +0
-0
... move this code to a new file in virt/kvm. dirty.c maybe. Then you can build include that file with obj-$CONFIG_foo in the Makefile on virt/kvm.
Alex
PATCH v11 3/6 arm: KVM: Add ARMv7 API to flush TLBs
In reply to Mario SmarduchThis patch adds ARMv7 architecture TLB Flush function.
--- arch/arm/include/asm/kvm_asm.h | 1 + arch/arm/include/asm/kvm_host.h | 12 ++++++++++++ arch/arm/kvm/Kconfig | 1 + arch/arm/kvm/interrupts.S | 12 ++++++++++++ 4 files changed, 26 insertions(+)
arch/arm/include/asm/kvm_asm.h +1 -0
@@ -78,6 +78,7 @@ extern char __kvm_hyp_code_end[];extern void __kvm_flush_vm_context (void );extern void __kvm_tlb_flush_vmid_ipa (struct kvm *kvm,phys_addr_t ipa); +extern void __kvm_tlb_flush_vmid (struct kvm *kvm);extern int __kvm_vcpu_run (struct kvm_vcpu *vcpu);#endif
arch/arm/include/asm/kvm_host.h +12 -0
@@ -220,6 +220,18 @@ static inline void __cpu_init_hyp_mode(phys_addr_t boot_pgd_ptr,kvm_call_hyp ((void *)hyp_stack_ptr, vector_ptr, pgd_ptr); } +/** +* kvm_arch_flush_remote_tlbs() - flush all VM TLB entries +* @kvm: pointer to kvm structure. +* +* Interface to HYP function to flush all VM TLB entries without address +* parameter. +*/ +static inline void kvm_arch_flush_remote_tlbs (struct kvm *kvm) +{ +kvm_call_hyp (__kvm_tlb_flush_vmid, kvm); +} +static inline int kvm_arch_dev_ioctl_check_extension (long ext) {return 0 ;
arch/arm/kvm/Kconfig +1 -0
@@ -24,6 +24,7 @@ config KVM select KVM_MMIO select KVM_ARM_HOST select HAVE_KVM_ARCH_DIRTY_LOG + select HAVE_KVM_ARCH_TLB_FLUSH_ALL depends on ARM_VIRT_EXT && ARM_LPAE && !CPU_BIG_ENDIAN ---help--- Support hosting virtualized guest machines. You will also
arch/arm/kvm/interrupts.S +12 -0
@@ -66,6 +66,18 @@ ENTRY(__kvm_tlb_flush_vmid_ipa) bx lr ENDPROC(__kvm_tlb_flush_vmid_ipa) +/** + * void __kvm_tlb_flush_vmid(struct kvm *kvm) - Flush per-VMID TLBs + * + * Reuses __kvm_tlb_flush_vmid_ipa() for ARMv7, without passing address + * parameter + */ + +ENTRY(__kvm_tlb_flush_vmid) + b __kvm_tlb_flush_vmid_ipa +ENDPROC(__kvm_tlb_flush_vmid) + + /******************************************************************** * Flush TLBs and instruction caches of all CPUs inside the inner-shareable * domain, for all VMIDs
Signature · 1 line
1.7.9.5
PATCH v11 4/6 arm: KVM: Add initial dirty page locking infrastructure
In reply to Mario SmarduchPatch adds support for initial write protection of VM memlsot. This patch series assumes that huge PUDs will not be used in 2nd stage tables, which is awlays valid on ARMv7.
--- arch/arm/include/asm/kvm_host.h | 2 + arch/arm/include/asm/kvm_mmu.h | 20 +++++ arch/arm/include/asm/pgtable-3level.h | 1 + arch/arm/kvm/arm.c | 9 +++ arch/arm/kvm/mmu.c | 129 +++++++++++++++++++++++++++++++++ 5 files changed, 161 insertions(+)
arch/arm/include/asm/kvm_host.h +2 -0
@@ -243,4 +243,6 @@ int kvm_perf_teardown(void);u64 kvm_arm_timer_get_reg (struct kvm_vcpu *,u64 regid);int kvm_arm_timer_set_reg (struct kvm_vcpu *,u64 regid,u64 value); +void kvm_mmu_wp_memory_region (struct kvm *kvm,int slot); +#endif /* __ARM_KVM_HOST_H__ */
arch/arm/include/asm/kvm_mmu.h +20 -0
@@ -114,6 +114,26 @@ static inline void kvm_set_s2pmd_writable(pmd_t *pmd)pmd_val (*pmd) |=L_PMD_S2_RDWR ; } +static inline void kvm_set_s2pte_readonly (pte_t *pte) +{ +pte_val (*pte) = (pte_val (*pte) & ~L_PTE_S2_RDWR ) |L_PTE_S2_RDONLY ; +} + +static inline bool kvm_s2pte_readonly (pte_t *pte) +{ +return (pte_val (*pte) &L_PTE_S2_RDWR ) ==L_PTE_S2_RDONLY ; +} + +static inline void kvm_set_s2pmd_readonly (pmd_t *pmd) +{ +pmd_val (*pmd) = (pmd_val (*pmd) & ~L_PMD_S2_RDWR ) |L_PMD_S2_RDONLY ; +} + +static inline bool kvm_s2pmd_readonly (pmd_t *pmd) +{ +return (pmd_val (*pmd) &L_PMD_S2_RDWR ) ==L_PMD_S2_RDONLY ; +} +/* Open coded p*d_addr_end that can deal with 64bit addresses */ #define kvm_pgd_addr_end (addr, end) \ ({ u64 __boundary = ((addr) + PGDIR_SIZE) & PGDIR_MASK; \
arch/arm/include/asm/pgtable-3level.h +1 -0
@@ -129,6 +129,7 @@#define L_PTE_S2_RDONLY (_AT(pteval_t, 1) << 6)/* HAP[1] */ #define L_PTE_S2_RDWR (_AT(pteval_t, 3) << 6)/* HAP[2:1] */ +#define L_PMD_S2_RDONLY (_AT(pmdval_t, 1) << 6)/* HAP[1] */ #define L_PMD_S2_RDWR (_AT(pmdval_t, 3) << 6)/* HAP[2:1] */ /*
arch/arm/kvm/arm.c +9 -0
@@ -242,6 +242,15 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,const struct kvm_memory_slot *old, enum kvm_mr_change change) { +#ifdef CONFIG_ARM +/* +* At this point memslot has been committed and there is an +* allocated dirty_bitmap[], dirty pages will be be tracked while the +* memory slot is write protected. +*/ + if ((change != KVM_MR_DELETE) && (mem->flags & KVM_MEM_LOG_DIRTY_PAGES)) + kvm_mmu_wp_memory_region(kvm, mem->slot); +#endif } void kvm_arch_flush_shadow_all(struct kvm *kvm)
arch/arm/kvm/mmu.c +129 -0
141 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v11 5/6 arm: KVM: dirty log read write protect support
In reply to Mario SmarduchThis patch adds support to track VM dirty pages, between dirty log reads. Pages that have been dirtied since last log read are write protected again, in preparation of next dirty log read. In addition ARMv7 dirty log read function is pushed up to generic layer.
--- arch/arm/kvm/Kconfig | 1 - arch/arm/kvm/arm.c | 2 ++ arch/arm/kvm/mmu.c | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-)
arch/arm/kvm/Kconfig +0 -1
@@ -23,7 +23,6 @@ config KVM select HAVE_KVM_CPU_RELAX_INTERCEPT select KVM_MMIO select KVM_ARM_HOST - select HAVE_KVM_ARCH_DIRTY_LOG select HAVE_KVM_ARCH_TLB_FLUSH_ALL depends on ARM_VIRT_EXT && ARM_LPAE && !CPU_BIG_ENDIAN ---help---
arch/arm/kvm/arm.c +2 -0
@@ -783,10 +783,12 @@ long kvm_arch_vcpu_ioctl(struct file *filp, } } +#ifdef CONFIG_ARM64 int kvm_arch_vm_ioctl_get_dirty_log (struct kvm *kvm,struct kvm_dirty_log *log) {return -EINVAL ; } +#endif static int kvm_vm_ioctl_set_device_addr (struct kvm *kvm,struct kvm_arm_device_addr *dev_addr)
arch/arm/kvm/mmu.c +22 -0
@@ -873,6 +873,28 @@ void kvm_mmu_wp_memory_region(struct kvm *kvm, int slot)spin_unlock (&kvm->mmu_lock); kvm_flush_remote_tlbs(kvm); } + +/** +* kvm_mmu_write_protected_pt_masked() - write protect dirty pages set in mask +* @kvm: The KVM pointer +* @slot: The memory slot associated with mask +* @gfn_offset: The gfn offset in memory slot +* @mask: The mask of dirty pages at offset 'gfn_offset' in this memory +* slot to be write protected +* +* Walks bits set in mask write protects the associated pte's. Caller must +* acquire kvm_mmu_lock. +*/ +void kvm_mmu_write_protect_pt_masked (struct kvm *kvm, +struct kvm_memory_slot *slot, +gfn_t gfn_offset,unsigned long mask) +{ +phys_addr_t base_gfn = slot->base_gfn + gfn_offset; +phys_addr_t start = (base_gfn +__ffs (mask)) <<PAGE_SHIFT ; +phys_addr_t end = (base_gfn +__fls (mask) +1 ) <<PAGE_SHIFT ; + +stage2_wp_range (kvm, start, end); +}#endif static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
Signature · 1 line
1.7.9.5
PATCH v11 6/6 arm: KVM: ARMv7 dirty page logging 2nd stage page fault
In reply to Mario SmarduchThis patch adds support for handling 2nd stage page faults during migration, it disables faulting in huge pages, and dissolves huge pages to page tables. In case migration is canceled huge pages may be used again.
--- arch/arm/kvm/mmu.c | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-)
arch/arm/kvm/mmu.c +39 -6
@@ -47,6 +47,15 @@ static phys_addr_t hyp_idmap_vector;#define kvm_pmd_huge (_x) (pmd_huge(_x) || pmd_trans_huge(_x))#define kvm_pud_huge (_x) pud_huge(_x) +static bool kvm_get_logging_state (struct kvm_memory_slot *memslot) +{ +#ifdef CONFIG_ARM +return !!memslot->dirty_bitmap; +#else +return false; +#endif +} +static void kvm_tlb_flush_vmid_ipa (struct kvm *kvm,phys_addr_t ipa) {/*
@@ -626,7 +635,8 @@ static int stage2_set_pmd_huge(struct kvm *kvm, struct kvm_mmu_memory_cache }static int stage2_set_pte (struct kvm *kvm,struct kvm_mmu_memory_cache *cache, -phys_addr_t addr,const pte_t *new_pte,bool iomap) +phys_addr_t addr,const pte_t *new_pte,bool iomap, +bool logging_active) {pmd_t *pmd;pte_t *pte, old_pte;
@@ -641,6 +651,18 @@ static int stage2_set_pte(struct kvm *kvm, struct kvm_mmu_memory_cache *cache,return 0 ; } +/* +* While dirty memory logging, clear PMD entry for huge page and split +* into smaller pages, to track dirty memory at page granularity. +*/ +if (logging_active &&kvm_pmd_huge (*pmd)) { +phys_addr_t ipa =pmd_pfn (*pmd) <<PAGE_SHIFT ; + +pmd_clear (pmd); +kvm_tlb_flush_vmid_ipa (kvm, ipa); +put_page (virt_to_page (pmd)); + } +/* Create stage-2 page mappings - Level 2 */ if (pmd_none (*pmd)) {if (!cache)
@@ -693,7 +715,7 @@ int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa,if (ret) goto out;spin_lock (&kvm->mmu_lock); - ret =stage2_set_pte (kvm, &cache, addr, &pte, true); + ret =stage2_set_pte (kvm, &cache, addr, &pte, true, false);spin_unlock (&kvm->mmu_lock);if (ret) goto out;
@@ -910,6 +932,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,struct kvm_mmu_memory_cache *memcache = &vcpu->arch.mmu_page_cache;struct vm_area_struct *vma;pfn_t pfn; +bool logging_active =kvm_get_logging_state (memslot); write_fault =kvm_is_write_fault (kvm_vcpu_get_hsr (vcpu));if (fault_status ==FSC_PERM && !write_fault) {
@@ -920,7 +943,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,/* Let's check if we will get back a huge page backed by hugetlbfs */ down_read (¤t->mm->mmap_sem); vma =find_vma_intersection (current->mm, hva, hva +1 ); -if (is_vm_hugetlb_page (vma)) { +if (is_vm_hugetlb_page (vma) && !logging_active) { hugetlb = true; gfn = (fault_ipa &PMD_MASK ) >>PAGE_SHIFT ; }else {
@@ -963,7 +986,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,spin_lock (&kvm->mmu_lock);if (mmu_notifier_retry (kvm, mmu_seq)) goto out_unlock; -if (!hugetlb && !force_pte) +if (!hugetlb && !force_pte && !logging_active) hugetlb =transparent_hugepage_adjust (&pfn, &fault_ipa);if (hugetlb) {
@@ -982,9 +1005,12 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,kvm_set_pfn_dirty (pfn); }coherent_cache_guest_page (vcpu, hva,PAGE_SIZE ); - ret =stage2_set_pte (kvm, memcache, fault_ipa, &new_pte, false); + ret =stage2_set_pte (kvm, memcache, fault_ipa, &new_pte, false, + logging_active); } +if (write_fault) +mark_page_dirty (kvm, gfn); out_unlock:spin_unlock (&kvm->mmu_lock);
@@ -1135,7 +1161,14 @@ static void kvm_set_spte_handler(struct kvm *kvm, gpa_t gpa, void *data) {pte_t *pte = (pte_t *)data; -stage2_set_pte (kvm,NULL , gpa, pte, false); +/* +* We can always call stage2_set_pte with logging_active == false, +* because MMU notifiers will have unmapped a huge PMD before calling +* ->change_pte() (which in turn calls kvm_set_spte_hva()) and therefore +* stage2_set_pte() never needs to clear out a huge PMD through this +* calling path. +*/ +stage2_set_pte (kvm,NULL , gpa, pte, false, false); }
Signature · 1 line
1.7.9.5
Re: [PATCH v11 6/6] arm: KVM: ARMv7 dirty page logging 2nd stage page fault
Quoted 6 lines · Mario Smarduch
This patch adds support for handling 2nd stage page faults during migration, it disables faulting in huge pages, and dissolves huge pages to page tables. In case migration is canceled huge pages may be used again.
Signed-off-by Mario Smarduch <[email protected]>
It seems here and in a bunch of the other patches you didn't apply my Reviewed-by tags. Did you change the patches in other ways than addressed by the review comments?
Thanks,
-Christoffer
Re: [PATCH v11 6/6] arm: KVM: ARMv7 dirty page logging 2nd stage page fault
Quoted 6 lines · Christoffer Dall
Quoted 5 lines · Mario Smarduch
This patch adds support for handling 2nd stage page faults during migration, it disables faulting in huge pages, and dissolves huge pages to page tables. In case migration is canceled huge pages may be used again.
Quoted 9 lines
Quoted 1 line
Signed-off-by Mario Smarduch <[email protected]>It seems here and in a bunch of the other patches you didn't apply my Reviewed-by tags. Did you change the patches in other ways than addressed by the review comments?
Thanks,
-Christoffer
Christoffer,
you comments and Hiabins were applied, no other changes.
Overlooked the acks/reviewed :(
Thanks,
- Mario