Skip to content

Commit df60cb2

Browse files
ScuDaysavpatel
authored andcommitted
KVM: riscv: Support enabling dirty log gradually in small chunks
There is already support of enabling dirty log gradually in small chunks for x86 in commit 3c9bd40 ("KVM: x86: enable dirty log gradually in small chunks") and c862626 ("KVM: arm64: Support enabling dirty log gradually in small chunks"). This adds support for riscv. x86 and arm64 writes protect both huge pages and normal pages now, so riscv protect also protects both huge pages and normal pages. On a nested virtualization setup (RISC-V KVM running inside a QEMU VM on an [Intel® Core™ i5-12500H] host), I did some tests with a 2G Linux VM using different backing page sizes. The time taken for memory_global_dirty_log_start in the L2 QEMU is listed below: Page Size Before After Optimization 4K 4490.23ms 31.94ms 2M 48.97ms 45.46ms 1G 28.40ms 30.93ms Signed-off-by: Quan Zhou <zhouquan@iscas.ac.cn> Signed-off-by: Dong Yang <dayss1224@gmail.com> Reviewed-by: Anup Patel <anup@brainfault.org> Link: https://lore.kernel.org/r/20251103062825.9084-1-dayss1224@gmail.com Signed-off-by: Anup Patel <anup@brainfault.org>
1 parent a2483d5 commit df60cb2

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

Documentation/virt/kvm/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8028,7 +8028,7 @@ will be initialized to 1 when created. This also improves performance because
80288028
dirty logging can be enabled gradually in small chunks on the first call
80298029
to KVM_CLEAR_DIRTY_LOG. KVM_DIRTY_LOG_INITIALLY_SET depends on
80308030
KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE (it is also only available on
8031-
x86 and arm64 for now).
8031+
x86, arm64 and riscv for now).
80328032

80338033
KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 was previously available under the name
80348034
KVM_CAP_MANUAL_DIRTY_LOG_PROTECT, but the implementation had bugs that make

arch/riscv/include/asm/kvm_host.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
BIT(IRQ_VS_TIMER) | \
6060
BIT(IRQ_VS_EXT))
6161

62+
#define KVM_DIRTY_LOG_MANUAL_CAPS (KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE | \
63+
KVM_DIRTY_LOG_INITIALLY_SET)
64+
6265
struct kvm_vm_stat {
6366
struct kvm_vm_stat_generic generic;
6467
};

arch/riscv/kvm/mmu.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,11 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
161161
* allocated dirty_bitmap[], dirty pages will be tracked while
162162
* the memory slot is write protected.
163163
*/
164-
if (change != KVM_MR_DELETE && new->flags & KVM_MEM_LOG_DIRTY_PAGES)
164+
if (change != KVM_MR_DELETE && new->flags & KVM_MEM_LOG_DIRTY_PAGES) {
165+
if (kvm_dirty_log_manual_protect_and_init_set(kvm))
166+
return;
165167
mmu_wp_memory_region(kvm, new->id);
168+
}
166169
}
167170

168171
int kvm_arch_prepare_memory_region(struct kvm *kvm,

0 commit comments

Comments
 (0)