euleros inclusion category: feature bugzilla: NA CVE: NA
This series supports log dirty for migration in RISC-V KVM. We have implemented the vm migration in Qemu, So these patches have been tested and are valid.
Link: https://gitee.com/openeuler/kernel/issues/I1SWY2
Yifei Jiang (4): riscv/kvm: Fix use VSIP_VALID_MASK mask HIP register riscv/kvm: add kvm_arch_mmu_enable_log_dirty_pt_masked riscv/kvm: implement kvm_vm_ioctl_get_dirty_log riscv/kvm: Add kvm_vm_ioctl_clear_dirty_log
arch/riscv/configs/defconfig | 1 + arch/riscv/kvm/Kconfig | 1 + arch/riscv/kvm/mmu.c | 37 +++++++++++++++++++++++++++ arch/riscv/kvm/vcpu.c | 2 +- arch/riscv/kvm/vm.c | 49 ++++++++++++++++++++++++++++++++++-- 5 files changed, 87 insertions(+), 3 deletions(-)
euleros inclusion category: feature bugzilla: NA CVE: NA
The correct sip/sie 0x222 could mask wrong 0x000 by VSIP_VALID_MASK, This patch fix it.
Link: https://gitee.com/openeuler/kernel/issues/I1SWY2 Signed-off-by: Yifei Jiang jiangyifei@huawei.com Signed-off-by: Yipeng Yin yinyipeng1@huawei.com --- arch/riscv/kvm/vcpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index d10905c18..0a7b492bc 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -445,8 +445,8 @@ static int kvm_riscv_vcpu_set_reg_csr(struct kvm_vcpu *vcpu,
if (reg_num == KVM_REG_RISCV_CSR_REG(sip) || reg_num == KVM_REG_RISCV_CSR_REG(sie)) { - reg_val = reg_val << VSIP_TO_HVIP_SHIFT; reg_val = reg_val & VSIP_VALID_MASK; + reg_val = reg_val << VSIP_TO_HVIP_SHIFT; }
((unsigned long *)csr)[reg_num] = reg_val;
euleros inclusion category: feature bugzilla: NA CVE: NA
Enable dirty logging for selected dirty pages.
Link: https://gitee.com/openeuler/kernel/issues/I1SWY2 Signed-off-by: Yifei Jiang jiangyifei@huawei.com Signed-off-by: Yipeng Yin yinyipeng1@huawei.com --- arch/riscv/kvm/mmu.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c index 81d15ca52..ad5bea790 100644 --- a/arch/riscv/kvm/mmu.c +++ b/arch/riscv/kvm/mmu.c @@ -358,6 +358,43 @@ void stage2_wp_memory_region(struct kvm *kvm, int slot) kvm_flush_remote_tlbs(kvm); }
+/* + * kvm_mmu_write_protect_pt_masked() - write protect dirty pages + * @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. + */ +static 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); +} + +/* + * kvm_arch_mmu_enable_log_dirty_pt_masked - enable dirty logging for selected + * dirty pages. + * + * It calls kvm_mmu_write_protect_pt_masked to write protect selected pages to + * enable dirty logging for them. + */ +void kvm_arch_mmu_enable_log_dirty_pt_masked(struct kvm *kvm, + struct kvm_memory_slot *slot, + gfn_t gfn_offset, unsigned long mask) +{ + kvm_mmu_write_protect_pt_masked(kvm, slot, gfn_offset, mask); +} + + int stage2_ioremap(struct kvm *kvm, gpa_t gpa, phys_addr_t hpa, unsigned long size, bool writable) {
euleros inclusion category: feature bugzilla: NA CVE: NA
Implement the interface kvm_vm_ioctl_get_dirty_log for getting and clearing the log of dirty pages in a slot.
Link: https://gitee.com/openeuler/kernel/issues/I1SWY2 Signed-off-by: Yifei Jiang jiangyifei@huawei.com Signed-off-by: Yipeng Yin yinyipeng1@huawei.com --- arch/riscv/kvm/vm.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-)
diff --git a/arch/riscv/kvm/vm.c b/arch/riscv/kvm/vm.c index 473299e71..26c228577 100644 --- a/arch/riscv/kvm/vm.c +++ b/arch/riscv/kvm/vm.c @@ -12,10 +12,39 @@ #include <linux/uaccess.h> #include <linux/kvm_host.h>
+/** + * 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 + * + * Steps 1-4 below provide general overview of dirty page logging. See + * kvm_get_dirty_log_protect() function description for additional details. + * + * We call kvm_get_dirty_log_protect() to handle steps 1-3, upon return we + * always flush the TLB (step 4) even if previous step failed and the dirty + * bitmap may be corrupt. Regardless of previous outcome the KVM logging API + * does not preclude user space subsequent dirty log read. Flushing TLB ensures + * writes will be marked dirty for next log read. + * + * 1. Take a snapshot of the bit and clear it if needed. + * 2. Write protect the corresponding page. + * 3. Copy the snapshot to the userspace. + * 4. Flush TLB's if needed. + */ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log) { - /* TODO: To be added later. */ - return -ENOTSUPP; + bool flush = false; + int r; + + mutex_lock(&kvm->slots_lock); + + r = kvm_get_dirty_log_protect(kvm, log, &flush); + + if (flush) + kvm_flush_remote_tlbs(kvm); + + mutex_unlock(&kvm->slots_lock); + return r; }
int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
euleros inclusion category: feature bugzilla: NA CVE: NA
Add the interface kvm_vm_ioctl_clear_dirty_log for clearing the log of dirty pages in a slot. In addition, config KVM_GENERIC_DIRTYLOG_READ_PROTECT is added in defconfig.
Link: https://gitee.com/openeuler/kernel/issues/I1SWY2 Signed-off-by: Yifei Jiang jiangyifei@huawei.com Signed-off-by: Yipeng Yin yinyipeng1@huawei.com --- arch/riscv/configs/defconfig | 1 + arch/riscv/kvm/Kconfig | 1 + arch/riscv/kvm/vm.c | 16 ++++++++++++++++ 3 files changed, 18 insertions(+)
diff --git a/arch/riscv/configs/defconfig b/arch/riscv/configs/defconfig index 1b8375b63..1bffcedb6 100644 --- a/arch/riscv/configs/defconfig +++ b/arch/riscv/configs/defconfig @@ -18,6 +18,7 @@ CONFIG_SOC_SIFIVE=y CONFIG_SMP=y CONFIG_VIRTUALIZATION=y CONFIG_KVM=y +CONFIG_KVM_GENERIC_DIRTYLOG_READ_PROTECT=y CONFIG_HOTPLUG_CPU=y CONFIG_MODULES=y CONFIG_MODULE_UNLOAD=y diff --git a/arch/riscv/kvm/Kconfig b/arch/riscv/kvm/Kconfig index 95d85d893..2fb5867de 100644 --- a/arch/riscv/kvm/Kconfig +++ b/arch/riscv/kvm/Kconfig @@ -28,6 +28,7 @@ config KVM select HAVE_KVM_VCPU_ASYNC_IOCTL select SRCU select HAVE_KVM_EVENTFD + select KVM_GENERIC_DIRTYLOG_READ_PROTECT help Support hosting virtualized guest machines.
diff --git a/arch/riscv/kvm/vm.c b/arch/riscv/kvm/vm.c index 26c228577..e95d3dd3e 100644 --- a/arch/riscv/kvm/vm.c +++ b/arch/riscv/kvm/vm.c @@ -47,6 +47,22 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, struct kvm_dirty_log *log) return r; }
+int kvm_vm_ioctl_clear_dirty_log(struct kvm *kvm, struct kvm_clear_dirty_log *log) +{ + bool flush = false; + int r; + + mutex_lock(&kvm->slots_lock); + + r = kvm_clear_dirty_log_protect(kvm, log, &flush); + + if (flush) + kvm_flush_remote_tlbs(kvm); + + mutex_unlock(&kvm->slots_lock); + return r; +} + int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) { int r;
Reviewed-by: Kai Deng dengkai1@huawei.com
-----邮件原件----- 发件人: Jiangyifei 发送时间: 2020年8月27日 10:04 收件人: Xiexiuqi xiexiuqi@huawei.com; Guohanjun (Hanjun Guo) guohanjun@huawei.com 抄送: kernel.openeuler kernel.openeuler@huawei.com; kernel@openeuler.org; Zhanghailiang zhang.zhanghailiang@huawei.com; Chenzhendong (alex) alex.chen@huawei.com; dengkai (A) dengkai1@huawei.com; Zhangxiaofeng (F) victor.zhangxiaofeng@huawei.com; yinyipeng yinyipeng1@huawei.com; Jiangyifei jiangyifei@huawei.com 主题: [PATCH kernel-5.5 0/4] Add RISC-V log dirty support
euleros inclusion category: feature bugzilla: NA CVE: NA
This series supports log dirty for migration in RISC-V KVM. We have implemented the vm migration in Qemu, So these patches have been tested and are valid.
Link: https://gitee.com/openeuler/kernel/issues/I1SWY2
Yifei Jiang (4): riscv/kvm: Fix use VSIP_VALID_MASK mask HIP register riscv/kvm: add kvm_arch_mmu_enable_log_dirty_pt_masked riscv/kvm: implement kvm_vm_ioctl_get_dirty_log riscv/kvm: Add kvm_vm_ioctl_clear_dirty_log
arch/riscv/configs/defconfig | 1 + arch/riscv/kvm/Kconfig | 1 + arch/riscv/kvm/mmu.c | 37 +++++++++++++++++++++++++++ arch/riscv/kvm/vcpu.c | 2 +- arch/riscv/kvm/vm.c | 49 ++++++++++++++++++++++++++++++++++-- 5 files changed, 87 insertions(+), 3 deletions(-)
-- 2.19.1
Acked-by: Xie XiuQi xiexiuqi@huawei.com
On 2020/8/27 10:03, Yifei Jiang wrote:
euleros inclusion category: feature bugzilla: NA CVE: NA
This series supports log dirty for migration in RISC-V KVM. We have implemented the vm migration in Qemu, So these patches have been tested and are valid.
Link: https://gitee.com/openeuler/kernel/issues/I1SWY2
Yifei Jiang (4): riscv/kvm: Fix use VSIP_VALID_MASK mask HIP register riscv/kvm: add kvm_arch_mmu_enable_log_dirty_pt_masked riscv/kvm: implement kvm_vm_ioctl_get_dirty_log riscv/kvm: Add kvm_vm_ioctl_clear_dirty_log
arch/riscv/configs/defconfig | 1 + arch/riscv/kvm/Kconfig | 1 + arch/riscv/kvm/mmu.c | 37 +++++++++++++++++++++++++++ arch/riscv/kvm/vcpu.c | 2 +- arch/riscv/kvm/vm.c | 49 ++++++++++++++++++++++++++++++++++-- 5 files changed, 87 insertions(+), 3 deletions(-)
Reviewed-by: Kai Deng dengkai1@huawei.com
-----邮件原件----- 发件人: Jiangyifei 发送时间: 2020年8月27日 10:04 收件人: Xiexiuqi xiexiuqi@huawei.com; Guohanjun (Hanjun Guo) guohanjun@huawei.com 抄送: kernel.openeuler kernel.openeuler@huawei.com; kernel@openeuler.org; Zhanghailiang zhang.zhanghailiang@huawei.com; Chenzhendong (alex) alex.chen@huawei.com; dengkai (A) dengkai1@huawei.com; Zhangxiaofeng (F) victor.zhangxiaofeng@huawei.com; yinyipeng yinyipeng1@huawei.com; Jiangyifei jiangyifei@huawei.com 主题: [PATCH kernel-5.5 0/4] Add RISC-V log dirty support
euleros inclusion category: feature bugzilla: NA CVE: NA
This series supports log dirty for migration in RISC-V KVM. We have implemented the vm migration in Qemu, So these patches have been tested and are valid.
Link: https://gitee.com/openeuler/kernel/issues/I1SWY2
Yifei Jiang (4): riscv/kvm: Fix use VSIP_VALID_MASK mask HIP register riscv/kvm: add kvm_arch_mmu_enable_log_dirty_pt_masked riscv/kvm: implement kvm_vm_ioctl_get_dirty_log riscv/kvm: Add kvm_vm_ioctl_clear_dirty_log
arch/riscv/configs/defconfig | 1 + arch/riscv/kvm/Kconfig | 1 + arch/riscv/kvm/mmu.c | 37 +++++++++++++++++++++++++++ arch/riscv/kvm/vcpu.c | 2 +- arch/riscv/kvm/vm.c | 49 ++++++++++++++++++++++++++++++++++-- 5 files changed, 87 insertions(+), 3 deletions(-)
-- 2.19.1