The dirty ring reserves room for CPU-side dirty buffers via kvm_cpu_dirty_log_size(). Report the HDBSS buffer entry count through it, so a full buffer flush always fits in the ring.
Pin the HDBSS buffer size to PAGE_SIZE when dirty-ring is enabled, via kvm_arch_dirty_ring_size_updated(): a larger buffer only shrinks the soft_limit and forces more frequent userspace drains. Signed-off-by: Tian Zheng <[email protected]> --- arch/arm64/kvm/arm.c | 8 ++++++++ arch/arm64/kvm/mmu.c | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 9d7bdece149a..5a7046acb62e 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -215,6 +215,14 @@ static int kvm_arm_default_max_vcpus(void) return vgic_present ? kvm_vgic_get_max_vcpus() : KVM_MAX_VCPUS; } +void kvm_arch_dirty_ring_size_updated(struct kvm *kvm) +{ + if (!system_supports_hdbss()) + return; + + kvm->arch.hdbss_buffer_size = KVM_ARM_HDBSS_DEFAULT_SIZE; +} + /** * kvm_arch_init_vm - initializes a VM data structure * @kvm: pointer to the KVM struct diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 7bf82d65041c..c1e09ba98d48 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -2841,3 +2841,11 @@ void kvm_toggle_cache(struct kvm_vcpu *vcpu, bool was_enabled) trace_kvm_toggle_cache(*vcpu_pc(vcpu), was_enabled, now_enabled); } + +int kvm_cpu_dirty_log_size(struct kvm *kvm) +{ + if (!system_supports_hdbss()) + return 0; + + return kvm_hdbss_buffer_size(kvm) / sizeof(u64); +} -- 2.43.0

